aboutsummaryrefslogtreecommitdiff
path: root/src/convert2native.cc
blob: eb14dae7bf8cb5599b50d958cecd889da1716dfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "IO.hh"
#include "IEEEIO.hh"
int main(int argc,char *argv[]){
  if(argc!=3){
    printf("Correct usage is %s <infile> <outfile>\n",argv[0]);
    exit(1); // failure code
  }
  IObase *infile=new IEEEIO(argv[1],IObase::Read);
  if(!infile->isValid()){printf("cant read %s\n",argv[1]); exit(0);}
  IObase *outfile=new IEEEIO(argv[2],IObase::Create);
  if(!outfile->isValid()){
    printf("cant write %s\n",argv[2]); 
    delete infile; 
    exit(0);
  }
  for(int i=0;i<infile->nDatasets();i++){
    int rank,dims[5];
    IObase::DataType type;
    char *data;

    fprintf(stderr,".%u",i);
    infile->readInfo(type,rank,dims);
    {
      int j,sz;
      for(j=0,sz=1;j<rank;j++) sz*=dims[j];
      sz*=IObase::sizeOf(type);
      data=new char[sz];
    }
    infile->read(data);
    outfile->write(type,rank,dims,data);
    delete data; // OK, so I'm not being smart about mem allocation here
    for(int j=0;j<infile->nAttributes();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 infile;
  delete outfile;
  return 0; // success code
}