void rspfVpfFeatureClassSchema::setFeatureClassMapping()
{
   if(!isClosed())
   {
      rspf_int32 featureIdx = getColumnPosition("feature_class");
      rspf_int32 table1Idx = getColumnPosition("table1");
      rspf_int32 table1KeyIdx = getColumnPosition("table1_key");
      rspf_int32 table2Idx = getColumnPosition("table2");
      rspf_int32 table2KeyIdx = getColumnPosition("table2_key");
      reset();
      if(getNumberOfRows() > 0)
      {
         row_type row;
         const int ROWS = getNumberOfRows();
         for(int rowIdx = 1; rowIdx <= ROWS; ++rowIdx)
         {
            if(rowIdx == 1)
            {
               row = read_row(rowIdx,
                              *theTableInformation);
            }
            else
            {
               row = read_next_row(*theTableInformation);
            }
            rspfFilename primitiveTable =  getColumnValueAsString(row,
                                                                   table2Idx);
            if(rspfVpfFeatureClass::isPrimitive(primitiveTable))
            {
               rspfString primitiveTableKey = getColumnValueAsString(row,
                                                                      table2KeyIdx);
               rspfFilename table = getColumnValueAsString(row,
                                                            table1Idx);
               rspfString tableKey = getColumnValueAsString(row,
                                                             table1KeyIdx);
               rspfString featureClass = getColumnValueAsString(row,
                                                                 featureIdx);
               rspfVpfFeatureClassSchemaNode node(table,
                                                   tableKey,
                                                   primitiveTable,
                                                   primitiveTableKey);
               
               theFeatureClassMap.insert(make_pair(featureClass,
                                                   node));
            }
            
            free_row(row, *theTableInformation);
         }
      }
   }
}
예제 #2
0
void ossimDoubleGridProperty::valueToString(ossimString& valueResult)const
{
  std::ostringstream out;
  int rowIdx = 0;
  int colIdx = 0;
  out << getNumberOfRows() << " " << getNumberOfCols() << " ";

  for(rowIdx = 0; rowIdx < (int)getNumberOfRows(); ++rowIdx)
    {
      for(colIdx = 0; colIdx < (int)getNumberOfCols(); ++colIdx)
	{
	  out << ossimString::toString(getValue(rowIdx, colIdx)) << " ";
	}
    }
  valueResult = out.str();
}
예제 #3
0
int main(){
	FILE * idDirectoryFile = fopen(ID_DIRECTORY_NAME,"r"); //find Halo IDs
	int numberOfHalos = getNumberOfRows(idDirectoryFile); //count number of halos
	char * HaloID;

	numberOfThreadsMutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
	threadAvailable = (pthread_cond_t *)malloc(sizeof(pthread_cond_t));

	pthread_mutex_init(numberOfThreadsMutex, NULL);		// Initialize mutex that is not yet locked.
	pthread_cond_init(threadAvailable, NULL);

	for(int n=0;n<numberOfHalos;n++){	//for each halo do this: (change to numberOfHalos later)
																	
		pthread_mutex_lock(numberOfThreadsMutex);		// Lock our mutex. CRITICAL SECTION START
		while (!(numberOfThreads < MAX_THREADS)) {
			pthread_cond_wait(threadAvailable, numberOfThreadsMutex);	// Sleep and wait for open thread.
		}
		
		numberOfThreads++;				// Increment our number of active threads.
		pthread_mutex_unlock(numberOfThreadsMutex);						// Release mutex lock.  CRITICAL SECTION END.
		
		HaloID = readNextID(idDirectoryFile);		//read halo ID
		
		pthread_t thread;
		pthread_create(&thread, NULL, &haloThread, HaloID);				// Break off our new thread to do the work.
		
	}		//end for loop, repeat for each halo.

	pthread_mutex_lock(numberOfThreadsMutex);
	while (numberOfThreads > 0) {}							// SPPIN
	pthread_mutex_unlock(numberOfThreadsMutex);

	//system("PAUSE");
	return 0;
}//end of program
예제 #4
0
/**
 * Creates a new game according to the settings the user made.
 *
 * @param factory Player factory to use to create the players.
 * @return New game.
 */
