;--------------------------------------------------------------------------- ; Document name: hsi_roll_db_full__define.pro ; Created by: Andre Csillaghy ; ; Last Modified: Fri May 2 13:59:50 2003 (csillag@soleil.cs.fh-aargau.ch) ; Aug 9, 2003 (ghurford@ssl.berkeley.edu) ;--------------------------------------------------------------------------- ; ; project: HESSI ; ; NAME: ; HESSI ROLL_DB_FULL CLASS DEFINITION ; ; PURPOSE: ; Manages HESSI PMT RAS data ; ; CATEGORY: ; Utilities (idl/util) ; ; CONSTRUCTION: ; obj = Obj_New( 'hsi_roll_db_full' ) ; obj = HSI_ROLL_DB_FULL() ; ; (INPUT) CONTROL PARAMETERS DEFINED IN THIS CLASS: ; ; ; (OUTPUT) INFORMATIONAL PARAMETERS DEFINED IN THIS CLASS: ; ; METHODS DEFINED OR OVERRIDDEN IN THIS CLASS: ; ; KEYWORDS: ; ; EXAMPLES: ; ; PARENT CLASS: ; Framework ; ; (AGGREGATED) SOURCE CLASSES: ; HSI_Packet ; ; DESTINATION CLASSES: ; ; SEE ALSO: ; ; HISTORY: ; ;-------------------------------------------------------------------- FUNCTION HSI_Roll_Db_Full::GetStruct RETURN, {hsi_roll_solution_full} END ;-------------------------------------------------------------------- PRO HSI_ROLL_DB::Generate, OBS_TIME_INTERVAL = obs_time_interval, DBSOLUTION = dbsolution ; wrapper around pmtras_db_generator pmtras_dbase_generator, anytim( obs_time_interval ), dbsol=dbsolution Ptr_Free, self.dbsolution self.dbsolution = Ptr_new( dbsolution ) repeat wdelete until !d.window eq -1 END ;-------------------------------------------------------------------- FUNCTION hsi_roll_db_full::GetRecSize return, 252 END ;-------------------------------------------------------------------- PRO HSI_Roll_Db_Full::Update, $ OBS_TIME_INTERVAL=obs_time_interval, $ FILENAME=filename, $ DBSOLUTION=dbsolution ; merge the old and the new points IF Keyword_Set( OBS_TIME_INTERVAL ) THEN BEGIN self->Generate, OBS_TIME_INTERVAL = obs_time_interval, DBSOLUTION = dbsolution ; self->Manager, dbsolution, dbsolution ENDIF ELSE IF Keyword_Set( FILENAME ) THEN BEGIN FOR i=0, N_Elements( filename )-1 DO BEGIN IF NOT file_exist( filename[i] ) THEN BEGIN print, filename[i], ' does not exist, skipping ...' ENDIF ELSE BEGIN Restore, filename[i] IF n_elements( dbsolution_tot ) EQ 0 THEN BEGIN dbsolution_tot = dbsolution ENDIF ELSE BEGIN dbsolution_tot = [dbsolution_tot, dbsolution] ENDELSE ENDELSE ENDFOR IF n_elements( dbsolution_tot ) EQ 0 THEN BEGIN print, 'no files found, exiting without update' return ENDIF dbsolution = dbsolution_tot ENDIF ELSE IF NOT Keyword_Set( DBSOLUTION ) THEN BEGIN dbsolution = *self.dbsolution ENDIF new_master = 'hsi_roll_db_master_' + time2file( ut_time() ) + '.dat' Message, ' writing new master db ' + new_master, /INFO self->write_log, ' Writing new master db ' + new_master Openw, unit, new_master, /GET_LUN, /XDR file_info = fstat( self.file_unit ) IF self.file_unit EQ 0 OR file_info.open EQ 0 THEN BEGIN ; if there is no master database available, then we just need to write ; the new elemenst in the file, and get out of here. Writeu, unit, dbsolution ; now we can close it and reopen it as the master database Free_lUn, unit self->open_dbase, filename = new_master RETURN ENDIF Point_LUn, self.file_unit, 0 n_valid_points = N_Elements( dbsolution ) i = 0L j = 0L done_old = 0 done_new = 0 Point_LUn, self.file_unit, 0 this_old_entry = self->GetStruct() Readu, self.file_unit, this_old_entry this_new_entry = dbsolution[0] WHILE NOT EOF(self.file_unit) DO BEGIN WHILE (this_old_entry.sctime LT this_new_entry.sctime OR done_new) $ AND NOT done_old DO BEGIN writeu, unit, this_old_entry ; print, 'writing: ', $ ; commented out 9Aug03 - gh ; hsi_sctime2any( {seconds: this_old_entry.sctime, bmicro: 0}, /ccs ) IF eof( self.file_unit ) THEN BEGIN done_old = 1 ENDIF ELSE BEGIN Readu, self.file_unit, this_old_entry ENDELSE ENDWHILE WHILE (this_new_entry.sctime LE this_old_entry.sctime OR done_old ) $ AND NOT done_new DO BEGIN ;print, 'writing: ', hsi_sctime2any( {seconds: this_new_entry.sctime, bmicro: 0}, /ccs ) writeu, unit, this_new_entry j = j+1 IF j GE n_valid_points THEN BEGIN done_new = 1 ENDIF ELSE BEGIN this_new_entry = dbsolution[j] ENDELSE ENDWHILE ENDWHILE Free_Lun, unit self->open_dbase, filename = new_master END ;-------------------------------------------------------------------- PRO HSI_Roll_DB_full::Open_dbase, FILENAME = filename IF Keyword_Set( FILENAME ) THEN BEGIN f = hsi_loc_file( filename, COUNT=count, /NO_DIALOG ) endif else begin f = hsi_loc_file( 'hsi_roll_db_master*.dat', COUNT=count, /NO_DIALOG ) endelse self->HSI_Roll_DB::Open_DBase, FILENAME = f, /NO_SEARCH END ;--------------------------------------------------------------------- PRO HSI_Roll_Db_Full::Manager ; here we will integrate the manager ; hsi_roll_manager, dbsol,valid_points ; currently we just pass all the points for testing valid_points = *self.dbsolution self.valid_points = Ptr_New( valid_points ) END ;-------------------------------------------------------------------- PRO HSI_roll_db_full::Generate_SSW_File, obs_time_interval ; obs time is rounded to the nearest month ; this is all for later IF 0 THEN BEGIN month_time_range = Round_Time( time_range, /MONTH ) fid = get_fid( month_time_range[0], month_time_range[1], /no_day ) file_prefix = 'hsi_db_' files = file_prefix + fid + '.fits' n_files = N_Elements( files ) sc_time_range = hsi_any2sctime( month_time_range, /SHORT ) ; first find the beginning yes_time = 0 i = 0 while not eof( unit ) and not yes_time do begin this_entry = a[i] yes_time = this_entry.time GE sc_time_range[0] i = i+1 endwhile file_idx = 0 ; now we have the beginning. let's write the files while not eof(unit) and this_entry.time le sc_time_range[1] do begin i_start = i i = i+1 ; are we using the correct file? entry_fid = get_fid( hsi_sctime2any( this_entry.time ), /no_day ) if entry_fid ne fid[file_idx] then begin ; now we have to write a new file file_idx = entry_fid print, 'writing primary header' ; FxHmake, primary_header, /EXTEND, /DATE, /INIT ; FxAddPar, primary_header, 'DATE_OBS', anytim(/ccsds, absolute_time_range[0]) ; FxAddPar, primary_header, 'DATE_END', anytim(/ccsds, absolute_time_range[1]) ; FxAddPar, primary_header, 'TIME_UNIT', self->Get( /TIME_UNIT ) ; MWrFITS, dummy, filename[file_idx], primary_header FXBHMake, header, N_Elements( data ), Tag_Names( data, /STRUCTURE_NAME ) FXAddPar, header, 'SECONDS', ut_ref.seconds FXAddPar, header, 'BMICRO', ut_ref.bmicro FXAddPar, header, 'EXTNAME', Tag_Names( data, /STRUCTURE_NAME ) MWrFITS, a[i_start:i], filename, header, /CREATE endif this_entry = a[i] endwhile ENDIF ; this is the temporary part to be revised later new_ssw = 'hsi_roll_db_' + time2file( ut_time() ) + '.dat' Message, ' writing new ssw db ' + new_ssw, /INFO self->write_log, ' Writing new ssw db ' + new_ssw Openw, unit, new_ssw, /GET_LUN, /XDR point_lun, self.file_unit, 0 this_entry = self->GetStruct() i = 0L ssw_entry = {hsi_roll_solution} WHILE NOT eof( self.file_unit ) DO BEGIN Readu, self.file_unit, this_entry Struct_Assign, this_entry, ssw_entry Writeu, unit, ssw_entry i = i+1 ENDWHILE Free_LUn, unit END ;----------------------------------------------------- PRO Hsi_roll_db_full__define self = {hsi_roll_db_full, $ INHERITS hsi_roll_db } END