comp.lang.ada
 help / color / mirror / Atom feed
* trying to call HDF5 from ada -- problems with constants
@ 2004-08-25 13:38 Christopher Broeg
  2004-08-25 16:35 ` Brian Catlin
  0 siblings, 1 reply; 9+ messages in thread
From: Christopher Broeg @ 2004-08-25 13:38 UTC (permalink / raw)


Hi,

I want to use HDF5 data format in my ada code. Since there is no ada 
binding available (tell me if there is!) I was just starting to do the c 
calls manually. Everything was fine until I needed the datatype 
constants, i.e. for H5Dcreate the type_id. The values of the constants 
is not visible in the corr. .h files in the example above:

H5Tpublic.h:
----------------------
#define H5T_STD_I32BE         (H5OPEN H5T_STD_I32BE_g)
H5_DLLVAR hid_t H5T_STD_I32BE_g;
----------------------
and in H5api_adpt.h:
----------------------
#if defined(_HDF5DLL_)
#pragma warning(disable: 4273)	/* Disable the dll linkage warnings */
#define H5_DLL __declspec(dllexport)
#define H5_DLLVAR __declspec(dllexport)
#elif defined(_HDF5USEDLL_)
#define H5_DLL __declspec(dllimport)
#define H5_DLLVAR __declspec(dllimport)
#else
#define H5_DLL
#define H5_DLLVAR extern
#endif /* _HDF5DLL_ */
----------------------

The only idea I could come up with was writing one c function for each 
constant and then linking to that c-library.
Is there no easier way? Besides, I'm not very good at c so I don't know 
how to compile libs in c.

I'd appreciate some help.

many thanks,

Chris.

---
Chrisopher Broeg
broeg~@astro.uni-jena.de (remove the ~)



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: trying to call HDF5 from ada -- problems with constants
  2004-08-25 13:38 trying to call HDF5 from ada -- problems with constants Christopher Broeg
@ 2004-08-25 16:35 ` Brian Catlin
  2004-08-26  8:04   ` Christopher Broeg
  0 siblings, 1 reply; 9+ messages in thread
From: Brian Catlin @ 2004-08-25 16:35 UTC (permalink / raw)


"Christopher Broeg" <broeg@astro.uni-jena.de~> wrote in message 
news:cgi4oa$o75$1@fsuj29.rz.uni-jena.de...
> Hi,
>
> I want to use HDF5 data format in my ada code. Since there is no ada binding 
> available (tell me if there is!)

A simple Google search reveals:

"Ada 95 bindings for the NCSA hierarchical data format"
http://portal.acm.org/citation.cfm?id=507581&jmp=references&coll=GUIDE&dl=ACM

I would contact the author (who works at Langley)

 -Brian


> I was just starting to do the c calls manually. Everything was fine until I 
> needed the datatype constants, i.e. for H5Dcreate the type_id. The values of 
> the constants is not visible in the corr. .h files in the example above:
>
> H5Tpublic.h:
> ----------------------
> #define H5T_STD_I32BE         (H5OPEN H5T_STD_I32BE_g)
> H5_DLLVAR hid_t H5T_STD_I32BE_g;
> ----------------------
> and in H5api_adpt.h:
> ----------------------
> #if defined(_HDF5DLL_)
> #pragma warning(disable: 4273) /* Disable the dll linkage warnings */
> #define H5_DLL __declspec(dllexport)
> #define H5_DLLVAR __declspec(dllexport)
> #elif defined(_HDF5USEDLL_)
> #define H5_DLL __declspec(dllimport)
> #define H5_DLLVAR __declspec(dllimport)
> #else
> #define H5_DLL
> #define H5_DLLVAR extern
> #endif /* _HDF5DLL_ */
> ----------------------
>
> The only idea I could come up with was writing one c function for each 
> constant and then linking to that c-library.
> Is there no easier way? Besides, I'm not very good at c so I don't know how to 
> compile libs in c.
>
> I'd appreciate some help.
>
> many thanks,
>
> Chris.
>
> ---
> Chrisopher Broeg
> broeg~@astro.uni-jena.de (remove the ~) 





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: trying to call HDF5 from ada -- problems with constants
  2004-08-25 16:35 ` Brian Catlin
@ 2004-08-26  8:04   ` Christopher Broeg
  2004-08-26 11:00     ` Jeff C,
  0 siblings, 1 reply; 9+ messages in thread
From: Christopher Broeg @ 2004-08-26  8:04 UTC (permalink / raw)


Brian Catlin wrote:
> "Christopher Broeg" <broeg@astro.uni-jena.de~> wrote in message 
> news:cgi4oa$o75$1@fsuj29.rz.uni-jena.de...
> 
>>Hi,
>>
>>I want to use HDF5 data format in my ada code. Since there is no ada binding 
>>available (tell me if there is!)
> 
> 
> A simple Google search reveals:
> 
> "Ada 95 bindings for the NCSA hierarchical data format"
> http://portal.acm.org/citation.cfm?id=507581&jmp=references&coll=GUIDE&dl=ACM
> 
> I would contact the author (who works at Langley)
> 
>  -Brian
> 

