cl1=200;
intpx=1700;
intpy=1600;
xhea=140;
yhea=133;
lpal=2000;

Point(1) = {0, 0, 0, cl1};
//Z at 1000 so, Y at 2000 se, X at 3000 ne, W at 4000 no
//entre par l'ouest
Function pointAtNivo
  Point(1000+i) = {intpx/2+xhea/2,intpy/2+yhea/2, nivo, cl1};
  Point(1100+i) = {160,intpy/2+yhea/2, nivo, cl1};
  Point(1900+i) = {intpx/2+xhea/2+lpal,intpy/2+yhea/2, nivo, cl1};
  Point(2000+i) = {-intpx/2-xhea/2,intpy/2+yhea/2, nivo, cl1};
  Point(3000+i) = {-intpx/2-xhea/2,-intpy/2+yhea/2, nivo, cl1};
  Point(3100+i) = {-655,-intpy/2+yhea/2, nivo, cl1};
  Point(3200+i) = {655,-intpy/2+yhea/2, nivo, cl1};
  Point(4000+i) = {intpx/2+xhea/2,-intpy/2+yhea/2, nivo, cl1};
  Point(4900+i) = {intpx/2+xhea/2+lpal,-intpy/2+yhea/2, nivo, cl1};


Return

Function lineAtNivo
  Line(1000*i+1)={1000*1+i, 1000*1+100+i};
  a[]=(1000*i+1);
  horz[]+=a[];
  Line(1000*i+2)={1000*1+100+i, 1000+1000*1+i};
  a[]=(1000*i+2);
  horz[]+=a[];
  Line(1000*i+3)={2000*1+i, 1000+2000*1+i};
  a[]=(1000*i+3);
  horz[]+=a[];
  Line(1000*i+4)={3000*1+i, 3000*1+100+i};
  a[]=(1000*i+4);
  horz[]+=a[];
  Line(1000*i+5)={3000*1+100+i, 3000*1+200+i};
  a[]=(1000*i+5);
  horz[]+=a[];
  Line(1000*i+6)={3000*1+200+i, 1000+3000*1+i};
  a[]=(1000*i+6);
  horz[]+=a[];
  Line(1000*i+7)={1000*4+i, 1000+i};
  a[]=(1000*i+7);
  horz[]+=a[];
  Line(1000*i+100)={1000*1+900+i, 1000*1+i};
  a[]=(1000*i+100);
  pal[]+=a[];
  Line(1000*i+200)={1000*4+900+i, 1000*4+i};
  a[]=(1000*i+200);
  pal[]+=a[];

Return

Function lineBelowNivo
  For j In {1:4}
	Line(1100*i+j)={1000*j+i-1, 1000*j+i};
	a[]=(1100*i+j);
	If (j==1)
	  vertne[]+=a[];
	EndIf
	If (j==2)
	  vertno[]+=a[];
	EndIf
	If (j==3)
	  vertso[]+=a[];
	EndIf
	If (j==4)
	  vertse[]+=a[];
	EndIf
  EndFor
Return

nivo=0;
i=1;
Call pointAtNivo;

nivo=nivo+2400;
i=i+1;
Call pointAtNivo;
Call lineAtNivo;
Call lineBelowNivo;

nivo=nivo+2400;
i=i+1;
Call pointAtNivo;
Call lineAtNivo;
Call lineBelowNivo;

nivo=nivo+2400;
i=i+1;
Call pointAtNivo;
Call lineAtNivo;
Delete {
  Line{4100, 4200};
}
Call lineBelowNivo;

nivo=nivo+800;
i=i+1;
Call pointAtNivo;
Call lineAtNivo;
Call lineBelowNivo;

nivo=nivo+1630;
i=i+1;
Call pointAtNivo;
//Call lineAtNivo;
Call lineBelowNivo;

nivo=nivo+790;
i=i+1;
Call pointAtNivo;
Call lineAtNivo;
Delete {
  Line{7100, 7200};
}
Call lineBelowNivo;

nivo=nivo+700;
i=i+1;
Call pointAtNivo;
//Call lineAtNivo;
Call lineBelowNivo;

