// a database of model definitions

public class modelDB
{
private static modelDEF modeldefs[];
private static int      size;
private static int      num;

//--------- optimization ---------
public static model  models[] = null;   // all models in existance
public static int    allocated;
public static void init_static(int dim) // dim = max number of model definitions
    {
	allocated = 0;
	size = dim;
	num  = 0;
        modeldefs = new modelDEF[size];
	models = new model[size*4];
    }
//--------------------------------
    
public static boolean insert(modelDEF modeldef)
    {
	for(int i=0; i<num; i++)
	    {
		if(modeldefs[i].name.equals(modeldef.name))
		    {
			System.err.println("model definition "+ modeldef.name +" already exists in the database");
			return false;
		    }
	    }
	modeldefs[num++] = modeldef;
	return true;
    }

public static modelDEF find(String name)
    {
	for(int i=0; i<num; i++)
	    {
		if(modeldefs[i].name.equals(name))
		    return modeldefs[i];
	    }
	System.err.println("model definition "+ name +" does not exists in the database");
	return null;
    }

public static model makemodel(String name)
    {
	modelDEF p = find(name);
	if(p == null)
	    {
		System.err.println("cannot create undefined model "+ name);
		return null;
	    }
	models[allocated++] = p.makemodel();
	return models[allocated-1];
    }

public static void makemodels()
    {
	for(int i=0; i<num; i++)
	    {
		modelDEF p = modeldefs[i];
		models[allocated++] = p.makemodel();
	    }
    }
}

