[Kst] extragear/graphics/kst/src/datasources/planckIDEF

Andrew Walker arwalker at sumusltd.com
Thu Mar 8 20:43:44 CET 2007


SVN commit 640679 by arwalker:

revise for changes to the IDEF. Not yet part of build so will not impact release

 M  +104 -127  planckIDEF.cpp  
 M  +2 -0      planckIDEF.h  


--- trunk/extragear/graphics/kst/src/datasources/planckIDEF/planckIDEF.cpp #640678:640679
@@ -54,7 +54,6 @@
 
 void PLANCKIDEFSource::addToMetadata( fitsfile *ffits, int &iStatus )
 {
-  QString   str;
   int iResult;
   int keysexist;
   int morekeys;
@@ -62,22 +61,42 @@
   iResult = fits_get_hdrspace( ffits, &keysexist, &morekeys, &iStatus );
   if( iResult == 0 )
   {
-    QString strTable;
-    KstObjectTag tableTag( strTable, tag( ) );
+    QString strKey;
     char keyname[FLEN_KEYWORD];
     char value[FLEN_VALUE];
     char comment[FLEN_COMMENT];
     int keynum;
+    int hdu;
 
+    fits_get_hdu_num( ffits, &hdu );
+
     for( keynum=1; keynum<=keysexist; ++keynum )
     {
       iResult = fits_read_keyn( ffits, keynum, keyname, value, comment, &iStatus );
       if( iResult == 0 )
       {
+        strKey.sprintf("%02d_%03d %s", hdu, keynum, keyname);
+
         KstString *metaString;
-        KstObjectTag newTag( keyname, tag( ) );
+        KstObjectTag newTag( strKey, tag( ) );
+        QString str;
 
-        str.sprintf( "%s %s", value, comment );
+        if( strlen( comment ) > 0 )
+        {
+          if( strlen( value ) > 0 )
+          {
+            str.sprintf( "%s / %s", value, comment );
+          }
+          else
+          {
+            str.sprintf( "%s", comment );
+          }
+        }
+        else if( strlen( value ) > 0 )
+        {
+          str.sprintf( "%s", value );
+        }
+
         metaString = new KstString( newTag, this, str );
         _metaData.insert( keyname, metaString );
       }
@@ -93,6 +112,7 @@
   char charName[ FLEN_CARD ];
   long lRepeat;
   long lWidth;
+  long l;
   int iHDUNumber;
   int iTypeCode;
   int iColNumber;
@@ -108,8 +128,8 @@
     if( iResult == 0 )
     {
       sprintf( charTemplate, "%d", col+1 );
-      iResult = fits_get_colname( ffits, CASEINSEN, charTemplate, charName, &iColNumber, &iStatus );
-      if( iResult == 0 )
+
+      if( fits_get_colname( ffits, CASEINSEN, charTemplate, charName, &iColNumber, &iStatus ) == 0 )
       {
         if( lRepeat == 1 )
         {
@@ -117,15 +137,29 @@
 
           fld->table = table;
           fld->column = iColNumber;
+          fld->entry = 1;
+          fld->entries = 1;
 
-          str = charName;
-          if( _fields.find( str ) != 0L )
-          {
-            str += QString("_%1").arg( iHDUNumber );
-          }
+          str = QString( "%1_%2" ).arg( charName ).arg( iHDUNumber-1 );
           _fields.insert( str, fld );
           _fieldList.append( str );
         }
+        else
+        {
+          for( l=0; l<lRepeat; ++l )
+          {
+            field *fld = new field;
+
+            fld->table = table;
+            fld->column = iColNumber;
+            fld->entry = l+1;
+            fld->entries = lRepeat;
+
+            str = QString( "%1_%2_%3" ).arg( charName ).arg( iHDUNumber-1 ).arg( l );
+            _fields.insert( str, fld );
+            _fieldList.append( str );
+          }
+        }
       }
     }
   }
@@ -184,6 +218,8 @@
 
           fld->table = 0;
           fld->column = 0;
+          fld->entry = 0;
+          fld->entries = 0;
 
           _fields.insert( "INDEX", fld );
           _fieldList.append( "INDEX" );
@@ -191,7 +227,7 @@
           //
           // add the fields and metadata...
           //
-          for( i=0; i<iNumHeaderDataUnits-1; i++ )
+          for( i=0; i<iNumHeaderDataUnits; i++ )
           {
             if( iStatus == 0 )
             {
@@ -203,50 +239,12 @@
               if( i > 0 )
               {
                 //
-                // create the time entries if necessary...
-                //
-                if( _fields.find( "TIME_ABSOLUTE" ) == 0L &&
-                    _fields.find( "TIME_RELATIVE" ) == 0L )
-                {
-                  char comment[FLEN_COMMENT];
-                  int iStatusDelta = 0;
-                  int iStatusZero = 0;
-
-                  fits_read_key( ffits, TDOUBLE, "DELTA_T", &_dTimeDelta, comment, &iStatusDelta );
-                  fits_read_key( ffits, TDOUBLE, "TIMEZERO", &_dTimeZero, comment, &iStatusZero );
-
-                  if( iStatusDelta == 0 )
-                  {
-                    if( iStatusZero == 0 )
-                    {
-                      field *fld = new field;
-
-                      fld->table = 0;
-                      fld->column = 0;
-
-                      _fields.insert( "TIME_ABSOLUTE", fld );
-                      _fieldList.append( "TIME_ABSOLUTE" );
-                    }
-                    else
-                    {
-                      field *fld = new field;
-
-                      fld->table = 0;
-                      fld->column = 0;
-
-                      _fields.insert( "TIME_RELATIVE", fld );
-                      _fieldList.append( "TIME_RELATIVE" );
-                    }
-                  }
-                }
-
-                //
                 // create the field entries...
                 //
                 fits_get_hdu_type( ffits, &iHDUType, &iStatus );
                 if( iStatus == 0 )
                 {
-                  if( iHDUType == BINARY_TBL || iHDUType == ASCII_TBL )
+                  if( iHDUType == BINARY_TBL )
                   {
                     int iNumCols;
 
@@ -312,24 +310,6 @@
 
     iRead =  n;
   }
-  else if( fieldName == "TIME_ABSOLUTE" && _fields.find( fieldName ) != 0L )
-  {
-    for( i = 0; i < n; ++i )
-    {
-      v[i] = _dTimeZero + ( double( s + i ) * _dTimeDelta );
-    }
-
-    iRead =  n;
-  }
-  else if( fieldName == "TIME_RELATIVE" && _fields.find( fieldName ) != 0L )
-  {
-    for( i = 0; i < n; i++ )
-    {
-      v[i] = double( s + i ) * _dTimeDelta;
-    }
-
-    iRead =  n;
-  }
   else
   {
     field *fld = 0L;
@@ -354,13 +334,13 @@
 
               if( n < 0 )
               {
-                iResult = fits_read_col( ffits, TDOUBLE, fld->column, s+1, 1, 1, &dNan, v, &iAnyNull, &iStatus );
+                iResult = fits_read_col( ffits, TDOUBLE, fld->column, s+1, fld->entry, 1, &dNan, v, &iAnyNull, &iStatus );
                 if( iResult == 0 )
                 {
                   iRead = 1;
                 }
               }
-              else
+              else if( fld->entries == 1 )
               {
                 iResult = fits_read_col( ffits, TDOUBLE, fld->column, s+1, 1, n, &dNan, v, &iAnyNull, &iStatus );
                 if( iResult == 0 )
@@ -368,7 +348,22 @@
                   iRead = n;
                 }
               }
- 
+              else
+              {
+                long naxes[] = { fld->entries, _numFrames };
+                long fpixels[] = { fld->entry, s + 1 };
+                long lpixels[] = { fld->entry, s + n };
+                long inc[] = { 1, 1 };
+
+                iResult = fits_read_subset_dbl( ffits, fld->column, 1,
+                          naxes, (long*)fpixels, (long*)lpixels, (long*)inc, dNan, v, &iAnyNull, &iStatus );
+
+                if( iResult == 0 )
+                {
+                  iRead = n;
+                }
+              }
+
               iStatus = 0;
             }
           }
@@ -520,76 +515,58 @@
 
             for( i=0; i<iNumHeaderDataUnits-1 && ok; i++ )
             {
-              ok = false;
-
-              fits_movrel_hdu( ffits, 1, &iHDUType, &iStatus);
-              if( iStatus == 0 && iHDUType == BINARY_TBL )
+              if( fits_movrel_hdu( ffits, 1, &iHDUType, &iStatus ) == 0 )
               {
-                if( fits_read_keyword( ffits, "EXTNAME", value, comment, &iStatus ) == 0 )
-                {
-                  QString section = QString( value ).section( '-', 1, 1 );
+                ok = false;
 
-                  if( section.compare( "OBTT" ) == 0 ||
-                      section.compare( "TOD." ) == 0 ||
-                      section.compare( "OBTH" ) == 0 ||
-                      section.compare( "HKP." ) == 0 )
+                if( iStatus == 0 && iHDUType == BINARY_TBL )
+                {
+                  if( fits_read_keyword( ffits, "TIMEZERO", value, comment, &iStatus ) == 0 )
                   {
-                    bool okCols = false;
-
-                    //
-                    // all the columns should have a repeat value of 1...
-                    //
-                    if( fits_get_num_cols( ffits, &cols, &iStatus ) == 0 )
+                    if( fits_read_keyword( ffits, "EXTNAME", value, comment, &iStatus ) == 0 )
                     {
-                      long lRepeat;
-                      long lWidth;
-                      int iTypeCode;
-                      int col;
-
-                      if( cols > 0 )
+                      QString section = QString( value ).section( '-', 1, 1 );
+  
+                      if( section.compare( "OBTT" ) == 0 ||
+                          section.compare( "TOD." ) == 0 ||
+                          section.compare( "OBTH" ) == 0 ||
+                          section.compare( "HKP." ) == 0 )
                       {
-                        okCols = true;
-
-                        for( col=0; col<cols; ++col )
+                        bool okCols = false;
+  
+                        if( fits_get_num_cols( ffits, &cols, &iStatus ) == 0 )
                         {
-                          if( fits_get_coltype( ffits, col+1, &iTypeCode, &lRepeat, &lWidth, &iStatus ) == 0 )
+                          if( cols > 0 )
                           {
-                            if( lRepeat != 1 )
-                            {
-                              okCols = false;
-
-                              break;
-                            }
+                            okCols = true;
                           }
-                          else
+                        }
+  
+                        if( okCols && fits_get_num_rows( ffits, &rows, &iStatus ) == 0 )
+                        {
+                          //
+                          // all tables should have the same number of rows...
+                          //
+                          if( i == 0 )
                           {
-                            okCols = false;
-
-                            break;
+                            rowsCompare = rows;
+  
+                            ok = true;
                           }
+                          else if( rowsCompare == rows )
+                          {
+                            ok = true;
+                          }
                         }
                       }
                     }
-
-                    if( okCols && fits_get_num_rows( ffits, &rows, &iStatus ) == 0 )
-                    {
-                      //
-                      // all tables should have the same number of rows...
-                      //
-                      if( i == 0 )
-                      {
-                        rowsCompare = rows;
-
-                        ok = true;
-                      }
-                      else if( rowsCompare == rows )
-                      {
-                        ok = true;
-                      }
-                    }
                   }
                 }
               }
+              else
+              {
+                ok = false;
+              }
             }
           }
           else
--- trunk/extragear/graphics/kst/src/datasources/planckIDEF/planckIDEF.h #640678:640679
@@ -24,6 +24,8 @@
 typedef struct {
     int table;
     int column;
+    int entry;
+    int entries;
 } field;
 
 class PLANCKIDEFSource : public KstDataSource {


More information about the Kst mailing list