program summarize_gain use precision_def use tbt_mod implicit none type bpm_files_struct real(rp) gain(0:120,4) real(rp) const(0:120) logical test(0:120) end type type (bpm_files_struct) bpm_files(100) type range_struct character*10 label real(rp) range(0:10) end type type button_gain_struct type (range_struct) button(0:3) end type type (button_gain_struct) table0_bpm_data(0:120), table1_bpm_data(0:120) character*120 comments_list(100)/100*"nodata"/, old_comments_list(100) character*100 list, file_names(100) character*140 line character*3 bpm_name character*100 file, new_file character*8 date character*1 table_name character*2 range_name character*14 type real(rp) b_max(3), b_min(3), gain(4), const real(rp) gain_avg(0:120,1:4), const_avg(0:120), gain_sig(0:120,1:4), const_sig(0:120),gain_sum(0:120,1:4) real(rp) ave_gain real(rp) sig_gain real(rp) sig_all real(rp) inv_gain(0:10,0:120,4) real(rp) inverse_gain(0:120,1:4) real(rp) scale_factor(0:10)/5.0, 0.0625, 0.125, 0.25, 0.5, & 1.0, 2.0, 4.0, 8.0, 28.5, 56.0/ real(rp) upper_limit integer bpm integer i,j integer l integer n(0:120) integer tot, totbad integer nt, nu integer m integer table, range integer ix integer com/0/ integer gain_correct(120), gain_correct_all/0/ integer ix_end gain_avg(0:120,1:4) = 1. inv_gain(0:10,0:120,1:4) = 1. gain_sum = 0. call read_string(' List of files to read ? (Def = "list.dat") ','list.dat',list) ! print '(a,$)',' List of files to read ? ' ! accept *,list open(unit=1, file = trim(list), readonly) i=1 do read(1,'(a)', end = 99)file_names(i) if(index(file_names(i),'!')/= 0)cycle i=i+1 end do 99 continue close(unit=1) tot=0 totbad=0 sig_gain = 0. write(73,*)' BPMs with gains outside 50% of unity ' do j = 1,i-1 open(unit=1, file=file_names(j), readonly) do read(1, '(a)', end=199)line ix = index(line,'gain_correct =') if(ix /= 0)then ix = ix + 14 ix_end = index(line,',') -1 read(line(ix:ix_end),*)gain_correct(j) if(j > 1 .and. gain_correct(j) /= gain_correct_all)then print *,' files in list are inconsistent with respect to gain correction status' stop endif if(gain_correct(j) == no_correct$ .or. gain_correct(j) == pedestal_correct$) type = 'ABSOLUTE' if(gain_correct(j) == gain_and_pedestal_correct$) type = 'MULTIPLICATIVE' gain_correct_all = gain_correct(j) cycle endif if(index(line,'#')/=0 .or. index(line,'!') /= 0)cycle print '(a)',line read(line, *, end=199)bpm, b_max, b_min, gain, const ave_gain = sum(gain)/4 gain(1:4) = gain(1:4)/ave_gain if(all(abs(gain(1:4)-1)<0.5) )then sig_gain = (gain(1)-1)**2 + (gain(2)-1)**2 +(gain(3)-1)**2 +(gain(4)-1)**2 + sig_gain tot = tot+4 write(13,'(e12.4)')gain(1:4) else write(73,'(i4,4e12.4)')bpm,gain(1:4) totbad=totbad+4 endif write(12,'(e12.4)') gain(1:4) bpm_files(j)%gain(bpm,1:4) = gain(1:4) bpm_files(j)%const(bpm) = const bpm_files(j)%test(bpm) = .true. end do 199 continue end do print '(a,i6,a)',' There are ',tot, ' buttons with gains within 50% of unity ' print '(a,i,a,e12.4)', ' The standard deviation of the ', tot,' gains = ', sqrt(sig_gain/tot) print '(a,i6,a)',' There are ',totbad,' buttons with gains outside 50% of unity (see fort.73)' n(0:120)=0 do j= 1,i-1 do bpm=0,120 if(.not. bpm_files(j)%test(bpm))cycle gain_sum(bpm,1:4) = bpm_files(j)%gain(bpm,1:4) + gain_sum(bpm,1:4) const_avg(bpm) = bpm_files(j)%const(bpm) + const_avg(bpm) n(bpm) = n(bpm) + 1 enddo enddo do bpm=0,120 if(n(bpm) == 0)cycle gain_avg(bpm,1:4) = gain_sum(bpm,1:4)/n(bpm) const_avg(bpm) = const_avg(bpm)/n(bpm) gain_sig(0:100,1:4)=0. const_sig(0:100)=0. end do sig_all=0. nt=0 nu=0 do j= 1,i-1 do bpm=0,120 if(.not. bpm_files(j)%test(bpm))cycle gain_sig(bpm,1:4) = (bpm_files(j)%gain(bpm,1:4) - gain_avg(bpm,1:4))**2 + gain_sig(bpm,1:4) const_sig(bpm) = (bpm_files(j)%const(bpm) - const_avg(bpm))**2 + const_sig(bpm) enddo enddo do bpm=0,120 if(n(bpm) <=1 )cycle nu=nu+1 if(any(gain_avg(bpm,1:4) -1>0.2))cycle gain_sig(bpm,1:4) = sqrt(gain_sig(bpm,1:4)/(n(bpm)-1)) const_sig(bpm) = sqrt(const_sig(bpm)/(n(bpm)-1)) sig_all = sum(gain_sig(bpm,1:4)**2)+sig_all nt = nt+1 enddo print '(a,i4,a)',' There are', nu,' BPMs' sig_all = sqrt(sig_all/nt) print '(a,e12.4,a,i4,a)',' sig_all = ',sig_all,' for the ', nt,' BPMs with gains within 20% of unity' ! write in format for cesrv open(unit = 13, file = 'button_gain.dat') write(13,'(a13)')'&button_gains' print '(a,$)',' Data type ? (0 or 1, 0,1,2,...,10) ' read(5,*) table,range call date_and_time(date) comments_list(1) = '[HEADER]' comments_list(2) = '.TYPE '//trim(type) com = 2 upper_limit = 0.25 call query_real('Gain error limit', upper_limit,'f6.2') print '(a,f6.2)',' Gain error limit = ', upper_limit do bpm = 0,120 if(n(bpm)==0)then gain_avg(bpm,1:4)=1 cycle endif write(11,'(i4,10e12.4)')bpm, gain_avg(bpm,1:4), gain_sig(bpm,1:4), const_avg(bpm), const_sig(bpm) do l=1,4 write(14,'(i4,4e12.4)')bpm, gain_avg(bpm,l), gain_sig(bpm,l), const_avg(bpm), const_sig(bpm) end do if(all(abs(gain_avg(bpm,1:4)-1)