Beispiel #1
0
///------------------------------------------------------------------------------
void mailbox::push(aid_t sender, message const& msg)
{
  recv_t rcv(sender);
  scope scp(boost::bind(&recv_queue_t::pop_back, &recv_que_));
  add_match_msg(rcv, sender, msg);
  scp.reset();
}
///----------------------------------------------------------------------------
aid_t coroutine_stackful_actor::recv(response_t res, message& msg, duration_t tmo)
{
  aid_t sender;

  recving_res_ = res;
  if (!mb_.pop(res, msg))
  {
    if (tmo > zero)
    {
      detail::scoped_bool<bool> scp(responsing_);
      if (tmo < infin)
      {
        start_recv_timer(tmo);
      }
      actor_code ac = yield();
      if (ac == actor_timeout)
      {
        return sender;
      }

      res = recving_res_;
      msg = recving_msg_;
      recving_res_ = response_t();
      recving_msg_ = message();
    }
    else
    {
      return sender;
    }
  }

  sender = res.get_aid();
  return sender;
}
Beispiel #3
0
///------------------------------------------------------------------------------
void mailbox::push(exit_t ex, message const& msg)
{
  recv_t rcv(ex);
  scope scp(boost::bind(&recv_queue_t::pop_back, &recv_que_));
  add_match_msg(rcv, ex.get_aid(), msg);
  scp.reset();
}
Beispiel #4
0
DWORD FileProcessor::Run(LPVOID /*arg*/)
{
	if( PP ){
	 FileEntry entry;
		nProcessed = 0;
		while( !PP->quitRequested() && (isBackwards ? PP->getBack(entry) : PP->getFront(entry)) ){
		 // create a scoped lock without closing it immediately
		 CRITSECTLOCK::Scope scp(PP->ioLock, 0);
			scope = &scp;
			currentEntry = &entry;
			_InterlockedIncrement(&PP->nProcessing);
			entry.compress( this, PP );
			_InterlockedDecrement(&PP->nProcessing);
			_InterlockedIncrement(&PP->nProcessed);
			currentEntry = NULL;
			nProcessed += 1;
			scope = NULL;

			runningTotalRaw += entry.fileInfo.st_size;
			runningTotalCompressed += (entry.compressedSize > 0)? entry.compressedSize : entry.fileInfo.st_size;
			/*if( PP->verbose() > 1 )*/{
#if defined(__MACH__)
                mach_port_t thread = mach_thread_self();
				mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
				thread_basic_info_data_t info;
				int kr = thread_info(thread, THREAD_BASIC_INFO, (thread_info_t) &info, &count);
				if( kr == KERN_SUCCESS ){
					 userTime = info.user_time.seconds + info.user_time.microseconds * 1e-6;
					 systemTime = info.system_time.seconds + info.system_time.microseconds * 1e-6;
					 avCPUUsage += info.cpu_usage * 100.0 / TH_USAGE_SCALE;
					 threadInfo = info;
					 hasInfo = true;
				}
				mach_port_deallocate(mach_task_self(), thread);
#elif defined(linux)
				struct rusage rtu;
				if (!getrusage(RUSAGE_THREAD, &rtu)) {
					const auto ut = rtu.ru_utime.tv_sec + rtu.ru_utime.tv_usec * 1e-6;
					const auto st = rtu.ru_stime.tv_sec + rtu.ru_stime.tv_usec * 1e-6;
					if (ut >= 0 && st >= 0) {
						userTime = ut, systemTime = st, hasInfo = true;
					}
				}
#	ifdef CLOCK_THREAD_CPUTIME_ID
				struct timespec ts;
				if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != -1) {
					cpuTime = ts.tv_sec + ts.tv_nsec * 1e-9;
					double t = userTime + systemTime;
					if (cpuTime > 0) {
						avCPUUsage += t * 100.0 / cpuTime;
					}
				}
#	endif
#endif
			}
		}
	}
	return DWORD(nProcessed);
}
void CurveDragPoint::dragged(Geom::Point &new_pos, GdkEventMotion *event)
{
    NodeList::iterator second = first.next();

    // special cancel handling - retract handles when if the segment was degenerate
    if (_is_drag_cancelled(event) && _segment_was_degenerate) {
        first->front()->retract();
        second->back()->retract();
        _pm.update();
        return;
    }

    if (_drag_initiated && !(event->state & GDK_SHIFT_MASK)) {
        SnapManager &m = _desktop->namedview->snap_manager;
        SPItem *path = static_cast<SPItem *>(_pm._path);
        m.setup(_desktop, true, path); // We will not try to snap to "path" itself
        Inkscape::SnapCandidatePoint scp(new_pos, Inkscape::SNAPSOURCE_OTHER_HANDLE);
        Inkscape::SnappedPoint sp = m.freeSnap(scp, Geom::OptRect(), false);
        new_pos = sp.getPoint();
        m.unSetup();
    }

    // Magic Bezier Drag Equations follow!
    // "weight" describes how the influence of the drag should be distributed
    // among the handles; 0 = front handle only, 1 = back handle only.
    double weight, t = _t;
    if (t <= 1.0 / 6.0) weight = 0;
    else if (t <= 0.5) weight = (pow((6 * t - 1) / 2.0, 3)) / 2;
    else if (t <= 5.0 / 6.0) weight = (1 - pow((6 * (1-t) - 1) / 2.0, 3)) / 2 + 0.5;
    else weight = 1;

    Geom::Point delta = new_pos - position();
    Geom::Point offset0 = ((1-weight)/(3*t*(1-t)*(1-t))) * delta;
    Geom::Point offset1 = (weight/(3*t*t*(1-t))) * delta;

    //modified so that, if the trace is bspline, it only acts if the SHIFT key is pressed
    if(!_pm._isBSpline()){
        first->front()->move(first->front()->position() + offset0);
        second->back()->move(second->back()->position() + offset1);
    }else if(weight>=0.8){
        if(held_shift(*event)){
            second->back()->move(new_pos);
        } else {
            second->move(second->position() + delta);
        }
    }else if(weight<=0.2){
        if(held_shift(*event)){
            first->back()->move(new_pos);
        } else {
            first->move(first->position() + delta);
        }
    }else{
        first->move(first->position() + delta);
        second->move(second->position() + delta);
    }
    _pm.update();
}
Beispiel #6
0
///------------------------------------------------------------------------------
void mailbox::push(request_t req, message const& msg)
{
  scope scp(boost::bind(&recv_queue_t::pop_back, &recv_que_));
  recv_t rcv(req);
  add_match_msg(rcv, aid_t(), msg);
  std::pair<wait_reply_list_t::iterator, bool> pr =
    wait_reply_list_.insert(std::make_pair(req.get_aid(), dummy_));
  pr.first->second.push_back(req);
  scp.reset();
}
///----------------------------------------------------------------------------
void coroutine_stackful_actor::resume(actor_code ac)
{
  detail::scope scp(boost::bind(&coroutine_stackful_actor::free_self, this));
  BOOST_ASSERT(yld_cb_);
  yld_cb_(ac);

  if (stat_ != off)
  {
    scp.reset();
  }
}
Beispiel #8
0
/*make argv a whole string*/
char *argstr(int argc, char *argv[], int f)
{
	char *str = malloc(slen(argv[f]));
	scp(argv[f], str);
	int i;
	for (i = f + 1; i < argc; i++) {
		str = realloc(str, slen(str) + slen(argv[i]) + 1);
		sadd(str, argv[i]);
	}
	return str;
}
Beispiel #9
0
void
ff_proc(feedforward ff)
{
    long            i, pl;

    for (pl = 0; pl < ff.nplanes - 1; pl++) {
        for (i = 0; i < ff.size[pl + 1]; i++) {
            ff.act[pl + 1][i] = ACTIVATION(ff.bias[pl][i]
                                           + scp(ff.wgt[pl][i], ff.act[pl], ff.size[pl]));
        }
    }
}
///----------------------------------------------------------------------------
aid_t coroutine_stackful_actor::recv(message& msg, match const& mach)
{
  aid_t sender;
  detail::recv_t rcv;

  if (!mb_.pop(rcv, msg, mach.match_list_))
  {
    duration_t tmo = mach.timeout_;
    if (tmo > zero)
    {
      detail::scoped_bool<bool> scp(recving_);
      if (tmo < infin)
      {
        start_recv_timer(tmo);
      }
      curr_match_ = mach;
      actor_code ac = yield();
      if (ac == actor_timeout)
      {
        return sender;
      }

      rcv = recving_rcv_;
      msg = recving_msg_;
      recving_rcv_ = detail::recv_t();
      recving_msg_ = message();
    }
    else
    {
      return sender;
    }
  }

  if (aid_t* aid = boost::get<aid_t>(&rcv))
  {
    sender = *aid;
  }
  else if (detail::request_t* req = boost::get<detail::request_t>(&rcv))
  {
    sender = req->get_aid();
    msg.req_ = *req;
  }
  else if (detail::exit_t* ex = boost::get<detail::exit_t>(&rcv))
  {
    sender = ex->get_aid();
  }

  return sender;
}
Beispiel #11
0
bool
MoveSCU
::_handle_store_association(DcmtkAssociation & association, Callback callback) const
{
    bool result = false;
    try
    {
        auto const store_callback = [&callback](message::CStoreRequest const & request) {
            callback(request.get_data_set());
            return message::Response::Success;
        };
        StoreSCP scp(this->_network, &association, store_callback);
        scp.receive_and_process();
    }
    catch(Exception const &)
    {
        result = true;
    }

    return result;
}
Beispiel #12
0
	void mvType::init(const mv &X, mv::Float epsilon, bool useAlgebraMetric, int guCnt) {
		mv rX = reverse(X);

		// test if null:
		mv Sq = (useAlgebraMetric) ? scp(X, rX) : scp(X, rX);
		Sq.compress(epsilon);
		if (_Float(Sq) == 0) {
			// X = multivector, case closed
			m_type = MULTIVECTOR;
			return;
		}

		// versor inverse must be true inverse:
		mv Xvi = (useAlgebraMetric) ? inverse(X) : inverse(X);
		mv Xgi = gradeInvolution(X);

		// check if (Xgi Xvi) is a scalar:
		mv XgiXvi = (useAlgebraMetric) ? gp(Xgi, Xvi) : gp(Xgi, Xvi);
		{
			mv tmp = XgiXvi;
			tmp.compress(epsilon);
			if (tmp.gu() != GRADE_0) { // if not scalar:
				// X = multivector, case closed
				m_type = MULTIVECTOR;
				return;
			}
		}

		// check if Xgi Xvi == Xvi Xgi
		mv XviXgi = (useAlgebraMetric) ? gp(Xvi, Xgi) : gp(Xvi, Xgi);
		{
			mv tmp = XviXgi - XgiXvi;
			tmp.compress(epsilon); // this should result in 0
			if (tmp.gu()) {
				// if not:
				// X = multivector, case closed
				m_type = MULTIVECTOR;
				return;
			}
		}

		// check if grade preserving for all basis vectors:
		{
			{
				// test e1		
				mv tmp = (useAlgebraMetric) ? gp(gp(Xvi, e1), Xgi) : gp(gp(Xvi, e1), Xgi);
				tmp.compress(epsilon);
				if (tmp.gu() != GRADE_1) { // X = multivector, case closed
					m_type = MULTIVECTOR;
					return;
				}
			}
			{
				// test e2		
				mv tmp = (useAlgebraMetric) ? gp(gp(Xvi, e2), Xgi) : gp(gp(Xvi, e2), Xgi);
				tmp.compress(epsilon);
				if (tmp.gu() != GRADE_1) { // X = multivector, case closed
					m_type = MULTIVECTOR;
					return;
				}
			}
		}

		// if homogeneous: blade
		if (guCnt == 1) m_type = BLADE;
		else m_type = VERSOR;
	}
