subroutine Cost

C     Profile:
C---------------------
C     This routine calculates the direct operating cost of a transport
C     airplane in cents per seat statute mile in a single class arrangement.
C     Part of the PASS group of programs   Ilan Kroo  1986
C
C     Documentation of the method:
C
C     The calculations follow the formulas in the ATA Standard Method
C     of Estimating Comparative Operating Costs of Turbine Powered
C     Transport Aircraft, Dec. 1967 with the following assumptions
C     and changes.
C
C     Note that input range is nautical miles
C     It is the overall range including climb and descent
C
C     Time to climb penalty is an input value from AA241 method.
C
C     Aircraft cost as follows from DC-10-10 data in 1983:
C
C     Component         Cost/lb.
C       Wing            121.5
C       Vertical        114.3
C       Horizontal      124.2
C       Fuselage        121.5
C       Gear            63.0
C       Surf. Cntrls.   244.8
C       Air Cond.       325.8
C       Nacelle/Pylon   332.1
C       Hydr./ Pneu.    244.8
C       APU             307.8
C       Instruments     820.8
C       Electrical      174.6
C       Electronics     2898.0
C       Furnishings     153.9
C
C     These values lead to an average cost of 100$/lb. for the
C     DC-10-10 in 1975 $.
C
C     Engine cost is based on Andersons data in the SAE report
C

C     Declarations:
C---------------------
      implicit none

      integer iEngineType, i

      real years, rfuel, roil, rins, rlabor, range, Vktscr
      real Wmaxtow, Wfuel, neng, npax, CgalFuel, Wmt
      real Weng, WWing, WVert, WHoriz, Wfuse, Wgear, WsurfC, Waircond
      real Wnacpy, Whydpnu, Wapu, Winst, Welectl, Welectn, Wfurnish
      real SLSTH, SLSP, Wrud

      real airway, time, blockt, blockV,Cpilot, Cfuel, WmtnoE,Tclimb
      real hours, flightt, ACcost, englbr
      real  Encost, Enpart, Clabor, Cparts, Utiliz, Cins, Cdepr, DOC
      real Inflate, Nseats

      real EngType, Ncrew, Nattend, Ccrew, IOC, TOC, TicketPrice

      real Residual,TripsYr,InitLoan,FinPer,IntRate,PayYear,PerIntR
      real TotNPay,SizPay,TotPay,PresVal,Cfin,InflRate

      logical Abort

C     Required inputs:
C---------------------
      call GET(range     ,'CruiseRange'     )
      call GET(Vktscr    ,'VktsAvg'         )
      call GET(Tclimb    ,'AddClimbTime'    )
      call GET(EngType   ,'EngineType'      )
      call GET(Inflate   ,'Inflation'       )
      call GET(InflRate  ,'InflationRate'   )
      call GET(WmaxTOW   ,'DesWeight.MaxTO' )
      call GET(Ncrew     ,'#Crew'           )
      call GET(CgalFuel  ,'Fuel-$perGal'    )
      call GET(Wfuel     ,'WFuel'           )
      call GET(roil      ,'Oil-$perLb'      )
      call GET(Neng      ,'#Engines'        )
      call GET(Wmt       ,'DesWeight.empty' )
      call GET(Weng      ,'WDryEngine'      )
      call GET(rlabor    ,'LaborRate'       )
      call GET(Wwing     ,'Wwing'           )
      call GET(WVert     ,'WVertical'       )
      call GET(Wrud      ,'WRudder'         )
      call GET(WHoriz    ,'WHorizontal'     )
      call GET(Wfuse     ,'WFuselage'       )
      call GET(Wgear     ,'WGear'           )
      call GET(Wsurfc    ,'WSurfaceControls')
      call GET(Waircond  ,'WAircondition'   )
      call GET(Wnacpy    ,'WNacelles&Pylons')
      call GET(Whydpnu   ,'WHydro&Pneumatic')
      call GET(Wapu      ,'WAPU'            )
      call GET(Winst     ,'WInstruments'    )
      call GET(Welectl   ,'WElectrical'     )
      call GET(Welectn   ,'WElectronics'    )
      call GET(Wfurnish  ,'WFurnishings'    )
      call GET(rIns      ,'InsureRate'      )
      call GET(years     ,'YearsToZero'     )
      call GET(Nseats    ,'#CoachSeats'     )
      call GET(TripsYr   ,'TripsPerYear'    )
      call GET(Residual  ,'Residual'        )
      call GET(IntRate   ,'AnnualInterestRate')
      call GET(PayYear   ,'PaymentsPerYear' )


      if(Abort()) return

      iEngineType = int(EngType+.1)
      if (iEngineType.eq.4) then
         call GET(SLSTH   ,'SLSPower'     )
         SLSTH = SLSTH*550 / (200*1.69)
      else
         call GET(SLSTH   ,'SLSThrust'    )
      end if
      if(Abort()) return

C     Calculations:
C---------------------
C
C       Block time, speed, distance
C       15 min ground man., climb penalty, 6 min air man.
C       -------------------------------------------------
        airway=.02*range*1.152
        if(range.lt.1216.)airway=7.+.015*range*1.152
        time=(range*1.152+airway+20.)/(Vktscr*1.152)
        blockT=time+.25+.1 + Tclimb
        blockV=range*1.152/blockT
