Index: /trunk/Makefile
===================================================================
--- /trunk/Makefile	(revision 8)
+++ /trunk/Makefile	(revision 9)
@@ -12,6 +12,6 @@
 
 # CFITSIODIR = /DATA/SITAR_1/whi550/Packages/cfitsio
-CFITSIODIR = /DATA/SITAR_1/whi550/Packages/cfitsio-myHack
-# CFITSIODIR = /DATA/SITAR_1/whi550/Packages/cfitsio-myHack-debug
+#CFITSIODIR = /DATA/SITAR_1/whi550/Packages/cfitsio-myHack
+ CFITSIODIR = /DATA/SITAR_1/whi550/Packages/cfitsio-myHack-debug
 CFITSIOINC = -I$(CFITSIODIR)
 CFITSIOLIB = -L$(CFITSIODIR) -lcfitsio
Index: /trunk/docs/conversionCodeDetails.tex
===================================================================
--- /trunk/docs/conversionCodeDetails.tex	(revision 8)
+++ /trunk/docs/conversionCodeDetails.tex	(revision 9)
@@ -533,9 +533,9 @@
 SRC_NAME=    pname             / Source or scan ID 
 COORD_MD= **need to choose**   / Coordinate mode (J2000, Gal, Ecliptic, etc.)
-STT_CRD1=    ra/gl_strt        / Start coord 1 (hh:mm:ss.sss or ddd.ddd)
-STT_CRD2=    dec/gb_strt       / Start coord 2 (-dd:mm:ss.sss or -dd.ddd) 
+STT_CRD1=    ra/gl             / Start coord 1 (hh:mm:ss.sss or ddd.ddd)
+STT_CRD2=    dec/gb            / Start coord 2 (-dd:mm:ss.sss or -dd.ddd) 
 TRK_MODE= **irrelevant**       / Track mode (TRACK, SCANGC, SCANLAT)
-STP_CRD1=    ra/gl_strt        / Stop coord 1 (hh:mm:ss.sss or ddd.ddd)
-STP_CRD2=    dec/gb_strt       / Stop coord 2 (-dd:mm:ss.sss or -dd.ddd) 
+STP_CRD1=    ra/gl             / Stop coord 1 (hh:mm:ss.sss or ddd.ddd)
+STP_CRD2=    dec/gb            / Stop coord 2 (-dd:mm:ss.sss or -dd.ddd) 
 SCANLEN = **survey-dependent** / [s] Requested scan length (E)
 FD_MODE =    fdcntrl           / Feed track mode - FA, CPA, SPA, TPA
@@ -790,4 +790,13 @@
 individual keywords and table columns.
 
+\subsection{Positional information}
+
+WARNING! Contrary to first thought, the existing header parameters
+\textsc{ra\_strt} and \textsc{dec\_strt} are not the appropriate ones
+for the \textsc{stt\_crd1,2} FITS keywords. They are the starting
+positions \emph{as far as the file is concerned}, and so are the same
+even when the telescope has moved to a different position. They are
+not the position of the start of the subints for a given sky location! 
+
 \subsection{Storing 1-bit binary data}
 
Index: /trunk/src/PSRFits.cc
===================================================================
--- /trunk/src/PSRFits.cc	(revision 8)
+++ /trunk/src/PSRFits.cc	(revision 9)
@@ -1,5 +1,7 @@
-#include "PSRFits.hh"
 #include <iostream>
 #include <string>
+#include <time.h>
+#include <fitsio.h>
+#include "PSRFits.hh"
 #include "Utils.hh"
 #include "Block.hh"
