Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    reassigning unit numbers in g77

    Hi everyone! I am dealing with an ancient and huge Fortran project that was being developed on various platforms for decades. I want to compile it with g77. My problem is that I/O units 5 and 6, which are by convention used for standard I/O, are in this code assigned to regular files, opened with OPEN statements. If I compile this with g77, the resulting executable encounters a segmentation fault when it tries to open a file and assign it to unit 6, because it is the console output. Since this unit number is accesed in thousands of places trough the code, I would like to avoid modifying the code, but instead somehow reassign unit numbers to make it possible to use units 5 and 6 for regular files. Is this possible? I know that I can redirect standard I/O using piping on the command line, but I would prefer a cleaner solution. Thanks!

  2. #2
    my first suggestion would be to use sed and regular expressions to replace all of the 5 and 6 unit numbers you talked about, simply because it is generally bad practice to use those unit numbers for files. sed would have no problem fixing thousands of cases for you, you just need to make sure you get the regular expression right so you don't change the numbers 5 and 6 to something else when they are in an actual number, like 3.567.

    that would be the "cleanest" fix. otherwise, you can rig some fix to associate stdin and stdout with some other unit numbers, but then the next guy that comes along is going to be sitting in the same boat you are.

    if you really want to change the number that stdin and stdout are associateed with, i dont know exactly how to do it, but you might try an open statement with the file "SYSIN" and "SYSOUT". these may be the filenames associated with 5 and 6, and you could maybe open them as files to associate them with different numbers.

    i haven't actually been able to try that, i dont have a FORTRAN 77 compiler on my machine any more, but that's what i would try first. If it doesn't work, check to make sure "SYSIN" and "SYSOUT" are actually the correct names.

  3. #3
    Thanks sirclif for your answer. I was thinking about regular expressions, but as I am not sure that I could list all possible contexts in which a unit number could appear and then write regular expressions that would certainly find everything, I would prefer to asociate stdin and stdout with something else. For example, a WRITE statement can have a unit number as the first argument, or it may appear later with 'UNIT=...', a unit number can also appear in CLOSE, REWIND and other statements, spaces are ignored in Fortran so maybe there is WRI TE in my code, or I may have UNI in columns 70-72, and NIT=6 in columns 7-11 of the next line. Things like these really appear in this code, I have seen them. So if I have to foresee all such things, I may as well write a compiler.

    So I tried with SYSIN and SYSOUT. These names appear on the Internet, but it seems that they are not parts of the Fortran 77 standard. I can open(98,'SYSIN'), but I think that the compiler thinks that SYSIN is a regular file, as the next line OPEN(6,'filename') leads to a segmentation fault. Also CLOSE(6) before all this leads to a segmentation fault.

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts