experchange > fortran

Ankita Bisht (12-30-18, 04:01 PM)
This program is running without any error but after the compilation and execution it's not giving any output and showing this message that " Filename.exe has stopped working". Can you please help me what is the problem with this programme?

real jn
dimension w(3,1801),af(1801),v1(1801),v2(1801),afj(1801),
1 v1j(1801),v2j(1801),wp(3,1801),afp(1801),bf(1801), an(3,3),
1 bn(3,3),cn(3,3),a(3,3),b(3),jn(3,1801),en(3,3,1801 ),
1 dn(3),v3(1801),v3j(1801),v3d(1801),v1d(1801),v2d(1 801),qq(5),
1 eta(1801),f(3,3),ee(3)
open(1,file='C1.txt',status='new')
data xx,h,dx/6.0,0.02,0.05/
m0=99999
p=2.0
S=0.5
Rea =10
Da=1.0
Nb=0.2
Nt=0.2
Pr=2
a11 =1.0
Ec =0.1
Br=Pr*Ec
M =0.2
Fr =1
L1= (S*(2*p-1)+1)/(p+1)
L2 = (S*(2-p)+p)/(p+1)
write(1,2) xx,h,dx
2 format(x,'ETAEND=',f5.2,x,'H=',f4.2,x,'DX=',f5.2,x )
C INITIAL PROFILES
n = 3
ni = int(xx/h)
n0 = ni + 1
fxi = 0.0
sxi = 0.0
gxi = 0.0
xi = 0.0
do 3 i=1,n0
eta(i)=xi
af(i) = 1.0- exp(-eta(i))
w(1,i) = exp(-eta(i))
v1(i) = -exp(-eta(i))
v1d(i) = exp(-eta(i))

w(2,i) = exp(-eta(i))
v2(i) = - exp(-eta(i))
v2d(i) = exp(-eta(i))

