source: ether_megapoli/trunk/applets/src/gov/noaa/pmel/sgt/dm/SimpleGrid.java @ 191

Last change on this file since 191 was 191, checked in by vmipsl, 13 years ago

Servlet _ Contour en cours

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