diff --git a/src/Makefile.am b/src/Makefile.am index 5a1540a8..3d24b418 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -60,9 +60,6 @@ write_musrRoot_runHeader_SOURCES = write_musrRoot_runHeader.cpp musrRootValidation_SOURCES = musrRootValidation.cpp dump_header_SOURCES = dump_header.cpp -xmldir = $(HOME)/.musrfit -xml_DATA = musrfit_startup.xml - LIBADD = $(PMUSR_LIBS) $(MUSR_ROOT_LIBS) $(LEM_LIBS) $(PSIBIN_LIBS) $(MUD_LIBS) $(PNEXUS_LIBS) AM_CXXFLAGS = $(LOCAL_BIN_CXXFLAGS) @@ -75,42 +72,3 @@ endif LIBS = $(PMUSR_LIBS) $(USERFCN_LIBS) $(MUSR_ROOT_LIBS) $(LEM_LIBS) $(PSIBIN_LIBS) $(MUD_LIBS) $(PNEXUS_LIBS) \ $(FFTW3_LIBS) $(GSL_LIBS) $(ROOT_LIBS) $(LIBXML2_LIBS) - -install-xmlDATA: $(xml_DATA) - test -z "$(xmldir)" || $(mkdir_p) "$(DESTDIR)$(xmldir)" - @if test -e "$(DESTDIR)$(xmldir)/$(xml_DATA)"; then \ - DIFF="$$(diff "$(DESTDIR)$(xmldir)/$(xml_DATA)" "$(xml_DATA)" 2>&1)"; \ - if test "x$$DIFF" != "x"; then \ - echo " " && \ - echo " musrfit_startup.xml in $(xmldir)" && \ - echo " is different from the distribution's version." && \ - echo " Do you want to overwrite it? [y/N]" && \ - read OVERWRITE && \ - if test "$$OVERWRITE" = "y" || test "$$OVERWRITE" = "Y"; then \ - echo "$(INSTALL_DATA) '$(xml_DATA)' '$(DESTDIR)$(xmldir)'" && \ - $(INSTALL_DATA) '$(xml_DATA)' '$(DESTDIR)$(xmldir)'; \ - fi; \ - fi; \ - else \ - echo "$(INSTALL_DATA) '$(xml_DATA)' '$(DESTDIR)$(xmldir)'" && \ - $(INSTALL_DATA) '$(xml_DATA)' '$(DESTDIR)$(xmldir)'; \ - fi - -uninstall-xmlDATA: - @if test -e "$(DESTDIR)$(xmldir)/$(xml_DATA)"; then \ - DIFF="$$(diff "$(DESTDIR)$(xmldir)/$(xml_DATA)" "$(xml_DATA)" 2>&1)"; \ - if test "x$$DIFF" != "x"; then \ - echo " " && \ - echo " musrfit_startup.xml in $(xmldir)" && \ - echo " is different from the distribution's version." && \ - echo " Do you want to remove it? [y/N]" && \ - read REMOVE && \ - if test "$$REMOVE" = "y" || test "$$REMOVE" = "Y"; then \ - echo "$(RM) '$(DESTDIR)$(xmldir)/$(xml_DATA)'" && \ - $(RM) "$(DESTDIR)$(xmldir)/$(xml_DATA)"; \ - fi; \ - else \ - echo "$(RM) '$(DESTDIR)$(xmldir)/$(xml_DATA)'" && \ - $(RM) "$(DESTDIR)$(xmldir)/$(xml_DATA)"; \ - fi; \ - fi diff --git a/src/classes/PStartupHandler.cpp b/src/classes/PStartupHandler.cpp index 6ce00364..e2bde964 100644 --- a/src/classes/PStartupHandler.cpp +++ b/src/classes/PStartupHandler.cpp @@ -27,6 +27,9 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include +#include + #include #include #include @@ -140,6 +143,23 @@ PStartupHandler::PStartupHandler() } } } + + // if musrfit_startup.xml is still not found, will create a default one + if (!fStartupFileFound) { + cout << endl << "**INFO** no musrfit_startup.xml file found, will write a default one." << endl; + if (!WriteDefaulStartupFile()) { + cerr << endl << "**ERROR** couldn't write default musrfit_startup.xml." << endl; + } else { + home = getenv("HOME"); + if (home != 0) { + sprintf(startup_path_name, "%s/.musrfit/musrfit_startup.xml", home); + if (StartupFileExists(startup_path_name)) { + fStartupFilePath = TString(startup_path_name); + fStartupFileFound = true; + } + } + } + } } //-------------------------------------------------------------------------- @@ -566,6 +586,107 @@ Bool_t PStartupHandler::StartupFileExists(Char_t *fln) return result; } +//-------------------------------------------------------------------------- +// WriteDefaulStartupFile +//-------------------------------------------------------------------------- +Bool_t PStartupHandler::WriteDefaulStartupFile() +{ + // get home + Char_t startup_path_name[256]; + Char_t *home=0; + home = getenv("HOME"); + if (home == 0) { + cerr << endl << "**ERROR** couldn't obtain $HOME." << endl; + return false; + } + + // first check that $HOME/.musrfit exists and if NOT create it + struct stat info; + + sprintf(startup_path_name, "%s/.musrfit", home); + if (!stat(startup_path_name, &info)) { + if (!(info.st_mode & S_IFDIR)) + return false; + } else { + if (mkdir(startup_path_name, 0777)) { + cerr << endl << "**ERROR** couldn't create '" << startup_path_name << "'" << endl; + return false; + } + } + + // set path-name for musrfit_startup.xml + sprintf(startup_path_name, "%s/.musrfit/musrfit_startup.xml", home); + + ofstream fout(startup_path_name, ofstream::out); + if (!fout.is_open()) { + cerr << endl << "**ERROR** couldn't open '" << startup_path_name << "' for writing." << endl; + return false; + } + + // write default musrfit_startup.xml + fout << "" << endl; + fout << "" << endl; + fout << " " << endl; + fout << " Defines default settings for the musrfit package" << endl; + fout << " " << endl; + fout << " /mnt/data/nemu/his" << endl; + fout << " /mnt/data/nemu/wkm" << endl; + fout << " /afs/psi.ch/project/nemu/data/his" << endl; + fout << " /afs/psi.ch/project/nemu/data/wkm" << endl; + fout << " /afs/psi.ch/project/bulkmusr/data/gps" << endl; + fout << " /afs/psi.ch/project/bulkmusr/data/dolly" << endl; + fout << " /afs/psi.ch/project/bulkmusr/data/gpd" << endl; + fout << " /afs/psi.ch/project/bulkmusr/data/ltf" << endl; + fout << " /afs/psi.ch/project/bulkmusr/data/alc" << endl; + fout << " /afs/psi.ch/project/bulkmusr/data/hifi" << endl; + fout << " /afs/psi.ch/project/bulkmusr/data/lem" << endl; + fout << " " << endl; + fout << " Gauss" << endl; + fout << " 0" << endl; + fout << " none" << endl; + fout << " real_and_imag" << endl; + fout << " 0.0" << endl; + fout << " 1.0" << endl; + fout << " " << endl; + fout << " " << endl; + fout << " " << endl; + fout << " " << endl; + fout << " 24 " << endl; + fout << " 25 " << endl; + fout << " 26 " << endl; + fout << " 27 " << endl; + fout << " 28 " << endl; + fout << " 29 " << endl; + fout << " 30 " << endl; + fout << " 20 " << endl; + fout << " 21 " << endl; + fout << " 22 " << endl; + fout << " 23 " << endl; + fout << " 2 " << endl; + fout << " 3 " << endl; + fout << " 5 " << endl; + fout << " " << endl; + fout << " " << endl; + fout << " " << endl; + fout << " 0,0,0 " << endl; + fout << " 255,0,0 " << endl; + fout << " 0,255,0 " << endl; + fout << " 0,0,255 " << endl; + fout << " 255,0,255 " << endl; + fout << " 0,255,255 " << endl; + fout << " 153,0,255 " << endl; + fout << " 102,102,51 " << endl; + fout << " 51,102,51 " << endl; + fout << " 153,0,0 " << endl; + fout << " " << endl; + fout << " " << endl; + fout << "" << endl; + + fout.close(); + + return true; +} + // ------------------------------------------------------------------------- // end // ------------------------------------------------------------------------- diff --git a/src/include/PStartupHandler.h b/src/include/PStartupHandler.h index 89602014..2f44fd9b 100644 --- a/src/include/PStartupHandler.h +++ b/src/include/PStartupHandler.h @@ -94,6 +94,7 @@ class PStartupHandler : public TObject, public TQObject PIntVector fColorList; ///< color list Bool_t StartupFileExists(Char_t *fln); + Bool_t WriteDefaulStartupFile(); ClassDef(PStartupHandler, 1) }; diff --git a/src/musrfit_startup.xml b/src/musrfit_startup.xml deleted file mode 100644 index 3aa5ab57..00000000 --- a/src/musrfit_startup.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - Defines default settings for the musrfit package - - /mnt/data/nemu/his - /mnt/data/nemu/wkm - /afs/psi.ch/project/nemu/data/his - /afs/psi.ch/project/nemu/data/wkm - /afs/psi.ch/project/bulkmusr/data/gps - /afs/psi.ch/project/bulkmusr/data/dolly - /afs/psi.ch/project/bulkmusr/data/gpd - /afs/psi.ch/project/bulkmusr/data/ltf - /afs/psi.ch/project/bulkmusr/data/alc - /afs/psi.ch/project/bulkmusr/data/hifi - /afs/psi.ch/project/bulkmusr/data/lem - - Gauss - 0 - none - real_and_imag - 0.0 - 1.0 - - - - - 24 - 25 - 26 - 27 - 28 - 29 - 30 - 20 - 21 - 22 - 23 - 2 - 3 - 5 - - - - 0,0,0 - 255,0,0 - 0,255,0 - 0,0,255 - 255,0,255 - 0,255,255 - 153,0,255 - 102,102,51 - 51,102,51 - 153,0,0 - - -