diff --git a/python/frep-C.py b/python/frep-C.py
index 1641a3625e5f3b91178e72a774058c131aa2a085..d671e2090e82d9c08c06e29c3e60c24eb2596050 100755
--- a/python/frep-C.py
+++ b/python/frep-C.py
@@ -88,6 +88,7 @@ int nx = (xmax-xmin)/delta;
 int ny = (ymax-ymin)/delta;
 int *m = (int*) calloc(nx*ny,sizeof(int));
 float layers[] = {{{layers}}};
+int nlayers = {nlayers};
 int nthreads = std::thread::hardware_concurrency();
 //
 int fn(float X,float Y,float Z) {{
@@ -96,7 +97,7 @@ int fn(float X,float Y,float Z) {{
 //
 void calc(int nx,int ny,int nthreads,int thread) {{
    int intensity;
-   for (int layer = 0; layer < 2; ++layer) {{
+   for (int layer = 0; layer < nlayers; ++layer) {{
       float z = layers[layer];
       if (thread == 0)
          cout << "   z = " << z << endl;