/[CCFs]/bin/mlovccf
ViewVC logotype

Annotation of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide 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 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.12 # $Id: mlovccf,v 1.11 2016/03/23 09:31:49 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 ccflib 1.12 echo "Error: ${VALID_CCF}/${validccflist} not found - Abort!"
114 ccflib 1.11 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 ccflib 1.12 n=0
122 ccflib 1.11 while read ccf
123     do
124 ccflib 1.12 n=$((n + 1))
125     echo "$n cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/"
126 ccflib 1.11 cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/
127 ccflib 1.12 done < ${VALID_CCF}/${validccflist}
128 ccflib 1.11
129     }
130    
131    
132 ccflib 1.10 # Get the list of all ODFs
133 ccflib 1.1
134 ccflib 1.10 xsaobslogsize="0"
135 ccflib 1.1
136 ccflib 1.10 getxsaobslog
137 ccflib 1.1
138 ccflib 1.10 xsaobslogsize=`stat --format=%s ${VALID_CCF}/xsaobslog_${now}.txt`
139 ccflib 1.1
140 ccflib 1.10 if [ "$xsaobslogsize" = "0" ] ; then
141     echo "Error: Failure to download the XSA Obs. Log file - Abort"
142     exit
143     fi
144 ccflib 1.1
145     # Sets SAS_CCFPATH and initialises HEADAS and SAS depending on host
146    
147     case "$host" in
148     xvsoc01|xmm)
149 ccflib 1.5 export SAS_CCFPATH="/data/xmm/ccflib/ftp-area/constituents"
150     export SAS_DIR=/data/xmm/ccflib/sas
151     export SAS_PATH=$SAS_DIR
152 ccflib 1.1 source $SAS_DIR/sas-setup.sh
153     ;;
154     sasbld01|sasbld02)
155 ccflib 1.5 export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
156 ccflib 1.1 /sas/bin/confsas
157     export HEADAS=/sasbuild/local/${host}/headas/architecture
158     . $HEADAS/headas-init.sh
159 ccflib 1.7 # 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 ccflib 1.1 source $HOME/setsas.sh 1> /dev/null
165 ccflib 1.7 echo "SAS Version: "
166     sasversion -V 1
167 ccflib 1.1 export SAS_VERBOSITY=0
168     ;;
169 ccflib 1.5 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 ccflib 1.7 # 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 ccflib 1.5 source $HOME/setsas.sh 1> /dev/null
180 ccflib 1.7 echo "SAS Version: "
181     sasversion -V 1
182 ccflib 1.5 export SAS_VERBOSITY=0
183     ;;
184     *) echo "Error: Do not know how to do it in host $host" ; exit ;;
185 ccflib 1.1 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 ccflib 1.2 # Output file
196 ccflib 1.3 touch ${VALID_CCF}/all_ccfs_${now}.txt
197 ccflib 1.2
198 ccflib 1.1 n=0
199 ccflib 1.2
200 ccflib 1.1 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 ccflib 1.2
232 ccflib 1.1 done < ${VALID_CCF}/${obsid}_ccfs.tmp
233    
234     rm ${VALID_CCF}/${obsid}_ccfs.tmp
235    
236 ccflib 1.3 mv ${VALID_CCF}/all_ccfs_${now}.txt ${VALID_CCF}/all_ccfs_${now}.tmp
237 ccflib 1.2
238 ccflib 1.3 cat ${VALID_CCF}/${obsid}_ccfs.txt ${VALID_CCF}/all_ccfs_${now}.tmp | sort -u > ${VALID_CCF}/all_ccfs_${now}.txt
239 ccflib 1.1
240     rm ${cif_file}
241     rm ${VALID_CCF}/${obsid}_ccfs.txt
242 ccflib 1.3 rm ${VALID_CCF}/all_ccfs_${now}.tmp
243 ccflib 1.1
244 ccflib 1.7 done < ${VALID_CCF}/xsaobslog_${now}.txt
245 ccflib 1.2
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 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
257 ccflib 1.2
258     cat ${ccf_classes} | sort -u > ${VALID_CCF}/kk.txt
259     mv ${VALID_CCF}/kk.txt ${ccf_classes}
260    
261 ccflib 1.3 # Output final file is named all_ccfs_${now}_table.txt
262    
263     total_number_of_ccfs=0
264 ccflib 1.2
265 ccflib 1.7 all_ccfs_table="${VALID_CCF}/all_ccfs_${now}_table.txt"
266 ccflib 1.2
267     [ -f "${all_ccfs_table}" ] && rm ${all_ccfs_table}
268    
269 ccflib 1.7 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 ccflib 1.2
275     while read ccf_class
276 ccflib 1.3 do
277     echo -n "Processing class $ccf_class ..."
278 ccflib 1.2 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 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
287 ccflib 1.2
288     cat ${issues_file} | sort -u > kk.txt
289     mv kk.txt ${issues_file}
290 ccflib 1.3 real_number_of_issues_for_this_class=`wc -l ${issues_file} | awk -F" " '{print $1}'`
291 ccflib 1.2
292     first_issue=`head -1 ${issues_file}`
293     last_issue=`tail -1 ${issues_file}`
294    
295 ccflib 1.3 li=$((10#$last_issue))
296     fi=$((10#$first_issue))
297    
298 ccflib 1.7 sequential_number_of_issues_for_this_class=$((li - fi + 1))
299 ccflib 1.8
300     asterisk=" "
301     [ "${real_number_of_issues_for_this_class}" -lt "${sequential_number_of_issues_for_this_class}" ] && asterisk="(*)"
302    
303 ccflib 1.7 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 ccflib 1.3
307 ccflib 1.8 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 ccflib 1.7
318     echo "done"
319 ccflib 1.2 done < ${ccf_classes}
320    
321 ccflib 1.7 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 ccflib 1.3 rm ${VALID_CCF}/ccf_classes.txt
327     rm ${VALID_CCF}/ccf_issues_for*.txt
328 ccflib 1.11
329     # Fill in the Valid CCF Set dir with the proper CCFs
330    
331 ccflib 1.12 fillvalidccfdir "all_ccfs_${now}.txt"

  ViewVC Help
Powered by ViewVC 1.1.27