Changeset 14611


Ignore:
Timestamp:
04/16/13 16:20:56 (12 years ago)
Author:
Mathieu Morlighem
Message:

CHG: netcdf(md) now writes results too

Location:
issm/trunk-jpl/src/m
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/classes/model/model.m

    r14609 r14611  
    11391139                function memory(obj) % {{{
    11401140                       
    1141                 disp(sprintf('\nMemory imprint: '));
     1141                disp(sprintf('\nMemory imprint:\n'));
    11421142
    11431143                fields=properties('model');
     
    11481148                        s=whos('field');
    11491149                        mem=mem+s.bytes/1e6;
    1150                         disp(sprintf('%19s: %g Mb',fields{i},s.bytes/1e6));
     1150                        disp(sprintf('%19s: %6.2f Mb',fields{i},s.bytes/1e6));
    11511151                end
    11521152                disp(sprintf('%19s--%10s','--------------','--------------'));
     
    11661166                ncid=netcdf.create(filename,'CLOBBER');
    11671167                netcdf.putAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'Conventions','CF-1.4');
    1168                 netcdf.putAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'Title',['ISSM model' obj.miscellaneous.name]);
     1168                netcdf.putAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'Title',['ISSM model (' obj.miscellaneous.name ')']);
    11691169                netcdf.putAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'Author',getenv('USER'));
    11701170                netcdf.putAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'Date',datestr(now));
    11711171
    1172                 %2. prepare some simple dimensions
     1172                %Preallocate variable id, needed to write variables in netcdf file
    11731173                var_id=zeros(300,1);%preallocate
    1174 
    1175                 %2. First round: define variables (step=1), put variable (step=2)
    1176                 fields1=properties('model');
    11771174
    11781175                for step=1:2,
    11791176                        counter=0;
    1180                         for i=1:length(fields1),
    1181                                 fields2=fields(obj.(fields1{i}));
    1182                                 for j=1:length(fields2)
    1183                                         counter   = counter+1;
    1184                                         fieldname = [fields1{i} '.' fields2{j}];
    1185                                         field     = obj.(fields1{i}).(fields2{j});
    1186                                         if isa(field,'double') & numel(field)==1,
    1187                                                 if step==1,
    1188                                                         var_id(counter) = netcdf.defVar(ncid,fieldname,'NC_DOUBLE',[]);
    1189                                                 else
    1190                                                         netcdf.putVar(ncid,var_id(counter),field);
    1191                                                 end
    1192                                         elseif isa(field,'double') & size(field,2)==1,
    1193                                                 if step==1,
    1194                                                         dim_id          = netcdf.defDim(ncid,[fieldname '_size1'],size(field,1));
    1195                                                         var_id(counter) = netcdf.defVar(ncid,fieldname,'NC_DOUBLE',dim_id);
    1196                                                 else
    1197                                                         netcdf.putVar(ncid,var_id(counter),field);
    1198                                                 end
    1199                                         elseif isa(field,'double') & size(field,2)>1,
    1200                                                 if step==1,
    1201                                                         dim1_id         = netcdf.defDim(ncid,[fieldname '_size1'],size(field,1));
    1202                                                         dim2_id         = netcdf.defDim(ncid,[fieldname '_size2'],size(field,2));
    1203                                                         var_id(counter) = netcdf.defVar(ncid,fieldname,'NC_DOUBLE',[dim2_id dim1_id]);
    1204                                                 else
    1205                                                         netcdf.putVar(ncid,var_id(counter),transpose(field));
    1206                                                 end
    1207                                         elseif isa(field,'char') & ~isempty(field),
    1208                                                 if step==1,
    1209                                                         dim_id          = netcdf.defDim(ncid,[fieldname '_size1'],numel(field));
    1210                                                         var_id(counter) = netcdf.defVar(ncid,fieldname,'NC_CHAR',dim_id);
    1211                                                 else
    1212                                                         netcdf.putVar(ncid,var_id(counter),transpose(field));
    1213                                                 end
    1214                                         elseif isa(field,'logical') & numel(field)==1,
    1215                                                 if step==1,
    1216                                                         var_id(counter) = netcdf.defVar(ncid,fieldname,'NC_BYTE',[]);
    1217                                                 else
    1218                                                         netcdf.putVar(ncid,var_id(counter),int8(field));
    1219                                                 end
    1220                                         else
    1221                                                 disp(['skipping ' fieldname '...']);
    1222                                         end
    1223                                 end
    1224 
    1225                         end
    1226 
     1177                        var_id=structtonc(ncid,'md',obj,0,var_id,counter,step);
    12271178                        if step==1, netcdf.endDef(ncid); end
    12281179                end
     1180
    12291181                if counter>300,
    12301182                        warning('preallocation of var_id need to be updated');
Note: See TracChangeset for help on using the changeset viewer.