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

Поисковые слова: http astrokuban.info astrokuban
#
#MODULE find_dump_times
#
#****************************************************************************
"""Produces a list of the observation and dump times for a particular
proposal on an SMS

TITLE: find_dump_times.py
DEVELOPER: Alan Patterson, 11-May-2003

PURPOSE: The tool produces a text report on the expected dump start time
and duration and the sunit for every record activity of the
specified proposal in the given MS.

USAGE: do find_dump_times
where: is the MS run name
is the proposal id

RETURNS: Nothing

MOD HISTORY:
Initial version app 05/12/04
Mods following python review app 05/28/04
Determine time zone gab 09/07/07
Fix zero day number drc 10/29/10
"""
#****************************************************************************
import sys
import string
import spss_sys_util
import spst_getopt
import os
import time_util
import stpydb
import re
import proposal_util
import obset_util
import sms_util
import mscl_util
import urllib2

__author__ = "Alan Patterson"
__version__ = "10/29/10"

WWW_TIME = 'http://tycho.usno.navy.mil/cgi-bin/timer.pl'

def run(*args):
"""Produces a dump schedule for each record action of a given proposal
on a specified MS. This is the planned (not actual) dump schedule and
a delay of 2 hours is assumed between dump end and ftp to STScI

Usage:
do find_dump_times

where is the MS run name
is the proposal id
"""
if len(args) == 0 or (len(args) == 1 and args[0] is None):
print run.__doc__
return not spss_sys_util.SUCCESS
low_args = []
for a in args:
low_args.append(string.lower(a))
allowed_options = ['outfile=']
options, parms = spst_getopt.spst_getopt(low_args,allowed_options)
if len(parms) < 2:
print 'Both the MS run name and proposal id must be specified'
return not spss_sys_util.SUCCESS
msrunname = parms[0]
propid = parms[1]

# find RDO file name from sms, pass_sms_is, ms object
sms = sms_util.sms(msrunname,pass_name=1)
pass_sms_id = sms.get_pass_sms_name()
ms = mscl_util.ms(pass_sms_id)
rdofilelist = ms.get_output_file('rdo')
if len(rdofilelist) == 0:
print 'No RDO file found for %s' % msrunname
return not spss_sys_util.SUCCESS
elif len(rdofilelist) > 1:
print 'Too many RDO files found'
return not spss_sys_util.SUCCESS
rdofile = rdofilelist[0]

# find program id
prop = proposal_util.proposal(propid)
prog = prop.get('program_id')

# Determine time zone.
time_file = urllib2.urlopen(WWW_TIME)
time_data = time_file.readlines()
time_zone_re = re.compile(r'.*E[D|S]T')
# Set default time zone
time_zone = 0
time_zone_str = 'GMT'
for line in time_data:
if time_zone_re.match(line):
if line.find('EDT') != -1:
time_zone = 4
time_zone_str = 'EDT'
elif line.find('EST') != -1:
time_zone = 5
time_zone_str = 'EST'


# begin output
if options.has_key('-outfile'):
fout = open(options['-outfile'],'w')
else:
fout = sys.stdout
fout.write(' Proposal %s dump schedule\n\n\n' % propid)
fout.write(' Dump\n')
fout.write('Start and Stop times Dump Start Duration Approx.\n')
fout.write('of On-Board Record (DOY/UT) Date/time (UT) hr:min ftp time (%s)* Visit\n'
% time_zone_str)
fout.write('--------------------------- --------------- ------ --------------- -----\n')
f = open(rdofile,'r')
line = f.readline()
# Calculate delta_time to correct UT to local time.
delta_time = time_zone*3600
while len(line) > 0:
z = string.split(line)

# MS RUN START: 2004.145 00:00:00.000
if string.find(line,'MS RUN START:') != -1:
ms_start = time_util.spss_time('%s:%s' % (z[3],z[4][:8]))

# DUMP - UNIT NO. 1, START: 145 01:17:00 DUR.: 050:30
# END: 145 02:07:30 BLOCKS: 13858
if string.find(line,'DUMP - UNIT') != -1:
part_time = time_util.delta_time('%s:%s' % (z[6],z[7]))
start = rational_time(part_time,ms_start)
# dump duration has to be less than 60 minutes
dur = time_util.delta_time(z[9])
line = f.readline()
z = string.split(line)
part_time2 = time_util.delta_time('%s:%s' % (z[1],z[2]))
end_tz = rational_time(part_time2,ms_start) - delta_time
#FTP time is assumed to be 2 hours after end of dump
ftp_time = end_tz + 3600*2

# 144 15:22:57 144 15:28:29 005:32 8N1-AC-XK 83 ACS SPLIT
if len(z) >= 8 and z[5][:3] == prog:
rec_start_delta = time_util.delta_time('%s:%s' % (z[0],z[1]))
rec_end_delta = time_util.delta_time('%s:%s' % (z[2],z[3]))
rstart = rational_time(rec_start_delta,ms_start)
rend = rational_time(rec_end_delta,ms_start)
# rstart = ms_start.normal(rec_start_delta)
# rend = ms_start.normal(rec_end_delta)
a = rstart.strftime("%j/%H:%M:%S")
b = rend.strftime("%j/%H:%M:%S")
c = start.strftime("%m/%d/%y %H:%M")
# default delta_time string is ddd:HH:MM:SS.000
# extract MM:SS (dump duration < 60M)
d = str(dur)[-9:-4]
e = ftp_time.strftime("%m/%d/%y %H:%M")
obset = obset_util.obset(prop,z[5][4:6])
su = obset.get('sunit_id')
fout.write('%s %s %s %s %s %s\n' % (a,b,c,d,e,su))
line = f.readline()
fout.write('\n\n\n * Note: time of an ftp transfer is estimated by adding ')
fout.write('2 hours to the time\n of the corresponding dump completion.\n')

return spss_sys_util.SUCCESS

def rational_time(day_hms_delta,ref_time):
"""Converts a delta time (day_hms_delta) to a full spss_time always
later than the ref_time

To be replaced by spss_time method .normal(delta)
"""
y = ref_time.strftime("%Y")
t = day_hms_delta + time_util.spss_time('%s.001' % y) - 86400.
if t < ref_time:
t = day_hms_delta + time_util.spss_time('%s.001' % str(int(y) + 1)) - 86400
return t

# to run on commandline
if __name__ == '__main__':
input1 = None
if len(sys.argv) > 1:
apply(run, tuple(sys.argv[1:]))
else:
run(None)