head	8.7;
access;
symbols;
locks; strict;
comment	@ * @;


8.7
date	2026.05.11.12.01.10;	author mcalabre;	state Exp;
branches;
next	8.6;

8.6
date	2026.03.29.13.53.56;	author mcalabre;	state Exp;
branches
	8.6.1.1;
next	8.5;

8.5
date	2025.12.06.13.47.41;	author mcalabre;	state Exp;
branches
	8.5.1.1;
next	8.4;

8.4
date	2024.10.28.13.56.16;	author mcalabre;	state Exp;
branches
	8.4.1.1;
next	8.3;

8.3
date	2024.05.13.16.33.00;	author mcalabre;	state Exp;
branches
	8.3.1.1;
next	8.2;

8.2
date	2023.11.16.10.00.29;	author mcalabre;	state Exp;
branches
	8.2.1.1;
next	8.1;

8.1
date	2023.07.05.17.12.07;	author mcalabre;	state Exp;
branches
	8.1.1.1;
next	8.0;

8.0
date	2023.07.01.06.15.04;	author mcalabre;	state Exp;
branches
	8.0.1.1;
next	7.13;

7.13
date	2022.10.07.03.43.35;	author mcalabre;	state Exp;
branches
	7.13.1.1;
next	7.12;

7.12
date	2022.09.09.04.57.58;	author mcalabre;	state Exp;
branches
	7.12.1.1;
next	7.11;

7.11
date	2022.04.26.06.13.52;	author mcalabre;	state Exp;
branches
	7.11.1.1;
next	7.10;

7.10
date	2022.04.23.14.25.15;	author mcalabre;	state Exp;
branches
	7.10.1.1;
next	7.9;

7.9
date	2022.03.25.15.14.48;	author mcalabre;	state Exp;
branches
	7.9.1.1;
next	7.8;

7.8
date	2022.03.25.06.11.49;	author mcalabre;	state Exp;
branches
	7.8.1.1;
next	7.7;

7.7
date	2021.07.12.06.36.49;	author mcalabre;	state Exp;
branches
	7.7.1.1;
next	7.6;

7.6
date	2021.04.13.12.57.01;	author mcalabre;	state Exp;
branches
	7.6.1.1;
next	7.5;

7.5
date	2021.03.20.05.54.58;	author mcalabre;	state Exp;
branches
	7.5.1.1;
next	7.4;

7.4
date	2021.01.31.02.24.51;	author mcalabre;	state Exp;
branches
	7.4.1.1;
next	7.3;

7.3
date	2020.06.03.03.37.02;	author mcalabre;	state Exp;
branches
	7.3.1.1;
next	7.2;

7.2
date	2020.03.09.07.31.23;	author mcalabre;	state Exp;
branches
	7.2.1.1;
next	7.1;

7.1
date	2019.12.31.13.25.19;	author mcalabre;	state Exp;
branches
	7.1.1.1;
next	6.4;

6.4
date	2019.08.15.09.30.18;	author mcalabre;	state Exp;
branches
	6.4.1.1;
next	6.3;

6.3
date	2019.07.12.07.33.39;	author mcalabre;	state Exp;
branches
	6.3.1.1;
next	6.2;

6.2
date	2018.10.20.10.03.13;	author mcalabre;	state Exp;
branches
	6.2.1.1;
next	6.1;

6.1
date	2018.10.19.08.35.17;	author mcalabre;	state Exp;
branches
	6.1.1.1;
next	5.20;

5.20
date	2018.10.05.05.32.41;	author mcalabre;	state Exp;
branches
	5.20.1.1;
next	5.19;

5.19
date	2018.07.26.15.37.04;	author mcalabre;	state Exp;
branches
	5.19.1.1;
next	5.18;

5.18
date	2018.01.10.08.32.14;	author mcalabre;	state Exp;
branches
	5.18.1.1;
next	5.17;

5.17
date	2017.09.18.08.44.23;	author mcalabre;	state Exp;
branches
	5.17.1.1;
next	5.16;

5.16
date	2017.01.15.04.25.01;	author mcalabre;	state Exp;
branches
	5.16.1.1;
next	5.15;

5.15
date	2016.04.05.12.55.10;	author mcalabre;	state Exp;
branches
	5.15.1.1;
next	5.14;

5.14
date	2016.02.07.10.49.31;	author mcalabre;	state Exp;
branches
	5.14.1.1;
next	5.13;

5.13
date	2016.01.26.08.51.13;	author mcalabre;	state Exp;
branches
	5.13.1.1;
next	5.12;

5.12
date	2015.11.15.02.13.00;	author mcalabre;	state Exp;
branches
	5.12.1.1;
next	5.11;

5.11
date	2015.10.18.09.13.05;	author mcalabre;	state Exp;
branches
	5.11.1.1;
next	5.10;

5.10
date	2015.10.09.08.19.15;	author mcalabre;	state Exp;
branches
	5.10.1.1;
next	5.9;

5.9
date	2015.07.21.09.20.01;	author mcalabre;	state Exp;
branches
	5.9.1.1;
next	5.8;

5.8
date	2015.07.08.11.03.59;	author mcalabre;	state Exp;
branches
	5.8.1.1;
next	5.7;

5.7
date	2015.06.29.02.44.16;	author mcalabre;	state Exp;
branches
	5.7.1.1;
next	5.6;

5.6
date	2015.06.14.07.11.24;	author mcalabre;	state Exp;
branches
	5.6.1.1;
next	5.5;

5.5
date	2015.05.05.13.16.31;	author mcalabre;	state Exp;
branches
	5.5.1.1;
next	5.4;

5.4
date	2015.04.21.14.41.05;	author mcalabre;	state Exp;
branches
	5.4.1.1;
next	5.3;

5.3
date	2015.04.21.02.50.51;	author mcalabre;	state Exp;
branches
	5.3.1.1;
next	5.2;

5.2
date	2015.04.15.12.35.07;	author mcalabre;	state Exp;
branches
	5.2.1.1;
next	5.1;

5.1
date	2015.04.07.10.56.36;	author mcalabre;	state Exp;
branches
	5.1.1.1;
next	5.0;

5.0
date	2015.04.05.12.24.59;	author mcalabre;	state Exp;
branches
	5.0.1.1;
next	4.25;

4.25
date	2014.12.14.14.29.36;	author mcalabre;	state Exp;
branches
	4.25.1.1;
next	4.24;

4.24
date	2014.09.18.15.25.00;	author mcalabre;	state Exp;
branches
	4.24.1.1;
next	4.23;

4.23
date	2014.05.13.05.50.51;	author mcalabre;	state Exp;
branches
	4.23.1.1;
next	4.22;

4.22
date	2014.04.12.15.03.52;	author mcalabre;	state Exp;
branches
	4.22.1.1;
next	4.21;

4.21
date	2014.03.24.05.12.27;	author mcalabre;	state Exp;
branches
	4.21.1.1;
next	4.20;

4.20
date	2013.12.18.05.42.49;	author mcalabre;	state Exp;
branches
	4.20.1.1;
next	4.19;

4.19
date	2013.09.29.14.17.51;	author mcalabre;	state Exp;
branches
	4.19.1.1;
next	4.18;

4.18
date	2013.07.13.10.00.04;	author mcalabre;	state Exp;
branches
	4.18.1.1;
next	4.17;

4.17
date	2013.01.29.05.29.20;	author cal103;	state Exp;
branches
	4.17.1.1;
next	4.16;

4.16
date	2012.11.07.04.42.44;	author cal103;	state Exp;
branches
	4.16.1.1;
next	4.15;

4.15
date	2012.09.26.14.26.05;	author cal103;	state Exp;
branches
	4.15.1.1;
next	4.14;

4.14
date	2012.07.13.10.02.27;	author cal103;	state Exp;
branches
	4.14.1.1;
next	4.13;

4.13
date	2012.03.14.07.39.30;	author cal103;	state Exp;
branches
	4.13.1.1;
next	4.12;

4.12
date	2012.02.29.07.57.56;	author cal103;	state Exp;
branches
	4.12.1.1;
next	4.11;

4.11
date	2012.02.20.23.30.02;	author cal103;	state Exp;
branches
	4.11.1.1;
next	4.10;

4.10
date	2012.02.05.23.41.44;	author cal103;	state Exp;
branches
	4.10.1.1;
next	4.9;

4.9
date	2012.01.24.05.40.29;	author cal103;	state Exp;
branches
	4.9.1.1;
next	4.8;

4.8
date	2011.08.15.08.05.53;	author cal103;	state Exp;
branches
	4.8.1.1;
next	4.7;

4.7
date	2011.02.07.07.03.42;	author cal103;	state Exp;
branches
	4.7.1.1;
next	4.6;

4.6
date	2010.11.16.06.15.31;	author cal103;	state Exp;
branches
	4.6.1.1;
next	4.5;

4.5
date	2010.07.16.07.01.25;	author cal103;	state Exp;
branches
	4.5.1.1;
next	4.4;

4.4
date	2009.08.06.07.41.33;	author cal103;	state Exp;
branches
	4.4.1.1;
next	4.3;

4.3
date	2007.12.27.05.41.36;	author cal103;	state Exp;
branches
	4.3.1.1;
next	4.2;

4.2
date	2005.09.21.13.21.57;	author cal103;	state Exp;
branches
	4.2.1.1;
next	4.1;

4.1
date	2005.08.25.08.10.47;	author cal103;	state Exp;
branches;
next	4.0;

4.0
date	2005.02.04.05.46.39;	author cal103;	state Exp;
branches;
next	3.6;

3.6
date	2004.08.25.04.22.31;	author cal103;	state Exp;
branches;
next	3.5;

3.5
date	2004.06.28.01.53.03;	author mcalabre;	state Exp;
branches;
next	3.4;

3.4
date	2004.02.11.00.15.03;	author mcalabre;	state Exp;
branches;
next	3.3;

3.3
date	2003.10.21.08.52.49;	author mcalabre;	state Exp;
branches;
next	3.2;

3.2
date	2003.09.09.04.04.04;	author mcalabre;	state Exp;
branches;
next	3.1;

3.1
date	2003.04.28.03.50.41;	author mcalabre;	state Exp;
branches;
next	3.0;

3.0
date	2003.04.01.04.11.54;	author mcalabre;	state Exp;
branches;
next	2.7;

2.7
date	2002.04.03.01.25.29;	author mcalabre;	state Exp;
branches;
next	2.6;

2.6
date	2001.11.15.03.14.40;	author mcalabre;	state Exp;
branches;
next	2.5;

2.5
date	2000.05.10.04.44.05;	author mcalabre;	state Exp;
branches;
next	2.4;

2.4
date	99.12.13.07.27.35;	author mcalabre;	state Exp;
branches;
next	2.3;

2.3
date	99.06.16.00.04.28;	author mcalabre;	state Exp;
branches;
next	2.2;

2.2
date	98.02.25.07.05.50;	author mcalabre;	state Exp;
branches;
next	2.1;

2.1
date	95.11.09.03.17.43;	author mcalabre;	state Exp;
branches;
next	2.0;

2.0
date	95.09.11.08.38.47;	author mcalabre;	state Exp;
branches;
next	1.2;

1.2
date	95.09.11.08.37.36;	author mcalabre;	state Exp;
branches;
next	1.1;

1.1
date	95.01.31.03.20.27;	author mcalabre;	state Exp;
branches;
next	;

4.2.1.1
date	2005.12.05.02.39.43;	author cal103;	state Exp;
branches;
next	4.2.1.2;

4.2.1.2
date	2007.12.03.05.02.17;	author cal103;	state Exp;
branches;
next	;

4.3.1.1
date	2007.12.27.13.23.47;	author cal103;	state Exp;
branches;
next	4.3.1.2;

4.3.1.2
date	2009.07.22.02.19.20;	author cal103;	state Exp;
branches;
next	4.3.1.3;

4.3.1.3
date	2009.07.27.06.05.48;	author cal103;	state Exp;
branches;
next	4.3.1.4;

4.3.1.4
date	2009.07.30.00.04.25;	author cal103;	state Exp;
branches;
next	4.3.1.5;

4.3.1.5
date	2009.07.30.04.20.24;	author cal103;	state Exp;
branches;
next	;

4.4.1.1
date	2009.08.10.08.52.49;	author cal103;	state Exp;
branches;
next	4.4.1.2;

4.4.1.2
date	2009.08.12.08.22.27;	author cal103;	state Exp;
branches;
next	4.4.1.3;

4.4.1.3
date	2010.01.19.03.42.50;	author cal103;	state Exp;
branches;
next	;

4.5.1.1
date	2010.07.16.07.05.31;	author cal103;	state Exp;
branches;
next	4.5.1.2;

4.5.1.2
date	2010.08.12.07.38.46;	author cal103;	state Exp;
branches;
next	;

4.6.1.1
date	2010.11.16.06.16.19;	author cal103;	state Exp;
branches;
next	4.6.1.2;

4.6.1.2
date	2011.01.14.06.33.16;	author cal103;	state Exp;
branches;
next	;

4.7.1.1
date	2011.02.07.07.04.22;	author cal103;	state Exp;
branches;
next	4.7.1.2;

4.7.1.2
date	2011.08.10.08.03.20;	author cal103;	state Exp;
branches;
next	;

4.8.1.1
date	2011.08.15.08.07.06;	author cal103;	state Exp;
branches;
next	4.8.1.2;

4.8.1.2
date	2012.01.24.05.23.06;	author cal103;	state Exp;
branches;
next	;

4.9.1.1
date	2012.01.24.05.41.45;	author cal103;	state Exp;
branches;
next	;

4.10.1.1
date	2012.02.05.23.42.46;	author cal103;	state Exp;
branches;
next	;

4.11.1.1
date	2012.02.20.23.31.13;	author cal103;	state Exp;
branches;
next	;

4.12.1.1
date	2012.02.29.07.59.10;	author cal103;	state Exp;
branches;
next	;

4.13.1.1
date	2012.03.14.07.40.37;	author cal103;	state Exp;
branches;
next	4.13.1.2;

4.13.1.2
date	2012.07.13.03.34.20;	author cal103;	state Exp;
branches;
next	;

4.14.1.1
date	2012.07.13.10.04.44;	author cal103;	state Exp;
branches;
next	;

4.15.1.1
date	2012.09.26.14.27.51;	author cal103;	state Exp;
branches;
next	;

4.16.1.1
date	2012.11.07.04.45.56;	author cal103;	state Exp;
branches;
next	4.16.1.2;

4.16.1.2
date	2013.01.29.05.09.44;	author cal103;	state Exp;
branches;
next	;

4.17.1.1
date	2013.01.29.05.32.32;	author cal103;	state Exp;
branches;
next	;

4.18.1.1
date	2013.07.13.10.02.37;	author mcalabre;	state Exp;
branches;
next	;

4.19.1.1
date	2013.09.29.14.20.38;	author mcalabre;	state Exp;
branches;
next	;

4.20.1.1
date	2013.12.18.05.46.55;	author mcalabre;	state Exp;
branches;
next	4.20.1.2;

4.20.1.2
date	2014.03.21.06.32.19;	author mcalabre;	state Exp;
branches;
next	;

4.21.1.1
date	2014.03.24.05.15.28;	author mcalabre;	state Exp;
branches;
next	;

4.22.1.1
date	2014.04.12.15.06.32;	author mcalabre;	state Exp;
branches;
next	;

4.23.1.1
date	2014.05.13.05.53.49;	author mcalabre;	state Exp;
branches;
next	;

4.24.1.1
date	2014.09.18.15.28.09;	author mcalabre;	state Exp;
branches;
next	;

4.25.1.1
date	2014.12.14.14.32.45;	author mcalabre;	state Exp;
branches;
next	4.25.1.2;

4.25.1.2
date	2015.01.06.01.01.06;	author mcalabre;	state Exp;
branches;
next	4.25.1.3;

4.25.1.3
date	2015.03.06.07.15.01;	author mcalabre;	state Exp;
branches;
next	;

5.0.1.1
date	2015.04.05.12.28.00;	author mcalabre;	state Exp;
branches;
next	;

5.1.1.1
date	2015.04.07.11.01.10;	author mcalabre;	state Exp;
branches;
next	;

5.2.1.1
date	2015.04.15.12.39.14;	author mcalabre;	state Exp;
branches;
next	;

5.3.1.1
date	2015.04.21.02.54.02;	author mcalabre;	state Exp;
branches;
next	;

5.4.1.1
date	2015.04.21.14.44.28;	author mcalabre;	state Exp;
branches;
next	;

5.5.1.1
date	2015.05.05.13.21.00;	author mcalabre;	state Exp;
branches;
next	;

5.6.1.1
date	2015.06.14.07.14.44;	author mcalabre;	state Exp;
branches;
next	5.6.1.2;

5.6.1.2
date	2015.06.27.06.21.47;	author mcalabre;	state Exp;
branches;
next	5.6.1.3;

5.6.1.3
date	2015.06.28.07.40.35;	author mcalabre;	state Exp;
branches;
next	;

5.7.1.1
date	2015.06.29.02.47.24;	author mcalabre;	state Exp;
branches;
next	;

5.8.1.1
date	2015.07.08.11.07.18;	author mcalabre;	state Exp;
branches;
next	;

5.9.1.1
date	2015.07.21.09.28.07;	author mcalabre;	state Exp;
branches;
next	;

5.10.1.1
date	2015.10.09.08.22.35;	author mcalabre;	state Exp;
branches;
next	;

5.11.1.1
date	2015.10.18.09.16.27;	author mcalabre;	state Exp;
branches;
next	;

5.12.1.1
date	2015.11.15.02.16.14;	author mcalabre;	state Exp;
branches;
next	5.12.1.2;

5.12.1.2
date	2016.01.25.05.17.04;	author mcalabre;	state Exp;
branches;
next	;

5.13.1.1
date	2016.01.26.08.54.32;	author mcalabre;	state Exp;
branches;
next	;

5.14.1.1
date	2016.02.07.10.52.44;	author mcalabre;	state Exp;
branches;
next	;

5.15.1.1
date	2016.04.05.12.58.35;	author mcalabre;	state Exp;
branches;
next	5.15.1.2;

5.15.1.2
date	2017.01.15.04.13.33;	author mcalabre;	state Exp;
branches;
next	;

5.16.1.1
date	2017.01.15.04.28.59;	author mcalabre;	state Exp;
branches;
next	;

5.17.1.1
date	2017.09.18.08.45.59;	author mcalabre;	state Exp;
branches;
next	5.17.1.2;

5.17.1.2
date	2018.01.10.08.25.34;	author mcalabre;	state Exp;
branches;
next	;

5.18.1.1
date	2018.01.10.08.33.04;	author mcalabre;	state Exp;
branches;
next	;

5.19.1.1
date	2018.07.26.15.41.40;	author mcalabre;	state Exp;
branches;
next	;

5.20.1.1
date	2018.10.05.05.33.33;	author mcalabre;	state Exp;
branches;
next	;

6.1.1.1
date	2018.10.19.08.36.15;	author mcalabre;	state Exp;
branches;
next	;

6.2.1.1
date	2018.10.20.10.04.15;	author mcalabre;	state Exp;
branches;
next	6.2.1.2;

6.2.1.2
date	2019.05.10.01.56.50;	author mcalabre;	state Exp;
branches;
next	;

6.3.1.1
date	2019.07.12.07.34.37;	author mcalabre;	state Exp;
branches;
next	;

6.4.1.1
date	2019.08.15.09.31.29;	author mcalabre;	state Exp;
branches;
next	6.4.1.2;

6.4.1.2
date	2019.12.31.03.28.03;	author mcalabre;	state Exp;
branches;
next	;

7.1.1.1
date	2019.12.31.13.28.19;	author mcalabre;	state Exp;
branches;
next	;

7.2.1.1
date	2020.03.09.07.34.50;	author mcalabre;	state Exp;
branches;
next	;

7.3.1.1
date	2020.06.03.03.38.10;	author mcalabre;	state Exp;
branches;
next	7.3.1.2;

7.3.1.2
date	2020.08.17.11.19.09;	author mcalabre;	state Exp;
branches;
next	7.3.1.3;

7.3.1.3
date	2021.01.19.14.09.10;	author mcalabre;	state Exp;
branches;
next	7.3.1.4;

7.3.1.4
date	2021.01.28.12.29.30;	author mcalabre;	state Exp;
branches;
next	;

7.4.1.1
date	2021.01.31.02.26.24;	author mcalabre;	state Exp;
branches;
next	;

7.5.1.1
date	2021.03.20.05.56.42;	author mcalabre;	state Exp;
branches;
next	;

7.6.1.1
date	2021.04.13.13.00.35;	author mcalabre;	state Exp;
branches;
next	;

7.7.1.1
date	2021.07.12.06.38.27;	author mcalabre;	state Exp;
branches;
next	7.7.1.2;

7.7.1.2
date	2022.03.25.06.05.59;	author mcalabre;	state Exp;
branches;
next	;

7.8.1.1
date	2022.03.25.06.14.14;	author mcalabre;	state Exp;
branches;
next	;

7.9.1.1
date	2022.03.25.15.16.40;	author mcalabre;	state Exp;
branches;
next	;

7.10.1.1
date	2022.04.23.14.26.54;	author mcalabre;	state Exp;
branches;
next	;

7.11.1.1
date	2022.04.26.06.15.32;	author mcalabre;	state Exp;
branches;
next	;

7.12.1.1
date	2022.09.09.05.00.36;	author mcalabre;	state Exp;
branches;
next	;

7.13.1.1
date	2022.10.07.03.45.47;	author mcalabre;	state Exp;
branches;
next	7.13.1.2;

7.13.1.2
date	2023.06.15.04.17.19;	author mcalabre;	state Exp;
branches;
next	;

8.0.1.1
date	2023.07.01.06.22.44;	author mcalabre;	state Exp;
branches;
next	;

8.1.1.1
date	2023.07.05.17.15.00;	author mcalabre;	state Exp;
branches;
next	;

8.2.1.1
date	2023.11.16.10.05.57;	author mcalabre;	state Exp;
branches;
next	8.2.1.2;

8.2.1.2
date	2024.04.02.14.01.58;	author mcalabre;	state Exp;
branches;
next	8.2.1.3;

8.2.1.3
date	2024.05.08.09.22.53;	author mcalabre;	state Exp;
branches;
next	8.2.1.4;

8.2.1.4
date	2024.05.08.15.39.34;	author mcalabre;	state Exp;
branches;
next	;

8.3.1.1
date	2024.05.13.16.35.39;	author mcalabre;	state Exp;
branches;
next	;

8.4.1.1
date	2024.10.28.13.58.41;	author mcalabre;	state Exp;
branches;
next	8.4.1.2;

8.4.1.2
date	2025.12.06.13.37.16;	author mcalabre;	state Exp;
branches;
next	;

8.5.1.1
date	2025.12.06.14.05.15;	author mcalabre;	state Exp;
branches;
next	8.5.1.2;

8.5.1.2
date	2026.03.29.13.36.16;	author mcalabre;	state Exp;
branches;
next	;

8.6.1.1
date	2026.03.29.14.19.26;	author mcalabre;	state Exp;
branches;
next	8.6.1.2;

8.6.1.2
date	2026.04.05.14.02.10;	author mcalabre;	state Exp;
branches;
next	8.6.1.3;

8.6.1.3
date	2026.04.13.03.12.13;	author mcalabre;	state Exp;
branches;
next	;


desc
@Implementation of the WCS spherical coordinate transformation equations.
@


8.7
log
@WCSLIB 8.7
@
text
@/*============================================================================
  WCSLIB 8.7 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2026, Mark Calabretta

  This file is part of WCSLIB.

  WCSLIB is free software: you can redistribute it and/or modify it under the
  terms of the GNU Lesser General Public License as published by the Free
  Software Foundation, either version 3 of the License, or (at your option)
  any later version.

  WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
  more details.

  You should have received a copy of the GNU Lesser General Public License
  along with WCSLIB.  If not, see http://www.gnu.org/licenses.

  Author: Mark Calabretta, Australia Telescope National Facility, CSIRO.
  http://www.atnf.csiro.au/computing/software/wcs
  $Id: sph.c,v 8.6.1.3 2026/04/13 03:12:13 mcalabre Exp mcalabre $
*===========================================================================*/

#include <math.h>
#include <stddef.h>

#include "wcstrig.h"
#include "sph.h"

#define tol 1.0e-5

//----------------------------------------------------------------------------

int sphx2s(
  const double eul[5],
  int nphi,
  int ntheta,
  int spt,
  int sll,
  const double phi[],
  const double theta[],
  double lng[],
  double lat[])

{
  int mphi, mtheta;
  if (ntheta > 0) {
    mphi   = nphi;
    mtheta = ntheta;
  } else {
    mphi   = 1;
    mtheta = 1;
    ntheta = nphi;
  }


  // Check for special-case rotations.
  if (eul[4] == 0.0) {
    if (eul[1] == 0.0) {
      // Simple change in origin of longitude.
      double dlng = fmod(eul[0] + 180.0 - eul[2], 360.0);

      int jphi = 0;
      const double *thetap = theta;
      double *lngp = lng;
      double *latp = lat;
      for (int itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
        const double *phip = phi + (ptrdiff_t)((jphi%nphi)*spt);
        for (int iphi = 0; iphi < mphi; iphi++, phip += spt, jphi++) {
          *lngp = *phip + dlng;
          *latp = *thetap;

          // Normalize the celestial longitude.
          if (eul[0] >= 0.0) {
            if (*lngp < 0.0) *lngp += 360.0;
          } else {
            if (*lngp > 0.0) *lngp -= 360.0;
          }

          if (*lngp > 360.0) {
            *lngp -= 360.0;
          } else if (*lngp < -360.0) {
            *lngp += 360.0;
          }

          lngp += sll;
          latp += sll;
        }
      }

    } else {
      // Pole-flip with change in origin of longitude.
      double dlng = fmod(eul[0] + eul[2], 360.0);

      int jphi = 0;
      const double *thetap = theta;
      double *lngp = lng;
      double *latp = lat;
      for (int itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
        const double *phip = phi + (ptrdiff_t)((jphi%nphi)*spt);
        for (int iphi = 0; iphi < mphi; iphi++, phip += spt, jphi++) {
          *lngp = dlng - *phip;
          *latp = -(*thetap);

          // Normalize the celestial longitude.
          if (eul[0] >= 0.0) {
            if (*lngp < 0.0) *lngp += 360.0;
          } else {
            if (*lngp > 0.0) *lngp -= 360.0;
          }

          if (*lngp > 360.0) {
            *lngp -= 360.0;
          } else if (*lngp < -360.0) {
            *lngp += 360.0;
          }

          lngp += sll;
          latp += sll;
        }
      }
    }

    return 0;
  }


  // Do phi dependency.
  const double *phip = phi;
  int rowoff = 0;
  int rowlen = nphi*sll;
  for (int iphi = 0; iphi < nphi; iphi++, rowoff += sll, phip += spt) {
    double dphi = *phip - eul[2];

    double *lngp = lng + rowoff;
    for (int itheta = 0; itheta < mtheta; itheta++) {
      *lngp = dphi;
      lngp += rowlen;
    }
  }


  // Do theta dependency.
  const double *thetap = theta;
  double *lngp = lng;
  double *latp = lat;
  for (int itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
    double sinthe, costhe;
    sincosd(*thetap, &sinthe, &costhe);

    double costhe3 = costhe*eul[3];
    double costhe4 = costhe*eul[4];
    double sinthe3 = sinthe*eul[3];
    double sinthe4 = sinthe*eul[4];

    for (int iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
      double dphi = *lngp;
      double sinphi, cosphi;
      sincosd(dphi, &sinphi, &cosphi);

      // Compute the celestial longitude.
      double x = sinthe4 - costhe3*cosphi;
      if (fabs(x) < tol) {
        // Rearrange formula to reduce roundoff errors.
        x = -cosd(*thetap + eul[1]) + costhe3*(1.0 - cosphi);
      }

      double dlng;
      double y = -costhe*sinphi;
      if (x != 0.0 || y != 0.0) {
        dlng = atan2d(y, x);
      } else {
        // Change of origin of longitude.
        if (eul[1] < 90.0) {
          dlng =  dphi + 180.0;
        } else {
          dlng = -dphi;
        }
      }
      *lngp = eul[0] + dlng;

      // Normalize the celestial longitude.
      if (eul[0] >= 0.0) {
        if (*lngp < 0.0) *lngp += 360.0;
      } else {
        if (*lngp > 0.0) *lngp -= 360.0;
      }

      if (*lngp > 360.0) {
        *lngp -= 360.0;
      } else if (*lngp < -360.0) {
        *lngp += 360.0;
      }

      // Compute the celestial latitude.
      if (fmod(dphi,180.0) == 0.0) {
        *latp = *thetap + cosphi*eul[1];
        if (*latp >  90.0) *latp =  180.0 - *latp;
        if (*latp < -90.0) *latp = -180.0 - *latp;
      } else {
        double z = sinthe3 + costhe4*cosphi;
        if (fabs(z) > 0.99) {
          // Use an alternative formula for greater accuracy.
          *latp = copysign(acosd(sqrt(x*x+y*y)), z);
        } else {
          *latp = asind(z);
        }
      }
    }
  }

  return 0;
}

//----------------------------------------------------------------------------

int sphs2x(
  const double eul[5],
  int nlng,
  int nlat,
  int sll,
  int spt,
  const double lng[],
  const double lat[],
  double phi[],
  double theta[])

{
  int mlng, mlat;
  if (nlat > 0) {
    mlng = nlng;
    mlat = nlat;
  } else {
    mlng = 1;
    mlat = 1;
    nlat = nlng;
  }


  // Check for special-case rotations.
  if (eul[4] == 0.0) {
    if (eul[1] == 0.0) {
      // Simple change in origin of longitude.
      double dphi = fmod(eul[2] - 180.0 - eul[0], 360.0);

      int jlng = 0;
      const double *latp   = lat;
      double *phip   = phi;
      double *thetap = theta;
      for (int ilat = 0; ilat < nlat; ilat++, latp += sll) {
        const double *lngp = lng + (ptrdiff_t)((jlng%nlng)*sll);
        for (int ilng = 0; ilng < mlng; ilng++, lngp += sll, jlng++) {
          *phip = fmod(*lngp + dphi, 360.0);
          *thetap = *latp;

          // Normalize the native longitude.
          if (*phip > 180.0) {
            *phip -= 360.0;
          } else if (*phip < -180.0) {
            *phip += 360.0;
          }

          phip   += spt;
          thetap += spt;
        }
      }

    } else {
      // Pole-flip with change in origin of longitude.
      double dphi = fmod(eul[2] + eul[0], 360.0);

      int jlng   = 0;
      const double *latp   = lat;
      double *phip   = phi;
      double *thetap = theta;
      for (int ilat = 0; ilat < nlat; ilat++, latp += sll) {
        const double *lngp = lng + (ptrdiff_t)((jlng%nlng)*sll);
        for (int ilng = 0; ilng < mlng; ilng++, lngp += sll, jlng++) {
          *phip = fmod(dphi - *lngp, 360.0);
          *thetap = -(*latp);

          // Normalize the native longitude.
          if (*phip > 180.0) {
            *phip -= 360.0;
          } else if (*phip < -180.0) {
            *phip += 360.0;
          }

          phip   += spt;
          thetap += spt;
        }
      }
    }

    return 0;
  }


  // Do lng dependency.
  const double *lngp = lng;
  int rowoff = 0;
  int rowlen = nlng*spt;
  for (int ilng = 0; ilng < nlng; ilng++, rowoff += spt, lngp += sll) {
    double dlng = *lngp - eul[0];

    double *phip = phi + rowoff;
    for (int ilat = 0; ilat < mlat; ilat++) {
      *phip = dlng;
      phip += rowlen;
    }
  }


  // Do lat dependency.
  const double *latp = lat;
  double *phip   = phi;
  double *thetap = theta;
  for (int ilat = 0; ilat < nlat; ilat++, latp += sll) {
    double sinlat, coslat;
    sincosd(*latp, &sinlat, &coslat);

    double coslat3 = coslat*eul[3];
    double coslat4 = coslat*eul[4];
    double sinlat3 = sinlat*eul[3];
    double sinlat4 = sinlat*eul[4];

    for (int ilng = 0; ilng < mlng; ilng++, phip += spt, thetap += spt) {
      double dlng = *phip;
      double sinlng, coslng;
      sincosd(dlng, &sinlng, &coslng);

      // Compute the native longitude.
      double x = sinlat4 - coslat3*coslng;
      if (fabs(x) < tol) {
        // Rearrange formula to reduce roundoff errors.
        x = -cosd(*latp+eul[1]) + coslat3*(1.0 - coslng);
      }

      double dphi;
      double y = -coslat*sinlng;
      if (x != 0.0 || y != 0.0) {
        dphi = atan2d(y, x);
      } else {
        // Change of origin of longitude.
        if (eul[1] < 90.0) {
          dphi =  dlng - 180.0;
        } else {
          dphi = -dlng;
        }
      }
      *phip = fmod(eul[2] + dphi, 360.0);

      // Normalize the native longitude.
      if (*phip > 180.0) {
        *phip -= 360.0;
      } else if (*phip < -180.0) {
        *phip += 360.0;
      }

      // Compute the native latitude.
      if (fmod(dlng,180.0) == 0.0) {
        *thetap = *latp + coslng*eul[1];
        if (*thetap >  90.0) *thetap =  180.0 - *thetap;
        if (*thetap < -90.0) *thetap = -180.0 - *thetap;
      } else {
        double z = sinlat3 + coslat4*coslng;
        if (fabs(z) > 0.99) {
          // Use an alternative formula for greater accuracy.
          *thetap = copysign(acosd(sqrt(x*x+y*y)), z);
        } else {
          *thetap = asind(z);
        }
      }
    }
  }

  return 0;
}