Thank you for your reply. Of course I read the article by B.R. 
Barkstrom. But the binding is no longer available. At first I was 
hesitant to bother the author directly, not wanting to bother him. But I 
will write him an email.

What is the standard way to import C constants that are not "constant" 
from one run to the next, but derived from some "invisible" library in 
the .h files?

Chris



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: trying to call HDF5 from ada -- problems with constants
  2004-08-26  8:04   ` Christopher Broeg
@ 2004-08-26 11:00     ` Jeff C,
  2004-08-26 11:46       ` Christopher Broeg
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff C, @ 2004-08-26 11:00 UTC (permalink / raw)



"Christopher Broeg" <broeg@astro.uni-jena.de~> wrote in message 
news:cgk5i0$cfu$1@fsuj29.rz.uni-jena.de...
> What is the standard way to import C constants that are not "constant" 
> from one run to the next, but derived from some "invisible" library in the 
> .h files?


If they really vary from one run to the next then I think you have no choice 
but to build bindings to C functions that return them. Alternatively 
assuming you have enough of the source you could recreate the code that 
builds
the constants via macros from C code.


If the constants vary from platform to platform but not run-to-run you can 
use an approach like AdaSockets does
where it builds the ada spec on the fly during the configure step using 
constants.sh and constants.c
(see the Adasockets distribution)
http://www.rfc1149.net/devel/adasockets 





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: trying to call HDF5 from ada -- problems with constants
  2004-08-26 11:00     ` Jeff C,
@ 2004-08-26 11:46       ` Christopher Broeg
  2004-08-26 18:29         ` Ludovic Brenta
  2004-08-26 19:20         ` Randy Brukardt
  0 siblings, 2 replies; 9+ messages in thread
From: Christopher Broeg @ 2004-08-26 11:46 UTC (permalink / raw)


Jeff C, wrote:
> "Christopher Broeg" <broeg@astro.uni-jena.de~> wrote in message 
> news:cgk5i0$cfu$1@fsuj29.rz.uni-jena.de...
> 
>>What is the standard way to import C constants that are not "constant" 
>>from one run to the next, but derived from some "invisible" library in the 
>>.h files?
> 
> 
> 
> If they really vary from one run to the next then I think you have no choice 
> but to build bindings to C functions that return them. Alternatively 
> assuming you have enough of the source you could recreate the code that 
> builds
> the constants via macros from C code.
> 
> 
> If the constants vary from platform to platform but not run-to-run you can 
> use an approach like AdaSockets does
> where it builds the ada spec on the fly during the configure step using 
> constants.sh and constants.c
> (see the Adasockets distribution)
> http://www.rfc1149.net/devel/adasockets 
> 
> 

tx. I just realized that with gnat I can import the constants directly. 
I realized that the ada specifications in the RM do never explicitly 
mention functions or procedures with respect to pragma import. So I did:

    H5T_STD_I32BE_g : Hid_t;
    pragma Import(C,H5T_STD_I32BE_g , "H5T_STD_I32BE_g");

and it works! All you have to do is call H5open manually, which is done 
automatically with the c preprocessor. Is this behaviour 
compiler-dependant, or ADA standard?

I'm surprised, because there was this long thread on this very topic 
explicitly stating that ada cannot import c constants... But I guess it 
only referred to preprocessor constants. All "variing" constants are of 
course real c constants visible in the library.

Thanx a lot for the reply.

Chris



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: trying to call HDF5 from ada -- problems with constants
  2004-08-26 11:46       ` Christopher Broeg
@ 2004-08-26 18:29         ` Ludovic Brenta
  2004-08-26 19:20         ` Randy Brukardt
  1 sibling, 0 replies; 9+ messages in thread
From: Ludovic Brenta @ 2004-08-26 18:29 UTC (permalink / raw)


Christopher Broeg writes:
> tx. I just realized that with gnat I can import the constants
> directly. I realized that the ada specifications in the RM do never
> explicitly mention functions or procedures with respect to pragma
> import. So I did:
>
>     H5T_STD_I32BE_g : Hid_t;
>     pragma Import(C,H5T_STD_I32BE_g , "H5T_STD_I32BE_g");
>
> and it works! All you have to do is call H5open manually, which is
> done automatically with the c preprocessor. Is this behaviour
> compiler-dependant, or ADA standard?

It is Ada standard, but the implementation depends on how well the Ada
compiler, C compiler, and linker get along with each other.  GNAT, GCC
and GNU ld get _very_ well along together :)

BTW, you can call H5open from within elaboration code if that helps
you, like this:

