--- PJ_rouss.c	Fri Feb 10 22:21:50 2006
+++ PJ_rouss.c	Sun Feb 05 10:30:38 2006
@@ -0,0 +1,128 @@
+/*
+** libproj -- library of cartographic projections
+**
+** Copyright (c) 2003, 2006   Gerald I. Evenden
+*/
+/*
+** Permission is hereby granted, free of charge, to any person obtaining
+** a copy of this software and associated documentation files (the
+** "Software"), to deal in the Software without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Software, and to
+** permit persons to whom the Software is furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be
+** included in all copies or substantial portions of the Software.
+**
+** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+#define PROJ_PARMS__ \
+	double s0; \
+	double A1, A2, A3, A4, A5, A6; \
+	double B1, B2, B3, B4, B5, B6, B7, B8; \
+	double C1, C2, C3, C4, C5, C6, C7, C8; \
+	double D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11; \
+	void *en;
+#define PJ_LIB__
+#include	<projects.h>
+PJ_CVSID("$Id: proj_rouss.c,v 3.1 2006/01/11 01:38:18 gie Exp $");
+PROJ_HEAD(rouss, "Roussilhe Stereographic") "\n\tAzi., Ellps.";
+FORWARD(e_forward); /* ellipsoid */
+	double s, al, cp, sp, al2, s2;
+	
+	cp = cos(lp.phi);
+	sp = sin(lp.phi);
+	s = proj_mdist(lp.phi, sp, cp,  P->en) - P->s0;
+	s2 = s * s;
+	al = lp.lam * cp / sqrt(1. - P->es * sp * sp);
+	al2 = al * al;
+	xy.x = P->k0 * al*(1.+s2*(P->A1+s2*P->A4)-al2*(P->A2+s*P->A3+s2*P->A5
+				+al2*P->A6));
+	xy.y = P->k0 * (al2*(P->B1+al2*P->B4)+
+		s*(1.+al2*(P->B3-al2*P->B6)+s2*(P->B2+s2*P->B8)+
+		s*al2*(P->B5+s*P->B7)));
+	return (xy);
+}
+INVERSE(e_inverse); /* ellipsoid */
+	double s, al, x = xy.x / P->k0, y = xy.y / P->k0, x2, y2;;
+
+	x2 = x * x;
+	y2 = y * y;
+	al = x*(1.-P->C1*y2+x2*(P->C2+P->C3*y-P->C4*x2+P->C5*y2-P->C7*x2*y)
+		+y2*(P->C6*y2-P->C8*x2*y));
+	s = P->s0 + y*(1.+y2*(-P->D2+P->D8*y2))+
+		x2*(-P->D1+y*(-P->D3+y*(-P->D5+y*(-P->D7+y*P->D11)))+
+		x2*(P->D4+y*(P->D6+y*P->D10)-x2*P->D9));
+	lp.phi=proj_inv_mdist(s, P->en);
+	printf("e_inverse() lp.phi=%f\n", lp.phi);
+	s = sin(lp.phi);
+	lp.lam=al * sqrt(1. - P->es * s * s)/cos(lp.phi);
+	return (lp);
+}
+FREEUP;
+	if (P) {
+		if (P->en)
+			free(P->en);
+		free(P);
+	}
+}
+ENTRY1(rouss, en)
+	double N0, es2, t, t2, R_R0_2, R_R0_4;
+
+	if (!((P->en = proj_mdist_ini(P->es))))
+		E_ERROR_0;
+	es2 = sin(P->phi0);
+	P->s0 = proj_mdist(P->phi0, es2, cos(P->phi0), P->en);
+	t = 1. - (es2 = P->es * es2 * es2);
+	N0 = 1./sqrt(t);
+	R_R0_2 = t * t / P->one_es;
+	R_R0_4 = R_R0_2 * R_R0_2;
+	t = tan(P->phi0);
+	t2 = t * t;
+	P->C1 = P->A1 = R_R0_2 / 4.;
+	P->C2 = P->A2 = R_R0_2 * (2 * t2 - 1. - 2. * es2) / 12.;
+	P->A3 = R_R0_2 * t * (1. + 4. * t2)/ ( 12. * N0);
+	P->A4 = R_R0_4 / 24.;
+	P->A5 = R_R0_4 * ( -1. + t2 * (11. + 12. * t2))/24.;
+	P->A6 = R_R0_4 * ( -2. + t2 * (11. - 2. * t2))/240.;
+	P->B1 = t / (2. * N0);
+	P->B2 = R_R0_2 / 12.;
+	P->B3 = R_R0_2 * (1. + 2. * t2 - 2. * es2)/4.;
+	P->B4 = R_R0_2 * t * (2. - t2)/(24. * N0);
+	P->B5 = R_R0_2 * t * (5. + 4.* t2)/(8. * N0);
+	P->B6 = R_R0_4 * (-2. + t2 * (-5. + 6. * t2))/48.;
+	P->B7 = R_R0_4 * (5. + t2 * (19. + 12. * t2))/24.;
+	P->B8 = R_R0_4 / 120.;
+	P->C3 = R_R0_2 * t * (1. + t2)/(3. * N0);
+	P->C4 = R_R0_4 * (-3. + t2 * (34. + 22. * t2))/240.;
+	P->C5 = R_R0_4 * (4. + t2 * (13. + 12. * t2))/24.;
+	P->C6 = R_R0_4 / 16.;
+	P->C7 = R_R0_4 * t * (11. + t2 * (33. + t2 * 16.))/(48. * N0);
+	P->C8 = R_R0_4 * t * (1. + t2 * 4.)/(36. * N0);
+	P->D1 = t / (2. * N0);
+	P->D2 = R_R0_2 / 12.;
+	P->D3 = R_R0_2 * (2 * t2 + 1. - 2. * es2) / 4.;
+	P->D4 = R_R0_2 * t * (1. + t2)/(8. * N0);
+	P->D5 = R_R0_2 * t * (1. + t2 * 2.)/(4. * N0);
+	P->D6 = R_R0_4 * (1. + t2 * (6. + t2 * 6.))/16.;
+	P->D7 = R_R0_4 * t2 * (3. + t2 * 4.)/8.;
+	P->D8 = R_R0_4 / 80.;
+	P->D9 = R_R0_4 * t * (-21. + t2 * (178. - t2 * 26.))/720.;
+	P->D10 = R_R0_4 * t * (29. + t2 * (86. + t2 * 48.))/(96. * N0);
+	P->D11 = R_R0_4 * t * (37. + t2 * 44.)/(96. * N0);
+	P->fwd = e_forward;
+	P->inv = e_inverse;
+	ENDENTRY(P)
+/*
+** $Log: proj_rouss.c,v $
+** Revision 3.1  2006/01/11 01:38:18  gie
+** Initial
+**
+*/
--- PJ_mdist.c	Fri Feb 10 22:21:50 2006
+++ PJ_mdist.c	Sun Feb 05 11:26:43 2006
@@ -0,0 +1,129 @@
+/*
+** libproj -- library of cartographic projections
+**
+** Copyright (c) 2003, 2006   Gerald I. Evenden
+*/
+/*
+** Permission is hereby granted, free of charge, to any person obtaining
+** a copy of this software and associated documentation files (the
+** "Software"), to deal in the Software without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Software, and to
+** permit persons to whom the Software is furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be
+** included in all copies or substantial portions of the Software.
+**
+** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+/* Computes distance from equator along the meridian to latitude phi
+** and inverse on unit ellipsoid.
+** Precision commensurate with double precision.
+*/
+#define PJ_LIB__
+#include <projects.h>
+PJ_CVSID("$Id: proj_mdist.c,v 3.1 2006/01/11 01:38:18 gie Exp $");
+#define MAX_ITER 20
+#define TOL 1e-14
+
+struct MDIST {
+	int nb;
+	double es;
+	double E;
+	double b[1];
+};
+#define B ((struct MDIST *)b)
+	void *
+proj_mdist_ini(double es) {
+	double numf, numfi, twon1, denf, denfi, ens, T, twon;
+	double den, El, Es;
+	double E[MAX_ITER];
+	struct MDIST *b;
+	int i, j;
+
+/* generate E(e^2) and its terms E[] */
+	ens = es;
+	numf = twon1 = denfi = 1.;
+	denf = 1.;
+	twon = 4.;
+	Es = El = E[0] = 1.;
+	for (i = 1; i < MAX_ITER ; ++i) {
+		numf *= (twon1 * twon1);
+		den = twon * denf * denf * twon1;
+		T = numf/den;
+		Es -= (E[i] = T * ens);
+		ens *= es;
+		twon *= 4.;
+		denf *= ++denfi;
+		twon1 += 2.;
+		if (Es == El) /* jump out if no change */
+			break;
+		El = Es;
+	}
+	if ((b = (struct MDIST *)malloc(sizeof(struct MDIST)+
+		(i*sizeof(double)))) == NULL)
+		return(NULL);
+	b->nb = i - 1;
+	b->es = es;
+	b->E = Es;
+	/* generate b_n coefficients--note: collapse with prefix ratios */
+	b->b[0] = Es = 1. - Es;
+	numf = denf = 1.;
+	numfi = 2.;
+	denfi = 3.;
+	for (j = 1; j < i; ++j) {
+		Es -= E[j];
+		numf *= numfi;
+		denf *= denfi;
+		b->b[j] = Es * numf / denf;
+		numfi += 2.;
+		denfi += 2.;
+	}
+	return (b);
+}
+	double
+proj_mdist(double phi, double sphi, double cphi, const void *b) {
+	double sc, sum, sphi2, D;
+	int i;
+
+	sc = sphi * cphi;
+	sphi2 = sphi * sphi;
+	D = phi * B->E - B->es * sc / sqrt(1. - B->es * sphi2);
+	sum = B->b[i = B->nb];
+	while (i) sum = B->b[--i] + sphi2 * sum;
+	return(D + sc * sum);
+}
+double
+proj_inv_mdist(double dist, const void *b) {
+	double s, t, phi, k;
+	int i;
+
+	k = 1./(1.- B->es);
+	i = MAX_ITER;
+	phi = dist;
+	while ( i-- ) {
+		s = sin(phi);
+		t = 1. - B->es * s * s;
+		phi -= t = (proj_mdist(phi, s, cos(phi), b) - dist) *
+			(t * sqrt(t)) * k;
+		if (fabs(t) < TOL) /* that is no change */
+			return phi;
+	}
+		/* convergence failed */
+	//E_ERROR(-17);
+	printf("ERROR:-17\n");
+	return phi;
+}
+/* Revision Log:
+** $Log: proj_mdist.c,v $
+** Revision 3.1  2006/01/11 01:38:18  gie
+** Initial
+**
+*/
--- Makefile.am	Sat Oct 30 04:36:25 2004
+++ Makefile.am	Sun Feb 05 10:33:59 2006
@@ -42,9 +42,9 @@
 	PJ_eck1.c PJ_eck2.c PJ_eck3.c PJ_eck4.c \
 	PJ_eck5.c PJ_fahey.c PJ_fouc_s.c PJ_gins8.c \
 	PJ_gn_sinu.c PJ_goode.c PJ_hatano.c PJ_loxim.c \
