ingo@686: package de.intevation.flys.artifacts.model; ingo@686: ingo@686: import java.util.ArrayList; ingo@686: ingo@686: import org.apache.log4j.Logger; ingo@686: ingo@686: public class Calculation1 ingo@686: extends Calculation ingo@686: { ingo@686: private static Logger logger = Logger.getLogger(Calculation1.class); ingo@686: ingo@686: protected double [] kms; ingo@686: protected double [] qs; ingo@686: protected double [] ws; ingo@686: protected boolean up; ingo@686: ingo@686: public Calculation1() { ingo@686: } ingo@686: ingo@686: public Calculation1( ingo@686: double [] kms, ingo@686: double [] qs, ingo@686: double [] ws, ingo@686: boolean up ingo@686: ) { ingo@686: this.kms = kms; ingo@686: this.qs = qs; ingo@686: this.ws = ws; ingo@686: this.up = up; ingo@686: } ingo@686: ingo@686: public WQKms [] calculate(WstValueTable wst) { ingo@686: ingo@686: ArrayList results = new ArrayList(); ingo@686: ingo@686: double ref = kms[up ? 0 : kms.length-1]; ingo@686: ingo@686: String prefix; ingo@686: double [] origData; ingo@686: ingo@686: if (ws != null) { prefix = "W="; origData = ws; } ingo@686: else { prefix = "Q="; origData = qs; } ingo@686: ingo@686: int oldNumProblems = numProblems(); ingo@686: ingo@686: for (int i = 0; i < qs.length; i++) { ingo@686: ingo@686: double [] oqs = new double[kms.length]; ingo@686: double [] ows = new double[kms.length]; ingo@686: ingo@686: boolean success = ingo@686: wst.interpolate(qs[i], ref, kms, ows, oqs, this) != null; ingo@686: ingo@686: int newNumProblems = numProblems(); ingo@686: ingo@686: if (success) { ingo@686: WQKms result = new WQKms(kms, oqs, ows, prefix + origData[i]); ingo@686: if (oldNumProblems != newNumProblems) { ingo@686: logger.debug( ingo@686: qs[i] + " caused " + (newNumProblems-oldNumProblems) + ingo@686: " new problem(s)."); ingo@686: result.removeNaNs(); ingo@686: } ingo@686: results.add(result); ingo@686: } ingo@686: ingo@686: oldNumProblems = newNumProblems; ingo@686: } ingo@686: ingo@686: return results.toArray(new WQKms[results.size()]); ingo@686: } ingo@686: } ingo@686: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :