Esempio n. 1
0
  /**
   * @brief Determines type of NAIF/ISIS kernel we're dealing with
   *
   * This method will open the file and look at the first 8 characters.  Valid
   * NAIF binary and text kernels typically have its type defined in the first 8
   * characters.  The expected format of these characters is "DAF/CK".  This
   * method retrieves this string, trims off formatting characters and spaces
   * and returns the string after the "/" character.  This value is returned as
   * the kernel type.
   *
   * It also checks for ISIS DEMs and a special case of ISIS IAKs, which does
   * not follow the NAIF convention.  ISIS IAKs don't typically contain the NAIF
   * format identifier but do contain the ".ti" file extention.
   *
   * UNKNOWN and DAF types are further checked by the filename.  This is a last
   * resort to properly tag kernel types that are ambiguous.  DAFs are common
   * for some SPKs.  UNKNOWNs are common for many kernels that do not follow the
   * NAIF standard first 8 character identifier model.
   *
   * @param kfile Name of potential NAIF kernel to determine type for
   *
   * @return QString Value of the identifier found.  If undetermined,
   *         "UNKNOWN" is returned.
   */
  QString Kernels::resolveType(const QString &kfile) const {
    FileName kernFile(kfile);
    QString kpath = kernFile.expanded();
    ifstream ifile(kpath.toAscii().data(), ios::in | ios::binary);
    QString ktype("UNKNOWN");
    if (ifile) {
      char ibuf[10];
      ifile.read(ibuf, 8);
      ibuf[8] = '\0';
      for (int i = 0 ; i < 8 ; i++)
        if (ibuf[i] == '\n') ibuf[i] = '\0';

      // See if the file is a known NAIF type.  Assume it has been
      // extracted from a NAIF compliant kernel
      QString istr = IString(ibuf).Trim(" \n\r\f\t\v\b").ToQt();
      if (istr.contains("/")) {
        ktype = istr.split("/").last();
      }

      // If type is not resolved, check file extensions and special ISIS types
      if ((ktype == "UNKNOWN") || (ktype == "DAF")) {
        ktype = resolveTypeByExt(kfile, ktype);
      }

    }
    return (ktype);
  }
Esempio n. 2
0
  virtual void dataEvent(const itype &data) final override {
    auto curKey = meta::slctTupleRef(data, Kslct{});
    auto curVal = meta::slctTupleRef(data, Vslct{});
    auto it = _index.find(curKey, _hash, _eq);

    if(TypeInfo::isRefRes) {
      if (it != std::end(_index)) {
        decltype(auto) x = meta::invokeReduce(_func, curKey, curVal, it->second);
        if (&x != &it->second) {
          it->second = x;
        }
      } else {
        it = _index.emplace_hint(it, ktype(curKey), _initVal);
        decltype(auto) x = meta::invokeReduce(_func, curKey, curVal, it->second);
        if (&x != &it->second) {
          it->second = x;
        }
      }
    } else {
      if (it != std::end(_index)) {
        it->second = meta::invokeReduce(_func, curKey, curVal, it->second);
      } else {
        it = _index.emplace_hint(
            it, ktype(curKey),
            meta::invokeReduce(_func, curKey, curVal, 
              (_initVal) ));
      }
    }

    if (_ordered) { 
      if (_first) {
        _first = false;
        _preIt = it;
      } else if (_preIt->first != curKey) {
        callKey<FO>();
        _index.erase(_preIt);
        _preIt = it;
      }
    }
  }
