Small Scientific Programs
Unit Conversion Pipeline
Scale Measurements
A small scientific program often starts by converting raw measurements into analysis units.
Program
Play the program to choose the conversion scale and see the same readings summarized in different units.
unit_conversion_pipeline.f90
Replay: real traced execution (multi-file project)
program unit_conversion_pipeline_demo
implicit none
real :: readings(3)
real :: scale
real :: converted(3)
real :: total
readings = [120.0, 150.0, 180.0]
scale = 0.01
converted = readings * scale
total = sum(converted)
print '(F0.2)', total
end program unit_conversion_pipeline_demo
program unit_conversion_pipeline_demo
implicit none
real :: readings(3)
real :: scale
real :: converted(3)
real :: total
readings = [120.0, 150.0, 180.0]
scale = 0.001
converted = readings * scale
total = sum(converted)
print '(F0.2)', total
end program unit_conversion_pipeline_demo
program unit_conversion_pipeline_demo
implicit none
real :: readings(3)
real :: scale
real :: converted(3)
real :: total
readings = [120.0, 150.0, 180.0]
scale = 0.10
converted = readings * scale
total = sum(converted)
print '(F0.2)', total
end program unit_conversion_pipeline_demo
readings ← [120.0, 150.0, 180.0]
8readings = [120.0, 150.0, 180.0]9scale = 0.01values this step[120.0, 150.0, 180.0]readingsscale ← 0.010
8readings = [120.0, 150.0, 180.0]9scale = 0.0110converted = readings * scalevalues this step0.010scaleconverted ← [1.20, 1.50, 1.80]
9scale = 0.0110converted = readings * scale11total = sum(converted)values this step[1.20, 1.50, 1.80]converted[120.0, 150.0, 180.0]readings0.010scaletotal ← 4.50
10converted = readings * scale11total = sum(converted)12print '(F0.2)', totalvalues this step4.50total[1.20, 1.50, 1.80]convertedprint '(F0.2)', total
11 total = sum(converted)12 print '(F0.2)', total13end program unit_conversion_pipeline_demooutput4.50values this step4.50total
readings ← [120.0, 150.0, 180.0]
8readings = [120.0, 150.0, 180.0]9scale = 0.001values this step[120.0, 150.0, 180.0]readingsscale ← 0.001
8readings = [120.0, 150.0, 180.0]9scale = 0.00110converted = readings * scalevalues this step0.001scaleconverted ← [0.12, 0.15, 0.18]
9scale = 0.00110converted = readings * scale11total = sum(converted)values this step[0.12, 0.15, 0.18]converted[120.0, 150.0, 180.0]readings0.001scaletotal ← 0.45
10converted = readings * scale11total = sum(converted)12print '(F0.2)', totalvalues this step0.45total[0.12, 0.15, 0.18]convertedprint '(F0.2)', total
11 total = sum(converted)12 print '(F0.2)', total13end program unit_conversion_pipeline_demooutput0.45values this step0.45total
readings ← [120.0, 150.0, 180.0]
8readings = [120.0, 150.0, 180.0]9scale = 0.10values this step[120.0, 150.0, 180.0]readingsscale ← 0.100
8readings = [120.0, 150.0, 180.0]9scale = 0.1010converted = readings * scalevalues this step0.100scaleconverted ← [12.00, 15.00, 18.00]
9scale = 0.1010converted = readings * scale11total = sum(converted)values this step[12.00, 15.00, 18.00]converted[120.0, 150.0, 180.0]readings0.100scaletotal ← 45.00
10converted = readings * scale11total = sum(converted)12print '(F0.2)', totalvalues this step45.00total[12.00, 15.00, 18.00]convertedprint '(F0.2)', total
11 total = sum(converted)12 print '(F0.2)', total13end program unit_conversion_pipeline_demooutput45.00values this step45.00total
pipeline
A conversion step can be separated from the final summary.
array scale
`readings * scale` applies one scalar conversion to every element.
sum
`sum(converted)` reduces the converted array to one reported value.