| 1 |
# To: [email protected] |
| 2 |
# Cc: [email protected] |
| 3 |
# Date: Mon, 20 Nov 1995 11:39:29 -0500 |
| 4 |
# From: "R. Hank Donnelly" <emory!head-cfa.harvard.edu!donnelly> |
| 5 |
# |
| 6 |
# Operating system: Linux1.2.13 (Slackware distrib) |
| 7 |
# GAWK version: 2.15 (?) |
| 8 |
# compiler: GCC (?) |
| 9 |
# |
| 10 |
# The following enclosed script does not want to fully process the input data |
| 11 |
# file. It correctly executes the operations on the first record, and then dies |
| 12 |
# on the second one. My true data file is much longer but this is |
| 13 |
# representative and it does fail on a file even as short as this one. |
| 14 |
# The failure appears to occur in the declared function add2output. Between the |
| 15 |
# steps of incrementing NF by one and setting $NF to the passed variable |
| 16 |
# the passed variable appears to vanish (i.e. NF does go from 68 to 69 |
| 17 |
# and before incrementing it "variable" equals what it should but after |
| 18 |
# "variable" has no value at all.) |
| 19 |
# |
| 20 |
# The scripts have been developed using nawk on a Sun (where they run fine) |
| 21 |
# I have tried gawk there but get a different crash which I have not yet traced |
| 22 |
# down. Ideally I would like to keep the script the same so that it would run |
| 23 |
# on either gawk or nawk (that way I can step back and forth between laptop and |
| 24 |
# workstation. |
| 25 |
# |
| 26 |
# Any ideas why the laptop installation is having problems? |
| 27 |
# Hank |
| 28 |
# |
| 29 |
# |
| 30 |
# #!/usr/bin/gawk -f |
| 31 |
|
| 32 |
BEGIN { |
| 33 |
# set a few values |
| 34 |
FS = "\t" |
| 35 |
OFS = "\t" |
| 36 |
pi = atan2(0, -1) |
| 37 |
# distance from HRMA to focal plane in mm |
| 38 |
fullradius = 10260.54 |
| 39 |
|
| 40 |
# set locations of parameters on input line |
| 41 |
nf_nrg = 1 |
| 42 |
nf_order = 3 |
| 43 |
nf_item = 4 |
| 44 |
nf_suite = 5 |
| 45 |
nf_grating = 8 |
| 46 |
nf_shutter = 9 |
| 47 |
nf_type = 13 |
| 48 |
nf_src = 14 |
| 49 |
nf_target = 15 |
| 50 |
nf_voltage = 16 |
| 51 |
nf_flux = 17 |
| 52 |
nf_filt1 = 20 |
| 53 |
nf_filt1_th = 21 |
| 54 |
nf_filt2 = 22 |
| 55 |
nf_filt2_th = 23 |
| 56 |
nf_bnd = 24 |
| 57 |
nf_hrma_polar = 27 |
| 58 |
nf_hrma_az = 28 |
| 59 |
nf_detector = 30 |
| 60 |
nf_acis_read = 32 |
| 61 |
nf_acis_proc = 33 |
| 62 |
nf_acis_frame = 34 |
| 63 |
nf_hxda_aplist = 36 |
| 64 |
nf_hxda_y_range = 37 |
| 65 |
nf_hxda_z_range = 38 |
| 66 |
nf_hxda_y_step = 39 |
| 67 |
nf_hxda_z_step = 40 |
| 68 |
nf_sim_z = 41 |
| 69 |
nf_fam_polar = 43 |
| 70 |
nf_fam_az = 44 |
| 71 |
nf_fam_dither_type = 45 |
| 72 |
nf_mono_init = 51 |
| 73 |
nf_mono_range = 52 |
| 74 |
nf_mono_step = 53 |
| 75 |
nf_defocus = 54 |
| 76 |
nf_acis_temp = 55 |
| 77 |
nf_tight = 59 |
| 78 |
nf_offset_y = 64 |
| 79 |
nf_offset_z = 65 |
| 80 |
|
| 81 |
while( getline < "xrcf_mnemonics.dat" > 0 ) { |
| 82 |
mnemonic[$1] = $2 |
| 83 |
} |
| 84 |
|
| 85 |
# "date" | getline date_line |
| 86 |
# ADR: use a fixed date so that testing will work |
| 87 |
date_line = "Sun Mar 10 23:00:27 EST 1996" |
| 88 |
split(date_line, in_date, " ") |
| 89 |
out_date = in_date[2] " " in_date[3] ", " in_date[6] |
| 90 |
} |
| 91 |
|
| 92 |
function add2output( variable ) { |
| 93 |
#print("hi1") >> "debug" |
| 94 |
NF++ |
| 95 |
#print("hi2") >> "debug" |
| 96 |
$NF = variable |
| 97 |
#print("hi3") >> "debug" |
| 98 |
} |
| 99 |
|
| 100 |
function error( ekey, message ) { |
| 101 |
print "Error at input line " NR ", anode " ekey >> "errors.cleanup" |
| 102 |
print " " message "." >> "errors.cleanup" |
| 103 |
} |
| 104 |
|
| 105 |
function hxda_na() { |
| 106 |
$nf_hxda_aplist = $nf_hxda_y_range = $nf_hxda_z_range = "N/A" |
| 107 |
$nf_hxda_y_step = $nf_hxda_z_step = "N/A" |
| 108 |
} |
| 109 |
|
| 110 |
function acis_na() { |
| 111 |
$nf_acis_read = $nf_acis_proc = $nf_acis_frame = $nf_acis_temp = "N/A" |
| 112 |
} |
| 113 |
|
| 114 |
function hrc_na() { |
| 115 |
# print ("hi") >> "debug" |
| 116 |
} |
| 117 |
|
| 118 |
function fpsi_na() { |
| 119 |
acis_na() |
| 120 |
hrc_na() |
| 121 |
$nf_sim_z = $nf_fam_polar = $nf_fam_az = $nf_fam_dither_type = "N/A" |
| 122 |
} |
| 123 |
|
| 124 |
function mono_na() { |
| 125 |
$nf_mono_init = $nf_mono_range = $nf_mono_step = "N/A" |
| 126 |
} |
| 127 |
|
| 128 |
# this gives the pitch and yaw of the HRMA and FAM |
| 129 |
# positive pitch is facing the source "looking down" |
| 130 |
# positive yaw is looking left |
| 131 |
# 0 az is north 90 is up |
| 132 |
# this also adds in the FAM X,Y,Z positions |
| 133 |
|
| 134 |
function polaz2yawpitch(polar, az) { |
| 135 |
theta = az * pi / 180 |
| 136 |
phi = polar * pi / 180 / 60 |
| 137 |
|
| 138 |
|
| 139 |
if( polar == 0 ) { |
| 140 |
add2output( 0 ) |
| 141 |
add2output( 0 ) |
| 142 |
} else { |
| 143 |
if(az == 0 || az == 180) |
| 144 |
add2output( 0 ) |
| 145 |
else |
| 146 |
add2output( - polar * sin(theta) ) |
| 147 |
|
| 148 |
|
| 149 |
# x = cos (phi) |
| 150 |
# y = sin (phi) * cos (theta) |
| 151 |
# add2output( atan2(y,x)*180 / pi * 60 ) |
| 152 |
|
| 153 |
if(az == 90 || az ==270 ) |
| 154 |
add2output( 0 ) |
| 155 |
else |
| 156 |
add2output( - polar * cos(theta) ) |
| 157 |
|
| 158 |
} |
| 159 |
# x = cos (phi) |
| 160 |
# z= sin (phi) * sin (theta) |
| 161 |
# add2output( atan2(z,x)*180 / pi * 60 ) |
| 162 |
|
| 163 |
if(config !~ /HXDA/) { |
| 164 |
# negative values of defocus move us farther from the source thus |
| 165 |
# increasing radius |
| 166 |
radius = fullradius - defocus |
| 167 |
|
| 168 |
# FAM_x; FAM_y; FAM_z |
| 169 |
if((offset_y == 0) && (offset_z == 0)){ |
| 170 |
add2output( fullradius - radius * cos (phi) ) |
| 171 |
|
| 172 |
if (az == 90 || az ==270) |
| 173 |
add2output( 0 ) |
| 174 |
else |
| 175 |
add2output( radius * sin (phi) * cos (theta) ) |
| 176 |
|
| 177 |
if (az == 0 || az == 180) |
| 178 |
add2output( 0 ) |
| 179 |
else |
| 180 |
add2output( - radius * sin (phi) * sin (theta) ) |
| 181 |
} else { |
| 182 |
# ******* THIS SEGMENT OF CODE IS NOT MATHEMATICALLY CORRECT FOR **** |
| 183 |
# OFF AXIS ANGLES AND IS SUPPLIED AS A WORKAROUND SINCE IT WILL |
| 184 |
# PROBABLY ONLY BE USED ON AXIS. |
| 185 |
add2output( defocus ) |
| 186 |
add2output( offset_y ) |
| 187 |
add2output( offset_z ) |
| 188 |
} |
| 189 |
|
| 190 |
} else { |
| 191 |
add2output( "N/A" ) |
| 192 |
add2output( "N/A" ) |
| 193 |
add2output( "N/A" ) |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
# set TIGHT/LOOSE to N/A if it is not one of the two allowed values |
| 198 |
function tight_na() { |
| 199 |
if( $nf_tight !~ /TIGHT|LOOSE/ ) { |
| 200 |
$nf_tight == "N/A" |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
# this entry is used to give certain entries names |
| 205 |
{ |
| 206 |
type = $nf_type |
| 207 |
item = $nf_item |
| 208 |
suite = $nf_suite |
| 209 |
order = $nf_order |
| 210 |
detector = $nf_detector |
| 211 |
grating = $nf_grating |
| 212 |
offset_y= $nf_offset_y |
| 213 |
offset_z= $nf_offset_z |
| 214 |
bnd = $nf_bnd |
| 215 |
defocus = $nf_defocus |
| 216 |
} |
| 217 |
|
| 218 |
{ |
| 219 |
# make configuration parameter |
| 220 |
# as well as setting configuration-dependent N/A values |
| 221 |
|
| 222 |
if( $nf_bnd ~ "SCAN" ) { |
| 223 |
# BND is scanning beam |
| 224 |
config = "BND" |
| 225 |
hxda_na() |
| 226 |
fpsi_na() |
| 227 |
} else { |
| 228 |
if( grating == "NONE" ) { |
| 229 |
config = "HRMA" |
| 230 |
} else { |
| 231 |
if( grating == "HETG" ) { |
| 232 |
if( order != "Both" ) { |
| 233 |
$nf_shutter = order substr($nf_shutter, \ |
| 234 |
index($nf_shutter, ",") ) |
| 235 |
} |
| 236 |
} else { |
| 237 |
order = "N/A" |
| 238 |
} |
| 239 |
config = "HRMA/" grating |
| 240 |
} |
| 241 |
|
| 242 |
if( detector ~ /ACIS|HRC/ ) { |
| 243 |
detsys = detector |
| 244 |
nsub = sub("-", ",", detsys) |
| 245 |
config = config "/" detsys |
| 246 |
hxda_na() |
| 247 |
} else { |
| 248 |
config = config "/HXDA" |
| 249 |
fpsi_na() |
| 250 |
if( detector == "HSI" ) { |
| 251 |
hxda_na() |
| 252 |
} |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
add2output( config ) |
| 257 |
|
| 258 |
if( $nf_src ~ /EIPS|Penning/ ) mono_na() |
| 259 |
|
| 260 |
if( $nf_src == "Penning" ) $nf_voltage = "N/A" |
| 261 |
|
| 262 |
itm = sprintf("%03d", item) |
| 263 |
|
| 264 |
if(config in mnemonic) { |
| 265 |
if( type in mnemonic ) { |
| 266 |
ID = mnemonic[config] "-" mnemonic[type] "-" suite "." itm |
| 267 |
add2output( ID ) |
| 268 |
} else { |
| 269 |
error(type, "measurement type not in list") |
| 270 |
} |
| 271 |
} else { |
| 272 |
error(config, "measurement configuration not in list") |
| 273 |
} |
| 274 |
|
| 275 |
# add date to output line |
| 276 |
add2output( out_date ) |
| 277 |
|
| 278 |
# Convert HRMA polar and azimuthal angles to yaw and pitch |
| 279 |
polaz2yawpitch($nf_hrma_polar, $nf_hrma_az) |
| 280 |
|
| 281 |
# set TIGHT/LOOSE to N/A if it is not one of the two allowed values |
| 282 |
tight_na() |
| 283 |
|
| 284 |
# compute number of HXDA apertures |
| 285 |
if( config ~ /HXDA/ && $nf_hxda_aplist != "N/A") |
| 286 |
add2output( split( $nf_hxda_aplist, dummy, "," ) ) |
| 287 |
else |
| 288 |
add2output( "N/A" ) |
| 289 |
|
| 290 |
# make sure the BND value is properly set |
| 291 |
if($nf_bnd == "FIXED" && detector ~ /ACIS/) |
| 292 |
$nf_bnd =bnd"-SYNC" |
| 293 |
else |
| 294 |
$nf_bnd = bnd"-FREE" |
| 295 |
print |
| 296 |
} |