Problem with compiled gfortran read/write

Bill
2013-08-12
2013-08-20
  • Bill
    Bill
    2013-08-12

    I have an old fortran program that I have compiled many times using Microsoft Fortran Compiler 3.2. (Fortran 77). I am now trying to compile to run Windows 64 bit machine. I installed gfortran and am able to compile to a .exe.

    I had to comment out a couple of directive lines to prevent errors with gfortran:
    c $Storage:2
    c $NoFloatCalls

    Several issues that I need to address, but this is the first problem:

    When I launch the exe program, it looks like it should. I can enter the filename to read from and can enter the filename to write.

    Problem is, somehow the exe program output is overwriting my input file and therefore causes errors.

    Are there any know issues with read/write?

    Thanks,
    Bill

     
    • Kai Tietz
      Kai Tietz
      2013-08-13

      2013/8/12 Bill wjbzone@users.sf.net:

      I have an old fortran program that I have compiled many times using
      Microsoft Fortran Compiler 3.2. (Fortran 77). I am now trying to compile to
      run Windows 64 bit machine. I installed gfortran and am able to compile to a
      .exe.

      I had to comment out a couple of directive lines to prevent errors with
      gfortran:
      c $Storage:2
      c $NoFloatCalls

      Several issues that I need to address, but this is the first problem:

      When I launch the exe program, it looks like it should. I can enter the
      filename to read from and can enter the filename to write.

      Problem is, somehow the exe program output is overwriting my input file and
      therefore causes errors.

      Are there any know issues with read/write?

      Thanks,
      Bill

      Hello Bill,

      not that I am aware about such issues. For me it sounds more like your
      application is using input-file also as output. I am not a
      fortran-guru, but I will try to ask the maintainer of gfortran. He
      might be able to give some additional tips.

      Regards,
      Kai

       
    • Kai Tietz
      Kai Tietz
      2013-08-13

      Hallo Bill,

      I forward you the reply of Tobias Burnus (a maintainer of
      gnu-fortran). Hope this answer will help you:

      ht übersetzen
      Deaktivieren für: Englisch
      Hi Bill,

      Kai Tietz wrote:

      Kai, I am thinking the same thing ("it sounds more like your
      application is using input-file also as output") but the code has been
      used many times. In looking thru the code I do not see any obvious
      problem...

      The output file is opened using:
      OPEN(1,FILE=FILOUT,STATUS='NEW')

      The input file is opened using:
      OPEN(6,FILE=FILEN(NORUN))

      My guess is that you run into the following problem: Unit 6 is the
      output unit (stdout, output to the console/terminal). That's not only
      the case with gfortran, but with most Fortran compilers. (But not with
      all.)

      Using code like
      write(,) 'ABC'
      or
      print *, "Hello World"
      also goes to the output unit.

      If you use: open(6, file=...), all output to unit 6 goes into that
      file. For instance, with write(6,) 'I go to that file'. With Fortran
      66/77/90/95 it is implementation dependent whether the open(6,...
      also affects write(
      ,) or not. Since Fortran 2003, the Fortran
      standard requires that "open(output_unit, ..." not only affects
      "write(output_unit,..." but also "write(
      ,...". (output_unit is a
      constant ("parameter") defined in Fortran 2003's intrinsic module
      "iso_fortran_env" and has the value 6 with gfortran.)

      I assume that your previous compiler handled it differently: While 6
      probably also went to stdout (before the OPEN), it doesn't affect
      output to the "" unit ("write(,...", print ...). At least that's
      what happens by default with the Intel compiler - and I'd guess that
      also your MS compiler did likewise.

      While one can change the Intel compiler to gfortran's / Fortran 2003's
      behaviour, gfortran has no option to change it the * handling. I think
      the best would be to replace the unit 6 by some other unit. The
      general advice is to avoid single digit units (0 to 9). Common
      "special" units are: 0 error unit, 5 input unit and - as written above
      - 6 for the output unit.

       
      • Bill
        Bill
        2013-08-20

        Looks like you are correct. Single digit unit was the problem.
        I changed this:
        OPEN(1,FILE=FILOUT,STATUS='NEW')
        OPEN(6,FILE=FILEN(NORUN))
        to this
        OPEN(16,FILE=FILEN(NORUN))
        OPEN(17,FILE=FILOUT,STATUS='NEW')
        and all instances of:
        "read(6," to "read(16,)"
        "write(1," to "write(17"

        Problem solved.
        Thanks!!! Bill

        Now on the the next problem. Getting a NaN (Not A Number) value on a variable and it hangs up a loop. I think I can solve this problem.

         
  • Bill
    Bill
    2013-08-13

    Kai, I am thinking the same thing ("it sounds more like your
    application is using input-file also as output") but the code has been used many times. In looking thru the code I do not see any obvious problem...

    The output file is opened using:
    OPEN(1,FILE=FILOUT,STATUS='NEW')

    The input file is opened using:
    OPEN(6,FILE=FILEN(NORUN))

    I searched thru the fortran code for a Write statement directing output to 6 "write(6" , but have not found any thing yet. Still Looking...

    I need to learn to use the debug program, or add some temporary write(,) statements.

    Thanks for the reply.
    Bill