How to pass allocatable arrays to subroutines in Fortran -


the following code returning segmentation fault because allocatable array trying pass not being recognized (size returns 1, when should 3). in page (http://www.eng-tips.com/viewthread.cfm?qid=170599) similar example seems indicate should work fine in f95; code file has .f90 extension, tried changing f95, , using gfortran compile.

my guess problem should in way passing allocatable array subroutine; doing wrong?

!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!  program test !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!  implicit none  double precision,allocatable :: array(:,:)  integer                      :: iii,jjj   allocate(array(3,3))  iii=1,3  jjj=1,3     array(iii,jjj)=iii+jjj     print*,array(iii,jjj)  enddo  enddo  call subtest(array)   end program !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!  subroutine subtest(array)  double precision,allocatable,intent(in) :: array(:,:)  integer                                 :: iii,jjj   print*,size(array,1),size(array,2)  iii=1,size(array,1)  jjj=1,size(array,2)     print*,array(iii,jjj)  enddo  enddo   end subroutine !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%! 

if procedure has dummy argument allocatable, explicit interface required in calling scope.

(there numerous things require explicit interface, allocatable dummy one.)

you can provide explicit interface putting interface block subroutine inside main program. alternative , far, far, far better option put subroutine inside module , use module in main program - explicit interface automatically created. there example of on eng-tips site provided link - see post xwb.

note makes sense dummy argument have allocatable attribute if going related allocation status - query status, reallocate it, deallocate it, etc.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -