void trace_wetbulb (short width) /*************************************************************/ /* TRACE_WETBULB */ /* John Hart NSSFC KCMO */ /* */ /* Plots environmental Wetbulb trace on SkewT. */ /*************************************************************/ { short i, x, y, xold, yold, ok = 0; float t1; setlinestyle (1, width); for (i = 0; i < sndgp->numlev; i++) { if (sndgp->sndg[i].dwpt > -200) { xold = x; yold = y; t1 = wetbulb (sndgp->sndg[i].pres, sndgp->sndg[i].temp, sndgp->sndg[i].dwpt); x = temp_to_pix (t1, sndgp->sndg[i].pres); y = pres_to_pix (sndgp->sndg[i].pres); if (ok == 0) { moveto (x, y); ok = 1; } else { moveto (xold, yold); lineto (x, y); } } } }
/*NP*/ void posneg_wetbulb(float start, float *pos, float *neg, float *top, float *bot) /***********************************************************************/ /* POSNEG */ /* Calculates positive and negative areas as related to winter weather */ /* forecasting. Search begins at 500mb, but only returns results if */ /* a positive area is found, overlaying a negative area. */ /* START is the upper limit of search.(default=init_phase) */ /***********************************************************************/ { float upper, lower, pe1, h1, te1, tp1, totp, totn, pe2, h2, te2, tp2, tdef1, tdef2; float lyrlast, lyre, tote, pelast, ptop, pbot, lvl; short i, lptr, uptr, warmlayer=0, coldlayer=0, phase; short pIndex, zIndex, tdIndex; char st[80]; *pos = 0; *neg = 0; *top = 0; *bot = 0; /* ----- If there is no sounding, do not compute ----- */ if (!qc(i_temp(500, I_PRES)) && !qc(i_temp(850, I_PRES))) return; pIndex = getParmIndex("PRES"); zIndex = getParmIndex("HGHT"); tdIndex = getParmIndex("DWPT"); if (!sndg || pIndex == -1 || zIndex == -1 || tdIndex == -1) return; /* ----- Find lowest observation in layer ----- */ lower = sndg[sfc()][pIndex]; lptr = sfc(); /* ----- Find highest observation in layer ----- */ if (start=-1) { strcpy( st, init_phase( &lvl, &phase )); if (lvl> 0) { upper = lvl; } else { upper=500; } } else { upper = start; } i=numlvl-1; while (sndg[i][pIndex] < upper) { i--; if (i < 0) { fprintf(stderr, "Warning: posneg_wetbulb: Could not find a pressure greater than %.2f\n", upper); fprintf(stderr, "Using %.2f as the upper level.\n", sndg[0][pIndex]); i = 0; break; } } uptr = i; if (sndg[i][pIndex] == upper) uptr--; /* ----- Start with top layer ----- */ pe1 = upper; h1 = i_hght(pe1 , I_PRES); te1 = wetbulb(pe1, i_temp(pe1, I_PRES), i_dwpt(pe1, I_PRES)); tp1 = 0; totp = totn = tote = ptop = pbot = 0; for( i = uptr; i >= lptr; i-- ) { if (qc(sndg[i][tdIndex])) { /* ----- Calculate every level that reports a temp ----- */ pe2 = sndg[i][pIndex]; h2 = sndg[i][zIndex]; te2 = wetbulb(pe2, i_temp(pe2, I_PRES), i_dwpt(pe2, I_PRES)); tp2 = 0; tdef1 = (0 - te1) / (te1 + 273.15); tdef2 = (0 - te2) / (te2 + 273.15); lyrlast = lyre; lyre = 9.8F * (tdef1 + tdef2) / 2.0F * (h2 - h1); /* Has a warm layer been found yet? */ if (te2>0) if (warmlayer==0) { warmlayer=1; ptop=pe2; } /* Has a cold layer been found yet? */ if (te2<0) if ((warmlayer==1) && (coldlayer==0)) { coldlayer=1; pbot=pe2; } if (warmlayer>0) { if (lyre>0) { totp += lyre; } else { totn += lyre; } tote += lyre; printf("%4.0f - %4.0f E=%6.0f TOT=%6.0f Top=%6.0f Bot=%6.0f\n", pe1, pe2, lyre, tote, ptop, pbot); } pelast = pe1; pe1 = pe2; h1 = h2; te1 = te2; tp1 = tp2; } } if ((warmlayer==1) && (coldlayer==1)) { *pos = totp; *neg = totn; *top = ptop; *bot = pbot; printf("Tot= %.0f J/kg Pos= %.0f J/kg Neg= %.0f J/kg\n", tote, totp, totn); printf("Top= %.0f Bot= %.0f\n", ptop, pbot); } else { printf("Warm/Cold Layers not found.\n" ); *pos = 0; *neg = 0; *top = 0; *bot = 0; } }