Menu

#479 readf problem formatted files

closed-fixed
nobody
None
5
2012-09-13
2012-08-31
ema
No

I am a new user of GDL and I have a problem with GDL "readf".

My problem is the following: I usually have to read files with a large and variable number of columns, but only few of them are needed,
i.e. say the first 5 columns of a file with 30 columns.

In IDL I used a simple procedure,

openr, unit, 'file_name'

- begin loop -

readf, unit, var_1, var_2, var_3, .. var_n
(where 'n' is much smaller than the actual column numbers of the file)

- end loop-

close, unit

So, I tried to use this procedure in GDL, but I can not read the file correctly.
It seems that at each loop readf do not read the correct row, but continues to read the line untill all the columns have been read.

The files I use have columns separated by spaces.

An example of such a file is the following:

# NMOD LOG(T) H/HE LOG L/Ls LOG TE LOG TC LOG RHOc TMAX MTMAX M-CC M-HEC M-CE L-PP L-CNO
1 1.09313015 0.71612E+00 2.51319 3.60580 5.23683 -3.15591 0.00000 0.00000 0.00000 0.00000 0.40000 0.191E-17 0.000E+00
2 1.17231139 0.71612E+00 1.85994 3.56524 5.26247 -3.11205 0.00000 0.00000 0.08615 0.00000 0.01818 0.309E-16 0.000E+00
3 1.18655183 0.71612E+00 1.85461 3.56442 5.26246 -3.11172 0.00000 0.00000 0.11274 0.00000 0.00000 0.313E-16 0.000E+00
4 1.20707350 0.71612E+00 1.76889 3.54252 5.26243 -3.11169 0.00000 0.00000 0.11380 0.00000 0.00000 0.381E-16 0.000E+00
5 1.21172533 0.71612E+00 1.76165 3.54076 5.26254 -3.11150 0.00000 0.00000 0.11194 0.00000 0.02457 0.388E-16 0.000E+00
6 1.21861097 0.71612E+00 1.75927 3.54034 5.26256 -3.11145 0.00000 0.00000 0.12085 0.00000 0.02510 0.391E-16 0.000E+00
7 1.22873896 0.71612E+00 1.75734 3.54009 5.26261 -3.11137 0.00000 0.00000 0.12204 0.00000 0.02669 0.394E-16 0.000E+00
8 1.24350140 0.71612E+00 1.75490 3.53981 5.26270 -3.11122 0.00000 0.00000 0.12231 0.00000 0.03095 0.398E-16 0.000E+00
9 1.26474481 0.71612E+00 1.75174 3.53947 5.26282 -3.11102 0.00000 0.00000 0.12231 0.00000 0.03520 0.403E-16 0.000E+00

I need to read column 4 and 5.

The program I used is the following,

pro read_test

txt = ''

openr, 2, 'example.txt'
readf, 2, txt
print,txt

i = -1
while (not(eof(2)) and i lt 10) do begin
readf, 2, col1, col2, col3, col4, col5
i=i+1
print, i, col1, col2, col3, col4, col5
endwhile
close, 2

end

And this is what I get:

# NMOD LOG(T) H/HE LOG L/Ls LOG TE LOG TC LOG RHOc TMAX MTMAX M-CC M-HEC M-CE L-PP L-CNO
0 1.00000 1.09313 0.71612 2.51319 3.60580
1 5.23683 -3.15591 0.00000 0.00000 0.00000
2 0.00000 0.40000 1.91000e-18 0.00000 2.00000
3 1.17231 0.71612 1.85994 3.56524 5.26247
4 -3.11205 0.00000 0.00000 0.08615 0.00000
5 0.01818 3.09000e-17 0.00000 3.00000 1.18655
6 0.71612 1.85461 3.56442 5.26246 -3.11172
7 0.00000 0.00000 0.11274 0.00000 0.00000
8 3.13000e-17 0.00000 4.00000 1.20707 0.71612
9 1.76889 3.54252 5.26243 -3.11169 0.00000
10 0.00000 0.11380 0.00000 0.00000 3.81000e-17

which is completely wrong!!

How can I solve the problem?

Other informations:
OS : Mac OS X 10.8
GDL : installed via fink (gdl v0.9.2-3)

Thank you very much.

Discussion

  • Alain C.

    Alain C. - 2012-09-01

    Unfortunately I am able to reproduce this bug on current CVS version.

    Alain

     
  • Marc Schellens

    Marc Schellens - 2012-09-13
    • status: open --> closed-fixed
     
  • Marc Schellens

    Marc Schellens - 2012-09-13

    Fixed in the CVS.

     

Log in to post a comment.