/* Change Log x 1. Set up 29/88/None toggle in RefreshMain() x 2. Don't call CovnertVertical() if horizontal datums are same. x 3. Set display and output files for no-rounding if no vertical conversion takes place. x 4. Modify to_printfile(), to_datafile() so they include horizontal. x 5. Recompile FORTRAN with extra fields.(Need Compilier) x 6. Change manual_input() to include 2D input. x 7. Check CORPSCON 3.01 for display of A & K. x 8. Get Blue Book format for horizontal. Also needed for x CORPSVER. x 9. Add other state plane zones to window. x 10. Get accuracies from NGS. x 11. Change NGVD/NAVD output to header in printfile. x 12. Modify file exists warning to execute just before conversions. 13. Add error messages for file opens 03/03/94 Added conversion to allow deg.dec and deg-min.dec in Batch File input 05/09/94 Fixed 32,000 point limit for read-in. 05/23/94 Fixed output unit problem in to_printfile(). 07/07/94 Added SP zone numbers to menus and output. 07/07/94 Added Vertical conversion warning to SetUp. 03/07/95 Fixed batch file read problem. A ',' in the first column caused an error on read in. 03/07/95 Fixed problem with erronous display of vertical output units in a printer file. */ //******************************************************************* // File: corps41.cpp // Authors: Jeff Ruby & Jeff Walker // Agency: U.S. Army Topographic Engineering Center // Last Modified: 11/1/94 // // This is the source file that is used to build the user // interface on the CORPSVER program. It accesses the // following files: // corpserr.cpp - displays error messages // corpsgui.cpp - user interface subroutines // corpskey.cpp - keyboard subroutines // spzones.cpp - builds state plane windows // // These files have .cpp extension but are, for the most part, // just C files. The only major exception is the comments. // Source was compiled on Borland Turbo C++. Many of the // graphics calls are Borland dependent. // // This program also uses system calls to four executable // files to do conversions from State Plane to Lat/Lon and // from UTM's to Lat/Lon. These files are: // corps27.exe - SP 27 to Lat/Lon 27 // corps83.exe - SP 83 to Lat/Lon 83 // corpsutm.exe - UTM's to Lat/Lon // corpsvrt.exe - vertical conversions //******************************************************************* #include #include #include #include #include #include #include #include #include #include #include #include "corpserr.h" #include "corps41.h" #include "corpsgui.h" #include "corpskey.h" #include "spzones.h" enum {CONSOLE,PRINTER,PRINTFILE,OUTFILE}; enum {IN_H,IN_V,OUT_H,OUT_V}; struct my_config { short IN, OUT, IN_SOURCE, OUTPUT, IN_UNIT, OUT_UNIT; int zone_in, zone_out; char file_in[60], pfile_out[60], dfile_out[60], project[31], agency[31]; short IN_VERT, OUT_VERT, IN_V_UNIT, OUT_V_UNIT; short in_menus[3], out_menus[3]; short Disclaimer; }; struct my_pt { char name[25]; double sp27x,sp27y, con27,k27, sp83x,sp83y, con83,k83, ddlat27,ddlon27, ddlat83,ddlon83, utm27x,utm27y, ucon27,uk27, utm83x,utm83y, ucon83,uk83, dlat,dlon, hgt29,hgt88, spinx,spiny, conin,kin, hgtin; int flag; }; struct date Today; enum {FALSE,TRUE}; struct my_config config; int Vert_Files_Found = TRUE; void main(void) { struct text_info before; int Exit = FALSE,tmp=0; int key=0; char ch; // Get screen info before program starts. gettextinfo(&before); _setcursortype(_NOCURSOR); // Call SetUp() the set up screen and config parameters. SetUp(); if((access("corpsnad.exe",0)!=0)||(access("corps27.exe",0)!=0)||(access("corps83.exe",0)!=0)||(access("corpsutm.exe",0)!=0)) {window(6,15,74,22); textattr(YELLOW+(BLUE<<4)); clrscr(); cprintf("Important Internal Files Not Locatable..\n\rHit Any Key to Quit\n\r"); getch(); } else if(_8087==0) { window(6,15,74,22); textattr(YELLOW+(BLUE<<4)); clrscr(); cprintf("No Math Co-Processor Present..\n\rHit Any Key to Quit\n\r"); getch(); } else { if((access("vertcone.94",0)!=0) ||(access("vertconc.94",0)!=0) ||(access("vertconw.94",0)!=0)) { // If Vertical conversion files are not found, disable vertical stuff. config.IN_VERT = config.OUT_VERT = 0; RefreshMain(2); RefreshMain(4); window(6,15,74,22); textattr(YELLOW+(BLUE<<4)); clrscr(); cprintf("Vertical Conversion Data Files Not Found\n\r" "Vertical Conversions Disabled\n\r" "Hit Any Key to Continue\n\r"); Vert_Files_Found = FALSE; getch(); clrscr(); } do { // Get input from keyboard. key = GetKey(); // Convert lower-case letters to upper-case. if((key>64)&&(key<91)) key+=32; switch(key) { // ESC will bring up QuitWindow() if at main menu. QuitWindow() will // issue user prompt to verify exit.0 case ESC: if(QuitWindow()) Exit = TRUE; break; // Call SetFormat() to set-up input point format. case '1': ESCBar(); SetFormat(1); MainBar(); break; // Call SetFormat() to set-up input point format. case '2': ESCBar(); SetFormat(2); MainBar(); break; // Call GetInput() to get the input source. case '3': ESCBar(); if((tmp=GetInput())!=0){ config.IN_SOURCE = tmp; // If input source is not manual input, prompt for input file name. if(config.IN_SOURCE>1) if(BuildText(20,16, " Enter File Name ", LIGHTGRAY,BLACK,BLACK,BLUE, BLUE,LIGHTGRAY,"Input File Name: ", config.file_in,20,1, sizeof("Input File Name: "), sizeof(config.file_in))==27) {MainBar();break;} // Call RefreshMain() to update screen. RefreshMain(5); } // Update screen. RefreshMain(6); MainBar(); break; // Toggle output destination. c-console, p-printer, f-printer file, // d-data file case 'c': SendDataSetup(0); break; case 'p': SendDataSetup(1); break; case 'f': SendDataSetup(2); break; case 'o': SendDataSetup(3); break; // Help. case F1: HelpBar(); help(); MainBar(); break; // Call GetHeader() to set company and project. case F2: QuitBar(); GetHeader(); MainBar(); break; // Build batch file. case F3: ESCBar(); BuildBatch(); RefreshMain(4); MainBar(); break; // Start conversion. case F4: MainBar(); convert(); ClearConsole(); MainBar(); break; default: break; } }while(Exit==FALSE); } // Reset window for pre-program display. window(1,1,80,25); textattr(before.attribute); _setcursortype(_NORMALCURSOR); clrscr(); // Write configuration file. rw_config(0); remove("INT$$#IN.BIN"); } void SetFormat(short opt) { // Temp variables. int zone=0; short hor=0,ver=0,h_unit=0,v_unit=0,*menus; // Set temps to current values. if(opt==1) { hor = config.IN; ver = config.IN_VERT; zone = config.zone_in; h_unit = config.IN_UNIT; v_unit = config.IN_V_UNIT; menus = config.in_menus; } else { hor = config.OUT; ver = config.OUT_VERT; zone = config.zone_out; h_unit = config.OUT_UNIT; v_unit = config.OUT_V_UNIT; menus = config.out_menus; } // Get horizontal format. If ESC is hit in GetHorizontal(), exit // the procedure without changing configuration. if(!GetHorizontal(&hor)) return; // If horizontal is not Lat/Lon, get appropriate zone. switch(hor) { // Get State Plane zone and units. If ESC is hit in // GetSPZone() or GetUnits(), exit the procedure // without changing configuration. case 1: case 2: if(!GetSPZone(hor%2,&zone,menus)) return; if(!GetUnits(&h_unit)) return; break; // Get UTM zone and units. If ESC is hit in // GetUTMZone() or GetUnits(), exit the procedure // without changing configuration. case 3: case 4: if(!GetUTMZone(&zone)) return; if(!GetUnits(&h_unit)) return; break; } // If values are accepted. Set horizontal config values // and refresh display. if(opt==1) { config.IN = hor; config.zone_in = zone; config.IN_UNIT= h_unit; RefreshMain(1); } else { config.OUT = hor; config.zone_out = zone; config.OUT_UNIT= h_unit; RefreshMain(3); } // Get vertical datum and units. If ESC is hit in // GetVertical() or GetUnits(), exit the procedure // without changing vertical configuration. if(Vert_Files_Found){ if(!GetVertical(&ver)) return; if(ver&&!GetUnits(&v_unit)) return; } // If values are accepted. Set vertical config values // and refresh display. if(opt==1) { config.IN_VERT = ver; config.IN_V_UNIT = v_unit; RefreshMain(2); if(ver==0){ config.OUT_VERT = 0; RefreshMain(4); } else if(!config.OUT_VERT){ config.OUT_VERT = config.IN_VERT==1 ? 2:1; config.OUT_V_UNIT = config.IN_V_UNIT; RefreshMain(4); } } else { config.OUT_VERT = ver; config.OUT_V_UNIT = v_unit; RefreshMain(4); if(ver==0){ config.IN_VERT = 0; RefreshMain(2); } else if(!config.IN_VERT){ config.IN_VERT = config.OUT_VERT==1 ? 2:1; config.IN_V_UNIT = config.OUT_V_UNIT; RefreshMain(2); } } } /* This procedure sets the current window to the console window */ void SetConsole(void) { window(6,15,74,22); textbackground(BLUE); textcolor(YELLOW); } /* This procedure sets and clears the console window. */ void ClearConsole(void) { SetConsole(); clrscr(); } /* reads and writes to the configuration file (which is in binary */ /* format) the default values. 1 is read, 0 is write.... */ void rw_config(short rw) { short i=0; char tmpstr[3]; FILE *fp; rw ? strcpy(tmpstr,"rb"):strcpy(tmpstr,"wb"); if((fp=fopen("CORPSCFG.BIN",tmpstr))!=NULL) { rw ? fread(&config,sizeof(struct my_config),1,fp): fwrite(&config,sizeof(struct my_config),1,fp);} else { config.IN=5; config.OUT=2; config.IN_SOURCE=config.OUTPUT=1; config.IN_UNIT=config.OUT_UNIT=config.IN_V_UNIT=config.OUT_V_UNIT=1; config.IN_VERT=1; config.OUT_VERT=2; config.zone_in=config.zone_out=4501; for(i=0;i<3;i++){ config.in_menus[i] = 1; config.out_menus[i] = 1; } config.Disclaimer=1; strcpy(config.file_in,"TESTIN.DAT"); strcpy(config.pfile_out,"PRINTER.DAT"); strcpy(config.dfile_out,"TESTOUT.DAT"); strcpy(config.project,"YOUR PROJECT"); strcpy(config.agency,"YOUR OFFICE");} fclose(fp); } /* This procedure sets the Send Data window values. ON/OFF values are toggled based on the choice value that is sent. If 'To Printer File' or 'To Data File' is toggle to ON, the user is prompted to enter a file name. */ void SendDataSetup(int choice) { int row=4,offset=0; short bit=1; char pstat[] = {" Printer File: "}; char ostat[] = {" Output File: "}; char stmp[22]; bit = bit<bordertoggle = ON; MakeWindow(tmp); delete tmp; tmp = new windowbox; // Set up main menu. default_windowbox(tmp); SetDimensions(tmp,3,3,45,12); SetColors(tmp,LIGHTGRAY,BLACK,BLACK,RED,BLUE); tmp->bordertoggle = ON; tmp->shadow = ON; strcpy(tmp->title," CORPSCON Main Menu "); MakeWindow(tmp); WriteText(3,2,tmp,"^1 - Input Data Format:"); WriteText(3,5,tmp,"^2 - Output Data Format:"); WriteText(3,8,tmp,"^3 - Input Data Source:"); SetColors(tmp,LIGHTGRAY,WHITE,BLACK,RED,BLUE); WriteText(3,3,tmp," Hor.:"); WriteText(3,4,tmp," Ver.:"); WriteText(3,6,tmp," Hor.:"); WriteText(3,7,tmp," Ver.:"); delete tmp; tmp = new windowbox; tmp = new windowbox; // Set up 'Send Data' window. default_windowbox(tmp); SetDimensions(tmp,49,3,76,10); SetColors(tmp,LIGHTGRAY,BLACK,BLACK,RED,BLUE); tmp->bordertoggle = ON; tmp->shadow = ON; strcpy(tmp->title," Send Data "); MakeWindow(tmp); WriteText(3,2,tmp,"To ^Console :"); WriteText(3,3,tmp,"To ^Printer :"); WriteText(3,4,tmp,"To Printer ^File:"); WriteText(3,6,tmp,"To ^Output File :"); delete tmp; tmp = new windowbox; // Set up console window. default_windowbox(tmp); SetDimensions(tmp,3,14,78,23); SetColors(tmp,BLUE,LIGHTGRAY,LIGHTGRAY,LIGHTGRAY,WHITE); tmp->bordertoggle = ON; strcpy(tmp->title," Console "); MakeWindow(tmp); delete tmp; // Display main bar. MainBar(); // Read config file. rw_config(1); // Initialize send data. for(i=0;i<4;i++) SendDataSetupInit(i); // Initialize Main for(i=1;i<=6;i++) RefreshMain(i); // if(config.Disclaimer) config.Disclaimer = Disclaimer(); } /* This procedure allows the user to build a batch file for input into CORPSVER. */ void BuildBatch(void) { struct date d; struct time t; int Point=1,Continue=1,choice=0; char FileName[] = {" Batch File Name: "}; char stuff[][80] = { " Latitude, Longitude, Elevation ", " Latitude, Longitude ", " Northing, Easting, Elevation ", " Northing, Easting " }; char stmp[121],x[80],y[80],z[80],name[80]; FILE *fout; getdate(&d); gettime(&t); strcpy(stmp,""); strcpy(x,""); strcpy(y,""); strcpy(z,""); strcpy(name,""); // Prompt user for file name. if(BuildText(20,16," Enter File Name ",LIGHTGRAY,BLACK,BLACK,BLUE, BLUE,LIGHTGRAY,FileName,config.file_in,20,1, sizeof(FileName),sizeof(config.file_in))==27) return; fout = fopen(config.file_in,"r"); // If file exists, issue warning message. if(fout!=NULL) { choice = FileExists(1); // If ESC return. if(choice==ESC) return; // Open for overwrite. else if(choice=='y'||choice=='Y') fout = fopen(config.file_in,"w"); // Open for append. else { fout = fopen(config.file_in,"a+"); rewind(fout); // Get current point number. while(!feof(fout)){ fgets(stmp,120,fout); if(feof(fout)) break; Point++; } } } // Open new file. else if((fout = fopen(config.file_in,"w"))==NULL) { CheckError(UNABLE_TO_OPEN_FOR_WRITING,config.file_in); return; } // Prompt user for batch file type: Lat,Lon,Hgt or X,Y,Z if((choice = BuildScroll(22,15,4," Batch File Type ", LIGHTGRAY,BLACK,BLACK,BLUE,BLUE,WHITE, stuff[0],sizeof(stuff)/sizeof(stuff[0]), sizeof(stuff[0]),1))==0) { fclose(fout); return; } QuitBar(); fprintf(fout,";USER GENERATED BATCH FILE\n"); fprintf(fout,";Software: CORPSCON v4.1\n"); fprintf(fout,";Company: %s\n",config.agency); fprintf(fout,";Project: %s\n",config.project); if(t.ti_hour<12) fprintf(fout,";Created: %d/%d/%d %2d:%02d AM\n", d.da_mon,d.da_day,d.da_year-1900,t.ti_hour,t.ti_min); else fprintf(fout,";Created: %d/%d/%d %2d:%02d PM\n", d.da_mon,d.da_day,d.da_year-1900,t.ti_hour-12,t.ti_min); // Loop, adding points to file until done. do { sprintf(stmp," Build Batch File - Point %d ",Point); switch(choice) { case 1: if(Get3DLL(stmp,y,x,z,name)) fprintf(fout,"%-20s,%16s,%16s,%16s\n",name,y,x,z); else Continue=0; break; case 2: if(Get2DLL(stmp,y,x,name)) fprintf(fout,"%-20s,%16s,%16s\n",name,y,x); else Continue=0; break; case 3: if(GetXYZ(stmp,x,y,z,name)) fprintf(fout,"%-20s,%16s,%16s,%16s\n",name,x,y,z); else Continue=0; break; case 4: if(GetXY(stmp,x,y,name)) fprintf(fout,"%-20s,%16s,%16s\n",name,x,y); else Continue=0; break; default: Continue=0; break; } Point++; }while(Continue); fclose(fout); } /* This procedure displays a scroll bar which allows the user to select the horizontal configuration. */ short GetHorizontal(short *old) { int choice=0; char stuff[][80] = {" State Plane, NAD 27 ", " State Plane, NAD 83 ", " UTM Coords., NAD 27 ", " UTM Coords., NAD 83 ", " Geographic Coordinates, NAD 27 ", " Geographic Coordinates, NAD 83 "}; choice = BuildScroll(20,15,6," Horizontal Format ", RED,YELLOW,YELLOW,WHITE,LIGHTGRAY,BLACK, stuff[0],sizeof(stuff)/sizeof(stuff[0]), sizeof(stuff[0]),*old); if(!choice) return 0; *old = choice; return 1; } /* This procedure displays a scroll bar which allows the user to select the vertical configuration. */ short GetVertical(short *old) { int choice=0,send=0; char stuff[][80] = { " NGVD 29 ", " NAVD 88 ", " None ", }; send = *old ? *old:3; choice = BuildScroll(30,15,6," Vertical Format ", RED,YELLOW,YELLOW,WHITE,LIGHTGRAY,BLACK, stuff[0],sizeof(stuff)/sizeof(stuff[0]), sizeof(stuff[0]),send); if(!choice) return 0; *old = choice==3 ? 0:choice; return 1; } /* This procedure displays a scroll bar which allows the user to select the type of units. */ short GetUnits(short *old) { int choice=0; char stuff[][80] = {" U.S. FOOT ", " INTL. FOOT ", " METER "}; choice = BuildScroll(30,15,3," Units ", RED,YELLOW,YELLOW,WHITE,LIGHTGRAY,BLACK, stuff[0],sizeof(stuff)/sizeof(stuff[0]), sizeof(stuff[0]),*old); if(!choice) return 0; *old = choice; return 1; } /* This procedure displays a scroll bar which allows the user to select the type of input. */ int GetInput(void) { int choice=0; char stuff[][80] = { " From Keyboard (Manual Entry) ", " From Batch File (ASCII Format) ", " From NGS Blue Book (*80*/*81*) ", }; choice = BuildScroll(20,15,6," Input File Format ", RED,YELLOW,YELLOW,WHITE,LIGHTGRAY,BLACK, stuff[0],sizeof(stuff)/sizeof(stuff[0]), sizeof(stuff[0]),config.IN_SOURCE); if(!choice) return 0; return choice; } /* This procedure refreshes a line in the main menu based on the input value 'opt'. */ void RefreshMain(short opt) { int row=5,col=13,offset=31,color=RED; char stmp[80]; strcpy(stmp,""); switch(opt) { // Horizontal case 1: strcpy(stmp,GetHoriz(config.IN,1)); break; // Vertical case 2: strcpy(stmp,GetVert(config.IN_VERT,1)); row++; break; case 3: strcpy(stmp,GetHoriz(config.OUT,0)); row+=3; break; case 4: strcpy(stmp,GetVert(config.OUT_VERT,0)); row+=4; break; // Input type case 5: strcpy(stmp,GetInputType(config.IN_SOURCE)); row+=6; col-=4; break; // Filename case 6: if(config.IN_SOURCE>1){ strncpy(stmp,config.file_in,15); stmp[15] = '\0'; } else strcpy(stmp,""); row+=5; col+=15; offset=16; break; default: break; } window(col,row,col+offset,row); textbackground(LIGHTGRAY); textcolor(color); clrscr(); cprintf(stmp); } /* This procedure returns a display string for horiz. for use in RefreshMain(). */ char *GetHoriz(short opt,short inout) { int zone=0; char stmp[80],units[15]; if(inout) { zone = config.zone_in; // Get string for units. strcpy(units,GetUnitStr(config.IN_UNIT)); } else { zone = config.zone_out; // Get string for units. strcpy(units,GetUnitStr(config.OUT_UNIT)); } switch(opt) { case 0: break; // SP 27 case 1: strcpy(stmp,GetAbbrev(1,zone)); strcat(stmp,", NAD 27"); strcat(stmp,units); break; // SP 83 case 2: strcpy(stmp,GetAbbrev(2,zone)); strcat(stmp,", NAD 83"); strcat(stmp,units); break; // UTM 27 case 3: sprintf(stmp,"UTM Zone %d, NAD 27",zone); strcat(stmp,units); break; // UTM 83 case 4: sprintf(stmp,"UTM Zone %d, NAD 83",zone); strcat(stmp,units); break; // Lat/Lon 27 case 5: strcpy(stmp,"Geographic, NAD 27\0"); break; // Lat/Lon 83 case 6: strcpy(stmp,"Geographic, NAD 83\0"); break; default: break; } return stmp; } /* This procedure returns a display string for vert. for use in RefreshMain(). */ char *GetVert(short opt,short inout) { char stmp[80],units[80]; // Get string for units. if(!opt) { strcpy(stmp,"None "); return stmp; } if(inout) strcpy(units,GetUnitStr(config.IN_V_UNIT)); else strcpy(units,GetUnitStr(config.OUT_V_UNIT)); switch(opt) { case 1: strcpy(stmp,"NGVD 29"); strcat(stmp,units); break; case 2: strcpy(stmp,"NAVD 88"); strcat(stmp,units); break; default: break; } return stmp; } /* This procedure returns a display string for units for use in RefreshMain(). */ char *GetUnitStr(short opt) { char stmp[20]; strcpy(stmp,""); switch(opt) { case 1: strcpy(stmp,", U.S. FT"); break; case 2: strcpy(stmp,", INTL. FT"); break; case 3: strcpy(stmp,", METERS"); break; default: break; } return stmp; } /* This procedure returns a display string for input type for use in RefreshMain(). */ char *GetInputType(short opt) { char stmp[40]; strcpy(stmp,""); switch(opt) { case 1: strcpy(stmp,"From Keyboard (Manual Entry)"); break; case 2: strcpy(stmp,"From Batch File (ASCII Format)"); break; case 3: strcpy(stmp,"From NGS Blue Book (*80*/*81*)"); break; case 4: strcpy(stmp,"From GeoLab File"); break; case 5: strcpy(stmp,"From FillNet File"); break; default: break; } return stmp; } /* This program creates a window for input of a Lat,Lon,Hgt point. */ short Get3DLL(char *title, char *lat, char *lon, char *hgt, char *name) { double dum1=0.0,dum2=0.0,dum3=0.0,sec=0.0; int i=0,valid=0,deg=0,min=0; char stat[][20] = {" Latitude: ", " Longitude: ", " Height: ", " Point Name: "}; char dynm[][80] = {"","","",""}; char stmp[121]; char old[4][80]; char sign; strcpy(dynm[0],lat); strcpy(dynm[1],lon); strcpy(dynm[2],hgt); strcpy(dynm[3],name); do { valid = 1; for(i=0;i<4;i++) strcpy(old[i],dynm[i]); BuildText(20,16,title,LIGHTGRAY,BLACK,BLACK,BLUE, BLUE,LIGHTGRAY,stat[0],dynm[0],20, sizeof(stat)/sizeof(stat[0]), sizeof(stat[0]),sizeof(dynm[0])); for(i=0;i<4;i++) if(strcmp(dynm[i],old[i])) break; if(i==4) return 0; if(!GetLatLon(&dum1,&dum2,dynm[0],dynm[1])) valid = 0; if(!sscanf(dynm[2],"%lf",&dum3)){ CheckError(INVALID_HEIGHT_ENTERED,dynm[2]); valid = 0; } }while(!valid); DD_to_DMS(dum1,&sign,°,&min,&sec); sprintf(dynm[0],"%c%d %d %lf",sign,deg,min,sec); DD_to_DMS(dum2,&sign,°,&min,&sec); sprintf(dynm[1],"%c%d %d %lf",sign,deg,min,sec); strcpy(lat,dynm[0]); strcpy(lon,dynm[1]); strcpy(hgt,dynm[2]); strcpy(name,dynm[3]); return 1; } /* This program creates a window for input of a Lat,Lon point. */ short Get2DLL(char *title, char *lat, char *lon, char *name) { double dum1=0.0,dum2=0.0,sec=0.0; int i=0,valid=0,deg=0,min=0; char stat[][20] = {" Latitude: ", " Longitude: ", " Point Name: "}; char dynm[][80] = {"","","",""}; char stmp[121]; char old[3][80]; char sign; strcpy(dynm[0],lat); strcpy(dynm[1],lon); strcpy(dynm[2],name); do { valid = 1; for(i=0;i<3;i++) strcpy(old[i],dynm[i]); BuildText(20,16,title,LIGHTGRAY,BLACK,BLACK,BLUE, BLUE,LIGHTGRAY,stat[0],dynm[0],20, sizeof(stat)/sizeof(stat[0]), sizeof(stat[0]),sizeof(dynm[0])); for(i=0;i<3;i++) if(strcmp(dynm[i],old[i])) break; if(i==3) return 0; if(!GetLatLon(&dum1,&dum2,dynm[0],dynm[1])) valid = 0; }while(!valid); DD_to_DMS(dum1,&sign,°,&min,&sec); sprintf(dynm[0],"%c%d %d %lf",sign,deg,min,sec); DD_to_DMS(dum2,&sign,°,&min,&sec); sprintf(dynm[1],"%c%d %d %lf",sign,deg,min,sec); strcpy(lat,dynm[0]); strcpy(lon,dynm[1]); strcpy(name,dynm[2]); return 1; } /* This program creates a window for input of a x,y,z point. */ short GetXYZ(char *title, char *x, char *y, char *z, char *name) { double dum1=0.0; int i=0,valid=0; char stat[][20] = {" Northing: ", " Easting: ", " Elevation: ", " Point Name: "}; char dynm[][80] = {"","","",""}; char stmp[121]; char old[4][80]; strcpy(dynm[0],y); strcpy(dynm[1],x); strcpy(dynm[2],z); strcpy(dynm[3],name); do { valid = 1; for(i=0;i<4;i++) strcpy(old[i],dynm[i]); BuildText(20,16,title,LIGHTGRAY,BLACK,BLACK,BLUE, BLUE,LIGHTGRAY,stat[0],dynm[0],20, sizeof(stat)/sizeof(stat[0]), sizeof(stat[0]),sizeof(dynm[0])); for(i=0;i<4;i++) if(strcmp(dynm[i],old[i])) break; if(i==4) return 0; if(!sscanf(dynm[0],"%lf",&dum1)){ CheckError(INVALID_NORTHING_ENTERED,dynm[0]); valid = 0; } if(!sscanf(dynm[1],"%lf",&dum1)){ CheckError(INVALID_EASTING_ENTERED,dynm[1]); valid = 0; } if(!sscanf(dynm[2],"%lf",&dum1)){ CheckError(INVALID_HEIGHT_ENTERED,dynm[2]); valid = 0; } }while(!valid); strcpy(y,dynm[0]); strcpy(x,dynm[1]); strcpy(z,dynm[2]); strcpy(name,dynm[3]); return 1; } /* This program creates a window for input of a x,y point. */ short GetXY(char *title, char *x, char *y, char *name) { double dum1=0.0; int i=0,valid=0; char stat[][20] = {" Northing: ", " Easting: ", " Point Name: "}; char dynm[][80] = {"","","",""}; char stmp[121]; char old[3][80]; strcpy(dynm[0],y); strcpy(dynm[1],x); strcpy(dynm[2],name); do { valid = 1; for(i=0;i<3;i++) strcpy(old[i],dynm[i]); BuildText(20,16,title,LIGHTGRAY,BLACK,BLACK,BLUE, BLUE,LIGHTGRAY,stat[0],dynm[0],20, sizeof(stat)/sizeof(stat[0]), sizeof(stat[0]),sizeof(dynm[0])); for(i=0;i<3;i++) if(strcmp(dynm[i],old[i])) break; if(i==3) return 0; if(!sscanf(dynm[0],"%lf",&dum1)){ CheckError(INVALID_NORTHING_ENTERED,dynm[0]); valid = 0; } if(!sscanf(dynm[1],"%lf",&dum1)){ CheckError(INVALID_EASTING_ENTERED,dynm[1]); valid = 0; } }while(!valid); strcpy(y,dynm[0]); strcpy(x,dynm[1]); strcpy(name,dynm[2]); return 1; } /* This program creates a window for input of the company and project names. */ short GetHeader(void) { char stat[][20] = {" Office: ", " Project: "}; char dynm[][80] = {"",""}; strcpy(dynm[0],config.agency); strcpy(dynm[1],config.project); if(!BuildText(20,16," Title Information ",LIGHTGRAY,BLACK,BLACK,BLUE, BLUE,LIGHTGRAY,stat[0],dynm[0],25, sizeof(stat)/sizeof(stat[0]), sizeof(stat[0]),sizeof(dynm[0]))) return 0; strncpy(config.agency,dynm[0],30); strncpy(config.project,dynm[1],30); return 1; } /* This program creates a window for input of a UTM zone. */ short GetUTMZone(int *zone) { int dum,inzone; short valid=0; char stat[] = {" Enter UTM zone(1-60): "}; char stmp[20]; inzone = *zone; if(inzone>36) inzone = 1; sprintf(stmp,"%d",inzone); do { if(BuildText(20,16," UTM ZONE ",LIGHTGRAY,BLACK,BLACK,BLUE, BLUE,LIGHTGRAY,stat,stmp,4,1,sizeof(stat), sizeof(stmp))==27) return 0; if(!sscanf(stmp,"%d",&dum)||dum<1||dum>60){ CheckError(INVALID_UTMZONE_ENTERED,stmp); valid = 0; } else valid=1; }while(!valid); *zone = dum; return 1; } /* This program reads an abbreviation for a state plane zone from a file. */ char *GetAbbrev(short opt,int zone) { int dum,i=0; char stmp[121],file[80]; char s27[] = {"abbrev.s27"}; char s83[] = {"abbrev.s83"}; FILE *fp; if(opt%2) strcpy(file,s27); else strcpy(file,s83); if((fp=fopen(file,"r"))==NULL){ CheckError(FILE_NOT_FOUND,file); return NULL; } while(!feof(fp)) { fgets(stmp,120,fp); stmp[strlen(stmp)-1] = '\0'; sscanf(stmp,"%d",&dum); if(zone==dum){ while(stmp[i]!=' ') i++; fclose(fp); return stmp+i+1; } } fclose(fp); return NULL; } /* This procedure converts a Dec.Deg to Deg-Min-Dec.Sec */ void DD_to_DMS(double dd, char *sign,int *deg, int *min, double *sec) { double dd2=0; int d,m; double s; dd2 = dd<0?dd2-dd:dd; d = (int)(dd2); m = (int)((dd2 - d) * 60.0); s = (dd2 - (double)(d + (m/60.0)))*3600.0; if(s>=59.99999) { s = 0.0; m ++; } if(m==60) { m = 0; d ++; } *deg = d; *min = m; *sec = s; *sign = dd<0?'-':' '; } /* creates a binary equivalent of that data, the format of*/ /* this file is as follows: Name(1-20),X,Y or Name(1-20), */ /* dd mm ss.sssss,dd mm ss.sssss. Also lines beginning */ /* with a semi-colon are considered to be comments and are*/ /* ignored. Returns number of pts are 0 on error...*/ long get_ascii_in(char filein[],char fileout[]) { FILE *tmp_file,*out_file; struct my_pt pt; long count=0; char line[200],name[50],str1[25],str2[25],str3[25]; if((tmp_file=fopen(filein,"rt"))==NULL){ CheckError(FILE_NOT_FOUND,filein); return 0; } if((out_file=fopen(fileout,"wb"))==NULL){ CheckError(UNABLE_TO_OPEN_FOR_WRITING,fileout); return 0; } while(!feof(tmp_file)) { if(kbhit()&&getch()==ESC) return 0; fgets(line,198,tmp_file); if(feof(tmp_file))break; if(line[0]==';'||line[0]=='#') continue; if(strlen(line) < 6) continue; if(*line==',') strcpy(name,""); else strcpy(name,strtok(line,",")); strncpy(pt.name,name,20); pt.name[20]='\0'; if(*line==',') strcpy(str1,strtok(line,",")); else strcpy(str1,strtok(NULL,",")); if(config.IN_VERT){ strcpy(str2,strtok(NULL,",")); strcpy(str3,strtok(NULL,"\0")); } else strcpy(str2,strtok(NULL,",")); pt.flag = 0; if(config.IN==1) { sscanf(str1,"%lf",&pt.sp27x); sscanf(str2,"%lf",&pt.sp27y); pt.spinx = pt.sp27x; pt.spiny = pt.sp27y; } else if(config.IN==2) { sscanf(str1,"%lf",&pt.sp83x); sscanf(str2,"%lf",&pt.sp83y); pt.spinx = pt.sp83x; pt.spiny = pt.sp83y; } else if(config.IN==3) { sscanf(str1,"%lf",&pt.utm27x); sscanf(str2,"%lf",&pt.utm27y); } else if(config.IN==4) { sscanf(str1,"%lf",&pt.utm83x); sscanf(str2,"%lf",&pt.utm83y); } else if(config.IN==5) { ConvertToDecDeg(&pt.ddlat27,str1) ? 0:CheckError(INVALID_LAT_VALUE,str1); pt.ddlat27>90.0||pt.ddlat27<0.0 ? CheckError(INVALID_LAT_VALUE,str1):0; ConvertToDecDeg(&pt.ddlon27,str2) ? 0:CheckError(INVALID_LON_VALUE,str2); pt.ddlon27>360.0||pt.ddlon27<0.0 ? CheckError(INVALID_LON_VALUE,str2):0; } else if(config.IN==6) { ConvertToDecDeg(&pt.ddlat83,str1) ? 0:CheckError(INVALID_LAT_VALUE,str1); pt.ddlat83>90.0||pt.ddlat83<0.0 ? CheckError(INVALID_LAT_VALUE,str1):0; ConvertToDecDeg(&pt.ddlon83,str2) ? 0:CheckError(INVALID_LON_VALUE,str2); pt.ddlon83>360.0||pt.ddlon83<0.0 ? CheckError(INVALID_LON_VALUE,str2):0; } if(config.IN_VERT==0){ pt.hgt29 = 0.0; pt.hgt88 = 0.0; pt.hgtin = 0.0; } else if(config.IN_VERT==1){ if(sscanf(str3,"%lf",&pt.hgt29)!=1) pt.hgt29 = 0.0; pt.hgt88 = pt.hgtin = pt.hgt29; if(config.IN_VERT==config.OUT_VERT) pt.hgt29 = cvt(config.IN_V_UNIT,config.OUT_V_UNIT,pt.hgt29); } else if(config.IN_VERT==2){ if(sscanf(str3,"%lf",&pt.hgt88)!=1) pt.hgt88 = 0.0; pt.hgt29 = pt.hgtin = pt.hgt88; if(config.IN_VERT==config.OUT_VERT) pt.hgt88 = cvt(config.IN_V_UNIT,config.OUT_V_UNIT,pt.hgt88); } fwrite(&pt,sizeof(struct my_pt),1,out_file); count++; } fclose(tmp_file); fclose(out_file); return count; } int manual_input(char file[]) { double dum=0.0,sec=0.0; int deg=0,min=0; short Continue=0; char x[40],y[40],z[40],name[50]; struct my_pt Pt; FILE *tmp_file; strcpy(x,""); strcpy(y,""); strcpy(z,""); strcpy(name,""); if((tmp_file = fopen(file,"wb"))==NULL){ CheckError(UNABLE_TO_OPEN_FOR_WRITING,file); return 0; } Pt.sp27x=Pt.sp27y=Pt.sp83x=Pt.sp83y=Pt.utm27x=Pt.utm27y=Pt.spinx=Pt.spiny=0.0; Pt.utm83x=Pt.utm83y=Pt.ddlat27=Pt.ddlon27=Pt.ddlat83=Pt.ddlon83=0.0; Pt.hgt29=Pt.hgt88=Pt.hgtin=0.0; Pt.flag = 0; if(config.IN<5) { if(config.IN_VERT) Continue = GetXYZ(" Manual Input - X,Y,Z ",x,y,z,name); else Continue = GetXY(" Manual Input - X,Y ",x,y,name); } else { if(config.IN_VERT) Continue = Get3DLL(" Manual Input - Lat,Lon,Elev. ",y,x,z,name); else Continue = Get2DLL(" Manual Input - Lat,Lon ",y,x,name); } if(!Continue){ fclose(tmp_file); return 0; } switch(config.IN) { case 1: sscanf(x,"%lf",&dum); Pt.sp27x = Pt.spinx = dum; sscanf(y,"%lf",&dum); Pt.sp27y = Pt.spiny = dum; break; case 2: sscanf(x,"%lf",&dum); Pt.sp83x = Pt.spinx = dum; sscanf(y,"%lf",&dum); Pt.sp83y = Pt.spiny = dum; break; case 3: sscanf(x,"%lf",&dum); Pt.utm27x = dum; sscanf(y,"%lf",&dum); Pt.utm27y = dum; break; case 4: sscanf(x,"%lf",&dum); Pt.utm83x = dum; sscanf(y,"%lf",&dum); Pt.utm83y = dum; break; case 5: sscanf(y,"%d %d %lf",°,&min,&sec); Pt.ddlat27 = (double)(deg + min/60.0 + sec/3600.0); sscanf(x,"%d %d %lf",°,&min,&sec); Pt.ddlon27 = (double)(deg + min/60.0 + sec/3600.0); break; case 6: sscanf(y,"%d %d %lf",°,&min,&sec); Pt.ddlat83 = (double)(deg + min/60.0 + sec/3600.0); sscanf(x,"%d %d %lf",°,&min,&sec); Pt.ddlon83 = (double)(deg + min/60.0 + sec/3600.0); break; default: break; } switch(config.IN_VERT) { case 0: break; case 1: sscanf(z,"%lf",&dum); Pt.hgt29 = Pt.hgtin = dum; if(config.IN_VERT==config.OUT_VERT) Pt.hgt29 = cvt(config.IN_V_UNIT,config.OUT_V_UNIT,Pt.hgt29); break; case 2: sscanf(z,"%lf",&dum); Pt.hgt88 = Pt.hgtin = dum; if(config.IN_VERT==config.OUT_VERT) Pt.hgt88 = cvt(config.IN_V_UNIT,config.OUT_V_UNIT,Pt.hgt88); break; } strcpy(Pt.name,name); fwrite(&Pt,sizeof(struct my_pt),1,tmp_file); fclose(tmp_file); return 1; } /* convert performs the conversion process and writes the */ /* output to a file, so that another procedure can read */ /* the information and send it to the correct media. */ void convert(void) { long NREC; short opt,DispLine=0; char file[60]; FILE *CTRL_fp, *fptmp; if((config.OUTPUT&4)&&fopen(config.pfile_out,"r")!=NULL) do { opt = FileExists(0); if(opt==ESC) return; else if(opt=='y'||opt=='Y'){ remove(config.pfile_out); break; } }while(!(opt=='y'&&opt=='Y')); if((config.OUTPUT&8)&&fopen(config.dfile_out,"r")!=NULL) switch(FileExists(1)) { case ESC: return; case 'y': case 'Y': remove(config.dfile_out); break; default: break; } remove("corps.err"); if(config.IN_SOURCE>1) { ESCBar(); ClearConsole(); gotoxy(1,++DispLine);cprintf("Reading Input File...\n\r"); if(config.IN_SOURCE==2) NREC=get_ascii_in(config.file_in,"INT$$#IN.BIN"); if(config.IN_SOURCE==3) NREC=get_bluebook_in(config.file_in,"INT$$#IN.BIN"); strcpy(file,"INT$$#IN.BIN "); } else { strcpy(file,"INT$$#IN.BIN "); NREC=1; QuitBar(); if(!manual_input(file)) return; ESCBar(); ClearConsole(); } if(NREC==0) { ClearConsole(); gotoxy(1,1);cprintf("No Points to Convert..\n\r"); return; } /* start conversion process.. */ if(config.IN<5) { if((CTRL_fp = fopen("INT$$IN.ASC","w"))==NULL) { ClearConsole(); gotoxy(1,1);cprintf("Error, Cannot open Control file..."); return;} SetConsole();gotoxy(1,++DispLine); switch (config.IN) { case 1: /* call pcgp27 */ cprintf("Converting SP to NAD 27 Geographic...\n\r"); fprintf(CTRL_fp,"%s\n1\n%d\n%d\n0\n",file,config.IN_UNIT,config.zone_in); fclose(CTRL_fp); system("CORPS27 < INT$$IN.ASC >>CORPS.ERR"); break; case 2: /* call spcs83 */ cprintf("Converting SP to NAD 83 Geographic...\n\r"); fprintf(CTRL_fp,"%s\n1\n%d\n%d\n0\n",file,config.IN_UNIT,config.zone_in); fclose(CTRL_fp); system("CORPS83 < INT$$IN.ASC >>CORPS.ERR"); break; case 3: /* call utm_s 27 */ cprintf("Converting UTM to NAD 27 Geographic...\n\r"); fprintf(CTRL_fp,"2\n1\n%d\n%s\n%d\n",config.IN_UNIT,file,config.zone_in); fclose(CTRL_fp); system("CORPSUTM < INT$$IN.ASC >>CORPS.ERR"); break; case 4: /* call utm_s 83 */ cprintf("Converting UTM to NAD 83 Geographic...\n\r"); fprintf(CTRL_fp,"2\n2\n%d\n%s\n%d\n",config.IN_UNIT,file,config.zone_in); fclose(CTRL_fp); system("CORPSUTM < INT$$IN.ASC >>CORPS.ERR"); break; } remove("INT$$#IN.BIN"); rename("INT$OUT","INT$$#IN.BIN"); _fpreset(); /* Resets 80x87 Math Co-Processor */ } if(kbhit()&&getch()==ESC) return; /* if config.IN is odd/even and config.OUT is even/odd perform nadcon transformation */ if((config.IN&1)^(config.OUT&1)) { if((CTRL_fp = fopen("INT$$IN.ASC","w"))==NULL) { textattr(YELLOW+(BLUE<<4)); ClearConsole(); gotoxy(1,1);cprintf("Error, Cannot open Control file..."); return;} SetConsole();gotoxy(1,++DispLine); if(config.IN&1) {/* 27 to 83 */ cprintf("Converting NAD 27 to NAD 83 Geographic...\n\r"); fprintf(CTRL_fp,"%s\n1\n",file);} else { /* 83 to 27 */ cprintf("Converting NAD 83 to NAD 27 Geographic...\n\r"); fprintf(CTRL_fp,"%s\n2\n",file);} fclose(CTRL_fp); system("CORPSNAD < INT$$IN.ASC >> CORPS.ERR"); remove("INT$$#IN.BIN"); rename("INT$OUT","INT$$#IN.BIN"); _fpreset(); /* Resets 80x87 Math Co-Processor */ } if(kbhit()&&getch()==ESC) return; if(config.OUT < 5) { if((CTRL_fp = fopen("INT$$IN.ASC","w"))==NULL) { textattr(YELLOW+(BLUE<<4)); gotoxy(1,1);cprintf("Error, Cannot open Control file..."); return;} SetConsole();gotoxy(1,++DispLine); switch (config.OUT) { case 1: // call pcgp27 cprintf("Converting NAD 27 Geographic to SP...\n\r"); fprintf(CTRL_fp,"%s\n0\n%d\n%d\n1\n",file,config.OUT_UNIT,config.zone_out); fclose(CTRL_fp); system("CORPS27 < INT$$IN.ASC >> CORPS.ERR"); break; case 2: // call spcs83 cprintf("Converting NAD 83 Geographic to SP...\n\r"); fprintf(CTRL_fp,"%s\n0\n%d\n%d\n1\n",file,config.OUT_UNIT,config.zone_out); fclose(CTRL_fp); system("CORPS83 < INT$$IN.ASC >> CORPS.ERR"); break; case 3: // call utm_s 27 cprintf("Converting NAD 27 Geographic to UTM...\n\r"); fprintf(CTRL_fp,"1\n1\n%d\n%s\n%d\n",config.OUT_UNIT,file,config.zone_out); fclose(CTRL_fp); system("CORPSUTM < INT$$IN.ASC >> CORPS.ERR"); break; case 4: // call utm_s 83 cprintf("Converting NAD 83 Geographic to UTM...\n\r"); fprintf(CTRL_fp,"1\n2\n%d\n%s\n%d\n",config.OUT_UNIT,file,config.zone_out); fclose(CTRL_fp); system("CORPSUTM < INT$$IN.ASC >> CORPS.ERR"); break; } remove("INT$$#IN.BIN"); rename("INT$OUT","INT$$#IN.BIN"); _fpreset(); // Resets 80x87 Math Co-Processor } if(kbhit()&&getch()==ESC) return; // if(config.IN_VERT==config.OUT_VERT && // config.IN_V_UNIT!=config.OUT_V_UNIT){ // } if(config.IN_VERT &&config.OUT_VERT &&(config.IN_VERT!=config.OUT_VERT)) { // Write to control file. // 0 for 29 to 88 // 1 for 88 to 29 SetConsole();gotoxy(1,++DispLine); cprintf("Converting Vertical...\n\r"); if((CTRL_fp = fopen("INT$$IN.ASC","w"))==NULL) { textattr(YELLOW+(BLUE<<4)); gotoxy(1,1);cprintf("Error, Cannot open Control file..."); return;} SetConsole();gotoxy(1,++DispLine); switch (config.IN_VERT) { case 1: // convert 29 to 88 cprintf("Converting NGVD 29 to NAVD 88...\n\r"); fprintf(CTRL_fp,"%s\n%d\n0\n%d\n%d\n",file,config.IN%2, config.IN_V_UNIT,config.OUT_V_UNIT); fclose(CTRL_fp); system("CORPSVRT < INT$$IN.ASC >> CORPS.ERR"); break; case 2: // convert 88 to 29 cprintf("Converting NAVD 88 to NGVD 29...\n\r"); fprintf(CTRL_fp,"%s\n%d\n1\n%d\n%d\n",file,config.IN%2, config.IN_V_UNIT,config.OUT_V_UNIT); fclose(CTRL_fp); system("CORPSVRT < INT$$IN.ASC >> CORPS.ERR"); break; } remove("INT$$#IN.BIN"); rename("INT$OUT","INT$$#IN.BIN"); _fpreset(); // Resets 80x87 Math Co-Processor } /* take to output format */ if(config.OUTPUT&1) to_console("INT$$#IN.BIN",NREC); if(config.OUTPUT&2) to_printer("INT$$#IN.BIN",NREC); if(config.OUTPUT&4) to_printfile("INT$$#IN.BIN",NREC); if(config.OUTPUT&8) to_datafile("INT$$#IN.BIN",NREC); /* Return to calling program */ remove("INT$$#IN.BIN"); remove("INT$$IN.ASC"); _fpreset(); /* Resets 80x87 Math Co-Processor */ clrscr(); } /* this procedure prints the results to the main console */ /* screen and prompts the user to toggle thru them (if */ /* NREC > 1).. ESC Quits */ void to_console(char file[],long NREC) { FILE *tmp_file; char sign=' '; long count=1; int i,value,x,ch=0,deg,min; double sec,in_ht,out_ht; char in_str[30],out_str[30]; struct my_pt pt; strcpy(in_str,""); strcpy(out_str,""); if(config.IN_SOURCE==1) ESCBar(); else ToConsoleBar(); window(6,15,74,22); textattr(YELLOW+(BLUE<<4)); clrscr(); if((tmp_file=fopen(file,"rb"))!=NULL) for(;;){ ClearConsole(); fseek(tmp_file,(long)((count-1)*sizeof(struct my_pt)),SEEK_SET); fread(&pt,sizeof(struct my_pt),1,tmp_file); gotoxy(1,1);cprintf("NAME: %19s",pt.name); gotoxy(35,1);clreol();cprintf("Record %ld of %ld",count,NREC); gotoxy(1,2);cprintf(" INPUT OUTPUT"); gotoxy(1,6);cprintf(" Convergence DD(A) & Scale Factor (K)"); for(i=0;i<=1;i++) { x = i?1:30; value = i?config.IN:config.OUT; switch(value) { case 1: gotoxy(x,3); i ? cprintf(" N: %14.5lf",pt.spiny):cprintf(" N: %14.5lf",pt.sp27y); gotoxy(x,4); i ? cprintf(" E: %14.5lf",pt.spinx):cprintf(" E: %14.5lf",pt.sp27x); i ? DD_to_DMS(pt.conin,&sign,°,&min,&sec):DD_to_DMS(pt.con27,&sign,°,&min,&sec); gotoxy(x,7);cprintf(" A: %c%02d %02d %08.5lf",sign,deg,min,sec); gotoxy(x,8); i ? cprintf(" K: %3.9lf",pt.kin):cprintf(" K: %3.9lf",pt.k27); break; case 2: gotoxy(x,3); i ? cprintf(" N: %14.5lf",pt.spiny):cprintf(" N: %14.5lf",pt.sp83y); gotoxy(x,4); i ? cprintf(" E: %14.5lf",pt.spinx):cprintf(" E: %14.5lf",pt.sp83x); i ? DD_to_DMS(pt.conin,&sign,°,&min,&sec):DD_to_DMS(pt.con83,&sign,°,&min,&sec); gotoxy(x,7);cprintf(" A: %c%02d %02d %08.5lf",sign,deg,min,sec); gotoxy(x,8); i ? cprintf(" K: %3.9lf",pt.kin):cprintf(" K: %3.9lf",pt.k83); break; case 3: gotoxy(x,3);cprintf(" N: %14.5lf",pt.utm27y); gotoxy(x,4);cprintf(" E: %14.5lf",pt.utm27x); DD_to_DMS(pt.ucon27,&sign,°,&min,&sec); gotoxy(x,7);cprintf(" A: %c%02d %02d %08.5lf",sign,deg,min,sec); gotoxy(x,8);cprintf(" K: %3.9lf",pt.uk27); break; case 4: gotoxy(x,3);cprintf(" N: %14.5lf",pt.utm83y); gotoxy(x,4);cprintf(" E: %14.5lf",pt.utm83x); DD_to_DMS(pt.ucon83,&sign,°,&min,&sec); gotoxy(x,7);cprintf(" A: %c%02d %02d %08.5lf",sign,deg,min,sec); gotoxy(x,8);cprintf(" K: %3.9lf",pt.uk83); break; case 5: DD_to_DMS(pt.ddlat27,&sign,°,&min,&sec); gotoxy(x,3);cprintf("LAT: %02d %02d %08.5lf",deg,min,sec); DD_to_DMS(pt.ddlon27,&sign,°,&min,&sec); gotoxy(x,4);cprintf("LON: %03d %02d %08.5lf",deg,min,sec); break; case 6: DD_to_DMS(pt.ddlat83,&sign,°,&min,&sec); gotoxy(x,3);cprintf("LAT: %02d %02d %08.5lf",deg,min,sec); DD_to_DMS(pt.ddlon83,&sign,°,&min,&sec); gotoxy(x,4);cprintf("LON: %03d %02d %08.5lf",deg,min,sec); break; } } if(config.IN_VERT) { switch(config.IN_VERT) { case 1: //in_ht = pt.hgt29; strcpy(in_str,"NGVD 29 HT: "); break; case 2: //in_ht = pt.hgt88; strcpy(in_str,"NAVD 88 HT: "); break; default: break; } //gotoxy(1,5);cprintf("%s%lf",in_str,in_ht); gotoxy(1,5);cprintf("%s%lf",in_str,pt.hgtin); switch(config.OUT_VERT) { case 1: out_ht = pt.hgt29; strcpy(out_str,"NGVD 29 HT: "); break; case 2: out_ht = pt.hgt88; strcpy(out_str,"NAVD 88 HT: "); break; default: break; } if(pt.flag&16){ gotoxy(30,5);cprintf("Could not be converted by Vertcon.");} else if(config.IN_VERT==config.OUT_VERT){ gotoxy(30,5);cprintf("%s%lf",out_str,out_ht);} else if(config.OUT_V_UNIT<3){ gotoxy(30,5);cprintf("%s%8.2lf",out_str,out_ht);} else{gotoxy(30,5);cprintf("%s%8.3lf",out_str,out_ht);} } ch = getch(); if(ch==27) break; if(ch==81) count=count==NREC?1:count+1; if(ch==73) count=count==1?NREC:count-1; } fclose(tmp_file); clrscr(); } /* converts the point to the format desired from the current */ /* format, returns the value as a double. US Foot-1, INTL */ /* FOOT-2, Meters-3..... */ double cvt(short curr,short des,double pt) { double UF=3937.0, // US FEET FOR UM=1200.0, // METERS CONVERSION. IF=1250.0, // INTERNATIONAL FEET FOR IM=381.0; // METERS CONVERSION. if(curr==des) return pt; if(curr==1) { pt*=(double)(UM/UF); if(des==2) pt*=(double)(IF/IM);} if(curr==2) { pt*=(double)(IM/IF); if(des==1) pt*=(double)(UF/UM);} if(curr==3) pt=des==1?pt*(double)(UF/UM):pt*(double)(IF/IM); return pt; } /* this procedure prints the results to a data file specified */ /* by the user in the main output menu, the format of the data*/ /* is generic NAME,X,Y (or LAT LON) with two comment lines at */ /* the top indicating what the data points were transferred */ /* from and to (i.e. 27 State Plane zone 4602 to NAD 83 Geo) */ void to_datafile(char file[],long NREC) { FILE *tmp_file,*out_file; struct date d; struct time t; long count; int latd,lond,latm,lonm; double lats,lons,height; char unit[40],spzone[40]; char sign=' '; struct my_pt pt; strcpy(unit,""); strcpy(spzone,""); getdate(&d); gettime(&t); window(6,15,74,22); textattr(YELLOW+(BLUE<<4)); clrscr(); cprintf("Formating data for Output file..\n\r"); if(((out_file=fopen(config.dfile_out,"a"))!=NULL)&&((tmp_file=fopen(file,"rb"))!=NULL)) { // strcpy(unit,GetUnitStr(config.IN_UNIT)); fprintf(out_file,";Software: CORPSCON v4.1\n;Agency: %s\n;Project: %s\n",config.agency,config.project); if(t.ti_hour<12) fprintf(out_file,";Created: %d/%d/%d %2d:%02d AM\n", d.da_mon,d.da_day,d.da_year-1900,t.ti_hour,t.ti_min); else fprintf(out_file,";Created: %d/%d/%d %2d:%02d PM\n", d.da_mon,d.da_day,d.da_year-1900,t.ti_hour-12,t.ti_min); strcpy(unit,GetUnitStr(config.OUT_UNIT)); if(config.OUT==1){ strcpy(spzone,GetAbbrev(1,config.zone_out)); fprintf(out_file,";Coordinates on NAD 27 State Plane - %s%s\n",spzone,unit); } if(config.OUT==2){ strcpy(spzone,GetAbbrev(2,config.zone_out)); fprintf(out_file,";Coordinates on NAD 83 State Plane - %s%s\n",spzone,unit); } if(config.OUT==3) fprintf(out_file,";Coordinates on NAD 27 UTM Zone %04d%s\n",config.zone_out,unit); if(config.OUT==4) fprintf(out_file,";Coordinates on NAD 83 UTM Zone %04d%s\n",config.zone_out,unit); if(config.OUT==5) fprintf(out_file,";Coordinates on NAD 27 Geographic Coordinates\n"); if(config.OUT==6) fprintf(out_file,";Coordinates on NAD 83 Geographic Coordinates\n"); strcpy(unit,GetUnitStr(config.OUT_V_UNIT)); if(config.OUT_VERT==1) fprintf(out_file,";Vertical on NGVD 29%s\n",unit); else if(config.OUT_VERT==2) fprintf(out_file,";Vertical on NAVD 88%s\n",unit); for(count=1;count<=NREC;count++){ fread(&pt,sizeof(struct my_pt),1,tmp_file); //height = config.IN_VERT==1 ? pt.hgt88:pt.hgt29; height = pt.hgtin; if(config.OUT==1) fprintf(out_file,"%-20s,%14.5lf,%14.5lf",pt.name,pt.sp27x,pt.sp27y); if(config.OUT==2) fprintf(out_file,"%-20s,%14.5lf,%14.5lf",pt.name,pt.sp83x,pt.sp83y); if(config.OUT==3) fprintf(out_file,"%-20s,%14.5lf,%14.5lf",pt.name,pt.utm27x,pt.utm27y); if(config.OUT==4) fprintf(out_file,"%-20s,%14.5lf,%14.5lf",pt.name,pt.utm83x,pt.utm83y); if(config.OUT==5) { DD_to_DMS(pt.ddlat27,&sign,&latd,&latm,&lats); DD_to_DMS(pt.ddlon27,&sign,&lond,&lonm,&lons); fprintf(out_file,"%-20s,%02d %02d %08.5lf,%03d %02d %08.5lf",pt.name,latd,latm,lats,lond,lonm,lons); } if(config.OUT==6) { DD_to_DMS(pt.ddlat83,&sign,&latd,&latm,&lats); DD_to_DMS(pt.ddlon83,&sign,&lond,&lonm,&lons); fprintf(out_file,"%-20s,%02d %02d %08.5lf,%03d %02d %08.5lf",pt.name,latd,latm,lats,lond,lonm,lons); } if(config.OUT_VERT) { if(config.IN_VERT==config.OUT_VERT) fprintf(out_file,",%14lf",height); else if(config.IN_V_UNIT<3) fprintf(out_file,",%10.2lf",height); else fprintf(out_file,",%10.3lf",height); if((pt.flag&4)&&(pt.flag&16)) fprintf(out_file," **HV**"); else if(pt.flag&4) fprintf(out_file," **H**"); else if(pt.flag&16) fprintf(out_file," **V**"); fprintf(out_file,"\n"); } else fprintf(out_file,"\n"); } } fclose(tmp_file); fclose(out_file); cprintf("Output file Completed.."); sleep(1); clrscr(); } void to_printfile(char file[],long NREC) { FILE *tmp_file,*out_file; long count; int latd,lond,latm,lonm,lines=3,tmp; int total_pages,lines_per_pt,total_lines,page=1; div_t rem; double lats,lons; struct my_pt pt; char line[26],sign=' '; char unit[20],spzone[30]; int deg,min; double sec; strcpy(unit,""); strcpy(spzone,""); window(6,15,74,22); textattr(YELLOW+(BLUE<<4)); clrscr(); cprintf("Formating data for Print file..\n\r"); if(((out_file=fopen(config.pfile_out,"w"))!=NULL)&&((tmp_file=fopen(file,"rb"))!=NULL)) for(count=1;count<=NREC;count++){ /* Print Headers in output file */ if(lines==3){ strcpy(unit,GetUnitStr(config.IN_UNIT)); strcpy(line," "); sprintf(&line[12-(int)(strlen(config.agency)/2)],"%s",config.agency); fprintf(out_file,"\n\n\n%20.20s%-25.25s\n"," ",line); strcpy(line," "); sprintf(&line[12-(int)(strlen(config.project)/2)],"%s",config.project); fprintf(out_file,"%20.20s%-25.25s%7.7s%d/%d/%d\n"," ",line," ",Today.da_mon,Today.da_day,Today.da_year-1900); fprintf(out_file,"\n ---------------------------------------------------------------\n"); if(config.IN==1){ strcpy(spzone,GetAbbrev(1,config.zone_in)); fprintf(out_file," Original Coords. on NAD 27 State Plane - %s%s\n",spzone,unit); } if(config.IN==2){ strcpy(spzone,GetAbbrev(2,config.zone_in)); fprintf(out_file," Original Coords. on NAD 83 State Plane - %s%s\n",spzone,unit); } if(config.IN==3) fprintf(out_file," Original Coords. on NAD 27 UTM Zone %04d%s\n",config.zone_in,unit); if(config.IN==4) fprintf(out_file," Original Coords. on NAD 83 UTM Zone %04d%s\n",config.zone_in,unit); if(config.IN==5) fprintf(out_file," Original Coords. on NAD 27 Geographic Coordinates\n"); if(config.IN==6) fprintf(out_file," Original Coords. on NAD 83 Geographic Coordinates\n"); strcpy(unit,GetUnitStr(config.OUT_UNIT)); if(config.OUT==1){ strcpy(spzone,GetAbbrev(1,config.zone_out)); fprintf(out_file," Translated Coords. on NAD 27 State Plane - %s%s\n",spzone,unit); } if(config.OUT==2){ strcpy(spzone,GetAbbrev(2,config.zone_out)); fprintf(out_file," Translated Coords. on NAD 83 State Plane - %s%s\n",spzone,unit); } if(config.OUT==3) fprintf(out_file," Translated Coords. on NAD 27 UTM Zone %04d%s\n",config.zone_out,unit); if(config.OUT==4) fprintf(out_file," Translated Coords. on NAD 83 UTM Zone %04d%s\n",config.zone_out,unit); if(config.OUT==5) fprintf(out_file," Translated Coords. on NAD 27 Geographic Coordinates\n"); if(config.OUT==6) fprintf(out_file," Translated Coords. on NAD 83 Geographic Coordinates\n"); if(config.IN_VERT) { strcpy(unit,GetUnitStr(config.IN_V_UNIT)); fprintf(out_file," Input Vertical - "); if(config.IN_VERT==1) fprintf(out_file,"NGVD 29"); else fprintf(out_file,"NAVD 88"); fprintf(out_file,"%s\n",unit); strcpy(unit,GetUnitStr(config.OUT_V_UNIT)); fprintf(out_file," Output Vertical - "); if(config.OUT_VERT==1) fprintf(out_file,"NGVD 29"); else fprintf(out_file,"NAVD 88"); fprintf(out_file,"%s\n",unit); lines+=2; } fprintf(out_file," ---------------------------------------------------------------\n"); fprintf(out_file," %-20s %-15s %-15s\n\n","NAME","INPUT","OUTPUT"); lines+=12; } fread(&pt,sizeof(struct my_pt),1,tmp_file); if(pt.flag&4){ fprintf(out_file," Following Point could not be Converted by Nadcon\n"); lines++; } if(pt.flag&8){ fprintf(out_file," Following UTM Point is not in zone %4d\n",config.zone_out); lines++; } if(pt.flag&16){ fprintf(out_file," Following Point could not be Converted by Vertcon\n"); lines++; } for(tmp=0;tmp<2;tmp++) { !tmp?fprintf(out_file," %-20s ",pt.name):fprintf(out_file," %-20s "," "); switch(config.IN) { case 1: !tmp?fprintf(out_file,"%14.5lf N ",pt.spiny):fprintf(out_file,"%14.5lf E ",pt.spinx); break; case 2: !tmp?fprintf(out_file,"%14.5lf N ",pt.spiny):fprintf(out_file,"%14.5lf E ",pt.spinx); break; case 3: !tmp?fprintf(out_file,"%14.5lf N ",pt.utm27y):fprintf(out_file,"%14.5lf E ",pt.utm27x); break; case 4: !tmp?fprintf(out_file,"%14.5lf N ",pt.utm83y):fprintf(out_file,"%14.5lf E ",pt.utm83x); break; case 5: DD_to_DMS(pt.ddlat27,&sign,&latd,&latm,&lats); DD_to_DMS(pt.ddlon27,&sign,&lond,&lonm,&lons); !tmp?fprintf(out_file," %02d %02d %08.5lf N ",latd,latm,lats):fprintf(out_file,"%03d %02d %08.5lf W ",lond,lonm,lons); break; case 6: DD_to_DMS(pt.ddlat83,&sign,&latd,&latm,&lats); DD_to_DMS(pt.ddlon83,&sign,&lond,&lonm,&lons); !tmp?fprintf(out_file," %02d %02d %08.5lf N ",latd,latm,lats):fprintf(out_file,"%03d %02d %08.5lf W ",lond,lonm,lons); break; }; switch(config.OUT) { case 1: !tmp?fprintf(out_file,"%14.5lf N\n",pt.sp27y):fprintf(out_file,"%14.5lf E\n",pt.sp27x); break; case 2: !tmp?fprintf(out_file,"%14.5lf N\n",pt.sp83y):fprintf(out_file,"%14.5lf E\n",pt.sp83x); break; case 3: !tmp?fprintf(out_file,"%14.5lf N\n",pt.utm27y):fprintf(out_file,"%14.5lf E\n",pt.utm27x); break; case 4: !tmp?fprintf(out_file,"%14.5lf N\n",pt.utm83y):fprintf(out_file,"%14.5lf E\n",pt.utm83x); break; case 5: DD_to_DMS(pt.ddlat27,&sign,&latd,&latm,&lats); DD_to_DMS(pt.ddlon27,&sign,&lond,&lonm,&lons); !tmp?fprintf(out_file," %02d %02d %08.5lf N\n",latd,latm,lats):fprintf(out_file,"%03d %02d %08.5lf W\n",lond,lonm,lons); break; case 6: DD_to_DMS(pt.ddlat83,&sign,&latd,&latm,&lats); DD_to_DMS(pt.ddlon83,&sign,&lond,&lonm,&lons); !tmp?fprintf(out_file," %02d %02d %08.5lf N\n",latd,latm,lats):fprintf(out_file,"%03d %02d %08.5lf W\n",lond,lonm,lons); break; }; } lines+=2; if(config.IN_VERT) { fprintf(out_file," Heights "); fprintf(out_file,"%11.5lf",pt.hgtin); // if(config.IN_VERT==1) // fprintf(out_file,"%11.5lf",pt.hgt29); // else if(config.IN_VERT==2) // fprintf(out_file,"%11.5lf",pt.hgt88); if(config.OUT_VERT==config.IN_VERT) { if(config.OUT_VERT==1) fprintf(out_file," %11.5lf\n",pt.hgt29); else if(config.OUT_VERT==2) fprintf(out_file," %11.5lf\n",pt.hgt88); else fprintf(out_file,"\n"); } else if(config.OUT_V_UNIT<3) { if(config.OUT_VERT==1) fprintf(out_file," %7.2lf\n",pt.hgt29); else if(config.OUT_VERT==2) fprintf(out_file," %7.2lf\n",pt.hgt88); else fprintf(out_file,"\n"); } else { if(config.OUT_VERT==1) fprintf(out_file," %8.3lf\n",pt.hgt29); else if(config.OUT_VERT==2) fprintf(out_file," %8.3lf\n",pt.hgt88); else fprintf(out_file,"\n"); } lines++; } if((config.IN<5)||(config.OUT<5)) { for(tmp=0;tmp<2;tmp++) { !tmp?fprintf(out_file," %-20s ","Convergence"):fprintf(out_file," %-20s ","Scale Factor"); switch(config.IN) { case 1: DD_to_DMS(pt.con27,&sign,°,&min,&sec); !tmp?fprintf(out_file,"%c%02d %02d %08.5lf ",sign,deg,min,sec):fprintf(out_file," %14.9lf ",pt.k27); break; case 2: DD_to_DMS(pt.con83,&sign,°,&min,&sec); !tmp?fprintf(out_file,"%c%02d %02d %08.5lf ",sign,deg,min,sec):fprintf(out_file," %14.9lf ",pt.k83); break; case 3: DD_to_DMS(pt.ucon27,&sign,°,&min,&sec); !tmp?fprintf(out_file,"%c%02d %02d %08.5lf ",sign,deg,min,sec):fprintf(out_file," %14.9lf ",pt.uk27); break; case 4: DD_to_DMS(pt.ucon83,&sign,°,&min,&sec); !tmp?fprintf(out_file,"%c%02d %02d %08.5lf ",sign,deg,min,sec):fprintf(out_file," %14.9lf ",pt.uk83); break; case 5: case 6: fprintf(out_file," %14s "," "); break; }; switch(config.OUT) { case 1: DD_to_DMS(pt.con27,&sign,°,&min,&sec); !tmp?fprintf(out_file,"%c%02d %02d %08.5lf \n",sign,deg,min,sec):fprintf(out_file," %14.9lf \n",pt.k27); break; case 2: DD_to_DMS(pt.con83,&sign,°,&min,&sec); !tmp?fprintf(out_file,"%c%02d %02d %08.5lf \n",sign,deg,min,sec):fprintf(out_file," %14.9lf \n",pt.k83); break; case 3: DD_to_DMS(pt.ucon27,&sign,°,&min,&sec); !tmp?fprintf(out_file,"%c%02d %02d %08.5lf \n",sign,deg,min,sec):fprintf(out_file," %14.9lf \n",pt.uk27); break; case 4: DD_to_DMS(pt.ucon83,&sign,°,&min,&sec); !tmp?fprintf(out_file,"%c%02d %02d %08.5lf \n",sign,deg,min,sec):fprintf(out_file," %14.9lf \n",pt.uk83); break; case 5: case 6: fprintf(out_file," %14s \n"," "); break; }; } lines+=2; } if((config.IN&1)^(config.OUT&1)) { if((config.IN<5)&&(config.OUT<5)){ fprintf(out_file,"%10.10sGrid Shift(US Ft), Delta North = %7.3f\n%29.29sDelta East = %7.3f\n"," ",fabs(pt.sp27y-pt.sp83y)," ",fabs(pt.sp27x-pt.sp83x)); lines+=2; } fprintf(out_file,"%10.10sDatum Shift(m), Delta Lat. = %7.3lf\n%26.26s Delta Lon. = %7.3lf\n"," ",pt.dlat," ",pt.dlon); lines+=2; } /*** Next Point ***/ fprintf(out_file,"\n"); lines++; if(count==1){ lines_per_pt = lines - 15; total_lines = lines_per_pt*(NREC); rem=div(total_lines,40); total_pages = rem.rem==0?rem.quot:rem.quot+1; } if (lines >=53) { for(tmp=lines;tmp<58;tmp++) fprintf(out_file,"\n"); fprintf(out_file," ---------------------------------------------------------------\n"); if(pt.flag)fprintf(out_file," U.S. Army Topo. Engineering Center, CORPSCON V4.1, Page %d \f",page); else fprintf(out_file," U.S. Army Topo. Engineering Center, CORPSCON V4.1, Page %d of %d\f",page,total_pages); ++page;lines=3; } } if(page==total_pages){ for(tmp=lines;tmp<58;tmp++) fprintf(out_file,"\n"); fprintf(out_file," ---------------------------------------------------------------\n"); if(pt.flag)fprintf(out_file," U.S. Army Topo. Engineering Center, CORPSCON V4.1, Page %d \f",page); else fprintf(out_file," U.S. Army Topo. Engineering Center, CORPSCON V4.1, Page %d of %d\f",page,total_pages); } fclose(tmp_file); fclose(out_file); cprintf("Output file Completed.."); sleep(1); ClearConsole(); } void to_printer(char file[],long NREC) { char tmpfile[60],line[100]; FILE *fp; int prtstatus,tmp,status,loop=0; int key=0; strcpy(tmpfile,config.pfile_out); strcpy(config.pfile_out,"INT$$%0.PRT"); to_printfile(file,NREC); /** SEND TO PRINTER **/ prtstatus = check_printer(); if(prtstatus==-1) cprintf("No printer found, cannot print..\n\r"); else if(prtstatus>0) { fp=fopen(config.pfile_out,"r"); while(!feof(fp)&&(key!=27)) { fgets(line,99,fp); for(tmp=0;(line[tmp]!='\0')&&(key!=27);tmp++){ do { loop=0; status=biosprint(0,line[tmp],prtstatus-1); if (status & 0x01) { cprintf("Device time out, LPT%1d:\r\n",prtstatus-1); loop=1; } if (status & 0x08) { cprintf("I/O error, LPT%1d:\r\n",prtstatus-1); loop=1; } if (status & 0x20) { cprintf("Out of paper, LPT%1d:\r\n",prtstatus-1); loop=1; } if(loop) { cprintf("Hit any key to continue, or ESC to exit printing.."); key = getch(); } } while (loop&&(key!=27)); } biosprint(0,'\r',prtstatus-1); }; fclose(fp); } sleep(3); remove("INT$$%0.PRT"); strcpy(config.pfile_out,tmpfile); } /* The following procedure checks lpt1: and lpt2: for printers if lpt1: receives acknowledgment (printer exists) will also try lpt2:. This procedure returns a value of 0 (no printer), 1 (lpt1:), or 2 (lpt2:).*/ int check_printer(void) { #define STATUS 2 /* printer status command */ int PORTNUM=0; /* port number for LPT1 */ int status, abyte=0, retstat=-1; for(PORTNUM=0;PORTNUM<2;PORTNUM++) { status = biosprint(STATUS, abyte, PORTNUM); if ((status & 0x08)&&(status & 0x40)){ cprintf("Found Printer on Port LPT%1d: Power is Off.\r\n",PORTNUM+1); continue; } else if ((status & 0x08)&& !(status & 0x40)){ cprintf("Printer on Port LPT%1d: Offline\r\n",PORTNUM+1); continue; } else if (!(status & 0x40) && !(status & 0x08) && !(status & 0x80)) { cprintf("No Printer Found on Port LPT%1d:\r\n",PORTNUM+1); continue; } if (status & 0x01) { cprintf("Device time out, LPT%1d:\r\n",PORTNUM+1); retstat = 0; } if (status & 0x08){ cprintf("I/O error, LPT%1d:\r\n",PORTNUM+1); retstat = 0; } else if (status & 0x80){ cprintf("Not busy, LPT%1d:\r\n",PORTNUM+1); return PORTNUM+1; } if (status & 0x10){ cprintf("Selected Printer on LPT%1d:\r\n",PORTNUM+1); retstat = PORTNUM+1; } if (status & 0x20){ cprintf("Out of paper, LPT%1d:\r\n",PORTNUM+1); retstat = 0; } if (status & 0x80){ cprintf("Not busy, LPT%1d:\r\n",PORTNUM+1); retstat = PORTNUM+1; } } return retstat; } /* this procedure reads an NGS Bluebook file of data and */ /* creates a binary equivalent of that data, the format of*/ /* *80* or *81* records. Also lines beginning */ /* with a semi-colon are considered to be comments and are*/ /* ignored. Returns number of pts are 0 on error...*/ long get_bluebook_in(char filein[],char fileout[]) { FILE *tmp_file,*out_file; struct my_pt pt; long count=0; int deg,min; double sec; char line[100],name[50],str1[25],str2[25],str3[25],test8081[25]; if((tmp_file=fopen(filein,"rt"))==NULL){ CheckError(FILE_NOT_FOUND,filein); return 0; } if((out_file=fopen(fileout,"wb"))==NULL){ CheckError(UNABLE_TO_OPEN_FOR_WRITING,fileout); return 0; } while(!feof(tmp_file)) { fgets(line,99,tmp_file); if(feof(tmp_file)) break; if(line[0]==';') continue; strncpy(test8081,&line[6],4);test8081[4]='\0'; if(strcmp(test8081,"*80*")&&strcmp(test8081,"*81*")) continue; if(strlen(line) < 35) break; pt.flag = 0; strncpy(pt.name,&line[14],20); pt.name[20]='\0'; if(config.IN<3) { strncpy(str1,&line[44],10);str1[10]='\0'; strncpy(str2,&line[54],11);str2[11]='\0'; } if(strlen(line)>=75) strncpy(str3,&line[69],6);str3[6]='\0'; if(config.IN==1) { sscanf(str1,"%lf",&pt.sp27x); sscanf(str2,"%lf",&pt.sp27y); pt.sp27x=pt.sp27x/1000.0; pt.sp27y=pt.sp27y/1000.0; } if(config.IN==2) { sscanf(str1,"%lf",&pt.sp83x); sscanf(str2,"%lf",&pt.sp83y); pt.sp83x=pt.sp83x/1000.0; pt.sp83y=pt.sp83y/1000.0; } if(config.IN==3) { sscanf(str1,"%lf",&pt.utm27x); sscanf(str2,"%lf",&pt.utm27y); pt.utm27x=pt.utm27x/1000.0; pt.utm27y=pt.utm27y/1000.0; } if(config.IN==4) { sscanf(str1,"%lf",&pt.utm83x); sscanf(str2,"%lf",&pt.utm83y); pt.utm83x=pt.utm83x/1000.0; pt.utm83y=pt.utm83y/1000.0; } if(config.IN==5) { strncpy(str1,&line[44],2);str1[2]='\0';deg=atoi(str1); strncpy(str1,&line[46],2);str1[2]='\0';min=atoi(str1); strncpy(str1,&line[48],7);str1[7]='\0';sec=(double)(atol(str1)/100000.0); pt.ddlat27 = (double)(deg + min/60.0 + sec/3600.0); strncpy(str1,&line[56],3);str1[3]='\0';deg=atoi(str1); strncpy(str1,&line[59],2);str1[2]='\0';min=atoi(str1); strncpy(str1,&line[61],7);str1[7]='\0';sec=(double)(atol(str1)/100000.0); pt.ddlon27 = (double)(deg + min/60.0 + sec/3600.0); } if(config.IN==6) { strncpy(str1,&line[44],2);str1[2]='\0';deg=atoi(str1); strncpy(str1,&line[46],2);str1[2]='\0';min=atoi(str1); strncpy(str1,&line[48],7);str1[7]='\0';sec=(double)(atol(str1)/100000.0); pt.ddlat83 = (double)(deg + min/60.0 + sec/3600.0); strncpy(str1,&line[56],3);str1[3]='\0';deg=atoi(str1); strncpy(str1,&line[59],2);str1[2]='\0';min=atoi(str1); strncpy(str1,&line[61],7);str1[7]='\0';sec=(double)(atol(str1)/100000.0); pt.ddlon83 = (double)(deg + min/60.0 + sec/3600.0); } sscanf(str3,"%lf",&pt.hgt29); pt.hgt29 /= 100.0; pt.hgt88 = pt.hgtin = pt.hgt29; fwrite(&pt,sizeof(struct my_pt),1,out_file); count++; } fclose(tmp_file); fclose(out_file); return count; } /* this procedure scrolls the Help file in a window on */ /* the main screen. */ void help(void) { int menu_area[71][11],ch=0; short tmp,pos=0; char line[70]; FILE *fp; gettext(5,14,75,23,menu_area); window(6,15,74,22); textattr(YELLOW+(BLUE<<4)); if((fp=fopen("CORPSCON.HLP","r"))!=NULL) for(;ch!=27;) { clrscr(); for(tmp=1;(tmp<=7)&&(!feof(fp));tmp++) { fgets(line,70,fp); gotoxy(1,tmp); cputs(line);} pos+=7; do{ ch=getch(); if(ch==0) ch=getch(); }while((ch!=73)&&(ch!=27)&&(ch!=81)&&(ch!=80)&&(ch!=72)); if(ch==73) { rewind(fp); pos=(pos-14)<0?0:pos-14; for(tmp=1;tmp<=pos;tmp++) fgets(line,70,fp);} else if(ch==72) { rewind(fp); pos=(pos-8)<0?0:pos-8; for(tmp=1;tmp<=pos;tmp++) fgets(line,70,fp);} else if(ch==80) { rewind(fp); pos=(pos-6)<0?0:pos-6; for(tmp=1;tmp<=pos;tmp++) fgets(line,70,fp);} } else { gotoxy(1,1);cprintf("Could not find CORPSCON.HLP file.."); sleep(2); } puttext(5,14,75,23,menu_area); } //******************************************************************* // This procedure converts latitude and longitude strings to // lat/lon doubles. It uses CheckError() in cverror.cpp // to display error messages. It uses ConvertToDecDeg() to // do the actual conversion. //******************************************************************* int GetLatLon(double *lat, double *lon, char *latin, char *lonin) { if(!ConvertToDecDeg(lat,latin)) CheckError(INVALID_LAT_ENTERED,latin); else if(*lat>90.0||*lat<0.0) CheckError(INVALID_LAT_VALUE,latin); else if(!ConvertToDecDeg(lon,lonin)) CheckError(INVALID_LON_ENTERED,lonin); else if(*lon>360.0||*lon<0.0) CheckError(INVALID_LON_VALUE,lonin); else return 1; return 0; } // This procedure converts a dd mm ss string to decimal degrees. int ConvertToDecDeg(double *value,char *str) { double deg=0.0,min=0.0,sec=0.0; int ideg=0,imin=0; char in[121]; strcpy(in,str); switch(sscanf(in,"%lf %lf %lf",°,&min,&sec)) { case 1: *value = deg; return 1; case 2: if(sscanf(in,"%d %lf",&ideg,&min)!=2) return 0; if(min>=60.0||min<0.0) return 0; *value = deg + min/60.0; return 1; case 3: if(sscanf(in,"%d %d %lf",&ideg,&imin,&sec)!=3) return 0; if(min>=60.0||min<0.0||sec>=60.0||sec<0.0)return 0; *value = deg + min/60.0 + sec/3600.0; return 1; default: return 0; } } int Disclaimer(void) { int x1=20,y1=6,x2=60,y2=16,ret=0; char before[4000]; windowbox tmp; default_windowbox(&tmp); SetDimensions(&tmp,x1,y1,x2,y2); SetColors(&tmp,RED,YELLOW,YELLOW,WHITE,WHITE); tmp.bordertoggle = ON; tmp.shadow = ON; strcpy(tmp.title," Warning! "); gettext(x1,y1,x2+2,y2+1,&before); MakeWindow(&tmp); WriteText(3,2,&tmp,"Vertical conversions are sufficient"); WriteText(3,3,&tmp,"for small-scale (1:24000) mapping"); WriteText(3,4,&tmp,"purposes only. Results should not be"); WriteText(3,5,&tmp,"used for site design and/or planning."); WriteText(3,6,&tmp,""); WriteText(3,7,&tmp,"Hit any key to continue."); WriteText(3,8,&tmp,""); WriteText(3,9,&tmp,"Enter '!' to remove this message from"); WriteText(3,10,&tmp,"future sessions of Corpscon."); // getch(); ret = GetKey(); puttext(x1,y1,x2+2,y2+1,&before); ret = ret=='!' ? 0:1; return ret; }