gcc vs gfortran

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

gcc vs gfortran

Patrick Dupre-5
Hello,

Several times I called a fortran routine from a c program, it was OK.
I am trying to do the same with complex numbers in the call.
Is it a problem ?
in c, I use double complex
in f95, I use COMPLEX*16

my fortran cade translated to c by f2c does not work

I get a segmentation fault:
are the formats of the complex incompatible different?
Do I need to add a compilation option?

Thank.

===========================================================================
 Patrick DUPRÉ                                 | | email: [hidden email]
 Laboratoire interdisciplinaire Carnot de Bourgogne
 9 Avenue Alain Savary, BP 47870, 21078 DIJON Cedex FRANCE
 Tel: +33 (0)380395988
===========================================================================
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@...
Reply | Threaded
Open this post in threaded view
|

Re: gcc vs gfortran

Tom Horsley-5
On Fri, 6 Dec 2019 11:30:14 +0100
Patrick Dupre wrote:

> in c, I use double complex
> in f95, I use COMPLEX*16

Never heard of double complex in c.

Fortran passes all arguments by reference, so a fortran
routine that has a complex*16 arg probably needs something
like this in C

struct c16 {
   double real;
   double imag;
};

fortran_routine(struct c16* arg);

That would be my guess, anyway.
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@...
Reply | Threaded
Open this post in threaded view
|

Re: gcc vs gfortran

George N. White III
In reply to this post by Patrick Dupre-5


On Fri, 6 Dec 2019 at 06:31, Patrick Dupre <[hidden email]> wrote:
Hello,

Several times I called a fortran routine from a c program, it was OK.
I am trying to do the same with complex numbers in the call.
Is it a problem ?
in c, I use double complex
in f95, I use COMPLEX*16


Typo?  From f2c.h:

typedef struct { doublereal r, i; } doublecomplex;

my fortran cade translated to c by f2c does not work

I get a segmentation fault:
are the formats of the complex incompatible different?
Do I need to add a compilation option?

Thank.

===========================================================================
 Patrick DUPRÉ                                 | | email: [hidden email]
 Laboratoire interdisciplinaire Carnot de Bourgogne
 9 Avenue Alain Savary, BP 47870, 21078 DIJON Cedex FRANCE
 Tel: +33 (0)380395988
===========================================================================
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@...


--
George N. White III


_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@...
Reply | Threaded
Open this post in threaded view
|

Re: gcc vs gfortran

Patrick Dupre-5
 
 
On Fri, 6 Dec 2019 at 06:31, Patrick Dupre <[hidden email]> wrote:
Hello,

Several times I called a fortran routine from a c program, it was OK.
I am trying to do the same with complex numbers in the call.
Is it a problem ?
in c, I use double complex
in f95, I use COMPLEX*16
 
 
Typo?  From f2c.h:
 
typedef struct { doublereal r, i; } doublecomplex;
 
 
This is f2c, I tried to avoid to use this old package
now there is is a complex librairy in gcc
which has all the functions for the complex,
In my opinion, f2c is only recommanded when you use the converter f2c
Actually, f2c, is not capable to convert all the Frotran progams, and it does
not make a great job as soon as the code is a bit complex
 
 
my fortran cade translated to c by f2c does not work

I get a segmentation fault:
are the formats of the complex incompatible different?
Do I need to add a compilation option?

Thank.

===========================================================================
 Patrick DUPRÉ                                 | | email: [hidden email]
 Laboratoire interdisciplinaire Carnot de Bourgogne
 9 Avenue Alain Savary, BP 47870, 21078 DIJON Cedex FRANCE
 Tel: +33 (0)380395988
===========================================================================
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@...


--
George N. White III
 
_______________________________________________ users mailing list -- [hidden email] To unsubscribe send an email to [hidden email] Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/users@...

_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@...
Reply | Threaded
Open this post in threaded view
|

Re: gcc vs gfortran

Patrick Dupre-5
In reply to this post by Tom Horsley-5
Actually, this is what I have:

in C

double complex a, b, z
int lnchf ip
out = conhyp_ (&a, &b, &z, &lnchf, &ip) ;

