函数

时间:2018-06-12 07:07:35

标签: c++ fortran g++

我在Fortran有一个求解器。我的主文件是C ++。我在主文件中包含解算器头文件来调用Fortran中的求解器函数。 但是在编译代码时出现以下错误。

In file included from eph.cpp:12:0:
eph.cpp: At global scope:
radau.h:48:29: error: expected initializer before ‘radau_’
  #define RADAU FORTRAN_NAME(radau)
                             ^
radau.h:36:25: note: in definition of macro ‘FORTRAN_NAME’
 #define FORTRAN_NAME(x) x ## _
                         ^
eph.cpp:225:17: note: in expansion of macro ‘RADAU’
  void __stdcall RADAU(int *n,void *Function,double *x,double *y,double *xend,d

我附加主.cpp文件和头文件以供参考。

eph.cpp

#include <iostream>

#include <cmath>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
//#include <fortran.h>
//#include "StiffIntegratorT.h"
//#include "NonStiffIntegratorT.h"
#include "forceModelsHPOP.h";
extern "C"{
#include "radau.h";
}

using namespace std;

//inline void Function( double x, double y[][1],double y0[][1]);
//inline void Jacobian(double x, double *y, double **J);
//inline void Mass(double **M);

/*---------------------------------Main Accel---------------------------------------------*/

void Function(int *n,double *var,double *y,double *f,double *rpar,int *ipar)
{
    double Mjd_UTC = 51543.9583333335;
    double A = 29.0;
    double M = 1005.0;
    double Cr = 1.0;
//  double *secs = 86400.0;
    double x; 
    var = &x;
    double MJD_UTC;
    MJD_UTC = Mjd_UTC+x/86400.0; 

    double UT1_TAI,UTC_GPS,UT1_GPS,TT_UTC,GPS_UTC;
    double xp,yp,UT1_UTC,lod,dpsi,deps,dxp,dyp,TAI_UTC;
    IERS(xp,yp,UT1_UTC,lod,dpsi,deps,dxp,dyp,TAI_UTC,MJD_UTC,'l');
    timediff(UT1_TAI,UTC_GPS,UT1_GPS,TT_UTC,GPS_UTC,UT1_UTC,TAI_UTC);

    double year, month, day, hour, minute, sec;
    double DJMJD0, DATE;
    double JD = MJD_UTC+2400000.5;
    invjday(year, month, day, hour, minute, sec,JD);
    iauCal2jd(DJMJD0, DATE,year, month, day);

    double TIME = (60*(60*hour + minute) + sec)/86400;
    double UTC = DATE + TIME;
    double TT = UTC + TT_UTC/86400;
    double TUT = TIME + UT1_UTC/86400;
    double UT1 = DATE + TUT;

    double Pi[3][3],NPB[3][3];
    double sp, gast;
    sp = iauSp00(DJMJD0, TT);
    iauPom00(Pi,xp, yp,sp);
    iauPnm06a(NPB,DJMJD0, TT);
    gast = iauGst06(DJMJD0, UT1, DJMJD0, TT, NPB);

    double eye[3][3] = {{1,0,0},{0,1,0},{0,0,1}};
    double Theta[3][3];
    iauRz(gast, eye);

    for(int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            Theta[i][j] = eye[i][j];
//          cout << Theta[i][j] << endl;
        }
    }

    double res1[3][3],E[3][3];
    multiplyMat(Theta,NPB,res1);
    multiplyMat(Pi,res1,E);

    double MJD_TDB;
    double r_Mercury[3], r_Venus[3], r_Earth[3], r_Mars[3], r_Jupiter[3], r_Saturn[3], r_Uranus[3], \
                    r_Neptune[3], r_Pluto[3], r_Moon[3], r_Sun[3], r_SunSSB[3];
    MJD_TDB = Mjday_TDB(TT);

    JPL_Eph_DE436(r_Mercury, r_Venus, r_Earth, r_Mars, r_Jupiter, r_Saturn, r_Uranus, \
                            r_Neptune, r_Pluto, r_Moon, r_Sun, r_SunSSB, MJD_TDB);

    static double r_Sun1[3][1],r_Moon1[3][1],r_Earth1[3][1];
    static double r_Mercury1[3][1],r_Venus1[3][1],r_Mars1[3][1],r_Jupiter1[3][1],r_Saturn1[3][1],r_Uranus1[3][1], \
                    r_Neptune1[3][1],r_Pluto1[3][1],r_SunSSB1[3][1];
    static double VecInPos[3][1],VecInVel[3][1];

    for(int i = 0; i < 3; i++)
    {
        r_Sun1[i][0] = r_Sun[i];
        r_Moon1[i][0] = r_Moon[i];
        r_Mercury1[i][0] = r_Mercury[i];
        r_Venus1[i][0] = r_Venus[i];
        r_Mars1[i][0] = r_Mars[i];
        r_Jupiter1[i][0] = r_Jupiter[i];
        r_Saturn1[i][0] = r_Saturn[i];
        r_Uranus1[i][0] = r_Uranus[i];
        r_Neptune1[i][0] = r_Neptune[i];
        r_Pluto1[i][0] = r_Pluto[i];
        r_Earth1[i][0] = r_Earth[i];
        r_SunSSB1[i][0] = r_SunSSB[i];
    }

    for(int i = 0; i < 3; i++)
    {
        VecInPos[i][0] = y[i];
        VecInVel[i][0] = y[i+3];
//      cout << VecInPos[i][0] << endl;
    }

    static double aG[3][1],aSol[3][1],asRad[3][1],aRel[3][1],a[3][1];
    for (int i = 0; i < 3; i++)
    {
//      cout << setprecision(11) << r_Sun1[i][0] << endl;
    }

    AccelHarmonic_ElasticEarth(aG, MJD_UTC, r_Sun1, r_Moon1, VecInPos, E, UT1_UTC, TT_UTC, xp, yp);
//  cout << aG[0][0] << endl;

    static double a1[3][1], a2[3][1], a3[3][1], a4[3][1], a5[3][1], a6[3][1], a7[3][1], a8[3][1], a9[3][1], a10[3][1];
    static double aS[3][1], aM[3][1], aMe[3][1], aV[3][1], aMa[3][1], aJ[3][1], aSa[3][1], aU[3][1], aN[3][1], aP[3][1];

    for (int i = 0; i < 3; i++)
    {
//      cout << setprecision(11) << GM_Sun << endl;
    }

    AccelPointMass(a1,VecInPos,r_Sun1,GM_Sun);
    AccelPointMass(a2,VecInPos,r_Moon1,GM_Moon);
    AccelPointMass(a3,VecInPos,r_Mercury1,GM_Mercury);
    AccelPointMass(a4,VecInPos,r_Venus1,GM_Venus);
    AccelPointMass(a5,VecInPos,r_Mars1,GM_Mars);
    AccelPointMass(a6,VecInPos,r_Jupiter1,GM_Jupiter);
    AccelPointMass(a7,VecInPos,r_Saturn1,GM_Saturn);
    AccelPointMass(a8,VecInPos,r_Uranus1,GM_Uranus);
    AccelPointMass(a9,VecInPos,r_Neptune1,GM_Neptune);
    AccelPointMass(a10,VecInPos,r_Pluto1,GM_Pluto);

    AccelSolrad(aSol, VecInPos, r_Earth1, r_Moon1, r_Sun1, r_SunSSB1, A, M, Cr, P_Sol, AU, "cylindrical");

    Relativity(aRel, VecInPos, VecInVel);

    for(int i = 0; i < 3; i++)
    {
        aS[i][0] = aG[i][0] + a1[i][0];
        aM[i][0] = aS[i][0] + a2[i][0];
        aMe[i][0] = aM[i][0] + a3[i][0];
        aV[i][0] = aMe[i][0] + a4[i][0];
        aMa[i][0] = aV[i][0] + a5[i][0];
        aJ[i][0] = aMa[i][0] + a6[i][0];
        aSa[i][0] = aJ[i][0] + a7[i][0];
        aU[i][0] = aSa[i][0] + a8[i][0];
        aN[i][0] = aU[i][0] + a9[i][0];
        aP[i][0] = aN[i][0] + a10[i][0];
        asRad[i][0] = aP[i][0] + aSol[i][0];
        a[i][0] = asRad[i][0] + aRel[i][0];
    }

    for(int i = 0; i < 3; i++)
    {
        f[i] = VecInVel[i][0];
        f[i+3] = a[i][0];
//      cout << f[i+3] << endl;
    }

    cout << "y0 " << f[0] << endl;
//}
    return;
//  cout << xp << endl;
}

