#!/usr/bin/awk -f BEGIN { nratoms["bonds"] = 2; nratoms["angles"] = 3; nratoms["dihedrals"] = 4; nratoms["pairs"] = 2; nratoms["dummies2"] = 3; nratoms["dummies3"] = 4; nratoms["dummies4"] = 5; nratoms["exclusions"] = -1; nratoms["constraints"] = 2; nratoms["settles"] = 1; nratoms["position_restraints"] = 1; nratoms["angle_restraints"] = 4; nratoms["angle_restraints_z"] = 2; nratoms["distance_restraints"] = 2; nratoms["orientation_restraints"] = 2; anr = 1; nerror=0; print ";"; print "; Processed by renumtop"; print ";"; } /^[ \t]*[;#]/ || !NF { print; next; } /^[ \t]*\[/ && /\][ \t]*$/ { block = $0; sub("^[ \t]*\[[ \t]*","",block); sub("[ \t]*\][ \t]*$","",block); tolower(block); printf("[ %s ]\n", block); next; } block=="atoms" { label = $1; if (atomnr[label]) { printf("; ERROR: duplicate atom label '%s' for atom #%d (already used for atom #%d)\n", label, anr, atomnr[label]); nerror++; } printf ("%6d %-6s %6d %-6s %-6s %-6d %10g %10g\n", anr, $2, $3, $4, $5, $6, $7, $8); atomnr[label] = anr; anr++; next; } { nrat = nratoms[block]; if (nrat==-1) nrat = NF; for(i=1; i<=nrat; i++) { anr = atomnr[$i] if ( !anr ) { printf("; ERROR: undefined atom label '%s'\n", $i); nerror++; anr = -1; } $i = anr; } for(i=1; i<=NF; i++) printf(" %5s", $i); printf("\n"); next; } END { if (nerror) { printf("\n"); printf("; ERROR: there were %d errors\n", nerror); printf("\n"); } exit nerror; } # last line