github.com/benhoyt/goawk@v1.8.1/testdata/gawk/tweakfld.awk (about) 1 # To: bug-gnu-utils@prep.ai.mit.edu 2 # Cc: arnold@gnu.ai.mit.edu 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 # "date" | getline date_line 82 # ADR: use a fixed date so that testing will work 83 date_line = "Sun Mar 10 23:00:27 EST 1996" 84 split(date_line, in_date, " ") 85 out_date = in_date[2] " " in_date[3] ", " in_date[6] 86 } 87 88 function add2output( variable ) { 89 #print("hi1") >> "debug" 90 NF++ 91 #print("hi2") >> "debug" 92 $NF = variable 93 #print("hi3") >> "debug" 94 } 95 96 function error( ekey, message ) { 97 # print "Error at input line " NR ", anode " ekey >> "errors.cleanup" 98 # print " " message "." >> "errors.cleanup" 99 } 100 101 function hxda_na() { 102 $nf_hxda_aplist = $nf_hxda_y_range = $nf_hxda_z_range = "N/A" 103 $nf_hxda_y_step = $nf_hxda_z_step = "N/A" 104 } 105 106 function acis_na() { 107 $nf_acis_read = $nf_acis_proc = $nf_acis_frame = $nf_acis_temp = "N/A" 108 } 109 110 function hrc_na() { 111 # print ("hi") >> "debug" 112 } 113 114 function fpsi_na() { 115 acis_na() 116 hrc_na() 117 $nf_sim_z = $nf_fam_polar = $nf_fam_az = $nf_fam_dither_type = "N/A" 118 } 119 120 function mono_na() { 121 $nf_mono_init = $nf_mono_range = $nf_mono_step = "N/A" 122 } 123 124 # this gives the pitch and yaw of the HRMA and FAM 125 # positive pitch is facing the source "looking down" 126 # positive yaw is looking left 127 # 0 az is north 90 is up 128 # this also adds in the FAM X,Y,Z positions 129 130 function polaz2yawpitch(polar, az) { 131 theta = az * pi / 180 132 phi = polar * pi / 180 / 60 133 134 135 if( polar == 0 ) { 136 add2output( 0 ) 137 add2output( 0 ) 138 } else { 139 if(az == 0 || az == 180) 140 add2output( 0 ) 141 else 142 add2output( - polar * sin(theta) ) 143 144 145 # x = cos (phi) 146 # y = sin (phi) * cos (theta) 147 # add2output( atan2(y,x)*180 / pi * 60 ) 148 149 if(az == 90 || az ==270 ) 150 add2output( 0 ) 151 else 152 add2output( - polar * cos(theta) ) 153 154 } 155 # x = cos (phi) 156 # z= sin (phi) * sin (theta) 157 # add2output( atan2(z,x)*180 / pi * 60 ) 158 159 if(config !~ /HXDA/) { 160 # negative values of defocus move us farther from the source thus 161 # increasing radius 162 radius = fullradius - defocus 163 164 # FAM_x; FAM_y; FAM_z 165 if((offset_y == 0) && (offset_z == 0)){ 166 add2output( fullradius - radius * cos (phi) ) 167 168 if (az == 90 || az ==270) 169 add2output( 0 ) 170 else 171 add2output( radius * sin (phi) * cos (theta) ) 172 173 if (az == 0 || az == 180) 174 add2output( 0 ) 175 else 176 add2output( - radius * sin (phi) * sin (theta) ) 177 } else { 178 # ******* THIS SEGMENT OF CODE IS NOT MATHEMATICALLY CORRECT FOR **** 179 # OFF AXIS ANGLES AND IS SUPPLIED AS A WORKAROUND SINCE IT WILL 180 # PROBABLY ONLY BE USED ON AXIS. 181 add2output( defocus ) 182 add2output( offset_y ) 183 add2output( offset_z ) 184 } 185 186 } else { 187 add2output( "N/A" ) 188 add2output( "N/A" ) 189 add2output( "N/A" ) 190 } 191 } 192 193 # set TIGHT/LOOSE to N/A if it is not one of the two allowed values 194 function tight_na() { 195 if( $nf_tight !~ /TIGHT|LOOSE/ ) { 196 $nf_tight == "N/A" 197 } 198 } 199 200 # this entry is used to give certain entries names 201 { 202 type = $nf_type 203 item = $nf_item 204 suite = $nf_suite 205 order = $nf_order 206 detector = $nf_detector 207 grating = $nf_grating 208 offset_y= $nf_offset_y 209 offset_z= $nf_offset_z 210 bnd = $nf_bnd 211 defocus = $nf_defocus 212 } 213 214 { 215 # make configuration parameter 216 # as well as setting configuration-dependent N/A values 217 218 if( $nf_bnd ~ "SCAN" ) { 219 # BND is scanning beam 220 config = "BND" 221 hxda_na() 222 fpsi_na() 223 } else { 224 if( grating == "NONE" ) { 225 config = "HRMA" 226 } else { 227 if( grating == "HETG" ) { 228 if( order != "Both" ) { 229 $nf_shutter = order substr($nf_shutter, \ 230 index($nf_shutter, ",") ) 231 } 232 } else { 233 order = "N/A" 234 } 235 config = "HRMA/" grating 236 } 237 238 if( detector ~ /ACIS|HRC/ ) { 239 detsys = detector 240 nsub = sub("-", ",", detsys) 241 config = config "/" detsys 242 hxda_na() 243 } else { 244 config = config "/HXDA" 245 fpsi_na() 246 if( detector == "HSI" ) { 247 hxda_na() 248 } 249 } 250 } 251 252 add2output( config ) 253 254 if( $nf_src ~ /EIPS|Penning/ ) mono_na() 255 256 if( $nf_src == "Penning" ) $nf_voltage = "N/A" 257 258 itm = sprintf("%03d", item) 259 260 if(config in mnemonic) { 261 if( type in mnemonic ) { 262 ID = mnemonic[config] "-" mnemonic[type] "-" suite "." itm 263 add2output( ID ) 264 } else { 265 error(type, "measurement type not in list") 266 } 267 } else { 268 error(config, "measurement configuration not in list") 269 } 270 271 # add date to output line 272 add2output( out_date ) 273 274 # Convert HRMA polar and azimuthal angles to yaw and pitch 275 polaz2yawpitch($nf_hrma_polar, $nf_hrma_az) 276 277 # set TIGHT/LOOSE to N/A if it is not one of the two allowed values 278 tight_na() 279 280 # compute number of HXDA apertures 281 if( config ~ /HXDA/ && $nf_hxda_aplist != "N/A") 282 add2output( split( $nf_hxda_aplist, dummy, "," ) ) 283 else 284 add2output( "N/A" ) 285 286 # make sure the BND value is properly set 287 if($nf_bnd == "FIXED" && detector ~ /ACIS/) 288 $nf_bnd =bnd"-SYNC" 289 else 290 $nf_bnd = bnd"-FREE" 291 print 292 }