@@ -84,7 +84,7 @@ public LoopCommandImpl(final LoopCommand command) throws Exception
8484 @ Override
8585 public long getWorkUnits ()
8686 {
87- final long iterations = 1 + Math . round ( Math . abs (( command . getEnd () - command . getStart ()) / command . getStepSize ()) );
87+ final long iterations = getNumSteps ( );
8888 long body_units = 0 ;
8989 for (ScanCommandImpl <?> command : implementation )
9090 body_units += command .getWorkUnits ();
@@ -128,21 +128,22 @@ private double getLoopStep()
128128 return step ;
129129 }
130130
131+ public int getNumSteps () {
132+ return (int )Math .ceil (Math .abs (((command .getEnd () - command .getStart ()) / command .getStepSize ()))) + 1 ;
133+ }
134+
131135 /** {@inheritDoc} */
132136 @ Override
133137 public void simulate (final SimulationContext context ) throws Exception
134138 {
135139 final SimulatedDevice device = context .getDevice (context .getMacros ().resolveMacros (command .getDeviceName ()));
136140
137- final double start = getLoopStart ();
138- final double end = getLoopEnd ();
139141 final double step = getLoopStep ();
140- if (step > 0 )
141- for (double value = start ; value <= end ; value += step )
142- simulateStep (context , device , value );
143- else // step is < 0, so stepping down
144- for (double value = end ; value >= start ; value += step )
145- simulateStep (context , device , value );
142+ // step is < 0 means we are stepping down
143+ double start = step < 0 ? getLoopEnd () : getLoopStart ();
144+ int num_steps = getNumSteps ();
145+ for (int i = 0 ; i < num_steps ; i ++)
146+ simulateStep (context , device , start + i * step );
146147 }
147148
148149 /** Simulate one step in the loop iteration
@@ -204,25 +205,13 @@ public void execute(final ScanContext context) throws Exception
204205 else
205206 condition = null ;
206207
207- double start = getLoopStart ();
208- double end = getLoopEnd ();
209208 double step = getLoopStep ();
210- if (step > 0 )
211- for (double value = start ; value <= end ; value += step )
212- {
213- executeStep (context , device , condition , readback , value );
214- // Permit changed step and end, but keep the direction
215- end = getLoopEnd ();
216- step = Math .abs (command .getStepSize ());
217- }
218- else // step is < 0, so stepping down
219- for (double value = end ; value >= start ; value += step )
220- {
221- executeStep (context , device , condition , readback , value );
222- // Permit changed step and start, but keep the direction
223- start = getLoopStart ();
224- step = - Math .abs (command .getStepSize ());
225- }
209+ // step is < 0 means we are stepping down
210+ double start = step < 0 ? getLoopEnd () : getLoopStart ();
211+ int num_steps = getNumSteps ();
212+
213+ for (int i = 0 ; i < num_steps ; i ++)
214+ executeStep (context , device , condition , readback , start + i * step );
226215 }
227216
228217 /** Execute one step of the loop
0 commit comments