- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am trying to convert the C part of a C/Fortran mixed language program to pure Fortran. The C part essentially invokes several file I/O related win32 APIs. One such API is the CreateFile function. The snippet from the origional C code is as follows:
hFile = CreateFile (cname,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
From reading the definition for CreateFile, I understand that one can "combine" GENERIC_READ and GENERIC_WRITE flags, and I assume that "|" represents the combine operation. When I use the equivalent Fortran function defined in KERNEL32 module, how do I represent the combine operation? Is it an addition or something else?
Thanks for any help,
Jon
I am trying to convert the C part of a C/Fortran mixed language program to pure Fortran. The C part essentially invokes several file I/O related win32 APIs. One such API is the CreateFile function. The snippet from the origional C code is as follows:
hFile = CreateFile (cname,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
From reading the definition for CreateFile, I understand that one can "combine" GENERIC_READ and GENERIC_WRITE flags, and I assume that "|" represents the combine operation. When I use the equivalent Fortran function defined in KERNEL32 module, how do I represent the combine operation? Is it an addition or something else?
Thanks for any help,
Jon
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Fortran equivalent of the "|" operator is the IOR intrinsic function. Many people will use .OR. instead, and that will work, but is not standard-conforming as .OR. is defined for use on LOGICAL values only, and you're working with integers. (C does not make the distinction.)
That said, I will sometimes use .OR. when I am feeling lazy. The disadvantage of IOR is that it takes only two arguments so you'd have to write:
IOR(IOR(GENERIC_READ,GENERIC_WRITE),IOR(FILE_SHARE_READ,FILE_SHARE_WRITE))
You could instead use:
GENERIC_READ .OR. GENERIC_WRITE .OR. FILE_SHARE_READ .OR. FILE_SHARE_WRITE
Do not use addition for this, even though it may work in some cases.
That said, I will sometimes use .OR. when I am feeling lazy. The disadvantage of IOR is that it takes only two arguments so you'd have to write:
IOR(IOR(GENERIC_READ,GENERIC_WRITE),IOR(FILE_SHARE_READ,FILE_SHARE_WRITE))
You could instead use:
GENERIC_READ .OR. GENERIC_WRITE .OR. FILE_SHARE_READ .OR. FILE_SHARE_WRITE
Do not use addition for this, even though it may work in some cases.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
INTEGER FUNCTION MOR (f1, f2, f3, f4, f5, f6, f7, f8)
IMPLICIT NONE
INTEGER,INTENT(IN) :: f1, f2
INTEGER,INTENT(IN),OPTIONAL :: f3, f4, f5, f6, f7, f8
! IOR of multiple arguments, as supplied
MOR = IOR(f1, f2)
IF (.NOT.PRESENT(f3)) RETURN
MOR = IOR(MOR,f3)
IF (.NOT.PRESENT(f4)) RETURN
MOR = IOR(MOR,f4)
IF (.NOT.PRESENT(f5)) RETURN
MOR = IOR(MOR,f5)
IF (.NOT.PRESENT(f6)) RETURN
MOR = IOR(MOR,f6)
IF (.NOT.PRESENT(f7)) RETURN
MOR = IOR(MOR,f7)
IF (.NOT.PRESENT(f8)) RETURN
MOR = IOR(MOR,f8)
END FUNCTION MOR
IMPLICIT NONE
INTEGER,INTENT(IN) :: f1, f2
INTEGER,INTENT(IN),OPTIONAL :: f3, f4, f5, f6, f7, f8
! IOR of multiple arguments, as supplied
MOR = IOR(f1, f2)
IF (.NOT.PRESENT(f3)) RETURN
MOR = IOR(MOR,f3)
IF (.NOT.PRESENT(f4)) RETURN
MOR = IOR(MOR,f4)
IF (.NOT.PRESENT(f5)) RETURN
MOR = IOR(MOR,f5)
IF (.NOT.PRESENT(f6)) RETURN
MOR = IOR(MOR,f6)
IF (.NOT.PRESENT(f7)) RETURN
MOR = IOR(MOR,f7)
IF (.NOT.PRESENT(f8)) RETURN
MOR = IOR(MOR,f8)
END FUNCTION MOR
![](/skins/images/C4F7392A5C68ACA60290C9576F107044/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page