inputting the ephemerides

T

Tim Greer

It only took up .1 of a single IQ to figure that out. Americans.. jeez

sln

Yes, yes, "all" Americans are dumb compared to you, and "all" Americans
are the same. Okay then.
 
T

Tim Greer

Larry said:
Tim,

I'd appreciate if you didn't respond to someone I, as OP, killfiled on
this
thread. Thx.

Add a filter so you don't see people replying to him (or killfile me,
too, if that's easier).
 
U

Uri Guttman

LG> my $filename = 'eph6.txt';
LG> my $filename2 = 'outfile1.txt';
LG> open(my $fh, '<', $filename) or die "cannot open $filename: $!";
LG> open(my $gh, $filename2) or die "cannot open $filename2: $!";LG> while (my $line = <$fh>) {
LG> $line =~ s/\t/ /g;
LG> $line =~ s/ER/ /g;
LG> $line =~ s/°/ /g;
LG> }
LG> close($fh);
JE> If at least he would write them out. But he is reading them, modifying
JE> the read text, and then discarding the modified text by overwriting it
JE> with the next line from the file.

yes, but he THINKS he is writing it out. the whole subthread on using
seek and its constants makes even less sense now that he isn't writing
out the modified text. i would still like to know why he thinks he needs
to write it out and then read it in together. this illogic is beyond
merely learning a new language and its quirks but seems to be a poor
understanding of basic data flow. this is more than coding fortran or c
in any language.

uri
 
L

Larry Gates

I agree.

Have you read "The camel has two humps"?
http://www.cs.mdx.ac.uk/research/PhDArea/saeed/paper1.pdf *

Some people fall into the "inconsistent" group - looking for meaning
where it does not exist. These people will probably not succeed as
programmers despite their intelligence and capacity for success in other
fields.

Just my ¤0.02 worth.

It makes for an interesting skim. I thought it was going to tie into perl
with the camel reference, but it instead points to bi-modal achievement.

I popped in on my uncle a few years back, who is director of mathematical
comp sci at SLU. He was finishing up a course in logic design and saw
exactly the same curve. The one hump got A's and B's, the other, CDF.

I got an A in fortran at BYU, something that Uri Guttman won't believe.
--
larry gates

That being said, I think we should immediately deprecate any string
concatenation that combines "19" with "99". :)
-- Larry Wall in <[email protected]>
 
L

Larry Gates

Hope this helps.

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

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.

Above is the current ephemeris for Albuquerque. The sun is almost on top
of Jupiter, rendering him invisible. Well ahead of it on the ecliptic is
Pluto. Closer in to the the sun are Mercury and Mars together. They must
be visible as morning stars. Neptune is almost in the same place as the
new Moon, both invisible. Saturn is invisible above China. Uranus is near
Venus, which is the only planet that offers convenient viewing. She has
started her pro-grade motion, which is in the direction of the greater
planets.

Cheers,
--
larry gates

It is, of course, written in Perl. Translation to C is left as an
exercise for the reader. :) -- Larry Wall in
<[email protected]>
 
J

Jim Gibson

Larry Gates said:
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.
 
L

Larry Gates

s[0] = Moon
s[1] = 21
s[2] = 10
s[3] = 19
s[4] = -15
s[5] = 43.1
s[6] = 62.6
s[7] = ER
s[8] = -3.535
s[9] = 73.245
s[10] = Set

I'm disappointed with the tone that this thread has assumed and believe
I've overstayed my welcome. The above shows why, in my opinion, there had
to be two stages of evaluation. This script is my solution.

#!/usr/bin/perl
# by larry gates; contributors from c.l.p.misc with gratitude
# data from http://www.fourmilab.ch/yoursky/

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 = 'outfile12.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/'//;

my $outline = join(' ', @s);
print $gh "$outline\n";
}

close($gh);
close($fh);

__END__

# perl reg16.pl

--
larry gates

I'm not consistent about consistency, you see, except when I am...
And I try to believe six foolish consistencies before breakfast each day.
:)
-- Larry Wall in <[email protected]>
 
L

Larry Gates

On Tue, 27 Jan 2009 17:07:03 -0800, Jim Gibson wrote:
[snipped and re-ordered]
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.

This is exactly the type of stuff that perl does better than compiled
languages. I'd continue if I weren't going to get flamed and shown the
door.
Well in fact you didn't do it at all. I and several other people had to
write the code for you.

Horseshit.

C:\MinGW\source>dir *.pl
Volume in drive C has no label.
Volume Serial Number is 942A-AD55

Directory of C:\MinGW\source

