comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: how to find number of lines in an ASCII file?
items: how to find number of lines in an ASCII file?

Re: how to find number of lines in an ASCII file?
type: item
description: Jason Li wrote: > > Hi, > > I have an ASCII text file that contains data in a nice tabular form, > > 0 28660 1827.1 72.7705 -158.8828 3388.0 22.3846 10.8545 > 1 28661 1827.7 72.7701 -158.8752 3391.0 21.1213 10.6029 > 2 28662 1828.3 72.7698 -158.8677 3394.0 19.8743 10.3546 > > I want to read them all and save into an array: data[8, numberOfLines]. But > I don't know numberOfLines in the file before hand. What is the most efficient > way to find that out? The simplest method I've found for this is to read the data into a text array as follows: line='' readf, lun, line text = [line] while (not eof(lun)) do begin readf, lun, line text = [text, line] endwhile data = fltarr[8, N_Elements(text)] tmpdata = fltarr[8] for i=0, N_Elements(text)-1 do begin reads, text[i], tmpdata data[*, i] = tmpdata endfor Phillip
creator: Phillip & Suzanne[2]
date: 1998-08-18T07:00:00-00:00

how to find number of lines in an ASCII file?
type: item
description: Hi, I have an ASCII text file that contains data in a nice tabular form, 0 28660 1827.1 72.7705 -158.8828 3388.0 22.3846 10.8545 1 28661 1827.7 72.7701 -158.8752 3391.0 21.1213 10.6029 2 28662 1828.3 72.7698 -158.8677 3394.0 19.8743 10.3546 . . . I want to read them all and save into an array: data[8, numberOfLines]. But I don't know numberOfLines in the file before hand. What is the most efficient way to find that out? On UNIX, I can pass number of lines information back from wc command. Of course the same code won't work a on Mac. Please help. many thanks -- ============================================================ ============ Jason Y. Li | Tel : (301) 286-1029 Code 913 | Fax : (301) 286-1759 NASA Goddard Space Flight Center | www : http://climate.gsfc.nasa.gov Greenbelt, MD 20771, USA | email: jyli@climate.gsfc.nasa.gov ============================================================ ============ Beauty of style, harmony, grace and good rhythm depend on simplicity.
creator: jyli
date: 1998-08-19T07:00:00-00:00

Re: how to find number of lines in an ASCII file?
type: item
description: Jason Li wrote: > Hi, > > I have an ASCII text file that contains data in a nice tabular form, > > 0 28660 1827.1 72.7705 -158.8828 3388.0 22.3846 10.8545 > 1 28661 1827.7 72.7701 -158.8752 3391.0 21.1213 10.6029 > 2 28662 1828.3 72.7698 -158.8677 3394.0 19.8743 10.3546 > . > . > . > > I want to read them all and save into an array: data[8, numberOfLines]. But > I don't know numberOfLines in the file before hand. What is the most efficient > way to find that out? > > On UNIX, I can pass number of lines information back from wc command. Of > course the same code won't work a on Mac. Please help. > > many thanks > Hi Jason, a few months ago I answered someone else in this way. We have a lot more routines for file handling. Reimar ; ; Copyright (c) 1996, Forschungszentrum Juelich GmbH ICG-1 ; All rights reserved. ; Unauthorized reproduction prohibited. ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. ;+ ; NAME: ; filesize ; ; PURPOSE: ; The result of this function is the bytelength of an ascii file ; ; CATEGORY: ; DATAFILES/FILE ; ; CALLING SEQUENCE: ; Result=filesize(file_name) ; ; INPUTS: ; file_name: the name of an ascii file ; ; OUTPUTS: ; This function returns the number of bytes of an ascii file ; ; EXAMPLE: ; Result=filesize('test.asc') ; ; MODIFICATION HISTORY: ; Written by: R.Bauer (ICG-1), Oct. 1996 ;- FUNCTION filesize, filename IF N_PARAMS(0) LT 1 THEN BEGIN HELP: MESSAGE, 'result=filesize()',/cont MESSAGE,'--------------------------------------------------- ----',/cont RETURN,-1 help_open: MESSAGE,'file: '+filename+' not found',/cont RETURN,-1 ENDIF OPENR, lun, filename, /GET_LUN,error=err IF err NE 0 THEN GOTO, help_open stats = FSTAT(lun) FREE_LUN, lun RETURN, stats.size END ------------------------------------------------------------ -------- ; ; Copyright (c) 1997, Forschung…
creator: R. Bauer
date: 1998-08-28T07:00:00-00:00

Re: how to find number of lines in an ASCII file?
type: item
description: Jason Li wrote: >> I have an ASCII text file that contains data in a nice tabular form, >> I want to read them all and save into an array: data[8, numberOfLines]. But >> I don't know numberOfLines in the file before hand. What is the most efficient >> way to find that out? I don't know if it is the most efficient (I doubt it), but I find easy the following way. (1) I use a csh script to append one line to the top of the file telling how many header lines, how many data lines and columns there are xasasc filename (2) I use an IDL procedure to read the data in a structure of arrays, one array being an entire column, one optionally can name the columns xasasc,'filename',strucname or xasasc,'filename',strucname,['name1','name2'.....] Use of the software below is free, adapt as you wish, just remember I did it first, no warranties implied, etc. etc. ------------------------------------------------------------ ---------------- Lucio Chiappetti - IFCTR/CNR - via Bassini 15 - I-20133 Milano (Italy) For more info : http://www.ifctr.mi.cnr.it/~lucio/personal.html ------------------------------------------------------------ ---------------- This is the xasasc shell script #! /bin/csh -f # # transform an ASCII tabular file into a "XAS ASCII file" # this is mainly for reading into IDL # a XAS ASCII file is defined as having a first record structured as # # on OSF Alpha changed grep -s to grep -s -q to suppress all echo # # XAS1ASC2GEN31234 n_header_records n_data_records n_columns # # followed by some (or none) header records # and some data records in free-format containing only numbers in columnar arrangement # # check if file already contains magic number in first line head -1 $1 | grep -s 'XAS1ASC2GEN31234' if ($status == 0) exit 1 # # determine number of records in file ($nlines[1]) set nlines = `wc -l $1` # # loop on all lines trying to identify header lines # an header line is defined as a non data line # a data line is defined as one containing only numbers in the form 1…
creator: LC's No-Spam Newsread
date: 1998-08-31T07:00:00-00:00