@SuppressWarnings({ "unchecked", "rawtypes" })
public static <G,T> Glyphset<G,T> autoLoad(File source, double glyphSize, Glyphset<G,T> glyphs) {
try {
DelimitedReader r = new DelimitedReader(source, 0, DelimitedReader.CSV);
String[] line = r.next();
int skip;
int xField, yField, colorField, valueField;
if (isNumber(line[0])) {
xField =0;
yField =1;
colorField = line.length >= 3 ? 2 : -1;
valueField = line.length >= 4 ? 3 : -1;
skip =0;
} else {
xField = fieldMatch("X", line, 0);
yField = fieldMatch("Y", line, 1);
colorField = fieldMatch("C", line, -1);
valueField = fieldMatch("V", line, -1);
skip =1;
}
if (glyphs instanceof MemMapList) {
MemMapList<G,T> list = new MemMapList<>(source, ((MemMapList<G,T>) glyphs).shaper(), ((MemMapList<G,T>) glyphs).valuer());
System.out.printf("Setup list of %d entries.\n", list.size());
return list;
} else {
int valField = Math.max(colorField, valueField);
int max = Math.max(xField, valField);
max = Math.max(max, yField);
Converter.TYPE[] types = new Converter.TYPE[max+1];
Arrays.fill(types, Converter.TYPE.X);
types[xField] = Converter.TYPE.DOUBLE;
types[yField] = Converter.TYPE.DOUBLE;
if (colorField >=0) {types[colorField] = Converter.TYPE.COLOR;}
if (valueField >=0) {types[valueField] = Converter.TYPE.DOUBLE;}
Valuer valuer;
if (valField >=0) {valuer = new Indexed.ToValue<Indexed,T>(valField);}
else {valuer = new Valuer.Constant<>(Color.red);}
return Util.load(
(Glyphset<Rectangle2D,T>) glyphs,
new DelimitedReader(source, skip, DelimitedReader.CSV),
new Converter(types),
new Indexed.ToRect(glyphSize, glyphSize, true, xField, yField),
valuer);
}