listHdr
author Andreas Thurnherr <ant@ldeo.columbia.edu>
Sat, 10 Apr 2021 05:52:17 -0400
changeset 58 78607e2e8add
parent 57 5a59411306ba
permissions -rwxr-xr-x
Nortek files

#!/usr/bin/perl
#======================================================================
#                    L I S T H D R 
#                    doc: Sat Jan 18 18:41:49 2003
#                    dlm: Wed Mar 17 22:53:25 2021
#                    (c) 2003 A.M. Thurnherr
#                    uE-Info: 50 35 NIL 0 0 72 10 2 4 NIL ofnI
#======================================================================

# Print useful info from the RDI BB header

# HISTORY:
#	Jan 18, 2003: - incepted as a test for [WorkhorseBinRead.pl]
#	Jan 19, 2003: - continued
#	Feb 14, 2003: - added BT setup params
#	Mar 15, 2003: - added and removed BATTERY
#	Feb 24, 2004: - corrected TRANSMIT_LAG_DISTANCE units
#	Feb 26, 2004: - added ENSEMBLE_LENGTH
#				  - added FIRMWARE
#	Mar  4, 2004: - added transducer orientation
#	Mar 30, 2004: - decified firmware output
#	Sep 14, 2005: - made BT data optional, dep. on NUMBER_OF_DATA_TYPES
#				  - added DATA_FORMAT & related
#	Sep 15, 2005: - change BinRead library name
#				  - compacted output format
#	Oct 30, 2005: - shuffled stuff, added DATA_FORMAT_VARIANT
#	Aug 21, 2006: - added CPU_SERIAL_NUMBER
#				  - added usage error
#	Sep 19, 2007: - adapted to new [RDI_BB_Read.pl] (not tested)
#	Jul  9, 2008: - added output regarding available sensors
#	Mar 20, 2013: - removed DATA_FORMAT stuff
#	Mar 25, 2013: - added INSTRUMENT_TYPE stuff instead
#   Apr 24, 2014: - BUG: USE_3_BEAM_ON_LOW_CORR was reported in water-track setup
#   Jul 12, 2014: - BUG: did not work with multiple input files
#                 - added -s)ummary option
#	Sep  9, 2014: - adapted to files with >7 data types
#				  - BUG: usage message was not produced on empty arglist
#	Jan  9, 2016: - added support for PRODUCER data field
#				  - updated getopts to current perl version
#				  - updated IO library name
#				  - adapted to [ADCP_tools_lib.pl]
#	Nov  9, 2016: - BUG: no error on missing files
#	Aug  7, 2017: - added LAG_LENGTH
#				  - added AMBIGUITY_VELOCITY
#	Aug  8, 2017: - added -l)ong listing
# 	Jun 13, 2019: - removed BT_PRESENT flag support
#	Jun 26, 2019: - added comment to the effect that BT setup cannot be listed
#					with this utility any more
#	Mar  6, 2021: - adapted to Nortek Signature data files
#	Mar 17, 2021: - updated HISTORY

use Getopt::Std;

($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+});
$ADCP_tools_minVersion = 2.1; 
require "$ADCP_TOOLS/ADCP_tools_lib.pl";

die("Usage: $0 [-s)ummary] [-l)ong listing] <PD0 file[...]>\n")
    unless (&getopts('ls') && @ARGV);

if ($opt_s) {
	print("#!/usr/bin/perl -S list\n");     
	chmod(0777&~umask,*STDOUT);
	print("#ANTS#FIELDS# {id} {serial_number} {transducer_frequency} {number_of_bins} {blanking_distance} {bin_length} {pulse_length}\n");
}

