Extend support writing linear least squares problems to disk.

1. Make the mechanism for writing problems to disk, generic and
controllable using an enum DumpType visible in the API.

2. Instead of single file containing protocol buffers, now matrices can
be written in a matlab/octave friendly format. This is now the default.

3. The support for writing problems to disk is moved into
linear_least_squares_problem.cc/h

4. SparseMatrix now has a ToTextFile virtual method which is
implemented by each of its subclasses to write a (i,j,s) triplets.

5. Minor changes to simple_bundle_adjuster to enable logging at startup.
diff --git a/include/ceres/solver.h b/include/ceres/solver.h
index 15fd733..bd66927 100644
--- a/include/ceres/solver.h
+++ b/include/ceres/solver.h
@@ -83,7 +83,8 @@
       minimizer_progress_to_stdout = false;
       return_initial_residuals = false;
       return_final_residuals = false;
-      lsqp_dump_format = "lm_iteration_%03d.lsqp";
+      lsqp_dump_directory = "/tmp";
+      lsqp_dump_format_type = TEXTFILE;
       crash_and_dump_lsqp_on_failure = false;
       check_gradients = false;
       gradient_check_relative_precision = 1e-8;
@@ -213,12 +214,8 @@
     //
     // This is ignored if protocol buffers are disabled.
     vector<int> lsqp_iterations_to_dump;
-
-    // Format string for the file name used for dumping the least
-    // squares problem to disk. If the format is 'ascii', then the
-    // problem is logged to the screen; don't try this with large
-    // problems or expect a frozen terminal.
-    string lsqp_dump_format;
+    string lsqp_dump_directory;
+    DumpFormatType lsqp_dump_format_type;
 
     // Dump the linear least squares problem to disk if the minimizer
     // fails due to NUMERICAL_FAILURE and crash the process. This flag
diff --git a/include/ceres/types.h b/include/ceres/types.h
index b83a266..433baa8 100644
--- a/include/ceres/types.h
+++ b/include/ceres/types.h
@@ -210,6 +210,33 @@
   SOLVER_TERMINATE_SUCCESSFULLY
 };
 
+// The format in which linear least squares problems should be logged
+// when Solver::Options::lsqp_iterations_to_dump is non-empty.
+enum DumpFormatType {
+  // Print the linear least squares problem in a human readable format
+  // to stderr. The Jacobian is printed as a dense matrix. The vectors
+  // D, x and f are printed as dense vectors. This should only be used
+  // for small problems.
+  CONSOLE,
+
+  // Write out the linear least squares problem to the directory
+  // pointed to by Solver::Options::lsqp_dump_directory as a protocol
+  // buffer. linear_least_squares_problems.h/cc contains routines for
+  // loading these problems. For details on the on disk format used,
+  // see matrix.proto. The files are named lm_iteration_???.lsqp.
+  PROTOBUF,
+
+  // Write out the linear least squares problem to the directory
+  // pointed to by Solver::Options::lsqp_dump_directory as text files
+  // which can be read into MATLAB/Octave. The Jacobian is dumped as a
+  // text file containing (i,j,s) triplets, the vectors D, x and f are
+  // dumped as text files containing a list of their values.
+  //
+  // A MATLAB/octave script called lm_iteration_???.m is also output,
+  // which can be used to parse and load the problem into memory.
+  TEXTFILE
+};
+
 const char* LinearSolverTypeToString(LinearSolverType type);
 const char* PreconditionerTypeToString(PreconditionerType type);
 const char* LinearSolverTerminationTypeToString(