/[CCFs]/bin/mlovccf
ViewVC logotype

Contents of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations)
Mon Sep 19 12:36:15 2016 UTC (8 years, 2 months ago) by ccflib
Branch: MAIN
Changes since 1.15: +3 -3 lines
changed email address from esa.int to sciops.esa.int

1 #! /bin/bash
2
3 # mlovccf (make list of valid ccfs)
4 #
5 # Makes the list of valid CCFs. These are all CCFs, among those published since the
6 # beginning of the project, that are required to process any ODF at a given date,
7 # typically the current date. This list will change with time as far as new
8 # CCFs are issued to deal with new calibration data and/or replace obsolete ones.
9 #
10 # To identify the set of CCFs required to process a given ODF is the job of task cifbuild.
11 # To make such identification, cifbuild needs only the start time of the observation.
12 # Therefore, if we provide a list of all observed ODFs at a given date together with their
13 # respective start time, we could compute all the CCFs required to process them.
14 # For such a moment, that list is the list of valid CCFs required to process
15 # any observed ODF.
16 #
17 # We need as input the list of all observed ODFs at a given date.
18 # This is obtained from the report of all observations that the XSA makes to CDS,
19 # xsaobslog.txt (http://nxsa.esac.esa.int/ftp_public/cfs_obslog/xsaobslog.txt).
20 #
21 # $Id: mlovccf,v 1.15 2016/04/13 10:26:13 ccflib Exp $
22
23 # Next two lines allow to submit this script to the grid
24 # request Bourne shell as shell for job
25 #$ -S /bin/bash
26
27 adminmail="eduardo.ojero@sciops.esa.int"
28
29 VALID_CCF="$HOME/valid_ccf"
30
31 mailfile="${VALID_CCF}/mailfile"
32
33 host=`hostname | cut -d. -f1`
34
35 now=`date +'%Y%m%d_%H%M'`
36 now_table=`date +'%Y-%m-%dT%H:%M:%S'`
37
38
39 # +++ Function mailnotify
40 #
41 # This function is used to notify adminmail on any issue while runnning this procedure
42 #
43 # Needs a subject as $1 and body as local file to be send.
44
45 mailnotify ()
46 {
47
48 [ "$#" -ne "2" ] && return
49
50 subject=$1
51
52 bodyfile=$2
53
54 [ ! -f "${bodyfile}" ] && return
55
56 echo ; echo "Sending message to ${adminmail} with subject ${subject}" ; echo
57
58 mailx -v -s "${subject}" "${adminmail}" < ${bodyfile}
59
60 }
61
62
63
64 # +++ Function getxsaobslog
65 #
66 # We need to get the list of all observed ODFs at the current date.
67 # This is obtained from http://nxsa.esac.esa.int/ftp_public/cds_obslog/xsaobslog.txt.
68
69 getxsaobslog ()
70 {
71
72 XSAOBSURL="http://nxsa.esac.esa.int/ftp_public/cds_obslog/xsaobslog.txt"
73
74 # Remove any xsaobslog.txt previously downloaded.
75
76 [ -f "${VALID_CCF}/xsaobslog.txt" ] && rm -rf ${VALID_CCF}/xsaobslog.txt
77
78 # Get the list latest list of ODFs available from nXSA server.
79
80 wget -q ${XSAOBSURL} -O ${VALID_CCF}/xsaobslog.txt
81
82 # Rename xsaobslog.txt to xsaobslog_${now}.txt just to have a reference
83 # of which list of ODFs was used to compute the list of valid CCFs.
84
85 mv ${VALID_CCF}/xsaobslog.txt ${VALID_CCF}/xsaobslog_${now}.txt
86
87 }
88
89
90
91 # +++ Function find_latest_mif to get the latest XMM_CALINDEX from given directory
92
93 find_latest_mif()
94 {
95
96 [ -z "$1" ] && return
97
98 CCFPATH="$1"
99
100 maxissue="0"
101 for mif in `ls -1 ${CCFPATH}/XMM_CALINDEX_*.CCF`
102 do
103 mifbase=`basename $mif`
104 issue=`echo $mifbase | awk -F"." '{print $1}' | awk -F"_" '{print $3}'`
105 [ "$issue" -ge "$maxissue" ] && maxissue="$issue"
106 done
107
108 MIF=${CCFPATH}/XMM_CALINDEX_${maxissue}.CCF
109
110 }
111
112
113
114 # +++Function get_ccf_list to list on stdout the table of CCFs in a given CIF.
115 #
116 # Requires that Heasoft is initialised. Otherwise exits with error.
117
118 get_ccf_list()
119 {
120 [ -z "$1" ] && return
121
122 cif_to_process="$1"
123
124 noversion=`which fversion | grep -c no`
125
126 if [ "${noversion}" != "0" ] ; then
127 echo "Error: Heasoft not initialised !"
128 [ -f "${mailfile}" ] && rm -rf ${mailfile}
129 echo "Running of fversion produced the following output:" >> $mailfile
130 echo "$noversion" >> $mailfile
131 mailnotify "mvloccf: Error: Heasoft not initialised!" $mailfile
132 rm ${mailfile}
133 exit
134 fi
135
136 fdump ${cif_to_process} prhead=no showcol=no showrow=no page=no \
137 columns="SCOPE TYPEID ISSUE" \
138 rows=- STDOUT
139 }
140
141
142
143
144 # +++ Fill in the valid_constituents directory with the Valid CCF set
145 #
146 # The directory to be filled in is ${VALIDCONSTITUENTSDISR}.
147 # This directory is synchronized with the similar directory in the
148 # external ftp server.
149 #
150 # In addition to that, we also use this function to fill in the
151 # /ccf/valid directory available for users in the intranet.
152
153 fillvalidccfdir()
154 {
155
156 [ -z "$1" ] && return
157
158 validccflist=$1
159
160 if [ ! -f "${VALID_CCF}/${validccflist}" ] ; then
161 echo "Error: ${VALID_CCF}/${validccflist} not found - Abort!"
162 [ -f "${mailfile}" ] && rm -rf ${mailfile}
163 echo "The list of valid CCF ${VALID_CCF}/${validccflist} is not found" >> $mailfile
164 mailnotify "mvloccf: Error: ${VALID_CCF}/${validccflist} not found - Abort!" $mailfile
165 rm ${mailfile}
166 exit
167 fi
168
169 VALIDCONSTITUENTSDIR="/home/ccflib/ftp-area/valid_constituents"
170 rm -rf ${VALIDCONSTITUENTSDIR}/*
171
172 VALIDCCFDIRINTRANET="/ccf/valid"
173 rm -rf ${VALIDCCFDIRINTRANET}/*
174
175 CONSTITUENTSDIR="/home/ccflib/ftp-area/constituents"
176 n=0
177 while read ccf
178 do
179 n=$((n + 1))
180 echo "$n cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/"
181 cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/
182 echo "$n cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCCFDIRINTRANET}/"
183 cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCCFDIRINTRANET}/
184 done < ${VALID_CCF}/${validccflist}
185
186 }
187
188
189 #
190 # M a i n p r o g r a m
191 #
192 # 1. Get the list of all ODFs
193
194
195 xsaobslogsize="0"
196
197 getxsaobslog
198
199 xsaobslogsize=`stat --format=%s ${VALID_CCF}/xsaobslog_${now}.txt`
200
201 if [ "$xsaobslogsize" = "0" ] ; then
202 echo "Error: Failure to download the XSA Obs. Log file - Abort"
203 [ -f "${mailfile}" ] && rm -rf ${mailfile}
204 echo "The XSA Obs. Log file has 0 size - Not downloaded?" >> $mailfile
205 echo "." >> $mailfile
206 mailnotify "mlovccf: Error: Failure to download the XSA Obs. Log file - Abort" "$mailfile"
207 rm ${mailfile}
208 exit
209 fi
210
211 # 2. Sets SAS_CCFPATH and initialises HEADAS and SAS depending on host
212
213 case "$host" in
214 xvsoc01|xmm)
215 export SAS_CCFPATH="/data/xmm/ccflib/ftp-area/constituents"
216 export SAS_DIR=/data/xmm/ccflib/sas
217 export SAS_PATH=$SAS_DIR
218 source $SAS_DIR/sas-setup.sh
219 ;;
220 sasbld01|sasbld02)
221 export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
222 /sas/bin/confsas
223 export HEADAS=/sasbuild/local/${host}/headas/architecture
224 . $HEADAS/headas-init.sh
225 # To be able to mix several jobs on the same ccflib account
226 [ ! -d "${HOME}/pfiles/${host}" ] && mkdir ${HOME}/pfiles/${host}
227 export PFILES="${HOME}/pfiles/${host};${HEADAS}/syspfiles"
228 echo -n "HEADAS version: "
229 fversion
230 source $HOME/setsas.sh 1> /dev/null
231 echo "SAS Version: "
232 sasversion -V 1
233 export SAS_VERBOSITY=0
234 ;;
235 scigrid6|cn-*)
236 export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
237 /sas/bin/confsas
238 export HEADAS=/sasbuild/local/sasbld02/headas/architecture
239 . $HEADAS/headas-init.sh
240 # To be able to mix several jobs on the same ccflib account
241 [ ! -d "${HOME}/pfiles/${host}" ] && mkdir ${HOME}/pfiles/${host}
242 export PFILES="${HOME}/pfiles/${host};${HEADAS}/syspfiles"
243 echo -n "HEADAS version: "
244 fversion
245 source $HOME/setsas.sh 1> /dev/null
246 echo "SAS Version: "
247 sasversion -V 1
248 export SAS_VERBOSITY=0
249 ;;
250 *) echo "Error: Do not know how to do it in host $host" ; exit ;;
251 esac
252
253 # 3. Finds the latest MIF issue
254
255 find_latest_mif "${SAS_CCFPATH}"
256
257
258 # 4. Scans the list of OBDS ID registered in the previous list to get the start time
259 # Then runs cifbuild to get the respective CIF.
260 # all_ccfs_${now}.txt is filled recursively on each iteration. Therefore we start
261 # with an empty file.
262
263 # Output file : ${VALID_CCF}/all_ccfs_${now}.txt
264
265 touch ${VALID_CCF}/all_ccfs_${now}.txt
266
267 n=0
268
269 while read line
270 do
271 obsid=`echo $line | awk -F"|" '{print $2}'`
272 stime=`echo $line | awk -F"|" '{print $9}'`
273 stime=`echo $stime | tr " " "T"`
274 n=$((n+1))
275 echo "($n) Processing $obsid $stime" ; echo
276
277 # Run cifbuild
278
279 cif_file=${VALID_CCF}/${obsid}.cif
280
281 cifbuild --withmasterindexset='yes' \
282 --masterindexset=${MIF} \
283 --withobservationdate='yes' \
284 --observationdate=${stime} \
285 --analysisdate='now' \
286 --calindexset=${cif_file}
287
288
289 # Gets the list of CCFs included in the CIF
290
291 get_ccf_list "${cif_file}" > ${VALID_CCF}/${obsid}_ccfs.tmp
292
293 while read line
294 do
295 [ "$line" = "" ] && continue
296 class=`echo $line | awk -F" " '{print $1"_"$2}'`
297 issue=`echo $line | awk -F" " '{print $3}'`
298 issue=`printf "%04d" ${issue}`
299 echo ${class}_${issue}.CCF >> ${VALID_CCF}/${obsid}_ccfs.txt
300
301 done < ${VALID_CCF}/${obsid}_ccfs.tmp
302
303 rm ${VALID_CCF}/${obsid}_ccfs.tmp
304
305 mv ${VALID_CCF}/all_ccfs_${now}.txt ${VALID_CCF}/all_ccfs_${now}.tmp
306
307 cat ${VALID_CCF}/${obsid}_ccfs.txt ${VALID_CCF}/all_ccfs_${now}.tmp | sort -u > ${VALID_CCF}/all_ccfs_${now}.txt
308
309 rm ${cif_file}
310 rm ${VALID_CCF}/${obsid}_ccfs.txt
311 rm ${VALID_CCF}/all_ccfs_${now}.tmp
312
313 done < ${VALID_CCF}/xsaobslog_${now}.txt
314
315 # 5. Make a table of classes and issues with the style "Pipeline Release Notes"
316 # To get a classification, we need first to obtain all available classes.
317 #
318
319
320 # Lists all CCF classes
321
322 ccf_classes="${VALID_CCF}/ccf_classes.txt"
323
324 while read line
325 do
326 class=`echo $line | awk -F"_" '{print $1"_"$2}'`
327 echo $class >> ${ccf_classes}
328 done < ${VALID_CCF}/all_ccfs_${now}.txt
329
330 cat ${ccf_classes} | sort -u > ${VALID_CCF}/kk.txt
331 mv ${VALID_CCF}/kk.txt ${ccf_classes}
332
333
334
335 # Output final file is named all_ccfs_${now}_table.txt
336
337 total_number_of_ccfs=0
338
339 all_ccfs_table="${VALID_CCF}/all_ccfs_${now}_table.txt"
340
341 [ -f "${all_ccfs_table}" ] && rm ${all_ccfs_table}
342
343 echo "Table of valid CCFs at $now_table" >> ${all_ccfs_table}
344 echo >> ${all_ccfs_table}
345 echo "|================================|=============|=======|" >> ${all_ccfs_table}
346 echo "| Calibration File | Issue range | Count |" >> ${all_ccfs_table}
347 echo "|================================|=============|=======|" >> ${all_ccfs_table}
348
349 while read ccf_class
350 do
351 echo -n "Processing class $ccf_class ..."
352 issues_file="${VALID_CCF}/ccf_issues_for_${ccf_class}.txt"
353 [ -f "${issues_file}" ] && rm ${issues_file}
354 while read line
355 do
356 class=`echo $line | awk -F"_" '{print $1"_"$2}'`
357 [ "$class" != "$ccf_class" ] && continue
358 issue=`echo $line | awk -F"_" '{print $3}' | cut -d. -f1`
359 echo $issue >> ${issues_file}
360 done < ${VALID_CCF}/all_ccfs_${now}.txt
361
362 cat ${issues_file} | sort -u > kk.txt
363 mv kk.txt ${issues_file}
364 real_number_of_issues_for_this_class=`wc -l ${issues_file} | awk -F" " '{print $1}'`
365
366 first_issue=`head -1 ${issues_file}`
367 last_issue=`tail -1 ${issues_file}`
368
369 li=$((10#$last_issue))
370 fi=$((10#$first_issue))
371
372 sequential_number_of_issues_for_this_class=$((li - fi + 1))
373
374 asterisk=" "
375 [ "${real_number_of_issues_for_this_class}" -lt "${sequential_number_of_issues_for_this_class}" ] && asterisk="(*)"
376
377 total_number_of_ccfs=$((real_number_of_issues_for_this_class + total_number_of_ccfs))
378
379 rn=$real_number_of_issues_for_this_class
380
381 if [ "${first_issue}" != "${last_issue}" ] ; then
382 if [ "$asterisk" = "(*)" ] ; then
383 printf "| %-30s | %4s-%4s(*)| %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
384 else
385 printf "| %-30s | %4s-%4s | %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
386 fi
387 else
388 printf "| %-30s | %4s | %4s |\n" ${ccf_class} ${first_issue} ${rn} >> ${all_ccfs_table}
389 fi
390
391
392 echo "done"
393 done < ${ccf_classes}
394
395 echo "|================================|=============|=======|" >> ${all_ccfs_table}
396 echo >> ${all_ccfs_table}
397 echo "(*): Incomplete range." >> ${all_ccfs_table}
398 echo "" >> ${all_ccfs_table}
399 echo "Total number of valid CCFs required : ${total_number_of_ccfs}" >> ${all_ccfs_table}
400 rm ${VALID_CCF}/ccf_classes.txt
401 rm ${VALID_CCF}/ccf_issues_for*.txt
402
403
404
405 # 6. Fill in the Valid CCF Set dir with the proper CCFs
406
407 fillvalidccfdir "all_ccfs_${now}.txt"
408
409 [ -f "${mailfile}" ] && rm -rf ${mailfile}
410 echo "Valid CCF Set successfully copied to ${VALIDCONSTITUENTSDIR}" >> $mailfile
411 echo "Valid CCF Set successfully copied to ${VALIDCCFDIRINTRANET}" >> $mailfile
412 mailnotify "mvloccf: Valid CCF Set created successfully" $mailfile
413 rm ${mailfile}

  ViewVC Help
Powered by ViewVC 1.1.27