void WriteStatistics(int pos) { int dual_accept = 0, dual_proposed = 0; float dual_rate = 0, opt3_rate = 0, subgrad_rate = 0, worst_rate = 0, accept_rate = 0; LocalTime(&total_time_cron); if (total_time_cron < lost_time_cron) (total_time_cron += 86400); total_time_cron -= lost_time_cron; dual_proposed = ProposedSolution[agent_dual] + ProposedSolution[agent_3opt] + ProposedSolution[agent_subgrad]; dual_accept = dual_proposed - dual_equal - dual_worst; dual_rate = ((float) SolutionAccept[agent_dual] / MaxLenDualMem) * 100; opt3_rate = ((float) SolutionAccept[agent_3opt] / MaxLenDualMem) * 100; subgrad_rate = ((float) SolutionAccept[agent_subgrad] / MaxLenDualMem) * 100; worst_rate = ((float) dual_worst / dual_proposed) * 100; accept_rate = ((float) dual_accept / dual_proposed) * 100; fprintf(fstts,"\n%6d %6d %6d %6d %6d %6d %5.1f %5.1f %13.3f%4d%13.3f%5.1f%13.3f%5.1f%13.3f%5.1f",total_time_cron, DualMem[pos].proc_time, dual_proposed, dual_accept, dual_equal, dual_worst, worst_rate, accept_rate, DualMem[nb_dual_sol_mem - 1].value, DualMem[nb_dual_sol_mem - 1].nb_cuts, BestSolution[agent_dual], dual_rate, BestSolution[agent_subgrad], subgrad_rate, BestSolution[agent_3opt], opt3_rate); fflush(fstts); }
word pl_convert_time(term_t time, term_t year, term_t month, term_t day, term_t hour, term_t minute, term_t second, term_t usec) { double tf; if ( PL_get_float(time, &tf) && tf <= PLMAXINT && tf >= PLMININT ) { long t = (long) tf; long us = (long)((tf - (double) t) * 1000.0); struct tm *tm = LocalTime(&t); if ( PL_unify_integer(year, tm->tm_year + 1900) && PL_unify_integer(month, tm->tm_mon + 1) && PL_unify_integer(day, tm->tm_mday) && PL_unify_integer(hour, tm->tm_hour) && PL_unify_integer(minute, tm->tm_min) && PL_unify_integer(second, tm->tm_sec) && PL_unify_integer(usec, us) ) succeed; else fail; } return PL_error("convert_time", 8, NULL, ERR_TYPE, ATOM_time_stamp, time); }
// returns the current gate we are in, either in the past or in the future. // It does not matter if it is still valid (it is expired). // There is ALWAYS an activegate, it cannot be negative! int InitActiveGate() { int timenow; timenow=LocalTime(); if (timenow<PGOpenTime) return(0); if (timenow>PGCloseTime) return(PGNumberOfGates-1); return(RunningGate()); }
static char *tstring(time_t t) { static pstring buf; pstrcpy(buf, asctime(LocalTime(&t))); all_string_sub(buf," "," ",sizeof(buf)); return buf; }
void CLiveRoomRankManager::OnUpdate(int nTimeElapse) { if (m_bHasUpdateBoard) { m_nTideUpdateTime += nTimeElapse; if (m_nTideUpdateTime >= m_nTideUpdateInterval) { m_nTideUpdateTime -= m_nTideUpdateInterval; DoUpdate(); } } else { time_t tNow = time(NULL); struct tm tmNow; LocalTime(&tNow, &tmNow); int nDailySeconds = tmNow.tm_hour * 3600 + tmNow.tm_min * 60 + tmNow.tm_sec; if (nDailySeconds >= m_nFirstUpdateTime) { DoUpdate(); m_bHasUpdateBoard = true; } } }
LocalTime toLocal(const Time & time) { /* struct tm tmt; makeLocalTime((time_t)time.Second(), tmt); return LocalTime(timeGM(&tmt), time.microSecond());*/ return LocalTime(time.Second(), time.microSecond()); }
// Returns the current open gate number, 0-x, or -1 (negative) if out of time. // This is NOT the next start! It tells you if a gate is open right now, within time limits. int RunningGate() { if(!UseGates()) { return (-1); } int timenow, gate, gatetime; timenow=LocalTime(); if (timenow<PGOpenTime || timenow>PGCloseTime) return(-1); // search up to gates+1 ex. 12.40 > 13:00 is end time // we are checking the END of the gate, so it is like having a gate+1 for (gate=1; gate<PGNumberOfGates; gate++) { gatetime=PGOpenTime + (gate * PGGateIntervalTime *60); // timenow cannot be lower than gate 0, because gate0 is PGOpenTime if (timenow < gatetime) { #if DEBUGATE StartupStore(_T("... Timenow: %d RunningGate n.%d (0-%d)\n"),timenow,gate-1,PGNumberOfGates-1); #endif return(gate-1); } } if(gate == PGNumberOfGates && timenow < PGCloseTime) { return PGNumberOfGates-1; } StartupStore(_T("--- RunningGate invalid: timenow=%d Open=%d Close=%d NumGates=%d Interval=%d%s"), timenow,PGOpenTime,PGCloseTime,PGNumberOfGates,PGGateIntervalTime,NEWLINE); return(-1); }
// Do we have some gates available, either running right now or in the future? // Basically mytime <CloseTime... bool HaveGates() { int timenow; timenow=LocalTime(); if (timenow>PGCloseTime) return(false); else return(true); }
char MaxExeTimeCron() { LocalTime(&total_time_cron); if (total_time_cron < lost_time_cron) (total_time_cron += 86400); total_time_cron -= lost_time_cron; return(total_time_cron < MaxExeTime); }
// Is the gate time open? bool IsGateOpen() { int timenow; timenow=LocalTime(); if ( (timenow>=PGOpenTime) && (timenow<=PGCloseTime)) return true; else return false; }
std::string Clock::ToHumanReadableString(const time_t t, const char* format) { char buffer[255]; tm timeinfo; if (::strftime(buffer, 255, format, &LocalTime(timeinfo, t)) == 0) { return std::string(); } else { return std::string(buffer); } }
VOID CMT::distJournal(VOID) { this->posCurrent = this->center; this->posChange = this->distCoeff * norm(posCurrent - posPrev); if (posChange < this->distThresh) { posChange = 0; } this->posGrowth += this->posChange; this->posPrev = this->posCurrent; this->noteFile << LocalTime(TRUE); if (posChange == 0) { this->noteFile << "\n"; } else { this->noteFile << "\t" << to_string(posChange) << "\n"; } }
// Create a backup of the configuration file void BackupCfgWEx(CFG_RW *rw, FOLDER *f, wchar_t *original, UINT revision_number) { wchar_t dirname[MAX_PATH]; wchar_t filename[MAX_PATH]; wchar_t fullpath[MAX_PATH]; wchar_t datestr[MAX_PATH]; SYSTEMTIME st; // Validate arguments if (f == NULL || filename == NULL || rw == NULL) { return; } // Determine the directory name UniFormat(dirname, sizeof(dirname), L"@backup.%s", original[0] == L'@' ? original + 1 : original); // Determine the file name LocalTime(&st); UniFormat(datestr, sizeof(datestr), L"%04u%02u%02u%02u_%s", st.wYear, st.wMonth, st.wDay, st.wHour, original[0] == L'@' ? original + 1 : original); if (revision_number == INFINITE) { UniStrCpy(filename, sizeof(filename), datestr); } else { UniFormat(filename, sizeof(filename), L"%08u_%s", revision_number, original[0] == L'@' ? original + 1 : original); } // Don't save if the date and time has not been changed if (UniStrCmpi(datestr, rw->LastSavedDateStr) == 0) { return; } UniStrCpy(rw->LastSavedDateStr, sizeof(rw->LastSavedDateStr), datestr); // Check the existence of file name if (IsFileExistsW(filename)) { return; } // Create the directory MakeDirW(dirname); // Save the file UniFormat(fullpath, sizeof(fullpath), L"%s/%s", dirname, filename); CfgSaveW(f, fullpath); }
// returns the current gate we are in, either in the past or in the future. // It does not matter if it is still valid (it is expired). // There is ALWAYS an activegate, it cannot be negative! int InitActiveGate() { ActiveGate = -1; PGOpenTime=((PGOpenTimeH*60)+PGOpenTimeM)*60; PGCloseTime=((PGCloseTimeH*60)+PGCloseTimeM)*60;; if (PGCloseTime>86399) PGCloseTime=86399; // 23:59:59 int timenow; timenow=LocalTime(); if (timenow<PGOpenTime) return(0); if (timenow>PGCloseTime) return(PGNumberOfGates-1); return(RunningGate()); }
void CLiveRoomRankManager::SetLiveRoomConfig( const char *pstrStartTime, const char *pstrEndTime, int nLeaderBoardSize, const char *pstrFirstUpdateTime, int nUpdateInterval,int nAuditionBaseScore) { m_nStartTime = SetTime(pstrStartTime); m_nEndTime = SetTime(pstrEndTime); m_nLeaderBoardSize = nLeaderBoardSize; std::string strTimeBuff("2014-07-01 "); if (pstrFirstUpdateTime) strTimeBuff.append(pstrFirstUpdateTime); time_t tFirstUpdateTime = SetTime(strTimeBuff.c_str()); struct tm tmFirstUpdateTime; LocalTime(&tFirstUpdateTime, &tmFirstUpdateTime); m_nFirstUpdateTime = tmFirstUpdateTime.tm_hour * 3600 + tmFirstUpdateTime.tm_min * 60 + tmFirstUpdateTime.tm_sec; m_nTideUpdateInterval = nUpdateInterval * 1000; m_nAuditionBaseScore = nAuditionBaseScore; }
// Initialize tiny log TINY_LOG *NewTinyLog() { char name[MAX_PATH]; SYSTEMTIME st; TINY_LOG *t; LocalTime(&st); MakeDir(TINY_LOG_DIRNAME); Format(name, sizeof(name), TINY_LOG_FILENAME, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); t = ZeroMalloc(sizeof(TINY_LOG)); StrCpy(t->FileName, sizeof(t->FileName), name); t->io = FileCreate(name); t->Lock = NewLock(); return t; }
time_t COnlineRewardInfoMgr::GetResetTime(time_t nNow) { if (nNow == 0) { nNow = time(NULL); } struct tm tTime; LocalTime(&nNow, &tTime); tTime.tm_hour = m_nResetHour; tTime.tm_min = m_nResetMin; tTime.tm_sec = m_nResetSec; time_t nTodayResetTime = mktime(&tTime); time_t nResetTime = nTodayResetTime; if (nNow >= nTodayResetTime) { nResetTime = nTodayResetTime + 24 * 60 * 60 ; } return nResetTime; }
// Returns the next gate number, 0-x, -1 (negative) if no gates left or time is over int NextGate() { int timenow, gate, gatetime; timenow=LocalTime(); if (timenow>PGCloseTime) { #if DEBUGATE StartupStore(_T("... Timenow: %d over, gate closed at %d\n"),timenow, PGCloseTime); #endif return(-1); } for (gate=0; gate<PGNumberOfGates; gate++) { gatetime=PGOpenTime + (gate * PGGateIntervalTime *60); if (timenow < gatetime) { #if DEBUGATE StartupStore(_T("... Timenow: %d Nextgate is n.%d(0-%d) at %d\n"),timenow, gate, PGNumberOfGates-1, gatetime); #endif return(gate); } } #if DEBUGATE StartupStore(_T("... Timenow: %d no NextGate\n"),timenow); #endif return(-1); }
static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct connections_data crec; if (dbuf.dsize != sizeof(crec)) return 0; memcpy(&crec, dbuf.dptr, sizeof(crec)); if (crec.cnum == -1) return 0; if (!process_exists(crec.pid) || !Ucrit_checkUsername(uidtoname(crec.uid))) { return 0; } d_printf("%-10.10s %5d %-12s %s", crec.name,(int)crec.pid, crec.machine, asctime(LocalTime(&crec.start))); return 0; }
void InitParamHashTable(int MaxLenDualMem_i, int MaxLenCutMem_i, int LenHashTab_i, int CutsofSol_i, int MaxSolDualAg_i) { int i = 0; MaxLenDualMem = MaxLenDualMem_i; MaxLenCutMem = MaxLenCutMem_i; LenHashTab = LenHashTab_i; CutsofSol = CutsofSol_i; MaxSolDualAg = ((float) MaxSolDualAg_i / 100); DualMem = (DualType *) malloc(MaxLenDualMem * sizeof(DualType)); memset( DualMem, 0, MaxLenDualMem * sizeof(DualType)); CutMem = (CutType *) malloc(MaxLenCutMem * sizeof(CutType)); memset( CutMem, 0, MaxLenCutMem * sizeof(CutType)); first_free = LenHashTab; for (i = 0; i < LenHashTab; i++) CutMem[i] = (CutType) {FALSE,FALSE,0,NULL,0,i,-1,-1,0}; for (i = LenHashTab; i < MaxLenCutMem-1; i++) CutMem[i] = (CutType) {FALSE,FALSE,0,NULL,0,i,-1,i+1,0}; CutMem[i] = (CutType) {FALSE,FALSE,0,NULL,0,i,-1,-1,0}; LocalTime(&lost_time_cron); }
// autonomous check for usegates, and current chosen activegate is open, so a valid start // is available crossing the start sector.. bool ValidGate() { // always ok to start, if no usegates if (!UseGates()) return true; if (ActiveGate <0 || ActiveGate>=PGNumberOfGates) { #if DEBUGTGATES StartupStore(_T("... ValidGate false, bad ActiveGate\n")); #endif return false; } int timenow; timenow=LocalTime(); if (timenow>PGCloseTime) { #if DEBUGTGATES StartupStore(_T("... ValidGate false, timenow>PGCloseTime\n")); #endif return false; // HaveGates } int timegate; timegate=GateTime(ActiveGate); if (timegate<1) { #if DEBUGTGATES StartupStore(_T("... ValidGate false, GateTime returned<0 for ActiveGate=%d\n"),ActiveGate); #endif return false; } if ( timenow<timegate ) { #if DEBUGTGATES StartupStore(_T("... ValidGate false, timenow<timegate for ActiveGate=%d\n"),ActiveGate); #endif return false; } #if DEBUGTGATES StartupStore(_T("... ValidGate TRUE for ActiveGate=%d\n"),ActiveGate); #endif return true; }
static void print_share_mode(share_mode_entry *e, char *fname) { static int count; if (count==0) { printf("Locked files:\n"); printf("Pid DenyMode R/W Oplock Name\n"); printf("--------------------------------------------------\n"); } count++; printf("%-5d ",e->pid); switch ((e->share_mode>>4)&0xF) { case DENY_NONE: printf("DENY_NONE "); break; case DENY_ALL: printf("DENY_ALL "); break; case DENY_DOS: printf("DENY_DOS "); break; case DENY_READ: printf("DENY_READ "); break; case DENY_WRITE:printf("DENY_WRITE "); break; } switch (e->share_mode&0xF) { case 0: printf("RDONLY "); break; case 1: printf("WRONLY "); break; case 2: printf("RDWR "); break; } if((e->op_type & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) printf("EXCLUSIVE+BATCH "); else if (e->op_type & EXCLUSIVE_OPLOCK) printf("EXCLUSIVE "); else if (e->op_type & BATCH_OPLOCK) printf("BATCH "); else printf("NONE "); printf(" %s %s",fname,asctime(LocalTime((time_t *)&e->time.tv_sec))); }
// Returns the gatetime difference to current local time. Positive if gate is in the future. int GateTimeDiff(int gate) { int timenow, gatetime; timenow=LocalTime(); gatetime=PGOpenTime + (gate * PGGateIntervalTime *60); return(gatetime-timenow); }
time_t Clock::Tick() { time_ = ::time(0); LocalTime(timeinfo_, time_); return time_; }
static void print_share_mode(share_mode_entry *e, char *fname) { static int count; if (count==0) { d_printf("Locked files:\n"); d_printf("Pid DenyMode Access R/W Oplock Name\n"); d_printf("--------------------------------------------------------------\n"); } count++; if (Ucrit_checkPid(e->pid)) { d_printf("%-5d ",(int)e->pid); switch (GET_DENY_MODE(e->share_mode)) { case DENY_NONE: d_printf("DENY_NONE "); break; case DENY_ALL: d_printf("DENY_ALL "); break; case DENY_DOS: d_printf("DENY_DOS "); break; case DENY_READ: d_printf("DENY_READ "); break; case DENY_WRITE: printf("DENY_WRITE "); break; case DENY_FCB: d_printf("DENY_FCB "); break; } d_printf("0x%-8x ",(unsigned int)e->desired_access); switch (e->share_mode&0xF) { case 0: d_printf("RDONLY "); break; case 1: d_printf("WRONLY "); break; case 2: d_printf("RDWR "); break; } if((e->op_type & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) d_printf("EXCLUSIVE+BATCH "); else if (e->op_type & EXCLUSIVE_OPLOCK) d_printf("EXCLUSIVE "); else if (e->op_type & BATCH_OPLOCK) d_printf("BATCH "); else if (e->op_type & LEVEL_II_OPLOCK) d_printf("LEVEL_II "); else d_printf("NONE "); d_printf(" %s %s",fname, asctime(LocalTime((time_t *)&e->time.tv_sec))); } }
int clsPI_MSM::JulianDay(time_t date) { struct tm dateInfo; LocalTime(date,&dateInfo); return dateInfo.tm_yday + 1; }
// this needs to be publicly available, for data paraser double GetTimezoneOffset(double t) { return (t - LocalTime(t)) / kMsecPerMinute; }
int main(int argc, char *argv[]) { FILE *f; pstring fname; int uid, c; static pstring servicesf = CONFIGFILE; extern char *optarg; int verbose = 0, brief =0; BOOL processes_only=False; int last_pid=0; struct session_record *ptr; TimeInit(); setup_logging(argv[0],True); charset_initialise(); DEBUGLEVEL = 0; dbf = fopen("/dev/null","w"); if (getuid() != geteuid()) { printf("smbstatus should not be run setuid\n"); return(1); } while ((c = getopt(argc, argv, "pds:u:b")) != EOF) { switch (c) { case 'b': brief = 1; break; case 'd': verbose = 1; break; case 'p': processes_only = 1; break; case 's': pstrcpy(servicesf, optarg); break; case 'u': /* added by OH */ Ucrit_addUsername(optarg); /* added by OH */ break; default: fprintf(stderr, "Usage: %s [-d] [-p] [-s configfile] [-u username]\n", *argv); /* changed by OH */ return (-1); } } get_myname(myhostname, NULL); if (!lp_load(servicesf,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); return (-1); } if (verbose) { printf("using configfile = %s\n", servicesf); printf("lockdir = %s\n", *lp_lockdir() ? lp_lockdir() : "NULL"); } pstrcpy(fname,lp_lockdir()); standard_sub_basic(fname); trim_string(fname,"","/"); pstrcat(fname,"/STATUS..LCK"); f = fopen(fname,"r"); if (!f) { printf("Couldn't open status file %s\n",fname); if (!lp_status(-1)) printf("You need to have status=yes in your smb config file\n"); return(0); } else if (verbose) { printf("Opened status file %s\n", fname); } uid = getuid(); if (!processes_only) { printf("\nSamba version %s\n",VERSION); if (brief) { printf("PID Username Machine Time logged in\n"); printf("-------------------------------------------------------------------\n"); } else { printf("Service uid gid pid machine\n"); printf("----------------------------------------------\n"); } } while (!feof(f)) { if (fread(&crec,sizeof(crec),1,f) != 1) break; if ( crec.magic == 0x280267 && process_exists(crec.pid) && Ucrit_checkUsername(uidtoname(crec.uid)) /* added by OH */ ) { if (brief) { ptr=srecs; while (ptr!=NULL) { if ((ptr->pid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) { if (ptr->start > crec.start) ptr->start=crec.start; break; } ptr=ptr->next; } if (ptr==NULL) { ptr=(struct session_record *) malloc(sizeof(struct session_record)); ptr->uid=crec.uid; ptr->pid=crec.pid; ptr->start=crec.start; strncpy(ptr->machine,crec.machine,30); ptr->machine[30]='\0'; ptr->next=srecs; srecs=ptr; } } else { Ucrit_addPid(crec.pid); /* added by OH */ if (processes_only) { if (last_pid != crec.pid) printf("%d\n",crec.pid); last_pid = crec.pid; /* XXXX we can still get repeats, have to add a sort at some time */ } else printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", crec.name,uidtoname(crec.uid),gidtoname(crec.gid),crec.pid, crec.machine,crec.addr, asctime(LocalTime(&crec.start))); } } } fclose(f); if (processes_only) exit(0); if (brief) { ptr=srecs; while (ptr!=NULL) { printf("%-8d%-10.10s%-30.30s%s",ptr->pid,uidtoname(ptr->uid),ptr->machine,asctime(LocalTime(&(ptr->start)))); ptr=ptr->next; } printf("\n"); exit(0); } printf("\n"); locking_init(1); if (share_mode_forall(print_share_mode) <= 0) printf("No locked files\n"); printf("\n"); share_status(stdout); locking_end(); return (0); }
int YLD::Execute() { CheckInputData(); initialOutputs(); struct tm timeinfo; LocalTime(m_date, &timeinfo); timeinfo.tm_mon = 0; timeinfo.tm_mday = 0; timeinfo.tm_hour = 0; timeinfo.tm_min = 0; timeinfo.tm_sec = 0; timeinfo.tm_isdst = false; time_t tYear = mktime(&timeinfo); time_t harvestDate = tYear + m_harvestDate; #pragma omp parallel for for (int i = 0; i < m_nCells; i++) { if (m_date > harvestDate && !m_harvested) { m_harvested = true; m_common->m_classification = (int) (m_classification[i]); //Harvest index //float harvestIndex = 0.0f;// potential harvest index for a given day //float totalPlantET = 0.0f;//actual ET simulated during life of plant //float totalPlantPET = 0.0f;//potential ET simulated during life of plant ////get total ET and PET(see grow.f Line 289-292) from zhiqiang if (m_frPHU[i] > 0.5 && m_frPHU[i] < m_frDeclineLAI[i]) { m_totalPlantET[i] += m_totalWaterUptake[i] + m_soilET[i]; m_totalPlantPET[i] += m_PET[i]; } // water deficiency factor m_wur[i] = 100.0f; if (m_totalPlantPET[i] > 10) m_wur[i] *= m_totalPlantET[i] / m_totalPlantPET[i]; //get optimal harvest index, p309 5:2.4.1 m_HI[i] = m_HiOpt[i] * 100.0f * m_frPHU[i] / (100.0f * m_frPHU[i] + exp(11.1f - 10.0f * m_frPHU[i])); m_Hiact[i] = m_HI[i] - m_HiMin[i] * (m_wur[i] / (m_wur[i] + exp(6.13f - 0.0883f * m_wur[i]))) + m_HiMin[i]; m_HI[i] = min(m_HI[i], m_Hiact[i]); //float yield = 0.0f; if (m_HiOpt[i] > 1.001) m_yield[i] = m_biomass[i] * (1.0f - 1.0f / (1.0f + m_HI[i])); else m_yield[i] = m_biomassAG[i] * m_HI[i]; m_yield[i] = max(0.0f, m_yield[i]); m_harvestEfficiency[i] = 0.5f; //harvestEfficiency read from database //IsGrain should read from database if (m_common->IsGrain())//grain harvest, no residue, see harvgrainop.f { m_yield[i] *= m_harvestEfficiency[i]; m_yieldN[i] = max(0.0f, min(m_yield[i] * m_frNyld[i], 0.85f * m_biomassN[i])); m_yieldP[i] = max(0.0f, min(m_yield[i] * m_frPyld[i], 0.85f * m_biomassP[i])); m_biomass[i] -= m_yield[i]; } else //biomass harvest, has residue, residue redistribute to soil layer, see harvestop.f { //divide yield to two parts:clip and yield m_clip[i] = m_yield[i] * (1 - m_harvestEfficiency[i]); m_yield[i] -= m_clip[i]; m_clip[i] = max(0.0f, m_clip[i]); m_yield[i] = max(0.0f, m_yield[i]); //harvest index override read from database //get N&P in clip and yield[i] m_yieldN[i] = max(0.0f, min(m_yield[i] * m_frNyld[i], 0.8f * (m_biomassN[i]))); m_yieldP[i] = max(0.0f, min(m_yield[i] * m_frPyld[i], 0.8f * (m_biomassP[i]))); m_clipN[i] = max(0.0f, min(m_clip[i] * m_frNyld[i], m_biomassN[i] - m_yieldN[i])); //N in clip residual,needed by nitrient cycling module m_clipP[i] = max(0.0f, min(m_clip[i] * m_frPyld[i], m_biomassP[i] - m_yieldP[i])); //P in clip residual,needed by nitrient cycling module //reset LAI, frPHU and root fraction m_removeFraction[i] = 1.0f; //the fraction of remove part to aboveground part if (m_biomass[i] - m_biomassRoot[i] > 1.0e-6) m_removeFraction[i] = (m_yield[i] + m_clip[i]) / (m_biomass[i] - m_biomassRoot[i]); m_removeFraction[i] = min(1.0f, m_removeFraction[i]); //root part m_rootFraction[i] = m_biomassRoot[i] / m_biomass[i]; m_rootLeft[i] = (m_biomass[i] - m_biomassRoot[i]) * (1 - m_removeFraction[i]) * m_rootFraction[i] / (1.0f - m_rootFraction[i]); m_rootRemove[i] = m_biomassRoot[i] - m_rootLeft[i]; //removed root as residual m_rootRemoveFraction[i] = 0.0f; if (m_biomassRoot[i] > 1.0e-6) m_rootRemoveFraction[i] = m_rootRemove[i] / (m_biomassRoot[i]); m_rootRemoveN[i] = m_rootRemoveFraction[i] * (m_biomassN[i]); m_rootRemoveP[i] = m_rootRemoveFraction[i] * (m_biomassP[i]); //remove aboveground and root biomass from total biomass //change the LAI and growth step if (m_biomass[i] > 0.001) { m_LAI[i] *= 1.0f - m_removeFraction[i]; if (m_frPHU[i] < 0.999) m_frPHU[i] *= 1.0f - m_removeFraction[i]; m_biomass[i] -= m_yield[i] + m_clip[i] + m_rootRemove[i]; m_biomassN[i] -= m_yieldN[i] + m_clipN[i] + m_rootRemoveN[i]; m_biomassP[i] -= m_yieldP[i] + m_clipP[i] + m_rootRemoveP[i]; m_biomass[i] = min(0.0f, m_biomass[i]); m_biomassN[i] = min(0.0f, m_biomassP[i]); m_biomassP[i] = min(0.0f, m_biomassP[i]); m_biomassRoot[i] = m_biomass[i] * (0.4f - 0.2f * m_frPHU[i]); } else { m_biomass[i] = 0.0f; m_biomassN[i] = 0.0f; m_biomassP[i] = 0.0f; m_biomassRoot[i] = 0.0f; m_LAI[i] = 0.0f; m_frPHU[i] = 0.0f; } } } } //m_lastSWE = m_swe; return 0; }
// this is called only when ActiveWayPoint is 0, still waiting for start void CheckStart(NMEA_INFO *Basic, DERIVED_INFO *Calculated, int *LastStartSector) { BOOL StartCrossed= false; if (UseGates()) { #if DEBUGATE StartupStore(_T("... CheckStart Timenow=%d OpenTime=%d CloseTime=%d ActiveGate=%d\n"),LocalTime(),PGOpenTime,PGCloseTime,ActiveGate); #endif int gatetimediff=-1; if ( ActiveGate<0 ) { // init activegate: assign first valid gate, current or future ActiveGate=InitActiveGate(); if (ActiveGate<0||ActiveGate>(PGNumberOfGates-1)) { FailStore(_T("INVALID ActiveGate=%d"),ActiveGate); DoStatusMessage(_T("ERR-430 INVALID ACTIVEGATE: DISABLED")); PGNumberOfGates=0; return; } #if DEBUGATE StartupStore(_T("... CheckStart: INIT ActiveGate=%d\n"),ActiveGate); #endif } else { if (HaveGates()) { gatetimediff=GateTimeDiff(ActiveGate); #if DEBUGATE StartupStore(_T("... CheckStart: ActiveGate=%d RunningGate=%d\n"),ActiveGate,RunningGate()); StartupStore(_T("... CheckStart: gatetimediff=%d\n"),gatetimediff); #endif // a gate can be in the future , or already open! // case: first start, activegate is the first gate if (gatetimediff==0) { #if DEBUGATE StartupStore(_T("... CheckStart: ActiveGate=%d now OPEN\n"),ActiveGate); #endif AlertGateOpen(ActiveGate); // nothing else to do: the current activegate has just open } else { // check that also non-armed start is detected if (ActiveGate<(PGNumberOfGates-1)) { if (GateTimeDiff(ActiveGate+1)==0) { #if DEBUGATE StartupStore(_T("... CheckStart: ActiveGate+1=%d now OPEN\n"),ActiveGate); #endif ActiveGate++; AlertGateOpen(ActiveGate); } } } // now check for special alerts on countdown, only on current armed start if (gatetimediff==3600 && ((PGGateIntervalTime>=70)||ActiveGate==0) ) { // 850 FIRST GATE OPEN IN 1 HOUR DoStatusMessage(gettext(TEXT("_@M850_"))); if (EnableSoundModes) { LKSound(_T("LK_DINGDONG.WAV")); } } if (gatetimediff==1800 && ((PGGateIntervalTime>=45)||ActiveGate==0) ) { // 851 FIRST GATE OPEN IN 30 MINUTES DoStatusMessage(gettext(TEXT("_@M851_"))); if (EnableSoundModes) { LKSound(_T("LK_DINGDONG.WAV")); } } if (gatetimediff==600 && ((PGGateIntervalTime>=15)||ActiveGate==0) ) { // 10 minutes to go // 852 10 MINUTES TO GO DoStatusMessage(gettext(TEXT("_@M852_"))); if (EnableSoundModes) { LKSound(_T("LK_HITONE.WAV")); } } if (gatetimediff==300 && ((PGGateIntervalTime>=10)||ActiveGate==0)) { // 5 minutes to go // 853 5 MINUTES TO GO DoStatusMessage(gettext(TEXT("_@M853_"))); if (EnableSoundModes) { LKSound(_T("LK_HITONE.WAV")); } } if (gatetimediff==60) { // 1 minute to go if (EnableSoundModes) { LKSound(_T("LK_3HITONES.WAV")); } } } // HaveGates } // not init } if (ISPARAGLIDER && PGStartOut) { // start OUT and go in if (!InStartSector(Basic,Calculated,*LastStartSector, &StartCrossed)) { Calculated->IsInSector = false; if (ReadyToStart(Calculated)) { aatdistance.AddPoint(Basic->Longitude, Basic->Latitude, 0); } if (ValidStartSpeed(Basic, Calculated, StartMaxSpeedMargin)) { ReadyToAdvance(Calculated, false, true); } } else Calculated->IsInSector = true; } else { // start IN and go out, OLD CLASSIC MODE if (InStartSector(Basic,Calculated,*LastStartSector, &StartCrossed)) { // InSector check calling this function is resetting IsInSector at each run, so it was false. Calculated->IsInSector = true; if (ReadyToStart(Calculated)) { aatdistance.AddPoint(Basic->Longitude, Basic->Latitude, 0); } // ToLo: we are ready to start even when outside start rules but within margin if (ValidStartSpeed(Basic, Calculated, StartMaxSpeedMargin)) { ReadyToAdvance(Calculated, false, true); } // TODO accuracy: monitor start speed throughout time in start sector } } // end start mode if (StartCrossed && ValidGate() ) { // 100509 #if DEBUGTGATES StartupStore(_T("... CheckStart: start crossed and valid gate!\n")); #endif // ToLo: Check weather speed and height are within the rules or not (zero margin) if(!IsFinalWaypoint() && ValidStartSpeed(Basic, Calculated) && InsideStartHeight(Basic, Calculated)) { // This is set whether ready to advance or not, because it will // appear in the flight log, so if it's valid, it's valid. Calculated->ValidStart = true; if (ReadyToAdvance(Calculated, true, true)) { ActiveWayPoint=0; // enforce this since it may be 1 StartTask(Basic,Calculated, true, true); } if (Calculated->Flying) { Calculated->ValidFinish = false; } // JMW TODO accuracy: This causes Vaverage to go bonkers // if the user has already passed the start // but selects the start // Note: pilot must have armed advance // for the start to be registered // ToLo: If speed and height are outside the rules they must be within the margin... } else { if ((ActiveWayPoint<=1) && !IsFinalWaypoint() && (Calculated->ValidStart==false) && (Calculated->Flying)) { #if 0 // 101014 This is called from wrong thread, and cause bad crashes // moved to new GCE event inside InputEvents - paolo // need to detect bad starts, just to get the statistics // in case the bad start is the best available, or the user // manually started StartTask(Basic, Calculated, false, false); // Calculated->ValidStart = false; bool startTaskAnyway = false; if (ReadyToAdvance(Calculated, true, true)) { dlgStartTaskShowModal(&startTaskAnyway, Calculated->TaskStartTime, Calculated->TaskStartSpeed, Calculated->TaskStartAltitude); if (startTaskAnyway) { ActiveWayPoint=0; // enforce this since it may be 1 StartTask(Basic,Calculated, true, true); } } Calculated->ValidStart = startTaskAnyway; #else // 101014 StartTask(Basic, Calculated, false, false); if (ReadyToAdvance(Calculated, true, true)) { InputEvents::processGlideComputer(GCE_TASK_CONFIRMSTART); } #endif if (Calculated->Flying) { Calculated->ValidFinish = false; } } } } }