C$Procedure RDCVAR ( Read the next variable from a kernel file ) C SUBROUTINE RDCVAR ( TABSYM, TABPTR, TABVAL, . NAME, EOF ) C C$ Abstract C C Read the next variable from the comments region of a DAF C based SPICE kernel file into a double precision symbol table. C C$ Required_Reading C C KERNEL C SYMBOLS C C$ Keywords C C FILES C C$ Declarations C INTEGER LBCELL PARAMETER ( LBCELL = -5 ) CHARACTER*(*) TABSYM ( LBCELL:* ) INTEGER TABPTR ( LBCELL:* ) DOUBLE PRECISION TABVAL ( LBCELL:* ) CHARACTER*(*) NAME LOGICAL EOF INTEGER LINLEN PARAMETER ( LINLEN = 80 ) C C$ Brief_I/O C C VARIABLE I/O DESCRIPTION C -------- --- -------------------------------------------------- C TABSYM, C TABPTR, C TABVAL I/O Symbol table. C NAME O Name of the variable. C EOF O End of file indicator. C LINLEN P Maximum line length. C C$ Detailed_Input C C TABSYM, C TABPTR, C TABVAL are the components of a double precision symbol C table. On input, the table may or may not contain C any variables. C C$ Detailed_Output C C TABSYM, C TABPTR, C TABVAL on output, contains the name and values of the next C variable in kernel file. Depending on the assignment C directive, the values in the file may replace or C augment any existing values. C C NAME is the name of the variable. NAME is blank if C no variable is read. C C EOF is true when the end of the kernel file has been C reached, and is false otherwise. The kernel file C is closed automatically when the end of the file C is reached. C C$ Parameters C C LINLEN is the maximum length of a line in the kernel file. C C$ Files C C RDCVAR reads from the file most recently opened by RDCNEW. C C$ Exceptions C C 1) If an error occurs parsing a date from the kernel file, the C error SPICE(DATEEXPECTED) is signalled. C C 2) If an error occurs parsing a numeric value from the kernel C file, the error SPICE(NUMBEREXPECTED) is signalled. C C$ Particulars C C None. C C$ Examples C C In the following example, RDCNEW and RDCVAR are used to read C the contents of two kernel files into a single symbol table. C First, the table is cleared. C C CALL SCARDC ( 0, TABSYM ) C CALL SCARDI ( 0, TABPTR ) C CALL SCARDD ( 0, TABVAL ) C C Next, the files are opened and read individually. C C DO I = 1, 2 C CALL RDCNEW ( KERNEL(I), BEGMRK, ENDMRK ) C C DO WHILE ( .NOT. EOF ) C CALL RDCVAR ( TABSYM, TABPTR, TABVAL, C . NAME, EOF ) C END DO C END DO C C Let the files KERNEL(1) and KERNEL(2) contain C C =========================================================== C C \begindata C DELTA_T_A = 32.184 C K = 1.657D-3 C ORBIT_ECC = 1.671D-2 C MEAN_ANOM = ( 6.239996D0, 1.99096871D-7 ) C C =========================================================== C C and C C =========================================================== C \begindata C K = 0.D0 C =========================================================== C C respectively. Then the contents of the symbol table are C C DELTA_T_A --> 32.184 C K --> 0.D0 C MEAN_ANOM --> 6.239996D0 C 1.99096871D-7 C ORBIT_ECC --> 1.671D-2 C C In particular, the value of K read from the second file replaces C the value read from the first file. C C$ Restrictions C C The input file must be opened and initialized by RDCNEW prior C to the first call to RDCVAR. C C$ Literature_References C C None. C C$ Author_and_Institution C C K.S. Zukor (JPL) C C$ Version C C- SPICELIB Version 1.0.0, 22-APR-1994 (KSZ) C C-& C C$ Index_Entries C C read the next variable from the comments of a kernel file C C-& C C SPICELIB functions C LOGICAL RETURN LOGICAL FAILED INTEGER NBLEN C C Local variables C CHARACTER*1 COMMA PARAMETER ( COMMA = ',' ) CHARACTER*1 BLANK PARAMETER ( BLANK = ' ' ) CHARACTER*1 LPAREN PARAMETER ( LPAREN = '(' ) CHARACTER*1 RPAREN PARAMETER ( RPAREN = ')' ) CHARACTER*(LINLEN) LINE CHARACTER*(LINLEN) VARNAM CHARACTER*3 DIRCTV CHARACTER*6 STATUS CHARACTER*30 CVALUE DOUBLE PRECISION DVALUE INTEGER I INTEGER STLEN CHARACTER*80 ERROR C C Standard SPICE error handling. C IF ( RETURN() ) THEN RETURN ELSE CALL CHKIN ( 'RDCVAR' ) END IF C C No variable yet. C NAME = ' ' C C No parsing error has occurred yet. C ERROR = ' ' C C Get the next data line. Unless something is terribly wrong, C this will begin a new variable definition. We have to read C the whole variable, unless we luck out and get an error, in C which case we can quit. C STATUS = 'BEGIN' DO WHILE ( ( STATUS .NE. 'DONE' ) .AND. . ( .NOT. FAILED() ) ) CALL RDCDAT ( LINE, EOF ) IF ( EOF ) THEN CALL CHKOUT ( 'RDCVAR' ) RETURN END IF STLEN = NBLEN ( LINE ) C C The first word on the first line should be the name of a C variable. The second word should be a directive: = or +=. C IF ( STATUS .EQ. 'BEGIN' ) THEN CALL NEXTWD ( LINE, VARNAM, LINE ) CALL NEXTWD ( LINE, DIRCTV, LINE ) C C If this is replacement (=) and not an addition (+=), C delete the values currently associated with the variable. C They will be replaced later. C IF ( DIRCTV .EQ. '=' ) THEN CALL SYDELD ( VARNAM, TABSYM, TABPTR, TABVAL ) END IF C C If this is a vector, the next thing on the line will be a C left parenthesis. Otherwise, assume that this is a scalar. C If it's a vector, get the first value. If it's a scalar, C plant a bogus right parenthesis, to make the following loop C terminate after one iteration. C CALL NEXTWD ( LINE, CVALUE, LINE ) IF ( CVALUE .EQ. LPAREN ) THEN CALL REPLCH ( LINE, COMMA, BLANK, LINE ) CALL NEXTWD ( LINE, CVALUE, LINE ) ELSE LINE = RPAREN END IF C C For subsequent lines, treat everything as a new value. C ELSE CALL NEXTWD ( LINE, CVALUE, LINE ) END IF C C We have a value anyway. Store it in the table. C C Keep going until the other shoe (the right parenthesis) C drops, or until the end of the line is reached. C C Dates begin with @; anything else is presumed to be a number. C DO WHILE ( CVALUE .NE. RPAREN .AND. CVALUE .NE. BLANK . .AND. STLEN .GT. 0 ) IF ( CVALUE(1:1) .EQ. '@' ) THEN CALL TPARSE ( CVALUE(2: ), DVALUE, ERROR ) IF ( ERROR .NE. ' ' ) THEN ERROR = 'Encountered : ' // CVALUE(2: ) CALL SETMSG ( ERROR ) CALL SIGERR ( 'SPICE(DATEEXPECTED)' ) CALL CHKOUT ( 'RDCVAR' ) RETURN END IF ELSE CALL NPARSD ( CVALUE, DVALUE, ERROR, I ) IF ( ERROR .NE. ' ' ) THEN PRINT *, 'cvalue is ', CVALUE ERROR = 'Encountered : ' // CVALUE CALL SETMSG ( ERROR ) CALL SIGERR ( 'SPICE(NUMBEREXPECTED)' ) CALL CHKOUT ( 'RDCVAR' ) RETURN END IF END IF CALL SYENQD ( VARNAM, DVALUE, TABSYM, . TABPTR, . TABVAL ) CALL NEXTWD ( LINE, CVALUE, LINE ) END DO IF ( CVALUE .EQ. RPAREN ) THEN STATUS = 'DONE' ELSE STATUS = 'INVAR' END IF END DO C C Return the name of the variable, but only if everything C went okay. C NAME = VARNAM CALL CHKOUT ( 'RDCVAR' ) RETURN END