C
C       Pilot cost (domestic)
C       -------------------------------
        If(EngType.eq.4)then
        Cpilot=Inflate*(.05*WmaxTOW/1000.+63.+ 35.*(Ncrew-2.))/blockV
        else
        Cpilot=Inflate*(.05*WmaxTOW/1000.+100.+ 35.*(Ncrew-2.))/blockV
        end if
        CCrew = Cpilot
        rfuel = CgalFuel*.156
        Cfuel=(rfuel*Wfuel+.135*roil*neng*time)/(range*1.152)*1.02
C
C       Maintenance:
C       ------------
        Wmtnoe=Wmt-Weng*neng
        hours=.05*Wmtnoe/1000.+6.-630./(120.+Wmtnoe/1000.)
        flightt=blockT-.25

        Clabor=(.59*hours*flightt+hours)/(range*1.152)*rlabor

cpg   The following factors on component weights are for 1967
cpg   values. The inflation rate up to 1983 would lead to 
cpg   correspondence with values quoted for DC-10-10 at start of subroutine.

        ACcost=(.675*Wwing+.635*(WVert+Wrud)+.690*WHoriz+.675*Wfuse
     >   +.35*Wgear+1.36*Wsurfc+1.81*Waircond+1.845*Wnacpy*neng
     >   +1.36*Whydpnu+1.71*Wapu+4.56*Winst+.97*Welectl+16.1*Welectn
     >   +.855*Wfurnish) * Inflate * 62.

        Cparts=(3.08*ACcost*flightt+6.24*ACcost)/(range*1.152*1.E6)

C       Engine Costs
C       ------------
        englbr=((.6+.027*slsth/1000.)*flightt+(.3+.03*slsth/1000.))
     >   *rlabor/(range*1.152)*neng

        EnCost =  10**(5.3 + (alog10(slsth)-3)/2*1.42)/2.72*Inflate

        Enpart=(2.5*EnCost*flightt+2.0*EnCost)
     >          /(1.E5*range*1.152)*neng

C       We have a sale on old low bypass engines:  20% off.
C       Propfans are 10% more, better data would be nice here.
        if (ienginetype .eq. 2) then
            englbr = englbr * 0.80
            EnCost = EnCost * 0.80
            Enpart = Enpart * 0.80
        endif
        if (ienginetype .eq. 3) then
            englbr = englbr * 1.1
            EnCost = EnCost * 1.1
            Enpart = Enpart * 1.1
        endif

c       Add 1.8 factor for maintenance burden
        Clabor=(Clabor+englbr) * 2.8
        Cparts=Cparts+enpart
C
C       Depreciation and Insurance
C       ---------------------------
        if(BlockT.le. 10.) then
           Utiliz=(2254.+901.*blockT-128.5*blockT**2+6.3*blockT**3)
        else
           Utiliz=(2254.+901.* 10   -128.5*  10  **2+6.3*  10  **3)
        end if

cian    New value for utilization if # trips per year is explicitly specified
        if(TripsYr.ne.0) Utiliz = blockT*TripsYr

        Cins=rins*(ACcost+EnCost*neng)/(utiliz*blockV)
        Cdepr=(1.1*ACcost+1.4*EnCost*neng)/(blockV*utiliz*years) - 
     >        Residual*(ACcost+EnCost*neng)/years

cian    Financing
cian    ---------
	
cian    Initial loan ammount is assumed to equal total cost of aircraft 
cian    and engines; the financing period is assumed equal to the depreciation 
cian    period.

	InitLoan = ACcost+EnCost*neng
        FinPer = years

cian    Effective interest rate during each period preceding payment
	PerIntR = IntRate/PayYear
cian    Total # of payments over time of loan
	TotNPay  = PayYear*years
cian    Size of each payments
	SizPay = InitLoan*((exp(PerIntR)-1)/(1-exp(-PerIntR*TotNPay)))
cian    Size of total payments
	TotPay = SizPay*TotNPay
cian    Present value of total payments over life of loan
	if (InflRate.eq.0.0) InflRate = 0.001
cian	Converts the annual inflation rate to rate per
cian	payment period. This allows the use of the convenient present value form
	InflRate = InflRate/PayYear
	PresVal = SizPay*(1-exp(-TotNPay*InflRate))/(exp(InflRate)-1)
cian    Financing cost simply equals the difference between this present value
cian    and the loan amount; divided by the loan period and annualized
cian    utilization we get the cost in $ per mile. 
	Cfin = (PresVal - InitLoan) / (blockV*years*Utiliz)


C
C
C       Direct Operating Costs
C       ----------------------
        DOC=(Cdepr+Cins+Cparts+Clabor+Cfuel+Cpilot+Cfin)/Nseats*100.

C     Repack database:
C---------------------
      call PUT(blockT      ,'BlockTime'   )
      call PUT(blockV      ,'BlockSpeed'  )
      call PUT(CCrew       ,'CrewCost'    )
      call PUT(Cfuel       ,'FuelCost'    )
      call PUT(Clabor      ,'LaborCost'   )
      call PUT(Cparts      ,'PartsCost'   )
      call PUT(Cins        ,'Insurance'   )
      call PUT(Cdepr       ,'Depreciation')
      call PUT(ACcost      ,'AirframeCost')
      call PUT(EnCost      ,'EngineCost'  )
      call PUT(DOC         ,'DOC'         )

      call PUT(Utiliz      ,'Utilization' )
      call PUT(InitLoan    ,'InitialLoan' )
      call PUT(SizPay      ,'PaymentSize' )
      call PUT(PresVal     ,'PresentValue')
      call PUT(Cfin         'FinanceCost' )

      return
      end