in reply to Managing structured data
#!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $sect_name = ""; # Name of section my $sect_unit = ""; # Units defaults to inches my $sect_depth = 0; # Distance from origin my $sect_plane = ""; # Plane, defaults to X-Y plane my $sect_num = 0; # Number of points my $file_name; my $fh; my $help = 0; my $_debug = 0; my $val1 = 0; my $val2 = 0; my %vector_hdr; # Headr information hash list my @vector_pts = (); # Array of x,y coordinates my $vector_str = ""; # my $top = 'xy'; my $bottom = 'yx'; my $right = 'zy'; my $left = 'yz'; my $front = 'zx'; my $back = 'xz'; GetOptions( 'file_name=s' => \$file_name, 'sect_name' => \$sect_name, 'sect_unit' => \$sect_unit, 'sect_depth' => \$sect_depth, 'sect_plane' => \$sect_plane, 'sect_num' => \$sect_num, 'help' => \$help, 'debug' => \$_debug, ); if(!$file_name){ print "No file was specified $!\n"; help(); exit; } #open file open($fh, $file_name) or die "Failed to open file $file_name: $!"; #process file content my $line_in; my $key; my $value; my $seq_num = 0; my $max = 0; my $plane; my $coord_x; my $coord_y; my $coord_z; while($line_in = <$fh>){ chomp $line_in; if($_debug){print "processing: $line_in\n";} if($line_in =~ m/^sect_/){ ($key, $value) = split(' ', $line_in); $vector_hdr{ $key } = $value; } else { # Put coordinates into 3D array # need test to skip lines with no data ($val1, $val2) = split(' ', $line_in); if($vector_hdr{'sect_plane'} =~ m/xy/){ $vector_pts[$seq_num][1] = $val1; $vector_pts[$seq_num][2] = $val2; $vector_pts[$seq_num][3] = $vector_hdr{'sect_depth'}; } # plot on front plane if($vector_hdr{'sect_plane'} =~ m/zx/){ $vector_pts[$seq_num][1] = $val2; $vector_pts[$seq_num][2] = $vector_hdr{'sect_depth'}; $vector_pts[$seq_num][3] = $val1; } # Plot on side plane if($vector_hdr{'sect_plane'} =~ m/zy/){ $vector_pts[$seq_num][1] = $vector_hdr{'sect_depth'}; $vector_pts[$seq_num][2] = $val2; $vector_pts[$seq_num][3] = $val1; } $seq_num = $seq_num + 1; } } exit;
|
|---|