# Chem3D Cartesian Coordinates 1 and 2
# Created:	 19/05/2010
# Last modified: 19/05/2010
# ChangeLog:
# Notes:	Only connectivity based on positions is supported. Atom type data is ignored.

filter(type="importmodel",name="Chem3D Cartesian Coordinates", nickname="cc", extension="cc1,cc2", glob="*.cc*", id=34)
{
	# Variable declaration
	int natoms, n, l, ffid, hascell=FALSE, exponent=0, con[10];
	model m;
	string e,title;
	double a,b,c,alpha,beta,gamma;
	vector v;
	atom i;

	# Read initial data
	readline(natoms,e,b,c,alpha,beta,gamma,exponent);

	# Was a cell specified?
	if (e != "")
	{
		a = atof(e);
		hascell = TRUE;
		printf("Model has a cell specification.\n");
	}

	while (!eof())
	{
		m = newmodel(filterfilename());
		# Since the connection data is supplied at the same time as the atoms, we must create all atoms at once,
		# and then set positions and bond them afterwards.
		for (n=1; n<=natoms; ++n) i = newatom(0);
		for (n=1; n<=natoms; ++n)
		{
			readline(e,l,v.x,v.y,v.z,ffid,con[1],con[2],con[3],con[4],con[5],con[6],con[7],con[8],con[9],con[10]);
			setelement(e,m.atoms[n]);
			if (hascell) v /= 10.0^exponent;
			m.atoms[n].r = v;
			# Connections
			for (l=1; l<=10; ++l)
			{
				if (con[l] == 0) break;
				newbond(n,con[l]);
			}
		}
		# Convert from fractional coordinates if necessary
		if (hascell) fractoreal();
		finalisemodel();
	}
}

