Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

See other macros in category: Obsolete
    Macros to work with cplot from within spec (using data groups) OBSOLETE Use cplotarray instead
    Plotting and printing in spec have some limitations which can be easily overcome by using the external program cplot. To let users with no knowledge in cplot use some of the common features of cplot this macro package has been written.
    For further functionality users are encouraged to use the cplot package directly. (Or their favourite plotting/graphics package).
    The macros in this package also provide a easy way to make special plots %{%(<a HREF=cplot.gif>example</a>)%}%. You can plot different plots on one page, mix 3D with one dimensional cuts, plot mca or thermocouple information and much more.

    Basic plots can be done with one or two commands.
    to set up the parameters (like titles..) for the plot
    to plot a graph from a datafile or the last scan done on the screen.
    to print a graph from a datafile or the last scan done on the printer
    to make a 3D or contour plot from a data file.
    If you call the macros mentioned above, a plot will be generated in each case. Macros in this section will only plot immediatly if you did not open the plot before with cp_opengraph.
    Opens a graph
    Closes the graph and makes the plot
    cp_windows 2 3:
    Sets the page up with 2 plots in x and 3 plots in y direction.
    goes to the next plot
    plots the data from a certain group
    plots the data from a file
    plots the data for selected counters
    plots a contour plot from data in file
    plots a 3D plot from the data in file
    The plot will go either to the printer or to the screen. You can select this by typing:
    • cp_setprinter
    • cp_setx11
    before the plot. The selected output device will stay active until you change it.
    and may be less important:
    goes to a new page
    puts a global title on the page
    puts title , x-label and y-label on an individual plot. This is done normally by the macros above.

    pplot (plots the current scan on the printer)
    pplot 12

    • cplot must be installed for you, that means:
      • setenv CPLOTHOME xxxx where xxxx is the home directory of cplot (normally something like ${BLISSADM}/spec/${BLOS}/cplot)
      • The cplot binary directory (${BLISSADM}/spec/${BLOS}/cplot/bin) must be in your path.
    • Your printer must be set up correctly
    • A cp_defaults macro has to be written - see ATTENTION

    First time I try to use variables and constant strings with one macro. If you want to give a string variable just enclose it in double brackets like usual. If you want to give a variable use single quotes double quotes '"testvar"'. You have to escape the single quotes in a macro definition \'"testvar"\'

    A macro has to be written to set the default values. This is an example of an cp_defaults file (should be in idxxspecial.mac) This example is included in the macro set. It can be copied and modified. The name has to be changed to cp_defaults.

    The file cplot.mac has to be read in !done by: startup script

    Usage: cpsetup
    Produces a menu with many options. Because of the number of options the menu is subdivided into groups of questions or flags - each marked with a number. You will see a page like this:
               ************** CPLOT OPTION MENU ******************
    01  Draw Lines YES 02 Draw Points YES 03  Error Bars NO  04       Log Y NO  
    05       Log X NO  06    Plot Key YES 07   Plot FWHM NO  08 Plot Commen NO  
    09 X Auto Scal YES 10 Y Auto Scal YES 11     Rescale YES 12    Portrait YES 
    13        Date YES 14  Page Title NO  15     Page No NO  16   File Name NO  
    17   Scan File NO  18   Over plot YES 
    19 FILE Name: datos Dir: /users/d/klora/working/cplot 
    20 DEFAULT Col X: 1 Col Y: -1 Col Z: 2 Scan No: -1 
    21 PRINTER Name: a4dc102 
    22 WINDOWS X: 2 Y: 2 
    23 MANUAL SCALE XMin: 0 XMax: 1 YMin: 0 YMax: 1 
    24 PAPERSIZE Long: 25.75 Short: 19.125 
    25 PAGE MARGIN Left: 0 Right: 0 Top: 0.1 Bottom: 0.1 
    26 PLOT MARGIN Left: 0.19 Right: 0.1 Top: 0.1 Bottom: 0.1 
    27 GLOBAL Title: Global title 
    28 COMMENT Comment: \CAND AN ADDITIONAL COMMENT Com Margin: 0.2 
    29 3D Contour Lines: 30 Viewpoint X: 1.3 Y: -2.4 Z: 2 
    30 CHAR SIZE Title: 5 Label: 4.5 Key: 4.5 Date: 3 
    31 SYMBOLS Point Code: 1 Point Size: 4 Point Grow Factor: 0 Line Code: 0 
    32 PLOT Title: A very long plottitle XLabel: X YLabel: Y XUnit:  YUnits:  
      Draw Lines: Connect the points with lines 
      Draw Points: Draw points at each data point
      Error Bars: Draw error bars (sqrt(data)) - not implemented yet
      Log Y: Use log y-axis. If the data contains 0 or negative numbers
         a linear axis will be used without error message.
      Log X: Same as for Y
      Plot Key: A key which indicates which curve corresponds to which symbol
         is plotted for each plot.
      Plot FWHM: Information like FWHM, Center of Mass, Peak position ,...
         is plotted below each plot. his is only done for the last curve
         plotted for the moment.
      Plot Comment: An additional comment is printed below each plot.
      X-Auto Scale: The X axis is scaled automatically. If you want to use
         a manual scale this option AND THE RESCALE OPTION has to be switched
         off and the manual scale entered.
      Y-Auto Scale: Same as X
      Rescale: Each curve in the plot is rescaled individually. For the
         second curve an extra axis will be plotted on the right hand side.
      Portrait: Changes the paper orientation
      Date: Put the date on each page
      Page Title: Put a global title on each page (set with global title)
      Page No: Put the page number on each page
      File Name: Put the file name on each page
      Scan File: Use always the spec DATAFILE and DATA_DIR and not the
         values from this menu
      Over plot: Plots the selected scans from a file in one graph
      FILE NAME and DIR: Filename of the files containing the scans
      DEFAULT: Default scan number, x, y, and z column if no input is provided
      PRINTER: The name of your printer
      WINDOWS: The number of plots on one page in x and y direction
      MANUAL: The manual scale if automatic scaling and resize is switched off
      PAPERSIZE: The size of a DINA4 page
      PAGE MARGIN: The margins on each page, Values go from 0 to 1
      PLOT MARGIN: Margins for each plot on one page. Values go from 0 to 1
      GLOBAL: The global title (Header on the page(s))
      COMMENT: A comment and the extra margin below the plot. If the 
         comment text starts with \C the following text will be centered.
      3D : Number of contour lines and view point for 3D plots
      CHAR SIZE: Font size of Title, labels, keys and the date
      SYMBOLS: Symbol for points (from 0 to 28, where 9 is a very small dot)
         Size of these symbols, A number which specifies how much a point
         should shrink if there are more plots on a page. 0 means shrink
         like everything else (labels for example) 1 means do not shrink
         at all. Values in between are allowed. Line Symbol from 0 to 6
         where 0 is a simple line.
      PLOT : The title and labels will be normally set to something
         meaningful. The units given here will be put on the plots.

    Usage: cp_opengraph
    Opens a new graph. This command will create a new temporary file to put the cplot commands in and inits a couple of variables. This macro is called from almost all the plot commands if the user did not type in cp_opengraph explicitely before.

    Usage: cp_newpage
    Closes the current page and opens a new one (with cp_startpage)

    Usage: cp_closegraph
    Closes the graph. This includes calling cplot to execute the script which has been written so far.

    Usage: cp_title [title string]
    Will put a title command into the script. If no input is given the title is taken from CP_PAR["TITLE"]

    Usage: cp_plottitle ["title"] ["xlabel"] ["ylabel"] ["xunits"] ["yunits"]
    Puts a individual plot title and axis information into the script file. If a parameter is not given it will take it from CP_PAR["PTITLE"] (or PXLABEL PYLABEL PXUNITS PYUNITS). The y-label length willbe cut to CP_PAR["YLABELLEN"] characters.

    Usage: cp_windows [no of columns] [no of lines]
    Will define the general page layout with <no of columns> number of plots in x direction and <no of lines> number of plots in y direction. If a parameter is not given it is taken from CP_PAR["COLS"] or CP_PAR["LINES"]. The CP_VAR["WID"] (for window id) is set to -1, the number of plots per page will be taken as CP_PAR["LINES"]*CP_PAR["COLS"] later. You can create your own special layout by assigning the border information to CP_WINDOW[uu] in the format:
    sprintf ("%f %f %f %f",1-y2,x1,1-y1,x2) for portrait and sprintf ("%f %f %f %f",x1,y1,x2,y2) for landscape. The number are relative positions between 0 and 1.

    Usage: cp_advance
    Advances one plot. If you do not enter this command all the plots will be plotted into the same graph.

    Usage: cp_mplot [group] [x-column] [y-column-list] [plot-title] [x-label] [y-label]
    This macro plots data from a specified group. The default values for group x and y are 0 0 1. The default values for the title, x and y labels are taken from CP_PAR["PTITLE"] , "PXLABEL", "PYLABEL". The graph is opened and closed if it is not already open.

    Usage: cp_fplot [scanno-list] [x-col] [y-col-list] [title] [x-label] [y-label]
    Plots data from a file. The default values for scanno-list, x-col, and y-col-list are taken from CP_PAR["SCANNO"]. The default title is "SCAN <SCANNO>: <SCANTITLE>". The default x-label is taken from the file column header. The y-label is contructed from all the file column headers if there is only one label. The keys are taken in any case from the file column headers. The graph is opened and closed if it is not already open. The plotwindow is advanced after each scan.

    Usage: cp_cplot <counter> <counter> <counter>
    Plot slected counters. (assumes PLOT2.MAC is used). The counter values are saved in PL_G2 ( format: motor counter0==sec counter1==mon ....)

    Usage: cp_3d [scanno-list] [x-col] [y-col] [z-col] [title] [xlabel] [ylabel]
    Calls cp_contour to make a 3D plot

    Usage: cp_cont [scanno-list] [x-col] [y-col] [z-col] [title] [xlabel] [ylabel]
    Calls cp_contour to make a contour plot

    Usage: cp_contour [scanno-list] [x-col] [y-col] [z-col] [title] [xlabel] [ylabel]
    Plot a contour plot or a 3D plot (can be selected with ["CP_FLAGS"]) of the selected scans. The default values for [scanno-list] [x-col] [y-col] [z-col] are taken from CP_PAR["SCANNO"], "XCOLUMN", "YCOLUMN", "ZCOLUMN". Title, x and y labels are constructed as in cp_fplot. Open the graph if not already open.

    Usage: cp_setprinter
    sets the filter to print on the printer

    Usage: cp_setx11
    sets the filter to print on the screen

    Usage: cplot <scan-list> [xcolumn] [ycolumn-list] or [detector-mnemonic] [detector-mnemonic] ...
    The first form of the command with the parameters command will plot for the scans given in scan-list the columns given in ycolumn-list against the column given as xcolumn. Default values for xcolumn is 1, for ycolumn-list the detector column. A list consists of comma separated numbers, mnemonics or regions. A region is two numbers or mnemonics (start and end) separated with a minus sign (-). Negative numbers are counted from the highest possible number, where -1 represents the last scan or the last column. No spaces are allowed (e.g. cplot -1--2,3,4-5 : plots from the last scan to the one before the last plus the third plus the fourth to the fifth scan, so in total 5 scans).
    The second form with the parameters [detector-mnemonic] [detector-mnemonic] plots for the last scan the given counters. If no argument is given the counters selected with plotselect are plotted.

    Usage: plot3d <scan-list> [xcolumn] [ycolumn] [z-column]
    This command will print the 3D representation of z-column against x and y.

