Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28760 Discussions

error #8093 and #6511 in  fortran 77

Manfredini_Bueno__Gu
1,917 Views

I can't solve the error of these lines in my code in fortran 77

 

      DO j=1,n                    
         s(j)=0.d0                   
         IF (j==1)THEN             
             s(j)=s(j)+0.d0           
         ELSE IF (j==2)THEN    
             s(j)=s(1)+0.01d0         
         ELSE IF (j>=3)THEN       
                g=j-1.d0            
             s=s(g)+0.01d0              
         END IF                          
         deltat(j)=s(j)                  
      END DO

these errors appear

error #8093: A do-variable within a DO body shall not appear in a variable definition context.

error #6511: This DO variable has already been used as an outer DO variable in the same nesting structure.

I tried it in different ways, but I can't solve it

 

0 Kudos
4 Replies
Arjen_Markus
Honored Contributor I
1,917 Views

This is not the entire code - you have an outer DO-loop using the same variable j that you have not shown here. (Moreover: the code contains at least one Fortran 90 feature - DO/ENDDO - but that is not the cause of the errors).

Basically, you seem to have something like:

DO j = 1,10

    DO j = 1,10

        ... do something useful

   ENDDO

ENDDO

The repeated use of the variable j in both these DO-loop is what causes the trouble - such variables are more or less protected.

 

 

 

0 Kudos
mecej4
Honored Contributor III
1,917 Views

Is the variable g a scalar integer? If so, why do you set g = j - 1.d0, i.e., a real (double precision) expression, rather than the simpler expression j - 1? On the other hand, if g is real, why do you use it as a subscript in s(g)? In fact, the entire code that you presented could be replaced by

s(1) = 0.d0
do j = 2, n
   s(j) = s(j-1) + 0.01d0
end do
delta(1:n) = s(1:n)

 

0 Kudos
FortranFan
Honored Contributor III
1,917 Views

Manfredini Bueno, Guilherme wrote:

I can't solve the error of these lines in my code in fortran 77

.. I tried it in different ways, but I can't solve it

@Manfredini Bueno, Guilherme,

If you're using Intel Fortran, you have a very powerful, modern compiler available for your use.  Given what you show in the original post, it may help you to review the Fortran language and then try to work on your code and solve the errors.  You may want to consider starting with a textbook such as this one: https://www.amazon.com/FORTRAN-SCIENTISTS-ENGINEERS-Stephen-Chapman/dp/0073385891: ;

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,917 Views

mecej4 (Blackbelt) wrote:

Is the variable g a scalar integer? If so, why do you set g = j - 1.d0, i.e., a real (double precision) expression, rather than the simpler expression j - 1? On the other hand, if g is real, why do you use it as a subscript in s(g)? In fact, the entire code that you presented could be replaced by

s(1) = 0.d0
do j = 2, n
   s(j) = s(j-1) + 0.01d0
end do
delta(1:n) = s(1:n)

 

I should caution in constructing deltas in the manner above. In the above case, in particular, 0.01d0 has a repeating binary fraction (mantissa), and thus cannot be expressed exactly in floating point (even in this case of use of double precision).

Example:

program HelloWorld2
    implicit none
    integer, parameter :: n=100000
    real(8) :: s(n), t(n), u(n)
    integer :: j, i
    
    s(1) = 0.d0
    do j = 2, n
       s(j) = s(j-1) + 0.01d0
    end do
    
    do j = 1, n
        t(j) = (j-1) * 0.01d0
    end do
    
    do j = 1, n
        u(j) = real((j-1),kind(0.0d0)) / 100.d0
    end do
	
    ! show first difference
    do j = 1, n
        if(s(j) /= t(j)) then
            print *, "s(j) /= t(j)", j, s(j), t(j), s(j)-t(j)
            exit
		end if
	end do
        
    do j = 1, n
        if(t(j) /= u(j)) then
            print *, "t(j) /= u(j)", j, t(j), u(j), t(j)-u(j)
            exit
		end if
	end do

    ! show
    print *, "do something at intervals of every 10.0 for s(j)"
    i = 0
    do j = 1, n, 1000
        if(mod(s(j), 10.0d0) == 0.0d0) then
            i = i + 1 ! something
		else
            print *, "mod(s(j), 10.0d0) /= 0.0d0)", j, s(j), mod(s(j), 10.0d0)
		endif
    end do
    print *, i, "intervals"
    print *
    print *, "do something at intervals of every 10.0 for t(j)"
    i = 0
    do j = 1, n, 1000
        if(mod(t(j), 10.0d0) == 0.0d0) then
            i = i + 1 ! something
        else
            print *, "mod(t(j), 10.0d0) /= 0.0d0)", j, t(j), mod(t(j), 10.0d0)
		endif
    end do
    print *, i, "intervals"
    
    print *
    print *, "do something at intervals of every 10.0 for u(j)"
    i = 0
    do j = 1, n, 1000
        if(mod(u(j), 10.0d0) == 0.0d0) then
            i = i + 1 ! something
        else
            print *, "mod(u(j), 10.0d0) /= 0.0d0)", j, u(j), mod(u(j), 10.0d0)
		endif
    end do
    print *, i, "intervals"
    
