Hi,

Are you creating the dataset with a float datatype?

Attached is an HDF4 program that creates a character dataset.
It creates the dataset as follows:

   sds_id = SDcreate(sd_id, "data1", DFNT_CHAR, rank, dims);

-Barbara


====================
Barbara Jones
The HDF Helpdesk

The HDF Group
[email protected]
====================

Folks
I am trying to write a simple character array through SDwritedata but
somehow my output SDS field ends up being of 32 bit floating bit type and
the values are all big floating point values. What am I doing wrong? See
some portions of my code below:

char * ref_name = NULL:
int32 ndata;
int i;

ndata = 7;
ioparam->out_sds.data_type = DFNT_CHAR;
ioparam->out_sds.data_size = DFKNTsize(ioparam->out_sds.data_type);

for (i = 0; i < ndata; i++) /* BIG Assumption that ref data will be always
1D */
     {
       ref_name = (void *) calloc (size, sizeof(char));
       status = get_name (foo, ref_name, size); /* Here the ref_name is
set */
       start[0] = i;
       edge[0] = 1;
       printf("Dataset: %s is %s\n",ioparam->in_sds.name,ref_name); /*
Here the names are printed correctly */
       if (SDwritedata(ioparam->out_sds.sds_id, start, NULL, edge,
(VOIDP)ref_name) == FAIL) {
         fprintf(stderr, "Error writing ref data from SDS %s\n", ioparam->
out_sds.name);
         return -1;
       }
       if (ref_name != NULL) free(ref_name);
     }

So the names are all printed correctly when I print them on the screen but
when I check the output file the fields are all float32.

Am I missing something here?
Thanks


--
Barbara L. Jones
[email protected]
/*******************************************************************/
/*                                                                 */
/*  sdtxt.c                                                    */
/*        This program creates an HDF file, sd.hdf, which          */
/*        contains an SDS of size 10 x 5.                          */
/*                                                                 */
/*******************************************************************/

#include "mfhdf.h"

#define DIM0 10
#define DIM1  5 

main( ) 
{
        int32 sd_id, sds_id, istat;
        int32 dims[2], start[2], edges[2], rank;
        char array_data [10][5];
        intn i,j;

        /* Create and open the file and initiate the SD interface. */
        sd_id = SDstart("sdtxt.hdf", DFACC_CREATE);

        /* Define the rank and dimensions of the data set to be created. */
        rank = 2;
        dims[0] = DIM0;
        dims[1] = DIM1;

        /* Create the array data set. */
        sds_id = SDcreate(sd_id, "data1", DFNT_CHAR, rank, dims);

        for (i = 0; i < DIM0; i++) 
          for (j = 0; j < DIM1; j++) 
                        array_data[i][j] = 'a';

        for (i = 0; i < rank; i++) {
                start[i] = 0;
                edges[i] = dims[i];
        }

        istat = SDwritedata(sds_id, start, NULL, edges, (VOIDP)array_data); 

        istat = SDendaccess(sds_id);
        istat = SDend(sd_id);
}


_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to