esrf

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

#%TITLE% graphical.mac
#%NAME%
#   Patches on some standard macros mostly for plot handling
#
#%CATEGORY% Tools
#
#%END%

#%IU% (a, x, y, range)
#%MDESC% replacement for the "arr__CFWHM" of "plotarray.mac".
# Patches the "plot" macro so the online peak search works with negativ peaks
# and without background subtraction. Used form online display "cplot" and CEN
#%BR%
# Arguments: a= scan data array (normally SCAN_D), x = x column number in
# "a", y = y column number in "a", range = string of format "n:m" which
# denoted the part of array "a" to be used.
# (Friedrich Schotte 30 Sep 98)

def arr__CFWHM (a, x, y, range) '{
  local t n n1 n2 i j
  split(range,t,":")
  n1=t[0]; n2=t[1]; n = n2-n1+1

  if (n<2) return "?"
  if (a[n2][x] == a[n1][x]) return a[n1][x]

  # the function "cfwhm" will only work properly if the base line is at 0.
  # Do a simple background subtraction by a linear interpolation of the two end
  # points
  local array Y[n]
  for (i=0,j=n1;i<n;i++,j++)
  {
    Y[i] = a[j][y] - a[n1][y] + (a[j][x]-a[n1][x]) * (a[n2][y]-a[n1][y])/(a[n2][x]-a[n1][x])
}
  # the function "cfwhm" will find the peak only if it is positive. In case
  # it is a negative make it positive first.
  if (array_op("sum",Y) < 0)
  {
   Y *= -1
  }
  return array_op("cfwhm",a[range][x],Y)
}'

#%IU% (a, x, y, range)
#%MDESC% replacement for the "arr__FWHM" of "plotarray.mac".
# Patches the "plot" macro so the online peak search works with negativ peaks
# and without background subtraction. Used form online display "cplot" and CEN
#%BR%
# Arguments: a= scan data array (normally SCAN_D), x = x column number in
# "a", y = y column number in "a", range = string of format "n:m" which
# denoted the part of array "a" to be used.
# (Friedrich Schotte 30 Sep 98)

def arr__FWHM (a, x, y, range) '{
  local t n n1 n2 i j
  split(range,t,":")
  n1=t[0]; n2=t[1]; n = n2-n1+1

  if (n<2) return "?"
  if (a[n2][x] == a[n1][x]) return 0

  # the function "cfwhm" will only work properly if the base line is at 0.
  # Do a simple background subtraction by a linear interpolation of the two end
  # points
  local array Y[n]
  for (i=0,j=n1;i<n;i++,j++)
    Y[i] = a[j][y] - a[n1][y] + (a[j][x]-a[n1][x]) * (a[n2][y]-a[n1][y])/(a[n2][x]-a[n1][x])

  # the function "fwhm" will find the peak only if it is positive. In case
  # it is a negative make it positive first.
  if (array_op("sum",Y) < 0) Y *= -1

  return array_op("fwhm",a[range][x],Y)
}'

#%IU% (a, x, y, range)
#%MDESC% replacement for the "arr__CFWHM" of "plotarray.mac".
# Patches the "plot" macro so the online peak search works with negativ peaks
# and without background subtraction. Used form online display "cplot" and CEN
#%BR%
# Arguments: a= scan data array (normally SCAN_D), x = x column number in
# "a", y = y column number in "a", range = string of format "n:m" which
# denoted the part of array "a" to be used.
# (Friedrich Schotte 30 Sep 98)

double array a_Y[4096]

def arr__COM (a, x, y, range) '{
  local t n n1 n2 i j
  split(range,t,":")
  n1=t[0]; n2=t[1]; n = n2-n1+1

  if (n<2) return "?"
  if (a[n2][x] == a[n1][x]) return a[n1][x]

  # the function "com" will only work properly if the base line is at 0.
  # Do a simple background subtraction by a linear interpolation of the two end
  # points
  for (i=0,j=n1;i<n;i++,j++) {
    a_Y[i] = a[j][y] - a[n1][y] + (a[j][x]-a[n1][x]) * (a[n2][y]-a[n1][y])/(a[n2][x]-a[n1][x])
  }

  return array_op("com",a[range][x],a_Y[range])
}'

#%UU% Muliply the currently plotted data of the last scan by -1. %BR%
# (Friedrich Schotte 30 Sep 98)

def invert '{
  local i n
  for (i=0; i<PLOT_NUM; i++)
  {
    n = cnt_num(PLOT_SEL[i])
    if (n != -1) SCAN_D[][n + PLOT_MOTS]*=-1
  }
  plot; # redraw plot window
}'

#%UU% Differentiate currently plotted data %BR%
# (Friedrich Schotte)
def diff '{
    local i j n
    local array diff_d[NPTS]


    double array DIFF_DATA[NPTS][PLOT_NUM]
    local DIFF_SIGN

    #???
    DIFF_SIGN = 1

    if ($#==1) {
        if ($1<0) { DIFF_SIGN= -1 }
    }

    for (i=0; i<PLOT_NUM; i++) {
        n = cnt_num(PLOT_SEL[i])
        if (n != -1) {
            if (NPTS>=2) {
                diff_d[0] =                                             \
                (SCAN_D[1][n + PLOT_MOTS] - SCAN_D[0][n + PLOT_MOTS]) / (SCAN_D[1][0] - SCAN_D[0][0])
            }

            for (j=1; j<NPTS-1; j++) {
                diff_d[j] =                                             \
                (SCAN_D[j+1][n + PLOT_MOTS] - SCAN_D[j-1][n + PLOT_MOTS]) / (SCAN_D[j+1][0] - SCAN_D[j-1][0])
            }

            if (NPTS>=2) {
                diff_d[NPTS-1] =                                        \
                (SCAN_D[NPTS-1][n + PLOT_MOTS] - SCAN_D[NPTS-2][n + PLOT_MOTS]) / (SCAN_D[NPTS-1][0] - SCAN_D[NPTS-2][0])
            }

            for (j=0; j<NPTS; j++) {
             	DIFF_DATA[j][i] = SCAN_D[j][n + PLOT_MOTS]
                SCAN_D[j][n + PLOT_MOTS] = DIFF_SIGN * diff_d[j]
            }
        }
    }
    plot; # redraw plot window
}'

# ???
def undiff '{
    local i j n

    for (i=0; i<PLOT_NUM; i++) {
        n = cnt_num(PLOT_SEL[i])
        if (n != -1) {
            for (j=0; j<NPTS; j++) {
                SCAN_D[j][n + PLOT_MOTS] = DIFF_DATA[j][i]
            }
        }
    }
    plot;

}'

#%MACROS%
#%IMACROS%
#%TOC%