#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>


char filename[5][FILENAME_MAX];
FILE *pFile[5];

long i;
double rho,hh,damp,amp;
double Q;

double ab,freq,fn;


void main()
{

	printf("\n\n  force_trans_modal  ver 1.0  \n");
	printf("\n  by Tom Irvine  \n  Email: tomirvine@aol.com \n\n");


	printf("\n  This program generates a power transmissibility function.");
	printf("\n  for a single-degree-of-freedom subjected to a force input. \n");

    printf("\n  The transmissibility dimension is: ( accel^2 / force^2 ) \n");

	printf("\n  The program can be used to determine modal damping by a "); 
	printf("\n  trial-and-error-curve fit with measured accelerometer data.");
    

	printf("\n\n\n  Enter output filename. \n");

	scanf("%s",filename[0]);

	pFile[0]=fopen(filename[0],"w");

	printf("\n");
 

	printf("\n Enter natural frequency (Hz) \n");
	scanf("%lf",&fn);

	printf("\n Enter Q \n");
    scanf("%lf",&Q);


 	printf("\n Enter peak amplitude \n");
    scanf("%lf",&ab);


    damp=1./(2*Q);

    rho=1.;
	amp= ab*(pow((2.*damp*rho),2.));



    freq=fn/2.;

	while(1)
	{

		rho = freq/fn;

		hh = pow( (1.-pow(rho,2.)),2.)+pow( (2.*damp*rho),2.);
        hh=1./hh;
		
		fprintf(pFile[0],"%12.4g %12.4g \n",freq,amp*hh);

	
		if( freq > 2.*fn ){break;}
		
		freq+=0.2;
	
	}

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

   exit(1);
}
