typedef struct {
   LONG minx;
   LONG miny;
   LONG maxx;
   LONG maxy;
   LONG level;
} TILEENV;


SE_RASCONSTRAINT rasconstraint;
SE_RASTILEINFO rastile_info;
SE_RASTERATTR raster_attrib;

TILEENV tileenv;


get_tile_envelope(raster_attrib,&tileenv);


rc = SE_rasconstraint_set_envelope ( rasconstraint, 
                                     tileenv.minx, 
                                     tileenv.minx, 
                                     tileenv.maxx, 
                                     tileenv.maxy);
check_error (rc, NULL, NULL, "SE_rasconstraint_set_envelope");

band_numbers = malloc(sizeof(LONG) * number_of_bands);

for (i=0; i<number_of_bands; i++)
   band_numbers[i] = i+1;

/* set the bands to be queried */

rc = SE_rasconstraint_set_bands ( rasconstraint, number_of_bands, band_numbers);
check_error (rc, NULL, NULL, "SE_rasconstraint_set_bands");

free(band_numbers);

/* Query the specified pyramid level */

rc = SE_rasconstraint_set_level (rasconstraint, tileenv.level);
check_error (rc, NULL, NULL, "SE_rasconstraint_set_level");


/*********************/
/* Create the stream */
/*********************/

rc = SE_stream_create(connection,&stream);
check_error (rc, connection, NULL, "SE_rasconstraint_set_level");


/***************************/
/*  Query the raster tile  */
/***************************/

rc = SE_stream_query_raster_tile (stream, rasconstraint);
check_error ( rc, NULL, stream, "SE_stream_query_raster_tile");

/********************************************************************/
/*  Fetch and display the tiles for the all the bands of the image  */
/********************************************************************/

max_tiles = number_of_bands * (tileenv.maxx - tileenv.minx + 1) * (tileenv.maxy - tileenv.miny + 1);

for (tiles=0; tiles<max_tiles; tiles++) {

	rc = SE_stream_get_raster_tile (stream, rastile_info);
	check_error ( rc, NULL, stream, "SE_stream_get_raster_tile");

	/* Display the tile info */

	rc = SE_rastileinfo_get_band_id (rastile_info,&band_id);
	check_error ( rc, NULL, stream, "SE_rastileinfo_get_band_id");

	printf("\n\nTile raster band id: %d\n",band_id);

	/* Print the upper left pixel position, or row column */
	/* of the tile                                        */

	rc = SE_rastileinfo_get_rowcol (rastile_info, &row, &column);
	check_error ( rc, NULL, stream, "SE_rastileinfo_get_rowcol");

	printf ("Tile row: %d column: %d\n",row,column);

	/* Display the tile's the pyramid level */

	rc = SE_rastileinfo_get_level (rastile_info, &level);
	check_error ( rc, NULL, stream, "SE_rastileinfo_get_level");

	printf ("Tile level: %d\n",level);

	/* Display the tile's pixel data */

	rc = SE_rastileinfo_get_pixel_data (rastile_info, (void *) &pixel_buffer, &length);
	check_error ( rc, NULL, stream, "SE_rastileinfo_get_pixel_data");

	print_pixels (pixel_type, pixels_per_tile, pixel_buffer, length);

	printf("\n\n");

} /* for loop for tiles */

/* Release the SE_RASCONSTRAINT structure */

SE_rasconstraint_free (rasconstraint);

/* Release the SE_RASTILEINFO structure. */

SE_rastileinfo_free (rastile_info);