/OUTPUT filename as three digit in Ansys APDL

Viewed 177

I have an operation inside a loop and save the output in each iteration, but I would like to name the file according to the iteration number, with leading zero if it's not a three digit number.

*DO, i, 1, 30

!operations goes here....
!...
!...

!out to file
/OUTPUT,%i%,txt

ENDDO

It however named the file as 1.txt, 2.txt, ... and 30.txt, not 001.txt, 002.txt.

I have tried

/OUTPUT,%02i,txt
/OUTPUT,%02i%,txt

But they output as literal string: %02i.txt and %02i%.txt respectively.

How to overcome this? Thanks!

1 Answers

Can you predefine the filenames? Than you can try something like this:

*dim,fnames,string,80,  3
fnames(1,1) = '001file'
fnames(1,2) = '002file'
fnames(1,3) = '003file'
*do,i,1,3
  /OUTPUT,%fnames(1,i)%,txt
*enddo

If not you can try:

*do,i,1,30
  *if,i,lt,10,then
    /OUTPUT,%00%%i%file,txt
  *elseif,i,lt,100,and,i,gt,9,then
    /OUTPUT,%0%%i%file,txt
  *else
    /OUTPUT,%i%file,txt
  *endif
*enddo
Related