| 1 | #! @PERL@ -w
 | 
|---|
| 2 | #
 | 
|---|
| 3 | # Project: ESPACK 
 | 
|---|
| 4 | # Jan Hamaekers
 | 
|---|
| 5 | # Frederik Heber
 | 
|---|
| 6 | # 2007
 | 
|---|
| 7 | #
 | 
|---|
| 8 | 
 | 
|---|
| 9 | use strict;
 | 
|---|
| 10 | 
 | 
|---|
| 11 | my ($Help, $Prefix, $Outputdir, $Inputdir, $bytes, $ions);
 | 
|---|
| 12 | my $i;
 | 
|---|
| 13 | use Getopt::Long;
 | 
|---|
| 14 | use File::Copy;
 | 
|---|
| 15 | 
 | 
|---|
| 16 | GetOptions("help"    => \$Help,
 | 
|---|
| 17 |         "prefix=s"     => \$Prefix,
 | 
|---|
| 18 |         "inputdir=s"    =>      \$Inputdir,
 | 
|---|
| 19 |         "outputdir=s",   => \$Outputdir);
 | 
|---|
| 20 | if ($Help) { usage();}
 | 
|---|
| 21 | 
 | 
|---|
| 22 | sub usage {
 | 
|---|
| 23 |     print STDERR <<"EOF";
 | 
|---|
| 24 | Usage: $0 [OPTIONS]
 | 
|---|
| 25 | Recreates the .dx files for OpenDX in a desired sequence from given .doc and .data files
 | 
|---|
| 26 |   --prefix <prefix>             read data from file prefixed with this
 | 
|---|
| 27 |   --inputdir <inputdir> read data from this directory
 | 
|---|
| 28 |   --outputdir <outputdir> put the resequenced field into this dir 
 | 
|---|
| 29 |   --help                        this help
 | 
|---|
| 30 | EOF
 | 
|---|
| 31 |   exit 1;
 | 
|---|
| 32 | }
 | 
|---|
| 33 | 
 | 
|---|
| 34 | if (!defined $Inputdir) { usage(); }
 | 
|---|
| 35 | 
 | 
|---|
| 36 | # open new .dx files and copy standard ones files
 | 
|---|
| 37 | if (!defined $Outputdir) {
 | 
|---|
| 38 |         if (defined $Inputdir) {
 | 
|---|
| 39 |           $Outputdir="$Inputdir/view";
 | 
|---|
| 40 |         } else {
 | 
|---|
| 41 |                 $Outputdir="./view";
 | 
|---|
| 42 |         }
 | 
|---|
| 43 | }
 | 
|---|
| 44 | mkdir $Outputdir;
 | 
|---|
| 45 | open(ELECTRONS_DX, ">$Outputdir/$Prefix.density.dx") or die "could not open $Outputdir/$Prefix.density.dx: $!";
 | 
|---|
| 46 | open(IONS_DX, ">$Outputdir/$Prefix.ions.dx") or die "could not open $Outputdir/$Prefix.ions.dx: $!";
 | 
|---|
| 47 | 
 | 
|---|
| 48 | if (defined $Prefix && defined $Inputdir) {
 | 
|---|
| 49 |         copy("$Inputdir/$Prefix.density.doc","$Outputdir/$Prefix.density.doc") or die "could not copy $Inputdir/$Prefix.density.doc to $Outputdir/: $!";
 | 
|---|
| 50 |         copy("$Inputdir/$Prefix.ions.datZ","$Outputdir/$Prefix.ions.datZ") or die "could not copy $Inputdir/$Prefix.ions.datZ to $Outputdir/: $!";
 | 
|---|
| 51 |         copy("$Inputdir/$Prefix.ions.doc","$Outputdir/$Prefix.ions.doc") or die "could not copy $Inputdir/$Prefix.ions.doc to $Outputdir/: $!";
 | 
|---|
| 52 | } else {
 | 
|---|
| 53 |         print "Need to know a prefix and inputdir for all OpenDX files!\n";
 | 
|---|
| 54 |         exit 1;
 | 
|---|
| 55 | }
 | 
|---|
| 56 | 
 | 
|---|
| 57 | 
 | 
|---|
| 58 | # copy first the lines or so for the box
 | 
|---|
| 59 | open(INPUT ,"<$Inputdir/$Prefix.density.dx");
 | 
|---|
| 60 | my $buffer;
 | 
|---|
| 61 | for ($i=1;$i<=11;$i++) {
 | 
|---|
| 62 |         $buffer = <INPUT>;
 | 
|---|
| 63 |         print ELECTRONS_DX "$buffer";
 | 
|---|
| 64 | }
 | 
|---|
| 65 | while (<INPUT>) {
 | 
|---|
| 66 |         if ( /object "dat.0000"/ ) {
 | 
|---|
| 67 |                 my @linebuffer = split(/[ \t]+/);
 | 
|---|
| 68 |                 $bytes = $linebuffer[9];
 | 
|---|
| 69 |         }
 | 
|---|
| 70 | }
 | 
|---|
| 71 | print "Found $bytes per data file\n";
 | 
|---|
| 72 | close(INPUT);
 | 
|---|
| 73 | open(INPUT ,"<$Inputdir/$Prefix.ions.dx");
 | 
|---|
| 74 | for ($i=1;$i<=4;$i++) {
 | 
|---|
| 75 |         $buffer = <INPUT>;
 | 
|---|
| 76 |         print IONS_DX "$buffer";
 | 
|---|
| 77 | }
 | 
