/* $Id:: abhav.c,v 1.3 2000/04/15 15:27:19 clark Exp $ Compile this program with cc abhav.c -lm -o abhav Run this program with abhave -h for help Normally you will need to give the -s and -e options with starting and ending degrees to output. TABLES for ABHAV SIGHT REDUCTION METHOD by J.D. WOODWORTH Update on 20 Dec 1991 to provide spaces every 5 degrees and to reduce the size accordingly. This program has been revised (17 Nov 90) to print on both sides of paper as follows; This is an xxxf.c program and will print on front side (odd pages). The xxxb.c program will print on back side (even pages). This program has been revised (17 Nov 90) so that both sides of paper can be printed as follows: This is an xxxf.c program and will print the front side or odd numbered pages. The xxxb.c program will print the back side (even pages). These tables have two minutes columns. Rev. Nov 89. The printout is reduced in size. This program is set up to be revised as follows: 1. For 0 to 5 degrees set location A for 0 to 5 and location B for a printout 7.0 for "a" and 7.1 for both "b" and "c". 2. For 6 to 173 degrees set location A for 6 to 173 and location B for a printout of 7.0 for all columns, "a", "b" and "c". Or smaller segments can be printed at one time. 3. For 174 to 179 degrees set location A for 174 to 179 and loca- tion B for a printout of 7.1 for both "a" and "c" and 7.0 for "b". */ #include #include #include #include #include #define CR1 fprintf(outdev,"\n") #define CR2 fprintf(outdev,"\n\n") #define CR3 fprintf(outdev,"\n\n\n") #define PRS(S) fprintf(outdev,"%s",S) #define PRT(S,F,F1,F2) fprintf(outdev,"%-5s%2.0f-%2.0f-%-4.0f",S,F,F1,F2) #define SE fprintf(outdev," ") #define SQ fprintf(outdev," ") #define SH fprintf(outdev," ") #define S1 fprintf(outdev," ") #define S2 fprintf(outdev," ") #define S3 fprintf(outdev," ") #define S4 fprintf(outdev," ") void help( char *name ); int main(int argc, char **argv) { FILE *outdev; int ideg; int startideg = 6; int endideg = 90; int imin; int k; int page; int skippage = 32384; /* forces all pages to print */ int oddpage = 32384; /* forces all pages to print */ double de1, de2, de3, rad, min, deg, f, h, a, b, c; char *format; char *base_file_name; char pagenum[]="0/.html"; char file_name[256]; int optc; int hopt=0; /* parse options */ while (1) { optc = getopt(argc, argv, "s:e:p:h:"); if (optc == -1) break; switch (optc) { case 's': startideg = atol ( optarg ); break; case 'e': endideg = atol ( optarg ); break; case 'p': /* paging option */ if ( *optarg == 'e' ) { skippage = 2; oddpage = 1; } else if ( *optarg == 'o' ) { skippage = 2; oddpage = 0; } else if ( *optarg == 'a' ) { skippage = 32384; /* force all pages to print */ oddpage = 32384; } else { fprintf(stderr, "-p option was %c and should be e(ven), o(dd), or a(ll)\n", *optarg); } break; case 'h': hopt++; base_file_name = optarg; skippage = 32384; /* force all pages to print */ oddpage = 32384; break; case '?': help(argv[0]); exit(-1); break; default: printf ("?? getopt returned character code 0%o\n", optc); help(argv[0]); } } /* end while */ /* if (optind < argc) { printf ("non-option ARGV-elements: "); while (optind < argc) printf ("%s", argv[optind++]); printf ("\n"); } */ outdev = stdout; rad=57.29578; for (ideg=startideg; ideg<=endideg; ideg+=3) { page=(ideg+3)/3; if ( hopt ) { (pagenum[1])++; if( pagenum[1] > '9' ) { pagenum[1] = '0'; (pagenum[0])++; } strncpy( file_name, base_file_name, 247 ); strcat( file_name, pagenum ); if ( NULL == (outdev = fopen ( file_name, "w" ))) { fprintf(stderr, "Cannot open %s for printing\n", file_name); exit(-1); } fprintf(outdev, ""); fprintf(outdev, "Page %10d %10d degrees", page, ideg ); fprintf(outdev, "\n\n"); } printf("ideg =%d, page =%d\n",ideg,page); if (page % skippage != oddpage ) { if (hopt) { fprintf(outdev, "
ABHAV TABLES %d TO %d DEGREES

