Changeset 25037
- Timestamp:
- 06/15/20 21:07:29 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/contrib/larour/ismip6.m
r25036 r25037 13 13 directories = {}; %directories where the files are 14 14 experiments = {}; %names of experiments 15 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 16 20 end 17 21 methods … … 46 50 end 47 51 52 %initialize fields: 53 self.thickness=cell(self.n,1); 54 self.deltathickness=cell(self.n,1); 55 self.icemask=cell(self.n,1); 56 self.oceanmask=cell(self.n,1); 57 48 58 end 49 59 end … … 55 65 disp(' CMIP5 Ocean MIP:'); 56 66 57 58 59 67 fielddisplay(self,'n','number of files'); 68 fielddisplay(self,'root','where are the files for ISMIP6'); 69 fielddisplay(self,'directories','IMSIP6 directories'); 60 70 end % }}} 61 71 function listexp(self) % {{{ … … 66 76 67 77 end % }}} 68 end 78 function [output,time]=read(self,experiment,field) % {{{ 79 80 %go through list of experiments and find the right one: 81 if strcmpi(class(experiment),'double'), 82 ind=experiment; 83 elseif strcmpi(class(experiment),'char'), 84 for i=1:self.n, 85 if strcmpi(experiment,self.experiments{i}), 86 ind=i; 87 break; 88 end 89 end 90 else 91 error(['ismip6 read error message: experiment should be a string or index']); 92 end 93 94 if ind==0 95 error(['ismip6 read error message: experiment ' experiment ' could not be found!']); 96 end; 97 98 %figure out the files in this directory: 99 dir=self.directories{ind}; 100 currentdir=pwd; 101 cd([self.root '/' dir]); 102 list=listfiles; 103 cd(currentdir); 104 105 %go through list of files and figure out which one starts with the field: 106 for i=1:length(list), 107 file=list{i}; 108 ind=findstr(file,'_'); 109 file_field=file(1:ind-1); 110 if strcmpi(file_field,field), 111 break; 112 end 113 end 114 115 %read file: 116 %output=ncread([self.root '/' dir '/' file],'file_field'); 117 time=ncread([self.root '/' dir '/' file],'time'); 118 output=ncread([self.root '/' dir '/' file ],field); 119 120 end % }}} 121 function interpolate(self,field,ismip2mesh,ismip2mesh_correction) % {{{ 122 123 for i=1:self.n, 124 disp(['reading and interpolating field ' field ' for model ' self.experiments{i}]); 125 126 %read field from disk: 127 [h,t]=self.read(i,field); nt=length(t); 128 129 %map onto 1 dimension field: 130 ht=zeros(size(h,1)*size(h,2),nt); 131 for j=1:size(h,3), 132 hj= h(:,:,j)'; hj=hj(:); ht(:,j)=double(hj); 133 end 134 135 %map onto mesh: 136 hg=ismip2mesh_correction.*(ismip2mesh*ht); 137 pos=find(isnan(hg)); hg(pos)=0; 138 139 %keep field: 140 if strcmpi(field,'lithk'), 141 self.thickness{i}=hg; 142 end 143 self.time{i}=t; 144 end 145 end % }}} 146 end 69 147 end
Note:
See TracChangeset
for help on using the changeset viewer.