src/tio_quant.c
/***************************************************************************************************
 *
 * TIO_Set_Quant_Range
 *
 * - can be called any time between create_quant and close_quant
 *
 **************************************************************************************************/
can be called any time between create_quant and close_quant
can be called any time between create_quant and close_quant
TIO_t
TIO_Set_Quant_Range( const TIO_File_t   fileID,
                     const TIO_Object_t quantID,
                     const TIO_Data_t   datatype,
                     const void         *qmin,
                     const void         *qmax )
{
  const char *subname = "TIO_Set_Quant_Range()";
  struct iFile_t  *tfile;
  struct iQuant_t *tquant;
  size_t dsi;
  int    irc;
  TIO_t  trc;
  TIObegin(subname,1);
  trc = cTIO_HierarchyGetObjectInfo( subname, fileID, NULL, quantID, CLASS_QUANT,
                                     &tfile, (void **)&tquant);
  if (TIO_SUCCESS != trc) {
    cTIOreturn (trc);
  }
  dsi = iTIO_SizeOf(datatype);
  if (0 == dsi) {
    TIOreturn(ERR_USER, "Invalid argument (datatype)", TIO_ERR_INVALID_DATATYPE);
  }
  if (tquant->rangeset) {
    TIOreturn(ERR_USER, "Quant range has already been set", TIO_ERR_INVALID_OPERATION);
  }
  if (datatype != tquant->datatype) {
    size_t dsf;
    void   *buf;
    dsf = iTIO_SizeOf(tquant->datatype);
    buf = TIOmalloc(TIOmax(dsi, dsf));
    if (qmin != NULL) {
      (void) memcpy(buf, qmin, dsi);
      irc = tfile->ConvBuf(datatype, tquant->datatype, 1, buf);
      if (irc < 0) {
        TIOfree (buf); buf = NULL;
        TIOreturn(ERR_USER, "Unable to convert between given datatype and that of quant",
                  TIO_ERR_INVALID_CONVERSION);
      }
      (void) memcpy(tquant->qmin, buf, dsf);
    }
    if (qmax != NULL) {
      (void) memcpy(buf, qmax, dsi);
      irc = tfile->ConvBuf(datatype, tquant->datatype, 1, buf);
      if (irc < 0) {
        TIOfree (buf); buf = NULL;
        TIOreturn(ERR_USER, "Unable to convert between given datatype and that of quant",
                  TIO_ERR_INVALID_CONVERSION);
      }
      (void) memcpy(tquant->qmax, buf, dsf);
    }
    TIOfree (buf); buf = NULL;
  }
  else {
    if (qmin != NULL) {
      (void) memcpy(tquant->qmin, qmin, dsi);
    }
    if (qmax != NULL) {
      (void) memcpy(tquant->qmax, qmax, dsi);
    }
  }
  tquant->rangeset = TRUE;
  TIOend(subname,1);
  return (TIO_SUCCESS);
}
TIO_t TIO_Set_Quant_Range ( const TIO_File_t fileID , const TIO_Object_t quantID , const TIO_Data_t datatype , const void * qmin , const void * qmax ) { const char * subname = " " ; struct iFile_t * tfile ; struct iQuant_t * tquant ; size_t dsi ; int irc ; TIO_t trc ; TIObegin ( subname , 1 ) ; trc = cTIO_HierarchyGetObjectInfo ( subname , fileID , NULL , quantID , CLASS_QUANT , & tfile , ( void * * ) & tquant ) ; if ( TIO_SUCCESS != trc ) { cTIOreturn ( trc ) ; } dsi = iTIO_SizeOf ( datatype ) ; if ( 0 == dsi ) { TIOreturn ( ERR_USER , " " , TIO_ERR_INVALID_DATATYPE ) ; } if ( tquant -> rangeset ) { TIOreturn ( ERR_USER , " " , TIO_ERR_INVALID_OPERATION ) ; } if ( datatype != tquant -> datatype ) { size_t dsf ; void * buf ; dsf = iTIO_SizeOf ( tquant -> datatype ) ; buf = TIOmalloc ( TIOmax ( dsi , dsf ) ) ; if ( qmin != NULL ) { ( void ) memcpy ( buf , qmin , dsi ) ; irc = tfile -> ConvBuf ( datatype , tquant -> datatype , 1 , buf ) ; if ( irc < 0 ) { TIOfree ( buf ) ; buf = NULL ; TIOreturn ( ERR_USER , " " , TIO_ERR_INVALID_CONVERSION ) ; } ( void ) memcpy ( tquant -> qmin , buf , dsf ) ; } if ( qmax != NULL ) { ( void ) memcpy ( buf , qmax , dsi ) ; irc = tfile -> ConvBuf ( datatype , tquant -> datatype , 1 , buf ) ; if ( irc < 0 ) { TIOfree ( buf ) ; buf = NULL ; TIOreturn ( ERR_USER , " " , TIO_ERR_INVALID_CONVERSION ) ; } ( void ) memcpy ( tquant -> qmax , buf , dsf ) ; } TIOfree ( buf ) ; buf = NULL ; } else { if ( qmin != NULL ) { ( void ) memcpy ( tquant -> qmin , qmin , dsi ) ; } if ( qmax != NULL ) { ( void ) memcpy ( tquant -> qmax , qmax , dsi ) ; } } tquant -> rangeset = TRUE ; TIOend ( subname , 1 ) ; return ( TIO_SUCCESS ) ; }
TIO_Set_Quant_Range
 - can be called any time between create_quant and close_quant
TIO_Set_Quant_Range - can be called any time between create_quant and close_quant
/* Postpone writing until collective quantity close call */