Location: PHPKode > projects > MM5 User Interface > mui_pack/mui/graph.php
<html>

<head>
<meta http-equiv="Content-Type" content="text/html">
<title>:: graph ::</title>
</head>

<body background="images/barbkgde.gif" link="#000000" vlink="#000000" alink="#000000" onload="AddtoCmbBox()">
<script language="javascript">
function popUps(URL,sw,sh) {
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+sw+",height="+sh+"');");
	}

function Choice(x){
	if(x==1)document.forms[0].formtype.value=4;
	else if(x==2) document.forms[0].formtype.value=5;
	else if(x==3) document.forms[0].formtype.value=6;
	else if(x==4){
		if( (document.forms[0].EdtHid1.value==0)&& (document.forms[0].EdtHid2.value==0)&&(document.forms[0].EdtHid3.value==0) )
			{
			alert("you must set at least one field !");
			document.forms[0].formtype.value=2;
			return 1;
			}
		var parameters="toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizeable=0,height=600,width=800";
		var runpath=document.forms[0].EdtHidRunDate.value;
		runpath=runpath.replace("/","_");
		runpath=runpath.replace("/","_");
		runpath=runpath+"/"+document.forms[0].EdtHidRunRun.value;
		UserID=document.forms[0].EdtHidID.value;
		GraphRunName=document.forms[0].GraphRunName.value;
		addr="cgi/graphout.php?gpath="+runpath+"&userid="+UserID+"&grunname="+GraphRunName;
		graphWindow=open(addr,"newDocument",parameters);
		window.close();
	    }

	}

function Type(){
	if(document.forms[0].CmbBoxType.selectedIndex==2)
		{
		document.forms[0].EdtLevel.value="";
		document.forms[0].EdtLevel.disabled=true;
		}
	else
		document.forms[0].EdtLevel.disabled=false;
	}
function Unit(mi,ci,increment){
	var CLW=["g/kg","kg/kg","mg/kg"];
	var DIV=["10**5/s","1/s"];
	var HEIGHT=["m"];
	var ICE=["g/kg","kg/kg","mg/kg"];
	var ICLW=["cm","mm","in"];
	var IRNW=["cm","mm","in"];
	var LHFLUX=["w/m2"];
	var LI=["K","C"];
	var LWDOWN=["w/m2"];
	var MDIV=["10**7/s","1/s"];
	var MSE=["j/kg"];
	var MSS=["j/kg"];
	var P=["mb","pa","hpa"];
	var PBLHGT=["m"];
	var PP=["mb","pa","hpa"];
	var PRH2O=["cm","mm","in"];
	var PSFC=["mb","pa","hpa"];
	var PSLV=["mb","pa","hpa"];
	var PTEND=["mb","pa","hpa"];
	var PV=["PVU","kg/s^3pa"];
	var QV=["g/kg","kg/kg"];
	var RAINC=["mm","cm","in"];
	var RAINN=["mm","cm","in"];
	var RAINT=["mm","cm","in"];
	var RDTEND=["k/day","k/h"];
	var REGIME=["category"];
	var RH=["%"];
	var RNW=["g/kg","kg/kg","mg/kg"];
	var RTENDC=["mm","cm","in"];
	var RTENDN=["mm","cm","in"];
	var RTENDT=["mm","cm","in"];
	var SHFLUX=["w/m2"];
	var SNOW=["g/kg","kg/kg","mg/kg"];
	var SOIL_T_1=["k"];
	var SOIL_T_2=["k"];
	var SOIL_T_3=["k"];
	var SOIL_T_4=["k"];
	var SOIL_T_5=["k"];
	var SOIL_T_6=["k"];
	var SWDOWN=["w/m2"];
	var T=["K","C","F"];
	var TD=["K","C","F"];
	var TDD=["K","C","F"];
	var TGD=["K","C"];
	var THETA=["K","C","F"];
	var THETAE=["K","C","F"];
	var U=["m/s","kt","cm/s"];
	var UST=["m/s"];
	var V=["m/s","kt","cm/s"];
	var VAB=["10**5/s","1/s"];
	var VESL=["m/s"];
	var VOR=["10**5/s","1/s"];
	var W=["m/s","kt"];
	var WIND=["m/s","kt","cm/s"];
	var NormalField=[CLW,DIV,HEIGHT,ICE,ICLW,IRNW,LHFLUX,LI,LWDOWN,MDIV,MSE,MSS,P,PBLHGT,PP,PRH2O,PSFC,PSLV,PTEND,PV,QV,RAINC,RAINN,RAINT,RDTEND,REGIME,RH,RNW,RTENDC,RTENDN,RTENDT,SHFLUX,SNOW,SOIL_T_1,SOIL_T_2,SOIL_T_3,SOIL_T_4,SOIL_T_5,SOIL_T_6,SWDOWN,T,TD,TDD,TGD,THETA,THETAE,U,UST,V,VAB,VESL,VOR,W,WIND];
	DeleteAllItems(document.forms[0].elements[ci]);
	var index=document.forms[0].elements[mi].selectedIndex+increment;
	if(index!=-1)	AddAllItems(document.forms[0].elements[ci],NormalField[index]);
	else  {
		document.forms[0].elements[ci+1].value="";
		document.forms[0].elements[ci+2].value="";
		}
	}
