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
|
# To: bug-gnu-utils@prep.ai.mit.edu
# Cc: arnold@gnu.ai.mit.edu
# Date: Mon, 20 Nov 1995 11:39:29 -0500
# From: "R. Hank Donnelly" <emory!head-cfa.harvard.edu!donnelly>
#
# Operating system: Linux1.2.13 (Slackware distrib)
# GAWK version: 2.15 (?)
# compiler: GCC (?)
#
# The following enclosed script does not want to fully process the input data
# file. It correctly executes the operations on the first record, and then dies
# on the second one. My true data file is much longer but this is
# representative and it does fail on a file even as short as this one.
# The failure appears to occur in the declared function add2output. Between the
# steps of incrementing NF by one and setting $NF to the passed variable
# the passed variable appears to vanish (i.e. NF does go from 68 to 69
# and before incrementing it "variable" equals what it should but after
# "variable" has no value at all.)
#
# The scripts have been developed using nawk on a Sun (where they run fine)
# I have tried gawk there but get a different crash which I have not yet traced
# down. Ideally I would like to keep the script the same so that it would run
# on either gawk or nawk (that way I can step back and forth between laptop and
# workstation.
#
# Any ideas why the laptop installation is having problems?
# Hank
#
#
# #!/usr/bin/gawk -f
BEGIN {
# set a few values
FS = "\t"
OFS = "\t"
pi = atan2(0, -1)
# distance from HRMA to focal plane in mm
fullradius = 10260.54
# set locations of parameters on input line
nf_nrg = 1
nf_order = 3
nf_item = 4
nf_suite = 5
nf_grating = 8
nf_shutter = 9
nf_type = 13
nf_src = 14
nf_target = 15
nf_voltage = 16
nf_flux = 17
nf_filt1 = 20
nf_filt1_th = 21
nf_filt2 = 22
nf_filt2_th = 23
nf_bnd = 24
nf_hrma_polar = 27
nf_hrma_az = 28
nf_detector = 30
nf_acis_read = 32
nf_acis_proc = 33
nf_acis_frame = 34
nf_hxda_aplist = 36
nf_hxda_y_range = 37
nf_hxda_z_range = 38
nf_hxda_y_step = 39
nf_hxda_z_step = 40
nf_sim_z = 41
nf_fam_polar = 43
nf_fam_az = 44
nf_fam_dither_type = 45
nf_mono_init = 51
nf_mono_range = 52
nf_mono_step = 53
nf_defocus = 54
nf_acis_temp = 55
nf_tight = 59
nf_offset_y = 64
nf_offset_z = 65
while( getline < "xrcf_mnemonics.dat" > 0 ) {
mnemonic[$1] = $2
}
# "date" | getline date_line
# ADR: use a fixed date so that testing will work
date_line = "Sun Mar 10 23:00:27 EST 1996"
split(date_line, in_date, " ")
out_date = in_date[2] " " in_date[3] ", " in_date[6]
}
function add2output( variable ) {
#print("hi1") >> "debug"
NF++
#print("hi2") >> "debug"
$NF = variable
#print("hi3") >> "debug"
}
function error( ekey, message ) {
print "Error at input line " NR ", anode " ekey >> "errors.cleanup"
print " " message "." >> "errors.cleanup"
}
function hxda_na() {
$nf_hxda_aplist = $nf_hxda_y_range = $nf_hxda_z_range = "N/A"
$nf_hxda_y_step = $nf_hxda_z_step = "N/A"
}
function acis_na() {
$nf_acis_read = $nf_acis_proc = $nf_acis_frame = $nf_acis_temp = "N/A"
}
function hrc_na() {
# print ("hi") >> "debug"
}
function fpsi_na() {
acis_na()
hrc_na()
$nf_sim_z = $nf_fam_polar = $nf_fam_az = $nf_fam_dither_type = "N/A"
}
function mono_na() {
$nf_mono_init = $nf_mono_range = $nf_mono_step = "N/A"
}
# this gives the pitch and yaw of the HRMA and FAM
# positive pitch is facing the source "looking down"
# positive yaw is looking left
# 0 az is north 90 is up
# this also adds in the FAM X,Y,Z positions
function polaz2yawpitch(polar, az) {
theta = az * pi / 180
phi = polar * pi / 180 / 60
if( polar == 0 ) {
add2output( 0 )
add2output( 0 )
} else {
if(az == 0 || az == 180)
add2output( 0 )
else
add2output( - polar * sin(theta) )
# x = cos (phi)
# y = sin (phi) * cos (theta)
# add2output( atan2(y,x)*180 / pi * 60 )
if(az == 90 || az ==270 )
add2output( 0 )
else
add2output( - polar * cos(theta) )
}
# x = cos (phi)
# z= sin (phi) * sin (theta)
# add2output( atan2(z,x)*180 / pi * 60 )
if(config !~ /HXDA/) {
# negative values of defocus move us farther from the source thus
# increasing radius
radius = fullradius - defocus
# FAM_x; FAM_y; FAM_z
if((offset_y == 0) && (offset_z == 0)){
add2output( fullradius - radius * cos (phi) )
if (az == 90 || az ==270)
add2output( 0 )
else
add2output( radius * sin (phi) * cos (theta) )
if (az == 0 || az == 180)
add2output( 0 )
else
add2output( - radius * sin (phi) * sin (theta) )
} else {
# ******* THIS SEGMENT OF CODE IS NOT MATHEMATICALLY CORRECT FOR ****
# OFF AXIS ANGLES AND IS SUPPLIED AS A WORKAROUND SINCE IT WILL
# PROBABLY ONLY BE USED ON AXIS.
add2output( defocus )
add2output( offset_y )
add2output( offset_z )
}
} else {
add2output( "N/A" )
add2output( "N/A" )
add2output( "N/A" )
}
}
# set TIGHT/LOOSE to N/A if it is not one of the two allowed values
function tight_na() {
if( $nf_tight !~ /TIGHT|LOOSE/ ) {
$nf_tight == "N/A"
}
}
# this entry is used to give certain entries names
{
type = $nf_type
item = $nf_item
suite = $nf_suite
order = $nf_order
detector = $nf_detector
grating = $nf_grating
offset_y= $nf_offset_y
offset_z= $nf_offset_z
bnd = $nf_bnd
defocus = $nf_defocus
}
{
# make configuration parameter
# as well as setting configuration-dependent N/A values
if( $nf_bnd ~ "SCAN" ) {
# BND is scanning beam
config = "BND"
hxda_na()
fpsi_na()
} else {
if( grating == "NONE" ) {
config = "HRMA"
} else {
if( grating == "HETG" ) {
if( order != "Both" ) {
$nf_shutter = order substr($nf_shutter, \
index($nf_shutter, ",") )
}
} else {
order = "N/A"
}
config = "HRMA/" grating
}
if( detector ~ /ACIS|HRC/ ) {
detsys = detector
nsub = sub("-", ",", detsys)
config = config "/" detsys
hxda_na()
} else {
config = config "/HXDA"
fpsi_na()
if( detector == "HSI" ) {
hxda_na()
}
}
}
add2output( config )
if( $nf_src ~ /EIPS|Penning/ ) mono_na()
if( $nf_src == "Penning" ) $nf_voltage = "N/A"
itm = sprintf("%03d", item)
if(config in mnemonic) {
if( type in mnemonic ) {
ID = mnemonic[config] "-" mnemonic[type] "-" suite "." itm
add2output( ID )
} else {
error(type, "measurement type not in list")
}
} else {
error(config, "measurement configuration not in list")
}
# add date to output line
add2output( out_date )
# Convert HRMA polar and azimuthal angles to yaw and pitch
polaz2yawpitch($nf_hrma_polar, $nf_hrma_az)
# set TIGHT/LOOSE to N/A if it is not one of the two allowed values
tight_na()
# compute number of HXDA apertures
if( config ~ /HXDA/ && $nf_hxda_aplist != "N/A")
add2output( split( $nf_hxda_aplist, dummy, "," ) )
else
add2output( "N/A" )
# make sure the BND value is properly set
if($nf_bnd == "FIXED" && detector ~ /ACIS/)
$nf_bnd =bnd"-SYNC"
else
$nf_bnd = bnd"-FREE"
print
}
|