-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacis-P3-fluence.pl
executable file
·796 lines (644 loc) · 25.6 KB
/
acis-P3-fluence.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
#!/usr/bin/perl
# ACIS particle fluence warning system for Chandra (based on ACE data)
# Created By Shanil Virani
# April 29, 2000
#
# Script updated by: Gregg Germain
# update: 16 March, 2011
# update: Move to han; major change to create one set of files for
# our real time web pages.
# Uses "getpath()" to select the path roof for all
# input and output files
#
# Update: Gregg Germain
# December 2012
# Modified to work under 64 bit Linux
#
#
# Update: Gregg Germain
# February 2016
# DSN summary file moved by MTA from
# /proj/rac/ops/ephem/dsn_summary.dat
#
# to
#
# /home/mta/Snap/DSN.schedule
#
#
# Update: Gregg Germain
# October 1, 2018
# Point to the DSN summary file located in
#
# /export/acis-flight/UTILITIES/DSN_summary.dat
#
#
# Update: Gregg Germain
# July 9, 2019
# Added Jack Steiner
# Updated Dick Edgar's entries
# Created the email and phone lists for easier maintenance
#
# Update: April 29, 2023
# Gregg Germain
# - Added Jim Francis to the alert list
# - Added OpsGenie as an emailing method
# - Fixed typos in comments
# - added -T switch to allow testing with lower limit thresholds.
#
################################################################################
use Fcntl qw(:DEFAULT :flock);
use Sys::Hostname;
use Getopt::Std;
use Getopt::Long;
# initialize test flag to False or No.
$test_flag = 0;
# Get any command line options
GetOptions( 't' => \$test_flag); # Test flag to indicate program should use test values
# If this is not a test run, set the values for fluence limit and bogus P3 delta limit to
# their production values
if ($test_flag == 0)
{
$flim = 1e9; # Fluence alert limit
$bogus_p3_delta_limit = 1.0e+05; # Production bogus delta value
}
else # Otherwise use the values for testing
{
$flim = 1.0;
$bogus_p3_delta_limit = 1.0;
}
# Get local machine name - up case it
$host = uc(hostname() );
# Set the base path
$pathroot = "/export/acis-flight/FLU-MON/";
$fluence_file = $pathroot."ACE-flux.dat";
$acisflux_file = $pathroot."ACIS-FLUENCE.dat";
$alert_file = $pathroot."falert.dat";
$fluence_archive = $pathroot."ACIS-fluence.arc";
$ACE_fluence_archive = $pathroot."ACE-fluence.arc";
$ephem_file = $pathroot."gephem.dat";
$focalplane_file = $pathroot."FPHIST-2001.dat";
$gratings_file = $pathroot."GRATHIST-2001.dat";
#$DSNsched_file = '/proj/rac/ops/ephem/dsn_summary.dat';
#$DSNsched_file = '/home/mta/Snap/DSN.schedule';
$DSNsched_file = '/export/acis-flight/UTILITIES/DSN_summary.dat';
$direction_file = $pathroot."cxodirect.dat";
$direction_file_out = $pathroot."$TestPathOut/cxodirect.dat";
$acisflux_file_out = $pathroot."$TestPathOut/ACIS-FLUENCE.dat";
$alert_file_out = $pathroot."$TestPathOut/falert.dat";
$fluence_archive_out = $pathroot."$TestPathOut/ACIS-fluence.arc";
$ACE_fluence_archive_out = $pathroot."$TestPathOut/ACE-fluence.arc";
$sampl = 300; # ACE sample time (seconds)
$writebit = 0; # flag to write to archive and rollover counters
#-----------------------------------------------------------------
# read the Chandra altitude direction file: cxodirect.dat
#-----------------------------------------------------------------
open (CXOA, $direction_file) or die "No CXO altitude information found in $direction_file!\n";
while ($altdir = <CXOA>) {
$cxoaltdir = $altdir;
}
close(CXOA);
chomp($cxoaltdir);
#
# read the ephemeris file: gephem.dat
#
open (EF, $ephem_file) or die "Ephemeris file $ephem_file not found!\n";
@e = split ' ',<EF>;
die "No ephemeris data found in $ephem_file\n" if (!@e or $#e < 5);
$r = $e[0];
$direct = $e[1];
#
# read the fluence file: ACE-flux.dat - get new E and P fluxes
#
open(FNAME, $fluence_file);
$histind = 0;
while ($line = <FNAME>) {
push (@histcount,$line);
$histind = $histind + 1;
}
close(FNAME);
@words= split ' ', $histcount[-3];
@words2= split ' ', $histcount[-1];
# Assign ACE electron and proton fluxes
# Electrons 38-53 175-315
$E1f=$words[7];
$E2f=$words[8];
# Protons 47-68 115-195 310-580 795-1193 1060-1900
$P1f=$words[10]; # REALLY P2
$P2f=$words[11]; # REALLY P3
$P3f=$words[12]; # REALLY P5
$P4f=$words[13]; # REALLY Fp6p
$P5f=$words[14]; # REALLY P7
# Concatenate Time of Flux Measurement
$currenttime = `date +"%Y:%j:%T:%Z"`;
@tfields = split(":",$currenttime);
if ($tfields[5] =~ "EDT") {
$tzone=4;
} elsif ($tfields[5] =~ "EST") {
$tzone=5;
} else {
$tzone=4;
print "Could not determine time zone information from date.\n";
}
$currentDECDOY = $tfields[0] + ($tfields[1] + ($tfields[2]+$tzone)/24 + $tfields
[3]/1440+ $tfields[4]/86400)/1000;
#-----------------------------------------------------------------
# Open the focal plane file: FPHIST-2001.dat
#-----------------------------------------------------------------
$fpindex = 0;
open (FPHIST, $focalplane_file) or die "Focal plane history file $focalplane_file not found!\n";
flock(FPHIST,LOCK_SH) || die "Error: Cannot get a shared lock on $focalplane_file\n";
while ($fpline = <FPHIST>) {
@fpcount = split '\t', $fpline;
@fpdecyr = split(":",$fpcount[0]);
$fpdecyear = $fpdecyr[0] + ($fpdecyr[1] + $fpdecyr[2]/24 + $fpdecyr[3]/1440 + $fpdecyr[4]/86400)/1000;
push (@fptime,$fpdecyear);
push (@fpinst,$fpcount[1]);
if ($fpindex > 0) {
if ($currentDECDOY <= $fptime[$fpindex] && $currentDECDOY >= $fptime[$fpindex-1]) {
$currentfpinst = $fpinst[$fpindex-1];
last;
} elsif ($currentDECDOY < $fptime[0]) {
print "Unable to determine current FPINST at beginning of FPINST file.\n";
last;
}
}
$fpindex = $fpindex + 1;
}
close (FPHIST);#releases the lock
if ($currentfpinst eq "") {
print "Unable to determine current FPINST at $currentDECDOY.\n";
}
$fpinfactor=1;
$fooyear=int($fptime[$fpindex]);
$decday=($fptime[$fpindex]-$fooyear)*1000;
$fooday=int($decday);
$dechour=($decday-$fooday)*24;
$foohour=int($dechour);
$foomin=int(($dechour-$foohour)*60);
$foosec=(($dechour-$foohour)*60 - $foomin)*60;
$foosec=sprintf("%6.3f",$foosec);
$simtime=sprintf("%4d:%3d:%2.2d:%2.2d:%6.3f",$fooyear,$fooday,$foohour,$foomin,$foosec);
# set flux factor based upon instrument
if ($fpinst[$fpindex-1] =~ "ACIS-S") {
$fpinfactor=1;
} elsif ($fpinst[$fpindex-1] =~ "ACIS-I") {
$fpinfactor=1;
} elsif ($fpinst[$fpindex-1] =~ "HRC-I") {
$fpinfactor=0;
} elsif ($fpinst[$fpindex-1] =~ "HRC-S") {
$fpinfactor=0;
} else {
$fpinfactor=1;
print "FP instrument was not found in $focalplane_file\n";
}
#-----------------------------------------------------------------
# Open the gratings file: GRATHIST-2001.dat
# -----------------------------------------------------------------
$grindex = 0;
open (GRATHIST, $gratings_file) or die "Gratings history file $gratings_file not found!\n";
flock(GRATHIST,LOCK_SH) || die "Error: Cannot get a shared lock on $gratings_file\n";
while ($grline = <GRATHIST>) {
@grcount = split '\t', $grline;
@grdecyr = split(":",$grcount[0]);
$grdecyear = $grdecyr[0] + ($grdecyr[1] + $grdecyr[2]/24 + $grdecyr[3]/1440 + $grdecyr[4]/86400)/1000;
push (@grtime,$grdecyear);
push (@hetg,$grcount[1]);
push (@letg,$grcount[2]);
if ($grindex > 0) {
if ($currentDECDOY <= $grtime[$grindex] && $currentDECDOY >= $grtime[$grindex-1]) {
$currenthetgstat = $hetg[$grindex-1];
$currentletgstat = $letg[$grindex-1];
last;
} elsif ($currentDECDOY < $grtime[0]) {
print "Unable to determine current GRAT STATUS at beginning of GRATHIST file.\n";
last;
}
}
$grindex = $grindex + 1;
}
close (GRATHIST);#releases the lock
if ($currentletgstat eq "") {
print "Unable to determine current LETG STAT at $currentDECDOY.\n";
}
if ($currenthetgstat eq "") {
print "Unable to determine current HETG STAT at $currentDECDOY.\n";
}
# Set grating factors based upon which (if any) grating is in
$gratfactor=1;
if ($hetg[$grindex-1] =~ "HETG-IN") {
$gratfactor=1/5;
} elsif ($hetg[$grindex-1] =~ "HETG-OUT") {
$gratfactor=1;
} else {
$gratfactor=1;
print "HETG Gratings status was not found in $gratings_file\n";
}
$gratfactor2=1;
if ($letg[$grindex-1] =~ "LETG-IN") {
$gratfactor2=1/2;
} elsif ($letg[$grindex-1] =~ "LETG-OUT") {
$gratfactor2=1;
} else {
$gratfactor2=1;
print "LETG Gratings status was not found in $gratings_file\n";
}
#----------------------------------------------------------------------------
# Open ACIS orbital fluence file to get OLD fluence history: ACIS-FLUENCE.dat
#----------------------------------------------------------------------------
open (ACISFLUX, $acisflux_file) or die "ACIS fluence orbit history file $acisflux_file not found!\n";
$fluxind = 0;
while ($line = <ACISFLUX>) {
push (@fluxcount,$line);
$histind = $fluxind + 1;
}
close(ACISFLUX);
# Assign PREVIOUS ACIS electron and proton fluences
@acisfluxdata = split ' ', $fluxcount[-1];
$OLDACISE1F=$acisfluxdata[6];
$OLDACISE2F=$acisfluxdata[7];
$OLDACISP1F=$acisfluxdata[8];
$OLDACISP2F=$acisfluxdata[9];
$OLDACISP3F=$acisfluxdata[10];
$OLDACISP4F=$acisfluxdata[11];
$OLDACISP5F=$acisfluxdata[12];
$NEWINTTIME=$acisfluxdata[13] + $sampl;
# Now get the PREVIOUS (OLD) ACIS electron and proton FLUX
@oldacisflux = split ' ', $fluxcount[-3];
$OLDACISFLUXE1F=$oldacisflux[7]; # E 38-53 DE1
$OLDACISFLUXE2F=$oldacisflux[8]; # E 175-315 DE4
$OLDACISFLUXP1F=$oldacisflux[10]; # P 47-68 P2
$OLDACISFLUXP2F=$oldacisflux[11]; # P 115-195 P3
$OLDACISFLUXP3F=$oldacisflux[12]; # P 310-580 P5
$OLDACISFLUXP4F=$oldacisflux[13]; # P 795-1193 FP6p
$OLDACISFLUXP5F=$oldacisflux[14]; # P 1060-1900 P7
#
# Set values for a test
#
# Ok now you have both the old values and new FLUX values. Compare
# them and look for any bogus jumps
#TTTTTTTTTTTTTTTTTTTTTTTt
#print "\nNEW P3 value: $P2f";
#print "\nOLD P3 value: $OLDACISFLUXP2F";
$bogus_p3_flag = 0;
$bogus_p3_delta = abs($P2f - $OLDACISFLUXP2F);
if( $bogus_p3_delta >= $bogus_p3_delta_limit)
{
$bogus_p3_new = $P2f;
# Use the old flux value BUT back out the gratings and FP effects
# because they will be re-introduced downstream
$bogus_p3_old = ($OLDACISFLUXP2F/$gratfactor/$gratfactor2)*$fpinfactor;
$bogus_p3_flag = 1;
# restore the P3 (P2f) value to the old value so that
# the new one is not used.
# restore the P3 (P2f) value to the old value so that
# the new one is not used.
$P2f = ($OLDACISFLUXP2F/$gratfactor/$gratfactor2)*$fpinfactor;
}
#--------------------------------------------------------------
#
# Now calculate the fluence values.
#
#--------------------------------------------------------------
if ($cxoaltdir eq "A" && $direct eq "A") {
# print "CXO is currently ascending\n";
# print "cxoaltdir = $cxoaltdir AND direct = $direct\n";
# Calculate NEW ACIS flux based on latest ACE measurement.
$ACISE1f=$E1f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISE2f=$E2f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP1f=$P1f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP2f=$P2f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP3f=$P3f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP4f=$P4f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP5f=$P5f*$gratfactor*$gratfactor2*$fpinfactor;
#
# Calculate new ACIS fluence: previous ACIS fluence value + new ACIS flux measurement * ACE sample time
#
$TOTALACISE1F = $ACISE1f * $sampl + $OLDACISE1F;
$TOTALACISE2F = $ACISE2f * $sampl + $OLDACISE2F;
$TOTALACISP1F = $ACISP1f * $sampl + $OLDACISP1F;
$TOTALACISP2F = $ACISP2f * $sampl + $OLDACISP2F;
$TOTALACISP3F = $ACISP3f * $sampl + $OLDACISP3F;
$TOTALACISP4F = $ACISP4f * $sampl + $OLDACISP4F;
$TOTALACISP5F = $ACISP5f * $sampl + $OLDACISP5F;
} elsif ($cxoaltdir eq "A" && $direct eq "D") {
# print "CXO has just transistioned from A to D\n";
# print "cxoaltdir = $cxoaltdir AND direct = $direct\n";
# Calculate NEW ACIS flux based on latest ACE measurement.
$ACISE1f=$E1f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISE2f=$E2f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP1f=$P1f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP2f=$P2f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP3f=$P3f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP4f=$P4f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP5f=$P5f*$gratfactor*$gratfactor2*$fpinfactor;
#
# Calculate new ACIS fluence: previous ACIS fluence value + new ACIS flux measurement * ACE sample time
#
$TOTALACISE1F = $ACISE1f * $sampl + $OLDACISE1F;
$TOTALACISE2F = $ACISE2f * $sampl + $OLDACISE2F;
$TOTALACISP1F = $ACISP1f * $sampl + $OLDACISP1F;
$TOTALACISP2F = $ACISP2f * $sampl + $OLDACISP2F;
$TOTALACISP3F = $ACISP3f * $sampl + $OLDACISP3F;
$TOTALACISP4F = $ACISP4f * $sampl + $OLDACISP4F;
$TOTALACISP5F = $ACISP5f * $sampl + $OLDACISP5F;
} elsif ($cxoaltdir eq "D" && $direct eq "D") {
# print "CXO is currently in its descent leg\n";
# print "cxoaltdir = $cxoaltdir AND direct = $direct\n";
# Calculate NEW ACIS flux based on latest ACE measurement.
$ACISE1f=$E1f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISE2f=$E2f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP1f=$P1f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP2f=$P2f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP3f=$P3f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP4f=$P4f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP5f=$P5f*$gratfactor*$gratfactor2*$fpinfactor;
#
# Calculate new ACIS fluence: previous ACIS fluence value + new ACIS flux measurement * ACE sample time
#
$TOTALACISE1F = $ACISE1f * $sampl + $OLDACISE1F;
$TOTALACISE2F = $ACISE2f * $sampl + $OLDACISE2F;
$TOTALACISP1F = $ACISP1f * $sampl + $OLDACISP1F;
$TOTALACISP2F = $ACISP2f * $sampl + $OLDACISP2F;
$TOTALACISP3F = $ACISP3f * $sampl + $OLDACISP3F;
$TOTALACISP4F = $ACISP4f * $sampl + $OLDACISP4F;
$TOTALACISP5F = $ACISP5f * $sampl + $OLDACISP5F;
} elsif ($cxoaltdir eq "D" && $direct eq "A") {
# print "CXO has just transistioned from D to A\n";
# print "cxoaltdir = $cxoaltdir AND direct = $direct\n";
$writebit = 1;
$fpinfactor = 0;
$NEWINTTIME = 0;
$OLDACISE1F = 0;
$OLDACISE2F = 0;
$OLDACISP1F = 0;
$OLDACISP2F = 0;
$OLDACISP3F = 0;
$OLDACISP4F = 0;
$OLDACISP5F = 0;
$ACISE1f=$E1f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISE2f=$E2f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP1f=$P1f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP2f=$P2f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP3f=$P3f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP4f=$P4f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP5f=$P5f*$gratfactor*$gratfactor2*$fpinfactor;
#
# Calculate new ACIS fluence: previous ACIS fluence value + new ACIS flux measurement * ACE sample time
#
$TOTALACISE1F = 0;
$TOTALACISE2F = 0;
$TOTALACISP1F = 0;
$TOTALACISP2F = 0;
$TOTALACISP3F = 0;
$TOTALACISP4F = 0;
$TOTALACISP5F = 0;
} else {
print "Fell into the ELSE section of fluence calculation loop. CHECK!\n";
print "cxoaltdir = $cxoaltdir AND direct = $direct\n";
$writebit = 1;
$fpinfactor = 0;
$NEWINTTIME = 0;
$OLDACISE1F = 0;
$OLDACISE2F = 0;
$OLDACISP1F = 0;
$OLDACISP2F = 0;
$OLDACISP3F = 0;
$OLDACISP4F = 0;
$OLDACISP5F = 0;
$ACISE1f=$E1f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISE2f=$E2f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP1f=$P1f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP2f=$P2f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP3f=$P3f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP4f=$P4f*$gratfactor*$gratfactor2*$fpinfactor;
$ACISP5f=$P5f*$gratfactor*$gratfactor2*$fpinfactor;
#
# Calculate new ACIS fluence: previous ACIS fluence value + new ACIS flux measurement * ACE sample time
#
$TOTALACISE1F = 0;
$TOTALACISE2F = 0;
$TOTALACISP1F = 0;
$TOTALACISP2F = 0;
$TOTALACISP3F = 0;
$TOTALACISP4F = 0;
$TOTALACISP5F = 0;
}
#-----------------------------------------------------------------
# open the ACIS_FLUENCE.dat for output
#-----------------------------------------------------------------
open (OUT, ">$acisflux_file_out");
print OUT "Latest valid ACIS flux and fluence data...",' 'x35,"$r km $direct$fpinst[$fpindex-1]:$hetg[$grindex-1]:$letg[$grindex-1]\n";
print OUT "$histcount[$histind-7]";
print OUT "$histcount[$histind-6]";
print OUT "$histcount[$histind-5]";
printf OUT "%4d%3d%3d%6d%8d%8d%3d %.2e %.2e%3d %.2e %.2e %.2e %.2e %.2e %3.2f\n",@words[0..6],$ACISE1f,$ACISE2f,$words[9],$ACISP1f,$ACISP2f,$ACISP3f,$ACISP4f,$ACISP5f, $words[15];
print OUT "ACIS Fluence data...Start DOY,SOD Int(s)\n";
printf OUT "%4d%3d%3d%6d%8d%8d %13.0f %12.0f %12.0f %11.0f %10.0f %10.0f %9.0f %6.0f\n",@words2[0..5],$TOTALACISE1F,$TOTALACISE2F,$TOTALACISP1F,$TOTALACISP2F,$TOTALACISP3F,$TOTALACISP4F,$TOTALACISP5F,$NEWINTTIME;
close(OUT);
#-----------------------------------------------------------------
# read the DSN schedule: dsn_summary.dat
#-----------------------------------------------------------------
# get present time and break it out into Greenwich Mean Time
$tsec = time;
($sec,$min,$hour,$dum,$dum,$dum,$dum,$doy) = gmtime($tsec);
# Calculate the numeric day of year
$doy += (($sec/60 + $min)/60 + $hour)/24 + 1;
open(DF,$DSNsched_file) or die "Cannot open $DSNsched_file\n";
while (<DF>) {
@cols = split;
@support = split(/\//, $cols[0]);
$day = $support[0];
@GMTtime = split(/\-/, $support[1]);
$SupDOY = $day + $GMTtime[0]/2400;
push @c,"$day:$cols[1]-$cols[2] UT\n" if ($doy < $SupDOY);
last if ($#c == 2);
}
close(DF);
#-----------------------------------------------------------------
# read the alert file: falert.dat (generally "0 0")
#-----------------------------------------------------------------
@pal = split ' ',<AF> if (open AF, $alert_file);
print STDERR "$host - No ACIS alert information found in $alert_file\n" if !@pal;
$scalef = 3; # scale factor between successive alert thresholds
$Nalerts = 1; # maximum number of alert messages
$Palert = 30*60; # 30 minute alert interval (seconds)
# use an open-ended geometric scaling for fluence thresholds
# 1e+09 for the first round
$threshold = $flim * $scalef**(int($pal[0]/$Nalerts));
# do the fluence limit checking and alerting
if ($TOTALACISP2F > $threshold && $tsec > ($pal[1]+$Palert)) {
chomp ($date = `date`);
$msg = sprintf "\n$host P3SCALING ACIS ALERT!! \n";
$msg .= sprintf "ACIS P3 fluence = %.2e ",$TOTALACISP2F;
$msg .= sprintf "p/(cm^2-sr-MeV), ";
$msg .= sprintf "in previous %.1f hrs\n",$NEWINTTIME/3600;
$msg .= sprintf "Above limit=%.1E ",$threshold;
$msg .= sprintf "at 112 - 187 keV.\n";
$msg .= sprintf "Latest ACE P3 proton";
$msg .= sprintf "flux = %.2e ",$ACISP2f;
$msg .= sprintf "p/(cm^2-s-sr-MeV).\n";
$msg .= sprintf "Next SIM trans (to ";
$msg .= sprintf "$fpinst[$fpindex]) occurs at ";
$msg .= sprintf "UT:$simtime.\n";
$msg .= sprintf "Present CXO alt: $r km and $direct.\n";
$msg .= sprintf "CXO SI config:\n";
$msg .= sprintf "$fpinst[$fpindex-1]:$hetg[$grindex-1]:$letg[$grindex-1]\n";
$msg .= sprintf "Next DSN contacts:\n @c";
$msg .= $date;
&send_email();
$pal[0]++;
if (open AF, ">$alert_file_out") { print AF "$pal[0] $tsec (ACIS alert number $pal[0], sent at $date)\n" }
else { print STDERR "Cannot write to $alert_file\n"};
}
# If the Bogus Flag was set, sent out a message
if ($bogus_p3_flag == 1)
{
chomp ($date = `date`);
$msg = sprintf "\n$host - Bogus ACE P3 alert! ";
$msg .= sprintf "Bogus P2F is: %.1f\n", $bogus_p3_new;
$msg .= sprintf "Bogus OLDACISFLUX is: %.1f\n", $bogus_p3_old;
$msg .= sprintf "Bogus Delta is: %.1f\n", $bogus_p3_delta;
$msg .= $date;
&send_email_to_acisdude();
# Clear out bogus values
$bogus_p3_delta = 0;
$bogus_p3_flag = 0;
}
#
# write to fluence_archive(ACIS-fluence.arc) and
# ACE_fluence_archive (ACE-fluence.arc) and
# alert_file (falert.dat)
if ($writebit == 1) {
open (AL, ">>$fluence_archive_out") or die "Cannot append to ACIS fluence archive $fluence_archive\n";
print AL "$fluxcount[-1]";
open (ACEL, ">>$ACE_fluence_archive_out") or die "Cannot append to ACE fluence archive $ACE_fluence_archive\n";
print ACEL "$histcount[-1]";
open (ALTF, ">$alert_file_out") or die "Cannot write to ACE alert counter file $alert_file\n";
print ALTF "0 0\n";
}
close(AL);
close(ACEL);
close(ALTF);
#-----------------------------------------------------------------
# Update the Chandra altitude direction file: cxodirect.dat
#-----------------------------------------------------------------
open (CXOW, ">$direction_file_out") or die "No CXO altitude information found in $direction_file!\n";
print CXOW "$direct\n";
close(CXOW);
# set the email addresses for people to be alerted
#################################################################################
#
# send_email
#
#################################################################################
sub send_email
{
# Create the email lists
$GreggEmail = "ggermain\\\@cfa.harvard.edu";
$GreggPhone = " 6177850976\\\@vtext.com";
$JohnZEmail = "john.zuhone\\\@cfa.harvard.edu";
$JohnZPhone = "7817085004\\\@vtext.com";
$PaulPEmail = "pplucinsky\\\@cfa.harvard.edu";
$PaulPPhone = "6177214366\\\@vtext.com";
$CatherineGEmail = "cgrant\\\@mit.edu";
# $CatherineGEmail = "cegrant\\\@cfa.harvard.edu";
$CatherineGPhone = "6175842686\\\@vtext.com";
$DickEEmail = "redgar\\\@cfa.harvard.edu";
$DickEPhone = "6178668615\\\@tmomail.net";
$RoyceBEmail = "buehler\\\@space.mit.edu";
$RoyceBPhone = "6178518470\\\@vtext.com";
$JackSteinerEmail = "James.Steiner\\\@cfa.harvard.edu";
$JackSteinerPhone = "6176809306\\\@vtext.com";
$JimFrancisEmail = "francisj\\\@mit.edu";
$JimFrancisPhone = "7742702359\\\@msg.fi.google.com";
$AcisdudeEmail = "${GreggEmail}, ${PaulPEmail}, ${CatherineGEmail}, ${RoyceBEmail}, ${JohnZEmail}, ${JackSteinerEmail}, ${JimFrancisEmail}";
$AcisdudeEmailPhone = "${GreggPhone}, ${PaulPPhone}, ${CatherineGPhone}, ${JohnZPhone}, ${JackSteinerPhone}, ${JimFrancisPhone}, ${AcisdudeEmail}";
$OpsGenie_yellow_alert_addr = "acis_yellow_alert\\\@alrmns.opsgenie.net";
$OpsGenie_red_alert_addr = "acis_red_alert\\\@alrmns.opsgenie.net";
#
# Operational
#
#
# A-Team
#
open (MAIL, "|mailx -s '$host - ACIS FLUENCE ALERT (ACE P3 Channel)!!' $AcisdudeEmail");
print MAIL $msg;
close MAIL;
# Open the mail to OpsGenie
open(MAIL, "|mailx -s '$host - ACIS FLUENCE ALERT (ACE P3 Channel)!!' $OpsGenie_yellow_alert_addr");
print MAIL $msg;
close MAIL;
#
# Me only for testing purposes.
#
# open (MAIL, "|mailx -s '$host - ACIS FLUENCE ALERT (ACE P3 Channel)!!' ggermain\@cfa.harvard.edu");
# print MAIL $msg;
# close MAIL;
}
#################################################################################
#
# send_email_to_acisdude
#
#################################################################################
sub send_email_to_acisdude
{
# Create the email lists
$GreggEmail = "ggermain\\\@cfa.harvard.edu";
$GreggPhone = " 6177850976\\\@vtext.com";
$JohnZEmail = "john.zuhone\\\@cfa.harvard.edu";
$JohnZPhone = "7817085004\\\@vtext.com";
$PaulPEmail = "pplucinsky\\\@cfa.harvard.edu";
$PaulPPhone = "6177214366\\\@vtext.com";
$CatherineGEmail = "cgrant\\\@mit.edu";
# $CatherineGEmail = "cegrant\\\@cfa.harvard.edu";
$CatherineGPhone = "6175842686\\\@vtext.com";
$DickEEmail = "redgar\\\@cfa.harvard.edu";
$DickEPhone = "6178668615\\\@tmomail.net";
$RoyceBEmail = "buehler\\\@space.mit.edu";
$RoyceBPhone = "6178518470\\\@vtext.com";
$JackSteinerEmail = "James.Steiner\\\@cfa.harvard.edu";
$JackSteinerPhone = "6176809306\\\@vtext.com";
$JimFrancisEmail = "francisj\\\@mit.edu";
$JimFrancisPhone = "7742702359\\\@msg.fi.google.com";
$AcisdudeEmail = "${GreggEmail}, ${PaulPEmail}, ${CatherineGEmail}, ${RoyceBEmail}, ${JohnZEmail}, ${JackSteinerEmail}, ${JimFrancisEmail}";
$AcisdudeEmailPhone = "${GreggPhone}, ${PaulPPhone}, ${CatherineGPhone}, ${JohnZPhone}, ${JackSteinerPhone}, ${JimFrancisPhone}, ${AcisdudeEmail}";
#
# A-Team
#
open (MAIL, "|mailx -s '$host - ACIS BOGUS ACE P3 ALERT', $AcisdudeEmail" );
print MAIL $msg;
close MAIL;
#
# Me
#
#open (MAIL, "|mailx -s '$host - ACIS BOGUS FLUX ALERT (ACE P3)!!' gregg\@head.cfa.harvard.edu");
# print MAIL $msg;
# close MAIL;
} # END SEND_EMAIL_TO_ACISDUDE
sub LOCK_SH() { 1 } # Shared lock (for reading)
sub LOCK_EX() { 2 } # Exclusive lock (for writing)
sub LOCK_NB() { 4 } # Non-blocking request (don't stall)
sub LOCK_UN() { 8 } # Free the lock (careful!)
#DISTRIBUTION LIST V3.0
#yellow limit trip:
#------------------
#sot_lead\@head.cfa.harvard.edu
#pgf\@space.mit.edu
#goeke\@space.mit.edu
#red limit trip:
#---------------
# 6177214366\@vtext.com - Paul's phone
# 6178518470\@vtext.com - Royce's phone
# 6177850976\@vtext.com - Gregg's phone
# 6178668615\@vtext.com - Dick Edgar's phone
#pplucinsky\@vzw.blackberry.net - Paul's phone
#sot_lead\@head.cfa.harvard.edu
#pgf\@space.mit.edu
#goeke\@space.mit.edu
# Defunct
#---------
#6178723731\@vtext.com - Joe's phone
#6177216763\@vtext.com - Nancy's phone
#joseph.depasquale\@vzw.blackberry.net - Joe's phone
#dschwartzo\@vzw.blackberry.net - Dan's phone