/**
 * \brief Perform a measurement at a certain focus position
 */
FocusValue	MeasureFocusWork::measureat(unsigned short pos) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "measurement at pos = %hu", pos);
	// move to the position
	focusingstatus(Focusing::MOVING);
	moveto(pos);

	// get an image
	focusingstatus(Focusing::MEASURING);
	ccd()->startExposure(exposure());
	ccd()->wait();
	ImagePtr	image = ccd()->getImage();

	// evaluate the image
	MeasureEvaluator	evaluator;
	double	value = evaluator(image);
	
	debug(LOG_DEBUG, DEBUG_LOG, 0, "pos = %hu, value = %g(%f)",
		pos, value, log10(value));

	// call the callback
	callback(evaluator.evaluated_image(), pos, value);

	// return the focus information
	return FocusValue(pos, value);
}
bool CCaliData::GetCaliCurveData_TypeA(int row, deque<CaliCurveData>& data) {
	int b=0,e=-1;
	GetComponentIndex(row, b, e);
	if (b > e) return false;
	for (int row=b; row<=e; ++row)
	{
		if (m_CaliItems[row].szContents==_T("")){
			data.clear();
			return false;
		}
		double dContents = _tstof(m_CaliItems[row].szContents);
		if (dContents==0.0000f) continue;

		if (m_tableType==_T("峰面积")) {
			double dPeakArea = _tstof(m_CaliItems[row].szPeakArea);
			CaliCurveData ccd(dContents, dPeakArea);                 
			data.push_back(ccd);
		}
		else if (m_tableType==_T("峰高")) {
			double dPeakHeight = _tstof(m_CaliItems[row].szPeakHeight);   
			CaliCurveData ccd(dContents, dPeakHeight);                 
			data.push_back(ccd);
		}
		else 
			return false;
	}
	return true;
}
/**
 * \brief Comparison operator for GuiderDescriptor objects
 */
bool	GuiderDescriptor::operator<(const GuiderDescriptor& other) const {
	if (name() < other.name()) {
		return true;
	}
	if (name() > other.name()) {
		return false;
	}
	if (instrument() < other.instrument()) {
		return true;
	}
	if (instrument() > other.instrument()) {
		return false;
	}
	if (ccd() < other.ccd()) {
		return true;
	}
	if (ccd() > other.ccd()) {
		return false;
	}
	if (guideport() < other.guideport()) {
		return true;
	}
	if (guideport() > other.guideport()) {
		return false;
	}
	return adaptiveoptics() < other.adaptiveoptics();
}
/**
 * \brief default main function for focusing
 */
