Index: /trunk/src/Header.hh
===================================================================
--- /trunk/src/Header.hh	(revision 7)
+++ /trunk/src/Header.hh	(revision 8)
@@ -22,5 +22,5 @@
   }
 
-  enum ISMOVING { GRID=0, POINT, MOVING };
+  enum ISMOVING { NOTGRID=0, POINT, MOVING, SCANNING };
 
   enum FIELDS 
Index: /trunk/src/PSRFits.cc
===================================================================
--- /trunk/src/PSRFits.cc	(revision 7)
+++ /trunk/src/PSRFits.cc	(revision 8)
@@ -35,8 +35,22 @@
  //--------------------------------------------------------------------------
 
-  PSRFits::~PSRFits()
-  {
-  }
- //--------------------------------------------------------------------------
+  PSRFits::PSRFits(DataBlock &block)
+  {
+    this->filestate = CLOSED;
+    this->openFile(block);
+  }
+ //--------------------------------------------------------------------------
+
+  int PSRFits::openFile(DataBlock &block)
+  {
+    std::string name = 
+      getIAUName(dmsToDec(block.getKeyword<std::string>(RA)),
+		 dmsToDec(block.getKeyword<std::string>(DEC)));
+    name += ".fits";
+    std::cerr << "Opening file " << name;
+    return this->openFile(name);
+  }
+ //--------------------------------------------------------------------------
+
 
   int PSRFits::openFile(std::string name)
@@ -52,4 +66,5 @@
     int status = 0, exists;
     fits_file_exists(name.c_str(),&exists,&status);
+    std::cerr << " Exists = " << exists << "\n";
     if(exists<=0){
       char *template_file = (char *)getPSRFITSdefn().c_str();
@@ -57,5 +72,5 @@
     }
     else{
-      fits_open_file(&fptr,name.c_str(),READWRITE,&status);
+      fits_open_file(&this->fptr, name.c_str(), READWRITE, &status);
     }
     if(status) FITSError("PSRFits::openFile",status);
@@ -65,4 +80,5 @@
 	this->fixPSRFITS();
       }
+      this->gotoPHU();
       this->filestate = OPEN;
     }
@@ -85,10 +101,10 @@
     if(USE_X) strcpy(cval,"16X");
     else      strcpy(cval,"2B");
-    fits_update_key(fptr, TSTRING, "TFORM19", cval, NULL, &status);
+    fits_update_key(this->fptr, TSTRING, "TFORM19", cval, NULL, &status);
     if(status) FITSError("PSRFits::fixPSRFITS", status);
     strcpy(cval,"deg");
-    fits_update_key(fptr, TSTRING, "TUNIT6", cval, NULL, &status);
+    fits_update_key(this->fptr, TSTRING, "TUNIT6", cval, NULL, &status);
     if(status) FITSError("PSRFits::fixPSRFITS", status);
-    fits_update_key(fptr, TSTRING, "TUNIT7", cval, NULL, &status);
+    fits_update_key(this->fptr, TSTRING, "TUNIT7", cval, NULL, &status);
     if(status) FITSError("PSRFits::fixPSRFITS", status);
 
@@ -134,5 +150,5 @@
      */
     int status = 0;
-    fits_movnam_hdu(this->fptr, ANY_HDU, "subint", 0, &status);
+    fits_movnam_hdu(this->fptr, BINARY_TBL, "SUBINT", 0, &status);
     if(status) FITSError("PSRFits::gotoSubint",status);
     return status;
@@ -289,8 +305,8 @@
     char *todaysdate;
     int timeref,status=0;
-    fits_get_system_time(todaysdate, &timeref, &status);
+//     fits_get_system_time(todaysdate, &timeref, &status);
     
     int ct=1;
-    this->updateKeyword("DATE", todaysdate);
+//     this->updateKeyword("DATE", todaysdate);
 //     this->updateKeyword("PROJID", block.getSurveyName());
     this->updateKeyword("TELESCOP", block.getKeyword<std::string>(TELID));
