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

Contents of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/grid_load_native.m

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


Revision 1.6 - (show annotations) (download)
Fri Mar 17 17:41:56 2017 UTC (8 years, 4 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint66f, checkpoint66e, checkpoint66o, HEAD
Changes since 1.5: +21 -4 lines
o grid_load_native.m
 - revise help section
 - add option to initialize hFacC etc. to 1 when called in stand-alone mode (i.e., with 3 arguments)
 - set gcm2facesFast,memoryLimit,facesExpand to false,0,[].
 - assign ioSize based on convert2gcmfaces(mygrid.XC) size (convert2gcmfaces now calls
   convert2array when fileFormat is 'native ') and facesSize based on mygrid.XC face sizes.
o rdmds2gcmfaces.m
 - allow for secondary output from rdmds.m
o write2nctiles.m
 - comment out definition of never-used itxt dimension (was copied from MITprof?)
o convert2gcmfaces.m
 - use convert2array convert2gcmfaces when mygrid.fileFormat is 'native'

1 function []=grid_load_native(dirGrid,nFaces,doWarn);
2 %object: load NATIVE FORMAT grid information, convert it to gcmfaces format
3 % and encapsulate it in the global mygrid structure.
4 %inputs: EITHER
5 % dirGrid is the directory where the grid files (gcm input) can be found.
6 % nFaces is the number of faces in this gcm set-up of current interest.
7 % 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 % 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
13
14 global mygrid;
15
16 alsoDoTheOldWay=0;
17 if alsoDoTheOldWay;
18 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
22 if isempty(whos('doWarn')); doWarn=1; end;
23
24 if nargin>0;
25 mygrid=[];
26 mygrid.dirGrid=dirGrid;
27 mygrid.nFaces=nFaces;
28 mygrid.fileFormat='native';
29 mygrid.gcm2facesFast=false;
30 mygrid.memoryLimit=0;
31 mygrid.facesExpand=[];
32 end;
33
34 %search for native grid files
35 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 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
44 %discard intermediate step grid files:
45 tmp1=[];
46 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 %list fields of interest and their sizes
52 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 if mygrid.nFaces~=length(files);
66 error('wrong specification of nFaces');
67 else;
68 Nfaces=length(files);
69 end;
70
71 for iFile=1:Nfaces;
72 tmp1=files(iFile).name;
73 %get face dimensions
74 if ~isempty(strfind(mygrid.dirGrid,'cs32_tutorial_held_suarez_cs'))|...
75 ~isempty(strfind(mygrid.dirGrid,'GRIDcube'))|...
76 ~isempty(strfind(tmp1,'cs32'));%special case of cs32
77 ni=32; nj=32;
78 elseif strcmp(tmp1(end-2:end),'bin');%get face dimension from file name
79 tmp2=strfind(tmp1,'_');
80 ni=str2num(tmp1(tmp2(2)+1:tmp2(3)-1));
81 nj=str2num(tmp1(tmp2(3)+1:end-4));
82 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 end;
87 if iFile==1&alsoDoTheOldWay; MM=ni; end;
88 fid=fopen([mygrid.dirGrid files(iFile).name],'r','b');
89 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 if alsoDoTheOldWay;
94 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 if ~isfield(mygrid,list_fields2{iFld}); eval(['mygrid.' list_fields2{iFld} '=gcmfaces;']); end;
98 eval(['mygrid.' list_fields2{iFld} '{iFile}=tmp1(1:ni,1:nj);']);
99 end;
100 fclose(fid);
101 if alsoDoTheOldWay;
102 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
109 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 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 end;
136

  ViewVC Help
Powered by ViewVC 1.1.22