#!/bin/bash
. /cluster/apps/courses/mmm/m_functions.bash
if [[ $# -ne 3 ]]
then
	echo "Error!!!
	Please specify three arguments
Description:
	This program creates a z histogram of a XYZ file
Usage:
	./histo_z file.xyz first_frame last_frame" >&2 
	exit 1
fi


if [[ ! -e $1 ]]
then
	echo "Error!!!
File $1 does not exist"
	exit 1
fi

#
# Number of subdivisions. can be changed
#
Nintervals=1000

#
# Determination of number of atoms
#
N_atoms=`m_xyznatoms < $1`


#
# Determination of zmin and zmax
#
MINMAX=( `m_xyzminmax z <  $1` )


#
# Number of the first slide
#
First_frame=$2

#
# Number of the last frame : put "all" or number of the last frame of xyz file
#
Last_frame=$3

#
# m_xyzframes - this function takes slides from the $First_slide to the $Last_slide
# m_xyzzhistogram  - this function creates z-histogram of a slab
#
m_xyzframes $First_frame $Last_frame $N_atoms $1 |  m_xyzzhistogram $Nintervals $N_atoms ${MINMAX[0]} ${MINMAX[1]}



