// compile as: // cc -lm -o dxf2mvg dxf2mvg.c #include #include #include #include FILE*fi,*fo; #define DEFAULT_DPI 1000 int DPI=DEFAULT_DPI; #define DEFAULT_STROKEWID 2 #define DEFAULT_OUTFILE "dxf.png" #define DEFAULT_LINECOL "black" #define DEFAULT_BGCOL "white" #define DEFAULT_MARG_L 30 #define DEFAULT_MARG_R 30 #define DEFAULT_MARG_T 30 #define DEFAULT_MARG_B 30 #define DEFAULT_FONTSIZE 10 #define DEFAULT_FONTCOLOR "red" #define COLLEN 32 #define DEFAULT_PRECISION 1 #define DEFAULT_FONTOFFS 3 int fontsize=DEFAULT_FONTSIZE; int fontoffsx=DEFAULT_FONTOFFS; int fontoffsy=DEFAULT_FONTOFFS; char fontcolor[COLLEN+2]=DEFAULT_FONTCOLOR; int showcoords=0; int pixelcoords=0; int coordcenterref=0; char textxysep[COLLEN+2]="\n"; char textpartssep[COLLEN+2]="\n"; char sizexysep[COLLEN+2]="\n"; int canvasaddx=0; int canvasaddy=0; int canvasaddl=0; int canvasaddt=0; int coordprec=DEFAULT_PRECISION; double crosscoordmaxx=0,crosscoordmaxy=0; double multix=1.0; double multiy=1.0; double addx=0.0; double addy=0.0; double preaddx=0.0; double preaddy=0.0; char bgcol[COLLEN+2]=DEFAULT_BGCOL; char linecol[COLLEN+2]=DEFAULT_LINECOL; char crosscol[COLLEN+2]=DEFAULT_LINECOL; char movecol1[COLLEN+2]="yellow"; char movecol2[COLLEN+2]="orange"; char movecol3[COLLEN+2]="green"; int strokewid=DEFAULT_STROKEWID; int showmoves=0; int showentities=0; int showentitiesall=0; int fliphorz=0; int flipvert=0; int x_fliphorz=0; int x_flipvert=0; int tozero=0; int x_tozero=0; int showcrosscoord=0; // show coordinates of cross mark centers int showlinecoord=1; // show coordinates of individual line endpoints - default 1, disabling in options int showcrosssize=0; // show dimensions of cross-center polylines int showonlycrosssize=0;// show dimensions, suppress coordinates int showcrossdimhalf=0; // show half-size of dimensions, radius instead of diameter int nomvg=0; // suppress MVG output, for other things int outputcoordvars=0; // output coordinates of crosses as bash variables int outputcoordcompact=0; char movecol[COLLEN+2]; long linenum=0; long movenum=0; char*outfile=DEFAULT_OUTFILE; int pixelsx,pixelsy; double minx,maxx,miny,maxy; long lines=0; long moves=0; long lsegments=0; long polylines=0; double getdouble() { char s[512]; fgets(s,510,fi); return atof(s); } double str2x(char*s) { double d; d=atof(s); if(x_tozero)d=d-minx; d=(d+preaddx)*multix; if(x_fliphorz)d=maxx-d; d=d+addx; return d; } double str2y(char*s) { double d; d=atof(s); if(x_tozero)d=d-miny; d=(d+preaddy)*multiy; if(x_flipvert)d=maxy-d; d=d+addy; return d; } int mm2pix(double d) { return round(d/25.4*DPI); } #define MAXXY 999999999 #define LTYPE_NONE 0 #define LTYPE_LINE 1 #define LTYPE_POLY 2 void setminmaxx(double d){if(dmaxx)maxx=d;} void setminmaxy(double d){if(dmaxy)maxy=d;} void scanfile() { char s1[512],s2[512],*sp; int i,t; double d; double x1,y1,x2,y2,xo=0,yo=0; int ltype=0; int movecheck=0; long polylen; minx=MAXXY;maxx=-MAXXY; miny=MAXXY;maxy=-MAXXY; rewind(fi); while(!feof(fi)){ fgets(s1,510,fi);sp=strchr(s1,0x0d);if(sp)sp[0]=0; fgets(s2,510,fi);sp=strchr(s2,0x0d);if(sp)sp[0]=0; if(ferror(fi)){fprintf(stderr,"[Error %i at read]",ferror(fi));return;} i=atoi(s1); //if(i==0)fprintf(stderr,"\n"); //fprintf(stderr,"#DXF: %i:%s\n",i,s2); switch(i){ //10=x1, 11=x2, 20=y1, 21=y2 case 0: if(!strncmp(s2,"VERTEX",6)){continue;} ltype=0; if(!strncmp(s2,"LINE",4)){ltype=LTYPE_LINE;lines++;} if(!strncmp(s2,"LWPOLYLINE",10)){ltype=LTYPE_POLY;polylines++;polylen=0;} if(!strncmp(s2,"POLYLINE",8)) {ltype=LTYPE_POLY;polylines++;polylen=0;} movecheck=0; break; /* case 10:if(ltype==0)break;d=str2x(s2);setminmaxx(d);x1=d; break; case 11:if(ltype==0)break;d=str2x(s2);setminmaxx(d);x2=d; break; case 20:if(ltype==0)break;d=str2x(s2);setminmaxy(d);y1=d; break; case 21:if(ltype==0)break;d=str2x(s2);setminmaxy(d);y2=d;lsegments++; if(!movecheck){ //fprintf(stderr," %f:%f %f:%f %f:%f\n",xo,yo,x1,y1,x2,y2); if((xo!=x1)||(yo!=y1))moves++; //if((xo!=x1)||(yo!=y1))fprintf(stderr," MOVE\n"); xo=x2;yo=y2; movecheck=1;} break; */ case 10:if(ltype==0)break;d=str2x(s2);setminmaxx(d); if(ltype==LTYPE_POLY){ if(polylen)x2=d;else x1=d; if(polylen)xo=d; //polylen++; }else x1=d; break; case 11:if(ltype==0)break;d=str2x(s2);setminmaxx(d);x2=d; break; case 20:if(ltype==0)break;d=str2x(s2);setminmaxy(d); if(ltype==LTYPE_POLY){ if(polylen)y2=d;else y1=d; if(polylen)yo=d; if(polylen)lsegments++; polylen++; //movecheck=0; if(!movecheck){// check if. //fprintf(stderr," %f:%f %f:%f %f:%f\n",xo,yo,x1,y1,x2,y2); if((xo!=x1)||(yo!=y1))moves++; //if((xo!=x1)||(yo!=y1))fprintf(stderr," MOVE\n"); xo=x2;yo=y2; movecheck=1;} }else y1=d; break; case 21:if(ltype==0)break;d=str2x(s2);setminmaxy(d);y2=d;lsegments++; if(!movecheck){ //fprintf(stderr," %f:%f %f:%f %f:%f\n",xo,yo,x1,y1,x2,y2); if((xo!=x1)||(yo!=y1))moves++; //if((xo!=x1)||(yo!=y1))fprintf(stderr," MOVE\n"); xo=x2;yo=y2; movecheck=1;} break; } // if((i==10)||(i==11)){d=str2x(s2);if(dmaxx)maxx=d;} // if((i==20)||(i==21)){d=str2y(s2);if(dmaxy)maxy=d;} // if(i==21)lsegments++; // if(i==0)ltype=0; // if(!strncmp(s2,"LINE",4)){ltype=LTYPE_LINE;lines++;} // if(!strncmp(s2,"LWPOLYLINE",10)){ltype=LTYPE_POLY;polylines++;} if(i==999){ double d; if(!strncmp(s2,"CROSSCOORDMAXX:",15))crosscoordmaxx=atof(s2+15); if(!strncmp(s2,"CROSSCOORDMAXY:",15))crosscoordmaxy=atof(s2+15); } } //overrride of maximum dimensions by crosses if(crosscoordmaxx>maxx)maxx=crosscoordmaxx; if(crosscoordmaxy>maxy)maxy=crosscoordmaxy; pixelsx=mm2pix(maxx)+strokewid; pixelsy=mm2pix(maxy)+strokewid; if(tozero){pixelsx-=mm2pix(minx);pixelsy-=mm2pix(miny);} } void printxycoord_o(double x,double y,int txtox,int txtoy,int showcoords,int showheigwid,double wid,double heig) { double showx,showy; char fmt[32]=""; showx=x;showy=y; char scoord[64]="",swide[64]="",ssep[32]=""; if(showcoords){ // snprintf(fmt,31,"text %%i,%%i '%%.%if%%s%%.%if'\n",coordprec,coordprec); snprintf(fmt,31,"%%.%if%%s%%.%if",coordprec,coordprec); // 999|CROSSCOORD:28.824385,19.141370 POLYDIM:57.648770,38.282740 len=1.500000 segnum=55 minmax=0.000000,-0.000000,57.648770,38.282740 if(coordcenterref){showx=showx-maxx/2;showy=showy-maxy/2;} if(pixelcoords)snprintf(scoord,63,"%i%s%i",mm2pix(showx),textxysep,mm2pix(showy)); else snprintf(scoord,63,fmt,showx,textxysep,showy); } if(showheigwid){ snprintf(fmt,31,"W:%%.%if%%sH:%%.%if",coordprec,coordprec); if(pixelcoords)snprintf(swide,63,"W:%i%sH:%i",mm2pix(wid),sizexysep,mm2pix(heig)); else snprintf(swide,63,fmt,wid,textxysep,heig); } if(showcoords)if(showheigwid)strcpy(ssep,textxysep); printf("text %i,%i '%s%s%s'\n",txtox+mm2pix(x)+canvasaddl,txtoy+mm2pix(y)+canvasaddt,scoord,ssep,swide); /* if(showcoords){ if(s[0]){strcat(fmt,"%s");} if(coordcenterref){showx=showx-maxx/2;showy=showy-maxy/2;} if(pixelcoords)printf("text %i,%i '%i%s%i%s'\n",txtox+mm2pix(x)+canvasaddl,txtoy+mm2pix(y)+canvasaddt,mm2pix(showx),textxysep,mm2pix(showy),s); // else printf("text %i,%i '%.2f%s%.2f'\n",mm2pix(x)+canvasaddl,mm2pix(y)+canvasaddt,showx,textxysep,showy); else printf(fmt,,s); } else{snprintf(fmt,31,"text %%i,%%i '%%s'\n");} }*/ } void printxycoord(double x,double y) { printxycoord_o(x,y,fontoffsx,fontoffsy,1,0,0.0,0.0); } void printxycoordS(double x,double y,double wid,double heig) { //fprintf(stderr,"XXXXXXXXXXXXX\n"); int coords=1; if(showonlycrosssize)coords=0; if(showcrossdimhalf){wid/=2;heig/=2;} printxycoord_o(x,y,fontoffsx,fontoffsy,coords,showcrosssize,wid,heig); //fprintf(stderr,"XXXXXXXXXXXXX\n"); } void printcoordvars(double showx,double showy,double wid,double heig,int n) { if(showcrossdimhalf){wid/=2;heig/=2;} if(coordcenterref){showx=showx-maxx/2;showy=showy-maxy/2;} if(outputcoordcompact){ if(pixelcoords){ printf("co%02ix=%i;\t",n,mm2pix(showx)); printf("co%02iy=%i;\t",n,mm2pix(showy)); printf("co%02iw=%i;\t",n,mm2pix(wid)); printf("co%02ih=%i;\t",n,mm2pix(heig)); }else{ printf("co%02ix=%f;\t",n,showx); printf("co%02iy=%f;\t",n,showy); printf("co%02iw=%f;\t",n,wid); printf("co%02ih=%f;\t",n,heig); } printf("#"); } else{ if(pixelcoords){ printf("co%02ix=%i\n",n,mm2pix(showx)); printf("co%02iy=%i\n",n,mm2pix(showy)); printf("co%02iw=%i\n",n,mm2pix(wid)); printf("co%02ih=%i\n",n,mm2pix(heig)); }else{ printf("co%02ix=%f\n",n,showx); printf("co%02iy=%f\n",n,showy); printf("co%02iw=%f\n",n,wid); printf("co%02ih=%f\n",n,heig); } } printf("\n"); } void do_outputcoordvars(FILE*f){ fprintf(f,"#DXF coordinate output variables\n"); fprintf(f,"#Dimensions: ");if(showcrossdimhalf)printf("halved\n");else printf("full\n"); fprintf(f,"#Units: ");if(pixelcoords)printf("pixels\n");else printf("millimeters\n"); if(pixelcoords) fprintf(f,"#DPI: %i\n",DPI); fprintf(f,"#CoordsRelTo: ");if(coordcenterref)printf("center\n");else printf("left-top\n"); fprintf(f,"\n"); } void scanfile_printcoords() { char s1[512],s2[512],*sp; int i,t; int iscross=0; double d; double x,y; int crossnum=0; rewind(fi); if(!nomvg){printf("fill '%s'\n",fontcolor); printf("stroke '%s'\n",fontcolor); printf("stroke-width 0\n"); printf("font-size %i\n",fontsize); printf("gravity northwest\n");} else if(outputcoordvars){ do_outputcoordvars(stdout); // printf("#DXF coordinate output variables\n"); // printf("#Dimensions: ");if(showcrossdimhalf)printf("halved\n");else printf("full\n"); // printf("#Units: ");if(pixelcoords)printf("pixels\n");else printf("millimeters\n"); // if(pixelcoords) // printf("#DPI: %i\n",DPI); // printf("#CoordsRelTo: ");if(coordcenterref)printf("center\n");else printf("left-top\n"); // printf("\n"); } while(!feof(fi)){ fgets(s1,510,fi);sp=strchr(s1,0x0d);if(sp)sp[0]=0; fgets(s2,510,fi);sp=strchr(s2,0x0d);if(sp)sp[0]=0;sp=strchr(s2,0x0a);if(sp)sp[0]=0; if(ferror(fi)){fprintf(stderr,"[Error %i at read]",ferror(fi));return;} i=atoi(s1); if(i==999){ if(!strcmp(s2,"----CROSSBEGIN"))iscross=1;else if(!strcmp(s2,"----CROSSEND"))iscross=0; } if(showcrosscoord){ if(i==999){ if(!strncmp("CROSSCOORD:",s2,11)){ if(!nomvg)printf("#COMMENT: %s\n",s2); double cx,cy,wid=-1.1,heig=-1.1; char*sp,*sp1,*sp2,*sp3; sp=strchr(s2,':');sp1=strchr(s2,','); if(sp)if(sp1){cx=str2x(sp+1);cy=str2y(sp1+1); //printxycoord(cx,cy); if(sp1){sp2=strstr(sp1,"POLYDIM:");if(sp2){ sp2=strchr(sp2,':');sp2++; sp3=strchr(sp2,',');if(sp3){ sp3++;wid=atof(sp2);heig=atof(sp3); }}} if(!nomvg)printxycoordS(cx,cy,wid,heig); if(nomvg)if(outputcoordvars) { if(!outputcoordcompact)printf("#%s\n",s2); printcoordvars(cx,cy,wid,heig,crossnum); } crossnum++; } } } } //fprintf(stderr,"%i %i %i %s\n",showlinecoord,iscross,i,s2); if(showlinecoord)if(!iscross) { if((i==10)||(i==11)){x=str2x(s2);} if((i==20)||(i==21)){y=str2y(s2); if(!nomvg)printxycoord(x,y); } } } pixelsx=mm2pix(maxx)+strokewid; pixelsy=mm2pix(maxy)+strokewid; } void setmovecolor(){ // if(movenum&0x01)strcpy(movecol,movecol1); // else strcpy(movecol,movecol2); long frac=(255*movenum/moves); // if(frac>255)frac=255; //sprintf(movecol,"#%02x%02x%02x",255-frac,0,frac); sprintf(movecol,"#%02x%02x%02x",0,frac,255-frac); } void printmoveline(double x1,double y1,double x2,double y2) { //if(movecol[0]==0)return; if(!showmoves)return; //if(x1==y1)if(x2==y2)return; // HOW CAN I BE THIS DUMB!?!?!? if(x1==x2)if(y1==y2)return; //if(movecol1[0]) setmovecolor(); printf("stroke '%s' line %li,%li %li,%li stroke '%s'\n",movecol,mm2pix(x1)+canvasaddl,mm2pix(y1)+canvasaddt,mm2pix(x2)+canvasaddl,mm2pix(y2)+canvasaddt,linecol); linenum++; movenum++; } void printline(double x1,double y1,double x2,double y2) { if(x1==x2)if(y1==y2)return; if(linenum==0)printmoveline(0,0,x1,x2); printf(" line %li,%li %li,%li\n",mm2pix(x1)+canvasaddl,mm2pix(y1)+canvasaddt,mm2pix(x2)+canvasaddl,mm2pix(y2)+canvasaddt); linenum++; } #define MAXDXFLINEDESC 1024 char dxflinedesc[MAXDXFLINEDESC]; void dxflinedesc_clear(){ dxflinedesc[0]=0; } void dxflinedesc_print(){ printf("##DXF: %s\n",dxflinedesc); dxflinedesc_clear(); } void dxflinedesc_addstr(char*s){ strncat(dxflinedesc,s,MAXDXFLINEDESC-1); dxflinedesc[MAXDXFLINEDESC-1]=0; } void dxflinedesc_addparm(char*s1,char*s2){ char s[255]; snprintf(s,255," %s=%s",s1,s2); strncat(dxflinedesc,s,MAXDXFLINEDESC-1); dxflinedesc[MAXDXFLINEDESC-1]=0; } void process_printstat(FILE*f){ fprintf(f,"#box %f %f %f %f\n",minx,miny,maxx,maxy); // printf("#viewbox %li %li %li %li\n",mm2pix(minx),mm2pix(miny),mm2pix(maxx),mm2pix(maxy)); fprintf(f,"##xysize %lix%li\n",pixelsx+canvasaddx+canvasaddl,pixelsy+canvasaddy+canvasaddt); fprintf(f,"##DPI %i\n",DPI); fprintf(f,"##BGCOL %s\n",bgcol); if(outfile && outfile[0])fprintf(f,"##outfile %s\n",outfile); else fprintf(f,"##outfile %s\n",DEFAULT_OUTFILE); fprintf(f,"\n"); } void processfile() { char s1[512],s2[512],*sp; int i,t; double x1=0,y1=0,x2=0,y2=0,xo=0,yo=0; int isline=0,ispoly=0; int polyseg=0; int iscross=0; x_fliphorz=fliphorz;x_flipvert=flipvert;x_tozero=tozero; process_printstat(stdout); // printf("#box %f %f %f %f\n",minx,miny,maxx,maxy); //// printf("#viewbox %li %li %li %li\n",mm2pix(minx),mm2pix(miny),mm2pix(maxx),mm2pix(maxy)); // printf("##xysize %lix%li\n",pixelsx+canvasaddx+canvasaddl,pixelsy+canvasaddy+canvasaddt); // printf("##DPI %i\n",DPI); // printf("##BGCOL %s\n",bgcol); // if(outfile && outfile[0])printf("##outfile %s\n",outfile); // else printf("##outfile %s\n",DEFAULT_OUTFILE); // printf("\n"); printf("stroke %s stroke-width %i\n",linecol,strokewid); rewind(fi); while(!feof(fi)){ fgets(s1,510,fi);sp=strchr(s1,0x0d);if(sp)sp[0]=0;sp=strchr(s1,0x0a);if(sp)sp[0]=0; fgets(s2,510,fi);sp=strchr(s2,0x0d);if(sp)sp[0]=0;sp=strchr(s2,0x0a);if(sp)sp[0]=0; if(ferror(fi)){fprintf(stderr,"[Error %i at read]",ferror(fi));return;} i=atoi(s1); if(showentitiesall){if(i==0)printf("\n"); printf("#DXF: %s:%s\n",s1,s2);} if(i==0){if(showentities)printf("#%s\n",s2); if(!strcmp(s2,"VERTEX")){continue;} if(!strcmp(s2,"LINE")){isline=1;ispoly=0;} else if(!strcmp(s2,"LWPOLYLINE")){ispoly=1;isline=0;polyseg=0;} else if(!strcmp(s2,"POLYLINE")){ispoly=1;isline=0;polyseg=0;} else {isline=0;ispoly=0;} } if(i==999){ if(!strcmp(s2,"----CROSSBEGIN")){iscross=1;printf("stroke '%s'\n",crosscol);} else if(!strcmp(s2,"----CROSSEND")){iscross=0;printf("stroke '%s'\n",linecol);} } if(!isline)if(!ispoly)continue; if(isline){ if(i==10)x1=str2x(s2);else if(i==11)x2=str2x(s2);else if(i==20)y1=str2y(s2);else if(i==21)y2=str2y(s2); if(i==21){printmoveline(xo,yo,x1,y1); printline(x1,y1,x2,y2); xo=x2;yo=y2;} } else if(ispoly){ if(i==10)x1=str2x(s2);else if(i==20)y1=str2y(s2); if(i==20){if(polyseg==0)printmoveline(xo,yo,x1,y1); else printline(xo,yo,x1,y1); xo=x1;yo=y1; polyseg++; } } //if(!strncmp(s,"LINE",4)) } // if(showmoves){ // strcpy(movecol,"#0000FF"); // printmoveline(xo,yo,0,0); // } //if(showmoves)printf("stroke '%s' line %li,%li %li,%li\n",movecol3,mm2pix(xo),mm2pix(yo),0,0); // printf(" -density 1000 -units PixelsPerInch \\\n"); // printf("dxf.png\n"); } void printreport(){ fprintf(stderr,"lines: %li\n",lines); fprintf(stderr,"polylines: %li\n",polylines); fprintf(stderr,"segments: %li\n",lsegments); fprintf(stderr,"moves: %li\n",moves); fprintf(stderr,"\n"); } void help(int forwrapper) { char s[32]; if(!forwrapper) {strcpy(s,"dxf2mvg"); printf("dxf2mvg - converts an OpenSCAD DXF file to a ImageMagick MVG vector file\n" " (does not support entities other than LINE and LWPOLYLINE)\n"); }else {strcpy(s,"dxf2png.sh"); printf("dxf2png.sh - converts an OpenSCAD DXF file to a bitmap image file\n" " (does not support entities other than LINE and LWPOLYLINE)\n" " (calls dxf2mvg, uses a temporary ImageMagick MVG file in /tmp)\n"); } printf("\nUsage: %s [options] \n",s); printf(" Modes:\n"); if(forwrapper){ printf(" -tomvg output mvg to stdout instead of generating image (MUST be first argument)\n" " -nocomment disables adding commandline parameters as image comment (MUST be first argument)\n" " -q run quietly, don't say the output file (MUST be first argument, or second with nocomment)\n" ); } printf( " -coordvars do not generate graphics, instead output coords of cross marks and object dimensions\n" " in bash variable syntax (MUST be first argument)\n" " -coordvarsc same, in compact form (MUST be first argument)\n" " Dimensions and orientation:\n" " -s scaling factor\n" " -sx scaling factor horizontal\n" " -sy scaling factor vertical\n" " -dx shift horizontal\n" " -dy shift vertical\n" " -fh flip horizontal\n" " -fv flip vertical\n" " -z if offset, align to zero before shifting\n" " Output and appearance:\n" " -o output file name (default \"%s\")\n" " -d DPI (default %i)\n" " -lw line width (default %i)\n" " -lcol line color (default %s)\n" " -bgcol background color (default %s)\n" " -lm show movement lines\n" " -vc show DXF entities in MVG comments\n" " -margx add n pixels to the right side\n" " -margy add n pixels to the bottom side\n" " -margt add n pixels to the top side\n" " -margl add n pixels to the left side\n" " Annotations and coordinates:\n" " -cp show coordinates in pixels\n" " -cm show coordinates in millimeters, with %i decimal places\n" " -cmprec show coordinates in millimeters, with n decimal places\n" " -cc show coordinates relative to object center (default: object left top)\n" " -cr show coordinates of cross marks\n" " -cro show only coordinates of cross marks, not of lines\n" " -crdim show coords and polyline width/height at cross mark\n" " -crdimo show only dimensions of cross marked object, no coords\n" " -crdimh show half of the dimensions value (radius vs diameter)\n" " -crcol color of cross marks, if present\n" " -cfs coordinates font size (default %i)\n" " -cfcol coordinates font color (default \"%s\")\n" " -csep coordinates separated by character (default newline)\n" " -dsep dimensions separated by character (default newline)\n" " Other:\n" " -h, -help, --help\n" " this help\n" ,DEFAULT_OUTFILE,DEFAULT_DPI,DEFAULT_STROKEWID,DEFAULT_LINECOL,DEFAULT_BGCOL,DEFAULT_PRECISION,DEFAULT_FONTSIZE,DEFAULT_FONTCOLOR); if(forwrapper) printf("\nUsage: %s -mvg \n" " generate image from MVG file , output to image \n",s); exit(0); } int main(int argc,char*argv[]) { //fi=stdin; char*fni; int t; outfile=""; if(argc<2)help(0); strcpy(movecol,movecol1); for(t=1;t