Creating netCDF files: How can I set the order of the dimensions in a field?
Afficher commentaires plus anciens
I have created a netCDF file with 3 dimensions (dim1,dim2,dim3) and a field that is defined on the (dim1,dim2,dim3) space. ncdump gives me
NetCDF-3 Classic myfile.nc {
dimensions:
dim1 = 12 ;
dim2 = 96 ;
dim3 = 14 ;
variables:
// Preference 'PRESERVE_FVD': false,
// dimensions consistent with ncBrowse, not with native MATLAB netcdf package.
single dim1(dim1), shape = [12]
single dim2(dim2), shape = [96]
int32 dim3(dim3), shape = [14]
single field(dim3,dim2,dim1), shape = [14 96 12]
How can I set the order of the dimensions on which the field is defined, i.e. so that ncdump will give me
single field(dim1,dim2,dim3), shape = [12 96 14]
? This is what I run for creating the file:
file='infile.nc';
dim2 = nc_varget ( file, 'dim2' );
dim3 = nc_varget ( file, 'dim3' );
field = nc_varget ( file, 'field' );
vardata_dim1 = [1 2 3 4 5 6 7 8 9 10 11 12];
vardata_dim2 = dim2;
vardata_dim3 = dim3;
vardata_field = field;
ncid = netcdf.create('myfile.nc','NC_WRITE');
dim_dim1 = netcdf.defDim(ncid,'dim1',12);
dim_dim2 = netcdf.defDim(ncid,'dim2',96);
dim_dim3 = netcdf.defDim(ncid,'dim3',14);
varID_dim1 = netcdf.defVar(ncid,'dim1','float',dim_dim1);
varID_dim2 = netcdf.defVar(ncid,'dim2','float',dim_dim2);
varID_dim3 = netcdf.defVar(ncid,'dim3','int',dim_dim3);
varID_field = netcdf.defVar(ncid,'field','float',[dim_dim1 dim_dim2 dim_dim3]);
netcdf.endDef(ncid);
netcdf.putVar(ncid,varID_dim1,vardata_dim1);
netcdf.putVar(ncid,varID_dim2,vardata_dim2);
netcdf.putVar(ncid,varID_dim3,vardata_dim3);
netcdf.putVar(ncid,varID_field,vardata_field);
netcdf.close(ncid)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Denoising and Compression dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!