00001
00005 #include <stdio.h>
00006 #include <bpm/bpm_messages.h>
00007 #include <bpm/bpm_process.h>
00008 #include <bpm/bpm_dsp.h>
00009
00010 int postprocess_waveform( bpmconf_t *bpm, bpmproc_t *proc, bpmcalib_t *cal,
00011 bpmproc_t *ampref, bpmproc_t *phaseref, unsigned int mode ) {
00012 char msg[80];
00013
00014 if ( ! bpm || ! proc || ! cal || ! ampref || ! phaseref ) {
00015 bpm_error( "Invalid pointer arguments in postprocess_waveform(...)",
00016 __FILE__, __LINE__ );
00017 return BPM_FAILURE;
00018 }
00019
00020
00021 proc->ddc_I = 0.;
00022 proc->ddc_Q = 0.;
00023 proc->ddc_pos = 0.;
00024 proc->ddc_slope = 0.;
00025
00026 if ( proc->ddc_success && ampref->ddc_success && phaseref->ddc_success ) {
00027
00028
00029 if ( get_IQ( proc->ddc_amp, proc->ddc_phase, ampref->ddc_amp, phaseref->ddc_phase,
00030 &(proc->ddc_Q), &(proc->ddc_I) ) == BPM_FAILURE ) {
00031 sprintf( msg, "Could not calculate I and Q for BPM %s in process_dipole(...)", bpm->name );
00032 bpm_error( msg, __FILE__, __LINE__ );
00033 proc->ddc_Q = 0.;
00034 proc->ddc_I = 0.;
00035 return BPM_FAILURE;
00036 }
00037
00038
00039 if ( !( mode & PROC_RAW_PHASE ) ) {
00040 proc->ddc_phase -= phaseref->ddc_phase;
00041 norm_phase( &(proc->ddc_phase) );
00042 }
00043
00044
00045 if ( get_pos( proc->ddc_Q, proc->ddc_I, cal->ddc_IQphase, cal->ddc_posscale,
00046 &(proc->ddc_pos) ) == BPM_FAILURE ) {
00047 sprintf( msg, "Could not get ddc position for BPM %s in process_dipole(...)", bpm->name );
00048 bpm_error( msg, __FILE__, __LINE__ );
00049 proc->ddc_pos = 0.;
00050 return BPM_FAILURE;
00051 }
00052 if ( get_slope( proc->ddc_Q, proc->ddc_I, cal->ddc_IQphase, cal->ddc_slopescale,
00053 &(proc->ddc_slope) ) == BPM_FAILURE ) {
00054 sprintf( msg, "Could not get ddc slope for BPM %s in process_dipole(...)", bpm->name );
00055 proc->ddc_slope = 0.;
00056 bpm_error( msg, __FILE__, __LINE__ );
00057 return BPM_FAILURE;
00058 }
00059
00060 }
00061
00062
00063
00064 proc->fit_I = 0.;
00065 proc->fit_Q = 0.;
00066 proc->fit_pos = 0.;
00067 proc->fit_slope = 0.;
00068
00069 if ( proc->fit_success && ampref->fit_success && phaseref->fit_success ) {
00070
00071
00072 if ( get_IQ( proc->fit_amp, proc->fit_phase, ampref->fit_amp, phaseref->fit_phase,
00073 &(proc->fit_Q), &(proc->fit_I) ) == BPM_FAILURE ) {
00074 sprintf( msg, "Could not calculate I and Q for BPM %s in process_dipole(...)", bpm->name );
00075 bpm_error( msg, __FILE__, __LINE__ );
00076 proc->fit_Q = 0.;
00077 proc->fit_I = 0.;
00078 return BPM_FAILURE;
00079 }
00080
00081
00082 if ( !( mode & PROC_RAW_PHASE ) ) {
00083 proc->fit_phase -= phaseref->fit_phase;
00084 norm_phase( &(proc->fit_phase) );
00085 }
00086
00087
00088 if ( get_pos( proc->fit_Q, proc->fit_I, cal->fit_IQphase, cal->fit_posscale,
00089 &(proc->fit_pos) ) == BPM_FAILURE ) {
00090 sprintf( msg, "Could not get fit position for BPM %s in process_dipole(...)", bpm->name );
00091 bpm_error( msg, __FILE__, __LINE__ );
00092 proc->fit_pos = 0.;
00093 return BPM_FAILURE;
00094 }
00095 if ( get_slope( proc->fit_Q, proc->fit_I, cal->fit_IQphase, cal->fit_slopescale,
00096 &(proc->fit_slope) ) == BPM_FAILURE ) {
00097 sprintf( msg, "Could not get fit slope for BPM %s in process_dipole(...)", bpm->name );
00098 proc->fit_slope = 0.;
00099 bpm_error( msg, __FILE__, __LINE__ );
00100 return BPM_FAILURE;
00101 }
00102
00103 }
00104
00105 return BPM_SUCCESS;
00106 }
00107