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