Jpp
ulib.csh
Go to the documentation of this file.
1 #!/bin/csh
2 #
3 #
4 # \author mdejong
5 #
6 #--------------------------------------------------------------------------------------
7 #
8 # Utility script for csh library functions.
9 #
10 #--------------------------------------------------------------------------------------
11 
12 setenv version 1.0
13 
14 
15 setenv DEBUG 0 # debug level
16 
17 setenv TIMER 0 # timer
18 
19 setenv DEFAULT_OPTION - # default option
20 
21 
22 # Wild card for any valid run number to be used as ${ANY_RUN_NUMBER}.
23 
24 setenv ANY_RUN_NUMBER "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"
25 
26 setenv PI 3.14159265359
27 setenv TIMESTAMP "#splitline{}{#splitline{%d:%m:%y}{ %H:%M}}%F1970-01-01 00:00:00"
28 
29 
30 #
31 # debug messages
32 #
33 alias fatal 'echo `date` FATAL \!* ; exit'
34 alias error 'eval "if ( $DEBUG >= 0 ) then \\
35  echo `date` ERROR \!* \\
36  endif"'
37 alias notice 'eval "if ( $DEBUG >= 1 ) then \\
38  echo `date` STATUS \!* \\
39  endif"'
40 alias status 'eval "if ( $DEBUG >= 2 ) then \\
41  echo `date` STATUS \!* \\
42  endif"'
43 alias warning 'eval "if ( $DEBUG >= 2 ) then \\
44  echo `date` WARNING \!* \\
45  endif"'
46 alias debug 'eval "if ( $DEBUG >= 3 ) then \\
47  echo `date` DEBUG \!* \\
48  endif"'
49 
50 
51 #
52 # Source including PATH.
53 #
54 # \param 1 name
55 #
56 alias source 'eval \\
57  "if ( \!:1 =~ */* ) then \\
58  unalias source \\
59  source \!:1 \!:2* \\
60  else \\
61  unalias source \\
62  source `which \!:1` \!:2* \\
63  endif"'
64 
65 
66 #
67 # Method to print environment variables.
68 #
69 alias print_env 'eval setenv'
70 
71 
72 #
73 # Method to check for CC Lyon.
74 #
75 # \return 1 for CC Lyon; else 0
76 #
77 alias is_CCLyon 'eval \\
78  "if ( $?HOST != 0 && `echo $HOST | cut -c1-2` == cc ) then \\
79  echo 1 \\
80  else \\
81  echo 0 \\
82  endif"'
83 
84 #
85 # Method to define variable.
86 #
87 # \param 1 variable
88 #
89 alias define_variable 'eval \\
90  "if (${?\!:1} == 0) then \\
91  setenv \!:1 \\
92  endif"'
93 
94 
95 #
96 # Method to set variable.
97 # Note that a value equal to $DEFAULT_OPTION will not modify the variable.
98 #
99 # \param 1 variable
100 # \param 2-N value(s)
101 #
102 alias set_variable 'eval \\
103  "if ("\"\!:2*\"" != "\"$DEFAULT_OPTION\"") then \\
104  setenv \!:1 "\"\!:2*\"" \\
105  endif"'
106 
107 
108 #
109 # Method to unset variable.
110 #
111 # \param 1 variable
112 #
113 alias unset_variable 'eval unsetenv \!:1'
114 
115 
116 #
117 # Method to print variables.
118 #
119 # \param 1-N list of variables
120 #
121 alias print_variable 'eval \\
122  "printf "%-20s\\ =\\ " \!:1 \\
123  echo "${\!:1}" \\
124  if (`echo \!:1* | wc -w` > 1) then \\
125  print_variable \!:2* \\
126  endif"'
127 
128 
129 #
130 # Method to check validity of variables.
131 #
132 # \param 1-N list of variables
133 #
134 alias check_variable 'eval \\
135  "if (! ${?\!:1}) then \\
136  fatal "Variable \!:1 not defined." \\
137  endif \\
138  if (`echo \!:1* | wc -w` > 1) then \\
139  check_variable \!:2* \\
140  endif"'
141 
142 
143 #
144 # Method to set array.
145 #
146 # \param 1 array name
147 # \param 2-N values
148 #
149 alias set_array 'eval "set \!:1=(\!:2*)"'
150 
151 
152 #
153 # Method to count directory in ':' separated path list.
154 #
155 # \param 1 path list
156 # \param 2 directory
157 #
158 alias count_directory 'eval "echo -n ${\!:1} | tr : \\n | grep "^\\\\\!:2\\\$" | wc -w"'
159 
160 
161 #
162 # Method to remove directory from ':' separated path list.
163 #
164 # \param 1 path list
165 # \param 2 directory
166 #
167 alias remove_directory 'eval "setenv \!:1 `echo -n ${\!:1} | tr : \\n | grep -v "^\\\\\!:2\\\$" | tr \\n : | sed "s/:\\\$//"`"'
168 
169 
170 #
171 # Method to remove variable from ':' separated path list.
172 #
173 # \param 1 path list
174 # \param 2 variable
175 #
176 alias remove_variable 'eval \\
177  "if (! ${?\!:2}) then \\
178  else \\
179  remove_directory \!:1 "\${\!:2}" \\
180  endif"'
181 
182 
183 #
184 # Method to insert directory into ':' separated path list.
185 #
186 # \param 1 path list
187 # \param 2 directory
188 #
189 alias insert_directory 'eval \\
190  "if (! ${?\!:1}) then \\
191  setenv \!:1 \!:2 \\
192  else if (`echo -n ${\!:1} | tr : \\n | grep "^\\\\\!:2\\\$" | wc -w` == 0) then \\
193  setenv \!:1 \!:2\:${\!:1} \\
194  endif"'
195 
196 
197 #
198 # Method to fit Gaussian distribution to histogram.
199 #
200 alias gauss '\\
201  JFit \\
202  -F "[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2])) + [3]" \\
203  -@ "p0 = 0.8*GetMaximum - GetMinimum" \\
204  -@ "p1 = GetMean" \\
205  -@ "p2 = 0.5*GetRMS" \\
206  -@ "p3 = GetMinimum"'
207 
208 
209 #
210 # Method to fit exponential distribution to histogram.
211 #
212 alias exponent '\\
213  JFit \\
214  -F "[0]*exp(-[1]*x) + [2]" \\
215  -@ "p0 = GetMaximum - GetMinimum" \\
216  -@ "p1 = 1.0/GetRMS" \\
217  -@ "p2 = GetMinimum"'