Example #1
0
/*
 *	readboard() 	Function to read in the scoreboard into a static buffer
 *
 *	returns -1 if unable to read in the scoreboard, returns 0 if all is OK
 */
readboard()
	{
	if (lopen(scorefile)<0)
	  { lprcat("Can't read scoreboard\n"); lflush(); return(-1); }
	lrfill((char*)sco,sizeof(sco));		lrfill((char*)winr,sizeof(winr));
	lrclose();  lcreat((char*)0);  return(0);
	}
Example #2
0
/*
 *	help function to display the help info
 *
 *	format of the .larn.help file
 *
 *	1st character of file:	# of pages of help available (ascii digit)
 *	page (23 lines) for the introductory message (not counted in above)
 *	pages of help text (23 lines per page)
 */
void
help(void)
{
	int i, j;
#ifndef VT100
	char tmbuf[128];		/* intermediate translation buffer when not a VT100 */
#endif /* VT100 */
	if ((j = openhelp()) < 0)	/* open the help file and get # pages */
		return;
	for (i = 0; i < 23; i++)	/* skip over intro message */
		lgetl();
	for (; j > 0; j--) {
		clear();
		for (i = 0; i < 23; i++)
#ifdef VT100
			lprcat(lgetl());	/* print out each line that we read in */
#else /* VT100 */
		{
			tmcapcnv(tmbuf, lgetl());
			lprcat(tmbuf);
		}		/* intercept \33's */
#endif /* VT100 */
		if (j > 1) {
			lprcat("    ---- Press ");
			standout("return");
			lprcat(" to exit, ");
			standout("space");
			lprcat(" for more help ---- ");
			i = 0;
			while ((i != ' ') && (i != '\n') && (i != '\33'))
				i = getchr();
			if ((i == '\n') || (i == '\33')) {
				lrclose();
				setscroll();
				drawscreen();
				return;
			}
		}
	}
	lrclose();
	retcont();
	drawscreen();
}
Example #3
0
/*
*  diedlog()   Subroutine to read a log file and print it out in ascii format
*/
void
diedlog (void)
{
  int n;
  char *p;
  struct stat stbuf;

  lcreat ((char *) 0);
  if (lopen (logfile) < 0)
    {
      lprintf ("Can't locate log file <%s>\n", logfile);
      return;
    }
  if (fstat (fd, &stbuf) < 0)
    {
      lprintf ("Can't  stat log file <%s>\n", logfile);
      return;
    }
  for (n = stbuf.st_size / sizeof (struct log_fmt); n > 0; --n)
    {
      lrfill ((char *) &logg, sizeof (struct log_fmt));
      p = ctime ((time_t *) & logg.diedtime);
      p[16] = '\n';
      p[17] = 0;
      lprintf ("Score: %d, Diff: %d,  %s %s on %d at %s", (int) (logg.score),
	       (int) (logg.diff), logg.who, logg.what, (int) (logg.cavelev),
	       p + 4);
#ifdef EXTRA
      if (logg.moves <= 0)
	logg.moves = 1;
      lprintf
	("  Experience Level: %d,  AC: %d,  HP: %d/%d,  Elapsed Time: %d minutes\n",
	 (int) (logg.lev), (int) (logg.ac), (int) (logg.hp),
	 (int) (logg.hpmax), (int) (logg.elapsedtime));

      lprintf
	("  BYTES in: %d, out: %d, moves: %d, deaths: %d, spells cast: %d\n",
	 (int) (logg.bytin), (int) (logg.bytout), (int) (logg.moves),
	 (int) (logg.killed), (int) (logg.spused));
      lprintf ("  out bytes per move: %d", (int) (logg.bytout / logg.moves));
      lprintf ("\n");
#endif
    }
  lflush ();
  lrclose ();
  return;
}
Example #4
0
int
getplid (char *nam)
{
  int fd7, high = 999, no;
  char *p, *p2;
  char name[80];

  if (havepid != -1)
    return (havepid);		/* already did it */
  lflush ();			/* flush any pending I/O */
  sprintf (name, "%s\n", nam);	/* append a \n to name */
  if (lopen (playerids) < 0)	/* no file, make it */
    {
      if ((fd7 = _creat (playerids, _S_IWRITE)) < 0)
	return (-1);		/* can't make it */
      _close (fd7);
      goto addone;		/* now append new playerid record to file */
    }
  for (;;)			/* now search for the name in the player id file */
    {
      p = lgetl ();
      if (p == NULL)
	break;			/* EOF? */
      no = atoi (p);		/* the id # */
      p2 = lgetl ();
      if (p2 == NULL)
	break;			/* EOF? */
      if (no > high)
	high = no;		/* accumulate highest id # */
      if (strcmp (p2, name) == 0)	/* we found him */
	{
	  return (no);		/* his id number */
	}
    }
  lrclose ();
  /* if we get here, we didn't find him in the file -- put him there */
addone:
  if (lappend (playerids) < 0)
    return (-1);		/* can't open file for append */
  lprintf ("%d\n%s", (int) ++high, name);	/* new id # and name */
  lwclose ();
  lcreat ((char *) 0);		/* re-open terminal channel */
  return (high);
}
Example #5
0
/*
 * readboard()	Function to read in the scoreboard into a static buffer
 *
 * returns -1 if unable to read in the scoreboard, returns 0 if all is OK
 */
