comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » EDG: Using IDL_MakeTempStruct() vs. IDL_ImportArray()
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
EDG: Using IDL_MakeTempStruct() vs. IDL_ImportArray() [message #90204] Tue, 10 February 2015 14:11 Go to next message
Peter Rodriguez is currently offline  Peter Rodriguez
Messages: 2
Registered: February 2015
Junior Member
Hi,

My objective is to create within C an IDL_TYP_STRUCT to be returned to IDL.

The EDG and Kling's book cover IDL_ImportArray(), but that costs me coding both for the C & IDL_STRUCT_TAG_DEF structures, so that data may be mapped.

I've been successful just using IDL_MakeTempStruct(strIDLdef, 1, &one, &vIDL, IDL_TRUE) having defined my strIDLdef and populating the structure manually via,
char *pIDL=vIDL->value.s.arr->data + IDL_StructTagInfoByName(strIDLdef,(char*)sTAG,IDL_MSG_LONGJM P,&vTAG);
Then employing CASE(vTAG->type) to stride and store within the data space appropriately.

However, upon return to IDL the structure fields are only accessible by index not tagname. Although the in-built tag_names() works!
IDL> o=my_make_struct("blablabla")
IDL> help,o
** Structure <743af8>, 7 tags, length=832, data length=830, refs=1:
sSCAN STRING 'PPI'
iANT_HGT_m INT 320
nSWEEPs LONG 3
fRAYres_deg FLOAT 0.500000
fBINres_km FLOAT 0.250000
fSWEEP_angle_deg_arr
FLOAT Array[40]
sSWEEP_ISO8601_arr
STRING Array[40]
IDL> help,o.sSCAN
% Tag name SSCAN is undefined for structure <Anonymous>.
% Execution halted at: $MAIN$
IDL> help,o.(0)
<Expression> STRING = 'PPI'
IDL> print,tag_names(o)
sSCAN iANT_HGT_m nSWEEPs fRAYres_deg fBINres_km fSWEEP_angle_deg_arr sSWEEP_ISO8601_arr

So as a work-around, I've written am IDL wrapper to rebuild/copy the structure based on determining the SIZE(/TYPE) of each field.

Does anyone have insight, how in C may I manually set each structure tagname string? The magic that IDL_ImportArray() apparently does... Something along the lines of tweaking vIDL->value.s.sdef I surmise because from the EDG "the implementation of structure definitions is not public information".

Thanks, Peter Rodriguez
Re: EDG: Using IDL_MakeTempStruct() vs. IDL_ImportArray() [message #90205 is a reply to message #90204] Tue, 10 February 2015 14:30 Go to previous messageGo to next message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
Hi Peter,

Here's some sample code from the TIFF module, where it is creating the "info" structure:

static IDL_STRUCT_TAG_DEF s_tags[] = {
{ "CHANNELS", 0, (void *) IDL_TYP_LONG },
{ "DIMENSIONS", dim_dims, (void *) IDL_TYP_LONG },
{ "HAS_PALETTE", 0, (void *) IDL_TYP_INT },
{ "IMAGE_INDEX", 0, (void *) IDL_TYP_LONG },
{ "NUM_IMAGES", 0, (void *) IDL_TYP_LONG },
{ "PIXEL_TYPE", 0, (void *) IDL_TYP_INT },
{ "TYPE", 0, (void *) IDL_TYP_STRING },
{ "BITS_PER_SAMPLE", 0, (void *) IDL_TYP_LONG },
{ "ORIENTATION", 0, (void *) IDL_TYP_LONG },
{ "PLANAR_CONFIG", 0, (void *) IDL_TYP_LONG },
{ "PHOTOMETRIC", 0, (void *) IDL_TYP_LONG },
{ "POSITION", dim_dims, (void *) IDL_TYP_FLOAT },
{ "RESOLUTION", dim_dims, (void *) IDL_TYP_FLOAT },
{ "UNITS", 0, (void *) IDL_TYP_LONG },
{ "TILE_SIZE", dim_dims, (void *) IDL_TYP_LONG },
{ "DESCRIPTION", 0, (void *) IDL_TYP_STRING },
{ "DOCUMENT_NAME", 0, (void *) IDL_TYP_STRING },
{ "DATE_TIME", 0, (void *) IDL_TYP_STRING },
{ "VERSION", 0, (void *) IDL_TYP_LONG },
{ 0 }
};

typedef struct {
IDL_LONG channels;
IDL_LONG dimensions[2];
IDL_INT has_palette;
IDL_LONG image_index;
IDL_LONG num_images;
IDL_INT pixel_type;
IDL_STRING type_str;
IDL_LONG bits_per_sample;
IDL_LONG orientation;
IDL_LONG planar_config;
IDL_LONG photometric;
float position[2];
float resolution[2];
IDL_LONG units;
IDL_LONG tile_size[2];
IDL_STRING description;
IDL_STRING document_name;
IDL_STRING date_time;
IDL_LONG version;
} ret_struct;

s_def = IDL_MakeStruct(0, s_tags); /* create the struct */
ret = (ret_struct *)
IDL_MakeTempStructVector(s_def, 1, &vpTmp,IDL_FALSE);


I'm not sure how much of this API is actually included in "idl_export.h", so you might be unsuccessful at getting this to compile. But hopefully it will give you a start!

Cheers,
Chris
Re: EDG: Using IDL_MakeTempStruct() vs. IDL_ImportArray() [message #90207 is a reply to message #90205] Tue, 10 February 2015 16:30 Go to previous messageGo to next message
Jim  Pendleton is currently offline  Jim Pendleton
Messages: 165
Registered: November 2011
Senior Member
On Tuesday, February 10, 2015 at 3:30:50 PM UTC-7, Chris Torrence wrote:
> Hi Peter,
>
> Here's some sample code from the TIFF module, where it is creating the "info" structure:
>
> static IDL_STRUCT_TAG_DEF s_tags[] = {
> { "CHANNELS", 0, (void *) IDL_TYP_LONG },
> { "DIMENSIONS", dim_dims, (void *) IDL_TYP_LONG },
> { "HAS_PALETTE", 0, (void *) IDL_TYP_INT },
> { "IMAGE_INDEX", 0, (void *) IDL_TYP_LONG },
> { "NUM_IMAGES", 0, (void *) IDL_TYP_LONG },
> { "PIXEL_TYPE", 0, (void *) IDL_TYP_INT },
> { "TYPE", 0, (void *) IDL_TYP_STRING },
> { "BITS_PER_SAMPLE", 0, (void *) IDL_TYP_LONG },
> { "ORIENTATION", 0, (void *) IDL_TYP_LONG },
> { "PLANAR_CONFIG", 0, (void *) IDL_TYP_LONG },
> { "PHOTOMETRIC", 0, (void *) IDL_TYP_LONG },
> { "POSITION", dim_dims, (void *) IDL_TYP_FLOAT },
> { "RESOLUTION", dim_dims, (void *) IDL_TYP_FLOAT },
> { "UNITS", 0, (void *) IDL_TYP_LONG },
> { "TILE_SIZE", dim_dims, (void *) IDL_TYP_LONG },
> { "DESCRIPTION", 0, (void *) IDL_TYP_STRING },
> { "DOCUMENT_NAME", 0, (void *) IDL_TYP_STRING },
> { "DATE_TIME", 0, (void *) IDL_TYP_STRING },
> { "VERSION", 0, (void *) IDL_TYP_LONG },
> { 0 }
> };
>
> typedef struct {
> IDL_LONG channels;
> IDL_LONG dimensions[2];
> IDL_INT has_palette;
> IDL_LONG image_index;
> IDL_LONG num_images;
> IDL_INT pixel_type;
> IDL_STRING type_str;
> IDL_LONG bits_per_sample;
> IDL_LONG orientation;
> IDL_LONG planar_config;
> IDL_LONG photometric;
> float position[2];
> float resolution[2];
> IDL_LONG units;
> IDL_LONG tile_size[2];
> IDL_STRING description;
> IDL_STRING document_name;
> IDL_STRING date_time;
> IDL_LONG version;
> } ret_struct;
>
> s_def = IDL_MakeStruct(0, s_tags); /* create the struct */
> ret = (ret_struct *)
> IDL_MakeTempStructVector(s_def, 1, &vpTmp,IDL_FALSE);
>
>
> I'm not sure how much of this API is actually included in "idl_export.h", so you might be unsuccessful at getting this to compile. But hopefully it will give you a start!
>
> Cheers,
> Chris

Peter,

It looks like you just need to ensure that the tag names in your C IDL_STRUCT_TAG_DEF are uppercase only. The interpreter isn't going to handle the mixed case that you're using presently.

Jim P.
Re: EDG: Using IDL_MakeTempStruct() vs. IDL_ImportArray() [message #90224 is a reply to message #90207] Thu, 12 February 2015 09:05 Go to previous message
Peter Rodriguez is currently offline  Peter Rodriguez
Messages: 2
Registered: February 2015
Junior Member
Yes, thank you, thank you Jim!

Funny how a nuance like that can derail things downstream.

In hindsight I do read in the EDG: char *name must be "Null-terminated uppercase name of the tag."

Hmm, it's an immutable string, so can't patch my code with toupper().
A simple vim command on my *.h file and a uppercase cast/check before IDL_StructTagInfoByName and I'm good.

Cheers, Peter
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Motley library on Sourceforge
Next Topic: Linux-like touch command in IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:19:08 PDT 2025

Total time taken to generate the page: 0.00427 seconds