/[CCFs]/bin/mlovccf
ViewVC logotype

Contents of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations)
Wed Mar 23 15:36:37 2016 UTC (8 years, 8 months ago) by ccflib
Branch: MAIN
Changes since 1.11: +7 -5 lines
Fixed while loop in fillvalidccfdir

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.11 2016/03/23 09:31:49 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: ${VALID_CCF}/${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 n=0
122 while read ccf
123 do
124 n=$((n + 1))
125 echo "$n cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/"
126 cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/
127 done < ${VALID_CCF}/${validccflist}
128
129 }
130
131
132 # Get the list of all ODFs
133
134 xsaobslogsize="0"
135
136 getxsaobslog
137
138 xsaobslogsize=`stat --format=%s ${VALID_CCF}/xsaobslog_${now}.txt`
139
140 if [ "$xsaobslogsize" = "0" ] ; then
141 echo "Error: Failure to download the XSA Obs. Log file - Abort"
142 exit
143 fi
144
145 # Sets SAS_CCFPATH and initialises HEADAS and SAS depending on host
146
147 case "$host" in
148 xvsoc01|xmm)
149 export SAS_CCFPATH="/data/xmm/ccflib/ftp-area/constituents"
150 export SAS_DIR=/data/xmm/ccflib/sas
151 export SAS_PATH=$SAS_DIR
152 source $SAS_DIR/sas-setup.sh
153 ;;
154 sasbld01|sasbld02)
155 export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
156 /sas/bin/confsas
157 export HEADAS=/sasbuild/local/${host}/headas/architecture
158 . $HEADAS/headas-init.sh
159 # To be able to mix several jobs on the same ccflib account
160 [ ! -d "${HOME}/pfiles/${host}" ] && mkdir ${HOME}/pfiles/${host}
161 export PFILES="${HOME}/pfiles/${host};${HEADAS}/syspfiles"
162 echo -n "HEADAS version: "
163 fversion
164 source $HOME/setsas.sh 1> /dev/null
165 echo "SAS Version: "
166 sasversion -V 1
167 export SAS_VERBOSITY=0
168 ;;
169 scigrid6|cn-*)
170 export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
171 /sas/bin/confsas
172 export HEADAS=/sasbuild/local/sasbld02/headas/architecture
173 . $HEADAS/headas-init.sh
174 # To be able to mix several jobs on the same ccflib account
175 [ ! -d "${HOME}/pfiles/${host}" ] && mkdir ${HOME}/pfiles/${host}
176 export PFILES="${HOME}/pfiles/${host};${HEADAS}/syspfiles"
177 echo -n "HEADAS version: "
178 fversion
179 source $HOME/setsas.sh 1> /dev/null
180 echo "SAS Version: "
181 sasversion -V 1
182 export SAS_VERBOSITY=0
183 ;;
184 *) echo "Error: Do not know how to do it in host $host" ; exit ;;
185 esac
186
187 # Finds the latest MIF issue
188
189 find_latest_mif "${SAS_CCFPATH}"
190
191
192 # Now scans the list of OBDS ID registered in the previous list to get the start time
193 # and then runs cifbuild to get the respective CIF
194
195 # Output file
196 touch ${VALID_CCF}/all_ccfs_${now}.txt
197
198 n=0
199
200 while read line
201 do
202 obsid=`echo $line | awk -F"|" '{print $2}'`
203 stime=`echo $line | awk -F"|" '{print $9}'`
204 stime=`echo $stime | tr " " "T"`
205 n=$((n+1))
206 echo "($n) Processing $obsid $stime" ; echo
207
208 # Run cifbuild
209
210 cif_file=${VALID_CCF}/${obsid}.cif
211
212 cifbuild --withmasterindexset='yes' \
213 --masterindexset=${MIF} \
214 --withobservationdate='yes' \
215 --observationdate=${stime} \
216 --analysisdate='now' \
217 --calindexset=${cif_file}
218
219
220 # Gets the list of CCFs included in the CIF
221
222 get_ccf_list "${cif_file}" > ${VALID_CCF}/${obsid}_ccfs.tmp
223
224 while read line
225 do
226 [ "$line" = "" ] && continue
227 class=`echo $line | awk -F" " '{print $1"_"$2}'`
228 issue=`echo $line | awk -F" " '{print $3}'`
229 issue=`printf "%04d" ${issue}`
230 echo ${class}_${issue}.CCF >> ${VALID_CCF}/${obsid}_ccfs.txt
231
232 done < ${VALID_CCF}/${obsid}_ccfs.tmp
233
234 rm ${VALID_CCF}/${obsid}_ccfs.tmp
235
236 mv ${VALID_CCF}/all_ccfs_${now}.txt ${VALID_CCF}/all_ccfs_${now}.tmp
237
238 cat ${VALID_CCF}/${obsid}_ccfs.txt ${VALID_CCF}/all_ccfs_${now}.tmp | sort -u > ${VALID_CCF}/all_ccfs_${now}.txt
239
240 rm ${cif_file}
241 rm ${VALID_CCF}/${obsid}_ccfs.txt
242 rm ${VALID_CCF}/all_ccfs_${now}.tmp
243
244 done < ${VALID_CCF}/xsaobslog_${now}.txt
245
246 # Make a table of classes and issues type "Pipeline Release Notes"
247
248 # Lists all CCF classes
249
250 ccf_classes="${VALID_CCF}/ccf_classes.txt"
251
252 while read line
253 do
254 class=`echo $line | awk -F"_" '{print $1"_"$2}'`
255 echo $class >> ${ccf_classes}
256 done < ${VALID_CCF}/all_ccfs_${now}.txt
257
258 cat ${ccf_classes} | sort -u > ${VALID_CCF}/kk.txt
259 mv ${VALID_CCF}/kk.txt ${ccf_classes}
260
261 # Output final file is named all_ccfs_${now}_table.txt
262
263 total_number_of_ccfs=0
264
265 all_ccfs_table="${VALID_CCF}/all_ccfs_${now}_table.txt"
266
267 [ -f "${all_ccfs_table}" ] && rm ${all_ccfs_table}
268
269 echo "Table of valid CCFs at $now_table" >> ${all_ccfs_table}
270 echo >> ${all_ccfs_table}
271 echo "|================================|=============|=======|" >> ${all_ccfs_table}
272 echo "| Calibration File | Issue range | Count |" >> ${all_ccfs_table}
273 echo "|================================|=============|=======|" >> ${all_ccfs_table}
274
275 while read ccf_class
276 do
277 echo -n "Processing class $ccf_class ..."
278 issues_file="${VALID_CCF}/ccf_issues_for_${ccf_class}.txt"
279 [ -f "${issues_file}" ] && rm ${issues_file}
280 while read line
281 do
282 class=`echo $line | awk -F"_" '{print $1"_"$2}'`
283 [ "$class" != "$ccf_class" ] && continue
284 issue=`echo $line | awk -F"_" '{print $3}' | cut -d. -f1`
285 echo $issue >> ${issues_file}
286 done < ${VALID_CCF}/all_ccfs_${now}.txt
287
288 cat ${issues_file} | sort -u > kk.txt
289 mv kk.txt ${issues_file}
290 real_number_of_issues_for_this_class=`wc -l ${issues_file} | awk -F" " '{print $1}'`
291
292 first_issue=`head -1 ${issues_file}`
293 last_issue=`tail -1 ${issues_file}`
294
295 li=$((10#$last_issue))
296 fi=$((10#$first_issue))
297
298 sequential_number_of_issues_for_this_class=$((li - fi + 1))
299
300 asterisk=" "
301 [ "${real_number_of_issues_for_this_class}" -lt "${sequential_number_of_issues_for_this_class}" ] && asterisk="(*)"
302
303 total_number_of_ccfs=$((real_number_of_issues_for_this_class + total_number_of_ccfs))
304
305 rn=$real_number_of_issues_for_this_class
306
307 if [ "${first_issue}" != "${last_issue}" ] ; then
308 if [ "$asterisk" = "(*)" ] ; then
309 printf "| %-30s | %4s-%4s(*)| %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
310 else
311 printf "| %-30s | %4s-%4s | %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
312 fi
313 else
314 printf "| %-30s | %4s | %4s |\n" ${ccf_class} ${first_issue} ${rn} >> ${all_ccfs_table}
315 fi
316
317
318 echo "done"
319 done < ${ccf_classes}
320
321 echo "|================================|=============|=======|" >> ${all_ccfs_table}
322 echo >> ${all_ccfs_table}
323 echo "(*): Incomplete range." >> ${all_ccfs_table}
324 echo "" >> ${all_ccfs_table}
325 echo "Total number of valid CCFs required : ${total_number_of_ccfs}" >> ${all_ccfs_table}
326 rm ${VALID_CCF}/ccf_classes.txt
327 rm ${VALID_CCF}/ccf_issues_for*.txt
328
329 # Fill in the Valid CCF Set dir with the proper CCFs
330
331 fillvalidccfdir "all_ccfs_${now}.txt"

  ViewVC Help
Powered by ViewVC 1.1.27