📄 mf_timemgr.c
字号:
/* MF_TimeMgr.c */#include "MF_TimeMgr.h"/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrNew"MF_TimeMgr MF_TimeMgrNew(MF_Time stepSize, MF_Date startDate, MF_Date stopDate, MF_Date baseDate){ MF_TimeMgr timeMgr; timeMgr = (MF_TimeMgr) malloc (sizeof(struct TimeMgrClass)); if(!timeMgr) return(MF_NULL); MF_TimeMgrConstruct(timeMgr, stepSize, startDate, stopDate, baseDate); return(timeMgr);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrNewIS"MF_TimeMgr MF_TimeMgrNewIS(int stepDays, int stepSecs, int startCalendarDate, int startTOD, int stopCalendarDate, int stopTOD, int baseCalendarDate, int baseTOD, MF_CalendarType type){ MF_TimeMgr timeMgr; timeMgr = (MF_TimeMgr) malloc (sizeof(struct TimeMgrClass)); if(!timeMgr) return(MF_NULL); MF_TimeMgrConstructIS(timeMgr, stepDays, stepSecs, startCalendarDate, startTOD, stopCalendarDate, stopTOD, baseCalendarDate, baseTOD, type); return(timeMgr);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrConstruct"int MF_TimeMgrConstruct(MF_TimeMgr this, MF_Time stepSize, MF_Date startDate, MF_Date stopDate, MF_Date baseDate){ #ifdef MF_DEBUG if((startDate->calendar.type != stopDate->calendar.type) || (baseDate->calendar.type != startDate->calendar.type)){ MF_ERRA(MF_ERR_ARG_OUTOFRANGE, 0, "start, stop and base dates must use the same calendar"); }#endif this->nstep = 0; MF_TimeCopyConstruct(&this->stepSize, stepSize); MF_DateCopyConstruct(&this->startDate, startDate); MF_DateCopyConstruct(&this->stopDate, stopDate); MF_DateCopyConstruct(&this->baseDate, baseDate); MF_DateCopyConstruct(&this->currDate, startDate); MF_DateConstructUndefined(&this->prevDate); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrConstructIS"int MF_TimeMgrConstructIS(MF_TimeMgr this, int stepDays, int stepSecs, int startCalendarDate, int startTOD, int stopCalendarDate, int stopTOD, int baseCalendarDate, int baseTOD, MF_CalendarType type){ MF_TimeClass stepSize; MF_DateClass startDate, stopDate, baseDate; MF_TimeConstructIS(&stepSize, stepDays, stepSecs); MF_DateConstructIS(&startDate, type, startCalendarDate, startTOD); MF_DateConstructIS(&stopDate, type, stopCalendarDate, stopTOD); MF_DateConstructIS(&baseDate, type, baseCalendarDate, baseTOD); MF_TimeMgrConstruct(this, &stepSize, &startDate, &stopDate, &baseDate); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrConstructNoBaseIS"int MF_TimeMgrConstructNoBaseIS(MF_TimeMgr this, int stepDays, int stepSecs, int startCalendarDate, int startTOD, int stopCalendarDate, int stopTOD, MF_CalendarType type){ int baseCalendarDate=startCalendarDate, baseTOD=startTOD; MF_TimeMgrConstructIS(this, stepDays, stepSecs, startCalendarDate, startTOD, stopCalendarDate, stopTOD, baseCalendarDate, baseTOD, type); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrConstructNoBase"int MF_TimeMgrConstructNoBase(MF_TimeMgr this, MF_Time stepSize, MF_Date startDate, MF_Date stopDate){ MF_DateClass baseDate; MF_DateCopyConstruct(&baseDate, startDate); MF_TimeMgrConstruct(this, stepSize, startDate, stopDate, &baseDate); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrAdvance"int MF_TimeMgrAdvance(MF_TimeMgr this){ MF_DateCopy(&this->prevDate, &this->currDate); MF_DateIncrement(&this->currDate, &this->currDate, &this->stepSize); ++this->nstep; return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrLastStep"int MF_TimeMgrLastStep(MF_TimeMgr this, MF_Bool *lastStep){ MF_DateClass temp; MF_DateConstructUndefined(&temp); MF_DateIncrement(&this->currDate, &temp, &this->stepSize); MF_DateIsLater(&this->stopDate, &temp, lastStep); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrSetStepSize"int MF_TimeMgrSetStepSize(MF_TimeMgr this, MF_Time stepSize){ MF_TimeCopy(&this->stepSize, stepSize); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrSetStepSizeIS"int MF_TimeMgrSetStepSizeIS(MF_TimeMgr this, int days, int seconds){ MF_TimeClass temp; MF_TimeConstructIS(&temp, days, seconds); MF_TimeMgrSetStepSize(this, &temp); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrGetStepSize"int MF_TimeMgrGetStepSize(MF_TimeMgr this, MF_Time stepSize){ MF_TimeCopy(stepSize, &this->stepSize); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrGetStepSizeIS"int MF_TimeMgrGetStepSizeIS(MF_TimeMgr this, int *days, int *seconds){ MF_TimeClass temp; MF_TimeConstructUndefined(&temp); MF_TimeMgrGetStepSize(this, &temp); MF_TimeGetIS(&temp, days, seconds); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrGetNStep"int MF_TimeMgrGetNStep(MF_TimeMgr this, int *nstep){ *nstep = this->nstep; return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrSetNStep"int MF_TimeMgrSetNStep(MF_TimeMgr this, int nstep){ this->nstep = nstep; return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrGetStartDate"int MF_TimeMgrGetStartDate(MF_TimeMgr this, MF_Date startDate){ MF_DateCopy(startDate, &this->startDate); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrGetStopDate"int MF_TimeMgrGetStopDate(MF_TimeMgr this, MF_Date stopDate){ MF_DateCopy(stopDate, &this->stopDate); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrGetBaseDate"int MF_TimeMgrGetBaseDate(MF_TimeMgr this, MF_Date baseDate){ MF_DateCopy(baseDate, &this->baseDate); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrGetCurrDate"int MF_TimeMgrGetCurrDate(MF_TimeMgr this, MF_Date currDate){ MF_DateCopy(currDate, &this->currDate); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrSetCurrDate"int MF_TimeMgrSetCurrDateIS(MF_TimeMgr this, int dateYYMMDD, int tod){ MF_CalendarType type; MF_DateGetCalendarType(&this->currDate, &type); MF_DateConstructIS(&this->currDate, type, dateYYMMDD, tod); /* Now update the previous date to reflect this change */ MF_DateDecrement(&this->currDate, &this->prevDate, &this->stepSize); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrGetPrevDate"int MF_TimeMgrGetPrevDate(MF_TimeMgr this, MF_Date prevDate){ MF_DateCopy(prevDate, &this->prevDate); return(MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrRestartWriteIS"int MF_TimeMgrRestartWriteIS(MF_TimeMgr this, MF_CalendarType *type, int *nstep, int *stepDays, int *stepSec, int *startYYMMDD, int *startSec, int *stopYYMMDD, int *stopSec, int *baseYYMMDD, int *baseSec, int *currYYMMDD, int *currSec){ /* Retrieve all calendar dates */ MF_TimeGetIS(&this->stepSize, stepDays, stepSec); MF_DateGetIS(&this->startDate, startYYMMDD, startSec); MF_DateGetIS(&this->stopDate, stopYYMMDD, stopSec); MF_DateGetIS(&this->baseDate, baseYYMMDD, baseSec); MF_DateGetIS(&this->currDate, currYYMMDD, currSec); /* Retrieve the calendar type */ MF_DateGetCalendarType(&this->currDate, type); /* Retrieve nstep */ *nstep = this->nstep; return (MF_SUCCESS);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrNewRestartReadIS"MF_TimeMgr MF_TimeMgrNewRestartReadIS(MF_CalendarType type, int nstep, int stepDays, int stepSec, int startYYMMDD, int startSec, int stopYYMMDD, int stopSec, int baseYYMMDD, int baseSec, int currYYMMDD, int currSec){ MF_TimeMgr timeMgr; /* Allocate space */ timeMgr = (MF_TimeMgr) malloc (sizeof(struct TimeMgrClass)); if(!timeMgr) return(MF_NULL); /* Initialize fields */ if (MF_SUCCESS != MF_TimeMgrRestartReadIS(timeMgr, type, nstep, stepDays, stepSec, startYYMMDD, startSec, stopYYMMDD, stopSec, baseYYMMDD, baseSec, currYYMMDD, currSec) ) { /* Initialization failed, so free memory and return error */ free(timeMgr); return (MF_NULL); } return (timeMgr);}/*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrRestartReadIS"int MF_TimeMgrRestartReadIS(MF_TimeMgr this, MF_CalendarType type, int nstep, int stepDays, int stepSec, int startYYMMDD, int startSec, int stopYYMMDD, int stopSec, int baseYYMMDD, int baseSec, int currYYMMDD, int currSec){ int rc; /* Construct the basic object (nstep is set to zero by this default constructor). */ rc = MF_TimeMgrConstructIS(this, stepDays, stepSec, startYYMMDD, startSec, stopYYMMDD, stopSec, baseYYMMDD, baseSec, type); /* Set the current date. This will also set prev date to be curr - tstep. */ MF_TimeMgrSetCurrDateIS(this, currYYMMDD, currSec); /* Set nstep */ this->nstep = nstep; return rc;} /*----------------------------------------------------------------------------*/#undef __FUNC__#define __FUNC__ "MF_TimeMgrDelete"void MF_TimeMgrDelete(MF_TimeMgr this){ free(this); return;}/*----------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -