Suppressing New-Line Characters in APDL, and a Better WRTTBL.mac

Categories:

OK, it is Friday afternoon and if I do not write something soon the week will be missed. We did not do a seminar this week so I can not just post the notes and some comments from the webinar, bummer.  All of the real tech support people at PADT have been busy with training, mentoring and doing tech support, so they did not kick anything out. So that leaves me to come up with something. So, as is usually with me, I looked for something I felt guilty or ashamed of. Because that is the way my brain works.

And I remembered that two posting ago I put out a piece of junk macro that printed out tables, as part of the second article on tables in APDL.  Although it worked it was brute force and it used a bunch of *if statements to determine how many columns to write.  Ugly.

While I was extruding that particular piece of bodily waste something in the back of my mind said that APDL had an undocumented command that would suppress a line-feed on a *VWRITE. This is what one does with ‘C’ and other languages invented after the 1970’s.  If you suppress the line-feed, you can just loop over the number of columns. 

Next step, go to the help and see if it is there is some clue as to if that tickle in my brain was valid.  I found a posting on XANSYS from 2004… by some guy name Eric Miller…  Go figure. 

There are two descriptors that are not documented in the help: ‘/’ and ‘$’. 

‘/’ adds a newline, and ‘$’ suppresses it.  So if I want to write out the values in a 1D array all on one line but I don’t know how long the array is I can do:

*dim,myar,,10
myar(1) = 1,2,3,4,5,6,7,8,9,10
*get,nrw,parm,myar,dim,X

*cfopen,foo1.txt

*do,i,1,nrw
*vlen,1
*vwrite,myar(i)
(g16.9,$)
*enddo
*vwrite
(x)
*cfclose
 
This ends up creating foo1.txt:

image

So, extrapolating this, we can rewrite the nothing-to-be-proud about old wrttbl.mac with

 

ttbl = arg1      ! Get the name of the table you want to write

fname = arg2     ! get the name of the file to write to

 

*get,nrw,parm,%ttbl%,dim,X         ! Get the size of the table

*get,ncl,parm,%ttbl%,dim,Y

*get,xax,parm,%ttbl%,var,1         ! Get the names of the columns

*get,yax,parm,%ttbl%,var,2

 

*cfopen,%fname%    !Open the file

 

*vwrite,ttbl,xax,yax    ! Write a header (note / to add a line)

('Table: ',A,' ',A,' vs ',A,/) 

 

*vwrite         ! write 10 spaces, then don't write a new line by using $

('          |',$)

 

*do,jj,1,ncl ! Loop on each column, writing out the column value ($ again)

    *vlen,1

    *vwrite,%ttbl%(0,jj)

    (g10.4,$)

*enddo

*vwrite    !You need a line feed now that you are done, just write a space

(' ')

*vwrite    !Write a line of  dashes to seperate the header, with a pipe

(10x,'|',$)   ! to seperate the row values

*do,jj,1,ncl

    *vwrite

    (10('-'),$)

*enddo

*vwrite

(' ')

 

*do,ii,1,nrw    !Now write the values, looping on each row, then each column

    *vlen,1

    *vwrite,%ttbl%(ii,0)

    (g10.4,'|',$) 

    *do,jj,1,ncl

        *vlen,1

        *vwrite,%ttbl%(ii,jj)

        (g10.4,$) 

    *enddo

    *vwrite

    (' ')

*enddo

 

*cfclose

Have a great weekend!

Categories

Get Your Ansys Products & Support from the Engineers who Contribute to this Blog.

Technical Expertise to Enable your Additive Manufacturing Success.

PADT’s Pulse Newsletter

Keep up to date on what is going on at PADT by subscribing to our newsletter.


By submitting this form, you are consenting to receive marketing emails from: . You can revoke your consent to receive emails at any time by using the SafeUnsubscribe® link, found at the bottom of every email. Emails are serviced by Constant Contact

Share this post:

Upcoming Events

04/03/2024

Low Frequency Updates in Ansys 2024 R1 - Webinar

04/03/2024

Venture Madness Conference Reception + Expo

04/03/2024

Stratasys F3300: Game Changing Throughput - Webinar

04/08/2024

39th Space Symposium

04/09/2024

39th Space Symposium

04/10/2024

Discovery Updates in Ansys 2024 R1 - Webinar

04/10/2024

39th Space Symposium

04/11/2024

39th Space Symposium

04/22/2024

Experience Stratasys Truck Tour: Houston, TX

04/24/2024

Structures Updates in Ansys 2024 R1 (2)

04/24/2024

Experience Stratasys Truck Tour: Houston, TX

05/07/2024

Experience Stratasys Truck Tour: Albuquerque, NM

05/08/2024

Fluent Materials Processing Updates in Ansys 2024 R1 - Webinar

05/09/2024

Experience Stratasys Truck Tour: Los Alamos, NM

05/14/2024

Simulation World 2024

05/15/2024

Simulation World 2024

05/16/2024

Simulation World 2024

05/22/2024

Optics Updates in Ansys 2024 R1 - Webinar

06/12/2024

Connect Updates in Ansys 2024 R1 - Webinar

06/26/2024

Structures Updates in Ansys 2024 R1 (3) - Webinar

06/27/2024

E-Mobility and Clean Energy Summit

07/10/2024

Fluids Updates in Ansys 2024 R1 - Webinar

08/05/2024

2024 CEO Leadership Retreat

10/23/2024

PADT30 | Nerdtoberfest 2024

Search in PADT site

Contact Us

Most of our customers receive their support over the phone or via email. Customers who are close by can also set up a face-to-face appointment with one of our engineers.

For most locations, simply contact us: