lib/App/SeismicUnixGui/sunix/NMO_Vel_Stk/sunmo.pm untested

filter: Statementstmt 0.0% 0 / 259 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 27 Podpod 0.0% 0 / 18 totaltotal 0.0% 0 / 337 CC 15 SCAR 15.5
CC
15
Cov
0%
_get_data_scale
6.0
cdp
6.0
invert
6.0
CRAP 4.7
1 package App::SeismicUnixGui::sunix::NMO_Vel_Stk::sunmo;
2  
3 =head1 DOCUMENTATION
4  
5 =head2 SYNOPSIS
6  
7 PROGRAM NAME: sunmo
8 AUTHOR: Juan Lorenzo (Perl module only)
9 DATE: Dec 1 2013
10 DESCRIPTION:
11 Version: 0.0.1
12 0.0.2 July 15, 2015 (JML)
13 0.0.3 Jan 14, 2020 (DLL)
14 0.0.4 Feb 06, 2020 (DLL)
15 =head2 USE
16  
17 =head3 NOTES
18  
19 =head4
20 Examples
21  
22 =head3 SEISMIC UNIX NOTES
23  
24 SUNMO - NMO for an arbitrary velocity function of time and CDP
25  
26 sunmo <stdin >stdout [optional parameters]
27  
28 Optional Parameters:
29 tnmo=0,... NMO times corresponding to velocities in vnmo
30 vnmo=1500,... NMO velocities corresponding to times in tnmo
31 cdp= CDPs for which vnmo & tnmo are specified (see Notes)
32 smute=1.5 samples with NMO stretch exceeding smute are zeroed
33 lmute=25 length (in samples) of linear ramp for stretch mute
34 sscale=1 =1 to divide output samples by NMO stretch factor
35 invert=0 =1 to perform (approximate) inverse NMO
36 upward=0 =1 to scan upward to find first sample to kill
37 voutfile= if set, interplolated velocity function v[cdp][t] is
38 output to named file.
39 Notes:
40 For constant-velocity NMO, specify only one vnmo=constant and omit tnmo.
41  
42 NMO interpolation error is less than 1 percent for frequencies less than
43 60 percent of the Nyquist frequency.
44  
45 Exact inverse NMO is impossible, particularly for early times at large
46 offsets and for frequencies near Nyquist with large interpolation errors.
47  
48 The "offset" header field must be set.
49 Use suazimuth to set offset header field when sx,sy,gx,gy are all
50 nonzero.
51  
52 For NMO with a velocity function of time only, specify the arrays
53 vnmo=v1,v2,... tnmo=t1,t2,...
54 where v1 is the velocity at time t1, v2 is the velocity at time t2, ...
55 The times specified in the tnmo array must be monotonically increasing.
56 Linear interpolation and constant extrapolation of the specified velocities
57 is used to compute the velocities at times not specified.
58 The same holds for the anisotropy coefficients as a function of time only.
59  
60 For NMO with a velocity function of time and CDP, specify the array
61 cdp=cdp1,cdp2,...
62 and, for each CDP specified, specify the vnmo and tnmo arrays as described
63 above. The first (vnmo,tnmo) pair corresponds to the first cdp, and so on.
64 Linear interpolation and constant extrapolation of 1/velocity^2 is used
65 to compute velocities at CDPs not specified.
66  
67 The format of the output interpolated velocity file is unformatted C floats
68 with vout[cdp][t], with time as the fast dimension and may be used as an
69 input velocity file for further processing.
70  
71 Note that this version of sunmo does not attempt to deal with anisotropy.
72 The version of sunmo with experimental anisotropy support is "sunmo_a
73  
74  
75 Credits:
76 SEP: Shuki Ronen, Chuck Sword
77 CWP: Shuki Ronen, Jack, Dave Hale, Bjoern Rommel
78 Modified: 08/08/98 - Carlos E. Theodoro - option for lateral offset
79 Modified: 07/11/02 - Sang-yong Suh -
80 added "upward" option to handle decreasing velocity function.
81 CWP: Sept 2010: John Stockwell
82 1. replaced Carlos Theodoro's fix
83 2. added the instruction in the selfdoc to use suazimuth to set
84 offset so that it accounts for lateral offset.
85 3. removed Bjoren Rommel's anisotropy stuff. sunmo_a is the
86 version with the anisotropy parameters left in.
87 4. note that scalel does not scale the offset field in
88 the segy standard.
89 Technical Reference:
90 The Common Depth Point Stack
91 William A. Schneider
92 Proc. IEEE, v. 72, n. 10, p. 1238-1254
93 1984
94  
95 Trace header fields accessed: ns, dt, delrt, offset, cdp, scalel
96  
97  
98 =head4 CHANGES and their DATES
99  
100 Juan Lorenzo July 15 2015
101 introduced "par" subroutine
102
103 V0.0.3 Jan 14 2020 automatic use of scalel
104  
105 =cut
106  
107 use Moose;
108 our $VERSION = '0.0.3';
109  
110 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
111 use aliased 'App::SeismicUnixGui::sunix::header::header_values';
112 use aliased 'App::SeismicUnixGui::misc::manage_files_by2';
113 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
114 use aliased 'App::SeismicUnixGui::misc::message';
115 use aliased 'App::SeismicUnixGui::misc::flow';
116  
117 use App::SeismicUnixGui::misc::control '0.0.3';
118 use aliased 'App::SeismicUnixGui::misc::control';
119  
120 my $get = L_SU_global_constants->new();
121 my $var = $get->var();
122 my $empty_string = $var->{_empty_string};
123  
124 my $sunmo = {
125 _base_file_name => '',
126 _cdp => '',
127 _invert => '',
128 _lmute => '',
129 _multi_gather_parfile => '',
130 _par => '',
131 _smute => '',
132 _sscale => '',
133 _scaled_par => '',
134 _tnmo => '',
135 _upward => '',
136 _vnmo => '',
137 _voutfile => '',
138 _Step => '',
139 _note => '',
140 };
141  
142 =head2 sub Step
143  
144 collects switches and assembles bash instructions
145 by adding the program name
146  
147 =cut
148  
149 sub Step {
150  
151 $sunmo->{_Step} = 'sunmo' . $sunmo->{_Step};
152 return ( $sunmo->{_Step} );
153  
154 }
155  
156 =head2 sub note
157  
158 collects switches and assembles bash instructions
159 by adding the program name
160  
161 =cut
162  
163 sub note {
164  
165 $sunmo->{_note} = 'sunmo' . $sunmo->{_note};
166 return ( $sunmo->{_note} );
167  
168 }
169  
170 =head2 sub clear
171  
172 =cut
173  
174 sub clear {
175 $sunmo->{_base_file_name} = '';
176 $sunmo->{_cdp} = '';
177 $sunmo->{_invert} = '';
178 $sunmo->{_lmute} = '';
179 $sunmo->{_smute} = '';
180 $sunmo->{_sscale} = '';
181 $sunmo->{_multi_gather_parfile} = '';
182 $sunmo->{_scaled_par} = '';
183 $sunmo->{_tnmo} = '';
184 $sunmo->{_upward} = '';
185 $sunmo->{_vnmo} = '';
186 $sunmo->{_voutfile} = '';
187 $sunmo->{_Step} = '';
188 $sunmo->{_note} = '';
189 }
190  
191 =head2 sub _get_data_scale
192  
193 get scalco or scalel from file header
194  
195 =cut
196  
197 sub _get_data_scale {
198 my ($self) = @_;
199  
200 =head2 instantiate class
201  
202 =cut
203  
204 # print("sunmo, _get_data_scale, _base_file_name=$sunmo->{_base_file_name}\n");
205  
206 my $sunmo = header_values->new();
207  
208 if ( defined $sunmo->{_base_file_name}
209 && $sunmo->{_base_file_name} ne $empty_string )
210 {
211 $sunmo->set_base_file_name( $sunmo->{_base_file_name} );
212 $sunmo->set_header_name('scalel');
213 my $data_scale = $sunmo->get_number();
214  
215 my $result = $data_scale;
216  
217 # print("sunmo, _get_data_scale, data_scale = $data_scale\n");
218 return ($result);
219  
220 }
221 else {
222  
223 my $data_scale = 1;
224 my $result = $data_scale;
225  
226 # print("sunmo, _get_data_scale, data_scale = 1:1\n");
227 return ($result);
228  
229 }
230 }
231  
232 =head2 sub cdp
233  
234  
235 =cut
236  
237 sub cdp {
238  
239 my ( $self, $cdp ) = @_;
240 if ($cdp) {
241  
242 $sunmo->{_cdp} = $cdp;
243 $sunmo->{_note} = $sunmo->{_note} . ' cdp=' . $sunmo->{_cdp};
244 $sunmo->{_Step} = $sunmo->{_Step} . ' cdp=' . $sunmo->{_cdp};
245  
246 }
247 else {
248 print("sunmo, cdp, missing cdp,\n");
249 }
250 }
251  
252 =head2 sub invert
253  
254  
255 =cut
256  
257 sub invert {
258  
259 my ( $self, $invert ) = @_;
260 if ( $invert ne $empty_string ) {
261  
262 $sunmo->{_invert} = $invert;
263 $sunmo->{_note} = $sunmo->{_note} . ' invert=' . $sunmo->{_invert};
264 $sunmo->{_Step} = $sunmo->{_Step} . ' invert=' . $sunmo->{_invert};
265  
266 }
267 else {
268 print("sunmo, invert, missing invert,\n");
269 }
270 }
271  
272 =head2 sub lmute
273  
274  
275 =cut
276  
277 sub lmute {
278  
279 my ( $self, $lmute ) = @_;
280 if ($lmute) {
281  
282 $sunmo->{_lmute} = $lmute;
283 $sunmo->{_note} = $sunmo->{_note} . ' lmute=' . $sunmo->{_lmute};
284 $sunmo->{_Step} = $sunmo->{_Step} . ' lmute=' . $sunmo->{_lmute};
285  
286 }
287 else {
288 print("sunmo, lmute, missing lmute,\n");
289 }
290 }
291  
292 =head2 sub par
293 V0.0.3 1-14-2020 DLL
294 automatic use of data_scale
295  
296 read par file (assume in m/s or ft/s)
297 scale a new output par file * data-scale
298 assign new output par file
299  
300 A typical parfile does only handles one gather
301 at a time
302  
303 =cut
304  
305 sub multi_gather_parfile {
306  
307 my ( $self, $par ) = @_;
308 if ( $par ne $empty_string ) {
309  
310 =head2 instantiate classes
311  
312 =cut
313  
314 my $files = manage_files_by2->new();
315 my $Project = Project_config->new();
316 my $control = control->new();
317  
318 =head2 declare local variables
319  
320 =cut
321  
322 my @parfile_in;
323 my @parfile_out;
324 my ( $inbound, $outbound );
325  
326 my $PL_SEISMIC = $Project->PL_SEISMIC;
327  
328 # par file names
329 $parfile_in[1] = $par;
330  
331 =head2 private definitions
332  
333 =cut
334  
335 $parfile_out[1] = '.temp_scaled_multi_gather_parfile_iVA';
336 $inbound = $PL_SEISMIC . '/' . $parfile_in[1];
337 $sunmo->{_scaled_par} = $PL_SEISMIC . '/' . $parfile_out[1];
338 $outbound = $sunmo->{_scaled_par};
339  
340 =head2 read i/p file
341 =cut
342  
343 $control->set_back_slashBgone($inbound);
344 $inbound = $control->get_back_slashBgone();
345  
346 my $ref_file_name = \$inbound;
347  
348 my ( $items_aref2, $numberOfItems_aref ) =
349 $files->read_par($ref_file_name);
350 my $row0_aref = @$items_aref2[0];
351 my @array_cdp_row = @$row0_aref;
352  
353 =head2 scale par file values
354  
355 =cut
356  
357 my @row_out;
358 my $row_out;
359 my $row;
360  
361 my @cdp_array = @array_cdp_row;
362 my $number_of_cdp_per_row = scalar @cdp_array;
363  
364 $row_out[1] = '.temp_row0';
365  
366 $row = $PL_SEISMIC . '/' . $row_out[1];
367  
368 open( my $fh, '>', $row );
369  
370 print $fh ("cdp=$cdp_array[1]");
371  
372 for ( my $i = 2 ; $i < $number_of_cdp_per_row ; $i++ ) {
373  
374 print $fh (",$cdp_array[$i]");
375  
376 }
377  
378 print $fh ("\n");
379  
380 close($fh);
381  
382 my $row1_sample = @$items_aref2[1];
383  
384 my @array_row1_sample = @$row1_sample;
385  
386 my $length_row1_sample = scalar @array_row1_sample;
387  
388 my $rowoutbound;
389  
390 my $array_columns = scalar @$items_aref2;
391  
392 # print("sunmo,par, number of rows $array_columns\n");
393  
394 for ( my $j = 1 ; $j < $array_columns ; $j += 2 ) {
395  
396 $parfile_out[1] = '.temp_row' . $j;
397  
398 $row_out = $PL_SEISMIC . '/' . $parfile_out[1];
399 $rowoutbound = $row_out;
400  
401 my $row_tnmo_aref = @$items_aref2[$j];
402  
403 my $row_vnmo_aref = @$items_aref2[ $j + 1 ];
404  
405 my @array_tnmo_row = @$row_tnmo_aref;
406  
407 # print("sunmo,par, tnmo_row @array_tnmo_row\n");
408  
409 my @array_vnmo_row = @$row_vnmo_aref;
410  
411 # print("sunmo,par, vnmo_row @array_vnmo_row\n");
412  
413 my $data_scale = _get_data_scale();
414  
415 # $data_scale = 100;
416  
417 for ( my $i = 1 ; $i < $length_row1_sample ; $i++ ) {
418  
419 $array_vnmo_row[$i] = $array_vnmo_row[$i] * $data_scale;
420  
421 }
422  
423 # print("sunmo,par,par, data_scale=$data_scale\n");
424 # print("$outbound, @array_tnmo_row, @array_vnmo_row \n");
425  
426 =head2 write new par file
427  
428  
429 =cut
430  
431 my $first_name = 'tnmo';
432 my $second_name = 'vnmo';
433 $files->write_multipar(
434 \$rowoutbound, \@array_cdp_row, \@array_tnmo_row,
435 \@array_vnmo_row, $first_name, $second_name
436 );
437  
438 }
439  
440 =head2 cat scaled par files
441  
442 =cut
443  
444 my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU;
445  
446 my $log = message->new();
447 my $run = flow->new();
448  
449 =head2 Declare
450  
451 local variables
452  
453 =cut
454  
455 my (@flow);
456 my (@items);
457 my $list = '';
458  
459 =head2 Set up a list of files for action
460  
461 my $file_name_list_in
462 my $file_name_list_out
463 my @file_name_list
464
465 =cut
466  
467 my $first_file_num = 1;
468 my $maxfile_num = $array_columns;
469  
470 # print("cat_max_file_num $maxfile_num \n");
471  
472 my $file_name_out = '.temp_scaled_multi_gather_parfile_iVA';
473 my $outboundcat = $PL_SEISMIC . '/' . $file_name_out;
474  
475 for ( my $i = $first_file_num ; $i < $maxfile_num ; $i = $i += 2 ) {
476  
477 $list = $list . $PL_SEISMIC . '/' . '.temp_row' . $i . ' ';
478  
479 }
480  
481 =head2 Set up FLOW
482  
483  
484 =cut
485  
486 my $cat = "cat $PL_SEISMIC/.temp_row0 $list > $outboundcat";
487  
488 =head2 RUN FLOW
489  
490  
491 =cut
492  
493 system($cat);
494  
495 =head2 LOG FLOW(s)
496  
497 to screen and FILE
498  
499 =cut
500  
501 print(" $cat\n");
502  
503 =head2 send to sunmo
504  
505 =cut
506  
507 # $sunmo->{_scaled_par} = $par;
508  
509 $sunmo->{_note} = $sunmo->{_note} . ' par=' . $sunmo->{_scaled_par};
510 $sunmo->{_Step} = $sunmo->{_Step} . ' par=' . $sunmo->{_scaled_par};
511  
512 }
513 else {
514 print("sunmo, par, missing par,\n");
515 }
516 }
517  
518 =head2 sub par
519 V0.0.3 1-14-2020 DLL
520 automatic use of data_scale
521  
522 read par file (assume in m/s or ft/s)
523 scale a new output par file * data-scale
524 assign new output par file
525  
526 A typical parfile does only handles one gather
527 at a time
528  
529 =cut
530  
531 sub par {
532  
533 my ( $self, $par ) = @_;
534 if ( $par ne $empty_string ) {
535  
536 print("sunmo, par file name in =$par\n");
537  
538 =head2 instantiate classes
539  
540 =cut
541  
542 my $files = manage_files_by2->new();
543 my $Project = Project_config->new();
544 my $control = control->new;
545  
546 =head2 declare local variables
547  
548 =cut
549  
550 my @parfile_in;
551 my @parfile_out;
552 my ( $inbound, $outbound );
553  
554 my $PL_SEISMIC = $Project->PL_SEISMIC;
555  
556 # par file names
557 $parfile_in[1] = $par;
558  
559 =head2 private definitions
560  
561 =cut
562  
563 $parfile_out[1] = '.temp_scaled_par_iVA';
564 $inbound = $PL_SEISMIC . '/' . $parfile_in[1];
565 $sunmo->{_scaled_par} = $PL_SEISMIC . '/' . $parfile_out[1];
566 $outbound = $sunmo->{_scaled_par};
567  
568 =head2 read i/p file
569 =cut
570  
571 $control->set_back_slashBgone($inbound);
572 $inbound = $control->get_back_slashBgone();
573  
574 my $ref_file_name = \$inbound;
575  
576 print("sunmo $inbound\n");
577  
578 my ( $items_aref2, $numberOfItems_aref ) =
579 $files->read_par($ref_file_name);
580  
581 my $no_rows = scalar @$items_aref2;
582  
583 print("sunmo,par, no_rows=$no_rows\n");
584  
585 my $row0_aref = @$items_aref2[0];
586  
587 print("sunmo,par, ARRAY ref inside ROW 0 $row0_aref\n");
588 my $row1_aref = @$items_aref2[1];
589  
590 print("sunmo,par, ARRAY ref inside ROW 1 $row1_aref\n");
591  
592 my @array_tnmo_row = @$row0_aref;
593  
594 print("sunmo,par, complete array values in row 0 @array_tnmo_row\n");
595 my @array_vnmo_row = @$row1_aref;
596  
597 print("sunmo,par, complete array values in row 1 @array_vnmo_row\n");
598  
599 my $length_tnmo_row = scalar @array_tnmo_row;
600 my $length_vnmo_row = scalar @array_vnmo_row;
601  
602 =head2 scale par file values
603  
604 =cut
605  
606 my $data_scale = _get_data_scale();
607  
608 # $data_scale = 100;
609  
610 for ( my $i = 1 ; $i < $length_vnmo_row ; $i++ ) {
611  
612 $array_vnmo_row[$i] = $array_vnmo_row[$i] * $data_scale;
613  
614 }
615  
616 print("sunmo,par,par, data_scale=$data_scale\n");
617  
618 =head2 write new par file
619  
620  
621 =cut
622  
623 my $first_name = 'tnmo';
624 my $second_name = 'vnmo';
625 $files->write_par( \$outbound, \@array_tnmo_row, \@array_vnmo_row,
626 $first_name, $second_name );
627 print("sunmo,par,first_name:$first_name,second_name:$second_name\n");
628  
629 =head2 send to sunmo
630  
631 =cut
632  
633 $sunmo->{_note} = $sunmo->{_note} . ' par=' . $sunmo->{_scaled_par};
634 $sunmo->{_Step} = $sunmo->{_Step} . ' par=' . $sunmo->{_scaled_par};
635  
636 }
637 else {
638 print("sunmo, par, missing par,\n");
639 }
640 }
641  
642 =head2 sub smute
643  
644  
645 =cut
646  
647 sub smute {
648  
649 my ( $self, $smute ) = @_;
650 if ($smute) {
651  
652 $sunmo->{_smute} = $smute;
653 $sunmo->{_note} = $sunmo->{_note} . ' smute=' . $sunmo->{_smute};
654 $sunmo->{_Step} = $sunmo->{_Step} . ' smute=' . $sunmo->{_smute};
655  
656 }
657 else {
658 print("sunmo, smute, missing smute,\n");
659 }
660 }
661  
662 =head2 sub sscale
663  
664  
665 =cut
666  
667 sub sscale {
668 my ( $self, $sscale ) = @_;
669 if ($sscale) {
670  
671 $sunmo->{_sscale} = $sscale;
672 $sunmo->{_note} = $sunmo->{_note} . ' sscale=' . $sunmo->{_sscale};
673 $sunmo->{_Step} = $sunmo->{_Step} . ' sscale=' . $sunmo->{_sscale};
674  
675 }
676 else {
677 print("sunmo, sscale, missing sscale,\n");
678 }
679 }
680  
681 =head2 sub set_base_file_name
682  
683 =cut
684  
685 sub set_base_file_name {
686  
687 my ( $self, $base_file_name ) = @_;
688  
689 if ( $base_file_name ne $empty_string ) {
690  
691 $sunmo->{_base_file_name} = $base_file_name;
692 print("header_values,set_base_file_name,$sunmo->{_base_file_name}\n");
693  
694 }
695 else {
696 print("header_values,set_base_file_name, missing base file name\n");
697 }
698  
699 return ();
700  
701 }
702  
703 =head2 sub tnmo
704  
705  
706 =cut
707  
708 sub tnmo {
709  
710 my ( $self, $tnmo ) = @_;
711 if ( $tnmo ne $empty_string ) {
712  
713 $sunmo->{_tnmo} = $tnmo;
714 $sunmo->{_note} = $sunmo->{_note} . ' tnmo=' . $sunmo->{_tnmo};
715 $sunmo->{_Step} = $sunmo->{_Step} . ' tnmo=' . $sunmo->{_tnmo};
716  
717 }
718 else {
719 print("sunmo, tnmo, missing tnmo,\n");
720 }
721 }
722  
723 =head2 sub upward
724  
725  
726 =cut
727  
728 sub upward {
729  
730 my ( $self, $upward ) = @_;
731 if ( $upward ne $empty_string ) {
732  
733 $sunmo->{_upward} = $upward;
734 $sunmo->{_note} = $sunmo->{_note} . ' upward=' . $sunmo->{_upward};
735 $sunmo->{_Step} = $sunmo->{_Step} . ' upward=' . $sunmo->{_upward};
736  
737 }
738 else {
739 print("sunmo, upward, missing upward,\n");
740 }
741 }
742  
743 =head2 sub vnmo
744  
745  
746 =cut
747  
748 sub vnmo {
749  
750 my ( $self, $vnmo ) = @_;
751 if ($vnmo) {
752  
753 $sunmo->{_vnmo} = $vnmo;
754 $sunmo->{_note} = $sunmo->{_note} . ' vnmo=' . $sunmo->{_vnmo};
755 $sunmo->{_Step} = $sunmo->{_Step} . ' vnmo=' . $sunmo->{_vnmo};
756  
757 }
758 else {
759 print("sunmo, vnmo, missing vnmo,\n");
760 }
761 }
762  
763 =head2 sub vnmo_mps
764  
765  
766 =cut
767  
768 sub vnmo_mps {
769  
770 my ( $self, $vnmo ) = @_;
771 if ($vnmo) {
772  
773 $sunmo->{_vnmo} = $vnmo;
774 $sunmo->{_note} = $sunmo->{_note} . ' vnmo=' . $sunmo->{_vnmo};
775 $sunmo->{_Step} = $sunmo->{_Step} . ' vnmo=' . $sunmo->{_vnmo};
776  
777 }
778 else {
779 print("sunmo, vnmo, missing vnmo,\n");
780 }
781 }
782  
783 =head2 sub voutfile
784  
785  
786 =cut
787  
788 sub voutfile {
789  
790 my ( $self, $voutfile ) = @_;
791 if ($voutfile) {
792  
793 $sunmo->{_voutfile} = $voutfile;
794 $sunmo->{_note} = $sunmo->{_note} . ' voutfile=' . $sunmo->{_voutfile};
795 $sunmo->{_Step} = $sunmo->{_Step} . ' voutfile=' . $sunmo->{_voutfile};
796  
797 }
798 else {
799 print("sunmo, voutfile, missing voutfile,\n");
800 }
801 }
802  
803 =head2 sub get_max_index
804
805 max index = number of input variables -1
806
807 =cut
808  
809 sub get_max_index {
810 my ($self) = @_;
811 my $max_index = 10;
812  
813 return ($max_index);
814 }
815  
816 1;