end program HelloWorld2
=========== output =============
 s(j) /= t(j)           7  6.000000000000000E-002  6.000000000000000E-002
  6.938893903907228E-018
 t(j) /= u(j)          36  0.350000000000000       0.350000000000000
  5.551115123125783E-017

 do something at intervals of every 10.0 for s(j)
 mod(s(j), 10.0d0) /= 0.0d0)        1001   9.99999999999983
   9.99999999999983
 mod(s(j), 10.0d0) /= 0.0d0)        2001   20.0000000000003
  3.268496584496461E-013
 mod(s(j), 10.0d0) /= 0.0d0)        3001   30.0000000000019
  1.890043677121866E-012
 mod(s(j), 10.0d0) /= 0.0d0)        4001   40.0000000000006
  6.110667527536862E-013
 mod(s(j), 10.0d0) /= 0.0d0)        5001   49.9999999999986
   9.99999999999862
 mod(s(j), 10.0d0) /= 0.0d0)        6001   59.9999999999966
   9.99999999999663
 mod(s(j), 10.0d0) /= 0.0d0)        7001   69.9999999999989
   9.99999999999891
 mod(s(j), 10.0d0) /= 0.0d0)        8001   80.0000000000040
  4.021671884402167E-012
 mod(s(j), 10.0d0) /= 0.0d0)        9001   90.0000000000091
  9.137579581874888E-012
 mod(s(j), 10.0d0) /= 0.0d0)       10001   100.000000000014
  1.425348727934761E-011
 mod(s(j), 10.0d0) /= 0.0d0)       11001   110.000000000019
  1.936939497682033E-011
 mod(s(j), 10.0d0) /= 0.0d0)       12001   120.000000000024
  2.448530267429305E-011
 mod(s(j), 10.0d0) /= 0.0d0)       13001   130.000000000027
  2.674482857401017E-011
 mod(s(j), 10.0d0) /= 0.0d0)       14001   140.000000000018
  1.764988155628089E-011
 mod(s(j), 10.0d0) /= 0.0d0)       15001   150.000000000009
  8.554934538551606E-012
 mod(s(j), 10.0d0) /= 0.0d0)       16001   159.999999999999
   9.99999999999946
 mod(s(j), 10.0d0) /= 0.0d0)       17001   169.999999999990
   9.99999999999037
 mod(s(j), 10.0d0) /= 0.0d0)       18001   179.999999999981
   9.99999999998127
 mod(s(j), 10.0d0) /= 0.0d0)       19001   189.999999999972
   9.99999999997218
 mod(s(j), 10.0d0) /= 0.0d0)       20001   199.999999999963
   9.99999999996308
 mod(s(j), 10.0d0) /= 0.0d0)       21001   209.999999999954
   9.99999999995399
 mod(s(j), 10.0d0) /= 0.0d0)       22001   219.999999999945
   9.99999999994489
 mod(s(j), 10.0d0) /= 0.0d0)       23001   229.999999999936
   9.99999999993580
 mod(s(j), 10.0d0) /= 0.0d0)       24001   239.999999999927
   9.99999999992670
 mod(s(j), 10.0d0) /= 0.0d0)       25001   249.999999999918
   9.99999999991761
 mod(s(j), 10.0d0) /= 0.0d0)       26001   259.999999999909
   9.99999999990854
 mod(s(j), 10.0d0) /= 0.0d0)       27001   269.999999999899
   9.99999999989944
 mod(s(j), 10.0d0) /= 0.0d0)       28001   279.999999999890
   9.99999999989035
 mod(s(j), 10.0d0) /= 0.0d0)       29001   289.999999999881
   9.99999999988125
 mod(s(j), 10.0d0) /= 0.0d0)       30001   299.999999999872
   9.99999999987216
 mod(s(j), 10.0d0) /= 0.0d0)       31001   309.999999999863
   9.99999999986306
 mod(s(j), 10.0d0) /= 0.0d0)       32001   319.999999999854
   9.99999999985397
 mod(s(j), 10.0d0) /= 0.0d0)       33001   329.999999999845
   9.99999999984487
 mod(s(j), 10.0d0) /= 0.0d0)       34001   339.999999999836
   9.99999999983578
 mod(s(j), 10.0d0) /= 0.0d0)       35001   349.999999999827
   9.99999999982668
 mod(s(j), 10.0d0) /= 0.0d0)       36001   359.999999999818
   9.99999999981759
 mod(s(j), 10.0d0) /= 0.0d0)       37001   369.999999999808
   9.99999999980849
 mod(s(j), 10.0d0) /= 0.0d0)       38001   379.999999999799
   9.99999999979940
 mod(s(j), 10.0d0) /= 0.0d0)       39001   389.999999999790
   9.99999999979030
 mod(s(j), 10.0d0) /= 0.0d0)       40001   399.999999999781
   9.99999999978121
 mod(s(j), 10.0d0) /= 0.0d0)       41001   409.999999999772
   9.99999999977211
 mod(s(j), 10.0d0) /= 0.0d0)       42001   419.999999999763
   9.99999999976302
 mod(s(j), 10.0d0) /= 0.0d0)       43001   429.999999999754
   9.99999999975392
 mod(s(j), 10.0d0) /= 0.0d0)       44001   439.999999999745
   9.99999999974483
 mod(s(j), 10.0d0) /= 0.0d0)       45001   449.999999999736
   9.99999999973573
 mod(s(j), 10.0d0) /= 0.0d0)       46001   459.999999999727
   9.99999999972664
 mod(s(j), 10.0d0) /= 0.0d0)       47001   469.999999999718
   9.99999999971755
 mod(s(j), 10.0d0) /= 0.0d0)       48001   479.999999999708
   9.99999999970845
 mod(s(j), 10.0d0) /= 0.0d0)       49001   489.999999999699
   9.99999999969936
 mod(s(j), 10.0d0) /= 0.0d0)       50001   499.999999999690
   9.99999999969026
 mod(s(j), 10.0d0) /= 0.0d0)       51001   509.999999999681
   9.99999999968117
 mod(s(j), 10.0d0) /= 0.0d0)       52001   519.999999999672
   9.99999999967213
 mod(s(j), 10.0d0) /= 0.0d0)       53001   529.999999999663
   9.99999999966303
 mod(s(j), 10.0d0) /= 0.0d0)       54001   539.999999999654
   9.99999999965394
 mod(s(j), 10.0d0) /= 0.0d0)       55001   549.999999999645
   9.99999999964484
 mod(s(j), 10.0d0) /= 0.0d0)       56001   559.999999999636
   9.99999999963575
 mod(s(j), 10.0d0) /= 0.0d0)       57001   569.999999999627
   9.99999999962665
 mod(s(j), 10.0d0) /= 0.0d0)       58001   579.999999999618
   9.99999999961756
 mod(s(j), 10.0d0) /= 0.0d0)       59001   589.999999999608
   9.99999999960846
 mod(s(j), 10.0d0) /= 0.0d0)       60001   599.999999999599
   9.99999999959937
 mod(s(j), 10.0d0) /= 0.0d0)       61001   609.999999999590
   9.99999999959027
 mod(s(j), 10.0d0) /= 0.0d0)       62001   619.999999999581
   9.99999999958118
 mod(s(j), 10.0d0) /= 0.0d0)       63001   629.999999999572
   9.99999999957208
 mod(s(j), 10.0d0) /= 0.0d0)       64001   639.999999999563
   9.99999999956299
 mod(s(j), 10.0d0) /= 0.0d0)       65001   649.999999999554
   9.99999999955389
 mod(s(j), 10.0d0) /= 0.0d0)       66001   659.999999999545
   9.99999999954480
 mod(s(j), 10.0d0) /= 0.0d0)       67001   669.999999999536
   9.99999999953570
 mod(s(j), 10.0d0) /= 0.0d0)       68001   679.999999999527
   9.99999999952661
 mod(s(j), 10.0d0) /= 0.0d0)       69001   689.999999999518
   9.99999999951751
 mod(s(j), 10.0d0) /= 0.0d0)       70001   699.999999999508
   9.99999999950842
 mod(s(j), 10.0d0) /= 0.0d0)       71001   709.999999999499
   9.99999999949932
 mod(s(j), 10.0d0) /= 0.0d0)       72001   719.999999999490
   9.99999999949023
 mod(s(j), 10.0d0) /= 0.0d0)       73001   729.999999999481
   9.99999999948113
 mod(s(j), 10.0d0) /= 0.0d0)       74001   739.999999999472
   9.99999999947204
 mod(s(j), 10.0d0) /= 0.0d0)       75001   749.999999999463
   9.99999999946294
 mod(s(j), 10.0d0) /= 0.0d0)       76001   759.999999999454
   9.99999999945385
 mod(s(j), 10.0d0) /= 0.0d0)       77001   769.999999999445
   9.99999999944475
 mod(s(j), 10.0d0) /= 0.0d0)       78001   779.999999999436
   9.99999999943566
 mod(s(j), 10.0d0) /= 0.0d0)       79001   789.999999999427
   9.99999999942656
 mod(s(j), 10.0d0) /= 0.0d0)       80001   799.999999999417
   9.99999999941747
 mod(s(j), 10.0d0) /= 0.0d0)       81001   809.999999999408
   9.99999999940837
 mod(s(j), 10.0d0) /= 0.0d0)       82001   819.999999999399
   9.99999999939928
 mod(s(j), 10.0d0) /= 0.0d0)       83001   829.999999999390
   9.99999999939018
 mod(s(j), 10.0d0) /= 0.0d0)       84001   839.999999999381
   9.99999999938109
 mod(s(j), 10.0d0) /= 0.0d0)       85001   849.999999999372
   9.99999999937199
 mod(s(j), 10.0d0) /= 0.0d0)       86001   859.999999999363
   9.99999999936290
 mod(s(j), 10.0d0) /= 0.0d0)       87001   869.999999999354
   9.99999999935380
 mod(s(j), 10.0d0) /= 0.0d0)       88001   879.999999999345
   9.99999999934471
 mod(s(j), 10.0d0) /= 0.0d0)       89001   889.999999999336
   9.99999999933561
 mod(s(j), 10.0d0) /= 0.0d0)       90001   899.999999999327
   9.99999999932652
 mod(s(j), 10.0d0) /= 0.0d0)       91001   909.999999999317
   9.99999999931742
 mod(s(j), 10.0d0) /= 0.0d0)       92001   919.999999999308
   9.99999999930833
 mod(s(j), 10.0d0) /= 0.0d0)       93001   929.999999999299
   9.99999999929923
 mod(s(j), 10.0d0) /= 0.0d0)       94001   939.999999999290
   9.99999999929014
 mod(s(j), 10.0d0) /= 0.0d0)       95001   949.999999999281
   9.99999999928104
 mod(s(j), 10.0d0) /= 0.0d0)       96001   959.999999999272
   9.99999999927195
 mod(s(j), 10.0d0) /= 0.0d0)       97001   969.999999999263
   9.99999999926285
 mod(s(j), 10.0d0) /= 0.0d0)       98001   979.999999999254
   9.99999999925376
 mod(s(j), 10.0d0) /= 0.0d0)       99001   989.999999999245
   9.99999999924466
           1 intervals

 do something at intervals of every 10.0 for t(j)
         100 intervals

 do something at intervals of every 10.0 for u(j)
         100 intervals

While the difference is not large (in fact it is quite tiny), this difference may become significant to the proper running of your program when the iteration count is expected (required) to fall on specific intervals.

The simplified "s(j-1)+ 0.01" is insufficient to meet this requirement.

While the "(j-1) * 0.01d0" is producing expected results, this potentially is by accident, not design.

The "real((j-1),kind(0.0d0)) / 100.d0" assures the computational arguments do not contain repeating fractions (provided the compiler optimization does not turn this into *.01d0.

In the case of computing T from dT the (j-1)*dT is sufficient

However for interval anniversary, it would be best to use integer values. In this example "T" would be expressed in 100ths of seconds and not seconds.

Jim Dempsey

0 Kudos
Reply