void	FocusWork::main(astro::thread::Thread<FocusWork>& thread) {
	if (!complete()) {
		debug(LOG_ERR, DEBUG_LOG, 0,
			"FocusWork is not completely configured");
		focusingstatus(Focusing::FAILED);
		return;
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "starting focus process in [%d,%d]",
		min(), max());

	// prepare the set of focus items to base the focus computation on
	FocusItems	focusitems;

	// prepare 
	for (int step = 0; step < steps(); step++) {
		// find position
		unsigned short	position
			= min() + (step * (max() - min())) / (steps() - 1);
		debug(LOG_DEBUG, DEBUG_LOG, 0, "next position: %hu", position);

		// move to this position
		moveto(position);

		// get an image
		focusingstatus(Focusing::MEASURING);
		ccd()->startExposure(exposure());
		usleep(1000000 * exposure().exposuretime());
		ccd()->wait();
		ImagePtr	image = ccd()->getImage();
		debug(LOG_DEBUG, DEBUG_LOG, 0, "got an image of size %s",
			image->size().toString().c_str());

		// evaluate the image
		double	value = (*evaluator())(image);
		debug(LOG_DEBUG, DEBUG_LOG, 0, "evaluated to %f", value);

		// callback with the evaluated image
		callback(evaluator()->evaluated_image(), position, value);

		// add the information to a set
		focusitems.insert(FocusItem(position, value));
	}

	// now solve we need a suitable solver for the method
	int	targetposition = solver()->position(focusitems);
	if ((targetposition < min()) || (targetposition > max())) {
		std::string	msg = stringprintf(
			"could not find a focus position: %d", targetposition);
		debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str());
		focusingstatus(Focusing::FAILED);
		return;
	}

	// move to the final focus position
	focusingstatus(Focusing::MOVING);
	moveto(targetposition);
	focusingstatus(Focusing::FOCUSED);
}
Beispiel #5
0
int
agentconn::cagent_fd (bool required)
{
  if (agentfd >= 0)
    return agentfd;

  static rxx sockfdre ("^-(\\d+)?$");
  if (agentsock && sockfdre.search (agentsock)) {
    if (sockfdre[1])
      agentfd = atoi (sockfdre[1]);
    else
      agentfd = 0;
    if (!isunixsocket (agentfd))
      fatal << "fd specified with '-S' not unix domain socket\n";
  }
  else if (agentsock) {
    agentfd = unixsocket_connect (agentsock);
    if (agentfd < 0 && required)
      fatal ("%s: %m\n", agentsock.cstr ());
  }
  else if (ccd (false)) {
    int32_t res;
    if (clnt_stat err = ccd ()->scall (AGENT_GETAGENT, NULL, &res)) {
      if (required)
	fatal << "sfscd: " << err << "\n";
    }
    else if (res) {
      if (required)
	fatal << "connecting to agent via sfscd: " << strerror (res) << "\n";
    }
    else if ((agentfd = sfscdxprt->recvfd ()) < 0) {
      fatal << "connecting to agent via sfscd: "
	    << "could not get file descriptor\n";
    }
  }
  else {
    if (str sock = agent_usersock (true))
      agentfd = unixsocket_connect (sock);
    if (agentfd < 0 && required)
      fatal << "sfscd not running and no standalone agent socket\n";
  }
  return agentfd;
}
Beispiel #6
0
int main(int argc, char** argv)
{
	std::unique_ptr<WeatherData> wd (new WeatherData);
	std::unique_ptr<CurrentConditionsDisplay> ccd (new CurrentConditionsDisplay(*wd));
	
	wd->registerObserver(ccd.get());
	wd->setParameters(1,2,3);
	ccd->display();

	return 0;
}
void Animation::CyclicCoordinateDescent::convergeToward(Math::Vector3f target, float maxAngle)
{
	Math::Vector3f lastNodePosition(0.0f);
	lastNodePosition[0] = m_lastNode->getGlobalTransformation()(0, 3);
	lastNodePosition[1] = m_lastNode->getGlobalTransformation()(1, 3);
	lastNodePosition[2] = m_lastNode->getGlobalTransformation()(2, 3);

	Math::Vector3f constraint = target - lastNodePosition;

	ccd(constraint, maxAngle);
}
Beispiel #8
0
void CReal::Cancel()
{
	if (isRational)
	{
		unsigned int c=ccd(nRational.nNumerator,nRational.nDenominator);
		if (c>1)
		{
			nRational.nNumerator/=int(c);
			nRational.nDenominator/=c;
		}
		else if (nRational.nNumerator==0)
			nRational.nDenominator=1;
	}
}
/**
 * \brief Get a cooler from an instrument
 */
