<commit_before>/*
 * RunGrid.cpp
 *
 * Grid-level initialization, run, and output (if any)
 *    Note: the output modules are put here, so can be flexible for outputs
 *
*/

#include "RunGrid.h"
#include "../TEMUtilityFunctions.h"

RunGrid::RunGrid() {
  // grided data record ids in .nc files
  gridrecno  = MISSING_I;
  drainrecno = MISSING_I;
  soilrecno  = MISSING_I;
  gfirerecno = MISSING_I;
};

RunGrid::~RunGrid() {
};

void RunGrid::setModelData(ModelData * mdp) {
  md= mdp;
};

/** Setups up the grid ids from various input files.
*
*  Note: recno - the order (from ZERO) in the .nc file, ids - the real
*        ids in the *.nc files
*/
void RunGrid::setup_gridids_from_files(int recno) {

  this->grdids.push_back(MISSING_I);
  this->grddrgids.push_back(MISSING_I);
  this->grdsoilids.push_back(MISSING_I);
  this->grdfireids.push_back(MISSING_I);

  NcFile grid_file = temutil::open_ncfile(md->grdinputdir+"grid.nc");

  NcVar* grididV = temutil::get_ncvar(grid_file, "GRIDID");
  grididV->set_cur(recno);
  grididV->get(&this->grdids.back(), 1);

  NcVar* drgidV = temutil::get_ncvar(grid_file, "DRAINAGEID");
  drgidV->set_cur(recno);
  drgidV->get(&this->grddrgids.back(), 1);

  NcVar* soilidV = temutil::get_ncvar(grid_file, "SOILID");
  soilidV->set_cur(recno);
  soilidV->get(&this->grdsoilids.back(), 1);

  NcVar* gfireidV = temutil::get_ncvar(grid_file, "GFIREID");
  gfireidV->set_cur(recno);
  gfireidV->get(&this->grdfireids.back(), 1);
  
}

/** Reading all grid-level data ids.
*/
int RunGrid::allgridids() {
  int error = 0;

  /* NOTE: Should probbaly add some kind of error checking. Right now, the 
   * error stack-variable is doing nothing.
   */

  for (int rec_num = 0; rec_num < md->act_gridno; ++rec_num) {
    this->setup_gridids_from_files(rec_num);
  }

  for (int i = 0; i < md->act_drainno; ++i) {

    this->drainids.push_back(MISSING_I);

    NcFile f = temutil::open_ncfile(md->grdinputdir+"drainage.nc");

    NcVar* v = temutil::get_ncvar(f, "DRAINAGEID");
    v->set_cur(i);
    v->get(&this->drainids.back(), 1);

  }

  for (int i = 0; i < md->act_soilno; ++i) {

    this->soilids.push_back(MISSING_I);

    NcFile f = temutil::open_ncfile(md->grdinputdir+"soiltexture.nc");

    NcVar* v = temutil::get_ncvar(f, "SOILID");
    v->set_cur(i);
    v->get(&this->soilids.back(), 1);

  }

  for (int i = 0; i < md->act_gfireno; ++i) {

    this->gfireids.push_back(MISSING_I);

    NcFile f = temutil::open_ncfile(md->grdinputdir+"firestatistics.nc");

    NcVar* v = temutil::get_ncvar(f, "GFIREID");
    v->set_cur(i);
    v->get(&this->gfireids.back(), 1);
  }

  return error;
};

//reading data for ONE grid, using its record no (the order) in .nc files,
// which must be known before calling
int RunGrid::readData() {
  //reading the grided 'lat/lon' data
  if (gridrecno<0) {
    return -1;
  }

  this->grid.gd.read_location_from_file(md->grdinputdir + "grid.nc", gridrecno);

  //reading the grided 'drainage type' data
  if (drainrecno<0) {
    return -2;
  }

  grid.gd.drainage_type_from_file(md->grdinputdir + "drainage.nc", drainrecno);

  //reading the grided 'soil texture' data
  if (soilrecno<0) {
    return -3;
  }

  grid.gd.soil_texture_from_file(md->grdinputdir + "soiltexture.nc", soilrecno);

  //reading the grided 'fire' data
  if (gfirerecno<0) {
    return -4;
  }

  grid.gd.g_fire_from_file(md->grdinputdir + "fire.nc", gfirerecno);

  //
  grid.reinit();          //checking grid data
  return 0;
};<commit_msg>Fix typo in file name - wrong fire file.<commit_after>/*
 * RunGrid.cpp
 *
 * Grid-level initialization, run, and output (if any)
 *    Note: the output modules are put here, so can be flexible for outputs
 *
*/

