<%@ Page Language="c#" Debug="true" ContentType="image/jpeg" runat="server" Inherits="Generic.GetJpeg" CodeFile="GetJpeg.aspx.cs" %>
<%@ Import Namespace="GenericImgCutout" %>
<%  

//******************************************************************
    // GetJpeg(ra, dec, zoom, height, width, [opt])
    // A wrapper for the method ImgCutout.GetJpeg().
	// Sample invocation:
	//    http://.../ImgCutout/GetJpeg.aspx?ra=195&dec=2.5&ppd=90000&height=201&width=301
	//
	// declare parameters
		
	double	ra		= 0;			// the right ascension in degrees [0..360]
	double	dec		= 0;			// the declination in degrees [-90..90]
	double  scale	= 0.396127;		// pixel scale in arcsec/pixel [60...240,000]
	Int32	height	= 128;			// pixel height of image
	Int32	width	= 128;			// pixel width of image
	string  opt		= "";			// drawing options
	string  rid		= "";			// list of regionids
	string  param	= "";
	string  query	= "";
	
	// parse required parameters and throw exception if missing.
	try {
		ra	   =  Double.Parse(Request[param = "ra"]);
		dec	   =  Double.Parse(Request[param = "dec"]);
		}
	catch{ throw (new System.ArgumentException("missing parameter: "+ param + 
			"ra must be in [0,360], dec must be in [-90..90], scale must be in [60...240000], height and width must be in [16...2048]"));
		}

	try { scale  =  Double.Parse (Request[param = "scale"]); } catch{;}
	try { height =  Int32.Parse  (Request[param = "height"]); } catch{;}
	try { width  =  Int32.Parse  (Request[param = "width" ]); } catch{;}
	

	if (Request["opt"] != null)   opt = Request["opt"];
	if (Request["rid"] != null)   rid = Request["rid"];
	if (Request["query"] != null)   query = Request[param = "query"];
	
	// Invoke web method and return its response.
	try{
        ImgCutout cutout = new ImgCutout();
		Response.BinaryWrite(cutout.GetJpeg(ra, dec, scale, height, width, opt, rid, query));
		}
	catch{Response.Redirect("noimage.jpg");}
%>
