1 |
#! /bin/csh -f |
2 |
# Script to generate or fill in HMI cosmic ray tables |
3 |
# |
4 |
# this is run in the task instance directory where there is a 'ticket' file that specifies |
5 |
# the request. |
6 |
|
7 |
# XXXXXXXXXX test |
8 |
set echo |
9 |
# XXXXXXXXXX test |
10 |
|
11 |
set HERE = $cwd |
12 |
set LOG = $HERE/runlog |
13 |
set BABBLE = $HERE/babble |
14 |
|
15 |
# post processing flag. Set to 1 for cosmic_rays to be made in su_production.cosmic_rays |
16 |
# with cosmic_ray_post program used to merge and move to hmi.cosmic_rays |
17 |
# set to 1 to enable, otherwise only hmi.cosmic_rays will be used. |
18 |
set DO_POST = 0 |
19 |
|
20 |
date > $LOG |
21 |
|
22 |
if ($?WORKFLOW_ROOT) then |
23 |
set WFDIR = $WORKFLOW_DATA |
24 |
set WFCODE = $WORKFLOW_ROOT |
25 |
else |
26 |
echo Need WORKFLOW_ROOT variable to be set. >>$LOG |
27 |
env >>$LOG |
28 |
exit 1 |
29 |
endif |
30 |
|
31 |
set wantlow = `cat wantlow` |
32 |
set wanthigh = `cat wanthigh` |
33 |
hostname >> $LOG |
34 |
date >> $LOG |
35 |
echo "wanthigh = " $wanthigh >> $LOG |
36 |
echo "wantlow = " $wantlow >> $LOG |
37 |
set ACTION = `grep ACTION ticket` |
38 |
set $ACTION |
39 |
|
40 |
set CAMERA = 0 |
41 |
|
42 |
# process SPECIAL ticket args |
43 |
set FIXMISSING = 0 |
44 |
set SPECIAL = (`grep SPECIAL ticket`) |
45 |
set $SPECIAL |
46 |
set special = (`echo $SPECIAL | sed -e 's/,/ /g'`) |
47 |
# now special contains a=b c=d |
48 |
set NSPECARGS = $#special |
49 |
set SPECARG = 1 |
50 |
while ($SPECARG <= $NSPECARGS) |
51 |
echo Extracting SPECIAL component $SPECARG which is $special[$SPECARG] |
52 |
if ($special[$SPECARG] == NONE) then |
53 |
else |
54 |
set $special[$SPECARG] |
55 |
endif |
56 |
@ SPECARG = $SPECARG + 1 |
57 |
end |
58 |
|
59 |
if ($CAMERA > 0) then |
60 |
set CAMARG = '[? CAMERA='$CAMERA' ?]' |
61 |
else |
62 |
set CAMARG |
63 |
endif |
64 |
|
65 |
# set QUALMASK = 0x2F000 |
66 |
set QUALMASK = 192512 |
67 |
|
68 |
set FFSN = `show_info hmi.lev1'['$wantlow'-'$wanthigh'][? (QUALITY & '$QUALMASK') = 0 ?]' n=1 -q key=FSN` |
69 |
set LFSN = `show_info hmi.lev1'['$wantlow'-'$wanthigh'][? (QUALITY & '$QUALMASK') = 0 ?]' n=-1 -q key=FSN` |
70 |
|
71 |
if ($LFSN <= $FFSN) then |
72 |
echo No good records to process between $wantlow and $wanthigh >>$LOG |
73 |
echo Allow OK status to let higher level code generate missing records. >>$LOG |
74 |
set retstatus = 0 |
75 |
goto FAILUREEXIT |
76 |
endif |
77 |
|
78 |
# get expected list of cosmic_ray records |
79 |
show_info hmi.lev1'[]['$FFSN'-'$LFSN'][? FID >= 10050 AND FID < 11000 ?][? (QUALITY & '$QUALMASK') = 0 ?][? T_OBS > 0 ?]'"$CAMARG" -q key=FSN > FSN_lev1 |
80 |
|
81 |
set N_NOCR = 100000000 |
82 |
# unless a SPECIAL arg of FIXMISSING=1 is present, just wait here until all records are present. I.e. convert to a proper action=3 |
83 |
if ($ACTION == 4 && $FIXMISSING == 0) then |
84 |
set loopcount = 0 |
85 |
while ($N_NOCR > 0) |
86 |
show_info hmi.cosmic_rays'[]['$FFSN'-'$LFSN'][? FID >= 10050 AND FID < 11000 ?][? T_OBS > 0 ?]'"$CAMARG" -q key=FSN > FSN_cosmic |
87 |
comm -23 FSN_lev1 FSN_cosmic > NOCR |
88 |
set N_NOCR = `wc -l <NOCR` |
89 |
echo "Lev1 records without cosmic ray records count = " $N_NOCR >>$LOG |
90 |
if ($N_NOCR < 1) exit 0 |
91 |
if ($loopcount > 576) then |
92 |
echo "FAIL - give up waiting after 4 days." >>$LOG |
93 |
echo "FAIL - give up waiting after 4 days." >>FAIL_reason |
94 |
cat N_NOCR >>FAIL_reason |
95 |
echo " " >>FAIL_reason |
96 |
set retstat = 9 |
97 |
goto FAILUREEXIT |
98 |
endif |
99 |
sleep 600 |
100 |
@ loopcount = $loopcount + 1 |
101 |
end |
102 |
endif |
103 |
|
104 |
if ($ACTION == 4) then |
105 |
show_info hmi.cosmic_rays'[]['$FFSN'-'$LFSN'][? FID >= 10050 AND FID < 11000 ?][? T_OBS > 0 ?]'"$CAMARG" -q key=FSN > FSN_cosmic |
106 |
comm -23 FSN_lev1 FSN_cosmic > NOCR |
107 |
set N_NOCR = `wc -l <NOCR` |
108 |
echo "Lev1 records without cosmic ray records count = " $N_NOCR >>$LOG |
109 |
|
110 |
if ($N_NOCR < 1) exit 0 |
111 |
|
112 |
set FIRST_FSN = `head -1 NOCR` |
113 |
set LAST_FSN = `tail -1 NOCR` |
114 |
else # ACTION == 5 |
115 |
set FIRST_FSN = $FFSN |
116 |
set LAST_FSN = $LFSN |
117 |
endif |
118 |
|
119 |
# increase range to allow preceeding and following filtergrams |
120 |
@ FIRST_FSN = $FIRST_FSN - 96 |
121 |
# set CHK_FSN1 = `show_info hmi.lev1'[? FSN = '$FIRST_FSN' ?]' n=-1 -q key=T_OBS` |
122 |
set CHK_FSN1 = `show_info hmi.lev1'[][$FIRST_FSN]' n=1 -q key=T_OBS_index` |
123 |
while ( $CHK_FSN1 < 0 ) |
124 |
# @ FIRST_FSN = $FIRST_FSN - 1 |
125 |
# set CHK_FSN1 = `show_info hmi.lev1'[? FSN = '$FIRST_FSN' ?]' n=-1 -q key=T_OBS` |
126 |
@ FIRST_FSN = $FIRST_FSN + 1 |
127 |
set CHK_FSN1 = `show_info hmi.lev1'[][$FIRST_FSN]' n=1 -q key=T_OBS_index` |
128 |
end |
129 |
|
130 |
@ LAST_FSN = $LAST_FSN + 96 |
131 |
# set CHK_FSN2 = `show_info hmi.lev1'[? FSN = '$LAST_FSN' ?]' n=-1 -q key=T_OBS` |
132 |
set CHK_FSN2 = `show_info hmi.lev1'[][$LAST_FSN]' n=1 -q key=T_OBS_index` |
133 |
while ( $CHK_FSN2 < 0 ) |
134 |
# @ LAST_FSN = $LAST_FSN + 1 |
135 |
# set CHK_FSN2 = `show_info hmi.lev1'[? FSN = '$LAST_FSN' ?]' n=-1 -q key=T_OBS` |
136 |
@ LAST_FSN = $LAST_FSN - 1 |
137 |
set CHK_FSN2 = `show_info hmi.lev1'[][$LAST_FSN]' n=1 -q key=T_OBS_index` |
138 |
end |
139 |
|
140 |
|
141 |
# get day of first FSN |
142 |
|
143 |
# note that there may be a missing T_OBS along with a good T_OBS for a given FSN |
144 |
set LFSNDAY = `show_info key=T_OBS -q hmi.lev1'[]['$LAST_FSN'][? T_OBS > 0 ?]'` |
145 |
set yyyymmdd = `printf "%.10s" $LFSNDAY` |
146 |
set mmdd = `echo $yyyymmdd | sed -e "s/.....//" -e "s/://" ` |
147 |
|
148 |
# For now assume that the list of missing CR records is contiguous, later use show_coverage key=FSN for |
149 |
# special conditions on FIDs and do only the UNKs. |
150 |
|
151 |
# Run Richard's flat field program in cosmic_rays only mode |
152 |
# modified from module_flatfield_daily_qsub_48_CRonly2_PZT_FSN.pl |
153 |
|
154 |
mkdir CRlogs |
155 |
set CRLOG = $HERE/CRlogs |
156 |
# set module_flatfield = /home/jsoc/cvs/Development/JSOC/bin/linux_x86_64/module_flatfield |
157 |
set module_flatfield = /home/jsoc/cvs/Development/JSOC/bin/linux_x86_64/module_flatfield |
158 |
set cosmic_ray_post = /home/jsoc/cvs/Development/JSOC/bin/linux_x86_64/cosmic_ray_post |
159 |
|
160 |
set QSUBCMD = CRY_$mmdd |
161 |
set QSTAT = $HERE/CRY_status |
162 |
touch $QSTAT |
163 |
cat > $QSUBCMD <<ENDCAT |
164 |
# |
165 |
#\$ -cwd |
166 |
set echo |
167 |
echo $HOST |
168 |
setenv OMP_NUM_THREADS 8 |
169 |
ENDCAT |
170 |
|
171 |
# Do these serially in a single node |
172 |
# 135, camera=1 |
173 |
set FIDLIST_1 = (10054 10055 10056 10057 10058 10059 10074 10075 10076 10077 10078 10079 \ |
174 |
10094 10095 10096 10097 10098 10099 10114 10115 10116 10117 10118 10119 \ |
175 |
10134 10135 10136 10137 10138 10139 10154 10155 10156 10157 10158 10159) |
176 |
# 45s, camera=2 |
177 |
set FIDLIST_2 = (10058 10059 10078 10079 10098 10099 10118 10119 10138 10139 10158 10159) |
178 |
|
179 |
# set ID = \$SGE_TASK_ID |
180 |
set ID = 1 |
181 |
while ($ID <= 48) |
182 |
if ($ID <= 36) then |
183 |
set ID1 = $ID |
184 |
set cadence = "135s" |
185 |
set camera = 1 |
186 |
set fid = $FIDLIST_1[$ID1] |
187 |
else |
188 |
@ ID2 = $ID - 36 |
189 |
set cadence = "45s" |
190 |
set camera = 2 |
191 |
set fid = $FIDLIST_2[$ID2] |
192 |
endif |
193 |
|
194 |
if ($DO_POST) then |
195 |
cat >>$QSUBCMD <<ENDCAT |
196 |
$module_flatfield -L input_series=hmi.lev1 cadence=$cadence cosmic_rays=1 flatfield=0 fid=$fid camera=$camera fsn_first=$FIRST_FSN fsn_last=$LAST_FSN datum=$yyyymmdd >>& $CRLOG/$ID.log |
197 |
if (\$status) echo "$ID error" >> $QSTAT |
198 |
ENDCAT |
199 |
else |
200 |
cat >>$QSUBCMD <<ENDCAT |
201 |
$module_flatfield -L input_series=hmi.lev1 cosmic_ray_series=hmi.cosmic_rays cadence=$cadence cosmic_rays=1 flatfield=0 fid=$fid camera=$camera fsn_first=$FIRST_FSN fsn_last=$LAST_FSN datum=$yyyymmdd >>& $CRLOG/$ID.log |
202 |
if (\$status) echo "$ID error" >> $QSTAT |
203 |
ENDCAT |
204 |
endif |
205 |
|
206 |
@ ID = $ID + 1 |
207 |
end |
208 |
|
209 |
# qsub -q j.q -o $LOG -e $LOG -t 1-48 -sync yes $QSUBCMD |
210 |
qsub -q j8.q -o $LOG -e $LOG -sync yes $QSUBCMD |
211 |
# qsub -q p8.q -o $LOG -e $LOG -sync yes $QSUBCMD |
212 |
set QSUBSTATUS = $status |
213 |
if ($QSUBSTATUS) then |
214 |
echo qsub failed with exit status $QSUBSTATUS >>$LOG |
215 |
set retstatus = 11 |
216 |
echo qsub failure >>$FAIL_REASON |
217 |
goto FAILUREEXIT |
218 |
endif |
219 |
|
220 |
set QSTAT_errcnt = `wc -l < $QSTAT` |
221 |
if ($QSTAT_errcnt) then |
222 |
echo $QSTAT_errcnt " status errors in module_flatfield" >>$LOG |
223 |
echo $QSTAT_errcnt " status errors in module_flatfield" >>$FAIL_reason |
224 |
set retstatus = 7 |
225 |
goto FAILUREEXIT |
226 |
endif |
227 |
|
228 |
if ($DO_POST) then |
229 |
# Now do the post processing |
230 |
set QSUBCMD = POS_$mmdd |
231 |
set QSTAT = $HERE/POS_status |
232 |
touch $QSTAT |
233 |
cat > $QSUBCMD <<ENDCAT |
234 |
# |
235 |
set echo |
236 |
setenv OMP_NUM_THREADS 1 |
237 |
$cosmic_ray_post -L input_series=su_production.cosmic_rays fsn_first=$FIRST_FSN fsn_last=$LAST_FSN camera=1 >>& $CRLOG/post.log |
238 |
if (\$status) echo "Cam1 error" >> $QSTAT |
239 |
$cosmic_ray_post -L input_series=su_production.cosmic_rays fsn_first=$FIRST_FSN fsn_last=$LAST_FSN camera=2 >>& $CRLOG/post.log |
240 |
if (\$status) echo "Cam2 error" >> $QSTAT |
241 |
ENDCAT |
242 |
|
243 |
qsub -q j.q -o $LOG -e $LOG -sync yes $QSUBCMD |
244 |
|
245 |
set QSTAT_errcnt = `wc -l < $QSTAT` |
246 |
if ($QSTAT_errcnt) then |
247 |
echo $QSTAT_errcnt " status errors in cosmic_ray_post" >>$LOG |
248 |
echo $QSTAT_errcnt " status errors in cosmic_ray_post" >>$FAIL_reason |
249 |
set retstatus = 7 |
250 |
goto FAILUREEXIT |
251 |
endif |
252 |
|
253 |
endif # DO_POST |
254 |
|
255 |
# verify make of cosmic ray records |
256 |
|
257 |
show_info hmi.cosmic_rays'[]['$FFSN'-'$LFSN'][? FID >= 10050 AND FID < 11000 ?][? T_OBS > 0 ?]'"$CAMARG" -q key=FSN > FSN_cosmic |
258 |
comm -23 FSN_lev1 FSN_cosmic > NOCR |
259 |
set N_NOCR = `wc -l <NOCR` |
260 |
echo "Lev1 records now without cosmic ray records count = " $N_NOCR >>$LOG |
261 |
|
262 |
if ($N_NOCR > 10) then |
263 |
echo "$N_NOCR lev1 records are still missing matching cosmic_ray records. " >>FAIL_reason |
264 |
echo "The missing cosmic_ray records are FSNs: ">>FAIL_reason |
265 |
cat NOCR >>FAIL_reason |
266 |
echo " " >>FAIL_reason |
267 |
set retstatus = 3 |
268 |
goto FAILUREEXIT |
269 |
endif |
270 |
|
271 |
exit 0 |
272 |
|
273 |
FAILUREEXIT: |
274 |
|
275 |
echo "No CR records available" >>$LOG |
276 |
exit $retstatus |