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

Home » Public Forums » archive » Re: read an irregularly structured ascii file.
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: read an irregularly structured ascii file. [message #81537] Tue, 25 September 2012 14:46
Russell Ryan is currently offline  Russell Ryan
Messages: 122
Registered: May 2012
Senior Member
On Tuesday, September 25, 2012 4:38:48 PM UTC-4, wlandsman wrote:
> On Tuesday, September 25, 2012 2:35:44 PM UTC-4, (unknown) wrote:
>
>
>
>>
>
>> 221 0. 125893. 141254. 158489. 177828. 199527. 223873. 251189.
>
>>
>
>> 281839. 316229. 354815. 398109. 446686. 501190. 562344. 630961.
>
>
>
> Ah, the joy of reading a raw Kurucz model atmosphere file. ( I am embarrassed to have recognized these numbers. More ammunition for my wife to call me a geek.)
>
>
>
> I have an old program to read similar files which I give below. Unfortunately, my file format was not identical to yours, so you will need multiple changes. I'd work on it one step at a time. First try to read only the first array, and after you succeed go to the next portion of the file.
>
>
>
> --Wayne
>
>
>
> pro rdkur,file,teff,logg,flux,wave
>
>
>
> close,1
>
> openr,1,file
>
> str = ' '
>
> nmod = 221
>
> teff = fltarr(nmod)
>
> logg = fltarr(nmod)
>
> wave = fltarr(1221)
>
> f = fltarr(1221)
>
> flux = fltarr(1221,nmod)
>
> j = 0
>
> test = ' '
>
> while test ne "END" do begin
>
> readf,1,str
>
> test = strtrim(gettok(str,' '),2)
>
> endwhile
>
> readf,1,wave
>
> while not eof(1) do begin
>
> readf,1,str
>
> dum = gettok(str,' ')
>
> teff[j] = float(gettok(str,' '))
>
> dum = gettok(str,' ')
>
> logg[j] = float(gettok(str,' '))
>
> readf,1,f
>
> flux[0,j] = f
>
> readf,1,f
>
> j = j+1
>
> endwhile
>
> j = j-1
>
> flux = flux[*,0:j]
>
> teff= teff[0:j]
>
> logg = logg[0:j]
>
>
>
> return
>
> end

Wayne,

I'd hoped an astronomer would chime in. Don't feel bad, I was helping a friend debug a code that used these files, and I explained his code was working because I recognized the numbers....

It looks like I came up with something similar (ie. a bunch of calls to gettok). It's kinda slow, about 12 for my test file, but I think it's fairly robust to a changing file format. I'll play around with your ideas...

Thanks!
Russell
Re: read an irregularly structured ascii file. [message #81538 is a reply to message #81537] Tue, 25 September 2012 13:38 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Tuesday, September 25, 2012 2:35:44 PM UTC-4, (unknown) wrote:

>
> 221 0. 125893. 141254. 158489. 177828. 199527. 223873. 251189.
>
> 281839. 316229. 354815. 398109. 446686. 501190. 562344. 630961.

Ah, the joy of reading a raw Kurucz model atmosphere file. ( I am embarrassed to have recognized these numbers. More ammunition for my wife to call me a geek.)

I have an old program to read similar files which I give below. Unfortunately, my file format was not identical to yours, so you will need multiple changes. I'd work on it one step at a time. First try to read only the first array, and after you succeed go to the next portion of the file.

--Wayne

pro rdkur,file,teff,logg,flux,wave

close,1
openr,1,file
str = ' '
nmod = 221
teff = fltarr(nmod)
logg = fltarr(nmod)
wave = fltarr(1221)
f = fltarr(1221)
flux = fltarr(1221,nmod)
j = 0
test = ' '
while test ne "END" do begin
readf,1,str
test = strtrim(gettok(str,' '),2)
endwhile
readf,1,wave
while not eof(1) do begin
readf,1,str
dum = gettok(str,' ')
teff[j] = float(gettok(str,' '))
dum = gettok(str,' ')
logg[j] = float(gettok(str,' '))
readf,1,f
flux[0,j] = f
readf,1,f
j = j+1
endwhile
j = j-1
flux = flux[*,0:j]
teff= teff[0:j]
logg = logg[0:j]

return
end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: kernel density estimator routine
Next Topic: Re: Escaped Characters in string output

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

Current Time: Wed Oct 08 13:36:42 PDT 2025

Total time taken to generate the page: 0.00648 seconds