#include <stdio.h>
#include <stdlib.h>
#define DB double
#define DO(x,y) for(x=0;x<y;x++)
#include<complex>
typedef std::complex<double> z_type;
#define Re(x) x.real()
#define Im(x) x.imag()
#define I z_type(0.,1.)
#include "ado.cin"
#include "ContoArrayJump1.cin"

z_type F(z_type z) {return sqrt(z);}

int main(){ int j,k,m,n; DB x,y, p,q, t; z_type z,c,d, cu,cd;
int M=41,M1=M+1;
int N=40,N1=N+1;
DB X[M1],Y[N1]; DB *g, *f, *w; // w is working array.
g=(DB *)malloc((size_t)((M1*N1)*sizeof(DB)));
f=(DB *)malloc((size_t)((M1*N1)*sizeof(DB)));
w=(DB *)malloc((size_t)((M1*N1)*sizeof(DB)));
char v[M1*N1]; // v is working array
//FILE *o;o=fopen("QuadraticMapByChatGPTtest11.eps","w");  ado(o,422,422);
//FILE *o;o=fopen("F1zChatGPTtest.eps","w");  ado(o,422,422);
//FILE *o;o=fopen("09.eps","w");  ado(o,422,422);
FILE *o;o=fopen("16.eps","w");  ado(o,422,422);
fprintf(o,"210 210 translate\n 100 100 scale\n");
fprintf(o,"1 setlinejoin 2 setlinecap\n");
fprintf(o,"/W { setlinewidth } def\n");
fprintf(o,"/RGB { setrgbcolor } def\n");
fprintf(o,"/S { stroke } def\n");
#define M(x,y) fprintf(o,"%6.3f %6.3f M\n",0.+x,0.+y); 
#define L(x,y) fprintf(o,"%6.3f %6.3f L\n",0.+x,0.+y); 
//DO(m,M1) X[m]=-2+.1*(m-.4);
DO(m,M1) X[m]=-2+.1*(m-.4);
//DO(n,N1) Y[n]=-2+.1*(n-.3); 
DO(n,N1) Y[n]=-2+.1*n; 
for(m=-2;m<3;m++){M(m,-2) L(m,2)}
for(n=-2;n<3;n++){M(-2,n) L(2,n)}
 fprintf(o,".01 W 0 0 0 RGB S\n");
DO(m,M1)DO(n,N1){      g[m*N1+n]=999;
                       f[m*N1+n]=999;}
DO(m,M1){x=X[m]; if(m/10*10==m) printf("x=%6.3f\n",x);
DO(n,N1){y=Y[n]; z=z_type(x,y); //if(abs(z+2.)>.019)
  c=F(z);
 p=Re(c); q=Im(c); if(p>-99 && p<99 )
//{ g[m*M1+n]=p;f[m*NM1+n]=q;}
{ g[m+M1*n]=p;f[m+M1*n]=q;}
       }}
fprintf(o,"1 setlinejoin 1 setlinecap\n"); p=.4;q=.2;
fprintf(o,".01 W 0 .6 0 RGB\n"); for(m=-3;m<3;m++)for(n=1;n<10;n+=1)ContoArrayJump1(o,f,X,Y,M,N,(m+.1*n),q);
fprintf(o,".01 W .8 0 0 RGB\n"); for(m=0;m<3;m++) for(n=1;n<10;n+=1)ContoArrayJump1(o,g,X,Y,M,N,-(m+.1*n),q);
fprintf(o,".01 W 0 0 .8 RGB\n"); for(m=0;m<3;m++) for(n=1;n<10;n+=1)ContoArrayJump1(o,g,X,Y,M,N, (m+.1*n),q);
fprintf(o,".02 W 0 0 .8 RGB\n"); for(m= 1;m<5;m++) ContoArrayJump1(o,f,X,Y,M,N, (0.+m),p); 
fprintf(o,".02 W .8 0 0 RGB\n"); for(m= 1;m<5;m++) ContoArrayJump1(o,f,X,Y,M,N, (0.-m),p);
fprintf(o,".02 W .5 0 .5 RGB\n");                  ContoArrayJump1(o,f,X,Y,M,N, (0.  ),p);
fprintf(o,".02 W 0 0 0 RGB\n"); for(m=-10;m<11;m++)ContoArrayJump1(o,g,X,Y,M,N,(0.+m),p);
fprintf(o,"showpage\n"); fprintf(o,"%c%cTrailer\n",'%','%');
fclose(o);  free(f); free(g); free(w);
      system("epstopdf 16.eps"); 
      system(    "open 16.pdf"); //for macintosh
}
