public override bool OnEnd(object data) { HDFGlue tool = new HDFGlue(); tool.AppName = "convert.2.hdf5.exe"; tool.AppPath = @"..\Run.1\convert\"; tool.WorkingDirectory = @"..\Run.1\convert\"; bool res = true; MohidRunEngineData mre = (MohidRunEngineData)data; string cumulativeFolder = @"..\cumulative\"; tool.Output = cumulativeFolder + "basin.refevtp.hdf5"; tool.Is3DFile = false; tool.FilesToGlue.Clear(); System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(mre.storeFolder.Path); foreach (System.IO.DirectoryInfo g in dir.GetDirectories()) { if (System.IO.File.Exists(g.FullName + System.IO.Path.DirectorySeparatorChar + "basin.refevtp.hdf5")) tool.FilesToGlue.Add(g.FullName + System.IO.Path.DirectorySeparatorChar + "basin.refevtp.hdf5"); } if (tool.FilesToGlue.Count > 0) if (tool.Glue() != 0) res = false; return res; }
protected bool GenerateMeteoFilesFromSources() { try { DateTime simStartDate = mre.sim.Start, simEndDate = mre.sim.End, simStart = simStartDate.AddSeconds(1), startsim, endsim; FileName file = new FileName(); string input_start_tag; string input_end_tag; bool found_file = false; System.IO.FileInfo fi; Dictionary<string, KeywordData> meteoFolderList; string dateStr; int maxSkips = root["max.skips", 10].AsInt(); int numberOfSkips = 0; List<string> requiredFiles = new List<string>(); bool isFirstInstant; long minimum_size; List<ConfigNode> sources = root.ChildNodes.FindAll(delegate(ConfigNode to_match) { return to_match.Name == "meteo.source"; }); bool skipInterpolation = root["skip.interpolation", false].AsBool(); if (sources == null) return false; if (sources.Count <= 0) return false; filesToGlue.Clear(); //This will ensure that the first hour of simulation is included in the meteo file. startsim = simStart.AddHours(-5); endsim = startsim.AddHours(5); Console.WriteLine("Sim start date : {0}", simStartDate.ToString("yyyy/MM/dd HH:mm:ss")); Console.WriteLine("Sim enddate : {0}", simEndDate.ToString("yyyy/MM/dd HH:mm:ss")); Console.WriteLine("Sim lenght (days): {0}", mre.sim.SimLenght); isFirstInstant = true; file.FullPath = ""; while (startsim < mre.sim.End || !found_file) { dateStr = startsim.ToString("yyyyMMddHH") + "_" + endsim.ToString("yyyyMMddHH"); Console.WriteLine("Looking for file {0}", "*" + dateStr + "*"); foreach (ConfigNode src in sources) { input_start_tag = src["input.start.tag", "D3_"].AsString(); input_end_tag = src["input.end.tag", ""].AsString(); minimum_size = src["minimum.size", 2000000].AsLong(); ConfigNode folders_list = src.ChildNodes.Find(delegate(ConfigNode to_match) { return to_match.Name == "meteo.folders.list"; }); if (folders_list == null) { //If the list of folders were not provided, looks for the meteo.folder keyword. //If the keyword is also missing, uses a default folder, that in this case will be 'H' meteoFolderList = new Dictionary<string, KeywordData>(); meteoFolderList.Add("1", root["meteo.folder", @"H:\"]); } else { meteoFolderList = folders_list.NodeData; } foreach (KeywordData folder in meteoFolderList.Values) { found_file = false; file.FullPath = folder.AsFilePath().Path + input_start_tag + dateStr + input_end_tag + ".hdf5"; if (System.IO.File.Exists(file.FullPath)) { fi = new System.IO.FileInfo(file.FullPath); if (fi.Length > minimum_size) { Console.WriteLine(" Found at {0} [{1}]", folder.AsFilePath().Path, src["name", ""].AsString()); if (!skipInterpolation) { try { Console.Write(" Interpolating file...."); if (!InterpolateMeteoFile(file, src)) { Console.WriteLine("[failed]"); continue; } else Console.WriteLine("[ok]"); } catch (Exception ex) { Console.WriteLine("[exception]"); Console.WriteLine(" Message returned: {0}", ex.Message); continue; } } else { filesToGlue.Add(file.FullPath); } found_file = true; break; } } } if (found_file) break; } if (!found_file) { Console.WriteLine(" Not found!", file); if ((++numberOfSkips) > maxSkips) { Console.WriteLine("Max number of skips reached during meteo creation file."); return false; } if (isFirstInstant) //first file in the list { Console.WriteLine("Going backward..."); endsim = startsim.AddHours(-1); startsim = startsim.AddHours(-6); continue; } else { Console.WriteLine("Skipping for the next file..."); startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); } } else if (isFirstInstant && numberOfSkips > 0) { numberOfSkips = 0; startsim = simStart.AddHours(1); endsim = startsim.AddHours(5); } else if (startsim > mre.sim.End) { numberOfSkips = 0; break; } else { numberOfSkips = 0; startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); } if (isFirstInstant && found_file) isFirstInstant = false; } //Now the interpolated files are glued HDFGlue glueTool = new HDFGlue(filesToGlue); glueTool.AppName = root["glue.exe.name", "glue.exe"].AsString(); glueTool.AppPath = root["glue.exe.path", @"..\tools\glue\"].AsString(); glueTool.WorkingDirectory = root["glue.working.folder", @"..\tools\glue\"].AsString(); glueTool.Output = outputPath + outputName; glueTool.Is3DFile = false; glueTool.ThrowExceptionOnError = true; Console.WriteLine("Gluing files..."); if (glueTool.Glue() != 0) { Console.WriteLine("Glue failed."); return false; } //Delete all the files in the temp directory try { System.IO.DirectoryInfo directory = new DirectoryInfo(@"..\tools\interpolation\temp\"); foreach (System.IO.FileInfo fileToDelete in directory.GetFiles()) fileToDelete.Delete(); } catch (Exception ex) { Console.WriteLine("Was not possible to empty the temp directory due to an exception."); Console.WriteLine("Message returned was: {0}", ex.Message); } //Saves the created meteo file in the folder if (!FileTools.CopyFile(root["local.boundary.conditions"].AsFilePath(), generalBoundary, "meteo.hdf5", Files.CopyOptions.OVERWRIGHT)) { Console.WriteLine("Was not possible to copy the meteo file to the meteo storage folder."); return false; } return true; } catch { return false; } }
protected bool GenerateMeteoFiles() { DateTime simStartDate = mre.sim.Start, simEndDate = mre.sim.End, simStart = simStartDate.AddSeconds(1), startsim, endsim; string dateStr; int counter; string mm5NewFilesFolder; FileName file = new FileName(); bool found_file = false; System.IO.FileInfo fi; Dictionary<string, KeywordData> meteoFolderList; filesToGlue.Clear(); if (root.NodeData.ContainsKey("new.mm5.folder")) mm5NewFilesFolder = root["new.mm5.folder"].AsFilePath().Path; else mm5NewFilesFolder = ""; //-------------------------------------------------------------------------------------------------------------- //1. Loads the list of folders to look for the meteo files. //-------------------------------------------------------------------------------------------------------------- ConfigNode foldersListNode = root.ChildNodes.Find(FindFoldersListBlocks); if (foldersListNode == null) { //If the list of folders were not provided, looks for the meteo.folder keyword. //If the keyword is also missing, uses a default folder, that in this case will be 'H' meteoFolderList = new Dictionary<string, KeywordData>(); meteoFolderList.Add("1", root["meteo.folder", @"H:\"]); } else { meteoFolderList = foldersListNode.NodeData; } //-------------------------------------------------------------------------------------------------------------- Console.WriteLine("Sim start date : {0}", simStartDate.ToString("yyyy/MM/dd HH:mm:ss")); Console.WriteLine("Sim enddate : {0}", simEndDate.ToString("yyyy/MM/dd HH:mm:ss")); Console.WriteLine("Sim lenght (days): {0}", mre.sim.SimLenght); //Console.WriteLine("Generating Meteo file from {0} to {1}", startsim.ToString("yyyy/MM/dd HH:mm:ss"), mre.sim.End.ToString("yyyy/MM/dd HH:mm:ss")); bool skipInterpolation = root["skip.interpolation", false].AsBool(); //This will ensure that the first hour of simulation is included in the meteo file. startsim = simStart.AddHours(-5); endsim = startsim.AddHours(5); //-------------------------------------------------------------------------------------------------------------- //2. Find the required files. The meteo file must contain data for the entire simulation period //-------------------------------------------------------------------------------------------------------------- bool isFirstInstant; Console.WriteLine("Folder where meteo files are: {0}", root["meteo.folder", @"H:\"].AsString()); Console.WriteLine(""); Console.WriteLine("Looking for files..."); Console.WriteLine(""); int maxSkips = root["max.skips", 10].AsInt(); int numberOfSkips = 0; List<string> requiredFiles = new List<string>(); Console.WriteLine("The folowing folders will be used on searching meteo files:"); counter = 0; foreach (KeywordData folder in meteoFolderList.Values) { counter++; Console.WriteLine(" {0}. {1}", counter, folder.AsFilePath().Path); } Console.WriteLine(""); isFirstInstant = true; file.FullPath = ""; while (startsim < mre.sim.End || !found_file) { dateStr = startsim.ToString("yyyyMMddHH") + "_" + endsim.ToString("yyyyMMddHH"); Console.WriteLine("Looking for {0}", @"D3_" + dateStr + ".hdf5"); foreach (KeywordData folder in meteoFolderList.Values) { found_file = false; file.FullPath = folder.AsFilePath().Path + @"D3_" + dateStr + ".hdf5"; if (System.IO.File.Exists(file.FullPath)) { fi = new System.IO.FileInfo(file.FullPath); if (fi.Length > 2000000) { Console.WriteLine(" Found at {0}", folder.AsFilePath().Path); if (!skipInterpolation) { try { Console.Write(" Interpolating file...."); if (!InterpolateMeteoFile(file)) { Console.WriteLine("[failed]"); continue; } else Console.WriteLine("[ok]"); } catch (Exception ex) { Console.WriteLine("[exception]"); Console.WriteLine(" Message returned: {0}", ex.Message); continue; } } else { filesToGlue.Add(file.FullPath); } found_file = true; break; } } } ////try to find the file (the period) in the "monthly" files in mohid land //if (!found_file && mm5NewFilesFolder != "") //{ // pathToFilesToGlue = root["mm5.months.folder"].AsFilePath().Path + // startsim.ToString("yyyy") + @"\"; // monthly_file = "MM5-D3-Portugal-" + startsim.ToString("yyyy-MM") + ".hdf5"; // if (System.IO.File.Exists(pathToFilesToGlue + monthly_file)) // { // //find block with info for extractor // ConfigNode extractorNode = root.ChildNodes.Find(FindHDFExtractorBlocks); // if (extractorNode != null) // { // ExternalApp extractorTool = new ExternalApp(); // replace_list.Clear(); // replace_list["<<input.hdf>>"] = pathToFilesToGlue + monthly_file; // replace_list["<<output.hdf>>"] = mm5NewFilesFolder + @"D3_" + dateStr + ".hdf5"; // replace_list["<<start>>"] = startsim.ToString("yyyy MM dd HH 00 00"); // replace_list["<<end>>"] = endsim.ToString("yyyy MM dd HH 00 00"); // string template = extractorNode["template", mre.sim.SimDirectory.Path + @"templates\tools\extractor.template"].AsString(); // string action = extractorNode["config.file.name", "extractor.cfg"].AsString(); // Console.WriteLine("Extracting template {0}.", action); // TextFile.Replace(template, extractorNode["working.folder", @"..\tools\extraction\"].AsFilePath().Path + action, ref replace_list); // extractorTool.WorkingDirectory = extractorNode["working.folder", @"..\tools\extraction\"].AsFilePath().Path; // extractorTool.Executable = root["extractor.exe", @"..\tools\extraction\extractor.exe"].AsString(); // extractorTool.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT; // extractorTool.TextToCheck = "successfully terminated"; // extractorTool.SearchTextOrder = SearchTextOrder.FROMEND; // extractorTool.Wait = true; // bool result = extractorTool.Run(); // if (!result) // { // Console.WriteLine("Extraction failed."); // } // else // { // requiredFiles.Add(mm5NewFilesFolder + file); // found_file = true; // } // } // } //} if (!found_file) { Console.WriteLine(" Not found!", file); if ((++numberOfSkips) > maxSkips) { Console.WriteLine("Max number of skips reached during meteo creation file."); return false; } if (isFirstInstant) //first file in the list { Console.WriteLine("Going backward..."); endsim = startsim.AddHours(-1); startsim = startsim.AddHours(-6); continue; } else { Console.WriteLine("Skipping for the next file..."); startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); } } else if (isFirstInstant && numberOfSkips > 0) { numberOfSkips = 0; counter = 0; startsim = simStart.AddHours(1); endsim = startsim.AddHours(5); } else if (startsim > mre.sim.End) { numberOfSkips = 0; break; } else { numberOfSkips = 0; startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); } if (isFirstInstant && found_file) isFirstInstant = false; } //-------------------------------------------------------------------------------------------------------------- //Now the interpolated files are glued HDFGlue glueTool = new HDFGlue(filesToGlue); glueTool.AppName = root["glue.exe.name", "glue.exe"].AsString(); glueTool.AppPath = root["glue.exe.path", @"..\tools\glue\"].AsString(); glueTool.WorkingDirectory = root["glue.working.folder", @"..\tools\glue\"].AsString(); glueTool.Output = outputPath + outputName; glueTool.Is3DFile = false; glueTool.ThrowExceptionOnError = true; Console.WriteLine("Gluing files..."); if (glueTool.Glue() != 0) { Console.WriteLine("Glue failed."); return false; } //Delete all the files in the temp directory try { System.IO.DirectoryInfo directory = new DirectoryInfo(@"..\tools\interpolation\temp\"); foreach (System.IO.FileInfo fileToDelete in directory.GetFiles()) fileToDelete.Delete(); } catch (Exception ex) { Console.WriteLine("Was not possible to empty the temp directory due to an exception."); Console.WriteLine("Message returned was: {0}", ex.Message); } //Saves the created meteo file in the folder if (!FileTools.CopyFile(root["local.boundary.conditions"].AsFilePath(), generalBoundary, "meteo.hdf5", Files.CopyOptions.OVERWRIGHT)) { Console.WriteLine("Was not possible to copy the meteo file to the meteo storage folder."); return false; } return true; }
protected bool Glue(DateTime start, DateTime end, List<string> list) { try { HDFGlue tool_glue = new HDFGlue(); tool_glue.Reset(); tool_glue.FilesToGlue = list; tool_glue.AppName = fGlueExe; tool_glue.AppPath = fGlueExePath; tool_glue.WorkingDirectory = fGlueWorkingFolder; tool_glue.Output = fOutputPath + fOutputTag + start.ToString("yyyyMMddHH") + "_" + end.ToString("yyyyMMddHH") + ".hdf5"; tool_glue.Is3DFile = false; tool_glue.ThrowExceptionOnError = true; tool_glue.Glue(); } catch (Exception ex) { fLastException = ex; return false; } return true; }
protected bool GenerateMeteoFiles(MohidRunEngineData mre) { //bool result = true; DateTime simStartDate = mre.sim.Start; DateTime startsim; DateTime endsim; string dateStr; DateTime simStart = simStartDate.AddSeconds(1); int counter; string file; bool found_file; System.IO.FileInfo fi; //First is required the glue of two files HDFGlue tool = new HDFGlue(); tool.AppName = "glue.exe"; tool.AppPath = @"..\tools\glue\"; tool.WorkingDirectory = @"..\tools\glue\"; tool.Output = @"..\" + mre.sim.SimDirectory.Path + @"local.data\boundary.conditions\mm5.glued.hdf5"; tool.Is3DFile = false; startsim = simStart.AddHours(-5); endsim = startsim.AddHours(5); Console.WriteLine("Sim start: {0}", simStartDate.ToString("yyyy/MM/dd HH:mm:ss")); Console.WriteLine("Generating Meteo file from {0} to {1}", startsim.ToString("yyyy/MM/dd HH:mm:ss"), startsim.AddHours(11).ToString("yyyy/MM/dd HH:mm:ss")); Console.WriteLine("Gluing files..."); for (counter = 0; counter < 57; counter++) { found_file = false; dateStr = startsim.ToString("yyyyMMddHH") + "_" + endsim.ToString("yyyyMMddHH"); file = @"H:\mm5_6h\" + startsim.ToString("yyyy") + @"\D3_" + dateStr + ".hdf5"; if (System.IO.File.Exists(file)) { fi = new System.IO.FileInfo(file); if (fi.Length > 2000000) found_file = true; } if (!found_file && startsim.Year == 2008) { file = @"H:\mm5_6h\2008_ANL\D3_" + dateStr + ".hdf5"; if (System.IO.File.Exists(file)) { fi = new System.IO.FileInfo(file); if (fi.Length > 2000000) found_file = true; } } if (!found_file) { file = @"\\DATACENTER\alexandria3\modelos\Meteo_IST\mm5_6h\D3_" + dateStr + ".hdf5"; if (System.IO.File.Exists(file)) { fi = new System.IO.FileInfo(file); if (fi.Length > 2000000) found_file = true; } } if (!found_file) { Console.WriteLine("The file 'D3_{0}.hdf5' was not found.", dateStr); return false; } else { tool.FilesToGlue.Add(file); //Console.WriteLine("Adding {0} to the list of files to be glued.", @"H:\mm5_6h\" + startsim.ToString("yyyy") + @"\D3_" + dateStr + ".hdf5"); startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); } } tool.ThrowExceptionOnError = true; if (tool.Glue() != 0) return false; Dictionary<string, string> replace_list = new Dictionary<string, string>(); replace_list["<<glued>>"] = @"..\" + mre.sim.SimDirectory.Path + @"local.data\boundary.conditions\"; replace_list["<<father>>"] = @"..\..\general.data\digital.terrain\"; replace_list["<<dest>>"] = @"..\..\general.data\boundary.conditions\" + mre.sim.Start.ToString("yyyyMMdd.HHmmss") + "-" + mre.sim.End.ToString("yyyyMMdd.HHmmss") + @"\"; replace_list["<<model>>"] = @"..\..\general.data\digital.terrain\"; TextFile.Replace(mre.sim.SimDirectory.Path + @"templates\tools\convert.to.HDF5.action.template", @"..\tools\interpolation\converttoHDF5action.dat", ref replace_list); //Now, do the "extraction" //if (!FileTools.CopyFile(new FileName(mre.sim.SimDirectory.Path + @"templates\tools\convert.to.HDF5.action.template"), new FileName(@"..\tools\interpolation\converttoHDF5action.dat"), CopyOptions.OVERWRIGHT)) // return false; ExternalApp app = new ExternalApp(); app.Executable = @"..\tools\interpolation\interpolation.exe"; app.WorkingDirectory = @"..\tools\interpolation\"; app.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT; app.TextToCheck = "successfully terminated"; app.SearchTextOrder = SearchTextOrder.FROMEND; app.Wait = true; Console.WriteLine("Interpolating meteo file to model grid..."); return app.Run(); }
protected bool Glue(DateTime start, DateTime end, List<string> list, ConfigNode log_entry) { try { string output = fOutputPath + fOutputTag + start.ToString("yyyyMMddHH") + "_" + end.ToString("yyyyMMddHH") + ".hdf5"; if (fLogExecution) log_entry.NodeData["glue.exception"].Set(""); if (!fOverwrite) { if (File.Exists(output)) { if (fLogExecution) log_entry.NodeData["output.file"].Set("[exists] " + output); return true; } } if (fLogExecution) log_entry.NodeData["output.file"].Set(output); HDFGlue tool_glue = new HDFGlue(); tool_glue.Reset(); tool_glue.FilesToGlue = list; tool_glue.AppName = fGlueExe; tool_glue.AppPath = fGlueExePath; tool_glue.WorkingDirectory = fGlueWorkingFolder; tool_glue.Output = output; tool_glue.Is3DFile = false; tool_glue.ThrowExceptionOnError = true; tool_glue.Glue(); } catch (Exception ex) { fLastException = ex; if (fLogExecution) log_entry.NodeData["glue.exception"].Set(ex.Message); return false; } return true; }
protected bool GenerateMeteoFiles(MohidRunEngineData mre) { DateTime simStartDate = mre.sim.Start; DateTime startsim; DateTime endsim; string dateStr; DateTime simStart = simStartDate.AddSeconds(1); int counter; string file, outputPath, outputName; bool found_file; System.IO.FileInfo fi; ConfigNode node = mre.cfg.Root.ChildNodes.Find(FindScriptBlocks); if (node == null) { Console.WriteLine("Node 'script.data' was not found in the config file."); return false; } //First is required the glue of the files HDFGlue tool = new HDFGlue(); tool.AppName = node["glue.exe.name", "glue.exe"].AsString(); tool.AppPath = node["glue.exe.path", @"..\tools\glue\"].AsString(); tool.WorkingDirectory = node["glue.working.folder", @"..\tools\glue\"].AsString(); outputPath = node["glue.output.path", @"..\" + mre.sim.SimDirectory.Path + @"local.data\boundary.conditions\"].AsString(); outputName = node["glue.output.name", "mm5.glued.hdf5"].AsString(); tool.Output = outputPath + outputName; tool.Is3DFile = false; //This will ensure that the first hour of simulation is included in the meteo file. startsim = simStart.AddHours(-5); endsim = startsim.AddHours(5); int maxSkips = node["max.skips", 10].AsInt(); int numberOfSkips = 0; Console.WriteLine("Sim start: {0}", simStartDate.ToString("yyyy/MM/dd HH:mm:ss")); Console.WriteLine("Generating Meteo file from {0} to {1}", startsim.ToString("yyyy/MM/dd HH:mm:ss"), mre.sim.End.ToString("yyyy/MM/dd HH:mm:ss")); Console.WriteLine("Sim lenght: {0}", mre.sim.SimLenght); int numberOfFiles = (int)(mre.sim.SimLenght * 4 + 1.0); Console.WriteLine("Expected number of 6 hours files to look: {0}", numberOfFiles); Console.WriteLine("Folder where meteo files are: {0}", node["meteo.folder", @"H:\"].AsString()); Console.WriteLine(""); Console.WriteLine("Looking for files..."); Console.WriteLine(""); for (counter = 0; counter < numberOfFiles; counter++) { found_file = false; dateStr = startsim.ToString("yyyyMMddHH") + "_" + endsim.ToString("yyyyMMddHH"); file = node["meteo.folder", @"H:\"].AsString() + @"D3_" + dateStr + ".hdf5"; if (System.IO.File.Exists(file)) { fi = new System.IO.FileInfo(file); if (fi.Length > 2000000) { found_file = true; tool.FilesToGlue.Add(file); } } if (!found_file) { Console.WriteLine("File '{0}' was not found.", file); if (counter + 1 == numberOfFiles) { counter--; numberOfSkips++; if (numberOfSkips > maxSkips) { Console.WriteLine("Max number of skips reached during meteo creation file."); return false; } } } startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); } Console.WriteLine("Gluing files..."); tool.ThrowExceptionOnError = true; if (tool.Glue() != 0) { Console.WriteLine("Glue failed."); return false; } Dictionary<string, string> replace_list = new Dictionary<string, string>(); replace_list["<<glued>>"] = outputPath; replace_list["<<father>>"] = node["father.grid", @"..\..\general.data\digital.terrain\"].AsString(); replace_list["<<dest>>"] = node["hdf.output.path", @"..\..\general.data\boundary.conditions\"].AsString() + mre.sim.Start.ToString("yyyyMMdd.HHmmss") + "-" + mre.sim.End.ToString("yyyyMMdd.HHmmss") + @"\"; replace_list["<<model>>"] = node["model.grid", @"..\..\general.data\digital.terrain\"].AsString(); string template = node["template", mre.sim.SimDirectory.Path + @"templates\tools\convert.to.HDF5.action.template"].AsString(); string action = node["action.file", @"..\tools\interpolation\converttoHDF5action.dat"].AsString(); TextFile.Replace(template, action, ref replace_list); ExternalApp app = new ExternalApp(); app.WorkingDirectory = node["interpolation.working.folder", @"..\tools\interpolation\"].AsString(); app.Executable = node["interpolation.exe", @"..\tools\interpolation\interpolation.exe"].AsString(); app.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT; app.TextToCheck = "successfully terminated"; app.SearchTextOrder = SearchTextOrder.FROMEND; app.Wait = true; Console.WriteLine("Interpolating meteo file to model grid..."); bool result = app.Run(); if (!result) { Console.WriteLine("Interpolation failed."); return false; } //Saves the created meteo file in the folder if (!FileTools.CopyFile(new FilePath(replace_list["<<dest>>"]), new FilePath(orig.Path), "meteo.hdf5", Files.CopyOptions.OVERWRIGHT)) { Console.WriteLine("Was not possible to copy the meteo file to the meteo storage folder."); return false; } return true; }
protected bool GlueFilesAsMM5(FileName file_to_process) { bool result = true; bool glue_now = true; string output; try { //if (last_stored_path != store_path.Path) //{ // last_stored_path = store_path.Path; // actual_index = 1; //} if ((actual_index >= 2 && actual_index <= 7 && first_glue_as_mm5) || (actual_index >= 8 && actual_index <= 13 && second_glue_as_mm5)) { string file_name; if (process_hdf) file_name = file_to_process.Path + file_to_process.Name.Substring(0, file_to_process.Name.Length - output_tag.Length) + "." + file_to_process.Extension; else file_name = file_to_process.FullPath; files_to_glue.Add(new FileName(file_name)); } else files_to_glue.Clear(); //actual_index++; if (files_to_glue.Count == 6) { string path; if (glue_on_separeted_folders) path = store_glue_folder.Path + last_store_name; else path = store_glue_folder.Path; //Console.WriteLine("{0}", store_glue_folder.Path); //Console.WriteLine("{0}", last_store_name); //Console.WriteLine("{0}", files_to_glue[0]); //Console.WriteLine("{0}", files_to_glue[0].Substring(files_to_glue[0].Length-10-output_tag.Length, 10)); //string first = files_to_glue[0].Name.Substring(files_to_glue[0].Name.Length-10-output_tag.Length, 10); //string last = files_to_glue[5].Name.Substring(files_to_glue[5].Name.Length-10-output_tag.Length, 10); string first = files_to_glue[0].Name.Substring(files_to_glue[0].Name.Length - 10, 10); string last = files_to_glue[5].Name.Substring(files_to_glue[5].Name.Length - 10, 10); output = path + files_to_glue[0].Name.Substring(0, files_to_glue[0].Name.Length - 21) + "_" + first + "_" + last + ".hdf5"; if (!System.IO.Directory.Exists(path)) System.IO.Directory.CreateDirectory(path); if (!replace_glued_files) if (System.IO.File.Exists(output)) glue_now = false; files_temp.Clear(); foreach (FileName f in files_to_glue) { files_temp.Add(f.FullPath); } HDFGlue glueTool = new HDFGlue(files_temp); glueTool.AppName = glue_exe.FullName; glueTool.AppPath = glue_exe.Path; glueTool.WorkingDirectory = working_folder.Path; glueTool.Output = output; glueTool.Is3DFile = false; glueTool.ThrowExceptionOnError = false; glueTool.Verbose = false; if (glue_now) { Console.WriteLine(" ----------------------------------"); Console.Write(" Gluing actual folder files as mm5."); if (glueTool.Glue() != 0) result = false; if (result) Console.WriteLine("[OK]"); else Console.WriteLine("[FAIL]"); } files_to_glue.Clear(); store_files_for_glue = false; if (result && glue_all) { if (first_glue) { Console.Write(" Gluing final file................."); System.IO.File.Copy(output, store_glue_folder.Path + "glued.hdf5", true); Console.WriteLine("[OK]"); first_glue = false; } else { Console.Write(" Gluing final file................."); files_temp.Clear(); files_temp.Add(store_glue_folder.Path + "glued.hdf5"); files_temp.Add(output); glueTool.FilesToGlue = files_temp; glueTool.Output = working_folder.Path + "new_glued.hdf5"; if (glueTool.Glue() != 0) result = false; if (result) Console.WriteLine("[OK]"); else Console.WriteLine("[FAIL]"); if (result) { Console.Write(" Replacing final file.............."); System.IO.File.Copy(working_folder.Path + "new_glued.hdf5", store_glue_folder.Path + "glued.hdf5", true); Console.WriteLine("[OK]"); } files_to_glue.Clear(); } } Console.WriteLine(" ----------------------------------"); } } catch (Exception ex) { last_exception = ex; files_to_glue.Clear(); Console.WriteLine("[FAIL]"); Console.WriteLine(" ----------------------------------"); result = false; } return result; }
protected bool GlueFiles(FileName file_to_process) { bool result = true; bool glue_now = true; string output; try { //if (actual_index == 1) //{ // store_files_for_glue = true; //} Console.WriteLine(" Actual index = {0}", actual_index); Console.Write(" Marking file for GLUE............."); if (store_files_for_glue) { if (actual_index >= starting_hour) { string file_name; //if (process_hdf) // file_name = file_to_process.Path + file_to_process.Name.Substring(0, file_to_process.Name.Length - output_tag.Length) + "." + file_to_process.Extension; //else file_name = file_to_process.FullPath; files_to_glue.Add(new FileName(file_name)); Console.WriteLine("[OK]"); } else Console.WriteLine("[FALSE]"); //actual_index++; if (files_to_glue.Count >= hours_to_glue) { Console.WriteLine(" ----------------------------------"); Console.Write(" Starting GLUE."); string path; if (glue_on_separeted_folders) path = store_glue_folder.Path + last_store_name; else path = store_glue_folder.Path; //output = path + last_store_name + ".hdf5"; string first = files_to_glue[0].Name.Substring(files_to_glue[0].Name.Length - 10, 10); string last = files_to_glue[files_to_glue.Count - 1].Name.Substring(files_to_glue[files_to_glue.Count - 1].Name.Length - 10, 10); output = path + files_to_glue[0].Name.Substring(0, files_to_glue[0].Name.Length - 21) + "_" + first + "_" + last + ".hdf5"; Console.WriteLine(""); Console.WriteLine("=> {0} = {1}", files_to_glue[0].Name, first); Console.WriteLine("=> {0} = {1}", files_to_glue[files_to_glue.Count - 1].Name, last); Console.WriteLine("=> {0}", output); //Console.ReadKey(); Console.Write(" Output file: {0}", last_store_name + ".hdf5"); if (!System.IO.Directory.Exists(path)) System.IO.Directory.CreateDirectory(path); if (!replace_glued_files) if (System.IO.File.Exists(output)) glue_now = false; files_temp.Clear(); foreach (FileName f in files_to_glue) { files_temp.Add(f.FullPath); } HDFGlue glueTool = new HDFGlue(files_temp); glueTool.AppName = glue_exe.FullName; glueTool.AppPath = glue_exe.Path; glueTool.WorkingDirectory = working_folder.Path; glueTool.Output = output; glueTool.Is3DFile = false; glueTool.ThrowExceptionOnError = true; glueTool.Verbose = true; if (glue_now) { Console.WriteLine(" ----------------------------------"); Console.WriteLine(" glueTool.AppName: {0}", glueTool.AppName); Console.WriteLine(" glueTool.AppPath: {0}", glueTool.AppPath); Console.WriteLine(" glueTool.WorkingDirectory: {0}", glueTool.WorkingDirectory); Console.WriteLine(" ----------------------------------"); Console.WriteLine("List of files to glue:"); foreach (FileName file in files_to_glue) Console.WriteLine(" {0}", file.Name); Console.Write(" Gluing actual folder files........"); if (glueTool.Glue() != 0) { result = false; } else result = true; if (result) Console.WriteLine("[OK]"); else { Console.WriteLine("[FAIL]"); } } files_to_glue.Clear(); store_files_for_glue = false; if (result && glue_all) { if (first_glue) { Console.Write(" Gluing final file................."); System.IO.File.Copy(output, store_glue_folder.Path + "glued.hdf5", true); Console.WriteLine("[OK]"); first_glue = false; } else { Console.Write(" Gluing final file................."); files_temp.Add(store_glue_folder.Path + "glued.hdf5"); files_temp.Add(output); glueTool.FilesToGlue = files_temp; glueTool.Output = working_folder.Path + "new_glued.hdf5"; if (glueTool.Glue() != 0) result = false; if (result) Console.WriteLine("[OK]"); else Console.WriteLine("[FAIL]"); if (result) { Console.Write(" Replacing final file.............."); System.IO.File.Copy(working_folder.Path + "new_glued.hdf5", store_glue_folder.Path + "glued.hdf5", true); Console.WriteLine("[OK]"); } files_to_glue.Clear(); } } Console.WriteLine(" ----------------------------------"); } } else Console.WriteLine("[FALSE]"); } catch (Exception ex) { last_exception = ex; files_to_glue.Clear(); Console.WriteLine("[FAIL]"); Console.WriteLine(" ----------------------------------"); result = false; } //Console.ReadKey(); return result; }
public override bool OnSimStart(object data) { MohidRunEngineData mre = (MohidRunEngineData)data; //bool result = true; DateTime startsim; DateTime endsim; string dateStr; DateTime simStart = mre.sim.Start; int counter; //First is required the glue of two files HDFGlue tool = new HDFGlue(); tool.AppName = "ConvertToHdf5_release_single.exe"; tool.AppPath = @"..\tools\Convert 2 HDF\"; tool.WorkingDirectory = @"..\tools\Convert 2 HDF\"; tool.Output = @"mm5.glued.hdf5"; tool.Is3DFile = false; startsim = simStart.AddHours(-5); endsim = startsim.AddHours(5); string file_to_glue, path; int tentatives; bool must_find_another; for (counter = 0; counter < 5; counter++) { tentatives = 3; must_find_another = true; while (must_find_another) { dateStr = startsim.ToString("yyyyMMddHH") + "_" + endsim.ToString("yyyyMMddHH"); file_to_glue = @"D3_" + dateStr + ".hdf5"; path = @"Q:\"; if (System.IO.File.Exists(path + file_to_glue)) { must_find_another = false; tool.FilesToGlue.Add(path + file_to_glue); startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); } else { tentatives--; if (tentatives == 0) return false; if (counter == 0) { startsim = startsim.AddHours(-6); endsim = startsim.AddHours(-1); } else { startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); } } } } tool.ThrowExceptionOnError = true; if (tool.Glue() != 0) return false; FileName template = new FileName(mre.sim.SimDirectory.Path + @"templates\tools\interpolate.template"); FileName griddata = new FileName(mre.sim.SimDirectory.Path + @"templates\tools\grid.data.dat"); //Now, do the "extraction" if (!FileTools.CopyFile(template, new FileName(@"..\tools\convert 2 hdf\converttoHDF5action.dat"), CopyOptions.OVERWRIGHT)) return false; if (!FileTools.CopyFile(griddata, new FileName(@"..\tools\convert 2 hdf\grid.data.dat"), CopyOptions.OVERWRIGHT)) return false; ExternalApp app = new ExternalApp(); app.Executable = @"..\tools\convert 2 hdf\ConvertToHdf5_release_double.exe"; app.WorkingDirectory = @"..\tools\convert 2 hdf\"; app.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT; app.TextToCheck = "successfully terminated"; app.SearchTextOrder = SearchTextOrder.FROMEND; app.Wait = true; if (!app.Run()) return false; if (!FileTools.CopyFile(new FileName(@"..\tools\convert 2 hdf\meteo.mm5.hdf5"), new FileName(mre.sim.SimDirectory.Path + @"local data\meteo.mm5.hdf5"), CopyOptions.OVERWRIGHT)) return false; return true; }
protected bool GenerateMeteoFiles(DateTime start, DateTime end) { DateTime simStartDate =start, simEndDate = end, simStart = simStartDate.AddSeconds(1), startsim, endsim; string dateStr; int counter; string mm5NewFilesFolder; FileName file = new FileName(); bool found_file = false; System.IO.FileInfo fi; Dictionary<string, KeywordData> meteoFolderList; filesToGlue.Clear(); if (root.NodeData.ContainsKey("new.mm5.folder")) mm5NewFilesFolder = root["new.mm5.folder"].AsFilePath().Path; else mm5NewFilesFolder = ""; //-------------------------------------------------------------------------------------------------------------- //1. Loads the list of folders to look for the meteo files. //-------------------------------------------------------------------------------------------------------------- ConfigNode foldersListNode = root.ChildNodes.Find(FindFoldersListBlocks); if (foldersListNode == null) { //If the list of folders were not provided, looks for the meteo.folder keyword. //If the keyword is also missing, uses a default folder, that in this case will be 'H' meteoFolderList = new Dictionary<string, KeywordData>(); meteoFolderList.Add("1", root["meteo.folder"]); } else { meteoFolderList = foldersListNode.NodeData; } //-------------------------------------------------------------------------------------------------------------- Console.WriteLine("Sim start date : {0}", simStartDate.ToString("yyyy/MM/dd HH:mm:ss")); Console.WriteLine("Sim enddate : {0}", simEndDate.ToString("yyyy/MM/dd HH:mm:ss")); //Console.WriteLine("Generating Meteo file from {0} to {1}", startsim.ToString("yyyy/MM/dd HH:mm:ss"), mre.sim.End.ToString("yyyy/MM/dd HH:mm:ss")); bool skipInterpolation = root["skip.interpolation", false].AsBool(); //This will ensure that the first hour of simulation is included in the meteo file. startsim = simStart.AddHours(-5); endsim = startsim.AddHours(5); //-------------------------------------------------------------------------------------------------------------- //2. Find the required files. The meteo file must contain data for the entire simulation period //-------------------------------------------------------------------------------------------------------------- bool isFirstInstant; Console.WriteLine("Folder where meteo files are: {0}", root["meteo.folder"].AsString()); Console.WriteLine(""); Console.WriteLine("Looking for files..."); Console.WriteLine(""); int maxSkips = root["max.skips", 10].AsInt(); int numberOfSkips = 0; List<string> requiredFiles = new List<string>(); Console.WriteLine("The folowing folders will be used on searching meteo files:"); counter = 0; foreach (KeywordData folder in meteoFolderList.Values) { counter++; Console.WriteLine(" {0}. {1}", counter, folder.AsFilePath().Path); } Console.WriteLine(""); isFirstInstant = true; file.FullPath = ""; while (startsim < end || !found_file) { dateStr = startsim.ToString("yyyyMMddHH") + "_" + endsim.ToString("yyyyMMddHH"); Console.WriteLine("Looking for {0}", @"D3_" + dateStr + ".hdf5"); foreach (KeywordData folder in meteoFolderList.Values) { found_file = false; file.FullPath = folder.AsFilePath().Path + @"D3_" + dateStr + ".hdf5"; if (System.IO.File.Exists(file.FullPath)) { fi = new System.IO.FileInfo(file.FullPath); if (fi.Length > 2000000) { Console.WriteLine(" Found at {0}", folder.AsFilePath().Path); if (!skipInterpolation) { try { Console.Write(" Interpolating file...."); if (!InterpolateMeteoFile(file)) { Console.WriteLine("[failed]"); continue; } else Console.WriteLine("[ok]"); } catch (Exception ex) { Console.WriteLine("[exception]"); Console.WriteLine(" Message returned: {0}", ex.Message); continue; } } else { filesToGlue.Add(file.FullPath); } found_file = true; break; } } } if (!found_file) { Console.WriteLine(" Not found!", file); if ((++numberOfSkips) > maxSkips) { Console.WriteLine("Max number of skips reached during meteo creation file."); return false; } if (isFirstInstant) //first file in the list { Console.WriteLine("Going backward..."); endsim = startsim.AddHours(-1); startsim = startsim.AddHours(-6); continue; } else { Console.WriteLine("Skipping for the next file..."); startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); } } else if (isFirstInstant && numberOfSkips > 0) { numberOfSkips = 0; counter = 0; startsim = simStart.AddHours(1); endsim = startsim.AddHours(5); } else if (startsim > end) { numberOfSkips = 0; break; } else { numberOfSkips = 0; startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); } if (isFirstInstant && found_file) isFirstInstant = false; } //-------------------------------------------------------------------------------------------------------------- //Now the interpolated files are glued HDFGlue glueTool = new HDFGlue(filesToGlue); glueTool.AppName = root["glue.exe.name"].AsString(); glueTool.AppPath = root["glue.exe.path"].AsString(); glueTool.WorkingDirectory = root["glue.working.folder"].AsString(); glueTool.Output = outputPath + outputName; glueTool.Is3DFile = false; glueTool.ThrowExceptionOnError = true; Console.WriteLine("Gluing files..."); if (glueTool.Glue() != 0) { Console.WriteLine("Glue failed."); return false; } //Delete all the files in the temp directory try { System.IO.DirectoryInfo directory = new DirectoryInfo(tempFolder); foreach (System.IO.FileInfo fileToDelete in directory.GetFiles()) fileToDelete.Delete(); } catch (Exception ex) { Console.WriteLine("Was not possible to empty the temp directory due to an exception."); Console.WriteLine("Message returned was: {0}", ex.Message); } return true; }
protected bool GenerateMeteoFiles(MohidRunEngineData mre) { DateTime simStartDate = mre.sim.Start; DateTime startsim; DateTime endsim; string dateStr; DateTime simStart = simStartDate.AddSeconds(1); int counter; string file, outputPath, outputName, tempFolder; bool found_file; System.IO.FileInfo fi; HDFGlue glueTool = new HDFGlue(); ExternalApp interpolateTool = new ExternalApp(); ConfigNode node = mre.cfg.Root.ChildNodes.Find(FindScriptBlocks); if (node == null) { Console.WriteLine("Node 'script.data' was not found in the config file."); return false; } //This will ensure that the first hour of simulation is included in the meteo file. startsim = simStart.AddHours(-5); endsim = startsim.AddHours(5); Console.WriteLine("Sim start: {0}", simStartDate.ToString("yyyy/MM/dd HH:mm:ss")); Console.WriteLine("Generating Meteo file from {0} to {1}", startsim.ToString("yyyy/MM/dd HH:mm:ss"), mre.sim.End.ToString("yyyy/MM/dd HH:mm:ss")); Console.WriteLine("Sim lenght: {0}", mre.sim.SimLenght); //Get some important input from the script block in config file outputPath = node["glue.output.path", @"..\" + mre.sim.SimDirectory.Path + @"local.data\boundary.conditions\"].AsString(); outputName = node["glue.output.name", "meteo.hdf5"].AsString(); tempFolder = node["interpolation.folder", @".\temp\"].AsString(); //First, find the required files. int numberOfFiles = (int)(mre.sim.SimLenght * 4 + 1.0); Console.WriteLine("Expected number of 6 hours files to look: {0}", numberOfFiles); Console.WriteLine("Folder where meteo files are: {0}", node["meteo.folder", @"H:\"].AsString()); Console.WriteLine(""); Console.WriteLine("Looking for files..."); Console.WriteLine(""); int maxSkips = node["max.skips", 10].AsInt(); int numberOfSkips = 0; List<string> requiredFiles = new List<string>(); for (counter = 0; counter < numberOfFiles; counter++) { found_file = false; dateStr = startsim.ToString("yyyyMMddHH") + "_" + endsim.ToString("yyyyMMddHH"); file = node["meteo.folder", @"H:\"].AsString() + @"D3_" + dateStr + ".hdf5"; if (System.IO.File.Exists(file)) { fi = new System.IO.FileInfo(file); if (fi.Length > 2000000) { found_file = true; requiredFiles.Add(file); } } if (!found_file) { Console.WriteLine("File '{0}' was not found.", file); if (counter + 1 == numberOfFiles) { counter--; numberOfSkips++; if (numberOfSkips > maxSkips) { Console.WriteLine("Max number of skips reached during meteo creation file."); return false; } } } startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); } //Now the files were found, they will be interpolated to the model's grid Console.WriteLine("Interpolating meteo file to model grid..."); Dictionary<string, string> replace_list = new Dictionary<string, string>(); FileName f_name = new FileName(); string path = node["glue.input.folder", @"..\interpolation\temp\"].AsString(); bool skipInterpolation = node["skip.interpolation", false].AsBool(); foreach (string f in requiredFiles) { f_name.FullPath = f; glueTool.FilesToGlue.Add(path + f_name.FullName); if (!skipInterpolation) { replace_list["<<input.hdf>>"] = f; replace_list["<<father.grid>>"] = node["father.grid", @"..\..\general.data\digital.terrain\mm5.dat"].AsString(); replace_list["<<output.hdf>>"] = tempFolder + f_name.FullName; replace_list["<<model.grid>>"] = node["model.grid", @"..\..\general.data\digital.terrain\grid.dat"].AsString(); string template = node["template", mre.sim.SimDirectory.Path + @"templates\tools\convert.to.HDF5.action.template"].AsString(); string action = node["action.file", @"..\tools\interpolation\converttoHDF5action.dat"].AsString(); TextFile.Replace(template, action, ref replace_list); interpolateTool.WorkingDirectory = node["interpolation.working.folder", @"..\tools\interpolation\"].AsString(); interpolateTool.Executable = node["interpolation.exe", @"..\tools\interpolation\interpolation.exe"].AsString(); interpolateTool.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT; interpolateTool.TextToCheck = "successfully terminated"; interpolateTool.SearchTextOrder = SearchTextOrder.FROMEND; interpolateTool.Wait = true; bool result = interpolateTool.Run(); if (!result) { Console.WriteLine("Interpolation failed."); return false; } } } //Now the interpolated files are glued glueTool.AppName = node["glue.exe.name", "glue.exe"].AsString(); glueTool.AppPath = node["glue.exe.path", @"..\tools\glue\"].AsString(); glueTool.WorkingDirectory = node["glue.working.folder", @"..\tools\glue\"].AsString(); glueTool.Output = outputPath + outputName; glueTool.Is3DFile = false; glueTool.ThrowExceptionOnError = true; Console.WriteLine("Gluing files..."); if (glueTool.Glue() != 0) { Console.WriteLine("Glue failed."); return false; } //Saves the created meteo file in the folder if (!FileTools.CopyFile(node["local.boundary.folder", @"..\actual\local.data\boundary.conditions\"].AsFilePath(), new FilePath(orig.Path), "meteo.hdf5", Files.CopyOptions.OVERWRIGHT)) { Console.WriteLine("Was not possible to copy the meteo file to the meteo storage folder."); return false; } //Delete all the files in the temp directory try { System.IO.DirectoryInfo directory = new DirectoryInfo(@"..\tools\interpolation\temp\"); foreach (System.IO.FileInfo fileToDelete in directory.GetFiles()) fileToDelete.Delete(); } catch (Exception ex) { Console.WriteLine("Was not possible to empty the temp directory due to an exception."); Console.WriteLine("Message returned was: {0}", ex.Message); } return true; }
protected bool GlueFiles(HDFGlue glue, bool is3D, FilePath workingFolder, FilePath destinationFolder, FileName toGlue, MohidRunEngineData mre) { glue.Output = @"..\..\cumulative\" + toGlue.FullName; glue.Is3DFile = false; glue.FilesToGlue.Clear(); //Console.WriteLine("Checking if '{0}' exists", destinationFolder.Path + toGlue.FullName); if (!System.IO.File.Exists(destinationFolder.Path + toGlue.FullName)) { //if (!FileTools.CopyFile(toGlue, new FileName(destinationFolder.Path + toGlue.FullName), CopyOptions.OVERWRIGHT)) // return false; System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(mre.storeFolder.Path); foreach (System.IO.DirectoryInfo g in dir.GetDirectories()) { if (System.IO.File.Exists(g.FullName + System.IO.Path.DirectorySeparatorChar + toGlue.FullName)) { //Console.WriteLine("File '{0}' exists", g.FullName + "\\" + toGlue.FullName); glue.FilesToGlue.Add(g.FullName + System.IO.Path.DirectorySeparatorChar + toGlue.FullName); } else { //Console.WriteLine("File '{0}' DO NOT exists", g.FullName + "\\" + toGlue.FullName); } } //Console.WriteLine("Found {0} files to GLUE.", glue.FilesToGlue.Count.ToString()); if (glue.FilesToGlue.Count > 0) if (glue.Glue() != 0) return false; return true; } if (!FileTools.CopyFile(new FileName(destinationFolder.Path + toGlue.FullName), new FileName(workingFolder.Path + toGlue.FullName), CopyOptions.OVERWRIGHT)) return false; glue.FilesToGlue.Add(toGlue.FullName); glue.FilesToGlue.Add(".." + System.IO.Path.DirectorySeparatorChar + toGlue.FullPath); if (glue.Glue() != 0) return false; return true; }
protected bool GenerateAlternativeMeteoFilesToForecast(DateTime simStartDate) { //bool result = true; DateTime startsim; DateTime endsim; string dateStr; DateTime simStart = simStartDate.AddSeconds(1); char pd = System.IO.Path.DirectorySeparatorChar; //First is required the glue of two files HDFGlue tool = new HDFGlue(); tool.AppName = "glue.exe"; tool.AppPath = System.IO.Path.Combine("..", "tools", "glue"); tool.WorkingDirectory = tool.AppPath; tool.Output = "meteo.glued.hdf5"; tool.Is3DFile = false; startsim = simStart.AddHours(-5); endsim = startsim.AddHours(5); dateStr = startsim.ToString("yyyyMMddHH") + "_" + endsim.ToString("yyyyMMddHH"); tool.FilesToGlue.Add("\\\\ftpserver\\ftp.mohid.com\\LocalUser\\meteoIST\\mm5_6h\\D3_" + dateStr + ".hdf5"); startsim = endsim.AddHours(1); endsim = startsim.AddHours(5); dateStr = startsim.ToString("yyyyMMddHH") + "_" + endsim.ToString("yyyyMMddHH"); tool.FilesToGlue.Add("\\\\ftpserver\\ftp.mohid.com\\LocalUser\\meteoIST\\mm5_6h\\D3_" + dateStr + ".hdf5"); tool.ThrowExceptionOnError = true; if (tool.Glue() != 0) return false; //Now, do the "extraction" if (!FileTools.CopyFile(new FileName(@".."+ pd + "templates" + pd + "tools" + pd + "ConvertToHDF5Action-2.template"), new FileName(@".." + pd + "tools" + pd + "interpolation" + pd + "ConvertToHDF5Action.dat"), CopyOptions.OVERWRIGHT)) return false; ExternalApp app = new ExternalApp(); app.Executable = @".." + pd + "tools" + pd + "interpolation" + pd + "interpolation.exe"; app.WorkingDirectory = @".." + pd + "tools" + pd + "interpolation" + pd; app.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT; app.TextToCheck = "successfully terminated"; app.SearchTextOrder = SearchTextOrder.FROMEND; app.Wait = true; return app.Run(); }