title: Saved variable in Module changes value when recalled in subroutine
body: <p>I am working with a FEM program written in Fortran language. It is a mechanical analysis that involves multiple set of material. The important variables are saved into modules that have the following form</p>
  
  <pre><code>MODULE element
    implicit none
    save
  
    TYPE proel_type
      INTEGER::  prop1
      INTEGER::  prop2
      REAL::     prop3
      REAL::     prop4
      ...
      INTEGER, ALLOCATABLE :: list1(:)
      REAL, ALLOCATABLE ::    array1(:)
      ...
      INTEGER::  LTYPE
      ...
    END TYPE proel_type
  
    TYPE(proel_type), ALLOCATABLE:: proel(:)
  
    INTEGER::  prop1
    INTEGER::  prop2
    REAL::     prop3
    REAL::     prop4
    ...
    INTEGER::  LTYPE
    INTEGER::  ISETS
    ...
  END MODULE element
  </code></pre>
  
  <p>As you can see, proel is an allocatable data structure that contains some information about the properties of the material, the element and so on. This data is taken from a text file through a I/O routine like</p>
  
  <pre><code>SUBROUTINE setdata
  USE element
  IMPLICIT NONE
  
  ALLOCATE(PROEL(NSETS))
  
  DO ISETS=1,NSETS
  
    ... ! here I am loading succefully the string variable STRVAR 
        ! from the text file with data
  
    LTYPE=GETVAL(STRVAR)    ! here I retreive the value of LTYPE
  
    PROEL(ISETS)%LTYPE=LTYPE ! here I save the (integer) variable for the set
  
    IF(LTYPE.NE.0)THEN
      CALL SETELM
    END IF
  END DO
  
  END SUBROUTINE
  </code></pre>
  
  <p>Inside subroutine SETELM I am setting some particular parameters used in the program, but at some point I recall LTYPE saved in PROEL</p>
  
  <pre><code>SUBROUTINE SETELM
  USE element
  IMPLICIT NONE
  
  LTYPE=PROEL(ISETS)%LTYPE
  
  SELECT CASE(LTYPE)
  
    CASE( 1)
      ...
    CASE( 2)
      ...
    CASE DEFAULT
      ...
  END SELECT
  END SUBROUTINE
  </code></pre>
  
  <p>Now, between the assignment LTYPE=PROEL(ISETS)%LTYPE and the SELECT CASE(LTYPE), the variable LTYPE changes value without any reason. The value is random (in the sense that I do not know where it comes from but it is not like uninitialized vars) and there are no others operations in the middle that work with LTYPE.</p>
  
  <p>I am working with VS2008 and Fortran, so I turned on every warning, but neither compilation nor runtime give some possible hint. </p>
  
  <p>Do you have any idea why is that happening?</p>