コード例 #1
0
ファイル: nc5dispatch.c プロジェクト: UV-CDAT/netcdf-c
static int
NC5_create(const char *path, int cmode,
	  size_t initialsz, int basepe, size_t *chunksizehintp,
	  int use_parallel, void* mpidata,
	  struct NC_Dispatch* table, NC* nc)
{
    int res;
    NC5_INFO* nc5;
    MPI_Comm comm = MPI_COMM_WORLD;
    MPI_Info info = MPI_INFO_NULL;

    /* Check the cmode for only valid flags*/
    if(cmode & ~LEGAL_CREATE_FLAGS)
	return NC_EINVAL;

    /* Cannot have both MPIO flags */
    if((cmode & (NC_MPIIO|NC_MPIPOSIX)) == (NC_MPIIO|NC_MPIPOSIX))
	return NC_EINVAL;

    /* Appears that this comment is wrong; allow 64 bit offset*/
    /* Cannot have 64 bit offset flag */
    /*if(cmode & (NC_64BIT_OFFSET)) return NC_EINVAL;*/

    comm = ((NC_MPI_INFO *)mpidata)->comm;
    info = ((NC_MPI_INFO *)mpidata)->info;

    /* Create our specific NC5_INFO instance */
    nc5 = (NC5_INFO*)calloc(1,sizeof(NC5_INFO));
    if(nc5 == NULL) return NC_ENOMEM;

    /* Link nc5 and nc */
    NC5_DATA_SET(nc,nc5);

    /* Fix up the cmode by keeping only essential flags;
       these are the flags that are the same in netcf.h and pnetcdf.h
    */
#if 0
    cmode &= (NC_WRITE | NC_NOCLOBBER | NC_LOCK | NC_SHARE | NC_64BIT_OFFSET);
#else
    cmode &= (NC_WRITE | NC_NOCLOBBER | NC_LOCK | NC_SHARE );
#endif

    /* It turns out that pnetcdf.h defines a flag called
       NC_64BIT_DATA (not to be confused with NC_64BIT_OFFSET).
       This flag is essential to getting ncmpi_create to create
       a proper pnetcdf format file.
       It just happens that the value of NC_64BIT_DATA is the same
       as the netcdf NC_NETCDF4 flag value. This is probably no accident.

       In any case, this flag must be set.
    */
    cmode |= (NC_NETCDF4);
    res = ncmpi_create(comm, path, cmode, info, &(nc->int_ncid));

    if(res && nc5 != NULL) free(nc5); /* reclaim allocated space */
    return res;
}
コード例 #2
0
ファイル: nc5dispatch.c プロジェクト: syntheticpp/netcdf-c
static int
NC5_open(const char *path, int cmode,
	    int basepe, size_t *chunksizehintp,
	    int use_parallel, void* mpidata,
	    struct NC_Dispatch* table, NC* nc)
{
    int res;
    NC5_INFO* nc5;
    MPI_Comm comm = MPI_COMM_WORLD;
    MPI_Info info = MPI_INFO_NULL;

    /* Check the cmode for only valid flags*/
    if(cmode & ~LEGAL_OPEN_FLAGS)
	return NC_EINVAL;

    /* Cannot have both MPIO flags */
    if((cmode & (NC_MPIIO|NC_MPIPOSIX)) == (NC_MPIIO|NC_MPIPOSIX))
	return NC_EINVAL;

    /* Appears that this comment is wrong; allow 64 bit offset*/
    /* Cannot have 64 bit offset flag */
    /* if(cmode & (NC_64BIT_OFFSET)) return NC_EINVAL; */

    if(mpidata != NULL) {
        comm = ((NC_MPI_INFO *)mpidata)->comm;
        info = ((NC_MPI_INFO *)mpidata)->info;
    } else {
	comm = MPI_COMM_WORLD;
	info = MPI_INFO_NULL;
    }

    /* Fix up the cmode by keeping only essential flags;
       these are the flags that are the same in netcf.h and pnetcdf.h
    */
    cmode &= (NC_WRITE | NC_NOCLOBBER | NC_LOCK | NC_SHARE | NC_64BIT_OFFSET);

    cmode |= (NC_NETCDF4); /* see comment in NC5_create */

    /* Create our specific NC5_INFO instance */
    nc5 = (NC5_INFO*)calloc(1,sizeof(NC5_INFO));
    if(nc5 == NULL) return NC_ENOMEM;

    /* Link nc5 and nc */
    NC5_DATA_SET(nc,nc5);

    res = ncmpi_open(comm, path, cmode, info, &(nc->int_ncid));

    /* Default to independent access, like netCDF-4/HDF5 files. */
    if(!res) {
	res = ncmpi_begin_indep_data(nc->int_ncid);
	nc5->pnetcdf_access_mode = NC_INDEPENDENT;
    }

    return res;
}