\n", ideg, ideg+2 ); } else { CR3; S4; S1; SQ; PRS("ABHAV TABLES"); CR2; } de1 = (double) ideg; de2 = (double) ideg + 1; de3 = (double) ideg+2; if (hopt) { fprintf(outdev, "

\n" ); fprintf(outdev, "", de1, de2, de3); fprintf(outdev, "\n"); fprintf(outdev, "\n"); fprintf(outdev, "\n"); } else { PRS(" ___________________________________________________________________________________"); CR1; fprintf(outdev," |Deg>|%12.0f |%12.0f |%12.0f |\n"); fprintf( outdev,"", min ); } else { fprintf(outdev," |%3.0f |",min); } /* A,B,C columns print */ for ( k=1; k <= 3 ; k++ ) { h = ( 1 - cos( f/rad )) / 2; a = fabs( ( log10( h ) ) * 100000 ); b = h * 100000; c = ( log10( fabs( 1/cos( f/rad ) ) ) ) * 100000; if (hopt) { if ( ideg >= 0 && ideg < 6 ) format = ""; if ( ideg >= 6 && ideg < 174 ) format = ""; if ( ideg >= 174 && ideg < 180 ) format = ""; fprintf(outdev, format, a, b, c ); } else { if ( ideg >= 0 && ideg < 6 ) format = "%7.0f|%7.1f|%7.1f|"; if ( ideg >= 6 && ideg < 174 ) format = "%7.0f|%7.0f|%7.0f|"; if ( ideg >= 174 && ideg < 180 ) format = "%7.1f|%7.0f|%7.1f|"; fprintf(outdev, format, a, b, c ); } f++; /* end column loop */ } /* printout set for nearest unit for a, b & c, location B */ if (hopt) { fprintf(outdev,"\n",min); } else { fprintf(outdev,"%3.0f |",min); CR1; } if (( imin+1 ) % 5 == 0 && imin != 59 ) { if (hopt) { fprintf(outdev, "\n"); fprintf(outdev, "\n"); fprintf(outdev, "\n"); fprintf(outdev, "\n"); fprintf(outdev, "\n"); } else { PRS(" | | | | | | | | | | | |"); CR1; } /*end space loop*/ } /*end minute loop*/ } if (hopt) { //fprintf(outdev,"
\n"); ; } else { fprintf(outdev,"\r"); PRS(" _________________________________________________________________________________"); CR3; CR3; CR3; } /*end line loop*/ } /*end degree loop*/ if (hopt) { fprintf( outdev, "
Deg­>%12.0f%12.0f%12.0f<­Deg
MinABCABCABCMin%3.0f%7.0f%7.1f%7.1f%7.0f%7.0f%7.0f%7.1f%7.0f%7.1f%3.0f
"); fclose(outdev); } } /*end main*/ return 0; } /* Gets character variable from keyboard */ char getcharacter(prompt,values) char prompt[],values[]; { char cstr[256],*charptr; while(1) { fprintf(stderr,"%s ( select one of )",prompt); for (charptr=values;*charptr;charptr++) { if(*charptr=='\n') { fprintf(stderr,""); } else { fprintf(stderr,"%c",*charptr); } } fprintf(stderr," )\n"); fgets(cstr,255,stdin); cstr[1]='\0'; /*make a one character string forstrpbrk*/ if(NULL!=strpbrk(values,cstr))break; fprintf(stderr,"input error, try again.\n"); } return cstr[0]; } void help( myname ) char *myname; { printf( "usage: %s [-s startdeg] [-e endeg] [-p e|o|a]\n", myname ); printf( "\n" ); printf( "-p sets the paging for even, odd or all pages\n" ); printf( "-h base_file_name prints the table in html mode\n" ); printf( "\n" ); }