/[CCFs]/bin/mlovccf
ViewVC logotype

Contents of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations)
Wed Mar 23 09:31:49 2016 UTC (8 years, 8 months ago) by ccflib
Branch: MAIN
Changes since 1.10: +33 -2 lines
Output file from wget set to /xsaobslog.txt

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.10 2016/03/21 15:36:25 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
28 VALID_CCF="$HOME/valid_ccf"
29
30 host=`hostname | cut -d. -f1`
31
32 now=`date +'%Y%m%d_%H%M'`
33 now_table=`date +'%Y-%m-%dT%H:%M:%S'`
34
35
36 # Function getxsaobslog
37 # We need to get the list of all observed ODFs at the current date.
38 # This is obtained from http://nxsa.esac.esa.int/ftp_public/cds_obslog/xsaobslog.txt.
39
40 getxsaobslog ()
41 {
42
43 XSAOBSURL="http://nxsa.esac.esa.int/ftp_public/cds_obslog/xsaobslog.txt"
44
45 # Remove any xsaobslog.txt previously downloaded.
46
47 [ -f "${VALID_CCF}/xsaobslog.txt" ] && rm -rf ${VALID_CCF}/xsaobslog.txt
48
49 # Get the list latest list of ODFs available from nXSA server.
50
51 wget -q ${XSAOBSURL} -O ${VALID_CCF}/xsaobslog.txt
52
53 # Rename xsaobslog.txt to xsaobslog_${now}.txt just to have a reference
54 # of which list of ODFs was used to compute the list of valid CCFs.
55
56 mv ${VALID_CCF}/xsaobslog.txt ${VALID_CCF}/xsaobslog_${now}.txt
57
58 }
59
60
61 # Function find_latest_mif to get the latest XMM_CALINDEX from given directory
62
63 find_latest_mif()
64 {
65
66 [ -z "$1" ] && return
67
68 CCFPATH="$1"
69
70 maxissue="0"
71 for mif in `ls -1 ${CCFPATH}/XMM_CALINDEX_*.CCF`
72 do
73 mifbase=`basename $mif`
74 issue=`echo $mifbase | awk -F"." '{print $1}' | awk -F"_" '{print $3}'`
75 [ "$issue" -ge "$maxissue" ] && maxissue="$issue"
76 done
77
78 MIF=${CCFPATH}/XMM_CALINDEX_${maxissue}.CCF
79
80 }
81
82 # Function get_ccf_list to list on stdout the table of CCFs in a given CIF.
83 # Requires that Heasoft is initialised. Otherwise exits with error.
84
85 get_ccf_list()
86 {
87 [ -z "$1" ] && return
88
89 cif_to_process="$1"
90
91 noversion=`which fversion | grep -c no`
92
93 if [ "${noversion}" != "0" ] ; then
94 echo "Error: Heasoft not initialised !"
95 exit
96 fi
97
98 fdump ${cif_to_process} prhead=no showcol=no showrow=no page=no \
99 columns="SCOPE TYPEID ISSUE" \
100 rows=- STDOUT
101 }
102
103 # Fill in the valid_constituents directory with the Valid CCF set
104
105 fillvalidccfdir()
106 {
107
108 [ -z "$1" ] && return
109
110 validccflist=$1
111
112 if [ ! -f "${VALID_CCF}/${validccflist}" ] ; then
113 echo "Error: ${validccflist} not found - Abort!"
114 exit
115 fi
116
117 VALIDCONSTITUENTSDIR="/home/ccflib/ftp-area/valid_constituents/"
118 rm -rf ${VALIDCONSTITUENTSDIR}/*
119
120 CONSTITUENTSDIR="/home/ccflib/ftp-area/constituents"
121
122 while read ccf
123 do
124 cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/
125 done < ${validccflist}
126
127 }
128
129
130 # Get the list of all ODFs
131
132 xsaobslogsize="0"
133
134 getxsaobslog
135
136 xsaobslogsize=`stat --format=%s ${VALID_CCF}/xsaobslog_${now}.txt`
137
138 if [ "$xsaobslogsize" = "0" ] ; then
139 echo "Error: Failure to download the XSA Obs. Log file - Abort"
140 exit
141 fi
142
143 # Sets SAS_CCFPATH and initialises HEADAS and SAS depending on host
144
145 case "$host" in
146 xvsoc01|xmm)
147 export SAS_CCFPATH="/data/xmm/ccflib/ftp-area/constituents"
148 export SAS_DIR=/data/xmm/ccflib/sas
149 export SAS_PATH=$SAS_DIR
150 source $SAS_DIR/sas-setup.sh
151 ;;
152 sasbld01|sasbld02)
153 export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
154 /sas/bin/confsas
155 export HEADAS=/sasbuild/local/${host}/headas/architecture
156 . $HEADAS/headas-init.sh
157 # To be able to mix several jobs on the same ccflib account
158 [ ! -d "${HOME}/pfiles/${host}" ] && mkdir ${HOME}/pfiles/${host}
159 export PFILES="${HOME}/pfiles/${host};${HEADAS}/syspfiles"
160 echo -n "HEADAS version: "
161 fversion
162 source $HOME/setsas.sh 1> /dev/null
163 echo "SAS Version: "
164 sasversion -V 1
165 export SAS_VERBOSITY=0
166 ;;
167 scigrid6|cn-*)
168 export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
169 /sas/bin/confsas
170 export HEADAS=/sasbuild/local/sasbld02/headas/architecture
171 . $HEADAS/headas-init.sh
172 # To be able to mix several jobs on the same ccflib account
173 [ ! -d "${HOME}/pfiles/${host}" ] && mkdir ${HOME}/pfiles/${host}
174 export PFILES="${HOME}/pfiles/${host};${HEADAS}/syspfiles"
175 echo -n "HEADAS version: "
176 fversion
177 source $HOME/setsas.sh 1> /dev/null
178 echo "SAS Version: "
179 sasversion -V 1
180 export SAS_VERBOSITY=0
181 ;;
182 *) echo "Error: Do not know how to do it in host $host" ; exit ;;
183 esac
184
185 # Finds the latest MIF issue
186
187 find_latest_mif "${SAS_CCFPATH}"
188
189
190 # Now scans the list of OBDS ID registered in the previous list to get the start time
191 # and then runs cifbuild to get the respective CIF
192
193 # Output file
194 touch ${VALID_CCF}/all_ccfs_${now}.txt
195
196 n=0
197
198 while read line
199 do
200 obsid=`echo $line | awk -F"|" '{print $2}'`
201 stime=`echo $line | awk -F"|" '{print $9}'`
202 stime=`echo $stime | tr " " "T"`
203 n=$((n+1))
204 echo "($n) Processing $obsid $stime" ; echo
205
206 # Run cifbuild
207
208 cif_file=${VALID_CCF}/${obsid}.cif
209
210 cifbuild --withmasterindexset='yes' \
211 --masterindexset=${MIF} \
212 --withobservationdate='yes' \
213 --observationdate=${stime} \
214 --analysisdate='now' \
215 --calindexset=${cif_file}
216
217
218 # Gets the list of CCFs included in the CIF
219
220 get_ccf_list "${cif_file}" > ${VALID_CCF}/${obsid}_ccfs.tmp
221
222 while read line
223 do
224 [ "$line" = "" ] && continue
225 class=`echo $line | awk -F" " '{print $1"_"$2}'`
226 issue=`echo $line | awk -F" " '{print $3}'`
227 issue=`printf "%04d" ${issue}`
228 echo ${class}_${issue}.CCF >> ${VALID_CCF}/${obsid}_ccfs.txt
229
230 done < ${VALID_CCF}/${obsid}_ccfs.tmp
231
232 rm ${VALID_CCF}/${obsid}_ccfs.tmp
233
234 mv ${VALID_CCF}/all_ccfs_${now}.txt ${VALID_CCF}/all_ccfs_${now}.tmp
235
236 cat ${VALID_CCF}/${obsid}_ccfs.txt ${VALID_CCF}/all_ccfs_${now}.tmp | sort -u > ${VALID_CCF}/all_ccfs_${now}.txt
237
238 rm ${cif_file}
239 rm ${VALID_CCF}/${obsid}_ccfs.txt
240 rm ${VALID_CCF}/all_ccfs_${now}.tmp
241
242 done < ${VALID_CCF}/xsaobslog_${now}.txt
243
244 # Make a table of classes and issues type "Pipeline Release Notes"
245
246 # Lists all CCF classes
247
248 ccf_classes="${VALID_CCF}/ccf_classes.txt"
249
250 while read line
251 do
252 class=`echo $line | awk -F"_" '{print $1"_"$2}'`
253 echo $class >> ${ccf_classes}
254 done < ${VALID_CCF}/all_ccfs_${now}.txt
255
256 cat ${ccf_classes} | sort -u > ${VALID_CCF}/kk.txt
257 mv ${VALID_CCF}/kk.txt ${ccf_classes}
258
259 # Output final file is named all_ccfs_${now}_table.txt
260
261 total_number_of_ccfs=0
262
263 all_ccfs_table="${VALID_CCF}/all_ccfs_${now}_table.txt"
264
265 [ -f "${all_ccfs_table}" ] && rm ${all_ccfs_table}
266
267 echo "Table of valid CCFs at $now_table" >> ${all_ccfs_table}
268 echo >> ${all_ccfs_table}
269 echo "|================================|=============|=======|" >> ${all_ccfs_table}
270 echo "| Calibration File | Issue range | Count |" >> ${all_ccfs_table}
271 echo "|================================|=============|=======|" >> ${all_ccfs_table}
272
273 while read ccf_class
274 do
275 echo -n "Processing class $ccf_class ..."
276 issues_file="${VALID_CCF}/ccf_issues_for_${ccf_class}.txt"
277 [ -f "${issues_file}" ] && rm ${issues_file}
278 while read line
279 do
280 class=`echo $line | awk -F"_" '{print $1"_"$2}'`
281 [ "$class" != "$ccf_class" ] && continue
282 issue=`echo $line | awk -F"_" '{print $3}' | cut -d. -f1`
283 echo $issue >> ${issues_file}
284 done < ${VALID_CCF}/all_ccfs_${now}.txt
285
286 cat ${issues_file} | sort -u > kk.txt
287 mv kk.txt ${issues_file}
288 real_number_of_issues_for_this_class=`wc -l ${issues_file} | awk -F" " '{print $1}'`
289
290 first_issue=`head -1 ${issues_file}`
291 last_issue=`tail -1 ${issues_file}`
292
293 li=$((10#$last_issue))
294 fi=$((10#$first_issue))
295
296 sequential_number_of_issues_for_this_class=$((li - fi + 1))
297
298 asterisk=" "
299 [ "${real_number_of_issues_for_this_class}" -lt "${sequential_number_of_issues_for_this_class}" ] && asterisk="(*)"
300
301 total_number_of_ccfs=$((real_number_of_issues_for_this_class + total_number_of_ccfs))
302
303 rn=$real_number_of_issues_for_this_class
304
305 if [ "${first_issue}" != "${last_issue}" ] ; then
306 if [ "$asterisk" = "(*)" ] ; then
307 printf "| %-30s | %4s-%4s(*)| %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
308 else
309 printf "| %-30s | %4s-%4s | %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
310 fi
311 else
312 printf "| %-30s | %4s | %4s |\n" ${ccf_class} ${first_issue} ${rn} >> ${all_ccfs_table}
313 fi
314
315
316 echo "done"
317 done < ${ccf_classes}
318
319 echo "|================================|=============|=======|" >> ${all_ccfs_table}
320 echo >> ${all_ccfs_table}
321 echo "(*): Incomplete range." >> ${all_ccfs_table}
322 echo "" >> ${all_ccfs_table}
323 echo "Total number of valid CCFs required : ${total_number_of_ccfs}" >> ${all_ccfs_table}
324 rm ${VALID_CCF}/ccf_classes.txt
325 rm ${VALID_CCF}/ccf_issues_for*.txt
326
327 # Fill in the Valid CCF Set dir with the proper CCFs
328
329 fillvalidccfdir all_ccfs_${now}.txt

  ViewVC Help
Powered by ViewVC 1.1.27