Re: inputting the ephemerides (SOLUTION!)



On Thu, 22 Jan 2009 13:19:09 -0800 (PST), Terence wrote:

Larry Gates wrote:
On Wed, 14 Jan 2009 00:25:42 -0800 (PST), Terence wrote:

I didn't try to make a perfect program; that's your job, but to
convince you that the method works.
Defining the rules for field parsing has to match all the
possibilities a user can attempt.

Can you talk through your getf subroutine in terms of IP and how you build
a real out of it. IP doesn't budge for the read of the lastreal, the
azimuth:
...
The real terms are picked up by the GETF subroutine.
The index to the text is IP as in all the other two subroutines and is
increased with each character picked up, by the line after the
statement labelled number 2

The characters are checked for being a leading blank (which is
ignored) or
a leading sign, or being digits or a decimal point (in which case
these are placed in the character string CWK).
Anything else or a trailing blank or reaching the end of the input
string stops the parsing and GOs to statement 7.
Here the string CWK of sign, digits and a decimal point if present are
converted to a real value F bu the use of a read-from-string operation
READ(CWK,900)

The proble you are experiencing is that in some of your input data,
the fields of characters and signed numbers are NOT separated by at
least one blank.



To solve this, you have to replace theis lins in routine GETC
4 I=ICHAR(CX)-48
By
4 IF (CX.EQ.'-') GO TO 7
IF (CX.EQ.'+') GO TO 7
I=ICHAR(CX)-48

This will then not only look for digits, but leading signs to stop the
parsing.
But THEN, you cannot have a minus or plus sign inside the text fields.

There are other ways of tackling this.
One way is to first read the input line to one string, then copy this
string character by character, but, (only after the index has reached
some minimum number, to pass any possible digits in your "celestial
body name" which is the first field), then inserting a blank, if
after you have picked up an alphabetic character, that the next
character is a sign (-/+) or a digit.
Then apply the EPH routines as before.

Another way is to write one routine which picks up substrings to the
limit of the input string:and returnes the length, startpoint and a
return code to identify the string type using rules:
"skip leading blanks before the next field"
"any optional sign followed by digits" CASE
1
"any optional sign followed by digits and just one dot" CASE 2
(extension of case 1)
"any characters including digits if immediately adjacent, until a
space followed by a sign or a digit".
CASE 3

But even so, you can invent a string which will fail these
anticipations, lncluding the one taht gave you problems, a minus sign
after ER..

I used this perl program to condition the data:

my $filename = 'eph6.txt';
my $filename2 = 'outfile1.txt';
open(my $fh, '<', $filename) or die "cannot open $filename: $!";
open(my $gh, '>', $filename2) or die "cannot open $filename2: $!";

while (my $line = <$fh>) {
$line =~ s/\t/ /g;
$line =~ s/ER/ /g;
$line =~ s/°/ /g;
print $gh $line;
print STDOUT $line;
}
close($fh);

# seek($fh,0,0);

close($gh);

# perl reg1.pl

With outfile1.txt as the input for your program, the output is:

C:\MinGW\source>g95 ter2.f -o g.exe

C:\MinGW\source>g
NAME OF DATA? (eph4.txt) >outfile1.txt
Sun 19h 43m 51s -21d 17.8' 0.984- 35.020 87.148 Set
Mercury 20h 36m 41s -16d 59.3' 0.747- 22.075 84.236 Set
Venus 22h 51m 18s -7d 46.9' 0.691 10.142 72.919 Up
Moon 10h 24m 21s 7d 29.5' 58.600- 4.992-102.785 Set
Mars 18h 58m 51s -23d 33.8' 2.398- 45.280 90.860 Set
Jupiter 20h 17m 22s -20d 8.1' 6.082- 27.618 83.843 Set
Saturn 11h 32m 29s 5d 16.0' 8.806- 19.672-111.729 Set
Uranus 23h 23m 12s -4d 46.5' 20.638 18.211 70.235 Up
Neptune 21h 41m 17s -14d 13.9' 30.892- 7.527 77.864 Set
Pluto 18h 6m 40s -17d 44.9' 32.485- 52.833 108.052 Set
STOP

C:\MinGW\source>

Looks like we've got to get the spacing on getf tweaked a little, but it's
starting to look like data. Tabs are bad news for data.
--
larry gates

One thing I do understand is that people get scared when I start
thinking out loud. :-)
-- Larry Wall in <20031212010945.GB29594@xxxxxxxx>
.



Relevant Pages

  • Re: user defined function that converts string to float
    ... > I need user defined function that converts string to float in c. ... initial, possibly empty, sequence of white-space characters (as ... point character, then an optional exponent part as defined in ... then a nonempty sequence of hexadecimal digits ...
    (comp.lang.c)
  • Re: inputting the ephemerides (SOLUTION!)
    ... Defining the rules for field parsing has to match all the ... these are placed in the character string CWK). ... string stops the parsing and GOs to statement 7. ... Here the string CWK of sign, digits and a decimal point if present are ...
    (comp.lang.fortran)
  • Re: test to confirm non-numeric characters
    ... In other words, you are looking for a test to see if your 10 character number string is made up of digits only, right? ... Function IsDigitsOnly(Value As String) As Boolean ... ' At least one character in TenCharString is not a digit ...
    (microsoft.public.excel.programming)
  • Re: Newbie - itoa implementation
    ... Now we need to convert from number of binary digits to number of decimal digits. ... Since we need space for the null character to terminate the string, ...
    (comp.lang.c)
  • Re: Parse string return unicode hex values
    ... > How do I parse a string and return the Unicode hex values for each ... The parsing bit is easy enough, but it the command to covert ...
    (comp.lang.tcl)