-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathacis-backstop.pl
executable file
·4172 lines (3749 loc) · 130 KB
/
acis-backstop.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
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /bin/env perl
#--------------------------------------------------------------------
# Note: /usr/local/bin on Solaris contains the most up to date perl
# /usr/local/bin on Linux points to /usr/bin, the most up to date perl
# SCRIPT USAGE:
# /data/acis/LoadReviews/script/acis-backstop.pl <full path to current week's OFLS version>/CDAY.hhmm.backstop <full path to preceding week's approved OFLS version>/ACIS-History.txt
#
# EXAMPLE:
# acis-backstop.pl {path/*.backstop} {path/ACIS-History.txt}
# acis-backstop.pl $SOTMP/2000/SEP1200/ofls/CMI256:1602.backstop $SOTMP/2000/SEP1200/ofls/ACIS-History.txt
#
# WORKING AREA: /data/acis/LoadReviews/script/
#
#--------------------------------------------------
#
# Produces as output in the directory the script was executed within:
# ACIS-LoadReview.txt <-- Reviewed by ACIS Ops
# ACIS-History.txt <-- To be used in the next load
# ACIS-FPHIST.dat <-- To be used by SNV in his ACIS orb fluence mon
# ACIS-GRATHIST.dat <-- To be used by SNV in his ACIS orb fluence mon
# ACIS-OBSHIST.txt <-- Used in ACIS Real-time web page
# ACIS-TLMHIST.txt <-- Used in ACIS Real-time web page
# ACIS-TSCHIST.txt <-- Used in ACIS Real-time web page
# ACIS-DITHHIST.dat <-- Used in ACIS Real-time web page
#
# UPDATE - June 26, 2016
# Royce Beuhler
# V2.15
# Added logic for the "bak" suffix capability.
#
# UPDATE - December 5, 2016
# Gregg Germain
# V2.16
# Changed from "Browser" username to "acisops" for access
# to the OCAT
#
# Update: January 31, 2017
# Gregg Germain
# - Modified program to always attempt to collect Dither
# information from the OCAT.
# - Modified program to always print out Dither
# information and put it before the "Cycle" printout
# - Always collect Dither info from the OCAT
#
# Update: June16, 2017
# Gregg Germain
# - Modified code to handle the fact that ECS measurement Obsid's
# now start at 38000.
# - Variables $min_cti_obsid and $max_special_obsid were created
# tomake any future Obsid limit change easy to implement.
# - Modified code to print out a row of "-cti"'s when a Perigee Passage
# CTI measurement is completed.
# - Added numerous comments
#
# Update: January 6, 2022
# Gregg Germain
# V3.3
# - Modified the "triplet" code to include WSPOW00000 as a legal
# triplet power command. Also combined the 2 individual sections
# of triplet power command test code into one which now includes the WSPOW0.
#
# Update: April 4, 2022
# - Incorporating HIST_File_Utilities_Class and creating
# ACIS-SCS155HIST.dat in OFLS directory
#
# Called from LR with this line:
#
# /data/acis/LoadReviews/script/acis-backstop.pl -s server CR*.backstop_path Cont_Load_ACIS-History.txt
# server - ocatsqlsrv
# Review Load backstop file path - /data/acis/LoadReviews/2022/MAR2821/oflsa/CR086_2107.backstop
# hist - $prev_load_dir/ACIS-History.txt
#
# Update: August 18, 2022
# - V3.5
# - Perigee Passage TXGING Quiet checks removed
#
# Update: October 25, 2024
# - V3.6
# - Solve the ACIS-HRC-ACIS SI mode issue when the two ACIS SI
# modes are the same.
#
#--------------------------------------------------------------------
use DBI;
use Text::ParseWords;
use IO::File;
use File::Basename;
use POSIX qw(tmpnam ceil floor);
use Getopt::Std;
use Getopt::Long;
use Time::Local;
use Date::Calc qw(Add_Delta_Days);
# ($year, $month, $day = Add_Delta_Days($year,1,1, $doy - 1);
use Date::Calc qw(Add_Delta_DHMS);
use Scalar::Util qw(reftype);
#----------------------------------------
#Variables:
#----------------------------------------
# ARGV[2] contains the full path to the Review load CR*.backstop file
# Extract the full path to the directory
$last_slash_pos = rindex($ARGV[2], "/");
# Extract the substring up to but not including the final /
$rev_load_dir_path = substr($ARGV[2], 0, $last_slash_pos);
# Create the Review Load SCS-155 Deadman History file ACIS-SCS155HIST.dat
system("python3 /data/acis/LoadReviews/script/UTILITIES/Create_Weekly_155_HIST_file.py $rev_load_dir_path");
$Rec_Time=""; # read the record and split
$Rec_VCDU=""; # VCDU counter
$Rec_MC=""; # Command
$Rec_Event=""; # event information
$Rec_Eventdata=""; # event data
$wspow=""; # wspow command, via sacgs
# As of June, 2017 Perigee Passage CTI obsids can be as low as 38000
$min_cti_obsid = 38000;
# Special observations such as Long Term CTI measurements, and others,
# are given Obsid's in the 60,000's. Various tests
$max_special_obsid = 69999;
$server="ocatsqlsrv"; #default server.
$ctifmtcheck=0;
$startscitime=0;
$startsciflag=0;
$lastCmdAcisFlag=0;
$lastCmdAcisTime=0;
$loadpblockflag=0;
$commflag=0;
$commstart=0;
$commend=0;
$radmonon=0;
$radmonff=0;
$radmonoff=0.0;
$hrcStime=0;
$elec1ent=0;
$elec1exit=0;
$NILpad=0;
$simtest1=0;
$simtest2=0;
$tstop=0;
$obsstart=0;
$exposure=0;
$obsend=0;
$delobs=0;
$enter_rad=0;
$perevt=0.0;
$timeindex=0;
$nom_zsim=0;
$delta_zsim=0;
$per_stopsci=0;
$per_vidalldn=0;
$perigee_time=0;
$per_oldstopsci=0;
$check_acis_sci=0;
$nil_flag=0; # doing a NIL measurement
$cti_flag=0; # doing a CTI measurement
#$quiet_flag=0; # quieted the threshold crossings
# Removed for FSW GIJ-58
$dec_day=0;
$pad=0;
$pad2=0;
$simtrans=0;
$viddwn_cnt=0;
$pblock_ef="N"; # pblock eventfilter(for win)
#
# For Cycles 1 through 10, eventAmplitdueRange was 15.0
# From 11 onward the new value was 13.
$pblock_lea=0.08; # Pblock lowerEventAmplitude(for win)
$pblock_ear=13.0; # pblock eventAmplitdueRange(for win)
$sys_cnt=0;
$huff_cnt=0;
$start_sci_cnt=0;
$stop_sci_count=0;
$obsid_cnt=0;
$letg_in_cnt=0;
$letg_out_cnt=0;
$hetg_in_cnt=0;
$hetg_out_cnt=0;
$start_comm=0;
$stop_comm=0;
$perigee_cnt=0;
$loaded_ocat=0; #has the ocat been loaded.
$compare=0; #has the ocat/pblock compare been done?
$flag_pblock=0; #pblock correctly loaded?
$flag_params=0; #Ocat & params match?
$flag_setup=0; #instrument setup ok?
$flag_ccds=0; #correct CCDs?
$flag_windows=0;#correct window?
@pblock_list; #obsids with pblock errors
@param_list; #Obsids with param errors
@setup_list; #Obsids with setup errors
@ccd_list; #Obsids with ccd errors
@window_list; #obsids with window errors
@error_list; #list of errors;
$tstart_orig=0; #time of start sci
$biasength="";
@biasinfo=0;
$biastime=0;
$tstart=0;#time of startsci+bias
$tstop=0;
$exposure=0;
$new_exposure=0;
$clear_buffer_time=0; #time to clear the buffers
$bitscleared=4320.0; #kbits in the buffers
$fmt_change=0.0; #time of format change;
$HETGin=0;
$LETGin=0;
$Test_Passed = 1;
#$Test_PassedC = 1;
#stored parameter blocks and window blocks.
$WTval="";
$WCval="";
$W2val="";
$W1val="";
$last_simode="";
$FPSI="??";
$HETG="??";
$LETG="??";
$FMT="??";
$DITH="UNKN";
$OBSID=999999;
$sim_z=0;
%pblock_entries=();
%ocat_entries=();
%window_entries=();
@window_wblock_array; #leave empty, array of window hash for wblock
@window_ocat_array; #leave empty, array of window hash for OCAT
$pow_cmd="";
$simode=""; # current Simode
$ocat_simode=""; # OCAT SI_mode
$cti_simode=""; # Radzone SImode
$nil_simode=""; # Nil simode
$needwindow=1; # need a window for this obs?
$inocat=0; # is this in the ocat?
$triplet_check=0; # check for radzone triplet
$dhhtr_state=0; # state of the detector heater 0=off 1=on
#$obs = { # Doesn't seem to be used anywhere. Uncomment
# $start=>0.0, # these for lines or else delete.
# $stop=>0.0,
#};
@crm_array;
@nil_array;
%command_list=();
%si_mode_list=();
%chandra_status=();
%perigee_status=();
$min_perigee_time=55.00;# min ks on 140+pitch in perigee
@maneuvers=(); # array of maneuver hash
$first=1;
#--------------------------------------------------------------------
#SCRIPT START *** SCRIPT START *** SCRIPT START *** SCRIPT START ***
#--------------------------------------------------------------------
#Check for options: will remove options from argv
$server="ocatsqlsrv";
GetOptions( 's=s' => \$server); #to be passed to acisparams.pl
if(@ARGV != 2){
die "ERROR! TWO INPUTS REQUIRED!\nUSAGE: $0 {current_week_path/*.backstop} {preceding_week_path/ACIS-History.txt}\n";
}
#--------------------------------------------------------------------
# NEW CODE to allow one acis-backstop.pl to run in regular and backup
# modes
# SET UP the directory for the scripts
#--------------------------------------------------------------------
#if($0 =~ /bak/){
#called as acis-backstop_bak.pl
if (`lr_suffix.pl`) { # Null string if not on backup machine
$base_dir=</data/acis-bak>;
}
else{
$base_dir=</data/acis>;
}
$script_dir="$base_dir/LoadReviews/script";
$sacgs_dir="$base_dir/sacgs/bin";
$tln_file="$base_dir/LoadReviews/script/ACIS_current.tln";
$sacgs_dir="$base_dir/LoadReviews/Linux/scripts";
$egrep="/bin/egrep";
#print "The base directory is $base_dir\n";
#SETUP ITEMS for the script
setup_command_list(\%command_list);
setup_SI_MODES(\%si_mode_list);
read_history($ARGV[1],\%chandra_status);
#need to read the perigee passage
read_perigee($ARGV[0],$ARGV[1],\%perigee_status);
# Extract the last SI mode from the Continuity load ACIS-History.txt file.
$last_simode=$chandra_status{last_simode};
$first_simode=1; #flag to allow the OFLS to repeat the parameter blocks
#--------------------------------------------------------------------
#Open all files to be used
#--------------------------------------------------------------------
umask(002);
open_files(SIMTSC,">ACIS-TSCHIST.dat");
open_files(OBSIDHIST,">ACIS-OBSHIST.dat");
open_files(FPHIST,">ACIS-FPHIST.dat");
open_files(GRATHIST,">ACIS-GRATHIST.dat");
open_files(DITHHIST,">ACIS-DITHHIST.dat");
open_files(TLMHIST,">ACIS-TLMHIST.dat");
open_files(LR, ">ACIS-LoadReview.txt");
open_files(HIST_OUT, ">ACIS-History.txt");
open_files(PERIGEE_OUT,">ACIS-Perigee.txt");
open_files(STOREHIST, ">ACIS-STORED-HIST.txt");
open_files(BACK,$ARGV[0]);
#------------------------------------------------------------
# Read and store the manuever start and stop times
# File is the directory of the backstop/mm*.sum
#--------------------------------------------------------------------
###NOTE- Make some changes to get rid of the extra calls to the maneuver
#FILE
$dir = dirname($ARGV[0]);
$dir2=dirname($ARGV[1]);
$last_manfile=`ls ${dir2}/mm*.sum 2>/dev/null`;
$manfile=`ls ${dir}/mm*.sum 2>/dev/null`;
&read_manuever($manfile,\@start_man,\@stop_man);
#read last and current maneuvers
&read_maneuver_hash($last_manfile,\@maneuvers);
&read_maneuver_hash($manfile,\@maneuvers);
#--------------------------------------------------------------------
# Read and store the CRM and NIL file information
# CRM file is backstop/*CRM*
# NIL file is backstop/*.er
#--------------------------------------------------------------------
$CRMfile=`ls ${dir}/DO*CRM_Pad.txt 2>/dev/null`;
read_CRM_file($CRMfile,\@crm_array);
$NILfile=`ls ${dir}/*.er 2>/dev/null`;
read_NIL_file($NILfile,\@nil_array);
print LR "\n-------------------------------------------------\n";
print LR "ACIS LOAD REVIEW OUTPUT:\n";
print LR "FOR REVIEW BY CXC ACIS OPS PERSONNEL\n";
print LR "\n";
print LR "-------------------------------------------------\n";
print LR "\n";
print LR "USING $ARGV[0]\n\n";
print LR "LOAD HISTORY FROM: $ARGV[1]\n\n";
print LR "-- CHANDRA LOAD START --\n\n";
#--------------------------------------------------------------------
#Open the database ONCE, connect NOW
#--------------------------------------------------------------------
#Connect to the database:
# OLD BROWSER USERNAME database username, password, and server
#$user="browser";
#$passwd="newuser";
# Browser replacement TEST OCAT
#$user="acisops";
#$passwd="aopspd22";
# Connect to the database: OPERATIONAL
# NEW OCAT USERNAME database username, password, and server
$user="acisops";
$passwd="gpCjops)";
$serverstr="dbi:Sybase:${server}";
#open connection to sql server
my $dbh = DBI->connect(($serverstr, $user, $passwd)) || die "Unable to connect to database". DBI->errstr;
# use axafocat and clean up
$dbh->do(q{use axafocat}) || die "Unable to access database axafocat". DBI->errstr;
#---------------------------------------------------------
# Main, read the next record in the backstop file
#--------------------------------------------------------------------
while ( <BACK> )
{
Process_Next_Record($_);
$scs_val=$Rec_Eventdata{SCS}; #new, record SCS data
push (@timecont,$dec_day);
#----------------------------------------
#if first time, update histories
#----------------------------------------
if($first == 1){
update_history_files(FPHIST,\%chandra_status);
update_history_files(GRATHIST,\%chandra_status);
update_history_files(TLMHIST,\%chandra_status);
update_history_files(OBSIDHIST,\%chandra_status);
update_history_files(DITHHIST,\%chandra_status);
update_history_files(LR,\%chandra_status);
$first=0;
}
#----------------------------------------
#Confirm that this is a command we care about
#----------------------------------------
if ($Rec_Event eq "ACISPKT" ||
$command_list{($Rec_Eventdata{TLMSID})} ||
$command_list{($Rec_Eventdata{TYPE})} ||
$command_list{($Rec_Event)} ||
$Rec_Eventdata{TLMSID} =~ /CSELFMT/ || #FORMAT
$Rec_Eventdata{TLMSID} =~ /\A1/) { #ACIS HARDWARE COMMANDS
#----------------------------------------
# We care. Handle each set of commands
#----------------------------------------
check_scs($scs_val); #check if this a valid for ACIS in vehicle load
#----------------------------------------
SWITCH: {
#Comms:
if($Rec_Eventdata{TLMSID} =~ /CTX/){
process_comm();
last SWITCH;
}
#Gratings:
if($Rec_Eventdata{TLMSID} =~ /ETG/){
process_TG(\%chandra_status);
last SWITCH;
}
#Dither:
if($Rec_Eventdata{TLMSID} =~ /DITH/){
process_dither(\%chandra_status);
last SWITCH;
}
#Radiation Monitor
if($Rec_Eventdata{TLMSID} =~ /OORMP/)
{
process_radmon(\%chandra_status,\%perigee_status,@crm_array);
last SWITCH;
}
#Format Change
if($Rec_Eventdata{TLMSID} =~ /CSELFMT/)
{
process_format(\%chandra_status);
last SWITCH;
}
#RadZone Entry and Exit
if($Rec_Event =~ /ORBPOINT/){
process_radzone(@crm_array);
last SWITCH;
}
#SIM FOCUS and Translations
if($Rec_Event =~ /^SIM/)
{
process_sim(\%chandra_status);
last SWITCH;
} # END SIMTRANS
#Obsid Changes in response to an MP_OBSID command
if ($Rec_Event =~ /MP_OBSID/)
{
obsid_change(\%chandra_status);
last SWITCH;
} # END OBSID CHANGES
#Stop Sciences
if ($Rec_Eventdata{TLMSID} =~ /AA00000000/){
process_stop_science();
confirm_packet_space();
last SWITCH;
} # END SUB STOP SCIENCE
#Start Science
if ($Rec_Eventdata{TLMSID} =~ /XTZ0000005/ ||
$Rec_Eventdata{TLMSID} =~ /XCZ0000005/)
{
process_start_science();
check_acistime();
last SWITCH;
}
#Load Parameter blocks
if ($Rec_Eventdata{TLMSID} =~ /WT0*/ ||
$Rec_Eventdata{TLMSID} =~ /WC0*/ )
{
check_acistime();
load_pblock(\%chandra_status);
last SWITCH;
}
#Load Window Blocks
if ($Rec_Eventdata{TLMSID} =~ /W100*/ ||
$Rec_Eventdata{TLMSID} =~ /W200*/)
{
load_windowblock(\%chandra_status);
check_acistime();
last SWITCH;
}
#all other ACIS commands:
else{
#process_acispkt();
process_acispkt(\%perigee_status);
check_acistime();
}
}#end SWITCH
}#end lines we care about - if ($Rec_Event eq "ACISPKT" ||.....
} #END WHILE BACK - end processing backstop file
end_load(\%chandra_status);
check_errors();
#cleanup
close(SIMTSC);
close(OBSIDHIST);
close(FPHIST);
close(GRATHIST);
close(DITHHIST);
close(TLMHIST);
close(LR);
close(HIST_OUT);
close(STOREHIST);
close(PERIGEE_OUT);
if(-f "/tmp/temp.tln"){
unlink("/tmp/temp.tln");
}
exit;
#--------------------------------------------------------------------
# SUBROUTINES SUBROUTINES SUBROUTINES SUBROUTINES SUBROUTINES
#--------------------------------------------------------------------
#--------------------------------------------------------------------
# Setup_command_list: take an array of commands that are
# actually used from the backstop file and
# fill a hash table with them for easy lookup
#--------------------------------------------------------------------
sub setup_command_list{
my($comms)=(@_);
@commands= ("AFIPD",#items that are $Rec_Eventdata{TLMSID}
"AODSDITH",
"AOENDITH",
"CTXAON",
"CTXAOF",
"CTXBON",
"CTXBOF",
"OORMPDS",
"OORMPEN",
"CSELFMT*",
"4ISHGBEN",#enable insert HETG
"4EXHGBEN",#start move
"4EXHGBDS",#end move
"4RTHGBEN",#enable retract HETG
"4OLETGIN",#Inerted LETG
"4OLETGRE",#Retracted LETG
"4OHETGIN",#inserted HETG
"4OHETGRE",#Retracted HETG
"EEF1000", #rad zone entry #$rec_Eventdata{TYPE}
"EE1RADZ0",#rad zone entry
"EE2RADZ0",#rad zone entry
"EP2RADZ0",#rad zone exit
"EP1RADZ0",#rad zone exit
"XEF1000", #rad zone exit
"EPERIGEE",#Perigee
"EAPOGEE", #Apogee
"SIMTRANS",
"SIMFOCUS",
"MP_OBSID",
"\A1");
$i=1;
foreach $f (@commands){
$$comms{$f} = $i++;
}
return;
}
#--------------------------------------------------------------------
#setup_SI_MODES- set up an associative array for
# diagnostics NOT in the ocat
#--------------------------------------------------------------------
sub setup_SI_MODES{
my($si_mode_array)=(@_);
#NEED THE ACIS UNDERCOVER SOMEHOW
$si_mode_array->{"WT007AC024"}="TE_007AC"; #new CTI
$si_mode_array->{"WT007EC024"}="TE_007AE"; #new CTI
$si_mode_array->{"WT00B26014"}="TE_00B26"; #new CTI
$si_mode_array->{"WT0021C034"}="TE_0021C"; #CTI S-array
$si_mode_array->{"WT00216034"}="TE_00216"; #CTI I-array
$si_mode_array->{"WT008EA024"}="TE_008EA"; #CTI mixed
$si_mode_array->{"WT00452024"}="HIE_0002"; #HRC-I event histogram
$si_mode_array->{"WT00452024"}="HIO_0002"; #HRC-I event histogram
$si_mode_array->{"WT00DAA014"}="H2C_0002"; #HRC-I event histogram
$si_mode_array->{"WT0023C024"}="HSE_0002"; #HRC-S event histogram (windows)
$si_mode_array->{"WT0023A024"}="HSO_0002"; #HRC-S event histogram (windows)
$si_mode_array->{"WT000B5024"}="TN_000B4"; #TN_000B4B raw mode I0-I3,S2,S3
$si_mode_array->{"WT000B7024"}="TN_000B6"; #TN_000B6B raw mode S0-S5
$si_mode_array->{"WT00549034"}="TN_00548"; #CHARGE INJECTION
$si_mode_array->{"WT0054B034"}="TN_0054B"; #CHARGE INJECTION
$si_mode_array->{"WT0054D034"}="TN_0054C"; #CHARGE INJECTION
$si_mode_array->{"WT006C2024"}="TE_006C2";#Focal Plane cooling test
$si_mode_array->{"WT007AC024"}="TE_007AC"; #ACIS-I, all but g255
$si_mode_array->{"WT007AE024"}="TE_007AE"; #ACIS-S, all but g255
$si_mode_array->{"WC000C4024"}="CC_000C4"; #ACIS-S, all but g255 CC
$si_mode_array->{"WC000C6024"}="CC_000C6"; #ACIS-I, all but g255 CC
#---
#alternating exp mode to calibrate particle background
#correction 4.0/3.2s frametimes, I0-I3,S2,S3
$si_mode_array->{"WT0031D024"}="TE_0031C";
$si_mode_array->{"WT0031C024"}="TE_0031C";
#---
#alternating exp mode to calibrate particle background
#correction 2.0/3.2s frametimes, I0-I3,S3
$si_mode_array->{"WT00681024"}="TE_00680";
$si_mode_array->{"WT00680024"}="TE_00680";
#---
#alternating exp mode to calibrate particle background
#correction 2.5/3.2s frametimes, I0-I3,S3
$si_mode_array->{"WT00683024"}="TE_00682";
$si_mode_array->{"WT00682024"}="TE_00682";
#---
#alternating exp mode to calibrate particle background
#correction 3.0/3.2s frametimes, I0-I3,S3
#---
$si_mode_array->{"WT00685024"}="TE_00684";
$si_mode_array->{"WT00684024"}="TE_00684";
#---
#alternating exp mode to calibrate particle background
#correction 3.5/3.2s frametimes, I0-I3,S3
$si_mode_array->{"WT00687024"}="TE_00686";
$si_mode_array->{"WT00686024"}="TE_00686";
#---
#alternating exp mode to calibrate particle background
#correction 4.0/3.2s frametimes, I0-I3,S3
$si_mode_array->{"WT00689024"}="TE_00688";
$si_mode_array->{"WT00688024"}="TE_00688";
#---
#alternating exp mode to calibrate particle background
#correction 1.5/3.2s frametimes, I0-I3,S3
#---
$si_mode_array->{"WT0068F024"}="TE_0068E";
$si_mode_array->{"WT0068E024"}="TE_0068E";
return;
}
#--------------------------------------------------------------------
#open_files: subroutine to open all files and to make the code easier
# to read
#--------------------------------------------------------------------
sub open_files{
my($fileh,$filename)=(@_);
open ($fileh,$filename) or die "ERROR!\nCould not OPEN $filename; file not created!\nUSAGE: acis-backstop.pl {current_week_path/*.backstop} {preceding_week_path/ACIS-History.txt}\n";
return;
}
#--------------------------------------------------------------------
# read_history: subroutine to read the history file and return
# a hash with the items
#--------------------------------------------------------------------
sub read_history{
my($hist_file,$histref)=(@_);
$histind = 0;
open_files(HIST,$hist_file);
while ($line = <HIST>) {
if($line =~ 'CHANDRA'){
#instead of an index, find the line that matches CHANDRA
chop($line);
$histline=$line;
}
}
close(HIST);
$delim=",";
$where=index($histline,'(');
if($where != -1){
$histline=substr($histline,$where,120);
$histline=~s/\(//;
$histline=~s/\)//;
}
else{die "ERROR!\n Improper format in History File:$hist_file\n";}
$histline=~s/\(//;
$histline=~s/\)//;
@words=quotewords($delim,$keep,$histline);
$$histref{"FPSI"} = $words[0];
$$histref{"HETG"} = $words[1];
$$histref{"LETG"} = $words[2];
$$histref{"OBSID"} = $words[3];
$$histref{"radmonstatus"} = $words[4];
$$histref{"FMT"} = $words[5];
$$histref{"DITH"} = $words[6];
#parse out the stored values on board.
$$histref{"WTval"} = $words[7];
$$histref{"WCval"} = $words[8];
$$histref{"W2val"} = $words[9];
$$histref{"W1val"} = $words[10];
$$histref{"last_simode"} = $words[11];
close(HIST);
return
}#--------------------------------------------------------------------
# read_perigee: subroutine to read the perigee file and return
# a hash with the items
#--------------------------------------------------------------------
sub read_perigee{
my($backstop_file,$hist_file,$periref)=(@_);
#parse out directory from history file add on perigee file name
$dirname = dirname($hist_file);
$peri_file="${dirname}/ACIS-Perigee.txt";
$curdirnam= dirname($backstop_file);
$periind = 0;
#in the case of an interrupt, the Perigee edit file will exist
if($dirname eq $curdirnam){
if( -e "${dirname}/ACIS-Perigee_edit.txt"){
$peri_file="${dirname}/ACIS-Perigee_edit.txt";
}
}
print "NOTE: Using $peri_file\n";
open_files(PERIGEE,$peri_file);
while ($line = <PERIGEE>) {
if($line =~ 'CHANDRA'){
#instead of an index, find the line that matches CHANDRA
chop($line);
$histline=$line;
}
}
close(PERIGEE);
$delim=",";
$where=index($histline,'(');
if($where != -1){
$histline=substr($histline,$where,80);
$histline=~s/\(//;
$histline=~s/\)//;
}
else{die "ERROR!\n Improper format in Perigee File:$peri_file\n";}
$histline=~s/\(//;
$histline=~s/\)//;
@words=quotewords($delim,$keep,$histline);
$$periref{"radtime"} = $words[0]; # time of last radtime
$$periref{"offtime"} = $words[1]; # time of last housing heater OFF
$$periref{"ontime"} = $words[2]; # time of last housing heater ON
$$periref{"TRIPLET"} = $words[3]; # is radzone triplet set?
close(PERIGEE);
#set the global values
if($words[0] != 0.00){
$radmonoff=parse_time($words[0]);
}
if($words[3] =~ /YES/){
$triplet_check=3;
}
$htroff=parse_time($words[1]);
$htron=parse_time($words[2]);
if($htron > $htroff){ #if the heater turn on was AFTER the off
$dhhtr=1; #the heater is ON
}
return
}
#--------------------------------------------------------------------
# Print Status
#--------------------------------------------------------------------
sub print_status{
my($FILEH,$stat) = (@_);
$FP=$$stat{"FPSI"};
$HETG=$$stat{"HETG"};
$LETG=$$stat{"LETG"};
$OBSID=$$stat{"OBSID"};
$RADMON=$$stat{"radmonstatus"};
$FMT=$$stat{"FMT"};
$DITH=$$stat{"DITH"};
print $FILEH "\n====> CHANDRA STATUS ARRAY=($FP,$HETG,$LETG,$OBSID,$RADMON,$FMT,$DITH)\n\n";
return;
}
#-----------------------------------------------------------------------------------
# Update Status - Update the specified member of the
# $chandra_status hash with the specified value
#
#------------------------------------------------------------------------------------
sub update_status
{
# Get the arguments - hash key, new value, the chandra_status hash
($key,$val,$stat) = (@_);
# Update the item
$$stat{$key}=$val;
return;
}
#--------------------------------------------------------------------
# update_history_files: Update the history files
#--------------------------------------------------------------------
sub update_history_files{
my($FILEH,$stat) = (@_);
$FP=$$stat{"FPSI"};
$HETG=$$stat{"HETG"};
$LETG=$$stat{"LETG"};
$OBSID=$$stat{"OBSID"};
$RADMON=$$stat{"radmonstatus"};
$FMT=$$stat{"FMT"};
$DITH=$$stat{"DITH"};
$W2val=$$stat{"W2val"};
$W1val=$$stat{"W1val"};
$WTval=$$stat{"WTval"};
$WCval=$$stat{"WCval"};
SWITCH:{
if ($FILEH =~ /FP/){
printf FPHIST "%15s\t%8s\t%6.0f\n",$fields[0],$FP,$OBSID;
last SWITCH;
}
if ($FILEH =~ /GRAT/){
printf GRATHIST "%15s\t%8s\t%8s\t%6.0f\n",$fields[0],$HETG,
$LETG,$OBSID;
last SWITCH;
}
if ($FILEH =~ /TLM/){
printf TLMHIST "%15s\tCOMMAND_HW\t%10s\n",$fields[0],$FMT;
last SWITCH;
}
if ($FILEH =~ /OBSID/){
printf OBSIDHIST "%15s\tMP_OBSID\t%9s\n",$fields[0],$OBSID;
last SWITCH;
}
if ($FILEH =~ /DITH/){
printf DITHHIST "%15s\tCOMMAND_SW\t%10s\n",$fields[0],$DITH;
last SWITCH;
}
;
if ($FILEH =~/HIST_OUT/){
printf HIST_OUT "%15s====> CHANDRA STATUS ARRAY AT LOAD END = ($FP,$HETG,$LETG,$OBSID,$RADMON,$FMT,$DITH,$WTval,$WCval,$W2val,$W1val,$last_simode)\n\n",$fields[0];
last SWITCH;
}
if($FILEH =~ /LR/){
print LR "CHANDRA STATUS ARRAY AT START OF LOAD REVIEW (FROM PREVIOUS LOAD HISTORY FILE):\n";
print LR "(FP SI,HETG status,LETG status,current OBSID,RadMon status,current TLM FMT,Dither)\n";
print LR "\t\t = ($FP,$HETG,$LETG,$OBSID,$RADMON,$FMT,$DITH)\n\n";
last SWITCH;
}
# Can't do these on Filehandle
if ($FILEH =~ /W2val/){
printf STOREHIST "%15s\tCOMMAND_SW\t%10s\n",$fields[0],$W2val;
last SWITCH;
}
if ($FILEH =~ /W1val/){
printf STOREHIST "%15s\tCOMMAND_SW\t%10s\n",$fields[0],$W1val;
last SWITCH;
}
if ($FILEH =~ /WTval/){
printf STOREHIST "%15s\tCOMMAND_SW\t%10s\n",$fields[0],$WTval;
last SWITCH;
}
if ($FILEH =~ /WCval/){
printf STOREHIST "%15s\tCOMMAND_SW\t%10s\n",$fields[0],$WCval;
last SWITCH;
}
die "Error: Do not recognize $FILEH\n";
}
return;
}
#--------------------------------------------------------------------
#Update Perigee History: record the last radmon off. heater times and
# if the triplet was recorded
#--------------------------------------------------------------------
sub update_perigee_history{
my($FILEH,$perigee_stat)= @_;
$raddis=$$perigee_stat{radtime};
$htroff=$$perigee_stat{offtime}; # time of last housing heater OFF
$htron=$$perigee_stat{ontime};
$trip="NO";
if($triplet_check == 3){
$trip = "YES";
}
printf $FILEH "load end ====> (radmon disab time, dhhtr off time, dhhtr on time, rad zone triplet)\n";
printf $FILEH "%15s====> CHANDRA PERIGEE INFO AT LOAD END = ($raddis,$htroff,$htron,$trip)\n\n",$fields[0];
return;
}
#--------------------------------------------------------------------
#read_CRM_file: Read the CRM file and store the information in an
# array of hashrefs...
#--------------------------------------------------------------------
sub read_CRM_file{
my($filename,$crm_list)= @_;
open (CRMPAD, "$filename") || warn "Warning! Cannot open CRM $file!";
my $si_mode='';
%list=();
while (<CRMPAD>)
{
$_=trim($_);
#SET UP COLUMNS FIRST
if($_ =~ /EVENT/){
my @row = split (/\s{2,15}/, $_);
@keys=@row;
}
else{
if($_ =~ /^X|^E/){
my %event_item=(());
@line = split (/\s+/, $_);
$size=@line;
#print "Size is $size\n @line\n";
#assign based on keys
for ($ii=0;$ii<$size;$ii++){
$list{$keys[$ii]}=$line[$ii];
}
foreach my $key ( keys %list ) {
if ($key =~ m/EVENT$/){
$crm_event = $list{$key};
}
if($key =~ m/SI_MODE/){
$si_mode=$list{$key};
}
if($key =~ m/ABSOLUTE/){
if ($key =~ m/adj E/ || $key =~ /AE/){
$crm_event_time1=$list{$key};
}
}
if($key =~ m/PAD/){
$padd=$list{$key}/86400.;
}
}
if(length($si_mode) < 8){ #empty
foreach $l (@line){
if($l =~ m/[A-Z]{2}_[A-Z|0-9]{5}/){
$si_mode=$l;
last;
}
}
}
my @crm_event_time = split(":",$crm_event_time1);
my $crm_ae_time = $crm_event_time[1] + $crm_event_time[2]/24 +
$crm_event_time[3]/1440 + $crm_event_time[4]/86400;
my $time_str=sprintf("%03d:%02d:%02d:%02d\n",$crm_event_time[1],
$crm_event_time[2],$crm_event_time[3],
$crm_event_time[4]);
%event_item=(
event=>$crm_event,
time=>$crm_ae_time,
pad=>$padd,
SI=>$si_mode,
string=>$time_str,
);
push(@crm_array,\%event_item);
$si_mode='';
} #if
}
} #while
# DEBUG--Keep this commented for debugging purposes
#foreach $item (@crm_array){
# print "Event=$$item{event} at $$item{time} with SI of $$item{SI}\n";
#}
close(CRMPAD);
}
#--------------------------------------------------------------------
# read_NIL_file :read records from NIL file
#--------------------------------------------------------------------
sub read_NIL_file{
my($filename,$nil_list)= @_;
$flag=0; # flag a record
open (NIL_ER, "$filename") || print "There are no NIL observations scheduled for this load.\n";
while (<NIL_ER>){
if($_ =~ /,ID=/ && # found a record
$_ !~ /COMMENT/){ #ignore the comments
my %nil_item;
my @row = split (/=/, $_);
my @val=split(/,/,$row[1]);
$id=trim($val[0]);
$foo=<NIL_ER>;
@row = split (/=/, $foo);
@val=split(/,/,$row[1]);