Changeset 21655
- Timestamp:
- 04/03/17 17:28:19 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/contrib/defleurian/netCDF/read_netCDF.m
r19157 r21655 1 1 function self=read_netCDF(filename) 2 2 3 % Different types in the netcdf standard are:4 % 2 for char5 % 4 for integer6 % 6 for doubles7 3 % Different types in the netcdf standard are: 4 % 2 for char 5 % 4 for integer 6 % 6 for doubles 7 8 8 ncid=netcdf.open(filename,'NC_NOWRITE'); 9 9 groupIDs=netcdf.inqGrps(ncid);%retrieve group IDs … … 30 30 %classtype have done is job, no need to keep it any more 31 31 if ~strcmp(attname,'classtype'), 32 attval=netcdf.getAtt(subgroupIDs( i),netcdf.getConstant('NC_GLOBAL'),attname);32 attval=netcdf.getAtt(subgroupIDs(j),netcdf.getConstant('NC_GLOBAL'),attname); 33 33 if strcmp(attval,'False'), 34 34 self.(groupName).(subclass).(attname)=false; … … 37 37 else 38 38 self.(groupName).(subclass).(attname)=attval; 39 40 41 39 end 40 end 41 end 42 42 %now loop on variable in group 43 count=0; 43 44 for k=1:length(varIDs), 44 45 [varname, xtype, varDimIDs, varAtts] =netcdf.inqVar(subgroupIDs(j),varIDs(k)); … … 48 49 [dimname, dimlen] = netcdf.inqDim(ncid,varDimIDs(l)); 49 50 count(l)=[dimlen]; 50 51 end 51 52 startpoint=zeros(size(varDimIDs)); 52 53 timestep=count(end); … … 59 60 self.(groupName).(subclass)(l).('outlog')=''; 60 61 self.(groupName).(subclass)(l).('SolutionType')=subclass; 61 end 62 clear count 63 end 64 end 65 %toolkits too require a specific treatment 66 elseif strcmp(whichclass,'toolkits'), 67 %just one variable here 68 varID=netcdf.inqVarIDs(groupIDs(i)); 69 [varname, xtype, varDimIDs, varAtts] =netcdf.inqVar(groupIDs(i),varID); 70 disp(sprintf('In %s, Treating variable %s of type %i',whichclass,varname,xtype)); 71 [dimname,numoffields] = netcdf.inqDim(ncid,varDimIDs(end)); 72 self.(groupName)=eval(whichclass); 73 for j=1:numoffields, 74 varval=netcdf.getVar(groupIDs(i),varID,[0,1,j-1],[40,1,1])'; 75 fieldname=netcdf.getVar(groupIDs(i),varID,[0,0,j-1],[40,1,1])'; 76 varval=cellstr(varval); 77 fieldname=cellstr(fieldname); 78 [val, status]=str2num(varval{1}); 79 if strcmp(varval{1},'false') |strcmp(varval{1},'true') , 80 status=0; 81 end 82 if status==1, 83 self.(groupName).(varname).(fieldname{1})=val; 84 else 85 self.(groupName).(varname).(fieldname{1})=varval{1}; 86 end 87 end 88 %Now for the other fields 89 62 end 63 count=0; 64 end 65 end 90 66 else, 91 67 %define the model structure … … 106 82 self.(groupName).(attname)=true; 107 83 else 108 self.(groupName).(attname)=attval;109 110 111 84 self.(groupName).(attname)=attval; 85 end 86 end 87 end 112 88 %now loop on variable in group 113 89 for j=1:length(varIDs), … … 127 103 else 128 104 self.(groupName).(varname)=netcdf.getVar(groupIDs(i),varIDs(j)); 129 130 131 132 105 end 106 end 107 end 108 end 133 109 netcdf.close(ncid) 134 110 end
Note:
See TracChangeset
for help on using the changeset viewer.