@@ -14,7 +16,7 @@
 {
   
-  void FITSError(std::string function, int status)
-  {
-    std::cerr << "FITSError <" << function << "> (status="<<status<<"): ";
+  inline void FITSError(std::string function, int status)
+  {
+    std::cerr << "\aFITSError <" << function << "> (status="<<status<<"): ";
     fits_report_error(stderr, status);
   }
@@ -45,5 +47,5 @@
   {
     std::string name = 
-      getIAUName(dmsToDec(block.getKeyword<std::string>(RA)),
+      getIAUName(dmsToDec(block.getKeyword<std::string>(RA))*15.,
 		 dmsToDec(block.getKeyword<std::string>(DEC)));
     name += ".fits";
@@ -150,5 +152,8 @@
      */
     int status = 0;
-    fits_movnam_hdu(this->fptr, BINARY_TBL, "SUBINT", 0, &status);
+    char name[8];
+    strcpy(name,"SUBINT");
+//     fits_movnam_hdu(this->fptr, BINARY_TBL, "SUBINT", 0, &status);
+    fits_movnam_hdu(this->fptr, BINARY_TBL, name, 0, &status);
     if(status) FITSError("PSRFits::gotoSubint",status);
     return status;
@@ -303,10 +308,15 @@
     this->gotoPHU();
 
-    char *todaysdate;
+//     time_t tp;
+//     struct tm *ptr;
+//     time(&tp);
+//     ptr = gmtime(&tp);         /* get GMT (= UTC) time */
+    char *todaysdate = new char[25];
     int timeref,status=0;
-//     fits_get_system_time(todaysdate, &timeref, &status);
-    
-    int ct=1;
-//     this->updateKeyword("DATE", todaysdate);
+    fits_get_system_time(todaysdate, &timeref, &status);
+    if(status) FITSError("PSRFits::writePHU", status);
+//     strftime(todaysdate, 25, "%Y-%m-%dT%H:%M:%S", ptr);
+    this->updateKeyword("DATE",     todaysdate);
+
 //     this->updateKeyword("PROJID", block.getSurveyName());
     this->updateKeyword("TELESCOP", block.getKeyword<std::string>(TELID));
@@ -325,19 +335,23 @@
 //     this->updateKeyword("BE_DCC  " **survey-dependent** );
 //     this->updateKeyword("TCYCLE  " **survey-dependent** );
-    this->updateKeyword("NRCVR", block.getKeyword<int>(NFILTER));          
+    this->updateKeyword("NRCVR",    block.getKeyword<int>(NFILTER));          
     this->updateKeyword("OBS_MODE", PHU_kw_obs_mode);
     this->updateKeyword("SRC_NAME", block.getKeyword<std::string>(PSRNAME));
     //  CHECK -- NEED TO DECIDE ON RA/DEC OR GL/GB
     this->updateKeyword("COORD_MD", PHU_kw_coord_md);
-    this->updateKeyword("STT_CRD1", block.getKeyword<std::string>(RA_STRT));
-    this->updateKeyword("STT_CRD2", block.getKeyword<std::string>(DEC_STRT));
+//     this->updateKeyword("STT_CRD1", block.getKeyword<std::string>(RA_STRT));
+//     this->updateKeyword("STT_CRD2", block.getKeyword<std::string>(DEC_STRT));
+    this->updateKeyword("STT_CRD1", block.getKeyword<std::string>(RA));
+    this->updateKeyword("STT_CRD2", block.getKeyword<std::string>(DEC));
 
 //     this->updateKeyword("TRK_MODE",    **irrelevant**       );
-    this->updateKeyword("STP_CRD1", block.getKeyword<std::string>(RA_STRT));
-    this->updateKeyword("STP_CRD2", block.getKeyword<std::string>(DEC_STRT));
+//     this->updateKeyword("STP_CRD1", block.getKeyword<std::string>(RA_STRT));
+//     this->updateKeyword("STP_CRD2", block.getKeyword<std::string>(DEC_STRT)); 
+    this->updateKeyword("STP_CRD1", block.getKeyword<std::string>(RA));
+    this->updateKeyword("STP_CRD2", block.getKeyword<std::string>(DEC));
 
 //     this->updateKeyword("SCANLEN", block.Survey().getScanLen());
-    this->updateKeyword("FD_MODE", block.getKeyword<std::string>(FDCNTRL));
-    this->updateKeyword("FA_REQ", block.getKeyword<float>(FEED_ANGLE));       
+    this->updateKeyword("FD_MODE",  block.getKeyword<std::string>(FDCNTRL));
+    this->updateKeyword("FA_REQ",   block.getKeyword<float>(FEED_ANGLE));
 //     this->updateKeyword("CAL_MODE" **no information**   );
 //     this->updateKeyword("CAL_FREQ" **no information**   );
@@ -358,5 +372,5 @@
  //--------------------------------------------------------------------------
 
-  void PSRFits::writeSubint(DataBlock &block)
+  int PSRFits::writeSubint(DataBlock &block)
   {
     /**
@@ -372,5 +386,9 @@
      *   At the end the current header unit will be the SUBINT extension.
      */
-    this->gotoSubint();
+    if(this->gotoSubint()){
+      std::cerr << "Could not go to the SUBINT table.\n";
+      return 1;
+    }
+    
     int ct = 1;
 
@@ -411,4 +429,6 @@
     this->writeDataArray(block);
    
+    return 0;
+
   }
  //--------------------------------------------------------------------------
Index: /trunk/src/PSRFits.hh
===================================================================
--- /trunk/src/PSRFits.hh	(revision 8)
+++ /trunk/src/PSRFits.hh	(revision 9)
@@ -12,6 +12,4 @@
 {
 	
-  //	enum HDU = {PHU=1, HISTORY, DIG_STAT, DIG_CNTS, 
-
   enum STATE { OPEN, CLOSED }; 
 	
@@ -46,5 +44,5 @@
     int startNewRow();
     void writePHU(DataBlock &block);
-    void writeSubint(DataBlock &block);
+    int  writeSubint(DataBlock &block);
     void startNewColumn();
     void writeColumnValue();
Index: /trunk/src/tests/s70FullTest.cc
===================================================================
--- /trunk/src/tests/s70FullTest.cc	(revision 8)
+++ /trunk/src/tests/s70FullTest.cc	(revision 9)
@@ -19,4 +19,5 @@
   DataBlock block(idSurvey(file));
   block.readBlock(fin);
+  fin.close();
   return ISMOVING(block.getKeyword<int>(MOVE));
 }
@@ -77,9 +78,13 @@
   block.readBlock(fin);
   
-  std::string currentRA = block.getKeyword<std::string>(RA_STRT);
+  std::string currentRA = block.getKeyword<std::string>(RA);
 
   int filecount = 0;
 //   PSRFits fitsfile(getFileName(filecount++));
-  PSRFits fitsfile(block);
+  PSRFits fitsfile;
+  if(fitsfile.openFile(block)) {
+    std::cerr << "\aCannot open file.\nExiting...\n";
+    return 1;
+  }
   fitsfile.writePHU(block);
   
@@ -89,5 +94,8 @@
     if(block.getKeyword<int>(MOVE)!=MOVING) {
       std::cerr << "block " << blockcount++;
-      fitsfile.writeSubint(block);
+      if(fitsfile.writeSubint(block)){
+	std::cerr << "Error. Exiting...\n";
+	return 1;
+      }
       std::cerr << " done\n";
     }
@@ -95,10 +103,10 @@
 
     std::cerr << currentRA << " "
-	      << block.getKeyword<std::string>(RA_STRT) << " "
+	      << block.getKeyword<std::string>(RA) << " "
 	      << block.getKeyword<int>(MOVE) <<" ";
 
     if(!eof){
 
-      if((block.getKeyword<std::string>(RA_STRT) != currentRA)
+      if((block.getKeyword<std::string>(RA) != currentRA)
 	 || (block.getKeyword<int>(MOVE)==MOVING)){
 	std::cerr << "Changing FITS file -- " << filecount << "\n";
@@ -111,5 +119,5 @@
 	fitsfile.openFile(block);
 	fitsfile.writePHU(block);
-	currentRA = block.getKeyword<std::string>(RA_STRT);
+	currentRA = block.getKeyword<std::string>(RA);
       }
 
@@ -123,4 +131,4 @@
   fitsfile.closeFile();
   fin.close();
-
+  std::cerr << "\n";
 }
