예제 #1
0
파일: IDLStruct.cpp 프로젝트: esheldon/misc
IDL_VPTR IDLStruct::vget(const char *name)
{

  IDL_VPTR tmp;
  UCHAR *p;
  char message[80];
  static int tag_index;

  // Does this tag exist?  This is the bottleneck, by far
  // Better for the user to find the index ahead of time
  // Slightly faster than doing the ful getRefFromIDLStrucf thing

  indexIter = tagIndexHash.find(name);
  if (indexIter == tagIndexHash.end()) tagMessage(name);
  tag_index = indexIter->second;

  // point at the data
  p = ( idlStruct->value.s.arr->data + tag_offsets[tag_index] );


  // for arrays. Problem is we still have to case the result
  if (tag_desc[tag_index]->flags & IDL_V_ARR)
    {
      // should copy the desc pointer efficiency
      tmp = IDL_ImportArray(tag_desc[tag_index]->value.arr->n_dim,
			    tag_desc[tag_index]->value.arr->dim,
			    tag_desc[tag_index]->type,
			    p,
			    NULL,NULL);
    }
  else // scalars: what if we want to modify the value? Should we just import 
    //as array anyway?  But how if the .arr is not set?
    {

      // This could be an issue
      tmp = IDL_Gettmp();

      tmp->type = tagDescHash[name]->type;
      switch (tagDescHash[name]->type) {
      case IDL_TYP_BYTE:    tmp->value.c =    *(UCHAR *)p;       break;
      case IDL_TYP_INT:     tmp->value.i =    *(short *)p;       break;
      case IDL_TYP_UINT:    tmp->value.ui =   *(IDL_UINT *)p;    break;
      case IDL_TYP_LONG:    tmp->value.l =    *(IDL_LONG *)p;    break;
      case IDL_TYP_ULONG:   tmp->value.ul =   *(IDL_ULONG *)p;   break;
      case IDL_TYP_LONG64:  tmp->value.l64 =  *(IDL_LONG64 *)p;  break;
      case IDL_TYP_ULONG64: tmp->value.ul64 = *(IDL_ULONG64 *)p; break;
      case IDL_TYP_FLOAT:   tmp->value.f =    *(float *)p;       break;
	//case IDL_TYP_FLOAT: IDL_StoreScalar(&tmp, IDL_TYP_FLOAT
      case IDL_TYP_DOUBLE:  tmp->value.d =    *(double *)p;      break;
      case IDL_TYP_UNDEF: IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_LONGJMP,
				      "TYPE is undefined");
      default: IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_LONGJMP,
				      "Cannot work with type");
      }

    }

  return(tmp);

}
예제 #2
0
IDL_VPTR hds2idl( int argc, IDL_VPTR argv[] ) {
/*
** Declare variables
*/
IDL_VPTR hds_name;       /* IDL_VPTR to name of the HDS object to be read */
IDL_VPTR var;            /* Variable pointer to IDL object */
IDL_VARIABLE temp;       /* Temporary storage for primitive scalar variable */
IDL_StructDefPtr sdef;   /* Structure definition of sub-structure */
IDL_STRING *objname;     /* Pointer to object name as IDL string */
HDSLoc *objloc = NULL;   /* Locator of file */

int status;             /* Starlink status */

char type[DAT__SZTYP+1];/* HDS type of component */
UCHAR idltype;          /* IDl type of component */
int ndims;              /* Number of dimensions of object */
int dims[DAT__MXDIM];   /* Dimensions of object HDS style */
IDL_LONG idldims[DAT__MXDIM];/* Dimensions of object IDL style */
int i;                  /* loop index */
int fstat;              /* Final status (before emsEload) */
int isstruct;           /* Whether object is structure */
void *tdata;            /* Pointer to data area of IDL variable or array */

char param[EMS__SZPAR+1]; /* Error message parameter name */
int parlen;             /* Length of error message parameter name */
char opstr[EMS__SZMSG+1]; /* Error message */
int oplen;              /* Length of error message */

IDL_LONG one[IDL_MAX_ARRAY_DIM]={1};

/* Start Error context */
   status = SAI__OK;
   emsMark();

/* Check that the correct number of arguments were passed in */
   if(argc != 1) {

   /* Print an error message and return */
      status = SAI__ERROR;
      emsRep( " ", "hds2idl: Incorrect number of arguments", &status );

   } else {
   /* Extract the arguments to comprehensible names */
      hds_name = argv[0];
      objname = &hds_name->value.str;

   /* Open the HDS object */
      getcomp( IDL_STRING_STR(objname), "READ", &objloc, &status );

   /* Check for structure or primitive */
      datStruc( objloc, &isstruct, &status );
      if (status == SAI__OK) {
         if ( isstruct ) {
         /* Create a structure */
            sdef = idlstructdef( objloc, &status );

         /* Create a temporary variable */
            if ( status == SAI__OK ) {
               (void *)IDL_MakeTempStruct( sdef, 1, one, &var, TRUE );
               idlstructfill( objloc, var->value.s, &status );
            }

         } else {
         /* Object is primitive */
            datType( objloc, type, &status );
            idltype = getidltype( type );
            datShape( objloc, DAT__MXDIM, dims, &ndims, &status );
            if ( status == SAI__OK ) {
               if (ndims) {
               /* Get dimensions IDL style */
                  for (i=0;i<ndims;i++) idldims[i] = (IDL_LONG)dims[i];
               /* Object is primitive array */
                  tdata = IDL_MakeTempArray( (int)idltype, ndims, idldims,
                    IDL_BARR_INI_ZERO , &var );

               } else {
               /* Object is primitive scalar */
                  var = &temp;
                  var->type = idltype;
                  var->flags = 0;
                  tdata = &var->value;
               }

               idlprimfill( objloc, var, tdata, &status );
            }

         }

      /* Annul the object (and close the file) */
         datAnnul( &objloc, &status );
      }
   }

   if ( status != SAI__OK ) {
   /*  Report any error messages             */
   /*  Adding Starlink-style !! and ! prefix */
      fstat = status;
      while ( status != SAI__OK ) {
         emsEload(
            param, &parlen, opstr, &oplen, &status );
         if ( status != SAI__OK )
            IDL_Message( IDL_M_NAMED_GENERIC, IDL_MSG_INFO, opstr );
      }

   /*  Set to return undefined variable */
      var = IDL_Gettmp();

   /*  and close error context */
      emsRlse();
   }

/*  That's it, return to the calling routine */
   return var;
}