#define SDESERVER "myserver"
#define SDEINSTANCE "myinstance"
#define SDEDATABASE "mydatabase"
#define SDEUSER	"myuser"
#define SDEPASSWORD "mypassword"
#define TABLE "myrastertable"
#define COLUMN "raster"

#include <stdlib.h>
#include <string.h>
#include "sdetype.h"
#include "sderaster.h"
#include "raster_source.h"

void main ( void) {

	SE_CONNECTION connection;
	SE_ERROR error;
	SE_STREAM stream;
	CHAR **columns,
	table[SE_MAX_TABLE_LEN],
	name_value[] = "ESRI_SDERASTERDATASET",
			*server,
			*instance,
			*database,
			*username,
			*password; 
	LONG rc,
	row_id = 1;
	SHORT name_ind = SE_IS_NOT_NULL_VALUE,
      	      raster_ind = SE_IS_NOT_NULL_VALUE,
      	      num_columns = 2;
	SE_RASTERATTR raster_attrib;

	/* set the business table */

	strcpy(table,TABLE);

	/* Set the ArcSDE server connection info. */
	
	server = SDESERVER;
	instance = SDEINSTANCE;
	database = SDEDATABASE;
	username = SDEUSER;
	password = SDEPASSWORD;

	/* Connect to the ArcSDE server  */

	rc = SE_connection_create (server,instance,database,username,password,&error,&connection);
	check_error (rc, connection,NULL,"SE_connection_create");

	/* Create and initialize the stream */

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

	/* Populate the column names */

	columns = (CHAR **) malloc (num_columns * sizeof(CHAR *));
	columns[0] = "name";
	columns[1] = COLUMN;

	/* Setup the stream update */

	rc = SE_stream_update_row (stream, table, &row_id, num_columns, (const CHAR **)columns);
	check_error (rc, NULL, stream, "SE_stream_update_row");

	/* Bind the NAME column */

	rc = SE_stream_bind_input_column (stream, 1, name_value, &name_ind);
	check_error (rc, NULL, stream, "SE_stream_bind_input_column");

	/* Initialize the raster attribute structure */

	rc = SE_rasterattr_create (&raster_attrib,TRUE);
	check_error (rc, NULL, NULL, "SE_rasterattr_create");

	/* To remove an existing pyramid set the level 0 and */
	/* the interpolation to SE_INTERPOLATION_NONE        */
	/* To remove the pyramid, uncomment this code        */

	/* rc = SE_rasterattr_set_pyramid_info (raster_attrib, 0, FALSE, SE_INTERPOLATION_NONE); */
	/* check_error (rc, NULL, NULL, "SE_rasterattr_set_pyramid_info");                       */

	/* To allow ArcSDE to automatically calculate the apex of the pyramid set the level */
        /* to SE_PYRAMID_AUTO_LEVEL and the interpolation either SE_INTERPOLATION_NEAREST,  */
	/* SE_INTERPOLATION_BILINEAR, or SE_INTERPOLATION_BICUBIC. Space can be saved by    */
        /* setting the skip1level parameter to TRUE                                         */
	/* To build the pyramid: uncomment this code.                                       */

	/* rc = SE_rasterattr_set_pyramid_info (raster_attrib,             */
        /*                                      SE_PYRAMID_AUTO_LEVEL,     */
        /*                                      TRUE,                      */
        /*                                      SE_INTERPOLATION_NEAREST); */
	/* check_error (rc, NULL, NULL, "SE_rasterattr_set_pyramid_info"); */

	/* Bind the raster attribute structure to the RASTER column */

	rc = SE_stream_bind_input_column (stream,2,(void *) raster_attrib,&raster_ind);
	check_error (rc, NULL, stream, "SE_stream_bind_input_column");

	/* Execute the pyramid update */

	rc = SE_stream_execute (stream);
	check_error (rc, NULL, stream, "SE_stream_execute");

	/*********/
	/* Cleanup */
	/*********/

	SE_rasterattr_free (raster_attrib);
	SE_stream_free (stream);
	SE_connection_free (connection);

}