internal static void GenerateControlFiles(string destinationFilePath, DateTime startDate, DateTime endDate, byte timeStep, UEBPackageRequest uebPkgRequest) { TimeSeriesFiles timeSeriesFiles = new TimeSeriesFiles(); //TODO: check the destinationFilePath exists // destinationFilePath value should be E:\CIWaterData\Temp when testing on localhost if (Directory.Exists(destinationFilePath) == false) { string errMsg = destinationFilePath + " was not found for creating UEB control files."; _logger.Error(errMsg); throw new Exception(errMsg); } try { //create the Overallcontrol.dat file CreateOverallControlFile(destinationFilePath, uebPkgRequest); //create the param.dat file //CreateParameterFile(destinationFilePath); //create the siteinital.dat file CreateSiteInitialFile(destinationFilePath, uebPkgRequest); //create the inputcontrol.dat file CreateInputControlFile(destinationFilePath, uebPkgRequest, timeSeriesFiles); //create the netCDFFileList.dat file //CreateNetCCDFFileListFile(destinationFilePath); // due to format change as suggested by Tseganeh // create dat files listing each of the timeseries netcdf files CreateNetCDFTimeSeriesListFiles(destinationFilePath, uebPkgRequest, timeSeriesFiles); //create the outputcontrol.dat file //CreateOutputControlFile(destinationFilePath); //create the aggregatedoutputcontrol.dat file //CreateAggregatedOutputControlFile(destinationFilePath); } catch (Exception ex) { string errMsg = "Failed to create UEB control files.\n"; errMsg += ex.Message; _logger.Fatal(errMsg); throw new Exception(errMsg); } }
//string destFiePath, DateTime startDate, DateTime endDate, byte timeStep, UEBPackageRequest uebPkgRequest private static void CreateInputControlFile(string destFiePath, UEBPackageRequest uebPkgRequest, TimeSeriesFiles timeSeriesFiles) { // TODO: remove magic strings used in this method //create the inputcontrol.dat file string fileName = "inputcontrol.dat"; string fileToWriteTo = Path.Combine(destFiePath, fileName); DateTime startDate = uebPkgRequest.StartDate; DateTime endDate = uebPkgRequest.EndDate; byte timeStep = uebPkgRequest.TimeStep; using (StreamWriter sw = new StreamWriter(fileToWriteTo)) { sw.WriteLine("Input Control file"); string dateFormat = "yyyy MM dd hh.mm"; sw.WriteLine(startDate.ToString(dateFormat)); // yyyy mm dd hh.mm (starting Date) sw.WriteLine(endDate.ToString(dateFormat)); // yyyy mm dd hh.mm (ending Date) sw.WriteLine(timeStep); // time step //TODO: Check how can we avoid hard coding this UTC time offset value sw.WriteLine("6.00"); // UTC time offset sw.WriteLine("Ta: Air temperature (always required)"); if (uebPkgRequest.TimeSeriesInputs.is_ta_compute) { sw.WriteLine("1"); // variable flag value for SCTC type variable sw.WriteLine("Talist.dat;X:x;Y:y;time:time;D:T;range:-20,40"); // this is the new format suggested by Tseganeh timeSeriesFiles.TaFileName = "Talist.dat"; } else if(uebPkgRequest.TimeSeriesInputs.is_ta_constant) { sw.WriteLine("2"); // variable flag value for SCTC type variable sw.WriteLine(uebPkgRequest.TimeSeriesInputs.ta_constant_value); // value of ta variable } else if (uebPkgRequest.TimeSeriesInputs.ta_grid_file_name.EndsWith(".nc")) { sw.WriteLine("1"); // variable flag value for SCTC type variable sw.WriteLine("Talist.dat;" + uebPkgRequest.TimeSeriesInputs.ta_grid_file_format + ";range:-20,40"); timeSeriesFiles.TaFileName = "Talist.dat"; } else if(string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.ta_text_file_name) == false) { sw.WriteLine("0"); // variable flag value for SCTC type variable sw.Write(uebPkgRequest.TimeSeriesInputs.ta_text_file_name); } sw.WriteLine("Prec: Precipitation (always required)"); if (uebPkgRequest.TimeSeriesInputs.is_prec_compute) { sw.WriteLine("1"); // variable flag value for SCTC type variable sw.WriteLine("Preclist.dat;X:x;Y:y;time:time;D:Prec"); // this is the new format suggested by Tseganeh timeSeriesFiles.PrecFileName = "Preclist.dat"; } else if (uebPkgRequest.TimeSeriesInputs.is_prec_constant) { sw.WriteLine("2"); // variable flag value for SCTC type variable sw.WriteLine(uebPkgRequest.TimeSeriesInputs.prec_constant_value); // value of prec variable } else if (uebPkgRequest.TimeSeriesInputs.prec_grid_file_name.EndsWith(".nc")) { sw.WriteLine("1"); // variable flag value for SCTC type variable sw.WriteLine("Preclist.dat;" + uebPkgRequest.TimeSeriesInputs.prec_grid_file_format); timeSeriesFiles.PrecFileName = "Preclist.dat"; } else if (string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.prec_text_file_name) == false) { sw.WriteLine("0"); // variable flag value for SCTC type variable sw.WriteLine(uebPkgRequest.TimeSeriesInputs.prec_text_file_name); } sw.WriteLine("v: Wind speed (always required)"); if (uebPkgRequest.TimeSeriesInputs.is_v_compute) { sw.WriteLine("1"); // variable flag value for SCTC type variable sw.WriteLine("Vlist.dat;X:x;Y:y;time:time;D:V"); // this is the new format suggested by Tseganeh timeSeriesFiles.VFileName = "Vlist.dat"; } else if (uebPkgRequest.TimeSeriesInputs.is_v_constant) { sw.WriteLine("2"); // variable flag value for SCTC type variable sw.WriteLine(uebPkgRequest.TimeSeriesInputs.v_constant_value); // value of v variable } else if (uebPkgRequest.TimeSeriesInputs.v_grid_file_name.EndsWith(".nc")) { sw.WriteLine("1"); // variable flag value for SCTC type variable sw.WriteLine("Vlist.dat;" + uebPkgRequest.TimeSeriesInputs.v_grid_file_format); timeSeriesFiles.VFileName = "Vlist.dat"; } else if (string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.v_text_file_name) == false) { sw.WriteLine("0"); // variable flag value for SCTC type variable sw.WriteLine(uebPkgRequest.TimeSeriesInputs.v_text_file_name); } sw.WriteLine("RH: Relative humidity (always required)"); if (uebPkgRequest.TimeSeriesInputs.is_rh_compute) { sw.WriteLine("1"); // variable flag value for SCTC type variable sw.WriteLine("RHlist.dat;X:x;Y:y;time:time;D:rh"); // this is the new format suggested by Tseganeh timeSeriesFiles.RhFileName = "RHlist.dat"; } else if (uebPkgRequest.TimeSeriesInputs.is_rh_constant) { sw.WriteLine("2"); // variable flag value for SCTC type variable sw.WriteLine(uebPkgRequest.TimeSeriesInputs.rh_constant_value); // value of rh variable } else if (uebPkgRequest.TimeSeriesInputs.rh_grid_file_name.EndsWith(".nc")) { sw.WriteLine("1"); // variable flag value for SCTC type variable sw.WriteLine("RHlist.dat;" + uebPkgRequest.TimeSeriesInputs.rh_grid_file_format); // this is the new format suggested by Tseganeh timeSeriesFiles.RhFileName = "RHlist.dat"; } else if (string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.rh_text_file_name) == false) { sw.WriteLine("0"); // variable flag value for SCTC type variable sw.WriteLine(uebPkgRequest.TimeSeriesInputs.rh_text_file_name); } if (uebPkgRequest.TimeSeriesInputs.is_snowalb_compute == false) { if (uebPkgRequest.TimeSeriesInputs.is_snowalb_constant) { sw.WriteLine("Snowalb: Snow albedo (0-1). (only required if ireadalb=1) The albedo of the snow surface to be used when the internal albedo calculations are to be overridden"); sw.WriteLine("2"); // variable flag value for SCTC type variable sw.WriteLine(uebPkgRequest.TimeSeriesInputs.snowalb_constant_value); } else if (uebPkgRequest.TimeSeriesInputs.snowalb_grid_file_name.EndsWith(".nc")) { sw.WriteLine("1"); // variable flag value for SCTC type variable sw.WriteLine("Snowalblist.dat;" + uebPkgRequest.TimeSeriesInputs.snowalb_grid_file_format); // this is the new format suggested by Tseganeh timeSeriesFiles.SnowalbFileName = "Snowalblist.dat"; } else if (string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.snowalb_text_file_name) == false) { sw.WriteLine("0"); // variable flag value for SCTC type variable sw.WriteLine(uebPkgRequest.TimeSeriesInputs.snowalb_text_file_name); } } if (uebPkgRequest.TimeSeriesInputs.is_qg_constant) { sw.WriteLine("Qg: : Ground heat flux (kJ/m2/hr)"); sw.WriteLine("2"); // variable flag value for SCTC type variable sw.WriteLine(uebPkgRequest.TimeSeriesInputs.qg_constant_value); } else if (uebPkgRequest.TimeSeriesInputs.qg_grid_file_name.EndsWith(".nc")) { sw.WriteLine("1"); // variable flag value for SCTC type variable sw.WriteLine("Qglist.dat;" + uebPkgRequest.TimeSeriesInputs.snowalb_grid_file_format); // this is the new format suggested by Tseganeh timeSeriesFiles.QgFileName = "Qglist.dat"; } else if (string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.qg_text_file_name) == false) { sw.WriteLine("0"); // variable flag value for SCTC type variable sw.WriteLine(uebPkgRequest.TimeSeriesInputs.qg_text_file_name); } } _logger.Info(fileName + " file was created."); }
private static void CreateNetCDFTimeSeriesListFiles(string destFiePath, UEBPackageRequest uebPkgRequest, TimeSeriesFiles timeSeriesFiles) { string fileToWriteTo = string.Empty; if (string.IsNullOrEmpty(timeSeriesFiles.TaFileName) == false) { fileToWriteTo = Path.Combine(destFiePath, timeSeriesFiles.TaFileName); using (StreamWriter sw = new StreamWriter(fileToWriteTo)) { if (uebPkgRequest.TimeSeriesInputs.is_ta_compute) { sw.WriteLine(UEB.UEBSettings.WATERSHED_MULTIPLE_TEMP_NETCDF_FILE_NAME); } else if (uebPkgRequest.TimeSeriesInputs.ta_grid_file_name.EndsWith(".nc")) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.ta_grid_file_name); } else if (string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.ta_text_file_name) == false) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.ta_text_file_name); } } _logger.Info(timeSeriesFiles.TaFileName + " file was created."); } if (string.IsNullOrEmpty(timeSeriesFiles.PrecFileName) == false) { fileToWriteTo = Path.Combine(destFiePath, timeSeriesFiles.PrecFileName); using (StreamWriter sw = new StreamWriter(fileToWriteTo)) { if (uebPkgRequest.TimeSeriesInputs.is_prec_compute) { sw.WriteLine(UEB.UEBSettings.WATERSHED_MULTIPLE_PRECP_NETCDF_FILE_NAME); } else if (uebPkgRequest.TimeSeriesInputs.prec_grid_file_name.EndsWith(".nc")) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.prec_grid_file_name); } else if (string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.prec_text_file_name) == false) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.prec_text_file_name); } } _logger.Info(timeSeriesFiles.PrecFileName + " file was created."); } if (string.IsNullOrEmpty(timeSeriesFiles.VFileName) == false) { fileToWriteTo = Path.Combine(destFiePath, timeSeriesFiles.VFileName); using (StreamWriter sw = new StreamWriter(fileToWriteTo)) { if (uebPkgRequest.TimeSeriesInputs.is_v_compute) { sw.WriteLine(UEB.UEBSettings.WATERSHED_MULTIPLE_WIND_NETCDF_FILE_NAME); } else if (uebPkgRequest.TimeSeriesInputs.v_grid_file_name.EndsWith(".nc")) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.v_grid_file_name); } else if (string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.v_text_file_name) == false) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.v_text_file_name); } } _logger.Info(timeSeriesFiles.VFileName + " file was created."); } if (string.IsNullOrEmpty(timeSeriesFiles.RhFileName) == false) { fileToWriteTo = Path.Combine(destFiePath, timeSeriesFiles.RhFileName); using (StreamWriter sw = new StreamWriter(fileToWriteTo)) { if (uebPkgRequest.TimeSeriesInputs.is_rh_compute) { sw.WriteLine(UEB.UEBSettings.WATERSHED_MULTIPLE_RH_NETCDF_FILE_NAME); } else if (uebPkgRequest.TimeSeriesInputs.rh_grid_file_name.EndsWith(".nc")) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.rh_grid_file_name); } else if (string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.rh_text_file_name) == false) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.rh_text_file_name); } } _logger.Info(timeSeriesFiles.RhFileName + " file was created."); } if (string.IsNullOrEmpty(timeSeriesFiles.SnowalbFileName) == false) { fileToWriteTo = Path.Combine(destFiePath, timeSeriesFiles.SnowalbFileName); using (StreamWriter sw = new StreamWriter(fileToWriteTo)) { if (uebPkgRequest.TimeSeriesInputs.snowalb_grid_file_name.EndsWith(".nc")) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.snowalb_grid_file_name); } else if (string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.snowalb_text_file_name) == false) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.snowalb_text_file_name); } } _logger.Info(timeSeriesFiles.SnowalbFileName + " file was created."); } if (string.IsNullOrEmpty(timeSeriesFiles.QgFileName) == false) { fileToWriteTo = Path.Combine(destFiePath, timeSeriesFiles.QgFileName); using (StreamWriter sw = new StreamWriter(fileToWriteTo)) { if (uebPkgRequest.TimeSeriesInputs.qg_grid_file_name.EndsWith(".nc")) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.qg_grid_file_name); } else if (string.IsNullOrEmpty(uebPkgRequest.TimeSeriesInputs.qg_text_file_name) == false) { sw.WriteLine(uebPkgRequest.TimeSeriesInputs.qg_text_file_name); } } _logger.Info(timeSeriesFiles.QgFileName + " file was created."); } }