Unverified Commit 9b0e649f authored by Christine Kim's avatar Christine Kim Committed by GitHub
Browse files

Write comment & replaced std::optional (#33)

parent b9c95a9e
Loading
Loading
Loading
Loading
+22 −20
Original line number Original line Diff line number Diff line
@@ -35,7 +35,7 @@ namespace SpiceQL {
       * @param centerOfMotion Naif body code of an object which is the center of motion for
       * @param centerOfMotion Naif body code of an object which is the center of motion for
       *                      bodyCode
       *                      bodyCode
       * @param referenceFrame Naif name of the reference system relative to which the state is
       * @param referenceFrame Naif name of the reference system relative to which the state is
       * @param id SPK segment identifier (max size 40)
       * @param segmentId SPK segment identifier (max size 40)
       * @param degree Degree of the Hermite polynomials used to interpolate the states
       * @param degree Degree of the Hermite polynomials used to interpolate the states
       * @param stateVelocities Time ordered vector of state velocities dX, dY, dZ
       * @param stateVelocities Time ordered vector of state velocities dX, dY, dZ
       * @param segmentComment The comment string for the new segment
       * @param segmentComment The comment string for the new segment
@@ -45,20 +45,20 @@ namespace SpiceQL {
                 int bodyCode,
                 int bodyCode,
                 int centerOfMotion,
                 int centerOfMotion,
                 std::string referenceFrame,
                 std::string referenceFrame,
                 std::string id, int degree,
                 std::string segmentId, int degree,
                 std::optional<std::vector<std::vector<double>>> stateVelocities,
                 std::vector<std::vector<double>> stateVelocities = {},
                 std::optional<std::string> segmentComment);
                 std::string segmentComment = "");


      //! @cond Doxygen_Suppress
      //! @cond Doxygen_Suppress
      std::vector<double> stateTimes;
      std::vector<double> stateTimes;
      int bodyCode;
      int bodyCode;
      int centerOfMotion;
      int centerOfMotion;
      std::string referenceFrame;
      std::string referenceFrame;
      std::string id;
      std::string segmentId;
      int polyDegree;
      int polyDegree;
      std::vector<std::vector<double>> statePositions;
      std::vector<std::vector<double>> statePositions;
      std::optional<std::vector<std::vector<double>>> stateVelocities;
      std::vector<std::vector<double>> stateVelocities;
      std::optional<std::string> comment;
      std::string comment;
      //! @endcond
      //! @endcond
  };
  };


@@ -82,23 +82,23 @@ namespace SpiceQL {
         * @param times times for the CK segment in ascending order
         * @param times times for the CK segment in ascending order
         * @param bodyCode Naif body code of an object whose state is described by the segments
         * @param bodyCode Naif body code of an object whose state is described by the segments
         * @param referenceFrame Naif name of the reference system relative to which the state is
         * @param referenceFrame Naif name of the reference system relative to which the state is
         * @param id SPK segment identifier (max size 40)
         * @param segmentId SPK segment identifier (max size 40)
         * @param anglularVelocities Time ordered vector of state velocities dX, dY, dZ
         * @param angularVelocities Time ordered vector of state velocities dX, dY, dZ
         * @param comment The comment string for the new segment
         * @param comment The comment string for the new segment
         */
         */
        CkSegment(std::vector<std::vector<double>> quats, std::vector<double> times,  int bodyCode,
        CkSegment(std::vector<std::vector<double>> quats, std::vector<double> times,  int bodyCode,
                  std::string referenceFrame, std::string id,
                  std::string referenceFrame, std::string segmentId,
                  std::optional<std::vector<std::vector<double>>> anglularVelocities = std::nullopt,
                  std::vector<std::vector<double>> angularVelocities = {},
                  std::optional<std::string> comment = std::nullopt);
                  std::string comment = "");


        //! @cond Doxygen_Suppress
        //! @cond Doxygen_Suppress
        std::vector<double> times;
        std::vector<double> times;
        std::vector<std::vector<double>> quats;
        std::vector<std::vector<double>> quats;
        int bodyCode;
        int bodyCode;
        std::string referenceFrame;
        std::string referenceFrame;
        std::string id;
        std::string segmentId;
        std::optional<std::vector<std::vector<double>>> angularVelocities = std::nullopt;
        std::vector<std::vector<double>> angularVelocities;
        std::optional<std::string> comment = std::nullopt;
        std::string comment;
        //! @endcond
        //! @endcond
    };
    };


