コード例 #1
0
ファイル: Table.cpp プロジェクト: corburn/ISIS
  /**
   * Adds a TableRecord to the Table
   *
   * @param rec The record to be added to the table
   */
  void Table::operator+=(Isis::TableRecord &rec) {
    if (RecordSize() == 0) {
      IString msg = "Unable to add records to Isis Table [" 
                    + p_blobName + "]. Bytes per record = [0 bytes].";
      throw IException(IException::Unknown, msg, _FILEINFO_);
    }

    // TODO: Determine why this error message causes mapmos to fail.  
    // The call comes from ProcessMapMosaic::StartProcess >>
    // ProcessMosaic::StartProcess when the InputImages table is
    // being filled  (see ProcessMosaic lines 704 - 732)
    // if (RecordSize() != rec.RecordSize()) {
    // IString msg = "Unable to add the given record with size = [" 
    //               + IString(rec.RecordSize()) + " bytes] to to Isis Table [" 
    //               + p_blobName + "] with record size = [" 
    //               + IString(RecordSize()) + " bytes]. Record sizes must match.";
    //   throw IException(IException::Unknown, msg, _FILEINFO_);
    // }
    // Temporary substitution?
    if (RecordSize() < rec.RecordSize()) {
      QString msg = "Unable to add the given record with size = [" 
                    + toString(rec.RecordSize()) + " bytes] to to Isis Table [" 
                    + p_blobName + "] with record size = [" 
                    + toString(RecordSize()) + " bytes]. Added record size can "
                    "not exceed table record size.";
      throw IException(IException::Unknown, msg, _FILEINFO_);
    }
    char *newbuf = new char[RecordSize()];
    rec.Pack(newbuf);
    p_recbufs.push_back(newbuf);
  }
コード例 #2
0
ファイル: Table.cpp プロジェクト: corburn/ISIS
  /**
   * Copy constructor for an Table object.  This constructor copies TableRecords
   * and the member variable values for record, records, assoc, and swap. 
   *
   * @param other The table to copy from
   */
  Table::Table(const Table &other) : Blob(other) {
    p_record = other.p_record;
    p_records = other.p_records;
    p_assoc = other.p_assoc;
    p_swap = other.p_swap;

    for (unsigned int i = 0; i < other.p_recbufs.size(); i++) {
      char *data = new char[RecordSize()];

      for (int j = 0; j < RecordSize(); j++) {
        data[j] = other.p_recbufs[i][j];
      }

      p_recbufs.push_back(data);
    }
  }
コード例 #3
0
ファイル: Table.cpp プロジェクト: corburn/ISIS
  /**
   * Sets the Table equal to the input Table object.  This method copies 
   * TableRecords and the member variable values for record, records, assoc, and 
   * swap. 
   *
   * @param other The table to copy from 
   *  
   * @return @b Table The copied table.
   */
  Table &Table::operator=(const Isis::Table &other) {
    *((Isis::Blob *)this) = *((Isis::Blob *)&other);
    p_record = other.p_record;
    p_records = other.p_records;
    p_assoc = other.p_assoc;
    p_swap = other.p_swap;

    for (unsigned int i = 0; i < other.p_recbufs.size(); i++) {
      char *data = new char[RecordSize()];

      for (int j = 0; j < RecordSize(); j++) {
        data[j] = other.p_recbufs[i][j];
      }

      p_recbufs.push_back(data);
    }

    return *this;
  }
コード例 #4
0
ファイル: Table.cpp プロジェクト: corburn/ISIS
  /**
   * Virtual function to Read the data
   *
   * @param stream InputStream to read data in from
   *
   * @throws Isis::IException::Io - Error reading or preparing to read a record
   */
  void Table::ReadData(std::istream &stream) {
    for (int rec = 0; rec < p_records; rec++) {
      streampos sbyte = (streampos)(p_startByte - 1) +
                        (streampos)(rec * RecordSize());
      stream.seekg(sbyte, std::ios::beg);
      if (!stream.good()) {
        QString msg = "Error preparing to read record [" + toString(rec + 1) +
                     "] from Table [" + p_blobName + "]";
        throw IException(IException::Io, msg, _FILEINFO_);
      }

      char *buf = new char[RecordSize()];
      stream.read(buf, RecordSize());
      if (!stream.good()) {
        QString msg = "Error reading record [" + toString(rec + 1) +
                      "] from Table [" + p_blobName + "]";
        throw IException(IException::Io, msg, _FILEINFO_);
      }

      if (p_swap) p_record.Swap(buf);
      p_recbufs.push_back(buf);
    }
  }
