1 |
gforget |
1.1 |
function []=gcmfaces_global(varargin); |
2 |
gforget |
1.6 |
%object: take care of path and global variables (mygrid and myenv), |
3 |
gforget |
1.1 |
% and sends global variables to caller routine workspace |
4 |
|
|
%optional inputs: optional paramaters take the following form |
5 |
|
|
% {'name',param1,param2,...}. Are currently active: |
6 |
gforget |
1.6 |
% {'resetGrid',resetGrid} states that mygrid will be cleared |
7 |
gforget |
1.1 |
% and re-loaded interactively (1), or not (0;default). |
8 |
|
|
% {'listVars',varName1,varName2} is a list of variables |
9 |
|
|
% to check is in mygrid (empty by default). |
10 |
gforget |
1.6 |
%notes: - in any call, if this has not yet been done, |
11 |
|
|
% this routine also adds gcmfaces subdirectories |
12 |
gforget |
1.1 |
% to the matlab path, and it defines myenv. |
13 |
gforget |
1.6 |
% - calls to this routine will eventually replace |
14 |
gforget |
1.1 |
% both gcmfaces_path and 'global mygrid' calls. |
15 |
|
|
|
16 |
|
|
%set optional paramaters to default values |
17 |
gforget |
1.6 |
resetGrid=0; listVars={}; |
18 |
gforget |
1.1 |
%set more optional paramaters to user defined values |
19 |
|
|
for ii=1:nargin; |
20 |
|
|
if ~iscell(varargin{ii}); |
21 |
|
|
warning('inputCheck:gcmfaces_global_1',... |
22 |
|
|
['As of june 2011, gcmfaces_global expects \n'... |
23 |
|
|
' its optional parameters as cell arrays. \n'... |
24 |
|
|
' Argument no. ' num2str(ii+1) ' was ignored \n'... |
25 |
|
|
' Type ''help gcmfaces_global'' for details.']); |
26 |
|
|
elseif ~ischar(varargin{ii}{1}); |
27 |
|
|
warning('inputCheck:gcmfaces_global_2',... |
28 |
|
|
['As of june 2011, gcmfaces_global expects \n'... |
29 |
|
|
' its optional parameters cell arrays \n'... |
30 |
|
|
' to start with character string. \n'... |
31 |
|
|
' Argument no. ' num2str(ii+1) ' was ignored \n'... |
32 |
|
|
' Type ''help gcmfaces_global'' for details.']); |
33 |
|
|
else; |
34 |
|
|
if strcmp(varargin{ii}{1},'listVars'); |
35 |
gforget |
1.6 |
eval([varargin{ii}{1} '={varargin{ii}{2:end}};']); |
36 |
gforget |
1.1 |
elseif strcmp(varargin{ii}{1},'resetGrid'); |
37 |
|
|
eval([varargin{ii}{1} '=varargin{ii}{2};']); |
38 |
|
|
else; |
39 |
|
|
warning('inputCheck:gcmfaces_global_3',... |
40 |
|
|
['unknown option ''' varargin{ii}{1} ''' was ignored']); |
41 |
|
|
end; |
42 |
|
|
end; |
43 |
|
|
end; |
44 |
|
|
|
45 |
|
|
|
46 |
|
|
%get/define global variables: |
47 |
|
|
global myenv mygrid; |
48 |
|
|
|
49 |
|
|
%take care of path: |
50 |
|
|
test0=which('convert2gcmfaces.m'); |
51 |
|
|
if isempty(test0); |
52 |
gforget |
1.3 |
test0=which('gcmfaces_global.m'); ii=strfind(test0,filesep); |
53 |
gforget |
1.1 |
mydir=test0(1:ii(end)); |
54 |
|
|
% |
55 |
|
|
eval(['addpath ' mydir ';']); |
56 |
|
|
eval(['addpath ' mydir '/gcmfaces_IO/;']); |
57 |
|
|
eval(['addpath ' mydir 'gcmfaces_convert/;']); |
58 |
|
|
eval(['addpath ' mydir 'gcmfaces_exch/;']); |
59 |
|
|
eval(['addpath ' mydir 'gcmfaces_maps/;']); |
60 |
|
|
eval(['addpath ' mydir '/gcmfaces_misc/;']); |
61 |
|
|
eval(['addpath ' mydir '/gcmfaces_calc/;']); |
62 |
|
|
eval(['addpath ' mydir '/gcmfaces_smooth/;']); |
63 |
|
|
eval(['addpath ' mydir 'ecco_v4/;']); |
64 |
|
|
eval(['addpath ' mydir 'sample_analysis/;']); |
65 |
|
|
eval(['addpath ' mydir 'sample_processing/;']); |
66 |
gforget |
1.2 |
eval(['addpath ' mydir 'gcmfaces_diags/;']); |
67 |
gforget |
1.1 |
eval(['addpath ' mydir 'gcmfaces_devel/;']); |
68 |
|
|
end; |
69 |
|
|
|
70 |
|
|
%environment variables: |
71 |
|
|
if isempty(myenv); |
72 |
gforget |
1.3 |
test0=which('gcmfaces_global.m'); ii=strfind(test0,filesep); |
73 |
gforget |
1.1 |
myenv.gcmfaces_dir=test0(1:ii(end)); |
74 |
|
|
myenv.verbose=0; |
75 |
|
|
myenv.lessplot=0; |
76 |
|
|
myenv.lesstest=0; |
77 |
|
|
myenv.useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); |
78 |
gforget |
1.5 |
myenv.issueWarnings=1; |
79 |
gforget |
1.1 |
%... check m_map and netcdf |
80 |
|
|
end; |
81 |
|
|
|
82 |
|
|
%load grid variables: |
83 |
|
|
if resetGrid==1; |
84 |
|
|
mygrid=[]; |
85 |
|
|
dirGrid=input('grid directory name?\n','s'); |
86 |
|
|
nFaces=input('number of grid faces?\n'); |
87 |
|
|
fileFormat=input('file format?\n[''native'',''straight'',''cube'' or ''compact'']\n','s'); |
88 |
|
|
if strcmp(fileFormat,'native'); |
89 |
|
|
grid_load_native(dirGrid,nFaces); |
90 |
|
|
else; |
91 |
|
|
grid_load(dirGrid,nFaces,fileFormat); |
92 |
|
|
end; |
93 |
|
|
end; |
94 |
|
|
|
95 |
|
|
%check available mygrid variables: |
96 |
|
|
for ii=1:length(listVars); |
97 |
gforget |
1.6 |
if ~isfield(mygrid,listVars{ii}); |
98 |
|
|
error(['mygrid does not include ' listVars{ii}]); |
99 |
gforget |
1.1 |
end; |
100 |
|
|
end; |
101 |
|
|
|
102 |
gforget |
1.4 |
%issue warning if mygrid is empty: |
103 |
gforget |
1.6 |
test0=~isfield(mygrid,'XC'); |
104 |
|
|
[ST,I]=dbstack; ST={ST(:).name}'; |
105 |
|
|
test1=1; |
106 |
gforget |
1.9 |
list1={'grid_load','startup','example_display','example_IO',... |
107 |
gforget |
1.6 |
'example_remap','example_griddata','example_interp','example_faces2latlon2faces',... |
108 |
gforget |
1.7 |
'example_bin_average','example_transports','example_budget',... |
109 |
gforget |
1.10 |
'profiles_process_init','gcmfaces_init','diags_pre_process','diags_grid'}; |
110 |
gforget |
1.6 |
for jj=1:length(list1); |
111 |
|
|
test1=test1&isempty(find(strcmp(ST,list1{jj}))); |
112 |
|
|
end; |
113 |
|
|
if test0&test1&myenv.issueWarnings; |
114 |
gforget |
1.8 |
warning('mygrid has not yet been loaded to memory'); |
115 |
gforget |
1.4 |
end; |
116 |
|
|
|
117 |
gforget |
1.1 |
%send to workspace: |
118 |
|
|
evalin('caller','global mygrid myenv'); |
119 |
|
|
|