title: Stack Overflow in Fortran program
body: <p>I have a problem with my simple Fortran program. I am working in Fortran 77, using Compaq Visual Fortran. The program structure must be in the form of a main and a subroutine, because it is part of a big program related to the finite element method.</p>
  
  <p>My issue is that I would like to set the values 10000 &amp; 10000 for <code>NHELE</code> and <code>NVELE</code> respectively, but when I run the code, the program stops and gives the following error:</p>
  
  <pre><code>forrt1: server &lt;170&gt;: program Exception - stack overflow
  </code></pre>
  
  <p>I've tried iteratively reducing the required values, until I reached 507 &amp; 507. At this point the code runs without errors.</p>
  
  <p>However, increasing the values to 508 &amp; 508 causes the same error to reappear.</p>
  
  <p>I think the problem is related to the subroutine <code>NIGTEE</code>, because when I rearrange the program without it, everything works fine.</p>
  
  <p>I've tried increasing the stack size to a maximum by using the menu <code>project&gt;&gt;settings&gt;&gt;link&gt;&gt;output&gt;&gt;reserve &amp; commit</code>
  but this didn't make a difference.</p>
  
  <p>How can I solve this problem?</p>
  
  <p>Here is my program:</p>
  
  <pre><code>PARAMETER(NHELE=508,NVELE=508)
  PARAMETER(NHNODE=NHELE+1,NVNODE=NVELE+1)
  PARAMETER(NTOTALELE=NHELE*NVELE)
  
  DIMENSION MELE(NTOTALELE,4)
  
      CALL NIGTEE(NHELE,NVELE,NHNODE,NVNODE,NTOTALELE,MELE)
  
  OPEN(UNIT=7,FILE='MeshNO For Rectangular.TXT',STATUS='UNKNOWN')
  WRITE(7,500) ((MELE(I,J),J=1,4),I=1,NTOTALELE)
  500 FORMAT(4I20)
  
      STOP
  END
  
    SUBROUTINE NIGTEE(NHELE,NVELE,NHNODE,NVNODE,NTOTALELE,MELE)
  DIMENSION NM(NVNODE,NHNODE),NODE(4)
  DIMENSION MELE(NTOTALELE,4)
  
  KK=0
  DO 20 I=1,NVNODE
  DO 20 J=1,NHNODE
  KK=KK+1
  NM(I,J)=KK
  20  CONTINUE
    KK=0
  DO 30 I=1,NVELE
  DO 30 J=1,NHELE
  NODE(1)=NM(I,J)
  NODE(2)=NM(I,J+1)
  NODE(3)=NM(I+1,J+1)
  NODE(4)=NM(I+1,J)
  KK=KK+1
  DO 50 II=1,4
  50  MELE(KK,II)=NODE(II)
  
  30  CONTINUE
    RETURN
  END
  </code></pre>
  
  <p>Thanks.</p>