0

I have a fortran subroutine called SNOW3L that takes several variables as intent in (see code below).

When I print the variables passed in this routine (INTG1, INTG2, CHAR1, ARR1 and ARR2), the values of INTG1, INTG2 and CHAR1 are OK and corresponds to the value of these variables before entering the routine. However, printing ARR1, ARR2 returns the following error : *"Segmentation fault - invalid memory reference" *

The code however works when I define the dimension of the intent(in) arrays (==> REAL, DIMENSION(KSIZE), INTENT(IN)).

Does anybody know why do I have such an error when the dimension of the intent(in) arrays are not explicitely defined ?

Thank you.

N3L

SUBROUTINE SNOW3L(INTG1,INTG2,CHAR1,ARR1,ARR2) 

   IMPLICIT NONE

   INTEGER, INTENT(IN) :: INTG1,INTG2
   CHARACTER(LEN=*),     INTENT(IN)    :: CHAR1
   REAL, DIMENSION(:), INTENT(IN) :: ARR1, ARR2

..................................................

Ian Bush
  • 6,996
  • 1
  • 21
  • 27
Teteh
  • 9
  • 2
  • Is the subroutine in a module or not? Also please show to code that calls the sub. Are any of the arrays allocatable in this case? – John Alexiou May 25 '23 at 12:04
  • [Reopen] The linked answer deals with the proper way to call a subroutine with or without an explicit interface description. But the _op_ is asking about array arguments and their size info. – John Alexiou May 25 '23 at 12:28
  • 1
    @JohnAlexiou the most likely reason why the OP gets segmentation faults why trying to access the arrays in the routine is because they doesn't use the routine through an explicit interface, and this is precisely what the linked question is dealing with. – PierU May 25 '23 at 12:36
  • @PierU - this is somewhat of an assumption at this point. I think the _op_ needs to [edit] the question and clarify those points and **then** if that is the case maybe there is a case to be made this a duplicate. IMHO this question was closed prematurely. – John Alexiou May 25 '23 at 14:10
  • Regardless of whether the question is a duplicate, @JohnAlexiou, noting that the question asker voted to close it as such: if the question needs an [edit] to clarify points then it's not at a point where a reopen vote is useful. (I voted to leave closed rather than unilaterally reopening for this reason.) If the question is clear and can be answered in a way a duplicate does not cover, then I'd be happy to reopen it. FWIW, the duplicate is as good as guess as any, especially when confirmed by the OP. – francescalus May 25 '23 at 15:30
  • @francescalus - the question needs clarification and might be a typo. There is **no** indication it is duplicate, other than conjecture. A subroutine lacking an interface does not necessarily result in a segmentation fault. – John Alexiou May 25 '23 at 16:45
  • @JohnAlexiou, "the question needs clarification and might be a typo" suggests that we both agree that the question is not ready to be reopened. Yes, I wouldn't have closed as a duplicate on such a conjecture, but that's not a good reason to re-open it. And there's one indication it's truly a duplicate: the person who asked the question voted to close it as such. – francescalus May 25 '23 at 16:56

0 Answers0