Index: /trunk/src/Header.cc
===================================================================
--- /trunk/src/Header.cc	(revision 9)
+++ /trunk/src/Header.cc	(revision 10)
@@ -11,5 +11,28 @@
   SurveySchema::SurveySchema(SURVEY surveyType)
   {
+    // Generic PHU Keywords that are the same for all surveys with PKS.
+    this->ant_x    = 0.;
+    this->ant_y    = 0.;
+    this->ant_z    = 0.;
+    this->frontend = " ";
+    this->fd_poln  = " ";
+    this->fd_hand  = 1;
+    this->fd_sang  = 0.;
+    this->fd_xyph  = 0.;
+    this->backend  = " ";
+    this->beconfig = " ";
+    this->be_phase = 0;  // 0=unknown
+    this->be_dcc   = 0;
+    this->tcycle   = 0.;
+    this->trk_mode = "TRACK"; // CHECK -- what is TRACK vs. SCANGC etc?
+    this->cal_mode = "OFF"; 
+    this->cal_freq = 0.;
+    this->cal_dcyc = 0.;
+    this->cal_phs  = 0.;
+    
     if(surveyType == S70){
+
+      this->scanlen = 152.;
+
       // This initialises the SurveyHeader arrays for the S70 setup.
       int s70Start[numKeywords] = {0,8,12,16,20,
@@ -53,4 +76,8 @@
     }
     else if(surveyType == PM || surveyType == PH){
+
+      if(surveyType == PM) this->scanlen = 2100.;
+      else                 this->scanlen = 265.;
+
       // This initialises the SurveyHeader arrays for the PM setup.
       int pmStart[numKeywords] = {0,6,10,16,20,
Index: /trunk/src/Header.hh
===================================================================
--- /trunk/src/Header.hh	(revision 9)
+++ /trunk/src/Header.hh	(revision 10)
@@ -46,13 +46,53 @@
     SurveySchema(){};
     SurveySchema(SURVEY surveyType);
-    SurveySchema(const SurveySchema& s){
-    for(int i=0;i<numKeywords;i++) startPosition[i]  = s.startPosition[i];
-    for(int i=0;i<numKeywords;i++) fieldLength[i]    = s.fieldLength[i];
-    for(int i=0;i<numKeywords;i++) fieldDimension[i] = s.fieldDimension[i];
+    SurveySchema(const SurveySchema& s)
+    {
+      for(int i=0;i<numKeywords;i++) startPosition[i]  = s.startPosition[i];
+      for(int i=0;i<numKeywords;i++) fieldLength[i]    = s.fieldLength[i];
+      for(int i=0;i<numKeywords;i++) fieldDimension[i] = s.fieldDimension[i];
+      ant_x    = s.ant_x;
+      ant_y    = s.ant_y;   
+      ant_z    = s.ant_z;    
+      frontend = s.frontend;
+      fd_poln  = s.fd_poln;  
+      fd_hand  = s.fd_hand; 
+      fd_sang  = s.fd_sang; 
+      fd_xyph  = s.fd_xyph; 
+      backend  = s.backend; 
+      beconfig = s.beconfig; 
+      be_phase = s.be_phase;
+      be_dcc   = s.be_dcc;
+      tcycle   = s.tcycle;   
+      trk_mode = s.trk_mode; 
+      scanlen  = s.scanlen;  
+      cal_mode = s.cal_mode; 
+      cal_freq = s.cal_freq; 
+      cal_dcyc = s.cal_dcyc; 
+      cal_phs  = s.cal_phs;  
     };
-    SurveySchema& operator= (const SurveySchema& s){
-    for(int i=0;i<numKeywords;i++) startPosition[i]  = s.startPosition[i];
-    for(int i=0;i<numKeywords;i++) fieldLength[i]    = s.fieldLength[i];
-    for(int i=0;i<numKeywords;i++) fieldDimension[i] = s.fieldDimension[i];
+    SurveySchema& operator= (const SurveySchema& s)
+    {
+      for(int i=0;i<numKeywords;i++) startPosition[i]  = s.startPosition[i];
+      for(int i=0;i<numKeywords;i++) fieldLength[i]    = s.fieldLength[i];
+      for(int i=0;i<numKeywords;i++) fieldDimension[i] = s.fieldDimension[i];
+      ant_x    = s.ant_x;
+      ant_y    = s.ant_y;   
+      ant_z    = s.ant_z;    
+      frontend = s.frontend;
+      fd_poln  = s.fd_poln;  
+      fd_hand  = s.fd_hand; 
+      fd_sang  = s.fd_sang; 
+      fd_xyph  = s.fd_xyph; 
+      backend  = s.backend; 
+      beconfig = s.beconfig; 
+      be_phase = s.be_phase;
+      be_dcc   = s.be_dcc;
+      tcycle   = s.tcycle;   
+      trk_mode = s.trk_mode; 
+      scanlen  = s.scanlen;  
+      cal_mode = s.cal_mode; 
+      cal_freq = s.cal_freq; 
+      cal_dcyc = s.cal_dcyc; 
+      cal_phs  = s.cal_phs;  
     };
     virtual ~SurveySchema(){};
@@ -70,4 +110,26 @@
       std::string surveyName;
     };
+
+    // accessor functions for PHU keyword values -- only get functions needed.
+    double      getAntX(){return ant_x;};
+    double      getAntY(){return ant_y;};
+    double      getAntZ(){return ant_z;};
+    std::string getFrontend(){return frontend;};
+    std::string getFd_poln(){return fd_poln;};
+    int         getFd_hand(){return fd_hand;};
+    float       getFd_sang(){return fd_sang;};
+    float       getFd_xyph(){return fd_xyph;};
+    std::string getBackend(){return backend;};
+    std::string getBeconfig(){return beconfig;};
+    int         getBe_phase(){return be_phase;};
+    int         getBe_dcc(){return be_dcc;};
+    double      getTcycle(){return tcycle;};
+    std::string getTrk_mode(){return trk_mode;};
+    float       getScanlen(){return scanlen;};
+    std::string getCal_mode(){return cal_mode;};
+    float       getCal_freq(){return cal_freq;};
+    float       getCal_dcyc(){return cal_dcyc;};
+    float       getCal_phs(){return cal_phs;};
+
  
   private:
@@ -75,4 +137,28 @@
     int fieldLength[numKeywords];
     int fieldDimension[numKeywords];
+
+    // The following are PHU keywords that are survey-dependent.
+    double      ant_x;
+    double      ant_y;
+    double      ant_z;
+    std::string frontend;
+    std::string fd_poln;
+    int         fd_hand;
+    float       fd_sang;
+    float       fd_xyph;
+    std::string backend;
+    std::string beconfig;
+    int         be_phase;
+    int         be_dcc;
+    double      tcycle;
+    std::string trk_mode;
+    float       scanlen;
+    std::string cal_mode;
+    float       cal_freq;
+    float       cal_dcyc;
+    float       cal_phs;
+
+    
+
   };
 
Index: /trunk/src/PSRFits.cc
===================================================================
--- /trunk/src/PSRFits.cc	(revision 9)
+++ /trunk/src/PSRFits.cc	(revision 10)
@@ -181,4 +181,11 @@
     return status;
   }
+  template <> int PSRFits::updateKeyword(std::string name, long value){
+    int status=0;
+    fits_update_key(this->fptr, TLONG, (char *)name.c_str(), 
+		    &value, NULL, &status);
+    if(status) FITSError("PSRFits::updateKeyword",status);
+    return status;
+  }
   template <> int PSRFits::updateKeyword(std::string name, float value){
     int status=0;
@@ -308,65 +315,93 @@
     this->gotoPHU();
 
-//     time_t tp;
-//     struct tm *ptr;
-//     time(&tp);
-//     ptr = gmtime(&tp);         /* get GMT (= UTC) time */
-    char *todaysdate = new char[25];
+    char *todaysdate     = new char[25];
     int timeref,status=0;
     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));
-//     this->updateKeyword("ANT_X", block.Survey().getAntX());          
-//     this->updateKeyword("ANT_Y", block.Survey().getAntY());        
-//     this->updateKeyword("ANT_Z", block.Survey().getAntZ());        
-    //CHECK -- find out these correct values
-//     this->updateKeyword("FRONTEND" **survey-dependent** );
-//     this->updateKeyword("FD_POLN " **survey-dependent** );
-//     this->updateKeyword("FD_HAND " **survey-dependent** );
-//     this->updateKeyword("FD_SANG " **survey-dependent** );
-//     this->updateKeyword("FD_XYPH " **survey-dependent** );
-//     this->updateKeyword("BACKEND " **survey-dependent** );
-//     this->updateKeyword("BECONFIG" **survey-dependent** );
-//     this->updateKeyword("BE_PHASE" **survey-dependent** );
-//     this->updateKeyword("BE_DCC  " **survey-dependent** );
-//     this->updateKeyword("TCYCLE  " **survey-dependent** );
-    this->updateKeyword("NRCVR",    block.getKeyword<int>(NFILTER));          
-    this->updateKeyword("OBS_MODE", PHU_kw_obs_mode);
-    this->updateKeyword("SRC_NAME", block.getKeyword<std::string>(PSRNAME));
+    std::string projid   = block.getSurveyName();
+    std::string telescop = block.getKeyword<std::string>(TELID);
+    // CHECK -- the following PHU keywords are all survey dependent
+    // CHECK -- need to find correct values.
+    double ant_x         = block.Survey().getAntX();
+    double ant_y         = block.Survey().getAntY();
+    double ant_z         = block.Survey().getAntZ();
+    std::string frontend = block.Survey().getFrontend();
+    std::string fd_poln  = block.Survey().getFd_poln();
+    int fd_hand          = block.Survey().getFd_hand();
+    float fd_sang        = block.Survey().getFd_sang();
+    float fd_xyph        = block.Survey().getFd_xyph();
+    std::string backend  = block.Survey().getBackend();
+    std::string beconfig = block.Survey().getBeconfig();
+    int be_phase         = block.Survey().getBe_phase();
+    int be_dcc           = block.Survey().getBe_dcc();
+    double tcycle        = block.Survey().getTcycle();
+    int nrcvr            = block.getKeyword<int>(NFILTER);
+    std::string obs_mode = PHU_kw_obs_mode;
+    std::string src_name = deblank(block.getKeyword<std::string>(PSRNAME));
+    std::string coord_md = PHU_kw_coord_md;
     //  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));
-    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));
-    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("CAL_MODE" **no information**   );
-//     this->updateKeyword("CAL_FREQ" **no information**   );
-    this->updateKeyword("CAL_DCYC", block.getKeyword<std::string>(CAL_CYCLE));
-    //     this->updateKeyword("CAL_PHS ", **no information**   );
+    std::string stt_crd1 = deblank(block.getKeyword<std::string>(RA));
+    std::string stt_crd2 = deblank(block.getKeyword<std::string>(DEC));
+    std::string trk_mode = block.Survey().getTrk_mode();
+    std::string stp_crd1 = deblank(block.getKeyword<std::string>(RA));
+    std::string stp_crd2 = deblank(block.getKeyword<std::string>(DEC));
+    float scanlen        = block.Survey().getScanlen();
+    std::string fd_mode  = deblank(block.getKeyword<std::string>(FDCNTRL));
+    float fa_req         = block.getKeyword<float>(FEED_ANGLE);
+    std::string cal_mode = block.Survey().getCal_mode();
+    float cal_freq       = block.Survey().getCal_freq();
+    float cal_dcyc       = block.Survey().getCal_dcyc();
+    float cal_phs        = block.Survey().getCal_phs();
     // CHECK -- STT_DATE NEEDS TO BE PUT INTO A STANDARD FORMAT.
