From bb4110e97123dee670e92253365a44cd496ef8ed Mon Sep 17 00:00:00 2001
From: Mark Jenkinson <mark@fmrib.ox.ac.uk>
Date: Fri, 17 Sep 2004 19:02:28 +0000
Subject: [PATCH] Made it work properly

---
 avwcpgeom.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/avwcpgeom.c b/avwcpgeom.c
index bfb7723..7faff6f 100644
--- a/avwcpgeom.c
+++ b/avwcpgeom.c
@@ -37,11 +37,12 @@ int main(argc,argv)
   char thestring[10000];
 /*   struct dsr hdr, hdr2; */
   FSLIO *src = NULL, *dest = NULL;
-  short need_to_copy = 0, x, y, z, v, copydim=1;
+  short x, y, z, v, copydim=1, t;
   float vx, vy, vz, tr;
   char c;
   short orig[5];
   void *buffer = NULL;
+  char desthdrname[10000];
 
   if (argc<3)
     usage();
@@ -64,21 +65,21 @@ int main(argc,argv)
     exit(EXIT_FAILURE);
   }
 
-  if ( FslGetFileType(dest) == FSL_TYPE_NIFTI_GZ ) {
-    short t;
-
-    need_to_copy = 1;
-    /* Read all the destination volumes... */
-    FslGetDim(dest, &x, &y, &z, &v);
-    if( (buffer = malloc(x * y * z * v * (FslGetDataType(dest, &t) / 8))) == NULL ) {
-      perror("Unable to allocate memory for NIFTI_GZ copy");
-      exit(EXIT_FAILURE);
-    }
-    FslReadVolumes(dest, buffer, v);
+  /* Read all the destination volumes... */
+  FslGetDim(dest, &x, &y, &z, &v);
+  if( (buffer = malloc(x * y * z * v * (FslGetDataType(dest, &t) / 8))) == NULL ) {
+    perror("Unable to allocate memory for copy");
+    exit(EXIT_FAILURE);
   }
+  FslReadVolumes(dest, buffer, v);
+
+
+  strcpy(desthdrname,dest->niftiptr->fname);
   FslClose(dest);
   /* ...and now reopen destination for writing */
-  dest = FslOpen(argv[2], "w");
+  dest = FslOpen(desthdrname, "w");
+
+  FslCloneHeader(dest,src);
 
 /* }}} */
   /* {{{ copy geom */
@@ -117,10 +118,11 @@ int main(argc,argv)
 /*      swap_hdr(&hdr2); */
 
  FslWriteHeader(dest);
- if(need_to_copy)
-   FslWriteVolumes(dest, buffer, v);
+ FslWriteVolumes(dest, buffer, v);
  FslClose(dest);
 
+ FslClose(src);
+
 /*  avw_write_hdr_only(thestring,&hdr2);  */
 
 /* }}} */
-- 
GitLab