/********************************************************************\
|*	Portons 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.							                     	*|
|*	                                                               	*|
\********************************************************************/
/************************************************************************\
|*	Copyright © 1997 Artificial Horizons, Inc..                    	*|
|*	Printed in the United States of America.                       	*|
|*	44 Montgomery. Suite 1480, San Francisco, CA, 94104 U.S.A.     	*|
|*	All rights reserved.                                           	*|
|*	                                                               	*|
|*	This product or document is protected by copyright and         	*|
|*	distributed under licenses restricting its use,                	*|
|*	copyright and 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   	*|
|*	Artificial Horizons, Inc. and its licensors.                   	*|
|*	                                                               	*|
|*	Artificial Horizons, Aviator, AVDS, FlightCam, ChaseCam,       	*|
|*	and TowerCam are trademarks or registered trademarks of        	*|
|*	of Artificial Horizons, Inc.                                   	*|
\************************************************************************/

 /***************************************************************************\
|*                                                                           *|
|* Copyright © 1989-1992 by Artificial Horizons®, Inc.  All rights reserved. *|
|*                                                                           *|
|*     This material  constitutes  the trade  secrets  and confidential,     *|
|*     proprietary information of Bruce Factor and Curtis Priem,  and is     *|
|*     under license  to Artificial Horizons, Inc.   The material is not     *|
|*     to be disclosed,  reproduced,  copied,  or used in any manner not     *|
|*     permitted under license from Artificial Horizons, Inc.   For more     *|
|*     information email "ahi-interest@ahi.com".                             *|
|*                                                                           *|
 \***************************************************************************/

#define PROGRAM_NAME		"PROCESSCOLORELEVATION"

#include <stdio.h>
#include <sys/types.h>
#include <math.h>

#include <atl.h>


int 	DEM_cood1,DEM_cood2,DEM_colo,DEM_rowo;
double dLong_00, dLat_00, dLong_0c, dLat_0c, dLong_r0, dLat_r0, dLong_rc, dLat_rc;

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



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;
	int iLevels;
	double gamma, time_of_day;
	Atl_color color[2];

	if ( argc != 6 ) {
		fprintf(stderr,"\n usage: %s long_min long_max lat_min lat_max levels\n",argv[0]);
		return(-1);
	}

	long_min = atof(argv[1]);
	long_max = atof(argv[2]);
	lat_min  = atof(argv[3]);
	lat_max  = atof(argv[4]);
	iLevels  = atoi(argv[5]);

	long_00  = long_min;
	lat_00   = lat_min;
	long_0c  = long_max;
	lat_0c   = lat_min;
	long_r0  = long_min;
	lat_r0   = lat_max;
	long_rc  = long_max;
	lat_rc   = lat_max;

	/***** calculate shading *****/
	color[0].red   =  190;  color[1].red   = 150;
	color[0].green = 195;  color[1].green = 155;
	color[0].blue  =  180;  color[1].blue  = 125;
	//time_of_day = 15.5;  /* 3:30 pm */
	time_of_day = 14.5;  /* 4:30 pm */
	printf("\nPhase 2: calculate shading\n\n");
	if (atl_shading(long_00, lat_00, long_0c, lat_0c,
				  long_r0, lat_r0, long_rc, lat_rc,
				  color, time_of_day) == -1)  {
		fprintf(stderr, "%s: error in calculating shading\n", PROGRAM_NAME);
		exit(-1);
	}


	/***** elevation postprocessing *****/
	printf("\nPhase 3: elevation postprocessing\n\n");
	if (atl_elevation_post(long_00, lat_00, long_0c, lat_0c,
						 long_r0, lat_r0, long_rc, lat_rc) == -1)  {
		fprintf(stderr, "%s: error in elevation postprocessing\n", PROGRAM_NAME);
		exit(-1);
	}

	/***** 8 bit color postprocessing *****/
	printf("\nPhase 5: 8 bit color postprocessing\n\n");
	gamma = 2.50;
	if (atl_color_post(long_00, lat_00, long_0c, lat_0c,
					 long_r0, lat_r0, long_rc, lat_rc,
					 gamma, ATL_COLOR8|ATL_BLUE_WATER) == -1)  {
		fprintf(stderr, "%s: error in 8 bit color postprocessing\n", PROGRAM_NAME);
		return(-1);
	}

	if (iLevels){
		printf("\nPhase 6: Converting multiple detail level terrain file into lower detail level files\n\n");
		if (atl_pclevels(long_00, lat_00, long_0c, lat_0c,
                         long_r0, lat_r0, long_rc, lat_rc) == -1)  {
			fprintf(stderr, "%s: error converting multiple detail level terrain file into lower detail level files\n", PROGRAM_NAME);
			return(-1);
		}
	}
	
	return(0);
}