@@ -428,5 +444,5 @@
     int colnum = this->getColnum("DAT_FREQ");
     status=0;
-    fits_modify_vector_len (fptr, colnum, numChannels, &status);
+    fits_modify_vector_len (this->fptr, colnum, numChannels, &status);
     if(status) FITSError("PSRFits::writeSupportArray", status);
     status=0;
@@ -437,5 +453,5 @@
     colnum = this->getColnum("DAT_WTS");
     status=0;
-    fits_modify_vector_len (fptr, colnum, numChannels, &status);
+    fits_modify_vector_len (this->fptr, colnum, numChannels, &status);
     if(status) FITSError("PSRFits::writeSupportArray", status);
     status=0;
@@ -446,5 +462,5 @@
     colnum = this->getColnum("DAT_OFFS");
     status=0;
-    fits_modify_vector_len (fptr, colnum, numChannels, &status);
+    fits_modify_vector_len (this->fptr, colnum, numChannels, &status);
     if(status) FITSError("PSRFits::writeSupportArray", status);
     status=0;
@@ -455,5 +471,5 @@
     colnum = this->getColnum("DAT_SCL");
     status=0;
-    fits_modify_vector_len (fptr, colnum, numChannels, &status);
+    fits_modify_vector_len (this->fptr, colnum, numChannels, &status);
     if(status) FITSError("PSRFits::writeSupportArray", status);
     status=0;
@@ -519,5 +535,5 @@
 
     status=0;
-    fits_write_col_byt(fptr, colnum, nrows, 1, numBytes, data, &status);
+    fits_write_col_byt(this->fptr, colnum, nrows, 1, numBytes, data, &status);
 //     fits_write_col(this->fptr, TBYTE, colnum, nrows, 1, numBytes, data, &status);
     if(status) FITSError("PSRFits::writeDataArray1", status);
Index: /trunk/src/PSRFits.hh
===================================================================
--- /trunk/src/PSRFits.hh	(revision 7)
+++ /trunk/src/PSRFits.hh	(revision 8)
@@ -29,6 +29,8 @@
     PSRFits();
     PSRFits(std::string name);
-    virtual ~PSRFits();
+    PSRFits(DataBlock &block);
+    virtual ~PSRFits(){};
     bool isNewFile(){return newFile;};
+    int openFile(DataBlock &block);
     int openFile(std::string name);
     void fixPSRFITS();
Index: /trunk/src/Utils.hh
===================================================================
--- /trunk/src/Utils.hh	(revision 7)
+++ /trunk/src/Utils.hh	(revision 8)
@@ -1,4 +1,6 @@
 #ifndef UTILS_HH_
 #define UTILS_HH_
+#include <iostream>
+#include <iomanip>
 #include <sstream>
 #include <string>
@@ -72,3 +74,36 @@
 double dmsToDec(std::string input);  // in Utils.cc
 
+inline std::string getIAUName(double ra, double dec)
+{
+  /**
+   * string getIAUName(double, double)
+   *  both ra and dec are assumed to be in degrees.
+   *  returns name of the form J1234m4321 or J1234p0123
+   *  (note -- assumes J2000.0)
+   */
+
+  double raHrs = ra / 15.;
+  int h = int(raHrs);
+  int m = (int)(fmod(raHrs,1.)*60.);
+  int s = (int)(fmod(raHrs,1./60.)*3600.);
+  std::stringstream ss(std::stringstream::out);
+  ss.setf(std::ios::showpoint);
+  ss.setf(std::ios::fixed);
+  ss << "J"; 
+  ss<<std::setw(2)<<std::setfill('0')<<h;
+  ss<<std::setw(2)<<std::setfill('0')<<m;
+  ss<<std::setw(2)<<std::setfill('0')<<s;
+  int sign = int( dec / fabs(dec) );
+  double d = dec / sign;
+  h = int(d);
+  m = (int)(fmod(d,1.)*60.);
+  s = (int)(fmod(d,1./60.)*3600.);
+  if(sign==1) ss<<"p"; else ss<<"m";
+  ss<<std::setw(2)<<std::setfill('0')<<h;
+  ss.unsetf(std::ios::showpos);
+  ss<<std::setw(2)<<std::setfill('0')<<m;
+  ss<<std::setw(2)<<std::setfill('0')<<s;
+  return ss.str();
+}
+
 #endif /*UTILS_HH_*/
