When we use APDL to output data to files, sometimes we may need to parameterize the output file names to facilitate simulation with other languages such as Matlab\Python.
This article mainly introduces how to implement parameterization of output file names.
APDL macro file parameter passing is mainly done by defining ARG1~ARG19 variable symbols in the macro file. The overall approach is as follows:
!Define macro file content
*Create,WriteData,mac
Filename=ARG1
*Cfopen,Filename,txt
!Data output related commands
……
*Cfclose
*End
!Run macro file, pass in parameters
Myfile=’AAdata’
WriteData,Myfile
Note that in APDL, character variables are generally defined using single quotes. Double quotes are invalid, and note that the character length of the file name with path should not exceed 264, otherwise it cannot be recognized!
Below demonstrates how to use it with a data output example
I. Definition of Output Data
*Dim,testA,array,100,4
*do,i,1,4
*do,j,1,100
testA(i,j)=i*j
*enddo
*enddo
II. Output array testA by rows, outputting 100 files in total, with each file name suffix being the corresponding row number.
!Build write function
*Create,WriteData,mac
filename=ARG1
!Row number of output data
HG=ARG2
*Cfopen,filename,txt
d1=testA(HG,1)
d2=testA(HG,2)
d3=testA(HG,3)
d4=testA(HG,4)
*Vwrite,d1,d2,d3,d4
(4F20.5)
*Cfclose
*END
!Output data
*do,i,1,100
filename='D:/ANSYS14/Data/testA_%i%'
*do,j,1,4
WriteData,filename,i
*enddo
*enddo
Screenshot as follows:

III. Output data by columns, 4 files in total, with file names defined in advance.
!Build output macro file
*Create,WriteData,mac
!Output file name
filename=ARG1
!Column number of output data
HG=ARG2
*Cfopen,filename,txt
*Vwrite,testA(1,HG)
(F20.5)
*Cfclose
*END
!Define array for output file names
*dim,FN,char,4,1
FN(1,1)='TTT'
FN(2,1)='SSS'
FN(3,1)='DDD'
FN(4,1)='RRR'
!Output data
*do,i,1,4
filename=strcat('D:/ANSYS14/Data/',FN(i,1))
WriteData,filename,i
*enddo
Screenshot as follows:

Using the above parameterized output file names, you can often achieve unexpected results. Give it a try!
If you find this useful, feel free to repost and share!








No comments yet