Re: IDL to write GrADS netCDF (SDF) [message #77609] |
Fri, 16 September 2011 07:01  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Rich Bantges writes:
> 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).
The COARDS standards can provide endless hours of
fun as you argue with your colleagues about what
they actually *mean*, but they do have to be followed,
apparently.
One of the standards has to do with the Order of Dimensions,
which apparently is Time, Latitude, Longitude. I can't test
this, because I don't have the data, but it seems to me
your variable dimensions are [lon,lat]. You might check
to see if that is causing a problem.
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.")
|
|
|
|
Re: IDL to write GrADS netCDF (SDF) [message #77624 is a reply to message #77623] |
Thu, 15 September 2011 08:15   |
msienkiewicz
Messages: 8 Registered: October 2000
|
Junior Member |
|
|
On Sep 15, 4:51 am, Rich Bantges <rbant...@gmail.com> wrote:
> On Sep 14, 8:47 pm, Brian Wolven <brian.wol...@gmail.com> wrote:
>
>> I'd suggest looking at the example in the IDL documentation for NCDF_VARPUT, leaving out some of the "extra" stuff in the middle where they rename a dimension, etc. That example has all of the basic commands.
>
> Hi Brian,
>
> Thanks, but when I follow that example (without the dimension etc.)
> GrADS reports:
> ga-> sdfopen test_grads_file.nc
> Scanning self-describing file: test_grads_file.nc
> gadsdf: SDF file has no discernable X coordinate.
>
> If you could paste an example that does work, that would be great.
>
> Rich
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.
|
|
|
|
|
Re: IDL to write GrADS netCDF (SDF) [message #77708 is a reply to message #77609] |
Fri, 16 September 2011 07:11  |
Kenneth P. Bowman
Messages: 585 Registered: May 2000
|
Senior Member |
|
|
In article <MPG.28dd04a587f2cf7698980e@news.giganews.com>,
David Fanning <news@dfanning.com> wrote:
> One of the standards has to do with the Order of Dimensions,
> which apparently is Time, Latitude, Longitude. I can't test
> this, because I don't have the data, but it seems to me
> your variable dimensions are [lon,lat]. You might check
> to see if that is causing a problem.
Be careful. I don't follow the COARDS standard myself (never
found a need to), but they are probably referring to the
C-language convention, where the last index varies fastest.
This is what you see when you use ncdump. You need to remember
to reverse the apparent order for IDL and Fortran.
Ken Bowman
|
|
|
Re: IDL to write GrADS netCDF (SDF) [message #84627 is a reply to message #77623] |
Fri, 16 September 2011 01:33  |
Rich Bantges
Messages: 3 Registered: September 2011
|
Junior Member |
|
|
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
|
|
|