-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPosition.java
More file actions
365 lines (341 loc) · 9.48 KB
/
Position.java
File metadata and controls
365 lines (341 loc) · 9.48 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
/*
Copyright 2006, Astrophysics Research Institute, Liverpool John Moores University.
This file is part of org.estar.toop.
org.estar.toop 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.toop 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.toop; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Position.java
// $Header: /space/home/eng/cjm/cvs/org_estar_toop/Position.java,v 1.4 2007-01-30 18:35:26 cjm Exp $
package org.estar.toop;
import java.io.*;
import java.util.*;
import ngat.util.*;
import ngat.util.logging.*;
import org.estar.astrometry.*;
/**
* Position command implementation.
* @author Steve Fraser, Chris Mottram
* @version $Revision$
*/
public class Position extends TOCCommand implements Logging, Runnable
{
/**
* Revision control system version id.
*/
public final static String RCSID = "$Id$";
/**
* Classname for logging.
*/
public static final String CLASS = "Position";
/**
* The command name.
*/
public static final String COMMAND_NAME = "POSITION";
/**
* Position state returned from the position command.
* @see #state
*/
public static final String POSITION_STATE_RISEN = "RISEN";
/**
* Position state returned from the position command.
* @see #state
*/
public static final String POSITION_STATE_SET = "SET";
/**
* Input into the position command, the Right Ascension.
*/
protected RA ra = null;
/**
* Input into the position command, the Declination.
*/
protected Dec dec = null;
/**
* Result returned from the Position command, showing what state the position is in.
* One of NEVER_SETS, NEVER_RISES, RISER.
*/
protected String category = null;
/**
* Result returned from the Position command, showing the current state the position is in.
* One of RISEN, SET.
*/
protected String state = null;
/**
* The number of seconds until the position will rise above the altitude limit of the telescope.
*/
protected int timeToRise = 0;
/**
* The number of seconds until the position will set below the altitude limit of the telescope.
*/
protected int timeToSet = 0;
/**
* The current altitude of the target, in decimal degrees.
*/
protected double altitude = 0;
/**
* The current azimuth of the target, in decimal degrees.
*/
protected double azimuth = 0;
/**
* The distance to the moon from the target, in decimal degrees.
*/
protected double moonDistance = 0;
/**
* Default constructor.
*/
public Position()
{
super();
}
/**
* Set the input RA to the POSITION command.
* @param r The ra.
* @see #ra
*/
public void setRA(RA r)
{
ra = r;
}
/**
* Set the input RA to the POSITION command.
* @param s The ra, as a string in the form HH:MM:SS.ss.
* @exception NumberFormatException Thrown if the RA is not legal.
* @see #ra
*/
public void setRA(String s) throws NumberFormatException
{
ra = new RA();
ra.parseColon(s);
}
/**
* Set the input declination to the POSITION command.
* @param d The declination.
* @see #dec
*/
public void setDec(Dec d)
{
dec = d;
}
/**
* Set the input declination to the POSITION command.
* @param s The dec, as a string in the form [+|-]DD:MM:SS.ss.
* @exception NumberFormatException Thrown if the declination is not legal.
* @see #dec
*/
public void setDec(String s) throws NumberFormatException
{
dec = new Dec();
dec.parseColon(s);
}
/**
* Run method.
* Setup commandString.
* Call TOCCommand.run.
*/
public void run()
{
commandString = new String(COMMAND_NAME+" "+ra.toString(':')+" "+dec.toString(':'));
super.run();
// diddly results
if(getSuccessful())
{
try
{
// altitude
altitude = getReplyValueDouble("alt");// in decimal degrees
sessionData.setProperty(".position.altitude",""+altitude);
// azimuth
azimuth = getReplyValueDouble("az");// in decimal degrees
sessionData.setProperty(".position.azimuth",""+azimuth);
// timeToRise
timeToRise = getReplyValueInt("rise");// in seconds
sessionData.setProperty(".position.time_to_rise",""+timeToRise);
// timeToSet
timeToSet = getReplyValueInt("set");// in seconds
sessionData.setProperty(".position.time_to_set",""+timeToSet);
// moonDistance
moonDistance = getReplyValueDouble("moon");// in decimal degrees
sessionData.setProperty(".position.moon_distance",""+moonDistance);
// category
category = getReplyValue("cat");
sessionData.setProperty(".position.category",category);
// state
state = getReplyValue("state");
sessionData.setProperty(".position.state",state);
// log
logger.log(INFO, 1, CLASS, RCSID,"run","Position successful altitude : "+altitude+
" azimuth : "+azimuth+
" category : "+category+
" state : "+state+
" time to set : "+timeToSet+" seconds "+
" time to rise : "+timeToRise+" seconds "+
" moon distance : "+moonDistance+" degrees.");
}
catch(NGATPropertyException e)
{
successful = false;
errorString = new String(this.getClass().getName()+
":run:Parsing POSITION results failed:"+e);
logger.log(INFO, 1, CLASS, RCSID,"run",errorString);
logger.dumpStack(1,e);
return;
}
}
else
{
logger.log(INFO, 1, CLASS, RCSID,"run","Position failed with error : "+getErrorString()+".");
}
}
/**
* Get the altitude returned from the POSITION command.
* @return The altitude in decimal degrees.
* @see #altitude
*/
public double getAltitude()
{
return altitude;
}
/**
* Get the azimuth returned from the POSITION command.
* @return The azimuth in decimal degrees.
* @see #azimuth
*/
public double getAzimuth()
{
return azimuth;
}
/**
* Get the moon distance returned from the POSITION command.
* @return The moon distance in decimal degrees.
* @see #moonDistance
*/
public double getMoonDistance()
{
return moonDistance;
}
/**
* Get the category returned from the POSITION command.
* @return The category of the target position, one of: NEVER_SETS, NEVER_RISES, RISER.
* @see #category
*/
public String getCategory()
{
return category;
}
/**
* Get the state returned from the POSITION command.
* @return The state of the target position, one of: RISEN, SET.
* @see #state
*/
public String getState()
{
return state;
}
/**
* The number of seconds until the target rises. Returned from the POSITION command.
* @return The number of seconds.
* @see #timeToRise
*/
public int getTimeToRise()
{
return timeToRise;
}
/**
* The number of seconds until the target sets. Returned from the POSITION command.
* @return The number of seconds.
* @see #timeToSet
*/
public int getTimeToSet()
{
return timeToSet;
}
/**
* Test main program.
* @param args The argument list.
*/
public static void main(String args[])
{
TOCSessionData sessionData = null;
Position position = null;
File propertiesFile = null;
Logger l = null;
String raString = null;
String decString = null;
if(args.length != 3)
{
System.out.println("java org.estar.toop.Position <properties filename> <RA> <Dec>");
System.exit(1);
}
propertiesFile = new File(args[0]);
raString = args[1];
decString = args[2];
// setup logger
ConsoleLogHandler console = new ConsoleLogHandler(new BasicLogFormatter(150));
console.setLogLevel(ALL);
l = LogManager.getLogger("org.estar.toop.TOCAClient");
l.setLogLevel(ALL);
l.addHandler(console);
l = LogManager.getLogger("org.estar.toop.TOCCommand");
l.setLogLevel(ALL);
l.addHandler(console);
l = LogManager.getLogger("org.estar.toop.Position");
l.setLogLevel(ALL);
l.addHandler(console);
l = LogManager.getLogger("org.estar.toop.TOCSessionData");
l.setLogLevel(ALL);
l.addHandler(console);
// load session data
sessionData = new TOCSessionData();
try
{
sessionData.load(propertiesFile);
}
catch(Exception e)
{
System.err.println("Loading session data failed:"+e);
e.printStackTrace();
System.exit(1);
}
position = new Position();
position.setSessionData(sessionData);
position.setRA(raString);
position.setDec(decString);
position.run();
if(position.getSuccessful())
{
System.out.println("Altitude: "+position.getAltitude()+" degrees.");
System.out.println("Azimuth: "+position.getAzimuth()+" degrees.");
System.out.println("Category: "+position.getCategory()+".");
System.out.println("State: "+position.getState()+".");
System.out.println("Time To Set: "+position.getTimeToSet()+" seconds.");
System.out.println("Time To Rise: "+position.getTimeToRise()+" seconds.");
System.out.println("Moon Distance: "+position.getMoonDistance()+" degrees.");
}
else
{
System.out.println("Position failed:"+position.getErrorString()+".");
}
System.out.println("Position finished.");
System.exit(0);
}
}
/*
** $Log: not supported by cvs2svn $
** Revision 1.3 2005/06/15 12:05:03 cjm
** Made Position class public, so we can access constants within it.
**
** Revision 1.2 2005/06/06 17:46:56 cjm
** Comment fix.
**
** Revision 1.1 2005/06/06 14:45:12 cjm
** Initial revision
**
*/