-
Notifications
You must be signed in to change notification settings - Fork 40
/
zmap.m
214 lines (183 loc) · 8.06 KB
/
zmap.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
function zmap(varargin)
%% run ZMAP Version 7.X
%
% This files start up ZMAP.
%
% Options:
% -debug : enables debugging functionality
% -restart : clear all windows and variables, then restart zmap
% -initonly : set up zmap paths and prefs, but don't open a window
% -RT : implement real-time mode
% -catalog alt_cat: use alt_cat as the prime catalog instead. It may be a variable name, a
% ZmapCatalog, or a value that canbe converted by ZmapCatalog
%
%
% Options to be probably implemented
% -grid :
% -selector :
% -shape :
% -state :
% -bordersonly :
%
%
%
% MAJOR CHANGES to ZMAP from v 6.0:
% - event catalog is now a ZmapCatalog instead of a variable-sized array
% - dates/times are handled by MATLAB's built-in datetime and duration data types
% - duplicated code has been removed or consolidated
% - scripts have been turned into functions and classes (allowing zmap functions to be run programmatically)
% - GUI elements have been consolidated, updated
% - unreachable code (& scripts not appearing in any menus) have been removed
% - added ability to import catalogs from FDSN web services.
% - global variables have been minimized. Data sharing occurs through one class.
% - only result variables should appear in the base workspace.
% - requires minimum of matlab v 2018a,
%
%
% see README.md and the help for individual parts of ZMAP for other change details
%
% The matlab searchpaths are updated, existing windows closed.
%
% Originally created by: Stefan Wiemer 12/94
% Modified by: Celso Reyes Spring 2017 - Winter 2018
%
% see also: ZmapCatalog, ZmapMainWindow
global ZG
% ZG (ZmapGlobal) provides access to all ZMAP's global variables
% When variables are accessed directly via ZmapGlobal.Data.variablename, they
% should not modify the original.
% However, assigning ZmapGlobal.Data to a variable first, provides direct [read/write] access to
% the variables.
% This allows assignment.
%
% ZmapGlobal.Data.ra = 100; % value is effectively ignored!
% ZG=ZmapGlobal.Data; %provide read/write access to global data.
% ZG.ra = 23 % changes ra globally
% advise matlab where it can find everything zmap
if ~exist('set_zmap_paths','file')
p = mfilename('fullpath');
p(end-length(mfilename) : end) = [];
addpath(fullfile(p,'src'));
end
set_zmap_paths;
startWindow = true;
debugMode = false;
possible_options = varargin(cellfun(@ischarlike,varargin));
options = lower(possible_options(startsWith(possible_options,'-')));
setappdata(groot,'ZmapCoordinateSystem', CoordinateSystems.geodetic);
% set application data
for option = string(options)
switch option
case "-restart"
msg.infodisp('Restarting ZMAP','initialization')
restartZmap('restart');
return
case "-quit"
msg.infodisp('Quitting ZMAP','initialization')
restartZmap('quit');
return
case "-debug"
msg.infodisp('debug mode enabled','initialization')
debugMode = true;
case "-initonly"
msg.infodisp('Initializing Zmap without starting the default main window','initialization')
startWindow = false;
case "-rt"
msg.infodisp('RealTimeMode enabled','initialization');
setappdata(groot,'ZmapRealTimeMode', true);
case "-cartesian"
% must be set prior to acessing ZmapGlobal for the first time
setappdata(groot,'ZmapCoordinateSystem', CoordinateSystems.cartesian);
%{
case {"-catalog"}
vaa = varargin;
notstrings =cellfun(@(x)~ischarlike(x),varargin);
vaa(notstrings)={''};
idx = find(vaa == "-catalog",1,'last'); %requres all members of vaa be strings
c = varargin{idx+1};
if ischarlike(c) && isvarname(c)
v=evalin('base',"whos('"+ c +"')");
if isempty(v)
msg.errordisp("cannot find the variable " + c, 'catalog specified');
return
end
alt_cat = evalin('base',"ZmapCatalog('Name', " + v.name + ")");
if isa(alt_cat, 'ZmapCatalog')
constructor_options.primeCatalog = alt_cat;
end
msg.infodisp("set primary catalog to the value from : " + v.name, 'catalog specified');
else
constructor_options.primeCatalog = ZmapCatalog.from(c);
msg.infodisp("set primary catalog from a : " + class(c), 'catalog specified');
end
%}
otherwise
msg.errordisp('Unknown ZMAP option: ' + option, 'Unknown ZMAP option, stopping');
return
end
end
switch getappdata(groot,'ZmapCoordinateSystem')
case CoordinateSystems.geodetic
setappdata(groot,'ZmapDefaultReferenceEllipsoid',referenceEllipsoid('earth','kilometer'));
case CoordinateSystems.cartesian
setappdata(groot,'ZmapDefaultReferenceEllipsoid',nonEllipsoid);
end
ZG = ZmapGlobal.Data;
ZG.debug = debugMode;
disp(['This is zmap.m - version ', ZmapGlobal.Data.zmap_version])
% Set up the different computer systems
sys = computer;
if verLessThan('matlab',ZG.min_matlab_version)
baseMsg = 'You are running a version of MATLAB older than %s. ZMAP %s requires MATLAB %s or newer';
messtext = sprintf(baseMsg, ZG.min_matlab_release, ZG.zmap_version, ZG.min_matlab_version);
msg.errordisp(messtext, 'Incompatible MATLAB Version');
errordlg(messtext,'Warning!')
pause(5)
return
end
tested_systems = {'MAC','PCW'};
if ~ismember( sys(1:3), tested_systems)
msg.warndisp('ZMAP has not been tested on this computer type', 'Untested System')
warndlg('Warning: ZMAP has not been tested on this computer type.','Untested System')
pause(5)
end
assignin('base','ZG',ZmapGlobal.Data);
% set local preference variables
ini_zmap
% set system dependent initial variables
ini_zmap_sys
% start the main zmap program
if startWindow
%get rid of message box that would exist if zmap was already opened without a catalog
delete(findall(groot,'Tag','Msgbox_No Active Catalogs'));
zw = findall(allchild(groot),'Tag','Zmap Main Window');
s=sprintf('%d ZMAP windows exist\n', numel(zw));
if ~isempty(zw)
emptyzw = arrayfun(@(x)~isstruct(x.UserData) || isempty(x.UserData.catalog), zw);
delete(zw(emptyzw));
s = s + "... of which " + sum(emptyzw) + " were empty";
end
msg.dbdisp(s)
cw = get(groot,'CurrentFigure');
if isempty(cw)
msg.dbdisp('No Figure currently exists');
else
switch cw.Tag
case 'Zmap Main Window'
msg.dbdisp('ZMAP Window Exists, and is active')
otherwise
% do nothing
end
end
cw = figure;
if ~isempty(ZG.primeCatalog) && questdlg('Open previous catalog?','ZMAP','Yes')=="Yes"
ZmapMainWindow(cw, ZG.primeCatalog);
else
ZmapMainWindow(cw, ZmapCatalog);
end
if ~isappdata(groot,'ZmapShowTips') || getappdata(groot,'ZmapShowTips')
show_a_tip();
setappdata(groot,'ZmapShowTips',false);
end
end
end