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

📄 esmc_date.c

📁 CCSM Research Tools: Community Atmosphere Model (CAM)
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: ESMC_Date.c,v 1.1.6.1 2002/04/24 03:25:43 erik Exp $ */#include "ESMC_Date.h"#include "ESMC_TimeMgmtUtil.h"#include "ESMC_Error.h"/*--------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateNewIS"int ESMC_DateNewIS(ESMC_Date *thisp, ESMC_CalendarType type, int yearmmdd, int seconds) {  int rc;  *thisp = (ESMC_Date) malloc (sizeof(struct DateClass));  rc = ESMC_DateConstructIS(*thisp, type, yearmmdd, seconds);  if (rc != ESMC_SUCCESS)    {      free (*thisp);      *thisp = 0;      return rc;    }  return(ESMC_SUCCESS);}/*--------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateNewUndefined"int ESMC_DateNewUndefined(ESMC_Date *thisp) {  int rc;  *thisp = (ESMC_Date) malloc (sizeof(struct DateClass));  rc = ESMC_DateConstructUndefined(*thisp);    if (rc != ESMC_SUCCESS)    {      free (*thisp);      *thisp = 0;      return rc;    }    return(ESMC_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateConstructIS"int ESMC_DateConstructIS(ESMC_Date this, ESMC_CalendarType type, int yearmmdd,   int seconds){  int year, month, day;  if((type == ESMC_CALENDAR_TYPE_UNDEFINED) ||      (seconds == ESMC_TIME_UNDEFINED)){    ESMC_DateConstructUndefined(this);    /* For cases in which the user wants to set the date's calendar type only. */    this->calendar.type = type;    return(ESMC_SUCCESS);  }  year = yearmmdd/10000;  if (yearmmdd < 0)     yearmmdd *= -1;  month = (yearmmdd%10000)/100;  day = yearmmdd%100;  ESMC_CalendarConstruct(&this->calendar, type, year);  ESMC_TODConstructIS(&this->tod, seconds);#ifdef ESMC_DEBUG  if((day < 1) || (day > this->calendar.dim[month])){    ESMC_ERRA1(ESMC_ERR_ARG_OUTOFRANGE, 0, "day = %d", day);  }  if((month < 1) || (month > 12)){    ESMC_ERRA1(ESMC_ERR_ARG_OUTOFRANGE,0, "month = %d", month);  }#endif  /* Compute the Julian day (absolute reference day). */  ESMC_DATE_2_JULIAN_DAY(this->julianDay, year, month, day);  ESMC_CalendarBuildDayOfYear(&this->calendar, month, day, &this->dayOfYear);  this->year = year;  this->month = month;  this->day = day;  return(ESMC_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateConstructUndefined"int ESMC_DateConstructUndefined(ESMC_Date this){  this->julianDay = ESMC_TIME_UNDEFINED;  this->dayOfYear = ESMC_TIME_UNDEFINED;  this->year = ESMC_TIME_UNDEFINED;  this->month = ESMC_TIME_UNDEFINED;  this->day = ESMC_TIME_UNDEFINED;  ESMC_CalendarConstructUndefined(&this->calendar);  ESMC_TODConstructUndefined(&this->tod);      return(ESMC_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateCopyConstruct"int ESMC_DateCopyConstruct(ESMC_Date this, ESMC_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(ESMC_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateCopy"int ESMC_DateCopy(ESMC_Date this, ESMC_Date orig){#ifdef ESMC_DEBUG  if((this->calendar.type != orig->calendar.type) &&     (this->calendar.type != ESMC_CALENDAR_TYPE_UNDEFINED)){    ESMC_ERRA(ESMC_ERR_ARG_OUTOFRANGE, 0, 	    "argument calendar types are different or uninitialized");  }#endif  ESMC_DateCopyConstruct(this, orig);  return(ESMC_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateSetIS"int ESMC_DateSetIS (ESMC_Date this, ESMC_CalendarType type, int yearmmdd, int seconds){  ESMC_DateConstructIS (this, type, yearmmdd, seconds);  return(ESMC_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateGetIS"int ESMC_DateGetIS(ESMC_Date this, int *yearmmdd, int *seconds){  int year;  if (this->year < 0)    year = -1*this->year;  else    year = this->year;  *yearmmdd = year*10000 + this->month*100 + this->day;  *seconds = this->tod.sec;  if (this->year < 0)    *yearmmdd *= -1;  return(ESMC_SUCCESS);		 }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateGetDayOfYear"int ESMC_DateGetDayOfYear(ESMC_Date this, int *dayOfYear){  *dayOfYear = this->dayOfYear;  return(ESMC_SUCCESS);		 }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateGetCalendarType"int ESMC_DateGetCalendarType(ESMC_Date this, ESMC_CalendarType *type){  *type = this->calendar.type;    return (ESMC_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_Date2Str"int ESMC_Date2Str(ESMC_Date this, char *str){  /* Implementation */  return(ESMC_SUCCESS);		 }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateIncrement"int ESMC_DateIncrement(ESMC_Date this, ESMC_Date incDate, ESMC_Time time){  int year, month, day;  int ndays;#ifdef ESMC_DEBUG  if((this->calendar.type != incDate->calendar.type) &&     (incDate->calendar.type != ESMC_CALENDAR_TYPE_UNDEFINED)){    ESMC_ERRA(ESMC_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. */  ESMC_TODIncrement(&this->tod, &time->tod, &incDate->tod, &ndays);  ndays += time->day;  incDate->julianDay = this->julianDay + ndays;  switch(this->calendar.type){    case ESMC_GREGORIAN:      ESMC_JULIAN_DAY_2_DATE(incDate->julianDay, year, month, day);      break;    case ESMC_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:      ESMC_ERRA(ESMC_ERR_ARG_OUTOFRANGE, 0, 	      "calendar type is not supported by this method");  }          incDate->year = year;  incDate->month = month;  incDate->day = day;  ESMC_CalendarConstruct(&incDate->calendar, this->calendar.type, year);  ESMC_CalendarBuildDayOfYear(&incDate->calendar, month, day, &incDate->dayOfYear);  return(ESMC_SUCCESS);		 }/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "ESMC_DateDecrement"int ESMC_DateDecrement(ESMC_Date this, ESMC_Date decDate, ESMC_Time time){  int year, month, day;  int ndays;#ifdef ESMC_DEBUG  if((this->calendar.type != decDate->calendar.type) &&     (decDate->calendar.type != ESMC_CALENDAR_TYPE_UNDEFINED)){    ESMC_ERRA(ESMC_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. */  ESMC_TODDecrement(&this->tod, &time->tod, &decDate->tod, &ndays);  ndays += time->day;  decDate->julianDay = this->julianDay - ndays;  switch(this->calendar.type){    case ESMC_GREGORIAN:      ESMC_JULIAN_DAY_2_DATE(decDate->julianDay, year, month, day);      break;    case ESMC_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:      ESMC_ERRA(ESMC_ERR_ARG_OUTOFRANGE, 0, 	      "calendar type is not supported by this method");  }          decDate->year = year;  decDate->month = month;  decDate->day = day;  ESMC_CalendarConstruct(&decDate->calendar, this->calendar.type, year);  ESMC_CalendarBuildDayOfYear(&decDate->calendar, month, day, &decDate->dayOfYear);

⌨️ 快捷键说明

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