void Jacobian(int *n, double *x, double *y, double *dfy,
           int *ldfy, double *rpar, double *ipar)
{
    return;
}

void Mass(int *n,double *am, int *lmas,int *rpar, int *ipar)
{
    return;
}

void solout(int *nr,double *xold,double *x,
            double *y,
            double *cont,int *lrc,
            int *n,
            double *rpar,int *ipar,
            int *irtrn)
{
//  printf("Step %3i: t=%1.3e, y=(%1.3e,%1.3e)\n",*nr, *x,y[0],y[1]);
//  cout << "Step \t:" << *nr << "t= " << *x << "y = " << "(" << y[0] << ", " << y[1] << ")" << endl;
    return;
}

extern "C"
{
    void __stdcall RADAU(int *n,void *Function,double *x,double *y,double *xend,double *h, \
        double *rtol,double *atol,int *itol, \
        void *Jacobian,int *ijac,int *mljac,int *mujac, \
        void *Mass,int *imas,int *mlmas,int *mumas, \
        void *solout,int *iout, \
                double *work,double *lwork,double *iwork,double *liwork,double *rpar,int *ipar,int *idid);
}

int main()
{

#define ND     6
#define NS     7
#define LWORK  (NS+1)*ND*ND+(3*NS+3)*ND+20
#define LIWORK (2+(NS-1)/2)*ND+20

    double y[ND],work[LWORK];
    int iwork[LIWORK];
    double x,xend;
    int i,idid;

    /*(no) parameter in the differential equation*/
    double   rpar=0;
    /*dimension of the system*/
    int  n=6;
    /* compute the jacobian analytically */
    int ijac=0;
    /* jacobian is a full matrix*/
    int mljac=n;
    int mujac=0;
    /* differential equation is in explicit form*/
    int imas=0;
    int mlmas=0;
    int mumas;
    int ipar=0;
    /* output routine is used during integration*/
    int iout=0;

    /* required tolerance*/
    double rtol=1.0e-2;
    double atol=1.0e-6*rtol;
    int itol=0;
    /* initial step size*/
    double h=1.0e-6;

    int lwork=LWORK;
    int liwork=LIWORK;

    /* initial values*/
    x=0.0;
    y[0]=-23788115.6646;
    y[1]=34839281.8482;
    y[2]=-14387.644;
    y[3]=-2537.92541;
    y[4]=-1732.91352;
    y[5]=0.87796;

    /* endpoint of integration*/
    xend=1.0;
    /* set default values */
    for(i=0; i<20; i++){
        iwork[i]=0;
        work[i]=0.0;
    }

//  printf("\n**********\n* radau  *\n**********\n\n");

    RADAU(&n,Function,&x,y,&xend,&h,
        &rtol,&atol,&itol,
        Jacobian,&ijac,&mljac,&mujac,
        Mass,&imas,&mlmas,&mumas,
        solout,&iout,
        work,&lwork,iwork,&liwork,&rpar,&ipar,&idid);

    return (0);
}

