Sangwoo wrote:
>
> Hi everyone!
>
> I'm gonna read a NCDF file. It may contain several variables within
> itself. When I extract a variable named "image", the procedure is as
> follows:
>
> cid=ncdf_open('test.nc')
> vid=ncdf_varid(cid,'image')
> ncdf_varget,cid,vid,image
>
> But suppose I don't know the name of each variable unfortunately. Is
> there any way to figure out the details of the included
> variables(name, dimension, etc.)? The second command fails when I put
> a wrong variable. And is there any way to read the included variables
> all at once? (something like /all keyword)
>
> I wonder if there's any way to figure out all details of the included
> variables from an NCDF file directly.
Yes, there is. For me at least, that's the point of netCDF.
I have a simple-minded read_ncdf() function that may do what you want. You can read all
the variable data by default:
IDL> error_status=read_ncdf('sndr_g12.EmisCoeff.nc',x,/quiet)
% Compiled module: READ_NCDF.
% Compiled module: IS_NCDF.
% Loaded DLM: NCDF.
IDL> help, x, /struct
** Structure <82417b4>, 10 tags, length=37856, data length=37856, refs=1:
RELEASE LONG 2
VERSION LONG 2
THETA_OFFSET DOUBLE 0.10000000
THETA_MAX DOUBLE 65.100000
NCEP_SENSOR_ID LONG Array[18]
WMO_SATELLITE_ID
LONG Array[18]
WMO_SENSOR_ID LONG Array[18]
SENSOR_CHANNEL LONG Array[18]
WIND_SPEED DOUBLE Array[13]
EMIS_COEFFICIENTS
DOUBLE Array[4, 5, 18, 13]
Or just the data you want:
IDL> error_status=read_ncdf('sndr_g12.EmisCoeff.nc',x,variable_li st=['Wind_Speed'],/quiet)
IDL> help, x, /struct
** Structure <82468d4>, 1 tags, length=104, data length=104, refs=1:
WIND_SPEED DOUBLE Array[13]
Or just the global attributes:
IDL> error_status=read_ncdf('sndr_g12.EmisCoeff.nc',x,/global_att ributes,/quiet)
IDL> help, x, /struct
** Structure <8240f34>, 7 tags, length=84, data length=84, refs=1:
WRITE_MODULE_HISTORY
STRING '$Id: write_emiscoeff_netcdf.pro,v 2.0 2003/06'...
CREATION_DATE_AND_TIME
STRING 'Tue Sep 16 16:53:38 2003'
TITLE STRING 'Emissivity fit coefficients for GOES-12 SOUND'...
HISTORY STRING '$Id: compute_emissivity_coefficients.pro,v 2.'...
SENSOR_NAME STRING 'SOUNDER'
PLATFORM_NAME STRING 'GOES-12'
COMMENT STRING 'Sensor emissivity created by Convolution:Spec'...
or all the variables and their attributes:
IDL> error_status=read_ncdf('sndr_g12.EmisCoeff.nc',x,/variable_a ttributes,/quiet)
IDL> help, x, /struct
** Structure <8241f2c>, 10 tags, length=38024, data length=38024, refs=1:
RELEASE STRUCT -> <Anonymous> Array[1]
VERSION STRUCT -> <Anonymous> Array[1]
THETA_OFFSET STRUCT -> <Anonymous> Array[1]
THETA_MAX STRUCT -> <Anonymous> Array[1]
NCEP_SENSOR_ID STRUCT -> <Anonymous> Array[1]
WMO_SATELLITE_ID
STRUCT -> <Anonymous> Array[1]
WMO_SENSOR_ID STRUCT -> <Anonymous> Array[1]
SENSOR_CHANNEL STRUCT -> <Anonymous> Array[1]
WIND_SPEED STRUCT -> <Anonymous> Array[1]
EMIS_COEFFICIENTS
STRUCT -> <Anonymous> Array[1]
IDL> help, x.emis_coefficients, /struct
** Structure <8240f3c>, 3 tags, length=37464, data length=37464, refs=2:
DATA DOUBLE Array[4, 5, 18, 13]
LONG_NAME STRING 'Emissivity model fit coefficients.'
UNITS STRING 'None.'
And you can use the tag_names routine to act on just the variables.
cheers,
paulv
--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
|