... char path[256] = ... // path of the GLI file to read int x=0, y=0, z=0 ; // volume resolution float org_x, org_y, org_z ; // volume origin float inc_x, inc_y, inc_z ; // voxel dimensions float *voxel ; // voxel values // --- Open the GLI file --- FILE *fi = fopen( path, "rb" ) ; if ( ! fi ) { // ... some error message here ... return( NULL ) ; } // ----------------------------------- // --- read the header of the file --- // ----------------------------------- // --- loop until the header is terminated --- for ( int go=1; go; ) { char str[180] ; // --- create the next label/value pair --- while( 1 ) { // --- read the next character --- int in = getc( fi ) ; // --- EOF in the header? something's wrong! --- if ( in == EOF ) { // ... some error message here ... return( NULL ) ; } // --- 0x0C (FF) --> end of the header --- if ( (char) in == 0x0C ) { str[i] = NULL ; go = NULL ; break ; } // --- 0x0A (CR) --> end of the line --- if ( (char) in == 0x0A ) { str[i] = NULL ; break ; } // --- space --> label/value pair separator --- if ( (char) in == ' ' ) { str[i] = NULL ; break ; } } // --- skip any empty strings --- if ( ! *str ) continue ; // --- now analyse this pair. Look for the ":" separator --- char *label = str ; char *value ; for ( value = str; value != ':'; value++ ) // --- if there is no ":" in the string, it is invalid! --- if ( ! value ) { // ... some error message here ... return( NULL ) ; } // --- insert a NULL to split the pair --- *value++ = NULL ; // --- search for the label key word --- if ( ! strcmp( label, "x" ) ) x = atoi( value ) ; else if ( ! strcmp( label, "y" ) ) y = atoi( value ) ; else if ( ! strcmp( label, "z" ) ) z = atoi( value ) ; else if ( ! strcmp( label, "org_x" ) ) org_x = atof( value ) ; else if ( ! strcmp( label, "org_y" ) ) org_y = atof( value ) ; else if ( ! strcmp( label, "org_z" ) ) org_z = atof( value ) ; else if ( ! strcmp( label, "inc_x" ) ) inc_x = atof( value ) ; else if ( ! strcmp( label, "inc_y" ) ) inc_y = atof( value ) ; else if ( ! strcmp( label, "inc_z" ) ) inc_z = atof( value ) ; } // ----------------------------------- // --- read the voxels --- // ----------------------------------- // --- we should have x,y,z values --- if ( (! x) || (! y) || (! z) ) { // ... some error message here ... return( NULL ) ; } // --- prepare memory for the voxels --- voxel = (float *) calloc( x * y * z * sizeof(float) ) ; if ( ! voxel ) { // ... some error message here ... return( NULL ) ; } int size = fread( voxel, sizeof(float), x * y * z, fi ) ; if ( size != x * y * z ) { // ... some error message here ... return( NULL ) ; } fclose( fi ) ; ...