Silverfrost Forums

Welcome to our forums

Need help! error 363 and 773

23 Mar 2015 4:46 #15949
program test
implicit none
real :: ngamma,n1,n2
n1=5
n2=5
ngamma=0
if (sqrt(n1+n2)>=ngamma)
  then ngamma=ngamma+1
    endif
print *,'gamma_n can be',ngamma
end program test

I want to show all ngamma. But the FORTRAN show error 363 and 773. Could someone help me about this?

23 Mar 2015 11:21 #15957

Is this what you wanted to do ? program test implicit none real :: ngamma,n1,n2 n1=5 n2=5 ngamma=0

 do
   ngamma=ngamma+1 
   if ( sqrt(n1+n2) >= ngamma ) then
     print *,'gamma_n can be',ngamma 
   else
     exit
   end if 
 end do

 end program test
23 Mar 2015 1:37 #15960

Quoted from JohnCampbell Is this what you wanted to do ? program test implicit none real :: ngamma,n1,n2 n1=5 n2=5 ngamma=0

 do
   ngamma=ngamma+1 
   if ( sqrt(n1+n2) >= ngamma ) then
     print *,'gamma_n can be',ngamma 
   else
     exit
   end if 
 end do

 end program test

Thank you very much! It works very well. However, I want to put it into another program, the FORTRAN said the error 328. Part of my code is

program simul
implicit none
real :: r1,r2,c1,c2,e,x,pa,pb,sumpc,sumpm,gamma,ker,hd,d,dhatp,dhat,pbsq,kf,sumpuj,nnn,maxpd,w,ngamma
real :: yy1,yy2,e1
integer, parameter :: NN = 1000
integer, parameter :: pi = 3.1415926
real,dimension(NN) :: xp,y,xr,yr,pu,rhok,pd,puj,cp
integer :: i,n1,n2,n,j,m,k,nrep
integer,dimension(1) :: place
print *,'input numbers before change point to continue'
read *, n1
print *,'input numbers after change point to continue'
read *, n2
print *,'input coefficient of relationship before change point to continue'
read *, r1
print *,'input coefficient of relationship after change point to continue'
read *, r2
ngamma=0 
 do 
   ngamma=ngamma+1 
   if ( ngamma<=sqrt(n1+n2)) then 
     print *,'gamma_n can be',ngamma 
   else 
     exit 
   end if 
 end do 
print *,'input gamma_n'
read *, gamma
23 Mar 2015 4:14 #15967

You do not need a DO loop to find the largest value of ngamma such that its square does not exceed the sum of n1 and n2. It would be enough to write

print *,'gamma_n can be <= ', int(sqrt(n1+n2))

if n1 and n2 are real, or print *,'gamma_n can be ⇐ ',int(sqrt(float(n1+n2))) when n1 and n2 are integers.

It would be more helpful if you post the error message text instead of just the error numbers. Most of us probably have not memorized the error numbers, and sometimes it is inconvenient to look them up.

24 Mar 2015 3:26 #15976

Quoted from mecej4 You do not need a DO loop to find the largest value of ngamma such that its square does not exceed the sum of n1 and n2. It would be enough to write

print *,'gamma_n can be <= ', int(sqrt(n1+n2))

if n1 and n2 are real, or print *,'gamma_n can be ⇐ ',int(sqrt(float(n1+n2))) when n1 and n2 are integers.

It would be more helpful if you post the error message text instead of just the error numbers. Most of us probably have not memorized the error numbers, and sometimes it is inconvenient to look them up.

Got u. Thank you very much.

25 Mar 2015 5:38 #15992

Quoted from mecej4 You do not need a DO loop to find the largest value of ngamma such that its square does not exceed the sum of n1 and n2. It would be enough to write

print *,'gamma_n can be <= ', int(sqrt(n1+n2))

if n1 and n2 are real, or print *,'gamma_n can be ⇐ ',int(sqrt(float(n1+n2))) when n1 and n2 are integers.

It would be more helpful if you post the error message text instead of just the error numbers. Most of us probably have not memorized the error numbers, and sometimes it is inconvenient to look them up.

One more question. if I want to name my output file as value of variable. how can I do that? For example, my n1=30,r1=1. I want to the name of output is 30,1.txt.

THx

25 Mar 2015 5:54 #15993

You can do use an internal write to form the file name, and then open the file with that name.

character(len=8) :: filename
...
write(filename,'(i2,',',i1,'.txt')') n1, r1
open(unit=..,file=filename,...)
...
write(...

It is probably not a good idea to have a comma as part of a file name.

25 Mar 2015 6:37 #15994

Quoted from mecej4 You can do use an internal write to form the file name, and then open the file with that name.

character(len=8) :: filename
...
write(filename,'(i2,',',i1,'.txt')') n1, r1
open(unit=..,file=filename,...)
...
write(...

It is probably not a good idea to have a comma as part of a file name.

yeah, you are right. But it doesnt work with 'write(filename,'(i2,i1,'.txt')') n1, r1'. I use this way and it works well:

character(len=16) :: filename
print *,'input the output file name'
read *,filename
open(unit=3, file='C:\Users\Administrator\Desktop\results'//filename//'.txt')

[/code]

Please login to reply.