General Mechanical

General Mechanical

*TREAD command, reading CSV-files containing all data.

    • Ermanno Manca


      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 file
      numlines = 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:
      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:


      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.

    • Mike Rife
      Ansys Employee

      Hi 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.


    • Dave Looman
      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 

    • Dave Looman
      Ansys Employee

      Also, the APDL gui is useful to review the *TREAD input.  In the top toolbar use Parameters> Array Parameters> Define/Edit...

    • mjmiddle
      Ansys Employee

      A 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:

      ! 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.0

      The 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

      • Ermanno Manca

        Thank 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?

    • mjmiddle
      Ansys Employee

      Two 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.
      ncols = 3
      *get,nlines,parm,newstr,dim,2    ! nlines will be 4 from data file below
      ! empty lines at the end of file will hurt this setup, since it will dimension based on number of lines.

      File "datafile.txt":

      Indices 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, 10

      The *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.5

      data 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

Viewing 5 reply threads
  • You must be logged in to reply to this topic.