Esempio n. 1
0
File: close.c Progetto: schwehr/hdf4
static void
cl_c()
{
    cline("   ncclose (ncid);");
    cline("   return 0;");
    cline("}");
}
Esempio n. 2
0
static void
cl_c(void)
{
    cline("   stat = nc_close(ncid);");
    cline("   check_err(stat,__LINE__,__FILE__);");
#ifndef vms
    cline("   return 0;");
#else
    cline("   return 1;");
#endif
    cline("}");
}
Esempio n. 3
0
void
roll(struct move *mm)
{
	char    c;
	int     row;
	int     col;

	row = col = 0;
	if (iroll) {
		if (tflag) {
			row = curr;
			col = curc;
			curmove(17, 0);
		} else
			writec('\n');
		writel("ROLL: ");
		c = readc();
		if (c != '\n') {
			while (c < '1' || c > '6')
				c = readc();
			mm->D0 = c - '0';
			writec(' ');
			writec(c);
			c = readc();
			while (c < '1' || c > '6')
				c = readc();
			mm->D1 = c - '0';
			writec(' ');
			writec(c);
			if (tflag) {
				curmove(17, 0);
				cline();
				curmove(row, col);
			} else
				writec('\n');
			return;
		}
		if (tflag) {
			curmove(17, 0);
			cline();
			curmove(row, col);
		} else
			writec('\n');
	}
	mm->D0 = rnum(6) + 1;
	mm->D1 = rnum(6) + 1;
	mm->d0 = 0;
}
Esempio n. 4
0
int
readc(void)
{
	char    c;

	if (tflag) {
		cline();
		newpos();
	}
	buflush();
	if (read(0, &c, 1) != 1)
		errexit("readc");
#ifdef WHY_IS_THIS_HARDWIRED_IN_HERE
	if (c == '\177')
		getout(0);
#endif
	if (c == '\033' || c == '\015')
		return ('\n');
	if (cflag)
		return (c);
	if (c == '\014')
		return ('R');
	if (c >= 'a' && c <= 'z')
		return (c & 0137);
	return (c);
}
Esempio n. 5
0
int main()
{	int n=0;
	g_irccoms=0;
	clinit(&g_irccoms);
	addcom(&g_irccoms,"list",NULL,plist,NULL,"List commands");
	while(cline(&g_irccoms,BLUE,NULL)!=DONE);
	return(1);
}
Esempio n. 6
0
clrest ()  {
	register int	r, c, j;

	r = curr;
	c = curc;
	for (j = r+1; j < 24; j++)  {
		curmove (j,0);
		cline();
	}
	curmove (r,c);
}
Esempio n. 7
0
/* Description:
Draws rocket 2 made of five lines.  This rocket looks like an arrowhead
Also draws rocket 2 torpedos as points. On exit leaves the DAC parked at the
center of the screen.
*/
void rocket2(rkt_data *rkt2)
{
int tmp_x, tmp_y;
int half_xs2, half_ys2;

  tmp_x = rkt2->xdisp - rkt2->xsize;    // pb_x = xd2 - xs2
  tmp_y = rkt2->ydisp - rkt2->ysize;    // pb_y = yd2 - ys2

  half_xs2 = rkt2->xsize >> 1;          // xs2/2
  half_ys2 = rkt2->ysize >> 1;          // ys2/2
  
  xinit = tmp_x;                        // start pb_x
  yinit = tmp_y;                        // start pb_y
  cline(rkt2->xdisp + rkt2->xsize, rkt2->ydisp + rkt2->ysize);  // draw line #1 b->a
  cline(tmp_x + half_ys2, tmp_y - half_xs2); // draw line #2 a->f
  cline(rkt2->xdisp - half_xs2, rkt2->ydisp - half_ys2); // draw line #3 f->c
  cline(tmp_x - half_ys2, tmp_y + half_xs2); // draw line #4 c->d
  cline(rkt2->xdisp + rkt2->xsize, rkt2->ydisp + rkt2->ysize); // draw line #5 d->a

  point(rkt2);                          // update and draw rkt2's torpedoes
  set_xy(center, center);               // park dot at center of screen
}
Esempio n. 8
0
void
getout(int dummy __unused)
{
	/* go to bottom of screen */
	if (tflag) {
		curmove(23, 0);
		cline();
	} else
		writec('\n');

	/* fix terminal status */
	fixtty(&old);
	exit(0);
}
Esempio n. 9
0
void
proll(struct move *mm)
{
	if (mm->d0)
		mswap(mm);
	if (cturn == 1)
		writel("Red's roll:  ");
	else
		writel("White's roll:  ");
	writec(mm->D0 + '0');
	writec('\040');
	writec(mm->D1 + '0');
	if (tflag)
		cline();
}
Esempio n. 10
0
void
gwrite(void)
{
	int     r, c;

	r = c = 0;
	if (tflag) {
		r = curr;
		c = curc;
		curmove(16, 0);
	}
	if (gvalue > 1) {
		writel("Game value:  ");
		wrint(gvalue);
		writel(".  ");
		if (dlast == -1)
			writel(color[0]);
		else
			writel(color[1]);
		writel(" doubled last.");
	} else {
		switch (pnum) {
		case -1:	/* player is red */
			writel(plred);
			break;
		case 0:	/* player is both colors */
			writel(nocomp);
			break;
		case 1:	/* player is white */
			writel(plwhite);
		}
	}

	if (rscore || wscore) {
		writel("  ");
		wrscore();
	}
	if (tflag) {
		cline();
		curmove(r, c);
	}
}
Esempio n. 11
0
/*  A constructor which is given a list of possible options and standard C-like fields with
    number of arguments and an array of char * pointers to arguments. If rupUnrec=true, unrecognized
    options are reported. */