-    std::string stt_date = block.getKeyword<std::string>(DATE);
+    std::string stt_date = deblank(block.getKeyword<std::string>(DATE));
     if(stt_date[0] == '0') stt_date = "20" + stt_date;
     else                   stt_date = "19" + stt_date;
+    for(int i=0;i<stt_date.size();i++) if(stt_date[i]=='/') stt_date[i]='-';
+    std::string stt_time = deblank(block.getKeyword<std::string>(UT));
+    long stt_imjd        = block.getKeyword<int>(MJD);
+    long stt_smjd        = long(dmsToDec(stt_time) * 3600.);
+    double stt_offs      = 0.; //CHECK -- what is STT_OFFS?
+    double stt_lst       = dmsToDec(block.getKeyword<std::string>(LST))*3600.;
+
+    this->UT_initial = stt_time;
+
+    this->updateKeyword("DATE",     todaysdate);
+    this->updateKeyword("PROJID",   projid);
+    this->updateKeyword("TELESCOP", telescop);
+    this->updateKeyword("ANT_X",    ant_x);          
+    this->updateKeyword("ANT_Y",    ant_y);        
+    this->updateKeyword("ANT_Z",    ant_z);        
+    this->updateKeyword("FRONTEND", frontend);
+    this->updateKeyword("FD_POLN",  fd_poln);
+    this->updateKeyword("FD_HAND",  fd_hand);
+    this->updateKeyword("FD_SANG",  fd_sang);
+    this->updateKeyword("FD_XYPH",  fd_xyph);
+    this->updateKeyword("BACKEND",  backend);
+    this->updateKeyword("BECONFIG", beconfig);
+    this->updateKeyword("BE_PHASE", be_phase);
+    this->updateKeyword("BE_DCC",   be_dcc);
+    this->updateKeyword("TCYCLE",   tcycle);
+    this->updateKeyword("NRCVR",    nrcvr);
+    this->updateKeyword("OBS_MODE", obs_mode);
+    this->updateKeyword("SRC_NAME", src_name);
+    this->updateKeyword("COORD_MD", coord_md);
+    this->updateKeyword("STT_CRD1", stt_crd1);
+    this->updateKeyword("STT_CRD2", stt_crd2);
+    this->updateKeyword("TRK_MODE", trk_mode);
+    this->updateKeyword("STP_CRD1", stp_crd1);
+    this->updateKeyword("STP_CRD2", stp_crd2);
+    this->updateKeyword("SCANLEN",  scanlen);
+    this->updateKeyword("FD_MODE",  fd_mode);
+    this->updateKeyword("FA_REQ",   fa_req);
+    this->updateKeyword("CAL_MODE", cal_mode);
+    this->updateKeyword("CAL_FREQ", cal_freq);
+    this->updateKeyword("CAL_DCYC", cal_dcyc);
+    this->updateKeyword("CAL_PHS ", cal_phs);
     this->updateKeyword("STT_DATE", stt_date);
-    this->updateKeyword("STT_TIME", block.getKeyword<std::string>(UT_STRT));
-    this->updateKeyword("STT_IMJD", block.getKeyword<int>(MJD));
-//     this->updateKeyword("STT_SMJD" **calculatable**     );
-//     this->updateKeyword("STT_OFFS" **unclear**          );
-    this->updateKeyword("STT_LST ", 
-			dmsToDec(block.getKeyword<std::string>(LST_STRT)) );
+    this->updateKeyword("STT_TIME", stt_time);
+    this->updateKeyword("STT_IMJD", stt_imjd);
+    this->updateKeyword("STT_SMJD", stt_smjd);
+    this->updateKeyword("STT_OFFS", stt_offs);
+    this->updateKeyword("STT_LST ", stt_lst);
   }
  //--------------------------------------------------------------------------
@@ -391,6 +426,4 @@
     }
     
-    int ct = 1;
-
     this->updateKeyword("NCH_FILE", block.getKeyword<int>(NCHAN));
     this->updateKeyword("INT_TYPE", SUBINT_kw_int_type);
@@ -398,30 +431,39 @@
     this->updateKeyword("NCH_STRT", SUBINT_kw_nch_strt);
 
+    this->startNewRow(); 
+    // CHECK -- need some check of blk_cntr to make sure the number is 
+    // CHECK -- incrementing correctly?
+    float tsubint = block.getKeyword<float>(BLK_SEC);
     float off_sub;
     // CHECK -- OFF_SUB is the offset, from the start (taken to mean the 
     // CHECK -- starting time listed in the PHU), of the centre of the 
     // CHECK -- current subintegration.
-    // CHECK -- This will need to be calculated from the keywords UT_STRT
-    // CHECK -- and UT (being the UT at the *start* of the current block)
-
-
-    this->startNewRow(); 
-    // CHECK -- need some check of blk_cntr to make sure the number is 
-    // CHECK -- incrementing correctly?
-    this->writeColumnValue("TSUBINT",  block.getKeyword<float>(BLK_SEC));
+    off_sub = dmsToDec(block.getKeyword<std::string>(UT)) - 
+      dmsToDec(this->UT_initial);
+    if(off_sub<0.) off_sub += 24.;
+    off_sub = off_sub*3600. + block.getKeyword<float>(BLK_SEC)/2.;
+    double lst_sub  = dmsToDec(block.getKeyword<std::string>(LST));
+    double ra_sub   = dmsToDec(block.getKeyword<std::string>(RA))*15.;
+    double dec_sub  = dmsToDec(block.getKeyword<std::string>(DEC));
+    double glon_sub = block.getKeyword<double>(GL);
+    double glat_sub = block.getKeyword<double>(GB);
+    float  fd_ang   = block.getKeyword<float>(FEED_ANGLE);
+    float  pos_ang  = 0.;  // CHECK -- NO OTHER WAY TO DETERMINE POS_ANG?
+    float  par_ang  = block.getKeyword<float>(PANGLE);
+    float  tel_az   = block.getKeyword<float>(TEL_AZ);
+    float  tel_zen  = block.getKeyword<float>(TEL_ZEN);
+    
+    this->writeColumnValue("TSUBINT",  tsubint);
     this->writeColumnValue("OFFS_SUB", off_sub);
