1 |
gforget |
1.9 |
function []=grid_load(dirGrid,nFaces,fileFormat,memoryLimit); |
2 |
gforget |
1.5 |
%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 |
gforget |
1.9 |
%optional: memoryLimit is a flag that allows the user to omit secondary |
8 |
|
|
% grid fields in case memory/storage become an issue. It |
9 |
|
|
% takes 3 values : (0; the default) includes everything |
10 |
|
|
% (1) omits all 3D fields but hFacC (2) only loads XC & YC. |
11 |
gforget |
1.5 |
|
12 |
|
|
input_list_check('grid_load',nargin); |
13 |
gforget |
1.1 |
|
14 |
gforget |
1.9 |
if isempty(whos('memoryLimit')); memoryLimit=0; end; |
15 |
|
|
|
16 |
gforget |
1.7 |
gcmfaces_global; mygrid=[]; |
17 |
|
|
|
18 |
gforget |
1.5 |
mygrid.dirGrid=dirGrid; |
19 |
|
|
mygrid.nFaces=nFaces; |
20 |
|
|
mygrid.fileFormat=fileFormat; |
21 |
gforget |
1.6 |
mygrid.gcm2facesFast=false; |
22 |
gforget |
1.9 |
mygrid.memoryLimit=memoryLimit; |
23 |
|
|
|
24 |
|
|
if mygrid.memoryLimit>0; |
25 |
|
|
gcmfaces_msg(['* Warning from grid_load : memoryLimit>0 ' ... |
26 |
|
|
'may precludes advanced gmcfaces functions.'],''); |
27 |
|
|
end; |
28 |
|
|
if mygrid.memoryLimit>1; |
29 |
|
|
gcmfaces_msg(['* Warning from grid_load : memoryLimit>1 ' ... |
30 |
|
|
'may only allow for basic fields displays.'],''); |
31 |
|
|
end; |
32 |
|
|
|
33 |
|
|
if ~isempty(dir([dirGrid 'grid.specs.mat'])); |
34 |
|
|
specs=open([dirGrid 'grid.specs.mat']); |
35 |
|
|
mygrid.ioSize=specs.ioSize; |
36 |
|
|
mygrid.facesSize=specs.facesSize; |
37 |
|
|
mygrid.facesExpand=specs.facesExpand; |
38 |
|
|
%example for creating grid.specs.mat, to put in dirGrid : |
39 |
|
|
%ioSize=[364500 1]; |
40 |
|
|
%facesSize=[[270 450];[0 0];[270 270];[180 270];[450 270]]; |
41 |
|
|
%facesExpand=[270 450]; |
42 |
|
|
%save grid.specs.mat ioSize facesSize facesExpand; |
43 |
|
|
else; |
44 |
|
|
%does this work for cube? |
45 |
|
|
v0=rdmds([dirGrid 'XC']); |
46 |
|
|
mygrid.ioSize=size(v0); |
47 |
|
|
nn=size(v0,1); pp=size(v0,2)/nn; |
48 |
|
|
mm=(pp+4-mygrid.nFaces)/4*nn; |
49 |
|
|
mygrid.facesSize=[[nn mm];[nn mm];[nn nn];[mm nn];[mm nn]]; |
50 |
|
|
mygrid.facesExpand=[]; |
51 |
|
|
end; |
52 |
gforget |
1.1 |
|
53 |
gforget |
1.5 |
if ~(nFaces==1&strcmp(fileFormat,'straight'))&... |
54 |
|
|
~(nFaces==6&strcmp(fileFormat,'cube'))&... |
55 |
|
|
~(nFaces==6&strcmp(fileFormat,'compact'))&... |
56 |
|
|
~(nFaces==5&strcmp(fileFormat,'compact')); |
57 |
gforget |
1.8 |
% if myenv.verbose; |
58 |
|
|
% fprintf('\nconvert2gcmfaces.m init: there are several supported file conventions. \n'); |
59 |
|
|
% fprintf(' By default gcmfaces assumes MITgcm type binary formats as follows: \n') |
60 |
|
|
% fprintf(' (1 face) straight global format; (4 or 5 faces) compact global format\n'); |
61 |
|
|
% fprintf(' (6 faces) cube format with one face after the other. \n'); |
62 |
|
|
% fprintf(' If this is inadequate, you can change the format below.\n\n'); |
63 |
|
|
% end; |
64 |
gforget |
1.5 |
error('non-tested topology/fileFormat'); |
65 |
gforget |
1.1 |
end; |
66 |
|
|
|
67 |
gforget |
1.6 |
%the various grid fields: |
68 |
gforget |
1.9 |
if mygrid.memoryLimit==0; |
69 |
|
|
list0={'XC','XG','YC','YG','RAC','RAZ','DXC','DXG','DYC','DYG','hFacC','hFacS','hFacW','Depth'}; |
70 |
|
|
elseif mygrid.memoryLimit==1; |
71 |
|
|
list0={'XC','XG','YC','YG','RAC','RAZ','DXC','DXG','DYC','DYG','hFacC','Depth'}; |
72 |
|
|
elseif mygrid.memoryLimit==2; |
73 |
|
|
list0={'XC','YC'}; |
74 |
|
|
end; |
75 |
|
|
|
76 |
gforget |
1.1 |
for iFld=1:length(list0); |
77 |
gforget |
1.8 |
eval(['mygrid.' list0{iFld} '=rdmds2gcmfaces([dirGrid ''' list0{iFld} '*'']);']); |
78 |
gforget |
1.1 |
end; |
79 |
|
|
|
80 |
gforget |
1.9 |
%the vertical grid |
81 |
|
|
list0={'RC','RF','DRC','DRF'}; |
82 |
|
|
for iFld=1:length(list0); |
83 |
|
|
eval(['mygrid.' list0{iFld} '=squeeze(rdmds([dirGrid ''' list0{iFld} '*'']));']); |
84 |
|
|
end; |
85 |
|
|
|
86 |
|
|
%grid orientation |
87 |
|
|
if mygrid.memoryLimit<2; |
88 |
|
|
list0={'AngleCS','AngleSN'}; |
89 |
|
|
test0=~isempty(dir([dirGrid 'AngleCS*'])); |
90 |
|
|
if test0; |
91 |
|
|
for iFld=1:length(list0); |
92 |
|
|
eval(['mygrid.' list0{iFld} '=rdmds2gcmfaces([dirGrid ''' list0{iFld} '*'']);']); |
93 |
|
|
end; |
94 |
|
|
else; |
95 |
|
|
warning('\n AngleCS/AngleSN not found; set to 1/0 assuming lat/lon grid.\n'); |
96 |
|
|
mygrid.AngleCS=mygrid.XC; mygrid.AngleCS(:)=1; |
97 |
|
|
mygrid.AngleSN=mygrid.XC; mygrid.AngleSN(:)=0; |
98 |
gforget |
1.8 |
end; |
99 |
gforget |
1.4 |
end; |
100 |
|
|
|
101 |
gforget |
1.9 |
%grid masks |
102 |
|
|
if mygrid.memoryLimit<1; |
103 |
|
|
mygrid.hFacCsurf=mygrid.hFacC; |
104 |
|
|
for ff=1:mygrid.hFacC.nFaces; mygrid.hFacCsurf{ff}=mygrid.hFacC{ff}(:,:,1); end; |
105 |
|
|
|
106 |
|
|
mskC=mygrid.hFacC; mskC(mskC==0)=NaN; mskC(mskC>0)=1; mygrid.mskC=mskC; |
107 |
|
|
mskW=mygrid.hFacW; mskW(mskW==0)=NaN; mskW(mskW>0)=1; mygrid.mskW=mskW; |
108 |
|
|
mskS=mygrid.hFacS; mskS(mskS==0)=NaN; mskS(mskS>0)=1; mygrid.mskS=mskS; |
109 |
gforget |
1.1 |
end; |
110 |
|
|
|
111 |
gforget |
1.9 |
%zonal mean and sections needed for transport computations |
112 |
|
|
if mygrid.memoryLimit<1; |
113 |
|
|
if ~isfield(mygrid,'mygrid.LATS_MASKS'); |
114 |
|
|
gcmfaces_lines_zonal; |
115 |
|
|
mygrid.LATS=[mygrid.LATS_MASKS.lat]'; |
116 |
|
|
end; |
117 |
|
|
if ~isfield(mygrid,'LINES_MASKS'); |
118 |
|
|
[lonPairs,latPairs,names]=line_greatC_TUV_MASKS_v4; |
119 |
|
|
gcmfaces_lines_transp(lonPairs,latPairs,names); |
120 |
|
|
end; |
121 |
|
|
end; |
122 |
gforget |
1.2 |
|
123 |
gforget |
1.8 |
%to allow convert2gcmfaces/doFast: |
124 |
gforget |
1.9 |
if isempty(mygrid.facesExpand)&mygrid.memoryLimit<2; |
125 |
|
|
tmp1=convert2gcmfaces(mygrid.XC); |
126 |
|
|
tmp1(:)=[1:length(tmp1(:))]; |
127 |
|
|
nn=length(tmp1(:)); |
128 |
|
|
mygrid.gcm2faces=convert2gcmfaces(tmp1); |
129 |
|
|
mygrid.faces2gcmSize=size(tmp1); |
130 |
|
|
mygrid.faces2gcm=convert2gcmfaces(tmp1); |
131 |
|
|
for iFace=1:mygrid.nFaces; |
132 |
|
|
n=length(mygrid.gcm2faces{iFace}(:)); |
133 |
|
|
mygrid.faces2gcm{iFace}=mygrid.gcm2faces{iFace}(:); |
134 |
|
|
mygrid.gcm2faces{iFace}=sparse([1:n],mygrid.gcm2faces{iFace}(:),ones(1,n),n,nn); |
135 |
|
|
end; |
136 |
|
|
mygrid.gcm2facesFast=true; |
137 |
gforget |
1.6 |
end; |
138 |
|
|
|
139 |
gforget |
1.1 |
|