TProgArguments::TProgArguments(const string &poss_options, int argc, char *argv[], bool repUnrec, bool parenth, bool anallowSpaces)
  : possibleOptions(), options(), unrecognized(), direct(), allowSpaces(anallowSpaces)
{ findPossibleOptions(poss_options);
  vector<string> optionsList;

  if (argc>1)
    if (parenth) {
      string cline(argv[1]);
      for(int i=2; i<argc; ) {
        string as(argv[i++]);
        if (as.find(' ')==string::npos) cline+=' '+as;
        else cline+=" \""+as+"\"";
      }
      string2atoms(cline, optionsList);
    }
    else
      while(--argc) optionsList.push_back(*(++argv));

  defile(optionsList);
  process(optionsList);

  if (repUnrec) reportUnrecognized();
}
Esempio n. 12
0
int main(int c, char *v[])
{
	if (c != 2 && c != 3) {
		fprintf(stderr, "usage:\n\t%s angle [img] >plot\n", *v);
		//                          0 1      2
		return 1;
	}
	float angle = atof(v[1]);
	char *in_img = c>2 ? v[2] : "-";
	int w, h;
	float *x = iio_read_image_float(in_img, &w, &h);
	int n = NFAC()*(2+hypot(w+2,h+2));
	fprintf(stderr, "geometry = %dx%d\n", w, h);
	fprintf(stderr, "n = %d\n", n);
	float l[n], musigma[2] = {0};
	if (isfinite(angle))
		cline(musigma, l, n, x, w, h, angle);
	else
		clineh(NULL, l, n, x, w, h);
	//plot_cline(l, n, v[1], musigma[0], musigma[1]);
	plot_cline2(l, n);
	free(x);
	return 0;
}
Esempio n. 13
0
/* generate C to put netCDF record from in-memory data */
static void
gen_load_c(
    void *rec_start
    )
{
    int  idim, ival;
    char *val_string;
    char *charvalp = NULL;
    short *shortvalp = NULL;
    int *intvalp = NULL;
    float *floatvalp = NULL;
    double *doublevalp = NULL;
    unsigned char *ubytevalp = NULL;
    unsigned short *ushortvalp = NULL;
    unsigned int *uintvalp = NULL;
    long long *int64valp = NULL;
    unsigned long long *uint64valp = NULL;
    char stmnt[C_MAX_STMNT];
    size_t stmnt_len;
    char s2[C_MAX_STMNT];

    if (!vars[varnum].has_data)
	return;

    s2[0] = '\0';
    cline("");
    sprintf(stmnt, "   {\t\t\t/* store %s */", vars[varnum].name);
    cline(stmnt);

    if (vars[varnum].ndims > 0) {
	if (vars[varnum].dims[0] == rec_dim) {
	    sprintf(stmnt, "    static MPI_Offset %s_start[RANK_%s];",
		    vars[varnum].lname, vars[varnum].lname);
	    cline(stmnt);

	    sprintf(stmnt, "    static MPI_Offset %s_count[RANK_%s];",
		    vars[varnum].lname, vars[varnum].lname);
	    cline(stmnt);
	}

	/* load variable with data values using static initialization */
	sprintf(stmnt, "    static %s %s[] = {",
		ncctype(vars[varnum].type),
		vars[varnum].lname);

	stmnt_len = strlen(stmnt);
	switch (vars[varnum].type) {
	  case NC_CHAR:
	    val_string = cstrstr((char *) rec_start, var_len);
	    sprintf(s2, "%s", val_string);
	    strncat(stmnt, s2, C_MAX_STMNT - strlen(stmnt) );
	    free(val_string);
	    break;
	  default:
	    switch (vars[varnum].type) {
	      case NC_BYTE:
		charvalp = (char *) rec_start;
		break;
	      case NC_SHORT:
		shortvalp = (short *) rec_start;
		break;
	      case NC_INT:
		intvalp = (int *) rec_start;
		break;
	      case NC_FLOAT:
		floatvalp = (float *) rec_start;
		break;
	      case NC_DOUBLE:
		doublevalp = (double *) rec_start;
		break;
	      case NC_UBYTE:
		ubytevalp = (unsigned char *) rec_start;
		break;
	      case NC_USHORT:
		ushortvalp = (unsigned short *) rec_start;
		break;
	      case NC_UINT:
		uintvalp = (unsigned int *) rec_start;
		break;
	      case NC_INT64:
		int64valp = (long long *) rec_start;
		break;
	      case NC_UINT64:
		uint64valp = (unsigned long long *) rec_start;
		break;
	      default:
		derror("Unhandled type %d\n", vars[varnum].type);
		return;
	    }
            for (ival = 0; ival < var_len-1; ival++) {
		switch (vars[varnum].type) {
		  case NC_BYTE:
			sprintf(s2, "%d, ", *charvalp++);
		    break;
		  case NC_SHORT:
			sprintf(s2, "%d, ", *shortvalp++);
		    break;
		  case NC_INT:
			sprintf(s2, "%ld, ", (long)*intvalp++);
		    break;
		  case NC_FLOAT:
			sprintf(s2, "%.8g, ", *floatvalp++);
		    break;
		  case NC_DOUBLE:
			sprintf(s2, "%#.16g", *doublevalp++);
			tztrim(s2);
			strcat(s2, ", ");
		    break;
		  case NC_UBYTE:
			sprintf(s2, "%hhu, ", (unsigned char)*ubytevalp++);
		    break;
		  case NC_USHORT:
			sprintf(s2, "%hu, ", (unsigned short)*ushortvalp++);
		    break;
		  case NC_UINT:
			sprintf(s2, "%u, ", (unsigned int)*uintvalp++);
		    break;
		  case NC_INT64:
			sprintf(s2, "%lld, ", (long long)*int64valp++);
		    break;
		  case NC_UINT64:
			sprintf(s2, "%llu, ", (unsigned long long)*uint64valp++);
		    break;
		  default:
		    derror("Unhandled type %d\n", vars[varnum].type);
		    return;

		}
		stmnt_len += strlen(s2);
		if (stmnt_len < C_MAX_STMNT)
		  strcat(stmnt, s2);
		else {
		    cline(stmnt);
		    strcpy(stmnt,s2);
		    stmnt_len = strlen(stmnt);
		}
	    }
	    for (;ival < var_len; ival++) {
		switch (vars[varnum].type) {
		  case NC_BYTE:
			sprintf(s2, "%d", *charvalp);
		    break;
		  case NC_SHORT:
			sprintf(s2, "%d", *shortvalp);
		    break;
		  case NC_INT:
			sprintf(s2, "%ld", (long)*intvalp);
		    break;
		  case NC_FLOAT:
			sprintf(s2, "%.8g", *floatvalp);
		    break;
		  case NC_DOUBLE:
			sprintf(s2, "%#.16g", *doublevalp++);
			tztrim(s2);
		    break;
		  case NC_UBYTE:
			sprintf(s2, "%hhu, ", (unsigned char)*ubytevalp++);
		    break;
		  case NC_USHORT:
			sprintf(s2, "%hu, ", (unsigned short)*ushortvalp++);
		    break;
		  case NC_UINT:
			sprintf(s2, "%u, ", (unsigned int)*uintvalp++);
		    break;
		  case NC_INT64:
			sprintf(s2, "%lld, ", (long long)*int64valp++);
		    break;
		  case NC_UINT64:
			sprintf(s2, "%llu, ", (unsigned long long)*uint64valp++);
		    break;
		  default:
		    derror("Unhandled type %d\n", vars[varnum].type);
		    break;
		}
		stmnt_len += strlen(s2);
		if (stmnt_len < C_MAX_STMNT)
		  strcat(stmnt, s2);
		else {
		    cline(stmnt);
		    strcpy(stmnt,s2);
		    stmnt_len = strlen(stmnt);
		}
	    }
	    break;
	}
	strcat(stmnt,"};");
	cline(stmnt);

	if (vars[varnum].dims[0] == rec_dim) {
	    sprintf(stmnt,
		    "    %s_len = %lu;			/* number of records of %s data */",
		    dims[rec_dim].lname,
		    (unsigned long)vars[varnum].nrecs, /* number of recs for this variable */
		    vars[varnum].name);
	    cline(stmnt);

	    for (idim = 0; idim < vars[varnum].ndims; idim++) {
		sprintf(stmnt, "    %s_start[%d] = 0;",
			vars[varnum].lname,
			idim);
		cline(stmnt);
	    }

	    for (idim = 0; idim < vars[varnum].ndims; idim++) {
		sprintf(stmnt, "    %s_count[%d] = %s_len;",
			vars[varnum].lname,
			idim,
			dims[vars[varnum].dims[idim]].lname);
		cline(stmnt);
	    }
	}

	if (vars[varnum].dims[0] == rec_dim) {
	    sprintf(stmnt,
		    "    stat = ncmpi_put_vara_%s_all(ncid, %s_id, %s_start, %s_count, %s);",
		    ncstype(vars[varnum].type),
		    vars[varnum].lname,
		    vars[varnum].lname,
		    vars[varnum].lname,
		    vars[varnum].lname);
	     cline(stmnt);
	} else {		/* non-record variables */
	    cline("  ncmpi_begin_indep_data(ncid);");
	    sprintf(stmnt,
		    "    stat = ncmpi_put_var_%s(ncid, %s_id, %s);",
		    ncstype(vars[varnum].type),
		    vars[varnum].lname,
		    vars[varnum].lname);
	    cline(stmnt);
	    cline("  ncmpi_end_indep_data(ncid);");
	}
    } else {			/* scalar variables */
	/* load variable with data values using static initialization */
	sprintf(stmnt, "    static %s %s = ",
		ncctype(vars[varnum].type),
		vars[varnum].lname);

	switch (vars[varnum].type) {
	  case NC_CHAR:
	    val_string = cstrstr((char *) rec_start, var_len);
	    val_string[strlen(val_string)-1] = '\0';
	    sprintf(s2, "'%s'", &val_string[1]);
	    free(val_string);
	    break;
	  case NC_BYTE:
	    charvalp = (char *) rec_start;
	    sprintf(s2, "%d", *charvalp);
	    break;
	  case NC_SHORT:
	    shortvalp = (short *) rec_start;
	    sprintf(s2, "%d", *shortvalp);
	    break;
	  case NC_INT:
	    intvalp = (int *) rec_start;
	    sprintf(s2, "%ld", (long)*intvalp);
	    break;
	  case NC_FLOAT:
	    floatvalp = (float *) rec_start;
	    sprintf(s2, "%.8g", *floatvalp);
	    break;
	  case NC_DOUBLE:
	    doublevalp = (double *) rec_start;
	    sprintf(s2, "%#.16g", *doublevalp++);
	    tztrim(s2);
	    break;
	  case NC_UBYTE:
	    ubytevalp = (unsigned char *) rec_start;
	    sprintf(s2, "%hhu", (unsigned char)*ubytevalp);
	    break;
	  case NC_USHORT:
	    ushortvalp = (unsigned short *) rec_start;
	    sprintf(s2, "%hu", (unsigned short)*ushortvalp);
	    break;
	  case NC_UINT:
	    uintvalp = (unsigned int *) rec_start;
	    sprintf(s2, "%u", (unsigned int)*uintvalp);
	    break;
	  case NC_INT64:
	    int64valp = (long long *) rec_start;
	    sprintf(s2, "%lld", (long long)*int64valp);
	    break;
	  case NC_UINT64:
	    uint64valp = (unsigned long long *) rec_start;
	    sprintf(s2, "%llu", (unsigned long long)*uint64valp);
	    break;
	  default:
	    derror("Unhandled type %d\n", vars[varnum].type);
	    break;
	}
	strncat(stmnt, s2, C_MAX_STMNT - strlen(stmnt) );
	strcat(stmnt,";");
	cline(stmnt);
	cline("  ncmpi_begin_indep_data(ncid);");
	sprintf(stmnt,
		"    stat = ncmpi_put_var_%s(ncid, %s_id, &%s);",
		ncstype(vars[varnum].type),
		vars[varnum].lname,
		vars[varnum].lname);
	cline(stmnt);
	cline("  ncmpi_end_indep_data(ncid);");
    }
    cline("    check_err(stat,__LINE__,__FILE__);");
    cline("   }");
}
Esempio n. 14
0
/*
 * Generate C code for creating netCDF from in-memory structure.
 */
