Example #1
0
  bool GboxInstance::HandleKeyboard(const pp::KeyboardInputEvent& event) {
    uint32_t key = event.GetKeyCode();
    uint32_t type = event.GetType();
    uint32_t mods = 0; // event.GetModifiers();

    theLog.info("+Input Keyboard: ty:%d mods:%d key:%d/%c (sca:%d)", 
        type, mods, key, key, m_key_shift);

    if (type == 9) return false; // not sure what this is for

    if (key == 16) { // shift
      if (type == 7) m_key_shift = true;
      if (type == 8) m_key_shift = false;
      return true;
    }
    if (key == 17) { // ctrl
      if (type == 7) m_key_ctrl = true;
      if (type == 8) m_key_ctrl = false;
      return true;
    }
    if (key == 18) { // alt
      if (type == 7) m_key_alt = true;
      if (type == 8) m_key_alt = false;
      return true;
    }
    if (key == 91) { // left apple
      if (type == 7) m_key_left_apple = true;
      if (type == 8) m_key_left_apple = false;
      return true;
    }
    if (key == 93) { // right apple
      if (type == 7) m_key_right_apple = true;
      if (type == 8) m_key_right_apple = false;
      return true;
    }

    if (type == 7) m_down_sca = sca(); // shift-ctrl-alt on only keydown matters

    const char *dc = key < 223 ? display_codes[key] : "";
    const char *cc = key < 223 ? control_codes[key] : "";
    const char *co = key < 223 ? codes[key] : "";

    theLog.info("%d/ dc: '%s'  cc: '%s'  co: '%s'", key, dc, cc, co);

    if (type == 8) {
      if (strlen(co)) {
        Key(key, m_down_sca, dc, cc, co);
        return true;
      }
    }
    if (key == 8 || key == 9 || key == 13 || key == 27 || key == 37 || key == 38) {
      return true;
    }

    //if (type != 7)
    //  theLog.info("+Input Keyboard: et:%d key:%d/%c (unhandled)", type, key, key);

    return false;
  }
Example #2
0
  bool GboxInstance::HandleMouse(const pp::MouseInputEvent& event) {
    PP_InputEvent_MouseButton button = event.GetButton();
    int32_t clicks = event.GetClickCount();
    pp::Point pt = event.GetPosition();
    int32_t type = event.GetType();

    if (sca() == 0x3)
      theLog.info("+Mouse:  ty:%d at:%d,%d but:%d clicks:%d",
            type, pt.x(), pt.y(), button, clicks);

    if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN && button == 0) {
      m_mouse_down0 = pt;
      m_time_at_mouse_down0 = m_core->GetTimeTicks();
    }
    if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN && button == 2) {
      m_mouse_down2 = pt;
      m_time_at_mouse_down2 = m_core->GetTimeTicks();
    }
    if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEMOVE) {
      if (m_time_at_mouse_down0) {
        // drag dynamics logic
        PP_TimeTicks now = m_core->GetTimeTicks();
        bool is_drag = false;
        double dx = pt.x() - m_mouse_down0.x();
        double dy = pt.y() - m_mouse_down0.y();
        if (sqrt(dx * dx + dy * dy) > 30) is_drag = true;
        if (now - m_time_at_mouse_down0 > 0.2) is_drag = true;
        if (is_drag) {
          Drag(m_mouse_down0.x(), m_mouse_down0.y(),
                    m_mouse_down0.x() - pt.x(), m_mouse_down0.y() - pt.y(), sca());
          m_mouse_down0 = pt;
        }
      }
    }
    if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEUP) {
      PP_TimeTicks now = m_core->GetTimeTicks();
      double diff = now - (button == 0 ? m_time_at_mouse_down0 : m_time_at_mouse_down2);
      Click(pt.x(), pt.y(), button, sca(), diff);

      if (button == 0)
        m_time_at_mouse_down0 = 0;
      else
        m_time_at_mouse_down2 = 0;
    }
    return true;
  }
