PRO cycdat4 ;+ ; ; NAME: ; cycdat4 ; PURPOSE: ; Puts the cycle type information in each data set header ; CATEGORY: ; Post Processing ; CALLING SEQUENCE: ; cycdat4 ; INPUTS: ; None ; OPTIONAL INPUT PARAMETERS: ; NONE ; OUTPUTS: ; The raw data are copied with updated headers into new files in 'post' ; IR Only ; OPTIONAL OUTPUT PARAMETERS: ; None ; KEYWORDS: ; None ; COMMON BLOCKS: ; c_system and c_header are required. ; SIDE EFFECTS: ; None ; RESTRICTIONS: ; None ; EXAMPLE: ; cycdat4 ; PROCEDURE: ; First I verify that there is data to process. ; Second I verify that I can create the sub-directories. ; Then I extract the descent cycle data ; Then I update data base files ; ; MODIFICATION HISTORY: ; 30-01-1994 NT Prototype. ; 14-03-1994 NT Inclusion of data set checker, lamp, and ; shutter cycle resource checker. ; 16-03-1994 NT Bugs fixed using false data generator to analyse. ; Inclusion of the time data set pixels analyser ; to determine the experiment on time. ; 30-05-1994 NT Inclusion of switches to turn off some functions ; and more verbosity. ; 06-06-1994 LED Added time statements to printouts ; 24-06-1994 LED Extracted from d_pstprc. Update IR only. ; 25-06-1994 LED Tested on test log "baptism2". Because no substantive ; changes were made from CFE routine, one file was ; checked against the Descent Data Set corresponding ; to it. ; ;---------------------------------------------------------------------------- ; D I S R S O F T (C) 1 9 9 4 ;----------------------------------------------------------------------------- ;- STATUS=STRARR(4) STATUS(0)='S' STATUS(1)='SUCCESS' ; USER enter name of routine inside quotes STATUS(2)='cycdat4' ; leave this STATUS(3)='' STATUS_SET=0 ; enter version number inside quotes VERSION='V1.0' ; enter the full procedure call in here CALL='cycdat4' OLD_DIRECTORY='DB/' NEW_DIRECTORY='post' print,SYSTIME(),' I am starting' @c_system.inc @c_header.inc CD,CURR=CURR ; error checking ---- insert maximum and minimum number of parameter IF (N_PARAMS(0) GT 0) THEN BEGIN STATUS(0)='F' STATUS(1)='FAILURE' STATUS(3)='Bad input parameters' PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+STATUS(3)+'. EXIT.' PRINT,'Call is '+CALL GOTO,LEAVE ENDIF CASE STRUPCASE(STRTRIM(!VERSION.OS,2)) OF 'HP-UX':BEGIN SEPARATOR='/' END 'WINDOWS':BEGIN SEPARATOR='\' END 'VMS':BEGIN SEPARATOR='.' END 'SUNOS':BEGIN SEPARATOR='/' END 'MACOS':BEGIN SEPARATOR=':' END ELSE:BEGIN STATUS(0)='F' STATUS(1)='FAILURE' STATUS(3)='Unknown operating system' PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+STATUS(3)+'. EXIT.' GOTO,LEAVE END ENDCASE Z_OLD=SIZE(OLD_DIRECTORY) Z_NEW=SIZE(NEW_DIRECTORY) IF (Z_OLD(0) NE 0) OR (Z_OLD(1) NE 7) THEN BEGIN STATUS(0)='F' STATUS(1)='FAILURE' STATUS(3)='Bad input old directory name' PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+STATUS(3)+'. EXIT.' GOTO,LEAVE ENDIF IF (Z_NEW(0) NE 0) OR (Z_NEW(1) NE 7) THEN BEGIN STATUS(0)='F' STATUS(1)='FAILURE' STATUS(3)='Bad input new directory name' PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+STATUS(3)+'. EXIT.' GOTO,LEAVE ENDIF ; check if the old directory is valid TEST=T_VALDIR(OLD_DIRECTORY) IF TEST NE 1 THEN BEGIN STATUS(0)='F' STATUS(1)='FAILURE' STATUS(3)='Raw data directory not existing' PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+STATUS(3)+'. EXIT.' GOTO,LEAVE ENDIF ; check if there are any files PRINT,SYSTIME(),' ',STRTRIM(STRUPCASE(STATUS(2)),2)+$ ' : Checking if there are files to process.' spawn,'find DB/Ir -type f -print |sort',NAMETABLE Z_NAMETABLE=SIZE(NAMETABLE) print,'There are this many files to process ',Z_NAMETABLE(1) IF (Z_NAMETABLE(0) EQ 0) AND (NAMETABLE(0) EQ '') THEN BEGIN STATUS(0)='F' STATUS(1)='FAILURE' STATUS(3)='No data files present in raw data directories' PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+STATUS(3)+'. EXIT.' GOTO,LEAVE ENDIF ; sub-directory names SUB_DIRS=['ir'] Z_SUB_DIRS=SIZE(SUB_DIRS) ; corresponding old sub-directory names OLD_SUB_DIRS=['Ir'] ; determine the full directory paths of the new data file structure NEW_DIR_TEMP=STRTRIM(NEW_DIRECTORY,2) NEW_STR_LEN=STRLEN(NEW_DIR_TEMP) WHILE T_SEPARA(STRMID(NEW_DIR_TEMP,NEW_STR_LEN-1,1)) NE -1 DO NEW_STR_LEN=$ NEW_STR_LEN-1 NEW_DIR_TEMP=STRMID(NEW_DIR_TEMP,0,NEW_STR_LEN) NEW_DIR_STRUC=STRARR(Z_SUB_DIRS(1)) FOR I=0,Z_SUB_DIRS(1)-1 DO BEGIN NEW_DIR_STRUC(I)=NEW_DIR_TEMP+SEPARATOR+SUB_DIRS(I) IF SEPARATOR EQ '.' THEN NEW_DIR_STRUC(I)=NEW_DIR_STRUC(I)+']' ENDFOR ; determine the full directory paths of the old data file structure OLD_DIR_TEMP=STRTRIM(OLD_DIRECTORY,2) OLD_STR_LEN=STRLEN(OLD_DIR_TEMP) WHILE T_SEPARA(STRMID(OLD_DIR_TEMP,OLD_STR_LEN-1,1)) NE -1 DO OLD_STR_LEN=$ OLD_STR_LEN-1 OLD_DIR_TEMP=STRMID(OLD_DIR_TEMP,0,OLD_STR_LEN) OLD_DIR_STRUC=STRARR(Z_SUB_DIRS(1)) FOR I=0,Z_SUB_DIRS(1)-1 DO BEGIN OLD_DIR_STRUC(I)=OLD_DIR_TEMP+SEPARATOR+OLD_SUB_DIRS(I) IF SEPARATOR EQ '.' THEN OLD_DIR_STRUC(I)=OLD_DIR_STRUC(I)+']' ENDFOR spawn,'mkdir post/ir' CASE STRUPCASE(STRTRIM(!VERSION.OS,2)) OF 'VMS':NEW_DIR_TEMP=NEW_DIR_TEMP+']' 'HP-UX':NEW_DIR_TEMP=NEW_DIR_TEMP+'/' 'WINDOWS':NEW_DIR_TEMP=NEW_DIR_TEMP+'\' 'SUNOS':NEW_DIR_TEMP=NEW_DIR_TEMP+'/' 'MACOS':NEW_DIR_TEMP=NEW_DIR_TEMP+':' ELSE:BEGIN STATUS(0)='F' STATUS(1)='FAILURE' STATUS(3)='Unknown operating system' PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+STATUS(3)+'. EXIT.' GOTO,LEAVE END ENDCASE ; determine the cycle type, scenario step, and spm_flag from the descent ; data sets and store in preparation for the rest of the business spawn,'find DB/Descent -type f -print |sort',DesNAMETABLE PRINT,SYSTIME(),' ',STRTRIM(STRUPCASE(STATUS(2)),2)+$ ' : Determining cycle information.' Z_NAMETABLE=SIZE(DesNAMETABLE) CYCLE_NUMBERS=INTARR(Z_NAMETABLE(1))-1 CYCLE_TYPES=INTARR(Z_NAMETABLE(1))-1 SCENARIO_STEPS=INTARR(Z_NAMETABLE(1))-1 SPM_FLAGS=INTARR(Z_NAMETABLE(1))-1 ; only enter the routine if valid descent data set files found IF Z_NAMETABLE(1) GT 0 and Z_NAMETABLE(1) NE 7 THEN BEGIN FOR I=0,Z_NAMETABLE(1)-1 DO BEGIN D_RHEAD,DesNAMETABLE(I),HEADER,STATUS1 IF STRUPCASE(STRMID(STRTRIM(STATUS1(0),2),0,1)) NE 'S' THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+'D_RHEAD failure on '+$ DesNAMETABLE(I)+'. Continuing.' GOTO,CARRY_AGAIN ENDIF OUT1=D_VALUE(HEADER,H_CYCLE_NUMBER,GOOD,STATUS1) IF STRUPCASE(STRMID(STRTRIM(STATUS1(0),2),0,1)) NE 'S' THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+$ 'No descent cycle number on '+$ DesNAMETABLE(I)+'. Continuing.' GOTO,CARRY_AGAIN ENDIF OUT2=D_VALUE(HEADER,H_CYCLE_TYPE,GOOD,STATUS1) IF STRUPCASE(STRMID(STRTRIM(STATUS1(0),2),0,1)) NE 'S' THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+$ 'No descent cycle type on '+$ DesNAMETABLE(I)+'. Continuing.' GOTO,CARRY_AGAIN ENDIF OUT3=D_VALUE(HEADER,H_SCEN_STEP,GOOD,STATUS1) IF STRUPCASE(STRMID(STRTRIM(STATUS1(0),2),0,1)) NE 'S' THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+$ 'No descent scenario step on '+$ DesNAMETABLE(I)+'. Continuing.' GOTO,CARRY_AGAIN ENDIF OUT4=D_VALUE(HEADER,H_SPM_FLAG,GOOD,STATUS1) IF STRUPCASE(STRMID(STRTRIM(STATUS1(0),2),0,1)) NE 'S' THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+$ 'No descent spm flag on '+$ DesNAMETABLE(I)+'. Continuing.' GOTO,CARRY_AGAIN ENDIF CYCLE_NUMBERS(I)=OUT1 CYCLE_TYPES(I)=OUT2 SCENARIO_STEPS(I)=OUT3 SPM_FLAGS(I)=OUT4 CARRY_AGAIN: ENDFOR CYCLE_TYPES=CYCLE_TYPES(WHERE(CYCLE_NUMBERS NE -1)) SCENARIO_STEPS=SCENARIO_STEPS(WHERE(CYCLE_NUMBERS NE -1)) SPM_FLAGS=SPM_FLAGS(WHERE(CYCLE_NUMBERS NE -1)) CYCLE_NUMBERS=CYCLE_NUMBERS(WHERE(CYCLE_NUMBERS NE -1)) ENDIF ELSE BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+$ 'No correct descent data sets found'+$ '. Continuing.' ENDELSE ; now begin the transfer of data from the old directory to the new one PRINT,SYSTIME(),' ',STRTRIM(STRUPCASE(STATUS(2)),2)+$ ' : Beginning creation of new files.' CD,CURR=HOLDING_DIR FOR I=0,Z_SUB_DIRS(1)-1 DO BEGIN CD,HOLDING_DIR CD,OLD_DIR_STRUC(I) print,SYSTIME(),' I am writing the files in directory: ',NEW_DIR_STRUC(I) spawn,'find . -type f -print',FILES FILES=strmid(FILES,2,1000) Z_FILES=SIZE(FILES) IF FILES(0) NE '' THEN BEGIN FOR J=0,Z_FILES(1)-1 DO BEGIN print,format='($,".")' D_IRREAD,FILES(J),HEADER,PIXELS,GEOM_DATA,STATUS1 IF STRUPCASE(STRMID(STRTRIM(STATUS1(0),2),0,1)) NE 'S' THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+'D_IRREAD failure on '+$ OLD_DIR_STRUC(I)+FILES(J)+' Continuing.' GOTO,CARRY_ON ENDIF ; PERFORM INTERPOLATION OPERATIONS HERE ; operation 1 map descent data into headers HEADER_OUT=HEADER+'' PIXELS_OUT=PIXELS+0 DESC_CYCLE_NUMBER=D_VALUE(HEADER_OUT,H_CYCLE_NUMBER,GOOD,STATUS1) IF STRUPCASE(STRMID(STRTRIM(STATUS1(0),2),0,1)) NE 'S' THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+'No cycle number found '+$ OLD_DIR_STRUC(I)+FILES(J)+' Continuing.' GOTO,NO_INSERT ENDIF DATA_SET=WHERE(CYCLE_NUMBERS EQ DESC_CYCLE_NUMBER,COUNT) IF COUNT EQ 0 THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+'No cycle number found '+$ 'in descent cycle table. Continuing.' GOTO,NO_INSERT ENDIF D_INSERT,HEADER_OUT+'',HEADER_OUT,CYCLE_TYPES(DATA_SET(0)),$ H_CYCLE_TYPE,'P','(I2)',STATUS1 IF STRUPCASE(STRMID(STRTRIM(STATUS1(0),2),0,1)) NE 'S' THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+'D_INSERT failure on '+$ OLD_DIR_STRUC(I)+FILES(J)+' Continuing.' GOTO,NO_INSERT ENDIF D_INSERT,HEADER_OUT+'',HEADER_OUT,SCENARIO_STEPS(DATA_SET(0)),$ H_SCEN_STEP,'P','(I2)',STATUS1 IF STRUPCASE(STRMID(STRTRIM(STATUS1(0),2),0,1)) NE 'S' THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+'D_INSERT failure on '+$ OLD_DIR_STRUC(I)+FILES(J)+' Continuing.' GOTO,NO_INSERT ENDIF D_INSERT,HEADER_OUT+'',HEADER_OUT,SPM_FLAGS(DATA_SET(0)),$ H_SPM_FLAG,'P','(I2)',STATUS1 IF STRUPCASE(STRMID(STRTRIM(STATUS1(0),2),0,1)) NE 'S' THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+'D_INSERT failure on '+$ OLD_DIR_STRUC(I)+FILES(J)+' Continuing.' GOTO,NO_INSERT ENDIF NO_INSERT: ; determine the new name of the file DECIMAL=STRPOS(FILES(J),'.') CD,CURR=TEMP CD,HOLDING_DIR CD,NEW_DIR_STRUC(I) NEW_NAME=STRMID(FILES(J),0,DECIMAL+3)+'A'+$ STRMID(FILES(J),DECIMAL+4,1000) D_IRWRIT,NEW_NAME,HEADER_OUT,PIXELS,GEOM_DATA,STATUS1 IF STRUPCASE(STRMID(STRTRIM(STATUS1(0),2),0,1)) NE 'S' THEN BEGIN PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+'D_IRWRIT failure on '+$ NEW_NAME+' Continuing.' STOP GOTO,CARRY_ON ENDIF CD,TEMP CARRY_ON: ENDFOR ENDIF ENDFOR GOTO,LEAVE CLOSING: STATUS(0)='F' STATUS(1)='FAILURE' STATUS(3)='I/O error' PRINT,' ' PRINT,STRTRIM(STRUPCASE(STATUS(2)),2)+' : '+STATUS(3)+'. Exiting.' FREE_LUN,UNIT LEAVE: CD,CURR RETURN ; or RETURN,OUTPUT if the program is a function END