×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Writing results to a txt file through a subroutine

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

RE: Writing results to a txt file through a subroutine

try

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

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

RE: Writing results to a txt file through a subroutine

(OP)
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

RE: Writing results to a txt file through a subroutine

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

RE: Writing results to a txt file through a subroutine

(OP)
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.

RE: Writing results to a txt file through a subroutine

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
 

RE: Writing results to a txt file through a subroutine

(OP)
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.

RE: Writing results to a txt file through a subroutine

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

RE: Writing results to a txt file through a subroutine

(OP)
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.

RE: Writing results to a txt file through a subroutine

just save it in the same folder as the inp/odb file.
use open(unit=105, file='\STATEV.txt', STATUS='NEW')

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources