#!/usr/local/bin/bash
#CATEGORY: Output examination and debugging
#SYNOPSIS: List the last energy from several JDFTx output files

if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
	echo '
	List the last energy from several JDFTx output files. Usage:
	
		listEnergy <file1> <file2> ...
	
	For each output file, one line with the energy and the
	name of the output file will be printed.
	'
	exit 0
fi

for FILE in $@; do
	awk '$1=="ElecMinimize:" && $2=="Iter:" { Energy=$5 } $1=="SCF:" && $2=="Cycle:" { Energy=$5 } END {printf("%.15f",Energy)}' $FILE
	echo " $FILE"
done

