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

📄 mf_date.c

📁 CCSM Research Tools: Community Atmosphere Model (CAM)
💻 C
📖 第 1 页 / 共 2 页
字号:
/* MF_Date.c */#include "MF_Date.h"/*--------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateNewIS"MF_Date MF_DateNewIS(MF_CalendarType type, int yearmmdd, int seconds) {  MF_Date date = MF_NULL;  date = (MF_Date) malloc (sizeof(struct DateClass));  if(!date) return(MF_NULL);  MF_DateConstructIS(date, type, yearmmdd, seconds);  return(date);}/*--------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateNewUndefined"MF_Date MF_DateNewUndefined() {  MF_Date date = MF_NULL;  date = (MF_Date) malloc (sizeof(struct DateClass));  if(!date) return(MF_NULL);  MF_DateConstructUndefined(date);  return(date);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateConstructIS"int MF_DateConstructIS(MF_Date this, MF_CalendarType type, int yearmmdd,   int seconds){  int year, month, day;  if((type == MF_CALENDAR_TYPE_UNDEFINED) || (yearmmdd == MF_TIME_UNDEFINED) ||      (seconds == MF_TIME_UNDEFINED)){    MF_DateConstructUndefined(this);    /* For cases in which the user wants to set the date's calendar type only. */    this->calendar.type = type;    return(MF_SUCCESS);  }  year = yearmmdd/10000;  month = (yearmmdd%10000)/100;  day = yearmmdd%100;  MF_CalendarConstruct(&this->calendar, type, year);  MF_TODConstructIS(&this->tod, seconds);#ifdef MF_DEBUG  if((day < 1) || (day > this->calendar.dim[month])){    MF_ERRA1(MF_ERR_ARG_OUTOFRANGE, 0, "day = %d", day);  }  if((month < 1) || (month > 12)){    MF_ERRA1(MF_ERR_ARG_OUTOFRANGE,0, "month = %d", month);  }#endif  /* Compute the Julian day (absolute reference day). */  MF_DATE_2_JULIAN_DAY(this->julianDay, year, month, day);  MF_CalendarBuildDayOfYear(&this->calendar, month, day, &this->dayOfYear);  this->year = year;  this->month = month;  this->day = day;  return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateConstructUndefined"int MF_DateConstructUndefined(MF_Date this){  this->julianDay = MF_TIME_UNDEFINED;  this->dayOfYear = MF_TIME_UNDEFINED;  this->year = MF_TIME_UNDEFINED;  this->month = MF_TIME_UNDEFINED;  this->day = MF_TIME_UNDEFINED;  MF_CalendarConstructUndefined(&this->calendar);  MF_TODConstructUndefined(&this->tod);      return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateCopyConstruct"int MF_DateCopyConstruct(MF_Date this, MF_Date orig){  this->calendar = orig->calendar;  this->tod = orig->tod;  this->year = orig->year;  this->month = orig->month;  this->day = orig->day;  this->julianDay = orig->julianDay;  this->dayOfYear = orig->dayOfYear;  return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateCopy"int MF_DateCopy(MF_Date this, MF_Date orig){#ifdef MF_DEBUG  if((this->calendar.type != orig->calendar.type) &&     (this->calendar.type != MF_CALENDAR_TYPE_UNDEFINED)){    MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, 	    "argument calendar types are different or uninitialized");  }#endif  MF_DateCopyConstruct(this, orig);  return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateSetIS"int MF_DateSetIS (MF_Date this, MF_CalendarType type, int yearmmdd, int seconds){#ifdef MF_DEBUG  if((MF_TIME_NEGATIVE_ATTR_IS(yearmmdd, seconds)) ||     (MF_TIME_UNDEFINED_ATTR_IS(yearmmdd, seconds))){    MF_ERRA2(MF_ERR_ARG_OUTOFRANGE, 0,     "yearmmdd or seconds are invalid or undefined: yearmmdd = %d, seconds = %d",    yearmmdd, seconds);  }#endif  MF_DateConstructIS (this, type, yearmmdd, seconds);  return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateGetIS"int MF_DateGetIS(MF_Date this, int *yearmmdd, int *seconds){  *yearmmdd = this->year*10000 + this->month*100 + this->day;  *seconds = this->tod.sec;  return(MF_SUCCESS);		 }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateGetDayOfYear"int MF_DateGetDayOfYear(MF_Date this, int *dayOfYear){  *dayOfYear = this->dayOfYear;  return(MF_SUCCESS);		 }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateGetCalendarType"int MF_DateGetCalendarType(MF_Date this, MF_CalendarType *type){  *type = this->calendar.type;    return (MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_Date2Str"int MF_Date2Str(MF_Date this, char *str){  char strLocal[32];  /* Implementation */  return(MF_SUCCESS);		 }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateIncrement"int MF_DateIncrement(MF_Date this, MF_Date incDate, MF_Time time){  int year, month, day;  int ndays;#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");  }#endif  /* Add the times of day for the original date and time increment      and return the result as a new time of day and a number of days. */  MF_TODIncrement(&this->tod, &time->tod, &incDate->tod, &ndays);  ndays += time->day;  incDate->julianDay = this->julianDay + ndays;  switch(this->calendar.type){    case MF_GREGORIAN:      MF_JULIAN_DAY_2_DATE(incDate->julianDay, year, month, day);      break;    case MF_NO_LEAP:      month = this->month;        year = this->year+(ndays/this->calendar.diy);      day = this->day+(ndays%this->calendar.diy);      while(day>this->calendar.dim[month]){        day-=this->calendar.dim[month];        month+=1;        if(month==13){          ++year;          month=1;        }      }      break;    default:      MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, 	      "calendar type is not supported by this method");  }          incDate->year = year;  incDate->month = month;  incDate->day = day;  MF_CalendarConstruct(&incDate->calendar, this->calendar.type, year);  MF_CalendarBuildDayOfYear(&incDate->calendar, month, day, &incDate->dayOfYear);  return(MF_SUCCESS);		 }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateDecrement"int MF_DateDecrement(MF_Date this, MF_Date decDate, MF_Time time){  int year, month, day;  int ndays;#ifdef MF_DEBUG  if((this->calendar.type != decDate->calendar.type) &&     (decDate->calendar.type != MF_CALENDAR_TYPE_UNDEFINED)){    MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, 	    "argument calendar types are different or uninitialized");  }#endif  /* Add the times of day for the original date and time increment      and return the result as a new time of day and a number of days. */  MF_TODDecrement(&this->tod, &time->tod, &decDate->tod, &ndays);  ndays += time->day;  decDate->julianDay = this->julianDay - ndays;  switch(this->calendar.type){    case MF_GREGORIAN:      MF_JULIAN_DAY_2_DATE(decDate->julianDay, year, month, day);      break;    case MF_NO_LEAP:      month = this->month;        year = this->year-(ndays/this->calendar.diy);      day = this->day-(ndays%this->calendar.diy); /* days may be negative at this point */      while(day<=0){        month-=1;        if(month==0){          --year;          month=12;        }        day+=this->calendar.dim[month];      }      break;    default:      MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, 	      "calendar type is not supported by this method");  }          decDate->year = year;  decDate->month = month;  decDate->day = day;  MF_CalendarConstruct(&decDate->calendar, this->calendar.type, year);  MF_CalendarBuildDayOfYear(&decDate->calendar, month, day, &decDate->dayOfYear);  return(MF_SUCCESS);		 }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_DateIncrementSec"int MF_DateIncrementSec(MF_Date this, MF_Date incDate, int nseconds){  MF_TimeClass time;

⌨️ 快捷键说明

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