/[MITgcm]/MITgcm_contrib/enderton/Diagnostics/DiagLoadGradsData.m
ViewVC logotype

Diff of /MITgcm_contrib/enderton/Diagnostics/DiagLoadGradsData.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by enderton, Mon Jan 31 15:43:26 2005 UTC revision 1.2 by enderton, Mon Jan 31 19:58:15 2005 UTC
# Line 1  Line 1 
1  function [data,xax,yax,zax,months,time,dim] = ...  function [data,xax,yax,zax,months,time,dim] = ...
2      DiagLoadGradsData(Grads,dad,fln)      DiagLoadGradsData(Grads,dad,fln,DiagDebug)
3    
4    
5    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6    %                          Parse table file                               %
7    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8    
9    format = 'NONSEQUENTIAL';
10    
 % Read table file.  
11  tablfile = [dad,'/',Grads,'.tabl'];  tablfile = [dad,'/',Grads,'.tabl'];
 datafile = [dad,'/',Grads,'.data'];  
12  file = textread(tablfile,'%s','delimiter','\n','whitespace','');  file = textread(tablfile,'%s','delimiter','\n','whitespace','');
13    
14  for iline = 1:length(file)  for iline = 1:length(file)
15      rem = file{iline}; tokens = {}; itoken = 0;      rem = file{iline}; tokens = {}; itoken = 0;
16      while isstr(rem)      while isstr(rem)
# Line 74  for iline = 1:length(file) Line 80  for iline = 1:length(file)
80          elseif isequal(monchar,'NOV'), inimonth = 11;          elseif isequal(monchar,'NOV'), inimonth = 11;
81          elseif isequal(monchar,'DEC'), inimonth = 12; end          elseif isequal(monchar,'DEC'), inimonth = 12; end
82          num = str2num(tokens{2});          num = str2num(tokens{2});
83          months=[inimonth:num]; time=months/12; nt = length(months);          months=[inimonth:num+inimonth-1];
84            time=months/12; nt = length(months);
85                    
86      end      end
87            
# Line 82  for iline = 1:length(file) Line 89  for iline = 1:length(file)
89          nv = str2num(tokens{2});          nv = str2num(tokens{2});
90          VARSline = iline;          VARSline = iline;
91      end      end
       
92      if isequal(tokens{1},fln)      if isequal(tokens{1},fln)
93          FIELDline = iline;          FIELDline = iline;
94          index = iline - VARSline;          ivar = iline - VARSline;
95      end      end
96            
97      if isequal(tokens{1},'UNDEF')      if isequal(tokens{1},'UNDEF')
98          undef = str2num(tokens{2});          undef = str2num(tokens{2});
99      end      end
100            
101        if isequal(tokens{1},'FORMAT')
102            if isequal(tokens{2},'SEQUENTIAL')
103                format = 'SEQUENTIAL';
104            else
105                disp(['Unrecognized grads FORMAT:  ',tokens{2}]);
106            end
107        end
108        
109        if isequal(tokens{1},'DSET')
110            datafile = [dad,tokens{2}(2:end)];
111        end  
112        
113  end  end
114    
115    
116    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117    %                       Verification and debugging                        %
118    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119    
120    if DiagDebug, disp(['  Debug -- grads data format:  ',format]); end
121    
122  % Verify that things are there.  % Verify that things are there.
123  parameters = {'xax' ,'yax' ,'zax' ,'time','nv'  ,'undef','index'};  parameters = {'xax' ,'yax' ,'zax' ,'time','nv'  ,'undef','ivar'};
124  GRADSnames = {'XDEF','YDEF','ZDEF','TDEF','VARS','UNDEF',fln    };  GRADSnames = {'XDEF','YDEF','ZDEF','TDEF','VARS','UNDEF',fln   };
125  for ii = 1:length(parameters)  for ii = 1:length(parameters)
126      try      try
127          eval([parameters{ii},';']);          eval([parameters{ii},';']);
# Line 105  for ii = 1:length(parameters) Line 130  for ii = 1:length(parameters)
130      end      end
131  end  end
132    
133  % Read in grads data using axis infomation.  
134    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135    %                              Read data file                             %
136    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137    
138  tol = 1e-5;  tol = 1e-5;
139  fid=fopen(datafile,'r','b');  fid=fopen(datafile,'r','b');
140  data = fread(fid,'real*4');  data = fread(fid,'real*4');
141  fclose(fid);  fclose(fid);
142    if isequal(format,'SEQUENTIAL')
143        index=true([nx*ny*nz*nv*nt+2*nv*nt,1]);
144        index([1:nx*ny*nz+2:end])=false;
145        index([2:nx*ny*nz+2:end])=false;
146        data = data(index);
147    end
148  data = reshape(data,[nx,ny,nz,nv,nt]);  data = reshape(data,[nx,ny,nz,nv,nt]);
149  data = squeeze(data(:,:,:,index,:));  data = squeeze(data(:,:,:,ivar,:));
150  data( abs((data-undef)/undef) < tol ) = NaN;  data( abs((data-undef)/undef) < tol ) = NaN;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.22