Question
Hello Programming in Fortran (force 2) I have an input file myfile.txt where there are 53 rows and 8 column input file --------------------------------------------------------------------------------- year data1
Hello
Programming in Fortran (force 2)
I have an input file "myfile.txt" where there are 53 rows and 8 column
input file
---------------------------------------------------------------------------------
year data1 data2 data3 S1 S2 S3 S4
2000 020201 2.0 23.0 3.5 6.3 5.2 4.9
2001 050362 3.2 66.0 0.0 2.9 5.0 6.0
....
2023 020503 1.2 72 5.0 0.0 5.3 0.0
---------------------------------------------------------------------------------
now based on S1 S2 S3 S4 I have to calculate for every year the Sw where
-------------------------------------------------------------------------
Sw=200.3*S1+63.0-0.002, if 3.5=
----------------------------------------------------------------------
Sw=193.2*S2+230-0.02 if 4=
---------------------------------------------------------------------------
Sw=190.2*S3+200-0.02 if 3.2=
Sw=100.1*S3+100-0.12 if 4=
----------------------------------------------------------------------------
Sw=200*S4+230-0.02 if 4=
-----------------------------------------------------------------------------
Then I have to calculate a mean Sw(total) for every year where Sw(total)=sum(Sw(i)/er(i))/sum(1/er(i))
and then calculate the mean er (er(total))wher er(total)=n*sum(1/er(i) where n=the total data for every year !but for only the data they have been used. For example if in a row S3=0.0 or less than 4 (which is in the condition) then n shouldnt count it.
The output file has to have the following format (columns)
year data1 data2 data3 S1 S2 S3 S4 Sw1 Sw2 Sw3 Sw4 Sw(total) n er(total)
....
----------------------------------------------------------------------------------------------------------------------------------------
then I put the if conditions (4 different if condition for every S) but I have problem calculate the Sw(total) the n and the er(total)
answer
integer, parameter :: m=53, j=14
real :: A(m,j)
real :: er1, er2, er3, er4, Sw_total, er_total, n
!initialize array to zero
do i = 1, m
do k = 1, j
A(i,k) = 0.0
end do
end do
!open input and output files
open(7, file='Myfile.txt', status='old')
open(8, file='output.out', status='unknown')
read(7,*)
!read data from input file
do l = 1, m
read(7,*) A(l,1), A(l,2), A(l,3), A(l,4), A(l,5), A(l,6), A(l,7), A(l,8)
end do
!calculate Sw values and errors for each data point
do i = 1, m
if (3.5 <= A(i,5) .and. A(i,5) <= 7) then
A(i,9) = 200.3*A(i,5) + 63.0 - 0.002
er1 = 0.01
else
A(i,9) = 0.0
er1 = 0.0
end if
if (4 <= A(i,6) .and. A(i,6) <= 7.2) then
A(i,10) = 193.2*A(i,6) + 230 - 0.02
er2 = 0.005
else
A(i,10) = 0.0
er2 = 0.0
end if
if (3.2 <= A(i,7) .and. A(i,7) <= 4) then
A(i,11) = 190.2*A(i,7) + 200 - 0.02
er3 = 0.01
else if (4 <= A(i,7) .and. A(i,7) <= 6.8) then
A(i,11) = 100.1*A(i,7) + 100 - 0.12
er3 = 0.1
else
A(i,11) = 0.0
er3 = 0.0
end if
if (4 <= A(i,8) .and. A(i,8) <= 7.2) then
A(i,12) = 200*A(i,8) + 230 - 0.02
er4 = 0.005
else
A(i,12) = 0.0
er4 = 0.0
end if
!calculate mean Sw(total) and er(total) for each year
Sw_total =( A(i,9)/er1 + A(i,10)/er2 + A(i,11)/er3 + A(i,12)/er4)/(er1+er2+er3+er4)
!n = number of data points used for each year (can be calculated using another loop with if conditions to check if S values are within the specified range)
! the n is found by set an count after every condition. But I dont know if the count should be inside every if condition or outside.
A(i,13) = Sw_total/er_total
A(i,14) = n !????????????????
A(i,15) = er_total/n
end do
some help! Especialy with the count and n
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started