Replace floating-point by integer in awk
Hi,
I am trying to write a script to extract multiple sets of data from a chemistry output file. The problem section is in the following format...
Geometry "geometry" -> "geometry"
1 Pd 46.0000 -0.19290971 0.00535260 0.02297606
2 P 15.0000 -0.14710910 -2.36148276 0.03834032
3 P 15.0000 -0.15274409 2.36634164 -0.06817369
4 C-t 6.0000 -2.28301257 -0.04175538 0.06012368
5 H-t 1.0000 -2.64711929 -0.61127738 -0.80775979
6 H-t 1.0000 -2.59746921 -0.53769963 0.98862569
7 H-t 1.0000 -2.72455591 0.96040010 0.02865251
8 O-t 8.0000 2.07206484 -0.64945821 -0.99276006
9 H-t 1.0000 2.35209406 -0.10074612 -1.74408343
10 H-t 1.0000 2.22690284 -0.00778417 0.03690656
11 O-t 8.0000 2.04896854 0.63726649 1.06014962
12 H-t 1.0000 2.29703540 0.08837100 1.82240885
Atomic Mass
My problem...
I need a way to convert the 3rd column (the "integer" in floating-point format) into just an integer BEFORE the print command so I can then treat these integers with an array from a split function.
Is there a way of doing this in my script...
#! /usr/bin/awk -f
#create array to convert integers to element symbols
# 1=H, 2=He, etc.
BEGIN {
i = 1;e = 1;
atomlist = "H ,He,Li,Be,B ,C ,N ,O ,F ,Ne,Na,Mg,Al,Si,P ,S ,Cl,Ar,K ,Ca,Sc,Ti,V,Cr,Mn,Fe,Co,Ni,Cu,Zn,Ga,Ge,As,Se,Br,Kr,Rb,Sr,Y,Zr,Nb,Mo,Tc,Ru,Rh,Pd,Ag,Cd,In,Sn,Sb,Te,I ,Xe,Cs,Ba,La,Ce,Pr,Nd,Pm,Sm,Eu,Gd,Tb,Dy,Ho,Er,Tm,Yb,Lu,Hf,Ta,W,Re,Os,Ir,Pt,Au,Hg,Tl,Pb,Bi,Po,At,Rn,F r,Ra,Ac,Th,Pa,U,Np,Pu,Am,Cm,Bk,Cf,Es,Fm,Md,No,Lr,Rf,Db,Sg,Bh,Hs,Mt";
split(atomlist,PSE,",")
}
# find out number of lines of data (natoms)
/Geometry "geometry" -> "geometry"/ {natoms=0;++steps}
# extract energy value for each set
/^@/ {
if ( $2 ~ /[0-9]+/ ) {
E[e++]=$3
}
}
# exctract only columns 3-6 from the set
# convert $3 from floating-point to integer
/Geometry "geometry" -> "geometry"/,/Atomic Mass/ {
if ( $1 ~ /[0-9]+/ ) {
++natoms;
S[i] = $3; <-- problem line here
X[i] = $4;
Y[i] = $5;
Z[i++] = $6
}
}
END {
i=1;k=1; j=natoms;
do {
if (j==natoms) {z++;printf("%i\n%22.8f\n",natoms,E[i++]);j=0};
printf("%s %8.6f %8.6f %8.6f",PSE[S[k]],X[k],Y[k],Z[k]);
printf("\n");
++k;++j}
while (k <= steps*natoms)
;
}
At the moment everything works except for that one column of data, as treating the floating-point with the array produces no result.
Any help would be fantastic!