| 1 | function []=gcmfaces_global(varargin); | 
| 2 | %object:    take care of path and global variables (mygrid and myenv), | 
| 3 | %           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 | %               {'resetGrid',resetGrid} states that mygrid will be cleared | 
| 7 | %                   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 | %notes:     - in any call, if this has not yet been done, | 
| 11 | %           this routine also adds gcmfaces subdirectories | 
| 12 | %           to the matlab path, and it defines myenv. | 
| 13 | %           - calls to this routine will eventually replace | 
| 14 | %           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 | 
| 22 | resetGrid=0; listVars={}; | 
| 23 | %set more optional paramaters to user defined values | 
| 24 | for ii=1:nargin; | 
| 25 | if ~iscell(varargin{ii}); | 
| 26 | warning('inputCheck:gcmfaces_global_1',... | 
| 27 | ['As of june 2011, gcmfaces_global expects \n'... | 
| 28 | '         its optional parameters as cell arrays. \n'... | 
| 29 | '         Argument no. ' num2str(ii+1) ' was ignored \n'... | 
| 30 | '         Type ''help gcmfaces_global'' for details.']); | 
| 31 | elseif ~ischar(varargin{ii}{1}); | 
| 32 | warning('inputCheck:gcmfaces_global_2',... | 
| 33 | ['As of june 2011, gcmfaces_global expects \n'... | 
| 34 | '         its optional parameters cell arrays \n'... | 
| 35 | '         to start with character string. \n'... | 
| 36 | '         Argument no. ' num2str(ii+1) ' was ignored \n'... | 
| 37 | '         Type ''help gcmfaces_global'' for details.']); | 
| 38 | else; | 
| 39 | if strcmp(varargin{ii}{1},'listVars'); | 
| 40 | eval([varargin{ii}{1} '={varargin{ii}{2:end}};']); | 
| 41 | elseif strcmp(varargin{ii}{1},'resetGrid'); | 
| 42 | eval([varargin{ii}{1} '=varargin{ii}{2};']); | 
| 43 | else; | 
| 44 | warning('inputCheck:gcmfaces_global_3',... | 
| 45 | ['unknown option ''' varargin{ii}{1} ''' was ignored']); | 
| 46 | end; | 
| 47 | end; | 
| 48 | end; | 
| 49 |  | 
| 50 |  | 
| 51 | %get/define global variables: | 
| 52 | global myenv mygrid; | 
| 53 |  | 
| 54 | %take care of path: | 
| 55 | test0=which('convert2gcmfaces.m'); | 
| 56 | if isempty(test0); | 
| 57 | test0=which('gcmfaces_global.m'); ii=strfind(test0,filesep); | 
| 58 | mydir=test0(1:ii(end)); | 
| 59 | % | 
| 60 | eval(['addpath ' mydir ';']); | 
| 61 | eval(['addpath ' mydir '/gcmfaces_IO/;']); | 
| 62 | eval(['addpath ' mydir 'gcmfaces_convert/;']); | 
| 63 | eval(['addpath ' mydir 'gcmfaces_exch/;']); | 
| 64 | eval(['addpath ' mydir 'gcmfaces_maps/;']); | 
| 65 | eval(['addpath ' mydir '/gcmfaces_misc/;']); | 
| 66 | eval(['addpath ' mydir '/gcmfaces_calc/;']); | 
| 67 | eval(['addpath ' mydir '/gcmfaces_smooth/;']); | 
| 68 | eval(['addpath ' mydir 'ecco_v4/;']); | 
| 69 | eval(['addpath ' mydir 'sample_analysis/;']); | 
| 70 | eval(['addpath ' mydir 'sample_processing/;']); | 
| 71 | eval(['addpath ' mydir 'gcmfaces_diags/;']); | 
| 72 | eval(['addpath ' mydir 'gcmfaces_devel/;']); | 
| 73 | end; | 
| 74 |  | 
| 75 | %environment variables: | 
| 76 | if isempty(myenv); | 
| 77 | test0=which('gcmfaces_global.m'); ii=strfind(test0,filesep); | 
| 78 | myenv.gcmfaces_dir=test0(1:ii(end)); | 
| 79 | myenv.verbose=0; | 
| 80 | myenv.lessplot=0; | 
| 81 | myenv.lesstest=0; | 
| 82 | myenv.useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); | 
| 83 | myenv.issueWarnings=1; | 
| 84 | %... check m_map and netcdf | 
| 85 | end; | 
| 86 |  | 
| 87 | %load grid variables: | 
| 88 | if resetGrid==1; | 
| 89 | mygrid=[]; | 
| 90 | dirGrid=input('grid directory name?\n','s'); | 
| 91 | nFaces=input('number of grid faces?\n'); | 
| 92 | fileFormat=input('file format?\n[''native'',''straight'',''cube'' or ''compact'']\n','s'); | 
| 93 | if strcmp(fileFormat,'native'); | 
| 94 | grid_load_native(dirGrid,nFaces); | 
| 95 | else; | 
| 96 | grid_load(dirGrid,nFaces,fileFormat); | 
| 97 | end; | 
| 98 | end; | 
| 99 |  | 
| 100 | %check available mygrid variables: | 
| 101 | for ii=1:length(listVars); | 
| 102 | if ~isfield(mygrid,listVars{ii}); | 
| 103 | error(['mygrid does not include ' listVars{ii}]); | 
| 104 | end; | 
| 105 | 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: | 
| 124 | evalin('caller','global mygrid myenv'); | 
| 125 |  |