Rocket motors are tested by restraining them on the ground, firing them with a k
ID: 3804816 • Letter: R
Question
Rocket motors are tested by restraining them on the ground, firing them with a known amount of propellant, and measuring the thrust over time. A typical curve is shown below.
The total impulse is the integral of the thrust over the operating duration of the motor. This can be approximated by
It = t(F1+F2+F3+…)
where: It = total impulse in lb-sec
t = time increment in seconds
F1, F2, F3, … = thrust at timesteps 1, 2, 3, … in lb
The specific impulse is the total impulse divided by the weight of the propellant burned in the test.
Isp = It/m
where: Isp = specific impulse in seconds
m = mass of propellant burned in pounds
The average thrust is found by dividing the total impulse by the thrust time.
Favg = It/t
where: Favg = average thrust in lb
t = total test time in seconds
An input data file called testdata contains time and thrust data for a rocket test where the mass of propellant burned was 1.74 lb. The first record line of the input file is the control number, which defines the number of data points to be read into the program. Each succeeding record line has two columns. The first column is the elapsed test time in seconds, and the second column is the thrust in pounds. The input file is comma delimited.
ASSIGNMENT:
Write a C program that will read the required values from the input file into two one-dimensional arrays. Using the thrust, time, and increment between timesteps (hint: you can get this from the time array – think about using one specific data value), compute the total thrust, total impulse, specific impulse, and average thrust. Print the total impulse, specific impulse, and average thrust to the computer screen and to an output file called results.
OUTPUT FORMAT:
********************************************
ROCKET MOTOR TEST RESULTS
Total Impulse: XXX.X lb-sec
Specific Impulse: XXX.X sec
Average Thrust: XXX.X lb
********************************************
FILE PATHS:
Before submitting your C source program, make sure that you set your input and output file paths to
U:ENGR 200.
the file :
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MASS_OF_PROPELANT 1.74
int main(){
FILE* stream = fopen("C:/Users/aditya/Desktop/input.txt", "r");
FILE* ostream = fopen("C:/Users/aditya/Desktop/result.txt", "w");
char line[1024];
int ctr = 0;
int no_Of_recs_in_file = 0;
double *times;
double *thrust;
int no_of_flds = 0;
double total_thrust = 0;
double total_impulse = 0;
double specific_impulse = 0;
double avg_thrust = 0;
double time_increment = 0;
double total_time = 0;
while(fgets(line,1024,stream)){
//printf("%s ",line);
no_of_flds = 0;
if (ctr == 0){
no_Of_recs_in_file = atoi(line);
times = (double*) malloc(no_Of_recs_in_file * sizeof(double));
thrust =(double*) malloc(no_Of_recs_in_file * sizeof(double));
}
else{
//printf("%s ",line);
char* parsedRec = strtok(line,",");
while(parsedRec != NULL){
if (no_of_flds ==0){
times[ctr - 1] = atof(parsedRec);
}
else if (no_of_flds ==1){
thrust[ctr - 1] = atof(parsedRec);
}
//printf("%s ",parsedRec);
parsedRec = strtok(NULL,",");
no_of_flds ++;
}
}
ctr++;
}
int i;
for (i =0;i<no_Of_recs_in_file;i++){
//printf("times - %f ",times[i]);
total_time = total_time +times[i];
}
time_increment = times[1] - times[0];
for (i =0;i<no_Of_recs_in_file;i++){
//printf("thrust - %f ",thrust[i]);
total_thrust = total_thrust +thrust[i];
}
total_impulse = total_thrust * time_increment ;
specific_impulse = total_impulse/MASS_OF_PROPELANT;
avg_thrust = total_impulse/total_time;
fprintf(ostream,"********************************* ");
fprintf(ostream,"ROCKET MOTOR TEST RESULTS ");
fprintf(ostream,"Total Impulse: %f lb-sec ",total_impulse);
fprintf(ostream,"Specific Impulse: %f sec ",specific_impulse);
fprintf(ostream,"Average thrust: %f lb ",avg_thrust);
fprintf(ostream,"********************************* ");
free(times);
free(thrust);
//printf("The total no of records read from the first line of the file : %d ",no_Of_recs_in_file);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.