while ($ARGV[0] ne '') {
	die("$ARGV[0]: No such file or directory\n")
		unless (-f $ARGV[0]);
	
	my($valid) = readHeader($ARGV[0],\%hdr,$opt_s);
	print("$ARGV[0]:\n") unless ($opt_s);

	if ($opt_s) {														# summary ANTS output
		my($id) = $ARGV[0];
		if ($id =~ /^\w{5}\d{3}\.\d{3}/) {								# leave just deployment name for std RDI files
			$id =~ s/00[0-9]\.000//;										
			$id =~ s@^.*/([^/]+)@\1@;
		}
		if ($valid) {
			printf("%s %d %.1f %d %g %d %.1f\n",
				$id,$hdr{SERIAL_NUMBER},$hdr{BEAM_FREQUENCY},
				$hdr{N_BINS},$hdr{BLANKING_DISTANCE},$hdr{BIN_LENGTH},
	            $hdr{TRANSMITTED_PULSE_LENGTH});
	    } else {
			printf("%s [no complete ensemble in file]\n",$id);
	    }
		shift;
		next;
	}

	shift;
	print("    Instrument Characteristics:\n");

	printf("\tPRODUCER\t\t\t= %s\n",$hdr{PRODUCER});
	if (defined($hdr{SERIAL_NUMBER})) {
		printf("\tINSTRUMENT\t\t\t= %s #%d\n",$hdr{INSTRUMENT_TYPE},$hdr{SERIAL_NUMBER});
    } else {
		printf("\tINSTRUMENT_TYPE\t\t\t= %s\n",$hdr{INSTRUMENT_TYPE});
    }
	printf("\tCPU_SERIAL_NUMBER\t\t= %s\n",$hdr{CPU_SERIAL_NUMBER})
		if ($opt_l && ($hdr{INSTRUMENT_TYPE} ne 'Explorer')
				   && ($hdr{INSTRUMENT_TYPE} ne 'Signature'));
	printf("\tFIRMWARE\t\t\t= %d.%d\n",$hdr{CPU_FW_VER},$hdr{CPU_FW_REV});
	printf("\tBEAM_FREQUENCY\t\t\t= %.1f kHz\n",$hdr{BEAM_FREQUENCY});
	printf("\tBEAM_ANGLE\t\t\t= %d deg\n",$hdr{BEAM_ANGLE}) if $opt_l;
	printf("\tN_BEAMS\t\t\t\t= %d\n",$hdr{N_BEAMS}) if $opt_l;
	printf("\tTRANSMIT_LAG_DISTANCE\t\t= %g m\n",$hdr{TRANSMIT_LAG_DISTANCE}) if $opt_l;
	printf("\tLAG_LENGTH\t\t\t= %d\n",$hdr{LAG_LENGTH}) if $opt_l;
	printf("\tN_DEMODS\t\t\t= %d\n",$hdr{N_DEMODS}) if $opt_l && defined($hdr{N_DEMODS});
	printf("\tSPEED_OF_SOUND\t\t\t= %d m/s [%s]\n",
				$hdr{SPEED_OF_SOUND},
				$hdr{SSPEED_CALCULATED} ? 'using measurements' : 'from settings');
	printf("\tAMBIGUITY_VELOCITY\t\t= %.1f m/s\n",
				ambiguity_velocity($hdr{BEAM_FREQUENCY},$hdr{BEAM_ANGLE},$hdr{SPEED_OF_SOUND},$hdr{TRANSMIT_LAG_DISTANCE}))
					unless ($hdr{INSTRUMENT_TYPE} eq 'Signature');

	printf("\tEnvironmental Sensors\t\t: ");
	printf("PRESSURE ") 						if ($hdr{PRESSURE_SENSOR});
	printf("CONDUCTIVITY ") 					if ($hdr{CONDUCTIVITY_SENSOR});
	printf("TEMPERATURE ") 						if ($hdr{TEMPERATURE_SENSOR});
	printf("COMPASS ") 							if ($hdr{COMPASS});
	printf("PITCH ") 							if ($hdr{PITCH_SENSOR});
	printf("ROLL ") 							if ($hdr{ROLL_SENSOR});
	print("\n");

	if ($opt_l) {
		printf("\tHardware Flags\t\t\t: ");
		printf("XDUCER_HEAD_ATTACHED ") 		if ($hdr{XDUCER_HEAD_ATTACHED});
		printf("CONVEX_BEAM_PATTERN ")			if ($hdr{CONVEX_BEAM_PATTERN});
		printf("CONCAVE_BEAM_PATTERN ") 		if ($hdr{CONCAVE_BEAM_PATTERN});
	    print("\n");
	}

	if ($opt_l) {
		print("    File Format:\n");
#		printf("\tNUMBER_OF_DATA_TYPES\t\t= %d\n",$hdr{NUMBER_OF_DATA_TYPES});
		printf("\tDATA_TYPES\t\t\t: @{$hdr{DATA_TYPES}}\n");
		printf("\tFIXED_LEADER_BYTES\t\t= %4d bytes\n",$hdr{FIXED_LEADER_BYTES});
		printf("\tENSEMBLE_BYTES\t\t\t= %4d bytes\n",$hdr{ENSEMBLE_BYTES});
		printf("\tHEADER_BYTES\t\t\t= %4d bytes\n",$hdr{HEADER_BYTES});
		printf("\tVARIABLE_LEADER_BYTES\t\t= %4d bytes\n",$hdr{VARIABLE_LEADER_BYTES});
		printf("\tVELOCITY_DATA_BYTES\t\t= %4d bytes\n",$hdr{VELOCITY_DATA_BYTES})
			if defined($hdr{VELOCITY_DATA_BYTES});
		printf("\tCORRELATION_DATA_BYTES\t\t= %4d bytes\n",$hdr{CORRELATION_DATA_BYTES})
			if defined($hdr{CORRELATION_DATA_BYTES});
		printf("\tECHO_INTENSITY_DATA_BYTES\t= %4d bytes\n",$hdr{ECHO_INTENSITY_DATA_BYTES})
			if defined($hdr{ECHO_INTENSITY_DATA_BYTES});
		printf("\tPERCENT_GOOD_DATA_BYTES\t\t= %4d bytes\n",$hdr{PERCENT_GOOD_DATA_BYTES})
			if defined($hdr{PERCENT_GOOD_DATA_BYTES});
	}

	print("    Coordinate System:\n");

	printf("\tHEADING_ALIGNMENT_CORRECTION\t\t= %g deg\n",    
												$hdr{HEADING_ALIGNMENT_CORRECTION})
												if defined($hdr{HEADING_ALIGNMENT_CORRECTION});
	printf("\tHEADING_BIAS_CORRECTION\t\t= %g deg\n",
												$hdr{HEADING_BIAS_CORRECTION})
												if defined($hdr{HEADING_BIAS_CORRECTION});
	print("\tFlags\t\t\t\t: ");
	printf("BEAM_COORDINATES ") 				if ($hdr{BEAM_COORDINATES});
	printf("INSTRUMENT_COORDINATES ")			if ($hdr{INSTRUMENT_COORDINATES});
	printf("SHIP_COORDINATES ") 				if ($hdr{SHIP_COORDINATES});
	printf("EARTH_COORDINATES ")				if ($hdr{EARTH_COORDINATES});
	printf("PITCH_AND_ROLL_USED ")				if ($hdr{PITCH_AND_ROLL_USED});
	printf("BIN_MAPPING_ALLOWED ")				if ($hdr{ALLOW_BIN_MAPPING});
	printf("USE_3_BEAM_ON_LOW_CORR ")			if ($hdr{USE_3_BEAM_ON_LOW_CORR});
	print("\n");
	
	
	if ($hdr{SPEED_OF_SOUND_CALCULATED}) {
		print("    Speed-of-Sound Sensors Used:\n");
		printf("\tPRESSURE\n")					if ($hdr{SSPEED_USING_PRESS});
		printf("\tCOMPASS_USED\n")				if ($hdr{COMPASS_USED});
		printf("\tPITCH_SENSOR_USED\n")			if ($hdr{PITCH_SENSOR_USED});
		printf("\tROLL_SENSOR_USED\n")			if ($hdr{ROLL_SENSOR_USED});
		printf("\tCONDUCTIVITY_SENSOR_USED\n")  if ($hdr{CONDUCTIVITY_SENSOR_USED});
		printf("\tTEMPERATURE_SENSOR_USED\n")	if ($hdr{TEMPERATURE_SENSOR_USED});
		print("\n");
	}
	
	
	print("    Bin Setup:\n");
	printf("\tN_BINS\t\t\t\t= %d\n",			$hdr{N_BINS});
	printf("\tBLANKING_DISTANCE\t\t= %g m\n", $hdr{BLANKING_DISTANCE});
	printf("\tDISTANCE_TO_BIN1_CENTER\t\t= %g m\n",   
												$hdr{DISTANCE_TO_BIN1_CENTER});
	printf("\tBIN_LENGTH\t\t\t= %g m\n",		$hdr{BIN_LENGTH});
	printf("\tTRANSMITTED_PULSE_LENGTH\t= %g m\n",    
												$hdr{TRANSMITTED_PULSE_LENGTH});
	printf("\tRL_FIRST_BIN\t\t\t= %d\n",		$hdr{RL_FIRST_BIN})	if $opt_l;
	printf("\tRL_LAST_BIN\t\t\t= %d\n",			$hdr{RL_LAST_BIN})  if $opt_l;
	
	
	print("    Water-Track Setup:\n");
	printf("\tPINGS_PER_ENSEMBLE\t\t= %d\n",	$hdr{PINGS_PER_ENSEMBLE});
	printf("\tTIME_BETWEEN_PINGS\t\t= %g s\n",$hdr{TIME_BETWEEN_PINGS});
	printf("\tTRANSMIT_POWER\t\t\t= %d\n",	$hdr{TRANSMIT_POWER});
	printf("\tMIN_CORRELATION\t\t\t= %d\n",	$hdr{MIN_CORRELATION});
	printf("\tMIN_PERCENT_GOOD\t\t= %d %%\n",	$hdr{MIN_PERCENT_GOOD});
	printf("\tMAX_ERROR_VELOCITY\t\t= %g m/s\n",
												$hdr{MAX_ERROR_VELOCITY});
	printf("\tFALSE_TARGET_THRESHOLD\t\t= %d\n",
												$hdr{FALSE_TARGET_THRESHOLD})
												if defined($hdr{FALSE_TARGET_THRESHOLD});
	printf("\tFlags\t\t\t\t: ");
	printf("NARROW_BANDWIDTH ") 				if ($hdr{NARROW_BANDWIDTH});
	printf("WIDE_BANDWIDTH ")					if ($hdr{WIDE_BANDWIDTH});
	printf("TRANSMIT_POWER_MAX ")				if ($hdr{TRANSMIT_POWER_MAX});
	print("\n");

	#----------------------------------------------------------------------
	# BT code is never executed since BT_MODE is not set any more
	#----------------------------------------------------------------------

	if (defined($hdr{BT_MODE})) {
		print("    Bottom-Track Setup:\n");
		printf("\tBT_MODE\t\t\t\t= %d\n", 			$hdr{BT_MODE});
		printf("\tBT_PINGS_PER_ENSEMBLE\t\t= %d\n",
													$hdr{BT_PINGS_PER_ENSEMBLE});
		printf("\tBT_TIME_BEFORE_REACQUIRE\t= %g s\n",
													$hdr{BT_TIME_BEFORE_REACQUIRE});
		printf("\tBT_MIN_CORRELATION\t\t= %d\n",$hdr{BT_MIN_CORRELATION});
		printf("\tBT_MIN_EVAL_AMPLITUDE\t\t= %d\n",
													$hdr{BT_MIN_EVAL_AMPLITUDE});
		printf("\tBT_MIN_PERCENT_GOOD\t\t= %d %%\n",
													$hdr{BT_MIN_PERCENT_GOOD});
		printf("\tBT_MAX_ERROR_VELOCITY\t\t= %g m/s\n",
													$hdr{BT_MAX_ERROR_VELOCITY})
													if defined($hdr{BT_MAX_ERROR_VELOCITY});
		printf("\tBT_RL_MIN_SIZE\t\t\t= %g m\n",	$hdr{BT_RL_MIN_SIZE});
		printf("\tBT_RL_NEAR\t\t\t= %g m\n",		$hdr{BT_RL_NEAR});
		printf("\tBT_RL_FAR\t\t\t= %g m\n",		$hdr{BT_RL_FAR});
		printf("\tBT_MAX_TRACKING_DEPTH\t\t= %g m\n"
	                                        ,       $hdr{BT_MAX_TRACKING_DEPTH});
    }
}