diff options
Diffstat (limited to 'src/ioconvert.cc')
-rw-r--r-- | src/ioconvert.cc | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/src/ioconvert.cc b/src/ioconvert.cc index 0b1f823..96e5bb1 100644 --- a/src/ioconvert.cc +++ b/src/ioconvert.cc @@ -3,9 +3,11 @@ #include <string.h> #include "IO.hh" #include "IEEEIO.hh" + #ifdef WITH_HDF4 #include "HDFIO.hh" #endif + #ifdef WITH_HDF5 #include "H5IO.hh" #endif @@ -25,9 +27,10 @@ int main(int argc,char *argv[]){ int sindex=0,dindex=0,findex=0; IObase *infile,*outfile; #ifdef WITH_HDF4 - HDFIO *hdffile = NULL; - int hdfin=0; + HDFIO *hdffile; #endif + int hdfin=0; + int h5in=0; for(i=1;i<argc;i++){ if(*(argv[i])=='-') findex=i; else if(!sindex) sindex=i; @@ -41,53 +44,44 @@ int main(int argc,char *argv[]){ else swap=0; // for the input file -#if defined(WITH_HDF4) || defined(WITH_HDF5) char *s_ext=strrchr(argv[sindex],'.'); char *d_ext=strrchr(argv[dindex],'.'); -#endif + if(s_ext && (!strcmp(s_ext,".ieee") || !strcmp(s_ext,".raw"))){ + infile=new IEEEIO(argv[sindex],IObase::Read); + } #ifdef WITH_HDF4 - if(s_ext && !strcmp(s_ext,".hdf")) - { + else if(s_ext && !strcmp(s_ext,".hdf")){ infile=hdffile=new HDFIO(argv[sindex],IObase::Read); hdfin=1; } - else #endif #ifdef WITH_HDF5 - if(s_ext && !strcmp(s_ext,".h5")) - { - infile=new H5IO(argv[sindex],IObase::Read); + else if(s_ext && (!strcmp(s_ext,".h5") || !strcmp(s_ext,".hdf5"))){ + infile = new H5IO(argv[sindex],IObase::Read); + if(!infile->isValid()) fprintf(stderr,"**** not hdf5 input?\n"); + h5in=1; } - else #endif - { - // assume its raw - infile=new IEEEIO(argv[sindex],IObase::Read); - } if(!infile->isValid()){ printf("cant read %s\n",argv[sindex]); usage(); } - // for the outfile, + // for the outfile, + if(d_ext && (!strcmp(d_ext,".ieee") || !strcmp(d_ext,".raw"))){ + outfile=new IEEEIO(argv[dindex],IObase::Create,swap); // swap only affects IEEEIO output + } #ifdef WITH_HDF4 - if(d_ext && !strcmp(d_ext,".hdf")) - { + else if(d_ext && !strcmp(d_ext,".hdf")){ outfile=new HDFIO(argv[dindex],IObase::Create); } - else #endif #ifdef WITH_HDF5 - if(d_ext && !strcmp(d_ext,".h5")) - { - outfile=new H5IO(argv[dindex],IObase::Create); + else if(d_ext && (!strcmp(d_ext,".h5") || !strcmp(d_ext,".hdf5"))){ + outfile = new H5IO(argv[dindex],IObase::Create); } - else #endif - { - // assume its raw - outfile=new IEEEIO(argv[dindex],IObase::Create,swap); // swap only affects IEEEIO output - } + if(!outfile->isValid()){ printf("cant write %s\n",argv[dindex]); delete infile; @@ -100,10 +94,8 @@ int main(int argc,char *argv[]){ IObase::DataType type; char *data; infile->seek(i); -#ifdef WITH_HDF4 if(hdfin && hdffile->isCoord()) continue; // skip coord vars -#endif - // fprintf(stderr,".%u",i); + fprintf(stderr,".%u",i); infile->readInfo(type,rank,dims); { int j,sz; @@ -117,7 +109,7 @@ int main(int argc,char *argv[]){ for(int j=0;j<infile->nAttributes();j++){ char name[256]; // should be big enough int length; - // fprintf(stderr,"a"); + fprintf(stderr,"a"); infile->readAttributeInfo(j,name,type,length); data = new char[length * IObase::sizeOf(type)]; infile->readAttribute(j,data); @@ -127,6 +119,6 @@ int main(int argc,char *argv[]){ } puts(""); delete outfile; - // delete infile; + delete infile; return 0; // success code } |