# /bin/csh -f # set_test_config_by_time - add config info to ground test data. # Synopsis: # set_test_config_by_time # Where interval is in the form time/interval, e.g. # set_test_config_by_time 2006.10.21_15:00/12h will get the daylight hours for 21 Oct 2006 # This script will find the times for all images in the specified interval then # for each of those times it will find the configuration files closest to but before # that time and add the keyword values to the image series headers. # It will look for "FTS" files and for "PCU" files. # set echo set noglob set TIME = $1 # source of image times and FSN, assume index key: FSN, T_OBS # set IMAGE_SERIES = hmi_ground.lev0_ral set IMAGE_SERIES = hmi_ground.lev0_fsfm_0445_0009 # source of config files, assume index keys: type, date, and segment: file set CONFIG_SERIES = hmi_ground.lev0_config # target series to update. assume index key fsn, and other keys: date and keys from config files. set CONFIG_FILES = hmi_ground.test_config_files # make temp file name set NOW = `date "+%Y%m%d"` set TMP = /tmp/pcufsn.$NOW.$$ mkdir $TMP # get list of images to process show_keys 'ds='$IMAGE_SERIES'[]['$TIME']' key=T_OBS,FSN -q >$TMP/times set nimages = `wc -l <$TMP/times` # Loop through available images to get PCU and other setup configuration keywords. set iimage = 0 while ($iimage < $nimages) # get this time and increment for next one set IMAGE_INFO = `head -1 $TMP/times` tail +2 $TMP/times >$TMP/moretimes mv $TMP/moretimes $TMP/times # get time and FSN for this image set IMAGE_TIME = $IMAGE_INFO[1] set IMAGE_SECS = `time_convert time=$IMAGE_TIME` set FSN = $IMAGE_INFO[2] echo Processing image $FSN from $IMAGE_TIME # loop through the possible types to get and process files # First get the "FTS" file with all keywords that is just before the image time # get filename for "FTS_LOG" config file at or just before this image time set FTS_INFO = `show_keys "ds=hmi_ground.test_config_files[? recnum = (select recnum from hmi_ground.test_config_files where type = 'fts_log' and date <= $IMAGE_SECS order by date desc limit 1) ?]" -p -q key=date seg=file ` if ($#FTS_INFO != 2) then echo Problem, no config data found for $IMAGE_TIME for FTS_LOG, $FTS_INFO exit endif # now get date and filename cp $FTS_INFO[2] $TMP/data # Add ".." around each line to preserve imbedded blanks in strings awk '{printf("\"%s\"\n",$0)}' <$TMP/data >$TMP/params set_keys -c ds=$CONFIG_SERIES fsn=$FSN T_OBS=$IMAGE_TIME @$TMP/params echo Set FTS params: cat $TMP/params # Now have all params but look to see if more recent PCU info available set PCU_INFO = `show_keys "ds=hmi_ground.test_config_files[? recnum = (select recnum from hmi_ground.test_config_files where type = 'pcu' and date <= $IMAGE_SECS order by date desc limit 1) ?]" -p -q key=date seg=file ` set pcu_time = `time_convert time=$PCU_INFO[1]` set new_pcu = `echo $pcu_time ">=" $IMAGE_SECS | bc -l` if ($new_pcu == 1) then cp $PCU_INFO[2] $TMP/data # Add ".." around each line to preserve imbedded blanks in strings awk '{printf("\"%s\"\n",$0)}' <$TMP/data >$TMP/params set_keys -c ds=$CONFIG_SERIES fsn=$FSN T_OBS=$IMAGE_TIME @$TMP/params echo Set PCU params: cat $TMP/params endif @ iimage = $iimage + 1 rm $TMP/data $TMP/params end rm -rf $TMP