!*********************************************************************************************************************************************************!
!* Copyright (c) <2015> <Purdue University> All rights reserved.																					     *!
!*                                                                      																			     *!
!* Developed by:  Fang Jiang, Wenbin Yu                                                                                                                  *!
!*        <Prof. Yu’s Research Group>,                                                                                                                   *!
!*        <School of Aeronautics and Astronautics, Purdue University>                                                                                    *!
!*        <https://cdmhub.org/projects/ansysvabsgui2015>                                                                                                 *!
!*                                                                      																			     *!
!* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),    *!
!* to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,  *!
!* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:            *!
!*                                                                      																			     *!
!* •Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.                        *!
!*                                                                      																			     *!
!* •Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation *!
!*  and/or other materials provided with the distribution.                                                                                               *!
!*                                                                      																			     *!
!* •Neither the names of < Prof. Yu’s Research Group, School of Aeronautics and Astronautics, Purdue University >,                                       *!
!*  nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission.   *!
!*                                                                      																			     *!
!* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *!
!* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *!
!* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER     *!
!* DEALINGS WITH THE SOFTWARE. 																															 *!
!*********************************************************************************************************************************************************!

!Airfoil geometry creating module
! variable list:
! LN_cntr: line counter between keypoints
! KPMOST: the virtual-timely highest key point number 

!FINISH
/PREP7

! Build geometry

*DEL, BSLNC
*DIM, BSLNC, ARRAY, PNUM, 2, 1,
*DEL, AFLNC_%LPS1HPS2%
*DIM, AFLNC_%LPS1HPS2%, ARRAY, PNUM, 2, 1,

*IF, LPS1HPS2, EQ, 1, THEN
*VREAD, BSLNC(1,1), UserAirFoilFiles/VABS_AirFoil_Profile_LPS_%AFFID%, TXT, , JIK, 2, PNUM
(F15.0,F15.0)
*VREAD, AFLNC_%LPS1HPS2%(1,1), UserAirFoilFiles/VABS_AirFoil_Profile_LPS_%AFFID%, TXT, , JIK, 2, PNUM
(F15.0,F15.0)
*ENDIF

*IF, LPS1HPS2, EQ, 2, THEN
*VREAD, BSLNC(1,1), UserAirFoilFiles/VABS_AirFoil_Profile_HPS_%AFFID%, txt, , JIK, 2, PNUM
(F15.0,F15.0)
*VREAD, AFLNC_%LPS1HPS2%(1,1), UserAirFoilFiles/VABS_AirFoil_Profile_HPS_%AFFID%, txt, , JIK, 2, PNUM
(F15.0,F15.0)
*ENDIF

!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/PREP7



!=====================================================================================


*GET, KPMOST, KP, 0, NUM, MAXD
*IF,flipflag,EQ,0,THEN
		!=====================================================================================
		ALLSEL,ALL
		*DO,i,1,PNUM
			K, KPMOST+i, BSLNC(i,1)*CL-centx, BSLNC(i,2)*CL-centy, 0             ! Default key point number
		*ENDDO
		KSEL,S,KP,,KPMOST+1,KPMOST+PNUM
		SPLINE,ALL
	*ELSEIF,flipflag,EQ,1
		!=====================================================================================
		ALLSEL,ALL
		*DO,i,PNUM,1,-1
		    j=1+PNUM-i
			K, KPMOST+j, -BSLNC(i,1)*CL+centx, BSLNC(i,2)*CL+centy, 0             ! Default key point number
		*ENDDO
		KSEL,S,KP,,KPMOST+1,KPMOST+PNUM
		SPLINE,ALL
	*ELSE
*ENDIF



CutP_0=1
*IF,flipflag,EQ,0,THEN
*DO,pp,1,10
!-------------------------------------------------------------------------------------
*IF,CutP_%pp%,NE,0,THEN
        KSEL,S,KP,,KPMOST+CutP_%(pp-1)%,KPMOST+CutP_%pp%
		LSLK,S,1
		*GET,LN_cntr,LINE,0,COUNT
		*IF,LN_cntr,GT,1,THEN
				LCOMB, ALL, , 0
			*ELSEIF,LN_cntr,EQ,1
			*ELSE
		*ENDIF
	*ELSEIF,CutP_%pp%,EQ,0
		KSEL,S,KP,, KPMOST+CutP_%(pp-1)%, KPMOST + PNUM
		LSLK,S,1
		*GET,LN_cntr,LINE,0,COUNT
		*IF,LN_cntr,GT,1,THEN
				LCOMB, ALL, , 0
			*ELSEIF,LN_cntr,EQ,1
			*ELSE
		*ENDIF	
		*EXIT  ! exit a nearest do-loop
	*ELSE			
*ENDIF
!-------------------------------------------------------------------------------------
*ENDDO
*ENDIF

!=====================================================================================
*IF,flipflag,EQ,1,THEN
*DO,pp,1,10
!-------------------------------------------------------------------------------------
*IF,CutP_%pp%,NE,0,THEN
		KSEL,S,KP,,(KPMOST+PNUM)-CutP_%pp%+1,(KPMOST+PNUM)-CutP_%pp-1%+1
		LSLK,S,1
		*GET,LN_cntr,LINE,0,COUNT
		*IF,LN_cntr,GT,1,THEN
				LCOMB, ALL, , 0
			*ELSEIF,LN_cntr,EQ,1
			*ELSE
		*ENDIF
	*ELSEIF,CutP_%pp%,EQ,0
		KSEL,S,KP,, KPMOST+1, (KPMOST + PNUM)-CutP_%(pp-1)%+1
		LSLK,S,1
		*GET,LN_cntr,LINE,0,COUNT
		*IF,LN_cntr,GT,1,THEN
				LCOMB, ALL, , 0
			*ELSEIF,LN_cntr,EQ,1
			*ELSE
		*ENDIF	
		*EXIT  ! exit a nearest do-loop
	*ELSE			
*ENDIF
!-------------------------------------------------------------------------------------
*ENDDO
*ENDIF

ALLSEL,ALL
/PNUM,KP,0  
/PNUM,LINE,1
/PNUM,AREA,0
/PNUM,VOLU,0
/PNUM,NODE,0
/PNUM,TABN,0
/PNUM,SVAL,0  
/NUMBER,0    !Specify whether numbers, colors, or both are used for displays 0:color and number; 1:only color; 2:only number; -1:nothing
/AUTO,1 
/REP,FAST
LPLOT






