#!/usr/bin/octave -qf
output_precision=15;

UTFIL= ['tread_S1002_t33.0_EN13715.wheel'];
flange_thickness=     33.0;

de= 32.5 - flange_thickness;

  eval (['fid= fopen ("', UTFIL,'", "w");']);        % Open the file
  if (fid == -1)
    error ("create_tread: Can not open UTFIL\n");
  endif

X2=-32.158;     % Section I to B1 without chamfer
Y2= -0.78;
X1=-70;
Y1= Y2+0.067*(X1-X2);
dx=0.02;
v_ut= create_line (X1, Y1, X2, Y2, dx);

for i= 1:length(v_ut)
 fprintf(fid, "%f  %f\n", v_ut(i,1),v_ut(i,2));
end

 fprintf(fid, "-32.158 -.78\n");        % Section B1 to D0 (Nominal running radius)
 fprintf(fid, "-32.0  -.769\n");
 fprintf(fid, "-31.5  -.737\n");
 fprintf(fid, "-31.0  -.705\n");
 fprintf(fid, "-30.5  -.675\n");
 fprintf(fid, "-30.0  -.646\n");
 fprintf(fid, "-29.5  -.619\n");
 fprintf(fid, "-29.0  -.592\n");
 fprintf(fid, "-28.5  -.567\n");
 fprintf(fid, "-28.0  -.543\n");
 fprintf(fid, "-27.5  -.521\n");
 fprintf(fid, "-27.0  -.499\n");
 fprintf(fid, "-26.5  -.479\n");
 fprintf(fid, "-26.0  -.460\n");
 fprintf(fid, "-25.5  -.443\n");
 fprintf(fid, "-25.0  -.426\n");
 fprintf(fid, "-24.5  -.410\n");
 fprintf(fid, "-24.0  -.396\n");
 fprintf(fid, "-23.5  -.382\n");
 fprintf(fid, "-23.0  -.370\n");
 fprintf(fid, "-22.5  -.358\n");
 fprintf(fid, "-22.0  -.348\n");
 fprintf(fid, "-21.5  -.338\n");
 fprintf(fid, "-21.0  -.328\n");
 fprintf(fid, "-20.5  -.320\n");
 fprintf(fid, "-20.0  -.312\n");
 fprintf(fid, "-19.5  -.304\n");
 fprintf(fid, "-19.0  -.298\n");
 fprintf(fid, "-18.5  -.291\n");
 fprintf(fid, "-18.0  -.285\n");
 fprintf(fid, "-17.5  -.280\n");
 fprintf(fid, "-17.0  -.274\n");
 fprintf(fid, "-16.5  -.269\n");
 fprintf(fid, "-16.0  -.265\n");
 fprintf(fid, "-15.5  -.260\n");
 fprintf(fid, "-15.0  -.256\n");
 fprintf(fid, "-14.5  -.251\n");
 fprintf(fid, "-14.0  -.247\n");
 fprintf(fid, "-13.5  -.242\n");
 fprintf(fid, "-13.0  -.238\n");
 fprintf(fid, "-12.5  -.234\n");
 fprintf(fid, "-12.0  -.229\n");
 fprintf(fid, "-11.5  -.224\n");
 fprintf(fid, "-11.0  -.219\n");
 fprintf(fid, "-10.5  -.214\n");
 fprintf(fid, "-10.0  -.208\n");
 fprintf(fid, " -9.5  -.203\n");
 fprintf(fid, " -9.0  -.196\n");
 fprintf(fid, " -8.5  -.190\n");
 fprintf(fid, " -8.0  -.183\n");
 fprintf(fid, " -7.5  -.176\n");
 fprintf(fid, " -7.0  -.168\n");
 fprintf(fid, " -6.5  -.160\n");
 fprintf(fid, " -6.0  -.151\n");
 fprintf(fid, " -5.5  -.142\n");
 fprintf(fid, " -5.0  -.132\n");
 fprintf(fid, " -4.5  -.122\n");
 fprintf(fid, " -4.0  -.111\n");
 fprintf(fid, " -3.5  -.100\n");
 fprintf(fid, " -3.0  -.087\n");
 fprintf(fid, " -2.5  -.075\n");
 fprintf(fid, " -2.0  -.061\n");
 fprintf(fid, " -1.5  -.047\n");
 fprintf(fid, " -1.0  -.032\n");
 fprintf(fid, " -0.5  -.016\n");
 fprintf(fid, "  0.0   .0\n");

% Section D0 to T1 is missing when flange thickness= 33;

v_ut= [
 0.5  0.001
 1.0  0.003
 1.5  0.005
 2.0  0.007
 2.5  0.009
 3.0  0.011
 3.5  0.013
 4.0  0.015
 4.5  0.017
 5.0  0.035
 5.5  0.054
 6.0  0.074
 6.5  0.094
 7.0  0.116
 7.5  0.138
 8.0  0.161
 8.5  0.185
 9.0  0.211
 9.5  0.237
10.0  0.264
10.5  0.292
11.0  0.322
11.5  0.352
12.0  0.384
12.5  0.417
13.0  0.451
13.5  0.486
14.0  0.523
14.5  0.561
15.0  0.600
15.5  0.640
16.0  0.682
16.5  0.726
17.0  0.771
17.5  0.818
18.0  0.866
18.5  0.916
19.0  0.967
19.5  1.021
20.0  1.076
20.5  1.134
21.0  1.193
21.5  1.254
22.0  1.318
22.5  1.384
23.0  1.452
23.5  1.523
24.0  1.597
24.5  1.673
25.0  1.752
25.5  1.834
26.0  1.920
26.5  2.008
27.0  2.101
27.5  2.197
28.0  2.297
28.5  2.401
29.0  2.509
29.5  2.623
30.0  2.741
30.5  2.865
31.0  2.994
31.5  3.129
32.0  3.270
32.5  3.419
33.0  3.576
33.5  3.743
34.0  3.922
34.5  4.114
35.0  4.321
35.5  4.547
36.0  4.793
36.5  5.062
37.0  5.357
37.5  5.681
38.0  6.038
38.5  6.432
39.0  6.867
];

istart= round(2.*(flange_thickness-28.5)) + 1;
ix= 0;
for iy= istart:77
 ++ix;
 fprintf(fid, "%f  %f\n", v_ut(ix,1),v_ut(iy,2));
end

fclose (fid);
