;docformat='rst' ;+ ; Get the orbit information for the most recent orbit in the ; AIM_CIPS_SCIENCE..Orbits table ; ; :Author: ; Chris Jeppesen, Bill Barrett ; ;- ;+ ; :Returns: ; one or more rows from the orbit table converted into orbit_info structure(s) ;- ;+ ; :Examples: ; last_orbit = get_last_orbit_info() ;- function get_last_orbit_info ; Keep a cache of the time and last orbit retrieved from the database, so that ; it is not necessary to continually repeat the same database query. common cached_last_orbit, $ last_orbit, $ last_access_time if ~keyword_set(last_access_time) then begin last_access_time = 0 last_orbit = -1 endif ; Since there is no realistic way of knowing whether the database tables have been ; updated other than by querying them, which is a time / network expensive ; operation, the decision has been made to cache the results of the last query, ; and to only check for updates periodically. ; Ten minutes is a heuristic, arbitrarily chosen time because the code that updates ; the Orbits and Sofie tables may be running asynchronously to this query. ; If a call has been made in the last ten minutes, use that result ; Otherwise check the data base. ten_minutes = 600L ; ten minutes in seconds now = systime(1) if (now - last_access_time) lt ten_minutes && size(last_orbit, /type) eq 8 then begin if get_debug_level() gt 5 then print, get_routine_name() + ' using cached last orbit #' + $ Strtrim(string(last_orbit.orbit_number,format='(%"%d")'), 2) +", starting at " + $ usec2vms(last_orbit.start_time) endif else begin ; Note that for efficiency this query uses a subselect in the where clause query = get_orbit_info_base_query() + $ ' where Sofie.orbitNum = (select max(orbitNum) from AIM_CIPS_SCIENCE.Orbits)' get_database_login, 'AIM_CIPS_SCIENCE', user=user, password=password, url=url query_database, query, data, nrows, user=user, password=password, dburl=url, /dbConnect if nrows lt 1 then message,"No data returned for: " + query last_access_time = now last_orbit = sql_to_orbit_info(data) endelse return, last_orbit end