w(3,i) = exp(-eta(i))
v3(i) = -exp(-eta(i))
v3d(i) = exp(-eta(i))
xi = xi + h
3 continue
x = 0.0
do 4 i=1,3
dn(i) = 0.0
jn(i,1) = w(i,1)
jn(1,n0)=0.0
jn(2,n0)=0.0
jn(3,n0)=0.0
do 4 j=1,3
an(i,j) = 0.0
bn(i,j) = 0.0
cn(i,j) = 0.0
en(i,j,1) = 0.0
en(i,j,n0) = 0.0
4 continue
C COMPUTATIONS STARTS WITH X DO LOOP
do 300 m=1,m0
if(x.ge.0.44)dx=0.01
if(x.ge.0.99)dx=0.005
if(x.ge.1.49)dx=0.0005
if(x.ge.1.64)dx=0.0001
itrn =0
5 itrn = itrn + 1
w(1,1) = 1.0
w(2,1) = 1.0
w(3,1) = 1.0
w(1,n0) = 0.0
w(2,n0) = 0.0
w(3,n0) = 0.0
C COMPUTATIONS STARTS WITH ETA DO LOOP
do 6 i=2,ni
i1 = i - 1
i2 = i + 1
v1(i) = ( w(1,i2) - w(1,i1) )/ (2.0 * h)
v2(i) = ( w(2,i2) - w(2,i1) )/ (2.0 * h)
v3(i) = ( w(3,i2) - w(3,i1) )/ (2.0 * h)
v1d(i) = ( w(1,i2) - 2.0 * w(1,i) + w(1,i1) )/ (h*h)
v2d(i) = ( w(2,i2) - 2.0 * w(2,i) + w(2,i1) )/ (h*h)
v3d(i) = ( w(3,i2) - 2.0 * w(3,i) + w(3,i1) )/ (h*h)
afj(i) = ( af(i) - afp(i) ) / dx
v1j(i) = ( w(1,i) - wp(1,i) )/ dx
v2j(i) = ( w(2,i) - wp(2,i) )/ dx
v3j(i) = ( w(3,i) - wp(3,i) )/ dx
if(m.eq.1)go to 51
if(m.ne.1)go to 52
51 continue
C MATRIX COEFFICIENT FOR X=0
a1 = a11+ p*(-v1(i))**(p-1)
a2 = L1*af(i)+(p*(p-1.0)/(a11+ p*(-v1(i))**(p-1)))*(L1*af(i)
1 *((-v1(i))**(p -1.0))-((Fr/Da)+S)*(w(1,i)**2)
1 *((-v1(i))**(p -2.0))
1 -(w(1,i)/Rea*Da)*((-v1(i))**(p -2.0)))
a3 = -2.0* ((Fr/Da)+S)*w(1,i)- (1.0/(Rea*Da))
a4 = 0
u1 = -((Fr/Da)+S)*(w(1,i)**2)-
1 ((p*(p-1)*((-v1(i))**(p -1.0)))/(a11+ p*(-v1(i))**(p-1)))*v1d(i)
b1 = 1.0
b2 = Nb*v3(i)+2*Nt*v2(i)+Pr*L1**af(i)
b3 = 0.0
b4 = (p+1.0)*Br*((-v1(i))**(p))
b5 = 2*Br*M*w(1,i)+((2*Br*w(1,i))/(Rea*Da))
1 +((3*Br*(w(1,i)**2)*Fr)/(Da))
b6 = Nb*v2(i)
u2 = -v2d(i)+(p-1)*Br*((-v1(i))**(p+1))+(Fr/Da)*(w(1,i)**3)
1 -Pr*L1*af(i)*v2(i)
c1 = 1.0
c2 = -Nt*v2(i)-Le*Pr*L1*af(i)
c3 = 0.0
c4 = -(Nt/Nb)*(Nb*v3(i)+2*Nt*v2(i)+Pr*L1*af(i))
c5 =0.0
c6 = -(Nt/Nb)*(2*Br*a11*v1(i)+(p+1)*Br*((-v1(i))**(p)))
c7 = -(Nt/Nb)*(2*Br*M*w(1,i)+(2*Br*w(1,i)/(Rea*Da))
1 +((3*Br*(w(1,i)**2)*Fr)/(Da)))
u3 = -(Nt/Nb)*( v2d(i)+(p-1)*Pr*((-v1(i))**(p+1))
1 +(Fr/Da)*(w(1,i)**3)-Pr*L1*v2(i)*af(i))
an(1,1) = a1/(h**2) -a2/(2*h)
an(1,2) = 0.0
an(1,3) = 0.0
an(2,1) = - b4/(2*h)
an(2,2) = b1/(h**2) -b2/(2*h)
an(2,3) = -b6/(2*h)
an(3,1) = -c6/(2*h)
an(3,2) = -c4/(2*h)
an(3,3) = c1/(h**2) -c2/(2*h)
bn(1,1) = -2.0*a1/(h**2)+a3
bn(1,2) = 0.0
bn(1,3) = 0.0
bn(2,1) = b5
bn(2,2) = -2.0*b1/(h**2)
bn(2,3) = 0.0
bn(3,1) = c7
bn(3,2) = 0.0
bn(3,3) = -2.0*c1/(h**2)
cn(1,1) = a1/(h**2)+a2/(2*h)
cn(1,2) = 0.0
cn(1,3) = 0.0
cn(2,1) = b4/2*h
cn(2,2) = b1/(h**2)+b2/(2*h)
cn(2,3) = b6/(2*h)
cn(3,1) = c6/(2*h)
cn(3,2) = c4/(2*h)
cn(3,3) = c1/(h**2)+c2/(2*h)
dn(1) = u1
dn(2) = u2
dn(3) = u3
go to 255
52 continue
C MATRIX COEFFICIENTS FOR NON-ZERO X

