Blame test/tweakfld.awk

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