@@ -146,8 +146,8 @@ namespace SpiceQL {
                  std::string referenceFrame,
                  std::string referenceFrame,
                  std::string segmentId,
                  std::string segmentId,
                  int polyDegree,
                  int polyDegree,
                  std::optional<std::vector<std::vector<double>>> stateVelocities = std::nullopt,
                  std::vector<std::vector<double>> stateVelocities = {},
                  std::optional<std::string> segmentComment = std::nullopt);
                  std::string segmentComment = "");




    /**
    /**
@@ -174,8 +174,8 @@ namespace SpiceQL {
                 std::string segmentId,
                 std::string segmentId,
                 std::string sclk,
                 std::string sclk,
                 std::string lsk,
                 std::string lsk,
                 std::optional<std::vector<std::vector<double>>> angularVelocity = std::nullopt,
                 std::vector<std::vector<double>> angularVelocity = {},
                 std::optional<std::string> comment= std::nullopt);
                 std::string comment = "");




    /**
    /**
@@ -193,6 +193,8 @@ namespace SpiceQL {
               std::string lsk,
               std::string lsk,
               std::vector<CkSegment> segments);
               std::vector<CkSegment> segments);


  void writeComment(std::string fileName,
                    std::string comment);


  /**
  /**
   * @brief Write json key value pairs into a NAIF text kernel
   * @brief Write json key value pairs into a NAIF text kernel
@@ -202,6 +204,6 @@ namespace SpiceQL {
   * @param comment the comment to add to the top of the kernel
   * @param comment the comment to add to the top of the kernel
   * @param keywords json object containing key/value pairs to write to the text kernel
   * @param keywords json object containing key/value pairs to write to the text kernel
   */
   */
  void writeTextKernel(std::string fileName, std::string type, nlohmann::json &keywords, std::optional<std::string> comment = std::nullopt);
  void writeTextKernel(std::string fileName, std::string type, nlohmann::json &keywords, std::string comment = "");


  }
  }
+66 −22
Original line number Original line Diff line number Diff line
@@ -20,15 +20,15 @@ namespace SpiceQL {
                          int bodyCode,
                          int bodyCode,
                          int centerOfMotion,
                          int centerOfMotion,
                          string referenceFrame,
                          string referenceFrame,
                          string id, int degree,
                          string segmentId, int degree,
                          optional<vector<vector<double>>> stateVelocities,
                          vector<vector<double>> stateVelocities,
                          optional<string> comment) {
                          string comment) {


    this->comment         = comment;
    this->comment         = comment;
    this->bodyCode        = bodyCode;
    this->bodyCode        = bodyCode;
    this->centerOfMotion  = centerOfMotion;
    this->centerOfMotion  = centerOfMotion;
    this->referenceFrame  = referenceFrame;
    this->referenceFrame  = referenceFrame;
    this->id              = id;
    this->segmentId       = segmentId;
    this->polyDegree      = degree;
    this->polyDegree      = degree;
    this->statePositions  = statePositions;
    this->statePositions  = statePositions;
    this->stateVelocities = stateVelocities;
    this->stateVelocities = stateVelocities;
@@ -61,14 +61,15 @@ namespace SpiceQL {
                       int bodyCode,
                       int bodyCode,
                       string referenceFrame,
                       string referenceFrame,
                       string segmentId,
                       string segmentId,
                       optional<vector<vector<double>>> anglularVelocities,
                       vector<vector<double>> angularVelocities,
                       optional<string> comment) {
                       string comment) {


    this->comment            = comment;
    this->quats              = quats;
    this->times              = times;
    this->bodyCode           = bodyCode;
    this->bodyCode           = bodyCode;
    this->referenceFrame     = referenceFrame;
    this->referenceFrame     = referenceFrame;
    this->id                 = segmentId;
    this->segmentId                 = segmentId;
    this->angularVelocities = anglularVelocities;
    this->angularVelocities  = angularVelocities;
    this->comment            = comment;
    this->comment            = comment;
  }
  }


@@ -81,8 +82,8 @@ namespace SpiceQL {
               string segmentId,
               string segmentId,
               string sclk,
               string sclk,
               string lsk,
               string lsk,
               optional<vector<vector<double>>> angularVelocities,
               vector<vector<double>> angularVelocities,
               optional<string> comment) {
               string comment) {


    SpiceInt handle;
    SpiceInt handle;
    
    
@@ -98,24 +99,32 @@ namespace SpiceQL {
      et = sclkdp;
      et = sclkdp;
    }
    }
    checkNaifErrors();
    checkNaifErrors();
    ckopn_c(path.c_str(), "CK", comment.value_or("CK Kernel").size(), &handle);

    if(comment.empty()) {
      comment = "CK Kernel";
    }

    ckopn_c(path.c_str(), "CK", comment.size(), &handle);
    checkNaifErrors();
    checkNaifErrors();

    ckw03_c (handle,
    ckw03_c (handle,
             times.at(0),
             times.at(0),
             times.at(times.size()-1),
             times.at(times.size()-1),
             bodyCode,
             bodyCode,
             referenceFrame.c_str(),
             referenceFrame.c_str(),
             (bool)angularVelocities,
             !angularVelocities.empty(),
             segmentId.c_str(),
             segmentId.c_str(),
             times.size(),
             times.size(),
             times.data(),
             times.data(),
             quats.data(),
             quats.data(),
             (angularVelocities) ? angularVelocities->data() : nullptr,
             (!angularVelocities.empty()) ? angularVelocities.data() : nullptr,
             times.size(),
             times.size(),
             times.data());
             times.data());
    checkNaifErrors();
    checkNaifErrors();
    ckcls_c(handle);
    ckcls_c(handle);
    checkNaifErrors();
    checkNaifErrors();

    writeComment(path, comment);
  }
  }




