Esempio n. 1
0
static void plot_harmonics(double rr, int zoomlevel, fftpart * fp)
{
   int ii, hh;
   double offsetf;
   char label[20];
   fftview *harmview;

   cpgsubp(4, 4);
   for (ii = 0, hh = 2; ii < 8; ii++, hh++) {
      cpgpanl(ii % 4 + 1, ii / 4 + 1);
      harmview = get_harmonic(hh * rr, zoomlevel, fp);
      if (harmview != NULL) {
         offsetf = plot_fftview(harmview, 0.0, 2.0, hh * rr, 2);
         snprintf(label, 20, "Harmonic %d", hh);
         cpgsave();
         cpgsch(2.0);
         cpgmtxt("T", -1.8, 0.05, 0.0, label);
         cpgunsa();
         free(harmview);
      }
   }
   for (ii = 8, hh = 2; ii < 16; ii++, hh++) {
      cpgpanl(ii % 4 + 1, ii / 4 + 1);
      harmview = get_harmonic(rr / (double) hh, zoomlevel, fp);
      if (harmview != NULL) {
         offsetf = plot_fftview(harmview, 0.0, 2.0, rr / (double) hh, 2);
         snprintf(label, 20, "Harmonic 1/%d", hh);
         cpgsave();
         cpgsch(2.0);
         cpgmtxt("T", -1.8, 0.05, 0.0, label);
         cpgunsa();
         free(harmview);
      }
   }
   cpgsubp(1, 1);
   cpgpanl(1, 1);
   cpgsvp(0.0, 1.0, 0.0, 1.0);
   cpgswin(2.0, 6.0, -2.0, 2.0);
   cpgmove(2.0, 0.0);
   cpgslw(3);
   cpgdraw(6.0, 0.0);
   cpgslw(1);
}
Esempio n. 2
0
int main(){
	printf("\n====================================================================\n");
	printf("This program is able to simulate the diffusion of heat\n");
	printf("across a metal plate of size %i x %i\n", ENV_SIZE_X, ENV_SIZE_Y);
	printf("====================================================================\n");

	//==========================================================================
	//--------------------------SYSTEM INITIALIZATIONS--------------------------
	//==========================================================================
	
	// initialize random seed
	srand(time(NULL));

	// force print all outputs (remove stdout buffer)
	setbuf(stdout, NULL);

	// initialize pgplot window
	if (!cpgopen("/XWINDOW"))
		errorCase(ERR_PGPLOT);

	cpgpap(0.0, 0.6);						// set window size
	cpgsubp(1,3);						// subdivide window into panels
	// heatmap
	cpgpanl(1,1);
	cpgsvp(0.0, 1.0, 0.0, 1.0);
	cpgswin(0, ENV_SIZE_X, 0, ENV_SIZE_Y);
	// flux plot
	cpgpanl(1,2);
	cpgsvp(0.08, 0.92, 0.08, 0.92);
	cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, FLUX_PLOT_Y1, FLUX_PLOT_Y2);
	cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0);
	cpglab("Time", "Flux", "");
	// heat plot
	cpgpanl(1,3);
	cpgsvp(0.08, 0.92, 0.08, 0.92);
	cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, LINE_PLOT_Y1, LINE_PLOT_Y2);
	cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0);
	cpglab("Time", "Total Heat", "");

	// initialize color table for pgplot display
  	float rl[9] = {-0.5, 0.0, 0.17, 0.33, 0.50, 0.67, 0.83, 1.0, 1.7};
  	float rr[9] = { 0.0, 0.0,  0.0,  0.0,  0.6,  1.0,  1.0, 1.0, 1.0};
  	float rg[9] = { 0.0, 0.0,  0.0,  1.0,  1.0,  1.0,  0.6, 0.0, 1.0};
  	float rb[9] = { 0.0, 0.3,  0.8,  1.0,  0.3,  0.0,  0.0, 0.0, 1.0};
  	cpgctab(rl, rr, rg, rb, 512,  1.0, 0.5);
	cpgscr(10, 0.0, 0.0, 1.0);
	cpgscr(11, 1.0, 0.0, 0.0);
	cpgsfs(3);


	//==========================================================================
	//--------------------------VARIABLE INITIALIZATIONS------------------------
	//==========================================================================

	// generic variables
	int i, j, k;						// counters

	// simulation environment
	float** simEnvEven = allocateArray2D(ENV_SIZE_X, ENV_SIZE_Y);
	float** simEnvOdd = allocateArray2D(ENV_SIZE_X, ENV_SIZE_Y);
	float* simLocal = allocateArray1D(5);

	// mnist handwritten numbers
	float** mnistDatabase = readCSV("mnist_train_100.csv", 100, 785);
	for (i=0; i<100; i++)
		for (j=0; j<785; j++)
			mnistDatabase[i][j] = mnistDatabase[i][j]/255.0;

	// current location and time
	int x,y,z;
	int t, tGlobal;

	// student number
	int studentNumbRaw;
	int studentNumbWorking;
	int studentNumb[7];

	// rates
	float rateDiff = 0.2;
	float delta;

	// flux variables
	float flux;
	float fluxTotal;
	float fluxAverage;
	float fluxHeat;
	float totalHeat;
	int x1, x2, y1, y2;

	// background heat
	float bgHeat;

	// tracking variables
	float totalHeatOld;
	float totalHeatPre;
	float tGlobalOld;
	float fluxOld;

	// pgplot variables
	float* plotImg = allocateArray1D(ENV_SIZE_TOTAL);
	float TR[6] = {0, 0, 1, ENV_SIZE_Y, -1, 0};
	float plotMinBound = 0;
	float plotMaxBound = 1;

	//==========================================================================
	//--------------------------------SETUP-------------------------------------
	//==========================================================================
	
	// ask for student number
	printf("Please enter your student number:\n");
	if (scanf("%i", &studentNumbRaw) == 0)
		errorCase(ERR_INVALID_INPUT);
	studentNumbWorking = studentNumbRaw;
	for (i=0; i<SN_LENGTH; i++){
		studentNumb[6-i] = studentNumbWorking%10;
		studentNumbWorking /= 10;
	}
	printf("\nYour student number is:\n");
	for (i=0; i<SN_LENGTH; i++)
		printf("%i", studentNumb[i]);
	printf("\n\n");

	// set and print diffusion rate based on last digit of student number
	rateDiff = ((((float)(studentNumb[6]))/10.0)*0.19)+0.01;
	printf("Your Diffusion Rate is: \n%f\n\n", rateDiff);

	// set and print background heat added based on last 4 digits of student number
	studentNumbRaw -= 1410000;
	bgHeat = ((float)((studentNumbRaw%97)%10));
	bgHeat += ((float)((studentNumbRaw%101)%8))*10;
	bgHeat /= 100;
	printf("Your Background Heat is: \n%f\n\n", bgHeat*100);

	// set and print domain for calculating flux
	// x1, y1 based on last four digits of student number
	x1 = studentNumbRaw % ENV_SIZE_X;
	y1 = studentNumbRaw % ENV_SIZE_Y;
	// x2, y2 based on last four digits of student number
	x2 = x1 + (studentNumbRaw % (97));
	if (x2 >= ENV_SIZE_X)
		x2 = ENV_SIZE_X - 1;
	y2 = y1 + (studentNumbRaw % (29));
	if (y2 >= ENV_SIZE_Y)
		y2 = ENV_SIZE_Y - 1;
	printf("Your Domain is: \n(%i, %i) X (%i, %i)\n\n", x1, y1, x2, y2);

	// environment initialization:
	// select digits and place into environment
	for (i=0; i<SN_LENGTH; i++){
		if (studentNumb[i] == 0)
			z = 0;
		else if (studentNumb[i] == 1)
			z = 13;
		else if (studentNumb[i] == 2)
			z = 27;
		else if (studentNumb[i] == 3)
			z = 33;
		else if (studentNumb[i] == 4)
			z = 44;
		else if (studentNumb[i] == 5)
			z = 55;
		else if (studentNumb[i] == 6)
			z = 60;
		else if (studentNumb[i] == 7)
			z = 71;
		else if (studentNumb[i] == 8)
			z = 81;
		else
			z = 89;

		for (x=0; x<28; x++)
			for (y=0; y<28; y++) {
				simEnvEven[x+(i*28)+1][y+1] = mnistDatabase[z][y*28+x] + bgHeat;
				if (simEnvEven[x+(i*28)+1][y+1] > 1.0)
					simEnvEven[x+(i*28)+1][y+1] = 1.0;
			}
	}


	//==========================================================================
	//--------------------------ACTUAL CODE-------------------------------------
	//==========================================================================

	// initialize display
	fixBoundaryConditions(simEnvEven);
	copyArray2D(simEnvEven, simEnvOdd, ENV_SIZE_X, ENV_SIZE_Y);
	loadImage(simEnvEven, plotImg);
	cpgpanl(1,1);
	cpgsvp(0.0, 1.0, 0.0, 1.0);
	cpgswin(0, ENV_SIZE_X, 0, ENV_SIZE_Y);
	cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR);
	cpgrect(x1, x2, y1, y2);

	// initialize trackers
	tGlobalOld = 0;
	fluxOld = 0;
	totalHeatOld = 0;
	for (x=x1; x<=x2; x++)
		for (y=y1; y<=y2; y++)
			totalHeatOld += simEnvEven[x][y];

	// initial delay to visualize starting matrix
	for (t=0; t<500000000; t++){}
	
	t = 0;
	tGlobal = 0;
	flux = 0;
	fluxAverage = 0;
	fluxTotal = 0;
	while(1){
		flux = 0;
		cpgpanl(1,1);
		cpgsvp(0.0, 1.0, 0.0, 1.0);
		cpgswin(0, ENV_SIZE_X, 0, ENV_SIZE_Y);

		// calculate heat changes using numeric methods
		fixBoundaryConditions(simEnvEven);

		//simEnvEven[50][15] = 100;
		//simEnvEven[60][15] = -10;

		copyArray2D(simEnvEven, simEnvOdd, ENV_SIZE_X, ENV_SIZE_Y);

		for (x=1; x<(ENV_SIZE_X-1); x++)
			for (y=1; y<(ENV_SIZE_Y-1); y++)
				if ((x+y)%2 == 0) {
					delta = rateDiff*(simEnvEven[x][y+1] - 2*simEnvEven[x][y] + simEnvEven[x][y-1]);
					simEnvOdd[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
					delta = rateDiff*(simEnvEven[x+1][y] - 2*simEnvEven[x][y] + simEnvEven[x-1][y]);
					simEnvOdd[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
				}
		for (x=1; x<(ENV_SIZE_X-1); x++)
			for (y=1; y<(ENV_SIZE_Y-1); y++)
				if ((x+y)%2 == 1) {
					delta = rateDiff*(simEnvOdd[x][y+1] - 2*simEnvOdd[x][y] + simEnvOdd[x][y-1]);
					simEnvOdd[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
					delta = rateDiff*(simEnvOdd[x+1][y] - 2*simEnvOdd[x][y] + simEnvOdd[x-1][y]);
					simEnvOdd[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
				}
		loadImage(simEnvOdd, plotImg);
		cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR);
		cpgrect(x1, x2, y1, y2);
		fluxTotal += flux;
		tGlobal++;

		flux = 0;

		//simEnvOdd[50][15] = 100;
		//simEnvOdd[60][15] = -10;

		fixBoundaryConditions(simEnvOdd);
		
		for (x=1; x<(ENV_SIZE_X-1); x++)
			for (y=1; y<(ENV_SIZE_Y-1); y++)
				if ((x+y)%2 == 1) {
					delta = rateDiff*(simEnvOdd[x][y+1] - 2*simEnvOdd[x][y] + simEnvOdd[x][y-1]);
					simEnvEven[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
					delta = rateDiff*(simEnvOdd[x+1][y] - 2*simEnvOdd[x][y] + simEnvOdd[x-1][y]);
					simEnvEven[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
				}
		for (x=1; x<(ENV_SIZE_X-1); x++)
			for (y=1; y<(ENV_SIZE_Y-1); y++)
				if ((x+y)%2 == 0) {
					delta = rateDiff*(simEnvEven[x][y+1] - 2*simEnvEven[x][y] + simEnvEven[x][y-1]);
					simEnvEven[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
					delta = rateDiff*(simEnvEven[x+1][y] - 2*simEnvEven[x][y] + simEnvEven[x-1][y]);
					simEnvEven[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
				}
		loadImage(simEnvEven, plotImg);
		cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR);
		cpgrect(x1, x2, y1, y2);
		fluxTotal += flux;
		tGlobal++;



		// flux line plot
		cpgpanl(1,2);
		cpgsvp(0.08, 0.92, 0.08, 0.92);
		cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, FLUX_PLOT_Y1, FLUX_PLOT_Y2);
		cpgmove(tGlobalOld, fluxOld);
		cpgdraw(tGlobal, flux);

		// heat line plot
		totalHeat = 0;
		for (x=x1; x<=x2; x++)
			for (y=y1; y<=y2; y++)
				totalHeat += simEnvEven[x][y];
		cpgpanl(1,3);
		cpgsvp(0.08, 0.92, 0.08, 0.92);
		cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, LINE_PLOT_Y1, LINE_PLOT_Y2);
		cpgmove(tGlobalOld, totalHeatOld);
		cpgdraw(tGlobal, totalHeat);

		// set trackers
		tGlobalOld = tGlobal;
		totalHeatOld = totalHeat;
		fluxOld = flux;

		if (tGlobal%100 == 0) {
			totalHeat = 0;
			for (x=x1; x<=x2; x++)
				for (y=y1; y<=y2; y++)
					totalHeat += simEnvEven[x][y];
			fluxAverage = fluxTotal/tGlobal;
			fluxHeat = totalHeat - totalHeatPre;
			printf("Total Heat: %f \n Current Divergence: %f \n Current Flux:       %f\n\n", totalHeat, flux, fluxHeat);
		}

		totalHeatPre = 0;
		for (x=x1; x<=x2; x++)
			for (y=y1; y<=y2; y++)
				totalHeatPre += simEnvEven[x][y];
	}
}
// make six Aitoff sky projection plots
//   using the data in ravec[field], decvec[field], and value[filter][field],
//   using the min and max data values in valmin[filter] and valmax[filter]
//   with filter=0 to NFILTERS-1
void plotSix(double nfields, double **value,
             double *ravec, double *decvec,
             double *valmin, double *valmax,
             int horizontal,
             char *label, char *title, char* plotName, int mask) {

	char str[1024];
	int filt, nf;
	double xmin, xmax, ymin, ymax;

	openPlot(plotName);
	cpgbbuf();

	if(horizontal==1) 
		cpgpap(PLOTSIZE/0.5,0.5); else cpgpap(PLOTSIZE/1.0,1.0);

	cpgsvp(0.02,0.98,0.15,0.95);
	xmax = 0.9*(M_PI);      
	xmin = -xmax;
	ymax = 0.9*(0.6*M_PI);  
	ymin = -ymax;
	ymin -= 0.18*ymax;      
	ymax -= 0.18*ymax;

	setupImplot(0.0, 1.0);

	if(horizontal==1) 
		cpgsubp(3,2); 
	else 
		cpgsubp(2,3);

	cpgsch(3.0); 
	cpgslw(2);

	for(filt=0; filt<NFILTERS; filt++) {
		int thereisdata = 0;
		for(nf=0; nf<nfields; nf++) {
			if (value[filt][nf] != 0.0) {
				thereisdata = 1;
			}
		}
		
		if ( thereisdata ) {
			if(horizontal==1) 
				cpgpanl(hpanelx[filt],hpanely[filt]); 
			else 
				cpgpanl(vpanelx[filt],vpanely[filt]);

			cpgswin(xmin,xmax,ymin,ymax);
			for(nf=0; nf<nfields; nf++) {
				if ( mask == 0 ) {
					if(value[filt][nf] > 0.0)
						projCircle(ravec[nf], decvec[nf], FIELD_RADIUS, (value[filt][nf]-valmin[filt])/(valmax[filt]-valmin[filt]));
				} else if ( mask == 1) {
					if(value[filt][nf] != 0.0)
						projCircle(ravec[nf], decvec[nf], FIELD_RADIUS, (value[filt][nf]-valmin[filt])/(valmax[filt]-valmin[filt]));
				}
			}
			aitoffGrid();
			galaxy(peakL, taperL, taperB);
			sprintf(str,"%s: %s", label, filtername[filt]);
			if(valmax[filt]>valmin[filt])
				mywedg(0.2, 0.15, 1.0, 8.0, valmin[filt], valmax[filt], str);
		}
	}

	cpgsch(1.0);
	cpgsubp(1,1);
	cpgswin(0,1,0,1);
	cpgptxt(0.5,1.02,0.0,0.5,title);
	cpgslw(1);    
	cpgebuf();

	closePlot();
}
Esempio n. 4
0
File: RGPMain.C Progetto: rjs80/RGIS
int main (int argc,char **argv)

	{
	int argPos, argNum = argc;
	char charBuffer [RGPBufferSIZE], panelTitle [RGPBufferSIZE], *outFile = (char *) "rgisplot";
	int panelRow, panelCol, panelRowNum,panelColNum, defaultLW;
	DBInt dataNum, entryNum = 0;
	DBInt ret, mode = 0, device = 0, format = 0, layout = 0;
	float x0, y0, x1, y1, pWidth = -1.0, pHeight = -1.0;
	DBObjData *dbData;

	for (argPos = 1;argPos < argNum; )
		{
		if (CMargTest (argv [argPos],"-m","--mode"))
			{
			const char *modes [] = { "interactive", "batch", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing mode!");    return (CMfailed); }
			if ((mode = CMoptLookup (modes,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid mode %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-d","--device"))
			{
			const char *devices [] = { "screen", "file", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing device!");  return (CMfailed); }
			if ((device = CMoptLookup (devices,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid device %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-p","--psize"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing psize!");   return (CMfailed); }
			if ((argv [argPos] == (char *) NULL) || (sscanf (argv [argPos],"%f,%f",&pWidth,&pHeight) != 2))
				{ CMmsgPrint (CMmsgUsrError,"Invalid page size %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-f","--format"))
			{
			const char *formats [] = { "eps", "gif", "ppm", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing format!");  return (CMfailed); }
			if ((format = CMoptLookup (formats,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid format %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-l","--layout"))
			{
			const char *layouts [] = { "portrait","landscape", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing layout!");  return (CMfailed); }
			if ((layout = CMoptLookup (layouts,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid layout %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-o","--output"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing output!");  return (CMfailed); }
			if (argv [argPos] == (char *) NULL)
				{ CMmsgPrint (CMmsgUsrError,"Invalid output file"); goto Usage; }
			outFile = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-h","--help"))
			{
			Usage:
			CMmsgPrint (CMmsgUsrError,"Usage: rgisPlot [-m <>] [-d <>] [-f <>] [-l <>] [-o <>] -h");
			CMmsgPrint (CMmsgUsrError,"                 -m, --mode <interactive | batch>");
			CMmsgPrint (CMmsgUsrError,"                 -d, --device <screen | file>");
			CMmsgPrint (CMmsgUsrError,"                 -p, --psize width,height");
			CMmsgPrint (CMmsgUsrError,"                 -f, --format <eps | gif>");
			CMmsgPrint (CMmsgUsrError,"                 -l, --layout <landscape | portrait>");
			CMmsgPrint (CMmsgUsrError,"                 -o, --output <filename>");
			argNum = CMargShiftLeft (argPos,argv,argNum);
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); }
		argPos++;

		}

	switch (device)
		{
		case 0: cpgopen ("/XWINDOW");	break;
		case 1:
			{
			char *formatStrings [] = { (char *) "CPS", (char *) "GIF", (char *) "PPM" };
			sprintf (charBuffer,layout == 0 ? "%s/V%s" : "%s/%s", outFile, formatStrings [format]);
			cpgopen (charBuffer);
			} break;
		default: return (CMfailed);
		}
	cpgscrn (0,"WHITE",&ret);
	if ((pWidth > 0.0) && (pHeight > 0.0)) cpgpap (pWidth, pHeight / pWidth);

	do	{
		RGPPrintMessage (mode,&entryNum,"Panel Layout [horizontal,vertical]:");
		while (fgets (charBuffer,sizeof (charBuffer) - 1,stdin) == (char *) NULL);
		if (sscanf (charBuffer,"%d,%d",&panelColNum,&panelRowNum) == 2) break;
		else
			if (RGPPrintError (mode,entryNum,"Panel layout input error")) goto Stop;
		} while (true);

	RGPInitPenColors ();
	cpgsubp (panelColNum,panelRowNum);
	cpgqlw (&defaultLW);

	ret = DBSuccess;
	for (panelRow = 0;panelRow < panelRowNum;++panelRow)
		for (panelCol = 0;panelCol < panelColNum; ++panelCol)

			{
			cpgpanl (panelCol + 1,panelRow + 1);
			cpgsch (1.8);
			cpgvstd ();
			do	{
				sprintf (charBuffer,"Panel Title [%d,%d]:",panelRow,panelCol);
				RGPPrintMessage (mode,&entryNum,charBuffer);
				if (fgets (panelTitle,sizeof (panelTitle) - 1,stdin) != (char *) NULL)
					{
					if (panelTitle [strlen (panelTitle) - 1] == '\n')
						panelTitle [strlen (panelTitle) - 1] = '\0';
					if (strlen (panelTitle) > 0) break;
					}
				RGPPrintError (mode,entryNum,"Panel Title input error"); goto Stop;
				} while (true);

			dataNum = 0;
			do {
				RGPPrintMessage (mode,&entryNum,"Mapextent [X0,Y0,X1,Y1]:");
				if (fgets (charBuffer,sizeof (charBuffer) - 1,stdin) == (char *) NULL) continue;
				if (sscanf (charBuffer,"%f,%f,%f,%f",&x0,&y0,&x1,&y1) == 4)	break;
				else	if (RGPPrintError (mode,entryNum,"Mapextent input error")) goto Stop;
				} while (true);
			cpgwnad (x0,x1,y0,y1);

			do	{
				sprintf (charBuffer,"RiverGIS data file [%d]:",++dataNum);
				RGPPrintMessage (mode,&entryNum, charBuffer);
				if ((fgets (charBuffer,sizeof (charBuffer) - 1,stdin) != (char *) NULL) &&
					 (strlen (charBuffer) > 0) && charBuffer [0] != '\n')
					{
					if (charBuffer [strlen (charBuffer) - 1] == '\n') charBuffer [strlen (charBuffer) - 1] = '\0';
					dbData = new DBObjData ();
					if (dbData->Read (charBuffer) != DBSuccess) { dataNum--; continue; }
					switch (dbData->Type ())
						{
						case DBTypeVectorPoint:
							if ((ret = RGPDrawVecPoint (mode, &entryNum, dbData)) == DBFault) goto Stop;
							break;
						case DBTypeVectorLine:
							if ((ret = RGPDrawVecLine (mode, &entryNum, dbData)) == DBFault) goto Stop;
							break;
						case DBTypeVectorPolygon:
							break;
						case DBTypeGridContinuous:
								if ((ret = RGPDrawGridContinuous (mode,&entryNum,dbData)) == DBFault)	goto Stop;
							break;
						case DBTypeGridDiscrete:
							break;
						case DBTypeNetwork:
							if ((ret = RGPDrawNetwork (mode, &entryNum, dbData)) == DBFault) goto Stop;
							break;
						default: CMmsgPrint (CMmsgUsrError,"Invalid data type"); dataNum--; break;
						}
					delete dbData;
					}
				else	break;
				} while (true);
			cpgbox ("BCMTS",0.0,0,"BCNMTS",0.0,0);
			cpgslw (2);
			cpgsch (2.5);
			cpgmtxt ("T",1.5,0.5,0.5,panelTitle);
			cpgslw (defaultLW);
			}
Stop:
	cpgend ();
	return (ret);
	}
void oppositionPlot(void) {
  int i;
  double rasun, decsun, distsun, toporasun, topodecsun, x, y, z;
  double jd, lstm, trueam, alt, ha, phi, longEcliptic, latEcliptic;
  double objra, objdec;
  
  openPlot("opposition");
  cpgpap(PLOTSIZE/0.5,0.5);

  cpgbbuf();

  cpgsubp(2,2);

  cpgpanl(1,1);
  cpgswin(PHIMIN, PHIMAX, AMMIN, AMMAX);
  cpgbox("BCNTS",0.0,0,"BVCNTS",0.0,0);
  cpgmtxt("L",2.0,0.5,0.5,"airmass");
  cpgmtxt("B",2.0,0.5,0.5,"angle from Sun");

  cpgsci(2);
  for(i=0; i<numobs; i++) {

    jd = obs[i].date + 2400000.5;
    lstm = lst(jd,longitude_hrs);

    // get ecliptic coordinates
    slaEqecl(obs[i].ra, obs[i].dec, obs[i].date, &longEcliptic, &latEcliptic);

    if(fabs(latEcliptic) < 10.0/DEG_IN_RADIAN && obs[i].twilight==0) {

      // get position of Sun
      accusun(jd, lstm, latitude_deg, &rasun, &decsun, &distsun,
              &toporasun, &topodecsun, &x, &y, &z);

      // sun-object angle in degrees
      // takes ra in hours, dec in degrees
      objra = adj_time(obs[i].ra*HRS_IN_RADIAN);
      objdec = obs[i].dec*DEG_IN_RADIAN;
      phi = mysubtend(rasun, decsun, objra, objdec)*DEG_IN_RADIAN;
      
      // angle from opposition is 180-phi
      //      FIXRANGE(phi,-180.0,180.0);
      
      //airmass takes ra, dec, in radians, returns true airmass
      airmass(obs[i].date, obs[i].ra, obs[i].dec, &trueam, &alt, &ha);
      
      cpgpt1(phi, trueam, -1);

    }
  }

  cpgsci(1);
  cpgptxt(0.0,3.0,0.0,0.5,"|ecliptic latitude|<10");
  cpgptxt(0.0,2.5,0.0,0.5,"night");

  cpgsci(3);
  cpgmove(-90.0,0.0);
  cpgdraw(-90.0,4.0);
  cpgmove( 90.0,0.0);
  cpgdraw( 90.0,4.0);
  cpgsci(1);


  cpgpanl(1,2);
  cpgswin(PHIMIN, PHIMAX, AMMIN, AMMAX);
  cpgbox("BCNTS",0.0,0,"BVCNTS",0.0,0);
  cpgmtxt("L",2.0,0.5,0.5,"airmass");
  cpgmtxt("B",2.0,0.5,0.5,"angle from Sun");

  cpgsci(2);
  for(i=0; i<numobs; i++) {

    jd = obs[i].date + 2400000.5;
    lstm = lst(jd,longitude_hrs);

    // get ecliptic coordinates
    slaEqecl(obs[i].ra, obs[i].dec, obs[i].date, &longEcliptic, &latEcliptic);

    if(fabs(latEcliptic) >= 10.0/DEG_IN_RADIAN  && obs[i].twilight==0 ) {

      // get position of Sun
      accusun(jd, lstm, latitude_deg, &rasun, &decsun, &distsun,
              &toporasun, &topodecsun, &x, &y, &z);

      // sun-object angle in degrees
      phi = mysubtend(rasun, decsun, obs[i].ra*HRS_IN_RADIAN, obs[i].dec*DEG_IN_RADIAN)*DEG_IN_RADIAN;
      
      // angle from opposition is 180-phi
      FIXRANGE(phi,-180.0,180.0);
      
      airmass(obs[i].date, obs[i].ra, obs[i].dec, &trueam, &alt, &ha);
      
      cpgpt1(phi, trueam, -1);

    }
  }

  cpgsci(1);
  cpgptxt(0.0,3.0,0.0,0.5,"|ecliptic latitude|>10");
  cpgptxt(0.0,2.5,0.0,0.5,"night");

  cpgsci(3);
  cpgmove(-90.0,0.0);
  cpgdraw(-90.0,4.0);
  cpgmove( 90.0,0.0);
  cpgdraw( 90.0,4.0);
  cpgsci(1);


  cpgpanl(2,1);
  cpgswin(PHIMIN, PHIMAX, AMMIN, AMMAX);
  cpgbox("BCNTS",0.0,0,"BVCNTS",0.0,0);
  cpgmtxt("L",2.0,0.5,0.5,"airmass");
  cpgmtxt("B",2.0,0.5,0.5,"angle from Sun");

  cpgsci(2);
  for(i=0; i<numobs; i++) {

    jd = obs[i].date + 2400000.5;
    lstm = lst(jd,longitude_hrs);

    // get ecliptic coordinates
    slaEqecl(obs[i].ra, obs[i].dec, obs[i].date, &longEcliptic, &latEcliptic);

    if(fabs(latEcliptic) < 10.0/DEG_IN_RADIAN  && obs[i].twilight==1) {

      // get position of Sun
      accusun(jd, lstm, latitude_deg, &rasun, &decsun, &distsun,
              &toporasun, &topodecsun, &x, &y, &z);

      // sun-object angle in degrees
      // takes ra in hours, dec in degrees
      objra = adj_time(obs[i].ra*HRS_IN_RADIAN);
      objdec = obs[i].dec*DEG_IN_RADIAN;
      phi = mysubtend(rasun, decsun, objra, objdec)*DEG_IN_RADIAN;
      
      // angle from opposition is 180-phi
      //      FIXRANGE(phi,-180.0,180.0);
      
      //airmass takes ra, dec, in radians, returns true airmass
      airmass(obs[i].date, obs[i].ra, obs[i].dec, &trueam, &alt, &ha);
      
      cpgpt1(phi, trueam, -1);

    }
  }

  cpgsci(1);
  cpgptxt(0.0,3.0,0.0,0.5,"|ecliptic latitude|<10");
  cpgptxt(0.0,2.5,0.0,0.5,"twilight");

  cpgsci(3);
  cpgmove(-90.0,0.0);
  cpgdraw(-90.0,4.0);
  cpgmove( 90.0,0.0);
  cpgdraw( 90.0,4.0);
  cpgsci(1);


  cpgpanl(2,2);
  cpgswin(PHIMIN, PHIMAX, AMMIN, AMMAX);
  cpgbox("BCNTS",0.0,0,"BVCNTS",0.0,0);
  cpgmtxt("L",2.0,0.5,0.5,"airmass");
  cpgmtxt("B",2.0,0.5,0.5,"angle from Sun");

  cpgsci(2);
  for(i=0; i<numobs; i++) {

    jd = obs[i].date + 2400000.5;
    lstm = lst(jd,longitude_hrs);

    // get ecliptic coordinates
    slaEqecl(obs[i].ra, obs[i].dec, obs[i].date, &longEcliptic, &latEcliptic);

    if(fabs(latEcliptic) >= 10.0/DEG_IN_RADIAN  && obs[i].twilight==1) {

      // get position of Sun
      accusun(jd, lstm, latitude_deg, &rasun, &decsun, &distsun,
              &toporasun, &topodecsun, &x, &y, &z);

      // sun-object angle in degrees
      phi = mysubtend(rasun, decsun, obs[i].ra*HRS_IN_RADIAN, obs[i].dec*DEG_IN_RADIAN)*DEG_IN_RADIAN;
      
      // angle from opposition is 180-phi
      FIXRANGE(phi,-180.0,180.0);
      
      airmass(obs[i].date, obs[i].ra, obs[i].dec, &trueam, &alt, &ha);
      
      cpgpt1(phi, trueam, -1);

    }
  }

  cpgsci(1);
  cpgptxt(0.0,3.0,0.0,0.5,"|ecliptic latitude|>10");
  cpgptxt(0.0,2.5,0.0,0.5,"twilight");

  cpgsci(3);
  cpgmove(-90.0,0.0);
  cpgdraw(-90.0,4.0);
  cpgmove( 90.0,0.0);
  cpgdraw( 90.0,4.0);
  cpgsci(1);


  cpgebuf();
  closePlot();
}
Esempio n. 6
0
int main()
{
	//
	printf("\n====================================================================\n");
	printf("This program is able to simulate a variety of ecological\n");
	printf("situations in a 2D lattice\n");
	printf("====================================================================\n");

	//==========================================================================
	//--------------------------SYSTEM INITIALIZATIONS--------------------------
	//==========================================================================
	
	// initialize random seed
	srand(time(NULL));

	// force print all outputs (remove stdout buffer)
	setbuf(stdout, NULL);

	// initialize pgplot window
	if (!cpgopen("/XWINDOW"))
		errorCase(ERR_PGPLOT);
	cpgpap(20.0, 0.33);						// set window size
	cpgsubp(3,1);							// subdivide window into panels

	// color indexes (R, G, B)
	cpgscr(0, 0.0, 0.0, 0.0);				// empty space, black
	cpgscr(1, 1.0, 1.0, 1.0);
	cpgscr(10, 0.0, 0.0, 0.0);				// empty space, black
	cpgscr(11, 0.5, 0.5, 0.5);				// Trophic 1, gray
	cpgscr(12, 0.5, 1.0, 1.0);				// Trophic 2, cyan
	cpgscr(13, 1.0, 0.5, 0.0);				// Trophic 3, orange
	cpgscr(14, 1.0, 0.0, 0.0);
	cpgscir(10,NUMB_TROPHIC+10);


	//==========================================================================
	//--------------------------VARIABLE INITIALIZATIONS------------------------
	//==========================================================================

	// generic variables
	int i, j, k;						// counters

	// simulation environment
	int** simEnv = allocateArray2DInt(ENV_SIZE_X, ENV_SIZE_Y);
	int** simEnvAge = allocateArray2DInt(ENV_SIZE_X, ENV_SIZE_Y);
	int* simLocal = allocateArray1DInt(5);

	// inputs
	char input;

	// current location and time
	int x,y;
	int tGlobal,t;
	int flagUpdate;

	// rates
	float predationRates[NUMB_TROPHIC-1] = RATE_PRED;
	float deathRates[NUMB_TROPHIC] = RATE_DEATH;

	//float aBirth = 0;			// A+0 -> A+A
//	float abPred = 0;			// B+A -> B+B
//	float bDeath = 0;			//   B ->   0

//	int aFlag; int abFlag; int bFlag;

	// population counts;
	int popCount[NUMB_TROPHIC];
	float popDens[NUMB_TROPHIC];
	float popDensOld[NUMB_TROPHIC];
	for (i=0; i<NUMB_TROPHIC; i++){
		popCount[i] = 0;
		popDens[i] = 0.0;
		popDensOld[i] = 1.0/(float)INIT_DENSITY;
	}
	float* ageStructure = allocateArray1D(ENV_SIZE_TOTAL);


	// pgplot variables
	float* plotImg = allocateArray1D(ENV_SIZE_TOTAL);
	//float TR[6] = {0, 1, 0, 0, 0, 1};
	float TR[6] = {0, 0, 1, ENV_SIZE_Y, -1, 0};
	float plotMinBound = 0.0;
	float plotMaxBound = (float)NUMB_TROPHIC;


	//==========================================================================
	//--------------------------ACTUAL CODE-------------------------------------
	//==========================================================================
	
	// environment initialization
	randomizeArray2DInt(simEnv, ENV_SIZE_X, ENV_SIZE_Y, NUMB_TROPHIC);

	// load initial display
	for (i=0; i<ENV_SIZE_X; i++)
		for (j=0; j<ENV_SIZE_Y; j++)
			plotImg[i*ENV_SIZE_Y+j] = (float)(simEnv[i][j]);
	cpgpanl(1,1);
	cpgswin(0, ENV_SIZE_X-1, 0, ENV_SIZE_Y-1);
	cpgsvp(0.01, 0.99, 0.01, 0.99);
	cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR);

	// Load graph labels
	// Population Density vs Time Plot
	cpgpanl(2,1);
	cpgsvp(0.08, 0.92, 0.08, 0.92);
	cpgswin(0, ENV_SIZE_X, 0, 1);
	cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0);
	cpglab("Time", "Population Density", "");

	// Phase Portrait Plot
	cpgpanl(3,1);
	cpgsvp(0.08, 0.92, 0.08, 0.92);
	cpgswin(0, 1, 0, 1);
	cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0);
	cpglab("", "", "Phase Portrait");
	cpgsci(11);
	cpglab("Population Density SpA", "", "");
	cpgsci(12);
	cpglab("", "Population Density SpB", "");
	
	// initial delay to visualize starting matrix
	for (t=0; t<500000000; t++){}

	tGlobal = 1;
	while(1){
		//aFlag = 0; abFlag = 0; bFlag = 0;

		// run simulation for a full Monte Carlo timestep (ENV_SIZE_X*ENV_SIZE_Y)
		for (t=0; t<ENV_SIZE_TOTAL; t++){
			ecoRun(simEnv, simEnvAge, simLocal, predationRates, deathRates);
		}
		incrementAge(simEnvAge);

	

		// plot stuffs
		if ((tGlobal%1) == 0){

			// calculate population densities
			updatePopDens(simEnv, popCount, popDens);

			// PLOT population densities
			cpgpanl(2,1);
			cpgsvp(0.08, 0.92, 0.08, 0.92);
			cpgswin(0, ENV_SIZE_X, 0, 1);
			for (i=0; i<NUMB_TROPHIC; i++){
				cpgsls(1); cpgsci(i+11);				// line style and color
				cpgmove((tGlobal-1), popDensOld[i]);
				cpgdraw(tGlobal, popDens[i]);
			}

			//printArray2DInt(simEnvAge, ENV_SIZE_X, ENV_SIZE_Y);

			// PLOT age structure
			/*updateAgeStructure(simEnv, simEnvAge, ageStructure, 1);
			cpgpanl(3,1);
			cpgsvp(0.08, 0.92, 0.08, 0.92);
			cpgswin(0, 10, 0, (ENV_SIZE_TOTAL/10));
			cpgsls(1); cpgsci(1);						// line style and color
			cpgeras();
			cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0);
			cpglab("Age", "Number of Individuals", "Age Structure");
			cpghist(popCount[1], ageStructure, 0, 10, 10, 1);*/

			
			// PLOT phase portrait
			cpgpanl(3,1);
			cpgsvp(0.08, 0.92, 0.08, 0.92);
			cpgswin(0, 1, 0, 1);
			cpgsls(1); cpgsci(1);						// line style and color
			cpgmove(popDensOld[0], popDensOld[1]);
			cpgdraw(popDens[0], popDens[1]);

			for (i=0; i<NUMB_TROPHIC; i++)
				popDensOld[i] = popDens[i];
		}

		// load array and display on pgplot
		if ((tGlobal%1) == 0){
			cpgpanl(1,1);
			cpgswin(0, ENV_SIZE_X, 0, ENV_SIZE_Y);
			cpgsvp(0.01, 0.99, 0.01, 0.99);
			for (i=0; i<ENV_SIZE_X; i++)
				for (j=0; j<ENV_SIZE_Y; j++)
					plotImg[i*ENV_SIZE_Y+j] = (float)(simEnv[i][j]);
			cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR);
		}


		tGlobal++;
		//for (t=0; t<10000000; t++){}
	}
}
Esempio n. 7
0
/* switch to a different panel on the view surface */
static void _pgpanl (int *ix, int *iy)
{
   cpgpanl (*ix, *iy);
}