function DeleteAllItems(X){
	while(X.length != 0)
		X.remove(0);
	}

function AddAllItems(X,ary){
	var i=0;
	while(i<ary.length){
		var uOption = document.createElement("OPTION");
		uOption.text=ary[i];
		uOption.value=ary[i];
		X.add(uOption);
		i++;
		}
	}


function RefereshDetail(){
	var index=document.forms[0].CmbBoxRunDate.selectedIndex;
	var folder=document.forms[0].CmbBoxRunDate.options[index].text;
	var index=document.forms[0].CmbBoxRunRun.selectedIndex;
	var subFolder=document.forms[0].CmbBoxRunRun.options[index].text;
	detailFrame.location.href="detail.php?folder="+folder+"&subFolder="+subFolder;
}

function FieldHelp(index){
	var Help=["cloud water(g/kg)",
		"divergence of horizontal wind(?)",
		"geopotential height(m)",
		"cloud ice(g/kg)",
		"integrated cloud water(cm)",
		"integrated rain water(cm)",
		"surface  latent heat flux(w/m2)",
		"lifted index(k)",
		"longwave downward radiation(w/m2)",
		"moisture divergence(10**7/s)",
		"moist static energy(j/kg)",
		"saturated moist static energy(j/kg)",
		"pressure(mb)",
		"pbl height(m)",
		"pressure perturbation(mb)",
		"precipitation watre(cm)",
		"surface pressure(mb)",
		"sea level pressure(mb)",
		"pressure change(mb)",
		"potential vorticity(pvu)",
		"mixing ratio(g/kg)",
		"convective accumulated precip(mm)",
		"stable accumuloted precip(mm)",
		"otal accumulated precipitation(mm)",
		"atmospheric radiative   tendency(k/day)",
		"PBL regimes (values 1-4) catagory",
		"relative humidity(%)",
		"rain water(g/kg)",
		"convective precip during interval(mm)",
		"stable precip during time interval(mm)",
		"total precip during time interval(mm)",
		"surface sensible heat flux(W/m2)",
		"snow(g/kg)",
		"soil temp in 10/40/100/200 cm layer(K)",
		"soil temp in 10/40/100/200 cm layer(K)",
		"soil temp in 10/40/100/200 cm layer(K)",
		"soil temp in 10/40/100/200 cm layer(K)",
		"soil temp in 10/40/100/200 cm layer(K)",
		"soil temp in 10/40/100/200 cm layer(K)",
		"shortwave downward radiation(W/m2)",
		"temperature(K)",
		"dew point temperature(K)",
		"dew point depression(K)",
		"ground temperature(K)",
		"potential temperature(K)",
		"equivalent potential temperature(K)",
		"u-component of wind(m/s)",
		"frictional velocity(m/s)",
		"v-component of wind(m/s)",
		"absolute vorticity(10**5/s)",
		"horizontal wind streamlines(m/s)",
		"relative vorticity(10**5/s)",
		"w-component of wind(m/s)",
		"wind speed(m/s)",
		"select map type",
		"set level for plot",
		"select your domain",
		"set Longitude",
		"set Latitude"];
	if(index==0)document.forms[0].OutputHelp.value=Help[document.forms[0].CmbBoxField.selectedIndex];
	else document.forms[0].OutputHelp.value=Help[index+53];
	}

</script>
<?php
include("mm5_p2.tpl");
//------------------MM5---------------------

