/* Copyright (C) 2008 Jiri Pittner or This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #define EPSPRINT .05 #include "la.h" #include "fourindex.h" #include "nonclass.h" #include "basic.h" using namespace std; using namespace LA; int main(int argc, char **argv) { sigtraceback(SIGSEGV,1); sigtraceback(SIGABRT,1); sigtraceback(SIGBUS,1); sigtraceback(SIGFPE,1); cout.setf(ios::scientific); cout.precision(16); int dim=0; int dim2=0; off64_t offset=0; int fortransequential=0; int skip=0; ++argv; bool orcaformat=false; //options can be given in any order: repeat until no option is recognized for(char **argv0=NULL; argv0!=argv;) { argv0=argv; if(argc>1 && !strcmp(*argv,"--orca")) {orcaformat=true; --argc; ++argv;} if(argc>2 && !strcmp(*argv,"-f")) {fortransequential=1; sscanf(*++argv,"%d",&skip); ++argv; argc-=2;} if(argc>2 && !strcmp(*argv,"-o")) {sscanf(*++argv,"%ld",&offset); ++argv; argc-=2;} if(argc>3 && !strcmp(*argv,"-d")) {sscanf(*++argv,"%d",&dim); sscanf(*++argv,"%d",&dim2); ++argv; argc-=3;} } NRMat a; if(dim>0 && dim2>0) a.resize(dim,dim2); int f=open(*argv,O_RDONLY); if(fortransequential) { uint32_t label1,label2; while(skip--) //skip given number of fortran sequential file records and start mark of next record { if(sizeof(uint32_t)!=read(f,&label1,sizeof(uint32_t))) laerror("cannot read fortran starting label of skipped record"); if((off_t) -1 == lseek(f,(off_t)label1,SEEK_CUR)) laerror("seek error in -f"); if(sizeof(uint32_t)!=read(f,&label2,sizeof(uint32_t))) laerror("cannot read fortran ending label of skipped record"); if(label1!=label2) laerror("fortran record length mismatch"); } if(sizeof(uint32_t)!=read(f,&label1,sizeof(uint32_t))) laerror("cannot read fortran starting label of target record"); } if(offset) {if((off_t) -1 == lseek64(f, offset, SEEK_SET)) laerror("seek error in -o");;} a.get(f,dim==0,false,orcaformat); close(f); cout <