コード例 #1
0
ファイル: handlers.c プロジェクト: arekinath/illumos-joyent
/*
 * Set device thresholds from (3) formats:
 * 	path	"always-on"
 * 	path	time-spec: [0-9]+[{h,m,s}]
 *	path	(ts1 ts2 ...)+
 */
int
devthr(void)
{
	int cmd, upval = OKUP, nthresh = 0, *vlist = NULL;
	pm_req_t pmreq;

	bzero(&pmreq, sizeof (pmreq));
	if (devpath(&pmreq.physpath, LINEARG(1), &upval))
		return (upval);

	if (strcmp(LINEARG(2), always_on) == 0) {
		cmd = PM_SET_DEVICE_THRESHOLD;
		pmreq.value = INT_MAX;
	} else if (get_thresh(&vlist, &nthresh)) {
		mesg(MERR, bad_thresh_fmt);
		upval = NOUP;
	} else if (nthresh == 1) {
		pmreq.value = *vlist;
		cmd = PM_SET_DEVICE_THRESHOLD;
	} else {
		pmreq.data = vlist;
		pmreq.datasize = (nthresh * sizeof (*vlist));
		cmd = PM_SET_COMPONENT_THRESHOLDS;
	}

	if (upval != NOUP && (upval = ioctl(pm_fd, cmd, &pmreq)) == -1)
		mesg(MERR, set_thresh_fmt, pmreq.physpath, strerror(errno));

	free(vlist);
	free(pmreq.physpath);
	return (upval);
}
コード例 #2
0
ファイル: line.c プロジェクト: imincik/pkg-grass
int edit_line_begin(void *closure)
{
    struct edit_line *el = closure;

    G_debug(2, "edit_line()");

    i_prompt("Edit line or boundary:");
    i_prompt_buttons("Select", "", "Quit tool");

    el->thresh = get_thresh();
    G_debug(2, "thresh = %f", el->thresh);

    el->phase = 1;
    set_mode(MOUSE_POINT);

    return 0;
}
コード例 #3
0
ファイル: line.c プロジェクト: imincik/pkg-grass
/* Snap to node */
int snap(double *x, double *y)
{
    int node;
    double thresh;

    G_debug(2, "snap(): x = %f, y = %f", *x, *y);

    thresh = get_thresh();

    node = Vect_find_node(&Map, *x, *y, 0, thresh, 0);

    if (node > 0)
	Vect_get_node_coor(&Map, node, x, y, NULL);

    G_debug(2, "node = %d x = %f, y = %f", node, *x, *y);
    return node;
}
コード例 #4
0
ファイル: more_cosine.cpp プロジェクト: KWMalik/nt2
int main()
{
  double maxdc = 0.0;
  double maxds = 0.0;
  double maxdca = 0.0;
  double maxdsa = 0.0;
  nt2::int32_t i = 0;
  nt2::int32_t j = 0;
  nt2::int32_t di = 0;
  float thresh = 0.0f;
  for(float a0 = nt2::Zero<float>(); a0 < 100*nt2::Pi<float>(); a0 = nt2::successor(a0, 1))
    {
      float s, c;
      nt2::sinecosine<nt2::direct_small>(a0, s, c);
      float scrm =  nt2::crlibm::sin_rn(a0);
      float ccrm =  nt2::crlibm::cos_rn(a0);
      double ds = nt2::ulpdist(s, scrm);
      maxds =  nt2::max(maxds, ds);
//       double dc = nt2::ulpdist(c, ccrm);
//       maxdc =  nt2::max(maxdc, dc);
//       histo(nt2::max(dc, ds));
//       get_thresh(nt2::max(dc, ds), a0);
      histo(ds);
      get_thresh(ds, a0);
      ++i;
    }
  std::cout << "nb values " << i << std::endl;
  std::cout << "ulp cos   " << maxdc << std::endl;
  std::cout << "ulp sin   " << maxds << std::endl;
  std::cout << std::setprecision(7) << "thresh    " << thresh<< std::endl;

  for(nt2::int32_t i=0; i < NB; i++)
   {
     std::cout << i << " -> " << h[i] << std::endl;
   }
  for(nt2::int32_t i=0; i < NB; i++)
   {
     std::cout << i << " -> " << thresh_at[i] << std::endl;
   }
  return 0;
}
コード例 #5
0
ファイル: line.c プロジェクト: imincik/pkg-grass
int move_line_begin(void *closure)
{
    struct move_line *ml = closure;

    G_debug(2, "move_line()");

    ml->Points = Vect_new_line_struct();
    ml->Cats = Vect_new_cats_struct();

    i_prompt(_("Move point, line, boundary, or centroid:"));
    i_prompt_buttons(_("Select"), "", _("Quit tool"));

    ml->thresh = get_thresh();
    G_debug(2, "thresh = %f", ml->thresh);

    ml->last_line = 0;

    set_mode(MOUSE_POINT);

    return 0;
}
コード例 #6
0
ファイル: line.c プロジェクト: imincik/pkg-grass
int delete_line_begin(void *closure)
{
    struct delete_line *dl = closure;

    G_debug(2, "delete_line()");

    dl->Points = Vect_new_line_struct();
    dl->Cats = Vect_new_cats_struct();

    i_prompt(_("Delete point, line, boundary, or centroid:"));
    i_prompt_buttons(_("Select"), _("Unselect"), _("Quit tool"));

    dl->thresh = get_thresh();
    G_debug(2, "thresh = %f", dl->thresh);

    dl->line = 0;
    dl->first = 1;
    dl->last_line = 0;

    set_mode(MOUSE_POINT);

    return 0;
}
コード例 #7
0
ファイル: CalcBlowingSnow.c プロジェクト: BramDr/VIC
/******************************************************************************
 * @brief    Calculate sublimation from blowing snow
 *****************************************************************************/
