#include #include #include #include "project.h" void initsystem(system *s) { if(!get_ell(&s->e, s->ename)) { list_ell(); exits("argument"); } if(!get_projection(&s->p, s->pname)) { list_projections(); exits("argument"); } (s->p.init)(&s->p, &s->e, s->parg); } void main(int argc, char **argv){ point pt; system isys, osys, *asys; Biobuf in, out; char *io; int verbose; verbose=0; asys=&isys; isys.ename=osys.ename="wgs84"; isys.pname=osys.pname="λφ"; isys.parg=osys.parg=""; ARGBEGIN { case 'i': asys=&isys; break; case 'o': asys=&osys; break; case 'v': verbose++; break; case 'e': asys->ename = ARGF(); break; case 'p': asys->pname=ARGF(); if(!asys->pname) exits("argument"); asys->parg=strchr(asys->pname, ','); if(asys->parg){ *asys->parg='\0'; asys->parg++; } else { asys->parg=""; } break; default: print("usage: proj [-i] [-e ellipsis] [-p projection] [-o [-e ellipsis] [-p projection]]\n"); exits("arguments"); break; } ARGEND Binit(&in, 0, OREAD); Binit(&out, 1, OWRITE); setfcr(getfcr() & ~(FPINVAL|FPZDIV|FPOVFL)); initsystem(&isys); initsystem(&osys); while(1) { if((io=Brdstr(&in, '\n', 1))==nil) break; pt=(isys.p.scan)(io); free(io); pt=(isys.p.λφ)(pt, &isys.e, &isys.p); if(verbose) printstd(pt); pt=(osys.p.xy)(pt, &osys.e, &osys.p); io=(osys.p.print)(pt); Bprint(&out, "%s\n", io); free(io); } }