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