# Gaussian03 Filter (for v1.2+)
# Created:	 15/09/2010
# Last modified: 15/09/2010
# ChangeLog:
#	15/09/2010 - Initial version.
# Notes:

filter(type="importmodel", name="Gaussian03 Log File", nickname="g03log", extension="log", glob="*.log", zmap="name", search="Gaussian(R) 03 program", id=911)
{
	# Variable declaration
	int result,nstructures,natoms,n,el,orientation;
	string line,name,discard;
	atom i;
	double rx,ry,rz;

	# Find input orientation and determine number of atoms
	orientation = 0;
	if (find("Input orientation:")) orientation = 1;
	else if (find("Standard orientation:")) orientation = 2;
	if (orientation == 0) error("Couldn't find any coordinates!");
	# Skip four header lines
	skipline(4);
	# Create a new model, and store its pointer for use later
	model m = newmodel(filterfilename());
	natoms = 0;
	do
	{
		readline(n, el, discard, rx, ry, rz);
		if (el != 0)
		{
			natoms++;
			i = newatom(el,rx,ry,rz);
		}
	} while (el != 0);
	printf("There are %i atoms in the structure.\n", natoms);

	# Now search for sets of coordinate
	nstructures = 0;
	while (!eof())
	{
		# Lines containing 'COORDINATES OF ALL ATOMS ARE' are the beginning of coordinate sections
		result = 0;
		if (orientation == 1) result = find("Input orientation:");
		else if (orientation == 2) result = find("Standard orientation:");
		if (result)
		{
			# Found a set of coordinates. Skip 4 lines and then read coordinates
			nstructures++;
			skipline(4);
			writevarf(name, "Frame %i", nstructures);
			addframe(name);
			for (n=1; n<=natoms; ++n)
			{
				readline(n,el,discard,rx,ry,rz);
				newatom(el,rx,ry,rz);
			}
			# Recalculate bonding
			rebond();
			finaliseframe();
		}
	}

	finalisemodel();
}

