      PROGRAM FLTCOND
      IMPLICIT NONE
      REAL MINWT, MAXWT,MINIX,MAXIX,MINIY,MAXIY,MINIZ,MAXIZ,
     +      FCG,ACG,MAXTTV,MAXT,TVUP,TVDOWN,TVYAW,
     +	     MAXLF,ALT(15),MINSPEED(15),MAXSPEED(15),
     +	     DUMMY,WT(15),IX(15),IY(15),IZ(15),CG(15),
     +	     THRUST(15),EPSILON(15),NU(15),LF(15),H(15),V(15)
      INTEGER N,IP,M,ISCREEN,I,L
      CHARACTER*50, TOPLINE
      CHARACTER*1, ICASE
      OPEN (UNIT = 10, FILE = 'FCINPUT.PRN', STATUS = 'OLD')
      REWIND (UNIT = 10)
      OPEN (UNIT = 15, FILE = 'FLTCOND.DAT')
      REWIND (UNIT = 15)
      ISCREEN = 5
C
C     *******************************************************************
C     This program determines the flight conditions at which
C     control power must be evaluated.  The input file is generated by a 
C     spreadsheet.  The output is a combination of wt., inertias, speed, 
C     alt., C.G. location, load factor, thrust and vectoring anles for 
C     each control power requirement catagory.
C
C     Prepared by Jacob Kay         Feb. 1992
C     ********************************************************************
C
C     *** INPUT PARAMETERS FROM FILE ***
      READ(10,*) MINWT, MAXWT
      READ(10,*) MINIX, MAXIX
      READ(10,*) MINIY, MAXIY
      READ(10,*) MINIZ, MAXIZ
C
C
      READ(10,*) FCG, ACG
      READ(10,*) MAXTTV, MAXT
      READ(10,*) TVUP, TVDOWN, TVYAW
      READ(10,*) MAXLF
      READ(10,*) N
      DO 1000, I = 1, N
         READ(10,*) ALT(I), MINSPEED(I),MAXSPEED(I)
 1000 CONTINUE
