コード例 #1
0
ファイル: binary.c プロジェクト: aharisu/Gauche
void Scm_PutBinaryS64(ScmUVector *uv, int off, ScmObj val, ScmSymbol *e)
{
    swap_s64_t v;
    CHECK_ENDIAN(e);
    v.val = Scm_GetInteger64Clamp(val, FALSE, FALSE);
    SWAP_64(e, v);
    inject(uv, v.buf, off, 8);
}
コード例 #2
0
ファイル: binary.c プロジェクト: aharisu/Gauche
ScmObj Scm_GetBinaryS64(ScmUVector *uv, int off, ScmSymbol *endian)
{
    swap_s64_t v;
    CHECK_ENDIAN(endian);
    extract(uv, v.buf, off, 8);
    SWAP_64(endian, v);
    return Scm_MakeInteger64(v.val);
}
コード例 #3
0
ファイル: binary.c プロジェクト: aharisu/Gauche
ScmObj Scm_ReadBinaryS64(ScmPort *iport, ScmSymbol *endian)
{
    swap_s64_t v;
    CHECK_ENDIAN(endian);
    if (getbytes(v.buf, 8, iport) == EOF) return SCM_EOF;
    SWAP_64(endian, v);
    return Scm_MakeInteger64(v.val);
}
コード例 #4
0
ファイル: vstpresetfile.cpp プロジェクト: Fooway/ChuckDelay
//------------------------------------------------------------------------
bool PresetFile::writeSize (TSize size)
{
#if BYTEORDER == kBigEndian
	SWAP_64 (size)
#endif	
	int32 numBytesWritten = 0;
	stream->write (&size, sizeof (TSize), &numBytesWritten);
	return numBytesWritten == sizeof (TSize);
}
コード例 #5
0
ファイル: binary.c プロジェクト: aharisu/Gauche
void Scm_WriteBinaryS64(ScmObj sval, ScmPort *oport, ScmSymbol *endian)
{
    swap_s64_t v;
    ENSURE_OPORT(oport);
    CHECK_ENDIAN(endian);
    v.val = Scm_GetInteger64Clamp(sval, FALSE, FALSE);
    SWAP_64(endian, v);
    Scm_Putz(v.buf, 8, oport);
}
コード例 #6
0
ファイル: RAWIV.cpp プロジェクト: ampereira/F2Dock
int readRAWIV( FFTW_DATA_TYPE **vol, int *xDim, int *yDim, int *zDim, double *xCenter, double *yCenter, double *zCenter, double *scale, char *fileName )
{
   FILE *fp;
   
   if ( ( fp = fopen( fileName, "rb" ) ) == NULL )
     {
      fprintf( stderr, "\nError: Failed to open file %s!\n\n", fileName );
      return 0;
     }
     
   fseek( fp, 0, SEEK_END );  
   long fileSize = ftell( fp );
   
   fseek( fp, 0, SEEK_SET );     
   
   RAWIVHeader header;

   if ( fread( &header, sizeof( header ), 1, fp ) != 1 )  
     {
      fprintf( stderr, "\nError: Failed to read header from file %s!\n\n", fileName );
      fclose( fp );      
      return 0;      
     }

   if ( !bigEndian( ) )
     {
      for ( int i = 0; i < 3; i++ )
        {
         SWAP_32( &( header.minExt[ i ] ) );
         SWAP_32( &( header.maxExt[ i ] ) );         
         SWAP_32( &( header.dim[ i ] ) );         
         SWAP_32( &( header.origin[ i ] ) );                           
         SWAP_32( &( header.span[ i ] ) );         
        }
        
      SWAP_32( &( header.numVertices ) );  
      SWAP_32( &( header.numCells ) );        
     }
   
   *xCenter = ( header.minExt[ 0 ] + header.maxExt[ 0 ] ) / 2.0;
   *yCenter = ( header.minExt[ 1 ] + header.maxExt[ 1 ] ) / 2.0;
   *zCenter = ( header.minExt[ 2 ] + header.maxExt[ 2 ] ) / 2.0;      
      
   float gridLength1D = header.maxExt[ 0 ] - header.minExt[ 0 ];   
   *scale = 1.0 / gridLength1D;
   
   *xDim = header.dim[ 0 ];
   *yDim = header.dim[ 1 ];
   *zDim = header.dim[ 2 ];      
   
   int dataTypeSize = ( fileSize - sizeof( header ) ) / ( ( *xDim ) * ( *yDim ) * ( *zDim ) );
   
   int rowLen;
   
   if ( dataTypeSize == 4 ) rowLen = ( *xDim ) * sizeof( float );
   else rowLen = ( *xDim ) * sizeof( double );
   
   unsigned char *buf = ( unsigned char * ) calloc( rowLen, 1 );
   
   if ( buf == NULL )
     {
      fprintf( stderr, "\nError: Failed to allocate temporary buffer space!\n\n" );
      fclose( fp );      
      return 0;      
     }
     
   *vol = ( FFTW_DATA_TYPE * ) malloc( ( *xDim ) * ( *yDim ) * ( *zDim ) * sizeof( FFTW_DATA_TYPE ) );  
   
   if ( *vol == NULL )
     {
      fprintf( stderr, "\nError: Failed to allocate buffer space for reading file *s!\n\n", fileName );
      free( buf );
      fclose( fp );      
      return 0;      
     }   

   FFTW_DATA_TYPE *volPtr = ( FFTW_DATA_TYPE * ) *vol;
   
   for ( int k = 0; k < *zDim; k++ )
     for ( int j = 0; j < *yDim; j++ )
       {
        if ( fread( buf, rowLen, 1, fp ) != 1 )  
          {
           fprintf( stderr, "\nError: Failed to read data from file %s!\n\n", fileName );
           free( buf );           
           free( *vol );
           fclose( fp );      
           return 0;      
          }

        if ( dataTypeSize == 4 )
          {
           if ( !bigEndian( ) )
             {
              for ( int i = 0; i < *xDim; i++ )
                SWAP_32( buf + i * sizeof( float ) );
             }
          
           float *bufPtr = ( float * ) buf;

           for ( int i = 0; i < *xDim; i++ )
              volPtr[ i ] = ( FFTW_DATA_TYPE ) bufPtr[ i ];
          }   
        else  
          {
           if ( !bigEndian( ) )
             {
              for ( int i = 0; i < *xDim; i++ )
                SWAP_64( buf + i * sizeof( double ) );
             }
          
           double *bufPtr = ( double * ) buf;

           for ( int i = 0; i < *xDim; i++ )
              volPtr[ i ] = ( FFTW_DATA_TYPE ) bufPtr[ i ];
          }   
           
        volPtr += ( *xDim );
       }     
     
   free( buf );
   fclose( fp );
 
   printf( "\n\nREAD %s ( xDim = %d, yDim = %d, zDim = %d, xCenter = %lf, yCenter = %lf, zCenter = %lf, scale = %lf, dataTypeSize = %d )!\n\n", 
           fileName, *xDim, *yDim, *zDim, *xCenter, *yCenter, *zCenter, *scale, dataTypeSize );
   
   return 1;
}