[Thread Prev][Thread Next][Index]

Re: [ferret_users] Looping over multile HDF files.



Hello C. Shaji,
What I would do is to write a script that does all the operations you want to do on each file. Then call this from another script, sending the month number, or perhaps the file path as an argument. You could also send in arguments with variable names, directory paths, and so on, if those things are not going to be the same

 ! script write_file.jnl
 ! open a monthly HDF file and re-write it as a binary file
 ! Argument: month number

 ! symbol nmon with month, e.g. 01, or 11
 define symbol nmon = $1
 if `($nmon) LT 10` THEN define symbol nmon = 0$1

 use
"http://data.nodc.noaa.gov/cgi-bin/nph-dods/pathfinder/Version5.0_Climatologies/Monthly/Combined/month($nmon)_combined.hdf"

 !Shows the dataset variables.

 show data
 show grid

 SHOW GRID CLIM_SST

 ! To get the axis information
 SHOW AXIS LONGITUDE
 SHOW AXIS LATITUDE

 SET MEMORY/SIZ=416

list/format=stream/file="/work/data/sst/pf/data/monthly/bin/month($nmon)_combined.bin" clim_sst

 let lat = Y[GY=clim_sst]
 let lon = X[GX=clim_sst]

list/format=stream/file="/work/data/sst/pf/data/monthly/bin/month($nmon)_combined_lat.grd" lat

list/format=stream/file="/work/data/sst/pf/data/monthly/bin/month($nmon)_combined_lon.grd" lon

  ! End of script write_file.jnl

Then call this script for each month:

 ! script all_months.jnl
 repeat/range=1:12:1/name=m (go write_file `m`)

Or, if for instance you found that some files didn't exist, this could also be called without a loop. It's easy to use an editor to make a list of commands:

  go write_file 1
  go write_file 3
  go write_file 4
  go write_file 5
  go write_file 6
  go write_file 9
...

Ansley

Dr.C.Shaji wrote:
Dear ferret users,
I am remotely accessing 12 HDF files one by one. Finally I would like to
write the data as binary in another 12 files. How can I do this using a
file loop.

1) For example, for a single file, I use the following commands to achieve
this.

use
"http://data.nodc.noaa.gov/cgi-bin/nph-dods/pathfinder/Version5.0_Climatologies/Monthly/Combined/month01_combined.hdf";
!January.
!Shows the dataset variables.

show data
show grid

SHOW GRID CLIM_SST

! To get the axis information
SHOW AXIS LONGITUDE
SHOW AXIS LATITUDE

SET MEMORY/SIZ=416

list/format=stream/file="/work/data/sst/pf/data/monthly/bin/month01_combined.bin"
 clim_sst !January

let lat = Y[GY=clim_sst]
let lon = X[GX=clim_sst]

list/format=stream/file="/work/data/sst/pf/data/monthly/bin/month01_combined_lat.grd"
 lat

list/format=stream/file="/work/data/sst/pf/data/monthly/bin/month01_combined_lon.grd"
 lon

2)
I want to access files such as month01_combined.hdf,
month02_combined.hdf,....month12_combined.hdf

Finally the binary files month??_combined.bin, month??_combined_lon.grd,
month??_combined_lon.grd have to be written in another directory.

Can someone suggest me some useful tips to do this in ferret?

Thanks in advance,
C. Shaji.





[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement