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

Annotation 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.3 - (hide annotations) (download)
Wed Jun 19 16:04:36 2013 UTC (12 years, 1 month ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65r, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u
Changes since 1.2: +15 -10 lines
- convert2widefaces.m : use missVal as defined in grid_load (0 except for grid itself)
- convert2widefaces.m : add fourth dimension.
- grid_load.m : define missVal for use in convert2widefaces.m
- grid_load.m : fix cropped grid if needed.
- grid_load_native.m : add doWarn switch, allow interative spec of grid file names.

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     %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 gforget 1.3 if isempty(whos('doWarn')); doWarn=1; end;
26    
27 gforget 1.1 global mygrid;
28 gforget 1.2 mygrid.dirGrid=dirGrid;
29     mygrid.nFaces=nFaces;
30     mygrid.fileFormat='native';
31 gforget 1.1
32 gforget 1.3 %search for native grid files
33 gforget 1.1 files=dir([dirGrid '*bin']);
34 gforget 1.3 while length(files)~=nFaces;
35     fprintf('dirGrid does not contain the expected number of ''*.bin'' grid files\n');
36     nm=input('please specify file name pattern for the native grid such as ''llc*.bin''\n');
37     files=dir([dirGrid nm]);
38     end;
39 gforget 1.2
40     %discard intermediate step grid files:
41     tmp1=[];
42 gforget 1.1 for ii=1:length(files);
43     if isempty(strfind(files(ii).name,'FM')); tmp1=[tmp1;ii]; end;
44     end;
45     files=files(tmp1);
46    
47 gforget 1.2 %list fields of interest and their sizes
48 gforget 1.1 list_fields2={'XC','YC','DXF','DYF','RAC','XG','YG','DXV','DYU','RAZ',...
49     'DXC','DYC','RAW','RAS','DXG','DYG'};
50     list_fields={'xC','yC','dxF','dyF','rA','xG','yG','dxV','dyU','rAz',...
51     'dxC','dyC','rAw','rAs','dxG','dyG'};
52     list_x={'xC','xC','xC','xC','xC','xG','xG','xG','xG','xG',...
53     'xW','xS','xW','xS','xS','xW'};
54     list_y={'yC','yC','yC','yC','yC','yG','yG','yG','yG','yG',...
55     'yW','yS','yW','yS','yS','yW'};
56     list_ni={'ni','ni','ni','ni','ni','ni+1','ni+1','ni+1','ni+1','ni+1',...
57     'ni+1','ni','ni+1','ni','ni','ni+1'};
58     list_nj={'nj','nj','nj','nj','nj','nj+1','nj+1','nj+1','nj+1','nj+1',...
59     'nj','nj+1','nj','nj+1','nj+1','nj'};
60    
61 gforget 1.2 if nFaces~=length(files);
62     error('wrong specification of nFaces');
63     else;
64     Nfaces=length(files);
65     end;
66 gforget 1.1
67     for iFile=1:Nfaces;
68     tmp1=files(iFile).name;
69 gforget 1.2 %we need to know the face dimensions
70     if ~isempty(strfind(dirGrid,'cs32_tutorial_held_suarez_cs'))|...
71     ~isempty(strfind(dirGrid,'GRIDcube'));%cs32
72 gforget 1.1 ni=32; nj=32;
73 gforget 1.2 else;%get the face dimensions form the file name
74 gforget 1.1 tmp2=strfind(tmp1,'_');
75     ni=str2num(tmp1(tmp2(2)+1:tmp2(3)-1));
76     nj=str2num(tmp1(tmp2(3)+1:end-4));
77     end;
78     if iFile==1; MM=ni; end;
79     fid=fopen([dirGrid files(iFile).name],'r','b');
80     for iFld=1:length(list_fields);
81     eval(['nni=' list_ni{iFld} ';']);
82     eval(['nnj=' list_nj{iFld} ';']);
83     tmp1=fread(fid,[ni+1 nj+1],'float64');
84 gforget 1.2 if useChrisFormat;
85 gforget 1.1 eval([list_fields{iFld} '{' num2str(iFile) '}.vals=tmp1(1:nni,1:nnj);']);
86     eval([list_fields{iFld} '{' num2str(iFile) '}.x=''' list_x{iFld} ''';']);
87     end;
88 gforget 1.2 if iFile==1; eval(['mygrid.' list_fields2{iFld} '=gcmfaces;']); end;
89     eval(['mygrid.' list_fields2{iFld} '{iFile}=tmp1(1:ni,1:nj);']);
90 gforget 1.1 end;
91     fclose(fid);
92 gforget 1.2 if useChrisFormat;
93 gforget 1.1 xS{iFile}.vals=(xG{iFile}.vals(2:end,:)+xG{iFile}.vals(1:end-1,:))/2;
94     yS{iFile}.vals=(yG{iFile}.vals(2:end,:)+yG{iFile}.vals(1:end-1,:))/2;
95     xW{iFile}.vals=(xG{iFile}.vals(:,2:end)+xG{iFile}.vals(:,1:end-1))/2;
96     yW{iFile}.vals=(yG{iFile}.vals(:,2:end)+yG{iFile}.vals(:,1:end-1))/2;
97     end;
98     end;
99 gforget 1.2
100 gforget 1.3 if doWarn;
101     list0={'hFacC','hFacS','hFacW','Depth','AngleCS','AngleSN'};
102     for ff=1:length(list0); warning(['native file miss ' list0{ff}]); end;
103     fprintf('\n\n which will severely limit diagnostic computations.\n');
104     fprintf(' So you may want to get a full grid from an MITgcm run.\n');
105     end;
106 gforget 1.2

  ViewVC Help
Powered by ViewVC 1.1.22