Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-07

Odd delimited text file length limitations

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ko Hashiguchi

Sirs (and Madams, as need be),

I use Free Pascal to compose simple filters: I take in a comma-delimited ASCII file, work the data, and spit back out the altered info.

I'm having a problem in that my program does not seem to be reading all of the ASCII files. The files are mostly double-precision numbers; I read and rewrite the files just to set up the filter and make sure it works, as a prelude to adding data-altering code, and the numbers on the end show up as zeros, not the double-precision numbers desired.

If I need to send a snippet of code, please let me know. You are corresponding to an amateur programmer, although the code I'm writing is going to be for personal business purposes.

Thank you for your consideration,

Ko Hashiguchi

Reply by email

Bart
to Ko Hashiguchi

Well, show us some example code, and some example files that go wrong, otherwise ti'll be hard to help.

Bart

Ko Hashiguchi wrote 19 lines
Sirs (and Madams, as need be), I use Free Pascal to compose simple filters: I take in a comma-delimited ASCII file, work the data, and spit back out the altered info. I'm having a problem in that my program does not seem to be reading all of the ASCII files. The files are mostly double-precision numbers; I read and rewrite the files just to set up the filter and make sure it works, as a prelude to adding data-altering code, and the numbers on the end show up as zeros, not the double-precision numbers desired. If I need to send a snippet of code, please let me know. You are corresponding to an amateur programmer, although the code I'm writing is going to be for personal business purposes. Thank you for your consideration, Ko Hashiguchi

Reply by email

Ko Hashiguchi
to Bart

Hello Bart,

Attached you will find the Free Pascal program (it's a console program and 11KB in size), the file it's supposed to alter, and the file the program is supposed to spit out.

The last two values in the rows in VchrtTRN.TXT are not supposed to have values of 0.0. This is where my problem is: why doesn't the program give me the expected, non-zero answer?

Perhaps there are compiler switches or something old and arcane like that, about which I am ignorant. At any rate, I'm stumped. If you can figure out my bone-headed errors, I'd be most grateful :)

Ko Hashiguchi

Bart wrote 32 lines
Well, show us some example code, and some example files that go wrong, otherwise ti'll be hard to help. Bart On 7/4/11, Ko Hashiguchi wrote: > Sirs (and Madams, as need be), > > I use Free Pascal to compose simple filters: I take in a comma-delimited > ASCII file, work the data, and spit back out the altered info. > > I'm having a problem in that my program does not seem to be reading all of > the ASCII files. The files are mostly double-precision numbers; I read and > rewrite the files just to set up the filter and make sure it works, as a > prelude to adding data-altering code, and the numbers on the end show up as > zeros, not the double-precision numbers desired. > > If I need to send a snippet of code, please let me know. You are > corresponding to an amateur programmer, although the code I'm writing is > going to be for personal business purposes. > > Thank you for your consideration, > > Ko Hashiguchi > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Bart
to Ko Hashiguchi

Hi Ko,

Ko Hashiguchi wrote
The last two values in the rows in VchrtTRN.TXT are not supposed to have values of 0.0. This is where my problem is: why doesn't the program give me the expected, non-zero answer?

I tried a different approach.
Instead of breaking down the InputString yourself, why not let a TStringList do it for you.

After doing so you can iterate through the stringlist and obtain the values.

You need unit Classes for TStringList
I also used StrToFloatDef instead of Val (but that is not necessary, just a matter of taste), this is in the unit SysUtils.

You need to use a try..finally block to make sure the stringlist gets freed, hence the {$Mode ObjFpc} compiler switch at the beginning. (In default mode FreePascal does not use exceptions and try..finally blocks)

In the program I also set DefaultFormatSettings.DecimalSeparator to '.', just to be sure (on my Dutch Windows it is ','). The value is needed in StrToFoatDef().

See attached test.lpr for what I did.
I'll attach the output as well.

Oddly the values for NodZ and NsdZ seem to be the same always, even thoug the values of OldiNod and OldiNsd (used as input for LongitudeString) are not the same (I tested this).

Not sure why.
I didn't look into the LongitudeString function though...

One other observation: you define the character for "degree" as an extende ASCII character (#187).
This will only work on your codepage, it probably will not on mine.

Bart

Reply by email

José Mejuto
to Ko Hashiguchi: Attached you will find the Free Pascal program (it's a console program and 11KB in size),…

Hello FPC-Pascal,

Wednesday, July 6, 2011, 8:55:10 AM, you wrote:

KH> Attached you will find the Free Pascal program (it's a console program and KH> 11KB in size), the file it's supposed to alter, and the file the program is KH> supposed to spit out.

Add at beginning {$H+} to switch on ansistrings, otherwise you are using shortstrings which are 255 characters in length at most, and your lines are around 300 chars.

Best regards, José

Reply by email

Jürgen Hestermann
to José Mejuto
Add at beginning {$H+} to switch on ansistrings, otherwise you are using shortstrings which are 255 characters in length at most, and your lines are around 300 chars.

Instead of using obscure compiler switches (where you never know for sure the scope and whether they work as you think) I would advice to not use generic types like "string" but use "ansistring". Then you realy know what type is used in the end.

Reply by email

Ko Hashiguchi
to Jürgen Hestermann

Thanks to all of you good people!

Believe it or not, my old code was based on help obtained back in May of 1995(!) I had not needed programming help since. I have to think of myself as an amateur scientist using Fortran, not to make applications to sell to users, but just to get answers -- except that I'm coding in flavors of Pascal.

I assure myself, late in the dead of night, that I'm not stupid, but as far as programming skills are concerned, I am most certainly not learned. Thanks again to you learned people :)

Ko Hashiguchi

On Wed, Jul 6, 2011 at 8:52 AM, Jürgen Hestermann <

Show quoted text 18 lines
wrote: José Mejuto schrieb: Add at beginning {$H+} to switch on ansistrings, otherwise you are > using shortstrings which are 255 characters in length at most, and > your lines are around 300 chars. > > Instead of using obscure compiler switches (where you never know for sure the scope and whether they work as you think) I would advice to not use generic types like "string" but use "ansistring". Then you realy know what type is used in the end. ______________________________**_________________ fpc-pascal maillist - http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>

Reply by email