//----------------------------------------------------------------------------

int sphdpa(
  int nfield,
  double lng0,
  double lat0,
  const double lng[],
  const double lat[],
  double dist[],
  double pa[])

{
  // Set the Euler angles for the coordinate transformation.
  double eul[5];
  eul[0] = lng0;
  eul[1] = 90.0 - lat0;
  eul[2] = 0.0;
  eul[3] = cosd(eul[1]);
  eul[4] = sind(eul[1]);

  // Transform field points to the new system.
  sphs2x(eul, nfield, 0, 1, 1, lng, lat, pa, dist);

  for (int i = 0; i < nfield; i++) {
    // Angular distance is obtained from latitude in the new frame.
    dist[i] = 90.0 - dist[i];

    // Position angle is obtained from longitude in the new frame.
    pa[i] = -pa[i];
    if (pa[i] < -180.0) pa[i] += 360.0;
  }

  return 0;
}

//----------------------------------------------------------------------------

int sphpad(
  int nfield,
  double lng0,
  double lat0,
  const double dist[],
  const double pa[],
  double lng[],
  double lat[])

{
  // Set the Euler angles for the coordinate transformation.
  double eul[5];
  eul[0] = lng0;
  eul[1] = 90.0 - lat0;
  eul[2] = 0.0;
  eul[3] = cosd(eul[1]);
  eul[4] = sind(eul[1]);

  for (int i = 0; i < nfield; i++) {
    // Latitude in the new frame is obtained from angular distance.
    lat[i] = 90.0 - dist[i];

    // Longitude in the new frame is obtained from position angle.
    lng[i] = -pa[i];
  }

  // Transform field points to the old system.
  sphx2s(eul, nfield, 0, 1, 1, lng, lat, lng, lat);

  return 0;
}
@


8.6
log
@WCSLIB 8.6
@
text
@d2 1
a2 1
  WCSLIB 8.6 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 8.5.1.2 2026/03/29 13:36:16 mcalabre Exp mcalabre $
d26 2
a30 2
#define copysign(X, Y) ((Y) < 0.0 ? -fabs(X) : fabs(X))

d66 2
a67 2
      double *lngp   = lng;
      double *latp   = lat;
d69 1
a69 1
        const double *phip = phi + (jphi%nphi)*spt;
d98 2
a99 2
      double *lngp   = lng;
      double *latp   = lat;
d101 1
a101 1
        const double *phip = phi + (jphi%nphi)*spt;
d252 1
a252 1
        const double *lngp = lng + (jlng%nlng)*sll;
d278 1
a278 1
        const double *lngp = lng + (jlng%nlng)*sll;
@


8.6.1.1
log
@WCSLIB 8.6 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 8.6 2026/03/29 13:53:56 mcalabre Exp $
@


8.6.1.2
log
@Found by Claude Code:
 - Removed the copysign() macro, now provided by C99.
@
text
@d22 1
a22 1
  $Id: sph.c,v 8.6.1.1 2026/03/29 14:19:26 mcalabre Exp mcalabre $
d29 2
d66 2
a67 2
      double *lngp = lng;
      double *latp = lat;
d98 2
a99 2
      double *lngp = lng;
      double *latp = lat;
@


8.6.1.3
log
@Inconsequential changes prompted by clang-tidy:
 - In sphx2s() and sphs2x(), cast address offset calculations to ptrdiff_t
   (bugprone-implicit-widening-of-multiplication-result).
@
text
@d22 1
a22 1
  $Id: sph.c,v 8.6.1.2 2026/04/05 14:02:10 mcalabre Exp mcalabre $
a25 2
#include <stddef.h>

d67 1
a67 1
        const double *phip = phi + (ptrdiff_t)((jphi%nphi)*spt);
d99 1
a99 1
        const double *phip = phi + (ptrdiff_t)((jphi%nphi)*spt);
d250 1
a250 1
        const double *lngp = lng + (ptrdiff_t)((jlng%nlng)*sll);
d276 1
a276 1
        const double *lngp = lng + (ptrdiff_t)((jlng%nlng)*sll);
@


8.5
log
@WCSLIB 8.5
@
text
@d2 2
a3 2
  WCSLIB 8.5 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2025, Mark Calabretta
d21 2
a22 2
  http://www.atnf.csiro.au/people/Mark.Calabretta
  $Id: sph.c,v 8.4.1.2 2025/12/06 13:37:16 mcalabre Exp mcalabre $
@


8.5.1.1
log
@WCSLIB 8.5 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 8.5 2025/12/06 13:47:41 mcalabre Exp $
@


8.5.1.2
log
@Updated date in copyright notice.
@
text
@d3 1
a3 1
  Copyright (C) 1995-2026, Mark Calabretta
d21 2
a22 2
  http://www.atnf.csiro.au/computing/software/wcs
  $Id: sph.c,v 8.5.1.1 2025/12/06 14:05:15 mcalabre Exp mcalabre $
@


8.4
log
@WCSLIB 8.4
@
text
@d2 2
a3 2
  WCSLIB 8.4 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2024, Mark Calabretta
d22 1
a22 1
  $Id: sph.c,v 8.3.1.1 2024/05/13 16:35:39 mcalabre Exp mcalabre $
@


8.4.1.1
log
@WCSLIB 8.4 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 8.4 2024/10/28 13:56:16 mcalabre Exp $
@


8.4.1.2
log
@Updated date in copyright notice.
@
text
@d3 1
a3 1
  Copyright (C) 1995-2025, Mark Calabretta
d22 1
a22 1
  $Id: sph.c,v 8.4.1.1 2024/10/28 13:58:41 mcalabre Exp mcalabre $
@


8.3
log
@WCSLIB 8.3
@
text
@d2 1
a2 1
  WCSLIB 8.3 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 8.2.1.4 2024/05/08 15:39:34 mcalabre Exp mcalabre $
@


8.3.1.1
log
@WCSLIB 8.3 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 8.3 2024/05/13 16:33:00 mcalabre Exp $
@


8.2
log
@WCSLIB 8.2
@
text
@d2 2
a3 2
  WCSLIB 8.2 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2023, Mark Calabretta
d22 1
a22 1
  $Id: sph.c,v 8.1.1.1 2023/07/05 17:15:00 mcalabre Exp mcalabre $
d47 1
a47 7
  int jphi, mphi, mtheta, rowlen, rowoff;
  double cosphi, costhe, costhe3, costhe4, dlng, dphi, sinphi, sinthe,
         sinthe3, sinthe4, x, y, z;
  register int iphi, itheta;
  register const double *phip, *thetap;
  register double *latp, *lngp;

d62 1
a62 1
      dlng = fmod(eul[0] + 180.0 - eul[2], 360.0);
