function get_galex_hlsp_telemetry, obs_year, obs_month, obs_day, obs_hour, $ data_dir = data_dir, sc_data = sc_data ;+ ; NAME: ; GET_GALEX_HLSP_TELEMETRY ; PURPOSE: ; Retrieve data from HLSP files for uv-bkgd public data ; EXPLANATION: ; The procedure is described in Murthy (2014) [DOI: 10.1007/s10509-013-1612-1]. ; I obtained the TLEs (two-line elements) from Space- Track.org ; (https://www.space-track.org/) and then used ; STK (http://www.agi.com/default.aspx) to calculate the latitude and ; longitude of the spacecraft ground track at a given UT and thereby ; the local spacecraft time. ; These data are available from the HLSP archive at MAST at the ; URL: http://archive.stsci.edu/prepds/uv-bkgd/ ; This program will read those data closest to the observation time and date ; into a structure with the following elements: ; 1. Year Integer Year of Observation ; 2. Month Integer Month of Observation ; 3. Day Integer Day of Observation ; 4. Hour Float Hour of Observation ; 5. sc_long Float Longitude of spacecraft on the Earth ; 6. sc_lat Float Latitude of spacecraft on the Earth ; ; Notes: The dates must all be numerical. ; The coordinates are in degrees and degrees/s ; ; CALLING SEQUENCE ; sc_pos = get_galex_hlsp_telemetry(year, month, day, hour, data_dir = data_dir) ; ; Inputs: ; YEAR - Required year ; MONTH - Required month ; DAY - Required day ; HOUR - Required hour ; ; Optional Input: ; data_dir - Location of data files. Default is in the running directory. ; sc_data - If it exists, data is not read from the file. ; ; Outputs: ; SC_POS - Structure (defined above) containing spacecraft ; location for defined time ; ; NOTES: Minimal error checking is done. Useful dates are between Jan. 3, 2003 ; and Mar. 25, 2013. ; If the program is to be called multiple times, it will save time to ; use the sc_data optional keyword to avoid rereading the file. ; PROCEDURES USED: ; None ; REVISION HISTORY ; Written by Jayant Murthy (jmurthy@yahoo.com): July 23, 2014 ; COPYRIGHT ; Simplified BSD license copied from Wikipedia ; (https://en.wikipedia.org/wiki/BSD_licenses) ; Copyright (c) 2014, Jayant Murthy ; All rights reserved. ; Redistribution and use in source and binary forms, with or without ; modification, are permitted provided that the following conditions are met: ; ; 1. Redistributions of source code must retain the above copyright notice, this ; list of conditions and the following disclaimer. ; 2. Redistributions in binary form must reproduce the above copyright notice, ; this list of conditions and the following disclaimer in the documentation ; and/or other materials provided with the distribution. ; ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ; ; The views and conclusions contained in the software and documentation are those ; of the authors and should not be interpreted as representing official policies, ; either expressed or implied, of the FreeBSD Project. ;- ;Read telemetry file into array if not(keyword_set(data_dir)) then data_dir = "" nrows=5381501 ;Check to make sure spacecraft data is complete, if not we read it again. if (n_elements(sc_data) ne 8*nrows)then begin openr,sc_unit,data_dir + $ "hlsp_uv-bkgd_galex_telemetry_telescope_fuv-nuv_v1_table.txt",/get_lun str = "" while (strcompress(str,/remove) ne "#END") do readf,sc_unit,str sc_data = fltarr(8,nrows) readf,sc_unit,sc_data free_lun,sc_unit endif sc_year = reform(sc_data(0,*), nrows) sc_month= reform(sc_data(1,*), nrows) sc_day = reform(sc_data(2,*), nrows) sc_hour = reform(sc_data(3,*), nrows) ;Number of days as a function of month days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30] leap_days = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30] for i=1,11 do days[i] = days[i-1] + days[i] for i=1,11 do leap_days[i] = leap_days[i-1] + leap_days[i] qpos = max(where((sc_year eq obs_year) and (sc_month eq obs_month) and $ (sc_day eq obs_day) and (sc_hour le obs_hour), nqpos)) if (nqpos eq 0)then stop,"Out of range" ;Difference between reference time and actual time diff_sec = (obs_year - sc_year(qpos))*50000 + $ (obs_month - sc_month(qpos))*50000 + $ (obs_day - sc_day(qpos))*50000 + $ (obs_hour - sc_hour(qpos))*3600 ;Correct for difference between actual time and reference time actual_lon = sc_data(4, qpos) + diff_sec*sc_data(5, qpos) if (actual_lon lt -180) then actual_lon = actual_lon + 360 if (actual_lon gt 180) then actual_lon = actual_lon - 360 actual_lat = sc_data(6, qpos) + diff_sec*sc_data(7, qpos) sc_pos = {space_pos, year: obs_year, month: obs_month, day: obs_day,$ hour: obs_hour, sc_long: actual_lon, sc_lat: actual_lat} return,sc_pos end