Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Using pipes for unformatted read,write

Andrew_Smith
Valued Contributor I
664 Views

I have two applications communcating via pipes and re-directed standard input and standard output. However this only allows formated data. The reason for having commincationis because the front end is a 32 bit legacy application which will take years to convert to 64 bit. This comminicates with a new 64 bit application written in Fortran.

I want to use unformatted (binary) communication over the pipes. I think I am supposed to open a file on the pipe but how?

Andy

0 Kudos
3 Replies
Jugoslav_Dujic
Valued Contributor II
664 Views

I have two applications communcating via pipes and re-directed standard input and standard output. However this only allows formated data. The reason for having commincationis because the front end is a 32 bit legacy application which will take years to convert to 64 bit. This comminicates with a new 64 bit application written in Fortran.

I want to use unformatted (binary) communication over the pipes. I think I am supposed to open a file on the pipe but how?

Redirecting of STDIO/STDOUT is just a convenience. In this way, you can use standard Fortran READ(*) and WRITE(*) rather than relatively cumbersome ReadFile/WriteFile. With a "pure" Win32 API solution, you would use ReadFile/WriteFile to communicate through the pipe (as, mostly in the original example). Obviously, you cannot use FORM="Unformatted" or "Binary" on unit *, though.

To get the best of both worlds (flexibility of pipes and standard simple Fortran I/O), take a look at USEROPEN specifier of OPEN statement. It will allow you to OPEN a fortran unit but with a handle that you want -- and that will be an appropriate end of a named pipe (it should be named because it's the simplest way for two processes to open the same pipe, as you cannot share/redirect the handle anymore).

(If you couldn't get the job done with USEROPEN, or it turns out to be too complicated, you can always resort ro ReadFile/WriteFile.)

0 Kudos
Andrew_Smith
Valued Contributor I
664 Views
Quoting - Jugoslav Dujic

Redirecting of STDIO/STDOUT is just a convenience. In this way, you can use standard Fortran READ(*) and WRITE(*) rather than relatively cumbersome ReadFile/WriteFile. With a "pure" Win32 API solution, you would use ReadFile/WriteFile to communicate through the pipe (as, mostly in the original example). Obviously, you cannot use FORM="Unformatted" or "Binary" on unit *, though.

To get the best of both worlds (flexibility of pipes and standard simple Fortran I/O), take a look at USEROPEN specifier of OPEN statement. It will allow you to OPEN a fortran unit but with a handle that you want -- and that will be an appropriate end of a named pipe (it should be named because it's the simplest way for two processes to open the same pipe, as you cannot share/redirect the handle anymore).

(If you couldn't get the job done with USEROPEN, or it turns out to be too complicated, you can always resort ro ReadFile/WriteFile.)

Thanks for the advice.

It took a while to get right but I have named pipes working in 32 bit.

But the UserOpen function does not resolve during linking when I switch the project to 64 bit platform. I also notice that createFile and createNamedPipe both return 64 bit file handles, yet UserOpen expects a 32 bit handle.

Is the UserOpen option not available for 64 bit IVF?

Andy

0 Kudos
Steven_L_Intel1
Employee
664 Views

Hmm - looks as if we may have overlooked something here. I'll investigate.

0 Kudos
Reply