Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
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 detector identifier or run number; to be used as ${ANY}.
23 
24 setenv ANY_ID "[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 locally set variable.
110 # Note that a value equal to $DEFAULT_OPTION will not modify the variable.
111 #
112 # \param 1 variable
113 # \param 2-N value(s)
114 #
115 alias set_local_variable 'eval \\
116  "if ("\"\!:2*\"" != "\"$DEFAULT_OPTION\"") then \\
117  set \!:1 "\"\!:2*\"" \\
118  endif"'
119 
120 
121 #
122 # Method to unset variable.
123 #
124 # \param 1 variable
125 #
126 alias unset_variable 'eval unsetenv \!:1'
127 
128 
129 #
130 # Method to print variables.
131 #
132 # \param 1-N list of variables
133 #
134 alias print_variable 'eval \\
135  "printf "%-20s\\ =\\ " \!:1 \\
136  echo "${\!:1}" \\
137  if (`echo \!:1* | wc -w` > 1) then \\
138  print_variable \!:2* \\
139  endif"'
140 
141 
142 #
143 # Method to check validity of variables.
144 #
145 # \param 1-N list of variables
146 #
147 alias check_variable 'eval \\
148  "if (! ${?\!:1}) then \\
149  fatal "Variable \!:1 not defined." \\
150  endif \\
151  if (`echo \!:1* | wc -w` > 1) then \\
152  check_variable \!:2* \\
153  endif"'
154 
155 
156 #
157 # Method to set array.
158 #
159 # \param 1 array name
160 # \param 2-N values
161 #
162 alias set_array 'eval "set \!:1=(\!:2*)"'
163 
164 
165 #
166 # Method to count directory in ':' separated path list.
167 #
168 # \param 1 path list
169 # \param 2 directory
170 #
171 alias count_directory 'eval "echo -n ${\!:1} | tr : \\n | grep "^\!:2\$" | wc -w"'
172 
173 
174 #
175 # Method to remove directory from ':' separated path list.
176 #
177 # \param 1 path list
178 # \param 2 directory
179 #
180 alias remove_directory 'eval "setenv \!:1 `echo -n ${\!:1} | tr : \\n | grep -v "^\!:2\$" | tr \\n : | sed "s/:\\\$//"`"'
181 
182 
183 #
184 # Method to remove variable from ':' separated path list.
185 #
186 # \param 1 path list
187 # \param 2 variable
188 #
189 alias remove_variable 'eval \\
190  "if (! ${?\!:2}) then \\
191  else \\
192  remove_directory \!:1 "\${\!:2}" \\
193  endif"'
194 
195 
196 #
197 # Method to insert directory into ':' separated path list.
198 #
199 # \param 1 path list
200 # \param 2 directory
201 #
202 alias insert_directory 'eval \\
203  "if (! ${?\!:1}) then \\
204  setenv \!:1 \!:2 \\
205  else if (`echo -n ${\!:1} | tr : \\n | grep "^\!:2\$" | wc -w` == 0) then \\
206  setenv \!:1 \!:2\:${\!:1} \\
207  endif"'