!
!       TITLE:  rvplot_nodal.mac (POST)
!
!
!  Plot nodal results versus node location for the selected node set.
!
!  This is the vector version of rplot_nodal.mac which uses *Vxx operations
!  to obtain the POST1 results for plotting.  This version of rplot_nodal
!  only uses Perl for writing PSI-Plot .DAT files (see mkdat option).
!
!  See "rplot_nodal.mac" for usage information.
!
!
!   rvplot_nodal.mac
!       line1.perl
!

! # of data sets (curves) to plot
*get,npairs_,cmd,0,nargs
npairs_=(npairs_-3)/2

*get,prkey_,active,0,prkey
/nopr

fini
/post1

!
! Give the input meaningful names
!
cs_=arg1
SrtDir_=arg2

*dim,items_,char,npairs_
*dim,comps_,char,npairs_
*dim,cmb_,char,npairs_      ! Combine items & comps

*do,i_,1,npairs_
    *if,i_,lt,5,then
        items_(i_)=arg%3+2*(i_-1)%
    *else
        items_(i_)=ar%3+2*(i_-1)%
    *endif

    *if,i_,lt,4,then
        comps_(i_)=arg%4+2*(i_-1)%
    *else
        comps_(i_)=ar%4+2*(i_-1)%
    *endif
        cmb_(i_)='%items_(i_)%%comps_(i_)%'
*enddo

!
! Save current settings
!
*get,csys_,active,0,csys
*get,rsys_,active,0,rsys
*get,dsys_,active,0,dsys

!
! All three coordinate systems must be set to get
! consistent results
!
rsys,cs_
csys,cs_
dsys,cs_        ! Needed for consistent NLIST

!
! Make a list of all the selected node numbers
!

! First get the max & min node numbers of the selected set
*get,nmax_,node,0,num,max
*get,nmin_,node,0,num,min
bw_=nmax_-nmin_+1               ! Bandwidth = Max possible # nodes in set

!
! Create one matrix containing all the data and
! define columns as follows:
!   1. Mask
!   2. Node number
!   3. Sort coordinate of nodes
!   4. Results for curve 1
!   5. Results for curve 2
!   .
!   .
!   n. Results for curve n
!
*dim,umat_,array,bw_,3+npairs_      ! Uncompressed full bandwidth matrix

! Get the mask vector of selected/unselected nodes in range
*vget,umat_(1,1),node,nmin_,nsel    ! -1=unsel,  0=undefined, 1=selected

! Make a list of node numbers
*vmask,umat_(1,1)
*vfill,umat_(1,2),ramp,nmin_,1

!
! Create a list of nodal locations for the abscissa (x-axis)
!
*vmask,umat_(1,1)
*vget,umat_(1,3),node,nmin_,loc,SrtDir_

!
! Fill the results into the uncompressed matrix
!
avprin,0,0                          ! Use nodal average
*do,i_,4,3+npairs_
    *vmask,umat_(1,1)
    *vget,umat_(1,i_),node,nmin_,items_(i_-3),comps_(i_-3)
*enddo

!
! Move the data into a compressed table
!
*get,ncount_,node,0,count           ! Number of nodes in set
*dim,vnodes_,array,bw_

*vlen,bw_
*vmask,umat_(1,1)
*vfun,vnodes_(1),comp,umat_(1,2)

*set,%SrtDir_%_
*dim,%SrtDir_%_,array,bw_
*vmask,umat_(1,1)
*vfun,%SrtDir_%_(1),comp,umat_(1,3)

!
! Apply the any math functions that may have been specified
!
! The use of temp_ and dup_ are work arounds for Ansys quirks.
!
*set,a_
*dim,a_,table,bw_,npairs_
*do,i_,1,npairs_
    *get,ptype_,parm,fcn%i_%,type   ! Define math function
    *if,ptype_,eq,3,then

        ! Check for 'abs' and 'ABS' only. 'Abs' will be slower
        *if,fcn%i_%,eq,'ABS',then
            fcn%i_%='abs'
        *endif

        *if,fcn%i_%,eq,'abs',then
            ! Compress matrix of y-data using abs value result
            *vabs,1
            *vmask,umat_(1,1)
            *vfun,a_(1,i_),comp,umat_(1,3+i_)
        *else
            ! Apply math function to result
            temp_=fcn%i_%
            *do,j_,1,ncount_
                *get,dup,node,vnodes_(j_),items_(i_),comps_(i_)
                dup=%temp_%(dup)
                a_(j_,i_)=dup
            *enddo
        *endif
    *else
        ! Compress matrix of y-data
        *vmask,umat_(1,1)
        *vfun,a_(1,i_),comp,umat_(1,3+i_)
    *endif
    /gcolumn,i_,%items_(i_)%%comps_(i_)%
*enddo

! Sort the matrix relative to the sort direction coordinate
*dim,orig_,,bw_

*vlen,ncount_
*moper,orig_(1),a_(1,1),sort,%SrtDir_%_(1)

*vlen,ncount_
*moper,orig_(1),vnodes_(1),sort,%SrtDir_%_(1)

*vlen,ncount_
*moper,orig_(1),%SrtDir_%_(1),sort,%SrtDir_%_(1)

*vlen,ncount_
*vplot,%SrtDir_%_(1),a_(1,1),2,3,4,5,6,7,8

*get,ptype_,parm,mkasc,type
*if,ptype_,ne,-1,then
/com, Write the data to a Tk-Solver ".asc" file
! if parameter "MKASC" is defined.
/nopr
/out,rplot_nodal,asc
*msg,info
node:
*vlen,ncount_
*vwrite,vnodes_(1)
(F8.0)

*msg,info,SrtDir_
%C:
*vlen,ncount_
*vwrite,%SrtDir_%_(1)
(E20.12)

*do,i_,1,npairs_
*msg,info,cmb_(i_)
%C:
*vlen,ncount_
*vwrite,a_(1,i_)
(E20.12)
*enddo
/out

*endif

*get,ptype_,parm,mkdat,type
*if,ptype_,ne,-1,then
/com, Write the data to a PSI-Plot ".dat" file
! if parameter "MKDAT" is defined.

! Create the first line of column names
/nopr
/out,rplot_nodal,dat
*vwrite
('node')
*vwrite,SrtDir_
(A8)
*vwrite,cmb_(1)
(A8)
/out
/sys,runperl.bat line1.perl rplot_nodal.dat

! Write out all the data in column format
/out,rplot_nodal,dat,,append
*vlen,ncount_
*if,npairs_,eq,1,then
*vwrite,vnodes_(1),%SrtDir_%_(1),a_(1,1)
(F8.0,2E20.12)
*elseif,npairs_,eq,2,then
*vwrite,vnodes_(1),%SrtDir_%_(1),a_(1),a_(1,2)
(F8.0,3E20.12)
*elseif,npairs_,eq,3,then
*vwrite,vnodes_(1),%SrtDir_%_(1),a_(1),a_(1,2),a_(1,3)
(F8.0,4E20.12)
*elseif,npairs_,eq,4,then
*vwrite,vnodes_(1),%SrtDir_%_(1),a_(1),a_(1,2),a_(1,3),a_(1,4)
(F8.0,5E20.12)
*elseif,npairs_,eq,5,then
*vwrite,vnodes_(1),%SrtDir_%_(1),a_(1),a_(1,2),a_(1,3),a_(1,4),a_(1,5)
(F8.0,6E20.12)
*elseif,npairs_,eq,6,then
*vwrite,vnodes_(1),%SrtDir_%_(1),a_(1),a_(1,2),a_(1,3),a_(1,4),a_(1,5),a_(1,6)
(F8.0,7E20.12)
*elseif,npairs_,eq,7,then
*vwrite,vnodes_(1),%SrtDir_%_(1),a_(1),a_(1,2),a_(1,3),a_(1,4),a_(1,5),a_(1,6),a_(1,7)
(F8.0,8E20.12)
*else
*vwrite,vnodes_(1),%SrtDir_%_(1),a_(1),a_(1,2),a_(1,3),a_(1,4),a_(1,5),a_(1,6),a_(1,7),a_(1,8)
(F8.0,9E20.12)
*endif
/out

*endif

!
! Restore settings and Clean Up
!
/nopr
rsys,rsys_
csys,csys_
dsys,dsys_

*do,i_,1,npairs_
    *set,fcn%i_%
*enddo

*set,mkdat
*set,mkasc

! These parameters must remain defined in order for printing to work correctly
!*set,%SrtDir_%_
!*set,SrtDir_
!*set,a_

*set,bw_
*set,cmb_
*set,comps_
*set,Comp_
*set,csys_
*set,cs_
*set,dsys_
*set,dup_
*set,fcnx_
*set,items_
*set,i_
*set,j_
*set,ncount_
*set,nmax_
*set,nmin_
*set,npairs_
*set,orig_
*set,ptype_
*set,rsys_
*set,temp_
*set,umat_
*set,vnodes_

*if,prkey_,eq,1,then
    /go
*endif