/* linefix.c lf1.bat = cl /AL linefix.c vmaputil sketmast mmserial vimage3 graphlib reads a map file and allows you to edit '.bin' file. Output goes into '.raw' so rename old one or you will lose it. You can also convert the raw file before exiting. */ #include #include #include "font.h" /* getfile stuff */ #define MAX_NUM 300 #define S_SIZE 40 #define MAX_X 640 extern char GF_String[MAX_NUM][S_SIZE]; /* display stuff */ #define NUM_TYPE 25 #define NUM_SIZE 25 #define NUM_PSIZE 3 #define NUM_FILL 5 #define NUM_SYM 25 #define MAX_COLORS 16 #define B_LINES 48 #define STR_LEN 100 Mouse=0; extern int LastN; unsigned char MT_Buff[12][MAX_X],Mbuff[B_LINES][MAX_X],Buffer[MAX_X]; int FontSize=2; char VideoType='X'; int ScreenXs,ScreenYs; int BottomHigh=96; int FullScreenXs,FullScreenYs; struct board { int row,col,color; }B_Id; struct Color { unsigned char r, g, b; }Lut[256]; /* VGA color stuff */ #define BLACK 0 #define D_GREY 1 #define M_GREY 2 #define L_GREY 3 #define WHITE 4 #define RED 5 #define ORANGE 6 #define YELLOW 7 #define GREEN 8 #define CYAN 9 #define BLUE 10 #define PURPLE 11 #define MAGENTA 12 #define BROWN 13 #define D_BLUE 14 #define BUFF 15 struct Color Vcolor[16]= { { 0, 0, 0}, { 46, 46, 46}, { 128,128,128}, { 191,191,191}, { 255,255,255}, { 255, 0, 0}, { 255,128, 0}, { 191,191, 0}, { 0,255, 0}, { 0,191,191}, { 40, 40,255}, { 128, 0,255}, { 191, 0,191}, { 96, 28, 14}, { 0, 20, 60}, { 105, 90, 75} }; /* map stuff */ #define MIN_PIX 0.000 #define SYM_SIZE 11 char T_Menu_L[NUM_TYPE+3][2][50]; int Sym_Size=SYM_SIZE; struct symbol_name { char name[50],filename[50]; float max_pix,min_pix; int color; char on; char Symbol[SYM_SIZE][SYM_SIZE]; }PlaceFile[NUM_SYM]; char String[STR_LEN]; struct map { int KeyPlotted; char Fill_Name[256][20]; int Fill_In; int Fill_After; int Fill_Color[256][2]; int Max_Fill; int Fill_Color_RGB[256][3]; float Fill_Color_IHS[256][3]; int Fill_Order[256]; int Comp_Color[256]; int Num_Fill; float FI_min[NUM_FILL],FI_max[NUM_FILL]; char Fill_In_Name[NUM_FILL][STR_LEN]; int White,Num_Color; int screen_xs,screen_ys; int Num_Type,Out; float Pixsize,Clat,Clon,Space; int Mback,Text,High,Back,Grat; int GratOn; int LatLon,Black; char Color_Name[MAX_COLORS][30]; int Color_Val[MAX_COLORS][3]; int Type; int Ns[NUM_TYPE]; int Mm[NUM_TYPE]; int NumSymbol; int Dummy1; int Dummy2; char Group_Name[NUM_TYPE][30]; struct line_name { char filename[54]; float max_pix,min_pix; int color; }MapFile[NUM_TYPE][NUM_SIZE]; struct place_name { char *name,*filename; float max_pix,min_pix; int color; }PlaceFile[3][3]; /* size = 18*3*3 = 162 bytes */ struct Color lut[256]; }M; unsigned char getpt(); struct map_input { char *name,type; double indat[6]; }miv; struct map_screen { int xc,yc,xs,ys; }map_pos; float MaxLat,MinLat,MaxLon,MinLon; /* other stuff */ #define ZOOM_NUM 100 #define MAX_SEG 10000 #define MAX_EDIT 500 #define MAX_PTS 1000 int Rxc,Ryc,Repeat; /* multiple screens if Repeat>1 */ int NumSec; /* number of active lines */ int NumSeg; /* number of lines in 'linefix.tmp */ int E[MAX_SEG],TmpNum; long TmpOffset[MAX_EDIT]; struct line { int numpt; float mmll[4],latlon[MAX_PTS][2]; long attrib; }; struct line L1,L2; char Cut[MAX_PTS]; float ZoomData[ZOOM_NUM][3]; int Z=0; int Edit,BackF[625],NumBackF; FILE *Fptmp,*Fpout; int NumChange=0; /* number of lines changed */ char Cr=0xd; int Cursor=0; int Shift=0; double DelLat=0.0,DelLon=0.0; int Digit=0; /* 1 if Sketch Master (GTCO) 12 x 18 tablet attached */ char Null[10]; char Zoom(); char m_getpad(); int prune(int *cx,int *cy,int *cxs,int *cys,int *cspeed); int message(char *string,int box,int text); main(argc,argv) int argc; char *argv[]; { int i,j,k; char ans; char cfile[100],string[100],name[100]; int val,num; cfile[0]='\0'; if(argc>1) { for(k=1;k=0) { BackF[NumBackF++]=val; printf("Background %3d '%s'\n",NumBackF,string); } }while(val>=0); printf("\n\nEditing ------- '%s'\n",GF_String[Edit]); for(i=0;i0) /* changes were made to GF_String[Edit] */ { printf("\n\nDo you wish to keep changes? (y or n)\n\n"); if(getch()=='n') { printf("No changes or entries made to file '%s'.raw.\n\n", GF_String[Edit]); } else { strcpy(name,GF_String[Edit]); for(k=0;k0) { fpdel=fopen("linefix.raw","wt"); if(fpdel) printf("Deleted line going into 'linefix.raw'\n\n"); else printf( "Could not open 'linefix.raw' to write. Deleted lines will be lost.\n\n"); } sprintf(string,"%s.raw",name); fpraw=fopen(string,"rt"); if(fpraw) { printf( "\n\nFile '%s' already exits. Do you want to overwrite it? (y or n)\n\n", string); if(getch()!='y') { printf("Give new file name.\n"); scanf("%s",name); for(k=0;k=0) /* line is redone read new data from '.tmp' */ { offset=TmpOffset[E[j]]; fseek(Fptmp,offset,SEEK_SET); fread((char *)&attrib,sizeof(long),1,Fptmp); fread((char *)&numpt,sizeof(int),1,Fptmp); fread((char *)mll,sizeof(float),4,Fptmp); numplot_change+=1; } else if(E[j]>-3) /* line not deleted read '.bin' */ { fseek(fpbin,offset,SEEK_SET); fread((char *)&numpt,sizeof(int),1,fpbin); fread((char *)mll,sizeof(float),4,fpbin); numplot_bin+=1; } if(E[j]==-3) /* line deleted */ { num_delete+=1; if(fpdel) { fseek(fpbin,offset,SEEK_SET); fread((char *)&numpt,sizeof(int),1,fpbin); fread((char *)mll,sizeof(float),4,fpbin); fprintf(fpdel,"%6ld",attrib); for(i=0;i0) { latlon[0]+=DelLat; latlon[1]+=DelLon; } if(i%3==0) fprintf(fpdel,"\n"); else fprintf(fpdel," "); fprintf(fpdel,"%10.6f %11.6f",latlon[0],latlon[1]); } fprintf(fpdel,"//\n"); } } else /* output line */ { fprintf(fpraw,"%6ld",attrib); for(i=0;i=0) fread((char *)latlon,sizeof(float),2,Fptmp); else fread((char *)latlon,sizeof(float),2,fpbin); if(Shift>0) { latlon[0]+=DelLat; latlon[1]+=DelLon; } if(i%3==0) fprintf(fpraw,"\n"); else fprintf(fpraw," "); fprintf(fpraw,"%10.6f %11.6f",latlon[0],latlon[1]); } fprintf(fpraw,"//\n"); } printf("%c%d + %d + %d = %d of %d",Cr, numplot_bin,numplot_change,num_delete, numplot_bin+numplot_change+num_delete,NumSec); } printf( "\nPrinted %d lines into '%s'-- %d line(s) changed and %d deleted.\n\n", numplot_bin+numplot_change,name,numplot_change,num_delete); fprintf(fpraw,"\n\n"); fclose(fpbin); fclose(fpatr); fclose(fphdr); fclose(fpraw); } /*********************************************************************** ** ** ** ** ************************************************************************/ int edit() { char ans; float pixsize=12.0,clat=38.0,clon=-95.75,space=10.0; int xc=0,yc=0,xs=ScreenXs,ys=ScreenYs,ix,iy,speed,isize=FontSize,color; int cx,cy,cspeed=16,bxs=16,bys=16; long seg_offset; Z=0; ZoomData[Z][0]=pixsize=M.Pixsize; ZoomData[Z][1]=clat=M.Clat; ZoomData[Z][2]=clon=M.Clon; space=M.Space; video_on(); set_lut('v',0); cx=ScreenXs/2; cy=ScreenYs/2; plot_footer(1); plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,1); do { message("choose option",BROWN,L_GREY); ans=getch(); unmessage("choose option",BROWN,L_GREY); if(ans=='P') prune(&cx,&cy,&bxs,&bys,&cspeed); if(ans=='L') get_location(&cx,&cy,&cspeed); if(ans=='I') dump_screen("choose option"); if(ans=='e') /* (e)dit line */ { line_edit(&cx,&cy); plot_footer(1); } if(ans=='c') { plot_footer(7); cut_line(&cx,&cy); plot_footer(1); } if(ans=='a') { add_line(&cx,&cy); plot_footer(1); } if(Z0) { DelLat=DelLon=0.0; plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,2); } plot_footer(5); shift_lines(&cx,&cy); plot_footer(1); plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,2); } if(Z>0&&ans=='r') { Z=0; pixsize=ZoomData[Z][0]; clat=ZoomData[Z][1]; clon=ZoomData[Z][2]; plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,2); } if(Z>0&&ans=='l') { Z-=1; pixsize=ZoomData[Z][0]; clat=ZoomData[Z][1]; clon=ZoomData[Z][2]; plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,2); } }while(ans!='x'); video_off(); } /*********************************************************************** ** ** ** ** ************************************************************************/ int prune(int *cx,int *cy,int *cxs,int *cys,int *cspeed) { int i,j,k; int xc=*cx,yc=*cy,xs=*cxs,ys=*cys,speed=*cspeed; char string[100]; FILE *fphdr; int numsec,numpt,num=0,numsec0,doit; double maxlat,minlat,maxlon,minlon,x,y,lat,lon; float mll[4],mnln,mxln,mnlt,mxlt; long offset,attrib; limit_area_all(&xc,&yc,&xs,&ys,&speed,ScreenXs,ScreenYs, 1,MT_Buff,WHITE,WHITE,128); x=xc+xs; y=yc; xy_ll(x,y,&maxlat,&maxlon); x=xc; y=yc+ys; xy_ll(x,y,&minlat,&minlon); sprintf(string,"%s.hdr",GF_String[Edit]); fphdr=fopen(string,"rb"); if(!fphdr) return(-1); fread((char *)&numsec,sizeof(int),1,fphdr); numsec0=numsec; numsec=NumSec; sprintf(string,"working %d segments (%d are original)",numsec,numsec0); message(string,BROWN,L_GREY); for(j=0;j=0) /* if line is redone read new data from '.tmp' */ { offset=TmpOffset[E[j]]; fseek(Fptmp,offset,SEEK_SET); fread((char *)&attrib,sizeof(long),1,Fptmp); fread((char *)&numpt,sizeof(int),1,Fptmp); fread((char *)mll,sizeof(float),4,Fptmp); doit=1; } if(doit==1) { mnln=mll[0];mxln=mll[1]; mnlt=mll[2];mxlt=mll[3]; if(E[j]!=-3&&mnln>=minlon&&mxln<=maxlon&&mnlt>=minlat&&mxlt<=maxlat) { plot_segment(&L1,BUFF,BUFF,GF_String[Edit],offset,j,0); unmessage(string,BROWN,L_GREY); sprintf(string,"%d deleted segment %d",++num,j+1); message(string,BROWN,L_GREY); E[j]=-3; /* marked as deleted */ NumChange+=1; } } } *cx=xc; *cy=yc; *cspeed=speed; *cxs=xs; *cys=ys; fclose(fphdr); unmessage(string,BROWN,L_GREY); return(num); } /*********************************************************************** ** ** ** ** ************************************************************************/ int shift_lines(cx,cy) int *cx,*cy; { int i,j,k; char ans,string[100],ans2; int speed=16,size=5; int ixo=*cx,iyo=*cy,pxo,pyo; double x,y,lat1,lon1,lat2,lon2; int segnum=NumSec; long offset=0,seg_offset=0; message("Move to point on yellow line & hit to quit" ,BROWN,L_GREY); if(Digit==0) { tcursor(0,*cx,*cy,size,Buffer); cursor(0,*cx,*cy,WHITE,size); } while((ans=m_getpad(&size,cx,cy,&speed,0))!=27&&ans!=13) { uncursor(0,ixo,iyo,size,Buffer); ixo=*cx;iyo=*cy; tcursor(0,*cx,*cy,size,Buffer); cursor(0,*cx,*cy,WHITE,5); } if(Digit==0) { uncursor(0,ixo,iyo,size,Buffer); tcursor(0,*cx,*cy,size,Buffer); cursor(0,*cx,*cy,ORANGE,size); } unmessage("Move to point on yellow line & hit to quit" ,BROWN,L_GREY); if(ans==27) { if(Digit==0) uncursor(0,*cx,*cy,size,Buffer); return(-1); } x=pxo=*cx;y=pyo=*cy; xy_ll(x,y,&lat1,&lon1); message("Move to new point on grey line & hit to quit" ,BROWN,L_GREY); if(Digit==0) { tcursor(0,*cx,*cy,size,Buffer); cursor(0,*cx,*cy,WHITE,size); } while((ans=m_getpad(&size,cx,cy,&speed,0))!=27&&ans!=13) { uncursor(0,ixo,iyo,size,Buffer); ixo=*cx;iyo=*cy; tcursor(0,*cx,*cy,size,Buffer); cursor(0,*cx,*cy,WHITE,5); } if(Digit==0) { uncursor(0,ixo,iyo,size,Buffer); tcursor(0,*cx,*cy,size,Buffer); cursor(0,*cx,*cy,ORANGE,size); } unmessage("Move to new point on grey line & hit to quit" ,BROWN,L_GREY); if(ans==27) { if(Digit==0) uncursor(0,*cx,*cy,size,Buffer); return(-1); } x=pxo=*cx;y=pyo=*cy; xy_ll(x,y,&lat2,&lon2); Shift+=1; NumChange+=1; DelLat=lat2-lat1; DelLon=lon2-lon1; } /*********************************************************************** ** ** ** ** ************************************************************************/ int cut_line(int *cx,int *cy) { int i,j,k; int segnum=-10; long seg_offset,offset=0; char string[100],ans,ans2; float pixsize=12.0,clat=38.0,clon=-95.75,space=10.0; double x,y,lat,lon,curlat,curlon,mindist,dist; int xc=0,yc=0,xs=ScreenXs,ys=ScreenYs,ix,iy,speed=1,isize=FontSize,color; int cxo,cyo,cspeed=16,px1,py1,px2,py2,p1,p2,pxo,pyo,point,csize=5; int num_cut=0,num,numpt,size=5; for(i=0;i",BROWN,L_GREY); segnum=find_segment(RED,GF_String[Edit],&seg_offset,cx,cy); if(segnum<0) { video_off(); printf("find_segment() failed\n"); exit(0); } if(segnum>=0) plot_segment(&L1,RED,WHITE,GF_String[Edit],seg_offset,segnum,0); else { video_off(); printf("plot_segment() failed\n"); exit(0); } unmessage("Move near line & hit ",BROWN,L_GREY); do { sprintf(string,"line number %d attribute %ld: CHOOSE OPTION:", segnum+1,L1.attrib); message(string,BROWN,L_GREY); ans=getpad(&csize,cx,cy,&cspeed,0); unmessage(string,BROWN,L_GREY); if(Z=0) replot_segment(&L1,RED,WHITE,GF_String[Edit],seg_offset,segnum); } plot_footer(7); } if(Digit==0&&ans=='c') /* cut at a point -- KeyBoard*/ { cspeed=16; message("Move near point to cut & hit ",BROWN,L_GREY); get_xy(cx,cy,&cspeed); unmessage("Move near point to cut & hit ",BROWN,L_GREY); x=*cx;y=*cy; xy_ll(x,y,&curlat,&curlon); mindist=100000.0; point=0; /* find the closest point */ for(i=0;i0&&point to cut to ignor"); message(string,BROWN,L_GREY); ans2=getch(); if(ans2==13) { Cut[point]=1; cursor(0,*cx,*cy,WHITE,7); num_cut+=1; } else uncursor(0,*cx,*cy,size,Buffer); unmessage(string,BROWN,L_GREY); } } }while(ans!='x'&&ans!=27); if(ans==27||num_cut==0) return(0); k=0;j=1;num=1; for(i=0;i=L1.numpt) { j-=1; num-=1; } numpt=num+1; fseek(Fptmp,offset,SEEK_END); E[NumSec++]=NumSeg; TmpOffset[NumSeg++]=ftell(Fptmp); fwrite((char *)&L1.attrib,sizeof(long),1,Fptmp); fwrite((char *)&numpt,sizeof(int),1,Fptmp); fwrite((char *)L1.mmll,sizeof(float),4,Fptmp); fwrite((char *)L1.latlon[k],sizeof(float),numpt*2,Fptmp); j+=1; k+=num; num=1; } fflush(Fptmp); replot_segment(&L1,GREEN,M_GREY,GF_String[Edit],seg_offset,segnum); E[segnum]=-3; /* mark original line as deleted */ NumChange+=1; return(1); } /*********************************************************************** ** ** ** ** ************************************************************************/ int add_line(cx,cy) int *cx,*cy; { int i,j,k; char ans,string[100],ans2; int speed=16,size=5; int ixo=*cx,iyo=*cy,pxo,pyo; double x,y,lat,lon; int segnum=NumSec; long offset=0,seg_offset=0; plot_footer(3); message("Move to start of line & hit [ to quit",BROWN,L_GREY); i=0; tcursor(0,*cx,*cy,size,Buffer); cursor(0,*cx,*cy,WHITE,size); while((ans=m_getpad(&size,cx,cy,&speed,0))!=27&&ans!=13) { uncursor(0,ixo,iyo,size,Buffer); ixo=*cx;iyo=*cy; tcursor(0,*cx,*cy,size,Buffer); cursor(0,*cx,*cy,WHITE,5); } uncursor(0,ixo,iyo,size,Buffer); tcursor(0,*cx,*cy,size,Buffer); cursor(0,*cx,*cy,ORANGE,size); unmessage("Move to start of line & hit [ to quit",BROWN,L_GREY); if(ans==27) { uncursor(0,*cx,*cy,size,Buffer); return(-1); } x=pxo=*cx;y=pyo=*cy; xy_ll(x,y,&lat,&lon); L1.latlon[i][0]=lat; L1.latlon[i++][1]=lon; sprintf(string,"Move to point %d & hit or option",i+1); message(string,BROWN,L_GREY); tplotln_inv_dot(0,pxo,pyo,*cx,*cy,Mbuff[0],ScreenXs); do { ans=getpad(&size,cx,cy,&speed,0); uncursor(0,ixo,iyo,size,Buffer); unplotln(0,pxo,pyo,ixo,iyo,Mbuff[0],ScreenXs); tplotln_inv_dot(0,pxo,pyo,*cx,*cy,Mbuff[0],ScreenXs); plotln(0,pxo,pyo,*cx,*cy,WHITE); if(ans==13) /* plot a point */ { unmessage(string,BROWN,L_GREY); plotln(0,pxo,pyo,*cx,*cy,RED); plotpt(0,pxo,pyo,WHITE); x=pxo=*cx;y=pyo=*cy; xy_ll(x+0.5,y+0.5,&lat,&lon); L1.latlon[i][0]=lat; L1.latlon[i++][1]=lon; sprintf(string,"Move to point %d & hit or option",i+1); message(string,BROWN,L_GREY); } if(ans=='e'||ans=='c') { if(ans=='c') /* close polygon */ { L1.latlon[i][0]=L1.latlon[0][0]; L1.latlon[i++][1]=L1.latlon[0][1]; } L1.numpt=i; L1.attrib=9999; fseek(Fptmp,offset,SEEK_END); E[NumSec++]=NumSeg; TmpOffset[NumSeg++]=ftell(Fptmp); fwrite((char *)&L1.attrib,sizeof(long),1,Fptmp); fwrite((char *)&L1.numpt,sizeof(int),1,Fptmp); set_mmll(L1.latlon,L1.mmll,L1.numpt); fwrite((char *)L1.mmll,sizeof(float),4,Fptmp); fwrite((char *)L1.latlon,sizeof(float),L1.numpt*2,Fptmp); fflush(Fptmp); replot_segment(&L1,ORANGE,M_GREY,GF_String[Edit],seg_offset,segnum); NumChange+=1; return(1); } if(ans=='x'||ans==27) replot_segment(&L1,BUFF,BUFF,GF_String[Edit],seg_offset,segnum); ixo=*cx;iyo=*cy; tcursor(0,*cx,*cy,size,Buffer); cursor(0,*cx,*cy,ORANGE,size); }while(ans!='x'); uncursor(0,*cx,*cy,size,Buffer); } /*********************************************************************** ** ** ** ** ************************************************************************/ int set_mmll(latlon,mmll,numpt) float *latlon,*mmll; int numpt; { int i,j,k; float maxlat=-100.0,minlat=100.0,maxlon=-400.0,minlon=400.0; float lat,lon; for(i=0;imaxlat) maxlat=lat; if(latmaxlon) maxlon=lon; if(lon",BROWN,L_GREY); segnum=find_segment(RED,GF_String[Edit],&seg_offset,&cx,&cy); if(segnum<0) { *e_cx=cx; *e_cy=cy; unmessage("Move near line & hit ",BROWN,L_GREY); return(0); } if(segnum>=0) plot_segment(&L1,RED,WHITE,GF_String[Edit],seg_offset,segnum,0); else { *e_cx=cx; *e_cy=cy; unmessage("Move near line & hit ",BROWN,L_GREY); return(0); } unmessage("Move near line & hit ",BROWN,L_GREY); do { sprintf(string,"line number %d attribute %ld: CHOOSE OPTION:", segnum+1,L1.attrib); message(string,BROWN,L_GREY); ans=getch(); unmessage(string,BROWN,L_GREY); if(Z=0) replot_segment(&L1,RED,WHITE,GF_String[Edit],seg_offset,segnum); } } if(Z>0&&ans=='r') { Z=0; pixsize=ZoomData[Z][0]; clat=ZoomData[Z][1]; clon=ZoomData[Z][2]; plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,2); if(segnum>=0) replot_segment(&L1,RED,WHITE,GF_String[Edit],seg_offset,segnum); } if(ans=='R') { pixsize=ZoomData[Z][0]; clat=ZoomData[Z][1]; clon=ZoomData[Z][2]; plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,2); if(segnum>=0) replot_segment(&L1,RED,WHITE,GF_String[Edit],seg_offset,segnum); } if(Z>0&&ans=='l') { Z-=1; pixsize=ZoomData[Z][0]; clat=ZoomData[Z][1]; clon=ZoomData[Z][2]; plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,2); if(segnum>=0) replot_segment(&L1,RED,WHITE,GF_String[Edit],seg_offset,segnum); } if(ans=='I') dump_screen(string); if(ans=='A') { get_string(string,Mbuff, "Enter","Attrib",0,0,100,47,1,1,Font,WHITE); sscanf(string,"%ld",&new_attrib); change_attrib(&L1,GF_String[Edit],seg_offset,segnum,new_attrib); } if(ans=='c') /* close polygon (join first and last point */ { n1=0; /* first point */ n2=L1.numpt-1; /* last point */ if(L1.latlon[n1][0]!=L1.latlon[n2][0]|| /* lats different or */ L1.latlon[n1][1]!=L1.latlon[n2][1]) /* lons different */ { /* then add first point to end of line */ L1.numpt+=1; L1.latlon[n2+1][0]=L1.latlon[n1][0]; L1.latlon[n2+1][1]=L1.latlon[n1][1]; /* plot line section */ lat=L1.latlon[n1][0]; lon=L1.latlon[n1][1]; ll_xy(&x,&y,lat,lon); px1=x+0.5;py1=y+0.5; lat=L1.latlon[n2][0]; lon=L1.latlon[n2][1]; ll_xy(&x,&y,lat,lon); px2=x+0.5;py2=y+0.5; plotln(0,px1,py1,px2,py2,RED); plotpt(0,px1,py1,WHITE); plotpt(0,px2,py2,WHITE); } } if(ans=='a') /* add points */ { cspeed=16; message("Move near center point & hit ",BROWN,L_GREY); get_xy(&cx,&cy,&cspeed); unmessage("Move near center point & hit ",BROWN,L_GREY); x=cx;y=cy; xy_ll(x,y,&curlat,&curlon); mindist=100000.0; point=0; /* find the closest point */ for(i=0;i1;k--) { L1.latlon[k][0]=L1.latlon[k-1][0]; /* move points over 1 */ L1.latlon[k][1]=L1.latlon[k-1][1]; } k=1; /* place point in middle */ L1.latlon[k][0]=(L1.latlon[k+1][0]+L1.latlon[k-1][0])/2.0; L1.latlon[k][1]=(L1.latlon[k+1][1]+L1.latlon[k-1][1])/2.0; L1.numpt+=1; } else /* other point chosen */ { for(k=L1.numpt+1;k>point+2;k--) { L1.latlon[k][0]=L1.latlon[k-2][0]; /* move top points over 2 */ L1.latlon[k][1]=L1.latlon[k-2][1]; } k=point+1; L1.latlon[k][0]=L1.latlon[k-1][0]; /* move point over 1 */ L1.latlon[k][1]=L1.latlon[k-1][1]; k=point+2; /* place upper point in middle */ L1.latlon[k][0]=(L1.latlon[k-1][0]+L1.latlon[k+1][0])/2.0; L1.latlon[k][1]=(L1.latlon[k-1][1]+L1.latlon[k+1][1])/2.0; k=point; /* place lower point in middle */ L1.latlon[k][0]=(L1.latlon[k-1][0]+L1.latlon[k+1][0])/2.0; L1.latlon[k][1]=(L1.latlon[k-1][1]+L1.latlon[k+1][1])/2.0; L1.numpt+=2; } replot_segment(&L1,RED,WHITE,GF_String[Edit],seg_offset,segnum); } if(ans=='D') { replot_segment(&L1,BUFF,BUFF,GF_String[Edit],seg_offset,segnum); E[segnum]=-3; /* marked as deleted */ *e_cx=cx; *e_cy=cy; NumChange+=1; return(1); } if(Digit==1&&ans=='m') /* move a point -- SketMaster */ { ans2='\0'; do { if(ans2==27) break; message("Move near a point & hit ",BROWN,L_GREY); get_xy(&cx,&cy,&cspeed); unmessage("Move near a point & hit ",BROWN,L_GREY); x=cx;y=cy; xy_ll(x,y,&curlat,&curlon); mindist=100000.0; point=0; /* find the closest point */ plot_footer(6); for(i=0;i",point+1); message(string,BROWN,L_GREY); lat=L1.latlon[point][0]; lon=L1.latlon[point][1]; ll_xy(&x,&y,lat,lon); pxo=cxo=cx=x; pyo=cyo=cy=y; px1=py1=px2=py2=p1=p2=-1; if(point>0) /* not the first point of the segment */ { lat=L1.latlon[point-1][0]; lon=L1.latlon[point-1][1]; ll_xy(&x,&y,lat,lon); px1=x;py1=y;p1=1; } if(point0) tplotln_inv_dot(0,px1,py1,cx,cy,Mbuff[0],ScreenXs); if(p2>0) tplotln_inv_dot(0,px2,py2,cx,cy,Mbuff[1],ScreenXs); if(p1>0) plotln(0,px1,py1,cx,cy,WHITE); if(p2>0) plotln(0,px2,py2,cx,cy,WHITE); x=cx;y=cy; xy_ll(x+0.5,y+0.5,&lat,&lon); do { if(ans2==27) break; ans2=m_getpad(&size,&cx,&cy,&speed,1); if(ans2=='m') /* move point */ { if(p2>0) unplotln(0,px2,py2,cxo,cyo,Mbuff[1],ScreenXs); if(p1>0) unplotln(0,px1,py1,cxo,cyo,Mbuff[0],ScreenXs); cxo=cx;cyo=cy; if(p1>0) tplotln_inv_dot(0,px1,py1,cx,cy,Mbuff[0],ScreenXs); if(p2>0) tplotln_inv_dot(0,px2,py2,cx,cy,Mbuff[1],ScreenXs); if(p1>0) plotln(0,px1,py1,cx,cy,WHITE); if(p2>0) plotln(0,px2,py2,cx,cy,WHITE); } if(p2>0) unplotln(0,px2,py2,cxo,cyo,Mbuff[1],ScreenXs); if(p1>0) unplotln(0,px1,py1,cxo,cyo,Mbuff[0],ScreenXs); if(ans2=='s') { replot_segment(&L1,BUFF,BUFF, GF_String[Edit],seg_offset,segnum); for(i=point;i0) plotln(0,px1,py1,pxo,pyo,BUFF); if(p2>0) plotln(0,px2,py2,pxo,pyo,BUFF); if(p1>0) plotln(0,px1,py1,cxo,cyo,RED); if(p2>0) plotln(0,px2,py2,cxo,cyo,RED); if(p1>0) plotpt(0,px1,py1,WHITE); if(p2>0) plotpt(0,px2,py2,WHITE); plotpt(0,cxo,cyo,WHITE); } }while(ans2=='m'); }while(ans2!=27); plot_footer(2); } if(Digit==0&&ans=='m') /* move a point -- KeyBoard*/ { cspeed=16; message("Move near a point & hit ",BROWN,L_GREY); get_xy(&cx,&cy,&cspeed); unmessage("Move near a point & hit ",BROWN,L_GREY); x=cx;y=cy; xy_ll(x,y,&curlat,&curlon); mindist=100000.0; point=0; /* find the closest point */ plot_footer(6); for(i=0;i",point+1); message(string,BROWN,L_GREY); lat=L1.latlon[point][0]; lon=L1.latlon[point][1]; ll_xy(&x,&y,lat,lon); pxo=cxo=cx=x; pyo=cyo=cy=y; px1=py1=px2=py2=p1=p2=-1; if(point>0) /* not the first point of the segment */ { lat=L1.latlon[point-1][0]; lon=L1.latlon[point-1][1]; ll_xy(&x,&y,lat,lon); px1=x;py1=y;p1=1; } if(point0) tplotln_inv_dot(0,px1,py1,cx,cy,Mbuff[0],ScreenXs); if(p2>0) tplotln_inv_dot(0,px2,py2,cx,cy,Mbuff[1],ScreenXs); if(p1>0) plotln(0,px1,py1,cx,cy,WHITE); if(p2>0) plotln(0,px2,py2,cx,cy,WHITE); if(Cursor==1) { tcursor(0,cx,cy,size,Buffer); cursor(0,cx,cy,GREEN,5); } x=cx;y=cy; xy_ll(x+0.5,y+0.5,&lat,&lon); while((ans2=m_getpad(&size,&cx,&cy,&speed,1))!=27&&ans2!=13) { if(ans2=='c') { if(Cursor==0) /* cursor off */ { Cursor==1; /* turn cursor on */ tcursor(0,cx,cy,size,Buffer); cursor(0,cx,cy,GREEN,5); x=cx;y=cy; xy_ll(x+0.5,y+0.5,&lat,&lon); sprintf(string, "pt %d [%ld] lat/lon %0.5lf %0.5lf to keep to quit", point,L1.attrib,lat,lon); message(string,BROWN,L_GREY); } else /* cursor on */ { Cursor=0; /* turn cursor off */ unmessage(string,BROWN,L_GREY); uncursor(0,cxo,cyo,size,Buffer); } plot_footer(6); } if(cx!=cxo||cy!=cyo) { if(Cursor==1) { unmessage(string,BROWN,L_GREY); uncursor(0,cxo,cyo,size,Buffer); } if(p2>0) unplotln(0,px2,py2,cxo,cyo,Mbuff[1],ScreenXs); if(p1>0) unplotln(0,px1,py1,cxo,cyo,Mbuff[0],ScreenXs); cxo=cx;cyo=cy; if(p1>0) tplotln_inv_dot(0,px1,py1,cx,cy,Mbuff[0],ScreenXs); if(p2>0) tplotln_inv_dot(0,px2,py2,cx,cy,Mbuff[1],ScreenXs); if(p1>0) plotln(0,px1,py1,cx,cy,WHITE); if(p2>0) plotln(0,px2,py2,cx,cy,WHITE); if(Cursor==1) { tcursor(0,cx,cy,size,Buffer); cursor(0,cx,cy,GREEN,5); x=cx;y=cy; xy_ll(x+0.5,y+0.5,&lat,&lon); sprintf(string, "pt %d [%ld] lat/lon %0.5lf %0.5lf to keep to quit", point,L1.attrib,lat,lon); message(string,BROWN,L_GREY); } } } if(Cursor==1) { unmessage(string,BROWN,L_GREY); uncursor(0,cxo,cyo,size,Buffer); } if(p2>0) unplotln(0,px2,py2,cxo,cyo,Mbuff[1],ScreenXs); if(p1>0) unplotln(0,px1,py1,cxo,cyo,Mbuff[0],ScreenXs); if(ans2==13) { x=cxo;y=cyo; xy_ll(x+0.5,y+0.5,&lat,&lon); L1.latlon[point][0]=lat; L1.latlon[point][1]=lon; replot_segment(&L1,RED,WHITE,GF_String[Edit],seg_offset,segnum); } if(p1>0) plotln(0,px1,py1,pxo,pyo,BUFF); if(p2>0) plotln(0,px2,py2,pxo,pyo,BUFF); if(p1>0) plotln(0,px1,py1,cxo,cyo,RED); if(p2>0) plotln(0,px2,py2,cxo,cyo,RED); if(p1>0) plotpt(0,px1,py1,WHITE); if(p2>0) plotpt(0,px2,py2,WHITE); plotpt(0,cxo,cyo,WHITE); plot_footer(2); } if(ans=='d') /* delete a point */ { message("Move near a point & hit ",BROWN,L_GREY); get_xy(&cx,&cy,&cspeed); unmessage("Move near a point & hit ",BROWN,L_GREY); x=cx;y=cy; xy_ll(x,y,&curlat,&curlon); mindist=100000.0; point=0; /* find the closest point */ for(i=0;iattrib=attrib; } else return(-1); fclose(fpatr); } else /* from update file */ return(-1); } /*********************************************************************** ** ** ** ** ************************************************************************/ int get_xy(x,y,speed) int *x,*y,*speed; { int size=5; int ixo=*x,iyo=*y; char ans; if(Digit==0) { tcursor(0,*x,*y,size,Buffer); cursor(0,*x,*y,WHITE,5); } while((ans=m_getpad(&size,x,y,speed,0))!=27&&ans!=13) { if(Digit==0) { uncursor(0,ixo,iyo,size,Buffer); ixo=*x;iyo=*y; tcursor(0,*x,*y,size,Buffer); cursor(0,*x,*y,WHITE,5); } } if(Digit==0) uncursor(0,ixo,iyo,size,Buffer); } /*********************************************************************** ** ** ***********************************************************************/ int replot_segment(segment,line,dot,region,seg_offset,segnum) struct line *segment; int line,dot; /* colors */ char *region; long seg_offset; int segnum; { int i,j,k,m,n=0,p; double x,y,xo,yo; int ix,iy,ixo=-1,iyo=-1; double dx,dy,dist; int secnum,numsec,ival; float latlon[2],mll[4],mnln,mxln,mnlt,mxlt; char string[40],pth[40],name[40],type[40]; int doit,numplot=0; int first_seg=-1,last_seg=-1,atr=0; for(i=0;inumpt;i++) { latlon[0]=segment->latlon[i][0]; latlon[1]=segment->latlon[i][1]; ll_xy(&x,&y,(double)latlon[0],(double)latlon[1]); if(i==0) { xo=x;yo=y; ixo=ix;iyo=iy; } ix=x;iy=y; if(i>0) plotln(0,ix,iy,ixo,iyo,line); ixo=ix;iyo=iy; xo=ix;yo=iy; } for(i=0;inumpt;i++) { latlon[0]=segment->latlon[i][0]; latlon[1]=segment->latlon[i][1]; ll_xy(&x,&y,(double)latlon[0],(double)latlon[1]); ix=x;iy=y; plotpt(0,ix,iy,dot); } } /*********************************************************************** ** ** iop: ** ** 0 -- use bin or update if available ** 1 -- use only bin file ** ***********************************************************************/ int plot_segment(segment,line,dot,region,seg_offset,segnum,iop) struct line *segment; int line,dot; /* colors */ char *region; long seg_offset; int segnum,iop; { int i,j,k,m,n=0,p; double x,y,xo,yo; int ix,iy,ixo=-1,iyo=-1; double dx,dy,dist; int secnum,numpt,numsec,ival; FILE *fp,*fpatr; float latlon[2],mll[4],mnln,mxln,mnlt,mxlt; char string[40],pth[40],name[40],type[40]; int doit,numplot=0; int first_seg=-1,last_seg=-1,atr=0; long offset,attrib; if(iop==1||E[segnum]<0) /* plot from '.bin' file */ { strcpy(string,region); strcat(string,".bin"); fp=fopen(string,"rb"); if(!fp) return(-1); strcpy(string,region); strcat(string,".atr"); fpatr=fopen(string,"rb"); if(fpatr) { offset=(long)segnum*(long)4; fseek(fpatr,offset,SEEK_SET); fread((char *)&attrib,sizeof(long),1,fpatr); segment->attrib=attrib; } else segment->attrib=9999; fseek(fp,seg_offset,SEEK_SET); fread((char *)&numpt,sizeof(int),1,fp); segment->numpt=numpt; fread((char *)mll,sizeof(float),4,fp); for(k=0;k<4;k++) segment->mmll[k]=mll[k]; for(i=0;ilatlon[i][0]=latlon[0]; segment->latlon[i][1]=latlon[1]; ll_xy(&x,&y,(double)latlon[0],(double)latlon[1]); if(i==0) { xo=x;yo=y; ixo=ix;iyo=iy; } ix=x;iy=y; if(i>0) plotln(0,ix,iy,ixo,iyo,line); ixo=ix;iyo=iy; xo=ix;yo=iy; } for(i=0;ilatlon[i][0]; latlon[1]=segment->latlon[i][1]; ll_xy(&x,&y,(double)latlon[0],(double)latlon[1]); ix=x;iy=y; plotpt(0,ix,iy,dot); } fclose(fp); fclose(fpatr); } else /* plot from update file */ { offset=TmpOffset[E[segnum]]; fseek(Fptmp,seg_offset,SEEK_SET); fread((char *)&attrib,sizeof(long),1,Fptmp); segment->attrib=attrib; fread((char *)&numpt,sizeof(int),1,Fptmp); segment->numpt=numpt; fread((char *)mll,sizeof(float),4,Fptmp); for(k=0;k<4;k++) segment->mmll[k]=mll[k]; for(i=0;ilatlon[i][0]=latlon[0]; segment->latlon[i][1]=latlon[1]; ll_xy(&x,&y,(double)latlon[0],(double)latlon[1]); if(i==0) { xo=x;yo=y; ixo=ix;iyo=iy; } ix=x;iy=y; if(i>0) plotln(0,ix,iy,ixo,iyo,line); ixo=ix;iyo=iy; xo=ix;yo=iy; } for(i=0;ilatlon[i][0]; latlon[1]=segment->latlon[i][1]; ll_xy(&x,&y,(double)latlon[0],(double)latlon[1]); ix=x;iy=y; plotpt(0,ix,iy,dot); } } } /*********************************************************************** ** ** Finds the closest point to the cursor and ** ** (1) returns the segment number which contains the point ** (2) the offset of the segment in the '.bin' file and ** (3) the x and y values of the closest point ** ** ** ***********************************************************************/ int find_segment(val,region,seg_offset,cur_x,cur_y) char *region; int val,*cur_x,*cur_y; long *seg_offset; { int i,j,k,m,n=0,p; double x,y,xo,yo,cx,cy; int ix,iy,ixo=*cur_x,iyo=*cur_y; double dx,dy,mindist=10000.0,dist; int secnum,numpt,numsec,ival; FILE *fp,*fphdr; float latlon[2],mll[4],mnln,mxln,mnlt,mxlt; char string[40],pth[40],name[40],type[40],ans; int doit,numplot=0; int first_seg=-1,last_seg=-1,atr=0; long offset,attrib; int seg_num=-1,size=5,speed=16; if(Digit==0) { tcursor(0,*cur_x,*cur_y,size,Buffer); cursor(0,*cur_x,*cur_y,WHITE,size); } while((ans=m_getpad(&size,cur_x,cur_y,&speed,0))!=27&&ans!=13) { uncursor(0,ixo,iyo,size,Buffer); ixo=*cur_x;iyo=*cur_y; tcursor(0,*cur_x,*cur_y,size,Buffer); cursor(0,*cur_x,*cur_y,WHITE,size); } if(Digit==0) uncursor(0,ixo,iyo,size,Buffer); if(ans==27) return(-4); cx=*cur_x; cy=*cur_y; strcpy(string,region); strcat(string,".bin"); fp=fopen(string,"rb"); if(!fp) return(-1); strcpy(string,region); strcat(string,".hdr"); fphdr=fopen(string,"rb"); if(!fphdr) { fclose(fp); return(-1); } fread((char *)&numsec,sizeof(int),1,fphdr); numsec=NumSec; for(j=0;j0) { ival=getch(); if(ival==27) { fclose(fp); fclose(fphdr); return(-2); } } /* read header file entry */ doit=1; fread((char *)&offset,sizeof(long),1,fphdr); fread((char *)mll,sizeof(float),4,fphdr); if(E[j]>=0) /* if line is redone read new data from '.tmp' */ { offset=TmpOffset[E[j]]; fseek(Fptmp,offset,SEEK_SET); fread((char *)&attrib,sizeof(long),1,Fptmp); fread((char *)&numpt,sizeof(int),1,Fptmp); fread((char *)mll,sizeof(float),4,Fptmp); } mnln=mll[0];mxln=mll[1];mnlt=mll[2];mxlt=mll[3]; if(mnln>MaxLon||mnlt>MaxLat||mxln=0) fread((char *)latlon,sizeof(float),2,Fptmp); else fread((char *)latlon,sizeof(float),2,fp); if(doit==1) { ll_xy(&x,&y,(double)latlon[0],(double)latlon[1]); dist=(x-cx)*(x-cx)+(y-cy)*(y-cy); if(distyc+ys+ScreenXs/2-1)cur_iy=yc+ys+ScreenXs/2-1; if(cur_ix>xc+xs+ScreenYs/2-1)cur_ix=xc+xs+ScreenYs/2-1; } } if(ans=='h'||ans=='H') { txs=ScreenXs; ScreenXs=FullScreenXs; save_box(0,M.Back,Mbuff, 0,0,FullScreenXs,32/lsize); paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize); sprintf(String, "(s)maller (l)arger 'Enter'=plot 'Esc'=exit without plotting"); plot_font_h(WHITE,1,1,String,FontSize,Font); ans=getch(); unsave_box(0,M.Back,Mbuff, 0,0,FullScreenXs,32/lsize); ScreenXs=txs; } if(ans=='l')cur_ps*=cur_scale; if(ans=='s')cur_ps/=cur_scale; if(cur_ps1) speed/=2; else cur_scale=sqrt((double)cur_scale); } if(ans=='+'&&speed<256)speed*=2; unplotln(0,ix[0],iy[0]+1,ix[1],iy[1],MT_Buff[0]); unplotln(0,ix[1]+1,iy[1],ix[2],iy[2],MT_Buff[1]); unplotln(0,ix[2],iy[2]-1,ix[3],iy[3],MT_Buff[2]); unplotln(0,ix[3]-1,iy[3],ix[0],iy[0],MT_Buff[3]); xy_ll((double)cur_ix,(double)cur_iy,&dlat,&dlon); cur_clat=dlat;cur_clon=dlon; get_corners(xc,yc,xs,ys, m_ps,m_clat,m_clon,cur_ps,cur_clat,cur_clon,ix,iy); tplotln_val(0,ix[0],iy[0]+1,ix[1],iy[1],MT_Buff[0],WHITE); tplotln_val(0,ix[1]+1,iy[1],ix[2],iy[2],MT_Buff[1],WHITE); tplotln_val(0,ix[2],iy[2]-1,ix[3],iy[3],MT_Buff[2],WHITE); tplotln_val(0,ix[3]-1,iy[3],ix[0],iy[0],MT_Buff[3],WHITE); }while(ans!=83&&ans!=27&&ans!=13); unplotln(0,ix[0],iy[0]+1,ix[1],iy[1],MT_Buff[0]); unplotln(0,ix[1]+1,iy[1],ix[2],iy[2],MT_Buff[1]); unplotln(0,ix[2],iy[2]-1,ix[3],iy[3],MT_Buff[2]); unplotln(0,ix[3]-1,iy[3],ix[0],iy[0],MT_Buff[3]); M.Pixsize=*pixsize=cur_ps; M.Clat=*clat=cur_clat; M.Clon=*clon=cur_clon; if(cur_ps<20) { *space=30.0; return(ans); } if(cur_ps<10) { *space=15.0; return(ans); } if(cur_ps<2) { *space=5.0; return(ans); } *space=1.0; return(ans); } /******************************************************************** ** ** ** ********************************************************************* */ int get_corners(xc,yc,xs,ys,m_pixsize,m_clat,m_clon, cur_pixsize,cur_clat,cur_clon,x,y) int xc,yc,xs,ys; float m_pixsize,m_clat,m_clon,cur_pixsize,cur_clat,cur_clon; int x[4],y[4]; { int i,j,k; double lat[4],lon[4],dx,dy; miv.indat[0]=cur_pixsize; miv.indat[1]=cur_clat; miv.indat[2]=cur_clon; miv.indat[3]=cur_clon; miv.indat[4]=cur_clat+10; miv.indat[5]=cur_clat-10; map_pos.xc=xc; map_pos.yc=yc; map_pos.xs=xs; map_pos.ys=ys; auto_set_cc(miv.type,miv.indat); xy_ll((double)xc,(double)yc,lat+0,lon+0); xy_ll((double)xc,(double)yc+ys-1,lat+1,lon+1); xy_ll((double)xc+xs-1,(double)yc+ys-1,lat+2,lon+2); xy_ll((double)xc+xs-1,(double)yc,lat+3,lon+3); miv.indat[0]=m_pixsize; miv.indat[1]=m_clat; miv.indat[2]=m_clon; miv.indat[3]=m_clon; miv.indat[4]=m_clat+10; miv.indat[5]=m_clat-10; map_pos.xc=xc; map_pos.yc=yc; map_pos.xs=xs; map_pos.ys=ys; auto_set_cc(miv.type,miv.indat); for(i=0;i<4;i++) { ll_xy(&dx,&dy,lat[i],lon[i]); x[i]=dx; y[i]=dy; } } /*********************************************************************** ** ** ** ** ************************************************************************/ int get_location(x,y,speed) int *x,*y,*speed; { int xc=0,yc=FullScreenYs-BottomHigh/FontSize,high=32/FontSize; int size=5,xo=*x,yo=*y; char string[100],ans; double lat,lon,dx,dy; yc+=high*2; ScreenYs=FullScreenYs; paint_box(0,D_GREY,MT_Buff,xc,yc,ScreenXs,high); plot_font_h(L_GREY,xc+5,yc+2, " to exit", FontSize,Font); xc=15*15/FontSize; tcursor(0,*x,*y,size,Buffer); cursor(0,*x,*y,WHITE,5); while((ans=getpad(&size,x,y,speed,0))!=27&&ans!=13) { uncursor(0,xo,yo,size,Buffer); xo=dx=*x;yo=dy=*y; tcursor(0,*x,*y,size,Buffer); cursor(0,*x,*y,WHITE,5); xy_ll(dx,dy,&lat,&lon); paint_box(0,D_GREY,MT_Buff,xc,yc,ScreenXs-xc,high); sprintf(string,"x=%3d y=%d lat=%10.6lf lon=%11.6lf", *x,*y,lat,lon); plot_font_h(L_GREY,xc+5,yc,string,FontSize,Font); } uncursor(0,xo,yo,size,Buffer); paint_box(0,D_GREY,MT_Buff,xc,yc,ScreenXs,high); ScreenYs=FullScreenYs-BottomHigh/FontSize; } /*********************************************************************** ** ** ** ** ************************************************************************/ int message(string,box,text) char *string; int box,text; { int xc=0,yc=FullScreenYs-BottomHigh/FontSize,ys=32/FontSize; int xs=strlen(string)*15/FontSize+5; yc+=ys*2; ScreenYs=FullScreenYs; paint_box(0,box,MT_Buff,xc,yc,xs,ys); plot_font_h(text,xc+3,yc+2,string,FontSize,Font); ScreenYs=FullScreenYs-BottomHigh/FontSize; } /*********************************************************************** ** ** ** ** ************************************************************************/ int unmessage(string,box,text) char *string; int box,text; { int xc=0,yc=FullScreenYs-BottomHigh/FontSize,ys=32/FontSize; int xs=strlen(string)*15/FontSize+5; yc+=ys*2; ScreenYs=FullScreenYs; paint_box(0,D_GREY,MT_Buff,xc,yc,xs,ys); ScreenYs=FullScreenYs-BottomHigh/FontSize; } /*********************************************************************** ** ** num: ** 1 -- main footer ** 2 -- EDIT SEGMENT: footer ** 3 -- ADD SEGMENT: footer ** 4 -- ZOOM: footer ** 5 -- SHIFT: footer ** 6 -- MOVE A POINT: ** 7 -- CUT A SEGMENT: ** ************************************************************************/ int plot_footer(num) int num; { int xc=0,yc=FullScreenYs-BottomHigh/FontSize,high=32/FontSize; ScreenYs=FullScreenYs; paint_box(0,D_GREY,MT_Buff,xc,yc,ScreenXs,BottomHigh/FontSize); if(num==1) { plot_font_h(L_GREY,xc+5,yc+2, "(e)dit segment (L)ocation (R)eplot map (S)hift map (P)rune e(x)it", FontSize,Font); plot_font_h(L_GREY,xc+5,yc+high+2, "(z)oom (r)eset zoom (l)ast zoom (a)dd segment (c)ut segment", FontSize,Font); } if(num==2) { plot_font_h(L_GREY,xc+5,yc+2, "EDIT SEGMENT: (m)ove point (c)lose (a)dd points (d)elete point e(x)it", FontSize,Font); plot_font_h(L_GREY,xc+5,yc+high+2, "(s)ave (z)oom (r)eset zoom (l)ast zoom (R)eplot map (D)elete line ", FontSize,Font); } if(num==3) { plot_font_h(L_GREY,xc+5,yc+2, "ADD A SEGMENT: (c)lose and save (e)nd and save", FontSize,Font); plot_font_h(L_GREY,xc+5,yc+high+2, " e(x)it without saving", FontSize,Font); } if(num==4) { plot_font_h(L_GREY,xc+5,yc+2, "ZOOM: Move Box With Arrow Keys to plot to exit", FontSize,Font); plot_font_h(L_GREY,xc+5,yc+high+2, "Change Box Size Using (l)arger or (s)maller '+' = faster '-' = slower", FontSize,Font); } if(num==5) { plot_font_h(L_GREY,xc+5,yc+2, "SHIFT: Mark a point on the on the yellow lines to plot", FontSize,Font); plot_font_h(L_GREY,xc+5,yc+high+2, " then mark where it should be. to exit", FontSize,Font); } if(num==6&&Digit==0) { plot_font_h(L_GREY,xc+5,yc+2, "MOVE A POINT: to keep to quit",FontSize,Font); if(Cursor==1) plot_font_h(L_GREY,xc+5,yc+high+2, " (c)ursor OFF for faster editing",FontSize,Font); else plot_font_h(L_GREY,xc+5,yc+high+2, " (c)ursor ON to get lat/lon of point",FontSize,Font); } if(num==6&&Digit==1) { plot_font_h(L_GREY,xc+5,yc+2, "MOVE A POINT:",FontSize,Font); plot_font_h(YELLOW,xc+5,yc+2, " Move Point", FontSize,Font); plot_font_h(WHITE,xc+5,yc+high/2+2, " Keep & Move Next Point", FontSize,Font); plot_font_h(GREEN,xc+5,yc+high/2+2, " Delete Point", FontSize,Font); plot_font_h(BLUE,xc+5,yc+high+2, " Exit Move", FontSize,Font); } if(num==7) { plot_font_h(L_GREY,xc+5,yc+2, "CUT A SEGMENT: (c)ut line (z)oom e(x)it to quit cut function", FontSize,Font); plot_font_h(L_GREY,xc+5,yc+high+2, " to make cut to ignore cut",FontSize,Font); } ScreenYs=FullScreenYs-BottomHigh/FontSize; } /******************************************************************** ** ** iop == 1 E[] is set ** ********************************************************************* */ int plot_map(xc,yc,xs,ys,pixsize,clat,clon,space,iop) int xc,yc,xs,ys,iop; float pixsize,clat,clon,space; { int i,j,k,l,m; double sp=space; int num,val,filled=0; int ix=ScreenXs/2,iy=ScreenYs/2,speed=16; char string[100]; miv.type=M.Type; miv.indat[0]=pixsize; miv.indat[1]=clat; miv.indat[2]=clon; miv.indat[3]=clon; miv.indat[4]=clat+10; miv.indat[5]=clat-10; map_pos.xc=0; map_pos.yc=0; map_pos.xs=ScreenXs; map_pos.ys=ScreenYs; auto_set_cc(miv.type,miv.indat); screen_mm(); paint_box(0,BUFF,MT_Buff,0,0,ScreenXs,ScreenYs); for(i=0;i0) { val=getch(); if(val==27) return(-1); } sprintf(string,"Plotting Line '%s'",GF_String[BackF[i]]); message(string,BROWN,L_GREY); num=convert_bin(D_GREY,GF_String[BackF[i]],0); unmessage(string,BROWN,L_GREY); if(num<-1) return(-2); } sprintf(string,"Plotting Line to Edit '%s'",GF_String[Edit]); message(string,BROWN,L_GREY); num=convert_bin(YELLOW,GF_String[Edit],iop); unmessage(string,BROWN,L_GREY); if(num<-1) return(-2); } /*********************************************************************** ** ** iop: ** 0 -- just plot line ** 1 -- plot and load NumSec and E[] ** 2 -- plot and check for changed lines (Edit line) ** ** E[]: ** -4 -- no segment ** -3 -- segment has been deleted ** -2 -- segment off screen and unchanged ** -1 -- segment on screen and unchanged ** >=0 -- number of segment in 'linefix.bin' ** ***********************************************************************/ int convert_bin(val,region,iop) char *region; int val,iop; { int i,j,k,m,n=0,p; double x,y,xo,yo; int ix,iy,ixo=-1,iyo=-1; double dx,dy,dist; int secnum,numpt,numsec,ival; FILE *fp,*fphdr,*fpatr; float latlon[2],mll[4],mnln,mxln,mnlt,mxlt; char string[40],pth[40],name[40],type[40]; int doit,numplot=0; int first_seg=-1,last_seg=-1,atr=0; long offset,attrib; strcpy(string,region); strcat(string,".bin"); fp=fopen(string,"rb"); if(!fp) return(-1); strcpy(string,region); strcat(string,".hdr"); fphdr=fopen(string,"rb"); if(!fphdr) { fclose(fp); return(-1); } strcpy(string,region); strcat(string,".atr"); fpatr=fopen(string,"rb"); if(fpatr) atr=1; fread((char *)&numsec,sizeof(int),1,fphdr); fread((char *)&numsec,sizeof(int),1,fp); if(iop==1) { NumSec=numsec; E[numsec]=-4; } if(iop==2) numsec=NumSec; for(j=0;j0) { ival=getch(); if(ival==27) { fclose(fp); fclose(fphdr); return(-2); } } /* read header file entr */ doit=1; fread((char *)&offset,sizeof(long),1,fphdr); fread((char *)mll,sizeof(float),4,fphdr); if(iop==1) E[j]=-2; if(atr==1) fread((char *)&attrib,sizeof(long),1,fpatr); if(iop==2&&E[j]>=0) /* if line is redone read new data from '.tmp' */ { offset=TmpOffset[E[j]]; fseek(Fptmp,offset,SEEK_SET); fread((char *)&attrib,sizeof(long),1,Fptmp); fread((char *)&numpt,sizeof(int),1,Fptmp); fread((char *)mll,sizeof(float),4,Fptmp); } if(iop!=2||Shift==0) { mnln=mll[0];mxln=mll[1]; mnlt=mll[2];mxlt=mll[3]; } else { mnln=mll[0]+DelLon;mxln=mll[1]+DelLon; mnlt=mll[2]+DelLat;mxlt=mll[3]+DelLat; } if(mnln>MaxLon||mnlt>MaxLat||mxln=0) fread((char *)latlon,sizeof(float),2,Fptmp); else fread((char *)latlon,sizeof(float),2,fp); if(doit==1) { if(iop!=2||Shift==0) ll_xy(&x,&y,(double)latlon[0],(double)latlon[1]); else ll_xy(&x,&y,(double)latlon[0]+DelLat, (double)latlon[1]+DelLon); if(i==0) { xo=x;yo=y; ixo=ix;iyo=iy; } ix=x;iy=y; plotpt(0,ix,iy,val); if(i>0) plotln(0,ix,iy,ixo,iyo,val); ixo=ix;iyo=iy; xo=ix;yo=iy; } } } } fclose(fp); fclose(fpatr); fclose(fphdr); return(numplot); } /************************************************************************** ** ** ** ************************************************************************* */ int video_on() { int i,row; FontSize=2; i=GetVideoBoardID(); if(VideoType=='X') { row=SetVideoMode(480,&B_Id); if(B_Id.row<400) VideoType='V'; else { ScreenXs=640; ScreenYs=row; } } if(VideoType=='Y') { row=SetVideoMode(400,&B_Id); if(B_Id.row<400) VideoType='V'; else { ScreenXs=640; ScreenYs=row; } } if(VideoType=='V') { row=SetVideoMode(0x12,&B_Id); if(B_Id.row!=480) VideoType='E'; else { ScreenXs=640; ScreenYs=480; } } if(VideoType=='S') { row=SetVideoMode(0x13,&B_Id); if(B_Id.row!=200) { SetVideoMode(0,&B_Id); printf("Could not boot color board.\n"); exit(0); } ScreenXs=320; ScreenYs=200; FontSize=3; } if(VideoType=='E') { row=SetVideoMode(0x10,&B_Id); if(B_Id.row!=350) { SetVideoMode(0,&B_Id); printf("Could not boot color board.\n"); exit(0); } ScreenXs=640; ScreenYs=350; } if(B_Id.row<0) { SetVideoMode(0,&B_Id); printf("Could not boot board -- row = %d\n\n",row); exit(0); } ScreenXs=FullScreenXs=B_Id.col; FullScreenYs=B_Id.row; ScreenYs=FullScreenYs-BottomHigh/FontSize; } /************************************************************************** ** ** ** ************************************************************************* */ int get_color(string) char *string; { int i,j,k; int val=-1; for(i=0;iMaxLat)MaxLat=flat; if(flon>MaxLon)MaxLon=flon; if(flatMaxLat)MaxLat=flat; if(flon>MaxLon)MaxLon=flon; if(flatMaxLat)MaxLat=flat; if(flon>MaxLon)MaxLon=flon; if(flatMaxLat)MaxLat=flat; if(flon>MaxLon)MaxLon=flon; if(flatMaxLat)MaxLat=flat; if(flon>MaxLon)MaxLon=flon; if(flatMaxLat)MaxLat=flat; if(flon>MaxLon)MaxLon=flon; if(flatMaxLat)MaxLat=flat; if(flon>MaxLon)MaxLon=flon; if(flatMaxLat)MaxLat=flat; if(flon>MaxLon)MaxLon=flon; if(flat180.0) lon_l-=360.0; if(lon_r>180.0) lon_r-=360.0; lat=-89.999; /* south pole check */ ll_xy(&x,&y,lat,lon); if(x>=0.0&&x0.0&&y=0.0&&x0.0&&ylon_r) /* date line on screen */ { MinLon=-360.0; MaxLon= 360.0; } } /************************************************************************** ** ** ** ************************************************************************* */ int read_control(filename) char *filename; { int i,j,k,n=1,m,p=0,u,v; FILE *fp; char string1[100],string2[100],string2a[100],string3[100],string2b[100]; char nam[100],type; int numread,val,numcolors; fp=fopen(filename,"rb"); if(!fp) return(-1); fscanf(fp,"%s",string1); if(strlen(string1)==1) { type=string1[0]; if(type=='l'||type=='a'||type=='m'|| type=='s'||type=='p'||type=='S') { M.Type=type; numread=fscanf(fp,"%f%f%f%f",&M.Pixsize,&M.Clat,&M.Clon,&M.Space); if(numread!=4) { return(-6); } } } do { numread=fscanf(fp,"%s",string1); }while(numread>0&&strcmpi(string1,"begin_color")!=0); if(numread<1) return(-2); /* could not find 'begin_color' */ i=0; do { fscanf(fp,"%s",M.Color_Name[i]); if(strcmpi(M.Color_Name[i],"end_color")!=0) { numread=fscanf(fp,"%s%d%d%d", string1,&M.Color_Val[i][0],&M.Color_Val[i][1],&M.Color_Val[i][2]); } i+=1; }while(numread==4&&strcmpi(M.Color_Name[i-1],"end_color")!=0&&i=0&&val=0&&val=0&&val=0&&val=0&&val=0&&val=0&&val0&&strcmpi(string1,"begin_vector")!=0); if(numread<1) return(-3); /* could not find 'begin_vector' */ i=0; do { numread=fscanf(fp,"%s",M.Group_Name[i]); if(numread==1&&strcmpi(M.Group_Name[i],"begin_names")==0) { do { numread==fscanf(fp,"%s",String); if(strcmpi(String,"end_names")!=0) { strcpy(PlaceFile[p].name,String); fscanf(fp,"%s%s",string1,string2); { if(strcmpi(string2,"ON")==0) PlaceFile[p].on=1; else if(strcmpi(string2,"OFF")==0) PlaceFile[p].on=0; else { printf("'%s' is not marked ON or OFF\n\n", PlaceFile[p].name); exit(0); } } fscanf(fp,"%s%f%f%s", PlaceFile[p].filename, &PlaceFile[p].max_pix,&PlaceFile[p].min_pix, string3); val=get_color(string3); if(val>=0&&val=NUM_SYM) { printf("Too many symbols\n"); exit(0); } M.NumSymbol=p; } }while(strcmpi(String,"end_names")!=0); numread=3; } else if(numread==1&&strcmpi(M.Group_Name[i],"fillin_ihs")==0) { M.Fill_In=3; M.Fill_After=i-1; fscanf(fp,"%s%d",String,&M.Num_Fill); for(m=0;mM.Max_Fill) M.Max_Fill=k; M.Fill_Order[n++]=k; strcpy(M.Fill_Name[k],string3); } }while(strcmpi(string1,"end")!=0); numread=3; } else { if(numread==1&&strcmpi(M.Group_Name[i],"end_vector")!=0) { numread=fscanf(fp,"%s%d%s", string1,&M.Ns[i],string2); strcpy(T_Menu_L[i][0],M.Group_Name[i]); strcat(T_Menu_L[i][0]," OFF"); strcpy(T_Menu_L[i][1],M.Group_Name[i]); strcat(T_Menu_L[i][1]," ON"); if(strcmpi(string2,"ON")==0) M.Mm[i]=1; else M.Mm[i]=0; if(M.Ns[i]==0||M.Ns[i]>NUM_SIZE) { printf("Bad M.Ns = %d\n",M.Ns[i]); return(-4); /* too many vectors in a group */ } } for(k=0;k=0&&val