01/11/2009 01:35 PM 538 faulk1.pl
01/11/2009 01:33 PM 178 faulk10.pl
01/20/2009 06:02 PM 323 faulk11.pl
01/20/2009 07:06 PM 328 faulk12.pl
01/20/2009 08:31 PM 288 faulk13.pl
01/21/2009 12:17 PM 447 faulk14.pl
01/20/2009 11:12 PM 180 faulk15.pl
01/21/2009 05:25 PM 491 faulk16.pl
01/22/2009 11:16 PM 578 faulk17.pl
01/22/2009 11:35 PM 631 faulk18.pl
01/23/2009 12:01 AM 810 faulk19.pl
01/11/2009 01:38 PM 244 faulk2.pl
01/09/2009 07:49 PM 228 faulk3.pl
01/11/2009 01:43 PM 322 faulk4.pl
01/11/2009 01:24 PM 172 faulk5.pl
01/11/2009 01:23 PM 176 faulk6.pl
01/11/2009 01:26 PM 126 faulk7.pl
01/11/2009 01:29 PM 112 faulk8.pl
01/11/2009 01:30 PM 146 faulk9.pl
01/15/2009 05:19 PM 372 larry1.pl
01/15/2009 05:55 PM 409 larry2.pl
01/23/2009 09:32 PM 437 reg1.pl
01/26/2009 03:36 PM 896 reg10.pl
01/26/2009 05:11 PM 910 reg11.pl
01/26/2009 06:26 PM 917 reg12.pl
01/26/2009 07:59 PM 848 reg13.pl
01/26/2009 08:36 PM 878 reg14.pl
01/27/2009 02:04 PM 967 reg15.pl
01/27/2009 10:12 PM 841 reg16.pl
01/25/2009 04:04 PM 600 reg2.pl
01/25/2009 04:06 PM 557 reg3.pl
01/26/2009 12:42 PM 661 reg4.pl
01/25/2009 04:21 PM 579 reg5.pl
01/25/2009 04:23 PM 579 reg6.pl
01/25/2009 04:55 PM 581 reg7.pl
01/26/2009 02:36 PM 554 reg8.pl
01/26/2009 02:50 PM 696 reg9.pl
01/22/2009 08:12 PM 1,074 rgb1.pl
01/22/2009 10:55 PM 388 rgb2.pl
01/07/2009 07:27 PM 2,203 scraper1.pl
12/12/2008 07:24 PM 1,905 script1.pl
12/15/2008 11:39 PM 2,017 script2.pl
12/16/2008 08:54 PM 2,157 script3.pl
12/09/2008 03:07 AM 1,080 sln1.pl
12/12/2008 06:28 PM 954 sln2.pl
12/14/2008 06:49 PM 72 tad1.pl
01/23/2009 12:38 AM 418 tad2.pl
01/23/2009 04:08 PM 363 tad3.pl
01/23/2009 09:14 PM 398 tad4.pl
01/23/2009 09:28 PM 437 tad5.pl
01/20/2009 11:08 PM 2,436 van1.pl
01/24/2009 04:24 PM 2,498 van2.pl

66 File(s) 58,944 bytes
0 Dir(s) 68,327,882,752 bytes free

C:\MinGW\source>
 
S

sln

Hope this helps.

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

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 ^ why ?????????
$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/'//;
[snip rest of code down]
Sun 20 41 55 -18 15.1 0.985 31.290 28.986 Up

[snip output ^^^]
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.

Above is the current ephemeris for Albuquerque. The sun is almost on top
^^ ^^^
[snip]

Since this may be searchable, I'm going to add a critique on your apparent final form.
I count 7 substitution regexs' above and one split. This occurs per line of data read in.

Things that were thrown out:

1. Positional field validation, number of fields validation, form of field validation, field parametric validation ...
(the list is endless here)
2. Empty line/things that break code... again endless
3. Redundancy, repative pos(0) searching loops pre-validation, performance issues
4. Even the slightest fallback error reporting for anomolies, no recovery
5. The notion of confidence in the parsed data
6. Refactoring ... the most important step

This is a sample output line from a print "@record" after all the regex substitutions:
"Sun 20 41 55 -18 15.1 0.985 31.290 28.986 Up"

They all seem to be the same. How did you determine this is what is needed?
The regex substitutions and split(), along with NOT validating anything,
suggest that you are firmly positive and confident of the form of not only the input
line, but the result after all these substitutions and split(), that you will get
the desired field data described above.

On this premise, and asuming that the only question is whether it will be just "Planets"
as the first field and some "text (Set/Up)" in the last field, there are only numbers
inbetween. Float and decimal numbers aren't distinctive in Perl, so you have a pattern
that is ALPHA CHARACTERS in the beginning, NUMBERS in the middle, ALPHA CHARACTERS at
the end.

I thought you were on track to validate fields/data et al, when you originally had that
huge ass regex, but you settled on the above as a final form, which does absolutely nothing
but try to stress test the regex engine to prove that you can remove one character at a time
from a string, the character you think (not know) is there, in an actual string, and by
searching from the beginning every time. On top of that, using split() as the grand finale.

If you take all of your regular expressions from above and replace it with this single regex:
my @rec = /(^\s*[a-z]+|[\d.+-]+|[a-z]+\s*$)/ig;
It produces the exact data output (and leaves the '+'):
"Sun 20 41 55 -18 15.1 0.985 31.290 28.986 Up"
In 1/50th the time that it takes to do all of your combined single character, re-start
regexs' and split(). And it does what you want to do, no validation.

As far as the '+' sign in text form? Thats all it is. Each number scalar has an internal
"text" representation (if its used textually) and "numeric" representation (if its used numerically).

$number = "+27"; print ($number * 1),"\n";


In the end, this was a learning exersice, nothing more. There are significantly harder regex
parsing circumstances. Some parsing conditions that would make your mind bend into a pretzl,
where the mistress of darkness has got you in a Kama Sutra position never thought possible.

But, the book is closed on this caper. Only took 300+ posts to figure it out ...


sln
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top