/***/
/* Synthetic image by euclidean distance.
/***/

FDATASIZE = 512;

if (sliceCode == 1)
   {
    float specBuff[xSize], simBuff[zSize*ySize], hdr[FDATASIZE];

    fd  = dOpen( name1, "r" );
 
    (void) dReadHdr( fd, hdr, 0 );
    (void) dRead( fd, specBuff, wordLen*size );
    (void) dClose( fd );
   };
 
sum = 0.0;

ix1 = integer( 0.2*size );
ixn = integer( 0.8*size );
 
for( i = ix1; i < ixn; i++ )
   {
    sum += (rdata[i] - specBuff[i])^2;
   }

simBuff[sliceCode - 1] = 100.0/(1.0 + sqrt(sum));

/***/
/* Write the synthetic 2D image:
/***/

if (sliceCode == ySize*zSize)
   {
    fd  = dOpen( planeName, "r" );

    (void) dReadHdr( fd, hdr, 0 );
    (void) dClose( fd );

    fd  = dOpen( simName, "w" );

    (void) dWrite( fd, hdr, wordLen*FDATASIZE );
    (void) dWrite( fd, simBuff, wordLen*zSize*ySize );
    (void) dClose( fd );
   };