-    this->writeColumnValue("LST_SUB",  
-			   dmsToDec(block.getKeyword<std::string>(LST)) );
-    this->writeColumnValue("RA_SUB",   
-			   dmsToDec(block.getKeyword<std::string>(RA))*15. );
-    this->writeColumnValue("DEC_SUB",  
-			   dmsToDec(block.getKeyword<std::string>(DEC)) );
-    this->writeColumnValue("GLON_SUB", block.getKeyword<double>(GL));
-    this->writeColumnValue("GLAT_SUB", block.getKeyword<double>(GB));
-    this->writeColumnValue("FD_ANG",   block.getKeyword<float>(FEED_ANGLE));
-//     this->writeColumnValue("POS_ANG",  posang);
-    this->writeColumnValue("PAR_ANG",  block.getKeyword<float>(PANGLE));
-    this->writeColumnValue("TEL_AZ",   block.getKeyword<float>(TEL_AZ));
-    this->writeColumnValue("TEL_ZEN",  block.getKeyword<float>(TEL_ZEN));
+    this->writeColumnValue("LST_SUB",  lst_sub);
+    this->writeColumnValue("RA_SUB",   ra_sub);
+    this->writeColumnValue("DEC_SUB",  dec_sub);
+    this->writeColumnValue("GLON_SUB", glon_sub);
+    this->writeColumnValue("GLAT_SUB", glat_sub);
+    this->writeColumnValue("FD_ANG",   fd_ang);
+    this->writeColumnValue("POS_ANG",  pos_ang);
+    this->writeColumnValue("PAR_ANG",  par_ang);
+    this->writeColumnValue("TEL_AZ",   tel_az);
+    this->writeColumnValue("TEL_ZEN",  tel_zen);
     
     this->writeSupportArrays(block); //DAT_FREQ,DAT_WTS,DAT_OFFS,DAT_SCL
