 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Mon Mar 23, 2015 5:46 am Post subject: Need help! error 363 and 773 |
|
|
Code: | 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? |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Mon Mar 23, 2015 12:21 pm Post subject: |
|
|
Is this what you wanted to do ? Code: | 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 |
|
|
Back to top |
|
 |
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Mon Mar 23, 2015 2:37 pm Post subject: Re: |
|
|
JohnCampbell wrote: | Is this what you wanted to do ? Code: | 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
Code: | 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
|
|
|
Back to top |
|
 |
mecej4
Joined: 31 Oct 2006 Posts: 1899
|
Posted: Mon Mar 23, 2015 5:14 pm Post subject: |
|
|
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
Code: | print *,'gamma_n can be <= ', int(sqrt(n1+n2)) | if n1 and n2 are real, or Code: | 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. |
|
Back to top |
|
 |
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Tue Mar 24, 2015 4:26 pm Post subject: Re: |
|
|
mecej4 wrote: | 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
Code: | print *,'gamma_n can be <= ', int(sqrt(n1+n2)) | if n1 and n2 are real, or Code: | 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. |
|
Back to top |
|
 |
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Wed Mar 25, 2015 6:38 pm Post subject: Re: |
|
|
mecej4 wrote: | 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
Code: | print *,'gamma_n can be <= ', int(sqrt(n1+n2)) | if n1 and n2 are real, or Code: | 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 |
|
Back to top |
|
 |
mecej4
Joined: 31 Oct 2006 Posts: 1899
|
Posted: Wed Mar 25, 2015 6:54 pm Post subject: |
|
|
You can do use an internal write to form the file name, and then open the file with that name.
Code: | 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. |
|
Back to top |
|
 |
star2066
Joined: 27 Jan 2015 Posts: 19
|
Posted: Wed Mar 25, 2015 7:37 pm Post subject: Re: |
|
|
mecej4 wrote: | You can do use an internal write to form the file name, and then open the file with that name.
Code: | 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:
Code: | character(len=16) :: filename
print *,'input the output file name'
read *,filename
open(unit=3, file='C:\Users\Administrator\Desktop\results\'//filename//'.txt')
| [/code] |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|