# macros for using the filters # # hp 05.11.1999 # hp 17.12.1999 FILTER_TRANSMISSION is calculated # hp 28.07.2000 brackets to protect local variables added # hp 26.01.2001 adapted for the use at 6ID-D # hp 04.05.2001 control of small beamshutter build by Peter Hiller added # hp 04.05.2001 macros are now able to control an unlimited number of # pressure driven filter banks build by Peter Hiller # # These macros use macros from the file hp_DAC_vmic4116.mac, thus this file has to be loaded # # # global definitions # global FILTER,FILTER_THICKNESS,FILTER_TRANSMISSION,FILTER_ENERGY, \ Filter,FILTER_thickness,FILTER_transmission,FILTER_energy, \ FILTER_POS,FILTER_ELEMENT,FILTER_DAC_CHANNEL,FILTER_SLEEP_TIME, \ FILTER_trans,FILTER_eichmotor,FILTER_eichtime,FILTER_eichcountrate, \ FILTER_eichstep,FILTER_quantity,FILTER_calibrated,FILTER_banks_in_use, \ FILTER_actual # # Number of Filter banks in use FILTER_banks_in_use = 2 # # Start value (should always be 0) FILTER_actual = 0 # # # # # # Konfiguration of Filter Bank 1 (internal Number 0): i = 0 # # # enter the used Element for the filters FILTER_ELEMENT[i] = "Fe" # # channel at the DAC where the filters are connected FILTER_DAC_CHANNEL[i] = 0 # # time to wait between the filter changes FILTER_SLEEP_TIME[i] = 0.5 # # number of filters built in FILTER_quantity[i] = 15 # # parameters for an automatic calibration of the filters FILTER_eichmotor[i] = "mond" FILTER_eichtime[i] = 10 FILTER_eichcountrate[i] = 10000 FILTER_eichstep[i] = 0.0001 FILTER_calibrated[i] = 0 # # filter positions measured while reducing the pressure # value marks the position directly before filter moves out of the beam FILTER_POS[i][0] = 32768 FILTER_POS[i][1] = 36850 FILTER_POS[i][2] = 37350 FILTER_POS[i][3] = 37850 FILTER_POS[i][4] = 38250 FILTER_POS[i][5] = 38900 FILTER_POS[i][6] = 39500 FILTER_POS[i][7] = 39900 FILTER_POS[i][8] = 40300 FILTER_POS[i][9] = 40750 FILTER_POS[i][10] = 41550 FILTER_POS[i][11] = 42250 FILTER_POS[i][12] = 42550 FILTER_POS[i][13] = 42850 FILTER_POS[i][14] = 43250 FILTER_POS[i][15] = 43900 FILTER_POS[i][16] = 49152 # # # # # # # # # # Konfiguration of Filter Bank 2 (internal Number 1): i = 1 # # # enter the used Element for the filters FILTER_ELEMENT[i] = "Fe" # # channel at the DAC where the filters are connected FILTER_DAC_CHANNEL[i] = 1 # # time to wait between the filter changes FILTER_SLEEP_TIME[i] = 0.5 # # number of filters built in FILTER_quantity[i] = 15 # # parameters for an automatic calibration of the filters FILTER_eichmotor[i] = "mond" FILTER_eichtime[i] = 10 FILTER_eichcountrate[i] = 10000 FILTER_eichstep[i] = 0.0001 FILTER_calibrated[i] = 0 # # filter positions measured while reducing the pressure # value marks the position directly before filter moves out of the beam FILTER_POS[i][0] = 32768 FILTER_POS[i][1] = 36850 FILTER_POS[i][2] = 37350 FILTER_POS[i][3] = 37850 FILTER_POS[i][4] = 38250 FILTER_POS[i][5] = 38900 FILTER_POS[i][6] = 39500 FILTER_POS[i][7] = 39900 FILTER_POS[i][8] = 40300 FILTER_POS[i][9] = 40750 FILTER_POS[i][10] = 41550 FILTER_POS[i][11] = 42250 FILTER_POS[i][12] = 42550 FILTER_POS[i][13] = 42850 FILTER_POS[i][14] = 43250 FILTER_POS[i][15] = 43900 FILTER_POS[i][16] = 49152 # # # # ################################################################################ # # marshutter # # hp 04.05.2001 # # open or close the small beamshutter build by Peter Hiller # ################################################################################ # def marshutter '{ local _1,wt,ch,vopen,vclose # wt = 0.2 ch = 2 vopen = 0.0 vclose = 5.0 # if ($# != 1) { printf("Usage: shutter_mar open \nor: shutter_mar close\n\n") exit } else { _1 = "$1" if (_1 == "open") { dac_volt ch vopen sleep(wt) } else if (_1 == "close") { dac_volt ch vclose sleep(wt) } else { print "Use open or close as argument!" exit } } }' # # # # ################################################################################ # # absorption # # hp 17.12.1999 # hp 26.01.2001 # # call program absor (based on Cromer, Liberman and McMasters) # ################################################################################ # def absorption ' unix("/export/home/hupfeld/common/absor") ' # # # # ################################################################################ # # _hp_calc_absor_filter # # hp 16.12.1999 # hp 26.01.2001 # # calculates the transmission through the filters for the actual energy using # routines based on Cromer, Liberman and McMasters (program alu) # ################################################################################ # def _hp_calc_absor_filter ' { local filename,unix_command1,unix_command2,unix_command3 filename = "/export/home/hupfeld/common/scratch/alu.dat" unix_command1 = "rm /export/home/hupfeld/common/scratch/alu.dat" unix_command2 = "chmod ugo+rw /export/home/hupfeld/common/scratch/alu.dat" unix_command3 = "/export/home/hupfeld/common/alu" FILTER_energy[FILTER_actual] = hc_over_e/LAMBDA unix(unix_command1) open(filename) fprintf(filename,"# %s %g %g\n",FILTER_ELEMENT[FILTER_actual],hc_over_e/LAMBDA*1000,FILTER_thickness[FILTER_actual]*1000) fprintf(filename,"FILTER_TRANSMISSION = %g\n",42) fprintf(filename,"# This file should not be edited or erased!\n") close(filename) unix(unix_command2) unix(unix_command3) open(filename) line1 = getline(filename,0) line2 = getline(filename,1) FILTER_transmission[FILTER_actual] = 0 sscanf(line2," FILTER_TRANSMISSION = %g",FILTER_transmission[FILTER_actual]) close(filename) } ' # # # # ################################################################################ # # _read_absor # # hp 01.12.1999 # hp 26.01.2001 # hp 04.05.2001 adapted to the use of multiple filterbanks # # determines the amount of alu in the beam and calls _hp_calc_absor_filter # ################################################################################ # def _read_absor ' { local i,j,bits,u,trans,fav # fav = FILTER_actual for(FILTER_actual=0;FILTER_actualFILTER_POS[FILTER_actual][i]) u = i } Filter[FILTER_actual] = u FILTER_thickness[FILTER_actual] = 3*Filter[FILTER_actual] trans = 1 if (FILTER_calibrated[FILTER_actual] == 1) { for(i=1;i<=Filter[FILTER_actual];i++) { trans = trans*FILTER_trans[FILTER_actual][i] } FILTER_transmission[FILTER_actual] = trans } else { _hp_calc_absor_filter } } FILTER_actual = fav # FILTER = 0 FILTER_THICKNESS = 0 FILTER_TRANSMISSION = 1 FILTER_ENERGY = 0 for(j=0;j 2)) { printf("Usage: set_absor [bank] value (0 to %g)\n",FILTER_quantity[FILTER_actual]) exit } if ($# == 1) { nr = int($1) } else if ($# == 2) { ii = int($1) _filter_check_nr ii nr = int($2) } if ((nr<0) || (nr>FILTER_quantity[FILTER_actual])) { printf("\nset_absor: Only values between 0 and %g are allowed, you used %g\n\n",FILTER_quantity[FILTER_actual],nr) exit } if (nr>Filter[FILTER_actual]) { dac_bit FILTER_DAC_CHANNEL[FILTER_actual] FILTER_POS[FILTER_actual][FILTER_quantity[FILTER_actual]+1] sleep(5*FILTER_SLEEP_TIME[FILTER_actual]) Filter[FILTER_actual] = FILTER_quantity[FILTER_actual] } for (i=Filter[FILTER_actual];i>=nr;i--) { pos = int((FILTER_POS[FILTER_actual][i]+FILTER_POS[FILTER_actual][i+1])/2) if (i == 0) pos = FILTER_POS[FILTER_actual][0] dac_bit FILTER_DAC_CHANNEL[FILTER_actual] pos sleep(FILTER_SLEEP_TIME[FILTER_actual]) } Filter[FILTER_actual] = nr FILTER_thickness[FILTER_actual] = 3*nr read_absor if (PRINTER != "") fprintf(PRINTER,"\n%s. Set Filter Bank %u to %d (%g mm %s, %g trans.).\n", \ date(),FILTER_actual,Filter[FILTER_actual],FILTER_thickness[FILTER_actual],FILTER_ELEMENT[FILTER_actual],FILTER_transmission[FILTER_actual]) if (DATAFILE != "") fprintf(DATAFILE,"#C %s. Set Filter Bank %u to %d (%g mm %s, %g trans.).\n", \ date(),FILTER_actual,Filter[FILTER_actual],FILTER_thickness[FILTER_actual],FILTER_ELEMENT[FILTER_actual],FILTER_transmission[FILTER_actual]) } ' # # # # ################################################################################ # # read_absor # # hp 05.11.1999 # hp 26.01.2001 # hp 04.05.2001 adapted to the use of multiple filterbanks # # calls _read_absor and displays which filter is set and the absorption # ################################################################################ # def read_absor ' { local nrf,jj if ($# == 0) { nrf = FILTER_actual _read_absor printf("Total number of filters in beam: %u\n",FILTER) printf("Total filter thickness: %g\n",FILTER_THICKNESS) printf("Total transmission: %g\n",FILTER_TRANSMISSION) for(jj=0;jj FILTER_banks_in_use)) { printf("Invalid Filter bank was addressed, only numbers between\n") printf("1 and %u are valid\n\n",FILTER_banks_in_use) exit } FILTER_actual = _1-1 } ' # # # # ################################################################################ # # filter_show_calibration # # hp 29.01.2001 # # shows the actual transmission values for all filters # ################################################################################ # def filter_show_calibration ' { local i if ($# == 1) { _filter_check_nr int($1) } else if ($# == 0) { } else { eprint "Wrong number of arguments in filter_show_calibration" exit } printf("\nfilter_show_calibration (hp) 29.01.2001\n\n") if (FILTER_calibrated[FILTER_actual] !=1) { printf("Filter bank %u has not been calibrated.\n",FILTER_actual+1) } else { printf("Calibration table for filter bank %u\n",FILTER_actual+1) printf("Filters were calibrated at %f keV\n\n",FILTER_energy[FILTER_actual]) for(i=1;i<=FILTER_quantity[FILTER_actual];i++) { printf("Filter %2g: %f\n",i,FILTER_trans[FILTER_actual][i]) } } } ' # # # # ################################################################################ # # filter_save_calibration # # hp 30.01.2001 # # saves the actual transmission values in a file # ################################################################################ # def filter_save_calibration ' { local filename printf("\nfilter_save_calibration (hp) 30.01.2001\n\n") if ($# != 1) { printf("usage: filter_save_calibration filename\n") exit } _filter_save_calibration "$*" } ' # # # # ################################################################################ # # _filter_save_calibration # # hp 30.01.2001 # # saves the actual transmission values in a file # ################################################################################ # def _filter_save_calibration ' { local i,j,u1,filename if ($# > 1) { printf("usage: _filter_save_calibration [filename]\n") exit } if ($# == 1) { filename = "$1" } else { filename = "filter_calibration.dat" } printf("Trying to remove file %s, if the file does not exist\nan error message will appear\n",filename) u1 = sprintf("rm %s\n",filename) unix(u1) open(filename) fprintf(filename,"# written by _filter_save_calibration (hp) 30.01.2001\n") fprintf(filename,"# Created at: %s\n",date()) fprintf(filename,"#\n") for(j=0;j0;ii--) { ct ct_time ct_steps = 0 while(S[DET]>FILTER_eichcountrate*ct_time) { waitmove get_angles pos = A[mot]+FILTER_eichstep*fac A[mot] = pos move_em ct ct_time ct_steps++ } if (ct_steps>10) fac = fac*2 ct FILTER_eichtime det1 = S[DET] if (MON != -1) mon1 = S[MON] set_absor ii-1 sleep(2) ct FILTER_eichtime det2 = S[DET] if (MON != -1) mon2 = S[MON] if (MON == -1) { if (det2>0) { FILTER_trans[FILTER_actual][ii] = det1/det2 } else { FILTER_trans[FILTER_actual][ii] = -1 } } else { if ((det2>0) && (mon2>0)) { FILTER_trans[FILTER_actual][ii] = (det1/mon1)/(det2/mon2) } else { FILTER_trans[FILTER_actual][ii] = -1 } } printf("Transmission filter %g: %f\n",ii,FILTER_trans[FILTER_actual][ii]) } set_absor FILTER_quantity[FILTER_actual] waitmove get_angles A[mot] = old_position move_em FILTER_calibrated[FILTER_actual] = 1 FILTER_energy[FILTER_actual] = -1*hc_over_e/LAMBDA filter_show_calibration } ' # # # #