RDI_PD0_IO.pl
changeset 36 515b06dae59c
parent 32 7155adf61d77
child 37 40d85448debf
equal deleted inserted replaced
35:7c394a2d1fc9 36:515b06dae59c
     1 #======================================================================
     1 #======================================================================
     2 #                    R D I _ P D 0 _ I O . P L 
     2 #                    R D I _ B B _ R E A D . P L 
     3 #                    doc: Sat Jan 18 14:54:43 2003
     3 #                    doc: Sat Jan 18 14:54:43 2003
     4 #                    dlm: Mon Feb 29 12:30:04 2016
     4 #                    dlm: Sat Jul 30 18:34:46 2016
     5 #                    (c) 2003 A.M. Thurnherr
     5 #                    (c) 2003 A.M. Thurnherr
     6 #                    uE-Info: 1232 63 NIL 0 0 72 10 2 4 NIL ofnI
     6 #                    uE-Info: 402 62 NIL 0 0 72 10 2 4 NIL ofnI
     7 #======================================================================
     7 #======================================================================
     8 
     8 
     9 # Read RDI BroadBand Binary Data Files (*.[0-9][0-9][0-9])
     9 # Read RDI BroadBand Binary Data Files (*.[0-9][0-9][0-9])
    10 
    10 
    11 # HISTORY:
    11 # HISTORY:
    73 #				  - added support for patching coordinate system
    73 #				  - added support for patching coordinate system
    74 #	Feb 16, 2016: - added transducer orientation to WBPens()
    74 #	Feb 16, 2016: - added transducer orientation to WBPens()
    75 #				  - BUG: most WBPens() error messages used wrong file name
    75 #				  - BUG: most WBPens() error messages used wrong file name
    76 #	Feb 23, 2016: - changed WBRhdr() to use 2nd ensemble (with correct data-source id)
    76 #	Feb 23, 2016: - changed WBRhdr() to use 2nd ensemble (with correct data-source id)
    77 #	Feb 26, 2016: - added basic BT data to WBPens(); not BT_RL_* and BT_SIGNAL_STRENGTH
    77 #	Feb 26, 2016: - added basic BT data to WBPens(); not BT_RL_* and BT_SIGNAL_STRENGTH
    78 #	Feb 29, 2016: - LEAP DAY: actually got BT data to work
    78 #	Feb 29, 2016: - LEAP DAY: actually got BT data patching to work
       
    79 #	Jul 30, 2016: - BUG: incomplete last ensemble with garbage content was returned on reading
       
    80 #						 WH300 data
    79 
    81 
    80 # FIRMWARE VERSIONS:
    82 # FIRMWARE VERSIONS:
    81 #	It appears that different firmware versions generate different file
    83 #	It appears that different firmware versions generate different file
    82 #	structures. Currently (Sep 2005) these routines have been tested
    84 #	structures. Currently (Sep 2005) these routines have been tested
    83 #	with the following firmware versions (as reported by [listHdr]):
    85 #	with the following firmware versions (as reported by [listHdr]):
   388 
   390 
   389 	skip_initial_trash();
   391 	skip_initial_trash();
   390 	sysread(WBRF,$buf,6) == 6 || die("$WBRcfn: $!");
   392 	sysread(WBRF,$buf,6) == 6 || die("$WBRcfn: $!");
   391 	($hid,$did,$dta->{ENSEMBLE_BYTES},$dummy,$dta->{NUMBER_OF_DATA_TYPES})
   393 	($hid,$did,$dta->{ENSEMBLE_BYTES},$dummy,$dta->{NUMBER_OF_DATA_TYPES})
   392 		= unpack('CCvCC',$buf);
   394 		= unpack('CCvCC',$buf);
   393 	$hid == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header",$hid,0));
   395 	$hid == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header (hid)",$hid,0));
   394 	$did == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header",$did,0));
   396 	$did == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header (did)",$did,0));
   395 
   397 
   396 	$start_ens = sysseek(WBRF,$dta->{ENSEMBLE_BYTES}-6+2,1) || die("$WBRcfn: $!");
   398 	$start_ens = sysseek(WBRF,$dta->{ENSEMBLE_BYTES}-6+2,1) || die("$WBRcfn: $!");
   397 	sysread(WBRF,$buf,6) == 6 || die("$WBRcfn: $!");
   399 	sysread(WBRF,$buf,6) == 6 || die("$WBRcfn: $!");
   398 	($hid,$did,$dta->{ENSEMBLE_BYTES},$dummy,$dta->{NUMBER_OF_DATA_TYPES})
   400 	($hid,$did,$dta->{ENSEMBLE_BYTES},$dummy,$dta->{NUMBER_OF_DATA_TYPES})
   399 		= unpack('CCvCC',$buf);
   401 		= unpack('CCvCC',$buf);
   400 	$hid == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header",$hid,0));
   402 	$hid == 0x7f || die(sprintf($FmtErr,$WBRcfn,"Header (hid2)",$hid,0));
   401 	$dta->{DATA_SOURCE_ID} = $did;
   403 	$dta->{DATA_SOURCE_ID} = $did;
   402 	if ($did == 0x7f) {
   404 	if ($did == 0x7f) {
   403 		$dta->{PRODUCER} = 'TRDI ADCP';
   405 		$dta->{PRODUCER} = 'TRDI ADCP';
   404 	} elsif (($did&0xF0) == 0xA0) {
   406 	} elsif (($did&0xF0) == 0xA0) {
   405 		$dta->{PRODUCER} = 'IMP+LADCP (Thurnherr software)';
   407 		$dta->{PRODUCER} = 'IMP+LADCP (Thurnherr software)';
   694 		# UH BB150 writes incomplete ensembles (i.e. short read
   696 		# UH BB150 writes incomplete ensembles (i.e. short read
   695 		# indicates EOF). FSU WH300 has bogus data in incomplete
   697 		# indicates EOF). FSU WH300 has bogus data in incomplete
   696 		# final ensemble.
   698 		# final ensemble.
   697 
   699 
   698 		sysseek(WBRF,$start_ens,0) || die("$WBRcfn: $!");
   700 		sysseek(WBRF,$start_ens,0) || die("$WBRcfn: $!");
   699 		sysread(WBRF,$buf,$ens_length) == $ens_length || last;
   701 		unless ((sysread(WBRF,$buf,$ens_length) == $ens_length) &&
   700 
   702 				(sysread(WBRF,$cs,2) == 2)) {
   701 		sysread(WBRF,$cs,2) == 2 || last;
   703 			pop(@{$E});
   702 		last unless (unpack('%16C*',$buf) == unpack('v',$cs));
   704 			last;
       
   705 		}
       
   706 
       
   707 		pop(@{$E}),last unless (unpack('%16C*',$buf) == unpack('v',$cs));
   703 
   708 
   704 		#------------------------------
   709 		#------------------------------
   705 		# Variable Leader
   710 		# Variable Leader
   706 		#------------------------------
   711 		#------------------------------
   707 	
   712 	
   780 			${$E}[$ens]->{PRESSURE_STDDEV} /= 1000;
   785 			${$E}[$ens]->{PRESSURE_STDDEV} /= 1000;
   781 			${$E}[$ens]->{YEAR} *= 100; ${$E}[$ens]->{YEAR} += $B3;
   786 			${$E}[$ens]->{YEAR} *= 100; ${$E}[$ens]->{YEAR} += $B3;
   782 			${$E}[$ens]->{SECONDS} += $B4/100;
   787 			${$E}[$ens]->{SECONDS} += $B4/100;
   783 		}
   788 		}
   784 
   789 
   785 		pop(@{$E}),last if (${$E}[$ens]->{MONTH}>12);						# 10/15/2014; IWISE#145 UL ???
   790 # 		THE FOLLOWING LINE OF CODE WAS REMOVED 7/30/2016 WHEN I ADDED A POP
       
   791 #		TO THE last STATEMENT ABOVE (INCOMPLETE ENSEMBLE)
       
   792 #		pop(@{$E}),last if (${$E}[$ens]->{MONTH}>12);						# 10/15/2014; IWISE#145 UL ???
   786 
   793 
   787 		if ($fixed_leader_bytes == 58) {									# Explorer DVL
   794 		if ($fixed_leader_bytes == 58) {									# Explorer DVL
   788 			sysread(WBRF,$buf,14) == 14 || die("$WBRcfn: $!");
   795 			sysread(WBRF,$buf,14) == 14 || die("$WBRcfn: $!");
   789 			(${$E}[$ens]->{ERROR_STATUS_WORD},
   796 			(${$E}[$ens]->{ERROR_STATUS_WORD},
   790 		 	 $dummy,${$E}[$ens]->{PRESSURE},${$E}[$ens]->{PRESSURE_STDDEV})
   797 		 	 $dummy,${$E}[$ens]->{PRESSURE},${$E}[$ens]->{PRESSURE_STDDEV})
  1185 		#-----------------------------------------
  1192 		#-----------------------------------------
  1186 
  1193 
  1187 		my($nxt);
  1194 		my($nxt);
  1188 		for ($nxt=6; $nxt<$ndt; $nxt++) {										# scan until BT found
  1195 		for ($nxt=6; $nxt<$ndt; $nxt++) {										# scan until BT found
  1189 			sysseek(WBPF,$start_ens+$WBPofs[$nxt],0) || die("$WBPcfn: $!");
  1196 			sysseek(WBPF,$start_ens+$WBPofs[$nxt],0) || die("$WBPcfn: $!");
  1190 			sysread(WBPF,$buf,2) == 2 || die("$WBPcfn: $!");
  1197 			sysread(WBPF,$buf,2) == 2 || die("$WBPcfn: $! [ens=$ens]");
  1191 			$id = unpack('v',$buf);
  1198 			$id = unpack('v',$buf);
  1192 			last if ($id == 0x0600);
  1199 			last if ($id == 0x0600);
  1193 		}
  1200 		}
  1194 
  1201 
  1195 		unless ($nxt == $ndt) {													# BT found
  1202 		unless ($nxt == $ndt) {													# BT found