1.grd文件读取(多维信息提取)
例子1:“
clc;clear all;
fid=fopen(‘G:\work\4\pre\rain6.grd’,‘rb’);
[ssh,count]=fread(fid,inf,‘float32’); %inf表示读取全部数据float32为浮点型
fclose(fid);
%size(a)
ssh=reshape(ssh,27,17,1,3,366); %27为X方向,17为Y方向,1为垂直Z方向,3为变量V维数,366为时间T维数
2.grd文件读取转nc文件
例子2:“
clear all
fid=fopen(‘SEVP_CLI_CHN_MERGE_CMP_PRE_HOUR_GRID_0.10-2016080223.grd’,‘rb’);
[ssh,count]=fread(fid,inf,‘float32’); %inf表示读取全部数据float32为浮点型
data1=reshape(ssh,[700 440 2]);% 根据ctl文件信息填写 X,Y,Z,V,T
fclose(fid);
%% 转nc存数据
RC=data1;
ncid = netcdf.create(‘0223.nc’,‘CLOBBER’);
lon=70.05:0.1:140.04;
lat=15.05:0.1:59.04;
%-----------------------------define dimension-----------------------------%
dimidx = netcdf.defDim(ncid,‘lon’,700); %%nstation=6876
dimidy = netcdf.defDim(ncid,‘lat’,440);
dimidz = netcdf.defDim(ncid,‘vars’,2);
%----------------------------define new variables---------------------------------%
varid1 = netcdf.defVar(ncid,‘RC’,‘double’,[dimidx dimidy dimidz]);
%经纬信息
varid2 = netcdf.defVar(ncid,‘lon’,‘double’,[dimidx]);
varid3 = netcdf.defVar(ncid,‘lat’,‘double’,[dimidy]);
% %---------------------------define attributes of the new variables--------------%
netcdf.putAtt(ncid,varid1,‘units’,‘Dimensionless’);
netcdf.putAtt(ncid,varid1,‘long_name’,‘regression coefficients’);
netcdf.putAtt(ncid,varid2,‘long_name’,‘longitude’);
netcdf.putAtt(ncid,varid3,‘long_name’,‘latitude’);
netcdf.endDef(ncid);
%-------------------------- ± ?-------------------------------------------%
netcdf.putVar(ncid,varid1,RC);
netcdf.putVar(ncid,varid2,lon);
netcdf.putVar(ncid,varid3,lat);
netcdf.close(ncid);