static void
gen_c(
     const char *filename)
{
    int idim, ivar, iatt, jatt, maxdims;
    int vector_atts;
    char *val_string;
    char stmnt[C_MAX_STMNT];

    /* wrap in main program */
    cline("#include <stdio.h>");
    cline("#include <stdlib.h>");
    cline("#include <netcdf.h>");
    cline("");
    cline("void");
    cline("check_err(const int stat, const int line, const char *file) {");
    cline("    if (stat != NC_NOERR) {");
    cline("	   (void) fprintf(stderr, \"line %d of %s: %s\\n\", line, file, nc_strerror(stat));");
    cline("        exit(1);");
    cline("    }");
    cline("}");
    cline("");
    cline("int");
    sprintf(stmnt, "main() {\t\t\t/* create %s */", filename);
    cline(stmnt);

    /* create necessary declarations */
    cline("");
    cline("   int  stat;\t\t\t/* return status */");
    cline("   int  ncid;\t\t\t/* netCDF id */");

    if (ndims > 0) {
	cline("");
	cline("   /* dimension ids */");
	for (idim = 0; idim < ndims; idim++) {
	    sprintf(stmnt, "   int %s_dim;", dims[idim].lname);
	    cline(stmnt);
	    }

	cline("");
	cline("   /* dimension lengths */");
	for (idim = 0; idim < ndims; idim++) {
	    if (dims[idim].size == NC_UNLIMITED) {
		sprintf(stmnt, "   size_t %s_len = NC_UNLIMITED;",
			dims[idim].lname);
	    } else {
		sprintf(stmnt, "   size_t %s_len = %lu;",
			dims[idim].lname,
			(unsigned long) dims[idim].size);
	    }
	    cline(stmnt);
	}
    }

    maxdims = 0;	/* most dimensions of any variable */
    for (ivar = 0; ivar < nvars; ivar++)
      if (vars[ivar].ndims > maxdims)
	maxdims = vars[ivar].ndims;

    if (nvars > 0) {
	cline("");
	cline("   /* variable ids */");
	for (ivar = 0; ivar < nvars; ivar++) {
	    sprintf(stmnt, "   int %s_id;", vars[ivar].lname);
	    cline(stmnt);
	}

	cline("");
	cline("   /* rank (number of dimensions) for each variable */");
	for (ivar = 0; ivar < nvars; ivar++) {
	    sprintf(stmnt, "#  define RANK_%s %d", vars[ivar].lname,
		    vars[ivar].ndims);
	    cline(stmnt);
	}
	if (maxdims > 0) {	/* we have dimensioned variables */
	    cline("");
	    cline("   /* variable shapes */");
	    for (ivar = 0; ivar < nvars; ivar++) {
		if (vars[ivar].ndims > 0) {
		    sprintf(stmnt, "   int %s_dims[RANK_%s];",
			    vars[ivar].lname, vars[ivar].lname);
		    cline(stmnt);
		}
	    }
	}
    }

    /* determine if we need any attribute vectors */
    vector_atts = 0;
    for (iatt = 0; iatt < natts; iatt++) {
	if (atts[iatt].type != NC_CHAR) {
	    vector_atts = 1;
	    break;
	}
    }
    if (vector_atts) {
	cline("");
	cline("   /* attribute vectors */");
	for (iatt = 0; iatt < natts; iatt++) {
	    if (atts[iatt].type != NC_CHAR) {
		sprintf(stmnt,
		    "   %s %s_%s[%lu];",
		    ncatype(atts[iatt].type),
		    atts[iatt].var == -1 ? "cdf" : vars[atts[iatt].var].lname,
		    atts[iatt].lname,
		    (unsigned long) atts[iatt].len);
		cline(stmnt);
	    }
	}
    }

    /* create netCDF file, uses NC_CLOBBER mode */
    cline("");
    cline("   /* enter define mode */");

    if (!cmode_modifier) {
	sprintf(stmnt,
		"   stat = nc_create(\"%s\", NC_CLOBBER, &ncid);",
		filename);
    } else if (cmode_modifier & NC_64BIT_OFFSET) {
	sprintf(stmnt,
		"   stat = nc_create(\"%s\", NC_CLOBBER|NC_64BIT_OFFSET, &ncid);",
		filename);
#ifdef USE_NETCDF4
    } else if (cmode_modifier & NC_CLASSIC_MODEL) {
	sprintf(stmnt,
		"   stat = nc_create(\"%s\", NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid);",
		filename);
    } else if (cmode_modifier & NC_NETCDF4) {
	sprintf(stmnt,
		"   stat = nc_create(\"%s\", NC_CLOBBER|NC_NETCDF4, &ncid);",
		filename);
#endif
    } else {
       derror("unknown cmode modifier");
    }
    cline(stmnt);
    cline("   check_err(stat,__LINE__,__FILE__);");
    
    /* define dimensions from info in dims array */
    if (ndims > 0) {
	cline("");
	cline("   /* define dimensions */");
    }
    for (idim = 0; idim < ndims; idim++) {
	sprintf(stmnt,
		"   stat = nc_def_dim(ncid, \"%s\", %s_len, &%s_dim);",
		dims[idim].name, dims[idim].lname, dims[idim].lname);
	cline(stmnt);
	cline("   check_err(stat,__LINE__,__FILE__);");
    }

    /* define variables from info in vars array */
    if (nvars > 0) {
	cline("");
	cline("   /* define variables */");
	for (ivar = 0; ivar < nvars; ivar++) {
	    cline("");
	    for (idim = 0; idim < vars[ivar].ndims; idim++) {
		sprintf(stmnt,
			"   %s_dims[%d] = %s_dim;",
			vars[ivar].lname,
			idim,
			dims[vars[ivar].dims[idim]].lname);
		cline(stmnt);
	    }
	    if (vars[ivar].ndims > 0) {	/* a dimensioned variable */
		sprintf(stmnt,
			"   stat = nc_def_var(ncid, \"%s\", %s, RANK_%s, %s_dims, &%s_id);",
			vars[ivar].name,
			nctype(vars[ivar].type),
			vars[ivar].lname,
			vars[ivar].lname,
			vars[ivar].lname);
	    } else {		/* a scalar */
		sprintf(stmnt,
			"   stat = nc_def_var(ncid, \"%s\", %s, RANK_%s, 0, &%s_id);",
			vars[ivar].name,
			nctype(vars[ivar].type),
			vars[ivar].lname,
			vars[ivar].lname);
	    }
	    cline(stmnt);
	    cline("   check_err(stat,__LINE__,__FILE__);");
	}
    }
    
    /* define attributes from info in atts array */
    if (natts > 0) {
	cline("");
	cline("   /* assign attributes */");
	for (iatt = 0; iatt < natts; iatt++) {
	    if (atts[iatt].type == NC_CHAR) { /* string */
		val_string = cstrstr((char *) atts[iatt].val, atts[iatt].len);
		sprintf(stmnt,
			"   stat = nc_put_att_text(ncid, %s%s, \"%s\", %lu, %s);",
			atts[iatt].var == -1 ? "NC_GLOBAL" : vars[atts[iatt].var].lname,
			atts[iatt].var == -1 ? "" : "_id",
			atts[iatt].name,
			(unsigned long) atts[iatt].len,
			val_string);
		cline(stmnt);
		free (val_string);
	    }
	    else {			/* vector attribute */
		for (jatt = 0; jatt < atts[iatt].len ; jatt++) {
		    val_string = cstring(atts[iatt].type,atts[iatt].val,jatt);
		    sprintf(stmnt, "   %s_%s[%d] = %s;",
			    atts[iatt].var == -1 ? "cdf" : vars[atts[iatt].var].lname,
			    atts[iatt].lname,
			    jatt, 
			    val_string);
		    cline(stmnt);
		    free (val_string);
		}
		
		sprintf(stmnt,
			"   stat = nc_put_att_%s(ncid, %s%s, \"%s\", %s, %lu, %s_%s);",
			ncatype(atts[iatt].type),
			atts[iatt].var == -1 ? "NC_GLOBAL" : vars[atts[iatt].var].lname,
			atts[iatt].var == -1 ? "" : "_id",
			atts[iatt].name,
			nctype(atts[iatt].type),
			(unsigned long) atts[iatt].len,
			atts[iatt].var == -1 ? "cdf" : vars[atts[iatt].var].lname,
			atts[iatt].lname);
		cline(stmnt);
	    }
	    cline("   check_err(stat,__LINE__,__FILE__);");
	}
    }

    if (nofill_flag) {
        cline("   /* don't initialize variables with fill values */");
	cline("   stat = nc_set_fill(ncid, NC_NOFILL, 0);");
	cline("   check_err(stat,__LINE__,__FILE__);");
    }

    cline("");
    cline("   /* leave define mode */");
    cline("   stat = nc_enddef (ncid);");
    cline("   check_err(stat,__LINE__,__FILE__);");
}
Esempio n. 15
0
	void morph(const QImage& I0,const QImage& I1,
		const QLineF* lines0,
		const QLineF* lines1,
		int lines_num,
		float s, // 0.0 -> 1.0
		float a,float b,float p, // parameters
		QImage& Idst,
		QVector<QLineF>& lines_dst,
		int show_ui)
	{

		assert(I0.size()==I1.size());
		

		int w=I0.width(),h=I0.height();
		QImage warped_I0(w,h,QImage::Format_ARGB32),
			warped_I1(w,h,QImage::Format_ARGB32);
		
		std::vector<CachedLine2> clines_dst,
			clines_0,clines_1;


		clines_0.reserve(lines_num);clines_1.reserve(lines_num);clines_dst.reserve(lines_num);
		
		for(int i=0;i<lines_num;++i)
		{
			clines_0.push_back(CachedLine2(lines0[i]));
			clines_1.push_back(CachedLine2(lines1[i]));
		}

		lines_dst.reserve(lines_num);
		lines_dst.clear();
		// interpolate feature lines
		//		by interpolate two endpoints
		//		or interpolate center and direction
		for(int i=0;i<lines_num;++i)
		{
			CachedLine2 cline(
				lerp(clines_0[i].P,clines_1[i].P,s),
				lerp(clines_0[i].Q,clines_1[i].Q,s),
				true
				);

			clines_dst.push_back(cline);

			lines_dst.push_back(QLineF(cline.P.x,cline.P.y,cline.Q.x,cline.Q.y));
			//lines_dst.push_back(QLineF(cline.Q.x,cline.Q.y,
			//	cline.Q.x+7.f*cline.unit_perpendicular.x,
			//	cline.Q.y+7.f*cline.unit_perpendicular.y));
		}

		int bytes=I0.byteCount(),bytes_line=I0.bytesPerLine();
#ifdef USE_BSGP
		if(show_ui&1)
			warp_bsgp((uchar*)I0.bits(),(uchar*)warped_I0.bits(),
			w,h,bytes,bytes_line,
			(FLine*)&clines_0[0],(FLine*)&clines_dst[0],lines_num,
			a,b,p);
		if(show_ui&2)
			warp_bsgp((uchar*)I1.bits(),(uchar*)warped_I1.bits(),
			w,h,bytes,bytes_line,
			(FLine*)&clines_1[0],(FLine*)&clines_dst[0],lines_num,
			a,b,p);
#else
		if(show_ui&1)
			warp(I0,&clines_0[0],&clines_dst[0],lines_num,warped_I0,a,b,p);
		if(show_ui&2)
			warp(I1,&clines_1[0],&clines_dst[0],lines_num,warped_I1,a,b,p);
		//warp_incremental(I1,&clines_1[0],&clines_dst[0],lines_num,warped_I1);
#endif


		

		//Idst=warped_I1;//.copy()
		if(show_ui==3)
#ifdef USE_BSGP
			cross_dissolve_bsgp(warped_I0.bits(),warped_I1.bits(),warped_I0.byteCount(),s,Idst.bits());
#else
			cross_dissolve(warped_I0,warped_I1,s,Idst);
#endif			
		else if(show_ui&1)
Esempio n. 16
0
/* zero if first move */
void
move(struct move *mm, int okay)
{
	int     i;		/* index */
	int     l;		/* last man */

	l = 0;
	if (okay) {
		/* see if comp should double */
		if (gvalue < 64 && dlast != cturn && dblgood()) {
			writel(*Colorptr);
			dble();	/* double */
			/* return if declined */
			if (cturn != 1 && cturn != -1)
				return;
		}
		roll(mm);
	}
	race = 0;
	for (i = 0; i < 26; i++) {
		if (board[i] < 0)
			l = i;
	}
	for (i = 0; i < l; i++) {
		if (board[i] > 0)
			break;
	}
	if (i == l)
		race = 1;

	/* print roll */
	if (tflag)
		curmove(cturn == -1 ? 18 : 19, 0);
	writel(*Colorptr);
	writel(" rolls ");
	writec(mm->D0 + '0');
	writec(' ');
	writec(mm->D1 + '0');
	/* make tty interruptable while thinking */
	if (tflag)
		cline();
	fixtty(&noech);

	/* find out how many moves */
	mm->mvlim = movallow(mm);
	if (mm->mvlim == 0) {
		writel(" but cannot use it.\n");
		nexturn();
		fixtty(&raw);
		return;
	}
	/* initialize */
	for (i = 0; i < 4; i++)
		cp[i] = cg[i] = 0;

	/* strategize */
	trymove(mm, 0, 0);
	pickmove(mm);

	/* print move */
	writel(" and moves ");
	for (i = 0; i < mm->mvlim; i++) {
		if (i > 0)
			writec(',');
		wrint(mm->p[i] = cp[i]);
		writec('-');
		wrint(mm->g[i] = cg[i]);
		makmove(mm, i);

		/*
		 * This assertion persuades gcc 4.5 that the loop
		 * doesn't result in signed overflow of i. mvlim
		 * isn't, or at least shouldn't be, changed by makmove
		 * at all.
		 */
		assert(mm->mvlim >= 0 && mm->mvlim <= 5);
	}
	writec('.');

	/* print blots hit */
	if (tflag)
		curmove(20, 0);
	else
		writec('\n');
	for (i = 0; i < mm->mvlim; i++)
		if (mm->h[i])
			wrhit(mm->g[i]);
	/* get ready for next move */
	nexturn();
	if (!okay) {
		buflush();
		sleep(3);
	}
	fixtty(&raw);		/* no more tty interrupt */
}
Esempio n. 17
0
/* zero if first move */
void
move(int okay)
{
    int i;			/* index */
    int l;			/* last man */

    l = 0;
    if (okay) {
        /* see if comp should double */
        if (gvalue < 64 && dlast != cturn && dblgood()) {
            writel(*Colorptr);
            dble();		/* double */
            /* return if declined */
            if (cturn != 1 && cturn != -1)
                return;
        }
        roll();
    }

    race = 0;
    for (i = 0; i < 26; i++) {
        if (board[i] < 0)
            l = i;
    }
    for (i = 0; i < l; i++) {
        if (board[i] > 0)
            break;
    }
    if (i == l)
        race = 1;

    /* print roll */
    if (tflag)
        curmove(cturn == -1 ? 18 : 19, 0);
    writel(*Colorptr);
    writel(" rolls ");
    writec(D0 + '0');
    writec(' ');
    writec(D1 + '0');
    /* make tty interruptable while thinking */
    if (tflag)
        cline();
    fixtty(noech);

    /* find out how many moves */
    mvlim = movallow();
    if (mvlim == 0) {
        writel(" but cannot use it.\n");
        nexturn();
        fixtty(raw);
        return;
    }

    /* initialize */
    for (i = 0; i < 4; i++)
        cp[i] = cg[i] = 0;

    /* strategize */
    trymove(0, 0);
    pickmove();

    /* print move */
    writel(" and moves ");
    for (i = 0; i < mvlim; i++) {
        if (i > 0)
            writec(',');
        wrint(p[i] = cp[i]);
        writec('-');
        wrint(g[i] = cg[i]);
        makmove(i);
    }
    writec('.');

    /* print blots hit */
    if (tflag)
        curmove(20, 0);
    else
        writec('\n');
    for (i = 0; i < mvlim; i++)
        if (h[i])
            wrhit(g[i]);
    /* get ready for next move */
    nexturn();
    if (!okay) {
        buflush();
        sleep(3);
    }
    fixtty(raw);		/* no more tty interrupt */
}
Esempio n. 18
0
getmove ()  {
	register int	i, c;

	c = 0;
	for (;;)  {
		i = checkmove(c);

		switch (i)  {
		case -1:
			if (movokay(mvlim))  {
				if (tflag)
					curmove (20,0);
				else
					writec ('\n');
				for (i = 0; i < mvlim; i++)
					if (h[i])
						wrhit(g[i]);
				nexturn();
				if (*offopp == 15)
					cturn *= -2;
				if (tflag && pnum)
					bflag = pnum;
				return;
			}

		case -4:
		case 0:
			if (tflag)
				refresh();
			if (i != 0 && i != -4)
				break;
			if (tflag)
				curmove (20,0);
			else
				writec ('\n');
			writel (*Colorptr);
			if (i == -4)
				writel (" must make ");
			else
				writel (" can only make ");
			writec (mvlim+'0');
			writel (" move");
			if (mvlim > 1)
				writec ('s');
			writec ('.');
			writec ('\n');
			break;

		case -3:
			if (quit())
				return;
		}

		if (! tflag)
			proll ();
		else  {
			curmove (cturn == -1? 18: 19,39);
			cline ();
			c = -1;
		}
	}
}
Esempio n. 19
0
void the_const_problem(ImageDouble& img, const ImageDouble& cimg) {

  mirage::img::Coordinate coord, origin, size;

  //                           //
  //  The problem with images  //
  //                           //

  ImageDouble::pixel_type pix,pix_end;
  ImageDouble::const_pixel_type cpix,cpix_end;
  ImageDouble::value_type *ptr;
  const ImageDouble::value_type *cptr;


  for(pix = img.begin(), pix_end = img.end(), 
        cpix = cimg.const_begin(), cpix_end = cimg.const_end();
      pix != pix_end && cpix != cpix_end;
      ++pix,++cpix) {
    coord = !pix;
    coord = !cpix;
    *pix  = *cpix;
    // *cpix = *pix;  ...is forbidden by the compiler.
  }

  coord(10,10);
  ptr  = &(img(coord));
  cptr = &(img(coord));
  ptr  = &(img[coord]);
  cptr = &(img[coord]);
  // ptr  = &(cimg(coord));  ...is forbidden by the compiler.
  cptr = &(cimg(coord));
  // ptr  = &(cimg[coord]);  ...is forbidden by the compiler.
  cptr = &(cimg[coord]);



  //                               //
  //  The problem with sub images  //
  //                               //



  origin(10,10);
  size(320,240);
  mirage::SubFrame<ImageDouble> subimg(img,origin,size);
  // mirage::SubFrame<ImageDouble> csubimg(cimg,origin,size); ... forbidden by the compiler.
  mirage::ConstSubFrame<ImageDouble> csubimg(cimg,origin,size);

  
  mirage::SubFrame<ImageDouble>::pixel_type spix,spix_end; // const_pixel_type is also available.
  mirage::ConstSubFrame<ImageDouble>::const_pixel_type cspix,cspix_end;

  
  for(spix = subimg.begin(), spix_end = subimg.end(), 
        cspix = csubimg.const_begin(), cspix_end = csubimg.const_end();
      spix != spix_end && cspix != cspix_end;
      ++spix, ++cspix) {
    coord = !spix;
    coord = !cspix;
    *spix  = *cspix;
    // *cspix = *spix;  ...is forbidden by the compiler.
  }

  coord(10,10);
  ptr  = &(subimg(coord));
  cptr = &(subimg(coord));
  ptr  = &(subimg[coord]);
  cptr = &(subimg[coord]);
  // ptr  = &(csubimg(coord));  ...is forbidden by the compiler.
  cptr = &(csubimg(coord));
  // ptr  = &(csubimg[coord]);  ...is forbidden by the compiler.
  cptr = &(csubimg[coord]);



  //                          //
  //  The problem with lines  //
  //                          //

  mirage::img::Line<ImageDouble> line;
  mirage::img::ConstLine<ImageDouble> cline;
  mirage::img::Line<ImageDouble>::pixel_type lpix,lpix_end; // const_pixel_type is also available.
  mirage::img::ConstLine<ImageDouble>::const_pixel_type clpix,clpix_end;

  line << img;
  // line << cimg;  ...is forbidden by the compiler.
  
  cline << img;
  cline << cimg;
  
  line(1,2,3);
  cline(1,2,3);

  for(lpix = line.begin(), lpix_end = line.end(), 
        clpix = cline.const_begin(), clpix_end = cline.const_end();
      lpix != lpix_end && clpix != clpix_end;
      ++lpix, ++clpix) {
    coord = !lpix;
    coord = !clpix;
    *lpix  = *clpix;
    // *clpix = *lpix;  ...is forbidden by the compiler.
  }


  lpix  = line.begin();
  clpix = cline.const_begin();
  ptr  = &(*lpix);
  cptr = &(*lpix);
  // ptr  = &(*clpix);  ...is forbidden by the compiler.
  cptr = &(*clpix);


}