/[CCFs]/bin/mlovccf
ViewVC logotype

Annotation of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (hide 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 ccflib 1.1 #! /bin/bash
2    
3     # mlovccf (make list of valid ccfs)
4     #
5 ccflib 1.7 # Makes the list of valid CCFs. These are all CCFs, among those published since the
6 ccflib 1.2 # beginning of the project, that are required to process any ODF at a given date,
7 ccflib 1.7 # typically the current date. This list will change with time as far as new
8 ccflib 1.2 # CCFs are issued to deal with new calibration data and/or replace obsolete ones.
9 ccflib 1.1 #
10 ccflib 1.10 # To identify the set of CCFs required to process a given ODF is the job of task cifbuild.
11 ccflib 1.2 # To make such identification, cifbuild needs only the start time of the observation.
12 ccflib 1.7 # 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 ccflib 1.1 #
17 ccflib 1.7 # 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 ccflib 1.10 # xsaobslog.txt (http://nxsa.esac.esa.int/ftp_public/cfs_obslog/xsaobslog.txt).
20 ccflib 1.2 #
21 ccflib 1.11 # $Id: mlovccf,v 1.10 2016/03/21 15:36:25 ccflib Exp $
22 ccflib 1.4
23     # Next two lines allow to submit this script to the grid
24     # request Bourne shell as shell for job
25 ccflib 1.6 #$ -S /bin/bash
26 ccflib 1.1
27 ccflib 1.5
28 ccflib 1.10 VALID_CCF="$HOME/valid_ccf"
29    
30 ccflib 1.1 host=`hostname | cut -d. -f1`
31    
32 ccflib 1.5 now=`date +'%Y%m%d_%H%M'`
33 ccflib 1.7 now_table=`date +'%Y-%m-%dT%H:%M:%S'`
34 ccflib 1.3
35 ccflib 1.10
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 ccflib 1.11 wget -q ${XSAOBSURL} -O ${VALID_CCF}/xsaobslog.txt
52 ccflib 1.10
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 ccflib 1.1 # 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 ccflib 1.10 # Function get_ccf_list to list on stdout the table of CCFs in a given CIF.
83 ccflib 1.2 # Requires that Heasoft is initialised. Otherwise exits with error.
84 ccflib 1.1
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 ccflib 1.11 # 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 ccflib 1.10 # Get the list of all ODFs
131 ccflib 1.1
132 ccflib 1.10 xsaobslogsize="0"
133 ccflib 1.1
134 ccflib 1.10 getxsaobslog
135 ccflib 1.1
136 ccflib 1.10 xsaobslogsize=`stat --format=%s ${VALID_CCF}/xsaobslog_${now}.txt`
137 ccflib 1.1
138 ccflib 1.10 if [ "$xsaobslogsize" = "0" ] ; then
139     echo "Error: Failure to download the XSA Obs. Log file - Abort"
140     exit
141     fi
142 ccflib 1.1
143     # Sets SAS_CCFPATH and initialises HEADAS and SAS depending on host
144    
145     case "$host" in
146     xvsoc01|xmm)
147 ccflib 1.5 export SAS_CCFPATH="/data/xmm/ccflib/ftp-area/constituents"
148     export SAS_DIR=/data/xmm/ccflib/sas
149     export SAS_PATH=$SAS_DIR
150 ccflib 1.1 source $SAS_DIR/sas-setup.sh
151     ;;
152     sasbld01|sasbld02)
153 ccflib 1.5 export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
154 ccflib 1.1 /sas/bin/confsas
155     export HEADAS=/sasbuild/local/${host}/headas/architecture
156     . $HEADAS/headas-init.sh
157 ccflib 1.7 # 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 ccflib 1.1 source $HOME/setsas.sh 1> /dev/null
163 ccflib 1.7 echo "SAS Version: "
164     sasversion -V 1
165 ccflib 1.1 export SAS_VERBOSITY=0
166     ;;
167 ccflib 1.5 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 ccflib 1.7 # 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 ccflib 1.5 source $HOME/setsas.sh 1> /dev/null
178 ccflib 1.7 echo "SAS Version: "
179     sasversion -V 1
180 ccflib 1.5 export SAS_VERBOSITY=0
181     ;;
182     *) echo "Error: Do not know how to do it in host $host" ; exit ;;
183 ccflib 1.1 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 ccflib 1.2 # Output file
194 ccflib 1.3 touch ${VALID_CCF}/all_ccfs_${now}.txt
195 ccflib 1.2
196 ccflib 1.1 n=0
197 ccflib 1.2
198 ccflib 1.1 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 ccflib 1.2
230 ccflib 1.1 done < ${VALID_CCF}/${obsid}_ccfs.tmp
231    
232     rm ${VALID_CCF}/${obsid}_ccfs.tmp
233    
234 ccflib 1.3 mv ${VALID_CCF}/all_ccfs_${now}.txt ${VALID_CCF}/all_ccfs_${now}.tmp
235 ccflib 1.2
236 ccflib 1.3 cat ${VALID_CCF}/${obsid}_ccfs.txt ${VALID_CCF}/all_ccfs_${now}.tmp | sort -u > ${VALID_CCF}/all_ccfs_${now}.txt
237 ccflib 1.1
238     rm ${cif_file}
239     rm ${VALID_CCF}/${obsid}_ccfs.txt
240 ccflib 1.3 rm ${VALID_CCF}/all_ccfs_${now}.tmp
241 ccflib 1.1
242 ccflib 1.7 done < ${VALID_CCF}/xsaobslog_${now}.txt
243 ccflib 1.2
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 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
255 ccflib 1.2
256     cat ${ccf_classes} | sort -u > ${VALID_CCF}/kk.txt
257     mv ${VALID_CCF}/kk.txt ${ccf_classes}
258    
259 ccflib 1.3 # Output final file is named all_ccfs_${now}_table.txt
260    
261     total_number_of_ccfs=0
262 ccflib 1.2
263 ccflib 1.7 all_ccfs_table="${VALID_CCF}/all_ccfs_${now}_table.txt"
264 ccflib 1.2
265     [ -f "${all_ccfs_table}" ] && rm ${all_ccfs_table}
266    
267 ccflib 1.7 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 ccflib 1.2
273     while read ccf_class
274 ccflib 1.3 do
275     echo -n "Processing class $ccf_class ..."
276 ccflib 1.2 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 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
285 ccflib 1.2
286     cat ${issues_file} | sort -u > kk.txt
287     mv kk.txt ${issues_file}
288 ccflib 1.3 real_number_of_issues_for_this_class=`wc -l ${issues_file} | awk -F" " '{print $1}'`
289 ccflib 1.2
290     first_issue=`head -1 ${issues_file}`
291     last_issue=`tail -1 ${issues_file}`
292    
293 ccflib 1.3 li=$((10#$last_issue))
294     fi=$((10#$first_issue))
295    
296 ccflib 1.7 sequential_number_of_issues_for_this_class=$((li - fi + 1))
297 ccflib 1.8
298     asterisk=" "
299     [ "${real_number_of_issues_for_this_class}" -lt "${sequential_number_of_issues_for_this_class}" ] && asterisk="(*)"
300    
301 ccflib 1.7 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 ccflib 1.3
305 ccflib 1.8 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 ccflib 1.7
316     echo "done"
317 ccflib 1.2 done < ${ccf_classes}
318    
319 ccflib 1.7 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 ccflib 1.3 rm ${VALID_CCF}/ccf_classes.txt
325     rm ${VALID_CCF}/ccf_issues_for*.txt
326 ccflib 1.11
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