Re: Implied do loops in IDL [message #2238] |
Thu, 16 June 1994 06:56 |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
leic@eiscata.ag.rl.ac.uk (University of Leicester) writes:
> I am pretty sure that SunOS also uses a 4byte prefix/postfix byte
> count. The only real way to be sure is to use od to get a dump
> of the first few records of the file and see what is in there.
Yes, it does.
Bill Thompson
|
|
|
Re: Implied do loops in IDL [message #2245 is a reply to message #2238] |
Wed, 15 June 1994 10:15  |
leic
Messages: 2 Registered: June 1994
|
Junior Member |
|
|
It is possible to read FORTRAN binary as normal (ie. without the
/F77_unformatted keyword) provided you know how FORTRAN handles
the unformatted records.
I have to do this with data I use which is output in exactly the
same implied DO loop way as is your data.
On our system (SGI IRIX 5) FORTRAN prepends and appends 4 bytes
to each record. This is a long word byte count of the record
length.
To read this data back in use the following algorithm :
; Open the file as a normal data file:
OPENR, lun, /GET_LUN, file
; Define a long word byte count to read at the start and end of
; each record:
byte_count = 1L
; To read a single record, first read the byte count, then create
; an array of the necessary data type and size:
READU,lun, byte_count
data = LONARR(byte_count/4)
; Finally, read the array and the terminating byte count:
READU,lun, data,byte_count
I am pretty sure that SunOS also uses a 4byte prefix/postfix byte
count. The only real way to be sure is to use od to get a dump
of the first few records of the file and see what is in there.
Hope this helps.
|
|
|
Re: Implied do loops in IDL [message #2249 is a reply to message #2245] |
Tue, 14 June 1994 07:33  |
landers
Messages: 45 Registered: May 1993
|
Member |
|
|
In article <tonym.1121921004A@llyene.jpl.nasa.gov>, tonym@lurleen.jpl.nasa.gov (Tony Mannucci) writes:
|> In FORTRAN, the file was written as:
|>
|> write(unit) n, (data(i), i = 1, n)
|>
|> and read as:
|>
|> read(unit) n, (data(i), i=1, n)
you could do something like this:
openr, unit,/Get_Lun, filename, /f77_Unformatted
; ....
while( reading_these_lines) do begin
file = fstat( unit ) ; remember where record begins
n = 0L ; make sure you read the right data type
readu, unit, n ; read the data count
data = fltarr( n ) ; make data array
point_lun, unit, file.cur_ptr ; rewind to the beginning of the record
readu, unit, n, data ; re-read the record, with data
; ... process data ...
end
;Dave
|
|
|
Re: Implied do loops in IDL [message #2259 is a reply to message #2249] |
Tue, 14 June 1994 00:53  |
knipp
Messages: 68 Registered: January 1993
|
Member |
|
|
In article 1121921004A@llyene.jpl.nasa.gov, tonym@lurleen.jpl.nasa.gov (Tony Mannucci) writes:
> I have a need for implied do loops in IDL but they appear to be unsupported.
> My need occurs when reading data from a file.
>
> Here is an example:
>
> In FORTRAN, the file was written as:
>
> write(unit) n, (data(i), i = 1, n)
>
> and read as:
>
> read(unit) n, (data(i), i=1, n)
>
> In this example, n is not generally fixed for every file record.
> It seems that the only way to read such files is with implied do's.
>
> Note that I am trying to avoid calling a FORTRAN routine at this
> point. Does anyone know if "native" IDL can handle such reads
> and writes?
>
> Tony Mannucci Jet Propulsion Laboratory
> tonym@lurleen.jpl.nasa.gov 4800 Oak Grove Drive
> M/S 238-600
> Voice: (818)354-1699 Fax: (818)393-4965 Pasadena, CA 91109
If you know the n (and type of your data) for each record, try
the following:
; (assuming your data is of type DOUBLE)
openr, uni, file, /get_lun
line = ''
for i=0, n_lines-1l do begin
readf, uni, line
data = dblarr(n(i))
sdowf = something_dependent_of_write_format
; p.e. if written with f8.3, then sdowf = 8
for j=0, n(i)-1 do $
data(j) = double(strmid(line, j, j + sdowf
; ... processing
endfor
free_lun, uni
I do not know if this helps - and it also seems to be quite slow,
Karlheinz
____________________________________________________________ __________________
__ ____ __
/ // _ \ / / Karlheinz Knipp phone: +49 511 - 762 4922
/ // /_/ // / University of Hannover fax: +49 511 - 762 2483
/ // ____// / Institute for Photogrammetry
/ // / / / Nienburger Str.1
/_//_/ /_/ FRG 30167 Hannover e-mail: knipp@ipi.uni-hannover.de
|
|
|
Re: Implied do loops in IDL [message #2260 is a reply to message #2259] |
Tue, 14 June 1994 02:25  |
sjt
Messages: 72 Registered: November 1993
|
Member |
|
|
Tony Mannucci (tonym@lurleen.jpl.nasa.gov) wrote:
: I have a need for implied do loops in IDL but they appear to be unsupported.
: My need occurs when reading data from a file.
: Here is an example:
: In FORTRAN, the file was written as:
: write(unit) n, (data(i), i = 1, n)
: and read as:
: read(unit) n, (data(i), i=1, n)
: In this example, n is not generally fixed for every file record.
: It seems that the only way to read such files is with implied do's.
: Note that I am trying to avoid calling a FORTRAN routine at this
: point. Does anyone know if "native" IDL can handle such reads
: and writes?
Probably not exactly as given as array elements and subranges are
considered to be expressions and are thus passed by value. However if
you can modify the fortran program to use:
write(unit) n
write(unit) (data(i), i=1,n)
then it becomes trivial:
readu, unit, n
data=fltarr(n)
readu, unit, data
If you can't modify the fortran then the bset I can think of in 2 minutes is:
point_lun, -unit, posit ; Get the current location
readu, unit, n
data=fltarr(n)
point_lun, unit, posit ; Restore file pointer.
readu, n,data
N.B. Remember fortran unformatted is a nasty format on Unix systems which
needs the /f77_unformatted key in the open.
: Tony Mannucci Jet Propulsion Laboratory
: tonym@lurleen.jpl.nasa.gov 4800 Oak Grove Drive
: M/S 238-600
: Voice: (818)354-1699 Fax: (818)393-4965 Pasadena, CA 91109
--
James Tappin, School of Physics & Space Research
University of Birmingham
sjt@xun8.sr.bham.ac.uk
"If all else fails--read the instructions!"
O__
-- \/`
|
|
|