-	PJ_mbt_fps.c PJ_mbtfpp.c PJ_mbtfpq.c PJ_moll.c \
+	PJ_mbt_fps.c PJ_mbtfpp.c PJ_mbtfpq.c PJ_mdist.c PJ_moll.c \
 	PJ_nell.c PJ_nell_h.c PJ_putp2.c PJ_putp3.c \
-	PJ_putp4p.c PJ_putp5.c PJ_putp6.c PJ_robin.c \
+	PJ_putp4p.c PJ_putp5.c PJ_putp6.c PJ_robin.c PJ_rouss.c \
 	PJ_sts.c PJ_urm5.c PJ_urmfps.c PJ_wag2.c \
 	PJ_wag3.c PJ_wink1.c PJ_wink2.c pj_latlong.c pj_geocent.c \
 	aasincos.c adjlon.c bch2bps.c bchgen.c \
--- Makefile.in	Sat Oct 30 04:42:41 2004
+++ Makefile.in	Sun Feb 05 12:38:30 2006
@@ -83,7 +83,7 @@
 	vector1.lo pj_release.lo pj_gauss.lo nad_cvt.lo nad_init.lo \
 	nad_intr.lo emess.lo pj_apply_gridshift.lo pj_datums.lo \
 	pj_datum_set.lo pj_transform.lo geocent.lo pj_utils.lo \
