src/photon/temper.c
int photon_stream_temper_next(photon_stream_temper_t *pst) {
	int result;
	long long diff;

	while ( 1 ) {
		debug("Photons in the queue: %zu (of %zu)\n", 
				photon_queue_size(pst->queue),
				queue_capacity(pst->queue));

		if ( feof(pst->stream_in) ) {
			debug("EOF for stream_in.\n");
			if ( photon_queue_empty(pst->queue) ) {
				debug("Queue empty.\n");
				return(EOF);
			} else {
				debug("Popping a photon from queue.\n");
				photon_queue_pop(pst->queue, &(pst->current_photon));
				return(PC_SUCCESS);
			}
		} else {
			if ( pst->yielded_all_sorted ) {
				debug("Acquiring more photons for the queue.\n");
				result = photon_stream_temper_populate(pst);

				if ( result != PC_SUCCESS && result != EOF ) {
					return(result);
				}

				debug("Sorting the queue.\n");
				photon_queue_sort(pst->queue);
				pst->yielded_all_sorted = 0;
			} else {
				debug("Trying to pop a photon.\n");

				if ( photon_queue_empty(pst->queue) ) {
					pst->yielded_all_sorted = 1;
				} else {
					photon_queue_front(pst->queue, &(pst->left));
					photon_queue_back(pst->queue, &(pst->right));

					diff = pst->window_dim(pst->right) -
							pst->window_dim(pst->left);

//					result = (diff >= pst->offset_span);

					if ( pst->filter_afterpulsing &&
							pst->mode == MODE_T3 && 
							pst->left->t3.pulse == 
								pst->right->t3.pulse ) {
						debug("Filtering afterpulsing but still on a pulse.\n");
						pst->yielded_all_sorted = 1;
					} else if ( diff >= pst->offset_span ) {
						debug("Found a photon outside the offset bounds\n");
						photon_queue_pop(pst->queue, &(pst->current_photon));
						return(PC_SUCCESS);
					} else {
						debug("Within the offset bounds, get more photons\n");
						pst->yielded_all_sorted = 1;
					}
				}
			}
		}
	}
}
/* Yield a photon from the queue. If values can be taken from the queue,
 * yield them. Otherwise, fill it up with new values and sort it, then try
 * to yield a value.
 */
Yield a photon from the queue. If values can be taken from the queue,
yield them. Otherwise, fill it up with new values and sort it, then try
to yield a value.
Yield a photon from the queue . If values can be taken from the queue yield them . Otherwise fill it up with new values and sort it then try to yield a value .
int photon_stream_temper_next(photon_stream_temper_t *pst) {
	int result;
	long long diff;
	while ( 1 ) {
		debug("Photons in the queue: %zu (of %zu)\n", 
				photon_queue_size(pst->queue),
				queue_capacity(pst->queue));
		if ( feof(pst->stream_in) ) {
			debug("EOF for stream_in.\n");
			if ( photon_queue_empty(pst->queue) ) {
				debug("Queue empty.\n");
				return(EOF);
			} else {
				debug("Popping a photon from queue.\n");
				photon_queue_pop(pst->queue, &(pst->current_photon));
				return(PC_SUCCESS);
			}
		} else {
			if ( pst->yielded_all_sorted ) {
				debug("Acquiring more photons for the queue.\n");
				result = photon_stream_temper_populate(pst);
				if ( result != PC_SUCCESS && result != EOF ) {
					return(result);
				}
				debug("Sorting the queue.\n");
				photon_queue_sort(pst->queue);
				pst->yielded_all_sorted = 0;
			} else {
				debug("Trying to pop a photon.\n");
				if ( photon_queue_empty(pst->queue) ) {
					pst->yielded_all_sorted = 1;
				} else {
					photon_queue_front(pst->queue, &(pst->left));
					photon_queue_back(pst->queue, &(pst->right));
					diff = pst->window_dim(pst->right) -
							pst->window_dim(pst->left);
					if ( pst->filter_afterpulsing &&
							pst->mode == MODE_T3 && 
							pst->left->t3.pulse == 
								pst->right->t3.pulse ) {
						debug("Filtering afterpulsing but still on a pulse.\n");
						pst->yielded_all_sorted = 1;
					} else if ( diff >= pst->offset_span ) {
						debug("Found a photon outside the offset bounds\n");
						photon_queue_pop(pst->queue, &(pst->current_photon));
						return(PC_SUCCESS);
					} else {
						debug("Within the offset bounds, get more photons\n");
						pst->yielded_all_sorted = 1;
					}
				}
			}
		}
	}
}
int photon_stream_temper_next ( photon_stream_temper_t * pst ) { int result ; long long diff ; while ( 1 ) { debug ( " \n " , photon_queue_size ( pst -> queue ) , queue_capacity ( pst -> queue ) ) ; if ( feof ( pst -> stream_in ) ) { debug ( " \n " ) ; if ( photon_queue_empty ( pst -> queue ) ) { debug ( " \n " ) ; return ( EOF ) ; } else { debug ( " \n " ) ; photon_queue_pop ( pst -> queue , & ( pst -> current_photon ) ) ; return ( PC_SUCCESS ) ; } } else { if ( pst -> yielded_all_sorted ) { debug ( " \n " ) ; result = photon_stream_temper_populate ( pst ) ; if ( result != PC_SUCCESS && result != EOF ) { return ( result ) ; } debug ( " \n " ) ; photon_queue_sort ( pst -> queue ) ; pst -> yielded_all_sorted = 0 ; } else { debug ( " \n " ) ; if ( photon_queue_empty ( pst -> queue ) ) { pst -> yielded_all_sorted = 1 ; } else { photon_queue_front ( pst -> queue , & ( pst -> left ) ) ; photon_queue_back ( pst -> queue , & ( pst -> right ) ) ; diff = pst -> window_dim ( pst -> right ) - pst -> window_dim ( pst -> left ) ; if ( pst -> filter_afterpulsing && pst -> mode == MODE_T3 && pst -> left -> t3 . pulse == pst -> right -> t3 . pulse ) { debug ( " \n " ) ; pst -> yielded_all_sorted = 1 ; } else if ( diff >= pst -> offset_span ) { debug ( " \n " ) ; photon_queue_pop ( pst -> queue , & ( pst -> current_photon ) ) ; return ( PC_SUCCESS ) ; } else { debug ( " \n " ) ; pst -> yielded_all_sorted = 1 ; } } } } } }
Yield a photon from the queue.
Yield a photon from the queue .
//					result = (diff >= pst->offset_span);