Ejemplo n.º 1
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Iget_name
 * Signature: (J)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL
Java_hdf_hdf5lib_H5_H5Iget_1name
    (JNIEnv *env, jclass clss, jlong obj_id)
{
    char *aName;
    jstring  str = NULL;
    ssize_t  buf_size;

    /* get the length of the name */
    buf_size = H5Iget_name((hid_t)obj_id, NULL, 0);

    if (buf_size <= 0) {
        h5badArgument(env, "H5Iget_name:  buf_size <= 0");
    } /* end if */
    else {
        buf_size++; /* add extra space for the null terminator */
        aName = (char*)HDmalloc(sizeof(char) * (size_t)buf_size);
        if (aName == NULL) {
            h5outOfMemory(env, "H5Iget_name:  malloc failed");
        } /* end if */
        else {
            buf_size = H5Iget_name((hid_t)obj_id, aName, (size_t)buf_size);
            if (buf_size < 0) {
                h5libraryError(env);
            } /* end if */
            else {
                str = ENVPTR->NewStringUTF(ENVPAR aName);
            }
            HDfree(aName);
        }
    }
    return str;
} /* end Java_hdf_hdf5lib_H5_H5Iget_1name */
Ejemplo n.º 2
0
void NSDFWriter::createEventMap()
{
    herr_t status;    
    hid_t eventMapContainer = require_group(filehandle_, MAPEVENTSRC);
    // Open the container for the event maps
    // Create the Datasets themselves (one for each field - each row
    // for one object).
    for (map< string, vector < string > >::iterator ii = classFieldToEventSrc_.begin();
         ii != classFieldToEventSrc_.end();
         ++ii){
        vector < string > pathTokens;
        tokenize(ii->first, "/", pathTokens);
        string className = pathTokens[0];
        string fieldName = pathTokens[1];
        hid_t classGroup = require_group(eventMapContainer, className);
        hid_t strtype = H5Tcopy(H5T_C_S1);
        status = H5Tset_size(strtype, H5T_VARIABLE);
        // create file space
        hid_t ftype = H5Tcreate(H5T_COMPOUND, sizeof(hvl_t) +sizeof(hobj_ref_t));
        status = H5Tinsert(ftype, "source", 0, strtype);
        status = H5Tinsert(ftype, "data", sizeof(hvl_t), H5T_STD_REF_OBJ);
        hsize_t dims[1] = {ii->second.size()};
        hid_t space = H5Screate_simple(1, dims, NULL);
        // The dataset for mapping is named after the field
        hid_t ds = H5Dcreate2(classGroup, fieldName.c_str(), ftype, space,
                              H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        status = H5Sclose(space);
        map_type * buf = (map_type*)calloc(ii->second.size(), sizeof(map_type));
        // Populate the buffer entries with source uid and data
        // reference
        for (unsigned int jj = 0; jj < ii->second.size(); ++jj){
            buf->source = ii->second[jj].c_str();
            char * dsname = (char*)calloc(256, sizeof(char));
            ssize_t size = H5Iget_name(classFieldToEvent_[ii->first][jj], dsname, 255);
            if (size > 255){
                free(dsname);
                dsname = (char*)calloc(size, sizeof(char));
                size = H5Iget_name(classFieldToEvent_[ii->first][jj], dsname, 255);
            }
            status = H5Rcreate(&(buf->data), filehandle_, dsname, H5R_OBJECT, -1);
            free(dsname);
            assert(status >= 0);            
        }
        // create memory space
        hid_t memtype = H5Tcreate(H5T_COMPOUND, sizeof(map_type));
        status = H5Tinsert(memtype, "source",
                           HOFFSET(map_type, source), strtype);
        status = H5Tinsert(memtype, "data",
                           HOFFSET(map_type, data), H5T_STD_REF_OBJ);
        status = H5Dwrite(ds, memtype,  H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
        free(buf);
        status = H5Tclose(strtype);
        status = H5Tclose(ftype);
        status = H5Tclose(memtype);
        status = H5Dclose(ds);
    }
}
Ejemplo n.º 3
0
Archivo: H5If.c Proyecto: ElaraFX/hdf5
/****if* H5If/h5iget_name_c
 * NAME
 *  h5iget_name_c
 * PURPOSE
 *  Call H5Iget_name to get object's name
 * INPUTS
 *  obj_id - object identifier
 *  buf_size - size of the buffer
 * OUTPUTS
 *  buf - buffer to hold the name
 * RETURNS
 *  length of the name on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *  Wednesday, March 12, 2003
 * HISTORY
 *
 *  Changed the size of c_buf_size to c_buf_size + 1, which
 *  fixes the problem of truncating the string by 1 if the
 *  exact size of the string (buf_size) is passed in.
 *               M. Scot Breitenfeld, April 21, 2008
 * SOURCE
*/
int_f
h5iget_name_c(hid_t_f *obj_id, _fcd buf, size_t_f *buf_size, size_t_f *name_size)
/******/
{
     int ret_value = -1;
     hid_t c_obj_id;
     ssize_t c_size;
     size_t c_buf_size;
     char *c_buf =NULL;

     /*
      * Allocate buffer to hold name of an object
      */
     c_buf_size = (size_t)*buf_size +1;
     c_buf = (char *)HDmalloc(c_buf_size);
     if (c_buf == NULL) return ret_value;

     /*
      * Call H5IAget_name function
      */
     c_obj_id = (hid_t)*obj_id;
     c_size = H5Iget_name(c_obj_id, c_buf, c_buf_size);
     if (c_size < 0) goto DONE;

     /*
      * Convert C name to FORTRAN and place it in the given buffer
      */
      HD5packFstring(c_buf, _fcdtocp(buf), c_buf_size-1);
      *name_size = (size_t_f)c_size;
      ret_value = 0;

DONE:
      HDfree(c_buf);
      return ret_value;
}
Ejemplo n.º 4
0
herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid, 
		     void *visitor_data)
{
   char name1[NC_MAX_NAME];
   H5G_stat_t statbuf;
   HDF5_OBJID_T *objid = visitor_data;

   /* This should get "/var1", the name of the dataset that the scale
    * is attached to. */
   if (H5Iget_name(did, name1, NC_MAX_NAME) < 0) ERR;
   if (strcmp(&name1[1], VAR1_NAME)) ERR;
   
   /*printf("visiting did 0x%x dim %d dsid 0x%x name of did %s \n", 
     did, dim, dsid, name1);*/

   /* Get more info on the dimscale object.*/
   if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR;
   objid->fileno[0] = statbuf.fileno[0];
   objid->objno[0] = statbuf.objno[0];
   objid->fileno[1] = statbuf.fileno[1];
   objid->objno[1] = statbuf.objno[1];
   /*printf("for dsid: statbuf.fileno = %d statbuf.objno = %d\n", 
     statbuf.fileno, statbuf.objno);*/

   if (H5Gget_objinfo(did, ".", 1, &statbuf) < 0) ERR;
   /*printf("for did: statbuf.fileno = %d statbuf.objno = %d\n", 
     statbuf.fileno, statbuf.objno);*/
   return 0;
}
Ejemplo n.º 5
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Iget_name_long
 * Signature: (JLjava/lang/String;J)J
 */
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5_H5Iget_1name_1long
    (JNIEnv *env, jclass clss, jlong obj_id, jobjectArray name, jlong buf_size)
{
    char *aName;
    jstring str;
    hssize_t size = -1;
    long bs;

    bs = (long)buf_size;
    if (bs <= 0) {
        h5badArgument(env, "H5Iget_name:  buf_size <= 0");
    } /* end if */
    else {
        aName = (char*)HDmalloc(sizeof(char) * (size_t)bs);
        if (aName == NULL) {
            h5outOfMemory(env, "H5Iget_name:  malloc failed");
        } /* end if */
        else {
            size = H5Iget_name((hid_t)obj_id, aName, (size_t)buf_size);
            if (size < 0) {
                h5libraryError(env);
            } /* end if */
            else {
                str = ENVPTR->NewStringUTF(ENVPAR aName);
                ENVPTR->SetObjectArrayElement(ENVPAR name, 0, str);
            }
            HDfree(aName);
        }
    }
    return (jlong)size;
} /* end Java_hdf_hdf5lib_H5_H5Iget_1name */
Ejemplo n.º 6
0
//--------------------------------------------------------------------------
// Function:    H5Object::getObjName
///\brief       Returns the name of this object as an \a H5std_string.
///\return      Name of the object
///\exception   H5::Exception
// Programmer   Binh-Minh Ribler - Mar, 2014
// Modification
//--------------------------------------------------------------------------
H5std_string H5Object::getObjName() const
{
    H5std_string obj_name(""); // object name to return

    // Preliminary call to get the size of the object name
    ssize_t name_size = H5Iget_name(getId(), NULL, static_cast<size_t>(0));

    // If H5Iget_name failed, throw exception
    if (name_size < 0)
    {
        throw Exception(inMemFunc("getObjName"), "H5Iget_name failed");
    }
    else if (name_size == 0)
    {
        throw Exception(inMemFunc("getObjName"), "Object must have a name, but name length is 0");
    }
    // Object's name exists, retrieve it
    else if (name_size > 0)
    {
        char* name_C = new char[name_size+1];  // temporary C-string
        HDmemset(name_C, 0, name_size+1); // clear buffer

        // Use overloaded function
        name_size = getObjName(name_C, name_size+1);

        // Convert the C object name to return
        obj_name = name_C;

        // Clean up resource
        delete []name_C;
    }
    // Return object's name
    return(obj_name);
}
Ejemplo n.º 7
0
/*-------------------------------------------------------------*/
static void validateFloat3Attribute(pNXVcontext self,
	hid_t dpField, char *name)
{
	hid_t attID, attType, attSpace;
	H5T_class_t h5class;
	hsize_t dims[2], maxDims[2];
	char fname[512];

	memset(fname,0,sizeof(fname));

	H5Iget_name(dpField,fname,sizeof(fname));

	if(!H5LTfind_attribute(dpField,name)){
			NXVsetLog(self,"sev","error");
			NXVprintLog(self,"message",
				"Missing attribute %s on %s",
				name, fname);
			NXVlog(self);
			self->errCount++;
	} else {
		attID = H5Aopen(dpField,name,H5P_DEFAULT);
		assert(attID >= 0);
		attType = H5Aget_type(attID);
		assert(attType >= 0);
		h5class = H5Tget_class(attType);
		if(h5class != H5T_FLOAT){
			NXVsetLog(self,"sev","error");
			NXVprintLog(self,"message",
				"%s attribute on %s is of wrong type, expected float",
				name, fname);
			NXVlog(self);
			self->errCount++;
		} else {
			attSpace = H5Aget_space(attID);
			if(H5Sget_simple_extent_ndims(attSpace) != 1){
				NXVsetLog(self,"sev","error");
				NXVprintLog(self,"message",
					"%s attribute on %s is of wrong rank, expected 1",
					name, fname);
				NXVlog(self);
				self->errCount++;
			} else {
				H5Sget_simple_extent_dims(attSpace,dims,maxDims);
				if(dims[0] != 3){
					NXVsetLog(self,"sev","error");
					NXVprintLog(self,"message",
						"%s attribute on %s is of wrong size, expected 3",
						name, fname);
					NXVlog(self);
					self->errCount++;
				}
			}
			H5Sclose(attSpace);
		}
		H5Tclose(attType);
		H5Aclose(attID);
	}
}
Ejemplo n.º 8
0
/*--------------------------------------------------------------
	This validates the lesser depends_on chain fields like
	vector, offset and transformation_type
----------------------------------------------------------------*/
static void validateDependsOnAttributes(pNXVcontext self,hid_t dpField)
{
	char fname[512], transData[512];
	hid_t attID, attType, attSpace;
	H5T_class_t h5class;

	memset(fname,0,sizeof(fname));
	memset(transData,0,sizeof(transData));

	H5Iget_name(dpField,fname,sizeof(fname));

	/*
		deal with transformation_type
	*/
	if(!H5LTfind_attribute(dpField,"transformation_type")){
			NXVsetLog(self,"sev","error");
			NXVprintLog(self,"message",
				"Missing attribute transformation_type on %s",
				fname);
			NXVlog(self);
			self->errCount++;
	} else {
		attID = H5Aopen(dpField,"transformation_type",H5P_DEFAULT);
		assert(attID >= 0);
		attType = H5Aget_type(attID);
		assert(attType >= 0);
		h5class = H5Tget_class(attType);
		if(h5class != H5T_STRING){
			NXVsetLog(self,"sev","error");
			NXVprintLog(self,"message",
				"transformation_type on %s is of wrong type, expected string",
				fname);
			NXVlog(self);
			self->errCount++;
		} else {
			H5NXget_attribute_string(self->fileID, fname,
					"transformation_type",transData);
			if(strcmp(transData,"translation") != 0
				&& strcmp(transData,"rotation") != 0){
					NXVsetLog(self,"sev","error");
					NXVprintLog(self,"message",
						"transformation_type on %s contains bad data: %s",
						fname,
						"expected rotation or translation");
					NXVlog(self);
					self->errCount++;
				}
		}
		H5Tclose(attType);
		H5Aclose(attID);
	}

	validateFloat3Attribute(self,dpField,"offset");
	validateFloat3Attribute(self,dpField,"vector");

}
Ejemplo n.º 9
0
herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid, 
		     void *visitor_data)
{
   char name1[STR_LEN], name2[STR_LEN];
   H5G_stat_t statbuf;

   (*(hid_t *)visitor_data) = dsid;
   if (H5Iget_name(did, name1, STR_LEN) < 0) ERR;
   if (H5Iget_name(dsid, name2, STR_LEN) < 0) ERR;
/*    printf("visiting did 0x%x dim %d dsid 0x%x name of did %s \n",  */
/* 	  did, dim, dsid, name1); */
/*    printf("name of dsid: %s\n", name2); */

   if (H5Gget_objinfo(did, ".", 1, &statbuf) < 0) ERR;
/*   printf("statbuf.fileno = %d statbuf.objno = %d\n", 
     statbuf.fileno, statbuf.objno);*/
   
   return 0;
}
Ejemplo n.º 10
0
/*--------------------------------------------------------------*/
static void validateDependsOn(pNXVcontext self, hid_t groupID,
	hid_t fieldID)
{
	char fname[512], dpData[1024];
	hid_t h5type, dpfieldID;
	H5T_class_t h5class;

	memset(fname,0,sizeof(fname));
	memset(dpData,0,sizeof(dpData));
	H5Iget_name(fieldID,fname,sizeof(fname));
	NXVsetLog(self,"dataPath",fname);
	NXVsetLog(self,"sev","debug");
	NXVprintLog(self,"message","Validating depends_on chain starting at %s",
						fname);
	NXVlog(self);

	/*
		test that the depends_on field is of the right type
	*/
	h5type = H5Dget_type(fieldID);
	h5class = H5Tget_class(h5type);
	H5Tclose(h5type);
	if(h5class != H5T_STRING){
			NXVsetLog(self,"sev","error");
			NXVsetLog(self,"message",
			"depends_on field is of wrong type, expect string");
			NXVlog(self);
			self->errCount++;
			return;
	}

	/*
		read the field
	*/
	H5LTread_dataset_string(groupID,"depends_on",dpData);

	/*
		find the field and start iterating through the chain
	*/

	dpfieldID = findDependentField(self,fieldID,dpData);
	if(dpfieldID < 0){
		NXVsetLog(self,"sev","error");
		NXVprintLog(self,"message",
		"Cannot even find the starting point of the depends_on chain, %s",
		dpData);
		NXVlog(self);
		self->errCount++;
		return;
	} else {
		validateDependsOnField(self,groupID,dpfieldID);
		H5Dclose(dpfieldID);
	}

}
Ejemplo n.º 11
0
/*-------------------------------------------------------------*/
static hid_t findDependentField(pNXVcontext self,
		hid_t inFieldID,char *dpData)
{
	char *pPtr;
	hid_t fieldID, groupID;
	char fname[512], newPath[1024], groupName[1024];

	/*
		get at enclosing group
  */
	memset(groupName,0,sizeof(groupName));
	H5Iget_name(inFieldID,groupName,sizeof(groupName));
	pPtr = strrchr(groupName,'/');
	*pPtr = '\0';
	pPtr = NULL;

	pPtr = strchr(dpData,'/');

	if(pPtr != NULL){
		if(pPtr == dpData){
			/* absolute path */
			if(H5LTpath_valid(self->fileID,dpData,1)){
				fieldID = H5Oopen(self->fileID,dpData,H5P_DEFAULT);
				return fieldID;
			} else {
				return -1;
			}
		} else {
			/* relative path further along the path */
			snprintf(newPath,sizeof(newPath), "%s/%s", groupName, dpData);
			if(H5LTpath_valid(self->fileID,newPath,1)){
				fieldID = H5Oopen(self->fileID,newPath,H5P_DEFAULT);
				return fieldID;
			} else {
				return -1;
			}
		}
	} else {
		/* path within the group */
		groupID = H5Oopen(self->fileID, groupName,H5P_DEFAULT);
		if(H5LTfind_dataset(groupID,dpData)){
			fieldID = H5Dopen(groupID,dpData,H5P_DEFAULT);
			H5Oclose(groupID);
			return fieldID;
		} else {
			H5Oclose(groupID);
			return -1;
		}
	}

	return -1;
}
Ejemplo n.º 12
0
//--------------------------------------------------------------------------
// Function:    getObjName
///\brief       Given an id, returns the type of the object.
///\return      The name of the object
// Programmer   Binh-Minh Ribler - Mar, 2014
//--------------------------------------------------------------------------
ssize_t H5Object::getObjName(char *obj_name, size_t buf_size) const
{
    // H5Iget_name will get buf_size-1 chars of the name to null terminate it
    ssize_t name_size = H5Iget_name(getId(), obj_name, buf_size);

    // If H5Iget_name returns a negative value, raise an exception
    if (name_size < 0)
    {
        throw Exception(inMemFunc("getObjName"), "H5Iget_name failed");
    }
    else if (name_size == 0)
    {
        throw Exception(inMemFunc("getObjName"), "Object must have a name, but name length is 0");
    }
    // Return length of the name
    return(name_size);
}
Ejemplo n.º 13
0
Archivo: cxi.c Proyecto: cxidb/libcxi
CXI_Data_Reference * cxi_create_data_link(CXI_Entry * entry, CXI_Dataset * data){
  if(!entry || ! data){
    return NULL;
  }
  if(entry->handle <= 0 || data->handle <= 0){
    return NULL;
  }
  CXI_Data * root_data = calloc(sizeof(CXI_Data),1);
  CXI_Data_Reference * data_ref = cxi_create_data(entry->handle,root_data);
  if(!data_ref) return NULL;
  char path[1024];
  if(H5Iget_name(data->handle, path, 1024) <= 0){
    return NULL;
  }
  if(H5Lcreate_soft(path, root_data->handle, "data", H5P_DEFAULT, H5P_DEFAULT) < 0){
    return NULL;
  }
  return data_ref;
}
Ejemplo n.º 14
0
herr_t alien_visitor2(hid_t did, unsigned dim, hid_t dsid, void *visitor_data)
{
   char name1[NC_MAX_NAME];
   H5G_stat_t statbuf;
   HDF5_OBJID_T *objid = visitor_data;

   if (H5Iget_name(did, name1, NC_MAX_NAME) < 0) ERR;
   /*printf("visiting did 0x%x dim %d dsid 0x%x name of did %s \n",  
     did, dim, dsid, name1); */

   /* Get obj id of the dimscale object. THis will be used later to
    * match dimensions to dimscales. */
   if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR;
   objid->fileno[0] = statbuf.fileno[0];
   objid->objno[0] = statbuf.objno[0];
   objid->fileno[1] = statbuf.fileno[1];
   objid->objno[1] = statbuf.objno[1];

   return 0;
}
Ejemplo n.º 15
0
herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid,
		     void *visitor_data)
{
   char name1[STR_LEN];
   H5G_stat_t statbuf;
   HDF5_OBJID_T *objid = visitor_data;

   /* This should get "/var1", the name of the dataset that the scale
    * is attached to. */
   if (H5Iget_name(did, name1, STR_LEN) < 0) ERR;
   if (strcmp(&name1[1], VAR1_NAME)) ERR;

   /* Get more info on the dimscale object.*/
   if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR;
   objid->fileno[0] = statbuf.fileno[0];
   objid->objno[0] = statbuf.objno[0];
   objid->fileno[1] = statbuf.fileno[1];
   objid->objno[1] = statbuf.objno[1];

   return 0;
}
Ejemplo n.º 16
0
/*-------------------------------------------------------------------------
 * Function:    toomany
 *
 * Purpose:     Build a file with too many symbolic links
 *
 * Return:      Success:        0
 *
 *              Failure:        -1
 *
 * Programmer:  Quincey Koziol
 *              Tuesday, August 9, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
toomany(hid_t fapl)
{
    hid_t		fid = (-1);     /* File ID */
    hid_t		gid = (-1);     /* Group ID */
    hid_t		gid2 = (-1);    /* Datatype ID */
    char                objname[NAME_BUF_SIZE];         /* Object name */
    ssize_t             name_len;       /* Length of object name */
    char		filename[NAME_BUF_SIZE]; 

    TESTING("too many links");

    /* Make certain test is valid */
    /* XXX: should probably make a "generic" test that creates the proper
     *          # of links based on this value - QAK
     */
    HDassert(H5G_NLINKS == 16);

    /* Create files */
    h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
    if((fid=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR;

    /* Create group with short name in file (used as target for hard links) */
    if((gid=H5Gcreate (fid, "final", (size_t)0))<0) TEST_ERROR;

    /* Create chain of hard links to existing object (no limit on #) */
    if(H5Glink2(fid, "final", H5G_LINK_HARD, fid, "hard1") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard1", H5G_LINK_HARD, fid, "hard2") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard2", H5G_LINK_HARD, fid, "hard3") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard3", H5G_LINK_HARD, fid, "hard4") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard4", H5G_LINK_HARD, fid, "hard5") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard5", H5G_LINK_HARD, fid, "hard6") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard6", H5G_LINK_HARD, fid, "hard7") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard7", H5G_LINK_HARD, fid, "hard8") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard8", H5G_LINK_HARD, fid, "hard9") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard9", H5G_LINK_HARD, fid, "hard10") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard10", H5G_LINK_HARD, fid, "hard11") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard11", H5G_LINK_HARD, fid, "hard12") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard12", H5G_LINK_HARD, fid, "hard13") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard13", H5G_LINK_HARD, fid, "hard14") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard14", H5G_LINK_HARD, fid, "hard15") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard15", H5G_LINK_HARD, fid, "hard16") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard16", H5G_LINK_HARD, fid, "hard17") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard17", H5G_LINK_HARD, fid, "hard18") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard18", H5G_LINK_HARD, fid, "hard19") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard19", H5G_LINK_HARD, fid, "hard20") < 0) TEST_ERROR;
    if(H5Glink2(fid, "hard20", H5G_LINK_HARD, fid, "hard21") < 0) TEST_ERROR;

    /* Create chain of soft links to existing object (limited) */
    if(H5Glink2(fid, "final", H5G_LINK_SOFT, fid, "soft1") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft1", H5G_LINK_SOFT, fid, "soft2") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft2", H5G_LINK_SOFT, fid, "soft3") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft3", H5G_LINK_SOFT, fid, "soft4") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft4", H5G_LINK_SOFT, fid, "soft5") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft5", H5G_LINK_SOFT, fid, "soft6") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft6", H5G_LINK_SOFT, fid, "soft7") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft7", H5G_LINK_SOFT, fid, "soft8") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft8", H5G_LINK_SOFT, fid, "soft9") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft9", H5G_LINK_SOFT, fid, "soft10") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft10", H5G_LINK_SOFT, fid, "soft11") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft11", H5G_LINK_SOFT, fid, "soft12") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft12", H5G_LINK_SOFT, fid, "soft13") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft13", H5G_LINK_SOFT, fid, "soft14") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft14", H5G_LINK_SOFT, fid, "soft15") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft15", H5G_LINK_SOFT, fid, "soft16") < 0) TEST_ERROR;
    if(H5Glink2(fid, "soft16", H5G_LINK_SOFT, fid, "soft17") < 0) TEST_ERROR;

    /* Close objects */
    if(H5Gclose(gid)<0) TEST_ERROR;
    if(H5Fclose(fid)<0) TEST_ERROR;

    /* Open file */
    if((fid=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0) TEST_ERROR;

    /* Open object through last hard link */
    if((gid = H5Gopen(fid, "hard21")) < 0) TEST_ERROR;

    /* Check name */
    if((name_len = H5Iget_name( gid, objname, (size_t)NAME_BUF_SIZE )) < 0) TEST_ERROR
    if(HDstrcmp(objname, "/hard21")) TEST_ERROR

    /* Create object in hard-linked group */
    if((gid2 = H5Gcreate(gid, "new_hard", (size_t)0)) < 0) TEST_ERROR

    /* Close group in hard-linked group */
    if(H5Gclose(gid2) < 0) TEST_ERROR

    /* Close hard-linked object */
    if(H5Gclose(gid) < 0) TEST_ERROR;

    /* Open object through too deep soft link */
    H5E_BEGIN_TRY {
        gid = H5Gopen(fid, "soft17");
    } H5E_END_TRY;
    if (gid >= 0) {
	H5_FAILED();
	puts("    Should have failed for sequence of too many nested links.");
	goto error;
    }

    /* Open object through lesser soft link */
    if((gid = H5Gopen(fid, "soft16")) < 0) TEST_ERROR;

    /* Check name */
    if((name_len = H5Iget_name( gid, objname, (size_t)NAME_BUF_SIZE )) < 0) TEST_ERROR
    if(HDstrcmp(objname, "/soft16")) TEST_ERROR

    /* Create object in external file */
    if((gid2 = H5Gcreate(gid, "new_soft", (size_t)0)) < 0) TEST_ERROR

    /* Close group in external file */
    if(H5Gclose(gid2) < 0) TEST_ERROR

    /* Close external object */
    if(H5Gclose(gid) < 0) TEST_ERROR;

    /* Close first file */
    if(H5Fclose(fid)<0) TEST_ERROR;

    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
    	H5Gclose (gid2);
    	H5Gclose (gid);
    	H5Fclose (fid);
    } H5E_END_TRY;
    return -1;
} /* end toomany() */
Ejemplo n.º 17
0
int
main (void)
{
    hid_t       file, space, dset, obj, attr;   /* Handles */
    herr_t      status;
    hsize_t     dims[1] = {DIM0};
    hobj_ref_t  wdata[DIM0],                    /* Write buffer */
                *rdata;                         /* Read buffer */
    H5G_obj_t   objtype;
    ssize_t     size;
    char        *name;
    int         ndims,
                i;

    /*
     * Create a new file using the default properties.
     */
    file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Create a dataset with a scalar dataspace.
     */
    space = H5Screate (H5S_SCALAR);
    obj = H5Dcreate (file, "DS2", H5T_STD_I32LE, space, H5P_DEFAULT);
    status = H5Dclose (obj);
    status = H5Sclose (space);

    /*
     * Create a group.
     */
    obj = H5Gcreate (file, "G1", H5P_DEFAULT);
    status = H5Gclose (obj);

    /*
     * Create references to the previously created objects.  Passing -1
     * as space_id causes this parameter to be ignored.  Other values
     * besides valid dataspaces result in an error.
     */
    status = H5Rcreate (&wdata[0], file, "G1", H5R_OBJECT, -1);
    status = H5Rcreate (&wdata[1], file, "DS2", H5R_OBJECT, -1);

    /*
     * Create dataset with a scalar dataspace to serve as the parent
     * for the attribute.
     */
    space = H5Screate (H5S_SCALAR);
    dset = H5Dcreate (file, DATASET, H5T_STD_I32LE, space, H5P_DEFAULT);
    status = H5Sclose (space);

    /*
     * Create dataspace.  Setting maximum size to NULL sets the maximum
     * size to be the current size.
     */
    space = H5Screate_simple (1, dims, NULL);

    /*
     * Create the attribute and write the object references to it.
     */
    attr = H5Acreate (dset, ATTRIBUTE, H5T_STD_REF_OBJ, space, H5P_DEFAULT);
    status = H5Awrite (attr, H5T_STD_REF_OBJ, wdata);

    /*
     * Close and release resources.
     */
    status = H5Aclose (attr);
    status = H5Dclose (dset);
    status = H5Sclose (space);
    status = H5Fclose (file);


    /*
     * Now we begin the read section of this example.  Here we assume
     * the attribute has the same name and rank, but can have any size.
     * Therefore we must allocate a new array to read in data using
     * malloc().
     */

    /*
     * Open file, dataset, and attribute.
     */
    file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
    dset = H5Dopen (file, DATASET);
    attr = H5Aopen_name (dset, ATTRIBUTE);

    /*
     * Get dataspace and allocate memory for read buffer.
     */
    space = H5Aget_space (attr);
    ndims = H5Sget_simple_extent_dims (space, dims, NULL);
    rdata = (hobj_ref_t *) malloc (dims[0] * sizeof (hobj_ref_t));

    /*
     * Read the data.
     */
    status = H5Aread (attr, H5T_STD_REF_OBJ, rdata);

    /*
     * Output the data to the screen.
     */
    for (i=0; i<dims[0]; i++) {
        printf ("%s[%d]:\n  ->", ATTRIBUTE, i);

        /*
         * Open the referenced object, get its name and type.
         */
        obj = H5Rdereference (dset, H5R_OBJECT, &rdata[i]);
        objtype = H5Rget_obj_type (dset, H5R_OBJECT, &rdata[i]);

        /*
         * Get the length of the name, allocate space, then retrieve
         * the name.
         */
        size = 1 + H5Iget_name (obj, NULL, 0);
        if (size > 1) {
            name = (char *) malloc (size);
            size = 1 + H5Iget_name (obj, name, size);
        }

        /*
         * Print the object type and close the object.
         */
        switch (objtype) {
            case H5G_GROUP:
                printf ("Group");
                status = H5Gclose (obj);
                break;
            case H5G_DATASET:
                printf ("Dataset");
                status = H5Dclose (obj);
                break;
            case H5G_TYPE:
                printf ("Named Datatype");
                status = H5Tclose (obj);
        }

        /*
         * Print the name and deallocate space for the name.
         */
        if (size > 1) {
            printf (": %s", name);
            free (name);
        }
        printf ("\n");
    }

    /*
     * Close and release resources.
     */
    free (rdata);
    status = H5Aclose (attr);
    status = H5Dclose (dset);
    status = H5Sclose (space);
    status = H5Fclose (file);

    return 0;
}
Ejemplo n.º 18
0
SWIGEXPORT hid_t JNICALL Java_permafrost_hdf_libhdf_ObjectLibExtensionJNI_JHOopen_1by_1idx(
	JNIEnv *jenv, 
	jclass jcls, 
	jint loc_id, 
	jstring group_name,
	jint idx_type, 
	jint order, 
	jlong n, 
	jint lapl_id, 
	jintArray type, 
	jobjectArray name
	) {
		jint sz = 0;
		char* pGroupName = NULL;
		hid_t obj_id = -1;
		jint jiType;
		char* pName = NULL;
		char* tmpName = NULL;
		const int szName = 64;
		int lenName = 0;
		jstring jname;

		if (!group_name) {
			SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "Null group name.");
			return (-1);
		} else if (!type) {
			SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "Null type array.");
			return (-1);
		} else if (!name) {
			SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "Null object name array.");
			return (-1);
		}
		sz = (*jenv)->GetArrayLength(jenv, type);
		if (sz < 1) {
			SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "Zero-length type array.");
			return (-1);
		}
		sz = (*jenv)->GetArrayLength(jenv, name);
		if (sz < 1) {
			SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "Zero-length object name array.");
			return (-1);
		}

		pGroupName = (char *)(*jenv)->GetStringUTFChars(jenv, group_name, 0);
		if (!pGroupName) return -1;
		
		obj_id = H5Oopen_by_idx(
			(hid_t)loc_id, 
			pGroupName, 
			(H5_index_t) idx_type, 
			(H5_iter_order_t) order,
			(hsize_t) n, 
			(hid_t) lapl_id
			);

		if (pGroupName) (*jenv)->ReleaseStringUTFChars(jenv, group_name, (const char *) pGroupName);
		if (obj_id <= 0) return (obj_id);

		jiType = (jint) H5Iget_type(obj_id);
		(*jenv)->SetIntArrayRegion(jenv, type, 0, 1, &jiType);

		pName = (char*) calloc(szName, sizeof(char));
		lenName = H5Iget_name(obj_id, pName, szName-1);
		if (lenName >= szName) {
			char* tmpName = (char*) realloc(pName, sizeof(char)*lenName+1);
			if (!tmpName) {
				free(pName);
				pName = NULL;
				H5Oclose(loc_id);
				return (-1);
			}
			pName = tmpName;
			lenName = H5Iget_name(obj_id, pName, lenName);
		}
		jname = (*jenv)->NewStringUTF(jenv, pName);
		(*jenv)->SetObjectArrayElement(jenv, name, 0, jname);
		
		free(pName);
		
		return (obj_id);
}
Ejemplo n.º 19
0
/*--------------------------------------------------------------*/
static void validateLink(pNXVcontext self, hid_t groupID,
		xmlChar *name, xmlChar *target)
{
	hid_t objID;
	herr_t att;
	char linkTarget[512], dataPath[512];
  char nxdlPath[512], curPath[512];

	/*
		set our path for correct error printing
	*/
	snprintf(nxdlPath,sizeof(nxdlPath),"%s/%s", self->nxdlPath,
		(char *)name);
	NXVsetLog(self,"nxdlPath",nxdlPath);
	H5Iget_name(groupID,curPath,sizeof(curPath));
	snprintf(dataPath,sizeof(dataPath),"%s/%s", curPath,
		(char *)name);
	NXVsetLog(self,"dataPath",dataPath);

	/*
		log what we are doing
	*/
	NXVsetLog(self,"sev","debug");
	NXVprintLog(self,"message","Validating link %s at %s",
		(char *)name, (char *)target);
	NXVlog(self);

	/*
		now we really validate
	*/
	if(H5LTpath_valid(groupID,(char *)name, 1)){
		/*
		  The positive test means that the link exists and is pointing to
			a valid HDF5 object. This is alread good.
		*/
		objID = H5Oopen(groupID,(char *)name,H5P_DEFAULT);
		assert(objID >= 0); /* we just tested for existence, didn't we? */
		memset(linkTarget,0,sizeof(linkTarget));
		att = H5NXget_attribute_string(groupID,(char *)name,"target",linkTarget);
		if(att < 0){
				NXVsetLog(self,"sev","error");
				H5Iget_name(objID,dataPath,sizeof(dataPath));
				NXVsetLog(self,"dataPath",dataPath);
				NXVsetLog(self,"message","Link is missing required attribute target");
				NXVlog(self);
				self->errCount++;
		} else {
			/*
				test that the target attribute really points to something
				real. It could be that the link was done right but the
				target attribute set sloppily.
			*/
			if(!H5LTpath_valid(self->fileID,linkTarget,1)){
				NXVsetLog(self,"sev","error");
				H5Iget_name(objID,dataPath,sizeof(dataPath));
				NXVsetLog(self,"dataPath",dataPath);
				NXVprintLog(self,"message","Link target %s is invalid",
					linkTarget);
				NXVlog(self);
				self->errCount++;
			} else {
				validateLinkTarget(self,target,linkTarget);
			}
		}
		H5Oclose(objID);
	} else {
		NXVsetLog(self,"sev","error");
		NXVprintLog(self,"message",
			"Required link %s missing or not pointing to an HDF5 object",
			(char *)name);
		NXVlog(self);
		self->errCount++;
	}
}
Ejemplo n.º 20
0
static void validateGroupAttributes(pNXVcontext self,
	hid_t groupID, xmlNodePtr groupNode)
{
	xmlNodePtr cur;
	xmlChar *type, *name;
	herr_t attID;
	char data[512], gname[512];

	memset(data,0,sizeof(data));
	memset(gname,0,sizeof(gname));
	H5Iget_name(groupID,gname,sizeof(gname));

	type = xmlGetProp(groupNode,(xmlChar *)"type");
	attID = H5NXget_attribute_string(groupID,gname,"NX_class",data);
	if(attID < 0){
		NXVsetLog(self,"sev","error");
		NXVsetLog(self,"message","Required group attribute NX_class missing");
		NXVlog(self);
		self->errCount++;
	} else {
		if(strcmp(data,(char *)type) != 0){
			/*
				accept NXsubentry if NXentry is asked for
			*/
			if(!(strcmp((char *)type,"NXentry") == 0 &&
		 	strcmp(data,"NXsubentry") == 0)){
				NXVsetLog(self,"sev","error");
				NXVprintLog(self,"message","Wrong group type, expected %s, got %s",
				(char *)type, data);
				NXVlog(self);
				self->errCount++;
			}
		}
	}
	xmlFree(type);

	/*
		search attribute child nodes
	*/
	cur = groupNode->xmlChildrenNode;
	while(cur != NULL){
		if(xmlStrcmp(cur->name, (xmlChar *)"attribute") == 0){
			name = xmlGetProp(cur,(xmlChar *)"name");
			if(!H5LTfind_attribute(groupID,(char *)name)){
					NXVsetLog(self,"sev","error");
					NXVprintLog(self,"message","Required group attribute %s missing",
					name);
					NXVlog(self);
					self->errCount++;
			} else {
				/*
					TODO validate attribute data.
					As we do not use group attributes heavily, deferred for
					now
				*/
			}
			xmlFree(name);
		}
		cur = cur->next;
	}
}
Ejemplo n.º 21
0
hid_t dat1Reopen( hid_t file_id, unsigned int flags, hid_t fapl,
                  int *status ){

/* Local Variables; */
   HDSLoc **loc;
   HDSLoc **loclist;
   char **paths;
   char file[EMS__SZMSG+1];
   char path[EMS__SZMSG+1];
   hid_t *file_ids;
   hid_t id;
   int *isgroup;
   int iloc;
   int nlev;
   int nloc;
   ssize_t size;

/* Return immediately if an error has already occurred. */
   if( *status != SAI__OK ) return file_id;

/* Get a list of any active locators associated with the file. Also get a
   list of file_ids for the same file that have associated locators. */
   hds1GetLocators( file_id, &nloc, &loclist, &file_ids, status );

/* Check that none of the locators are mapped. */
   if( *status == SAI__OK ) {
      loc = loclist;
      for( iloc = 0; iloc < nloc; iloc++,loc++ ) {
         if( (*loc)->regpntr ) {
            hdsTrace( (*loc), &nlev, path, file, status, sizeof(path), sizeof(file) );
            *status = DAT__PRMAP;
            emsRepf( " ", "hdsOpen: Cannot re-open '%s' in read-write mode "
                     "since '%s' is currently mapped.", status, file, path );
            break;
         }
      }
   }

/* Store the path to the HDF5 object associated with each active locator,
   and also a flag indicating if the HDF5 object is a group or dataset.
   Then close the HDF5 objects. */
   paths = MEM_CALLOC( nloc, sizeof( *paths ) );
   isgroup = MEM_CALLOC( nloc, sizeof( *isgroup ) );
   if( paths && isgroup && *status == SAI__OK ) {
      loc = loclist;
      for( iloc = 0; iloc < nloc; iloc++,loc++ ) {
         if( (*loc)->group_id ) {
            isgroup[ iloc ] = 1;
            id = (*loc)->group_id;
         } else {
            isgroup[ iloc ] = 0;
            id = (*loc)->dataset_id;
         }
         if( id ) {
            size = H5Iget_name( id, NULL, 0 );
            paths[ iloc ] = MEM_CALLOC( size + 1, 1 );
            H5Iget_name( id, paths[ iloc ], size + 1 );
         } else {
            hdsTrace( (*loc), &nlev, path, file, status, sizeof(path), sizeof(file) );
            *status = DAT__FATAL;
            emsRepf( " ", "hdsOpen: Locator for '%s.%s' has no group or "
                     "dataset so cannot be reopened.", status, file, path );
            break;
         }
         if( H5Oclose( id ) < 0 ) {
            hdsTrace( (*loc), &nlev, path, file, status, sizeof(path), sizeof(file) );
            *status = DAT__FATAL;
            dat1H5EtoEMS( status );
            emsRepf( " ", "hdsOpen: Failed to close HDF5 object for '%s.%s'.",
                     status, file, path );
            break;
         }
      }
   }

/* Get the path for the file. */
   H5Fget_name( file_id, path, sizeof(path) );

/* Close all HDF5 file_ids associated with file. */
   if( *status == SAI__OK ) {
      int this_closed = 0;

      int i = -1;
      while( file_ids[ ++i ] ) {

         if( file_ids[ i ] == file_id ) this_closed = 1;

         if( H5Fclose( file_ids[ i ] ) < 0 ) {
            *status = DAT__FATAL;
            dat1H5EtoEMS( status );
            emsRepf( " ", "hdsOpen: Failed to close file '%s' prior to "
                     "re-opening it.", status, path );
            break;
         }
      }

/* Close the supplied file_id if it has not already been closed. */
      if( !this_closed ) {
         if( H5Fclose( file_id ) < 0 ) {
            *status = DAT__FATAL;
            dat1H5EtoEMS( status );
            emsRepf( " ", "hdsOpen: Failed to close file '%s' prior to "
                     "re-opening it.", status, path );
         }
      }
   }

/* Re-open it. */
   if( *status == SAI__OK ) {
      file_id = H5Fopen( path, flags, fapl );
      if( file_id < 0 ) {
         *status = DAT__FATAL;
         dat1H5EtoEMS( status );
         emsRepf( " ", "hdsOpen: Failed to reopen file '%s'.",
                  status, path );
      }
   }

/* Update the file, group and dataset id in each locator. */
   if( *status == SAI__OK ) {
      loc = loclist;
      for( iloc = 0; iloc < nloc; iloc++,loc++ ) {
         hds1SetFileId( (*loc), file_id, status );
         if( isgroup[ iloc ] ) {
            (*loc)->group_id = H5Gopen2( file_id, paths[ iloc ], H5P_DEFAULT );
         } else {
            (*loc)->dataset_id = H5Dopen2( file_id, paths[ iloc ], H5P_DEFAULT );
         }
      }
   }

/* Free resources. */
   if( paths ) {
      for( iloc = 0; iloc < nloc; iloc++ ) {
         MEM_FREE( paths[ iloc ] );
      }
      MEM_FREE( paths );
   }
   if( isgroup ) MEM_FREE( isgroup );
   if( loclist ) MEM_FREE( loclist );
   if( file_ids ) MEM_FREE( file_ids );

/* Return the new file id. */
   return file_id;
}
Ejemplo n.º 22
0
/* Test basic functionality of registering and deleting types and IDs */
static int basic_id_test(void)
{
    H5I_type_t myType = H5I_BADID;
    hid_t arrayID = H5I_INVALID_HID;
    void* testObj = NULL;
    void* testPtr = NULL;
    char nameString[10];
    hid_t testID;
    ssize_t testSize = -1;
    herr_t err;
    int num_ref;
    hsize_t num_members;


    /* Try to register an ID with ficticious types */
    H5E_BEGIN_TRY
    arrayID = H5Iregister((H5I_type_t) 420, testObj);
    H5E_END_TRY

    VERIFY(arrayID, H5I_INVALID_HID, "H5Iregister");
    if(arrayID != H5I_INVALID_HID)
        goto out;

    H5E_BEGIN_TRY
    arrayID = H5Iregister((H5I_type_t) -1, testObj);
    H5E_END_TRY

    VERIFY(arrayID, H5I_INVALID_HID, "H5Iregister");
    if(arrayID != H5I_INVALID_HID)
        goto out;

    /* Try to access IDs with ficticious types */
    H5E_BEGIN_TRY
    testPtr = H5Iobject_verify((hid_t)100, (H5I_type_t) 0);
    H5E_END_TRY

    VERIFY(testPtr, NULL, "H5Iobject_verify");
    if(testPtr != NULL)
        goto out;

    H5E_BEGIN_TRY
    testPtr = H5Iobject_verify((hid_t)700, (H5I_type_t) 700);
    H5E_END_TRY

    VERIFY(testPtr, NULL, "H5Iobject_verify");
    if(testPtr != NULL)
        goto out;

    /* Register a type */
    myType = H5Iregister_type((size_t)64, 0, (H5I_free_t) free );

    CHECK(myType, H5I_BADID, "H5Iregister_type");
    if(myType == H5I_BADID)
        goto out;

    /* Register an ID and retrieve the object it points to.
     * Once the ID has been registered, testObj will be freed when
         * its ID type is destroyed. */
    testObj = HDmalloc(7 * sizeof(int));
    arrayID = H5Iregister(myType, testObj);

    CHECK(arrayID, H5I_INVALID_HID, "H5Iregister");
    if(arrayID == H5I_INVALID_HID)
    {
        HDfree(testObj);
        goto out;
    }

    testPtr = (int *) H5Iobject_verify(arrayID, myType);

    VERIFY(testPtr, testObj, "H5Iobject_verify");
    if(testPtr != testObj)
        goto out;

    /* Ensure that H5Iget_file_id and H5Iget_name() fail, since this
         * is an hid_t for the wrong kind of object */
    H5E_BEGIN_TRY
    testID = H5Iget_file_id(arrayID);
    H5E_END_TRY

    VERIFY(testID, H5I_INVALID_HID, "H5Iget_file_id");
    if(testID != H5I_INVALID_HID)
        goto out;

    H5E_BEGIN_TRY
    testSize = H5Iget_name(arrayID, nameString, (size_t)9);
    H5E_END_TRY

    VERIFY(testSize, -1, "H5Iget_name");
    if(testSize != -1)
        goto out;

    /* Make sure H5Iremove_verify catches objects of the wrong type */
    H5E_BEGIN_TRY
    testPtr = (int*) H5Iremove_verify(arrayID, (H5I_type_t) 0);
    H5E_END_TRY

    VERIFY(testPtr, NULL, "H5Iremove_verify");
    if(testPtr != NULL)
        goto out;

    H5E_BEGIN_TRY
    testPtr = (int*) H5Iremove_verify(arrayID, (H5I_type_t) ((int) myType-1));
    H5E_END_TRY

    VERIFY(testPtr, NULL, "H5Iremove_verify");
    if(testPtr != NULL)
        goto out;

    /* Remove an ID and make sure we can't access it */
    testPtr = (int*) H5Iremove_verify(arrayID, myType);

    CHECK(testPtr, NULL, "H5Iremove_verify");
    if(testPtr == NULL)
        goto out;

    H5E_BEGIN_TRY
    testPtr = (int*) H5Iobject_verify(arrayID, myType);
    H5E_END_TRY

    VERIFY(testPtr, NULL, "H5Iobject_verify");
    if(testPtr != NULL)
        goto out;

    /* Delete the type and make sure we can't access objects within it */
    arrayID = H5Iregister(myType, testObj);

    err = H5Idestroy_type(myType);
    VERIFY(err, 0, "H5Idestroy_type");
    if( err != 0)
        goto out;
    VERIFY(H5Itype_exists(myType), 0, "H5Itype_exists");
    if(H5Itype_exists(myType) != 0)
        goto out;

    H5E_BEGIN_TRY
    VERIFY(H5Inmembers(myType, NULL), -1, "H5Inmembers");
    if(H5Inmembers(myType, NULL) != -1)
        goto out;
    H5E_END_TRY

    /* Register another type and another object in that type */
    myType = H5Iregister_type((size_t)64, 0, (H5I_free_t) free );

    CHECK(myType, H5I_BADID, "H5Iregister_type");
    if(myType == H5I_BADID)
        goto out;

    /* The memory that testObj pointed to should already have been
     * freed when the previous type was destroyed.  Allocate new
     * memory for it.
         */
    testObj = HDmalloc(7 * sizeof(int));
    arrayID = H5Iregister(myType, testObj);

    CHECK(arrayID, H5I_INVALID_HID, "H5Iregister");
    if(arrayID == H5I_INVALID_HID)
    {
        HDfree(testObj);
        goto out;
    }

    err = H5Inmembers(myType, &num_members);
    CHECK(err, -1, "H5Inmembers");
    if (err < 0)
        goto out;
    VERIFY(num_members, 1, "H5Inmembers");
    if(num_members != 1)
        goto out;

    /* Increment references to type and ensure that dec_type_ref
    	doesn't destroy the type */
    num_ref = H5Iinc_type_ref(myType);
    VERIFY(num_ref, 2, "H5Iinc_type_ref");
    if( num_ref != 2)
        goto out;
    num_ref = H5Idec_type_ref(myType);
    VERIFY(num_ref, 1, "H5Idec_type_ref");
    if(num_ref != 1)
        goto out;
    err = H5Inmembers(myType, &num_members);
    CHECK(err, -1, "H5Inmembers");
    if (err < 0)
        goto out;
    VERIFY(num_members, 1, "H5Inmembers");
    if(num_members != 1)
        goto out;

    /* This call to dec_type_ref should destroy the type */
    num_ref = H5Idec_type_ref(myType);
    VERIFY(num_ref, 0, "H5Idec_type_ref");
    if(num_ref != 0)
        goto out;
    VERIFY(H5Itype_exists(myType), 0, "H5Itype_exists");
    if (H5Itype_exists(myType) != 0)
        goto out;

    H5E_BEGIN_TRY
    err = H5Inmembers(myType, &num_members);
    if(err >= 0)
        goto out;
    H5E_END_TRY

    return 0;

out:
    /* Clean up type if it has been allocated and free memory used
         * by testObj */
    if(myType >= 0)
        H5Idestroy_type(myType);

    return -1;
}
Ejemplo n.º 23
0
int main(void)
{
    hid_t file_id;        /* file identifier */
    hid_t space_id;       /* dataspace identifiers */
    hid_t spacer_id;
    hid_t dsetv_id;       /*dataset identifiers*/
    hid_t dsetr_id;
    hsize_t dims[2] =  {2,9};
    hsize_t dimsr[1] =  {2};
    int rank = 2;
    int rankr =1;
    herr_t status;
    hdset_reg_ref_t ref[2];
    hdset_reg_ref_t ref_out[2];
    int data[2][9] = {{1,1,2,3,3,4,5,5,6},{1,2,2,3,4,4,5,6,6}};
    int data_out[2][9] = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0}};
    hsize_t start[2];
    hsize_t count[2];
    hsize_t coord[2][3] = {{0, 0, 1}, {6, 0, 8}};
    unsigned num_points = 3;
    int i, j;
    size_t name_size1, name_size2;
    char buf1[10], buf2[10];

    /*
     * Create file with default file access and file creation properties.
     */
    file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Create dataspace for datasets.
     */
    space_id = H5Screate_simple(rank, dims, NULL);
    spacer_id = H5Screate_simple(rankr, dimsr, NULL);

    /*
     * Create integer dataset.
     */
    dsetv_id = H5Dcreate2(file_id, dsetnamev, H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Write data to the dataset.
     */
    status = H5Dwrite(dsetv_id, H5T_NATIVE_INT, H5S_ALL , H5S_ALL, H5P_DEFAULT,data);
    status = H5Dclose(dsetv_id);

    /*
     * Dataset with references.
     */
    dsetr_id = H5Dcreate2(file_id, dsetnamer, H5T_STD_REF_DSETREG, spacer_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Create a reference to the hyperslab.
     */
    start[0] = 0;
    start[1] = 3;
    count[0] = 2;
    count[1] = 3;
    status = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start, NULL, count, NULL);
    status = H5Rcreate(&ref[0], file_id, dsetnamev, H5R_DATASET_REGION, space_id);

    /*
     * Create a reference to elements selection.
     */
    status = H5Sselect_none(space_id);
    status = H5Sselect_elements(space_id, H5S_SELECT_SET, num_points, (const hsize_t *)coord);
    status = H5Rcreate(&ref[1], file_id, dsetnamev, H5R_DATASET_REGION, space_id);

    /*
     * Write dataset with the references.
     */
    status = H5Dwrite(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT,ref);

    /*
     * Close all objects.
     */
    status = H5Sclose(space_id);
    status = H5Sclose(spacer_id);
    status = H5Dclose(dsetr_id);
    status = H5Fclose(file_id);

    /*
     * Reopen the file to read selections back.
     */
    file_id = H5Fopen(filename, H5F_ACC_RDWR,  H5P_DEFAULT);

    /*
     * Reopen the dataset with object references and read references
     * to the buffer.
     */
    dsetr_id = H5Dopen2(file_id, dsetnamer, H5P_DEFAULT);

    status = H5Dread(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL,
                   H5P_DEFAULT, ref_out);

    /*
     * Dereference the first reference.
     */
    dsetv_id = H5Rdereference2(dsetr_id, H5P_DEFAULT, H5R_DATASET_REGION, &ref_out[0]);
    /*
     * Get name of the dataset the first region reference points to
     * using H5Rget_name
     */
    name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], (char*)buf1, 10);
    printf(" Dataset's name (returned by H5Rget_name) the reference points to is %s, name length is %d\n", buf1, (int)name_size1);
    /*
     * Get name of the dataset the first region reference points to
     * using H5Iget_name
     */
    name_size2 = H5Iget_name(dsetv_id, (char*)buf2, 10);
    printf(" Dataset's name (returned by H5Iget_name) the reference points to is %s, name length is %d\n", buf2, (int)name_size2);

    space_id = H5Rget_region(dsetr_id, H5R_DATASET_REGION,&ref_out[0]);

    /*
     * Read and display hyperslab selection from the dataset.
     */

    status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id,
                   H5P_DEFAULT, data_out);
    printf("Selected hyperslab: ");
    for (i = 0; i <= 1; i++)
    {
        printf("\n");
        for (j = 0; j <= 8; j++)
            printf("%d ", data_out[i][j]);
    }
    printf("\n");

    /*
     * Close dataspace and the dataset.
     */
    status = H5Sclose(space_id);
    status = H5Dclose(dsetv_id);

    /*
     * Initialize data_out array again to get point selection.
     */
    for (i = 0; i <= 1; i++)
        for (j = 0; j <= 8; j++)
            data_out[i][j] = 0;

    /*
     * Dereference the second reference.
     */
    dsetv_id = H5Rdereference2(dsetr_id, H5P_DEFAULT, H5R_DATASET_REGION, &ref_out[1]);
    space_id = H5Rget_region(dsetv_id, H5R_DATASET_REGION,&ref_out[1]);

    /*
     * Read selected data from the dataset.
     */

    status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id,
                   H5P_DEFAULT, data_out);
    printf("Selected points: ");
    for (i = 0; i <= 1; i++)
    {
        printf("\n");
        for (j = 0; j <= 8; j++)
            printf("%d ", data_out[i][j]);
    }
    printf("\n");

    /*
     * Close dataspace and the dataset.
     */
    status = H5Sclose(space_id);
    status = H5Dclose(dsetv_id);
    status = H5Dclose(dsetr_id);
    status = H5Fclose(file_id);

    return 0;
}
Ejemplo n.º 24
0
/*--------------------------------------------------------------*/
static void validateDependsOnField(pNXVcontext self,
		hid_t groupID,hid_t dpFieldID)
{
	char fname[512], transData[512];
	hid_t attID, attType, attSpace, dpField;
	H5T_class_t h5class;

	memset(fname,0,sizeof(fname));
	memset(transData,0,sizeof(transData));

	H5Iget_name(dpFieldID,fname,sizeof(fname));
	NXVsetLog(self,"dataPath", fname);
	NXVsetLog(self,"sev","debug");
	NXVprintLog(self,"message","Validating depends_on element %s", fname);
	NXVlog(self);

	/*
		validate the simple ones
	*/
	validateDependsOnAttributes(self,dpFieldID);

	/*
		follow the depends_on chain
	*/
	if(!H5LTfind_attribute(dpFieldID,"depends_on")){
			NXVsetLog(self,"sev","error");
			NXVprintLog(self,"message",
				"Missing attribute depends_on on %s",
				fname);
			NXVlog(self);
			self->errCount++;
	} else {
		attID = H5Aopen(dpFieldID,"depends_on",H5P_DEFAULT);
		assert(attID >= 0);
		attType = H5Aget_type(attID);
		assert(attType >= 0);
		h5class = H5Tget_class(attType);
		if(h5class != H5T_STRING){
			NXVsetLog(self,"sev","error");
			NXVprintLog(self,"message",
				"depends_onattribute on %s is of wrong type, expected string",
				fname);
			NXVlog(self);
			self->errCount++;
		} else {
			H5NXget_attribute_string(self->fileID, fname,
					"depends_on",transData);
			if(strcmp(transData,".") == 0){
				H5Dclose(dpFieldID);
				return;
			} else {
				dpField = findDependentField(self,dpFieldID,transData);
				if(dpField < 0){
						NXVsetLog(self,"sev","error");
						NXVprintLog(self,"message","Dependency chain broken at %s, %s %s",
					 		fname, transData, "pointing nowhere (nirvana?)");
						NXVlog(self);
						self->errCount++;
				} else {
					validateDependsOnField(self,groupID,dpField);
					H5Dclose(dpField);
				}
			}
		}
	}
}
Ejemplo n.º 25
0
//-*****************************************************************************
ArImpl::~ArImpl()
{

    m_data.reset();

    if ( m_file >= 0 )
    {
        int dsetCount = H5Fget_obj_count( m_file,
            H5F_OBJ_LOCAL | H5F_OBJ_DATASET);
        int grpCount = H5Fget_obj_count( m_file,
            H5F_OBJ_LOCAL | H5F_OBJ_GROUP );
        int dtypCount = H5Fget_obj_count( m_file,
            H5F_OBJ_LOCAL | H5F_OBJ_DATATYPE );
        int attrCount = H5Fget_obj_count( m_file,
            H5F_OBJ_LOCAL | H5F_OBJ_ATTR );

        int objCount = dsetCount + grpCount + dtypCount + attrCount;

        if ( objCount != 0 )
        {
            std::stringstream strm;
            strm << "Open HDF5 handles detected during reading:" << std::endl
                 << "DataSets: " << dsetCount
                 << ", Groups: " << grpCount
                 << ", DataTypes: " << dtypCount
                 << ", Attributes: " << attrCount;

            std::vector< hid_t > objList;

            // when getting the name corresponding to a hid_t, the get_name
            // functions always append a NULL character, which we strip off
            // when injecting into out stream.
            std::string name;

            if ( dsetCount > 0 )
            {
                strm << std::endl << "DataSets: " << std::endl;
                objList.resize( dsetCount );
                H5Fget_obj_ids( m_file, H5F_OBJ_LOCAL | H5F_OBJ_DATASET,
                    dsetCount, &objList.front() );
                for ( int i = 0; i < dsetCount; ++i )
                {
                    int strLen = H5Iget_name( objList[i], NULL, 0 ) + 1;
                    name.resize( strLen );
                    H5Iget_name( objList[i], &(name[0]), strLen );
                    strm << name.substr(0, name.size() - 1) << std::endl;
                }
            }

            if ( grpCount > 0 )
            {
                strm << std::endl << std::endl << "Groups:" << std::endl;
                objList.resize( grpCount );
                H5Fget_obj_ids( m_file, H5F_OBJ_LOCAL | H5F_OBJ_GROUP,
                    grpCount, &objList.front() );
                for ( int i = 0; i < grpCount; ++i )
                {
                    int strLen = H5Iget_name( objList[i], NULL, 0 ) + 1;
                    name.resize( strLen );
                    H5Iget_name( objList[i], &(name[0]), strLen );
                    strm << std::endl << name.substr(0, name.size() - 1);
                }
            }

            if ( attrCount > 0 )
            {
                strm << std::endl << std::endl << "Attrs:" << std::endl;
                objList.resize( attrCount );
                H5Fget_obj_ids( m_file, H5F_OBJ_LOCAL | H5F_OBJ_ATTR,
                    attrCount, &objList.front() );
                for ( int i = 0; i < attrCount; ++i )
                {
                    int strLen = H5Aget_name( objList[i], 0, NULL ) + 1;
                    name.resize( strLen );
                    H5Aget_name( objList[i], strLen, &(name[0]) );
                    strm << std::endl << name.substr(0, name.size() - 1);
                }
            }

            // just for formatting purposes
            if ( dtypCount > 0 )
            {
                strm << std::endl;
            }

            m_file = -1;
            ABCA_THROW( strm.str() );
        }

        H5Fclose( m_file );
        m_file = -1;
    }
}
Ejemplo n.º 26
0
int
main (void)
{
    hid_t               file, space, memspace, dset, dset2, attr;
                                                    /* Handles */
    herr_t              status;
    hsize_t             dims[1] = {DIM0},
                        dims2[2] = {DS2DIM0, DS2DIM1},
                        coords[4][2] = { {0,  1},
                                         {2, 11},
                                         {1,  0},
                                         {2,  4} },
                        start[2] = {0, 0},
                        stride[2] = {2, 11},
                        count[2] = {2, 2},
                        block[2] = {1, 3};
    hssize_t            npoints;
    hdset_reg_ref_t     wdata[DIM0],                /* Write buffer */
                        *rdata;                     /* Read buffer */
    ssize_t             size;
    char                wdata2[DS2DIM0][DS2DIM1] = {"The quick brown",
                                                    "fox jumps over ",
                                                    "the 5 lazy dogs"},
                        *rdata2,
                        *name;
    int                 ndims,
                        i;

    /*
     * Create a new file using the default properties.
     */
    file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /*
     * Create a dataset with character data.
     */
    space = H5Screate_simple (2, dims2, NULL);
    dset2 = H5Dcreate (file, DATASET2, H5T_STD_I8LE, space, H5P_DEFAULT,
                H5P_DEFAULT, H5P_DEFAULT);
    status = H5Dwrite (dset2, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                wdata2);

    /*
     * Create reference to a list of elements in dset2.
     */
    status = H5Sselect_elements (space, H5S_SELECT_SET, 4, coords[0]);
    status = H5Rcreate (&wdata[0], file, DATASET2, H5R_DATASET_REGION, space);

    /*
     * Create reference to a hyperslab in dset2, close dataspace.
     */
    status = H5Sselect_hyperslab (space, H5S_SELECT_SET, start, stride, count,
                block);
    status = H5Rcreate (&wdata[1], file, DATASET2, H5R_DATASET_REGION, space);
    status = H5Sclose (space);

    /*
     * Create dataset with a null dataspace to serve as the parent for
     * the attribute.
     */
    space = H5Screate (H5S_NULL);
    dset = H5Dcreate (file, DATASET, H5T_STD_I32LE, space, H5P_DEFAULT,
                H5P_DEFAULT, H5P_DEFAULT);
    status = H5Sclose (space);

    /*
     * Create dataspace.  Setting maximum size to NULL sets the maximum
     * size to be the current size.
     */
    space = H5Screate_simple (1, dims, NULL);

    /*
     * Create the attribute and write the region references to it.
     */
    attr = H5Acreate (dset, ATTRIBUTE, H5T_STD_REF_DSETREG, space, H5P_DEFAULT,
                    H5P_DEFAULT);
    status = H5Awrite (attr, H5T_STD_REF_DSETREG, wdata);

    /*
     * Close and release resources.
     */
    status = H5Aclose (attr);
    status = H5Dclose (dset);
    status = H5Dclose (dset2);
    status = H5Sclose (space);
    status = H5Fclose (file);


    /*
     * Now we begin the read section of this example.  Here we assume
     * the attribute has the same name and rank, but can have any size.
     * Therefore we must allocate a new array to read in data using
     * malloc().
     */

    /*
     * Open file, dataset, and attribute.
     */
    file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
    dset = H5Dopen (file, DATASET, H5P_DEFAULT);
    attr = H5Aopen (dset, ATTRIBUTE, H5P_DEFAULT);

    /*
     * Get dataspace and allocate memory for read buffer.
     */
    space = H5Aget_space (attr);
    ndims = H5Sget_simple_extent_dims (space, dims, NULL);
    rdata = (hdset_reg_ref_t *) malloc (dims[0] * sizeof (hdset_reg_ref_t));
    status = H5Sclose (space);

    /*
     * Read the data.
     */
    status = H5Aread (attr, H5T_STD_REF_DSETREG, rdata);

    /*
     * Output the data to the screen.
     */
    for (i=0; i<dims[0]; i++) {
        printf ("%s[%d]:\n  ->", ATTRIBUTE, i);

        /*
         * Open the referenced object, retrieve its region as a
         * dataspace selection.
         */
        dset2 = H5Rdereference (dset, H5P_DEFAULT, H5R_DATASET_REGION, &rdata[i]);
        space = H5Rget_region (dset, H5R_DATASET_REGION, &rdata[i]);

        /*
         * Get the length of the object's name, allocate space, then
         * retrieve the name.
         */
        size = 1 + H5Iget_name (dset2, NULL, 0);
        name = (char *) malloc (size);
        size = H5Iget_name (dset2, name, size);

        /*
         * Allocate space for the read buffer.  We will only allocate
         * enough space for the selection, plus a null terminator.  The
         * read buffer will be 1-dimensional.
         */
        npoints = H5Sget_select_npoints (space);
        rdata2 = (char *) malloc (npoints + 1);

        /*
         * Read the dataset region, and add a null terminator so we can
         * print it as a string.
         */
        memspace = H5Screate_simple (1, (hsize_t *) &npoints, NULL);
        status = H5Dread (dset2, H5T_NATIVE_CHAR, memspace, space, H5P_DEFAULT,
                    rdata2);
        rdata2[npoints] = '\0';

        /*
         * Print the name and region data, close and release resources.
         */
        printf (" %s: %s\n", name, rdata2);
        free (rdata2);
        free (name);
        status = H5Sclose (space);
        status = H5Sclose (memspace);
        status = H5Dclose (dset2);
    }

    /*
     * Close and release resources.
     */
    free (rdata);
    status = H5Aclose (attr);
    status = H5Dclose (dset);
    status = H5Fclose (file);

    return 0;
}
Ejemplo n.º 27
0
std::string HdfGroup::name() const
{
  char name[HDF_MAX_NAME];
  H5Iget_name( d->id, name, HDF_MAX_NAME );
  return std::string( name );
}
Ejemplo n.º 28
0
/*--------------------------------------------------------------*/
int NXVvalidateGroup(pNXVcontext self, hid_t groupID,
	xmlNodePtr groupNode)
{
		hash_table namesSeen, baseNames;
		xmlNodePtr cur = NULL;
		xmlChar *name = NULL, *myClass = NULL;
		xmlChar *target = NULL;
		hid_t childID;
		char fName[256], childName[512], nxdlChildPath[512], childPath[512];
		char mynxdlPath[512];
		char *savedNXDLPath, *pPtr;
		SecondPassData spd;
		hsize_t idx = 0;

		/*
			manage nxdlPath, xmlGetNodePath does not work
		*/
		savedNXDLPath = self->nxdlPath;
		myClass = xmlGetProp(groupNode,(xmlChar *)"type");
		if(self->nxdlPath == NULL) {
			snprintf(mynxdlPath,sizeof(mynxdlPath),"/%s", (char *) myClass);
		} else {
			snprintf(mynxdlPath,sizeof(mynxdlPath),"%s/%s",
				self->nxdlPath, (char *) myClass);
		}
		self->nxdlPath = mynxdlPath;

		/*
			tell what we are doing
		*/
		H5Iget_name(groupID,fName,sizeof(fName));
		NXVsetLog(self,"sev","debug");
		NXVsetLog(self,"message","Validating group");
		NXVsetLog(self,"nxdlPath",self->nxdlPath);
		NXVsetLog(self,"dataPath",fName);
		NXVlog(self);


		validateGroupAttributes(self, groupID, groupNode);
		hash_construct_table(&namesSeen,100);

		/* first pass */
		cur = groupNode->xmlChildrenNode;
		while(cur != NULL){
			if(xmlStrcmp(cur->name,(xmlChar *) "group") == 0){
					childID = findGroup(self, groupID, cur);
					if(childID >= 0){
							H5Iget_name(childID, childName,sizeof(childName));
							/*
								we have to get at the HDF5 name. There may be no
								name in the NXDL, but a suitable group has been found
								by NXclass.
							*/
							pPtr = strrchr(childName,'/');
							if(pPtr != NULL){
								hash_insert(pPtr+1,strdup(""),&namesSeen);
							} else {
								hash_insert(childName,strdup(""),&namesSeen);
							}
							NXVvalidateGroup(self,childID,cur);
					} else {
						name = xmlGetProp(cur,(xmlChar *)"type");
						snprintf(nxdlChildPath,sizeof(nxdlChildPath),"%s/%s",
							self->nxdlPath, (char *)name);
						xmlFree(name);
						NXVsetLog(self,"dataPath",fName);
						NXVsetLog(self,"nxdlPath", nxdlChildPath);
						if(!isOptional(cur)){
							NXVsetLog(self,"sev","error");
							NXVsetLog(self,"message","Required group missing");
							NXVlog(self);
							self->errCount++;
						} else {
							NXVsetLog(self,"sev","warnopt");
							NXVsetLog(self,"message","Optional group missing");
							NXVlog(self);
						}
					}
			}
			if(xmlStrcmp(cur->name,(xmlChar *) "field") == 0){
					name = xmlGetProp(cur,(xmlChar *)"name");
					if(H5LTfind_dataset(groupID,(char *)name) ) {
						childID = H5Dopen(groupID,(char *)name,H5P_DEFAULT);
					} else {
						childID = -1;
					}
					snprintf(childPath,sizeof(childPath),"%s/%s",
						fName,name);
					if(childID < 0){
						NXVsetLog(self,"dataPath",childPath);
						snprintf(nxdlChildPath,sizeof(nxdlChildPath),
							"%s/%s", self->nxdlPath, name);
						NXVsetLog(self,"nxdlPath", nxdlChildPath);
						if(!isOptional(cur)){
									NXVsetLog(self,"sev","error");
									NXVsetLog(self,"message","Required field missing");
									NXVlog(self);
									self->errCount++;
						} else {
							NXVsetLog(self,"sev","warnopt");
							NXVsetLog(self,"message","Optional field missing");
							NXVlog(self);
						}
					} else {
						if(xmlStrcmp(name,(xmlChar *)"depends_on") == 0){
							/*
								This must b validated from the field level. As
								it might point to fields which are not in the
								application definition
							*/
							validateDependsOn(self,groupID,childID);
						} else {
							NXVvalidateField(self,childID, cur);
						}
						hash_insert((char *)name,strdup(""),&namesSeen);
					}
					xmlFree(name);
			}
			if(xmlStrcmp(cur->name,(xmlChar *) "link") == 0){
				name = xmlGetProp(cur,(xmlChar *)"name");
				target = xmlGetProp(cur,(xmlChar *)"target");
				hash_insert((char *)name,strdup(""),&namesSeen);
				validateLink(self,groupID,name, target);
				xmlFree(name);
				xmlFree(target);
			}
			cur = cur->next;
		}

		/*
			Second pass: search the HDF5 group for additional
			stuff which have not checked yet. Most of the hard work
			is in the SecondPassIterator.
		*/
		hash_construct_table(&baseNames,100);
		NXVloadBaseClass(self,&baseNames,(char *)myClass);
		spd.baseNames = &baseNames;
		spd.namesSeen = &namesSeen;
		spd.self = self;
		NXVsetLog(self,"nxdlPath", mynxdlPath);
		H5Literate(groupID, H5_INDEX_NAME, H5_ITER_INC, &idx,
			SecondPassIterator, &spd);

		/*
			clean up
		*/
		hash_free_table(&namesSeen,free);
		hash_free_table(&baseNames,free);
		xmlFree(myClass);
		/*
			restore my paths...
		*/
		self->nxdlPath = savedNXDLPath;
		return 0;
	}
