Example #1
0
complex float* load_zra(const char* name, unsigned int D, long dims[D])
{
	int fd;
	if (-1 == (fd = open(name, O_RDONLY)))
		io_error("Loading ra file %s", name);

	if (-1 == read_ra(fd, D, dims))
		io_error("Loading ra file %s", name);

//	long T = md_calc_size(D, dims) * sizeof(complex float);

	void* addr;
	struct stat st;

	if (-1 == fstat(fd, &st))
		io_error("Loading ra file %s", name);

	off_t header_size;

	if (-1 == (header_size = lseek(fd, 0, SEEK_CUR)))
		io_error("Loading ra file %s", name);

	// ra allows random stuff at the end
//	if (T + header_size >= st.st_size)
//		io_error("Loading ra file %s", name);

	assert(header_size < 4096);

	if (MAP_FAILED == (addr = mmap(NULL, st.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)))
		io_error("Loading ra file %s", name);

	if (-1 == close(fd))
		io_error("Loading ra file %s", name);

	return (complex float*)(addr + header_size);;
}
Example #2
0
bool CatalogDB::AddCatalogContents(const QString& fname) {
  QDir::setCurrent(QDir::homePath());  // for files with relative path
  QString filename = fname;
  // If the filename begins with "~", replace the "~" with the user's home
  // directory (otherwise, the file will not successfully open)
  if (filename.at(0) == '~')
      filename = QDir::homePath() + filename.mid(1, filename.length());

  QFile ccFile(filename);

  if (ccFile.open(QIODevice::ReadOnly)) {
      QStringList columns;  // list of data column descriptors in the header
      QString catalog_name;
      char delimiter;

      QTextStream stream(&ccFile);
      // TODO(spacetime) : Decide appropriate number of lines to be read
      QStringList lines;
      for (int times = 10; times >= 0 && !stream.atEnd(); --times)
        lines.append(stream.readLine());
      /*WAS
        * = stream.readAll().split('\n', QString::SkipEmptyParts);
        * Memory Hog!
        */

      if (lines.size() < 1 ||
          !ParseCatalogInfoToDB(lines, columns, catalog_name, delimiter)) {
          kWarning() << "Issue in catalog file header: " << filename;
          ccFile.close();
          return false;
      }
      ccFile.close();
      // The entry in the Catalog table is now ready!

      /*
        * Now 'Columns' should be a StringList of the Header contents
        * Hence, we 1) Convert the Columns to a KSParser compatible format
        *           2) Use KSParser to read stuff and store in DB
        */

      // Part 1) Conversion to KSParser compatible format
      QList< QPair<QString, KSParser::DataTypes> > sequence =
                                          buildParserSequence(columns);

      // Part 2) Read file and store into DB
      KSParser catalog_text_parser(filename, '#', sequence, delimiter);

      QHash<QString, QVariant> row_content;
      while (catalog_text_parser.HasNextRow()) {
        row_content = catalog_text_parser.ReadNextRow();

        CatalogEntryData catalog_entry;

        dms read_ra(row_content["RA"].toString(), false);
        dms read_dec(row_content["Dc"].toString(), true);
        kDebug()<<row_content["Nm"].toString();
        catalog_entry.catalog_name = catalog_name;
        catalog_entry.ID = row_content["ID"].toInt();
        catalog_entry.long_name = row_content["Nm"].toString();
        catalog_entry.ra = read_ra.Degrees();
        catalog_entry.dec = read_dec.Degrees();
        catalog_entry.type = row_content["Tp"].toInt();
        catalog_entry.magnitude = row_content["Mg"].toFloat();
        catalog_entry.position_angle = row_content["PA"].toFloat();
        catalog_entry.major_axis = row_content["Mj"].toFloat();
        catalog_entry.minor_axis = row_content["Mn"].toFloat();
        catalog_entry.flux = row_content["Flux"].toFloat();

        AddEntry(catalog_entry);
      }
  }
  return true;
}