/[CCFs]/bin/mlovccf
ViewVC logotype

Contents of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Wed Mar 11 16:12:16 2015 UTC (9 years, 8 months ago) by ccflib
Branch: MAIN
Changes since 1.4: +17 -6 lines
Added support to run on scigrid6 and cn execution hosts in SciGrid

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

  ViewVC Help
Powered by ViewVC 1.1.27