double
CalcBlowingSnow(double   Dt,
                double   Tair,
                unsigned LastSnow,
                double   SurfaceLiquidWater,
                double   Wind,
                double   Ls,
                double   AirDens,
                double   EactAir,
                double   ZO,
                double   Zrh,
                double   snowdepth,
                double   lag_one,
                double   sigma_slope,
                double   Tsnow,
                int      iveg,
                int      Nveg,
                double   fe,
                double   displacement,
                double   roughness,
                double  *TotalTransport)
{
    extern parameters_struct param;
    extern option_struct     options;

    /* Local variables: */
    double                   Age;
    double                   U10, Uo, prob_occurence;
    double                   es, Ros, F;
    double                   SubFlux;
    double                   Diffusivity;
    double                   ushear;
    double                   Tk;
    double                   utshear;
    int                      p;
    double                   upper, lower, Total;
    double                   area;
    double                   sigma_w;
    double                   Zo_salt;
    double                   ratio, wind10;
    double                   Uveg, hv, Nd;
    double                   Transport;

    /*******************************************************************/
    /* Calculate some general variables, that don't depend on wind speed. */

    /* Age in hours */
    Age = LastSnow * Dt / SEC_PER_HOUR;

    /* Saturation density of water vapor, Liston A-8 */
    es = svp(Tair);

    Tk = Tair + CONST_TKFRZ;

    Ros = CONST_EPS * es / (CONST_RDAIR * Tk);

    /* Diffusivity in m2/s, Liston eq. A-7 */
    Diffusivity = (2.06e-5) * pow(Tk / 273., 1.75);

    // Essery et al. 1999, eq. 6 (m*s/kg)
    F = (Ls / (param.BLOWING_KA * Tk)) * (Ls * Tk / CONST_RDAIR - 1.);
    F += 1. / (Diffusivity * Ros);

    /* grid cell 10 m wind speed = 50th percentile wind */
    /* Wind speed at 2 m above snow was passed to this function. */

    wind10 = Wind * log(10. / ZO) / log((2 + ZO) / ZO);

    /* Check for bare soil case. */
    if (iveg == Nveg) {
        fe = 1500;
        sigma_slope = .0002;
    }
    // sigma_w/uo:
    ratio = (2.44 - (0.43) * lag_one) * sigma_slope;

    sigma_w = wind10 * ratio;
    Uo = wind10;

    /*********** Parameters for roughness above snow. *****************/
    hv = (3. / 2.) * displacement;
    Nd = (4. / 3.) * (roughness / displacement);

    /*******************************************************************/
    /** Begin loop through wind probability function.                  */

    Total = 0.0;
    *TotalTransport = 0.0;
    area = 1. / (double) param.BLOWING_NUMINCS;

    if (snowdepth > 0.0) {
        if (options.BLOWING_SPATIAL_WIND && sigma_w != 0.) {
            for (p = 0; p < param.BLOWING_NUMINCS; p++) {
                SubFlux = lower = upper = 0.0;
                /* Find the limits of integration. */
                if (p == 0) {
                    lower = -9999;
                    upper = Uo + sigma_w * log(2. * (p + 1) * area);
                }
                else if (p > 0 && p < param.BLOWING_NUMINCS / 2) {
                    lower = Uo + sigma_w * log(2. * (p) * area);
                    upper = Uo + sigma_w * log(2. * (p + 1) * area);
                }
                else if (p < (param.BLOWING_NUMINCS - 1) && p >=
                         (double) param.BLOWING_NUMINCS / 2) {
                    lower = Uo - sigma_w * log(2. - 2. * (p * area));
                    upper = Uo - sigma_w * log(2. - 2. * ((p + 1.) * area));
                }
                else if (p == param.BLOWING_NUMINCS - 1) {
                    lower = Uo - sigma_w * log(2. - 2. * (p * area));
                    upper = 9999;
                }

                if (lower > upper) { /* Could happen if lower > Uo*2 */
                    lower = upper;
                    log_err("Error with probability boundaries");
                }


                /* Find expected value of wind speed for the interval. */
                U10 = Uo;
                if (lower >= Uo) {
                    U10 = -0.5 *
                          ((upper +
                            sigma_w) * exp((-1. / sigma_w) * (upper - Uo)) -
                           (lower +
                            sigma_w) *
                           exp((-1. / sigma_w) * (lower - Uo))) / area;
                }
                else if (upper <= Uo) {
                    U10 = 0.5 *
                          ((upper -
                            sigma_w) * exp((1. / sigma_w) * (upper - Uo)) -
                           (lower -
                            sigma_w) *
                           exp((1. / sigma_w) * (lower - Uo))) / area;
                }
                else {
                    log_err("Problem with probability ranges: Increment = %d, "
                            "integration limits = %f - %f", p, upper, lower);
                }

                if (U10 < 0.4) {
                    U10 = .4;
                }

                if (U10 > 25.) {
                    U10 = 25.;
                }
                /*******************************************************************/
                /* Calculate parameters for probability of blowing snow occurence. */
                /* ( Li and Pomeroy 1997) */

                if (snowdepth < hv) {
                    Uveg = U10 / sqrt(1. + 170 * Nd * (hv - snowdepth));
                }
                else {
                    Uveg = U10;
                }


                prob_occurence = get_prob(Tair, Age, SurfaceLiquidWater, Uveg);

                /*******************************************************************/
                /* Calculate threshold shear stress. Send 0 for constant or  */
                /* 1 for variable threshold after Li and Pomeroy (1997)      */

                utshear =
                    get_thresh(Tair, SurfaceLiquidWater, ZO);

                /* Iterate to find actual shear stress during saltation. */

                shear_stress(U10, ZO, &ushear, &Zo_salt, utshear);

                if (ushear > utshear) {
                    SubFlux = CalcSubFlux(EactAir, es, Zrh, AirDens, utshear,
                                          ushear, fe, Tsnow,
                                          Tair, U10, Zo_salt, F, &Transport);
                }
                else {
                    SubFlux = 0.0;
                    Transport = 0.0;
                }

                Total += (1. / (double) param.BLOWING_NUMINCS) * SubFlux *
                         prob_occurence;
                *TotalTransport += (1. / (double) param.BLOWING_NUMINCS) *
                                   Transport * prob_occurence;
            }
        }
        else {
            U10 = Uo;
            /*******************************************************************/
            /* Calculate parameters for probability of blowing snow occurence. */
            /* ( Li and Pomeroy 1997) */

            if (snowdepth < hv) {
                Uveg = U10 / sqrt(1. + 170 * Nd * (hv - snowdepth));
            }
            else {
                Uveg = U10;
            }

            prob_occurence = get_prob(Tair, Age, SurfaceLiquidWater, Uveg);

            /*******************************************************************/
            /* Calculate threshold shear stress. Send 0 for constant or  */
            /* 1 for variable threshold after Li and Pomeroy (1997)      */

            utshear = get_thresh(Tair, SurfaceLiquidWater, ZO);

            /* Iterate to find actual shear stress during saltation. */

            shear_stress(Uo, ZO, &ushear, &Zo_salt, utshear);

            if (ushear > utshear) {
                SubFlux = CalcSubFlux(EactAir, es, Zrh, AirDens, utshear,
                                      ushear, fe, Tsnow,
                                      Tair, Uo, Zo_salt, F, &Transport);
            }
            else {
                SubFlux = 0.0;
                Transport = 0.0;
            }
            Total = SubFlux * prob_occurence;
            *TotalTransport = Transport * prob_occurence;
        }
    }

    if (Total < -.00005) {
        Total = -.00005;
    }

    return Total;
}
コード例 #8
0
ファイル: line.c プロジェクト: imincik/pkg-grass
int new_line_update(void *closure, int sxn, int syn, int button)
{
    struct new_line *nl = closure;
    double x = D_d_to_u_col(sxn);
    double y = D_d_to_u_row(syn);
    double dist;

    G_debug(3, "button = %d x = %d = %f y = %d = %f", button, sxn, x, syn, y);

    if (nl->first && button == 3) {	/* Quit tool ( points & lines ), first is always for points */
	Tool_next = TOOL_NOTHING;
	return 1;
    }
    
    if (button > 3) /* Do nothing on mouse scroll */ 
        return 0; 

    if (nl->type & GV_POINTS && (button == 1 ||  button == 2)) {
	snap(&x, &y);
	Vect_append_point(nl->Points, x, y, 0);

	write_line(&Map, nl->type, nl->Points);
	updated_lines_and_nodes_erase_refresh_display();
	return 1;
    }
    else {			/* GV_LINES */
	/* Button may be 1,2,3 */
	if (button == 1) {	/* New point */
	    if (snap(&x, &y) == 0) {
		/* If not snapping to other features, try to snap to lines start.
		 * Allows to create area of single boundary. */
		if (nl->Points->n_points > 2) {
		    dist = Vect_points_distance(nl->Points->x[0], nl->Points->y[0], 0, x, y, 0, WITHOUT_Z);
		    if (dist < get_thresh()) {
			x = nl->Points->x[0];
			y = nl->Points->y[0];
		    }
		}
	    }
	    if (Vect_append_point(nl->Points, x, y, 0) == -1) {
		G_warning(_("Out of memory! Point not added."));
		return 0;
	    }

	    if (nl->type == GV_LINE)
		symb_set_driver_color(SYMB_LINE);
	    else
		symb_set_driver_color(SYMB_BOUNDARY_0);

	    display_points(nl->Points, 1);
	    set_location(D_u_to_d_col(x), D_u_to_d_row(y));
	    nl->first = 0;
	    set_mode(MOUSE_LINE);
	}
	else if (button == 2) {	/* Undo last point */
	    if (nl->Points->n_points >= 1) {
		symb_set_driver_color(SYMB_BACKGROUND);
		display_points(nl->Points, 1);
		nl->Points->n_points--;

		if (nl->type == GV_LINE)
		    symb_set_driver_color(SYMB_LINE);
		else
		    symb_set_driver_color(SYMB_BOUNDARY_0);

		display_points(nl->Points, 1);
		set_location(D_u_to_d_col
			     (nl->Points->x[nl->Points->n_points - 1]),
			     D_u_to_d_row(nl->Points->
					  y[nl->Points->n_points - 1])
		    );
	    }
	    if (nl->Points->n_points == 0) {
		i_prompt_buttons(_("New point"), "", _("Quit tool"));
		nl->first = 1;
		set_mode(MOUSE_POINT);
	    }
	}
	else if (button == 3) {		/* write the line and quit */
	    if (nl->Points->n_points > 1) {
		/* Before the line is written, we must check if connected to existing nodes, if yes,
		 * such nodes must be add to update list before! the line is written (areas/isles */
		int node1 =
		    Vect_find_node(&Map, nl->Points->x[0], nl->Points->y[0],
				   nl->Points->z[0], 0, Vect_is_3d(&Map));
		int i = nl->Points->n_points - 1;
		int node2 =
		    Vect_find_node(&Map, nl->Points->x[i], nl->Points->y[i],
				   nl->Points->z[i], 0, Vect_is_3d(&Map));

		G_debug(2, "  old node1 = %d  old node2 = %d", node1, node2);
		write_line(&Map, nl->type, nl->Points);
		updated_lines_and_nodes_erase_refresh_display();
	    }
	    else
		G_warning(_("Less than 2 points for line -> nothing written"));

	    return 1;
	}
	G_debug(2, "n_points = %d", nl->Points->n_points);
    }

    i_prompt_buttons(_("New point"), _("Undo last point"), _("Close line"));
    return 0;
}
コード例 #9
0
ファイル: CalcBlowingSnow.c プロジェクト: jhamman/VIC_glacier
/*****************************************************************************
  Function name: CalcBlowingSnow()

  Purpose      : Calculate sublimation from blowing snow

  Required     :  double Dt;                     Model time step (hours) 
  double Tair;                    Air temperature (C) 
  int LastSnow;                   Time steps since last snowfall. 
  double SurfaceLiquidWater;      Liquid water in the surface layer (m) 
  double Wind;                    Wind speed (m/s), 2 m above snow 
  double Ls;                      Latent heat of sublimation (J/kg) 
  double AirDens;                 Density of air (kg/m3) 
  double Lv;                      Latent heat of vaporization (J/kg3) 
  double Press;                   Air pressure (Pa) 
  double EactAir;                 Actual vapor pressure of air (Pa) 
  double ZO;                      Snow roughness height (m)
  Returns      : BlowingMassFlux

  Modifies     : 

  Comments     : Called from SnowPackEnergyBalance
    Reference:  

*****************************************************************************/
double CalcBlowingSnow( double Dt, 
			double Tair,
			int LastSnow,
			double SurfaceLiquidWater,
			double Wind,
			double Ls,
			double AirDens,
			double Press,
			double EactAir,
			double ZO,
			double Zrh,
			double snowdepth,
			float lag_one,
			float sigma_slope,
			double Tsnow, 
			int iveg, 
			int Nveg, 
			float fe,
			double displacement,
			double roughness,
			double *TotalTransport)

