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!

Rebinning Data 1

Status
Not open for further replies.

hummus

Programmer
Jul 2, 2008
15
US
Hi,

I need help in constructing a Fortran program that will rebin the following data. Here is what I need to do:

-I need to construct the data so that for every 5 bins(0-.5,.5-1,1-1.5, etc.) the total sum of the counts for the 5 bins are displayed.
-Also the average error, which equals (SQRT((error_bin1^2)+(error_bin2^2)...)) needs to be displayed for every 5 bins.
-So, basically I am trying to present the data in a more presentable form, but still in the same table format.

I appreciate your help!

Bin Counts Error
0.0 0.1 0.000000e+00 1.246307e+03
0.1 0.2 0.000000e+00 1.384062e+03
0.2 0.3 0.000000e+00 7.293359e+02
0.3 0.4 0.000000e+00 4.347419e+02
0.4 0.5 0.000000e+00 2.886545e+02
0.5 0.6 0.000000e+00 2.121605e+02
0.6 0.7 0.000000e+00 1.780368e+02
0.7 0.8 1.860239e+03 1.260624e+03
0.8 0.9 4.459698e+04 8.547545e+04
0.9 1.0 2.186709e+03 4.667829e+03
1.0 1.1 1.435697e+02 8.899864e+02
1.1 1.2 -2.663352e+02 5.854734e+02
1.2 1.3 3.914954e+02 3.700430e+02
1.3 1.4 4.836762e+02 3.082303e+02
1.4 1.5 2.310999e+02 2.661533e+02
1.5 1.6 3.931144e+01 1.878104e+02
1.6 1.7 2.174683e+02 1.717450e+02
1.7 1.8 5.201125e+01 1.321500e+02
1.8 1.9 2.651151e+02 1.599340e+02
1.9 2.0 4.399519e+01 1.297579e+02
2.0 2.1 2.419880e+02 1.585462e+02
2.1 2.2 9.620107e+01 1.061600e+02
2.2 2.3 9.430807e+01 1.349242e+02
2.3 2.4 -4.409645e+01 1.153539e+02
2.4 2.5 6.508822e+01 7.076512e+01
2.5 2.6 -2.414544e+02 1.244045e+02
2.6 2.7 5.022138e+01 6.547811e+01
2.7 2.8 -4.759686e+01 8.690866e+01
2.8 2.9 -2.192769e+02 9.773648e+01
2.9 3.0 -3.211433e+01 7.493255e+01
3.0 3.1 1.774129e+02 8.275328e+01
3.1 3.2 9.261980e+01 1.052127e+02
3.2 3.3 1.125748e+02 1.160030e+02
3.3 3.4 1.338158e+02 7.524153e+01
3.4 3.5 1.175320e+02 6.544840e+01
3.5 3.6 1.007442e+02 7.027041e+01
3.6 3.7 8.079117e+00 4.768503e+01
3.7 3.8 2.831477e+01 5.651733e+01
3.8 3.9 6.895191e+01 6.264614e+01
3.9 4.0 6.547348e+01 5.151797e+01
4.0 4.1 -2.703517e+01 3.432813e+01
4.1 4.2 1.818555e+01 3.942893e+01
4.2 4.3 -8.891703e+00 6.226578e+01
4.3 4.4 2.875568e+01 4.892077e+01
4.4 4.5 -1.410340e+01 5.061625e+01
4.5 4.6 -9.170539e+01 6.407574e+01
4.6 4.7 7.644147e+01 4.559211e+01
4.7 4.8 8.188116e+01 4.467571e+01
4.8 4.9 8.369775e+01 4.402335e+01
4.9 5.0 4.915925e+01 3.741202e+01
5.0 5.1 1.232162e+01 4.187785e+01
5.1 5.2 -2.983277e+01 4.723371e+01
5.2 5.3 2.215924e+01 4.793545e+01
5.3 5.4 3.477517e+01 4.777378e+01
5.4 5.5 1.354970e+01 3.513870e+01
5.5 5.6 1.877098e+00 3.377090e+01
5.6 5.7 -4.757156e+01 3.816899e+01
5.7 5.8 -3.269796e+01 4.006648e+01
5.8 5.9 1.258449e+01 4.790275e+01
5.9 6.0 1.808871e+01 4.483938e+01
6.0 6.1 4.012610e+01 3.483579e+01
(there is more data, but this should suffice)
 
Which part are you having problems with?
 
I am new to Fortran, so I am learning the language right now. I have done C++ before, but I need to use Fortran with this problem. If you want to help me with the basic steps I will need to take with this, that would be great. Thanks again.
 
Ok, this is what I have so far. If it works, it can only do 5 bins at a time. Is there any code I could use so the user can enter in all the data at once, so it will display the sum of the counts and total error for every 5 bins in table format? Your help is greatlty appreciated.

Code:
PROGRAM REBINNING_DATA

IMPLICIT NONE

REAL :: Count_Total, Error_Total
REAL :: c1, c2, c3, c4, c5
REAL :: e1, e2, e3, e4, e5

!Receive Count Data
WRITE(*,*) 'Enter Counts'
READ(*,*) c1, c2, c3, c4, c5

!Compute Count Sum
Count_Total = (c1 + c2 + c3 + c4 + c5)

!Receive Error Data
WRITE(*,*) 'Enter Errors'
READ(*,*) e1, e2, e3, e4, e5

!Compute Error Total
Error_Total = !Error formula

!Display Results
WRITE(*,*)
WRITE(*,*) 'Count sum is', Count_Total
WRITE(*,*)
WRITE(*,*) 'Error total is', Error_Total

END PROGRAM REBINNING_DATA
 
Try to solve this problem on C++ (familiar language, post #2?) then translate it to Fortran by hand (syntactically and semantically ~ 1:1 in this area;)...
 
I wrote the program, but there are quite a few errors (see below) when it comes to my arrays. I'm not sure how I can fix them. Your help is greatly appreciated.

Code
Code:
PROGRAM REBINNING_DATA

      IMPLICIT NONE

      INTEGER :: ndet, ntenths, nbins, ngroups, newbins 
      INTEGER :: nj, bincounter

	         ngroups = 15	!Number of groups
	         ndet = 20	!Number of detectors
	         ntenths = 5	!Size of resized bin

      DIMENSION Count(ndet, ngroups, 200),
     Err(ndet, ngroups, 200), LowMeV(ndet, ngroups, 200), 
     HiMeV(ndet, ngroups, 200)

      DIMENSION Count_total (ndet, ngroups, 200), 
     Err_total(ndet, ngroups, 200), 
     Err_totalsq(ndet, ngroups, 200), 
     Err_new(ndet, ngroups, 200), 
     wi(ndet, ngroups, 200),  
     Count_avg(ndet, ngroups, 200),  
     newlo(ndet, ngroups, 200), 
     newhi(ndet, ngroups, 200)

      bincounter = 0
      Err_total = 0.0
      Count_total = 0.0
      Err_totalsq = 0.0
      Err_new = 0.0

      Do n = 1, ndet

		Do i = 1, ngroups

	        WRITE(*,*) 'Enter the number of lines of data'

	        READ(*,*) nbins

	        WRITE(*,*) 'Enter data'

		Do j = 1, nbins
		
		READ(*,*) LowMeV(n, i, j), HiMeV(n, i, j), 
     Count(n, i, j), Err(n, i, j)

      bincounter = bincounter + 1

		End do

	newbins = bincounter / ntenths

	Do j = 1, newbins

		Do m = 1, ntenths

		nj = ((j-1)*ntenths) + m

		wi(n, i, j) = (1.0 / Err(n, i, nj))**2

		Count_total(n, i, j) = Count_total(n, i, j) 
     + Count(n, i, nj) * wi( n, i, j)

		Err_total(n, i, j) = Err_total(n, i, j)
     +wi(n, i, j)

		End do

	Err_totalsq(n, i, j) = Err_total(n, i, j)**2

	Count_avg(n, i, j) = Count_total(n, i, j)
     /wi(n, i, j)

		Do m = 1, ntenths

		   nj = ((j-1)*ntenths) + m

		   Err_new(n, i, j) = Err_new(n, i, j)
     +((1.0/Err(n, i, nj))**2)/Err_totalsq(n, i, j)
		if (m.eq.1) newlo(n ,i, j) = LoMeV(n, i, nj)

		if (m.e.ntenths) newhi(n, i, j) =
     HiMeV(n, i, nj)
	
		End do

	End do

      WRITE(*,*) 'NaI Low ADCL Threshold'

      WRITE(*,*) 'Average Counts and Total Error'

      WRITE(*,*)

	Do j = 1, new bins

	WRITE(*,*) newlo(n, i, j), newhi(n, i, j),
     Count_avg(n, i, j), Err_new(n, i, j)

	End do

      End do

      End do

      END PROGRAM REBINNING_DATA

Errors
Code:
Rebin2.FOR:1:
    PROGRAM REBINNING_DATA
    ^
Non-numeric character at (^) in label field [info -f g77 M LEX]
Rebin2.FOR: In program `MAIN__':
Rebin2.FOR:5:
         INTEGER :: ndet, ntenths, nbins, ngroups, newbins
                    1
Rebin2.FOR:12: (continued):
         DIMENSION Count(ndet, ngroups, 200),
                         2
Invalid declaration of or reference to symbol `ndet' at (2) [initially seen at (1)]
Rebin2.FOR:5:
         INTEGER :: ndet, ntenths, nbins, ngroups, newbins
                                          1
Rebin2.FOR:12: (continued):
         DIMENSION Count(ndet, ngroups, 200),
                               2
Invalid declaration of or reference to symbol `ngroups' at (2) [initially seen at (1)]
Rebin2.FOR:8:
                    ngroups = 15   !Number of groups
                    1
Rebin2.FOR:12: (continued):
         DIMENSION Count(ndet, ngroups, 200),
         2
Statement at (2) invalid in context established by statement at (1)
Rebin2.FOR:8:
                    ngroups = 15   !Number of groups
                    1
Rebin2.FOR:16: (continued):
         DIMENSION Count_total (ndet, ngroups, 200),
         2
Statement at (2) invalid in context established by statement at (1)
Rebin2.FOR:26:
         Err_total = 0.0
         ^
Invalid declaration of or reference to symbol `err_total' at (^) [initially seen at (^)]
Rebin2.FOR:27:
         Count_total = 0.0
         ^
Invalid declaration of or reference to symbol `count_total' at (^) [initially seen at (^)]
Rebin2.FOR:28:
         Err_totalsq = 0.0
         ^
Invalid declaration of or reference to symbol `err_totalsq' at (^) [initially seen at (^)]
Rebin2.FOR:29:
         Err_new = 0.0
         ^
Invalid declaration of or reference to symbol `err_new' at (^) [initially seen at (^)]
Rebin2.FOR:31:
         Do n = 1, ndet
            ^
Invalid declaration of or reference to symbol `n' at (^) [initially seen at (^)]Rebin2.FOR:33:
                   Do i = 1, ngroups
                      ^
Invalid declaration of or reference to symbol `i' at (^) [initially seen at (^)]Rebin2.FOR:41:
                   Do j = 1, nbins
                      ^
Invalid declaration of or reference to symbol `j' at (^) [initially seen at (^)]Rebin2.FOR:43:
                   READ(*,*) LowMeV(n, i, j), HiMeV(n, i, j),
                             ^
Invalid declaration of or reference to symbol `lowmev' at (^) [initially seen at (^)]
Rebin2.FOR:43:
                   READ(*,*) LowMeV(n, i, j), HiMeV(n, i, j),
                                              ^
Invalid declaration of or reference to symbol `himev' at (^) [initially seen at (^)]
Rebin2.FOR:44:
        Count(n, i, j), Err(n, i, j)
         ^
Invalid declaration of or reference to symbol `ount' at (^) [initially seen at (^)]
Rebin2.FOR:44:
        Count(n, i, j), Err(n, i, j)
                        ^
Invalid declaration of or reference to symbol `err' at (^) [initially seen at (^)]
Rebin2.FOR:54:
                   Do m = 1, ntenths
                      ^
Invalid declaration of or reference to symbol `m' at (^) [initially seen at (^)]Rebin2.FOR:58:
                   wi(n, i, j) = (1.0 / Err(n, i, nj))**2
                   ^
Invalid declaration of or reference to symbol `wi' at (^) [initially seen at (^)]
Rebin2.FOR:61:
        + Count(n, i, nj) * wi( n, i, j)
          ^
Invalid form for assignment statement at (^)
Rebin2.FOR:64:
        +wi(n, i, j)
         ^
Invalid form for assignment statement at (^)
Rebin2.FOR:70:
           Count_avg(n, i, j) = Count_total(n, i, j)
           ^
Invalid declaration of or reference to symbol `count_avg' at (^) [initially seen at (^)]
Rebin2.FOR:71:
        /wi(n, i, j)
         ^
Invalid form for assignment statement at (^)
Rebin2.FOR:77:
                      Err_new(n, i, j) = Err_new(n, i, j)
                                         1
Rebin2.FOR:78: (continued):
        +((1.0/Err(n, i, nj))**2)/Err_totalsq(n, i, j)
         2
Invalid use at (2) of substring operator on (1)
Rebin2.FOR:79:
                   if (m.eq.1) newlo(n ,i, j) = LoMeV(n, i, nj)
                               ^
Invalid declaration of or reference to symbol `newlo' at (^) [initially seen at (^)]
Rebin2.FOR:79:
                   if (m.eq.1) newlo(n ,i, j) = LoMeV(n, i, nj)
                                                ^
Invalid declaration of or reference to symbol `lomev' at (^) [initially seen at (^)]
Rebin2.FOR:81:
                   if (m.e.ntenths) newhi(n, i, j) =
                        ^
Period at (^) not followed by valid keyword forming a valid binary operator; `.e.' is not a valid binary operator
Rebin2.FOR:81:
                   if (m.e.ntenths) newhi(n, i, j) =
                                    ^
Invalid declaration of or reference to symbol `newhi' at (^) [initially seen at (^)]
Rebin2.FOR:82:
        HiMeV(n, i, nj)
         ^
Invalid declaration of or reference to symbol `imev' at (^) [initially seen at (^)]
Rebin2.FOR:97:
        Count_avg(n, i, j), Err_new(n, i, j)
         ^
Invalid declaration of or reference to symbol `ount_avg' at (^) [initially seen at (^)]
Rebin2.FOR:8:
                    ngroups = 15   !Number of groups
                    1
Rebin2.FOR:105: (continued):
         END PROGRAM REBINNING_DATA
                     2
Program name at (2) superfluous, no PROGRAM statement specified at (1)
Rebin2.FOR:6: warning: unused variable `nj'
 
Add -ffree-form switch to cmd line (using free format source - or rewrite all source in old fashioned fixed form;), place all declarations before statements (it's not C++), explicitly declare all variables...
and try again.
 
Apropos, in free form source don't forget to add ampersand at the end of line when continuation used.
 
I declared the array variables as REAL. I kept the source in the fixed form (instead of the ampersand, I kept the continuation lines in column 6). I keep getting errors with the arrays, and I'm not sure how I can fix it. Thanks for your help.

Fixed: I declared the array variables:
Code:
REAL :: Count, Err, HiMeV, Count_total, Err_total
      REAL :: Err_totalsq, Err_new, wi, Count_avg, newlo
      REAL :: newhi

The errors I'm getting are mostly due to the way I'm declaring the arrays:
Code:
DIMENSION Count(ndet, ngroups, 200),
     Err(ndet, ngroups, 200), LowMeV(ndet, ngroups, 200), 
     HiMeV(ndet, ngroups, 200)

      DIMENSION Count_total (ndet, ngroups, 200), 
     Err_total(ndet, ngroups, 200), 
     Err_totalsq(ndet, ngroups, 200), 
     Err_new(ndet, ngroups, 200), 
     wi(ndet, ngroups, 200),  
     Count_avg(ndet, ngroups, 200),  
     newlo(ndet, ngroups, 200), 
     newhi(ndet, ngroups, 200)

Errors:
Code:
Rebin3.FOR:1:
    PROGRAM REBINNING_DATA
    ^
Non-numeric character at (^) in label field [info -f g77 M LEX]
Rebin3.FOR: In program `MAIN__':
Rebin3.FOR:5:
         INTEGER :: ndet, ntenths, nbins, ngroups, newbins
                    1
Rebin3.FOR:15: (continued):
         DIMENSION Count(ndet, ngroups, 200),
                         2
Invalid declaration of or reference to symbol `ndet' at (2) [initially seen at (1)]
Rebin3.FOR:5:
         INTEGER :: ndet, ntenths, nbins, ngroups, newbins
                                          1
Rebin3.FOR:15: (continued):
         DIMENSION Count(ndet, ngroups, 200),
                               2
Invalid declaration of or reference to symbol `ngroups' at (2) [initially seen at (1)]
Rebin3.FOR:11:
                    ngroups = 15   !Number of groups
                    1
Rebin3.FOR:15: (continued):
         DIMENSION Count(ndet, ngroups, 200),
         2
Statement at (2) invalid in context established by statement at (1)
Rebin3.FOR:11:
                    ngroups = 15   !Number of groups
                    1
Rebin3.FOR:19: (continued):
         DIMENSION Count_total (ndet, ngroups, 200),
         2
Statement at (2) invalid in context established by statement at (1)
Rebin3.FOR:34:
         Do n = 1, ndet
            ^
Invalid declaration of or reference to symbol `n' at (^) [initially seen at (^)]Rebin3.FOR:36:
                   Do i = 1, ngroups
                      ^
Invalid declaration of or reference to symbol `i' at (^) [initially seen at (^)]Rebin3.FOR:44:
                   Do j = 1, nbins
                      ^
Invalid declaration of or reference to symbol `j' at (^) [initially seen at (^)]Rebin3.FOR:46:
                   READ(*,*) LowMeV(n, i, j), HiMeV(n, i, j),
                             ^
Invalid declaration of or reference to symbol `lowmev' at (^) [initially seen at (^)]
Rebin3.FOR:7:
         REAL :: Count, Err, HiMeV, Count_total, Err_total
                             1
Rebin3.FOR:46: (continued):
                   READ(*,*) LowMeV(n, i, j), HiMeV(n, i, j),
                                              2
Invalid declaration of or reference to symbol `himev' at (2) [initially seen at (1)]
Rebin3.FOR:47:
        Count(n, i, j), Err(n, i, j)
         ^
Invalid declaration of or reference to symbol `ount' at (^) [initially seen at (^)]
Rebin3.FOR:7:
         REAL :: Count, Err, HiMeV, Count_total, Err_total
                        1
Rebin3.FOR:47: (continued):
        Count(n, i, j), Err(n, i, j)
                        2
Invalid declaration of or reference to symbol `err' at (2) [initially seen at (1)]
Rebin3.FOR:57:
                   Do m = 1, ntenths
                      ^
Invalid declaration of or reference to symbol `m' at (^) [initially seen at (^)]Rebin3.FOR:8:
         REAL :: Err_totalsq, Err_new, wi, Count_avg, newlo
                                       1
Rebin3.FOR:61: (continued):
                   wi(n, i, j) = (1.0 / Err(n, i, nj))**2
                   2
Invalid declaration of or reference to symbol `wi' at (2) [initially seen at (1)]
Rebin3.FOR:7:
         REAL :: Count, Err, HiMeV, Count_total, Err_total
                                    1
Rebin3.FOR:63: (continued):
                   Count_total(n, i, j) = Count_total(n, i, j)
                   2
Invalid declaration of or reference to symbol `count_total' at (2) [initially seen at (1)]
Rebin3.FOR:64:
        + Count(n, i, nj) * wi( n, i, j)
          ^
Invalid form for assignment statement at (^)
Rebin3.FOR:7:
         REAL :: Count, Err, HiMeV, Count_total, Err_total
                                                 1
Rebin3.FOR:66: (continued):
                   Err_total(n, i, j) = Err_total(n, i, j)
                   2
Invalid declaration of or reference to symbol `err_total' at (2) [initially seen at (1)]
Rebin3.FOR:67:
        +wi(n, i, j)
         ^
Invalid form for assignment statement at (^)
Rebin3.FOR:8:
         REAL :: Err_totalsq, Err_new, wi, Count_avg, newlo
                 1
Rebin3.FOR:71: (continued):
           Err_totalsq(n, i, j) = Err_total(n, i, j)**2
           2
Invalid declaration of or reference to symbol `err_totalsq' at (2) [initially seen at (1)]
Rebin3.FOR:8:
         REAL :: Err_totalsq, Err_new, wi, Count_avg, newlo
                                           1
Rebin3.FOR:73: (continued):
           Count_avg(n, i, j) = Count_total(n, i, j)
           2
Invalid declaration of or reference to symbol `count_avg' at (2) [initially seen at (1)]
Rebin3.FOR:74:
        /wi(n, i, j)
         ^
Invalid form for assignment statement at (^)
Rebin3.FOR:8:
         REAL :: Err_totalsq, Err_new, wi, Count_avg, newlo
                              1
Rebin3.FOR:80: (continued):
                      Err_new(n, i, j) = Err_new(n, i, j)
                      2
Invalid declaration of or reference to symbol `err_new' at (2) [initially seen at (1)]
Rebin3.FOR:80:
                      Err_new(n, i, j) = Err_new(n, i, j)
                                         1
Rebin3.FOR:81: (continued):
        +((1.0/Err(n, i, nj))**2)/Err_totalsq(n, i, j)
         2
Invalid use at (2) of substring operator on (1)
Rebin3.FOR:8:
         REAL :: Err_totalsq, Err_new, wi, Count_avg, newlo
                                                      1
Rebin3.FOR:82: (continued):
                   if (m.eq.1) newlo(n ,i, j) = LoMeV(n, i, nj)
                               2
Invalid declaration of or reference to symbol `newlo' at (2) [initially seen at (1)]
Rebin3.FOR:82:
                   if (m.eq.1) newlo(n ,i, j) = LoMeV(n, i, nj)
                                                ^
Invalid declaration of or reference to symbol `lomev' at (^) [initially seen at (^)]
Rebin3.FOR:84:
                   if (m.e.ntenths) newhi(n, i, j) =
                        ^
Period at (^) not followed by valid keyword forming a valid binary operator; `.e.' is not a valid binary operator
Rebin3.FOR:9:
         REAL :: newhi
                 1
Rebin3.FOR:84: (continued):
                   if (m.e.ntenths) newhi(n, i, j) =
                                    2
Invalid declaration of or reference to symbol `newhi' at (2) [initially seen at (1)]
Rebin3.FOR:85:
        HiMeV(n, i, nj)
         ^
Invalid declaration of or reference to symbol `imev' at (^) [initially seen at (^)]
Rebin3.FOR:100:
        Count_avg(n, i, j), Err_new(n, i, j)
         ^
Invalid declaration of or reference to symbol `ount_avg' at (^) [initially seen at (^)]
Rebin3.FOR:11:
                    ngroups = 15   !Number of groups
                    1
Rebin3.FOR:108: (continued):
         END PROGRAM REBINNING_DATA
                     2
Program name at (2) superfluous, no PROGRAM statement specified at (1)
Rebin3.FOR:7: warning: unused variable `count'
Rebin3.FOR:6: warning: unused variable `nj'
 
Fixed format? Why PROGRAM stmt started in the 1st pos?

Define ngroups, ndet and ntenths in PARAMETER (symbolic constant) declaration, for example:
Code:
      PARAMETER (ngroups = 15)

Declare all variables explicitly (see I, J et al in DO-loops).

Correct misspelling(s), for example, you wrote LOMEV instead of LOWMEV (and add LOWMEV to REAL:: declaration).

...then try again...

(PS. Better use free format in your next Fortran project;-}
 
Thank you so much for your help.

(PS. Better use free format in your next Fortran project;-}
Yes, I definately will.


Here is what I fixed:
Code:
INTEGER :: n, i, j, m
Code:
PARAMETER (ngroups = 15)	!Number of groups
      PARAMETER (ndet = 20)	!Number of detectors
      PARAMETER (ntenths = 5)	!Size of resized bin
-I declared LowMeV as a REAL

The errors I get now (which are a lot less):
Code:
Rebin3.FOR: In program `rebinning_data':
Rebin3.FOR:30:
         Err_total = 0.0
         ^
Expression at (^) has incorrect data type or rank for its context
Rebin3.FOR:31:
         Count_total = 0.0
         ^
Expression at (^) has incorrect data type or rank for its context
Rebin3.FOR:32:
         Err_totalsq = 0.0
         ^
Expression at (^) has incorrect data type or rank for its context
Rebin3.FOR:33:
         Err_new = 0.0
         ^
Expression at (^) has incorrect data type or rank for its context
Rebin3.FOR:48:
        Count(n, i, j), Err(n, i, j)
         ^
Invalid declaration of or reference to symbol `ount' at (^) [initially seen at (^)]
Rebin3.FOR:65:
        + Count(n, i, nj) * wi( n, i, j)
          ^
Invalid form for assignment statement at (^)
Rebin3.FOR:68:
        +wi(n, i, j)
         ^
Invalid form for assignment statement at (^)
Rebin3.FOR:75:
        /wi(n, i, j)
         ^
Invalid form for assignment statement at (^)
Rebin3.FOR:81:
                      Err_new(n, i, j) = Err_new(n, i, j)
                                         1
Rebin3.FOR:82: (continued):
        +((1.0/Err(n, i, nj))**2)/Err_totalsq(n, i, j)
         2
Invalid use at (2) of substring operator on (1)
Rebin3.FOR:85:
                   if (m.e.ntenths) newhi(n, i, j) =
                        ^
Period at (^) not followed by valid keyword forming a valid binary operator; `.e.' is not a valid binary operator
Rebin3.FOR:86:
        HiMeV(n, i, nj)
         ^
Invalid declaration of or reference to symbol `imev' at (^) [initially seen at (^)]
Rebin3.FOR:101:
        Count_avg(n, i, j), Err_new(n, i, j)
         ^
Invalid declaration of or reference to symbol `ount_avg' at (^) [initially seen at (^)]
Rebin3.FOR:9: warning: unused variable `count_avg__'
Rebin3.FOR:8: warning: unused variable `count_total__'
Rebin3.FOR:8: warning: unused variable `count'
 
Ok, ignore the last error code. I fixed the continuation (I wasn't aware that you needed a character in the 6th column for continuing lines). Here's the errors I get know:
Code:
Rebin3.FOR: In program `rebinning_data':
Rebin3.FOR:30:
         Err_total = 0.0
         ^
Expression at (^) has incorrect data type or rank for its context
Rebin3.FOR:31:
         Count_total = 0.0
         ^
Expression at (^) has incorrect data type or rank for its context
Rebin3.FOR:32:
         Err_totalsq = 0.0
         ^
Expression at (^) has incorrect data type or rank for its context
Rebin3.FOR:33:
         Err_new = 0.0
         ^
Expression at (^) has incorrect data type or rank for its context
Rebin3.FOR:85:
                   if (m.e.ntenths) newhi(n, i, j) =
                        ^
Period at (^) not followed by valid keyword forming a valid binary operator; `.e.' is not a valid binary operator
Thanks
 
1. Alas, Fortran is not equal to unforgettable PL/I: you can't clear an array by a simple scalar assignment. Set zeroes on element by element basis (via DO-loops).
2. I think, the last message is self-descriptive one. There are .EQ. and .NE. ops in Fortran, but what is it: .e.?
 
Set zeroes on element by element basis (via DO-loops).
Could you give me an example of how to do this? Thank you.
 
Evidently (like C++;), for example:
Code:
...
real a(10,20,30)
integer i, j, k
...
do i = 1,10
   do j = 1,20
      do k = 1,30
         a(i,j,k) = 0.0
      end do
   end do
end do
...
Of course, you may write a special subroutine to simplify this operation, but why? Better fire point-blank...

 
I entered this code right after I declared all of my variables and arrays:
Code:
Do n = 1, ndet

      	Do i = 1, ngroups
	
	  Do j = 1, nbins

	  Err_total(n,i,j) = 0.0

	  Count_total(n,i,j) = 0.0
	  
	  Err_totalsq(n,i,j) = 0.0

	  Err_new(n,i,j) = 0.0

	  End do

	End do

      End do

And when I tried to execute the program I received a segmentation fault. I'm not sure what I did wrong.
 
Well, you are on debugging stage now. Go forward step by step. Segmentation fault? OK: where, when (then why;)?..
It's your program, it's your job...

It's possible to debug program w/o debugger (better with;). Add trace printing, intervening loop counter outputs etc...

Yet another tip. Don't waste the time for test data typing during every test run. Make a simple text file with data then read it in your program. There are many ways to do it. For example:
Code:
! Windows environment; test data file path
character*(*), parameter:: fname = 'f:\junk\testdata\data.txt'
integer, parameter:: fun = 10 ! assign test data unit number
integer i
integer k ! data record counter
integer, parameter:: n = 1000 ! max data elements
! Suppose we have four numbers per line:
! line_number x_value y_value z_value
! 1           1.0     10.0    100.0
integer nn(n)
real x(n), y(n), z(n)
...
! Load data from the file
k = 0
open(unit=fun,FILE=fname,ACTION='READ',STATUS='OLD',err=666)
do i = 1, n
   read(fun,*,end=555) nn(i),x(i), y(i), z(i)
   ! print *,nn(i),x(i),y(i),z(i)
   k = k + 1
end do
555 close(UNIT=fun)
if (k.eq.0) then
    ! No data: say wow, stop program or what else...
end if
! print *, k, ' data elements read'
... ! process data
stop
! Open file failed handling
666 print *,'Can not open file ', fname
end program

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top