001 package org.wdssii.polarmerger; 002 003 import java.util.Date; 004 005 import org.wdssii.core.DataType; 006 007 /** 008 * The latest observation wins. 009 * 010 * @author lakshman 011 * 012 */ 013 public class LatestObservationMerger implements ObservationMerger { 014 015 private Date[][][] latestTimes; 016 017 public void init(float[][][] values) { 018 if (latestTimes == null || latestTimes.length != values.length 019 || latestTimes[0].length != values[0].length 020 || latestTimes[0][0].length != values[0][0].length) { 021 // each of these is null 022 latestTimes = new Date[values.length][values[0].length][values[0][0].length]; 023 } else { 024 for (int i=0; i < latestTimes.length; ++i){ 025 for (int j=0; j < latestTimes[0].length; ++j){ 026 for (int k=0; k < latestTimes[0][0].length; ++k){ 027 latestTimes[i][j][k] = null; 028 } 029 } 030 } 031 } 032 } 033 034 public void update(float[][][] values, int w_e, int w_az, int w_rn, Observation obs, float wt) { 035 Date current = latestTimes[w_e][w_az][w_rn]; 036 if (current == null || obs.getTime().after(current)){ 037 latestTimes[w_e][w_az][w_rn] = obs.getTime(); 038 values[w_e][w_az][w_rn] = obs.getValue(); 039 } 040 } 041 042 public void finishComputation(float[][][] values) { 043 for (int i=0; i < latestTimes.length; ++i){ 044 for (int j=0; j < latestTimes[0].length; ++j){ 045 for (int k=0; k < latestTimes[0][0].length; ++k){ 046 if (latestTimes[i][j][k] == null){ 047 values[i][j][k] = DataType.MissingData; 048 } 049 } 050 } 051 } 052 } 053 054 055 }