Re: Reading fortran [message #45587 is a reply to message #45586] |
Tue, 20 September 2005 07:45   |
savoie
Messages: 68 Registered: September 1996
|
Member |
|
|
David Fanning <davidf@dfanning.com> writes:
> Andres writes:
>
>> Hi all,
>>
>> does somebody knows how to read this (fortran way)
>>
>> do 210 j=1,ngr2
>> write(10) real(rhoc(j)),
>> 2 real(psi1(j)),real(psi2(j)),real(psi3(j))
>> write(10) aimag(rhoc(j)),
>> 2 aimag(psi1(j)),aimag(psi2(j)),aimag(psi3(j))
>> 210 continue
>>
>> in IDL? I managed, but it takes forever for big "ngr2". This is what I
>> do:
>>
>> rhoc=fltarr(ng3)
>> psi1=fltarr(ng3) & psi2=fltarr(ng3) & psi3=fltarr(ng3)
>>
>> For i=0l,ng3-1l do begin
>> readu,lun,tmp1,tmp2,tmp3,tmp4
>> rhoc[i]=tmp1
>> psi1[i]=tmp2
>> psi2[i]=tmp3
>> psi3[i]=tmp4
>> Endfor
>>
>> but this takes a long time... Anybody knows a fast way?
>
> Here is an article for you to read:
>
> http://www.dfanning.com/tips/ascii_column_data.html
I don't think he's reading ascii data. I think he's reading a long list of
floats?
If the problem is that the data is in Fortran order, shouldn't he be reading
into a large array and then transposing?
how about (assuming ngr2 * 4 * sizeof(float) < memory available):
pro read_fortran
;; The data is 4 columns x ngr rows, but Fortran is stored row major.
data = make_array( ngr2, 4, /float )
openr, lun, "your_file_name", /GET_LUN
readu, lun, data
col_row_data = transpose( data )
rhoc = col_row_data[ 0, * ]
psi1 = col_row_data[ 1, * ]
psi2 = col_row_data[ 2, * ]
psi3 = col_row_data[ 3, * ]
end
Is this sort of what you're looking for? Completely untested of course.
Check out this fanning article for colum/row major information/headache.
http://www.dfanning.com/misc_tips/colrow_major.html
Hope this helps.
Matt
--
Matthew Savoie - Scientific Programmer
National Snow and Ice Data Center
(303) 735-0785 http://nsidc.org
|
|
|