1 |
gforget |
1.2 |
function []=grid_load_native(dirGrid,nFaces); |
2 |
|
|
%object: load NATIVE FORMAT 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 |
|
|
% |
7 |
|
|
%note: - originally from /net/ross/raid2/gforget/mygrids/gael_code_v2/faces2mitgcm/mitgcmmygrid_read.m |
8 |
|
|
% - the hardcoded useChrisFormat allows to recover Chris' format used by the grid generation routines |
9 |
|
|
% |
10 |
gforget |
1.1 |
%examples of dirGrid: |
11 |
|
|
%dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/cube_FM/cube_96/'; |
12 |
|
|
%dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/llcRegLatLon/llc_96/'; |
13 |
|
|
%dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/llpcRegLatLon/llpc_96/'; |
14 |
|
|
%dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/llcMoreTrop/eccollc_96/'; |
15 |
|
|
%dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/llcRegLatLon/llc_540/'; |
16 |
|
|
%dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/cube_FM/cube_32/'; |
17 |
|
|
%dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/cs32_tutorial_held_suarez_cs/'; |
18 |
|
|
|
19 |
gforget |
1.2 |
useChrisFormat=1; |
20 |
|
|
if useChrisFormat==1; |
21 |
|
|
global MM Nfaces; |
22 |
|
|
global dyG dxG dxF dyF dxC dyC dyU dxV rA rAw rAs rAz xC yC xG yG xS yS xW yW; |
23 |
|
|
end; |
24 |
gforget |
1.1 |
|
25 |
|
|
global mygrid; |
26 |
gforget |
1.2 |
mygrid.dirGrid=dirGrid; |
27 |
|
|
mygrid.nFaces=nFaces; |
28 |
|
|
mygrid.fileFormat='native'; |
29 |
gforget |
1.1 |
|
30 |
|
|
files=dir([dirGrid '*bin']); |
31 |
gforget |
1.2 |
|
32 |
|
|
%discard intermediate step grid files: |
33 |
|
|
tmp1=[]; |
34 |
gforget |
1.1 |
for ii=1:length(files); |
35 |
|
|
if isempty(strfind(files(ii).name,'FM')); tmp1=[tmp1;ii]; end; |
36 |
|
|
end; |
37 |
|
|
files=files(tmp1); |
38 |
|
|
|
39 |
gforget |
1.2 |
%list fields of interest and their sizes |
40 |
gforget |
1.1 |
list_fields2={'XC','YC','DXF','DYF','RAC','XG','YG','DXV','DYU','RAZ',... |
41 |
|
|
'DXC','DYC','RAW','RAS','DXG','DYG'}; |
42 |
|
|
list_fields={'xC','yC','dxF','dyF','rA','xG','yG','dxV','dyU','rAz',... |
43 |
|
|
'dxC','dyC','rAw','rAs','dxG','dyG'}; |
44 |
|
|
list_x={'xC','xC','xC','xC','xC','xG','xG','xG','xG','xG',... |
45 |
|
|
'xW','xS','xW','xS','xS','xW'}; |
46 |
|
|
list_y={'yC','yC','yC','yC','yC','yG','yG','yG','yG','yG',... |
47 |
|
|
'yW','yS','yW','yS','yS','yW'}; |
48 |
|
|
list_ni={'ni','ni','ni','ni','ni','ni+1','ni+1','ni+1','ni+1','ni+1',... |
49 |
|
|
'ni+1','ni','ni+1','ni','ni','ni+1'}; |
50 |
|
|
list_nj={'nj','nj','nj','nj','nj','nj+1','nj+1','nj+1','nj+1','nj+1',... |
51 |
|
|
'nj','nj+1','nj','nj+1','nj+1','nj'}; |
52 |
|
|
|
53 |
gforget |
1.2 |
if nFaces~=length(files); |
54 |
|
|
error('wrong specification of nFaces'); |
55 |
|
|
else; |
56 |
|
|
Nfaces=length(files); |
57 |
|
|
end; |
58 |
gforget |
1.1 |
|
59 |
|
|
for iFile=1:Nfaces; |
60 |
|
|
tmp1=files(iFile).name; |
61 |
gforget |
1.2 |
%we need to know the face dimensions |
62 |
|
|
if ~isempty(strfind(dirGrid,'cs32_tutorial_held_suarez_cs'))|... |
63 |
|
|
~isempty(strfind(dirGrid,'GRIDcube'));%cs32 |
64 |
gforget |
1.1 |
ni=32; nj=32; |
65 |
gforget |
1.2 |
else;%get the face dimensions form the file name |
66 |
gforget |
1.1 |
tmp2=strfind(tmp1,'_'); |
67 |
|
|
ni=str2num(tmp1(tmp2(2)+1:tmp2(3)-1)); |
68 |
|
|
nj=str2num(tmp1(tmp2(3)+1:end-4)); |
69 |
|
|
end; |
70 |
|
|
if iFile==1; MM=ni; end; |
71 |
|
|
fid=fopen([dirGrid files(iFile).name],'r','b'); |
72 |
|
|
for iFld=1:length(list_fields); |
73 |
|
|
eval(['nni=' list_ni{iFld} ';']); |
74 |
|
|
eval(['nnj=' list_nj{iFld} ';']); |
75 |
|
|
tmp1=fread(fid,[ni+1 nj+1],'float64'); |
76 |
gforget |
1.2 |
if useChrisFormat; |
77 |
gforget |
1.1 |
eval([list_fields{iFld} '{' num2str(iFile) '}.vals=tmp1(1:nni,1:nnj);']); |
78 |
|
|
eval([list_fields{iFld} '{' num2str(iFile) '}.x=''' list_x{iFld} ''';']); |
79 |
|
|
end; |
80 |
gforget |
1.2 |
if iFile==1; eval(['mygrid.' list_fields2{iFld} '=gcmfaces;']); end; |
81 |
|
|
eval(['mygrid.' list_fields2{iFld} '{iFile}=tmp1(1:ni,1:nj);']); |
82 |
gforget |
1.1 |
end; |
83 |
|
|
fclose(fid); |
84 |
gforget |
1.2 |
if useChrisFormat; |
85 |
gforget |
1.1 |
xS{iFile}.vals=(xG{iFile}.vals(2:end,:)+xG{iFile}.vals(1:end-1,:))/2; |
86 |
|
|
yS{iFile}.vals=(yG{iFile}.vals(2:end,:)+yG{iFile}.vals(1:end-1,:))/2; |
87 |
|
|
xW{iFile}.vals=(xG{iFile}.vals(:,2:end)+xG{iFile}.vals(:,1:end-1))/2; |
88 |
|
|
yW{iFile}.vals=(yG{iFile}.vals(:,2:end)+yG{iFile}.vals(:,1:end-1))/2; |
89 |
|
|
end; |
90 |
|
|
end; |
91 |
gforget |
1.2 |
|
92 |
|
|
list0={'hFacC','hFacS','hFacW','Depth','AngleCS','AngleSN'}; |
93 |
|
|
for ff=1:length(list0); warning(['native file miss ' list0{ff}]); end; |
94 |
|
|
fprintf('\n\n which will severely limit diagnostic computations.\n'); |
95 |
|
|
fprintf(' So you may want to get a full grid from an MITgcm run.\n'); |
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|