Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/process_onboard_from_ccs.py
Дата изменения: Fri Apr 8 12:46:12 2016
Дата индексирования: Mon Apr 11 06:22:14 2016
Кодировка:

Поисковые слова: изучение луны
#
#MODULE process_onboard_from_ccs
#
#***********************************************************************
"""

**PURPOSE** --
Populate relation wiephemeris with the data sent through a namelist
file by CCS.

Developed from PROCESS_ONBOARD_FROM_CCS.COM written by Danny Jones.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --
Initial implementation 5/18/01
code cleanup and modernization; use namelist_util.namelist. drc 9/8/15

"""
#***********************************************************************
import spss_sys_util
import on_board
import time_util
from namelist_util import read_namelist

NAMELIST_NAME = 'EPHUPLPRM'

__version__ = '15.09.08'


def run(File=None):
"""Populate relation wiephemeris with namelist data from CCS.

Usage:
do process_onboard_from_ccs
"""

if not File:
print run.__doc__
return spss_sys_util.SUCCESS

# Get the db field to namelist keyword translation
dbfields_dict = dbfields_to_keywords()

# Read the namelist file...
namelist_dict = read_namelist(File)

# Sanity check the namelist
# The input file should only have one namelist.
if len(namelist_dict) != 1:
raise ValueError("""File %s should contain exactly one namelist.
It contains %i namelists.""" %
(File, len(namelist_dict)))

# Make sure the namelist has the right name.
if NAMELIST_NAME not in namelist_dict.keys():
raise ValueError("File %s should contain a namelist named %s." %
(File, NAMELIST_NAME))

ephem_dict = namelist_dict[NAMELIST_NAME]
ephem_dict_keys = ephem_dict.keys()
#ephem_dict_keys.remove('key_list')
namelist_keywords = ephem_dict_keys[:]
datfile_keywords = dbfields_dict.values()

# Make sure the database fields map exactly into the fields from
# the namelist with no extra fields.
for datfile_keyword in dbfields_dict.values():
try:
namelist_keywords.remove(datfile_keyword)
except:
raise ValueError(datfile_keyword + " not found in namelist.")

if namelist_keywords:
raise ValueError("Namelist has extra keywords %s" %
str(namelist_keywords))

for namelist_keyword in ephem_dict_keys:
datfile_keywords.remove(namelist_keyword)

if datfile_keywords:
raise ValueError("Namelist has missing keywords %s" %
str(datfile_keywords))

# Make sure each namelist field has a value.
empty_fields = []
for key in ephem_dict.keys():
if not ephem_dict[key]:
empty_fields.append(key)
if empty_fields:
raise ValueError("Namelist contains empty fields: %s" % empty_fields)

# Make sure EP_EFFECT_TIME is not zero.
if float(ephem_dict['EP_EFFECT_TIME'][0]) == 0.0:
raise ValueError("EP_EFFECT_TIME contains a bad value.")

# If everything checks out, run the passfile -onboard command.
status, text = spss_sys_util.command('passfile -onboard ' + File, 1)

if status != spss_sys_util.SUCCESS:
raise RuntimeError("passfile -onboard failed!")

# Use 'on_board' to send mail to opus that a new on-board ephem is ready
on_board.send_report(time_util.spss_time(float(ephem_dict['EP_EPOCH'][0])
+ time_util.EPHEM_ADJUST_SECS))

return spss_sys_util.SUCCESS


def dbfields_to_keywords(
datfile=spss_sys_util.resolver('PE_DAT',
'process_onboard_from_ccs.dat')):
"""Read the file containing the translations of keyword names in the file
from CCS to their corresponding database fields. Returns a dictionary
with the keys being the database field names and the values being the
namelist keywords.
"""
dict = {}
for line in open(datfile).readlines():
key, value = line.split()
dict[key] = value
return dict