I'm working in a finite difference method on an irregular grid, this is the important part of the code:
IMPLICIT DOUBLE PRECISION (A-Z)
REAL*16 IPSI,ICORR,POT(20000),VA(20000),delta1(20000),
$delta2(20000),R(20000),a,b,d
COMPLEX Y(20000),TY2(50000),Z(20000),PSI0(20000),RES,DPSI,C,
$CORR,OPK
DO I=3,NR-1
delta1=R(I)-R(I-1)
delta2=R(I+1)-R(I)
a=(2/(delta1*(delta1+delta2)))
b=(-2/(delta1*delta2))
d=(2/(delta2*(delta1+delta2)))
TY2(I)=((d*Z(I+1))+(b*Z(I))+(a*Z(I-1)))
ENDDO
When I try to compile I got Error: Incompatible ranks 0 and 1 in assignment at (1) for a,b,d and TY2. Any solution will be appreciated. Thanks!
a=(2/(delta1*(delta1+delta2)))
b=(-2/(delta1*delta2))
and the following lines are illegal. On the right you have arrays, on the left a scalar.
Maybe you forgot some index like delta1(I) or delta1 should be a scalar. We can't say without knowing more about your code.
Related
I'm working in a finite difference method on an irregular grid, this is the important part of the code:
IMPLICIT DOUBLE PRECISION (A-Z)
REAL*16 IPSI,ICORR,POT(20000),VA(20000),delta1(20000),
$delta2(20000),R(20000),a,b,d
COMPLEX Y(20000),TY2(50000),Z(20000),PSI0(20000),RES,DPSI,C,
$CORR,OPK
DO I=3,NR-1
delta1=R(I)-R(I-1)
delta2=R(I+1)-R(I)
a=(2/(delta1*(delta1+delta2)))
b=(-2/(delta1*delta2))
d=(2/(delta2*(delta1+delta2)))
TY2(I)=((d*Z(I+1))+(b*Z(I))+(a*Z(I-1)))
ENDDO
When I try to compile I got Error: Incompatible ranks 0 and 1 in assignment at (1) for a,b,d and TY2. Any solution will be appreciated. Thanks!
a=(2/(delta1*(delta1+delta2)))
b=(-2/(delta1*delta2))
and the following lines are illegal. On the right you have arrays, on the left a scalar.
Maybe you forgot some index like delta1(I) or delta1 should be a scalar. We can't say without knowing more about your code.
Here's a part of my fortran code after compiling gives me an error saying that 'icount at (1) is not a variable
Here goes my code:
integer*4 iy1
integer*2 id1,im1
parameter (month=12,maxper=5,specmax=8)
real conc(month,8,icount(8,month))
integer smonth(12),icount(8,month)
real per(maxper),rper(maxper)
data smonth/12,1,2,3,4,5,6,7,8,9,10,11/
data per/0.10,0.25,0.5,0.75,0.90/
open(unit=1`,file='data_co.txt',status='old')
open(unit=2,file='chennai_alldatatop10.txt',status='unknown',iostat=ierr)
if(ierr.eq.0)close(2,status='delete')
open(unit=2, file='chennai_alldatatop10.txt',status='unknown')
inum=0
2 read(2,*,end=3)id1,im1,iy1,conc1
icount(1,im1)=inum+1
conc(im1,1,icount(1,im1))=conc1
goto 2
3 continue
end
In your variable declarations at the top of your code, you switched the order:
real conc(month,8,icount(8,month))
integer smonth(12),icount(8,month)
You are using icount before you defined it, so your code should look like this:
integer smonth(12),icount(8,month)
real conc(month,8,icount(8,month))
But actually, this doesn't make any sense either, if icount(8, month) has not yet been initialized to a value. So your code should look like this:
integer smonth(12), icount(8,month)
real conc(month, 8, some_scalar_value)
I am facing trouble in compiling a simple piece of code. Following are the details:
Variable declaration:
double q_old[3][N], q_new[3][N], u[3][N], flux[3][N+1], fl[3][N+1], fr[3][N+1];
The following line seems to be the source of error:
fl[0][1:N+1] = u[1][0:N]*u[0][0:N]; // this does not work
fl[0][1:N] = u[1][0:N]*u[0][0:N]; // this works
The error:
shocktube.c(47): catastrophic error: section length mismatch in array expression
compilation aborted for shocktube.c (code 1)
I am using intel icpc compiler. The first statement does not work but the second does, which is really weird because AFAIK the size of the LHS array in the first statement will be N(index varying from 1 to N) and size of RHS should also be N(0 to N-1), while in the second statement size of LHS is N-1.
Thanks,
The Intel array section notation is [start:length], not [start:end]. Therefore, this line
fl[0][1:N+1] = u[1][0:N]*u[0][0:N]; // this does not work
is invalid because you are indexing past the end of the array (specifically, you are asking for indices [1, N+2) in the fl array, whose last dimension only has N+1 elements).
The error probably should be a little gentler ("catastrophic" is not a term I'd apply to a user error), but this is ultimately not the compiler's fault.
I'm writing a linear inverse program using geophysical data. I'm new to programming in Fortran although I have created programs relating to geophysical problems with Fortran before.
I'm encountering the error : "Error: Incompatible ranks 0 and 1 in assignment" when compiling. I know this has to do with lengths not agreeing, but I have been unable to resolve it. I want to assign the row of Prism_r(i,pp) with the values previously calculated, namely r1-r4. The error is as followed:
Prism_r(i,pp)=(/ r1(pp),r2(pp),r3(pp),r4(pp) /)
1
Error: Incompatible ranks 0 and 1 in assignment at (1)
Here is the relevant code:
real, dimension(0:P-1) :: r1, r2, r3, r4
real, dimension(0:D-1,0:3) ::Prism_r, Prism_theta
.....
do i=0,D-1
do pp=0,P-1
r1(pp)=sqrt((x2+2*PP-0.2*i)**2+z1**2)
r2(pp)=sqrt((x2+2*PP-0.2*i)**2+z2**2)
r3(pp)=sqrt((x1+2*PP-0.2*i)**2+z2**2)
r4(pp)=sqrt((x1+2*PP-0.2*i)**2+z1**2)
Prism_r(i,pp)=(/ r1(pp),r2(pp),r3(pp),r4(pp) /)
enddo
enddo
The calculations are being performed correctly when I comment Prism_r out, but it will not assign values to it. Does anyone have advice to how I need to correctly define r1-r4 so their values will be assigned to Prism_r?
It actually doesn't have to do with lengths not agreeing, but instead with ranks not agreeing, just as the error message says.
Prism_r(i,pp) is a single element of the array: it's a scalar, i.e. rank 0.
(/ r1(pp),r2(pp),r3(pp),r4(pp) /) is a rank 1 array (of length four).
In fortran you can't assign an array to a scalar.
I am working on writing a Fortran which has to solve square root and that results in getting a complex number, but Fortran doesn't print it or passes that to another variable. It gives (NaN, 0.000).
This is a dummy code to represent the problem that i am having with the actual code i am working on. If you guys can give me any information that would be helpful. Thank You.
program test
IMPLICIT NONE
COMPLEX X
REAL a, b, c
a = 1
b = 1
c = 1
X = sqrt(b - 4*a*c)
print *, REAL(X), ' - j',-AIMAG(X)
end program test
Since a, b and c are all reals, the expression on the right-hand side of the assignment will be calculated in real arithmetic. Assigning it to a complex variable on the left-hand side doesn't change that. If you want the calculation done as a complex value, the easiest way is to declare a, b, and c as complex.