#!/usr/bin/bash

#script pickMin_irc.sh
#	- select Mth configuration from the end of a file in XDATCAR format and write it into
#	the file POSCAR.pick (POSCAR format)
#
#	- M must be provided as argument by user. In this case, for instance:
#
#	pickMin_irc.sh 20
#
#	M is set to 20, i.e., 20th configuration from the end of XDATCAR is selected

pick=$1

nions=$(head -7 XDATCAR|tail -1| awk '{print $1+$2+$3+$4+$5+$6+$7+$8+$9+$10}')

echo NIONS: $nions

head -7 XDATCAR > POSCAR.pick

let nl1=pick*nions+pick

let nl2=nions+1


tail -$nl1 XDATCAR |head -$nl2 >> POSCAR.pick