In Fortran:
      FUNCTION CONHYP (A,B,Z,LNCHF,IP)

      INTEGER LNCHF,IP
      COMPLEX*16 CHGF,A,B,Z,CONHYP

And what I get is
A= b, B=z (the other values are wrong)
It means that the first variable (here a) is just lost
How can I fix this?


>
> > in c, I use double complex
> > in f95, I use COMPLEX*16
>
> Never heard of double complex in c.
>
> Fortran passes all arguments by reference, so a fortran
> routine that has a complex*16 arg probably needs something
> like this in C
>
> struct c16 {
>    double real;
>    double imag;
> };
>
> fortran_routine(struct c16* arg);
>
> That would be my guess, anyway.
> _______________________________________________
> users mailing list -- [hidden email]
> To unsubscribe send an email to [hidden email]
> Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
> List Archives: https://lists.fedoraproject.org/archives/list/users@...
>
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@...
Reply | Threaded
Open this post in threaded view
|

Re: gcc vs gfortran

Tom Horsley-5
On Fri, 6 Dec 2019 18:12:28 +0100
Patrick Dupre wrote:

> out = conhyp_ (&a, &b, &z, &lnchf, &ip) ;

I don't know what "out" is, but if the return type of
a fortran function is some struct-like object (which
complex might qualify as), I believe there is a
hidden first argument that is a pointer to the
place where the function stores the result (on the
other hand, I've delved into so many function argument
details while supporting my debugger, I may be remember
some completely different language conventions :-).
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@...
Reply | Threaded
Open this post in threaded view
|

Re: gcc vs gfortran

Jakub Jelinek
In reply to this post by Patrick Dupre-5
On Fri, Dec 06, 2019 at 06:12:28PM +0100, Patrick Dupre wrote:
> Actually, this is what I have:
>
> in C
>
> double complex a, b, z
> int lnchf ip
> out = conhyp_ (&a, &b, &z, &lnchf, &ip) ;

The above isn't very close to C, e.g. ; is missing at the end of first line,
, and ; are missing around ip on the second line and out is not declared.
More importantly, you haven't shown the declaration of conhyp_ nor
state which architecture this is on.  For complex I'm just guessing you have
#include <complex.h>.

> In Fortran:
>       FUNCTION CONHYP (A,B,Z,LNCHF,IP)
>
>       INTEGER LNCHF,IP
>       COMPLEX*16 CHGF,A,B,Z,CONHYP
>
> And what I get is
> A= b, B=z (the other values are wrong)
> It means that the first variable (here a) is just lost
> How can I fix this?

If the arguments are shifted, then most likely the first argument is a
hidden result.  It really depends on which architecture it is and how
_Complex double is returned there.

        Jakub
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@...
Reply | Threaded
Open this post in threaded view
|

Re: gcc vs gfortran

Patrick Dupre-5
OK, it is fixed,

I compiled with the option -ff2c
This was an error

> > in C
> >
> > double complex a, b, z
> > int lnchf ip
> > out = conhyp_ (&a, &b, &z, &lnchf, &ip) ;
>
> The above isn't very close to C, e.g. ; is missing at the end of first line,
> , and ; are missing around ip on the second line and out is not declared.
> More importantly, you haven't shown the declaration of conhyp_ nor
> state which architecture this is on.  For complex I'm just guessing you have
> #include <complex.h>.
>
> > In Fortran:
> >       FUNCTION CONHYP (A,B,Z,LNCHF,IP)
> >
> >       INTEGER LNCHF,IP
> >       COMPLEX*16 CHGF,A,B,Z,CONHYP
> >
> > And what I get is
> > A= b, B=z (the other values are wrong)
> > It means that the first variable (here a) is just lost
> > How can I fix this?
>
> If the arguments are shifted, then most likely the first argument is a
> hidden result.  It really depends on which architecture it is and how
> _Complex double is returned there.
>
> Jakub
> _______________________________________________
> users mailing list -- [hidden email]
> To unsubscribe send an email to [hidden email]
> Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
> List Archives: https://lists.fedoraproject.org/archives/list/users@...
>
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@...