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

What does getC do that standard Fortran can't?

Norman_K_
New Contributor I
565 Views

I am trying to read stdin in a CGI program being run by an Apache server, written in Fortran, called with POST and I have tried various forms of READ(* but cannot read even the first character.  But IFPORT function getC works a charm! So my questions:

What is it that getC does?

Can I do the same from standard Fortran, and if so, how?

Thanks in anticipation

N

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
565 Views

Fortran formatted READ is record-oriented, and wants a record with a line terminator. You should be able to get what you want if you open the file ACCESS='STREAM', FORM='UNFORMATTED' and read into a character variable (with an unformatted READ).

View solution in original post

0 Kudos
5 Replies
Eugene_E_Intel
Employee
565 Views

Hello,

How were you calling "read"?

Note: you may find the following interesting as a reference: http://flibs.sourceforge.net/fortran-fastcgi-nginx.html

I haven't tried it myself, but it looks similar, to what you are trying to do.

Thank you,

--Eugene

 

0 Kudos
Norman_K_
New Contributor I
565 Views

The web server is Apache in the form of XAMPP, straight out of the box on Windows 10 

I have been able to read environment variable correctly, so I am sure POST was 'used' by the calling HTML, then here are 5 attempts so far (they start !read) as well as the getC call that works. 

use, intrinsic     :: iso_fortran_env, only: input_unit, output_unit
use, non_intrinsic :: IFPORT
...
nin = input_unit
...
    if(IsLike(value,'POST')) then
        !How much content is waiting
        call GET_ENVIRONMENT_VARIABLE('CONTENT_LENGTH', value, length, status)
        ...
        read(value, *, iostat=my_iostat, iomsg=my_iomsg) ilen 
        ...
        !Try reading straight from stdin (none work)
        !read (nin, '(a)', iostat=my_iostat, iomsg=my_iomsg) value(1:ilen-1)
        !read (nin, *, iostat=my_iostat, iomsg=my_iomsg) value(1:ilen)
        !read (nin, *, iostat=my_iostat, iomsg=my_iomsg) value
        
        !Try one character at a time
        do i = 1, ilen
            my_iostat = getC(value(i:i)) ! WORKS! but requires USE IFPORT
            !read (nin, '(a1)', advance='NO', iostat=my_iostat, iomsg=my_iomsg) value(i:i)
            !read (nin, '(a1)', iostat=my_iostat, iomsg=my_iomsg) value(i:i)
            
            ...      
        end do

        write(nout,'(a)') 'Formatted read found value = "'//trim(value)//'"<br><br>'

I have a working solution, as shown above. It is just that I do not understand why!

Thanks

0 Kudos
Steve_Lionel
Honored Contributor III
566 Views

Fortran formatted READ is record-oriented, and wants a record with a line terminator. You should be able to get what you want if you open the file ACCESS='STREAM', FORM='UNFORMATTED' and read into a character variable (with an unformatted READ).

0 Kudos
Norman_K_
New Contributor I
565 Views

Dear Steve,

Your suggestion works, many thanks.

What I have learnt is that I can use OPEN on a preconnected channel (stdin) and specify things like access='stream' and form='unformatted' as you suggest, this may be more widely useful than just this post on the forum.

BW

0 Kudos
Steve_Lionel
Honored Contributor III
565 Views

Glad to have helped.

0 Kudos
Reply