*
* $Id$
*
* $Log$
* Revision 1.1  1996/03/08 11:40:50  mclareni
* Initial revision
*
*
#include "kapack/pilot.h"
      SUBROUTINE KAADD(LUN,MAJNAM,MINNAM,IDATA,LDATA,IRC)
*
*.....ADD A RECORD TO A KA-FILE
*
#include "kapack/kax000.inc"
#include "kapack/kax020.inc"
#include "kapack/kax050.inc"
#include "kapack/kax0a0.inc"
*
      CHARACTER MAJNAM*(*), MINNAM*(*)
*
      INTEGER IDATA(*)
*
*-----------------------------------------------------------------------
*
      CALL KAXINI(LUN)
      IF ( .NOT. MODIFY )  GO TO 21
*
*.....PROCESS THE MAJOR NAME
      CALL KAXMAJ(MAJNAM,*11,*31)
*
*.....CHECK THE RECORD LENGTH, LDATA
      IF ( LDATA.LT.-1 .OR. LDATA.GT.KLMAX(0) )  GO TO 13
      LXDATA = LDATA
      IF ( LXDATA .EQ. -1 )  LXDATA = KLDEF(0)
*
*.....CONVERT THE MINOR NAME TO A KEY
      CALL KAXNAM(MINNAM,MINKEY,*12)
*
*.....ADD THE RECORD TO THE MINOR TREE
      CALL KAXADD(KROOT(0),MINKEY,IDATA,LXDATA,*41,*91)
*
*.....SUCCESSFUL COMPLETION
      IRC = 0
      WRITE(MSG,100) MAJNAM, MINNAM, LXDATA, LUN
      CALL KAXMSG(LUNLOG,MSG)
      RETURN
*
*.....ERROR PROCESSING
 11   IRC = 1
      WRITE(MSG,111) MAJNAM
      GO TO 99
*
 12   IRC = 1
      WRITE(MSG,112) MINNAM
      GO TO 99
*
 13   IRC = 1
      WRITE(MSG,113) LDATA, KLMAX(0), MAJNAM
      GO TO 99
*
 21   IRC = 2
      WRITE(MSG,121) LUN
      GO TO 99
*
 31   IRC = 3
      WRITE(MSG,131) MAJNAM, MINNAM, LUN
      GO TO 99
*
 41   IRC = 4
      WRITE(MSG,141) MAJNAM, MINNAM, LUN
      GO TO 99
*
 91   WRITE(MSG,191) MAJNAM, MINNAM, LUN
      CALL KAXMSG(LUNERR,MSG)
      CALL KAXEND
*
 99   CALL KAXMSG(LUNERR,MSG)
      IF ( RETURN )  RETURN
      CALL KAXEND
*
 100  FORMAT('CRNKA010 KAADD: ''',A,' ',A,''' OF LENGTH ',I11,
     +       ' WORDS HAS BEEN ADDED TO THE KA-FILE ON UNIT ',I3)
 111  FORMAT('CRNKA011 KAADD: ''',A,''' IS NOT AN ACCEPTABLE MAJOR
     +        NAME')
 112  FORMAT('CRNKA012 KAADD: ''',A,''' IS NOT AN ACCEPTABLE MINOR
     +        NAME')
 113  FORMAT('CRNKA013 KAADD: ',I11,' IS NOT AN ACCEPTABLE RECORD ',
     +       ' LENGTH, IT MUST BE IN THE RANGE 0 - ',I11,
     +       ' FOR MAJOR NAME ''',A,'''')
 121  FORMAT('CRNKA014 KAADD: MODIFICATION ATTEMPTED ON UNIT ',I3,
     +       ' WITH MODIFY=NO SET')
 131  FORMAT('CRNKA015 KAADD: ADDITION OF ''',A,' ',A,''' FAILED
     +        ON UNIT ',I3,', THE MAJOR NAME DOES NOT EXIST IN THE
     +        KA-FILE')
 141  FORMAT('CRNKA016 KAADD: ADDITION OF ''',A,' ',A,''' FAILED
     +        ON UNIT ',I3,', THIS RECORD ALREADY EXISTS IN THE
     +        KA-FILE')
 191  FORMAT('CRNKA017 KAADD: ADDITION OF ''',A,' ',A,''' FAILED
     +        ON UNIT ',I3,', THE KA-FILE CONTAINS INSUFFICIENT FREE
     +        SPACE')
*
      END
