Skip to content

Commit

Permalink
Add datRenam and datMove
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Sep 4, 2014
1 parent 44e80cc commit ab09f61
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ datGet1C.c \
datGetVC.c \
datLen.c \
datMap.c \
datMove.c \
datMsg.c \
datName.c \
datNcomp.c \
Expand All @@ -104,6 +105,7 @@ datPut.c \
datPut1C.c \
datPutVC.c \
datRef.c \
datRenam.c \
datShape.c \
datSize.c \
datStruc.c \
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ SG/4 says Primtive precision vs Storage precision
`datLen` is called but in some cases seemingly as an alias
for `datClen`.

### datRenam

Need to test whether `datRenam` or `datMove` break locators
that are previously associated with the objects being moved/renamed.
H5Lmove indicates that they should still work fine.

### Incompatibilies

HDF5 does not support an array of structures. Structures must be supported
Expand Down
133 changes: 133 additions & 0 deletions datMove.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
*+
* Name:
* datMove
* Purpose:
* Move an object
* Language:
* Starlink ANSI C
* Type of Module:
* Library routine
* Invocation:
* datMove( HDSLoc **locator1, const HDSLoc *locator2, const char *name_str,
* int *status );
* Arguments:
* locator1 = HDSLoc ** (Given and Returned)
* Object locator to move. Locator will be annulled and
* set to NULL after moving.
* locator2 = const HDSLoc * (Given)
* Structure to receive the item.
* name = const char * (Given)
* Name of component in new location.
* status = int* (Given and Returned)
* Pointer to global status.
* Description:
* Move and object to a new location (i.e. copy and erase the original).
* Authors:
* TIMJ: Tim Jenness (Cornell)
* {enter_new_authors_here}
* Notes:
* - If the object is an array, locator1 must point to the complete
* array, not a slice or cell. locator1 is annulled if the operation is
* successful (if it is the last primary locator associated with a
* container file, then the container file will be closed - see
* datPrmry but note that the HDF5 interface does not currently support
* primary vs secondary locators).
* - The operation will fail if a component of the same
* name already exists in the structure. The object to be moved
* need not be in the same container file as the structure.
* History:
* 2014-09-04 (TIMJ):
* Initial version
* {enter_further_changes_here}
* Copyright:
* Copyright (C) 2014 Cornell University
* All Rights Reserved.
* Licence:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* - Neither the name of the {organization} nor the names of its
* contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
* Bugs:
* {note_any_bugs_here}
*-
*/

#include "hdf5.h"
#include "hdf5_hl.h"

#include "ems.h"
#include "sae_par.h"

#include "hds1.h"
#include "dat1.h"
#include "hds.h"

#include "dat_err.h"

int
datMove( HDSLoc **locator1, const HDSLoc *locator2, const char *name_str,
int *status ) {

HDSLoc * parentloc = NULL;
char sourcename[DAT__SZNAM+1];
char cleanname[DAT__SZNAM+1];

if (*status != SAI__OK) return *status;

dau1CheckName( name_str, 1, cleanname, sizeof(cleanname), status );
if (*status != SAI__OK) return *status;

/* Have to give the source name as "." doesn't seem to be allowed.
so get the name and the parent locator */
datParen( *locator1, &parentloc, status );
datName( *locator1, sourcename, status );

CALLHDFQ(H5Lmove( parentloc->group_id, sourcename,
locator2->group_id, cleanname, H5P_DEFAULT, H5P_DEFAULT));

CLEANUP:
if (parentloc) datAnnul( &parentloc, status );
if (*status == SAI__OK) {
datAnnul(locator1, status );
}
return *status;
}
162 changes: 162 additions & 0 deletions datRenam.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
*+
* Name:
* datRenam
* Purpose:
* Rename object
* Language:
* Starlink ANSI C
* Type of Module:
* Library routine
* Invocation:
* datRenam( HDSLoc *locator, const char *name_str, int *status);
* Arguments:
* locator = HDSLoc * (Given and Returned)
* Object locator. Updated to reflect new name of object.
* name_str = const char * (Given)
* New object name.
* status = int* (Given and Returned)
* Pointer to global status.
* Description:
* Rename an object in the hierarchy.
* Authors:
* TIMJ: Tim Jenness (Cornell)
* {enter_new_authors_here}
* Notes:
* - This locator is updated by the routine to reflect the new location
* of the object in the hierarchy. This is a change in API compared to
* HDS.
* History:
* 2014-09-04 (TIMJ):
* Initial version
* {enter_further_changes_here}
* Copyright:
* Copyright (C) 2014 Cornell University
* All Rights Reserved.
* Licence:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* - Neither the name of the {organization} nor the names of its
* contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
* Bugs:
* {note_any_bugs_here}
*-
*/

#include "hdf5.h"
#include "hdf5_hl.h"

#include "ems.h"
#include "sae_par.h"

#include "hds1.h"
#include "dat1.h"
#include "hds.h"

#include "dat_err.h"

int
datRenam( HDSLoc *locator, const char *name_str, int *status) {

HDSLoc * clonedloc = NULL;
HDSLoc * parentloc = NULL;
HDSLoc * movedloc = NULL;
int there = 0;

if (*status != SAI__OK) return *status;

/* We need to get the locator of the parent as we need to be moving it
within the current group. */
datParen( locator, &parentloc, status );

/* It is an error to rename over something that already exists */
datThere( parentloc, name_str, &there, status );
if (there) {
*status = DAT__COMEX;
emsRepf("datRenam_1", "datRenam: Component '%s' already exists in this structure",
status, name_str );
goto CLEANUP;
}

/* To rename we are actually moving. HDF5 does not see any difference
between moving and renaming so we just call datMove. */

/* First we clone the input locator so that we do not free the caller's locator. */
datClone( locator, &clonedloc, status );

/* Move the item to the new location */
datMove( &clonedloc, parentloc, name_str, status );

/* but now we have to find the thing we just moved */
datFind( parentloc, name_str, &movedloc, status );

/* and we now do the fiddly bit where we have to
replace the bits in the callers locator */
#define COPYCOMP(item,closefunc) \
if (*status == SAI__OK) { \
if (movedloc->item > 0 && locator->item > 0) { \
CALLHDFQ(closefunc(locator->item)); \
locator->item = movedloc->item; \
movedloc->item = 0; /* Null it out */ \
} else if (movedloc->item <= 0 && locator->item > 0) { \
*status = DAT__OBJIN; \
emsRep("datRenam_2", "Original locator has " #item \
" but renamed locator does not (Possible programming error)", \
status ); \
} else if (movedloc->item > 0 && locator->item <= 0) { \
*status = DAT__OBJIN; \
emsRep("datRenam_2", "Renamed locator has " #item \
" but original locator does not (Possible programming error)", \
status ); \
} \
}

COPYCOMP( dataset_id, H5Dclose );
COPYCOMP( group_id, H5Gclose );
COPYCOMP( dataspace_id, H5Sclose );

CLEANUP:
if (clonedloc) datAnnul( &clonedloc, status );
if (parentloc) datAnnul( &parentloc, status );
if (movedloc) datAnnul( &movedloc, status );

return *status;
}
2 changes: 1 addition & 1 deletion hds.h
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ datRefct(const HDSLoc *locator,
/*=============================*/

int
datRenam(const HDSLoc *locator,
datRenam(HDSLoc *locator,
const char *name_str,
int *status);

Expand Down

0 comments on commit ab09f61

Please sign in to comment.