help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C/C++ question for dynamically linked .oct functions


From: E. Joshua Rigler
Subject: Re: C/C++ question for dynamically linked .oct functions
Date: Fri, 13 Jul 2001 08:15:35 -0600

I plan to eventually provide a nicer interface for the average user,
once I get this "back-end" interface working.  No matter what I do, it
is still necesary to convert CDF options (which must be strings in
Octave) to the appropriate long integer that the libCDF library uses to
specify what actions to take.

The CDF specification is quite complex.  If I simply write a separate
function for each possible type of request a user might make, I could be
looking at potentially hundreds of different functions (well, many
dozens anyway).  If I create a backend that essentially gives the Octave
user direct access to the libCDF library, then they have the flexibility
to do whatever they want to the CDF file, even if a specific function
hasn't been written to do exactly what they want.  Another benefit is
that now the "front-end" routines can all be written as *.m files, much
easier in my mind.

After much reading and thinking after my initial post, I've come to the
conclusion that I will simply have to reimplement the cdf.h file for
Octave, and associate strings with long integers (as opposed to using
macros), since there is no way I can use it (cdf.h) at anytime other
than compile time.  Thanks for the comments though, and if you have any
more suggestions, I'm all ears.

-EJR



Pascal Fleury wrote:
> 
> Why not replace the ugly calling method with nicer ones ?
> Like [Octave syntax]
> 
> octave:1> id = CDFLibOpen(filename)
> octave:2> A = CDFReadMatrix(id)
> octave:3> CDFLibClose(id)
> 
> Just a comment, I have no experience with CDF. But it would make it nicer to
> the Octave user than to the C lib user :-)
> Internally, in these functions (in the *.oct file) you can use the
> appropriate macro. So it is more a conversion to Octave than to C++ ...
> 
> Pascal
> 
> "E. Joshua Rigler" wrote:
> 
> > Maybe this is a hopeless question, but I'll ask anyway...
> >
> > I have a C library I'm trying to write an interface to in C++, so that I
> > can use it with Octave.  This C library does something I find odd, but
> > there's little I can do about it.  It has a single function that takes a
> > variable length argument list, and does different things based on what
> > arguments it is passed.  The odd part is that the arguments that
> > determine which actions are taken, and which inputs are required, are
> > supposed to be macros.
> >
> > For example:
> >
> >   CDFlib(OPEN_, CDF_, 'filename', &id)
> >
> > ...forces the CDFlib function to open a CDF file of name "filename", and
> > return the filehandle as a void pointer.  "OPEN_" is a macro that
> > expands to a long integer, and is defined in cdf.h.  Similarly, "CDF_"
> > is a macro that expands to a different long integer and is also defined
> > in cdf.h.
> >
> > Now, I want to pass strings from Octave to CDFlib.oct, so that the
> > interface would be more like:
> >
> >   id = CDFlib('OPEN_', 'CDF_', 'filename')
> >
> > where id is now an index of an element of a static array of filehandle
> > pointers within CDFlib.oct (this is necessary since Octave can't handle
> > a pointer data type).
> >
> > What I would like to do is simply convert the string into its macro.  I
> > realize that this is more-or-less impossible, since the macros are
> > expanded at compile time, but the alternative is to try to figure out
> > what each of the macros in cdf.h is supposed to expand to, and write a
> > huge conditional or switch statement to assign the proper long
> > integers.  This is not a desirable thing because 1) it would be a major
> > pain, and 2) I don't necessarily trust the macro expansions in cdf.h to
> > remain constant, but the macro names should.
> >
> > Any ideas?
> >
> > -EJR
> >
> > P.S. For those of you actually interested in what I'm working on, don't
> > worry about the non-intuitive nature of this interface.  It is only a
> > first step.  It will serve as a portal to the C CDF library for more
> > intuitive octave functions for manipulating CDF files.
> >



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]