aboutsummaryrefslogtreecommitdiff
path: root/noao/astutil/pdm/pdmfindmin.x
blob: 4053bf43dc639048dca1a824df29eae8982436b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
include <mach.h>
include <ctype.h>
include <error.h>
include "pdm.h"

# PDM_FINDMIN -- Find the minimum value of the abscissa.

int procedure pdm_findmin (pdmp, ptype, startint, endint, is, ie)

pointer	pdmp			# pointer to PDM data structure
int	ptype			# plot type
double	startint, endint	# start and end ordinates
int	is, ie			# start and end indexs

double	miny, dy, dx
int	i, isave, npt
pointer	xpt, ypt

begin
	# Dereference npt.
	npt = PDM_NPT(pdmp)

	# Dereference the appropriate abcissa and ordinate.
	switch (ptype) {
	case DATAPLOT:
	    xpt = PDM_XP(pdmp)
	    ypt = PDM_DYP(pdmp)
	case THETAPPLOT:
	    xpt = PDM_XTHP(pdmp)
	    ypt = PDM_YTHP(pdmp)
	case THETAFPLOT:
	    ypt = PDM_YTHP(pdmp)
	    xpt = PDM_XTHP(pdmp)
	case PHASEPLOT:
	    ypt = PDM_YPHP(pdmp)
	    xpt = PDM_XPHP(pdmp)
	}

	# Search the abscissas between startint and endint
	# for the minimum value.

	isave = 1
	miny = MAX_DOUBLE
	do i = is, ie {
	    dx = Memd[xpt+i-1]
	    dy = Memd[ypt+i-1]
	    if (dx > startint && dx < endint) {
		if (dy < miny) {
	    	    miny = dy
	    	    isave = i
		}
	    }
	}

	# Return the corresponding index value.
	return (isave)
end