Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

File Direct Acces Problem

orhun
Beginner
1,066 Views
Hi,

I am having some trouble porting a Microsoft Fortran code to Intel Fortran. I am by no means a Fortran expert so go easy on me :)

I am using Intel Fortran Compiler for 32-bit applications, Version 7.1 Build 20031229Z, under VS 2003, WinXP.

My code is (greatly simplified)

program tomtest
CHARACTER*127 MONTH

OPEN(70,FILE='ORHUN.TXT',FORM='FORMATTED',ACCESS='DIRECT', RECL=256)

MONTH = 'AUGUST'
WRITE(70,101) MONTH
101 FORMAT(A8)
end program tomtest


and on runtime I am getting

Input/Output Error 119: ACCESS conflict
In Procedure: main program
At Line: 27
Statement: Formatted WRITE
Unit: 70
Connected To: ORHUN.TXT
Form: Formatted
Access: Direct
Nextrec: 1
Records Read : 0
Records Written: 0
End of diagnostics


Now I know "WRITE(70,101) MONTH" statement is not a direct access statement and I can add "REC=WHATEVER" (and I did and it works) but the "Intel Fortran Programmers Reference" (Direct Access section) tells me that

"If REC= is not specified:
The WRITE statement outputs to the record at the position of the file pointer, and the file pointer is advanced to the next record."

but Error 119 states otherwise in
"Intel Fortran Compiler for Windows System User`s Guide" (Input/Output Errors)

So please someone help to figure out what is wrong with the code.

Thanks in advance.
0 Kudos
8 Replies
Steven_L_Intel1
Employee
1,066 Views

I suspect that the documentation is confusing in this regard - leaving out the REC= makes it a sequential WRITE which is disallowed for direct access. The 8.0 documentation is clearer on this.

The code is wrong - you will have to fix it to add the REC=, or, if you don't want direct access, remove ACCESS='DIRECT'.

It is not clear to me why you are using ACCESS='DIRECT' - if it is to eliminate record delimiters, consider FORM='BINARY' instead.

0 Kudos
orhun
Beginner
1,066 Views
Thanks for your quick answer.

I am not sure why ACCESS='DIRECT' has been used but some (if not most) of the WRITE statements depend on this questionable (default?) behaviour, in the code I am trying to compile with Intel. (It has been developed under MS Fortran Power Station)

I do not have access to 8.0 documentation now but I`ll check what it says on this issue, as soon as I can.
0 Kudos
Steven_L_Intel1
Employee
1,066 Views
I don't think you can do this in 7.1, but in 8.0, you can:
Add the /fpscomp:general option to your settings. (Right click on project name, select Properties, Fortran, Compatibility, Other PowerStation, Yes. Then you'll get the behavior you want.

Message Edited by sblionel on 08-27-2004 05:03 PM

0 Kudos
orhun
Beginner
1,066 Views
Yes, it took me some time to remember 8.0 has some Power Station compatibility settings, and I tried it a couple minutes ago, and it worked.

But unfortunately, there is a behaivour that the current code depends on and 8.0 compatibility settings does not cover.

And that is "short circuiting". This is the reason why I had to stay at 7.1 and could not upgrade to 8.0, in the first place. (we had this discussion some months ago)

Well, now it is time to decide and figure out which is easier to identify and fix 'short-ciruiting or REC behaviour'

If anyone has some suggestions on how to identify 'short-circuit' depended if statements, other than checking each if statement by hand please (I say it again please) send me an email.

Thanks.
0 Kudos
keefer
Beginner
1,066 Views
Hi,
I use direct access files a lot. I don't believe that they can be "Formatted" or that an I/Ostatement to one can specify a format. Their whole purpose is to allow fast, random access to data on disk. This is achieved by using fixed length records which don't require end-of-record markers and do require the user to keep track of the number of records written and which record contains the data one wishes to access. The user basically just specifies a block of some number of bytes (or words) and transfers the Nth block to or from the disk to RAM. The run time system does look at any of the bytes, nor buffer it (although the OS may effectively buffer the file). And it is up to the user to interpret what each byte means, i.e, is it a character in a string or a portion of a numeric variable.
Although you have probably already done so, I suggest that you use a different file format, especially if you need format control and/or process the file sequentially. Let Fortran do the housekeeping/bookkeeping work for you.
Regards,
Keith
0 Kudos
Steven_L_Intel1
Employee
1,066 Views
Formatted, direct access works fine. With direct access, you always have to specify a RECL, so it always knows exactly how many bytes to read or write. The MS compiler wrote a record terminator anyway, in addition to the specified RECL = in Visual Fortran, you can get that behavior with /fpscomp:general.
0 Kudos
keefer
Beginner
1,066 Views
Steve and "obirsoy",
Mea culpa. In the future I will be sure to RTFM ("F" stands for "Fortran"), before, rather than after offering advice. My statement is true for earlier versions of some compilers, back when Fortran code was much more aligned with machine capabilities, which were also much more limited. One of the big advantages of direct access I/O was that no temporary copy of the record was required, as would seem (I speculate) to be the case with formatted I/O, reducing the amount of core (aka RAM today) required.
My appolgies to both of you.
Regards,
Keith
(P.S. Thanks for not just telling me to mind my own business.)
0 Kudos
Steven_L_Intel1
Employee
1,066 Views
I don't know how "early" you want to go, but formatted, direct access is a standard part of Fortran 77. I'd have to go look at a F66 standard to see what it said - F66 didn't have OPEN but it did define direct access. I don't recall if DEFINE FILE was part of F66 or not.
0 Kudos
Reply