From 31790f2f9f1f09f7ab2e71f4ab60e6b81ec93305 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Fri, 31 Oct 2014 13:32:36 -0700 Subject: [PATCH] hds: Refactor datCopy and datCcopy code + Realise that all the _v4 _v5 macro shenanigans are not needed as hds_select.c will do the right thing anyhow. + Break datCopyXtoY.c into separate files to allow other routines to call them. + datCcopy-like routine now used for first level of copying. This simplifies the code quite a lot. --- libraries/hds/Makefile.am | 5 +- libraries/hds/dat1.h | 17 +- libraries/hds/dat1CcopyLocXtoY.c | 133 ++++++++++ .../hds/{datCcopyXtoY.c => dat1CcopyXtoY.c} | 48 +--- libraries/hds/dat1CopyPrimXtoY.c | 150 +++++++++++ libraries/hds/dat1CopyStrucXtoY.c | 140 ++++++++++ libraries/hds/dat1CopyXtoY.c | 94 +++++++ libraries/hds/datCcopy4to5.c | 18 -- libraries/hds/datCcopy5to4.c | 18 -- libraries/hds/datCopy4to5.c | 31 --- libraries/hds/datCopy5to4.c | 31 --- libraries/hds/datCopyXtoY.c | 243 ------------------ libraries/hds/hds_select.c | 40 ++- libraries/hds/helper/mkhdswrapper.py | 26 +- 14 files changed, 593 insertions(+), 401 deletions(-) create mode 100644 libraries/hds/dat1CcopyLocXtoY.c rename libraries/hds/{datCcopyXtoY.c => dat1CcopyXtoY.c} (64%) create mode 100644 libraries/hds/dat1CopyPrimXtoY.c create mode 100644 libraries/hds/dat1CopyStrucXtoY.c create mode 100644 libraries/hds/dat1CopyXtoY.c delete mode 100644 libraries/hds/datCcopy4to5.c delete mode 100644 libraries/hds/datCcopy5to4.c delete mode 100644 libraries/hds/datCopy4to5.c delete mode 100644 libraries/hds/datCopy5to4.c delete mode 100644 libraries/hds/datCopyXtoY.c diff --git a/libraries/hds/Makefile.am b/libraries/hds/Makefile.am index 75daee616c6..095ca4be74a 100644 --- a/libraries/hds/Makefile.am +++ b/libraries/hds/Makefile.am @@ -79,9 +79,10 @@ F_C_ROUTINES = hds_run.c fortran_interface.c hdsFind.c BLOCK_DATA_FILES = cmp_blk.f C_ROUTINES = \ + dat1CcopyLocXtoY.c dat1CcopyXtoY.c \ + dat1CopyPrimXtoY.c dat1CopyStrucXtoY.c dat1CopyXtoY.c \ datExportFloc.c datImportFloc.c dat1_import_floc.c hdsdim.c \ - hds_select.c datCopy5to4.c datCopy4to5.c \ - datCcopy5to4.c datCcopy4to5.c + hds_select.c DAT_PAR: dat_par_f$(EXEEXT) ./dat_par_f > DAT_PAR diff --git a/libraries/hds/dat1.h b/libraries/hds/dat1.h index 9c094ce74b0..4e42a934da9 100644 --- a/libraries/hds/dat1.h +++ b/libraries/hds/dat1.h @@ -62,23 +62,28 @@ /* compiler to be able to know how to read the version. */ #define HDS_USE_INTERNAL_STRUCT 1 typedef struct LOC { int hds_version; } HDSLoc; +#include "hds_types.h" HDSLoc * dat1_import_floc ( const char flocator[DAT__SZLOC], int loc_length, int * status); int -datCopy5to4(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name_c, int *status); +dat1CopyXtoY(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name_c, int *status); int -datCopy4to5(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name_c, int *status); +dat1CcopyXtoY(const HDSLoc *locator1X, const HDSLoc *locator2Y, const char *name, + HDSLoc **locator3Y, int *status ); + +HDSLoc * +dat1CcopyLocXtoY(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name, + hdsbool_t * struc, int *status ); int -datCcopy4to5(const HDSLoc *locator1X, const HDSLoc *locator2Y, const char *name, - HDSLoc **locator3Y, int *status ); +dat1CopyPrimXtoY( const HDSLoc *locatorX, HDSLoc *locatorY, int *status ); int -datCcopy5to4(const HDSLoc *locator1X, const HDSLoc *locator2Y, const char *name, - HDSLoc **locator3Y, int *status ); +dat1CopyStrucXtoY( const HDSLoc *locatorX, const HDSLoc *locatorY, + int *status ); #endif diff --git a/libraries/hds/dat1CcopyLocXtoY.c b/libraries/hds/dat1CcopyLocXtoY.c new file mode 100644 index 00000000000..0307f55832e --- /dev/null +++ b/libraries/hds/dat1CcopyLocXtoY.c @@ -0,0 +1,133 @@ +/* +*+ +* Name: +* dat1CcopyLocXtoY + +* Purpose: +* Variant of datCcopy that returns the locator + +* Language: +* Starlink ANSI C + +* Type of Module: +* Library routine + +* Invocation: +* loc = dat1CcopyLocXtoY(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name, +* hdsbool_t * struc, int *status ) {( int * status ); + +* Arguments: +* locator1X = const HDSLoc * (Given) +* Object locator to copy. In version X. +* locator2Y = const HDSLoc * (Given) +* Locator of structure to receive copy of object. Structure is in +* a version Y file. +* name = const char * (Given) +* Name of object when copied into structure. +* struc = hdsbool_t * (Returned) +* True if a structure was created, false if a primitive was created. +* status = int* (Given and Returned) +* Pointer to global status. + +* Description: +* Identical to dat1CcopyXtoY except that the interface is changed such that a locator +* is returned directly and a boolean argument is set to indicate whether a structure +* or primitive was created. + +* Returned Value: +* loc = HDSLoc * +* Locator to the object that was created. + +* Authors: +* TIMJ: Tim Jenness (Cornell) +* {enter_new_authors_here} + +* Notes: +* - Will work even if the two locators are from different versions. + +* History: +* 2014-10-31 (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 "ems.h" +#include "sae_par.h" + +#include "dat1.h" +#include "hds.h" + +HDSLoc * +dat1CcopyLocXtoY(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name, + hdsbool_t * struc, int *status ) { + char type_str[DAT__SZTYP+1]; + hdsdim hdims[DAT__MXDIM]; + int ndims; + HDSLoc *outloc = NULL; + hdsbool_t isstruct = 0; + + if (*status != SAI__OK) return NULL; + + /* Always create the output and get a locator to it*/ + datType( locatorX, type_str, status ); + datShape( locatorX, DAT__MXDIM, hdims, &ndims, status ); + datNew( locatorY, name, type_str, ndims, hdims, status ); + datFind( locatorY, name, &outloc, status ); + + /* What happens next depends on whether we have a structure + as we only do more if we have a primitive that is defined. */ + datStruc( locatorX, &isstruct, status ); + + if (!isstruct) { + hdsbool_t state = 0; + /* We only copy if the primitive object is defined */ + datState( locatorX, &state, status ); + if ( state ) dat1CopyPrimXtoY( locatorX, outloc, status ); + } + + if (*status != SAI__OK) { + if (outloc) datAnnul(&outloc, status); + } + if (struc) *struc = isstruct; + return outloc; +} diff --git a/libraries/hds/datCcopyXtoY.c b/libraries/hds/dat1CcopyXtoY.c similarity index 64% rename from libraries/hds/datCcopyXtoY.c rename to libraries/hds/dat1CcopyXtoY.c index 0635d47199e..821e1bb6baf 100644 --- a/libraries/hds/datCcopyXtoY.c +++ b/libraries/hds/dat1CcopyXtoY.c @@ -1,7 +1,7 @@ /* *+ * Name: -* datCcopyXtoY +* dat1CcopyXtoY * Purpose: * Copy one structure level from version X locator to version Y locator @@ -13,8 +13,8 @@ * Library routine * Invocation: -* datCcopyXtoY(const HDSLoc *locator1X, const HDSLoc *locator2Y, const char *name, - HDSLoc **locator3Y, int *status ); +* dat1CcopyXtoY(const HDSLoc *locator1X, const HDSLoc *locator2Y, const char *name, +* HDSLoc **locator3Y, int *status ); * Arguments: * locator1X = const HDSLoc * (Given) @@ -40,6 +40,8 @@ * {enter_new_authors_here} * Notes: +* - Use datCcopy directly when the source and target locator +* are from the same version. * - When copying primitive types the data will be mapped and * copied from one location to another. * - In general this routine will be no less efficient than @@ -75,46 +77,12 @@ #include "sae_par.h" #include "dat1.h" -#include "star/hds_v4.h" -#include "star/hds_v5.h" +#include "hds.h" int -datCcopyXtoY(const HDSLoc *locator1X, const HDSLoc *locator2Y, const char *name, +dat1CcopyXtoY(const HDSLoc *locator1X, const HDSLoc *locator2Y, const char *name, HDSLoc **locator3Y, int *status ) { - char type_str[DAT__SZTYP+1]; - hdsdim hdims[DAT__MXDIM]; - int ndims; - hdsbool_t struc = 0; - if (*status != SAI__OK) return *status; - - datStruc_vX( locator1X, &struc, status ); - - if (struc) { - - /* need the type and dimensionality of the structure to create - in new location */ - datType_vX( locator1X, type_str, status ); - datShape_vX( locator1X, DAT__MXDIM, hdims, &ndims, status ); - datNew_vY( locator2Y, name, type_str, ndims, hdims, status ); - - } else { - hdsbool_t state = 0; - /* We only copy if the primitive object is defined */ - datState_vX( locator1X, &state, status ); - if ( state ) { - datCopyXtoY( locator1X, locator2Y, name, status ); - } else { - /* Undefined so just make something of the right shape and type */ - datType_vX( locator1X, type_str, status ); - datShape_vX( locator1X, DAT__MXDIM, hdims, &ndims, status ); - datNew_vY( locator2Y, name, type_str, ndims, hdims, status ); - } - - } - - /* and get a locator to the copied entity */ - datFind_vY( locator2Y, name, locator3Y, status ); - + *locator3Y = dat1CcopyLocXtoY( locator1X, locator2Y, name, NULL, status ); return *status; } diff --git a/libraries/hds/dat1CopyPrimXtoY.c b/libraries/hds/dat1CopyPrimXtoY.c new file mode 100644 index 00000000000..ebf1f46e8f7 --- /dev/null +++ b/libraries/hds/dat1CopyPrimXtoY.c @@ -0,0 +1,150 @@ +/* +*+ +* Name: +* dat1CopyPrimXtoY + +* Purpose: +* Copy the contents of one primitive locator to another + +* Language: +* Starlink ANSI C + +* Type of Module: +* Library routine + +* Invocation: +* dat1CopyPrimXtoY( const HDSLoc *locatorX, HDSLoc *locatorY, int *status ); + +* Arguments: +* locatorX = const HDSLoc * (Given) +* Locator to primitive object. +* locatorY = HDSLoc * (Given) +* Locator to a primitive object to receive the data. Should be same type +* and dimensionality as locatorX. +* status = int* (Given and Returned) +* Pointer to global status. + +* Description: +* Given a locator to a primitive object and the locator to a target primitive +* object, copies data from one to the other. The locators must refer to objects +* of the same type and dimensionality. + +* Authors: +* TIMJ: Tim Jenness (Cornell) +* {enter_new_authors_here} + +* Notes: +* - Do not use if the input and output locators are of the same HDS version. +* It will be much more efficient to use datCopy. + + +* History: +* 2014-10-31 (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 + +#include "ems.h" +#include "sae_par.h" + +#include "dat1.h" +#include "hds.h" +#include "dat_err.h" + +int +dat1CopyPrimXtoY( const HDSLoc *locatorX, HDSLoc *locatorY, int *status ) { + void *indata = NULL; + void *outdata = NULL; + size_t nbX = 0; + size_t nbY = 0; + size_t nelemX; + size_t nelemY; + HDSLoc * clonedloc = NULL; + char type_str[DAT__SZTYP+1]; + + if (*status != SAI__OK) return *status; + + /* Need to get the data type (should be same in both by definition) */ + datType( locatorX, type_str, status ); + + /* We need to clone the input locator so that we can write to + the struct (it is const) */ + datClone( locatorX, &clonedloc, status ); + + /* Map the data arrays as vectors */ + datMapV( clonedloc, type_str, "READ", &indata, &nelemX, status ); + datMapV( locatorY, type_str, "WRITE", &outdata, &nelemY, status ); + + if (*status == SAI__OK) { + if (nelemX != nelemY) { + *status = DAT__WEIRD; + emsRepf("datCopyXtoY_prim1","datCopy: Primitive element counts differ between source and target.", + status); + } + } + + /* Sanity check the bytes used for each representation */ + datLen( locatorX, &nbX, status ); + datLen( locatorY, &nbY, status ); + + if (*status == SAI__OK) { + if (nbX != nbY) { + *status = DAT__FATAL; + emsRepf("datCopyXtoY_prim", "datCopy: Number of bytes per element in source (%zu) != target (%zu)", + status, nbX, nbY ); + } + } + + if (*status == SAI__OK) { + size_t nbytes; + nbytes = nelemX * nbX; + memcpy( outdata, indata, nbytes ); + } + + datUnmap( clonedloc, status ); + datUnmap( locatorY, status ); + datAnnul( &clonedloc, status ); + return *status; +} diff --git a/libraries/hds/dat1CopyStrucXtoY.c b/libraries/hds/dat1CopyStrucXtoY.c new file mode 100644 index 00000000000..c9f914d98ac --- /dev/null +++ b/libraries/hds/dat1CopyStrucXtoY.c @@ -0,0 +1,140 @@ +/* +*+ +* Name: +* dat1CopyStrucXtoY + +* Purpose: +* Copy the contents of one structure to another empty structure + +* Language: +* Starlink ANSI C + +* Type of Module: +* Library routine + +* Invocation: +* dat1CopyStrucXtoY( const HDSLoc *locatorX, const HDSLoc *locatorY, int *status ); + +* Arguments: +* locatorX = const HDSLoc * (Given) +* Structure to be copied. Contents are copied recursively. +* locatorY = const HDSLoc * (Given) +* Locator to structure to receive content. This must have the +* same dimensionality of locatorX and is assumed to be empty. +* status = int* (Given and Returned) +* Pointer to global status. + +* Description: +* Recursively copy all the contents of one structure to another +* structure. The target structure should be empty and have the +* same type and dimensionality as the source structure. The structure +* is not copied below the target structure (as happens with datCopy). + +* Authors: +* TIMJ: Tim Jenness (Cornell) +* {enter_new_authors_here} + +* Notes: +* - Do not use if the input and output locators are of the same HDS version. +* It will be much more efficient to use datCopy. + +* History: +* 2014-10-31 (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 "ems.h" +#include "sae_par.h" + +#include "dat1.h" +#include "hds.h" + +int +dat1CopyStrucXtoY( const HDSLoc *locatorX, const HDSLoc *locatorY, int *status ) { + HDSLoc * veclocY = NULL; + HDSLoc * veclocX = NULL; + size_t nelem = 0; + int ncomp = 0; + int i; + hdsdim cell; + + if (*status != SAI__OK) return *status; + + /* X is the source structure and Y is the receiving empty structure. + Vectorize both to simplify the copy if they are arrays. */ + + datVec( locatorX, &veclocX, status ); + datVec( locatorY, &veclocY, status ); + + datSize(locatorY, &nelem, status); + + /* Loop over all the elements in the vectorized structure */ + for (cell=1; cell<=nelem; cell++) { + HDSLoc * cellLocX = NULL; + HDSLoc * cellLocY = NULL; + hdsdim cellpos[1]; + + cellpos[0] = cell; + datCell( veclocX, 1, cellpos, &cellLocX, status ); + datCell( veclocY, 1, cellpos, &cellLocY, status ); + + /* Now traverse all the components in this cell of X, copying to Y */ + datNcomp( cellLocX, &ncomp, status ); + + for (i=1; i<=ncomp; i++) { + HDSLoc * templocX = NULL; + char thisname[DAT__SZNAM+1]; + datIndex( cellLocX, i, &templocX, status ); + datName( templocX, thisname, status ); + dat1CopyXtoY( templocX, cellLocY, thisname, status ); + datAnnul( &templocX, status ); + } + datAnnul( &cellLocX, status ); + datAnnul( &cellLocY, status ); + } + + datAnnul( &veclocX, status ); + datAnnul( &veclocY, status ); + return *status; +} diff --git a/libraries/hds/dat1CopyXtoY.c b/libraries/hds/dat1CopyXtoY.c new file mode 100644 index 00000000000..24b6f4b3c47 --- /dev/null +++ b/libraries/hds/dat1CopyXtoY.c @@ -0,0 +1,94 @@ +/* +*+ +* Name: +* dat1CopyXtoY + +* Purpose: +* Copy structures and data from version X locator to version Y locator + +* Language: +* Starlink ANSI C + +* Type of Module: +* Library routine + +* Invocation: +* dat1CopyXtoY(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name_c, int *status); + +* Arguments: +* locatorX = const HDSLoc * (Given) +* Locator of object to copy. In version X. +* locatorY = const HDSLoc * (Given) +* Locator of structure to receive the copy. +* Structure is in a version Y file. +* name = const char * (Given) +* Name of newly copied object. +* status = int* (Given and Returned) +* Pointer to global status. + +* Description: +* Recursively copy an object from a version X locator to a version +* Y structure locator. The complete object is copied one item at +* a time. This is far less efficient than using the native HDSv4 +* or HDSv5 datCopy implementations and should only be used when +* the two input locators are associated with different HDS versions. + +* Authors: +* TIMJ: Tim Jenness (Cornell) +* {enter_new_authors_here} + +* Notes: +* - This is not an efficient copy. The components are traversed +* one at a time and created in the target. Primitives will be mapped +* and copied one primitive at a time. + +* History: +* 2014-10-28 (TIMJ): +* Initial version +* {enter_further_changes_here} + +* Copyright: +* Copyright (C) 2014 Cornell University +* All Rights Reserved. + +* Licence: +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 3 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be +* useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +* PURPOSE. See the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . + +* Bugs: +* {note_any_bugs_here} +*- +*/ + +#include "dat1.h" +#include "sae_par.h" +#include "hds.h" +#include "dat_err.h" +#include "hds_types.h" +#include "ems.h" + +int +dat1CopyXtoY(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name_c, int *status) { + hdsbool_t isstruc; + HDSLoc * outloc = NULL; + if (*status != SAI__OK) return *status; + + /* First simply create the next level down */ + outloc = dat1CcopyLocXtoY( locatorX, locatorY, name_c, &isstruc, status ); + + /* Primitives will have been copied already, just need to copy structures */ + if (isstruc) dat1CopyStrucXtoY( locatorX, outloc, status ); + if (outloc) datAnnul(&outloc, status); + return *status; +} + diff --git a/libraries/hds/datCcopy4to5.c b/libraries/hds/datCcopy4to5.c deleted file mode 100644 index 88991f31565..00000000000 --- a/libraries/hds/datCcopy4to5.c +++ /dev/null @@ -1,18 +0,0 @@ - -/* Copy version 4 objects to a version 5 file */ - -/* We define X to be 4 and Y to be 5 - where X is the source and Y is the target */ - -#define datCopyXtoY datCopy4to5 -#define datCcopyXtoY datCcopy4to5 - -#define datStruc_vX datStruc_v4 -#define datShape_vX datShape_v4 -#define datType_vX datType_v4 -#define datState_vX datState_v4 - -#define datNew_vY datNew_v5 -#define datFind_vY datFind_v5 - -#include "datCcopyXtoY.c" diff --git a/libraries/hds/datCcopy5to4.c b/libraries/hds/datCcopy5to4.c deleted file mode 100644 index 79a16bde3ef..00000000000 --- a/libraries/hds/datCcopy5to4.c +++ /dev/null @@ -1,18 +0,0 @@ - -/* Copy version 5 objects to a version 4 file */ - -/* We define X to be 5 and Y to be 4 - where X is the source and Y is the target */ - -#define datCopyXtoY datCopy5to4 -#define datCcopyXtoY datCcopy5to4 - -#define datStruc_vX datStruc_v5 -#define datShape_vX datShape_v5 -#define datType_vX datType_v5 -#define datState_vX datState_v5 - -#define datNew_vY datNew_v4 -#define datFind_vY datFind_v4 - -#include "datCcopyXtoY.c" diff --git a/libraries/hds/datCopy4to5.c b/libraries/hds/datCopy4to5.c deleted file mode 100644 index 06d443c10ea..00000000000 --- a/libraries/hds/datCopy4to5.c +++ /dev/null @@ -1,31 +0,0 @@ - -/* Copy version 4 objects to a version 5 file */ - -/* We define X to be 4 and Y to be 5 - where X is the source and Y is the target */ - -#define datCopyXtoY datCopy4to5 - -#define datStruc_vX datStruc_v4 -#define datShape_vX datShape_v4 -#define datType_vX datType_v4 -#define datMap_vX datMap_v4 -#define datUnmap_vX datUnmap_v4 -#define datLen_vX datLen_v4 -#define datIndex_vX datIndex_v4 -#define datAnnul_vX datAnnul_v4 -#define datVec_vX datVec_v4 -#define datCell_vX datCell_v4 -#define datName_vX datName_v4 -#define datNcomp_vX datNcomp_v4 - -#define datNew_vY datNew_v5 -#define datFind_vY datFind_v5 -#define datMap_vY datMap_v5 -#define datUnmap_vY datUnmap_v5 -#define datLen_vY datLen_v5 -#define datAnnul_vY datAnnul_v5 -#define datVec_vY datVec_v5 -#define datCell_vY datCell_v5 - -#include "datCopyXtoY.c" diff --git a/libraries/hds/datCopy5to4.c b/libraries/hds/datCopy5to4.c deleted file mode 100644 index 232db758b51..00000000000 --- a/libraries/hds/datCopy5to4.c +++ /dev/null @@ -1,31 +0,0 @@ - -/* Copy version 5 objects to a version 4 file */ - -/* We define X to be 5 and Y to be 4 - where X is the source and Y is the target */ - -#define datCopyXtoY datCopy5to4 - -#define datStruc_vX datStruc_v5 -#define datShape_vX datShape_v5 -#define datType_vX datType_v5 -#define datMap_vX datMap_v5 -#define datUnmap_vX datUnmap_v5 -#define datLen_vX datLen_v5 -#define datIndex_vX datIndex_v5 -#define datAnnul_vX datAnnul_v5 -#define datVec_vX datVec_v5 -#define datCell_vX datCell_v5 -#define datName_vX datName_v5 -#define datNcomp_vX datNcomp_v5 - -#define datNew_vY datNew_v4 -#define datFind_vY datFind_v4 -#define datMap_vY datMap_v4 -#define datUnmap_vY datUnmap_v4 -#define datLen_vY datLen_v4 -#define datAnnul_vY datAnnul_v4 -#define datVec_vY datVec_v4 -#define datCell_vY datCell_v4 - -#include "datCopyXtoY.c" diff --git a/libraries/hds/datCopyXtoY.c b/libraries/hds/datCopyXtoY.c deleted file mode 100644 index 5c6d5f7df99..00000000000 --- a/libraries/hds/datCopyXtoY.c +++ /dev/null @@ -1,243 +0,0 @@ -/* -*+ -* Name: -* datCopyXtoY - -* Purpose: -* Copy structures and data from version X locator to version Y locator - -* Language: -* Starlink ANSI C - -* Type of Module: -* Library routine - -* Invocation: -* datCopyXtoY(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name_c, int *status); - -* Arguments: -* locatorX = const HDSLoc * (Given) -* Locator of object to copy. In version X. -* locatorY = const HDSLoc * (Given) -* Locator of structure to receive the copy. -* Structure is in a version Y file. -* name = const char * (Given) -* Name of newly copied object. -* status = int* (Given and Returned) -* Pointer to global status. - -* Description: -* Recursively copy an object from a version X locator to a version -* Y structure locator. The complete object is copied. - -* Authors: -* TIMJ: Tim Jenness (Cornell) -* {enter_new_authors_here} - -* Notes: -* - This is not an efficient copy. The components are traversed -* one at a time, created in the target. Primitives will be mapped -* and copied one primitive at a time. - -* History: -* 2014-10-28 (TIMJ): -* Initial version -* {enter_further_changes_here} - -* Copyright: -* Copyright (C) 2014 Cornell University -* All Rights Reserved. - -* Licence: -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as -* published by the Free Software Foundation; either version 3 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be -* useful, but WITHOUT ANY WARRANTY; without even the implied -* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -* PURPOSE. See the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . - -* Bugs: -* {note_any_bugs_here} -*- -*/ - -#include - -#include "dat1.h" -#include "sae_par.h" -#include "star/hds_v4.h" -#include "star/hds_v5.h" -#include "dat_err.h" -#include "hds_types.h" -#include "ems.h" - -static int -dat1CopyPrimXtoY( const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name_c, int *status ); -static int -dat1CopyStrucXtoY( const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name_c, int *status ); -static HDSLoc * -dat1CreateComponentXinY( const HDSLoc * locatorX, const HDSLoc *locatorY, const char *name_c, char type_str[DAT__SZTYP+1], size_t *nelem, int *status ); - -int -datCopyXtoY(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name_c, int *status) { - hdsbool_t isstruc; - if (*status != SAI__OK) return *status; - - datStruc_vX( locatorX, &isstruc, status ); - - if (isstruc) { - - dat1CopyStrucXtoY( locatorX, locatorY, name_c, status ); - - } else { - dat1CopyPrimXtoY( locatorX, locatorY, name_c, status ); - } - - return *status; -} - -static HDSLoc * -dat1CreateComponentXinY( const HDSLoc * locatorX, const HDSLoc *locatorY, const char *name_c, char type_str[DAT__SZTYP+1], size_t *nelem, int *status ){ - HDSLoc * outlocY = NULL; - HDSLoc * veclocY = NULL; - hdsdim shapeX[DAT__MXDIM]; - int actdim; - int i; - - if (*status != SAI__OK) return NULL; - - /* Get the shape of X */ - datShape_vX( locatorX, DAT__MXDIM, shapeX, &actdim, status ); - - *nelem = 1; - for (i=0; i