spec

Software for Diffraction

3.3.3. - Basic Utility Macros



These straightforward macros combine a number of built-in functions and commands to provide a higher level of functionality with minimal input. First, here is their usage:
help [topic]                        # Display help files
config                              # Edit hardware configuration
onsim                               # Turn on simulate mode
offsim                              # Turn off simulate mode
debug [value]                       # Select debugging categories
bug                                 # Mail a bug report
whats object                        # Identify the object

gpset variable value                # Comment if a variable has changed


Here are the definitions for some:
# Examine help file, use default if no argument.
def help  '
      if ($#)
          gethelp("$1");
      else {
          local t
          for (t="help";;)
              if (gethelp(t) || (t = input("\nSubject?  ")) == ")
                  break
      }
'
# View (and modify), then reread configuration file.
# Use -s flag if in simulate mode.  Re-order motor numbers
# with _assign.  Check for monochromator mnemonics.
def config '
      wait(-1)
      user_waitall
      sync
      unix(sprintf("%s/edconf %s %s/%s",\
              SPECD, set_sim(-1)? "-s":", SPECD, SPEC))
      reconfig
      user_config
      _assign
      _assign_mono
'
def user_config ''
# Turn simulate mode on.  Comment on printer and file if changed.
def onsim '{
      local t

      if (!(t = set_sim(1))) { qcomment "Simulate mode ON" }
      printf("Simulate was %s, is now %s.\n", t? "on":"off",\
                                     set_sim(-1)? "ON":"OFF")
}'
# Turn simulate mode off.
def offsim '{
      local t

      if (t = set_sim(0)) { qcomment "Simulate mode OFF" }
      printf("Simulate was %s, is now %s.\n", t? "on":"off",\
                                     set_sim(-1)? "ON":"OFF")
}'
# Easy way to set the debug level.
# +arg adds bits to DEBUG.  -arg removes them.
def debug '{
      local t

      if ($# == 0) {
              gethelp("debug")
              t = input(sprintf("\nDebug value (%d)? ", DEBUG))
      } else
              t = "$*"
      if (index(t, "+"))      DEBUG |= 0+t
      else if (index(t, "-")) DEBUG &= ~(0-t)
      else                    DEBUG  = 0+t
}'
# Send a bug report to the administrator.
def bug '
      print "The mail utility will be run for you.  Describe your"
      print "problem to the administrator.  When you are done, type ^D."
      {
        local s
        s = unix(sprintf("%s -s \"Bug from %s\" %s", MAIL, USER, ADMIN))
        printf("Bug report %ssent to %s.", s? "not ":", ADMIN)
      }
'
# Set something and comment if it has changed.
def gpset '
      if ($1 != $2) {
              comment "$2 reset from %g to %g" "$2,$1"
              $2 = $1
      }
'