Changeset 194
- Timestamp:
- 09/13/11 16:18:53 (13 years ago)
- Location:
- ether_megapoli/trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
ether_megapoli/trunk/domain/interface/com/ether/AxeTypeForMobilePlateform.java
r171 r194 4 4 { 5 5 D2_POINTS, 6 D2_CONTOUR,7 6 } -
ether_megapoli/trunk/persistence/implementation/com/ether/dao/ValueDAOImpl.java
r191 r194 87 87 criteria.addOrder( Order.asc( "localisation.localisationLon" ) ); 88 88 89 // final List<Object[]> objects = selectAllByCriteria( Object[].class, criteria ); 90 // TODO : remove maxResults to 10 91 final List<Object[]> objects = selectPage( null, 100, criteria ); 89 final List<Object[]> objects = selectAllByCriteria( Object[].class, criteria ); 92 90 93 91 final double[] latitudeValues = new double[objects.size()]; … … 131 129 criteria.addOrder( Order.asc( "localisation.localisationLon" ) ); 132 130 133 // final List<Object[]> objects = selectAllByCriteria( Object[].class, criteria ); 134 // TODO : remove maxResults to 10 135 final List<Object[]> objects = selectPage( null, 100, criteria ); 131 final List<Object[]> objects = selectAllByCriteria( Object[].class, criteria ); 136 132 137 133 final List<Double> latitudeValues = new ArrayList<Double>( objects.size() ); … … 169 165 return count( criteria ); 170 166 } 171 172 // @NotNull173 // public Integer getNumberValuesByPlateformByParameterByPeriod( @NotNull final List<Pair> pairs, @Nullable final Date beginDate, @Nullable final Date endDate )174 // throws PersistenceException175 // {176 // final DetachedCriteria criteria = DetachedCriteria.forClass( Valeur.class, "value" )177 // .add( Restrictions.eq( "value.parametre.id", parameterId ) )178 // .createCriteria( "mesure", "measure" )179 // .add( Restrictions.eq( "measure.plateforme.id", plateformId ) );180 //181 // if( null != beginDate )182 // criteria.add( Restrictions.ge( "measure.mesureDate", beginDate ) );183 // if( null != endDate )184 // criteria.add( Restrictions.le( "measure.mesureDate", endDate ) );185 //186 // criteria.setProjection( Projections.property( "value.valeurVal" ) );187 //188 // return count( criteria );189 // }190 191 167 } -
ether_megapoli/trunk/persistence/interface/com/ether/dao/ValueDAO.java
r191 r194 2 2 3 3 import com.ether.Data; 4 import com.ether.Pair;5 4 import com.ether.PersistenceException; 6 5 import com.medias.database.objects.Valeur; … … 33 32 Integer getNumberValuesByPlateformByParameterByPeriod( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date beginDate, @Nullable final Date endDate ) 34 33 throws PersistenceException; 35 36 // @NotNull37 // Integer getNumberValuesByPlateformByParameterByPeriod( @NotNull final List<Pair> pairs, @Nullable final Date beginDate, @Nullable final Date endDate )38 // throws PersistenceException;39 34 } -
ether_megapoli/trunk/service/implementation/com/ether/BouchonHelper.java
r191 r194 12 12 import java.util.Calendar; 13 13 import java.util.Date; 14 import java.util.GregorianCalendar; 14 15 import java.util.List; 16 import java.util.SimpleTimeZone; 17 import java.util.TimeZone; 15 18 16 19 public class BouchonHelper … … 259 262 final double[] values = new double[size]; 260 263 final Date[] dates = new Date[size]; 261 final Calendar cal = Calendar.getInstance(); 264 // final Calendar cal = Calendar.getInstance( new SimpleTimeZone( 0, "GMT" ) ); 265 final Calendar cal = new GregorianCalendar( TimeZone.getTimeZone( "GMT" )); 266 cal.setTimeInMillis( Long.valueOf( "1246811160000" ) ); 262 267 263 268 for( int i = 0; i < size; i++ ) 264 269 { 270 dates[i] = cal.getTime(); 265 271 values[i] = (double) i * Math.random() * delta; 266 cal.set( Calendar.MINUTE, (int) ( 2 + i + ( Math.random() * 8 ) ) );267 dates[i] = cal.getTime();272 // cal.add( Calendar.MINUTE, (int) ( 2 + i + ( Math.random() * 8 ) ) ); 273 cal.add( Calendar.HOUR, (int) ( 2 * i + 2 ) ); 268 274 } 269 275 return new Data( values, dates ); -
ether_megapoli/trunk/service/implementation/com/ether/EtherPlotContentServiceImpl.java
r191 r194 197 197 * Create a test grid with sinasoidal-ramp data. 198 198 */ 199 // Range2D xr = new Range2D( 190.0f, 250.0f, 1.0f );200 // Range2D yr = new Range2D( 0.0f, 45.0f, 1.0f );201 199 Range2D xr = new Range2D( 190.0f, 200.0f, 1.0f ); 202 200 Range2D yr = new Range2D( 0.0f, 4.0f, 1.0f ); … … 221 219 axis2[count] = yr.start + count * yr.delta; 222 220 223 // final double[] valuesOrigPetites = getValues( axis1, num1, axis2, 2, TestData.SINE_RAMP, 12.0f, 30.f, 5.0f );224 // final double[] valuesOrigPetites = getValues( longitudeValues, longitudeValues.length, latitudeValues, latitudeValues.length, TestData.SINE_RAMP, 12.0f, 30.f, 5.0f );225 226 // final double[] valuesOrig = new double[num1 * num2];227 // for( int count = 0; count < valuesOrigPetites.length; count++ )228 // {229 // valuesOrig[count] = valuesOrigPetites[count];230 // }231 // for( int count = valuesOrigPetites.length; count < num1 * num2; count++ )232 // {233 // valuesOrig[count] = Double.NaN;234 // }235 236 221 final double[] parameterValuesArray = EtherHelper.convertListDoubleToDoubleArray( parameterValues ); 237 final double[] parameterValuesMap = new double[latitudeValues.size() * longitudeValues.size()]; 238 for( int i = 0; i < parameterValuesArray.length; i++ ) 239 parameterValuesMap[i] = parameterValuesArray[i]; 240 241 for( int i = parameterValuesArray.length; i < latitudeValues.size() * longitudeValues.size(); i++ ) 242 parameterValuesMap[i] = Double.NaN; 222 // final double[] parameterValuesMap = new double[latitudeValues.size() * longitudeValues.size()]; 223 224 // for( int i = 0; i < parameterValuesArray.length; i++ ) 225 // parameterValuesMap[i] = parameterValuesArray[i]; 226 227 // for( int i = parameterValuesArray.length; i < latitudeValues.size() * longitudeValues.size(); i++ ) 228 // parameterValuesMap[i] = Double.NaN; 243 229 244 230 SGLabel keyLabel = new SGLabel( "Key Label", "", new Point2D.Double( 0.0, 0.0 ) ); … … 251 237 xMeta = new SGTMetaData( bundle.getString( "plot.longitude" ), bundle.getString( "plot.degres" ) ); 252 238 yMeta = new SGTMetaData( bundle.getString( "plot.latitude" ), bundle.getString( "plot.degres" ) ); 253 // final SimpleGrid sg = new SimpleGrid( valuesOrig, axis1, axis2, "Test Series" );254 // simpleGrid = new SimpleGrid( parameterValues, longitudeValues, latitudeValues, "Test Series" );255 // simpleGrid = new SimpleGrid( valuesOrig, longitudeValues, latitudeValues, "Test Series" );256 // simpleGrid = new SimpleGrid( valuesOrig, axis1, axis2, "Test Series" );257 239 258 240 final double[] longitudeValuesArray = EtherHelper.convertListDoubleToDoubleArray( longitudeValues ); 259 241 final double[] latitudeValuesArray = EtherHelper.convertListDoubleToDoubleArray( latitudeValues ); 260 simpleGrid = new SimpleGrid( parameterValues Map, longitudeValuesArray, latitudeValuesArray, "Test Series" );242 simpleGrid = new SimpleGrid( parameterValuesArray, longitudeValuesArray, latitudeValuesArray, "Test Series" ); 261 243 262 244 simpleGrid.setXMetaData( xMeta ); … … 275 257 final ContourLevels clevels = ContourLevels.getDefault( datar ); 276 258 final ColorMap cmap = createColorMap( datar ); 277 278 // final Range2D datarOrig = new Range2D( 5f, 10.0f, 1f );279 // final ContourLevels clevelsOrig = ContourLevels.getDefault( datarOrig );280 // final ColorMap cmapOrig = createColorMap( datarOrig );281 // final GridAttribute gridAttributeOrig = new GridAttribute( clevelsOrig );282 // gridAttributeOrig.setColorMap( cmapOrig );283 // gridAttributeOrig.setStyle( GridAttribute.RASTER_CONTOUR );284 285 259 286 260 // Create a grid for contour data … … 550 524 551 525 // final Data valuesLists = _etherService.getListsByPlateformByParameterByPeriodForTimeSerie( plateformId, parameterId, beginDate, endDate ); 552 final Data valuesLists = BouchonHelper.createValuesForTimeSerie( 50, delta );526 final Data valuesLists = BouchonHelper.createValuesForTimeSerie( 2, delta ); 553 527 554 528 final double[] dataArray = (double[]) valuesLists.getFirstArray(); -
ether_megapoli/trunk/service/implementation/com/ether/EtherServiceImpl.java
r191 r194 117 117 } 118 118 119 120 119 @NotNull 121 120 @Transactional(readOnly = true) -
ether_megapoli/trunk/service/implementation/gov/noaa/pmel/sgt/GridCartesianRenderer.java
r192 r194 285 285 final PointAttribute pointAttribute = new PointAttribute(); 286 286 PlotMark pm = new PlotMark( pointAttribute ); 287 pm.setMark( 51 ); 287 288 pm.setMarkHeightP( 0.2 ); 288 289 … … 295 296 * method. 296 297 * 297 * @see CartesianRenderer#getRenderer298 298 * @see Graph 299 299 */ … … 309 309 * method. 310 310 * 311 * @see CartesianRenderer#getRenderer312 311 * @see Graph 313 312 */ … … 323 322 * method. 324 323 * 325 * @see CartesianRenderer#getRenderer326 324 * @see Graph 327 325 */ -
ether_megapoli/trunk/service/implementation/gov/noaa/pmel/util/GeoDate.java
r192 r194 13 13 package gov.noaa.pmel.util; 14 14 15 import java.util.Date; 16 import java.util.Calendar; 17 import java.util.GregorianCalendar; 18 import java.util.TimeZone; 19 20 import java.text.DateFormat; 21 import java.text.SimpleDateFormat; 22 import java.text.ParsePosition; 15 import java.text.DateFormat; 16 import java.text.ParsePosition; 17 import java.text.SimpleDateFormat; 18 import java.util.Calendar; 19 import java.util.Date; 20 import java.util.GregorianCalendar; 21 import java.util.TimeZone; 23 22 24 23 /** … … 32 31 * representations of time. 33 32 * 34 * @see GregorianCalendar35 *36 33 * @author Donald Denbo 37 34 * @version $Revision: 1.17 $, $Date: 2003/08/22 23:02:40 $ 35 * @see GregorianCalendar 38 36 * @since sgt 1.0 39 37 */ 40 public class GeoDate extends java.util.Date implements java.io.Serializable { 41 private int max_day_[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 42 private boolean splitDone_; 43 private int yearday_; 44 private int dayofweek_; 45 private int year_; 46 private int month_; 47 private int day_; 48 private int hour_; 49 private int minute_; 50 private int second_; 51 private int msec_; 52 private int MSec_; 53 private int JDay_; 54 private boolean EPICTimeDone_; 55 private boolean relativeTime_ = false; 56 private static Calendar cal_ = new GregorianCalendar(TimeZone.getTimeZone("GMT")); 57 /** Increment or decrement in days. */ 58 public static final int DAYS = 1; 59 /** Increment or decrement in months. */ 60 public static final int MONTHS = 2; 61 /** Increment or decrement in years. */ 62 public static final int YEARS = 4; 63 /** Increment or decrement in hours. */ 64 public static final int HOURS = 5; 65 /** Increment or decrement in minutes */ 66 public static final int MINUTES = 6; 67 /** Increment or decrement in seonds */ 68 public static final int SECONDS = 7; 69 /** Increment or decrement in milliseconds */ 70 public static final int MSEC = 8; 71 /** Number of milliseconds in a day. */ 72 public static final long MSECS_IN_DAY = 86400000; 73 /** Construct a new <code>GeoDate</code>. */ 74 public GeoDate() { 75 super(); 76 } 77 /** 78 * Construct a new <code>GeoDate</code> from a 79 * <code>String</code>. Formatting is done using 80 * <code>SimpleDateFormat</code>. The specified time 81 * is taken to be "GMT". 82 * 83 * @param time character representation of time 84 * @param format codes used to read time 85 */ 86 public GeoDate(String time,String format) throws IllegalTimeValue { 87 super(); 88 ParsePosition pos = new ParsePosition(0); 89 DateFormat df = new SimpleDateFormat(format); 90 df.setCalendar(cal_); 91 92 Date dte = df.parse(time, pos); 93 if(dte == null) { 94 throw new IllegalTimeValue("Parse error: " + time + ", " + format); 95 } 96 setTime(dte.getTime()); 97 } 98 /** 99 * Constructs a new <code>GeoDate</code> from an 100 * existing <code>GeoDate</code>. 101 * 102 * @param t <code>GeoDate</code> 103 */ 104 public GeoDate(GeoDate t) { 105 super(t.getTime()); 106 } 107 /** 108 * Construct a new <code>GeoDate</code> from values. The 109 * specified time is taken to be "GMT". 110 * 111 * @param mon month 112 * @param day day of the month 113 * @param year year (no offset!) 114 * @param hour hour 115 * @param min minutes 116 * @param sec seconds 117 * @param msec milliseconds 118 * @exception IllegalTimeValue The constructor was called with a set 119 * of parameters that does not constitute a legitimate time value. 120 */ 121 public GeoDate(int mon,int day,int year,int hour,int min,int sec,int msec) throws IllegalTimeValue { 122 this.set(mon, day, year, hour, min, sec, msec); 123 } 124 /** 125 * Construct a new <code>GeoDate</code> from a 126 * <code>Date</code> object. No time zone conversion 127 * is done. 128 * 129 * @param date Date object 130 */ 131 public GeoDate(Date date) { 132 setTime(date.getTime()); 133 } 134 /** 135 * Construct a new <code>GeoDate</code> from EPIC double integers. 136 * Time zone for conversion is "GMT". 137 * 138 * @param jday julian day 139 * @param msec milliseconds since midnight 140 */ 141 public GeoDate(int jday, int msec) { 142 set(jday, msec); 143 } 144 145 /** 146 * Allocates a GeoDate object and initializes it to represent 147 * the specified number of milliseconds since the standard 148 * base time know as "the epoch", namely January 1, 1970, 00:00:00 149 * GMT. 150 */ 151 public GeoDate(long date) { 152 setTime(date); 153 } 154 /** 155 * Set the relativeTime flag. The relativeTime flag indicates that 156 * the <code>GeoDate</code> object does not represent an actual 157 * absolute time, but a temporal duration. 158 */ 159 public void setRelativeTime(boolean relative) { 160 relativeTime_ = relative; 161 } 162 /** 163 * Tests the relativeTime flag. 164 * 165 * @return if true, time is a duration 166 */ 167 public boolean isRelativeTime() { 168 return relativeTime_; 169 } 170 /** 171 * Change value of <code>GeoDate</code> from EPIC double 172 * integers. 173 * Time zone for conversion is "GMT". 174 * 175 * @param jday julian day 176 * @param msec milliseconds since midnight 177 */ 178 public void set(int jday, int msec) { 179 int ja, jb, jc, jd, je; 180 double jalpha, second; 181 int day, month, year, hour, minute, sec; 182 183 if(jday > 2299161) { 184 jalpha = ((double)(jday - 1867216)-0.25)/36524.25; 185 ja = jday + 1 + (int)jalpha - (int)(0.25*jalpha); 186 } else { 187 ja = jday; 188 } 189 jb = ja + 1524; 190 jc = (int)(6680.0 + ((double)(jb - 2439870) - 122.1)/365.25); 191 jd = (int)(365*jc + (0.25*jc)); 192 je = (int)((jb - jd)/30.6001); 193 194 day = (int)(jb - jd) - (int)(30.6001*je); 195 month = (int)(je - 1); 196 if(month > 12) month -= 12; 197 year = (int)(jc - 4715); 198 if(month > 2) --year; 199 if(year <= 0) --year; 200 ja = msec/1000; 201 hour = (int)(ja/3600); 202 minute = (int)((ja - hour*3600)/60); 203 second = (double)(msec - (hour*3600 + minute*60)*1000)/1000.0; 204 sec = (int)second; 205 msec = ((int)(second*1000.0))%1000; 206 try{ 207 set(month, day, year, hour, minute, sec, msec); 208 } catch (IllegalTimeValue e) {} 209 } 210 /** 211 * Change value of <code>GeoDate</code> from values. 212 * Time zone for conversion is "GMT". 213 * 214 * @param mon month (1=January, 12=December) 215 * @param day day of the month 216 * @param year year (no offset!) 217 * @param hour hour 218 * @param min minutes 219 * @param sec seconds 220 * @param msec milliseconds 221 * @exception IllegalTimeValue The parameters passed to this method represent a time 222 * value that is invalid 223 * 224 */ 225 public void set(int mon,int day,int year,int hour,int min,int sec,int msec) throws IllegalTimeValue { 226 int jy, jm, ja, jul; 227 int leap = (year%4 != 0? 0: (year%400 == 0? 1: (year%100==0? 0: 1))); 228 max_day_[1] = 28 + leap; 229 230 if(mon > 12 || mon < 1) { 231 this.setTime(0); 232 throw new IllegalTimeValue("value of month out of range"); 233 } 234 if(day > max_day_[mon-1] || day < 1) { 235 this.setTime(0); 236 throw new IllegalTimeValue("value of day out of range"); 237 } 238 if(hour >= 24 || hour < 0) { 239 this.setTime(0); 240 throw new IllegalTimeValue("value of hour out of range"); 241 } 242 if(min >= 60 || min < 0) { 243 this.setTime(0); 244 throw new IllegalTimeValue("value of minute out of range"); 245 } 246 if(sec >= 60 || sec < 0) { 247 this.setTime(0); 248 throw new IllegalTimeValue("value of second out of range"); 249 } 250 if(msec >= 1000 || msec < 0) { 251 this.setTime(0); 252 throw new IllegalTimeValue("value of msec out of range"); 253 } 254 255 cal_.clear(); 256 cal_.set(year, mon - 1, day, hour, min, sec); 257 258 // this.setTime(cal.getTimeInMillis() + msec); 259 this.setTime((cal_.getTime()).getTime() + msec); 260 splitDone_ = false; 261 EPICTimeDone_ = false; 262 } 263 /** 264 * Get the number of days in the current month. 265 * 266 * @return number of days in current month 267 **/ 268 public int getDaysInMonth() { 269 int leap; 270 int year = cal_.get(Calendar.YEAR); 271 leap = (year%4 != 0? 0: (year%400 == 0? 1: (year%100==0? 0: 1))); 272 max_day_[1] = 28 + leap; 273 return max_day_[month_-1]; 274 } 275 /** 276 * Set to current time. 277 */ 278 public void now() { 279 Date nw = new Date(); 280 this.setTime(nw.getTime()); 281 } 282 /** 283 * Add time to current <code>GeoDate</code>. This operation only 284 * makes since if <code>time</code> is a relative time value, 285 * i.e. the result of a 286 * <code>GeoDate</code> subrtraction. 287 * 288 * @param time <code>GeoDate</code> 289 * @return new <code>GeoDate</code> 290 */ 291 public GeoDate add(GeoDate time) { 292 GeoDate time2 = new GeoDate(); 293 long MSec = getTime() + time.getTime(); 294 295 time2.splitDone_ = false; 296 time2.EPICTimeDone_ = false; 297 time2.setTime(MSec); 298 return time2; 299 } 300 /** 301 * Subtract time2 from current <code>GeoDate</code>. 302 * 303 * @param time2 subtracthend 304 * @return new <code>GeoDate</code> 305 */ 306 public GeoDate subtract(GeoDate time2) { 307 GeoDate delta = new GeoDate(); 308 long MSec = getTime() - time2.getTime(); 309 310 delta.splitDone_ = false; 311 delta.EPICTimeDone_ = false; 312 delta.setTime(MSec); 313 delta.setRelativeTime(true); 314 return delta; 315 } 316 /** 317 * Divide by value. Current time should the result of adding two times or 318 * subtracting two times to be a meaningful calculation. 319 * 320 * @param val divisor 321 * @return new <code>GeoDate</code> 322 */ 323 public GeoDate divide(double val) { 324 GeoDate result = new GeoDate(); 325 326 if(val == 0.0) return null; 327 328 result.setTime((long)(((double)getTime())/val)); 329 330 result.splitDone_ = false; 331 result.EPICTimeDone_ = false; 332 result.setRelativeTime(true); 333 return result; 334 } 335 void splitTimeFormat() { 336 int ja, jb, jc, jd, je; 337 double jalpha; 338 GeoDate gt; 339 340 if(splitDone_) return; 341 342 cal_.setTime(this); 343 day_ = cal_.get(Calendar.DAY_OF_MONTH); 344 month_ = cal_.get(Calendar.MONTH) + 1; 345 year_ = cal_.get(Calendar.YEAR); 346 hour_ = cal_.get(Calendar.HOUR_OF_DAY); 347 minute_ = cal_.get(Calendar.MINUTE); 348 second_ = cal_.get(Calendar.SECOND); 349 msec_ = cal_.get(Calendar.MILLISECOND); 350 dayofweek_ = cal_.get(Calendar.DAY_OF_WEEK) - 1; 351 yearday_ = cal_.get(Calendar.DAY_OF_YEAR); 352 353 splitDone_ = true; 354 } 355 /** 356 * Increment current <code>GeoDate</code> 357 * by <code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, 358 * <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code> 359 * 360 * @param val amount to increment 361 * @param tu time units (<code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code>) 362 * operation. 363 */ 364 public GeoDate increment(float val,int tu) { 365 return increment((double)val, tu); 366 } 367 /** 368 * Increment current <code>GeoDate</code> 369 * by <code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, 370 * <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code> 371 * 372 * @param val amount to increment 373 * @param tu time units (<code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code>) 374 * operation. 375 */ 376 public GeoDate increment(double val,int tu) { 377 int leap; 378 int ival = (int)val; 379 double fract = (val - ival); 380 long MSec = getTime(); 381 switch(tu) { 382 case MSEC: 383 MSec += (long)val; 384 setTime(MSec); 385 break; 386 case SECONDS: 387 MSec += (long)(val*1000); 388 setTime(MSec); 389 break; 390 case MINUTES: 391 MSec += (long)(val*60000); 392 setTime(MSec); 393 break; 394 case HOURS: 395 MSec += (long)(val*3600000); 396 setTime(MSec); 397 break; 398 case DAYS: // days and fraction days 399 MSec += (long)(val*MSECS_IN_DAY); 400 setTime(MSec); 401 break; 402 case MONTHS: // nearest day 403 splitTimeFormat(); 404 month_ += ival; 405 year_ += ((month_-1)/12); 406 month_ -= ((month_-1)/12)*12; 407 if(month_ == 0) month_ = 1; 408 leap = (year_%4 != 0? 0: (year_%400 == 0? 1: (year_%100==0? 0: 1))); 409 max_day_[1] = 28 + leap; 410 day_ += (int)(fract*max_day_[month_-1]); 411 if(day_ > max_day_[month_-1]) { 412 day_ -= max_day_[month_-1]; 413 month_++; 414 year_ += ((month_-1)/12); 415 month_ -= ((month_-1)/12)*12; 416 if(month_ == 0) month_ =1; 417 } 418 try { 419 this.set(month_, day_, year_, hour_, minute_, second_, msec_); 420 } catch (IllegalTimeValue e) { 421 System.err.println(e); 422 } 423 break; 424 case YEARS: // nearest day 425 splitTimeFormat(); 426 year_ += ival; 427 leap = (year_%4 != 0? 0: (year_%400 == 0? 1: (year_%100==0? 0: 1))); 428 max_day_[1] = 28 + leap; 429 if(day_ > max_day_[month_-1]) day_ = max_day_[month_-1]; 430 try { 431 this.set(month_, day_, year_, hour_, minute_, second_, msec_); 432 } catch (IllegalTimeValue e) { 433 System.err.println(e); 434 } 435 setTime(getTime() + (long)(fract*365.25)*MSECS_IN_DAY); 436 break; 437 } 438 splitDone_ = false; 439 EPICTimeDone_ = false; 440 return this; 441 } 442 /** 443 * Decrement current <code>GeoDate</code> 444 * by <code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, 445 * <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code> 446 * 447 * @param val amount to decrement 448 * @param tu time units (<code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code>) 449 * operation. 450 */ 451 public GeoDate decrement(float val,int tu) { 452 return decrement((double)val, tu); 453 } 454 /** 455 * Decrement current <code>GeoDate</code> 456 * by <code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, 457 * <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code> 458 * 459 * @param val amount to decrement 460 * @param tu time units (<code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code>) 461 * operation. 462 */ 463 public GeoDate decrement(double val,int tu) { 464 int leap; 465 int ival = (int)val; 466 double fract = (val - ival); 467 long MSec = getTime(); 468 469 switch(tu) { 470 case MSEC: 471 MSec -= (long)val; 472 setTime(MSec); 473 break; 474 case SECONDS: 475 MSec -= (long)(val*1000); 476 setTime(MSec); 477 break; 478 case MINUTES: 479 MSec -= (long)(val*60000); 480 setTime(MSec); 481 break; 482 case HOURS: 483 MSec -= (long)(val*3600000); 484 setTime(MSec); 485 break; 486 case DAYS: 487 MSec -= (long)(val*MSECS_IN_DAY); 488 setTime(MSec); 489 break; 490 case MONTHS: 491 splitTimeFormat(); 492 month_ -= ival; 493 if(month_ <= 0) { 494 year_ -= (month_-1)/12 + 1; 495 month_ += ((month_-1)/12)*12 + 12; 496 } 497 if(month_ == 0) month_ = 12; 498 leap = (year_%4 != 0? 0: (year_%400 == 0? 1: (year_%100==0? 0: 1))); 499 max_day_[1] = 28 + leap; 500 day_ -= (int)(fract*max_day_[month_-1]); 501 if(day_ > max_day_[month_-1]) { 502 day_ -= max_day_[month_-1]; 503 month_--; 504 if(month_ <= 0) { 505 year_ -= (month_-1)/12 + 1; 506 month_ += ((month_-1)/12)*12; 507 } 508 if(month_ == 0) month_ = 12; 509 } 510 try { 511 this.set(month_, day_, year_, hour_, minute_, second_, msec_); 512 } catch (IllegalTimeValue e) { 513 System.err.println(e); 514 } 515 break; 516 case YEARS: 517 splitTimeFormat(); 518 year_ -= ival; 519 leap = (year_%4 != 0? 0: (year_%400 == 0? 1: (year_%100==0? 0: 1))); 520 max_day_[1] = 28 + leap; 521 if(day_ > max_day_[month_-1]) day_ = max_day_[month_-1]; 522 try { 523 this.set(month_, day_, year_, hour_, minute_, second_, msec_); 524 } catch (IllegalTimeValue e) { 525 System.err.println(e); 526 } 527 setTime(getTime() - (long)(fract*365.25)*MSECS_IN_DAY); 528 break; 529 } 530 splitDone_ = false; 531 EPICTimeDone_ = false; 532 return this; 533 } 534 /** 535 * Time offset from reference <code>GeoDate</code> 536 * 537 * @param ref reference <code>GeoDate</code> 538 * @return offset in days 539 */ 540 public double offset(GeoDate ref) { 541 double val; 542 val = ((double)(this.getTime() - ref.getTime()))/86400000.0; 543 return val; 544 } 545 /** 546 * Set a <code>GeoDate</code> from year and year-day. 547 * 548 * @param year year 549 * @param yearday year-day number (Jan 1 = 1) 550 * parameters that does not constitute a legitimate time value. 551 */ 552 public void setYearYearDay(int year,int yearday) { 553 try { 554 this.set(1, 1, year, 0, 0, 0, 0); 555 } catch (IllegalTimeValue e) { 556 System.err.println(e); 557 } 558 setTime(getTime() + (yearday - 1)*MSECS_IN_DAY); 559 } 560 /** 561 * Get a reference to the <code>GregorianCalendar</code> set 562 * to the current <code>GeoDate</code> time. 563 * 564 * @return <code>Calendar</code> 565 */ 566 public Calendar getCalendar() { 567 cal_.setTime(this); 568 return cal_; 569 } 570 /** 571 * Get year-day number (Jan 1 = 1) 572 */ 573 public int getYearday() { 574 splitTimeFormat(); 575 return yearday_; 576 } 577 /** 578 * Get year 579 * 580 * @deprecated Overrides a deprecated method, replaced by {@link #getGMTYear}. 581 */ 582 public int getYear() { 583 splitTimeFormat(); 584 return year_; 585 } 586 /** 587 * Get year. 588 */ 589 public int getGMTYear() { 590 splitTimeFormat(); 591 return year_; 592 } 593 /** 594 * Get month 595 * 596 * @deprecated Overrides a deprecated method, replaced by {@link #getGMTMonth}. 597 */ 598 public int getMonth() { 599 splitTimeFormat(); 600 return month_; 601 } 602 /** 603 * Get month 604 */ 605 public int getGMTMonth() { 606 splitTimeFormat(); 607 return month_; 608 } 609 /** 610 * Get day 611 * 612 * @deprecated Overrides a deprecated method, replaced by {@link #getGMTDay}. 613 */ 614 public int getDay() { 615 splitTimeFormat(); 616 return day_; 617 } 618 /** 619 * Get day 620 */ 621 public int getGMTDay() { 622 splitTimeFormat(); 623 return day_; 624 } 625 /** 626 * Get hours 627 * 628 * @deprecated Overrides a deprecated method, replaced by {@link #getGMTHours}. 629 */ 630 public int getHours() { 631 splitTimeFormat(); 632 return hour_; 633 } 634 /** 635 * Get hours 636 */ 637 public int getGMTHours() { 638 splitTimeFormat(); 639 return hour_; 640 } 641 /** 642 * Get minutes 643 * 644 * @deprecated Overrides a deprecated method, replaced by {@link #getGMTMinutes}. 645 */ 646 public int getMinutes() { 647 splitTimeFormat(); 648 return minute_; 649 } 650 /** 651 * Get minutes 652 */ 653 public int getGMTMinutes() { 654 splitTimeFormat(); 655 return minute_; 656 } 657 /** 658 * Get secondss 659 * @deprecated replaced by {@link #getGMTSeconds}. 660 */ 661 public double getSecondss() { 662 splitTimeFormat(); 663 return second_; 664 } 665 /** 666 * Get seconds and fraction of seconds. 667 */ 668 public double getGMTSeconds() { 669 splitTimeFormat(); 670 return second_; 671 } 672 /** 673 * get EPIC Julian Day 674 */ 675 public int getJDay() { 676 splitTimeFormat(); 677 computeEPICTime(); 678 return JDay_; 679 } 680 /** 681 * get milliseconds since midnight 682 */ 683 public int getMSec() { 684 splitTimeFormat(); 685 computeEPICTime(); 686 return MSec_; 687 } 688 689 private void computeEPICTime() { 690 if(EPICTimeDone_) return; 691 int GREGORIAN__ = (15+31*(10+12*1582)); 692 int jy, jm, ja, jul; 693 int year = year_; 694 int mon = month_; 695 int day = day_; 696 int hour = hour_; 697 int min = minute_; 698 int sec = second_; 699 int msec = msec_; 700 701 int leap = (year%4 != 0? 0: (year%400 == 0? 1: (year%100==0? 0: 1))); 702 703 if(year < 0) ++year; 704 if(mon > 2) { 705 jy = year; 706 jm = mon + 1; 707 } else { 708 jy = year - 1; 709 jm = mon + 13; 710 } 711 jul = (int)(Math.floor(365.25*jy)+Math.floor(30.6001*jm)+day+1720995); 712 if(day + 31L*(mon+12L*year) >= GREGORIAN__) { 713 ja = (int)(0.01*jy); 714 jul += 2 - ja + (int)(0.25*ja); 715 } 716 717 JDay_ = jul; 718 MSec_ = (int)((hour*3600L+min*60L)*1000L+sec*1000L+msec); 719 720 EPICTimeDone_ = true; 721 } 722 /** 723 * Convert <code>GeoDate</code> to <code>String</code> 724 * using standard format "yyyy-MM-dd HH:mm:ss z" 725 * and "GMT" time zone. 726 * 727 * @return date 728 */ 729 public String toString() { 730 DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); 731 df.setCalendar(cal_); 732 return df.format(this); 733 } 734 /** 735 * Convert <code>GeoDate</code> to <code>String</code> 736 * using provided format. The <code>SimpleDateFormat</code> 737 * and the <code>GregorianCalendar</code> is used to format 738 * the <code>GeoDate</code>. A format of "decade" will create 739 * a string of the form 1990 or 1980. 740 * 741 * @see SimpleDateFormat 742 * 743 * @param format String containing codes used to write time. 744 */ 745 public String toString(String format) { 746 if(format.equals("decade")) { 747 splitTimeFormat(); 748 return Integer.toString((year_/10)*10); 749 } else { 750 DateFormat df = new SimpleDateFormat(format); 751 df.setCalendar(cal_); 752 return df.format(this); 753 } 754 } 755 /** 756 * Tests to see if value represents missing data. A value from the 757 * getTime() method of <code>Long.MIN_VALUE</code> represents a 758 * missing observation. 759 * 760 * @see gov.noaa.pmel.sgt.dm.SGTData#getXRange() 761 */ 762 public boolean isMissing() { 763 return getTime() == Long.MIN_VALUE; 764 } 765 /** 766 * Tests to see if the current GeoDate is less than, equal, or greater than. 767 * another GeoDate 768 */ 769 public int compareTo(GeoDate anotherDate) { 770 if (this.getTime() < anotherDate.getTime()) 771 return -1; 772 else if (this.getTime() == anotherDate.getTime()) 773 return 0; 774 else 775 return 1; 776 } 38 public class GeoDate 39 extends java.util.Date 40 implements java.io.Serializable 41 { 42 private int max_day_[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 43 private boolean splitDone_; 44 private int yearday_; 45 private int dayofweek_; 46 private int year_; 47 private int month_; 48 private int day_; 49 private int hour_; 50 private int minute_; 51 private int second_; 52 private int msec_; 53 private int MSec_; 54 private int JDay_; 55 private boolean EPICTimeDone_; 56 private boolean relativeTime_ = false; 57 // private static Calendar cal_ = new GregorianCalendar(TimeZone.getTimeZone("GMT")); 58 // VMIPSL 59 private static Calendar cal_ = Calendar.getInstance(); 60 /** 61 * Increment or decrement in days. 62 */ 63 public static final int DAYS = 1; 64 /** 65 * Increment or decrement in months. 66 */ 67 public static final int MONTHS = 2; 68 /** 69 * Increment or decrement in years. 70 */ 71 public static final int YEARS = 4; 72 /** 73 * Increment or decrement in hours. 74 */ 75 public static final int HOURS = 5; 76 /** 77 * Increment or decrement in minutes 78 */ 79 public static final int MINUTES = 6; 80 /** 81 * Increment or decrement in seonds 82 */ 83 public static final int SECONDS = 7; 84 /** 85 * Increment or decrement in milliseconds 86 */ 87 public static final int MSEC = 8; 88 /** 89 * Number of milliseconds in a day. 90 */ 91 public static final long MSECS_IN_DAY = 86400000; 92 93 /** 94 * Construct a new <code>GeoDate</code>. 95 */ 96 public GeoDate() 97 { 98 super(); 99 } 100 101 /** 102 * Construct a new <code>GeoDate</code> from a 103 * <code>String</code>. Formatting is done using 104 * <code>SimpleDateFormat</code>. The specified time 105 * is taken to be "GMT". 106 * 107 * @param time character representation of time 108 * @param format codes used to read time 109 */ 110 public GeoDate( String time, String format ) 111 throws IllegalTimeValue 112 { 113 super(); 114 ParsePosition pos = new ParsePosition( 0 ); 115 DateFormat df = new SimpleDateFormat( format ); 116 df.setCalendar( cal_ ); 117 118 Date dte = df.parse( time, pos ); 119 if( dte == null ) 120 { 121 throw new IllegalTimeValue( "Parse error: " + time + ", " + format ); 122 } 123 setTime( dte.getTime() ); 124 } 125 126 /** 127 * Constructs a new <code>GeoDate</code> from an 128 * existing <code>GeoDate</code>. 129 * 130 * @param t <code>GeoDate</code> 131 */ 132 public GeoDate( GeoDate t ) 133 { 134 super( t.getTime() ); 135 } 136 137 /** 138 * Construct a new <code>GeoDate</code> from values. The 139 * specified time is taken to be "GMT". 140 * 141 * @param mon month 142 * @param day day of the month 143 * @param year year (no offset!) 144 * @param hour hour 145 * @param min minutes 146 * @param sec seconds 147 * @param msec milliseconds 148 * @throws IllegalTimeValue The constructor was called with a set 149 * of parameters that does not constitute a legitimate time value. 150 */ 151 public GeoDate( int mon, int day, int year, int hour, int min, int sec, int msec ) 152 throws IllegalTimeValue 153 { 154 this.set( mon, day, year, hour, min, sec, msec ); 155 } 156 157 /** 158 * Construct a new <code>GeoDate</code> from a 159 * <code>Date</code> object. No time zone conversion 160 * is done. 161 * 162 * @param date Date object 163 */ 164 public GeoDate( Date date ) 165 { 166 setTime( date.getTime() ); 167 } 168 169 /** 170 * Construct a new <code>GeoDate</code> from EPIC double integers. 171 * Time zone for conversion is "GMT". 172 * 173 * @param jday julian day 174 * @param msec milliseconds since midnight 175 */ 176 public GeoDate( int jday, int msec ) 177 { 178 set( jday, msec ); 179 } 180 181 /** 182 * Allocates a GeoDate object and initializes it to represent 183 * the specified number of milliseconds since the standard 184 * base time know as "the epoch", namely January 1, 1970, 00:00:00 185 * GMT. 186 */ 187 public GeoDate( long date ) 188 { 189 setTime( date ); 190 } 191 192 /** 193 * Set the relativeTime flag. The relativeTime flag indicates that 194 * the <code>GeoDate</code> object does not represent an actual 195 * absolute time, but a temporal duration. 196 */ 197 public void setRelativeTime( boolean relative ) 198 { 199 relativeTime_ = relative; 200 } 201 202 /** 203 * Tests the relativeTime flag. 204 * 205 * @return if true, time is a duration 206 */ 207 public boolean isRelativeTime() 208 { 209 return relativeTime_; 210 } 211 212 /** 213 * Change value of <code>GeoDate</code> from EPIC double 214 * integers. 215 * Time zone for conversion is "GMT". 216 * 217 * @param jday julian day 218 * @param msec milliseconds since midnight 219 */ 220 public void set( int jday, int msec ) 221 { 222 int ja, jb, jc, jd, je; 223 double jalpha, second; 224 int day, month, year, hour, minute, sec; 225 226 if( jday > 2299161 ) 227 { 228 jalpha = ( (double) ( jday - 1867216 ) - 0.25 ) / 36524.25; 229 ja = jday + 1 + (int) jalpha - (int) ( 0.25 * jalpha ); 230 } 231 else 232 { 233 ja = jday; 234 } 235 jb = ja + 1524; 236 jc = (int) ( 6680.0 + ( (double) ( jb - 2439870 ) - 122.1 ) / 365.25 ); 237 jd = (int) ( 365 * jc + ( 0.25 * jc ) ); 238 je = (int) ( ( jb - jd ) / 30.6001 ); 239 240 day = (int) ( jb - jd ) - (int) ( 30.6001 * je ); 241 month = (int) ( je - 1 ); 242 if( month > 12 ) month -= 12; 243 year = (int) ( jc - 4715 ); 244 if( month > 2 ) --year; 245 if( year <= 0 ) --year; 246 ja = msec / 1000; 247 hour = (int) ( ja / 3600 ); 248 minute = (int) ( ( ja - hour * 3600 ) / 60 ); 249 second = (double) ( msec - ( hour * 3600 + minute * 60 ) * 1000 ) / 1000.0; 250 sec = (int) second; 251 msec = ( (int) ( second * 1000.0 ) ) % 1000; 252 try 253 { 254 set( month, day, year, hour, minute, sec, msec ); 255 } 256 catch( IllegalTimeValue e ) 257 { 258 } 259 } 260 261 /** 262 * Change value of <code>GeoDate</code> from values. 263 * Time zone for conversion is "GMT". 264 * 265 * @param mon month (1=January, 12=December) 266 * @param day day of the month 267 * @param year year (no offset!) 268 * @param hour hour 269 * @param min minutes 270 * @param sec seconds 271 * @param msec milliseconds 272 * @throws IllegalTimeValue The parameters passed to this method represent a time 273 * value that is invalid 274 */ 275 public void set( int mon, int day, int year, int hour, int min, int sec, int msec ) 276 throws IllegalTimeValue 277 { 278 int jy, jm, ja, jul; 279 int leap = ( year % 4 != 0 ? 0 : ( year % 400 == 0 ? 1 : ( year % 100 == 0 ? 0 : 1 ) ) ); 280 max_day_[1] = 28 + leap; 281 282 if( mon > 12 || mon < 1 ) 283 { 284 this.setTime( 0 ); 285 throw new IllegalTimeValue( "value of month out of range" ); 286 } 287 if( day > max_day_[mon - 1] || day < 1 ) 288 { 289 this.setTime( 0 ); 290 throw new IllegalTimeValue( "value of day out of range" ); 291 } 292 if( hour >= 24 || hour < 0 ) 293 { 294 this.setTime( 0 ); 295 throw new IllegalTimeValue( "value of hour out of range" ); 296 } 297 if( min >= 60 || min < 0 ) 298 { 299 this.setTime( 0 ); 300 throw new IllegalTimeValue( "value of minute out of range" ); 301 } 302 if( sec >= 60 || sec < 0 ) 303 { 304 this.setTime( 0 ); 305 throw new IllegalTimeValue( "value of second out of range" ); 306 } 307 if( msec >= 1000 || msec < 0 ) 308 { 309 this.setTime( 0 ); 310 throw new IllegalTimeValue( "value of msec out of range" ); 311 } 312 313 cal_.clear(); 314 cal_.set( year, mon - 1, day, hour, min, sec ); 315 316 // this.setTime(cal.getTimeInMillis() + msec); 317 this.setTime( ( cal_.getTime() ).getTime() + msec ); 318 splitDone_ = false; 319 EPICTimeDone_ = false; 320 } 321 322 /** 323 * Get the number of days in the current month. 324 * 325 * @return number of days in current month 326 */ 327 public int getDaysInMonth() 328 { 329 int leap; 330 int year = cal_.get( Calendar.YEAR ); 331 leap = ( year % 4 != 0 ? 0 : ( year % 400 == 0 ? 1 : ( year % 100 == 0 ? 0 : 1 ) ) ); 332 max_day_[1] = 28 + leap; 333 return max_day_[month_ - 1]; 334 } 335 336 /** 337 * Set to current time. 338 */ 339 public void now() 340 { 341 Date nw = new Date(); 342 this.setTime( nw.getTime() ); 343 } 344 345 /** 346 * Add time to current <code>GeoDate</code>. This operation only 347 * makes since if <code>time</code> is a relative time value, 348 * i.e. the result of a 349 * <code>GeoDate</code> subrtraction. 350 * 351 * @param time <code>GeoDate</code> 352 * @return new <code>GeoDate</code> 353 */ 354 public GeoDate add( GeoDate time ) 355 { 356 GeoDate time2 = new GeoDate(); 357 long MSec = getTime() + time.getTime(); 358 359 time2.splitDone_ = false; 360 time2.EPICTimeDone_ = false; 361 time2.setTime( MSec ); 362 return time2; 363 } 364 365 /** 366 * Subtract time2 from current <code>GeoDate</code>. 367 * 368 * @param time2 subtracthend 369 * @return new <code>GeoDate</code> 370 */ 371 public GeoDate subtract( GeoDate time2 ) 372 { 373 GeoDate delta = new GeoDate(); 374 long MSec = getTime() - time2.getTime(); 375 376 delta.splitDone_ = false; 377 delta.EPICTimeDone_ = false; 378 delta.setTime( MSec ); 379 delta.setRelativeTime( true ); 380 return delta; 381 } 382 383 /** 384 * Divide by value. Current time should the result of adding two times or 385 * subtracting two times to be a meaningful calculation. 386 * 387 * @param val divisor 388 * @return new <code>GeoDate</code> 389 */ 390 public GeoDate divide( double val ) 391 { 392 GeoDate result = new GeoDate(); 393 394 if( val == 0.0 ) return null; 395 396 result.setTime( (long) ( ( (double) getTime() ) / val ) ); 397 398 result.splitDone_ = false; 399 result.EPICTimeDone_ = false; 400 result.setRelativeTime( true ); 401 return result; 402 } 403 404 void splitTimeFormat() 405 { 406 int ja, jb, jc, jd, je; 407 double jalpha; 408 GeoDate gt; 409 410 if( splitDone_ ) return; 411 412 cal_.setTime( this ); 413 day_ = cal_.get( Calendar.DAY_OF_MONTH ); 414 month_ = cal_.get( Calendar.MONTH ) + 1; 415 year_ = cal_.get( Calendar.YEAR ); 416 hour_ = cal_.get( Calendar.HOUR_OF_DAY ); 417 minute_ = cal_.get( Calendar.MINUTE ); 418 second_ = cal_.get( Calendar.SECOND ); 419 msec_ = cal_.get( Calendar.MILLISECOND ); 420 dayofweek_ = cal_.get( Calendar.DAY_OF_WEEK ) - 1; 421 yearday_ = cal_.get( Calendar.DAY_OF_YEAR ); 422 423 splitDone_ = true; 424 } 425 426 /** 427 * Increment current <code>GeoDate</code> 428 * by <code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, 429 * <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code> 430 * 431 * @param val amount to increment 432 * @param tu time units (<code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code>) 433 * operation. 434 */ 435 public GeoDate increment( float val, int tu ) 436 { 437 return increment( (double) val, tu ); 438 } 439 440 /** 441 * Increment current <code>GeoDate</code> 442 * by <code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, 443 * <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code> 444 * 445 * @param val amount to increment 446 * @param tu time units (<code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code>) 447 * operation. 448 */ 449 public GeoDate increment( double val, int tu ) 450 { 451 int leap; 452 int ival = (int) val; 453 double fract = ( val - ival ); 454 long MSec = getTime(); 455 switch( tu ) 456 { 457 case MSEC: 458 MSec += (long) val; 459 setTime( MSec ); 460 break; 461 case SECONDS: 462 MSec += (long) ( val * 1000 ); 463 setTime( MSec ); 464 break; 465 case MINUTES: 466 MSec += (long) ( val * 60000 ); 467 setTime( MSec ); 468 break; 469 case HOURS: 470 MSec += (long) ( val * 3600000 ); 471 setTime( MSec ); 472 break; 473 case DAYS: // days and fraction days 474 MSec += (long) ( val * MSECS_IN_DAY ); 475 setTime( MSec ); 476 break; 477 case MONTHS: // nearest day 478 splitTimeFormat(); 479 month_ += ival; 480 year_ += ( ( month_ - 1 ) / 12 ); 481 month_ -= ( ( month_ - 1 ) / 12 ) * 12; 482 if( month_ == 0 ) month_ = 1; 483 leap = ( year_ % 4 != 0 ? 0 : ( year_ % 400 == 0 ? 1 : ( year_ % 100 == 0 ? 0 : 1 ) ) ); 484 max_day_[1] = 28 + leap; 485 day_ += (int) ( fract * max_day_[month_ - 1] ); 486 if( day_ > max_day_[month_ - 1] ) 487 { 488 day_ -= max_day_[month_ - 1]; 489 month_++; 490 year_ += ( ( month_ - 1 ) / 12 ); 491 month_ -= ( ( month_ - 1 ) / 12 ) * 12; 492 if( month_ == 0 ) month_ = 1; 493 } 494 try 495 { 496 this.set( month_, day_, year_, hour_, minute_, second_, msec_ ); 497 } 498 catch( IllegalTimeValue e ) 499 { 500 System.err.println( e ); 501 } 502 break; 503 case YEARS: // nearest day 504 splitTimeFormat(); 505 year_ += ival; 506 leap = ( year_ % 4 != 0 ? 0 : ( year_ % 400 == 0 ? 1 : ( year_ % 100 == 0 ? 0 : 1 ) ) ); 507 max_day_[1] = 28 + leap; 508 if( day_ > max_day_[month_ - 1] ) day_ = max_day_[month_ - 1]; 509 try 510 { 511 this.set( month_, day_, year_, hour_, minute_, second_, msec_ ); 512 } 513 catch( IllegalTimeValue e ) 514 { 515 System.err.println( e ); 516 } 517 setTime( getTime() + (long) ( fract * 365.25 ) * MSECS_IN_DAY ); 518 break; 519 } 520 splitDone_ = false; 521 EPICTimeDone_ = false; 522 return this; 523 } 524 525 /** 526 * Decrement current <code>GeoDate</code> 527 * by <code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, 528 * <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code> 529 * 530 * @param val amount to decrement 531 * @param tu time units (<code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code>) 532 * operation. 533 */ 534 public GeoDate decrement( float val, int tu ) 535 { 536 return decrement( (double) val, tu ); 537 } 538 539 /** 540 * Decrement current <code>GeoDate</code> 541 * by <code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, 542 * <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code> 543 * 544 * @param val amount to decrement 545 * @param tu time units (<code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, <code>DAYS</code>, <code>MONTHS</code>, or <code>YEARS</code>) 546 * operation. 547 */ 548 public GeoDate decrement( double val, int tu ) 549 { 550 int leap; 551 int ival = (int) val; 552 double fract = ( val - ival ); 553 long MSec = getTime(); 554 555 switch( tu ) 556 { 557 case MSEC: 558 MSec -= (long) val; 559 setTime( MSec ); 560 break; 561 case SECONDS: 562 MSec -= (long) ( val * 1000 ); 563 setTime( MSec ); 564 break; 565 case MINUTES: 566 MSec -= (long) ( val * 60000 ); 567 setTime( MSec ); 568 break; 569 case HOURS: 570 MSec -= (long) ( val * 3600000 ); 571 setTime( MSec ); 572 break; 573 case DAYS: 574 MSec -= (long) ( val * MSECS_IN_DAY ); 575 setTime( MSec ); 576 break; 577 case MONTHS: 578 splitTimeFormat(); 579 month_ -= ival; 580 if( month_ <= 0 ) 581 { 582 year_ -= ( month_ - 1 ) / 12 + 1; 583 month_ += ( ( month_ - 1 ) / 12 ) * 12 + 12; 584 } 585 if( month_ == 0 ) month_ = 12; 586 leap = ( year_ % 4 != 0 ? 0 : ( year_ % 400 == 0 ? 1 : ( year_ % 100 == 0 ? 0 : 1 ) ) ); 587 max_day_[1] = 28 + leap; 588 day_ -= (int) ( fract * max_day_[month_ - 1] ); 589 if( day_ > max_day_[month_ - 1] ) 590 { 591 day_ -= max_day_[month_ - 1]; 592 month_--; 593 if( month_ <= 0 ) 594 { 595 year_ -= ( month_ - 1 ) / 12 + 1; 596 month_ += ( ( month_ - 1 ) / 12 ) * 12; 597 } 598 if( month_ == 0 ) month_ = 12; 599 } 600 try 601 { 602 this.set( month_, day_, year_, hour_, minute_, second_, msec_ ); 603 } 604 catch( IllegalTimeValue e ) 605 { 606 System.err.println( e ); 607 } 608 break; 609 case YEARS: 610 splitTimeFormat(); 611 year_ -= ival; 612 leap = ( year_ % 4 != 0 ? 0 : ( year_ % 400 == 0 ? 1 : ( year_ % 100 == 0 ? 0 : 1 ) ) ); 613 max_day_[1] = 28 + leap; 614 if( day_ > max_day_[month_ - 1] ) day_ = max_day_[month_ - 1]; 615 try 616 { 617 this.set( month_, day_, year_, hour_, minute_, second_, msec_ ); 618 } 619 catch( IllegalTimeValue e ) 620 { 621 System.err.println( e ); 622 } 623 setTime( getTime() - (long) ( fract * 365.25 ) * MSECS_IN_DAY ); 624 break; 625 } 626 splitDone_ = false; 627 EPICTimeDone_ = false; 628 return this; 629 } 630 631 /** 632 * Time offset from reference <code>GeoDate</code> 633 * 634 * @param ref reference <code>GeoDate</code> 635 * @return offset in days 636 */ 637 public double offset( GeoDate ref ) 638 { 639 double val; 640 val = ( (double) ( this.getTime() - ref.getTime() ) ) / 86400000.0; 641 return val; 642 } 643 644 /** 645 * Set a <code>GeoDate</code> from year and year-day. 646 * 647 * @param year year 648 * @param yearday year-day number (Jan 1 = 1) 649 * parameters that does not constitute a legitimate time value. 650 */ 651 public void setYearYearDay( int year, int yearday ) 652 { 653 try 654 { 655 this.set( 1, 1, year, 0, 0, 0, 0 ); 656 } 657 catch( IllegalTimeValue e ) 658 { 659 System.err.println( e ); 660 } 661 setTime( getTime() + ( yearday - 1 ) * MSECS_IN_DAY ); 662 } 663 664 /** 665 * Get a reference to the <code>GregorianCalendar</code> set 666 * to the current <code>GeoDate</code> time. 667 * 668 * @return <code>Calendar</code> 669 */ 670 public Calendar getCalendar() 671 { 672 cal_.setTime( this ); 673 return cal_; 674 } 675 676 /** 677 * Get year-day number (Jan 1 = 1) 678 */ 679 public int getYearday() 680 { 681 splitTimeFormat(); 682 return yearday_; 683 } 684 685 /** 686 * Get year 687 * 688 * @deprecated Overrides a deprecated method, replaced by {@link #getGMTYear}. 689 */ 690 public int getYear() 691 { 692 splitTimeFormat(); 693 return year_; 694 } 695 696 /** 697 * Get year. 698 */ 699 public int getGMTYear() 700 { 701 splitTimeFormat(); 702 return year_; 703 } 704 705 /** 706 * Get month 707 * 708 * @deprecated Overrides a deprecated method, replaced by {@link #getGMTMonth}. 709 */ 710 public int getMonth() 711 { 712 splitTimeFormat(); 713 return month_; 714 } 715 716 /** 717 * Get month 718 */ 719 public int getGMTMonth() 720 { 721 splitTimeFormat(); 722 return month_; 723 } 724 725 /** 726 * Get day 727 * 728 * @deprecated Overrides a deprecated method, replaced by {@link #getGMTDay}. 729 */ 730 public int getDay() 731 { 732 splitTimeFormat(); 733 return day_; 734 } 735 736 /** 737 * Get day 738 */ 739 public int getGMTDay() 740 { 741 splitTimeFormat(); 742 return day_; 743 } 744 745 /** 746 * Get hours 747 * 748 * @deprecated Overrides a deprecated method, replaced by {@link #getGMTHours}. 749 */ 750 public int getHours() 751 { 752 splitTimeFormat(); 753 return hour_; 754 } 755 756 /** 757 * Get hours 758 */ 759 public int getGMTHours() 760 { 761 splitTimeFormat(); 762 return hour_; 763 } 764 765 /** 766 * Get minutes 767 * 768 * @deprecated Overrides a deprecated method, replaced by {@link #getGMTMinutes}. 769 */ 770 public int getMinutes() 771 { 772 splitTimeFormat(); 773 return minute_; 774 } 775 776 /** 777 * Get minutes 778 */ 779 public int getGMTMinutes() 780 { 781 splitTimeFormat(); 782 return minute_; 783 } 784 785 /** 786 * Get secondss 787 * 788 * @deprecated replaced by {@link #getGMTSeconds}. 789 */ 790 public double getSecondss() 791 { 792 splitTimeFormat(); 793 return second_; 794 } 795 796 /** 797 * Get seconds and fraction of seconds. 798 */ 799 public double getGMTSeconds() 800 { 801 splitTimeFormat(); 802 return second_; 803 } 804 805 /** 806 * get EPIC Julian Day 807 */ 808 public int getJDay() 809 { 810 splitTimeFormat(); 811 computeEPICTime(); 812 return JDay_; 813 } 814 815 /** 816 * get milliseconds since midnight 817 */ 818 public int getMSec() 819 { 820 splitTimeFormat(); 821 computeEPICTime(); 822 return MSec_; 823 } 824 825 private void computeEPICTime() 826 { 827 if( EPICTimeDone_ ) return; 828 int GREGORIAN__ = ( 15 + 31 * ( 10 + 12 * 1582 ) ); 829 int jy, jm, ja, jul; 830 int year = year_; 831 int mon = month_; 832 int day = day_; 833 int hour = hour_; 834 int min = minute_; 835 int sec = second_; 836 int msec = msec_; 837 838 int leap = ( year % 4 != 0 ? 0 : ( year % 400 == 0 ? 1 : ( year % 100 == 0 ? 0 : 1 ) ) ); 839 840 if( year < 0 ) ++year; 841 if( mon > 2 ) 842 { 843 jy = year; 844 jm = mon + 1; 845 } 846 else 847 { 848 jy = year - 1; 849 jm = mon + 13; 850 } 851 jul = (int) ( Math.floor( 365.25 * jy ) + Math.floor( 30.6001 * jm ) + day + 1720995 ); 852 if( day + 31L * ( mon + 12L * year ) >= GREGORIAN__ ) 853 { 854 ja = (int) ( 0.01 * jy ); 855 jul += 2 - ja + (int) ( 0.25 * ja ); 856 } 857 858 JDay_ = jul; 859 MSec_ = (int) ( ( hour * 3600L + min * 60L ) * 1000L + sec * 1000L + msec ); 860 861 EPICTimeDone_ = true; 862 } 863 864 /** 865 * Convert <code>GeoDate</code> to <code>String</code> 866 * using standard format "yyyy-MM-dd HH:mm:ss z" 867 * and "GMT" time zone. 868 * 869 * @return date 870 */ 871 public String toString() 872 { 873 DateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss z" ); 874 df.setCalendar( cal_ ); 875 return df.format( this ); 876 } 877 878 /** 879 * Convert <code>GeoDate</code> to <code>String</code> 880 * using provided format. The <code>SimpleDateFormat</code> 881 * and the <code>GregorianCalendar</code> is used to format 882 * the <code>GeoDate</code>. A format of "decade" will create 883 * a string of the form 1990 or 1980. 884 * 885 * @param format String containing codes used to write time. 886 * @see SimpleDateFormat 887 */ 888 public String toString( String format ) 889 { 890 if( format.equals( "decade" ) ) 891 { 892 splitTimeFormat(); 893 return Integer.toString( ( year_ / 10 ) * 10 ); 894 } 895 else 896 { 897 DateFormat df = new SimpleDateFormat( format ); 898 df.setCalendar( cal_ ); 899 return df.format( this ); 900 } 901 } 902 903 /** 904 * Tests to see if value represents missing data. A value from the 905 * getTime() method of <code>Long.MIN_VALUE</code> represents a 906 * missing observation. 907 * 908 * @see gov.noaa.pmel.sgt.dm.SGTData#getXRange() 909 */ 910 public boolean isMissing() 911 { 912 return getTime() == Long.MIN_VALUE; 913 } 914 915 /** 916 * Tests to see if the current GeoDate is less than, equal, or greater than. 917 * another GeoDate 918 */ 919 public int compareTo( GeoDate anotherDate ) 920 { 921 if( this.getTime() < anotherDate.getTime() ) 922 return -1; 923 else if( this.getTime() == anotherDate.getTime() ) 924 return 0; 925 else 926 return 1; 927 } 777 928 } -
ether_megapoli/trunk/service/interface/com/ether/EtherService.java
r191 r194 37 37 38 38 @NotNull 39 <T1, T2, T3> Data< T1[], T2[], T3[]> getArraysByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd )39 <T1, T2, T3> Data<List<T1>, List<T2>, List<T3>> getListsByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 40 40 throws ServiceException; 41 41 42 42 @NotNull 43 <T1, T2, T3> Data< List<T1>, List<T2>, List<T3>> getListsByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd )43 <T1, T2, T3> Data<T1[], T2[], T3[]> getArraysByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 44 44 throws ServiceException; 45 45 -
ether_megapoli/trunk/service/test/com/ether/OtherTest.java
r191 r194 10 10 import java.util.Calendar; 11 11 import java.util.Date; 12 import java.util.GregorianCalendar; 12 13 import java.util.HashSet; 13 14 import java.util.List; 14 15 import java.util.Set; 16 import java.util.TimeZone; 15 17 16 18 /** … … 54 56 shortDates.add( shortFormat.format( aDate ) ); 55 57 } 58 59 final Calendar cal = Calendar.getInstance(); 60 cal.setTimeInMillis( Long.valueOf( "1246811160000" ) ); 61 // 05/07/2009 18h26 62 Date date = cal.getTime(); 63 64 cal.setTimeInMillis( Long.valueOf( "1246818360000" ) ); 65 // 05/07/2009 20h26 66 date = cal.getTime(); 56 67 } 57 68 … … 121 132 Assert.assertEquals( doubles1[1], (double) doubleList.get( 1 ), 0 ); 122 133 } 134 135 @Test 136 public void testCreateValuesForTimeSerie() 137 { 138 final Integer size = 5; 139 final Integer delta = 8; 140 141 final double[] values = new double[size]; 142 final Date[] dates = new Date[size]; 143 final Calendar calCEST = Calendar.getInstance(); 144 final Date paf = calCEST.getTime(); 145 calCEST.setTimeInMillis( Long.valueOf( "1246811160000" ) ); 146 final Date dateCEST = calCEST.getTime(); 147 148 final Calendar calGMT = new GregorianCalendar( TimeZone.getTimeZone( "GMT" ) ); 149 final Date pif = calGMT.getTime(); 150 calGMT.setTimeInMillis( Long.valueOf( "1246811160000" ) ); 151 final Date dateGMT = calGMT.getTime(); 152 153 final Date date = new Date(); 154 final DateFormat cetFormat = new SimpleDateFormat(); 155 final DateFormat gmtFormat = new SimpleDateFormat(); 156 final TimeZone gmtTime = TimeZone.getTimeZone( "GMT" ); 157 final TimeZone cetTime = TimeZone.getTimeZone( "CET" ); 158 cetFormat.setTimeZone( gmtTime ); 159 gmtFormat.setTimeZone( cetTime ); 160 System.out.println( "GMTÂ Time:Â " + cetFormat.format( date ) ); 161 System.out.println( "CETÂ Time:Â " + gmtFormat.format( date ) ); 162 163 for( int i = 0; i < size; i++ ) 164 { 165 // cal.add( Calendar.MINUTE, (int) ( 2 + i + ( Math.random() * 8 ) ) ); 166 calGMT.add( Calendar.MINUTE, (int) ( 2 * i ) ); 167 dates[i] = calGMT.getTime(); 168 values[i] = (double) i * Math.random() * delta; 169 } 170 171 final Data datas = new Data( values, dates ); 172 } 173 123 174 } -
ether_megapoli/trunk/web/resources/js/etherHelper.js
r89 r194 2 2 // Requires prototype and DomHelper.js 3 3 4 function disableContainer( containerId)4 function disableContainer( containerId ) 5 5 { 6 var container = Dom.getContainer(containerId);7 container.addClassName("disable");6 var container = Dom.getContainer( containerId ); 7 container.addClassName( "disable" ); 8 8 } 9 9 10 function enableContainer( containerId)10 function enableContainer( containerId ) 11 11 { 12 var container = Dom.getContainer(containerId);13 container.removeClassName("disable");12 var container = Dom.getContainer( containerId ); 13 container.removeClassName( "disable" ); 14 14 } 15 15 16 /** 17 * This method indicates if an element is included in a list 18 * @param list 19 * @param element 20 */ 21 function content( elementList, element ) 22 { 23 var resu = false; 24 $A(elementList).each( function( listElement ) 25 { 26 if( listElement == element ) 27 { 28 resu = true; 29 throw $break; 30 } 31 }.bind( this ) ); 32 return resu; 33 } 34 -
ether_megapoli/trunk/web/src/com/ether/ControllerPlot.java
r191 r194 113 113 final Integer plateformId = (Integer) pIdPIdList.get( 0 ).getFirstValue(); 114 114 final Integer parameterId = (Integer) pIdPIdList.get( 0 ).getSecondValue(); 115 //final Data valuesLists = _etherService.getListsByPlateformByParameterByPeriodFor2D( plateformId, parameterId, formatedDateBegin, formatedDateEnd );116 final Data valuesLists = BouchonHelper.createRealValuesFor2D();115 final Data valuesLists = _etherService.getListsByPlateformByParameterByPeriodFor2D( plateformId, parameterId, formatedDateBegin, formatedDateEnd ); 116 // final Data valuesLists = BouchonHelper.createRealValuesFor2D(); 117 117 megapoliPlot.setData( valuesLists ); 118 118 119 119 megapoliPlot.setTimeSerie( false ); 120 120 megapoliPlot.setLegendToHide( false ); 121 //megapoliPlot.setValuesNumber( ( (ArrayList) valuesLists.getFirstArray() ).size() );122 megapoliPlot.setValuesNumber( 5 );121 megapoliPlot.setValuesNumber( ( (ArrayList) valuesLists.getFirstArray() ).size() ); 122 // megapoliPlot.setValuesNumber( 5 ); 123 123 } 124 124 -
ether_megapoli/trunk/web/visualization/visu_parameter_by_pf-script.jsp
r185 r194 105 105 paramSelect.classNameOption = "select_plot_option"; 106 106 this.selectPlots = new Select( paramSelect ); 107 this.selectParameters = $A(); 107 108 this.selectPlots.add( null, interfaceTexts["data.visualization.graph.noPlot"] ); 108 109 this.selectPlots.selectFirst( false ); … … 187 188 188 189 $( "textareaTitle" ).value = this.selectedPlateform.getName(); 190 191 // Init number and list of parameter to display 192 if( "MOBILE" == this.selectedPlateform.jsonElement.type ) 193 this.updateNumberAndListParameterToDisplay( 0 ); 194 189 195 this.requestParametersByPlateform(); 190 196 this.testAllFields(); … … 404 410 case 0: 405 411 // INIT 412 this.selectPlots.clear(); 413 this.selectParameters.clear(); 414 this.selectPlotsPlateformType = false; 415 406 416 if( this.selectedPlateform && this.selectedParameter ) 407 417 { 408 this.selectPlots.clear();409 this.selectPlotsPlateformType = false;410 418 this.selectPlots.changeSelectMiddle( this.selectedPlateform.getId() + "-" + this.selectedParameter.getId(), this.selectedPlateform.getName() + " - " + this.selectedParameter.getName() ); 411 419 … … 415 423 else 416 424 { 417 this.selectPlots.clear();418 425 this.selectPlots.add( null, interfaceTexts["data.visualization.graph.noPlot"] ); 419 426 this.selectPlots.selectFirst( false ); 420 this.selectPlotsPlateformType = false;421 427 422 428 this.numberParameterToDisplay = 0; … … 424 430 } 425 431 break; 432 426 433 case 1 : 427 434 // SELECT 428 if( 0 == this.numberParameterToDisplay )435 if( 0 == this.numberParameterToDisplay || "MOBILE" == this.selectedPlateform.jsonElement.type ) 429 436 { 430 437 this.selectPlots.clear(); 438 this.selectParameters.clear(); 431 439 this.numberParameterToDisplay = 1; 432 440 } … … 435 443 $( "messages_number_parameters" ).innerHTML = this.numberParameterToDisplay + " " + interfaceTexts["data.visualization.parameter"]; 436 444 break; 445 437 446 default: 438 447 // ADD 439 448 var plotValue = this.selectedPlateform.getId() + "-" + this.selectedParameter.getId(); 440 if( !this.selectPlots.content( plotValue ) ) 449 var isParameterAlreadySelected = content( this.selectParameters, this.selectedParameter.getId() ); 450 if( !this.selectPlots.content( plotValue ) && (isParameterAlreadySelected || (!isParameterAlreadySelected && this.selectParameters.size() < 2)) ) 441 451 { 442 452 this.selectPlots.add( plotValue, this.selectedPlateform.getName() + " - " + this.selectedParameter.getName() ); 443 453 this.selectPlots.select( plotValue, false ); 444 454 this.selectPlotsPlateformType = this.selectedPlateform.jsonElement.type; 455 this.selectParameters[this.selectParameters.size()] = this.selectedParameter.getId(); 445 456 446 457 this.numberParameterToDisplay = this.selectPlots.getSize(); -
ether_megapoli/trunk/web/visualization/visu_parameter_by_pf.jsp
r173 r194 137 137 interfaceTexts["<%=AxeTypeForFixedPlateform.TIME_POINTS%>"] = "<bean:message key="data.visualization.axeType.TimePoints"/>"; 138 138 interfaceTexts["<%=AxeTypeForMobilePlateform.D2_POINTS%>"] = "<bean:message key="data.visualization.axeType.2DPoints"/>"; 139 interfaceTexts["<%=AxeTypeForMobilePlateform.D2_CONTOUR%>"] = "<bean:message key="data.visualization.axeType.2DContour"/>";140 139 141 140 var interfaceVisualization = new InterfaceVisualization( ${plateforms}, ${axeTypesForFixedPlateforms}, ${axeTypesForMobilePlateforms} );
Note: See TracChangeset
for help on using the changeset viewer.