Off[General::spell]; 
    Off[General::spell1];

f4Calculate[stepsize_] := 
        Module[
{}, 
Run["perl \
$LABPATH/4/4.pl",  stepsize]; 
$points4 = 
            ReadList["$LABTMP/4", {Number, 
                Number}];
];

f4Plot[resonance_] := 
        Module[
{colors, lists, idx, plots, 
            i}, 

If[
              resonance > 
                0, 
colors = {RGBColor[1, 0, 0], 
                  RGBColor[0, 1, 0], RGBColor[0, 0, 1],  RGBColor[1, 0, 1], 
                  RGBColor[0, 1, 1], RGBColor[0, 0, 0], RGBColor[ .5, 0, 0], 
                  RGBColor[0,  .5, 0], RGBColor[0, 0,  .5], 
                  RGBColor[ .5,  .5, 0],  RGBColor[ .5, 0,  .5], 
                  RGBColor[0,  .5,  .5], RGBColor[ .5,  .5,  .5], 
                  RGBColor[ .25, 0, 0], RGBColor[0,  .25, 0], 
                  RGBColor[0, 0,  .5], RGBColor[ .25,  .25, 0],  
                  RGBColor[ .25, 0,  .25], RGBColor[0,  .25,  .25], 
                  RGBColor[ .25,  .25,  .25]}; 

lists = {{$points4[[1]]}}; 
For[
                i = 2, i ≤ resonance, i++, 
                lists = 
                  Append[lists, {$points4[[i]]}]]; 

For[i = (resonance + 1), 
                i ≤  Dimensions[$points4][[1]], i++, 
idx  =  Mod[i, resonance]; 
If[
                  idx == 0, 
                  idx  =  resonance]; 
lists[[idx]] = 
                  Append[lists[[idx]], $points4[[i]]];
]; 

plots = {}; 
For[i = 1, 
                i ≤ resonance, i++, 
plots = 
                  Append[plots, 
                    ListPlot[lists[[i]], PlotJoined -> True, 
                      PlotStyle -> colors[[i]], 
                      DisplayFunction -> 
                        Identity]]; 
plots = 
                  Append[plots, 
                    ListPlot[lists[[i]], 
                      PlotStyle -> colors[[i]], 
                      DisplayFunction -> 
                        Identity]];
]; 
Show[plots, 
                DisplayFunction -> $DisplayFunction];
,  (* else,  
                just show all points *) 
ListPlot[$points4, 
                  PlotStyle -> 
                    RGBColor[0, 0, 
                      1]];
];
];

stepsize = 2.78452;  

    f4Calculate[stepsize];

cycleLength = 0;    
f4Plot[cycleLength];

stepsize = 2.51381;  

    f4Calculate[stepsize];

cycleLength = 0;    
f4Plot[cycleLength];

stepsize = 1.8899;  

    f4Calculate[stepsize];

cycleLength = 0;    

    f4Plot[cycleLength];

stepsize = 1.23044;  

    f4Calculate[stepsize];

cycleLength = 0;    

    f4Plot[cycleLength];

stepsize = 0.993579;  

    f4Calculate[stepsize];

cycleLength = 0;    

    f4Plot[cycleLength];