-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTMLTelescope.java
More file actions
414 lines (380 loc) · 11 KB
/
RTMLTelescope.java
File metadata and controls
414 lines (380 loc) · 11 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/*
Copyright 2006, Astrophysics Research Institute, Liverpool John Moores University.
This file is part of org.estar.rtml.
org.estar.rtml is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
org.estar.rtml is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with org.estar.rtml; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// RTMLTelescope.java
// $Header: /space/home/eng/cjm/cvs/org_estar_rtml/RTMLTelescope.java,v 1.1 2008-06-05 14:18:18 cjm Exp $
package org.estar.rtml;
import java.io.*;
import java.text.*;
/**
* This class is a data container for information contained in the Telescope nodes/tags of an RTML document.
* @author Chris Mottram
* @version $Revision$
* @see org.estar.rtml.RTMLAttributes
*/
public class RTMLTelescope extends RTMLAttributes implements Serializable
{
/**
* Revision control system version id.
*/
public final static String RCSID = "$Id$";
/**
* Serial version ID. Fixed as these documents can be used as parameters in RMI calls across JVMs.
*/
static final long serialVersionUID = 4696210110556867480L;
/**
* The name of the telescope.
*/
protected String name = null;
/**
* The aperture of the telescope.
* @see #apertureUnits
*/
protected double aperture = 0.0;
/**
* The units of the aperture of the telescope.
* Should be "meters" in RTML3.1a, and one of %lengthUnits; entity in RTML 2.2.
* @see #aperture
*/
protected String apertureUnits = "meters";
/**
* The type of the aperture of the telescope: one of:geometric|effective.
* Only used in RTML3.1a, defaults to "geometric".
* @see #aperture
*/
protected String apertureType = "geometric";
/**
* The focal ratio of the telescope. Specified as f/\d+\.?\d* in RTML 3.1a i.e. "f/10".
*/
protected String focalRatio = null;
/**
* The Focal Length of the telescope.
* @see #focalLengthUnits
*/
protected double focalLength = 0.0;
/**
* The units of the focal length of the telescope.
* Should be "meters" in RTML3.1a, and one of %lengthUnits; entity in RTML 2.2.
* @see #focalLength
*/
protected String focalLengthUnits = "meters";
/**
* Where the telescope is sited.
* @see org.estar.rtml.RTMLTelescopeLocation
*/
protected RTMLTelescopeLocation location = null;
/**
* Default constructor.
*/
public RTMLTelescope()
{
super();
}
/**
* Method to set the name.
* @param s The name.
* @see #name
*/
public void setName(String s)
{
name = s;
}
/**
* Method to get the name.
* @return The name.
* @see #name
*/
public String getName()
{
return name;
}
/**
* Method to set the aperture. The units of the value are stored in apertureUnits.
* @param d The aperture value.
* @see #aperture
* @see #apertureUnits
*/
public void setAperture(double d)
{
aperture = d;
}
/**
* Method to set the aperture. The units of the value are stored in apertureUnits.
* @param s The aperture's double value as a string.
* @exception NumberFormatException Thrown if s is not a valid double.
* @see #aperture
* @see #apertureUnits
*/
public void setAperture(String s) throws NumberFormatException
{
aperture = Double.parseDouble(s);
}
/**
* Method to get the aperture.
* @return The aperture value. The units of the value are stored in apertureUnits.
* @see #aperture
* @see #apertureUnits
*/
public double getAperture()
{
return aperture;
}
/**
* Method to get the aperture. It will convert the following units ( a subset of %lengthUnits in RTML 2.2):
* "m"|"meter"|"meters"|"metres"|"cm"|"centimeter"|"centimeters"|"mm"|"millimeter"|"millimeters"|
* "ft"|"foot"|"feet"|"inch"|"inches".
* @return The aperture value, in meters.
* @exception IllegalArgumentException Thrown if apertureUnits are not convertable.
* @see #aperture
* @see #apertureUnits
* @see #getLengthUnitsMetersMultiplicationFactor
*/
public double getApertureMeters() throws IllegalArgumentException
{
double multiplicationFactor;
multiplicationFactor = getLengthUnitsMetersMultiplicationFactor(apertureUnits);
return aperture*multiplicationFactor;
}
/**
* Method to set the aperture units.
* @param s The aperture units. Should be "meters" in RTML3.1a, and one of %lengthUnits; entity in RTML 2.2.
* @see #apertureUnits
*/
public void setApertureUnits(String s)
{
apertureUnits = s;
}
/**
* Method to get the aperture units.
* @return The aperture units.
* @see #apertureUnits
*/
public String getApertureUnits()
{
return apertureUnits;
}
/**
* Method to set the aperture type.
* @param s The aperture type. Only used in RTML 3.1a, one of:geometric|effective .
* @see #apertureType
*/
public void setApertureType(String s)
{
apertureType = s;
}
/**
* Method to get the aperture type.
* @return The aperture type.
* @see #apertureType
*/
public String getApertureType()
{
return apertureType;
}
/**
* Method to set the focal ratio.
* @param s The focal ratio.
* @see #focalRatio
*/
public void setFocalRatio(String s)
{
focalRatio = s;
}
/**
* Method to get the focal ratio.
* @return The focal ratio.
* @see #focalRatio
*/
public String getFocalRatio()
{
return focalRatio;
}
/**
* Method to set the focal length. The units of the value are stored in focalLengthUnits.
* @param d The focal length value.
* @see #focalLength
* @see #focalLengthUnits
*/
public void setFocalLength(double d)
{
focalLength = d;
}
/**
* Method to set the focal length. The units of the value are stored in focalLengthUnits.
* @param s The focal length's double value as a string.
* @exception NumberFormatException Thrown if s is not a valid double.
* @see #focalLength
* @see #focalLengthUnits
*/
public void setFocalLength(String s) throws NumberFormatException
{
focalLength = Double.parseDouble(s);
}
/**
* Method to get the focal length.
* @return The focal length value. The units of the value are stored in focalLengthUnits.
* @see #focalLength
* @see #focalLengthUnits
*/
public double getFocalLength()
{
return focalLength;
}
/**
* Method to get the focal length. It will convert the following units ( a subset of %lengthUnits in RTML 2.2):
* "m"|"meter"|"meters"|"metres"|"cm"|"centimeter"|"centimeters"|"mm"|"millimeter"|"millimeters"|
* "ft"|"foot"|"feet"|"inch"|"inches".
* @return The focal length value, in meters.
* @exception IllegalArgumentException Thrown if focalLengthUnits are not convertable.
* @see #focalLength
* @see #focalLengthUnits
* @see #getLengthUnitsMetersMultiplicationFactor
*/
public double getFocalLengthMeters() throws IllegalArgumentException
{
double multiplicationFactor;
multiplicationFactor = getLengthUnitsMetersMultiplicationFactor(focalLengthUnits);
return focalLength*multiplicationFactor;
}
/**
* Method to set the focal length units.
* @param s The focal length units. Should be "meters" in RTML3.1a,
* and one of %lengthUnits; entity in RTML 2.2.
* @see #focalLengthUnits
*/
public void setFocalLengthUnits(String s)
{
focalLengthUnits = s;
}
/**
* Method to get the focal length units.
* @return The focal length units.
* @see #focalLengthUnits
*/
public String getFocalLengthUnits()
{
return focalLengthUnits;
}
/**
* Method to set the telescope location.
* @param o The telescope location.
* @see #location
*/
public void setLocation(RTMLTelescopeLocation o)
{
location = o;
}
/**
* Method to get the telescope location.
* @return The telescope location.
* @see #location
*/
public RTMLTelescopeLocation getLocation()
{
return location;
}
/**
* String representation of this Telescope.
* @see #toString(java.lang.String)
*/
public String toString()
{
return(toString(""));
}
/**
* String representation of this Telescope, with specified prefix.
* @param prefix A string to prefix to each line of data we print out.
* @see #name
* @see #aperture
* @see #apertureUnits
* @see #apertureType
* @see #focalRatio
* @see #focalLength
* @see #focalLengthUnits
* @see #location
* @see org.estar.rtml.RTMLAttributes#toString(java.lang.String)
*/
public String toString(String prefix)
{
DecimalFormat nf = null;
StringBuffer sb = new StringBuffer();
nf = new DecimalFormat("###0.0#");
sb.append(prefix+"Telescope :\n");
sb.append(super.toString(prefix+"\t"));
sb.append(prefix+"\tName : "+name+"\n");
if((aperture != 0.0)&&(apertureUnits != null))
sb.append(prefix+"\tAperture : "+nf.format(aperture)+" "+apertureUnits+"("+apertureType+")\n");
if(focalRatio != null)
sb.append(prefix+"\tFocal Ratio : "+focalRatio+"\n");
if((focalLength != 0.0)&&(focalLengthUnits != null))
sb.append(prefix+"\tFocal Length : "+nf.format(focalLength)+" "+focalLengthUnits+"\n");
if(location != null)
sb.append(location.toString(prefix+"\t")+"\n");
return(sb.toString());
}
/**
* Get the multiplication factor to apply to the units specified to return a length in meters.
* It will convert the following units ( a subset of %lengthUnits in RTML 2.2):
* "m"|"meter"|"meters"|"metres"|"cm"|"centimeter"|"centimeters"|"mm"|"millimeter"|"millimeters"|
* "ft"|"foot"|"feet"|"inch"|"inches".
* @param s The units string.
* @return The multiplication value.
* @exception IllegalArgumentException Thrown if the units are not convertable.
*/
protected double getLengthUnitsMetersMultiplicationFactor(String s)
{
double multiplicationFactor;
multiplicationFactor = 1.0;
if(s.equals("m"))
multiplicationFactor = 1.0;
else if(s.equals("meter"))
multiplicationFactor = 1.0;
else if(s.equals("meters"))
multiplicationFactor = 1.0;
else if(s.equals("metres"))
multiplicationFactor = 1.0;
else if(s.equals("cm"))
multiplicationFactor = 0.01;
else if(s.equals("centimeter"))
multiplicationFactor = 0.01;
else if(s.equals("centimeters"))
multiplicationFactor = 0.01;
else if(s.equals("mm"))
multiplicationFactor = 0.001;
else if(s.equals("millimeter"))
multiplicationFactor = 0.001;
else if(s.equals("millimeters"))
multiplicationFactor = 0.001;
else if(s.equals("ft"))
multiplicationFactor = 0.3048;
else if(s.equals("foot"))
multiplicationFactor = 0.3048;
else if(s.equals("feet"))
multiplicationFactor = 0.3048;
else if(s.equals("inch"))
multiplicationFactor = 0.0254;
else if(s.equals("inches"))
multiplicationFactor = 0.0254;
else
{
throw new IllegalArgumentException(this.getClass().getName()+
":getLengthUnitsMetersMultiplicationFactor: Illegal units:"+s);
}
return multiplicationFactor;
}
}
//
// $Log: not supported by cvs2svn $
//