Beispiel #1
0
void WMAPSource::addToMetadata( fitsfile *ffits, const int iNumCols, int &iStatus )
{
  QString str;
  char charTemplate[ FLEN_CARD ];
  char charName[ FLEN_CARD ];
  long lRepeat;
  long lWidth;
  int iTypeCode;
  int iColNumber;
  int iResult;
  int entry;
  int col;

  for( col=0; col<iNumCols; col++ )
  {
    iResult = fits_get_coltype( ffits, col+1, &iTypeCode, &lRepeat, &lWidth, &iStatus );
    if( iResult == 0 )
    {
      sprintf( charTemplate, "%d", col+1 );
      iResult = fits_get_colname( ffits, CASEINSEN, charTemplate, charName, &iColNumber, &iStatus );
      if( iResult == 0 )
      {
        if( lRepeat == 3 )
        {
          QString strValue;
          double dNan = strtod( "nan", NULL );
          double value;
          int iAnyNull;

          for( entry=0; entry<lRepeat; entry++ )
          {
            iResult = fits_read_col( ffits, TDOUBLE, iColNumber, 1, entry+1, 1, &dNan, &value, &iAnyNull, &iStatus );
            if( iResult == 0 )
            {
              KstString *metaString;
              QString keyname = QString("%1_%2").arg(charName).arg(QChar('X'+entry));
              KstObjectTag newTag( keyname, tag( ) );

              strValue = QString("%1").arg(value);
              metaString = new KstString( newTag, this, strValue );
              _metaData.insert( keyname, metaString );
            }
          }
        }
      }
    }
  }
}
Beispiel #2
0
void PLANCKIDEFSource::addToFieldList( fitsfile *ffits, const int iNumCols, int &iStatus )
{
  QString str;
  char charTemplate[ FLEN_CARD ];
  char charName[ FLEN_CARD ];
  long lRepeat;
  long lWidth;
  int iHDUNumber;
  int iTypeCode;
  int iColNumber;
  int iResult;
  int table;
  int col;

  table = fits_get_hdu_num( ffits, &iHDUNumber );

  for( col=0; col<iNumCols; col++ )
  {
    iResult = fits_get_coltype( ffits, col+1, &iTypeCode, &lRepeat, &lWidth, &iStatus );
    if( iResult == 0 )
    {
      sprintf( charTemplate, "%d", col+1 );
      iResult = fits_get_colname( ffits, CASEINSEN, charTemplate, charName, &iColNumber, &iStatus );
      if( iResult == 0 )
      {
        if( lRepeat == 1 )
        {
          field *fld = new field;

          fld->table = table;
          fld->column = iColNumber;

          str = charName;
          if( _fields.find( str ) != 0L )
          {
            str += QString("_%1").arg( iHDUNumber );
          }
          _fields.insert( str, fld );
          _fieldList.append( str );
        }
      }
    }
  }
}
Kst::Object::UpdateType LFIIOSource::update() {

  Kst::Object::UpdateType updateType = Kst::Object::NO_CHANGE;
  QString               strTemplate;
  QString               strName;
  fitsfile*             ffits;
  char                  charTemplate[FLEN_CARD];
  char                  charName[FLEN_CARD];
  long                  lNumFrames;
  long                  lMaxRepeat = 1;
  long                  lRepeat;
  long                  lWidth;
  int                   iColNumber;
  int                   iNumCols;
  int                   iStatus = 0;
  int                   iResult = 0;
  int                   iTypeCode;
  int                   i;
  int                   newNF = 0;

  _valid  = false;

  if(!_filename.isNull() && !_filename.isEmpty()) {
    iResult = fits_open_table( &ffits, _filename.ascii(), READONLY, &iStatus );
    if(iResult == 0) {
      // determine size of data...
      iResult = fits_get_num_cols( ffits, &iNumCols, &iStatus );
      if(iResult == 0) {
        iResult = fits_get_num_rows( ffits, &lNumFrames, &iStatus );
        if(iResult == 0) {
          _fieldList.clear();
          _fieldList.append("INDEX");

          _valid = true;
          _bHasTime = false;

          // need to multiply lNumFrames by the maximum value of the vector repeat value...
          for(i = 0; i<iNumCols; i++) {
            iStatus = 0;

            sprintf(charTemplate, "%d", i+1);
            iResult = fits_get_colname( ffits, CASEINSEN, charTemplate, charName, &iColNumber, &iStatus );
            if(iResult == 0) {
              int iOffset = i;
              strName = charName;

              // ensure that we don't add duplicates to the _fieldList...
              while(_fieldList.findIndex(strName) != -1) {
                strName = QString("%1[%2]").arg(charName).arg(iOffset);
                iOffset++;
              }
            } else {
              strName.setNum(i);
            }

            _fieldList.append(strName);

            iStatus = 0;
            iResult = fits_get_coltype( ffits, i+1, &iTypeCode, &lRepeat, &lWidth, &iStatus );
            if(iResult == 0) {
              if(lRepeat > lMaxRepeat) {
                lMaxRepeat = lRepeat;
              }
            }
          }

          // check if we have a time field defined by the header keys TIMEZERO and DELTA_T.
          //  If so then we create a new field called $TIME_FIELD, unless such a field already
          //  exists, in which case we do nothing...
          char charTimeZero[] = "TIMEZERO";

          iStatus = 0;
          iResult = fits_read_key( ffits, TDOUBLE, charTimeZero, &_dTimeZero, 0L, &iStatus );
          if(iResult == 0) {
            char charTimeDelta[] = "DELTA_T";

            iResult = fits_read_key( ffits, TDOUBLE, charTimeDelta, &_dTimeDelta, 0L, &iStatus );
            if(iResult == 0) {
              if(_fieldList.find(QString(TIME_FIELD)) == _fieldList.end()) {
                _bHasTime = true;
                _fieldList.append(TIME_FIELD);
              }
            }
          }

          if(lNumFrames * lMaxRepeat != _numFrames) {
            _numCols   = iNumCols;
            newNF = lNumFrames * lMaxRepeat;
            updateType = Kst::Object::UPDATE;
          }
        }
      }
      iStatus = 0;
      fits_close_file( ffits, &iStatus );
    }
  }

  bool isnew = newNF != _numFrames;

  _numFrames = newNF;

  return (isnew ? Kst::Object::UPDATE : Kst::Object::NO_CHANGE);
}
Beispiel #4
0
void WMAPSource::addToFieldList( fitsfile *ffits, const int iNumCols, const long lNumRows, const long lNumBaseRows, int &iStatus )
{
  QString str;
  char charTemplate[ FLEN_CARD ];
  char charName[ FLEN_CARD ];
  long lRepeat;
  long lWidth;
  int iHDUNumber;
  int iTypeCode;
  int iColNumber;
  int iResult;
  int table;
  int entry;
  int col;

  table = fits_get_hdu_num( ffits, &iHDUNumber );

  for( col=0; col<iNumCols; col++ )
  {
    iResult = fits_get_coltype( ffits, col+1, &iTypeCode, &lRepeat, &lWidth, &iStatus );
    if( iResult == 0 )
    {
      sprintf( charTemplate, "%d", col+1 );
      iResult = fits_get_colname( ffits, CASEINSEN, charTemplate, charName, &iColNumber, &iStatus );
      if( iResult == 0 )
      {
        if( lRepeat == 1 )
        {
          field *fld = new field;

          fld->table = table;
          fld->column = iColNumber;
          fld->entry = 1;
          fld->entries = lRepeat;
          fld->numSamplesPerFrame = lNumRows / lNumBaseRows;
          fld->numFrames = lNumBaseRows;

          str = charName;
          if( _fields.find( str ) != 0L )
          {
            str += QString("_%1").arg( iHDUNumber );
          }
          _fields.insert( str, fld );
          _fieldList.append( str );
        }
        else if( lRepeat == 3 )
        {
          for( entry=0; entry<lRepeat; entry++ )
          {
            field *fld = new field;

            fld->table = table;
            fld->column = iColNumber;
            fld->entry = entry+1;
            fld->entries = lRepeat;
            fld->numSamplesPerFrame = lNumRows / lNumBaseRows;
            fld->numFrames = lNumBaseRows;

            str = QString("%1_%2").arg(charName).arg(QChar('X'+entry));
            _fields.insert( str, fld );
            _fieldList.append( str );
          }
        }
        else if( strcmp( charName, "QUATERN" ) == 0 )
        {
          for( entry=0; entry<4; entry++ )
          {
            field *fld = new field;

            fld->table = table;
            fld->column = iColNumber;
            fld->entry = entry+1;
            fld->entries = 4;
            fld->numSamplesPerFrame = ( lRepeat / 4 ) - 3;
            fld->numFrames = lNumBaseRows;

            str = QString("%1_%2").arg(charName).arg(QChar('a'+entry));
            _fields.insert( str, fld );
            _fieldList.append( str );
          }
        }
        else
        {
          for( entry=0; entry<lRepeat; entry++ )
          {
            field *fld = new field;

            fld->table = table;
            fld->column = iColNumber;
            fld->entry = entry+1;
            fld->entries = lRepeat;
            fld->numSamplesPerFrame = lNumRows / lNumBaseRows;
            fld->numFrames = lNumBaseRows;

            str = QString("%1_%2").arg(charName).arg(entry);
            _fields.insert( str, fld );
            _fieldList.append( str );
          }
        }
      }
    }
  }
}
Beispiel #5
0
KstObject::UpdateType LFIIOSource::update( int u ) 
{
  Q_UNUSED( u )

  KstObject::UpdateType updateType =  KstObject::NO_CHANGE;
  QString               strTemplate;
  QString               strName;
  fitsfile*             ffits;
  char                  charTemplate[ FLEN_CARD ];
  char                  charName[ FLEN_CARD ];
  long                  lNumFrames;
  long                  lMaxRepeat = 1;
  long                  lRepeat;
  long                  lWidth;
  int                   iColNumber;
  int                   iNumCols;
  int                   iStatus = 0;
  int                   iResult = 0;
  int                   iTypeCode;
  int                   i;

  _valid  = false;

  if( !_filename.isNull( ) && !_filename.isEmpty( ) )
  {
    iResult = fits_open_table( &ffits, _filename.ascii( ), READONLY, &iStatus );
    if( iResult == 0 )
    {
      //
      // determine size of data...
      //
      iResult = fits_get_num_cols( ffits, &iNumCols, &iStatus );
      if( iResult == 0 )
      {
        iResult = fits_get_num_rows( ffits, &lNumFrames, &iStatus );
        if( iResult == 0 )
        {
          _strListColNames.clear( );

          _valid = true;

          //
	        // need to multiply lNumFrames by the maximum value of the vector repeat value...
	        //
          for( i=0; i<iNumCols; i++ )
          {
            iStatus = 0;
            
            sprintf( charTemplate, "%d", i+1 );
            iResult = fits_get_colname( ffits, CASEINSEN, charTemplate, charName, &iColNumber, &iStatus );
            if( iResult == 0 )
            { 
              strName = charName;
              _strListColNames.append( strName );
            }
            else
            {
              strName.setNum( i );
              _strListColNames.append( strName );
            }
              
            iStatus = 0;
            iResult = fits_get_coltype( ffits, i+1, &iTypeCode, &lRepeat, &lWidth, &iStatus );
            if( iResult == 0 )
            {
              if( lRepeat > lMaxRepeat )
              {
                lMaxRepeat = lRepeat;
              }
            }
          }

          if( lNumFrames * lMaxRepeat != _numFrames )
	        {
            _numCols   = iNumCols;
            _numFrames = lNumFrames * lMaxRepeat;
            updateType = KstObject::UPDATE;
          }
        }
      }
      iStatus = 0;
      fits_close_file( ffits, &iStatus );   
    }
  }
  
  return updateType;
}