public void createAndSaveUrl(String Path, String DistrictID) throws Exception{

		Properties properties = new Properties();
		properties.load(this.getClass().getResourceAsStream("/com/opendap/poc/ServerContentDownloader.properties"));
		String parent = new File(this.getClass().getResource("/boo.txt").getFile()).getParent();
		String folderProperty = properties.getProperty("folder");
		
		
		//String folderPath = folderProperty +"/" + DistrictID + "/" + Path; 
		String folderPath = "Data/188/2012-03-21";
		
		/* build connection to the database */
			try{
				File dir = new File(parent, folderPath);
				dir.mkdirs();
				new File(dir, "newboo3.txt").createNewFile();
				//System.out.println(dir.getAbsolutePath());
			}catch(Exception e){
				e.printStackTrace();
			}
			try	{
			int id = 1;
			//String DistrictID ="188";
			/*Get the district coordinates */
			File aFile = new File(this.getClass().getResource("/DistrictCoordinates.txt").getFile());
			String LatLong = "";
			double maxLat = 0.0;
			double minLat = 0.0;
			double maxLon = 0.0;
			double minLon =0.0;
 			
 			Double GCMLat = 0.0;
 			Double GCMLon = 0.0;
 			double GCMLatMin = 0.0; 
 			double GCMLatMax = 0.0;
 			double GCMLonmin = 0.0;
 			double GCMLonMax = 0.0;
 			
 			Vector LatVec = new Vector();
			Vector LonVec = new Vector();
			try	{
				 BufferedReader input =  new BufferedReader(new FileReader(aFile));
				 String line = null; //not declared within while loop
				     while (( line = input.readLine()) != null){
				    	 StringTokenizer sta = new StringTokenizer(line.toString(),"@");
			    		 //sta.nextToken();
			    		 if(sta.nextToken().toString().equals(DistrictID)){  	
				    		    sta.nextToken();
				    		 	LatLong = sta.nextToken();
				    		 	LatLong = LatLong.replace("MULTIPOLYGON(((", "");
								LatLong = LatLong.replace(")))", "");
								LatLong = LatLong.replace("))", ",");
								LatLong = LatLong.replace("((", "");
								//defining the area of the resterization
								StringTokenizer st = new StringTokenizer(LatLong,",");
				            	StringTokenizer stRaster = new StringTokenizer(LatLong,",");
				            	while(stRaster.hasMoreElements() ){
									String next = stRaster.nextElement().toString();
									StringTokenizer st3 = new StringTokenizer(next);
									Double Lat = Double.parseDouble(st3.nextElement().toString());
									Double Lon = Double.parseDouble(st3.nextElement().toString());
									LatVec.add(Lat);
									LonVec.add(Lon);
				    			}
								maxLat = Double.parseDouble(Collections.max(LatVec).toString());
				    			minLat = Double.parseDouble(Collections.min(LatVec).toString());
				    			maxLon = Double.parseDouble(Collections.max(LonVec).toString());
				    			minLon = Double.parseDouble(Collections.min(LonVec).toString());
				    			
				    			GCMLat = (maxLat+minLat)/2;
				    			GCMLon = (maxLon + minLon)/2;
				    			GCMLatMin = GCMLat - 5; 
				    			GCMLatMax = GCMLat + 5;
				    			GCMLonmin = GCMLon - 5;
				    			GCMLonMax = GCMLon + 5;
				    			
				          }
				     }
			}catch(Exception e){}
				        			
    		int dist = Integer.parseInt(DistrictID);
			id = dist;
			//the id in database is 1 more than the normal id
			id++;
			String filename = "";
			String urlString = "";
			double Lon = 0.0;
			double Lat = 0.0;
			/*Get the grid co-ordinates of the region */
			filename =  "GridCoordinates.tsv";
			urlString = servletURLPattern_Coordinates.replace("{{minLat}}", String.valueOf(minLat))
						.replace("{{maxLat}}",String.valueOf(maxLat)).replace("{{minLon}}", String.valueOf(minLon)).
						replace("{{maxLon}}", String.valueOf(maxLon)).replace("{{id}}",String.valueOf(id));
		    System.out.println("urlString :" + urlString);
		    saveUrl(filename , urlString);
			
			/* Get the soil parameters from the Datalibrary */
			filename = "soil.cdf";
			urlString = servletURLPattern_soil.replace("{{minLat}}", String.valueOf(minLat))
						.replace("{{maxLat}}",String.valueOf(maxLat)).replace("{{minLon}}", String.valueOf(minLon)).
						replace("{{maxLon}}", String.valueOf(maxLon)).replace("{{id}}",String.valueOf(id));
		    System.out.println("urlString :" + urlString);
		    saveUrl(filename , urlString);
		    
		    /*Call the soil function to convert the soil into ID*/
		    //Soil sol = new Soil();			
			
			/*Get the rainfall co-ordinates for the dataset */
			GridCoordinates grid = new GridCoordinates();
			Vector vec = grid.Coordinates(folderPath);
			Vector rainParameters = new Vector();
			Vector NHMMrain = new Vector();
			RainNHMM rnhmm = new RainNHMM();
			System.out.println ("Vector Size =" + vec.size());
			for(int i = 0; i <vec.size();i++){
				System.out.println(i);
				String pathname = "";
				
				Lon = Double.parseDouble(vec.get(i).toString());
				Lat = Double.parseDouble(vec.get(i+1).toString());
				i++;
				
				/*this call saves the rainfall values*/
				pathname = "rainfall"+"-"+Lat+"-"+Lon;
				filename = pathname+".cdf";
			    urlString = servletURLPattern_rainfall.replace("{{Lat}}", String.valueOf(Lat))
							.replace("{{Lon}}",String.valueOf(Lon)).replace("{{id}}",String.valueOf(id));
			    System.out.println("urlString :" + urlString);
			    saveUrl(filename , urlString);
			    
			     /* this methods builds up the rainfall files for HMM use*/
				 pathname = "rainfall"+"-"+Lat+"-"+Lon;
				 rainParameters = rnhmm.WriteRain(folderPath,pathname);
				 NHMMrain.add(rainParameters);
				
				 /*this call saves the Tmax values when it rained*/
				 pathname = "TmaxR"+Lat+"-"+Lon;
				 filename = pathname+".tsv";
				 urlString = servletURLPattern_TmaxAvgR.replace("{{Lat}}", String.valueOf(Lat))
								.replace("{{Lon}}",String.valueOf(Lon));
				 System.out.println("urlString :" + urlString);
				 saveUrl(filename , urlString);
				    
			     /*this call saves the Tmax values when it did not rain*/
				   pathname = "TmaxNR"+Lat+"-"+Lon;
				   filename = pathname+".tsv";
				   urlString = servletURLPattern_TmaxAvgNR.replace("{{Lat}}", String.valueOf(Lat))
									.replace("{{Lon}}",String.valueOf(Lon));
				   System.out.println("urlString :" + urlString);
				   saveUrl(filename , urlString);
				  
			      /*this call saves the Tmin values when it rained*/
				   pathname = "TminR"+Lat+"-"+Lon;
				   filename = pathname+".tsv";
				   urlString = servletURLPattern_TminAvgR.replace("{{Lat}}", String.valueOf(Lat))
									.replace("{{Lon}}",String.valueOf(Lon));
				   System.out.println("urlString :" + urlString);
				   saveUrl(filename , urlString);
				   
			       /*this call saves the Tmin values when it not rained*/
				   pathname = "TminNR"+Lat+"-"+Lon;
				   filename = pathname+".tsv";
				   urlString = servletURLPattern_TminAvgNR.replace("{{Lat}}", String.valueOf(Lat))
									.replace("{{Lon}}",String.valueOf(Lon));
				   System.out.println("urlString :" + urlString);
				   saveUrl(filename , urlString);
				   
			       /*this call saves the SRad values when it not rained*/ 
				   pathname = "SRadNR"+Lat+"-"+Lon;
				   filename = pathname+".tsv";
				   urlString = servletURLPattern_SRadNR.replace("{{Lat}}", String.valueOf(Lat))
									.replace("{{Lon}}",String.valueOf(Lon));
				   System.out.println("urlString :" + urlString);
				   saveUrl(filename , urlString);
				   
				   /* this call saves the SRad values when it rained */
				   pathname = "SRadR"+Lat+"-"+Lon;
				   filename = pathname+".tsv";
				   urlString = servletURLPattern_SRadR.replace("{{Lat}}", String.valueOf(Lat))
									.replace("{{Lon}}",String.valueOf(Lon));
				   System.out.println("urlString :" + urlString);
				   saveUrl(filename , urlString);
				   
				   /**/
				  
		      }
			
			/* this call defines the input parameters to HMM */
			rnhmm.WriteInputFiles(folderPath, "sim_nhmm_ind_delexp_params.txt");
			rnhmm.WriteInputFiles(folderPath, "lrn_nhmm_ind_delexp_params.txt");

			/**************Builds up the rainfall file to be read by NHMM *************************/
			/*File dir = new File(parent, folderPath);
			File writeFile = new File(dir,"HMM_Input.txt");
			FileOutputStream fout = new FileOutputStream(writeFile);
			Writer output = new BufferedWriter(new FileWriter(writeFile));
			System.out.println(((Vector) NHMMrain.get(0)).size());
			for(int k = 0; k <((Vector) NHMMrain.get(0)).size();k++)
				{
					output.write(((Vector) NHMMrain.get(0)).get(k) + "\t" +((Vector) NHMMrain.get(1)).get(k) + "\t" + ((Vector) NHMMrain.get(2)).get(k));
					output.write("\n");
				}
			
			/******************************************************************/
			
			/* this call downloads the GCM data */
		    /*for(int iYear=1982;iYear<2010;iYear++)
		    {
			filename = "GCM_"+iYear+".txt";
			
			urlString = servletURLPattern_GCM.replace("{{year}}", String.valueOf(iYear)).replace("{{minLat}}", String.valueOf(GCMLatMin))
							.replace("{{maxLat}}",String.valueOf(GCMLatMax)).replace("{{minLon}}", String.valueOf(GCMLonmin)).
							replace("{{maxLon}}", String.valueOf(GCMLonMax));
			 System.out.println("urlString :" + urlString);
			 saveUrl(filename , urlString);
		    }
		    
		    /*this builds up a single input to GCM and keeps it in a single file*/
		 /*   Vector vGCM = new Vector();
		    for(int iYear=1982;iYear<2010;iYear++)
		    {
		    	System.out.println(folderPath+ "/GCM_"+iYear+".txt");
		    	File aGCM = new File(this.getClass().getResource("/" +folderPath+ "/GCM_"+iYear+".txt").getFile());
		    	BufferedReader input =  new BufferedReader(new FileReader(aGCM));
		    	String line = null; //not declared within while loop
		         while (( line = input.readLine()) != null){
		        	 System.out.println(line);
		        	 vGCM.add(line);
		         }
		    }
		      File dir = new File(parent, folderPath);
			  File writeFile = new File(dir,"GCM.txt");
			  FileOutputStream fout = new FileOutputStream(writeFile);
			  Writer outputGCM = new BufferedWriter(new FileWriter(writeFile));
		       for (int k = 0; k < vGCM.size(); k++){
		    	 outputGCM.write(vGCM.get(k).toString());
		    	 outputGCM.write("\n");
		    	 outputGCM.flush();
       			}
		       outputGCM.close();
		       
			 /*Call the HMM simulations at this point */
			 
			 /*Once the dataset for HMM is run...call the NHMM to run at this point*/
			 ReadNHMMOutput rd = new ReadNHMMOutput();
			 
			 for(int i = 0; i <vec.size();i++)
				{
				 Lon = Double.parseDouble(vec.get(i).toString());
				 Lat = Double.parseDouble(vec.get(i+1).toString());
				 i++;
				}
				 	
			 
			 /*Once the NHMM is ready call the ReadNHMMOutput to build the input rainfall file*/
			 
			 /* At this point Call the 
			/* Write the input files for the crop models */
			/*	rnhmm.WriteInputFiles(folderPath, "/DATA.CDE");
				
				rnhmm.WriteInputFiles(folderPath, "/DETAIL.CDE");
				
				rnhmm.WriteInputFiles(folderPath, "/DSMODEL.ERR");
				
				rnhmm.WriteInputFiles(folderPath, "/GCOEFF.CDE");
				
				rnhmm.WriteInputFiles(folderPath, "/GRSTAGE.CDE");
				
				rnhmm.WriteInputFiles(folderPath, "/JDATE.CDE");
				
				rnhmm.WriteInputFiles(folderPath, "/PEST.CDE");
				
				rnhmm.WriteInputFiles(folderPath, "/SGCER040.CUL");
				
				rnhmm.WriteInputFiles(folderPath, "/SGCER040.ECO");
				
				rnhmm.WriteInputFiles(folderPath, "/SGCER040.SPE");
				
				rnhmm.WriteInputFiles(folderPath, "/Simulation.cde");
				
				rnhmm.WriteInputFiles(folderPath, "/SOIL.CDE");
				
				rnhmm.WriteInputFiles(folderPath, "/WEATHER.CDE");
				
				rnhmm.WriteInputFiles(folderPath, "/soil.sol");
				
				rnhmm.WriteInputFiles(folderPath, "/GATI0301.WTH");
				
				//rnhmm.WriteInputFiles(folderPath2, "GCM.txt");
				
				//rnhmm.WriteInputFiles(folderPath2, "DSSATCSM40");
				
				rnhmm.WriteInputFiles(folderPath, "/1-21.WTH");*/
				
				/********Read the crop Model File into the Folder*********/
				/*FileChannel ic = new FileInputStream("DSSATCSM40").getChannel();
				System.out.println(folderPath);
				FileChannel oc = new FileOutputStream(folderPath+"/DSSATCSM40").getChannel();
				ic.transferTo(0,ic.size(),oc);
				ic.close();
				oc.close();*/
				
			//}
			//System.out.println(HMMInput);

			

		  /*  filename = folderPath+ "/Tmax.cdf";
			urlString = servletURLPattern_Tmax.replace("{{minLat}}", String.valueOf(minLat))
						.replace("{{maxLat}}",String.valueOf(maxLat)).replace("{{minLon}}", String.valueOf(minLon)).
						replace("{{maxLon}}", String.valueOf(maxLon)).replace("{{id}}",String.valueOf(id));
		    //System.out.println("urlString :" + urlString);
		    saveUrl(filename , urlString);

		    /*filename = folderPath2+ "/[X+Y]Tmin.tsv";
			urlString = servletURLPattern_Tmin.replace("{{minLat}}", String.valueOf(minLat))
						.replace("{{maxLat}}",String.valueOf(maxLat)).replace("{{minLon}}", String.valueOf(minLon)).
						replace("{{maxLon}}", String.valueOf(maxLon)).replace("{{id}}",String.valueOf(id));
		    //System.out.println("urlString :" + urlString);
		    saveUrl(filename , urlString);*/
		    
		    
		    

			//}//end of while
		//}//end of if


		}
		/*catch(ClassNotFoundException Exception)	{
			System.out.println("error occoured during loading the driver");
		}*/
		catch(Exception e){
		System.out.println("error occoured during connecting " + e);
		e.printStackTrace();
		}
	}