-	pj_gridinfo.lo pj_gridlist.lo jniproj.lo
+	pj_gridinfo.lo pj_gridlist.lo jniproj.lo PJ_mdist.lo PJ_rouss.lo
 libproj_la_OBJECTS = $(am_libproj_la_OBJECTS)
 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
 PROGRAMS = $(bin_PROGRAMS)
@@ -132,6 +132,8 @@
 @AMDEP_TRUE@	./$(DEPDIR)/PJ_mbt_fps.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/PJ_mbtfpp.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/PJ_mbtfpq.Plo ./$(DEPDIR)/PJ_merc.Plo \
+@AMDEP_TRUE@	./$(DEPDIR)/PJ_mdist.Plo \
+@AMDEP_TRUE@	./$(DEPDIR)/PJ_rouss.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/PJ_mill.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/PJ_mod_ster.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/PJ_moll.Plo ./$(DEPDIR)/PJ_mpoly.Plo \
@@ -352,7 +354,7 @@
 	pj_open_lib.c pj_param.c pj_phi2.c pj_pr_list.c \
 	pj_qsfn.c pj_strerrno.c pj_tsfn.c pj_units.c \
 	pj_zpoly1.c rtodms.c vector1.c pj_release.c pj_gauss.c \
-	\
+	PJ_mdist.c PJ_rouss.c \
 	nad_cvt.c nad_init.c nad_intr.c emess.c emess.h \
 	pj_apply_gridshift.c pj_datums.c pj_datum_set.c pj_transform.c \
 	geocent.c geocent.h pj_utils.c pj_gridinfo.c pj_gridlist.c \
