package stat; import java.awt.*; import java.io.*; import parameters.Parameter; import parameters.ParameterSet; import parameters.ParameterSetArray; /** Saves the values of the parameters in each parameter set to a file. Each parameter set is on its own row, with each parameter on its own column. The first columns give the group and tag numbers of each parameter set, and then any saved value fields (like the score) for the set. If you only want to save the value fields, without the parameter values, use DumpValueFields statistic. @see DumpValueFieldsStat */ public class DumpStat extends Stat { public DumpStat() {} public void calculateStat() { int i; if(paramSets == null) { System.out.println("No Cam loaded - DumpStat did nothing"); return; } FileDialog fd = new FileDialog(new Frame(), "Save into file:", FileDialog.SAVE); fd.show(); if(fd.getFile() == null) return; try { PrintWriter ps = new PrintWriter(new FileOutputStream(fd.getDirectory() + fd.getFile())); prototype = paramSets.getPrototype(); if(prototype == null) prototype = paramSets.goToBeginning(); if(prototype == null) { ps.close(); return; } // Nothing in cam file // First go through and save titles ps.print("GroupNum\tTag\t"); for(i = 0; i < prototype.getNumValueFields(); i++) ps.print(prototype.getFieldName(i) + "\t"); printParameterLabels(prototype, ps); ps.println(""); // Next go through all the param sets, and print out each one in same order as prototype ParameterSet set = paramSets.goToBeginning(); while(set != null) { ps.print(set.getGroupNum() + "\t" + set.getTag() + "\t"); for(i = 0; i < prototype.getNumValueFields(); i++) ps.print(set.getFieldValue(i) + "\t"); for(i = 0; i < prototype.getNumParams(); i++) { try { int pos = set.getPosition(prototype.getName(i)); ps.print(set.getValue(pos) + "\t"); } catch(Exception e) { ps.print("\t"); } // This one was missing } ps.println(""); System.out.println("Dumped group " + set.getGroupNum()); set = paramSets.getNextSet(); } ps.close(); } catch(Exception e) { System.out.println("Error in DumpStat: " + e.toString()); } } }