Ejemplo n.º 1
0
/* Converts secs into the ISO difftime representation */
char *
isodiff_from_secs (int secs)
{
	static char buffer [60], *p;
	int years, months, weeks, days, hours, minutes;
	
	years = months = weeks = days = hours = minutes = 0;
	
	years    = secs / (365 * 86400);
	secs    %= (365 * 86400);
	months   = secs / (30 * 86400);
	secs    %= (30 * 86400);
	weeks    = secs / (7 * 86400);
	secs    %= (7 * 86400);
	days     = secs / 86400;
	secs    %= 86400;
	hours    = secs / 3600;
	secs    %= 3600;
	minutes  = secs / 60;
	secs    %= 60;

	strcpy (buffer, "P");
	p = buffer + 1;
	if (years)
		p = pcat (p, years, 'Y');
	if (months)
		p = pcat (p, months, 'M');
	if (weeks)
		p = pcat (p, weeks, 'W');
	if (days)
		p = pcat (p, days, 'D');
	if (hours || minutes || secs){
		*p++ = 'T';
		if (hours)
			p = pcat (p, hours, 'H');
		if (minutes)
			p = pcat (p, minutes, 'M');
		if (secs)
			p = pcat (p, secs, 'S');
	}
	
	return buffer;
}
Ejemplo n.º 2
0
model_data::model_data(int argc,char * argv[]) : ad_comm(argc,argv)
{
		ifstream ifs( "seed.txt" ); // if this file is available
		ifs>>seed; //read in the seed
		seed += 10; // add 10 to the seed
		ofstream ofs( "seed.txt" ); //put out to seed.txt
		ofs<<seed<<endl; //the new value of the seed
  syr.allocate("syr");
  nyr.allocate("nyr");
  sage.allocate("sage");
  nage.allocate("nage");
  smon.allocate("smon");
  nmon.allocate("nmon");
  sarea.allocate("sarea");
  narea.allocate("narea");
  nations.allocate("nations");
  border.allocate(1,nations-1,"border");
  Ro.allocate("Ro");
  h.allocate("h");
  m.allocate("m");
  fe.allocate("fe");
  q.allocate("q");
  sigR.allocate("sigR");
  tau_c.allocate("tau_c");
  mo.allocate("mo");
  err.allocate("err");
  wa.allocate(sage,nage,"wa");
  fa.allocate(sage,nage,"fa");
  va.allocate(sage,nage,"va");
  minPos.allocate(sage,nage,"minPos");
  maxPos501.allocate("maxPos501");
  maxPos502.allocate("maxPos502");
  maxPossd1.allocate("maxPossd1");
  maxPossd2.allocate("maxPossd2");
  cvPos.allocate("cvPos");
  TotEffyear.allocate(1,nations,syr,nyr,"TotEffyear");
  TotEffmonth.allocate(1,nations,smon,nmon,"TotEffmonth");
  eof.allocate("eof");
		
		if( eof != 999 )
		{
			cout<<"Error reading data.\n Fix it."<<endl;
			cout<< "eof is: "<<eof<<endl;
			ad_exit(1);
		}
  age.allocate(sage,nage);
  areas.allocate(sarea,narea);
  nationareas.allocate(1,nations);
  wt.allocate(syr,nyr);
			ntstp = (nmon-smon+1) * (nyr-syr+1);
			age.fill_seqadd(sage,1);
			areas.fill_seqadd(sarea,1);
			nationareas.initialize();
			dvector natmp(1,nations);
			
			natmp(1)=sarea;
			for(int n=1; n<=nations-1; n++)
			{
				natmp(n+1)=border(n);
				for(int a=sarea;a<=narea;a++)
				{
					if(areas(a)>=natmp(n)&areas(a)<border(n))
					{
						nationareas(n)++;
					}
				}
			}
			nationareas(nations)=narea-sarea+1 - sum(nationareas(1,nations-1));
		
			random_number_generator rng(seed);
			wt.fill_randn(rng);
			wt*=sigR;
  indyr.allocate(1,ntstp);
  indmonth.allocate(1,ntstp);
  indnatarea.allocate(sarea,narea);
  pcat.allocate(1,nations);
       			int aa =0;
       			
       			for(int y=syr;y<=nyr;y++)		
       			{
       				for(int ii=smon;ii<=nmon;ii++)
       				{
       					aa++;
       					indyr(aa) = y;
       					indmonth(aa) = ii;
       				}
       			}
      		
       			ivector natmp1(1,nations+1);
       			natmp1(1) = sarea;
       			for(int n=1;n<=nations;n++)
       			{
       				natmp1(n+1)= natmp1(n)+nationareas(n);
       				for(int b = natmp1(n); b <= natmp1(n+1)-1 ; b++)
       				{
       					indnatarea(b)=n;
       				}
       			}
       			indnatarea(narea)=nations;
       			
       			pcat.initialize();
       			for(int n=1;n<=nations;n++)
       			{
       				for(int i=1;i<=ntstp;i++)
       				{
       					if(TotEffmonth(n)(indmonth(i))>0)
       					{
       						pcat(n)++;
       					}
       							
       				}
       			}
       			tot_pcat=sum(pcat);
    
       			
}