#include #include #include #include "IO.hh" #include "IEEEIO.hh" #ifdef WITH_HDF4 #include "HDFIO.hh" #endif #ifdef WITH_HDF5 #include "H5IO.hh" #endif char *programname; void usage(){ printf("Correct usage is %s [-swapbytes]\n",programname); puts("-swapbytes requests opposite of native byte-order for IEEEIO output"); puts("The default is to write IEEE files in native byte-order"); exit(1); // failure code } int main(int argc,char *argv[]){ programname=argv[0]; // for usage/error_exit routine if(argc<3) usage(); int i,swap; int sindex=0,dindex=0,findex=0; IObase *infile,*outfile; #ifdef WITH_HDF4 HDFIO *hdffile = NULL; int hdfin=0; #endif for(i=1;iisValid()){ printf("cant read %s\n",argv[sindex]); usage(); } // for the outfile, #ifdef WITH_HDF4 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 #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; usage(); } // Now do the conversion for(i=0;inDatasets();i++){ int rank,dims[5]; IObase::DataType type; char *data; infile->seek(i); #ifdef WITH_HDF4 if(hdfin && hdffile->isCoord()) continue; // skip coord vars #endif // fprintf(stderr,".%u",i); infile->readInfo(type,rank,dims); { int j,sz; for(j=0,sz=1;jread(data); outfile->write(type,rank,dims,data); delete data; // OK, so I'm not being smart about mem allocation here for(int j=0;jnAttributes();j++){ char name[256]; // should be big enough int length; // fprintf(stderr,"a"); infile->readAttributeInfo(j,name,type,length); data = new char[length * IObase::sizeOf(type)]; infile->readAttribute(j,data); outfile->writeAttribute(name,type,length,data); delete data; } } puts(""); delete outfile; // delete infile; return 0; // success code }