/*----------------------------------------------------------------

Hit ctrl-enter to execute.

Description:

	Demonstration script for image management.
	by Chris Meyer, Oct 97.  
	Copyright Gatan Inc.
	Further annotations by Paul Thomas, March 2001

-----------------------------------------------------------------*/

/* First, print out the names of the open images */

// Get the id number of the frontmost image
number id = getfrontimageid()						

// While the id no. is non-zero, loop through the image id's
while ( id != 0 )
{
	result( "OPEN: " )

	// Check to see that image is real
	if ( isimagereal( id ) )
	{
		// Get the image from its id no 
		image img := getimagefromid( id )

		// Get its name and place in results window
		result( "Real: " + getname( img ) + "\n" )
	}
	else
	if ( isimagecomplex( id ) )
	{
		// Perform the same procedure for complex images...
		compleximage img := getimagefromid( id )
		result( "Complex: " + getname( img ) + "\n" )
	}
	else
	{	
		// and also for RGB iimages
		rgbimage img := getimagefromid( id )
		result( "RGB: " + getname( img ) + "\n" )
	}

	// Get the next images id no using the GetNextImageID function
	id = getnextimageid( id )
}


/* Now, print out the names of all images (includes hidden images) */

// Find out how many images are loaded
number count = CountImages()

number i

// Loop through each image
for ( i=0; i < count; i++ )
{
	result( "ALL: " )
	// Get the image id no for the n'th image
	number id = getnthimageid( i )

	// Check to see if the i'th image is real...
	if ( isimagereal( id ) )
	{
		// If so, get the image and post its name to the results window..
		image img := getimagefromid( id )
		result( "Real: " + getname( img ) + "\n" )
	}
	else
	// and likewise for complex images...
	if ( isimagecomplex( id ) )
	{
		compleximage img := getimagefromid( id )
		result( "Complex: " + getname( img ) + "\n" )
	}
	else
	{	
		// and RGB images
		rgbimage img := getimagefromid( id )
		result( "RGB: " + getname( img ) + "\n" )
	}
}
