C++, Fortran Interfacing

On UNIX

On the Control System

Calling fortran subroutines from c++

In the c++ program:

  #include "forsubs.h"
  int vec_cur[9];
  vxgetn("CSR POS PKUA", 1, 9, vec_cur);
Where forsubs.h contains:
  #include "forstring.h"
  extern "C" {
   int vxgetn(const FORstring &mnem, const int &ele1, const int &ele2,
                   int *vec);
  }

Where forstring.h contains:

  #ifndef FORSTRINGS
  #include <string.h>
  #include <descrip.h>
  class FORstring : private dsc$descriptor_s{
  public:
   FORstring(){
    dsc$b_dtype = DSC$K_DTYPE_T;
    dsc$b_class = DSC$K_CLASS_S;
    dsc$w_length = 0;
    dsc$a_pointer = 0;
   }
   FORstring(char *s){
    dsc$b_dtype = DSC$K_DTYPE_T;
    dsc$b_class = DSC$K_CLASS_S;
    dsc$w_length = strlen(s);
    dsc$a_pointer = s;
   }
   FORstring &operator=(char *s){
    dsc$b_dtype = DSC$K_DTYPE_T;
    dsc$b_class = DSC$K_CLASS_S;
    dsc$w_length = strlen(s);
    dsc$a_pointer = s;
    return *this;
   }
   operator char *(){return dsc$a_pointer;}

   friend void Ctof(FORstring *fstr, char *s[], int numel){
    for(int i=0; i<numel; i++) fstr[i] = s[i];
   }
  };
  #define FORSTRINGS
  #endif
The previous is from Tom Pelaia's directory.
Mike Forster