RDI_PD0_IO.pl
changeset 52 5b07a9b89aee
parent 51 148c092b3a09
child 55 540d6574caca
equal deleted inserted replaced
51:148c092b3a09 52:5b07a9b89aee
     1 #======================================================================
     1 #======================================================================
     2 #                    R D I _ P D 0 _ I O . P L 
     2 #                    R D I _ P D 0 _ I O . P L 
     3 #                    doc: Sat Jan 18 14:54:43 2003
     3 #                    doc: Sat Jan 18 14:54:43 2003
     4 #                    dlm: Sun Apr 12 20:02:30 2020
     4 #                    dlm: Tue Apr 14 21:43:23 2020
     5 #                    (c) 2003 A.M. Thurnherr
     5 #                    (c) 2003 A.M. Thurnherr
     6 #					 uE-Info: 123 72 NIL 0 0 72 0 2 4 NIL ofnI
     6 #					 uE-Info: 126 73 NIL 0 0 72 0 2 4 NIL ofnI
     7 #======================================================================
     7 #======================================================================
     8     
     8     
     9 # Read RDI PD0 binary data files (*.[0-9][0-9][0-9])
     9 # Read RDI PD0 binary data files (*.[0-9][0-9][0-9])
    10     
    10     
    11 # HISTORY:
    11 # HISTORY:
   119 #	Jun 30, 2019: - added dirty flag to prevent bad PD0 patching
   119 #	Jun 30, 2019: - added dirty flag to prevent bad PD0 patching
   120 #				  - added $show_progress
   120 #				  - added $show_progress
   121 #	Feb 13, 2020: - added support for $readDataProgress (to Jun 13 version)
   121 #	Feb 13, 2020: - added support for $readDataProgress (to Jun 13 version)
   122 #	Apr 12, 2020: - merged laptop and whoosher versions which both implemented
   122 #	Apr 12, 2020: - merged laptop and whoosher versions which both implemented
   123 #					progreass; not sure whether this merge is successful
   123 #					progreass; not sure whether this merge is successful
   124 	
   124 #				  - disabled duplicate ens detection, which turns reading into
       
   125 #					O(N^2) process
       
   126 #	Apr 14, 2020: - BUG: WBPens did not work for ens# > 65535 (high byte)	
   125     
   127     
   126 # FIRMWARE VERSIONS:
   128 # FIRMWARE VERSIONS:
   127 #	It appears that different firmware versions generate different file
   129 #	It appears that different firmware versions generate different file
   128 #	structures. Currently (Sep 2005) these routines have been tested
   130 #	structures. Currently (Sep 2005) these routines have been tested
   129 #	with the following firmware versions (as reported by [listHdr]):
   131 #	with the following firmware versions (as reported by [listHdr]):
   829 #		}
   831 #		}
   830 
   832 
   831 		sysread(WBRF,$buf,1) == 1 || die("$WBRcfn: $!");
   833 		sysread(WBRF,$buf,1) == 1 || die("$WBRcfn: $!");
   832 		$ensNo += unpack('C',$buf) << 16;
   834 		$ensNo += unpack('C',$buf) << 16;
   833 
   835 
   834 		for (my($i)=$ens; $i>0; $i--) {											# check for duplicate ens; e.g. 2018 S4P 24UL
   836 ##		CODE DISABLED BECAUSE IT TAKES TOO MUCH TIME ON LARGE FILES.
   835 			if (${$E}[$i]->{NUMBER} == $ensNo) {									
   837 ##		NOT SURE HOW COMMON DUPLICATE ENSEMBLES ARE.		
   836 				$RDI_PD0_IO::File_Dirty = 1;
   838 ##
   837 				print(STDERR "WARNING (RDI_PD0_IO): duplicate ensemble $ensNo skipped\n");
   839 ##		for (my($i)=$ens; $i>0; $i--) {											# check for duplicate ens; e.g. 2018 S4P 24UL
   838 				pop(@{$E});
   840 ##			if (${$E}[$i]->{NUMBER} == $ensNo) {									
   839 				$ens--;
   841 ##				$RDI_PD0_IO::File_Dirty = 1;
   840 				next ENSEMBLE;
   842 ##				print(STDERR "WARNING (RDI_PD0_IO): duplicate ensemble $ensNo skipped\n");
   841 			}
   843 ##				pop(@{$E});
   842 		}
   844 ##				$ens--;
       
   845 ##				next ENSEMBLE;
       
   846 ##			}
       
   847 ##		}
   843 		    
   848 		    
   844 		${$E}[$ens]->{NUMBER} = $ensNo;
   849 		${$E}[$ens]->{NUMBER} = $ensNo;
   845 	    
   850 	    
   846 		sysread(WBRF,$buf,30) == 30 || die("$WBRcfn: $!");
   851 		sysread(WBRF,$buf,30) == 30 || die("$WBRcfn: $!");
   847 		(${$E}[$ens]->{BUILT_IN_TEST_ERROR},${$E}[$ens]->{SPEED_OF_SOUND},
   852 		(${$E}[$ens]->{BUILT_IN_TEST_ERROR},${$E}[$ens]->{SPEED_OF_SOUND},
  1115         sysseek(WBRF,$start_ens+$ens_length+2,0) || die("$WBRcfn: $!");
  1120         sysseek(WBRF,$start_ens+$ens_length+2,0) || die("$WBRcfn: $!");
  1116 	} # ens loop
  1121 	} # ens loop
  1117 	print(STDERR "\n") if ($RDI_PD0_IO::show_progress);
  1122 	print(STDERR "\n") if ($RDI_PD0_IO::show_progress);
  1118 }
  1123 }
  1119 
  1124 
  1120 sub WBRdtaIndex($)
  1125 sub WBRdtaIndex($)																# return index of particular data type
  1121 {
  1126 {																				#	where index refers to data sections inside PD0 files
  1122 	my($trgid) = @_;
  1127 	my($trgid) = @_;
  1123 	our($ndt,$buf,$id,$start_ens,@WBRofs);
  1128 	our($ndt,$buf,$id,$start_ens,@WBRofs);
  1124 	
  1129 	
  1125 	for (my($di)=2; $di<$ndt; $di++) {
  1130 	for (my($di)=2; $di<$ndt; $di++) {
  1126 		sysseek(WBRF,$start_ens+$WBRofs[$di],0) || die("$WBRcfn: $!");
  1131 		sysseek(WBRF,$start_ens+$WBRofs[$di],0) || die("$WBRcfn: $!");
  1248 		#----------------------------------------------------------------------
  1253 		#----------------------------------------------------------------------
  1249 
  1254 
  1250 		sysseek(WBPF,$start_ens+$WBPofs[1]+2,0) || die("$WBPcfn: $!");
  1255 		sysseek(WBPF,$start_ens+$WBPofs[1]+2,0) || die("$WBPcfn: $!");
  1251 		sysread(WBPF,$buf,2) == 2 || die("$WBPcfn: $!");
  1256 		sysread(WBPF,$buf,2) == 2 || die("$WBPcfn: $!");
  1252 		my($ensNo) = unpack("v",$buf);											# only lower two bytes!!!
  1257 		my($ensNo) = unpack("v",$buf);											# only lower two bytes!!!
  1253 		sysseek(WBPF,$start_ens+$WBPofs[1]+13,0) || die("$WBPcfn: $!");			# jump to high byte
  1258 		sysseek(WBPF,$start_ens+$WBPofs[1]+11,0) || die("$WBPcfn: $!");			# jump to high byte
  1254 		sysread(WBPF,$buf,1) == 1 || die("$WBPcfn: $!");
  1259 		sysread(WBPF,$buf,1) == 1 || die("$WBPcfn: $!");
  1255 		$ensNo += unpack('C',$buf) << 16;
  1260 		$ensNo += unpack('C',$buf) << 16;
  1256 		die("ensNo = $ensNo (should be $dta->{ENSEMBLE}[$ens]->{NUMBER})\n")
  1261 		die("ensNo = $ensNo (should be $dta->{ENSEMBLE}[$ens]->{NUMBER})\n")
  1257 			unless ($ensNo == $dta->{ENSEMBLE}[$ens]->{NUMBER});
  1262 			unless ($ensNo == $dta->{ENSEMBLE}[$ens]->{NUMBER});
  1258 
  1263