read variable lon and lat in group larvae in netcdf4 a.nc

23 views (last 30 days)
I want to read the lat and lon in the group larvae. Is there a way to read this with the buildin function ncread? A ncdump -h of the file a.nc is
ncdump -h a.nc
netcdf a {
dimensions:
lat = 335 ;
lon = 115 ;
level = 9 ;
variables:
float latitudes(lat, lon) ;
float longitudes(lat, lon) ;
// global attributes:
:grid_dimensions = 335L, 115L, 9L ;
group: ocean {
dimensions:
time = UNLIMITED ; // (1 currently)
reltime = 1 ;
variables:
int model_time(time, reltime) ;
float u_velocity(time, level, lat, lon) ;
float v_velocity(time, level, lat, lon) ;
float w_velocity(time, level, lat, lon) ;
float temperature(time, level, lat, lon) ;
float salinity(time, level, lat, lon) ;
// group attributes:
:time_step = 360L ;
:step = 1L ;
} // group ocean
group: larvae {
dimensions:
time = UNLIMITED ; // (1 currently)
reltime = 1 ;
npart = 441 ;
variables:
int model_time(time, reltime) ;
float lat(time, npart) ;
float lon(time, npart) ;
float depth(time, npart) ;
float total_body_burden(time, npart) ;
float mortality(time, npart) ;
float size(time, npart) ;
float weight(time, npart) ;
// group attributes:
:step = 1L ;
} // group larvae
}
  2 Comments
Ashish Uthama
Ashish Uthama on 28 Jan 2014
Also, you could try using NCDISP in MATLAB to get similar output as ncdump.

Sign in to comment.

Answers (1)

AJ von Alt
AJ von Alt on 20 Jan 2014
Edited: AJ von Alt on 20 Jan 2014
You can read a variable 'variablename' in a group '/groupname/' using '/groupname/variablename' as the argument for the varname field in the function ncread.
This code should produce the desired results for an input file 'ncfilename.nc':
lat = ncread( 'ncfilename.nc' , '/larvae/lat')

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!