예제 #1
0
void Vegetation_Bgc::prepareIntegration(const bool & equil) {
	//calculate some variables that are constant through out the integration
	nfeed = bd->nfeed;
	avlnflg = bd->avlnflg;
	equiled = equil;

	double pet = ed->m_l2a.pet;
	double eet = ed->m_l2a.eet;
	if (pet == 0.0)
		pet = 0.0001; //Yuan: to avoid gv=NaN
	bd->m_vegd.gv = getGV(eet, pet);

	//assign states to temporary state variable
	tmp_vegs.c = bd->m_vegs.c;
	tmp_vegs.ston = bd->m_vegs.ston;
	tmp_vegs.strn = bd->m_vegs.strn;
	tmp_vegs.unnormleaf = bd->m_vegs.unnormleaf;

	bd->m_vegd.ftemp = getTempFactor4GPP(ed->m_atms.ta);

	bd->m_vegd.raq10 = getRaq10(ed->m_atms.ta);

}
예제 #2
0
int sched::run()
{
	myLogger.lw(INFO,"RUN: Starting SCHED Run...");
	message msg;
	
	// Starting conditions:	
	int temp = getGV(playFname);
	if( temp <= 0 )
	{
		play = false;
		if( setGV(playFname, (int) play) == -1 )
		{
			myLogger.lw(ERROR,"RUN: Error setting current event counter to global var at %s",playFname);	
		}
	}
	else
	{
		play = (bool) temp;
	}
	
	currEvent = getGV(currEventFname);
	if( (currEvent < 0) || (currEvent >= numEvents) )
	{
		currEvent = -1;
		if( setGV(currEventFname, currEvent) == -1 )
		{
			myLogger.lw(ERROR,"RUN: Error setting current event to global var at %s",currEventFname);	
		}
	}
	else
	
	eventCounter = getGV(eventCounterFname);
	if( (eventCounter < 0) )
	{
		eventCounter = 0;
		if( setGV(eventCounterFname, eventCounter) == -1 )
		{
			myLogger.lw(ERROR,"RUN: Error setting current event counter to global var at %s",eventCounterFname);	
		}
	}
	
	timeSlept = getGV(timeSleptFname);
	if( (timeSlept < 0) )
	{
		timeSlept = 0;
		if( setGV(timeSleptFname, timeSlept) == -1 )
		{
			myLogger.lw(ERROR,"RUN: Error setting current event counter to global var at %s",timeSleptFname);	
		}
	}
	
	myLogger.lw(INFO,"RUN: Restored current event as %d, count %d, timeslept %d, play %d",currEvent,eventCounter,timeSlept,(int) play);	
	
	// Update semaphores:
	setSemaphore(sched_semid,1,(int) play);
	setSemaphore(sched_semid,2,currEvent);
	setSemaphore(sched_semid,3,eventCounter);
	setSemaphore(sched_semid,4,timeSlept);
 	
 	int presleep = 0;
 	if( currEvent > 0 )
 	{
 		presleep = event[currEvent].sleep;
 	}
 	
 	// Sleep initially and wait for play, or advance when the next event is scheduled.
	if(sched_sleep(presleep) == -1)
	{
		myLogger.lw(INFO,"RUN: Schedule terminated. Dying gracefully.");
		return 0;
	}
 	currEvent++;
	
	for(; currEvent < numEvents; currEvent++)
	{	
		// Update semaphore & file:
		setGV(currEventFname, currEvent);
		setSemaphore(sched_semid,2,currEvent);
		
		// Form message
		msg.cmd = event[currEvent].cmd;
		myLogger.lw(INFO,"RUN: Starting event %d. Run %d time(s): %s",event[currEvent].num,event[currEvent].count,msg.toString());
		
		eventCounter = 0;
		while( (eventCounter < event[currEvent].count) || (event[currEvent].count == -1) )
		{
			// Update semaphore & file:
			setGV(eventCounterFname, eventCounter);
			setSemaphore(sched_semid,3,eventCounter);
			
			myLogger.lw(INFO,"RUN: Running event %d. Count %d of %d.",event[currEvent].num,eventCounter + 1,event[currEvent].count);
			
			// Run command up to 5 times if failures occure:
			for( int numTrys = 0; numTrys < 5; numTrys++ )
			{
				commandWrapper.execute(&msg);
				if(msg.rsp.ret != 1)
				{
					myLogger.lw(ERROR,"RUN: Event %d returned with error 0x%x on try %d. Sleeping 1 second and trying again.",event[currEvent].num, msg.rsp.ret, numTrys);
					usleep(1000000);
				}
				else
				{
					myLogger.lw(INFO,"RUN: Event %d successful on try %d.",event[currEvent].num, numTrys);
					break; // command success, go to sleepy time.
				}
			}
			
			if(sched_sleep(event[currEvent].sleep) == -1)
			{
				myLogger.lw(INFO,"RUN: Schedule terminated. Dying gracefully.");
				return 0;
			}
			
			// Increment to next event:	
			eventCounter++;
		}
	}
	
	myLogger.lw(INFO,"RUN: Schedule completed. Dying gracefully.");
	
	return 0;
}