-
-
January 18, 2023 at 3:15 pm
Ermanno Manca
SubscriberHello,
I'm facing some problems using the *TREAD command. My problem is that displaying my table with the *STATUS command, gives me one less column and row of data.
I used the following code:
/INQUIRE,filelines,LINES,my_file_path,CSV    ! Discover the number of lines in a text filenumlines = filelines-skiplines                ! numlines = filelines - skiplines (here: 1)*DEL, read_csv,,NOPR*DIM,  read_csv,TABLE,numlines-1,numcols-1   ! Create table array to hold data*TREAD, read_csv,fnames_input(1,1),CSV,,skiplines  ! Import data into table*STATUS, read_csvÂI followed the instructions given here:Âhttps://simutechgroup.com/using-tread-in-ansys-mechanical-apdl-to-read-external-data/ÂBecause as described, entering the actual number of rows and columns for the relevant data leads to an unintentional shift of data.ÂThis is the content of the CSV in my_file_path:
Time Heatflux1 Heatflux2 Heatflux3 0 301 88 62 60 226.8 89 62 120 149 90 62 180 73 91 62 240 0 91 62 300 0 90 62 360 0 90 62 This is the output I get with the code described above:
 LOCATION         VALUE
    1    1    1   226.800000   Â
    2    1    1   149.000000   Â
    3    1    1   73.0000000   Â
    4    1    1   0.00000000   Â
    5    1    1   0.00000000   Â
    6    1    1   0.00000000   Â
    1    2    1   89.0000000   Â
    2    2    1   90.0000000   Â
    3    2    1   91.0000000   Â
    4    2    1   91.0000000   Â
    5    2    1   90.0000000   Â
    6    2    1   90.0000000   Â
    1    3    1   62.0000000   Â
    2    3    1   62.0000000   Â
    3    3    1   62.0000000   Â
    4    3    1   62.0000000   Â
    5    3    1   62.0000000   Â
    6    3    1   62.0000000   ÂIs there any way to get the first row and column included in my table without changing the csv-file?
Thanks a lot in advance.
-
January 23, 2023 at 4:32 pm
mrife
Ansys EmployeeHi Ermanno Manca
Just like there is a zeroth column (that holds the time data in your example) there is a zeroth row that needs data since you have more than one column. The '301, 88, 62' row is going to that zeroth row.Â
The example from the SimuTech page shows this but watch out as the first multi-column data screen shot is a little wrong/odd as the spreadsheet data does not match the text file nor APDL screenshot data. But idea is discussed.
MIkeÂ
-
January 23, 2023 at 4:37 pm
dlooman
Ansys Employee*TREAD treats the data as an indexed array. Column 0 and row 0 are the indices. Since your first row of data was read in as row 0 you can include it in the *status output with *status,0,NÂ
-
January 23, 2023 at 4:42 pm
dlooman
Ansys EmployeeAlso, the APDL gui is useful to review the *TREAD input. In the top toolbar use Parameters> Array Parameters> Define/Edit...
-
January 24, 2023 at 6:56 am
mjmiddle
Ansys EmployeeA key concept with table arrays is that indices are real numbers, but only when retrieving table values, not when setting. You do not use the same index entries when retrieving as when setting. The zero row, column is where the real-number index is stored. Simple example:
*DIM,springvari,TABLE,4,1,1,TIME,
! Time values
springvari(1,0) = 0.0 Â Â ! table row (retrieve-row) index set to zero column
springvari(2,0) = 1.0 Â Â ! table index
springvari(3,0) = 1.5 Â Â ! table index
springvari(4,0) = 2.0 Â Â ! table index
! Load values
springvari(1,1) = 50.0
springvari(2,1) = 50.0
springvari(3,1) = 275.0
springvari(4,1) = 500.0The above is actually a 1-dimensional array, so the second index would normally not be used in regular arrays. Do not use the same index entries when retrieving as when setting:
/com, %springvari(3,1)% Â Â ! do not do this. Â It is past the maximum range and will return the max value 500
! do this:
/com, %springvari(1.5,1)% Â Â ! returns 275.0. Note that you set index (3,1) to this value but used (1.5,1) to retrieve
/com, %springvari(1.75,1)% Â Â ! returns 387.5 (linear interpolated)
! or just do this since it is really meant to be a 1-dimensional array:
/com, %springvari(1.75)% Â Â ! returns 387.5
! you can't return the index numbers set as table entries:
/com, %springvari(3,0)% Â Â ! the second index is ignored since it's meant to be a 1D array. So same as %springvari(3)% which returns max value (500) since it is past the max index 2.0-
January 24, 2023 at 10:33 am
Ermanno Manca
SubscriberThank you so much for the explanation and the example.
Is there any other way to get the same index entries when retrieving as when setting while working with CSV files?Â
Â
So that the zeroth column and row are not used as indices?
-
-
January 24, 2023 at 7:07 am
mjmiddle
Ansys EmployeeTwo dimensional example:
If both row and column are greater than 1, the zero row and zero column are indices, so you will dimension row and column as one-less than number of rows and columns seen in the data file. The first row in the file is the column indices. Â The first column in the file is the row indices.
Example:
filename='datafile'
ncols = 3
*sread,newstr,%filename%,txt
*get,nlines,parm,newstr,dim,2 Â Â ! nlines will be 4 from data file below
*dim,t300,table,nlines-1,ncols-1
*tread,t300,%filename%,txt
! empty lines at the end of file will hurt this setup, since it will dimension based on number of lines.File "datafile.txt":
0,1.1,2.5
0.002,0.0017787,5
0.004,0.0025841,7
0.006,0.0033896,10Indices must be ascending order, so this applies to data in the first row and first column.
*tread can use data as comma, tab, or space delimited. Â Most all other code in APDL won't use tabs.
The first row and first column of data will not be seen when printing out the array since these are used as the indices.
When you get the data with *status, it will look like this:
row, col, value
1, 1, 0.0017787
2, 1, 0.0025841
3, 1, 0.0033896
1, 2, 5
2, 2, 7
3, 2, 10The *tread will set up indices like this:
t300(1,0) = 0.002
t300(2,0) = 0.004
t300(3,0) = 0.006
t300(0,0) = 0 Â Â ! not sure if this can be used
t300(0,1) = 1.1
t300(0,2) = 2.5data is set up like this as rows, cols seen from *status above:
t300(1,1) = 0.0017787
t300(2,1) = 0.0025841
t300(3,1) = 0.0033896
t300(1,2) = 5
t300(2,2) = 7
t300(3,2) = 10
-
- The topic ‘*TREAD command, reading CSV-files containing all data.’ is closed to new replies.
- The legend values are not changing.
- LPBF Simulation of dissimilar materials in ANSYS mechanical (Thermal Transient)
- Convergence error in modal analysis
- APDL, memory, solid
- How to model a bimodular material in Mechanical
- Meaning of the error
- Simulate a fan on the end of shaft
- Real Life Example of a non-symmetric eigenvalue problem
- Nonlinear load cases combinations
- How can the results of Pressures and Motions for all elements be obtained?
-
4077
-
1487
-
1318
-
1156
-
1021
© 2025 Copyright ANSYS, Inc. All rights reserved.