Пример #1
0
/*-------------------------------------------------------------------------
 * Function:    h5_make_local_copy
 *
 * Purpose:     Make copy of file.  Some tests write to data files under that
 *              are under version control.  Those tests should make a copy of
 *              the versioned file and write to the copy.  This function
 *              prepends srcdir to the name of the file to be copied and uses
 *              the name of the copy as is.
 *
 * Return:      Success:        0
 *
 *              Failure:        -1
 *
 * Programmer:  Larry Knox
 *              Monday, October 13, 2009
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
hid_t
h5_make_local_copy(char *origfilename, char *local_copy_name)
{
    int fd_old = (-1), fd_new = (-1);   /* File descriptors for copying data */
    ssize_t nread;                      /* Number of bytes read in */
    char  buf[READ_BUF_SIZE];        /* Buffer for copying data */
    char  filename[FILENAME_BUF_SIZE] = "";
#ifdef H5_VMS 
    HDstrcat(filename, origfilename);
#else
    char * srcdir = HDgetenv("srcdir"); /* The source directory */

    if(srcdir && ((HDstrlen(srcdir) +
                   HDstrlen(origfilename) + 6) < FILENAME_BUF_SIZE)) {
        HDstrcpy(filename, srcdir);
        HDstrcat(filename, "/");
    }
    HDstrcat(filename, origfilename);