CoolerPtr	Instrument::cooler() {
	if (!isLocal(DeviceName::Cooler)) {
		throw std::runtime_error("not a local cooler");
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "retrieve Cooler for instrument '%s'",
		_name.c_str());
	Repository	repository;
	Devices	devices(repository);
	InstrumentComponentPtr	coolerptr = component(DeviceName::Cooler);
	switch (coolerptr->component_type()) {
	case InstrumentComponent::direct:
	case InstrumentComponent::mapped:
		return devices.getCooler(coolerptr->devicename());
	case InstrumentComponent::derived:
		break;
	}
	InstrumentComponentDerived	*from
		= dynamic_cast<InstrumentComponentDerived *>(&*coolerptr);
	if (from->derivedfrom() != DeviceName::Ccd) {
		throw std::runtime_error("only know how to derive from a ccd");
	}
	return ccd()->getCooler();
}
bool Animation::CyclicCoordinateDescent::solve(Math::Vector3f target, float maxAngle)
{
	Math::Vector3f constraint;
	Math::Vector3f lastPosition(0.0f);
	Math::Vector3f lastNodePosition(0.0f);

	do
	{
		lastNodePosition[0] = m_lastNode->getGlobalTransformation()(0, 3);
		lastNodePosition[1] = m_lastNode->getGlobalTransformation()(1, 3);
		lastNodePosition[2] = m_lastNode->getGlobalTransformation()(2, 3);
	
		if ((lastPosition-lastNodePosition).norm() < 0.001f)
			return false;

		lastPosition = lastNodePosition;
		constraint = target - lastNodePosition;

		ccd(constraint, maxAngle);
	} while(constraint.norm() > 0.1f);

	return true;
}
int main(int argc, char *argv[])
{
    int sockfd, portno, n;

    struct sockaddr_in serv_addr;
    struct hostent *server;

    char buffer[256], command[256], arg[256], *occur;
    if (argc < 3) {
       fprintf(stderr,"usage %s hostname port\n", argv[0]);
       exit(0);
    }
    portno = atoi(argv[2]);
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) 
        error("ERROR opening socket");
    server = gethostbyname(argv[1]);
    if (server == NULL) {
        fprintf(stderr,"ERROR, no such host\n");
        exit(0);
    }
    
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);    
    serv_addr.sin_port = htons(portno);
    if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) 
        error("ERROR connecting");

    printf(MAKE_RED_DARK"Start FTP Program\n"RESET_COLOR);
    printf(MAKE_YELLOW"1.Go 2. Exit\n"RESET_COLOR);
    printf(MAKE_GREEN_DARK"Enter UR Choice :: "RESET_COLOR);
    bzero(buffer,256);
    fgets(buffer,255,stdin);
    
    while(strcmp(buffer,"exit\n"))       //Keep getting command prompt till exit
    {
        system("clear");
        printf(MAKE_GREEN_DARK"\nSN   Command Name          Syntax"RESET_COLOR);
        printf("\n--------------------------------------------------");
    	printf("\n1.      get            get  <fileName>");
    	printf("\n2.      get            get  *.<fileExtension>");
    	printf("\n3.      mget           mget <fileName> <fileName> ");    	    	    	
    	printf("\n4.      put            put  <fileName>");
    	printf("\n5.      put            put  *.<fileExtension>");
    	printf("\n6.      mput           mput <fileName> <fileName> ");    	    	    	
    	printf("\n7.      lcd            lcd  <folderName> ");
    	printf("\n8.      cd             cd   <folderName> ");    	
    	printf("\n9.      lls            lls  ");
    	printf("\n10.     ls             ls   ");
    	printf("\n11.     pwd            pwd   ");
    	printf("\n12.     lpwd           lpwd   ");
    	printf("\n13.     exit           exit\n\n\n");    	    	    	
    	
    	
    	if(!strcmp(buffer,"\n"))
    		;
    	else if(!strcmp(buffer, "go\n"))
    	     ;    	    	
    	else if(!strcmp(buffer, "pwd\n"))
    	{
    	    n = write(sockfd,buffer,255);
   	    if (n < 0) 
        	error(MAKE_RED_DARK"ERROR writing to socket"RESET_COLOR);
	    //printf("%d\n",sockfd);            
    	    serPwd(sockfd);    	    	   
    	}
	else if(!strcmp(buffer, "lpwd\n"))
    	{
    	    char lPwd[256];
            printf(MAKE_GREEN_DARK"Present Working Directory-Client \n%s\n"RESET_COLOR, getcwd(lPwd, sizeof(lPwd)));  
    	}    	    	    	    	      	     
    	else if(!strcmp(buffer,"lcd\n"))
    		cd(NULL);	/*local cd*/
    	else if(!strcmp(buffer,"cd\n"))
    	{
    		n = write(sockfd,buffer,255);
    		if(n<0)
    		   error(MAKE_RED_DARK"ERROR writing to socket"RESET_COLOR);
    		ccd(sockfd);		
    	}
    	else if(!strcmp(buffer,"lls\n"))
    		ls();	/*local ls*/
    	else if(!strcmp(buffer,"ls\n"))
    	{		
	     n = write(sockfd,buffer,255);
   	     if (n < 0) 
        	error(MAKE_RED_DARK"ERROR writing to socket"RESET_COLOR);
	    // printf("%d\n",sockfd);
             lls(sockfd);
	}
    	else
    	{
    		bzero(command,256);
    		bzero(arg,256);	
    		occur=strchr(buffer,' ');
    		if(occur==NULL)
    		{
    			printf(MAKE_RED_DARK"\nEnter Command-->> "RESET_COLOR);
    			bzero(buffer,256);
    			fgets(buffer,255,stdin);
    			continue;
    		}
   		strcpy(command,buffer);
   		occur=strchr(command,' ');
   		if(occur==NULL)
    		{
    			printf(MAKE_RED_DARK"\nEnter Command-->> "RESET_COLOR);
    			bzero(buffer,256);
    			fgets(buffer,255,stdin);
    			continue;
    		}
   		*occur='\0';
   		strcpy(arg,occur+1);
   		occur=strchr(arg,'\n');
   		*occur='\0';
    		if(!strcmp(command,"get"))
    		{				
		     if((arg[0]=='*') && (arg[1]=='.'))
		     {
			bzero(buffer,256);
			strcpy(buffer,"getall ");
			strcat(buffer,arg);
			strcat(buffer,"\n");
			n = write(sockfd,buffer,255);
   			if (n < 0) 
        		    error(MAKE_RED_DARK"ERROR writing to socket"RESET_COLOR);
			getall(arg,sockfd);
		     }
		     else
		     {
			n = write(sockfd,buffer,255);
   			if (n < 0) 
        			error(MAKE_RED_DARK"ERROR writing to socket"RESET_COLOR);
			getfile(arg,sockfd);
		     }
    		}
		else if(!strcmp(command,"put"))
    		{
    		    if((arg[0]=='*') && (arg[1]=='.'))
			putall(arg,sockfd);
		    else
		    {
			n = write(sockfd,buffer,255);
   			if (n < 0) 
        		   error(MAKE_RED_DARK"ERROR writing to socket"RESET_COLOR);			
			putfile(arg,sockfd);
		    }	
    		}
		else if(!strcmp(command,"mget"))
			mgetfile(arg,sockfd);
		else if(!strcmp(command,"mput"))
    			mputfile(arg,sockfd);
    		else if(!strcmp(command,"lcd"))
    			cd(arg);
    		else if(!strcmp(command,"cd"))
    		{
		     n = write(sockfd,buffer,255);
   		     if (n < 0) 
        		error(MAKE_RED_DARK"ERROR writing to socket"RESET_COLOR);			
		     ccd(sockfd);	
    		}
    		else
    		    	printf("Enter Command-->> ");
  	}
  	
    	printf("Enter Command-->> ");
    	bzero(buffer,256);
    	fgets(buffer,255,stdin);

    } //End of while
    
    if(!strcmp(buffer,"exit\n"))
    {
       	n = write(sockfd,buffer,255);
   	if (n < 0) 
            error("ERROR writing to socket");
            
        bzero(buffer,256);
    	read(sockfd,buffer,18);	
        printf("%s\n-----Exit-----\n",buffer);
    }
    return 0;
}
/**
 * \brief Main function of the Focusing process
 */
