diff --git a/.gitignore b/.gitignore
index 6deec976380ada3d89b99a723abb1c4df20cf173..ecb83700cb4f01a8442484d33b4b02010c8592a6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+build/include
 build/cluster/*
 build/sphere/*
 build/trapping/*
diff --git a/src/sphere/List.h b/src/include/List.h
similarity index 100%
rename from src/sphere/List.h
rename to src/include/List.h
diff --git a/src/include/file_io.h b/src/include/file_io.h
new file mode 100644
index 0000000000000000000000000000000000000000..2c6fdd1d25fe4d220a04dd323a5e996b8393b971
--- /dev/null
+++ b/src/include/file_io.h
@@ -0,0 +1,6 @@
+extern "C" void open_file_(int*, const char*, const char*, const char*);
+extern "C" void close_file_(int*);
+extern "C" void read_int_(int*, int*);
+extern "C" void write_complex_(int*, double*, double*);
+extern "C" void write_double_(int*, double*);
+extern "C" void write_int_(int*, int*);
diff --git a/src/sphere/edfb.cpp b/src/sphere/edfb.cpp
index 9ca373da45f620309468938e91bcb9b751e451fe..04ded87d1a91de67f47373058ed33598388b4569 100644
--- a/src/sphere/edfb.cpp
+++ b/src/sphere/edfb.cpp
@@ -7,7 +7,8 @@
 #include <cstring>
 #include <iostream>
 #include <fstream>
-#include "List.h"
+#include "../include/file_io.h"
+#include "../include/List.h"
 
 using namespace std;
 
@@ -391,24 +392,27 @@ int main(int argc, char **argv) {
   // The FORTRAN code writes an auxiliary file in binary format. This should
   // be avoided or possibly replaced with the use of standard file formats for
   // scientific use (e.g. FITS).
-  ofstream tedf_file;
-  tedf_file.open("c_TEDF", ofstream::binary);
-  tedf_file.write(reinterpret_cast<char *>(&nsph), sizeof(nsph));
+  int uid = 27;
+  string bin_file_name = "c_TEDF";
+  string status = "UNKNOWN";
+  string mode = "UNFORMATTED";
+  open_file_(&uid, bin_file_name.c_str(), status.c_str(), mode.c_str());
+  write_int_(&uid, &nsph);
   for (int iogi = 0; iogi < nsph; iogi++)
-    tedf_file.write(reinterpret_cast<char *>(iog + iogi), sizeof(iog[iogi]));
-  tedf_file.write(reinterpret_cast<char *>(&exdc), sizeof(exdc));
-  tedf_file.write(reinterpret_cast<char *>(&wp), sizeof(wp));
-  tedf_file.write(reinterpret_cast<char *>(&xip), sizeof(xip));
-  tedf_file.write(reinterpret_cast<char *>(&idfc), sizeof(idfc));
-  tedf_file.write(reinterpret_cast<char *>(&nxi), sizeof(nxi));
+    write_int_(&uid, (iog + iogi));
+  write_double_(&uid, &exdc);
+  write_double_(&uid, &wp);
+  write_double_(&uid, &xip);
+  write_int_(&uid, &idfc);
+  write_int_(&uid, &nxi);
   for (int i115 = 1; i115 <= nsph; i115++) {
     if (iog[i115 - 1] < i115) continue;
-    tedf_file.write(reinterpret_cast<char *>(nshl + i115 - 1), sizeof(nshl[i115 - 1]));
-    tedf_file.write(reinterpret_cast<char *>(ros + i115 - 1), sizeof(ros[i115 - 1]));
+    write_int_(&uid, (nshl + i115 -1));
+    write_double_(&uid, (ros + i115 - 1));
     nsh = nshl[i115 - 1];
     if (i115 == 1) nsh += ies;
     for (int ins = 0; ins < nsh; ins++)
-      tedf_file.write(reinterpret_cast<char *>(rcf[i115 - 1] + ins), sizeof(rcf[i115 - 1][ins]));
+      write_double_(&uid, (rcf[i115 - 1] + ins));
   }
   // Remake the dc0m matrix.
   dc0m = new complex<double>**[max_nsh];
@@ -435,12 +439,11 @@ int main(int argc, char **argv) {
 	// The FORTRAN code writes the complex numbers as a 16-byte long binary stream.
 	// Here we assume that the 16 bytes are equally split in 8 bytes to represent the
 	// real part and 8 bytes to represent the imaginary one.
-	tedf_file.write(reinterpret_cast<char *>(&dc0_real), sizeof(dc0_real));
-	tedf_file.write(reinterpret_cast<char *>(&dc0_img), sizeof(dc0_img));
+	write_complex_(&uid, &dc0_real, &dc0_img);
       }
     }
   }
-  tedf_file.close();
+  close_file_(&uid);
   if (idfc != 0) {
     fprintf(output, "  DIELECTRIC CONSTANTS\n");
     for (int i473 = 1; i473 <= nsph; i473++) {