Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/set_gs_select.py
Дата изменения: Fri Feb 28 14:46:11 2014
Дата индексирования: Sat Mar 1 16:39:38 2014
Кодировка:
# MODULE set_gs_select
#
#******************************************************************************
"""Sets the guide star selection flag for the specified gs for the specified
obset.

TITLE: set_gs_select.py
DEVELOPER: Merle Reinhart, 16-Jun-2000

PURPOSE: Set the guide star selection flag in the database for the
specified guide star for the specified obset.

USAGE: do set_gs_select []
where is the input gs selection file that contains a
list of the gs selections records for the stars
that the tool will select. The contents and
structure of the records is constructed by the
ccl_gsselect tool.
is an optional argument that can have a value
of Y or N. Y means proceed and N means abort.
If the argument is not specified on the command
line, then the user is prompted.

RETURNS: Nothing

MOD HISTORY:
"""
#******************************************************************************

def run (input_file=None, cont=''):
"""Sets the guide star selection flag based upon data in the input_file.
"""

import os, string, re, errno
import spss_sys_util, stpydb

# Check for a valid input_file parameter
if (not input_file):
input_file = raw_input('Enter the GS selection filename >> ')
if (input_file == ''):
raise IOError('You must enter a GS selection filename')
# end if
# end if

input_file = string.strip(input_file)
if (not os.path.exists(input_file)):
# ENOENT is the 'file not found' error
raise IOError(errno.ENOENT,os.strerror(errno.ENOENT),input_file)
# end if

# Check if cont have a valid value if entered
if (cont == ''):
print 'WARNING: This routine will modify GS pair selections'
print ' for data in %s' % input_file
cont = raw_input('Continue? (Y|N) >> ')
# end if
cont = string.upper(cont)[0:1]
if (cont == 'N'):
return Exception('GS Selection terminated at your request')
# end if

spssdb = spss_sys_util.get_environ_variable('SPSS_DB')[0]
db = stpydb.stpydb(dbmsName=spssdb)

x = open(input_file, 'r')

eof = 0
count = 0
old_id = '#'
transaction_open = 0

while (not eof):
record = string.split(string.strip(x.readline()))
if (len(record) == 0):
eof = 1
continue
# end if

ccl, cclver = string.split(record[0], ':')
id = record[1]
prop, obs, ver = string.split(id, ':')
seq_num = record[2]
gsp_id = record[3]
scenario = record[6]
min_num_gs = record[7]

# If we have a new obset, then commit any open transaction, tell
# the user we are starting a new obset and open a new transaction
if (id != old_id):
if (transaction_open):
db.commitTransaction()
transaction_open = 0
# end if

# Initialize the selection order
order = 1

print
print '********************************************************'
print 'Processing obset: %s; PCS Scenario: %s' % \
(id, scenario)
print '********************************************************'
print '--------------------------------------------------------'
print "Required number of GS's = %s" % min_num_gs
print '--------------------------------------------------------'
db.beginTransaction()
transaction_open = 1
else:
order = order + 1
# If there are more records for an obset in the file than there
# should be for the scenario, then mention is and skip the record
# but continue through the rest of the file
if (order > int(min_num_gs)):
print ' >>> ERROR: You have more records for this obset ' \
'than required: max = %s' % min_num_gs
print ' >>> Skipping this record.'
continue
# end if
# end if


# Wipe out any existing selections IFF we have a new obset
if (order == 1):
# Zero out the current wggs_pairs selections
print ' Zeroing existing wggs_pairs selections.....',
db.query('update wggs_pairs')
db.query(' set selected = "0"')
db.query(' where proposal_id = @prop')
db.query(' and obset_id = @obs')
db.query(' and version_num = @ver')
db.query(' and selected != "0"')
db.setParam('prop', prop)
db.setParam('obs', obs)
db.setParam('ver', ver)
db.executeUpdate()
num_rows = db.getRowcount()
print '%s rows affected' % num_rows

# Zero out the current qbgsp_select selections
print ' Zeroing existing qbgsp_select selections...',
db.query('update qbgsp_select')
db.query(' set select_order = 0')
db.query(' where ccl_name = @ccl')
db.query(' and ccl_version = @cclver')
db.query(' and proposal_id = @prop')
db.query(' and obset_id = @obs')
db.query(' and version_num = @ver')
db.query(' and select_order != 0')
db.setParam('ccl', ccl)
db.setParam('cclver', int(cclver))
db.setParam('prop', prop)
db.setParam('obs', obs)
db.setParam('ver', ver)
db.executeUpdate()
num_rows = db.getRowcount()
print '%s rows affected' % num_rows
# end if

print ' Setting wggs_pairs GS Selections...........',
db.query('update wggs_pairs')
db.query(' set selected = @order')
db.query(' where proposal_id = @prop')
db.query(' and obset_id = @obs')
db.query(' and version_num = @ver')
db.query(' and sel_seq = @seq')
db.setParam('order', str(order))
db.setParam('prop', prop)
db.setParam('obs', obs)
db.setParam('ver', ver)
db.setParam('seq', int(seq_num))
db.executeUpdate()
num_rows = db.getRowcount()
print '%s rows affected' % num_rows

print ' Setting qbgsp_select GS Selections.........',
db.query('update qbgsp_select')
db.query(' set select_order = @order')
db.query(' where ccl_name = @ccl')
db.query(' and ccl_version = @cclver')
db.query(' and proposal_id = @prop')
db.query(' and obset_id = @obs')
db.query(' and version_num = @ver')
db.query(' and gsp_id = @gsp')
db.setParam('order', order)
db.setParam('ccl', ccl)
db.setParam('cclver', int(cclver))
db.setParam('prop', prop)
db.setParam('obs', obs)
db.setParam('ver', ver)
db.setParam('gsp', gsp_id)
db.executeUpdate()
num_rows = db.getRowcount()
print '%s rows affected' % num_rows

old_id = id
count = count + 1
# end while

if (transaction_open):
db.commitTransaction()
# end if

x.close()

if (count == 0):
print
print '**************************************************************'
print 'WARNING: No GS pair data was found in the file %s which' % \
input_file
print ' was input to the GS selection routine SET_GS_SELECT.'
print '**************************************************************'
# end if

return
# end def run