void	VCurveFocusWork::main(astro::thread::Thread<FocusWork>& /* thread */) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "start focusing work");
	if (!complete()) {
		focusingstatus(Focusing::FAILED);
		throw std::runtime_error("focuser not completely specified");
	}

	FocusCompute	fc;

	// determine how many intermediate steps we want to access

	if (min() < focuser()->min()) {
		throw std::runtime_error("minimum too small");
	}

	// based on the exposure specification, build an evaluator
	ImageSize	size = exposure().size();
	int	radius = std::min(size.width(), size.height()) / 2;
	FWHM2Evaluator	evaluator(size.center(), radius);

	unsigned long	delta = max() - min();
	for (int i = 0; i < steps(); i++) {
		// compute new position
		unsigned short	position = min() + (i * delta) / (steps() - 1);
		debug(LOG_DEBUG, DEBUG_LOG, 0, "measuring position %hu",
			position);

		// move to new position
		moveto(position);
		
		// get an image from the Ccd
		focusingstatus(Focusing::MEASURING);
		ccd()->startExposure(exposure());
		usleep(1000000 * exposure().exposuretime());
		ccd()->wait();
		ImagePtr	image = ccd()->getImage();
		
		// turn the image into a value
		FWHMInfo	fwhminfo = focusFWHM2_extended(image,
					size.center(), radius);
		double	value = fwhminfo.radius;

		// add the new value 
		fc.insert(std::pair<unsigned short, double>(position, value));

		// send the callback data
		callback(combine(image, fwhminfo), position, value);
	}

	// compute the best focus position
	double	focusposition = 0;
	try {
		focusposition = fc.focus();
	} catch (std::exception& x) {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "no optimal focus position: %s",
			x.what());
		focusingstatus(Focusing::FAILED);
		return;
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "optimal focus position: %f",
		focusposition);

	// plausibility check for the position
	if (!((focusposition >= min()) && (focusposition <= max()))) {
		focusingstatus(Focusing::FAILED);
		debug(LOG_DEBUG, DEBUG_LOG, 0, "focusing failed");
		return;
	}

	// move to the focus position
	unsigned short	targetposition = focusposition;
	moveto(targetposition);
	focusingstatus(Focusing::FOCUSED);
	debug(LOG_DEBUG, DEBUG_LOG, 0, "target position reached");
}
Beispiel #13
0
bool CCaliData::GetCaliCurveData_TypeB(int row, deque<CaliCurveData>& data) {
                                                         //need refactoring
	//判断所有内标属性内是否存至少1个内标,否则无显示
	bool hasInterior=false;
	const int itemSize = m_CaliItems.size();
	for (int i=0; i<itemSize; ++i) {
		if (m_CaliItems[i].szIsInterior==_T("是")){
			hasInterior=true;
			break;
		}
	}
	if (!hasInterior) return false;

	
	//判断选中组份是否标记为内标
	int b=0,e=-1;
	GetComponentIndex(row, b, e);
	if (b > e) return false;
	//校正区域显示"无效校正曲线"或直接无显示
	if (m_CaliItems[b].szIsInterior==_T("是")) return false;
	//选中组份无内标编号的,不参与计算校正方程	
	if (m_CaliItems[b].szInteriorNo==_T(""))   return false;


	//那么找到同内标编号且同级别的内标
	CString cStrNo = m_CaliItems[b].szInteriorNo;
	const int itemNum = m_CaliItems.size();
	int bb=0,ee=0;
	for (int i=0; i<itemNum; ++i)
	{
		if (i>=b && i<=e) continue;
		if (m_CaliItems[i].szInteriorNo == cStrNo)
		{
			if (m_CaliItems[i].szIsInterior==_T("是"))
			{
				GetComponentIndex(i, bb, ee);
				break;
			}
		}
	}

	for (int row=b; row<=e; ++row)
	{
		CString cStrLv = m_CaliItems[row].szLevel;
		for (int irow = bb; irow<=ee; irow++)
		{
			if (m_CaliItems[irow].szLevel == cStrLv) //全匹配
			{
				if (m_CaliItems[row].szContents==_T("")||m_CaliItems[irow].szContents==_T("")){
					data.clear();
					return false;
				}
				double dContents_c = _tstof(m_CaliItems[row].szContents);
				double dContents_i = _tstof(m_CaliItems[irow].szContents);
				if (dContents_i==0.0000f) continue;
				double _x = dContents_c/dContents_i;
				double _y;
				if (m_tableType==_T("峰面积")) {
					double dPeakArea_c = _tstof(m_CaliItems[row].szPeakArea); 
					double dPeakArea_i = _tstof(m_CaliItems[irow].szPeakArea); 
					if (dPeakArea_i==0.0000f) continue;
					_y = dPeakArea_c/dPeakArea_i;
				} else if(m_tableType==_T("峰高")) {
					double dPeakHeight_c = _tstof(m_CaliItems[row].szPeakHeight); 
					double dPeakHeight_i = _tstof(m_CaliItems[irow].szPeakHeight); 
					if (dPeakHeight_i==0.0000f) continue;
					_y = dPeakHeight_c/dPeakHeight_i;
				} else {
					return false;
				}
				if (_x==0.0000f) continue;

				if (_x!=1.0000f || _y!=1.0000f) { //这里把原先&& 改成||
					CaliCurveData ccd(_x, _y);
					data.push_back(ccd);
				}
			}
		} 
	}
	return true;
}
main()
{
    char option;
    AbstractPizza* ap1;
    while( option != 'n' )
    {
        order o2;
        o2.incrementordernumber();
        o2.menu();
        int choice;
        cout<<"\n\t\t********ORDER NUMBER:\t"<<o2.returnordernumber()<<"**********\n";
        choice=5;
        while(!(choice>=1 && choice<=4))
            {
                cout<<"\nPlease Enter Your Choice between 1 & 4:\t\t";
                cin>>choice;
            }
            switch(choice)
            {
        case(1):
                ap1= new ChickenTikkaPizza;
        break;
        case(2):
                ap1= new BeefRoastPizza;
        break;
        case(3):
                ap1= new FourSeasonPizza;
        break;
        case(4):
                ap1= new HawiianPizza;
        break;
        }
        o2.inputperson();
        char choice2='l';
              
        do
        {
            cout<<"\nPlease enter c to pay via credit card and p to pay via cash:\t";
            fflush(stdin);
            cin>>choice2;
        }
        while(!(choice2=='c' || choice2=='p'));
        if(choice2=='c')      
        {
            o2.c1input();
            creditcard cca(12, 2004, 1111222);
            creditcard ccb(12, 2004, 1234567);
            creditcard ccc(12, 2004, 9876543);
            creditcard ccd(12, 2004, 1212121);
            system("cls");
            if( ( o2.comparecredit(cca) || o2.comparecredit(ccb) || o2.comparecredit(ccc) || o2.comparecredit(ccd) ) && ( o2.returnc1size() >= ap1->returnprice() ) )
            {
                cout<<"\n\n\n\n\n\n****Your Account Balance\t"<<o2.returnc1size()<<"\n****Your Order Cost\t\t"<<ap1->returnprice()<<"\n****Balance after transaction\t"<<o2.returnc1size()-ap1->returnprice() ;
                ap1->bake();
            }
            else
            {
                if(!( o2.comparecredit(cca) || o2.comparecredit(ccb) || o2.comparecredit(ccc) || o2.comparecredit(ccd) ))
                cout<<"\n\n\n\n\n\nINVALID CREDIT CARD NUMBER , ORDER COULD NOT BE PROCESSED";
                else if(! ( o2.returnc1size() >= ap1->returnprice() ) )
                cout<<"\n\n\n\n\n\nINSUFFICIENT FUNDS , ORDER COULD NOT BE PROCESSED";
            }
        }
        else
            cout<<"\nThanks for paying by CASH";
        choice2='l';
        o2.displayperson();
        fflush(stdin);
        option=getch();
    }
    delete ap1;
    return 0;
}
std::string	GuiderDescriptor::toString() const {
	return stringprintf("%s:%s|%s|%s", name().c_str(),
		instrument().c_str(), ccd().c_str(),
		guideport().c_str(), adaptiveoptics().c_str());
}
/**
 * \brief Equality operator for GuiderDescriptor objects
 */
bool	GuiderDescriptor::operator==(const GuiderDescriptor& other) const {
	return (instrument() == other.instrument())
		&& (ccd() == other.ccd())
		&& (guideport() == other.guideport());
}