标题:radau.h

#ifndef RADAU_H
#define RADAU_H

#ifdef CPP
extern C {
#endif

//#define INTEL_FORTRAN
/*#define IRIX*/                   /* MipsPro Compiler */
//#define SOLARIS                /* Sun Workshop Compiler */
#define Gplusplus                   

/* without underscore, upper case*/
#ifdef INTEL_FORTRAN
#define UPPERCASE
#define FORTRAN_NAME(x) x
#endif

/* with underscore, lower case*/
#ifdef IRIX  
#define FORTRAN_NAME(x) x ## _
#endif

/* with underscore, lower case*/
#ifdef SOLARIS  
#define FORTRAN_NAME(x) x ## _
#endif

/* with underscore, lower case*/
#ifdef Gplusplus
#define LOWERCASE
#define FORTRAN_NAME(x) x ## _
#endif


#ifdef UPPERCASE
#define RADAU FORTRAN_NAME(RADAU)
#define RADAU5 FORTRAN_NAME(RADAU5) 
#define CONTRA FORTRAN_NAME(CONTRA) 
#define CONTR5 FORTRAN_NAME(CONTR5)
#endif
#ifdef LOWERCASE
//#define RADAU FORTRAN_NAME(radau)
    #define RADAU FORTRAN_NAME(radau)
//#define RADAU5 FORTRAN_NAME(radau5)
//#define CONTRA FORTRAN_NAME(contra) 
//#define CONTR5 FORTRAN_NAME(contr5) 

#endif

解算器defn位于头文件的下一行。

0 个答案:

没有答案