Beispiel #13
0
///----------------------------------------------------------------------------
void conn::run(
  gce::self_t self, socket_ptr skt,
  gce::aid_t group_aid, app_ctxid_list_t game_list
  )
{
  try
  {
    gce::yield_t yield = self.get_yield();

    gce::detail::scope scp(boost::bind(&tcp_socket::close, skt));
    gce::response_t res =
      gce::request(
        self, group_aid,
        gce::atom("add_conn")
        );
    gce::message msg;
    self.recv(res, msg);
    if (msg.get_type() != gce::atom("ok"))
    {
      throw std::runtime_error("add_conn error");
    }

    gce::detail::scope quit_scp(
      boost::bind(
        &quit_callback, boost::ref(self), group_aid
        )
      );

    gce::aid_t tmo_aid =
      gce::spawn(
        self,
        boost::bind(&conn::timeout, _1),
        gce::linked
        );

    gce::aid_t recv_aid =
      gce::spawn(
        self,
        boost::bind(
          &conn::recv, _1, skt,
          tmo_aid, self.get_aid(), game_list
          ),
        gce::linked,
        true
        );

    bool running = true;
    while (running)
    {
      gce::message msg;
      gce::aid_t sender = self.recv(msg);
      gce::match_t type = msg.get_type();
      if (type == gce::exit || type == gce::atom("stop"))
      {
        running = false;
      }
      else if (type == gce::atom("fwd_msg"))
      {
        gce::message m;
        msg >> m;
        skt->send(m, yield);
      }
      else
      {
        std::string errmsg("conn::run unexpected message, type: ");
        errmsg += gce::atom(type);
        throw std::runtime_error(errmsg);
      }
    }
static void cintrp_expand(char **p, int s, int e, const int *cv)
{
  int i;
  for(i=s; i<e;) {
    switch(parse_res[i].id) {
    case -1:
      scp(p, i);
      break;

    case PA:
      if(cv[IxSFAO])
	scs(p, "(s->aacc << 7)");
      else
	scs(p, "s->aacc");
      break;

    case PC: {
      const char *r = NULL;
      if(cv[IxCMODE] == 0)
	r = "s->cmem[i->param]";
      else if(cv[IxCMODE] == 1)
	r = "s->cmem[s->ca]";
      else if(cv[IxCMODE] == 2)
	r = "s->cmem[s->ca++]";
      else
	abort();

      if(cv[IxCRM] == 0 || cv[IxCRM] == 3)
	scs(p, r);
      else if(cv[IxCRM] == 1) {
	scs(p, "(");
	scs(p, r);
	scs(p, " & 0xffff0000)");
      } else if(cv[IxCRM] == 2) {
	scs(p, "(");
	scs(p, r);
	scs(p, " << 16)");
      } else
	abort();
      break;
    }

    case PD:
      if(cv[IxDMODE] == 0)
	if(cv[IxDBP])
	  scs(p, "(s->dmem1[(i->param + s->ba1) & 0x1f] << 8)");
	else
	  scs(p, "(s->dmem0[(i->param + s->ba0) & 0xff] << 8)");
      else if(cv[IxDMODE] == 1)
	if(cv[IxDBP])
	  scs(p, "(s->dmem1[(s->id + s->ba1) & 0x1f] << 8)");
	else
	  scs(p, "(s->dmem0[(s->id + s->ba0) & 0xff] << 8)");
      else if(cv[IxDMODE] == 2)
	if(cv[IxDBP])
	  scs(p, "(s->dmem1[((s->id++) + s->ba1) & 0x1f] << 8)");
	else
	  scs(p, "(s->dmem0[((s->id++) + s->ba0) & 0xff] << 8)");
      else
	abort();
      break;

    case PI:
      scs(p, "i->param");
      break;

    case PD24:
      if(cv[IxDMODE] == 0)
	if(cv[IxDBP])
	  scs(p, "s->dmem1[(i->param + s->ba1) & 0x1f]");
	else
	  scs(p, "s->dmem0[(i->param + s->ba0) & 0xff]");
      else if(cv[IxDMODE] == 1)
	if(cv[IxDBP])
	  scs(p, "s->dmem1[(s->id + s->ba1) & 0x1f]");
	else
	  scs(p, "s->dmem0[(s->id + s->ba0) & 0xff]");
      else if(cv[IxDMODE] == 2)
	if(cv[IxDBP])
	  scs(p, "s->dmem1[((s->id++) + s->ba1) & 0x1f]");
	else
	  scs(p, "s->dmem0[((s->id++) + s->ba0) & 0xff]");
      else
	abort();
      break;

    case PML:
      if(cv[IxSFMA] == 0)
	scs(p, "s->macc");
      else if(cv[IxSFMA] == 1)
	scs(p, "(s->macc << 2)");
      else if(cv[IxSFMA] == 2)
	scs(p, "(s->macc << 4)");
      else if(cv[IxSFMA] == 3)
	scs(p, "(s->macc >> 16)");
      else
	abort();
      break;

    case PMO: {
      static const long long rounding[8] = {
	0,
	1LL << (48-32-1),
	1LL << (48-24-1),
	1LL << (48-30-1),
	1LL << (48-16-1),
	0, 0, 0
      };
      static const unsigned long long rmask[8] = {
	~0ULL,
	(~0ULL) << (48-32),
	(~0ULL) << (48-24),
	(~0ULL) << (48-30),
	(~0ULL) << (48-16),
	~0ULL, ~0ULL, ~0ULL
      };

      char r[256];
      sprintf(r, "tms57002_macc_to_output_%d%s(s, 0x%016" I64FMT "xULL, 0x%016" I64FMT "xULL)", cv[IxSFMO], cv[IxMOVM] ? "s" : "", rounding[cv[IxRND]], rmask[cv[IxRND]]);
      scs(p, r);
      break;
    }

    case PMV: {
      char r[256];
      sprintf(r, "tms57002_check_macc_overflow_%d%s(s)", cv[IxSFMO], cv[IxMOVM] ? "s" : "");
      scs(p, r);
      break;
    }

    case PB:
      scs(p, "s->pc = ");
      cintrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1], cv);
      scs(p, ";\n");
      scs(p, "  s->sti |= S_BRANCH");
      break;

    case PWA:
      scs(p, "r = ");
      cintrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1], cv);
      scs(p, ";\n");
      scs(p, "  if(r < -0x80000000 || r > 0x7fffffff)\n");
      scs(p, "    s->st1 |= ST1_AOV;\n");
      scs(p, "  s->aacc = r");
      break;

    case PWC:
      if(cv[IxCMODE] == 0)
	scs(p, "s->cmem[i->param] = ");
      else if(cv[IxCMODE] == 1)
	scs(p, "s->cmem[s->ca] = ");
      else if(cv[IxCMODE] == 2)
	scs(p, "s->cmem[s->ca++] = ");
      else
	abort();

      cintrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1], cv);
      break;

    case PWD:
      if(cv[IxDMODE] == 0)
	if(cv[IxDBP])
	  scs(p, "s->dmem1[(i->param + s->ba1) & 0x1f] = ");
	else
	  scs(p, "s->dmem0[(i->param + s->ba0) & 0xff] = ");
      else if(cv[IxDMODE] == 1)
	if(cv[IxDBP])
	  scs(p, "s->dmem1[(s->id + s->ba1) & 0x1f] = ");
	else
	  scs(p, "s->dmem0[(s->id + s->ba0) & 0xff] = ");
      else if(cv[IxDMODE] == 2)
	if(cv[IxDBP])
	  scs(p, "s->dmem1[((s->id++) + s->ba1) & 0x1f] = ");
	else
	  scs(p, "s->dmem0[((s->id++) + s->ba0) & 0xff] = ");
      else
	abort();

      cintrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1], cv);
      break;

    case SFAI:
      cintrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1], cv);
      scs(p, " = ");
      if(cv[IxSFAI])
	scs(p, "((INT32)(");
      cintrp_expand(p, parse_res[i].ppos[1], parse_res[i].ppos[2], cv);
      if(cv[IxSFAI])
	scs(p, ")) >> 1");
      break;
    }

    if(parse_res[i].id == -1)
      i++;
    else
      i = parse_res[i].ppos[parse_res[i].pcount];
  }
}
static void intrp_expand(char **p, int s, int e)
{
  int i;
  for(i=s; i<e;) {
    switch(parse_res[i].id) {
    case -1:
      scp(p, i);
      break;

    case PA:
      scs(p, "tms57002_aacc_to_output(s)");
      break;

    case PC:
      scs(p, "tms57002_opc_read_c(s, opcode)");
      break;

    case PD:
      scs(p, "(tms57002_opc_read_d(s, opcode) << 8)");
      break;

    case PI:
      scs(p, "(opcode & 0xff)");
      break;

    case PD24:
      scs(p, "tms57002_opc_read_d(s, opcode)");
      break;

    case PML:
      scs(p, "tms57002_macc_to_loop(s)");
      break;

    case PMO:
      scs(p, "tms57002_macc_to_output(s)");
      break;

    case PMV:
      scs(p, "tms57002_check_macc_overflow(s)");
      break;

    case PB:
      scs(p, "s->pc = ");
      intrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1]);
      scs(p, ";\n");
      scs(p, "  s->sti |= S_BRANCH");
      break;

    case PWA:
      scs(p, "r = ");
      intrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1]);
      scs(p, ";\n");
      scs(p, "  if(r < -0x80000000 || r > 0x7fffffff)\n");
      scs(p, "    s->st1 |= ST1_AOV;\n");
      scs(p, "  s->aacc = r");
      break;

    case PWC:
      scs(p, "tms57002_opc_write_c(s, opcode, ");
      intrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1]);
      scs(p, ")");
      break;

    case PWD:
      scs(p, "tms57002_opc_write_d(s, opcode, ");
      intrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1]);
      scs(p, ")");
      break;

    case SFAI:
      intrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1]);
      scs(p, " = ");
      intrp_expand(p, parse_res[i].ppos[1], parse_res[i].ppos[2]);
      scs(p, ";\n");
      scs(p, "  if(s->st1 & ST1_SFAI)\n");
      scs(p, "    ");
      intrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1]);
      scs(p, " = ((INT32)");
      intrp_expand(p, parse_res[i].ppos[0], parse_res[i].ppos[1]);
      scs(p, ") >> 1");
      break;
    }

    if(parse_res[i].id == -1)
      i++;
    else
      i = parse_res[i].ppos[parse_res[i].pcount];
  }
}
static void save_dasm_cat(FILE *f, const char *def, instr *il, int count)
{
  static const pdesc pp[] = {
    { "c", 0, PC },
    { "d", 0, PD },
    { "i", 0, PI },
    { 0 }
  };

  int i;
  fprintf(f, "#ifdef %s\n", def);
  for(i=0; i != count; i++)
    if(il[i].name) {
      int par[3];
      int pc = 0;
      int j;
      char buf[4096], *p = buf;
      parse(il[i].dasm, pp);
      for(j=0; j<parse_count;j++) {
	switch(parse_res[j].id) {
	case -1:
	  scp(&p, j);
	  break;
	case PC:
	  scs(&p, "%s");
	  par[pc++] = PC;
	  break;
	case PD:
	  scs(&p, "%s");
	  par[pc++] = PD;
	  break;
	case PI:
	  scs(&p, "%02x");
	  par[pc++] = PI;
	  break;
	}
      }
      *p = 0;

      fprintf(f, "    case 0x%02x:\n", i);
      fprintf(f, "      sprintf(buf, \"%s\"", buf);
      for(j=0; j != pc; j++)
	switch(par[j]) {
	case PC:
	  fprintf(f, ", tms57002_get_memadr(opcode, 'c')");
	  break;
	case PD:
	  fprintf(f, ", tms57002_get_memadr(opcode, 'd')");
	  break;
	case PI:
	  fprintf(f, ", opcode & 0xff");
	  break;
	}


      fprintf(f, ");\n");
      fprintf(f, "      break;\n");
      fprintf(f, "\n");
    }

  fprintf(f, "#endif\n\n");
}
Beispiel #17
0
        /* NP */
