C$Procedure CKLBL ( Generate an MGSO or PDS CK label file ) SUBROUTINE CKLBL ( LBLTYP, CKFNM, KWTBLE, KWPTR, KWVALS ) C$ Abstract C C Collect label information from a specified CK file and generate C labels values for creating an CK 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*(*) CKFNM 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 CKFNM I The name of the CK 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 CKFNM The name of a binary CK 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 CK 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 CK 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 CK 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 CK file, the error C MAKLABEL(NOTACKFILE) 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 CK 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$ Version C C- Beta Version 2.1.0, 9-JUL-1998 (BVS) C C Keyword INSTRUMENT_ID was changed to NAIF_INSTRUMENT_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 a ck 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_CK_FILE' ) C C Lower bound index for SPICELIB "CELL" arrays. C C C Maximum length of keyword-value labels. C INTEGER LBLLEN PARAMETER ( LBLLEN = 132 ) 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 spacecraft that can be stored for a particular C file. C INTEGER MXCRFT PARAMETER ( MXCRFT = 100 ) C C Maximum length of an instrument name. C INTEGER INMLEN PARAMETER ( INMLEN = 80 ) C C Maximum length of a body name. C INTEGER BNMLEN PARAMETER ( BNMLEN = 80 ) C C Maximum length of a time string. C INTEGER TIMLEN PARAMETER ( TIMLEN = 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 CK files. C INTEGER CKND PARAMETER ( CKND = 2 ) INTEGER CKNI PARAMETER ( CKNI = 6 ) INTEGER CKNS PARAMETER ( CKNS = CKND + (CKNI+1)/2 ) C C Mnemonics for the elements of the double precision summary array C of an CK 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 CK file. C INTEGER PINSTR PARAMETER ( PINSTR = 1 ) INTEGER PFRAME PARAMETER ( PFRAME = PINSTR + 1 ) INTEGER PTYPE PARAMETER ( PTYPE = PFRAME + 1 ) INTEGER PANGVF PARAMETER ( PANGVF = PTYPE + 1 ) INTEGER PBADDR PARAMETER ( PBADDR = PANGVF + 1 ) INTEGER PEADDR PARAMETER ( PEADDR = PBADDR + 1 ) C C Local variables C CHARACTER*(BNMLEN) SCNAME CHARACTER*(TIMLEN) BEGISO CHARACTER*(TIMLEN) ENDISO CHARACTER*(TIMLEN) BEGSCL CHARACTER*(TIMLEN) ENDSCL CHARACTER*(ALEN) ARCH CHARACTER*(TYPLEN) TYPE CHARACTER*(TYPLEN) MYLBLT CHARACTER*(LBLLEN) NOTE CHARACTER*(LBLLEN) VALUE CHARACTER*(LBLLEN) PRODID DOUBLE PRECISION DSUMRY(CKND) DOUBLE PRECISION SUMMRY(CKNS) DOUBLE PRECISION BEGET DOUBLE PRECISION ENDET DOUBLE PRECISION TMPBEG DOUBLE PRECISION TMPEND DOUBLE PRECISION BSCLK DOUBLE PRECISION ESCLK INTEGER SCIDS(LBCELL:MXCRFT) INTEGER INSIDS(LBCELL:MXINST) INTEGER HANDLE INTEGER I INTEGER DOTLOC INTEGER DIRLOC INTEGER ISUMRY(CKNI) INTEGER SCID INTEGER SCLKID INTEGER NSC INTEGER NINSTR LOGICAL SEGFND LOGICAL FOUND C C Standard SPICE error handling. C CALL CHKIN ( 'CKLBL' ) 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( 'CKLBL' ) 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 ( CKFNM ) ) THEN CALL SETMSG ( 'The CK file ''#'' does not exist.' ) CALL ERRCH ( '#', CKFNM ) CALL SIGERR ( 'MAKLABEL(FILEDOESNOTEXIST)' ) CALL CHKOUT( 'CKLBL' ) RETURN END IF CALL GETFAT ( CKFNM, ARCH, TYPE ) IF ( FAILED() ) THEN CALL CHKOUT( 'CKLBL' ) 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 ( '#', CKFNM ) CALL SIGERR ( 'MAKLABEL(UNKNOWNFILETYPE)' ) CALL CHKOUT ( 'CKLBL' ) RETURN END IF IF ( TYPE .NE. 'CK' ) THEN CALL SETMSG ( 'The file ''#'' has a file type, ''#'',' . // ' and this subroutine only works with' . // ' CK files.' ) CALL ERRCH ( '#', CKFNM ) CALL ERRCH ( '#', TYPE ) CALL SIGERR ( 'MAKLABEL(NOTACKFILE)' ) CALL CHKOUT( 'CKLBL' ) RETURN END IF C C At this point, we know that: C C We have a SPICE file available for completing (?) the C template. C C First, we open the CK 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 BEGET = DPMAX() ENDET = DPMIN() CALL DAFOPR ( CKFNM, HANDLE ) CALL DAFBFS ( HANDLE ) CALL DAFFNA ( SEGFND ) IF ( FAILED() ) THEN CALL CHKOUT ( 'CKLBL' ) RETURN END IF DO WHILE ( SEGFND ) CALL DAFGS ( SUMMRY ) CALL DAFUS ( SUMMRY, CKND, CKNI, DSUMRY, ISUMRY ) IF ( FAILED() ) THEN CALL CHKOUT ( 'CKLBL' ) RETURN END IF C C Get the id-codes for the spacecraft and clock for C this instrument/structure. C CALL CKMETA ( ISUMRY(PINSTR), 'SPK', SCID ) CALL CKMETA ( ISUMRY(PINSTR), 'SCLK', SCLKID ) C C Insert the spacecraft and structure id's into the sets C we've collected so far. C CALL INSRTI ( SCID, SCIDS ) CALL INSRTI ( ISUMRY(PINSTR), INSIDS ) C C Decode the beginning ... C BSCLK = DSUMRY(PBEGTM) CALL SCDECD ( SCLKID, BSCLK, BEGSCL ) CALL SCS2E ( SCLKID, BEGSCL, TMPBEG ) IF ( FAILED() ) THEN CALL CHKOUT ( 'CKLBL' ) RETURN END IF C C ... and ending times associated with this segment. C ESCLK = DSUMRY(PENDTM) CALL SCDECD ( SCLKID, ESCLK, ENDSCL ) CALL SCS2E ( SCLKID, ENDSCL, TMPEND ) IF ( FAILED() ) THEN CALL CHKOUT ( 'CKLBL' ) RETURN END IF C C Keep track of the earliest and latest epochs in the C set of segment descriptors. C BEGET = MIN ( BEGET, TMPBEG ) ENDET = MAX ( ENDET, TMPEND ) CALL DAFFNA ( SEGFND ) IF ( FAILED() ) THEN CALL CHKOUT ( 'CKLBL' ) RETURN END IF END DO C C We're done with the CK file, so let's close it. C CALL CKCLS ( HANDLE ) IF ( FAILED() ) THEN CALL CHKOUT( 'CKLBL' ) RETURN END IF C C Convert the beginning epoch and ending epoch into the ISO time C format. C CALL ET2ISO_M ( BEGET, 'C', 3, BEGISO ) CALL ET2ISO_M ( ENDET, 'C', 3, ENDISO ) IF ( FAILED() ) THEN CALL CHKOUT( 'CKLBL' ) RETURN END IF 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 CK file. C C Remove any leading path or directory elements. C DIRLOC = CPOSR ( CKFNM, '/]', RTRIM(CKFNM) ) IF ( DIRLOC .EQ. 0 ) THEN PRODID = CKFNM ELSE PRODID = CKFNM(DIRLOC+1:) END IF C C If its 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 CK file. C IF ( MYLBLT .EQ. 'MGSO' ) THEN DOTLOC = CPOSR ( PRODID, '.', RTRIM(PRODID) ) IF ( DOTLOC .EQ. 0 ) THEN PRODID = PRODID(:RTRIM(PRODID)) // '.xc' ELSE PRODID = PRODID(1:DOTLOC) // 'xc' END IF END IF C C Construct the value of the NOTE that goes into the label C file. C IF ( MYLBLT .EQ. 'PDS' ) THEN NOTE = 'SPICE binary CK file.' ELSE IF ( MYLBLT .EQ. 'MGSO' ) THEN NOTE = 'SPICE transfer format CK file.' END IF C C At this point a good portion of the label information is C ready to go. Since it is, we load it into the keyword C symbol table now. C CALL SYIFSC( 'INSTRUMENT_NAME', 'UNK', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'KERNEL_TYPE_ID', TYPE, KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'PRODUCT_ID', PRODID, KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'START_TIME', BEGISO, KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'STOP_TIME', ENDISO, KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'TARGET_NAME', 'N/A', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'PLATFORM_OR_MOUNTING_NAME', 'UNK', KWTBLE, . KWPTR, . KWVALS ) CALL SYIFSC( 'SPACECRAFT_CLOCK_START_COUNT', BEGSCL, KWTBLE, . KWPTR, . KWVALS ) CALL SYIFSC( 'SPACECRAFT_CLOCK_STOP_COUNT', ENDSCL, KWTBLE, . KWPTR, . KWVALS ) C C Keywords: 'SPACECRAFT_NAME' C =========================== C C Collect the names of all spacecraft. 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 Now 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( 'CKLBL') 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 ( 'CKLBL' ) 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 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 IF ( .NOT. ELEMC( 'NAIF_INSTRUMENT_ID', KWTBLE ) ) THEN NINSTR = CARDI(INSIDS) DO I = 1, NINSTR CALL INTSTR ( INSIDS(I), VALUE ) CALL SYENQC ( 'NAIF_INSTRUMENT_ID', VALUE, . KWTBLE, KWPTR, KWVALS) END DO END IF CALL SYIFSC( 'SOURCE_PRODUCT_ID', 'UNK', KWTBLE, KWPTR, KWVALS ) CALL SYIFSC( 'NOTE', NOTE, KWTBLE, KWPTR, KWVALS ) C C That's all folks!!! C CALL CHKOUT ( 'CKLBL' ) RETURN END