double massbal_getLoadingError() // // Input: none // Output: none // Purpose: computes runoff load mass balance error. // { int j; double loadIn; double loadOut; double maxError = 0.0; for (j = 0; j < Nobjects[POLLUT]; j++) { // --- get final pollutant loading remaining on land surface LoadingTotals[j].finalLoad += massbal_getBuildup(j); // --- compute total load added to study area loadIn = LoadingTotals[j].initLoad + LoadingTotals[j].buildup + LoadingTotals[j].deposition; // --- compute total load removed from study area loadOut = LoadingTotals[j].sweeping + LoadingTotals[j].infil + LoadingTotals[j].bmpRemoval + LoadingTotals[j].runoff + LoadingTotals[j].finalLoad; // --- compute mass balance error LoadingTotals[j].pctError = 0.0; if ( fabs(loadIn - loadOut) < 0.001 ) { LoadingTotals[j].pctError = TINY; } else if ( loadIn > 0.0 ) { LoadingTotals[j].pctError = 100.0 * (1.0 - loadOut / loadIn); } else if ( loadOut > 0.0 ) { LoadingTotals[j].pctError = 100.0 * (loadIn / loadOut - 1.0); } maxError = MAX(maxError, LoadingTotals[j].pctError); // --- report total counts as log10 if ( Pollut[j].units == COUNT ) { LoadingTotals[j].initLoad = LOG10(LoadingTotals[j].initLoad); LoadingTotals[j].buildup = LOG10(LoadingTotals[j].buildup); LoadingTotals[j].deposition = LOG10(LoadingTotals[j].deposition); LoadingTotals[j].sweeping = LOG10(LoadingTotals[j].sweeping); LoadingTotals[j].infil = LOG10(LoadingTotals[j].infil); LoadingTotals[j].bmpRemoval = LOG10(LoadingTotals[j].bmpRemoval); LoadingTotals[j].runoff = LOG10(LoadingTotals[j].runoff); LoadingTotals[j].finalLoad = LOG10(LoadingTotals[j].finalLoad); } } return maxError; }
//------------------------------------------------------------------------------ // double QEAnalogIndicator::calcFraction (const double x) { double result; // Calculate the fractional scale and constrain to be in range. // if (this->getLogScale ()) { result = (LOG10 (x) - LOG10 (this->mMinimum)) / (LOG10 (this->mMaximum) - LOG10 (this->mMinimum)); } else { result = (x - this->mMinimum) / (this->mMaximum - this->mMinimum); } result = LIMIT (result, 0.0, 1.0); return result; }
void wiplogarithm(float array[], int nxy, float scale) { register int j; for (j = 0; j < nxy; j++) array[j] = (array[j] > 0.0) ? (scale * LOG10(array[j])) : -50.0; return; }
inline SLmillibel QOpenSLESAudioOutput::adjustVolume(qreal vol) { if (qFuzzyIsNull(vol)) return SL_MILLIBEL_MIN; if (qFuzzyCompare(vol, qreal(1.0))) return 0; return 20 * LOG10(vol) * 100; // I.e., 20 * LOG10(SL_MILLIBEL_MAX * vol / SL_MILLIBEL_MAX) }
// calculating the table for loudness calculation based on absLtq = ank static void Loudness_Tabelle (PsyModel* m) { int n; float midfreq; float tmp; // ca. dB(A) for ( n = 0; n < PART_LONG; n++ ){ midfreq = (MPC_WH[n] + MPC_WL[n] + 3) * (0.25 * m->SampleFreq / 512); // center frequency in kHz, why +3 ??? tmp = LOG10 (midfreq) - 3.5f; // dB(A) tmp = -10 * tmp * tmp + 3 - midfreq/3000; m->tables.Loudness [n] = POW10 ( 0.1 * tmp ); // conversion into power } }
void writeLinkLoads() { int i, j, p; double x; char units[15]; char linkLine[] = "--------------------"; char pollutLine[] = "--------------"; // --- print the table headings WRITE(""); WRITE("***************************"); WRITE("Link Pollutant Load Summary"); WRITE("***************************"); WRITE(""); fprintf(Frpt.file, "\n %s", linkLine); for (p = 0; p < Nobjects[POLLUT]; p++) fprintf(Frpt.file, "%s", pollutLine); fprintf(Frpt.file, "\n "); for (p = 0; p < Nobjects[POLLUT]; p++) fprintf(Frpt.file, "%14s", Pollut[p].ID); fprintf(Frpt.file, "\n Link "); for (p = 0; p < Nobjects[POLLUT]; p++) { i = UnitSystem; if ( Pollut[p].units == COUNT ) i = 2; strcpy(units, LoadUnitsWords[i]); fprintf(Frpt.file, "%14s", units); } fprintf(Frpt.file, "\n %s", linkLine); for (p = 0; p < Nobjects[POLLUT]; p++) fprintf(Frpt.file, "%s", pollutLine); // --- print the pollutant loadings carried by each link for ( j = 0; j < Nobjects[LINK]; j++ ) { fprintf(Frpt.file, "\n %-20s", Link[j].ID); for (p = 0; p < Nobjects[POLLUT]; p++) { x = Link[j].totalLoad[p] * LperFT3 * Pollut[p].mcf; if ( Pollut[p].units == COUNT ) x = LOG10(x); if ( x < 10000. ) fprintf(Frpt.file, "%14.3f", x); else fprintf(Frpt.file, "%14.3e", x); } } WRITE(""); }
//------------------------------------------------------------------------------ // bool QEAnalogIndicator::firstValue (int & itc, double & value, bool & isMajor) { double real; bool result; if (this->getLogScale ()) { real = 9.0 * LOG10 (this->mMinimum); } else { real = this->mMinimum / this->getMinorInterval (); } // Use floor to round down and - 0.5 to mitigate any rounding effects. // Subtract an addition -1 to ensure first call to nextValue returns a // value no greater than the first required value. // itc = int (floor (real) - 0.5) - 1; result = this->nextValue (itc, value, isMajor); while (result && (value < this->mMinimum)) { result = this->nextValue (itc, value, isMajor); } return result; }
int APPEND (FUNC_PREFIX, ecvt_r) (FLOAT_TYPE value, int ndigit, int *decpt, int *sign, char *buf, size_t len) { int exponent = 0; if (!ISNAN (value) && !ISINF (value) && value != 0.0) { FLOAT_TYPE (*log10_function) (FLOAT_TYPE) = &LOG10; if (log10_function) { /* Use the reasonable code if -lm is included. */ FLOAT_TYPE dexponent; dexponent = FLOOR (LOG10 (FABS (value))); value *= EXP (dexponent * -M_LN10); exponent = (int) dexponent; } else { /* Slow code that doesn't require -lm functions. */ FLOAT_TYPE d; if (value < 0.0) d = -value; else d = value; if (d < 1.0) { do { d *= 10.0; --exponent; } while (d < 1.0); } else if (d >= 10.0) { do { d *= 0.1; ++exponent; } while (d >= 10.0); } if (value < 0.0) value = -d; else value = d; } } else if (value == 0.0) /* SUSv2 leaves it unspecified whether *DECPT is 0 or 1 for 0.0. * This could be changed to -1 if we want to return 0. */ exponent = 0; if (ndigit <= 0 && len > 0) { buf[0] = '\0'; *decpt = 1; if (!ISINF (value) && !ISNAN (value)) *sign = value < 0.0; else *sign = 0; } else if (APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit - 1, decpt, sign, buf, len)) return -1; *decpt += exponent; return 0; }
double massbal_getQualError() // // Input: none // Output: none // Purpose: computes water quality routing mass balance error. // { int p; double maxQualError = 0.0; double totalInflow; double totalOutflow; double cf; // --- analyze each pollutant for (p = 0; p < Nobjects[POLLUT]; p++) { // --- get final mass stored in nodes and links QualTotals[p].finalStorage += massbal_getStoredMass(p); //(5.1.008) // --- compute % difference between total inflow and outflow totalInflow = QualTotals[p].dwInflow + QualTotals[p].wwInflow + QualTotals[p].gwInflow + QualTotals[p].iiInflow + QualTotals[p].exInflow + QualTotals[p].initStorage; totalOutflow = QualTotals[p].flooding + QualTotals[p].outflow + QualTotals[p].reacted + QualTotals[p].seepLoss + //(5.1.008) QualTotals[p].finalStorage; QualTotals[p].pctError = 0.0; if ( fabs(totalInflow - totalOutflow) < 0.001 ) { QualTotals[p].pctError = TINY; } else if ( totalInflow > 0.0 ) { QualTotals[p].pctError = 100.0 * (1.0 - totalOutflow / totalInflow); } else if ( totalOutflow > 0.0 ) { QualTotals[p].pctError = 100.0 * (totalInflow / totalOutflow - 1.0); } // --- update max. error among all pollutants if ( fabs(QualTotals[p].pctError) > fabs(maxQualError) ) { maxQualError = QualTotals[p].pctError; } // --- convert totals to reporting units (lbs, kg, or Log(Count)) cf = LperFT3; if ( Pollut[p].units == COUNT ) { QualTotals[p].dwInflow = LOG10(cf * QualTotals[p].dwInflow); QualTotals[p].wwInflow = LOG10(cf * QualTotals[p].wwInflow); QualTotals[p].gwInflow = LOG10(cf * QualTotals[p].gwInflow); QualTotals[p].iiInflow = LOG10(cf * QualTotals[p].iiInflow); QualTotals[p].exInflow = LOG10(cf * QualTotals[p].exInflow); QualTotals[p].flooding = LOG10(cf * QualTotals[p].flooding); QualTotals[p].outflow = LOG10(cf * QualTotals[p].outflow); QualTotals[p].reacted = LOG10(cf * QualTotals[p].reacted); QualTotals[p].seepLoss = LOG10(cf * QualTotals[p].seepLoss); //(5.1.008) QualTotals[p].initStorage = LOG10(cf * QualTotals[p].initStorage); QualTotals[p].finalStorage = LOG10(cf * QualTotals[p].finalStorage); } else { cf = cf * UCF(MASS); if ( Pollut[p].units == UG ) cf /= 1000.0; QualTotals[p].dwInflow *= cf; QualTotals[p].wwInflow *= cf; QualTotals[p].gwInflow *= cf; QualTotals[p].iiInflow *= cf; QualTotals[p].exInflow *= cf; QualTotals[p].flooding *= cf; QualTotals[p].outflow *= cf; QualTotals[p].reacted *= cf; QualTotals[p].seepLoss *= cf; QualTotals[p].initStorage *= cf; QualTotals[p].finalStorage *= cf; } } QualError = maxQualError; return maxQualError; }
double massbal_getQualError() // // Input: none // Output: none // Purpose: computes water quality routing mass balance error. // { int j, p; double maxQualError = 0.0; double finalStorage; double totalInflow; double totalOutflow; double cf; // --- analyze each pollutant for (p = 0; p < Nobjects[POLLUT]; p++) { // --- get final mass stored in nodes and links finalStorage = 0.0; for (j = 0; j < Nobjects[NODE]; j++) { finalStorage += Node[j].newVolume * Node[j].newQual[p]; } for (j = 0; j < Nobjects[LINK]; j++) { finalStorage += Link[j].newVolume * Link[j].newQual[p]; } QualTotals[p].finalStorage = finalStorage; // --- compute % difference between total inflow and outflow totalInflow = QualTotals[p].dwInflow + QualTotals[p].wwInflow + QualTotals[p].gwInflow + QualTotals[p].iiInflow + QualTotals[p].exInflow + QualTotals[p].initStorage; totalOutflow = QualTotals[p].outflow + QualTotals[p].pumpedVol + finalStorage; QualTotals[p].internalOutflow = 0.0; if ( fabs(totalInflow - totalOutflow) < 0.001 ) { QualTotals[p].internalOutflow = TINY; } else if ( totalInflow > 0.0 ) { QualTotals[p].internalOutflow = 100.0 * (1.0 - totalOutflow / totalInflow); } else if ( totalOutflow > 0.0 ) { QualTotals[p].internalOutflow = 100.0 * (totalInflow / totalOutflow - 1.0); } // --- update max. error among all pollutants if ( fabs(QualTotals[p].internalOutflow) > fabs(maxQualError) ) { maxQualError = QualTotals[p].internalOutflow; } // --- convert totals to reporting units (lbs, kg, or Log(Count)) cf = LperFT3; if ( Pollut[p].units == COUNT ) { QualTotals[p].dwInflow = LOG10(cf * QualTotals[p].dwInflow); QualTotals[p].wwInflow = LOG10(cf * QualTotals[p].wwInflow); QualTotals[p].gwInflow = LOG10(cf * QualTotals[p].gwInflow); QualTotals[p].iiInflow = LOG10(cf * QualTotals[p].iiInflow); QualTotals[p].exInflow = LOG10(cf * QualTotals[p].exInflow); QualTotals[p].outflow = LOG10(cf * QualTotals[p].outflow); QualTotals[p].pumpedVol = LOG10(cf * QualTotals[p].pumpedVol); QualTotals[p].initStorage = LOG10(cf * QualTotals[p].initStorage); QualTotals[p].finalStorage = LOG10(cf * QualTotals[p].finalStorage); } else { cf = cf * UCF(MASS); if ( Pollut[p].units == UG ) cf /= 1000.0; QualTotals[p].dwInflow *= cf; QualTotals[p].wwInflow *= cf; QualTotals[p].gwInflow *= cf; QualTotals[p].iiInflow *= cf; QualTotals[p].exInflow *= cf; QualTotals[p].outflow *= cf; QualTotals[p].pumpedVol *= cf; QualTotals[p].initStorage *= cf; QualTotals[p].finalStorage *= cf; } } QualError = maxQualError; return maxQualError; }
float TramaParametriza(Ttrastero *trastero,TTrastero2 *trastero2,int32 nframes, Tparamet *paramet) { float total; FILE *fp; static int gendatos = 0; if (gendatos == 0) { fp = fopen("datospar.sal", "wt"); fprintf(fp, "Coef preenf: %f\n", __coef_preenf); fprintf(fp, "Coef rasta : %f\n", __coef_rasta); fprintf(fp, "Coef preenf rasta: %f\n", trastero->preenf); fclose(fp); } else gendatos = 1; VectorImprimir("jlpc.dep",nframes,trastero->a,__long_ventana,"antes preenf..."); //VectorImprimir("jlpc.dep",nframes,trastero->hamwei,__long_ventana,"hamwei"); Hamm_Preenf(trastero->a, trastero->hamwei,__coef_preenf); VectorImprimir("jlpc.dep",nframes,trastero->a,__long_ventana,"tras preenf..."); /* CÁLCULO DE LA FFT PARA CADA TRAMA */ realfft(__fft_points,trastero->a); Energia(trastero->a,trastero->c,__fft_points/2,trastero->y); VectorImprimir("jlpc.dep",nframes,trastero->c,__fft_points/2,"FFT"); total=Promedio(trastero->c,__fft_points/2); total=10*LOG10(total); __energias[nframes]=paramet->mfc[0][nframes][__numParam-1]=trastero->nmfc[nframes][__numParam-1]=total; //__ErrMsg(stderr,"mfcc y energ'ia\n"); /* ENERGÍA EN CADA FILTRO */ plp(trastero->pptr.nfilts, trastero->filwei, trastero->ibegen, trastero->c, trastero->sp, trastero->splog, nframes, trastero->filtertype); VectorImprimir("jlpc.dep",nframes,trastero->splog[nframes], trastero->pptr.nfilts,"LogEnergBand tras PLP"); //__ErrMsg(stderr,"plp\n"); /* RASTA FILTERING AND RASTA MEL */ rasta_trama (trastero->pptr.nfilts, trastero->preenf, trastero->sp, trastero->splog, trastero->spfilt, nframes, paramet->mfc, trastero->nmfc,trastero->filtertype, trastero->_melNum,&(trastero->pptr)); if (nframes>=4) { VectorImprimir("jlpc.dep",nframes-4,trastero->splog[nframes-4],trastero->pptr.nfilts,"LogEnergBand2 tras PLP"); VectorImprimir("jlpc.dep",nframes-3,trastero->splog[nframes-3],trastero->pptr.nfilts,"LogEnergBand2 tras PLP"); VectorImprimir("jlpc.dep",nframes-2,trastero->splog[nframes-2],trastero->pptr.nfilts,"LogEnergBand2 tras PLP"); VectorImprimir("jlpc.dep",nframes-1,trastero->splog[nframes-1],trastero->pptr.nfilts,"LogEnergBand2 tras PLP"); VectorImprimir("jlpc.dep",nframes,trastero->splog[nframes],trastero->pptr.nfilts,"LogEnergBand2 tras PLP"); VectorImprimir("jlpc.dep",nframes,trastero->spfilt[nframes],trastero->pptr.nfilts,"LogEnergBand tras rasta"); VectorImprimir("jlpc.dep",nframes,paramet->mfc[0][nframes],trastero->_melNum,"parrasta"); } if (paramet->n_codeBooks > 1) { __CalculaDelta_trama (paramet, nframes-DELTA,trastero2); if (nframes>=DELTA) VectorImprimir("jlpc.dep",nframes-DELTA,paramet->mfc[1][nframes-DELTA],trastero->_melNum,"delta parrasta"); } //falta un factor 2 PI? parece que no return total; }
smpl_t aubio_db_spl (fvec_t * o) { return 10. * LOG10 (aubio_level_lin (o)); }
/* input must be stepsize long */ void aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, const fvec_t * input, fvec_t * output) { uint_t k, l, maxharm = 0; smpl_t phaseDifference = TWO_PI * (smpl_t) p->stepSize / (smpl_t) p->fftSize; aubio_fpeak_t peaks[MAX_PEAKS]; for (k = 0; k < MAX_PEAKS; k++) { peaks[k].db = -200.; peaks[k].bin = 0.; } for (k = 0; k < input->length; k++) { p->winput->data[k] = p->win->data[k] * input->data[k]; } aubio_fft_do (p->fft, p->winput, p->fftOut); for (k = 0; k <= p->fftSize / 2; k++) { smpl_t magnitude = 20. * LOG10 (2. * p->fftOut->norm[k] / (smpl_t) p->fftSize), phase = p->fftOut->phas[k], tmp, bin; /* compute phase difference */ tmp = phase - p->fftLastPhase->data[k]; p->fftLastPhase->data[k] = phase; /* subtract expected phase difference */ tmp -= (smpl_t) k *phaseDifference; /* map delta phase into +/- Pi interval */ tmp = aubio_unwrap2pi (tmp); /* get deviation from bin frequency from the +/- Pi interval */ tmp = p->fftSize / (smpl_t) p->stepSize * tmp / (TWO_PI); /* compute the k-th partials' true bin */ bin = (smpl_t) k + tmp; if (bin > 0.0 && magnitude > peaks[0].db) { // && magnitude < 0) { memmove (peaks + 1, peaks, sizeof (aubio_fpeak_t) * (MAX_PEAKS - 1)); peaks[0].bin = bin; peaks[0].db = magnitude; } } k = 0; for (l = 1; l < MAX_PEAKS && peaks[l].bin > 0.0; l++) { sint_t harmonic; for (harmonic = 5; harmonic > 1; harmonic--) { if (peaks[0].bin / peaks[l].bin < harmonic + .02 && peaks[0].bin / peaks[l].bin > harmonic - .02) { if (harmonic > (sint_t) maxharm && peaks[0].db < peaks[l].db / 2) { maxharm = harmonic; k = l; } } } } output->data[0] = peaks[k].bin; /* quick hack to clean output a bit */ if (peaks[k].bin > 5000.) output->data[0] = 0.; }
static int print_f(void (*printchar_handler)(struct printchar_handler_data *d, int c), struct printchar_handler_data *printchar_data, long double r, int width, int precision, unsigned int ops, int base, int with_exp, int is_shortened) { char buff[PRINT_F_BUFF_SZ], *str, *end, *prefix, *postfix; DOUBLE ip, fp, ep; int pc, i, ch, len, prefix_len, postfix_len, pad_count, sign_count, zero_left, letter_base; assert(printchar_handler != NULL); assert(width >= 0); assert(precision >= 0); postfix = end = str = &buff[0] + sizeof buff / sizeof buff[0] - 1; *end = '\0'; prefix = signbit(r) ? (r = -r, base == 16) ? ops & OPS_SPEC_UPPER_CASE ? "-0X" : "-0x" : "-" : ops & OPS_FLAG_WITH_SIGN ? base == 16 ? ops & OPS_SPEC_UPPER_CASE ? "+0X" : "+0x" : "+" : ops & OPS_FLAG_EXTRA_SPACE ? base == 16 ? ops & OPS_SPEC_UPPER_CASE ? " 0X" : " 0x" : " " : base == 16 ? ops & OPS_SPEC_UPPER_CASE ? "0X" : "0x" : ""; sign_count = i = pc = 0; prefix_len = strlen(prefix); letter_base = ops & OPS_SPEC_UPPER_CASE ? 'A' : 'a'; precision = ops & OPS_PREC_IS_GIVEN ? is_shortened ? max(precision, 1) : precision : base == 16 ? 12 : PRINT_F_PREC_DEFAULT; fp = MODF(r, &ip); if (with_exp || is_shortened) { ep = 0.0L; while (ip >= base) fp = MODF((ip + fp) / base, &ip), ep += 1.0L; if (fp != 0.0L) while (ip == 0.0L) fp = MODF((ip + fp) * base, &ip), ep -= 1.0L; if ((ep < -4) || (ep >= precision)) with_exp = 1; } fp = with_exp ? fp : MODF(r, &ip); precision -= is_shortened ? ceill(LOG10(ip)) + (ip != 0.0L) : 0; assert(precision >= 0); for (; (sign_count < precision) && (FMOD(fp, 1.0L) != 0.0L); ++sign_count) fp *= base; fp = roundl(fp); ip = precision ? fp != POW(base, sign_count) ? ip : ip + 1.0L : roundl(ip + fp); fp = fp != POW(base, sign_count) ? fp : 0.0L; if (with_exp && (ip >= base)) fp = MODF((ip + fp) / base, &ip), ep += 1.0L; if (with_exp) { do { ch = FMOD(FABS(ep), base); assert((ch >= 0) && (ch < base)); if (ch >= 10) ch += letter_base - 10 - '0'; *--postfix = ch + '0'; MODF(ep / base, &ep); } while (ep != 0.0L); if ((strlen(postfix) == 1) && (base != 16)) *--postfix = '0'; *--postfix = signbit(ep) ? '-' : '+'; *--postfix = base == 16 ? ops & OPS_SPEC_UPPER_CASE ? 'P' : 'p' : ops & OPS_SPEC_UPPER_CASE ? 'E' : 'e'; str = end = postfix - 1; *end = '\0'; } for (; i < sign_count; ++i) { ch = FMOD(fp, base); assert((ch >= 0) && (ch < base)); if (ch >= 10) ch += letter_base - 10 - '0'; *--str = ch + '0'; MODF(fp / base, &fp); } if ((precision && !is_shortened) || sign_count || (ops & OPS_FLAG_WITH_SPEC)) { *--str = '.'; } do { ch = (int)FMOD(ip, (long double)base); assert((ch >= 0) && (ch < base)); if (ch >= 10) ch += letter_base - 10 - '0'; *--str = ch + '0'; MODF(ip / base, &ip); } while (ip != 0.0L); len = end - str; postfix_len = strlen(postfix); zero_left = is_shortened ? 0 : precision - sign_count; pad_count = max(width - prefix_len - len - zero_left - postfix_len, 0); if (!(ops & (OPS_FLAG_ZERO_PAD | OPS_FLAG_LEFT_ALIGN))) { pc += pad_count; while (pad_count--) printchar_handler(printchar_data, ' '); } pc += prefix_len; while (prefix_len--) printchar_handler(printchar_data, *prefix++); if (ops & OPS_FLAG_ZERO_PAD) { pc += pad_count; while (pad_count--) printchar_handler(printchar_data, '0'); } pc += len; while (len--) printchar_handler(printchar_data, *str++); pc += zero_left; while (zero_left--) printchar_handler(printchar_data, '0'); pc += postfix_len; while (postfix_len--) printchar_handler(printchar_data, *postfix++); if (ops & OPS_FLAG_LEFT_ALIGN) { pc += pad_count; while (pad_count--) printchar_handler(printchar_data, ' '); } return pc; }
void writeOutfallLoads() // // Input: node // Output: none // Purpose: writes simulation statistics for outfall nodess to report file. // { char units[15]; int i, j, k, p; double x; double outfallCount, flowCount; double flowSum, freqSum, volSum; double* totals; if ( Nnodes[OUTFALL] > 0 ) { // --- initial totals totals = (double *) calloc(Nobjects[POLLUT], sizeof(double)); for (p=0; p<Nobjects[POLLUT]; p++) totals[p] = 0.0; flowSum = 0.0; freqSum = 0.0; volSum = 0.0; // --- print table title WRITE(""); WRITE("***********************"); WRITE("Outfall Loading Summary"); WRITE("***********************"); WRITE(""); // --- print table column headers fprintf(Frpt.file, "\n -----------------------------------------------------------"); for (p = 0; p < Nobjects[POLLUT]; p++) fprintf(Frpt.file, "--------------"); fprintf(Frpt.file, "\n Flow Avg Max Total"); for (p=0; p<Nobjects[POLLUT]; p++) fprintf(Frpt.file," Total"); fprintf(Frpt.file, "\n Freq Flow Flow Volume"); for (p = 0; p < Nobjects[POLLUT]; p++) fprintf(Frpt.file, "%14s", Pollut[p].ID); fprintf(Frpt.file, "\n Outfall Node Pcnt %3s %3s %8s", FlowUnitWords[FlowUnits], FlowUnitWords[FlowUnits], VolUnitsWords[UnitSystem]); for (p = 0; p < Nobjects[POLLUT]; p++) { i = UnitSystem; if ( Pollut[p].units == COUNT ) i = 2; strcpy(units, LoadUnitsWords[i]); fprintf(Frpt.file, "%14s", units); } fprintf(Frpt.file, "\n -----------------------------------------------------------"); for (p = 0; p < Nobjects[POLLUT]; p++) fprintf(Frpt.file, "--------------"); // --- identify each outfall node for (j=0; j<Nobjects[NODE]; j++) { if ( Node[j].type != OUTFALL ) continue; k = Node[j].subIndex; flowCount = OutfallStats[k].totalPeriods; // --- print node ID, flow freq., avg. flow, max. flow & flow vol. fprintf(Frpt.file, "\n %-20s", Node[j].ID); x = 100.*flowCount/(double)StepCount; fprintf(Frpt.file, "%7.2f", x); freqSum += x; if ( flowCount > 0 ) x = OutfallStats[k].avgFlow*UCF(FLOW)/flowCount; else x = 0.0; flowSum += x; fprintf(Frpt.file, " "); fprintf(Frpt.file, FlowFmt, x); fprintf(Frpt.file, " "); fprintf(Frpt.file, FlowFmt, OutfallStats[k].maxFlow*UCF(FLOW)); fprintf(Frpt.file, "%12.3f", NodeInflow[j] * Vcf); volSum += NodeInflow[j]; // --- print load of each pollutant for outfall for (p=0; p<Nobjects[POLLUT]; p++) { x = OutfallStats[k].totalLoad[p] * LperFT3 * Pollut[p].mcf; totals[p] += x; if ( Pollut[p].units == COUNT ) x = LOG10(x); fprintf(Frpt.file, "%14.3f", x); } } // --- print total outfall loads outfallCount = Nnodes[OUTFALL]; fprintf(Frpt.file, "\n -----------------------------------------------------------"); for (p = 0; p < Nobjects[POLLUT]; p++) fprintf(Frpt.file, "--------------"); fprintf(Frpt.file, "\n System %7.2f ", freqSum/outfallCount); fprintf(Frpt.file, FlowFmt, flowSum); fprintf(Frpt.file, " "); fprintf(Frpt.file, FlowFmt, MaxOutfallFlow*UCF(FLOW)); fprintf(Frpt.file, "%12.3f", volSum * Vcf); for (p = 0; p < Nobjects[POLLUT]; p++) { x = totals[p]; if ( Pollut[p].units == COUNT ) x = LOG10(x); fprintf(Frpt.file, "%14.3f", x); } WRITE(""); free(totals); } }
void writeSubcatchLoads() { int i, j, p; double x; double* totals; char units[15]; char subcatchLine[] = "--------------------"; char pollutLine[] = "--------------"; // --- create an array to hold total loads for each pollutant totals = (double *) calloc(Nobjects[POLLUT], sizeof(double)); if ( totals ) { // --- print the table headings WRITE(""); WRITE("****************************"); WRITE("Subcatchment Washoff Summary"); WRITE("****************************"); WRITE(""); fprintf(Frpt.file, "\n %s", subcatchLine); for (p = 0; p < Nobjects[POLLUT]; p++) fprintf(Frpt.file, "%s", pollutLine); fprintf(Frpt.file, "\n "); for (p = 0; p < Nobjects[POLLUT]; p++) fprintf(Frpt.file, "%14s", Pollut[p].ID); fprintf(Frpt.file, "\n Subcatchment "); for (p = 0; p < Nobjects[POLLUT]; p++) { i = UnitSystem; if ( Pollut[p].units == COUNT ) i = 2; strcpy(units, LoadUnitsWords[i]); fprintf(Frpt.file, "%14s", units); totals[p] = 0.0; } fprintf(Frpt.file, "\n %s", subcatchLine); for (p = 0; p < Nobjects[POLLUT]; p++) fprintf(Frpt.file, "%s", pollutLine); // --- print the pollutant loadings from each subcatchment for ( j = 0; j < Nobjects[SUBCATCH]; j++ ) { fprintf(Frpt.file, "\n %-20s", Subcatch[j].ID); for (p = 0; p < Nobjects[POLLUT]; p++) { x = Subcatch[j].totalLoad[p]; totals[p] += x; if ( Pollut[p].units == COUNT ) x = LOG10(x); fprintf(Frpt.file, "%14.3f", x); } } // --- print the total loading of each pollutant fprintf(Frpt.file, "\n %s", subcatchLine); for (p = 0; p < Nobjects[POLLUT]; p++) fprintf(Frpt.file, "%s", pollutLine); fprintf(Frpt.file, "\n System "); for (p = 0; p < Nobjects[POLLUT]; p++) { x = totals[p]; if ( Pollut[p].units == COUNT ) x = LOG10(x); fprintf(Frpt.file, "%14.3f", x); } free(totals); WRITE(""); } }