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

Home » Public Forums » archive » readf,1,format= ......
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: readf,1,format= ...... [message #57468 is a reply to message #57392] Sun, 09 December 2007 08:07 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
woopik@interia.pl writes:

> sorry a type error but nothing change when i use FMTp for both
> (FMT is quite similar)
>
> function read_local ,file
> FMT=
> '(I5,2X,D13.8,2X,D13.8,3X,F8.2,3X,F8.2,3X,F7.2,3X,F7.2,3X,F6 .2,3X,F6.2,3X,F6.2,3X,F6.2,4X,F6.2,3X,F6.2,3X,F6.2,2X,F6.2)'
> spawn, ['wc', '-l', file], result, /noshell
> nlines = long(result(0))
> ttab = MAKE_ARRAY(nlines-5,15,/DOUBLE)
> OPENR,1,file
> line=''
> readf,1,line
> for i=1,nlines-5 do begin
> READF,1,FORMAT=FMT, n,ra,dec, l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12
> ttab[i-1,0]=n & ttab[i-1,1]=ra & ttab[i-1,2]=dec
> ttab[i-1,3]=l1 & ttab[i-1,4]=l2 & ttab[i-1,5]=l3
> ttab[i-1,6]=l4 & ttab[i-1,7]=l5 & ttab[i-1,8]=l6
> ttab[i-1,9]=l7 & ttab[i-1,10]=l8 & ttab[i-1,11]=l9
> ttab[i-1,12]=l10 & ttab[i-1,13]=l11 & ttab[i-1,14]=l12
> endfor
> CLOSE , 1
> print,FORMAT=FMT,ttab[0,*]
> RETURN,ttab
> end

Well, this is most interesting. There is a mismatch between
your variables (n, ra, dec, etc.) and your FORMAT statement.
In other words, ra and dec, since they are undeclared in the
program, are by default floats. Your format statement is going
to try to read them as doubles. The "rules" of input state that
IDL "tries to do what you want to do". Here, it thinks what you
are trying to do, is stuff a double into a float, and it does
this correctly. The variable ttab is a double, but it has been
stuffed with a floating value (from ra and dec).

The solution is to declare the variables on your READF
statement to be what you want to read into. That is, doubles.
However, I completely agree with Vince that what you REALLY
want to do is read this data in another way, rather than
line by line, practically the worst way to read data in IDL
(ala READ_ASCII). I think I would take his structure advice.
That will also solve your problem here.

Cheers,

David

P.S. Here is the program I used to test your program with the
data you sent yesterday:

function read_local ,file
FMT='(I5,2X,D13.8,2X,D13.8)'
nlines = File_lines(file)
ttab = MAKE_ARRAY(3,nlines,/DOUBLE)
n = 0L
ra = 0.0D0
dec = 0.0D0
OPENR,1,file
for I=0,nlines-1 do begin
READF,1,FORMAT=FMT, n,ra,dec
ttab[0,I]=n & ttab[1,I]=ra & ttab[2,I]=dec
endfor
CLOSE , 1
print,FORMAT=FMT,ttab
RETURN,ttab
end

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Readf
Next Topic: PLOT x and y ranges

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

Current Time: Fri Oct 10 11:39:36 PDT 2025

Total time taken to generate the page: 1.51985 seconds