/ Published in: Perl

Scans a file for a series of floating point numbers separated by spaces.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/perl # Usage in command line: perl <app> <file-to-be-converted> <width> <height> # e.g. <app> myGeo.geo 30 30 # Parse .geo file and reformat as REFRACT-style height data file my $origfile = $ARGV[0]; my $sizeX = $ARGV[1]; my $sizeY = $ARGV[2]; my $outfile = "refract_" . $origfile; my %hTmp; #open (OUT, ">$outfile") or die "Couldn't open output file: $!"; my $numPoints = 0; my $rowPoints = 0; my $dataOut = ""; while (my $sLine = <IN>) { #print "line\n"; #if ($sLine =~ m/^([-+]?([0-9]*\.)?[0-9]+) ([-+]?([0-9]*\.)?[0-9]+) ([-+]?([0-9]*\.)?[0-9]+) [-+]?([0-9]*\.)?[0-9]+/) { if ($sLine =~ m/^([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+$/ ) { my $x = $1; my $y = $2; my $z = $3; $dataOut .= "$myString "; $rowPoints++; if ($rowPoints >= $sizeX) { $dataOut .= "\n"; $rowPoints = 0; } $numPoints++; } } #close OUT; close IN; #print "Num points: $numPoints \n";
Comments