|---|
| 78 | while (<INPUT>) {
 | 
|---|
| 79 |         if ( /object "ionpos.0000"/ ) {
 | 
|---|
| 80 |                 my @linebuffer = split(/[ \t]+/);
 | 
|---|
| 81 |                 $ions = $linebuffer[11];
 | 
|---|
| 82 |         }
 | 
|---|
| 83 | }
 | 
|---|
| 84 | print "Found $ions per data file\n";
 | 
|---|
| 85 | close(INPUT);
 | 
|---|
| 86 | 
 | 
|---|
| 87 | # add per object the referencing and copy the .data file
 | 
|---|
| 88 | my ($source, $dest);
 | 
|---|
| 89 | for($i=0;$i<=$#ARGV;$i++) {
 | 
|---|
| 90 |         $source = sprintf("%04d",$ARGV[$i]);
 | 
|---|
| 91 |         $dest = sprintf("%04d",$i);
 | 
|---|
| 92 |         copy("$Inputdir/$Prefix.density.data.$source","$Outputdir/$Prefix.density.data.$dest") or die "could not copy $Inputdir/$Prefix.density.data.$source to $Outputdir/$Prefix.density.data.$dest: $!";
 | 
|---|
| 93 |         printf(ELECTRONS_DX "object \"dat.%04d\" class array type float rank 0 items %d lsb binary\n", $i, $bytes);
 | 
|---|
| 94 |         printf(ELECTRONS_DX "data file $Prefix.density.data.%04d,0\n",$i);
 | 
|---|
| 95 |         print (ELECTRONS_DX "attribute \"dep\" string \"positions\"\n\n");  # 0 - 8586755 Bytes\n\n");
 | 
|---|
| 96 |         printf(ELECTRONS_DX "object \"obj.%04d\" class field\n",$i);
 | 
|---|
| 97 |         printf(ELECTRONS_DX "component \"positions\" \"posdens\"\ncomponent \"connections\" \"gridcon\"\ncomponent \"data\" \"dat.%04d\"\n\n",$i);
 | 
|---|
| 98 | 
 | 
|---|
| 99 |         copy("$Inputdir/$Prefix.ions.force.$source","$Outputdir/$Prefix.ions.force.$dest") or die "could not copy $Inputdir/$Prefix.ions.force.$source to $Outputdir/$Prefix.ions.force.$dest:$!";
 | 
|---|
| 100 |         copy("$Inputdir/$Prefix.ions.pos.$source","$Outputdir/$Prefix.ions.pos.$dest") or die "could not copy $Inputdir/$Prefix.ions.pos.$source to $Outputdir/$Prefix.ions.pos.$dest:$!";
 | 
|---|
| 101 |         printf(IONS_DX "object \"ionpos.%04d\" class array type float rank 1 shape 3 items %d lsb binary\n", $i, $ions);
 | 
|---|
| 102 |         printf(IONS_DX "data file $Prefix.ions.pos.%04d,0\n\n",$i);
 | 
|---|
| 103 |         printf(IONS_DX "object \"iondatF.%04d\" class array type float rank 1 shape 3 items %d lsb binary\n",$i, $ions);
 | 
|---|
| 104 |         printf(IONS_DX "data file $Prefix.ions.force.%04d,0\nattribute \"dep\" string \"positions\"\n\n",$i);
 | 
|---|
| 105 |         printf(IONS_DX "object \"ionobjF.%04d\" class field\n",$i);
 | 
|---|
| 106 |         printf(IONS_DX "component \"positions\" \"ionpos.%04d\"\n",$i);
 | 
|---|
| 107 |         printf(IONS_DX "component \"data\" \"iondatF.%04d\"\n",$i);
 | 
|---|
| 108 |         printf(IONS_DX "object \"ionobjZ.%04d\" class field\n",$i);
 | 
|---|
| 109 |         printf(IONS_DX "component \"positions\" \"ionpos.%04d\"\ncomponent \"data\" \"iondatZ\"\n\n",$i);
 | 
|---|
| 110 | }
 | 
|---|
| 111 | 
 | 
|---|
| 112 | # finialize with member list
 | 
|---|
| 113 | print ELECTRONS_DX "object \"series\" class series\n";
 | 
|---|
| 114 | print IONS_DX "object \"ionseriesF\" class series\n";
 | 
|---|
| 115 | for($i=0;$i<=$#ARGV;$i++) {
 | 
|---|
| 116 |         printf(ELECTRONS_DX "member %d \"obj.%04d\" position %d.000000\n",$i,$i,$i);
 | 
|---|
| 117 |         printf(IONS_DX "member %d \"ionobjF.%04d\" position %d.000000\n",$i,$i,$i);
 | 
|---|
| 118 | }
 | 
|---|
| 119 | print ELECTRONS_DX "end\n";
 | 
|---|
| 120 | print IONS_DX "\n";
 | 
|---|
| 121 | print IONS_DX "object \"ionseriesZ\" class series\n";
 | 
|---|
| 122 | for($i=0;$i<=$#ARGV;$i++) {
 | 
|---|
| 123 |         printf(IONS_DX "member %d \"ionobjZ.%04d\" position %d.000000\n",$i,$i,$i);
 | 
|---|
| 124 | }
 | 
|---|
| 125 | print IONS_DX "end\n";
 | 
|---|
| 126 | 
 | 
|---|
| 127 | # end
 | 
|---|
| 128 | exit 0
 | 
|---|