English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Scripting (https://eab.abime.net/forumdisplay.php?f=117)
-   -   Hi Soft Basic help wanted (https://eab.abime.net/showthread.php?t=65725)

alphagemini 07 September 2012 10:28

Hi Soft Basic help wanted
 
I am trying to write a routine to sort listed data into time difference groups such that any group of data with a fixed time difference will have a line of space before the next group as follows:-
Basic data list
a
b
c
d
e
f
g
h
etc

If a-b < 5 then print a and b, if b-c < 5 print a,b and c etc
If c-d > 5 then print a line of space and start again at d

this will then look like this:-

a
b
c

d
e
f
g

h etc

Any item without a close neighbour is to be unlisted

Can anyone help?

Leffmann 07 September 2012 12:40

You can do this by starting at the first value and search forward while the difference is lower than your threshold. If the interval you searched in covers more than one value then you print these and a blank line after. If the next value after the interval is still inside your list then you repeat the whole procedure.

EDIT: assuming you have a list sorted in ascending order:
Code:

' set the threshold and number of items in our list
t = 5
n = 10

list(n) = list(n-1)+t

' search through the whole list
s = 0
while s < n

 ' find the end of the current interval
 e = s
 while list(e+1)-list(e) < t
  e = e+1
 wend

 ' if there were more than 1 item we print them
 if e-s > 0
  for i = s to e
  print list(i)
  next
  print
 end if

' step to the next item and repeat
s = e+1

wend


alphagemini 07 September 2012 17:00

Thanks. I will ponder on your answer and see if I can make it applicable. If not, may I
ask for more help?

regards

Dan

Leffmann 07 September 2012 20:18

Sure, no problem. This code should work with HiSoft Basic v2.0 from 1994, I'm not sure how compatible the other versions are.

alphagemini 11 September 2012 10:11

Hi Leffmann, my HiSoft basic program is V2.0, so it should work. My data generated from another program is filed in the following format:-

Day 11 9 Time 0 0 4 Har 12 22 35
Day 11 9 Time 10 10 40 Har 16 52 48

This makes the line lengths different. If we need the length of the file to use in the
formula you gave me, we need the number of lines and not just the file length. Typically my files have between 3500 and 4000 lines. I tried using the following code to find the file length:-

Open for input as #1 :
length&=LOF(1)
FileBuf$=INPUT$(length&,#1)
PRINT LOF(1)

I use the print statement to check LOF. The result is a large number 155378 is an example. To find the number of lines we need to divide this by the number of data bits in a line (I think). Therefore the line lengths must be equal. How can I file data so that all of the items are tabbed in columns? This would be useful also for visual inspection of the data. I use the following code in my data generation program.

OPEN ans2$ for APPEND AS #1

thanks for your help

Leffmann 11 September 2012 18:03

You can achieve both tabulation and fixed-width lines if you write your data with the print using-statement, f.ex:

Code:

print #1, using "### ### ### \    \", x, y, 10, "test"
The # specifies where you want to fit digits and the \\ including the space in between specifies where you want strings. These are the only formatting specifiers I remember off the top of my head.

Do you have the v2.0 manual btw? I'd like to add it to my own files but can't find a download anywhere.

EDIT: if the lines in your file are already sorted, and you're not doing anything else with the file but reading it in to group the lines and print them, then you can probably do this in one go and print as you read.

prowler 12 September 2012 00:33

Quote:

Originally Posted by Leffmann (Post 838957)
Do you have the v2.0 manual btw? I'd like to add it to my own files but can't find a download anywhere.

HiSoft Basic 2.0 Manual-on-disk is in The Zone for you. :)

alphagemini 12 September 2012 07:02

Quote:

Originally Posted by Leffmann (Post 838957)
You can achieve both tabulation and fixed-width lines if you write your data with the print using-statement, f.ex:

Code:

print #1, using "### ### ### \    \", x, y, 10, "test"
The # specifies where you want to fit digits and the \\ including the space in between specifies where you want strings. These are the only formatting specifiers I remember off the top of my head.

Do you have the v2.0 manual btw? I'd like to add it to my own files but can't find a download anywhere.

EDIT: if the lines in your file are already sorted, and you're not doing anything else with the file but reading it in to group the lines and print them, then you can probably do this in one go and print as you read.


Yes I have the original manual in hard copy. I find it hard to use because I'm not really a programmer. I'm just starting to learn but have a research
project to complete. I shall try your advice. Thanks for your help

alphagemini 12 September 2012 07:04

Quote:

Originally Posted by prowler (Post 839070)
HiSoft Basic 2.0 Manual-on-disk is in The Zone for you. :)


I have the original in hard copy. Using it with all that jargon is a big task for a
a starter!

alphagemini 12 September 2012 14:45

Quote:

Originally Posted by Leffmann (Post 838957)
You can achieve both tabulation and fixed-width lines if you write your data with the print using-statement, f.ex:

Code:

print #1, using "### ### ### \    \", x, y, 10, "test"
The # specifies where you want to fit digits and the \\ including the space in between specifies where you want strings. These are the only formatting specifiers I remember off the top of my head.

Do you have the v2.0 manual btw? I'd like to add it to my own files but can't find a download anywhere.

EDIT: if the lines in your file are already sorted, and you're not doing anything else with the file but reading it in to group the lines and print them, then you can probably do this in one go and print as you read.



Thanks. I have now managed to get the files right and can calculate the number of lines of text. Next is to get the search routine right.

Leffmann 13 September 2012 12:43

Quote:

Originally Posted by prowler (Post 839070)
HiSoft Basic 2.0 Manual-on-disk is in The Zone for you. :)

Thanks a lot! Been looking for this everywhere.

Quote:

Originally Posted by alphagemini (Post 839093)
Yes I have the original manual in hard copy. I find it hard to use because I'm not really a programmer. I'm just starting to learn but have a research
project to complete. I shall try your advice. Thanks for your help

Yes I understand, the manual is more of a reference and not so much a guide to programming for someone just starting out. Glad you got the formatting sorted out.


All times are GMT +2. The time now is 23:51.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.07453 seconds with 11 queries