Let’s say that you have a file with numbers and text, separated by a space, and you want to read it into APDL arrays and strings.

/inquire,MY_LINES,lines,filename.txt

This reads the number of lines in the text file filename.txt and places that value in a scalar parameter MY_LINES. This allows us to dynamically obtain the length of the arrays (i.e., each line has two entries, number and text).

Next, the arrays will be dimensioned as follows:

*dim,STRING_DATA,string,128,MY_LINES
*dim,ARRAY_DATA,array,MY_LINES

Data can then be read and put into the string STRING_DATA:

*sread,STRING_DATA(1),filename.txt

The data containing number and text is read into each index of the string array STRING_DATA. Now, the data needs to be parsed using string functions; in this case, a space character is assumed to delimit the text:

*do,AR80,1,MY_LINES
AR70 = strpos(STRING_DATA(1,AR80),’ ‘)
ARRAY_DATA(AR80) = valchr(strsub(STRING_DATA(1,AR80),1,AR70))
AR71 = strleng(STRING_DATA(1,AR80))-AR70+1
STRING_DATA(1,AR80) = strsub(STRING_DATA(1,AR80),AR70,AR71)
*enddo

Looping through the number of lines (items in the array), the string position of the first occurrence of the space character (‘ ‘) is found.  The string is then cut up to that space – assuming that the first entry is a number, this is converted to from a string to number with the valchr() function.  Then, the last portion of the string is cut and put back into itself.

This is just a simple example of using string functions, /INQUIRE, and *SREAD commands to read arbitrary data from a text file and parse it accordingly.

Of course, if the data in a text file to be read only contains numbers, *TREAD or *VREAD are easier alternatives requiring no string functions.