*deck,USSFin       USERDISTRIB                                          jas
      subroutine USSFin
c **********  a user subroutine called after a substep  **********
c
c         Also calls the macro ussfin.mac
c
c         in order to activate this user programmable feature,
c         the user must enter the usrcal command.
c
c  Subroutines USSBeg, UItBeg, UItFin and USSFin default to reading a command 
c  macro file from the current working directory whose name is a
c  subroutine.mac (ie ussfin.mac is read by USSFin.F).   No user action
c  to relink the ANSYS program is required for the command macro to be
c  read except that the calling subroutine must be activated by the USRCAL
c  command.   The design of the command reading ability of these subroutines
c  is limited to APDL parameter setting commands (*GET, *SET, a=value, etc)
c  and testing for general ANSYS commands is limited.  Commands which are
c  known to work include *DIM, *STAT.  Commands which require another line
c  (*MSG, *VWRITE) are not allowed. Other commands which are known to not
c  work are the solution loading commands (D, F, SFE, etc).  If these
c  capabilties are required, the user will need to create a Fortran
c  subroutine and link this subroutine into ANSYS, as described in
c  Section 1.1 of the Guide to ANSYS User Programmable Features.
c
c 
c  While parameter substitution into commands is not permitted,  USSBeg,
c  etc. were designed to be used in conjunction with dynamic tables and
c  parameter substitution from the user subroutine.  As an example,
c  consider an ANSYS table defined as d5 = f(par1),  If  d5 contains
c  values of displacement as a function of PAR1, then d5 may be used
c  as a constraint, as
c  
c  *dim,d5,table,10,1,1,PAR1
c  d5(1)=0,.1,.25,
c  
c  /solu
c  d,5,ux,%d5%
c  
c  Modify the value of PAR1 in USSBeg.MAC and the constraint on
c  node 5, ux can then be modified in the middle of a load step.
c  
c      
c  The following is an example of a valid input that may be read by 
c  USSBeg, UItBeg, UItFin and USSFin.
c  
c  /COM, SAMPLE ussfin.mac
c  a=5
c  b=nx(1)                        ! *get function is ok
c  *get,c,active,solu,Time,cpu    ! *get is ok
c  *dim,array,,6                  ! array parameters are ok
c  array(1) = 1
c  array(2) = 2
c  array(3) = 3
c  array(4) = 4
c  array(5) = 5
c  array(6) = 6
c  *vleng,3                       ! vector operations are ok
c  *vfun,array(4),copy,array(1)
c  *stat
c  *stat,array(1)
c  array(1)=
c  nnode = ndinqr(0,14)
c  *dim,array,,nnode
c  *vget,array(1),NODE,1,NSEL
c  *stat,array(1)
c  array(1)=
c  /eof
c  
c  /COM, COMMANDS BELOW THIS LINE ARE KNOWN TO NOT WORK
c  
c  p,1,6,2000                     ! commands DO NOT work
c  d,1,uy,.1
c  *msg,note
c  THIS IS A TEST MESSAGE
c  *vwrite,array(1)
c  (/ b = ,f10.4)
c                          
c
c         *** Copyright ANSYS.  All Rights Reserved.
c         *** ansys, inc.
c
#include "impcom.inc"
#include "syspar.inc"

      external             runfile, erhandler
      integer              runfile, kerr, kallone, usrerr
      character*(LENNAM)   fname
      character*8          fext
      character*(LENDIR)   fdir
      data                 kallone / 2 /
      data                 usrerr  / 0 /
c
c   *** customer should remove the below warning when making any changes ***
c     call anserr (2,'ANSYS,INC.-supplied version of coding for USSFin
c    x  has been used',0.0d0,' ')

      if (kallone .gt. 1) then
         call erhandler ('USSFin',5000,2,'ANSYS, Inc.-supplied version 
     x    of coding for USSFin has been used.',0.0d0,' ')
         kallone = -2
      endif

c        *****  this will run the macro ussfin.mac at this point  *****
c        *****  the number of calls to ussfin.mac may not equal   *****
c        *****  the number of calls to ussbeg.mac since ussfin    *****
c        *****  is not called if the substep is converged.  This  *****
c        *****  would require a change to svkan

      if (usrerr .le. 0) then
         fname = 'ussfin'
         fext  = 'mac'
         fdir = '    '
         kerr = runfile (fname,fext,fdir)
         usrerr = kerr
      endif
c     kerr = 0, successful   else error
c            1, bad file name  (fillab)
c            2, unable to open (sysopn)
c            3, read error on file
                                 
      return
      end
