Skip to content
Snippets Groups Projects
Commit 46437f42 authored by Matthew Webster's avatar Matthew Webster
Browse files

Fixes to more closely match previous version

parent 7fb1a9e2
No related branches found
No related tags found
No related merge requests found
// fslcreatehd.cc - Copy certain parts of an AVW header // fslcreatehd.cc - Copy certain parts of an AVW header
// Mark Jenkinson, Steve Smith and Matthew Webster, FMRIB Image Analysis Group // Mark Jenkinson, Steve Smith and Matthew Webster, FMRIB Image Analysis Group
// Copyright (C) 2001-2005 University of Oxford // Copyright (C) 2001-2005 University of Oxford
// CCOPYRIGHT // CCOPYRIGHT
#include "newimage/newimageall.h" #include "newimage/newimageall.h"
#include <fstream> #include <fstream>
...@@ -9,12 +9,15 @@ ...@@ -9,12 +9,15 @@
using namespace NEWIMAGE; using namespace NEWIMAGE;
void print_usage(const string& progname) void print_usage(const string& progname)
{ {
cout << endl; cout << endl;
cout << "Usage: fslcreatehd <xsize> <ysize> <zsize> <tsize> <xvoxsize> <yvoxsize> <zvoxsize> <tr> <xorigin> <yorigin> <zorigin> <datatype> <headername>" << endl; cout << "Usage: fslcreatehd <xsize> <ysize> <zsize> <tsize> <xvoxsize> <yvoxsize> <zvoxsize> <tr> <xorigin> <yorigin> <zorigin> <datatype> <headername>" << endl;
cout << " fslcreatehd <nifti_xml_file> <headername>" << endl; cout << " fslcreatehd <nifti_xml_file> <headername>" << endl;
cout << " Datatype values: " << DT_UNSIGNED_CHAR << "=char, " << DT_SIGNED_SHORT << "=short, " << DT_SIGNED_INT <<"=int, " << DT_FLOAT << "=float, " << DT_DOUBLE<< "=double" << endl; cout << " Datatype values: " << DT_UNSIGNED_CHAR << "=char, " << DT_SIGNED_SHORT << "=short, " << DT_SIGNED_INT <<"=int, " << DT_FLOAT << "=float, " << DT_DOUBLE<< "=double" << endl;
cout << " In the first form, a radiological image will be created, the origin being given as voxel co-ordindates," << endl;
cout << " if the output file already exists, its data ( but not geometric information ) will be copied if it has" << endl;
cout << " a matching number of elements."
cout << " In the second form, an XML-ish form of nifti header is read (as output by fslhd -x)" << endl; cout << " In the second form, an XML-ish form of nifti header is read (as output by fslhd -x)" << endl;
cout << " Note that stdin is used if '-' is used in place of a filename" << endl; cout << " Note that stdin is used if '-' is used in place of a filename" << endl;
...@@ -30,10 +33,10 @@ int fslcreatehd_main(int argc, char *argv[]) ...@@ -30,10 +33,10 @@ int fslcreatehd_main(int argc, char *argv[])
string filename; string filename;
int fileread(1); int fileread(1);
bool existingImage(false); bool existingImage(false);
if (argc==3) /* use the XML form of header specification */ if (argc==3) /* use the XML form of header specification */
filename = string(argv[2]); filename = string(argv[2]);
else else
filename = string(argv[13]); filename = string(argv[13]);
/* check if file already exists and if so, read the image contents */ /* check if file already exists and if so, read the image contents */
...@@ -43,11 +46,11 @@ int fslcreatehd_main(int argc, char *argv[]) ...@@ -43,11 +46,11 @@ int fslcreatehd_main(int argc, char *argv[])
header=reader.loadImage(filename,buffer,extensions); header=reader.loadImage(filename,buffer,extensions);
originalHeader=header; originalHeader=header;
} }
if (argc>3) { if (argc>3) {
/* set uninteresting defaults */ /* set uninteresting defaults */
if (!existingImage) if (!existingImage)
header.datatype=atoi(argv[12]); header.datatype=atoi(argv[12]);
header.dim[0]=4; header.dim[0]=4;
for (int i=1;i<=4;i++) for (int i=1;i<=4;i++)
...@@ -57,40 +60,40 @@ int fslcreatehd_main(int argc, char *argv[]) ...@@ -57,40 +60,40 @@ int fslcreatehd_main(int argc, char *argv[])
if ( atoi(argv[9]) != 0 || atoi(argv[10]) != 0 || atoi(argv[11]) != 0 ) { if ( atoi(argv[9]) != 0 || atoi(argv[10]) != 0 || atoi(argv[11]) != 0 ) {
header.sX[3]=atoi(argv[9]); header.sX[0]=-header.pixdim[1];
header.sY[3]=atoi(argv[10]); header.sY[1]=header.pixdim[2];
header.sZ[3]=atoi(argv[11]); header.sZ[2]=header.pixdim[3];
header.sX[0]=atoi(argv[5]); header.sX[3]=-header.pixdim[1]*(header.dim[1]-1.0-atoi(argv[9]));
header.sY[1]=atoi(argv[6]); header.sY[3]=-header.pixdim[2]*atoi(argv[10]);
header.sZ[2]=atoi(argv[7]); header.sZ[3]=-header.pixdim[3]*atoi(argv[11]);
} }
} else { } else {
/* read XML form */ /* read XML form */
char *newstr, *oldfname, *oldiname; char *newstr, *oldfname, *oldiname;
ifstream inputfile; ifstream inputfile;
vector<string> settings; vector<string> settings;
if (strcmp(argv[1],"-")==0) {fileread=0;} if (strcmp(argv[1],"-")==0) {fileread=0;}
newstr = (char *)calloc(10000,1); newstr = (char *)calloc(10000,1);
oldfname = (char *)calloc(10000,1); oldfname = (char *)calloc(10000,1);
oldiname = (char *)calloc(10000,1); oldiname = (char *)calloc(10000,1);
if (fileread) if (fileread)
{ {
inputfile.open (argv[1], ifstream::in | ifstream::binary); inputfile.open (argv[1], ifstream::in | ifstream::binary);
if (!inputfile.is_open()) if (!inputfile.is_open())
{ {
cerr << "Cannot open file " << argv[1] << endl; cerr << "Cannot open file " << argv[1] << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
do do
{ {
if (fileread) if (fileread)
{ {
inputfile.getline(newstr,9999); // maybe use > for delimiting character remove while increase size inputfile.getline(newstr,9999); // maybe use > for delimiting character remove while increase size
} }
else else
{ {
if (fgets(newstr,9999,stdin)==NULL) break; if (fgets(newstr,9999,stdin)==NULL) break;
} }
...@@ -99,7 +102,7 @@ int fslcreatehd_main(int argc, char *argv[]) ...@@ -99,7 +102,7 @@ int fslcreatehd_main(int argc, char *argv[])
header=NiftiHeader(settings); header=NiftiHeader(settings);
if (fileread) if (fileread)
inputfile.close(); inputfile.close();
} }
...@@ -117,7 +120,7 @@ int fslcreatehd_main(int argc, char *argv[]) ...@@ -117,7 +120,7 @@ int fslcreatehd_main(int argc, char *argv[])
fill(buffer,buffer+header.nElements(),0); fill(buffer,buffer+header.nElements(),0);
} }
int filetype=FslGetEnvOutputType(); int filetype=FslGetEnvOutputType();
if(!existingImage) { if(!existingImage) {
filename=make_basename(filename)+outputExtension(filetype); filename=make_basename(filename)+outputExtension(filetype);
} }
...@@ -132,12 +135,10 @@ int fslcreatehd_main(int argc, char *argv[]) ...@@ -132,12 +135,10 @@ int fslcreatehd_main(int argc, char *argv[])
int main(int argc,char *argv[]) int main(int argc,char *argv[])
{ {
if (argc != 14 && argc != 3) if (argc != 14 && argc != 3)
{ {
print_usage(string(argv[0])); print_usage(string(argv[0]));
return 1; return 1;
} }
return fslcreatehd_main(argc,argv); return fslcreatehd_main(argc,argv);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment