Incompatible ranks 0 and 2 in assignment [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

This question already has an answer here:

I have tried to write a code in fortran to calculate the coordination number. But a got these errors

 coord.f:43.72:              read(13,*) ri(i),  g(2,2,i),   g(1,2,i),   g(1,2,i),    g(1,                                                                         1 Error: Expected array subscript at (1) coord.f:78.38:            call integrate(npts-1,ri,gt,ans)                                                                     1 Warning: Rank mismatch in argument 'ans' at (1) (scalar and rank-2) coord.f:79.8:          t1(ia,ib)=ans                                                            1 Error: Incompatible ranks 0 and 2 in assignment at (1) coord.f:52.32:        call coordination(ri,g,ro,num)                                                                     1 Warning: Invalid procedure argument at (1) 

This is the code below which I have tried for it. Can anyone please help me to solve these errors?

ccccc   Solution for Coordination number:   c   2 :macro-ion c   1 :counter-ion          include "prmts" ! parameter for npts, l, pi, bl!         character init*10          integer icont(l,l)         double precision grid, dm22, dr, dt, num          double precision g(l,l,npts),      &  ro(l,l),z(l),r(l),ri(npts),dm(l,l),       &  h(l,l,npts),ans(l,l), t1(l,l),gt(npts)          open(unit=13,file='grm.out.txt',status='old')         open(unit=14,file='cor.out',status='unknown')           read(13,*)(z(i),i=1,l)  ! algebric charge  !          read(13,*)(r(i),i=1,l)  ! radious of ions  !          read(13,*)ro(2,2)   ! no.density of 2  !                        do i = 1, l           r(i) = r(i)         enddo         dm22 = dm22         dr = r(2)/grid         ro(2,2) = ro(2,2)         ro(1,1) = -z(2)*ro(2,2)/z(1)                    ! From condition of electro neutrality !           open(unit=13,file='grm.out.txt',status='old')          do i=1, npts-1             read(13,*) ri(i),  g(2,2,i),   g(1,2,i),   g(1,2,i),    g(1,1,i)          enddo              close(13)  CCCCC   CALCULATE COORDINATION NUMBER          call coordination(ri,g,ro,num)          write(14,*)"# Cornum = ", num(ia,ib)          write(14,*)"#----------------------------------------------"         write(14,*)"#   num22   num21   num12  num11    "         write(14,*)"#----------------------------------------------"  999 format( 4f18.6)          stop         end    ! end of main !           subroutine coordination(ri,g,ro,num)         include 'prmts' ! for l, npts, pi and bl !         double precision ri(npts), g(l,l,npts), ro(l,l)      &  , num(l,l), ans(l,l), t1(l,l),gt(npts)         integer i, ia, ib  CCCCC   COORDINATION NUMBER CCCCC   Cornum : Coordination number.          do ia=1,l         do ib=1,l         do i=1,npts-1           gt(i)=g(ia,ib,i)*ri(i)**2         enddo           call integrate(npts-1,ri,gt,ans)           t1(ia,ib)=ans         enddo         enddo  CCCCC   COORDINATION NUMBER          do ia=1,l         do ib=1,l           num(ia,ib)= 4.0d0*pi*ro(ib,ib)*t1(ia,ib)         enddo         enddo         write(*,*) 'Cornum = ', num(ia,ib)         end        subroutine integrate(n,x,y,ans)       integer          nin, nout       parameter        (nin=5,nout=6)       double precision ans, error       integer          ifail, n       double precision x(n), y(n)          ifail = 1           call pintegr(x,y,n,ans,error,ifail)           if (ifail.eq.0) then             write (nout,99999) 'integral = ', ans,      +        '     estimated error = ', error          else if (ifail.eq.1) then             write (nout,*) 'less than 4 points supplied'          else if (ifail.eq.2) then             write (nout,*)      +        'points not in increasing or decreasing order'          else if (ifail.eq.3) then             write (nout,*) 'points not all distinct'          end if       return  99999 format (1x,a,e12.4,a,e12.4)       end        subroutine pintegr(x,y,n,ans,er,ifail)       double precision  ans, er       integer n       double precision  x(n), y(n)       double precision c, d1, d2, d3, h1, h2, h3, h4, r1, r2, r3,       * r4, s       integer i, nn       ans = 0.0d0       er = 0.0d0       if (n.ge.4) go to 20       ifail = 1       return         h2 = x(2) - x(1)  20         do 80 i = 3, n          h3 = x(i) - x(i-1)          if (h2*h3) 40, 40, 80         write(*,*)'points not specified correctly'        40          ifail = 3          return      continue         80        d3 = (y(2)-y(1))/h2       h3 = x(3) - x(2)       d1 = (y(3)-y(2))/h3       h1 = h2 + h3       d2 = (d1-d3)/h1       h4 = x(4) - x(3)       r1 = (y(4)-y(3))/h4       r2 = (r1-d1)/(h4+h3)       h1 = h1 + h4       r3 = (r2-d2)/h1       ans = h2*(y(1)+h2*(d3/2.0d0-h2*(d2/6.0d0-(h2+2.0d0*h3)*r3/12.0d0))      *      )       s = -(h2**3)*(h2*(3.0d0*h2+5.0d0*h4)+10.0d0*h3*h1)/60.0d0       r4 = 0.0d0        nn = n - 1       do 120 i = 3, nn          ans = ans + h3*((y(i)+y(i-1))/2.0d0-h3*h3*(d2+r2+(h2-h4)*r3)      *         /12.0d0)          c = h3**3*(2.0d0*h3*h3+5.0d0*(h3*(h4+h2)+2.0d0*h4*h2))/120.0d0          er = er + (c+s)*r4          if (i.ne.3) s = c          if (i.eq.3) s = s + 2.0d0*c          if (i-n+1) 100, 140, 100          h1 = h2                   100          h2 = h3          h3 = h4          d1 = r1          d2 = r2          d3 = r3          h4 = x(i+2) - x(i+1)          r1 = (y(i+2)-y(i+1))/h4          r4 = h4 + h3          r2 = (r1-d1)/r4          r4 = r4 + h2          r3 = (r2-d2)/r4          r4 = r4 + h1          r4 = (r3-d3)/r4        continue       120         continue       140           ans = ans + h4*(y(n)-h4*(r1/2.0d0+h4*(r2/6.0d0+(2.0d0*h3+h4)          *      *r3/12.0d0)))            er = er - h4**3*r4*(h4*(3.0d0*h4+5.0d0*h2)+10.0d0*h3*(h2+h3+h4))          *     /60.0d0 + s*r4            ans = ans + er            ifail = 0             return            end  END of Program 

回答1:

The key is to notice that the first error is at column 72 and that the line is incomplete in the error message.

The line is to long for Fortran 77 which allows only 72 characters. Divide the lines into to or use some compiler option to allow longer lines (breaks portability).

There are other errors too, like

t1(ia,ib)=ans 

t1(ia,ib) is a scalar (one array element) and ans is an array. That is not possible, you must be consistent.

The procedure integrate defines its dummy argument ans as a scalar real due to implicit typing, but you pass an array ans to it. That is also not possible.

I suggest you to use implicit none in all programs although it is technically not Fortran 77. It will help you to avoid many errors.

Finally, num was declared as as double precision but used as

num(ia,ib)

for this reason the compiler thinks it is an external function and warns you about the invalid procedure argument. You must be consistent and declare it as an array or use it as a scalar.

Probably, there are many more errors in the code, it is quite messy and very hard to read.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!