⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mf_date.c

📁 CCSM Research Tools: Community Atmosphere Model (CAM)
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifdef MF_DEBUG  if((this->calendar.type != incDate->calendar.type) &&     (incDate->calendar.type != MF_CALENDAR_TYPE_UNDEFINED)){    MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, 	    "argument calendar types are different or uninitialized");  }  if((nseconds < 0) || (nseconds == MF_TIME_UNDEFINED)){    MF_ERRA1(MF_ERR_ARG_OUTOFRANGE, 0,     "seconds are invalid or undefined: seconds = %d", nseconds);  }#endif    switch(this->tod.type){    case MF_TOD_INT_SEC:      MF_TimeConstructIS(&time, 0, nseconds);      break;    default:      MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, 	      "time of day type is not supported by this method");  }  MF_DateIncrement(this, incDate, &time);  return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateIncrementDay"int MF_DateIncrementDay (MF_Date this, MF_Date incDate, int ndays){  MF_TimeClass time;#ifdef MF_DEBUG  if((this->calendar.type != incDate->calendar.type) &&     (incDate->calendar.type != MF_CALENDAR_TYPE_UNDEFINED)){    MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, 	    "argument calendar types are different or uninitialized");  }  if((ndays < 0) || (ndays == MF_TIME_UNDEFINED)){    MF_ERRA1(MF_ERR_ARG_OUTOFRANGE, 0,     "days are invalid or undefined: days = %d", ndays);  }#endif    switch(this->tod.type){    case MF_TOD_INT_SEC:      MF_TimeConstructIS(&time, ndays, 0);      break;    default:      MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, 	      "time of day type is not supported by this method");  }  MF_DateIncrement(this, incDate, &time);  return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateIncrementMonth"int MF_DateIncrementMonth (MF_Date this, MF_Date incDate, int nmonths){#ifdef MF_DEBUG  if((this->calendar.type != incDate->calendar.type) &&     (incDate->calendar.type != MF_CALENDAR_TYPE_UNDEFINED)){    MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, 	    "argument calendar types are different or uninitialized");  }  if((nmonths < 0) || (nmonths == MF_TIME_UNDEFINED)){    MF_ERRA1(MF_ERR_ARG_OUTOFRANGE, 0,     "months are invalid or undefined: months = %d", nmonths);  }#endif  MF_DateCopy(incDate, this);  incDate->month += nmonths;    /* Cycle to a new year if needed. */  if(incDate->month > 12){    incDate->year += (incDate->month)/12;     incDate->month = (incDate->month)%12;    /* If in a new year, rebuild the calendar. */    MF_CalendarConstruct(&incDate->calendar, incDate->calendar.type, incDate->year);  }  /* If the current day exceeds the number of days in the month, set the     day of the month to the last day of the month. Seconds will remain the     same.  Flag if this happens when in DEBUG mode. */  if(incDate->day > incDate->calendar.dim[incDate->month]){#ifdef DEBUG    MF_ERRA(MF_ERR_DATE, 0,"incrementing by a month resulted in an invalid day");    #endif    incDate->day = incDate->calendar.dim[incDate->month];  }  /* Compute the new Julian day. */  MF_DATE_2_JULIAN_DAY(incDate->julianDay, incDate->year, incDate->month, incDate->day);    /* Compute the new day of the year */    MF_CalendarBuildDayOfYear(&incDate->calendar, incDate->month, incDate->day,     &incDate->dayOfYear);  return(MF_SUCCESS);}  /*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateIncrementYear"int MF_DateIncrementYear (MF_Date this, MF_Date incDate, int nyears){#ifdef MF_DEBUG  if((this->calendar.type != incDate->calendar.type) &&     (incDate->calendar.type != MF_CALENDAR_TYPE_UNDEFINED)){    MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, 	    "argument calendar types are different or uninitialized");  }  if((nyears < 0) || (nyears == MF_TIME_UNDEFINED)){    MF_ERRA1(MF_ERR_ARG_OUTOFRANGE, 0,     "years are invalid or undefined: years = %d", nyears);  }#endif  MF_DateCopy(incDate, this);  incDate->year+=nyears;    MF_CalendarConstruct(&incDate->calendar, incDate->calendar.type, incDate->year);  /* If the current day exceeds the number of days in the month, set the     day of the month to the last day of the month. Seconds will remain the     same.  Flag if this happens when in DEBUG mode. */  if(incDate->day > incDate->calendar.dim[incDate->month]){#ifdef DEBUG    MF_ERRA(MF_ERR_DATE, 0,"incrementing by a year resulted in an invalid day");    #endif    incDate->day = incDate->calendar.dim[incDate->month];  }  /* Compute the new Julian day. */  MF_DATE_2_JULIAN_DAY(incDate->julianDay, incDate->year, incDate->month, incDate->day);    /* Compute the new day of the year */    MF_CalendarBuildDayOfYear(&incDate->calendar, incDate->month, incDate->day,     &incDate->dayOfYear);  return(MF_SUCCESS);}  /*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateDiff"int MF_DateDiff (MF_Date earlyDate, MF_Date lateDate, MF_Time diff, 		  MF_Bool *isLater){  int extraday, earlyJulDay, lateJulDay;  MF_DateClass tmpEarly, tmpLate;  MF_TimeClass earlyTime, lateTime;#ifdef MF_DEBUG  /* Check that date arguments are using the same calendar. */  if(earlyDate->calendar.type != lateDate->calendar.type)    MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, "dates must use the same calendar");#endif  switch(earlyDate->calendar.type){    case MF_GREGORIAN:      MF_DATE_2_JULIAN_DAY(earlyJulDay, earlyDate->year, earlyDate->month,        earlyDate->day);            MF_DATE_2_JULIAN_DAY(lateJulDay, lateDate->year, lateDate->month,        lateDate->day);      MF_TimeConstruct(&earlyTime, earlyJulDay, &earlyDate->tod);      MF_TimeConstruct(&lateTime, lateJulDay, &lateDate->tod);      MF_TimeDiff(&earlyTime, &lateTime, diff, isLater);      break;    case MF_NO_LEAP:      MF_DateIsLater(earlyDate, lateDate, isLater);       if(*isLater){        MF_DateCopyConstruct(&tmpEarly, earlyDate);	MF_DateCopyConstruct(&tmpLate, lateDate);      }      else{        MF_DateCopyConstruct(&tmpEarly, lateDate);	MF_DateCopyConstruct(&tmpLate, earlyDate);      }      MF_TODDecrement(&tmpLate.tod, &tmpEarly.tod, &diff->tod, &extraday);      if(extraday == 1) MF_DateIncrementDay(&tmpEarly, &tmpEarly, 1);       diff->day = tmpLate.dayOfYear - tmpEarly.dayOfYear;      if(diff->day < 0){        diff->day += tmpLate.calendar.diy;        ++(tmpEarly.year);      }      diff->day += (tmpLate.year - tmpEarly.year)*365;      break;      default:      MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, 	      "calendar type is not supported by this method");  }      return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateIsLater"int MF_DateIsLater (MF_Date earlyDate, MF_Date lateDate, MF_Bool *isLater){  MF_Bool todIsLater;#ifdef MF_DEBUG  /* Check that date arguments are using the same calendar. */  if(earlyDate->calendar.type != lateDate->calendar.type)    MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, "dates must use the same calendar");#endif  /* If none of these complete conditions was satisfied, the result is false. */  *isLater= MF_FALSE;    if(lateDate->year > earlyDate->year)    {      /* Year is larger, so done */      *isLater = MF_TRUE;    }  else if(lateDate->year == earlyDate->year)    {      /* Years are equal, so further testing required */      if (lateDate->dayOfYear > earlyDate->dayOfYear)	{	  /* Year ==, Day is larger, so done. */	  *isLater = MF_TRUE;	}      else if(lateDate->dayOfYear == earlyDate->dayOfYear)      	{	  /* Year==, Day ==, so test time of day */	  MF_TODIsLater(&earlyDate->tod, &lateDate->tod, &todIsLater);	  if(todIsLater)	    {	      /* Time of day larger, done */	      *isLater=MF_TRUE;	    }	} /* Days == */    } /* Years == */  return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DatePrint"int MF_DatePrint(MF_Date this){  printf("Printing Date:\n");  printf("year      = %d\n",  this->year);  printf("month     = %d\n",  this->month);  printf("day       = %d\n",  this->day);  printf("julianDay = %d\n", this->julianDay);  printf("dayOfYear = %d\n", this->dayOfYear);   printf("Printing Date internal Calendar:\n");  MF_CalendarPrint(&this->calendar);  printf("Printing Date internal TOD:\n");  MF_TODPrint(&this->tod);  return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/int MF_DateGetFltDayOfYear(MF_Date this, double *day){  int iday;  int ret = MF_SUCCESS;    ret = MF_DateGetDayOfYear(this, &iday);  *day = (double) iday;  /* e.g. 0.1 days = 2.4 hours = 8640 seconds */  /* Handle the integer seconds and the normal case here.  this->tod.msec     turns out to be -1, not zero == MF_TIME_UNDEFINED */  if (this->tod.msec == MF_TIME_UNDEFINED)  {    *day += (this->tod.sec)      / (double) (MF_SID) ;   }  else  {    *day += (this->tod.sec + (this->tod.msec / 1000.0) )      / (double) (MF_SID) ;   }  return ret;}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateDelete"void MF_DateDelete (MF_Date this){  free(this);    return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -