C$Procedure SCLLBL ( Generate an MGSO or PDS SCLK label file ) SUBROUTINE SCLLBL ( LBLTYP, SCLFNM, KWTBLE, KWPTR, KWVALS ) C$ Abstract C C Collect label information from a specified SCLK file and generate C labels values for creating an SCLK label. C C$ Copyright C C Copyright (1996), California Institute of Technology. C U.S. Government sponsorship acknowledged. C C$ Required_Reading C C None C C$ Keywords C C None. C C$ Declarations IMPLICIT NONE INTEGER LBCELL PARAMETER ( LBCELL = -5 ) CHARACTER*(*) LBLTYP CHARACTER*(*) SCLFNM CHARACTER*(*) KWTBLE( LBCELL:*) INTEGER KWPTR ( LBCELL:*) CHARACTER*(*) KWVALS( LBCELL:*) C$ Brief_I/O C C Variable I/O Description C -------- --- -------------------------------------------------- C LBLTYP I The type of label file to produce: MGSO or PDS. C SCLFNM I The name of the SCLK file to use. C KWTBLE I/O The names portion of a symbol table C KWPTR I/O The pointers portion of a symbol table C KWVALS I/O The values portion of a symbol table C C$ Detailed_Input C C LBLTYP The type of label file to be produced. The allowed C types are: 'MGSO' or 'PDS'. C C SCLFNM The name of a binary SCLK file to use when generating C values for keywords in the label file. This file must C already exist. C C KWTBLE The symbol table of keyword value lists that will C KWPTR later be converted into an label file for the C KWVALS input SCLK file. On input, this symbol table contains C the values that were supplied in the MAKLABEL C template file. C C C$ Detailed_Output C C KWTBLE The symbol table of keyword value lists that will C KWPTR later be converted into an label file for the C KWVALS input SCLK file. On output, this symbol table contains C the values that were supplied in the MAKLABEL C template file as well as all values that are C appropriate for an SCLK label. C C$ Parameters C C None. C C$ Exceptions C C 1) If the label type is not one of 'MGSO' or 'PDS' then the error C MAKLABEL(BADLABELTYPE) will be signalled. C C 2) If the SCLK SPICE kernel file does not exist, the error C MAKLABEL(FILEDOESNOTEXIST) will be signalled. C C 3) If the type of the SPICE kernel file cannot be C determined, the error MAKLABEL(UNKNOWNFILETYPE) will be C signalled. C C 4) If the SPICE binary kernel file is not an SCLK file, the error C MAKLABEL(NOTASCLKFILE) will be signalled. C C 6) If the name for a body ID code cannot be found, the error C MAKLABEL(BODYNOTFOUND) will be signalled. C C$ Files C C None. C C$ Particulars C C This subroutine scans an ASCII SCLK file collecting C information used to generate a set of labels. C C$ Examples C C None. C C$ Restrictions C C This subroutine is to be used only with the MAKLABEL program. C C$ Literature_References C C None. C C$ Author_and_Institution C C B.V. Semenov (JPL) C W.L. Taber (JPL) C K.R. Gehringer (JPL) C C$ Version C C- Beta Version 2.2.0, 9-JUL-1998 (BVS) C C Keyword INSTRUMENT_ID was changed to NAIF_INSTRUMENT_ID. C C- Beta Version 2.1.0, 17-DEC-1996 (WLT) C C Fixed the assignment for KERNEL_TYPE_ID. C C- Beta Version 2.0.0, 4-DEC-1996 (WLT) C C Really and truly this routine should have a new name, C the calling sequence and functionality are totally C different from the last edition of this routine. C C- Beta Version 1.0.0, 25-JAN-1996 (KRG) C C-& C$ Index_Entries C C create a NAIF label file from an sclk file C C-& C C SPICELIB functions C INTEGER CARDI INTEGER RTRIM INTEGER POS INTEGER CPOSR INTEGER WDCNT LOGICAL BEINT LOGICAL ELEMC LOGICAL EXISTS LOGICAL FAILED C C Other functions C C C Local parameters C C Template for the CDB data set ID value. C CHARACTER*(*) MGSODI PARAMETER ( MGSODI = 'SPICE_SCLK_FILE' ) C C Maximum length of an error message. C INTEGER ERRLEN PARAMETER ( ERRLEN = 132 ) C C Maximum length of keyword-value labels. C INTEGER LBLLEN PARAMETER ( LBLLEN = 132 ) C C Maximum length of line in a spice text kernel. C INTEGER LINLEN PARAMETER ( LINLEN = 255 ) C C Maximum length of kernel variable name in a spice text kernel. C INTEGER KVNLEN PARAMETER ( KVNLEN = 80 ) C C Position of the equal sign in a label. C INTEGER EQUPOS PARAMETER ( EQUPOS = 30 ) C C Maximum number of body names that can be stored for a particular C file. C INTEGER MXCRFT PARAMETER ( MXCRFT = 100 ) C C Maximum length of spacecraft name. C INTEGER SNMLEN PARAMETER ( SNMLEN = 80 ) C C Length of a file architecture. C INTEGER ALEN PARAMETER ( ALEN = 3 ) C C Length of a file type. C INTEGER TYPLEN PARAMETER ( TYPLEN = 4 ) C C Size of a "word" C INTEGER WDSIZE PARAMETER ( WDSIZE = 32 ) C C Local variables C CHARACTER*(SNMLEN) SCNAME CHARACTER*(SNMLEN) CHSCID CHARACTER*(ALEN) ARCH CHARACTER*(TYPLEN) TYPE CHARACTER*(TYPLEN) MYLBLT CHARACTER*(LINLEN) LINE CHARACTER*(KVNLEN) WORD CHARACTER*(ERRLEN) ERRMSG CHARACTER*(WDSIZE) VARNAM CHARACTER*(LBLLEN) NOTE CHARACTER*(LBLLEN) PRODID CHARACTER*(LBLLEN) VALUE INTEGER SCIDS(LBCELL:MXCRFT) INTEGER ERRPOS INTEGER I INTEGER SCLPOS INTEGER N INTEGER DIRLOC INTEGER NSC INTEGER SCID LOGICAL EOF LOGICAL SCLK LOGICAL FOUND C C Standard SPICE error handling. C CALL CHKIN ( 'SCLLBL' ) C C Initialize the "cell" arrays that we use. C CALL SSIZEI ( MXCRFT, SCIDS ) IF ( FAILED() ) THEN CALL CHKOUT( 'SCLLBL' ) RETURN END IF C C Check to see if the label type we were given is one we recognize. C We only recognize 'PDS' and 'MGSO'. C CALL LJUST ( LBLTYP, MYLBLT ) CALL LJUST ( MYLBLT, MYLBLT ) IF ( ( MYLBLT .NE. 'PDS' ) .AND. ( MYLBLT .NE. 'MGSO' ) ) THEN CALL SETMSG ( 'The label type ''#'' was not recognized.' . // ' Only label types ''PDS'' and ''MGSO''' . // ' are recognized.' ) CALL ERRCH ( '#', MYLBLT ) CALL SIGERR ( 'MAKLABEL(BADLABELTYPE)' ) CALL CHKOUT( 'SCLLBL' ) RETURN END IF C C Check to see that the file exists, and that it is a SPICE file, C and hence one we know how to process. C IF ( .NOT. EXISTS ( SCLFNM ) ) THEN CALL SETMSG ( 'The SCLK file ''#'' does not exist.' ) CALL ERRCH ( '#', SCLFNM ) CALL SIGERR ( 'MAKLABEL(FILEDOESNOTEXIST)' ) CALL CHKOUT( 'SCLLBL' ) RETURN END IF CALL GETFAT ( SCLFNM, ARCH, TYPE ) IF ( FAILED() ) THEN CALL CHKOUT( 'SCLLBL' ) RETURN END IF IF ( ( ARCH .EQ. '?' ) .OR. ( TYPE .EQ. '?' ) ) THEN C C We didn't have a file that we know how to deal with. So, C we toss our hands in the air and signal an error. C CALL SETMSG ( 'The architecture or type of the file' . // ' ''#'' was not recognized.' ) CALL ERRCH ( '#', SCLFNM ) CALL SIGERR ( 'MAKLABEL(UNKNOWNFILETYPE)' ) CALL CHKOUT ( 'SCLLBL' ) RETURN END IF IF ( TYPE .NE. 'SCLK' ) THEN CALL SETMSG ( 'The file ''#'' has a file type, ''#'',' . // ' and this subroutine only works with' . // ' SCLK files.' ) CALL ERRCH ( '#', SCLFNM ) CALL ERRCH ( '#', TYPE ) CALL SIGERR ( 'MAKLABEL(NOTANSCLKFILE)' ) CALL CHKOUT( 'SCLLBL' ) RETURN END IF C C At this point, we know that: C C 1) We have a SPICE file available for generating labels. C 2) We know that the label file that we are to produce does not C exist, so we can safely create it. C C So we will try to create the label file for the SCLK file now. C C C First, load the SCLK file into the kernel pool. We do this as a C generic test to see if it is a correctly formatted SCLK file. C CALL LDPOOL ( SCLFNM ) IF ( FAILED() ) THEN CALL CHKOUT( 'SCLLBL' ) RETURN END IF C C Now we scan through the keywords looking for a trailing number, C i.e., keywords of interest will have the form 'SCLK_cccc_nnnn' C where we desire to obtain the value of 'nnnn' as an integer. If C the last part of the name is not an integer, we are not C interested in it. All SCLK variables of interest will have the C spacecraft number, which is the negation of the SPICE spacecraft C ID code, as the trailing bit after the last underscore. This is C what we want. The keywords will also all begin with "SCLK_". C C Open the SCLK file. C CALL RDKNEW ( SCLFNM ) IF ( FAILED() ) THEN CALL CHKOUT( 'SCLLBL' ) RETURN END IF C C We read in lines and process them, right now we suspect we C have an SCLK file, but until we find a variable name in C the file of the form SCLK_DATA_TYPE_# where # is some integer C we shall reserve judgement. C EOF = .FALSE. SCLK = .FALSE. DO WHILE ( .NOT. EOF ) CALL RDKDAT ( LINE, EOF ) IF ( FAILED() ) THEN CALL CHKOUT( 'SCLLBL' ) RETURN END IF IF ( .NOT. EOF ) THEN CALL NEXTWD ( LINE, WORD, LINE ) C C Every SCLK file must have the variable SCLK_DATA_TYPE_# C as a variable. If we don't find this variable, we C don't have an SCLK kernel. C SCLPOS = POS ( WORD, 'SCLK_DATA_TYPE_', 1 ) IF ( SCLPOS .GT. 0 ) THEN CALL REPLCH ( WORD, '_', ' ', WORD ) N = WDCNT ( WORD ) CALL NTHWD ( WORD, N, CHSCID, I ) IF ( BEINT ( CHSCID ) ) THEN SCLK = .TRUE. C C See if the user explicitly set the ID code of C the object associated with the clock. C VARNAM = 'SCLK_NAIFID_' // CHSCID CALL GIPOOL ( VARNAM, 1, 1, N, SCID, FOUND ) C C If we didn't find an explicit reference to the C associated NAIF ephemeris object in the kernel C pool, we fall back to the convention between C Clock ids and Spacecraft ids. C IF ( .NOT. FOUND ) THEN CALL NPARSI ( CHSCID, SCID, ERRMSG, ERRPOS ) SCID = -SCID END IF CALL INSRTI ( SCID, SCIDS ) IF ( FAILED() ) THEN CALL CHKOUT( 'SCLLBL' ) RETURN END IF END IF END IF END IF END DO IF ( .NOT. SCLK ) THEN CALL SETMSG ( 'The file ''#'', is internally labelled ' . // 'as an SCLK file, but it doesn''t ' . // 'contain a kernel pool variable of the ' . // 'form ''SCLK_DATA_TYPE_'' ' . // '(where is some integer ' . // 'string. Please check the file to ' . // 'determine the cause of this discrepancy ' ) CALL ERRCH ( '#', SCLFNM ) CALL SIGERR ( 'MAKLABEL(NOTANSCLKFILE)' ) CALL CHKOUT ( 'SCLLBL' ) RETURN END IF C C We have collected everything we plan to get out of the SCLK C kernel. Here's the stuff we can fill in without any further C processing. C NOTE = 'SPICE text SCLK kernel file.' CALL SYIFSC( 'KERNEL_TYPE_ID', 'SCLK', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'START_TIME', 'N/A', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'STOP_TIME', 'N/A', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'TARGET_NAME', 'N/A', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'INSTRUMENT_NAME', 'N/A', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'NAIF_INSTRUMENT_ID','N/A', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'SOURCE_PRODUCT_ID', 'UNK', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'NOTE', NOTE, KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'SPACECRAFT_CLOCK_START_COUNT', 'N/A', KWTBLE, . KWPTR, . KWVALS ) CALL SYIFSC( 'SPACECRAFT_CLOCK_STOP_COUNT', 'N/A', KWTBLE, . KWPTR, . KWVALS ) CALL SYIFSC( 'PLATFORM_OR_MOUNTING_NAME', 'N/A', KWTBLE, . KWPTR, . KWVALS ) C C The remaining pieces require a small amount of processing. C C Keyword: PRODUCT_ID C =================== C C Set the product ID. This is the filename with all leading C directory stuff removed. C C Remove any leading path or directory elements. C DIRLOC = CPOSR ( SCLFNM, '/]', RTRIM(SCLFNM) ) IF ( DIRLOC .EQ. 0 ) THEN PRODID = SCLFNM ELSE PRODID = SCLFNM(DIRLOC+1:) END IF CALL SYIFSC( 'PRODUCT_ID', PRODID, KWTBLE, KWPTR, KWVALS ) C C Keyword: SPACECRAFT_NAME C ======================== C C There is probably only one spacecraft id in our set, but C we handle the odd case that maybe there's more than one. C NSC = CARDI( SCIDS ) IF ( NSC .EQ. 0 ) THEN CALL SYIFSC( 'SPACECRAFT_NAME', 'N/A', KWTBLE, KWPTR, KWVALS ) ELSE IF ( .NOT. ELEMC('SPACECRAFT_NAME', KWTBLE) ) THEN DO I = 1, NSC C C Determine the name of the current spacecraft ... C CALL MYBD2N ( SCIDS(I), SCNAME ) IF ( FAILED() ) THEN CALL CHKOUT ( 'SCLLBL' ) RETURN END IF C C ... and put the name into the symbol table. C CALL SYENQC ( 'SPACECRAFT_NAME', SCNAME, KWTBLE, . KWPTR, . KWVALS ) END DO END IF C C Keyword: DATA_SET_ID C ==================== C C Look up the current value for the DATA_SET_ID. This will C be overridden by the SYPOPC call below if anything at all C is present. C VALUE = MGSODI CALL SYPOPC( 'DATA_SET_ID', KWTBLE, KWPTR, KWVALS, VALUE, FOUND ) IF ( MYLBLT .EQ. 'PDS' .AND. .NOT. FOUND ) THEN C C If we didn't get a value back from the call above C we are totally out of luck. C CALL SETMSG ( 'There was no template value supplied ' . // 'for the DATA_SET_ID in the TEMPLATE ' . // 'file. Until that information is ' . // 'supplied the label file can not be ' . // 'created. ' ) CALL SIGERR ( 'MAKLABEL(NODATASETID)' ) CALL CHKOUT ( 'SCLLBL' ) RETURN END IF C C A blank value for the DATA_SET_ID is not acceptable. C IF ( VALUE .EQ. ' ' ) THEN VALUE = MGSODI END IF C C If the current value is just a template, fill in the marker C (this has no effect if there isn't a marker present). C CALL REPMC ( VALUE, '#', TYPE, VALUE ) CALL SYSETC ('DATA_SET_ID', VALUE, KWTBLE, KWPTR,KWVALS ) C C That's all folks!!! C CALL CHKOUT ( 'SCLLBL' ) RETURN END