• Pascal Question

    From Black Panther@21:1/186 to All on Tue May 22 12:40:39 2018
    Hi All,

    With my work schedule getting messed up for today, I've decided to do some
    work on my MTAFile program. Instead of working my normal 7am to 4pm, they
    want me to work overnight, in preparation for inventory. So, I'll be working 10pm to 7am... :(

    In the previous week, I have done a complete re-write of this program. It was
    a mess, as it was my first program I wrote, while learning the basics of Pascal.

    Anyway, I've been trying to get the program to sort the output in
    alphabetical order, first by the file echo name, then by the filename. I've been having some issues in accomplishing this.

    The program is reading the .tic files, and storing them in an array of
    records. The record definition is as follows:

    type
    ticfiles = record
    area : string;
    areadesc: string;
    filename: string;
    size : integer;
    desc : array [1..60] of string;
    ldesc : array [1..60] of string;
    origin : string;
    magic : string;
    replaces: string;
    end;

    I have tried using a couple different sort methods, but I don't think they
    are working well with strings, instead of integers.

    I have even thought about adding an 'areaorder:integer' and
    'fileorder:integer' into the records, and writing a procedure to insert
    numbers by the alphabetically order. This was also giving me the red-ass...

    As I know there are some Pascal programmers out here, I thought I'd ask for some suggestions as to how to best accomplish this task.

    Just an FYI, I am using Lazarus v1.8.2+dfsg-3 with FPC v3.0.4. I'm not sure
    if the versions make much difference or not... :)

    Thank you all in advance for your assistance. This has been a thorn in my
    side for a couple weeks now... :)


    ---

    Black Panther
    a.k.a. Dan Richter
    Sysop - Castle Rock BBS (RCS)
    telnet://bbs.castlerockbbs.com
    http://www.castlerockbbs.com
    The sparrows are flying again....

    --- Mystic BBS v1.12 A39 2018/04/21 (Linux/64)
    * Origin: Castle Rock BBS - bbs.castlerockbbs.com (21:1/186)
  • From Al@21:4/106 to Black Panther on Tue May 22 12:30:18 2018
    Re: Pascal Question
    By: Black Panther to All on Tue May 22 2018 12:40 pm

    With my work schedule getting messed up for today, I've decided to do some work on my MTAFile program. Instead of working my normal 7am to 4pm, they want me to work overnight, in preparation for inventory. So, I'll be working 10pm to 7am... :(

    Sorry to hear that. That happens to me too every year when the temps peak in the summer. The tempurature in the foundry where I work gets to hot to work so they move my shift (afternoons) to the night shift.

    Even so it is still good and warm in the foundry but it is better than the temps in the afternoon. The forcast high for today is 29C so it won't be long until that happens. I'll likely be on the night shift for 2 - 3 months.

    I really hate getting home and trying to sleep at 8 in the morning.

    Ttyl :-),
    Al


    ... The computer made me do it!
    --- SBBSecho 3.04-Linux
    * Origin: The Rusty MailBox - Penticton, BC Canada (21:4/106)
  • From Avon@21:1/101 to Black Panther on Wed May 23 09:04:48 2018
    On 05/22/18, Black Panther pondered and said...

    With my work schedule getting messed up for today, I've decided to do
    some work on my MTAFile program. Instead of working my normal 7am to
    4pm, they want me to work overnight, in preparation for inventory. So, I'll be working 10pm to 7am... :(

    Bummer Dan... I woke up at 5.30am today, was ready to leave for work at 7am
    and started at 8am this morning,will leave work early today as my day is also kinda messed up... darn body clock..

    --- Mystic BBS v1.12 A39 2018/04/21 (Windows/32)
    * Origin: Agency BBS | Dunedin, New Zealand | agency.bbs.nz (21:1/101)
  • From Black Panther@21:1/186 to Al on Tue May 22 15:06:18 2018
    On 05/22/18, Al said the following...

    Sorry to hear that. That happens to me too every year when the temps
    peak in the summer. The tempurature in the foundry where I work gets to hot to work so they move my shift (afternoons) to the night shift.

    Back when I lived in Wisconsin, I worked for a few years at an iron foundry. One of those years, we had a HOT summer. Both 1st and 2nd shifts were given extended leave, as it was unsafe working conditions. All they had was a skeleton crew to keep all the equipment running.

    In the middle of the afternoon, it could reach temps of 140F (60C). They even tried working 30 minutes on and 30 minutes off...

    I really hate getting home and trying to sleep at 8 in the morning.

    When I was younger, I would get done with work at 6am, and be at the bar
    until about 11am. That was a strange feeling at first. There's just something wrong with drinking at 6am... :)


    ---

    Black Panther
    a.k.a. Dan Richter
    Sysop - Castle Rock BBS (RCS)
    telnet://bbs.castlerockbbs.com
    http://www.castlerockbbs.com
    The sparrows are flying again....

    --- Mystic BBS v1.12 A39 2018/04/21 (Linux/64)
    * Origin: Castle Rock BBS - bbs.castlerockbbs.com (21:1/186)
  • From Black Panther@21:1/186 to Avon on Tue May 22 15:20:00 2018
    On 05/23/18, Avon said the following...

    Bummer Dan... I woke up at 5.30am today, was ready to leave for work at 7am and started at 8am this morning,will leave work early today as my
    day is also kinda messed up... darn body clock..

    At least it's only for one day... I don't know if my body could handle
    working nights for an extended period of time anymore... :)

    They say you're only as old as you feel. I'm sure tomorrow morning, I'll feel like I'm about 150... ;)


    ---

    Black Panther
    a.k.a. Dan Richter
    Sysop - Castle Rock BBS (RCS)
    telnet://bbs.castlerockbbs.com
    http://www.castlerockbbs.com
    The sparrows are flying again....

    --- Mystic BBS v1.12 A39 2018/04/21 (Linux/64)
    * Origin: Castle Rock BBS - bbs.castlerockbbs.com (21:1/186)
  • From Avon@21:1/101 to Black Panther on Wed May 23 10:42:00 2018
    On 05/22/18, Black Panther pondered and said...

    At least it's only for one day... I don't know if my body could handle working nights for an extended period of time anymore... :)

    It's worse when it's like that I reckon.... I did a few weeks of 12am -6am on-air then went back to noon-4pm and nearly killed me, well it felt like
    that :)

    --- Mystic BBS v1.12 A39 2018/04/21 (Windows/32)
    * Origin: Agency BBS | Dunedin, New Zealand | agency.bbs.nz (21:1/101)
  • From Al@21:4/106 to Black Panther on Wed May 23 01:32:44 2018
    Re: Re: Pascal Question
    By: Black Panther to Al on Tue May 22 2018 03:06 pm

    In the middle of the afternoon, it could reach temps of 140F (60C). They even tried working 30 minutes on and 30 minutes off...

    That is extreme. If the temps here aproach 50C thay start to think about shutting down. If it goes above 55C they will shut it down.

    I find working in temps above 45C hard to handle. Someone at my foundry died of heat stroke before I started there so they take it very seriously.

    Ttyl :-),
    Al


    ... Atheism is a non-prophet organization.
    --- SBBSecho 3.04-Linux
    * Origin: The Rusty MailBox - Penticton, BC Canada (21:4/106)
  • From xqtr@21:1/111 to Black Panther on Wed May 23 07:07:33 2018
    Anyway, I've been trying to get the program to sort the output in alphabetical order, first by the file echo name, then by the filename. I've been having some issues in accomplishing this.
    The program is reading the .tic files, and storing them in an array of records. The record definition is as follows:
    I have tried using a couple different sort methods, but I don't think
    they are working well with strings, instead of integers.
    I have even thought about adding an 'areaorder:integer' and 'fileorder:integer' into the records, and writing a procedure to insert numbers by the alphabetically order. This was also giving me the red-ass...

    What Sort method you used? How do you do the comparison of the strings to see which is first and which is second, alphabetically?

    A simple way is to use the ord function for the first character of each string and if its numerical value is greater, sort it accordingly. In pseudocode:

    value1 = 'apples'
    value2 = 'bananas'

    if ord(value1[1]) > value2[1]) then reverse_order else leave_it;

    If you dont care about capital or small letters, convert all strings to capital letters.

    If you are using FreePascal, i am sure it has some libraries/objects to do sorting, with the Bubble sort method, i think.

    .----- --- -- -
    | Another Droid BBS
    : Telnet : andr01d.zapto.org:9999 [UTC 11:00 - 20:00]
    . Contact : xqtr@gmx.com

    --- Mystic BBS v1.12 A38 2018/01/01 (Raspberry Pi/32)
    * Origin: Another Droid BBS (21:1/111)
  • From Black Panther@21:1/186 to xqtr on Wed May 23 08:25:06 2018
    On 05/23/18, xqtr said the following...

    What Sort method you used? How do you do the comparison of the strings
    to see which is first and which is second, alphabetically?

    I was just using < and >.

    if upcase(tic[d].area) < upcase(tic[z].area then ...

    A simple way is to use the ord function for the first character of each string and if its numerical value is greater, sort it accordingly. In pseudocode:

    if ord(value1[1]) > value2[1]) then reverse_order else leave_it;

    I never thought of using ord. I'll give that a try. I could always extend it
    to check for the second, third, etc, characters as well, in case of multiple areas with the same first character...

    If you dont care about capital or small letters, convert all strings to capital letters.

    That's what I've been trying as well. By using the < and >, I believe it
    checks the ASCII value of the letters, and lower and capitals are different...

    I think I may have just figured out why my way wasn't working. By using the line like I have above, it would be checking the ASCII value of the entire string, not just the first letter...

    If you are using FreePascal, i am sure it has some libraries/objects to
    do sorting, with the Bubble sort method, i think.

    I did look, and noticed there are sorts like bubble, quick, etc, but they all looked like they just worked with integers... Could something like that be
    used for strings as well?

    Thanks for the help.


    ---

    Black Panther
    a.k.a. Dan Richter
    Sysop - Castle Rock BBS (RCS)
    telnet://bbs.castlerockbbs.com
    http://www.castlerockbbs.com
    The sparrows are flying again....

    --- Mystic BBS v1.12 A39 2018/04/21 (Linux/64)
    * Origin: Castle Rock BBS - bbs.castlerockbbs.com (21:1/186)
  • From xqtr@21:1/111 to Black Panther on Wed May 23 12:59:49 2018
    I was just using < and >.
    if upcase(tic[d].area) < upcase(tic[z].area then ...

    In Freepascal that should also work... Are you sure that the problem is the comparison and not, for example, the record exchange? For example if
    tic[d] needs to exchange position with the tic[z] record, you must use a temp record to successful do the exchange like this:
    tmp = tic[z]; tic[z]:=tic[a]; tic[a]:=tmp;

    Also you must do the comparisons approximately n^2 times, to fully sort the array of records you have.. where n is the size of the array/list of records you have. In this page you can see a complete example for string comparison in records. Check the Sort procedure. Its not the ideal algorithm for too many items.

    http://computer-programming-forum.com/29-pascal/a795719a54ad7e31.htm

    .----- --- -- -
    | Another Droid BBS
    : Telnet : andr01d.zapto.org:9999 [UTC 11:00 - 20:00]
    . Contact : xqtr@gmx.com

    --- Mystic BBS v1.12 A38 2018/01/01 (Raspberry Pi/32)
    * Origin: Another Droid BBS (21:1/111)
  • From Black Panther@21:1/186 to xqtr on Wed May 23 14:58:31 2018
    On 05/23/18, xqtr said the following...

    I was just using < and >.
    if upcase(tic[d].area) < upcase(tic[z].area then ...

    In Freepascal that should also work... Are you sure that the problem is

    It would have worked if I were using:

    if upcase(tic[d].area[1]) < upcase(tic[z].area[1] then ...

    By adding the character position, I'm able to sort it just fine. (at least by the first letter)

    the comparison and not, for example, the record exchange? For example if tic[d] needs to exchange position with the tic[z] record, you must use a temp record to successful do the exchange like this:
    tmp = tic[z]; tic[z]:=tic[a]; tic[a]:=tmp;

    Yup, I've got that part working. :)

    tic[temp]:=tic[d];
    tic[d]:=tic[z];
    tic[z]:=tic[temp];

    Also you must do the comparisons approximately n^2 times, to fully sort the array of records you have.. where n is the size of the array/list of

    That's what I'm working on now.

    records you have. In this page you can see a complete example for string comparison in records. Check the Sort procedure. Its not the ideal algorithm for too many items.

    That's actually a better example than others that I've found. I'll have to
    see if I can incorporate it into my code.

    Thank you for all your help.


    ---

    Black Panther
    a.k.a. Dan Richter
    Sysop - Castle Rock BBS (RCS)
    telnet://bbs.castlerockbbs.com
    http://www.castlerockbbs.com
    The sparrows are flying again....

    --- Mystic BBS v1.12 A39 2018/04/21 (Linux/64)
    * Origin: Castle Rock BBS - bbs.castlerockbbs.com (21:1/186)
  • From Vk3jed@21:1/109 to Al on Thu May 24 14:12:00 2018
    Al wrote to Black Panther <=-

    That is extreme. If the temps here aproach 50C thay start to think
    about shutting down. If it goes above 55C they will shut it down.

    I find working in temps above 45C hard to handle. Someone at my foundry died of heat stroke before I started there so they take it very
    seriously.

    Try 50C+ It's tough and you can only do it 10-15 minutes at a time, before taking a rest at least as long in cool conditions or in a rehab chair to bring the body temperature back down again. I did it couple of times in my late teens/early 20s in a malfunctioning wood drying kiln. Luckily, it was the middle of winter, with the outside temperature around 0-5C, which helped with maintaining a reasonable body temperature during rest breaks.


    ... Ignorance is the mother of research.
    === MultiMail/Win32 v0.49
    --- SBBSecho 3.03-Linux
    * Origin: Freeway BBS Bendigo,Australia freeway.apana.org.au (21:1/109)
  • From Al@21:4/106 to Vk3jed on Thu May 24 01:29:29 2018
    Re: Re: Pascal Question
    By: Vk3jed to Al on Thu May 24 2018 02:12 pm

    Try 50C+ It's tough and you can only do it 10-15 minutes at a time, before taking a rest at least as long in cool conditions or in a rehab chair to bring the body temperature back down again. I did it couple of times in my late teens/early 20s in a malfunctioning wood drying kiln. Luckily, it was the middle of winter, with the outside temperature around 0-5C, which helped with maintaining a reasonable body temperature during rest breaks.

    It was aprox. 36C in my work area today. I suppose that will go up as summer moves in.. :)

    Had a heat stroke incident today at work, someone I was training had to spend a few hours in the first aid room. He was overdressed. His usual job requires coveralls so that is what he was wearing. Not a good idea in my area. The pouring floor on my left and the heat treat ovens on my right.

    Aside from the first aid room there is no cool place at the foundry to cool off. The best we can do is find a bit of shade.. hard to do here in the summer.

    Ttyl :-),
    Al


    ... No special reason, just government policy
    --- SBBSecho 3.04-Linux
    * Origin: The Rusty MailBox - Penticton, BC Canada (21:4/106)
  • From Avon@21:1/101 to Al on Thu May 24 20:55:30 2018
    On 05/24/18, Al pondered and said...

    It was aprox. 36C in my work area today. I suppose that will go up as summer moves in.. :)

    Wow that's hot it got to 12C today...

    Had a heat stroke incident today at work, someone I was training had to spend a few hours in the first aid room. He was overdressed. His usual
    job requires coveralls so that is what he was wearing. Not a good idea
    in my area. The pouring floor on my left and the heat treat ovens on my right.

    Poor fellow... that's a tough introduction to the new work area.

    Aside from the first aid room there is no cool place at the foundry to cool off. The best we can do is find a bit of shade.. hard to do here in the summer.

    You're welcome to my 9C high forecast for tomorrow!

    --- Mystic BBS v1.12 A39 2018/04/21 (Windows/32)
    * Origin: Agency BBS | Dunedin, New Zealand | agency.bbs.nz (21:1/101)
  • From Al@21:4/106 to Avon on Thu May 24 02:17:29 2018
    Re: Re: Pascal Question
    By: Avon to Al on Thu May 24 2018 08:55 pm

    Wow that's hot it got to 12C today...

    It got up to 29C here today. Quite warm for spring and it's been like that for a few weeks now. I hope this summer is not going to be a hot one agian. Last year large swaths of BC got burned up in forest fires. Quite a few small towns as well as larger ones got it too.

    Poor fellow... that's a tough introduction to the new work area.

    He's a long time employee too.. no stranger to the heat but it is something we need to be aware of at the foundry. It's normaly 10C (or more) warmer inside the foundry than the outside temp.

    It's nice in the winter, but not so nice in the summer.

    You're welcome to my 9C high forecast for tomorrow!

    If I could I would trade you +10 for -10.. but it just doesn't work.. :)

    Ttyl :-),
    Al


    ... Disclaimer: Advice void where prohibitted by common sense!
    --- SBBSecho 3.04-Linux
    * Origin: The Rusty MailBox - Penticton, BC Canada (21:4/106)
  • From Vk3jed@21:1/109 to Al on Thu May 24 19:55:00 2018
    Al wrote to Vk3jed <=-

    It was aprox. 36C in my work area today. I suppose that will go up as summer moves in.. :)

    Had a heat stroke incident today at work, someone I was training had to spend a few hours in the first aid room. He was overdressed. His usual
    job requires coveralls so that is what he was wearing. Not a good idea
    in my area. The pouring floor on my left and the heat treat ovens on my right.

    Aside from the first aid room there is no cool place at the foundry to cool off. The best we can do is find a bit of shade.. hard to do here
    in the summer.

    I think here the workplace safety regulators would have something to say. There would certainly be a Worksafe investigation if it was a major health incident.


    ... Many Myths are based on truth. Spock, stardate 5832.3.
    === MultiMail/Win32 v0.49
    --- SBBSecho 3.03-Linux
    * Origin: Freeway BBS Bendigo,Australia freeway.apana.org.au (21:1/109)
  • From Al@21:4/106 to Vk3jed on Thu May 24 03:34:34 2018
    Re: Re: Pascal Question
    By: Vk3jed to Al on Thu May 24 2018 07:55 pm

    I think here the workplace safety regulators would have something to say. There would certainly be a Worksafe investigation if it was a major health incident.

    Worksafe knows us well. They are here frequently making sure things are up to standards. We have had incidents here, a fire a few years ago on the melt deck that we all lost a few days work over but no one was hurt.

    This one wasn't major though. The worker just needed to lose his coveralls and cool down then he was back to work although on light duty.

    There is one cool place I forgot about. The lunch room is cool in summer and warm in winter. I rarely use it myself because I prefer to go outdoors and get some fresh air on my breaks.

    Ttyl :-),
    Al


    ... No sense being pessimistic. It wouldn't work anyway.
    --- SBBSecho 3.04-Linux
    * Origin: The Rusty MailBox - Penticton, BC Canada (21:4/106)
  • From Vk3jed@21:1/109 to Al on Thu May 24 21:31:00 2018
    Al wrote to Vk3jed <=-

    Worksafe knows us well. They are here frequently making sure things are
    up to standards. We have had incidents here, a fire a few years ago on
    the melt deck that we all lost a few days work over but no one was
    hurt.

    I see. :)

    This one wasn't major though. The worker just needed to lose his
    coveralls and cool down then he was back to work although on light
    duty.

    That's not too bad. Probably more heat exhaustion than heat stroke.

    There is one cool place I forgot about. The lunch room is cool in
    summer and warm in winter. I rarely use it myself because I prefer to
    go outdoors and get some fresh air on my breaks.

    I'm with you, outdoors rules. :)


    ... You! What PLANET is this? McCoy, stardate 3134.0.
    === MultiMail/Win32 v0.49
    --- SBBSecho 3.03-Linux
    * Origin: Freeway BBS Bendigo,Australia freeway.apana.org.au (21:1/109)
  • From tenser@21:1/112 to xqtr on Sun May 27 11:12:50 2018
    Also you must do the comparisons approximately n^2 times, to fully sort the array of records you have.. where n is the size of the array/list of records you have. In this page you can see a complete example for string comparison in records. Check the Sort procedure. Its not the ideal algorithm for too many items.

    I'd be somewhat shocked and horrified if the default sorting algorithm
    provided by Free Pascal was O(n^2), let alone bubble sort (which is approximately the worst non-joke algorithm, even by O(n^2) criteria).

    More likely it is a heap or merge sort, to guarantee O(n lg n) time;
    the former if one wants O(1) space complexity as well. It may be quicksort, however, which has O(n lg n) average-case running time.

    Most sorting algorithms provided by most language libraries can be used
    on both strings and integers (they are "generic" on the input type), and
    if you want to sort by two keys, you provide a custom comparison function
    that sorts by the primary key and then the secondary key, *or* use a stable sort sorting by the secondary key and *then* the primary key.

    --- Mystic BBS v1.12 A39 2018/04/21 (Windows/32)
    * Origin: Black Flag : ACiD Telnet HQ> blackflag.acid.org:28 (21:1/112)
  • From xqtr@21:1/111 to tenser on Sun May 27 07:01:04 2018
    I'd be somewhat shocked and horrified if the default sorting algorithm provided by Free Pascal was O(n^2), let alone bubble sort (which is approximately the worst non-joke algorithm, even by O(n^2) criteria).

    I am not sure which algorithm FreePascal uses. I was referring to a piece of code in a link that i provided.

    .----- --- -- -
    | Another Droid BBS
    : Telnet : andr01d.zapto.org:9999 [UTC 11:00 - 20:00]
    . Contact : xqtr@gmx.com

    --- Mystic BBS v1.12 A38 2018/01/01 (Raspberry Pi/32)
    * Origin: Another Droid BBS (21:1/111)