Index: /trunk/src/PSRFits.hh
===================================================================
--- /trunk/src/PSRFits.hh	(revision 9)
+++ /trunk/src/PSRFits.hh	(revision 10)
@@ -55,4 +55,5 @@
     bool newFile;
     STATE filestate;
+    std::string UT_initial; // the UT at the start of the FITS file data.
   };
 
Index: /trunk/src/Utils.hh
===================================================================
--- /trunk/src/Utils.hh	(revision 9)
+++ /trunk/src/Utils.hh	(revision 10)
@@ -15,4 +15,19 @@
   std::string newstring;
   for(int j=i;j<s.size();j++) newstring += s[j];
+  return newstring;
+}
+
+inline std::string deblank(std::string s)
+{
+  int beg=0;
+  while(s[beg]==' '){
+    beg++;
+  }
+  int end=s.size()-1;
+  while(s[end]==' '){
+    end--;
+  }
+  std::string newstring;
+  for(int j=beg;j<=end;j++) newstring += s[j];
   return newstring;
 }
Index: /trunk/src/tests/headertest.cc
===================================================================
--- /trunk/src/tests/headertest.cc	(revision 9)
+++ /trunk/src/tests/headertest.cc	(revision 10)
@@ -8,5 +8,5 @@
   try{
     std::cout <<"S70: ";
-    SurveySchema survey1("S70");
+    SurveySchema survey1(S70);
     std::cout << survey1.getStartPosition(FREQ_CHAN1) << std::endl;
     std::cout << survey1.readParameter<int>(hdrtest,TAPENR) << std::endl;
@@ -23,14 +23,18 @@
 		<< survey1.getFieldDimension(STATUS) << "\n";
     }
+    std::cout << "ANT_X = " << survey1.getAntX() <<"\n";
+    std::cout << "FD_POLN = " << survey1.getFd_poln() <<"\n";
+    std::cout << "FD_XYPH = " << survey1.getFd_xyph() <<"\n";
+    std::cout << "TCYCLE = " << survey1.getTcycle() << "\n";
 
     std::cout <<"PM : ";
-    SurveySchema survey2("PM");
+    SurveySchema survey2(PM);
     std::cout << survey2.getStartPosition(FREQ_CHAN1) << std::endl;
     std::cout << survey2.readParameter<int>(hdrtest,TAPENR) << std::endl;
     
-    std::cout <<"BOB: ";
-    SurveySchema survey3("BOB");
-    std::cout << survey3.getStartPosition(FREQ_CHAN1) << std::endl;
-    std::cout << survey3.readParameter<int>(hdrtest,TAPENR) << std::endl;
+//     std::cout <<"BOB: ";
+//     SurveySchema survey3("BOB");
+//     std::cout << survey3.getStartPosition(FREQ_CHAN1) << std::endl;
+//     std::cout << survey3.readParameter<int>(hdrtest,TAPENR) << std::endl;
  }
   catch(SurveySchema::xBadSurvey bad){
Index: /trunk/src/tests/s70FullTest.cc
===================================================================
--- /trunk/src/tests/s70FullTest.cc	(revision 9)
+++ /trunk/src/tests/s70FullTest.cc	(revision 10)
@@ -76,4 +76,8 @@
   bool eof;
   DataBlock block(currentSurvey);
+  std::cerr << block.Survey().getAntX() << "\n";
+  SurveySchema testsurv(currentSurvey);
+  std::cerr << testsurv.getAntX() << "\n";
+  
   block.readBlock(fin);
   