コード例 #5
0
ファイル: Table.cpp プロジェクト: corburn/ISIS
  //! Virtual Function to prepare labels for writing
  void Table::WriteInit() {
    p_blobPvl["Records"] = toString(Records());
    p_nbytes = Records() * RecordSize();

    if (Isis::IsLsb()) {
      p_blobPvl["ByteOrder"] = Isis::ByteOrderName(Isis::Lsb);
    }
    else {
      p_blobPvl["ByteOrder"] = Isis::ByteOrderName(Isis::Msb);
    }

    if (p_blobPvl.hasKeyword("Association")) {
      p_blobPvl.deleteKeyword("Association");
    }
    if (p_assoc == Samples) {
      p_blobPvl += Isis::PvlKeyword("Association", "Samples");
    }
    else if (p_assoc == Lines) {
      p_blobPvl += Isis::PvlKeyword("Association", "Lines");
    }
    else if (p_assoc == Bands) {
      p_blobPvl += Isis::PvlKeyword("Association", "Bands");
    }
  }
コード例 #6
0
ファイル: esig2fea.c プロジェクト: RobBullen/AudioMorphing
main(int   argc,
     char  **argv)
{
    extern int	    optind;	/* for use of getopt() */
    extern char	    *optarg;	/* for use of getopt() */
    int		    ch;		/* command-line option letter */

    static char	    *ProgName = "esig2fea";	/* name of this program */
    static char	    *Version = SCCS_VERSION;	/* program SCCS version */
    static char	    *Date = SCCS_DATE;		/* program SCCS date */

    char	    **field_names = NULL;
    int		    num_fields = 0;
    int		    alloc_fields = 0;

    int		    rflag = NO;	/* -r option specified? */
    char	    *rrange;	/* arguments of -r option */
    long	    start_rec;	/* starting record number */
    long	    end_rec;	/* ending record number */
    long	    num_recs;	/* number of records to read
				   (0 means all up to end of file) */
    long	    num_read;	/* number of records actually read */

    char	    *iname;	/* input file name */
    FILE	    *ifile;	/* input stream */
    FieldList	    list;	/* input field list */
    int		    inord;	/* input: field order or type order? */
    FieldSpec	    **ifields;	/* input fields in field or type order */

    char	    *subtype = NULL;		/* FEA subtype name */
    int		    subtype_code = NONE;	/* numeric subtype code */
    FieldSpec	    *fld;	/* spec of various special fields */

    char	    *oname;	/* output file name */
    FILE	    *ofile;	/* output stream */
    struct header   *ohd;	/* output file header */
    struct fea_data *orec;	/* output record */
    int		    outord = TYPE_ORDER;

    char	    *version;	/* version from input preamble */
    int		    arch;	/* architecture from input preamble */
    long	    pre_size;	/* preamble size */
    long	    hdr_size;	/* header size (bytes) from preamble */
    long	    rec_size;	/* record size from preamble */

    double	    rec_freq;
    double	    start_time_offset;
    double	    *data;
    long	    len, i;


    struct header   *source;	/* embedded source-file header */


    while ((ch = getopt(argc, argv, "f:r:x:FT:")) != EOF)
	switch (ch)
	{
	case 'f':
	    if (num_fields >= alloc_fields)
	    {
		size_t	size;

		alloc_fields = num_fields + 1 + num_fields/2;
		size = (alloc_fields + 1) * sizeof(char *);
		field_names = (char **)
		    ((field_names == NULL)
		     ? malloc(size)
		     : realloc(field_names, size));
	    }
	    field_names[num_fields++] = optarg;
	    field_names[num_fields] = NULL;
	    break;
	case 'r':
	    rflag = YES;
	    rrange = optarg;
	    break;
	case 'x':
	    debug_level = atoi(optarg);
	    break;
	case 'F':
	    outord = FIELD_ORDER;
	    break;
	case 'T':
	    subtype = optarg;
	    break;
	default:
	    SYNTAX;
	    break;
	}

    if (argc - optind > 2)
    {
	fprintf(stderr,
		"%s: too many file names specified.\n", ProgName);
	SYNTAX;
    }
    if (argc - optind < 2)
    {
	fprintf(stderr,
		"%s: too few file names specified.\n", ProgName);
	SYNTAX;
    }


    DebugMsgLevel = debug_level;
    DebugMsgFunc = DebugPrint;

    iname = argv[optind++];
    list = OpenIn(iname, &version,
		  &arch, &pre_size, &hdr_size, &rec_size, &ifile);
    REQUIRE(list != NULL, "read header failed");
    if (ifile == stdin)
	iname = "<stdin>";

    oname = argv[optind++];

    start_rec = 0;
    end_rec = LONG_MAX;
    num_recs = 0;	/* 0 means continue to end of file */

    if (rflag)
    {
	lrange_switch(rrange, &start_rec, &end_rec, 0);
	if (end_rec != LONG_MAX)
	    num_recs = end_rec - start_rec + 1;
    }

    REQUIRE(start_rec >= 0, "can't start before beginning of file");
    REQUIRE(end_rec >= start_rec, "empty range of records specified");

    if (debug_level)
	fprintf(stderr,
		"start_rec: %ld.  end_rec: %ld.  num_recs: %ld.\n",
		start_rec, end_rec, num_recs);

    REQUIRE(GetFieldOrdering(list, &inord),
	    "cant get field ordering of input");

    switch (inord)
    {
    case TYPE_ORDER:
	if (debug_level)
	    fprintf(stderr, "making type-ordered field array.\n");
	ifields = TypeOrder(list);
	break;
    case FIELD_ORDER:
	if (debug_level)
	    fprintf(stderr, "making field-ordered field array.\n");
	ifields = FieldOrder(list);
	break;
    default:
	REQUIRE(0, "input order neither TYPE_ORDER nor FIELD_ORDER");
	break;
    }

    ohd = FieldList_to_fea(list, &orec, field_names, FALSE);

    REQUIRE(ohd != NULL,
	    "failure converting input field list to header & record struct");

    if (subtype != NULL)
    {
	subtype_code = lin_search(fea_file_type, subtype);

	if (subtype_code == -1)
	    fprintf(stderr, "%s: unknown FEA file subtype \"%s\" ignored.\n",
		    ProgName, subtype);
	else
	    ohd->hd.fea->fea_type = subtype_code;
    }

    if (outord == FIELD_ORDER)
	ohd->hd.fea->field_order = YES;

    fld = FindField(list, "recordFreq");

    if (fld != NULL && fld->occurrence == GLOBAL && fld->data != NULL)
    {
	(void) type_convert(1L, (char *) fld->data, ElibTypeToEsps(fld->type),
			    (char *) &rec_freq, FDOUBLE, (void (*)()) NULL);

	*add_genhd_d("record_freq", NULL, 1, ohd) = rec_freq;
    }
    else
	rec_freq = 1.0;

    fld = FindField(list, "startTime");

    if (fld != NULL
	&& fld->occurrence == GLOBAL && fld->data != NULL && rec_freq != 0)
    {
	start_time_offset = start_rec / rec_freq;

	len = FieldLength(fld);
	data = (double *) type_convert(len, (char *) fld->data,
				       ElibTypeToEsps(fld->type),
				       (char *) NULL, FDOUBLE,
				       (void (*)()) NULL);

	if (start_time_offset != 0)
	{
	    for (i = 0; i < len; i++)
		data[i] += start_time_offset;
	}

	(void) add_genhd_d("start_time", data, len, ohd);
    }

    (void) strcpy(ohd->common.prog, ProgName);
    (void) strcpy(ohd->common.vers, Version);
    (void) strcpy(ohd->common.progdate, Date);

    source = FieldList_to_fea(list, NULL, NULL, TRUE);
    add_source_file(ohd, savestring(iname), source);

    add_comment(ohd, get_cmd_line(argc, argv));

    oname = eopen(ProgName,
		  oname, "w", NONE, NONE, NULL, &ofile);
    write_header(ohd, ofile);

    num_read = SkipRecs(ifile, start_rec,
			RecordSize(list, arch), ifields, arch);

    if (num_read != start_rec)
    {
	fprintf(stderr,
		"%s: couldn't reach starting record; only %ld skipped.\n",
		ProgName, num_read);
	exit(0);
    }

    for ( ;
	 num_read <= end_rec && ReadRecord(ifields, arch, ifile);
	 num_read++)
    {
	put_fea_rec(orec, ohd, ofile);
    }

    if (num_read <= end_rec && num_recs != 0)
	fprintf(stderr, "esig2fea: only %ld records read.\n",
		num_read - start_rec);

    exit(0);
    /*NOTREACHED*/
}
コード例 #7
0
ファイル: Table.cpp プロジェクト: corburn/ISIS
 /**
  * Virtual function to write the data
  *
  * @param os Outputstream to write the data to
  */
 void Table::WriteData(std::fstream &os) {
   for (int rec = 0; rec < Records(); rec++) {
     os.write(p_recbufs[rec], RecordSize());
   }
 }
コード例 #8
0
int asc2eph( const char* headerFile, int numAsciiFiles, const char* asciiFiles[])
{
    FILE* f = fopen( "JPLEPH", "w+");
    int i, retVal = 0;
    EphCtx ctx;
    long recordSize;
    double previousValues[2] = {0.0, 0.0};

    if (!f)
    {
        fprintf(stderr, "Error:unable to create binary ephemeris file\n");
        return 2;
    }

    retVal = ProcessHeader( f, &ctx, headerFile);
    if (retVal)
    {
        goto exit;
    }

    /* make sure files are processed in order */
    if (numAsciiFiles > 1)
    {
        qsort( asciiFiles, numAsciiFiles, sizeof(asciiFiles[0]), cmp);
    }

    recordSize = RecordSize(&ctx);
    /* go to data record 2  -- data will go there */
    if (0 != fseek(f, 2 * recordSize, SEEK_SET))
    {
        retVal = ERR_FILE_SEEK;
        goto exit;
    }

    for (i = 0; i < numAsciiFiles; ++i)
    {
        retVal = AppendAscii( f, &ctx, i, asciiFiles[i], previousValues);
        if (retVal)
        {
            goto exit;
        }
    }

    /* WRAP EVERYTHING by writing missing part of record 0: SS,  NCon,
     AU, EM_RATIO, DENUM */
    /* first JD: read from first data record, i.e. record 2 */
    if (0 != fseek(f, 2 * recordSize, SEEK_SET))
    {
        retVal = ERR_FILE_SEEK;
        goto exit;
    }
    if (1 != fread(previousValues, sizeof(double), 1, f))
    {
        retVal = ERR_FILE_READ;
        goto exit;
    }
    /* previousValues[0] = firstJD, previousValues[1] = lastJD */

    /* make sure minJD <= firstJD and lastJD <= maxJD
      firstJD <= lastJD is checked when processing the ascii files */
    if (previousValues[0] < ctx.ss[0] || previousValues[1] > ctx.ss[1])
    {
        retVal = ERR_INVALID_DATA_RANGE;
        goto exit;
    }
    ctx.ss[0] = previousValues[0];
    ctx.ss[1] = previousValues[1];


    retVal = WriteRecord0(f, &ctx, recordSize);

exit:

    fclose(f);
    return retVal;
}
コード例 #9
0
int ProcessHeader(FILE* out, EphCtx* ctx, const char* headerFileName)
{
    int i, tmp, retVal;

    FILE* f = fopen(headerFileName, "r");
    if (!f)
    {
        fprintf(stderr, "Error:unable to open header file: %s\n",
                headerFileName);
        return ERR_FILE_OPEN;

    }

    if ((retVal = ScanNextLine(f, 2, "KSIZE= %d NCOEFF= %d",
                               &ctx->ksize, &ctx->nCoeff)))
    {
        goto exit;
    }

    /*************** GROUP 1010 *****************/
    if ((retVal = GetSpecificGroup(f, 1010)))
    {
        goto exit;
    }

    /* goofy fortran i/o: fill 3 lines of 84 chars from the file */
    for (i = 0; i < 3; ++i)
    {
        long numChars;

        if ( !fgets(gLine, sizeof(gLine), f))
        {
            retVal = ERR_EOF;
            goto exit;
        }

        numChars = strlen( gLine);

        while (iscntrl(gLine[numChars-1]))
        {
            --numChars;
        }

        memset( gLine + numChars, 0x20, 84 - numChars);
        if (84 != fwrite( gLine, 1, 84, out))
        {
            retVal = ERR_FILE_WRITE;
            goto exit;
        }
    }

    /*************** GROUP 1030 *****************/
    if ((retVal = GetSpecificGroup(f, 1030)))
    {
        goto exit;
    }

    if ((retVal = ScanNextLine(f, 3, "%lf %lf %lf",
                               ctx->ss, ctx->ss+1, ctx->ss+2)))
    {
        goto exit;
    }

    /*************** GROUP 1040 *****************/
    if ((retVal = GetSpecificGroup(f, 1040)))
    {
        goto exit;
    }

    if ((retVal = ScanNextLine(f, 1, "%d", &ctx->nCon)))
    {
        goto exit;
    }

    /* read ctx->ncon names, names 6 characters long (padded with space)
     and preceded by 2 spaces  10 names per line of 80 chars*/
    if ((retVal = ProcessNames(out, f, ctx)))
    {
        goto exit;
    }

    /*************** GROUP 1041 *****************/
    if ((retVal = GetSpecificGroup(f, 1041)))
    {
        goto exit;
    }

    if ((retVal = ScanNextLine(f, 1, "%d", &tmp)))
    {
        goto exit;
    }

    if (tmp != ctx->nCon)
    {
        retVal = ERR_FORMAT;
        goto exit;
    }
    /* go to data record 1 and write the values */
    if (0 != fseek(out, RecordSize(ctx), SEEK_SET))
    {
        retVal = ERR_FILE_SEEK;
        goto exit;
    }

    if ((retVal = WriteRecord(out, f, ctx->nCon, NULL)))
    {
        goto exit;
    }

    /*************** GROUP 1050 *****************/
    if ((retVal = GetSpecificGroup(f, 1050)))
    {
        goto exit;
    }

    if ((retVal = ProcessGroup1050(out, f)))
    {
        goto exit;
    }


    retVal = 0;

exit:

    fclose(f);
    return retVal;

}