From 4a56e62c3f830789ecfacdb9381a7282960ce3d4 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Wed, 29 Oct 2014 15:07:36 -0700 Subject: [PATCH] hds: Implement datCcopy between v5 and v4 and vice versa --- libraries/hds/Makefile.am | 3 +- libraries/hds/dat1.h | 8 +++ libraries/hds/datCcopy4to5.c | 18 ++++++ libraries/hds/datCcopy5to4.c | 18 ++++++ libraries/hds/datCcopyXtoY.c | 120 +++++++++++++++++++++++++++++++++++ 5 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 libraries/hds/datCcopy4to5.c create mode 100644 libraries/hds/datCcopy5to4.c create mode 100644 libraries/hds/datCcopyXtoY.c diff --git a/libraries/hds/Makefile.am b/libraries/hds/Makefile.am index 32d5984c87d..f27f69612ba 100644 --- a/libraries/hds/Makefile.am +++ b/libraries/hds/Makefile.am @@ -80,7 +80,8 @@ BLOCK_DATA_FILES = cmp_blk.f C_ROUTINES = \ datExportFloc.c datImportFloc.c dat1_import_floc.c hdsdim.c \ - hds_select.c datCopy5to4.c datCopy4to5.c + hds_select.c datCopy5to4.c datCopy4to5.c \ + datCcopy5to4.c datCcopy4to5.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 42efbd3c94d..9c094ce74b0 100644 --- a/libraries/hds/dat1.h +++ b/libraries/hds/dat1.h @@ -72,5 +72,13 @@ datCopy5to4(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name_c, int datCopy4to5(const HDSLoc *locatorX, const HDSLoc *locatorY, const char *name_c, int *status); +int +datCcopy4to5(const HDSLoc *locator1X, const HDSLoc *locator2Y, const char *name, + HDSLoc **locator3Y, int *status ); + +int +datCcopy5to4(const HDSLoc *locator1X, const HDSLoc *locator2Y, const char *name, + HDSLoc **locator3Y, int *status ); + #endif diff --git a/libraries/hds/datCcopy4to5.c b/libraries/hds/datCcopy4to5.c new file mode 100644 index 00000000000..88991f31565 --- /dev/null +++ b/libraries/hds/datCcopy4to5.c @@ -0,0 +1,18 @@ + +/* 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 new file mode 100644 index 00000000000..79a16bde3ef --- /dev/null +++ b/libraries/hds/datCcopy5to4.c @@ -0,0 +1,18 @@ + +/* 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/datCcopyXtoY.c b/libraries/hds/datCcopyXtoY.c new file mode 100644 index 00000000000..0635d47199e --- /dev/null +++ b/libraries/hds/datCcopyXtoY.c @@ -0,0 +1,120 @@ +/* +*+ +* Name: +* datCcopyXtoY + +* Purpose: +* Copy one structure level from version X locator to version Y locator + +* Language: +* Starlink ANSI C + +* Type of Module: +* Library routine + +* Invocation: +* datCcopyXtoY(const HDSLoc *locator1X, const HDSLoc *locator2Y, const char *name, + HDSLoc **locator3Y, 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. +* locator3Y = HDSLoc ** (Returned) +* Locator of newly copied component. Will be in version Y. +* status = int* (Given and Returned) +* Pointer to global status. + +* Description: +* Copy an object into a structure and give the new component the +* specified name. If the source object is a structure, a new structure +* of the same type and shape is created but the content of the +* original structure is not copied. + +* Authors: +* TIMJ: Tim Jenness (Cornell) +* {enter_new_authors_here} + +* Notes: +* - 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 +* calling datCcopy between locators of the same data type. + +* History: +* 2014-10-29 (TIMJ): +* Initial version. Logic copied from HDSv4 datccopy.c +* {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 "sae_par.h" +#include "dat1.h" +#include "star/hds_v4.h" +#include "star/hds_v5.h" + +int +datCcopyXtoY(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 ); + + return *status; +}