Ejemplo n.º 1
0
static void
def_enum (definition * defp)
{
  token tok;
  enumval_list *elist;
  enumval_list **tailp;

  defp->def_kind = DEF_ENUM;
  scan (TOK_IDENT, &tok);
  defp->def_name = tok.str;
  scan (TOK_LBRACE, &tok);
  tailp = &defp->def.en.vals;
  do
    {
      scan (TOK_IDENT, &tok);
      elist = ALLOC (enumval_list);
      elist->name = tok.str;
      elist->assignment = NULL;
      scan3 (TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
      if (tok.kind == TOK_EQUAL)
	{
	  scan_num (&tok);
	  elist->assignment = tok.str;
	  scan2 (TOK_COMMA, TOK_RBRACE, &tok);
	}
      *tailp = elist;
      tailp = &elist->next;
    }
  while (tok.kind != TOK_RBRACE);
  *tailp = NULL;
}
Ejemplo n.º 2
0
bool load_configuration_values(const k3d::filesystem::path& file_path, k3d::double_t& recursion, k3d::double_t& basic_angle, k3d::double_t& thickness)
{
	// Open configuration file
	k3d::filesystem::ifstream file(file_path);
	if(!file.good())
	{
		k3d::log() << error << k3d_file_reference << ": error opening [" << file_path.native_console_string() << "]" << std::endl;
		return 0.0;
	}

	// Get recursion level
	std::string temp;
	return_val_if_fail(ls_line(file, temp), false);
	std::stringstream scan(temp);
	scan >> recursion;

	// Get asic angle
	return_val_if_fail(ls_line(file, temp), false);
	std::stringstream scan2(temp);
	scan2 >> basic_angle;

	// Get thickness
	return_val_if_fail(ls_line(file, temp), false);
	std::stringstream scan3(temp);
	scan3 >> thickness;

	return true;
}
Ejemplo n.º 3
0
static void
def_union(definition *defp)
{
	token tok;
	declaration dec;
	case_list *cases;
	case_list **tailp;

	defp->def_kind = DEF_UNION;
	scan(TOK_IDENT, &tok);
	defp->def_name = tok.str;
	scan(TOK_SWITCH, &tok);
	scan(TOK_LPAREN, &tok);
	get_declaration(&dec, DEF_UNION);
	defp->def.un.enum_decl = dec;
	tailp = &defp->def.un.cases;
	scan(TOK_RPAREN, &tok);
	scan(TOK_LBRACE, &tok);
	scan(TOK_CASE, &tok);
	while (tok.kind == TOK_CASE) {
		scan(TOK_IDENT, &tok);
		cases = ALLOC(case_list);
		cases->case_name = tok.str;
		scan(TOK_COLON, &tok);
		get_declaration(&dec, DEF_UNION);
		cases->case_decl = dec;
		*tailp = cases;
		tailp = &cases->next;
		scan(TOK_SEMICOLON, &tok);
		scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
	}
	*tailp = NULL;
	if (tok.kind == TOK_DEFAULT) {
		scan(TOK_COLON, &tok);
		get_declaration(&dec, DEF_UNION);
		defp->def.un.default_decl = ALLOC(declaration);
		*defp->def.un.default_decl = dec;
		scan(TOK_SEMICOLON, &tok);
		scan(TOK_RBRACE, &tok);
	} else {
		defp->def.un.default_decl = NULL;
	}
}
Ejemplo n.º 4
0
static void
def_union (definition *defp)
{
  token tok;
  declaration dec;
  case_list *cases;
/*  case_list *tcase; */
  case_list **tailp;
#if 0
  int flag;
#endif

  defp->def_kind = DEF_UNION;
  scan (TOK_IDENT, &tok);
  defp->def_name = tok.str;
  scan (TOK_SWITCH, &tok);
  scan (TOK_LPAREN, &tok);
  get_declaration (&dec, DEF_UNION);
  defp->def.un.enum_decl = dec;
  tailp = &defp->def.un.cases;
  scan (TOK_RPAREN, &tok);
  scan (TOK_LBRACE, &tok);
  scan (TOK_CASE, &tok);
  while (tok.kind == TOK_CASE)
    {
      scan2 (TOK_IDENT, TOK_CHARCONST, &tok);
      cases = ALLOC (case_list);
      cases->case_name = tok.str;
      scan (TOK_COLON, &tok);
      /* now peek at next token */
#if 0
      flag = 0;
#endif
      if (peekscan (TOK_CASE, &tok))
	{

	  do
	    {
	      scan2 (TOK_IDENT, TOK_CHARCONST, &tok);
	      cases->contflag = 1;	/* continued case statement */
	      *tailp = cases;
	      tailp = &cases->next;
	      cases = ALLOC (case_list);
	      cases->case_name = tok.str;
	      scan (TOK_COLON, &tok);

	    }
	  while (peekscan (TOK_CASE, &tok));
	}
#if 0
      else if (flag)
	{

	  *tailp = cases;
	  tailp = &cases->next;
	  cases = ALLOC (case_list);
	};
#endif

      get_declaration (&dec, DEF_UNION);
      cases->case_decl = dec;
      cases->contflag = 0;	/* no continued case statement */
      *tailp = cases;
      tailp = &cases->next;
      scan (TOK_SEMICOLON, &tok);

      scan3 (TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
    }
  *tailp = NULL;
  if (tok.kind == TOK_DEFAULT)
    {
      scan (TOK_COLON, &tok);
      get_declaration (&dec, DEF_UNION);
      defp->def.un.default_decl = ALLOC (declaration);
      *defp->def.un.default_decl = dec;
      scan (TOK_SEMICOLON, &tok);
      scan (TOK_RBRACE, &tok);
    }
  else
    {
      defp->def.un.default_decl = NULL;
    }
}
Ejemplo n.º 5
0
/* ********************************************************************** */
void
detectEdgeNodata::generateNodata(AMI_STREAM<elevation_type> &elstr) { 
  nodataQueue = new queue<nodataType>();
  scan3(elstr, nr, nc, nodata, *this); 
  delete nodataQueue;
}
Ejemplo n.º 6
0
int main(int argc, char **argv) {

    unsigned char *pds, *gds;
    FILE *input, *inv, *output;
    int i, iscale;

    float *data, *tmp;
    double shmax, shmin;
    int ndata, nmax, date;

    long int pos_tmp, pos_rh, len_grib;
    int lev, press;
    char *levels[] = {"1000 mb","925 mb","850 mb",
	"700 mb","600 mb","500 mb","400 mb","300 mb"};

    /* preliminaries .. open up all files */

    if (argc != 4) {
	fprintf(stderr, "%s [in gribfile] [inv] [out gribfile]\n", argv[0]);
	exit(8);
    }
    if ((input = fopen(argv[1],"rb")) == NULL) {
        fprintf(stderr,"could not open file: %s\n", argv[1]);
        exit(7);
    }
    if ((inv = fopen(argv[2],"rb")) == NULL) {
        fprintf(stderr,"could not open file: %s\n", argv[2]);
        exit(7);
    }
    if ((output = fopen(argv[3],"wb+")) == NULL) {
        fprintf(stderr,"could not open file: %s\n", argv[3]);
        exit(7);
    }

    nmax = 0;
    tmp = NULL;

    for (lev = 0; lev < sizeof(levels) / sizeof(char *); lev++) {
	rewind(inv);

	/* read the temperature */

	pos_tmp = scan3(inv, 0, "TMP", levels[lev]);
	if (pos_tmp < 0) continue;

	len_grib = rd_grib_rec(input, pos_tmp, &pds, &gds, &data, &ndata);
	if (len_grib <= 0) {
	    fprintf(stderr,"bad record\n");
	    exit(8);
	}
	if (ndata > nmax) {
	    if (tmp != NULL) free(tmp);    
	    nmax = ndata;
	    tmp = malloc(nmax*sizeof (float));
	    if (tmp == NULL) {
		fprintf(stderr,"malloc error\n");
		exit(8);
	    }
	}
	for (i = 0; i < ndata; i++) tmp[i] = data[i];

	/* read for the same date */

	date = PDS_Hour(pds) + 100*PDS_Day(pds) + 10000*PDS_Month(pds) +
		1000000*PDS_Year4(pds);

	/* read RH */

	pos_rh = scan3(inv, date, "RH", levels[lev]);
	if (pos_rh < 0) {
	    rewind(inv);
	    pos_rh = scan3(inv, 0, "RH", levels[lev]);
	}
	printf("%ld %ld\n", pos_tmp, pos_rh);
	len_grib = rd_grib_rec(input, pos_rh, &pds, &gds, &data, &ndata);
	if (len_grib <= 0) {
	    fprintf(stderr,"bad record\n");
	    exit(8);
	}

	/* compute SPFH */
	press = atoi(levels[lev]);
	for (i = 0; i < ndata; i++) {
	    if(!UNDEFINED_VAL(data[i]) && !UNDEFINED_VAL(tmp[i])) 
	        data[i] = spfh(tmp[i], data[i], (float) press);
	}

	/* figure out a good decimal scaling
	 * use what was used in NCEP/NCAR Reanalysis
	 * assume data is all defined
	 */
	shmax = 0;
	shmin = 1e20;
	for (i = 1; i < ndata; i++) {
	    if (!UNDEFINED_VAL(data[i])) {
	        shmin = shmin <= data[i] ? shmin : data[i];
	        shmax = shmax >= data[i] ? shmax : data[i];
	    }
	}
	shmax = shmax - shmin;
	iscale = 0;
	if (shmax != 0.0) {
	    while (shmax < 999.9) {
		iscale++;
		shmax *= 10.0;
	    }
	    while (shmax > 9999.9) {
		iscale--;
		shmax /= 10.0;
	    }
	}

	pds = PDStool(pds,P_param(SPFH),P_dec_scale(iscale), P_end);
	wrt_grib_rec(pds, gds, data, ndata, output);
    }

    fclose(output);
    fclose(inv);
    fclose(input);
    return 0;
}