Skip to content

Commit

Permalink
Corrected amount Q is shifted by at each timestep to include num_dela…
Browse files Browse the repository at this point in the history
…y+num_time_delay_histo_ords, instead of just num_time_dealy_histo_ords. Also edited a print statement, and an error to provide assistance to user about how to fix error.
  • Loading branch information
Ben-Choat authored and madMatchstick committed Jan 12, 2024
1 parent 3e674e3 commit d28a857
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/topmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ extern void topmod(FILE *output_fptr, int nstep, int num_topodex_values,
current_time_step, *sump, *sumae, *sumq, stand_alone
added as function input parameters */
//shift Q array to align current time step
shift_Q(Q, num_time_delay_histo_ords);
shift_Q(Q, num_delay + num_time_delay_histo_ords);

double ex[num_topodex_values+1]; //+1 to maintin 1 based array indexing
//NJF TODO consider warning on all program limits here since this is essentially
Expand Down Expand Up @@ -331,6 +331,7 @@ for(ir=1;ir<=num_time_delay_histo_ords;ir++)
//Accumulate previous time dealyed flow with current
Q[in]+=(*Qout)*time_delay_histogram[ir];
}

//Add current time flow to mass balance variable
*sumq += Q[it];
/* BMI Adaption: replace nstep with current_time_step */
Expand Down Expand Up @@ -704,6 +705,8 @@ extern void calc_time_delay_histogram(int num_channels, double area,
sumar += (*time_delay_histogram)[1];
if(sumar < 0.99999 || sumar > 1.00001){
printf("ERROR: Histogram oridnates do not sum to 1.\n");
printf("Check that the correct number of values for cum_dist_area_with_dist and dist_from_outlet are provided.\n");
printf("The number of values for each variable should be equal to the number of channels (i.e., num_channels).\n\n");
exit(-1); //FIXME this fuction should probably return an error code
//and the error be handled elsewhere, not just an exit here...
}
Expand Down Expand Up @@ -757,6 +760,7 @@ extern void init_discharge_array(int *num_delay, double *Q0, double area,
in=(*num_delay)+i;
(*Q)[in]+=(*Q0)*(area-sum);
};

return;
}

Expand Down Expand Up @@ -943,7 +947,7 @@ printf("rv = %f\n", *rv);
printf("\nWater balance:\n");
printf("szm = %f\n", *szm);
printf("sr0 = %f\n", *sr0);
printf("t0 = %f\n", *t0);
printf("t0 = %f\n\n", *t0);

//NJF num_channels is the value provided (SHOULD COME FROM TREAD)
//Convert distance/area form to time delay histogram ordinates
Expand Down

0 comments on commit d28a857

Please sign in to comment.