I recently found a backup storage hard disk. This hard disk holds scripts and programs going back to 1998.
This specific perl script I am posting here is/was used to extract water depth data from p190 seismic files and convert it into a format Surfer could read and in turn generate images as the one below (image source: Schlumberger Water Services)
If I were to write this today I would probably write it rather differently, but alas it worked.
If I were to write this today I would probably write it rather differently, but alas it worked.
Pure nostalgia.
#!/opt/perl5/bin/perl # SUB ROUTINE DECLARATION sub GetFileBaseName; sub Grab_XYZ; sub Presentation1; sub Presentation2; sub Presentation3; # VARABLE DECLARATION @file_list = `ls -1 *.{p190,WGS84,tc,AGD84,AGD66,WGS-84,AGD-84,AGD-66,Kertau}`; chop @file_list; open (OUTFILE, ">surfer_file") or die ("Could not open surfer_file.\n"); # MAIN SCRIPT FLOW Presentation1; foreach $file (@file_list){ open (P190FILE, "$file") or die ("Could not open $file.\n"); $filebasename = GetFileBaseName($file); $shot_record = "S" . $filebasename; $counter = 0; print ("Filebasename: $filebasename\n"); $line = <P190FILE>; while ($line ne ""){ Grab_XYZ; } close (P190FILE); if ($counter == 0){ $status = "FAILED"; } else{ $status = "OK"; } Presentation2; } close (OUTFILE); Presentation3; # SUB ROUTINE IMPLEMENTATIONS sub Grab_XYZ{ if ($line =~ /$shot_record/){ $x = substr($line,46,9); $y = substr($line,55,9); $z = -substr($line,64,6); print OUTFILE ("$x $y $z\n"); $line = <P190FILE>; $counter++; #print ("$counter\n"); } else{ $line = <P190FILE>; } } sub GetFileBaseName { my ($input_str) = @_; my ($end_pos, $temp); if ($input_str =~/_/g){ $start_pos = pos ($input_str); } if ($input_str =~ /\./g){ $end_pos = pos ($input_str) - $start_pos ; } $temp = substr ($input_str, $start_pos, $end_pos-1); return ($temp); } sub Presentation1{ $~ = "MYFORMAT1"; write; } sub Presentation2{ $~ = "MYFORMAT2"; write; } sub Presentation3{ $~ = "MYFORMAT3"; write; } format MYFORMAT1 = ******************************************************************************** * | NUMBER OF VALUES GRABBED | * * FILE |-----------------------------------| STATUS * * | X | Y | Z | * ******************************************************************************** . format MYFORMAT2 = * @<<<<<<<<<<<<<<<<<<<<<<<<<< | @|||||| | @|||||| | @|||||| | @||||||| * $file $counter $counter $counter $status . format MYFORMAT3 = ******************************************************************************** * STATUS: FINISHED PROCESSING * * OUTPUT FILE: surfer_file * ******************************************************************************** Author : Kenneth Thorman Script : make_surfer_file Date : 26/4 - 1999 .
No comments:
Post a Comment