mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-21 03:13:42 +08:00
porting changes from other PR
This commit is contained in:
parent
ee941decca
commit
2cd228bcd4
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user