source: ether_statistics/service/implementation/gov/noaa/pmel/sgt/dm/ThreeDGrid.java @ 569

Last change on this file since 569 was 569, checked in by vmipsl, 12 years ago

Nouveau projet

File size: 14.3 KB
Line 
1/**
2 * $Id: ThreeDGrid.java,v 1.3 2003/02/11 01:47:40 oz Exp $
3 *
4 * This software is provided by NOAA for full, free and open release.  It is
5 * understood by the recipient/user that NOAA assumes no liability for any
6 * errors contained in the code.  Although this software is released without
7 * conditions or restrictions in its use, it is expected that appropriate
8 * credit be given to its author and to the National Oceanic and Atmospheric
9 * Administration should the software be included by the recipient as an
10 * element in other product development.
11 */
12
13package gov.noaa.pmel.sgt.dm;
14
15import gov.noaa.pmel.sgt.SGLabel;
16import gov.noaa.pmel.util.GeoDate;
17import gov.noaa.pmel.util.Range2D;
18import gov.noaa.pmel.util.SoTRange;
19
20import java.beans.PropertyChangeSupport;
21import java.beans.PropertyChangeListener;
22import java.io.Serializable;
23
24/**
25 * <code>ThreeDGrid</code> provides an implementation of the
26 * <code>SGT3DGrid</code> and <code>Cartesian</code> interfaces.
27 *
28 * @author Donald Denbo
29 * @version $Revision: 1.3 $, $Date: 2003/02/11 01:47:40 $
30 * @since 1.0
31 * @see SGTGrid
32 * @see Cartesian
33 */
34public class ThreeDGrid implements SGT3DGrid, Cartesian, Cloneable, Serializable {
35  protected double[] xloc_;
36  protected double[] yloc_;
37  protected double[] zloc_;
38  protected GeoDate[] tloc_;
39  protected double[] grid_;
40  protected double[] xEdges_;
41  protected double[] yEdges_;
42  protected double[] zEdges_;
43  protected GeoDate[] tEdges_;
44  protected boolean hasXEdges_;
45  protected boolean hasYEdges_;
46  protected boolean hasZEdges_;
47  protected String title_;
48  protected SGLabel keyTitle_ = null;
49  protected String id_ = null;
50  protected boolean xTime_;
51  protected boolean yTime_;
52  protected boolean zTime_;
53    /**@shapeType AggregationLink
54  * @clientRole x*/
55    protected SGTMetaData xMetaData_ = null;
56    /**@shapeType AggregationLink
57  * @clientRole y*/
58    protected SGTMetaData yMetaData_ = null;
59    /**@shapeType AggregationLink
60  * @clientRole z*/
61    protected SGTMetaData zMetaData_ = null;
62    /**@shapeType AggregationLink
63  * @clientRole associated data*/
64    protected SGTMetaData valMetaData_ = null;
65    protected SGTGrid associatedData_;
66  private SoTRange xRange_ = null;
67  private SoTRange yRange_ = null;
68  private SoTRange zRange_ = null;
69  private SoTRange xEdgesRange_ = null;
70  private SoTRange yEdgesRange_ = null; 
71  private SoTRange zEdgesRange_ = null;
72  private Range2D valRange_ = null;
73  private PropertyChangeSupport changes_ = new PropertyChangeSupport(this);
74
75  /**
76   * Default constructor.
77   */
78  public ThreeDGrid() {
79    //this(null, (double[])null, (double[])null, (double[])null, "");
80  }
81 
82  /**
83   * Constructor for X, Y, and Z coordinates as double.
84   *
85   * @param grid Z values
86   * @param xloc X coordinates
87   * @param yloc Y coordinates
88   * @param zloc Z coordinates
89   * @param title the title
90   */
91  public ThreeDGrid(double[] grid, double[] xloc,
92                    double[] yloc, double[] zloc, String title) {
93    grid_ = grid;
94    xloc_ = xloc;
95    yloc_ = yloc;
96    zloc_ = zloc;
97    title_ = title;
98    xTime_ = false;
99    yTime_ = false;
100    zTime_ = false;
101    hasXEdges_ = false;
102    hasYEdges_ = false;
103    hasZEdges_ = false;
104    xRange_ = computeSoTRange(xloc);
105    yRange_ = computeSoTRange(yloc);
106    zRange_ = computeSoTRange(yloc);
107    valRange_ = computeRange2D(grid);
108  }
109 
110  /**
111   * Constructor for X time and Y, Z double.
112   *
113   * @param grid values
114   * @param tloc Time coordinates
115   * @param yloc Y coordinates
116   * @param zloc Z coordinates
117   * @param title the title
118   */
119  public ThreeDGrid(double[] grid, GeoDate[] tloc,
120                    double[] yloc, double[] zloc, String title) {
121    grid_ = grid;
122    tloc_ = tloc;
123    yloc_ = yloc;
124    zloc_ = zloc;
125    title_ = title;
126    xTime_ = true;
127    yTime_ = false;
128    zTime_ = false;
129    hasXEdges_ = false;
130    hasYEdges_ = false;
131    hasZEdges_ = false;
132    xRange_ = computeSoTRange(tloc);
133    yRange_ = computeSoTRange(yloc);
134    zRange_ = computeSoTRange(zloc);
135    valRange_ = computeRange2D(grid);
136  }
137  /**
138   * Constructor for X, Z double and Y time.
139   *
140   * @param grid values
141   * @param xloc X coordinates
142   * @param xloc Z coordinates
143   * @param tloc Time coordinates
144   * @param title the title
145   */
146  public ThreeDGrid(double[] grid, double[] xloc,
147                    GeoDate[] tloc,double[] zloc, String title) {
148    grid_ = grid;
149    xloc_ = xloc;
150    tloc_ = tloc;
151    zloc_ = zloc;
152    title_ = title;
153    xTime_ = false;
154    yTime_ = true;
155    zTime_ = false;
156    hasXEdges_ = false;
157    hasYEdges_ = false;
158    hasZEdges_ = false;
159    xRange_ = computeSoTRange(xloc);
160    yRange_ = computeSoTRange(tloc);
161    zRange_ = computeSoTRange(zloc);
162    valRange_ = computeRange2D(grid);
163  }
164 
165  /**
166   * Constructor for X double and Y double, and Z time.
167   *
168   * @param grid Z values
169   * @param xloc X coordinates
170   * @param tloc Time coordinates
171   * @param title the title
172   */
173  public ThreeDGrid(double[] grid, double[] xloc,
174                    double[] yloc, GeoDate[] tloc, String title) {
175    grid_ = grid;
176    xloc_ = xloc;
177    yloc_ = yloc;
178    tloc_ = tloc;
179    title_ = title;
180    xTime_ = false;
181    yTime_ = false;
182    zTime_ = true;
183    hasXEdges_ = false;
184    hasYEdges_ = false;
185    hasZEdges_ = false;
186    xRange_ = computeSoTRange(xloc);
187    yRange_ = computeSoTRange(yloc);
188    zRange_ = computeSoTRange(tloc);
189    valRange_ = computeRange2D(grid);
190  }
191 
192  /**
193   * Create a copy of the grid.
194   *
195   * @since 2.0
196   * @see SGTData
197   */
198  public SGTData copy() {
199    SGT3DGrid newGrid;
200    try {
201      newGrid = (SGT3DGrid)clone();
202    } catch (CloneNotSupportedException e) {
203      newGrid = new ThreeDGrid();
204    }
205    return (SGTData)newGrid;
206  }
207 
208  public double[] getXArray() {
209    return xloc_;
210  }
211 
212  /**
213   * Get the length of the x axis
214   *
215   * @since 2.0
216   */
217  public int getXSize() {
218    return xloc_.length;
219  }
220 
221  public double[] getYArray() {
222    return yloc_;
223  }
224  /**
225   * Get the length of the y axis
226   *
227   * @since 2.0
228   */
229   
230  public int getYSize() {
231    return yloc_.length;
232  }
233 
234  public double[] getZArray() {
235    return zloc_;
236  }
237 
238  public int getZSize() {
239    return zloc_.length;
240  }
241 
242  public double[] getValArray() {
243    return grid_;
244  }
245 
246  public int getValArraySize() {
247    return grid_.length;
248  }
249 
250  public GeoDate[] getTimeArray() {
251    return tloc_;
252  }
253  /**
254   * Get the length of the Time axis
255   *
256   * @since 2.0
257   */
258  public int getTSize() {
259    return tloc_.length;
260  }
261  public boolean isXTime() {
262    return xTime_;
263  }
264  public boolean isYTime() {
265    return yTime_;
266  }
267  public boolean isZTime() {
268    return zTime_;
269  }
270  public void setXTime(boolean flag) {
271    xTime_ = flag;
272  }
273  public void setYTime(boolean flag) {
274    yTime_= flag;
275  }
276  public void setZTime(boolean flag) {
277    zTime_= flag;
278  }
279  public SGTMetaData getXMetaData() {
280    return xMetaData_;
281  }
282  public SGTMetaData getYMetaData() {
283    return yMetaData_;
284  }
285  public SGTMetaData getZMetaData() {
286    return zMetaData_;
287  }
288  public SGTMetaData getValMetaData() {
289    return valMetaData_;
290  }
291  public String getTitle() {
292    return title_;
293  }
294  /**
295   * Set the associated data grid.
296   * <BR><B>Property Change:</B> <code>associatedDataModified</code>.
297   *
298   * @since 2.0
299   */
300  public void setAssociatedData(SGTGrid assoc) {
301    associatedData_ = assoc;
302    changes_.firePropertyChange("associatedDataModified",
303                                null,
304                                assoc);
305  }
306  public SGTGrid getAssociatedData() {
307    return associatedData_;
308  }
309  public boolean hasAssociatedData() {
310    return (associatedData_ != null);
311  }
312  public boolean hasXEdges() {
313    return hasXEdges_;
314  }
315  public double[] getXEdges() {
316    return xEdges_;
317  }
318 
319  public boolean hasZEdges() {
320    return hasZEdges_;
321  }
322  /**
323   * Set the values for the z grid edges.
324   */
325  public void setZEdges(double[] edge) {
326    zEdges_ = edge;
327    hasZEdges_ = true;
328    zEdgesRange_ = computeSoTRange(edge);
329  }
330 
331  public double[] getZEdges() {
332    return zEdges_;
333  }
334  /**
335   * Set the values for the x grid edges.
336   */
337  public void setXEdges(double[] edge) {
338    xEdges_ = edge;
339    hasXEdges_ = true;
340    xEdgesRange_ = computeSoTRange(edge);
341  }
342  public boolean hasYEdges() {
343    return hasYEdges_;
344  }
345  public double[] getYEdges() {
346    return yEdges_;
347  }
348  /**
349   * Set the values for the y grid edges.
350   */
351  public void setYEdges(double[] edge) {
352    yEdges_ = edge;
353    hasYEdges_ = true;
354    yEdgesRange_ = computeSoTRange(edge);
355  }
356  public GeoDate[] getTimeEdges() {
357    return tEdges_;
358  }
359  /**
360   * Set the values for the temporal grid edges.
361   */
362  public void setTimeEdges(GeoDate[] edge) {
363    tEdges_ = edge;
364    if (xTime_) {
365      hasXEdges_ = true;
366      xEdgesRange_ = computeSoTRange(edge);
367    } 
368    else if(yTime_){
369      hasYEdges_ = true;
370      yEdgesRange_ = computeSoTRange(edge);
371    }
372    else if(zTime_){
373      hasZEdges_ = true;
374      zEdgesRange_ = computeSoTRange(edge);
375    }
376  }
377  /**
378   * Set the <code>SGTMetaData</code> associated with the x
379   * coordinate.
380   */
381  public void setXMetaData(SGTMetaData md) {
382    xMetaData_ = md;
383  }
384  /**
385   * Set the <code>SGTMetaData</code> associated with the y
386   * coordinate.
387   */
388  public void setYMetaData(SGTMetaData md) {
389    yMetaData_ = md;
390  }
391  /**
392   * Set the <code>SGTMetaData</code> associated with the z
393   * coordinate.
394   */
395  public void setZMetaData(SGTMetaData md) {
396    zMetaData_ = md;
397  }
398  /**
399   * Set the <code>SGTMetaData</code> associated with the z
400   * coordinate.
401   */
402  public void setValMetaData(SGTMetaData md) {
403    valMetaData_ = md;
404  }
405  /**
406   * Set the grid title
407   */
408  public void setTitle(String title) {
409    title_ = title;
410  }
411  public SGLabel getKeyTitle() {
412    return keyTitle_;
413  }
414  /** Set the title formatted for the <code>VectorKey</code>. */
415  public void setKeyTitle(SGLabel title) {
416    keyTitle_ = title;
417  }
418  /**
419   * Get the unique identifier.  The presence of the identifier
420   * is optional, but if it is present it should be unique.  This
421   * field is used to search for the layer that contains the data.
422   *
423   * @since 2.0
424   * @return unique identifier
425   * @see gov.noaa.pmel.sgt.Pane
426   * @see gov.noaa.pmel.sgt.Layer
427   */
428  public String getId() {
429    return id_;
430  }
431  /**
432   * Set the unique identifier.
433   */
434  public void setId(String ident) {
435    id_ = ident;
436  }
437  /**
438   * Set the x coordinate grid centers
439   * <BR><B>Property Change:</B> <code>dataModified</code>.
440   */
441  public void setXArray(double[] xloc) {
442    xloc_ = xloc;
443    xTime_ = false;
444    xRange_ = computeSoTRange(xloc);
445    changes_.firePropertyChange("dataModified",
446                                new Integer(0),
447                                new Integer(xloc.length));
448  }
449  /**
450   * Set the y coordinate grid centers
451   * <BR><B>Property Change:</B> <code>dataModified</code>.
452   */
453  public void setYArray(double[] yloc) {
454    yloc_ = yloc;
455    yTime_ = false;
456    yRange_ = computeSoTRange(yloc);
457    changes_.firePropertyChange("dataModified",
458                                new Integer(0),
459                                new Integer(yloc.length));
460  }
461  /**
462   * Set the z coordinate grid centers
463   * <BR><B>Property Change:</B> <code>dataModified</code>.
464   */
465  public void setZArray(double[] zloc) {
466    zloc_ = zloc;
467    zTime_ = false;
468    zRange_ = computeSoTRange(zloc);
469    changes_.firePropertyChange("dataModified",
470                                new Integer(0),
471                                new Integer(zloc.length));
472  }
473  /**
474   * Set the z grid values.
475   * <BR><B>Property Change:</B> <code>dataModified</code>.
476   */
477  public void setValArray(double[] grid) {
478    grid_ = grid;
479    valRange_ = computeRange2D(grid);
480    changes_.firePropertyChange("dataModified",
481                                new Integer(0),
482                                new Integer(grid.length));
483  }
484  /**
485   * set the temporal grid centers
486   * <BR><B>Property Change:</B> <code>dataModified</code>.
487   */
488  public void setTimeArray(GeoDate[] tloc) {
489    tloc_ = tloc;
490    if (xTime_) {
491      xRange_ = computeSoTRange(tloc);
492    } 
493    else if(yTime_) {
494      yRange_ = computeSoTRange(tloc);
495    }
496    else if(zTime_) {
497      zRange_ = computeSoTRange(tloc);
498    }
499    changes_.firePropertyChange("dataModified",
500                                new Integer(0),
501                                new Integer(tloc.length));
502  }
503  public SoTRange getXRange() {
504    return xRange_.copy();
505  }
506  public SoTRange getYRange() {
507    return yRange_.copy();
508  }
509  public SoTRange getZRange() {
510    return zRange_.copy();
511  }
512  public Range2D getValRange() {
513    return valRange_;
514  }
515  /**
516   * Return the range of the x edges
517   *
518   * @since 2.0
519   */
520  public SoTRange getXEdgesRange() {
521    return xEdgesRange_;
522  }
523  /**
524   * Return the range of the y edges
525   *
526   * @since 2.0
527   */
528  public SoTRange getYEdgesRange() {
529    return yEdgesRange_;
530  }
531 
532  public SoTRange getZEdgesRange() {
533    return zEdgesRange_;
534  }
535
536  public void addPropertyChangeListener(PropertyChangeListener l) {
537    changes_.addPropertyChangeListener(l);
538  }
539  public void removePropertyChangeListener(PropertyChangeListener l) {
540    changes_.removePropertyChangeListener(l);
541  }
542
543  private SoTRange computeSoTRange(double[] array) {
544    Range2D range = computeRange2D(array);
545    return new SoTRange.Double(range.start, range.end);
546  }
547  private SoTRange computeSoTRange(GeoDate[] tarray) {
548    long start = Long.MAX_VALUE;
549    long end = Long.MIN_VALUE;
550    long value;
551    int count = 0;
552    for(int i=0; i < tarray.length; i++) {
553      if(!(tarray[i] == null || tarray[i].isMissing())) {
554        value = tarray[i].getTime();
555        start = Math.min(start, value);
556        end = Math.max(end, value);
557        count++;
558      }
559    }
560    if(count == 0) {
561      return new SoTRange.GeoDate(new GeoDate(Long.MIN_VALUE),
562                                  new GeoDate(Long.MAX_VALUE));
563    } else {
564      return new SoTRange.GeoDate(new GeoDate(start), new GeoDate(end));
565    }
566  }
567  private Range2D computeRange2D(double[] array) {
568    double start = Double.POSITIVE_INFINITY;
569    double end = Double.NEGATIVE_INFINITY;
570    int count = 0;
571    for(int i=0; i < array.length; i++) {
572      if(!Double.isNaN(array[i])) {
573        start = Math.min(start, array[i]);
574        end = Math.max(end, array[i]);
575        count++;
576      }
577    }
578    if(count == 0) {
579      return new Range2D(Double.NaN, Double.NaN);
580    } else {
581      return new Range2D(start, end);
582    }
583  }
584}
Note: See TracBrowser for help on using the repository browser.