1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
PROGRAM DESCRIPTION:
This program computes horizontal displacement and velocity of the bumber at
each time value after impact, replace the zero values that were initially read
into arry. A report is printed to the computer screen and an output file.
DESCRIPTION OF VARIABLES
NAME | TYPE | DESCRIPTION
|
train | double | two-dimensional array of train values
dis | double | horizontal displacement in meter
velocity | double | velocity in meter per second
nimpact | int | number of impacts
nvalue | int | number of values
i | int | outer for loop control variable (impact)
j | int | inner for loop control variable (value)
*******************************************************************************/
/* Preprocessor directives */
#include <stdio.h>
#include <math.h>
#define inputfile "I:\\train.txt"
#define outputfile "I:\\train_report.txt"
/* Main function */
int main(void)
{
/* Declare variables */
double train[51][3],velocity, dis;
int i,j,nimpact, nvalue;
FILE *obs, *report;
/* Open input file */
obs = fopen(inputfile,"r");
report = fopen(outputfile,"w");
/* Verify input file and read input data */
if(obs == NULL)
{
printf("\n\n\n\n ERROR OPENING INPUT FILE.");
printf("\n\n PROGRAM TERMINATED.\n\n\n");
return 0;
}
else
{
/* Read number of impacts and values */
fscanf(obs,"%i %i",&nimpact,&nvalue);
/* Read input data into train array */
for(i=0; i<=nimpact-1; i++)
{
for(j=0; j<=nvalue-1; j++)
fscanf(obs,"%lf",&train[i][j]);
}
}
/* Compute displacement and velocity */
for(j=0; j<=nvalue-1; j++)
{
for(i=0; i<=nimpact-1; i++)
dis= 4.219*(exp(-1.58*train[i][1])-exp(-6.32*train[i][1]));
velocity= (26.67*exp(-6.32*train[i][1]))-(6.67*exp(-1.58*train[i][1]));
}
for(i=0; i<=nimpact-1; i++)
train[i][2]=dis;
train[i][3]=velocity;
/* Print headings */
printf("************ START REPORT ***********");
printf("\n TRAIN CAR STOPPING ANALYSIS"
"\n\n\n Time Displacement Velocity"
"\n\n (s) (m) (m/s)");
/* Print array */
for(i=0; i<=nimpact-1; i++)
{
for(j=0; j<=nvalue-1; j++)
{
printf("\n%6.3f %6.3f %6.3f",train[i][j], train[i][2], train[i][3]);
}
}
/* Close input file */
fclose(obs);
fclose(report);
/* Exit program */
return 0;
} |