Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/check_eps_ovr.py
Дата изменения: Fri Feb 28 14:46:08 2014
Дата индексирования: Sat Mar 1 16:38:32 2014
Кодировка:

Поисковые слова: apod
#
#MODULE check_eps_ovr
#
#***********************************************************************
"""

**PURPOSE** --
Perform various functions relating to the EPS override file.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --

o Initial implementation 11/02/00
o Update docstring for eps_ovr version numbers (SPSS 44.5).
12/17/01 drc
"""
#***********************************************************************
import spss_sys_util, sms_util, string, os, time_util, ccl_util, re, stpydb
from boolean import *

dbconn = stpydb.stpydb(dbmsName=spss_sys_util.get_environ_variable("SPSS_DB")[0])
dbconn.query('select min_sa_angle, max_sa_angle from sa_eps_parms')
result = {}
while dbconn.execute(result):
pass

SA_MIN_ANGLE = result['min_sa_angle']
SA_MAX_ANGLE = result['max_sa_angle']

time_rgx1 = re.compile('^\d\d\d\d\.\d\d\d:\d\d:\d\d:\d\d$')
time_rgx2 = re.compile('^\d\d\d\d\.\d\d\d:\d\d:\d\d$')


def run(cclname=None, eps_ovr_file=None, *args):
"""Validated an EPS override file.

Usage:
do check_eps_ovr [-move]

The '-move' option will cause the validated EPS override file to be copied
to SPSS_SMS/.eps_ovr_#. The default is to not move the override
file.
"""

if not cclname or not eps_ovr_file:
# Spew out the usage and quit when no calendar name
# is provided.
print run.__doc__
return spss_sys_util.SUCCESS

move = false

# Parse the arguments
for arg in args:
if string.lower(arg) == "-move":
move = true

sms = sms_util.sms(cclname)

verify_status = verify_eps_ovr(sms, eps_ovr_file)
if verify_status and move:
sms.set_eps_override_file(eps_ovr_file)
print "The EPS override file has been copied to %s." % sms.eps_override_file
elif move:
print "The override file was NOT moved to the operational area."

if verify_status:
return spss_sys_util.SUCCESS
else:
return not spss_sys_util.SUCCESS

def verify_eps_ovr(sms, eps_ovr_file):
"""Verify an existing EPS override file.
"""
winlist = []
count = 0
good_override_file = true

for line in open(eps_ovr_file, "r").readlines():
count = count + 1
# Remove comments
bang_index = string.find(line, '!')
if bang_index != -1:
line = line[:bang_index]

# Skip blank lines
if not string.strip(line):
continue

try:
str_start_time, str_end_time, str_min_angle, str_max_angle = string.split(line)
except ValueError, e:
print e
print "Line %i has wrong number of elements: %s" % (count, line)
print "EPS override file should have"
print "start time, end time, minimum angle, maximum angle, and an optional"
print "comment only on each line"
good_override_file = false
continue

try:
start_time = check_time(sms, str_start_time)
except ValueError, e:
print e
print "Line %i has a problem with the start time: %s" % (count, line)
good_override_file = false
continue
try:
end_time = check_time(sms, str_end_time)
except ValueError, e:
print e
print "Line %i has a problem with the end time: %s" % (count, line)
good_override_file = false
continue

try:
window = time_util.window(start_time, end_time)
except time_util.WindowError, e:
print e
print "Line %i has a problem with the start and end times: %s" % (count, line)
good_override_file = false
continue

for win in winlist:
if win.overlaps(window):
print ("Line %i has a problem -- Window %s overlaps %s: %s" %
(count, win, window, line))
good_override_file = false


winlist.append(window)

try:
min_angle = check_angle(str_min_angle)
max_angle = check_angle(str_max_angle)
angle_pair_check(min_angle, max_angle)
except ValueError, e:
print e
print "Line %i has a problem with the angles: %s" % (count, line)
good_override_file = false
continue

print "Line %i is valid: %s" % (count, line)

if count == 0:
print "WARNING: File %s has zero non-comment lines" % eps_ovr_file

if good_override_file:
print "EPS override file %s is valid" % eps_ovr_file
else:
print "EPS override file %s is INVALID." % eps_ovr_file

return good_override_file


def angle_pair_check(min_angle, max_angle):
"""Check that the minimum angle is not greater than the maximum angle.
"""
if min_angle > max_angle:
raise ValueError("Minimum angle (%f) must be <= maximum angle (%f)"
% (min_angle, max_angle))
return


def check_time(sms, str_time):
"""Check that the input time is formatted correctly and between the begin
and end time of the sms.

Returns the time as an spss_time object.
"""
if not (time_rgx1.match(str_time) or time_rgx2.match(str_time)):
raise ValueError('Incorrect format for time: %s' % str_time)

time = time_util.spss_time(str_time)

if not (sms.get_begin_time() <= time <= sms.get_end_time()):
print "Calendar begin time: %s" % sms.get_begin_time()
print "Calendar end time: %s" % sms.get_end_time()
raise ValueError('Times must be within calendar time frame: %s' % time)

return time


def check_angle(str_angle):
"""Check that the input angle is a proper float and between the min and max SA angles.
"""
try:
angle = float(str_angle)
except ValueError:
print "%s cannot be cast as a float" % str_angle
raise

if not (SA_MIN_ANGLE <= angle <= SA_MAX_ANGLE):
print "Solar array minimum angle: %f" % SA_MIN_ANGLE
print "Solar array maximum angle: %f" % SA_MAX_ANGLE
raise ValueError('Angles must be between SA max and min angles: %f' % angle)

return angle