Internal Macros:
    Usage: cp_defaults

    Usage: example_cp_defaults

    Usage: cp_menu
    Display once the menu and asks the user

    Usage: cp_pflags <Flag explanation string> <Flag>
    Displays the flag explanation string with the flag status (Bit is given, Variable CP_PAR["FLAGS"] is used) and saves this information for later reference in optarr and optflag (1 for flags)

    Usage: cp_ppars <title> [<par expl.> <par name> [<par expl.> <par name>] ...
    Displays the title and expl. string for each parameter. A parameter is defined as CP_PAR["<parameter name>"]. The information is stored for later reference.

    Usage: cp_askpar
    Asks the user to enter a reference number and displays the questions stored with cp_ppars or toggles the flag

    Usage: cp_startpage
    Opens only a new page and puts the title on the page

    Usage: cp_ongraph
    Command will send all the output of the following print commands to the cplot scriptfile.

    Usage: cp_offgraph
    This command will switch the output back to the terminal

    Usage: cp_ondata
    This command will send all the following output to the script file for the current plot. As scaling commands will have to be given before the actual data (to plot 2 or more curves in the same plot) another file then the graph file is used for this purpose.

    Usage: cp_offdata
    Switches the output back to the terminal

    Usage: cp_restext
    Puts the calculated result (FWHM ..) and a comment from CP_PAR["COMMENT"] in the script.

    Usage: cp_indmarg
    Calculates the window size, depending on CP_PAR["PLMARG"], ..PRMARG, PBMARG, PTMARG and puts it into the script file.

    Usage: cp_text <text string>
    Puts a text string below a plot.

    Usage: cp_fonts
    Sets the font size for title, labels, keys, date, text and symbols from global parameters.

    Usage: cp_data group x y [point symbol] [point size] [line symbol]
    Puts the data points and some scaling and axis information in the cplot data script. If the three last parameters are not given they will be taken from: CP_PAR["PSYMBOL"], CP_PAR["PSIZE"], CP_PAR["LSYMBOL"], If the option <Resize every plot> is set, the y-label must be known here. Depending if the label to be drawn is on the left or on the right hand side CP_PAR["KEYT1"] or CP_PAR["KEYT2"] will be used.

    Usage: cp_plotdata
    The script written to the data file will be inserted with some scale information into the cplot graph script.

    Usage: cp_key
    If the option <Key> is set, this macro will insert the CP_PAR["NOKEYS"] # keys with symbols CP_PAR["KEYxx"] and text CP_PAR["KEYTxx"]

    Usage: cp_getfileinfo [filename]
    Gets information about the scans in a file. If filename is not given CP_PAR["FILENAME"] will be used. The following global variables contain the information:
    CP_SCANNO real scanno, CP_SCANTITLE = "ascan ddsd sds d", CP_SCANAXIS columns separated with two blanks split(SC_SCANAXIS[uu],tt," "), CP_SCANINFO No of scans

    Usage: cp_getfiledata_awk [Scan-no] [column-list] [filename]
    Reads the specified columns from scan <Scan-no> and puts them into group CP_FILEGRP. CP_VAR["PTSINFILE"] will contain the number of points read and CP_VAR["COLSINFILE"] the number of columns. The default values are taken from CP_PAR["SCANNO"] and CP_PAR[FILENAME"] If CP_PAR["USESCANS"] is set the program scans is used and not awk if the number of columns is less than 4.

    Usage: cp_getfiledata

    Usage: cp_updatefilename
    Used internally. Will update CP_PAR["FILENAME"] from spec's DATAFILE or value given by the user.

    Usage: cp_ftitle [title] [x-label] [y-label]
    Used in cp_fplot to create and plot the title and the labels.

    Usage: cp_memdefaults <no-of-pars> <group> <x> <y-list> <title> <xlabel> <ylabel>
    Used in cp_mplot to get defaults

    Usage: cp_filedefaults <n--of-pars> <scanno-list> <x-col> <ycol-list> <title> <xlabel> <ylabel>
    Used in cp_fplot to get defaults

    Usage: cp_analpars <list>
    <list> is parsed to get a list of selected elements. CP_MAXSEL must be the highest possible number for an element. This is used to interpret -1. <list> can be given as single number, region (a-b), negative number (from the end) and comma separated lists of this Example: -5--1,2,4-6 The result is returned in the global array CP_SELECTED. The number of selected elements is in CP_SELNO. Split behaves strange (1--1 is splited in |1|-1|)

    Usage: cp_analparsmne

    Usage: cp_replacemnes

    Usage: cp_replace_test

    Usage: cp_contourdata [scanno-list] [x-col] [y-col] [z-col] [title] [xlabel] [ylabel]
    Plot a contour plot or a 3D plot (can be selected with ["CP_FLAGS"]) of the selected scans. The default values for [scanno-list] [x-col] [y-col] [z-col] are taken from CP_PAR["SCANNO"], "XCOLUMN", "YCOLUMN", "ZCOLUMN". Title, x and y labels are constructed as in cp_fplot. Open the graph if not already open.

    Usage: cp_contourdefaults <no of pars> <scan-list> <x-col> <y-col> <z-col>
    used in cp_contour to get default values for contour or 3D plots.

    Usage: cp_fconttitle <no-of-pars> <title> <x-label> <y-label>
    used in cp_contour to plot title and labels.

    Usage: pplot

    Usage: cp_guessplot <input parameters from pplot or cplot>
    tries to guess (from the first parameter) if user wants to plot from memory or from a file and calls cp_mplot or cp_fplot

    Usage: cp_contr

    Usage: cp_plot3d

    Usage: pplot3d

    Usage: contour

    Usage: pcontour

    Usage: cplot_test

    Usage: cplot_test2

    Usage: cplot_test3

    Usage: cp_test4

Filename: cplot.mac
Author: Jorg Klora , 3.94 Version: 0.600
Last mod.: 27/02/2008 14:43 by rey