Repository navigation
Expand file tree
/
Copy pathsnap.cgi
More file actions
executable file
·228 lines (195 loc) · 6.59 KB
/
Copy pathsnap.cgi
File metadata and controls
executable file
·228 lines (195 loc) · 6.59 KB
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
#!/usr/bin/perl -w
#/proj/axaf/bin/perl -w
# browse the Chandra snapshot archive
# October 2000: State checking added by TLA
# Robert Cameron
# October 1999
use CGI ':standard';
#use lib '/proj/rad1/ska/lib/perl5/local';
#use lib '/proj/ascwww/AXAF/extra/science/cgi-gen/mta/Snap';
use lib '/data/mta4/www/Snapshot';
use Chex;
# read the snapshot archive
#$snarcdir = '/pool7/brad/snarc';
#mirror $snarcdir = '/data/mta/www/MIRROR/Snap';
#$snarcdir = '/proj/ascwww/AXAF/extra/science/cgi-gen/mta/Snap';
$snarcdir = '/data/mta4/www/Snapshot';
@snarcfiles = <$snarcdir/snarc.2*>;
foreach $f (@snarcfiles) {
if (open SF, $f) {
while (<SF>) {
if (/UTC/) { push @r,$r; $r = '' };
$r .= $_;
}
close SF;
}
}
push @r,$r;
shift @r;
# read the top line of the latest snapshot
#$top = (open SF, '/pool14/chandra/chandra_psi.snapshot')? <SF> : '';
$top = (open SF, './chandra.snapshot')? <SF> : '';
#$top = (open SF, '/data/mta/www/MIRROR/Snap/chandra.snapshot')? <SF> : '';
#### this stuff is to generate $top if chandra.snapshot is not kept current
# but, for now it is, so skip this
#read the ephemeris file
#
#@ephem = split ' ',<EF> if open (EF, '/proj/rac/ops/ephem/gephem.dat');
#
## read the ACE flux
#
#$fluf = "/proj/rac/ops/ACE/fluace.dat";
#if (open FF, $fluf) {
# @ff = <FF>;
# @fl = split ' ',$ff[-3];
# $fluxace = $fl[11];
# close FF;
#} else { print STDERR "$fluf not found!\n" };
#
## read the ACIS fluence
#
##$fluf = "/data/acis25/svirani/ACIS/FLU-MON/ACIS-FLUENCE.dat";
##if (open FF, $fluf) {
# #@ff = <FF>;
# #@fl = split ' ',$ff[-1];
# #$fluace = $fl[9];
# #close FF;
##} else { print STDERR "$fluf not found!\n" };
#
## read the CRM fluence - replaces F_ACE in snapshot May 2001
#$fluf = "/proj/rac/ops/CRM/CRMsummary.dat";
#if (open FF, $fluf) {
# @ff = <FF>;
# @fl = split ' ',$ff[-1];
# $flucrm = $fl[-1];
# close FF;
#} else { print STDERR "$fluf not found!\n" };
#
## read the ACE Kp file
#
#$kpf = "/proj/rac/ops/ACE/kp.dat";
#if (open KPF, $kpf) {
# while (<KPF>) { $kp = $_ };
#} else { print STDERR "Cannot read $kpf\n" };
#@kp = split /\s+/, $kp;
#
#$utc = `date -u +"%Y:%j:%T (%b%e)"`;
#chomp $utc;
#
##$top = sprintf "UTC %s f_ACE %.2e F_ACE %.2e Kp %.1f R km%7s%s\n",$utc,$fluxace,$fluace,$kp[9],$ephem[0],$ephem[1];
#$top = sprintf "UTC %s f_ACE %.2e F_CRM %.2e Kp %.1f R km%7s%s\n",$utc,$fluxace,$flucrm,$kp[9],$ephem[0],$ephem[1];
####### end generate $top #############################################
# read the current proton flux info
#$pfile = '/proj/rac/ops/CRM2/CRMsummary.dat';
# Reads current web directory file copied by the tlogr_linux.pl script.
$pfile = './CRMsummary.dat'; # it is now copied over for DMZ transistion 11/16/10 bds
open FF, $pfile;
while (<FF>) {$fluxinfo .= $_};
# write a snapshot plus CGI controls
print header, start_html(-title => "Chandra Snapshot Browser",
-BGCOLOR => 'black',
-TEXT => 'white',
-LINK => 'white',
-VLINK => 'white',
-ALINK => 'white');
if (defined param("idx") && ! defined param("action")) {
$action = "Indef";
$i = param("idx");
} else {
$action = (defined param("action"))? param("action") : "Latest";
$i = (defined param("idx"))? param("idx") : $#r;
}
$i = 0 if ($action=~/Earliest/);
$i++ if ($action=~/Next/);
$i-- if ($action=~/Prev/);
$i = $#r if ($action=~/Latest/);
$i = 0 if ($i < 0);
$i = $#r if ($i > $#r || $i=~/[^0-9]/);
$cur = CGI->new();
$cur->param("idx",$i);
#print pre("<meta http-equiv=\"refresh\" content=\"60, \/snap.cgi\">");
#$snap_text = check_state($r[$i]);
#print pre($snap_text);
print pre($r[$i]);
print start_form;
print submit(-name=>'action',-value=>"Earliest");
print submit(-name=>'action',-value=>"Prev");
print $cur->textfield("idx",$i,4);
print submit(-name=>'action',-value=>"Next");
print submit(-name=>'action',-value=>"Latest");
print "\n     <a href=\"./snapshot_hlp.html\">Explanation<\/a>\n";
print h4('Current Data:');
print pre($top);
print pre($fluxinfo);
print end_form,end_html;
########################################################################
sub check_state {
########################################################################
my $snap = shift;
# Create the Chandra Expected state object
$chex = Chex->new;
# Get OBT from snapshot
($date) = get_value($snap, 'OBT','CTUVCDU');
# Set up tolerances for ra, dec, roll
$d2r = 3.14159265/180.;
$ra_tol = 50/3600.;
$dec_tol = 50/3600.;
$roll_tol = 500/3600.;
# If there is a unique value of dec, then adjust $ra_tol
%pred = $chex->get($date);
@dec_vals = @{$pred{dec}};
$ra_tol *= 1.0 / (cos($dec_vals[0] * $d2r) + 1e-5) if (@dec_vals == 1) ;
# Define variables to check
my @checks = ({ state_var => 'simtsc',
prec => 'SIM TTpos',
post => 'HETG Angle',
tol => 5},
{ state_var => 'simfa',
prec => 'SIM FApos',
post => 'LETG Angle',
tol => 5},
{ state_var => 'obsid',
prec => 'OBSID',
post => 'EPState',
tol => 0.001},
{ state_var => 'ra',
prec => 'RA',
post => 'Bus V',
tol => $ra_tol},
{ state_var => 'dec',
prec => ' Dec ',
post => 'Bus I',
tol => $dec_tol},
{ state_var => 'roll',
prec => 'Roll',
post => 'ACA Object',
tol => $roll_tol}
);
# Now do the checking, and adjust color of text accordingly
foreach $check (@checks) {
($val, $index0, $index1) = get_value($snap, $check->{prec}, $check->{post});
$match = $chex->match(var => $check->{state_var}, # State variable name
val => $val, # Observed state value
tol => $check->{tol});
$color = "#66FFFF"; # Default to blue (not checked or undef)
$color = "#FF0000" if ($match == 0); # Bad match => red
$color = "#33CC00" if ($match == 1); # Good match => green
substr $snap, $index1-1, 0, "</font>";
substr $snap, $index0, 0, "<font color=\"$color\">";
}
return $snap;
}
####################################################################################
sub get_value {
####################################################################################
# Get a value in $s which is surrounded by $prec and $post
my ($s, $prec, $post) = @_;
my $index0 = index($s, $prec);
my $index1 = index($s, $post);
my $start = $index0 + length $prec;
my $len = $index1 - $start;
my $val = substr $s, $start, $len;
$val =~ s/^\s+//;
$val =~ s/\s+$//;
return ($val, $index0, $index1);
}