Re: inputting the ephemerides



In article <12dg1hj34pets$.p21zbcmg2lw8$.dlg@xxxxxxxxxx>, Larry Gates
<larry@xxxxxxxxxxxxxxx> wrote:

On Mon, 26 Jan 2009 17:37:55 -0800, Jim Gibson wrote:

Hope this helps.

Constructive comments do. Adding in the NOOP lines gives me the output I'm
looking for:

It was not the lines themselves that are "NOOP", as you have shown
yourself. It was the fact that you were applying them to a scalar
variable that was then ignored and over-written with the next input
line that made your lines "no-operations".


use strict;
use warnings;

# open input file
my $filename = 'eph9.txt';
open(my $fh, '<', $filename) or
die "cannot open $filename for reading: $!";

# open output file
my $filename2 = 'outfile11.txt';
open(my $gh, '>', $filename2) or
die "cannot open $filename2 for writing: $!";

# process all lines in input file
while( my $line = <$fh> ) {
chomp($line);

# get rid of °, + and ER
$line =~ s/ER//g;
$line =~ s/°//g;
$line =~ s/\+//g;
my @s = split /\s+/, $line;

# modify fields
$s[1] =~ s/h//;
$s[2] =~ s/m//;
$s[3] =~ s/s//;
$s[5] =~ s/'//;

# print modified fields
for my $i (0..$#s) {
print "s[$i] = $s[$i]\n";
}

# write modified fields to output file
my $outline = join(' ', @s);
print $gh "$outline\n";
}

# close input and output files
close($gh) or die("Error closing $filename2: $!");
close($fh) or die("Error closing $filename: $!");

__END__

# perl reg15.pl

C:\MinGW\source>type outfile11.txt
Sun 20 41 55 -18 15.1 0.985 31.290 28.986 Up
Mercury 19 37 21 -18 9.2 0.703 23.506 43.890 Up
Venus 23 38 15 -1 11.5 0.589 49.918 -29.062 Up
Moon 21 48 14 -11 42.6 62.2 42.389 12.334 Up
Mars 19 44 11 -22 12.5 2.363 21.142 39.928 Up
Jupiter 20 30 48 -19 23.6 6.088 29.121 31.156 Up
Saturn 11 30 46 5 30.8 8.631 -46.580 155.929 Set
Uranus 23 25 19 -4 32.5 20.818 47.940 -22.647 Up
Neptune 21 43 12 -14 4.3 30.982 39.839 13.351 Up
Pluto 18 8 33 -17 44.6 32.377 9.447 60.368 Up

C:\MinGW\source>

I'm gonna continue this on the fortran side. This was the hardest regex
I've done by the longest of shots, and I couldn't have done it without your
(plural) help.

Well in fact you didn't do it at all. I and several other people had to
write the code for you. Perl is much better suited for this type of
task than Fortran (I have coded in both). Sticking with Perl and
learning enough Perl to do this job would make you a better programmer.
However, they may not be your goal.

There is nothing difficult about this program. There are certainly no
hard regular expressions. There is a sequence of substitution
operators, each performing a simple task of removing something from
your input. I think you had problems with the concepts of reading and
writing files. Reading from one file and writing to another file is the
simplest way to deal with the problem of modifying a file.

Good luck with the Fortran.

--
Jim Gibson
.