Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in constructing problem

Status
Not open for further replies.

jonfrag

Programmer
Jul 25, 2014
5
GR
Hello I'm new here i need some help with a program. I have a file (ava.dat) which contains 6.000.000 integer numbers (non zero). There is a threshold value (mthres). I want to find which elements are greater or equal from this threshold and to make a calculation which will concern the next 10000 elements. I;m starting like this

.....
nmax=6000000
mthres=220970869
open(1,file='ava.dat')
do i=1,nmax
read(1,*)s(i)
if (s(i).ge.mthres) then
...

How can define the steps i+1,i+10000 where i is the position in which τηε criterio s(i).ge.mthres holds???

Any help would be appreciated
 
You have to read all the values first.
Code:
open(...
read(1,*)(s(i), i = 1, nmax)
close(1)
do i = 1, nmax - 10000
   if (s(i) .ge.mthres) then
       ! do something with s(i+1)
       ! do something with s(i+10000)
   end if
end do
 
First of all i would like to thank you for your response. I want to do the following calculation:
When i read the element s(i) which is greater or equal to mthres, i want to calculate the sum for the next 10000 steps :

cum=0.0
1st calculation: cum=cum+s(i+1)=s(i+1)
2nd calculation: cum=s(i+1)+s(i+2)
...
100000st calculation: cum=cum+s(i+10000)

I want to follow this procedure for each s(i).ge.mthres

Thanx!!!!!
 
Not sure if your first calculation is what you really want - you may have a typo = should be +. I'm assuming you want the sum of the next 10000 elements including the one that is greater than mthres.

I'm just guessing that you want to do something like this.
Code:
integer::cumCounter
...
cumCounter = -1
do i = 1, nmax - 10000
   if (cumCounter .gt. 0) then
       ! Not reached the 10000 yet
       cum = cum + s(i)
       cumCounter = cumCounter - 1
   else if (cumCounter .eq. 0) then
       ! do something with cum otherwise you will lose it
       print *, cum
       ! reset counter
       cumCounter = -1
   else if (s(i) .ge.mthres) then
       !  I may be out by 1 - you may have to start at 9999
       cumCounter = 10000
       cum = s(i)
   end if
end do
 
Thanks again for your response. I will tell you analytically what i want to do and any further help would be appreciated.
In a time series comprising 6.000.000 (file='ava.dat.2500') events i calculate the quantity k1 with the program described below ypolk1.f90. This program gives me exactly the results i expect and want.
Let me now define a threshold value, mthres. I want to read the file ava.dat.2500 which is a one dimension array of 6.000.000 elements. I want to find each element of this array which is greater or equal than mthres and to apply the program ypolk1.f90 for the next 10.000 elements (the element which is greater or equal than mthres is not included). In the file 'ava.dat.2500' there are 2216 elements greater than mthres so the procedure described by the following program should run 2216 times i guess.

program ypolk1
double precision k1(6000000),avx(6000000),avx2(6000000),a(6000000),b,c,ath,n(6000000),x
integer i,nmax
nmax=6000000
ath=0.0
open(10,file='ava.dat.2500')
do i=1,nmax
read(10,*) x
a(i)=x
ath=ath+x
n(i)=ath
end do
close (10)
avx(1)=1.0
avx2(1)=1.0
k1(1)=0.0
do i=1,nmax
b=dble(i)/dble(i+1)
c=n(i)/(n(i)+a(i+1))
avx(i+1)=b*c*avx(i)+a(i+1)/(n(i)+a(i+1))
avx2(i+1)=(b**2)*c*avx2(i)+a(i+1)/(n(i)+a(i+1))
k1(i+1)=avx2(i+1)-avx(i+1)*avx(i+1)
end do
do i=1,nmax
print*,i
write(13,*) i,k1(i)
end do
close(13)
end

Thanks again!!!!!!!!!!!
 
Say you have two values that are greater than mthres at location 25 and 27. Do you wish to calculate the values at both 25 and 27 or just 25 and resume the search at 10025.
 
I want to calculate the values at both 25 and 27 (26-10025 and 28-10027) ! If we assume that there are 5 values greater than mthres, we will have 5 small times series in which i want to apply the procedure described by ypol.k1

1st time series : k1(i+1) k1(i+2).....k1(i+10000)
2nd time series : k1(i+1) k1(i+2).....k1(i+10000)
...........................................
5th time series : k1(i+1) k1(i+2).....k1(i+10000)

Of course, the i is different in each time series.

Finally, i want to write the average k1 in each step: k1(i+1)/5 etc


 
You've told me what the problem is but not which part are you having difficulty in coding.

Also I don't quite understand the last bit on k1(i+1)/5.
 
The program ypolk1.f90 calculate the quantity k1 for each value of 'ava.dat.2500'. There is a threshold value, 'mthres'. First, I want to find which values of 'ava.dat.2500' are greater (or equal) than mthres (easy...). Then, i want to apply the procedure described in ypolk1.f90 to the following 10.000 values of each value which is greater (or equal) than mthres (without including the value which is greater then mthres,if the value is in the position i=500, i want to calculate the quantity k1 for the positions "i=501,10500"). How can we write this loop?? In the ypolk1.f90 there is the quantity b=dble(i)/dble(i+1). How can we express this quantity??? This "i" counts the consecutive values, i mean that if there is a value greater (or equal) than mthres then for the next value from which we start the calculation we have b=dble(1)/dble(1+1) because is the first value etc. (we don;t care in which position is this value). The k1(i+1)/5 is the average value of k1 in the first position after the value which is greater than mthres, if we assume that there are only 5 values.ge.mthres. I want the average k1 in each position. I don;t know if i explain exactly what i want to do.

I really thank you again!!
 
What you're describing will go something like this. I've embedded your comments with my interpretation of what you think your problem is
Code:
   ! sets all the values in k1 to 0
   k1 = 0.0
   nvalues = 0
   nrange = 10000
   do i = 1, nmax - (nrange + 1)
      ! First, I want to find which values of 'ava.dat.2500' are greater (or equal) than mthres (easy...).
      if (a(i) .ge. mthres) then
          nvalues = nvalues + 1
          ! Then, i want to apply the procedure described in ypolk1.f90 to the
          ! following 10.000 values of each value which is greater (or equal)
          ! than mthres (without including the value which is greater then mthres
          do j = 1, nrange
             !  In the ypolk1.f90 there is the quantity b=dble(i)/dble(i+1). How can we express this quantity??? This "i" counts the consecutive values, i mean that if there is a value greater (or equal) than mthres then for the next value from which we start the calculation we have b=dble(1)/dble(1+1) because is the first value etc. (we don;t care in which position is this value)
             b = dble(j) / dble(j + 1)
             ! do your calculation using (i+j) as an index, use j if you want the relative position
             ix = i + j
             c = n(ix)/(n(ix)+a(ix+1))
             ...
             ! Not sure about this one - do you want a cumulative value and then store
             ! it in k1(i+1) at the end of the loop?
             k1(ix) = ...
          end do
      end if
   end do
   !The k1(i+1)/5 is the average value of k1 in the first position after the value
   !which is greater than mthres, if we assume that there are only 5 values.ge.mthres. 
   !I want the average k1 in each position. I don;t know if i explain exactly what i
   !want to do.
   ! divide all values in k1 by number of values > mthres.  This is an array operation
   k1 = k1 / nvalues
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top