title: Reading/Writing file and then creating .exe file in Fortran
body: <p>I am completely new to Fortran but have been given these files (see below) which reads an input text file, uses the Fortran code to calculate a set of values then writes them into an output text file. The programme works for all cases except Case 4, 8 and 11, producing the error:</p>
  
  <pre><code>forrtl: severe (24): end-of-file during read, unit 5, file C:\temp\sharclab\i_capa.txt
  
  Image              PC        Routine            Line        Source             
  Capacity.exe       0046B6EE  Unknown               Unknown  Unknown
  Capacity.exe       00468940  Unknown               Unknown  Unknown
  Capacity.exe       00411C9A  Unknown               Unknown  Unknown
  Capacity.exe       004118C7  Unknown               Unknown  Unknown
  Capacity.exe       0040C416  Unknown               Unknown  Unknown
  Capacity.exe       0040BBDA  Unknown               Unknown  Unknown
  Capacity.exe       0040714C  _MAIN__                    16  main.F90
  Capacity.exe       0046EB78  Unknown               Unknown  Unknown
  Capacity.exe       004528E0  Unknown               Unknown  Unknown
  kernel32.dll       7C817067  Unknown               Unknown  Unknown
  </code></pre>
  
  <p>I will post the code below and if anyone can help me solve this I would very much appreciate it, thank you!</p>
  
  <p>First file (only the particular parts that don't function):</p>
  
  <pre><code>Case (4)
  
      DiamRoul = abs(DonneesRlt(1))
      DiamPrim = abs(DonneesRlt(2))
      NbRoul = abs(int(DonneesRlt(3)))
      NbRangRoul = abs(int(DonneesRlt(4)))
      LongEff = abs(DonneesRlt(5))
  
      If ((NbRoul==0).OR.(DiamPrim==0)) Then
          CodeErr = 1
      else ! Calcul si nb corps roulants différent de zéro
  
          Gamma = DiamRoul / DiamPrim
  
          FC = 17.24553 * ((1 + (1.04 * ((1 - Gamma) / (1 + Gamma)) 
   &amp;      ** P1) ** P3) ** P4) * (((Gamma ** P2) * (1 - Gamma)  
   &amp;      ** P5) / ((1 + Gamma) ** P11))
  
          ChargeDynSNR = FC * ((NbRangRoul * LongEff) ** P6) 
   &amp;      * (NbRoul ** P7) * (DiamRoul ** P5) * 1.1293
  
          ChargeDynISO = FC * ((NbRangRoul * LongEff) ** P6)  
   &amp;      * (NbRoul ** P7) * (DiamRoul ** P5) * 1.1
  
          ChargeStaSNR = 4.4 * (1 - Gamma) * NbRangRoul * NbRoul 
   &amp;      * LongEff * DiamRoul
  
          ChargeStaISO = ChargeStaSNR   
  
      End If
  
  
  Case (8)
  
      DiamRoul = abs(DonneesRlt(1))
      DiamPrim = abs(DonneesRlt(2))
      NbRoul = abs(int(DonneesRlt(3)))
      LongEff = abs(DonneesRlt(4))
  
      If ((NbRoul==0).OR.(DiamPrim==0)) Then
          CodeErr = 1
      else  ! Calcul si nb corps roulants différent de zéro       
  
          Gamma = DiamRoul / DiamPrim
  
          FC = 34.48913 * 0.85 * (Gamma ** P2)
  
          ChargeDynSNR = FC * (LongEff ** P6) * (NbRoul ** P7) * 
   &amp;                      (DiamRoul ** P5) * 1
  
          ChargeDynISO = ChargeDynSNR
  
          ChargeStaSNR = 22 * (1 - Gamma) * NbRoul * LongEff 
   &amp;                      * DiamRoul
  
          ChargeStaISO = ChargeStaSNR
      End If
  
  Case (11)
  
      DiamRoul = abs(DonneesRlt(1))
      NbRoul = abs(int(DonneesRlt(2)))
      LongEff = abs(DonneesRlt(3))
      DiamPrim = abs(DonneesRlt(4))
      AngleDeg = 45
      AngleMin = 0
      AngleSec = 0
      NbRoul = abs(int(NbRoul / 2))
      NbRangRoul = 2
      DiamSpher = 0
  
      If (NbRoul==0) Then
          CodeErr = 1
      else ! Calcul si nb corps roulants différent de zéro
  
          Alpha = pi * (AngleDeg + (AngleMin / 60) + (AngleSec / 
   &amp;              3600)) / 180
  
          If (DiamPrim==0) Then
              DiamPrim = (DiamSpher - DiamRoul) * DCos(Alpha)
          End If
  
          Gamma = (DiamRoul * DCos(Alpha)) / DiamPrim
  
          FC = 17.24553 * ((1 + (1.04 * ((1 - Gamma) / (1 + Gamma)) 
   &amp;      ** P1) ** P3) ** P4) * (((Gamma ** P2) * (1 - Gamma)  
   &amp;      ** P5) / ((1 + Gamma) ** P11))
  
          ChargeDynSNR = FC * ((NbRangRoul * LongEff * DCos(Alpha)) 
   &amp;      ** P6) * (NbRoul ** P7) *   (DiamRoul ** P5) * 1.1
  
          ChargeDynISO = ChargeDynSNR
  
          ChargeStaSNR = 4.4 * (1 - Gamma) * NbRangRoul * NbRoul * 
   &amp;      LongEff * DiamRoul * DCos(Alpha)
  
          ChargeStaISO = ChargeStaSNR
      End If
  
  End Select  
  
  !     Arrondissement de toutes les charges calculées
  if (ChargeDynSNR.LE.0) then
      ChargeDynSNR = 0
      ChargeDynSNRArr = 0
  else
      Call Arron(TypeRlt, ChargeDynSNR, CapaArr)
      ChargeDynSNRArr = CapaArr
  end if
  
  if (ChargeDynISO.LE.0) then
      ChargeDynISO = 0
      ChargeDynISOArr = 0
  else
      Call Arron(TypeRlt, ChargeDynISO, CapaArr)
      ChargeDynISOArr = CapaArr
  end if
  
  if (ChargeStaSNR.LE.0) then
      ChargeStaSNR = 0
      ChargeStaSNRArr = 0
  else
      Call Arron(TypeRlt, ChargeStaSNR, CapaArr)
      ChargeStaSNRArr = CapaArr
  end if
  
  if (ChargeStaISO.LE.0) then
      ChargeStaISO = 0
      ChargeStaISOArr = 0
  else
      Call Arron(TypeRlt, ChargeStaISO, CapaArr)
      ChargeStaISOArr = CapaArr
  endif
  
      !     Toutes les charges calculées sont multipliées par 10.
  Charges(1) = ChargeDynSNR * 10
  Charges(2) = ChargeDynISO * 10
  Charges(3) = ChargeStaSNR * 10
  Charges(4) = ChargeStaISO * 10
  ChargesArr(1) = ChargeDynSNRArr * 10
  ChargesArr(2) = ChargeDynISOArr * 10
  ChargesArr(3) = ChargeStaSNRArr * 10
  ChargesArr(4) = ChargeStaISOArr * 10
  
  return
  END subroutine
  </code></pre>
  
  <p>Second file (main.F90):</p>
  
  <pre><code>program main
  implicit  none
  
  integer TypeRlt
      !   Entrees/Sorties
  real*8 DonneesRlt(15)
      !   Sorties 
  integer CodeErr
  real*8 Charges(4)
  integer ChargesArr(4)
  
  open (5, FILE='C:\temp\sharclab\i_capa.txt')
  open (6, FILE='C:\temp\sharclab\o_capa.txt')
  
  read(5,*) TypeRlt
  read(5,*) DonneesRlt
  
  write(*,*) TypeRlt
  write(*,*) DonneesRlt
  
  close(5)
  !TypeRlt = 5
  
  
  call Capacites(TypeRlt,DonneesRlt,Charges,ChargesArr,CodeErr)
  
  write(6,*) ChargesArr(1)
  write(6,*) ChargesArr(2)
  write(6,*) ChargesArr(3)
  write(6,*) ChargesArr(4)
  close(6)
  
  write(*,*) ChargesArr(1)
  write(*,*) ChargesArr(2)
  write(*,*) ChargesArr(3)
  write(*,*) ChargesArr(4)
  
  end
  </code></pre>
  
  <p>I apologise if the code hasn't been copied in properly..The two text files are simply a vertical list of values for which if there isn't 15 value present (required for this Fortran programme), a value of 0 is put in it's place.</p>
  
  <p>As this programme functions correctly for another cases (which I haven't posted here). I don't understand why it doesn't do the same for these cases..</p>