Ansys Assistant will be unavailable on the Learning Forum starting January 30. An upgraded version is coming soon. We apologize for any inconvenience and appreciate your patience. Stay tuned for updates.
Preprocessing

Preprocessing

Topics related to geometry, meshing, and CAD.

How to read values from an external .txt file into an ARRAY in APDL ?

    • Phanindra Reddy Ravi
      Subscriber

      I had a text file with values as below

      59, -65, 5, 5, 0, -65, 85, 90, -30, -30, -30, 60, -70, 10, 40, 40, 40, 45, 80, 80, 80, 85, 0

      67, 5, -65, 0, -65, 90, -90, -50, -50, -50, -45, 20, -70, 0, -5, -10, -90, -90, -5, 85, 85, 0, -65

      71, 15, -65, -30, -30, -30, -30, -30, -35, -35, -35, 0, -65, 30, -70, -10, -10, -10, 65, -65, -65, 0, 50

      How should I read these values into an array in APDL ?


      I tried using *vread but I am getting error.


      /INQUIRE,rows,LINES,'file','txt'

      *DIM,arr_data,ARRAY,rows,23


      *VREAD,arr_data,'file','txt',' ',jik,23,rows,1,0


      I am getting fallowing warning

      In the graphical user interface, the VREAD command can only be executed

       from an external file such as /INPUT or *USE. The command is ignored.


      Please can anyone share working code to read the above external data into an array in APDL ?

    • Phanindra Reddy Ravi
      Subscriber
      I am able to get desired array.
    • Karthik Remella
      Administrator
      Hello Awesome! Great to know that you found the answer to your question. If you can share it with the forum members, that might be useful to others.
      Good luck with your modeling.
      Karthik
    • Phanindra Reddy Ravi
      Subscriber
      /INQUIRE,tot_keypoints,LINES,Keypointnumbers,txt
      *DIM,KPOINT_NO,,tot_keypoints,2
      *VRead,KPOINT_NO(1,1),Keypointnumbers,txt,,JIK,2,tot_keypoints
      (2F6.0) ! I forget to specify this formate in the above code so I got error
      !---------------------------------------------------------------------------------------------------------
      *dim,KpArr,array,tot_keypoints
      *DO,I,1,tot_keypoints
      KpArr(I) = KPOINT_NO(I,1)
      *ENDDO
      !---------------------------------------------------------------------------------------------------------
      *DO,I,1,tot_keypoints
      filename = KPOINT_NO(I,1)
      /INQUIRE,r3,LINES,file_%filename%,txt
      *DIM,KPFile_NO,,r3,1
      *VRead,KPFile_NO(1,1),file_%filename%,txt,,JIK,1,r3
      (F6.0)
      *ENDDO
      !---------------------------------------------------------------------------------------------------------

      As per my knowledge from APDL Codes for creating ARRAYs each row in the file should have same number of coloumns
      So I saved the values of each row in a seperate file and implemented the above APDL CODE.

      Data in each row of the above .txt file is saved in seperate files with the file named as file_59.txt , file_67.txt, file_71.txt, file_76.txt, file_82.txt.
      Example: File file_82.txt has the fallowing colomn data.
      82
      25
      -60
      -60
      -15
      -70
      -70
      5
      -60
      20
      45
      10
      10
      -15
      -70
      -70
      50
      55
      -60
      -60
      -15
      -15
      -80
      0
      -65
      -10
      85
      -5
      -5
      -5
      -5
      -5
      -5
      -5
      -10
      -10
      -10
      -10
      -10
      -10
      80
      15
      15
      -60
      10
      -60
      -5
      70
      20
      -60
      -15
      -15
      -85
      65
      -5
      5
      -65

      Data contained in the file named "Keypointnumbers.txt" is given beolw:
      59, 61
      67, 41
      71, 42
      76, 48
      82, 57
      first coloumns represents number for iterating over files in the later steps
      and second colomns represents the number of rows present in each file.


Viewing 3 reply threads
  • The topic ‘How to read values from an external .txt file into an ARRAY in APDL ?’ is closed to new replies.
[bingo_chatbox]