Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26758 Discussions

What does getC do that standard Fortran can't?

Norman_K_
New Contributor I
152 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
Black Belt Retired Employee
152 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

5 Replies
Eugene_E_Intel
Employee
152 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

 

Norman_K_
New Contributor I
152 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

Steve_Lionel
Black Belt Retired Employee
153 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

Norman_K_
New Contributor I
152 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

Steve_Lionel
Black Belt Retired Employee
152 Views

Glad to have helped.

Reply