a1 = a11+ p*((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Br*M*w(1,i)
1 +(2*Br*w(1,i)/(Rea*Da))+((3*Br*(w(1,i)**2)*Fr)/(Da))
1 + Pr*L2*xx*v2j(i))
u3 = -L2*Le*Pr*xx*v3j(i)*w(1,i)-(Nt/Nb)*( v2d(i)+(p-1)*Pr*
1 ((-v1(i))**(p+1))+(Fr/Da)*(w(1,i)**3)
1 -Pr*L1*v2(i)*af(i)+Pr*L2*xx*v2(i)*afj(i))
an(1,1) = a1/(h**2) -a2/(2*h)
an(1,2) = 0.0
an(1,3) = 0.0
an(2,1) = - b4/(2.0*h)
an(2,2) = b1/(h**2) -b2/(2.0*h)
an(2,3) = -b6/(2.0*h)
an(3,1) = -c6/(2.0*h)
an(3,2) = -c4/(2.0*h)
an(3,3) = c1/(h**2) -c2/(2.0*h)
bn(1,1) = -2.0*a1/(h**2)+a3+ a4/(dx)
bn(1,2) = 0.0
bn(1,3) = 0.0
bn(2,1) = b5
bn(2,2) = -2.0*b1/(h**2)+b3/dx
bn(2,3) = 0.0
bn(3,1) = c7
bn(3,2) = c5/dx
bn(3,3) = -2.0*c1/(h**2)+c3/dx
cn(1,1) = a1/(h**2)+a2/(2.0*h)
cn(1,2) = 0.0
cn(1,3) = 0.0
cn(2,1) = b4/2.0*h
cn(2,2) = b1/(h**2)+b2/(2.0*h)
cn(2,3) = b6/(2.0*h)
cn(3,1) = c6/(2.0*h)
cn(3,2) = c4/(2.0*h)
cn(3,3) = c1/(h**2)+c2/(2.0*h)
dn(1) = u1+ (a4/dx)*wp(1,i)
dn(2) = u2+(b3/dx)*wp(2,i)
dn(3) = u3+(c3/dx)*wp(3,i)+(c5/dx)*wp(2,i)
go to 255
C VARGA ALGORITHM
255 do 7 j=1,3
do 7 ll=1,3
b(j)=0.0
a(j,ll)=0.0
do 7 k=1,3
b(j) = b(j) + an(j,k) * jn(k,i1)
7 a(j,ll) = a(j,ll) + an(j,k) * en(k,ll,i1)
do 8 j=1,3
b(j) = dn(j) - b(j)
do 8 k=1,3
a(j,k) = bn(j,k) - a(j,k)
8 continue
call matinv(a,n,qq,f)
do 9 j=1,3
do 9 ll=1,3
jn(j,i)=0.0
en(j,ll,i) = 0.0
do 9 k=1,3
jn(j,i) = jn(j,i) + f(j,k)*b(k)
en(j,ll,i) = en(j,ll,i) + f(j,k)*cn(k,ll)
9 continue
6 continue
do 10 i1=2,ni
i= n0 - i1 + 1
i2 = i + 1
do 11 j=1,3
w(j,i) = 0.0
do 11 k=1,3
11 w(j,i) = w(j,i) + en(j,k,i)*w(k,i2)
do 12 j=1,3
12 w(j,i) = jn(j,i) - w(j,i)
10 continue
C CALCULATIONS OF VELOCITY AND ENTHALPY GRADIENTS
fx0=(-11.0*w(1,1)+18.0*w(1,2)-9.0*w(1,3)+2.0*w(1,4))/(h*6.0)
sx0=(-11.0*w(2,1)+18.0*w(2,2)-9.0*w(2,3)+2.0*w(2,4))/(h*6.0)
gx0=(-11.0*w(3,1)+18.0*w(3,2)-9.0*w(3,3)+2.0*w(3,4))/(h*6.0)
do 13 i=1,n0
13 bf(i) = w(1,i)
af(1)=0.0
af(2)=af(1)+(bf(1)+bf(2))*(h/2.0)
do 14 i=3,n0
i1 = i - 1
i2 = i - 2
af(i) = af(i2) + ( bf(i2) + 4.0* bf(i1) + bf(i) ) * h/3.0
14 continue
C TEST FOR CONVERGENCE
c11 = abs(fxi - fx0)
c12 = abs(sxi - sx0)
c13 = abs(gxi - gx0)
c123 = amax1(c11,c12,c13)
if(c123.lt.0.001)goto 15
if(itrn.ge.80) goto 505
fxi = fx0
sxi = sx0
gxi = gx0
go to 5
15 continue
if(fx0.lt.0.02) goto 211
m1 = m - 1
m11 = m1/1
sm1 = float(m1)/1.0
ssm = abs(sm1 - m11)
if(ssm.lt.0.001)go to 211
go to 212
C PRINTING FINAL RESULTS
211 skfx= a11*fx0-(-fx0)**p
skfz= -sx0
httr=-gx0
write(*,16)x,fx0,sx0,gx0,skfx,skfz,httr
write(1,16)x,fx0,sx0,gx0,skfx,skfz,httr
c write(1,18)
16 format(x,'X=',f6.4,x,'FX0=',f9.3,x,'SX0=',f9.4,x,' GX0=',
1 f9.4,x,'CFX=',f7.3,x,'CFZ=',f9.3,x,'ST=',f8.3)
212 if( (abs(x - 0.0)).lt.0.0001)go to 555
if( (abs(x - 1.5)).lt.0.0001)go to 555
if( (abs(x - 1.0)).lt.0.0001)go to 555
go to 444
555 write(1,997)
997 format(4x,'ETA',6x,'AF',6x,'F',7x,'S',7x,'G',6x,
1 'ETA',6x,'AF',6x,'F',7x,'S',7x,'G',x)
ni2 = ni/2
n02 = ni2 + 1
do 17 j=1,n02,10
j1 = j + ni2
write(1,19)eta(j),af(j),w(1,j),w(2,j),w(3,j),eta(j 1),af(j1),
1 w(1,j1),w(2,j1),w(3,j1)
19 format(10(x,f7.4))
17 continue
444 do 45 i=1,n0
afp(i) = af(i)
wp(1,i) = w(1,i)
wp(2,i) = w(2,i)
wp(3,i) = w(3,i)
45 continue
if(abs(x).ge.2.250)go to 505
300 x = x + dx
write(1,18)
18 format(2x,19(x,'*-*'))
write(1,61)
61 format(30x,'PROGRAMM IS OVER')
write(1,18)
505 stop
end
C SUBROUTINE FOR MATRIX INVERSE
subroutine matinv(a,n,qq,f)
real a(3,3),f(3,3),qq(5),ee(3)
n = 3
qq(1) = 1.0
k = 1
do 101 i=1,n
do 101 j=1,n
101 f(i,j) = a(i,j)
106 qq(k+1) = 0.0
do 102 i=1,n
102 qq(k+1) = qq(k+1) + f(i,i)
fk = k
qq(k+1) = - qq(k+1) / fk
do 112 i=1,n
112 f(i,i) = f(i,i) + qq(k+1)
if(k-n+1)104,105,104
104 do 108 j=1,n
do 111 l=1,n
111 ee(l) = f(l,j)
do 108 i=1,n
f(i,j) = 0.0
do 108 is=1,n
108 f(i,j) = f(i,j) + a(i,is) * ee(is)
k = k + 1
go to 106
105 qq(n+1) = 0.0
do 107 j=1,n
107 qq(n+1) = qq(n+1) - a(1,j) * f(j,1)
if(qq(n+1))109,110,109
109 do 208 i=1,n
do 208 j=1,n
208 f(i,j) = - f(i,j) / qq(n+1)
110 return
end
mecejfour (12-30-18, 04:33 PM)
On Sun, 30 Dec 2018 06:01:31 -0800, Ankita Bisht wrote:

> This program is running without any error but after the compilation and
> execution it's not giving any output and showing this message that "
> Filename.exe has stopped working". Can you please help me what is the
> problem with this programme?


The program is not "without any error" if it stopped working!

Use your Fortran compiler's debugging facilities and learn to locate and
repair errors yourself.

1. The variable "Le" is used without having been given any value.

2. In the expressions for evaluating C4 (two places), you have the piece "/
nb", but the value of NB = 0. You have to take care of this error.

--mecej4
Ankita Bisht (12-30-18, 05:54 PM)
On Sunday, December 30, 2018 at 8:03:09 PM UTC+5:30, mecejfour wrote:
> On Sun, 30 Dec 2018 06:01:31 -0800, Ankita Bisht wrote:
> The program is not "without any error" if it stopped working!
> Use your Fortran compiler's debugging facilities and learn to locate and
> repair errors yourself.
> 1. The variable "Le" is used without having been given any value.
> 2. In the expressions for evaluating C4 (two places), you have the piece "/
> nb", but the value of NB = 0. You have to take care of this error.
> --mecej4


Dear Sir/ Ma'am I have not assigned Nb a zero value and still, after changing its value this program stops working without showing any error. Actually, I am new to Fortran please guide me to locate the error.
mecejfour (12-30-18, 07:00 PM)
On Sun, 30 Dec 2018 07:54:09 -0800, Ankita Bisht wrote:

> Dear Sir/ Ma'am I have not assigned Nb a zero value and still, after
> changing its value this program stops working without showing any error.
> Actually, I am new to Fortran please guide me to locate the error.


Quite early in your main program, you have the statement

Nb = 0.2

There is no explicit declaration of the variable, so Fortran's implicit
rule takes effect, making Nb an integer variable. When a real valued
expression is assigned to Nb, the expression is truncated to the next
lower integer, which is 0.

You may have other similar implicitly typed variables (such as Le) which
probably should be declared as REAL, or given new names that make them
REAL under implicit typing rules.

Please consult a Fortran text for details.

--mecej4
FortranFan (12-30-18, 07:13 PM)
On Sunday, December 30, 2018 at 10:54:11 AM UTC-5, Ankita Bisht wrote:

> .. I am new to Fortran please guide me to locate the error.


@Ankita Bisht,

First, can you please confirm your questions are not part of some student assignments or exams or projects as part of some course at an educational institution? in which case, you should really be referring to the study material available to you (and all other students) to troubleshoot and develop your solutions.

Assuming your needs are education-related, I'll suggest a few things:

1) Since you are new to Fortran, you may want to refer to "free" resources online to "get up to speed" on the language e.g.,



