Re: inputting the ephemerides (SOLUTION!)



Just lost all all my typing! Argh! Again:

As I said, these routines ASSUME there will be at least once blank
space between the terms, so that you can have digits in text like
"Asteroid2x2008".

But this rule is boken by, as an example:-
Moon 10h 11m 44s 9d .4' 58.500ER-45.535 171.391 Set
where there is no space before the minus sign (nor after the 5 before
"ER" and so "ER-45.565" is picked up as a text string (losing F2) and
then F3 is read in place of F2.

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.

Now, I have to write another parser to read a Fomat statement and work
out the start points and lengths of each field, so that I can offer
the user manual input of control data, or the use of a control record,
or both (by editing the control-record-supplied parameters in the
manual method screen). This means the program has to pick up the
fields from the control records, to put on the screen for editing.
It's the same problem as the above; but different rules because the
Format statement follows Fortran rules)



George wrote:
On Thu, 8 Jan 2009 21:42:11 -0800 (PST), Terence wrote:

NAME OF DATA? >EPH1.DAT
Sun 19h 42m 48s -21d 20.3' .984 26.312 32.500 Up
Mercury 20h 37m 12s -17d 2.0' .752 35.288 20.668 Up
Venus 22h 50m 24s -7d 53.8' .693 44.516 -22.170 Up
Moon 10h 11m 44s 9d .4' 58.500ER-45.535 171.391 Set
Mars 18h 58m 2s -23d 34.8' 2.399 18.938 40.728 Up
Jupiter 20h 17m 7s -20d 8.8' 6.081 30.764 24.779 Up
Saturn 11h 32m 30s 5d 15.8' 8.810- 42.678 143.140 Set
Uranus 23h 23m 10s -4d 46.7' 20.635 44.216 -34.367 Up
Neptune 21h 41m 15s -14d 14.1' 30.890 40.660 1.951 Up

Somewhere along the way, I've lost the last float, which Terence calls F3.
There isn't anything fishy-looking in the format:

PROGRAM EPH
CHARACTER*12 CEPH
CHARACTER C(80)
CHARACTER*8 CPLAN
CHARACTER CH,CM,CS,CD,CP,CQ
CHARACTER*2 CE
CHARACTER*3 CT1,CT2,CF
INTEGER IHR,IMIN,ISEC,IRAD
REAL FM,FF,F1,F2,F3
INTEGER MAX,IP
C
MAX=80
WRITE(0,901)
901 FORMAT(' NAME OF DATA? (eph4.txt) >',\)
read(*,902) CEPH
902 FORMAT(A12)
OPEN (5,FILE=CEPH,STATUS='OLD',ACCESS='SEQUENTIAL',
1 FORM='FORMATTED')
C output file:
OPEN (12,FILE='processed1.txt',STATUS='REPLACE',
1 ACCESS='SEQUENTIAL')
C
1 READ (5,903,END=999) C
903 FORMAT(80A1)
C
C WRITE(0,904) C
C 904 FORMAT(1X,80A1)
C
IP=1
CALL GETC(C,MAX,IP,CPLAN,8)
CALL GETD(C,MAX,IP,IHR)
CALL GETC(C,MAX,IP,CH,1)
CALL GETD(C,MAX,IP,IMIN)
CALL GETC(C,MAX,IP,CM,1)
CALL GETD(C,MAX,IP,ISEC)
CALL GETC(C,MAX,IP,CS,1)
CALL GETD(C,MAX,IP,IRAD)
CALL GETC(C,MAX,IP,CD,1)
CALL GETF(C,MAX,IP,FM)
CALL GETC(C,MAX,IP,CQ,1)
CALL GETF(C,MAX,IP,F1)
CALL GETC(C,MAX,IP,CE,2)
CALL GETF(C,MAX,IP,F2)
CALL GETF(C,MAX,IP,F3)
CALL GETC(C,MAX,IP,CF,3)
C
WRITE(0,908) CPLAN,IHR,CH,IMIN,CM,ISEC,CS,IRAD,FM,CQ,
1 F1,CE,F2,F3,CF
908 FORMAT(1X,A8,I3,A1,I3,A1,I3,A1,I7,'d',F5.1,A1,
1 F8.3,A2,F7.3,F8.3,1X,A3)


C**
C** ADD HERE WRITE OUT TO FILE, WHAT IS NEEDED


WRITE(12,909) CPLAN,IHR,IMIN,ISEC,IRAD,FM,
1 F1,F2,F3
909 FORMAT(1X,A8,I3,I3,I3,I7,F5.1,
1 F8.3,F7.3,F8.3,1X)



