!+ ! Subroutine plotdo (plot_type, graph, hardcopy_flag, u, no_close) ! ! Subroutine to stuff the appropriate data in arrays for plot_graph to read !- subroutine plotdo (plot_type, graph, hardcopy_flag, u, no_close) use cesrv_struct use cesrv_interface use file_number_mod use quick_plot implicit none type (universe_struct), target :: u type (graph_struct) :: graph type (p2_plot_struct) p_top, p_bottom type (qp_symbol_struct) sym_info real(rp) :: x_win_pix = 640, y_win_pix = 730 real(rp) x1_marg / 55 /, y1_marg / 30 / real(rp) x2_marg / 190 /, y2_marg / 30 / real(rp), save :: scale integer, save :: i_chan_x = -1, i_chan_hard = -1 integer ix, ios, n character(*) plot_type character(80) lines(3), line character(8) extension character(140) plot_file, dir, file logical hardcopy_flag, error logical :: init_needed = .true. logical, optional :: no_close logical ok, plot_has_ref, line1_eq_title2 ! some init you do only once... ! set page size if (.not. logic%plotit) return if (plot_type == 'INIT' .and. .not. init_needed) return n = min(len(plot_type), 5) ! Can be 4 if 'INIT' if (plot_type == 'INIT' .or. plot_type(1:n) == 'SCALE' .or. plot_type == 'WIDE') then scale = 1.0 if (plot_type(1:n) == 'SCALE') then read (plot_type(7:), *, iostat = ios) scale if (scale <= 0 .or. ios /= 0) then print *, 'PLOTDO: BAD SCALE FACTOR: ' // trim(plot_type(7:)) return endif endif if (i_chan_x /= -1) call qp_close_page if (logic%wide_plot_window) then call qp_open_page ('X', i_chan_x, 2*x_win_pix, y_win_pix, 'POINTS', scale = scale) else call qp_open_page ('X', i_chan_x, x_win_pix, y_win_pix, 'POINTS', scale = scale) endif call qp_set_text_attrib ("GRAPH_TITLE", height = 15.0_rp) call qp_set_text_attrib ("LEGEND", height = 10.0_rp) init_needed = .false. return endif ! init p_top = graph%top1 p_bottom = graph%bottom1 if (logic%plot_what == 'PLOT_WAVE') then call waveit (u, error) if (error) return p_top = u%wave%p2 p_bottom = u%wave%p2 endif plot_has_ref = (plot_type_has(plot_ref$, p_bottom%plot_data) .or. & plot_type_has(plot_ref$, p_bottom%base) .or. & plot_type_has(plot_ref$, p_top%plot_data) .or. & plot_type_has(plot_ref$, p_top%base)) ! Query for title lines ! For consistancy always query for input with command_file_open lines = '' if (plot_type == 'PS' .or. plot_type == 'GIF') then ok = .false. ix = len_trim(u%main_title1) if (ix /= 0 .or. logic%command_file_open) then print *, 'Title1: ', trim(u%main_title1) call get_input_string ('Use this for the 1st title line ?', line) call string_trim (line, line, ix) if (ix == 0 .or. line(1:1) == 'y' .or. line(1:1) == 'Y') ok = .true. endif if (.not. ok) then call get_input_string ('Title for plot:', u%main_title1) endif ok = .false. ix = len_trim(u%main_title2) if (logic%command_file_open .or. (ix /= 0 .and. & (u%main_title2(1:3) /= 'Ref' .or. & plot_type_has(plot_ref$, logic%opt_base) .or. plot_has_ref))) then print *, 'Title2: ', trim(u%main_title2) call get_input_string ('Use this for the 2nd title line ?', & line) call string_trim (line, line, ix) if (ix == 0 .or. line(1:1) == 'y' .or. line(1:1) == 'Y') ok = .true. endif if (.not. ok) then call get_input_string ('Subtitle for plot:', u%main_title2) endif lines(1) = u%main_title1 lines(2) = u%main_title2 else line1_eq_title2 = .false. if (p_top%plot_data == plot_meas$ .or. p_bottom%plot_data == plot_meas$) then lines(1) = u%main_title1 elseif (plot_has_ref) then lines(1) = u%main_title2 line1_eq_title2 = .true. else lines(1) = ' ' endif if (plot_has_ref .and. .not. line1_eq_title2) then lines(2) = u%main_title2 else lines(2) = ' ' endif endif ! Decide how big the plotting page has to be based upon what is plotted ! If get_next_graphic_file_name returns plot_file = '' then we cannot ! write to the shared disk so just make a local file 'cesrv.xxx' ! Normally the PS/GIF file will be in front and the graphics will be output to it ! Exception: When multiple pages are needed, the PS/GIF window must be kept in ! front of the X-window. ! In this case, close the X-window and reopen it at the end. if (plot_type == 'PS' .or. plot_type == 'GIF') then if (i_chan_hard /= -1 .or. logic_option(.false., no_close)) then call qp_close_page ! Close X-window and will reopen at end i_chan_x = -1 endif if (i_chan_hard == -1) then call str_downcase (extension, plot_type) call get_next_graphic_file_name ('mode', extension, plot_file) if (plot_file == '') then print *, 'PLOTDO: Could not write to the shared disk.' print *, ' Will create a local plot file instead.' plot_file = 'cesrv.' // extension endif if (logic%wide_plot_window) then call qp_open_page (trim(plot_type) // '-L', i_chan_hard, 2*x_win_pix, y_win_pix, 'POINTS', plot_file, 0.0_rp) else call qp_open_page (plot_type, i_chan_hard, x_win_pix, y_win_pix, 'POINTS', plot_file, 0.0_rp) endif else call qp_clear_page endif call qp_save_state (.false.) call qp_get_symbol_attrib (sym_info) sym_info%height = 0.8 * sym_info%height sym_info%type = circle_filled_sym$ call qp_set_symbol (sym_info) call qp_set_line_attrib ('PLOT', width = 1) else call qp_clear_page endif ! Plot... call plot_this ! End stuff if (plot_type == 'PS' .or. plot_type == 'GIF') then call qp_restore_state if (.not. logic_option(.false., no_close)) then call qp_close_page if (plot_type == 'GIF' .and. plot_file /= 'cesrv.gif') then ix = splitfilename (plot_file, dir, file) call to_gif_index (file, .false., lines) endif print *, 'Written: ', trim(plot_file) if (hardcopy_flag) then call system_command ('lpr ' // trim(plot_file)) print *, 'file sent to the printer using the lpr command...' endif i_chan_hard = -1 endif endif ! If closed then reopen the X-window if (i_chan_x == -1) then call qp_open_page ('X', i_chan_x, x_win_pix, y_win_pix, 'POINTS', scale = scale) call qp_set_text_attrib ("GRAPH_TITLE", height = 15.0_rp) call qp_set_text_attrib ("LEGEND", height = 12.0_rp) call plot_this endif !------------------------------------------------------------------------------- !------------------------------------------------------------------------------- contains subroutine plot_this ! if (logic%plot_what == 'PLOT_DATA') then call qp_set_margin (x1_marg, x2_marg, y1_marg, y2_marg, 'POINTS') ! margins call qp_set_page_border (0.0_rp, 0.0_rp, 0.0_rp, 50.0_rp, 'POINTS') else call qp_set_margin (x1_marg, x1_marg, y1_marg, y1_marg, 'POINTS') ! margins call qp_set_page_border (0.0_rp, 0.0_rp, 0.0_rp, 50.0_rp, 'POINTS') endif if (logic%plot_special) then call plot_special (u) elseif (logic%plot_what == 'PLOT_RAW') then call plot_raw (u) else call ring_calc (u) ! recalc the twiss parameters if (logic%plot_what == 'PLOT_WAVE') then call plot_wave(u) elseif (logic%plot_what == 'PLOT_QUAD_K1') then call var_plot ('STANDARD', u%quad_k1, u) elseif (logic%plot_what == 'PLOT_SKEW_QUAD_K1') then call var_plot ('STANDARD', u%skew_quad_k1, u) elseif (logic%plot_what == 'PLOT_SEX_K2') then call var_plot ('STANDARD', u%sex_k2, u) elseif (logic%plot_what == 'PLOT_HSTEER_KICK') then call var_plot ('STANDARD', u%hsteer_kick, u) elseif (logic%plot_what == 'PLOT_HBND_KICK') then call var_plot ('HBND', u%hsteer_kick, u) elseif (logic%plot_what == 'PLOT_VSTEER_KICK') then call var_plot ('STANDARD', u%vsteer_kick, u) elseif (logic%plot_what == 'PLOT_DATA') then if (graph%top1%d2%type /= none_data$) then call setup_data_plot (graph%top1, u) call draw_data_plots (graph%top1, u) endif if (graph%bottom1%d2%type /= none_data$) then call setup_data_plot (graph%bottom1, u) call draw_data_plots (graph%bottom1, u) endif if (logic%wide_plot_window) then if (graph%top2%d2%type /= none_data$) then call setup_data_plot (graph%top2, u) call draw_data_plots (graph%top2, u) endif if (graph%bottom2%d2%type /= none_data$) then call setup_data_plot (graph%bottom2, u) call draw_data_plots (graph%bottom2, u) endif endif endif endif ! call qp_draw_main_title (lines) if (logic%u_num > 1) then write (lines(1), '(a,i2,a,i2)') 'Universe ', logic%u_view, ' of ', logic%u_num call qp_draw_text (lines(1), -200.0_rp, -22.0_rp, 'POINTS/PAGE/RT', height = 10.0_rp) endif end subroutine end subroutine