我有40个netcdf文件名为‘V10M 1961_v10M_Iberia.nc’,'lffd1962_V10M_Iberia‘.‘V10M 2000_V10M_Iberia’。
我希望在相同的程序中打开它们,在所有变量中得到相同的变量,在变量中应用一些等式,然后用修改后的变量创建40个新的netcdf文件。
要打开40个文件,我已经开发了这段代码,它可以工作。
for yr=1961:2000
inFile=strcat('lffd',num2str(yr),'_V10M_Iberia.nc'); disp(inFile)
nc=netcdf.open(inFile,'NC_NOWRITE');
netcdf.close(nc)
end现在我要得到所有这些变量中的变量4。这个变量是一个3D矩阵(70x51x(8760或8784)),类似于下一行,但有一个40年循环:
ws_1961(1962, etc, etc) = netcdf.getVar(nc,4);我的工作空间里应该有40个新变量。在此之后,我想在这40个变量中应用这个方程:
ws_80 = ws.*(log(z/alpha)/log(exp(1))/(log(10/alpha)/log(exp(1))));最后,使用我的新变量在每个文件中创建40个新的netcdf文件。
就像这样:
outFile=strcat('year',num2str(yr),'_80m.nc')
ncid = netcdf.create(outFile,'CLOBBER');
dimid0 = netcdf.defDim(ncid,'longitude',nlon); % getvar number 1
dimid1 = netcdf.defDim(ncid,'latitude',nlat); %getvar number 2
dimid2 = netcdf.defDim(ncid,'time',nt); %getvar number 3
varid0 = netcdf.defVar(ncid,'longitude','double', dimid0);
varid1 = netcdf.defVar(ncid,'latitude','double', dimid1);
varid2 = netcdf.defVar(ncid,'time','double', dimid2);
varid3 = netcdf.defVar(ncid,'ws_80','double', [dimid0 dimid1 dimid2]);
netcdf.putAtt(ncid,varid0,'units','degrees_east');
netcdf.putAtt(ncid,varid0,'long_name','longitude');
netcdf.putAtt(ncid,varid1,'units','degrees_north');
netcdf.putAtt(ncid,varid1,'degrees_north','latitude');
netcdf.endDef(ncid);
netcdf.putVar(ncid,varid0,longitude);
netcdf.putVar(ncid,varid1,latitude);
netcdf.putVar(ncid,varid2,time);
netcdf.putVar(ncid,varid3,ws80);我很难以一种你们都理解的方式来解释这件事,所以请你随心所欲地问。
发布于 2014-01-20 16:31:39
这是一些“空中编码”,让你开始。
% The variable we want to process
myVarName = 'ws_80';
for yr=1961:2000
inFile = strcat('lffd',num2str(yr),'_V10M_Iberia.nc');
disp(inFile);
outFile = strcat('lffd',num2str(yr),'_V10M_Iberia_processed.nc');
disp(outFile);
% copy input file to create a template for the output
copyDone = copyfile(inFile, outFile,'f');
if(~copyDone)
error('Could not copy file');
end
% Read variable
inVar = ncread(inFile,myVarName);
% Replace this line with your equation
outVar = myProcessFunction(inVar);
% Write variable
ncwrite(outFile, myVarName, outVar);
end您将不得不修改这个以实现您的目标。试一试,回到你被困的地方。
https://stackoverflow.com/questions/21231968
复制相似问题