d64 7
a70 7
      jphi   = 0;
      thetap = theta;
      lngp   = lng;
      latp   = lat;
      for (itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
        phip = phi + (jphi%nphi)*spt;
        for (iphi = 0; iphi < mphi; iphi++, phip += spt, jphi++) {
d94 1
a94 1
      dlng = fmod(eul[0] + eul[2], 360.0);
d96 7
a102 7
      jphi   = 0;
      thetap = theta;
      lngp   = lng;
      latp   = lat;
      for (itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
        phip = phi + (jphi%nphi)*spt;
        for (iphi = 0; iphi < mphi; iphi++, phip += spt, jphi++) {
d130 5
a134 5
  phip = phi;
  rowoff = 0;
  rowlen = nphi*sll;
  for (iphi = 0; iphi < nphi; iphi++, rowoff += sll, phip += spt) {
    dphi = *phip - eul[2];
d136 2
a137 2
    lngp = lng + rowoff;
    for (itheta = 0; itheta < mtheta; itheta++) {
d145 5
a149 4
  thetap = theta;
  lngp = lng;
  latp = lat;
  for (itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
a150 4
    costhe3 = costhe*eul[3];
    costhe4 = costhe*eul[4];
    sinthe3 = sinthe*eul[3];
    sinthe4 = sinthe*eul[4];
d152 8
a159 2
    for (iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
      dphi = *lngp;
d163 1
a163 1
      x = sinthe4 - costhe3*cosphi;
d169 2
a170 1
      y = -costhe*sinphi;
d202 1
a202 1
        z = sinthe3 + costhe4*cosphi;
d230 1
a230 7
  int jlng, mlat, mlng, rowlen, rowoff;
  double coslat, coslat3, coslat4, coslng, dlng, dphi, sinlat, sinlat3,
         sinlat4, sinlng, x, y, z;
  register int ilat, ilng;
  register const double *latp, *lngp;
  register double *phip, *thetap;

d245 1
a245 1
      dphi = fmod(eul[2] - 180.0 - eul[0], 360.0);
d247 7
a253 7
      jlng   = 0;
      latp   = lat;
      phip   = phi;
      thetap = theta;
      for (ilat = 0; ilat < nlat; ilat++, latp += sll) {
        lngp = lng + (jlng%nlng)*sll;
        for (ilng = 0; ilng < mlng; ilng++, lngp += sll, jlng++) {
d271 1
a271 1
      dphi = fmod(eul[2] + eul[0], 360.0);
d273 7
a279 7
      jlng   = 0;
      latp   = lat;
      phip   = phi;
      thetap = theta;
      for (ilat = 0; ilat < nlat; ilat++, latp += sll) {
        lngp = lng + (jlng%nlng)*sll;
        for (ilng = 0; ilng < mlng; ilng++, lngp += sll, jlng++) {
d301 8
a308 9
  lngp = lng;
  rowoff = 0;
  rowlen = nlng*spt;
  for (ilng = 0; ilng < nlng; ilng++, rowoff += spt, lngp += sll) {
    dlng = *lngp - eul[0];

    phip = phi + rowoff;
    thetap = theta;
    for (ilat = 0; ilat < mlat; ilat++) {
d316 5
a320 4
  latp = lat;
  phip   = phi;
  thetap = theta;
  for (ilat = 0; ilat < nlat; ilat++, latp += sll) {
a321 4
    coslat3 = coslat*eul[3];
    coslat4 = coslat*eul[4];
    sinlat3 = sinlat*eul[3];
    sinlat4 = sinlat*eul[4];
d323 8
a330 2
    for (ilng = 0; ilng < mlng; ilng++, phip += spt, thetap += spt) {
      dlng = *phip;
d334 1
a334 1
      x = sinlat4 - coslat3*coslng;
d340 2
a341 1
      y = -coslat*sinlng;
d367 1
a367 1
        z = sinlat3 + coslat4*coslng;
d393 1
a393 1
  int i;
a394 2

  // Set the Euler angles for the coordinate transformation.
d404 1
a404 1
  for (i = 0; i < nfield; i++) {
d428 1
a428 1
  int i;
a429 2

  // Set the Euler angles for the coordinate transformation.
d436 1
a436 1
  for (i = 0; i < nfield; i++) {
@


8.2.1.1
log
@WCSLIB 8.2 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 8.2 2023/11/16 10:00:29 mcalabre Exp $
@


8.2.1.2
log
@Updated date in copyright notice.
@
text
@d3 1
a3 1
  Copyright (C) 1995-2024, Mark Calabretta
d22 1
a22 1
  $Id: sph.c,v 8.2.1.1 2023/11/16 10:05:57 mcalabre Exp mcalabre $
@


8.2.1.3
log
@Converted to C99-style intermingled variable declarations.
@
text
@d22 1
a22 1
  $Id: sph.c,v 8.2.1.2 2024/04/02 14:01:58 mcalabre Exp mcalabre $
d47 7
a53 1
  int mphi, mtheta;
d68 1
a68 1
      double dlng = fmod(eul[0] + 180.0 - eul[2], 360.0);
d70 7
a76 7
      int jphi = 0;
      const double *thetap = theta;
      double *lngp   = lng;
      double *latp   = lat;
      for (int itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
        const double *phip = phi + (jphi%nphi)*spt;
        for (int iphi = 0; iphi < mphi; iphi++, phip += spt, jphi++) {
d100 1
a100 1
      double dlng = fmod(eul[0] + eul[2], 360.0);
d102 7
a108 7
      int jphi = 0;
      const double *thetap = theta;
      double *lngp   = lng;
      double *latp   = lat;
      for (int itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
        const double *phip = phi + (jphi%nphi)*spt;
        for (int iphi = 0; iphi < mphi; iphi++, phip += spt, jphi++) {
d136 5
a140 5
  const double *phip = phi;
  int rowoff = 0;
  int rowlen = nphi*sll;
  for (int iphi = 0; iphi < nphi; iphi++, rowoff += sll, phip += spt) {
    double dphi = *phip - eul[2];
d142 2
a143 2
    double *lngp = lng + rowoff;
    for (int itheta = 0; itheta < mtheta; itheta++) {
d151 4
a154 5
  const double *thetap = theta;
  double *lngp = lng;
  double *latp = lat;
  for (int itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
    double sinthe, costhe;
d156 4
d161 2
a162 8
    double costhe3 = costhe*eul[3];
    double costhe4 = costhe*eul[4];
    double sinthe3 = sinthe*eul[3];
    double sinthe4 = sinthe*eul[4];

    for (int iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
      double dphi = *lngp;
      double sinphi, cosphi;
d166 1
a166 1
      double x = sinthe4 - costhe3*cosphi;
d172 1
a172 2
      double dlng;
      double y = -costhe*sinphi;
d204 1
a204 1
        double z = sinthe3 + costhe4*cosphi;
d232 7
a238 1
  int mlng, mlat;
d253 1
a253 1
      double dphi = fmod(eul[2] - 180.0 - eul[0], 360.0);
d255 7
a261 7
      int jlng = 0;
      const double *latp   = lat;
      double *phip   = phi;
      double *thetap = theta;
      for (int ilat = 0; ilat < nlat; ilat++, latp += sll) {
        const double *lngp = lng + (jlng%nlng)*sll;
        for (int ilng = 0; ilng < mlng; ilng++, lngp += sll, jlng++) {
d279 1
a279 1
      double dphi = fmod(eul[2] + eul[0], 360.0);
d281 7
a287 7
      int jlng   = 0;
      const double *latp   = lat;
      double *phip   = phi;
      double *thetap = theta;
      for (int ilat = 0; ilat < nlat; ilat++, latp += sll) {
        const double *lngp = lng + (jlng%nlng)*sll;
        for (int ilng = 0; ilng < mlng; ilng++, lngp += sll, jlng++) {
d309 9
a317 9
  const double *lngp = lng;
  int rowoff = 0;
  int rowlen = nlng*spt;
  for (int ilng = 0; ilng < nlng; ilng++, rowoff += spt, lngp += sll) {
    double dlng = *lngp - eul[0];

    double *phip = phi + rowoff;
    double *thetap = theta;
    for (int ilat = 0; ilat < mlat; ilat++) {
d325 4
a328 5
  const double *latp = lat;
  double *phip   = phi;
  double *thetap = theta;
  for (int ilat = 0; ilat < nlat; ilat++, latp += sll) {
    double sinlat, coslat;
d330 4
d335 2
a336 8
    double coslat3 = coslat*eul[3];
    double coslat4 = coslat*eul[4];
    double sinlat3 = sinlat*eul[3];
    double sinlat4 = sinlat*eul[4];

    for (int ilng = 0; ilng < mlng; ilng++, phip += spt, thetap += spt) {
      double dlng = *phip;
      double sinlng, coslng;
d340 1
a340 1
      double x = sinlat4 - coslat3*coslng;
d346 1
a346 2
      double dphi;
      double y = -coslat*sinlng;
d372 1
a372 1
        double z = sinlat3 + coslat4*coslng;
d398 3
a401 1
  double eul[5];
d411 1
a411 1
  for (int i = 0; i < nfield; i++) {
d435 3
a438 1
  double eul[5];
d445 1
a445 1
  for (int i = 0; i < nfield; i++) {
@


8.2.1.4
log
@Attended to compiler warnings about unused variables.
@
text
@d22 1
a22 1
  $Id: sph.c,v 8.2.1.3 2024/05/08 09:22:53 mcalabre Exp mcalabre $
d308 1
@


8.1
log
@WCSLIB 8.1
@
text
@d2 1
a2 1
  WCSLIB 8.1 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 8.0.1.1 2023/07/01 06:22:44 mcalabre Exp mcalabre $
@


8.1.1.1
log
@WCSLIB 8.1 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 8.1 2023/07/05 17:12:07 mcalabre Exp $
@


8.0
log
@WCSLIB 8.0
@
text
@d2 1
a2 1
  WCSLIB 8.0 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 7.13.1.2 2023/06/15 04:17:19 mcalabre Exp mcalabre $
@


8.0.1.1
log
@WCSLIB 8.0 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 8.0 2023/07/01 06:15:04 mcalabre Exp $
@


7.13
log
@WCSLIB 7.13
@
text
@d2 2
a3 2
  WCSLIB 7.13 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2022, Mark Calabretta
d22 1
a22 1
  $Id: sph.c,v 7.12.1.1 2022/09/09 05:00:36 mcalabre Exp mcalabre $
@


7.13.1.1
log
@WCSLIB 7.13 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 7.13 2022/10/07 03:43:35 mcalabre Exp $
@


7.13.1.2
log
@Updated date in copyright notice.
@
text
@d3 1
a3 1
  Copyright (C) 1995-2023, Mark Calabretta
d22 1
a22 1
  $Id: sph.c,v 7.13.1.1 2022/10/07 03:45:47 mcalabre Exp mcalabre $
@


7.12
log
@WCSLIB 7.12
@
text
@d2 1
a2 1
  WCSLIB 7.12 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 7.11.1.1 2022/04/26 06:15:32 mcalabre Exp mcalabre $
@


7.12.1.1
log
@WCSLIB 7.12 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 7.12 2022/09/09 04:57:58 mcalabre Exp $
@


7.11
log
@WCSLIB 7.11
@
text
@d2 1
a2 1
  WCSLIB 7.11 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 7.10.1.1 2022/04/23 14:26:54 mcalabre Exp mcalabre $
@


7.11.1.1
log
@WCSLIB 7.11 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 7.11 2022/04/26 06:13:52 mcalabre Exp $
@


7.10
log
@WCSLIB 7.10
@
text
@d2 1
a2 1
  WCSLIB 7.10 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 7.9.1.1 2022/03/25 15:16:40 mcalabre Exp mcalabre $
@


7.10.1.1
log
@WCSLIB 7.10 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 7.10 2022/04/23 14:25:15 mcalabre Exp $
@


7.9
log
@WCSLIB 7.9
@
text
@d2 1
a2 1
  WCSLIB 7.9 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 7.8.1.1 2022/03/25 06:14:14 mcalabre Exp mcalabre $
@


7.9.1.1
log
@WCSLIB 7.9 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 7.9 2022/03/25 15:14:48 mcalabre Exp $
@


7.8
log
@WCSLIB 7.8
@
text
@d2 1
a2 1
  WCSLIB 7.8 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 7.7.1.2 2022/03/25 06:05:59 mcalabre Exp mcalabre $
@


7.8.1.1
log
@WCSLIB 7.8 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 7.8 2022/03/25 06:11:49 mcalabre Exp $
@


7.7
log
@WCSLIB 7.7
@
text
@d2 2
a3 2
  WCSLIB 7.7 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2021, Mark Calabretta
d22 1
a22 1
  $Id: sph.c,v 7.6.1.1 2021/04/13 13:00:35 mcalabre Exp mcalabre $
@


7.7.1.1
log
@WCSLIB 7.7 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 7.7 2021/07/12 06:36:49 mcalabre Exp $
@


7.7.1.2
log
@Updated date in copyright notice.
@
text
@d3 1
a3 1
  Copyright (C) 1995-2022, Mark Calabretta
d22 1
a22 1
  $Id: sph.c,v 7.7.1.1 2021/07/12 06:38:27 mcalabre Exp mcalabre $
@


7.6
log
@WCSLIB 7.6
@
text
@d2 1
a2 1
  WCSLIB 7.6 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 7.5.1.1 2021/03/20 05:56:42 mcalabre Exp mcalabre $
@


7.6.1.1
log
@WCSLIB 7.6 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 7.6 2021/04/13 12:57:01 mcalabre Exp $
@


7.5
log
@WCSLIB 7.5
@
text
@d2 1
a2 1
  WCSLIB 7.5 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 7.4.1.1 2021/01/31 02:26:24 mcalabre Exp mcalabre $
@


7.5.1.1
log
@WCSLIB 7.5 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 7.5 2021/03/20 05:54:58 mcalabre Exp $
@


7.4
log
@WCSLIB 7.4
@
text
@d2 1
a2 1
  WCSLIB 7.4 - an implementation of the FITS WCS standard.
d22 1
a22 1
  $Id: sph.c,v 7.3.1.4 2021/01/28 12:29:30 mcalabre Exp mcalabre $
@


7.4.1.1
log
@WCSLIB 7.4 development branch.
@
text
@d22 1
a22 1
  $Id: sph.c,v 7.4 2021/01/31 02:24:51 mcalabre Exp $
@


7.3
log
@WCSLIB 7.3
@
text
@d2 2
a3 3

  WCSLIB 7.3 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2020, Mark Calabretta
a19 2
  Direct correspondence concerning WCSLIB to mark@@calabretta.id.au

d22 1
a22 1
  $Id: sph.c,v 7.2.1.1 2020/03/09 07:34:50 mcalabre Exp mcalabre $
d33 1
a33 1
/*--------------------------------------------------------------------------*/
d64 1
a64 1
  /* Check for special-case rotations. */
d67 1
a67 1
      /* Simple change in origin of longitude. */
d80 1
a80 1
          /* Normalize the celestial longitude. */
d99 1
a99 1
      /* Pole-flip with change in origin of longitude. */
d112 1
a112 1
          /* Normalize the celestial longitude. */
d135 1
a135 1
  /* Do phi dependency. */
d150 1
a150 1
  /* Do theta dependency. */
d165 1
a165 1
      /* Compute the celestial longitude. */
d168 1
a168 1
        /* Rearrange formula to reduce roundoff errors. */
d176 1
a176 1
        /* Change of origin of longitude. */
d185 1
a185 1
      /* Normalize the celestial longitude. */
d198 1
a198 1
      /* Compute the celestial latitude. */
d206 1
a206 1
          /* Use an alternative formula for greater accuracy. */
d218 1
a218 1
/*--------------------------------------------------------------------------*/
d249 1
a249 1
  /* Check for special-case rotations. */
d252 1
a252 1
      /* Simple change in origin of longitude. */
d265 1
a265 1
          /* Normalize the native longitude. */
d278 1
a278 1
      /* Pole-flip with change in origin of longitude. */
d291 1
a291 1
          /* Normalize the native longitude. */
d308 1
a308 1
  /* Do lng dependency. */
d324 1
a324 1
  /* Do lat dependency. */
d339 1
a339 1
      /* Compute the native longitude. */
d342 1
a342 1
        /* Rearrange formula to reduce roundoff errors. */
d350 1
a350 1
        /* Change of origin of longitude. */
d359 1
a359 1
      /* Normalize the native longitude. */
d366 1
a366 1
      /* Compute the native latitude. */
d374 1
a374 1
          /* Use an alternative formula for greater accuracy. */
d386 1
a386 1
/*--------------------------------------------------------------------------*/
d401 1
a401 1
  /* Set the Euler angles for the coordinate transformation. */
d408 1
a408 1
  /* Transform field points to the new system. */
d412 1
a412 1
    /* Angular distance is obtained from latitude in the new frame. */
d415 1
a415 1
    /* Position angle is obtained from longitude in the new frame. */
d423 1
a423 1
/*--------------------------------------------------------------------------*/
d438 1
a438 1
  /* Set the Euler angles for the coordinate transformation. */
d446 1
a446 1
    /* Latitude in the new frame is obtained from angular distance. */
d449 1
a449 1
    /* Longitude in the new frame is obtained from position angle. */
d453 1
a453 1
  /* Transform field points to the old system. */
@


7.3.1.1
log
@WCSLIB 7.3 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 7.3 2020/06/03 03:37:02 mcalabre Exp $
@


7.3.1.2
log
@Switched to C99 style commenting (i.e. using //) within the code.
@
text
@d2 1
d25 1
a25 1
  $Id: sph.c,v 7.3.1.1 2020/06/03 03:38:10 mcalabre Exp mcalabre $
d36 1
a36 1
//----------------------------------------------------------------------------
d67 1
a67 1
  // Check for special-case rotations.
d70 1
a70 1
      // Simple change in origin of longitude.
d83 1
a83 1
          // Normalize the celestial longitude.
d102 1
a102 1
      // Pole-flip with change in origin of longitude.
d115 1
a115 1
          // Normalize the celestial longitude.
d138 1
a138 1
  // Do phi dependency.
d153 1
a153 1
  // Do theta dependency.
d168 1
a168 1
      // Compute the celestial longitude.
d171 1
a171 1
        // Rearrange formula to reduce roundoff errors.
d179 1
a179 1
        // Change of origin of longitude.
d188 1
a188 1
      // Normalize the celestial longitude.
d201 1
a201 1
      // Compute the celestial latitude.
d209 1
a209 1
          // Use an alternative formula for greater accuracy.
d221 1
a221 1
//----------------------------------------------------------------------------
d252 1
a252 1
  // Check for special-case rotations.
d255 1
a255 1
      // Simple change in origin of longitude.
d268 1
a268 1
          // Normalize the native longitude.
d281 1
a281 1
      // Pole-flip with change in origin of longitude.
d294 1
a294 1
          // Normalize the native longitude.
d311 1
a311 1
  // Do lng dependency.
d327 1
a327 1
  // Do lat dependency.
d342 1
a342 1
      // Compute the native longitude.
d345 1
a345 1
        // Rearrange formula to reduce roundoff errors.
d353 1
a353 1
        // Change of origin of longitude.
d362 1
a362 1
      // Normalize the native longitude.
d369 1
a369 1
      // Compute the native latitude.
d377 1
a377 1
          // Use an alternative formula for greater accuracy.
d389 1
a389 1
//----------------------------------------------------------------------------
d404 1
a404 1
  // Set the Euler angles for the coordinate transformation.
d411 1
a411 1
  // Transform field points to the new system.
d415 1
a415 1
    // Angular distance is obtained from latitude in the new frame.
d418 1
a418 1
    // Position angle is obtained from longitude in the new frame.
d426 1
a426 1
//----------------------------------------------------------------------------
d441 1
a441 1
  // Set the Euler angles for the coordinate transformation.
d449 1
a449 1
    // Latitude in the new frame is obtained from angular distance.
d452 1
a452 1
    // Longitude in the new frame is obtained from position angle.
d456 1
a456 1
  // Transform field points to the old system.
@


7.3.1.3
log
@Updated date in copyright notice.
@
text
@d3 1
a3 1
  Copyright (C) 1995-2021, Mark Calabretta
d24 1
a24 1
  $Id: sph.c,v 7.3.1.2 2020/08/17 11:19:09 mcalabre Exp mcalabre $
@


7.3.1.4
log
@Removed my email address from the copyright notice.
@
text
@d20 2
d24 1
a24 1
  $Id: sph.c,v 7.3.1.3 2021/01/19 14:09:10 mcalabre Exp mcalabre $
@


7.2
log
@WCSLIB 7.2
@
text
@d3 1
a3 1
  WCSLIB 7.2 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 7.1.1.1 2019/12/31 13:28:19 mcalabre Exp mcalabre $
@


7.2.1.1
log
@WCSLIB 7.2 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 7.2 2020/03/09 07:31:23 mcalabre Exp $
@


7.1
log
@WCSLIB 7.1
@
text
@d3 1
a3 1
  WCSLIB 7.1 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 6.4.1.2 2019/12/31 03:28:03 mcalabre Exp mcalabre $
@


7.1.1.1
log
@WCSLIB 7.1 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 7.1 2019/12/31 13:25:19 mcalabre Exp $
@


6.4
log
@WCSLIB 6.4
@
text
@d3 2
a4 2
  WCSLIB 6.4 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2019, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 6.3.1.1 2019/07/12 07:34:37 mcalabre Exp mcalabre $
@


6.4.1.1
log
@WCSLIB 6.4 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 6.4 2019/08/15 09:30:18 mcalabre Exp $
@


6.4.1.2
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
  Copyright (C) 1995-2020, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 6.4.1.1 2019/08/15 09:31:29 mcalabre Exp mcalabre $
@


6.3
log
@WCSLIB 6.3
@
text
@d3 1
a3 1
  WCSLIB 6.3 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 6.2.1.2 2019/05/10 01:56:50 mcalabre Exp mcalabre $
@


6.3.1.1
log
@WCSLIB 6.3 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 6.3 2019/07/12 07:33:39 mcalabre Exp $
@


6.2
log
@WCSLIB 6.2
@
text
@d3 2
a4 2
  WCSLIB 6.2 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2018, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 6.1.1.1 2018/10/19 08:36:15 mcalabre Exp mcalabre $
@


6.2.1.1
log
@WCSLIB 6.2 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 6.2 2018/10/20 10:03:13 mcalabre Exp $
@


6.2.1.2
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
  Copyright (C) 1995-2019, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 6.2.1.1 2018/10/20 10:04:15 mcalabre Exp mcalabre $
@


6.1
log
@WCSLIB 6.1
@
text
@d3 1
a3 1
  WCSLIB 6.1 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.20.1.1 2018/10/05 05:33:33 mcalabre Exp mcalabre $
@


6.1.1.1
log
@WCSLIB 6.1 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 6.1 2018/10/19 08:35:17 mcalabre Exp $
@


5.20
log
@WCSLIB 5.20
@
text
@d3 1
a3 1
  WCSLIB 5.20 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.19.1.1 2018/07/26 15:41:40 mcalabre Exp mcalabre $
@


5.20.1.1
log
@WCSLIB 5.20 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.20 2018/10/05 05:32:41 mcalabre Exp $
@


5.19
log
@WCSLIB 5.19
@
text
@d3 1
a3 1
  WCSLIB 5.19 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.18.1.1 2018/01/10 08:33:04 mcalabre Exp mcalabre $
@


5.19.1.1
log
@WCSLIB 5.19 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.19 2018/07/26 15:37:04 mcalabre Exp $
@


5.18
log
@WCSLIB 5.18
@
text
@d3 1
a3 1
  WCSLIB 5.18 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.17.1.2 2018/01/10 08:25:34 mcalabre Exp mcalabre $
@


5.18.1.1
log
@WCSLIB 5.18 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.18 2018/01/10 08:32:14 mcalabre Exp $
@


5.17
log
@WCSLIB 5.17
@
text
@d3 2
a4 2
  WCSLIB 5.17 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2017, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 5.16.1.1 2017/01/15 04:28:59 mcalabre Exp mcalabre $
@


5.17.1.1
log
@WCSLIB 5.17 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.17 2017/09/18 08:44:23 mcalabre Exp $
@


5.17.1.2
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
  Copyright (C) 1995-2018, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 5.17.1.1 2017/09/18 08:45:59 mcalabre Exp mcalabre $
@


5.16
log
@WCSLIB 5.16
@
text
@d3 1
a3 1
  WCSLIB 5.16 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.15.1.2 2017/01/15 04:13:33 mcalabre Exp mcalabre $
@


5.16.1.1
log
@WCSLIB 5.16 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.16 2017/01/15 04:25:01 mcalabre Exp $
@


5.15
log
@WCSLIB 5.15
@
text
@d3 2
a4 2
  WCSLIB 5.15 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2016, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 5.14.1.1 2016/02/07 10:52:44 mcalabre Exp mcalabre $
@


5.15.1.1
log
@WCSLIB 5.15 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.15 2016/04/05 12:55:10 mcalabre Exp $
@


5.15.1.2
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
  Copyright (C) 1995-2017, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 5.15.1.1 2016/04/05 12:58:35 mcalabre Exp mcalabre $
@


5.14
log
@WCSLIB 5.14
@
text
@d3 1
a3 1
  WCSLIB 5.14 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.13.1.1 2016/01/26 08:54:32 mcalabre Exp mcalabre $
@


5.14.1.1
log
@WCSLIB 5.14 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.14 2016/02/07 10:49:31 mcalabre Exp $
@


5.13
log
@WCSLIB 5.13
@
text
@d3 1
a3 1
  WCSLIB 5.13 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.12.1.2 2016/01/25 05:17:04 mcalabre Exp mcalabre $
@


5.13.1.1
log
@WCSLIB 5.13 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.13 2016/01/26 08:51:13 mcalabre Exp $
@


5.12
log
@WCSLIB 5.12
@
text
@d3 2
a4 2
  WCSLIB 5.12 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2015, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 5.11.1.1 2015/10/18 09:16:27 mcalabre Exp mcalabre $
@


5.12.1.1
log
@WCSLIB 5.12 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.12 2015/11/15 02:13:00 mcalabre Exp $
@


5.12.1.2
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
  Copyright (C) 1995-2016, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 5.12.1.1 2015/11/15 02:16:14 mcalabre Exp mcalabre $
@


5.11
log
@WCSLIB 5.11
@
text
@d3 1
a3 1
  WCSLIB 5.11 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.10.1.1 2015/10/09 08:22:35 mcalabre Exp mcalabre $
@


5.11.1.1
log
@WCSLIB 5.11 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.11 2015/10/18 09:13:05 mcalabre Exp $
@


5.10
log
@WCSLIB 5.10
@
text
@d3 1
a3 1
  WCSLIB 5.10 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.9.1.1 2015/07/21 09:28:07 mcalabre Exp mcalabre $
@


5.10.1.1
log
@WCSLIB 5.10 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.10 2015/10/09 08:19:15 mcalabre Exp $
@


5.9
log
@WCSLIB 5.9
@
text
@d3 1
a3 1
  WCSLIB 5.9 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.8.1.1 2015/07/08 11:07:18 mcalabre Exp mcalabre $
@


5.9.1.1
log
@WCSLIB 5.9 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.9 2015/07/21 09:20:01 mcalabre Exp $
@


5.8
log
@WCSLIB 5.8
@
text
@d3 1
a3 1
  WCSLIB 5.8 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.7.1.1 2015/06/29 02:47:24 mcalabre Exp mcalabre $
@


5.8.1.1
log
@WCSLIB 5.8 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.8 2015/07/08 11:03:59 mcalabre Exp $
@


5.7
log
@WCSLIB 5.7
@
text
@d3 1
a3 1
  WCSLIB 5.7 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.6.1.3 2015/06/28 07:40:35 mcalabre Exp mcalabre $
@


5.7.1.1
log
@WCSLIB 5.7 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.7 2015/06/29 02:44:16 mcalabre Exp $
@


5.6
log
@WCSLIB 5.6
@
text
@d3 1
a3 1
  WCSLIB 5.6 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.5.1.1 2015/05/05 13:21:00 mcalabre Exp mcalabre $
d67 1
a67 1
  /* Check for a simple change in origin of longitude. */
d70 1
d78 1
a78 1
        phip = phi + jphi%nphi;
d96 2
a97 2
          lngp   += sll;
          latp   += sll;
d102 1
d110 1
a110 1
        phip = phi + jphi%nphi;
d128 2
a129 2
          lngp   += sll;
          latp   += sll;
d252 1
a252 1
  /* Check for a simple change in origin of longitude. */
d255 1
d263 1
a263 1
        lngp = lng + jlng%nlng;
d281 1
d289 1
a289 1
        lngp = lng + jlng%nlng;
@


5.6.1.1
log
@WCSLIB 5.6 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.6 2015/06/14 07:11:24 mcalabre Exp $
@


5.6.1.2
log
@Fixed a few comments in sphx2s() and sphs2x().
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.6.1.1 2015/06/14 07:14:44 mcalabre Exp mcalabre $
d67 1
a67 1
  /* Check for special-case rotations. */
a69 1
      /* Simple change in origin of longitude. */
a100 1
      /* Pole-flip with change in origin of longitude. */
d250 1
a250 1
  /* Check for special-case rotations. */
a252 1
      /* Simple change in origin of longitude. */
a277 1
      /* Pole-flip with change in origin of longitude. */
@


5.6.1.3
log
@Bug fixes for handling vector strides in the special-case branches in
sphx2s() and sphx2s().
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.6.1.2 2015/06/27 06:21:47 mcalabre Exp mcalabre $
d78 1
a78 1
        phip = phi + (jphi%nphi)*spt;
d96 2
a97 2
          lngp += sll;
          latp += sll;
d110 1
a110 1
        phip = phi + (jphi%nphi)*spt;
d128 2
a129 2
          lngp += sll;
          latp += sll;
d263 1
a263 1
        lngp = lng + (jlng%nlng)*sll;
d289 1
a289 1
        lngp = lng + (jlng%nlng)*sll;
@


5.5
log
@WCSLIB 5.5
@
text
@d3 1
a3 1
  WCSLIB 5.5 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.4.1.1 2015/04/21 14:44:28 mcalabre Exp mcalabre $
@


5.5.1.1
log
@WCSLIB 5.5 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.5 2015/05/05 13:16:31 mcalabre Exp $
@


5.4
log
@WCSLIB 5.4
@
text
@d3 1
a3 1
  WCSLIB 5.4 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.3.1.1 2015/04/21 02:54:02 mcalabre Exp mcalabre $
@


5.4.1.1
log
@WCSLIB 5.4 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.4 2015/04/21 14:41:05 mcalabre Exp $
@


5.3
log
@WCSLIB 5.3
@
text
@d3 1
a3 1
  WCSLIB 5.3 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.2.1.1 2015/04/15 12:39:14 mcalabre Exp mcalabre $
@


5.3.1.1
log
@WCSLIB 5.3 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.3 2015/04/21 02:50:51 mcalabre Exp $
@


5.2
log
@WCSLIB 5.2
@
text
@d3 1
a3 1
  WCSLIB 5.2 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.1.1.1 2015/04/07 11:01:10 mcalabre Exp mcalabre $
@


5.2.1.1
log
@WCSLIB 5.2 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.2 2015/04/15 12:35:07 mcalabre Exp $
@


5.1
log
@WCSLIB 5.1
@
text
@d3 1
a3 1
  WCSLIB 5.1 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 5.0.1.1 2015/04/05 12:28:00 mcalabre Exp mcalabre $
@


5.1.1.1
log
@WCSLIB 5.1 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.1 2015/04/07 10:56:36 mcalabre Exp $
@


5.0
log
@WCSLIB 5.0
@
text
@d3 1
a3 1
  WCSLIB 5.0 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 4.25.1.3 2015/03/06 07:15:01 mcalabre Exp mcalabre $
@


5.0.1.1
log
@WCSLIB 5.0 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 5.0 2015/04/05 12:24:59 mcalabre Exp $
@


4.25
log
@WCSLIB 4.25
@
text
@d3 2
a4 2
  WCSLIB 4.25 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2014, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 4.24.1.1 2014/09/18 15:28:09 mcalabre Exp mcalabre $
d50 1
a50 1
  int mphi, mtheta, rowlen, rowoff;
d72 1
a72 3
      lngp = lng;
      latp = lat;
      phip   = phi;
d74 5
a78 2
      for (itheta = 0; itheta < ntheta; itheta++) {
        for (iphi = 0; iphi < mphi; iphi++) {
a96 2
          phip   += spt;
          thetap += spt;
d103 1
a103 3
      lngp = lng;
      latp = lat;
      phip   = phi;
d105 5
a109 2
      for (itheta = 0; itheta < ntheta; itheta++) {
        for (iphi = 0; iphi < mphi; iphi++) {
a127 2
          phip   += spt;
          thetap += spt;
d233 1
a233 1
  int mlat, mlng, rowlen, rowoff;
d255 2
a256 2
      lngp = lng;
      latp = lat;
d259 3
a261 2
      for (ilat = 0; ilat < nlat; ilat++) {
        for (ilng = 0; ilng < mlng; ilng++) {
a273 2
          lngp   += sll;
          latp   += sll;
d280 2
a281 2
      lngp = lng;
      latp = lat;
d284 3
a286 2
      for (ilat = 0; ilat < nlat; ilat++) {
        for (ilng = 0; ilng < mlng; ilng++) {
a298 2
          lngp   += sll;
          latp   += sll;
@


4.25.1.1
log
@WCSLIB 4.25 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.25 2014/12/14 14:29:36 mcalabre Exp $
@


4.25.1.2
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
  Copyright (C) 1995-2015, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 4.25.1.1 2014/12/14 14:32:45 mcalabre Exp mcalabre $
@


4.25.1.3
log
@In sphx2s() and sphx2s(), fixed a bug in the vector indexing for the simple
change in origin of longitude.  This bug, uncovered by valgrind, was
supposedly fixed at 4.7.1.2.  It actually dates back to the introduction
of this code at 4.3.1.4.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.25.1.2 2015/01/06 01:01:06 mcalabre Exp mcalabre $
d50 1
a50 1
  int jphi, mphi, mtheta, rowlen, rowoff;
d72 3
a74 1
      jphi   = 0;
d76 2
a77 5
      lngp   = lng;
      latp   = lat;
      for (itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
        phip = phi + jphi%nphi;
        for (iphi = 0; iphi < mphi; iphi++, phip += spt, jphi++) {
d96 2
d104 3
a106 1
      jphi   = 0;
d108 2
a109 5
      lngp   = lng;
      latp   = lat;
      for (itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
        phip = phi + jphi%nphi;
        for (iphi = 0; iphi < mphi; iphi++, phip += spt, jphi++) {
d128 2
d235 1
a235 1
  int jlng, mlat, mlng, rowlen, rowoff;
d257 2
a258 2
      jlng   = 0;
      latp   = lat;
d261 2
a262 3
      for (ilat = 0; ilat < nlat; ilat++, latp += sll) {
        lngp = lng + jlng%nlng;
        for (ilng = 0; ilng < mlng; ilng++, lngp += sll, jlng++) {
d275 2
d283 2
a284 2
      jlng   = 0;
      latp   = lat;
d287 2
a288 3
      for (ilat = 0; ilat < nlat; ilat++, latp += sll) {
        lngp = lng + jlng%nlng;
        for (ilng = 0; ilng < mlng; ilng++, lngp += sll, jlng++) {
d301 2
@


4.24
log
@WCSLIB 4.24
@
text
@d3 1
a3 1
  WCSLIB 4.24 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 4.23.1.1 2014/05/13 05:53:49 mcalabre Exp mcalabre $
@


4.24.1.1
log
@WCSLIB 4.24 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.24 2014/09/18 15:25:00 mcalabre Exp $
@


4.23
log
@WCSLIB 4.23
@
text
@d3 1
a3 1
  WCSLIB 4.23 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 4.22.1.1 2014/04/12 15:06:32 mcalabre Exp mcalabre $
@


4.23.1.1
log
@WCSLIB 4.23 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.23 2014/05/13 05:50:51 mcalabre Exp $
@


4.22
log
@WCSLIB 4.22
@
text
@d3 1
a3 1
  WCSLIB 4.22 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 4.21.1.1 2014/03/24 05:15:28 mcalabre Exp mcalabre $
@


4.22.1.1
log
@WCSLIB 4.22 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.22 2014/04/12 15:03:52 mcalabre Exp $
@


4.21
log
@WCSLIB 4.21
@
text
@d3 1
a3 1
  WCSLIB 4.21 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 4.20.1.2 2014/03/21 06:32:19 mcalabre Exp mcalabre $
@


4.21.1.1
log
@WCSLIB 4.21 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.21 2014/03/24 05:12:27 mcalabre Exp $
@


4.20
log
@WCSLIB 4.20
@
text
@d3 2
a4 2
  WCSLIB 4.20 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2013, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 4.19.1.1 2013/09/29 14:20:38 mcalabre Exp mcalabre $
@


4.20.1.1
log
@WCSLIB 4.20 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.20 2013/12/18 05:42:49 mcalabre Exp $
@


4.20.1.2
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
  Copyright (C) 1995-2014, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 4.20.1.1 2013/12/18 05:46:55 mcalabre Exp mcalabre $
@


4.19
log
@WCSLIB 4.19
@
text
@d3 1
a3 1
  WCSLIB 4.19 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 4.18.1.1 2013/07/13 10:02:37 mcalabre Exp mcalabre $
@


4.19.1.1
log
@WCSLIB 4.19 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.19 2013/09/29 14:17:51 mcalabre Exp $
@


4.18
log
@WCSLIB 4.18
@
text
@d3 1
a3 1
  WCSLIB 4.18 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 4.17.1.1 2013/01/29 05:32:32 cal103 Exp cal103 $
@


4.18.1.1
log
@WCSLIB 4.18 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.18 2013/07/13 10:00:04 mcalabre Exp $
@


4.17
log
@WCSLIB 4.17
@
text
@d3 1
a3 1
  WCSLIB 4.17 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 4.16.1.2 2013/01/29 05:09:44 cal103 Exp cal103 $
@


4.17.1.1
log
@WCSLIB 4.17 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.17 2013/01/29 05:29:20 cal103 Exp $
@


4.16
log
@WCSLIB 4.16
@
text
@d3 2
a4 2
  WCSLIB 4.16 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2012, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 4.15.1.1 2012/09/26 14:27:51 cal103 Exp cal103 $
@


4.16.1.1
log
@WCSLIB 4.16 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.16 2012/11/07 04:42:44 cal103 Exp $
@


4.16.1.2
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
  Copyright (C) 1995-2013, Mark Calabretta
d25 1
a25 1
  $Id: sph.c,v 4.16.1.1 2012/11/07 04:45:56 cal103 Exp cal103 $
@


4.15
log
@WCSLIB 4.15
@
text
@d3 1
a3 1
  WCSLIB 4.15 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 4.14.1.1 2012/07/13 10:04:44 cal103 Exp cal103 $
@


4.15.1.1
log
@WCSLIB 4.15 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.15 2012/09/26 14:26:05 cal103 Exp $
@


4.14
log
@WCSLIB 4.14
@
text
@d3 1
a3 1
  WCSLIB 4.14 - an implementation of the FITS WCS standard.
d25 1
a25 1
  $Id: sph.c,v 4.13.1.2 2012/07/13 03:34:20 cal103 Exp cal103 $
@


4.14.1.1
log
@WCSLIB 4.14 development branch.
@
text
@d25 1
a25 1
  $Id: sph.c,v 4.14 2012/07/13 10:02:27 cal103 Exp $
@


4.13
log
@WCSLIB 4.13
@
text
@d3 1
a3 1
  WCSLIB 4.13 - an implementation of the FITS WCS standard.
d19 1
a19 1
  along with WCSLIB.  If not, see <http://www.gnu.org/licenses/>.
d21 5
a25 11
  Correspondence concerning WCSLIB may be directed to:
    Internet email: mcalabre@@atnf.csiro.au
    Postal address: Dr. Mark Calabretta
                    Australia Telescope National Facility, CSIRO
                    PO Box 76
                    Epping NSW 1710
                    AUSTRALIA

  Author: Mark Calabretta, Australia Telescope National Facility
  http://www.atnf.csiro.au/~mcalabre/index.html
  $Id: sph.c,v 4.12.1.1 2012/02/29 07:59:10 cal103 Exp cal103 $
@


4.13.1.1
log
@WCSLIB 4.13 development branch.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.13 2012/03/14 07:39:30 cal103 Exp $
@


4.13.1.2
log
@Changed contact details.
@
text
@d19 1
a19 1
  along with WCSLIB.  If not, see http://www.gnu.org/licenses.
d21 11
a31 5
  Direct correspondence concerning WCSLIB to mark@@calabretta.id.au

  Author: Mark Calabretta, Australia Telescope National Facility, CSIRO.
  http://www.atnf.csiro.au/people/Mark.Calabretta
  $Id: sph.c,v 4.13.1.1 2012/03/14 07:40:37 cal103 Exp cal103 $
@


4.12
log
@WCSLIB 4.12
@
text
@d3 1
a3 1
  WCSLIB 4.12 - an implementation of the FITS WCS standard.
d31 1
a31 1
  $Id: sph.c,v 4.11.1.1 2012/02/20 23:31:13 cal103 Exp cal103 $
@


4.12.1.1
log
@WCSLIB 4.12 development branch.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.12 2012/02/29 07:57:56 cal103 Exp $
@


4.11
log
@WCSLIB 4.11
@
text
@d3 1
a3 1
  WCSLIB 4.11 - an implementation of the FITS WCS standard.
d31 1
a31 1
  $Id: sph.c,v 4.10.1.1 2012/02/05 23:42:46 cal103 Exp cal103 $
@


4.11.1.1
log
@WCSLIB 4.11 development branch.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.11 2012/02/20 23:30:02 cal103 Exp $
@


4.10
log
@WCSLIB 4.10
@
text
@d3 1
a3 1
  WCSLIB 4.10 - an implementation of the FITS WCS standard.
d31 1
a31 1
  $Id: sph.c,v 4.9.1.1 2012/01/24 05:41:45 cal103 Exp cal103 $
@


4.10.1.1
log
@WCSLIB 4.10 development branch.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.10 2012/02/05 23:41:44 cal103 Exp $
@


4.9
log
@WCSLIB 4.9
@
text
@d3 1
a3 1
  WCSLIB 4.9 - an implementation of the FITS WCS standard.
d31 1
a31 1
  $Id: sph.c,v 4.8.1.2 2012/01/24 05:23:06 cal103 Exp cal103 $
@


4.9.1.1
log
@WCSLIB 4.9 development branch.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.9 2012/01/24 05:40:29 cal103 Exp $
@


4.8
log
@WCSLIB 4.8
@
text
@d3 2
a4 2
  WCSLIB 4.8 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2011, Mark Calabretta
d31 1
a31 1
  $Id: sph.c,v 4.7.1.2 2011/08/10 08:03:20 cal103 Exp cal103 $
@


4.8.1.1
log
@WCSLIB 4.8 development branch.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.8 2011/08/15 08:05:53 cal103 Exp $
@


4.8.1.2
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
  Copyright (C) 1995-2012, Mark Calabretta
d31 1
a31 1
  $Id: sph.c,v 4.8.1.1 2011/08/15 08:07:06 cal103 Exp cal103 $
@


4.7
log
@WCSLIB 4.7
@
text
@d3 1
a3 1
  WCSLIB 4.7 - an implementation of the FITS WCS standard.
d31 1
a31 1
  $Id: sph.c,v 4.6.1.2 2011/01/14 06:33:16 cal103 Exp cal103 $
d82 2
a83 2
      for (itheta = 0; itheta < ntheta; itheta++, phip += spt, thetap += spt) {
        for (iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
d99 5
d114 2
a115 2
      for (itheta = 0; itheta < ntheta; itheta++, phip += spt, thetap += spt) {
        for (iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
d131 5
d267 2
a268 2
      for (ilat = 0; ilat < nlat; ilat++, lngp += sll, latp += sll) {
        for (ilng = 0; ilng < mlng; ilng++, phip += spt, thetap += spt) {
d278 5
d293 2
a294 2
      for (ilat = 0; ilat < nlat; ilat++, lngp += sll, latp += sll) {
        for (ilng = 0; ilng < mlng; ilng++, phip += spt, thetap += spt) {
d304 5
@


4.7.1.1
log
@WCSLIB 4.7 development branch.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.7 2011/02/07 07:03:42 cal103 Exp $
@


4.7.1.2
log
@Fixed an insanely stupid bug for the case where eul[4] == 0.0 introduced
at 4.4.1.2.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.7.1.1 2011/02/07 07:04:22 cal103 Exp $
d82 2
a83 2
      for (itheta = 0; itheta < ntheta; itheta++) {
        for (iphi = 0; iphi < mphi; iphi++) {
a98 5

          lngp   += sll;
          latp   += sll;
          phip   += spt;
          thetap += spt;
d109 2
a110 2
      for (itheta = 0; itheta < ntheta; itheta++) {
        for (iphi = 0; iphi < mphi; iphi++) {
a125 5

          lngp   += sll;
          latp   += sll;
          phip   += spt;
          thetap += spt;
d257 2
a258 2
      for (ilat = 0; ilat < nlat; ilat++) {
        for (ilng = 0; ilng < mlng; ilng++) {
a267 5

          phip   += spt;
          thetap += spt;
          lngp   += sll;
          latp   += sll;
d278 2
a279 2
      for (ilat = 0; ilat < nlat; ilat++) {
        for (ilng = 0; ilng < mlng; ilng++) {
a288 5

          phip   += spt;
          thetap += spt;
          lngp   += sll;
          latp   += sll;
@


4.6
log
@WCSLIB 4.6
@
text
@d3 2
a4 2
  WCSLIB 4.6 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2010, Mark Calabretta
d31 1
a31 1
  $Id: sph.c,v 4.5.1.2 2010/08/12 07:38:46 cal103 Exp cal103 $
@


4.6.1.1
log
@WCSLIB 4.6 development branch.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.6 2010/11/16 06:15:31 cal103 Exp $
@


4.6.1.2
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
  Copyright (C) 1995-2011, Mark Calabretta
d31 1
a31 1
  $Id: sph.c,v 4.6.1.1 2010/11/16 06:16:19 cal103 Exp cal103 $
@


4.5
log
@WCSLIB 4.5
@
text
@d3 1
a3 1
  WCSLIB 4.5 - an implementation of the FITS WCS standard.
d31 1
a31 1
  $Id: sph.c,v 4.4.1.3 2010/01/19 03:42:50 cal103 Exp cal103 $
d411 36
@


4.5.1.1
log
@WCSLIB 4.5 development branch.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.5 2010/07/16 07:01:25 cal103 Exp $
@


4.5.1.2
log
@Added sphpad().
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.5.1.1 2010/07/16 07:05:31 cal103 Exp cal103 $
a410 36

/*--------------------------------------------------------------------------*/

int sphpad(
  int nfield,
  double lng0,
  double lat0,
  const double dist[],
  const double pa[],
  double lng[],
  double lat[])

{
  int i;
  double eul[5];

  /* Set the Euler angles for the coordinate transformation. */
  eul[0] = lng0;
  eul[1] = 90.0 - lat0;
  eul[2] = 0.0;
  eul[3] = cosd(eul[1]);
  eul[4] = sind(eul[1]);

  for (i = 0; i < nfield; i++) {
    /* Latitude in the new frame is obtained from angular distance. */
    lat[i] = 90.0 - dist[i];

    /* Longitude in the new frame is obtained from position angle. */
    lng[i] = -pa[i];
  }

  /* Transform field points to the old system. */
  sphx2s(eul, nfield, 0, 1, 1, lng, lat, lng, lat);

  return 0;
}
@


4.4
log
@WCSLIB 4.4
@
text
@d3 2
a4 2
  WCSLIB 4.4 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2009, Mark Calabretta
d31 1
a31 1
  $Id: sph.c,v 4.3.1.5 2009/07/30 04:20:24 cal103 Exp cal103 $
d74 27
a100 2
  if (eul[1] == 0.0) {
    dlng = fmod(eul[0] + 180.0 - eul[2], 360.0);
d102 2
a103 15
    lngp = lng;
    latp = lat;
    phip   = phi;
    thetap = theta;
    for (itheta = 0; itheta < ntheta; itheta++, phip += spt, thetap += spt) {
      for (iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
        *lngp = *phip + dlng;
        *latp = *thetap;

        /* Normalize the celestial longitude. */
        if (eul[0] >= 0.0) {
          if (*lngp < 0.0) *lngp += 360.0;
        } else {
          if (*lngp > 0.0) *lngp -= 360.0;
        }
d105 21
a125 4
        if (*lngp > 360.0) {
          *lngp -= 360.0;
        } else if (*lngp < -360.0) {
          *lngp += 360.0;
d249 21
a269 2
  if (eul[1] == 0.0) {
    dphi = fmod(eul[2] - 180.0 - eul[0], 360.0);
d271 18
a288 14
    lngp = lng;
    latp = lat;
    phip   = phi;
    thetap = theta;
    for (ilat = 0; ilat < nlat; ilat++, lngp += sll, latp += sll) {
      for (ilng = 0; ilng < mlng; ilng++, phip += spt, thetap += spt) {
        *phip = fmod(*lngp + dphi, 360.0);
        *thetap = *latp;

        /* Normalize the native longitude. */
        if (*phip > 180.0) {
          *phip -= 360.0;
        } else if (*phip < -180.0) {
          *phip += 360.0;
@


4.4.1.1
log
@WCSLIB 4.4 development branch.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.4 2009/08/06 07:41:33 cal103 Exp $
@


4.4.1.2
log
@In sphx2s() and sphx2s(), handle the case where eul[4] = 0.0 separately
for speed and accuracy.  This change also fixes a subtle bug in cels2x()
that occurs when celprm::isolat == 1 and the magnitude of the first
latitude in the lat[] vector exceeds 90 deg (email from Hans Terlouw,
2009/08/11).
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.4.1.1 2009/08/10 08:52:49 cal103 Exp cal103 $
d74 17
a90 25
  if (eul[4] == 0.0) {
    if (eul[1] == 0.0) {
      dlng = fmod(eul[0] + 180.0 - eul[2], 360.0);

      lngp = lng;
      latp = lat;
      phip   = phi;
      thetap = theta;
      for (itheta = 0; itheta < ntheta; itheta++, phip += spt, thetap += spt) {
        for (iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
          *lngp = *phip + dlng;
          *latp = *thetap;

          /* Normalize the celestial longitude. */
          if (eul[0] >= 0.0) {
            if (*lngp < 0.0) *lngp += 360.0;
          } else {
            if (*lngp > 0.0) *lngp -= 360.0;
          }

          if (*lngp > 360.0) {
            *lngp -= 360.0;
          } else if (*lngp < -360.0) {
            *lngp += 360.0;
          }
a91 4
      }

    } else {
      dlng = fmod(eul[0] + eul[2], 360.0);
d93 4
a96 21
      lngp = lng;
      latp = lat;
      phip   = phi;
      thetap = theta;
      for (itheta = 0; itheta < ntheta; itheta++, phip += spt, thetap += spt) {
        for (iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
          *lngp = dlng - *phip;
          *latp = -(*thetap);

          /* Normalize the celestial longitude. */
          if (eul[0] >= 0.0) {
            if (*lngp < 0.0) *lngp += 360.0;
          } else {
            if (*lngp > 0.0) *lngp -= 360.0;
          }

          if (*lngp > 360.0) {
            *lngp -= 360.0;
          } else if (*lngp < -360.0) {
            *lngp += 360.0;
          }
d220 2
a221 21
  if (eul[4] == 0.0) {
    if (eul[1] == 0.0) {
      dphi = fmod(eul[2] - 180.0 - eul[0], 360.0);

      lngp = lng;
      latp = lat;
      phip   = phi;
      thetap = theta;
      for (ilat = 0; ilat < nlat; ilat++, lngp += sll, latp += sll) {
        for (ilng = 0; ilng < mlng; ilng++, phip += spt, thetap += spt) {
          *phip = fmod(*lngp + dphi, 360.0);
          *thetap = *latp;

          /* Normalize the native longitude. */
          if (*phip > 180.0) {
            *phip -= 360.0;
          } else if (*phip < -180.0) {
            *phip += 360.0;
          }
        }
      }
d223 14
a236 18
    } else {
      dphi = fmod(eul[2] + eul[0], 360.0);

      lngp = lng;
      latp = lat;
      phip   = phi;
      thetap = theta;
      for (ilat = 0; ilat < nlat; ilat++, lngp += sll, latp += sll) {
        for (ilng = 0; ilng < mlng; ilng++, phip += spt, thetap += spt) {
          *phip = fmod(dphi - *lngp, 360.0);
          *thetap = -(*latp);

          /* Normalize the native longitude. */
          if (*phip > 180.0) {
            *phip -= 360.0;
          } else if (*phip < -180.0) {
            *phip += 360.0;
          }
@


4.4.1.3
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
  Copyright (C) 1995-2010, Mark Calabretta
d31 1
a31 1
  $Id: sph.c,v 4.4.1.2 2009/08/12 08:22:27 cal103 Exp cal103 $
@


4.3
log
@WCSLIB 4.3
@
text
@d3 2
a4 2
    WCSLIB 4.3 - an implementation of the FITS WCS standard.
    Copyright (C) 1995-2007, Mark Calabretta
d6 1
a6 1
    This file is part of WCSLIB.
d8 24
a31 24
    WCSLIB is free software: you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License as published by the
    Free Software Foundation, either version 3 of the License, or (at your
    option) any later version.

    WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
    more details.

    You should have received a copy of the GNU Lesser General Public License
    along with WCSLIB.  If not, see <http://www.gnu.org/licenses/>.

    Correspondence concerning WCSLIB may be directed to:
       Internet email: mcalabre@@atnf.csiro.au
       Postal address: Dr. Mark Calabretta
                       Australia Telescope National Facility, CSIRO
                       PO Box 76
                       Epping NSW 1710
                       AUSTRALIA

    Author: Mark Calabretta, Australia Telescope National Facility
    http://www.atnf.csiro.au/~mcalabre/index.html
    $Id: sph.c,v 4.2.1.2 2007/12/03 05:02:17 cal103 Exp cal103 $
d44 10
a53 1
int sphx2s(eul, nphi, ntheta, spt, sll, phi, theta, lng, lat)
d55 145
a199 4
const double eul[5];
int nphi, ntheta, spt, sll;
const double phi[], theta[];
double lng[], lat[];
d202 100
a301 43
   int mphi, mtheta, rowlen, rowoff;
   double cosphi, costhe, costhe3, costhe4, dlng, dphi, sinphi, sinthe,
          sinthe3, sinthe4, x, y, z;
   register int iphi, itheta;
   register const double *phip, *thetap;
   register double *latp, *lngp;

   if (ntheta > 0) {
      mphi   = nphi;
      mtheta = ntheta;
   } else {
      mphi   = 1;
      mtheta = 1;
      ntheta = nphi;
   }


   /* Do phi dependency. */
   phip = phi;
   rowoff = 0;
   rowlen = nphi*sll;
   for (iphi = 0; iphi < nphi; iphi++, rowoff += sll, phip += spt) {
      dphi = *phip - eul[2];

      lngp = lng + rowoff;
      for (itheta = 0; itheta < mtheta; itheta++) {
         *lngp = dphi;
         lngp += rowlen;
      }
   }


   /* Do theta dependency. */
   thetap = theta;
   lngp = lng;
   latp = lat;
   for (itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
      costhe = cosd(*thetap);
      sinthe = sind(*thetap);
      costhe3 = costhe*eul[3];
      costhe4 = costhe*eul[4];
      sinthe3 = sinthe*eul[3];
      sinthe4 = sinthe*eul[4];
d303 13
a315 52
      for (iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
         dphi = *lngp;
         cosphi = cosd(dphi);
         sinphi = sind(dphi);

         /* Compute the celestial longitude. */
         x = sinthe4 - costhe3*cosphi;
         if (fabs(x) < tol) {
            /* Rearrange formula to reduce roundoff errors. */
            x = -cosd(*thetap+eul[1]) + costhe3*(1.0 - cosphi);
         }

         y = -costhe*sinphi;
         if (x != 0.0 || y != 0.0) {
            dlng = atan2d(y, x);
         } else {
            /* Change of origin of longitude. */
            if (eul[1] < 90.0) {
               dlng =  dphi + 180.0;
            } else {
               dlng = -dphi;
            }
         }
         *lngp = eul[0] + dlng;

         /* Normalize the celestial longitude. */
         if (eul[0] >= 0.0) {
            if (*lngp < 0.0) *lngp += 360.0;
         } else {
            if (*lngp > 0.0) *lngp -= 360.0;
         }

         if (*lngp > 360.0) {
            *lngp -= 360.0;
         } else if (*lngp < -360.0) {
            *lngp += 360.0;
         }

         /* Compute the celestial latitude. */
         if (fmod(dphi,180.0) == 0.0) {
            *latp = *thetap + cosphi*eul[1];
            if (*latp >  90.0) *latp =  180.0 - *latp;
            if (*latp < -90.0) *latp = -180.0 - *latp;
         } else {
            z = sinthe3 + costhe4*cosphi;
            if (fabs(z) > 0.99) {
               /* Use an alternative formula for greater accuracy. */
               *latp = copysign(acosd(sqrt(x*x+y*y)), z);
            } else {
               *latp = asind(z);
            }
         }
d317 2
a318 1
   }
d320 1
a320 1
   return 0;
d325 8
a332 6
int sphs2x(eul, nlng, nlat, sll, spt, lng, lat, phi, theta)

const double eul[5];
int nlat, nlng, sll, spt;
const double lat[], lng[];
double phi[], theta[];
d335 2
a336 43
   int mlat, mlng, rowlen, rowoff;
   double coslat, coslat3, coslat4, coslng, dlng, dphi, sinlat, sinlat3,
          sinlat4, sinlng, x, y, z;
   register int ilat, ilng;
   register const double *latp, *lngp;
   register double *phip, *thetap;

   if (nlat > 0) {
      mlng = nlng;
      mlat = nlat;
   } else {
      mlng = 1;
      mlat = 1;
      nlat = nlng;
   }


   /* Do lng dependency. */
   lngp = lng;
   rowoff = 0;
   rowlen = nlng*spt;
   for (ilng = 0; ilng < nlng; ilng++, rowoff += spt, lngp += sll) {
      dlng = *lngp - eul[0];

      phip = phi + rowoff;
      for (ilat = 0; ilat < mlat; ilat++) {
         *phip = dlng;
         phip += rowlen;
      }
   }


   /* Do lat dependency. */
   latp = lat;
   phip   = phi;
   thetap = theta;
   for (ilat = 0; ilat < nlat; ilat++, latp += sll) {
      coslat  = cosd(*latp);
      sinlat  = sind(*latp);
      coslat3 = coslat*eul[3];
      coslat4 = coslat*eul[4];
      sinlat3 = sinlat*eul[3];
      sinlat4 = sinlat*eul[4];
d338 18
a355 48
      for (ilng = 0; ilng < mlng; ilng++, phip += spt, thetap += spt) {
         dlng = *phip;
         coslng = cosd(dlng);
         sinlng = sind(dlng);

         /* Compute the native longitude. */
         x = sinlat4 - coslat3*coslng;
         if (fabs(x) < tol) {
            /* Rearrange formula to reduce roundoff errors. */
            x = -cosd(*latp+eul[1]) + coslat3*(1.0 - coslng);
         }

         y = -coslat*sinlng;
         if (x != 0.0 || y != 0.0) {
            dphi = atan2d(y, x);
         } else {
            /* Change of origin of longitude. */
            if (eul[1] < 90.0) {
               dphi =  dlng - 180.0;
            } else {
               dphi = -dlng;
            }
         }
         *phip = fmod(eul[2] + dphi, 360.0);

         /* Normalize the native longitude. */
         if (*phip > 180.0) {
            *phip -= 360.0;
         } else if (*phip < -180.0) {
            *phip += 360.0;
         }

         /* Compute the native latitude. */
         if (fmod(dlng,180.0) == 0.0) {
            *thetap = *latp + coslng*eul[1];
            if (*thetap >  90.0) *thetap =  180.0 - *thetap;
            if (*thetap < -90.0) *thetap = -180.0 - *thetap;
         } else {
            z = sinlat3 + coslat4*coslng;
            if (fabs(z) > 0.99) {
               /* Use an alternative formula for greater accuracy. */
               *thetap = copysign(acosd(sqrt(x*x+y*y)), z);
            } else {
               *thetap = asind(z);
            }
         }
      }
   }
d357 1
a357 1
   return 0;
@


4.3.1.1
log
@WCSLIB 4.3 development branch.
@
text
@d3 2
a4 2
    WCSLIB 4.4 - an implementation of the FITS WCS standard.
    Copyright (C) 1995-2008, Mark Calabretta
d31 1
a31 1
    $Id: sph.c,v 4.3 2007/12/27 05:41:36 cal103 Exp cal103 $
@


4.3.1.2
log
@Code for sphdpa(); ANSIfied prototypes for sphx2s() and sphs2x();
changed indentation.
@
text
@d3 2
a4 2
  WCSLIB 4.4 - an implementation of the FITS WCS standard.
  Copyright (C) 1995-2009, Mark Calabretta
d6 1
a6 1
  This file is part of WCSLIB.
d8 24
a31 24
  WCSLIB is free software: you can redistribute it and/or modify it under the
  terms of the GNU Lesser General Public License as published by the Free
  Software Foundation, either version 3 of the License, or (at your option)
  any later version.

  WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
  more details.

  You should have received a copy of the GNU Lesser General Public License
  along with WCSLIB.  If not, see <http://www.gnu.org/licenses/>.

  Correspondence concerning WCSLIB may be directed to:
    Internet email: mcalabre@@atnf.csiro.au
    Postal address: Dr. Mark Calabretta
                    Australia Telescope National Facility, CSIRO
                    PO Box 76
                    Epping NSW 1710
                    AUSTRALIA

  Author: Mark Calabretta, Australia Telescope National Facility
  http://www.atnf.csiro.au/~mcalabre/index.html
  $Id: sph.c,v 4.3.1.1 2007/12/27 13:23:47 cal103 Exp cal103 $
d44 6
a49 10
int sphx2s(
  const double eul[5],
  int nphi,
  int ntheta,
  int spt,
  int sll,
  const double phi[],
  const double theta[],
  double lng[],
  double lat[])
d52 28
a79 54
  int mphi, mtheta, rowlen, rowoff;
  double cosphi, costhe, costhe3, costhe4, dlng, dphi, sinphi, sinthe,
         sinthe3, sinthe4, x, y, z;
  register int iphi, itheta;
  register const double *phip, *thetap;
  register double *latp, *lngp;

  if (ntheta > 0) {
    mphi   = nphi;
    mtheta = ntheta;
  } else {
    mphi   = 1;
    mtheta = 1;
    ntheta = nphi;
  }


  /* Do phi dependency. */
  phip = phi;
  rowoff = 0;
  rowlen = nphi*sll;
  for (iphi = 0; iphi < nphi; iphi++, rowoff += sll, phip += spt) {
    dphi = *phip - eul[2];

    lngp = lng + rowoff;
    for (itheta = 0; itheta < mtheta; itheta++) {
      *lngp = dphi;
      lngp += rowlen;
    }
  }


  /* Do theta dependency. */
  thetap = theta;
  lngp = lng;
  latp = lat;
  for (itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
    costhe = cosd(*thetap);
    sinthe = sind(*thetap);
    costhe3 = costhe*eul[3];
    costhe4 = costhe*eul[4];
    sinthe3 = sinthe*eul[3];
    sinthe4 = sinthe*eul[4];

    for (iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
      dphi = *lngp;
      cosphi = cosd(dphi);
      sinphi = sind(dphi);

      /* Compute the celestial longitude. */
      x = sinthe4 - costhe3*cosphi;
      if (fabs(x) < tol) {
        /* Rearrange formula to reduce roundoff errors. */
        x = -cosd(*thetap+eul[1]) + costhe3*(1.0 - cosphi);
d81 1
a82 12
      y = -costhe*sinphi;
      if (x != 0.0 || y != 0.0) {
        dlng = atan2d(y, x);
      } else {
        /* Change of origin of longitude. */
        if (eul[1] < 90.0) {
          dlng =  dphi + 180.0;
        } else {
          dlng = -dphi;
        }
      }
      *lngp = eul[0] + dlng;
d84 64
a147 5
      /* Normalize the celestial longitude. */
      if (eul[0] >= 0.0) {
        if (*lngp < 0.0) *lngp += 360.0;
      } else {
        if (*lngp > 0.0) *lngp -= 360.0;
d149 1
d151 1
a151 24
      if (*lngp > 360.0) {
        *lngp -= 360.0;
      } else if (*lngp < -360.0) {
        *lngp += 360.0;
      }

      /* Compute the celestial latitude. */
      if (fmod(dphi,180.0) == 0.0) {
        *latp = *thetap + cosphi*eul[1];
        if (*latp >  90.0) *latp =  180.0 - *latp;
        if (*latp < -90.0) *latp = -180.0 - *latp;
      } else {
        z = sinthe3 + costhe4*cosphi;
        if (fabs(z) > 0.99) {
          /* Use an alternative formula for greater accuracy. */
          *latp = copysign(acosd(sqrt(x*x+y*y)), z);
        } else {
          *latp = asind(z);
        }
      }
    }
  }

  return 0;
d156 6
a161 10
int sphs2x(
  const double eul[5],
  int nlng,
  int nlat,
  int sll,
  int spt,
  const double lng[],
  const double lat[],
  double phi[],
  double theta[])
d164 28
a191 66
  int mlat, mlng, rowlen, rowoff;
  double coslat, coslat3, coslat4, coslng, dlng, dphi, sinlat, sinlat3,
         sinlat4, sinlng, x, y, z;
  register int ilat, ilng;
  register const double *latp, *lngp;
  register double *phip, *thetap;

  if (nlat > 0) {
    mlng = nlng;
    mlat = nlat;
  } else {
    mlng = 1;
    mlat = 1;
    nlat = nlng;
  }


  /* Do lng dependency. */
  lngp = lng;
  rowoff = 0;
  rowlen = nlng*spt;
  for (ilng = 0; ilng < nlng; ilng++, rowoff += spt, lngp += sll) {
    dlng = *lngp - eul[0];

    phip = phi + rowoff;
    for (ilat = 0; ilat < mlat; ilat++) {
      *phip = dlng;
      phip += rowlen;
    }
  }


  /* Do lat dependency. */
  latp = lat;
  phip   = phi;
  thetap = theta;
  for (ilat = 0; ilat < nlat; ilat++, latp += sll) {
    coslat  = cosd(*latp);
    sinlat  = sind(*latp);
    coslat3 = coslat*eul[3];
    coslat4 = coslat*eul[4];
    sinlat3 = sinlat*eul[3];
    sinlat4 = sinlat*eul[4];

    for (ilng = 0; ilng < mlng; ilng++, phip += spt, thetap += spt) {
      dlng = *phip;
      coslng = cosd(dlng);
      sinlng = sind(dlng);

      /* Compute the native longitude. */
      x = sinlat4 - coslat3*coslng;
      if (fabs(x) < tol) {
        /* Rearrange formula to reduce roundoff errors. */
        x = -cosd(*latp+eul[1]) + coslat3*(1.0 - coslng);
      }

      y = -coslat*sinlng;
      if (x != 0.0 || y != 0.0) {
        dphi = atan2d(y, x);
      } else {
        /* Change of origin of longitude. */
        if (eul[1] < 90.0) {
          dphi =  dlng - 180.0;
        } else {
          dphi = -dlng;
        }
d193 1
a193 1
      *phip = fmod(eul[2] + dphi, 360.0);
a194 6
      /* Normalize the native longitude. */
      if (*phip > 180.0) {
        *phip -= 360.0;
      } else if (*phip < -180.0) {
        *phip += 360.0;
      }
d196 58
a253 13
      /* Compute the native latitude. */
      if (fmod(dlng,180.0) == 0.0) {
        *thetap = *latp + coslng*eul[1];
        if (*thetap >  90.0) *thetap =  180.0 - *thetap;
        if (*thetap < -90.0) *thetap = -180.0 - *thetap;
      } else {
        z = sinlat3 + coslat4*coslng;
        if (fabs(z) > 0.99) {
          /* Use an alternative formula for greater accuracy. */
          *thetap = copysign(acosd(sqrt(x*x+y*y)), z);
        } else {
          *thetap = asind(z);
        }
d255 1
a255 39
    }
  }

  return 0;
}

/*--------------------------------------------------------------------------*/

int sphdpa(
  int nfield,
  double lng0,
  double lat0,
  const double lng[],
  const double lat[],
  double dist[],
  double pa[])

{
  int i;
  double eul[5];

  /* Set the Euler angles for the coordinate transformation. */
  eul[0] = lng0;
  eul[1] = 90.0 - lat0;
  eul[2] = 0.0;
  eul[3] = cosd(eul[1]);
  eul[4] = sind(eul[1]);

  /* Transform field points to the new system. */
  sphs2x(eul, nfield, 0, 1, 1, lng, lat, pa, dist);

  for (i = 0; i < nfield; i++) {
    /* Angular distance is obtained from latitude in the new frame. */
    dist[i] = 90.0 - dist[i];

    /* Position angle is obtained from longitude in the new frame. */
    pa[i] = -pa[i];
    if (pa[i] < -180.0) pa[i] += 360.0;
  }
d257 1
a257 1
  return 0;
@


4.3.1.3
log
@Added error messaging based on wcserr.  Changes supplied by Michael
Droettboom (STScI) with respect to the released WCSLIB 4.7 sources.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.3.1.2 2009/07/22 02:19:20 cal103 Exp cal103 $
d93 2
a94 1
    sincosd(*thetap, &sinthe, &costhe);
d102 2
a103 1
      sincosd(dphi, &sinphi, &cosphi);
d109 1
a109 1
        x = -cosd(*thetap + eul[1]) + costhe3*(1.0 - cosphi);
d209 2
a210 1
    sincosd(*latp, &sinlat, &coslat);
d218 2
a219 1
      sincosd(dlng, &sinlng, &coslng);
@


4.3.1.4
log
@In sphx2s() and sphx2s(), handle a simple change in origin of longitude
separately for speed and accuracy.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.3.1.3 2009/07/27 06:05:48 cal103 Exp cal103 $
a72 32
  /* Check for a simple change in origin of longitude. */
  if (eul[1] == 0.0) {
    dlng = eul[0] + 180.0 - eul[2];

    lngp = lng;
    latp = lat;
    phip   = phi;
    thetap = theta;
    for (itheta = 0; itheta < ntheta; itheta++, phip += spt, thetap += spt) {
      for (iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
        *lngp = *phip + dlng;
        *latp = *thetap;

        /* Normalize the celestial longitude. */
        if (eul[0] >= 0.0) {
          if (*lngp < 0.0) *lngp += 360.0;
        } else {
          if (*lngp > 0.0) *lngp -= 360.0;
        }

        if (*lngp > 360.0) {
          *lngp -= 360.0;
        } else if (*lngp < -360.0) {
          *lngp += 360.0;
        }
      }
    }

    return 0;
  }


a186 26
  /* Check for a simple change in origin of longitude. */
  if (eul[1] == 0.0) {
    dphi = eul[2] - 180.0 - eul[0];

    lngp = lng;
    latp = lat;
    phip   = phi;
    thetap = theta;
    for (ilat = 0; ilat < nlat; ilat++, lngp += sll, latp += sll) {
      for (ilng = 0; ilng < mlng; ilng++, phip += spt, thetap += spt) {
        *phip = fmod(*lngp + dphi, 360.0);
        *thetap = *latp;

        /* Normalize the native longitude. */
        if (*phip > 180.0) {
          *phip -= 360.0;
        } else if (*phip < -180.0) {
          *phip += 360.0;
        }
      }
    }

    return 0;
  }


a194 1
    thetap = theta;
@


4.3.1.5
log
@Continuing from the previous change, when the origin of longitude doesn't
actually change, ensure that sphs2x() returns phi == lng with the same
sign when lng == +/-180.0.  This is mainly to assist PGSBOX in drawing
coordinate graticules.
@
text
@d31 1
a31 1
  $Id: sph.c,v 4.3.1.4 2009/07/30 00:04:25 cal103 Exp cal103 $
d75 1
a75 1
    dlng = fmod(eul[0] + 180.0 - eul[2], 360.0);
d221 1
a221 1
    dphi = fmod(eul[2] - 180.0 - eul[0], 360.0);
@


4.2
log
@WCSLIB 4.2
@
text
@d2 30
a31 29
*
*   WCSLIB 4.2 - an implementation of the FITS WCS standard.
*   Copyright (C) 1995-2005, Mark Calabretta
*
*   WCSLIB is free software; you can redistribute it and/or modify it under
*   the terms of the GNU General Public License as published by the Free
*   Software Foundation; either version 2 of the License, or (at your option)
*   any later version.
*
*   WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY
*   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
*   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
*   details.
*
*   You should have received a copy of the GNU General Public License along
*   with WCSLIB; if not, write to the Free Software Foundation, Inc.,
*   59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
*
*   Correspondence concerning WCSLIB may be directed to:
*      Internet email: mcalabre@@atnf.csiro.au
*      Postal address: Dr. Mark Calabretta
*                      Australia Telescope National Facility, CSIRO
*                      PO Box 76
*                      Epping NSW 1710
*                      AUSTRALIA
*
*   Author: Mark Calabretta, Australia Telescope National Facility
*   http://www.atnf.csiro.au/~mcalabre/index.html
*   $Id: sph.c,v 4.1 2005/08/25 08:10:47 cal103 Exp cal103 $
@


4.2.1.1
log
@WCSLIB 4.2 development branch.
@
text
@d3 1
a3 1
*   WCSLIB 4.3 - an implementation of the FITS WCS standard.
d30 1
a30 1
*   $Id: sph.c,v 4.2 2005/09/21 13:21:57 cal103 Exp cal103 $
@


4.2.1.2
log
@Switched to LGPL 3.0.
@
text
@d2 29
a30 30

    WCSLIB 4.3 - an implementation of the FITS WCS standard.
    Copyright (C) 1995-2007, Mark Calabretta

    This file is part of WCSLIB.

    WCSLIB is free software: you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License as published by the
    Free Software Foundation, either version 3 of the License, or (at your
    option) any later version.

    WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
    more details.

    You should have received a copy of the GNU Lesser General Public License
    along with WCSLIB.  If not, see <http://www.gnu.org/licenses/>.

    Correspondence concerning WCSLIB may be directed to:
       Internet email: mcalabre@@atnf.csiro.au
       Postal address: Dr. Mark Calabretta
                       Australia Telescope National Facility, CSIRO
                       PO Box 76
                       Epping NSW 1710
                       AUSTRALIA

    Author: Mark Calabretta, Australia Telescope National Facility
    http://www.atnf.csiro.au/~mcalabre/index.html
    $Id: sph.c,v 4.2.1.1 2005/12/05 02:39:43 cal103 Exp cal103 $
@


4.1
log
@WCSLIB 4.1
@
text
@d3 1
a3 1
*   WCSLIB 4.1 - an implementation of the FITS WCS standard.
d30 1
a30 1
*   $Id: sph.c,v 4.0 2005/02/04 05:46:39 cal103 Exp cal103 $
@


4.0
log
@WCSLIB 4.0: changed from LGPL to GPL; removed unnecessary casts of void
pointers (a hangover from K&R C); declare const pointers to refer to const
function arguments where necessary.
@
text
@d3 1
a3 1
*   WCSLIB 4.0 - an implementation of the FITS WCS standard.
d30 1
a30 1
*   $Id: sph.c,v 3.6 2004/08/25 04:22:31 cal103 Exp cal103 $
@


3.6
log
@WCSLIB 3.6: removed support for K&R C.
@
text
@d3 2
a4 2
*   WCSLIB 3.6 - an implementation of the FITS WCS convention.
*   Copyright (C) 1995-2004, Mark Calabretta
d6 4
a9 4
*   This library is free software; you can redistribute it and/or modify it
*   under the terms of the GNU Library General Public License as published
*   by the Free Software Foundation; either version 2 of the License, or (at
*   your option) any later version.
d11 4
a14 4
*   This library is distributed in the hope that it will be useful, but
*   WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
*   General Public License for more details.
d16 3
a18 3
*   You should have received a copy of the GNU Library General Public License
*   along with this library; if not, write to the Free Software Foundation,
*   Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
d30 1
a30 1
*   $Id: sph.c,v 3.5 2004/06/28 01:53:03 mcalabre Exp mcalabre $
d55 2
a56 1
   register double *latp, *lngp, *phip, *thetap;
d69 1
a69 1
   phip = (double *)phi;
d84 1
a84 1
   thetap = (double *)theta;
d167 2
a168 1
   register double *latp, *lngp, *phip, *thetap;
d181 1
a181 1
   lngp = (double *)lng;
d196 1
a196 1
   latp = (double *)lat;
@


3.5
log
@WCSLIB 3.5
@
text
@d3 1
a3 1
*   WCSLIB 3.5 - an implementation of the FITS WCS convention.
d30 1
a30 1
*   $Id: sph.c,v 3.4 2004/02/11 00:15:03 mcalabre Exp mcalabre $
a35 6

#ifndef __STDC__
#ifndef const
#define const
#endif
#endif
@


3.4
log
@WCSLIB 3.4: sphx2s() and sphs2x() incorrectly handled the "change in the
origin of longitude" special case that arises when delta_p = -90, in the even
more restrictive case where |theta| = 90 also; it applied Eq. (3) instead of
Eq. (4) of Paper II.
@
text
@d3 1
a3 1
*   WCSLIB 3.4 - an implementation of the FITS WCS convention.
d29 2
a30 1
*   $Id: sph.c,v 3.3 2003/10/21 08:52:49 mcalabre Exp mcalabre $
@


3.3
log
@WCSLIB 3.3
@
text
@d3 2
a4 2
*   WCSLIB 3.3 - an implementation of the FITS WCS convention.
*   Copyright (C) 1995-2003, Mark Calabretta
d29 1
a29 1
*   $Id: sph.c,v 3.2 2003/09/09 04:04:04 mcalabre Exp mcalabre $
d116 5
a120 1
            dlng = dphi + 180.0;
d227 5
a231 1
            dphi = dlng - 180.0;
@


3.2
log
@WCSLIB 3.2
@
text
@d3 1
a3 1
*   WCSLIB 3.2 - an implementation of the FITS WCS convention.
d29 1
a29 1
*   $Id: sph.c,v 3.1 2003/04/28 03:50:41 mcalabre Exp mcalabre $
@


3.1
log
@WCSLIB 3.1
@
text
@d3 1
a3 1
*   WCSLIB 3.1 - an implementation of the FITS WCS convention.
d29 1
a29 1
*   $Id: sph.c,v 3.0 2003/04/01 04:11:54 mcalabre Exp mcalabre $
@


3.0
log
@WCSLIB 3.0
@
text
@d3 1
a3 1
*   WCSLIB 3.0 - an implementation of the FITS WCS convention.
d29 1
a29 1
*   $Id: sph.c,v 2.6 2001/11/15 03:14:40 mcalabre Exp $
@


2.7
log
@Updated date in copyright notice.
@
text
@d3 2
a4 2
*   WCSLIB - an implementation of the FITS WCS proposal.
*   Copyright (C) 1995-2002, Mark Calabretta
d22 4
a25 4
*      Postal address: Dr. Mark Calabretta,
*                      Australia Telescope National Facility,
*                      P.O. Box 76,
*                      Epping, NSW, 2121,
a27 60
*=============================================================================
*
*   C routines for the spherical coordinate transformations used by the FITS
*   "World Coordinate System" (WCS) convention.
*
*   Summary of routines
*   -------------------
*   The spherical coordinate transformations are implemented via separate
*   functions for the transformation in each direction.
*
*   Forward transformation; sphfwd()
*   --------------------------------
*   Transform celestial coordinates to the native coordinates of a projection.
*
*   Given:
*      lng,lat  double   Celestial longitude and latitude, in degrees.
*      eul[5]   double   Euler angles for the transformation:
*                          0: Celestial longitude of the native pole, in
*                             degrees.
*                          1: Celestial colatitude of the native pole, or
*                             native colatitude of the celestial pole, in
*                             degrees.
*                          2: Native longitude of the celestial pole, in
*                             degrees.
*                          3: cos(eul[1])
*                          4: sin(eul[1])
*
*   Returned:
*      phi,     double   Longitude and latitude in the native coordinate
*      theta             system of the projection, in degrees.
*
*   Function return value:
*               int      Error status
*                           0: Success.
*
*   Reverse transformation; sphrev()
*   --------------------------------
*   Transform native coordinates of a projection to celestial coordinates.
*
*   Given:
*      phi,     double   Longitude and latitude in the native coordinate
*      theta             system of the projection, in degrees.
*      eul[5]   double   Euler angles for the transformation:
*                          0: Celestial longitude of the native pole, in
*                             degrees.
*                          1: Celestial colatitude of the native pole, or
*                             native colatitude of the celestial pole, in
*                             degrees.
*                          2: Native longitude of the celestial pole, in
*                             degrees.
*                          3: cos(eul[1])
*                          4: sin(eul[1])
*
*   Returned:
*      lng,lat  double   Celestial longitude and latitude, in degrees.
*
*   Function return value:
*               int      Error status
*                           0: Success.
*
d29 1
a29 1
*   $Id: sph.c,v 2.6 2001/11/15 03:14:40 mcalabre Exp mcalabre $
a41 1
#ifdef COPYSIGN
d43 2
a44 1
#endif
d46 1
a46 1
const double tol = 1.0e-5;
d48 1
a48 1
int sphfwd (lng, lat, eul, phi, theta)
d50 4
a53 2
const double lat, lng, eul[5];
double *phi, *theta;
d56 14
a69 1
   double coslat, coslng, dlng, dphi, sinlat, sinlng, x, y, z;
a70 2
   coslat = cosd(lat);
   sinlat = sind(lat);
d72 12
a83 16
   dlng = lng - eul[0];
   coslng = cosd(dlng);
   sinlng = sind(dlng);

   /* Compute the native longitude. */
   x = sinlat*eul[4] - coslat*eul[3]*coslng;
   if (fabs(x) < tol) {
      /* Rearrange formula to reduce roundoff errors. */
      x = -cosd(lat+eul[1]) + coslat*eul[3]*(1.0 - coslng);
   }
   y = -coslat*sinlng;
   if (x != 0.0 || y != 0.0) {
      dphi = atan2d(y, x);
   } else {
      /* Change of origin of longitude. */
      dphi = dlng - 180.0;
a84 1
   *phi = eul[2] + dphi;
a85 6
   /* Normalize the native longitude. */
   if (*phi > 180.0) {
      *phi -= 360.0;
   } else if (*phi < -180.0) {
      *phi += 360.0;
   }
d87 60
a146 12
   /* Compute the native latitude. */
   if (fmod(dlng,180.0) == 0.0) {
      *theta = lat + coslng*eul[1];
      if (*theta >  90.0) *theta =  180.0 - *theta;
      if (*theta < -90.0) *theta = -180.0 - *theta;
   } else {
      z = sinlat*eul[3] + coslat*eul[4]*coslng;
      if (fabs(z) > 0.99) {
         /* Use an alternative formula for greater numerical accuracy. */
         *theta = copysign(acosd(sqrt(x*x+y*y)), z);
      } else {
         *theta = asind(z);
d153 1
a153 1
/*-----------------------------------------------------------------------*/
d155 1
a155 1
int sphrev (phi, theta, eul, lng, lat)
d157 4
a160 2
const double phi, theta, eul[5];
double *lng, *lat;
d163 9
a171 18
   double cosphi, costhe, dlng, dphi, sinphi, sinthe, x, y, z;

   costhe = cosd(theta);
   sinthe = sind(theta);

   dphi = phi - eul[2];
   cosphi = cosd(dphi);
   sinphi = sind(dphi);

   /* Compute the celestial longitude. */
   x = sinthe*eul[4] - costhe*eul[3]*cosphi;
   if (fabs(x) < tol) {
      /* Rearrange formula to reduce roundoff errors. */
      x = -cosd(theta+eul[1]) + costhe*eul[3]*(1.0 - cosphi);
   }
   y = -costhe*sinphi;
   if (x != 0.0 || y != 0.0) {
      dlng = atan2d(y, x);
d173 3
a175 2
      /* Change of origin of longitude. */
      dlng = dphi + 180.0;
a176 1
   *lng = eul[0] + dlng;
d178 13
a190 5
   /* Normalize the celestial longitude. */
   if (eul[0] >= 0.0) {
      if (*lng < 0.0) *lng += 360.0;
   } else {
      if (*lng > 0.0) *lng -= 360.0;
a192 5
   if (*lng > 360.0) {
      *lng -= 360.0;
   } else if (*lng < -360.0) {
      *lng += 360.0;
   }
d194 54
a247 12
   /* Compute the celestial latitude. */
   if (fmod(dphi,180.0) == 0.0) {
      *lat = theta + cosphi*eul[1];
      if (*lat >  90.0) *lat =  180.0 - *lat;
      if (*lat < -90.0) *lat = -180.0 - *lat;
   } else {
      z = sinthe*eul[3] + costhe*eul[4]*cosphi;
      if (fabs(z) > 0.99) {
         /* Use an alternative formula for greater numerical accuracy. */
         *lat = copysign(acosd(sqrt(x*x+y*y)), z);
      } else {
         *lat = asind(z);
@


2.6
log
@Changed date in copyright notice.
@
text
@d4 1
a4 1
*   Copyright (C) 1995-2001, Mark Calabretta
d89 1
a89 1
*   $Id: sph.c,v 2.5 2000/05/10 04:44:05 mcalabre Exp mcalabre $
@


2.5
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
*   Copyright (C) 1995-2000, Mark Calabretta
d89 1
a89 1
*   $Id: sph.c,v 2.4 1999/12/13 07:27:35 mcalabre Exp mcalabre $
@


2.4
log
@Revised include file handling.
@
text
@d4 1
a4 1
*   Copyright (C) 1995-1999, Mark Calabretta
d89 1
a89 1
*   $Id: sph.c,v 2.3 1999/06/16 00:04:28 mcalabre Exp mcalabre $
@


2.3
log
@Updated date in copyright notice.
@
text
@d89 1
a89 1
*   $Id: sph.c,v 2.2 1998/02/25 07:05:50 mcalabre Exp mcalabre $
d92 1
d94 1
@


2.2
log
@Updated date in copyright notice.
@
text
@d4 1
a4 1
*   Copyright (C) 1995-1998, Mark Calabretta
d89 1
a89 1
*   $Id: sph.c,v 2.1 1995/11/09 03:17:43 mcalabre Exp mcalabre $
@


2.1
log
@In sphrev(), normalize the celestial longitude so that it has the same sign
as eul[0].
@
text
@d4 1
a4 1
*   Copyright (C) 1995, Mark Calabretta
d89 1
a89 1
*   $Id: sph.c,v 2.0 1995/09/11 08:38:47 mcalabre Exp mcalabre $
@


2.0
log
@WCSLIB 2.0
@
text
@d89 1
a89 1
*   $Id: sph.c,v 1.2 1995/09/11 08:37:36 mcalabre Exp mcalabre $
d121 1
a121 1
   /* Compute native coordinates. */
d136 1
a136 1
   /* Normalize. */
d143 1
d178 1
a178 1
   /* Compute celestial coordinates. */
d193 7
a199 1
   /* Normalize. */
d206 1
@


1.2
log
@Improve numerical precision by using small angle formulae or alternative
formulae as required.
@
text
@d89 1
a89 1
*   $Id: sph.c,v 1.1 1995/01/31 03:20:27 mcalabre Exp mcalabre $
@


1.1
log
@Initial revision
@
text
@d44 1
a44 1
*      eul[6]   double   Euler angles for the transformation:
a53 1
*                          5: eul[2] - eul[0]
d70 1
a70 1
*      eul[6]   double   Euler angles for the transformation:
a79 1
*                          5: eul[2] - eul[0]
d89 1
a89 1
*   $Id$
d100 5
d108 1
a108 1
const double lat, lng, eul[6];
d112 1
a112 1
   double coslat, coslng, dlng, sinlng, sinlat, x, y;
d122 5
a126 1
   x =  sinlat*eul[4] - coslat*eul[3]*coslng;
d129 1
a129 1
      *phi = eul[2] + atan2d(y, x);
d132 1
a132 1
      *phi = eul[5] + lng;
d134 1
d143 13
a155 1
   *theta = asind(sinlat*eul[3] + coslat*eul[4]*coslng);
d164 1
a164 1
const double phi, theta, eul[6];
d168 1
a168 1
   double cosphi, costhe, dphi, sinphi, sinthe, x, y;
d178 5
a182 1
   x =  sinthe*eul[4] - costhe*eul[3]*cosphi;
d185 1
a185 1
      *lng = eul[0] + atan2d(y, x);
d188 1
a188 1
      *lng = phi - eul[5];
d190 1
d199 13
a211 1
   *lat = asind(sinthe*eul[3] + costhe*eul[4]*cosphi);
@