Index: /trunk/src/tests/s70FullTest.cc
===================================================================
--- /trunk/src/tests/s70FullTest.cc	(revision 7)
+++ /trunk/src/tests/s70FullTest.cc	(revision 8)
@@ -13,4 +13,13 @@
 using std::string;
 
+ISMOVING moveStatus(std::string file)
+{
+  std::ifstream fin;
+  fin.open(file.c_str(), std::ios::binary);
+  DataBlock block(idSurvey(file));
+  block.readBlock(fin);
+  return ISMOVING(block.getKeyword<int>(MOVE));
+}
+
 std::string getFileName(int number)
 {
@@ -23,5 +32,5 @@
 {
   std::string fname;
-  if(argc==1) fname = "../data/s70_tape_test_S181_S18101.dat";
+  if(argc==1) fname = "data/s70_tape_test_S181_S18101.dat";
   else if(argc==2) fname = argv[1];
   else{
@@ -33,12 +42,31 @@
 
   if(currentSurvey == PM){
-    std::cerr <<"\aOops! This is a PM survey!\n Good, but not for this program\nExiting...\n";
+    std::cerr <<"\aOops! This is a PM survey!\n Good, but not for this program\nExiting...\n"; 
   }
   if(currentSurvey != S70){
     if(currentSurvey!=PM)
-      std::cerr <<"\aOops! This isn't an S70 survey!\nExiting...\n";
+      std::cerr <<"\aOops! This isn't an S70 survey file!\nExiting...\n";
     return 1;
   }
   else std::cerr <<"Yes! This is an S70 survey file. Go ahead...\n";
+
+  ISMOVING status = moveStatus(fname);
+  if(status == NOTGRID){
+    std::cerr <<"\aOops! This is not a gridded observation -- and so not a survey\nExiting...";
+    return 1;
+  }
+  else if(status == SCANNING){
+    std::cerr <<"\aOops! This is a scanning observation -- how did that happen?\nExiting...";
+    return 1;
+  }
+  else if(status == MOVING)
+    std::cerr <<"OK... we are moving, but carry on in case we stop...\n";
+  else if(status == POINT)
+    std::cerr <<"Excellent... a pointed observation. Let's go!\n";
+  else{
+    std::cerr <<"\a\a\aOops! status is an unknown value (" 
+	      << status << ")\nExiting...\n";
+    return 1;
+  }
 
   std::ifstream fin;
@@ -52,5 +80,6 @@
 
   int filecount = 0;
-  PSRFits fitsfile(getFileName(filecount++));
+//   PSRFits fitsfile(getFileName(filecount++));
+  PSRFits fitsfile(block);
   fitsfile.writePHU(block);
   
@@ -79,5 +108,6 @@
       if((fitsfile.getFilestate()==CLOSED)
 	 &&(block.getKeyword<int>(MOVE)==POINT)){
-	fitsfile.openFile(getFileName(filecount++));
+// 	fitsfile.openFile(getFileName(filecount++));
+	fitsfile.openFile(block);
 	fitsfile.writePHU(block);
 	currentRA = block.getKeyword<std::string>(RA_STRT);
Index: /trunk/src/tests/test_s70_data_read.cc
===================================================================
--- /trunk/src/tests/test_s70_data_read.cc	(revision 7)
+++ /trunk/src/tests/test_s70_data_read.cc	(revision 8)
@@ -48,5 +48,5 @@
   string filename;
   if(argc==1){
-    filename = "../data/s70_tape_test_S181_S18101.dat";
+    filename = "data/s70_tape_test_S181_S18101.dat";
   }
   else if(argc==2){
