void basicIO::dumpDEMdata() const
{
    if (time_.outputTime())
    {
        // make time directory
        if (parOutput_) lagPath_=buildFilePath(dirName_);
        else
        {
            Info << "createTimeDir(path_), path="<<path_ << endl;
            Info << "lagPath_=createTimeDir(fileName(lagPath_/lagrangian)), lagPath="<<path_ << endl;
        	lagPath_=createTimeDir(path_);
        	lagPath_=createTimeDir(fileName(lagPath_/"lagrangian"));
        }
        // calc the number of particles on proc
        int count(0);
        for(int index = 0;index < particleCloud_.numberOfParticles(); ++index)
            if (particleCloud_.cellIDs()[index][0] > -1) count++;
        nPProc_=count;
        
        // stream data to file
        streamDataToPath(lagPath_, particleCloud_.positions(), "positions","vector","Cloud<passiveParticle>","0");
        streamDataToPath(lagPath_, particleCloud_.velocities(), "v","vector","vectorField","");
        streamDataToPath(lagPath_, particleCloud_.radii(), "r","scalar","scalarField","");
    }
}
// Construct from components
basicIO::basicIO
(
    const dictionary& dict,
    cfdemCloud& sm
)
:
    IOModel(dict,sm),
    //propsDict_(dict.subDict(typeName + "Props")),
    dirName_("lagrangian"),
    path_("dev/null"),
    parOutput_(true),
    nPProc_(-1),
    lagPath_("dev/null")
{
	if (
            particleCloud_.dataExchangeM().myType()=="oneWayVTK" ||
            dict_.found("serialOutput")
       )
    {
        parOutput_=false;
        Warning << "IO model is in serial write mode, only data on proc 0 is written" << endl;
    }

    //if (propsDict_.found("dirName")) dirName_=word(propsDict_.lookup("dirName"));
    path_ = buildFilePath(dirName_);
}
Beispiel #3
0
OptionDirectory::OptionDirectory(string root, int id, string displayValue, string type) :
    OptionSelect(id, displayValue), root(root), type(type)
{
    vector<string> subfolders = JFileSystem::GetInstance()->scanfolder(root);
    
    for (size_t i = 0; i < subfolders.size(); ++i)
    {
        string subfolder = subfolders[i].substr(0, subfolders[i].length());
        if(subfolder[subfolders[i].length()-1] == '/')
        subfolder = subfolders[i].substr(0, subfolders[i].length() - 1); //remove trailing "/" 
        vector<string> path;
        path.push_back(root);
        path.push_back(subfolder);
        string filePath = buildFilePath(path, type);
        if (JFileSystem::GetInstance()->FileExists(filePath))
            addSelection(subfolder);
    }
    initSelections();
}
Beispiel #4
0
/*
**  Returns a pointer to the name of an rc file of the requested type.
**
**  Preconditions:
**      - MAXPATHLEN is set to the max. allowed path length
**      - fullPath points to a buffer of at least MAXPATHLEN
**
**  Returns:
**      - NULL if an error occurs while creating a directory
**      - Pointer to a static array containing the file name
**
*/
const char* GetRCFileName(int type)
{
    static char rcFiles[N_FILE_TYPES][MAXPATHLEN + 1];
    static int namesDetermined = False;

    if (!namesDetermined)
    {
        char* nedit_home;
        int i;

        if ((nedit_home = getenv("NEDIT_HOME")) == NULL)
        {
            /*  No NEDIT_HOME */
#ifdef VMS
            /* This is a default VMS setup */
            for (i = 0; i < N_FILE_TYPES; i++)
            {
                buildFilePath(rcFiles[i], "SYS$LOGIN", hiddenFileNames[i]);
            }
#else /* #ifdef VMS */
            /* Let's try if ~/.nedit is a regular file or not. */
            char legacyFile[MAXPATHLEN + 1];
            buildFilePath(legacyFile, GetHomeDir(), hiddenFileNames[NEDIT_RC]);
            if (isRegFile(legacyFile))
            {
                /* This is a legacy setup with rc files in $HOME */
                for (i = 0; i < N_FILE_TYPES; i++)
                {
                    buildFilePath(rcFiles[i], GetHomeDir(), hiddenFileNames[i]);
                }
            } else
            {
                /* ${HOME}/.nedit does not exist as a regular file. */
                /* FIXME: Devices, sockets and fifos are ignored for now. */
                char defaultNEditHome[MAXPATHLEN + 1];
                buildFilePath(defaultNEditHome, GetHomeDir(), DEFAULT_NEDIT_HOME);
                if (!isDir(defaultNEditHome))
                {
                    /* Create DEFAULT_NEDIT_HOME */
                    if (mkdir(defaultNEditHome, 0777) != 0)
                    {
                        perror("nedit: Error while creating rc file directory"
                                " $HOME/" DEFAULT_NEDIT_HOME "\n"
                                " (Make sure all parent directories exist.)");
                        return NULL;
                    }
                }

                /* All set for DEFAULT_NEDIT_HOME, let's copy the names */
                for (i = 0; i < N_FILE_TYPES; i++)
                {
                    buildFilePath(rcFiles[i], defaultNEditHome, plainFileNames[i]);
                }
            }
#endif /* #ifdef VMS */
        } else
        {
            /*  $NEDIT_HOME is set. */
#ifndef VMS
            /* FIXME: Is this required? Does VMS know stat(), mkdir()? */
            if (!isDir(nedit_home))
            {
                /* Create $NEDIT_HOME */
                if (mkdir(nedit_home, 0777) != 0)
                {
                    perror("nedit: Error while creating rc file directory $NEDIT_HOME\n"
                            "nedit: (Make sure all parent directories exist.)");
                    return NULL;
                }
            }
#endif /* #ifndef VMS */

            /* All set for NEDIT_HOME, let's copy the names */
            for (i = 0; i < N_FILE_TYPES; i++)
            {
                buildFilePath(rcFiles[i], nedit_home, plainFileNames[i]);
            }
        }

        namesDetermined = True;
    }

    return rcFiles[type];
}
Beispiel #5
0
    void onPrepared()
    {
      if (!m_OKToGo)
        return;

      if (!m_PlotProgram.isFound())
      {
        OPENFLUID_LogWarning("Required GNUplot program not found");
        m_OKToGo = false;
        return;
      }


      std::ostringstream TmpOSS;

      TmpOSS << ((OPENFLUID_GetEndDate().diffInSeconds(OPENFLUID_GetBeginDate())) / 2);

      m_PlotXTics = TmpOSS.str();


      prepareTempDirectory();

      if (!m_OKToGo)
        return;


      openfluid::tools::Filesystem::removeDirectory(m_TmpDir+"/"+m_GNUPlotSubDir);
      openfluid::tools::Filesystem::makeDirectory(m_TmpDir+"/"+m_GNUPlotSubDir);

      if (!openfluid::tools::Filesystem::isDirectory(m_TmpDir+"/"+m_GNUPlotSubDir))
      {
        OPENFLUID_LogWarning("Cannot initialize gnuplot temporary directory");
        m_OKToGo = false;
        return;
      }



      // initialize data files

      for (std::list<KmlSerieInfo>::iterator it=m_KmlSeriesInfos.begin();it!=m_KmlSeriesInfos.end();++it)
      {
        if ((*it).VarsListStr == "*")
        {
          (*it).VarsList =
              mp_SpatialData->spatialUnits((*it).UnitsClass)->list()->front().variables()->getVariablesNames();
        }
        else
        {
          openfluid::tools::tokenizeString((*it).VarsListStr,(*it).VarsList,";");
        }

        if ((*it).VarsList.empty())
        {
          OPENFLUID_LogWarning("Variable list is empty");
          m_OKToGo = false;
          return;
        }


        for (std::map<openfluid::core::UnitID_t,KmlUnitInfoExtra>::iterator it2=(*it).UnitsInfos.begin();
            it2!=(*it).UnitsInfos.end();
            ++it2)
        {

          if ((*it2).second.IsPlotted)
          {
            std::string DataFilename =
                buildFilePath(m_TmpDir+"/"+m_GNUPlotSubDir,
                              (*it).UnitsClass,(*it2).second.UnitID,
                              "","dat");

            (*it2).second.DataFile = new std::ofstream(DataFilename.c_str());
            (*((*it2).second.DataFile)) << "#" << DataFilename << "\n";
          }
        }
      }
    }
