/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_IO/grid_load.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/grid_load.m

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


Revision 1.6 - (hide annotations) (download)
Tue Jul 5 17:51:13 2011 UTC (14 years ago) by gforget
Branch: MAIN
Changes since 1.5: +17 -2 lines
- introduce mygrid.gcm2facesFast that speeds up convert2gcmfaces.
- mygrid.gcm2facesFast is originally set up to false in grid_load;
  then the grid is loaded, which allows the computation of
  mygrid.gcm2faces, mygrid.faces2gcmSize and mygrid.faces2gcm;
  at this point mygrid.gcm2facesFast is set to true, and any
  other call to convert2gcmfaces will use the faster approach.

1 gforget 1.5 function []=grid_load(dirGrid,nFaces,fileFormat);
2     %object: load grid information, convert it to gcmfaces format
3     % and encapsulate it in the global mygrid structure.
4     %inputs: dirGrid is the directory where the grid files (gcm output) can be found.
5     % nFaces is the number of faces in this gcm set-up of current interest.
6     % fileFormat is the file format ('straight','cube','compact')
7    
8     input_list_check('grid_load',nargin);
9 gforget 1.1
10     global mygrid;
11 gforget 1.5 mygrid.dirGrid=dirGrid;
12     mygrid.nFaces=nFaces;
13     mygrid.fileFormat=fileFormat;
14 gforget 1.6 mygrid.gcm2facesFast=false;
15 gforget 1.1
16 gforget 1.5 if ~(nFaces==1&strcmp(fileFormat,'straight'))&...
17     ~(nFaces==6&strcmp(fileFormat,'cube'))&...
18     ~(nFaces==6&strcmp(fileFormat,'compact'))&...
19     ~(nFaces==5&strcmp(fileFormat,'compact'));
20     % if gcmfaces_verbose;
21     % fprintf('\nconvert2gcmfaces.m init: there are several supported file conventions. \n');
22     % fprintf(' By default gcmfaces assumes MITgcm type binary formats as follows: \n')
23     % fprintf(' (1 face) straight global format; (4 or 5 faces) compact global format\n');
24     % fprintf(' (6 faces) cube format with one face after the other. \n');
25     % fprintf(' If this is inadequate, you can change the format below.\n\n');
26     % end;
27     error('non-tested topology/fileFormat');
28 gforget 1.1 end;
29    
30 gforget 1.6 %the various grid fields:
31 gforget 1.1 list0={'XC','XG','YC','YG','RAC','RAZ','DXC','DXG','DYC','DYG',...
32 gforget 1.4 'hFacC','hFacS','hFacW','Depth'};
33 gforget 1.1 for iFld=1:length(list0);
34 gforget 1.5 eval(['mygrid.' list0{iFld} '=rdmds2gcmfaces([dirGrid ''' list0{iFld} '*'']);']);
35 gforget 1.1 end;
36    
37 gforget 1.4 list0={'AngleCS','AngleSN'};
38     test0=~isempty(dir([dirGrid 'AngleCS*']));
39     if test0;
40     for iFld=1:length(list0);
41 gforget 1.5 eval(['mygrid.' list0{iFld} '=rdmds2gcmfaces([dirGrid ''' list0{iFld} '*'']);']);
42 gforget 1.4 end;
43     else;
44     warning('\n AngleCS/AngleSN not found; set to 1/0 assuming lat/lon grid.\n');
45     mygrid.AngleCS=mygrid.XC; mygrid.AngleCS(:)=1;
46     mygrid.AngleSN=mygrid.XC; mygrid.AngleSN(:)=0;
47     end;
48    
49 gforget 1.1 list0={'RC','RF','DRC','DRF'};
50     for iFld=1:length(list0);
51 gforget 1.2 eval(['mygrid.' list0{iFld} '=squeeze(rdmds([dirGrid ''' list0{iFld} '*'']));']);
52 gforget 1.1 end;
53    
54 gforget 1.6 %masks:
55 gforget 1.1 mygrid.hFacCsurf=mygrid.hFacC;
56     for ff=1:mygrid.hFacC.nFaces; mygrid.hFacCsurf{ff}=mygrid.hFacC{ff}(:,:,1); end;
57    
58 gforget 1.2 mskC=mygrid.hFacC; mskC(mskC==0)=NaN; mskC(mskC>0)=1; mygrid.mskC=mskC;
59     mskW=mygrid.hFacW; mskW(mskW==0)=NaN; mskW(mskW>0)=1; mygrid.mskW=mskW;
60     mskS=mygrid.hFacS; mskS(mskS==0)=NaN; mskS(mskS>0)=1; mygrid.mskS=mskS;
61    
62 gforget 1.6 %to allow convert2gcmfaces/doFast:
63     tmp1=convert2gcmfaces(mygrid.XC);
64     tmp1(:)=[1:90*1170];
65     nn=length(tmp1(:));
66     mygrid.gcm2faces=convert2gcmfaces(tmp1);
67     mygrid.faces2gcmSize=size(tmp1);
68     mygrid.faces2gcm=convert2gcmfaces(tmp1);
69     for iFace=1:5;
70     n=length(mygrid.gcm2faces{iFace}(:));
71     mygrid.faces2gcm{iFace}=mygrid.gcm2faces{iFace}(:);
72     mygrid.gcm2faces{iFace}=sparse([1:n],mygrid.gcm2faces{iFace}(:),ones(1,n),n,nn);
73     end;
74     mygrid.gcm2facesFast=true;
75    
76 gforget 1.1

  ViewVC Help
Powered by ViewVC 1.1.22