c
c    @(#)nitr.f	1.2
c
       real function nitr(stheta)

c	This function applies reference curves from Elrod and Kester
c	(1985) to calculate nitrate concentration given a sigma theta 
c	value. 
c	If the value is shallower than the minimum density, 
c	nitrate is assumed to be zero.
c	If value is deeper than max, set to value at deepest knot
c	(i.e.17.6)
c	Fred Lipschultz 12.4.87

       include'mladv.inc'
       include'trc.inc'

       real c(4,4),knot(5)
       data knot/26.32,26.83,27.18,27.25,27.92/
       data c/40.7,-61.9,58.3,-0.3,
     +	      23.0,27.3,-46.0,12.1,
     +	      25.2,-21.0,-375.5,21.5,
     +	      16.7,-99.9,94.0,23.0/
	
       if (ino3in .eq. 2) then
          nitr = surno3 + (stheta - sursigt) * grdno3
          if (nitr .lt. 0.) nitr = 0.
          return
         endif

       if (ino3in .eq. 3) then
          if (stheta .le. 25.80) then
             nitr = 0.
            else if (stheta .le. 26.14) then
             nitr = (stheta - 25.8) * 1.27
            else if (stheta .le. 26.26) then
             nitr = .4321 + (stheta - 26.14) * 11.8975
            else
             nitr = 1.8598 + (stheta - 26.26) * 4.5709
           endif
          return
         endif

       if (stheta .le. knot(1)) then
	  nitr=0.
       elseif (stheta .gt. knot(5)) then
          nitr = 17.6
       else
          do 10 i=2,5
	     if (stheta .le. knot(i)) then
	        d=stheta-knot(i-1)
	        nitr=((c(3,i-1)*d+c(2,i-1))*d+c(1,i-1))*d+c(4,i-1)
                goto 11
             endif	
 10       continue
 11       continue

	endif

        if (nitr.lt.0.) nitr=0.

        return
	end
