From 3d21fa580c34e599ab13d49eae54caf9522fb2c0 Mon Sep 17 00:00:00 2001
From: Matthew Webster <mwebster@fmrib.ox.ac.uk>
Date: Fri, 9 Jan 2015 15:54:22 +0000
Subject: [PATCH] Current Version Jan 15

---
 fslchfiletype.cc | 14 +++++++-----
 fslcomplex.cc    | 58 ++++++++++++++++++++++++------------------------
 fslselectvols.cc | 12 +++++-----
 3 files changed, 43 insertions(+), 41 deletions(-)

diff --git a/fslchfiletype.cc b/fslchfiletype.cc
index ec99898..f70b836 100644
--- a/fslchfiletype.cc
+++ b/fslchfiletype.cc
@@ -5,6 +5,7 @@
 
 #include "newimage/newimageall.h"
 #include "newimage/fmribmain.h"
+#include <cstdlib>
 
 using namespace NEWIMAGE;
 
@@ -20,9 +21,9 @@ int printUsage(const string& progname)
 template <class T>
 int fmrib_main(int argc, char *argv[])
 {
-  volume4D<T> input;
-  read_volume4D(input,string(argv[0]));
-  save_volume4D_dtype(input,string(argv[1]),dtype(string(argv[0])));
+  volume<T> input;
+  read_volume(input,string(argv[0]));
+  save_volume_dtype(input,string(argv[1]),dtype(string(argv[0])));
   return 0;
 }
 
@@ -44,13 +45,14 @@ int main(int argc,char *argv[])
   else if (string(argv[1])=="NIFTI_PAIR_GZ") outputType=FSL_TYPE_NIFTI_PAIR_GZ;
   else return printUsage(string(argv[0]));
 
