/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/profiles_misc/model_load.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_misc/model_load.m

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


Revision 1.1 - (show annotations) (download)
Wed Apr 13 21:16:01 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
new capability: interpolation and storage of collocated model profiles
in a MITprof netcdf file. Successfully tested with an annual T/S climatology of SOSE59.

1 function [grid,atlas]=model_load(model,varargin);
2 % [grid,atlas]=model_load(model,[reload]);
3 %
4 % model is a string used to select the model to be loaded
5 % 'OCCA' : ECCOv4 grid + OCCA atlas
6 % 'SOSE59' : SOSE59 grid + atlas
7 %
8 % if reload=0 (default), variables are loaded from .mat files
9 % if reload=1 , variables are loaded from original files, and saved in
10 % the matlab form.
11 %
12 % - grid ("model"_grid.mat)
13 % mygrid : structure containing XC, YC, RAC and RC
14 % mytri : information used for delaunay triangulation
15 % MYBASININDEX : basin index
16 %
17 % - state/variance reference climatologies ("model"_atlas.mat)
18 % atlas : T/S atlas in a structure format
19 % atlas.T, atlas.S are cells of 4-dim arrays with monthly values
20 %
21 % gcmfaces toolbox must be working
22 %
23
24 % process arguments
25 reload=0;
26 if nargin>1,
27 reload=varargin{1};
28 end
29
30 % directory where .mat model files are stored
31 dir_model='/Users/roquet/Documents/MATLAB/MITprof/model_database/';
32
33
34 % try to load .mat files
35 if reload==0 & exist([dir_model model '_grid.mat'],'file') & exist([dir_model model '_atlas.mat'],'file')
36 % load grid and atlas
37 load([dir_model model '_grid.mat']);
38 load([dir_model model '_atlas.mat']);
39 return
40
41 end
42
43
44 % if reload~=0 or fields are not found, generation of .mat files
45
46 % protect global grid variables
47 global mygrid mytri MYBASININDEX
48 mygrid1=mygrid; mytri1=mytri; MYBASININDEX1=MYBASININDEX;
49
50 switch model
51 case 'OCCA',
52 % atlas made combining OCCA, PHC in arctic and WOA in marginal seas
53 % using the grid ECCOv4, monthly values
54
55 % set directories:
56 dir_in='/Users/roquet/Documents/MATLAB/MITprof/climatology/';
57 dirGrid=[dir_in 'GRIDv4/'];
58 fileBasin=[dir_in 'basin_masks_eccollc_90x50.bin'];
59 fileT=[dir_in 'T_OWPv1_M_eccollc_90x50.bin'];
60 fileS=[dir_in 'S_OWPv1_M_eccollc_90x50.bin'];
61
62 %load and save grid :
63 global fileFormat; fileFormat='compact';
64 grid_load(dirGrid,5); gcmfaces_bindata;
65 mygrid=rmfield(mygrid,{'XG','YG','RAC','RAZ','DXC','DYC','DXG','DYG'});
66 mygrid=rmfield(mygrid,{'hFacC','hFacW','hFacS','Depth','AngleCS','AngleSN'});
67 mygrid=rmfield(mygrid,{'hFacCsurf','mskW','mskS','DRC','DRF','RF'});
68 % list_param={'XC','YC','RAC','RC'};
69 % grid_load(dirGrid,5,list_param);
70 % gcmfaces_bindata;
71 MYBASININDEX=convert2array(v4_read_bin(fileBasin,1,0));
72 grid.name=model;
73 grid.mygrid=mygrid;
74 grid.mytri=mytri;
75 grid.MYBASININDEX=MYBASININDEX;
76
77 % read T/S Atlas
78 fldT=mygrid.mskC; fldT(:)=0; fldS=fldT;
79 for tt=1:12;
80 fldT(:,:,:,tt)=v4_read_bin(fileT,tt).*mygrid.mskC;
81 fldS(:,:,:,tt)=v4_read_bin(fileS,tt).*mygrid.mskC;
82 end;
83 atlas.name=model;
84 atlas.T={convert2array(fldT)}; atlas.S={convert2array(fldS)};
85
86 case 'SOSE59',
87 % 59th iteration of SOSE, annual climatology
88
89 % set directories:
90 dir_in='/Users/roquet/Documents/donnees/MODEL/SOSE59/';
91 dirGrid=[dir_in 'grid/'];
92
93 %load grid :
94 global fileFormat; fileFormat='straight';
95 grid_load(dirGrid,1); gcmfaces_bindata;
96 mygrid=rmfield(mygrid,{'XG','YG','RAC','RAZ','DXC','DYC','DXG','DYG'});
97 mygrid=rmfield(mygrid,{'hFacC','hFacW','hFacS','Depth','AngleCS','AngleSN'});
98 mygrid=rmfield(mygrid,{'hFacCsurf','mskW','mskS','DRC','DRF','RF'});
99 % list_param={'XC','YC','RAC','RC'};
100 % grid_load(dirGrid,1,list_param);
101 % gcmfaces_bindata;
102
103 MYBASININDEX=convert2array(mygrid.mskC(:,:,1));
104 MYBASININDEX(isnan(MYBASININDEX))=0;
105
106 grid.name=model;
107 grid.mygrid=mygrid;
108 grid.mytri=mytri;
109 grid.MYBASININDEX=MYBASININDEX;
110
111 % load atlas
112 atlas_file=[dir_in 'SOSE59_TS.mat'];
113 load(atlas_file);
114 atlas.name=model;
115 atlas.T={THETA_SOSE59};
116 atlas.S={SALT_SOSE59};
117
118 otherwise
119 error('not a valid model string');
120 end
121
122 % save .mat files
123 save([dir_model model '_grid.mat'],'grid');
124 save([dir_model model '_atlas.mat'],'atlas');
125
126 % reload global grid variables
127 mygrid=mygrid1; mytri=mytri1; MYBASININDEX=MYBASININDEX1;
128
129

  ViewVC Help
Powered by ViewVC 1.1.22