source: util/ReSequenceDX.pl.in@ 71dc4e

Last change on this file since 71dc4e was ccd028, checked in by Frederik Heber <heber@…>, 17 years ago

if no options are given, prints usage() and exit

  • Property mode set to 100644
File size: 4.8 KB
Line 
1#! @PERL@ -w
2#
3# Project: ESPACK
4# Jan Hamaekers
5# Frederik Heber
6# 2007
7#
8
9use strict;
10
11my ($Help, $Prefix, $Outputdir, $Inputdir, $bytes, $ions);
12my $i;
13use Getopt::Long;
14use File::Copy;
15
16GetOptions("help" => \$Help,
17 "prefix=s" => \$Prefix,
18 "inputdir=s" => \$Inputdir,
19 "outputdir=s", => \$Outputdir);
20if ($Help) { usage();}
21
22sub usage {
23 print STDERR <<"EOF";
24Usage: $0 [OPTIONS]
25Recreates 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
30EOF
31 exit 1;
32}
33
34if (!defined $Inputdir) { usage(); }
35
36# open new .dx files and copy standard ones files
37if (!defined $Outputdir) {
38 if (defined $Inputdir) {
39 $Outputdir="$Inputdir/view";
40 } else {
41 $Outputdir="./view";
42 }
43}
44mkdir $Outputdir;
45open(ELECTRONS_DX, ">$Outputdir/$Prefix.density.dx") or die "could not open $Outputdir/$Prefix.density.dx: $!";
46open(IONS_DX, ">$Outputdir/$Prefix.ions.dx") or die "could not open $Outputdir/$Prefix.ions.dx: $!";
47
48if (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
59open(INPUT ,"<$Inputdir/$Prefix.density.dx");
60my $buffer;
61for ($i=1;$i<=11;$i++) {
62 $buffer = <INPUT>;
63 print ELECTRONS_DX "$buffer";
64}
65while (<INPUT>) {
66 if ( /object "dat.0000"/ ) {
67 my @linebuffer = split(/[ \t]+/);
68 $bytes = $linebuffer[9];
69 }
70}
71print "Found $bytes per data file\n";
72close(INPUT);
73open(INPUT ,"<$Inputdir/$Prefix.ions.dx");
74for ($i=1;$i<=4;$i++) {
75 $buffer = <INPUT>;
76 print IONS_DX "$buffer";
77}
78while (<INPUT>) {
79 if ( /object "ionpos.0000"/ ) {
80 my @linebuffer = split(/[ \t]+/);
81 $ions = $linebuffer[11];
82 }
83}
84print "Found $ions per data file\n";
85close(INPUT);
86
87# add per object the referencing and copy the .data file
88my ($source, $dest);
89for($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
113print ELECTRONS_DX "object \"series\" class series\n";
114print IONS_DX "object \"ionseriesF\" class series\n";
115for($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}
119print ELECTRONS_DX "end\n";
120print IONS_DX "\n";
121print IONS_DX "object \"ionseriesZ\" class series\n";
122for($i=0;$i<=$#ARGV;$i++) {
123 printf(IONS_DX "member %d \"ionobjZ.%04d\" position %d.000000\n",$i,$i,$i);
124}
125print IONS_DX "end\n";
126
127# end
128exit 0
Note: See TracBrowser for help on using the repository browser.