예제 #1
0
/*
 * Converts broken-down time to time in seconds since 1 Jan 1970 00:00.
 * Pays no attention to time zone or daylight savings time.  Another way
 * to think about this function is that it is the inverse of gmtime().
 * One word of caution: the values in the broken down time must be
 * correct.
 *
 * This function is different from mktime() in three ways:
 * 1. mktime() accepts a broken-down local time and converts it to a scalar
 *    UTC time.  Thus, mktime() takes time zone and daylight savings time
 *    information into account when computing the scalar time.  (This makes
 *    mktime() highly non-portable).
 * 2. mktime() will adjust for non-standard values, such as a tm_mday member
 *    that is out of range.  This function does no such conversion.
 * 3. mktime() sets the struct fields tm_yday, tm_wday, and tm_isdst to
 *    their correct values on output.  This function does not.
 */
static DwUint32 my_inv_gmtime(struct tm* ptms)
{
    DwInt32 jdn;
    DwUint32 t;

    jdn = ymd_to_jdnl(ptms->tm_year+1900, ptms->tm_mon+1,
        ptms->tm_mday, -1);
    t = jdn - JDN_JAN_1_1970;  /* days    */
    t = 24*t + ptms->tm_hour;  /* hours   */
    t = 60*t + ptms->tm_min;   /* minutes */
    t = 60*t + ptms->tm_sec;   /* seconds */
    return t;
}
예제 #2
0
int main(int argc, char *argv[])
{
      int day, yr, mo;
      char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
                        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
      long jdn;

      if (3 > argc)
      {
            puts("Usage: JDN d m y");
            puts("where: d = day (1 - 31)");
            puts("       m = month (1 - 12)");
            puts("       y = year (1 - 99, 1800 - 3000)");
            return -1;
      }

      yr  = atoi(argv[3]);
      mo  = atoi(argv[2]);
      day = atoi(argv[1]);

      if (mo < 1 || 12 < mo)
            return -1;

      if (day < 1 || 31 < day)
            return -1;

      if (100 > yr)
            yr += 1900;

      printf("User specified %d-%s-%d...\n\n", day, months[mo - 1], yr);

      jdn = ymd_to_jdnl(yr, mo, day, 0);
      jdnl_to_ymd(jdn, &yr, &mo, &day, 0);

      printf("jdn_l(%d-%s-%d) = %ld\n", day, months[mo - 1], yr, jdn);
      return 0;
}
예제 #3
0
DwInt32 DwDateTime::DateAsJulianDayNum() const
{
    DwInt32 jdn = ymd_to_jdnl(mYear, mMonth, mDay, -1);
    return jdn;
}
예제 #4
0
int get_sstfiles(long julianday, char *crwpath, char *sstfilepath, char *qualfilepath) {

  int year, month, day, day_of_year;
  long start_day; 

  /* get year and day of year from julian day */
  jdnl_to_ymd(julianday, &year, &month, &day, 0); 
  start_day = ymd_to_jdnl(year, 1, 1, 0); 
  day_of_year = (int)(julianday - start_day) + 1;

  /* determine appropriate suffixes */

  char sst_end[] = ".s04d1pfv50-sst-16b.hdf";
  char qual_end[] = ".m04d1pfv50-qual.hdf";
   
  if (year <= 1981 && day_of_year < 236) { /* date is before start of dataset */
      printf("Non-existent sst file date requested: %d %d\n", year, day_of_year);
      exit(1);
  }

  switch (year) {
    case 1981:
    case 1982: if (year == 1982 && ((day_of_year >= 148 && day_of_year <= 151) || 
                                   (day_of_year >= 268 && day_of_year <= 269))) {
                 return -1; /* missing days */
               }
    case 1983: if (year == 1983 && day_of_year >= 218 && day_of_year <= 219) {
                 return -1; /* missing days */
               }
    case 1984: if (year == 1984 && ((day_of_year >= 14 && day_of_year <= 15) ||
                                   day_of_year == 84 || day_of_year == 342)) {
                 return -1; /* missing days */
               }
    case 1985: 
               if (year == 1985 && day_of_year >= 40 && day_of_year <= 42) {
                 return -1; /* missing days */
               } else if (year == 1985 && day_of_year > 9) {
                 strcpy(sst_end, ".s04d1pfv50-sst-16b.hdf");
                 strcpy(qual_end, ".m04d1pfv50-qual.hdf");
               } else {
                 strcpy(sst_end, ".s04d1pfv51-sst.hdf");
                 strcpy(qual_end, ".m04d1pfv51-qual.hdf");
               }
               break;

    case 2002: strcpy(sst_end, ".s04d1pfv50-sst.hdf");
               strcpy(qual_end, ".m04d1pfv50-qual.hdf");
               break;
    case 2003: 
    case 2004: strcpy(sst_end, ".s04d4pfv50-sst.hdf");
               strcpy(qual_end, ".m04d4pfv50-qual.hdf"); 
               break;
    case 2005:
               if (day_of_year <= 155) {
                 strcpy(sst_end, ".s04d4pfv50-sst.hdf");
                 strcpy(qual_end, ".m04d4pfv50-qual.hdf");
               } else { /* 2AM satellite becomes available */
                 strcpy(sst_end, ".s04d1pfv50-sst.hdf");
                 strcpy(qual_end, ".m04d1pfv50-qual.hdf");
               }
               break;
    case 2006:
               strcpy(sst_end, ".s04d1pfv50-sst.hdf");
               strcpy(qual_end, ".m04d1pfv50-qual.hdf");
               break;
    case 2007:
    case 2008:
    case 2009:
               strcpy(sst_end, ".s04d1pfrt-sst.hdf");
               strcpy(qual_end, ".m04d1pfrt-qual.hdf");
               break;
  }

  /* add prefix of year and day */
  size_t size = 47; /* maximum size of filepath */
  char *buf = (char*)malloc(size);
  snprintf(buf, size, "%sPF4km/all/SST_daily_%d/%d%03d", crwpath, year, year, day_of_year);

  strcpy(sstfilepath, buf);
  strcat(sstfilepath, sst_end);
  strcpy(qualfilepath, buf);
  strcat(qualfilepath, qual_end);

  return 0; /* return SUCCESS */
}