Beispiel #6
0
    void writeKmlFile(const std::string& DocFilePath)
    {
      std::ofstream KmlFile(DocFilePath.c_str());

      KmlFile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
      KmlFile << "<kml xmlns=\"http://www.opengis.net/kml/2.2\" "
                 "xmlns:gx=\"http://www.google.com/kml/ext/2.2\" "
                 "xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";

      KmlFile << "<Document>\n";

      KmlFile << "  <name>" << m_Title << "</name>\n";
      KmlFile << "  <open>1</open>\n";

      for (std::list<KmlSerieInfo>::iterator it=m_KmlSeriesInfos.begin();it!=m_KmlSeriesInfos.end();++it)
      {

        std::string TmpStyleID = (*it).UnitsClass +"_style";

        if ((*((*it).UnitsInfos.begin())).second.GeometryType == wkbPolygon)
        {
          KmlFile << "    <Style id=\"" << TmpStyleID << "\"><PolyStyle><color>"<< (*it).DefaultColor
                  << "</color><outline>1</outline></PolyStyle></Style>\n";
          KmlFile << "    <Style id=\"" << TmpStyleID << "_plotted\"><PolyStyle><color>"<< (*it).PlottedColor
                  << "</color></PolyStyle><outline>1</outline></Style>\n";
        }
        else if ((*((*it).UnitsInfos.begin())).second.GeometryType == wkbLineString)
        {
          KmlFile << "    <Style id=\"" << TmpStyleID << "\"><LineStyle><color>"<< (*it).DefaultColor
                  << "</color><width>" << (*it).LineWidth
                  << "</width></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>\n";
          KmlFile << "    <Style id=\"" << TmpStyleID << "_plotted\"><LineStyle><color>"
                  << (*it).PlottedColor << "</color><width>" << (*it).LineWidth
                  << "</width></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>\n";
        }
        else
        {
          OPENFLUID_LogWarning("Unsupported geometry format in source geometry file");
          m_OKToGo = false;
          return;
        }

        KmlFile << "    <Folder>\n";
        KmlFile << "      <name>" << (*it).UnitsClass << "</name>\n";

        for (std::map<openfluid::core::UnitID_t,KmlUnitInfoExtra>::iterator it2=(*it).UnitsInfos.begin();
            it2!=(*it).UnitsInfos.end();
            ++it2)
        {
          KmlFile << "    <Placemark>\n";


          KmlFile << "      <name>" << (*it).UnitsClass << " " << (*it2).second.UnitID << "</name>\n";

          KmlFile << "      <description>\n<![CDATA[\n";
          KmlFile << "Unit class: " << (*it).UnitsClass << "<br/>\n";
          KmlFile << "Unit ID: " << (*it2).second.UnitID << "<br/>\n";

          KmlFile << "<br/>\n";

          if ((*it2).second.IsPlotted)
          {
            KmlFile << "<img src=\"" << buildFilePath(m_KmzDataSubDir,(*it).UnitsClass,
                                                      (*it2).second.UnitID,"","png") << "\"/>\n";
          }

          KmlFile << "\n]]>\n      </description>\n";


          if ((*it2).second.IsPlotted)
          {
            KmlFile << "      <styleUrl>#" << TmpStyleID << "_plotted</styleUrl>\n";
          }
          else
          {
            KmlFile << "      <styleUrl>#" << TmpStyleID << "</styleUrl>\n";
          }



          if ((*it2).second.GeometryType == wkbPolygon)
          {
            KmlFile << "<Polygon><tessellate>1</tessellate><outerBoundaryIs><LinearRing><coordinates>"
                    << (*it2).second.CoordsStr << "</coordinates></LinearRing></outerBoundaryIs></Polygon>\n";
          }
          else if ((*it2).second.GeometryType == wkbLineString)
          {
            KmlFile << "<LineString><tessellate>1</tessellate><coordinates>" << (*it2).second.CoordsStr
                    << "</coordinates></LineString>\n";
          }
          else
          {
            OPENFLUID_LogWarning("Unsupported geometry format in source geometry file");
            m_OKToGo = false;
            return;
          }


          KmlFile << "    </Placemark>\n";
        }

        KmlFile << "    </Folder>\n";
      }


      KmlFile << "</Document>\n";
      KmlFile << "</kml>\n";
      KmlFile.close();
    }
