problems writing netcdf file with 3-d variable

Hello,
I am trying to write some data I have to a netcdf file. Here is the code:
st_num = 1:370;
year = 1895:2011;
month = 1:12;
% Open netCDF file.
ncid = netcdf.create('SPEI1.nc','NC_WRITE');
% Define the dimensions of the variable.
IDdimid = netcdf.defDim(ncid,'station_ID',length(st_num));
modimid = netcdf.defDim(ncid,'month',length(month));
yeardimid = netcdf.defDim(ncid,'year',length(year));
data_ids = ([IDdimid modimid yeardimid]);
data_ids
whos
yearID = netcdf.defVar(ncid,'year','double',yeardimid);
moID = netcdf.defVar(ncid,'month','double',modimid);
stnumID = netcdf.defVar(ncid,'station_ID','double',IDdimid);
dataID = netcdf.defVar(ncid,'SPEI1','double',data_ids);
% Leave define mode and enter data mode to write data.
netcdf.endDef(ncid)
% Write data to variable.
netcdf.putVar(ncid,dataID,SPEI1);
netcdf.close(ncid);
My SPEI1 variable is a 117x12x370 double. The data that is written into SPEI1 is not in the correct location and much of the newly written data does not exist in my original SPEI1 Matlab variable.
When I dump the netcdf file all the dimensions seem to be as they should though...:
NetCDF SPEI1.nc {
dimensions:
station_ID = 370 ;
month = 12 ;
year = 117 ;
variables:
// Preference 'PRESERVE_FVD': false,
// dimensions consistent with ncBrowse, not with native MATLAB netcdf package.
double year(year), shape = [117]
double month(month), shape = [12]
double station_ID(station_ID), shape = [370]
double SPEI1(year,month,station_ID), shape = [117 12 370]
Do anyone have any suggestions for my problem?
Thanks, Dan

4 comentarios

Walter Roberson
Walter Roberson el 8 de Nov. de 2011
If you read the new file back in, then does the data portion compare as equal to what was written?
Dan
Dan el 8 de Nov. de 2011
No, that's the problem. I can't recognize the data when I read it back in. I have no idea how or why the data was rearranged in the writing process...
Dan
Dan el 8 de Nov. de 2011
I found a fix for the problem, at the beginning of script:
SPEI1 = permute(SPEI1,[3 2 1])
I'm sure exactly why I need to do this, but it works!
Ashish Uthama
Ashish Uthama el 8 de Nov. de 2011
Dan, if data_ids = ([IDdimid modimid yeardimid]); i.e the variable dimensions ought to match the order of the defined dimensions (370x12x117).

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Preguntada:

Dan
el 8 de Nov. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by