nivo=nivo+370+xhea/2;
i=i+1;
Point(1000+i) = {intpx/2+xhea/2,intpy/2+yhea/2, nivo, cl1};
Point(1100+i) = {890+xhea/2-600,intpy/2+yhea/2, nivo, cl1};
Point(1900+i) = {intpx/2+xhea/2+lpal,intpy/2+yhea/2, nivo, cl1};
Point(2000+i) = {-intpx/2-xhea/2,intpy/2+yhea/2, nivo, cl1};
Point(2100+i) = {-intpx/2-xhea/2,90+600, nivo, cl1};
Point(2200+i) = {-intpx/2-xhea/2,90, nivo, cl1};
Point(2300+i) = {-intpx/2-xhea/2,90-600, nivo, cl1};
Point(3000+i) = {-intpx/2-xhea/2,-intpy/2+yhea/2, nivo, cl1};
Point(3100+i) = {-655,-intpy/2+yhea/2, nivo, cl1};
Point(3200+i) = {655,-intpy/2+yhea/2, nivo, cl1};
Point(4000+i) = {intpx/2+xhea/2,-intpy/2+yhea/2, nivo, cl1};
Point(4900+i) = {intpx/2+xhea/2+lpal,-intpy/2+yhea/2, nivo, cl1};
Point(4100+i) = {intpx/2+xhea/2,90+600, nivo, cl1};
Point(4200+i) = {intpx/2+xhea/2,90, nivo, cl1};
Point(4300+i) = {intpx/2+xhea/2,90-600, nivo, cl1};
Point(2110+i) = {0,90+600, nivo, cl1};
Point(2210+i) = {0,90, nivo, cl1};
Point(2310+i) = {0,90-600, nivo, cl1};


Line(1000*i+1)={1000*1+i, 1000*1+100+i};
a[]=(1000*i+1);
horz[]+=a[];
Line(1000*i+2)={1000*1+100+i, 1000+1000*1+i};
a[]=(1000*i+2);
horz[]+=a[];
Line(1000*i+3)={2000*1+i, 2000*1+100+i};
a[]=(1000*i+3);
horz[]+=a[];
Line(1000*i+4)={2000*1+100+i, 2000*1+200+i};
a[]=(1000*i+4);
horz[]+=a[];
Line(1000*i+5)={2000*1+200+i, 2000*1+300+i};
a[]=(1000*i+5);
horz[]+=a[];
Line(1000*i+6)={2000*1+300+i, 1000+2000*1+i};
a[]=(1000*i+6);
horz[]+=a[];
Line(1000*i+7)={3000*1+i, 3000*1+100+i};
a[]=(1000*i+7);
horz[]+=a[];
Line(1000*i+8)={3000*1+100+i, 3000*1+200+i};
a[]=(1000*i+8);
horz[]+=a[];
Line(1000*i+9)={3000*1+200+i, 1000+3000*1+i};
a[]=(1000*i+9);
horz[]+=a[];
Line(1000*i+10)={4000*1+i, 4000*1+300+i};
a[]=(1000*i+10);
horz[]+=a[];
Line(1000*i+11)={4000*1+300+i, 4000*1+200+i};
a[]=(1000*i+11);
horz[]+=a[];
Line(1000*i+12)={4000*1+200+i, 4000*1+100+i};
a[]=(1000*i+12);
horz[]+=a[];
Line(1000*i+13)={4000*1+100+i, 1000+i};
a[]=(1000*i+13);
horz[]+=a[];
Line(1000*i+21)={2000*1+100+i, 2000*1+110+i};
a[]=(1000*i+21);
horz[]+=a[];
Line(1000*i+22)={2000*1+110+i, 4000*1+100+i};
a[]=(1000*i+22);
horz[]+=a[];
Line(1000*i+23)={2000*1+200+i, 2000*1+210+i};
a[]=(1000*i+23);
horz[]+=a[];
Line(1000*i+24)={2000*1+210+i, 4000*1+200+i};
a[]=(1000*i+24);
horz[]+=a[];
Line(1000*i+25)={2000*1+300+i, 2000*1+310+i};
a[]=(1000*i+25);
horz[]+=a[];
Line(1000*i+26)={2000*1+310+i, 4000*1+300+i};
a[]=(1000*i+26);
horz[]+=a[];
Call lineBelowNivo;


Physical Point("sol") = {1001, 2001, 3001, 4001};
Physical Point("sortie") = {1902, 4902, 1903, 4903, 1905, 4905};
Physical Point("chtop1") = {2119};
Physical Point("chtop2") = {2219};
Physical Point("chtop3") = {2319};
Physical Line("vertso") = vertso[];
Physical Line("vertse") = vertse[];
Physical Line("vertne") = vertne[];
Physical Line("vertno") = vertno[];
Physical Line("horz") = horz[];
Physical Line("pal") = pal[];

