6#--------------------------------------------------------------------------------------
8# Utility script for csh library functions.
10#--------------------------------------------------------------------------------------
15setenv DEBUG 0 # debug level
19setenv DEFAULT_OPTION - # default option
22# Wild card for any valid detector identifier or run number; to be used as ${ANY}.
24setenv ANY_ID "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"
26setenv PI 3.14159265359
27setenv TIMESTAMP "#splitline{}{#splitline{%d-%m-%y}{ %H:%M}}%F1970-01-01 00:00:00"
33alias fatal 'echo `date` FATAL \!* ; exit'
34alias error 'eval "if ( $DEBUG >= 0 ) then \\
35 echo `date` ERROR \!* \\
37alias notice 'eval "if ( $DEBUG >= 1 ) then \\
38 echo `date` STATUS \!* \\
40alias status 'eval "if ( $DEBUG >= 2 ) then \\
41 echo `date` STATUS \!* \\
43alias warning 'eval "if ( $DEBUG >= 2 ) then \\
44 echo `date` WARNING \!* \\
46alias 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.
69alias print_env 'eval setenv'
73# Method to check for CC Lyon.
75# \return 1 for CC Lyon; else 0
77alias is_CCLyon 'eval \\
78 "if ( $?HOST != 0 && `echo $HOST | cut -c1-2` == cc ) then \\
85# Method to define variable.
89alias 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.
102alias set_variable 'eval \\
103 "if ("\"\!:2*\"" != "\"$DEFAULT_OPTION\"") then \\
104 setenv \!:1 "\"\!:2*\"" \\
109# Method to locally set variable.
110# Note that a value equal to $DEFAULT_OPTION will not modify the variable.
115alias set_local_variable 'eval \\
116 "if ("\"\!:2*\"" != "\"$DEFAULT_OPTION\"") then \\
117 set \!:1 "\"\!:2*\"" \\
122# Method to unset variable.
126alias unset_variable 'eval unsetenv \!:1'
130# Method to print variables.
132# \param 1-N list of variables
134alias print_variable 'eval \\
135 "printf "%-20s\\ =\\ " \!:1 \\
137 if (`echo \!:1* | wc -w` > 1) then \\
138 print_variable \!:2* \\
143# Method to check validity of variables.
145# \param 1-N list of variables
147alias check_variable 'eval \\
148 "if (! ${?\!:1}) then \\
149 fatal "Variable \!:1 not defined." \\
151 if (`echo \!:1* | wc -w` > 1) then \\
152 check_variable \!:2* \\
157# Method to set array.
162alias set_array 'eval "set \!:1=(\!:2*)"'
166# Method to count directory in ':' separated path list.
171alias count_directory 'eval "echo -n ${\!:1} | tr : \\n | grep "^\!:2\$" | wc -w"'
175# Method to remove directory from ':' separated path list.
180alias remove_directory 'eval "setenv \!:1 `echo -n ${\!:1} | tr : \\n | grep -v "^\!:2\$" | tr \\n : | sed "s/:\\\$//"`"'
184# Method to remove variable from ':' separated path list.
189alias remove_variable 'eval \\
190 "if (! ${?\!:2}) then \\
192 remove_directory \!:1 "\${\!:2}" \\
197# Method to insert directory into ':' separated path list.
202alias insert_directory 'eval \\
203 "if (! ${?\!:1}) then \\
205 else if (`echo -n ${\!:1} | tr : \\n | grep "^\!:2\$" | wc -w` == 0) then \\
206 setenv \!:1 \!:2\:${\!:1} \\