QSharedPointer< ::Game::Game> NewGame::createGame(::Game::Players::Factory& factory) const
{
	QSharedPointer< ::GameLogic::FourInALine::Game> fourInALine;
	QSharedPointer< ::Game::Game> game;
	auto firstPlayer = this->createFirstPlayer(factory);
	auto secondPlayer = this->createSecondPlayer(factory);
	auto boardConfigurationWidget = this->gameSetupWidget->getBoardConfigurationWidget();
	auto timeLimitConfigurationWidget = this->gameSetupWidget->getTimeLimitConfigurationWidget();
	auto gameConfigurationWidget = this->gameSetupWidget->getGameConfigurationWidget();

	unsigned int nRows = boardConfigurationWidget->getNumberOfRows();
	unsigned int nColumns = boardConfigurationWidget->getNumberOfColumns();
	unsigned int firstMove = gameConfigurationWidget->getFirstMove();

	fourInALine.reset(new ::GameLogic::FourInALine::Game(nRows, nColumns, firstMove));

	if (timeLimitConfigurationWidget->hasTimeLimit())
	{
		fourInALine->setTimeLimit(timeLimitConfigurationWidget->getTimeLimit());
		fourInALine->setTimeoutAction(timeLimitConfigurationWidget->getTimeoutAction());
	}

	game = QSharedPointer< ::Game::Game>(new ::Game::Game(fourInALine, firstPlayer, secondPlayer));
	game->setAllowHint(gameConfigurationWidget->isAllowHintEnabled() &&
	                   gameConfigurationWidget->getAllowHint());
	game->setAllowUndo(gameConfigurationWidget->isAllowUndoEnabled() &&
	                   gameConfigurationWidget->getAllowUndo());
	game->setSaveHighscore(gameConfigurationWidget->isSaveHighscoreEnabled() &&
	                       gameConfigurationWidget->getSaveHighscore());

	return game;
}
예제 #5
0
ossim_uint32 ossimDoubleGridProperty::getNumberOfCols()const
{
  if(getNumberOfRows())
    {
      return (ossim_uint32)theValues[0].size();
    }
  return 0;
}
size_t CompressedDataMatrix::getNumberOfNonZeroEntries(int column) const {
    const auto type = getFormatType(column);
    if (type == INTERCEPT || type == DENSE) {
        return getNumberOfRows();
    } else {
        return getNumberOfEntries(column);
    }
}
예제 #7
0
ossim_int32 ossimNitfImageHeaderV2_1::getNumberOfPixelsPerBlockVert()const
{
//   return ossimString(theNumberOfPixelsPerBlockVert).toInt32();
   ossim_int32 rval = ossimString(theNumberOfPixelsPerBlockVert).toInt32();
   if ((rval == 0) && (getNumberOfBlocksPerRow() == 1))
   {
      rval = getNumberOfRows();
   }
   return rval;
}
예제 #8
0
double ossimDoubleGridProperty::getValue(ossim_uint32 row, 
					 ossim_uint32 col)const
{
  if((row < getNumberOfRows())&&
     (col < getNumberOfCols()))
    {
      return theValues[(int)row][(int)col];
    }

  return 0.0;
}
예제 #9
0
bool ossimNitfImageHeader::isSameAs(const ossimNitfImageHeader* hdr) const
{
   if (!hdr) return false;
   
   return ( (isCompressed() == hdr->isCompressed()) &&
            (getNumberOfRows() == hdr->getNumberOfRows()) &&
            (getNumberOfBands() == hdr->getNumberOfBands()) &&
            (getNumberOfCols() == hdr->getNumberOfCols()) &&
            (getNumberOfBlocksPerRow() == hdr->getNumberOfBlocksPerRow()) &&
            (getNumberOfBlocksPerCol() == hdr->getNumberOfBlocksPerCol()) &&
            (getNumberOfPixelsPerBlockHoriz() ==
             hdr->getNumberOfPixelsPerBlockHoriz()) &&
            (getNumberOfPixelsPerBlockVert() ==
             hdr->getNumberOfPixelsPerBlockVert()) &&
            (getBitsPerPixelPerBand() == hdr->getBitsPerPixelPerBand()) &&
            (getImageRect() == hdr->getImageRect()) &&
            (getIMode() == hdr->getIMode()) &&
            (getCoordinateSystem() == hdr->getCoordinateSystem()) &&
            (getGeographicLocation() == hdr->getGeographicLocation()) );
}
bool ossimVpfBoundingRecordTable::openTable(const ossimFilename& tableName)
{
   bool result = false;
   theExtent = ossimVpfExtent(0,0,0,0);
   bool firstOneSetFlag = false;
   
   if(ossimVpfTable::openTable(tableName))
   {
      ossim_int32 xminIdx = getColumnPosition("XMIN");
      ossim_int32 yminIdx = getColumnPosition("YMIN");
      ossim_int32 xmaxIdx = getColumnPosition("XMAX");
      ossim_int32 ymaxIdx = getColumnPosition("YMAX");
      
      if((xminIdx < 0)||
         (yminIdx < 0)||
         (xmaxIdx < 0)||
         (ymaxIdx < 0))
      {
         closeTable();
      }
      else
      {
         if(getNumberOfRows() > 0)
         {
            result = true;
            reset();
            ossim_int32 n = 1;
            
            ossim_float32 xmin;
            ossim_float32 ymin;
            ossim_float32 xmax;
            ossim_float32 ymax;
            
            row_type row;
            for(int rowIdx = 1; rowIdx < getNumberOfRows(); ++rowIdx)
            {
               if(rowIdx == 1)
               {
                  row = read_row(rowIdx,
                                 *theTableInformation);
               }
               else
               {
                  row = read_next_row(*theTableInformation);
               }
               get_table_element(xminIdx,
                                 row,
                                 *theTableInformation,
                                 &xmin,
                                 &n);
               get_table_element(yminIdx,
                                 row,
                                 *theTableInformation,
                                 &ymin,
                                 &n);
               get_table_element(xmaxIdx,
                                 row,
                                 *theTableInformation,
                                 &xmax,
                                 &n);
               get_table_element(ymaxIdx,
                                 row,
                                 *theTableInformation,
                                 &ymax,
                                 &n);
               if(!is_vpf_null_float(xmin)&&
                  !is_vpf_null_float(ymin)&&
                  !is_vpf_null_float(xmax)&&
                  !is_vpf_null_float(ymax))
               {
                  if(!firstOneSetFlag)
                  {
                     theExtent = ossimVpfExtent(xmin,
                                                ymin,
                                                xmax,
                                                ymax);
                     firstOneSetFlag = true;
                  }
                  else
                  {
                     theExtent = theExtent + ossimVpfExtent(xmin,
                                                            ymin,
                                                            xmax,
                                                            ymax);
                  }                  
               }
               free_row(row, *theTableInformation);
            }
         }
      }
   }
   return result;
}
예제 #11
0
파일: ExcelCUDA.c 프로젝트: huoyao/cudasdk
__declspec(dllexport) LPXLOPER12 WINAPI CUDAPriceAsian(LPXLOPER12 pxSpot,
        LPXLOPER12 pxStrike,
        LPXLOPER12 pxRiskFreeRate,
        LPXLOPER12 pxVolatility,
        LPXLOPER12 pxExpiry,
        LPXLOPER12 pxCallput,
        int        nTimesteps,
        int        nScenarios)
{
    int ok = 1;
    int n = -1;
    unsigned int i;
    LPXLOPER12 pxRes = (LPXLOPER12)malloc(sizeof(XLOPER12));
    int error = -1;

    unsigned int nOptions = 0;
    float *spot         = 0;
    float *strike       = 0;
    float *riskFreeRate = 0;
    float *volatility   = 0;
    float *expiry       = 0;
    int   *callNotPut   = 0;
    float *value        = 0;

    // First we need to determine how many options we will process
    if (ok)
    {
        n = max(n, getNumberOfRows(pxSpot));
        n = max(n, getNumberOfRows(pxStrike));
        n = max(n, getNumberOfRows(pxRiskFreeRate));
        n = max(n, getNumberOfRows(pxVolatility));
        n = max(n, getNumberOfRows(pxExpiry));
    }

    if (n <= 0)
        ok = 0;
    else
        nOptions = n;

    // Allocate memory to collect the data from Excel
    if (ok && (spot = (float *)malloc(nOptions * sizeof(float))) == NULL)
        ok = 0;

    if (ok && (strike = (float *)malloc(nOptions * sizeof(float))) == NULL)
        ok = 0;

    if (ok && (riskFreeRate = (float *)malloc(nOptions * sizeof(float))) == NULL)
        ok = 0;

    if (ok && (volatility = (float *)malloc(nOptions * sizeof(float))) == NULL)
        ok = 0;

    if (ok && (expiry = (float *)malloc(nOptions * sizeof(float))) == NULL)
        ok = 0;

    if (ok && (callNotPut = (int *)malloc(nOptions * sizeof(int))) == NULL)
        ok = 0;

    if (ok && (value = (float *)malloc(nOptions * sizeof(float))) == NULL)
        ok = 0;

    // Collect data from Excel
    if (ok)
        ok = extractData(pxSpot, nOptions, spot, &error);

    if (ok)
        ok = extractData(pxStrike, nOptions, strike, &error);

    if (ok)
        ok = extractData(pxRiskFreeRate, nOptions, riskFreeRate, &error);

    if (ok)
        ok = extractData(pxVolatility, nOptions, volatility, &error);

    if (ok)
        ok = extractData(pxExpiry, nOptions, expiry, &error);

    if (ok)
        ok = extractData(pxCallput, nOptions, value, &error);

    // Interpret call/put flags, 1 and 2 are exactly representable in fp types
    for (i = 0 ; ok && i < nOptions ; i++)
    {
        if (value[i] == 1.0)
            callNotPut[i] = 1;
        else if (value[i] == 2.0)
            callNotPut[i] = 0;
        else
            ok = 0;

        value[i] = -1;
    }

    // Run the pricing function
    if (ok)
        priceAsianOptions(spot, strike, riskFreeRate, volatility, expiry, callNotPut, value, nOptions, (unsigned int)nTimesteps, (unsigned int)nScenarios);

    // If pricing more than one option then allocate memory for result XLOPER12
    if (ok && nOptions > 1)
    {
        if ((pxRes->val.array.lparray = (LPXLOPER12)malloc(nOptions * sizeof(XLOPER12))) == NULL)
            ok = 0;
    }

    // Copy the result into the XLOPER12
    if (ok)
    {
        if (nOptions > 1)
        {
            for (i = 0 ; i < nOptions ; i++)
            {
                pxRes->val.array.lparray[i].val.num = (double)value[i];
                pxRes->val.array.lparray[i].xltype = xltypeNum;
                pxRes->val.array.rows    = nOptions;
                pxRes->val.array.columns = 1;
            }

            pxRes->xltype = xltypeMulti;
            pxRes->xltype |= xlbitDLLFree;
        }
        else
        {
            pxRes->val.num = value[0];
            pxRes->xltype = xltypeNum;
            pxRes->xltype |= xlbitDLLFree;
        }
    }
    else
    {
        pxRes->val.err = (error < 0) ? xlerrValue : error;
        pxRes->xltype = xltypeErr;
        pxRes->xltype |= xlbitDLLFree;
    }

    // Cleanup
    if (spot)
        free(spot);

    if (strike)
        free(strike);

    if (riskFreeRate)
        free(riskFreeRate);

    if (volatility)
        free(volatility);

    if (expiry)
        free(expiry);

    if (callNotPut)
        free(callNotPut);

    if (value)
        free(value);

    // Note that the pxRes will be freed when Excel calls xlAutoFree12
    return pxRes;
}
예제 #12
0
extern "C" void * haloThread(void * id){
	char * HaloID = (char *)id;
	cout << "Analyzing halo with ID " << HaloID << endl;
	int numberOfParticles, nCols;
	double ** positionsArray;
	Particle ** particlesArray;
	FILE * output;
	double radius = 0;
	double u;

	FILE * positionFile = getPositionFile(HaloID);		//make the file path
	if (positionFile == NULL)
		printf("POSITION FILE NULL\n");
	numberOfParticles = getNumberOfRows(positionFile);	//count number of particles in file
	nCols = getNumberOfColumns(positionFile);			//get number of columns in file (3)
	particlesArray = new ParticleArray[numberOfParticles];	//make an array of particles
	for (int i = 0; i < numberOfParticles; i++){
		particlesArray[i] = new Particle();					//each location in the array is a particle (with positions)
	}
	positionsArray = assembleArray(positionFile,numberOfParticles,nCols);
	for (int i = 0; i<numberOfParticles;i++){
		particlesArray[i]->position.x = positionsArray[i][0];
		particlesArray[i]->position.y = positionsArray[i][1];
		particlesArray[i]->position.z = positionsArray[i][2];
		free(positionsArray[i]);
	}
	delete positionsArray;
       
	for(int i = 0; i < numberOfParticles; i++){

		for(int j = 0; j < numberOfParticles; j++){
				radius = sqrt(sq((particlesArray[i]->position.x)-(particlesArray[j]->position.x))+sq((particlesArray[i]->position.y)-(particlesArray[j]->position.y))+sq((particlesArray[i]->position.z)-(particlesArray[j]->position.z)));
				u = radius/EPSILON;
				if(u<0.5){
					particlesArray[i]->directPotential += GRAVITATIONAL_CONSTANT*PARTICLE_MASS*MASS_MULTIPLIER/EPSILON*(16.0/3.0*sq(u)-48.0/5.0*fourth(u)+32.0/5.0*fifth(u)-14.0/5.0);
				}
				else if(u<1){
					particlesArray[i]->directPotential += GRAVITATIONAL_CONSTANT*PARTICLE_MASS*MASS_MULTIPLIER/EPSILON*(1.0/(15.0*u)+32.0/3.0*sq(u)-16.0*third(u)+48.0/5.0*fourth(u)-32.0/15.0*fifth(u)-16.0/5.0);
				}
				else{
					particlesArray[i]->directPotential += GRAVITATIONAL_CONSTANT*PARTICLE_MASS*MASS_MULTIPLIER/EPSILON*(-1.0/u);
				}

		}
		if(i%100000==0){cout <<HaloID <<" - " <<i <<"th particle's potential calculated" <<endl;}
	}

	output = makeOutputFileName(HaloID);		//make output file

	//print output
	for(int i = 0; i<numberOfParticles; i++){
		fprintf(output,"%f%c\n",particlesArray[i]->directPotential,delimeter);
	}

	//free memory
	for (int i = 0; i < numberOfParticles; i++){
		delete particlesArray[i]; 
	}
	delete particlesArray;

	//close files
	fclose(positionFile);
	fclose(output);

		// Reduce our active threads count.
	pthread_mutex_lock(numberOfThreadsMutex);
	numberOfThreads--;
	pthread_mutex_unlock(numberOfThreadsMutex);
	pthread_cond_signal(threadAvailable);			// Signal to wake up main.

	cout <<"Halo " << HaloID <<" done." <<endl;

}
template<typename X> rawData<X>* C_readDicomDiffData::getUnmosaicData_(unsigned short nb_slice_per_mosa)
{
    //returned pointer
    rawData<X>* rawDataX = NULL;

    if(mImage.GetNumberOfDimensions()!=2) return NULL;

    //get number of byte in image buffer
    unsigned long buffLen = mImage.GetBufferLength();

    //allocate a temporary buffer of buffLen bytes
    char* buff = new char[buffLen];
    if(buff==NULL) return NULL;

    //get image buffer into temporary buffer
    if(mImage.GetBuffer(buff))
    {
        ///get subimage dimension
        unsigned long subDimX, subDimY, squareDim;
        if(sqrt(nb_slice_per_mosa)==floor(sqrt(nb_slice_per_mosa)))
        {
            squareDim = (unsigned short) floor(sqrt(nb_slice_per_mosa));
        }
        else
        {
            squareDim = (unsigned short) floor(sqrt(nb_slice_per_mosa)) + 1;
        }
        //cout << "before getNumberOfColumns" << endl;
        subDimX = getNumberOfColumns()/squareDim;
        //cout << "after getNumberOfColumns" << endl;
        subDimY = getNumberOfRows()/squareDim;
        //cout << "after getNumberOfRows" << endl;

        ///allocate storage
        rawDataX = new rawData<X>(getPixelRepresentation(), 2+1, subDimY, subDimX, nb_slice_per_mosa);
        if(rawDataX==NULL)
        {
            delete buff;
            return NULL;
        }
        if(rawDataX->raw1D==NULL && rawDataX->raw2D==NULL && rawDataX->raw3D==NULL && rawDataX->raw4D==NULL)
        {
            delete buff;
            delete rawDataX;
            return NULL;
        }

        //reorganize buffer into rawData structure
        X* bufferX = (X*) buff;
        for(unsigned long i=0 ; i<rawDataX->DimX ; i++)
        {
            for(unsigned long j=0 ; j<rawDataX->DimY ; j++)
            {
                for(unsigned long k=0 ; k<rawDataX->DimZ ; k++)
                {
                    ///store data
                    rawDataX->raw3D[i][j][k] = bufferX[rawDataX->getIndex3DUnmosaic(i,j,k)];
                }
            }
        }



    }

    //cout << "before getPixelDimX" << endl;
    rawDataX->pixDimX = getPixelDimX();
    //cout << "after getPixelDimX" << endl;
    rawDataX->pixDimY = getPixelDimY();
    rawDataX->pixDimZ = getPixelDimZ(); ///may not be right
    rawDataX->pixDimT = 1.0;
    delete buff;
    return rawDataX;
}