2) Note Fortran is a type "sensitive" programming language with a few built-in aspects such as IMPLICIT typing by default (see: ) and also by default INVARIANT types during run-time i.e., a type thatis INTEGER will remain as INTEGER during program execution.

Thus in your code, the variable 'Nb' is not given a type, so per the IMPLICIT typing rules in the language, 'Nb' is of INTEGER type. Now your code has an assignment 'Nb = 0.2", suggesting Nb is supposed to be an object of floating-point type but it has not been declared as such. Since Nb is treated as INTEGER, the assignment likely results in a "cast" of the value 0.2 to an integer value of zero. Subsequently, on line 117 (per my copy and paste) the instruction 'c4 = -(Nt/Nb)*(Nb*v3(i)+2*Nt*v2(i)+Pr*L1*af(i))' likely results in a division-by-zero causing your program to stop working.

I'll suggest you first familiarize yourself sufficiently with Fortran usingthe above resources (note there are YouTube videos also).

You can then start to "fix" your code by introducing "IMPLICIT NONE" statement at the beginning, declaring all your variables explicitly as either INTEGER, or LOGICAL, or appropriate floating-point type as in REAL(kind=wp),etc. Re: floating-point, see this:



Good luck,
robin.vowels (12-31-18, 01:14 AM)
On Monday, December 31, 2018 at 4:00:27 AM UTC+11, mecejfour wrote:
> On Sun, 30 Dec 2018 07:54:09 -0800, Ankita Bisht wrote:


> Quite early in your main program, you have the statement
> Nb = 0.2
> There is no explicit declaration of the variable, so Fortran's implicit
> rule takes effect, making Nb an integer variable. When a real valued
> expression is assigned to Nb, the expression is truncated to the next
> lower integer, which is 0.
> You may have other similar implicitly typed variables (such as Le) which
> probably should be declared as REAL, or given new names that make them
> REAL under implicit typing rules.
> Please consult a Fortran text for details.


Same goes for Nt, M, and probably L1 and L2.
bernard gingold (12-31-18, 09:10 AM)
On Sunday, December 30, 2018 at 3:01:33 PM UTC+1, Ankita Bisht wrote:
[..]
> 208 f(i,j) = - f(i,j) / qq(n+1)
> 110 return
> end


You should definitely use debugger in order to investigate that problem.
By reading 'mecej4' and 'FortranFan' answer the best option to start an investigation is to break at subroutine 'jn' (is this subroutine name?) prologue and to inspect these automatic variables: Nb,Nt and M.
Probably they would have a value of 0.
As a side note: -- Learn to use your tools of trade (debuggers, profilers and even PE or ELF file readers)
Thomas Koenig (12-31-18, 12:11 PM)
Ankita Bisht <bishtankita2> schrieb:
> This program is running without any error but after the compilation and execution it's not giving any output and showing this message that " Filename.exe has stopped working". Can you please help me what is the problem with this programme?


Use the error and warning reporting facilities that compilers have.

I assume you have, or can get access to, gfortran - it's free, after
all.

Running this program through "gfortran -std=legacy -Og -Wall" yields

foo3.f:14:11:

14 | Nb=0.2
| 1
Warning: Change of value in conversion from 'REAL(4)' to 'INTEGER(4)' at (1) [-Wconversion]
foo3.f:15:11:

15 | Nt=0.2
| 1
Warning: Change of value in conversion from 'REAL(4)' to 'INTEGER(4)' at (1) [-Wconversion]
foo3.f:20:11:

20 | M =0.2
| 1
Warning: Change of value in conversion from 'REAL(4)' to 'INTEGER(4)' at (1) [-Wconversion]
foo3.f:22:12:

22 | L1= (S*(2*p-1)+1)/(p+1)
| 1
Warning: Possible change of value in conversion from REAL(4) to INTEGER(4) at (1) [-Wconversion]
foo3.f:23:13:

23 | L2 = (S*(2-p)+p)/(p+1)
| 1
Warning: Possible change of value in conversion from REAL(4) to INTEGER(4) at (1) [-Wconversion]
foo3.f:6:26:

6 | 1 eta(1801),f(3,3),ee(3)
| 1
Warning: Unused variable 'ee' declared at (1) [-Wunused-variable]
foo3.f:115:0:

115 | c2 = -Nt*v2(i)-Le*Pr*L1*af(i)
|
Warning: 'le' may be used uninitialized in this function [-Wmaybe-uninitialized]

All the variables Nb, Nt, M, L1 and L2 are implicitly declared INTEGER.
Similar Threads