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

Home » Public Forums » archive » Formatted read of text file
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: Formatted read of text file [message #9293 is a reply to message #9154] Wed, 11 June 1997 00:00 Go to previous message
Harald Frey is currently offline  Harald Frey
Messages: 41
Registered: March 1997
Member
Matt Cheselka wrote:
>
> I have a file that contains row and column data like the following:
>
> # I E E_conv E_bl E_saa Resid_RMS
> # 0 3.512799e-05 3.512799e-05 0.000000e+00 0.000000e+00 3.512799e-05
> 1 1.445887e-05 1.445921e-05 0.000000e+00 0.000000e+00 1.445921e-05
> 2 7.363944e-06 7.364333e-06 0.000000e+00 0.000000e+00 7.364333e-06
> .
> .
> .
>
> So my question is a two-parter.
>
> First, how to I skip the first two lines of this file?
>
> Second, what is proper way to do a formatted read of each of the 6 columns in
> the remaining rows? I would like to have each column value put into its
> own array so I can then plot/print out each column individually.
>
> My guess is that I have to use and OPENR first to open the file, but that
> may not even be the best way to do it.
>

; -----------------------------------------------------------
pro read_formatted_file

file_name='test.dat' ; change if you want

dummy=' '
openr,unit,file_name,/get_lun
readf,unit,dummy,format='(/a20)'
print,dummy ; only to check the result of ; readf

on_ioerror,io_error
a=fltarr(5) ; define input
num=0
numb_of_lines=2
numb=intarr(numb_of_lines)
array=fltarr(5,numb_of_lines) ; define result

; if you don't know the number of lines you can also use the ;
"while" command
for i=0,numb_of_lines do begin
readf,unit,num,a,format='(i2,5g13.6)'
array(*,i)=a
endfor

io_error:
plot_io,array(0,*)

end
; ----------------------------------------------------

Harald Frey
Space Sciences Laboratory
University of California
Berkeley, CA 94720
hfrey@ssl.berkeley.edu
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Image Object Scaling Bug
Next Topic: Matlab <--> PV-Wave ?

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

Current Time: Wed Oct 08 19:20:30 PDT 2025

Total time taken to generate the page: 0.00445 seconds