int
readboard()
{
	int	i;

	setegid(egid);
	i = lopen(scorefile);
	setegid(gid);
	if (i < 0) {
		lprcat("Can't read scoreboard\n");
		lflush();
		return (-1);
	}
	lrfill((char *) sco, sizeof(sco));
	lrfill((char *) winr, sizeof(winr));
	lrclose();
	lcreat((char *) 0);
	return (0);
}
Example #6
0
/*
*  readboard()     Function to read in the scoreboard into a static buffer
*
*  returns -1 if unable to read in the scoreboard, returns 0 if all is OK
*/
static int
readboard (void)
{

  if (lopen (scorefile) < 0)
    {

      lprcat ("Can't read scoreboard\n");
      lflush ();

      return -1;
    }

  lrfill ((char *) sco, sizeof (sco));
  lrfill ((char *) winr, sizeof (winr));
  lrclose ();
  lcreat ((char *) 0);
  return 0;
}
Example #7
0
/*
 * diedlog() 	Subroutine to read a log file and print it out in ascii format
 */
void
diedlog(void)
{
	int    n;
	char  *p;
	static char  q[] = "?";
	struct stat     stbuf;
	time_t t;

	lcreat((char *) 0);
	if (lopen(logfile) < 0) {
		lprintf("Can't locate log file <%s>\n", logfile);
		return;
	}
	if (fstat(io_infd, &stbuf) < 0) {
		lprintf("Can't  stat log file <%s>\n", logfile);
		return;
	}
	for (n = stbuf.st_size / sizeof(struct log_fmt); n > 0; --n) {
		lrfill((char *) &logg, sizeof(struct log_fmt));
		t = logg.diedtime;
		if ((p = ctime(&t)) == NULL)
			p = q;
		else {
			p[16] = '\n';
			p[17] = 0;
		}
		lprintf("Score: %ld, Diff: %ld,  %s %s on %ld at %s", (long) (logg.score), (long) (logg.diff), logg.who, logg.what, (long) (logg.cavelev), p + 4);
#ifdef EXTRA
		if (logg.moves <= 0)
			logg.moves = 1;
		lprintf("  Experience Level: %ld,  AC: %ld,  HP: %ld/%ld,  Elapsed Time: %ld minutes\n", (long) (logg.lev), (long) (logg.ac), (long) (logg.hp), (long) (logg.hpmax), (long) (logg.elapsedtime));
		lprintf("  CPU time used: %ld seconds,  Machine usage: %ld.%02ld%%\n", (long) (logg.cputime), (long) (logg.usage / 100), (long) (logg.usage % 100));
		lprintf("  BYTES in: %ld, out: %ld, moves: %ld, deaths: %ld, spells cast: %ld\n", (long) (logg.bytin), (long) (logg.bytout), (long) (logg.moves), (long) (logg.killed), (long) (logg.spused));
		lprintf("  out bytes per move: %ld,  time per move: %ld ms\n", (long) (logg.bytout / logg.moves), (long) ((logg.cputime * 1000) / logg.moves));
#endif
	}
	lflush();
	lrclose();
	return;
}
Example #8
0
/*
 *	function to display the welcome message and background
 */
