This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Code compilation with GCC and GFORTRAN 4.4.3


Hello,
I wonder if anybody has a solution/suggestions to the problem I am
facing with gcc and gfortran 4.4.3. I am pasting all necessary files,
in case anybody wants to test it. I would much appreciate any
help/suggestions:

main.f90
==================
      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.
          print*,"key done position 2 =",key,done
       else
          print*,"key done position 3 =",key,done
          if ((.not.done).and.(key.ne.' ').and.(key(1:1).ne.'#'))   &
          print*,"key= ",key, " not recognized"
       end if

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

      end

getkey.c
=====================
#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);
}

Makefile
======================
SHELL =/bin/sh
COMMAND = run

OBJF90 = main.o
OBJC   = getkey.o

OBJS = $(OBJF90) $(OBJC)

CPROC = -DLINUX
FFLAGS = -O3 -DLINUX -fdefault-real-8 -ffree-line-length-132
CFLAGS = -O3

F90 = gfortran
CC  = gcc

$(COMMAND): $(OBJS)
        $(F90) $(FFLAGS) -o $(COMMAND) $(OBJS) $(LIBS)

.SUFFIXES:.f90
.f.o:
        $(F90) -c $(FFLAGS) $<
.f90.o:
        $(F90) -c $(FFLAGS) $<
.c.o:

        $(CC) -c $(CFLAGS) $(CPROC) $<
.f90.mod:
        $(F90) $(FFLAGS) -c $<

clean:
        rm -f core *.o *.l *.mod


input (save as a file)
==============
#####################################################################
#        INPUT DECK FOR 2D FREE SURFACE FLOWS USING MIXED METHOD    #
#####################################################################
title    channel flow
restart  off  !! restart from existing solutions
done


--------------------------------------
make and ./run <input

It gives me:
key done position 1 =#################### T
 key done position 3 =#################### T
 end do while... end testing... stopping

Why does 'done' become True after parsing the first line? The same
code works OK in intel compilers (ifort and icc) in the same machine,
and earlier GNU compilers in other machines. How do I figure out if my
gcc and gfortran installation is correct or not?

Advance thanks,
Muhammad Akbar






On Fri, May 21, 2010 at 6:58 AM, Muhammad Akbar <mkakbar@gmail.com> wrote:
> 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@google.com> wrote:
>> Muhammad Akbar <mkakbar@gmail.com> 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@gcc.gnu.org and
>> gcc-help@gcc.gnu.org. ?This message should only have gone to
>> gcc-help@gcc.gnu.org. ?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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]