Index: /trunk/sql/angsep_query-s70.sql
===================================================================
--- /trunk/sql/angsep_query-s70.sql	(revision 91)
+++ /trunk/sql/angsep_query-s70.sql	(revision 92)
@@ -8,15 +8,16 @@
 -- The old query of RA=0 and DEC=-49 should pick up four files.
 --SET @qra=0., @qdec=-49.;
-SET @ngpra=192.859508, @ngpdec=27.128336, @ascnode=32.932; -- base coords for galactic coord transformation.
 SELECT filename, raj, decj, 0.5*(bmaj+bmin) as beamsize, obsfreq, scanlen,
 (degrees( acos( cos(radians(rajd-@qra))*cos(radians(decjd))*cos(radians(@qdec))+sin(radians(decjd))*sin(radians(@qdec)) ) )) as angsep,
-(degrees( asin( cos(radians(decjd))*cos(radians(@ngpdec))*cos(radians(rajd-@ngpra)) + sin(radians(decjd))*sin(radians(@ngpdec))))) as gb,
---degrees( atan2( ( sin(radians(decjd))*cos(radians(@ngpdec)) - cos(radians(decjd))*sin(radians(@ngpdec))*cos(radians(rajd-@ngpra)) ) , ( cos(radians(decjd))*sin(radians(rajd-@ngpra)) ) ) ) + @ascnode as gl,
+--case when degrees( atan2( ( sin(radians(decjd))*cos(radians(@ngpdec)) - cos(radians(decjd))*sin(radians(@ngpdec))*cos(radians(rajd-@ngpra)) ) , ( cos(radians(decjd))*sin(radians(rajd-@ngpra)) ) ) ) + @ascnode > 0 
+--     then degrees( atan2( ( sin(radians(decjd))*cos(radians(@ngpdec)) - cos(radians(decjd))*sin(radians(@ngpdec))*cos(radians(rajd-@ngpra)) ) , ( cos(radians(decjd))*sin(radians(rajd-@ngpra)) ) ) ) + @ascnode
+--     else degrees( atan2( ( sin(radians(decjd))*cos(radians(@ngpdec)) - cos(radians(decjd))*sin(radians(@ngpdec))*cos(radians(rajd-@ngpra)) ) , ( cos(radians(decjd))*sin(radians(rajd-@ngpra)) ) ) ) + @ascnode + 360. end
+--as 
 gl,
+--(degrees( asin( cos(radians(decjd))*cos(radians(@ngpdec))*cos(radians(rajd-@ngpra)) + sin(radians(decjd))*sin(radians(@ngpdec))))) as 
+gb,
 src_name
 FROM s70
 WHERE (degrees( acos( cos(radians(rajd-@qra))*cos(radians(decjd))*cos(radians(@qdec))+sin(radians(decjd))*sin(radians(@qdec)) ) ) - 0.25*(bmaj+bmin) ) <  1.
-and
-gl = ( select case degrees( atan2( ( sin(radians(decjd))*cos(radians(@ngpdec)) - cos(radians(decjd))*sin(radians(@ngpdec))*cos(radians(rajd-@ngpra)) ) , ( cos(radians(decjd))*sin(radians(rajd-@ngpra)) ) ) ) + @ascnode
 ORDER by angsep;
 -- period;
Index: /trunk/sql/create_table_s70.sql
===================================================================
--- /trunk/sql/create_table_s70.sql	(revision 91)
+++ /trunk/sql/create_table_s70.sql	(revision 92)
@@ -26,4 +26,6 @@
 	period DECIMAL(32,24),
 	dm DECIMAL(16,10),
+	gl DECIMAL(9,4),
+	gb DECIMAL(9,4),
 	PRIMARY KEY (file_id)
 );
@@ -39,3 +41,6 @@
 OPTIONALLY ENCLOSED BY "\""
 IGNORE 1 LINES  -- this ignores the first line in the csv file which contains the column headers.
-(filename,fileloc,hdrver,survey,src_name,raj,decj,rajd,decjd,bmaj,bmin,bpa,date_obs,mjd,obsfreq,chanbw,nchan,scanlen,tbin);
+(filename,fileloc,hdrver,survey,src_name,raj,decj,rajd,decjd,gl,gb,bmaj,bmin,bpa,date_obs,mjd,obsfreq,chanbw,nchan,scanlen,tbin);
+
+-- -- add gl and gb columns to the table.
+-- -- SET @ngpra=192.859508, @ngpdec=27.128336, @ascnode=32.932; -- base coords for galactic coord transformation.
Index: /trunk/src/pvo-metadata.cc
===================================================================
--- /trunk/src/pvo-metadata.cc	(revision 91)
+++ /trunk/src/pvo-metadata.cc	(revision 92)
@@ -52,4 +52,9 @@
       else this->decjd = dmsToDec(this->decj);
 
+      if(this->raj != nullString && this->decj != nullString)
+	equatToGal(this->rajd,this->decjd, this->gl, this->gb);
+      else
+	this->gl = this->gb = nullFloat;
+
       if(fitsfile.getKeyword<std::string>("DATE-OBS",this->date)!=0) 
 	this->date = nullString;
