mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-21 03:13:42 +08:00
Merge branch 'ejh_try2' of https://github.com/NetCDF-World-Domination-Council/netcdf-c into gh1487.wif
This commit is contained in:
commit
e7cc899264
@ -72,6 +72,7 @@ extern int add_to_NCList(NC*);
|
||||
extern void del_from_NCList(NC*);/* does not free object */
|
||||
extern NC* find_in_NCList(int ext_ncid);
|
||||
extern NC* find_in_NCList_by_name(const char*);
|
||||
extern int move_in_NCList(NC *ncp, int new_id);
|
||||
extern void free_NCList(void);/* reclaim whole list */
|
||||
extern int count_NCList(void); /* return # of entries in NClist */
|
||||
extern int iterate_NCList(int i,NC**); /* Walk from 0 ...; ERANGE return => stop */
|
||||
|
@ -388,6 +388,7 @@ int nc4_file_list_add(int ncid, const char *path, int mode,
|
||||
int nc4_file_list_get(int ncid, char **path, int *mode,
|
||||
void **dispatchdata);
|
||||
int nc4_file_list_del(int ncid);
|
||||
int nc4_file_change_ncid(int ncid, unsigned short new_ncid_index);
|
||||
int nc4_var_list_add(NC_GRP_INFO_T* grp, const char* name, int ndims,
|
||||
NC_VAR_INFO_T **var);
|
||||
int nc4_var_list_add2(NC_GRP_INFO_T* grp, const char* name,
|
||||
|
@ -100,6 +100,35 @@ add_to_NCList(NC* ncp)
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move an NC in the nc_filelist. This is required by PIO.
|
||||
*
|
||||
* @param ncp Pointer to already-allocated and initialized NC struct.
|
||||
* @param new_id New index in the nc_filelist for this file.
|
||||
*
|
||||
* @return ::NC_NOERR No error.
|
||||
* @return ::NC_EINVAL Invalid input.
|
||||
* @author Ed Hartnett
|
||||
*/
|
||||
int
|
||||
move_in_NCList(NC *ncp, int new_id)
|
||||
{
|
||||
/* If no files in list, error. */
|
||||
if (!nc_filelist)
|
||||
return NC_EINVAL;
|
||||
|
||||
/* If new slot is already taken, error. */
|
||||
if (nc_filelist[new_id])
|
||||
return NC_EINVAL;
|
||||
|
||||
/* Move the file. */
|
||||
nc_filelist[ncp->ext_ncid >> ID_SHIFT] = NULL;
|
||||
nc_filelist[new_id] = ncp;
|
||||
ncp->ext_ncid = (new_id << ID_SHIFT);
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an NC struct from the list. This happens when the file is
|
||||
* closed. Relies on all memory in the NC being deallocated after this
|
||||
|
@ -125,30 +125,42 @@ nc4_file_list_add(int ncid, const char *path, int mode, void **dispatchdata)
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/* /\** */
|
||||
/* * @internal Change the ncid of an open file. This is needed for PIO */
|
||||
/* * integration. */
|
||||
/* * */
|
||||
/* * @param ncid The ncid of the file (aka ext_ncid). */
|
||||
/* * @param new_ncid The new ncid to use. */
|
||||
/* * */
|
||||
/* * @return ::NC_NOERR No error. */
|
||||
/* * @return ::NC_EBADID No NC struct with this ext_ncid. */
|
||||
/* * @return ::NC_ENOMEM Out of memory. */
|
||||
/* * @author Ed Hartnett */
|
||||
/* *\/ */
|
||||
/* int */
|
||||
/* nc4_file_change_ncid(int ncid, int new_ncid) */
|
||||
/* { */
|
||||
/* NC *nc; */
|
||||
/* int ret; */
|
||||
/**
|
||||
* @internal Change the ncid of an open file. This is needed for PIO
|
||||
* integration.
|
||||
*
|
||||
* @param ncid The ncid of the file (aka ext_ncid).
|
||||
* @param new_ncid The new ncid index to use (i.e. the first two bytes
|
||||
* of the ncid).
|
||||
*
|
||||
* @return ::NC_NOERR No error.
|
||||
* @return ::NC_EBADID No NC struct with this ext_ncid.
|
||||
* @return ::NC_ENOMEM Out of memory.
|
||||
* @author Ed Hartnett
|
||||
*/
|
||||
int
|
||||
nc4_file_change_ncid(int ncid, unsigned short new_ncid_index)
|
||||
{
|
||||
NC *nc;
|
||||
int ret;
|
||||
|
||||
/* /\* Find NC pointer for this file. *\/ */
|
||||
/* if ((ret = NC_check_id(ncid, &nc))) */
|
||||
/* return ret; */
|
||||
LOG((2, "%s: ncid %d new_ncid_index %d", __func__, ncid, new_ncid_index));
|
||||
|
||||
/* return NC_NOERR; */
|
||||
/* } */
|
||||
/* Find NC pointer for this file. */
|
||||
if ((ret = NC_check_id(ncid, &nc)))
|
||||
return ret;
|
||||
|
||||
/* Move it in the list. It will faile if list spot is already
|
||||
* occupied. */
|
||||
LOG((3, "moving nc->ext_ncid %d nc->ext_ncid >> ID_SHIFT %d",
|
||||
nc->ext_ncid, nc->ext_ncid >> ID_SHIFT));
|
||||
if (move_in_NCList(nc, new_ncid_index))
|
||||
return NC_EIO;
|
||||
LOG((3, "moved to new_ncid_index %d new nc->ext_ncid %d", new_ncid_index,
|
||||
nc->ext_ncid));
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Get info about a file on the list of libsrc4 open
|
||||
|
@ -265,36 +265,37 @@ main(int argc, char **argv)
|
||||
free_NC(ncp);
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
/* printf("Testing changing ncid..."); */
|
||||
/* { */
|
||||
/* NC *ncp, *ncp2; */
|
||||
/* int mode = 0; */
|
||||
/* NCmodel model; */
|
||||
/* int ret; */
|
||||
printf("Testing changing ncid...");
|
||||
{
|
||||
NC *ncp;
|
||||
NCmodel model;
|
||||
NC_GRP_INFO_T *grp;
|
||||
NC_FILE_INFO_T *h5;
|
||||
int old_ncid;
|
||||
|
||||
/* /\* Create the NC* instance and insert its dispatcher and model. *\/ */
|
||||
/* if ((ret = new_NC(NULL, FILE_NAME, mode, &model, &ncp))) ERR; */
|
||||
/* Create the NC, add it to nc_filelist array, add and init
|
||||
* NC_FILE_INFO_T. */
|
||||
if (new_NC(NC3_dispatch_table, FILE_NAME, 0, &model, &ncp)) ERR;
|
||||
add_to_NCList(ncp);
|
||||
if (nc4_file_list_add(ncp->ext_ncid, FILE_NAME, 0, NULL)) ERR;
|
||||
if (nc4_find_nc_grp_h5(ncp->ext_ncid, NULL, &grp, &h5)) ERR;
|
||||
|
||||
/* /\* Add to list of known open files and define ext_ncid. *\/ */
|
||||
/* add_to_NCList(ncp); */
|
||||
/* Change the ncid. */
|
||||
old_ncid = ncp->ext_ncid;
|
||||
if (nc4_file_change_ncid(ncp->ext_ncid, TEST_VAL_42)) ERR;
|
||||
|
||||
/* /\* Find it in the list. *\/ */
|
||||
/* if (!(ncp2 = find_in_NCList(ncp->ext_ncid))) ERR; */
|
||||
/* if (!(ncp2 = find_in_NCList_by_name(FILE_NAME))) ERR; */
|
||||
/* if ((ret = iterate_NCList(1, &ncp2))) ERR; */
|
||||
/* if (count_NCList() != 1) ERR; */
|
||||
/* Can't find old ncid. */
|
||||
if (nc4_find_nc_grp_h5(old_ncid, NULL, NULL, NULL) != NC_EBADID) ERR;
|
||||
|
||||
/* /\* Change the ncid. *\/ */
|
||||
/* if (nc4_file_change_ncid(ncp->ext_ncid, TEST_VAL_42)) ERR; */
|
||||
/* Delete it. */
|
||||
if (nc4_file_list_del(ncp->ext_ncid)) ERR;
|
||||
del_from_NCList(ncp); /* Will free empty list. */
|
||||
free_NC(ncp);
|
||||
|
||||
/* /\* Delete it. *\/ */
|
||||
/* del_from_NCList(ncp); /\* Will free empty list. *\/ */
|
||||
/* free_NC(ncp); */
|
||||
/* Ensure it is no longer in list. */
|
||||
/* if (find_in_NCList(ncp->ext_ncid)) ERR; */
|
||||
|
||||
/* /\* Ensure it is no longer in list. *\/ */
|
||||
/* /\* if (find_in_NCList(ncp->ext_ncid)) ERR; *\/ */
|
||||
|
||||
/* } */
|
||||
/* SUMMARIZE_ERR; */
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
||||
|
@ -77,6 +77,37 @@ main(int argc, char **argv)
|
||||
if (find_in_NCList(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("Testing moving in NC list (needed for PIO)...");
|
||||
{
|
||||
int ncid;
|
||||
NC *ncp, *ncp2;
|
||||
int mode = 0;
|
||||
NCmodel model;
|
||||
int ret;
|
||||
|
||||
/* Create the NC* instance and add it to list. */
|
||||
if ((ret = new_NC(NULL, FILE_NAME, mode, &model, &ncp))) ERR;
|
||||
add_to_NCList(ncp);
|
||||
|
||||
/* Find it in the list. */
|
||||
if (!(ncp2 = find_in_NCList(ncp->ext_ncid))) ERR;
|
||||
|
||||
/* Move it. */
|
||||
ncid = ncp->ext_ncid;
|
||||
if (move_in_NCList(ncp, TEST_VAL_42)) ERR;
|
||||
|
||||
/* Now we won't find old ncid in the list. */
|
||||
if (find_in_NCList(ncid)) ERR;
|
||||
|
||||
/* Delete it. */
|
||||
ncid = ncp->ext_ncid;
|
||||
del_from_NCList(ncp); /* Will free empty list. */
|
||||
free_NC(ncp);
|
||||
|
||||
/* Ensure it is no longer in list. */
|
||||
if (find_in_NCList(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
#ifdef LARGE_FILE_TESTS
|
||||
/* This test is slow, only run it on large file test builds. */
|
||||
printf("Testing maxing out NC list...");
|
||||
|
Loading…
Reference in New Issue
Block a user