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

📄 mf_calendar.c

📁 CCSM Research Tools: Community Atmosphere Model (CAM)
💻 C
字号:
/* MF_Calendar.c */#include "MF_Calendar.h"/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_CalendarConstruct"int MF_CalendarConstruct(MF_Calendar this, MF_CalendarType type, int year){  int i, j;  int dimStandard[13] = {0, 31,28,31, 30,31,30, 31,31,30, 31,30,31};  #ifdef MF_DEBUG  if((type != MF_NO_LEAP) && (type != MF_GREGORIAN) && (type != MF_360_DAY))      MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, "calendar type is not valid");#endif  if(year == MF_TIME_UNDEFINED){    MF_CalendarConstructUndefined(this);    this->type = type;    return(MF_SUCCESS);  }  /* Set the number of days per month according to the desired calendar.      Initialize arrays in case this method is used to rebuild an existing     calendar. */  this->dim[0] = MF_TIME_UNDEFINED;  this->dimRunningSum[0] = MF_TIME_UNDEFINED;  for(i=1; i<13; i++){    this->dimRunningSum[i] = 0;  }  if(type == MF_360_DAY){    for(i=1; i<13; i++){      this->dim[i] = 30;    }  }   else {    for(i=1; i<13; i++){      this->dim[i] = dimStandard[i];    }  }  /* Adjust the number of days if this is a leap year */  if((type == MF_GREGORIAN) && MF_IS_LEAP_YEAR(year)){    this->dim[2]=29;  }  /* Compute and store the running sum of days per month. */  for(i=2; i<13; i++){    for(j=1; j<i; j++){      this->dimRunningSum[i] += this->dim[j];    }    }  this->diy = this->dimRunningSum[12] + this->dim[12];  this->type=type;  return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_CalendarConstructUndefined"int MF_CalendarConstructUndefined(MF_Calendar this){  int i;  this->diy = MF_TIME_UNDEFINED;  this->type = MF_CALENDAR_TYPE_UNDEFINED;      for(i=0; i<13; i++){    this->dim[i] = MF_TIME_UNDEFINED;    this->dimRunningSum[i] = MF_TIME_UNDEFINED;  }  return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_CalendarBuildDayOfYear"int MF_CalendarBuildDayOfYear(MF_Calendar this, int month, int day, 			      int *dayOfYear){  *dayOfYear = this->dimRunningSum[month]+day;  if((this->diy == 366)&&(month > 2)) *dayOfYear += 1.;    return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_CalendarPrint"int MF_CalendarPrint(MF_Calendar this){  int i;  char str[32];  switch(this->type){    case MF_CALENDAR_TYPE_UNDEFINED:      strcpy(str, "MF_CALENDAR_TYPE_UNDEFINED");      break;    case MF_NO_LEAP:      strcpy(str, "MF_NO_LEAP");      break;    case MF_GREGORIAN:      strcpy(str, "MF_GREGORIAN");      break;    case MF_360_DAY:      strcpy(str, "MF_360_DAY");      break;    default:      strcpy(str, "UNRECOGNIZED CALENDAR TYPE");  }   printf("Printing Calendar:\n");  printf("type         = %s\n", str);  printf("days in year = %d\n", this->diy);  printf("days in month:");  for(i=1; i<13; i++){    printf(" %d", this->dim[i]);  }  printf("\n");  printf("running sum of days in month:");  for(i=1; i<13; i++){    printf(" %d", this->dimRunningSum[i]);  }  printf("\n");    return(MF_SUCCESS);}

⌨️ 快捷键说明

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