{
  /* Local variables: */

  double Age;
  double U10, Uo, prob_occurence;
  double es, Ros, F;
  double SubFlux;
  double Diffusivity;
  double ushear, Qsalt, hsalt, phi_s, psi_s;
  double Tk;
  double Lv;
  double T, ztop;
  double ut10, utshear;
  int p;
  double upper, lower, Total;
  double area;
  double sigma_w;
  double undersat_2;
  double b, temp2; /* SBSM scaling parameter. */
  double temp, temp3;
  double Zo_salt;
  double ratio, wind10;
  double Uveg, hv, Nd;
  double Transport;
  int count=0;

  Lv = (2.501e6 - 0.002361e6 * Tsnow);
  /*******************************************************************/
  /* Calculate some general variables, that don't depend on wind speed. */

  /* Age in hours */
  Age = LastSnow*(Dt);
      
  /* Saturation density of water vapor, Liston A-8 */
  es = svp(Tair);

  Tk = Tair  + KELVIN;
    
  Ros = 0.622*es/(287*Tk);
  
  /* Diffusivity in m2/s, Liston eq. A-7 */
  Diffusivity = (2.06e-5) * pow(Tk/273.,1.75);

  // Essery et al. 1999, eq. 6 (m*s/kg)
  F = (Ls/(Ka*Tk))*(Ls*MW/(R*Tk) - 1.);
  F += 1./(Diffusivity*Ros);

  /* grid cell 10 m wind speed = 50th percentile wind */
  /* Wind speed at 2 m above snow was passed to this function. */

  wind10 = Wind*log(10./ZO)/log((2+ZO)/ZO);
  //  fprintf(stderr,"wind=%f, Uo=%f\n",Wind, Uo);

  /* Check for bare soil case. */
  if(iveg == Nveg) {
    fe = 1500;
    sigma_slope = .0002;
  }
  // sigma_w/uo:
  ratio = (2.44 - (0.43)*lag_one)*sigma_slope;
  //  sigma_w = wind10/(.69+(1/ratio));
  //  Uo = sigma_w/ratio;
  
  sigma_w = wind10*ratio;
  Uo = wind10;
  
  /*********** Parameters for roughness above snow. *****************/
    hv = (3./2.)*displacement;
    Nd = (4./3.)*(roughness/displacement);

  /*******************************************************************/
  /** Begin loop through wind probability function.                  */

  Total = 0.0;
  *TotalTransport = 0.0;
  area = 1./NUMINCS;
  
  if(snowdepth > 0.0) {
    if(SPATIAL_WIND && sigma_w != 0.) {
      for(p= 0; p< NUMINCS; p++) {
      
	SubFlux = lower = upper = 0.0;
      /* Find the limits of integration. */
      if(p==0) {
	lower = -9999;
	upper = Uo + sigma_w*log(2.*(p+1)*area);
      }
      else if(p > 0 && p < NUMINCS/2) {
	lower = Uo + sigma_w*log(2.*(p)*area);
	upper = Uo + sigma_w*log(2.*(p+1)*area);
      }
      else if(p < (NUMINCS-1) && p >= NUMINCS/2) {
	lower = Uo - sigma_w*log(2.-2.*(p*area));
	upper = Uo - sigma_w*log(2.-2.*((p+1.)*area));
      }
      else if(p == NUMINCS-1) {
	lower =  Uo - sigma_w*log(2.-2.*(p*area));
	upper = 9999;
      }

      if(lower > upper)  {/* Could happen if lower > Uo*2 */
	lower = upper;
	fprintf(stderr,"Warning: Error with probability boundaries in CalcBlowingSnow()\n");
      }


      /* Find expected value of wind speed for the interval. */
      U10 = Uo;
      if(lower >= Uo ) 
	U10 = -0.5*((upper+sigma_w)*exp((-1./sigma_w)*(upper - Uo))
		    - (lower+sigma_w)*exp((-1./sigma_w)*(lower - Uo)))/area;
      else if(upper <= Uo )
	U10 = 0.5*((upper-sigma_w)*exp((1./sigma_w)*(upper - Uo))
		   - (lower-sigma_w)*exp((1./sigma_w)*(lower - Uo)))/area;
      else {
	fprintf(stderr,"ERROR in CalcBlowingSnow.c: Problem with probability ranges\n");
	fprintf(stderr,"  Increment = %d, integration limits = %f - %f\n",p,upper, lower);
        return ( ERROR );
      }
   
      if(U10 < 0.4)
	U10 = .4;

      if(U10 > 25.) U10 = 25.;
      /*******************************************************************/
      /* Calculate parameters for probability of blowing snow occurence. */
      /* ( Li and Pomeroy 1997) */

      if(snowdepth < hv) {
		Uveg = U10/sqrt(1.+ 170*Nd*(hv - snowdepth));
      }
      else
	Uveg = U10;
  
      //  fprintf(stderr, "Uveg = %f, U10 = %f\n",Uveg, U10);

      prob_occurence = get_prob(Tair, Age, SurfaceLiquidWater, Uveg);

      //   printf("prob=%f\n",prob_occurence);
     
      /*******************************************************************/
      /* Calculate threshold shear stress. Send 0 for constant or  */
      /* 1 for variable threshold after Li and Pomeroy (1997)      */

      utshear = get_thresh(Tair, SurfaceLiquidWater, ZO, VAR_THRESHOLD);
   
      /* Iterate to find actual shear stress during saltation. */

      shear_stress(U10, ZO, &ushear, &Zo_salt, utshear);
      
      if(ushear > utshear) {
	
	SubFlux = CalcSubFlux(EactAir, es, Zrh, AirDens, utshear,ushear, fe, Tsnow, 
			      Tair, U10, Zo_salt, F, &Transport);
      }
      else {
	SubFlux=0.0;
	Transport = 0.0;
      }
 
      Total += (1./NUMINCS)*SubFlux*prob_occurence;
      *TotalTransport += (1./NUMINCS)*Transport*prob_occurence;

      }
   
    }
    else {
      U10=Uo;
       /*******************************************************************/
      /* Calculate parameters for probability of blowing snow occurence. */
      /* ( Li and Pomeroy 1997) */
  
      if(snowdepth < hv)
	Uveg = U10/sqrt(1.+ 170*Nd*(hv - snowdepth));
      else
	Uveg = U10;

      prob_occurence = get_prob(Tair, Age, SurfaceLiquidWater, Uveg);
    
      /*******************************************************************/
      /* Calculate threshold shear stress. Send 0 for constant or  */
      /* 1 for variable threshold after Li and Pomeroy (1997)      */

      utshear = get_thresh(Tair, SurfaceLiquidWater, ZO, VAR_THRESHOLD);

      /* Iterate to find actual shear stress during saltation. */
      
      shear_stress(Uo, ZO, &ushear, &Zo_salt, utshear);

      if(ushear > utshear) {
	SubFlux = CalcSubFlux(EactAir, es, Zrh, AirDens, utshear,ushear, fe, Tsnow, 
			      Tair, Uo, Zo_salt, F, &Transport);
      }
      else {
	SubFlux=0.0;
	Transport = 0.0;
      }
      Total = SubFlux*prob_occurence;
      *TotalTransport = Transport*prob_occurence;
    }
  }

  if(Total < -.00005)
    Total = -.00005;
 
  return Total;
  
}