nc_dump.m
is an m-file that can be used to interrogate
the structure of a netCDF file or OPeNDAP dataset. It's about the first command
that I use when I need to look at a new dataset.
If you have R2008b or higher, try this
nc_dump('example.nc')
netCDF example.nc { dimensions: x = 50 ; y = 50 ; z = 5 ; t = UNLIMITED ; (0 currently) variables: // Preference 'PRESERVE_FVD': true, // dimensions consistent with native MATLAB netcdf package, not with ncBrowse. double avagadros_number([]), shape = [1] :description = "this variable has no dimensions" int16 temperature(x), shape = [50] :scale_factor = 1.8 :add_offset = 32 :units = "degrees_fahrenheit" :description = "F = 9/5*C + 32" single peaks(x,y), shape = [50 50] :description = "z = peaks(50);" int32 time_series(z,t), shape = [5 0] :description = "this variable has an unlimited dimension" //global attributes: :creation_date = "09-Jun-2008" }
So you can see that there are 4 variables and 4 dimensions in the example file. The output looks a lot like the output of Unidata's ncdump command, although it is not identical.
You might have noticed the bit about the PRESERVE_FVD preference... SNCTOOLS has a few preferences (you've already encountered the USE_JAVA preference) that control its operation. The PRESERVE_FVD preference controls whether the data is transposed or not and how dimensions are displayed. MATLAB dimensions start with the fastest-varying first and end with with slowest-varying (same as Fortran). The C language is the reverse, with the slowest-varying dimension coming first, and the fastest-varying dimension last. In the example above, the peaks variable lists the x dimension first (fastest-varying) and then the y dimension.
In the earliest days of mexcdf, this was not the case. The data was always transposed so that the slowest-varying dimension of the variable AS IT EXISTS IN THE FILE would come first, and the fastest-varying dimension of the variable AS IT EXISTS IN THE FILE came last. One can force SNCTOOLS to do this by resetting the PRESERVE_FVD preference to false.
setpref('SNCTOOLS','PRESERVE_FVD',false); nc_dump('example.nc');
netCDF example.nc { dimensions: x = 50 ; y = 50 ; z = 5 ; t = UNLIMITED ; (0 currently) variables: // Preference 'PRESERVE_FVD': false, // dimensions consistent with ncBrowse, not with native MATLAB netcdf package. double avagadros_number([]), shape = [1] :description = "this variable has no dimensions" int16 temperature(x), shape = [50] :scale_factor = 1.8 :add_offset = 32 :units = "degrees_fahrenheit" :description = "F = 9/5*C + 32" single peaks(y,x), shape = [50 50] :description = "z = peaks(50);" int32 time_series(t,z), shape = [0 5] :description = "this variable has an unlimited dimension" //global attributes: :creation_date = "09-Jun-2008" }
You can see now that the dimensions have been reverses. Which order you prefer is up to you, but it's up to you to set the preference correctly. For the remainder of this tutorial, it is assumed that PRESERVE_FVD is set to true.
And finally, try an OPeNDAP data set available at Unidata.
today = datestr(floor(now),'yyyymmdd'); url = ['http://motherlode.ucar.edu:8080/thredds/dodsC/satellite/CTP/SUPER-NATIONAL_1km/current/SUPER-NATIONAL_1km_CTP_',today,'_0000.gini']; nc_dump ( url )
URL http://motherlode.ucar.edu:8080/thredds/dodsC/satellite/CTP/SUPER-NATIONAL_1km/current/SUPER-NATIONAL_1km_CTP_20100628_0000.gini { dimensions: time = 1 ; x = 1536 ; y = 1008 ; variables: // Preference 'PRESERVE_FVD': true, // dimensions consistent with native MATLAB netcdf package, not with ncBrowse. double time(time), shape = [1] :long_name = "time since base date" :_CoordinateAxisType = "Time" :units = "msecs since 1970-01-01T00:00:00Z" double x(x), shape = [1536] :long_name = "projection x coordinate" :units = "km" :_CoordinateAxisType = "GeoX" double y(y), shape = [1008] :long_name = "projection y coordinate" :units = "km" :_CoordinateAxisType = "GeoY" char Stereographic([]), shape = [1] :grid_mapping_name = "stereographic" :longitude_of_projection_origin = -105 :latitude_of_projection_origin = 90 :scale_factor_at_projection_origin = 0.933013 :_CoordinateTransformType = "Projection" :_CoordinateAxes = "x y " int8 CTP(x,y,time), shape = [1536 1008 1] :_Unsigned = "true" :_CoordinateAxes = "x y time" :long_name = "Cloud Top Pressure or Height" :units = "N/A" :_missing_value = 255 s :scale_factor = 1 s :add_offset = 0 s //global attributes: :Conventions = "_Coordinates" :source_id = 1 b :entity_id = 6 b :sector_id = 9 b :phys_elem = 27 b :time_coverage_start = "2010-06-28T00:00:00" :time_coverage_end = "2010-06-28T00:00:00" :ProjIndex = 5 b :ProjName = "POLARSTEREOGRAPHIC" :NX = 1536 d :NY = 1008 d :Lov = -105 :DxKm = 7.9465 :DyKm = 7.9465 :ProjCenter = 1 d :Latin = 0 :title = "Composite" :summary = "Gridded Cloud Top Pressure or Height" :id = "Supernational" :keywords_vocabulary = "CTP" :cdm_data_type = "GRID" :standard_name_vocabulary = "Cloud Top Pressure or Height" :creator_name = "UNIDATA" :creator_url = "http://www.unidata.ucar.edu/" :naming_authority = "UCAR/UOP" :geospatial_lat_min = 7.838100 f :geospatial_lat_max = 79.760857 f :geospatial_lon_min = -141.027405 f :geospatial_lon_max = -32.417683 f :imageResolution = 1 b :compressionFlag = 0 b }
So you can see that the m-file nc_dump.m
basically does the
same thing as ncdump
of the netCDF source distribution.