@@ -124,4 +129,14 @@
 	std::stringstream ss;
 	ss << std::fixed << std::setprecision(dubwidth) << d;
+	return ss.str();
+      }
+      else return nullString;
+    }
+
+    std::string doubleToString(double d, int prec)
+    {
+      if(d > nullFloat){
+	std::stringstream ss;
+	ss << std::fixed << std::setprecision(prec) << d;
 	return ss.str();
       }
@@ -234,4 +249,6 @@
 	      << "RAJd,"
 	      << "DECJd,"
+	      << "GL,"
+	      << "GB,"
 	      << "BMAJ,"
 	      << "BMIN,"
@@ -271,5 +288,7 @@
 	fileout << std::fixed << std::setprecision(6)
 		<< datalist[i].getRaD()                     << ","
-		<< datalist[i].getDecD()                    << ",";
+		<< datalist[i].getDecD()                    << ","
+		<< doubleToString(datalist[i].getGL(),4)    << ","
+		<< doubleToString(datalist[i].getGB(),4)    << ",";
 
 	fileout << floatToString(datalist[i].getBmaj())     << ","
Index: /trunk/src/pvo-metadata.hh
===================================================================
--- /trunk/src/pvo-metadata.hh	(revision 91)
+++ /trunk/src/pvo-metadata.hh	(revision 92)
@@ -18,4 +18,5 @@
 
     std::string doubleToString(double d);
+    std::string doubleToString(double d, int prec);
     std::string floatToString(float f);
     std::string intToString(int i);
@@ -40,4 +41,6 @@
  RAJd           Right Ascension, in decimal degrees.\n\
  DecJd          Declination, in decimal degrees.\n\
+ GL             Galactic Longitude, in degrees.\n\
+ GB             Galactic Latitude, in degrees.\n\
  BMAJ           The FWHM of the major axis of the beam.\n\
  BMIN           The FWHM of the minor axis of the beam.\n\
@@ -90,4 +93,8 @@
       std::string getDate(){return date;};
       void        setDate(std::string s){date=s;};
+      double      getGL(){return gl;};
+      void        setGL(double d){gl=d;};
+      double      getGB(){return gb;};
+      void        setGB(double d){gb=d;};
       float       getBeamsize(){return beamsize;};
       void        setBeamsize(float f){beamsize=f;};
@@ -129,4 +136,6 @@
       float       rajd;
       float       decjd;
+      double      gl;
+      double      gb;
       std::string date;
       float       beamsize;
Index: /trunk/src/pvo-utils.cc
===================================================================
--- /trunk/src/pvo-utils.cc	(revision 91)
+++ /trunk/src/pvo-utils.cc	(revision 92)
@@ -389,4 +389,43 @@
     
   }
+  //------------------------------------------------------------------------
+
+  void equatToGal(double ra, double dec, double &gl, double &gb)
+  {
+    /**
+     * Converts an equatorial (ra,dec) position to galactic
+     * coordinates. The equatorial position is assumed to be J2000.0.
+     *
+     * \param ra Right Ascension, J2000.0
+     * \param dec Declination, J2000.0
+     * \param gl Galactic Longitude. Returned value.
+     * \param gb Galactic Latitude. Returned value.
+     */
+
+    const double NGP_RA = 192.859508 * M_PI/180.;
+    const double NGP_DEC= 27.128336 * M_PI/180.;
+    const double ASC_NODE=32.932;
+
+    double deltaRA = ra * M_PI/180. - NGP_RA;
+    double d = dec     * M_PI/180.;
+    double sinb = cos(d) * cos(NGP_DEC) * cos(deltaRA) + sin(d) * sin(NGP_DEC);
+    gb = asin(sinb);
+//     double tanl = (sin(d) - sinb * sin(NGP_DEC)) / (cos(d) * sin(deltaRA) * cos(NGP_DEC));
+//     gl = atan(tanl) * 180. / M_PI + ASC_NODE;
+//     gl = fmod(gl+360.,360.);
+    double sinl = (sin(d)*cos(NGP_DEC) - cos(d)*cos(deltaRA)*sin(NGP_DEC)) / cos(gb);
+    double cosl = cos(d) * sin(deltaRA) / cos(gb);
+    if(sinl>0){
+      if(cosl>0) gl = atan(sinl/cosl);
+      else       gl = atan(sinl/cosl) + M_PI;
+    }
+    else{
+      if(cosl>0) gl = atan(sinl/cosl) + 2.*M_PI;
+      else       gl = atan(sinl/cosl) + M_PI;
+    }
+
+    gb = asin(sinb) * 180. / M_PI;
+    gl = gl * 180. / M_PI + ASC_NODE;
+  }
 
 }
Index: /trunk/src/pvo-utils.hh
===================================================================
--- /trunk/src/pvo-utils.hh	(revision 91)
+++ /trunk/src/pvo-utils.hh	(revision 92)
@@ -179,4 +179,7 @@
   double angSep(double ra1, double dec1, double ra2, double dec2);
 
+  /** Convert equatorial coordinates to Galactic. */
+  void equatToGal(double ra, double dec, double &gl, double &gb);
+
   std::string getIAUName(double ra, double dec);  
   ///< Create an IAU-style formatted name, based on the equatorial position.