-  FslSetOverrideOutputType(outputType);
+  //argv[1] has a valid outtype at this point
+  setenv("FSLOUTPUTTYPE",argv[1], true);
 
   if (dtype(inputFile)==DT_COMPLEX) 
   {
     volume4D<float> real, imaginary;
-    read_complexvolume4D(real, imaginary, inputFile);
-    save_complexvolume4D(real, imaginary, outputFile);
+    read_complexvolume(real, imaginary, inputFile);
+    save_complexvolume(real, imaginary, outputFile);
   }
   else  
   {
diff --git a/fslcomplex.cc b/fslcomplex.cc
index b832e3b..1731849 100644
--- a/fslcomplex.cc
+++ b/fslcomplex.cc
@@ -45,21 +45,21 @@ void fix_start_and_end(int& start, int& end, int mint, int maxt)
 void realpolar(const string& fin, const string& fabs, const string& fphase, 
 	       int start, int end) 
 {
-  volume4D<float> vreal, vimag;
-  read_complexvolume4D(vreal, vimag, fin);
+  volume<float> vreal, vimag;
+  read_complexvolume(vreal, vimag, fin);
   fix_start_and_end(start,end,vreal.mint(),vreal.maxt());
 
   if (fabs.size()>0) {
-    volume4D<float> vabs;
+    volume<float> vabs;
     for (int n=start; n<=end; n++) {
       vabs.addvolume(abs(vreal[n],vimag[n]));
     }
     vabs.copyproperties(vreal);
-    save_volume4D(vabs,fabs);
+    save_volume(vabs,fabs);
   }
 
   if (fphase.size()>0) {
-    volume4D<float> vphase;
+    volume<float> vphase;
     for (int n=start; n<=end; n++) {
       vphase.addvolume(phase(vreal[n],vimag[n]));
     }
@@ -71,26 +71,26 @@ void realpolar(const string& fin, const string& fabs, const string& fphase,
 void realcartesian(const string& fin, const string& freal, const string& fimag, 
 		   int start, int end)
 {
-  volume4D<float> vreal, vimag;
-  read_complexvolume4D(vreal, vimag, fin);
+  volume<float> vreal, vimag;
+  read_complexvolume(vreal, vimag, fin);
   fix_start_and_end(start,end,vreal.mint(),vreal.maxt());
 
   if (freal.size()>0) {
-    volume4D<float> vre;
+    volume<float> vre;
     for (int n=start; n<=end; n++) {
       vre.addvolume(vreal[n]);
     }
     vre.copyproperties(vreal);
-    save_volume4D(vre,freal);
+    save_volume(vre,freal);
   }
 
   if (fimag.size()>0) {
-    volume4D<float> vim;
+    volume<float> vim;
     for (int n=start; n<=end; n++) {
       vim.addvolume(vimag[n]);
     }
     vim.copyproperties(vimag);
-    save_volume4D(vim,fimag);
+    save_volume(vim,fimag);
   }
 }
 
@@ -98,21 +98,21 @@ void realcartesian(const string& fin, const string& freal, const string& fimag,
 void complexsave(const string& freal, const string& fimag, 
 		 const string& fcomplex, int start, int end)
 {
-  volume4D<float> vreal, vimag;
-  read_volume4D(vreal, freal);
-  read_volume4D(vimag, fimag);
+  volume<float> vreal, vimag;
+  read_volume(vreal, freal);
+  read_volume(vimag, fimag);
   fix_start_and_end(start,end,Max(vreal.mint(),vimag.mint()),
 		    Min(vreal.maxt(),vimag.maxt()));
 
   if (fcomplex.size()>0) {
-    volume4D<float> vre, vim;
+    volume<float> vre, vim;
     for (int n=start; n<=end; n++) {
       vre.addvolume(vreal[n]);
       vim.addvolume(vimag[n]);
     }
     vre.copyproperties(vreal);
     vim.copyproperties(vimag);
-    save_complexvolume4D(vre,vim,fcomplex);
+    save_complexvolume(vre,vim,fcomplex);
   }
 }
 
@@ -120,21 +120,21 @@ void complexsave(const string& freal, const string& fimag,
 void complexpolar(const string& fabsvol, const string& fphasevol, 
 		  const string& fcomplex, int start, int end)
 {
-  volume4D<float> vabs, vphase;
-  read_volume4D(vabs, fabsvol);
-  read_volume4D(vphase, fphasevol);
+  volume<float> vabs, vphase;
+  read_volume(vabs, fabsvol);
+  read_volume(vphase, fphasevol);
   fix_start_and_end(start,end,Max(vabs.mint(),vphase.mint()),
 		    Min(vabs.maxt(),vphase.maxt()));
 
   if (fcomplex.size()>0) {
-    volume4D<float> vre, vim;
+    volume<float> vre, vim;
     for (int n=start; n<=end; n++) {
       vre.addvolume(real(vabs[n],vphase[n]));
       vim.addvolume(imag(vabs[n],vphase[n]));
     }
     vre.copyproperties(vabs);
     vim.copyproperties(vphase);
-    save_complexvolume4D(vre,vim,fcomplex);
+    save_complexvolume(vre,vim,fcomplex);
   }
 }
 
@@ -142,7 +142,7 @@ void complexsplit(const string& fsource, const string& fdest,
 		  int start, int end)
 {
   volume4D<float> vreal, vimag;
-  read_complexvolume4D(vreal, vimag, fsource);
+  read_complexvolume(vreal, vimag, fsource);
   fix_start_and_end(start,end,Max(vreal.mint(),vimag.mint()),
 		    Min(vreal.maxt(),vimag.maxt()));
 
@@ -154,16 +154,16 @@ void complexsplit(const string& fsource, const string& fdest,
     }
     vre.copyproperties(vreal);
     vim.copyproperties(vimag);
-    save_complexvolume4D(vre,vim,fdest);
+    save_complexvolume(vre,vim,fdest);
   }
 }
 
 void complexmerge(const string& fsource1, const string& fsource2,
 		  const string& fdest)
 {
-  volume4D<float> vr1, vi1, vr2, vi2;
-  read_complexvolume4D(vr1, vi1, fsource1);
-  read_complexvolume4D(vr2, vi2, fsource2);
+  volume<float> vr1, vi1, vr2, vi2;
+  read_complexvolume(vr1, vi1, fsource1);
+  read_complexvolume(vr2, vi2, fsource2);
 
   if (!samesize(vr1,vi1)) {
     cerr << "Could not process image " << fsource1 << " correctly." << endl;
@@ -185,7 +185,7 @@ void complexmerge(const string& fsource1, const string& fsource2,
     }
     vdr.copyproperties(vr1);
     vdi.copyproperties(vr2);
-    save_complexvolume4D(vdr,vdi,fdest);
+    save_complexvolume(vdr,vdi,fdest);
   }
 }
 
@@ -193,8 +193,8 @@ void complexmerge(const string& fsource1, const string& fsource2,
 void copyonly(const string& fsource, const string& fdest)
 {
   volume4D<float> vreal, vimag;
-  read_complexvolume4D(vreal, vimag, fsource);
-  save_complexvolume4D(vreal, vimag, fdest);
+  read_complexvolume(vreal, vimag, fsource);
+  save_complexvolume(vreal, vimag, fdest);
 }
 
 
diff --git a/fslselectvols.cc b/fslselectvols.cc
index d77c5b2..6b1d723 100644
--- a/fslselectvols.cc
+++ b/fslselectvols.cc
@@ -133,16 +133,16 @@ int main(int argc,char *argv[]){
       bool meancalc=calc_mean.value(), varcalc=calc_var.value();
 
       if(!meancalc && !varcalc)
-	subdata.reinitialize(data[0].xsize(),data[0].ysize(),data[0].zsize(),list.Ncols());
+	subdata.reinitialize(data.xsize(),data.ysize(),data.zsize(),list.Ncols());
       else
-	subdata.reinitialize(data[0].xsize(),data[0].ysize(),data[0].zsize(),1);
+	subdata.reinitialize(data.xsize(),data.ysize(),data.zsize(),1);
       subdata=0;
-      copybasicproperties(data[0],subdata[0]);
+      copybasicproperties(data,subdata);
       
       float v,v2;
-      for(int z=0;z<data[0].zsize();z++){
-	for(int y=0;y<data[0].ysize();y++){
-	  for(int x=0;x<data[0].xsize();x++){
+      for(int z=0;z<data.zsize();z++){
+	for(int y=0;y<data.ysize();y++){
+	  for(int x=0;x<data.xsize();x++){
 	    v=0;v2=0;
 	    for(int i=1;i<=list.Ncols();i++){	  
 	      v += data[list(1,i)](x,y,z);
-- 
GitLab