Re: Code compilation with GCC and GFORTRAN

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



OK, to gcc-help it is. For some reason my mails sent from gmail were
bouncing back...

I have a input parsing fortran routine, which calls a c routine. Here
is part of the fortran routine. I have added print statements to show
the result:
***************************************
  subroutine parseinput()
     implicit none
     character(len=20) key
     logical done, getkey

     done = .false.
     do while (.not.done)

        done = .not.getkey(key)
        print*,"key done position 1 =",key,done

        if (key.eq.'done') then
           done = .true.
        else
           print*,"key done position 2 =",key,done
           if ((.not.done).and.(key.ne.' ').and.(key(1:1).ne.'#'))   &
           call error("getpar: key ("//key//") not recognized",-999,.false.)
        end if

     end do   !! enddo of "do while (.not. done)"
     print*,"end do while... end testing... stopping"
     stop
*********************************************************

Here is the 'getkey' c routine:
=====================

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define LINESIZE 120

int nstack = -1;
FILE *fstack[10];
char cbuffer[LINESIZE];
/* get a line from stdin and read first string as key */
int getkey_(key)
char key[];
{
        char *ckey = key, *ckeyinb;
        int i; long int noeof = 0;
        if (nstack == -1) { fstack[0] = stdin; nstack = 0; }
        /* clean the buffer */
        for (i=0;i<LINESIZE;i++) *(cbuffer+i) = ' ';
        for (i=0;i<20;i++) *(ckey+i) = ' ';
        /* prompt */
        if (isatty(fileno(fstack[nstack]))) printf("> ");
        /* get a line */
        if (fgets(cbuffer,LINESIZE,fstack[nstack])!=0) {
                if (sscanf(cbuffer,"%s",ckey)!=EOF) {
                        /* find key in buffer and erase it */
                        ckeyinb = strpbrk(cbuffer, ckey);
                        for (i=0;i<strlen(ckey);i++) *(ckeyinb+i) = ' ';
                }
                /* fill rest of key with spaces, so that .eq. works */
                for (i=strlen(ckey);i<20;i++) *(ckey+i) = ' ';
                noeof = 0xffffffffffffffff;
        }
        return(noeof);
}
============================

Here is my sample input 'in_testing' (The # signs are part of the input file)
================================
#####################################################################
#        INPUT DECK FOR 2D FREE SURFACE FLOWS USING MIXED METHOD    #
#####################################################################
title    channel flow
restart  off  !! restart from existing solutions
done
===================================

If I compile the code in the Ubuntu machine using gfortran and gcc,
'getkey' seem to compile OK. However, I get the following warning in a
different c routine, like this:
readarr.c:33: warning: ignoring return value of ‘fread’,declared with
attribute warn_unused_result

When I run the executable, I get the followings (never completes the
do while loop!):
./run <in_testing
 key done position 1 =#################### T
 key done position 2 =#################### T
 end do while... end testing... stopping

The 'done' became True just after parsing the first line!

Now, if I compile and run the same code either using intel compiler in
the same (Ubuntu) machine and/or  in the RedHat machine with different
version of gcc and gfortran, I get the following expected output. The
compilation does not give any warning either:

./run <in_testing
 key done position 1 =#################### F
 key done position 2 =#################### F
 key done position 1 =#                    F
 key done position 2 =#                    F
 key done position 1 =#################### F
 key done position 2 =#################### F
 key done position 1 =title                F
 key done position 1 =restart              F
 key done position 1 =done                 F
 end do while... end testing... stopping

(Please notice in the fortran routine that 'done' becomes True after
my print statement)

I hope it is detail enough.I wonder if I am missing any libraries in
the Ubuntu machine! If you need any specific info, please let me know.
Also, is there any way to check/verify whether I have all needed
libraries for gcc and gfortran?

Advance thanks!
Muhammad Akbar

On Thu, May 20, 2010 at 7:43 PM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote:
> Muhammad Akbar <mkakbar@xxxxxxxxx> writes:
>
>> I have a FORTRAN code that uses some c routines. I compile it with gcc
>> and gfortran in RedHat Linux without any problem. Recently I bought a
>> laptop with Ubuntu. I have gcc and gfortran version 4.4.3 in it. When
>> I compile the code, I see the following warning:
>>
>> warning: ignoring return value of 'fread', declared with attribute
>> warn_unused_result
>>
>> When I try to run the executable, it does not run as expected. Is
>> there any library
>> files that I am missing? Please help.
>> I am using the following flags:
>> gcc -c -O3 -DLINUX
>> gfortran -c -O3 -DLINUX -fdefault-real-8 -ffree-line-length-132
>>
>> By the way, I have installed Intel compilers, and the code runs fine
>> with icc and ifort. I am puzzled!
>
>
> Please never send messages to both gcc@xxxxxxxxxxx and
> gcc-help@xxxxxxxxxxxx  This message should only have gone to
> gcc-help@xxxxxxxxxxxx  Please take any followups to gcc-help.  Thanks.
>
> It is impossible for us to answer your question without more
> information, because you didn't tell us what you mean by "does not run
> as expected."  Also, if it runs on RedHat Linux but fails on Ubuntu,
> then it is probably not an issue with gcc.
>
> Ian
>


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux