1 |
function []=gcmfaces_global(varargin); |
function []=gcmfaces_global(varargin); |
2 |
%object: take care of path and global variables (mygrid and myenv), |
%object: take care of path and global variables (mygrid and myenv), |
3 |
% and sends global variables to caller routine workspace |
% and sends global variables to caller routine workspace |
4 |
%optional inputs: optional paramaters take the following form |
%optional inputs: optional paramaters take the following form |
5 |
% {'name',param1,param2,...}. Are currently active: |
% {'name',param1,param2,...}. Are currently active: |
6 |
% {'resetGrid',resetGrid} states that mygrid will be cleared |
% {'resetGrid',resetGrid} states that mygrid will be cleared |
7 |
% and re-loaded interactively (1), or not (0;default). |
% and re-loaded interactively (1), or not (0;default). |
8 |
% {'listVars',varName1,varName2} is a list of variables |
% {'listVars',varName1,varName2} is a list of variables |
9 |
% to check is in mygrid (empty by default). |
% to check is in mygrid (empty by default). |
10 |
%notes: - in any call, if this has not yet been done, |
%notes: - in any call, if this has not yet been done, |
11 |
% this routine also adds gcmfaces subdirectories |
% this routine also adds gcmfaces subdirectories |
12 |
% to the matlab path, and it defines myenv. |
% to the matlab path, and it defines myenv. |
13 |
% - calls to this routine will eventually replace |
% - calls to this routine will eventually replace |
14 |
% both gcmfaces_path and 'global mygrid' calls. |
% both gcmfaces_path and 'global mygrid' calls. |
15 |
|
|
16 |
|
warning(sprintf(['This version of gcmfaces, from an old CVS server, is \n' ... |
17 |
|
' now considered deprecated. Future devopment will proceed, instead, \n' ... |
18 |
|
' via GitHub. For up to date documentation, please refer to \n' ... |
19 |
|
' http://gcmfaces.readthedocs.io/en/latest/'])); |
20 |
|
|
21 |
%set optional paramaters to default values |
%set optional paramaters to default values |
22 |
resetGrid=0; listVars={}; |
resetGrid=0; listVars={}; |
23 |
%set more optional paramaters to user defined values |
%set more optional paramaters to user defined values |
24 |
for ii=1:nargin; |
for ii=1:nargin; |
25 |
if ~iscell(varargin{ii}); |
if ~iscell(varargin{ii}); |
37 |
' Type ''help gcmfaces_global'' for details.']); |
' Type ''help gcmfaces_global'' for details.']); |
38 |
else; |
else; |
39 |
if strcmp(varargin{ii}{1},'listVars'); |
if strcmp(varargin{ii}{1},'listVars'); |
40 |
eval([varargin{ii}{1} '={varargin{ii}{2:end}};']); |
eval([varargin{ii}{1} '={varargin{ii}{2:end}};']); |
41 |
elseif strcmp(varargin{ii}{1},'resetGrid'); |
elseif strcmp(varargin{ii}{1},'resetGrid'); |
42 |
eval([varargin{ii}{1} '=varargin{ii}{2};']); |
eval([varargin{ii}{1} '=varargin{ii}{2};']); |
43 |
else; |
else; |
54 |
%take care of path: |
%take care of path: |
55 |
test0=which('convert2gcmfaces.m'); |
test0=which('convert2gcmfaces.m'); |
56 |
if isempty(test0); |
if isempty(test0); |
57 |
test0=which('gcmfaces_global.m'); ii=strfind(test0,'/'); |
test0=which('gcmfaces_global.m'); ii=strfind(test0,filesep); |
58 |
mydir=test0(1:ii(end)); |
mydir=test0(1:ii(end)); |
59 |
% |
% |
60 |
eval(['addpath ' mydir ';']); |
eval(['addpath ' mydir ';']); |
68 |
eval(['addpath ' mydir 'ecco_v4/;']); |
eval(['addpath ' mydir 'ecco_v4/;']); |
69 |
eval(['addpath ' mydir 'sample_analysis/;']); |
eval(['addpath ' mydir 'sample_analysis/;']); |
70 |
eval(['addpath ' mydir 'sample_processing/;']); |
eval(['addpath ' mydir 'sample_processing/;']); |
71 |
|
eval(['addpath ' mydir 'gcmfaces_diags/;']); |
72 |
eval(['addpath ' mydir 'gcmfaces_devel/;']); |
eval(['addpath ' mydir 'gcmfaces_devel/;']); |
73 |
end; |
end; |
74 |
|
|
75 |
%environment variables: |
%environment variables: |
76 |
if isempty(myenv); |
if isempty(myenv); |
77 |
test0=which('gcmfaces_global.m'); ii=strfind(test0,'/'); |
test0=which('gcmfaces_global.m'); ii=strfind(test0,filesep); |
78 |
myenv.gcmfaces_dir=test0(1:ii(end)); |
myenv.gcmfaces_dir=test0(1:ii(end)); |
79 |
myenv.verbose=0; |
myenv.verbose=0; |
80 |
myenv.lessplot=0; |
myenv.lessplot=0; |
81 |
myenv.lesstest=0; |
myenv.lesstest=0; |
82 |
myenv.useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); |
myenv.useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); |
83 |
|
myenv.issueWarnings=1; |
84 |
%... check m_map and netcdf |
%... check m_map and netcdf |
85 |
end; |
end; |
86 |
|
|
99 |
|
|
100 |
%check available mygrid variables: |
%check available mygrid variables: |
101 |
for ii=1:length(listVars); |
for ii=1:length(listVars); |
102 |
if ~isfield(mygrid,listVars{ii}); |
if ~isfield(mygrid,listVars{ii}); |
103 |
error(['mygrid does not include ' listVars{ii}]); |
error(['mygrid does not include ' listVars{ii}]); |
104 |
end; |
end; |
105 |
end; |
end; |
106 |
|
|
107 |
|
%issue warning if mygrid is empty: |
108 |
|
test0=~isfield(mygrid,'XC'); |
109 |
|
[ST,I]=dbstack; ST={ST(:).name}'; |
110 |
|
test1=1; |
111 |
|
list1={'grid_load','startup','example_display','example_IO',... |
112 |
|
'example_remap','example_griddata','example_interp','example_faces2latlon2faces',... |
113 |
|
'example_bin_average','example_transports','example_budget',... |
114 |
|
'profiles_process_init','gcmfaces_init','diags_pre_process','diags_grid'}; |
115 |
|
list1={list1{:},'profiles_prep_main','profiles_prep_select','MITprof_demo'}; |
116 |
|
for jj=1:length(list1); |
117 |
|
test1=test1&isempty(find(strcmp(ST,list1{jj}))); |
118 |
|
end; |
119 |
|
if test0&test1&myenv.issueWarnings; |
120 |
|
warning('mygrid has not yet been loaded to memory'); |
121 |
|
end; |
122 |
|
|
123 |
%send to workspace: |
%send to workspace: |
124 |
evalin('caller','global mygrid myenv'); |
evalin('caller','global mygrid myenv'); |
125 |
|
|