package P is
   pragma Elaborate_Body (P); -- force elaboration of the body (optional)

   H5T_STD_I32BE_g : Hid_t;
   pragma Import(C,H5T_STD_I32BE_g , "H5T_STD_I32BE_g");
end P;

package body P is
begin
   H5T_STD_I32BE_g := H5open;  -- elaboration code
end P;

The elaboration runs before your main subprogram.

> I'm surprised, because there was this long thread on this very topic
> explicitly stating that ada cannot import c constants... But I guess
> it only referred to preprocessor constants. All "variing" constants
> are of course real c constants visible in the library.

That's right, Ada cannot see preprocessor constants, she can only see
C's "static" variables.  This is really done by the linker.

-- 
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: trying to call HDF5 from ada -- problems with constants
  2004-08-26 11:46       ` Christopher Broeg
  2004-08-26 18:29         ` Ludovic Brenta
@ 2004-08-26 19:20         ` Randy Brukardt
  2004-08-27  0:54           ` Jeffrey Carter
  1 sibling, 1 reply; 9+ messages in thread
From: Randy Brukardt @ 2004-08-26 19:20 UTC (permalink / raw)


"Christopher Broeg" <broeg@astro.uni-jena.de~> wrote in message
news:cgkii4$lga$1@fsuj29.rz.uni-jena.de...
...
> tx. I just realized that with gnat I can import the constants directly.
> I realized that the ada specifications in the RM do never explicitly
> mention functions or procedures with respect to pragma import. So I did:
>
>     H5T_STD_I32BE_g : Hid_t;
>     pragma Import(C,H5T_STD_I32BE_g , "H5T_STD_I32BE_g");
>
> and it works! All you have to do is call H5open manually, which is done
> automatically with the c preprocessor. Is this behaviour
> compiler-dependant, or ADA standard?

Pragma Import on objects is standard (presuming interface to C is supported
by the implementation).
Since this object is going to be a constant in the Ada code, it's
unfortunate that you can't declare it that way:

    H5T_STD_I32BE_g : constant Hid_t;

but that lack of an explicit initializer makes it illegal. (I think an
implementation could support this if it wanted to - pragma Import can be a
completion - but I don't know if any do.)

> I'm surprised, because there was this long thread on this very topic
> explicitly stating that ada cannot import c constants... But I guess it
> only referred to preprocessor constants. All "variing" constants are of
> course real c constants visible in the library.

I certainly thought you were talking about preprocessor constants. I've
never seen a library level constant in C, so I never thought that you might
be talking about that. I suspect that is true of most of the people here.

             Randy.






^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: trying to call HDF5 from ada -- problems with constants
  2004-08-26 19:20         ` Randy Brukardt
@ 2004-08-27  0:54           ` Jeffrey Carter
  2004-08-27 11:32             ` Christopher Broeg
  0 siblings, 1 reply; 9+ messages in thread
From: Jeffrey Carter @ 2004-08-27  0:54 UTC (permalink / raw)


Randy Brukardt wrote:
> Since this object is going to be a constant in the Ada code, it's
> unfortunate that you can't declare it that way:
> 
>     H5T_STD_I32BE_g : constant Hid_t;
> 
> but that lack of an explicit initializer makes it illegal. (I think an
> implementation could support this if it wanted to - pragma Import can be a
> completion - but I don't know if any do.)

What? I've thought this has always been legal Ada 95. Certainly

package Import_Constant is
    I : constant Integer;
    pragma Import (C, I, "i");
end Import_Constant;

compiles without error (GNAT 3.15p/Win98).

-- 
Jeff Carter
"My legs are gray, my ears are gnarled, my eyes are old and bent."
Monty Python's Life of Brian
81




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: trying to call HDF5 from ada -- problems with constants
  2004-08-27  0:54           ` Jeffrey Carter
@ 2004-08-27 11:32             ` Christopher Broeg
  0 siblings, 0 replies; 9+ messages in thread
From: Christopher Broeg @ 2004-08-27 11:32 UTC (permalink / raw)


Thanx to all of you! You've been of great help.
Special thanks to ludovic brenta for the tip with elaborate body..

Everything seems to be working fine now. All that remains is finding
out the correct hdf-style constants for the native datatypes.

thanx a lot,

Chris



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-08-27 11:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-25 13:38 trying to call HDF5 from ada -- problems with constants Christopher Broeg
2004-08-25 16:35 ` Brian Catlin
2004-08-26  8:04   ` Christopher Broeg
2004-08-26 11:00     ` Jeff C,
2004-08-26 11:46       ` Christopher Broeg
2004-08-26 18:29         ` Ludovic Brenta
2004-08-26 19:20         ` Randy Brukardt
2004-08-27  0:54           ` Jeffrey Carter
2004-08-27 11:32             ` Christopher Broeg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox