! TITLE:  yield.mac  (POST)
!
!   - Reformated cvctrl from xansys.net by Chris Kennedy
!   - commented out *ASK prompting.
!   - changed variable names especially _parnam style 
!   - mention that based upon last plot setting
!   - rethink min-max labels because not in correct place and not turning
!     off correctly
!   - ernorm toggle not sure if working
! OBJECTIVE:
!  
!   
!
! COMMAND SYNTAX:
!          (1)   (2)    (3)     (4)
!   yield, Sy, posneg, mm_lbl, ernorm
!
! ARGUMENTS:
!
!  Sy = the material yield stress
!  posneg = 0/1 toggle, when set to 1 force +- YIELD spread on contour legend
!  mm_lbl = 0/1 toggle, when set to 1 hide min and max values in
!                     legend and replace with MIN/MAX label.
!  ernorm = 0/1 toggle, if 1 then ERNORM,ON is set.
!    
! DESCRIPTION:
!
!  In Post1 plots show elements that exceed the YIELD stress value as red, 
!  and elements which have a compressive stress lower than -YIELD as blue. 
!  If the minimum stress is not less than -YIELD than the actual minimum is 
!  used instead of -YIELD.
!
!  Uses /CVAL to control contours.
!   
! WARNING:
!
! EXAMPLES:
!
! TO BE DONE:
!
!  - *GET ERNORM status?
!  - How does previous plot setting (e.g. min, max) effect?
!
*get,AR67,ACTIVE,,PRKEY
/NOPR

! ar20 - material yield stress
! ar22 - the increment
*DIM,V_,,8
err_=0

!    *do,j,1,5
!     *ASK,ar20,'the material yield stress ',10000
!     *if,ar20,gt,0,then
!       *exit
!     *endif
!    *enddo
!*else
    ar20=arg1
!*endif

ar20=abs(ar20)

*get,mxcont_,plnsol,,max
*get,mncont_,plnsol,,min

*IF,mncont_,gt,ar20,then
   *MSG,WARN,mncont_,ar20
   The minimum stress value is %G, the requested range is +- %G. %/&
   This is not possible in CVCTRL.
   err_=1
*ELSE
   *if,mxcont_,eq,0,then
      mxcont_=10*ar20             ! set the V8 value high.
      V_(8)=mxcont_
   *elseif,mxcont_,lt,ar20,then   ! say the maximum stress is less than yeild.
      V_(8)=ar20
      ar20=mxcont_
   *elseif,mxcont_,ge,ar20,then
      V_(8)=mxcont_
   *endif

!    *IF,mncont_,gt,0,then       !commented out in original cvctrl.mac
!        *IF,mncont_,lt,1,then
!            mncont_=0
!        *ENDIF
!    *ENDIF
!    *if,mncont_,eq,0,then
!       mncont_=-ar20
!    *endif
     *if,arg2,eq,1,then
        ! arg2 = 1 Set +- YIELD.
        mncont_=-ar20
     *endif
*ENDIF

V_(1)=mncont_    ! the first value is mncont_, everything below is blue
V_(7)=ar20
ar22=(ar20-mncont_)/6             ! the increment

*DO,ar23,2,7
   V_(ar23)=mncont_+ar22*(ar23-1)
*ENDDO

*IF,err_,eq,1,then
   V_(1)=
   return,,ar67
*ENDIF


/CVAL,all,V_(1),V_(2),V_(3),V_(4),V_(5),V_(6),V_(7),V_(8)

*if,arg4,eq,1,then
  ! legend values are shifted down
  _ysh=-.042
  ! ernorm,on
*else
  _ysh=0
  ! ernorm,off
*endif
!
!
/replot
!
*if,arg3,eq,10,then
    !
    !
    ! Cover up the min and max values.
    ! 0 - black
    ! 15 - white
    !
    /ANUM ,0,     4, .9    , 0.24600
    /LSPEC,   0,     0, 12.000
    /LINE, 1.140, 0.246+_ysh, 1.440, 0.246+_ysh
    /ANUM ,0,     4, .9    ,-0.0960
    /LINE, 1.140,-0.095+_ysh, 1.440,-0.095+_ysh
    !
    ! MIN & MAX
    ! 4 - blue
    ! 12 - red
    ! 10 - yellow
    !
    /ANUM ,0,     1,  .9    , 0.24
    /TSPEC, 10, 0.65,   1,   0,   0
    /TLAB, 1.16, 0.237+_ysh,MIN
    /ANUM ,0,     1,  .9    ,-0.11100
    /TSPEC, 10, 0.65,   1,   0,   0
    /TLAB, 1.16,-0.108+_ysh,MAX
*endif

*IF,arg3,eq,1,then
    /ANUM ,0,     5,  1.3355    , 0.20633
    /LSPEC,    15,     0, 1.000
    /PSPEC,     4,     1,     0
    /POLY,4, 1.205, 0.179, 1.465, 0.179, 1.465, 0.233, 1.205, 0.233
    /ANUM ,0,     5,  1.3199    ,-0.29677
    /PSPEC,    12,     1,     0
    /POLY,4, 1.194,-0.321, 1.446,-0.321, 1.446,-0.273, 1.194,-0.273
    /ANUM ,0,     1,  1.3421    ,-0.31231
    /TSPEC, 10, 1.000,   1,   0,   0
    /TLAB, 1.220,-0.312,MAX STR
    /ANUM ,0,     1,  1.3477    , 0.18230
    /TLAB, 1.225, 0.182,MIN STR
*ENDIF

/go


! parsav,all,PARM,tmp
V_(1)=

*if,AR67,EQ,1,THEN
  /GOPR
*endif
/EOF