示例#1
0
文件: trap.c 项目: 99years/plan9
void
dotrap(void)
{
	int i;
	struct var *trapreq;
	struct word *starval;
	starval = vlook("*")->val;
	while(ntrap) for(i = 0;i!=NSIG;i++) while(trap[i]){
		--trap[i];
		--ntrap;
		if(getpid()!=mypid) Exit(getstatus());
		trapreq = vlook(Signame[i]);
		if(trapreq->fn){
			start(trapreq->fn, trapreq->pc, (struct var *)0);
			runq->local = newvar(strdup("*"), runq->local);
			runq->local->val = copywords(starval, (struct word *)0);
			runq->local->changed = 1;
			runq->redir = runq->startredir = 0;
		}
		else if(i==SIGINT || i==SIGQUIT){
			/*
			 * run the stack down until we uncover the
			 * command reading loop.  Xreturn will exit
			 * if there is none (i.e. if this is not
			 * an interactive rc.)
			 */
			while(!runq->iflag) Xreturn();
		}
		else Exit(getstatus());
	}
}
示例#2
0
static void dopipe(Node *n) {
	int i, j, sp, pid, fd_prev, fd_out, pids[512], stats[512], p[2];
	bool intr;
	Node *r;

	fd_prev = fd_out = 1;
	for (r = n, i = 0; r != NULL && r->type == nPipe; r = r->u[2].p, i++) {
		if (i > 500) /* the only hard-wired limit in rc? */
			rc_error("pipe too long");
		if (pipe(p) < 0) {
			uerror("pipe");
			rc_error(NULL);
		}
		if ((pid = rc_fork()) == 0) {
			setsigdefaults(FALSE);
			redirq = NULL; /* clear preredir queue */
			mvfd(p[0], r->u[1].i);
			if (fd_prev != 1)
				mvfd(fd_prev, fd_out);
			close(p[1]);
			walk(r->u[3].p, FALSE);
			exit(getstatus());
		}
		if (fd_prev != 1)
			close(fd_prev); /* parent must close all pipe fd's */
		pids[i] = pid;
		fd_prev = p[1];
		fd_out = r->u[0].i;
		close(p[0]);
	}
	if ((pid = rc_fork()) == 0) {
		setsigdefaults(FALSE);
		mvfd(fd_prev, fd_out);
		walk(r, FALSE);
		exit(getstatus());
		/* NOTREACHED */
	}
	redirq = NULL; /* clear preredir queue */
	close(fd_prev);
	pids[i++] = pid;

	/* collect statuses */

	intr = FALSE;
	for (j = 0; j < i; j++) {
		rc_wait4(pids[j], &sp, TRUE);
		stats[j] = sp;
		intr |= (sp == SIGINT);
	}
	setpipestatus(stats, i);
	sigchk();
}
示例#3
0
文件: exec.c 项目: kisom/site-tools
void
Xpipewait(void)
{
	char status[NSTATUS+1];
	if(runq->pid==-1)
		setstatus(concstatus(runq->status, getstatus()));
	else{
		strncpy(status, getstatus(), NSTATUS);
		status[NSTATUS]='\0';
		Waitfor(runq->pid, 1);
		runq->pid=-1;
		setstatus(concstatus(getstatus(), status));
	}
}
示例#4
0
文件: glom.c 项目: muennich/rc3
static List *mkcmdarg(Node *n) {
	char *name;
	List *ret = nnew(List);
	Estack *e = nnew(Estack);
	Edata efd;
	int p[2];
	if (pipe(p) < 0) {
		uerror("pipe");
		return NULL;
	}
	if (rc_fork() == 0) {
		setsigdefaults(FALSE);
		if (mvfd(p[n->u[0].i == rFrom], n->u[0].i == rFrom) < 0) /* stupid hack */
			exit(1);
		close(p[n->u[0].i != rFrom]);
		redirq = NULL;
		walk(n->u[2].p, FALSE);
		exit(getstatus());
	}

#if HAVE_DEV_FD
	name = nprint("/dev/fd/%d", p[n->u[0].i != rFrom]);
#else
	name = nprint("/proc/self/fd/%d", p[n->u[0].i != rFrom]);
#endif

	efd.fd = p[n->u[0].i != rFrom];
	except(eFd, efd, e);
	close(p[n->u[0].i == rFrom]);
	ret->w = name;
	ret->m = NULL;
	ret->n = NULL;
	return ret;
}
示例#5
0
文件: glom.c 项目: muennich/rc3
static List *backq(Node *ifs, Node *n) {
	int p[2], sp;
	pid_t pid;
	List *bq;
	struct termios t;
	if (n == NULL)
		return NULL;
	if (pipe(p) < 0) {
		uerror("pipe");
		rc_error(NULL);
	}
	if (interactive)
		tcgetattr(0, &t);
	if ((pid = rc_fork()) == 0) {
		mvfd(p[1], 1);
		close(p[0]);
		redirq = NULL;
		walk(n, FALSE);
		exit(getstatus());
	}
	close(p[1]);
	bq = bqinput(glom(ifs), p[0]);
	close(p[0]);
	rc_wait4(pid, &sp, TRUE);
	if (interactive && WIFSIGNALED(sp))
		tcsetattr(0, TCSANOW, &t);
	statprint(-1, sp);
	varassign("bqstatus", word(strstatus(sp), NULL), FALSE);
	sigchk();
	return bq;
}
示例#6
0
文件: trap.c 项目: JamesLinus/inferno
void
dotrap(void)
{
	Var *trapreq;
	Word *starval;

	while(refdec(&ntrap) >= 0) {
		if(flag['S'])
			exits(truestatus()?"":getstatus());
		starval=vlook("*")->val;
		trapreq=vlook("sysint");
		if(trapreq->fn){
			start(trapreq->fn, trapreq->pc, (Var*)0);
			runq->local=newvar(strdup("*"), runq->local);
			runq->local->val=copywords(starval, (Word*)0);
			runq->local->changed=1;
			runq->redir=runq->startredir=0;
		} else {
			/*
			 * run the stack down until we uncover the
			 * command reading loop.  Xreturn will exit
			 * if there is none (i.e. if this is not
			 * an interactive rc.)
			 */
			while(!runq->iflag)
				Xreturn();
		}
	}
}
示例#7
0
文件: plan9.c 项目: aahud/harvey
void
Exit(char *stat)
{
	Updenv();
	setstatus(stat);
	exits(truestatus()?"":getstatus());
}
示例#8
0
文件: glom.c 项目: muennich/rc3
static List *mkcmdarg(Node *n) {
	int fd;
	char *name;
	Edata efifo;
	Estack *e = enew(Estack);
	List *ret = nnew(List);
	static int fifonumber = 0;

	name = nprint("/tmp/rc%d.%d", getpid(), fifonumber++);
	if (mkfifo(name, 0666) < 0) {
		uerror("mkfifo");
		return NULL;
	}
	if (rc_fork() == 0) {
		setsigdefaults(FALSE);
		fd = rc_open(name, (n->u[0].i != rFrom) ? rFrom : rCreate); /* stupid hack */
		if (fd < 0) {
			uerror("open");
			exit(1);
		}
		if (mvfd(fd, (n->u[0].i == rFrom)) < 0) /* same stupid hack */
			exit(1);
		redirq = NULL;
		walk(n->u[2].p, FALSE);
		exit(getstatus());
	}
	efifo.name = name;
	except(eFifo, efifo, e);
	ret->w = name;
	ret->m = NULL;
	ret->n = NULL;
	return ret;
}
示例#9
0
文件: main.cpp 项目: RotileQ/practice
int main(void)
{
	scanf("%d",&tcase);
	int tt=1;
	while(tcase--){
	    scanf("%d",&n);
		int ca=0,cb=0;
		status=0;
		int cnt=0;
		for(int i=0;i<n;i++){
		    int u,v;
			scanf("%d%d",&u,&v);
			int ta=ca,tb=cb;
		    status=getstatus(status,1<<mat[u][v],(cnt&1)?cb:ca);
			if(ca==ta&&cb==tb)
				cnt++;
		}
		int ans;
		if(cnt&1)  ans=minsearch(status,-inf,ca,cb);  
		else
			ans=maxsearch(status,inf,ca,cb);
		printf("Game %d: %c wins.\n",tt++,ans==inf?'A':'B');
		 
	}
	return 0;
} 
示例#10
0
/*
 * This is the function that reads in a # commented file and prints the
 * status report for every url found in it.  The file should be in the
 * format of one url per line, blank lines and lines beginning with # are
 * ignored.
 */
