comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » ncdf_varput for NetCDF coordinate axes
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
ncdf_varput for NetCDF coordinate axes [message #93744] Tue, 11 October 2016 15:35
MarioIncandenza is currently offline  MarioIncandenza
Messages: 231
Registered: February 2005
Senior Member
Hello IDL Wizards,

I wrote a routine to create a netCDF file, and I did it wrong:

; Create a new NetCDF file with the filename NCFILE
id = NCDF_CREATE(ncfilea, /CLOBBER)
<...>
; Create global attributes
NCDF_ATTPUT, id, /GLOBAL, 'COMMENT','Initial Implementation'
<...>
; Fill the file with default values:
NCDF_CONTROL, id, /FILL
; Create dimensions: CF convention is T,Z,Y,X
yid = NCDF_DIMDEF(id, 'y', sz[2]) ; Make dimensions.
xid = NCDF_DIMDEF(id, 'x', sz[1]) ; Make dimensions.
;create coordinates (1d variables for each DIMENSION)
latid = NCDF_VARDEF(id, 'Latitude', [yid], /FLOAT)
NCDF_ATTPUT, id, latid, 'standard_name', 'latitude_north'; CF
NCDF_ATTPUT, id, latid, 'long_name', 'latitude'; CF
NCDF_ATTPUT, id, latid, 'units', 'degrees_north'; CF convention
NCDF_ATTPUT, id, latid, 'axis', 'Y'; CF convention
lonid = NCDF_VARDEF(id, 'Longitude', [xid], /FLOAT)
NCDF_ATTPUT, id, lonid, 'standard_name', 'longitude_east'; CF
NCDF_ATTPUT, id, lonid, 'long_name', 'longitude'; CF
NCDF_ATTPUT, id, lonid, 'units', 'degrees_east'; CF convention
NCDF_ATTPUT, id, lonid, 'axis', 'X'; CF convention
<...>
; Put file in data mode:
NCDF_CONTROL, id, /ENDEF
; Input data for coordinate axes:
NCDF_VARPUT, id, yid, (findgen(540)/3.)-90+(1/6.); WRONG
NCDF_VARPUT, id, xid, (findgen(1080)/3.)-180+(1/6.); WRONG


Do you see the problem? The calls to VARPUT use XID|YID (from NCDF_DIMDEF) when they should be using LONID|LATID (from NCDF_VARDEF).

However, this incorrect code produces the correct result:

ncdump ncfilea:
netcdf ncfilea {
dimensions:
y = 540 ;
x = 1080 ;
variables:
float Latitude(y) ;
Latitude:standard_name = "latitude_north" ;
Latitude:long_name = "latitude" ;
Latitude:units = "degrees_north" ;
Latitude:axis = "Y" ;
float Longitude(x) ;
Longitude:standard_name = "longitude_east" ;
Longitude:long_name = "longitude" ;
Longitude:units = "degrees_east" ;
Longitude:axis = "X" ;
<...>
data:
Latitude = -89.83334, -89.5, -89.16667, -88.83334, -88.5, -88.16667,
-87.83334, -87.5, -87.16667, -86.83334, -86.5, -86.16667, -85.83334, <...>

Does anyone have an explanation for why this works? Is there magic related to the 'AXIS' attribute?

--Edward H.
[Message index]
 
Read Message
Previous Topic: Pixel positions passing trough a curve
Next Topic: IDL Beginner exercise help

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:51:31 PDT 2025

Total time taken to generate the page: 0.00381 seconds