General

General

How to access the working directory and the name of the currently opened .ad file via User Subroutine in Autodyn?

Tagged: autodyn, solver

    • FAQFAQ
      Participant

      The example below shows how to access the location and the name of the currently opened Autodyn file. The variables FDPRNT and FNID from the module fildef provide the directory and the name. If you compile the example below, launch the usersub exe file, open an Autodyn ad file and execute EXEDIT, the subtoutine will check get the location and the name of the file and open a text file with the same name as the ad file, but with the extension _OUTPUT.log in the working directory and will write the string “Hello World!” to text file.

      ! BEGIN EXAMPLE

      SUBROUTINE EXEDIT3

      USE kindef, ONLY: INT4
      USE fildef, ONLY : FDPRNT, FNID
      USE mdpp , ONLY : MYTASK
      IMPLICIT NONE

      INTEGER(INT4) :: I,J,K,KK, ICHK, IOS, NUNIT
      CHARACTER(LEN=256) :: FNAME
      CHARACTER (LEN=5) :: TEXT5
      DO I = 256, 1, -1
      IF (FNID(I:I)/=’ ‘) EXIT
      END DO
      DO J = 256, 1, -1
      IF (FDPRNT(J:J)/=’ ‘) EXIT
      END DO

      ! Include the task number in the log file
      CALL CONITC (MYTASK,TEXT5)
      DO K = 2,5
      IF (TEXT5(K:K)==’$’) EXIT
      KK = K
      END DO

      FNAME = FDPRNT(1:J)//’/’//FNID(1:i)//’_OUTPUT’//TEXT5(2:KK)//’.log’
      NUNIT = 78 ! HOPEFULLY FREE UNIT

      OPEN(UNIT=NUNIT,NAME=FNAME,FORM=’FORMATTED’, IOSTAT=IOS)
      WRITE (NUNIT,*,IOSTAT=IOS) ‘Hello World!’
      CLOSE (NUNIT)

      END SUBROUTINE EXEDIT3