title: Fortran 90: signal SIGSEGV: Segmentation fault - invalid memory reference
body: <p>The code I have written below compiles fine using GFORTRAN, however when I run the executable, the terminal window returns...</p>
  
  <pre><code>Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
  
  Backtrace for this error:
  #0  0x7FC1D0F93697
  #1  0x7FC1D0F93CDE
  #2  0x7FC1D048E3EF
  #3  0x7FC1D05AF392
  #4  0x7FC1D1058360
  #5  0x400CBA in MAIN__ at TRANS2DATUM.f90:?
  Segmentation fault (core dumped)
  </code></pre>
  
  <p>The code is as follows</p>
  
  <pre><code>PROGRAM TRANSLATE
  
         IMPLICIT NONE 
  
            REAL, ALLOCATABLE :: X(:), Y(:), Z(:)
            INTEGER, ALLOCATABLE ::  NID(:)
  
            REAL     MINVALUE
            INTEGER  i, NUMA
  
            OPEN(1,FILE='NODE_original.dat',STATUS='OLD')
            OPEN(2,FILE='NODE_trans.dat',STATUS='NEW')
  
  10        READ(1,*,END=100)NID(i), X(i), Y(i), Z(i)
  
            i=i+1
            GOTO 10
  
  100       CONTINUE
            NUMA=i
  
            ALLOCATE (NID(NUMA),X(NUMA),Y(NUMA),Z(NUMA))
  
  !       Find the z value that should be zero
            MINVALUE=Z(1)
            DO i = 1, NUMA
               If ( i .EQ. 1) GOTO 11
               If (Z(i) .LE. Z(i-1)) THEN 
                    MINVALUE=Z(i)
               Else
               END IF
  
  11           CONTINUE             
            END DO
            WRITE(*,*) "MINIMUM Z DIMENSION IS: ",MINVALUE
  
            IF (MINVALUE .EQ. 0) GOTO 12
            WRITE(2,*)"*NODES, NSET=NBRICK"
            DO i = 1, NUMA
               Z(i) = Z(i) - MINVALUE
               WRITE(2, 1002) NID(i), X(i), Y(i), Z(i)
            END DO 
  
  
  
  1002     FORMAT(I10,3(",",F12.5))
  12       WRITE(*,*) "ERROR: MINIUMUM VALUE ALREADY ZERO NO TRANSLATION REQUIRED"
           STOP
  
  END PROGRAM
  </code></pre>
  
  <p>When I use this command as recommended in one of the comments below:</p>
  
  <pre><code>gfortran -o -g -Wall -fcheck=all  T2DATUM TRANS2DATUM.f90
  </code></pre>
  
  <p>I get the following </p>
  
  <pre><code>T2DATUM: In function `_fini':
  (.fini+0x0): multiple definition of `_fini'
  /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o:(.fini+0x0): first defined here
  T2DATUM: In function `data_start':
  (.data+0x0): multiple definition of `__data_start'
  /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o:(.data+0x0): first defined here
  T2DATUM:(.rodata+0x8): multiple definition of `__dso_handle'
  /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o:(.rodata+0x0): first defined here
  T2DATUM:(.rodata+0x0): multiple definition of `_IO_stdin_used'
  /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o:(.rodata.cst4+0x0): first defined here
  T2DATUM: In function `_start':
  (.text+0x0): multiple definition of `_start'
  /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o:(.text+0x0): first defined here
  T2DATUM: In function `_init':
  (.init+0x0): multiple definition of `_init'
  /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o:(.init+0x0): first defined here
  /tmp/ccbWNZCJ.o: In function `main':
  TRANS2DATUM.f90:(.text+0x1205): multiple definition of `main'
  T2DATUM:(.text+0xc43): first defined here
  /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
  T2DATUM:(.data+0x8): first defined here
  /usr/bin/ld: error in T2DATUM(.eh_frame); no .eh_frame_hdr table will be created.
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>But I have no idea what any of this means </p>
  
  <p>What is causing this issue? </p>
  
  <p>I am thinking it is to do with the allocatable arrays? I was hoping to use dynamic arrays because I don't have to recompile everytime I need to change the size of the arrays. Is this the best way of doing this?</p>
  
  <p>Thanks for any help.  </p>