function Java(){
	print "<script language=\"javascript\">
	       function WhenDateSelect(){";
	$fp=fopen("/mm5/backup/run_dates","r");
	while( !feof($fp) ){
			   $line=fgets($fp,1024);
	                   if($line=="")break;
			   $line=str_replace("\n","",$line);
			   $line=str_replace("/","_",$line);
			   print "var D$line=[";
			   $fpn=fopen("/mm5/backup/$line/runs","r");
			   $run=fgets($fpn,1024);
			   $run=str_replace("\n","",$run);
			   print "\"$run\"";
			   while( !feof($fpn) ){
						$run=fgets($fpn,1024);
						if($run=="")break;
						print ",";
						$run=str_replace("\n","",$run);
						print "\"$run\"";
						}
			   print "];";
			   fclose($fpn);
			   }

	print      "var DatesSTR=[";
	$fp=fopen("/mm5/backup/run_dates","r");
	$line=fgets($fp,1024);
	$line=str_replace("\n","",$line);
        $line=str_replace("/","_",$line);
        print "\"D$line\"";
	while( !feof($fp) ){
			   $line=fgets($fp,1024);
	                   if($line=="")break;
 			   print ",";
			   $line=str_replace("\n","",$line);
			   $line=str_replace("/","_",$line);
	                   print "\"D$line\"";
			   }
	print "];";
	fclose($fp);

	print      "var DatesTWO=[";
	$fp=fopen("/mm5/backup/run_dates","r");
	$line=fgets($fp,1024);
	$line=str_replace("\n","",$line);
        $line=str_replace("/","_",$line);
        print "D$line";
	while( !feof($fp) ){
			   $line=fgets($fp,1024);
	                   if($line=="")break;
 			   print ",";
			   $line=str_replace("\n","",$line);
			   $line=str_replace("/","_",$line);
	                   print "D$line";
			   }
	print "];";
	fclose($fp);

	print "var selecteditem=document.forms[0].CmbBoxRunDate.value;
	       if(selecteditem==null)selecteditem=DatesSTR[0];";
	print "else {
		   removeOptions();";
	print "    newstr=selecteditem.replace(\"/\",\"_\");
	           newstr=newstr.replace(\"/\",\"_\");
	           arrayname=\"D\"+newstr;
		   }
	       var itemindex=0;
	       while( arrayname!=DatesSTR[itemindex] ) itemindex++;
	       var i=0;
	       while(i<DatesTWO[itemindex].length){
					    addOption(DatesTWO[itemindex][i],\"item\"+i);
					    i++;
					   }
	       RefereshDetail();
	}";

	print "function removeOptions(){
			while(document.forms[0].CmbBoxRunRun.length != 0)
				document.forms[0].CmbBoxRunRun.remove(0);
			}
		function addOption(text, value){
			var oOption = document.createElement(\"OPTION\");
			oOption.text=text;
			oOption.value=text;
			document.forms[0].CmbBoxRunRun.add(oOption);
		};";

	print "function AddtoCmbBox(){;
	       var Dates=[";
	$fp=fopen("/mm5/backup/run_dates","r");
	$line=fgets($fp,1024);
	$line=str_replace("\n","",$line);
        print "\"$line\"";
	while( !feof($fp) ){
			   $line=fgets($fp,1024);
	                   if($line=="")break;
 			   print ",";
			   $line=str_replace("\n","",$line);
	                   print "\"$line\"";
			   }
	print "];";
	fclose($fp);

	print "var i=0;
	       while(i<Dates.length ){
					var oOption = document.createElement(\"OPTION\");
					oOption.text=Dates[i];
					oOption.value=Dates[i];
					document.forms[0].CmbBoxRunDate.add(oOption);
   				        i++;
			   	     }
		WhenDateSelect();
		};";
	print "</script>";
	}
function Reload($top4part1,$top4part3,$mid4p1,$mid4p2,$bottom4,$CmbBoxRunDate,$CmbBoxRunRun,$DistPath,$writeable,$GraphRunName){
 //Java();//print need java tags
 print $top4part1;
 print "<select size=\"1\" name=\"CmbBoxRunDate\" value=\"$CmbBoxRunDate\">
	<option>$CmbBoxRunDate</option>
	</select>
	</font>
        <input type=\"hidden\" value=\"$CmbBoxRunDate\" name=\"EdtHidRunDate\">
	</td>
	<td width=\"25%\" style=\"padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1; border-left-width:1; border-right-width:1; border-top-width:1; border-bottom-style:solid; border-bottom-width:1\" height=\"23\" bgcolor=\"#7777BD\">
        <font size=\"2\">Run
	<select size=\"1\" name=\"CmbBoxRunRun\" value=\"$CmbBoxRunRun\">
	<option>$CmbBoxRunRun</option>
        </select></font>
	<input type=\"hidden\" value=\"$CmbBoxRunRun\" name=\"EdtHidRunRun\">
	</td>";
 print $top4part3;
 print "<select size=\"1\" name=\"CmbBoxDomain\">";
 $fp=fopen("$DistPath/domain.opt", "r");
 $no=0;
 while(!feof($fp)){fgets($fp,1024);$no++;}
 fclose($fp);
 for($i=1;$i<$no;$i++)
 		print "<option>Domain $i</option>";
 print "</select>&nbsp;&nbsp;";
 print $mid4p1;
 $fp=fopen("$DistPath/domain.opt", "r");
 $no=0;
 while(!feof($fp)){fgets($fp,1024);$no++;}
 fclose($fp);
 for($i=1;$i<$no;$i++)
	print "<option>Domain $i</option>";
 print $mid4p2;
 if(file_exists("$writeable/outconf.opt"))
 {
 $fp1=fopen("$writeable/outconf.opt","r");
 $i=1;
 while(!feof($fp1)){
 		   $line=fgets($fp1,1024);
                   if($line=="")break;
                   $fields=split("[|]",$line);
                   if($i%2!=1)$rowcolor="#C0C0C0";
                   else $rowcolor="#FFFFFF";
			$row="
			      <tr>
				<td width=\"102\" align=\"center\" bgcolor=\"$rowcolor\" style=\"border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\">
				<font size=\"2\">$fields[1]</font></td>
				<td width=\"495\" align=\"center\" bgcolor=\"$rowcolor\" style=\"border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\">
				<font size=\"2\">plot=$fields[0] ; unit=$fields[2] ; contour=$fields[3] ; smooth=$fields[4] ; overlay=$fields[6]</font></td>
			      </tr>";
		   print $row;
                   $i++;
 		   }
 fclose($fp1);
 }
 if(file_exists("$writeable/outdom.opt"))
 {
 $fp2=fopen("$writeable/outdom.opt","r");
 while(!feof($fp2)){
 		   $line=fgets($fp2,1024);
                   if($line=="")break;
                   $fields=split("[|,]",$line);
                   if($i%2!=1)$rowcolor="#C0C0C0";
                   else $rowcolor="#FFFFFF";
                   if($fields[1] !="X ")
			$row="
			<tr>
				<td width=\"102\" align=\"center\" bgcolor=\"$rowcolor\" style=\"border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\">
				<font size=\"2\">SKEWTLL</font></td>
				<td width=\"495\" align=\"center\" bgcolor=\"$rowcolor\" style=\"border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\">
				<font size=\"2\">domain=$fields[0]; lon=$fields[4]; lat=$fields[5]</font></td>
			</tr>";
                   else{
	     	        $line=fgets($fp2,1024);
                        if($line=="")break;
                        $Xrow2=split("[|]",$line);
		   	$row="
			      <tr>
				<td width=\"102\" align=\"center\" bgcolor=\"$rowcolor\" style=\"border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\">
				<font size=\"2\">X</font></td>
				<td width=\"495\" align=\"center\" bgcolor=\"$rowcolor\" style=\"border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\">
				<font size=\"2\">type=cross section ; domain=$fields[0]; x1=$fields[2]; y1=$fields[3]; x2=$fields[4]; y2=$fields[5]; field=$Xrow2[2]; overlay=$Xrow2[7]</font></td>
			      </tr>";
		      }
                   print $row;
                   $i++;
 		   }
 fclose($fp2);
 }
 $tmp=split("/",$writeable);
 print "<input type=\"hidden\" value=\"$tmp[5]\" name=\"EdtHidID\">
       <input type=\"hidden\" value=\"$GraphRunName\" name=\"GraphRunName\">";
 print $bottom4;
 }
///******************************************
if($seemout!="y"){
	Java(); //print need java tags
	//draw page 4
	print "<form action=\"graph.php\" method=\"post\">
	       <input type=\"hidden\" value=\"y\" name=\"seemout\">
	       <input type=\"hidden\" value=\"2\"  name=\"formtype\">
	       <input type=\"hidden\" value=\"0\" name=\"EdtHid1\">
	       <input type=\"hidden\" value=\"0\" name=\"EdtHid2\">
	       <input type=\"hidden\" value=\"0\" name=\"EdtHid3\">";
	print "<select size=\"1\" name=\"CmbBoxRunDate\" onchange=\"WhenDateSelect()\"></select>
	       <select size=\"1\" name=\"CmbBoxRunRun\" onchange=\"RefereshDetail()\"></select>
	       <p> Enter Graph run name: <input type=\"text\" name=\"GraphRunName\" maxlength=\"4\" size=\"2\"></p>
	       <p><input type=\"submit\" value=\"Go to Graph\"></p></form>";
	print "<br><center>
		<iframe src=\"blank.html\" name=\"detailFrame\" width=\"620\" height=\"600\" scrolling=\"1\"
	        	frameborder=\"0\"></iframe></center>";
 }
//------------------------------------------
else {

     /*@check for unique graph run name for this date*/
	$archive_path=split("[/.-]",$CmbBoxRunDate);
	$ERROR=0;
	$ErrorAry=array();
	if (file_exists("/mm5/archive/$archive_path[0]/$archive_path[1]/$archive_path[2]/graph/runs") ){
		$fp=fopen("/mm5/archive/$archive_path[0]/$archive_path[1]/$archive_path[2]/graph/runs","r");
		while(!feof($fp)){
                	$rec=fgets($fp,1024);
		    	$rec=str_replace("\n","",$rec);
		    	if( $rec==$GraphRunName)
				{$ERROR=1;array_push($ErrorAry,"$GraphRunName already exist, please change it.");}
                    }
               fclose($fp);
	  }
       if($GraphRunName=="" or ereg("[?!#$%^&*()=:+,;><@|~`\"\' ]",$GraphRunName)){
		$ERROR=1;
		array_push($ErrorAry,"$GraphRunName is invalid , please correct it.");
		}

       if($ERROR==1){
        	print "<h2>The following errors has been occured...</h2>";
	        for($i=0;$i<sizeof($ErrorAry);$i++)print "<p><font color=red><b>&sect;</b> $ErrorAry[$i]</font></p>";
          	die("<input type=\"button\" value=\"Back\" name=\"btnBack\" onclick=\"javascript:history.back(1)\">");
         	}
     /**/

     $Cmb=str_replace("/","_",$CmbBoxRunDate);
     $DistPath="/mm5/backup/".$Cmb."/".$CmbBoxRunRun;
     if ( $EdtHidID=="" ){
	//make user folder for graph
	srand((double) microtime() * 1000000);
	$folder=uniqid("Graph",rand());
	while ( is_dir("$DistPath/$folder") )$folder=uniqid("Graph",rand());
	mkdir("$DistPath/$folder",0777);
	$writeable="$DistPath/$folder";
      }
      else $writeable="$DistPath/$EdtHidID";
     //----------------------------
      switch($formtype){
		      case 2:	print  "<form action=\"graph.php\" method=\"post\">
		      			<input type=\"hidden\" value=\"0\" name=\"EdtHid1\">
	       				<input type=\"hidden\" value=\"0\" name=\"EdtHid2\">
	       				<input type=\"hidden\" value=\"0\" name=\"EdtHid3\">";
		      		print $top4part1;
				print "<select size=\"1\" name=\"CmbBoxRunDate\" value=\"$CmbBoxRunDate\">
					<option>$CmbBoxRunDate</option>
					</select>
					</font><input type=\"hidden\" value=\"$CmbBoxRunDate\" name=\"EdtHidRunDate\">					</td>
					<td width=\"25%\" style=\"padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1; border-left-width:1; border-right-width:1; border-top-width:1; border-bottom-style:solid; border-bottom-width:1\" height=\"23\" bgcolor=\"#7777BD\">
					<font size=\"2\">Run
					<select size=\"1\" name=\"CmbBoxRunRun\" value=\"$CmbBoxRunRun\">
					<option>$CmbBoxRunRun</option>
					</select></font><input type=\"hidden\" value=\"$CmbBoxRunRun\" name=\"EdtHidRunRun\"></td>";
				print $top4part3;
				print "<select size=\"1\" name=\"CmbBoxDomain\">";
				$fp=fopen("$DistPath/domain.opt", "r");
				$no=0;
				while(!feof($fp)){fgets($fp,1024);$no++;}
				fclose($fp);
				for($i=1;$i<$no;$i++)
					print "<option>Domain $i</option>";
				print "</select>&nbsp;&nbsp;";
				print $mid4p1;
				$fp=fopen("$DistPath/domain.opt", "r");
				$no=0;
				while(!feof($fp)){fgets($fp,1024);$no++;}
				fclose($fp);
				for($i=1;$i<$no;$i++)
					print "<option>Domain $i</option>";
				print $mid4p2;
				print "<input type=\"hidden\" value=\"$folder\" name=\"EdtHidID\">
				       <input type=\"hidden\" value=\"$GraphRunName\" name=\"GraphRunName\">";
				print $bottom4;
				$ret=-1;
				break;
		      case 4:$param=$CmbBoxField.",".$CmbBoxType.",".$EdtLevel.",".$EdtHid1.",".$EdtHid2.",".
		      		    $CmbBoxUnit.",".$EdtContour.",".$EdtSmooth.",".$CmbBoxOverField.",".
				    $CmbBoxOverUnit.",".$EdtOverContour.",".$EdtOverSmooth.",".$EdtHid3;
			     $ret=CheckP41($param,$DistPath,$writeable);
			     break;
                      case 5:$param=$CmbBoxDomain.",".$EdtLon.",".$EdtLat.",".$EdtHid2.",".$EdtHid1.",".$EdtHid3;
                             $ret=CheckP42($param,$DistPath,$writeable);
		             break;
                      case 6:$param=$EdtX1.",".$EdtY1.",".$EdtX2.",".$EdtY2.",".$CmbBoxCrossField.",".
		      	            $CmbBoxCrossUnit.",".$EdtCrossContour.",".$EdtCrossSmooth.",".
				    $CmbBoxOverCrossField.",".$CmbBoxOverCrossUnit.",".$EdtOverCrossContour.",".
				    $EdtOverCrossSmooth.",".$EdtHid3.",".$EdtHid2.",".$EdtHid1.",".$CmbBoxCrossDomain;
                             $ret=CheckCross($param,$DistPath,$writeable);
		      	     break;
     				  }//end switch
     if($ret!=-1)Reload($top4part1,$top4part3,$mid4p1,$mid4p2,$bottom4,$CmbBoxRunDate,$CmbBoxRunRun,$DistPath,$writeable,$GraphRunName);
     }

function CheckCross($line,$DistPath,$writeable){
	$NestIX=array();
	$NestJX=array();
	$fp=fopen("$DistPath/domain.opt","r");
        $rec=fgets($fp,1024);
        $fields=split(",",$rec);
	while(!feof($fp)){
                    $abs=abs($fields[2]-$fields[4]);
                    array_push($NestIX,round($abs*111/$fields[5])); //NestIX
                    $abs=abs($fields[1]-$fields[3]);
                    array_push($NestJX,round($abs*111/$fields[5])); //NestJY
	            $rec=fgets($fp,1024);
                    $fields=split(",",$rec);
		}
	fclose($fp);
	$ErrorFlag=0;
	$ErrorAry=array();
	$fields=split(",",$line);
	//check for errors
	$item=substr($fields[15],7,1);
	if( ($fields[4]=="")or($fields[5]=="")or($fields[6]=="")or($fields[7]=="") )
		{$ErrorFlag=1;array_push($ErrorAry,"some fields are empty.");};
	if( ($fields[0]<3)or($fields[1]<3)or($fields[2]>$NestJX[$item])or($fields[3]>$NestIX[$item]) )
		{$ErrorFlag=1;array_push($ErrorAry,"3 &lsaquo; X1,X2 &lsaquo; $NestJX[$item] and
						    3 &lsaquo; Y1,Y2 &lsaquo; $NestIX[$item]");};
	$tmp=split(" ",$fields[15]);
	$i=$tmp[1];
	$rec=$i."|"."X"." | ".$fields[0]." | ".$fields[1]." | ".$fields[2]." | ".$fields[3]." ||  |  |  |\n".
	     $i."|"."X"." | ".$fields[4]." | ".$fields[5]." | ".$fields[6]." | ".$fields[7]." || ".$fields[8]." | ".$fields[9]." | ".$fields[10]." | ".$fields[11]."\n";
	if( $fields[14]==0 ){
			$fp=fopen("$writeable/outconf.opt","w");
			fclose($fp);
		}
	if($fields[12]!=0){
		$fp=fopen("$writeable/outdom.opt","r");
		while(!feof($fp)){
			$red=fgets($fp,1024);
			$test=split("[|]",$red);
			if($test[1]=="X ") {
					   $red2=fgets($fp,1024);
					   $red=$red.$red2;
					   if($red==$rec){$ErrorFlag=1;array_push($ErrorAry,"This field already exsit.");break;}
					   }
			}
		fclose($fp);
	}
	if($ErrorFlag!=1){
		if( ($fields[13]==0 )&&($fields[12]==0)){
			$fp=fopen("$writeable/outdom.opt","w+");
			fwrite($fp,$rec);
			fclose($fp);
			}
		else{
			$fps = fopen ("$writeable/outdom.opt", "r+");
			$fpd = fopen ("$writeable/outdom.tmp", "w+");
			for($i=0;$i<(2*$fields[12]+$fields[13]);$i++){
					$line=fgets($fps,1024);
					fwrite($fpd,$line);
					}
			fseek($fpd,0,SEEK_END);
			fwrite($fpd,$rec);
			fclose($fpd);
			fclose($fps);
			$fps = fopen ("$writeable/outdom.tmp", "r");
			$fpd = fopen ("$writeable/outdom.opt", "w+");
			while(!feof($fps)){
					$line=fgets($fps,1024);
					fwrite($fpd,$line);
						}
			fclose($fpd);
			fclose($fps);
			 }
	         $no=$fields[12]+1;
  		 print "<form action=\"graph.php\" method=\"post\">";
		 print "<input type=\"hidden\" value=\"$fields[14]\" name=\"EdtHid1\">";
		 print "<input type=\"hidden\" value=\"$fields[13]\" name=\"EdtHid2\">";
		 print "<input type=\"hidden\" value=\"$no\" name=\"EdtHid3\">";
		 return 0;
		  }
	else{
        	print "<h2>The following errors has been occured...</h2>";
	        for($i=0;$i<sizeof($ErrorAry);$i++)print "<p><font color=red><b>&sect;</b> $ErrorAry[$i]</font></p>";
          	print "<input type=\"button\" value=\"Back\" name=\"btnBack\" onclick=\"javascript:history.back(1)\">";
		return -1;
		}

        }
function Checkp41($line,$DistPath,$writeable){
	$ErrorFlag=0;
	$ErrorAry=array();
	$fields=split(",",$line);
	if( ($fields[4]==0)&&($fields[12]==0) ){
			$fp=fopen("$writeable/outdom.opt","w");
			fclose($fp);
	}
	if( ($fields[1]!="Sigma")&&(($fields[2]<100)or($fields[2]>10000)) ){$ErrorFlag=1;array_push($ErrorAry,"100 &lsaquo; Level &lsaquo; 10000");}
	if( ($fields[6]=="")or($fields[7]=="")or($fields[5]=="") ){$ErrorFlag=1;array_push($ErrorAry,"Some fields are empty.");}
	if( $fields[1]!="Sigma" )
		$rec="T".$fields[1][0].$fields[2]." | ".$fields[0]." | ".$fields[5]." | ".$fields[6]." | ".$fields[7]." || ".$fields[8]." | ".$fields[9]." | ".$fields[10]." | ".$fields[11]."\n";
	else
		$rec="T"." | ".$fields[0]." | ".$fields[5]." | ".$fields[6]." | ".$fields[7]." || ".$fields[8]." | ".$fields[9]." | ".$fields[10]." | ".$fields[11]."\n";
	if($fields[3]!=0){
		$fp=fopen("$writeable/outconf.opt","r");
		while(!feof($fp)){
			$red=fgets($fp,1024);
			if($red==$rec){$ErrorFlag=1;array_push($ErrorAry,"This field already exsit.");break;}
			}
		fclose($fp);
	}
	if($ErrorFlag!=1){
		if( $fields[3]==0 ){
			$fp=fopen("$writeable/outconf.opt","w+");
			fwrite($fp,$rec);
			fclose($fp);
			}
		else {
        	         $fps = fopen ("$writeable/outconf.opt", "r+");
                	 $fpd = fopen ("$writeable/outconf.tmp", "w+");
	                 for($i=0;$i<$fields[3];$i++){
                                           $line=fgets($fps,1024);
                                           fwrite($fpd,$line);
                                          }
                 	fseek($fpd,0,SEEK_END);
                 	fwrite($fpd,$rec);
                 	fclose($fpd);
                 	fclose($fps);
                 	$fps = fopen ("$writeable/outconf.tmp", "r");
                 	$fpd = fopen ("$writeable/outconf.opt", "w+");
                 	while(!feof($fps)){
                 			    $line=fgets($fps,1024);
                                	    fwrite($fpd,$line);
                 				    }
                 	fclose($fpd);
                 	fclose($fps);
			}
		$no=$fields[3]+1;
		print "<form action=\"graph.php\" method=\"post\">";
		print "<input type=\"hidden\" value=\"$no\" name=\"EdtHid1\">";
		print "<input type=\"hidden\" value=\"$fields[4]\" name=\"EdtHid2\">";
		print "<input type=\"hidden\" value=\"$fields[12]\" name=\"EdtHid3\">";
		return 0;
		}
	else{
        	print "<h2>The following errors has been occured...</h2>";
	        for($i=0;$i<sizeof($ErrorAry);$i++)print "<p><font color=red><b>&sect;</b> $ErrorAry[$i]</font></p>";
          	print "<input type=\"button\" value=\"Back\" name=\"btnBack\" onclick=\"javascript:history.back(1)\">";
		return -1;
		}
	}
//**************************************************
function Checkp42($line,$DistPath,$writeable){
	$ErrorFlag=0;
	$ErrorAry=array();
	$fields=split(",",$line);
	if( $fields[4]==0 ){
			$fp=fopen("$writeable/outconf.opt","w");
			fclose($fp);
		}
	$tmp=split(" ",$fields[0]);
	$i=$tmp[1];
	$fi=fopen("$DistPath/domain.opt","r");
	for($j=0;$j<$i;$j++)
		$line=fgets($fi,1024);
	fclose($fi);
	$tmp=split(",",$line);
	if(($fields[1]<$tmp[1])or($fields[1]>$tmp[3])or($fields[2]>$tmp[2])or($fields[2]<$tmp[4])){$ErrorFlag=1;array_push($ErrorAry,"Point isnt into domain $i.");};
	$rec=$i."|"."T | SKEWTLL | A | ".$fields[1]." | ".$fields[2]." ||\n";
	if( ($fields[3]!=0)&&($fields[5]==0) ){
		$fp=fopen("$writeable/outdom.opt","r");
		while(!feof($fp)){
			$red=fgets($fp,1024);
			if($red==$rec){$ErrorFlag=1;array_push($ErrorAry,"This field already exsit.");break;}
			}
		fclose($fp);
	}

	if($ErrorFlag!=1){
		if( ($fields[3]==0 )&&($fields[5]==0)){
			$fp=fopen("$writeable/outdom.opt","w+");
			fwrite($fp,$rec);
			fclose($fp);
			}
		else {
        	         $fps = fopen ("$writeable/outdom.opt", "r+");
                	 $fpd = fopen ("$writeable/outdom.tmp", "w+");
	                 for($i=0;$i<(2*$fields[5]+$fields[3]);$i++){
                                           $line=fgets($fps,1024);
                                           fwrite($fpd,$line);
                                          }
                 	fseek($fpd,0,SEEK_END);
                 	fwrite($fpd,$rec);
                 	fclose($fpd);
                 	fclose($fps);
                 	$fps = fopen ("$writeable/outdom.tmp", "r");
                 	$fpd = fopen ("$writeable/outdom.opt", "w+");
                 	while(!feof($fps)){
                 			    $line=fgets($fps,1024);
                                	    fwrite($fpd,$line);
                 				    }
                 	fclose($fpd);
                 	fclose($fps);
			}
		$no=$fields[3]+1;
		print "<form action=\"graph.php\" method=\"post\">";
		print "<input type=\"hidden\" value=\"$fields[4]\" name=\"EdtHid1\">";
		print "<input type=\"hidden\" value=\"$no\" name=\"EdtHid2\">";
		print "<input type=\"hidden\" value=\"$fields[5]\" name=\"EdtHid3\">";
		return 0;
		}
	else{
        	print "<h2>The following errors has been occured...</h2>";
	        for($i=0;$i<sizeof($ErrorAry);$i++)print "<p><font color=red><b>&sect;</b> $ErrorAry[$i]</font></p>";
          	print "<input type=\"button\" value=\"Back\" name=\"btnBack\" onclick=\"javascript:history.back(1)\">";
		return -1;
		}
	}

//**************************************************
?>
</body>

</html>
Return current item: MM5 User Interface