Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to do matrix match and interpolation in perl?

Status
Not open for further replies.

wwq

Programmer
Jun 5, 2013
4
IE
Hi, I am a newbie to perl. I have two files and I want to match pattern from both to do interpolation calculation. So far I have been trying the code below. It cannot work. I have no idea and please help..


Perl:
my @array1 = <FILE1>; 
my $i=0;
my $line,
my @array2 = <FILE2>;
my $x,$y;
$x = 10;
$y = 250;

foreach my $row (@array1) {

chomp unless /^\)/;
my @list=split('\s',$row); #print "@list\n";
}

foreach my $line (@array2) {

	if ($line =~ m/main_name1/){  
		$a = $line;       }

for (my $i=0; $i <30; $i++) {

		if ($a =~ m/@list[i]/) {

print "$a\n";
}
}
}


file 1:

bb0
bc3
bd0
be0
bb0
bb5
bc3
bd5
bb0
bb5
bc3
bd5
bb0
bb5
bc3
bd5

file2:

name report
date:xx/xx/xxxx
-----------------------------------------

main_name1 ("the_file_name_8X10_bb0") {
/* this is a junk line */
index_1 ("0.1200000, 0.4800000, 1.2000000, 2.4000000, [highlight #EDD400]7.2000000, 12.0000000[/highlight], 24.0000000, 36.0000000") ;
index_2 ("16.0000000, 56.0000000, 96.0000000, 144.0300000, [highlight #EDD400]192.0000000, 256.0000000[/highlight], 320.0000000, 479.9000000, 800.0000000, 1200.0000000") ;
values ( "39.6636309, 59.1070318, 72.6976132, 86.7251080, 98.6390341, 112.5696930, 124.7442851, 150.6943227, 188.4133693, 220.8960581", "44.4041774, 64.1903482, 77.9177813, 92.1000906, 104.3426792, 118.6010917, 131.0899563, 157.8042314, 197.1439906, 231.1411201", "52.8052356, 72.7173741, 86.6670009, 100.9410486, 113.4063143, 127.9952311, 140.7229196, 168.1848141, 209.3378697, 245.1742359", "65.8845734, 85.9166962, 99.9534283, 114.2388318, 126.7928198, 141.5717011, 154.4555669, 182.2364133, 224.6724425, 262.1539516", "117.0780951, 137.2804785, 151.4523818, 165.7750354, [highlight #EDD400]178.2789707, 193.0143185[/highlight], 205.9712350, 233.8256283, 276.7105601, 315.3086544", "168.0926821, 188.3450711, 202.5068214, 216.8686836, [highlight #EDD400]229.4003443, 244.0858202[/highlight], 256.9792908, 284.7358553, 327.5081823, 365.9534220", "295.6953111, 315.9660636, 329.9845930, 344.5615819, 356.7884994, 371.8664446, 384.5206821, 412.2845518, 454.6702275, 493.1196474", "422.9423779, 443.1897970, 457.3997527, 471.7801320, 484.2643484, 499.0738412, 512.0028551, 539.5509984, 581.9306393, 620.2029936" );
}

main_name2 ("the_file_name_8X10_bb0") {
/* this is a junk line */
index_1 ("0.1200000, 0.4800000, 1.2000000, 2.4000000, [highlight #FCE94F]7.2000000, 12.0000000[/highlight], 24.0000000, 36.0000000") ;
index_2 ("16.0000000, 56.0000000, 96.0000000, 144.0500000, [highlight #EDD400]192.0000000, 256.0000000[/highlight], 320.0000000, 480.0000000, 800.0000000, 1200.0000000") ;
values ( "38.9031557, 59.3631057, 74.0414966, 89.7778356, 103.8467792, 120.5091944, 135.4761604, 168.9835348, 224.4149068, 280.3698790", "44.1658352, 64.9012577, 79.8573015, 95.7974826, 110.2348315, 127.3987077, 142.8483329, 177.3561724, 234.8787954, 293.1761448", "53.6827453, 74.5926291, 89.7411270, 105.7738063, 120.3785447, 137.9816340, 153.8481015, 189.3911151, 249.0834269, 310.3759865", "68.7519096, 89.8120395, 105.0088166, 121.0699791, 135.7020262,153.4412663, 169.4713737, 205.6045679, 266.6403766, 330.5321031", "128.2294100, 149.4841067, 164.7327108, 180.8346303, [highlight #EDD400]195.3443189, 212.8943462[/highlight], 228.7596102, 264.9764618, 326.4846668, 391.7089519", "187.5589563, 208.8225889, 224.0988039, 240.2305021, [highlight #EDD400]254.8329621, 272.3795708[/highlight], 288.0900116, 324.1648334, 385.5641251, 450.4454446", "335.9742994, 357.2249959, 372.5479456, 388.3683361, 402.7784289, 420.8079496, 436.4289668, 472.1778875, 533.6969353, 598.3536396", "484.5194493, 505.2830998, 520.5685830, 536.4717557, 551.0296415, 568.8878639, 584.6488867, 620.2409910, 681.6165449, 746.1500150" );
}
...
...
..
.

1) File 2 is a large file which contains different names(eg. [COLOR=bb0][/color]), index_values, and values. I would like to search extract data (name,index_1,index_2 and values) and do interpolation calculation based on file 1's names. Every value for index_1, index_2 and values will be differ for each name.
2) Given refer numbers 10 and 250 to do interpolation. when name from file 1 matched at main_name1 and main_name2 of file 2, search location of reference number 10 and 250 at index_1 and index_2 respectively. For example given, after matched bb0 (name from file 1) with main_name1, search reference number location. Location will in between range 7.2000000 (location 5th) and 12.0000000 (6th) while 250 will be in range 192.0000000 (5th) and 256.0000000 (6th).
3) Refer to obtained range ( [highlight #EDD400]7.2000000 and 12.0000000 && 192.0000000 and 256.0000000[/highlight]). We know that they are located at 5th and 6th && 5th and 6th of index_1 and index_2 respectively. Next for 'values' group, 5th and 6th (index_1) pointed to 5th and 6th row of 'values'. Now we can only refer to row 5th and 6th in 'values'. At row 5th, 5th (index_2) pointed to location 5th which is number 178.2789707, 6th (index_2) pointed to location 6th = 193.0143185. Do the same to row 6th. And we will get new 4 numbers of range which are 178.2789707,193.0143185 from row 5th and 229.4003443, 244.0858202 from row 6th.
4) Get bilinear interpolation based on the 4 numbers (1[highlight #EDD400]78.2789707,193.0143185[/highlight] and [highlight #EDD400]229.4003443, 244.0858202[/highlight]). Link
5) Do steps 2-4 for main_name2 according to file 1 name list. Each name from file 1 has 2 main names (main_name1 & main_name2).
6) Compare interpolation result from both main_name1 and main_name2. The larger interpolation will be max_interpolation while smaller will be min.

Result:

name max min
bb0
bc3
..
.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top