void ScrAddrFilter::checkForMerge()
{
   if (mergeFlag_ == true)
   {
      /***
      We're about to add a set of newly registered scrAddrs to the BDM's
      ScrAddrFilter map. Make sure they are scanned up to the last known
      top block first, then merge it in.
      ***/

      //create SAF to scan the addresses to merge
      std::shared_ptr<ScrAddrFilter> sca(copy());
      for (auto& scraddr : scrAddrDataForSideScan_.scrAddrsToMerge_)
         sca->scrAddrMap_.insert(scraddr);

      if (config().armoryDbType != ARMORY_DB_SUPER)
      {
         BinaryData lastScannedBlockHash = scrAddrDataForSideScan_.lastScannedBlkHash_;

         uint32_t topBlock = currentTopBlockHeight();
         uint32_t startBlock;

         //check last scanned blk hash against the blockchain      
         Blockchain& bc = blockchain();
         const BlockHeader& bh = bc.getHeaderByHash(lastScannedBlockHash);

         if (bh.isMainBranch())
         {
            //last scanned block is still on main branch
            startBlock = bh.getBlockHeight() + 1;
         }
         else
         {
            //last scanned block is off the main branch, undo till branch point
            const Blockchain::ReorganizationState state =
               bc.findReorgPointFromBlock(lastScannedBlockHash);
            ReorgUpdater reorg(state, &bc, lmdb_, config(), sca.get(), true);

            startBlock = state.reorgBranchPoint->getBlockHeight() + 1;
         }

         if (startBlock < topBlock)
            sca->applyBlockRangeToDB(startBlock, topBlock + 1, vector<string>());
      }

      //grab merge lock
      while (mergeLock_.fetch_or(1, memory_order_acquire));

      scrAddrMap_.insert(sca->scrAddrMap_.begin(), sca->scrAddrMap_.end());
      scrAddrDataForSideScan_.scrAddrsToMerge_.clear();

      mergeFlag_ = false;

      //release lock
      mergeLock_.store(0, memory_order_release);
   }
}
QgsPoint3DSymbol QgsPoint3DSymbolWidget::symbol() const
{
  QVariantMap vm;
  switch ( cboShape->currentIndex() )
  {
    case 0:  // sphere
      vm[QStringLiteral( "radius" )] = spinRadius->value();
      break;
    case 1:  // cylinder
      vm[QStringLiteral( "radius" )] = spinRadius->value();
      vm[QStringLiteral( "length" )] = spinLength->value();
      break;
    case 2:  // cube
      vm[QStringLiteral( "size" )] = spinSize->value();
      break;
    case 3:  // cone
      vm[QStringLiteral( "topRadius" )] = spinTopRadius->value();
      vm[QStringLiteral( "bottomRadius" )] = spinBottomRadius->value();
      vm[QStringLiteral( "length" )] = spinLength->value();
      break;
    case 4:  // plane
      vm[QStringLiteral( "size" )] = spinSize->value();
      break;
    case 5:  // torus
      vm[QStringLiteral( "radius" )] = spinRadius->value();
      vm[QStringLiteral( "minorRadius" )] = spinMinorRadius->value();
      break;
    case 6:  // model
      vm[QStringLiteral( "model" )] = lineEditModel->text();
      vm[QStringLiteral( "overwriteMaterial" )] = cbOverwriteMaterial->isChecked();
      break;
  }

  QQuaternion rot( QQuaternion::fromEulerAngles( spinRX->value(), spinRY->value(), spinRZ->value() ) );
  QVector3D sca( spinSX->value(), spinSY->value(), spinSZ->value() );
  QVector3D tra( spinTX->value(), spinTY->value(), spinTZ->value() );

  QMatrix4x4 tr;
  tr.translate( tra );
  tr.scale( sca );
  tr.rotate( rot );

  QgsPoint3DSymbol sym;
  sym.setAltitudeClamping( static_cast<Qgs3DTypes::AltitudeClamping>( cboAltClamping->currentIndex() ) );
  sym.setShape( static_cast<QgsPoint3DSymbol::Shape>( cboShape->itemData( cboShape->currentIndex() ).toInt() ) );
  sym.setShapeProperties( vm );
  sym.setMaterial( widgetMaterial->material() );
  sym.setTransform( tr );
  return sym;
}
Example #5
0
  bool GboxInstance::HandleInputEvent(const pp::InputEvent &event) {
    bool ret = false; // handled?

    switch (event.GetType()) {
    case PP_INPUTEVENT_TYPE_KEYDOWN:
    case PP_INPUTEVENT_TYPE_KEYUP:
    case PP_INPUTEVENT_TYPE_CHAR:
    case PP_INPUTEVENT_TYPE_CONTEXTMENU:
      {
        pp::KeyboardInputEvent key_event(event);
        ret = HandleKeyboard(key_event);
      }
      break;

    case PP_INPUTEVENT_TYPE_MOUSEDOWN:
    case PP_INPUTEVENT_TYPE_MOUSEMOVE:
    case PP_INPUTEVENT_TYPE_MOUSEUP:
    case PP_INPUTEVENT_TYPE_MOUSEENTER:
    case PP_INPUTEVENT_TYPE_MOUSELEAVE:
    case PP_INPUTEVENT_TYPE_WHEEL:
      {
        pp::MouseInputEvent mouse_event(event);
        ret = HandleMouse(mouse_event);
      }
      break;

    case PP_INPUTEVENT_TYPE_UNDEFINED:
    case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
      ret = false;

    default:
      break;
    }

#if 1
    if (!ret && sca() == 0x3)
      theLog.info("_Input Event: (%s a) et:%d handled:%d count:%d",
        kVersion, event.GetType(), ret, ++m_mc);
#endif
    return ret;
  }
