I have an array in a text file, and I need to read it into ANSYS. The array is written out in another analysis, and can change length depending on a number of parameters. I can use *VREAD to get the array data, but the *VREAD requires that the array is previously defined, and I do not know in advance how many points will be in the text file. What can I do?


If your array data always has the same number of columns, and you only need to know the rows, you can use the /INQUIRE command.

/INQUIRE, Parameter, FUNC, Fname, Ext

Parameter = scalar variable where resulting line count will be stored (e.g., "rows")
FUNC = use the LINES function in this example
Fname = filename where array data is stored (e.g., "myFile")
Ext = extension of filename (e.g., "txt")

Then, you can define and dimension your array using the *DIM command.

*DIM, Par, Type, IMAX, JMAX, KMAX, Var1, Var2, Var3, CSYSID

Par = array variable where data will be stored (e.g., arr_data)
Type = use the ARRAY type in this example
IMAX = number of rows in the array; use "rows" from the /INQUIRE command
JMAX = number of columns (e.g., "3")

Now, you have an array dimensioned properly, according to the data in "myFile.txt". Finally, you can fill the variable with *VREAD.

*VREAD, ParR, Fname, Ext, --, Label, n1, n2, n3, NSKIP

ParR = array variable where array data will be stored; use "arr_data" defined by the *DIM command
Fname = filename where array data is stored; use same "myFile" from /INQUIRE command
Ext = extension of filename; use same "txt" from /INQUIRE command
Label = order in which data are to be read (e.g., for text files containing a 2D array, this is typically "JIK")
n1 = number of "J's" if you use "JIK" (e.g., "3")
n2 = number of "I's" if you use "JIK" (e.g., "rows")

This can all be setup using variables to avoid typing errors; for example,

filenam = 'myfile'
fileext = 'txt'
cols = 3
/INQUIRE,rows,LINES,%filenam%,%fileext%
*DIM,arr_data,ARRAY,rows,cols
*VREAD,arr_data,%filenam%,%fileext%,,JIK,cols,rows





Show Form
No comments yet. Be the first to add a comment!