The routine sm_scan.prepare_scan_parameters() is meant to quickly check the self-consistency of parameters for a requested scan. It will make adjustments to parameters in the structure sm_par; this revised structure will therefore refer to a possible upcoming scan and no longer correctly describe the last scan taken, so one may want to make a copy of the last scan's sm_par in case the user decides not to acquire a new scan in favor of re-displaying the previous scan.
Before calling this routine, it's espected that the user will have provided values for the following sm_par elements: i32_fast_device, i32_slow_device, i32_n_fast_pixels, i32_n_slow_pixels, f32_fast_pixel_um, f32_slow_pixel_um, i32_bidirectional, and f32_dwell_msec. If a spectral scan is being requested, the user should also specify f32_start_ev and f32_stop_ev.
The routine sm_scan.prepare_scan_parameters() then does some rather obvious checks, such as whether the requested fast and slow axes scan devices (sm_par.i32_fast_device and sm_par.i32_slow_device) exist. We then set the private variables f32_fast_minstep_um and f32_slow_minstep_um to the minimum step size for the respective scan devices, and adjust the requested pixel sizes to be positive integer mutiples of these minimum values (we save these integer multiples as sm_scan private variables i32_fast_steps_per_pixel and i32_slow_steps_per_pixel, and aduust sm_par.f32_fast_pixel_um and sm_par.f32_slow_pixel_um accordingly).
If a stepping motor is the fast scan axis, we must check the requested pixel dwell time. The dwell time can be no shorter than i32_fast_steps_per_pixel divided by sm_scan.default_speed_sps(), so sm_par.f32_dwell_msec may end up being adjusted.
Now that we know the fast axis scan speed and pixel size, we calculate the private variables i32_fast_prescan_pixels and i32_fast_postscan_pixels required based on the scan speed and the motor acceleration (given by sm_scan.default_accel_spsps()). We can then calculate the starting and ending positions of the fast scan axis device as sm_par.f32_fast_start_um and sm_par.f32_fast_stop_um, and ditto for the slow axis positions. We then check the validity of these values with calls to sm_scan.check_moveto_micron() (see Sec. 13.5.1). If necessary, the number of pixels sm_par.i32_fast_pixels and sm_par.i32_slow_pixels will be adjusted to keep the scan within limits.
If we are to acquire a spectrum or a contrast scan (i.e., the fast axis device is SM_PAR_EV_DEVICE), we have a number of additional tasks. These are handled by calling the routine sm_scan.prepare_sgm_scan() as described in Sec. 13.4.1 below.