Ejemplo n.º 29
0
/*--------------------------------------------------------------*/
static herr_t SecondPassIterator(hid_t g_id,
		const char *name,
		const H5L_info_t *info, void *op_data)
{
	SecondPassData *spd = (SecondPassData *)op_data;
  H5O_info_t obj_info;
	hid_t attID, groupID, dataID;
	char nxClass[512], fname[512];

	/*
		have we seen that yet?
	*/
	if(hash_lookup((char *)name,spd->namesSeen) != NULL){
		return 0;
	}

	/*
		Nope, we will have to warn...
	*/
	H5Oget_info_by_name(g_id, name, &obj_info,H5P_DEFAULT);
	if(obj_info.type == H5O_TYPE_GROUP){
		groupID = H5Gopen(g_id,name,H5P_DEFAULT);
		H5Iget_name(groupID, fname,sizeof(fname));
		NXVsetLog(spd->self,"dataPath",fname);
		if(H5LTfind_attribute(groupID,"NX_class") == 1){
			memset(nxClass,0,sizeof(nxClass));
			H5NXget_attribute_string(g_id,name,
			"NX_class", nxClass);
			if(hash_lookup(nxClass,spd->baseNames) == NULL){
				NXVsetLog(spd->self,"sev","warnundef");
				NXVprintLog(spd->self,"message","Unknown group %s of class %s found",
					name, nxClass);
				NXVlog(spd->self);
				spd->self->warnCount++;
			} else {
				NXVsetLog(spd->self,"sev","warnbase");
				NXVprintLog(spd->self,"message",
					"Additional base class group %s of type %s found",
					name, nxClass);
				NXVlog(spd->self);
				spd->self->warnCount++;
			}
		} else {
			NXVsetLog(spd->self,"sev","warnundef");
			NXVprintLog(spd->self,"message",
				"Additional non NeXus group %s found",
				name);
			NXVlog(spd->self);
			spd->self->warnCount++;
    }
		H5Gclose(groupID);
	} else if (obj_info.type == H5O_TYPE_DATASET) {
		dataID = H5Dopen(g_id,name,H5P_DEFAULT);
		H5Iget_name(dataID, fname,sizeof(fname));
		H5Dclose(dataID);
		NXVsetLog(spd->self,"dataPath",fname);
		if(hash_lookup((char *)name,spd->baseNames) == NULL){
			NXVsetLog(spd->self,"sev","warnundef");
			NXVprintLog(spd->self,"message","Unknown dataset %s found",
			name);
			NXVlog(spd->self);
			spd->self->warnCount++;
		} else {
			NXVsetLog(spd->self,"sev","warnbase");
			NXVprintLog(spd->self,"message","Additional base class dataset %s found",
			name);
			NXVlog(spd->self);
			spd->self->warnCount++;
		}
	}

	return 0;
}