Beispiel #7
0
    void buildGnuplotImages(const std::string& WorkDir, const std::string& DestDir)
    {
      for (std::list<KmlSerieInfo>::iterator it=m_KmlSeriesInfos.begin();it!=m_KmlSeriesInfos.end();++it)
      {
        for (std::map<openfluid::core::UnitID_t,KmlUnitInfoExtra>::iterator it2=(*it).UnitsInfos.begin();
            it2!=(*it).UnitsInfos.end();
            ++it2)
        {

          if ((*it2).second.IsPlotted)
          {
            std::string ScriptFilename = WorkDir+"/tmpscript.gp";
            std::string DataFilename = buildFilePath(WorkDir,(*it).UnitsClass,
                                                     (*it2).second.UnitID,"","dat");
            std::string OutputFilename = buildFilePath(DestDir,(*it).UnitsClass,
                                                       (*it2).second.UnitID,"","png");

            unsigned int Columns = 1;
            unsigned int Rows = 1;

            if ((*it).VarsList.size() > 1)
            {
              Columns = (unsigned int)(std::ceil(std::sqrt((*it).VarsList.size())));
              Rows = (unsigned int)(std::ceil((*it).VarsList.size() / Columns));
            }


            std::ofstream ScriptFile(ScriptFilename.c_str());
            ScriptFile << "set terminal png size 640,480 small\n";
            ScriptFile << "set output \"" << OutputFilename << "\"\n";
            ScriptFile << "set nokey\n";
            ScriptFile << "set xdata time\n";
            ScriptFile << "set timefmt \"%Y%m%d-%H%M%S\"\n";
            ScriptFile << "set datafile separator \";\"\n";
            ScriptFile << "set datafile commentschars \"#\"\n";
            ScriptFile << "set format x \"%Y-%m-%d\\n%H:%M:%S\"\n";
            ScriptFile << "set xtics " << m_PlotXTics << " font \",7\"\n";
            ScriptFile << "set ytics autofreq font \",7\"\n";

            ScriptFile << "set origin 0,0\n";
            ScriptFile << "set multiplot layout " << Rows << "," << Columns << " rowsfirst scale 1,1\n";

            for (unsigned int i=0; i< (*it).VarsList.size();i++)
            {
              ScriptFile << "set title \"" << (*it).VarsList[i] << "\" font \",9\"\n";
              ScriptFile << "plot \""<< DataFilename << "\" using 1:"<< (i+2) <<" with lines\n";
            }

            ScriptFile << "unset multiplot\n";

    //        ScriptFile << "set title \"" << (*it).VarName << "\" font \",9\"\n";
    //        ScriptFile << "plot \""<< DataFilename << "\" using 1:2 with lines\n";
            ScriptFile.close();


            // execution of the script

            if (m_PlotProgram.isFound())
            {

              QString GNUPlotCommand = QString("\"%1\" \"%2\"").arg(m_PlotProgram.getFullProgramPath())
                                                               .arg(QString::fromStdString(ScriptFilename));
              QProcess::execute(GNUPlotCommand);
            }

          }
        }
      }

    }