void
welcome(void)
{
	int i;
#ifndef VT100
	char tmbuf[128];	/* intermediate translation buffer when not a VT100 */
#endif /* VT100 */
	if (openhelp() < 0)	/* open the help file */
		return;
	clear();
	for (i = 0; i < 23; i++)
#ifdef VT100
		lprcat(lgetl());/* print out each line that we read in */
#else /* VT100 */
	{
		tmcapcnv(tmbuf, lgetl());
		lprcat(tmbuf);
	}			/* intercept \33's */
#endif /* VT100 */
	lrclose();
	retcont();		/* press return to continue */
}
Example #9
0
int main(int argc, char *argv[])
{
	bool cmplx, abc, taper;
	int ix, iz, it, itau, n2, m2;
	int nx, nz, ntau, nt, pad1, nb, nx2, nz2, nzx2, fnx, fnz, fnzx, nk;
	float dt, dtau, par, dz, dx, thresh;
	float tau0, tau;

	float **lt, **rt;
	float *curr, *prev;

	float ***dd, ***mm, **v0;

	sf_axis ax, az, atau;
	sf_file tgather, cgather, left, right;

	int cpuid, numprocs, nth;
	float *sendbuf, *recvbuf;
	MPI_Comm comm=MPI_COMM_WORLD;

	sf_init(argc, argv);

	MPI_Init(&argc, &argv);
	MPI_Comm_rank(comm, &cpuid);
	MPI_Comm_size(comm, &numprocs);

#ifdef _OPENMP
#pragma omp parallel
	{
		nth=omp_get_num_threads();
	}
	sf_warning(">>> Using %d threads <<<", nth);
#endif

	tgather=sf_input("--input");
	cgather=sf_output("--output");
	left=sf_input("left");
	right=sf_input("right");

	az=sf_iaxa(tgather, 1);
	ax=sf_iaxa(tgather, 2);
	atau=sf_iaxa(tgather, 3);

	nz=sf_n(az); dz = sf_d(az); 
	nx=sf_n(ax); dx = sf_d(ax);
	ntau=sf_n(atau); dtau=sf_d(atau); tau0=sf_o(atau);

	if(cpuid==0){
		sf_oaxa(cgather, az, 1);
		sf_oaxa(cgather, ax, 2);
		sf_oaxa(cgather, atau, 3);
	}

	if(!sf_getfloat("dt", &dt)) dt=0.001; /* time interval */
	if(!sf_getint("nb", &nb)) nb=60; /* boundary width */
	if(!sf_getfloat("par", &par)) par=0.01; /* absorbing boundary coefficient */
	if(!sf_getbool("cmplx", &cmplx)) cmplx=false; /* use complex FFT */
	if(!sf_getbool("abc", &abc)) abc=true; /* absorbing boundary condition */
	if(!sf_getint("pad1", &pad1)) pad1=1; /* padding factor on the first axis */
	if(!sf_getbool("taper", &taper)) taper=true; /* tapering */
	if(!sf_getfloat("thresh", &thresh)) thresh=0.92; /* thresholding */

	nx2=nx+2*nb;
	nz2=nz+2*nb;

	nk=fft2_init(cmplx,pad1,nz2,nx2,&fnz,&fnx);

	nzx2=nz2*nx2;
	fnzx=fnz*fnx;

	if (!sf_histint(left,"n1",&n2) || n2 != nzx2) sf_error("Need n1=%d in left",nzx2);
	if (!sf_histint(left,"n2",&m2))  sf_error("Need n2= in left");

	if (!sf_histint(right,"n1",&n2) || n2 != m2) sf_error("Need n1=%d in right",m2);
	if (!sf_histint(right,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in right",nk);

	lt = sf_floatalloc2(nzx2,m2);
	rt = sf_floatalloc2(m2,nk);

	sf_floatread(lt[0],nzx2*m2,left);
	sf_floatread(rt[0],m2*nk,right);

	dd=sf_floatalloc3(nz, nx, ntau);
	mm=sf_floatalloc3(nz, nx, ntau);
	v0=sf_floatalloc2(nz2, nx2);
	curr=sf_floatalloc(fnzx);
	prev=sf_floatalloc(fnzx);

	/* broad cast input time-shift gather */
	if(cpuid==0) sf_floatread(dd[0][0], ntau*nx*nz, tgather);
	for(itau=0; itau<ntau; itau++){
		MPI_Bcast(dd[itau][0], nx*nz, MPI_FLOAT, 0, comm);
	}

	/* initialize corrected time-shift gather */
#ifdef _OPENMP
#pragma omp parallel for private(itau, ix, iz)
#endif
	for(itau=0; itau<ntau; itau++)
		for(ix=0; ix<nx; ix++)
			for(iz=0; iz<nz; iz++)
				mm[itau][ix][iz]=0.;

	/* initialize functions */
	lrinit(nx2, nz2, m2, cmplx, pad1, nb, par, abc, lt, rt, taper, thresh, dz, dx);

	/* tau loop */
	for(itau=cpuid; itau<ntau; itau+=numprocs){
		sf_warning("itau=%d/%d", itau+1, ntau);

		tau=tau0+itau*dtau;

		// tau=0
		if(itau==(ntau-1)/2){
			for(ix=0; ix<nx; ix++)
				for(iz=0; iz<nz; iz++)
					mm[itau][ix][iz]=dd[itau][ix][iz];
			continue;
		}

		// calculate v0 (derivative with respect to tau)
		zero2(v0, nz2, nx2);
		if(itau==0){
			for(ix=0; ix<nx; ix++){
				for(iz=0; iz<nz; iz++){
					v0[ix+nb][iz+nb]=(dd[1][ix][iz]-dd[0][ix][iz])/dtau;
				}
			}
		} else if (itau==ntau-1){
			for(ix=0; ix<nx; ix++){
				for(iz=0; iz<nz; iz++){
					v0[ix+nb][iz+nb]=(dd[ntau-1][ix][iz]-dd[ntau-2][ix][iz])/dtau;
				}
			}
		} else {
#ifdef _OPENMP
#pragma omp parallel for private(ix, iz)
#endif
			for(ix=0; ix<nx; ix++){
				for(iz=0; iz<nz; iz++){
					v0[ix+nb][iz+nb]=(dd[itau+1][ix][iz]-dd[itau-1][ix][iz])/dtau/2.0;
				}
			}
		}

		// calculate u1
		zero1(curr, fnzx);
		zero1(prev, fnzx);
#ifdef _OPENMP
#pragma omp parallel for private(ix, iz)
#endif
		for(ix=0; ix<nx; ix++)
			for(iz=0; iz<nz; iz++)
				curr[(ix+nb)*fnz+iz+nb]=dd[itau][ix][iz];

		// tau>0
		if(itau>(ntau-1)/2){
			// calculate u(t-lt)
			for (ix=0; ix<nx2; ix++)
				for (iz=0; iz<nz2; iz++)
					prev[ix*fnz+iz]=2.*v0[ix][iz]*dt;

			lrupdate(curr,prev);

			for (ix=0; ix<fnzx; ix++)
				curr[ix]=curr[ix]/2.;
			// it loop
			nt=tau/dt+0.5;
			for(it=1; it<nt; it++){
			//	sf_warning("it=%d/%d;", it+1, nt);

				lrupdate(curr,prev);
			} //end of it
#ifdef _OPENMP
#pragma omp parallel for private(ix, iz)
#endif
			for(ix=0; ix<nx; ix++){
				for(iz=0; iz<nz; iz++){
					mm[itau][ix][iz]=curr[(ix+nb)*fnz+iz+nb];
				}
			}
		} // end of positive tau

		// tau<0
		if(itau<(ntau-1)/2){
			//calculate u(t+lt)
			for (ix=0; ix<nx2; ix++)
				for(iz=0; iz<nz2; iz++)
					prev[ix*fnz+iz]=-2.*v0[ix][iz]*dt;

			lrupdate(curr, prev);

			for (ix=0; ix<fnzx; ix++)
				curr[ix]=curr[ix]/2.;

			// it loop
			nt=-tau/dt+0.5;
			for(it=1; it<nt; it++){
				//sf_warning("it=%d/%d;", it+1, nt);

				lrupdate(curr, prev);
			}//end of it
#ifdef _OPENMP
#pragma omp parallel for private(ix, iz)
#endif
			for(ix=0; ix<nx; ix++){
				for(iz=0; iz<nz; iz++){
					mm[itau][ix][iz]=curr[(ix+nb)*fnz+iz+nb];
				}
			}
		}// end of negative tau
	} //end of itau
	MPI_Barrier(comm);

	/* corrected time-shift gather reduction */
	for(itau=0; itau<ntau; itau++){
		if(cpuid==0){
			sendbuf=MPI_IN_PLACE;
			recvbuf=mm[itau][0];
		}else{
			sendbuf=mm[itau][0];
			recvbuf=NULL;
		}
		MPI_Reduce(sendbuf, recvbuf, nz*nx, MPI_FLOAT, MPI_SUM, 0, comm);
	}
	
	if(cpuid==0) sf_floatwrite(mm[0][0], ntau*nz*nx, cgather);

	lrclose();
	MPI_Finalize();
}