C
C     *** ECHO VALUES TO MONITOR TERMINAL ***
 1010 WRITE(ISCREEN,2000)
 2000 FORMAT (//////T8,  'SUMMARY OF INPUT PARAMETERS:')
      WRITE(ISCREEN,2010) MINWT, MAXWT
 2010 FORMAT (/T2,'(1)',T7,'Max Gross Wt (lbs)',T30,F7.0,T44,'(2)',
     +         T50,'Min Gross Wt (lbs)',T73, F7.0)
      WRITE(ISCREEN,2020) MINIX,MAXIX
 2020 FORMAT (T2,'(3)',T7,'Min I-xx (slug-ft^2)',T30,F7.0,T44,'(4)',
     +         T50,'Max I-xx (slug-ft^2)',T73, F7.0)
      WRITE(ISCREEN,2030) MINIY,MAXIY
 2030 FORMAT (T2,'(5)',T7,'Min I-yy (slug-ft^2)',T30,F7.0,T44,'(6)',
     +         T50,'Max I-yy (slug-ft^2)',T73, F7.0)
      WRITE(ISCREEN,2040) MINIZ,MAXIZ
 2040 FORMAT (T2,'(7)',T7,'Min I-zz (slug-ft^2)',T30,F7.0,T44,'(8)',
     +         T50,'Max I-xx (slug-ft^2)',T73, F7.0)
      WRITE(ISCREEN,2050) FCG
 2050 FORMAT (/T2,'(9)',T7,'Forward C.G. Location               ',
     +		'(% Mean Chord)',T60,F7.2)
      WRITE(ISCREEN,2060) ACG
 2060 FORMAT (T2,'(10)',T7,'Aft C.G. Location                   ',
     + '(% Mean Chord)', T60,F7.2)
      WRITE(ISCREEN,2070) MAXTTV
 2070 FORMAT (/T2,'(11)',T7,'Max Thrust with Thrust Vectoring    (lbs)',
     +         T60, F7.0)
      WRITE(ISCREEN,2080) MAXT
 2080 FORMAT (T2,'(12)',T7,'Max Thrust without Thrust Vectoring (lbs)',
     + 	 T60, F7.0)
      WRITE(ISCREEN,2090) TVUP
 2090 FORMAT (T2,'(13)',T7,'Max Thrust Deflection Angle--up     (deg)',
     +	        T60,F6.1)
      WRITE(ISCREEN,2100) TVDOWN
 2100 FORMAT (T2,'(14)',T7,'Max Thrust Deflection Angle--down   (deg)',
     +	       T60,F6.1)	
      WRITE(ISCREEN,2110) TVYAW
 2110 FORMAT (T2,'(15)',T7,'Max Thrust Deflection Angle--yaw    (deg)',
     +	       T60,F6.1)
      WRITE(ISCREEN,2120) MAXLF
 2120 FORMAT (/T2,'(16)',T7,'Max Normal Load Factor              (G)',
     +		T60,F4.1)
C
C     *** ALLOW USER TO MAKE ANY CHANGES TO THE DISPLAYED PARAMETERS ***
      WRITE(ISCREEN,3000) 
 3000 FORMAT (//, ' Change parameters? (y/n)')
      READ(*,3010) ICASE
 3010 FORMAT (A1)
      IF ((ICASE.EQ.'N').OR.(ICASE.EQ.'n')) GOTO 3500
      IF ((ICASE.EQ.'Y').OR.(ICASE.EQ.'y')) GOTO 3015
      WRITE(ISCREEN,3020)
 3020 FORMAT (' Illegal entry!')
      GOTO 1010
C     ** MAKE CHANGES **
 3015 WRITE(ISCREEN,3030)
 3030 FORMAT (' Enter parameter number, and new value.')
      READ(*,*) IP,DUMMY
              IF (IP.EQ.1) 	MINWT 	= DUMMY
              IF (IP.EQ.2) 	MAXWT 	= DUMMY
              IF (IP.EQ.3) 	MINIX 	= DUMMY
              IF (IP.EQ.4) 	MAXIX 	= DUMMY
              IF (IP.EQ.5) 	MINIY 	= DUMMY
              IF (IP.EQ.6) 	MAXIY 	= DUMMY
              IF (IP.EQ.7) 	MINIZ 	= DUMMY
              IF (IP.EQ.8) 	MAXIZ 	= DUMMY
              IF (IP.EQ.9)	FCG 	= DUMMY
              IF (IP.EQ.10)	ACG 	= DUMMY
              IF (IP.EQ.11)	MAXTTV	= DUMMY
              IF (IP.EQ.12)	MAXT	= DUMMY
              IF (IP.EQ.13) TVUP	= DUMMY
              IF (IP.EQ.14) TVDOWN	= DUMMY
              IF (IP.EQ.15) TVYAW	= DUMMY
              IF (IP.EQ.16) MAXLF	= DUMMY
C
C     ** DISPLAY ALL PARAMETERS AGAIN (1ST PAGE)**
      GOTO 1010
C
C     ** DISPLAY PARAMETERS ON 2ND PAGE **
 3500 WRITE(ISCREEN,3510)
 3510 FORMAT (/////,T7,'<< Altitude-Speed Range >> of ',//)
      DO 3600, I = 1, N
            WRITE(ISCREEN, 3520) I,ALT(I),MINSPEED(I),MAXSPEED(I)
 3600 CONTINUE
 3520 FORMAT (T2,'(',I2,')',T10,'Alt (ft) = ',T20,F7.0,T35,
     +        'Speed (knots) = ',T50,F6.0,' - ', F6.0 )
C     ** CHANGE ANYTHING? **
      WRITE(ISCREEN,3530) N
 3530 FORMAT (///////////,' Enter item to be changed (1-',I2,')',/,
     +        ' Enter 0 if no change needed.')
      READ(*,*) IP
      IF (IP.EQ.0) GOTO 4000
      WRITE(ISCREEN,3540)
 3540 FORMAT (' Enter the new altitude and speed.')
      READ(*,*) ALT(IP),MINSPEED(IP),MAXSPEED(IP)
      IF (IP.GT.N) THEN
              ALT(N+1) = ALT(IP)
              MINSPEED(N+1) = MINSPEED(IP)
              MAXSPEED(N+1) = MAXSPEED(IP)
              N = N+1
      ENDIF
C     ** DISPLAY 2ND PAGE AGIAIN **
      GOTO 3500
C
C     *** GO INTO EACH CONTROL POWER CATAGORY; GET A SET OF COMBINATIONS
C         OF FLIGHT CONDITION VARIABLES;WRITE TO OUTPUT FILE. ***
C
      WRITE(15,500)
 500  FORMAT ('FLIGHT CONDITION VARIABLES TO BE TESTED: ')	
C
C     ** (01)NOSEWHEEL LIFT-OFF **
 4000 TOPLINE = 'NOSE-WHEEL LIFT-OFF:'
      M = 3
      DO 4100, I = 1, M
         WT(I) = MAXWT
         IX(I) = 9E15
         IY(I) = MAXIY
         IZ(I) = 9E15
         CG(I) = FCG
         NU(1) = 0.0
         LF(I) = 9E15
         H(I) = 0.0
         V(I) = 9E15
 4100 CONTINUE
C     <O1> NO THRUST VECTORING
         THRUST(1) = MAXT
         EPSILON(1) = 0.0
C     <02> THURST DEFLECTION UP MAX (TO GET MAX PITCH-UP MOMENT)
         THRUST(2) = MAXTTV
         EPSILON(2) = -TVUP
C     <03> THURST DEFLECTION DOWN MAX (TO GET MAX UP FORCE)
         THRUST(3) = MAXTTV
         EPSILON(3) = TVDOWN
      CALL PRINTOUT(TOPLINE,M,WT,IX,IY,IZ,CG,THRUST,EPSILON,
     +			NU,LF,H,V)
 
C
C
C     *** (02) LANDING PITCH MOMENT ***
      TOPLINE = 'LANDING:'
      M = 1
      WT(1) = MAXWT
      IX(1) = 9E15
      IY(1) = MAXIY
      IZ(1) = 9E15 
      CG(1) = FCG
      THRUST(1) = 9E15
      EPSILON(1) = 0.0
      NU(1) = 0.0
      LF(1) = 1.0
      H(1) = 0.0
      V(1) = 9E15
      CALL PRINTOUT(TOPLINE,M,WT,IX,IY,IZ,CG,THRUST,EPSILON,
     +			NU,LF,H,V)
C
C     *** (03)UNACCELERATED FLT: 1-G TRIM ***
      TOPLINE = '1-G TRIM: '
      M = 4
C     ** LOWEST ALTITUDE **
      DO 4300, I = 1, 2
         WT(I) = MAXWT
         IX(I) = 9E15  
	  IY(I) = 9E15  
         IZ(I) = 9E15  
         CG(I) = FCG
         EPSILON(I) = 0.0
         NU(I) = 0.0
	  LF(I) = 1.0
         H(I)	= 0.0
 4300 CONTINUE 
      THRUST(1) = 9E15
      THRUST(2) = 9E15
      V(1) = MINSPEED(1)
      V(2) = MAXSPEED(1)
C     ** HIGHEST ALTITUDE **
      DO 4310, I = 3,4
         WT(I) = (MAXWT+MINWT)/2.0
         IX(I) = 9E15                      
         IY(I) = 9E15
         IZ(I) = 9E15                   
         CG(I) = (FCG+ACG)/2.0	
         EPSILON(I) = 0.0
         NU(I) = 0.0
         LF(I) = 1.0
         H(I)	= ALT(N)
 4310 CONTINUE
      THRUST(3) = 9E15
      THRUST(4) = 9E15
      V(3) = MINSPEED(N)
      V(4) = MAXSPEED(N)
      CALL PRINTOUT(TOPLINE,M,WT,IX,IY,IZ,CG,THRUST,EPSILON,
     +			NU,LF,H,V)
C
C     *** MANEUVERING FLT. **
      TOPLINE = 'MANEUVERING FLIGHT: '
      M = 4
C     ** LOWEST ALTITUDE **
      DO 4400, I = 1, 2
         WT(I) = MAXWT
         IX(I) = 9E15  
         IY(I) = 9E15  
         IZ(I) = 9E15
         CG(I) = FCG
         THRUST(I) = 9E15
         EPSILON(I) = 0.0
         NU(I) = 0.0
         H(I) = ALT(1)
 4400 CONTINUE 
         LF(1) = 1.5
         LF(2) = MAXLF
         V(1)	= MINSPEED(1)
         V(2) = MAXSPEED(1)
C     ** HIGHEST ALTITUDE **
      DO 4410, I = 3,4
         WT(I) = (MAXWT+MINWT)/2.0
         IX(I) = 9E15
         IY(I) = 9E15
         IZ(I) = 9E15
         CG(I) = (FCG+ACG)/2.0
         THRUST(I) = 9E15	
         EPSILON(I) = 0.0
         NU(I) = 0.0
         H(I) = ALT(N)
 4410 CONTINUE
         LF(3) = 1.5
         LF(4) = .95*MAXLF
	  V(3)	= MINSPEED(N)
	  V(4)	= MAXSPEED(N)
      CALL PRINTOUT(TOPLINE,M,WT,IX,IY,IZ,CG,THRUST,EPSILON,
     +			NU,LF,H,V)
C
C
C
C     *** (06)SHORT PERIOD-CAP ***
      TOPLINE = 'SHORT PERIOD & CAP REQUIREMENTS:'
      WRITE(15,502) TOPLINE
      WRITE(15,503)
 502  FORMAT(A50)
 503  FORMAT('Perform evaluation at design points.'//)
C
C     *** (07)PITCH DUE TO STABILITY AXIS ROLL ***
      TOPLINE = 'PITCH DUE TO STABILITY AXIS ROLL'
      M = 9
C     ** LOW ALTITUDE **
      DO 4700, I = 1, 3
         WT(I) = 9E15
         IX(I) = MINIX
         IY(I) = 9E15
         IZ(I) = MAXIZ
	  CG(I) = (FCG+ACG)/2.0
         THRUST(I) = 9E15
         EPSILON(I) = 0.0
         NU(I) = 0.0
         LF(I) = 9E15
         H(I) = ALT(1)
 4700 CONTINUE 
	 V(1) = MINSPEED(1)
	 V(2) = (MINSPEED(1)+MAXSPEED(1))/2.0
	 V(3) = MAXSPEED(1)	
C     ** MEDIUM ALT **
      DO 4710, I = 4, 6
	  WT(I) = 9E15
         IX(I) = MINIX
         IY(I) = 9E15
         IZ(I) = MAXIZ
         CG(I) = (FCG+ACG)/2.0
         THRUST(I) = 9E15
         EPSILON(I) = 0.0
         NU(I) = 0.0
         LF(I) = 9E15
	  H(I) = ALT((N+1)/2)
 4710 CONTINUE 
         V(4) = MINSPEED((N+1)/2)
         V(5) = (MINSPEED((N+1)/2)+MAXSPEED((N+1)/2))/2.0
         V(6) = MAXSPEED((N+1)/2)
C	** HIGH ALT **
	DO 4720, I = 7, 9
	  WT(I) = 9E15
         IX(I) = MINIX
         IY(I) = 9E15
         IZ(I) = MAXIZ
         CG(I) = (FCG+ACG)/2.0
         THRUST(I) = 9E15
         EPSILON(I) = 0.0
         NU(I) = 0.0
         LF(I) = 9E15
	  H(I) = ALT(N)
 4720 CONTINUE 
         V(7) = MINSPEED(N)
         V(8) = (MINSPEED(N)+MAXSPEED(N))/2.0
         V(9) = MAXSPEED(N)	
      CALL PRINTOUT(TOPLINE,M,WT,IX,IY,IZ,CG,THRUST,EPSILON,
     +			NU,LF,H,V)	
C
C     *** (08) TIME-TO-BANK (ROLL AXIS) ***
      TOPLINE = 'TIME-to-BANK PERFORMANCE: '
      M = 12
C     ** LOW ALT **
      DO 4800, I = 1, 4
         WT(I) = 9E15
         IX(I) = MAXIX
         IY(I) = 9E15
         IZ(I) = MAXIZ
         CG(I) = (FCG+ACG)/2.0
         THRUST(I) = 9E15
         EPSILON(I) = 0.0
         NU(I) = 0.0
         LF(I) = 1.0
	  H(I)	= ALT(1)
 4800	CONTINUE 
         V(1) = MINSPEED(1)
         V(2) = MINSPEED(1)+(MAXSPEED(1)-MINSPEED(1))/3.0
         V(3) = MINSPEED(1)+(MAXSPEED(1)-MINSPEED(1))*2.0/3.0
         V(4) = MAXSPEED(1)	
C     ** MED ALT **
         L = (N+1)/2
      DO 4820, I = 5, 8
         WT(I) = 9E15
         IX(I) = MAXIX
         IY(I) = 9E15
         IZ(I) = MAXIZ
         CG(I) = (FCG+ACG)/2.0
         THRUST(I) = 9E15
         EPSILON(I) = 0.0
         NU(I) = 0.0
         LF(I) = 1.0
         H(I) = ALT(L)
 4820 CONTINUE 
       V(5) = MINSPEED(L)
       V(6) = MINSPEED(L)+(MAXSPEED(L)-MINSPEED(L))/3.0
       V(7) = MINSPEED(L)+(MAXSPEED(L)-MINSPEED(L))*2.0/3.0
       V(8) = MAXSPEED(L)		
C     ** HIGH ALT **
      DO 4830, I = 9, 12
         WT(I) = 9E15
         IX(I) = MAXIX
         IY(I) = 9E15
         IZ(I) = MAXIZ
         CG(I) = (FCG+ACG)/2.0
         THRUST(I) = 9E15
         EPSILON(I) = 0.0
         NU(I) = 0.0
         LF(I) = 1.0
         H(I)	= ALT(N)
 4830	CONTINUE 
         V(9) = MINSPEED(N)
         V(10) = MINSPEED(N)+(MAXSPEED(N)-MINSPEED(N))/3.0
         V(11) = MINSPEED(N)+(MAXSPEED(N)-MINSPEED(N))*2.0/3.0
         V(12) = MAXSPEED(N)
      CALL PRINTOUT(TOPLINE,M,WT,IX,IY,IZ,CG,THRUST,EPSILON,
     +			NU,LF,H,V)	
C		
C     *** (09) STEADY SIDESLIP ***
      TOPLINE = 'STEADY SIDESLIP'
      M = 1
      WT(1) = (MAXWT+MINWT)/2.0
      IX(1) = 9E15
      IY(1) = 9E15
      IZ(1) = 9E15
      CG(1) = ACG
      THRUST(1) = 9E15
      EPSILON(1) = 0.0
      NU(1) = 0.0
      LF(1) = 1.0
      H(1) = ALT(1)
      V(1) = MINSPEED(1)
      CALL PRINTOUT(TOPLINE,M,WT,IX,IY,IZ,CG,THRUST,EPSILON,
     +			NU,LF,H,V)	
C
C     *** (10) ASYMMETRIC THRUST ***
      TOPLINE = 'ENGINE-OUT TRIM:'
      M = 2
      DO 6000, I = 1, 2
         WT(I) = MINWT
         IX(I) = 9E15
         IY(I) = 9E15 
         IZ(I) = 9E15 
         CG(I) = ACG
         EPSILON(I) = 0.0
         NU(I) = 0.0
         LF(I) = 1.0
         H(I) = ALT(1)
         V(I)	= MINSPEED(1)	
 6000 CONTINUE
         THRUST(1) = MAXT/2.0
         THRUST(2) = MAXTTV/2.0
      CALL PRINTOUT(TOPLINE,M,WT,IX,IY,IZ,CG,THRUST,EPSILON,
     +			NU,LF,H,V)
C
C
C     *** (13) ROLL-YAW COUPLING (ROLLING PULLOUT) ***
      TOPLINE = 'COORDINATED ROLL & ROLLING PULLOUT:'
      M = 6
C     ** LOW ALTITUDE **
      DO 6300, I = 1, 3
         WT(I) = 9E15
         IX(I) = MINIX
         IY(I) = MAXIY
         IZ(I) = 9E15
         CG(I) = ACG
	  THRUST(I) = 9E15
         EPSILON(I) = 0.0
	  NU(I) = 1.0
         H(I)	= ALT(1)
 6300	CONTINUE
         V(1) = MINSPEED(1)
         V(2) = (MAXSPEED(1)+MINSPEED(1))/2.0
         V(3) = MAXSPEED(1)
         LF(1) = 1.5
         LF(2) = MAXLF/2.0+1.0
         LF(3) = MAXLF
C	** HIGH ALT **
	DO 6310, I = 4, 6
         WT(I) = 9E15
         IX(I) = MINIX
         IY(I) = MAXIY
         IZ(I) = 9E15
         CG(I) = ACG
	  THRUST(I) = 9E15
         EPSILON(I) = 0.0
	  NU(I) = 1.0
         H(I)	= ALT(N)
 6310 CONTINUE
         V(4) = MINSPEED(N)
         V(5) = (MAXSPEED(N)+MINSPEED(N))/2.0
         V(6) = MAXSPEED(N)
         LF(1) = 1.5
         LF(2) = MAXLF/2.0+1.0
         LF(3) = MAXLF
      CALL PRINTOUT(TOPLINE,M,WT,IX,IY,IZ,CG,THRUST,EPSILON,
     +			NU,LF,H,V)	
C
C
      STOP
C
      END
C
      SUBROUTINE PRINTOUT(TOPLINE,M,WT,IX,IY,IZ,CG,THRUST,EPSILON,
     +				NU,LF,H,V)
      REAL WT(15),IX(15),IY(15),IZ(15),CG(15),THRUST(15),
     +		EPSILON(15),NU(15),LF(15),H(15),V(15)
      INTEGER M
      CHARACTER*50, TOPLINE
C
C
      WRITE(15,40) TOPLINE
 40   FORMAT (A50)
      WRITE(15,50)
 50   FORMAT ('W (lbs)',T11,'I-x',T21,'I-y',T31,'I-z',T41,'Xcg (ft)',
     +        T51, 'T (lbs)', T59, 'Load Factor',T71,'ALT (ft)',
     +        T81,'Spd (kts)',T91,'V T DEF',T101,'H T Def(deg)') 
      DO 100, I = 1, M
	  WRITE(15,110) WT(I),IX(I),IY(I),IZ(I),
     +	        CG(I),THRUST(I),LF(I),H(I),V(I),EPSILON(I),NU(I)
 110  FORMAT(11(E9.3,1X))
 100  CONTINUE
      WRITE(15,200)
 200  FORMAT (' ')
	RETURN
	END