示例#1
0
/*++++++++++++++++++++++++++++++++++++++++++++++++++*/
int IDL_STDCALL _SDMF_RD_PT_CLUS_ATTR( int argc, void *argv[] )
{
     IDL_STRING      *dbName;
     unsigned char   *coaddf;
     unsigned short  state_id, clus_id;
     unsigned short  *num_pixels, *num_obs;
     float           *pet;

     char    grpName[9], clusName[11];
     hid_t   fid = -1, gid = -1;
/*
 * check number of parameters
 */
     if ( argc != 7 ) NADC_GOTO_ERROR( NADC_ERR_PARAM, err_msg );
     dbName   = (IDL_STRING *) argv[0];
     state_id = *(unsigned short *) argv[1];
     clus_id  = *(unsigned short *) argv[2];
     coaddf   = (unsigned char *) argv[3];
     num_pixels = (unsigned short *) argv[4];
     num_obs  = (unsigned short *) argv[5];
     pet      = (float *) argv[6];

     fid = H5Fopen( dbName->s, H5F_ACC_RDONLY, H5P_DEFAULT );
     if ( fid < 0 ) NADC_GOTO_ERROR( NADC_ERR_HDF_FILE, dbName->s );

     (void) snprintf( grpName, 9, "State_%02hu", state_id );
     gid = H5Gopen( fid, grpName, H5P_DEFAULT );
     if ( gid < 0 ) NADC_GOTO_ERROR( NADC_ERR_HDF_FILE, grpName );

     (void) snprintf( clusName, 11, "cluster_%02hu", clus_id );
     (void) H5LTget_attribute_uchar( gid, clusName, "coaddf", coaddf );
     (void) H5LTget_attribute_ushort( gid, clusName, "numObs", num_obs );
     (void) H5LTget_attribute_ushort( gid, clusName,"numPixels", num_pixels );
     if ( H5LTget_attribute_float( gid, clusName, "PET", pet ) < 0 )
	  NADC_GOTO_ERROR( NADC_ERR_HDF_ATTR, "PET" );

     (void) H5Gclose( gid );
     (void) H5Fclose( fid );
     return 1;
 done:
     H5E_BEGIN_TRY {
	  (void) H5Gclose( gid );
	  (void) H5Fclose( fid );
     } H5E_END_TRY;
     return -1;
}
示例#2
0
static herr_t make_attributes( hid_t loc_id, const char* obj_name )
{

    int         rank_out;
    hsize_t     *dims_out = 0;
    H5T_class_t type_class;
    size_t      type_size;
    int         i;

    char    attr_str_in[]     = {"My attribute"};
    char    attr_str_out[20];
    char    attr_char_in[5]   = {1,2,3,4,5};
    char    attr_char_out[5];
    short   attr_short_in[5]  = {1,2,3,4,5};
    short   attr_short_out[5];
    int     attr_int_in[5]    = {1,2,3,4,5};
    int     attr_int_out[5];
    long    attr_long_in[5]   = {1,2,3,4,5};
    long    attr_long_out[5];
    float   attr_float_in[5]  = {1,2,3,4,5};
    float   attr_float_out[5];
    double  attr_double_in[5] = {1,2,3,4,5};
    double  attr_double_out[5];
    unsigned char    attr_uchar_in[5]   = {1,2,3,4,5};
    unsigned char    attr_uchar_out[5];
    unsigned short   attr_ushort_in[5]  = {1,2,3,4,5};
    unsigned short   attr_ushort_out[5];
    unsigned int     attr_uint_in[5]    = {1,2,3,4,5};
    unsigned int     attr_uint_out[5];
    unsigned long    attr_ulong_in[5]   = {1,2,3,4,5};
    unsigned long    attr_ulong_out[5];

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_string test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_string");

    /* Set the attribute */
    if ( H5LTset_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_in ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_string test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_string");


    /* Get the attribute */
    if ( H5LTget_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_out ) < 0 )
        return -1;

    if ( strcmp( attr_str_in, attr_str_out ) != 0 )
    {
        return -1;
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_char test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_char");

    /* Set the attribute */
    if ( H5LTset_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_char test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_char");

    /* Get the attribute */
    if ( H5LTget_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_char_in[i] != attr_char_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR2_NAME, H5T_NATIVE_CHAR, attr_char_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_char_in[i] != attr_char_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_short test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_short");

    /* Set the attribute */
    if ( H5LTset_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTget_attribute_short test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_short");

    /* Get the attribute */
    if ( H5LTget_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_short_in[i] != attr_short_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR3_NAME, H5T_NATIVE_SHORT, attr_short_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_short_in[i] != attr_short_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_int");

    /* Set the attribute */
    if ( H5LTset_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_int");

    /* Get the attribute */
    if ( H5LTget_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_int_in[i] != attr_int_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR4_NAME, H5T_NATIVE_INT, attr_int_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_int_in[i] != attr_int_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_long test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_long");

    /* Set the attribute */
    if ( H5LTset_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_long test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_long");

    /* Get the attribute */
    if ( H5LTget_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_long_in[i] != attr_long_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR5_NAME, H5T_NATIVE_LONG, attr_long_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_long_in[i] != attr_long_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_uchar test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_uchar");

    /* Set the attribute */
    if ( H5LTset_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_uchar test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_uchar");

    /* Get the attribute */
    if ( H5LTget_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uchar_in[i] != attr_uchar_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR6_NAME, H5T_NATIVE_UCHAR, attr_uchar_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uchar_in[i] != attr_uchar_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_ushort test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_ushort");

    /* Set the attribute */
    if ( H5LTset_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTget_attribute_ushort test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_ushort");

    /* Get the attribute */
    if ( H5LTget_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ushort_in[i] != attr_ushort_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR7_NAME, H5T_NATIVE_USHORT, attr_ushort_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ushort_in[i] != attr_ushort_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_uint");

    /* Set the attribute */
    if ( H5LTset_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_uint");

    /* Get the attribute */
    if ( H5LTget_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uint_in[i] != attr_uint_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR8_NAME, H5T_NATIVE_UINT, attr_uint_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uint_in[i] != attr_uint_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_ulong test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_ulong");

    /* Set the attribute */
    if ( H5LTset_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_long test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_ulong");

    /* Get the attribute */
    if ( H5LTget_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ulong_in[i] != attr_ulong_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR9_NAME, H5T_NATIVE_ULONG, attr_ulong_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ulong_in[i] != attr_ulong_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_float test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_float");

    /* Set the attribute */
    if ( H5LTset_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_float test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_float");


    /* Get the attribute */
    if ( H5LTget_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_float_in[i] != attr_float_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR10_NAME, H5T_NATIVE_FLOAT, attr_float_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_float_in[i] != attr_float_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_double test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_double");

    /* Set the attribute */
    if ( H5LTset_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_double test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_double");

    /* Get the attribute */
    if ( H5LTget_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_double_in[i] != attr_double_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR11_NAME, H5T_NATIVE_DOUBLE, attr_double_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_double_in[i] != attr_double_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTget_attribute_ndims test
    *-------------------------------------------------------------------------
    */


    TESTING("H5LTget_attribute_ndims");

    if ( H5LTget_attribute_ndims( loc_id, obj_name, ATTR2_NAME, &rank_out ) < 0 )
        return -1;

    if ( rank_out != 1 ) {
        return -1;
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_info test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_info");

    dims_out = (hsize_t*) malloc( sizeof(hsize_t) * rank_out );

    if ( H5LTget_attribute_info( loc_id, obj_name, ATTR2_NAME, dims_out, &type_class,
        &type_size) < 0 )
        return -1;

    for (i = 0; i < rank_out; i++)
    {
        if ( dims_out[i] != 5 ) {
            return -1;
        }
    }

    if ( type_class != H5T_INTEGER ) {
        return -1;
    }

    if ( dims_out )
        free( dims_out );

    PASSED();

    return 0;
}
示例#3
0
/*+++++++++++++++++++++++++
.IDENTifer   SDMF_rd_pt_cluster
.PURPOSE     read cluster records from SDMF last-limb/Sun database
.INPUT/OUTPUT
  call as    SDMF_rd_pt_cluster( locID, clus_id, &numIndx, metaIndx, 
                                   pixel_val );
     input:
           hid_t  locID          :  HDF5 identifier of group
	   unsigned char clus_id :  Cluster ID, range 1 - 40
	   size_t *metaIndx      :  array with requested indices
 in/output:
	   size_t *numIndx       :  [input]  dimension of metaIndx (or zero)
                                    [output] number of records read
    output:
           float *pixel_val      : pixel values of SDMF last-limb/Sun database

.RETURNS     nothing, error status passed by global variable ``nadc_stat''
.COMMENTS    static function
-------------------------*/
void SDMF_rd_pt_cluster( hid_t locID, unsigned char clus_id, 
			   size_t *numIndx, size_t *metaIndx,
			   float *pixel_val )
{
     register size_t  nr, np;

     char           clusName[11];
     unsigned char  coaddf;
     unsigned short num_pixels, num_obs, *usbuff;
     unsigned int   *ubuff;

     hid_t   ptable;
     hsize_t nrecords;
     size_t  total_values;
/*
 * does the dataset already exists?
 */
     (void) snprintf( clusName, 11, "cluster_%02hhu", clus_id );
     if ( (ptable = H5PTopen( locID, clusName )) == H5I_BADID ) return;
/*
 * obtain table info
 */
     (void) H5PTget_num_packets( ptable, &nrecords );
     if ( *numIndx == 0 ) {
	  *numIndx = (size_t) nrecords;
	  for ( nr = 0; nr < nrecords; nr++ ) metaIndx[nr] = nr;
     }
     if ( nrecords == 0 ) {
	  (void) H5PTclose( ptable );
          return;
     }
     (void) H5LTget_attribute_uchar( locID, clusName, "coaddf", &coaddf );
     (void) H5LTget_attribute_ushort( locID, clusName, "numObs", &num_obs );
     (void) H5LTget_attribute_ushort( locID, clusName,"numPixels",&num_pixels );
     total_values = (size_t) num_obs * num_pixels;
/*
 * allocate temporary buffer to store cluster data
 */
     if ( coaddf == (unsigned char) 1 ) {
	  usbuff = (unsigned short *) malloc( total_values * sizeof(short) );
	  ubuff = NULL;
     } else {
	  usbuff = NULL;
	  ubuff = (unsigned int *) malloc( total_values * sizeof(int) );
     }
/*
 * read cluster records
 */
     nr = 0;
     do {
	  if ( coaddf == (unsigned char) 1 ) {
	       (void) H5PTread_packets( ptable, (hsize_t) metaIndx[nr], 
					1, usbuff );
	       for ( np = 0; np < total_values; np++ )
		    *pixel_val++ = (float) usbuff[np];
	  } else {
	       (void) H5PTread_packets( ptable, (hsize_t) metaIndx[nr], 
					1, ubuff );
	       for ( np = 0; np < total_values; np++ ) {
		    *pixel_val++ = (float) ubuff[np];
	       }
	  }
     } while ( ++nr < (*numIndx) );

     if ( usbuff != NULL ) free( usbuff );
     if ( ubuff != NULL  ) free( ubuff );
}