Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/check_occults.py
Дата изменения: Fri Apr 8 12:46:10 2016
Дата индексирования: Mon Apr 11 01:33:13 2016
Кодировка:
#
#MODULE check_occults
#
#***********************************************************************
"""

**PURPOSE** --
Check that the proper amount of time has been left command groups.

Developed from CHECK_OCCULTS.COM.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --
Initial implementation 5/11/01
Raise an error when the RMS file does not exist. Also, append to an
already existing error file. dc 4/21/03
Added some major capabilities to check overlaps between a number of
PLCP groups. mdr 8/4/09
Don't ignore back-to-back commands that are the same. mdr 10/20/09
Refine slew regex. drc 11/02/09
Fix a bug checking for overlaps with PCPTERM and PTERMIN. mdr 11/16/09
Add the combined F1/F2 maintenance slew group and correct time. mdr 4/19/10
Mods for new maintenance slew timing. mdr 2/16/12
Correct issues in 1|2-gyro mode verses 3|T-gyro mode. mdr 8/27/15
"""
#***********************************************************************
import spss_sys_util
import re
import time_util
import sys
import os

time_regex = re.compile("^\s+\*+(\d\d\d\d\.\d\d\d:\d\d:\d\d:\d\d\.\d\d\d)\*+")
gsacq_regex = re.compile("^.*(GUIDE STAR ACQUISITION)(.*)")
slew_regex = re.compile("^\s+ (SLEW) (.*)")
pcpocult_regex = re.compile("^.*GROUP,(PCPOCULT)(.*)")
pcpterm_regex = re.compile("^.*GROUP,(PCPTERM)(.*)")
pcpsaa_regex = re.compile("^.*GROUP,(PCPSAA)(.*)")
f1slew_regex = re.compile("^.*GROUP,(PCPF1SSA)(.*)")
f2slew_regex = re.compile("^.*GROUP,(PCPF2SSA)(.*)")
f12slew_regex = re.compile("^.*GROUP,(PCPF12SA)(.*)")
offset_regex = re.compile("^.*TABLE,(MOFFSREQ)(.*)")
its_regex = re.compile("^.*GROUP,(PITSSCHD)(.*)")
ptermin_regex = re.compile("^.*GROUP,(PTERMIN)(.*)")
gyromode_regex = re.compile("^.*A (GYRO_MODE)=([123T])(.*)")

PCPOCULT_DELTA = 5
PCPTERM_DELTA = 15
PCPSAA_DELTA = 5
PCPF_SSA_DELTA = 236
OFFSET_DELTA = 27
ITS_DELTA = 420
PTERMIN_DELTA = 5

__version__ = "15.08.27"


def run(rmsfile=None, error_file=None):
"""Check an RMS file for the proper time between various PLCP groups.

Usage:
do check_occults []

This tool will check for overlaps between the various Terminate
groups, slews, gsacqs and maintenance slews.
Errors are printed to 'error_file'. If 'error_file' already
exists, it is appended to.

"""
if not rmsfile:
# Spew out the usage and quit when no rms file name
# is provided.
print run.__doc__
return spss_sys_util.SUCCESS

if error_file:
error_file_id = open(error_file, 'a')
else:
error_file_id = sys.stdout

if not os.path.isfile(rmsfile):
raise ValueError(".rms file %s does not exist." % rmsfile)

error_file_id.write(find_errors(rmsfile))
error_file_id.close()

return spss_sys_util.SUCCESS
# end def run


def find_errors(rmsfile):
"""Does the actual checking of the RMS file. Returns a string.
"""
outstring = "\nResults of check_occults.py\n"
outstring += "---------------------------\n"
rmsid = open(rmsfile)
lastcmd = None
lasttime = None
laststring = ''
lastcmd_delta = 0
line = rmsid.readline()
found_error = 0
term_grp_on = 1
gyro_mode = 0
delta = 0
three_gyromode = ('3', 'T')
reduced_gyromode = ('1', '2')
term_group_cmds_reduced_gyromode = ("PCPOCULT", "PCPSAA", "PCPTERM")
term_group_cmds_three_gyromode = ("PCPOCULT", "PCPSAA")
other_cmds_reduced_gyromode = ("GUIDE STAR ACQUISITION",
"SLEW",
"PCPF1SSA",
"PCPF2SSA",
"PCPF12SA",
"MOFFSREQ",
"PITSSCHD",
"PTERMIN")
other_cmds_three_gyromode = ("GUIDE STAR ACQUISITION",
"SLEW",
"PCPF1SSA",
"PCPF2SSA",
"PCPF12SA",
"MOFFSREQ",
"PITSSCHD",
"PTERMIN",
"PCPTERM")
term_group_cmds = term_group_cmds_three_gyromode
other_cmds = other_cmds_three_gyromode
while line:
gyromodelist = gyromode_regex.findall(line)
if (len(gyromodelist) != 0):
# Found the gyro_mode line so pull out the mode
gyro_mode = gyromodelist[0][1]
if (gyro_mode in reduced_gyromode):
term_group_cmds = term_group_cmds_reduced_gyromode
other_cmds = other_cmds_reduced_gyromode
# end if
# end if
timelist = time_regex.findall(line)
if timelist:
# We found a time, now see if the next line is of interest
cmdtime = timelist[0]
line = rmsid.readline()
cmdlist = (gsacq_regex.findall(line) or pcpocult_regex.findall(line) or
slew_regex.findall(line) or pcpterm_regex.findall(line) or
pcpsaa_regex.findall(line) or f1slew_regex.findall(line) or
f2slew_regex.findall(line) or offset_regex.findall(line) or
its_regex.findall(line) or ptermin_regex.findall(line) or
f12slew_regex.findall(line))
if cmdlist:
# We have one of the above
cmd = cmdlist[0]
cmdtime = time_util.spss_time(cmdtime)
cmd_delta = 0
if (cmd[0] == "GUIDE STAR ACQUISITION"):
# Find the end time (2 lines later)
line = rmsid.readline()
line = rmsid.readline()
#print "GSACQ", line
cmd_delta = time_util.spss_time(line[40:58]) - cmdtime
# end if
if (cmd[0] == "SLEW"):
# Find the end time (2 lines later)
line = rmsid.readline()
line = rmsid.readline()
#print "SLEW", line
cmd_delta = time_util.spss_time(line[43:61]) - cmdtime
# end if

if (lastcmd):
# We are not at the beginning of the RMS.
if (lastcmd[0] == "GUIDE STAR ACQUISITION"):
delta = lastcmd_delta
laststring = " ACQ at " + str(lasttime)
term_grp_on = 1
elif (lastcmd[0] == "SLEW"):
delta = lastcmd_delta
laststring = " SLEW at " + str(lasttime)
elif (lastcmd[0] == "PCPOCULT"):
delta = PCPOCULT_DELTA
laststring = " PCPOCULT at " + str(lasttime)
term_grp_on = 0
elif (lastcmd[0] == "PCPTERM"):
delta = PCPTERM_DELTA
laststring = " PCPTERM at " + str(lasttime)
term_grp_on = 0
elif (lastcmd[0] == "PCPSAA"):
delta = PCPSAA_DELTA
laststring = " PCPSAA at " + str(lasttime)
term_grp_on = 0
elif (lastcmd[0] == "PCPF1SSA"):
delta = PCPF_SSA_DELTA
laststring = " PCPF1SSA at " + str(lasttime)
term_grp_on = 0
elif (lastcmd[0] == "PCPF2SSA"):
delta = PCPF_SSA_DELTA
laststring = " PCPF2SSA at " + str(lasttime)
term_grp_on = 0
elif (lastcmd[0] == "PCPF12SA"):
delta = PCPF_SSA_DELTA
laststring = " PCPF12SA at " + str(lasttime)
term_grp_on = 0
elif (lastcmd[0] == "MOFFSREQ"):
delta = OFFSET_DELTA
laststring = " GENSLEW at " + str(lasttime)
elif (lastcmd[0] == "PITSSCHD"):
delta = ITS_DELTA
laststring = " PITSSCHD at " + str(lasttime)
elif (lastcmd[0] == "PTERMIN"):
delta = PTERMIN_DELTA
laststring = " PTERMIN at " + str(lasttime)
term_grp_on = 0
# end if
if ((cmdtime - lasttime) < delta):
# The commands are too close together
cmdstring = " unknown\n"
if (cmd[0] == "GUIDE STAR ACQUISITION"):
cmdstring = " ACQ at " + str(cmdtime) + "\n"
elif (cmd[0] == "SLEW"):
cmdstring = " SLEW at " + str(cmdtime) + "\n"
elif ((cmd[0] == "PCPOCULT") and (term_grp_on)):
cmdstring = " PCPOCULT at " + str(cmdtime) + "\n"
elif (cmd[0] == "PCPTERM"):
if (((gyro_mode in reduced_gyromode) and (term_grp_on)) or
(gyro_mode in three_gyromode)):
cmdstring = " PCPTERM at " + str(cmdtime) + "\n"
# end if
elif ((cmd[0] == "PCPSAA") and (term_grp_on)):
cmdstring = " PCPSAA at " + str(cmdtime) + "\n"
elif (cmd[0] == "PCPF1SSA"):
cmdstring = " PCPF1SSA at " + str(cmdtime) + "\n"
elif (cmd[0] == "PCPF2SSA"):
cmdstring = " PCPF2SSA at " + str(cmdtime) + "\n"
elif (cmd[0] == "PCPF12SA"):
cmdstring = " PCPF12SA at " + str(cmdtime) + "\n"
elif (cmd[0] == "MOFFSREQ"):
cmdstring = " GENSLEW at " + str(cmdtime) + "\n"
elif (cmd[0] == "PITSSCHD"):
cmdstring = " PITSSCHD at " + str(cmdtime) + "\n"
elif (cmd[0] == "PTERMIN"):
cmdstring = " PTERMIN at " + str(cmdtime) + "\n"
# end if
if (cmdstring != " unknown\n"):
found_error = 1
outstring += laststring + " overlaps" + cmdstring + \
" minimum start-to-start delta is %3i seconds\n" % delta
# end if
# end if
# end if
if (((term_grp_on) and (cmd[0] in term_group_cmds)) or (cmd[0] in other_cmds)):
lastcmd = cmd
lasttime = cmdtime
lastcmd_delta = cmd_delta
# end if
# end if
# end if
line = rmsid.readline()
# end while
if not found_error:
outstring = outstring + "No errors found\n"

return outstring
# end def find_errors


if __name__ == '__main__':
if len(sys.argv) > 1:
print sys.argv
run(*tuple(sys.argv[1:]))
else:
run()