C$Procedure IKLBL ( Generate an MGSO or PDS IK label file ) SUBROUTINE IKLBL ( LBLTYP, IKFNM, KWTBLE, KWPTR, KWVALS ) C$ Abstract C C Collect label information from a specified IK file and generate C labels, writing them to a file. C C$ Copyright C C Copyright (1995), 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*(*) IKFNM 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 IKFNM I The name of the IK 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 IK 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 IK 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 IK 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 IK 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 IK 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 IK file, the error C MAKLABEL(NOTANIKFILE) will be signalled. C C$ Files C C None. C C$ Particulars C C This subroutine scans an ASCII IK 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 ik file C C-& C C SPICELIB functions C INTEGER CARDI INTEGER RTRIM INTEGER POS INTEGER CPOSR LOGICAL BEINT LOGICAL ELEMC LOGICAL EXISTS LOGICAL FAILED C C Local parameters C C Template for the CDB data set ID value. C CHARACTER*(*) MGSODI PARAMETER ( MGSODI = 'SPICE_IK_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 Maximum number of Instruments that can be stored for a particular C file. C INTEGER MXINST PARAMETER ( MXINST = 100 ) 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 Local variables C CHARACTER*(SNMLEN) SCNAME CHARACTER*(SNMLEN) CHINID CHARACTER*(ALEN) ARCH CHARACTER*(TYPLEN) TYPE CHARACTER*(TYPLEN) MYLBLT CHARACTER*(LINLEN) LINE CHARACTER*(KVNLEN) WORD CHARACTER*(ERRLEN) ERRMSG CHARACTER*(LBLLEN) NOTE CHARACTER*(LBLLEN) PRODID CHARACTER*(LBLLEN) VALUE INTEGER SCIDS(LBCELL:MXCRFT) INTEGER INSIDS(LBCELL:MXINST) INTEGER ERRPOS INTEGER I INTEGER IKPOS INTEGER DIRLOC INTEGER NSC INTEGER NINSTR INTEGER SCID INTEGER INSTID LOGICAL EOF LOGICAL FOUND C C Standard SPICE error handling. C CALL CHKIN ( 'IKLBL' ) C C Initialize the "cell" arrays that we use. C CALL SSIZEI ( MXCRFT, SCIDS ) CALL SSIZEI ( MXINST, INSIDS ) 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 ( 'IKLBL' ) 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 ( IKFNM ) ) THEN CALL SETMSG ( 'The IK file ''#'' does not exist.' ) CALL ERRCH ( '#', IKFNM ) CALL SIGERR ( 'MAKLABEL(FILEDOESNOTEXIST)' ) CALL CHKOUT ( 'IKLBL' ) RETURN END IF CALL GETFAT ( IKFNM, ARCH, TYPE ) IF ( FAILED() ) THEN CALL CHKOUT( 'IKLBL' ) 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 ( '#', IKFNM ) CALL SIGERR ( 'MAKLABEL(UNKNOWNFILETYPE)' ) CALL CHKOUT ( 'IKLBL' ) RETURN END IF IF ( TYPE .NE. 'IK' ) THEN CALL SETMSG ( 'The file ''#'' has a file type, ''#'',' . // ' and this subroutine only works with' . // ' IK files.' ) CALL ERRCH ( '#', IKFNM ) CALL ERRCH ( '#', TYPE ) CALL SIGERR ( 'MAKLABEL(NOTANIKFILE)' ) CALL CHKOUT( 'IKLBL' ) RETURN END IF C C At this point, we know that: C C 1) We have a SPICE file available 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 IK file now. C C First, load the IK file into the kernel pool. We do this to C verify that the file is a properly formatted instrument kernel. C CALL LDPOOL ( IKFNM ) IF ( FAILED() ) THEN CALL CHKOUT( 'IKLBL' ) 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 'IK_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 IK 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 "IK_". C C Open the IK file. C CALL RDKNEW ( IKFNM ) IF ( FAILED() ) THEN CALL CHKOUT( 'IKLBL' ) RETURN END IF C C We read in lines and process them. C EOF = .FALSE. DO WHILE ( .NOT. EOF ) CALL RDKDAT ( LINE, EOF ) IF ( FAILED() ) THEN CALL CHKOUT( 'IKLBL' ) RETURN END IF IF ( .NOT. EOF ) THEN CALL NEXTWD ( LINE, WORD, LINE ) IKPOS = POS ( WORD, 'INS', 1 ) IF ( IKPOS .GT. 0 ) THEN CALL REMSUB ( WORD, IKPOS, IKPOS+2, WORD ) CALL REPLCH ( WORD, '_', ' ', WORD ) CALL NEXTWD ( WORD, CHINID, WORD ) IF ( BEINT ( CHINID ) ) THEN CALL NPARSI ( CHINID, INSTID, ERRMSG, ERRPOS ) SCID = INSTID/1000 CALL INSRTI ( INSTID, INSIDS ) CALL INSRTI ( SCID, SCIDS ) IF ( FAILED() ) THEN CALL CHKOUT( 'IKLBL' ) RETURN END IF END IF END IF END IF END DO IF ( CARDI(INSIDS) .EQ. 0 ) THEN CALL SETMSG ( 'No instrument data was found in the ' . // 'kernel ''#'' which is labelled as an ' . // 'instrument kernel. You need to examine ' . // 'this file to determine why there are now ' . // 'kernel pool variables of the form ' . // 'INS_ (where is some ' . // 'integer) present in the file. ' ) CALL ERRCH ( '#', IKFNM ) CALL SIGERR ( 'MAKLABEL(NOTANIKkernel)' ) CALL CHKOUT ( 'IKLBL' ) RETURN END IF C C Set the value for the note that should accompany the C other label information. C NOTE = 'SPICE text IK file.' 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 ( IKFNM, '/]', RTRIM(IKFNM) ) IF ( DIRLOC .EQ. 0 ) THEN PRODID = IKFNM ELSE PRODID = IKFNM(DIRLOC+1:) END IF C C The items that follow can now be filled in with no additional C processing, so we take care of that task now. C CALL SYIFSC( 'KERNEL_TYPE_ID', TYPE, KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'PRODUCT_ID', PRODID, 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', 'UNK', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'SOURCE_PRODUCT_ID', 'UNK', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'NOTE', NOTE, KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'PLATFORM_OR_MOUNTING_NAME', 'UNK', 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 ) 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 This is a cut and paste from other label routines. C If you actually get here, NSC cannot be zero. However, C leaving the logic in place to handle this case doesn't C hurt anything and may actually avoid recoding if the C day ever comes that we have more reasonable I-kernels. 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 CALL MYBD2N ( SCIDS(I), SCNAME ) CALL SYENQC ( 'SPACECRAFT_NAME', SCNAME, KWTBLE, . KWPTR, . KWVALS ) IF ( FAILED() ) THEN CALL CHKOUT ( 'IKLBL' ) RETURN END IF END DO END IF C C Keyword: NAIF_INSTRUMENT_ID C ====================== C C Create the string versions of the instrument id-codes and put C them into the keyword table. C NINSTR = CARDI(INSIDS) IF ( .NOT. ELEMC ( 'NAIF_INSTRUMENT_ID', KWTBLE ) ) THEN DO I = 1, NINSTR CALL INTSTR( INSIDS(I), VALUE ) CALL SYENQC( 'NAIF_INSTRUMENT_ID', VALUE, . 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 ( 'IKLBL' ) 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 ( 'IKLBL' ) RETURN END