Changeset 21655


Ignore:
Timestamp:
04/03/17 17:28:19 (8 years ago)
Author:
schlegel
Message:

CHG: matlab read works for all but requestedoutput outputdefinition and results

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/contrib/defleurian/netCDF/read_netCDF.m

    r19157 r21655  
    11function self=read_netCDF(filename)
    22
    3 % Different types in the netcdf standard are:
    4 %   2 for char
    5 %   4 for integer
    6 %   6 for doubles       
    7        
     3        % Different types in the netcdf standard are:
     4        %   2 for char
     5        %   4 for integer
     6        %   6 for doubles       
     7
    88        ncid=netcdf.open(filename,'NC_NOWRITE');
    99        groupIDs=netcdf.inqGrps(ncid);%retrieve group IDs
     
    3030                                        %classtype have done is job, no need to keep it any more
    3131                                        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);
    3333                                                if strcmp(attval,'False'),
    3434                                                        self.(groupName).(subclass).(attname)=false;
     
    3737                                                else
    3838                                                        self.(groupName).(subclass).(attname)=attval;
    39                               end
    40                       end
    41                     end
     39                                                end
     40                                        end
     41                                end
    4242                                %now loop on variable in group
     43                                count=0;
    4344                                for k=1:length(varIDs),
    4445                                        [varname, xtype, varDimIDs, varAtts] =netcdf.inqVar(subgroupIDs(j),varIDs(k));
     
    4849                                                [dimname, dimlen] = netcdf.inqDim(ncid,varDimIDs(l));
    4950                                                count(l)=[dimlen];
    50                       end
     51                                        end
    5152                                        startpoint=zeros(size(varDimIDs));
    5253                                        timestep=count(end);
     
    5960                                                self.(groupName).(subclass)(l).('outlog')='';
    6061                                                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
    9066                else,
    9167                        %define the model structure
     
    10682                                                self.(groupName).(attname)=true;
    10783                                        else
    108                                         self.(groupName).(attname)=attval;
    109                     end
    110                   end
    111           end
     84                                                self.(groupName).(attname)=attval;
     85                                        end
     86                                end
     87                        end
    11288                        %now loop on variable in group
    11389                        for j=1:length(varIDs),
     
    127103                                else
    128104                                        self.(groupName).(varname)=netcdf.getVar(groupIDs(i),varIDs(j));
    129                     end
    130                   end
    131           end
    132   end
     105                                end
     106                        end
     107                end
     108        end
    133109        netcdf.close(ncid)
    134110end
Note: See TracChangeset for help on using the changeset viewer.