#include "RunGrid.h"
#include "../TEMUtilityFunctions.h"

RunGrid::RunGrid() {
  // grided data record ids in .nc files
  gridrecno  = MISSING_I;
  drainrecno = MISSING_I;
  soilrecno  = MISSING_I;
  gfirerecno = MISSING_I;
};

RunGrid::~RunGrid() {
};

void RunGrid::setModelData(ModelData * mdp) {
  md= mdp;
};

/** Setups up the grid ids from various input files.
*
*  Note: recno - the order (from ZERO) in the .nc file, ids - the real
*        ids in the *.nc files
*/
void RunGrid::setup_gridids_from_files(int recno) {

  this->grdids.push_back(MISSING_I);
  this->grddrgids.push_back(MISSING_I);
  this->grdsoilids.push_back(MISSING_I);
  this->grdfireids.push_back(MISSING_I);

  NcFile grid_file = temutil::open_ncfile(md->grdinputdir+"grid.nc");

  NcVar* grididV = temutil::get_ncvar(grid_file, "GRIDID");
  grididV->set_cur(recno);
  grididV->get(&this->grdids.back(), 1);

  NcVar* drgidV = temutil::get_ncvar(grid_file, "DRAINAGEID");
  drgidV->set_cur(recno);
  drgidV->get(&this->grddrgids.back(), 1);

  NcVar* soilidV = temutil::get_ncvar(grid_file, "SOILID");
  soilidV->set_cur(recno);
  soilidV->get(&this->grdsoilids.back(), 1);

  NcVar* gfireidV = temutil::get_ncvar(grid_file, "GFIREID");
  gfireidV->set_cur(recno);
  gfireidV->get(&this->grdfireids.back(), 1);
  
}

/** Reading all grid-level data ids.
*/
int RunGrid::allgridids() {
  int error = 0;

  /* NOTE: Should probbaly add some kind of error checking. Right now, the 
   * error stack-variable is doing nothing.
   */

  for (int rec_num = 0; rec_num < md->act_gridno; ++rec_num) {
    this->setup_gridids_from_files(rec_num);
  }

  for (int i = 0; i < md->act_drainno; ++i) {

    this->drainids.push_back(MISSING_I);

    NcFile f = temutil::open_ncfile(md->grdinputdir+"drainage.nc");

    NcVar* v = temutil::get_ncvar(f, "DRAINAGEID");
    v->set_cur(i);
    v->get(&this->drainids.back(), 1);

  }

  for (int i = 0; i < md->act_soilno; ++i) {

    this->soilids.push_back(MISSING_I);

    NcFile f = temutil::open_ncfile(md->grdinputdir+"soiltexture.nc");

    NcVar* v = temutil::get_ncvar(f, "SOILID");
    v->set_cur(i);
    v->get(&this->soilids.back(), 1);

  }

  for (int i = 0; i < md->act_gfireno; ++i) {

    this->gfireids.push_back(MISSING_I);

    NcFile f = temutil::open_ncfile(md->grdinputdir+"firestatistics.nc");

    NcVar* v = temutil::get_ncvar(f, "GFIREID");
    v->set_cur(i);
    v->get(&this->gfireids.back(), 1);
  }

  return error;
};

//reading data for ONE grid, using its record no (the order) in .nc files,
// which must be known before calling
int RunGrid::readData() {
  //reading the grided 'lat/lon' data
  if (gridrecno<0) {
    return -1;
  }

  this->grid.gd.read_location_from_file(md->grdinputdir + "grid.nc", gridrecno);

  //reading the grided 'drainage type' data
  if (drainrecno<0) {
    return -2;
  }

  grid.gd.drainage_type_from_file(md->grdinputdir + "drainage.nc", drainrecno);

  //reading the grided 'soil texture' data
  if (soilrecno<0) {
    return -3;
  }

  grid.gd.soil_texture_from_file(md->grdinputdir + "soiltexture.nc", soilrecno);

  //reading the grided 'fire' data
  if (gfirerecno<0) {
    return -4;
  }

  grid.gd.g_fire_from_file(md->grdinputdir + "firestatistics.nc", gfirerecno);

  //
  grid.reinit();          //checking grid data
  return 0;
};
{'fraction_non_alphanumeric': 0.16256227758007116, 'fraction_numerical': 0.00597864768683274, 'mean_word_length': 3.693386773547094, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6507681', 'n_tokens_mistral': 2964, 'n_tokens_neox': 2835, 'n_words': 571}