!+ ! program plot_fit ! ! Plot_fit reads a list of files created by program GAIN_TBT. ! It is necessary to first run GAIN_TBT ! GAIN_TBT creates a file for the data and gain fit for each BPM and adds the name of that file ! to a list. The name of the list file is FILE_LIST.dat ! Plot_fit reads FILE_LIST.dat and plots the gain fit data for all of the files in the list ! program plot_fit use quick_plot use precision_def implicit none integer id real(rp) xlen/800./, ylen/540./ character*3 answer call qp_open_page('X', id,xlen,ylen,'POINTS') call draw call read_string(' Hardcopy ? ','n',answer) if(answer(1:1) == 'y' .or. answer(1:1) == 'Y')then call qp_open_page('PS-L', plot_file = 'B+-+-B++--_vs_B+--+.ps') call draw call qp_close_page endif end subroutine draw use quick_plot use precision_def implicit none type bp_data real(rp) x,y end type type (bp_data) raw(10000), fitted(10000) real(rp) gain(4) character*100 list(100), title character*19 bpm_file character*40 descrip character*2 bpm integer number, np, id integer i, ngraph integer ix logical hardcopy/.false./ call qp_set_page_border (0.01_rp, 0.02_rp, 0.02_rp, 0.02_rp, '%PAGE') call qp_set_margin (0.02_rp, 0.02_rp, 0.015_rp, 0.015_rp, '%PAGE') descrip = '(B\d+-+-\u)(B\d++--\u) vs B\d+--+\u' call qp_draw_text (descrip, 0.84_rp, 1.0_rp, '%PAGE', 'CT',height=13.0_rp,color='black') call qp_draw_text ('raw data', 0.9_rp, 0.95_rp, '%PAGE', 'CT',height=13.0_rp,color='red') call qp_draw_text ('corrected with', 0.9_rp, 0.92_rp, '%PAGE', 'CT',height=13.0_rp,color='blue') call qp_draw_text ('fitted gains', 0.9_rp, 0.90_rp, '%PAGE', 'CT',height=13.0_rp,color='blue') ! get the list of BPM files call get_bpm_list(list, number) print '(a,$)',' Which BPM ? (-1 for all) ' read(5,'(a)') bpm if(bpm(1:2) == '-1')then do i =1,number ngraph = i call string_trim(list(i),list(i),ix) bpm_file = list(i)(1:ix) call read_bpm_file(bpm_file,title,raw, gain, np) bpm_file = trim(bpm_file)//'_fit' call read_bpm_file(bpm_file,title,fitted, gain, np) call plot_bpm_data(raw,fitted,gain,title,np,ngraph) end do else print *,' bpm ', bpm bpm_file = 'BPM_'//trim(bpm)//'.dat' print *,' bpm_file = ',bpm_file ngraph= -1 call read_bpm_file(bpm_file,title,raw, gain, np) bpm_file = trim(bpm_file)//'_fit' print *,' fit_file = ', bpm_file call read_bpm_file(bpm_file,title,fitted, gain, np) call plot_bpm_data(raw,fitted,gain,title,np,ngraph) endif return end subroutine plot_bpm_data(raw,fitted,gain, title ,np, ngraph) use quick_plot use precision_def implicit none type bp_data real(rp) x,y end type type (bp_data) raw(10000), fitted(10000) character*100 title real(rp) gain(4), x(10000), z(10000), xmin, xmax, zmin, zmax integer width/7/, height/7/ integer np, ngraph, ix, iy,i integer off/0/ logical clear_page/.false./ if(ngraph == -1)then width=1 height = 1 ngraph = 1 endif if(ngraph > 48)then off = 49 if(.not. clear_page)then pause ' CR to continue' call qp_clear_page endif clear_page = .true. endif ix = mod(ngraph-1-off, width) + 1 iy = (ngraph-1-off)/width + 1 call qp_set_box (ix, iy, width,height) xmin=min(minval(raw(:)%x),minval(fitted(:)%x))/100 xmax=max(maxval(raw(:)%x),maxval(fitted(:)%x))/100 zmin=min(minval(raw(:)%y),minval(fitted(:)%y))/1e6 zmax=max(maxval(raw(:)%y),maxval(fitted(:)%y))/1e6 forall(i=1:np)x(i) = raw(i)%x/100 forall(i=1:np)z(i) = raw(i)%y/1e6 call qp_calc_and_set_axis ('X', xmin,xmax, 4, 8, 'GENERAL') call qp_calc_and_set_axis ('Y', zmin,zmax, 4, 8, 'GENERAL') ! call qp_draw_axes ("B\d+--+\u", "(B\d+-+-\u)B(\d++--\u)",trim(title)) call qp_draw_axes call qp_set_symbol_attrib ('square', color = 'red', height = 1.0_rp) call qp_draw_data (x, z,draw_line = .false., symbol_every = 1) forall(i=1:np)x(i) = fitted(i)%x/100 forall(i=1:np)z(i) = fitted(i)%y/1e6 call qp_set_symbol_attrib ('star5_filled', color = 'blue', height = 1.0_rp) call qp_draw_data (x, z,draw_line = .false., symbol_every = 1) call qp_draw_text (title, 0.8_rp, 0.1_rp,"%GRAPH",height=10.0_rp) return end subroutine plot_bpm_data subroutine get_bpm_list(list, number) use precision_def implicit none character*(100) list(100) character(100) list_file, file_in, file_out, default integer iu,i, io, lunget integer number integer ix default = 'file_list.dat' ! print '(a,$)',' list file name ? (eg file_list.dat) ' ! read(*,'(a)') file_in ! call string_trim(file_in, file_out, ix) ! if(ix == 0 .or. ix == len(file_in))then ! list_file = default ! else ! list_file = file_out ! endif call read_string(' list file name ? (DEF = file_list.dat) ', default, list_file) print *, list_file iu=lunget() open(unit=iu, file=list_file, readonly) i=1 do read(iu,'(a)',iostat=io)list(i) if(io <0)exit i=i+1 end do number = i-1 close(iu) return end subroutine get_bpm_list subroutine read_bpm_file(bpm_file,title,raw, gain, np) use precision_def implicit none integer scale type bp_data real(rp) x,y end type type (bp_data) raw(10000) character*(19) bpm_file character*(*) title character*120 line character*100 word real(rp) gain(4), temp(7), const,delta_h,delta_v integer np,bpm integer number,i,iu, lunget integer io, ix, index integer but_scale/10000/ namelist /button_sums/index,bpm,gain,const,delta_h,delta_v i=0 iu=lunget() open(unit=iu, file = trim(bpm_file), readonly) read(iu,nml=button_sums, iostat=io) write(word,'(i)')bpm call string_trim(word,word,ix) title = word(1:ix) do i=i+1 if(i>10000)exit read(iu,*,iostat=io)temp if(io < 0)exit raw(i)%x = temp(3)/but_scale raw(i)%y= temp(6)/but_scale end do np = i close(iu) return end subroutine read_bpm_file