short ww_type(short *wwtype, short *dcp)
        /********************************************************************/
        /*      Watch type guidance                                         */
        /*      A decision tree to help with ww issuance                    */
        /*                                                                  */
        /*      Rich Thompson SPC OUN                                       */
        /********************************************************************/
        {
        float ix1, ix2, ix3, ix4, lr75, shr6, t500, fzlh, mumixr, lowrh, midrh, low_mid_rh;
        float mucn, mlcn, mlcp, sbcp, mucp, lr1, lr3, shr6_dir, sr46_dir, sr46_spd, shr6_sr46_diff, mmp;
        float sig_tor, sig_tor_winter, sighail, wind_dmg, rm_scp, cbsig, dncp, srh1, sblcl, mllcl;
        float oldlplpres, pres, pbot, ptop, shr8, bot, top, esrh, lm_scp;
        short oldlplchoice, ww_choice;
        short pIndex, tIndex, zIndex, tdIndex;
        short x1, y1, x2, y2, tlx, tly, wid;
        struct _parcel pcl;
        char st[40];

        tlx = hov.tlx + 409;
        tly = hov.bry;
        wid = 119;

        setcliprgn( tlx+2, tly+2, tlx+wid+24, tly+wid+1);
        setcolor(0);
        setlinestyle( 1, 1 );
        rectangle( 1,tlx, tly, tlx+wid+27, tly+wid+1);
        setcolor(1);
        rectangle( 0, tlx, tly, tlx+wid+27, tly+wid+1);
        setlinestyle( 1, 1 );
        moveto( tlx + 2, tly + 18);
	lineto(tlx + wid + 27, tly + 18);


        /* ----- Plot Label ----- */
        set_font(6);
        setcolor(1);
        outgtext( "Psbl Watch Type", tlx + 20, tly + 3 );

	*wwtype = 0;
	*dcp = 0;

        oldlplchoice = lplvals.flag;

        tIndex = getParmIndex("TEMP");
        pIndex = getParmIndex("PRES");
        zIndex = getParmIndex("HGHT");
        tdIndex = getParmIndex("DWPT");

/* 24 Mar 2008 */
/*        effective_inflow_layer(100, -250, &pbot, &ptop);*/

	/* sb parcel */
        define_parcel(1,0);
        ix1 = parcel(-1, -1, lplvals.pres, lplvals.temp, lplvals.dwpt, &pcl);
        sbcp = pcl.bplus;
        sblcl = agl(i_hght(pcl.lclpres, I_PRES));
        sig_tor_winter = sigtorn_fixed(st_dir, st_spd);

	/* ml parcel */
        define_parcel(4,100);
        ix1 = parcel(-1, -1, lplvals.pres, lplvals.temp, lplvals.dwpt, &pcl);
        mlcn = pcl.bminus;
        mlcp = pcl.bplus;
        mllcl = agl(i_hght(pcl.lclpres, I_PRES));
        sig_tor = sigtorn_cin(st_dir, st_spd);

	/* mu parcel */
        define_parcel(3,400);
        mucp = parcel(-1, -1, lplvals.pres, lplvals.temp, lplvals.dwpt, &pcl);
        mucn = pcl.bminus;

	dncp = dcape(&ix1, &ix2);

	/* sighail ingredients */
        lr75 = lapse_rate(&ix1, 700, 500);
        wind_shear(sndg[sfc()][pIndex], i_pres(msl(6000)), &ix1, &ix2, &ix3, &ix4);
        shr6 = ix4;
        shr6_dir = ix3;
        wind_shear(sndg[sfc()][pIndex], i_pres(msl(8000)), &ix1, &ix2, &ix3, &ix4);
	shr8 = ix4;
        mumixr = mixratio(lplvals.pres, lplvals.dwpt);
        t500 =  i_temp(500, I_PRES);
        fzlh = mtof(agl(i_hght(temp_lvl(0, &ix1), I_PRES)));
        sighail = sig_hail(pcl.bplus, mumixr, lr75, t500, kt_to_mps(shr6), fzlh, pcl.bminus, 0, 0, 25, mlcp);

        rm_scp = scp(st_dir, st_spd);
        wind_dmg = damaging_wind();

        sr_wind( i_pres(msl(4000)), i_pres(msl(6000)), st_dir, st_spd, &ix1, &ix2, &ix3, &ix4);
        sr46_dir = ix3;
        sr46_spd = ix4;
        shr6_sr46_diff = (shr6_dir - sr46_dir);
	srh1 = helicity(0, 1000, st_dir, st_spd, &ix1, &ix2);
	bot = agl(i_hght(p_bot, I_PRES));
	top = agl(i_hght(p_top, I_PRES));	
	esrh = helicity(bot, top, st_dir, st_spd, &ix1, &ix2);

        lapse_rate(&ix2, sndg[sfc()][pIndex], i_pres(sndg[sfc()][zIndex]+1000));
        lr1 = ix2;
        lapse_rate(&ix2, sndg[sfc()][pIndex], i_pres(sndg[sfc()][zIndex]+3000));
        lr3 = ix2;

        mean_relhum(&ix1, sndg[sfc()][pIndex]-150, sndg[sfc()][pIndex]-350);
        midrh = ix1;
        mean_relhum(&ix1, sndg[sfc()][pIndex], sndg[sfc()][pIndex]-150);
        lowrh = ix1;
        low_mid_rh = ((lowrh + midrh)/2);
        mmp = coniglio1();
        cbsig = (mlcp * kt_to_mps(shr6));

/* 24 Mar 2008 */
/* all "p_bot" below were changed from "pbot" */

/* Decision tree below is identical to the operational "ww_type" flow chart documentation 9/23/09 RLT */
        if ((sig_tor >= 3.0) && (sig_tor_winter >= 3.0) && (srh1 >= 150) && (esrh >= 150) && (sr46_spd >= 15.0) && (shr8 >= 40.0) && (sblcl < 1000) && (mllcl < 1100) && (lr1 >= 5.0) && (bot == 0.0)) {
		*dcp = 1;
		*wwtype = 5;
                ww_choice = 5;
        	/*printf("\n dcp (in PDS) = %d", *dcp);*/
        	set_font(6);
        	setcolor(7);
        	outgtext( "PDS TOR", tlx + 45, tly + 60 );
                }

/*        else
        if ((sig_tor_winter >= 4.0) && (sr46_spd >= 15.0) && (shr8 >= 40.0) && (sblcl < 1000) && (lr1 >= 5.0) && (bot == 0.0)) {
                *dcp = 2;
                *wwtype = 5;
                ww_choice = 5;
                set_font(6);
                setcolor(7);
                outgtext( "PDS TOR", tlx + 45, tly + 60 );
                }
*/	
        else
        if (((sig_tor >= 3.0) || (sig_tor_winter >= 4.0)) && (bot == 0.0)) {
                *dcp = 3;
                *wwtype = 4;
                ww_choice = 4;
                /*printf("\n dcp (in TOR) = %d", *dcp);*/
                set_font(6);
                setcolor(2);
                outgtext( "TOR", tlx + 45, tly + 60 );
                }
	
        else
        if (((sig_tor >= 1.0) || (sig_tor_winter >= 1.0)) && ((sr46_spd >= 15.0) || (shr8 >= 40.0)) && (bot == 0.0)) {
                *dcp = 4;
                *wwtype = 4;
                ww_choice = 4;
                /*printf("\n dcp (in TOR) = %d", *dcp);*/
                set_font(6);
                setcolor(2);
                outgtext( "TOR", tlx + 45, tly + 60 );
                }

        else
        if (((sig_tor >= 1.0) || (sig_tor_winter >= 1.0)) && (low_mid_rh >= 60) && (lr1 >= 5.0) && (bot == 0.0)) {
                *dcp = 5;
                *wwtype = 4;
                ww_choice = 4;
                /*printf("\n dcp (in TOR) = %d", *dcp);*/
                set_font(6);
                setcolor(2);
                outgtext( "TOR", tlx + 45, tly + 60 );
                }

        else
        if ((( sig_tor >= 1.0) || (sig_tor_winter >= 1.0)) && (bot == 0.0)) {
                *dcp = 6;
                *wwtype = 3;	
                ww_choice = 3; 
                /*printf("\n dcp (in mrgl TOR) = %d", *dcp);*/
	        set_font(6);
                setcolor(2);
                outgtext( "mrgl TOR", tlx + 40, tly + 60 );
                }

        else
        if (((( sig_tor >= 0.5) && (esrh >= 150)) || ((sig_tor_winter >= 0.5) && (srh1 >= 150))) && (bot == 0.0)) {
                *dcp = 7;
                *wwtype = 3;	
                ww_choice = 3;
                /*printf("\n dcp (in mrgl TOR) = %d", *dcp);*/
                set_font(6);
                setcolor(2);
                outgtext( "mrgl TOR", tlx + 40, tly + 60 );
                }

        else
        if ((( sig_tor_winter >= 1.0) || (rm_scp >= 4.0) || (sig_tor >= 1.0)) && (mucn >= -50.0)) {
                *dcp = 8;
                *wwtype = 2;
                ww_choice = 2;
                /*printf("\n dcp (in SVR) = %d", *dcp);*/
	        set_font(6);
                setcolor(6);
                outgtext( "SVR",  tlx + 60, tly + 60 );
                }

        else
        if ((rm_scp >= 2.0) && ((sighail >= 1.0) || (dncp >= 750)) && (mucn >= -50.0)) {
                *dcp = 9;
                *wwtype = 2;
                ww_choice = 2;
                /*printf("\n dcp (in SVR) = %d", *dcp);*/
                set_font(6);
                setcolor(6);
                outgtext( "SVR",  tlx + 60, tly + 60 );
                }

        else
        if ((cbsig >= 30000) && (mmp >= 0.6) && (mucn >= -50.0)) {
                *dcp = 10;
                *wwtype = 2;
                ww_choice = 2;
                /*printf("\n dcp (in SVR) = %d", *dcp);*/
                set_font(6);
                setcolor(6);
                outgtext( "SVR",  tlx + 60, tly + 60 );
                }
        
	else
        if ((mucn >= -75.0) && ((wind_dmg >= 0.5) || (sighail >= 0.5) || (rm_scp >= 0.5)))  {
                *dcp = 11;
                *wwtype = 1;
                ww_choice = 1;
                /*printf("\n dcp (in mrgl SVR) = %d", *dcp);*/
	        set_font(6);
                setcolor(26);
                outgtext( "MRGL SVR",  tlx + 40, tly + 60 );
                }
        else    {
                *dcp = 0;
                /*printf("\n dcp (after logic checks) = %d", *dcp);*/
                *wwtype = 0;
                ww_choice = 0;
		}

        if (*wwtype == 0) {
                set_font(6);
                setcolor(19);
                outgtext( "NONE",  tlx + 50, tly + 60 );
                }
    	//printf("sig_tor=%f sig_tor_winter=%f srh1=%f esrh=%f sr46_spd=%f shr8=%f sblcl=%f\n mllcl=%f lr1=%f bot=%f low_mid_rh=%f rm_scp=%f\n mucn=%f dncp=%f sighail=%f cbsig=%f wind_dmg=%f",
    	//		sig_tor,sig_tor_winter,srh1,esrh,sr46_spd,shr8, sblcl, mllcl, lr1, bot, low_mid_rh, rm_scp,mucn, dncp, sighail, cbsig, wind_dmg);

/*      define_parcel(oldlplchoice, oldlplpres); */
        
        /* set parcel back to user selection */
        if (oldlplchoice == 1)
          pres = 0;
        else if (oldlplchoice == 2)
          pres = 0;
        else if (oldlplchoice == 3)
          pres = mu_layer;
        else if (oldlplchoice == 4)
          pres = mml_layer;
        else if (oldlplchoice == 5)
          pres = user_level;
        else if (oldlplchoice == 6)
          pres = mu_layer;
        define_parcel(oldlplchoice, pres);

        return ww_choice;

        }