comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: read multiple files with varying names
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: read multiple files with varying names [message #66641 is a reply to message #66601] Fri, 29 May 2009 07:01 Go to previous messageGo to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
sophie.hoss@gmail.com wrote:
> On 28 Mai, 17:25, "Jean H." <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
> wrote:
>> sophie.h...@gmail.com wrote:
>>> s=strarr(cols)
>>> n=0
>>> while (~ eof(file) and (n lt rows_data -1 )) do begin
>>> ; Read a line of data
>>> readf,lun,s
>>> ; Store it in data
>>> data[*,n]=s
>>> n=n+1 (*****)
>>> end
>>> data=data[*,0:n-1]
>>> I did the while-loop because I learned that IDL might not read every
>>> line separately. Don't know if it's the most elegant version but at
>>> least it is one.
>>> for the sake of my sanity, any help is appreciated!
>>> cheers,
>>> sophie
>> Sophie,
>> when reading strings, the whole line is read. So when you read in S, you
>> are reading nb_cols LINES.. s[0] = line0, s[1] = line1 etc. You would
>> have to read the whole line then separate the columns.
>>
>> You can do it in one step
>>
>> data = strarr(nbLines)
>> readf,lun,data
>>
>> Jean- Zitierten Text ausblenden -
>>
>> - Zitierten Text anzeigen -
>
> Jean, thanks for that, but I'm still stuck with the same problem no
> matter how I do it. I cut the code short to
>
> CD, 'filepath'
> ci_files = FILE_SEARCH('ci*', COUNT=num_ci_files_found)
>
> for i = 0,(num_ci_files_found-1) do begin
>
> file = ci_files(i)
> rows = File_Lines(file)
> OpenR, lun, file, /Get_Lun
> header = StrArr(34)
> ReadF, lun, header
> Point_Lun, -lun, currentLocation
> data = strarr(12, rows-(n_elements(header))) ; i know there's 12
> columns
> readF, lun, data
>
> ; from here on I want to extract one column only and
> save this column (radiation data from one station for one month) in a
> file where I later add values from all other stations for this
> specific month, then take the average from all stations over the whole
> month)
>
> --> READF: End of file encountered.
>
> Do I need to include a format statement? I read some posts saying it
> is sometimes (in easy cases) better to forget about any format
> statements...
>
> thanks for your input...
> sophie, going crazy

Sophie,

you are still reading a text line, so without the format, the whole line
is stored where you believe one column value would be stored. In other
words, you are reading 12 * nb_lines LINES, which is obviously too much.

So, if possible, you would have to play with the formats...

For example, reading a simple file that contains:
a b c
d e f

can be read as:
data = strarr(3,2)
readf,lun,data, format = '(3A2)' ;3 times a text (A) of length 2 (the space)

but if you do
readf,lun,data
then you get the same error as you are know. And if you print data[0,0],
you get "a b c"

Jean
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Am I having a blackout?
Next Topic: How to extract latitude and longitude information from HDF file?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:20:57 PDT 2025

Total time taken to generate the page: 0.00376 seconds