;+ ; Project : STEREO - SSC ; ; Name : SSC_WRITE_OEM ; ; Purpose : Write out OEM ephemeris files. ; ; Category : STEREO, Operations, Orbit ; ; Explanation : This procedure writes out a daily ephemeris for one of the two ; STEREO spacecraft in Orbital Ephemeris Message (OEM) format. ; This format is used by some of the NOAA ground stations to ; track the spacecraft between DSN passes. ; ; Syntax : SSC_WRITE_OEM, SPACECRAFT, DATE [, DELTA=DELTA ] ; ; Inputs : SPACECRAFT = Can be one of the following forms: ; ; 'A' 'B' ; 'STA' 'STB' ; 'Ahead' 'Behind' ; 'STEREO Ahead' 'STEREO Behind' ; 'STEREO-Ahead' 'STEREO-Behind' ; 'STEREO_Ahead' 'STEREO_Behind' ; ; Case is not important. The NAIF numeric codes of ; -234 and -235 respectively can also be used. ; ; DATE = The date that the ephemeris will cover. Can be in ; any format recognized by ANYTIM2UTC. Only the date ; is used--any time information is ignored. ; ; Opt. Inputs : None. ; ; Outputs : The ephemeris file is written to disk with a filename generated ; from the spacecraft and date, e.g. ; ; ahead_20061113_01.oem ; ; The last two digits in the filename is a version number which ; is incremented each time the procedure is called. If the new ; version is identical to the previous version, it is deleted. ; ; Opt. Outputs: None. ; ; Keywords : DELTA = Step size in seconds. Default is 60. ; ; ERRMSG = If defined and passed, then any error messages will be ; returned to the user in this parameter rather than ; depending on the MESSAGE routine in IDL. If no errors ; are encountered, then a null string is returned. In ; order to use this feature, ERRMSG must be defined ; first, e.g. ; ; ERRMSG = '' ; SSC_WRITE_OEM, ERRMSG=ERRMSG, ... ; IF ERRMSG NE '' THEN ... ; ; Will also accept any LOAD_STEREO_SPICE keywords. ; ; Env. vars. : SSC_STATIONS_OEM_W = Directory to write OEM files to. ; ; Calls : ANYTIM2UTC, PARSE_STEREO_NAME, LOAD_STEREO_SPICE, ANYTIM2CAL, ; CONCAT_DIR, GET_UTC, ANYTIM2TAI, TAI2UTC, GET_STEREO_COORD ; ; Common : None. ; ; Restrictions: None. ; ; Side effects: The SPICE kernels will be loaded, if not loaded already. ; ; Prev. Hist. : None. ; ; History : Version 1, 13-Nov-2006, William Thompson, GSFC ; ; Contact : WTHOMPSON ;- ; pro ssc_write_oem, spacecraft, date, delta=delta, errmsg=errmsg, _extra=_extra on_error, 2 ; ; Make sure that delta is defined. ; if n_elements(delta) ne 1 then delta = 60.d0 ; ; Determine the start and end times, based on the beginning and end of a ; calendar day. ; message = '' start_time = anytim2utc(date, errmsg=message) if message ne '' then goto, handle_error ; start_time.time = 0 end_time = start_time end_time.mjd = end_time.mjd + 1 ; ; Determine which spacecraft was requested, and translate it into the proper ; input for SPICE. Determine the SPACEWARN object ID number. ; sc = parse_stereo_name(spacecraft, ['STEREO-A','STEREO-B']) case sc of 'STEREO-A': begin fname = 'ahead' id = '29510' end 'STEREO-B': begin fname = 'behind' id = '29511' end else: begin message = 'Unable to recognize spacecraft ' + strtrim(sc,2) goto, handle_error end endcase ; ; Make sure that the SPICE kernels are loaded. ; load_stereo_spice, errmsg=message, _extra=_extra if message ne '' then goto, handle_error ; ; Create the filename based on the spacecraft and the date. ; filename = fname + '_' + anytim2cal(date, form=8, /date) filename = concat_dir(getenv('SSC_STATIONS_OEM_W'), filename) ; ; Find any existing files, extract the highest index number, and increment it ; by 1. ; files = filename + '_??.oem' files = file_search( files, count=count) if count gt 0 then begin s = sort(files) files = files(reverse(s)) lastfile = files[0] underscore = strpos(lastfile, '_', /reverse_search) index = fix(strmid(lastfile, underscore+1, 2)) + 1 end else begin index = 1 lastfile = '' endelse filename = filename + '_' + string(index,format='(I2.2)') + '.oem' ; ; Open the output file, and write out the header. ; openw, unit, filename, /get_lun printf, unit, 'CCSDS_OEM_VERS = 1.0' get_utc, utc, /ccsds printf, unit, 'CREATION_DATE = ' + utc printf, unit, 'ORIGINATOR = STEREO Science Center' printf, unit ; printf, unit, 'META_START' printf, unit, 'OBJECT_NAME = ' + sc printf, unit, 'OBJECT_ID = ' + id printf, unit, 'CENTER_NAME = EARTH' printf, unit, 'REF_FRAME = EME2000' printf, unit, 'TIME_SYSTEM = UTC' printf, unit, 'START_TIME = ' + anytim2utc(start_time, /ccsds) printf, unit, 'STOP_TIME = ' + anytim2utc(end_time, /ccsds) printf, unit, 'META_STOP' printf, unit ; ; Step through the times and write out the ephemeris data. ; tai = anytim2tai(start_time, /nocorrect) tai1 = anytim2tai(end_time, /nocorrect) repeat begin utc = tai2utc(tai, /nocorrect, /ccsds) state = get_stereo_coord(utc, sc, system='GEI') printf, unit, utc, state, format='(A, 3F15.3, 3F12.5)' last_tai = tai tai = tai + delta endrep until tai gt tai1 ; ; Make sure the end time is included in the ephemeris data. ; if last_tai lt tai1 then begin utc = tai2utc(tai1, /nocorrect, /ccsds) state = get_stereo_coord(utc, sc, system='GEI') printf, unit, utc, state, format='(A, 3F15.3, 3F12.5)' endif ; ; Close the output file and check to see if the file is identical to the ; previously generated file, if any. ; free_lun, unit if index gt 1 then begin openr, unit1, /get_lun, filename openr, unit2, /get_lun, lastfile test = 0 line1 = 'string' line2 = 'string' ; ; Skip over first two lines so as to ignore the creation date. ; for i=1,2 do begin readf, unit1, line1 readf, unit2, line2 endfor ; while (not eof(unit1)) and (not eof(unit2)) do begin readf, unit1, line1 readf, unit2, line2 test = test or (line1 ne line2) endwhile test = test or (not eof(unit1)) test = test or (not eof(unit2)) free_lun, unit1, unit2 if not test then begin print, 'Deleting '+filename file_delete, filename endif endif ; return ; ; Error handling point. ; handle_error: if n_elements(errmsg) eq 0 then message, message else $ errmsg = 'ssc_write_oem: ' + message ; end