#!/usr/bin/perl 

# script to create a google earth script (.KML) of summed Annual NPP data available from the University of Maryland Global Land Cover Facility. By arlduc (arlduc@amnh.org)

my ($one, $two, $three, $four, $five, $six, $seven, $eight, $north, $south, $east, $west, $i);

$north = "90";
$south = "-90";
$east = "180";
$west = "-180";
$frameCtr = 0;

open ( SCRIPT_OUT, ">UMD_GLCF_SummedAnnualNPP.kml" );

#lines to print out script headers
printf SCRIPT_OUT ("<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n <kml xmlns=\"http://earth.google.com/kml/2.1\"> \n\n");
printf SCRIPT_OUT ("kml script by Arlene Ducao, Science Bulletins, AMNH \narlduc@amnh.org\n\n");

printf SCRIPT_OUT ("<Folder> \n<open>1</open>");
printf SCRIPT_OUT ("<name> Summed Annual Net Primary Productivity</name> \n");
printf SCRIPT_OUT ("<description>images from http://glcfapp.umiacs.umd.edu:8080/esdi/index.jsp</description> \n\n");


#while-loop to go through each line of the dataset
for ($i=1981; $i<2001; $i++) {

		printf SCRIPT_OUT ("<GroundOverlay>\n");
		printf SCRIPT_OUT ("<name> %s </name>\n", $i);
		printf SCRIPT_OUT ("<visibility>1</visibility>\n");
		printf SCRIPT_OUT ("<Icon>\n");
		printf SCRIPT_OUT ("http://www.arlduc.org/3dAnim/AMNH/googleEarth/UMD_GLCF_SummedAnnualNPP/%s_npp_latlon.browse.jpg\n", $i);
	  	printf SCRIPT_OUT ("</Icon>\n");
	  	printf SCRIPT_OUT ("<LatLonBox>\n");
		printf SCRIPT_OUT ("<north>%s</north>\n", $north);
		printf SCRIPT_OUT ("<south>%s</south>\n", $south);
		printf SCRIPT_OUT ("<east>%s</east>\n", $east);
		printf SCRIPT_OUT ("<west>%s</west>\n", $west);
		printf SCRIPT_OUT ("<rotation>0</rotation>\n");
	  	printf SCRIPT_OUT ("</LatLonBox>\n");
	  	printf SCRIPT_OUT ("<TimeSpan>\n");
		printf SCRIPT_OUT ("<begin> %s </begin>\n", $i);
		#printf SCRIPT_OUT ("<end>2004-12-31</end>\n");
	  	printf SCRIPT_OUT ("</TimeSpan>\n");
		printf SCRIPT_OUT ("</GroundOverlay>\n\n\n\n");	

}

printf SCRIPT_OUT ("</Folder> \n");
printf SCRIPT_OUT ("</kml>");

printf STDOUT ("written to specified KML file.\n");