#endif

    /* Copy old file into temporary file */
    if((fd_old = HDopen(filename, O_RDONLY, 0666)) < 0) return -1;
    if((fd_new = HDopen(local_copy_name, O_RDWR|O_CREAT|O_TRUNC, 0666))
        < 0) return -1;

    /* Copy data */
    while((nread = HDread(fd_old, buf, (size_t)READ_BUF_SIZE)) > 0)
        HDwrite(fd_new, buf, (size_t)nread);

    /* Close files */
    if(HDclose(fd_old) < 0) return -1;
    if(HDclose(fd_new) < 0) return -1;

    return 0;
}
Пример #2
0
static void
get_unique_name(void)
{
    const char *prefix = NULL;
    const char *env = HDgetenv("HDF5_PREFIX");

    if (env)
        prefix = env;

    if (option_prefix)
        prefix = option_prefix;

    if (prefix)
        /* 2 = 1 for '/' + 1 for null terminator */
        filename = (char *) HDmalloc(HDstrlen(prefix) + HDstrlen(ZIP_PERF_FILE) + 2);
    else
        filename = (char *) HDmalloc(HDstrlen(ZIP_PERF_FILE) + 1);

    if (!filename)
        error("out of memory");

    filename[0] = 0;
    if (prefix){
        HDstrcpy(filename, prefix);
        HDstrcat(filename, "/");
    }
    HDstrcat(filename, ZIP_PERF_FILE);
}
Пример #3
0
/*--------------------------------------------------------------------------
 * Function: H5L_build_name
 *
 * Purpose:  Prepend PREFIX to FILE_NAME and store in FULL_NAME
 *
 * Return:   Non-negative on success/Negative on failure
 *
 * Programmer:	Vailin Choi, April 2, 2008
 *
 * Modification: Raymond Lu, 14 Jan. 2009
 *           Added support for OpenVMS pathname
--------------------------------------------------------------------------*/
static herr_t
H5L_build_name(char *prefix, char *file_name, char **full_name/*out*/)
{
    size_t      prefix_len;             /* length of prefix */
    size_t      fname_len;              /* Length of external link file name */
    herr_t      ret_value = SUCCEED;    /* Return value */

    FUNC_ENTER_NOAPI_NOINIT(H5L_build_name)

    prefix_len = HDstrlen(prefix);
    fname_len = HDstrlen(file_name);

    /* Allocate a buffer to hold the filename + prefix + possibly the delimiter + terminating null byte */
    if(NULL == (*full_name = (char *)H5MM_malloc(prefix_len + fname_len + 2)))
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate filename buffer")

    /* Copy the prefix into the buffer */
    HDstrcpy(*full_name, prefix);

    if (!CHECK_DELIMITER(prefix[prefix_len-1]))
        HDstrcat(*full_name, DIR_SEPS);

    /* Add the external link's filename to the prefix supplied */
    HDstrcat(*full_name, file_name);

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* H5L_build_name() */
Пример #4
0
/*-------------------------------------------------------------------------
 * Function:    read_new
 *
 * Purpose:     Test reading a file with "new style" (compact) groups
 *
 * Return:      Success:        0
 *
 *              Failure:        -1
 *
 * Programmer:  Quincey Koziol
 *              Monday, October 24, 2005
 *
 *-------------------------------------------------------------------------
 */
static int
read_new(hid_t fapl)
{
    hid_t		fid = (-1);     /* File ID */
    hid_t		gid = (-1);     /* Group ID */
    char       *srcdir = HDgetenv("srcdir"); /*where the src code is located*/
    char       filename[512]="";  /* test file name */

    TESTING("reading new groups");

    /* Generate correct name for test file by prepending the source path */
    if(srcdir && ((HDstrlen(srcdir) + HDstrlen(FILE_NEW_GROUPS) + 1) < sizeof(filename))) {
        HDstrcpy(filename, srcdir);
        HDstrcat(filename, "/");
    }
    HDstrcat(filename, FILE_NEW_GROUPS);

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

    /* Attempt to open root group */
    if((gid = H5Gopen(fid, "/")) < 0) TEST_ERROR;

    /* Attempt to open new "empty" group (should fail) */
    H5E_BEGIN_TRY {
        if(H5Gopen(gid, "empty") >= 0) TEST_ERROR;
    } H5E_END_TRY;

    /* Attempt to open new group with link messages (should fail) */
    H5E_BEGIN_TRY {
        if(H5Gopen(gid, "links") >= 0) TEST_ERROR;
    } H5E_END_TRY;

    /* Close root group */
    if(H5Gclose(gid) < 0) TEST_ERROR;

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

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
    	H5Gclose(gid);
    	H5Fclose(fid);
    } H5E_END_TRY;
    return 1;
} /* end read_new() */
Пример #5
0
/*-------------------------------------------------------------------------
 * Function:    ud_link_compat
 *
 * Purpose:     Ensure that User-defined links (introduced in 1.8) can be
 *              handled by HDF5 1.6.
 *
 * Return:      Success:        0
 *              Failure:        -1
 *
 * Programmer:  James Laird
 *              Tuesday, July 25, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
ud_link_compat(hid_t fapl)
{
    hid_t       fid = (-1);
    H5G_stat_t  sb;
    char      * srcdir = getenv("srcdir");      /* The source directory */
    char        pathbuf[NAME_BUF_SIZE];         /* Path to the files */
    char        namebuf[NAME_BUF_SIZE];

    TESTING("compatibility with User-defined links");

    /*
     * Create the name of the file to open (in case we are using the --srcdir
     * option and the file is in a different directory from this test).
     */
    if (srcdir && ((HDstrlen(srcdir) + 2) < sizeof(pathbuf)) )
    {
        HDstrcpy(pathbuf, srcdir);
        HDstrcat(pathbuf, "/");
    }
    else
        HDstrcpy(pathbuf, "");

    if(HDstrlen(pathbuf) + HDstrlen(LE_FILENAME) >= sizeof(namebuf)) TEST_ERROR
    HDstrcpy(namebuf, pathbuf);
    HDstrcat(namebuf, LE_FILENAME);

    /* Open a file with an external link in it */
    if((fid = H5Fopen(namebuf, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR

    /* Trying to open the link or get info about it should fail. */
    H5E_BEGIN_TRY {
        if(H5Gopen(fid, "ext_link") >= 0) TEST_ERROR
        if(H5Gget_objinfo(fid, "ext_link", FALSE, &sb) >= 0) TEST_ERROR
    } H5E_END_TRY

    /* There isn't much more we can do with the link. We shouldn't try moving
     * it or deleting it. */
    if(H5Fclose(fid) < 0) TEST_ERROR

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Fclose(fid);
    } H5E_END_TRY
    return -1;
} /* end ud_link_compat() */
Пример #6
0
/*
NAME
   HDgettagsname -- return a text name of a tag
USAGE
   char * HDgettagsname(tag)
   uint16   tag;          IN: tag of element to find
RETURNS
   Descriptive text or NULL
DESCRIPTION
   Map a tag to a dynamically allocated text name of it.
   Checks for special elements now.

--------------------------------------------------------------------------- */
char *
HDgettagsname(uint16 tag)
{
    CONSTR(FUNC, "HDgettagsname");  /* for HERROR */
    char       *ret = NULL;
    intn        i;

    if (SPECIALTAG(tag))
        ret = (char *) HDstrdup("Special ");
    tag = BASETAG(tag);
    for (i = 0; i < (intn)(sizeof(tag_descriptions) / sizeof(tag_descript_t)); i++)
        if (tag_descriptions[i].tag == tag)
          {
              if (ret == NULL)
                  ret = (char *) HDstrdup(tag_descriptions[i].name);
              else
                {
                    char       *t;

                    t = (char *) HDmalloc(HDstrlen(ret) +
                                    HDstrlen(tag_descriptions[i].name) + 2);
                    if (t == NULL)
                      {
                          HDfree(ret);
                          HRETURN_ERROR(DFE_NOSPACE, NULL)
                      }     /* end if */
                    HDstrcpy(t, ret);
                    HDstrcat(t, tag_descriptions[i].name);
                    HDfree(ret);
                    ret = t;
                }   /* end else */
          }     /* end if */
Пример #7
0
Файл: an.c Проект: schwehr/hdf4
void
test_an(void)
{
    char        labsds[MAXLEN_LAB], labris[MAXLEN_LAB], descsds[MAXLEN_DESC],
                descris[MAXLEN_DESC];
    uint8       pal[768];
    uint8      *image, *newimage;
    uint16      refnum;
    int32       ret;
    intn        rank;
    int         j;
    int32       dimsizes[2];
    float      *data;

/* set up object labels and descriptions */

    HDstrcpy(labsds, "Object label #1: sds");
    HDstrcpy(labris, "Object label #2: image");
    HDstrcpy(descsds, "Object Descr #1: 1  2  3  4  5  6  7  8  9 10 11 12 \n");
    HDstrcat(descsds, "             13 14 15 16 17 18 19 20 **END SDS DESCR**\n");
    HDstrcpy(descris, "Object Descr #2: A B C D E F G H I J K L \n");
    HDstrcat(descris, "                M N O **END IMAGE DESCR **\n");

/***** generate float array and image *****/

    data = (float *) HDmalloc(ROWS * COLS * sizeof(float));
    image = (uint8 *) HDmalloc(ROWS * COLS * sizeof(char));
    newimage = (uint8 *) HDmalloc(ROWS * COLS * sizeof(char));

    dimsizes[0] = ROWS;
    dimsizes[1] = COLS;

    gen2Dfloat(ROWS, COLS, data);
    genimage(ROWS, COLS, data, image);

    ret = DFSDsetdims(2, dimsizes);
    RESULT("DFSDsetdims");

/********  Write labels and descriptions *********/
    MESSAGE(5, printf("***  Writing labels and descriptions with SDS and RIS ***\n");
        );
Пример #8
0
pack_info_t* options_get_object(const char *path, pack_opttbl_t *table) {
	unsigned int i;
	char tbl_path[MAX_NC_NAME + 1]; /* +1 for start with "/" case */

	for (i = 0; i < table->nelems; i++) {
		/* make full path (start with "/") to compare correctly  */
		if (HDstrncmp(table->objs[i].path, "/", 1)) {
			HDstrcpy(tbl_path, "/");
			HDstrcat(tbl_path, table->objs[i].path);
		}
		else
			HDstrcpy(tbl_path, table->objs[i].path);

		/* found it */
		if (HDstrcmp(tbl_path, path) == 0) {
			return (&table->objs[i]);
		}
	}

	return NULL;
}
Пример #9
0
/*-------------------------------------------------------------------------
 * Function:    parse_command_line
 *
 * Purpose:     Parse the command line for h5watch (take only long options)
 *
 * Return:      Success:    Set the corresponding command flags and return void
 *              Failure:    Exits program with EXIT_FAILURE value.
 *
 * Programmer:  Vailin Choi; August 2010
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static void
parse_command_line(int argc, const char *argv[])
{
    int	opt;	/* Command line option */
    int tmp;

     /* no arguments */
    if (argc == 1) {
        usage(h5tools_getprogname());
        leave(EXIT_FAILURE);
    }

    /* parse command line options */
    while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) {
        switch ((char)opt) {
        case '?':
        case 'h': /* --help */
	    usage(h5tools_getprogname());
            leave(EXIT_SUCCESS);

        case 'V': /* --version */
            print_version(progname);
            leave(EXIT_SUCCESS);
            break;

        case 'w': /* --width=N */
	    g_display_width = (int)HDstrtol(opt_arg, NULL, 0);
	    if(g_display_width < 0) {
		usage(h5tools_getprogname());
		leave(EXIT_FAILURE);
	    }
            break;

        case 'd': /* --dim */
	    g_monitor_size_only = TRUE;
            break;

        case 'S': /* --simple */
	    g_simple_output = TRUE;
            break;
	
	case 'l': /* --label */
	    g_label = TRUE;
            break;

        case 'p': /* --polling=N */
	    /* g_polling_interval = HDstrtod(opt_arg, NULL); */
	    if((tmp = (int)HDstrtol(opt_arg, NULL, 10)) <= 0) {
		usage(h5tools_getprogname());
		leave(EXIT_FAILURE);
	    }
	    g_polling_interval = (unsigned)tmp;
            break;

        case 'f': /* --fields=<list_of_fields> */
	    if(g_list_of_fields == NULL) {
		if((g_list_of_fields = HDstrdup(opt_arg)) == NULL) {
		    error_msg("memory allocation failed (file %s:line %d)\n",
			      __FILE__, __LINE__);
		    leave(EXIT_FAILURE);
		}
	    } else {
		char *str;

		if((str = HDstrdup(opt_arg)) == NULL) {
		    error_msg("memory allocation failed (file %s:line %d)\n",
			      __FILE__, __LINE__);
		    leave(EXIT_FAILURE);
		}
		if((g_list_of_fields = (char *)HDrealloc(g_list_of_fields, HDstrlen(g_list_of_fields) + HDstrlen(str) + 2)) == NULL) {
		    error_msg("memory allocation failed (file %s:line %d)\n",
			      __FILE__, __LINE__);
		    leave(EXIT_FAILURE);

		}
		HDstrcat(g_list_of_fields, FIELD_SEP);
		HDstrcat(g_list_of_fields, str);
	    }

            break;

        default:
	    usage(h5tools_getprogname());
            leave(EXIT_FAILURE);
        }
    }
    

    /* check for object to be processed */
    if (argc <= opt_ind) {
        error_msg("missing dataset name\n");
	usage(h5tools_getprogname());
        leave(EXIT_FAILURE);
    }
} /* parse_command_line() */
Пример #10
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	H5O_mtime_decode() test.
 *
 * Return:	Success:
 *
 *		Failure:
 *
 * Programmer:	Robb Matzke
 *              Thursday, July 30, 1998
 *
 * Modifications:
 *              Added checks for old and new modification time messages
 *              in pre-created datafiles (generated with gen_old_mtime.c and
 *              gen_new_mtime.c).
 *              Quincey Koziol
 *              Friday, January  3, 2003
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t	fapl, file, space, dset;
    hsize_t	size[1] = {2};
    time_t	now;
    struct tm	*tm;
    H5O_info_t	oi1, oi2;
    signed char	buf1[32], buf2[32];
    char	filename[1024];

    h5_reset();
    fapl = h5_fileaccess();

    TESTING("modification time messages");

    /* Create the file, create a dataset, then close the file */
    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR;
    if((space = H5Screate_simple(1, size, NULL)) < 0) TEST_ERROR;
    if((dset = H5Dcreate2(file, "dset", H5T_NATIVE_SCHAR, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        TEST_ERROR;
    now = HDtime(NULL);
    if(H5Dclose(dset) < 0) TEST_ERROR;
    if(H5Sclose(space) < 0) TEST_ERROR;
    if(H5Fclose(file) < 0) TEST_ERROR;

    /*
     * Open the file and get the modification time. We'll test the
     * H5Oget_info() arguments too: being able to stat something without
     * knowing its name.
     */
    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
    if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR;
    if(H5Oget_info_by_name(file, "dset", &oi1, H5P_DEFAULT) < 0) TEST_ERROR;
    if((dset = H5Dopen2(file, "dset", H5P_DEFAULT)) < 0) TEST_ERROR;
    if(H5Oget_info(dset, &oi2) < 0) TEST_ERROR;
    if(H5Dclose(dset) < 0) TEST_ERROR;
    if(H5Fclose(file) < 0) TEST_ERROR;

    /* Compare addresses & times from the two ways of calling H5Oget_info() */
    if(oi1.addr != oi2.addr || oi1.mtime != oi2.mtime) {
        H5_FAILED();
        puts("    Calling H5Oget_info() with the dataset ID returned");
        puts("    different values than calling it with a file and dataset");
        puts("    name.");
        goto error;
    }

    /* Compare times -- they must be within 60 seconds of one another */
    if(0 == oi1.mtime) {
        SKIPPED();
        puts("    The modification time could not be decoded on this OS.");
        puts("    Modification times will be mantained in the file but");
        puts("    cannot be queried on this system.  See H5O_mtime_decode().");
        return 0;
    } else if(HDfabs(HDdifftime(now, oi1.mtime)) > 60.0) {
        H5_FAILED();
        tm = HDlocaltime(&(oi1.mtime));
        HDstrftime((char*)buf1, sizeof buf1, "%Y-%m-%d %H:%M:%S", tm);
        tm = HDlocaltime(&now);
        HDstrftime((char*)buf2, sizeof buf2, "%Y-%m-%d %H:%M:%S", tm);
        printf("    got: %s\n    ans: %s\n", buf1, buf2);
        goto error;
    }
    PASSED();


    /* Check opening existing file with old-style modification time information
     * and make certain that the time is correct
     */
    TESTING("accessing old modification time messages");

    {
        char testfile[512]="";
        char *srcdir = HDgetenv("srcdir");

        if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE1) + 1) < sizeof(testfile))){
            HDstrcpy(testfile, srcdir);
            HDstrcat(testfile, "/");
        }
        HDstrcat(testfile, TESTFILE1);
        file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT);
        if(file >= 0){
            if(H5Oget_info_by_name(file, "/Dataset1", &oi1, H5P_DEFAULT) < 0)
                TEST_ERROR;
            if(oi1.mtime != MTIME1) {
                H5_FAILED();
                   /* If this fails, examine H5Omtime.c.  Modification time is very
                    * system dependant (e.g., on Windows DST must be hardcoded). */
                puts("    Old modification time incorrect");
                goto error;
            }
            if(H5Fclose(file) < 0) TEST_ERROR;
        }
        else {
            H5_FAILED();
            printf("***cannot open the pre-created old modification test file (%s)\n",
                testfile);
            goto error;
        } /* end else */
    }
    PASSED();

    /* Check opening existing file with new-style modification time information
     * and make certain that the time is correct
     */
    TESTING("accessing new modification time messages");

    {
        char testfile[512]="";
        char *srcdir = HDgetenv("srcdir");

        if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE2) + 1) < sizeof(testfile))){
            HDstrcpy(testfile, srcdir);
            HDstrcat(testfile, "/");
        }
        HDstrcat(testfile, TESTFILE2);
        file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT);
        if(file >= 0){
            if(H5Oget_info_by_name(file, "/Dataset1", &oi2, H5P_DEFAULT) < 0)
                TEST_ERROR;
            if(oi2.mtime != MTIME2) {
               H5_FAILED();
               puts("    Modification time incorrect.");
               goto error;
            }
            if(H5Fclose(file) < 0) TEST_ERROR;
        }
        else {
            H5_FAILED();
            printf("***cannot open the pre-created old modification test file (%s)\n",
                testfile);
            goto error;
        } /* end else */
    }
    PASSED();

    /* All looks good */
    puts("All modification time tests passed.");
    h5_cleanup(FILENAME, fapl);
    return 0;

    /* Something broke */