Beispiel #8
0
// -------------------------------------------------------------------------
//  Returns a pointer to the name of an rc file of the requested type.
//
//  Preconditions:
//      - MAXPATHLEN is set to the max. allowed path length
//      - fullPath points to a buffer of at least MAXPATHLEN
//
//  Returns:
//      - NULL if an error occurs while creating a directory
//      - Pointer to a static array containing the file name
// -------------------------------------------------------------------------
const char* GetRCFileName(FileTypes type)
{
   static std::string rcFiles[N_FILE_TYPES];
   static bool namesDetermined = false;

   if (!namesDetermined)
   {
      std::string nedit_home = GetEnv("NEDIT_HOME");
      if (nedit_home.empty())
      {  //  No NEDIT_HOME
         // Let's try if ~/.nedit is a regular file or not.
         std::string  legacyFile = buildFilePath(GetHomeDir(), hiddenFileNames[NEDIT_RC]);
         if (isRegFile(legacyFile))
         {
            // This is a legacy setup with rc files in $HOME
            for (int i = 0; i < N_FILE_TYPES; i++)
            {
               rcFiles[i] = buildFilePath(GetHomeDir(), hiddenFileNames[i]);
            }
         }
         else
         {
            // ${HOME}/.nedit does not exist as a regular file.
            // FIXME: Devices, sockets and fifos are ignored for now.
            std::string defaultNEditHome = buildFilePath(GetHomeDir(), DEFAULT_NEDIT_HOME);
            if (!isDir(defaultNEditHome))
            {
               /* Create DEFAULT_NEDIT_HOME */
#ifdef WIN32
               if (mkdir(defaultNEditHome.c_str()) != 0)
#else
               if (mkdir(defaultNEditHome.c_str(), 0777) != 0)
#endif
               {
                  perror("nedit: Error while creating rc file directory"
                         " $HOME/" DEFAULT_NEDIT_HOME "\n"
                         " (Make sure all parent directories exist.)");
                  return NULL;
               }
            }

            /* All set for DEFAULT_NEDIT_HOME, let's copy the names */
            for (int i = 0; i < N_FILE_TYPES; i++)
            {
               rcFiles[i] = buildFilePath(defaultNEditHome.c_str(), plainFileNames[i]);
            }
         }
      }
      else
      {  // $NEDIT_HOME is set.
         // FIXME: Is this required? Does VMS know stat(), mkdir()?
         if (!isDir(nedit_home))
         {
            /* Create $NEDIT_HOME */
#ifdef WIN32
            if (mkdir(nedit_home.c_str()) != 0)
#else
            if (mkdir(nedit_home.c_str(), 0777) != 0)
#endif
            {
               perror("nedit: Error while creating rc file directory $NEDIT_HOME\n"
                      "nedit: (Make sure all parent directories exist.)");
               return NULL;
            }
         }

         // All set for NEDIT_HOME, let's copy the names
         for (int i = 0; i < N_FILE_TYPES; i++)
         {
            rcFiles[i] = buildFilePath(nedit_home.c_str(), plainFileNames[i]);
         }
      }

      namesDetermined = true;
   }

   return rcFiles[type].c_str();
}