Пример #1
0
// ADD-BY-LEETEN 07/22/2011-BEGIN
void
ITLRandomField::_CollectRandomSamplesInBlock
(
	const int iBlock,
	const int iRandomVariable,	// CRandomVariable& cRandomVariable,
	float pfRandomSamples[],
	// ADD-BY-LEETEN 07/31/2011-BEGIN
	const bool bIsMappingToBins
	// ADD-BY-LEETEN 07/31/2011-END
)
{
	const CRandomVariable& cRandomVariable = this->CGetRandomVariable(iRandomVariable);
	int iFeatureLength = cRandomVariable.piFeatureVector.USize();

	// allocate the feature vector
	TBuffer<double> pdFeatureVector;
	pdFeatureVector.alloc(iFeatureLength);

	const CBlock& cBlock = this->CGetBlock(iBlock);
	int iNrOfCells = 1;
	for(int d = 0; d < CBlock::MAX_DIM; d++)
		iNrOfCells *= cBlock.piDimLengths[d];

	for(int c = 0; c < iNrOfCells; c++)
	{
		// collect the feature vector
		for(int f = 0; f < iFeatureLength; f++)
		{
			int iDataComponent = cRandomVariable.piFeatureVector[f];
			const CDataComponent& cDataComponent = this->CGetDataComponent(iDataComponent);

			const CArray &cArray = this->CGetArray(iBlock, iDataComponent);
			const double *pdData = cArray.pdData;
			int iBase = cArray.iBase;
			int iStep = cArray.iStep;
			double dValue = pdData[iBase + c * iStep];
			pdFeatureVector[f] = cDataComponent.cRange.DClamp(dValue);
		}
		double dSample = cRandomVariable.DGetRandomVariable(&pdFeatureVector[0]);
		dSample = cRandomVariable.cRange.DClamp(dSample);
		if( bIsMappingToBins )
		  {
		    dSample = cRandomVariable.DMapToBin(dSample);
		  }
		pfRandomSamples[c] = (float)dSample;
	}
}
Пример #2
0
void
ITLRandomField::_DumpData2NetCdf
(
		)
{
  for(int b = 0; b < IGetNrOfBlocks(); b++)
    {
      const CBlock& cBlock = this->CGetBlock(b);
      int iNrOfCells = 1;
      for(int d = 0; d < CBlock::MAX_DIM; d++)
	iNrOfCells *= cBlock.piDimLengths[d];

      TBuffer<double> pdTemp;
      pdTemp.alloc(iNrOfCells);

		#ifndef WITH_PNETCDF	// ADD-BY-LEETEN 09/01/2011
      size_t puStart[6];
      size_t puCount[6];
      // ADD-BY-LEETEN 09/01/2011-BEGIN
      #else	// #ifndef WITH_PNETCDF
      MPI_Offset puStart[6];
      MPI_Offset puCount[6];
      MPI_Offset puStride[6];
      for(int d = 0; d < sizeof(puStride)/sizeof(puStride[0]); d ++)
    	  puStride[d] = 1;
		#endif	// #ifndef WITH_PNETCDF
      // ADD-BY-LEETEN 09/01/2011-END

      // time
      puStart[0] = this->IGetNrOfTimeStamps() - 1;
      puCount[0] = 1;

      // block
		#ifndef WITH_PNETCDF	// ADD-BY-LEETEN 09/01/2011
      puStart[1] = (size_t)b;
      // ADD-BY-LEETEN 09/01/2011-BEGIN
      #else	// #ifndef WITH_PNETCDF
      puStart[1] = (size_t)CGetBlock(b).iGlobalId;
	  #endif	// #ifndef WITH_PNETCDF
      // ADD-BY-LEETEN 09/01/2011-END
      puCount[1] = 1;

      for(int d = 0; d < CBlock::MAX_DIM; d++)
	{
	  puStart[2+d] = 0;
	  puCount[2+d] = (size_t)cBlock.piDimLengths[CBlock::MAX_DIM - 1 - d];
	}

      for(int c = 0; c < IGetNrOfDataComponents(); c++)
	{ 
	  const CDataComponent& cDataComponent = CGetDataComponent(c);
	  const CArray &cArray = this->CGetArray(b, c);
	  const double *pdData = cArray.pdData;
	  int iBase = cArray.iBase;
	  int iStep = cArray.iStep;

	  for(int v = 0; v < iNrOfCells; v++)
	    {
	      double dValue = pdData[iBase + v * iStep];
	      pdTemp[v] = cDataComponent.cRange.DClamp(dValue);
	    }

		#ifndef	WITH_PNETCDF	// ADD-BY-LEETEN 08/12/2011
	  // dump the geometry of the given dim.
	  ASSERT_NETCDF(nc_put_vara_double(
					   iNcId,
					   cDataComponent.iVarId,
					   puStart,
					   puCount,
					   &pdTemp[0]));

		// ADD-BY-LEETEN 08/12/2011-BEGIN
		#else	// #ifndef	WITH_PNETCDF
	  	// MOD-BY-LEETEN 09/01/2011-FROM:
			// LOG_ERROR(fprintf(stderr, "PNetCDF is not fully supported yet."))
		// TO:
		ASSERT_NETCDF(ncmpi_put_vars_double_all(
					   iNcId,
					   cDataComponent.iVarId,
					   puStart,
					   puCount,
					   puStride,
					   &pdTemp[0]));
		// MOD-BY-LEETEN 09/01/2011-END
		#endif	// #ifndef	WITH_PNETCDF
		// ADD-BY-LEETEN 08/12/2011-END
	}
    }
}
Пример #3
0
void
ITLRandomField::_CloseNetCdf
(
)
{
	// MOD-BY-LEETEN 09/01/2011-FROM:
		// if( iNcId > 0 )
	// TO:
	if( iNcId >= 0 )
	// MOD-BY-LEETEN 09/01/2011-END
	{
		// write the time stamp
		TBuffer<int> piTemp;
		piTemp.alloc(this->IGetNrOfTimeStamps());
		for(int t = 0; t < (int)piTemp.USize(); t++)
			piTemp[t] = this->viTimeStamps[t];

		#ifndef	WITH_PNETCDF		// ADD-BY-LEETEN 08/12/2011
		#if 0 // DEL-BY-LEETEN 09/01/2011-BEGIN
			// since the time step wil lbe written earlier, this part can be removed
			size_t uStart = 0;
			size_t uCount = piTemp.USize();
			ASSERT_NETCDF(nc_put_vara_int(
					iNcId,
					iNcTimeVarId,
					&uStart,
					&uCount,
					&piTemp[0]));
		#endif	// DEL-BY-LEETEN 09/01/2011-END
        /* Close the file. */
	    ASSERT_NETCDF(nc_close(iNcId));

		// ADD-BY-LEETEN 08/12/2011-BEGIN
		#else	// #ifndef	WITH_PNETCDF

	    #if 0 // DEL-BY-LEETEN 09/01/2011-BEGIN
			MPI_Offset uStart = 0;
			MPI_Offset uCount = piTemp.USize();

			ASSERT_NETCDF(ncmpi_begin_indep_data(iNcId));
			if( 0 == iRank )
				ASSERT_NETCDF(ncmpi_put_vara_int(
						iNcId,
						iNcTimeVarId,
						&uStart,
						&uCount,
						&piTemp[0]));
			ASSERT_NETCDF(ncmpi_end_indep_data(iNcId));
		#endif	// DEL-BY-LEETEN 09/01/2011-END

        /* Close the file. */
	    ASSERT_NETCDF(ncmpi_close(iNcId));
		#endif	// #ifndef	WITH_PNETCDF
		// ADD-BY-LEETEN 08/12/2011-END

	    // MOD-BY-LEETEN 09/01/2011-FROM:
	    	// iNcId = 0;
		// TO:
	    iNcId = -1;
	    // MOD-BY-LEETEN 09/01/2011-END
	}
};
Пример #4
0
void
ITLRandomField::_DumpRandomSamples2NetCdf
(
 const int iRandomVariable
		)
{
  for(int b = 0; b < IGetNrOfBlocks(); b++)
    {
      const CBlock& cBlock = this->CGetBlock(b);
      int iNrOfCells = 1;
      for(int d = 0; d < CBlock::MAX_DIM; d++)
	iNrOfCells *= cBlock.piDimLengths[d];

      TBuffer<float> pfTemp;
      pfTemp.alloc(iNrOfCells);

	  #ifndef WITH_PNETCDF	// ADD-BY-LEETEN 09/01/2011
      size_t puStart[6];
      size_t puCount[6];

      // ADD-BY-LEETEN 09/01/2011-BEGIN
      #else	// #ifndef WITH_PNETCDF
      MPI_Offset puStart[6];
      MPI_Offset puCount[6];
      MPI_Offset puStride[6];
      for(int d = 0; d < sizeof(puStride)/sizeof(puStride[0]); d ++)
    	  puStride[d] = 1;
	  #endif	// #ifndef WITH_PNETCDF
      // ADD-BY-LEETEN 09/01/2011-END

      // time
      puStart[0] = this->IGetNrOfTimeStamps() - 1;
      puCount[0] = 1;

      // block
	  #ifndef WITH_PNETCDF	// ADD-BY-LEETEN 09/01/2011
      puStart[1] = (size_t)b;
      // ADD-BY-LEETEN 09/01/2011-BEGIN
      #else	// #ifndef WITH_PNETCDF
      puStart[1] = (size_t)CGetBlock(b).iGlobalId;
	  #endif	// #ifndef WITH_PNETCDF
      // ADD-BY-LEETEN 09/01/2011-END
      puCount[1] = 1;

      for(int d = 0; d < CBlock::MAX_DIM; d++)
	{
	  puStart[2+d] = 0;
	  puCount[2+d] = (size_t)cBlock.piDimLengths[CBlock::MAX_DIM - 1 - d];
	}

      _CollectRandomSamplesInBlock(b, iRandomVariable, &pfTemp[0], true);


		#ifndef	WITH_PNETCDF	// ADD-BY-LEETEN 08/12/2011
      ASSERT_NETCDF(nc_put_vara_float(
				      iNcId,
				      CGetRandomVariable(iRandomVariable).iVarId,
				      puStart,
				      puCount,
				      &pfTemp[0]));
		// ADD-BY-LEETEN 08/12/2011-BEGIN
		#else	// #ifndef	WITH_PNETCDF
      	// MOD-BY-LEETEN 09/01/2011-FROM:
			// LOG_ERROR(fprintf(stderr, "PNetCDF is not fully supported yet."))
		// TO:
		ASSERT_NETCDF(ncmpi_put_vars_float_all(
					  iNcId,
					  CGetRandomVariable(iRandomVariable).iVarId,
					  puStart,
					  puCount,
					  puStride,
					  &pfTemp[0]));
		// MOD-BY-LEETEN 09/01/2011-END
		#endif	// #ifndef	WITH_PNETCDF
		// ADD-BY-LEETEN 08/12/2011-END
    }
}