615   G4int returnvalue = 0; 
size_t rflag = 0;
 
  620   fTab = 
new G4int*[fRows];
 
  621   for ( 
G4int i = 0; i < fRows; i ++ ) {
 
  622         fTab[i] = 
new G4int[fColumns];
 
  625   if(fBitAllocated == 8) { 
 
  627     std::printf(
"@@@ Error! Picture != 16 bits...\n");
 
  628     std::printf(
"@@@ Error! Picture != 16 bits...\n");
 
  629     std::printf(
"@@@ Error! Picture != 16 bits...\n");
 
  631     unsigned char ch = 0;
 
  633     for(
G4int j = 0; j < fRows; j++) {
 
  634       for(
G4int i = 0; i < fColumns; i++) {
 
  636         rflag = std::fread( &ch, 1, 1, dicom);
 
  637         fTab[j][i] = ch*fRescaleSlope + fRescaleIntercept;
 
  645     for( 
G4int j = 0; j < fRows; j++) {
 
  646       for( 
G4int i = 0; i < fColumns; i++) {
 
  648         rflag = std::fread(sbuff, 2, 1, dicom);
 
  649         GetValue(sbuff, pixel);
 
  650         fTab[j][i] = pixel*fRescaleSlope + fRescaleIntercept;
 
  656   char * nameProcessed = 
new char[FILENAMESIZE];
 
  659   std::sprintf(nameProcessed,
"%s.g4dcmb",filename2);
 
  660   fileOut = std::fopen(nameProcessed,
"w+b");
 
  661   std::printf(
"### Writing of %s ###\n",nameProcessed);
 
  663   unsigned int nMate = fMaterialIndices.size();
 
  664   rflag = std::fwrite(&nMate, 
sizeof(
unsigned int), 1, fileOut);
 
  666   std::map<G4float,G4String>::const_iterator ite;
 
  667   for( ite = fMaterialIndices.begin(); ite != fMaterialIndices.end(); ite++ ){
 
  669     for( 
G4int ii = (*ite).second.length(); ii < 40; ii++ ) {
 
  673     const char* mateNameC = mateName.c_str();
 
  674     rflag = std::fwrite(mateNameC, 
sizeof(
char),40, fileOut);
 
  677   unsigned int fRowsC = fRows/fCompression;
 
  678   unsigned int fColumnsC = fColumns/fCompression;
 
  679   unsigned int planesC = 1;
 
  680   G4float pixelLocationXM = -fPixelSpacingX*fColumns/2.;
 
  681   G4float pixelLocationXP = fPixelSpacingX*fColumns/2.;
 
  682   G4float pixelLocationYM = -fPixelSpacingY*fRows/2.;
 
  683   G4float pixelLocationYP = fPixelSpacingY*fRows/2.;
 
  684   G4float fSliceLocationZM = fSliceLocation-fSliceThickness/2.;
 
  685   G4float fSliceLocationZP = fSliceLocation+fSliceThickness/2.;
 
  687   rflag = std::fwrite(&fRowsC, 
sizeof(
unsigned int), 1, fileOut);
 
  688   rflag = std::fwrite(&fColumnsC, 
sizeof(
unsigned int), 1, fileOut);
 
  689   rflag = std::fwrite(&planesC, 
sizeof(
unsigned int), 1, fileOut);
 
  691   rflag = std::fwrite(&pixelLocationXM, 
sizeof(
G4float), 1, fileOut);
 
  692   rflag = std::fwrite(&pixelLocationXP, 
sizeof(
G4float), 1, fileOut);
 
  693   rflag = std::fwrite(&pixelLocationYM, 
sizeof(
G4float), 1, fileOut);
 
  694   rflag = std::fwrite(&pixelLocationYP, 
sizeof(
G4float), 1, fileOut);
 
  695   rflag = std::fwrite(&fSliceLocationZM, 
sizeof(
G4float), 1, fileOut);
 
  696   rflag = std::fwrite(&fSliceLocationZP, 
sizeof(
G4float), 1, fileOut);
 
  699   std::printf(
"%8i   %8i\n",fRows,fColumns);
 
  700   std::printf(
"%8f   %8f\n",fPixelSpacingX,fPixelSpacingY);
 
  701   std::printf(
"%8f\n", fSliceThickness);
 
  702   std::printf(
"%8f\n", fSliceLocation);
 
  703   std::printf(
"%8i\n", fCompression);
 
  705   G4int compSize = fCompression;
 
  712     for( 
G4int ww = 0; ww < fRows; ww++) {
 
  713       for( 
G4int xx = 0; xx < fColumns; xx++) {
 
  715         density = Pixel2density(mean);
 
  716         unsigned int mateID = GetMaterialIndex( density );
 
  717         rflag = std::fwrite(&mateID, 
sizeof(
unsigned int), 1, fileOut);
 
  724     for(
G4int ww = 0; ww < fRows ;ww += compSize ) {
 
  725       for(
G4int xx = 0; xx < fColumns ;xx +=compSize ) {
 
  728         for(
int sumx = 0; sumx < compSize; sumx++) {
 
  729           for(
int sumy = 0; sumy < compSize; sumy++) {
 
  730             if(ww+sumy >= fRows || xx+sumx >= fColumns) overflow = 
true;
 
  731             mean += fTab[ww+sumy][xx+sumx];
 
  735         mean /= compSize*compSize;
 
  738           density = Pixel2density(mean);
 
  739           unsigned int mateID = GetMaterialIndex( density );
 
  740           rflag = std::fwrite(&mateID, 
sizeof(
unsigned int), 1, fileOut);
 
  749     for( 
G4int ww = 0; ww < fRows; ww++) {
 
  750       for( 
G4int xx = 0; xx < fColumns; xx++) {
 
  752         density = Pixel2density(mean);
 
  753         rflag = std::fwrite(&density, 
sizeof(
G4float), 1, fileOut);
 
  760     for(
G4int ww = 0; ww < fRows ;ww += compSize ) {
 
  761       for(
G4int xx = 0; xx < fColumns ;xx +=compSize ) {
 
  764         for(
int sumx = 0; sumx < compSize; sumx++) {
 
  765           for(
int sumy = 0; sumy < compSize; sumy++) {
 
  766             if(ww+sumy >= fRows || xx+sumx >= fColumns) overflow = 
true;
 
  767             mean += fTab[ww+sumy][xx+sumx];
 
  771         mean /= compSize*compSize;
 
  774           density = Pixel2density(mean);
 
  775           rflag = std::fwrite(&density, 
sizeof(
G4float), 1, fileOut);
 
  782   rflag = std::fclose(fileOut);
 
  784   delete [] nameProcessed;
 
  792   if (rflag) 
return returnvalue;