Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing results to a txt file through a subroutine 1

Status
Not open for further replies.

Timusop

Mechanical
Sep 23, 2011
58
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
 
Replies continue below

Recommended for you

try

101 FORMAT (F12.6)
WRITE(1,101), STATE(1)


not sure about the comma in the WRITE statement
 
Hi,

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
 
Thank-you all for your input, but still having problems with this. I tried the following but still no success:

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
 
Hello,

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 declaration block
...
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
 
Thanks you for your input, I am still having problems with this. It does not print out a .txt file, but I do not recieve any error messages, so it makes this tricky to solve. I have uploaded the .for file to this post if you could offer any more input? Thanks again.
 
 http://files.engineering.com/getfile.aspx?folder=b0bd113b-a475-4161-bb40-5c603e321f27&file=Model_1_Code_2.for
Hi,

I changed folowing line:
Code:
       if (105.NE.isFileOpen) then
into
Code:
       if (.NOT. isFileOpen) then
and I added full path to the file to save the file in the same directory as inputdeck.
Now it works on my side. Please try and let me know.

Regards,
Bartosz
 
Hi,

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.
 
Hi,

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
 
 http://files.engineering.com/getfile.aspx?folder=b774acfe-4e0e-4dda-86c2-12d92251cb69&file=29092011_eng_tips_save_into_ascii.zip
Thanks Bartosz, Managed to get it working finally with all your help. I also noticed that I could not leave the STAVEV.txt file in my h: drive. It only seemed to work if the directory for STATEV.txt was set to C:\Abaqus_Temp.

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.
 
just save it in the same folder as the inp/odb file.
use open(unit=105, file='\STATEV.txt', STATUS='NEW')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor