src/statistics/intensity.c
intensity_photon_t *intensity_photon_alloc(unsigned int const channels, 
		int const mode) {
	intensity_photon_t *intensity = NULL;

	intensity = (intensity_photon_t *)malloc(sizeof(intensity_photon_t));

	if ( intensity == NULL ) {
		return(intensity);
	}

	if ( mode == MODE_T2 ) {
		intensity->channel_dim = t2_channel_dimension;
		intensity->window_dim = t2_window_dimension;
	} else if ( mode == MODE_T3 ) {
		intensity->channel_dim = t3_channel_dimension;
		intensity->window_dim = t3_window_dimension;
	} else {
		error("Invalid mode: %d\n", mode);
		intensity_photon_free(&intensity);
		return(intensity);
	}

	intensity->channels = channels;
	intensity->counts = counts_alloc(intensity->channels);

	if ( intensity->counts == NULL ) {
		intensity_photon_free(&intensity);
		return(intensity);
	}

	return(intensity);
}
/*
 * Due to the need to have a system where a photon stream can be analyzed in
 * a single pass, the intensity object has to operate in a somewhat 
 * counterintuiive fashion.
 *
 * A normal intensity procedure would look like:
 *
 * window = Window()
 * counts = Counts()
 *
 * for photon in photons:
 *     if photon in window:
 *         counts.increment(photon)
 *     elif photon before window:
 *         continue
 *     else:
 *         print(counts)
 *         counts.init()
 *         window.next()
 *
 * if not counts.empty():
 *     print(counts)
 *
 *
 * To perform this same method where photons can be added arbitrarily and the
 * result accessed as needed, do the following instead:
 *
 * window = Window()
 * intensity = Intensity()
 *
 * for photon in photons:
 *     intensity.push(photon)
 *     while intensity.available():
 *         print(intensity)
 *         intensity.next()
 *
 * intensity.flush()
 * while intensity.available():
 *     print(intensity)
 *     intensity.next()
 *
 *
 * The mechanisms for checking the validity of photons and incrementing
 * counts remain the same, but we have to keep track of state explicitly in
 * the intensity object, rather than implicitly in the procedure.
 */
Due to the need to have a system where a photon stream can be analyzed in
a single pass, the intensity object has to operate in a somewhat
counterintuiive fashion.

A normal intensity procedure would look like.

window = Window()
counts = Counts()





To perform this same method where photons can be added arbitrarily and the
result accessed as needed, do the following instead.

window = Window()
intensity = Intensity()





The mechanisms for checking the validity of photons and incrementing
counts remain the same, but we have to keep track of state explicitly in
the intensity object, rather than implicitly in the procedure.
Due to the need to have a system where a photon stream can be analyzed in a single pass the intensity object has to operate in a somewhat counterintuiive fashion . A normal intensity procedure would look like . window = Window () counts = Counts () To perform this same method where photons can be added arbitrarily and the result accessed as needed do the following instead . window = Window () intensity = Intensity () The mechanisms for checking the validity of photons and incrementing counts remain the same but we have to keep track of state explicitly in the intensity object rather than implicitly in the procedure .
intensity_photon_t *intensity_photon_alloc(unsigned int const channels, 
		int const mode) {
	intensity_photon_t *intensity = NULL;
	intensity = (intensity_photon_t *)malloc(sizeof(intensity_photon_t));
	if ( intensity == NULL ) {
		return(intensity);
	}
	if ( mode == MODE_T2 ) {
		intensity->channel_dim = t2_channel_dimension;
		intensity->window_dim = t2_window_dimension;
	} else if ( mode == MODE_T3 ) {
		intensity->channel_dim = t3_channel_dimension;
		intensity->window_dim = t3_window_dimension;
	} else {
		error("Invalid mode: %d\n", mode);
		intensity_photon_free(&intensity);
		return(intensity);
	}
	intensity->channels = channels;
	intensity->counts = counts_alloc(intensity->channels);
	if ( intensity->counts == NULL ) {
		intensity_photon_free(&intensity);
		return(intensity);
	}
	return(intensity);
}
intensity_photon_t * intensity_photon_alloc ( unsigned int const channels , int const mode ) { intensity_photon_t * intensity = NULL ; intensity = ( intensity_photon_t * ) malloc ( sizeof ( intensity_photon_t ) ) ; if ( intensity == NULL ) { return ( intensity ) ; } if ( mode == MODE_T2 ) { intensity -> channel_dim = t2_channel_dimension ; intensity -> window_dim = t2_window_dimension ; } else if ( mode == MODE_T3 ) { intensity -> channel_dim = t3_channel_dimension ; intensity -> window_dim = t3_window_dimension ; } else { error ( " \n " , mode ) ; intensity_photon_free ( & intensity ) ; return ( intensity ) ; } intensity -> channels = channels ; intensity -> counts = counts_alloc ( intensity -> channels ) ; if ( intensity -> counts == NULL ) { intensity_photon_free ( & intensity ) ; return ( intensity ) ; } return ( intensity ) ; }
Due to the need to have a system where a photon stream can be analyzed in
 a single pass, the intensity object has to operate in a somewhat
 counterintuiive fashion.
Due to the need to have a system where a photon stream can be analyzed in a single pass the intensity object has to operate in a somewhat counterintuiive fashion .