Re: the last line of a large file [message #55238 is a reply to message #55237] |
Fri, 10 August 2007 05:34   |
Conor
Messages: 138 Registered: February 2007
|
Senior Member |
|
|
On Aug 9, 5:22 pm, Paul van Delst <Paul.vanDe...@noaa.gov> wrote:
> Jean H. wrote:
>> Hi,
>
>> If you are sure it is the last line that you want to omit, you could do
>> something like:
>
>> nbOfLines = FILE_LINES(YourFileName)
>
>> for i = 0, nbOfLines - 2 do begin
>> readf, in_unit, input_line
>> endfor
>
> Or, if each record is the same format and consists only of numbers (no A-Z characters),
> you could probably get rid of the above loop too. E.g. say you have 10 columns of numbers
> per record (line)
>
> n_Records = FILE_LINES(YourFileName) - 1L
> ...open the file....
> All_the_Useful_Data = FLTARR(10,n_Records)
> readf, in_unit, All_the_Useful_Data
>
> ?
>
> I think that should work (or something like it).
>
> Of course, if you have records split over multiple lines, then it gets hairier.
>
>
>
>
>
>>> I am processing a large file with data in the same format till the
>>> last line. In the last line, it states how many records are included
>>> in this file.
>
>>> So the structure of my program is:
>
>>> while not eof(in_unit) do begin
>>> readf, in_unit, input_line
>>> if( input_line ne 'last line) then begin
>>> .....
>>> else
>>> ....
>>> endif
>>> endwhile
>
>>> Do I have to use 'if/then' to test whether every input_line is the
>>> last line of the file? Since there are many data records in the file,
>>> repeat calls to 'if/then' can be time consuming. But if I don't do the
>>> test, the program will be halted when it read in the last line.
>
>>> A Easy way I can think of is to delete the last line, but sometime we
>>> are not supposed to change the input files.
>
> You should also tell the people who wrote the code that creates the files that the number
> of records information is more useful if they stick it at the beginning of the file. :o)
>
> cheers,
>
> paulv
lol! Really! What in the world is the point of putting the number of
lines at the end of the file? That's got to be about the silliest
thing I've ever heard of. By the time you've actually read to the end
of the file, you already know how many lines there are!
|
|
|