@@ -127,12 +136,12 @@ namespace SpiceQL {
                 string referenceFrame,
                 string referenceFrame,
                 string segmentId,
                 string segmentId,
                 int polyDegree,
                 int polyDegree,
                 optional<vector<vector<double>>> stateVelocities,
                 vector<vector<double>> stateVelocities,
                 optional<string> segmentComment) {
                 string segmentComment) {


    vector<vector<double>> states;
    vector<vector<double>> states;


    if (!stateVelocities) {
    if (stateVelocities.empty()) {
      // init a 0 velocity array
      // init a 0 velocity array
      vector<vector<double>> velocities;
      vector<vector<double>> velocities;
      for (int i = 0; i < statePositions.size(); i++) {
      for (int i = 0; i < statePositions.size(); i++) {
@@ -141,7 +150,7 @@ namespace SpiceQL {
      stateVelocities = velocities;
      stateVelocities = velocities;
    }
    }


    states = concatStates(statePositions, *stateVelocities);
    states = concatStates(statePositions, stateVelocities);


    SpiceInt handle;
    SpiceInt handle;
    checkNaifErrors();
    checkNaifErrors();
@@ -163,6 +172,9 @@ namespace SpiceQL {
    spkcls_c(handle);
    spkcls_c(handle);
    checkNaifErrors();
    checkNaifErrors();


    // Write comment to header
    writeComment(fileName, segmentComment);

    return;
    return;
  }
  }


@@ -183,7 +195,7 @@ namespace SpiceQL {
             segments[0].bodyCode,
             segments[0].bodyCode,
             segments[0].centerOfMotion,
             segments[0].centerOfMotion,
             segments[0].referenceFrame,
             segments[0].referenceFrame,
             segments[0].id,
             segments[0].segmentId,
             segments[0].polyDegree,
             segments[0].polyDegree,
             segments[0].stateVelocities,
             segments[0].stateVelocities,
             segments[0].comment);
             segments[0].comment);
@@ -206,7 +218,7 @@ namespace SpiceQL {
            segments[0].times,
            segments[0].times,
            segments[0].bodyCode,
            segments[0].bodyCode,
            segments[0].referenceFrame,
            segments[0].referenceFrame,
            segments[0].id,
            segments[0].segmentId,
            sclk,
            sclk,
            lsk,
            lsk,
            segments[0].angularVelocities,
            segments[0].angularVelocities,
@@ -214,8 +226,40 @@ namespace SpiceQL {


  }
  }


  void writeComment(string fileName, string comment) {
    SpiceInt handle;
    dafopw_c(fileName.c_str(), &handle);
    checkNaifErrors();

    // Trap errors so they are not fatal if the comment section fills up.
    // Calling environments can decide how to handle it.

    string commOut;
    checkNaifErrors();
    for ( int i = 0 ; i < comment.size() ; i++ ) {
        if ( comment[i] == '\n' ) {
          while ( commOut.size() < 2 ) { commOut.append(" "); }
          dafac_c(handle, 1, commOut.size(), commOut.data());
          checkNaifErrors();
          commOut.clear();
        }
        else {
          commOut.push_back(comment[i]);
        }
    }

    // See if there is residual to write
    if ( commOut.size() > 0 ) {
      while ( commOut.size() < 2 ) { commOut.append(" "); }
      dafac_c(handle, 1, commOut.size(), commOut.data());
      checkNaifErrors();
    }

    // Close file handle
    dafcls_c(handle);
  }


  void writeTextKernel(string fileName, string type, json &keywords, optional<string> comment) {
  void writeTextKernel(string fileName, string type, json &keywords, string comment) {


    /**
    /**
     * @brief Return an adjusted string such that it multi-lined if longer than some max length.
     * @brief Return an adjusted string such that it multi-lined if longer than some max length.
@@ -286,7 +330,7 @@ namespace SpiceQL {


    textKernel << "KPL/" + toUpper(type) << endl << endl;
    textKernel << "KPL/" + toUpper(type) << endl << endl;
    textKernel << "\\begintext" << endl << endl;
    textKernel << "\\begintext" << endl << endl;
    textKernel << comment.value_or("") << endl << endl;
    textKernel << comment << endl << endl;
    textKernel << "\\begindata" << endl << endl;
    textKernel << "\\begindata" << endl << endl;


    for(auto it = keywords.begin(); it != keywords.end(); it++) {
    for(auto it = keywords.begin(); it != keywords.end(); it++) {