C$Procedure SPKLBL ( Generate an MGSO or PDS SPK label file ) SUBROUTINE SPKLBL ( LBLTYP, SPKFNM, KWTBLE, KWPTR, KWVALS ) C$ Abstract C C Collect label information from a specified SPK file and generate C labels values for creating an SPK 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*(*) SPKFNM 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 SPKFNM I The name of the SPK 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 SPKFNM The name of a binary SPK 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 SPK 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 SPK 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 SPK 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 binary SPICE kernel file does not exist, the error C MAKLABEL(FILEDOESNOTEXIST) will be signalled. C C 3) If the type of the SPICE binary 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 SPK file, the error C MAKLABEL(NOTASPKFILE) 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 a binary SPICE SPK file collecting C information used to generate a set of labels. It then C generates a label file. 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 C$ Version C C- Beta Version 3.1.0, 9-JUL-1998 (BVS) C C Keyword INSTRUMENT_ID was changed to NAIF_INSTRUMENT_ID. C C- Beta Version 3.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 2.0.0, 22-NOV-1996 (WLT) C C Modified the portion of the code that writes out the C SPACECRAFT_NAME label. The Cassini project ground data C system, (following there usual professional practices) cannot C handle having the spacecraft name appear between a single C pair of braces, (even though the SFDU standard says you are C supposed to be able to do this). Since it is beyond the C capabilities of the SFDU lore masters to make their software C work according to its specifications, NAIF is once again C called upon to modify working software so that the SFDU empire C can be appeased. "Better, Faster, Cheaper ..." C C Another special Cassinism was added. If the name returned for C the spacecraft by ZZBODC2N is 'CAS' we change it to 'CASSINI'. 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 spk file C C-& C C SPICELIB functions C DOUBLE PRECISION DPMAX DOUBLE PRECISION DPMIN INTEGER CARDI INTEGER RTRIM INTEGER CPOSR 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_SPK_FILE' ) C C Maximum length of keyword-value labels. C INTEGER LBLLEN PARAMETER ( LBLLEN = 132 ) C C Maximum number of body IDs that can be stored for a particular C file. C INTEGER MXBODS PARAMETER ( MXBODS = 100 ) C C Maximum number of spacecraft IDs that can be stored for a C particular file. C INTEGER MXSCID PARAMETER ( MXSCID = 100 ) C C Maximum length of body name. C INTEGER NAMLEN PARAMETER ( NAMLEN = 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 Values of ND, NI and NS for SPK files. C INTEGER SPKND PARAMETER ( SPKND = 2 ) INTEGER SPKNI PARAMETER ( SPKNI = 6 ) INTEGER SPKNS PARAMETER ( SPKNS = SPKND + (SPKNI+1)/2 ) C C Mnemonics for the elements of the double precision summary array C of an SPK file. C INTEGER PBEGTM PARAMETER ( PBEGTM = 1 ) INTEGER PENDTM PARAMETER ( PENDTM = PBEGTM + 1 ) C C Mnemonics for the elements of the integer summary array C of an SPK file. C INTEGER PBODY PARAMETER ( PBODY = 1 ) INTEGER PCENTR PARAMETER ( PCENTR = PBODY + 1 ) INTEGER PFRAME PARAMETER ( PFRAME = PCENTR + 1 ) INTEGER PTYPE PARAMETER ( PTYPE = PFRAME + 1 ) INTEGER PBADDR PARAMETER ( PBADDR = PTYPE + 1 ) INTEGER PEADDR PARAMETER ( PEADDR = PBADDR + 1 ) C C Room allotted for time strings. C INTEGER TIMLEN PARAMETER ( TIMLEN = 80 ) C C Local variables C CHARACTER*(ALEN) ARCH CHARACTER*(TIMLEN) BEGISO CHARACTER*(NAMLEN) BODY CHARACTER*(TIMLEN) ENDISO CHARACTER*(LBLLEN) VALUE CHARACTER*(TYPLEN) MYLBLT CHARACTER*(LBLLEN) NOTE CHARACTER*(LBLLEN) PRODID CHARACTER*(NAMLEN) SCNAME CHARACTER*(TYPLEN) TYPE DOUBLE PRECISION BEGET DOUBLE PRECISION DSUMRY(SPKND) DOUBLE PRECISION ENDET DOUBLE PRECISION SUMMRY(SPKNS) INTEGER BODIDS(LBCELL:MXBODS) INTEGER DIRLOC INTEGER DOTLOC INTEGER HANDLE INTEGER I INTEGER ISUMRY(SPKNI) INTEGER NBODS INTEGER NSC INTEGER SCIDS(LBCELL:MXSCID) LOGICAL FOUND LOGICAL SEGFND C C Standard SPICE error handling. C CALL CHKIN ( 'SPKLBL' ) C C Initialize the "cell" arrays that we use. C CALL SSIZEI ( MXSCID, SCIDS ) CALL SSIZEI ( MXBODS, BODIDS ) IF ( FAILED() ) THEN CALL CHKOUT( 'SPKLBL' ) 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( 'SPKLBL' ) RETURN END IF C C Check to see that the file exists. C IF ( .NOT. EXISTS ( SPKFNM ) ) THEN CALL SETMSG ( 'The SPK file ''#'' does not exist.' ) CALL ERRCH ( '#', SPKFNM ) CALL SIGERR ( 'MAKLABEL(FILEDOESNOTEXIST)' ) CALL CHKOUT( 'SPKLBL' ) RETURN END IF C C Get the file's architecture and type. C CALL GETFAT ( SPKFNM, ARCH, TYPE ) IF ( FAILED() ) THEN CALL CHKOUT( 'SPKLBL' ) RETURN END IF C C Check to see if we couldn't figure out either the architecture C or the type. C 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 ( '#', SPKFNM ) CALL SIGERR ( 'MAKLABEL(UNKNOWNFILETYPE)' ) CALL CHKOUT ( 'SPKLBL' ) RETURN END IF C C Verify that the type of the file is 'SPK'. SPK files are the C only ones this subroutine can generate labels for. C IF ( TYPE .NE. 'SPK' ) THEN CALL SETMSG ( 'The file ''#'' has a file type, ''#'',' . // ' and this subroutine only works with' . // ' SPK files.' ) CALL ERRCH ( '#', SPKFNM ) CALL ERRCH ( '#', TYPE ) CALL SIGERR ( 'MAKLABEL(NOTANSPKFILE)' ) CALL CHKOUT( 'SPKLBL' ) RETURN END IF C C At this point, we know that: C C 1) We have a SPICE SPK file available for generating labels. C 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 now try to create the label information for the SPK file. C C First, we open the SPK file and loop through all of the C segments collecting the body names and the earliest starting C epoch and the latest ending epoch. These epochs will become the C start epoch and the stop epoch in the NAIF label file produced. C CALL DAFOPR ( SPKFNM, HANDLE ) CALL DAFBFS ( HANDLE ) IF ( FAILED() ) THEN CALL CHKOUT ( 'SPKLBL' ) RETURN END IF BEGET = DPMAX() ENDET = DPMIN() CALL DAFFNA ( SEGFND ) IF ( FAILED() ) THEN CALL CHKOUT ( 'SPKLBL' ) RETURN END IF DO WHILE ( SEGFND ) CALL DAFGS ( SUMMRY ) CALL DAFUS ( SUMMRY, SPKND, SPKNI, DSUMRY, ISUMRY ) IF ( FAILED() ) THEN CALL CHKOUT ( 'SPKLBL' ) RETURN END IF BEGET = MIN ( BEGET, DSUMRY(PBEGTM) ) ENDET = MAX ( ENDET, DSUMRY(PENDTM) ) IF ( ISUMRY(PBODY) .LT. 0 ) THEN CALL INSRTI ( ISUMRY(PBODY), SCIDS ) END IF CALL INSRTI ( ISUMRY(PBODY), BODIDS ) CALL DAFFNA ( SEGFND ) IF ( FAILED() ) THEN CALL CHKOUT ( 'SPKLBL' ) RETURN END IF END DO C C We're done with the SPK file, so let's close it. C CALL SPKCLS ( HANDLE ) IF ( FAILED() ) THEN CALL CHKOUT( 'SPKLBL' ) RETURN END IF C C Here are the items we can fill in with no further consideration: C C 'KERNEL_TYPE_ID' value 'SPK' C 'INSTRUMENT_NAME' value 'N/A' C 'NAIF_INSTRUMENT_ID' value 'N/A' C 'SOURCE_PRODUCT_ID' value 'UNK' C 'PLATFORM_OR_MOUNTING_NAME' value 'N/A' C 'SPACECRAFT_CLOCK_START_COUNT' value 'N/A' C 'SPACECRAFT_CLOCK_STOP_COUNT' value 'N/A' C C We need to determine the values for the following items: C C Keywords: 'START_TIME' C 'STOP_TIME' C 'PRODUCT_ID' C 'SPACECRAFT_NAME' C 'TARGET_NAME' C 'DATA_SET_ID' C 'NOTE' C C We fill in the known items right here. C CALL SYIFSC( 'KERNEL_TYPE_ID', 'SPK', 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( 'PLATFORM_OR_MOUNTING_NAME', 'N/A', . 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 Keywords: 'START_TIME', 'STOP_TIME' C =================================== C C Convert the beginning epoch and ending epoch into the ISO time C format. C CALL ET2ISO_M ( BEGET, 'C', 0, BEGISO ) CALL ET2ISO_M ( ENDET, 'C', 0, ENDISO ) IF ( FAILED() ) THEN CALL CHKOUT( 'SPKLBL' ) RETURN END IF CALL SYIFSC( 'START_TIME', BEGISO, KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'STOP_TIME', ENDISO, KWTBLE, KWPTR, KWVALS ) C C Keywords: 'PRODUCT_ID' C ====================== C C Set the product ID. This is the filename with all leading C directory stuff removed. Also, for MGSO labels, this is the name C of a transfer file, and for PDS files, this is the name of the C binary SPK file. C C Remove any leading path or directory elements. C DIRLOC = CPOSR ( SPKFNM, '/]', RTRIM(SPKFNM) ) IF ( DIRLOC .EQ. 0 ) THEN PRODID = SPKFNM ELSE PRODID = SPKFNM(DIRLOC+1:) END IF C C If it is an MGSO file, then, since we have a binary file, C we need to change the extension, if given, to be that of a C transfer SPK file. C IF ( MYLBLT .EQ. 'MGSO' ) THEN DOTLOC = CPOSR ( PRODID, '.', RTRIM(PRODID) ) IF ( DOTLOC .EQ. 0 ) THEN PRODID = PRODID(:RTRIM(PRODID)) // '.xsp' ELSE PRODID = PRODID(1:DOTLOC) // 'xsp' END IF END IF CALL SYIFSC( 'PRODUCT_ID', PRODID, KWTBLE, KWPTR, KWVALS ) C C Keywords: 'SPACECRAFT_NAME' C =========================== C C Collect the names of all spacecraft contained in this C SPK file. C NSC = CARDI ( SCIDS ) IF ( NSC .EQ. 0 ) THEN C C If we don't already have a SPACECRAFT_NAME value set it C to 'N/A'. C CALL SYIFSC ( 'SPACECRAFT_NAME', 'N/A', KWTBLE, . KWPTR, . KWVALS ) ELSE IF ( .NOT. ELEMC( 'SPACECRAFT_NAME', KWTBLE ) ) THEN C C Fill in the values we have in hand. C DO I = 1, NSC CALL MYBD2N( SCIDS(I), SCNAME ) CALL SYPSHC( 'SPACECRAFT_NAME', SCNAME, KWTBLE, . KWPTR, . KWVALS ) C C Make sure nothing bad happened. C IF ( FAILED() ) THEN CALL CHKOUT( 'SPKLBL') RETURN END IF END DO END IF C C Keywords: 'TARGET_NAME' C ======================= C C Repeat the steps above for the other objects in the file. C NBODS = CARDI ( BODIDS ) IF ( NBODS .EQ. 0 ) THEN C C If we don't already have a TARGET_NAME value set it C to 'N/A'. C CALL SYIFSC ( 'TARGET_NAME', 'N/A', KWTBLE, . KWPTR, . KWVALS ) ELSE IF ( .NOT. ELEMC ( 'TARGET_NAME', KWTBLE ) ) THEN C C Now fill in the values we have in hand. C DO I = 1, NBODS CALL MYBD2N( BODIDS(I), BODY ) CALL SYENQC( 'TARGET_NAME', BODY, KWTBLE, . KWPTR, . KWVALS ) C C Make sure nothing bad happened. C IF ( FAILED() ) THEN CALL CHKOUT( 'SPKLBL') RETURN END IF END DO END IF C C Keywords: 'DATA_SET_ID' C ====================== C C Create the DATA_SET_ID label value. Note that VALUE will be C overwritten by SYPOPC only if there is a value present in the C Keyword symbol table. 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 ( 'SPKLBL' ) RETURN END IF 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 Keywords: 'NOTE' C ================ C C Create the "note" for this product. C IF ( MYLBLT .EQ. 'PDS' ) THEN NOTE = 'SPICE binary SPK file.' ELSE IF ( MYLBLT .EQ. 'MGSO' ) THEN NOTE = 'SPICE transfer format SPK file.' END IF CALL SYIFSC( 'NOTE', NOTE, KWTBLE, KWPTR, KWVALS ) CALL CHKOUT ( 'SPKLBL' ) RETURN END