问题
I have a 3 dimensional variable my_var
within a netcdf (original.nc) file (150x100x20000). I want to convert all of the elements within this variable from Celsius to Kelvin and then rewrite the variable's new values in a copy (test.nc) of the original file.
%make a copy of the file I’m editing (so I can write the new values to it later
copyfile('original.nc','test.nc');
%gets the attributes of the file
fileattrib('test.nc','+w');
%get id and opens the file for editing
ncid=netcdf.open('test.nc','WRITE');
%gets variable id and specifies the original variable for editing
varid=netcdf.inqVarID(ncid,'my_var');
my_var=ncread('original.nc','my_var');
%converts the data from celcius to kelvin
new_myvar=convtemp(my_var,'C','K');
netcdf.putVar(ncid,varid,new_myvar);
netcdf.close(ncid);
I can't get the new_myvar
variable to write over the original variable properly. The conversion to Kelvin is occurring correctly as far as I can tell: so the new_myvar
variable is correct.
I think it has to do with the indexing..but I'm not sure.
I tried:
[dimname0,dimlength0]=netcdf.inqDim(ncid,0);
[dimname1,dimlength1]=netcdf.inqDim(ncid,0);
[dimname2,dimlength2]=netcdf.inqDim(ncid,0);
netcdf.putVar(ncid,testid,new_myvar,[0,0,0],[dimlength0-1,dimlength1-1,dimlength2-1]);
thinking that this would specify how many dimensions (and how many elements (the count)) needed to be filled. But it's not rewriting the variable correctly. Can anyone see what I'm doing wrong?
来源:https://stackoverflow.com/questions/23362906/editing-a-netcdf-variable