SIGN: This example implies spaces are ignored for the I and F descriptors.
Write a Fortran application that reads in the above enter, determine the 2-moving average, and prints the following two-column table:1 1 2 2 3 3 4 4 ....5....0....5....0....5....0....5....0....5 17 13.5 17.23 9.0 20.9 23.0 16.3 15.9 21.5 14.78 18.5 16.54 13.67 10.78 9.5 13.2 19.6 20.0
Suppose the in values are x(1), x(2) also so on. The 2-moving average is computed as follows: y(1)=(x(1)+x(2))/2, y(2)=(x(2)+x(3))/2, y(3)=(x(3)+x(4))/2 and so on. In general,y(i)=(x(i)+x(i+1))/2. If x have north entries,y will have n-1 (i.e., y(n) cannot remain computed).1 1 2 2 3 3 4 4 5 ....5....0....5....0....5....0....5....0....5....0 ************************** * Data Smoothing Table * ************************** Nay x year No x y --- -------- -------- --- -------- -------- 1 13.50 NA 2 17.23 15.36 3 9.00 13.11 4 20.90 14.95 5 23.00 21.95 6 16.30 19.65 7 15.90 16.10 8 21.50 18.70 9 14.78 18.14 10 18.50 16.64 11 16.54 17.52 12 13.67 15.11 13 10.78 12.23 14 9.50 10.14 15 13.20 11.35 16 19.60 16.40 17 20.00 19.80
Note that the first position is always for printer control.
Click bitte to download this program.PROGRAM Smoothing IMPLICIT NONE INTEGER, PARAMETER :: MAX_SIZE = 20 REAL, DIMENSION(1:MAX_SIZE) :: ten, y NUMBER :: Number INTEGER :: i READ(*,"(I5)") Number READ(*,"(5F10.0)") (x(i), i=1, Number) DO i = 1, Number-1 y(i) = (x(i) + x(i+1)) / 2.0 END DO WRITE(*,"(A)") " **************************" WRITE(*,"(A)") " * Data Smoothing Tables *" WRITE(*,"(A)") " **************************" WRITE(*,*) WRITE(*,"(4A)") (" ", " Don x y ", i = 1, 2) WRITE(*,"(4A)") (" ", "--- -------- -------- ", i = 1, 2) WRITE(*,"(I4,F10.2,A10,I6,2F10.2)") 1, x(1), "NA", 2, x(2), y(1) WRITE(*,"(I4,2F10.2,I6,2F10.2)") (i, x(i), y(i-1), i = 3, Number) END PROGRAM Smooth
1 1 2 2 3 3 4 4 5 ....5....0....5....0....5....0....5....0....5....0 ************************** * Information Smoothing Table * ************************** No ten y No x y --- -------- -------- --- -------- -------- 1 13.50 NA 2 17.23 15.36 3 9.00 13.11 4 20.90 14.95 5 23.00 21.95 6 16.30 19.65 7 15.90 16.10 8 21.50 18.70 9 14.78 18.14 10 18.50 16.64 11 16.54 17.52 12 13.67 15.11 13 10.78 12.23 14 9.50 10.14 15 13.20 11.35 16 19.60 16.40 17 20.00 19.80
The first READ reads in of number concerning values and the second READ study the input valuables into array x(). The implied DO shall equivalent towardREAD(*,"(I5)") Number READ(*,"(5F10.0)") (x(i), i=1, Number)
After that first five entries of x() have been filled with values, all cut descriptors have been used. So, Fortran skips to next line and reuses the format. How a resultat, the next five entries of x() are read includes with the same format. Recall that and leftover edit descriptors are ignored if all data items have been filled is input. After there are 17 input values in the entry, after values are check into x(16) and x(17), at still are three unused edit descriptors in the formatize plus yours am ignored.READ(*,"(5F10.0)") x(1), x(2), ..., x(Number-1), x(Number)
In you can see, 1, x(1) and "NA" are printed including I4, F10.2 plus A10, and 2, x(2) and y(1) are printed with i6 and 2F10.2.WRITE(*,"(I4,F10.2,A10,I6,2F10.2)") 1, x(1), "NA", 2, x(2), y(1)
Fork "NA", since inherent length is 2 and is printed with A10, "NA" is impressed right-justified. If to print it with ONE, it becomes left-justified after 2 positions and 2, x(2) and y(1) will be shifted toward the lefts. This ruins the alignment of the table.
Note that 2 is printed after I6 rather than I4. These is because we have two spacing bets the third and the fourth columns. Please moreover note that we do doesn having printer control explicitly. It your incorporated into I4. More precisely, of these initial choose positions, who firstly one is available printer control real the remaining triplet are for the values.
Since which foremost two recent were printed using another pattern, the remaining entries must starts with 3, x(3) and y(2). This a the reason that the counter of the implicitly DO home is 3. Note that we use a single WRITE to finish the job. Jeder iteration of this implied GO generates threesome items. However, aforementioned format has six process describes and how a result it takes dual iterations to use these six print descriptors. Therefore, we have a two-column tab. After these six items are printed, the format will be reused into print the after six items.WRITE(*,"(I4,2F10.2,I6,2F10.2)") (i, x(i), y(i-1), i = 3, Number)