Changeset 14611
- Timestamp:
- 04/16/13 16:20:56 (12 years ago)
- 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 1139 1139 function memory(obj) % {{{ 1140 1140 1141 disp(sprintf('\nMemory imprint: 1141 disp(sprintf('\nMemory imprint:\n')); 1142 1142 1143 1143 fields=properties('model'); … … 1148 1148 s=whos('field'); 1149 1149 mem=mem+s.bytes/1e6; 1150 disp(sprintf('%19s: % gMb',fields{i},s.bytes/1e6));1150 disp(sprintf('%19s: %6.2f Mb',fields{i},s.bytes/1e6)); 1151 1151 end 1152 1152 disp(sprintf('%19s--%10s','--------------','--------------')); … … 1166 1166 ncid=netcdf.create(filename,'CLOBBER'); 1167 1167 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 ')']); 1169 1169 netcdf.putAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'Author',getenv('USER')); 1170 1170 netcdf.putAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'Date',datestr(now)); 1171 1171 1172 % 2. prepare some simple dimensions1172 %Preallocate variable id, needed to write variables in netcdf file 1173 1173 var_id=zeros(300,1);%preallocate 1174 1175 %2. First round: define variables (step=1), put variable (step=2)1176 fields1=properties('model');1177 1174 1178 1175 for step=1:2, 1179 1176 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); 1227 1178 if step==1, netcdf.endDef(ncid); end 1228 1179 end 1180 1229 1181 if counter>300, 1230 1182 warning('preallocation of var_id need to be updated');
Note:
See TracChangeset
for help on using the changeset viewer.