error:
    return 1;
}
Пример #11
0
/*-------------------------------------------------------------------------
 * Function:  h5_fixname
 *
 * Purpose:  Create a file name from a file base name like `test' and
 *    return it through the FULLNAME (at most SIZE characters
 *    counting the null terminator). The full name is created by
 *    prepending the contents of HDF5_PREFIX (separated from the
 *    base name by a slash) and appending a file extension based on
 *    the driver supplied, resulting in something like
 *    `ufs:/u/matzke/test.h5'.
 *
 * Return:  Success:  The FULLNAME pointer.
 *
 *    Failure:  NULL if BASENAME or FULLNAME is the null
 *        pointer or if FULLNAME isn't large enough for
 *        the result.
 *
 * Programmer:  Robb Matzke
 *              Thursday, November 19, 1998
 *
 *-------------------------------------------------------------------------
 */
char *
h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size)
{
    const char     *prefix = NULL;
    const char     *suffix = ".h5";     /* suffix has default */
    char           *ptr, last = '\0';
    size_t          i, j;
    hid_t           driver = -1;
    int             isppdriver = 0;  /* if the driver is MPI parallel */

    if (!base_name || !fullname || size < 1)
        return NULL;

    HDmemset(fullname, 0, size);

    /* figure out the suffix */
    if(H5P_DEFAULT != fapl) {
        if((driver = H5Pget_driver(fapl)) < 0)
            return NULL;

        if(H5FD_FAMILY == driver)
            suffix = "%05d.h5";
        else if (H5FD_MULTI == driver)
            suffix = NULL;
    }

    /* Must first check fapl is not H5P_DEFAULT (-1) because H5FD_XXX
     * could be of value -1 if it is not defined.
     */
    isppdriver = H5P_DEFAULT != fapl && (H5FD_MPIO==driver);

    /* Check HDF5_NOCLEANUP environment setting.
     * (The #ifdef is needed to prevent compile failure in case MPI is not
     * configured.)
     */
    if(isppdriver) {
#ifdef H5_HAVE_PARALLEL
        if(getenv_all(MPI_COMM_WORLD, 0, "HDF5_NOCLEANUP"))
            SetTestNoCleanup();
#endif  /* H5_HAVE_PARALLEL */
    } else {
        if(HDgetenv("HDF5_NOCLEANUP"))
            SetTestNoCleanup();
    }

    /* Check what prefix to use for test files. Process HDF5_PARAPREFIX and
     * HDF5_PREFIX.
     * Use different ones depending on parallel or serial driver used.
     * (The #ifdef is needed to prevent compile failure in case MPI is not
     * configured.)
     */
    if(isppdriver) {
#ifdef H5_HAVE_PARALLEL
  /*
         * For parallel:
         *      First use command line option, then the environment
         *      variable, then try the constant
   */
        static int explained = 0;

        prefix = (paraprefix ? paraprefix : getenv_all(MPI_COMM_WORLD, 0, "HDF5_PARAPREFIX"));

        if (!prefix && !explained) {
            /* print hint by process 0 once. */
            int mpi_rank;

            MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);

            if (mpi_rank == 0)
                printf("*** Hint ***\n"
                        "You can use environment variable HDF5_PARAPREFIX to "
                        "run parallel test files in a\n"
                        "different directory or to add file type prefix. E.g.,\n"
                        "   HDF5_PARAPREFIX=pfs:/PFS/user/me\n"
                        "   export HDF5_PARAPREFIX\n"
                        "*** End of Hint ***\n");

            explained = TRUE;
#ifdef HDF5_PARAPREFIX
            prefix = HDF5_PARAPREFIX;
#endif  /* HDF5_PARAPREFIX */
        }
#endif  /* H5_HAVE_PARALLEL */
    } else {
        /*
         * For serial:
         *      First use the environment variable, then try the constant
        */
        prefix = HDgetenv("HDF5_PREFIX");

#ifdef HDF5_PREFIX
        if (!prefix)
            prefix = HDF5_PREFIX;
#endif  /* HDF5_PREFIX */
    }

    /* Prepend the prefix value to the base name */
    if (prefix && *prefix) {
        if (isppdriver) {
            /* This is a parallel system */
            char *subdir;

            if (!HDstrcmp(prefix, HDF5_PARAPREFIX)) {
                /*
                 * If the prefix specifies the HDF5_PARAPREFIX directory, then
                 * default to using the "/tmp/$USER" or "/tmp/$LOGIN"
                 * directory instead.
                 */
                char *user, *login;

                user = HDgetenv("USER");
                login = HDgetenv("LOGIN");
                subdir = (user ? user : login);

                if (subdir) {
                    for (i = 0; i < size && prefix[i]; i++)
                        fullname[i] = prefix[i];

                    fullname[i++] = '/';

                    for (j = 0; i < size && subdir[j]; ++i, ++j)
                        fullname[i] = subdir[j];
                }
            }

            if (!fullname[0]) {
                /* We didn't append the prefix yet */
                HDstrncpy(fullname, prefix, size);
                fullname[size -1] = '\0';
            }

            if (HDstrlen(fullname) + HDstrlen(base_name) + 1 < size) {
                /*
                 * Append the base_name with a slash first. Multiple
                 * slashes are handled below.
                 */
                h5_stat_t buf;

                if (HDstat(fullname, &buf) < 0)
                    /* The directory doesn't exist just yet */
                    if (HDmkdir(fullname, (mode_t)0755) < 0 && errno != EEXIST)
                        /*
                         * We couldn't make the "/tmp/${USER,LOGIN}"
                         * subdirectory.  Default to PREFIX's original
                         * prefix value.
                         */
                        HDstrcpy(fullname, prefix);

                HDstrcat(fullname, "/");
                HDstrcat(fullname, base_name);
            } else {
                /* Buffer is too small */
                return NULL;
            }
        } else {
            if (HDsnprintf(fullname, size, "%s/%s", prefix, base_name) == (int)size)
                /* Buffer is too small */
                return NULL;
        }
    } else if (HDstrlen(base_name) >= size) {
  /* Buffer is too small */
  return NULL;
    } else {
  HDstrcpy(fullname, base_name);
   }

    /* Append a suffix */
    if (suffix) {
  if (HDstrlen(fullname) + HDstrlen(suffix) >= size)
            return NULL;

  HDstrcat(fullname, suffix);
    }

    /* Remove any double slashes in the filename */
    for (ptr = fullname, i = j = 0; ptr && i < size; i++, ptr++) {
        if (*ptr != '/' || last != '/')
            fullname[j++] = *ptr;

        last = *ptr;
    }

    return fullname;
}
Пример #12
0
/* 
 * Setup Use Case parameters by parsing command line options.
 * Setup default values if not set by options. */
