/[CCFs]/bin/mlovccf
ViewVC logotype

Annotation of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Tue Mar 10 17:00:47 2015 UTC (9 years, 8 months ago) by ccflib
Branch: MAIN
Changes since 1.3: +5 -1 lines
Include lines to run it on the grid

1 ccflib 1.1 #! /bin/bash
2    
3     # mlovccf (make list of valid ccfs)
4     #
5 ccflib 1.2 # Makes the list of valid CCFs that 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. Thus, 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 ccflib 1.1 #
10 ccflib 1.2 # To identify the set of CCFs required to process a given ODF is the task of cifbuild.
11     # To make such identification, cifbuild needs only the start time of the observation.
12 ccflib 1.1 #
13 ccflib 1.2 # If we get the list of required CCFs for all observed ODFs at a given date,
14     # we will obtain for such a moment, the list of valid CCFs required to process
15     # any observed ODF. Thus, we need as input the list of all observed ODFs at a given
16     # date. This is obtained from the report of all observations that the XSA makes to CDS,
17     # xsaobslog.txt (ftp://nxsa.esac.esa.int/pub/cfs_obslog/xsaobslog.txt).
18     #
19 ccflib 1.4 # $Id: mlovccf,v 1.3 2015/03/10 16:51:28 ccflib Exp $
20    
21     # Next two lines allow to submit this script to the grid
22     # request Bourne shell as shell for job
23     #$ -S /bin/sh
24 ccflib 1.1
25     host=`hostname | cut -d. -f1`
26    
27 ccflib 1.3 now=`date +'%Y-%M-%dT%H:%M:%S'`
28    
29 ccflib 1.1 # Function find_latest_mif to get the latest XMM_CALINDEX from given directory
30    
31     find_latest_mif()
32     {
33    
34     [ -z "$1" ] && return
35    
36     CCFPATH="$1"
37    
38     maxissue="0"
39     for mif in `ls -1 ${CCFPATH}/XMM_CALINDEX_*.CCF`
40     do
41     mifbase=`basename $mif`
42     issue=`echo $mifbase | awk -F"." '{print $1}' | awk -F"_" '{print $3}'`
43     [ "$issue" -ge "$maxissue" ] && maxissue="$issue"
44     done
45    
46     MIF=${CCFPATH}/XMM_CALINDEX_${maxissue}.CCF
47    
48     }
49    
50 ccflib 1.2 # Function get_ccf_list to list on stdout the table of CCFs in a given CIF
51 ccflib 1.1 #
52 ccflib 1.2 # Requires that Heasoft is initialised. Otherwise exits with error.
53 ccflib 1.1
54     get_ccf_list()
55     {
56     [ -z "$1" ] && return
57    
58     cif_to_process="$1"
59    
60     noversion=`which fversion | grep -c no`
61    
62     if [ "${noversion}" != "0" ] ; then
63     echo "Error: Heasoft not initialised !"
64     exit
65     fi
66    
67     fdump ${cif_to_process} prhead=no showcol=no showrow=no page=no \
68     columns="SCOPE TYPEID ISSUE" \
69     rows=- STDOUT
70     }
71    
72    
73 ccflib 1.2 # We need to get the list of all observed ODFs at the current date.
74     # This is obtained from ftp://nxsa.esac.esa.int/pub/cds_obslog/xsaobslog.txt.
75 ccflib 1.1
76     VALID_CCF="$HOME/valid_ccf"
77    
78     cd ${VALID_CCF}
79     wget -nc -q ftp://nxsa.esac.esa.int/pub/cds_obslog/xsaobslog.txt
80    
81    
82     # Sets SAS_CCFPATH and initialises HEADAS and SAS depending on host
83    
84     case "$host" in
85     xvsoc01|xmm)
86     SAS_CCFPATH="/data/xmm/ccflib/ftp-area/constituents"
87     SAS_DIR=/data/xmm/ccflib/sas
88     SAS_PATH=$SAS_DIR
89     source $SAS_DIR/sas-setup.sh
90     ;;
91     sasbld01|sasbld02)
92     SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
93     /sas/bin/confsas
94     export HEADAS=/sasbuild/local/${host}/headas/architecture
95     . $HEADAS/headas-init.sh
96     source $HOME/setsas.sh 1> /dev/null
97     export SAS_VERBOSITY=0
98     ;;
99     esac
100    
101     # Finds the latest MIF issue
102    
103     find_latest_mif "${SAS_CCFPATH}"
104    
105    
106     # Now scans the list of OBDS ID registered in the previous list to get the start time
107     # and then runs cifbuild to get the respective CIF
108    
109 ccflib 1.2 # Output file
110 ccflib 1.3 touch ${VALID_CCF}/all_ccfs_${now}.txt
111 ccflib 1.2
112 ccflib 1.1 n=0
113 ccflib 1.2
114 ccflib 1.1 while read line
115     do
116     obsid=`echo $line | awk -F"|" '{print $2}'`
117     stime=`echo $line | awk -F"|" '{print $9}'`
118     stime=`echo $stime | tr " " "T"`
119     n=$((n+1))
120     echo "($n) Processing $obsid $stime" ; echo
121    
122     # Run cifbuild
123    
124     cif_file=${VALID_CCF}/${obsid}.cif
125    
126     cifbuild --withmasterindexset='yes' \
127     --masterindexset=${MIF} \
128     --withobservationdate='yes' \
129     --observationdate=${stime} \
130     --analysisdate='now' \
131     --calindexset=${cif_file}
132    
133    
134     # Gets the list of CCFs included in the CIF
135    
136     get_ccf_list "${cif_file}" > ${VALID_CCF}/${obsid}_ccfs.tmp
137    
138     while read line
139     do
140     [ "$line" = "" ] && continue
141     class=`echo $line | awk -F" " '{print $1"_"$2}'`
142     issue=`echo $line | awk -F" " '{print $3}'`
143     issue=`printf "%04d" ${issue}`
144     echo ${class}_${issue}.CCF >> ${VALID_CCF}/${obsid}_ccfs.txt
145 ccflib 1.2
146 ccflib 1.1 done < ${VALID_CCF}/${obsid}_ccfs.tmp
147    
148     rm ${VALID_CCF}/${obsid}_ccfs.tmp
149    
150 ccflib 1.3 mv ${VALID_CCF}/all_ccfs_${now}.txt ${VALID_CCF}/all_ccfs_${now}.tmp
151 ccflib 1.2
152 ccflib 1.3 cat ${VALID_CCF}/${obsid}_ccfs.txt ${VALID_CCF}/all_ccfs_${now}.tmp | sort -u > ${VALID_CCF}/all_ccfs_${now}.txt
153 ccflib 1.1
154     rm ${cif_file}
155     rm ${VALID_CCF}/${obsid}_ccfs.txt
156 ccflib 1.3 rm ${VALID_CCF}/all_ccfs_${now}.tmp
157 ccflib 1.1
158     done < ${VALID_CCF}/xsaobslog.txt
159 ccflib 1.2
160     # Make a table of classes and issues type "Pipeline Release Notes"
161    
162     # Lists all CCF classes
163    
164     ccf_classes="${VALID_CCF}/ccf_classes.txt"
165    
166     while read line
167     do
168     class=`echo $line | awk -F"_" '{print $1"_"$2}'`
169     echo $class >> ${ccf_classes}
170 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
171 ccflib 1.2
172     cat ${ccf_classes} | sort -u > ${VALID_CCF}/kk.txt
173     mv ${VALID_CCF}/kk.txt ${ccf_classes}
174    
175 ccflib 1.3 # Output final file is named all_ccfs_${now}_table.txt
176    
177     total_number_of_ccfs=0
178 ccflib 1.2
179 ccflib 1.3 all_ccfs_table="{VALID_CCF}/all_ccfs_${now}_table.txt
180 ccflib 1.2
181     [ -f "${all_ccfs_table}" ] && rm ${all_ccfs_table}
182    
183 ccflib 1.3 echo "Table of valid CCFs at $now" >> ${all_ccfs_table}
184     echo >> ${all_ccfs_table}
185 ccflib 1.2 echo "|================================|=============|" >> ${all_ccfs_table}
186     echo "| Calibration File | Issue range |" >> ${all_ccfs_table}
187     echo "|================================|=============|" >> ${all_ccfs_table}
188    
189     while read ccf_class
190 ccflib 1.3 do
191     echo -n "Processing class $ccf_class ..."
192 ccflib 1.2 issues_file="${VALID_CCF}/ccf_issues_for_${ccf_class}.txt"
193     [ -f "${issues_file}" ] && rm ${issues_file}
194     while read line
195     do
196     class=`echo $line | awk -F"_" '{print $1"_"$2}'`
197     [ "$class" != "$ccf_class" ] && continue
198     issue=`echo $line | awk -F"_" '{print $3}' | cut -d. -f1`
199     echo $issue >> ${issues_file}
200 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
201 ccflib 1.2
202     cat ${issues_file} | sort -u > kk.txt
203     mv kk.txt ${issues_file}
204 ccflib 1.3 real_number_of_issues_for_this_class=`wc -l ${issues_file} | awk -F" " '{print $1}'`
205 ccflib 1.2
206     first_issue=`head -1 ${issues_file}`
207     last_issue=`tail -1 ${issues_file}`
208    
209 ccflib 1.3 li=$((10#$last_issue))
210     fi=$((10#$first_issue))
211    
212     sequential_number_of_issues_for_this_class=$(($li - $fi + 1))
213     if [ "${real_number_of_issues_for_this_class}" -lt "${sequential_number_of_issues_for_this_class}" ] ; then
214     asterisk="(*)"
215     else
216     asterisk=" "
217     fi
218     total_number_of_ccfs=$(($real_number_of_issues_for_this_class + $total_number_of_ccfs))
219    
220 ccflib 1.2 if [ "${first_issue}" != "${last_issue}" ] ; then
221 ccflib 1.3 printf "| %-30s | %4s-%4s%3s|\n" ${ccf_class} ${first_issue} ${last_issue} ${asterisk} >> ${all_ccfs_table}
222 ccflib 1.2 else
223 ccflib 1.3 printf "| %-30s | %4s |\n" ${ccf_class} ${first_issue} >> ${all_ccfs_table}
224 ccflib 1.2 fi
225    
226     done < ${ccf_classes}
227    
228 ccflib 1.3 echo "|================================|=============|" >> ${all_ccfs_table}
229     echo >> ${all_ccfs_table}
230     echo "(*): Some issues in the range are not required." >> ${all_ccfs_table}
231     rm ${VALID_CCF}/ccf_classes.txt
232     rm ${VALID_CCF}/ccf_issues_for*.txt
233    
234    
235    
236     echo ; echo "Number of valid CCFs required as of $now : ${total_number_of_ccfs}"

  ViewVC Help
Powered by ViewVC 1.1.27