C ********************************
C *  AIRCRAFT MOMENT OF INERTIA  *
C *         CALCULATIONS         * 
C ********************************

C The purpose of this code is to 
C calculate the moments of inertia
C of a radio controlled aircraft.


C Use the data file 'CMIDATA'  to enter in the
C information 

C Enter first the x , y, z coordinates.  Then mass.  Then the 
C moments of inertia about the three axis for each component.

C x,y,z are in inches.   The mass is in slugs.  The moments of 
C inertia are in slug-ft2.

C the final line in the data file needs to have an 'EnD'  typed
C to terminate the code.



C ********************************
C *    DECLARE   VARIABLES       *   
C ********************************

       REAL  x(50),y(50),z(50),m(50),ix(50),iy(50),iz(50) 
       REAL  Ixt,Iyt,Izt   
       REAl  Xt,Yt,Zt,Mt 
       REAL  Xcm, Ycm, Zcm 
       character * 15 desc(50)  
       Integer w,iw
C ************************
C *    READ IN DATA      *
C ************************

       OPEN(1, file='CMIDATA')


       w=1

        

 10        read (1,*) desc(w), x(w),y(w),z(w),m(w),ix(w),iy(w),iz(w) 

        

        if (desc(w).EQ.'EnD')  goto 15 

        w=w+1

        goto 10


 15    continue
 
        close(1)


       w=w-1

C **********************
C * BEGIN CALCULATIONS *
C **********************


C CENTER OF MASS CALCULATIONS

C  ZERO THE CM VALUES
 
        Xcm = 0.0
        Ycm = 0.0
        Zcm = 0.0
        Mt  = 0.0 


      do 40 iw = 1,w


         Xt = Xt + m(iw)*x(iw)     


         Yt = Yt + m(iw)*y(iw)


         Zt = Zt + m(iw)*z(iw)

         Mt =  Mt + m(iw)


 40     continue


          Xcm=Xt/Mt 

          Ycm=Yt/Mt  

          Zcm=Zt/Mt 





C   ZERO THE I's

         Ixt = 0.0
         Iyt = 0.0
         Izt = 0.0
     

C  SUM MOMENTS OF INERTIA + MOVE THEM TO CM WITH PARALLEL AXIS THM    

        do 50 iw =1,w


          Ixt = Ixt + ix(iw)+m(iw)*((y(iw)-Ycm)**2+(z(iw)-Zcm)**2)/144 

          Iyt = Iyt + iy(iw)+m(iw)*((x(iw)-Xcm)**2+(z(iw)-Zcm)**2)/144 
        
          Izt = Izt + iz(iw)+m(iw)*((y(iw)-Ycm)**2+(x(iw)-Xcm)**2)/144 
        

 50      continue




C   P R E T T Y    O U T P U T
C**************************************


        print *, '   '
        print *, '   '
        print *, '   '
        print *, '   '
 




  
        print *, '                     ********************************'
        print *, '                     *  AIRCRAFT MOMENT OF INERTIA  *'      
        print *, '                     *         CALCULATIONS         *'
        print *, '                     ********************************'



        print *,  '   ' 
        print *,  '   '  



        print *, '               D A T A   F R O M   I N P U T  F I L E'   
        print *, '               **************************************'

        print *,  '   ' 
        print *,  '   '  

        print 27, 'DESCRIPTION    ', 'X pos', 'Y pos', 'Z pos',
     Z      'Mass ', 'Ix  ', 'Iy  ', 'Iz  '  


        print 27, '               ', 'in  ','in  ','in  ',
     Z      'Slugs','sl-ft2','sl-ft2','sl-ft2' 

        print 27, '***************','*******','*******','*******', 
     Z       '*******','*******','*******','*******'
 
 27    format(1x,a15,1x,a7,1x,a7,1x,a7,1x,a7,1x,a7,1x,a7,1x,a7) 
        


         do 20 iw=1,w

       print 25, desc(iw),x(iw),y(iw),z(iw),m(iw),ix(iw),iy(iw),iz(iw)

 25    format(1x,a15,1x,f7.3,1x,f7.3,1x,f7.3,1x,f7.3,1x,f7.3,1x,f7.3,1x 
     Z       f7.3)
    
    
 20      continue

        print *, 'DATA IS MEASURED FROM THE FIREWALL'          

        print *,  '   '
        print *,  '   ' 


      
        print *, '                            R E S U L T S'
        print *, '               **************************************'

        print *,  '   '
        print *,  '   ' 

        print *, 'CENTER OF MASS LOCATION (Xcm,Ycm,Zcm) ==>',Xcm,Ycm,Zcm 
        print *, 'The units are inches'        
        print *,  '   '
        print *,  '   ' 


        print *, 'Moments Of Inertia (Ix,Iy,Iz) ==>',Ixt,Iyt,Izt
        print *, 'The units are slug-ft-ft'


        print *,  '   '
        print *,  '   ' 
        
        print *, 'TOTAL MASS OF AIRCRAFT: ',Mt,' Slugs'
        print *, '                        ',32.2*Mt,' lbs'

        print *,  '   '
        print *,  '   ' 


      end 
