1 |
gforget |
1.3 |
function []=grid_load_native(dirGrid,nFaces,doWarn); |
2 |
gforget |
1.2 |
%object: load NATIVE FORMAT grid information, convert it to gcmfaces format |
3 |
|
|
% and encapsulate it in the global mygrid structure. |
4 |
gforget |
1.4 |
%inputs: EITHER |
5 |
gforget |
1.6 |
% dirGrid is the directory where the grid files (gcm input) can be found. |
6 |
gforget |
1.2 |
% nFaces is the number of faces in this gcm set-up of current interest. |
7 |
gforget |
1.6 |
% doWarn; if doWarn==1 then warn user that mygrid is not complete (e.g. hFacC, |
8 |
|
|
% etc. are missing); if doWarn==0 then initialize hFacC etc. to 1 instead. |
9 |
gforget |
1.4 |
% OR |
10 |
|
|
% [] if mygrid has already read by grid_load.m from XC.data, YC.data, etc. |
11 |
|
|
% from which grid_load_native can get dirGrid and nFaces |
12 |
gforget |
1.1 |
|
13 |
gforget |
1.4 |
|
14 |
|
|
global mygrid; |
15 |
|
|
|
16 |
|
|
alsoDoTheOldWay=0; |
17 |
|
|
if alsoDoTheOldWay; |
18 |
gforget |
1.2 |
global MM Nfaces; |
19 |
|
|
global dyG dxG dxF dyF dxC dyC dyU dxV rA rAw rAs rAz xC yC xG yG xS yS xW yW; |
20 |
|
|
end; |
21 |
gforget |
1.1 |
|
22 |
gforget |
1.3 |
if isempty(whos('doWarn')); doWarn=1; end; |
23 |
|
|
|
24 |
gforget |
1.4 |
if nargin>0; |
25 |
|
|
mygrid=[]; |
26 |
|
|
mygrid.dirGrid=dirGrid; |
27 |
|
|
mygrid.nFaces=nFaces; |
28 |
|
|
mygrid.fileFormat='native'; |
29 |
gforget |
1.6 |
mygrid.gcm2facesFast=false; |
30 |
|
|
mygrid.memoryLimit=0; |
31 |
|
|
mygrid.facesExpand=[]; |
32 |
gforget |
1.4 |
end; |
33 |
gforget |
1.1 |
|
34 |
gforget |
1.3 |
%search for native grid files |
35 |
gforget |
1.4 |
files=dir([mygrid.dirGrid 'grid_cs32*bin']); |
36 |
|
|
if isempty(files); files=dir([mygrid.dirGrid 'tile*.mitgrid']); end; |
37 |
|
|
if isempty(files); files=dir([dirGrid '*bin']); end; |
38 |
|
|
while length(files)~=mygrid.nFaces; |
39 |
gforget |
1.3 |
fprintf('dirGrid does not contain the expected number of ''*.bin'' grid files\n'); |
40 |
|
|
nm=input('please specify file name pattern for the native grid such as ''llc*.bin''\n'); |
41 |
|
|
files=dir([dirGrid nm]); |
42 |
|
|
end; |
43 |
gforget |
1.2 |
|
44 |
|
|
%discard intermediate step grid files: |
45 |
|
|
tmp1=[]; |
46 |
gforget |
1.1 |
for ii=1:length(files); |
47 |
|
|
if isempty(strfind(files(ii).name,'FM')); tmp1=[tmp1;ii]; end; |
48 |
|
|
end; |
49 |
|
|
files=files(tmp1); |
50 |
|
|
|
51 |
gforget |
1.2 |
%list fields of interest and their sizes |
52 |
gforget |
1.1 |
list_fields2={'XC','YC','DXF','DYF','RAC','XG','YG','DXV','DYU','RAZ',... |
53 |
|
|
'DXC','DYC','RAW','RAS','DXG','DYG'}; |
54 |
|
|
list_fields={'xC','yC','dxF','dyF','rA','xG','yG','dxV','dyU','rAz',... |
55 |
|
|
'dxC','dyC','rAw','rAs','dxG','dyG'}; |
56 |
|
|
list_x={'xC','xC','xC','xC','xC','xG','xG','xG','xG','xG',... |
57 |
|
|
'xW','xS','xW','xS','xS','xW'}; |
58 |
|
|
list_y={'yC','yC','yC','yC','yC','yG','yG','yG','yG','yG',... |
59 |
|
|
'yW','yS','yW','yS','yS','yW'}; |
60 |
|
|
list_ni={'ni','ni','ni','ni','ni','ni+1','ni+1','ni+1','ni+1','ni+1',... |
61 |
|
|
'ni+1','ni','ni+1','ni','ni','ni+1'}; |
62 |
|
|
list_nj={'nj','nj','nj','nj','nj','nj+1','nj+1','nj+1','nj+1','nj+1',... |
63 |
|
|
'nj','nj+1','nj','nj+1','nj+1','nj'}; |
64 |
|
|
|
65 |
gforget |
1.4 |
if mygrid.nFaces~=length(files); |
66 |
gforget |
1.2 |
error('wrong specification of nFaces'); |
67 |
|
|
else; |
68 |
|
|
Nfaces=length(files); |
69 |
|
|
end; |
70 |
gforget |
1.1 |
|
71 |
|
|
for iFile=1:Nfaces; |
72 |
|
|
tmp1=files(iFile).name; |
73 |
gforget |
1.4 |
%get face dimensions |
74 |
|
|
if ~isempty(strfind(mygrid.dirGrid,'cs32_tutorial_held_suarez_cs'))|... |
75 |
gforget |
1.5 |
~isempty(strfind(mygrid.dirGrid,'GRIDcube'))|... |
76 |
|
|
~isempty(strfind(tmp1,'cs32'));%special case of cs32 |
77 |
gforget |
1.1 |
ni=32; nj=32; |
78 |
gforget |
1.4 |
elseif strcmp(tmp1(end-2:end),'bin');%get face dimension from file name |
79 |
gforget |
1.1 |
tmp2=strfind(tmp1,'_'); |
80 |
|
|
ni=str2num(tmp1(tmp2(2)+1:tmp2(3)-1)); |
81 |
|
|
nj=str2num(tmp1(tmp2(3)+1:end-4)); |
82 |
gforget |
1.4 |
elseif isfield(mygrid,'XC');%get face dimention from previous grid load |
83 |
|
|
[ni,nj]=size(mygrid.XC{iFile}); |
84 |
|
|
else; |
85 |
|
|
error('could not determine face size'); |
86 |
gforget |
1.1 |
end; |
87 |
gforget |
1.4 |
if iFile==1&alsoDoTheOldWay; MM=ni; end; |
88 |
|
|
fid=fopen([mygrid.dirGrid files(iFile).name],'r','b'); |
89 |
gforget |
1.1 |
for iFld=1:length(list_fields); |
90 |
|
|
eval(['nni=' list_ni{iFld} ';']); |
91 |
|
|
eval(['nnj=' list_nj{iFld} ';']); |
92 |
|
|
tmp1=fread(fid,[ni+1 nj+1],'float64'); |
93 |
gforget |
1.4 |
if alsoDoTheOldWay; |
94 |
gforget |
1.1 |
eval([list_fields{iFld} '{' num2str(iFile) '}.vals=tmp1(1:nni,1:nnj);']); |
95 |
|
|
eval([list_fields{iFld} '{' num2str(iFile) '}.x=''' list_x{iFld} ''';']); |
96 |
|
|
end; |
97 |
gforget |
1.4 |
if ~isfield(mygrid,list_fields2{iFld}); eval(['mygrid.' list_fields2{iFld} '=gcmfaces;']); end; |
98 |
gforget |
1.2 |
eval(['mygrid.' list_fields2{iFld} '{iFile}=tmp1(1:ni,1:nj);']); |
99 |
gforget |
1.1 |
end; |
100 |
|
|
fclose(fid); |
101 |
gforget |
1.4 |
if alsoDoTheOldWay; |
102 |
gforget |
1.1 |
xS{iFile}.vals=(xG{iFile}.vals(2:end,:)+xG{iFile}.vals(1:end-1,:))/2; |
103 |
|
|
yS{iFile}.vals=(yG{iFile}.vals(2:end,:)+yG{iFile}.vals(1:end-1,:))/2; |
104 |
|
|
xW{iFile}.vals=(xG{iFile}.vals(:,2:end)+xG{iFile}.vals(:,1:end-1))/2; |
105 |
|
|
yW{iFile}.vals=(yG{iFile}.vals(:,2:end)+yG{iFile}.vals(:,1:end-1))/2; |
106 |
|
|
end; |
107 |
|
|
end; |
108 |
gforget |
1.2 |
|
109 |
gforget |
1.6 |
if nargin>0; |
110 |
|
|
mygrid.ioSize=size(convert2gcmfaces(mygrid.XC)); |
111 |
|
|
mygrid.facesSize=[]; |
112 |
|
|
for ii=1:mygrid.nFaces; mygrid.facesSize=[mygrid.facesSize; size(mygrid.XC{ii})]; end; |
113 |
|
|
end; |
114 |
|
|
|
115 |
|
|
if nargin>0&doWarn==0; |
116 |
|
|
warning('initializing hFacC, Depth, DRF, etc. to 1'); |
117 |
|
|
list0={'hFacC','hFacS','hFacW','Depth','mskC','mskW','mskS'}; |
118 |
|
|
for ii=1:length(list0); mygrid.(list0{ii})=1+0*mygrid.XC; end; |
119 |
|
|
mygrid.RC=-0.5; mygrid.RF=[0 -1]; mygrid.DRC=1; mygrid.DRF=1; |
120 |
|
|
end; |
121 |
|
|
|
122 |
|
|
if nargin>0&doWarn; |
123 |
|
|
list0={'hFacC','hFacS','hFacW','mskC','mskW','mskS','Depth','AngleCS','AngleSN'}; |
124 |
gforget |
1.4 |
nWarn=0; |
125 |
|
|
for ff=1:length(list0); |
126 |
|
|
if ~isfield(mygrid,list0{ff}); |
127 |
|
|
warning(['The following variable is missing in mygrid: ' list0{ff}]); |
128 |
|
|
nWarn=nWarn+1; |
129 |
|
|
end; |
130 |
|
|
end; |
131 |
|
|
if nWarn>0; |
132 |
|
|
warning('Missing these variables may restrict diagnostic possibilities.'); |
133 |
|
|
nWarn |
134 |
|
|
end; |
135 |
gforget |
1.3 |
end; |
136 |
gforget |
1.2 |
|