![]() |
Tutorial | |
|
Using IDL To Work With Fitted ACF DataOverviewThis tutorial shows you how to use the The libraries consist of functions written both in native IDL and functions that act as wrappers and use the Reading
|
pro readfitacf
; Open the fit index file and load it into the inx structure
openr,inp,'test.fitinx',/GET_LUN,/STDIO,/SWAP_IF_BIG_ENDIAN
s=FitLoadInx(inp,inx)
free_lun,inp
; Open the raw file for read only
inp=FitOpen('test.fitacf',/read)
; Search for a specific time in the file
s=FitSeek(inp,2002,12,19,0,30,10,inx,atme=atme)
while FitRead(inp,prm,fit) ne -1 do begin
print, prm.time.hr,prm.time.mt,prm.time.sc
plot,fit.v[0:prm.nrang-1]
stop
endwhile
free_lun,inp
end |
The file is opened using the call to FitOpen if successful, this function returns the logical unit number associated with the file.
The fitacf files can have an optional, associated index file that greatly speeds up searching for specific records. If this file is not available, then a much slower manual search is performed.
The read routine FitRead returns two structures, the first is the radar parameter block and the second is the fitted ACF data. The contents of these structures are documented in RFC #0020 and RFC #0022
fit FilesThe example program presented below does the simple task of reading records from a fit file and plots the lag-zero power measurements.
pro readfit
; Open the fit file
fitfp=OldFitOpen('test.fit','test.inx')
; Search for a specific time in the file
s=OldFitSeek(fitfp,2002,12,19,1,30,10,atme=atme)
while OldFitRead(fitfp,prm,fit) ne -1 do begin
print, prm.time.hr,prm.time.mt,prm.time.sc
plot,fit.v[0:prm.nrang-1]
stop
endwhile
s=OldFitClose(fitfp)
end
|
The file is opened using the call to OldFitOpen if successful, this function returns a structure containing the fit file pointer.
The fit file may have an associated index file that should be past as the second argument to OldFitOpen. The index file greatly speeds up searching for specific records, if the index file is not supplied a much slower manual search is performed.
When the file is finished with, you should call OldFitClose to close the file and to free up any memory resources used.
fitacf FilesThe program presented below is a simple extension to the read program that uses the FitWrite function to write the data to a new file.
pro writefitacf
; Open the fit index file and load it into the inx structure
openr,inp,'test.fitinx',/GET_LUN,/STDIO,/SWAP_IF_BIG_ENDIAN
s=FitLoadInx(inp,inx)
free_lun,inp
; Open the raw file for read only
inp=FitOpen('test.fitacf',/read)
out=FitOpen('test2.fitacf',/write)
; Search for a specific time in the file
s=FitSeek(inp,2002,12,19,0,30,10,inx,atme=atme)
while FitRead(inp,prm,fit) ne -1 do begin
print, prm.time.hr,prm.time.mt,prm.time.sc
s=FitWrite(out,prm,fit)
endwhile
free_lun,inp
free_lun,out
end
|
fit FilesWriting fit files is slightly more complicated as the file format includes a header record and each record has a record number and the data file has an associated index file.
irec and drec to track the data record number and the index record number. The OldFitWrite function returns the number of blocks required to write each record of fit data and this value should be added to drec. The header for the fit file is written using OldFitWriteHeader and the header for the index file is written using OldFitInxWriteHeader.
Once the index file has been written out, a call is made to OldFitInxClose to make sure that the index contains the start and end time of the file.
pro writefit
openw,out,'test2.fit',bufsize=0,/get_lun,/stdio
openw,inx,'test2.inx',bufsize=0,/get_lun,/stdio
fitfp=OldFitOpen('test.fit','test.inx')
irec=1L
drec=2L
dnum=0L
s=OldFitSeek(fitfp,2002,12,19,1,30,10,atme=atme)
while OldFitRead(fitfp,prm,fit) ne -1 do begin
print, prm.time.hr,prm.time.mt,prm.time.sc
tprm=prm
if (drec eq 2) then s=OldFitWriteHeader(out,prm,fit)
if (irec eq 1) then s=OldFitInxWriteHeader(inx,prm)
dnum=OldFitWrite(out,prm,fit)
s=OldFitInxWrite(inx,drec,dnum,prm)
drec+=dnum
irec++
endwhile
s=OldFitInxClose(inx,tprm,irec-1)
s=OldFitClose(fitfp)
free_lun,inx
free_lun,out
end
|
Unlike the read routines which use a structure as the file pointer, writing of fit files is done using standard IDL logical unit numbers.
| Back |