Question

In: Physics

Write a Fortran program that is able to read in the data file. The file has...

Write a Fortran program that is able to read in the data file.

The file has lines with the structure: 19990122 88888 30.5

Where:

i) the first is an 8 digit code with the date: yyyymmdd (yyyy is the year, mm is the month, and dd is the day)

ii) the second is the five digit odometer reading of a car

iii) the third is the amount of fuel put into the car on that date to fill the tank up to full

The program must be able to determine the average miles per gallon consumed and the sigma of this distribution

(NOTE: I know that I can't attach the file itself, so there is no way for you to properly debug the code.That's fine. I just need help with the structure and setup)

Solutions

Expert Solution

Please look at the following step-wise solution. I have added program snippets in each steps.

THE PROGRAM IS WELL COMMENTED using ' ! '

THE HIGHLIGHTED LINES ARE THE PART OF THE CODE

1. Reading the data into three different array(one each for date, odometer reading and petrol refil amount)

Replace n by the number of lines in the data file

PROGRAM MILEAGE

INT date[n],odo[n],dist   !! ARRAY for date and odomoter reading. put the value of n i,e the number of lines in data file, and distance travelled

FLOAT petrol[n], avg_miles[n-1], mean_dist !! ARRAY for petrol input and avg_miles calculation and for average

FLOAT total,mean,square,sigma

OPEN(1, FILE="DATA_FILE.dat , STATUS="unknown")

!! The do loop to read the data file

do i=1,n

read(1,*) date[i],odo[i],petrol[i]

enddo

2. NEXT WE NEED TO FIND THE DISTRIBUITION OF AVERAGE MILES PER GALLON

Now, lets say, the car was entirely filled on the first day. If we subtract the odometer reading in second row from first row to find the distance travelled and the amount of petrol refilled in second row is the amount of petrol used to travel the distance we have found

do i=2,n

dist=odo[i]-odo[i-1]

avg_miles[i-1]=dist/petrol[i]

total = total+avg_miles[i-1]

enddo

3. NEXT WE HAVE TO FIND THE SIGMA OF THE AVERAGE MILES PER GALLON DISTRIBUITION.

!! MEAN OF average miles per gallon

mean = total/(n-1).   

!! SIGMA OF THE DISTRIBUITION

do i= 1,n-1

square=square+(avg_miles[i] - mean)**2   

enddo

sigma = sqrt(square/n-1)    !! Here while finding sigma we have to divide one entry less than the total number of entrries in avg_miles which is actually one less than the total number of rows in data file. eg- if data file has 10 entries than avg_miles array has 9 entries and we will divide square by 8 while finding sigma(sample standard deviation)

write(*,*) "The Sigma of the distribuition is"

write(*,*) sigma

END PROGRAM MILEAGE


Related Solutions

Write a C++ program to read a data file containing the velocity of cars crossing an...
Write a C++ program to read a data file containing the velocity of cars crossing an intersection. Then determine the average velocity and the standard deviation of this data set. Use the concept of vector array to store the data and perform the calculations. Include a function called “Standard” to perform the standard deviation calculations and then return the value to the main function for printing. Data to use. 10,15,20,25,30,35,40,45,50,55. Please use something basic.
(Write/read data) Write a Program in BlueJ to create a file name Excersise12_15.txt if it does...
(Write/read data) Write a Program in BlueJ to create a file name Excersise12_15.txt if it does not exist. Write 100 integers created randomly into the file using text I/O. Integers are separated by spaces in the file. Read data back from the file and display the data in increasing order. After writing the file to disk, the input file should be read into an array, sorted using the static Arrays.sort() method from the Java API and then displayed in the...
Write a java program that can create, read, and append a file. Assume that all data...
Write a java program that can create, read, and append a file. Assume that all data written to the file are string type. One driver class and a class that contains the methods. The program should have three methods as follows: CreateFile - only creating a file. Once it create a file successfully, it notifies to the user that it creates a file successfully. ReadingFile - It reads a contents of the file. This method only allow to read a...
Write a C program that will read different data types from the following file and store...
Write a C program that will read different data types from the following file and store it in the array of structures. Given file: (This file have more than 1000 lines of similar data): time latitude longitude depth mag magType nst gap dmin 2020-10-19T23:28:33.400Z 61.342 -147.3997 12.3 1.6 ml 12 84 0.00021 2020-10-19T23:26:49.460Z 38.838501 -122.82684 1.54 0.57 md 11 81 0.006757 2020-10-19T23:17:28.720Z 35.0501667 -117.6545 0.29 1.51 ml 17 77 0.1205 2020-10-19T22:47:44.770Z 38.187 -117.7385 10.8 1.5 ml 15 100.22 0.049 2020-10-19T22:42:26.224Z...
Please write a java program to write to a text file and to read from a...
Please write a java program to write to a text file and to read from a text file.
Write a program in python to read from a file the names and grades of a...
Write a program in python to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a getGrades() function that reads data from a file and stores it and returns it as a...
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Python program: Write a program that reads a text file named test_scores.txt to read the name...
Python program: Write a program that reads a text file named test_scores.txt to read the name of the student and his/her scores for 3 tests. The program should display class average for first test (average of scores of test 1) and average (average of 3 tests) for each student. Expected Output: ['John', '25', '26', '27'] ['Michael', '24', '28', '29'] ['Adelle', '23', '24', '20'] [['John', '25', '26', '27'], ['Michael', '24', '28', '29'], ['Adelle', '23', '24', '20']] Class average for test 1...
(C++) Write a program to read from a grade database (data.txt). The database (text file) has...
(C++) Write a program to read from a grade database (data.txt). The database (text file) has students names, and grades for 10 quizzes.Use the given function prototypes to write the functions. Have main call your functions. The arrays should be declared in main() and passed to the functions as parameters. This is an exercise in parallel arrays, int and char 2 dim arrays. Function prototypes: int readData(ifstream &iFile, int scores[][10], char names[][30]); This functions takes the file stream parameter inFile...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT