*
* $Id$
*
* $Log$
* Revision 1.1  1996/03/08 11:40:50  mclareni
* Initial revision
*
*
#include "kapack/pilot.h"
      SUBROUTINE KAPUTM(LUN,MAJNAM,LDEF,LMAX,IRC)
*
*.....REPLACE A MAJOR ENTRY IN A KA-FILE
*
*.....UPDATING OF MAJOR NAME STACK ENTRIES ADDED 880628
*
#include "kapack/kax000.inc"
#include "kapack/kax020.inc"
#include "kapack/kax02c.inc"
#include "kapack/kax050.inc"
#include "kapack/kax0a0.inc"
*
      CHARACTER MAJNAM*(*)
*
      PARAMETER (MAJLEN=3)
      INTEGER MAJREC(1:MAJLEN)
*
*-----------------------------------------------------------------------
*
      CALL KAXINI(LUN)
      IF ( .NOT. MODIFY )  GO TO 21
*
*.....CHECK THE DEFAULT AND MAXIMUM LENGTHS
      IF ( LDEF .LT. 0 )  GO TO 12
      IF ( LMAX .LT. 0 )  GO TO 13
      IF ( LDEF .GT. LMAX )  GO TO 14
*
*.....PROCESS THE MAJOR NAME
      CALL KAXMAJ(MAJNAM,*11,*31)
*
*.....BUILD THE NEW MAJOR ENTRY AND REPLACE IT IN THE MAJOR TREE
      MAJREC(1) = KROOT(0)
      MAJREC(2) = LDEF
      MAJREC(3) = LMAX
      CALL KAXPUT(1,MAJKEY,MAJREC,*31,*41)
*.....UPDATE THE LENGTH ATTRIBUTES OF THE MAJOR NAME IN THE STACK
      KLDEF(0)= LDEF
      KLDEF(1)= LDEF
      KLMAX(0)= LMAX
      KLMAX(1)= LMAX
*
*.....SUCCESSFUL COMPLETION
      IRC = 0
      WRITE(MSG,100) MAJNAM, LUN, LDEF, LMAX
      CALL KAXMSG(LUNLOG,MSG)
      RETURN
*
*.....ERROR PROCESSING
 11   IRC = 1
      WRITE(MSG,111) MAJNAM
      GO TO 99
*
 12   IRC = 1
      WRITE(MSG,112) LDEF
      GO TO 99
*
 13   IRC = 1
      WRITE(MSG,113) LMAX
      GO TO 99
*
 14   IRC = 1
      WRITE(MSG,114) LDEF, LMAX
      GO TO 99
*
 21   IRC = 2
      WRITE(MSG,121) LUN
      GO TO 99
*
 31   IRC = 3
      WRITE(MSG,131) MAJNAM, LUN
      GO TO 99
*
 41   IRC = 4
      WRITE(MSG,141) MAJNAM, LUN
      GO TO 99
*
 99   CALL KAXMSG(LUNERR,MSG)
      IF ( RETURN )  RETURN
      CALL KAXEND
*
 100  FORMAT('CRNKA110 KAPUTM: MAJOR NAME ''',A,
     +       ''' HAS BEEN REPLACED IN THE KA-FILE ON UNIT ',I3,
     +       ' WITH DEFAULT LENGTH ',I11,' AND MAXIMUM LENGTH ',I11)
 111  FORMAT('CRNKA111 KAPUTM: ''',A,''' IS NOT AN ACCEPTABLE MAJOR
     +        NAME')
 112  FORMAT('CRNKA112 KAPUTM: ',I11,' IS NOT AN ACCEPTABLE VALUE FOR
     +        THE DEFAULT RECORD LENGTH')
 113  FORMAT('CRNKA113 KAPUTM: ',I11,' IS NOT AN ACCEPTABLE VALUE FOR
     +        THE MAXIMUM RECORD LENGTH')
 114  FORMAT('CRNKA114 KAPUTM: THE DEFAULT RECORD LENGTH OF ',I11,
     +       ' EXCEEDS THE MAXIMUM RECORD LENGTH OF ',I11)
 121  FORMAT('CRNKA115 KAPUTM: MODIFICATION ATTEMPTED ON UNIT ',I3,
     +       ' WITH MODIFY=NO SET')
 131  FORMAT('CRNKA116 KAPUTM: REPLACEMENT OF MAJOR NAME ''',A,
     +       ''' FAILED ON UNIT ',I3,', THIS MAJOR NAME DOES NOT EXIST
     +        IN THE KA-FILE')
 141  FORMAT('CRNKA117 KAPUTM: REPLACEMENT OF MAJOR NAME ''',A,
     +       ''' FAILED ON UNIT ',I3,
     +       ', THE MAJOR NAME HAS NOT BEEN ACCESSED IN UPDATE MODE')
*
      END
