- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a large program that reads in an input file that contains a list of additional input files and a unit number. I like to change the code so that it can take advantage of the Fortran 2008 NEWUNIT feature, but this always sets the unit number to a negative value. This is a problem because the code decides what features to employ based on a unit number being greater than zero.
Is there anyway to have something as the following:
[fortran]
LOGICAL::OPENFILE
...
IUNIT=0
IF(OPENFILE) OPEN(NEWUNIT=IUNIT,FILE='TEMP.txt')
[/fortran]
But have the unit number stored in IUNIT be greater than zero (i.e. IUNIT>0 if opened)
If this is not possible, it would be a great feature to employ in future versions of the Intel compiler because due to the complexity of the code it would be virtually impossible to change it from IF(IUNIT>0) to IF(IUNIT/=0).
Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
NEWUNIT being negatice appaers to be part of the rational of the new feature and is what the standard prescribes. There are many ways you can go this, for example make a ultilty routine wrappers around open and close that track avialable units for example.
"virtually impossible to change it from IF(IUNIT>0) to IF(IUNIT/=0)." not an imposibility just some work!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Note that the F2008 standard requires that the unit number that comes back with the NEWUNIT specifier be a negative number. You can also get valid negative numbers for unit numbers in other ways too.
Edit: beaten to the punch...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would say its pretty much inpossible given financing for the software and value of time. IUNIT is actually a vector of length 50 that gets sent to subroutines that set it to scalar variables that get passed to additional subroutines and the choas dominos from there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So does the code currently work, and if so why do you want to change it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Though the number of test for IUNIT may be large and disbursed throught the program, the number of places where you use OPEN and CLOSE may be small. If this is the case, the consider creating converter functions, the one to insert into the table strips the sign bit off the returned NEWUNIT number from OPEN, and one that propagates the next to sign bit to sign bit for the CLOSE/INQUIRE. This will have a minimal restriction of reducing the numbers of + or - unit numbers to 1 billion each (using 32-bit integer unit number).
Personally I would fix the test points. Perhapse insert a logical function for test (IF(isOpen(UnitTable)) ...)
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use the INQUIRE, OPENED option instead of relying on a specific value of a unit number.
If that would help. I imagine the negative value for NEWUNIT is a compiler option -- other compilers might do it differently.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
lklawrie wrote:Actually, the Fortran 2008 standard controls the allowable values of NEWUNIT
I imagine the negative value for NEWUNIT is a compiler option -- other compilers might do it differently.
9.5.6.12 NEWUNIT= specifier in the OPEN statement
1 The variable is defined with a processor determined NEWUNIT value if no error occurs during the execution of the OPEN statement. If an error occurs, the processor shall not change the value of the variable.2 A NEWUNIT value is a negative number, and shall not be equal to -1, any of the named constants ERROR_UNIT, INPUT_UNIT, or OUTPUT_UNIT from the intrinsic module ISO FORTRAN ENV (13.8.2), any value used by the processor for the unit argument to a defined input/output procedure, nor any previous NEWUNIT value that identifies a file that is connected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, have not memorized the F2008 standard.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page