#!/usr/bin/perl
# Script for generating an fcc slab
# (Dmitri Schebarchov - 05/03/2007)

$lattice=1.00; 
$xyzfile="fcc100-coords";

$nmax_x=5;
$nmax_y=5;
$nmax_z=3;
$num=4; # number of atoms in cubic cell

# Primitive (cubic) cell:
$x0=0.00;
$y0=0.00;
$z0=0.00;

$x1=0.50;
$y1=0.50;
$z1=0.00;

$x2=0.50;
$y2=0.00;
$z2=0.50;

$x3=0.00;
$y3=0.50;
$z3=0.50;

$natoms=$nmax_x*$nmax_y*$nmax_z*$num;
$sep=$lattice/sqrt(2);
$bx=$nmax_x*$lattice;
$by=$nmax_y*$lattice;
$bz=$nmax_z*$lattice;

open(XYZFILE,">$xyzfile") || die ("Couldn't open file $xyzfile, stopped");

print XYZFILE "$natoms\n";
printf(XYZFILE "fcc: $nmax_x X $nmax_y X $nmax_z primitive cells (box: %9.4f X %9.4f X %9.4f Angstrom), sep=%9.4f\n",$bx,$by,$bz,$sep);

for($nz=0; $nz<$nmax_z; $nz++){
    for($ny=0; $ny<$nmax_y; $ny++){				
	for($nx=0; $nx<$nmax_x; $nx++){
	  
	    printf(XYZFILE " %10.5f %10.5f %10.5f \n",
		   ($x0+$nx)*$lattice,($y0+$ny)*$lattice,($z0+$nz)*$lattice);
	    
	    printf(XYZFILE " %10.5f %10.5f %10.5f \n",
		   ($x1+$nx)*$lattice,($y1+$ny)*$lattice,($z1+$nz)*$lattice);
	    
	    printf(XYZFILE " %10.5f %10.5f %10.5f \n",
		   ($x2+$nx)*$lattice,($y2+$ny)*$lattice,($z2+$nz)*$lattice);
	    
	    printf(XYZFILE " %10.5f %10.5f %10.5f \n",
		   ($x3+$nx)*$lattice,($y3+$ny)*$lattice,($z3+$nz)*$lattice);
	}
    }
}

close(XYZFILE) || die ("Couldn't close file $xyzfile, stopped");

exit(0);