C**
GO TO 1
999 STOP ' '
END
SUBROUTINE GETD(C,MAX,IP,NUM)
CHARACTER C(MAX),CX
INTEGER IP,MAX,NUM,I
C STOPS ON TRAILING BLANK OR CHARACTER
C IP POINTS TO LAST DIGIT/BLANK THAT STOPPED THE LAST PROCESS
NUM=0
M=1
GO TO 3
2 IF (IP.GE.MAX) GO TO 4
IP=IP+1
C PASS LEADING BLANKS
3 CX=C(IP)
IF (CX.EQ.' ') GO TO 2
C SIGN?
IF (CX.EQ.'+') GO TO 5
IF (CX.NE.'-') GO TO 4
M=-1
GO TO 5
C NOW ONLY DIGITS
4 I=ICHAR(CX)-48
IF (I.LT.0) GO TO 6
IF (I.GT.9) GO TO 6
NUM=10*NUM+I
5 IF (IP.GE.MAX) GO TO 6
IP=IP+1
CX=C(IP)
IF (CX.NE.' ') GO TO 4
C NOT BLANK OR DIGIT
6 NUM=NUM*M
RETURN
END
SUBROUTINE GETC(C,MAX,IP,CST,MAXS)
CHARACTER C(MAX),CST(MAXS),CX
INTEGER IP,MAX,MAXS,I,J
C STOPS ON TRAILING BLANK OR DIGIT
C IP POINTS TO CHARACTER/BLANK THAT STOPPED THE LAST PROCESS
J=0
CST(1:MAXS)=' '
GO TO 3
2 IF (IP.GE.MAX) GO TO 6
IP=IP+1
C PASS LEADING BLANKS
3 CX=C(IP)
IF (CX.EQ.' ') GO TO 2
C OPTION TO REMOVE "STRANGE UPPER ASCII TABLE" AND DELETE
IF (ICHAR(CX).GT.126) GO TO 2
4 I=ICHAR(CX)-48
C NO DIGITS IN TEXT
IF (I.LT.0) GO TO 5
C DIGIT?
IF (I.LE.9) GO TO 7
C IS CHARACTER
5 IF (J.GE.MAXS) GO TO 6
J=J+1
CST(J)=CX
6 IF (IP.GE.MAX) GO TO 7
IP=IP+1
CX=C(IP)
IF (CX.NE.' ') GO TO 4
7 RETURN
END
SUBROUTINE GETF(C,MAX,IP,F)
CHARACTER C(MAX),CX
CHARACTER*8 CWK
INTEGER IP,MAX,NUM,I
C STOPS ON TRAILING BLANK OR CHARACTER
C IP POINTS TO LAST DIGIT/BLANK THAT STOPPED THE LAST PROCESS
F=0.0
J=0
CWK=' '
GO TO 3
2 IF (IP.GE.MAX) GO TO 6
IP=IP+1
C PASS LEADING BLANKS
3 CX=C(IP)
IF (CX.EQ.' ') GO TO 2
C SIGN?
IF (CX.EQ.'+') GO TO 5
IF (CX.EQ.'-') GO TO 5
C NOW ONLY DIGITS AND DOT
4 IF (CX.EQ.'.') GO TO 5
I=ICHAR(CX)-48
IF (I.LT.0) GO TO 7
IF (I.GT.9) GO TO 7
C
5 IF (J.GE.8) GO TO 6
J=J+1
CWK(J:J)=CX
6 IF (IP.GE.MAX) GO TO 7
IP=IP+1
CX=C(IP)
IF (CX.NE.' ') GO TO 4
C BLANK OR CHARACTER
7 CONTINUE
READ(CWK,900) F
900 FORMAT(F8.3)
RETURN
END
c g95 ter2.f -o g.exe


C:\MinGW\source>g
NAME OF DATA? (eph4.txt) >eph6.txt
Sun 19h 43m 51s 21d 17.8' 0.984 - 35.020 0.000
Mercury 20h 36m 41s 16d 59.3' 0.747 - 22.075 0.000

Venus 22h 51m 18s 7d 46.9' 0.691 10.142 0.000
Moon 10h 24m 21s 7d 29.5' 58.600ER 4.992 0.000 -
Mars 18h 58m 51s 23d 33.8' 2.398 - 45.280 0.000
Jupiter 20h 17m 22s 20d 8.1' 6.082 - 27.618 0.000

Saturn 11h 32m 29s 5d 16.0' 8.806 - 19.672 0.000 -
Uranus 23h 23m 12s 4d 46.5' 20.638 18.211 0.000
Neptune 21h 41m 17s 14d 13.9' 30.892 - 7.527 0.000

Pluto 18h 6m 40s 17d 44.9' 32.485 - 52.833 0.000
STOP

C:\MinGW\source>type processed1.txt
Sun 19 43 51 21 17.8 0.984 35.020 0.000
Mercury 20 36 41 16 59.3 0.747 22.075 0.000
Venus 22 51 18 7 46.9 0.691 10.142 0.000
Moon 10 24 21 7 29.5 58.600 4.992 0.000
Mars 18 58 51 23 33.8 2.398 45.280 0.000
Jupiter 20 17 22 20 8.1 6.082 27.618 0.000
Saturn 11 32 29 5 16.0 8.806 19.672 0.000
Uranus 23 23 12 4 46.5 20.638 18.211 0.000
Neptune 21 41 17 14 13.9 30.892 7.527 0.000
Pluto 18 6 40 17 44.9 32.485 52.833 0.000

C:\MinGW\source>

Fishing for tips.
--
George

Bring them on.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
.



Relevant Pages

  • Re: Effective/Proper use of "regular expressions"
    ... parenthesized elements in your regular expression, ... from the set (unless the first character in the bracket expression is ... The range 0-9 is the set of all digits, ... a literal period followed by one or more digits". ...
    (comp.lang.tcl)
  • 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: 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: Invariant with DIGIT-CHAR-P and the reader.
    ... The current situation in CLISP allows users to parse Unicode text ... either ASCII, some sort of ISO-Latin, or Unicode and this will work ... because the digits are probably located identically. ... But, strictly, there is no requirement at all that the ASCII character ...
    (comp.lang.lisp)

Loading