#include <math.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <conio.h>



void material(void);



double cmat,cref,diam,scale;



double E,W;



int iflag,imat;





const double  PI=   atan2(0.,-1.);

const double TPI=2.*atan2(0.,-1.);



void main()
{



	printf("\n\n\n\n ring_mode.cpp, ver 1.1,  May 1, 2008 ");

    printf("\n\n by Tom Irvine ");

	printf("\n Email: tomirvine@aol.com \n");



	printf("\n This program calculates the ring frequency for a cylindrical structure. \n");



    iflag=0;

    double t;

	while(1)
	{

		material();



		printf("\n\n Enter diameter (in) \n");
		scanf("%lf",&diam);


		printf("\n\n Enter thickness (in) \n");
		scanf("%lf",&t);

		printf("\n\n Ring Frequency = %12.4g Hz \n",cmat/(PI*diam));


		int n;
		
		double n2;
		double d2=pow(diam,2);
		double t2=pow(t,2);
		
		double fn;

		double rho=W;

		printf("\n\n In-plane bending modes for a thin-walled ring: \n");

		for(n=1;n<=20;n++)
		{
			n2=pow(n,2);
			
			fn=n*(n2-1.)/( (PI*d2)*sqrt(n2+1) );

			fn*=sqrt( (E*t2/rho)/3.);

			printf(" %d  %8.2lf Hz \n",n,fn);
		}


		printf("\n\n Another case? ");

		printf("\n  1=yes   2=no \n");

		scanf("%d",&iflag);



        if( iflag != 1 ){break;}

	}





	printf("\n\n\n Press any key to exit.\n\n");

	getch();

}



void material(void)
{

   

	printf("\n Enter material: \n 1=aluminum  2=steel  3=titanium  4=graphite/epoxy  5=other \n");

    scanf("%d",&imat);



  



	if(imat==1)  // Aluminum
	{



		W=0.098;

		E=1.0E+07;

	}

	if(imat==2)  // Steel

	{

	



		W=0.283;

		E=2.9E+07;



	}

	if(imat==3)  // Titanium

	{

	



		W=0.163;

		E=1.6E+07;



	}

	if(imat==4)  // Graphite Epoxy

	{

	



		W=0.058;

		E=1.0E+07;



	}



    if(imat==5)  // Other

	{





		printf("\n Enter cylindrical skin weight density (lbm/in^3) \n");

   		char sW[16];

		scanf("%s",&sW);

		sscanf(sW,"%lf",&W);



		printf("\n Enter elastic modulus (lbf/in^2) \n");

   		char sE[16];

		scanf("%s",&sE);

		sscanf(sE,"%lf",&E);





	}

	

	W/=386.;



	cmat = sqrt( (E/W));



	printf("\n\n Speed of Sound in Material = %10.3g in/sec ",cmat);

	  printf("\n                            = %10.3g ft/sec \n",cmat/12.);



}
