Community
cancel
Showing results for
Did you mean:
Highlighted
Beginner
35 Views

## LOOP

Please how do I calculate functn for ranges (1 to 218) until end of ndata? See the attached file.

Tags (1)
11 Replies
Highlighted
Black Belt
35 Views

This is a poorly posed question and cannot be answered without knowing about the contents of the two input data files and the relation between the two files.

Highlighted
Beginner
35 Views

I'm sorry for the poor presentation of that question.

First, the data in the two files have the same data range (i.e. 1 - 218). But the data in 'SIM' file increases in the same interval (1 - 218) as one varies some parameters in the model that generated it. So,the data in that 'SIM' file was increased 3 times (i.e. 3*218=654).

I want to calculate functn for ranges (1 to 218) until end of ndata instead of taking the sum for the entire ndata.

Highlighted
Black Belt
35 Views

Gloria E. wrote:

First, the data in the two files have the same data range (i.e. 1 - 218). But the data in 'SIM' file increases in the same interval (1 - 218) as one varies some parameters in the model that generated it. So,the data in that 'SIM' file was increased 3 times (i.e. 3*218=654).

Lines 219-436 are identical to lines 1-218. So are lines 437-654. What purpose does this duplication serve?

I want to calculate functn for ranges (1 to 218) until end of ndata instead of taking the sum for the entire ndata.

That sentence is incomprehensible. What is the definition of 'functn'? What do you mean by 'end of ndata'?

Please tell us, precisely and clearly, what the data files contain and what you wish to compute.

It is rarely useful to pore over lines of code and deduce definitions of terms and explanations of what the code is supposed to do.

Highlighted
Beginner
35 Views

I duplicated lines 1-218 to create a scenario to test the program. Actually, the data in 'SIM' file (1-218) will be replicated many times with different set of values.

Functn is a cumulative of ((obsq - q)**2) for the following intervals 1-218, 219-436, 437-654 etc.

'end of ndata' is the last value in 'SIM' file.

I'm trying to get cumulative of ((obsq - q)**2) at these intervals (1-218, 219-436, 437-654, 655-872 .....). The data in 'OBS' file remains same for those intervals.

Highlighted
Black Belt
35 Views

If the data sets are small enough to fit into memory, it is more efficient to read all the input data into memory, and reuse the data as often as needed. For example:

```PROGRAM MY_TEST
integer, parameter :: NOBS = 218
REAL::obsq(NOBS),q(NOBS),functn
INTEGER::ndata,set

OPEN(16,FILE='SIM.DAT',STATUS='OLD')
OPEN(9,FILE='CHINWE.DAT',STATUS='REPLACE')

ndata=NOBS
OPEN(8,FILE='OBS.DAT',STATUS='OLD')
close(8)
set=0
DO
functn = sum((obsq-q)**2)
set = set+1
write(9,*) set,functn
write(*,*) set,functn
END DO
100 continue
close (9)
close (16)
END PROGRAM

```

Highlighted
Beginner
35 Views

Thank you very much. I really appreciate your effort.

Please one more thing, I want the program to display different values of that 'functn' from 1-218, 219-436, 437-654 etc. For instance, the first 'functn' in the first interval will be 114.49, followed by 188.1064 and 285.72653 etc.

Highlighted
Black Belt
35 Views

The program in #6 will do exactly what you asked for in #7 if the data in lines 219-436 of SIM.DAT are different from the data in lines 1-218, and so on. With the SIM.DAT that you posted in #1, as I already remarked, you have replicated data, so the output will be three identical lines.

Highlighted
Beginner
35 Views

Yes the output will be replicated three times. But I want the program to display the cumulative at different levels such as

1     114.49

2     188.10

3     285.72

4.    378.88

and so on.

This  will be replicated three times because of the data in 'SIM' file.

Highlighted
Black Belt
35 Views

If I guess what you want correctly, i.e., that you wish to print the cumulative sums Σj=1 to i (obsj - simj)2 for i = 1, 2,..., replace Line-16 of the code in #6 by

```     functn = 0
do i=1,ndata
functn=functn+(obsq(i)-q(i))**2
write(*,'(F10.2)')functn
end do
```

Sooner or later, you will have to learn to write your own programs, using a programming language suited for your needs.

You will also need to describe your goals precisely. Vague statements such as those in #9 will not do. I have no idea as to where the numbers that you listed in #9 came from.

Highlighted
New Contributor I
35 Views

I think mecej4 is being very kind to you. a little effort on your part is quite helpful to reviewers.

Brooks

Highlighted
Beginner
35 Views