void getInputFile(char *file){ printf("Input File: "); scanf("%s[64]", file); while(!checkOpenFile(file)){ printf("'%s' is not usable!\nInput File: ", file); scanf("%s[64]", file); } }
/** * Loads a tomography parameterization file into a newly created table * workspace. The file must have the following syntax: * * @verbatim <NXentry name="entry1"> <NXprocess name="processing"> <NXnote name="id"> <values id="ID VALUE" params="..." name="..." cite="..."> </values> </NXnote> </NXprocess> </NXentry> @endverbatim * * @param fname name of the parameterization file * @param wsName name of workspace where to load the file data * * @return table workspace with parameters (plugins) found in the * loaded file */ ITableWorkspace_sptr LoadSavuTomoConfig::loadFile(std::string& fname, std::string& wsName) { // Throws an exception if there is a problem with file access //Mantid::NeXus::NXRoot root(fname); boost::shared_ptr<NeXus::File> f; if (!checkOpenFile(fname, f)) { throw std::runtime_error( "Failed to recognize this file as a NeXus file, cannot continue."); } ITableWorkspace_sptr ws = API::WorkspaceFactory::Instance().createTable(); if (!ws) throw std::runtime_error("Could not create TableWorkspace for " "workspace with name '" + wsName + "'"); // init workspace ws->setTitle("Table with tomography parameters from file " + fname); ws->addColumn("str", "ID"); ws->addColumn("str", "Parameters"); ws->addColumn("str", "Name"); ws->addColumn("str", "Cite"); // a bit of file consistency check, check at least there's a // 'entry1' // it could be more strict and demand entries.size()==1 std::map<std::string, std::string> entries = f->getEntries(); std::string mainEntryName = "entry"; auto it = entries.find(mainEntryName); if (entries.end() == it) { throw std::runtime_error("Could not find the '" + mainEntryName + "' " "entry. Even though this file looks like a valid NeXus file, it is " "not in the correct format for tomography reconstruction " "parameterization files."); } // go through the input file plugin entries f->openGroup(mainEntryName, "NXentry"); f->openGroup("process", "NXprocess"); size_t pluginsLen = f->getEntries().size(); for (size_t j=0; j<pluginsLen; j++) { API::TableRow table = ws->appendRow(); std::string entryIdx = boost::lexical_cast<std::string>(j); try { f->openGroup(entryIdx, "NXnote"); } catch(NeXus::Exception &e) { // detailed NeXus error message and throw... g_log.error() << "Failed to load plugin '" << j << "' from" "NeXus file. Error description: " << e.what() << std::endl; throw std::runtime_error("Could not load one or more plugin " "entries from the tomographic reconstruction parameterization " "file. Please check that the file is correct."); } // TODO: check final 'schema', get these 4 fields from the file std::string id = ""; std::string params = ""; std::string name = ""; std::string cite = ""; try { f->readData("data", params); f->readData("id", id); f->readData("name", name); // cite not available for now // f->readData("cite", cite); // This might be extended to an NXcite group that would be included // not here but inside an "intermediate" NXcollection group. That // NXcite would have 4 arrays: description, doi, endnote, bibtex. // But this is what we have so far. cite = "Not available"; } catch(NeXus::Exception &e) { // permissive, just error message but carry on g_log.warning() << "Failed to read some fields in tomographic " "reconstruction plugin line. The file seems to be wrong. Error " "description: " << e.what() << std::endl; } table << id << params << name << cite; f->closeGroup(); progress(static_cast<double>(j)/static_cast<double>(pluginsLen)); } f->close(); return ws; }