Writing results to a txt file through a subroutine
Writing results to a txt file through a subroutine
(OP)
I would like to write results to a .txt file through a subroutine, but can not find the code to include into my subroutine. Can anyone help? I have provide my current subroutine below. Thanks.
SUBROUTINE USDFLD (FIELD,STATEV,PNEWDT,DIRECT,T,CELENT,TIME,DTIME,CMNAME,ORNAME,NFIELD,NSTATV,NOEL,NPT,LAYER,KSPT,KSTEP,KINC,NDI,NSHR,COORD,JMAC,JMATYP,MATLAYO,LACCFLA)
c
INCLUDE 'ABA_PARAM.INC'
c
CHARACTER*80
CMNAME,ORNAME
CHARACTER*3 FLGRAY(15)
DIMENSION FIELD(NFIELD),STATEV(NSTATV),DIRECT(3,3),T(3,3),TIME
DIMENSION ARRAY(15),JARRAY(15),JMAC(*),JMATYP(*),COORD(*)
c
CALL GETVRM ('E',ARRAY,JARRAY,FLGRAY,JRCD,JMAC,JMATYP,MATLAYO,LACCFLA) EPS=ABS(ARRAY(1))
c
FIELD(1)=EPS
c
STATEV(1)=FIELD(1)
c
OPEN (unit=1, file='STATEV.txt')
WRITE (1),STATEV(1)
c
RETURN
END
SUBROUTINE USDFLD (FIELD,STATEV,PNEWDT,DIRECT,T,CELENT,TIME,DTIME,CMNAME,ORNAME,NFIELD,NSTATV,NOEL,NPT,LAYER,KSPT,KSTEP,KINC,NDI,NSHR,COORD,JMAC,JMATYP,MATLAYO,LACCFLA)
c
INCLUDE 'ABA_PARAM.INC'
c
CHARACTER*80
CMNAME,ORNAME
CHARACTER*3 FLGRAY(15)
DIMENSION FIELD(NFIELD),STATEV(NSTATV),DIRECT(3,3),T(3,3),TIME
DIMENSION ARRAY(15),JARRAY(15),JMAC(*),JMATYP(*),COORD(*)
c
CALL GETVRM ('E',ARRAY,JARRAY,FLGRAY,JRCD,JMAC,JMATYP,MATLAYO,LACCFLA) EPS=ABS(ARRAY(1))
c
FIELD(1)=EPS
c
STATEV(1)=FIELD(1)
c
OPEN (unit=1, file='STATEV.txt')
WRITE (1),STATEV(1)
c
RETURN
END





RE: Writing results to a txt file through a subroutine
101 FORMAT (F12.6)
WRITE(1,101), STATE(1)
not sure about the comma in the WRITE statement
RE: Writing results to a txt file through a subroutine
You can use fortran OPEN Fortran statment to open external file and next WRITE statment to save any information into the file.
List file units which you can use with OPEN statement you will find in Abaqus documentation in chapter: 3.7 FORTRAN unit numbers.
Regards,
Bartosz
RE: Writing results to a txt file through a subroutine
INTEGER, PARAMETER :: uSTATEV = 105
..
..
101 FORMAT (F12.6)
OPEN (UNIT=uSTATEV,
1 FILE='C:\.....STATEV.txt',
2 STATUS='NEW')
WRITE(105,101) STATEV(1)
..
..
I have tried using the following reference for help: Structured Fortran 77 for engineers and scientists (5th Ed.) Delores M.Etter
RE: Writing results to a txt file through a subroutine
The OPEN fortran statement should be run only one time.
You can not use the same file unit two times. Since you are using
STATUS='NEW' you can not create the same file two times.
USDFLD subroutine is called for each Abaqus increment, it means
in your example during second increment fortran try to use 105 file
unit second time and create file which already exists.
You must control how many times you use OPEN statement.
To do it you can use additional logic variable to control is your file
is open or not.
CODE
...
c since the variable is initialize in declaration block .FALSE.
c value will be set only for first USDFLD call.
c since we have "save" parameter the variable will be not destroyed c after USDFLD call.
logical, save :: isFileOpen = .FALSE.
...
c statement block
...
c is the file open?
if (.not. isFileOpen) then
c open external file
open(unit=105, file='C:\Temp\STATEV.txt', STATUS='NEW')
c change file flag
isFileOpen = .TRUE.
end if
c write data to STATEV.txt file
write(105,'(F12.6)') statev(1)
...
Regards,
Bartosz
RE: Writing results to a txt file through a subroutine
RE: Writing results to a txt file through a subroutine
I changed folowing line:
CODE
CODE
Now it works on my side. Please try and let me know.
Regards,
Bartosz
RE: Writing results to a txt file through a subroutine
I made the changes above also, but still no sign of a STATEV.txt file after I run the analysis. I am running the analysis from a command window using the following commands:
abaqus job=input user=subroutine
Can I ask how you got it to work on your side and how did you try this yourself?
Thank-you for all your help. Much appreciated.
RE: Writing results to a txt file through a subroutine
I am attaching my inputdeck an your subroutine with modification.
Please update path to ascii file in OPEN statement.
I just used my old model where I was testing something, so there are many things which you do not need, do not worry about it.
One more thought, are you sure that Abaqus calls USDFLD subroutine?
Perhaps you have no material definition with dependencies than Abaqus will not call your subroutine even that you added it with user option.
Regards,
Bartosz
RE: Writing results to a txt file through a subroutine
I recieved the following error message when trying to use the directory on my h: drive:
forrtl: severe (9): permission to access file denied, unit 105, file H:\......\STATEV.txt
I guess I will just need to use the C:\ drive for the STATEV.txt file.
Thanks again for all you input and support.
RE: Writing results to a txt file through a subroutine
use open(unit=105, file='\STATEV.txt', STATUS='NEW')