/********************************************************************\
|*	Copyright © 1998-99 RasSimTech Ltd.		                    	*|
|*	Printed in the United States of America.                       	*|
|*	All rights reserved.                                           	*|
|*	                                                               	*|
|*	This product or document is protected by copyright and         	*|
|*	distributed under licenses restricting its use,                	*|
|*	copyrightand distribution under licenses restricting           	*|
|*	its use, copying, distribution and decompilation.              	*|
|*	                                                               	*|
|*	No part of this product or document may be reproduced in       	*|
|*	any form by any means without prior written authorization of   	*|
|*	RasSimTech Ltd.							                     	*|
|*	                                                               	*|
\********************************************************************/



#define PROGRAM_NAME		"CTG2AVDS"

#include <io.h>
#include <stdio.h>
#include <sys/types.h>
#include <math.h>
#include <sys/stat.h>
#include <fcntl.h>


#include <CTG2AVDS.h>

void ctg2AVDSColor();
sColor265 MapCTGColors();



double dem_long_min, dem_long_max, dem_lat_min, dem_lat_max;
int 	DEM_cood1,DEM_cood2,DEM_colo,DEM_rowo;

#define MAX_ARRAY (1600)
int		elev_array[MAX_ARRAY][MAX_ARRAY];

int iLatSWCP,iLongSWCP,iLatNWCP,iLongNWCP,iLatNCCP,iLongNCCP,iLatNECP,iLongNECP;
int iLatSECP,iLongSECP,iLatSCCP,iLongSCCP;
char caOutFilename[256];
int iNumRows,iNumCols;


main(argc,argv)
int		argc;
char	*argv[];
{
  double long_00, lat_00, long_0c, lat_0c, long_r0, lat_r0, long_rc, lat_rc;
  double long_min, long_max, lat_min, lat_max;
  double gamma=1.0;

	double dRot,dTransX,dTransY,dSizeX,dSizeY;
	double dOrigX,dOrigY,dMinX,dMinY,dMaxX,dMaxY;
	double dSinRot,dCosRot;
	if ( argc != 7 ) {
		fprintf(stderr,"\n usage: %s ctg_filename Rot(deg) TransX TransY SizeX SizeY \n",argv[0]);
		return(-1);
	}

	dRot = atof(argv[2]);
	dTransX = atof(argv[3]);
	dTransY  = atof(argv[4]);
	dSizeX  = atof(argv[5]);
	dSizeY  = atof(argv[6]);

	ctg2AVDSColor(argv[1]);

	long_min = iLongSWCP/1e4;
	long_max = iLongNECP/1e4;
	lat_min  = iLatSWCP/1e4;
	lat_max  = iLatNECP/1e4;

	dOrigX = (long_max - long_min)/2.0 + long_min;
	dMinX = long_min - dOrigX;
	dMaxX = long_max - dOrigX;

	dOrigY = (lat_max - lat_min)/2.0 + lat_min;
	dMinY = lat_min - dOrigY;
	dMaxY = lat_max - dOrigY;
	
	dSinRot = sin(dRot/57.2958);
	dCosRot = cos(dRot/57.2958);
	
	fprintf(stderr,"long_min = %f \n",long_min);
	fprintf(stderr,"long_max = %f \n",long_max);
	fprintf(stderr,"lat_min = %f \n",lat_min);
	fprintf(stderr,"lat_max = %f \n",lat_max);

	long_00 = (dCosRot*dMinX + dSinRot*dMinY)*dSizeX + (dOrigX + dTransX);
	lat_00  =  (-dSinRot*dMinX + dCosRot*dMinY)*dSizeY + (dOrigY + dTransY);

	long_0c = (dCosRot*dMaxX + dSinRot*dMinY)*dSizeX + (dOrigX + dTransX);
	lat_0c  = (-dSinRot*dMaxX + dCosRot*dMinY)*dSizeY + (dOrigY + dTransY);

	long_r0 = (dCosRot*dMinX + dSinRot*dMaxY)*dSizeX + (dOrigX + dTransX);
	lat_r0  = (-dSinRot*dMinX + dCosRot*dMaxY)*dSizeY + (dOrigY + dTransY);

	long_rc = (dCosRot*dMaxX + dSinRot*dMaxY)*dSizeX + (dOrigX + dTransX);
	lat_rc  = (-dSinRot*dMaxX + dCosRot*dMaxY)*dSizeY + (dOrigY + dTransY);

	fprintf(stderr,"long_00 = %f \n",long_00);
	fprintf(stderr,"lat_00 = %f \n",lat_00);
	fprintf(stderr,"long_0c = %f \n",long_0c);
	fprintf(stderr,"lat_0c = %f \n",lat_0c);
	fprintf(stderr,"long_r0 = %f \n",long_r0);
	fprintf(stderr,"lat_r0 = %f \n",lat_r0);
	fprintf(stderr,"long_rc = %f \n",long_rc);
	fprintf(stderr,"lat_rc = %f \n",lat_rc);
	
	printf("\nPhase 2: Processing Colors\n\n");
 
 
	 if (atl_color(long_00, lat_00, long_0c, lat_0c,
          long_r0, lat_r0, long_rc, lat_rc,
          caOutFilename, iNumRows, iNumCols, gamma) == -1)  {
    fprintf(stderr, "%s: error in calculating shading\n", PROGRAM_NAME);
    exit(-1);
  }

	exit(0);
}







/*  ctg2AVDSColor:
	configures USGS Small Scale (3-arc-second DEM datafiles) for use
	by the AVDS terrain conversion utilities. We obtained the orginal terrain
	data files from the U.S. Geological Survey, National Mapping Information, 
	web site: http://mapping.usgs.gov
*/



#define COLS_OUT (1201)
#define ROWS_OUT (1201)
/* the following are the Type A record position for the indicated information */
#define GRND_COOD_1_1 (22)
#define GRND_COOD_2_1 (GRND_COOD_1_1 + 1)
#define GRND_COOD_3_1 (GRND_COOD_1_1 + 2)
#define GRND_COOD_4_1 (GRND_COOD_1_1 + 3)
#define GRND_COOD_1_2 (GRND_COOD_1_1 + 4)
#define GRND_COOD_2_2 (GRND_COOD_1_1 + 5)
#define GRND_COOD_3_2 (GRND_COOD_1_1 + 6)
#define GRND_COOD_4_2 (GRND_COOD_1_1 + 7)
#define DEMA_ROWS (36)
#define DEMA_COLS (DEMA_ROWS + 1)
/* the following are the Type B record position for the indicated information */
#define DEMB_ROWS (2)
#define DEMB_COLS (DEMB_ROWS + 1)
#define DEMB_MIN_ELEV (7)
#define DEMB_MAX_ELEV (DEMB_MIN_ELEV+1)




void
ctg2AVDSColor(file1)
char	*file1;
{
	FILE	*fp1, *fp2;
	char 	fname1[256];
	char	c;
	int		ii;
	int		scan_ans = 0;

	int iCounter=0;

	char cBuff[81],c2Buff[20];
	int iNumCells,iSizeCell,iNumOverLays,iTypeMap,iProjectionZone,iCodeMapProj,iScalePlot,iDate;
	int iIndexColMin,iIndexRowMin,iIndexColMax,iIndexRowMax,iIndexColSWCP,iIndexRowSWCP;
	int iIndexColNWCP,iIndexRowNWCP,iIndexColNCCP,iIndexRowNCCP,iIndexColNECP,iIndexRowNECP;
	int iIndexColSECP,iIndexRowSECP,iIndexColSCCP,iIndexRowSCCP;

	int iEastingUTMWestCells,iNorthingUTMNorthCells,iDateFileCreation;
	char caTitle[64];	
	int iCount;
	int	iEndFlag = 0;
	int iNumUTMZone,iEastingUTM,iNorthingUTM,iCodeLandUse,iCodePolitical;
	int iCodeHydrological,iCodeCensus,iCodeFederal,iCodeState;
	sColor265 sLandColors;
	sColor265 *sColorGrid;
	short *sColorGridPtr;
	int iColorGridSize;
	int iCellRow,iCellCol;

	int iSizesColor265;
	int iNumBytes;
	iSizesColor265 = sizeof(sColor265);

	cBuff[80] = "";

	sprintf(fname1,"%s",file1);
	if ( (fp1=fopen(fname1,"r")) == NULL ) {
		fprintf(stderr,"\n error:Could not open '%s'\n",fname1);
		exit(-1);
	}
	fprintf(stderr,"\n\nprocessing: %s \n",fname1);

		/* move pointer over the dem quad name */	


	for (iCount=1;iCount<=5;iCount++){
		for (ii=0;ii<80;ii++){
			c = getc(fp1);
			if (c == EOF){
				fprintf(stderr,"error processing: %s \n\n",fname1);
				exit(-1);
			}else{
				cBuff[ii] = c;
			}
		}
			//do process stuff here
		switch(iCount){
			case 1:
				strncpy(c2Buff,&cBuff[0],10);c2Buff[10]=NULL;
				iNumRows = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[10],10);c2Buff[10]=NULL;
				iNumCells = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[20],10);c2Buff[10]=NULL;
				iNumCols = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[35],5);c2Buff[5]=NULL;
				iSizeCell = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[40],5);c2Buff[5]=NULL;
				iNumOverLays = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[45],5);c2Buff[5]=NULL;
				iTypeMap = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[50],5);c2Buff[5]=NULL;
				iProjectionZone = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[55],5);c2Buff[5]=NULL;
				iCodeMapProj = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[60],5);c2Buff[5]=NULL;
				iScalePlot = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[70],10);c2Buff[10]=NULL;
				iDate = atoi(c2Buff);
				iColorGridSize = iNumRows*iNumCols*iSizesColor265;
				sColorGrid = (int *)MALLOC(iColorGridSize);
				memset( (char*)sColorGrid, 0, iColorGridSize);

				break;
			case 2:
				strncpy(c2Buff,&cBuff[0],5);c2Buff[5]=NULL;
				iIndexColMin = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[5],5);c2Buff[5]=NULL;
				iIndexRowMin = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[10],5);c2Buff[5]=NULL;
				iIndexColMax = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[15],5);c2Buff[5]=NULL;
				iIndexRowMax = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[20],5);c2Buff[5]=NULL;
				iIndexColSWCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[25],5);c2Buff[5]=NULL;
				iIndexRowSWCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[30],5);c2Buff[5]=NULL;
				iIndexColNWCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[35],5);c2Buff[5]=NULL;
				iIndexRowNWCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[40],5);c2Buff[5]=NULL;
				iIndexColNCCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[45],5);c2Buff[5]=NULL;
				iIndexRowNCCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[50],5);c2Buff[5]=NULL;
				iIndexColNECP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[55],5);c2Buff[5]=NULL;
				iIndexRowNECP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[60],5);c2Buff[5]=NULL;
				iIndexColSECP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[65],5);c2Buff[5]=NULL;
				iIndexRowSECP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[70],5);c2Buff[5]=NULL;
				iIndexColSCCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[75],5);c2Buff[5]=NULL;
				iIndexRowSCCP = atoi(c2Buff);
				break;
			case 3:					// note that longitude have a minus sign infront of them
				strncpy(c2Buff,&cBuff[0],10);c2Buff[10]=NULL;
				iLatSWCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[10],10);c2Buff[10]=NULL;
				iLongSWCP = -atoi(c2Buff);
				strncpy(c2Buff,&cBuff[20],10);c2Buff[10]=NULL;
				iLatNWCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[30],10);c2Buff[10]=NULL;
				iLongNWCP = -atoi(c2Buff);
				strncpy(c2Buff,&cBuff[40],10);c2Buff[10]=NULL;
				iLatNCCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[50],10);c2Buff[10]=NULL;
				iLongNCCP = -atoi(c2Buff);
				strncpy(c2Buff,&cBuff[60],10);c2Buff[10]=NULL;
				iLatNECP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[70],10);c2Buff[10]=NULL;
				iLongNECP = -atoi(c2Buff);
				break;
			case 4:
				strncpy(c2Buff,&cBuff[0],10);c2Buff[10]=NULL;
				iLatSECP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[10],10);c2Buff[10]=NULL;
				iLongSECP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[20],10);c2Buff[10]=NULL;
				iLatSCCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[30],10);c2Buff[10]=NULL;
				iLongSCCP = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[40],10);c2Buff[10]=NULL;
				iEastingUTMWestCells = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[50],10);c2Buff[10]=NULL;
				iNorthingUTMNorthCells = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[60],10);c2Buff[10]=NULL;
				iDateFileCreation = atoi(c2Buff);
				break;
			default:
			case 5:
				strncpy(caTitle,&cBuff[0],64);c2Buff[64]=NULL;
				break;
		}
	}

	fprintf(stderr,"\n Reading and Converting Land Use \n\n",caOutFilename); 

	while (!iEndFlag){
			for (ii=0;ii<80;ii++){
				c = getc(fp1);
				if (c == EOF){
					fprintf(stderr,"error processing: %s \n\n",fname1);
					iEndFlag=1;
				}else{
					cBuff[ii] = c;
				}
			}
			if (!iEndFlag){
				strncpy(c2Buff,&cBuff[0],3);c2Buff[3]=NULL;
				iNumUTMZone = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[3],8);c2Buff[8]=NULL;
				iEastingUTM = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[11],8);c2Buff[8]=NULL;
				iNorthingUTM = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[20],10);c2Buff[10]=NULL;
				iCodeLandUse = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[30],10);c2Buff[10]=NULL;
				iCodePolitical = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[40],10);c2Buff[10]=NULL;
				iCodeHydrological = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[50],10);c2Buff[10]=NULL;
				iCodeCensus = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[60],10);c2Buff[10]=NULL;
				iCodeFederal = atoi(c2Buff);
				strncpy(c2Buff,&cBuff[70],10);c2Buff[10]=NULL;
				iCodeState = atoi(c2Buff);
				sLandColors = MapCTGColors(iCodeLandUse);
				iCellRow = (int)(((iNorthingUTMNorthCells+iSizeCell/2) - iNorthingUTM)/iSizeCell);
				iCellRow = iNumRows - iCellRow + 1;	// put last row first in file
				iCellCol = (int)((iEastingUTM - (iEastingUTMWestCells-iSizeCell/2))/iSizeCell);
				sColorGridPtr = (short*)((int)sColorGrid +
                              (iCellRow-1)*iNumCols*iSizesColor265 +
                              (iCellCol-1)*iSizesColor265);
				memcpy( sColorGridPtr, &sLandColors, iSizesColor265 );
				iCounter++;
			}
		}
	sprintf(caOutFilename,"%s.%04dx%04d",fname1,iNumRows,iNumCols);
	if ( (fp2=open(caOutFilename, O_RDWR|_O_BINARY|_O_CREAT  )) == -1 ) {
		fprintf(stderr,"\n error: Could not open '%s'\n",caOutFilename);
		exit(-1);
	}
	fprintf(stderr,"\rwriting file:[%s] \n\n",caOutFilename); 
	_lseek( fp2, 0, SEEK_SET );
	iNumBytes = _write(fp2, (char *)sColorGrid, iColorGridSize);
	close(fp2);
	free(sColorGrid);
	fprintf(stderr,"\n\n Conversion Saved to file: %s \n",caOutFilename); 
	fclose(fp1);
	fprintf(stderr,"\n"); 
	fprintf(stderr," Count = %i \n",iCounter);
	return;
}


sColor265
MapCTGColors(int iLandUse){

	switch(iLandUse){
			case 1:	//Urban or Built-up Land	
				saCTGColors.ucRed = 200;
				saCTGColors.ucGreen = 200;
				saCTGColors.ucBlue = 200;
				break;
			case 11:	//Residential
				saCTGColors.ucRed = 200;
				saCTGColors.ucGreen = 200;
				saCTGColors.ucBlue = 200;
				break;
			case 12:	//Commercial and Services
				saCTGColors.ucRed = 175;
				saCTGColors.ucGreen = 175;
				saCTGColors.ucBlue = 175;
				break;
			case 13:		//Industrial
				saCTGColors.ucRed = 150;
				saCTGColors.ucGreen = 150;
				saCTGColors.ucBlue = 150;
				break;
			case 14:		//Transportation, Communications and Utilities
				saCTGColors.ucRed = 125;
				saCTGColors.ucGreen = 125;
				saCTGColors.ucBlue = 125;
				break;
			case 15:		//Industrial and Commercial Complexes
				saCTGColors.ucRed = 100;
				saCTGColors.ucGreen = 100;
				saCTGColors.ucBlue = 100;
				break;
			case 16:		//Mixed Urban or Built-up Land
				saCTGColors.ucRed = 75;
				saCTGColors.ucGreen = 75;
				saCTGColors.ucBlue = 75;
				break;
			case 17:		//Other Urban or Built-up Land
				saCTGColors.ucRed = 50;
				saCTGColors.ucGreen = 50;
				saCTGColors.ucBlue = 50;
				break;

			case 2:	//Agricultural Land	
				saCTGColors.ucRed = 0;
				saCTGColors.ucGreen = 100;
				saCTGColors.ucBlue = 0;
				break;
			case 21:	//	Cropland and Pasture
				saCTGColors.ucRed = 25;
				saCTGColors.ucGreen = 125;
				saCTGColors.ucBlue = 25;
				break;
			case 22:	//	Orchards, Groves, Vineyards, Nurseries, and Ornamental Horticultural Areas
				saCTGColors.ucRed = 50;
				saCTGColors.ucGreen = 150;
				saCTGColors.ucBlue = 50;
				break;
			case 23:	//	Confined Feeding Operations
				saCTGColors.ucRed = 75;
				saCTGColors.ucGreen = 175;
				saCTGColors.ucBlue = 75;
				break;
			case 24:	//	Other Agricultural Land
				saCTGColors.ucRed = 100;
				saCTGColors.ucGreen = 200;
				saCTGColors.ucBlue = 100;
				break;

			case 3:	//Rangeland	
				saCTGColors.ucRed = 120;
				saCTGColors.ucGreen = 125;
				saCTGColors.ucBlue = 100;
				break;
			case 31:	//	Herbaceous Rangeland
				saCTGColors.ucRed = 220;
				saCTGColors.ucGreen = 210;
				saCTGColors.ucBlue = 155;
				break;
			case 32:	//	Shrub and Brush Rangeland
				saCTGColors.ucRed = 145;
				saCTGColors.ucGreen = 140;
				saCTGColors.ucBlue = 105;
				break;
			case 33:	//	Mixed Rangeland
				saCTGColors.ucRed = 160;
				saCTGColors.ucGreen = 150;
				saCTGColors.ucBlue = 120;
				break;

			case 4:	//Forest Land	
				saCTGColors.ucRed = 0;
				saCTGColors.ucGreen = 100;
				saCTGColors.ucBlue = 50;
				break;
			case 41:	//	Deciduous Forest Land
				saCTGColors.ucRed = 50;
				saCTGColors.ucGreen = 140;
				saCTGColors.ucBlue = 100;
				break;
			case 42:	//	Evergreen Forest Land
				saCTGColors.ucRed = 100;
				saCTGColors.ucGreen = 120;
				saCTGColors.ucBlue = 90;
				break;
			case 43:	//	Mixed Forest Land
				saCTGColors.ucRed = 45;
				saCTGColors.ucGreen = 120;
				saCTGColors.ucBlue = 30;
				break;

			case 5:	//Water	
				saCTGColors.ucRed = 0;
				saCTGColors.ucGreen = 0;
				saCTGColors.ucBlue = 200;
				break;
			case 51:	//	Streams and Canals
				saCTGColors.ucRed = 50;
				saCTGColors.ucGreen = 50;
				saCTGColors.ucBlue = 200;
				break;
			case 52:	//	Lakes
				saCTGColors.ucRed = 120;
				saCTGColors.ucGreen = 155;
				saCTGColors.ucBlue = 235;
				break;
			case 53:	//	Reservoirs
				saCTGColors.ucRed = 80;
				saCTGColors.ucGreen = 125;
				saCTGColors.ucBlue = 230;
				break;
			case 54:	//	Bays and Estuaries
				saCTGColors.ucRed = 50;
				saCTGColors.ucGreen = 180;
				saCTGColors.ucBlue = 240;
				break;

			case 6:	//Wetland	
				saCTGColors.ucRed = 50;
				saCTGColors.ucGreen = 100;
				saCTGColors.ucBlue = 0;
				break;
			case 61:	//	Forested Wetland
				saCTGColors.ucRed = 150;
				saCTGColors.ucGreen = 200;
				saCTGColors.ucBlue = 205;
				break;
			case 62:	//	Nonforested Wetland
				saCTGColors.ucRed = 150;
				saCTGColors.ucGreen = 200;
				saCTGColors.ucBlue = 175;
				break;

			case 7:	//Barren Land	
				saCTGColors.ucRed = 150;
				saCTGColors.ucGreen = 150;
				saCTGColors.ucBlue = 100;
				break;
			case 71:	//	Dry Salt Flats
				saCTGColors.ucRed = 200;
				saCTGColors.ucGreen = 200;
				saCTGColors.ucBlue = 200;
				break;
			case 72:	//	Beaches
				saCTGColors.ucRed = 225;
				saCTGColors.ucGreen = 225;
				saCTGColors.ucBlue = 225;
				break;
			case 73:	//	Sandy Areas Other than Beaches
				saCTGColors.ucRed = 210;
				saCTGColors.ucGreen = 225;
				saCTGColors.ucBlue = 210;
				break;
			case 74:	//	Bare Exposed Rock
				saCTGColors.ucRed = 225;
				saCTGColors.ucGreen = 190;
				saCTGColors.ucBlue = 150;
				break;
			case 75:	//	Strip Mines, Quarries, and Gravel Pits
				saCTGColors.ucRed = 210;
				saCTGColors.ucGreen = 165;
				saCTGColors.ucBlue = 110;
				break;
			case 76:	//	Transitional Areas
				saCTGColors.ucRed = 190;
				saCTGColors.ucGreen = 225;
				saCTGColors.ucBlue = 125;
				break;
			case 77:	//	Mixed Barren Land
				saCTGColors.ucRed = 175;
				saCTGColors.ucGreen = 175;
				saCTGColors.ucBlue = 125;
				break;

			case 8:	//Tundra	
				saCTGColors.ucRed = 150;
				saCTGColors.ucGreen = 100;
				saCTGColors.ucBlue = 150;
				break;
			case 81:	//	Shrub and Brush Tundra
				saCTGColors.ucRed = 175;
				saCTGColors.ucGreen = 125;
				saCTGColors.ucBlue = 175;
				break;
			case 82:	//	Herbaceous Tundra
				saCTGColors.ucRed = 200;
				saCTGColors.ucGreen = 150;
				saCTGColors.ucBlue = 200;
				break;
			case 83:	//	Bare Ground
				saCTGColors.ucRed = 225;
				saCTGColors.ucGreen = 175;
				saCTGColors.ucBlue = 225;
				break;
			case 84:	//	Wet Tundra
				saCTGColors.ucRed = 225;
				saCTGColors.ucGreen = 175;
				saCTGColors.ucBlue = 225;
				break;
			case 85:	//	Mixed Tundra
				saCTGColors.ucRed = 225;
				saCTGColors.ucGreen = 175;
				saCTGColors.ucBlue = 225;
				break;

			case 9:	//Perennial Snow or Ice	91	Perennial Snowfields
				saCTGColors.ucRed = 250;
				saCTGColors.ucGreen = 250;
				saCTGColors.ucBlue = 250;
				break;
			case 92:	//	Glaciers
				saCTGColors.ucRed = 250;
				saCTGColors.ucGreen = 250;
				saCTGColors.ucBlue = 250;
				break;
			default:	//	brown
				saCTGColors.ucRed = 208;
				saCTGColors.ucGreen = 202;
				saCTGColors.ucBlue = 121;
				break;
		}

	saCTGColors.ucAlpha = 250;
	return(saCTGColors);
}