/[CCFs]/bin/mlovccf
ViewVC logotype

Contents of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Tue Mar 10 13:27:33 2015 UTC (9 years, 8 months ago) by ccflib
Branch: MAIN
Changes since 1.1: +77 -13 lines
Added code to produce a Table of the rages of valid CCFs as it is doen for the Pipeline Release Notes

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

  ViewVC Help
Powered by ViewVC 1.1.27