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@708:     protected double    refKm;
sascha@678: 
sascha@678:     public Calculation1() {
sascha@678:     }
sascha@678: 
sascha@678:     public Calculation1(
sascha@742:         double [] kms,
sascha@742:         double [] qs,
sascha@678:         double [] ws,
sascha@738:         double    refKm
sascha@678:     ) {
sascha@708:         this.kms   = kms;
sascha@708:         this.qs    = qs;
sascha@708:         this.ws    = ws;
sascha@708:         this.refKm = refKm;
sascha@678:     }
sascha@678: 
sascha@709:     public CalculationResult calculate(WstValueTable wst) {
sascha@678: 
sascha@678:         ArrayList<WQKms> results = new ArrayList<WQKms>();
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@738:                 wst.interpolate(qs[i], refKm, 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@742:                         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@742: 
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 :