void
dofile(char *filename)
{
    FILE   *f;
    char    line[8192];
    struct status st;

    f = fopen(filename, "r");
    if (!f) {
        perror(filename);
        exit(1);
    }
    while (fgets(line, 8192, f)) {
        /* KILL WHITEY! */
        while (*line && isspace(line[strlen(line) - 1]))
            line[strlen(line) - 1] = NULL;

        /* Ignore blank lines and lines beginning with # */
        if (!(line[0] == NULL || line[0] == '#')) {
            st = getstatus(line);
            printstatus(line, st);
            freestatus(st);
        }
    }

    fclose(f);
}
示例#11
0
static void
initialize(void)
{
    if ((block = malloc(blocksize)) == NULL)
	error(FATAL, "no memory");

    ttyi = fileno(stdout);

    if ((ttyo = dup(ttyi)) == -1)
	error(FATAL, "can't dup file descriptor for stdout");

/*
 *
 * Makes sure the printer is in the
 * IDLE state before any real data is sent.
 *
 */


    logit("printer startup\n");

    while ( 1 )
	switch (getstatus(1))
	{
	    case IDLE:
		    if (postbegin != NULL)
			write(ttyo, postbegin, strlen(postbegin));
		    else
			write(ttyo, "\n", 1);
		    return;

	    case WAITING:
	    case BUSY:
	    case ERROR:
		    write(ttyo, "\003\004", 2);
		    sleep(1);
		    break;

	    case FLUSHING:
		    write(ttyo, "\004", 1);
		    sleep(1);
		    break;

	    case PRINTERERROR:
	    case INITIALIZING:
		    sleep(15);
		    break;

	    case DISCONNECT:
		    /* talk to spooler w/S_FAULT_ALERT */
		    error(FATAL, "printer appears to be offline");
		    break;

	    default:
		    sleep(1);
		    break;

	}   /* End switch */

}   /* End of initialize */
示例#12
0
文件: exec.c 项目: kisom/site-tools
int
truestatus(void)
{
	char *s;
	for(s = getstatus();*s;s++)
		if(*s!='|' && *s!='0')
			return 0;
	return 1;
}
示例#13
0
int CodesObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = TSqlObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    
#ifndef QT_NO_PROPERTIES
     if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< int*>(_v) = getid(); break;
        case 1: *reinterpret_cast< QString*>(_v) = gettitle(); break;
        case 2: *reinterpret_cast< QString*>(_v) = getcode(); break;
        case 3: *reinterpret_cast< QString*>(_v) = getcode_url(); break;
        case 4: *reinterpret_cast< int*>(_v) = getstatus(); break;
        case 5: *reinterpret_cast< QDateTime*>(_v) = getcreated_at(); break;
        case 6: *reinterpret_cast< QDateTime*>(_v) = getupdated_at(); break;
        case 7: *reinterpret_cast< int*>(_v) = geteditable(); break;
        case 8: *reinterpret_cast< int*>(_v) = getuser_id(); break;
        case 9: *reinterpret_cast< QString*>(_v) = getshow_from(); break;
        }
        _id -= 10;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setid(*reinterpret_cast< int*>(_v)); break;
        case 1: settitle(*reinterpret_cast< QString*>(_v)); break;
        case 2: setcode(*reinterpret_cast< QString*>(_v)); break;
        case 3: setcode_url(*reinterpret_cast< QString*>(_v)); break;
        case 4: setstatus(*reinterpret_cast< int*>(_v)); break;
        case 5: setcreated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 6: setupdated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 7: seteditable(*reinterpret_cast< int*>(_v)); break;
        case 8: setuser_id(*reinterpret_cast< int*>(_v)); break;
        case 9: setshow_from(*reinterpret_cast< QString*>(_v)); break;
        }
        _id -= 10;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 10;
    } else if (_c == QMetaObject::RegisterPropertyMetaType) {
        if (_id < 10)
            *reinterpret_cast<int*>(_a[0]) = -1;
        _id -= 10;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
示例#14
0
文件: stress.c 项目: ppibburr/rabel
int main (int argc, char *argv[])
{
struct _comm comm;
struct _data data;
struct plc5stat status;
	int count,sts,extsts,lcount,type;
	count=0;
	lcount=0;
	if (argc == 3)
		count = 1;
	if (argc == 4)
		count = atoi(argv[3]);
	if ((argc < 3) || (argc > 4))
		{
		printf ("\nThis program will read a register from an Ethernet connected Allen Bradley\n");
		printf ("PLC-5.  It should also work with a Pyramid Integrator.\n\n");
		printf ("Correct Usage:\nab <plc ip addr> <plc register> {<quantity>}\n");
		printf ("ab 192.168.10.5 n7:0   - will read one integer from N7:0 on plc 192.168.10.5\n");
		printf ("ab 192.168.10.5 n7:30 4 - will read four integers from N7:30 on plc 192.168.10.5\n"); 
		printf ("\n\n");
		exit (-1);
		}

	comm=attach(argv[1],FALSE);
	if (comm.error != 0)
		{
		printf ("Could not connect.  Check your address and try again.\n");
		exit (-1);
		}
	status = getstatus(comm,FALSE);
	type = PLC5;
	if (status.type == 0xde)
		type = PLC5250;
	comm.tns = comm.tns + 4;
while (data.len >= 0)
	{
	lcount++;
	data=word_read(comm,argv[2],count,type,FALSE);
	if (data.len < 0)
		{
		sts = data.data[0];
		extsts = data.data[1];
		printf ("An error occured.  The PLC STS byte is %d, the EXT STS byte is %d\n",sts,extsts);
		if (sts != 0xf0)
			printf ("Primary Error code is %s\n",errors[(sts/16)]);
		if (extsts != 0)
			printf ("Extended error code is %s\n",ext_errors[extsts]);
		}
	printf ("Loop # %d   got %d bytes back.\n",lcount,data.len);
//	for (x=0;x<data.len;x++)
//		printf ("%d\n",data.data[x]);
	comm.tns = comm.tns + 4;
	}
	
	close (comm.handle);
	exit (0);
}
示例#15
0
int remote_playloop(void) {

  Status s;

  /* Check the status. If the player should pause,
     then signal that the command has been processed
     and wait for a new status. A new status will end
     the player and return control to the main loop.
     The main loop will signal that the new command
     has been processed.
   */
  
  pthread_mutex_lock (&main_lock);
  s = getstatus();
  pthread_mutex_unlock (&main_lock);

  send_log("playloop entry s=%d", s);

  if (s == PAUSE) {

    /* Send "pause on" */
    send_msg("P 1");

    while (s == PAUSE) {

      sem_post(&sem_processed);
      sem_wait(&sem_command);
      pthread_mutex_lock (&main_lock);
      s = getstatus();
      pthread_mutex_unlock (&main_lock);
    }

    /* Send "pause off" */
    send_msg("P 2");
  }

    /* Send stop msg to the frontend */
    /* this probably should be done after the audio buffer is flushed and no audio is actually playing, but don't know how */
  if ((s == STOP) || (s == QUIT)) send_msg("P 0");

  send_log("playloop exit s=%d", s);

  return ((s == NEXT) || (s == STOP) || (s == QUIT));
}
示例#16
0
// returns the type of controller (1 PLC5, 2 PLC5250, 3 SLC5, 4 MICRO)
int abel_comm_object_get_device_type(ABELCommObject* obj)
{
  struct plc5stat status;
  status = getstatus(obj->comm1,FALSE);
  if (status.type == 0xee)
	return 3;
  if (status.type == 0xeb)
	return 1;
  if (status.type == 0xde)
	return 2;
}
示例#17
0
文件: exec.c 项目: kisom/site-tools
void
Xreturn(void)
{
	struct thread *p = runq;
	turfredir();
	while(p->argv) poplist();
	codefree(p->code);
	runq = p->ret;
	efree((char *)p);
	if(runq==0)
		Exit(getstatus());
}
示例#18
0
extern void statprint(int pid, int i) {
	if (i & 0xff) {
		char *msg = ((i & 0x7f) < NUMOFSIGNALS ? signals[i & 0x7f].msg : "");
		if (pid != -1)
			fprint(2, "%d: ", pid);
		if (i & 0x80) {
			if (*msg == '\0')
				fprint(2, "core dumped\n");
			else
				fprint(2, "%s--core dumped\n", msg);
		} else if (*msg != '\0')
			fprint(2, "%s\n", msg);
	}
	if (i != 0 && dashee && !cond)
		rc_exit(getstatus());
}
示例#19
0
BOOL CALLBACK
status_dialog (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	TCHAR *status1, *status2;
	RECT rect;

	switch (msg) {
	case WM_INITDIALOG:
		SetTimer (hwnd, TIMERID, UPDATE_ELAPSE, NULL);
		return TRUE;
	case WM_COMMAND:
		switch (wparam) {
		case IDCANCEL:
			EndDialog (hwnd, 0);
			break;
		}
		return TRUE;
	case WM_TIMER:
		getstatus (&status1, &status2);
		SetWindowText (GetDlgItem (hwnd, IDC_STATUS1), status1);
		SetWindowText (GetDlgItem (hwnd, IDC_STATUS2), status2);
		SetWindowLong (hwnd, DWL_MSGRESULT, 0);
		return TRUE;
	case WM_SIZE:
		rect.left = 16;
		rect.top = 16;
		rect.right = 32;
		rect.bottom = 32;
		MapDialogRect (hwnd, &rect);
		MoveWindow (GetDlgItem (hwnd, IDC_STATUS1),
			    LOWORD (lparam) - rect.left * 4, rect.top,
			    rect.left * 3, rect.top, TRUE);
		MoveWindow (GetDlgItem (hwnd, IDC_STATUS2), rect.left,
			    rect.top * 3, LOWORD (lparam) - rect.left * 2,
			    HIWORD (lparam) - rect.top * 6, TRUE);
		MoveWindow (GetDlgItem (hwnd, IDCANCEL),
			    LOWORD (lparam) - rect.left * 4,
			    HIWORD (lparam) - rect.top * 2,
			    rect.left * 3, rect.top, TRUE);
		return TRUE;
	}
	return FALSE;
}
示例#20
0
static bool isrdonly( struct dirent *dent, char *path )
{
    unsigned    bit;
    uid_t       user;

    user = geteuid();
    if( user == 0 ) {
        /* we're root - we can alway write the file */
        return( false );
    }
    getstatus( dent, path );
    if( dent->d_stat.st_uid == user ) {
        bit = S_IWUSR;
    } else if( dent->d_stat.st_gid == getegid() ) {
        bit = S_IWGRP;
    } else {
        bit = S_IWOTH;
    }
    return( !(dent->d_stat.st_mode & bit) );
}
示例#21
0
文件: exec.c 项目: kisom/site-tools
void
Xexit(void)
{
	struct var *trapreq;
	struct word *starval;
	static int beenhere = 0;
	if(getpid()==mypid && !beenhere){
		trapreq = vlook("sigexit");
		if(trapreq->fn){
			beenhere = 1;
			--runq->pc;
			starval = vlook("*")->val;
			start(trapreq->fn, trapreq->pc, (struct var *)0);
			runq->local = newvar(strdup("*"), runq->local);
			runq->local->val = copywords(starval, (struct word *)0);
			runq->local->changed = 1;
			runq->redir = runq->startredir = 0;
			return;
		}
	}
	Exit(getstatus());
}
示例#22
0
文件: main.cpp 项目: RotileQ/practice
int maxsearch(int state,int beta,int ca,int cb)
{
	int alpha=-inf;
	if(ca>=5)  return inf;
	else if(cb>=5)  return -inf;
	if(state==STATUS)  return ca>cb?inf:-inf;

	int remain=(~state)&STATUS;
	while(remain){
		int seg=remain&(-remain);
		int ta=ca,tb=cb;
		int now=getstatus(state,seg,ta);
		int tmp;
		if(ta>ca)
			tmp=maxsearch(now,beta,ta,tb);
		else
		    tmp=minsearch(now,alpha,ta,tb);
		if(tmp>alpha)  alpha=tmp; 
		if(tmp>=beta) return alpha;
		remain-=seg;
	}
	return alpha;
}
示例#23
0
文件: slcread.c 项目: 376473984/pvb
int main (int argc, char *argv[])
{
struct _comm comm;
struct _data data;
struct plc5stat status;
	int count,x,sts,extsts,type;
	unsigned int temp1, temp2;
	count=0;
	if (argc == 3)
		count = 1;
	if (argc == 4)
		count = atoi(argv[3]);
	if ((argc < 3) || (argc > 4))
		{
		printf ("\nThis program will read a register from an Ethernet connected Allen Bradley\n");
		printf ("PLC-5.  It should also work with a Pyramid Integrator.\n\n");
		printf ("Correct Usage:\nab <plc ip addr> <plc register> {<quantity>}\n");
		printf ("ab 192.168.10.5 n7:0   - will read one integer from N7:0 on plc 192.168.10.5\n");
		printf ("ab 192.168.10.5 n7:30 4 - will read four integers from N7:30 on plc 192.168.10.5\n"); 
		printf ("\n\n");
		exit (-1);
		}

	comm=abel_attach(argv[1],FALSE);
	if (comm.error != 0)
		{
		printf ("Could not connect.  Check your address and try again.\n");
		exit (-1);
		}
	status = getstatus (comm,FALSE);
	type = PLC5;
	if (status.type == 0xde)
		type = PLC5250;
	if (status.type == 0xee)
		type = SLC;
	comm.tns = comm.tns + 4;

	data=protread3(comm,argv[2],count,type,FALSE);
	if (data.len == -1)
		{
		sts = data.data[0];
		extsts = data.data[1];
		printf ("An error occured.  The PLC STS byte is %d, the EXT STS byte is %d\n",sts,extsts);
		if (sts != 0xf0)
			printf ("Primary Error code is %s\n",errors[(sts/16)]);
		if (extsts != 0)
			printf ("Extended error code is %s\n",ext_errors[extsts]);
		close (comm.handle);
		exit (-1);
		}
	switch (data.name.section)
		{
		case 0:
			if (data.name.floatdata == TRUE)
				{
				for (x=0;x<data.len;x=x+2)
					{
					temp1 = (data.data[x]);
					temp2 = (data.data[x+1]);
					printf ("%f\n",itof(temp1,temp2));
					}
				}
			if (data.name.floatdata == FALSE)
				{
				for (x=0;x<(data.len);x++)
					printf ("%d\n",(short)data.data[x]);
				}
			break;
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
			for (x=0;x<data.len;x++)
				printf ("%02X  ",(byte)data.data[x]);
			printf ("\n");
		}	 
	close (comm.handle);
	exit (0);
}
示例#24
0
bool WI_StrDataLoc::wassearchsuccesful ( )
{
	return getstatus ( );// was it successful?
}
示例#25
0
文件: xp1.c 项目: wjlei1990/WORKFLOW
void xp1(int *nerr)
{
        int n;
	char *kptext, kret[9];
	int l1dttm, lany, lbotaxsave, lbottcsave, lframesave, ltitlsave, 
	 ltoptcsave, lwait, lxgrdsave, lxlabsave, lxlims, lylabsave,
	 lprint = FALSE , ltry = FALSE ;
	int i, jdfl, jdfl1, jdfl2, jfr, jperfr, n1dttm[6], 
	 ncret, nfr, nlcx, nlcy, nperfr, num, notused;
	float tmax, tmaxj, tmin, tminj, toff[MDFL], ypdel, ypmxsave;

	static int lrel = FALSE;
	static int lperpl = FALSE;
	static int nperpl = 3;
	static char kwait[9] = "Waiting$";

	float *const Toff = &toff[0] - 1;


	/*=====================================================================
	 * PURPOSE:  To execute the action command P1.
	 *           This command makes a multi-trace, multi-window plot.
	 *=====================================================================
	 * OUTPUT ARGUMENTS:
	 *    nerr:    Error return flag.  Set to 0 if no error occurred.
	 *             Potential error numbers:  1001, 1504.
	 *=====================================================================
	 * MODULE/LEVEL:  gam/2
	 *=====================================================================
	 * GLOBAL INPUT:
	 *    mach:
	 *    dfm:     ndfl, sacmem
	 *    hdr:     begin, ennd, delta
	 *    gem:     lbotax, lbottc, ltopax, ltoptc, lxlab, lylab, ltitl,
	 *             lxgrd, ypmn, ypmx, chht, tsdef
	 *    gam:     kgddef
	 *=====================================================================
	 * SUBROUTINES CALLED:
	 *=====================================================================
	 * MODIFICATION HISTORY:
	 *    970908:  Modified response to ddttm.  maf 
	 *    970723:  Commented out an if statement to fix a bug which kept
	 *             p1 relative from functioning when xlim was set. maf
         *    970130:  Added arguments to dispid() to plot file number. maf
	 *    910607:  Move stmt label 8888 back to where it was.
	 *             Changed gots to goto plrest after call to plsave.
	 *             Error condition before lframesave goes to return. (wct).
	 *    910607:  Added call to zgetgd when no graphics device specified.
	 *             Changed call to begindevice to begindevices. (wct)
	 *    910220:  Move stmt label 8888, so lframe etc. are restored on err exit
	 *    880411:  Axes annotation now controlled by GEM variables.
	 *    850321:  Now displaying REL offset below FILEID.
	 *    821228:  Added calls to DISPID, DISPPK and PLHOME.
	 *    821122:  Added check for bad date fields.
	 *             Fixed bug involving titles and PP option.
	 *    820823:  Fixed bug involving extra x axes when using PP option.
	 *    820721:  Changed to newest set of parsing and checking functions.
	 *    811228:  Deleted call to ZCLIP.
	 *    810120:  Changed to output message retrieval from disk.
	 *    800920:  Added PERPLOT option.
	 *             Fixed bug in REL/ABS option.
	 *    800905:  Pick and file id options to new DISPLAY command.
	 *    800618:  Added pick display capability to this plot.
	 *=====================================================================
	 * DOCUMENTED/REVIEWED: 
	 *===================================================================== */
	/* PROCEDURE: */
	/* Errors before plsave have to avoid going to execute plrest. */
	*nerr = 0;

	/* PARSING PHASE: */

	/* - Loop on each token in command: */

	while ( lcmore( nerr ) ){
	    /* -- "PERPLOT ON/OFF/n":  change number of files plotted per frame. */
	    if( lklogi( "PERPLOT$",9, &lperpl, &nperpl ) )
	    { /* do nothing */ }

	    /* -- "RELATIVE/ABSOLUTE":  change method of displaying time on x axis. */
	    else if( lclog2( "RELATIVE$",10, "ABSOLUTE$",10, &lrel ) )
	    { /* do nothing */ }

            /* if PRINT option is tried, get printer name */
            else if ( ltry ) {
                lcchar ( MAXPRNTRNAMELEN   , kmgem.kptrName ,
                         MAXPRNTRNAMELEN+1 , &notused ) ;
                terminate ( kmgem.kptrName ) ;
                if ( !lprint )
                    kmgem.kptrName[0] = '\0' ;

                ltry = FALSE ;
            }

	    /* -- "PRINT":  print the final product */
	    else if( lckey( "PRINT#$", 8 ) ) {
		ltry = TRUE ;
		if ( cmgdm.lbegf ) {
		    setmsg ( "WARNING" , 2403 ) ;
		    outmsg () ;
		    clrmsg () ;
		}
		else {
		    lprint = TRUE ;
		}
	    }

	    /* -- Bad syntax. */
	    else{
		cfmt( "ILLEGAL OPTION:",17 );
		cresp();
	    }
	} /* end while */

	/* - The above loop is over when one of two conditions has been met:
	 *   (1) An error in parsing has occurred.  In this case NERR is > 0 .
	 *   (2) All the tokens in the command have been successfully parsed. */

	if( *nerr != 0 )
	    goto L_8888;

	/* CHECKING PHASE: */

	/* - Check for null data file list. */

	vflist( nerr );
	if( *nerr != 0 )
	    goto L_8888;

	/* - Check to make sure all files are time series files. */

	vftime( nerr );
	if( *nerr != 0 ){
	    aplmsg( "Use PLOTSP command to plot spectral data.",42 );
	    goto L_8888;
	}

	/* - If no graphics device is open, try to open the default device. */

	getstatus( "ANY", &lany );
	if( !lany ){
	    zgetgd( kmgam.kgddef,9 );
	    begindevices( kmgam.kgddef,9, 1, nerr );
	    if( *nerr != 0 )
		goto L_8888;
	}

	/* EXECUTION PHASE: */

	/* - Save current plot and x limit attributes.
	 * - Error after plsave have to go to execute plrest. */

	plsave();

        /* initialize plot offsets */
        for ( i=0; i<MDFL; i++) toff[i] = 0.0;

	/* - Set up specific options that apply only to this plot. */

	lbotaxsave = cmgem.axis[BOTTOM].annotate;
	lbottcsave = cmgem.axis[BOTTOM].ticks;
	ltoptcsave = cmgem.axis[TOP].ticks;
	cmgem.axis[BOTTOM].ticks    = FALSE;
	cmgem.axis[BOTTOM].annotate = FALSE;

	lxlabsave = cmgem.xlabel.on;
	lylabsave = cmgem.ylabel.on;
	ltitlsave = cmgem.title.on;
	lxgrdsave = cmgem.lxgrd;
	cmgem.xlabel.on = FALSE;
	cmgem.ylabel.on = FALSE;
	cmgem.title.on  = FALSE;
	cmgem.lxgrd = FALSE;

	/* - Set up y window for each subplot. */

	if( lperpl ){
	    nfr = (cmdfm.ndfl - 1)/nperpl + 1;
	    nperfr = nperpl;
	}
	else{
	    nfr = 1;
	    nperfr = cmdfm.ndfl;
	}
	ypdel = (cmgem.plot.ymax - cmgem.plot.ymin)/(float)( nperfr );

	/* - Check WAIT option.  This is on when:
	 * -- A wait request has been made.
	 * -- An active device (normally the user's terminal) is on. */

	if( cmgam.lwaitr )
	    getstatus( "ACTIVE", &lwait );
	else
	    lwait = FALSE;

	/* - Loop on number of frames: */

	jdfl1 = 1;
	ypmxsave = cmgem.plot.ymax;
	lframesave = cmgem.lframe;
	for( jfr = 1; jfr <= nfr; jfr++ ){
	    /* set cmgem.lframe FALSE for each pass through loop, because 
		endframe() sets it back to TRUE for the next pass. */
	    cmgem.lframe = FALSE;

	    /* -- No wait after last frame. */
	    if( jfr == nfr && !cmgam.lwaite )
		lwait = FALSE;

	    /* -- Loop on data files in each frame: */

	    jdfl2 = min( cmdfm.ndfl, jdfl1 + nperfr - 1 );

	    /* -- Determine time limits for x axis of this frame.
	     *    (Correct for any differences in GMT reference time.) */

	    getfil( jdfl1, TRUE, &num, &nlcy, &nlcx, nerr );
	    if( *nerr != 0 )
		goto L_7777;
	    jperfr = 1;
	    getxlm( &lxlims, &tmin, &tmax );
/*            if( !lxlims ){	commented out to allow relative mode when xlim is set. maf 970723 */
		if( lrel ){
		    tmax = tmax - tmin;
		    Toff[jperfr] = -tmin;
		    tmin = 0.;
	    	}
	    	else{
		    copyi( nzdttm, n1dttm, 6 );
		    l1dttm = ldttm( n1dttm );
		    Toff[jperfr] = 0.;
	    	}
		for( jdfl = jdfl1 + 1; jdfl <= jdfl2; jdfl++ ){
		    jperfr = jperfr + 1;
		    getfil( jdfl, TRUE, &num, &nlcy, &nlcx, nerr );
		    if( *nerr != 0 )
			goto L_7777;
		    getxlm( &lxlims, &tminj, &tmaxj );
		    if( lrel ){
			tmax = fmax( tmax, tmaxj - tminj );
			Toff[jperfr] = -tminj;
		    }
		    else{
			if( l1dttm && ldttm( nzdttm ) ){
			    ddttm( nzdttm, n1dttm, &Toff[jperfr] );
			    /* if it starts 2 days after the first file,
				plot relative. maf 970908 */
			    if ( fabs ( Toff[jperfr] ) > TWODAYS )
				Toff[jperfr] = 0 ;
			}
			else{
			    Toff[jperfr] = 0.;
			}
			tmin = fmin( tmin, tminj + Toff[jperfr] );
			tmax = fmax( tmax, tmaxj + Toff[jperfr] );
		    } /* end else associated with if ( lrel ) */
		} /* end for( jdfl = jdfl1 + 1; jdfl <= jdfl2; jdfl++ ) */
/*	    }  end if ( !lxlims ) commented out to allow relative mode when xlim is set. maf 970723 */

	    /* - Check range of time limits to avoid errors that could occur
	     *   later during plotting. *

	    if( fabs( tmax - tmin ) > (float)( MLARGE ) ){
		*nerr = 1504;
		setmsg( "ERROR", *nerr );
		goto L_7777;
	    } */

	    /* - Set x axis plot limits. */

	    cmgem.lxlim = TRUE;
	    cmgem.ximn = tmin;
	    cmgem.ximx = tmax;

	    if( lframesave ){
		beginframe( lprint , nerr );
		if( *nerr != 0 )
		    goto L_7777;
		getvspace( &cmgem.view.xmin, &cmgem.view.xmax, 
                           &cmgem.view.ymin, &cmgem.view.ymax );
	    }
	    jperfr = 0;

	    cmgem.tsdef = fmin( cmgem.tsdef, (cmgem.view.ymax - cmgem.view.ymin)/(8.0*
	     (float)( nperfr )) );
	    cmgam.tsfid = cmgem.tsdef;
	    cmgam.tspk = cmgem.tsdef;
	    cmgem.tsaxis = cmgem.tsdef;

	    for( jdfl = jdfl1; jdfl <= jdfl2; jdfl++ ){
		jperfr = jperfr + 1;
		cmgem.plot.ymin = cmgem.plot.ymax - ypdel;

		/* --- Get pointers to this file's location in memory. */

		getfil( jdfl, TRUE, &num, &nlcy, &nlcx, nerr );
		if( *nerr != 0 )
		    goto L_7777;

		/* --- Set up x axis data values. */

		if( *leven ){
		    cmgem.xgen.on = TRUE;
		    cmgem.xgen.delta = *delta;
		    cmgem.xgen.first = *begin + Toff[jperfr];
		}
		else{
		    cmgem.xgen.on = FALSE;
		}

		/* --- Set up y axis plot limits. */

		getylm( &cmgem.lylim, &cmgem.yimn, &cmgem.yimx );

		/* --- Plot this file. */

		pl2d( cmmem.sacmem[nlcx], cmmem.sacmem[nlcy], num, 1, 1, nerr );
		if( *nerr != 0 )
		    goto L_7777;

		/* --- Plot picks and fileid. */

		disppk( Toff[jperfr] );
                
		/* --- Add a label with offset time if this is a REL plot. */
                kptext = NULL;
                n = 0;
		if( lrel && cmgam.lfidrq ){
                  asprintf(&kptext, "OFFSET: %10.3e", -Toff[jperfr] );
                  n = 1;
                }
		dispid( cmgam.lfinorq , jdfl, n, &kptext );
                if(kptext) {
                  free(kptext);
                  kptext = NULL;
                }
		cmgem.plot.ymax = cmgem.plot.ymin;
	    } 

	    /* -- Draw bottom x axis. */
	    cmgem.axis[BOTTOM].annotate = lbotaxsave;
	    cmgem.axis[BOTTOM].ticks    = lbottcsave;
	    cmgem.axis[TOP].ticks       = ltoptcsave;
	    cmgem.lxgrd = lxgrdsave;
	    cmgem.uplot.ymax = ypmxsave*cmgem.view.ymax;
	    cmgem.chht = cmgem.tsaxis;
	    cmgem.chwid = cmgem.txrat*cmgem.chht;
	    settextsize( cmgem.chwid, cmgem.chht );
	    if( cmgem.ixint == AXIS_LINEAR ){
		xlinax();
	    }
	    else if( cmgem.ixint == AXIS_LOG ){
		xlogax();
	    }

	    /* -- Draw axes labels and title. */
	    if( lxlabsave )
                centxt( kmgem.kxlab,145, cmgem.xlabel.len, cmgem.xlabel.pos, cmgem.xlabel.text_size );
	    if( lylabsave )
		centxt( kmgem.kylab,145, cmgem.ylabel.len, cmgem.ylabel.pos, cmgem.ylabel.text_size );
	    if( ltitlsave )
		centxt( kmgem.ktitl,145, cmgem.title.len, cmgem.title.pos, cmgem.title.text_size );

	    /* -- Home cursor, advance frame and restore some GEM parameters. */
	    plhome();
	    if( lframesave )
		endframe( FALSE , nerr );
            else
              flushbuffer( nerr );
	    cmgem.plot.ymax = ypmxsave;
	    cmgem.axis[BOTTOM].annotate = FALSE;
	    cmgem.axis[BOTTOM].ticks    = FALSE;

	    /* -- Wait for user prompt before plotting next frame if appropriate. */
	    if( lwait ){
		zgpmsg( kwait,9, kret,9 );
		ncret = indexb( kret,9 );
		upcase( kret, ncret, kret,9 );
		if( kret[0] == 'K' )
		    goto L_7777;
		if( kret[0] == 'G' )
		    lwait = FALSE;
	    }

	    jdfl1 = jdfl2 + 1;
	} /* end for ( jfr ) */

	/* - Restore plot and x limit attributes.  Return. */

L_7777:
	plrest();
	cmgam.tsfid = cmgem.tsdef;
	cmgam.tspk = cmgem.tsdef;
	cmgem.tsaxis = cmgem.tsdef;

	cmgem.plot.ymax = ypmxsave;
	cmgem.axis[BOTTOM].annotate = lbotaxsave;
	cmgem.axis[BOTTOM].ticks    = lbottcsave;
	cmgem.lframe = lframesave;

L_8888:
	return;
} /* end of function */
示例#26
0
extern int main(int argc, char *argv[], char *envp[]) {
	char *dashsee[2], *dollarzero, *null[1];
	int c;
	initprint();
	dashsee[0] = dashsee[1] = NULL;
	dollarzero = argv[0];
	rc_pid = getpid();
	dashell = (*argv[0] == '-'); /* Unix tradition */
	while ((c = rc_getopt(argc, argv, "c:deiIlnopsvx")) != -1)
		switch (c) {
		case 'c':
			dashsee[0] = rc_optarg;
			goto quitopts;
		case 'd':
			dashdee = TRUE;
			break;
		case 'e':
			dashee = TRUE;
			break;
		case 'I':
			dashEYE = TRUE;
			interactive = FALSE;
			break;
		case 'i':
			dasheye = interactive = TRUE;
			break;
		case 'l':
			dashell = TRUE;
			break;
		case 'n':
			dashen = TRUE;
			break;
		case 'o':
			dashoh = TRUE;
			break;
		case 'p':
			dashpee = TRUE;
			break;
		case 's':
			dashess = TRUE;
			break;
		case 'v':
			dashvee = TRUE;
			break;
		case 'x':
			dashex = TRUE;
			break;
		case '?':
			exit(1);
		}
quitopts:
	argv += rc_optind;
	/* use isatty() iff neither -i nor -I is set, and iff the input is not from a script or -c flags */
	if (!dasheye && !dashEYE && dashsee[0] == NULL && (dashess || *argv == NULL))
		interactive = isatty(0);
	if (!dashoh) {
		checkfd(0, rFrom);
		checkfd(1, rCreate);
		checkfd(2, rCreate);
	}
	initsignal();
	inithash();
	initparse();
	assigndefault("ifs", " ", "\t", "\n", (void *)0);
#ifdef DEFAULTPATH
	assigndefault("path", DEFAULTPATH, (void *)0);
#endif
	assigndefault("pid", nprint("%d", rc_pid), (void *)0);
	assigndefault("prompt", "; ", "", (void *)0);
	assigndefault("version", VERSION, "$Release: @(#)" PACKAGE " " VERSION " " RELDATE " $", (void *)0);
	initenv(envp);
	initinput();
	null[0] = NULL;
	starassign(dollarzero, null, FALSE); /* assign $0 to $* */
	inithandler();

	if (dashell) {
		char *rcrc;
		int fd;

		rcrc = concat(varlookup("home"), word("/.rcrc", NULL))->w;
		fd = rc_open(rcrc, rFrom);
		if (fd == -1) {
			if (errno != ENOENT)
				uerror(rcrc);
		} else {
			bool push_interactive;

			pushfd(fd);
			push_interactive = interactive;
			interactive = FALSE;
			doit(TRUE);
			interactive = push_interactive;
			close(fd);
		}
	}

	if (dashsee[0] != NULL || dashess) {	/* input from  -c or -s? */
		if (*argv != NULL)
			starassign(dollarzero, argv, FALSE);
		if (dashess)
			pushfd(0);
		else
			pushstring(dashsee, TRUE);
	} else if (*argv != NULL) {	/* else from a file? */
		b_dot(--argv);
		rc_exit(getstatus());
	} else {			/* else stdin */
		pushfd(0);
	}
	dasheye = FALSE;
	doit(TRUE);
	rc_exit(getstatus());
	return 0; /* Never really reached. */
}
示例#27
0
static void
filter(void)
{
    static int	wflag = 0;	/* nonzero if we've written a block */
    int		fd_in = fileno(stdin);

/*
 *
 * Responsible for sending the next file to the printer.
 * Most of the hard stuff is done in getstatus() and readline().
 * All this routine really does is control what happens for the
 * different printer states. 
 *
 */


    logit("sending file\n");

    curfile++;

    while (readblock(fd_in))
	switch (getstatus(0))
	{
	    case WAITING:
		    writeblock();
		    wflag = 1;
		    break;

	    case BUSY:
	    case PRINTING:
	    case PRINTERERROR:
		    if (tostdout == FALSE)
		    {
			writeblock();
			wflag = 1;
		    }
		    else
			sleep(1);
		    break;

	    case UNKNOWN:
		    if (tostdout == FALSE)
		    {
			writeblock();
			wflag = 1;
		    }
		    break;

	    case NOSTATUS:
		    if (tostdout == FALSE)
		    {
			if (wflag)
			    writeblock();
		    }
		    else
			sleep(1);
		    break;

	    case IDLE:
		    if (wflag)
			error(FATAL, "printer is idle");
		    write(ttyo, "\n", 1);
		    break;

	    case ERROR:
		    fprintf(stderr, "%s", mesg);	/* for csw */
		    error(FATAL, "PostScript error");
		    break;

	    case FLUSHING:
		    error(FATAL, "PostScript error");
		    break;

	    case INITIALIZING:
		    error(FATAL, "printer booting");
		    break;

	    case DISCONNECT:
		    error(FATAL, "printer appears to be offline");
		    break;

	}   /* End switch */

}   /* End of print */
示例#28
0
static bool isdir( struct dirent *dent, char *path )
{
    getstatus( dent, path );
    return( S_ISDIR( dent->d_stat.st_mode ) );
}
示例#29
0
int main(int argc, char *argv[]) {
  int     nelem, nimages;

  float  *tagon[MAXELEM], *tagoff[MAXELEM], *tagdiff[MAXELEM];  // Images
  double *tagctrl;            // tag control variable values
  float  *mean_on, *mean_off, // mean of tag on/off images
         *mean_diff,          // mean of pairwise difference images
	 *diff_mean;          // difference of mean on/off images
  double *image_arr;
  
  fdf_header      fdf_hdr;
  char    filename[MAXSTR];


  float noise_thr = 0;

  // Loop variables
  int slice, image, images, ndiff;
  int pixel, datapts;
  int i;
  int debug_pixel, debug;
  
  /* input arguments */
  user_input input = {
    0,          // debug
    "asltag",   // tagvar
    -1,         // noise
    -1,         // pixel 
    "ASL",      // outdir 
    ".",        // indir 
    0,          // write all pairs of subtracted images
    0,          // subtraction scheme (integer), default strict pairs
    "pair"      // subtraction scheme (string), default strict pairs
  };

  
  /*******************************************************************/  
  /*** Calculations **************************************************/  
  /*******************************************************************/  
  // Get arguments from commandline
  get_args(&input, argc, argv);
  debug = input.debug;
  if (debug) {
    if (input.pixel < 0) 
      debug_pixel = fdf_hdr.ro_size/2*fdf_hdr.pe_size + fdf_hdr.pe_size/2;
    else
      debug_pixel = input.pixel;
  }
  else debug_pixel = -1;

  /* Set up string for procpar; 
     this is for future expansion, to allow 
       - data to be in arbitrary directory
       - S(0) and S(non-zero)to be in different directories 
  */
  strcpy(procpar,input.indir);
  strcat(procpar,"/procpar");
  if (debug) printf("indir = %s, procpar = %s\n",input.indir,procpar);


  // Determine the number of images
  nelem = getstatus(input.tagvar);
  
  if (nelem == 0) {
    exit(0);  // error message is printed by getstatus
  }
    

  // Read tag control variable
  if ((tagctrl = (double *) malloc(sizeof(double)*nelem)) == NULL) nomem();
  getarray(input.tagvar,tagctrl);

  /* Is this an epi scan with reference scan(s)? */
  images = getstatus("image");
  if (images == nelem) { // assume image is arrayed in parallel with the variable
    //find out how many ref scans
    if ((image_arr = (double *) malloc(sizeof(double)*images)) == NULL) nomem();
    getarray("image",image_arr);
    nimages = 0;
    for (i = 0; i < images; i++)
      if (image_arr[i] == 1) 
        nimages++;
  }
  else nimages = nelem;

  if (debug) printf("nelem, nimages, images = %d, %d, %d\n",nelem, nimages, images);


/* XXX Check if we have an equal number of tag on/off ??? */

  
  /* Initialize fdf header */
  init_fdf_header(&fdf_hdr);


  /* Allocate memory for all images */
  datapts = fdf_hdr.ro_size*fdf_hdr.pe_size;
  switch(input.subtr) {
    case 0:  ndiff = nimages/2;   break; //strict pairwise
    case 1:  ndiff = nimages - 1; break; // adjacent pairs
    case 2:  ndiff = nimages - 2; break; // "surround" subtraction
    default: printf("Invalid subtraction scheme\n");exit(0);
  }
  
  
  for (image = 0; image < ndiff; image++) {
/* XXX CHECK if tagctrl = -1, 0 , 1 */
    if ((tagon[image]   = (float *)malloc(datapts*sizeof(float))) == NULL) nomem();
    if ((tagoff[image]  = (float *)malloc(datapts*sizeof(float))) == NULL) nomem();
    if ((tagdiff[image] = (float *)malloc(datapts*sizeof(float))) == NULL) nomem();
  }
  if ((mean_on   = (float *)malloc(datapts*sizeof(float))) == NULL) nomem();
  if ((mean_off  = (float *)malloc(datapts*sizeof(float))) == NULL) nomem();
  if ((mean_diff = (float *)malloc(datapts*sizeof(float))) == NULL) nomem();
  if ((diff_mean = (float *)malloc(datapts*sizeof(float))) == NULL) nomem();


  /* Create directory to put output in */
  if (strcmp(input.outdir, "./")) {
    if (debug) printf("Making directory %s\n",input.outdir);
    mkdir(input.outdir,0777);
  }

  
  /*******************************************************************/  
  /*** Slice by slice calculations ***********************************/  
  /*******************************************************************/  
  for (slice = 0; slice < fdf_hdr.slices; slice++) {
    i = 0;
    for (image = 0; image < nimages; image+=2) {
/* XXX check control variable */
      /* Read tag on */
      sprintf(filename,"%s/slice%03dimage%03decho001.fdf",
              input.indir,slice+1,image+1);
      if (debug) printf("tag on  [%d]: %s\n",i,filename);
      read_fdf_data(filename,tagon[i],&fdf_hdr);

      /* Read tag off */
      sprintf(filename,"%s/slice%03dimage%03decho001.fdf",
              input.indir,slice+1,image+2);
      if (debug) printf("tag off [%d]: %s\n",i,filename);
      read_fdf_data(filename,tagoff[i],&fdf_hdr);
      
      i++;
    } // end read image loop
    if (debug) printf("\n");    

    // Noise threshold - user input or based on histogram
    if (input.noise > 0) noise_thr = input.noise;
    else // Get noise from the first image
      noise_thr = threshold(tagon[0],&fdf_hdr);

    if (debug) printf("noise level %f\n",noise_thr);

    /*******************************************************************/  
    /*** Pixel loop ****************************************************/  
    /*******************************************************************/  
    for (pixel = 0; pixel < datapts; pixel++) {
      mean_diff[pixel] = 0;
     
      if (tagon[0][pixel] > noise_thr) {
        switch (input.subtr) {
	  case 0: // strictly pairwise: 0-0, 1-1, 2-2, ...
            for (image = 0; image < nimages/2; image++) {
	      tagdiff[image][pixel]  = (tagon[image][pixel] - tagoff[image][pixel]);
	      mean_diff[pixel]      += tagdiff[image][pixel];
            } 
	    break;

	  case 1:   // adjacent pairs: 0-0, 1-0, 1-1, 2-1, ...
	    i = 0;
            for (image = 0; image < nimages/2-1; image++) {
	      tagdiff[i][pixel] = (tagon[image][pixel] - tagoff[image][pixel]);
	      mean_diff[pixel] +=  tagdiff[i][pixel];
	      i++;
              if (pixel == debug_pixel) printf("subtract %d - %d\n",image,image);
	      
	      tagdiff[i][pixel] = (tagon[image+1][pixel] - tagoff[image][pixel]);
	      mean_diff[pixel] +=  tagdiff[i][pixel];
              if (pixel == debug_pixel) printf("subtract %d - %d\n",image+1,image);

	      i++;
            }
   	    tagdiff[i][pixel] = (tagon[nimages/2-1][pixel] - tagoff[nimages/2-1][pixel]);
            if (pixel == debug_pixel) printf("subtract %d - %d\n",nimages/2,nimages/2);

            mean_diff[pixel] +=  tagdiff[i][pixel];
	    break;

	  case 2: // surrounding pairs
	    i = 0;
            for (image = 0; image < nimages/2-1; image++) {
	      tagdiff[i][pixel] = ((tagon[image][pixel]+tagon[image+1][pixel])/2 - tagoff[image][pixel]);
	      mean_diff[pixel] +=  tagdiff[i][pixel];
	      i++;
              if (pixel == debug_pixel) printf("subtract %d+%d - %d\n",image,image+1,image);

	      tagdiff[i][pixel] = (tagon[image+1][pixel] - (tagoff[image][pixel]+tagoff[image+1][pixel])/2);
	      mean_diff[pixel] +=  tagdiff[i][pixel];
	      i++;
              if (pixel == debug_pixel) printf("subtract %d - %d+%d\n",image+1,image,image+1);
            }
	    break;
	  }
	  // divide by # pairs of images
	  mean_diff[pixel] /= ndiff;

      } // end check noise threshold 
    } // end pixel loop    
    

    /* Write Images maps: */
    fdf_hdr.array_dim     = 1 + input.write_all*ndiff;
    fdf_hdr.slice_no      = slice + 1;
    fdf_hdr.array_index   = 1;
    fdf_hdr.display_order = 1;

    if (input.write_all) {
      for (image = 0; image < ndiff; image++) {
	// write tag difference image
	sprintf(filename,"%s/tagdiff_%03d_%03d.fdf",input.outdir,image+1,slice+1);
	write_fdf(filename,tagdiff[image],&fdf_hdr);
	fdf_hdr.array_index++;
	fdf_hdr.display_order++;
      }
    }

    sprintf(filename,"%s/diff_%s_%03d.fdf",input.outdir,input.method,slice+1);
    write_fdf(filename,mean_diff,&fdf_hdr);
    fdf_hdr.array_index++;
    fdf_hdr.display_order++;

  } // end slice loop
  
}
示例#30
0
static void
reset(void)
{
    int		sleeptime = 15;		/* for 'out of paper' etc. */
    int		senteof = FALSE;

/*
 *
 * We're all done sending the input files, so we'll send an EOF to the
 * printer and wait until it tells us it's done.
 *
 */


    logit("waiting for end of job\n");

    while (1)
    {
	switch (getstatus(2))
	{
	    case WAITING:
		write(ttyo, "\004", 1);
		senteof = TRUE;
		sleeptime = 15;
		break;

	    case ENDOFJOB:
		if (senteof == TRUE)
		{
		    logit("job complete\n");
		    return;
		}
		sleeptime = 15;
		break;

	    case BUSY:
	    case PRINTING:
		sleeptime = 15;
		sleep(1);
		break;

	    case PRINTERERROR:
		sleep(sleeptime++);
		break;

	    case ERROR:
		fprintf(stderr, "%s", mesg);	/* for csw */
		error(FATAL, "PostScript error");
		return;

	    case FLUSHING:
		error(FATAL, "PostScript error");
		return;

	    case IDLE:
		error(FATAL, "printer is idle");
		return;

	    case INITIALIZING:
		error(FATAL, "printer booting");
		return;

	    case DISCONNECT:
		error(FATAL, "printer appears to be offline");
		return;

	    default:
		sleep(1);
		break;

	}   /* End switch */

	if (sleeptime > 60)
	    sleeptime = 60;

    }	/* End while */

}   /* End of reset */