Changeset 21645


Ignore:
Timestamp:
03/30/17 02:27:52 (8 years ago)
Author:
schlegel
Message:

CHG: add output definitions

File:
1 edited

Legend:

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

    r21643 r21645  
    4343        end
    4444
    45         %Needs a first turn arround for var def
     45        typelist=[{'numeric'} {'logical'} {'string'} {'char'} {'cell'}];
    4646 
    4747        %get all model classes and create respective groups
     
    8585                    end
    8686            end
    87                 else
    88                         for j=1:length(groupfields),
    89                                 disp(sprintf('=====Field name in tree %s ',groupfields{j}));
     87         else
     88                 for j=1:length(groupfields),
     89                         Var=md.(groups{i}).(groupfields{j});
     90                         if isa(Var,'cell')
     91                                 Stdlist=false;
     92                                 if length(Var) == 0
     93                                         Stdlist=true;
     94                                 else
     95                                         for k=1:length(typelist)
     96                                                if isa(Var{1},typelist{k})
     97                                                        Stdlist=true;
     98                                                end
     99                                        end
     100                                end
     101
    90102                                netcdf.putAtt(groupID,netcdf.getConstant('NC_GLOBAL'),'classtype',class(md.(groups{i})));
    91                                 Var=md.(groups{i}).(groupfields{j});
     103                                if(Stdlist)
     104                                        disp(sprintf('=====Field name in tree %s ',groupfields{j}));
     105                                        [DimSize,DimValue]=DefCreateVar(ncid,Var,groupID,groupfields{j},DimSize,DimValue,false);
     106                                else
     107                                        listsize=length(Var);
     108                                        subgroupID=netcdf.defGrp(groupID,groupfields{j});
     109                                        netcdf.putAtt(subgroupID,netcdf.getConstant('NC_GLOBAL'),'classtype',class(md.(groups{i}).(groupfields{j})));
     110                                        for l=1:listsize
     111                                                if isprop(Var{l},'name')
     112                                                        lname=Var{l}.name;
     113                                                elseif isprop(Var{l},'step')
     114                                                        lname=Var{l}.step
     115                                                else
     116                                                        lname=[class(Var{l}) int2str(l)];
     117                                                end
     118                                                listgroupID=netcdf.defGrp(subgroupID,lname);
     119                                                netcdf.putAtt(listgroupID,netcdf.getConstant('NC_GLOBAL'),'classtype',class(Var{l}));
     120                                                subfields=fields(Var{l});
     121                                                for m=1:length(subfields)
     122                                                        if ~strcmp(subfields{m},'outlog')
     123                                                                [DimSize,DimValue]=DefCreateVar(ncid,Var{l}.(subfields{m}),listgroupID,subfields{m},DimSize,DimValue,false);
     124                                                        end
     125                                                end
     126                                        end
     127                                end
     128                        else
     129                                netcdf.putAtt(groupID,netcdf.getConstant('NC_GLOBAL'),'classtype',class(md.(groups{i})));
    92130                                [DimSize,DimValue]=DefCreateVar(ncid,Var,groupID,groupfields{j},DimSize,DimValue,false);
    93             end
    94           end   
    95   end
    96         netcdf.close(ncid);
     131                        end
     132                 end
     133         end   
     134 end
     135 netcdf.close(ncid);
    97136end
    98137
     
    141180                                        endpoint=min(length(Var{i}),40);
    142181                                        startpoint=0;
    143                     end
     182                                end
    144183                                if length(Var{i})>40,
    145184                                        netcdf.putVar(groupID,varid,startpoint,endpoint,Var{i}(1:40))
    146185                                        disp(sprintf('some variable have been truncated'));
    147                           else
     186                                else
    148187                                        netcdf.putVar(groupID,varid,startpoint,endpoint,Var{i})
    149               end
    150             end
    151           end
     188                                end
     189                        end
     190                end
    152191        elseif isa(Var,'struct'),
    153192                %Start by getting the structure fields and size
Note: See TracChangeset for help on using the changeset viewer.