/[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.1 - (hide annotations) (download)
Wed Feb 10 14:46:48 2010 UTC (15 years, 5 months ago) by gforget
Branch: MAIN
matlab_class: backward compatibility routines

1 gforget 1.1 function []=mitgcmmygrid_read(dirGrid,gridType,varargin);
2     %read the mygrid from the input (not mds) mygrid file
3     %this routine is an adaptation of
4     %/net/ross/raid2/gforget/mygrids/gael_code_v2/faces2mitgcm/mitgcmmygrid_read.m
5     %examples of dirGrid:
6     %dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/cube_FM/cube_96/';
7     %dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/llcRegLatLon/llc_96/';
8     %dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/llpcRegLatLon/llpc_96/';
9     %dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/llcMoreTrop/eccollc_96/';
10     %dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/llcRegLatLon/llc_540/';
11     %dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/cube_FM/cube_32/';
12     %dirGrid='/net/weddell/raid3/gforget/mygrids/mygridCompleted/cs32_tutorial_held_suarez_cs/';
13    
14     if nargin==3; useNativeFormat=varargin{1}; else; useNativeFormat=0; end;
15    
16     if useNativeFormat==1;
17     global MM Nfaces;
18     global dyG dxG dxF dyF dxC dyC dyU dxV rA rAw rAs rAz xC yC xG yG xS yS xW yW;
19     else;
20     global mygrid;
21     end;
22    
23     files=dir([dirGrid '*bin']);
24     tmp1=[];
25     for ii=1:length(files);
26     if isempty(strfind(files(ii).name,'FM')); tmp1=[tmp1;ii]; end;
27     end;
28     files=files(tmp1);
29    
30    
31     list_fields2={'XC','YC','DXF','DYF','RAC','XG','YG','DXV','DYU','RAZ',...
32     'DXC','DYC','RAW','RAS','DXG','DYG'};
33     list_fields={'xC','yC','dxF','dyF','rA','xG','yG','dxV','dyU','rAz',...
34     'dxC','dyC','rAw','rAs','dxG','dyG'};
35     list_x={'xC','xC','xC','xC','xC','xG','xG','xG','xG','xG',...
36     'xW','xS','xW','xS','xS','xW'};
37     list_y={'yC','yC','yC','yC','yC','yG','yG','yG','yG','yG',...
38     'yW','yS','yW','yS','yS','yW'};
39     list_ni={'ni','ni','ni','ni','ni','ni+1','ni+1','ni+1','ni+1','ni+1',...
40     'ni+1','ni','ni+1','ni','ni','ni+1'};
41     list_nj={'nj','nj','nj','nj','nj','nj+1','nj+1','nj+1','nj+1','nj+1',...
42     'nj','nj+1','nj','nj+1','nj+1','nj'};
43    
44     Nfaces=length(files);
45    
46     for iFile=1:Nfaces;
47     tmp1=files(iFile).name;
48     if strfind(dirGrid,'cs32_tutorial_held_suarez_cs');
49     ni=32; nj=32;
50     else;
51     tmp2=strfind(tmp1,'_');
52     ni=str2num(tmp1(tmp2(2)+1:tmp2(3)-1));
53     nj=str2num(tmp1(tmp2(3)+1:end-4));
54     end;
55     if iFile==1; MM=ni; end;
56     fid=fopen([dirGrid files(iFile).name],'r','b');
57     for iFld=1:length(list_fields);
58     eval(['nni=' list_ni{iFld} ';']);
59     eval(['nnj=' list_nj{iFld} ';']);
60     tmp1=fread(fid,[ni+1 nj+1],'float64');
61     if useNativeFormat;
62     eval([list_fields{iFld} '{' num2str(iFile) '}.vals=tmp1(1:nni,1:nnj);']);
63     eval([list_fields{iFld} '{' num2str(iFile) '}.x=''' list_x{iFld} ''';']);
64     else;
65     if iFile==1; eval(['mygrid.' list_fields2{iFld} '=gcmfaces(Nfaces,''' gridType ''');']); end;
66     eval(['mygrid.' list_fields2{iFld} '{iFile}=tmp1(1:ni,1:nj);']);
67     end;
68     end;
69     fclose(fid);
70     if useNativeFormat;
71     xS{iFile}.vals=(xG{iFile}.vals(2:end,:)+xG{iFile}.vals(1:end-1,:))/2;
72     yS{iFile}.vals=(yG{iFile}.vals(2:end,:)+yG{iFile}.vals(1:end-1,:))/2;
73     xW{iFile}.vals=(xG{iFile}.vals(:,2:end)+xG{iFile}.vals(:,1:end-1))/2;
74     yW{iFile}.vals=(yG{iFile}.vals(:,2:end)+yG{iFile}.vals(:,1:end-1))/2;
75     end;
76     end;

  ViewVC Help
Powered by ViewVC 1.1.22