@@ -635,6 +637,8 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proj.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rtodms.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector1.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PJ_mdist.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PJ_rouss.Plo@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
--- makefile.vc	Thu Oct 28 18:40:54 2004
+++ makefile.vc	Sun Feb 05 10:34:35 2006
@@ -40,7 +40,8 @@
 	PJ_chamb.obj PJ_hammer.obj PJ_lagrng.obj PJ_larr.obj \
 	PJ_lask.obj PJ_nocol.obj PJ_ob_tran.obj PJ_oea.obj \
 	PJ_tpeqd.obj PJ_vandg.obj PJ_vandg2.obj PJ_vandg4.obj \
-	PJ_wag7.obj pj_latlong.obj PJ_krovak.obj pj_geocent.obj 
+	PJ_wag7.obj pj_latlong.obj PJ_krovak.obj pj_geocent.obj \
+	PJ_mdist.obj PJ_rouss.obj
 
 pseudo = \
 	PJ_boggs.obj PJ_collg.obj PJ_crast.obj PJ_denoy.obj \
--- pj_list.h	Tue Oct 19 16:39:45 2004
+++ pj_list.h	Sun Feb 05 11:19:54 2006
@@ -101,6 +101,7 @@
 PROJ_HEAD(qua_aut, "Quartic Authalic")
 PROJ_HEAD(robin, "Robinson")
 PROJ_HEAD(rpoly, "Rectangular Polyconic")
+PROJ_HEAD(rouss, "Roussilhe Stereographic")
 PROJ_HEAD(sinu, "Sinusoidal (Sanson-Flamsteed)")
 PROJ_HEAD(somerc, "Swiss. Obl. Mercator")
 PROJ_HEAD(stere, "Stereographic")
--- proj.def	Thu Oct 28 18:40:54 2004
+++ proj.def	Sun Feb 05 12:31:16 2006
@@ -39,3 +39,4 @@
 	pj_param		  @37
 	pj_ell_set		  @38
 	pj_mkparam		  @39
+	pj_release		  @40
--- projects.h	Thu Oct 28 18:40:54 2004
+++ projects.h	Sun Feb 05 10:33:04 2006
@@ -377,6 +377,9 @@
 double pj_qsfn_(double, PJ *);
 double *pj_authset(double);
 double pj_authlat(double, double *);
+void *proj_mdist_ini(double es);
+double proj_mdist(double phi, double sphi, double cphi, const void *b);
+double proj_inv_mdist(double dist, const void *b);
 COMPLEX pj_zpoly1(COMPLEX, COMPLEX *, int);
 COMPLEX pj_zpolyd1(COMPLEX, COMPLEX *, int, COMPLEX *);
 FILE *pj_open_lib(char *, char *);
