Changeset 25061
- Timestamp:
- 06/18/20 00:06:01 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/contrib/larour/ismip6.m
r25037 r25061 11 11 root = ''; %where are the files for CMIP5 12 12 n = 0; %number of files 13 directories = {}; %directories where the files are 14 experiments = {}; %names of experiments 15 thickness = {}; %placeholder for thicknesses 16 deltathickness = {}; %placeholder for delta thicknesses 17 icemask = {}; %placeholder for ice masks 18 oceanmask = {}; %placeholder for ocean masks 19 time = {}; %placeholder for times 13 directories = {}; %directories where the files are 14 experiments = {}; %names of experiments 15 thickness = {}; %placeholder for thicknesses 16 deltathickness = {}; %placeholder for delta thicknesses 17 icemask = {}; %placeholder for ice masks 18 oceanmask = {}; %placeholder for ocean masks 19 time = {}; %placeholder for times 20 timestart = {}; %placeholder for times 21 calendar = {}; %placeholder for times 20 22 end 21 23 methods … … 67 69 fielddisplay(self,'n','number of files'); 68 70 fielddisplay(self,'root','where are the files for ISMIP6'); 69 fielddisplay(self,'directories','IMSIP6 directories'); 71 fielddisplay(self,'directories','directories'); 72 fielddisplay(self,'experiments','experiments'); 73 fielddisplay(self,'thickness','thickness'); 74 fielddisplay(self,'deltathickness','deltathickness'); 75 fielddisplay(self,'icemask','icemask'); 76 fielddisplay(self,'oceanmask','oceanmask'); 77 fielddisplay(self,'time','time'); 78 fielddisplay(self,'timestart','timestart'); 79 fielddisplay(self,'calendar','calendar'); 70 80 end % }}} 71 81 function listexp(self) % {{{ … … 76 86 77 87 end % }}} 78 function [output,time ]=read(self,experiment,field) % {{{88 function [output,time,timestart,calendar]=read(self,experiment,field) % {{{ 79 89 80 90 %go through list of experiments and find the right one: … … 118 128 output=ncread([self.root '/' dir '/' file ],field); 119 129 130 %figure out start time: 131 info=ncinfo([self.root '/' dir '/' file]); 132 attributes=[]; 133 for i=1:length(info.Variables), 134 if strcmpi(info.Variables(i).Name,'time'), 135 attributes=info.Variables(i).Attributes; 136 break; 137 end 138 end 139 for j=1:length(attributes), 140 if strcmpi(attributes(j).Name,'units') | strcmpi(attributes(j).Name,'unit'), 141 timestart=attributes(j).Value; 142 end 143 if strcmpi(attributes(j).Name,'calendar') 144 calendar=attributes(j).Value; 145 end 146 end 147 148 end % }}} 149 function info=readinfo(self,experiment,field) % {{{ 150 151 %go through list of experiments and find the right one: 152 if strcmpi(class(experiment),'double'), 153 ind=experiment; 154 elseif strcmpi(class(experiment),'char'), 155 for i=1:self.n, 156 if strcmpi(experiment,self.experiments{i}), 157 ind=i; 158 break; 159 end 160 end 161 else 162 error(['ismip6 read error message: experiment should be a string or index']); 163 end 164 165 if ind==0 166 error(['ismip6 read error message: experiment ' experiment ' could not be found!']); 167 end; 168 169 %figure out the files in this directory: 170 dir=self.directories{ind}; 171 currentdir=pwd; 172 cd([self.root '/' dir]); 173 list=listfiles; 174 cd(currentdir); 175 176 %go through list of files and figure out which one starts with the field: 177 for i=1:length(list), 178 file=list{i}; 179 ind=findstr(file,'_'); 180 file_field=file(1:ind-1); 181 if strcmpi(file_field,field), 182 break; 183 end 184 end 185 186 %read attributes 187 info=ncinfo([self.root '/' dir '/' file]); 188 120 189 end % }}} 121 190 function interpolate(self,field,ismip2mesh,ismip2mesh_correction) % {{{ … … 125 194 126 195 %read field from disk: 127 [h,t ]=self.read(i,field); nt=length(t);196 [h,t,t0,cal]=self.read(i,field); nt=length(t); 128 197 129 198 %map onto 1 dimension field: … … 140 209 if strcmpi(field,'lithk'), 141 210 self.thickness{i}=hg; 211 self.deltathickness{i}=diff(hg,1,2); 142 212 end 143 213 self.time{i}=t; 214 self.timestart{i}=t0; 215 self.calendar{i}=cal; 216 144 217 end 145 218 end % }}}
Note:
See TracChangeset
for help on using the changeset viewer.