6 #--------------------------------------------------------------------------------------
 
    8 #                   Utility script for csh library functions.
 
   10 #--------------------------------------------------------------------------------------
 
   15 setenv     DEBUG 0                    # debug level
 
   17 setenv     TIMER 0                    # timer
 
   19 setenv     DEFAULT_OPTION -           # default option
 
   22 # Wild card for any valid run number to be used as ${ANY_RUN_NUMBER}.
 
   24 setenv ANY_RUN_NUMBER "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"
 
   26 setenv PI                3.14159265359
 
   27 setenv TIMESTAMP         "#splitline{}{#splitline{%d:%m:%y}{  %H:%M}}%F1970-01-01 00:00:00"
 
   33 alias fatal   'echo `date` FATAL   \!* ; exit'
 
   34 alias error   'eval "if ( $DEBUG >= 0 ) then  \\
 
   35  echo `date` ERROR   \!*                      \\
 
   37 alias notice  'eval "if ( $DEBUG >= 1 ) then  \\
 
   38  echo `date` STATUS  \!*                      \\
 
   40 alias status  'eval "if ( $DEBUG >= 2 ) then  \\
 
   41  echo `date` STATUS  \!*                      \\
 
   43 alias warning 'eval "if ( $DEBUG >= 2 ) then  \\
 
   44  echo `date` WARNING \!*                      \\
 
   46 alias debug   'eval "if ( $DEBUG >= 3 ) then  \\
 
   47  echo `date` DEBUG   \!*                      \\
 
   52 # Source including PATH. 
 
   57     "if ( \!:1 =~ */* ) then       \\
 
   62    source `which \!:1` \!:2*  \\
 
   67 # Method to print environment variables.
 
   69 alias print_env 'eval setenv'
 
   73 # Method to check for CC Lyon.
 
   75 # \return         1 for CC Lyon; else 0
 
   77 alias is_CCLyon 'eval                                             \\
 
   78     "if ( $?HOST != 0 && `echo $HOST | cut -c1-2` == cc ) then    \\
 
   85 # Method to define variable.
 
   89 alias define_variable 'eval                   \\
 
   90     "if (${?\!:1} == 0) then                  \\
 
   96 # Method to set variable.
 
   97 # Note that a value equal to $DEFAULT_OPTION will not modify the variable.
 
  100 # \param  2-N     value(s)
 
  102 alias set_variable 'eval                                \\
 
  103     "if ("\"\!:2*\"" != "\"$DEFAULT_OPTION\"") then     \\
 
  104     setenv \!:1 "\"\!:2*\""                             \\
 
  109 # Method to unset variable.
 
  113 alias unset_variable 'eval unsetenv \!:1'
 
  117 # Method to print variables.
 
  119 # \param  1-N     list of variables
 
  121 alias print_variable 'eval                    \\
 
  122     "printf "%-20s\\ =\\ " \!:1               \\
 
  124     if (`echo \!:1* | wc -w` > 1) then        \\
 
  125     print_variable \!:2*                      \\
 
  130 # Method to check validity of variables.
 
  132 # \param  1-N     list of variables
 
  134 alias check_variable 'eval                    \\
 
  135     "if (! ${?\!:1}) then                     \\
 
  136     fatal "Variable \!:1 not defined."        \\
 
  138     if (`echo \!:1* | wc -w` > 1) then        \\
 
  139     check_variable \!:2*                      \\
 
  144 # Method to set array.
 
  146 # \param  1       array name
 
  149 alias set_array 'eval "set \!:1=(\!:2*)"'
 
  153 # Method to count directory in ':' separated path list.
 
  158 alias count_directory 'eval "echo -n ${\!:1} | tr : \\n | grep "^\\\\\!:2\\\$" | wc -w"'
 
  162 # Method to remove directory from ':' separated path list.
 
  167 alias remove_directory 'eval "setenv \!:1 `echo -n ${\!:1} | tr : \\n | grep -v "^\\\\\!:2\\\$" | tr \\n : | sed "s/:\\\$//"`"'
 
  171 # Method to remove variable from ':' separated path list.
 
  176 alias remove_variable 'eval            \\
 
  177     "if (! ${?\!:2}) then              \\
 
  179     remove_directory \!:1 "\${\!:2}"   \\
 
  184 # Method to insert directory into ':' separated path list.
 
  189 alias insert_directory 'eval                                                          \\
 
  190     "if (! ${?\!:1}) then                                                             \\
 
  192     else if (`echo -n ${\!:1} | tr : \\n | grep "^\\\\\!:2\\\$" | wc -w` == 0) then   \\
 
  193     setenv \!:1 \!:2\:${\!:1}                                                         \\
 
  198 # Method to fit Gaussian distribution to histogram.
 
  202         -F "[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2])) + [3]"    \\
 
  203         -@ "p0 = 0.8*GetMaximum - GetMinimum"                 \\
 
  205         -@ "p2 = 0.5*GetRMS"                                  \\
 
  206         -@ "p3 = GetMinimum"'                                 
 
  210 # Method to fit exponential distribution to histogram.
 
  214         -F "[0]*exp(-[1]*x) + [2]"                            \\
 
  215         -@ "p0 = GetMaximum - GetMinimum"                     \\
 
  216         -@ "p1 = 1.0/GetRMS"                                  \\
 
  217         -@ "p2 = GetMinimum"'