On Sep 15, 4:33 pm, David Fanning <n...@dfanning.com> wrote:
> msienkiewicz writes:
>> Rich, it sounds like the netCDF files that you are creating are not
>> COARDS compliant. Maybe you could try using 'xdfopen' in GrADS
>> (http://www.iges.org/grads/gadoc/gradcomdxdfopen.html) and use a data
>> descriptor file to help GrADS interpret your file.
>
> If it is just a COARDS compliant file you need to
> create, I believe I know how to do that. If you
> send me the file you are creating, I could have
> a quick look for you.
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>
Hi David,
Thanks again for your offer of help. Appended below is the IDL code
I've written that essentially restores and IDL save file and then
attempts to write them in a GrADS compatible netCDF file - this works
ok, but if I try and make "vid = NCDF_VARDEF(id, 'MEAN_AOD', [zid,
xid, yid], /FLOAT)" GrADS with the sdfopen command won't read the
variables (obviously making the mean_aod a 3D array).
Many thanks,
Rich
; Program to read in the IDL save file containing the AODs
; and then write these out in GrADS compatible NetCDF format
;
; AUTHOR: R Bantges
; Date: 5 Sept 2011
; VERSION 1: Original
;
; DEPENDENCIES: [1] Called from convert_idl_grads.pro
;
; INPUTS: [1] Requires the filename and various definitions from the
calling routine
;
; NOTES: [1] Region is defined for the KAUST specific project (25W to
65E, by 0 to 50N)
PRO write_grads_netcdf
; Restore the IDL file
; Restored arrays will be: frac_ir[days, frac, nlon, nlat] - frac
refers to the number of pixels in bin (0.01) is 0th index
; mean_aod055_ir[days, frac, nlon, nlat] -
the mean is the mean over the bin
; nir - nir is the number of
contributing pixels
; sd_aod055_ir - standard deviation of
mean
RESTORE, '/work/bantges/dust_processing/aod_output/res01/2009/02/
seviri_aod_200902_0800_res01.sav'
; Determine number of days
ndays = N_ELEMENTS(mean_aod055_ir[*,0,0,0])
z = 1 + INDGEN(ndays)
nz = ndays
; Temporary test (just select a single day, ideally want
REFORM(mean_aod055_ir[*,0,0,*]) and similarly for sd_aod055_ir)
mean_aod = REFORM(mean_aod055_ir[0,0,*,*])
sd_aod = REFORM(sd_aod055_ir[0,0,*,*])
; Base the output_filename on the input filename
output_filename = '/work/bantges/test_aod.nc'
; Define the standard longitude and latitude
nx = 900 ; Number of 'x' coordinates (longitude)
ny = 500 ; Number of 'y' coordinates (latitude)
xmin = -25. ; Minimum longitude
xmax = 65. ; Maximum longitude
dx = (xmax - xmin)/(nx - 1) ; Longitude spacing
x = xmin + dx*FINDGEN(nx) ; Compute x-coordinates
ymin = 0.0 ;Minimum latitude
ymax = 50.0 ;Maximum latitude
dy = (ymax - ymin)/(ny - 1) ; Latitude spacing
y = ymin + dy*FINDGEN(ny) ; Compute y-coordinates
; Now convert to netCDF
PRINT,'Creating netCDF..'
; Open the a new netCDF file
id = NCDF_CREATE(output_filename, CLOBBER = clobber) ; Create
netCDF output file
; Define the dimensions
xid = NCDF_DIMDEF(id, 'XAX1D', nx) ; Define x-dimension
(longitude)
yid = NCDF_DIMDEF(id, 'YAX1D', ny) ; Define y-dimension
(latitude)
zid = NCDF_DIMDEF(id, 'ZAX1D', nz) ; Define z-dimension (day
of month)
; Define the variables
vid = NCDF_VARDEF(id, 'XAX1D', xid, /FLOAT) ; Define longitude
variable
vid = NCDF_VARDEF(id, 'YAX1D', yid, /FLOAT) ; Define latitude
variable
vid = NCDF_VARDEF(id, 'ZAX1D', zid, /SHORT) ; Define day variable
vid = NCDF_VARDEF(id, 'MEAN_AOD', [xid, yid], /FLOAT) ; Define
aod_055 variable
vid = NCDF_VARDEF(id, 'SD_AOD', [xid, yid], /FLOAT) ; Define
aod_055 variable
; Assign attributes to the variables
NCDF_ATTPUT, id, 'XAX1D', 'units', 'degrees_east' ;Write longitude
units attribute
NCDF_ATTPUT, id, 'YAX1D', 'units', 'degrees_north' ;Write latitude
units attribute
NCDF_ATTPUT, id, 'ZAX1D', 'units', 'none' ;Write latitude
units attribute
NCDF_ATTPUT, id, 'MEAN_AOD', 'units', 'none' ;Write pressure units
attribute
NCDF_ATTPUT, id, 'SD_AOD', 'units', 'none' ;Write pressure units
attribute
NCDF_CONTROL, id, /ENDEF ;Exit define mode
NCDF_VARPUT, id, xid, x ;Write longitude to file
NCDF_VARPUT, id, yid, y ;Write latitude to file
NCDF_VARPUT, id, zid, z ;Write days to file
NCDF_VARPUT, id, 'MEAN_AOD', mean_aod ; Write mean AOD to file
NCDF_VARPUT, id, 'SD_AOD', sd_aod ; Write STDDEV AOD to file
NCDF_CLOSE, id ; Close netCDF output file
STOP
END
|