示例#1
0
文件: sexpr.C 项目: bougyman/sfs
void
gread_string (gread_state *state)
{
  int c = gget ();
  switch (c) {
    case EOF:
      gerror ();
    case '"':
      {
        gstring *string = New gstring (*(state->chars));
        delete state->chars;
        delete state;
        greturn (string);
      }
    case '\\':
      c = gget ();
      switch (c) {
        case EOF:
          gerror ();
        case 'n':
          state->chars->append ('\n');
          ggoto (gread_string, state);
      }
      // else fall through
    default:
      state->chars->append (c);
      ggoto (gread_string, state);
  }
}
示例#2
0
文件: sexpr.C 项目: bougyman/sfs
void
gread_gob (gread_state *ignore)
{
  consume_whitespace ();
  int c = gget ();

  switch (c) {
    case EOF:
      gerror (); // unexpected end of input
    case '(':
      {
      gread_res = NULL;
      gread_state *state = New gread_state;
      state->list.elms = state->list.elmstail = NULL;
      ggoto (gread_list, state);
      }
    case ')':
      gerror (); // unbalanced parentheses
    case '"':
      {
      gread_state *state = New gread_state;
      state->chars = New str;
      ggoto (gread_string, state);
      }
    default:
      if (isdigit (c)) {
        gread_state *state = New gread_state;
        state->chars = New str;
        state->chars->append (c);
        ggoto (gread_integer, state);
      }
      else if (issymbolchar (c)) {
        gread_state *state = New gread_state;
        state->chars = New str;
        state->chars->append (tolower (c));
        ggoto (gread_symbol, state);
      }
      else
        gerror (); // unexpected character
  }
}
示例#3
0
文件: thread_pool.c 项目: Gurut/gross
void
send_result(edict_t *edict, void *result)
{
	int ret;
	poolresult_message_t message;

	message.result = result;

	ret = put_msg(edict->resultmq, &message, sizeof(message));
	if (ret < 0)
		gerror("send_result");
}
示例#4
0
SEXP gribr_is_multi_message(SEXP fileHandle) {
  int err;
  int n_on;
  int n_off;
  codes_handle *h = NULL;
  FILE *file = NULL;

  file = R_ExternalPtrAddr(fileHandle);

  err = codes_count_in_file(DEFAULT_CONTEXT, file, &n_off);
  if (err) {
    gerror("unable to count grib messages", err);
  }

  codes_grib_multi_support_on(DEFAULT_CONTEXT);

  n_on = 0;
  while((h = codes_grib_handle_new_from_file(DEFAULT_CONTEXT, file, &err))) {
    n_on++;
    codes_handle_delete(h);
  }
  if (err) {
    gerror("unable to count grib messages", err);
  }

  /* This rewind is important as neglecting to do so will
   * leave the file handle in a unusable state and cause
   * R to crash */
  if (fseek(file, 0, SEEK_SET)) {
    error("gribr: unable to rewind file");
  }

  codes_grib_multi_support_off(DEFAULT_CONTEXT);

  if (n_on != n_off) {
    return ScalarLogical(TRUE);
  }

  return ScalarLogical(FALSE);
}
示例#5
0
  void
grimlyreapvm ()
{
  bool isreapable();

        statusofalloc("statalloc");
        for (; grimreaper; grimreaper = (vmthingtype *)grimreaper->vmdocument.nextvm) {

                if (isreapable ()) {
                        reap ();
                        return;
                 }
                ++grimreaper->vmdocument.age;
        }
        gerror ("Nothing to reap.\n");
}
示例#6
0
文件: utils.c 项目: Gurut/gross
/* 
 * writet	- write a terminated string to a descriptor
 */
ssize_t
writet(int fd, const char *line, const char *terminator)
{
	char *str;
	size_t linelen;
	size_t len;

	linelen = strlen(line) + strlen(terminator) + 1;
	str = malloc(linelen);
	if (!str) {
		gerror("malloc");
		return -1;
	}
	snprintf(str, linelen, "%s%s", line, terminator);
	len = writen(fd, str, linelen - 1);
	Free(str);
	return len;
}
示例#7
0
文件: sexpr.C 项目: bougyman/sfs
void
gread_list (gread_state *state)
{
  if (gread_res) {
    gpair *newpair = New gpair (gread_res, bottom);
    gpair *head = state->list.elms;
    gpair *tail = state->list.elmstail;
    if (tail) {
      tail->cdr = newpair;
      tail = newpair;
    }
    else
      head = tail = newpair;
    state->list.elms = head;
    state->list.elmstail = tail;
  }

  consume_whitespace ();
  int c = gget ();
  switch (c) {
    case EOF:
      gerror ();
    case ')':
      {
        gpair *elms = state->list.elms;
        delete state;
        if (elms)
          greturn (elms);
        else
          greturn (bottom);
      }
    default:
      gunget (c);
      gpush (gread_list, state);
      ggoto (gread_gob, NULL);
  }
}
示例#8
0
/* global definitions and init calls go here */
$GLOBAL

/* main program */
int main (int argc, char **argv)
{
  int c, i, got, total, rectype, start, stop, skip, args;
  int del=0;
  char *s;
  Fun fun, ofun;
  Row rowbuf, rowptr;
  Row cur, prev, next;
  $AUTO
  
  /* local definitions, followed by init calls go here */
  $LOCAL

  /* exit on gio errors */
  setgerror(1);

  /* avoid shared library problems by using "process" type for filtering */
  putenv("FILTER_PTYPE=process");

  /* process switch arguments */
  while ((c = getopt(argc, argv, "d")) != -1){
    switch(c){
    case 'd':
      del = 1;
      break;
    }
  }
  /* check for required arguments */
  args = argc - optind;
  /* make sure we have minimal arguments */
  if( args < $ARGS ){
    if( $ARGS == 1 )
      fprintf(stderr,
      "usage: [expr] | funcalc [-e expr] [-f file] iname\n");
    else
      fprintf(stderr,
      "usage: [expr] | funcalc [-e expr] [-f file] iname oname [cols]\n");
    goto error;
  }

  /* set rectype: determine whether we need prev,next records */
  rectype=$RECTYPE;

  /* get maxrow,if user-specified */
  if( (s=(char *)getenv("FUN_MAXROW")) != NULL )
    maxrow = atoi(s);
  /* make sure max row is large enough to handle prev, next */
  if( rectype & (REC_PREV|REC_NEXT) ) maxrow = MAX(3,maxrow);

  /* open input file */
  if( !(fun = FunOpen(argv[optind+0], "rc", NULL)) ){
      gerror(stderr, "could not FunOpen input file: %s\n", argv[optind+0]);
      goto error;
  }

  /* open the output FITS image, inheriting params from input */
  if( $ARGS > 1 ){
    if( !(ofun = FunOpen(argv[optind+1], "w", fun)) ){
      gerror(stderr, "could not FunOpen output file: %s\n", argv[optind+1]);
      goto error;
    }
  }

  /* select columns */
  FunColumnSelect(fun, sizeof(RowRec), "merge=replace", 
		  $SELECT
		  NULL);

  /* activate specified columns -- these will be written to the output file */
  if( args >= 3 )
    FunColumnActivate(fun, argv[optind+2], NULL);

  /* allocate space for rowbuf -- we will manage this buffer ourselves */
  rowbuf = (Row)calloc(maxrow, sizeof(RowRec));

  /*  no record read yet */
  total = 0;

  /* any user-defined calls before we enter the row loop go here */
  $BEFORE

  /* main loop -- get rows and process */
  while( 1 ){
    /* need prev record */
    if( rectype & REC_PREV ){
      /* no records yet: read new batch of records into start of rowbuf */
      if( total == 0 ){
        rowptr = rowbuf;
      }
      /* we have read records: move last record from last batch into first
	 new record and read new records after that */
      else{
        /* if we are accessing next, we did not actually process final record,
           therefore we do it now */
        if( rectype & REC_NEXT ){
          memcpy(rowbuf, rowbuf+(got-2), sizeof(RowRec)*2);
          rowptr = rowbuf+2;
        }
        /* not accessing next, so we just move last record processed */
        else{
          memcpy(rowbuf, rowbuf+(got-1), sizeof(RowRec));
          rowptr = rowbuf+1;
        }
      }
      /* start at 2nd record so as to have a valid prev */
      start = 1;
    }
    /* processing that does not require prev */
    else{
      rowptr = rowbuf;
      start = 0;
    }

    /* adjust maxrow to account for handling of prev record */
    skip = (rowptr - rowbuf)/sizeof(RowRec);

    /* read new rows */
    if( !FunTableRowGet(fun, rowptr, maxrow-skip, NULL, &got) )
      break;

    /* if we need access to next record, don't process the last one we read */
    if( rectype & REC_NEXT ){
      stop = got - 1;
    }
    /* processing that does not require acces to next, process as cur */
    else{
      stop = got;
    }

    /* process all rows */
    for(i=start; i<stop; i++){
      /* set up pointer to current row */
      cur = rowbuf+i;
      /* set up pointer to prev and next as needed */
      if( rectype & REC_PREV ) prev = rowbuf+(i-1);
      if( rectype & REC_NEXT ) next = rowbuf+(i+1);
      /* execute the expression */
      $EXPR
      /* write out this row with the new column */
      if( $ARGS > 1 )
        FunTableRowPut(ofun, (char *)cur, 1, i, NULL);
    }
    total += got;
  }

  /* any user-defined calls after we finish the row loop go here */
  $AFTER

  /* free row data */
  if( rowbuf ) free(rowbuf);

  /* clean up -- close output before input to perform flush automatically */
  if( $ARGS > 1 )
    FunClose(ofun);
  FunClose(fun);

  /* delete program if necessary */
  if( del ) unlink(argv[0]);
  return(0);

error:
  /* delete program if necessary */
  if( del ) unlink(argv[0]);
  return(1);
}
示例#9
0
文件: bloommgr.c 项目: Gurut/gross
static void *
bloommgr(void *arg)
{
	update_message_t message;
	sha_256_t digest;
	int ret;
	size_t size;
	startup_sync_t ss;

	ctx->filter = build_bloom_ring(ctx->config.num_bufs, ctx->config.filter_size);

	logstr(GLOG_INFO, "bloommgr starting...");

	sem_post(ctx->locks.sync_guard);

	/* pseudo-loop */
	for (;;) {
		size = get_msg(ctx->update_q, &message, MSGSZ);
		if (size < 0) {
			gerror("get_msg bloommgr");
			continue;
		}
		switch (message.mtype) {
		case UPDATE:
			logstr(GLOG_DEBUG, "received update command");
			memcpy(&digest, message.mtext, sizeof(sha_256_t));
			ACTIVATE_BLOOM_GUARD();
			insert_digest_bloom_ring_queue(ctx->filter, digest);
			RELEASE_BLOOM_GUARD();
			/* debug_print_digest(digest, TRUE); */
			break;
		case UPDATE_OPER:
			/* logstr(GLOG_DEBUG, "received update oper command"); */
			memcpy(&digest, message.mtext, sizeof(sha_256_t));
			ACTIVATE_BLOOM_GUARD();
			insert_digest_bloom_ring_queue(ctx->filter, digest);
			RELEASE_BLOOM_GUARD();
			break;
		case ABSOLUTE_UPDATE:
			memcpy(&ss, message.mtext, sizeof(ss));
			/* logstr(GLOG_INSANE, "Absolute update, buffer %d, index %d", ss.buffer, ss.index); */
			ACTIVATE_BLOOM_GUARD();
			insert_absolute_bloom_ring_queue(ctx->filter, ss.filter, FILTER_SIZE,
			    ss.index, ss.buffer);
			RELEASE_BLOOM_GUARD();
			break;
		case ROTATE:
			logstr(GLOG_DEBUG, "received rotate command");
			/* debug_print_ring_queue(ctx->filter, TRUE); */
			create_thread(NULL, DETACH, &rotate, NULL);
			break;
		case SYNC_AGGREGATE:
			sync_aggregate(ctx->filter);
			ret = sem_post(ctx->locks.sync_guard);
			if (ret)
				daemon_fatal("pthread_mutex_unlock");
			break;
		default:
			logstr(GLOG_ERROR, "Unknown message type in update queue");
			break;
		}
	}

	/* NOTREACHED */ 
	/* release_bloom_ring_queue(ctx->filter);*/
}
示例#10
0
int main (int argc, char **argv)
{
  int i, got;
  int maxrow=MAXROW;
  double x=0.5;
  char *tmode;
  char *s;
  Fun fun, fun2;
  Ev ebuf, ev;

  /* exit on gio errors */
  setgerror(2);

  /* make sure we have minimal arguments */
  if( argc < 3 )
    gerror(stderr, "usage: %s iname oname [columns]\n", argv[0]);

  /* get maxrow,if user-specified */
  if( (s=(char *)getenv("FUN_MAXROW")) != NULL )
    maxrow = atoi(s);

  /* open input file */
  if( !(fun = FunOpen(argv[1], "rc", NULL)) )
    gerror(stderr, "could not FunOpen input file: %s\n", argv[1]);

  /* open the output FITS image, inheriting params from input */
  if( !(fun2 = FunOpen(argv[2], "w", fun)) )
    gerror(stderr, "could not FunOpen output file: %s\n", argv[2]);

  /* if we have "time2", read it, else create it */
  if( FunColumnLookup(fun, "tinc", 0, NULL, NULL, NULL, NULL, NULL, NULL) )
    tmode = "rw";
  else
    tmode = "w";

  FunColumnSelect(fun, sizeof(EvRec), "merge=replace",
		  "time",     "D", 	"r",    FUN_OFFSET(Ev, time),
		  "ntime",    "D", 	"rw",    FUN_OFFSET(Ev, ntime),
		  "tinc",     "D",      tmode,   FUN_OFFSET(Ev, tinc),
		  NULL);

  /* activate specified columns -- these will be written to the output file */
  if( argc >= 4 )
    FunColumnActivate(fun, argv[3], NULL);

  /* get rows -- let routine allocate the row array */
  while( (ebuf = (Ev)FunTableRowGet(fun, NULL, maxrow, NULL, &got)) ){
    /* process all rows */
    for(i=0; i<got; i++){
      /* point to the i'th row */
      ev = ebuf+i;
      ev->tinc += (i*sqrt(cos(x)*cos(x) + sin(x)*sin(x)));
      ev->ntime = ev->time + ev->tinc;
      /* write out row with the new columns */
      FunTableRowPut(fun2, (char *)ev, 1, i, NULL);
    }
    /* free row data */
    if( ebuf ) free(ebuf);
  }

  /* clean up -- close output before input to perform flush automatically */
  FunClose(fun2);
  FunClose(fun);
  return(0);
}
示例#11
0
int FunInfoGet(Fun fun, ...) 
{
  int type;
  int got;
  char *addr;
  Fun ofun;
  va_list args;
  va_start(args, fun);
#else
int FunInfoGet(va_alist) va_dcl
{
  Fun fun;
  int type;
  int got;
  char *addr;
  Fun ofun;
  va_list args;
  va_start(args);
  fun  = va_arg(args, Fun);
#endif
  /* just in case ... */
  if( !_FunValid(fun) ){
    gerror(stderr, "invalid funtools handle\n");
    return 0;
  }
  /* if we delayed the open before, we have to open now */
  if( !fun->header && strchr(fun->mode, 'r') )
    _FunFITSOpen(fun, fun->fname, "r");

  for(got=0; (type=va_arg(args, int)); got++){
    addr=va_arg(args, void *);
    ofun = fun;
    if( fun->current ) fun = fun->current;
    switch(type){
    case FUN_FNAME:
      if( addr ) memcpy(addr, &fun->fname, sizeof(fun->fname));
      break;
    case FUN_GIO:
      if( addr ) memcpy(addr, &fun->gio, sizeof(fun->gio));
      break;
    case FUN_HEADER:
      if( addr ) memcpy(addr, &fun->header, sizeof(fun->header));
      break;
    case FUN_THEADER:
      if( addr ) memcpy(addr, &fun->theader, sizeof(fun->theader));
      break;
    case FUN_WCS:
      if( addr ) memcpy(addr, &fun->wcs, sizeof(fun->wcs));
      break;
    case FUN_WCS0:
      if( addr ) memcpy(addr, &fun->wcs0, sizeof(fun->wcs0));
      break;
    case FUN_TYPE:
      if( addr ) memcpy(addr, &fun->type, sizeof(fun->type));
      break;
    case FUN_BITPIX:
      if( addr ) memcpy(addr, &fun->bitpix, sizeof(fun->bitpix));
      break;
    case FUN_MIN1:
      if( addr ) memcpy(addr, &fun->min1, sizeof(fun->min1));
      break;
    case FUN_MAX1:
      if( addr ) memcpy(addr, &fun->max1, sizeof(fun->max1));
      break;
    case FUN_MIN2:
      if( addr ) memcpy(addr, &fun->min2, sizeof(fun->min2));
      break;
    case FUN_MAX2:
      if( addr ) memcpy(addr, &fun->max2, sizeof(fun->max2));
      break;
    case FUN_DIM1:
      if( addr ) memcpy(addr, &fun->dim1, sizeof(fun->dim1));
      break;
    case FUN_DIM2:
      if( addr ) memcpy(addr, &fun->dim2, sizeof(fun->dim2));
      break;
    case FUN_DIMS:
      if( addr ) memcpy(addr, &fun->dims, sizeof(fun->dims));
      break;
    case FUN_ENDIAN:
      if( addr ) memcpy(addr, &fun->endian, sizeof(fun->endian));
      break;
    case FUN_FILTER:
      if( addr ) memcpy(addr, &fun->filter, sizeof(fun->filter));
      break;
    case FUN_OPS:
      if( addr ) memcpy(addr, &fun->ops, sizeof(fun->ops));
      break;
      /* image information */
    case FUN_DTYPE:
      if( addr ) memcpy(addr, &fun->dtype, sizeof(fun->dtype));
      break;
    case FUN_DLEN:
      if( addr ) memcpy(addr, &fun->dlen, sizeof(fun->dlen));
      break;
    case FUN_DPAD:
      if( addr ) memcpy(addr, &fun->dpad, sizeof(fun->dpad));
      break;
    case FUN_DOBLANK:
      if( addr ) memcpy(addr, &fun->doblank, sizeof(fun->doblank));
      break;
    case FUN_BLANK:
      if( addr ) memcpy(addr, &fun->blank, sizeof(fun->blank));
      break;
    case FUN_SCALED:
      if( addr ) memcpy(addr, &fun->scaled, sizeof(fun->scaled));
      break;
    case FUN_BSCALE:
      if( addr ) memcpy(addr, &fun->bscale, sizeof(fun->bscale));
      break;
    case FUN_BZERO:
      if( addr ) memcpy(addr, &fun->bzero, sizeof(fun->bzero));
      break;
      /* table information */
    case FUN_BINCOLS:
      if( addr ) memcpy(addr, &fun->bincols, sizeof(fun->bincols));
      break;
    case FUN_BINOFFS:
      if( addr ) memcpy(addr, fun->bin, sizeof(fun->bin));
      break;
    case FUN_ROWSIZE:
      if( addr ) memcpy(addr, &fun->rowsize, sizeof(fun->rowsize));
      break;
    case FUN_NROWS:
      if( addr ) memcpy(addr, &fun->total, sizeof(fun->total));
      break;
    case FUN_ROW:
      if( addr ) memcpy(addr, &fun->io, sizeof(fun->io));
      break;
    case FUN_OVERFLOW:
      if( addr ) memcpy(addr, &fun->overflow, sizeof(fun->overflow));
      break;
      /* array information */
    case FUN_SKIP:
      if( addr ) memcpy(addr, &fun->skip, sizeof(fun->skip));
      break;
      /* section information */
    case FUN_IFUN:
    case FUN_IFUN0:
      if( addr ) memcpy(addr, &fun->ifun, sizeof(fun->ifun));
      break;
    case FUN_BFUN:
      if( addr ) memcpy(addr, fun->bfun, sizeof(fun->bfun));
      break; 
   case FUN_SECT_X0:
      if( addr ) memcpy(addr, &fun->x0, sizeof(fun->x0));
      break;
    case FUN_SECT_X1:
      if( addr ) memcpy(addr, &fun->x1, sizeof(fun->x1));
      break;
    case FUN_SECT_Y0:
      if( addr ) memcpy(addr, &fun->y0, sizeof(fun->y0));
      break;
    case FUN_SECT_Y1:
      if( addr ) memcpy(addr, &fun->y1, sizeof(fun->y1));
      break;
    case FUN_SECT_BLOCK:
      if( addr ) memcpy(addr, &fun->block, sizeof(fun->block));
      break;
    case FUN_SECT_BTYPE:
      if( addr ) memcpy(addr, &fun->btype, sizeof(fun->btype));
      break;
    case FUN_SECT_DIM1:
      if( addr ) memcpy(addr, &fun->odim1, sizeof(fun->odim1));
      break;
    case FUN_SECT_DIM2:
      if( addr ) memcpy(addr, &fun->odim2, sizeof(fun->odim2));
      break;
    case FUN_SECT_DIMS:
      if( addr ) memcpy(addr, &fun->odims, sizeof(fun->odims));
      break;
    case FUN_SECT_BITPIX:
      if( addr ) memcpy(addr, &fun->obitpix, sizeof(fun->obitpix));
      break;
    case FUN_SECT_DTYPE:
      if( addr ) memcpy(addr, &fun->odtype, sizeof(fun->odtype));
      break;
      /* convenient ways to get to data in binned images and tables */
    case FUN_RAWBUF:
      if( addr ) memcpy(addr, &fun->rawbuf, sizeof(fun->rawbuf));
      break;
    case FUN_RAWSIZE:
      if( addr ) memcpy(addr, &fun->rawsize, sizeof(fun->rawsize));
      break;
      /* specified columns */
    case FUN_NCOL:
      if( addr ) memcpy(addr, &fun->ncol, sizeof(fun->ncol));
      break;
    case FUN_COLS:
      if( addr ) memcpy(addr, &fun->cols, sizeof(fun->cols));
      break;
    case FUN_LTYPE:
      if( addr ) memcpy(addr, &ofun->ltype, sizeof(ofun->ltype));
      break;
    case FUN_LMEM:
      if( addr ) memcpy(addr, &ofun->lmem, sizeof(ofun->lmem));
      break;
    case FUN_HEAD:
      if( addr ) memcpy(addr, &ofun->head, sizeof(ofun->head));
      break;
    case FUN_CURRENT:
      if( addr ) memcpy(addr, &ofun->current, sizeof(ofun->current));
      break;
    case FUN_NEXT:
      if( addr ) memcpy(addr, &ofun->next, sizeof(ofun->next));
      break;
    case FUN_RAWPARAM:
      if( addr ) memcpy(addr, &fun->doraw, sizeof(fun->doraw));
      break;
    case FUN_PRIMARYHEADER:
      if( addr ) memcpy(addr, &fun->doprim, sizeof(fun->doprim));
      break;
    case FUN_VCOLS:
      if( addr ) memcpy(addr, &fun->vcols, sizeof(fun->vcols));
      break;
    case FUN_VFMT:
      if( addr ) memcpy(addr, &fun->vfmt, sizeof(fun->vfmt));
      break;
    default:
      gerror(stderr,
	     "invalid info parameter passed to FunInfoGet: %d\n", type);
      return(got);
    }
  }
  return got;
}

/*
 *
 * FunInfoPut -- set information in the funtools struct
 *
 */
#ifdef __STDC__
int FunInfoPut(Fun fun, ...) 
{
  Fun ref;
  Fun oifun;
  Fun ofun;
  int i;
  int type;
  int got;
  char *addr;
  va_list args;
  va_start(args, fun);
#else
int FunInfoPut(va_alist) va_dcl
{
  Fun fun;
  Fun ref;
  Fun oifun;
  Fun ofun;
  int i;
  int type;
  int got;
  char *addr;
  va_list args;
  va_start(args);
  fun  = va_arg(args, Fun);
#endif
  /* just in case ... */
  if( !_FunValid(fun) ){
    gerror(stderr, "invalid funtools handle\n");
    return 0;
  }
  /* if we delayed the open before, we have to open now */
  if( !fun->header && strchr(fun->mode, 'r') )
    _FunFITSOpen(fun, fun->fname, "r");

  ofun = fun;
  if( fun->current ) fun = fun->current;
  for(got=0; (type=va_arg(args, int)); got++){
    addr=va_arg(args, void *);
    switch(type){
    case FUN_FNAME:
      if( addr ){
	if( fun->fname ) xfree(fun->fname);
	fun->fname = xstrdup(addr);
      }
      break;
    case FUN_GIO:
      if( addr ) memcpy(&fun->gio, addr, sizeof(fun->gio));
      break;
    case FUN_HEADER:
      if( addr ) memcpy(&fun->header, addr, sizeof(fun->header));
      break;
    case FUN_THEADER:
      if( addr ) memcpy(&fun->theader, addr, sizeof(fun->theader));
      break;
    case FUN_WCS:
      if( addr ) memcpy(&fun->wcs, addr, sizeof(fun->wcs));
      break;
    case FUN_WCS0:
      if( addr ) memcpy(&fun->wcs0, addr, sizeof(fun->wcs0));
      break;
    case FUN_TYPE:
      if( addr ) memcpy(&fun->type, addr, sizeof(fun->type));
      break;
    case FUN_BITPIX:
      if( addr ) memcpy(&fun->bitpix, addr, sizeof(fun->bitpix));
      break;
    case FUN_MIN1:
      if( addr ) memcpy(&fun->min1, addr, sizeof(fun->min1));
      break;
    case FUN_MAX1:
      if( addr ) memcpy(&fun->max1, addr, sizeof(fun->max1));
      break;
    case FUN_MIN2:
      if( addr ) memcpy(&fun->min2, addr, sizeof(fun->min2));
      break;
    case FUN_MAX2:
      if( addr ) memcpy(&fun->max2, addr, sizeof(fun->max2));
      break;
    case FUN_DIM1:
      if( addr ) memcpy(&fun->dim1, addr, sizeof(fun->dim1));
      break;
    case FUN_DIM2:
      if( addr ) memcpy(&fun->dim2, addr, sizeof(fun->dim2));
      break;
    case FUN_DIMS:
      if( addr ) memcpy(&fun->dims, addr, sizeof(fun->dims));
      break;
    case FUN_ENDIAN:
      if( addr ) memcpy(&fun->endian, addr, sizeof(fun->endian));
      break;
    case FUN_OPS:
      if( addr ) memcpy(&fun->ops, addr, sizeof(fun->ops));
      break;
    case FUN_FILTER:
      if( addr ) memcpy(&fun->filter, addr, sizeof(fun->filter));
      break;
      /* image information */
    case FUN_DTYPE:
      if( addr ) memcpy(&fun->dtype, addr, sizeof(fun->dtype));
      break;
    case FUN_DLEN:
      if( addr ) memcpy(&fun->dlen, addr, sizeof(fun->dlen));
      break;
    case FUN_DPAD:
      if( addr ) memcpy(&fun->dpad, addr, sizeof(fun->dpad));
      break;
    case FUN_DOBLANK:
      if( addr ) memcpy(&fun->doblank, addr, sizeof(fun->doblank));
      break;
    case FUN_BLANK:
      if( addr ) memcpy(&fun->blank, addr, sizeof(fun->blank));
      break;
    case FUN_SCALED:
      if( addr ) memcpy(&fun->scaled, addr, sizeof(fun->scaled));
      break;
    case FUN_BSCALE:
      if( addr ) memcpy(&fun->bscale, addr, sizeof(fun->bscale));
      break;
    case FUN_BZERO:
      if( addr ) memcpy(&fun->bzero, addr, sizeof(fun->bzero));
      break;
      /* table information */
    case FUN_BINCOLS:
      if( addr ) memcpy(&fun->bincols, addr, sizeof(fun->bincols));
      break;
    case FUN_BINOFFS:
      if( addr ) memcpy(fun->bin, addr, sizeof(fun->bin));
      break;
    case FUN_ROWSIZE:
      if( addr ) memcpy(&fun->rowsize, addr, sizeof(fun->rowsize));
      break;
    case FUN_NROWS:
      if( addr ) memcpy(&fun->total, addr, sizeof(fun->total));
      break;
    case FUN_OVERFLOW:
      if( addr ) memcpy(&fun->overflow, addr, sizeof(fun->overflow));
      break;
      /* array information */
    case FUN_SKIP:
      if( addr ) memcpy(&fun->skip, addr, sizeof(fun->skip));
      break;
      /* section information */
    case FUN_IFUN:
      if( addr ){
	ref = *(Fun *)addr;
	if( _FunValid(ref) ){
	  /* first, remove old ifun from the backlink list */
	  if( (oifun = fun->ifun) != NULL ){
	    for(i=0; i<FUN_MAXBFUN; i++){
	      if( oifun->bfun[i] == fun ){
		oifun->bfun[i] = NULL;
		break;
	      }
	    }
	  }
	  /* set new reference handle */
	  fun->ifun = ref;
	  /* enter this handle in the backlink list of the reference file */
	  for(i=0; i<FUN_MAXBFUN; i++){
	    if( !fun->ifun->bfun[i] ){
	      fun->ifun->bfun[i] = fun;
	      break;
	    }
	  }
	  /* free old columns */
	  _FunColumnFree(fun);
	  /* new ref handle means reset the ops for this funtools struct */
	  fun->ops = 0;
	  fun->bytes = 0;
	}
      }
      /* reset the fun handle */
      else
	fun->ifun = NULL;
      break;
    /* same as FUN_IFUN above, but don't reset I/O or columns */
    case FUN_IFUN0:
      if( addr ){
	ref = *(Fun *)addr;
	if( _FunValid(ref) ){
	  /* first, remove old ifun from the backlink list */
	  if( (oifun = fun->ifun) != NULL ){
	    for(i=0; i<FUN_MAXBFUN; i++){
	      if( oifun->bfun[i] == fun ){
		oifun->bfun[i] = NULL;
		break;
	      }
	    }
	  }
	  /* set new reference handle */
	  fun->ifun = ref;
	  /* enter this handle in the backlink list of the reference file */
	  for(i=0; i<FUN_MAXBFUN; i++){
	    if( !fun->ifun->bfun[i] ){
	      fun->ifun->bfun[i] = fun;
	      break;
	    }
	  }
	}
      }
      /* reset the fun handle */
      else
	fun->ifun = NULL;
      break;
    case FUN_BFUN:
      if( addr ) memcpy(fun->bfun, addr, sizeof(fun->bfun));
      break; 
    case FUN_SECT_X0:
      if( addr ) memcpy(&fun->x0, addr, sizeof(fun->x0));
      break;
    case FUN_SECT_X1:
      if( addr ) memcpy(&fun->x1, addr, sizeof(fun->x1));
      break;
    case FUN_SECT_Y0:
      if( addr ) memcpy(&fun->y0, addr, sizeof(fun->y0));
      break;
    case FUN_SECT_Y1:
      if( addr ) memcpy(&fun->y1, addr, sizeof(fun->y1));
      break;
    case FUN_SECT_BLOCK:
      if( addr ) memcpy(&fun->block, addr, sizeof(fun->block));
      break;
    case FUN_SECT_BTYPE:
      if( addr ) memcpy(&fun->btype, addr, sizeof(fun->btype));
      break;
    case FUN_SECT_DIM1:
      if( addr ) memcpy(&fun->odim1, addr, sizeof(fun->odim1));
      break;
    case FUN_SECT_DIM2:
      if( addr ) memcpy(&fun->odim2, addr, sizeof(fun->odim2));
      break;
    case FUN_SECT_DIMS:
      if( addr ) memcpy(&fun->odims, addr, sizeof(fun->odims));
      break;
    case FUN_SECT_BITPIX:
      if( addr ) memcpy(&fun->obitpix, addr, sizeof(fun->obitpix));
      break;
    case FUN_SECT_DTYPE:
      if( addr ) memcpy(&fun->odtype, addr, sizeof(fun->odtype));
      break;
      /* convenient ways to get to data in binned images and tables */
    case FUN_RAWBUF:
      if( addr ) memcpy(&fun->rawbuf, addr, sizeof(fun->rawbuf));
      break;
    case FUN_RAWSIZE:
      if( addr ) memcpy(&fun->rawsize, addr, sizeof(fun->rawsize));
      break;
      /* specified columns */
    case FUN_NCOL:
      if( addr ) memcpy(&fun->ncol, addr, sizeof(fun->ncol));
      break;
    case FUN_COLS:
      if( addr ) memcpy(&fun->cols, addr, sizeof(fun->cols));
      break;
    case FUN_LTYPE:
      if( addr ) memcpy(&ofun->ltype, addr, sizeof(ofun->ltype));
      break;
    case FUN_LMEM:
      if( addr ) memcpy(&ofun->lmem, addr, sizeof(ofun->lmem));
      break;
    case FUN_HEAD:
      if( addr ) memcpy(&ofun->head, addr, sizeof(ofun->head));
      break;
    case FUN_CURRENT:
      if( addr ) memcpy(&ofun->current, addr, sizeof(ofun->current));
      break;
    case FUN_NEXT:
      if( addr ) memcpy(&ofun->next, addr, sizeof(ofun->next));
      break;
    case FUN_RAWPARAM:
      if( addr ) memcpy(&fun->doraw, addr, sizeof(fun->doraw));
      break;
    case FUN_PRIMARYHEADER:
      if( addr ) memcpy(&fun->doprim, addr, sizeof(fun->doprim));
      break;
    case FUN_VCOLS:
      if( addr ){
	if( fun->vcols ) xfree(fun->vcols);
	fun->vcols = xstrdup(addr);
      }
    case FUN_VFMT:
      if( addr ){
	if( fun->vfmt ) xfree(fun->vfmt);
	fun->vfmt = xstrdup(addr);
      }
      break;
    default:
      gerror(stderr,
	     "invalid info parameter passed to FunInfoPut: %d\n", type);
      return(got);
    }
  }
  return got;
}
示例#12
0
int
client_postfix(int argc, char **argv)
{
	int fd;
	struct sockaddr_in gserv;
	char mbuf[MAXLINELEN * 4];
	char line[MAXLINELEN];
	size_t linelen;
	int opt = 1;
	int counter = 0;
	int match = 0;
	int cmatch = 0;
	int runs = 1;
	char *sender, *recipient, *caddr, *helo;

#if RANDOM
	srand(time(NULL));
#endif

	if (argc != 9 && argc != 7 && argc != 6) {
		fprintf(stderr,
		    "usage: gclient postfix sender recipient ip_address helo [runs] [host port]\n");
		return 1;
	}

	sender = argv[2];
	recipient = argv[3];
	caddr = argv[4];
	helo = argv[5];

	fd = socket(AF_INET, SOCK_STREAM, 0);

	memset(&gserv, 0, sizeof(gserv));
	gserv.sin_family = AF_INET;

	setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));

	if (argc == 9) {
		inet_pton(AF_INET, argv[7], &gserv.sin_addr);
		gserv.sin_port = htons(atoi(argv[8]));
	} else {
		inet_pton(AF_INET, "127.0.0.1", &gserv.sin_addr);
		gserv.sin_port = htons(GROSSPORT);
	}

	if (connect(fd, (struct sockaddr *)&gserv, sizeof(gserv))) {
		gerror("connect");
		return 2;
	}

	if (argc > 6)
		runs = atoi(argv[6]);

	while (counter < runs) {
		counter++;
		snprintf(mbuf, MAXLINELEN * 4,
#if RANDOM
		    "sender=%d\nrecipient=%d\nclient_address=%d\nhelo_name=%d\n\n",
		    random(), random(), random(), random());
#else
		    "sender=%s\nrecipient=%s\nclient_address=%s\nhelo_name=%s\n\n",
		    sender, recipient, caddr, helo);
#endif /* RANDOM */

		writen(fd, mbuf, strlen(mbuf));

		do {
			linelen = readline(fd, line, MAXLINELEN);
			if (linelen < 0) {
				gerror("readline");
				return 2;
			}

			if (strlen(line) > 0)
				printf("%s\n", line);

			if (line[0] && line[8] == 'u') {
				match++;
				cmatch++;
			}

		} while (strlen(line) > 0);


		if (counter % 10000 == 0) {
			printf("%d, %d, %f\n", counter, cmatch, ((double)match) / 10000);
			fflush(stdout);
			match = 0;
		}
	}
	close(fd);

	return 0;
}
示例#13
0
int main(int argc, char **argv)
{
  int c;
  int args;
  int offscl;
  int dim1, dim2;
  int ix, iy;
  int offset;
  int debug=0;
  int dowcs=1;
  int idx=0;
  char tbuf[SZ_LINE];
  double dval1, dval2;
  double dx, dy;
  double *dbuf;
  struct WorldCoor *wcs;
  Fun fun;

  /* process switch arguments */
  while( (c = getopt(argc, argv, "d")) != -1){
    switch(c){
    case 'd':
      debug = 1;
      break;
    case 'i':
      dowcs = 0;
      break;
    }
  }

  /* check for required arguments */
  args = argc - optind;
  if( args < 1 ){
    fprintf(stderr, "usage: %s iname -d -i\n", argv[0]);
    fprintf(stderr, "\n");
    fprintf(stderr, "where:\n");
    fprintf(stderr, "  -d\tprint out input and output position values\n");
    fprintf(stderr, "  -i\tinput values are image x,y (not ra,dec in deg)\n");
    fprintf(stderr, "\n");
    exit(1);
  }

  /* exit on gio errors */
  setgerror(2);

  /* open the input FITS file */
  if( !(fun = FunOpen(argv[optind], "r", NULL)) )
    gerror(stderr, "could not FunOpen input file: %s\n", argv[optind]);

  /* extract and bin the data section into a double float image buffer */
  if( !(dbuf = FunImageGet(fun, NULL, "bitpix=-64")) )
    gerror(stderr, "could not FunImageGet: %s\n", argv[1]);

  /* get required information from funtools structure */
  FunInfoGet(fun,
	     FUN_SECT_DIM1,	&dim1,
	     FUN_SECT_DIM2,	&dim2,
	     FUN_WCS, 		&wcs,
	     0);

  /* for each line in the contour file ... */
  while( fgets(tbuf, SZ_LINE, stdin) ){
    /* ignore comments */
    if( *tbuf == '#' )
      continue;
    /* blank lines means reset counter */
    if( *tbuf == '\n' ){
      fprintf(stdout, "\n");
      idx = 0;
      continue;
    }
    /* input contour values: ra, dec in degrees (or image coords if -i) */
    if(sscanf(tbuf, "%lf %lf", &dval1, &dval2) != 2){
      gerror(stderr, "invalid line in contour file: %s\n", tbuf);
    }
    /* convert input ra, dec to image x, y */
    if( dowcs ){
      wcs2pix(wcs, dval1, dval2, &dx, &dy, &offscl);
      /* make sure we are not off scale */
      if( offscl ){
	fprintf(stderr, "warning: wcs position is offscale: %s\n", tbuf);
	continue;
      }
    }
    else{
      dx = dval1;
      dy = dval2;
    }
    /* convert image values to integers */
    ix = (int)(dx+0.5);
    iy = (int)(dy+0.5);
    /* sanity checks -- must be inside the image */
    if( (ix < 1) || (ix > dim1) || (iy < 1) || (iy > dim2)){
      fprintf(stderr, "warning: image position off image: %s\n", tbuf);
      continue;
    }
    /* calculate offset into dbuf */
    offset = (iy-1)*dim1 + ix-1;
    /* write out the index and the pixel value at the image position */
    fprintf(stdout, "%d\t%f", idx, dbuf[offset]);
    /* debugging info, if necessary */
    if( debug ){
      fprintf(stdout, "\t %f %f\t%d %d", dval1, dval2, ix, iy);
    }
    /* finish off line */
    fprintf(stdout, "\n");
    /* bump to next index */
    idx++;
  }

  /* close output first so that flush happens automatically */
  FunClose(fun);
  if( dbuf ) free(dbuf);
  return(0);
}
示例#14
0
int main(int argc, char **argv)
{
  int i;
  int got;
  int npha;
  char tbuf[SZ_LINE];
  Ev ebuf, ev, nev;
  Fun fun, fun2;

  /* make sure we have minimal arguments */
  if( argc < 3 ){
    fprintf(stderr, "usage: %s iname oname [columns]\n", argv[0]);
    exit(1);
  }

  /* exit on gio errors */
  setgerror(2);

  /* open input FITS file for reading, and allowing copy of other extensions */
  if( !(fun = FunOpen(argv[1], "rc", NULL)) )
    gerror(stderr, "could not FunOpen input file: %s\n", argv[1]);

  /* look for the size of the phas vector */
  if( !FunColumnLookup(fun, "phas", 0, NULL, NULL, NULL, NULL, &npha, NULL) )
    gerror(stderr, "can't find phas column\n");

  /* open the output FITS image, inheriting params from input */
  if( !(fun2 = FunOpen(argv[2], "w", fun)) )
    gerror(stderr, "could not FunOpen output file: %s\n", argv[2]);

  /* allocate a new row buffer, now that we know the size of phas */
  nev = (Ev)calloc(1, sizeof(EvRec));
  nev->phas = (int *)calloc(npha, sizeof(int));

  /* create format statement for the pha vector, @ means its a pointer */
  sprintf(tbuf, "@%dJ", npha);
  /* specify input columns we want brought into user space */
  FunColumnSelect(fun, sizeof(EvRec), "merge=replace",
		  "$x",   "D",  "rw", FUN_OFFSET(Ev, x),
		  "$y",   "D",  "rw", FUN_OFFSET(Ev, y),
		  "phas", tbuf, "rw", FUN_OFFSET(Ev, phas),
		  NULL);

  /* set columns to be written to the output file */
  if( argc >= 4 )
    FunColumnActivate(fun, argv[3], NULL);

  /* loop through rows and replicate */
  while( (ebuf=(Ev)FunTableRowGet(fun, NULL, MAXROW, NULL, &got)) ){
    for(i=0; i<got; i++){
      /* get pointer to the user info containing x,y, phas */
      ev = ebuf+i;
      /* generate a new rows (with new x, y, phas values) */
      Reverse(ev->x, ev->y, ev->phas,
	      &(nev->x), &(nev->y), nev->phas, npha);
      /* write this new row -- with the replacements from user space */
      FunTableRowPut(fun2, nev, 1, i, NULL);
    }
    if( ebuf ) free(ebuf);
  }

  /* free the new row */
  if( nev ){
    if( nev->phas ) free(nev->phas);
    free(nev);
  }
      
  /* close output before input so that funtools will copy the rest of the
     input extensions to the output (if such copy is requred) */
  FunClose(fun2);
  FunClose(fun);
  return(0);
}