Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran 90 function invocation

  1. Nov 12, 2008 #1
    i have a fortran 90 function invoked:
    iret = store_data(ncid_bfm,var_ids(n),OCET_SHAPE,NO_BOXES,garray=D3DIAGNOS(i,:))
    each time i get to that line i get segmentation fault

    on the calling unit variables a defined like so:
    ! !IROUTINE: Store the results
    subroutine save_bfm(time)
    ! output of BFM variables
    ! !USES:
    implicit none
    REALTYPE,intent(in) :: time
    integer :: iret
    integer :: i,j,k,n
    REALTYPE :: temp_time

    and on the invoked function the definitions are:
    integer function store_data(ncid,id,var_shape,nbox, &
    iscalar,iarray,scalar,array,garray, &
    ! This routine is used to store a variable in the NetCDF file.
    ! The subroutine uses {\tt optional} parameters to find out which data
    ! type to save.
    ! !USES:
    integer, intent(in) :: ncid,id,var_shape,nbox
    integer, optional :: iscalar
    integer, optional :: iarray(1:nbox)
    REALTYPE, optional :: scalar
    REALTYPE, optional :: array(1:nbox)
    REALTYPE, optional :: garray(1:nbox)
    REALTYPE, optional :: array2d(:,:)
    REALTYPE, optional :: array3d(:,:,:)
    ! Original author(s): Karsten Bolding & Hans Burchard
    ! Modifications: Marcello Vichi
    integer :: iret,n=0
    integer :: idum(1:nbox)
    REAL_4B :: r4,dum(1:nbox)

    my question is what can i do to prevent this fault??
  2. jcsd
  3. Nov 12, 2008 #2
    A segmentation fault usually means that you are trying to read or write to a memory location that you do not have the permission to do so. This usually translates to an array out of bourds situation, or calling a subroutine that is undefined. In certain cases, the memory location of the program has been inadvertently by data, and the program goes haywire.
    As your problem is not intermittent, my first guess is you have an undefined subroutine, or a jump to an undefined location.
    See if your compiler/linker has debug options to detect missing modules.
    If that is not the case, see if you have debug options to check array bounds during execution. It slows down execution, but gives you a better chance to find your problem.
    The definition of the variables gives very little hint. It is the program structure or the usage of arrays, that is causing the problem.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?