; this program takes the text output with tab delimiters from the Exel spread ; sheat that creats DISR calibration command strings and parses each line into ; an array of strings. PRO convert_disr, p, out, comnt, byte_count, line_count,delay_time,next_time,short ; conver disr commands from string array p COMMON Single_measurment_delays, ulvs_delay, dlvs_delay, ccd_delay, dark_delay, $ image_delay, sli_strip_delay, s_a_delay, dlis_delay, ulis_delay, $ ulis_dlis_delay, long_ir_delay, dlv_delay, ulv_delay comnt = ' ' out(0) = 23 out(1) = 146 out(2) = 192 out(3) = 0 out(4) = 0 out(6) = p(3) / 256 out(7) = p(3) MOD 256 ; command id number out(8) = 0 out(9) = p(1) MOD 8 ; opcode for type of test byte_count = 0 ; flag to indicate sucessful command interpretation if (p(2) EQ 'sngl_meas') then begin out(9) = 3 ;single measurement mode opcode comnt = 'DISR snglmeas ' out(10) = 0 out(11) = p(5) MOD 16 if p(5) EQ 2 then begin comnt = comnt + 'ULVS ' next_time = ulvs_delay + (p(19) / 500) ; time delay, including exposure time endif $ else if p(5) EQ 3 then begin comnt = comnt + 'DLVS ' next_time = dlvs_delay + (p(19) / 500) ; time delay, including exposure time endif $ else if p(5) EQ 4 then begin comnt = comnt + 'CCD ' next_time = ccd_delay + (p(19) / 500) ; time delay, including exposure time endif $ else if p(5) EQ 5 then begin comnt = comnt + 'Dark ' next_time = dark_delay + (p(19) / 500) ; time delay, including exposure time endif $ else if p(5) EQ 6 then begin comnt = comnt + 'Image ' next_time = image_delay + (p(19) / 500) ; time delay, including exposure time endif $ else if p(5) EQ 7 then begin comnt = comnt + 'Strp ' next_time = sli_strip_delay + (p(19) / 500) ; time delay, including exposure time endif $ else if p(5) EQ 8 then begin comnt = comnt + 'Solar ' next_time = s_a_delay + (p(19) / 500) ; time delay, including exposure time endif $ else if p(5) EQ 9 then begin comnt = comnt + 'DLIS ' next_time = dlis_delay; + (((p(21) * 65536) + p(23)) / 1000) ; time delay, including collection time endif $ else if p(5) EQ 10 then begin comnt = comnt + 'ULIS ' next_time = ulis_delay; + (((p(21) * 65536) + p(23)) / 1000) ; time delay, including collection time endif $ else if p(5) EQ 11 then begin comnt = comnt + 'U/DLIS ' next_time = u_dlis_delay + (((p(21) * 65536) + p(23)) / 1000) ; time delay, including collection time endif $ else if p(5) EQ 12 then begin comnt = comnt + 'Lng IR ' next_time = long_ir_delay + (((p(21) * 65536) + p(23)) / 1000) ; time delay, including collection time endif $ else if p(5) EQ 13 then begin comnt = comnt + 'DLV ' next_time = dlv_delay endif $ else if p(5) EQ 14 then begin comnt = comnt + 'ULV ' next_time = ulv_delay endif $ else $ comnt = comnt + 'unkown ' out(12) = p(7) MOD 256 ; reps for this measurement comnt = comnt + STRING(FORMAT="(I0)",(out(12))) + 'rep ' if p(9) EQ 1 then begin op1 = 16 comnt = comnt + 'cl1 ' endif $ else begin op1 = 0 endelse if p(11) EQ 1 then begin op1 = op1 + 8 comnt = comnt + 'cl2 ' endif if ( p(13) EQ 1) then begin op1 = op1 + 4 comnt = comnt + 'cl3 ' endif if ( p(15) EQ 1) then begin op1 = op1 + 2 comnt = comnt + 'SSL ' endif if ( p(17) EQ 1) then begin op1 = 1 comnt = comnt + 'auto ' endif $ else begin comnt = comnt + 'nauto ' endelse READS, p(31),FORMAT="(Z4)", op3 READS, p(33), FORMAT="(Z4)", op4 if ((op3 AND '8000'XL) EQ 0) then $ comnt = comnt + 'nbad ' $ else $ comnt = comnt +'bad ' if ((op3 AND '4000'XL) EQ 0) then $ comnt = comnt + 'nsqrt ' $ else $ comnt = comnt +'sqrt ' if ((op3 AND '2000'XL) EQ 0) then $ comnt = comnt + 'nsum ' $ else begin comnt = comnt +'sum ' if p(5) EQ 3 then $ comnt = comnt + STRING(FORMAT="(I0)",(op3 MOD 256)) endelse if ((op3 AND '1000'XL) EQ 0) then $ comnt = comnt + 'nopt ' $ else $ comnt = comnt +'opt ' if ((op3 AND '0800'XL) EQ 0) then $ comnt = comnt + 'ncomp ' $ else if ((op4 AND '1000'XL) EQ 0) then $ comnt = comnt +'HWcmp ' + STRING(FORMAT="(I0)",((op4 / 32) MOD 128)) + ' '$ else $ comnt = comnt + 'SWcmp ' if ((op3 AND '0400'XL) EQ 0) then $ comnt = comnt + '12 ' $ else $ comnt = comnt +'16 ' if ((op4 AND '8000'XL) EQ 0) then $ comnt = comnt + 'ndrk ' $ else $ comnt = comnt +'dark ' if ((op4 AND '4000'XL) EQ 0) then $ comnt = comnt + 'all ' $ else if (p(5) EQ 6) then begin if (op4 MOD 32) EQ '15'xl then $ comnt = comnt +'DLI-2 ' $ else if (op4 MOD 32) EQ '16'xl then $ comnt = comnt +'SLI ' $ else if (op4 MOD 32) EQ '17'xl then $ comnt = comnt +'DLI-1 ' endif if ((op4 AND '2000'XL) EQ 0) then $ comnt = comnt + 'sngl' $ else $ comnt = comnt + 'hlvs' if (p(5) EQ 7) then $ comnt = comnt + 'col ' + STRING(FORMAT="(I0)",(p(35))) out(13) = op1 ; cal lamp 1,2,3, SSL lamp, auto exposure out(14) = p(19) / 128 ; exposure time out(15) = (p(19)*2) mod 256 ; exposure time out(16) = p(21) / 16777216 ; collection time out(17) = (p(21)/65536) mod 256 ; collection time out(18) = (p(21) / 256) mod 256 ; collection time out(19) = p(21) mod 256 ; collection time out(20) = p(23) / 256 ; shutter period out(21) = p(23) mod 256 ; shutter period out(22) = p(25) / 256 ; shutter operating mode out(23) = p(25) mod 256 ; shutter operating mode out(24) = p(27) / 256 ; ULIS sample time out(25) = p(27) mod 256 ; ULIS sample time out(26) = p(29) / 256 ; DLIS sample time out(27) = p(29) mod 256 ; DLIS sample time out(28) = op3 / 256 ; general processing options out(29) = op3 mod 256 ; general processing options out(30) = op4 / 256 ; image processing options out(31) = op4 mod 256 ; image processing options out(32) = p(35) / 256 ; strip coumn number out(33) = p(35) mod 256 ; strip coumn number byte_count = 34 endif $ else if ( p(2) EQ 'chg_mode') then begin comnt = 'DISR change mode ' out(8) = 00 out(9) = 02 ; change mode command out(10) = p(5) mod 8 ; mode (1..4) out(11) = p(7) mod 16 ; scenario number (1..8) out(12) = 0 ; sun simulator flag out(13) = p(9) mod 2 ; sun simulator flag (0 - off, 1 - on) byte_count = 14 next_time = 20 ; delay after change mode if (out(10) EQ 1) then begin if (out(13) EQ 0) then $ comnt = comnt + 'Descent sun sim off' $ else $ comnt = comnt + 'Descent sun sim on' endif if (out(10) EQ 2) then begin if (out(11) EQ 1) then $ comnt = comnt + 'Health check' $ else if (out(11) EQ 2) then $ comnt = comnt + 'In-flight Cal' $ else $ comnt = comnt + 'Cal Senario ' + STRING(FORMAT="(I0)",(out(11))) endif if (out(10) EQ 3) then $ comnt = comnt + 'Single measr' if (out(10) EQ 4) then $ comnt = comnt + 'Mem access' endif $ else if ( p(2) EQ "cmnd_enab") then begin out(8) = 00 out(9) = 01 ; enable command receipt out(10) = 00 out(11) = p(5) mod 2 ; receipt enable (0 - disable, 1 - enable) byte_count = 12 next_time = 2 if(out(11) EQ 0) then $ comnt = 'DISR command disable' $ else $ comnt = 'DISR command enable' endif $ else if ( p(2) EQ 'sngl_test') then begin comnt = 'DISR single test ' out(8) = 00 out(9) = 04 ; single test command out(10) = p(5) mod 64 ; test type out(11) = p(7) mod 256 ; test parameter out(12) = p(9) / 256 ; repetitions out(13) = p(9) mod 256 ; repetitions byte_count = 14 next_time = 120 if (out(10) EQ 32) then $ comnt = comnt + STRING(FORMAT="(I0)",(out(11))) + ' shutter tests' if (out(10) EQ 33) then begin comnt = comnt + 'DCS test ratio ' + STRING(FORMAT="(I0)",(out(11) MOD 32)) if (out(11) GT 128) then $ comnt = comnt + ' gradual' $ else if (out(11) GT 64) then $ comnt = comnt + ' 1/distance checkerboard' $ else $ comnt = comnt + ' normal checkerboard' endif if (out(10) EQ 34) then begin if(out(11) EQ 1) then $ comnt = comnt + 'Focal plane heater' $ else if(out(11) EQ 1) then $ comnt = comnt + 'SH Aux heater' $ else $ comnt = comnt + 'Both heaters' endif if (out(10) EQ 35) then begin if (out(11) EQ 0) then $ comnt = comnt + 'Cal lamp test, no lamps' $ else if (out(11) EQ 1) then $ comnt = comnt + 'Cal lamp test, lamp 1' $ else if (out(11) EQ 2) then $ comnt = comnt + 'Cal lamp test, lamp 2' $ else if (out(11) EQ 3) then $ comnt = comnt + 'Cal lamp test, lamp 1 and 2' $ else if (out(11) EQ 4) then $ comnt = comnt + 'Cal lamp test, lamp 3' $ else if (out(11) EQ 5) then $ comnt = comnt + 'Cal lamp test, lamp 1 and 3' $ else if (out(11) EQ 6) then $ comnt = comnt + 'Cal lamp test, lamp 2 and 3' $ else if (out(11) EQ 7) then $ comnt = comnt + 'Cal lamp test, all lamps' endif if (out(10) EQ 36) then begin if(out(11) EQ 0) then $ comnt = comnt + 'Surface Science Lamp, lamp off' $ else if(out(11) EQ 1) then $ comnt = comnt + 'Surface Science Lamp, lamp on' endif if (out(10) EQ 37) then $ comnt = comnt + 'Sun Lamp test' endif $ else if ( p(2) EQ 'eeprom') then begin comnt = 'DISR uplink eeprom, not implimented at this time' out(8) = 00 out(9) = 05 ; uplink eeprom command out(10) = 00 out(11) = p(5) mod 4 ; number of patches (1..3) byte_count = 12 next_time = 1 ; remainder of uplink command not coded at this time endif $ else if ( p(2) EQ 'ram_uplink') then begin comnt = 'DISR uplink ram, not implimented at this time' out(8) = 00 out(9) = 06 ; uplink ram command out(10) = p(5) mod 256 ; number of 16 bit words to uplink out(11) = p(7) mod 1 ; code flag out(12) = p(9) / 256 ; start address in RAM to replace out(13) = p(9) mod 256 ; start address in RAM to replace byte_count = 14 next_time = 1 endif $ else if ( p(2) EQ 'mem_dump') then begin comnt = 'DISR dump memory' out(8) = 00 out(9) = 07 ; dump memory command out(10) = p(5) / 256 ; number of memory ranges to dump out(11) = p(5) mod 256 ; number of memory ranges to dump n = FIX(p(5)) count = 0 i = 7 j = 12 while (count LT n) do begin out(j) = p(i) / 16777216 ; start address out(j+1) = (p(i)/65536) mod 256 ; start address out(j+2) = (p(i) / 256) mod 256 ; start address out(j+3) = p(i) mod 256 ; start address out(j+4) = p(i+2) / 16777216 ; length out(j+5) = (p(i+2)/65536) mod 256 ; length out(j+6) = (p(i+2) / 256) mod 256 ; length out(j+7) = p(i+2) mod 256 ; length comnt = comnt + ', from ' + STRING(FORMAT="(I0)",(p(i))) + ' to ' + STRING(FORMAT="(I0)",(p(i+2))) i = i + 4 j = j + 8 endwhile byte_count = j next_time = 20 endif $ else begin print, p(0), p(1), p(2), p(3), p(4)$ , FORMAT = '( "failed DISR comand p0 ",a, " p1 ", a, " p2 ", a, " p3 ", a, " p4 ",a)' endelse if (byte_count GT 0) then begin ; only generate output if real command out(5) = byte_count - 5 ; last byte of header shows count after header out(byte_count) = 204 ; CRC placeholder out(byte_count+1) = 204 ; applies to all DISR commands byte_count = byte_count + 2 save_to_temp,p, line_count, out, comnt, byte_count,delay_time,next_time,short endif end PRO convert_disr_cal, p, out, comnt, byte_count, line_count, delay_time,next_time,short ; translate DISR-CAL commands next_time = 0 if (strlen(p(2)) GE 3) then begin while (strlen(p(2)) LT 5) do p(2) = p(2) + ' ' ; left justify to 5 chars comnd = STRING(FORMAT="(a5)",p(2)) ; make sure exactly 5 character long i = 5 ; look for parameters while (strlen(p(i)) GT 0) do begin $ comnd = comnd + STRING(FORMAT="(' ',a)",p(i)) i = i + 2 endwhile comnt = 'CAL ' + comnd ; use command string for comment byte_count = strlen(comnd) ; should also be number of bytes in out comnd = BYTE(comnd) ; convert string to integer array for i = 0, byte_count-1 do $ out(i) = comnd(i) save_to_temp,p, line_count, out, comnt, byte_count,delay_time,next_time,short endif $ else begin print, FORMAT="('failed DISR-CAL command p0 ',a,' p1 ',a,' p2 ',a,' p3 ',a,' p4 ',a)", $ p(0), p(1), p(2), p(3), p(4) endelse end PRO save_to_temp, p, line_count, out, comnt, byte_count, delay_time,next_time,short ; save command file format codes in temp file for i = 0, byte_count-1 do $ ; output command bytes printf,2,out(i),FORMAT="(I0)" if (short NE 1) then begin for i = byte_count, 299 do $ ; fill with FF's printf,2,255,FORMAT="(I0)" endif printf,2,p(1),FORMAT="(I0)" ; 0=DISR, 1=OGSE, 2=DISR-CAL if (p(1) EQ 0) then $ ; DISR opcode, 0 for OGSE and DISR-CAL printf,2,out(9),FORMAT="(I0)" $ else $ printf,2,0,FORMAT="(I0)" printf,2,byte_count,FORMAT="(I0)" ;length of used portion of 300 bytes p(0) = FIX(p(0)) ; convert to integer format, if not already ;********if (p(0) LE 0) then $ printf,2,delay_time,FORMAT="(I0)"; *********$ ; time delay after last command ;***********else printf,2,p(0),FORMAT="(I0)" delay_time = next_time ; shift time to execute of current command into delay for next printf,2,0,FORMAT="(I0)" ; time delay in seconds ( 1 for milliseconds) printf,2,0,FORMAT="(I0)" ; edited flag (must be 0) printf,2,0,FORMAT="(I0)" ; checksum placehilder printf,2,comnt,FORMAT="(A)" ; comment string line_count = line_count + 1 ; keep track of count for final command file end ; begining of main program COMMON Single_measurment_delays, ulvs_delay, dlvs_delay, ccd_delay, dark_delay, $ image_delay, sli_strip_delay, s_a_delay, dlis_delay, ulis_delay, u_dlis_delay, $ long_ir_delay, dlv_delay, ulv_delay ulvs_delay = 3 dlvs_delay = 4 ccd_delay = 70 dark_delay = 5 image_delay = 62 sli_strip_delay = 5 s_a_delay = 2 dlis_delay = 2 ulis_delay = 2 u_dlis_delay = 4 long_ir_delay = 5 dlv_delay = 1 ulv_delay = 1 close,1 ; just in case something left open close,2 delay_time = 0 next_time = 0 ; name of input file print,"Enter name of input and output programs s='' read,s print,s i = 0 p = strarr(50) ; array of fifty strings to store each parameter in line p(0) = '' p(1) = '' p(2) = '' while (strlen(s) GT 0) do begin j = -1 j = strpos(s, ' ',j) ; look for space delimiter beween files if (j LT 0) then $ j = strpos(s, string(9B), j) ; look for tab delimieter if (j LT 0) then $ j = strpos(s, ',', j) ; look for comma delimieter if (j LT 0) then begin p(i) = s ; get last parameter s = '' endif $ else begin p(i) = strmid(s, 0, j) ; get file name from response s = strmid(s, j+1, strlen(s) - j - 1) endelse i = i + 1 endwhile if (strlen(p(0)) GT 1) then $ input_file = p(0) $ else $ input_file = 'test' if (strlen(p(1)) GT 1) then $ output_file = p(1) $ else $ output_file = 'gse.cmd' p(2) = strupcase(p(2)) if (p(2) EQ 'S') then $ short = 1 $ else $ short = 0 if(input_file NE output_file) then begin print,FORMAT="('Opening file ',a,' to translate into file ',a)",input_file, output_file openr,1,input_file ; get tab delimited text file openw,2,'temp_trn.tmp' ; store intermediate translation s='' ; creat string to get line of data out = BYTARR(300) ; create output string in command file format comnt = '' ; create string to hold descriptive commnat for command file line_count = 0 ; count of lines in command file byte_count = 0 ; changed for each command line pcount = 0 ; count of params found on this line count = 0 ; how many lines read in so far readf,1,s ; first two lines are descriptive, readf,1,s ; not data while (not EOF(1)) do begin readf,1,s ; get next line of text count = count + 1 ; keep track ogf line number pcount = 0 i = 0 ; position of tabs j = 0 ; position of last tab while ( i NE -1) do begin i = strpos(s, string(9B), i) ; find location of next tab if (i NE -1) then begin p(pcount) = strmid(s, j, (i - j)) ; get only between tabs pcount = pcount + 1 i = i + 1 ; be sure to skip this tab next time j = i ; start of next sub string end end if (p(1) EQ 0) then convert_disr, p, out, comnt, byte_count, line_count,delay_time,next_time,short $ else if (p(1) EQ 1) then convert_disr_cal, p, out, comnt, byte_count, line_count,delay_time,next_time,short $ else print,FORMAT="('line not understood p0 ',a,' p1 ',a,' p2 ',a,' p3 ',a,' p4 ',a,' p5 ',a)", $ p(0), p(1), p(2), p(3), p(4), p(5) for i = 0, 299 do out(i) = 255 comnt = '' for i = 0, 49 do p(i) = '' ; clear array before next line read in endwhile endif $ else $ print,FORMAT="('input file ',a,' is same as output file ',a)",input,output close, 1 ; close input file when done close, 2 ; close temp file openr,1,'temp_trn.tmp' ; now read back intermediate file ; name of output file openw,2,output_file ; and create final command file printf,2,FORMAT="(I0)",line_count while (not EOF(1)) do begin readf,1,s printf,2,s endwhile close, 1 ; close temp file when done close, 2 ; close final command file print,FORMAT="('command file generated with ',i,' lines of code.')",line_count end ; of program parse2