Esempio n. 3
0
  /**
   * @brief Check kernel type by file extension and special ISIS kernels
   *
   * This method is a fallback attempt to determine the type of an expected NAIF
   * kernel.  This method assumes the proper way (inspecting first 8 characters
   * of the kernel file) did not succeed in making this determination.
   *
   * There are some times that are expected to fail this test.  ISIS DEMs are
   * cube files and will not be determined using the NAIF 8 character approach.
   * As such, all files that end in .cub are assumed to be DEMs and are tagged
   * as such.
   *
   * There are also some special ISIS IK addendum files that exist in the ISIS
   * system.  These files are used to augment an instruments' IK kernel and
   * potentially override some of the original IK contents.  This file type is
   * determined by checking for a ".ti" extension and then further checking the
   * base filename for the substring "Addendum".  This is the only way to ensure
   * it is an ISIS IAK file.  It must pass both tests or it is simply tagged as
   * an IK (due to the .ti extension).
   *
   * The remainder of the tests are strictly testing the file extension. Here is
   * how the associations are made to the files based upon their file
   * extensions:
   *
   * .cub         = DEM - ISIS cubes are DEMs
   * .ti          = IK - unless "Addendum" is in basename, then it is an IAK
   * .tf          = FK - frames kernel
   * .tsc         = SCLK - spacecraft clock kernel
   * .tsl         = LSK - leap seconds kernel
   * .tpc         = PCK - planetary ephemeris kernel
   * .bc          = CK - C-kernel
   * .bsp         = SPK - spacecraft position kernel
   * .bes         = EK - event kernels
   *
   * If none of these file extensions or condition are found, then the value of
   * the parameter iktype is returned as the default type.
   *
   * @param kfile  File to determine type for
   * @param iktype Default type to be used in none are determined from this
   *               methiod
   *
   * @return QString Type of kernel found from file extensions
   */
  QString Kernels::resolveTypeByExt(const QString &kfile,
                                    const QString &iktype) const {

    QString ktype(iktype);  // Set default condition

    //  Deciminate file parts
    FileName kf(kfile);
    string ext = IString(kf.extension()).DownCase();

    //  Check extensions for types
    if (ext == "cub") {
      ktype = "DEM";
    }
    else if (ext == "ti") {
      //  Assume its an instrument kernel but check for ISIS IAK file
      ktype = "IK";
      string base = IString(kf.baseName()).DownCase();
      string::size_type idx = base.find("addendum");
      if (idx != string::npos) {   // This is an ISIS IK addendum (IAK)
        ktype = "IAK";
      }
    }
    else if (ext == "tsc") {
      ktype = "SCLK";
    }
    else if (ext == "tf") {
      ktype = "FK";
    }
    else if (ext == "tls") {
      ktype = "LSK";
    }
    else if (ext == "tpc") {
      ktype = "PCK";
    }
    else if (ext == "bc") {
      ktype = "CK";
    }
    else if (ext == "bsp") {
      ktype = "SPK";
    }
    else if (ext == "bes") {
      ktype = "EK";
    }

    return (ktype);
  }
Esempio n. 4
0
File: _nk20.c Progetto: kevinarpe/kx
static PyObject*
_arraytok(PyObject* self, PyObject* a)
{
	K kobj = 0;
	if (!PyArray_Check(a)) {
		return PyErr_Format(PyExc_TypeError, 
				    "argument is not a numeric array");	
	}
	PyArrayObject* arr = (PyArrayObject*)a;
	if (!PyArray_ISCONTIGUOUS(arr)) {
		return PyErr_Format(PyExc_TypeError, 
				    "cannot handle non-contiguous arrays");	
	}
	int n = PyArray_SIZE(arr);
	int t = ktype(arr->descr->type_num);
	if (t > 0) {
		kobj = gtn(-t,n);
		memcpy(kobj->k, arr->data, PyArray_NBYTES(arr));
	} else if (arr->descr->type_num == PyArray_OBJECT) {
		/* special handling for arrays of strings */
		char** strings = malloc(n*sizeof(char*));
		PyObject** objects = (PyObject**)arr->data;
		int i;
		for (i = 0; i < n; ++i) {
			char* str = PyString_AsString(objects[i]);
			if (str) {
				strings[i] = str;
			} else {
				free(strings);
				/* XXX should we raise our own exception here       *
				 * XXX or keep the one which came from "AsString"?  */
				return NULL;
			}
		}
		kobj = gtn(-4, n);
		for (i = 0; i < n; ++i) {
			KS(kobj)[i] = sp(strings[i]);
		}
	}
	return PyK_mk_K(kobj);
}