/[MITgcm]/MITgcm_contrib/mitgcm_tools/loadgrid.m
ViewVC logotype

Annotation of /MITgcm_contrib/mitgcm_tools/loadgrid.m

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


Revision 1.1.1.1 - (hide annotations) (download) (vendor branch)
Thu Sep 25 13:42:11 2003 UTC (21 years, 9 months ago) by adcroft
Branch: adcroft
CVS Tags: initial
Changes since 1.1: +0 -0 lines
Checking in Adcroft's matlab scripts for posterity.

1 adcroft 1.1 function [GRID] = loadgrid(varargin)
2     %loadgrid()
3     %loadgrid(DIRECTORY)
4     %
5     %Reads MITgcm output files and input "data" file to create a GRID structure
6     %If DIRECTORY is not specified the current working directory is used.
7     %
8     %e.g.
9     %>> GRID=loadgrid
10     %GRID =
11     % drf: [50 70 100 140 190 240 290 340 390 440 490 540 590 640 690]
12     % drc: [25 60 85 120 165 215 265 315 365 415 465 515 565 615 665]
13     % rf: [1x16 double]
14     % rc: [1x15 double]
15     % xc: [90x40 double]
16     % yc: [90x40 double]
17     % xg: [90x40 double]
18     % yg: [90x40 double]
19     % dxg: [90x40 double]
20     % dyg: [90x40 double]
21     % rac: [90x40 double]
22     % hfacc: [90x40x15 double]
23     % hfacw: [90x40x15 double]
24     % hfacs: [90x40x15 double]
25     % mskc: [90x40x15 double]
26     % mAtl: [90x40 double]
27     % matl: [90x40 double]
28     % mPac: [90x40 double]
29     % mpac: [90x40 double]
30     % msoc: [90x40 double]
31     %>> GRID2=loadgrid('/scratch/john/run2/');
32     %
33     %Most elements of the structure are named to corresponding to MITgcm
34     %variables.
35     %
36     %Lower case regional masks (matl, mpac and msoc) denote Atlantic and Pacific
37     %Southern Ocean regions only and are exclusive (i.e. matl does not extend
38     %into the Southern Ocean).
39     %Upper case regional masks (mAtl and mPac) denotes sectors and do include the
40     %Southern Ocean.
41     % sum(sum( GRID.mskc(:,:,1) )) = sum( GRID.mAtl(:) + GRID.mPac(:) )
42     % = sum( GRID.matl(:) + GRID.mpac(:) + GRID.msoc(:) )
43     %
44     %Written by adcroft@mit.edu, 2001
45     %$Header:
46    
47     if nargin==0
48     Dir='./';
49     elseif nargin==1
50     Dir=[varargin{1} '/'];
51     else
52     error('I don''t know what to do with the second argument');
53     end
54    
55     % Extract drF from "data" file
56     datafile=[Dir 'data'];
57     fid=fopen(datafile,'r');
58     if fid==-1
59     error(['Could not open file:' datafile ' for reading']);
60     end
61     fclose(fid);
62     drf=evalc([ ...
63     '!awk ''/[dD[eE][lL][rRzZpP]/,/XXX/ {printf "%s",$0}'' ' datafile ...
64     '| sed ''s/[dD][eE][lL][zZrRpP][ ]*=\([0-9,. ]*\).*/\1/'' ' ...
65     '| sed ''s/[ ]//g'' ' ...
66     '| sed ''s/,/ /g'' ' ...
67     ';'
68     ]);
69     eval(['drf=[' drf '];'])
70     drf=drf;
71     drc=(drf([1 1:end-1])+drf)/2; drc(1)=drc(1)/2;
72    
73     %% % Extract drC from output file
74     %% outputfile='output.txt';
75     %% drc=evalc(['!head -1000 ' outputfile ...
76     %% ' | awk ''/drC/,/;/ {print $3}'' -' ...
77     %% ' | egrep "e|E"' ...
78     %% ' | sed ''s/,//'' ']);
79     %% eval(['drc=[' drc '];'])
80     %% drc=drc';
81     %% % Extract drF from output file
82     %% drf=evalc('!head -1000 output.txt | awk "/drF/,/;/ {print \$3}" - | egrep "e|E" | sed s/,// ');
83     %% eval(['drf=[' drf '];'])
84     %% drf=drf';
85    
86     rf=-cumsum([0 drf]);
87     rc=-cumsum([drc]);
88    
89     GRID.drf=drf;
90     GRID.drc=drc;
91     GRID.rf=rf;
92     GRID.rc=rc;
93    
94     xc=rdmds([Dir 'XC']); GRID.xc=xc;
95     yc=rdmds([Dir 'YC']); GRID.yc=yc;
96     xg=rdmds([Dir 'XG']); GRID.xg=xg;
97     yg=rdmds([Dir 'YG']); GRID.yg=yg;
98    
99     dxg=rdmds([Dir 'DXG']); GRID.dxg=dxg;
100     dyg=rdmds([Dir 'DYG']); GRID.dyg=dyg;
101    
102     rac=rdmds([Dir 'RAC']); GRID.rac=rac;
103    
104     hfacc=rdmds([Dir 'hFacC']); GRID.hfacc=hfacc;
105     hfacw=rdmds([Dir 'hFacW']); GRID.hfacw=hfacw;
106     hfacs=rdmds([Dir 'hFacS']); GRID.hfacs=hfacs;
107    
108     mskc=hfacc; mskc(find(hfacc~=0))=1; GRID.mskc=mskc;
109    
110     mskc=mskc(:,:,1);
111     j=[];
112     %j=[j find( yc>-32.5 & xc>290 )'];
113     %j=[j find( yc>-32.5 & xc<25 )'];
114     j=[j find( xc>290 )'];
115     j=[j find( xc<25 & xc>290-360 )'];
116     j=[j find( yc>9 & yc<60 & (yc-9)+(xc-276)>0 )'];
117     j=[j find( yc>9 & yc<60 & (yc-9)+(xc-276+360)>0 & xc<30 )'];
118     j=[j find( yc>17 & yc<60 & xc>261 )'];
119     j=[j find( yc>50 & (yc-70)-(xc-270)<0 )'];
120     j=[j find( yc>31 & xc<38 & xc>-90 )'];
121     j=[j find( yc>31 & xc>360-90 )'];
122     j=[j find( yc>64 )'];
123     matl=0*mskc;
124     matl(j)=1;
125     matl=matl.*mskc;
126     GRID.mAtl=matl;
127    
128     j=[];
129     j=[j find( yc>-32.5 )'];
130     matl=0*mskc;
131     matl(j)=1;
132     matl=GRID.mAtl.*matl.*mskc;
133     GRID.matl=matl;
134    
135     mpac=(1-matl).*mskc;
136     j=[];
137     j=[j find( yc<65 )'];
138     mpac=0*mskc;
139     mpac(j)=1;
140     mpac=mpac.*mskc.*(1-GRID.mAtl);
141     GRID.mPac=mpac;
142    
143     j=[];
144     j=[j find( yc>-32.5 )'];
145     mpac=0*mskc;
146     mpac(j)=1;
147     mpac=GRID.mPac.*mpac.*mskc;
148     GRID.mpac=mpac;
149    
150     msoc=(1-matl).*(1-mpac).*mskc;
151     j=[];
152     j=[j find( yc<0 )'];
153     GRID.msoc=msoc.*mskc.*(1-mpac).*(1-matl);
154    

  ViewVC Help
Powered by ViewVC 1.1.22