| [a0bcf1] | 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 | # open new .dx files and copy standard ones files | 
|---|
|  | 35 | if (!defined $Outputdir) { | 
|---|
|  | 36 | if (defined $Inputdir) { | 
|---|
|  | 37 | $Outputdir="$Inputdir/view"; | 
|---|
|  | 38 | } else { | 
|---|
|  | 39 | $Outputdir="./view"; | 
|---|
|  | 40 | } | 
|---|
|  | 41 | } | 
|---|
|  | 42 | mkdir $Outputdir; | 
|---|
|  | 43 | open(ELECTRONS_DX, ">$Outputdir/$Prefix.density.dx") or die "could not open $Outputdir/$Prefix.density.dx: $!"; | 
|---|
|  | 44 | open(IONS_DX, ">$Outputdir/$Prefix.ions.dx") or die "could not open $Outputdir/$Prefix.ions.dx: $!"; | 
|---|
|  | 45 |  | 
|---|
|  | 46 | if (defined $Prefix && defined $Inputdir) { | 
|---|
|  | 47 | copy("$Inputdir/$Prefix.density.doc","$Outputdir/$Prefix.density.doc") or die "could not copy $Inputdir/$Prefix.density.doc to $Outputdir/: $!"; | 
|---|
|  | 48 | copy("$Inputdir/$Prefix.ions.datZ","$Outputdir/$Prefix.ions.datZ") or die "could not copy $Inputdir/$Prefix.ions.datZ to $Outputdir/: $!"; | 
|---|
|  | 49 | copy("$Inputdir/$Prefix.ions.doc","$Outputdir/$Prefix.ions.doc") or die "could not copy $Inputdir/$Prefix.ions.doc to $Outputdir/: $!"; | 
|---|
|  | 50 | } else { | 
|---|
|  | 51 | print "Need to know a prefix and inputdir for all OpenDX files!\n"; | 
|---|
|  | 52 | exit 1; | 
|---|
|  | 53 | } | 
|---|
|  | 54 |  | 
|---|
|  | 55 |  | 
|---|
|  | 56 | # copy first the lines or so for the box | 
|---|
|  | 57 | open(INPUT ,"<$Inputdir/$Prefix.density.dx"); | 
|---|
|  | 58 | my $buffer; | 
|---|
|  | 59 | for ($i=1;$i<=11;$i++) { | 
|---|
|  | 60 | $buffer = <INPUT>; | 
|---|
|  | 61 | print ELECTRONS_DX "$buffer"; | 
|---|
|  | 62 | } | 
|---|
|  | 63 | while (<INPUT>) { | 
|---|
|  | 64 | if ( /object "dat.0000"/ ) { | 
|---|
|  | 65 | my @linebuffer = split(/[ \t]+/); | 
|---|
|  | 66 | $bytes = $linebuffer[9]; | 
|---|
|  | 67 | } | 
|---|
|  | 68 | } | 
|---|
|  | 69 | print "Found $bytes per data file\n"; | 
|---|
|  | 70 | close(INPUT); | 
|---|
|  | 71 | open(INPUT ,"<$Inputdir/$Prefix.ions.dx"); | 
|---|
|  | 72 | for ($i=1;$i<=4;$i++) { | 
|---|
|  | 73 | $buffer = <INPUT>; | 
|---|
|  | 74 | print IONS_DX "$buffer"; | 
|---|
|  | 75 | } | 
|---|
|  | 76 | while (<INPUT>) { | 
|---|
|  | 77 | if ( /object "ionpos.0000"/ ) { | 
|---|
|  | 78 | my @linebuffer = split(/[ \t]+/); | 
|---|
|  | 79 | $ions = $linebuffer[11]; | 
|---|
|  | 80 | } | 
|---|
|  | 81 | } | 
|---|
|  | 82 | print "Found $ions per data file\n"; | 
|---|
|  | 83 | close(INPUT); | 
|---|
|  | 84 |  | 
|---|
|  | 85 | # add per object the referencing and copy the .data file | 
|---|
|  | 86 | my ($source, $dest); | 
|---|
|  | 87 | for($i=0;$i<=$#ARGV;$i++) { | 
|---|
|  | 88 | $source = sprintf("%04d",$ARGV[$i]); | 
|---|
|  | 89 | $dest = sprintf("%04d",$i); | 
|---|
|  | 90 | 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: $!"; | 
|---|
|  | 91 | printf(ELECTRONS_DX "object \"dat.%04d\" class array type float rank 0 items %d lsb binary\n", $i, $bytes); | 
|---|
|  | 92 | printf(ELECTRONS_DX "data file $Prefix.density.data.%04d,0\n",$i); | 
|---|
|  | 93 | print (ELECTRONS_DX "attribute \"dep\" string \"positions\"\n\n");  # 0 - 8586755 Bytes\n\n"); | 
|---|
|  | 94 | printf(ELECTRONS_DX "object \"obj.%04d\" class field\n",$i); | 
|---|
|  | 95 | printf(ELECTRONS_DX "component \"positions\" \"posdens\"\ncomponent \"connections\" \"gridcon\"\ncomponent \"data\" \"dat.%04d\"\n\n",$i); | 
|---|
|  | 96 |  | 
|---|
|  | 97 | 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:$!"; | 
|---|
|  | 98 | 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:$!"; | 
|---|
|  | 99 | printf(IONS_DX "object \"ionpos.%04d\" class array type float rank 1 shape 3 items %d lsb binary\n", $i, $ions); | 
|---|
|  | 100 | printf(IONS_DX "data file $Prefix.ions.pos.%04d,0\n\n",$i); | 
|---|
|  | 101 | printf(IONS_DX "object \"iondatF.%04d\" class array type float rank 1 shape 3 items %d lsb binary\n",$i, $ions); | 
|---|
|  | 102 | printf(IONS_DX "data file $Prefix.ions.force.%04d,0\nattribute \"dep\" string \"positions\"\n\n",$i); | 
|---|
|  | 103 | printf(IONS_DX "object \"ionobjF.%04d\" class field\n",$i); | 
|---|
|  | 104 | printf(IONS_DX "component \"positions\" \"ionpos.%04d\"\n",$i); | 
|---|
|  | 105 | printf(IONS_DX "component \"data\" \"iondatF.%04d\"\n",$i); | 
|---|
|  | 106 | printf(IONS_DX "object \"ionobjZ.%04d\" class field\n",$i); | 
|---|
|  | 107 | printf(IONS_DX "component \"positions\" \"ionpos.%04d\"\ncomponent \"data\" \"iondatZ\"\n\n",$i); | 
|---|
|  | 108 | } | 
|---|
|  | 109 |  | 
|---|
|  | 110 | # finialize with member list | 
|---|
|  | 111 | print ELECTRONS_DX "object \"series\" class series\n"; | 
|---|
|  | 112 | print IONS_DX "object \"ionseriesF\" class series\n"; | 
|---|
|  | 113 | for($i=0;$i<=$#ARGV;$i++) { | 
|---|
|  | 114 | printf(ELECTRONS_DX "member %d \"obj.%04d\" position %d.000000\n",$i,$i,$i); | 
|---|
|  | 115 | printf(IONS_DX "member %d \"ionobjF.%04d\" position %d.000000\n",$i,$i,$i); | 
|---|
|  | 116 | } | 
|---|
|  | 117 | print ELECTRONS_DX "end\n"; | 
|---|
|  | 118 | print IONS_DX "\n"; | 
|---|
|  | 119 | print IONS_DX "object \"ionseriesZ\" class series\n"; | 
|---|
|  | 120 | for($i=0;$i<=$#ARGV;$i++) { | 
|---|
|  | 121 | printf(IONS_DX "member %d \"ionobjZ.%04d\" position %d.000000\n",$i,$i,$i); | 
|---|
|  | 122 | } | 
|---|
|  | 123 | print IONS_DX "end\n"; | 
|---|
|  | 124 |  | 
|---|
|  | 125 | # end | 
|---|
|  | 126 | exit 0 | 
|---|