Example #6
0
int main(int argc, char** argv) {
    // Dimension
    int n = 2;
    // Box size
    int d = 3;
    // Accuracy 
    double eps = 0.1;
    // Cut analysis depth
    int ldepth = 1;
    // Use or not boxed cut
    bool boxedcut = true;


    if (argc != 7)
        BNB_ERROR_REPORT("Usage runpolymi.exe dimension box_size polynom cut_depth use_boxed_cut (0/1) record");
    n = atoi(argv[1]);
    d = atoi(argv[2]);
    ldepth = atoi(argv[4]);
    boxedcut = (atoi(argv[5]) == 0) ? false : true;
    double record = atof(argv[6]);

    PolyMIFactory polymifact(n, d, argv[3]);
    NlpProblem<double>* nlp = polymifact.getProb();


    /* Setup cut generators */
    /* Cut generator for objective*/
    NlpRecStore<double> ors(record, nlp);
    PointCutFactory<double> pfact(&ors);
    PolyObjective<double>* obj = dynamic_cast<PolyObjective<double>*> (nlp->mObj);
    PolyEigenSupp objEigenSupp(obj);
    EigenCutFactory<double> objEigenCutFact(&ors, &objEigenSupp, obj, eps);

    /* Setup composite cut factory  */
    CompCutFactory <double> fact;
    fact.push(&pfact);
    fact.push(&objEigenCutFact);

    /* Setup cut applicator */
    SmartCutApplicator<double> sca(nlp->mVariables);
    
    if (boxedcut == 0)
        sca.getOptions() = SmartCutApplicator<double>::Options::CUT_BALL_SIMPLE;
    if (boxedcut == 1)
        sca.getOptions() = SmartCutApplicator<double>::Options::CUT_BALL_BOXED;
    if (boxedcut == 2)
        sca.getOptions() = (SmartCutApplicator<double>::Options::CUT_BALL_SIMPLE
            | SmartCutApplicator<double>::Options::CUT_BALL_BOXED);


    /* Setup splitter */
    //StdBoxSplitter<double> splt;
    MIBoxSplitter<double> splt(nlp->mVariables);

    /* Setup solver */
    BNCSolver<double> bnc(&fact, &sca, &splt, ldepth);
    BNBTree tree(makeRootNode(*nlp));
    BNBNode* root = tree.getRoot();
    WFSDFSManager manager;
    manager.setOptions(WFSDFSManager::Options::DFS);
    manager.reg(root);
    BNCState<double> state(&manager, &ors);
    state.mForest.push_back(&tree);


    /* Solving problem */
    bool ru;
    long long int iters = 10000000;

    bnc.solve(iters, state, ru);

    /* Printing results*/
    std::cout << iters << " iterations\n";
    std::cout << "Record = " << state.mRecord->getValue() << "\n";
    VecUtils::vecPrint(n, (double*) ors.getX());

    return 0;
}
Example #7
0
double* calcSCA(char m[],int n,int l)
{
/*
This function is used to calculate the OMES matrix.
m is the fastas sequences which has been concanated to one array
n is the number of sequences and l is the length.
len(m) must eaqul to l*n.

example:
*/

  int i,j,k,k1,k2;
  char reslist[]={ 'A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 
      'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y'};
  double q[]={.073, .025, .050, .061, .042, .072, .023, .053, .064, .089,
         .023, .043, .052, .040, .052, .073, .056, .063, .013, .033};
  int resnum=sizeof(reslist)/sizeof(char);
  double *p;
  p= malloc(l*resnum*sizeof(double));
  double *sca;
  sca = malloc( l*l * sizeof(double) );
  for (i=0;i<l;i++)
    for (j=0;j<resnum;j++)
      p[i*resnum+j]=0;
  for (i=0;i<l;i++)
  {
    double count=0;
    for (j=0;j<n;j++)
      for (k=0;k<resnum;k++)
        if (m(j,i)==reslist[k])
        {
          p[i*resnum+k]++;
          count++;
          break;
        }
    double sumall=0.0,temp=0.0;
    sumall=0;
    for (k=0;k<resnum;k++)
    {
      p[i*resnum+k]=p[i*resnum+k]*1.0/n;
      if (p[i*resnum+k]>=1.0-1e-10 || p[i*resnum+k]<=1e-10)
      {
        p[i*resnum+k]=0.0;
        temp=0;
      }
      else
      {
        temp=fabs(log((1-q[k])/q[k]*p[i*resnum+k]/(1-p[i*resnum+k])))*p[i*resnum+k];
        p[i*resnum+k]=temp*fabs(log((1-q[k])/q[k]*p[i*resnum+k]/(1-p[i*resnum+k])));
      }
        sumall=sumall+temp*temp;
    }
    sumall=sqrt(sumall);
    if (sumall<1e-10)
      for(k=0;k<resnum;k++)
        p[i*resnum+k]=0;
    else
      for (k=0;k<resnum;k++)
      {
        p[i*resnum+k]=p[i*resnum+k]/sumall;
      }
  }
  double *x;
  x=malloc(n*l*sizeof(double));
  double *sumx;
  sumx=malloc(l*sizeof(double));
  for (j=0;j<l;j++)
    sumx[j]=0.0;
  for (j=0;j<n*l;j++)
    x[j]=0.0;
  for (i=0;i<n;i++)
  {
    for (j=0;j<l;j++)
    {
      for (k=0;k<resnum;k++)
      {
        if (reslist[k]==m(i,j))
        {
          x[i*l+j]=p[j*resnum+k];
          sumx[j]+=x[i*l+j];
        }
      }
    }
  }
  for (i=0;i<l;i++)
  {
    for (j=i;j<l;j++)
    {
      double add=0;
      for (k=0;k<n;k++)
      {
        add+=x[k*l+i]*x[k*l+j];
      }
      add=(add/n-sumx[i]*sumx[j]/n/n);
      if (add<0)
        add=-add;
      sca(i,j)=add;
      sca(j,i)=add;
    }
  }
  free(p);
  free(x);
  free(sumx);
  return sca;
}
Example #8
0
int sindexcombined(char *slopefile,  char *scaterrainfile, char *scarminroadfile, char* scarmaxroadfile,
           char *tergridfile, char *terparfile, char *satfile, char* sincombinedfile, double Rminter, double Rmaxter, 
		   double *par)
{	
	MPI_Init(NULL,NULL);{
	FILE *fp;
	int i, j, mter, err, filetype, index, rno, nx, ny;
	float ndva, ndvs;
	short *ndvter;
	int nor;
	double X1, X2, cellsat, dx, dy;
	float rs, rw, g;
	float tmin, tmax, cmin, cmax, tphimin, tphimax;
  
	const double PI = 3.14159265358979;

	struct calreg{
		float tmin;
		float tmax;
		float cmin;
		float cmax;
		float tphimin;
		float tphimax;
		float r;
	} ;  /* this could be malloced or should be checked
                    to ensure fewer than 100 regions */
	g=par[0];
	rw=par[1];
	nor = 0;
	
	struct calreg *region;	

	char headers[MAXLN];

	// find number of regions
	fp = fopen(terparfile, "r");
	if (fp == NULL)return 15;

	// Pabitra (9/10/2015): the following code to count the number of lines 
	// handles if the last line does not end with end of line character
	while ( fgets ( headers, sizeof headers, fp) != NULL)
	{
		nor++;
	}
	/*while (readline(fp,headers) != EOF)
	{
		nor++;
	}*/
	(std::fclose)(fp);

	// number of regions is  total lines in the file minus 1 (for the header text line)
	nor = nor - 1;
		
	region = (calreg*)calloc(nor, sizeof(calreg));
	getRegionIndex(terparfile, nor);

	fp = fopen(terparfile, "r");	
	readline(fp,headers);
	//  i = -1;  DGT 12/31/14 Not needed
	index = 0;
	do
	{
		j = fscanf(fp,"%i,%f,%f,%f,%f,%f,%f,%f \n", &rno, &tmin,
					&tmax, &cmin, &cmax,  &tphimin, &tphimax, &rs);
		
		region[index].tmin = tmin;
		region[index].tmax = tmax;
		region[index].cmin  = cmin;
		region[index].cmax  = cmax;
		region[index].tphimin =tphimin * PI/180 ;
		region[index].tphimax = tphimax * PI/180;
		region[index].r = rw/rs;
		index++;
	}while (index < nor);

	(std::fclose)(fp);

	//MPI_Init(NULL,NULL);{

	int rank, size;
	MPI_Comm_rank(MCW, &rank);
	MPI_Comm_size(MCW, &size);
	if(rank == 0) printf("SinmapSI version %s\n", TDVERSION);

	double begin,end;
	//Begin timer
	begin = MPI_Wtime();

	//Create tiff object, read and store header info
	tiffIO slp(slopefile, FLOAT_TYPE);
	long totalX = slp.getTotalX();
	long totalY = slp.getTotalY();
	dx = slp.getdxA();
	dy = slp.getdyA();	
	
	tiffIO sca(scaterrainfile, FLOAT_TYPE);

	tiffIO *sca_min = NULL;
	if (*scarminroadfile != NULL)
	{
		sca_min = new tiffIO(scarminroadfile, FLOAT_TYPE);		
	}
	
	tiffIO *sca_max = NULL;
	if (*scarmaxroadfile != NULL)
	{
		sca_max = new tiffIO(scarmaxroadfile, FLOAT_TYPE);		
	}
		
	tiffIO cal(tergridfile, SHORT_TYPE);

	if(rank==0)
	{
		float timeestimate=(1e-7*totalX*totalY/pow((double) size,1))/60+1;  // Time estimate in minutes
		fprintf(stderr,"This run may take on the order of %.0f minutes to complete.\n",timeestimate);
		fprintf(stderr,"This estimate is very approximate. \nRun time is highly uncertain as it depends on the complexity of the input data \nand speed and memory of the computer. This estimate is based on our testing on \na dual quad core Dell Xeon E5405 2.0GHz PC with 16GB RAM.\n");
		fflush(stderr);
	}

	
	//Create partition and read data from slope file
	tdpartition *slpData;
	slpData = CreateNewPartition(slp.getDatatype(), totalX, totalY, dx, dy, slp.getNodata());
	nx = slpData->getnx();
	ny = slpData->getny();
	ndvs = *(float*)slp.getNodata();	
	int xstart, ystart;
	slpData->localToGlobal(0, 0, xstart, ystart);
	// TODO: put similar comments for the other savedxdyc() function used in this function
	// for a complete slpData partition would need to run slpData->savedxdyc(slp) to save lat variable cell sizes
	// here not done as cell size not needed
	//slpData->savedxdyc(slp);

	slp.read(xstart, ystart, ny, nx, slpData->getGridPointer());

	//Create partition and read data from clibration grid file
	tdpartition *calData;
	calData = CreateNewPartition(cal.getDatatype(), totalX, totalY, dx, dy, -1);
	calData->localToGlobal(0, 0, xstart, ystart);
	calData->savedxdyc(cal);
	cal.read(xstart, ystart, ny, nx, calData->getGridPointer());
			
	ndvter = (short*)cal.getNodata();	
			
	//Create partition and read data from sca grid file
	tdpartition *scaData;
	scaData = CreateNewPartition(sca.getDatatype(), totalX, totalY, dx, dy, sca.getNodata());
	scaData->localToGlobal(0, 0, xstart, ystart);
	scaData->savedxdyc(sca);
	sca.read(xstart, ystart, ny, nx, scaData->getGridPointer());

	//Create partition and read data from sca min grid file
	tdpartition *scaMinData = NULL;
	if (sca_min != NULL)
	{		
		scaMinData = CreateNewPartition(sca_min->getDatatype(), totalX, totalY, dx, dy, sca_min->getNodata());
		scaMinData->localToGlobal(0, 0, xstart, ystart);
		scaMinData->savedxdyc(*sca_min);
		sca_min->read(xstart, ystart, ny, nx, scaMinData->getGridPointer());
	}
	
	//Create partition and read data from sca max grid file
	tdpartition *scaMaxData = NULL;
	if(sca_max != NULL)
	{		
		scaMaxData = CreateNewPartition(sca_max->getDatatype(), totalX, totalY, dx, dy, sca_max->getNodata());
		scaMaxData->localToGlobal(0, 0, xstart, ystart);
		scaMaxData->savedxdyc(*sca_max);
		sca_max->read(xstart, ystart, ny, nx, scaMaxData->getGridPointer());
	}
	

	short cal_cell_value = 0;
	float slope_cell_value = 0;
	float sca_cell_value = 0;
	float sca_min_cell_value = 0;
	float sca_max_cell_value = 0;
	float csi_data = 0;
	int region_index = 0;

	//Create empty partition to store csi data
	tdpartition *csiData;
	csiData = CreateNewPartition(FLOAT_TYPE, totalX, totalY, dx, dy, -1.0f);

	//Create empty partition to store sat data
	tdpartition *satData;
	satData = CreateNewPartition(FLOAT_TYPE, totalX, totalY, dx, dy, -1.0f);

	//Share information and set borders to zero
	slpData->share();
	scaData->share();
	if(scaMinData != NULL)
	{
		scaMinData->share();
	}
	
	if(scaMaxData != NULL)
	{
		scaMaxData->share();
	}

	calData->share();
	csiData->clearBorders();
	satData->clearBorders();	
	
	for(j = 0; j < ny; j++) {
		for(i = 0; i < nx; i++ ) {
			calData->getData(i, j, cal_cell_value);
			slpData->getData(i, j, slope_cell_value);
			scaData->getData(i, j, sca_cell_value);
			if(scaMinData != NULL)
			{
				scaMinData->getData(i, j, sca_min_cell_value);
			}

			if(scaMaxData != NULL)
			{
				scaMaxData->getData(i, j, sca_max_cell_value);
			}
			
			region_index = findRegIndex(cal_cell_value, nor, *ndvter);
			
			//  DGT 12/31/14.  Changed the logic below from region_index < *ndvter to region_index < 0 to allow for *ndvter to be positive
			if (region_index < 0 || sca_cell_value < 0 || sca_min_cell_value < 0 || sca_max_cell_value < 0 || slope_cell_value == ndvs){
				csiData->setToNodata(i, j);
				satData->setToNodata(i, j);				
			}
			else{
				
				if(Rmaxter != 0 || sca_max_cell_value != 0){
					X2 = (sca_cell_value * Rmaxter + sca_max_cell_value)/region[region_index].tmin;
					X1 = (sca_cell_value * Rminter + sca_min_cell_value)/region[region_index].tmax;	
					csi_data = (float)sindexcell(slope_cell_value, 1,
								region[region_index].cmin, region[region_index].cmax, 
								region[region_index].tphimin, region[region_index].tphimax,
								X1, X2, region[region_index].r, &cellsat);
				
									
					csiData->setData(i, j, csi_data);
					satData->setData(i, j, float(cellsat));
					
				}				
			}				
		}
	}
	
	//  DGT 12/31/14 commented passing of borders.  This function acts locally so does not need any border sharing
	//Pass information
	//csiData->addBorders();		
	//satData->addBorders();	

	//Clear out borders
	//csiData->clearBorders();
	//satData->clearBorders();

	//Stop timer
	end = MPI_Wtime();
 	double compute, temp;
    compute = end-begin;

    MPI_Allreduce (&compute, &temp, 1, MPI_DOUBLE, MPI_SUM, MCW);
    compute = temp/size;

    if( rank == 0)
	{
		printf("Compute time: %f\n",compute);		
	}

	//Create and write to the csi TIFF file
	float aNodata = -1.0f;
	tiffIO csi(sincombinedfile, FLOAT_TYPE, &aNodata, slp);
	csi.write(xstart, ystart, ny, nx, csiData->getGridPointer());
	//Create and write to the sat TIFF file
	tiffIO sat(satfile, FLOAT_TYPE, &aNodata, slp);
	sat.write(xstart, ystart, ny, nx, satData->getGridPointer());

	}MPI_Finalize();

	return 0;
}
Example #9
0
void ScriptMachine::executeThread(SCMThread &t, int msPassed)
{
	if( t.wakeCounter > 0 ) {
		t.wakeCounter = std::max( t.wakeCounter - msPassed, 0 );
	}
	if( t.wakeCounter > 0 ) return;
	
	bool hasDebugging = !! bpHandler;
	
    while( t.wakeCounter == 0 ) {
        auto pc = t.programCounter;
        auto opcode = _file->read<SCMOpcode>(pc);

		bool isNegatedConditional = ((opcode & SCM_NEGATE_CONDITIONAL_MASK) == SCM_NEGATE_CONDITIONAL_MASK);
		opcode = opcode & ~SCM_NEGATE_CONDITIONAL_MASK;

		ScriptFunctionMeta* foundcode;
		if( ! _ops->findOpcode(opcode, &foundcode) )
		{
            throw IllegalInstruction(opcode, pc, t.name);
		}
		ScriptFunctionMeta& code = *foundcode;

        pc += sizeof(SCMOpcode);

		SCMParams parameters;
		
		bool hasExtraParameters = code.arguments < 0;
		auto requiredParams = std::abs(code.arguments);

		for( int p = 0; p < requiredParams || hasExtraParameters; ++p ) {
            auto type_r = _file->read<SCMByte>(pc);
			auto type = static_cast<SCMType>(type_r);

			if( type_r > 42 ) {
				// for implicit strings, we need the byte we just read.
				type = TString;
			}
			else {
                pc += sizeof(SCMByte);
			}

			parameters.push_back(SCMOpcodeParameter { type, { 0 } });
			switch(type) {
			case EndOfArgList:
				hasExtraParameters = false;
				break;
			case TInt8:
                parameters.back().integer = _file->read<std::uint8_t>(pc);
                pc += sizeof(SCMByte);
				break;
			case TInt16:
                parameters.back().integer = _file->read<std::int16_t>(pc);
                pc += sizeof(SCMByte) * 2;
				break;
			case TGlobal: {
				auto v = _file->read<std::uint16_t>(pc);
				parameters.back().globalPtr = globalData.data() + v; //* SCM_VARIABLE_SIZE;
				if( v >= _file->getGlobalsSize() )
				{
					state->world->logger->error("SCM", "Global Out of bounds! "+ std::to_string(v) + " " + std::to_string(_file->getGlobalsSize()));
				}
                pc += sizeof(SCMByte) * 2;
			}
				break;
			case TLocal: {
				auto v = _file->read<std::uint16_t>(pc);
				parameters.back().globalPtr = t.locals.data() + v * SCM_VARIABLE_SIZE;
				if( v >= SCM_THREAD_LOCAL_SIZE )
				{
					state->world->logger->error("SCM", "Local Out of bounds!");
				}
                pc += sizeof(SCMByte) * 2;
			}
				break;
			case TInt32:
                parameters.back().integer = _file->read<std::uint32_t>(pc);
                pc += sizeof(SCMByte) * 4;
				break;
			case TString:
                std::copy(_file->data()+pc, _file->data()+pc+8,
						  parameters.back().string);
                pc += sizeof(SCMByte) * 8;
				break;
			case TFloat16:
                parameters.back().real = _file->read<std::int16_t>(pc) / 16.f;
                pc += sizeof(SCMByte) * 2;
				break;
			default:
                throw UnknownType(type, pc, t.name);
				break;
			};
		}

        ScriptArguments sca(&parameters, &t, this);

        if( hasDebugging )
        {
			auto activeBreakpoint = findBreakpoint(t, pc);
			if( activeBreakpoint || interupt )
			{
                interupt = false;
                SCMBreakpoint bp;
                bp.pc = t.programCounter;
                bp.thread = &t;
                bp.vm = this;
                bp.function = &code;
                bp.args = &sca;
                bpHandler(bp);
            }
        }

#if RW_SCRIPT_DEBUG
		if (strcmp(t.name, "EIGHT") == 0)
		{
			printf("% 8s  %04x %04x % 25s", t.name, t.programCounter, opcode, code.signature.c_str());
			for (auto& a : sca.getParameters())
			{
				printf(" %08x", a.integerValue());
			}
			printf("\n");
		}
#endif

        // After debugging has been completed, update the program counter
        t.programCounter = pc;

		if(code.function)
        {
			code.function(sca);
		}

		if(isNegatedConditional) {
			t.conditionResult = !t.conditionResult;
		}

		// Handle conditional results for IF statements.
		if( t.conditionCount > 0 && opcode != 0x00D6 ) /// @todo add conditional flag to opcodes instead of checking for 0x00D6
		{
			--t.conditionCount;
			if ( t.conditionAND )
			{
				if ( t.conditionResult == false ) 
				{
					t.conditionMask = 0;
				}
				else
				{
					// t.conditionMask is already set to 0xFF by the if and opcode.
				}
			}
			else
			{
				t.conditionMask = t.conditionMask || t.conditionResult;
			}
			
			t.conditionResult = (t.conditionMask != 0);
		}
    }
	
	SCMOpcodeParameter p;
	p.globalPtr = (t.locals.data() + 16 * sizeof ( SCMByte ) * 4);
	*p.globalInteger += msPassed;
	p.globalPtr = (t.locals.data() + 17 * sizeof ( SCMByte ) * 4);
	*p.globalInteger += msPassed;
	
	if( t.wakeCounter == -1 ) {
		t.wakeCounter = 0;
	}
}