/* THIS PROGRAM WILL READ A MIM AND DETERMINE IF THE COORDINATES FOR PGX's ARE ORDER CLOCKWISE AND COUNTERCLOCKWISE. BASED ON WHAT THE USER SPECIFIES FOR DESIRED ORDERING, THE PROGRAM WILL REORDER THE COORDINATES FOR THE PGX AND CREATE A NEW MIM. FORMAT : pgx_clock mimname OUTPUT FILENAME: mimname_c cc = counter clock-wise cw = clock-wise */ #include #include #include #include #include "mapfonts.h" #include "parseTokens.h" #define TRUE 1 #define FALSE 0 int parseTokens(); void mimft_coord(FILE *inFile, char text[], float xa[], float ya[], long int npt [], long int *ncycle, float *minx, float *maxx, float *miny, float *maxy); short int clockw(float xa[], float ya[], long int npts, long int *ptr); void flip(float xa[], float ya[], long int npts, long int *ptr); void mimft_coord_out_dec(FILE *outFile, char text_in[], float xa[], float ya[],long int npt[], long int ncycle); main(argc, argv) int argc; char *argv[]; { FILE *inFilePtr; FILE *outFilePtr; float xa[10000],ya[10000],xc,yc,xdim,ydim,read,fminx,fmaxx,fminy,fmaxy,fx,fy; long int ncycle, nxy[200]; char text[255], text2[255], tmp[255]; char outFileName[60],inner[2],outer[2]; long int i, j, k, l, m, n, count=0,start=0; long int numToks, numrecs, numpolys, numpts; short int statusflag=0,order=0,optiono=0,optioni=0; int debug = 0, debug2 = 0; long int *ptr; if(argc < 4) { printf(" Missing input parameters. \n"); printf(" Use format: pgx_clock \n"); /* printf(" Use format: pgx_clock \n"); */ printf(" EXAMPLE: pgx_clock myfile cw cc\n"); exit(1); } /* DETERMINE DESIRED ORDERING FOR POLYGON CYCLES */ strncpy(outer,argv[2],2); strncpy(inner,argv[3],2); n=strlen(outer); for(i=0;i\n"); printf("Invalid options for rotation of outer and inner polygons\n"); printf("Use cc for counter clock-wise and cw for clockwise\n"); exit(1); } /* OPEN INPUT MIM */ printf("\ninput metafile: %s\n",argv[1]); if((inFilePtr = fopen(argv[1], "r")) == NULL) { printf(" opening modify metafile\n"); exit(1); } /* OPEN OUTPUT MIM */ outFileName[0] = NULL; strncpy(outFileName,argv[1],50); strcat(outFileName,"_c"); printf("\noutput metafile: %s\n",outFileName); if((outFilePtr = fopen(outFileName, "w")) == NULL) { printf(" opening new file for output\n"); exit(1); } /* READ THROUGH MIM */ while(fgets(text,255,inFilePtr) != NULL && !feof(inFilePtr)) { numToks = parseTokens(text); strcpy(tmp, *tokenStrPtrs); /* IF COMMAND IS PGX REORDER IF NECESSARY AND WRITE TO OUTPUT MIM */ if (strncmp(tmp,"*pgX",4) == 0) { /* CHECK STATUS OF PGX COMMAND */ statusflag=0; for(k=4; k0) { if(strncmp(inner,"cw",2)==0 && order==0)flip(xa,ya,count,ptr); if(strncmp(inner,"cc",2)==0 && order==1) { if(debug)printf("call flip with x2 of %6.3f\n",xa[start+1]); flip(xa,ya,count,ptr); if(debug)printf("after flip with x2 of %6.3f\n",xa[start+1]); } } start=start+count; } /* WRITE OUT PGX IN MIM */ mimft_coord_out_dec(outFilePtr,text,xa,ya,nxy,ncycle); } /* End if for status check */ if(statusflag)fputs(text,outFilePtr); }/* End if for pgx */ /* FOR ALL OTHER MIM COMMANDS, WRITE TO OUTPUT MIM AND CONTINUE */ else { fputs(text,outFilePtr); } continue; } /* End while loop */ fclose(inFilePtr); fclose(outFilePtr); } /* end of main */