Ejemplo n.º 1
0
  void DatabaseIO::create_path(const std::string &filename) const
  {
    bool               error_found = false;
    std::ostringstream errmsg;

    if (myProcessor == 0) {
      Ioss::FileInfo file = Ioss::FileInfo(filename);
      std::string    path = file.pathname();

      const int mode = 0777; // Users umask will be applied to this.

      auto iter = path.begin();
      while (iter != path.end() && !error_found) {
        iter                  = std::find(iter, path.end(), '/');
        std::string path_root = std::string(path.begin(), iter);

        if (iter != path.end()) {
          ++iter; // Skip past the '/'
        }

        if (path_root.empty()) { // Path started with '/'
          continue;
        }

        struct stat st;
        if (stat(path_root.c_str(), &st) != 0) {
          if (mkdir(path_root.c_str(), mode) != 0 && errno != EEXIST) {
            errmsg << "ERROR: Cannot create directory '" << path_root
                   << "' : " << std::strerror(errno) << "\n";
            error_found = true;
          }
        }
        else if (!S_ISDIR(st.st_mode)) {
          errno = ENOTDIR;
          errmsg << "ERROR: Path '" << path_root << "' is not a directory.\n";
          error_found = true;
        }
      }
    }
    else {
      // Give the other processors something to say in case there is an error.
      errmsg << "ERROR: Could not create path. See processor 0 output for more "
                "details.\n";
    }

    // Sync all processors with error status...
    // All processors but 0 will have error_found=false
    // Processor 0 will have error_found = true or false depending on path
    // result.
    int is_error = error_found ? 1 : 0;
    error_found  = (util().global_minmax(is_error, Ioss::ParallelUtils::DO_MAX) == 1);

    if (error_found) {
      IOSS_ERROR(errmsg);
    }
  }
Ejemplo n.º 2
0
  void DatabaseIO::initialize(const Ioss::Region *region) const
  {
    if (!initialized_) {
      assert(layout_ == NULL);
      assert(legend_ == NULL);

      DatabaseIO *new_this = const_cast<DatabaseIO*>(this);

      if (properties.exists("FIELD_SEPARATOR")) {
	new_this->separator_ = properties.get("FIELD_SEPARATOR").get_string();
      }

      if (properties.exists("FILE_FORMAT")) {
	std::string format = properties.get("FILE_FORMAT").get_string();
	if (Ioss::Utils::case_strcmp(format, "spyhis") == 0)
	  new_this->fileFormat = SPYHIS;
      }

      bool append = open_create_behavior() == Ioss::DB_APPEND;

      if (util().parallel_rank() == 0) {

        new_this->logStream = open_stream(get_filename(),
            &(new_this->streamNeedsDelete),
            append);

        if (new_this->logStream == NULL) {
	  Ioss::FileInfo path = Ioss::FileInfo(get_filename());
	  Ioss::Utils::create_path(path.pathname());
	  new_this->logStream = open_stream(get_filename(),
              &(new_this->streamNeedsDelete),
              append);
        }
      } else {
	// All processors except processor 0
	new_this->logStream = NULL;
      }

      // Pull variables from the regions property data...
      if (properties.exists("TIME_STAMP_FORMAT")) {
	new_this->tsFormat = properties.get("TIME_STAMP_FORMAT").get_string();
      }

      if (properties.exists("SHOW_TIME_STAMP")) {
	bool show_time_stamp = properties.get("SHOW_TIME_STAMP").get_int() == 1;
	if (!show_time_stamp) {
	  new_this->tsFormat="";
	}
      }

      if (properties.exists("PRECISION")) {
	new_this->precision_ = properties.get("PRECISION").get_int();
      }

      if (properties.exists("FIELD_WIDTH")) {
	new_this->fieldWidth_ = properties.get("FIELD_WIDTH").get_int();
      } else {
	// +1.xxxxxxe+00 The x count is the precision the "+1.e+00" is the 7
	new_this->fieldWidth_ = precision_ + 7;
      }	

      if (properties.exists("SHOW_LABELS")) {
	new_this->showLabels = (properties.get("SHOW_LABELS").get_int() == 1);
      }

      if (properties.exists("SHOW_LEGEND")) {
	new_this->showLegend = (properties.get("SHOW_LEGEND").get_int() == 1 && !new_this->appendOutput);
      }

      if (properties.exists("SHOW_TIME_FIELD")) {
	new_this->addTimeField = (properties.get("SHOW_TIME_FIELD").get_int() == 1);
      }

      if (fileFormat == SPYHIS) {
	new_this->addTimeField = true;
	new_this->showLegend = true;
	new_this->showLabels = false;
	new_this->tsFormat = "";
      }
      
      if (showLegend) {
	new_this->legend_ = new Layout(false, precision_, separator_, fieldWidth_);
	if (!tsFormat.empty()) {
	  new_this->legend_->add_literal("+");
	  new_this->legend_->add_literal(time_stamp(tsFormat));
	  new_this->legend_->add_literal(" ");
	}

	if (addTimeField) {
	  new_this->legend_->add_legend("Time");
	}
      }
      new_this->initialized_ = true;
    }
  }