Re: [ROOT] How to link fortran and c++

From: Andre Holzner (Andre.Holzner@cern.ch)
Date: Wed Apr 04 2001 - 09:53:17 MEST


Hi Wang,

are you sure herfasy_(..) takes four real*8 arguments ?
E.g. The usual 'real' under fortran is float& in c++
on i386 Linuxes.

Could you post the function header of herfasy.f ?

Which platform are you using ?

best regards,

André



Wang Xu wrote:
> 
> Dear Rooters,
>         I try to link a fortran code(herasy.f) to the c++ code. The
> fortran code by itself works fine but if it link to this c++ code, one of
> subroutine of the fortran code dosen't give a right answer. Have you ever
> met same problem? If you did, please give me some suggestion as soon as
> possible.
> (I suspicious that I didn't put correct flag when I complie these two
> code. what I did is following:
>  f77 -c herfasy.f *.f
>  g++ -c acceptance.cxx
>  g++ herfasy.o *.o acceptance.o -L/lib -l* -lg2c)
>         Thanks,
>         wang
> Here is the acceptance.cxx
> #include <stdio.h>
> #include <iostream.h>
> 
> // ROOT include
> #include "TROOT.h"
> #include "TFile.h"
> #include "TNtuple.h"
> #include "TMath.h"
> 
> extern "C" void herfasy_(double &,double &, double &,double &);
> 
> int main()
> {
>   TROOT accept("accept","accept");
>   TFile *f = new
> TFile("/work/halla/e95001-2/wangxu/hbook/eq05/gmn_1pass_21067.root");
> TNtuple *h1 = (TNtuple*) f->Get("h1");
>   Float_t  asyt,thetat, yt, phit, deltat;
>   double Enbeam,omega,thetas,asytt;
>   Int_t nbytes;
>   Enbeam=1.727;
>   Float_t Eset=1.453;
>   Float_t thed = 25.80;
>   // Set branch addresses
>   h1->SetBranchAddress("Ethetat",     &thetat);  // in mr
>   h1->SetBranchAddress("Ephit", &phit);          // in mr
>   h1->SetBranchAddress("Eyt",     &yt);          // in mm
>   h1->SetBranchAddress("Edelta", &deltat);      // in %
>   TFile *acceptance = new TFile("acceptance.root", "RECREATE");
>     TNtuple *ntuple = new TNtuple("ntuple", "Asymetry Study",
>      "Ethetat:Ephit:Eyt:Edelta:asyt");
>   // Total event number
>     //Int_t nentries = (Int_t) h1->GetEntries();
>    Int_t nentries=1;
>    for(Int_t i=0; i<nentries; i++) {
>     nbytes += h1->GetEvent(i);
>     thetas=acos(cos(thed*3.1415926/180+phit/1000)*cos(thetat/1000));
>     thetas= thetas*180/3.1415926;
>     omega=Enbeam-Eset*(1+deltat/100);
>     herfasy_(Enbeam,thetas,omega,asytt);
>     asyt=asytt;
>     printf("%f\n",asyt);
>    ntuple->Fill(thetat,phit,deltat,asyt);
>    }
>  ntuple->Write();
>   f->Close();
>   acceptance->Close();
>    return(0);
> }

-- 
------------------+----------------------------------
Andre Holzner     | +41 22 76 76750 
Bureau 32 2-C13   | Building 32     
CERN              | Office 2-C13    
CH-1211 Geneve 23 | http://wwweth.cern.ch/~holzner/



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:41 MET