필터 지우기
필터 지우기

dimensions of opened NetCDF files

조회 수: 5 (최근 30일)
Christoph
Christoph 2012년 10월 22일
답변: Odontungalag Dorjsuren 2015년 4월 28일
Hi,
I frequently use NetCDF files to load data in Matlab:
ncload mydata.nc; for a quick open of new files
nc_varget(); to get specific variables
Now, I changed to a new workplace and found here the handling with
ncid = netcdf.open('myfile.nc','nowrite');
varid = netcdf.reqvarid(ncid,'variable');
data = netcdf.getVar(ncid,varid);
This works, but the dimension is changed: While ncload loads the variable correctly as e.g. 12 x 40 x 180 x 90 (as described in the NetCDF file, ncdump),
with netcdf.getVar I get a variable of size 90 x 180 x 40 x12, which is quite inconvenient. Is this a usual behavior of netcdf.xxx or is there something I didn't recognize?
I appreciate any information, Christoph

채택된 답변

John
John 2012년 10월 23일
When you shell out to run ncdump, you are running a C executable that is linked into the netcdf library. Since it is written in C, it used row-major order, so "time_counter" becomes the first dimension listed as it varies the slowest.
MATLAB is column-major order, so "time_counter" gets listed last, since that's where the slowest-varying dimension would be.
So, no, no mistake, it's just fallout from row-major-order vs. column-major-ordering. Also, since you are using NC_VARGET, check the snctools README, there's a discussion of the issue there.
  댓글 수: 1
Christoph
Christoph 2012년 10월 24일
John, Thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

John
John 2012년 10월 22일
Hi Christoph,
The "ncload" function referred to is part of the "netcdf toolbox", which is a very old and unsupported piece of software. It transposes the data when it reads and writes, whereas the native netcdf.getVar and putVar functions do not transpose, thus preserving the ordering of the data.
  댓글 수: 1
Christoph
Christoph 2012년 10월 23일
편집: Christoph 2012년 10월 23일
Hi John, thanks for your reply. Since ncload is that old I would assume there's trouble with that, but the opposite is the case:
!ncdump -h run10/BTST25_1m_19900101_19901231_grid_T.nc
netcdf BTST25_1m_19900101_19901231_grid_T {
dimensions:
x = 454 ;
y = 512 ;
deptht = 64 ;
time_counter = UNLIMITED ; // (12 currently)
tbnds = 2 ;
variables:
[...]
float votemper(time_counter, deptht, y, x) ;
votemper:units = "degC" ;
votemper:standard_name = "temperature" ;
votemper:_FillValue = 9.96921e+36f ;
votemper:coordinates = "time_counter deptht nav_lat nav_lon" ;
Then, if I use
ncload run10/BTST25_1m_19900101_19901231_grid_T.nc;
size(votemper)
ans =
12 64 512 454
Same for nc_varget:
clear
ncfile = 'run10/BTST25_1m_19900101_19901231_grid_T.nc';
data = nc_varget(ncfile,'votemper');
size(data)
ans =
12 64 512 454
However, with netcdf.xxx I get the following:
clear
ncid=netcdf.open('run10/BTST25_1m_19900101_19901231_grid_T.nc','nowrite');
varid=netcdf.inqVarID(ncid,'votemper');
data = netcdf.GetVar(ncid,varid);
size(data)
ans =
454 512 64 12
I don't know, whether this is due to a mistake of how I handle the ncfile, or some bug in the NetCDF package used here? Kindly appreciate further ideas or comments... thanks.
Christoph

댓글을 달려면 로그인하십시오.


Odontungalag Dorjsuren
Odontungalag Dorjsuren 2015년 4월 28일
HI. How to open data .nc

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by