;+ ; Project : STEREO - SSC ; ; Name : SSC_REGISTER_STEREO_KERNEL ; ; Purpose : Register a STEREO SPICE kernel in the database ; ; Category : STEREO, Orbit ; ; Explanation : Registers a STEREO SPICE kernel in the "stereo_kernels" ; database. The database stores the following parameters: ; ; FILENAME e.g. "ahead_2006_042_03.epm.bsp" ; FILEPREFIX e.g. "ahead_2006_042" ; VERSION e.g. 3 (or -1 if not found) ; FILETYPE "epm", "depm", or "ah" ; SCID Either A or B ; START_DATE Start time for data within the file ; END_DATE End time for data within the file ; MOD_DATE File modification date ; FILEPATH Relative path within SolarSoft (usually blank) ; VALID Either 0 or 1 ; ; Syntax : SSC_REGISTER_STEREO_KERNEL, FILENAME [, FILEORIG ] ; ; Examples : ; ; Inputs : FILENAME = The name of the binary SPICE kernel file to ; register. Can also be an array of filenames. ; ; Opt. Inputs : FILEORIG = The name of the original transfer-format file. Used ; to determine the file modification date. ; ; Outputs : Information about the SPICE kernel is stored in the ; stereo_kernels.db* database files. ; ; Opt. Outputs: None. ; ; Keywords : 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. In order to ; use this feature, ERRMSG must be defined first, e.g. ; ; ERRMSG = '' ; SSC_REGISTER_STEREO_KERNEL, ERRMSG=ERRMSG, ... ; IF ERRMSG NE '' THEN ... ; ; Calls : DATATYPE, FILE_EXIST, BREAK_FILE, VALID_NUM, CONCAT_DIR, ; GET_STEREO_SPICE_RANGE, DBOPEN, DBFIND, DBUPDATE, DBBUILD, ; DBCLOSE ; ; Common : None. ; ; Env. Vars. : Uses the environment variable STEREO_SPICE_W to point to the ; database files. If not found, it defaults to the current ; directory. ; ; Restrictions: ; ; Side effects: None. ; ; Prev. Hist. : None. ; ; History : Version 1, 22-Feb-2006, William Thompson, GSFC ; ; Contact : WTHOMPSON ;- ; pro ssc_register_stereo_kernel, filename, fileorig, errmsg=errmsg on_error, 2 ; ; Check the input parameters. ; if datatype(filename,1) ne 'String' then begin message = 'Filename not passed' goto, handle_error endif n_files = n_elements(filename) if n_elements(fileorig) eq 0 then fileorig = filename if n_elements(fileorig) ne n_files then begin message = 'FILENAME and FILEORIG arrays have different sizes' goto, handle_error endif ; ; Get the file creation dates. If the .x* file exists, then base the time on ; that file. ; mod_date = dblarr(n_files) for i=0L,n_files-1 do begin if not file_exist(fileorig[i]) then begin message = 'File ' + fileorig[i] + ' not found' goto, handle_error endif testfile = fileorig[i] pos = strpos(testfile, '.b', /reverse_search) if pos gt 0 then strput, testfile, '.x', pos openr, unit, testfile, /get_lun mod_date[i] = (fstat(unit)).mtime + 378691200.D0 ;Unix time -> UTC free_lun, unit endfor ; ; Get the full name, spacecraft, prefix, version, and type. ; break_file, filename, disk, dir, prefix, ext name = prefix + ext scid = strupcase(strmid(name,0,1)) ;First letter ; type = strarr(n_files) ;First part of extension pos = strpos(ext,'.',1) for i=0L,n_files-1 do if pos[i] gt 0 then type[i] = strmid(ext[i],1,pos[i]-1) ; pos = strpos(prefix, '_', /reverse_search) ;Last underscore version = replicate(-1,n_files) for i=0L,n_files-1 do begin if pos[i] gt 0 then begin sversion = strmid(prefix[i], pos[i]+1, strlen(prefix[i])-pos[i]-1) if valid_num(sversion) then begin version[i] = fix(sversion) prefix[i] = strmid(prefix[i], 0, pos[i]) endif endif endfor ; ; Get the start and end times. ; start_date = dblarr(n_files) end_date = dblarr(n_files) for i=0L,n_files-1 do begin get_stereo_spice_range, filename[i], date0, date1, /tai start_date[i] = date0 end_date[i] = date1 endfor ; ; Open the database file for write access. ; unavail = 0 !priv = 2 database = concat_dir(getenv('STEREO_SPICE_W'), 'stereo_kernels') dbopen, database, 1, unavail=unavail if unavail then begin message = 'Unable to open STEREO_KERNELS database' goto, handle_error endif ; ; Find the entries that already exist. ; entry = lonarr(n_files) for i=0L,n_files-1 do entry[i] = dbfind('filename=' + name[i], /silent) wfound = where(entry gt 0, nfound, complement=wnew, ncomplement=nnew) ; ; If the entry already exists, then modify the information. ; if nfound gt 0 then dbupdate, entry[wfound], $ 'filename,fileprefix,version,filetype,scid,start_date,end_date,mod_date', $ name[wfound], prefix[wfound], version[wfound], type[wfound], scid[wfound], $ start_date[wfound], end_date[wfound], mod_date[wfound] ; ; Otherwise, add the entry. ; if nnew gt 0 then begin path = strarr(nnew) valid = version gt 0 dbbuild, name[wnew], prefix[wnew], version[wnew], type[wnew], scid[wnew], $ start_date[wnew], end_date[wnew], mod_date[wnew], path, valid[wnew], $ status=status if status eq 0 then begin message = 'Write to database not successful' goto, handle_error endif endif goto, finish ; ; Error handling point. ; HANDLE_ERROR: if n_elements(errmsg) ne 0 then $ errmsg = 'ssc_register_stereo_kernel: ' + message else $ message, message, /continue ; ; Close the database, and return whether the routine was successful or not. ; FINISH: dbclose end