static int
parse_option(int argc, char * const argv[])
{
    int ret_value=0;
    int c;
    /* command line options: See function usage for a description */
    const char *cmd_options = "f:hn:s:y:z:";

    /* suppress getopt from printing error */
    opterr = 0;

    while (1){
	c = getopt (argc, argv, cmd_options);
	if (-1 == c)
	    break;
	switch (c) {
	  case 'h':
	    usage(progname_g);
	    exit(0);
	    break;
	  case 'f':	/* usecase data file name */
	    filename_g = optarg;
	    break;
	  case 'n':	/* number of planes to write/read */
	    if ((nplanes_g = atoi(optarg)) <= 0){
		fprintf(stderr, "bad number of planes %s, must be a positive integer\n", optarg);
		usage(progname_g);
		Hgoto_error(-1);
	    };
	    break;
	  case 's':	/* use swmr file open mode */
	    if ((use_swmr_g = atoi(optarg)) < 0){
		fprintf(stderr, "swmr value should be 0(no) or 1(yes)\n");
		usage(progname_g);
		Hgoto_error(-1);
	    };
	    break;
	  case 'y':	/* Number of planes per chunk */
	    if ((chunkplanes_g = atoi(optarg)) <= 0){
		fprintf(stderr, "bad number of planes per chunk %s, must be a positive integer\n", optarg);
		usage(progname_g);
		Hgoto_error(-1);
	    };
	    break;
	  case 'z':	/* size of chunk=(z,z) */
	    if ((chunksize_g = atoi(optarg)) <= 0){
		fprintf(stderr, "bad chunksize %s, must be a positive integer\n", optarg);
		usage(progname_g);
		Hgoto_error(-1);
	    };
	    break;
	  case '?':
	    fprintf(stderr, "getopt returned '%c'.\n", c);
	    Hgoto_error(-1);
	  default:
	    fprintf(stderr, "getopt returned unexpected value.\n");
	    fprintf(stderr, "Unexpected value is %d\n", c);
	    Hgoto_error(-1);
	}
    }

    /* set test file name if not given */
    if (!filename_g){
	/* default data file name is <progname>.h5 */
	if ((filename_g = (char*)HDmalloc(HDstrlen(progname_g)+4))==NULL) {
	    fprintf(stderr, "malloc: failed\n");
	    Hgoto_error(-1);
	};
	HDstrcpy(filename_g, progname_g);
	HDstrcat(filename_g, ".h5");
    }

done:
    /* All done. */
    return(ret_value);
} /* parse_option() */
Пример #13
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:     Exercise private object header behavior and routines
 *
 * Return:	Success:        0
 *		Failure:        1
 *
 * Programmer:	Robb Matzke
 *              Tuesday, November 24, 1998
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t	fapl = -1, file = -1;
    hid_t	dset = -1;
    H5F_t	*f = NULL;
    char	filename[1024];
    H5O_hdr_info_t hdr_info;            /* Object info */
    H5O_loc_t	oh_loc, oh_loc2;        /* Object header locations */
    time_t	time_new, ro;
    int         chunkno;                /* Chunk index for message */
    int		i;                      /* Local index variable */
    hbool_t     b;                      /* Index for "new format" loop */
    herr_t      ret;                    /* Generic return value */

    /* Reset library */
    h5_reset();
    fapl = h5_fileaccess();
    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);

    /* Loop over old & new formats */
    for(b = FALSE; b <= TRUE; b++) {
        /* Display info about testing */
        if(b)
            HDputs("Using new file format:");
        else
            HDputs("Using default file format:");

        /* Set the format to use for the file */
        if(H5Pset_libver_bounds(fapl, (b ? H5F_LIBVER_LATEST : H5F_LIBVER_EARLIEST), H5F_LIBVER_LATEST) < 0)
            FAIL_STACK_ERROR

	/* test on object continuation block */
	if(test_cont(filename, fapl) < 0)
            FAIL_STACK_ERROR

        /* Create the file to operate on */
        if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
            TEST_ERROR
        if(NULL == (f = (H5F_t *)H5I_object(file)))
            FAIL_STACK_ERROR


        /*
         * Test object header creation
         * (using default group creation property list only because it's convenient)
         */
        TESTING("object header creation");
        HDmemset(&oh_loc, 0, sizeof(oh_loc));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0)
            FAIL_STACK_ERROR
        PASSED();


        /* create a new message */
        TESTING("message creation");
        time_new = 11111111;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR
        if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(ro != time_new)
            TEST_ERROR
        PASSED();


        /*
         * Test modification of an existing message.
         */
        TESTING("message modification");
        time_new = 33333333;
        if(H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR
        if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(ro != time_new)
            TEST_ERROR

        /* Make certain that chunk #0 in the object header can be encoded with a 1-byte size */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.space.total >=256)
            TEST_ERROR

        PASSED();

        /*
         * Test creation of a bunch of messages one after another to see
         * what happens when the object header overflows in core.
         * (Use 'old' MTIME message here, because it is large enough to be
         *  replaced with a continuation message (the new one is too small)
         *  and the library doesn't understand how to migrate more than one
         *  message from an object header currently - QAK - 10/8/03)
         */
        TESTING("object header overflow in memory");
        for(i = 0; i < 40; i++) {
            time_new = (i + 1) * 1000 + 1000000;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
        } /* end for */
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR

        /* Make certain that chunk #0 in the object header will be encoded with a 2-byte size */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.space.total < 256)
            TEST_ERROR

        PASSED();

        /* Close & re-open file & object header */
        /* (makes certain that an object header in the new format that transitions
         *  between 1-byte chunk #0 size encoding and 2-byte chunk #0 size encoding
         *  works correctly - QAK)
         */
        TESTING("close & re-open object header");
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR
        if(H5Fclose(file) < 0)
            FAIL_STACK_ERROR
        if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
            FAIL_STACK_ERROR
        if(NULL == (f = (H5F_t *)H5I_object(file)))
            FAIL_STACK_ERROR
        oh_loc.file = f;
        if(H5O_open(&oh_loc) < 0)
            FAIL_STACK_ERROR
        PASSED();

        /*
         * Test creation of a bunch of messages one after another to see
         * what happens when the object header overflows on disk.
         */
        TESTING("object header overflow on disk");
        for(i = 0; i < 10; i++) {
            time_new = (i + 1) * 1000 + 10;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
            if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
            if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
                FAIL_STACK_ERROR
        } /* end for */
        PASSED();

        /*
         * Delete all time messages.
         */
        TESTING("message deletion");
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(H5O_msg_read(&oh_loc, H5O_MTIME_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        PASSED();


        /*
         * Constant message handling.
         * (can't write to them, but should be able to remove them)
         */
        TESTING("constant message handling");
        time_new = 22222222;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, H5O_MSG_FLAG_CONSTANT, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0)
            FAIL_STACK_ERROR
        if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR
        if(ro != time_new)
            TEST_ERROR
        time_new = 33333333;
        H5E_BEGIN_TRY {
            ret = H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT);
        } H5E_END_TRY;
        if(ret >= 0)
            TEST_ERROR
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR
        PASSED();


        /* release resources */
        TESTING("object header closing");
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR
        PASSED();

        /*
         * Test moving message to first chunk
         */
        TESTING("locking messages");
        HDmemset(&oh_loc, 0, sizeof(oh_loc));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Create second object header, to guarantee that first object header uses multiple chunks */
        HDmemset(&oh_loc2, 0, sizeof(oh_loc2));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Fill object header with messages, creating multiple chunks */
        for(i = 0; i < 10; i++) {
            time_new = (i + 1) * 1000 + 10;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
        } /* end for */

        /* Get # of object header chunks */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.nchunks != 2)
            TEST_ERROR

        /* Add message to lock to object header */
        time_new = 11111111;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 1)
            TEST_ERROR

        /* Lock the message into the chunk */
        if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Attempt to lock the message twice */
        H5E_BEGIN_TRY {
            ret = H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT);
        } H5E_END_TRY;
        if(ret >= 0)
            TEST_ERROR

        /* Delete all the other messages, which would move the message into
         * chunk #0, if it wasn't locked
         */
        if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 1)
            TEST_ERROR

        /* Unlock the message */
        if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Attempt to unlock the message twice */
        H5E_BEGIN_TRY {
            ret = H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT);
        } H5E_END_TRY;
        if(ret >= 0)
            TEST_ERROR

        /* Close object headers */
        if(H5O_close(&oh_loc2) < 0)
            FAIL_STACK_ERROR
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR

        /* Open first object header */
        HDmemset(&oh_loc, 0, sizeof(oh_loc));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Create second object header, to guarantee that first object header uses multiple chunks */
        HDmemset(&oh_loc2, 0, sizeof(oh_loc2));
        if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0)
            FAIL_STACK_ERROR
        if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT))
            FAIL_STACK_ERROR

        /* Add message to move to object header */
        time_new = 11111111;
        if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 0)
            TEST_ERROR

        /* Lock the message into the chunk */
        if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Fill object header with messages, creating multiple chunks */
        /* (would normally move locked message to new chunk) */
        for(i = 0; i < 10; i++) {
            time_new = (i + 1) * 1000 + 10;
            if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0)
                FAIL_STACK_ERROR
        } /* end for */

        /* Get # of object header chunks */
        if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0)
            FAIL_STACK_ERROR
        if(hdr_info.nchunks != 2)
            TEST_ERROR

        /* Verify chunk index for message */
        if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0)
            FAIL_STACK_ERROR
        if(chunkno != 0)
            TEST_ERROR

        /* Unlock the message */
        if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0)
            FAIL_STACK_ERROR

        /* Close object headers */
        if(H5O_close(&oh_loc2) < 0)
            FAIL_STACK_ERROR
        if(H5O_close(&oh_loc) < 0)
            FAIL_STACK_ERROR

        PASSED();


        /* Test reading datasets with undefined object header messages */
        HDputs("Accessing objects with unknown header messages:");
        {
            hid_t file2;                    /* File ID for 'bogus' object file */
            hid_t sid;                      /* Dataspace ID */
            hid_t aid;                      /* Attribute ID */
            char testpath[512] = "";
            char testfile[512] = "";
            char *srcdir = HDgetenv("srcdir");

            /* Build path to all test files */
            if(srcdir && ((HDstrlen(srcdir) + 2) < sizeof(testpath))) {
                HDstrcpy(testpath, srcdir);
                HDstrcat(testpath, "/");
            } /* end if */

            /* Build path to test file */
            if(srcdir && ((HDstrlen(testpath) + HDstrlen(FILE_BOGUS) + 1) < sizeof(testfile)))
                HDstrcpy(testfile, testpath);
            HDstrcat(testfile, FILE_BOGUS);

            TESTING("object with unknown header message and no flags set");

            /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) */
            if((file2 = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Open the dataset with the unknown header message, but no extra flags */
            if((dset = H5Dopen2(file2, "/Dataset1", H5P_DEFAULT)) < 0)
                TEST_ERROR
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            PASSED();

            TESTING("object with unknown header message & 'fail if unknown and open for write' flag set");

            /* Open the dataset with the unknown header message, and "fail if unknown and open for write" flag */
            if((dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT)) < 0)
                TEST_ERROR
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            PASSED();

            TESTING("object with unknown header message & 'mark if unknown' flag set");

            /* Copy object with "mark if unknown" flag on message into file that can be modified */
            if(H5Ocopy(file2, "/Dataset3", file, "/Dataset3", H5P_DEFAULT, H5P_DEFAULT) < 0)
                TEST_ERROR

            /* Close the file we created (to flush changes to file) */
            if(H5Fclose(file) < 0)
                TEST_ERROR

            /* Re-open the file created, with read-only permissions */
            if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
                TEST_ERROR

            /* Open the dataset with the "mark if unknown" message */
            if((dset = H5Dopen2(file, "/Dataset3", H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Check that the "unknown" message was _NOT_ marked */
            if(H5O_check_msg_marked_test(dset, FALSE) < 0)
                FAIL_STACK_ERROR

            /* Close the dataset */
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            /* Close the file we created (to flush change to object header) */
            if(H5Fclose(file) < 0)
                TEST_ERROR

            /* Re-open the file created */
            if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
                TEST_ERROR

            /* Open the dataset with the "mark if unknown" message */
            if((dset = H5Dopen2(file, "/Dataset3", H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Create data space */
            if((sid = H5Screate(H5S_SCALAR)) < 0)
                FAIL_STACK_ERROR

            /* Create an attribute, to get the object header into write access */
            if((aid = H5Acreate2(dset, "Attr", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
                FAIL_STACK_ERROR

            /* Close dataspace */
            if(H5Sclose(sid) < 0)
                FAIL_STACK_ERROR

            /* Close attribute */
            if(H5Aclose(aid) < 0)
                FAIL_STACK_ERROR

            /* Close the dataset */
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            /* Close the file we created (to flush change to object header) */
            if(H5Fclose(file) < 0)
                TEST_ERROR

            /* Re-open the file created */
            if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
                TEST_ERROR

            /* Re-open the dataset with the "mark if unknown" message */
            if((dset = H5Dopen2(file, "/Dataset3", H5P_DEFAULT)) < 0)
                TEST_ERROR

            /* Check that the "unknown" message was marked */
            if(H5O_check_msg_marked_test(dset, TRUE) < 0)
                FAIL_STACK_ERROR

            /* Close the dataset */
            if(H5Dclose(dset) < 0)
                TEST_ERROR

            /* Close the file with the bogus objects */
            if(H5Fclose(file2) < 0)
                TEST_ERROR

            PASSED();

            /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) with RW intent this time */
            if((file2 = H5Fopen(testfile, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
                TEST_ERROR

            TESTING("object with unknown header message & 'fail if unknown and open for write' flag set");

            /* Attempt to open the dataset with the unknown header message, and "fail if unknown and open for write" flag */
            H5E_BEGIN_TRY {
                dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT);
            } H5E_END_TRY;
            if(dset >= 0) {
                H5Dclose(dset);
                TEST_ERROR
            } /* end if */

            /* Close the file with the bogus objects */
            if(H5Fclose(file2) < 0)
                TEST_ERROR

            PASSED();
        }

        /* Close the file we created */
        if(H5Fclose(file) < 0)
            TEST_ERROR

	/* Test object header creation metadata cache issues */
	if(test_ohdr_cache(filename, fapl) < 0)
            TEST_ERROR
    } /* end for */
Пример #14
0
/*
 * test_strpad
 * Tests string padding for a UTF-8 string.
 * Converts strings to shorter and then longer strings.
 * Borrows heavily from dtypes.c, but is more complicated because
 * the string is randomly generated.
 */
void test_strpad(hid_t UNUSED fid, const char *string)
{
    /* buf is used to hold the data that H5Tconvert operates on. */
    char     buf[LONG_BUF_SIZE];

    /* cmpbuf holds the output that H5Tconvert should produce,
     * to compare against the actual output. */
    char     cmpbuf[LONG_BUF_SIZE];

    /* new_string is a slightly modified version of the UTF-8
     * string to make the tests run more smoothly. */
    char     new_string[MAX_STRING_LENGTH + 2];

    size_t   length;  /* Length of new_string in bytes */
    size_t   small_len;  /* Size of the small datatype */
    size_t   big_len;   /* Size of the larger datatype */
    hid_t    src_type, dst_type;
    herr_t   ret;

    /* The following tests are simpler if the UTF-8 string contains
     * the right number of bytes (even or odd, depending on the test).
     * We create a 'new_string' whose length is convenient by prepending
     * an 'x' to 'string' when necessary. */
    length = HDstrlen(string);
    if(length % 2 != 1)
    {
      HDstrcpy(new_string, "x");
      HDstrcat(new_string, string);
      length++;
    } else {
      HDstrcpy(new_string, string);
    }


    /* Convert a null-terminated string to a shorter and longer null
     * terminated string. */

    /* Create a src_type that holds the UTF-8 string and its final NULL */
    big_len = length + 1;                     /* +1 byte for final NULL */
    HDassert((2*big_len)<=sizeof(cmpbuf));
    src_type = mkstr(big_len, H5T_STR_NULLTERM);
    CHECK(src_type, FAIL, "mkstr");
    /* Create a dst_type that holds half of the UTF-8 string and a final
     * NULL */
    small_len = (length + 1) / 2;
    dst_type = mkstr(small_len, H5T_STR_NULLTERM);
    CHECK(dst_type, FAIL, "mkstr");

    /* Fill the buffer with two copies of the UTF-8 string, each with a
     * terminating NULL.  It will look like "abcdefg\0abcdefg\0". */
    strncpy(buf, new_string, big_len);
    strncpy(&buf[big_len], new_string, big_len);

    ret = H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT);
    CHECK(ret, FAIL, "H5Tconvert");

    /* After conversion, the buffer should look like
     * "abc\0abc\0abcdefg\0".  Note that this is just what the bytes look
     * like; UTF-8 characters may well have been truncated.
     * To check that the conversion worked properly, we'll build this
     * string manually. */
    HDstrncpy(cmpbuf, new_string, small_len - 1);
    cmpbuf[small_len - 1] = '\0';
    HDstrncpy(&cmpbuf[small_len], new_string, small_len -1);
    cmpbuf[2 * small_len - 1] = '\0';
    HDstrcpy(&cmpbuf[2 * small_len], new_string);

    VERIFY(HDmemcmp(buf, cmpbuf, 2*big_len), 0, "HDmemcmp");

    /* Now convert from smaller datatype to bigger datatype.  This should
     * leave our buffer looking like: "abc\0\0\0\0\0abc\0\0\0\0\0" */
    ret = H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT);
    CHECK(ret, FAIL, "H5Tconvert");

    /* First fill the buffer with NULLs */
    HDmemset(cmpbuf, '\0', (size_t)LONG_BUF_SIZE);
    /* Copy in the characters */
    HDstrncpy(cmpbuf, new_string, small_len -1);
    HDstrncpy(&cmpbuf[big_len], new_string, small_len -1);

    VERIFY(HDmemcmp(buf, cmpbuf, 2*big_len), 0, "HDmemcmp");

    ret = H5Tclose(src_type);
    CHECK(ret, FAIL, "H5Tclose");
    ret = H5Tclose(dst_type);
    CHECK(ret, FAIL, "H5Tclose");


    /* Now test null padding.  Null-padded strings do *not* need
     * terminating NULLs, so the sizes of the datatypes are slightly
     * different and we want a string with an even number of characters. */
    length = HDstrlen(string);
    if(length % 2 != 0)
    {
      HDstrcpy(new_string, "x");
      HDstrcat(new_string, string);
      length++;
    } else {
      HDstrcpy(new_string, string);
    }

    /* Create a src_type that holds the UTF-8 string */
    big_len = length;
    HDassert((2*big_len)<=sizeof(cmpbuf));
    src_type = mkstr(big_len, H5T_STR_NULLPAD);
    CHECK(src_type, FAIL, "mkstr");
    /* Create a dst_type that holds half of the UTF-8 string */
    small_len = length / 2;
    dst_type = mkstr(small_len, H5T_STR_NULLPAD);
    CHECK(dst_type, FAIL, "mkstr");

    /* Fill the buffer with two copies of the UTF-8 string.
     * It will look like "abcdefghabcdefgh". */
    strncpy(buf, new_string, big_len);
    strncpy(&buf[big_len], new_string, big_len);

    ret = H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT);
    CHECK(ret, FAIL, "H5Tconvert");

    /* After conversion, the buffer should look like
     * "abcdabcdabcdefgh".  Note that this is just what the bytes look
     * like; UTF-8 characters may well have been truncated.
     * To check that the conversion worked properly, we'll build this
     * string manually. */
    HDstrncpy(cmpbuf, new_string, small_len);
    HDstrncpy(&cmpbuf[small_len], new_string, small_len);
    HDstrncpy(&cmpbuf[2 * small_len], new_string, big_len);

    VERIFY(HDmemcmp(buf, cmpbuf, 2*big_len), 0, "HDmemcmp");

    /* Now convert from smaller datatype to bigger datatype.  This should
     * leave our buffer looking like: "abcd\0\0\0\0abcd\0\0\0\0" */
    ret = H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT);
    CHECK(ret, FAIL, "H5Tconvert");

    /* First fill the buffer with NULLs */
    HDmemset(cmpbuf, '\0', (size_t)LONG_BUF_SIZE);
    /* Copy in the characters */
    HDstrncpy(cmpbuf, new_string, small_len);
    HDstrncpy(&cmpbuf[big_len], new_string, small_len);

    VERIFY(HDmemcmp(buf, cmpbuf, 2*big_len), 0, "HDmemcmp");

    ret = H5Tclose(src_type);
    CHECK(ret, FAIL, "H5Tclose");
    ret = H5Tclose(dst_type);
    CHECK(ret, FAIL, "H5Tclose");


    /* Test space padding.  This is very similar to null-padding; we can
       use the same values of length, small_len, and big_len. */

    src_type = mkstr(big_len, H5T_STR_SPACEPAD);
    CHECK(src_type, FAIL, "mkstr");
    dst_type = mkstr(small_len, H5T_STR_SPACEPAD);
    CHECK(src_type, FAIL, "mkstr");

    /* Fill the buffer with two copies of the UTF-8 string.
     * It will look like "abcdefghabcdefgh". */
    HDstrcpy(buf, new_string);
    HDstrcpy(&buf[big_len], new_string);

    ret = H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT);
    CHECK(ret, FAIL, "H5Tconvert");

    /* After conversion, the buffer should look like
     * "abcdabcdabcdefgh".  Note that this is just what the bytes look
     * like; UTF-8 characters may have been truncated.
     * To check that the conversion worked properly, we'll build this
     * string manually. */
    HDstrncpy(cmpbuf, new_string, small_len);
    HDstrncpy(&cmpbuf[small_len], new_string, small_len);
    HDstrncpy(&cmpbuf[2 * small_len], new_string, big_len);

    VERIFY(HDmemcmp(buf, cmpbuf, 2*big_len), 0, "HDmemcmp");

    /* Now convert from smaller datatype to bigger datatype.  This should
     * leave our buffer looking like: "abcd    abcd    " */
    ret = H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT);
    CHECK(ret, FAIL, "H5Tconvert");

    /* First fill the buffer with spaces */
    HDmemset(cmpbuf, ' ', (size_t)LONG_BUF_SIZE);
    /* Copy in the characters */
    HDstrncpy(cmpbuf, new_string, small_len);
    HDstrncpy(&cmpbuf[big_len], new_string, small_len);

    VERIFY(HDmemcmp(buf, cmpbuf, 2*big_len), 0, "HDmemcmp");

    ret = H5Tclose(src_type);
    CHECK(ret, FAIL, "H5Tclose");
    ret = H5Tclose(dst_type);
    CHECK(ret, FAIL, "H5Tclose");
}
Пример #15
0
/*
 * test_objnames
 * Tests that UTF-8 can be used for object names in the file.
 * Tests groups, datasets, named datatypes, and soft links.
 * Note that this test doesn't actually mark the names as being
 * in UTF-8.  At the time this test was written, that feature
 * didn't exist in HDF5, and when the character encoding property
 * was added to links it didn't change how they were stored in the file,
 * -JML 2/2/2006
 */
void test_objnames(hid_t fid, const char* string)
{
  hid_t grp_id, grp1_id, grp2_id, grp3_id;
  hid_t type_id, dset_id, space_id;
  char read_buf[MAX_STRING_LENGTH];
  char path_buf[MAX_PATH_LENGTH];
  hsize_t dims=1;
  hobj_ref_t obj_ref;
  herr_t ret;

  /* Create a group with a UTF-8 name */
  grp_id = H5Gcreate2(fid, string, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  CHECK(grp_id, FAIL, "H5Gcreate2");

  /* Set a comment on the group to test that we can access the group
   * Also test that UTF-8 comments can be read.
   */
  ret = H5Oset_comment_by_name(fid, string, string, H5P_DEFAULT);
  CHECK(ret, FAIL, "H5Oset_comment_by_name");
  ret = H5Oget_comment_by_name(fid, string, read_buf, (size_t)MAX_STRING_LENGTH, H5P_DEFAULT);
  CHECK(ret, FAIL, "H5Oget_comment_by_name");

  ret = H5Gclose(grp_id);
  CHECK(ret, FAIL, "H5Gclose");

  VERIFY(HDstrcmp(string, read_buf), 0, "strcmp");

  /* Create a new dataset with a UTF-8 name */
  grp1_id = H5Gcreate2(fid, GROUP1_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  CHECK(grp1_id, FAIL, "H5Gcreate2");

  space_id = H5Screate_simple(RANK, &dims, NULL);
  CHECK(space_id, FAIL, "H5Screate_simple");
  dset_id = H5Dcreate2(grp1_id, string, H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  CHECK(dset_id, FAIL, "H5Dcreate2");

  /* Make sure that dataset can be opened again */
  ret = H5Dclose(dset_id);
  CHECK(ret, FAIL, "H5Dclose");
  ret = H5Sclose(space_id);
  CHECK(ret, FAIL, "H5Sclose");

  dset_id = H5Dopen2(grp1_id, string, H5P_DEFAULT);
  CHECK(ret, FAIL, "H5Dopen2");
  ret = H5Dclose(dset_id);
  CHECK(ret, FAIL, "H5Dclose");
  ret = H5Gclose(grp1_id);
  CHECK(ret, FAIL, "H5Gclose");

  /* Do the same for a named datatype */
  grp2_id = H5Gcreate2(fid, GROUP2_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  CHECK(grp2_id, FAIL, "H5Gcreate2");

  type_id = H5Tcreate(H5T_OPAQUE, (size_t)1);
  CHECK(type_id, FAIL, "H5Tcreate");
  ret = H5Tcommit2(grp2_id, string, type_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  CHECK(type_id, FAIL, "H5Tcommit2");
  ret = H5Tclose(type_id);
  CHECK(type_id, FAIL, "H5Tclose");

  type_id = H5Topen2(grp2_id, string, H5P_DEFAULT);
  CHECK(type_id, FAIL, "H5Topen2");
  ret = H5Tclose(type_id);
  CHECK(type_id, FAIL, "H5Tclose");

  /* Don't close the group -- use it to test that object references
   * can refer to objects named in UTF-8 */

  space_id = H5Screate_simple(RANK, &dims, NULL);
  CHECK(space_id, FAIL, "H5Screate_simple");
  dset_id = H5Dcreate2(grp2_id, DSET3_NAME, H5T_STD_REF_OBJ, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  CHECK(ret, FAIL, "H5Dcreate2");

  /* Create reference to named datatype */
  ret = H5Rcreate(&obj_ref, grp2_id, string, H5R_OBJECT, -1);
  CHECK(ret, FAIL, "H5Rcreate");
  /* Write selection and read it back*/
  ret = H5Dwrite(dset_id, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, &obj_ref);
  CHECK(ret, FAIL, "H5Dwrite");
  ret = H5Dread(dset_id, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, &obj_ref);
  CHECK(ret, FAIL, "H5Dread");

  /* Ensure that we can open named datatype using object reference */
  type_id = H5Rdereference2(dset_id, H5P_DEFAULT, H5R_OBJECT, &obj_ref);
  CHECK(type_id, FAIL, "H5Rdereference2");
  ret = H5Tcommitted(type_id);
  VERIFY(ret, 1, "H5Tcommitted");

  ret = H5Tclose(type_id);
  CHECK(type_id, FAIL, "H5Tclose");
  ret = H5Dclose(dset_id);
  CHECK(ret, FAIL, "H5Dclose");
  ret = H5Sclose(space_id);
  CHECK(ret, FAIL, "H5Sclose");

  ret = H5Gclose(grp2_id);
  CHECK(ret, FAIL, "H5Gclose");

  /* Create "group3".  Build a hard link from group3 to group2, which has
   * a datatype with the UTF-8 name.  Create a soft link in group3
   * pointing through the hard link to the datatype.  Give the soft
   * link a name in UTF-8.  Ensure that the soft link works. */

  grp3_id = H5Gcreate2(fid, GROUP3_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  CHECK(grp3_id, FAIL, "H5Gcreate2");

  ret = H5Lcreate_hard(fid, GROUP2_NAME, grp3_id, GROUP2_NAME, H5P_DEFAULT, H5P_DEFAULT);
  CHECK(ret, FAIL, "H5Lcreate_hard");
  HDstrcpy(path_buf, GROUP2_NAME);
  HDstrcat(path_buf, "/");
  HDstrcat(path_buf, string);
  ret = H5Lcreate_hard(grp3_id, path_buf, H5L_SAME_LOC, string, H5P_DEFAULT, H5P_DEFAULT);
  CHECK(ret, FAIL, "H5Lcreate_hard");

  /* Open named datatype using soft link */
  type_id = H5Topen2(grp3_id, string, H5P_DEFAULT);
  CHECK(type_id, FAIL, "H5Topen2");

  ret = H5Tclose(type_id);
  CHECK(type_id, FAIL, "H5Tclose");
  ret = H5Gclose(grp3_id);
  CHECK(ret, FAIL, "H5Gclose");
}
static int read_data( const char* fname, /*IN*/
                     hsize_t *width, /*OUT*/
                     hsize_t *height /*OUT*/ )
{
    int    i, n;
    int    color_planes;
    char   str[20];
    FILE   *f;
    int    w, h;
    char   *srcdir = getenv("srcdir"); /* the source directory */
    char   data_file[512]="";          /* buffer to hold name of existing data file */

    /*-------------------------------------------------------------------------
    * compose the name of the file to open, using "srcdir", if appropriate
    *-------------------------------------------------------------------------
    */
    HDstrcpy(data_file, "");
    if (srcdir)
    {
        HDstrcpy(data_file, srcdir);
        HDstrcat(data_file, "/");
    }
    HDstrcat(data_file,fname);

    /*-------------------------------------------------------------------------
    * read
    *-------------------------------------------------------------------------
    */

    f = HDfopen(data_file, "r");
    if ( f == NULL )
    {
        printf( "Could not open file %s. Try set $srcdir \n", data_file );
        return -1;
    }

    fscanf( f, "%s", str );
    fscanf( f, "%d", &color_planes );
    fscanf( f, "%s", str );
    fscanf( f, "%d", &h);
    fscanf( f, "%s", str );
    fscanf( f, "%d", &w);

    *width = (hsize_t)w;
    *height = (hsize_t)h;

    if ( image_data )
    {
        HDfree( image_data );
        image_data=NULL;
    }

    image_data = (unsigned char*) HDmalloc (w * h * color_planes * sizeof( unsigned char ));

    for (i = 0; i < h * w * color_planes ; i++)
    {
        fscanf( f, "%d",&n );
        image_data[i] = (unsigned char)n;
    }
    HDfclose(f);

    return 1;

}
Пример #17
0
/*-------------------------------------------------------------------------
 * Function:	test_4
 *
 * Purpose:	Tests opening an external link twice.  It exposed a bug
 *              in the library.  This function tests the fix.  This test
 *              doesn't work with MULTI driver.
 *
 * Return:	Success:	0
 *
 * 		Failure:	number of errors
 *
 * Programmer:	Raymond Lu
 *              5 November 2007
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_4 (hid_t fapl)
{
    hid_t fid = -1;
    hid_t gid = -1;
    hid_t xid = -1;
    hid_t xid2 = -1;
    char  filename[1024];		/*file name			*/
    char  pathname[1024];
    char *srcdir = getenv("srcdir"); /*where the src code is located*/

    TESTING("opening external link twice");

    /* Make a copy of the FAPL, in order to switch to the sec2 driver */
    /* (useful when running test with another VFD) */
    if((fapl = H5Pcopy(fapl)) < 0) FAIL_STACK_ERROR;

    /* Switch local copy of the fapl to the sec2 driver */
    if(H5Pset_fapl_sec2(fapl) < 0) FAIL_STACK_ERROR;

    h5_fixname(FILENAME[3], fapl, filename, sizeof filename);

    if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        goto error;

    if((gid = H5Gopen2(fid, "/", H5P_DEFAULT)) < 0)
        goto error;

    pathname[0] = '\0';
    /* Generate correct name for test file by prepending the source path */
    if(srcdir && ((HDstrlen(srcdir) + HDstrlen(LINKED_FILE) + 1) < sizeof(pathname))) {
        HDstrcpy(pathname, srcdir);
        HDstrcat(pathname, "/");
    }
    HDstrcat(pathname, LINKED_FILE);

    /* Create an external link to an existing file*/
    if(H5Lcreate_external(pathname, "/group", gid, " link", H5P_DEFAULT, H5P_DEFAULT) < 0)
        goto error;

    if(H5Gclose(gid) < 0)
        goto error;

    if(H5Fclose(fid) < 0)
        goto error;

    /* Reopen the file */
    if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
        goto error;

    /* Open the external link which is "/ link" as created previously via H5Lcreate_external() */
    if((xid = H5Gopen2(fid, "/ link", H5P_DEFAULT)) < 0)
        goto error;

    /* Open the external link twice */
    if((xid2 = H5Gopen2(xid, ".", H5P_DEFAULT)) < 0)
        goto error;

    if(H5Gclose(xid2) < 0)
        goto error;

    if(H5Gclose(xid) < 0)
        goto error;

    if(H5Fclose(fid) < 0)
        goto error;

    if(H5Pclose(fapl) < 0)
        TEST_ERROR

    PASSED();

    return 0;

 error:
    H5E_BEGIN_TRY {
        H5Gclose(gid);
        H5Gclose(xid);
        H5Gclose(xid2);
        H5Fclose(fid);
    } H5E_END_TRY;
    return 1;
}
Пример #18
0
/*
 * Function:    sio_create_filename
 * Purpose:     Create a new filename to write to. Determine the correct
 *              suffix to append to the filename by the type of I/O we're
 *              doing. Also, place in the /tmp/{$USER,$LOGIN} directory if
 *              USER or LOGIN are specified in the environment.
 * Return:      Pointer to filename or NULL
 * Programmer:  Bill Wendling, 21. November 2001
 * Modifications: Support for file drivers. Christian Chilan, April, 2008
 */
    static char *
sio_create_filename(iotype iot, const char *base_name, char *fullname, size_t size, parameters *param)
{
    const char *prefix, *suffix="";
    char *ptr, last = '\0';
    size_t i, j;
    vfdtype vfd;
    vfd = param->vfd;

    if (!base_name || !fullname || size < 1)
    return NULL;

    memset(fullname, 0, size);

    switch (iot) {
    case POSIXIO:
        suffix = ".posix";
        break;
    case HDF5:
        suffix = ".h5";
        if (vfd == family)
            suffix = "%05d.h5";
        else if (vfd == multi)
            suffix = NULL;
        break;
    default:
        /* unknown request */
        HDfprintf(stderr, "Unknown IO type request (%d)\n", (int)iot);
        HDassert(0 && "Unknown IO type");
        break;
    }

    /* First use the environment variable and then try the constant */
    prefix = HDgetenv("HDF5_PREFIX");

#ifdef HDF5_PREFIX
    if (!prefix)
    prefix = HDF5_PREFIX;
#endif  /* HDF5_PREFIX */

    /* Prepend the prefix value to the base name */
    if (prefix && *prefix) {
    /* If the prefix specifies the HDF5_PREFIX directory, then
     * default to using the "/tmp/$USER" or "/tmp/$LOGIN"
     * directory instead. */
    register char *user, *login, *subdir;

    user = HDgetenv("USER");
    login = HDgetenv("LOGIN");
    subdir = (user ? user : login);

    if (subdir) {
        for (i = 0; i < size-1 && prefix[i]; i++)
        fullname[i] = prefix[i];

        fullname[i++] = '/';

        for (j = 0; i < size && subdir[j]; i++, j++)
        fullname[i] = subdir[j];
    } else {
        /* We didn't append the prefix yet */
        HDstrncpy(fullname, prefix, size);
        fullname[size - 1] = '\0';
    }

    if ((HDstrlen(fullname) + HDstrlen(base_name) + 1) < size) {
        /* Append the base_name with a slash first. Multiple slashes are
         * handled below. */
        h5_stat_t buf;

        if (HDstat(fullname, &buf) < 0)
        /* The directory doesn't exist just yet */
        if (HDmkdir(fullname, 0755) < 0 && errno != EEXIST) {
            /* We couldn't make the "/tmp/${USER,LOGIN}" subdirectory.
             * Default to PREFIX's original prefix value. */
            HDstrcpy(fullname, prefix);
        }

        HDstrcat(fullname, "/");
        HDstrcat(fullname, base_name);
    } else {
        /* Buffer is too small */
        return NULL;
    }
    } else if (strlen(base_name) >= size) {
    /* Buffer is too small */
        return NULL;
    } else {
        HDstrcpy(fullname, base_name);
    }

    /* Append a suffix */
    if (suffix) {
        if (HDstrlen(fullname) + HDstrlen(suffix) >= size)
            return NULL;

        HDstrcat(fullname, suffix);
    }

    /* Remove any double slashes in the filename */
    for (ptr = fullname, i = j = 0; ptr && (i < size); i++, ptr++) {
        if (*ptr != '/' || last != '/')
            fullname[j++] = *ptr;

        last = *ptr;
    }

    return fullname;
}
Пример #19
0
static int read_palette(const char* fname,
                        rgb_t *palette,
                        size_t palette_size)
{
    FILE          *file;
    char          buffer[80];
    unsigned      u;
    unsigned int  red;
    unsigned int  green;
    unsigned int  blue;
    unsigned      nentries;
    char          *srcdir = getenv("srcdir"); /* the source directory */
    char          data_file[512];             /* buffer to hold name of existing data file */

    /*-------------------------------------------------------------------------
    * compose the name of the file to open, using "srcdir", if appropriate
    *-------------------------------------------------------------------------
    */
    HDstrcpy(data_file, "");
    if (srcdir)
    {
        HDstrcpy(data_file, srcdir);
        HDstrcat(data_file, "/");
    }
    HDstrcat(data_file,fname);

    /* ensure the given palette is valid */
    if (!palette)
        return -1;

    /* open the input file */
    if (!(file = HDfopen(data_file, "r")))
    {
        printf( "Could not open file %s. Try set $srcdir \n", data_file );
        return -1;
    }

    /* read the file ident string */
    if (HDfgets(buffer, sizeof(buffer), file) == NULL)
    {
        HDfclose(file);
        return -1;
    }

    /* ensure it matches the palette file ident string */
    if ( HDstrncmp(buffer, STRING_JASC, sizeof(STRING_JASC) - 1) != 0 &&
            HDstrncmp(buffer, STRING_CWPAL, sizeof(STRING_CWPAL) - 1) != 0 )
    {
        HDfclose(file);
        return -1;
    }

    /* read the version string */
    if (HDfgets(buffer, sizeof(buffer), file) == NULL)
    {
        HDfclose(file);
        return -1;
    }

    /* ensure it matches the palette file version string */
    if ( HDstrncmp(buffer, VERSION_JASC, sizeof(VERSION_JASC) - 1) != 0 &&
            HDstrncmp(buffer, VERSION_CWPAL, sizeof(VERSION_CWPAL) - 1) != 0 )
    {
        HDfclose(file);
        return -1;
    }

    /* read the number of colors */
    if (HDfgets(buffer, sizeof(buffer), file) == NULL)
    {
        HDfclose(file);
        return -1;
    }


    /* extract the number of colors.
    check for missing version or number of colors
    in this case it reads the first entry
    */
    if ( HDstrlen( buffer ) > 4 )
    {
        HDfclose(file);
        return -1;
    }

    if (sscanf(buffer, "%u", &nentries) != 1)
    {
        HDfclose(file);
        return -1;
    }

    /* ensure there are a sensible number of colors in the palette */
    if ((nentries > 256) || (nentries > palette_size))
    {
        HDfclose(file);
        return(-1);
    }

    /* read the palette entries */
    for (u = 0; u < nentries; u++)
    {
        /* extract the red, green and blue color components.  */
        if (fscanf(file, "%u %u %u", &red, &green, &blue) != 3)
        {
            HDfclose(file);
            return -1;
        }
        /* store this palette entry */
        palette[u].r = (unsigned char)red;
        palette[u].g = (unsigned char)green;
        palette[u].b = (unsigned char)blue;
    }

    /* close file */
    HDfclose(file);

    return (int)nentries;
}
Пример #20
0
static int test_generate(void)
{
    hid_t    fid;
    hsize_t  pal_dims[2] = { 256, 3 };
    float    *data;
    int      imax, jmax, kmax;
    int      n_elements;
    float    valex, xmin, xmax, value;
    FILE     *f = NULL;
    char     *srcdir = getenv("srcdir"); /* the source directory */
    char     data_file[512]="";          /* buffer to hold name of existing data file */
    int      i;
    int      retval = FAIL;

    /* create a file using default properties */
    if ((fid=H5Fcreate(FILE3,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0)
        goto out;

    printf("Testing read and process data and make indexed images\n");

    /*-------------------------------------------------------------------------
    * compose the name of the file to open, using the srcdir, if appropriate
    *-------------------------------------------------------------------------
    */
    if ( srcdir )
    {
        HDstrcpy(data_file, srcdir);
        HDstrcat(data_file, "/");
    }
    HDstrcat(data_file,DATA_FILE4);

    /*-------------------------------------------------------------------------
    * read data; the file data format is described below
    *-------------------------------------------------------------------------
    */

    f  = HDfopen( data_file, "r" ) ;
    if ( f == NULL )
    {
        printf( "Could not find file %s. Try set $srcdir \n", data_file );
        goto out;
    }

    /*
    !The first line of the ASCII file contains the dimension of the array :
    ! IMAX, JMAX, KMAX. The integers are stored with the FORTRAN format I5.
    !The second line contains the exclusion value, the minimum and the maximum value of this
    ! file. These numbers are stored with the FORTRAN format E12.5.
    ! The remaining lines contains the data of the array, with 5 numbers per line
    ! (except the last line for each I-line).
    ! The array is stored in horizontal slices from sea surface to sea bottom and from
    ! north to south. So the indexes go from :
    !
    !   DO K = KMAX to 1
    !       DO J = JMAX to 1
    !           DO I = 1 to IMAX
    !              read
    !           OD
    !       OD
    !   OD
    !
    !              ____________________________
    !             /                           /| (imax,jmax,kmax)
    !            /        sea surface        / |
    !           /                           /  |
    !          /__________________________ /   |
    !          |                          |    |
    !          |                          |    | (imax,jmax,1)        n
    !          |                          |   /                      /
    !          |                          |  /                      /
    !     ^  j |                          | /             w  <-----o-----> e
    !  k  |  / |__________________________|/                      /
    !     | /                           (imax,1,1)               /
    !     |---------->                                          s
    !     i
    !
    */


    fscanf( f, "%d %d %d", &imax, &jmax, &kmax );
    fscanf( f, "%f %f %f", &valex, &xmin, &xmax );

    /* Sanity check on scanned-in values */
    if(imax < 1 || jmax < 1 || kmax < 1)
        goto out;

    /* Test product for integer overflow */
    if(imax > INT_MAX / jmax)
        goto out;
    if(imax * jmax > INT_MAX / kmax)
        goto out;

    n_elements = imax * jmax * kmax;

    /* Test buffer sizes for overflow */
    if(n_elements > INT_MAX / (int)sizeof(unsigned char))
        goto out;
    if(n_elements > INT_MAX / (int)sizeof(float))
        goto out;
    
    data = (float *)HDmalloc((size_t)n_elements * sizeof(float));
    if(NULL == data)
        goto out;
    image_data = (unsigned char *)HDmalloc((size_t)n_elements * sizeof(unsigned char));
    if(NULL == image_data)
        goto out;

    for ( i = 0; i < n_elements; i++ )
    {
        fscanf( f, "%f ", &value );
        data[i] = value;
    }
    HDfclose(f);
    f = NULL;

    /*-------------------------------------------------------------------------
    * transform the data from floating point to unsigned char
    * we are processing all the data here
    *-------------------------------------------------------------------------
    */

    TESTING2("make indexed image from all the data");

    for ( i = 0; i < n_elements; i++ )
        image_data[i] = (unsigned char)(( 255 * (data[i] - xmin ) ) / (xmax - xmin ));

    /* Make the image */
    if ((H5IMmake_image_8bit(fid,"All data",(hsize_t)imax,(hsize_t)jmax,image_data))<0)
        goto out;

    PASSED();

    /*-------------------------------------------------------------------------
    * transform the data from floating point to unsigned char
    * here we just process the land data
    *-------------------------------------------------------------------------
    */

    TESTING2("make indexed image from land data");

    for ( i = 0; i < n_elements; i++ )
    {
        if ( data[i] < 0 )
            image_data[i] = 0;
        else
            image_data[i] = (unsigned char)(( 255 * (data[i] ) ) / xmax );
    }

    /* make the image */
    if ((H5IMmake_image_8bit(fid,"Land data",(hsize_t)imax,(hsize_t)jmax,image_data))<0)
        goto out;

    PASSED();

    /*-------------------------------------------------------------------------
    * transform the data from floating point to unsigned char
    * here we just process the sea data
    *-------------------------------------------------------------------------
    */

    TESTING2("make indexed image from sea data");

    for ( i = 0; i < n_elements; i++ )
    {
        if ( data[i] > 0 )
            image_data[i] = 0;
        else
            image_data[i] = (unsigned char)(( 255 * (data[i] - xmin ) ) / xmin );
    }

    /* make the image */
    if ((H5IMmake_image_8bit(fid,"Sea data",(hsize_t)imax,(hsize_t)jmax,image_data))<0)
        goto out;

    PASSED();

    /*-------------------------------------------------------------------------
    * make a palette and attach it to the datasets
    *-------------------------------------------------------------------------
    */

    TESTING2("attaching palettes");

    /* make a palette */
    if ((H5IMmake_palette(fid,PAL1_NAME,pal_dims,pal_rgb))<0)
        goto out;

    /* attach the palette to the image datasets */
    if ((H5IMlink_palette(fid,"All data",PAL1_NAME))<0)
        goto out;
    if ((H5IMlink_palette(fid,"Land data",PAL1_NAME))<0)
        goto out;
    if ((H5IMlink_palette(fid,"Sea data",PAL1_NAME))<0)
        goto out;

    PASSED();


    /*-------------------------------------------------------------------------
    * close
    *-------------------------------------------------------------------------
    */
    if (H5Fclose(fid)<0)
        goto out;

    /* Release memory buffers */
    HDfree(data);
    HDfree(image_data);

    /* Indicate success */
    return 0;

    /* error zone, gracefully close */
out:
    /* Release memory buffers */
    if(data)
        HDfree(data);
    if(image_data)
        HDfree(image_data);

    H5E_BEGIN_TRY {
        H5Fclose(fid);
    } H5E_END_TRY;
    if(f)
        HDfclose(f);
    H5_FAILED();
    return retval;
}
Пример #21
0
/*-------------------------------------------------------------------------
 * Function:    test_family_compat
 *
 * Purpose:     Tests the backward compatibility for FAMILY driver.
 *              See if we can open files created with v1.6 library.
 *              The source file was created by the test/file_handle.c
 *              of the v1.6 library.  Then tools/misc/h5repart.c was
 *              used to concantenated.  The command was "h5repart -m 5k
 *              family_file%05d.h5 family_v16_%05d.h5".
 *
 * Return:      Success:        0
 *              Failure:        -1
 *
 * Programmer:  Raymond Lu
 *              June 3, 2005
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_family_compat(void)
{
    hid_t       file = (-1), fapl;
    hid_t       dset;
    char        dname[]="dataset";
    char        filename[1024];
    char        pathname[1024], pathname_individual[1024];
    char        newname[1024], newname_individual[1024];
    FILE        *tmp_fp, *old_fp;       /* Pointers to temp & old files */
    int         counter = 0;

    TESTING("FAMILY file driver backward compatibility");

    /* Set property list and file name for FAMILY driver */
    fapl = h5_fileaccess();

    if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE2, H5P_DEFAULT) < 0)
        TEST_ERROR;

    h5_fixname(COMPAT_BASENAME, fapl, filename, sizeof filename);
    h5_fixname(FILENAME[3], fapl, newname, sizeof newname);

    pathname[0] = '\0';
    HDstrcat(pathname, filename);

    /* The following code makes the copies of the family files in the source directory.
     * Since we're going to open the files with write mode, this protects the original
     * files.
     */
    sprintf(newname_individual, newname, counter);
    sprintf(pathname_individual, pathname, counter);

    while (h5_make_local_copy(pathname_individual, newname_individual) >= 0) {
        counter++;
        sprintf(newname_individual, newname, counter);
        sprintf(pathname_individual, pathname, counter);
    }

    if ((NULL != (old_fp = HDfopen(pathname_individual,"rb"))) && 
        (NULL != (tmp_fp = HDfopen(newname_individual,"wb"))))
	TEST_ERROR;

    /* Make sure we can open the file.  Use the read and write mode to flush the
     * superblock. */
    if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0)
        TEST_ERROR;

    if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0)
        TEST_ERROR;

    if(H5Dclose(dset) < 0)
        TEST_ERROR;

    if(H5Fclose(file) < 0)
        TEST_ERROR;

    /* Open the file again to make sure it isn't corrupted. */
    if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0)
        TEST_ERROR;

    if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0)
        TEST_ERROR;

    if(H5Dclose(dset) < 0)
        TEST_ERROR;

    if(H5Fclose(file) < 0)
        TEST_ERROR;

    h5_cleanup(FILENAME, fapl);

    PASSED();

    return 0;

error:
    H5E_BEGIN_TRY {
        H5Fclose(file);
        H5Pclose(fapl); 
    } H5E_END_TRY;

    return -1;
} /* end test_family_compat() */
Пример #22
0
static
void read_info(const char *filename,
               pack_opt_t *options)
{

    char stype[10];
    char comp_info[1024];
    FILE *fp;
    char c;
    int  i, rc=1;
    char  *srcdir = getenv("srcdir"); /* the source directory */
    char  data_file[512]="";          /* buffer to hold name of existing file */

    /* compose the name of the file to open, using the srcdir, if appropriate */
    if (srcdir){
        HDstrcpy(data_file,srcdir);
        HDstrcat(data_file,"/");
    }
    HDstrcat(data_file,filename);


    if ((fp = HDfopen(data_file, "r")) == (FILE *)NULL) {
        error_msg("cannot open options file %s\n", filename);
        HDexit(EXIT_FAILURE);
    }

    /* cycle until end of file reached */
    while( 1 )
    {
        rc=fscanf(fp, "%s", stype);
        if (rc==-1)
            break;

       /*-------------------------------------------------------------------------
        * filter
        *-------------------------------------------------------------------------
        */
        if (HDstrcmp(stype,"-f") == 0) {

            /* find begining of info */
            i=0; c='0';
            while( c!=' ' )
            {
                fscanf(fp, "%c", &c);
                if (HDfeof(fp)) break;
            }
            c='0';
            /* go until end */
            while( c!=' ' )
            {
                fscanf(fp, "%c", &c);
                comp_info[i]=c;
                i++;
                if (HDfeof(fp)) break;
                if (c==10 /*eol*/) break;
            }
            comp_info[i-1]='\0'; /*cut the last " */

            if (h5repack_addfilter(comp_info,options)==-1){
                error_msg("could not add compression option\n");
                HDexit(EXIT_FAILURE);
            }
        }
        /*-------------------------------------------------------------------------
        * layout
        *-------------------------------------------------------------------------
        */
        else if (HDstrcmp(stype,"-l") == 0) {

            /* find begining of info */
            i=0; c='0';
            while( c!=' ' )
            {
                fscanf(fp, "%c", &c);
                if (HDfeof(fp)) break;
            }
            c='0';
            /* go until end */
            while( c!=' ' )
            {
                fscanf(fp, "%c", &c);
                comp_info[i]=c;
                i++;
                if (HDfeof(fp)) break;
                if (c==10 /*eol*/) break;
            }
            comp_info[i-1]='\0'; /*cut the last " */

            if (h5repack_addlayout(comp_info,options)==-1){
                error_msg("could not add chunck option\n");
                HDexit(EXIT_FAILURE);
            }
        }
        /*-------------------------------------------------------------------------
        * not valid
        *-------------------------------------------------------------------------
        */
        else {
            error_msg("bad file format for %s", filename);
            HDexit(EXIT_FAILURE);
        }
    }

    HDfclose(fp);
    return;
}