aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/crystal.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-06-26 17:10:29 +0200
committerThomas White <taw@physics.org>2020-07-29 18:53:44 +0200
commit21acbb9efcbc5158f62e43d025db1ca7b2369fb8 (patch)
tree0c2d06975ff0b55b66fdf776fc02a6ef1970193f /libcrystfel/src/crystal.c
parent9509c5e2ae310e80d880104bfb57fc887878ccbc (diff)
Add crystal_copy_deep()
Diffstat (limited to 'libcrystfel/src/crystal.c')
-rw-r--r--libcrystfel/src/crystal.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/libcrystfel/src/crystal.c b/libcrystfel/src/crystal.c
index 9202c668..bec3a890 100644
--- a/libcrystfel/src/crystal.c
+++ b/libcrystfel/src/crystal.c
@@ -7,7 +7,7 @@
* a research centre of the Helmholtz Association.
*
* Authors:
- * 2013-2016 Thomas White <taw@physics.org>
+ * 2013-2020 Thomas White <taw@physics.org>
* 2016 Valerio Mariani
*
* This file is part of CrystFEL.
@@ -33,6 +33,7 @@
#include "crystal.h"
#include "utils.h"
+#include "reflist-utils.h"
/**
@@ -127,6 +128,44 @@ Crystal *crystal_copy(const Crystal *cryst)
/**
+ * \param cryst: A \ref Crystal to copy.
+ *
+ * Creates a new \ref Crystal which is a copy of \p cryst. The copy is a "deep
+ * copy", which means that copies ARE made of the data structures which
+ * \p cryst contains references to, for example its \ref RefList.
+ *
+ * \returns A (deep) copy of \p cryst, or NULL on failure.
+ *
+ */
+Crystal *crystal_copy_deep(const Crystal *cryst)
+{
+ Crystal *c;
+
+ c = crystal_new();
+ if ( c == NULL ) return NULL;
+
+ memcpy(c, cryst, sizeof(Crystal));
+ if ( c->notes != NULL ) c->notes = strdup(c->notes);
+
+ if ( cryst->cell != NULL ) {
+ UnitCell *cell;
+ cell = cell_new_from_cell(cryst->cell);
+ if ( cell == NULL ) return NULL;
+ c->cell = cell;
+ }
+
+ if ( cryst->reflections != NULL ) {
+ RefList *refls;
+ refls = copy_reflist(cryst->reflections);
+ if ( refls == NULL ) return NULL;
+ c->reflections = refls;
+ }
+
+ return c;
+}
+
+
+/**
* \param cryst: A \ref Crystal to free.
*
* Frees a \ref Crystal, and all internal resources concerning that crystal.