From 8ae0df878c1c91b6a19f76b70eda0a4477e5f585 Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Mon, 24 Jul 2023 09:25:56 +0100 Subject: [PATCH 1/8] Adds source file and example --- .gitignore | 11 + DSPC_bilayer_example.py | 131 ++ RAT/SLDFunction.cpp | 261 +++ RAT/SLDFunction.h | 30 + RAT/abelesParallelPoints.cpp | 371 ++++ RAT/abelesParallelPoints.h | 30 + RAT/abelesSingle.cpp | 352 ++++ RAT/abelesSingle.h | 30 + RAT/acos.cpp | 97 + RAT/acos.h | 35 + RAT/adaptive.cpp | 1658 +++++++++++++++++ RAT/adaptive.h | 37 + RAT/allOrAny.cpp | 47 + RAT/allOrAny.h | 34 + RAT/allocateLayersForContrast.cpp | 86 + RAT/allocateLayersForContrast.h | 31 + RAT/allocateParamsToLayers.cpp | 72 + RAT/allocateParamsToLayers.h | 30 + RAT/applyBackgroundCorrection.cpp | 77 + RAT/applyBackgroundCorrection.h | 29 + RAT/asinh.cpp | 54 + RAT/asinh.h | 35 + RAT/asymconvstep.cpp | 171 ++ RAT/asymconvstep.h | 31 + RAT/backSort.cpp | 84 + RAT/backSort.h | 33 + RAT/blockedSummation.cpp | 175 ++ RAT/blockedSummation.h | 32 + RAT/bsearch.cpp | 52 + RAT/bsearch.h | 33 + RAT/callCppFunc.cpp | 85 + RAT/callCppFunc.h | 32 + RAT/callReflectivity.cpp | 544 ++++++ RAT/callReflectivity.h | 37 + RAT/chiSquared.cpp | 88 + RAT/chiSquared.h | 28 + RAT/coder_array.h | 796 ++++++++ RAT/coder_bounded_array.h | 37 + RAT/coder_setenv.c | 22 + RAT/coder_setenv.h | 15 + RAT/colon.cpp | 99 + RAT/colon.h | 31 + RAT/complexTimes.cpp | 141 ++ RAT/complexTimes.h | 35 + RAT/customModelClass.cpp | 483 +++++ RAT/customModelClass.h | 59 + RAT/dataResolutionPolly.cpp | 71 + RAT/dataResolutionPolly.h | 29 + RAT/dylib.hpp | 320 ++++ RAT/eml_erfcore.cpp | 179 ++ RAT/eml_erfcore.h | 29 + RAT/eml_mtimes_helper.cpp | 95 + RAT/eml_mtimes_helper.h | 34 + RAT/erf.cpp | 37 + RAT/erf.h | 31 + RAT/eventHelper.hpp | 79 + RAT/examples/main.cpp | 646 +++++++ RAT/examples/main.h | 49 + RAT/exp.cpp | 41 + RAT/exp.h | 29 + RAT/find.cpp | 62 + RAT/find.h | 31 + RAT/flip.cpp | 39 + RAT/flip.h | 30 + RAT/getenv.cpp | 41 + RAT/getenv.h | 30 + RAT/groupLayersMod.cpp | 183 ++ RAT/groupLayersMod.h | 30 + RAT/groupLayersModImaginary.cpp | 196 ++ RAT/groupLayersModImaginary.h | 30 + RAT/interp1.cpp | 134 ++ RAT/interp1.h | 32 + RAT/length.cpp | 39 + RAT/length.h | 32 + RAT/libManager.h | 48 + RAT/linspace.cpp | 105 ++ RAT/linspace.h | 31 + RAT/log1p.cpp | 42 + RAT/log1p.h | 35 + RAT/log2.cpp | 35 + RAT/log2.h | 29 + RAT/lower.cpp | 35 + RAT/lower.h | 30 + RAT/makeSLDProfileXY.cpp | 320 ++++ RAT/makeSLDProfileXY.h | 32 + RAT/makeSLDProfiles.cpp | 49 + RAT/makeSLDProfiles.h | 31 + RAT/mergesort.cpp | 110 ++ RAT/mergesort.h | 34 + RAT/minOrMax.cpp | 111 ++ RAT/minOrMax.h | 36 + RAT/nullAssignment.cpp | 57 + RAT/nullAssignment.h | 32 + RAT/reflectivityCalculation.cpp | 503 +++++ RAT/reflectivityCalculation.h | 29 + RAT/reflectivityCalculation_data.cpp | 32 + RAT/reflectivityCalculation_data.h | 28 + RAT/reflectivityCalculation_initialize.cpp | 29 + RAT/reflectivityCalculation_initialize.h | 26 + RAT/reflectivityCalculation_internal_types.h | 64 + RAT/reflectivityCalculation_rtwutil.cpp | 42 + RAT/reflectivityCalculation_rtwutil.h | 26 + RAT/reflectivityCalculation_terminate.cpp | 26 + RAT/reflectivityCalculation_terminate.h | 26 + RAT/reflectivityCalculation_types.h | 220 +++ RAT/relop.cpp | 54 + RAT/relop.h | 33 + RAT/repmat.cpp | 38 + RAT/repmat.h | 31 + RAT/resampleLayers.cpp | 69 + RAT/resampleLayers.h | 28 + RAT/resampleLayersReIm.cpp | 196 ++ RAT/resampleLayersReIm.h | 33 + RAT/resolutionPolly.cpp | 73 + RAT/resolutionPolly.h | 29 + RAT/rtGetInf.cpp | 49 + RAT/rtGetInf.h | 34 + RAT/rtGetNaN.cpp | 35 + RAT/rtGetNaN.h | 32 + RAT/rt_defines.h | 45 + RAT/rt_nonfinite.cpp | 31 + RAT/rt_nonfinite.h | 36 + RAT/rtwtypes.h | 42 + RAT/shiftData.cpp | 153 ++ RAT/shiftData.h | 30 + RAT/sortAscendLE.cpp | 38 + RAT/sortAscendLE.h | 32 + RAT/sortIdx.cpp | 48 + RAT/sortIdx.h | 34 + RAT/sortLE.cpp | 53 + RAT/sortLE.h | 34 + RAT/sortrows.cpp | 62 + RAT/sortrows.h | 30 + RAT/sqrt.cpp | 104 ++ RAT/sqrt.h | 35 + ...tandardTFCustomLayersParallelContrasts.cpp | 227 +++ RAT/standardTFCustomLayersParallelContrasts.h | 38 + RAT/standardTFCustomLayersParallelPoints.cpp | 191 ++ RAT/standardTFCustomLayersParallelPoints.h | 38 + ...dTFCustomLayersReflectivityCalculation.cpp | 152 ++ ...ardTFCustomLayersReflectivityCalculation.h | 34 + RAT/standardTFCustomLayersSingle.cpp | 193 ++ RAT/standardTFCustomLayersSingle.h | 38 + RAT/standardTFCustomXYParallelContrasts.cpp | 232 +++ RAT/standardTFCustomXYParallelContrasts.h | 38 + RAT/standardTFCustomXYParallelPoints.cpp | 204 ++ RAT/standardTFCustomXYParallelPoints.h | 38 + ...ndardTFCustomXYReflectivityCalculation.cpp | 152 ++ ...tandardTFCustomXYReflectivityCalculation.h | 34 + RAT/standardTFCustomXYSingle.cpp | 202 ++ RAT/standardTFCustomXYSingle.h | 38 + RAT/standardTFLayersCore.cpp | 683 +++++++ RAT/standardTFLayersCore.h | 48 + RAT/standardTFReflectivityCalculation.cpp | 151 ++ RAT/standardTFReflectivityCalculation.h | 34 + ...ndardTFStandardLayersParallelContrasts.cpp | 241 +++ ...tandardTFStandardLayersParallelContrasts.h | 38 + ...standardTFStandardLayersParallelPoints.cpp | 204 ++ RAT/standardTFStandardLayersParallelPoints.h | 38 + ...FStandardLayersReflectivityCalculation.cpp | 154 ++ ...dTFStandardLayersReflectivityCalculation.h | 34 + RAT/standardTFStandardLayersSingle.cpp | 208 +++ RAT/standardTFStandardLayersSingle.h | 38 + RAT/strcmp.cpp | 341 ++++ RAT/strcmp.h | 42 + RAT/sum.cpp | 36 + RAT/sum.h | 30 + RAT/tmwtypes.h | 888 +++++++++ RAT/triggerEvent.cpp | 253 +++ RAT/triggerEvent.h | 37 + RAT/unsafeSxfun.cpp | 67 + RAT/unsafeSxfun.h | 28 + README.md | 8 + data/data1.csv | 82 + data/data2.csv | 82 + rat.cpp | 762 ++++++++ requirements.txt | 3 + 177 files changed, 19432 insertions(+) create mode 100644 .gitignore create mode 100644 DSPC_bilayer_example.py create mode 100644 RAT/SLDFunction.cpp create mode 100644 RAT/SLDFunction.h create mode 100644 RAT/abelesParallelPoints.cpp create mode 100644 RAT/abelesParallelPoints.h create mode 100644 RAT/abelesSingle.cpp create mode 100644 RAT/abelesSingle.h create mode 100644 RAT/acos.cpp create mode 100644 RAT/acos.h create mode 100644 RAT/adaptive.cpp create mode 100644 RAT/adaptive.h create mode 100644 RAT/allOrAny.cpp create mode 100644 RAT/allOrAny.h create mode 100644 RAT/allocateLayersForContrast.cpp create mode 100644 RAT/allocateLayersForContrast.h create mode 100644 RAT/allocateParamsToLayers.cpp create mode 100644 RAT/allocateParamsToLayers.h create mode 100644 RAT/applyBackgroundCorrection.cpp create mode 100644 RAT/applyBackgroundCorrection.h create mode 100644 RAT/asinh.cpp create mode 100644 RAT/asinh.h create mode 100644 RAT/asymconvstep.cpp create mode 100644 RAT/asymconvstep.h create mode 100644 RAT/backSort.cpp create mode 100644 RAT/backSort.h create mode 100644 RAT/blockedSummation.cpp create mode 100644 RAT/blockedSummation.h create mode 100644 RAT/bsearch.cpp create mode 100644 RAT/bsearch.h create mode 100644 RAT/callCppFunc.cpp create mode 100644 RAT/callCppFunc.h create mode 100644 RAT/callReflectivity.cpp create mode 100644 RAT/callReflectivity.h create mode 100644 RAT/chiSquared.cpp create mode 100644 RAT/chiSquared.h create mode 100644 RAT/coder_array.h create mode 100644 RAT/coder_bounded_array.h create mode 100644 RAT/coder_setenv.c create mode 100644 RAT/coder_setenv.h create mode 100644 RAT/colon.cpp create mode 100644 RAT/colon.h create mode 100644 RAT/complexTimes.cpp create mode 100644 RAT/complexTimes.h create mode 100644 RAT/customModelClass.cpp create mode 100644 RAT/customModelClass.h create mode 100644 RAT/dataResolutionPolly.cpp create mode 100644 RAT/dataResolutionPolly.h create mode 100644 RAT/dylib.hpp create mode 100644 RAT/eml_erfcore.cpp create mode 100644 RAT/eml_erfcore.h create mode 100644 RAT/eml_mtimes_helper.cpp create mode 100644 RAT/eml_mtimes_helper.h create mode 100644 RAT/erf.cpp create mode 100644 RAT/erf.h create mode 100644 RAT/eventHelper.hpp create mode 100644 RAT/examples/main.cpp create mode 100644 RAT/examples/main.h create mode 100644 RAT/exp.cpp create mode 100644 RAT/exp.h create mode 100644 RAT/find.cpp create mode 100644 RAT/find.h create mode 100644 RAT/flip.cpp create mode 100644 RAT/flip.h create mode 100644 RAT/getenv.cpp create mode 100644 RAT/getenv.h create mode 100644 RAT/groupLayersMod.cpp create mode 100644 RAT/groupLayersMod.h create mode 100644 RAT/groupLayersModImaginary.cpp create mode 100644 RAT/groupLayersModImaginary.h create mode 100644 RAT/interp1.cpp create mode 100644 RAT/interp1.h create mode 100644 RAT/length.cpp create mode 100644 RAT/length.h create mode 100644 RAT/libManager.h create mode 100644 RAT/linspace.cpp create mode 100644 RAT/linspace.h create mode 100644 RAT/log1p.cpp create mode 100644 RAT/log1p.h create mode 100644 RAT/log2.cpp create mode 100644 RAT/log2.h create mode 100644 RAT/lower.cpp create mode 100644 RAT/lower.h create mode 100644 RAT/makeSLDProfileXY.cpp create mode 100644 RAT/makeSLDProfileXY.h create mode 100644 RAT/makeSLDProfiles.cpp create mode 100644 RAT/makeSLDProfiles.h create mode 100644 RAT/mergesort.cpp create mode 100644 RAT/mergesort.h create mode 100644 RAT/minOrMax.cpp create mode 100644 RAT/minOrMax.h create mode 100644 RAT/nullAssignment.cpp create mode 100644 RAT/nullAssignment.h create mode 100644 RAT/reflectivityCalculation.cpp create mode 100644 RAT/reflectivityCalculation.h create mode 100644 RAT/reflectivityCalculation_data.cpp create mode 100644 RAT/reflectivityCalculation_data.h create mode 100644 RAT/reflectivityCalculation_initialize.cpp create mode 100644 RAT/reflectivityCalculation_initialize.h create mode 100644 RAT/reflectivityCalculation_internal_types.h create mode 100644 RAT/reflectivityCalculation_rtwutil.cpp create mode 100644 RAT/reflectivityCalculation_rtwutil.h create mode 100644 RAT/reflectivityCalculation_terminate.cpp create mode 100644 RAT/reflectivityCalculation_terminate.h create mode 100644 RAT/reflectivityCalculation_types.h create mode 100644 RAT/relop.cpp create mode 100644 RAT/relop.h create mode 100644 RAT/repmat.cpp create mode 100644 RAT/repmat.h create mode 100644 RAT/resampleLayers.cpp create mode 100644 RAT/resampleLayers.h create mode 100644 RAT/resampleLayersReIm.cpp create mode 100644 RAT/resampleLayersReIm.h create mode 100644 RAT/resolutionPolly.cpp create mode 100644 RAT/resolutionPolly.h create mode 100644 RAT/rtGetInf.cpp create mode 100644 RAT/rtGetInf.h create mode 100644 RAT/rtGetNaN.cpp create mode 100644 RAT/rtGetNaN.h create mode 100644 RAT/rt_defines.h create mode 100644 RAT/rt_nonfinite.cpp create mode 100644 RAT/rt_nonfinite.h create mode 100644 RAT/rtwtypes.h create mode 100644 RAT/shiftData.cpp create mode 100644 RAT/shiftData.h create mode 100644 RAT/sortAscendLE.cpp create mode 100644 RAT/sortAscendLE.h create mode 100644 RAT/sortIdx.cpp create mode 100644 RAT/sortIdx.h create mode 100644 RAT/sortLE.cpp create mode 100644 RAT/sortLE.h create mode 100644 RAT/sortrows.cpp create mode 100644 RAT/sortrows.h create mode 100644 RAT/sqrt.cpp create mode 100644 RAT/sqrt.h create mode 100644 RAT/standardTFCustomLayersParallelContrasts.cpp create mode 100644 RAT/standardTFCustomLayersParallelContrasts.h create mode 100644 RAT/standardTFCustomLayersParallelPoints.cpp create mode 100644 RAT/standardTFCustomLayersParallelPoints.h create mode 100644 RAT/standardTFCustomLayersReflectivityCalculation.cpp create mode 100644 RAT/standardTFCustomLayersReflectivityCalculation.h create mode 100644 RAT/standardTFCustomLayersSingle.cpp create mode 100644 RAT/standardTFCustomLayersSingle.h create mode 100644 RAT/standardTFCustomXYParallelContrasts.cpp create mode 100644 RAT/standardTFCustomXYParallelContrasts.h create mode 100644 RAT/standardTFCustomXYParallelPoints.cpp create mode 100644 RAT/standardTFCustomXYParallelPoints.h create mode 100644 RAT/standardTFCustomXYReflectivityCalculation.cpp create mode 100644 RAT/standardTFCustomXYReflectivityCalculation.h create mode 100644 RAT/standardTFCustomXYSingle.cpp create mode 100644 RAT/standardTFCustomXYSingle.h create mode 100644 RAT/standardTFLayersCore.cpp create mode 100644 RAT/standardTFLayersCore.h create mode 100644 RAT/standardTFReflectivityCalculation.cpp create mode 100644 RAT/standardTFReflectivityCalculation.h create mode 100644 RAT/standardTFStandardLayersParallelContrasts.cpp create mode 100644 RAT/standardTFStandardLayersParallelContrasts.h create mode 100644 RAT/standardTFStandardLayersParallelPoints.cpp create mode 100644 RAT/standardTFStandardLayersParallelPoints.h create mode 100644 RAT/standardTFStandardLayersReflectivityCalculation.cpp create mode 100644 RAT/standardTFStandardLayersReflectivityCalculation.h create mode 100644 RAT/standardTFStandardLayersSingle.cpp create mode 100644 RAT/standardTFStandardLayersSingle.h create mode 100644 RAT/strcmp.cpp create mode 100644 RAT/strcmp.h create mode 100644 RAT/sum.cpp create mode 100644 RAT/sum.h create mode 100644 RAT/tmwtypes.h create mode 100644 RAT/triggerEvent.cpp create mode 100644 RAT/triggerEvent.h create mode 100644 RAT/unsafeSxfun.cpp create mode 100644 RAT/unsafeSxfun.h create mode 100644 README.md create mode 100644 data/data1.csv create mode 100644 data/data2.csv create mode 100644 rat.cpp create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..dd0d153c --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Editor Folders +.idea +.vscode + +# Build +*.rat.cpp \ No newline at end of file diff --git a/DSPC_bilayer_example.py b/DSPC_bilayer_example.py new file mode 100644 index 00000000..af8b3b55 --- /dev/null +++ b/DSPC_bilayer_example.py @@ -0,0 +1,131 @@ +import cppimport +import numpy as np + +rat = cppimport.imp("rat") + +if __name__ == '__main__': + #------------------------------------------------------------------------------------ + # Control + control = rat.Control() + problem = rat.ProblemDefinition() + limits = rat.Limits() + cells = rat.Cells() + + control.proc = 'calculate' + control.para = 'points' + control.display = 'iter' + control.calcSld = False + control.resamPars = [0.9000, 50] + + control.checks.params_fitYesNo = [1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1] + control.checks.backs_fitYesNo = np.ones((2)) + control.checks.shifts_fitYesNo = [0] + control.checks.scales_fitYesNo = [0, 0] + control.checks.nbairs_fitYesNo = [0] + control.checks.nbsubs_fitYesNo = [0, 0] + control.checks.resol_fitYesNo = [0] + + #------------------------------------------------------------------------------------ + # ProblemDef + problem.contrastBacks = [1, 2] + problem.contrastBacksType = [1, 1] + problem.TF = 'non polarised' + problem.resample = [0, 0] + problem.dataPresent = [1, 1] + problem.oilChiDataPresent = [0, 0] + problem.numberOfContrasts = 2 + problem.geometry = 'substrate/liquid' + problem.useImaginary = False + problem.contrastShifts = [1, 1] + problem.contrastScales = [1, 1] + problem.contrastNbas = [1, 1] + problem.contrastNbss = [1, 2] + problem.contrastRes = [1, 1] + problem.backs = [2.28525214157571e-06, 3.10246417982706e-06] + problem.shifts = [0] + problem.sf = [0.102860901766649, 0.151378164199993] + problem.nba = [2.07399989449186e-06] + problem.nbs = [5.98067802097389e-06, 2.21000000000000e-06] + problem.res = [0.0300] + problem.params = [5.08929897223891, 19.2830495317839, 3.39317612702561e-06, 21.5451088784623, -4.01001212540204e-07, 1.24963548580913, 8.09797576127018, 20.3854719276630, + 0, 5.79580504624961, 1.75686012656988e-06, 10.0916971312704, 11.7066921282983, 1.47000000000000e-06, 5.63694566866001, 17.8733566725932, -4.61089672942576e-07, + 17.8556570737753, 41.4142113901161, 100, 25.6893163532023] + problem.numberOfLayers = 6 + problem.modelType = 'standard layers' + problem.contrastCustomFiles = [np.NAN, np.NaN] + problem.contrastDomainRatios = [0, 0] + problem.domainRatio = [] + problem.numberOfDomainContrasts = 0 + problem.domainContrastCustomFiles = [] + problem.fitpars = [5.08929897223891, 19.2830495317839, 21.5451088784623, 1.24963548580913, 8.09797576127018, + 20.3854719276630, 5.79580504624961, 10.0916971312704, 11.7066921282983, 5.63694566866001, + 17.8733566725932, 17.8556570737753, 41.4142113901161, 25.6893163532023, 2.28525214157571e-06, + 3.10246417982706e-06] + problem.otherpars = [3.39317612702561e-06, -4.01001212540204e-07, 0, 1.75686012656988e-06, 1.47e-06, -4.61089672942576e-07, + 100, 0.102860901766649, 0.151378164199993,0, 2.07399989449186e-06, 5.98067802097389e-06, 2.21e-06, 0.030] + problem.fitconstr = [[2, 8], [5, 60], [15, 35], [1, 50], [1, 15], [10, 28], [5, 17], + [10, 50], [7, 17], [2, 15], [14, 22], [10, 50], [10, 50], [0, 60], [5.0e-10, 7.0e-06], + [1.0e-10, 4.99999987368938e-06]] + problem.otherconstr = [[3.39e-06, 3.41e-06], [-5.0e-07, -3.0e-07], [0, 1.0e-09], [1.0e-07, 2.0e-06], [5.0e-07, 1.5e-06], + [-5.0e-07, 0], [99.9, 100], [0.050, 0.20], [0.050, 0.20], [-0.00010, 0.00010], [2.0e-06, 2.1e-06], + [5.50000004295725e-06, 6.4e-06], [2.0e-06, 4.99999987368938e-06], [0.010, 0.050]] + + #------------------------------------------------------------------------------------ + # Limits + limits.params = [[2, 8], [5, 60], [0, 0], [15, 35], [-0, -0], [1, 50], [1, 15], + [10, 28], [0, 0], [5, 17], [0, 0], [10, 50], [7, 17], [0, 0], [2, 15], + [14, 22], [-0, 0], [10, 50], [10, 50], [99.9,100], [0, 60]] + limits.backs = [[5.0000e-10, 7.0000e-06], [1.0000e-10, 5.0000e-06]] + limits.scales = [[0.0500, 0.2000], [0.0500, 0.2000]] + limits.shifts = [[-1.0000e-04, 1.0000e-04]] + limits.nba = [[2.0000e-06, 2.1000e-06]] + limits.nbs = [[5.5000e-06, 6.4000e-06], [2.0000e-06, 5.0000e-06]] + limits.res = [[0.0100, 0.0500]] + limits.domainRatio = [] + + #------------------------------------------------------------------------------------- + # Cells + cells.f1 = [[0, 1], [0, 1]] + cells.f2 = [np.loadtxt('data/data1.csv', delimiter=','), + np.loadtxt('data/data2.csv', delimiter=',')] + cells.f3 = [[0.011403, 0.59342], [0.011403, 0.59342]] + cells.f4 = [[0.011403, 0.70956], [0.011403, 0.59342]] + cells.f5 = [[1, 2, 3, 4, 5, 6, 6, 5], [1, 2, 3, 4, 5, 6, 6, 5]] + cells.f6 = [[2, 3, 1, 21, 2], + [4, 5, 7, 6, 2], + [10, 11, 7, 12, 2], + [8, 9, 15, 20, 2], + [13, 14, 15, 19, 2], + [16, 17, 15, 18, 2]] + cells.f7 = ['Substrate Roughness', 'Oxide thick', 'Oxide SLD', 'Sam tails thick', 'Sam tails SLD', + 'Sam tails hydration', 'Sam rough', 'cw thick', 'cw SLD', 'SAM head thick', 'SAM head SLD', + 'SAM head hydration', 'Bilayer head thick', 'Bilayer head SLD', 'Bilayer rough', + 'Bilayer tails thick', 'Bilayer tails SLD', 'Bilayer tails hydr', 'Bilayer heads hydr', 'cw hydration', 'Oxide Hydration'] + cells.f8 = ['Backs parameter 1', 'Backs parameter 2'] + cells.f9 = ['Scalefactor 1', 'Scalefactor 2'] + cells.f10 = ['Qz shift 1'] + cells.f11 = ['Air'] + cells.f12 = ['D2O', 'SMW'] + cells.f13 = ['Resolution par 1'] + # cells.f14 = [['', '', '']] + cells.f15 = ['constant', 'constant'] + cells.f16 = ['constant'] + # cells.f17 = [[], []] + # cells.f18 = [] + # cells.f19 = [] + # cells.f20 = [] + + problem, output = rat.reflectivityCalculation(problem, cells, limits, control) + + print(problem.ssubs) + print(problem.backgrounds) + print(problem.qshifts) + print(problem.scalefactors) + print(problem.nbairs) + print(problem.nbsubs) + print(problem.resolutions) + print(problem.calculations.all_chis) + print(problem.calculations.sum_chi) + print(problem.allSubRough) + print(problem.resample) + \ No newline at end of file diff --git a/RAT/SLDFunction.cpp b/RAT/SLDFunction.cpp new file mode 100644 index 00000000..8ea4073a --- /dev/null +++ b/RAT/SLDFunction.cpp @@ -0,0 +1,261 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// SLDFunction.cpp +// +// Code generation for function 'SLDFunction' +// + +// Include files +#include "SLDFunction.h" +#include "find.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void SLDFunction(real_T x, const real_T SLD_data[], const int32_T SLD_size[2], + real_T sldVal_data[], int32_T *sldVal_size) + { + ::coder::array b_i; + ::coder::array c_i; + ::coder::array r; + ::coder::array c_SLD_data; + ::coder::array d_SLD_data; + ::coder::array e_SLD_data; + ::coder::array f_SLD_data; + ::coder::array g_SLD_data; + int32_T loop_ub; + boolean_T b_SLD_data[1000]; + + // sldVal = SLDFunction(x,SLD) + // SLD = [x rho;....xn rho] + // x = value in Angstrom. + // + // This function returns the SLD (y) value associated with the + // supplied value of x. SLD is a two column, XY array defining an + // SLD profile. This function interpolates the SLD profile + // to return the SLD at the specific value of X. X can be a vector of + // multiple points. + // + // (c) Arwel Hughes 2019. + // Last modified - AVH, 26/11/19. + // global sldProfile + // + // SLD = sldProfile; + // SLD = getappdata(0,'SLDFunctionSLD'); + loop_ub = SLD_size[0]; + for (int32_T i{0}; i < loop_ub; i++) { + b_SLD_data[i] = (SLD_data[i] == x); + } + + c_SLD_data.set(&b_SLD_data[0], SLD_size[0]); + coder::eml_find(c_SLD_data, r); + b_i.set_size(r.size(0)); + loop_ub = r.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_i[i] = r[i]; + } + + if (b_i.size(0) != 0) { + *sldVal_size = b_i.size(0); + loop_ub = b_i.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + sldVal_data[i] = SLD_data[(b_i[i] + SLD_size[0]) - 1]; + } + } else { + real_T deltaY; + int32_T belowVals_data[1000]; + int32_T belowVals_size; + loop_ub = SLD_size[0]; + for (int32_T i{0}; i < loop_ub; i++) { + b_SLD_data[i] = (x > SLD_data[i]); + } + + d_SLD_data.set(&b_SLD_data[0], SLD_size[0]); + coder::eml_find(d_SLD_data, r); + b_i.set_size(r.size(0)); + loop_ub = r.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_i[i] = r[i]; + } + + loop_ub = SLD_size[0]; + for (int32_T i{0}; i < loop_ub; i++) { + b_SLD_data[i] = (x > SLD_data[i]); + } + + e_SLD_data.set(&b_SLD_data[0], SLD_size[0]); + coder::eml_find(e_SLD_data, r); + belowVals_size = r.size(0); + loop_ub = r.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + belowVals_data[i] = r[i]; + } + + loop_ub = SLD_size[0]; + for (int32_T i{0}; i < loop_ub; i++) { + b_SLD_data[i] = (x < SLD_data[i]); + } + + f_SLD_data.set(&b_SLD_data[0], SLD_size[0]); + coder::eml_find(f_SLD_data, r); + c_i.set_size(r.size(0)); + loop_ub = r.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + c_i[i] = r[i]; + } + + loop_ub = SLD_size[0]; + for (int32_T i{0}; i < loop_ub; i++) { + b_SLD_data[i] = (x < SLD_data[i]); + } + + g_SLD_data.set(&b_SLD_data[0], SLD_size[0]); + coder::eml_find(g_SLD_data, r); + belowVals_size = belowVals_data[belowVals_size - 1]; + deltaY = (x - SLD_data[b_i[b_i.size(0) - 1] - 1]) * (std::abs(SLD_data[(r + [0] + SLD_size[0]) - 1] - SLD_data[(belowVals_size + SLD_size[0]) - 1]) / + (SLD_data[r[0] - 1] - SLD_data[belowVals_size - 1])); + if (SLD_data[(b_i[b_i.size(0) - 1] + SLD_size[0]) - 1] < SLD_data[(c_i[0] + + SLD_size[0]) - 1]) { + *sldVal_size = 1; + sldVal_data[0] = SLD_data[(b_i[b_i.size(0) - 1] + SLD_size[0]) - 1] + + deltaY; + } else { + *sldVal_size = 1; + sldVal_data[0] = SLD_data[(b_i[b_i.size(0) - 1] + SLD_size[0]) - 1] - + deltaY; + } + + // sldVal = interp1(z,rho,x); + } + } + + void SLDFunction(real_T x, const ::coder::array &SLD, ::coder:: + array &sldVal) + { + ::coder::array b_i; + ::coder::array c_i; + ::coder::array r; + ::coder::array b_SLD_data; + ::coder::array c_SLD_data; + ::coder::array d_SLD_data; + ::coder::array e_SLD_data; + ::coder::array f_SLD_data; + int32_T SLD_size; + int32_T loop_ub; + boolean_T SLD_data[10000]; + + // sldVal = SLDFunction(x,SLD) + // SLD = [x rho;....xn rho] + // x = value in Angstrom. + // + // This function returns the SLD (y) value associated with the + // supplied value of x. SLD is a two column, XY array defining an + // SLD profile. This function interpolates the SLD profile + // to return the SLD at the specific value of X. X can be a vector of + // multiple points. + // + // (c) Arwel Hughes 2019. + // Last modified - AVH, 26/11/19. + // global sldProfile + // + // SLD = sldProfile; + // SLD = getappdata(0,'SLDFunctionSLD'); + SLD_size = SLD.size(0); + loop_ub = SLD.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + SLD_data[i] = (SLD[i] == x); + } + + b_SLD_data.set(&SLD_data[0], SLD_size); + coder::eml_find(b_SLD_data, r); + b_i.set_size(r.size(0)); + loop_ub = r.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_i[i] = r[i]; + } + + if (b_i.size(0) != 0) { + sldVal.set_size(b_i.size(0)); + loop_ub = b_i.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + sldVal[i] = SLD[(b_i[i] + SLD.size(0)) - 1]; + } + } else { + real_T deltaY; + int32_T belowVals_data[10000]; + int32_T belowVals_size; + SLD_size = SLD.size(0); + loop_ub = SLD.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + SLD_data[i] = (x > SLD[i]); + } + + c_SLD_data.set(&SLD_data[0], SLD_size); + coder::eml_find(c_SLD_data, r); + b_i.set_size(r.size(0)); + loop_ub = r.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_i[i] = r[i]; + } + + SLD_size = SLD.size(0); + loop_ub = SLD.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + SLD_data[i] = (x > SLD[i]); + } + + d_SLD_data.set(&SLD_data[0], SLD_size); + coder::eml_find(d_SLD_data, r); + belowVals_size = r.size(0); + loop_ub = r.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + belowVals_data[i] = r[i]; + } + + SLD_size = SLD.size(0); + loop_ub = SLD.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + SLD_data[i] = (x < SLD[i]); + } + + e_SLD_data.set(&SLD_data[0], SLD_size); + coder::eml_find(e_SLD_data, r); + c_i.set_size(r.size(0)); + loop_ub = r.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + c_i[i] = r[i]; + } + + SLD_size = SLD.size(0); + loop_ub = SLD.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + SLD_data[i] = (x < SLD[i]); + } + + f_SLD_data.set(&SLD_data[0], SLD_size); + coder::eml_find(f_SLD_data, r); + deltaY = (x - SLD[b_i[b_i.size(0) - 1] - 1]) * (std::abs(SLD[(r[0] + + SLD.size(0)) - 1] - SLD[(belowVals_data[belowVals_size - 1] + SLD.size(0)) + - 1]) / (SLD[r[0] - 1] - SLD[belowVals_data[belowVals_size - 1] - 1])); + if (SLD[(b_i[b_i.size(0) - 1] + SLD.size(0)) - 1] < SLD[(c_i[0] + SLD.size + (0)) - 1]) { + sldVal.set_size(1); + sldVal[0] = SLD[(b_i[b_i.size(0) - 1] + SLD.size(0)) - 1] + deltaY; + } else { + sldVal.set_size(1); + sldVal[0] = SLD[(b_i[b_i.size(0) - 1] + SLD.size(0)) - 1] - deltaY; + } + + // sldVal = interp1(z,rho,x); + } + } +} + +// End of code generation (SLDFunction.cpp) diff --git a/RAT/SLDFunction.h b/RAT/SLDFunction.h new file mode 100644 index 00000000..4e9625fd --- /dev/null +++ b/RAT/SLDFunction.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// SLDFunction.h +// +// Code generation for function 'SLDFunction' +// +#ifndef SLDFUNCTION_H +#define SLDFUNCTION_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void SLDFunction(real_T x, const real_T SLD_data[], const int32_T SLD_size[2], + real_T sldVal_data[], int32_T *sldVal_size); + void SLDFunction(real_T x, const ::coder::array &SLD, ::coder:: + array &sldVal); +} + +#endif + +// End of code generation (SLDFunction.h) diff --git a/RAT/abelesParallelPoints.cpp b/RAT/abelesParallelPoints.cpp new file mode 100644 index 00000000..cc2a77e7 --- /dev/null +++ b/RAT/abelesParallelPoints.cpp @@ -0,0 +1,371 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// abelesParallelPoints.cpp +// +// Code generation for function 'abelesParallelPoints' +// + +// Include files +#include "abelesParallelPoints.h" +#include "exp.h" +#include "reflectivityCalculation_data.h" +#include "reflectivityCalculation_rtwutil.h" +#include "rt_nonfinite.h" +#include "sqrt.h" +#include "coder_array.h" +#include "omp.h" +#include + +// Function Declarations +namespace RAT +{ + static creal_T findkn(real_T k0, const creal_T sld); +} + +// Function Definitions +namespace RAT +{ + static creal_T findkn(real_T k0, const creal_T sld) + { + creal_T kn; + kn.re = k0 * k0 - 12.566370614359172 * sld.re; + kn.im = 0.0 - 12.566370614359172 * sld.im; + coder::internal::scalar::b_sqrt(&kn); + return kn; + } + + void abelesParallelPoints(const ::coder::array &q, real_T N, const + ::coder::array &layers_thick, const ::coder::array + &layers_rho, const ::coder::array &layers_sig, ::coder::array< + real_T, 1U> &ref) + { + creal_T M_n[2][2]; + creal_T M_res[2][2]; + creal_T M_tot[2][2]; + creal_T M_n_tmp; + creal_T beta; + creal_T bulk_in_SLD; + creal_T denom1; + creal_T denom_n; + creal_T err1; + creal_T err_n; + creal_T k1; + creal_T kn_ptr; + creal_T knp1; + creal_T nom1; + creal_T nom_n; + creal_T r01; + creal_T r_n_np1; + creal_T sld_1; + creal_T sld_np1; + real_T M_tot_re_tmp; + real_T R; + real_T b_M_tot_re_tmp; + real_T brm; + real_T c_M_tot_re_tmp; + real_T d; + real_T d1; + real_T d_M_tot_re_tmp; + real_T im; + real_T k0; + real_T nom_n_re; + real_T sigmasqrd; + real_T sigmasqrd_tmp; + int32_T i1; + int32_T i2; + int32_T loop_ub; + int32_T n; + ref.set_size(q.size(0)); + loop_ub = q.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + ref[i] = 0.0; + } + + loop_ub = q.size(0) - 1; + +#pragma omp parallel for \ + num_threads(omp_get_max_threads()) \ + private(beta,r_n_np1,err_n,sigmasqrd,denom_n,nom_n,knp1,sld_np1,r01,err1,denom1,nom1,k1,sld_1,R,k0,bulk_in_SLD,kn_ptr,M_res,M_n,M_tot,i1,n,nom_n_re,sigmasqrd_tmp,brm,im,M_n_tmp,d,d1,i2,M_tot_re_tmp,b_M_tot_re_tmp,c_M_tot_re_tmp,d_M_tot_re_tmp) + + for (int32_T points = 0; points <= loop_ub; points++) { + M_tot[0][0].re = 0.0; + M_tot[0][0].im = 0.0; + M_res[0][0].re = 0.0; + M_res[0][0].im = 0.0; + M_tot[0][1].re = 0.0; + M_tot[0][1].im = 0.0; + M_res[0][1].re = 0.0; + M_res[0][1].im = 0.0; + M_tot[1][0].re = 0.0; + M_tot[1][0].im = 0.0; + M_tot[1][1].re = 0.0; + M_tot[1][1].im = 0.0; + kn_ptr.re = 0.0; + kn_ptr.im = 0.0; + bulk_in_SLD.re = layers_rho[0].re; + bulk_in_SLD.im = layers_rho[0].im + 1.0E-30; + k0 = q[points] / 2.0; + i1 = static_cast(N - 1.0); + for (n = 0; n < i1; n++) { + if (static_cast(n) + 1U == 1U) { + // Find k1.. + sld_1.re = layers_rho[1].re - bulk_in_SLD.re; + sld_1.im = layers_rho[1].im - bulk_in_SLD.im; + k1 = findkn(k0, sld_1); + + // Find r01 + nom1.re = k0 - k1.re; + denom1.re = k0 + k1.re; + sigmasqrd = layers_sig[1] * layers_sig[1]; + err1.re = sigmasqrd * (k0 * (-2.0 * k1.re)); + err1.im = sigmasqrd * (k0 * (-2.0 * k1.im)); + coder::b_exp(&err1); + if (k1.im == 0.0) { + nom_n_re = nom1.re / denom1.re; + sigmasqrd_tmp = 0.0; + } else if (denom1.re == 0.0) { + if (nom1.re == 0.0) { + nom_n_re = (0.0 - k1.im) / k1.im; + sigmasqrd_tmp = 0.0; + } else if (0.0 - k1.im == 0.0) { + nom_n_re = 0.0; + sigmasqrd_tmp = -(nom1.re / k1.im); + } else { + nom_n_re = (0.0 - k1.im) / k1.im; + sigmasqrd_tmp = -(nom1.re / k1.im); + } + } else { + brm = std::abs(denom1.re); + sigmasqrd_tmp = std::abs(k1.im); + if (brm > sigmasqrd_tmp) { + sigmasqrd_tmp = k1.im / denom1.re; + im = denom1.re + sigmasqrd_tmp * k1.im; + nom_n_re = (nom1.re + sigmasqrd_tmp * (0.0 - k1.im)) / im; + sigmasqrd_tmp = ((0.0 - k1.im) - sigmasqrd_tmp * nom1.re) / im; + } else if (sigmasqrd_tmp == brm) { + if (denom1.re > 0.0) { + sigmasqrd_tmp = 0.5; + } else { + sigmasqrd_tmp = -0.5; + } + + if (k1.im > 0.0) { + im = 0.5; + } else { + im = -0.5; + } + + nom_n_re = (nom1.re * sigmasqrd_tmp + (0.0 - k1.im) * im) / brm; + sigmasqrd_tmp = ((0.0 - k1.im) * sigmasqrd_tmp - nom1.re * im) / + brm; + } else { + sigmasqrd_tmp = denom1.re / k1.im; + im = k1.im + sigmasqrd_tmp * denom1.re; + nom_n_re = (sigmasqrd_tmp * nom1.re + (0.0 - k1.im)) / im; + sigmasqrd_tmp = (sigmasqrd_tmp * (0.0 - k1.im) - nom1.re) / im; + } + } + + r01.re = nom_n_re * err1.re - sigmasqrd_tmp * err1.im; + r01.im = nom_n_re * err1.im + sigmasqrd_tmp * err1.re; + + // Generate the M1 matrix: + M_tot[0][0].re = 1.0; + M_tot[0][0].im = 0.0; + M_tot[1][0] = r01; + M_tot[0][1] = r01; + M_tot[1][1].re = 1.0; + M_tot[1][1].im = 0.0; + kn_ptr = k1; + } else { + // Find kn and k_n+1 (ex. k1 and k2 for n=1): _/ + sld_np1.re = layers_rho[n + 1].re - bulk_in_SLD.re; + sld_np1.im = layers_rho[n + 1].im - bulk_in_SLD.im; + knp1 = findkn(k0, sld_np1); + + // Find r_n,n+1: + nom_n.re = kn_ptr.re - knp1.re; + nom_n.im = kn_ptr.im - knp1.im; + denom_n.re = kn_ptr.re + knp1.re; + denom_n.im = kn_ptr.im + knp1.im; + sigmasqrd_tmp = layers_sig[n + 1]; + sigmasqrd = sigmasqrd_tmp * sigmasqrd_tmp; + sigmasqrd_tmp = -2.0 * kn_ptr.re; + im = -2.0 * kn_ptr.im; + err_n.re = sigmasqrd * (sigmasqrd_tmp * knp1.re - im * knp1.im); + err_n.im = sigmasqrd * (sigmasqrd_tmp * knp1.im + im * knp1.re); + coder::b_exp(&err_n); + if (denom_n.im == 0.0) { + if (nom_n.im == 0.0) { + nom_n_re = nom_n.re / denom_n.re; + sigmasqrd_tmp = 0.0; + } else if (nom_n.re == 0.0) { + nom_n_re = 0.0; + sigmasqrd_tmp = nom_n.im / denom_n.re; + } else { + nom_n_re = nom_n.re / denom_n.re; + sigmasqrd_tmp = nom_n.im / denom_n.re; + } + } else if (denom_n.re == 0.0) { + if (nom_n.re == 0.0) { + nom_n_re = nom_n.im / denom_n.im; + sigmasqrd_tmp = 0.0; + } else if (nom_n.im == 0.0) { + nom_n_re = 0.0; + sigmasqrd_tmp = -(nom_n.re / denom_n.im); + } else { + nom_n_re = nom_n.im / denom_n.im; + sigmasqrd_tmp = -(nom_n.re / denom_n.im); + } + } else { + brm = std::abs(denom_n.re); + sigmasqrd_tmp = std::abs(denom_n.im); + if (brm > sigmasqrd_tmp) { + sigmasqrd_tmp = denom_n.im / denom_n.re; + im = denom_n.re + sigmasqrd_tmp * denom_n.im; + nom_n_re = (nom_n.re + sigmasqrd_tmp * nom_n.im) / im; + sigmasqrd_tmp = (nom_n.im - sigmasqrd_tmp * nom_n.re) / im; + } else if (sigmasqrd_tmp == brm) { + if (denom_n.re > 0.0) { + sigmasqrd_tmp = 0.5; + } else { + sigmasqrd_tmp = -0.5; + } + + if (denom_n.im > 0.0) { + im = 0.5; + } else { + im = -0.5; + } + + nom_n_re = (nom_n.re * sigmasqrd_tmp + nom_n.im * im) / brm; + sigmasqrd_tmp = (nom_n.im * sigmasqrd_tmp - nom_n.re * im) / brm; + } else { + sigmasqrd_tmp = denom_n.re / denom_n.im; + im = denom_n.im + sigmasqrd_tmp * denom_n.re; + nom_n_re = (sigmasqrd_tmp * nom_n.re + nom_n.im) / im; + sigmasqrd_tmp = (sigmasqrd_tmp * nom_n.im - nom_n.re) / im; + } + } + + r_n_np1.re = nom_n_re * err_n.re - sigmasqrd_tmp * err_n.im; + r_n_np1.im = nom_n_re * err_n.im + sigmasqrd_tmp * err_n.re; + + // Find the Phase Factor = (k_n * d_n) + sigmasqrd_tmp = layers_thick[n] * kn_ptr.re; + im = layers_thick[n] * kn_ptr.im; + beta.re = sigmasqrd_tmp * 0.0 - im; + beta.im = sigmasqrd_tmp + im * 0.0; + + // Create the M_n matrix: _/ + M_n_tmp = beta; + coder::b_exp(&M_n_tmp); + M_n[0][0] = M_n_tmp; + M_n[1][0].re = r_n_np1.re * M_n_tmp.re - r_n_np1.im * M_n_tmp.im; + M_n[1][0].im = r_n_np1.re * M_n_tmp.im + r_n_np1.im * M_n_tmp.re; + M_n_tmp.re = -beta.re; + M_n_tmp.im = -beta.im; + coder::b_exp(&M_n_tmp); + M_n[0][1].re = r_n_np1.re * M_n_tmp.re - r_n_np1.im * M_n_tmp.im; + M_n[0][1].im = r_n_np1.re * M_n_tmp.im + r_n_np1.im * M_n_tmp.re; + + // Multiply the matrices + sigmasqrd_tmp = M_n[0][0].re; + im = M_n[0][0].im; + brm = M_n[0][1].re; + nom_n_re = M_n[0][1].im; + d = M_n[1][0].re; + d1 = M_n[1][0].im; + for (i2 = 0; i2 < 2; i2++) { + M_tot_re_tmp = M_tot[0][i2].re; + b_M_tot_re_tmp = M_tot[0][i2].im; + c_M_tot_re_tmp = M_tot[1][i2].re; + d_M_tot_re_tmp = M_tot[1][i2].im; + M_res[0][i2].re = (M_tot_re_tmp * sigmasqrd_tmp - b_M_tot_re_tmp * + im) + (c_M_tot_re_tmp * brm - d_M_tot_re_tmp * + nom_n_re); + M_res[0][i2].im = (M_tot_re_tmp * im + b_M_tot_re_tmp * + sigmasqrd_tmp) + (c_M_tot_re_tmp * nom_n_re + + d_M_tot_re_tmp * brm); + M_res[1][i2].re = (M_tot_re_tmp * d - b_M_tot_re_tmp * d1) + + (c_M_tot_re_tmp * M_n_tmp.re - d_M_tot_re_tmp * M_n_tmp.im); + M_res[1][i2].im = (M_tot_re_tmp * d1 + b_M_tot_re_tmp * d) + + (c_M_tot_re_tmp * M_n_tmp.im + d_M_tot_re_tmp * M_n_tmp.re); + } + + // Reassign the values back to M_tot: + M_tot[0][0] = M_res[0][0]; + M_tot[0][1] = M_res[0][1]; + M_tot[1][0] = M_res[1][0]; + M_tot[1][1] = M_res[1][1]; + + // Point to k_n+1 and sld_n+1 via kn_ptr sld_n_ptr: + kn_ptr = knp1; + } + } + + if (M_res[0][0].im == 0.0) { + if (M_res[0][1].im == 0.0) { + M_n_tmp.re = M_res[0][1].re / M_res[0][0].re; + M_n_tmp.im = 0.0; + } else if (M_res[0][1].re == 0.0) { + M_n_tmp.re = 0.0; + M_n_tmp.im = M_res[0][1].im / M_res[0][0].re; + } else { + M_n_tmp.re = M_res[0][1].re / M_res[0][0].re; + M_n_tmp.im = M_res[0][1].im / M_res[0][0].re; + } + } else if (M_res[0][0].re == 0.0) { + if (M_res[0][1].re == 0.0) { + M_n_tmp.re = M_res[0][1].im / M_res[0][0].im; + M_n_tmp.im = 0.0; + } else if (M_res[0][1].im == 0.0) { + M_n_tmp.re = 0.0; + M_n_tmp.im = -(M_res[0][1].re / M_res[0][0].im); + } else { + M_n_tmp.re = M_res[0][1].im / M_res[0][0].im; + M_n_tmp.im = -(M_res[0][1].re / M_res[0][0].im); + } + } else { + brm = std::abs(M_res[0][0].re); + sigmasqrd_tmp = std::abs(M_res[0][0].im); + if (brm > sigmasqrd_tmp) { + sigmasqrd_tmp = M_res[0][0].im / M_res[0][0].re; + im = M_res[0][0].re + sigmasqrd_tmp * M_res[0][0].im; + M_n_tmp.re = (M_res[0][1].re + sigmasqrd_tmp * M_res[0][1].im) / im; + M_n_tmp.im = (M_res[0][1].im - sigmasqrd_tmp * M_res[0][1].re) / im; + } else if (sigmasqrd_tmp == brm) { + if (M_res[0][0].re > 0.0) { + sigmasqrd_tmp = 0.5; + } else { + sigmasqrd_tmp = -0.5; + } + + if (M_res[0][0].im > 0.0) { + im = 0.5; + } else { + im = -0.5; + } + + M_n_tmp.re = (M_res[0][1].re * sigmasqrd_tmp + M_res[0][1].im * im) / + brm; + M_n_tmp.im = (M_res[0][1].im * sigmasqrd_tmp - M_res[0][1].re * im) / + brm; + } else { + sigmasqrd_tmp = M_res[0][0].re / M_res[0][0].im; + im = M_res[0][0].im + sigmasqrd_tmp * M_res[0][0].re; + M_n_tmp.re = (sigmasqrd_tmp * M_res[0][1].re + M_res[0][1].im) / im; + M_n_tmp.im = (sigmasqrd_tmp * M_res[0][1].im - M_res[0][1].re) / im; + } + } + + R = rt_hypotd_snf(M_n_tmp.re, M_n_tmp.im); + ref[points] = R * R; + } + } +} + +// End of code generation (abelesParallelPoints.cpp) diff --git a/RAT/abelesParallelPoints.h b/RAT/abelesParallelPoints.h new file mode 100644 index 00000000..6784ab81 --- /dev/null +++ b/RAT/abelesParallelPoints.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// abelesParallelPoints.h +// +// Code generation for function 'abelesParallelPoints' +// +#ifndef ABELESPARALLELPOINTS_H +#define ABELESPARALLELPOINTS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void abelesParallelPoints(const ::coder::array &q, real_T N, const + ::coder::array &layers_thick, const ::coder::array + &layers_rho, const ::coder::array &layers_sig, ::coder::array< + real_T, 1U> &ref); +} + +#endif + +// End of code generation (abelesParallelPoints.h) diff --git a/RAT/abelesSingle.cpp b/RAT/abelesSingle.cpp new file mode 100644 index 00000000..ce69f4bc --- /dev/null +++ b/RAT/abelesSingle.cpp @@ -0,0 +1,352 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// abelesSingle.cpp +// +// Code generation for function 'abelesSingle' +// + +// Include files +#include "abelesSingle.h" +#include "exp.h" +#include "reflectivityCalculation_data.h" +#include "reflectivityCalculation_rtwutil.h" +#include "rt_nonfinite.h" +#include "sqrt.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void abelesSingle(const ::coder::array &q, real_T N, const ::coder:: + array &layers_thick, const ::coder::array< + creal_T, 1U> &layers_rho, const ::coder::array + &layers_sig, ::coder::array &ref) + { + creal_T M_n[2][2]; + creal_T M_res[2][2]; + creal_T M_tot[2][2]; + creal_T M_n_tmp; + creal_T k1; + creal_T knp1; + real_T kn_ptr_im; + real_T kn_ptr_re; + int32_T i; + int32_T loop_ub; + + // New Matlab version of reflectivity + // with complex rho... + // Pre-allocation + M_tot[0][0].re = 0.0; + M_tot[0][0].im = 0.0; + M_res[0][0].re = 0.0; + M_res[0][0].im = 0.0; + M_tot[0][1].re = 0.0; + M_tot[0][1].im = 0.0; + M_res[0][1].re = 0.0; + M_res[0][1].im = 0.0; + M_tot[1][0].re = 0.0; + M_tot[1][0].im = 0.0; + M_tot[1][1].re = 0.0; + M_tot[1][1].im = 0.0; + kn_ptr_re = 0.0; + kn_ptr_im = 0.0; + ref.set_size(q.size(0)); + loop_ub = q.size(0); + for (i = 0; i < loop_ub; i++) { + ref[i] = 0.0; + } + + i = q.size(0); + for (int32_T points{0}; points < i; points++) { + real_T M_n_tmp_tmp; + real_T brm; + real_T bulk_in_SLD_im; + real_T bulk_in_SLD_re; + real_T k0; + real_T re; + bulk_in_SLD_re = layers_rho[0].re; + bulk_in_SLD_im = layers_rho[0].im + 1.0E-30; + k0 = q[points] / 2.0; + loop_ub = static_cast(N - 1.0); + for (int32_T n{0}; n < loop_ub; n++) { + if (static_cast(n) + 1U == 1U) { + real_T ar; + real_T im; + real_T r01_im; + real_T r01_re; + + // Find k1.. + k1.re = k0 * k0 - 12.566370614359172 * (layers_rho[1].re - + bulk_in_SLD_re); + k1.im = 0.0 - 12.566370614359172 * (layers_rho[1].im - bulk_in_SLD_im); + coder::internal::scalar::b_sqrt(&k1); + + // Find r01 + M_n_tmp_tmp = layers_sig[1] * layers_sig[1]; + M_n_tmp.re = M_n_tmp_tmp * (k0 * (-2.0 * k1.re)); + M_n_tmp.im = M_n_tmp_tmp * (k0 * (-2.0 * k1.im)); + coder::b_exp(&M_n_tmp); + ar = k0 - k1.re; + im = k0 + k1.re; + if (k1.im == 0.0) { + im = ar / im; + re = 0.0; + } else if (im == 0.0) { + if (ar == 0.0) { + im = (0.0 - k1.im) / k1.im; + re = 0.0; + } else if (0.0 - k1.im == 0.0) { + im = 0.0; + re = -(ar / k1.im); + } else { + im = (0.0 - k1.im) / k1.im; + re = -(ar / k1.im); + } + } else { + brm = std::abs(im); + re = std::abs(k1.im); + if (brm > re) { + M_n_tmp_tmp = k1.im / im; + re = im + M_n_tmp_tmp * k1.im; + im = (ar + M_n_tmp_tmp * (0.0 - k1.im)) / re; + re = ((0.0 - k1.im) - M_n_tmp_tmp * ar) / re; + } else if (re == brm) { + if (im > 0.0) { + M_n_tmp_tmp = 0.5; + } else { + M_n_tmp_tmp = -0.5; + } + + if (k1.im > 0.0) { + re = 0.5; + } else { + re = -0.5; + } + + im = (ar * M_n_tmp_tmp + (0.0 - k1.im) * re) / brm; + re = ((0.0 - k1.im) * M_n_tmp_tmp - ar * re) / brm; + } else { + M_n_tmp_tmp = im / k1.im; + re = k1.im + M_n_tmp_tmp * im; + im = (M_n_tmp_tmp * ar + (0.0 - k1.im)) / re; + re = (M_n_tmp_tmp * (0.0 - k1.im) - ar) / re; + } + } + + r01_re = im * M_n_tmp.re - re * M_n_tmp.im; + r01_im = im * M_n_tmp.im + re * M_n_tmp.re; + + // Generate the M1 matrix: + M_tot[0][0].re = 1.0; + M_tot[0][0].im = 0.0; + M_tot[1][0].re = r01_re; + M_tot[1][0].im = r01_im; + M_tot[0][1].re = r01_re; + M_tot[0][1].im = r01_im; + M_tot[1][1].re = 1.0; + M_tot[1][1].im = 0.0; + kn_ptr_re = k1.re; + kn_ptr_im = k1.im; + } else { + real_T ai; + real_T ar; + real_T b_kn_ptr_re; + real_T beta_im; + real_T beta_re; + real_T bi; + real_T d; + real_T d1; + real_T im; + real_T r_n_np1_im; + real_T r_n_np1_re; + + // Find kn and k_n+1 (ex. k1 and k2 for n=1): _/ + knp1.re = k0 * k0 - 12.566370614359172 * (layers_rho[n + 1].re - + bulk_in_SLD_re); + knp1.im = 0.0 - 12.566370614359172 * (layers_rho[n + 1].im - + bulk_in_SLD_im); + coder::internal::scalar::b_sqrt(&knp1); + + // Find r_n,n+1: + re = -2.0 * kn_ptr_re; + im = -2.0 * kn_ptr_im; + M_n_tmp_tmp = layers_sig[n + 1]; + M_n_tmp_tmp *= M_n_tmp_tmp; + M_n_tmp.re = M_n_tmp_tmp * (re * knp1.re - im * knp1.im); + M_n_tmp.im = M_n_tmp_tmp * (re * knp1.im + im * knp1.re); + coder::b_exp(&M_n_tmp); + ar = kn_ptr_re - knp1.re; + ai = kn_ptr_im - knp1.im; + im = kn_ptr_re + knp1.re; + bi = kn_ptr_im + knp1.im; + if (bi == 0.0) { + if (ai == 0.0) { + b_kn_ptr_re = ar / im; + re = 0.0; + } else if (ar == 0.0) { + b_kn_ptr_re = 0.0; + re = ai / im; + } else { + b_kn_ptr_re = ar / im; + re = ai / im; + } + } else if (im == 0.0) { + if (ar == 0.0) { + b_kn_ptr_re = ai / bi; + re = 0.0; + } else if (ai == 0.0) { + b_kn_ptr_re = 0.0; + re = -(ar / bi); + } else { + b_kn_ptr_re = ai / bi; + re = -(ar / bi); + } + } else { + brm = std::abs(im); + re = std::abs(bi); + if (brm > re) { + M_n_tmp_tmp = bi / im; + re = im + M_n_tmp_tmp * bi; + b_kn_ptr_re = (ar + M_n_tmp_tmp * ai) / re; + re = (ai - M_n_tmp_tmp * ar) / re; + } else if (re == brm) { + if (im > 0.0) { + M_n_tmp_tmp = 0.5; + } else { + M_n_tmp_tmp = -0.5; + } + + if (bi > 0.0) { + re = 0.5; + } else { + re = -0.5; + } + + b_kn_ptr_re = (ar * M_n_tmp_tmp + ai * re) / brm; + re = (ai * M_n_tmp_tmp - ar * re) / brm; + } else { + M_n_tmp_tmp = im / bi; + re = bi + M_n_tmp_tmp * im; + b_kn_ptr_re = (M_n_tmp_tmp * ar + ai) / re; + re = (M_n_tmp_tmp * ai - ar) / re; + } + } + + r_n_np1_re = b_kn_ptr_re * M_n_tmp.re - re * M_n_tmp.im; + r_n_np1_im = b_kn_ptr_re * M_n_tmp.im + re * M_n_tmp.re; + + // Find the Phase Factor = (k_n * d_n) + kn_ptr_re *= layers_thick[n]; + kn_ptr_im *= layers_thick[n]; + beta_re = kn_ptr_re * 0.0 - kn_ptr_im; + beta_im = kn_ptr_re + kn_ptr_im * 0.0; + + // Create the M_n matrix: _/ + M_n_tmp.re = beta_re; + M_n_tmp.im = beta_im; + coder::b_exp(&M_n_tmp); + M_n[0][0] = M_n_tmp; + M_n[1][0].re = r_n_np1_re * M_n_tmp.re - r_n_np1_im * M_n_tmp.im; + M_n[1][0].im = r_n_np1_re * M_n_tmp.im + r_n_np1_im * M_n_tmp.re; + M_n_tmp.re = -beta_re; + M_n_tmp.im = -beta_im; + coder::b_exp(&M_n_tmp); + + // Multiply the matrices + ar = M_n[0][0].re; + d = M_n[0][0].im; + d1 = r_n_np1_re * M_n_tmp.re - r_n_np1_im * M_n_tmp.im; + re = r_n_np1_re * M_n_tmp.im + r_n_np1_im * M_n_tmp.re; + im = M_n[1][0].re; + M_n_tmp_tmp = M_n[1][0].im; + for (int32_T i1{0}; i1 < 2; i1++) { + bi = M_tot[0][i1].re; + brm = M_tot[0][i1].im; + ai = M_tot[1][i1].re; + b_kn_ptr_re = M_tot[1][i1].im; + M_res[0][i1].re = (bi * ar - brm * d) + (ai * d1 - b_kn_ptr_re * re); + M_res[0][i1].im = (bi * d + brm * ar) + (ai * re + b_kn_ptr_re * d1); + M_res[1][i1].re = (bi * im - brm * M_n_tmp_tmp) + (ai * M_n_tmp.re - + b_kn_ptr_re * M_n_tmp.im); + M_res[1][i1].im = (bi * M_n_tmp_tmp + brm * im) + (ai * M_n_tmp.im + + b_kn_ptr_re * M_n_tmp.re); + } + + // Reassign the values back to M_tot: + M_tot[0][0] = M_res[0][0]; + M_tot[0][1] = M_res[0][1]; + M_tot[1][0] = M_res[1][0]; + M_tot[1][1] = M_res[1][1]; + + // Point to k_n+1 and sld_n+1 via kn_ptr sld_n_ptr: + kn_ptr_re = knp1.re; + kn_ptr_im = knp1.im; + } + } + + if (M_res[0][0].im == 0.0) { + if (M_res[0][1].im == 0.0) { + M_n_tmp.re = M_res[0][1].re / M_res[0][0].re; + M_n_tmp.im = 0.0; + } else if (M_res[0][1].re == 0.0) { + M_n_tmp.re = 0.0; + M_n_tmp.im = M_res[0][1].im / M_res[0][0].re; + } else { + M_n_tmp.re = M_res[0][1].re / M_res[0][0].re; + M_n_tmp.im = M_res[0][1].im / M_res[0][0].re; + } + } else if (M_res[0][0].re == 0.0) { + if (M_res[0][1].re == 0.0) { + M_n_tmp.re = M_res[0][1].im / M_res[0][0].im; + M_n_tmp.im = 0.0; + } else if (M_res[0][1].im == 0.0) { + M_n_tmp.re = 0.0; + M_n_tmp.im = -(M_res[0][1].re / M_res[0][0].im); + } else { + M_n_tmp.re = M_res[0][1].im / M_res[0][0].im; + M_n_tmp.im = -(M_res[0][1].re / M_res[0][0].im); + } + } else { + brm = std::abs(M_res[0][0].re); + re = std::abs(M_res[0][0].im); + if (brm > re) { + M_n_tmp_tmp = M_res[0][0].im / M_res[0][0].re; + re = M_res[0][0].re + M_n_tmp_tmp * M_res[0][0].im; + M_n_tmp.re = (M_res[0][1].re + M_n_tmp_tmp * M_res[0][1].im) / re; + M_n_tmp.im = (M_res[0][1].im - M_n_tmp_tmp * M_res[0][1].re) / re; + } else if (re == brm) { + if (M_res[0][0].re > 0.0) { + M_n_tmp_tmp = 0.5; + } else { + M_n_tmp_tmp = -0.5; + } + + if (M_res[0][0].im > 0.0) { + re = 0.5; + } else { + re = -0.5; + } + + M_n_tmp.re = (M_res[0][1].re * M_n_tmp_tmp + M_res[0][1].im * re) / + brm; + M_n_tmp.im = (M_res[0][1].im * M_n_tmp_tmp - M_res[0][1].re * re) / + brm; + } else { + M_n_tmp_tmp = M_res[0][0].re / M_res[0][0].im; + re = M_res[0][0].im + M_n_tmp_tmp * M_res[0][0].re; + M_n_tmp.re = (M_n_tmp_tmp * M_res[0][1].re + M_res[0][1].im) / re; + M_n_tmp.im = (M_n_tmp_tmp * M_res[0][1].im - M_res[0][1].re) / re; + } + } + + re = rt_hypotd_snf(M_n_tmp.re, M_n_tmp.im); + ref[points] = re * re; + } + } +} + +// End of code generation (abelesSingle.cpp) diff --git a/RAT/abelesSingle.h b/RAT/abelesSingle.h new file mode 100644 index 00000000..c1d70ada --- /dev/null +++ b/RAT/abelesSingle.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// abelesSingle.h +// +// Code generation for function 'abelesSingle' +// +#ifndef ABELESSINGLE_H +#define ABELESSINGLE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void abelesSingle(const ::coder::array &q, real_T N, const ::coder:: + array &layers_thick, const ::coder::array< + creal_T, 1U> &layers_rho, const ::coder::array + &layers_sig, ::coder::array &ref); +} + +#endif + +// End of code generation (abelesSingle.h) diff --git a/RAT/acos.cpp b/RAT/acos.cpp new file mode 100644 index 00000000..92d14680 --- /dev/null +++ b/RAT/acos.cpp @@ -0,0 +1,97 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// acos.cpp +// +// Code generation for function 'acos' +// + +// Include files +#include "acos.h" +#include "asinh.h" +#include "complexTimes.h" +#include "rt_nonfinite.h" +#include "sqrt.h" +#include "rt_defines.h" +#include + +// Function Declarations +namespace RAT +{ + static real_T rt_atan2d_snf(real_T u0, real_T u1); +} + +// Function Definitions +namespace RAT +{ + static real_T rt_atan2d_snf(real_T u0, real_T u1) + { + real_T y; + if (std::isnan(u0) || std::isnan(u1)) { + y = rtNaN; + } else if (std::isinf(u0) && std::isinf(u1)) { + int32_T i; + int32_T i1; + if (u0 > 0.0) { + i = 1; + } else { + i = -1; + } + + if (u1 > 0.0) { + i1 = 1; + } else { + i1 = -1; + } + + y = std::atan2(static_cast(i), static_cast(i1)); + } else if (u1 == 0.0) { + if (u0 > 0.0) { + y = RT_PI / 2.0; + } else if (u0 < 0.0) { + y = -(RT_PI / 2.0); + } else { + y = 0.0; + } + } else { + y = std::atan2(u0, u1); + } + + return y; + } + + namespace coder + { + namespace internal + { + namespace scalar + { + void b_acos(creal_T *x) + { + creal_T u; + creal_T v; + real_T d; + if ((x->im == 0.0) && (!(std::abs(x->re) > 1.0))) { + x->re = std::acos(x->re); + x->im = 0.0; + } else { + v.re = x->re + 1.0; + v.im = x->im; + b_sqrt(&v); + u.re = 1.0 - x->re; + u.im = 0.0 - x->im; + b_sqrt(&u); + d = complexTimes(v.re, -v.im, u.re, u.im); + b_asinh(&d); + x->re = 2.0 * rt_atan2d_snf(u.re, v.re); + x->im = d; + } + } + } + } + } +} + +// End of code generation (acos.cpp) diff --git a/RAT/acos.h b/RAT/acos.h new file mode 100644 index 00000000..921b0d20 --- /dev/null +++ b/RAT/acos.h @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// acos.h +// +// Code generation for function 'acos' +// +#ifndef ACOS_H +#define ACOS_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace scalar + { + void b_acos(creal_T *x); + } + } + } +} + +#endif + +// End of code generation (acos.h) diff --git a/RAT/adaptive.cpp b/RAT/adaptive.cpp new file mode 100644 index 00000000..7e611163 --- /dev/null +++ b/RAT/adaptive.cpp @@ -0,0 +1,1658 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// adaptive.cpp +// +// Code generation for function 'adaptive' +// + +// Include files +#include "adaptive.h" +#include "SLDFunction.h" +#include "acos.h" +#include "allOrAny.h" +#include "eml_mtimes_helper.h" +#include "linspace.h" +#include "minOrMax.h" +#include "reflectivityCalculation_internal_types.h" +#include "repmat.h" +#include "rt_nonfinite.h" +#include "sortrows.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void b_binary_expand_op(::coder::array &in1, const + cell_24 *in2, const ::coder::array &in3, real_T in4); + static void b_increaseSampling(::coder::array &dataPoints, const :: + coder::array &segmentsToSplit, const real_T sldProfile_data[], + const int32_T sldProfile_size[2]); + static void binary_expand_op(const ::coder::array &in1, const :: + coder::array &in2, const ::coder::array &in3, :: + coder::array &in4, ::coder::array &in5, ::coder:: + array &in6); + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, int32_T in3, int32_T in4, int32_T in5, int32_T in6); + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, int32_T in3, int32_T in4, int32_T in5); + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const ::coder:: + array &in4, const ::coder::array &in5, const ::coder:: + array &in6); + static void calculateCentralAngles(const ::coder::array &XYdata, + const real_T dataBoxSize[2], ::coder::array &cornerAngle); + static void calculateTrianglesSides(const ::coder::array &XYdata, :: + coder::array &firstStep, ::coder::array &secondStep, + ::coder::array &longStep); + static void increaseSampling(::coder::array &dataPoints, const :: + coder::array &segmentsToSplit, const ::coder::array &sldProfile); + static void normalizeFunction(const ::coder::array &x, const + real_T sldProfile_data[], const int32_T sldProfile_size[2], ::coder::array< + real_T, 1U> &y); + static void normalizeFunction(const ::coder::array &x, const :: + coder::array &sldProfile, ::coder::array &y); + static void times(::coder::array &in1, const ::coder::array &in2, const ::coder::array &in3); +} + +// Function Definitions +namespace RAT +{ + static void b_binary_expand_op(::coder::array &in1, const + cell_24 *in2, const ::coder::array &in3, real_T in4) + { + int32_T i; + int32_T in2_idx_0; + int32_T stride_1_0; + in2_idx_0 = in2->f1.size(0) - 2; + if (in3.size(0) == 1) { + i = in2_idx_0; + } else { + i = in3.size(0); + } + + in1.set_size(i); + stride_1_0 = (in3.size(0) != 1); + if (in3.size(0) != 1) { + in2_idx_0 = in3.size(0); + } + + for (i = 0; i < in2_idx_0; i++) { + in1[i] = (in3[i * stride_1_0] < in4); + } + } + + static void b_increaseSampling(::coder::array &dataPoints, const :: + coder::array &segmentsToSplit, const real_T sldProfile_data[], + const int32_T sldProfile_size[2]) + { + ::coder::array b_dataPoints; + ::coder::array newDataPoints; + ::coder::array b_newDataPoints; + ::coder::array r4; + ::coder::array r2; + ::coder::array r3; + ::coder::array r; + ::coder::array r1; + int32_T end; + int32_T input_sizes_idx_0; + + // increaseSampling increase the sampling of an input function + end = segmentsToSplit.size(0); + input_sizes_idx_0 = 0; + for (int32_T i{0}; i < end; i++) { + if (segmentsToSplit[i]) { + input_sizes_idx_0++; + } + } + + newDataPoints.set_size(input_sizes_idx_0, 2); + for (int32_T i{0}; i < 2; i++) { + for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { + newDataPoints[b_i + newDataPoints.size(0) * i] = 0.0; + } + } + + r.set_size(segmentsToSplit.size(0) + 1); + input_sizes_idx_0 = segmentsToSplit.size(0); + for (int32_T i{0}; i < input_sizes_idx_0; i++) { + r[i] = segmentsToSplit[i]; + } + + r[segmentsToSplit.size(0)] = false; + r1.set_size(segmentsToSplit.size(0) + 1); + r1[0] = false; + input_sizes_idx_0 = segmentsToSplit.size(0); + for (int32_T i{0}; i < input_sizes_idx_0; i++) { + r1[i + 1] = segmentsToSplit[i]; + } + + end = r.size(0) - 1; + input_sizes_idx_0 = 0; + for (int32_T i{0}; i <= end; i++) { + if (r[i]) { + input_sizes_idx_0++; + } + } + + r2.set_size(input_sizes_idx_0); + input_sizes_idx_0 = 0; + for (int32_T i{0}; i <= end; i++) { + if (r[i]) { + r2[input_sizes_idx_0] = i + 1; + input_sizes_idx_0++; + } + } + + end = r1.size(0) - 1; + input_sizes_idx_0 = 0; + for (int32_T i{0}; i <= end; i++) { + if (r1[i]) { + input_sizes_idx_0++; + } + } + + r3.set_size(input_sizes_idx_0); + input_sizes_idx_0 = 0; + for (int32_T i{0}; i <= end; i++) { + if (r1[i]) { + r3[input_sizes_idx_0] = i + 1; + input_sizes_idx_0++; + } + } + + if (r2.size(0) == r3.size(0)) { + input_sizes_idx_0 = r2.size(0); + for (int32_T i{0}; i < input_sizes_idx_0; i++) { + newDataPoints[i] = 0.5 * (dataPoints[r2[i] - 1] + dataPoints[r3[i] - 1]); + } + } else { + binary_expand_op(newDataPoints, dataPoints, r2, r3); + } + + b_newDataPoints.set_size(newDataPoints.size(0)); + input_sizes_idx_0 = newDataPoints.size(0); + for (int32_T i{0}; i < input_sizes_idx_0; i++) { + b_newDataPoints[i] = newDataPoints[i]; + } + + normalizeFunction(b_newDataPoints, sldProfile_data, sldProfile_size, r4); + input_sizes_idx_0 = r4.size(0); + for (int32_T i{0}; i < input_sizes_idx_0; i++) { + newDataPoints[i + newDataPoints.size(0)] = r4[i]; + } + + // For simplicity append the new points at the end and then sort. + if (newDataPoints.size(0) != 0) { + input_sizes_idx_0 = newDataPoints.size(0); + } else { + input_sizes_idx_0 = 0; + } + + if (dataPoints.size(0) != 0) { + end = dataPoints.size(0); + } else { + end = 0; + } + + b_dataPoints.set_size(end + input_sizes_idx_0, 2); + for (int32_T i{0}; i < 2; i++) { + for (int32_T b_i{0}; b_i < end; b_i++) { + b_dataPoints[b_i + b_dataPoints.size(0) * i] = dataPoints[b_i + + dataPoints.size(0) * i]; + } + + for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { + b_dataPoints[(b_i + end) + b_dataPoints.size(0) * i] = newDataPoints[b_i + + newDataPoints.size(0) * i]; + } + } + + dataPoints.set_size(b_dataPoints.size(0), 2); + input_sizes_idx_0 = b_dataPoints.size(0); + for (int32_T i{0}; i < 2; i++) { + for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { + dataPoints[b_i + dataPoints.size(0) * i] = b_dataPoints[b_i + + b_dataPoints.size(0) * i]; + } + } + + coder::sortrows(dataPoints); + } + + static void binary_expand_op(const ::coder::array &in1, const :: + coder::array &in2, const ::coder::array &in3, :: + coder::array &in4, ::coder::array &in5, ::coder:: + array &in6) + { + ::coder::array b_in1; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + int32_T stride_2_0; + if (in3.size(0) == 1) { + if (in2.size(0) == 1) { + i = in1.size(0); + } else { + i = in2.size(0); + } + } else { + i = in3.size(0); + } + + b_in1.set_size(i, 2); + stride_0_0 = (in1.size(0) != 1); + stride_1_0 = (in2.size(0) != 1); + stride_2_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + if (in2.size(0) == 1) { + loop_ub = in1.size(0); + } else { + loop_ub = in2.size(0); + } + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_in1[i1 + b_in1.size(0) * i] = in1[i1 * stride_0_0 + in1.size(0) * i] / + in2[i1 * stride_1_0 + in2.size(0) * i] - in3[i1 * stride_2_0 + + in3.size(0) * i]; + } + } + + calculateTrianglesSides(b_in1, in4, in5, in6); + } + + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, int32_T in3, int32_T in4, int32_T in5, int32_T in6) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + if ((in6 - in5) + 1 == 1) { + i = (in4 - in3) + 1; + } else { + i = (in6 - in5) + 1; + } + + in1.set_size(i, 2); + stride_0_0 = ((in4 - in3) + 1 != 1); + stride_1_0 = ((in6 - in5) + 1 != 1); + if ((in6 - in5) + 1 == 1) { + loop_ub = (in4 - in3) + 1; + } else { + loop_ub = (in6 - in5) + 1; + } + + for (i = 0; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + in1[i1 + in1.size(0) * i] = in2[(in3 + i1 * stride_0_0) + in2.size(0) * + i] - in2[(in5 + i1 * stride_1_0) + in2.size(0) * i]; + } + } + } + + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, int32_T in3, int32_T in4, int32_T in5) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + if (in5 + 1 == 1) { + i = (in4 - in3) + 1; + } else { + i = in5 + 1; + } + + in1.set_size(i, 2); + stride_0_0 = ((in4 - in3) + 1 != 1); + stride_1_0 = (in5 + 1 != 1); + if (in5 + 1 == 1) { + loop_ub = (in4 - in3) + 1; + } else { + loop_ub = in5 + 1; + } + + for (i = 0; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + in1[i1 + in1.size(0) * i] = in2[(in3 + i1 * stride_0_0) + in2.size(0) * + i] - in2[i1 * stride_1_0 + in2.size(0) * i]; + } + } + } + + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const ::coder:: + array &in4, const ::coder::array &in5, const ::coder:: + array &in6) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + int32_T stride_2_0; + int32_T stride_3_0; + if (in6.size(0) == 1) { + if (in4.size(0) == 1) { + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + } else { + i = in4.size(0); + } + } else { + i = in6.size(0); + } + + in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + stride_2_0 = (in4.size(0) != 1); + stride_3_0 = (in6.size(0) != 1); + if (in6.size(0) == 1) { + if (in4.size(0) == 1) { + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); + } + } else { + loop_ub = in4.size(0); + } + } else { + loop_ub = in6.size(0); + } + + for (i = 0; i < loop_ub; i++) { + int32_T i1; + i1 = i * stride_2_0; + in1[i].re = ((in2[i * stride_0_0] + in3[i * stride_1_0]) - (in4[i1] + + in5[i1])) / 2.0 / in6[i * stride_3_0]; + in1[i].im = 0.0; + } + } + + static void calculateCentralAngles(const ::coder::array &XYdata, + const real_T dataBoxSize[2], ::coder::array &cornerAngle) + { + ::coder::array r4; + ::coder::array b_XYdata; + ::coder::array firstStep; + ::coder::array longStep; + ::coder::array r; + ::coder::array secondStep; + ::coder::array firstStepSquared; + ::coder::array r1; + ::coder::array r2; + ::coder::array r3; + ::coder::array secondStepSquared; + real_T dv[2]; + real_T varargin_1; + int32_T i; + int32_T i1; + int32_T k; + + // Calculate the central angle of the triangles formed by data points. + // For input size NxM, the output size is (N-2)xN, because the first and the + // last point are not the central corner of any triangle. + // Normalize data, because angles depend on scaling. + // calculate cosine of central angles + coder::repmat(dataBoxSize, static_cast(XYdata.size(0)), b_XYdata); + coder::internal::minimum(XYdata, dv); + coder::repmat(dv, static_cast(XYdata.size(0)), r); + if (XYdata.size(0) == 1) { + i = b_XYdata.size(0); + } else { + i = XYdata.size(0); + } + + if ((XYdata.size(0) == b_XYdata.size(0)) && (i == r.size(0))) { + b_XYdata.set_size(XYdata.size(0), 2); + k = XYdata.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < k; i1++) { + b_XYdata[i1 + b_XYdata.size(0) * i] = XYdata[i1 + XYdata.size(0) * i] / + b_XYdata[i1 + b_XYdata.size(0) * i] - r[i1 + r.size(0) * i]; + } + } + + calculateTrianglesSides(b_XYdata, firstStep, secondStep, longStep); + } else { + binary_expand_op(XYdata, b_XYdata, r, firstStep, secondStep, longStep); + } + + // calculate area of squares of length of triangle sides + r1.set_size(firstStep.size(0)); + k = firstStep.size(0); + for (i = 0; i < k; i++) { + varargin_1 = firstStep[i]; + r1[i] = varargin_1 * varargin_1; + } + + r2.set_size(firstStep.size(0)); + k = firstStep.size(0); + for (i = 0; i < k; i++) { + varargin_1 = firstStep[i + firstStep.size(0)]; + r2[i] = varargin_1 * varargin_1; + } + + firstStepSquared.set_size(r1.size(0)); + k = r1.size(0); + for (i = 0; i < k; i++) { + firstStepSquared[i] = r1[i] + r2[i]; + } + + r1.set_size(secondStep.size(0)); + k = secondStep.size(0); + for (i = 0; i < k; i++) { + varargin_1 = secondStep[i]; + r1[i] = varargin_1 * varargin_1; + } + + r2.set_size(secondStep.size(0)); + k = secondStep.size(0); + for (i = 0; i < k; i++) { + varargin_1 = secondStep[i + secondStep.size(0)]; + r2[i] = varargin_1 * varargin_1; + } + + secondStepSquared.set_size(r1.size(0)); + k = r1.size(0); + for (i = 0; i < k; i++) { + secondStepSquared[i] = r1[i] + r2[i]; + } + + r1.set_size(longStep.size(0)); + k = longStep.size(0); + for (i = 0; i < k; i++) { + varargin_1 = longStep[i]; + r1[i] = varargin_1 * varargin_1; + } + + r2.set_size(longStep.size(0)); + k = longStep.size(0); + for (i = 0; i < k; i++) { + varargin_1 = longStep[i + longStep.size(0)]; + r2[i] = varargin_1 * varargin_1; + } + + if (firstStepSquared.size(0) == secondStepSquared.size(0)) { + r3.set_size(firstStepSquared.size(0)); + k = firstStepSquared.size(0); + for (i = 0; i < k; i++) { + r3[i] = firstStepSquared[i] * secondStepSquared[i]; + } + } else { + times(r3, firstStepSquared, secondStepSquared); + } + + i = r3.size(0); + for (k = 0; k < i; k++) { + r3[k] = std::sqrt(r3[k]); + } + + if (firstStepSquared.size(0) == 1) { + i = secondStepSquared.size(0); + } else { + i = firstStepSquared.size(0); + } + + if (firstStepSquared.size(0) == 1) { + i1 = secondStepSquared.size(0); + } else { + i1 = firstStepSquared.size(0); + } + + if (i1 == 1) { + i1 = r1.size(0); + } else if (firstStepSquared.size(0) == 1) { + i1 = secondStepSquared.size(0); + } else { + i1 = firstStepSquared.size(0); + } + + if ((firstStepSquared.size(0) == secondStepSquared.size(0)) && (i == r1.size + (0)) && (i1 == r3.size(0))) { + r4.set_size(firstStepSquared.size(0)); + k = firstStepSquared.size(0); + for (i = 0; i < k; i++) { + r4[i].re = ((firstStepSquared[i] + secondStepSquared[i]) - (r1[i] + r2[i])) + / 2.0 / r3[i]; + r4[i].im = 0.0; + } + } else { + binary_expand_op(r4, firstStepSquared, secondStepSquared, r1, r2, r3); + } + + i = r4.size(0); + for (k = 0; k < i; k++) { + coder::internal::scalar::b_acos(&r4[k]); + } + + cornerAngle.set_size(r4.size(0)); + k = r4.size(0); + for (i = 0; i < k; i++) { + cornerAngle[i] = r4[i].re; + } + } + + static void calculateTrianglesSides(const ::coder::array &XYdata, :: + coder::array &firstStep, ::coder::array &secondStep, + ::coder::array &longStep) + { + int32_T i; + int32_T i1; + int32_T i2; + int32_T i3; + int32_T loop_ub; + + // Return the sides (deltaX, deltaY) of the triangles formed by data points. + // For input size NxM, the output size is (N-2)xN, because the first and the + // last point are not the central corner of any triangle. + if (XYdata.size(0) - 1 < 2) { + i = 0; + i1 = 0; + } else { + i = 1; + i1 = XYdata.size(0) - 1; + } + + if (XYdata.size(0) - 2 < 1) { + i2 = 0; + } else { + i2 = XYdata.size(0) - 2; + } + + loop_ub = i1 - i; + if (loop_ub == i2) { + firstStep.set_size(loop_ub, 2); + for (i1 = 0; i1 < 2; i1++) { + for (i2 = 0; i2 < loop_ub; i2++) { + firstStep[i2 + firstStep.size(0) * i1] = XYdata[(i + i2) + XYdata.size + (0) * i1] - XYdata[i2 + XYdata.size(0) * i1]; + } + } + } else { + binary_expand_op(firstStep, XYdata, i, i1 - 1, i2 - 1); + } + + if (XYdata.size(0) < 3) { + i = 0; + i1 = 0; + i2 = 0; + i3 = 0; + } else { + i = 2; + i1 = XYdata.size(0); + i2 = 1; + i3 = XYdata.size(0) - 1; + } + + loop_ub = i1 - i; + if (loop_ub == i3 - i2) { + secondStep.set_size(loop_ub, 2); + for (i1 = 0; i1 < 2; i1++) { + for (i3 = 0; i3 < loop_ub; i3++) { + secondStep[i3 + secondStep.size(0) * i1] = XYdata[(i + i3) + + XYdata.size(0) * i1] - XYdata[(i2 + i3) + XYdata.size(0) * i1]; + } + } + } else { + binary_expand_op(secondStep, XYdata, i, i1 - 1, i2, i3 - 1); + } + + if (XYdata.size(0) < 3) { + i = 0; + i1 = 0; + } else { + i = 2; + i1 = XYdata.size(0); + } + + if (XYdata.size(0) - 2 < 1) { + i2 = 0; + } else { + i2 = XYdata.size(0) - 2; + } + + loop_ub = i1 - i; + if (loop_ub == i2) { + longStep.set_size(loop_ub, 2); + for (i1 = 0; i1 < 2; i1++) { + for (i2 = 0; i2 < loop_ub; i2++) { + longStep[i2 + longStep.size(0) * i1] = XYdata[(i + i2) + XYdata.size(0) + * i1] - XYdata[i2 + XYdata.size(0) * i1]; + } + } + } else { + binary_expand_op(longStep, XYdata, i, i1 - 1, i2 - 1); + } + } + + static void increaseSampling(::coder::array &dataPoints, const :: + coder::array &segmentsToSplit, const ::coder::array &sldProfile) + { + ::coder::array b_dataPoints; + ::coder::array newDataPoints; + ::coder::array b_newDataPoints; + ::coder::array r4; + ::coder::array r2; + ::coder::array r3; + ::coder::array r; + ::coder::array r1; + int32_T end; + int32_T input_sizes_idx_0; + + // increaseSampling increase the sampling of an input function + end = segmentsToSplit.size(0); + input_sizes_idx_0 = 0; + for (int32_T i{0}; i < end; i++) { + if (segmentsToSplit[i]) { + input_sizes_idx_0++; + } + } + + newDataPoints.set_size(input_sizes_idx_0, 2); + for (int32_T i{0}; i < 2; i++) { + for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { + newDataPoints[b_i + newDataPoints.size(0) * i] = 0.0; + } + } + + r.set_size(segmentsToSplit.size(0) + 1); + input_sizes_idx_0 = segmentsToSplit.size(0); + for (int32_T i{0}; i < input_sizes_idx_0; i++) { + r[i] = segmentsToSplit[i]; + } + + r[segmentsToSplit.size(0)] = false; + r1.set_size(segmentsToSplit.size(0) + 1); + r1[0] = false; + input_sizes_idx_0 = segmentsToSplit.size(0); + for (int32_T i{0}; i < input_sizes_idx_0; i++) { + r1[i + 1] = segmentsToSplit[i]; + } + + end = r.size(0) - 1; + input_sizes_idx_0 = 0; + for (int32_T i{0}; i <= end; i++) { + if (r[i]) { + input_sizes_idx_0++; + } + } + + r2.set_size(input_sizes_idx_0); + input_sizes_idx_0 = 0; + for (int32_T i{0}; i <= end; i++) { + if (r[i]) { + r2[input_sizes_idx_0] = i + 1; + input_sizes_idx_0++; + } + } + + end = r1.size(0) - 1; + input_sizes_idx_0 = 0; + for (int32_T i{0}; i <= end; i++) { + if (r1[i]) { + input_sizes_idx_0++; + } + } + + r3.set_size(input_sizes_idx_0); + input_sizes_idx_0 = 0; + for (int32_T i{0}; i <= end; i++) { + if (r1[i]) { + r3[input_sizes_idx_0] = i + 1; + input_sizes_idx_0++; + } + } + + if (r2.size(0) == r3.size(0)) { + input_sizes_idx_0 = r2.size(0); + for (int32_T i{0}; i < input_sizes_idx_0; i++) { + newDataPoints[i] = 0.5 * (dataPoints[r2[i] - 1] + dataPoints[r3[i] - 1]); + } + } else { + binary_expand_op(newDataPoints, dataPoints, r2, r3); + } + + b_newDataPoints.set_size(newDataPoints.size(0)); + input_sizes_idx_0 = newDataPoints.size(0); + for (int32_T i{0}; i < input_sizes_idx_0; i++) { + b_newDataPoints[i] = newDataPoints[i]; + } + + normalizeFunction(b_newDataPoints, sldProfile, r4); + input_sizes_idx_0 = r4.size(0); + for (int32_T i{0}; i < input_sizes_idx_0; i++) { + newDataPoints[i + newDataPoints.size(0)] = r4[i]; + } + + // For simplicity append the new points at the end and then sort. + if (newDataPoints.size(0) != 0) { + input_sizes_idx_0 = newDataPoints.size(0); + } else { + input_sizes_idx_0 = 0; + } + + if (dataPoints.size(0) != 0) { + end = dataPoints.size(0); + } else { + end = 0; + } + + b_dataPoints.set_size(end + input_sizes_idx_0, 2); + for (int32_T i{0}; i < 2; i++) { + for (int32_T b_i{0}; b_i < end; b_i++) { + b_dataPoints[b_i + b_dataPoints.size(0) * i] = dataPoints[b_i + + dataPoints.size(0) * i]; + } + + for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { + b_dataPoints[(b_i + end) + b_dataPoints.size(0) * i] = newDataPoints[b_i + + newDataPoints.size(0) * i]; + } + } + + dataPoints.set_size(b_dataPoints.size(0), 2); + input_sizes_idx_0 = b_dataPoints.size(0); + for (int32_T i{0}; i < 2; i++) { + for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { + dataPoints[b_i + dataPoints.size(0) * i] = b_dataPoints[b_i + + b_dataPoints.size(0) * i]; + } + } + + coder::sortrows(dataPoints); + } + + static void normalizeFunction(const ::coder::array &x, const + real_T sldProfile_data[], const int32_T sldProfile_size[2], ::coder::array< + real_T, 1U> &y) + { + real_T tmp_data[1000]; + int32_T i; + int32_T tmp_size; + + // Subfunctions + // NORMALIZEFUNCTION evaluates a function and returns a NxM array, where N + // is the number of elements of x and M is the number of outputs of func. + // All the outputs of func must be scalar. + // The optional parameter 'vectorizable' (default false) allows to specify + // that the input function can be vectorized. + // Modified by AVH for use with coder + // if (~exist('vectorizable','var') || isempty(vectorizable)) + // end + // abs(nargout(func)); %for anonymous functions nargout<0 + y.set_size(x.size(0)); + + // if vectorizable + // % For uniformity reasons, transform the 'x' array into a column vector. + // % In this way it does not matter if it is given as a column or a row + // % vector. + // [newValues{:}] = func(x(:)); + // y = cell2mat(newValues); + // else + i = x.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + // Remove cell array so no need for cell2mat + // which won't compile - AVH + // [newValues{:}] = func(x(i)); + // y(i,:) = cell2mat(newValues); + SLDFunction(x[b_i], sldProfile_data, sldProfile_size, tmp_data, &tmp_size); + y[b_i] = tmp_data[0]; + } + + // end + } + + static void normalizeFunction(const ::coder::array &x, const :: + coder::array &sldProfile, ::coder::array &y) + { + ::coder::array r; + int32_T i; + + // Subfunctions + // NORMALIZEFUNCTION evaluates a function and returns a NxM array, where N + // is the number of elements of x and M is the number of outputs of func. + // All the outputs of func must be scalar. + // The optional parameter 'vectorizable' (default false) allows to specify + // that the input function can be vectorized. + // Modified by AVH for use with coder + // if (~exist('vectorizable','var') || isempty(vectorizable)) + // end + // abs(nargout(func)); %for anonymous functions nargout<0 + y.set_size(x.size(0)); + + // if vectorizable + // % For uniformity reasons, transform the 'x' array into a column vector. + // % In this way it does not matter if it is given as a column or a row + // % vector. + // [newValues{:}] = func(x(:)); + // y = cell2mat(newValues); + // else + i = x.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + // Remove cell array so no need for cell2mat + // which won't compile - AVH + // [newValues{:}] = func(x(i)); + // y(i,:) = cell2mat(newValues); + SLDFunction(x[b_i], sldProfile, r); + y[b_i] = r[0]; + } + + // end + } + + static void times(::coder::array &in1, const ::coder::array &in2, const ::coder::array &in3) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = in2[i * stride_0_0] * in3[i * stride_1_0]; + } + } + + void adaptive(const real_T sldProfile_data[], const int32_T sldProfile_size[2], + const real_T startDomain[2], real_T minAngle, real_T nPoints, + cell_24 *out) + { + ::coder::array b_out; + ::coder::array r; + ::coder::array cornerAngle; + ::coder::array hiVal; + ::coder::array newDomain; + ::coder::array b_trianglesToRefine; + ::coder::array r1; + ::coder::array segmentsToSplit; + ::coder::array trianglesToRefine; + int32_T loop_ub; + int32_T nRefinements; + boolean_T exitg1; + + // adaptive: evaluates a matlab function on a given range + // + // 'adaptive.m' allows to sample a function using a reduced number of + // points. It works iteratively adding new points where needed. + // It is especially useful for functions which are computationally intensive + // (e.g. involve solving a differential equation). + // + // Usage: + // XY = adaptive(func, [xstart, xend]) + // evaluates 'func' in the range [xstart, xend]. Key-value arguments are + // used to control the function evaluation. If the function 'func' returns + // multiple output values, only the first one is used for the refinement + // process, but all of them are calculated and returned as additional + // columns in the output matrix. The output matrix XY contains the new + // domain points in the first column and the output values in the other + // columns. + // [x,yy] = adaptive(func, [xstart, xend]) + // as before but separately returns the array with the domain points and + // the array/matrix with the function output values. + // [x,yy] = adaptive(func, xarray, ...) + // as before but explicitly provide an initial array of domain points. + // + // Methods: + // 'adaptive' provides three methods for refining the function evaluation: + // 1) add more points near the sharp corners, which are found by + // considering the triangles formed by three successive points and + // measuring the central angle. + // 2) measure the area of the same triangles and add more points when the + // area is bigger than a threshold. + // 3) measure the length of the segments formed by pairs of successive + // and split the segments which are longer than a threshold. + // If no methods is explicitly specified, the 'angle' method is used. + // + // Input parameters + // - func: input function (function handle) + // - initialDomain: initial domain points (1D array) + // + // Optional key-value input parameters + // - 'nPoints': (default 20) + // initial number of domain points, only used if an initial domain + // array is not excplitely provided. + // - 'maxRefinements': (default 10) + // Specifies the maximum number of refinement steps. + // - 'minAngle': (default 0.8*pi) + // Refine near the points which forms, together with their left and right + // neighbours, a triangle with central angle smaller than a given value. + // - 'maxArea': (default 5e-4) + // Refine near the points which forms, together with their left and right + // neighbours, a triangle with area larger than a threshold. The threshold + // in normalized to the area enclosing th graph: + // threshold==maxArea*(max(x)-min(x))*(max(f(x))-min(f(x))) + // - 'maxLength': (default Inf) + // Refine all the sements which are longer than a given threshold. The + // threshold is relative to the input and output ranges. Specifically, + // before applying the threshold, the data are normalized so that + // max(x)-min(x)==1 and max(f(x))-min(f(x))==1. + // - 'minLength': (default 0) + // Exclude from the refinement process the segments which are shorter + // than a given threshold. The threshold is relative to the input and + // output ranges. Specifically, before applying the threshold, the + // data are normalized so that max(x)-min(x)==1 and max(f(x))-min(f(x))==1. + // - 'minSignal': (default 0.2) + // Exclude from the refinement process the points where the function is + // below a threshold. The threshold is relative to the output range: In + // this example threshold == 0.01*(max(f(x))-min(f(x))). + // - 'vectorizable': (default false) + // Specifies whether the input function accepts arrays as input + // (e.g. f(x)==x.^2). + // - 'waitbar': (default false) + // Display a waitbar. + // + // Output parameters + // - a NxM array where N is the number of domain points and M is the number + // of output parameters of the input function. + // + // Examples: + // + // % Refine a function near sharp corners. The option 'minAngle' is useful + // % for having more points near the peaks of the function. + // f = @(x) exp(-x.^2/4).*sin(3*x); + // % for test-purpose also evaluate the function directly + // x2 = -10:0.01:10; + // y2 = f(x2); + // y = adaptive(f, [-5,5], 'minAngle',0.8*pi); + // figure(1); plot(x2,f(x2),'k--',y(:,1),y(:,2),'o-'); + // legend('high sampling','adaptive') + // title('y = adaptive(f, [xstart, xend], ''minAngle'',0.8*pi)') + // % as before but starting with an inital array of domain points + // x = -5:5; + // y = adaptive(f, x, 'minAngle',0.8*pi); + // figure(2); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); + // legend('initial sampling','high sampling','adaptive') + // title('y = adaptive(f, x, ''minAngle'',0.8*pi)') + // + // % Refine a function near sharp corners, but do not split segments which + // % are already shorter than 'minLength'. + // y = adaptive(f, x, 'minAngle',0.8*pi, 'minLength',0.05); + // figure(3); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); + // legend('initial sampling','high sampling','adaptive') + // title('y = adaptive(f, x, ''minAngle'',0.8*pi, ''minLength'',0.05)'); + // + // % Refine a function until the areas of the triangles formed by + // % triplets of successive points are smaller than 'maxArea'. + // y = adaptive(f, x, 'maxArea',1e-3); + // figure(4); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); + // legend('initial sampling','high sampling','adaptive') + // title('y = adaptive(f, x, ''maxArea'',1e-3)') + // + // % Refine a function until the segments formed by pairs of successive + // % points are shorter than 'maxLength'. + // y = adaptive(f, x, 'maxLength',0.1); + // figure(5); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); + // legend('initial sampling','high sampling','adaptive') + // title('y = adaptive(f, x, ''maxLength'',0.1)'); + // Copyright + // 2017, Alberto Comin - LMU Muenchen + // Version changes: + // + // 24/01/2017: 1) new default: when no optional argument is given, use the + // 'angle' method as default 2) it is now possible to provide just the + // start and the end of the function domain, instead of having to + // explicitly provide an initial array 3) a new key-word argument + // 'nPoints' controls the number of initial domain points in the cases when + // the initial array is not explicitly provided. 4) it is now possible to + // return the domain points and the function values either as a single 2D + // array or as two separate arrays. + // 25/01/2017: fixed defaults for the case when no method is specified + // Default settings + // nPoints = 20; + // minAngle = 0.8*pi; + // units normalized to data range + // Test-mode + // The test mode is activated by calling 'adaptive.m' with no input. + // if nargin==0 + // initialDomain = -10:10; + // input_func = @(x) 100*exp(-(x+5.2).^2) + 50*exp(-5*(x-0.5).^2)+ 20*exp(-10*(x-5.8).^2); + // thresholdingAngles = true; + // minAngle = 0.8*pi; + // thresholdingLength = true; + // minLength = 0.02; + // disp('Running adaptive.m in test mode'); + // fprintf('input function: %s\n',func2str(input_func)); + // disp('Plotting the function on a initial set of points'); + // testFigureHandle = figure(); + // plot(initialDomain, input_func(initialDomain),'bs-','LineWidth',1.5); + // grid on; xlabel('x'); ylabel('y'); title('adaptive.m example'); + // end + // Processing input arguments + // assert(isa(input_func,'function_handle'),'adaptiveFunctionEvaluation:ArgChk',... + // 'the first argument must be a function handle'); + // assert(isnumeric(initialDomain) && isvector(initialDomain),... + // 'adaptiveFunctionEvaluation:ArgChk','initial points must be specified as a numeric vector'); + // + // nExtraArgIn = numel(varargin); + // if mod(nExtraArgIn,2)==1 + // error('adaptiveFunctionEvaluation:ArgChk', ... + // 'At least a key or a value is missing in the key-value arguments list.'); + // end + // usingDefaultMethod = true; + // n = 1; + // minAngle = 0.7 * pi; + // thresholdingAngles = true; + // nPoints = 50; + // while n < nExtraArgIn + // switch lower(varargin{n}) + // case 'minangle' + // minAngle = varargin{n+1}; + // n = n+2; + // case 'maxarea' + // maxArea = varargin{n+1}; + // thresholdingArea = true; + // usingDefaultMethod = false; + // n = n+2; + // case 'maxlength' + // maxLength = varargin{n+1}; + // thresholdingLength = true; + // usingDefaultMethod = false; + // n = n+2; + // case 'minlength' + // minLength = varargin{n+1}; + // thresholdingLength = true; + // n = n+2; + // case 'minsignal' + // minSignal = varargin{n+1}; + // thresholdingSignal = true; + // n = n+2; + // case 'npoints' + // nPoints = varargin{n+1}; + // n = n+2; + // case 'vectorize' + // vectorizable = varargin{n+1}; + // n = n+2; + // case 'maxrefinements' + // maxRefinements = varargin{n+1}; + // n = n+2; + // case 'waitbar' + // displayWaitbar = varargin{n+1}; + // n = n+2; + // otherwise + // error('adaptiveFunctionEvaluation:ArgChk',... + // ['unknown keyword argument: ', varargin{n}]); + // end + // end + // if no method is specified use the 'angle' method as default + // if usingDefaultMethod + // thresholdingAngles = true; + // end + // Initial function evaluation + // if initialDomain only contains the start and the end points, create a new + // array with 'nPoints' points. + coder::linspace(startDomain[0], startDomain[1], nPoints, r); + newDomain.set_size(r.size(1)); + loop_ub = r.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + newDomain[i] = r[i]; + } + + // Normalize the input function: This step allows to use the same syntax for + // functions with single or multiple output parameters. + // Remove this syntax for compile - AVH + // func = @(x) normalizeFunction(x,sldProfile,vectorizable); + // Evaluate the input function on the initial set of points. + normalizeFunction(newDomain, sldProfile_data, sldProfile_size, hiVal); + + // dataPoints = [initialDomain(:), func(initialDomain(:))]; + out->f1.set_size(newDomain.size(0), 2); + loop_ub = newDomain.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + out->f1[i] = newDomain[i]; + } + + loop_ub = hiVal.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + out->f1[i + out->f1.size(0)] = hiVal[i]; + } + + // Iterative function refinement + // if displayWaitbar + // refinementWaitbar = waitbar(0,['Evaluating function ',func2str(func)],... + // 'CreateCancelBtn','setappdata(gcbf,''canceling'',true)'); + // setappdata(refinementWaitbar,'canceling',false) + // end + nRefinements = 0; + exitg1 = false; + while ((!exitg1) && (nRefinements < 10)) { + real_T dv[2]; + real_T dv1[2]; + boolean_T y; + + // calculate the box which encloses the current data points: + // Each point is considered as the central corner of the triangle formed + // with its left and right hand side neighbours. The first and the last + // points are not the central corner of any triangle, so for N points + // there are only N-2 triangles. + // if thresholdingArea + // triangleArea = calculateTrianglesArea(dataPoints(:,1:2)); + // bigTriangles = triangleArea > (maxArea * dataBoxArea); + // trianglesToRefine = trianglesToRefine | bigTriangles; + // end + b_out.set_size(out->f1.size(0), 2); + loop_ub = out->f1.size(0); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_out[i1 + b_out.size(0) * i] = out->f1[i1 + out->f1.size(0) * i]; + } + } + + coder::internal::maximum(b_out, dv); + b_out.set_size(out->f1.size(0), 2); + loop_ub = out->f1.size(0); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_out[i1 + b_out.size(0) * i] = out->f1[i1 + out->f1.size(0) * i]; + } + } + + coder::internal::minimum(b_out, dv1); + b_out.set_size(out->f1.size(0), 2); + loop_ub = out->f1.size(0); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_out[i1 + b_out.size(0) * i] = out->f1[i1 + out->f1.size(0) * i]; + } + + dv[i] -= dv1[i]; + } + + calculateCentralAngles(b_out, dv, cornerAngle); + if (out->f1.size(0) - 2 == cornerAngle.size(0)) { + trianglesToRefine.set_size(out->f1.size(0) - 2); + loop_ub = out->f1.size(0) - 2; + for (int32_T i{0}; i < loop_ub; i++) { + trianglesToRefine[i] = (cornerAngle[i] < minAngle); + } + } else { + b_binary_expand_op(trianglesToRefine, out, cornerAngle, minAngle); + } + + // For N points there are N-2 triangles and N-1 triangle sides. Each + // triangle side is a segment, which can be split or not depending on the + // refinement parameters. + b_trianglesToRefine.set_size(trianglesToRefine.size(0) + 1); + loop_ub = trianglesToRefine.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_trianglesToRefine[i] = trianglesToRefine[i]; + } + + b_trianglesToRefine[trianglesToRefine.size(0)] = false; + r1.set_size(trianglesToRefine.size(0) + 1); + r1[0] = false; + loop_ub = trianglesToRefine.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + r1[i + 1] = trianglesToRefine[i]; + } + + segmentsToSplit.set_size(b_trianglesToRefine.size(0)); + loop_ub = b_trianglesToRefine.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + segmentsToSplit[i] = (b_trianglesToRefine[i] || r1[i]); + } + + // if thresholdingLength + // dataSegments = diff(dataPoints(:,1:2)); + // normalizedSegments = bsxfun(@rdivide, dataSegments, dataBoxSize); + // segmentsLengthNormalized = hypot(normalizedSegments(:,1), normalizedSegments(:,2)); + // tooLongSegments = segmentsLengthNormalized > maxLength; + // longEnoughSegments = segmentsLengthNormalized > minLength; + // segmentsToSplit = (segmentsToSplit | tooLongSegments) & longEnoughSegments; + // end + // if thresholdingSignal + // segmentsCenters = (dataPoints(1:end-1,2)+dataPoints(2:end,2))/2; + // centerAboveThreshold = segmentsCenters > minSignal * max(abs(dataPoints(:,2))); + // segmentsToSplit = segmentsToSplit & centerAboveThreshold; + // end + y = coder::internal::allOrAny_anonFcn3(segmentsToSplit.size(0), + segmentsToSplit); + if (y) { + b_increaseSampling(out->f1, segmentsToSplit, sldProfile_data, + sldProfile_size); + + // Removed waitbar for compile - AVH + // if displayWaitbar + // if getappdata(refinementWaitbar,'canceling'), break; end + // waitbar(nRefinements/maxRefinements,refinementWaitbar); + // end + nRefinements++; + } else { + exitg1 = true; + } + } + + // if displayWaitbar + // delete(refinementWaitbar); + // end + // Plotting refined function + // Removed for compile - AVH + // if nargin==0 % test mode + // figure(testFigureHandle); + // hold on; + // plot(dataPoints(:,1), dataPoints(:,2),'ro-'); + // legend('initial', 'refiniment'); + // end + // if nargout==1 + // elseif nargout>1 + // out{1} = dataPoints(:,1); + // out{2} = dataPoints(:,2:end); + // end + } + + void adaptive(const ::coder::array &sldProfile, const real_T + startDomain[2], real_T minAngle, real_T nPoints, cell_24 *out) + { + ::coder::array b_out; + ::coder::array r; + ::coder::array cornerAngle; + ::coder::array hiVal; + ::coder::array newDomain; + ::coder::array b_trianglesToRefine; + ::coder::array r1; + ::coder::array segmentsToSplit; + ::coder::array trianglesToRefine; + int32_T loop_ub; + int32_T nRefinements; + boolean_T exitg1; + + // adaptive: evaluates a matlab function on a given range + // + // 'adaptive.m' allows to sample a function using a reduced number of + // points. It works iteratively adding new points where needed. + // It is especially useful for functions which are computationally intensive + // (e.g. involve solving a differential equation). + // + // Usage: + // XY = adaptive(func, [xstart, xend]) + // evaluates 'func' in the range [xstart, xend]. Key-value arguments are + // used to control the function evaluation. If the function 'func' returns + // multiple output values, only the first one is used for the refinement + // process, but all of them are calculated and returned as additional + // columns in the output matrix. The output matrix XY contains the new + // domain points in the first column and the output values in the other + // columns. + // [x,yy] = adaptive(func, [xstart, xend]) + // as before but separately returns the array with the domain points and + // the array/matrix with the function output values. + // [x,yy] = adaptive(func, xarray, ...) + // as before but explicitly provide an initial array of domain points. + // + // Methods: + // 'adaptive' provides three methods for refining the function evaluation: + // 1) add more points near the sharp corners, which are found by + // considering the triangles formed by three successive points and + // measuring the central angle. + // 2) measure the area of the same triangles and add more points when the + // area is bigger than a threshold. + // 3) measure the length of the segments formed by pairs of successive + // and split the segments which are longer than a threshold. + // If no methods is explicitly specified, the 'angle' method is used. + // + // Input parameters + // - func: input function (function handle) + // - initialDomain: initial domain points (1D array) + // + // Optional key-value input parameters + // - 'nPoints': (default 20) + // initial number of domain points, only used if an initial domain + // array is not excplitely provided. + // - 'maxRefinements': (default 10) + // Specifies the maximum number of refinement steps. + // - 'minAngle': (default 0.8*pi) + // Refine near the points which forms, together with their left and right + // neighbours, a triangle with central angle smaller than a given value. + // - 'maxArea': (default 5e-4) + // Refine near the points which forms, together with their left and right + // neighbours, a triangle with area larger than a threshold. The threshold + // in normalized to the area enclosing th graph: + // threshold==maxArea*(max(x)-min(x))*(max(f(x))-min(f(x))) + // - 'maxLength': (default Inf) + // Refine all the sements which are longer than a given threshold. The + // threshold is relative to the input and output ranges. Specifically, + // before applying the threshold, the data are normalized so that + // max(x)-min(x)==1 and max(f(x))-min(f(x))==1. + // - 'minLength': (default 0) + // Exclude from the refinement process the segments which are shorter + // than a given threshold. The threshold is relative to the input and + // output ranges. Specifically, before applying the threshold, the + // data are normalized so that max(x)-min(x)==1 and max(f(x))-min(f(x))==1. + // - 'minSignal': (default 0.2) + // Exclude from the refinement process the points where the function is + // below a threshold. The threshold is relative to the output range: In + // this example threshold == 0.01*(max(f(x))-min(f(x))). + // - 'vectorizable': (default false) + // Specifies whether the input function accepts arrays as input + // (e.g. f(x)==x.^2). + // - 'waitbar': (default false) + // Display a waitbar. + // + // Output parameters + // - a NxM array where N is the number of domain points and M is the number + // of output parameters of the input function. + // + // Examples: + // + // % Refine a function near sharp corners. The option 'minAngle' is useful + // % for having more points near the peaks of the function. + // f = @(x) exp(-x.^2/4).*sin(3*x); + // % for test-purpose also evaluate the function directly + // x2 = -10:0.01:10; + // y2 = f(x2); + // y = adaptive(f, [-5,5], 'minAngle',0.8*pi); + // figure(1); plot(x2,f(x2),'k--',y(:,1),y(:,2),'o-'); + // legend('high sampling','adaptive') + // title('y = adaptive(f, [xstart, xend], ''minAngle'',0.8*pi)') + // % as before but starting with an inital array of domain points + // x = -5:5; + // y = adaptive(f, x, 'minAngle',0.8*pi); + // figure(2); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); + // legend('initial sampling','high sampling','adaptive') + // title('y = adaptive(f, x, ''minAngle'',0.8*pi)') + // + // % Refine a function near sharp corners, but do not split segments which + // % are already shorter than 'minLength'. + // y = adaptive(f, x, 'minAngle',0.8*pi, 'minLength',0.05); + // figure(3); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); + // legend('initial sampling','high sampling','adaptive') + // title('y = adaptive(f, x, ''minAngle'',0.8*pi, ''minLength'',0.05)'); + // + // % Refine a function until the areas of the triangles formed by + // % triplets of successive points are smaller than 'maxArea'. + // y = adaptive(f, x, 'maxArea',1e-3); + // figure(4); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); + // legend('initial sampling','high sampling','adaptive') + // title('y = adaptive(f, x, ''maxArea'',1e-3)') + // + // % Refine a function until the segments formed by pairs of successive + // % points are shorter than 'maxLength'. + // y = adaptive(f, x, 'maxLength',0.1); + // figure(5); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); + // legend('initial sampling','high sampling','adaptive') + // title('y = adaptive(f, x, ''maxLength'',0.1)'); + // Copyright + // 2017, Alberto Comin - LMU Muenchen + // Version changes: + // + // 24/01/2017: 1) new default: when no optional argument is given, use the + // 'angle' method as default 2) it is now possible to provide just the + // start and the end of the function domain, instead of having to + // explicitly provide an initial array 3) a new key-word argument + // 'nPoints' controls the number of initial domain points in the cases when + // the initial array is not explicitly provided. 4) it is now possible to + // return the domain points and the function values either as a single 2D + // array or as two separate arrays. + // 25/01/2017: fixed defaults for the case when no method is specified + // Default settings + // nPoints = 20; + // minAngle = 0.8*pi; + // units normalized to data range + // Test-mode + // The test mode is activated by calling 'adaptive.m' with no input. + // if nargin==0 + // initialDomain = -10:10; + // input_func = @(x) 100*exp(-(x+5.2).^2) + 50*exp(-5*(x-0.5).^2)+ 20*exp(-10*(x-5.8).^2); + // thresholdingAngles = true; + // minAngle = 0.8*pi; + // thresholdingLength = true; + // minLength = 0.02; + // disp('Running adaptive.m in test mode'); + // fprintf('input function: %s\n',func2str(input_func)); + // disp('Plotting the function on a initial set of points'); + // testFigureHandle = figure(); + // plot(initialDomain, input_func(initialDomain),'bs-','LineWidth',1.5); + // grid on; xlabel('x'); ylabel('y'); title('adaptive.m example'); + // end + // Processing input arguments + // assert(isa(input_func,'function_handle'),'adaptiveFunctionEvaluation:ArgChk',... + // 'the first argument must be a function handle'); + // assert(isnumeric(initialDomain) && isvector(initialDomain),... + // 'adaptiveFunctionEvaluation:ArgChk','initial points must be specified as a numeric vector'); + // + // nExtraArgIn = numel(varargin); + // if mod(nExtraArgIn,2)==1 + // error('adaptiveFunctionEvaluation:ArgChk', ... + // 'At least a key or a value is missing in the key-value arguments list.'); + // end + // usingDefaultMethod = true; + // n = 1; + // minAngle = 0.7 * pi; + // thresholdingAngles = true; + // nPoints = 50; + // while n < nExtraArgIn + // switch lower(varargin{n}) + // case 'minangle' + // minAngle = varargin{n+1}; + // n = n+2; + // case 'maxarea' + // maxArea = varargin{n+1}; + // thresholdingArea = true; + // usingDefaultMethod = false; + // n = n+2; + // case 'maxlength' + // maxLength = varargin{n+1}; + // thresholdingLength = true; + // usingDefaultMethod = false; + // n = n+2; + // case 'minlength' + // minLength = varargin{n+1}; + // thresholdingLength = true; + // n = n+2; + // case 'minsignal' + // minSignal = varargin{n+1}; + // thresholdingSignal = true; + // n = n+2; + // case 'npoints' + // nPoints = varargin{n+1}; + // n = n+2; + // case 'vectorize' + // vectorizable = varargin{n+1}; + // n = n+2; + // case 'maxrefinements' + // maxRefinements = varargin{n+1}; + // n = n+2; + // case 'waitbar' + // displayWaitbar = varargin{n+1}; + // n = n+2; + // otherwise + // error('adaptiveFunctionEvaluation:ArgChk',... + // ['unknown keyword argument: ', varargin{n}]); + // end + // end + // if no method is specified use the 'angle' method as default + // if usingDefaultMethod + // thresholdingAngles = true; + // end + // Initial function evaluation + // if initialDomain only contains the start and the end points, create a new + // array with 'nPoints' points. + coder::linspace(startDomain[0], startDomain[1], nPoints, r); + newDomain.set_size(r.size(1)); + loop_ub = r.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + newDomain[i] = r[i]; + } + + // Normalize the input function: This step allows to use the same syntax for + // functions with single or multiple output parameters. + // Remove this syntax for compile - AVH + // func = @(x) normalizeFunction(x,sldProfile,vectorizable); + // Evaluate the input function on the initial set of points. + normalizeFunction(newDomain, sldProfile, hiVal); + + // dataPoints = [initialDomain(:), func(initialDomain(:))]; + out->f1.set_size(newDomain.size(0), 2); + loop_ub = newDomain.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + out->f1[i] = newDomain[i]; + } + + loop_ub = hiVal.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + out->f1[i + out->f1.size(0)] = hiVal[i]; + } + + // Iterative function refinement + // if displayWaitbar + // refinementWaitbar = waitbar(0,['Evaluating function ',func2str(func)],... + // 'CreateCancelBtn','setappdata(gcbf,''canceling'',true)'); + // setappdata(refinementWaitbar,'canceling',false) + // end + nRefinements = 0; + exitg1 = false; + while ((!exitg1) && (nRefinements < 10)) { + real_T dv[2]; + real_T dv1[2]; + boolean_T y; + + // calculate the box which encloses the current data points: + // Each point is considered as the central corner of the triangle formed + // with its left and right hand side neighbours. The first and the last + // points are not the central corner of any triangle, so for N points + // there are only N-2 triangles. + // if thresholdingArea + // triangleArea = calculateTrianglesArea(dataPoints(:,1:2)); + // bigTriangles = triangleArea > (maxArea * dataBoxArea); + // trianglesToRefine = trianglesToRefine | bigTriangles; + // end + b_out.set_size(out->f1.size(0), 2); + loop_ub = out->f1.size(0); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_out[i1 + b_out.size(0) * i] = out->f1[i1 + out->f1.size(0) * i]; + } + } + + coder::internal::maximum(b_out, dv); + b_out.set_size(out->f1.size(0), 2); + loop_ub = out->f1.size(0); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_out[i1 + b_out.size(0) * i] = out->f1[i1 + out->f1.size(0) * i]; + } + } + + coder::internal::minimum(b_out, dv1); + b_out.set_size(out->f1.size(0), 2); + loop_ub = out->f1.size(0); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_out[i1 + b_out.size(0) * i] = out->f1[i1 + out->f1.size(0) * i]; + } + + dv[i] -= dv1[i]; + } + + calculateCentralAngles(b_out, dv, cornerAngle); + if (out->f1.size(0) - 2 == cornerAngle.size(0)) { + trianglesToRefine.set_size(out->f1.size(0) - 2); + loop_ub = out->f1.size(0) - 2; + for (int32_T i{0}; i < loop_ub; i++) { + trianglesToRefine[i] = (cornerAngle[i] < minAngle); + } + } else { + b_binary_expand_op(trianglesToRefine, out, cornerAngle, minAngle); + } + + // For N points there are N-2 triangles and N-1 triangle sides. Each + // triangle side is a segment, which can be split or not depending on the + // refinement parameters. + b_trianglesToRefine.set_size(trianglesToRefine.size(0) + 1); + loop_ub = trianglesToRefine.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_trianglesToRefine[i] = trianglesToRefine[i]; + } + + b_trianglesToRefine[trianglesToRefine.size(0)] = false; + r1.set_size(trianglesToRefine.size(0) + 1); + r1[0] = false; + loop_ub = trianglesToRefine.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + r1[i + 1] = trianglesToRefine[i]; + } + + segmentsToSplit.set_size(b_trianglesToRefine.size(0)); + loop_ub = b_trianglesToRefine.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + segmentsToSplit[i] = (b_trianglesToRefine[i] || r1[i]); + } + + // if thresholdingLength + // dataSegments = diff(dataPoints(:,1:2)); + // normalizedSegments = bsxfun(@rdivide, dataSegments, dataBoxSize); + // segmentsLengthNormalized = hypot(normalizedSegments(:,1), normalizedSegments(:,2)); + // tooLongSegments = segmentsLengthNormalized > maxLength; + // longEnoughSegments = segmentsLengthNormalized > minLength; + // segmentsToSplit = (segmentsToSplit | tooLongSegments) & longEnoughSegments; + // end + // if thresholdingSignal + // segmentsCenters = (dataPoints(1:end-1,2)+dataPoints(2:end,2))/2; + // centerAboveThreshold = segmentsCenters > minSignal * max(abs(dataPoints(:,2))); + // segmentsToSplit = segmentsToSplit & centerAboveThreshold; + // end + y = coder::internal::allOrAny_anonFcn3(segmentsToSplit.size(0), + segmentsToSplit); + if (y) { + increaseSampling(out->f1, segmentsToSplit, sldProfile); + + // Removed waitbar for compile - AVH + // if displayWaitbar + // if getappdata(refinementWaitbar,'canceling'), break; end + // waitbar(nRefinements/maxRefinements,refinementWaitbar); + // end + nRefinements++; + } else { + exitg1 = true; + } + } + + // if displayWaitbar + // delete(refinementWaitbar); + // end + // Plotting refined function + // Removed for compile - AVH + // if nargin==0 % test mode + // figure(testFigureHandle); + // hold on; + // plot(dataPoints(:,1), dataPoints(:,2),'ro-'); + // legend('initial', 'refiniment'); + // end + // if nargout==1 + // elseif nargout>1 + // out{1} = dataPoints(:,1); + // out{2} = dataPoints(:,2:end); + // end + } +} + +// End of code generation (adaptive.cpp) diff --git a/RAT/adaptive.h b/RAT/adaptive.h new file mode 100644 index 00000000..1103dc68 --- /dev/null +++ b/RAT/adaptive.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// adaptive.h +// +// Code generation for function 'adaptive' +// +#ifndef ADAPTIVE_H +#define ADAPTIVE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_24; +} + +// Function Declarations +namespace RAT +{ + void adaptive(const real_T sldProfile_data[], const int32_T sldProfile_size[2], + const real_T startDomain[2], real_T minAngle, real_T nPoints, + cell_24 *out); + void adaptive(const ::coder::array &sldProfile, const real_T + startDomain[2], real_T minAngle, real_T nPoints, cell_24 *out); +} + +#endif + +// End of code generation (adaptive.h) diff --git a/RAT/allOrAny.cpp b/RAT/allOrAny.cpp new file mode 100644 index 00000000..efd9eaed --- /dev/null +++ b/RAT/allOrAny.cpp @@ -0,0 +1,47 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// allOrAny.cpp +// +// Code generation for function 'allOrAny' +// + +// Include files +#include "allOrAny.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T allOrAny_anonFcn3(int32_T n, const ::coder::array + &X) + { + int32_T k; + boolean_T exitg1; + boolean_T varargout_1; + varargout_1 = false; + k = 0; + exitg1 = false; + while ((!exitg1) && (k <= n - 1)) { + if (X[k]) { + varargout_1 = true; + exitg1 = true; + } else { + k++; + } + } + + return varargout_1; + } + } + } +} + +// End of code generation (allOrAny.cpp) diff --git a/RAT/allOrAny.h b/RAT/allOrAny.h new file mode 100644 index 00000000..9bcd4449 --- /dev/null +++ b/RAT/allOrAny.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// allOrAny.h +// +// Code generation for function 'allOrAny' +// +#ifndef ALLORANY_H +#define ALLORANY_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T allOrAny_anonFcn3(int32_T n, const ::coder::array + &X); + } + } +} + +#endif + +// End of code generation (allOrAny.h) diff --git a/RAT/allocateLayersForContrast.cpp b/RAT/allocateLayersForContrast.cpp new file mode 100644 index 00000000..b2410788 --- /dev/null +++ b/RAT/allocateLayersForContrast.cpp @@ -0,0 +1,86 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// allocateLayersForContrast.cpp +// +// Code generation for function 'allocateLayersForContrast' +// + +// Include files +#include "allocateLayersForContrast.h" +#include "length.h" +#include "nullAssignment.h" +#include "reflectivityCalculation_internal_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + void allocateLayersForContrast(const ::coder::array + &contrastLayers, const ::coder::array + &outParameterisedLayers, boolean_T useImaginary, real_T + thisContrastLayers_data[], int32_T thisContrastLayers_size[2]) + { + int32_T i; + int32_T n; + + // Decide which layers are needed for a particular contrast. + // This function takes the master array of all layers + // and extracts which parameters are required for + // a particular contrast. + // + // INPUTS: + // outParameterisedLayers - List of all the available layers + // thisContrastLayers - Array detailing which layers are required for this contrast + if (useImaginary) { + n = coder::internal::intlength(contrastLayers.size(0), contrastLayers.size + (1)); + thisContrastLayers_size[0] = n; + thisContrastLayers_size[1] = 6; + for (i = 0; i < 6; i++) { + for (int32_T i1{0}; i1 < n; i1++) { + thisContrastLayers_data[i1 + n * i] = 0.0; + } + } + } else { + n = coder::internal::intlength(contrastLayers.size(0), contrastLayers.size + (1)); + thisContrastLayers_size[0] = n; + thisContrastLayers_size[1] = 5; + for (i = 0; i < 5; i++) { + for (int32_T i1{0}; i1 < n; i1++) { + thisContrastLayers_data[i1 + n * i] = 0.0; + } + } + } + + i = coder::internal::intlength(contrastLayers.size(0), contrastLayers.size(1)); + for (int32_T b_i{0}; b_i < i; b_i++) { + if (contrastLayers[b_i] != 0.0) { + // % Check the length of thisLayer. If it's 6, then we have an + // % imaginary SLD defined. Combile them into one complex number at + // % this point. + // if length(thisLayer) == 6 + // compSLD = complex(thisLayer(2),thisLayer(3)); + // thisLayer = [thisLayer(1) compSLD thisLayer(4:end)]; + // end + n = outParameterisedLayers[static_cast(contrastLayers[b_i]) - 1] + .f1.size[1]; + for (int32_T i1{0}; i1 < n; i1++) { + thisContrastLayers_data[b_i + thisContrastLayers_size[0] * i1] = + outParameterisedLayers[static_cast(contrastLayers[b_i]) - 1] + .f1.data[i1]; + } + } else { + coder::internal::nullAssignment(thisContrastLayers_data, + thisContrastLayers_size); + } + } + } +} + +// End of code generation (allocateLayersForContrast.cpp) diff --git a/RAT/allocateLayersForContrast.h b/RAT/allocateLayersForContrast.h new file mode 100644 index 00000000..fb9a622b --- /dev/null +++ b/RAT/allocateLayersForContrast.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// allocateLayersForContrast.h +// +// Code generation for function 'allocateLayersForContrast' +// +#ifndef ALLOCATELAYERSFORCONTRAST_H +#define ALLOCATELAYERSFORCONTRAST_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void allocateLayersForContrast(const ::coder::array + &contrastLayers, const ::coder::array + &outParameterisedLayers, boolean_T useImaginary, real_T + thisContrastLayers_data[], int32_T thisContrastLayers_size[2]); +} + +#endif + +// End of code generation (allocateLayersForContrast.h) diff --git a/RAT/allocateParamsToLayers.cpp b/RAT/allocateParamsToLayers.cpp new file mode 100644 index 00000000..07841532 --- /dev/null +++ b/RAT/allocateParamsToLayers.cpp @@ -0,0 +1,72 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// allocateParamsToLayers.cpp +// +// Code generation for function 'allocateParamsToLayers' +// + +// Include files +#include "allocateParamsToLayers.h" +#include "length.h" +#include "reflectivityCalculation_internal_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include +#include + +// Function Definitions +namespace RAT +{ + void allocateParamsToLayers(const ::coder::array ¶ms, const :: + coder::array &layersDetails, ::coder::array &outLayers) + { + real_T thisOutLayer_data[10]; + int32_T i; + + // Allocates parameters from the parameter array to the correct layers + // + // This function takes the list of all layers in 'layersDetails', + // then loops over all the layers, putting in the correct + // parameter value from the parameters array into each layer in + // the 'outLayers' cell array + i = layersDetails.size(0); + outLayers.set_size(1, layersDetails.size(0)); + for (int32_T b_i{0}; b_i < i; b_i++) { + int32_T i1; + int32_T n; + n = coder::internal::intlength(layersDetails[b_i].f1.size(0), + layersDetails[b_i].f1.size(1)); + if (n - 1 >= 0) { + std::memset(&thisOutLayer_data[0], 0, static_cast(n) * sizeof + (real_T)); + } + + i1 = coder::internal::intlength(layersDetails[b_i].f1.size(0), + layersDetails[b_i].f1.size(1)); + for (int32_T b_n{0}; b_n <= i1 - 2; b_n++) { + if (!std::isnan(layersDetails[b_i].f1[b_n])) { + thisOutLayer_data[b_n] = params[static_cast(layersDetails[b_i] + .f1[b_n]) - 1]; + } else { + thisOutLayer_data[b_n] = rtNaN; + } + } + + thisOutLayer_data[coder::internal::intlength(layersDetails[b_i].f1.size(0), + layersDetails[b_i].f1.size(1)) - 1] = layersDetails[b_i] + .f1[layersDetails[b_i].f1.size(0) * layersDetails[b_i].f1.size(1) - 1]; + outLayers[b_i].f1.size[0] = 1; + outLayers[b_i].f1.size[1] = n; + for (i1 = 0; i1 < n; i1++) { + outLayers[b_i].f1.data[i1] = thisOutLayer_data[i1]; + } + } + } +} + +// End of code generation (allocateParamsToLayers.cpp) diff --git a/RAT/allocateParamsToLayers.h b/RAT/allocateParamsToLayers.h new file mode 100644 index 00000000..358372b8 --- /dev/null +++ b/RAT/allocateParamsToLayers.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// allocateParamsToLayers.h +// +// Code generation for function 'allocateParamsToLayers' +// +#ifndef ALLOCATEPARAMSTOLAYERS_H +#define ALLOCATEPARAMSTOLAYERS_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void allocateParamsToLayers(const ::coder::array ¶ms, const :: + coder::array &layersDetails, ::coder::array &outLayers); +} + +#endif + +// End of code generation (allocateParamsToLayers.h) diff --git a/RAT/applyBackgroundCorrection.cpp b/RAT/applyBackgroundCorrection.cpp new file mode 100644 index 00000000..6248d64e --- /dev/null +++ b/RAT/applyBackgroundCorrection.cpp @@ -0,0 +1,77 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// applyBackgroundCorrection.cpp +// +// Code generation for function 'applyBackgroundCorrection' +// + +// Include files +#include "applyBackgroundCorrection.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void applyBackgroundCorrection(::coder::array &reflect, ::coder:: + array &Simul, ::coder::array &shifted_dat, real_T + backg, real_T backsType) + { + ::coder::array b_reflect; + switch (static_cast(backsType)) { + case 1: + { + int32_T loop_ub; + + // Add background to the simulation + b_reflect.set_size(reflect.size(0)); + loop_ub = reflect.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_reflect[i] = reflect[i + reflect.size(0)] + backg; + } + + loop_ub = b_reflect.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + reflect[i + reflect.size(0)] = b_reflect[i]; + } + + b_reflect.set_size(Simul.size(0)); + loop_ub = Simul.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_reflect[i] = Simul[i + Simul.size(0)] + backg; + } + + loop_ub = b_reflect.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + Simul[i + Simul.size(0)] = b_reflect[i]; + } + } + break; + + case 2: + { + int32_T loop_ub; + + // %Subtract the background from the data.. + b_reflect.set_size(shifted_dat.size(0)); + loop_ub = shifted_dat.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_reflect[i] = shifted_dat[i + shifted_dat.size(0)] - backg; + } + + loop_ub = b_reflect.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + shifted_dat[i + shifted_dat.size(0)] = b_reflect[i]; + } + + // shifted_dat(:,3) = shifted_dat(:,3) - backg; + } + break; + } + } +} + +// End of code generation (applyBackgroundCorrection.cpp) diff --git a/RAT/applyBackgroundCorrection.h b/RAT/applyBackgroundCorrection.h new file mode 100644 index 00000000..984865b1 --- /dev/null +++ b/RAT/applyBackgroundCorrection.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// applyBackgroundCorrection.h +// +// Code generation for function 'applyBackgroundCorrection' +// +#ifndef APPLYBACKGROUNDCORRECTION_H +#define APPLYBACKGROUNDCORRECTION_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void applyBackgroundCorrection(::coder::array &reflect, ::coder:: + array &Simul, ::coder::array &shifted_dat, real_T + backg, real_T backsType); +} + +#endif + +// End of code generation (applyBackgroundCorrection.h) diff --git a/RAT/asinh.cpp b/RAT/asinh.cpp new file mode 100644 index 00000000..23f39b25 --- /dev/null +++ b/RAT/asinh.cpp @@ -0,0 +1,54 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// asinh.cpp +// +// Code generation for function 'asinh' +// + +// Include files +#include "asinh.h" +#include "log1p.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace scalar + { + void b_asinh(real_T *x) + { + boolean_T xneg; + xneg = (*x < 0.0); + if (xneg) { + *x = -*x; + } + + if (*x >= 2.68435456E+8) { + *x = std::log(*x) + 0.69314718055994529; + } else if (*x > 2.0) { + *x = std::log(2.0 * *x + 1.0 / (std::sqrt(*x * *x + 1.0) + *x)); + } else { + real_T t; + t = *x * *x; + *x += t / (std::sqrt(t + 1.0) + 1.0); + b_log1p(x); + } + + if (xneg) { + *x = -*x; + } + } + } + } + } +} + +// End of code generation (asinh.cpp) diff --git a/RAT/asinh.h b/RAT/asinh.h new file mode 100644 index 00000000..c03bcc04 --- /dev/null +++ b/RAT/asinh.h @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// asinh.h +// +// Code generation for function 'asinh' +// +#ifndef ASINH_H +#define ASINH_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace scalar + { + void b_asinh(real_T *x); + } + } + } +} + +#endif + +// End of code generation (asinh.h) diff --git a/RAT/asymconvstep.cpp b/RAT/asymconvstep.cpp new file mode 100644 index 00000000..78b16eb0 --- /dev/null +++ b/RAT/asymconvstep.cpp @@ -0,0 +1,171 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// asymconvstep.cpp +// +// Code generation for function 'asymconvstep' +// + +// Include files +#include "asymconvstep.h" +#include "eml_mtimes_helper.h" +#include "erf.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void asymconvstep(const ::coder::array &x, real_T xw, real_T xcen, + real_T s1, real_T s2, real_T h, ::coder::array + &f) + { + ::coder::array b_r; + ::coder::array b_x; + ::coder::array r1; + real_T a; + real_T aFactor; + real_T bFactor; + real_T l; + real_T r; + int32_T loop_ub; + + // Produces a step function convoluted with differnt error functions + // on each side. + // Convstep (x,xw,xcen,s1,s2,h) + // x = vector of x values + // xw = Width of step function + // xcen = Centre point of step function + // s1 = Roughness parameter of left side + // s2 = Roughness parameter of right side + // h = Height of step function. + // if length(xw) > 1 + // ME = MException('VerifyOutput:OutOfBounds', ... + // 'xw must be single value'); + // throw(ME); + // end + // + // if length(xcen) > 1 + // ME = MException('VerifyOutput:OutOfBounds', ... + // 'xcen must be single value'); + // throw(ME); + // end + // + // if length(s1) > 1 + // ME = MException('VerifyOutput:OutOfBounds', ... + // 's1 must be single value'); + // throw(ME); + // end + // + // if length(s2) > 1 + // ME = MException('VerifyOutput:OutOfBounds', ... + // 's2 must be single value'); + // throw(ME); + // end + r = xcen + xw / 2.0; + l = xcen - xw / 2.0; + aFactor = 1.4142135623730951 * s1; + bFactor = 1.4142135623730951 * s2; + a = h / 2.0; + b_x.set_size(1, x.size(1)); + loop_ub = x.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_x[i] = (x[i] - l) / aFactor; + } + + coder::b_erf(b_x, b_r); + b_x.set_size(1, x.size(1)); + loop_ub = x.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_x[i] = (x[i] - r) / bFactor; + } + + coder::b_erf(b_x, r1); + if (b_r.size(1) == r1.size(1)) { + f.set_size(1, b_r.size(1)); + loop_ub = b_r.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + f[i] = a * (b_r[i] - r1[i]); + } + } else { + binary_expand_op(f, a, b_r, r1); + } + } + + void asymconvstep(const ::coder::array &x, real_T xw, real_T xcen, + real_T s1, real_T s2, ::coder::array &f) + { + ::coder::array b_r; + ::coder::array b_x; + ::coder::array r1; + real_T aFactor; + real_T bFactor; + real_T l; + real_T r; + int32_T loop_ub; + + // Produces a step function convoluted with differnt error functions + // on each side. + // Convstep (x,xw,xcen,s1,s2,h) + // x = vector of x values + // xw = Width of step function + // xcen = Centre point of step function + // s1 = Roughness parameter of left side + // s2 = Roughness parameter of right side + // h = Height of step function. + // if length(xw) > 1 + // ME = MException('VerifyOutput:OutOfBounds', ... + // 'xw must be single value'); + // throw(ME); + // end + // + // if length(xcen) > 1 + // ME = MException('VerifyOutput:OutOfBounds', ... + // 'xcen must be single value'); + // throw(ME); + // end + // + // if length(s1) > 1 + // ME = MException('VerifyOutput:OutOfBounds', ... + // 's1 must be single value'); + // throw(ME); + // end + // + // if length(s2) > 1 + // ME = MException('VerifyOutput:OutOfBounds', ... + // 's2 must be single value'); + // throw(ME); + // end + r = xcen + xw / 2.0; + l = xcen - xw / 2.0; + aFactor = 1.4142135623730951 * s1; + bFactor = 1.4142135623730951 * s2; + b_x.set_size(1, x.size(1)); + loop_ub = x.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_x[i] = (x[i] - l) / aFactor; + } + + coder::b_erf(b_x, b_r); + b_x.set_size(1, x.size(1)); + loop_ub = x.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_x[i] = (x[i] - r) / bFactor; + } + + coder::b_erf(b_x, r1); + if (b_r.size(1) == r1.size(1)) { + f.set_size(1, b_r.size(1)); + loop_ub = b_r.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + f[i] = 0.0 * (b_r[i] - r1[i]); + } + } else { + binary_expand_op(f, b_r, r1); + } + } +} + +// End of code generation (asymconvstep.cpp) diff --git a/RAT/asymconvstep.h b/RAT/asymconvstep.h new file mode 100644 index 00000000..422c2896 --- /dev/null +++ b/RAT/asymconvstep.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// asymconvstep.h +// +// Code generation for function 'asymconvstep' +// +#ifndef ASYMCONVSTEP_H +#define ASYMCONVSTEP_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void asymconvstep(const ::coder::array &x, real_T xw, real_T xcen, + real_T s1, real_T s2, real_T h, ::coder::array + &f); + void asymconvstep(const ::coder::array &x, real_T xw, real_T xcen, + real_T s1, real_T s2, ::coder::array &f); +} + +#endif + +// End of code generation (asymconvstep.h) diff --git a/RAT/backSort.cpp b/RAT/backSort.cpp new file mode 100644 index 00000000..03d13668 --- /dev/null +++ b/RAT/backSort.cpp @@ -0,0 +1,84 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// backSort.cpp +// +// Code generation for function 'backSort' +// + +// Include files +#include "backSort.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void backSort(real_T cBacks, real_T cShifts, real_T cScales, real_T cNbas, + real_T cNbss, real_T cRes, const ::coder::array + &backs, const ::coder::array &shifts, const ::coder:: + array &sf, const ::coder::array &nba, + const ::coder::array &nbs, const ::coder::array< + real_T, 2U> &res, real_T *backg, real_T *qshift, real_T *b_sf, + real_T *b_nba, real_T *b_nbs, real_T *resol) + { + // Distributes the background and shift values among the different contrasts + // + // USAGE:: + // + // [backg,qshift,sf,nba,nbs,resol] = backsort(cBacks,cShifts,cScales,cNbas,cNbss,cRes,backs,shifts,sf,nba,nbs,res) + // + // INPUTS: + // * cBacks : Which backround value is associated with each contrast + // * cShifts : Which qz_shift value is associated with each contrast + // * cScales : Which scalefactor value is associated with each contrast + // * cNbas : Which NBa value is associated with each contrast + // * cNbss : Which Nbs value is associated with each contrast + // * cRes : Which resolution value is associated with each contrast + // * backs : List of all background values. + // * shifts : List of all qz-shift values + // * sf : List of all scalefactor values + // * nba : List of all nba values + // * nbs : List of all nbs values + // * res : List of all resolution values + // + // OUTPUTS: + // * backgs : list of actual background values for each contrast + // * qshifts : list of actual shift values for each contrast + // * sfs : list of actual shift values for each contrast + // * nbas : list of actual shift values for each contrast + // * nbss : list of actual shift values for each contrast + // * nbss : list of actual shift values for each contrast + // + // for i = 1:nc + // thisBack = cBacks(i); + *backg = backs[static_cast(cBacks) - 1]; + + // thisShift = cShifts(i); + *qshift = shifts[static_cast(cShifts) - 1]; + + // thisScale = cScales(i); + *b_sf = sf[static_cast(cScales) - 1]; + + // thisNbair = cNbas(i); + *b_nba = nba[static_cast(cNbas) - 1]; + + // thisNbsub = cNbss(i); + *b_nbs = nbs[static_cast(cNbss) - 1]; + + // thisResol = cRes(i); + if (cRes != -1.0) { + *resol = res[static_cast(cRes) - 1]; + } else { + *resol = -1.0; + + // Negative value means we have a data resolution.. + } + + // end + } +} + +// End of code generation (backSort.cpp) diff --git a/RAT/backSort.h b/RAT/backSort.h new file mode 100644 index 00000000..cb95c8ee --- /dev/null +++ b/RAT/backSort.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// backSort.h +// +// Code generation for function 'backSort' +// +#ifndef BACKSORT_H +#define BACKSORT_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void backSort(real_T cBacks, real_T cShifts, real_T cScales, real_T cNbas, + real_T cNbss, real_T cRes, const ::coder::array + &backs, const ::coder::array &shifts, const ::coder:: + array &sf, const ::coder::array &nba, + const ::coder::array &nbs, const ::coder::array< + real_T, 2U> &res, real_T *backg, real_T *qshift, real_T *b_sf, + real_T *b_nba, real_T *b_nbs, real_T *resol); +} + +#endif + +// End of code generation (backSort.h) diff --git a/RAT/blockedSummation.cpp b/RAT/blockedSummation.cpp new file mode 100644 index 00000000..19b360a5 --- /dev/null +++ b/RAT/blockedSummation.cpp @@ -0,0 +1,175 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// blockedSummation.cpp +// +// Code generation for function 'blockedSummation' +// + +// Include files +#include "blockedSummation.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + namespace coder + { + static void nestedIter(const ::coder::array &x, int32_T vlen, :: + coder::array &y); + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + static void nestedIter(const ::coder::array &x, int32_T vlen, :: + coder::array &y) + { + ::coder::array bsum; + int32_T bsubs_idx_1; + int32_T firstBlockLength; + int32_T i; + int32_T lastBlockLength; + int32_T nblocks; + y.set_size(x.size(0)); + bsum.set_size(x.size(0)); + if (vlen <= 1024) { + firstBlockLength = vlen; + lastBlockLength = 0; + nblocks = 1; + } else { + firstBlockLength = 1024; + nblocks = vlen / 1024; + lastBlockLength = vlen - (nblocks << 10); + if (lastBlockLength > 0) { + nblocks++; + } else { + lastBlockLength = 1024; + } + } + + i = x.size(0); + for (int32_T k{0}; k < i; k++) { + y[k] = x[k]; + } + + for (int32_T k{2}; k <= firstBlockLength; k++) { + i = x.size(0); + for (int32_T b_k{0}; b_k < i; b_k++) { + if (vlen >= 2) { + y[b_k] = y[b_k] + x[b_k + x.size(0) * (k - 1)]; + } + } + } + + for (int32_T ib{2}; ib <= nblocks; ib++) { + int32_T hi; + firstBlockLength = (ib - 1) << 10; + i = x.size(0); + if (x.size(0) - 1 >= 0) { + bsubs_idx_1 = firstBlockLength + 1; + } + + for (int32_T k{0}; k < i; k++) { + bsum[k] = x[k + x.size(0) * (bsubs_idx_1 - 1)]; + } + + if (ib == nblocks) { + hi = lastBlockLength; + } else { + hi = 1024; + } + + for (int32_T k{2}; k <= hi; k++) { + int32_T varargin_1; + varargin_1 = firstBlockLength + k; + i = x.size(0); + for (int32_T b_k{0}; b_k < i; b_k++) { + if (vlen >= 2) { + bsum[b_k] = bsum[b_k] + x[b_k + x.size(0) * (varargin_1 - 1)]; + } + } + } + + i = y.size(0); + for (int32_T k{0}; k < i; k++) { + y[k] = y[k] + bsum[k]; + } + } + } + + void blockedSummation(const ::coder::array &x, int32_T vlen, :: + coder::array &y) + { + if ((x.size(0) == 0) || (x.size(1) == 0) || (vlen == 0)) { + int32_T loop_ub; + y.set_size(x.size(0)); + loop_ub = x.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + y[i] = 0.0; + } + } else { + nestedIter(x, vlen, y); + } + } + + real_T nestedIter(const ::coder::array &x, int32_T vlen) + { + real_T y; + int32_T firstBlockLength; + int32_T lastBlockLength; + int32_T nblocks; + if (vlen <= 1024) { + firstBlockLength = vlen; + lastBlockLength = 0; + nblocks = 1; + } else { + firstBlockLength = 1024; + nblocks = vlen / 1024; + lastBlockLength = vlen - (nblocks << 10); + if (lastBlockLength > 0) { + nblocks++; + } else { + lastBlockLength = 1024; + } + } + + y = x[0]; + for (int32_T k{2}; k <= firstBlockLength; k++) { + if (vlen >= 2) { + y += x[k - 1]; + } + } + + for (int32_T ib{2}; ib <= nblocks; ib++) { + real_T bsum; + int32_T hi; + firstBlockLength = (ib - 1) << 10; + bsum = x[firstBlockLength]; + if (ib == nblocks) { + hi = lastBlockLength; + } else { + hi = 1024; + } + + for (int32_T k{2}; k <= hi; k++) { + if (vlen >= 2) { + bsum += x[(firstBlockLength + k) - 1]; + } + } + + y += bsum; + } + + return y; + } + } +} + +// End of code generation (blockedSummation.cpp) diff --git a/RAT/blockedSummation.h b/RAT/blockedSummation.h new file mode 100644 index 00000000..07b8280f --- /dev/null +++ b/RAT/blockedSummation.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// blockedSummation.h +// +// Code generation for function 'blockedSummation' +// +#ifndef BLOCKEDSUMMATION_H +#define BLOCKEDSUMMATION_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void blockedSummation(const ::coder::array &x, int32_T vlen, :: + coder::array &y); + real_T nestedIter(const ::coder::array &x, int32_T vlen); + } +} + +#endif + +// End of code generation (blockedSummation.h) diff --git a/RAT/bsearch.cpp b/RAT/bsearch.cpp new file mode 100644 index 00000000..9298e8e0 --- /dev/null +++ b/RAT/bsearch.cpp @@ -0,0 +1,52 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// bsearch.cpp +// +// Code generation for function 'bsearch' +// + +// Include files +#include "bsearch.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + int32_T b_bsearch(const ::coder::array &x, real_T xi) + { + int32_T high_i; + int32_T low_ip1; + int32_T n; + high_i = x.size(0); + n = 1; + low_ip1 = 2; + while (high_i > low_ip1) { + int32_T mid_i; + mid_i = (n >> 1) + (high_i >> 1); + if (((n & 1) == 1) && ((high_i & 1) == 1)) { + mid_i++; + } + + if (xi >= x[mid_i - 1]) { + n = mid_i; + low_ip1 = mid_i + 1; + } else { + high_i = mid_i; + } + } + + return n; + } + } + } +} + +// End of code generation (bsearch.cpp) diff --git a/RAT/bsearch.h b/RAT/bsearch.h new file mode 100644 index 00000000..65fddb75 --- /dev/null +++ b/RAT/bsearch.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// bsearch.h +// +// Code generation for function 'bsearch' +// +#ifndef BSEARCH_H +#define BSEARCH_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + int32_T b_bsearch(const ::coder::array &x, real_T xi); + } + } +} + +#endif + +// End of code generation (bsearch.h) diff --git a/RAT/callCppFunc.cpp b/RAT/callCppFunc.cpp new file mode 100644 index 00000000..9590f374 --- /dev/null +++ b/RAT/callCppFunc.cpp @@ -0,0 +1,85 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// callCppFunc.cpp +// +// Code generation for function 'callCppFunc' +// + +// Include files +#include "callCppFunc.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "libManager.h" +#include +#include +#include +#include +#include +#include +#include + +// Function Definitions +namespace RAT +{ + void callCppFunc(::coder::array ¶ms, real_T nba, real_T nbs, + real_T numberOfContrasts, const char_T libraryName_data[], + const int32_T libraryName_size[2], const char_T + functionName_data[], const int32_T functionName_size[2], + real_T output_data[], int32_T output_size[2], real_T + *subRough) + { + Library p; + real_T tempOutput[1000][3]; + real_T nLayers; + int32_T loop_ub; + char_T b_functionName_data[10001]; + char_T b_libraryName_data[10001]; + + // Use 3rd party 'dylib.hpp' to implement a cross-platform Cpp runtime + // class loader.... https://github.com/martin-olivier/dylib + // coder.varsize('output',[1000 1],[1 0]); + // Make an instance + p = Library(); + + // We need to add a null terminator to the library names in order for + // them to match C/C++ format. See.... + // https://uk.mathworks.com/help/coder/ug/c-strings-for-null-terminated-matlab-strings.html + loop_ub = libraryName_size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&libraryName_data[0], &libraryName_data[loop_ub], + &b_libraryName_data[0]); + } + + b_libraryName_data[libraryName_size[1]] = '\x00'; + loop_ub = functionName_size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&functionName_data[0], &functionName_data[loop_ub], + &b_functionName_data[0]); + } + + b_functionName_data[functionName_size[1]] = '\x00'; + + // call the class method in libManager.h + std::mem_fn(&Library::loadRunner)(p, ¶ms[0], &nba, &nbs, + numberOfContrasts, &tempOutput[0][0], subRough, &nLayers, + &b_libraryName_data[0], &b_functionName_data[0]); + if (nLayers < 1.0) { + loop_ub = 0; + } else { + loop_ub = static_cast(nLayers); + } + + output_size[0] = loop_ub; + output_size[1] = 3; + for (int32_T i{0}; i < 3; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + output_data[i1 + loop_ub * i] = tempOutput[i1][i]; + } + } + } +} + +// End of code generation (callCppFunc.cpp) diff --git a/RAT/callCppFunc.h b/RAT/callCppFunc.h new file mode 100644 index 00000000..8b56ae64 --- /dev/null +++ b/RAT/callCppFunc.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// callCppFunc.h +// +// Code generation for function 'callCppFunc' +// +#ifndef CALLCPPFUNC_H +#define CALLCPPFUNC_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void callCppFunc(::coder::array ¶ms, real_T nba, real_T nbs, + real_T numberOfContrasts, const char_T libraryName_data[], + const int32_T libraryName_size[2], const char_T + functionName_data[], const int32_T functionName_size[2], + real_T output_data[], int32_T output_size[2], real_T + *subRough); +} + +#endif + +// End of code generation (callCppFunc.h) diff --git a/RAT/callReflectivity.cpp b/RAT/callReflectivity.cpp new file mode 100644 index 00000000..26ae241b --- /dev/null +++ b/RAT/callReflectivity.cpp @@ -0,0 +1,544 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// callReflectivity.cpp +// +// Code generation for function 'callReflectivity' +// + +// Include files +#include "callReflectivity.h" +#include "abelesParallelPoints.h" +#include "abelesSingle.h" +#include "colon.h" +#include "dataResolutionPolly.h" +#include "resolutionPolly.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include +#include + +namespace py = pybind11; + +// Function Definitions +namespace RAT +{ + void b_callReflectivity(real_T nbairs, real_T nbsubs, const real_T + simLimits_data[], const real_T repeatLayers[2], const ::coder::array &this_data, ::coder::array &layers, real_T ssubs, real_T res, + boolean_T useImaginary, ::coder::array &reflectivity, ::coder:: + array &Simulation) + { + ::coder::array slds; + ::coder::array firstSection; + ::coder::array lastSection; + ::coder::array r; + ::coder::array roughs; + ::coder::array simRef; + ::coder::array simResolData; + ::coder::array simXdata; + ::coder::array thicks; + real_T b; + real_T nLayersTot; + real_T nRepeats; + real_T step; + int32_T b_nLayersTot; + int32_T i; + int32_T i1; + int32_T loop_ub; + uint32_T layerCount; + uint32_T splits_idx_1; + if (repeatLayers[0] != 0.0) { + nRepeats = repeatLayers[1]; + } else { + nRepeats = 1.0; + } + + // Build the input arrays for thick, sld and rough..... + if (layers.size(0) == 0) { + // No layers defined. Make a zeros dummy zero layer + layers.set_size(1, 3); + layers[0] = 0.0; + layers[layers.size(0)] = nbairs; + layers[layers.size(0) * 2] = 0.0; + } + + // Number of layers (including repeats) + nLayersTot = static_cast(layers.size(0)) * nRepeats + 2.0; + + // Make arrays for thick, sld, rough + b_nLayersTot = static_cast(nLayersTot); + thicks.set_size(b_nLayersTot); + roughs.set_size(b_nLayersTot); + for (i = 0; i < b_nLayersTot; i++) { + thicks[i] = 0.0; + roughs[i] = 0.0; + } + + if (useImaginary) { + slds.set_size(b_nLayersTot); + for (i = 0; i < b_nLayersTot; i++) { + slds[i].re = 0.0; + slds[i].im = 0.0; + } + } else { + slds.set_size(b_nLayersTot); + for (i = 0; i < b_nLayersTot; i++) { + slds[i].re = 0.0; + slds[i].im = 0.0; + } + } + + // Populate the d,rho,sig arrays... + layerCount = 2U; + i = static_cast(nRepeats); + for (int32_T m{0}; m < i; m++) { + i1 = layers.size(0); + for (int32_T n{0}; n < i1; n++) { + if (!useImaginary) { + b_nLayersTot = static_cast(layerCount + static_cast + (n)) - 1; + thicks[b_nLayersTot] = layers[n]; + slds[b_nLayersTot].re = layers[n + layers.size(0)]; + slds[b_nLayersTot].im = 0.0; + roughs[b_nLayersTot] = layers[n + layers.size(0) * 2]; + } else { + b_nLayersTot = static_cast(layerCount + static_cast + (n)) - 1; + thicks[b_nLayersTot] = layers[n]; + slds[b_nLayersTot].re = layers[n + layers.size(0)]; + slds[b_nLayersTot].im = layers[n + layers.size(0) * 2]; + roughs[b_nLayersTot] = layers[n + layers.size(0) * 3]; + } + } + + layerCount += static_cast(layers.size(0)); + } + + // Add the air and substrate parameters + slds[0].re = nbairs; + slds[0].im = 0.0; + slds[slds.size(0) - 1].re = nbsubs; + slds[slds.size(0) - 1].im = 0.0; + roughs[roughs.size(0) - 1] = ssubs; + if (simLimits_data[0] < this_data[0]) { + step = this_data[1] - this_data[0]; + b = this_data[0] - step; + if (std::isnan(step) || std::isnan(b)) { + firstSection.set_size(1, 1); + firstSection[0] = rtNaN; + } else if ((step == 0.0) || ((simLimits_data[0] < b) && (step < 0.0)) || + ((b < simLimits_data[0]) && (step > 0.0))) { + firstSection.set_size(1, 0); + } else if ((std::isinf(simLimits_data[0]) || std::isinf(b)) && (std::isinf + (step) || (simLimits_data[0] == b))) { + firstSection.set_size(1, 1); + firstSection[0] = rtNaN; + } else if (std::isinf(step)) { + firstSection.set_size(1, 1); + firstSection[0] = simLimits_data[0]; + } else if ((std::floor(simLimits_data[0]) == simLimits_data[0]) && (std:: + floor(step) == step)) { + loop_ub = static_cast((b - simLimits_data[0]) / step); + firstSection.set_size(1, loop_ub + 1); + for (i = 0; i <= loop_ub; i++) { + firstSection[i] = simLimits_data[0] + step * static_cast(i); + } + } else { + coder::eml_float_colon(simLimits_data[0], step, b, firstSection); + } + } else { + firstSection.set_size(1, 0); + } + + if (simLimits_data[1] > this_data[this_data.size(0) - 1]) { + step = this_data[this_data.size(0) - 1] - this_data[this_data.size(0) - 2]; + b = this_data[this_data.size(0) - 1] + step; + if (std::isnan(b) || std::isnan(step)) { + lastSection.set_size(1, 1); + lastSection[0] = rtNaN; + } else if ((step == 0.0) || ((b < simLimits_data[1]) && (step < 0.0)) || + ((simLimits_data[1] < b) && (step > 0.0))) { + lastSection.set_size(1, 0); + } else if ((std::isinf(b) || std::isinf(simLimits_data[1])) && (std::isinf + (step) || (b == simLimits_data[1]))) { + lastSection.set_size(1, 1); + lastSection[0] = rtNaN; + } else if (std::isinf(step)) { + lastSection.set_size(1, 1); + lastSection[0] = b; + } else if ((std::floor(b) == b) && (std::floor(step) == step)) { + loop_ub = static_cast((simLimits_data[1] - b) / step); + lastSection.set_size(1, loop_ub + 1); + for (i = 0; i <= loop_ub; i++) { + lastSection[i] = b + step * static_cast(i); + } + } else { + coder::eml_float_colon(b, step, simLimits_data[1], lastSection); + } + } else { + lastSection.set_size(1, 0); + } + + b_nLayersTot = firstSection.size(1); + simXdata.set_size((this_data.size(0) + firstSection.size(1)) + + lastSection.size(1)); + loop_ub = firstSection.size(1); + for (i = 0; i < loop_ub; i++) { + simXdata[i] = firstSection[i]; + } + + loop_ub = this_data.size(0); + for (i = 0; i < loop_ub; i++) { + simXdata[i + b_nLayersTot] = this_data[i]; + } + + loop_ub = lastSection.size(1); + for (i = 0; i < loop_ub; i++) { + simXdata[(i + b_nLayersTot) + this_data.size(0)] = lastSection[i]; + } + + splits_idx_1 = static_cast(firstSection.size(1)) + + static_cast(this_data.size(0)); + Simulation.set_size(simXdata.size(0), 2); + loop_ub = simXdata.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + Simulation[i1 + Simulation.size(0) * i] = 0.0; + } + } + + loop_ub = simXdata.size(0); + for (i = 0; i < loop_ub; i++) { + Simulation[i] = simXdata[i]; + } + + // If we are using data resolutions, then we also need to adjust the length + // of the reolution column. We do thit by just extending with the rosolution + // values at the ends of the curve. + simResolData.set_size(1); + simResolData[0] = 0.0; + if (res == -1.0) { + b_nLayersTot = firstSection.size(1); + simResolData.set_size((this_data.size(0) + firstSection.size(1)) + + lastSection.size(1)); + loop_ub = firstSection.size(1); + for (i = 0; i < loop_ub; i++) { + simResolData[i] = this_data[this_data.size(0) * 3]; + } + + loop_ub = this_data.size(0); + for (i = 0; i < loop_ub; i++) { + simResolData[i + b_nLayersTot] = this_data[i + this_data.size(0) * 3]; + } + + loop_ub = lastSection.size(1); + for (i = 0; i < loop_ub; i++) { + simResolData[(i + b_nLayersTot) + this_data.size(0)] = this_data + [(this_data.size(0) + this_data.size(0) * 3) - 1]; + } + } + + // Parallelise over points + // Calculate reflectivity.... + abelesParallelPoints(simXdata, nLayersTot, thicks, slds, roughs, simRef); + + // Apply resolution + // Note: paraPoints gives an error during valifation, so use + // single cored resolution as a workaround for now. + if (res == -1.0) { + // simRef = dataResolutionPollyParallelPoints(simXdata,simRef,simResolData,length(simXdata)); + dataResolutionPolly(simXdata, simRef, simResolData, static_cast + (simXdata.size(0)), r); + loop_ub = r.size(0); + for (i = 0; i < loop_ub; i++) { + Simulation[i + Simulation.size(0)] = r[i]; + } + } else { + // simRef = resolutionPollyParallelPoints(simXdata,simRef,res,length(simXdata)); + resolutionPolly(simXdata, simRef, res, static_cast(simXdata.size(0)), + r); + loop_ub = r.size(0); + for (i = 0; i < loop_ub; i++) { + Simulation[i + Simulation.size(0)] = r[i]; + } + } + + if (static_cast(firstSection.size(1)) + 1U > splits_idx_1) { + i = 0; + i1 = 0; + } else { + i = firstSection.size(1); + i1 = static_cast(splits_idx_1); + } + + loop_ub = i1 - i; + reflectivity.set_size(loop_ub, 2); + for (i1 = 0; i1 < 2; i1++) { + for (b_nLayersTot = 0; b_nLayersTot < loop_ub; b_nLayersTot++) { + reflectivity[b_nLayersTot + reflectivity.size(0) * i1] = Simulation[(i + + b_nLayersTot) + Simulation.size(0) * i1]; + } + } + } + + void callReflectivity(real_T nbairs, real_T nbsubs, const real_T + simLimits_data[], const real_T repeatLayers[2], const :: + coder::array &this_data, ::coder::array< + real_T, 2U> &layers, real_T ssubs, real_T res, boolean_T + useImaginary, ::coder::array &reflectivity, :: + coder::array &Simulation) + { + ::coder::array slds; + ::coder::array firstSection; + ::coder::array lastSection; + ::coder::array r; + ::coder::array roughs; + ::coder::array simRef; + ::coder::array simResolData; + ::coder::array simXdata; + ::coder::array thicks; + real_T b; + real_T nLayersTot; + real_T nRepeats; + real_T step; + int32_T b_nLayersTot; + int32_T i; + int32_T i1; + int32_T loop_ub; + uint32_T layerCount; + uint32_T splits_idx_1; + if (repeatLayers[0] != 0.0) { + nRepeats = repeatLayers[1]; + } else { + nRepeats = 1.0; + } + + // Build the input arrays for thick, sld and rough..... + if (layers.size(0) == 0) { + // No layers defined. Make a zeros dummy zero layer + layers.set_size(1, 3); + layers[0] = 0.0; + layers[layers.size(0)] = nbairs; + layers[layers.size(0) * 2] = 0.0; + } + + // Number of layers (including repeats) + nLayersTot = static_cast(layers.size(0)) * nRepeats + 2.0; + + // Make arrays for thick, sld, rough + b_nLayersTot = static_cast(nLayersTot); + thicks.set_size(b_nLayersTot); + roughs.set_size(b_nLayersTot); + for (i = 0; i < b_nLayersTot; i++) { + thicks[i] = 0.0; + roughs[i] = 0.0; + } + + if (useImaginary) { + slds.set_size(b_nLayersTot); + for (i = 0; i < b_nLayersTot; i++) { + slds[i].re = 0.0; + slds[i].im = 0.0; + } + } else { + slds.set_size(b_nLayersTot); + for (i = 0; i < b_nLayersTot; i++) { + slds[i].re = 0.0; + slds[i].im = 0.0; + } + } + + // Populate the d,rho,sig arrays... + layerCount = 2U; + i = static_cast(nRepeats); + for (int32_T m{0}; m < i; m++) { + i1 = layers.size(0); + for (int32_T n{0}; n < i1; n++) { + if (!useImaginary) { + b_nLayersTot = static_cast(layerCount + static_cast + (n)) - 1; + thicks[b_nLayersTot] = layers[n]; + slds[b_nLayersTot].re = layers[n + layers.size(0)]; + slds[b_nLayersTot].im = 0.0; + roughs[b_nLayersTot] = layers[n + layers.size(0) * 2]; + } else { + b_nLayersTot = static_cast(layerCount + static_cast + (n)) - 1; + thicks[b_nLayersTot] = layers[n]; + slds[b_nLayersTot].re = layers[n + layers.size(0)]; + slds[b_nLayersTot].im = layers[n + layers.size(0) * 2]; + roughs[b_nLayersTot] = layers[n + layers.size(0) * 3]; + } + } + + layerCount += static_cast(layers.size(0)); + } + + // Add the air and substrate parameters + slds[0].re = nbairs; + slds[0].im = 0.0; + slds[slds.size(0) - 1].re = nbsubs; + slds[slds.size(0) - 1].im = 0.0; + roughs[roughs.size(0) - 1] = ssubs; + if (simLimits_data[0] < this_data[0]) { + step = this_data[1] - this_data[0]; + b = this_data[0] - step; + if (std::isnan(step) || std::isnan(b)) { + firstSection.set_size(1, 1); + firstSection[0] = rtNaN; + } else if ((step == 0.0) || ((simLimits_data[0] < b) && (step < 0.0)) || + ((b < simLimits_data[0]) && (step > 0.0))) { + firstSection.set_size(1, 0); + } else if ((std::isinf(simLimits_data[0]) || std::isinf(b)) && (std::isinf + (step) || (simLimits_data[0] == b))) { + firstSection.set_size(1, 1); + firstSection[0] = rtNaN; + } else if (std::isinf(step)) { + firstSection.set_size(1, 1); + firstSection[0] = simLimits_data[0]; + } else if ((std::floor(simLimits_data[0]) == simLimits_data[0]) && (std:: + floor(step) == step)) { + loop_ub = static_cast((b - simLimits_data[0]) / step); + firstSection.set_size(1, loop_ub + 1); + for (i = 0; i <= loop_ub; i++) { + firstSection[i] = simLimits_data[0] + step * static_cast(i); + } + } else { + coder::eml_float_colon(simLimits_data[0], step, b, firstSection); + } + } else { + firstSection.set_size(1, 0); + } + + if (simLimits_data[1] > this_data[this_data.size(0) - 1]) { + step = this_data[this_data.size(0) - 1] - this_data[this_data.size(0) - 2]; + b = this_data[this_data.size(0) - 1] + step; + if (std::isnan(b) || std::isnan(step)) { + lastSection.set_size(1, 1); + lastSection[0] = rtNaN; + } else if ((step == 0.0) || ((b < simLimits_data[1]) && (step < 0.0)) || + ((simLimits_data[1] < b) && (step > 0.0))) { + lastSection.set_size(1, 0); + } else if ((std::isinf(b) || std::isinf(simLimits_data[1])) && (std::isinf + (step) || (b == simLimits_data[1]))) { + lastSection.set_size(1, 1); + lastSection[0] = rtNaN; + } else if (std::isinf(step)) { + lastSection.set_size(1, 1); + lastSection[0] = b; + } else if ((std::floor(b) == b) && (std::floor(step) == step)) { + loop_ub = static_cast((simLimits_data[1] - b) / step); + lastSection.set_size(1, loop_ub + 1); + for (i = 0; i <= loop_ub; i++) { + lastSection[i] = b + step * static_cast(i); + } + } else { + coder::eml_float_colon(b, step, simLimits_data[1], lastSection); + } + } else { + lastSection.set_size(1, 0); + } + + b_nLayersTot = firstSection.size(1); + simXdata.set_size((this_data.size(0) + firstSection.size(1)) + + lastSection.size(1)); + loop_ub = firstSection.size(1); + for (i = 0; i < loop_ub; i++) { + simXdata[i] = firstSection[i]; + } + + loop_ub = this_data.size(0); + for (i = 0; i < loop_ub; i++) { + simXdata[i + b_nLayersTot] = this_data[i]; + } + + loop_ub = lastSection.size(1); + for (i = 0; i < loop_ub; i++) { + simXdata[(i + b_nLayersTot) + this_data.size(0)] = lastSection[i]; + } + + splits_idx_1 = static_cast(firstSection.size(1)) + + static_cast(this_data.size(0)); + Simulation.set_size(simXdata.size(0), 2); + loop_ub = simXdata.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + Simulation[i1 + Simulation.size(0) * i] = 0.0; + } + } + + loop_ub = simXdata.size(0); + for (i = 0; i < loop_ub; i++) { + Simulation[i] = simXdata[i]; + } + + // If we are using data resolutions, then we also need to adjust the length + // of the reolution column. We do thit by just extending with the rosolution + // values at the ends of the curve. + simResolData.set_size(1); + simResolData[0] = 0.0; + if (res == -1.0) { + b_nLayersTot = firstSection.size(1); + simResolData.set_size((this_data.size(0) + firstSection.size(1)) + + lastSection.size(1)); + loop_ub = firstSection.size(1); + for (i = 0; i < loop_ub; i++) { + simResolData[i] = this_data[this_data.size(0) * 3]; + } + + loop_ub = this_data.size(0); + for (i = 0; i < loop_ub; i++) { + simResolData[i + b_nLayersTot] = this_data[i + this_data.size(0) * 3]; + } + + loop_ub = lastSection.size(1); + for (i = 0; i < loop_ub; i++) { + simResolData[(i + b_nLayersTot) + this_data.size(0)] = this_data + [(this_data.size(0) + this_data.size(0) * 3) - 1]; + } + } + + // Single cored over points + // Calculate reflectivity..... + abelesSingle(simXdata, nLayersTot, thicks, slds, roughs, simRef); + + // Apply resolution correction... + if (res == -1.0) { + dataResolutionPolly(simXdata, simRef, simResolData, static_cast + (simXdata.size(0)), r); + loop_ub = r.size(0); + for (i = 0; i < loop_ub; i++) { + Simulation[i + Simulation.size(0)] = r[i]; + } + } else { + resolutionPolly(simXdata, simRef, res, static_cast(simXdata.size(0)), + r); + loop_ub = r.size(0); + for (i = 0; i < loop_ub; i++) { + Simulation[i + Simulation.size(0)] = r[i]; + } + } + + if (static_cast(firstSection.size(1)) + 1U > splits_idx_1) { + i = 0; + i1 = 0; + } else { + i = firstSection.size(1); + i1 = static_cast(splits_idx_1); + } + + loop_ub = i1 - i; + reflectivity.set_size(loop_ub, 2); + for (i1 = 0; i1 < 2; i1++) { + for (b_nLayersTot = 0; b_nLayersTot < loop_ub; b_nLayersTot++) { + reflectivity[b_nLayersTot + reflectivity.size(0) * i1] = Simulation[(i + + b_nLayersTot) + Simulation.size(0) * i1]; + } + } + } +} + +// End of code generation (callReflectivity.cpp) diff --git a/RAT/callReflectivity.h b/RAT/callReflectivity.h new file mode 100644 index 00000000..dcd13405 --- /dev/null +++ b/RAT/callReflectivity.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// callReflectivity.h +// +// Code generation for function 'callReflectivity' +// +#ifndef CALLREFLECTIVITY_H +#define CALLREFLECTIVITY_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void b_callReflectivity(real_T nbairs, real_T nbsubs, const real_T + simLimits_data[], const real_T repeatLayers[2], const ::coder::array &this_data, ::coder::array &layers, real_T ssubs, real_T res, + boolean_T useImaginary, ::coder::array &reflectivity, ::coder:: + array &Simulation); + void callReflectivity(real_T nbairs, real_T nbsubs, const real_T + simLimits_data[], const real_T repeatLayers[2], const :: + coder::array &this_data, ::coder::array< + real_T, 2U> &layers, real_T ssubs, real_T res, boolean_T + useImaginary, ::coder::array &reflectivity, :: + coder::array &Simulation); +} + +#endif + +// End of code generation (callReflectivity.h) diff --git a/RAT/chiSquared.cpp b/RAT/chiSquared.cpp new file mode 100644 index 00000000..5efef94d --- /dev/null +++ b/RAT/chiSquared.cpp @@ -0,0 +1,88 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// chiSquared.cpp +// +// Code generation for function 'chiSquared' +// + +// Include files +#include "chiSquared.h" +#include "find.h" +#include "minOrMax.h" +#include "rt_nonfinite.h" +#include "sum.h" +#include "unsafeSxfun.h" +#include "coder_array.h" +#include + +namespace py = pybind11; +// Function Definitions +namespace RAT +{ + real_T chiSquared(const ::coder::array &thisData, const ::coder:: + array &thisFit, real_T P) + { + ::coder::array terms; + ::coder::array n; + ::coder::array b_terms; + real_T b_thisData[2]; + real_T N; + int32_T i; + int32_T loop_ub; + + // Chi-squared function is used to evaluate the goodness of fit. + // It is a measure of the difference between the observed and expected. + // allChis = zeros(1,numberOfContrasts); + // thisData = allData{i}; + // thisFit = allFits{i}; + b_thisData[0] = thisData.size(0); + b_thisData[1] = 1.0; + N = coder::internal::b_maximum(b_thisData); + + if (N <= P) { + N = P + 1.0; + } + + if (thisData.size(0) == 1) { + i = thisFit.size(0); + } else { + i = thisData.size(0); + } + + if ((thisData.size(0) == thisFit.size(0)) && (i == thisData.size(0))) { + terms.set_size(thisData.size(0)); + loop_ub = thisData.size(0); + for (i = 0; i < loop_ub; i++) { + real_T varargin_1; + varargin_1 = (thisData[i + thisData.size(0)] - thisFit[i + thisFit.size + (0)]) / thisData[i + thisData.size(0) * 2]; + terms[i] = varargin_1 * varargin_1; + } + } else { + binary_expand_op(terms, thisData, thisFit); + } + + b_terms.set_size(terms.size(0)); + loop_ub = terms.size(0); + for (i = 0; i < loop_ub; i++) { + b_terms[i] = (terms[i] == rtInf); + } + + coder::eml_find(b_terms, n); + if (n.size(0) != 0) { + loop_ub = n.size(0); + for (i = 0; i < loop_ub; i++) { + terms[n[i] - 1] = 0.0; + } + } + + return 1.0 / (N - P) * coder::sum(terms); + + // allChis(i) = chi2; + } +} + +// End of code generation (chiSquared.cpp) diff --git a/RAT/chiSquared.h b/RAT/chiSquared.h new file mode 100644 index 00000000..eb9822ea --- /dev/null +++ b/RAT/chiSquared.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// chiSquared.h +// +// Code generation for function 'chiSquared' +// +#ifndef CHISQUARED_H +#define CHISQUARED_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + real_T chiSquared(const ::coder::array &thisData, const ::coder:: + array &thisFit, real_T P); +} + +#endif + +// End of code generation (chiSquared.h) diff --git a/RAT/coder_array.h b/RAT/coder_array.h new file mode 100644 index 00000000..c6f39d7e --- /dev/null +++ b/RAT/coder_array.h @@ -0,0 +1,796 @@ +/* Copyright 2019-2021 The MathWorks, Inc. */ +/* Copied from + * fullfile(matlabroot,'extern','include','coder','coder_array','coder_array_rtw_cpp11.h') */ + +#ifndef _mw_coder_array_cpp11_h +#define _mw_coder_array_cpp11_h + +// Usage: +// +// coder::array: T base type of data, N number of dimensions +// +// coder::array() +// : default constructor +// coder::array(coder::array const &) +// : copy constructor (always make a deep copy of other array) +// coder::array(T const *data, SizeType const *sz) +// : Set data with sizes of this array. +// : (Data is not copied, data is not deleted) +// coder::array::operator = (coder coder::array &) +// : Assign into this array; +// : delete its previous contents (if owning the data.) +// set(T const *data, SizeType sz1, SizeType sz2, ...) +// : Set data with dimensions. +// : (Data is not copied, data is not deleted) +// set_size(SizeType sz1, SizeType sz2, ...) +// : Set sizes of array. Reallocate memory of data if needed. +// bool is_owner() : Return true if the data is owned by the class. +// void set_owner(b) : Set if the data is owned by the class. +// SizeType capacity() : How many entries are reserved by memory allocation. +// reshape( SizeType sz1, SizeType sz2, ...) +// : Reshape array to a different ND shape. Do not copy the data. +// : The number of elements must not be changed (numel()==sz1*sz2*...) +// : Return the array with possibly new number of dimensions. +// clear() : Reset array to be empty. +// SizeType numel() : Return the number of elements. +// operator [] (SizeType index) : Extract element at linear index (0 based.) +// size(SizeType dimension) : Size of array of the provided dimension. +// SizeType * size() : Return the pointer to all the sizes of this array. +// SizeType index(SizeType i1, SizeType i2, ...) +// : Compute the linear index from ND index (i1,i2,...) +// at(SizeType i1, SizeType i2, ...) : The element at index (i1,i2,...) + +#include +#include +#include +#include +#include + +#ifndef INT32_T +#include "rtwtypes.h" +#endif + +namespace coder { + +#ifndef CODER_ARRAY_NEW_DELETE +#define CODER_ARRAY_NEW_DELETE +#define CODER_NEW(T, N) new T[N] +#define CODER_DELETE(P) delete[](P) +#endif + +#ifndef CODER_ARRAY_SIZE_TYPE_DEFINED +using SizeType = int; +#endif + +namespace std = ::std; + +namespace detail { + +#ifndef CODER_ARRAY_DATA_PTR_DEFINED +template +class data_ptr { + public: + using value_type = T; + using size_type = SZ; + + data_ptr() + : data_(nullptr) + , size_(0) + , capacity_(0) + , owner_(false) { + } + data_ptr(T* _data, SZ _sz) + : data_(_data) + , size_(_sz) + , capacity_(_sz) + , owner_(false) { + } + + data_ptr(data_ptr const& _other) + : data_(_other.owner_ ? nullptr : _other.data_) + , size_(_other.owner_ ? 0 : _other.size_) + , capacity_(_other.owner_ ? 0 : _other.capacity_) + , owner_(_other.owner_) { + if (owner_) { + resize(_other.size_); + (void)std::copy(_other.data_, _other.data_ + size_, data_); + } + } + + ~data_ptr() { + if (owner_) { + CODER_DELETE(data_); + } + } + SZ capacity() const { + return capacity_; + } + void reserve(SZ _n) { + if (_n > capacity_) { + T* const new_data{CODER_NEW(T, _n)}; + (void)std::copy(data_, data_ + size_, new_data); + if (owner_) { + CODER_DELETE(data_); + } + data_ = new_data; + capacity_ = _n; + owner_ = true; + } + } + void resize(SZ _n) { + reserve(_n); + size_ = _n; + } + + private: + // Prohibit use of assignment operator to prevent subtle bugs + void operator=(data_ptr const& _other); + + public: + void set(T* _data, SZ _sz) { + if (owner_) { + CODER_DELETE(data_); + } + data_ = _data; + size_ = _sz; + owner_ = false; + capacity_ = size_; + } + + void copy(T const* const _data, SZ _size) { + if (data_ == _data) { + size_ = _size; + return; + } + if (owner_) { + CODER_DELETE(data_); + } + data_ = CODER_NEW(T, _size); + owner_ = true; + size_ = _size; + capacity_ = size_; + (void)std::copy(_data, _data + _size, data_); + } + + void copy(data_ptr const& _other) { + copy(_other.data_, _other.size_); + } + + operator T*() { + return &data_[0]; + } + + operator T const *() const { + return &data_[0]; + } + + T& operator[](SZ _index) { + return data_[_index]; + } + T const& operator[](SZ _index) const { + return data_[_index]; + } + + T* operator->() { + return data_; + } + + T const* operator->() const { + return data_; + } + + bool is_null() const { + return data_ == nullptr; + } + + void clear() { + if (owner_) { + CODER_DELETE(data_); + } + data_ = nullptr; + size_ = 0; + capacity_ = 0; + owner_ = false; + } + + bool is_owner() const { + return owner_; + } + + void set_owner(bool _b) { + owner_ = _b; + } + + private: + T* data_; + SZ size_; + SZ capacity_; + bool owner_; +}; +#endif + +} // namespace detail + +// Implementing the random access iterator class so coder::array can be +// used in STL iterators. +template +class array_iterator : public std::iterator { + public: + array_iterator() + : arr_(nullptr) + , i_(0) { + } + array_iterator(array_iterator const& other) + : arr_(other.arr_) + , i_(other.i_) { + } + ~array_iterator() { + } + typename T::value_type& operator*() const { + return (*arr_)[i_]; + } + typename T::value_type* operator->() const { + return &(*arr_)[i_]; + } + typename T::value_type& operator[](typename T::size_type _di) const { + return (*arr_)[i_ + _di]; + } + array_iterator& operator++() { + ++i_; + return *this; + } + array_iterator& operator--() { + --i_; + return *this; + } + array_iterator operator++(int) { + array_iterator cp{*this}; + ++i_; + return cp; + } + array_iterator operator--(int) { + array_iterator cp{*this}; + --i_; + return cp; + } + array_iterator& operator=(array_iterator const& _other) { + this->i_ = _other.i_; + return *this; + } + bool operator==(array_iterator const& _other) const { + return i_ == _other.i_; + } + bool operator!=(array_iterator const& _other) const { + return i_ != _other.i_; + } + bool operator<(array_iterator const& _other) const { + return i_ < _other.i_; + } + bool operator>(array_iterator const& _other) const { + return i_ > _other.i_; + } + bool operator<=(array_iterator const& _other) const { + return i_ <= _other.i_; + } + bool operator>=(array_iterator const& _other) const { + return i_ >= _other.i_; + } + array_iterator operator+(typename T::size_type _add) const { + array_iterator cp{*this}; + cp.i_ += _add; + return cp; + } + array_iterator& operator+=(typename T::size_type _add) { + this->i_ += _add; + return *this; + } + array_iterator operator-(typename T::size_type _subtract) const { + array_iterator cp{*this}; + cp.i_ -= _subtract; + return cp; + } + array_iterator& operator-=(typename T::size_type _subtract) { + this->i_ -= _subtract; + return *this; + } + typename T::size_type operator-(array_iterator const& _other) const { + return static_cast(this->i_ - _other.i_); + } + + array_iterator(T* _arr, typename T::size_type _i) + : arr_(_arr) + , i_(_i) { + } + + private: + T* arr_; + typename T::size_type i_; +}; + +// Const version of the array iterator. +template +class const_array_iterator : public std::iterator { + public: + const_array_iterator() + : arr_(nullptr) + , i_(0) { + } + const_array_iterator(const_array_iterator const& other) + : arr_(other.arr_) + , i_(other.i_) { + } + ~const_array_iterator() { + } + typename T::value_type const& operator*() const { + return (*arr_)[i_]; + } + typename T::value_type const* operator->() const { + return &(*arr_)[i_]; + } + typename T::value_type const& operator[](typename T::size_type _di) const { + return (*arr_)[i_ + _di]; + } + const_array_iterator& operator++() { + ++i_; + return *this; + } + const_array_iterator& operator--() { + --i_; + return *this; + } + const_array_iterator operator++(int) { + const_array_iterator copy{*this}; + ++i_; + return copy; + } + const_array_iterator operator--(int) { + const_array_iterator copy{*this}; + --i_; + return copy; + } + const_array_iterator& operator=(const_array_iterator const& _other) { + this->i_ = _other.i_; + return *this; + } + bool operator==(const_array_iterator const& _other) const { + return i_ == _other.i_; + } + bool operator!=(const_array_iterator const& _other) const { + return i_ != _other.i_; + } + bool operator<(const_array_iterator const& _other) const { + return i_ < _other.i_; + } + bool operator>(const_array_iterator const& _other) const { + return i_ > _other.i_; + } + bool operator<=(const_array_iterator const& _other) const { + return i_ <= _other.i_; + } + bool operator>=(const_array_iterator const& _other) const { + return i_ >= _other.i_; + } + const_array_iterator operator+(typename T::size_type _add) const { + const_array_iterator cp{*this}; + cp.i_ += _add; + return cp; + } + const_array_iterator& operator+=(typename T::size_type _add) { + this->i_ += _add; + return *this; + } + const_array_iterator operator-(typename T::size_type _subtract) const { + const_array_iterator cp{*this}; + cp.i_ -= _subtract; + return cp; + } + + const_array_iterator& operator-=(typename T::size_type _subtract) { + this->i_ -= _subtract; + return *this; + } + + typename T::size_type operator-(const_array_iterator const& _other) const { + return static_cast(this->i_ - _other.i_); + } + + const_array_iterator(T const* _arr, typename T::size_type _i) + : arr_(_arr) + , i_(_i) { + } + + private: + T const* arr_; + typename T::size_type i_; + typename T::size_type n_; +}; + +namespace detail { + +// detail::numel: Compile-time product of the given size vector of length N. +template +class numel { + public: + template + static SZ compute(SZ _size[]) { + return _size[N - 1] * numel::compute(_size); + } +}; +template <> +class numel<0> { + public: + template + static SZ compute(SZ[]) { + return 1; + } +}; + +// Compute the product for a set of numeric arguments: product(10, 20, 30, ...) => +// 10*20*30*... +template +struct product_i { + static SZ compute(First _f, Rest... _rest) { + return _f * product_i::compute(_rest...); + } +}; +template +struct product_i { + static SZ compute(Last _l) { + return _l; + } +}; + +template +SZ product(Args... args) { + return product_i::compute(args...); +} + +// Compute flat index from (column-major) ND size vector and a list of indices. +template +class index_nd { + public: + template + static SZ compute(SZ const _size[], SZ const _indices[]) { + SZ const weight{numel::compute(_size)}; + return weight * _indices[I - 1] + index_nd::compute(_size, _indices); + } +}; + +template <> +class index_nd<0> { + public: + template + static SZ compute(SZ[], SZ[]) { + return 0; + } +}; + +template +struct match_dimensions {}; + +template <> +struct match_dimensions { + static void check() { + } +}; + +} // namespace detail + +// Base class for code::array. SZ is the type used for sizes (currently int32_t.) +// Overloading up to 10 dimensions (not using variadic templates to +// stay compatible with C++98.) +template +class array_base { + public: + using value_type = T; + using size_type = SZ; + + array_base() { + (void)::memset(size_, 0, sizeof(SZ) * N); + } + + array_base(T* _data, SZ const* _sz) + : data_(_data, coder::detail::numel::compute(_sz)) { + (void)std::copy(_sz, _sz + N, size_); + } + + array_base(array_base const&) = default; + + array_base& operator=(array_base const& _other) { + data_.copy(_other.data_); + (void)std::copy(_other.size_, _other.size_ + N, size_); + return *this; + } + + template + void set(T* _data, Dims... dims) { + coder::detail::match_dimensions::check(); + data_.set(_data, coder::detail::product(dims...)); + set_size_i<0>(dims...); + } + + bool is_owner() const { + return data_.is_owner(); + } + + void set_owner(bool b) { + data_.set_owner(b); + } + + SZ capacity() const { + return data_.capacity(); + } + + private: + template + void set_size_i(First f, Rest... rest) { + size_[_i] = f; + set_size_i<_i + 1, Rest...>(rest...); + } + template + void set_size_i(Last l) { + size_[_i] = l; + } + + public: + void reserve(SZ _n) { + ensureCapacity(_n); + } + + template + void set_size(Dims... dims) { + coder::detail::match_dimensions::check(); + set_size_i<0>(dims...); + ensureCapacity(numel()); + } + + template + array_base reshape_n(SZ const (&_ns)[N1]) const { + array_base reshaped{const_cast(&data_[0]), _ns}; + return reshaped; + } + + template + array_base(sizeof...(Dims))> reshape(Dims... dims) const { + SZ const ns[]{static_cast(dims)...}; + return reshape_n(ns); + } + + T& operator[](SZ _index) { + return data_[_index]; + } + + T const& operator[](SZ _index) const { + return data_[_index]; + } + + void clear() { + data_.clear(); + } + + T* data() { + return data_; + } + + T const* data() const { + return data_; + } + + SZ* size() { + return &size_[0]; + } + + SZ const* size() const { + return &size_[0]; + } + + SZ size(SZ _index) const { + return size_[_index]; + } + + SZ numel() const { + return coder::detail::numel::compute(size_); + } + + template + SZ index(Dims... _dims) const { + coder::detail::match_dimensions::check(); + SZ const indices[]{static_cast(_dims)...}; + return coder::detail::index_nd(sizeof...(_dims))>::compute(size_, indices); + } + + template + T& at(Dims... _i) { + coder::detail::match_dimensions::check(); + return data_[index(_i...)]; + } + + template + T const& at(Dims... _i) const { + coder::detail::match_dimensions::check(); + return data_[index(_i...)]; + } + + array_iterator > begin() { + return array_iterator >(this, 0); + } + array_iterator > end() { + return array_iterator >(this, this->numel()); + } + const_array_iterator > begin() const { + return const_array_iterator >(this, 0); + } + const_array_iterator > end() const { + return const_array_iterator >(this, this->numel()); + } + + protected: + coder::detail::data_ptr data_; + SZ size_[N]; + + private: + void ensureCapacity(SZ _newNumel) { + if (_newNumel > data_.capacity()) { + SZ i{data_.capacity()}; + if (i < 16) { + i = 16; + } + + while (i < _newNumel) { + if (i > 1073741823) { + i = MAX_int32_T; + } else { + i *= 2; + } + } + data_.reserve(i); + } + data_.resize(_newNumel); + } +}; + +// The standard coder::array class with base type and number of dimensions. +template +class array : public array_base { + private: + using Base = array_base; + + public: + array() + : Base() { + } + array(array const& _other) + : Base(_other) { + } + array(Base const& _other) + : Base(_other) { + } + array(T* _data, SizeType const* _sz) + : Base(_data, _sz) { + } +}; + +// Specialize on char_T (row vector) for better support on strings. +template <> +class array : public array_base { + private: + using Base = array_base; + + public: + array() + : array_base() { + } + array(array const& _other) + : Base(_other) { + } + array(Base const& _other) + : Base(_other) { + } + + array(std::string const& _str) { + operator=(_str); + } + + array(char_T const* const _str) { + operator=(_str); + } + + array(std::vector const& _vec) { + SizeType const n{static_cast(_vec.size())}; + set_size(1, n); + data_.copy(&_vec[0], n); + } + + array& operator=(std::string const& _str) { + SizeType const n{static_cast(_str.size())}; + set_size(1, n); + data_.copy(_str.c_str(), n); + return *this; + } + + array& operator=(char_T const* const _str) { + SizeType const n{static_cast(strlen(_str))}; + set_size(1, n); + data_.copy(_str, n); + return *this; + } + + operator std::string() const { + return std::string(static_cast(&(*this)[0]), static_cast(size(1))); + } +}; + +// Specialize on 2 dimensions for better support interactions with +// std::vector and row vectors. +template +class array : public array_base { + private: + using Base = array_base; + + public: + array() + : Base() { + } + array(array const& _other) + : Base(_other) { + } + array(Base const& _other) + : Base(_other) { + } + array(std::vector const& _vec) { + operator=(_vec); + } + + array& operator=(std::vector const& _vec) { + SizeType n{static_cast(_vec.size())}; + Base::set_size(1, n); + Base::data_.copy(&_vec[0], n); + return *this; + } + + operator std::vector() const { + T const* p{&Base::data_[0]}; + return std::vector(p, p + Base::numel()); + } +}; + +// Specialize on 1 dimension for better support with std::vector and +// column vectors. +template +class array : public array_base { + private: + using Base = array_base; + + public: + array() + : Base() { + } + array(array const& _other) + : Base(_other) { + } + array(Base const& _other) + : Base(_other) { + } + array(std::vector const& _vec) { + operator=(_vec); + } + + array& operator=(std::vector const& _vec) { + SizeType n{static_cast(_vec.size())}; + Base::set_size(n); + Base::data_.copy(&_vec[0], n); + return *this; + } + + operator std::vector() const { + T const* p{&Base::data_[0]}; + return std::vector(p, p + Base::numel()); + } +}; +} // namespace coder + +#endif diff --git a/RAT/coder_bounded_array.h b/RAT/coder_bounded_array.h new file mode 100644 index 00000000..b08c1fdd --- /dev/null +++ b/RAT/coder_bounded_array.h @@ -0,0 +1,37 @@ +/* Copyright 2020 The Mathworks, Inc. */ +/* Copied from fullfile(matlabroot,'extern','include','coder','coder_array','coder_bounded_array.h') + */ + +#ifndef _mw_coder_bounded_array_h +#define _mw_coder_bounded_array_h + +#ifdef MATLAB_MEX_FILE +#include "tmwtypes.h" +#else +#include "rtwtypes.h" +#endif + +namespace coder { + +#ifndef CODER_ARRAY_SIZE_TYPE_DEFINED +#if __cplusplus >= 201103L +using SizeType = int; +#else +typedef int SizeType; +#endif +#endif + +// Bounded array +template +struct bounded_array { + T data[UpperBoundSize]; + SizeType size[NumDims]; +}; + +template +struct empty_bounded_array { + SizeType size[NumDims]; +}; +} // namespace coder + +#endif diff --git a/RAT/coder_setenv.c b/RAT/coder_setenv.c new file mode 100644 index 00000000..4a3c00e5 --- /dev/null +++ b/RAT/coder_setenv.c @@ -0,0 +1,22 @@ +/* Copyright 2020 The MathWorks, Inc. */ +#include "coder_setenv.h" + +#ifdef _MSC_VER +#include +#include +#include +#else +#define _POSIX_C_SOURCE 200112L +#include +#endif + +void portableSetEnv(const char* aName, const char* aValue) { +#ifdef _MSC_VER + char* pvBuffer = (char*)malloc(strlen(aName) + strlen(aValue) + 2); + sprintf(pvBuffer, "%s=%s", aName, aValue); + _putenv(pvBuffer); + free(pvBuffer); +#else + setenv(aName, aValue, 1); +#endif +} diff --git a/RAT/coder_setenv.h b/RAT/coder_setenv.h new file mode 100644 index 00000000..03598cdf --- /dev/null +++ b/RAT/coder_setenv.h @@ -0,0 +1,15 @@ +/* Copyright 2020 The MathWorks, Inc. */ +#ifndef CODER_SETENV_H +#define CODER_SETENV_H + +#ifdef __cplusplus +extern "C" { +#endif + +void portableSetEnv(const char* aName, const char* aValue); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/RAT/colon.cpp b/RAT/colon.cpp new file mode 100644 index 00000000..9ff4e5e8 --- /dev/null +++ b/RAT/colon.cpp @@ -0,0 +1,99 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// colon.cpp +// +// Code generation for function 'colon' +// + +// Include files +#include "colon.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + static void float_colon_length(real_T a, real_T d, real_T b, int32_T *n, + real_T *anew, real_T *bnew, boolean_T *n_too_large); + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + static void float_colon_length(real_T a, real_T d, real_T b, int32_T *n, + real_T *anew, real_T *bnew, boolean_T *n_too_large) + { + real_T cdiff; + real_T ndbl; + *anew = a; + ndbl = std::floor((b - a) / d + 0.5); + *bnew = a + ndbl * d; + if (d > 0.0) { + cdiff = *bnew - b; + } else { + cdiff = b - *bnew; + } + + if (std::abs(cdiff) < 4.4408920985006262E-16 * std::fmax(std::abs(a), std:: + abs(b))) { + ndbl++; + *bnew = b; + } else if (cdiff > 0.0) { + *bnew = a + (ndbl - 1.0) * d; + } else { + ndbl++; + } + + *n_too_large = (ndbl > 2.147483647E+9); + if (ndbl >= 0.0) { + *n = static_cast(ndbl); + } else { + *n = 0; + } + } + + void eml_float_colon(real_T a, real_T d, real_T b, ::coder::array + &y) + { + real_T a1; + real_T b1; + int32_T n; + boolean_T n_too_large; + float_colon_length(a, d, b, &n, &a1, &b1, &n_too_large); + y.set_size(1, n); + if (n > 0) { + y[0] = a1; + if (n > 1) { + real_T kd; + int32_T nm1d2; + y[n - 1] = b1; + nm1d2 = (n - 1) / 2; + for (int32_T k{0}; k <= nm1d2 - 2; k++) { + kd = (static_cast(k) + 1.0) * d; + y[k + 1] = a1 + kd; + y[(n - k) - 2] = b1 - kd; + } + + if (nm1d2 << 1 == n - 1) { + y[nm1d2] = (a1 + b1) / 2.0; + } else { + kd = static_cast(nm1d2) * d; + y[nm1d2] = a1 + kd; + y[nm1d2 + 1] = b1 - kd; + } + } + } + } + } +} + +// End of code generation (colon.cpp) diff --git a/RAT/colon.h b/RAT/colon.h new file mode 100644 index 00000000..42070349 --- /dev/null +++ b/RAT/colon.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// colon.h +// +// Code generation for function 'colon' +// +#ifndef COLON_H +#define COLON_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void eml_float_colon(real_T a, real_T d, real_T b, ::coder::array + &y); + } +} + +#endif + +// End of code generation (colon.h) diff --git a/RAT/complexTimes.cpp b/RAT/complexTimes.cpp new file mode 100644 index 00000000..5c2ade80 --- /dev/null +++ b/RAT/complexTimes.cpp @@ -0,0 +1,141 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// complexTimes.cpp +// +// Code generation for function 'complexTimes' +// + +// Include files +#include "complexTimes.h" +#include "rt_nonfinite.h" +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace scalar + { + static real_T rescale(real_T *re, real_T *im); + } + } + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace scalar + { + static real_T rescale(real_T *re, real_T *im) + { + real_T absim; + real_T scale; + scale = std::abs(*re); + absim = std::abs(*im); + if (scale > absim) { + if (*re < 0.0) { + *re = -1.0; + } else { + *re = 1.0; + } + + *im /= scale; + } else if (absim > scale) { + *re /= absim; + if (*im < 0.0) { + *im = -1.0; + } else { + *im = 1.0; + } + + scale = absim; + } else { + if (*re < 0.0) { + *re = -1.0; + } else { + *re = 1.0; + } + + if (*im < 0.0) { + *im = -1.0; + } else { + *im = 1.0; + } + } + + return scale; + } + + real_T complexTimes(real_T ar, real_T ai, real_T br, real_T bi) + { + real_T cr; + real_T sai; + real_T sar; + real_T sbi; + real_T sbr; + if ((ai == 0.0) && (bi == 0.0)) { + cr = 0.0; + } else { + real_T t3; + real_T t4; + t3 = ar * bi; + t4 = ai * br; + cr = t3 + t4; + if ((std::isinf(cr) || std::isnan(cr)) && (!std::isnan(ar)) && (!std:: + isnan(ai)) && (!std::isnan(br)) && (!std::isnan(bi))) { + real_T scaleA; + real_T scaleB; + boolean_T finiteScale; + sar = ar; + sai = ai; + scaleA = rescale(&sar, &sai); + sbr = br; + sbi = bi; + scaleB = rescale(&sbr, &sbi); + if ((!std::isinf(scaleA)) && (!std::isnan(scaleA)) && ((!std:: + isinf(scaleB)) && (!std::isnan(scaleB)))) { + finiteScale = true; + } else { + finiteScale = false; + } + + if (std::isnan(cr) || (std::isinf(cr) && finiteScale)) { + cr = sar * sbi + sai * sbr; + if (cr != 0.0) { + cr = cr * scaleA * scaleB; + } else if ((std::isinf(scaleA) && ((br == 0.0) || (bi == 0.0))) || + (std::isinf(scaleB) && ((ar == 0.0) || (ai == 0.0)))) + { + if (std::isnan(t3)) { + t3 = 0.0; + } + + if (std::isnan(t4)) { + t4 = 0.0; + } + + cr = t3 + t4; + } + } + } + } + + return cr; + } + } + } + } +} + +// End of code generation (complexTimes.cpp) diff --git a/RAT/complexTimes.h b/RAT/complexTimes.h new file mode 100644 index 00000000..978ad9f0 --- /dev/null +++ b/RAT/complexTimes.h @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// complexTimes.h +// +// Code generation for function 'complexTimes' +// +#ifndef COMPLEXTIMES_H +#define COMPLEXTIMES_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace scalar + { + real_T complexTimes(real_T ar, real_T ai, real_T br, real_T bi); + } + } + } +} + +#endif + +// End of code generation (complexTimes.h) diff --git a/RAT/customModelClass.cpp b/RAT/customModelClass.cpp new file mode 100644 index 00000000..408a7ad3 --- /dev/null +++ b/RAT/customModelClass.cpp @@ -0,0 +1,483 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// customModelClass.cpp +// +// Code generation for function 'customModelClass' +// + +// Include files +#include "customModelClass.h" +#include "backSort.h" +#include "callCppFunc.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "strcmp.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Type Definitions +namespace RAT +{ + struct cell_wrap_34 + { + ::coder::array f1; + }; + + struct cell_wrap_35 + { + ::coder::array f1; + }; +} + +// Function Declarations +namespace RAT +{ + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 1U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 1U> &r1); +} + +// Function Definitions +namespace RAT +{ + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + void customModelClass::processCustomLayers(const ::coder::array + &cBacks, const ::coder::array &cShifts, const ::coder::array< + real_T, 2U> &cScales, const ::coder::array &cNbas, const ::coder:: + array &cNbss, const ::coder::array &cRes, const :: + coder::array &backs, const ::coder::array &shifts, + const ::coder::array &sf, const ::coder::array &nba, + const ::coder::array &nbs, const ::coder::array &res, + const ::coder::array &cCustFiles, real_T numberOfContrasts, + const ::coder::array &customFiles, const ::coder::array< + real_T, 2U> ¶ms, boolean_T useImaginary, ::coder::array + &allLayers, ::coder::array &allRoughs) + { + ::coder::array tempAllLayers; + ::coder::array b_params; + ::coder::array thisContrastLayers; + real_T a__1; + real_T a__2; + real_T a__3; + real_T a__4; + real_T bulkIn; + real_T bulkOut; + real_T d1; + int32_T loop_ub_tmp; + + // Top-level function for processing custom layers for all the + // contrasts. + // Do some pre-definitions to keep the compiler happy... + loop_ub_tmp = static_cast(numberOfContrasts); + allRoughs.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + allRoughs[i] = 0.0; + } + + tempAllLayers.set_size(loop_ub_tmp); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + real_T d; + int32_T b_index; + + // TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's.. + // Choose which custom file is associated with this contrast + // Check what language it is.... + // ... and path + // ....also file. + // Find values of 'bulkIn' and 'bulkOut' for this + // contrast... + backSort(cBacks[b_i], cShifts[b_i], cScales[b_i], cNbas[b_i], cNbss[b_i], + cRes[b_i], backs, shifts, sf, nba, nbs, res, &a__1, &a__2, &a__3, + &bulkIn, &bulkOut, &a__4); + thisContrastLayers.set_size(1, 3); + thisContrastLayers[0] = 1.0; + thisContrastLayers[thisContrastLayers.size(0)] = 1.0; + thisContrastLayers[thisContrastLayers.size(0) * 2] = 1.0; + + // typeDef + d = cCustFiles[b_i]; + if (coder::internal::j_strcmp(customFiles[static_cast(d) - 1].f1 + [1].f1.data, customFiles[static_cast(d) - 1].f1[1].f1.size)) + { + b_index = 0; + } else if (coder::internal::k_strcmp(customFiles[static_cast(d) - + 1].f1[1].f1.data, customFiles[static_cast(d) - 1].f1 + [1].f1.size)) { + b_index = 1; + } else if (coder::internal::l_strcmp(customFiles[static_cast(d) - + 1].f1[1].f1.data, customFiles[static_cast(d) - 1].f1 + [1].f1.size)) { + b_index = 2; + } else { + b_index = -1; + } + + switch (b_index) { + case 0: + // Excecute a custom model function in the base Matlab workspace. + // This function uses feval to cause Matlab coder to pass excecution + // of the function named in 'fname' back to the base Matlab workspace, + // 'feval' generates an automatic coder.extrinsic call. + // Use a coder.extrinsic call here, so Coder will + // pass the excecution of the function back to the calling Matlab + // session. There is no need to explicitly declare the extrinsic + // as Coder automatically does this when it encounters 'feval' + // https://uk.mathworks.com/help/simulink/ug/use-matlab-engine-to-execute-a-function-call-in-generated-code.html + // Pre-define the outputs to keep the compiler happy + // Need to define the size of the outputs with coder preprocessor + // directives + // This maybe should be a 'coder.typeof' instead? + // + // % Because it is feval, coder sends this call to + // % the base Matlab workspace. The outputs of feval are mxArrays, + // % so we need to do some work afterwards casting these to doubles (below) + // + // % For backwards compatability with Rascal1... + // bulkOuts = zeros(nContrasts,1); + // bulkOuts(contrast) = bulkOut; + // + // % Feval is automatic call to base Matlab workspace.... + // [tempOut,tempRough] = feval(funcName,params,bulkIn,bulkOuts,contrast); + // + // % Tell coder n is doubles by defining it (otherwise 'size(n)' seems to return + // % [mxArray mxArray] not [double double]!), fill n with the size of the mxArray + // % 'tempOut', and use n to allocate the correct number of elements to 'output' + // % by filling output with zeros (i.e. output is an array of doubles) + // n = size(tempOut); + // + // % Copy the mxArrays to our doubles arrays, which then makes coder cast + // % the mxArrays to double. + // sRough = tempRough; + // output = tempOut; + thisContrastLayers.set_size(0, 0); + allRoughs[b_i] = 3.0; + break; + + case 1: + { + b_params.set_size(1, params.size(1)); + b_index = params.size(1) - 1; + for (int32_T i{0}; i <= b_index; i++) { + b_params[i] = params[i]; + } + + int32_T iv[2]; + int32_T iv1[2]; + int32_T iv2[2]; + thisContrastLayers.reserve(3000); + iv[0] = customFiles[static_cast(d) - 1].f1[0].f1.size[0]; + iv[1] = customFiles[static_cast(d) - 1].f1[0].f1.size[1]; + iv1[0] = customFiles[static_cast(d) - 1].f1[0].f1.size[0]; + iv1[1] = customFiles[static_cast(d) - 1].f1[0].f1.size[1]; + callCppFunc(b_params, bulkIn, bulkOut, static_cast(b_i) + 1.0, + customFiles[static_cast(d) - 1].f1[0].f1.data, iv, + customFiles[static_cast(d) - 1].f1[0].f1.data, + iv1, (real_T *)thisContrastLayers.data(), iv2, &d1); + allRoughs[b_i] = d1; + (*(int32_T (*)[2])thisContrastLayers.size())[0] = iv2[0]; + (*(int32_T (*)[2])thisContrastLayers.size())[1] = iv2[1]; + } + break; + + case 2: + // Excecute a python custom model function in the base Matlab workspace. + // This function uses feval to cause Matlab coder to execute + // 'callPythonFunction' in the base Matlab workspace. + // 'feval' generates an automatic coder.extrinsic call... + // Use a coder.extrinsic call here, so Coder will + // pass the excecution of the function back to the calling Matlab + // session. There is no need to explicitly declare the extrinsic + // as Coder automatically does this when it encounters 'feval' + // https://uk.mathworks.com/help/simulink/ug/use-matlab-engine-to-execute-a-function-call-in-generated-code.html + // Pre-define the outputs to keep the compiler happy + // Need to define the size of the outputs with coder preprocessor + // directives + // This maybe should be a 'coder.typeof' instead? + // Because it is feval, coder sends this call to + // the base Matlab workspace. The outputs of feval are mxArrays, + // so we need to do some work afterwards casting these to doubles (below) + // [tempOut,tempRough] = feval('callPythonFunction',funcName,params,bulkIn,bulkOut,contrast); + // Tell coder n is doubles by defining it (otherwise 'size(n)' seems to return + // [mxArray mxArray] not [double double]!), fill n with the size of the mxArray + // 'tempOut', and use n to allocate the correct number of elements to 'output' + // by filling output with zeros (i.e. output is an array of doubles) + // n = size(tempOut); + // Copy the mxArrays to our doubles arrays, which then makes coder cast + // the mxArrays to double. + // sRough = tempRough; + // output = tempOut; + thisContrastLayers.set_size(0, 0); + allRoughs[b_i] = 3.0; + break; + } + + // If the output layers has 5 columns, then we need to do + // the hydration correction (the user has not done it in the + // custom function). Do that here.... + if (!useImaginary) { + // Applies the hydration correction to real value of layers + // if it is necessary.. (This is for when im(SLD) is not used) + // The only guidance we have to whether the user is using hydration + // in their custom model is the numbre of columns of the output + // [nlayers x nCols] + tempAllLayers[b_i].f1.set_size(thisContrastLayers.size(0), + thisContrastLayers.size(1)); + b_index = thisContrastLayers.size(1); + for (int32_T i{0}; i < b_index; i++) { + int32_T loop_ub; + loop_ub = thisContrastLayers.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + tempAllLayers[b_i].f1[i1 + tempAllLayers[b_i].f1.size(0) * i] = + thisContrastLayers[i1 + thisContrastLayers.size(0) * i]; + } + } + } else { + // Applies the hydration correction to real value of layers + // if it is necessary.. (This is for when im(SLD) is used) + // The only guidance we have to whether the user is using hydration + // in their custom model is the number of columns of the output + // [nlayers x nCols] + tempAllLayers[b_i].f1.set_size(thisContrastLayers.size(0), + thisContrastLayers.size(1)); + b_index = thisContrastLayers.size(1); + for (int32_T i{0}; i < b_index; i++) { + int32_T loop_ub; + loop_ub = thisContrastLayers.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + tempAllLayers[b_i].f1[i1 + tempAllLayers[b_i].f1.size(0) * i] = + thisContrastLayers[i1 + thisContrastLayers.size(0) * i]; + } + } + } + } + + cast(tempAllLayers, allLayers); + } + + void customModelClass::processCustomXY(const ::coder::array + &cBacks, const ::coder::array &cShifts, const ::coder::array< + real_T, 2U> &cScales, const ::coder::array &cNbas, const ::coder:: + array &cNbss, const ::coder::array &cRes, const :: + coder::array &backs, const ::coder::array &shifts, + const ::coder::array &sf, const ::coder::array &nba, + const ::coder::array &nbs, const ::coder::array &res, + const ::coder::array &cCustFiles, real_T numberOfContrasts, + const ::coder::array &customFiles, const ::coder::array< + real_T, 2U> ¶ms, ::coder::array &allSLDs, ::coder:: + array &allRoughs) + { + ::coder::array tempAllSLDs; + ::coder::array b_params; + real_T tmp_data[3000]; + real_T a__5; + real_T a__6; + real_T a__7; + real_T a__8; + real_T bulkIn; + real_T bulkOut; + real_T d1; + int32_T loop_ub_tmp; + + // Top-level function for processing custom XY profiles for all the + // contrasts. + // Do some pre-definitions to keep the compiler happy... + loop_ub_tmp = static_cast(numberOfContrasts); + allRoughs.set_size(loop_ub_tmp); + tempAllSLDs.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + allRoughs[i] = 0.0; + + // Type def as double (size not important) + tempAllSLDs[i].f1.set_size(1, 2); + tempAllSLDs[i].f1[0] = 0.0; + tempAllSLDs[i].f1[tempAllSLDs[i].f1.size(0)] = 0.0; + } + + // 3 columns to allow for potential imaginary curve + for (int32_T i{0}; i < loop_ub_tmp; i++) { + real_T d; + int32_T b_index; + + // TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's.. + // Choose which custom file is associated with this contrast + // Check what language it is.... + // ... and path + // ....also file. + // Find values of 'bulkIn' and 'bulkOut' for thid + // contrast... + backSort(cBacks[i], cShifts[i], cScales[i], cNbas[i], cNbss[i], cRes[i], + backs, shifts, sf, nba, nbs, res, &a__5, &a__6, &a__7, &bulkIn, + &bulkOut, &a__8); + d = cCustFiles[i]; + if (coder::internal::j_strcmp(customFiles[static_cast(d) - 1].f1 + [1].f1.data, customFiles[static_cast(d) - 1].f1[1].f1.size)) + { + b_index = 0; + } else if (coder::internal::k_strcmp(customFiles[static_cast(d) - + 1].f1[1].f1.data, customFiles[static_cast(d) - 1].f1 + [1].f1.size)) { + b_index = 1; + } else if (coder::internal::l_strcmp(customFiles[static_cast(d) - + 1].f1[1].f1.data, customFiles[static_cast(d) - 1].f1 + [1].f1.size)) { + b_index = 2; + } else { + b_index = -1; + } + + switch (b_index) { + case 0: + // Excecute a custom model function in the base Matlab workspace. + // This function uses feval to cause Matlab coder to pass excecution + // of the function named in 'fname' back to the base Matlab workspace, + // 'feval' generates an automatic coder.extrinsic call. + // Use a coder.extrinsic call here, so Coder will + // pass the excecution of the function back to the calling Matlab + // session. There is no need to explicitly declare the extrinsic + // as Coder automatically does this when it encounters 'feval' + // https://uk.mathworks.com/help/simulink/ug/use-matlab-engine-to-execute-a-function-call-in-generated-code.html + // Pre-define the outputs to keep the compiler happy + // Need to define the size of the outputs with coder preprocessor + // directives + // This maybe should be a 'coder.typeof' instead? + // + // % Because it is feval, coder sends this call to + // % the base Matlab workspace. The outputs of feval are mxArrays, + // % so we need to do some work afterwards casting these to doubles (below) + // + // % For backwards compatability with Rascal1... + // bulkOuts = zeros(nContrasts,1); + // bulkOuts(contrast) = bulkOut; + // + // % Feval is automatic call to base Matlab workspace.... + // [tempOut,tempRough] = feval(funcName,params,bulkIn,bulkOuts,contrast); + // + // % Tell coder n is doubles by defining it (otherwise 'size(n)' seems to return + // % [mxArray mxArray] not [double double]!), fill n with the size of the mxArray + // % 'tempOut', and use n to allocate the correct number of elements to 'output' + // % by filling output with zeros (i.e. output is an array of doubles) + // n = size(tempOut); + // + // % Copy the mxArrays to our doubles arrays, which then makes coder cast + // % the mxArrays to double. + // sRough = tempRough; + // output = tempOut; + tempAllSLDs[i].f1.set_size(0, 0); + allRoughs[i] = 3.0; + break; + + case 1: + { + int32_T tmp_size[2]; + b_params.set_size(1, params.size(1)); + b_index = params.size(1) - 1; + for (int32_T b_i{0}; b_i <= b_index; b_i++) { + b_params[b_i] = params[b_i]; + } + + int32_T iv[2]; + int32_T iv1[2]; + iv[0] = customFiles[static_cast(d) - 1].f1[0].f1.size[0]; + iv[1] = customFiles[static_cast(d) - 1].f1[0].f1.size[1]; + iv1[0] = customFiles[static_cast(d) - 1].f1[0].f1.size[0]; + iv1[1] = customFiles[static_cast(d) - 1].f1[0].f1.size[1]; + callCppFunc(b_params, bulkIn, bulkOut, static_cast(i) + 1.0, + customFiles[static_cast(d) - 1].f1[0].f1.data, iv, + customFiles[static_cast(d) - 1].f1[0].f1.data, + iv1, tmp_data, tmp_size, &d1); + allRoughs[i] = d1; + b_index = tmp_size[0]; + tempAllSLDs[i].f1.set_size(tmp_size[0], 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + for (int32_T i1{0}; i1 < b_index; i1++) { + tempAllSLDs[i].f1[i1 + tempAllSLDs[i].f1.size(0) * b_i] = + tmp_data[i1 + tmp_size[0] * b_i]; + } + } + } + break; + + case 2: + // Excecute a python custom model function in the base Matlab workspace. + // This function uses feval to cause Matlab coder to execute + // 'callPythonFunction' in the base Matlab workspace. + // 'feval' generates an automatic coder.extrinsic call... + // Use a coder.extrinsic call here, so Coder will + // pass the excecution of the function back to the calling Matlab + // session. There is no need to explicitly declare the extrinsic + // as Coder automatically does this when it encounters 'feval' + // https://uk.mathworks.com/help/simulink/ug/use-matlab-engine-to-execute-a-function-call-in-generated-code.html + // Pre-define the outputs to keep the compiler happy + // Need to define the size of the outputs with coder preprocessor + // directives + // This maybe should be a 'coder.typeof' instead? + // Because it is feval, coder sends this call to + // the base Matlab workspace. The outputs of feval are mxArrays, + // so we need to do some work afterwards casting these to doubles (below) + // [tempOut,tempRough] = feval('callPythonFunction',funcName,params,bulkIn,bulkOut,contrast); + // Tell coder n is doubles by defining it (otherwise 'size(n)' seems to return + // [mxArray mxArray] not [double double]!), fill n with the size of the mxArray + // 'tempOut', and use n to allocate the correct number of elements to 'output' + // by filling output with zeros (i.e. output is an array of doubles) + // n = size(tempOut); + // Copy the mxArrays to our doubles arrays, which then makes coder cast + // the mxArrays to double. + // sRough = tempRough; + // output = tempOut; + tempAllSLDs[i].f1.set_size(0, 0); + allRoughs[i] = 3.0; + break; + } + } + + cast(tempAllSLDs, allSLDs); + } +} + +// End of code generation (customModelClass.cpp) diff --git a/RAT/customModelClass.h b/RAT/customModelClass.h new file mode 100644 index 00000000..86c43f46 --- /dev/null +++ b/RAT/customModelClass.h @@ -0,0 +1,59 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// customModelClass.h +// +// Code generation for function 'customModelClass' +// +#ifndef CUSTOMMODELCLASS_H +#define CUSTOMMODELCLASS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_wrap_7; + struct cell_wrap_15; +} + +// Type Definitions +namespace RAT +{ + class customModelClass + { + public: + static void processCustomLayers(const ::coder::array &cBacks, + const ::coder::array &cShifts, const ::coder::array + &cScales, const ::coder::array &cNbas, const ::coder::array< + real_T, 2U> &cNbss, const ::coder::array &cRes, const ::coder:: + array &backs, const ::coder::array &shifts, const :: + coder::array &sf, const ::coder::array &nba, const + ::coder::array &nbs, const ::coder::array &res, + const ::coder::array &cCustFiles, real_T numberOfContrasts, + const ::coder::array &customFiles, const ::coder::array< + real_T, 2U> ¶ms, boolean_T useImaginary, ::coder::array &allLayers, ::coder::array &allRoughs); + static void processCustomXY(const ::coder::array &cBacks, const :: + coder::array &cShifts, const ::coder::array + &cScales, const ::coder::array &cNbas, const ::coder::array< + real_T, 2U> &cNbss, const ::coder::array &cRes, const ::coder:: + array &backs, const ::coder::array &shifts, const :: + coder::array &sf, const ::coder::array &nba, const + ::coder::array &nbs, const ::coder::array &res, + const ::coder::array &cCustFiles, real_T numberOfContrasts, + const ::coder::array &customFiles, const ::coder::array< + real_T, 2U> ¶ms, ::coder::array &allSLDs, ::coder:: + array &allRoughs); + }; +} + +#endif + +// End of code generation (customModelClass.h) diff --git a/RAT/dataResolutionPolly.cpp b/RAT/dataResolutionPolly.cpp new file mode 100644 index 00000000..b0f98a4f --- /dev/null +++ b/RAT/dataResolutionPolly.cpp @@ -0,0 +1,71 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// dataResolutionPolly.cpp +// +// Code generation for function 'dataResolutionPolly' +// + +// Include files +#include "dataResolutionPolly.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void dataResolutionPolly(const ::coder::array &xdata, const :: + coder::array &ydata, const ::coder::array &resData, + real_T points, ::coder::array &out) + { + int32_T i; + int32_T loop_ub_tmp; + + // Apply resolution correction + loop_ub_tmp = static_cast(points); + out.set_size(loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { + out[i] = 0.0; + } + + for (int32_T j{0}; j < loop_ub_tmp; j++) { + real_T a; + real_T sumg; + int32_T ilow; + sumg = 0.0; + out[j] = 0.0; + if (static_cast(j) + 1U > 10U) { + ilow = -10; + } else { + ilow = static_cast(-(static_cast(j) + 1.0)) + 1; + } + + if (static_cast(j) + 1.0 < points - 10.0) { + a = 10.0; + } else { + a = points - (static_cast(j) + 1.0); + } + + i = static_cast(a + (1.0 - static_cast(ilow))); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T g; + int32_T a_tmp; + a_tmp = static_cast((static_cast(j) + 1.0) + + static_cast(ilow + b_i)) - 1; + a = (xdata[a_tmp] - xdata[j]) / (resData[j] * xdata[j]); + g = std::exp(-(a * a)); + sumg += g; + out[j] = out[j] + ydata[a_tmp] * g; + } + + if (sumg != 0.0) { + out[j] = out[j] / sumg; + } + } + } +} + +// End of code generation (dataResolutionPolly.cpp) diff --git a/RAT/dataResolutionPolly.h b/RAT/dataResolutionPolly.h new file mode 100644 index 00000000..44aa5787 --- /dev/null +++ b/RAT/dataResolutionPolly.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// dataResolutionPolly.h +// +// Code generation for function 'dataResolutionPolly' +// +#ifndef DATARESOLUTIONPOLLY_H +#define DATARESOLUTIONPOLLY_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void dataResolutionPolly(const ::coder::array &xdata, const :: + coder::array &ydata, const ::coder::array &resData, + real_T points, ::coder::array &out); +} + +#endif + +// End of code generation (dataResolutionPolly.h) diff --git a/RAT/dylib.hpp b/RAT/dylib.hpp new file mode 100644 index 00000000..00dd978a --- /dev/null +++ b/RAT/dylib.hpp @@ -0,0 +1,320 @@ +/** + * \file dylib.hpp + * \brief Cross-platform Dynamic Library Loader + * \author Martin Olivier + * \version 1.8.1 + * + * MIT License + * Copyright (c) 2022 Martin Olivier + */ + +#pragma once + +#include +#include +#include +#include +#if defined(_WIN32) || defined(_WIN64) +#define WIN32_LEAN_AND_MEAN +#define DYLIB_API extern "C" __declspec(dllexport) +#include +#undef WIN32_LEAN_AND_MEAN +#else +#define DYLIB_API extern "C" +#include +#endif + +/** + * The dylib class can hold a dynamic library instance and interact with it + * by getting its symbols like functions or global variables + */ +class dylib +{ +private: +#if defined(_WIN32) || defined(_WIN64) + HINSTANCE m_handle{nullptr}; + static HINSTANCE open_lib(const char *path) noexcept + { + return LoadLibraryA(path); + } + FARPROC get_symbol(const char *name) const noexcept + { + return GetProcAddress(m_handle, name); + } + void close_lib() noexcept + { + FreeLibrary(m_handle); + } + static char *get_error_message() noexcept + { + constexpr size_t buf_size = 512; + auto error_code = GetLastError(); + if (!error_code) + return nullptr; + static char msg[buf_size]; + auto lang = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); + const DWORD len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, error_code, lang, msg, buf_size, nullptr); + if (len > 0) + return msg; + return nullptr; + } +#else + void *m_handle{nullptr}; + static void *open_lib(const char *path) noexcept + { + return dlopen(path, RTLD_NOW | RTLD_LOCAL); + } + void *get_symbol(const char *name) const noexcept + { + return dlsym(m_handle, name); + } + void close_lib() noexcept + { + dlclose(m_handle); + } + static char *get_error_message() noexcept + { + return dlerror(); + } +#endif + static std::string get_handle_error(const std::string &name) + { + std::string msg = "dylib: error while loading dynamic library \"" + name + "\""; + auto err = get_error_message(); + if (!err) + return msg; + return msg + '\n' + err; + } + static std::string get_symbol_error(const std::string &name) + { + std::string msg = "dylib: error while loading symbol \"" + name + "\""; + auto err = get_error_message(); + if (!err) + return msg; + return msg + '\n' + err; + } + static std::string get_missing_handle_error(const std::string &symbol_name) + { + return "dylib: could not get symbol \"" + symbol_name + "\", no dynamic library currently loaded"; + } + +public: + +#if defined(_WIN32) || defined(_WIN64) + static constexpr auto extension = ".dll"; +#elif defined(__APPLE__) + static constexpr auto extension = ".dylib"; +#else + static constexpr auto extension = ".so"; +#endif + + /** + * This exception is thrown when the dylib class encountered an error + * + * @return the error message by calling what() member function + */ + class exception : public std::exception + { + protected: + const std::string m_error; + public: + explicit exception(std::string &&message) : m_error(std::move(message)) {} + const char *what() const noexcept override {return m_error.c_str();} + }; + + /** + * This exception is thrown when the library failed to load + * or encountered symbol resolution issues + * + * @param message the error message + */ + class handle_error : public exception + { + public: + explicit handle_error(std::string &&message) : exception(std::move(message)) {} + }; + + /** + * This exception is thrown when the library failed to load a symbol. + * This usually happens when you forgot to put before a library function or variable + * + * @param message the error message + */ + class symbol_error : public exception + { + public: + explicit symbol_error(std::string &&message) : exception(std::move(message)) {} + }; + + dylib(const dylib&) = delete; + dylib& operator=(const dylib&) = delete; + + dylib(dylib &&other) noexcept : m_handle(other.m_handle) + { + other.m_handle = nullptr; + } + + dylib& operator=(dylib &&other) noexcept + { + if (this != &other) { + close(); + m_handle = other.m_handle; + other.m_handle = nullptr; + } + return *this; + } + + dylib() noexcept = default; + + /** + * Creates a dynamic library instance + * + * @param path path to the dynamic library to load + * @param ext use dylib::extension to specify the os extension (optional parameter) + */ + explicit dylib(const char *path) + { + open(path); + } + + explicit dylib(const std::string &path) + { + open(path.c_str()); + } + + dylib(std::string path, const char *ext) + { + open(std::move(path), ext); + } + + ~dylib() + { + close(); + } + + /** + * Load a dynamic library into the object. + * If a dynamic library was already opened, it will be unload and replaced + * + * @param path the path of the dynamic library to load + * @param ext use dylib::extension to detect the current os extension (optional parameter) + */ + void open(const char *path) + { + close(); + if (!path) + throw handle_error(get_handle_error("(nullptr)")); + m_handle = open_lib(path); + if (!m_handle) + throw handle_error(get_handle_error(path)); + } + + void open(const std::string &path) + { + open(path.c_str()); + } + + void open(std::string path, const char *ext) + { + if (!ext) + throw handle_error("dylib: failed to load \"" + path + "\", bad extension: (nullptr)"); + open(path + ext); + } + + /** + * Get a function from the dynamic library currently loaded in the object + * + * @param T the template argument must be the function prototype. + * it must be the same pattern as the template of std::function + * @param name the symbol name of the function to get from the dynamic library + * + * @return std::function that contains the function + */ + template + std::function get_function(const char *name) const + { + if (!name) + throw symbol_error(get_symbol_error("(nullptr)")); + if (!m_handle) + throw handle_error(get_missing_handle_error(name)); + auto sym = get_symbol(name); + if (!sym) + throw symbol_error(get_symbol_error(name)); + return reinterpret_cast(sym); + } + + template + std::function get_function(const std::string &name) const + { + return get_function(name.c_str()); + } + + /** + * Get a global variable from the dynamic library currently loaded in the object + * + * @param T type of the global variable + * @param name the name of the global variable to get from the dynamic library + * + * @return global variable of type + */ + template + T &get_variable(const char *name) const + { + if (!name) + throw symbol_error(get_symbol_error("(nullptr)")); + if (!m_handle) + throw handle_error(get_missing_handle_error(name)); + auto sym = get_symbol(name); + if (!sym) + throw symbol_error(get_symbol_error(name)); + return *reinterpret_cast(sym); + } + + template + T &get_variable(const std::string &name) const + { + return get_variable(name.c_str()); + } + + /** + * Check if a symbol exists in the currently loaded dynamic library. + * This method will return false if no dynamic library is currently loaded or if the symbol equals nullptr + * + * @param symbol the symbol name to look for + * + * @return true if the symbol exists in the dynamic library, false otherwise + */ + bool has_symbol(const char *symbol) const noexcept + { + if (!symbol) + return false; + if (!m_handle) + return false; + return get_symbol(symbol) != nullptr; + } + + bool has_symbol(const std::string &symbol) const noexcept + { + return has_symbol(symbol.c_str()); + } + + /** + * @return true if a dynamic library is currently loaded in the object, false otherwise + */ + operator bool() const noexcept + { + return m_handle != nullptr; + } + + /** + * Close the dynamic library currently loaded in the object. + * This function will be automatically called by the class destructor + */ + void close() noexcept + { + if (m_handle) { + close_lib(); + m_handle = nullptr; + } + } +}; \ No newline at end of file diff --git a/RAT/eml_erfcore.cpp b/RAT/eml_erfcore.cpp new file mode 100644 index 00000000..0ad76f38 --- /dev/null +++ b/RAT/eml_erfcore.cpp @@ -0,0 +1,179 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eml_erfcore.cpp +// +// Code generation for function 'eml_erfcore' +// + +// Include files +#include "eml_erfcore.h" +#include "log2.h" +#include "rt_nonfinite.h" +#include + +// Function Declarations +namespace RAT +{ + static real_T rt_powd_snf(real_T u0, real_T u1); +} + +// Function Definitions +namespace RAT +{ + static real_T rt_powd_snf(real_T u0, real_T u1) + { + real_T y; + if (std::isnan(u0) || std::isnan(u1)) { + y = rtNaN; + } else { + real_T d; + real_T d1; + d = std::abs(u0); + d1 = std::abs(u1); + if (std::isinf(u1)) { + if (d == 1.0) { + y = 1.0; + } else if (d > 1.0) { + if (u1 > 0.0) { + y = rtInf; + } else { + y = 0.0; + } + } else if (u1 > 0.0) { + y = 0.0; + } else { + y = rtInf; + } + } else if (d1 == 0.0) { + y = 1.0; + } else if (d1 == 1.0) { + if (u1 > 0.0) { + y = u0; + } else { + y = 1.0 / u0; + } + } else if (u1 == 2.0) { + y = u0 * u0; + } else if ((u1 == 0.5) && (u0 >= 0.0)) { + y = std::sqrt(u0); + } else if ((u0 < 0.0) && (u1 > std::floor(u1))) { + y = rtNaN; + } else { + y = std::pow(u0, u1); + } + } + + return y; + } + + namespace coder + { + real_T scalar_erf(real_T x) + { + real_T P; + real_T absx; + real_T s; + real_T y; + + // ========================== COPYRIGHT NOTICE ============================ + // The algorithms for calculating ERF(X) and ERFC(X) are derived + // from FDLIBM, which has the following notice: + // + // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + // + // Developed at SunSoft, a Sun Microsystems, Inc. business. + // Permission to use, copy, modify, and distribute this + // software is freely granted, provided that this notice + // is preserved. + // ============================= END ================================ + absx = std::abs(x); + if (std::isnan(x)) { + y = rtNaN; + } else if (std::isinf(x)) { + if (x < 0.0) { + y = -1.0; + } else { + y = 1.0; + } + } else if (absx < 0.84375) { + if (absx < 3.7252902984619141E-9) { + if (absx < 2.8480945388892178E-306) { + y = 0.125 * (8.0 * x + 1.0270333367641007 * x); + } else { + y = x + 0.12837916709551259 * x; + } + } else { + s = x * x; + y = x + x * ((s * (s * (s * (s * -2.3763016656650163E-5 - + 0.0057702702964894416) - 0.02848174957559851) - 0.3250421072470015) + + 0.12837916709551256) / (s * (s * (s * (s * (s * + -3.9602282787753681E-6 + 0.00013249473800432164) + + 0.0050813062818757656) + 0.0650222499887673) + 0.39791722395915535) + + 1.0)); + } + } else if (absx < 1.25) { + P = (absx - 1.0) * ((absx - 1.0) * ((absx - 1.0) * ((absx - 1.0) * + ((absx - 1.0) * ((absx - 1.0) * -0.0021663755948687908 + + 0.035478304325618236) - 0.11089469428239668) + + 0.31834661990116175) - 0.37220787603570132) + 0.41485611868374833) - + 0.0023621185607526594; + s = (absx - 1.0) * ((absx - 1.0) * ((absx - 1.0) * ((absx - 1.0) * + ((absx - 1.0) * ((absx - 1.0) * 0.011984499846799107 + + 0.013637083912029051) + 0.12617121980876164) + + 0.071828654414196266) + 0.540397917702171) + 0.10642088040084423) + + 1.0; + if (x >= 0.0) { + y = P / s + 0.84506291151046753; + } else { + y = -0.84506291151046753 - P / s; + } + } else if (absx > 6.0) { + if (x < 0.0) { + y = -1.0; + } else { + y = 1.0; + } + } else { + real_T R; + real_T S; + s = 1.0 / (absx * absx); + if (absx < 2.8571434020996094) { + R = s * (s * (s * (s * (s * (s * (s * -9.8143293441691455 - + 81.2874355063066) - 184.60509290671104) - 162.39666946257347) - + 62.375332450326006) - 10.558626225323291) - + 0.69385857270718176) - 0.0098649440348471482; + S = s * (s * (s * (s * (s * (s * (s * (s * -0.0604244152148581 + + 6.5702497703192817) + 108.63500554177944) + 429.00814002756783) + + 645.38727173326788) + 434.56587747522923) + + 137.65775414351904) + 19.651271667439257) + 1.0; + } else { + R = s * (s * (s * (s * (s * (s * -483.5191916086514 - + 1025.0951316110772) - 637.56644336838963) - 160.63638485582192) - + 17.757954917754752) - 0.799283237680523) - + 0.0098649429247001; + S = s * (s * (s * (s * (s * (s * (s * -22.440952446585818 + + 474.52854120695537) + 2553.0504064331644) + 3199.8582195085955) + + 1536.729586084437) + 325.79251299657392) + + 30.338060743482458) + 1.0; + } + + b_log2(absx, &s, &P); + s = std::floor(s * 2.097152E+6) / 2.097152E+6 * rt_powd_snf(2.0, P); + y = std::exp(-s * s - 0.5625) * std::exp((s - absx) * (s + absx) + R / S) + / absx; + if (x < 0.0) { + y--; + } else { + y = 1.0 - y; + } + } + + return y; + } + } +} + +// End of code generation (eml_erfcore.cpp) diff --git a/RAT/eml_erfcore.h b/RAT/eml_erfcore.h new file mode 100644 index 00000000..f76642bb --- /dev/null +++ b/RAT/eml_erfcore.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eml_erfcore.h +// +// Code generation for function 'eml_erfcore' +// +#ifndef EML_ERFCORE_H +#define EML_ERFCORE_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + real_T scalar_erf(real_T x); + } +} + +#endif + +// End of code generation (eml_erfcore.h) diff --git a/RAT/eml_mtimes_helper.cpp b/RAT/eml_mtimes_helper.cpp new file mode 100644 index 00000000..795b35b0 --- /dev/null +++ b/RAT/eml_mtimes_helper.cpp @@ -0,0 +1,95 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eml_mtimes_helper.cpp +// +// Code generation for function 'eml_mtimes_helper' +// + +// Include files +#include "eml_mtimes_helper.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void binary_expand_op(::coder::array &in1, real_T in2, const :: + coder::array &in3, const ::coder::array< + real_T, 2U> &in4) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in4.size(1) == 1) { + i = in3.size(1); + } else { + i = in4.size(1); + } + + in1.set_size(1, i); + stride_0_1 = (in3.size(1) != 1); + stride_1_1 = (in4.size(1) != 1); + if (in4.size(1) == 1) { + loop_ub = in3.size(1); + } else { + loop_ub = in4.size(1); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = in2 * (in3[i * stride_0_1] - in4[i * stride_1_1]); + } + } + + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in3.size(1) == 1) { + i = in2.size(1); + } else { + i = in3.size(1); + } + + in1.set_size(1, i); + stride_0_1 = (in2.size(1) != 1); + stride_1_1 = (in3.size(1) != 1); + if (in3.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(1); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = 0.0 * (in2[i * stride_0_1] - in3[i * stride_1_1]); + } + } + + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in3, const ::coder::array &in4, + const ::coder::array &in5) + { + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + stride_0_0 = (in4.size(0) != 1); + stride_1_0 = (in5.size(0) != 1); + if (in5.size(0) == 1) { + loop_ub = in4.size(0); + } else { + loop_ub = in5.size(0); + } + + for (int32_T i{0}; i < loop_ub; i++) { + in1[i] = 0.5 * (in3[in4[i * stride_0_0] - 1] + in3[in5[i * stride_1_0] - 1]); + } + } +} + +// End of code generation (eml_mtimes_helper.cpp) diff --git a/RAT/eml_mtimes_helper.h b/RAT/eml_mtimes_helper.h new file mode 100644 index 00000000..55ab18c9 --- /dev/null +++ b/RAT/eml_mtimes_helper.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eml_mtimes_helper.h +// +// Code generation for function 'eml_mtimes_helper' +// +#ifndef EML_MTIMES_HELPER_H +#define EML_MTIMES_HELPER_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void binary_expand_op(::coder::array &in1, real_T in2, const :: + coder::array &in3, const ::coder::array< + real_T, 2U> &in4); + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3); + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in3, const ::coder::array &in4, + const ::coder::array &in5); +} + +#endif + +// End of code generation (eml_mtimes_helper.h) diff --git a/RAT/erf.cpp b/RAT/erf.cpp new file mode 100644 index 00000000..732ce526 --- /dev/null +++ b/RAT/erf.cpp @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// erf.cpp +// +// Code generation for function 'erf' +// + +// Include files +#include "erf.h" +#include "eml_erfcore.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_erf(const ::coder::array &x, ::coder::array + &y) + { + y.set_size(1, x.size(1)); + if (x.size(1) != 0) { + int32_T i; + i = x.size(1); + for (int32_T k{0}; k < i; k++) { + y[k] = scalar_erf(x[k]); + } + } + } + } +} + +// End of code generation (erf.cpp) diff --git a/RAT/erf.h b/RAT/erf.h new file mode 100644 index 00000000..54f5df83 --- /dev/null +++ b/RAT/erf.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// erf.h +// +// Code generation for function 'erf' +// +#ifndef ERF_H +#define ERF_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_erf(const ::coder::array &x, ::coder::array + &y); + } +} + +#endif + +// End of code generation (erf.h) diff --git a/RAT/eventHelper.hpp b/RAT/eventHelper.hpp new file mode 100644 index 00000000..a1ab809c --- /dev/null +++ b/RAT/eventHelper.hpp @@ -0,0 +1,79 @@ +#ifndef WRAPPER_H +#define WRAPPER_H + +#include +#include +#include "dylib.hpp" // dylib.hpp is a header file that contains the dylib class that extracts a function from dll + +class eventHelper +{ + public: + std::unique_ptr library; + bool initialised = false; + + eventHelper(void){}; + ~eventHelper(void){}; + + eventHelper& operator=(eventHelper* other) noexcept + { + if (other) { + this->library = std::move(other->library); + this->initialised = other->initialised; + } + else { + this->library = NULL; + this->initialised = false; + } + return *this; + }; + + eventHelper& operator=(eventHelper &&other) noexcept + { + if (this != &other) { + this->library = std::move(other.library); + this->initialised = other.initialised; + } + return *this; + }; + + bool isInitialised(void){ return this->initialised;}; + + void init(const char* path) + { + try + { + char filename[18] = "eventManager"; + this->library = std::unique_ptr(new dylib(path, strcat(filename, dylib::extension))); + this->initialised = true; + } + catch (const dylib::handle_error &) + { + this->initialised = false; + } + }; + + void sendMessage(const char* msg) + { + auto sendMessage = library->get_function("sendMessage"); + + // pass the arguments to the function + return sendMessage(msg); + + }; + + void updatePlot(int nContrast, double* reflect, double* nReflect, double* shiftedData, double* nShiftedData, + double* sldProfiles, double* nSldProfiles, double* layers, double* nLayers, double* ssubs, + double* resample, double* dataPresent, const char* modelType) + { + auto updatePlot = library->get_function("updatePlot"); + + // pass the arguments to the function + return updatePlot(nContrast, reflect, nReflect, shiftedData, nShiftedData, sldProfiles, nSldProfiles, + layers, nLayers, ssubs, resample, dataPresent, modelType); + + }; +}; + +#endif diff --git a/RAT/examples/main.cpp b/RAT/examples/main.cpp new file mode 100644 index 00000000..7d85384f --- /dev/null +++ b/RAT/examples/main.cpp @@ -0,0 +1,646 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// main.cpp +// +// Code generation for function 'main' +// + +/*************************************************************************/ +/* This automatically generated example C++ main file shows how to call */ +/* entry-point functions that MATLAB Coder generated. You must customize */ +/* this file for your application. Do not modify this file directly. */ +/* Instead, make a copy of this file, modify it, and integrate it into */ +/* your development environment. */ +/* */ +/* This file initializes entry-point function arguments to a default */ +/* size and value before calling the entry-point functions. It does */ +/* not store or use any values returned from the entry-point functions. */ +/* If necessary, it does pre-allocate memory for returned values. */ +/* You can use this file as a starting point for a main function that */ +/* you can deploy in your application. */ +/* */ +/* After you copy the file, and before you deploy it, you must make the */ +/* following changes: */ +/* * For variable-size function arguments, change the example sizes to */ +/* the sizes that your application requires. */ +/* * Change the example values of function arguments to the values that */ +/* your application requires. */ +/* * If the entry-point functions return values, store these values or */ +/* otherwise use them as required by your application. */ +/* */ +/*************************************************************************/ + +// Include files +#include "main.h" +#include "reflectivityCalculation.h" +#include "reflectivityCalculation_initialize.h" +#include "reflectivityCalculation_terminate.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Declarations +static void argInit_1x2_real_T(real_T result[2]); +static void argInit_1x3_cell_wrap_6(RAT::cell_wrap_6 result[3]); +static coder::array argInit_1xd10000_cell_wrap_0(); +static coder::array argInit_1xd10000_cell_wrap_1(); +static coder::array argInit_1xd10000_cell_wrap_2(); +static coder::array argInit_1xd10000_cell_wrap_3(); +static coder::array argInit_1xd10000_cell_wrap_5(); +static coder::array argInit_1xd10000_cell_wrap_6(); +static coder::array argInit_1xd10000_cell_wrap_7(); +static void argInit_1xd10000_char_T(char_T result_data[], int32_T result_size[2]); +static coder::array argInit_1xd10000_real_T(); +static boolean_T argInit_boolean_T(); +static void argInit_cell_8(RAT::cell_8 *result); +static RAT::cell_wrap_0 argInit_cell_wrap_0(); +static RAT::cell_wrap_1 argInit_cell_wrap_1(); +static RAT::cell_wrap_2 argInit_cell_wrap_2(); +static RAT::cell_wrap_3 argInit_cell_wrap_3(); +static void argInit_cell_wrap_4(RAT::cell_wrap_4 *result); +static void argInit_cell_wrap_5(RAT::cell_wrap_5 *result); +static void argInit_cell_wrap_6(RAT::cell_wrap_6 *result); +static void argInit_cell_wrap_7(RAT::cell_wrap_7 *result); +static char_T argInit_char_T(); +static coder::array argInit_d10000x1_cell_wrap_4(); +static coder::array argInit_d10000x2_real_T(); +static coder::array argInit_d10000xd10000_real_T(); +static coder::array argInit_d1xd10000_real_T(); +static void argInit_d1xd2_real_T(real_T result_data[], int32_T result_size[2]); +static real_T argInit_real_T(); +static void argInit_struct0_T(RAT::struct0_T *result); +static void argInit_struct1_T(RAT::struct1_T *result); +static void argInit_struct2_T(RAT::struct2_T *result); +static void argInit_struct3_T(RAT::struct3_T *result); + +// Function Definitions +static void argInit_1x2_real_T(real_T result[2]) +{ + // Loop over the array to initialize each element. + for (int32_T idx1{0}; idx1 < 2; idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result[idx1] = argInit_real_T(); + } +} + +static void argInit_1x3_cell_wrap_6(RAT::cell_wrap_6 result[3]) +{ + // Loop over the array to initialize each element. + for (int32_T idx1{0}; idx1 < 3; idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + argInit_cell_wrap_6(&result[idx1]); + } +} + +static coder::array argInit_1xd10000_cell_wrap_0() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(1, 2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < 1; idx0++) { + for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result[idx1] = argInit_cell_wrap_0(); + } + } + + return result; +} + +static coder::array argInit_1xd10000_cell_wrap_1() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(1, 2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < 1; idx0++) { + for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result[idx1] = argInit_cell_wrap_1(); + } + } + + return result; +} + +static coder::array argInit_1xd10000_cell_wrap_2() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(1, 2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < 1; idx0++) { + for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result[idx1] = argInit_cell_wrap_2(); + } + } + + return result; +} + +static coder::array argInit_1xd10000_cell_wrap_3() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(1, 2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < 1; idx0++) { + for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result[idx1] = argInit_cell_wrap_3(); + } + } + + return result; +} + +static coder::array argInit_1xd10000_cell_wrap_5() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(1, 2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < 1; idx0++) { + for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + argInit_cell_wrap_5(&result[idx1]); + } + } + + return result; +} + +static coder::array argInit_1xd10000_cell_wrap_6() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(1, 2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < 1; idx0++) { + for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + argInit_cell_wrap_6(&result[idx1]); + } + } + + return result; +} + +static coder::array argInit_1xd10000_cell_wrap_7() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(1, 2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < 1; idx0++) { + for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + argInit_cell_wrap_7(&result[idx1]); + } + } + + return result; +} + +static void argInit_1xd10000_char_T(char_T result_data[], int32_T result_size[2]) +{ + // Set the size of the array. + // Change this size to the value that the application requires. + result_size[0] = 1; + result_size[1] = 2; + + // Loop over the array to initialize each element. + for (int32_T idx1{0}; idx1 < 2; idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result_data[idx1] = argInit_char_T(); + } +} + +static coder::array argInit_1xd10000_real_T() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(1, 2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < 1; idx0++) { + for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result[idx1] = argInit_real_T(); + } + } + + return result; +} + +static boolean_T argInit_boolean_T() +{ + return false; +} + +static void argInit_cell_8(RAT::cell_8 *result) +{ + coder::array result_tmp; + coder::array b_result_tmp; + coder::array c_result_tmp; + coder::array d_result_tmp; + coder::array e_result_tmp; + + // Set the value of each structure field. + // Change this value to the value that the application requires. + result_tmp = argInit_1xd10000_cell_wrap_0(); + result->f1 = result_tmp; + b_result_tmp = argInit_1xd10000_cell_wrap_1(); + result->f2 = b_result_tmp; + result->f3 = result_tmp; + result->f4 = argInit_1xd10000_cell_wrap_2(); + c_result_tmp = argInit_1xd10000_cell_wrap_3(); + result->f5 = c_result_tmp; + result->f6 = argInit_d10000x1_cell_wrap_4(); + d_result_tmp = argInit_1xd10000_cell_wrap_5(); + result->f7 = d_result_tmp; + e_result_tmp = argInit_1xd10000_cell_wrap_6(); + result->f8 = e_result_tmp; + result->f9 = e_result_tmp; + result->f10 = e_result_tmp; + result->f11 = e_result_tmp; + result->f12 = e_result_tmp; + result->f13 = e_result_tmp; + result->f14 = argInit_1xd10000_cell_wrap_7(); + result->f15 = d_result_tmp; + result->f16 = d_result_tmp; + result->f17 = b_result_tmp; + result->f18 = result_tmp; + result->f19 = c_result_tmp; + result->f20 = e_result_tmp; +} + +static RAT::cell_wrap_0 argInit_cell_wrap_0() +{ + RAT::cell_wrap_0 result; + + // Set the value of each structure field. + // Change this value to the value that the application requires. + argInit_1x2_real_T(result.f1); + return result; +} + +static RAT::cell_wrap_1 argInit_cell_wrap_1() +{ + RAT::cell_wrap_1 result; + + // Set the value of each structure field. + // Change this value to the value that the application requires. + result.f1 = argInit_d10000xd10000_real_T(); + return result; +} + +static RAT::cell_wrap_2 argInit_cell_wrap_2() +{ + RAT::cell_wrap_2 result; + + // Set the value of each structure field. + // Change this value to the value that the application requires. + argInit_d1xd2_real_T(result.f1.data, result.f1.size); + return result; +} + +static RAT::cell_wrap_3 argInit_cell_wrap_3() +{ + RAT::cell_wrap_3 result; + + // Set the value of each structure field. + // Change this value to the value that the application requires. + result.f1 = argInit_d1xd10000_real_T(); + return result; +} + +static void argInit_cell_wrap_4(RAT::cell_wrap_4 *result) +{ + // Set the value of each structure field. + // Change this value to the value that the application requires. + argInit_d1xd2_real_T(result->f1.data, result->f1.size); +} + +static void argInit_cell_wrap_5(RAT::cell_wrap_5 *result) +{ + // Set the value of each structure field. + // Change this value to the value that the application requires. + argInit_1xd10000_char_T(result->f1.data, result->f1.size); +} + +static void argInit_cell_wrap_6(RAT::cell_wrap_6 *result) +{ + // Set the value of each structure field. + // Change this value to the value that the application requires. + argInit_1xd10000_char_T(result->f1.data, result->f1.size); +} + +static void argInit_cell_wrap_7(RAT::cell_wrap_7 *result) +{ + // Set the value of each structure field. + // Change this value to the value that the application requires. + argInit_1x3_cell_wrap_6(result->f1); +} + +static char_T argInit_char_T() +{ + return '?'; +} + +static coder::array argInit_d10000x1_cell_wrap_4() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < result.size(0); idx0++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + argInit_cell_wrap_4(&result[idx0]); + } + + return result; +} + +static coder::array argInit_d10000x2_real_T() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(2, 2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < result.size(0); idx0++) { + for (int32_T idx1{0}; idx1 < 2; idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result[idx0 + result.size(0) * idx1] = argInit_real_T(); + } + } + + return result; +} + +static coder::array argInit_d10000xd10000_real_T() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(2, 2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < result.size(0); idx0++) { + for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result[idx0 + result.size(0) * idx1] = argInit_real_T(); + } + } + + return result; +} + +static coder::array argInit_d1xd10000_real_T() +{ + coder::array result; + + // Set the size of the array. + // Change this size to the value that the application requires. + result.set_size(1, 2); + + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < result.size(0); idx0++) { + for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result[result.size(0) * idx1] = argInit_real_T(); + } + } + + return result; +} + +static void argInit_d1xd2_real_T(real_T result_data[], int32_T result_size[2]) +{ + // Set the size of the array. + // Change this size to the value that the application requires. + result_size[0] = 1; + result_size[1] = 2; + + // Loop over the array to initialize each element. + for (int32_T idx1{0}; idx1 < 2; idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result_data[idx1] = argInit_real_T(); + } +} + +static real_T argInit_real_T() +{ + return 0.0; +} + +static void argInit_struct0_T(RAT::struct0_T *result) +{ + coder::array b_result_tmp; + real_T result_tmp; + + // Set the value of each structure field. + // Change this value to the value that the application requires. + result_tmp = argInit_real_T(); + result->numberOfLayers = result_tmp; + result->numberOfDomainContrasts = result_tmp; + b_result_tmp = argInit_1xd10000_real_T(); + result->contrastBacks = b_result_tmp; + result->contrastBacksType = b_result_tmp; + argInit_1xd10000_char_T(result->TF.data, result->TF.size); + result->resample = b_result_tmp; + result->dataPresent = b_result_tmp; + result->oilChiDataPresent = b_result_tmp; + result->numberOfContrasts = result_tmp; + argInit_1xd10000_char_T(result->geometry.data, result->geometry.size); + result->useImaginary = argInit_boolean_T(); + result->contrastShifts = b_result_tmp; + result->contrastScales = b_result_tmp; + result->contrastNbas = b_result_tmp; + result->contrastNbss = b_result_tmp; + result->contrastRes = b_result_tmp; + result->backs = b_result_tmp; + result->shifts = b_result_tmp; + result->sf = b_result_tmp; + result->nba = b_result_tmp; + result->nbs = b_result_tmp; + result->res = b_result_tmp; + result->params = b_result_tmp; + argInit_1xd10000_char_T(result->modelType.data, result->modelType.size); + result->contrastCustomFiles = b_result_tmp; + result->contrastDomainRatios = b_result_tmp; + result->domainRatio = b_result_tmp; + result->domainContrastCustomFiles = b_result_tmp; + b_result_tmp = argInit_d10000xd10000_real_T(); + result->fitpars = b_result_tmp; + result->otherpars = b_result_tmp; + result->fitconstr = b_result_tmp; + result->otherconstr = b_result_tmp; +} + +static void argInit_struct1_T(RAT::struct1_T *result) +{ + coder::array result_tmp; + + // Set the value of each structure field. + // Change this value to the value that the application requires. + result_tmp = argInit_d10000x2_real_T(); + result->params = result_tmp; + result->backs = result_tmp; + result->scales = result_tmp; + result->shifts = result_tmp; + result->nba = result_tmp; + result->nbs = result_tmp; + result->res = result_tmp; + result->domainRatio = result_tmp; +} + +static void argInit_struct2_T(RAT::struct2_T *result) +{ + real_T result_tmp; + + // Set the value of each structure field. + // Change this value to the value that the application requires. + result_tmp = argInit_real_T(); + result->tolFun = result_tmp; + result->maxFunEvals = result_tmp; + result->maxIter = result_tmp; + result->populationSize = result_tmp; + result->fWeight = result_tmp; + result->F_CR = result_tmp; + result->VTR = result_tmp; + result->numGen = result_tmp; + result->strategy = result_tmp; + result->Nlive = result_tmp; + result->nmcmc = result_tmp; + result->propScale = result_tmp; + result->nsTolerance = result_tmp; + result->calcSld = result_tmp; + result->updateFreq = result_tmp; + result->updatePlotFreq = result_tmp; + result->nSamples = result_tmp; + result->nChains = result_tmp; + result->lambda = result_tmp; + result->pUnitGamma = result_tmp; + argInit_1xd10000_char_T(result->para.data, result->para.size); + argInit_1xd10000_char_T(result->proc.data, result->proc.size); + argInit_1xd10000_char_T(result->display.data, result->display.size); + result->tolX = result_tmp; + argInit_1x2_real_T(result->resamPars); + argInit_1xd10000_char_T(result->boundHandling.data, result->boundHandling.size); + argInit_struct3_T(&result->checks); +} + +static void argInit_struct3_T(RAT::struct3_T *result) +{ + coder::array result_tmp; + + // Set the value of each structure field. + // Change this value to the value that the application requires. + result_tmp = argInit_1xd10000_real_T(); + result->params_fitYesNo = result_tmp; + result->backs_fitYesNo = result_tmp; + result->shifts_fitYesNo = result_tmp; + result->scales_fitYesNo = result_tmp; + result->nbairs_fitYesNo = result_tmp; + result->nbsubs_fitYesNo = result_tmp; + result->resol_fitYesNo = result_tmp; + result->domainRatio_fitYesNo = result_tmp; +} + +int32_T main(int32_T, char **) +{ + // Initialize the application. + // You do not need to do this more than one time. + RAT::reflectivityCalculation_initialize(); + + // Invoke the entry-point functions. + // You can call entry-point functions multiple times. + main_reflectivityCalculation(); + + // Terminate the application. + // You do not need to do this more than one time. + RAT::reflectivityCalculation_terminate(); + return 0; +} + +void main_reflectivityCalculation() +{ + RAT::cell_11 result; + RAT::cell_8 problemDefCells; + RAT::struct0_T problemDef; + RAT::struct1_T problemDefLimits; + RAT::struct2_T controls; + RAT::struct4_T problem; + + // Initialize function 'reflectivityCalculation' input arguments. + // Initialize function input argument 'problemDef'. + argInit_struct0_T(&problemDef); + + // Initialize function input argument 'problemDefCells'. + argInit_cell_8(&problemDefCells); + + // Initialize function input argument 'problemDefLimits'. + argInit_struct1_T(&problemDefLimits); + + // Initialize function input argument 'controls'. + argInit_struct2_T(&controls); + + // Call the entry-point 'reflectivityCalculation'. + RAT::reflectivityCalculation(&problemDef, &problemDefCells, &problemDefLimits, + &controls, &problem, &result); +} + +// End of code generation (main.cpp) diff --git a/RAT/examples/main.h b/RAT/examples/main.h new file mode 100644 index 00000000..5462f7f0 --- /dev/null +++ b/RAT/examples/main.h @@ -0,0 +1,49 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// main.h +// +// Code generation for function 'main' +// + +/*************************************************************************/ +/* This automatically generated example C++ main file shows how to call */ +/* entry-point functions that MATLAB Coder generated. You must customize */ +/* this file for your application. Do not modify this file directly. */ +/* Instead, make a copy of this file, modify it, and integrate it into */ +/* your development environment. */ +/* */ +/* This file initializes entry-point function arguments to a default */ +/* size and value before calling the entry-point functions. It does */ +/* not store or use any values returned from the entry-point functions. */ +/* If necessary, it does pre-allocate memory for returned values. */ +/* You can use this file as a starting point for a main function that */ +/* you can deploy in your application. */ +/* */ +/* After you copy the file, and before you deploy it, you must make the */ +/* following changes: */ +/* * For variable-size function arguments, change the example sizes to */ +/* the sizes that your application requires. */ +/* * Change the example values of function arguments to the values that */ +/* your application requires. */ +/* * If the entry-point functions return values, store these values or */ +/* otherwise use them as required by your application. */ +/* */ +/*************************************************************************/ +#ifndef MAIN_H +#define MAIN_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +extern int32_T main(int32_T argc, char **argv); +extern void main_reflectivityCalculation(); + +#endif + +// End of code generation (main.h) diff --git a/RAT/exp.cpp b/RAT/exp.cpp new file mode 100644 index 00000000..10d2c128 --- /dev/null +++ b/RAT/exp.cpp @@ -0,0 +1,41 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// exp.cpp +// +// Code generation for function 'exp' +// + +// Include files +#include "exp.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_exp(creal_T *x) + { + if (x->im == 0.0) { + x->re = std::exp(x->re); + x->im = 0.0; + } else if (std::isinf(x->im) && std::isinf(x->re) && (x->re < 0.0)) { + x->re = 0.0; + x->im = 0.0; + } else { + real_T d; + real_T r; + r = std::exp(x->re / 2.0); + d = x->im; + x->re = r * (r * std::cos(x->im)); + x->im = r * (r * std::sin(d)); + } + } + } +} + +// End of code generation (exp.cpp) diff --git a/RAT/exp.h b/RAT/exp.h new file mode 100644 index 00000000..ed2149c9 --- /dev/null +++ b/RAT/exp.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// exp.h +// +// Code generation for function 'exp' +// +#ifndef EXP_H +#define EXP_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_exp(creal_T *x); + } +} + +#endif + +// End of code generation (exp.h) diff --git a/RAT/find.cpp b/RAT/find.cpp new file mode 100644 index 00000000..0498c26f --- /dev/null +++ b/RAT/find.cpp @@ -0,0 +1,62 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// find.cpp +// +// Code generation for function 'find' +// + +// Include files +#include "find.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void eml_find(const ::coder::array &x, ::coder::array &i) + { + int32_T idx; + int32_T ii; + int32_T nx; + boolean_T exitg1; + nx = x.size(0); + idx = 0; + i.set_size(x.size(0)); + ii = 0; + exitg1 = false; + while ((!exitg1) && (ii <= nx - 1)) { + if (x[ii]) { + idx++; + i[idx - 1] = ii + 1; + if (idx >= nx) { + exitg1 = true; + } else { + ii++; + } + } else { + ii++; + } + } + + if (x.size(0) == 1) { + if (idx == 0) { + i.set_size(0); + } + } else { + if (idx < 1) { + idx = 0; + } + + i.set_size(idx); + } + } + } +} + +// End of code generation (find.cpp) diff --git a/RAT/find.h b/RAT/find.h new file mode 100644 index 00000000..d6c079e5 --- /dev/null +++ b/RAT/find.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// find.h +// +// Code generation for function 'find' +// +#ifndef FIND_H +#define FIND_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void eml_find(const ::coder::array &x, ::coder::array &i); + } +} + +#endif + +// End of code generation (find.h) diff --git a/RAT/flip.cpp b/RAT/flip.cpp new file mode 100644 index 00000000..9041449a --- /dev/null +++ b/RAT/flip.cpp @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// flip.cpp +// +// Code generation for function 'flip' +// + +// Include files +#include "flip.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void flip(::coder::array &x) + { + if (x.size(0) > 1) { + int32_T i; + i = x.size(0) >> 1; + for (int32_T k{0}; k < i; k++) { + real_T tmp; + int16_T i1; + i1 = static_cast(x.size(0) - k); + tmp = x[k]; + x[k] = x[i1 - 1]; + x[i1 - 1] = tmp; + } + } + } + } +} + +// End of code generation (flip.cpp) diff --git a/RAT/flip.h b/RAT/flip.h new file mode 100644 index 00000000..a5197d80 --- /dev/null +++ b/RAT/flip.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// flip.h +// +// Code generation for function 'flip' +// +#ifndef FLIP_H +#define FLIP_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void flip(::coder::array &x); + } +} + +#endif + +// End of code generation (flip.h) diff --git a/RAT/getenv.cpp b/RAT/getenv.cpp new file mode 100644 index 00000000..5f80679b --- /dev/null +++ b/RAT/getenv.cpp @@ -0,0 +1,41 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// getenv.cpp +// +// Code generation for function 'getenv' +// + +// Include files +#include "getenv.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include +#include +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_getenv(::coder::array &value) + { + char *rawValue; + rawValue = getenv("RAT_PATH"); + if (rawValue == NULL) { + value.set_size(1, 0); + } else { + size_t length; + length = strlen(rawValue); + value.set_size(1, (int32_T)length); + memcpy((void *)&value[0], (void *)rawValue, (size_t)(int32_T)length * + sizeof(char)); + } + } + } +} + +// End of code generation (getenv.cpp) diff --git a/RAT/getenv.h b/RAT/getenv.h new file mode 100644 index 00000000..35a61aaa --- /dev/null +++ b/RAT/getenv.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// getenv.h +// +// Code generation for function 'getenv' +// +#ifndef GETENV_H +#define GETENV_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_getenv(::coder::array &value); + } +} + +#endif + +// End of code generation (getenv.h) diff --git a/RAT/groupLayersMod.cpp b/RAT/groupLayersMod.cpp new file mode 100644 index 00000000..3a8ce628 --- /dev/null +++ b/RAT/groupLayersMod.cpp @@ -0,0 +1,183 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// groupLayersMod.cpp +// +// Code generation for function 'groupLayersMod' +// + +// Include files +#include "groupLayersMod.h" +#include "rt_nonfinite.h" +#include "strcmp.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void groupLayersMod(const ::coder::array &allLayers, real_T + allRoughs, const char_T geometry_data[], const int32_T + geometry_size[2], real_T nbair, real_T nbsubs, ::coder:: + array &outLayers, real_T *outSsubs) + { + ::coder::array layers; + ::coder::array roughs; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + uint32_T unnamed_idx_0; + + // Arrange layers according to geometry and apply any coverage correction. + // + // USAGE:: + // + // [outLayers, outSsubs] = groupLayersMod(allLayers,allRoughs,numberOfContrasts,geometry,nbairs,nbsubs) + // + // INPUTS: + // + // * allLayers = cell array, one for each contrast. Each cell is the list of layer values for each contrast. + // * allRoughs = Double of substrate roughness for each contrast. + // * numberOfContrasts = double. + // * geometry = 'Air / Liquid (or solid)' or 'Solid / Liquid' + // * nbairs = vector of nbair values. + // * nbsubs = vector of nbsub values. + // + // The paratt calculation procedds through the + // z,rho,rough stack, and the parameter 'ssub' in + // callParatt is the final roughness encountered. + // + // * For air liquid 'ssub' is therefore the substrate roughness. + // + // * For solid liquid, the substrate roughness is the first roughness encountered, and 'ssub' is then the roughness of the outermost layer + // + // Outputs: + // + // * outLayers = cell array of layers param values for each contrast. + // + // * outSsubs = vector of substrate roughness values. + // + // outLayers = cell(1,numberOfContrasts); + // outSsubs = zeros(1,numberOfContrasts); + // for i = 1:numberOfContrasts + *outSsubs = allRoughs; + unnamed_idx_0 = static_cast(allLayers.size(0)); + layers.set_size(allLayers.size(0), allLayers.size(1)); + loop_ub = allLayers.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = static_cast(unnamed_idx_0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + layers[i1 + layers.size(0) * i] = 0.0; + } + } + + if ((allLayers.size(0) != 0) && (allLayers.size(1) != 0)) { + if (coder::internal::i_strcmp(geometry_data, geometry_size)) { + layers.set_size(allLayers.size(0), allLayers.size(1)); + loop_ub = allLayers.size(1); + b_loop_ub = allLayers.size(0); + for (i = 0; i < loop_ub; i++) { + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + layers[i1 + layers.size(0) * i] = allLayers[i1 + allLayers.size(0) * + i]; + } + } + + // s_sub = rsub; + } else { + *outSsubs = allLayers[(allLayers.size(0) + allLayers.size(0) * 2) - 1]; + if (allLayers.size(0) > 1) { + roughs.set_size(allLayers.size(0)); + roughs[0] = allRoughs; + loop_ub = allLayers.size(0); + for (i = 0; i <= loop_ub - 2; i++) { + roughs[i + 1] = allLayers[i + allLayers.size(0) * 2]; + } + } else { + roughs.set_size(1); + roughs[0] = allRoughs; + } + + if (allLayers.size(1) == 5) { + layers.set_size(allLayers.size(0), 4); + loop_ub = allLayers.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i] = allLayers[i]; + } + + loop_ub = allLayers.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i + layers.size(0)] = allLayers[i + allLayers.size(0)]; + } + + loop_ub = roughs.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i + layers.size(0) * 2] = roughs[i]; + } + + loop_ub = allLayers.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i + layers.size(0) * 3] = allLayers[i + allLayers.size(0) * 3]; + } + } else { + layers.set_size(allLayers.size(0), 3); + loop_ub = allLayers.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i] = allLayers[i]; + } + + loop_ub = allLayers.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i + layers.size(0)] = allLayers[i + allLayers.size(0)]; + } + + loop_ub = roughs.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i + layers.size(0) * 2] = roughs[i]; + } + } + } + + // Deal with the %coverage if present + if (allLayers.size(1) == 5) { + i = allLayers.size(0); + for (int32_T j{0}; j < i; j++) { + real_T this_pcw; + this_pcw = allLayers[j + allLayers.size(0) * 3]; + if (!std::isnan(this_pcw)) { + real_T d; + if (allLayers[j + allLayers.size(0) * 4] == 1.0) { + d = nbair; + } else { + d = nbsubs; + } + + layers[j + layers.size(0)] = d * (this_pcw / 100.0) + (1.0 - + this_pcw / 100.0) * layers[j + layers.size(0)]; + } + } + } + } + + // problem.layers{i} = layers; + // problem.ssubs(i) = s_sub; + if ((layers.size(0) != 0) && (layers.size(1) != 0)) { + outLayers.set_size(layers.size(0), 3); + loop_ub = layers.size(0); + for (i = 0; i < 3; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + outLayers[i1 + outLayers.size(0) * i] = layers[i1 + layers.size(0) * i]; + } + } + } else { + outLayers.set_size(1, 3); + outLayers[0] = 0.0; + outLayers[outLayers.size(0)] = 0.0; + outLayers[outLayers.size(0) * 2] = 0.0; + } + } +} + +// End of code generation (groupLayersMod.cpp) diff --git a/RAT/groupLayersMod.h b/RAT/groupLayersMod.h new file mode 100644 index 00000000..9cb79841 --- /dev/null +++ b/RAT/groupLayersMod.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// groupLayersMod.h +// +// Code generation for function 'groupLayersMod' +// +#ifndef GROUPLAYERSMOD_H +#define GROUPLAYERSMOD_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void groupLayersMod(const ::coder::array &allLayers, real_T + allRoughs, const char_T geometry_data[], const int32_T + geometry_size[2], real_T nbair, real_T nbsubs, ::coder:: + array &outLayers, real_T *outSsubs); +} + +#endif + +// End of code generation (groupLayersMod.h) diff --git a/RAT/groupLayersModImaginary.cpp b/RAT/groupLayersModImaginary.cpp new file mode 100644 index 00000000..36b5652e --- /dev/null +++ b/RAT/groupLayersModImaginary.cpp @@ -0,0 +1,196 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// groupLayersModImaginary.cpp +// +// Code generation for function 'groupLayersModImaginary' +// + +// Include files +#include "groupLayersModImaginary.h" +#include "rt_nonfinite.h" +#include "strcmp.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void groupLayersModImaginary(const ::coder::array &allLayers, + real_T allRoughs, const char_T geometry_data[], const int32_T geometry_size + [2], real_T nbair, real_T nbsubs, ::coder::array &outLayers, + real_T *outSsubs) + { + ::coder::array layers; + ::coder::array sldss; + ::coder::array roughs; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + uint32_T unnamed_idx_0; + + // Arrange layers according to geometry and apply any coverage correction. + // + // USAGE:: + // + // [outLayers, outSsubs] = groupLayersMod(allLayers,allRoughs,numberOfContrasts,geometry,nbairs,nbsubs) + // + // INPUTS: + // + // * allLayers = cell array, one for each contrast. Each cell is the list of layer values for each contrast. + // * allRoughs = Double of substrate roughness for each contrast. + // * numberOfContrasts = double. + // * geometry = 'Air / Liquid (or solid)' or 'Solid / Liquid' + // * nbairs = vector of nbair values. + // * nbsubs = vector of nbsub values. + // + // The paratt calculation procedds through the + // z,rho,rough stack, and the parameter 'ssub' in + // callParatt is the final roughness encountered. + // + // * For air liquid 'ssub' is therefore the substrate roughness. + // + // * For solid liquid, the substrate roughness is the first roughness encountered, and 'ssub' is then the roughness of the outermost layer + // + // Outputs: + // + // * outLayers = cell array of layers param values for each contrast. + // + // * outSsubs = vector of substrate roughness values. + // + // outLayers = cell(1,numberOfContrasts); + // outSsubs = zeros(1,numberOfContrasts); + // for i = 1:numberOfContrasts + *outSsubs = allRoughs; + unnamed_idx_0 = static_cast(allLayers.size(0)); + layers.set_size(allLayers.size(0), allLayers.size(1)); + loop_ub = allLayers.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = static_cast(unnamed_idx_0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + layers[i1 + layers.size(0) * i] = 0.0; + } + } + + if ((allLayers.size(0) != 0) && (allLayers.size(1) != 0)) { + if (coder::internal::i_strcmp(geometry_data, geometry_size)) { + layers.set_size(allLayers.size(0), allLayers.size(1)); + loop_ub = allLayers.size(1); + b_loop_ub = allLayers.size(0); + for (i = 0; i < loop_ub; i++) { + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + layers[i1 + layers.size(0) * i] = allLayers[i1 + allLayers.size(0) * + i]; + } + } + + // s_sub = rsub; + } else { + sldss.set_size(allLayers.size(0), 2); + loop_ub = allLayers.size(0); + for (i = 0; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + sldss[i1 + sldss.size(0) * i] = allLayers[i1 + allLayers.size(0) * + (i + 1)]; + } + } + + *outSsubs = allLayers[(allLayers.size(0) + allLayers.size(0) * 3) - 1]; + if (allLayers.size(0) > 1) { + roughs.set_size(allLayers.size(0)); + roughs[0] = allRoughs; + loop_ub = allLayers.size(0); + for (i = 0; i <= loop_ub - 2; i++) { + roughs[i + 1] = allLayers[i + allLayers.size(0) * 3]; + } + } else { + roughs.set_size(1); + roughs[0] = allRoughs; + } + + if (allLayers.size(1) == 5) { + b_loop_ub = allLayers.size(0) << 1; + layers.set_size(allLayers.size(0), 4); + loop_ub = allLayers.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i] = allLayers[i]; + } + + for (i = 0; i < b_loop_ub; i++) { + layers[i + layers.size(0)] = sldss[i]; + } + + loop_ub = roughs.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i + layers.size(0) * 2] = roughs[i]; + } + + loop_ub = allLayers.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i + layers.size(0) * 3] = allLayers[i + allLayers.size(0) * 4]; + } + } else { + b_loop_ub = allLayers.size(0) << 1; + layers.set_size(allLayers.size(0), 3); + loop_ub = allLayers.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i] = allLayers[i]; + } + + for (i = 0; i < b_loop_ub; i++) { + layers[i + layers.size(0)] = sldss[i]; + } + + loop_ub = roughs.size(0); + for (i = 0; i < loop_ub; i++) { + layers[i + layers.size(0) * 2] = roughs[i]; + } + } + } + + // Deal with the %coverage if present + if (allLayers.size(1) == 6) { + i = allLayers.size(0); + for (int32_T j{0}; j < i; j++) { + real_T d; + d = allLayers[j + allLayers.size(0) * 4]; + if (!std::isnan(d)) { + real_T d1; + if (d == 1.0) { + d1 = nbair; + } else { + d1 = nbsubs; + } + + layers[j + layers.size(0)] = d1 * (d / 100.0) + (1.0 - d / 100.0) * + layers[j + layers.size(0)]; + + // layers(j,3) = pc_add*(this_pcw/100) + (1-(this_pcw/100))*layers(j,3); + } + } + } + } + + // problem.layers{i} = layers; + // problem.ssubs(i) = s_sub; + if ((layers.size(0) != 0) && (layers.size(1) != 0)) { + outLayers.set_size(layers.size(0), 4); + loop_ub = layers.size(0); + for (i = 0; i < 4; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + outLayers[i1 + outLayers.size(0) * i] = layers[i1 + layers.size(0) * i]; + } + } + } else { + outLayers.set_size(1, 4); + outLayers[0] = 0.0; + outLayers[outLayers.size(0)] = 0.0; + outLayers[outLayers.size(0) * 2] = 0.0; + outLayers[outLayers.size(0) * 3] = 0.0; + } + } +} + +// End of code generation (groupLayersModImaginary.cpp) diff --git a/RAT/groupLayersModImaginary.h b/RAT/groupLayersModImaginary.h new file mode 100644 index 00000000..2fc57d8b --- /dev/null +++ b/RAT/groupLayersModImaginary.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// groupLayersModImaginary.h +// +// Code generation for function 'groupLayersModImaginary' +// +#ifndef GROUPLAYERSMODIMAGINARY_H +#define GROUPLAYERSMODIMAGINARY_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void groupLayersModImaginary(const ::coder::array &allLayers, + real_T allRoughs, const char_T geometry_data[], const int32_T geometry_size + [2], real_T nbair, real_T nbsubs, ::coder::array &outLayers, + real_T *outSsubs); +} + +#endif + +// End of code generation (groupLayersModImaginary.h) diff --git a/RAT/interp1.cpp b/RAT/interp1.cpp new file mode 100644 index 00000000..93637384 --- /dev/null +++ b/RAT/interp1.cpp @@ -0,0 +1,134 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// interp1.cpp +// +// Code generation for function 'interp1' +// + +// Include files +#include "interp1.h" +#include "bsearch.h" +#include "flip.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "omp.h" +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + static void interp1Linear(const ::coder::array &y, const ::coder:: + array &xi, ::coder::array &yi, const ::coder:: + array &varargin_1); + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + static void interp1Linear(const ::coder::array &y, const ::coder:: + array &xi, ::coder::array &yi, const ::coder:: + array &varargin_1) + { + real_T maxx; + real_T minx; + real_T r; + int32_T n; + int32_T ub_loop; + minx = varargin_1[0]; + maxx = varargin_1[varargin_1.size(0) - 1]; + ub_loop = xi.size(0) - 1; + +#pragma omp parallel for \ + num_threads(omp_get_max_threads()) \ + private(n,r) + + for (int32_T k = 0; k <= ub_loop; k++) { + if (std::isnan(xi[k])) { + yi[k] = rtNaN; + } else if ((!(xi[k] > maxx)) && (!(xi[k] < minx))) { + n = internal::b_bsearch(varargin_1, xi[k]) - 1; + r = (xi[k] - varargin_1[n]) / (varargin_1[n + 1] - varargin_1[n]); + if (r == 0.0) { + yi[k] = y[n]; + } else if (r == 1.0) { + yi[k] = y[n + 1]; + } else if (y[n] == y[n + 1]) { + yi[k] = y[n]; + } else { + yi[k] = (1.0 - r) * y[n] + r * y[n + 1]; + } + } + } + } + + void interp1(const ::coder::array &varargin_1, const ::coder:: + array &varargin_2, const ::coder::array + &varargin_3, ::coder::array &Vq) + { + ::coder::array x; + ::coder::array y; + int32_T i; + int32_T k; + int32_T nx; + y.set_size(varargin_2.size(0)); + k = varargin_2.size(0); + for (i = 0; i < k; i++) { + y[i] = varargin_2[i]; + } + + x.set_size(varargin_1.size(0)); + k = varargin_1.size(0); + for (i = 0; i < k; i++) { + x[i] = varargin_1[i]; + } + + nx = varargin_1.size(0) - 1; + Vq.set_size(varargin_3.size(0)); + k = varargin_3.size(0); + for (i = 0; i < k; i++) { + Vq[i] = rtNaN; + } + + if (varargin_3.size(0) != 0) { + k = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (k <= nx) { + if (std::isnan(varargin_1[k])) { + exitg1 = 1; + } else { + k++; + } + } else { + if (varargin_1[1] < varargin_1[0]) { + i = (nx + 1) >> 1; + for (int32_T b_j1{0}; b_j1 < i; b_j1++) { + real_T xtmp; + xtmp = x[b_j1]; + k = nx - b_j1; + x[b_j1] = x[k]; + x[k] = xtmp; + } + + flip(y); + } + + interp1Linear(y, varargin_3, Vq, x); + exitg1 = 1; + } + } while (exitg1 == 0); + } + } + } +} + +// End of code generation (interp1.cpp) diff --git a/RAT/interp1.h b/RAT/interp1.h new file mode 100644 index 00000000..d9767ea6 --- /dev/null +++ b/RAT/interp1.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// interp1.h +// +// Code generation for function 'interp1' +// +#ifndef INTERP1_H +#define INTERP1_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void interp1(const ::coder::array &varargin_1, const ::coder:: + array &varargin_2, const ::coder::array + &varargin_3, ::coder::array &Vq); + } +} + +#endif + +// End of code generation (interp1.h) diff --git a/RAT/length.cpp b/RAT/length.cpp new file mode 100644 index 00000000..7167b86c --- /dev/null +++ b/RAT/length.cpp @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// length.cpp +// +// Code generation for function 'length' +// + +// Include files +#include "length.h" +#include "rt_nonfinite.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + int32_T intlength(int32_T varargin_1, int32_T varargin_2) + { + int32_T n; + if ((varargin_1 == 0) || (varargin_2 == 0)) { + n = 0; + } else if (varargin_1 >= varargin_2) { + n = varargin_1; + } else { + n = varargin_2; + } + + return n; + } + } + } +} + +// End of code generation (length.cpp) diff --git a/RAT/length.h b/RAT/length.h new file mode 100644 index 00000000..2bc62c03 --- /dev/null +++ b/RAT/length.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// length.h +// +// Code generation for function 'length' +// +#ifndef LENGTH_H +#define LENGTH_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + int32_T intlength(int32_T varargin_1, int32_T varargin_2); + } + } +} + +#endif + +// End of code generation (length.h) diff --git a/RAT/libManager.h b/RAT/libManager.h new file mode 100644 index 00000000..3c3afcb7 --- /dev/null +++ b/RAT/libManager.h @@ -0,0 +1,48 @@ +#ifndef WRAPPER_H +#define WRAPPER_H + + +#include +#include +#include +#include +#include +#include +#include "dylib.hpp" // dylib.hpp is a header file that contains the dylib class that extracts a function from dll + +class Library +{ + public: + std::string functionName; + std::string libName; + + Library(void){}; + ~Library(void){}; + + void loadInfo(std::string libName, std::string functionName) + { + this->libName = libName; + this->functionName = functionName; + }; + + // coder.ref(params),coder.ref(nba),coder.ref(nbs),numberOfContrasts,coder.ref(output),coder.ref(subrough)); + void loadRunner(double* params,double *bulk_in,double *bulk_out,int contrast,double *tempOutput,double *roughness,double *nLayers,char* libName,char* functionName) + + { + // create an instance of dylib + dylib library; + + // load the library with libName + library = dylib (libName,dylib::extension); + + // store the function pointer in func + auto func = library.get_function(functionName); + + // pass the arguments to the function + func(params, bulk_in, bulk_out, contrast, tempOutput, roughness, nLayers); + + }; +}; + +#endif + diff --git a/RAT/linspace.cpp b/RAT/linspace.cpp new file mode 100644 index 00000000..f0a2e73e --- /dev/null +++ b/RAT/linspace.cpp @@ -0,0 +1,105 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// linspace.cpp +// +// Code generation for function 'linspace' +// + +// Include files +#include "linspace.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void linspace(real_T d1, real_T d2, real_T n, ::coder::array &y) + { + if (!(n >= 0.0)) { + y.set_size(1, 0); + } else { + real_T delta1; + delta1 = std::floor(n); + y.set_size(1, static_cast(delta1)); + if (static_cast(delta1) >= 1) { + y[static_cast(delta1) - 1] = d2; + if (y.size(1) >= 2) { + y[0] = d1; + if (y.size(1) >= 3) { + if (d1 == -d2) { + int32_T i; + delta1 = d2 / (static_cast(y.size(1)) - 1.0); + i = y.size(1) - 1; + for (int32_T k{2}; k <= i; k++) { + y[k - 1] = static_cast(((k << 1) - y.size(1)) - 1) * + delta1; + } + + if ((y.size(1) & 1) == 1) { + y[y.size(1) >> 1] = 0.0; + } + } else if (((d1 < 0.0) != (d2 < 0.0)) && ((std::abs(d1) > + 8.9884656743115785E+307) || (std::abs(d2) > + 8.9884656743115785E+307))) { + real_T delta2; + int32_T i; + delta1 = d1 / (static_cast(y.size(1)) - 1.0); + delta2 = d2 / (static_cast(y.size(1)) - 1.0); + i = y.size(1); + for (int32_T k{0}; k <= i - 3; k++) { + y[k + 1] = (d1 + delta2 * (static_cast(k) + 1.0)) - + delta1 * (static_cast(k) + 1.0); + } + } else { + int32_T i; + delta1 = (d2 - d1) / (static_cast(y.size(1)) - 1.0); + i = y.size(1); + for (int32_T k{0}; k <= i - 3; k++) { + y[k + 1] = d1 + (static_cast(k) + 1.0) * delta1; + } + } + } + } + } + } + } + + void linspace(real_T d1, real_T d2, real_T y[500]) + { + y[499] = d2; + y[0] = d1; + if (d1 == -d2) { + real_T delta1; + delta1 = d2 / 499.0; + for (int32_T k{0}; k < 498; k++) { + y[k + 1] = (2.0 * (static_cast(k) + 2.0) - 501.0) * delta1; + } + } else if (((d1 < 0.0) != (d2 < 0.0)) && ((std::abs(d1) > + 8.9884656743115785E+307) || (std::abs(d2) > + 8.9884656743115785E+307))) { + real_T delta1; + real_T delta2; + delta1 = d1 / 499.0; + delta2 = d2 / 499.0; + for (int32_T k{0}; k < 498; k++) { + y[k + 1] = (d1 + delta2 * (static_cast(k) + 1.0)) - delta1 * ( + static_cast(k) + 1.0); + } + } else { + real_T delta1; + delta1 = (d2 - d1) / 499.0; + for (int32_T k{0}; k < 498; k++) { + y[k + 1] = d1 + (static_cast(k) + 1.0) * delta1; + } + } + } + } +} + +// End of code generation (linspace.cpp) diff --git a/RAT/linspace.h b/RAT/linspace.h new file mode 100644 index 00000000..3ced8174 --- /dev/null +++ b/RAT/linspace.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// linspace.h +// +// Code generation for function 'linspace' +// +#ifndef LINSPACE_H +#define LINSPACE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void linspace(real_T d1, real_T d2, real_T n, ::coder::array &y); + void linspace(real_T d1, real_T d2, real_T y[500]); + } +} + +#endif + +// End of code generation (linspace.h) diff --git a/RAT/log1p.cpp b/RAT/log1p.cpp new file mode 100644 index 00000000..89e7571c --- /dev/null +++ b/RAT/log1p.cpp @@ -0,0 +1,42 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// log1p.cpp +// +// Code generation for function 'log1p' +// + +// Include files +#include "log1p.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace scalar + { + void b_log1p(real_T *z) + { + real_T absz; + absz = std::abs(*z); + if ((absz > 4.503599627370496E+15) || (std::isinf(*z) || std::isnan(*z))) + { + (*z)++; + *z = std::log(*z); + } else if (!(absz < 2.2204460492503131E-16)) { + *z = std::log(*z + 1.0) * (*z / ((*z + 1.0) - 1.0)); + } + } + } + } + } +} + +// End of code generation (log1p.cpp) diff --git a/RAT/log1p.h b/RAT/log1p.h new file mode 100644 index 00000000..c761da5f --- /dev/null +++ b/RAT/log1p.h @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// log1p.h +// +// Code generation for function 'log1p' +// +#ifndef LOG1P_H +#define LOG1P_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace scalar + { + void b_log1p(real_T *z); + } + } + } +} + +#endif + +// End of code generation (log1p.h) diff --git a/RAT/log2.cpp b/RAT/log2.cpp new file mode 100644 index 00000000..6a12a4a1 --- /dev/null +++ b/RAT/log2.cpp @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// log2.cpp +// +// Code generation for function 'log2' +// + +// Include files +#include "log2.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_log2(real_T x, real_T *f, real_T *e) + { + int32_T eint; + if ((!std::isinf(x)) && (!std::isnan(x))) { + *f = std::frexp(x, &eint); + *e = eint; + } else { + *f = x; + *e = 0.0; + } + } + } +} + +// End of code generation (log2.cpp) diff --git a/RAT/log2.h b/RAT/log2.h new file mode 100644 index 00000000..4c2d136c --- /dev/null +++ b/RAT/log2.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// log2.h +// +// Code generation for function 'log2' +// +#ifndef LOG2_H +#define LOG2_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_log2(real_T x, real_T *f, real_T *e); + } +} + +#endif + +// End of code generation (log2.h) diff --git a/RAT/lower.cpp b/RAT/lower.cpp new file mode 100644 index 00000000..00cd66ca --- /dev/null +++ b/RAT/lower.cpp @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// lower.cpp +// +// Code generation for function 'lower' +// + +// Include files +#include "lower.h" +#include "reflectivityCalculation_data.h" +#include "rt_nonfinite.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void lower(const char_T x_data[], const int32_T x_size[2], char_T y_data[], + int32_T y_size[2]) + { + int32_T i; + y_size[0] = 1; + y_size[1] = x_size[1]; + i = x_size[1]; + for (int32_T k{0}; k < i; k++) { + y_data[k] = cv[static_cast(x_data[k]) & 127]; + } + } + } +} + +// End of code generation (lower.cpp) diff --git a/RAT/lower.h b/RAT/lower.h new file mode 100644 index 00000000..9663d0ae --- /dev/null +++ b/RAT/lower.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// lower.h +// +// Code generation for function 'lower' +// +#ifndef LOWER_H +#define LOWER_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void lower(const char_T x_data[], const int32_T x_size[2], char_T y_data[], + int32_T y_size[2]); + } +} + +#endif + +// End of code generation (lower.h) diff --git a/RAT/makeSLDProfileXY.cpp b/RAT/makeSLDProfileXY.cpp new file mode 100644 index 00000000..552e5f8a --- /dev/null +++ b/RAT/makeSLDProfileXY.cpp @@ -0,0 +1,320 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// makeSLDProfileXY.cpp +// +// Code generation for function 'makeSLDProfileXY' +// + +// Include files +#include "makeSLDProfileXY.h" +#include "asymconvstep.h" +#include "blockedSummation.h" +#include "minOrMax.h" +#include "rt_nonfinite.h" +#include "sum.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void makeSLDProfileXY(real_T nbair, real_T nbsub, real_T ssub, const ::coder:: + array &layers, real_T numberOfLayers, real_T + nrepeats, ::coder::array &out) + { + ::coder::array Lays; + ::coder::array SLD; + ::coder::array airBox; + ::coder::array r; + ::coder::array r1; + ::coder::array r2; + ::coder::array x; + ::coder::array b_SLD; + ::coder::array b_layers; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + if (numberOfLayers > 0.0) { + real_T b; + real_T lastBoxEdge; + real_T nextLayRough; + int32_T i1; + b_layers.set_size(layers.size(0)); + loop_ub = layers.size(0); + for (i = 0; i < loop_ub; i++) { + b_layers[i] = layers[i]; + } + + b = coder::sum(b_layers) * nrepeats + 150.0; + if (std::isnan(b)) { + x.set_size(1, 1); + x[0] = rtNaN; + } else if (b < 0.0) { + x.set_size(1, 0); + } else { + x.set_size(1, static_cast(b) + 1); + loop_ub = static_cast(b); + for (i = 0; i <= loop_ub; i++) { + x[i] = i; + } + } + + b = numberOfLayers * nrepeats; + Lays.set_size(x.size(1), static_cast(b + 2.0)); + loop_ub = static_cast(b + 2.0); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = x.size(1); + for (i1 = 0; i1 < b_loop_ub; i1++) { + Lays[i1 + Lays.size(0) * i] = 0.0; + } + } + + nextLayRough = layers[layers.size(0) * 2]; + asymconvstep(x, 100.0, 0.0, nextLayRough, nextLayRough, nbair, airBox); + lastBoxEdge = 50.0; + i = static_cast(nrepeats); + for (int32_T n{0}; n < i; n++) { + i1 = static_cast(numberOfLayers); + for (int32_T b_i{0}; b_i < i1; b_i++) { + real_T thisBoxCentre; + real_T thisLayThick; + thisLayThick = layers[b_i]; + if (static_cast(b_i) + 1.0 < numberOfLayers) { + nextLayRough = layers[(b_i + layers.size(0) * 2) + 1]; + + // elseif (i == numberOfLayers) && (n < nrepeats) + // nextLayRough = layers(1,3); + } else { + nextLayRough = ssub; + } + + thisBoxCentre = lastBoxEdge + thisLayThick / 2.0; + b_loop_ub = static_cast((static_cast(b_i) + 1.0) + + numberOfLayers * ((static_cast(n) + 1.0) - 1.0)) - 1; + asymconvstep(x, thisLayThick, thisBoxCentre, layers[b_i + layers.size + (0) * 2], nextLayRough, layers[b_i + layers.size(0)], r1); + loop_ub = Lays.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + Lays[i2 + Lays.size(0) * b_loop_ub] = r1[i2]; + } + + lastBoxEdge = thisBoxCentre + thisLayThick / 2.0; + + // plot(x,Lays(:,i)); + } + } + + // layers(end,3); + asymconvstep(x, (x[x.size(1) - 1] - lastBoxEdge) * 2.0, x[x.size(1) - 1], + nextLayRough, ssub, nbsub, r1); + loop_ub = Lays.size(0); + for (i = 0; i < loop_ub; i++) { + Lays[i + Lays.size(0) * (static_cast(b + 1.0) - 1)] = r1[i]; + } + + // plot(x,Lays(:,(numberOfLayers*nrepeats)+1)) + loop_ub = Lays.size(0); + for (i = 0; i < loop_ub; i++) { + Lays[i + Lays.size(0) * (static_cast(b + 2.0) - 1)] = airBox[i]; + } + + // plot(x,Lays(:,(numberOfLayers*nrepeats)+2)) + coder::blockedSummation(Lays, Lays.size(1), b_SLD); + b_loop_ub = b_SLD.size(0); + SLD.set_size(b_SLD.size(0), 1); + for (i = 0; i < b_loop_ub; i++) { + SLD[i] = b_SLD[i]; + } + } else { + real_T tmp_data[101]; + real_T widths; + x.set_size(1, 101); + r.set_size(1, 101); + for (i = 0; i < 101; i++) { + x[i] = i; + tmp_data[i] = i; + r[i] = i; + } + + widths = coder::internal::maximum(tmp_data); + asymconvstep(r, widths, 0.0, ssub, ssub, nbair, r1); + r.set_size(1, 101); + for (i = 0; i < 101; i++) { + tmp_data[i] = i; + r[i] = i; + } + + asymconvstep(r, widths, coder::internal::maximum(tmp_data), ssub, ssub, + nbsub, r2); + SLD.set_size(1, r1.size(1)); + loop_ub = r1.size(1); + for (i = 0; i < loop_ub; i++) { + SLD[SLD.size(0) * i] = r1[i] + r2[i]; + } + } + + // plot(x,SLD) + b_loop_ub = SLD.size(0) * SLD.size(1); + out.set_size(x.size(1), 2); + loop_ub = x.size(1); + for (i = 0; i < loop_ub; i++) { + out[i] = x[i]; + } + + for (i = 0; i < b_loop_ub; i++) { + out[i + out.size(0)] = SLD[i]; + } + } + + void makeSLDProfileXY(real_T ssub, const ::coder::array &layers, + real_T numberOfLayers, real_T nrepeats, ::coder::array< + real_T, 2U> &out) + { + ::coder::array Lays; + ::coder::array SLD; + ::coder::array airBox; + ::coder::array r; + ::coder::array r1; + ::coder::array r2; + ::coder::array x; + ::coder::array b_SLD; + ::coder::array b_layers; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + if (numberOfLayers > 0.0) { + real_T b; + real_T lastBoxEdge; + real_T nextLayRough; + int32_T i1; + b_layers.set_size(layers.size(0)); + loop_ub = layers.size(0); + for (i = 0; i < loop_ub; i++) { + b_layers[i] = layers[i]; + } + + b = coder::sum(b_layers) * nrepeats + 150.0; + if (std::isnan(b)) { + x.set_size(1, 1); + x[0] = rtNaN; + } else if (b < 0.0) { + x.set_size(1, 0); + } else { + x.set_size(1, static_cast(b) + 1); + loop_ub = static_cast(b); + for (i = 0; i <= loop_ub; i++) { + x[i] = i; + } + } + + b = numberOfLayers * nrepeats; + Lays.set_size(x.size(1), static_cast(b + 2.0)); + loop_ub = static_cast(b + 2.0); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = x.size(1); + for (i1 = 0; i1 < b_loop_ub; i1++) { + Lays[i1 + Lays.size(0) * i] = 0.0; + } + } + + nextLayRough = layers[layers.size(0) * 2]; + asymconvstep(x, 100.0, 0.0, nextLayRough, nextLayRough, airBox); + lastBoxEdge = 50.0; + i = static_cast(nrepeats); + for (int32_T n{0}; n < i; n++) { + i1 = static_cast(numberOfLayers); + for (int32_T b_i{0}; b_i < i1; b_i++) { + real_T thisBoxCentre; + real_T thisLayThick; + thisLayThick = layers[b_i]; + if (static_cast(b_i) + 1.0 < numberOfLayers) { + nextLayRough = layers[(b_i + layers.size(0) * 2) + 1]; + + // elseif (i == numberOfLayers) && (n < nrepeats) + // nextLayRough = layers(1,3); + } else { + nextLayRough = ssub; + } + + thisBoxCentre = lastBoxEdge + thisLayThick / 2.0; + b_loop_ub = static_cast((static_cast(b_i) + 1.0) + + numberOfLayers * ((static_cast(n) + 1.0) - 1.0)) - 1; + asymconvstep(x, thisLayThick, thisBoxCentre, layers[b_i + layers.size + (0) * 2], nextLayRough, layers[b_i + layers.size(0)], r1); + loop_ub = Lays.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + Lays[i2 + Lays.size(0) * b_loop_ub] = r1[i2]; + } + + lastBoxEdge = thisBoxCentre + thisLayThick / 2.0; + + // plot(x,Lays(:,i)); + } + } + + // layers(end,3); + asymconvstep(x, (x[x.size(1) - 1] - lastBoxEdge) * 2.0, x[x.size(1) - 1], + nextLayRough, ssub, r1); + loop_ub = Lays.size(0); + for (i = 0; i < loop_ub; i++) { + Lays[i + Lays.size(0) * (static_cast(b + 1.0) - 1)] = r1[i]; + } + + // plot(x,Lays(:,(numberOfLayers*nrepeats)+1)) + loop_ub = Lays.size(0); + for (i = 0; i < loop_ub; i++) { + Lays[i + Lays.size(0) * (static_cast(b + 2.0) - 1)] = airBox[i]; + } + + // plot(x,Lays(:,(numberOfLayers*nrepeats)+2)) + coder::blockedSummation(Lays, Lays.size(1), b_SLD); + b_loop_ub = b_SLD.size(0); + SLD.set_size(b_SLD.size(0), 1); + for (i = 0; i < b_loop_ub; i++) { + SLD[i] = b_SLD[i]; + } + } else { + real_T tmp_data[101]; + real_T widths; + x.set_size(1, 101); + r.set_size(1, 101); + for (i = 0; i < 101; i++) { + x[i] = i; + tmp_data[i] = i; + r[i] = i; + } + + widths = coder::internal::maximum(tmp_data); + asymconvstep(r, widths, 0.0, ssub, ssub, r1); + r.set_size(1, 101); + for (i = 0; i < 101; i++) { + tmp_data[i] = i; + r[i] = i; + } + + asymconvstep(r, widths, coder::internal::maximum(tmp_data), ssub, ssub, r2); + SLD.set_size(1, r1.size(1)); + loop_ub = r1.size(1); + for (i = 0; i < loop_ub; i++) { + SLD[SLD.size(0) * i] = r1[i] + r2[i]; + } + } + + // plot(x,SLD) + b_loop_ub = SLD.size(0) * SLD.size(1); + out.set_size(x.size(1), 2); + loop_ub = x.size(1); + for (i = 0; i < loop_ub; i++) { + out[i] = x[i]; + } + + for (i = 0; i < b_loop_ub; i++) { + out[i + out.size(0)] = SLD[i]; + } + } +} + +// End of code generation (makeSLDProfileXY.cpp) diff --git a/RAT/makeSLDProfileXY.h b/RAT/makeSLDProfileXY.h new file mode 100644 index 00000000..226d1efe --- /dev/null +++ b/RAT/makeSLDProfileXY.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// makeSLDProfileXY.h +// +// Code generation for function 'makeSLDProfileXY' +// +#ifndef MAKESLDPROFILEXY_H +#define MAKESLDPROFILEXY_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void makeSLDProfileXY(real_T nbair, real_T nbsub, real_T ssub, const ::coder:: + array &layers, real_T numberOfLayers, real_T + nrepeats, ::coder::array &out); + void makeSLDProfileXY(real_T ssub, const ::coder::array &layers, + real_T numberOfLayers, real_T nrepeats, ::coder::array< + real_T, 2U> &out); +} + +#endif + +// End of code generation (makeSLDProfileXY.h) diff --git a/RAT/makeSLDProfiles.cpp b/RAT/makeSLDProfiles.cpp new file mode 100644 index 00000000..93a50afc --- /dev/null +++ b/RAT/makeSLDProfiles.cpp @@ -0,0 +1,49 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// makeSLDProfiles.cpp +// +// Code generation for function 'makeSLDProfiles' +// + +// Include files +#include "makeSLDProfiles.h" +#include "makeSLDProfileXY.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void makeSLDProfiles(real_T nbair, real_T nbsub, const ::coder::array &sld, real_T ssub, const real_T repeats[2], ::coder:: + array &sldProfile) + { + real_T d; + if (repeats[0] == 0.0) { + d = 1.0; + } else { + d = repeats[1]; + } + + makeSLDProfileXY(nbair, nbsub, ssub, sld, static_cast(sld.size(0)), + d, sldProfile); + } + + void makeSLDProfiles(const ::coder::array &sld, real_T ssub, const + real_T repeats[2], ::coder::array &sldProfile) + { + real_T d; + if (repeats[0] == 0.0) { + d = 1.0; + } else { + d = repeats[1]; + } + + makeSLDProfileXY(ssub, sld, static_cast(sld.size(0)), d, sldProfile); + } +} + +// End of code generation (makeSLDProfiles.cpp) diff --git a/RAT/makeSLDProfiles.h b/RAT/makeSLDProfiles.h new file mode 100644 index 00000000..a73ccffc --- /dev/null +++ b/RAT/makeSLDProfiles.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// makeSLDProfiles.h +// +// Code generation for function 'makeSLDProfiles' +// +#ifndef MAKESLDPROFILES_H +#define MAKESLDPROFILES_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void makeSLDProfiles(real_T nbair, real_T nbsub, const ::coder::array &sld, real_T ssub, const real_T repeats[2], ::coder:: + array &sldProfile); + void makeSLDProfiles(const ::coder::array &sld, real_T ssub, const + real_T repeats[2], ::coder::array &sldProfile); +} + +#endif + +// End of code generation (makeSLDProfiles.h) diff --git a/RAT/mergesort.cpp b/RAT/mergesort.cpp new file mode 100644 index 00000000..672589e8 --- /dev/null +++ b/RAT/mergesort.cpp @@ -0,0 +1,110 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mergesort.cpp +// +// Code generation for function 'mergesort' +// + +// Include files +#include "mergesort.h" +#include "rt_nonfinite.h" +#include "sortLE.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + void b_mergesort(::coder::array &idx, const ::coder::array< + real_T, 2U> &x, const int32_T dir_data[], int32_T n) + { + ::coder::array iwork; + int32_T b_i; + int32_T i; + int32_T k; + int32_T qEnd; + iwork.set_size(idx.size(0)); + i = n - 1; + for (k = 1; k <= i; k += 2) { + if (sortLE(x, dir_data, k, k + 1)) { + idx[k - 1] = k; + idx[k] = k + 1; + } else { + idx[k - 1] = k + 1; + idx[k] = k; + } + } + + if ((n & 1) != 0) { + idx[n - 1] = n; + } + + b_i = 2; + while (b_i < n) { + int32_T i2; + int32_T j; + i2 = b_i << 1; + j = 1; + for (int32_T pEnd{b_i + 1}; pEnd < n + 1; pEnd = qEnd + b_i) { + int32_T kEnd; + int32_T p; + int32_T q; + p = j; + q = pEnd; + qEnd = j + i2; + if (qEnd > n + 1) { + qEnd = n + 1; + } + + k = 0; + kEnd = qEnd - j; + while (k + 1 <= kEnd) { + int32_T i1; + i = idx[q - 1]; + i1 = idx[p - 1]; + if (sortLE(x, dir_data, i1, i)) { + iwork[k] = i1; + p++; + if (p == pEnd) { + while (q < qEnd) { + k++; + iwork[k] = idx[q - 1]; + q++; + } + } + } else { + iwork[k] = i; + q++; + if (q == qEnd) { + while (p < pEnd) { + k++; + iwork[k] = idx[p - 1]; + p++; + } + } + } + + k++; + } + + for (k = 0; k < kEnd; k++) { + idx[(j + k) - 1] = iwork[k]; + } + + j = qEnd; + } + + b_i = i2; + } + } + } + } +} + +// End of code generation (mergesort.cpp) diff --git a/RAT/mergesort.h b/RAT/mergesort.h new file mode 100644 index 00000000..320ab5e4 --- /dev/null +++ b/RAT/mergesort.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mergesort.h +// +// Code generation for function 'mergesort' +// +#ifndef MERGESORT_H +#define MERGESORT_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void b_mergesort(::coder::array &idx, const ::coder::array< + real_T, 2U> &x, const int32_T dir_data[], int32_T n); + } + } +} + +#endif + +// End of code generation (mergesort.h) diff --git a/RAT/minOrMax.cpp b/RAT/minOrMax.cpp new file mode 100644 index 00000000..252f1fc8 --- /dev/null +++ b/RAT/minOrMax.cpp @@ -0,0 +1,111 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// minOrMax.cpp +// +// Code generation for function 'minOrMax' +// + +// Include files +#include "minOrMax.h" +#include "relop.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + real_T b_maximum(const real_T x[2]) + { + real_T ex; + if ((x[0] < x[1]) || (std::isnan(x[0]) && (!std::isnan(x[1])))) { + ex = x[1]; + } else { + ex = x[0]; + } + + return ex; + } + + real_T maximum(const real_T x_data[]) + { + real_T ex; + int32_T idx; + int32_T k; + if (!std::isnan(x_data[0])) { + idx = 1; + } else { + boolean_T exitg1; + idx = 0; + k = 2; + exitg1 = false; + while ((!exitg1) && (k < 102)) { + if (!std::isnan(x_data[k - 1])) { + idx = k; + exitg1 = true; + } else { + k++; + } + } + } + + if (idx == 0) { + ex = x_data[0]; + } else { + ex = x_data[idx - 1]; + idx++; + for (k = idx; k < 102; k++) { + real_T d; + d = x_data[k - 1]; + if (ex < d) { + ex = d; + } + } + } + + return ex; + } + + void maximum(const ::coder::array &x, real_T ex[2]) + { + int32_T m; + m = x.size(0); + for (int32_T j{0}; j < 2; j++) { + ex[j] = x[x.size(0) * j]; + for (int32_T i{2}; i <= m; i++) { + real_T d; + d = x[(i + x.size(0) * j) - 1]; + if (relop(ex[j], d)) { + ex[j] = d; + } + } + } + } + + void minimum(const ::coder::array &x, real_T ex[2]) + { + int32_T m; + m = x.size(0); + for (int32_T j{0}; j < 2; j++) { + ex[j] = x[x.size(0) * j]; + for (int32_T i{2}; i <= m; i++) { + real_T d; + d = x[(i + x.size(0) * j) - 1]; + if (b_relop(ex[j], d)) { + ex[j] = d; + } + } + } + } + } + } +} + +// End of code generation (minOrMax.cpp) diff --git a/RAT/minOrMax.h b/RAT/minOrMax.h new file mode 100644 index 00000000..d6fe0317 --- /dev/null +++ b/RAT/minOrMax.h @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// minOrMax.h +// +// Code generation for function 'minOrMax' +// +#ifndef MINORMAX_H +#define MINORMAX_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + real_T b_maximum(const real_T x[2]); + real_T maximum(const real_T x_data[]); + void maximum(const ::coder::array &x, real_T ex[2]); + void minimum(const ::coder::array &x, real_T ex[2]); + } + } +} + +#endif + +// End of code generation (minOrMax.h) diff --git a/RAT/nullAssignment.cpp b/RAT/nullAssignment.cpp new file mode 100644 index 00000000..ae317642 --- /dev/null +++ b/RAT/nullAssignment.cpp @@ -0,0 +1,57 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// nullAssignment.cpp +// +// Code generation for function 'nullAssignment' +// + +// Include files +#include "nullAssignment.h" +#include "rt_nonfinite.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + void nullAssignment(real_T x_data[], int32_T x_size[2]) + { + int32_T i; + int32_T i1; + int32_T j; + int32_T nrows; + i = x_size[1]; + nrows = x_size[0]; + for (j = 0; j < i; j++) { + for (int32_T b_i{0}; b_i <= nrows - 2; b_i++) { + i1 = b_i + x_size[0] * j; + x_data[i1] = x_data[i1 + 1]; + } + } + + if (x_size[0] - 1 < 1) { + nrows = 0; + } else { + nrows = x_size[0] - 1; + } + + j = x_size[1]; + for (i = 0; i < j; i++) { + for (i1 = 0; i1 < nrows; i1++) { + x_data[i1 + nrows * i] = x_data[i1 + x_size[0] * i]; + } + } + + x_size[0] = nrows; + x_size[1] = j; + } + } + } +} + +// End of code generation (nullAssignment.cpp) diff --git a/RAT/nullAssignment.h b/RAT/nullAssignment.h new file mode 100644 index 00000000..0e49f6e7 --- /dev/null +++ b/RAT/nullAssignment.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// nullAssignment.h +// +// Code generation for function 'nullAssignment' +// +#ifndef NULLASSIGNMENT_H +#define NULLASSIGNMENT_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void nullAssignment(real_T x_data[], int32_T x_size[2]); + } + } +} + +#endif + +// End of code generation (nullAssignment.h) diff --git a/RAT/reflectivityCalculation.cpp b/RAT/reflectivityCalculation.cpp new file mode 100644 index 00000000..d30e904b --- /dev/null +++ b/RAT/reflectivityCalculation.cpp @@ -0,0 +1,503 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation.cpp +// +// Code generation for function 'reflectivityCalculation' +// + +// Include files +#include "reflectivityCalculation.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "standardTFReflectivityCalculation.h" +#include "strcmp.h" +#include "triggerEvent.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Type Definitions +namespace RAT +{ + struct cell_wrap_12 + { + ::coder::array f1; + }; +} + +// Function Declarations +namespace RAT +{ + static void cast(const cell_8 *r, cell_19 *r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 2U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 1U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 2U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 2U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_12, 1U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_12, 1U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_13, 1U> &r1); +} + +// Function Definitions +namespace RAT +{ + static void cast(const cell_8 *r, cell_19 *r1) + { + int32_T loop_ub; + r1->f1.set_size(1, r->f1.size(1)); + loop_ub = r->f1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f1[i] = r->f1[i]; + } + + cast(r->f2, r1->f2); + r1->f3.set_size(1, r->f3.size(1)); + loop_ub = r->f3.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f3[i] = r->f3[i]; + } + + cast(r->f4, r1->f4); + cast(r->f5, r1->f5); + cast(r->f6, r1->f6); + r1->f7.set_size(1, r->f7.size(1)); + loop_ub = r->f7.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f7[i] = r->f7[i]; + } + + r1->f8.set_size(1, r->f8.size(1)); + loop_ub = r->f8.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f8[i] = r->f8[i]; + } + + r1->f9.set_size(1, r->f9.size(1)); + loop_ub = r->f9.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f9[i] = r->f9[i]; + } + + r1->f10.set_size(1, r->f10.size(1)); + loop_ub = r->f10.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f10[i] = r->f10[i]; + } + + r1->f11.set_size(1, r->f11.size(1)); + loop_ub = r->f11.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f11[i] = r->f11[i]; + } + + r1->f12.set_size(1, r->f12.size(1)); + loop_ub = r->f12.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f12[i] = r->f12[i]; + } + + r1->f13.set_size(1, r->f13.size(1)); + loop_ub = r->f13.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f13[i] = r->f13[i]; + } + + r1->f14.set_size(1, r->f14.size(1)); + loop_ub = r->f14.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f14[i] = r->f14[i]; + } + + r1->f15.set_size(1, r->f15.size(1)); + loop_ub = r->f15.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f15[i] = r->f15[i]; + } + + r1->f16.set_size(1, r->f16.size(1)); + loop_ub = r->f16.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f16[i] = r->f16[i]; + } + + cast(r->f17, r1->f17); + r1->f18.set_size(1, r->f18.size(1)); + loop_ub = r->f18.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f18[i] = r->f18[i]; + } + + cast(r->f19, r1->f19); + r1->f20.set_size(1, r->f20.size(1)); + loop_ub = r->f20.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f20[i] = r->f20[i]; + } + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 2U> &r1) + { + int32_T i; + r1.set_size(1, r.size(1)); + i = r.size(1) - 1; + for (int32_T i1{0}; i1 <= i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size[1]; + r1[r1.size(0) * i1].f1.set_size(r[r.size(0) * i1].f1.size[0], r[r.size(0) * + i1].f1.size[1]); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size[0]; + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[r1[i1].f1.size(0) * i2] = r[i1].f1.data[r[i1].f1.size[0] * + i2]; + } + } + } + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size[1]; + r1[i1].f1.set_size(r[i1].f1.size[0], r[i1].f1.size[1]); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size[0]; + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[r1[i1].f1.size(0) * i2] = r[i1].f1.data[r[i1].f1.size[0] * + i2]; + } + } + } + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 2U> &r1) + { + int32_T i; + r1.set_size(1, r.size(1)); + i = r.size(1) - 1; + for (int32_T i1{0}; i1 <= i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[r1.size(0) * i1].f1.set_size(r[r.size(0) * i1].f1.size(0), r[r.size(0) * + i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_15, 2U> &r1) + { + int32_T i; + r1.set_size(1, r.size(1)); + i = r.size(1) - 1; + for (int32_T i1{0}; i1 <= i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[r1.size(0) * i1].f1.set_size(r[r.size(0) * i1].f1.size(0), r[r.size(0) * + i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[r1[i1].f1.size(0) * i2] = r[i1].f1[r[i1].f1.size(0) * i2]; + } + } + } + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_12, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(0); + r1[i1].f1.set_size(r[i1].f1.size(0), 2); + for (int32_T i2{0}; i2 < 2; i2++) { + for (int32_T i3{0}; i3 < loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_12, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_13, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + void reflectivityCalculation(const struct0_T *problemDef, const cell_8 + *problemDefCells, const struct1_T *, const struct2_T *controls, struct4_T + *problem, cell_11 *result) + { + ::coder::array Simulation; + ::coder::array reflectivity; + ::coder::array sldProfiles; + ::coder::array allLayers; + ::coder::array layerSlds; + ::coder::array shifted_data; + ::coder::array b_allLayers; + ::coder::array b_layerSlds; + ::coder::array b_shifted_data; + ::coder::array b_sldProfiles; + ::coder::array b_Simulation; + ::coder::array b_reflectivity; + cell_19 r; + int32_T i; + int32_T i1; + + // Main entry point into the reflectivity calculation for the toolbox. + // This is the main function that is called by any of the minimisers or + // analysis tools from the rest of the toolbox. + // + // *The main job of this function is to decide which type of calculation + // (i.e. 'Target function' is required, and call the relevant routines. + // The types of available target functions are:* + // + // * non polarised - The main basic target function type, for non polarised neutrons (or x-rays) with non-absorbing samples. Different model types are specified in sub functions from here. + // + // * oil water - Target function for oil-water samples + // + // * domains - Target function for samples consisting of domains which are larger than the beam lateral coherence length. + // + // * magnetic - Target function for cases for polarised neutrons with polarisation analysis. + // + // triggerEvent('message', 'Running reflectivity calculation...'); + // for compilation, we have to preallocate memory for the output arrays + // Setting these parameters in the struct defines them as doubles + problem->ssubs.set_size(1); + problem->ssubs[0] = 0.0; + problem->backgrounds.set_size(1); + problem->backgrounds[0] = 0.0; + problem->qshifts.set_size(1); + problem->qshifts[0] = 0.0; + problem->scalefactors.set_size(1); + problem->scalefactors[0] = 0.0; + problem->nbairs.set_size(1); + problem->nbairs[0] = 0.0; + problem->nbsubs.set_size(1); + problem->nbsubs[0] = 0.0; + problem->resolutions.set_size(1); + problem->resolutions[0] = 0.0; + problem->calculations.all_chis.set_size(1); + problem->calculations.all_chis[0] = 0.0; + problem->calculations.sum_chi = 0.0; + problem->allSubRough.set_size(1); + problem->allSubRough[0] = 0.0; + problem->resample.set_size(1, 1); + problem->resample[0] = 0.0; + + // We also foll the results arrays to define their + // type and size. (NOTE: at the moment we have a 'coder.varsize' + // pre-processor directives for the compiler here and at the + // end for the results block. We are unlikely to need both + // TODO: Find out which is necessary and tidy this up. + i = static_cast(problemDef->numberOfContrasts); + reflectivity.set_size(i); + Simulation.set_size(i); + shifted_data.set_size(i); + layerSlds.set_size(i); + sldProfiles.set_size(i); + allLayers.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + reflectivity[b_i].f1.set_size(2, 2); + reflectivity[b_i].f1[0] = 1.0; + reflectivity[b_i].f1[1] = 1.0; + reflectivity[b_i].f1[reflectivity[b_i].f1.size(0)] = 1.0; + reflectivity[b_i].f1[reflectivity[b_i].f1.size(0) + 1] = 1.0; + Simulation[b_i].f1.set_size(2, 2); + Simulation[b_i].f1[0] = 1.0; + Simulation[b_i].f1[1] = 1.0; + Simulation[b_i].f1[Simulation[b_i].f1.size(0)] = 1.0; + Simulation[b_i].f1[Simulation[b_i].f1.size(0) + 1] = 1.0; + shifted_data[b_i].f1.set_size(2, 3); + layerSlds[b_i].f1.set_size(2, 3); + sldProfiles[b_i].f1.set_size(2, 2); + sldProfiles[b_i].f1[0] = 1.0; + sldProfiles[b_i].f1[1] = 1.0; + sldProfiles[b_i].f1[sldProfiles[b_i].f1.size(0)] = 1.0; + sldProfiles[b_i].f1[sldProfiles[b_i].f1.size(0) + 1] = 1.0; + allLayers[b_i].f1.set_size(2, 3); + for (i1 = 0; i1 < 3; i1++) { + shifted_data[b_i].f1[shifted_data[b_i].f1.size(0) * i1] = 1.0; + shifted_data[b_i].f1[shifted_data[b_i].f1.size(0) * i1 + 1] = 1.0; + layerSlds[b_i].f1[layerSlds[b_i].f1.size(0) * i1] = 1.0; + layerSlds[b_i].f1[layerSlds[b_i].f1.size(0) * i1 + 1] = 1.0; + allLayers[b_i].f1[allLayers[b_i].f1.size(0) * i1] = 1.0; + allLayers[b_i].f1[allLayers[b_i].f1.size(0) * i1 + 1] = 1.0; + } + } + + // Decide which target function we are calling and call the relevant routines + if (coder::internal::b_strcmp(problemDef->TF.data, problemDef->TF.size)) { + i1 = 0; + } else { + i1 = -1; + } + + if (i1 == 0) { + cast(problemDefCells, &r); + standardTFReflectivityCalculation(problemDef, &r, controls, problem, + b_reflectivity, b_Simulation, b_shifted_data, b_layerSlds, b_sldProfiles, + b_allLayers); + cast(b_reflectivity, reflectivity); + cast(b_Simulation, Simulation); + cast(b_shifted_data, shifted_data); + cast(b_layerSlds, layerSlds); + cast(b_sldProfiles, sldProfiles); + cast(b_allLayers, allLayers); + + // case 'oil water' + // problem = oilWaterTF_reflectivityCalculation(problemDef,problemDefCells,controls); + // case 'magnetic' + // problem = polarisedTF_reflectivityCalculation(problemDef,problemDefCells,controls); + // case 'domains' + // [problem,reflectivity,Simulation,shifted_data,layerSlds,sldProfiles,allLayers] = domainsTF_reflectivityCalculation(problemDef,problemDefCells,problemDefLimits,controls); + // otherwise + // error('The calculation type "%s" is not supported', whichTF); + } + + result->f1.set_size(i); + result->f2.set_size(i); + result->f3.set_size(i); + result->f4.set_size(i); + result->f5.set_size(i); + result->f6.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + int32_T b_loop_ub; + int32_T loop_ub; + loop_ub = reflectivity[b_i].f1.size(0); + result->f1[b_i].f1.set_size(reflectivity[b_i].f1.size(0), 2); + b_loop_ub = Simulation[b_i].f1.size(0); + result->f2[b_i].f1.set_size(Simulation[b_i].f1.size(0), 2); + for (i1 = 0; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + result->f1[b_i].f1[i2 + result->f1[b_i].f1.size(0) * i1] = + reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1]; + } + + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + result->f2[b_i].f1[i2 + result->f2[b_i].f1.size(0) * i1] = + Simulation[b_i].f1[i2 + Simulation[b_i].f1.size(0) * i1]; + } + } + + loop_ub = shifted_data[b_i].f1.size(0); + result->f3[b_i].f1.set_size(shifted_data[b_i].f1.size(0), 3); + b_loop_ub = layerSlds[b_i].f1.size(0); + result->f4[b_i].f1.set_size(layerSlds[b_i].f1.size(0), 3); + for (i1 = 0; i1 < 3; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + result->f3[b_i].f1[i2 + result->f3[b_i].f1.size(0) * i1] = + shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1]; + } + + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + result->f4[b_i].f1[i2 + result->f4[b_i].f1.size(0) * i1] = + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1]; + } + } + + loop_ub = sldProfiles[b_i].f1.size(0); + result->f5[b_i].f1.set_size(sldProfiles[b_i].f1.size(0), 2); + for (i1 = 0; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + result->f5[b_i].f1[i2 + result->f5[b_i].f1.size(0) * i1] = + sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1]; + } + } + + loop_ub = allLayers[b_i].f1.size(0); + result->f6[b_i].f1.set_size(allLayers[b_i].f1.size(0), 3); + for (i1 = 0; i1 < 3; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + result->f6[b_i].f1[i2 + result->f6[b_i].f1.size(0) * i1] = + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1]; + } + } + } + + // Send plot event + triggerEvent(result->f1, result->f3, result->f5, result->f6, problem->ssubs, + problemDef->resample, problemDef->dataPresent, + problemDef->modelType.data, problemDef->modelType.size); + + // Pre-processor directives for Matlab Coder + // to define the size of the output array + // Result coder definitions.... + // Reflectivity + // Simulatin + // Shifted data + // Layers slds + // Sld profiles + // All layers (resampled) + } +} + +// End of code generation (reflectivityCalculation.cpp) diff --git a/RAT/reflectivityCalculation.h b/RAT/reflectivityCalculation.h new file mode 100644 index 00000000..f18bc96f --- /dev/null +++ b/RAT/reflectivityCalculation.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation.h +// +// Code generation for function 'reflectivityCalculation' +// +#ifndef REFLECTIVITYCALCULATION_H +#define REFLECTIVITYCALCULATION_H + +// Include files +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + extern void reflectivityCalculation(const struct0_T *problemDef, const cell_8 * + problemDefCells, const struct1_T *problemDefLimits, const struct2_T + *controls, struct4_T *problem, cell_11 *result); +} + +#endif + +// End of code generation (reflectivityCalculation.h) diff --git a/RAT/reflectivityCalculation_data.cpp b/RAT/reflectivityCalculation_data.cpp new file mode 100644 index 00000000..7c7a3b9e --- /dev/null +++ b/RAT/reflectivityCalculation_data.cpp @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation_data.cpp +// +// Code generation for function 'reflectivityCalculation_data' +// + +// Include files +#include "reflectivityCalculation_data.h" +#include "rt_nonfinite.h" + +// Variable Definitions +namespace RAT +{ + omp_nest_lock_t reflectivityCalculation_nestLockGlobal; + const char_T cv[128]{ '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', + '\x07', '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f', + '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', + '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', ' ', '!', '\"', '#', + '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', + '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', + 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', + 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\\', ']', '^', '_', + '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', + '~', '\x7f' }; +} + +// End of code generation (reflectivityCalculation_data.cpp) diff --git a/RAT/reflectivityCalculation_data.h b/RAT/reflectivityCalculation_data.h new file mode 100644 index 00000000..3866071f --- /dev/null +++ b/RAT/reflectivityCalculation_data.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation_data.h +// +// Code generation for function 'reflectivityCalculation_data' +// +#ifndef REFLECTIVITYCALCULATION_DATA_H +#define REFLECTIVITYCALCULATION_DATA_H + +// Include files +#include "rtwtypes.h" +#include "omp.h" +#include +#include + +// Variable Declarations +namespace RAT +{ + extern omp_nest_lock_t reflectivityCalculation_nestLockGlobal; + extern const char_T cv[128]; +} + +#endif + +// End of code generation (reflectivityCalculation_data.h) diff --git a/RAT/reflectivityCalculation_initialize.cpp b/RAT/reflectivityCalculation_initialize.cpp new file mode 100644 index 00000000..60d0d597 --- /dev/null +++ b/RAT/reflectivityCalculation_initialize.cpp @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation_initialize.cpp +// +// Code generation for function 'reflectivityCalculation_initialize' +// + +// Include files +#include "reflectivityCalculation_initialize.h" +#include "reflectivityCalculation_data.h" +#include "rt_nonfinite.h" +#include "triggerEvent.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + void reflectivityCalculation_initialize() + { + omp_init_nest_lock(&reflectivityCalculation_nestLockGlobal); + helper_not_empty_init(); + triggerEvent_init(); + } +} + +// End of code generation (reflectivityCalculation_initialize.cpp) diff --git a/RAT/reflectivityCalculation_initialize.h b/RAT/reflectivityCalculation_initialize.h new file mode 100644 index 00000000..500e9df2 --- /dev/null +++ b/RAT/reflectivityCalculation_initialize.h @@ -0,0 +1,26 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation_initialize.h +// +// Code generation for function 'reflectivityCalculation_initialize' +// +#ifndef REFLECTIVITYCALCULATION_INITIALIZE_H +#define REFLECTIVITYCALCULATION_INITIALIZE_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + extern void reflectivityCalculation_initialize(); +} + +#endif + +// End of code generation (reflectivityCalculation_initialize.h) diff --git a/RAT/reflectivityCalculation_internal_types.h b/RAT/reflectivityCalculation_internal_types.h new file mode 100644 index 00000000..df95bd78 --- /dev/null +++ b/RAT/reflectivityCalculation_internal_types.h @@ -0,0 +1,64 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation_internal_types.h +// +// Code generation for function 'reflectivityCalculation' +// +#ifndef REFLECTIVITYCALCULATION_INTERNAL_TYPES_H +#define REFLECTIVITYCALCULATION_INTERNAL_TYPES_H + +// Include files +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Type Definitions +namespace RAT +{ + struct cell_wrap_15 + { + ::coder::array f1; + }; + + struct cell_19 + { + ::coder::array f1; + ::coder::array f2; + ::coder::array f3; + ::coder::array f4; + ::coder::array f5; + ::coder::array f6; + ::coder::array f7; + ::coder::array f8; + ::coder::array f9; + ::coder::array f10; + ::coder::array f11; + ::coder::array f12; + ::coder::array f13; + ::coder::array f14; + ::coder::array f15; + ::coder::array f16; + ::coder::array f17; + ::coder::array f18; + ::coder::array f19; + ::coder::array f20; + }; + + struct cell_wrap_20 + { + ::coder::bounded_array f1; + }; + + struct cell_24 + { + ::coder::array f1; + }; +} + +#endif + +// End of code generation (reflectivityCalculation_internal_types.h) diff --git a/RAT/reflectivityCalculation_rtwutil.cpp b/RAT/reflectivityCalculation_rtwutil.cpp new file mode 100644 index 00000000..800d352d --- /dev/null +++ b/RAT/reflectivityCalculation_rtwutil.cpp @@ -0,0 +1,42 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation_rtwutil.cpp +// +// Code generation for function 'reflectivityCalculation_rtwutil' +// + +// Include files +#include "reflectivityCalculation_rtwutil.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + real_T rt_hypotd_snf(real_T u0, real_T u1) + { + real_T a; + real_T b; + real_T y; + a = std::abs(u0); + b = std::abs(u1); + if (a < b) { + a /= b; + y = b * std::sqrt(a * a + 1.0); + } else if (a > b) { + b /= a; + y = a * std::sqrt(b * b + 1.0); + } else if (std::isnan(b)) { + y = rtNaN; + } else { + y = a * 1.4142135623730951; + } + + return y; + } +} + +// End of code generation (reflectivityCalculation_rtwutil.cpp) diff --git a/RAT/reflectivityCalculation_rtwutil.h b/RAT/reflectivityCalculation_rtwutil.h new file mode 100644 index 00000000..a9aedba0 --- /dev/null +++ b/RAT/reflectivityCalculation_rtwutil.h @@ -0,0 +1,26 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation_rtwutil.h +// +// Code generation for function 'reflectivityCalculation_rtwutil' +// +#ifndef REFLECTIVITYCALCULATION_RTWUTIL_H +#define REFLECTIVITYCALCULATION_RTWUTIL_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + extern real_T rt_hypotd_snf(real_T u0, real_T u1); +} + +#endif + +// End of code generation (reflectivityCalculation_rtwutil.h) diff --git a/RAT/reflectivityCalculation_terminate.cpp b/RAT/reflectivityCalculation_terminate.cpp new file mode 100644 index 00000000..11f8c636 --- /dev/null +++ b/RAT/reflectivityCalculation_terminate.cpp @@ -0,0 +1,26 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation_terminate.cpp +// +// Code generation for function 'reflectivityCalculation_terminate' +// + +// Include files +#include "reflectivityCalculation_terminate.h" +#include "reflectivityCalculation_data.h" +#include "rt_nonfinite.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + void reflectivityCalculation_terminate() + { + omp_destroy_nest_lock(&reflectivityCalculation_nestLockGlobal); + } +} + +// End of code generation (reflectivityCalculation_terminate.cpp) diff --git a/RAT/reflectivityCalculation_terminate.h b/RAT/reflectivityCalculation_terminate.h new file mode 100644 index 00000000..7f574928 --- /dev/null +++ b/RAT/reflectivityCalculation_terminate.h @@ -0,0 +1,26 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation_terminate.h +// +// Code generation for function 'reflectivityCalculation_terminate' +// +#ifndef REFLECTIVITYCALCULATION_TERMINATE_H +#define REFLECTIVITYCALCULATION_TERMINATE_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + extern void reflectivityCalculation_terminate(); +} + +#endif + +// End of code generation (reflectivityCalculation_terminate.h) diff --git a/RAT/reflectivityCalculation_types.h b/RAT/reflectivityCalculation_types.h new file mode 100644 index 00000000..e75b6034 --- /dev/null +++ b/RAT/reflectivityCalculation_types.h @@ -0,0 +1,220 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation_types.h +// +// Code generation for function 'reflectivityCalculation' +// +#ifndef REFLECTIVITYCALCULATION_TYPES_H +#define REFLECTIVITYCALCULATION_TYPES_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#define MAX_THREADS omp_get_max_threads() + +// Type Definitions +namespace RAT +{ + struct cell_wrap_0 + { + real_T f1[2]; + }; + + struct struct0_T + { + ::coder::array contrastBacks; + ::coder::array contrastBacksType; + ::coder::bounded_array TF; + ::coder::array resample; + ::coder::array dataPresent; + ::coder::array oilChiDataPresent; + real_T numberOfContrasts; + ::coder::bounded_array geometry; + boolean_T useImaginary; + ::coder::array contrastShifts; + ::coder::array contrastScales; + ::coder::array contrastNbas; + ::coder::array contrastNbss; + ::coder::array contrastRes; + ::coder::array backs; + ::coder::array shifts; + ::coder::array sf; + ::coder::array nba; + ::coder::array nbs; + ::coder::array res; + ::coder::array params; + real_T numberOfLayers; + ::coder::bounded_array modelType; + ::coder::array contrastCustomFiles; + ::coder::array contrastDomainRatios; + ::coder::array domainRatio; + real_T numberOfDomainContrasts; + ::coder::array domainContrastCustomFiles; + ::coder::array fitpars; + ::coder::array otherpars; + ::coder::array fitconstr; + ::coder::array otherconstr; + }; + + struct cell_wrap_1 + { + ::coder::array f1; + }; + + struct cell_wrap_2 + { + ::coder::bounded_array f1; + }; + + struct cell_wrap_3 + { + ::coder::array f1; + }; + + struct cell_wrap_4 + { + ::coder::bounded_array f1; + }; + + struct cell_wrap_5 + { + ::coder::bounded_array f1; + }; + + struct cell_wrap_6 + { + ::coder::bounded_array f1; + }; + + struct cell_wrap_7 + { + cell_wrap_6 f1[3]; + }; + + struct cell_8 + { + ::coder::array f1; + ::coder::array f2; + ::coder::array f3; + ::coder::array f4; + ::coder::array f5; + ::coder::array f6; + ::coder::array f7; + ::coder::array f8; + ::coder::array f9; + ::coder::array f10; + ::coder::array f11; + ::coder::array f12; + ::coder::array f13; + ::coder::array f14; + ::coder::array f15; + ::coder::array f16; + ::coder::array f17; + ::coder::array f18; + ::coder::array f19; + ::coder::array f20; + }; + + struct struct1_T + { + ::coder::array params; + ::coder::array backs; + ::coder::array scales; + ::coder::array shifts; + ::coder::array nba; + ::coder::array nbs; + ::coder::array res; + ::coder::array domainRatio; + }; + + struct struct3_T + { + ::coder::array params_fitYesNo; + ::coder::array backs_fitYesNo; + ::coder::array shifts_fitYesNo; + ::coder::array scales_fitYesNo; + ::coder::array nbairs_fitYesNo; + ::coder::array nbsubs_fitYesNo; + ::coder::array resol_fitYesNo; + ::coder::array domainRatio_fitYesNo; + }; + + struct struct2_T + { + ::coder::bounded_array para; + ::coder::bounded_array proc; + ::coder::bounded_array display; + real_T tolX; + real_T tolFun; + real_T maxFunEvals; + real_T maxIter; + real_T populationSize; + real_T fWeight; + real_T F_CR; + real_T VTR; + real_T numGen; + real_T strategy; + real_T Nlive; + real_T nmcmc; + real_T propScale; + real_T nsTolerance; + real_T calcSld; + real_T resamPars[2]; + real_T updateFreq; + real_T updatePlotFreq; + real_T nSamples; + real_T nChains; + real_T lambda; + real_T pUnitGamma; + ::coder::bounded_array boundHandling; + struct3_T checks; + }; + + struct struct5_T + { + ::coder::array all_chis; + real_T sum_chi; + }; + + struct struct4_T + { + ::coder::array ssubs; + ::coder::array backgrounds; + ::coder::array qshifts; + ::coder::array scalefactors; + ::coder::array nbairs; + ::coder::array nbsubs; + ::coder::array resolutions; + struct5_T calculations; + ::coder::array allSubRough; + ::coder::array resample; + }; + + struct cell_wrap_9 + { + ::coder::array f1; + }; + + struct cell_wrap_13 + { + ::coder::array f1; + }; + + struct cell_11 + { + ::coder::array f1; + ::coder::array f2; + ::coder::array f3; + ::coder::array f4; + ::coder::array f5; + ::coder::array f6; + }; +} + +#endif + +// End of code generation (reflectivityCalculation_types.h) diff --git a/RAT/relop.cpp b/RAT/relop.cpp new file mode 100644 index 00000000..02eb3396 --- /dev/null +++ b/RAT/relop.cpp @@ -0,0 +1,54 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// relop.cpp +// +// Code generation for function 'relop' +// + +// Include files +#include "relop.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T b_relop(real_T a, real_T b) + { + boolean_T p; + if (std::isnan(b)) { + p = false; + } else if (std::isnan(a)) { + p = true; + } else { + p = (a > b); + } + + return p; + } + + boolean_T relop(real_T a, real_T b) + { + boolean_T p; + if (std::isnan(b)) { + p = false; + } else if (std::isnan(a)) { + p = true; + } else { + p = (a < b); + } + + return p; + } + } + } +} + +// End of code generation (relop.cpp) diff --git a/RAT/relop.h b/RAT/relop.h new file mode 100644 index 00000000..53147759 --- /dev/null +++ b/RAT/relop.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// relop.h +// +// Code generation for function 'relop' +// +#ifndef RELOP_H +#define RELOP_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T b_relop(real_T a, real_T b); + boolean_T relop(real_T a, real_T b); + } + } +} + +#endif + +// End of code generation (relop.h) diff --git a/RAT/repmat.cpp b/RAT/repmat.cpp new file mode 100644 index 00000000..0ae77f39 --- /dev/null +++ b/RAT/repmat.cpp @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// repmat.cpp +// +// Code generation for function 'repmat' +// + +// Include files +#include "repmat.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void repmat(const real_T a[2], real_T varargin_1, ::coder::array + &b) + { + b.set_size(static_cast(varargin_1), 2); + if (static_cast(varargin_1) != 0) { + int32_T i; + i = static_cast(varargin_1) - 1; + for (int32_T k{0}; k < 2; k++) { + for (int32_T t{0}; t <= i; t++) { + b[t + b.size(0) * k] = a[k]; + } + } + } + } + } +} + +// End of code generation (repmat.cpp) diff --git a/RAT/repmat.h b/RAT/repmat.h new file mode 100644 index 00000000..7806ff69 --- /dev/null +++ b/RAT/repmat.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// repmat.h +// +// Code generation for function 'repmat' +// +#ifndef REPMAT_H +#define REPMAT_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void repmat(const real_T a[2], real_T varargin_1, ::coder::array + &b); + } +} + +#endif + +// End of code generation (repmat.h) diff --git a/RAT/resampleLayers.cpp b/RAT/resampleLayers.cpp new file mode 100644 index 00000000..17ae4137 --- /dev/null +++ b/RAT/resampleLayers.cpp @@ -0,0 +1,69 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// resampleLayers.cpp +// +// Code generation for function 'resampleLayers' +// + +// Include files +#include "resampleLayers.h" +#include "adaptive.h" +#include "length.h" +#include "reflectivityCalculation_internal_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void resampleLayers(const ::coder::array &sldProfile, const real_T + resamPars[2], ::coder::array &newSLD) + { + cell_24 expl_temp; + real_T b_sldProfile[2]; + int32_T i; + int32_T n; + + // Function handle for adaptive resampling + // f = @(x) SLDFunction(x); + // + // Keep points and minangle as constants for now + // will fix later + b_sldProfile[0] = sldProfile[0]; + b_sldProfile[1] = sldProfile[sldProfile.size(0) - 1]; + adaptive(sldProfile, b_sldProfile, resamPars[0] * 3.1415926535897931, + resamPars[1], &expl_temp); + n = coder::internal::intlength(expl_temp.f1.size(0), 1); + newSLD.set_size(n - 1, 3); + n--; + for (i = 0; i < 3; i++) { + for (int32_T i1{0}; i1 < n; i1++) { + newSLD[i1 + newSLD.size(0) * i] = 0.0; + } + } + + // Now build a layer model from these resampled points + i = coder::internal::intlength(expl_temp.f1.size(0), 1); + for (n = 0; n <= i - 2; n++) { + real_T d; + real_T d1; + real_T thisLayRho; + d = expl_temp.f1[(n + expl_temp.f1.size(0)) + 1]; + d1 = expl_temp.f1[n + expl_temp.f1.size(0)]; + if (d > d1) { + thisLayRho = (d - d1) / 2.0 + d1; + } else { + thisLayRho = (d1 - d) / 2.0 + d; + } + + newSLD[n] = expl_temp.f1[n + 1] - expl_temp.f1[n]; + newSLD[n + newSLD.size(0)] = thisLayRho; + newSLD[n + newSLD.size(0) * 2] = 2.2204460492503131E-16; + } + } +} + +// End of code generation (resampleLayers.cpp) diff --git a/RAT/resampleLayers.h b/RAT/resampleLayers.h new file mode 100644 index 00000000..a2b0ad17 --- /dev/null +++ b/RAT/resampleLayers.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// resampleLayers.h +// +// Code generation for function 'resampleLayers' +// +#ifndef RESAMPLELAYERS_H +#define RESAMPLELAYERS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void resampleLayers(const ::coder::array &sldProfile, const real_T + resamPars[2], ::coder::array &newSLD); +} + +#endif + +// End of code generation (resampleLayers.h) diff --git a/RAT/resampleLayersReIm.cpp b/RAT/resampleLayersReIm.cpp new file mode 100644 index 00000000..389dab08 --- /dev/null +++ b/RAT/resampleLayersReIm.cpp @@ -0,0 +1,196 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// resampleLayersReIm.cpp +// +// Code generation for function 'resampleLayersReIm' +// + +// Include files +#include "resampleLayersReIm.h" +#include "adaptive.h" +#include "interp1.h" +#include "reflectivityCalculation_internal_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void resampleLayersReIm(const ::coder::array &sldProfile, const :: + coder::array &sldProfileIm, const real_T resamPars[2], ::coder:: + array &newSLD) + { + ::coder::array b_expl_temp; + ::coder::array b_sldProfileIm; + ::coder::array c_sldProfileIm; + ::coder::array newYIm; + cell_24 expl_temp; + real_T b_sldProfile[2]; + int32_T i; + int32_T loop_ub; + + // Resample the SLD profile. In this case we have an imaginary SLD also, and + // so we resample that onto the same points as the real one.. + // Function handle for adaptive resampling + // f = @(x) SLDFunction(x); + // + // Keep points and minangle as constants for now + // will fix later + // newX = linspace(xstart,xend,100); + b_sldProfile[0] = sldProfile[0]; + b_sldProfile[1] = sldProfile[sldProfile.size(0) - 1]; + adaptive(sldProfile, b_sldProfile, resamPars[0] * 3.1415926535897931, + resamPars[1], &expl_temp); + + // Now interpolate the imaginary profile so that it is on the same x points + // as the resampled real one.... + b_sldProfileIm.set_size(sldProfileIm.size(0)); + loop_ub = sldProfileIm.size(0); + for (i = 0; i < loop_ub; i++) { + b_sldProfileIm[i] = sldProfileIm[i]; + } + + c_sldProfileIm.set_size(sldProfileIm.size(0)); + loop_ub = sldProfileIm.size(0); + for (i = 0; i < loop_ub; i++) { + c_sldProfileIm[i] = sldProfileIm[i + sldProfileIm.size(0)]; + } + + b_expl_temp.set_size(expl_temp.f1.size(0)); + loop_ub = expl_temp.f1.size(0); + for (i = 0; i < loop_ub; i++) { + b_expl_temp[i] = expl_temp.f1[i]; + } + + coder::interp1(b_sldProfileIm, c_sldProfileIm, b_expl_temp, newYIm); + newSLD.set_size(expl_temp.f1.size(0) - 1, 4); + loop_ub = expl_temp.f1.size(0) - 1; + for (i = 0; i < 4; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + newSLD[i1 + newSLD.size(0) * i] = 0.0; + } + } + + // Now build a layer model from these resampled points + i = expl_temp.f1.size(0); + for (int32_T n{0}; n <= i - 2; n++) { + real_T d; + real_T d1; + real_T thisLayRho; + real_T thisLayRhoIm; + d = expl_temp.f1[(n + expl_temp.f1.size(0)) + 1]; + d1 = expl_temp.f1[n + expl_temp.f1.size(0)]; + if (d > d1) { + thisLayRho = (d - d1) / 2.0 + d1; + } else { + thisLayRho = (d1 - d) / 2.0 + d; + } + + d = newYIm[n + 1]; + if (d > newYIm[n]) { + thisLayRhoIm = (d - newYIm[n]) / 2.0 + newYIm[n]; + } else { + thisLayRhoIm = (newYIm[n] - d) / 2.0 + d; + } + + newSLD[n] = expl_temp.f1[n + 1] - expl_temp.f1[n]; + newSLD[n + newSLD.size(0)] = thisLayRho; + newSLD[n + newSLD.size(0) * 2] = thisLayRhoIm; + newSLD[n + newSLD.size(0) * 3] = 2.2204460492503131E-16; + } + } + + void resampleLayersReIm(const real_T sldProfile_data[], const int32_T + sldProfile_size[2], const real_T sldProfileIm_data[], const int32_T + sldProfileIm_size[2], const real_T resamPars[2], ::coder::array + &newSLD) + { + ::coder::array b_expl_temp; + ::coder::array d_sldProfileIm_data; + ::coder::array e_sldProfileIm_data; + ::coder::array newYIm; + cell_24 expl_temp; + real_T b_sldProfileIm_data[1000]; + real_T c_sldProfileIm_data[1000]; + real_T sldProfile[2]; + int32_T i; + int32_T loop_ub; + + // Resample the SLD profile. In this case we have an imaginary SLD also, and + // so we resample that onto the same points as the real one.. + // Function handle for adaptive resampling + // f = @(x) SLDFunction(x); + // + // Keep points and minangle as constants for now + // will fix later + // newX = linspace(xstart,xend,100); + sldProfile[0] = sldProfile_data[0]; + sldProfile[1] = sldProfile_data[sldProfile_size[0] - 1]; + adaptive(sldProfile_data, sldProfile_size, sldProfile, resamPars[0] * + 3.1415926535897931, resamPars[1], &expl_temp); + + // Now interpolate the imaginary profile so that it is on the same x points + // as the resampled real one.... + loop_ub = sldProfileIm_size[0]; + if (loop_ub - 1 >= 0) { + std::copy(&sldProfileIm_data[0], &sldProfileIm_data[loop_ub], + &b_sldProfileIm_data[0]); + } + + loop_ub = sldProfileIm_size[0]; + for (i = 0; i < loop_ub; i++) { + c_sldProfileIm_data[i] = sldProfileIm_data[i + sldProfileIm_size[0]]; + } + + b_expl_temp.set_size(expl_temp.f1.size(0)); + loop_ub = expl_temp.f1.size(0); + for (i = 0; i < loop_ub; i++) { + b_expl_temp[i] = expl_temp.f1[i]; + } + + d_sldProfileIm_data.set(&b_sldProfileIm_data[0], sldProfileIm_size[0]); + e_sldProfileIm_data.set(&c_sldProfileIm_data[0], sldProfileIm_size[0]); + coder::interp1(d_sldProfileIm_data, e_sldProfileIm_data, b_expl_temp, newYIm); + newSLD.set_size(expl_temp.f1.size(0) - 1, 4); + loop_ub = expl_temp.f1.size(0) - 1; + for (i = 0; i < 4; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + newSLD[i1 + newSLD.size(0) * i] = 0.0; + } + } + + // Now build a layer model from these resampled points + i = expl_temp.f1.size(0); + for (int32_T n{0}; n <= i - 2; n++) { + real_T d; + real_T d1; + real_T thisLayRho; + real_T thisLayRhoIm; + d = expl_temp.f1[(n + expl_temp.f1.size(0)) + 1]; + d1 = expl_temp.f1[n + expl_temp.f1.size(0)]; + if (d > d1) { + thisLayRho = (d - d1) / 2.0 + d1; + } else { + thisLayRho = (d1 - d) / 2.0 + d; + } + + d = newYIm[n + 1]; + if (d > newYIm[n]) { + thisLayRhoIm = (d - newYIm[n]) / 2.0 + newYIm[n]; + } else { + thisLayRhoIm = (newYIm[n] - d) / 2.0 + d; + } + + newSLD[n] = expl_temp.f1[n + 1] - expl_temp.f1[n]; + newSLD[n + newSLD.size(0)] = thisLayRho; + newSLD[n + newSLD.size(0) * 2] = thisLayRhoIm; + newSLD[n + newSLD.size(0) * 3] = 2.2204460492503131E-16; + } + } +} + +// End of code generation (resampleLayersReIm.cpp) diff --git a/RAT/resampleLayersReIm.h b/RAT/resampleLayersReIm.h new file mode 100644 index 00000000..6c966241 --- /dev/null +++ b/RAT/resampleLayersReIm.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// resampleLayersReIm.h +// +// Code generation for function 'resampleLayersReIm' +// +#ifndef RESAMPLELAYERSREIM_H +#define RESAMPLELAYERSREIM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void resampleLayersReIm(const ::coder::array &sldProfile, const :: + coder::array &sldProfileIm, const real_T resamPars[2], ::coder:: + array &newSLD); + void resampleLayersReIm(const real_T sldProfile_data[], const int32_T + sldProfile_size[2], const real_T sldProfileIm_data[], const int32_T + sldProfileIm_size[2], const real_T resamPars[2], ::coder::array + &newSLD); +} + +#endif + +// End of code generation (resampleLayersReIm.h) diff --git a/RAT/resolutionPolly.cpp b/RAT/resolutionPolly.cpp new file mode 100644 index 00000000..2fc6b78a --- /dev/null +++ b/RAT/resolutionPolly.cpp @@ -0,0 +1,73 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// resolutionPolly.cpp +// +// Code generation for function 'resolutionPolly' +// + +// Include files +#include "resolutionPolly.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void resolutionPolly(const ::coder::array &xdata, const ::coder:: + array &ydata, real_T res, real_T points, :: + coder::array &out) + { + int32_T i; + int32_T loop_ub_tmp; + + // Apply resolution correction + res += 0.0001; + loop_ub_tmp = static_cast(points); + out.set_size(loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { + out[i] = 0.0; + } + + for (int32_T j{0}; j < loop_ub_tmp; j++) { + real_T a; + real_T sumg; + int32_T ilow; + sumg = 0.0; + out[j] = 0.0; + if (static_cast(j) + 1U > 10U) { + ilow = -10; + } else { + ilow = static_cast(-(static_cast(j) + 1.0)) + 1; + } + + // try + if (static_cast(j) + 1.0 < points - 10.0) { + a = 10.0; + } else { + a = points - (static_cast(j) + 1.0); + } + + i = static_cast(a + (1.0 - static_cast(ilow))); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T g; + int32_T a_tmp; + a_tmp = static_cast((static_cast(j) + 1.0) + + static_cast(ilow + b_i)) - 1; + a = (xdata[a_tmp] - xdata[j]) / (res * xdata[j]); + g = std::exp(-(a * a)); + sumg += g; + out[j] = out[j] + ydata[a_tmp] * g; + } + + if (sumg != 0.0) { + out[j] = out[j] / sumg; + } + } + } +} + +// End of code generation (resolutionPolly.cpp) diff --git a/RAT/resolutionPolly.h b/RAT/resolutionPolly.h new file mode 100644 index 00000000..37354ea9 --- /dev/null +++ b/RAT/resolutionPolly.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// resolutionPolly.h +// +// Code generation for function 'resolutionPolly' +// +#ifndef RESOLUTIONPOLLY_H +#define RESOLUTIONPOLLY_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void resolutionPolly(const ::coder::array &xdata, const ::coder:: + array &ydata, real_T res, real_T points, :: + coder::array &out); +} + +#endif + +// End of code generation (resolutionPolly.h) diff --git a/RAT/rtGetInf.cpp b/RAT/rtGetInf.cpp new file mode 100644 index 00000000..475dc669 --- /dev/null +++ b/RAT/rtGetInf.cpp @@ -0,0 +1,49 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rtGetInf.cpp +// +// Code generation for function 'reflectivityCalculation' +// + +// Abstract: +// MATLAB for code generation function to initialize non-finite, Inf and MinusInf +// Include files +#include "rtGetInf.h" +#include "rt_nonfinite.h" + +// Function: rtGetInf ================================================================== +// Abstract: +// Initialize rtInf needed by the generated code. +real_T rtGetInf(void) +{ + return rtInf; +} + +// Function: rtGetInfF ================================================================= +// Abstract: +// Initialize rtInfF needed by the generated code. +real32_T rtGetInfF(void) +{ + return rtInfF; +} + +// Function: rtGetMinusInf ============================================================= +// Abstract: +// Initialize rtMinusInf needed by the generated code. +real_T rtGetMinusInf(void) +{ + return rtMinusInf; +} + +// Function: rtGetMinusInfF ============================================================ +// Abstract: +// Initialize rtMinusInfF needed by the generated code. +real32_T rtGetMinusInfF(void) +{ + return rtMinusInfF; +} + +// End of code generation (rtGetInf.cpp) diff --git a/RAT/rtGetInf.h b/RAT/rtGetInf.h new file mode 100644 index 00000000..bd5175cd --- /dev/null +++ b/RAT/rtGetInf.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rtGetInf.h +// +// Code generation for function 'reflectivityCalculation' +// +#ifndef RTGETINF_H +#define RTGETINF_H + +// Include files +#include "rtwtypes.h" +#ifdef __cplusplus + +extern "C" +{ + +#endif + + extern real_T rtGetInf(void); + extern real32_T rtGetInfF(void); + extern real_T rtGetMinusInf(void); + extern real32_T rtGetMinusInfF(void); + +#ifdef __cplusplus + +} + +#endif +#endif + +// End of code generation (rtGetInf.h) diff --git a/RAT/rtGetNaN.cpp b/RAT/rtGetNaN.cpp new file mode 100644 index 00000000..e82ce1d1 --- /dev/null +++ b/RAT/rtGetNaN.cpp @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rtGetNaN.cpp +// +// Code generation for function 'reflectivityCalculation' +// + +// Abstract: +// MATLAB for code generation function to initialize non-finite, NaN +// Include files +#include "rtGetNaN.h" +#include "rt_nonfinite.h" + +// Function: rtGetNaN ====================================================================== +// Abstract: +// Initialize rtNaN needed by the generated code. +// NaN is initialized as non-signaling. Assumes IEEE. +real_T rtGetNaN(void) +{ + return rtNaN; +} + +// Function: rtGetNaNF ===================================================================== +// Abstract: +// Initialize rtNaNF needed by the generated code. +// NaN is initialized as non-signaling. Assumes IEEE +real32_T rtGetNaNF(void) +{ + return rtNaNF; +} + +// End of code generation (rtGetNaN.cpp) diff --git a/RAT/rtGetNaN.h b/RAT/rtGetNaN.h new file mode 100644 index 00000000..828e4593 --- /dev/null +++ b/RAT/rtGetNaN.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rtGetNaN.h +// +// Code generation for function 'reflectivityCalculation' +// +#ifndef RTGETNAN_H +#define RTGETNAN_H + +// Include files +#include "rtwtypes.h" +#ifdef __cplusplus + +extern "C" +{ + +#endif + + extern real_T rtGetNaN(void); + extern real32_T rtGetNaNF(void); + +#ifdef __cplusplus + +} + +#endif +#endif + +// End of code generation (rtGetNaN.h) diff --git a/RAT/rt_defines.h b/RAT/rt_defines.h new file mode 100644 index 00000000..bbc6a3d5 --- /dev/null +++ b/RAT/rt_defines.h @@ -0,0 +1,45 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rt_defines.h +// +// Code generation for function 'reflectivityCalculation' +// +#ifndef RT_DEFINES_H +#define RT_DEFINES_H + +// Include files +#include "rtwtypes.h" +#ifdef __cplusplus + +extern "C" +{ + +#endif + + static const real_T RT_PI { 3.14159265358979323846 }; + + static const real32_T RT_PIF { 3.1415927F }; + + static const real_T RT_LN_10 { 2.30258509299404568402 }; + + static const real32_T RT_LN_10F { 2.3025851F }; + + static const real_T RT_LOG10E { 0.43429448190325182765 }; + + static const real32_T RT_LOG10EF { 0.43429449F }; + + static const real_T RT_E { 2.7182818284590452354 }; + + static const real32_T RT_EF { 2.7182817F }; + +#ifdef __cplusplus + +} + +#endif +#endif + +// End of code generation (rt_defines.h) diff --git a/RAT/rt_nonfinite.cpp b/RAT/rt_nonfinite.cpp new file mode 100644 index 00000000..8915df2c --- /dev/null +++ b/RAT/rt_nonfinite.cpp @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rt_nonfinite.cpp +// +// Code generation for function 'reflectivityCalculation' +// + +// Abstract: +// MATLAB for code generation function to initialize non-finites, +// (Inf, NaN and -Inf). +// Include files +#include "rt_nonfinite.h" +#include +#include + +real_T rtNaN { std::numeric_limits::quiet_NaN() }; + +real_T rtInf { std::numeric_limits::infinity() }; + +real_T rtMinusInf { -std::numeric_limits::infinity() }; + +real32_T rtNaNF { std::numeric_limits::quiet_NaN() }; + +real32_T rtInfF { std::numeric_limits::infinity() }; + +real32_T rtMinusInfF { -std::numeric_limits::infinity() }; + +// End of code generation (rt_nonfinite.cpp) diff --git a/RAT/rt_nonfinite.h b/RAT/rt_nonfinite.h new file mode 100644 index 00000000..712242fb --- /dev/null +++ b/RAT/rt_nonfinite.h @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rt_nonfinite.h +// +// Code generation for function 'reflectivityCalculation' +// +#ifndef RT_NONFINITE_H +#define RT_NONFINITE_H + +// Include files +#include "rtwtypes.h" +#ifdef __cplusplus + +extern "C" +{ + +#endif + + extern real_T rtInf; + extern real_T rtMinusInf; + extern real_T rtNaN; + extern real32_T rtInfF; + extern real32_T rtMinusInfF; + extern real32_T rtNaNF; + +#ifdef __cplusplus + +} + +#endif +#endif + +// End of code generation (rt_nonfinite.h) diff --git a/RAT/rtwtypes.h b/RAT/rtwtypes.h new file mode 100644 index 00000000..a71b5fd2 --- /dev/null +++ b/RAT/rtwtypes.h @@ -0,0 +1,42 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rtwtypes.h +// +// Code generation for function 'reflectivityCalculation' +// +#ifndef RTWTYPES_H +#define RTWTYPES_H + +/*=======================================================================* + * Fixed width word size data types: * + * int64_T - signed 64 bit integers * + * uint64_T - unsigned 64 bit integers * + *=======================================================================*/ +#if defined(__APPLE__) +# ifndef INT64_T +# define INT64_T long +# define FMT64 "l" +# if defined(__LP64__) && !defined(INT_TYPE_64_IS_LONG) +# define INT_TYPE_64_IS_LONG +# endif +# endif +#endif + +#if defined(__APPLE__) +# ifndef UINT64_T +# define UINT64_T unsigned long +# define FMT64 "l" +# if defined(__LP64__) && !defined(INT_TYPE_64_IS_LONG) +# define INT_TYPE_64_IS_LONG +# endif +# endif +#endif + +// Include files +#include "tmwtypes.h" +#endif + +// End of code generation (rtwtypes.h) diff --git a/RAT/shiftData.cpp b/RAT/shiftData.cpp new file mode 100644 index 00000000..d979968a --- /dev/null +++ b/RAT/shiftData.cpp @@ -0,0 +1,153 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// shiftData.cpp +// +// Code generation for function 'shiftData' +// + +// Include files +#include "shiftData.h" +#include "find.h" +#include "linspace.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +namespace py = pybind11; +// Function Definitions +namespace RAT +{ + void shiftData(real_T scalefac, real_T horshift, real_T dataPresent, ::coder:: + array &data, const real_T dataLimits[2], const + real_T simLimits_data[], ::coder::array + &shifted_data) + { + ::coder::array b_data; + ::coder::array b_i; + ::coder::array b_data_data; + ::coder::array c_data_data; + boolean_T data_data[10000]; + // Shifts the data according to scale factor. If there is no data, makes + // x-data over the simulation range. + // + // INPUTS: + // + // * scalefac = problem.scalefactors; + // * horshift = problem.qshifts; + // * numberOfContrasts = problem.numberOfContrasts; + // * dataPresent = problem.dataPresent; + // * allData = problem.data; + // * dataLimits = problem.dataLimits; + if (static_cast(dataPresent) == 1) { + int32_T data_size; + int32_T hiIndex; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T lowIndex; + if (scalefac == 0.0) { + scalefac = 1.0E-30; + } + + b_data.set_size(data.size(0)); + loop_ub = data.size(0); + for (i = 0; i < loop_ub; i++) { + b_data[i] = data[i] + horshift; + } + + loop_ub = b_data.size(0); + for (i = 0; i < loop_ub; i++) { + data[i] = b_data[i]; + } + + b_data.set_size(data.size(0)); + loop_ub = data.size(0); + for (i = 0; i < loop_ub; i++) { + b_data[i] = data[i + data.size(0)] / scalefac; + } + + loop_ub = b_data.size(0); + for (i = 0; i < loop_ub; i++) { + data[i + data.size(0)] = b_data[i]; + } + + b_data.set_size(data.size(0)); + loop_ub = data.size(0); + for (i = 0; i < loop_ub; i++) { + b_data[i] = data[i + data.size(0) * 2] / scalefac; + } + + loop_ub = b_data.size(0); + for (i = 0; i < loop_ub; i++) { + data[i + data.size(0) * 2] = b_data[i]; + } + + data_size = data.size(0); + loop_ub = data.size(0); + for (i = 0; i < loop_ub; i++) { + data_data[i] = (data[i] < dataLimits[0]); + } + + b_data_data.set(&data_data[0], data_size); + coder::eml_find(b_data_data, b_i); + if (b_i.size(0) != 0) { + lowIndex = b_i[b_i.size(0) - 1]; + } else { + lowIndex = 1; + } + + data_size = data.size(0); + loop_ub = data.size(0); + for (i = 0; i < loop_ub; i++) { + data_data[i] = (data[i] > dataLimits[1]); + } + + c_data_data.set(&data_data[0], data_size); + coder::eml_find(c_data_data, b_i); + if (b_i.size(0) != 0) { + hiIndex = b_i[0]; + } else { + hiIndex = data.size(0); + } + + if (lowIndex > hiIndex) { + i = 0; + i1 = 0; + } else { + i = lowIndex - 1; + i1 = hiIndex; + } + + loop_ub = i1 - i; + shifted_data.set_size(loop_ub, data.size(1)); + data_size = data.size(1); + for (i1 = 0; i1 < data_size; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + shifted_data[i2 + shifted_data.size(0) * i1] = data[(i + i2) + + data.size(0) * i1]; + } + } + } else { + real_T dv1[3][500]; + real_T dv[500]; + coder::linspace(simLimits_data[0], simLimits_data[1], dv); + for (int32_T i{0}; i < 500; i++) { + dv1[0][i] = dv[i]; + dv1[1][i] = 0.0; + dv1[2][i] = 0.0; + } + + shifted_data.set_size(500, 3); + for (int32_T i{0}; i < 3; i++) { + for (int32_T i1{0}; i1 < 500; i1++) { + shifted_data[i1 + shifted_data.size(0) * i] = dv1[i][i1]; + } + } + } + } +} + +// End of code generation (shiftData.cpp) diff --git a/RAT/shiftData.h b/RAT/shiftData.h new file mode 100644 index 00000000..fb4f93c5 --- /dev/null +++ b/RAT/shiftData.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// shiftData.h +// +// Code generation for function 'shiftData' +// +#ifndef SHIFTDATA_H +#define SHIFTDATA_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void shiftData(real_T scalefac, real_T horshift, real_T dataPresent, ::coder:: + array &data, const real_T dataLimits[2], const + real_T simLimits_data[], ::coder::array + &shifted_data); +} + +#endif + +// End of code generation (shiftData.h) diff --git a/RAT/sortAscendLE.cpp b/RAT/sortAscendLE.cpp new file mode 100644 index 00000000..04a6cb7c --- /dev/null +++ b/RAT/sortAscendLE.cpp @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sortAscendLE.cpp +// +// Code generation for function 'sortAscendLE' +// + +// Include files +#include "sortAscendLE.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T sortAscendLE(real_T a, real_T b) + { + boolean_T p; + if ((a <= b) || std::isnan(b)) { + p = true; + } else { + p = false; + } + + return p; + } + } + } +} + +// End of code generation (sortAscendLE.cpp) diff --git a/RAT/sortAscendLE.h b/RAT/sortAscendLE.h new file mode 100644 index 00000000..2e96f3b8 --- /dev/null +++ b/RAT/sortAscendLE.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sortAscendLE.h +// +// Code generation for function 'sortAscendLE' +// +#ifndef SORTASCENDLE_H +#define SORTASCENDLE_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T sortAscendLE(real_T a, real_T b); + } + } +} + +#endif + +// End of code generation (sortAscendLE.h) diff --git a/RAT/sortIdx.cpp b/RAT/sortIdx.cpp new file mode 100644 index 00000000..18880f58 --- /dev/null +++ b/RAT/sortIdx.cpp @@ -0,0 +1,48 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sortIdx.cpp +// +// Code generation for function 'sortIdx' +// + +// Include files +#include "sortIdx.h" +#include "mergesort.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + void sortIdx(const ::coder::array &x, const int32_T col_data[], + ::coder::array &idx) + { + int32_T k; + int32_T n; + n = x.size(0); + idx.set_size(x.size(0)); + k = x.size(0); + for (int32_T i{0}; i < k; i++) { + idx[i] = 0; + } + + if (x.size(0) == 0) { + for (k = 0; k < n; k++) { + idx[k] = k + 1; + } + } else { + b_mergesort(idx, x, col_data, x.size(0)); + } + } + } + } +} + +// End of code generation (sortIdx.cpp) diff --git a/RAT/sortIdx.h b/RAT/sortIdx.h new file mode 100644 index 00000000..07071381 --- /dev/null +++ b/RAT/sortIdx.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sortIdx.h +// +// Code generation for function 'sortIdx' +// +#ifndef SORTIDX_H +#define SORTIDX_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void sortIdx(const ::coder::array &x, const int32_T col_data[], + ::coder::array &idx); + } + } +} + +#endif + +// End of code generation (sortIdx.h) diff --git a/RAT/sortLE.cpp b/RAT/sortLE.cpp new file mode 100644 index 00000000..a861eebb --- /dev/null +++ b/RAT/sortLE.cpp @@ -0,0 +1,53 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sortLE.cpp +// +// Code generation for function 'sortLE' +// + +// Include files +#include "sortLE.h" +#include "rt_nonfinite.h" +#include "sortAscendLE.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T sortLE(const ::coder::array &v, const int32_T + dir_data[], int32_T idx1, int32_T idx2) + { + int32_T k; + boolean_T exitg1; + boolean_T p; + p = true; + k = 0; + exitg1 = false; + while ((!exitg1) && (k < 2)) { + real_T v1; + real_T v2; + v1 = v[(idx1 + v.size(0) * (dir_data[k] - 1)) - 1]; + v2 = v[(idx2 + v.size(0) * (dir_data[k] - 1)) - 1]; + if ((v1 == v2) || (std::isnan(v1) && std::isnan(v2))) { + k++; + } else { + p = sortAscendLE(v1, v2); + exitg1 = true; + } + } + + return p; + } + } + } +} + +// End of code generation (sortLE.cpp) diff --git a/RAT/sortLE.h b/RAT/sortLE.h new file mode 100644 index 00000000..a65cb4d6 --- /dev/null +++ b/RAT/sortLE.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sortLE.h +// +// Code generation for function 'sortLE' +// +#ifndef SORTLE_H +#define SORTLE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T sortLE(const ::coder::array &v, const int32_T + dir_data[], int32_T idx1, int32_T idx2); + } + } +} + +#endif + +// End of code generation (sortLE.h) diff --git a/RAT/sortrows.cpp b/RAT/sortrows.cpp new file mode 100644 index 00000000..de789474 --- /dev/null +++ b/RAT/sortrows.cpp @@ -0,0 +1,62 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sortrows.cpp +// +// Code generation for function 'sortrows' +// + +// Include files +#include "sortrows.h" +#include "rt_nonfinite.h" +#include "sortIdx.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + namespace coder + { + static void apply_row_permutation(::coder::array &y, const :: + coder::array &idx); + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + static void apply_row_permutation(::coder::array &y, const :: + coder::array &idx) + { + ::coder::array ycol; + int32_T m; + m = y.size(0) - 1; + ycol.set_size(y.size(0)); + for (int32_T j{0}; j < 2; j++) { + for (int32_T i{0}; i <= m; i++) { + ycol[i] = y[(idx[i] + y.size(0) * j) - 1]; + } + + for (int32_T i{0}; i <= m; i++) { + y[i + y.size(0) * j] = ycol[i]; + } + } + } + + void sortrows(::coder::array &y) + { + ::coder::array r; + int32_T col_data[2]; + col_data[0] = 1; + col_data[1] = 2; + internal::sortIdx(y, col_data, r); + apply_row_permutation(y, r); + } + } +} + +// End of code generation (sortrows.cpp) diff --git a/RAT/sortrows.h b/RAT/sortrows.h new file mode 100644 index 00000000..75d95ae2 --- /dev/null +++ b/RAT/sortrows.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sortrows.h +// +// Code generation for function 'sortrows' +// +#ifndef SORTROWS_H +#define SORTROWS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void sortrows(::coder::array &y); + } +} + +#endif + +// End of code generation (sortrows.h) diff --git a/RAT/sqrt.cpp b/RAT/sqrt.cpp new file mode 100644 index 00000000..e37f343d --- /dev/null +++ b/RAT/sqrt.cpp @@ -0,0 +1,104 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sqrt.cpp +// +// Code generation for function 'sqrt' +// + +// Include files +#include "sqrt.h" +#include "reflectivityCalculation_rtwutil.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace scalar + { + void b_sqrt(creal_T *x) + { + real_T absxi; + real_T absxr; + real_T xi; + real_T xr; + xr = x->re; + xi = x->im; + if (xi == 0.0) { + if (xr < 0.0) { + absxr = 0.0; + absxi = std::sqrt(-xr); + } else { + absxr = std::sqrt(xr); + absxi = 0.0; + } + } else if (xr == 0.0) { + if (xi < 0.0) { + absxr = std::sqrt(-xi / 2.0); + absxi = -absxr; + } else { + absxr = std::sqrt(xi / 2.0); + absxi = absxr; + } + } else if (std::isnan(xr)) { + absxr = rtNaN; + absxi = rtNaN; + } else if (std::isnan(xi)) { + absxr = rtNaN; + absxi = rtNaN; + } else if (std::isinf(xi)) { + absxr = std::abs(xi); + absxi = xi; + } else if (std::isinf(xr)) { + if (xr < 0.0) { + absxr = 0.0; + absxi = xi * -xr; + } else { + absxr = xr; + absxi = 0.0; + } + } else { + absxr = std::abs(xr); + absxi = std::abs(xi); + if ((absxr > 4.4942328371557893E+307) || (absxi > + 4.4942328371557893E+307)) { + absxr *= 0.5; + absxi = rt_hypotd_snf(absxr, absxi * 0.5); + if (absxi > absxr) { + absxr = std::sqrt(absxi) * std::sqrt(absxr / absxi + 1.0); + } else { + absxr = std::sqrt(absxi) * 1.4142135623730951; + } + } else { + absxr = std::sqrt((rt_hypotd_snf(absxr, absxi) + absxr) * 0.5); + } + + if (xr > 0.0) { + absxi = 0.5 * (xi / absxr); + } else { + if (xi < 0.0) { + absxi = -absxr; + } else { + absxi = absxr; + } + + absxr = 0.5 * (xi / absxi); + } + } + + x->re = absxr; + x->im = absxi; + } + } + } + } +} + +// End of code generation (sqrt.cpp) diff --git a/RAT/sqrt.h b/RAT/sqrt.h new file mode 100644 index 00000000..6348c3b6 --- /dev/null +++ b/RAT/sqrt.h @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sqrt.h +// +// Code generation for function 'sqrt' +// +#ifndef SQRT_H +#define SQRT_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace scalar + { + void b_sqrt(creal_T *x); + } + } + } +} + +#endif + +// End of code generation (sqrt.h) diff --git a/RAT/standardTFCustomLayersParallelContrasts.cpp b/RAT/standardTFCustomLayersParallelContrasts.cpp new file mode 100644 index 00000000..f636eed2 --- /dev/null +++ b/RAT/standardTFCustomLayersParallelContrasts.cpp @@ -0,0 +1,227 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomLayersParallelContrasts.cpp +// +// Code generation for function 'standardTFCustomLayersParallelContrasts' +// + +// Include files +#include "standardTFCustomLayersParallelContrasts.h" +#include "backSort.h" +#include "customModelClass.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "standardTFLayersCore.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + void standardTFCustomLayersParallelContrasts(const struct0_T *problemDef, + const cell_19 *problemDefCells, const struct2_T *controls, ::coder::array< + real_T, 1U> &outSsubs, ::coder::array &backgs, ::coder::array< + real_T, 1U> &qshifts, ::coder::array &sfs, ::coder::array &nbas, ::coder::array &nbss, ::coder::array + &resols, ::coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) + { + ::coder::array Simul; + ::coder::array layerSld; + ::coder::array reflect; + ::coder::array resamLayers; + ::coder::array shifted_dat; + ::coder::array sldProfile; + real_T dv[2]; + real_T dv1[2]; + real_T calcSld; + real_T thisBackground; + real_T thisChiSquared; + real_T thisNba; + real_T thisNbs; + real_T thisQshift; + real_T thisResol; + real_T thisSf; + real_T thisSsubs; + int32_T b_i; + int32_T b_loop_ub; + int32_T i1; + int32_T loop_ub; + int32_T nParams; + int32_T ub_loop; + boolean_T useImaginary; + + // Multi threaded version of the custom layers, standardTF reflectivity + // calculation. The function extracts the relevant parameters from the input + // arrays, allocates these on a pre-contrast basis, then calls the 'core' + // calculation (the core layers standardTf calc is shared between multiple + // calculation types). + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // The min input array 'problemDefCells' is a master array where + // all the cell arrays are grouped together. There are + // repeatLayers - controls repeating of the layers stack + // allData - Array of all the data arrays + // dataLimits - Min max limits in q for the data arrays + // simLimits - Limits in Q for the reflkectivity simulations + // Layers details - Master array of all available layers + // contrastLayers - Which specific combination of arrays are needed for + // each contrast. + // Custom files - Filenames and path for any custom files used + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + calcSld = controls->calcSld; + useImaginary = problemDef->useImaginary; + + // Pre-Allocation of output arrays... + backgs.set_size(static_cast(problemDef->numberOfContrasts)); + + // --- End Memory Allocation --- + // Resampling parameters + // Process the custom models.... + customModelClass::processCustomLayers(problemDef->contrastBacks, + problemDef->contrastShifts, problemDef->contrastScales, + problemDef->contrastNbas, problemDef->contrastNbss, + problemDef->contrastRes, problemDef->backs, problemDef->shifts, + problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, + problemDef->contrastCustomFiles, problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, problemDef->useImaginary, + allLayers, allRoughs); + + // Multi cored over all contrasts + outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); + sldProfiles.set_size(static_cast(problemDef->numberOfContrasts)); + reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); + Simulation.set_size(static_cast(problemDef->numberOfContrasts)); + shifted_data.set_size(static_cast(problemDef->numberOfContrasts)); + layerSlds.set_size(static_cast(problemDef->numberOfContrasts)); + chis.set_size(static_cast(problemDef->numberOfContrasts)); + qshifts.set_size(static_cast(problemDef->numberOfContrasts)); + sfs.set_size(static_cast(problemDef->numberOfContrasts)); + nbas.set_size(static_cast(problemDef->numberOfContrasts)); + nbss.set_size(static_cast(problemDef->numberOfContrasts)); + resols.set_size(static_cast(problemDef->numberOfContrasts)); + ub_loop = static_cast(problemDef->numberOfContrasts) - 1; + +#pragma omp parallel for \ + num_threads(omp_get_max_threads()) \ + private(sldProfile,reflect,Simul,shifted_dat,layerSld,resamLayers,thisSsubs,thisChiSquared,thisResol,thisNbs,thisNba,thisSf,thisQshift,thisBackground,dv,dv1,loop_ub,b_i,b_loop_ub,i1) + + for (int32_T i = 0; i <= ub_loop; i++) { + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBacks[i], problemDef->contrastShifts[i], + problemDef->contrastScales[i], problemDef->contrastNbas[i], + problemDef->contrastNbss[i], problemDef->contrastRes[i], + problemDef->backs, problemDef->shifts, problemDef->sf, + problemDef->nba, problemDef->nbs, problemDef->res, + &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, + &thisResol); + + // Get the custom layers output for this contrast + // For the other parameters, we extract the correct ones from the input + // arrays + // Now call the core standardTF_stanlay reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the reflectivity calculation + dv[0] = problemDefCells->f3[i].f1[0]; + dv[1] = problemDefCells->f3[i].f1[1]; + dv1[0] = problemDefCells->f1[i].f1[0]; + dv1[1] = problemDefCells->f1[i].f1[1]; + standardTFLayersCore(allLayers[i].f1, allRoughs[i], + problemDef->geometry.data, problemDef->geometry.size, + thisNba, thisNbs, problemDef->resample[i], calcSld, + thisSf, thisQshift, problemDef->dataPresent[i], + problemDefCells->f2[i].f1, dv, (const real_T *)((:: + coder::array *)&problemDefCells->f4[i].f1)->data(), dv1, + thisBackground, thisResol, + problemDef->contrastBacksType[i], static_cast + (nParams), controls->resamPars, useImaginary, + sldProfile, reflect, Simul, shifted_dat, layerSld, + resamLayers, &thisChiSquared, &thisSsubs); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + outSsubs[i] = thisSsubs; + loop_ub = sldProfile.size(1); + sldProfiles[i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = sldProfile.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + sldProfiles[i].f1[i1 + sldProfiles[i].f1.size(0) * b_i] = + sldProfile[i1 + sldProfile.size(0) * b_i]; + } + } + + loop_ub = reflect.size(0); + reflectivity[i].f1.set_size(reflect.size(0), 2); + b_loop_ub = Simul.size(0); + Simulation[i].f1.set_size(Simul.size(0), 2); + for (b_i = 0; b_i < 2; b_i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + reflectivity[i].f1[i1 + reflectivity[i].f1.size(0) * b_i] = reflect[i1 + + reflect.size(0) * b_i]; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + Simulation[i].f1[i1 + Simulation[i].f1.size(0) * b_i] = Simul[i1 + + Simul.size(0) * b_i]; + } + } + + loop_ub = shifted_dat.size(1); + shifted_data[i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = shifted_dat.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + shifted_data[i].f1[i1 + shifted_data[i].f1.size(0) * b_i] = + shifted_dat[i1 + shifted_dat.size(0) * b_i]; + } + } + + loop_ub = layerSld.size(1); + layerSlds[i].f1.set_size(layerSld.size(0), layerSld.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = layerSld.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + layerSlds[i].f1[i1 + layerSlds[i].f1.size(0) * b_i] = layerSld[i1 + + layerSld.size(0) * b_i]; + } + } + + loop_ub = resamLayers.size(1); + allLayers[i].f1.set_size(resamLayers.size(0), resamLayers.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = resamLayers.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + allLayers[i].f1[i1 + allLayers[i].f1.size(0) * b_i] = resamLayers[i1 + + resamLayers.size(0) * b_i]; + } + } + + chis[i] = thisChiSquared; + backgs[i] = thisBackground; + qshifts[i] = thisQshift; + sfs[i] = thisSf; + nbas[i] = thisNba; + nbss[i] = thisNbs; + resols[i] = thisResol; + } + } +} + +// End of code generation (standardTFCustomLayersParallelContrasts.cpp) diff --git a/RAT/standardTFCustomLayersParallelContrasts.h b/RAT/standardTFCustomLayersParallelContrasts.h new file mode 100644 index 00000000..1787781f --- /dev/null +++ b/RAT/standardTFCustomLayersParallelContrasts.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomLayersParallelContrasts.h +// +// Code generation for function 'standardTFCustomLayersParallelContrasts' +// +#ifndef STANDARDTFCUSTOMLAYERSPARALLELCONTRASTS_H +#define STANDARDTFCUSTOMLAYERSPARALLELCONTRASTS_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFCustomLayersParallelContrasts(const struct0_T *problemDef, + const cell_19 *problemDefCells, const struct2_T *controls, ::coder::array< + real_T, 1U> &outSsubs, ::coder::array &backgs, ::coder::array< + real_T, 1U> &qshifts, ::coder::array &sfs, ::coder::array &nbas, ::coder::array &nbss, ::coder::array + &resols, ::coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); +} + +#endif + +// End of code generation (standardTFCustomLayersParallelContrasts.h) diff --git a/RAT/standardTFCustomLayersParallelPoints.cpp b/RAT/standardTFCustomLayersParallelPoints.cpp new file mode 100644 index 00000000..e6ec909a --- /dev/null +++ b/RAT/standardTFCustomLayersParallelPoints.cpp @@ -0,0 +1,191 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomLayersParallelPoints.cpp +// +// Code generation for function 'standardTFCustomLayersParallelPoints' +// + +// Include files +#include "standardTFCustomLayersParallelPoints.h" +#include "backSort.h" +#include "customModelClass.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "standardTFLayersCore.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + void standardTFCustomLayersParallelPoints(const struct0_T *problemDef, const + cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) + { + ::coder::array layerSld; + ::coder::array resamLayers; + ::coder::array shifted_dat; + ::coder::array sldProfile; + real_T thisBackground; + real_T thisNba; + real_T thisNbs; + real_T thisQshift; + real_T thisResol; + real_T thisSf; + int32_T i; + + // Multi threaded version of the custom layers over reflectivity poimnts + // for standardTF reflectivity calculation. + // The function extracts the relevant parameters from the input + // arrays, allocates these on a pre-contrast basis, then calls the 'core' + // calculation (the core layers standardTf calc is shared between multiple + // calculation types). + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // The min input array 'problemDefCells' is a master array where + // all the cell arrays are grouped together. There are + // repeatLayers - controls repeating of the layers stack + // allData - Array of all the data arrays + // dataLimits - Min max limits in q for the data arrays + // simLimits - Limits in Q for the reflkectivity simulations + // Layers details - Master array of all available layers + // contrastLayers - Which specific combination of arrays are needed for + // each contrast. + // Custom files - Filenames and path for any custom files used + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + // Pre-Allocation of output arrays... + i = static_cast(problemDef->numberOfContrasts); + backgs.set_size(i); + + // --- End Memory Allocation --- + // Resampling parameters + // Process the custom models.... + customModelClass::processCustomLayers(problemDef->contrastBacks, + problemDef->contrastShifts, problemDef->contrastScales, + problemDef->contrastNbas, problemDef->contrastNbss, + problemDef->contrastRes, problemDef->backs, problemDef->shifts, + problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, + problemDef->contrastCustomFiles, problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, problemDef->useImaginary, + allLayers, allRoughs); + + // Single cored over all contrasts + outSsubs.set_size(i); + sldProfiles.set_size(i); + reflectivity.set_size(i); + Simulation.set_size(i); + shifted_data.set_size(i); + layerSlds.set_size(i); + chis.set_size(i); + qshifts.set_size(i); + sfs.set_size(i); + nbas.set_size(i); + nbss.set_size(i); + resols.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T dv[2]; + real_T dv1[2]; + int32_T b_loop_ub; + int32_T loop_ub; + + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], + problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], + problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], + problemDef->backs, problemDef->shifts, problemDef->sf, + problemDef->nba, problemDef->nbs, problemDef->res, + &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, + &thisResol); + + // Get the custom layers output for this contrast + // For the other parameters, we extract the correct ones from the input + // arrays + // Now call the core standardTF_stanlay reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the reflectivity calculation + dv[0] = problemDefCells->f3[b_i].f1[0]; + dv[1] = problemDefCells->f3[b_i].f1[1]; + dv1[0] = problemDefCells->f1[b_i].f1[0]; + dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_standardTFLayersCore(allLayers[b_i].f1, allRoughs[b_i], + problemDef->geometry.data, problemDef->geometry.size, thisNba, thisNbs, + problemDef->resample[b_i], controls->calcSld, thisSf, thisQshift, + problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, dv, (const + real_T *)((::coder::array *)&problemDefCells->f4[b_i].f1) + ->data(), dv1, thisBackground, thisResol, problemDef-> + contrastBacksType[b_i], static_cast(problemDef->params.size(1)), + controls->resamPars, problemDef->useImaginary, sldProfile, + reflectivity[b_i].f1, Simulation[b_i].f1, shifted_dat, layerSld, + resamLayers, &chis[b_i], &outSsubs[b_i]); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + loop_ub = sldProfile.size(1); + sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = sldProfile.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = + sldProfile[i2 + sldProfile.size(0) * i1]; + } + } + + loop_ub = shifted_dat.size(1); + shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shifted_dat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1] = + shifted_dat[i2 + shifted_dat.size(0) * i1]; + } + } + + loop_ub = layerSld.size(1); + layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = layerSld.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = layerSld[i2 + + layerSld.size(0) * i1]; + } + } + + loop_ub = resamLayers.size(1); + allLayers[b_i].f1.set_size(resamLayers.size(0), resamLayers.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = resamLayers.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + resamLayers[i2 + resamLayers.size(0) * i1]; + } + } + + backgs[b_i] = thisBackground; + qshifts[b_i] = thisQshift; + sfs[b_i] = thisSf; + nbas[b_i] = thisNba; + nbss[b_i] = thisNbs; + resols[b_i] = thisResol; + } + } +} + +// End of code generation (standardTFCustomLayersParallelPoints.cpp) diff --git a/RAT/standardTFCustomLayersParallelPoints.h b/RAT/standardTFCustomLayersParallelPoints.h new file mode 100644 index 00000000..7b78d985 --- /dev/null +++ b/RAT/standardTFCustomLayersParallelPoints.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomLayersParallelPoints.h +// +// Code generation for function 'standardTFCustomLayersParallelPoints' +// +#ifndef STANDARDTFCUSTOMLAYERSPARALLELPOINTS_H +#define STANDARDTFCUSTOMLAYERSPARALLELPOINTS_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFCustomLayersParallelPoints(const struct0_T *problemDef, const + cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); +} + +#endif + +// End of code generation (standardTFCustomLayersParallelPoints.h) diff --git a/RAT/standardTFCustomLayersReflectivityCalculation.cpp b/RAT/standardTFCustomLayersReflectivityCalculation.cpp new file mode 100644 index 00000000..5080ad99 --- /dev/null +++ b/RAT/standardTFCustomLayersReflectivityCalculation.cpp @@ -0,0 +1,152 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomLayersReflectivityCalculation.cpp +// +// Code generation for function 'standardTFCustomLayersReflectivityCalculation' +// + +// Include files +#include "standardTFCustomLayersReflectivityCalculation.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "standardTFCustomLayersParallelContrasts.h" +#include "standardTFCustomLayersParallelPoints.h" +#include "standardTFCustomLayersSingle.h" +#include "strcmp.h" +#include "sum.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + void standardTFCustomLayersReflectivityCalculation(const struct0_T *problemDef, + const cell_19 *problemDefCells, const struct2_T *controls, struct4_T + *problem, ::coder::array &reflectivity, ::coder::array< + cell_wrap_9, 1U> &Simulation, ::coder::array &shifted_data, + ::coder::array &layerSlds, ::coder::array + &sldProfiles, ::coder::array &allLayers) + { + int32_T loop_ub_tmp; + + // Custom layers reflectivity calculation for standardTF + // This function decides on parallelisation options before calling the + // relevant version of the main custom layers calculation. It is more + // efficient to have multiple versions of the core calculation, each dealing + // with a different scheme for parallelisation. These are: + // single - single threaded teflectivity calculation + // points - parallelise over points in the reflectivity calculation + // contrasts - parallelise over contrasts. + // Pre-allocation - It's necessary to + // pre-allocate the memory for all the arrays + // for compilation, so do this in this block. + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgrounds.set_size(loop_ub_tmp); + problem->qshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->nbairs.set_size(loop_ub_tmp); + problem->nbsubs.set_size(loop_ub_tmp); + problem->calculations.all_chis.set_size(loop_ub_tmp); + problem->resolutions.set_size(loop_ub_tmp); + problem->allSubRough.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + Simulation.set_size(loop_ub_tmp); + shifted_data.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + sldProfiles.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgrounds[i] = 0.0; + problem->qshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->nbairs[i] = 0.0; + problem->nbsubs[i] = 0.0; + problem->calculations.all_chis[i] = 0.0; + problem->resolutions[i] = 0.0; + problem->allSubRough[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + Simulation[i].f1.set_size(2, 2); + Simulation[i].f1[0] = 1.0; + Simulation[i].f1[1] = 1.0; + Simulation[i].f1[Simulation[i].f1.size(0)] = 1.0; + Simulation[i].f1[Simulation[i].f1.size(0) + 1] = 1.0; + shifted_data[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + sldProfiles[i].f1.set_size(2, 2); + sldProfiles[i].f1[0] = 1.0; + sldProfiles[i].f1[1] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; + allLayers[i].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i] = 1.0; + shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; + } + } + + // End pre-allocation + if (coder::internal::f_strcmp(controls->para.data, controls->para.size)) { + loop_ub_tmp = 0; + } else if (coder::internal::g_strcmp(controls->para.data, + controls->para.size)) { + loop_ub_tmp = 1; + } else if (coder::internal::h_strcmp(controls->para.data, + controls->para.size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + standardTFCustomLayersSingle(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgrounds, problem->qshifts, + problem->scalefactors, problem->nbairs, problem->nbsubs, + problem->resolutions, problem->calculations.all_chis, reflectivity, + Simulation, shifted_data, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + + case 1: + standardTFCustomLayersParallelPoints(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgrounds, problem->qshifts, + problem->scalefactors, problem->nbairs, problem->nbsubs, + problem->resolutions, problem->calculations.all_chis, reflectivity, + Simulation, shifted_data, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + + case 2: + standardTFCustomLayersParallelContrasts(problemDef, problemDefCells, + controls, problem->ssubs, problem->backgrounds, problem->qshifts, + problem->scalefactors, problem->nbairs, problem->nbsubs, + problem->resolutions, problem->calculations.all_chis, reflectivity, + Simulation, shifted_data, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + } + + problem->calculations.sum_chi = coder::sum(problem->calculations.all_chis); + problem->resample.set_size(1, problemDef->resample.size(1)); + loop_ub_tmp = problemDef->resample.size(1); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + problem->resample[b_i] = problemDef->resample[b_i]; + } + } +} + +// End of code generation (standardTFCustomLayersReflectivityCalculation.cpp) diff --git a/RAT/standardTFCustomLayersReflectivityCalculation.h b/RAT/standardTFCustomLayersReflectivityCalculation.h new file mode 100644 index 00000000..913dcd12 --- /dev/null +++ b/RAT/standardTFCustomLayersReflectivityCalculation.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomLayersReflectivityCalculation.h +// +// Code generation for function 'standardTFCustomLayersReflectivityCalculation' +// +#ifndef STANDARDTFCUSTOMLAYERSREFLECTIVITYCALCULATION_H +#define STANDARDTFCUSTOMLAYERSREFLECTIVITYCALCULATION_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFCustomLayersReflectivityCalculation(const struct0_T *problemDef, + const cell_19 *problemDefCells, const struct2_T *controls, struct4_T + *problem, ::coder::array &reflectivity, ::coder::array< + cell_wrap_9, 1U> &Simulation, ::coder::array &shifted_data, + ::coder::array &layerSlds, ::coder::array + &sldProfiles, ::coder::array &allLayers); +} + +#endif + +// End of code generation (standardTFCustomLayersReflectivityCalculation.h) diff --git a/RAT/standardTFCustomLayersSingle.cpp b/RAT/standardTFCustomLayersSingle.cpp new file mode 100644 index 00000000..470d6556 --- /dev/null +++ b/RAT/standardTFCustomLayersSingle.cpp @@ -0,0 +1,193 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomLayersSingle.cpp +// +// Code generation for function 'standardTFCustomLayersSingle' +// + +// Include files +#include "standardTFCustomLayersSingle.h" +#include "backSort.h" +#include "customModelClass.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "standardTFLayersCore.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + void standardTFCustomLayersSingle(const struct0_T *problemDef, const cell_19 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) + { + ::coder::array layerSld; + ::coder::array resamLayers; + ::coder::array shifted_dat; + ::coder::array sldProfile; + real_T thisBackground; + real_T thisNba; + real_T thisNbs; + real_T thisQshift; + real_T thisResol; + real_T thisSf; + int32_T i; + + // Single threaded version of the custom layers, standardTF reflectivity + // calculation. The function extracts the relevant parameters from the input + // arrays, allocates these on a pre-contrast basis, then calls the 'core' + // calculation (the core layers standardTf calc is shared between multiple + // calculation types). + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // The min input array 'problemDefCells' is a master array where + // all the cell arrays are grouped together. There are + // repeatLayers - controls repeating of the layers stack + // allData - Array of all the data arrays + // dataLimits - Min max limits in q for the data arrays + // simLimits - Limits in Q for the reflkectivity simulations + // Layers details - Master array of all available layers + // contrastLayers - Which specific combination of arrays are needed for + // each contrast. + // Custom files - Filenames and path for any custom files used + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + // Pre-Allocation of output arrays... + i = static_cast(problemDef->numberOfContrasts); + backgs.set_size(i); + + // --- End Memory Allocation --- + // Resampling parameters + // Process the custom models.... + customModelClass::processCustomLayers(problemDef->contrastBacks, + problemDef->contrastShifts, problemDef->contrastScales, + problemDef->contrastNbas, problemDef->contrastNbss, + problemDef->contrastRes, problemDef->backs, problemDef->shifts, + problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, + problemDef->contrastCustomFiles, problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, problemDef->useImaginary, + allLayers, allRoughs); + + // Single cored over all contrasts + outSsubs.set_size(i); + sldProfiles.set_size(i); + reflectivity.set_size(i); + Simulation.set_size(i); + shifted_data.set_size(i); + layerSlds.set_size(i); + chis.set_size(i); + qshifts.set_size(i); + sfs.set_size(i); + nbas.set_size(i); + nbss.set_size(i); + resols.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T dv[2]; + real_T dv1[2]; + int32_T b_loop_ub; + int32_T loop_ub; + + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], + problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], + problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], + problemDef->backs, problemDef->shifts, problemDef->sf, + problemDef->nba, problemDef->nbs, problemDef->res, + &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, + &thisResol); + + // Get the custom layers output for this contrast + // For the other parameters, we extract the correct ones from the input + // arrays + // Now call the core standardTF_stanlay reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the reflectivity calculation + dv[0] = problemDefCells->f3[b_i].f1[0]; + dv[1] = problemDefCells->f3[b_i].f1[1]; + dv1[0] = problemDefCells->f1[b_i].f1[0]; + dv1[1] = problemDefCells->f1[b_i].f1[1]; + standardTFLayersCore(allLayers[b_i].f1, allRoughs[b_i], + problemDef->geometry.data, problemDef->geometry.size, + thisNba, thisNbs, problemDef->resample[b_i], + controls->calcSld, thisSf, thisQshift, + problemDef->dataPresent[b_i], problemDefCells->f2[b_i] + .f1, dv, (const real_T *)((::coder::array + *)&problemDefCells->f4[b_i].f1)->data(), dv1, thisBackground, thisResol, + problemDef->contrastBacksType[b_i], + static_cast(problemDef->params.size(1)), + controls->resamPars, problemDef->useImaginary, + sldProfile, reflectivity[b_i].f1, Simulation[b_i].f1, + shifted_dat, layerSld, resamLayers, &chis[b_i], + &outSsubs[b_i]); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + loop_ub = sldProfile.size(1); + sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = sldProfile.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = + sldProfile[i2 + sldProfile.size(0) * i1]; + } + } + + loop_ub = shifted_dat.size(1); + shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shifted_dat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1] = + shifted_dat[i2 + shifted_dat.size(0) * i1]; + } + } + + loop_ub = layerSld.size(1); + layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = layerSld.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = layerSld[i2 + + layerSld.size(0) * i1]; + } + } + + loop_ub = resamLayers.size(1); + allLayers[b_i].f1.set_size(resamLayers.size(0), resamLayers.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = resamLayers.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + resamLayers[i2 + resamLayers.size(0) * i1]; + } + } + + backgs[b_i] = thisBackground; + qshifts[b_i] = thisQshift; + sfs[b_i] = thisSf; + nbas[b_i] = thisNba; + nbss[b_i] = thisNbs; + resols[b_i] = thisResol; + } + } +} + +// End of code generation (standardTFCustomLayersSingle.cpp) diff --git a/RAT/standardTFCustomLayersSingle.h b/RAT/standardTFCustomLayersSingle.h new file mode 100644 index 00000000..c1e645c4 --- /dev/null +++ b/RAT/standardTFCustomLayersSingle.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomLayersSingle.h +// +// Code generation for function 'standardTFCustomLayersSingle' +// +#ifndef STANDARDTFCUSTOMLAYERSSINGLE_H +#define STANDARDTFCUSTOMLAYERSSINGLE_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFCustomLayersSingle(const struct0_T *problemDef, const cell_19 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); +} + +#endif + +// End of code generation (standardTFCustomLayersSingle.h) diff --git a/RAT/standardTFCustomXYParallelContrasts.cpp b/RAT/standardTFCustomXYParallelContrasts.cpp new file mode 100644 index 00000000..fb08a7f1 --- /dev/null +++ b/RAT/standardTFCustomXYParallelContrasts.cpp @@ -0,0 +1,232 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomXYParallelContrasts.cpp +// +// Code generation for function 'standardTFCustomXYParallelContrasts' +// + +// Include files +#include "standardTFCustomXYParallelContrasts.h" +#include "applyBackgroundCorrection.h" +#include "backSort.h" +#include "callReflectivity.h" +#include "chiSquared.h" +#include "customModelClass.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "resampleLayers.h" +#include "resampleLayersReIm.h" +#include "rt_nonfinite.h" +#include "shiftData.h" +#include "coder_array.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + void standardTFCustomXYParallelContrasts(const struct0_T *problemDef, const + cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) + { + ::coder::array Simul; + ::coder::array b_problemDefCells; + ::coder::array b_sldProfiles; + ::coder::array layerSld; + ::coder::array reflect; + ::coder::array shifted_dat; + real_T reSLD_data[2000]; + real_T dv[2]; + real_T d; + real_T d1; + real_T d2; + real_T d3; + real_T d4; + real_T d5; + int32_T iv[2]; + int32_T reSLD_size[2]; + int32_T b_loop_ub; + int32_T i1; + int32_T i2; + int32_T loop_ub; + int32_T loop_ub_tmp; + int32_T nParams; + boolean_T useImaginary; + + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // The min input array 'problemDefCells' is a master array where + // all the cell arrays are grouped together. There are + // repeatLayers - controls repeating of the layers stack + // allData - Array of all the data arrays + // dataLimits - Min max limits in q for the data arrays + // simLimits - Limits in Q for the reflkectivity simulations + // Layers details - Master array of all available layers + // contrastLayers - Which specific combination of arrays are needed for + // each contrast. + // Custom files - Filenames and path for any custom files used + // % Layers details N/A + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + + // Pre-Allocation... + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + backgs.set_size(loop_ub_tmp); + outSsubs.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + outSsubs[i] = 0.0; + } + + // Resampling parameters + useImaginary = problemDef->useImaginary; + customModelClass::processCustomXY(problemDef->contrastBacks, + problemDef->contrastShifts, problemDef->contrastScales, + problemDef->contrastNbas, problemDef->contrastNbss, + problemDef->contrastRes, problemDef->backs, problemDef->shifts, + problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, + problemDef->contrastCustomFiles, problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, sldProfiles, allRoughs); + qshifts.set_size(loop_ub_tmp); + sfs.set_size(loop_ub_tmp); + nbas.set_size(loop_ub_tmp); + nbss.set_size(loop_ub_tmp); + resols.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + shifted_data.set_size(loop_ub_tmp); + chis.set_size(loop_ub_tmp); + Simulation.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + loop_ub_tmp--; + +#pragma omp parallel for \ + num_threads(omp_get_max_threads()) \ + private(b_sldProfiles,b_problemDefCells,layerSld,reflect,Simul,shifted_dat,reSLD_data,reSLD_size,d,d1,d2,d3,d4,d5,loop_ub,b_loop_ub,i1,i2,dv,iv) + + for (int32_T b_i = 0; b_i <= loop_ub_tmp; b_i++) { + backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], + problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], + problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], + problemDef->backs, problemDef->shifts, problemDef->sf, + problemDef->nba, problemDef->nbs, problemDef->res, &d5, &d4, &d3, + &d2, &d1, &d); + backgs[b_i] = d5; + qshifts[b_i] = d4; + sfs[b_i] = d3; + nbas[b_i] = d2; + nbss[b_i] = d1; + resols[b_i] = d; + + // Resample the layers + if (!useImaginary) { + resampleLayers(sldProfiles[b_i].f1, controls->resamPars, layerSld); + } else { + loop_ub = sldProfiles[b_i].f1.size(0); + reSLD_size[0] = sldProfiles[b_i].f1.size(0); + reSLD_size[1] = 2; + for (i1 = 0; i1 < 2; i1++) { + for (i2 = 0; i2 < loop_ub; i2++) { + reSLD_data[i2 + reSLD_size[0] * i1] = sldProfiles[b_i].f1[i2 + + sldProfiles[b_i].f1.size(0) * i1]; + } + } + + loop_ub = sldProfiles[b_i].f1.size(0); + b_sldProfiles.set_size(sldProfiles[b_i].f1.size(0), 2); + for (i1 = 0; i1 < loop_ub; i1++) { + b_sldProfiles[i1] = sldProfiles[b_i].f1[i1]; + b_sldProfiles[i1 + b_sldProfiles.size(0)] = sldProfiles[b_i].f1[i1 + + sldProfiles[b_i].f1.size(0) * 2]; + } + + iv[0] = (*(int32_T (*)[2])b_sldProfiles.size())[0]; + iv[1] = (*(int32_T (*)[2])b_sldProfiles.size())[1]; + resampleLayersReIm(reSLD_data, reSLD_size, (const real_T *) + b_sldProfiles.data(), iv, controls->resamPars, + layerSld); + } + + layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + loop_ub = layerSld.size(1); + allLayers[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + b_loop_ub = layerSld.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + for (i2 = 0; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = layerSld[i2 + + layerSld.size(0) * i1]; + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = layerSld[i2 + + layerSld.size(0) * i1]; + } + } + + b_problemDefCells.set_size(problemDefCells->f2[problemDefCells->f2.size(0) + * b_i].f1.size(0), problemDefCells->f2[problemDefCells->f2.size(0) * b_i] + .f1.size(1)); + loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + for (i1 = 0; i1 <= loop_ub; i1++) { + b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + for (i2 = 0; i2 <= b_loop_ub; i2++) { + b_problemDefCells[i2 + b_problemDefCells.size(0) * i1] = + problemDefCells->f2[b_i].f1[i2 + problemDefCells->f2[b_i].f1.size(0) + * i1]; + } + } + + dv[0] = problemDefCells->f3[b_i].f1[0]; + dv[1] = problemDefCells->f3[b_i].f1[1]; + shiftData(sfs[b_i], qshifts[b_i], problemDef->dataPresent[b_i], + b_problemDefCells, dv, (const real_T *)((::coder::array *)&problemDefCells->f4[b_i].f1)->data(), shifted_dat); + shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); + loop_ub = shifted_dat.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = shifted_dat.size(0); + for (i2 = 0; i2 < b_loop_ub; i2++) { + shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1] = + shifted_dat[i2 + shifted_dat.size(0) * i1]; + } + } + + dv[0] = problemDefCells->f1[b_i].f1[0]; + dv[1] = problemDefCells->f1[b_i].f1[1]; + callReflectivity(nbas[b_i], nbss[b_i], (const real_T *)((::coder::array< + real_T, 2U> *)&problemDefCells->f4[b_i].f1)->data(), dv, shifted_dat, + layerSld, 0.0, resols[b_i], useImaginary, reflect, Simul); + applyBackgroundCorrection(reflect, Simul, shifted_dat, backgs[b_i], + problemDef->contrastBacksType[b_i]); + loop_ub = reflect.size(0); + reflectivity[b_i].f1.set_size(reflect.size(0), 2); + b_loop_ub = Simul.size(0); + Simulation[b_i].f1.set_size(Simul.size(0), 2); + for (i1 = 0; i1 < 2; i1++) { + for (i2 = 0; i2 < loop_ub; i2++) { + reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1] = + reflect[i2 + reflect.size(0) * i1]; + } + + for (i2 = 0; i2 < b_loop_ub; i2++) { + Simulation[b_i].f1[i2 + Simulation[b_i].f1.size(0) * i1] = Simul[i2 + + Simul.size(0) * i1]; + } + } + + if (problemDef->dataPresent[b_i] != 0.0) { + chis[b_i] = chiSquared(shifted_dat, reflect, static_cast(nParams)); + } else { + chis[b_i] = 0.0; + } + } + } +} + +// End of code generation (standardTFCustomXYParallelContrasts.cpp) diff --git a/RAT/standardTFCustomXYParallelContrasts.h b/RAT/standardTFCustomXYParallelContrasts.h new file mode 100644 index 00000000..dbad9e56 --- /dev/null +++ b/RAT/standardTFCustomXYParallelContrasts.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomXYParallelContrasts.h +// +// Code generation for function 'standardTFCustomXYParallelContrasts' +// +#ifndef STANDARDTFCUSTOMXYPARALLELCONTRASTS_H +#define STANDARDTFCUSTOMXYPARALLELCONTRASTS_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFCustomXYParallelContrasts(const struct0_T *problemDef, const + cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); +} + +#endif + +// End of code generation (standardTFCustomXYParallelContrasts.h) diff --git a/RAT/standardTFCustomXYParallelPoints.cpp b/RAT/standardTFCustomXYParallelPoints.cpp new file mode 100644 index 00000000..f36d7ad8 --- /dev/null +++ b/RAT/standardTFCustomXYParallelPoints.cpp @@ -0,0 +1,204 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomXYParallelPoints.cpp +// +// Code generation for function 'standardTFCustomXYParallelPoints' +// + +// Include files +#include "standardTFCustomXYParallelPoints.h" +#include "applyBackgroundCorrection.h" +#include "backSort.h" +#include "callReflectivity.h" +#include "chiSquared.h" +#include "customModelClass.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "resampleLayers.h" +#include "resampleLayersReIm.h" +#include "rt_nonfinite.h" +#include "shiftData.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void standardTFCustomXYParallelPoints(const struct0_T *problemDef, const + cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) + { + ::coder::array b_problemDefCells; + ::coder::array b_sldProfiles; + ::coder::array layerSld; + ::coder::array reflect; + ::coder::array shifted_dat; + int32_T sldProfiles_size[2]; + int32_T loop_ub_tmp; + boolean_T useImaginary; + + // Multi threaded version of the custom XY profile over reflectivity points + // for standardTF reflectivity calculation. + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // The min input array 'problemDefCells' is a master array where + // all the cell arrays are grouped together. There are + // repeatLayers - controls repeating of the layers stack + // allData - Array of all the data arrays + // dataLimits - Min max limits in q for the data arrays + // simLimits - Limits in Q for the reflkectivity simulations + // Layers details - Master array of all available layers + // contrastLayers - Which specific combination of arrays are needed for + // each contrast. + // Custom files - Filenames and path for any custom files used + // % Layers details N/A + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + // Pre-Allocation... + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + backgs.set_size(loop_ub_tmp); + outSsubs.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + outSsubs[i] = 0.0; + } + + // Resampling parameters + useImaginary = problemDef->useImaginary; + customModelClass::processCustomXY(problemDef->contrastBacks, + problemDef->contrastShifts, problemDef->contrastScales, + problemDef->contrastNbas, problemDef->contrastNbss, + problemDef->contrastRes, problemDef->backs, problemDef->shifts, + problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, + problemDef->contrastCustomFiles, problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, sldProfiles, allRoughs); + qshifts.set_size(loop_ub_tmp); + sfs.set_size(loop_ub_tmp); + nbas.set_size(loop_ub_tmp); + nbss.set_size(loop_ub_tmp); + resols.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + shifted_data.set_size(loop_ub_tmp); + chis.set_size(loop_ub_tmp); + Simulation.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + real_T dv[2]; + int32_T b_loop_ub; + int32_T loop_ub; + backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], + problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], + problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], + problemDef->backs, problemDef->shifts, problemDef->sf, + problemDef->nba, problemDef->nbs, problemDef->res, &backgs[b_i], + &qshifts[b_i], &sfs[b_i], &nbas[b_i], &nbss[b_i], &resols[b_i]); + + // Resample the layers + if (!useImaginary) { + resampleLayers(sldProfiles[b_i].f1, controls->resamPars, layerSld); + } else { + real_T sldProfiles_data[2000]; + loop_ub = sldProfiles[b_i].f1.size(0); + sldProfiles_size[0] = sldProfiles[b_i].f1.size(0); + sldProfiles_size[1] = 2; + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + sldProfiles_data[i1 + sldProfiles_size[0] * i] = sldProfiles[b_i] + .f1[i1 + sldProfiles[b_i].f1.size(0) * i]; + } + } + + loop_ub = sldProfiles[b_i].f1.size(0); + b_sldProfiles.set_size(sldProfiles[b_i].f1.size(0), 2); + for (int32_T i{0}; i < loop_ub; i++) { + b_sldProfiles[i] = sldProfiles[b_i].f1[i]; + b_sldProfiles[i + b_sldProfiles.size(0)] = sldProfiles[b_i].f1[i + + sldProfiles[b_i].f1.size(0) * 2]; + } + + int32_T iv[2]; + iv[0] = (*(int32_T (*)[2])b_sldProfiles.size())[0]; + iv[1] = (*(int32_T (*)[2])b_sldProfiles.size())[1]; + resampleLayersReIm(sldProfiles_data, sldProfiles_size, (const real_T *) + b_sldProfiles.data(), iv, controls->resamPars, + layerSld); + } + + layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + loop_ub = layerSld.size(1); + allLayers[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + b_loop_ub = layerSld.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + layerSlds[b_i].f1[i1 + layerSlds[b_i].f1.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + allLayers[b_i].f1[i1 + allLayers[b_i].f1.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + + b_problemDefCells.set_size(problemDefCells->f2[problemDefCells->f2.size(0) + * b_i].f1.size(0), problemDefCells->f2[problemDefCells->f2.size(0) * b_i] + .f1.size(1)); + loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + for (int32_T i{0}; i <= loop_ub; i++) { + b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + for (int32_T i1{0}; i1 <= b_loop_ub; i1++) { + b_problemDefCells[i1 + b_problemDefCells.size(0) * i] = + problemDefCells->f2[b_i].f1[i1 + problemDefCells->f2[b_i].f1.size(0) + * i]; + } + } + + dv[0] = problemDefCells->f3[b_i].f1[0]; + dv[1] = problemDefCells->f3[b_i].f1[1]; + shiftData(sfs[b_i], qshifts[b_i], problemDef->dataPresent[b_i], + b_problemDefCells, dv, (const real_T *)((::coder::array *)&problemDefCells->f4[b_i].f1)->data(), shifted_dat); + shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); + loop_ub = shifted_dat.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = shifted_dat.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + shifted_data[b_i].f1[i1 + shifted_data[b_i].f1.size(0) * i] = + shifted_dat[i1 + shifted_dat.size(0) * i]; + } + } + + dv[0] = problemDefCells->f1[b_i].f1[0]; + dv[1] = problemDefCells->f1[b_i].f1[1]; + b_callReflectivity(nbas[b_i], nbss[b_i], (const real_T *)((::coder::array< + real_T, 2U> *)&problemDefCells->f4[b_i].f1)->data(), dv, shifted_dat, + layerSld, 0.0, resols[b_i], useImaginary, reflect, + Simulation[b_i].f1); + applyBackgroundCorrection(reflect, Simulation[b_i].f1, shifted_dat, + backgs[b_i], problemDef->contrastBacksType[b_i]); + loop_ub = reflect.size(0); + reflectivity[b_i].f1.set_size(reflect.size(0), 2); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + reflectivity[b_i].f1[i1 + reflectivity[b_i].f1.size(0) * i] = + reflect[i1 + reflect.size(0) * i]; + } + } + + if (problemDef->dataPresent[b_i] != 0.0) { + chis[b_i] = chiSquared(shifted_dat, reflect, static_cast + (problemDef->params.size(1))); + } else { + chis[b_i] = 0.0; + } + } + } +} + +// End of code generation (standardTFCustomXYParallelPoints.cpp) diff --git a/RAT/standardTFCustomXYParallelPoints.h b/RAT/standardTFCustomXYParallelPoints.h new file mode 100644 index 00000000..7c9a3fb1 --- /dev/null +++ b/RAT/standardTFCustomXYParallelPoints.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomXYParallelPoints.h +// +// Code generation for function 'standardTFCustomXYParallelPoints' +// +#ifndef STANDARDTFCUSTOMXYPARALLELPOINTS_H +#define STANDARDTFCUSTOMXYPARALLELPOINTS_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFCustomXYParallelPoints(const struct0_T *problemDef, const + cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); +} + +#endif + +// End of code generation (standardTFCustomXYParallelPoints.h) diff --git a/RAT/standardTFCustomXYReflectivityCalculation.cpp b/RAT/standardTFCustomXYReflectivityCalculation.cpp new file mode 100644 index 00000000..d4ffcaf0 --- /dev/null +++ b/RAT/standardTFCustomXYReflectivityCalculation.cpp @@ -0,0 +1,152 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomXYReflectivityCalculation.cpp +// +// Code generation for function 'standardTFCustomXYReflectivityCalculation' +// + +// Include files +#include "standardTFCustomXYReflectivityCalculation.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "standardTFCustomXYParallelContrasts.h" +#include "standardTFCustomXYParallelPoints.h" +#include "standardTFCustomXYSingle.h" +#include "strcmp.h" +#include "sum.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + void standardTFCustomXYReflectivityCalculation(const struct0_T *problemDef, + const cell_19 *problemDefCells, const struct2_T *controls, struct4_T + *problem, ::coder::array &reflectivity, ::coder::array< + cell_wrap_9, 1U> &Simulation, ::coder::array &shifted_data, + ::coder::array &layerSlds, ::coder::array + &sldProfiles, ::coder::array &allLayers) + { + int32_T loop_ub_tmp; + + // Custom XP profile reflectivity calculation for standardTF + // This function decides on parallelisation options before calling the + // relevant version of the main custom XY calculation. It is more + // efficient to have multiple versions of the core calculation, each dealing + // with a different scheme for parallelisation. These are: + // single - single threaded teflectivity calculation + // points - parallelise over points in the reflectivity calculation + // contrasts - parallelise over contrasts. + // Pre-allocation - It's necessary to + // pre-allocate the memory for all the arrays + // for compilation, so do this in this block. + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgrounds.set_size(loop_ub_tmp); + problem->qshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->nbairs.set_size(loop_ub_tmp); + problem->nbsubs.set_size(loop_ub_tmp); + problem->calculations.all_chis.set_size(loop_ub_tmp); + problem->resolutions.set_size(loop_ub_tmp); + problem->allSubRough.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + Simulation.set_size(loop_ub_tmp); + shifted_data.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + sldProfiles.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgrounds[i] = 0.0; + problem->qshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->nbairs[i] = 0.0; + problem->nbsubs[i] = 0.0; + problem->calculations.all_chis[i] = 0.0; + problem->resolutions[i] = 0.0; + problem->allSubRough[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + Simulation[i].f1.set_size(2, 2); + Simulation[i].f1[0] = 1.0; + Simulation[i].f1[1] = 1.0; + Simulation[i].f1[Simulation[i].f1.size(0)] = 1.0; + Simulation[i].f1[Simulation[i].f1.size(0) + 1] = 1.0; + shifted_data[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i] = 1.0; + shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + } + + sldProfiles[i].f1.set_size(2, 2); + sldProfiles[i].f1[0] = 1.0; + sldProfiles[i].f1[1] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; + allLayers[i].f1.set_size(2, 1); + allLayers[i].f1[0] = 1.0; + allLayers[i].f1[1] = 1.0; + } + + if (coder::internal::f_strcmp(controls->para.data, controls->para.size)) { + loop_ub_tmp = 0; + } else if (coder::internal::g_strcmp(controls->para.data, + controls->para.size)) { + loop_ub_tmp = 1; + } else if (coder::internal::h_strcmp(controls->para.data, + controls->para.size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + standardTFCustomXYSingle(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgrounds, problem->qshifts, + problem->scalefactors, problem->nbairs, problem->nbsubs, + problem->resolutions, problem->calculations.all_chis, reflectivity, + Simulation, shifted_data, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + + case 1: + standardTFCustomXYParallelPoints(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgrounds, problem->qshifts, + problem->scalefactors, problem->nbairs, problem->nbsubs, + problem->resolutions, problem->calculations.all_chis, reflectivity, + Simulation, shifted_data, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + + case 2: + standardTFCustomXYParallelContrasts(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgrounds, problem->qshifts, + problem->scalefactors, problem->nbairs, problem->nbsubs, + problem->resolutions, problem->calculations.all_chis, reflectivity, + Simulation, shifted_data, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + } + + problem->calculations.sum_chi = coder::sum(problem->calculations.all_chis); + problem->resample.set_size(1, problem->allSubRough.size(0)); + loop_ub_tmp = problem->allSubRough.size(0); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + problem->resample[b_i] = 1.0; + } + } +} + +// End of code generation (standardTFCustomXYReflectivityCalculation.cpp) diff --git a/RAT/standardTFCustomXYReflectivityCalculation.h b/RAT/standardTFCustomXYReflectivityCalculation.h new file mode 100644 index 00000000..81d5f624 --- /dev/null +++ b/RAT/standardTFCustomXYReflectivityCalculation.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomXYReflectivityCalculation.h +// +// Code generation for function 'standardTFCustomXYReflectivityCalculation' +// +#ifndef STANDARDTFCUSTOMXYREFLECTIVITYCALCULATION_H +#define STANDARDTFCUSTOMXYREFLECTIVITYCALCULATION_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFCustomXYReflectivityCalculation(const struct0_T *problemDef, + const cell_19 *problemDefCells, const struct2_T *controls, struct4_T + *problem, ::coder::array &reflectivity, ::coder::array< + cell_wrap_9, 1U> &Simulation, ::coder::array &shifted_data, + ::coder::array &layerSlds, ::coder::array + &sldProfiles, ::coder::array &allLayers); +} + +#endif + +// End of code generation (standardTFCustomXYReflectivityCalculation.h) diff --git a/RAT/standardTFCustomXYSingle.cpp b/RAT/standardTFCustomXYSingle.cpp new file mode 100644 index 00000000..83ad5d70 --- /dev/null +++ b/RAT/standardTFCustomXYSingle.cpp @@ -0,0 +1,202 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomXYSingle.cpp +// +// Code generation for function 'standardTFCustomXYSingle' +// + +// Include files +#include "standardTFCustomXYSingle.h" +#include "applyBackgroundCorrection.h" +#include "backSort.h" +#include "callReflectivity.h" +#include "chiSquared.h" +#include "customModelClass.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "resampleLayers.h" +#include "resampleLayersReIm.h" +#include "rt_nonfinite.h" +#include "shiftData.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void standardTFCustomXYSingle(const struct0_T *problemDef, const cell_19 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) + { + ::coder::array b_problemDefCells; + ::coder::array b_sldProfiles; + ::coder::array layerSld; + ::coder::array reflect; + ::coder::array shifted_dat; + int32_T sldProfiles_size[2]; + int32_T loop_ub_tmp; + boolean_T useImaginary; + + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // The min input array 'problemDefCells' is a master array where + // all the cell arrays are grouped together. There are + // repeatLayers - controls repeating of the layers stack + // allData - Array of all the data arrays + // dataLimits - Min max limits in q for the data arrays + // simLimits - Limits in Q for the reflkectivity simulations + // Layers details - Master array of all available layers + // contrastLayers - Which specific combination of arrays are needed for + // each contrast. + // Custom files - Filenames and path for any custom files used + // % Layers details N/A + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + // Pre-Allocation... + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + backgs.set_size(loop_ub_tmp); + outSsubs.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + outSsubs[i] = 0.0; + } + + // Resampling parameters + useImaginary = problemDef->useImaginary; + customModelClass::processCustomXY(problemDef->contrastBacks, + problemDef->contrastShifts, problemDef->contrastScales, + problemDef->contrastNbas, problemDef->contrastNbss, + problemDef->contrastRes, problemDef->backs, problemDef->shifts, + problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, + problemDef->contrastCustomFiles, problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, sldProfiles, allRoughs); + qshifts.set_size(loop_ub_tmp); + sfs.set_size(loop_ub_tmp); + nbas.set_size(loop_ub_tmp); + nbss.set_size(loop_ub_tmp); + resols.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + shifted_data.set_size(loop_ub_tmp); + chis.set_size(loop_ub_tmp); + Simulation.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + real_T dv[2]; + int32_T b_loop_ub; + int32_T loop_ub; + backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], + problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], + problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], + problemDef->backs, problemDef->shifts, problemDef->sf, + problemDef->nba, problemDef->nbs, problemDef->res, &backgs[b_i], + &qshifts[b_i], &sfs[b_i], &nbas[b_i], &nbss[b_i], &resols[b_i]); + + // Resample the layers + if (!useImaginary) { + resampleLayers(sldProfiles[b_i].f1, controls->resamPars, layerSld); + } else { + real_T sldProfiles_data[2000]; + loop_ub = sldProfiles[b_i].f1.size(0); + sldProfiles_size[0] = sldProfiles[b_i].f1.size(0); + sldProfiles_size[1] = 2; + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + sldProfiles_data[i1 + sldProfiles_size[0] * i] = sldProfiles[b_i] + .f1[i1 + sldProfiles[b_i].f1.size(0) * i]; + } + } + + loop_ub = sldProfiles[b_i].f1.size(0); + b_sldProfiles.set_size(sldProfiles[b_i].f1.size(0), 2); + for (int32_T i{0}; i < loop_ub; i++) { + b_sldProfiles[i] = sldProfiles[b_i].f1[i]; + b_sldProfiles[i + b_sldProfiles.size(0)] = sldProfiles[b_i].f1[i + + sldProfiles[b_i].f1.size(0) * 2]; + } + + int32_T iv[2]; + iv[0] = (*(int32_T (*)[2])b_sldProfiles.size())[0]; + iv[1] = (*(int32_T (*)[2])b_sldProfiles.size())[1]; + resampleLayersReIm(sldProfiles_data, sldProfiles_size, (const real_T *) + b_sldProfiles.data(), iv, controls->resamPars, + layerSld); + } + + layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + loop_ub = layerSld.size(1); + allLayers[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + b_loop_ub = layerSld.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + layerSlds[b_i].f1[i1 + layerSlds[b_i].f1.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + allLayers[b_i].f1[i1 + allLayers[b_i].f1.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + + b_problemDefCells.set_size(problemDefCells->f2[problemDefCells->f2.size(0) + * b_i].f1.size(0), problemDefCells->f2[problemDefCells->f2.size(0) * b_i] + .f1.size(1)); + loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + for (int32_T i{0}; i <= loop_ub; i++) { + b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + for (int32_T i1{0}; i1 <= b_loop_ub; i1++) { + b_problemDefCells[i1 + b_problemDefCells.size(0) * i] = + problemDefCells->f2[b_i].f1[i1 + problemDefCells->f2[b_i].f1.size(0) + * i]; + } + } + + dv[0] = problemDefCells->f3[b_i].f1[0]; + dv[1] = problemDefCells->f3[b_i].f1[1]; + shiftData(sfs[b_i], qshifts[b_i], problemDef->dataPresent[b_i], + b_problemDefCells, dv, (const real_T *)((::coder::array *)&problemDefCells->f4[b_i].f1)->data(), shifted_dat); + shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); + loop_ub = shifted_dat.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = shifted_dat.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + shifted_data[b_i].f1[i1 + shifted_data[b_i].f1.size(0) * i] = + shifted_dat[i1 + shifted_dat.size(0) * i]; + } + } + + dv[0] = problemDefCells->f1[b_i].f1[0]; + dv[1] = problemDefCells->f1[b_i].f1[1]; + callReflectivity(nbas[b_i], nbss[b_i], (const real_T *)((::coder::array< + real_T, 2U> *)&problemDefCells->f4[b_i].f1)->data(), dv, shifted_dat, + layerSld, 0.0, resols[b_i], useImaginary, reflect, + Simulation[b_i].f1); + applyBackgroundCorrection(reflect, Simulation[b_i].f1, shifted_dat, + backgs[b_i], problemDef->contrastBacksType[b_i]); + loop_ub = reflect.size(0); + reflectivity[b_i].f1.set_size(reflect.size(0), 2); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + reflectivity[b_i].f1[i1 + reflectivity[b_i].f1.size(0) * i] = + reflect[i1 + reflect.size(0) * i]; + } + } + + if (problemDef->dataPresent[b_i] != 0.0) { + chis[b_i] = chiSquared(shifted_dat, reflect, static_cast + (problemDef->params.size(1))); + } else { + chis[b_i] = 0.0; + } + } + } +} + +// End of code generation (standardTFCustomXYSingle.cpp) diff --git a/RAT/standardTFCustomXYSingle.h b/RAT/standardTFCustomXYSingle.h new file mode 100644 index 00000000..7d88a55f --- /dev/null +++ b/RAT/standardTFCustomXYSingle.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFCustomXYSingle.h +// +// Code generation for function 'standardTFCustomXYSingle' +// +#ifndef STANDARDTFCUSTOMXYSINGLE_H +#define STANDARDTFCUSTOMXYSINGLE_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFCustomXYSingle(const struct0_T *problemDef, const cell_19 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); +} + +#endif + +// End of code generation (standardTFCustomXYSingle.h) diff --git a/RAT/standardTFLayersCore.cpp b/RAT/standardTFLayersCore.cpp new file mode 100644 index 00000000..c28e51c6 --- /dev/null +++ b/RAT/standardTFLayersCore.cpp @@ -0,0 +1,683 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFLayersCore.cpp +// +// Code generation for function 'standardTFLayersCore' +// + +// Include files +#include "standardTFLayersCore.h" +#include "applyBackgroundCorrection.h" +#include "callReflectivity.h" +#include "chiSquared.h" +#include "groupLayersMod.h" +#include "groupLayersModImaginary.h" +#include "makeSLDProfiles.h" +#include "resampleLayers.h" +#include "resampleLayersReIm.h" +#include "rt_nonfinite.h" +#include "shiftData.h" +#include "coder_array.h" +#include + +namespace py = pybind11; +// Function Definitions +namespace RAT +{ + void b_standardTFLayersCore(const ::coder::array &contrastLayers, + real_T rough, const char_T geometry_data[], const int32_T geometry_size[2], + real_T nba, real_T nbs, real_T resample, real_T calcSld, real_T sf, real_T + qshift, real_T dataPresent, const ::coder::array &data, const + real_T dataLimits[2], const real_T simLimits_data[], const real_T + repeatLayers[2], real_T background, real_T resol, real_T backsType, real_T + params, const real_T resamPars[2], boolean_T useImaginary, ::coder::array< + real_T, 2U> &sldProfile, ::coder::array &reflect, ::coder::array< + real_T, 2U> &Simul, ::coder::array &shifted_dat, ::coder::array< + real_T, 2U> &theseLayers, ::coder::array &resamLayers, real_T + *chiSq, real_T *ssubs) + { + ::coder::array b_data; + ::coder::array b_theseLayers; + ::coder::array c_theseLayers; + ::coder::array layerSld; + ::coder::array sldProfileIm; + ::coder::array thisSldLays; + ::coder::array thisSldLaysIm; + ::coder::array d_theseLayers; + int32_T b_loop_ub; + int32_T i; + int32_T i1; + int32_T loop_ub; + + // This is the main reflectivity calculation for all Layers models in the + // standard target function. + // + // The function first arranges the + // roughness' in the correct order according + // to geometry. Then, if required it calculates the SLD profile and if + // requested resamples this into a number of zero-roughness layers + // (roughness resampling). It the applies any scalefactors and qz shifts + // the data requires. This is done before calculating the reflectivity to + // ensure that the reflectivity is calculated over the same range in qz as + // the shifted datapoints. The main reflectivity calculation is then + // called, including the resolution function. The calculation outputs two + // profiles - 'reflect' which is the same range as the points, and + // 'Simulation' which can be a different range to allow extrapolation. + // The background correction is the applied, and finally chi-squared is + // calculated. + // + // Inputs: + // contrastLayers : + // rough : + // geometry : + // nba : + // nbs : + // resample : + // calcSld : + // sf : + // qshift : + // dataPresent : + // data : + // dataLimits : + // simLimits : + // repeatLayers : + // background : + // resol : + // backsType : + // params : + // parallelPoints : + // + // Outputs: + // + // ------------------------------------------------------------------------ + // + // (c) Arwel Hughes - 12/1/21 + // + // Last Modified: 12/1/21 by Arwel Hughes. + // + // ------------------------------------------------------------------------ + // Pre-definition for Coder.. + thisSldLaysIm.set_size(1, 2); + sldProfileIm.set_size(1, 2); + thisSldLaysIm[0] = 0.0; + sldProfileIm[0] = 0.0; + thisSldLaysIm[thisSldLaysIm.size(0)] = 0.0; + sldProfileIm[sldProfileIm.size(0)] = 0.0; + + // Bulid up the layers matrix for this contrast + if (!useImaginary) { + groupLayersMod(contrastLayers, rough, geometry_data, geometry_size, nba, + nbs, layerSld, ssubs); + theseLayers.set_size(layerSld.size(0), 3); + loop_ub = layerSld.size(0); + for (i = 0; i < 3; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } else { + groupLayersModImaginary(contrastLayers, rough, geometry_data, + geometry_size, nba, nbs, layerSld, ssubs); + theseLayers.set_size(layerSld.size(0), 4); + loop_ub = layerSld.size(0); + for (i = 0; i < 4; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } + + // Make the SLD profiles. + // If resampling is needed, then enforce the calcSLD flag, so as to catch + // the error af trying to resample a non-existent profile. + if ((resample == 1.0) && (calcSld == 0.0)) { + calcSld = 1.0; + } + + // If calc SLD flag is set, then calculate the SLD profile + if (calcSld == 1.0) { + // If we need them both, we process real and imaginary parts of the SLD + // seperately... + if (useImaginary) { + int32_T result; + int8_T input_sizes_idx_1; + int8_T sizes_idx_1; + boolean_T empty_non_axis_sizes; + if (theseLayers.size(1) < 4) { + i = 0; + i1 = 0; + } else { + i = 3; + i1 = 4; + } + + if (theseLayers.size(0) != 0) { + result = theseLayers.size(0); + } else { + result = 0; + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + input_sizes_idx_1 = 2; + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || ((theseLayers.size(0) != 0) && (i1 - i != 0))) + { + sizes_idx_1 = static_cast(i1 - i); + } else { + sizes_idx_1 = 0; + } + + b_theseLayers.set_size(theseLayers.size(0), 2); + loop_ub = theseLayers.size(0); + for (int32_T i2{0}; i2 < 2; i2++) { + for (b_loop_ub = 0; b_loop_ub < loop_ub; b_loop_ub++) { + b_theseLayers[b_loop_ub + b_theseLayers.size(0) * i2] = + theseLayers[b_loop_ub + theseLayers.size(0) * i2]; + } + } + + loop_ub = i1 - i; + c_theseLayers.set_size(theseLayers.size(0), loop_ub); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = theseLayers.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + c_theseLayers[i2 + c_theseLayers.size(0) * i1] = theseLayers[i2 + + theseLayers.size(0) * (i + i1)]; + } + } + + thisSldLays.set_size(result, input_sizes_idx_1 + sizes_idx_1); + loop_ub = input_sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * i] = b_theseLayers[i1 + + result * i]; + } + } + + loop_ub = sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * (i + input_sizes_idx_1)] = + c_theseLayers[i1 + result * i]; + } + } + + if (theseLayers.size(0) != 0) { + result = theseLayers.size(0); + } else { + result = 0; + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + input_sizes_idx_1 = 1; + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + sizes_idx_1 = static_cast(theseLayers.size(1) - 2); + } else { + sizes_idx_1 = 0; + } + + d_theseLayers.set_size(theseLayers.size(0)); + loop_ub = theseLayers.size(0); + for (i = 0; i < loop_ub; i++) { + d_theseLayers[i] = theseLayers[i]; + } + + c_theseLayers.set_size(theseLayers.size(0), theseLayers.size(1) - 2); + loop_ub = theseLayers.size(1); + b_loop_ub = theseLayers.size(0); + for (i = 0; i <= loop_ub - 3; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + c_theseLayers[i1 + c_theseLayers.size(0) * i] = theseLayers[i1 + + theseLayers.size(0) * (i + 2)]; + } + } + + thisSldLaysIm.set_size(result, input_sizes_idx_1 + sizes_idx_1); + loop_ub = input_sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLaysIm[i1] = d_theseLayers[i1]; + } + } + + loop_ub = sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLaysIm[i1 + thisSldLaysIm.size(0) * (i + input_sizes_idx_1)] = + c_theseLayers[i1 + result * i]; + } + } + } else { + thisSldLays.set_size(theseLayers.size(0), theseLayers.size(1)); + loop_ub = theseLayers.size(1); + b_loop_ub = theseLayers.size(0); + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * i] = theseLayers[i1 + + theseLayers.size(0) * i]; + } + } + } + + makeSLDProfiles(nba, nbs, thisSldLays, *ssubs, repeatLayers, b_theseLayers); + sldProfile.set_size(b_theseLayers.size(0), 2); + loop_ub = b_theseLayers.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + sldProfile[i1 + sldProfile.size(0) * i] = b_theseLayers[i1 + + b_theseLayers.size(0) * i]; + } + } + + // If we have imaginary, we are also + // going to need an SLD profile for the imaginary part + if (useImaginary) { + // Note nba and nbs = 0 since there is never any imaginary part for + // the bulk phases.. + makeSLDProfiles(thisSldLaysIm, *ssubs, repeatLayers, b_theseLayers); + sldProfileIm.set_size(b_theseLayers.size(0), 2); + loop_ub = b_theseLayers.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + sldProfileIm[i1 + sldProfileIm.size(0) * i] = b_theseLayers[i1 + + b_theseLayers.size(0) * i]; + } + } + } + } else { + sldProfile.set_size(1, 2); + sldProfile[0] = 0.0; + sldProfile[sldProfile.size(0)] = 0.0; + } + + // If required, then resample the SLD + if (resample == 1.0) { + if (!useImaginary) { + resampleLayers(sldProfile, resamPars, layerSld); + } else { + resampleLayersReIm(sldProfile, sldProfileIm, resamPars, layerSld); + } + + resamLayers.set_size(layerSld.size(0), layerSld.size(1)); + loop_ub = layerSld.size(1); + b_loop_ub = layerSld.size(0); + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + resamLayers[i1 + resamLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } else { + resamLayers.set_size(1, 3); + resamLayers[0] = 0.0; + resamLayers[resamLayers.size(0)] = 0.0; + resamLayers[resamLayers.size(0) * 2] = 0.0; + } + + // Apply scale factors and q shifts to the data + b_data.set_size(data.size(0), data.size(1)); + loop_ub = data.size(1) - 1; + for (i = 0; i <= loop_ub; i++) { + b_loop_ub = data.size(0) - 1; + for (i1 = 0; i1 <= b_loop_ub; i1++) { + b_data[i1 + b_data.size(0) * i] = data[i1 + data.size(0) * i]; + } + } + + shiftData(sf, qshift, dataPresent, b_data, dataLimits, simLimits_data, + shifted_dat); + + // Calculate the reflectivity + b_callReflectivity(nba, nbs, simLimits_data, repeatLayers, shifted_dat, + layerSld, *ssubs, resol, useImaginary, reflect, Simul); + + // Apply background correction, either to the simulation or the data + applyBackgroundCorrection(reflect, Simul, shifted_dat, background, backsType); + + // Calculate chi squared. + *chiSq = chiSquared(shifted_dat, reflect, params); + } + + void standardTFLayersCore(const ::coder::array &contrastLayers, + real_T rough, const char_T geometry_data[], const int32_T geometry_size[2], + real_T nba, real_T nbs, real_T resample, real_T calcSld, real_T sf, real_T + qshift, real_T dataPresent, const ::coder::array &data, const + real_T dataLimits[2], const real_T simLimits_data[], const real_T + repeatLayers[2], real_T background, real_T resol, real_T backsType, real_T + params, const real_T resamPars[2], boolean_T useImaginary, ::coder::array< + real_T, 2U> &sldProfile, ::coder::array &reflect, ::coder::array< + real_T, 2U> &Simul, ::coder::array &shifted_dat, ::coder::array< + real_T, 2U> &theseLayers, ::coder::array &resamLayers, real_T + *chiSq, real_T *ssubs) + { + ::coder::array b_data; + ::coder::array b_theseLayers; + ::coder::array c_theseLayers; + ::coder::array layerSld; + ::coder::array sldProfileIm; + ::coder::array thisSldLays; + ::coder::array thisSldLaysIm; + ::coder::array d_theseLayers; + int32_T b_loop_ub; + int32_T i; + int32_T i1; + int32_T loop_ub; + + // This is the main reflectivity calculation for all Layers models in the + // standard target function. + // + // The function first arranges the + // roughness' in the correct order according + // to geometry. Then, if required it calculates the SLD profile and if + // requested resamples this into a number of zero-roughness layers + // (roughness resampling). It the applies any scalefactors and qz shifts + // the data requires. This is done before calculating the reflectivity to + // ensure that the reflectivity is calculated over the same range in qz as + // the shifted datapoints. The main reflectivity calculation is then + // called, including the resolution function. The calculation outputs two + // profiles - 'reflect' which is the same range as the points, and + // 'Simulation' which can be a different range to allow extrapolation. + // The background correction is the applied, and finally chi-squared is + // calculated. + // + // Inputs: + // contrastLayers : + // rough : + // geometry : + // nba : + // nbs : + // resample : + // calcSld : + // sf : + // qshift : + // dataPresent : + // data : + // dataLimits : + // simLimits : + // repeatLayers : + // background : + // resol : + // backsType : + // params : + // parallelPoints : + // + // Outputs: + // + // ------------------------------------------------------------------------ + // + // (c) Arwel Hughes - 12/1/21 + // + // Last Modified: 12/1/21 by Arwel Hughes. + // + // ------------------------------------------------------------------------ + // Pre-definition for Coder.. + thisSldLaysIm.set_size(1, 2); + sldProfileIm.set_size(1, 2); + thisSldLaysIm[0] = 0.0; + sldProfileIm[0] = 0.0; + thisSldLaysIm[thisSldLaysIm.size(0)] = 0.0; + sldProfileIm[sldProfileIm.size(0)] = 0.0; + + // Bulid up the layers matrix for this contrast + if (!useImaginary) { + groupLayersMod(contrastLayers, rough, geometry_data, geometry_size, nba, + nbs, layerSld, ssubs); + theseLayers.set_size(layerSld.size(0), 3); + loop_ub = layerSld.size(0); + for (i = 0; i < 3; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } else { + groupLayersModImaginary(contrastLayers, rough, geometry_data, + geometry_size, nba, nbs, layerSld, ssubs); + theseLayers.set_size(layerSld.size(0), 4); + loop_ub = layerSld.size(0); + for (i = 0; i < 4; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } + + // Make the SLD profiles. + // If resampling is needed, then enforce the calcSLD flag, so as to catch + // the error af trying to resample a non-existent profile. + if ((resample == 1.0) && (calcSld == 0.0)) { + calcSld = 1.0; + } + + // If calc SLD flag is set, then calculate the SLD profile + if (calcSld == 1.0) { + // If we need them both, we process real and imaginary parts of the SLD + // seperately... + if (useImaginary) { + int32_T result; + int8_T input_sizes_idx_1; + int8_T sizes_idx_1; + boolean_T empty_non_axis_sizes; + if (theseLayers.size(1) < 4) { + i = 0; + i1 = 0; + } else { + i = 3; + i1 = 4; + } + + if (theseLayers.size(0) != 0) { + result = theseLayers.size(0); + } else { + result = 0; + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + input_sizes_idx_1 = 2; + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || ((theseLayers.size(0) != 0) && (i1 - i != 0))) + { + sizes_idx_1 = static_cast(i1 - i); + } else { + sizes_idx_1 = 0; + } + + b_theseLayers.set_size(theseLayers.size(0), 2); + loop_ub = theseLayers.size(0); + for (int32_T i2{0}; i2 < 2; i2++) { + for (b_loop_ub = 0; b_loop_ub < loop_ub; b_loop_ub++) { + b_theseLayers[b_loop_ub + b_theseLayers.size(0) * i2] = + theseLayers[b_loop_ub + theseLayers.size(0) * i2]; + } + } + + loop_ub = i1 - i; + c_theseLayers.set_size(theseLayers.size(0), loop_ub); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = theseLayers.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + c_theseLayers[i2 + c_theseLayers.size(0) * i1] = theseLayers[i2 + + theseLayers.size(0) * (i + i1)]; + } + } + + thisSldLays.set_size(result, input_sizes_idx_1 + sizes_idx_1); + loop_ub = input_sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * i] = b_theseLayers[i1 + + result * i]; + } + } + + loop_ub = sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * (i + input_sizes_idx_1)] = + c_theseLayers[i1 + result * i]; + } + } + + if (theseLayers.size(0) != 0) { + result = theseLayers.size(0); + } else { + result = 0; + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + input_sizes_idx_1 = 1; + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + sizes_idx_1 = static_cast(theseLayers.size(1) - 2); + } else { + sizes_idx_1 = 0; + } + + d_theseLayers.set_size(theseLayers.size(0)); + loop_ub = theseLayers.size(0); + for (i = 0; i < loop_ub; i++) { + d_theseLayers[i] = theseLayers[i]; + } + + c_theseLayers.set_size(theseLayers.size(0), theseLayers.size(1) - 2); + loop_ub = theseLayers.size(1); + b_loop_ub = theseLayers.size(0); + for (i = 0; i <= loop_ub - 3; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + c_theseLayers[i1 + c_theseLayers.size(0) * i] = theseLayers[i1 + + theseLayers.size(0) * (i + 2)]; + } + } + + thisSldLaysIm.set_size(result, input_sizes_idx_1 + sizes_idx_1); + loop_ub = input_sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLaysIm[i1] = d_theseLayers[i1]; + } + } + + loop_ub = sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLaysIm[i1 + thisSldLaysIm.size(0) * (i + input_sizes_idx_1)] = + c_theseLayers[i1 + result * i]; + } + } + } else { + thisSldLays.set_size(theseLayers.size(0), theseLayers.size(1)); + loop_ub = theseLayers.size(1); + b_loop_ub = theseLayers.size(0); + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * i] = theseLayers[i1 + + theseLayers.size(0) * i]; + } + } + } + + makeSLDProfiles(nba, nbs, thisSldLays, *ssubs, repeatLayers, b_theseLayers); + sldProfile.set_size(b_theseLayers.size(0), 2); + loop_ub = b_theseLayers.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + sldProfile[i1 + sldProfile.size(0) * i] = b_theseLayers[i1 + + b_theseLayers.size(0) * i]; + } + } + + // If we have imaginary, we are also + // going to need an SLD profile for the imaginary part + if (useImaginary) { + // Note nba and nbs = 0 since there is never any imaginary part for + // the bulk phases.. + makeSLDProfiles(thisSldLaysIm, *ssubs, repeatLayers, b_theseLayers); + sldProfileIm.set_size(b_theseLayers.size(0), 2); + loop_ub = b_theseLayers.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + sldProfileIm[i1 + sldProfileIm.size(0) * i] = b_theseLayers[i1 + + b_theseLayers.size(0) * i]; + } + } + } + } else { + sldProfile.set_size(1, 2); + sldProfile[0] = 0.0; + sldProfile[sldProfile.size(0)] = 0.0; + } + + // If required, then resample the SLD + if (resample == 1.0) { + if (!useImaginary) { + resampleLayers(sldProfile, resamPars, layerSld); + } else { + resampleLayersReIm(sldProfile, sldProfileIm, resamPars, layerSld); + } + + resamLayers.set_size(layerSld.size(0), layerSld.size(1)); + loop_ub = layerSld.size(1); + b_loop_ub = layerSld.size(0); + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + resamLayers[i1 + resamLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } else { + resamLayers.set_size(1, 3); + resamLayers[0] = 0.0; + resamLayers[resamLayers.size(0)] = 0.0; + resamLayers[resamLayers.size(0) * 2] = 0.0; + } + + // Apply scale factors and q shifts to the data + b_data.set_size(data.size(0), data.size(1)); + loop_ub = data.size(1) - 1; + for (i = 0; i <= loop_ub; i++) { + b_loop_ub = data.size(0) - 1; + for (i1 = 0; i1 <= b_loop_ub; i1++) { + b_data[i1 + b_data.size(0) * i] = data[i1 + data.size(0) * i]; + } + } + + shiftData(sf, qshift, dataPresent, b_data, dataLimits, simLimits_data, + shifted_dat); + + // Calculate the reflectivity + callReflectivity(nba, nbs, simLimits_data, repeatLayers, shifted_dat, + layerSld, *ssubs, resol, useImaginary, reflect, Simul); + + // Apply background correction, either to the simulation or the data + applyBackgroundCorrection(reflect, Simul, shifted_dat, background, backsType); + + // Calculate chi squared. + *chiSq = chiSquared(shifted_dat, reflect, params); + } +} + +// End of code generation (standardTFLayersCore.cpp) diff --git a/RAT/standardTFLayersCore.h b/RAT/standardTFLayersCore.h new file mode 100644 index 00000000..75eb4694 --- /dev/null +++ b/RAT/standardTFLayersCore.h @@ -0,0 +1,48 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFLayersCore.h +// +// Code generation for function 'standardTFLayersCore' +// +#ifndef STANDARDTFLAYERSCORE_H +#define STANDARDTFLAYERSCORE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void b_standardTFLayersCore(const ::coder::array &contrastLayers, + real_T rough, const char_T geometry_data[], const int32_T geometry_size[2], + real_T nba, real_T nbs, real_T resample, real_T calcSld, real_T sf, real_T + qshift, real_T dataPresent, const ::coder::array &data, const + real_T dataLimits[2], const real_T simLimits_data[], const real_T + repeatLayers[2], real_T background, real_T resol, real_T backsType, real_T + params, const real_T resamPars[2], boolean_T useImaginary, ::coder::array< + real_T, 2U> &sldProfile, ::coder::array &reflect, ::coder::array< + real_T, 2U> &Simul, ::coder::array &shifted_dat, ::coder::array< + real_T, 2U> &theseLayers, ::coder::array &resamLayers, real_T + *chiSq, real_T *ssubs); + void standardTFLayersCore(const ::coder::array &contrastLayers, + real_T rough, const char_T geometry_data[], const int32_T geometry_size[2], + real_T nba, real_T nbs, real_T resample, real_T calcSld, real_T sf, real_T + qshift, real_T dataPresent, const ::coder::array &data, const + real_T dataLimits[2], const real_T simLimits_data[], const real_T + repeatLayers[2], real_T background, real_T resol, real_T backsType, real_T + params, const real_T resamPars[2], boolean_T useImaginary, ::coder::array< + real_T, 2U> &sldProfile, ::coder::array &reflect, ::coder::array< + real_T, 2U> &Simul, ::coder::array &shifted_dat, ::coder::array< + real_T, 2U> &theseLayers, ::coder::array &resamLayers, real_T + *chiSq, real_T *ssubs); +} + +#endif + +// End of code generation (standardTFLayersCore.h) diff --git a/RAT/standardTFReflectivityCalculation.cpp b/RAT/standardTFReflectivityCalculation.cpp new file mode 100644 index 00000000..7f212a51 --- /dev/null +++ b/RAT/standardTFReflectivityCalculation.cpp @@ -0,0 +1,151 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFReflectivityCalculation.cpp +// +// Code generation for function 'standardTFReflectivityCalculation' +// + +// Include files +#include "standardTFReflectivityCalculation.h" +#include "lower.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "standardTFCustomLayersReflectivityCalculation.h" +#include "standardTFCustomXYReflectivityCalculation.h" +#include "standardTFStandardLayersReflectivityCalculation.h" +#include "strcmp.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + void standardTFReflectivityCalculation(const struct0_T *problemDef, const + cell_19 *problemDefCells, const struct2_T *controls, struct4_T *problem, :: + coder::array &reflectivity, ::coder::array + &Simulation, ::coder::array &shifted_data, ::coder::array< + cell_wrap_15, 1U> &layerSlds, ::coder::array &sldProfiles, + ::coder::array &allLayers) + { + int32_T switch_expression_size[2]; + int32_T loop_ub_tmp; + char_T switch_expression_data[10000]; + + // Main function for the standardTF reflectivity calculation + // This function decides what type of model is being analysed and barnches + // to the correct one. The main options are: + // layers - This is the equivalent of Standard Layers in RasCAL + // Custom Layers - This is also a layers calculation, but the + // specification of the layers is dne using a user defined + // function. + // Custom XY - This also has a model described by a user supplied + // function, but in this case the function generates an + // SLD profile (i.e. XY function) rather than a list of + // layers. + // Find out the model type from the input structs + // Pre-allocate the output arrays.. this is necessary because otherwise + // the compiler complains with 'Output argument <....> is not assigned on + // some execution paths' error + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgrounds.set_size(loop_ub_tmp); + problem->qshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->nbairs.set_size(loop_ub_tmp); + problem->nbsubs.set_size(loop_ub_tmp); + problem->resolutions.set_size(loop_ub_tmp); + problem->calculations.all_chis.set_size(loop_ub_tmp); + problem->calculations.sum_chi = 0.0; + problem->allSubRough.set_size(loop_ub_tmp); + problem->resample.set_size(1, loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + Simulation.set_size(loop_ub_tmp); + shifted_data.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + sldProfiles.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgrounds[i] = 0.0; + problem->qshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->nbairs[i] = 0.0; + problem->nbsubs[i] = 0.0; + problem->resolutions[i] = 0.0; + problem->calculations.all_chis[i] = 0.0; + problem->allSubRough[i] = 0.0; + problem->resample[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + Simulation[i].f1.set_size(2, 2); + Simulation[i].f1[0] = 1.0; + Simulation[i].f1[1] = 1.0; + Simulation[i].f1[Simulation[i].f1.size(0)] = 1.0; + Simulation[i].f1[Simulation[i].f1.size(0) + 1] = 1.0; + shifted_data[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + sldProfiles[i].f1.set_size(2, 2); + sldProfiles[i].f1[0] = 1.0; + sldProfiles[i].f1[1] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; + allLayers[i].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i] = 1.0; + shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; + } + } + + coder::lower(problemDef->modelType.data, problemDef->modelType.size, + switch_expression_data, switch_expression_size); + if (coder::internal::c_strcmp(switch_expression_data, switch_expression_size)) + { + loop_ub_tmp = 0; + } else if (coder::internal::d_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 1; + } else if (coder::internal::e_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + // Standard layers calculation + standardTFStandardLayersReflectivityCalculation(problemDef, + problemDefCells, controls, problem, reflectivity, Simulation, + shifted_data, layerSlds, sldProfiles, allLayers); + break; + + case 1: + // Custom layers with user supplied custom model file + standardTFCustomLayersReflectivityCalculation(problemDef, problemDefCells, + controls, problem, reflectivity, Simulation, shifted_data, layerSlds, + sldProfiles, allLayers); + break; + + case 2: + // Custom SLD profile with user defined model file + standardTFCustomXYReflectivityCalculation(problemDef, problemDefCells, + controls, problem, reflectivity, Simulation, shifted_data, layerSlds, + sldProfiles, allLayers); + break; + } + } +} + +// End of code generation (standardTFReflectivityCalculation.cpp) diff --git a/RAT/standardTFReflectivityCalculation.h b/RAT/standardTFReflectivityCalculation.h new file mode 100644 index 00000000..80289017 --- /dev/null +++ b/RAT/standardTFReflectivityCalculation.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFReflectivityCalculation.h +// +// Code generation for function 'standardTFReflectivityCalculation' +// +#ifndef STANDARDTFREFLECTIVITYCALCULATION_H +#define STANDARDTFREFLECTIVITYCALCULATION_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFReflectivityCalculation(const struct0_T *problemDef, const + cell_19 *problemDefCells, const struct2_T *controls, struct4_T *problem, :: + coder::array &reflectivity, ::coder::array + &Simulation, ::coder::array &shifted_data, ::coder::array< + cell_wrap_15, 1U> &layerSlds, ::coder::array &sldProfiles, + ::coder::array &allLayers); +} + +#endif + +// End of code generation (standardTFReflectivityCalculation.h) diff --git a/RAT/standardTFStandardLayersParallelContrasts.cpp b/RAT/standardTFStandardLayersParallelContrasts.cpp new file mode 100644 index 00000000..b3aba987 --- /dev/null +++ b/RAT/standardTFStandardLayersParallelContrasts.cpp @@ -0,0 +1,241 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFStandardLayersParallelContrasts.cpp +// +// Code generation for function 'standardTFStandardLayersParallelContrasts' +// + +// Include files +#include "standardTFStandardLayersParallelContrasts.h" +#include "allocateLayersForContrast.h" +#include "allocateParamsToLayers.h" +#include "backSort.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "standardTFLayersCore.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + void standardTFStandardLayersParallelContrasts(const struct0_T *problemDef, + const cell_19 *problemDefCells, const struct2_T *controls, ::coder::array< + real_T, 1U> &outSsubs, ::coder::array &backgs, ::coder::array< + real_T, 1U> &qshifts, ::coder::array &sfs, ::coder::array &nbas, ::coder::array &nbss, ::coder::array + &resols, ::coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) + { + ::coder::array outParameterisedLayers; + ::coder::array Simul; + ::coder::array b_thisContrastLayers_data; + ::coder::array layerSld; + ::coder::array reflect; + ::coder::array resampledLayers; + ::coder::array shifted_dat; + ::coder::array sldProfile; + real_T thisContrastLayers_data[6000]; + real_T dv[2]; + real_T dv1[2]; + real_T calcSld; + real_T thisBackground; + real_T thisChiSquared; + real_T thisNba; + real_T thisNbs; + real_T thisQshift; + real_T thisResol; + real_T thisSf; + real_T thisSsubs; + int32_T thisContrastLayers_size[2]; + int32_T b_i; + int32_T b_loop_ub; + int32_T i1; + int32_T loop_ub; + int32_T nParams; + int32_T ub_loop; + boolean_T useImaginary; + + // Standard Layers calculation paralelised over the outer loop + // This is the main reflectivity calculation of the standard layers + // calculation type. It extracts the required paramters for the contrasts + // from the input arrays, then passes the main calculation to + // 'standardLayersCore', which carries out the calculation iteslf. + // The core calculation is common for both standard and custom layers. + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // The min input array 'problemDefCells' is a master array where + // all the cell arrays are grouped together. There are + // repeatLayers - controls repeating of the layers stack + // allData - Array of all the data arrays + // dataLimits - Min max limits in q for the data arrays + // simLimits - Limits in Q for the reflkectivity simulations + // Layers details - Master array of all available layers + // contrastLayers - Which specific combination of arrays are needed for + // each contrast. + // Custom files - Filenames and path for any custom files used + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + calcSld = controls->calcSld; + useImaginary = problemDef->useImaginary; + + // Allocate the memory for the output arrays before the main loop + backgs.set_size(static_cast(problemDef->numberOfContrasts)); + + // end memory allocation. + // First we need to allocate the absolute values of the input + // parameters to all the layers in the layers list. This only needs + // to be done once, and so is done outside the contrasts loop + allocateParamsToLayers(problemDef->params, problemDefCells->f6, + outParameterisedLayers); + + // Resample parameters if required + // Loop over all the contrasts + outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); + sldProfiles.set_size(static_cast(problemDef->numberOfContrasts)); + reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); + Simulation.set_size(static_cast(problemDef->numberOfContrasts)); + shifted_data.set_size(static_cast(problemDef->numberOfContrasts)); + layerSlds.set_size(static_cast(problemDef->numberOfContrasts)); + chis.set_size(static_cast(problemDef->numberOfContrasts)); + qshifts.set_size(static_cast(problemDef->numberOfContrasts)); + sfs.set_size(static_cast(problemDef->numberOfContrasts)); + nbas.set_size(static_cast(problemDef->numberOfContrasts)); + nbss.set_size(static_cast(problemDef->numberOfContrasts)); + resols.set_size(static_cast(problemDef->numberOfContrasts)); + allRoughs.set_size(static_cast(problemDef->numberOfContrasts)); + allLayers.set_size(static_cast(problemDef->numberOfContrasts)); + ub_loop = static_cast(problemDef->numberOfContrasts) - 1; + +#pragma omp parallel for \ + num_threads(omp_get_max_threads()) \ + private(sldProfile,reflect,Simul,shifted_dat,layerSld,resampledLayers,thisSsubs,thisChiSquared,thisContrastLayers_data,thisContrastLayers_size,thisResol,thisNbs,thisNba,thisSf,thisQshift,thisBackground,dv,dv1,loop_ub,b_i,b_loop_ub,i1) \ + firstprivate(b_thisContrastLayers_data) + + for (int32_T i = 0; i <= ub_loop; i++) { + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBacks[i], problemDef->contrastShifts[i], + problemDef->contrastScales[i], problemDef->contrastNbas[i], + problemDef->contrastNbss[i], problemDef->contrastRes[i], + problemDef->backs, problemDef->shifts, problemDef->sf, + problemDef->nba, problemDef->nbs, problemDef->res, + &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, + &thisResol); + + // Also need to determine which layers from the overall layers list + // are required for this contrast, and put them in the correct order + // according to geometry + allocateLayersForContrast(problemDefCells->f5[i].f1, + outParameterisedLayers, useImaginary, thisContrastLayers_data, + thisContrastLayers_size); + + // For the other parameters, we extract the correct ones from the input + // arrays + // Substrate roughness is always first parameter for standard layers + // Now call the core standardTF_stanlay reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the core layers calculation + b_thisContrastLayers_data.set(&thisContrastLayers_data[0], + thisContrastLayers_size[0], thisContrastLayers_size[1]); + dv[0] = problemDefCells->f3[i].f1[0]; + dv[1] = problemDefCells->f3[i].f1[1]; + dv1[0] = problemDefCells->f1[i].f1[0]; + dv1[1] = problemDefCells->f1[i].f1[1]; + standardTFLayersCore(b_thisContrastLayers_data, problemDef->params[0], + problemDef->geometry.data, problemDef->geometry.size, + thisNba, thisNbs, problemDef->resample[i], calcSld, + thisSf, thisQshift, problemDef->dataPresent[i], + problemDefCells->f2[i].f1, dv, (const real_T *)((:: + coder::array *)&problemDefCells->f4[i].f1)->data(), dv1, + thisBackground, thisResol, + problemDef->contrastBacksType[i], static_cast + (nParams), controls->resamPars, useImaginary, + sldProfile, reflect, Simul, shifted_dat, layerSld, + resampledLayers, &thisChiSquared, &thisSsubs); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + outSsubs[i] = thisSsubs; + loop_ub = sldProfile.size(1); + sldProfiles[i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = sldProfile.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + sldProfiles[i].f1[i1 + sldProfiles[i].f1.size(0) * b_i] = + sldProfile[i1 + sldProfile.size(0) * b_i]; + } + } + + loop_ub = reflect.size(0); + reflectivity[i].f1.set_size(reflect.size(0), 2); + b_loop_ub = Simul.size(0); + Simulation[i].f1.set_size(Simul.size(0), 2); + for (b_i = 0; b_i < 2; b_i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + reflectivity[i].f1[i1 + reflectivity[i].f1.size(0) * b_i] = reflect[i1 + + reflect.size(0) * b_i]; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + Simulation[i].f1[i1 + Simulation[i].f1.size(0) * b_i] = Simul[i1 + + Simul.size(0) * b_i]; + } + } + + loop_ub = shifted_dat.size(1); + shifted_data[i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = shifted_dat.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + shifted_data[i].f1[i1 + shifted_data[i].f1.size(0) * b_i] = + shifted_dat[i1 + shifted_dat.size(0) * b_i]; + } + } + + loop_ub = layerSld.size(1); + layerSlds[i].f1.set_size(layerSld.size(0), layerSld.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = layerSld.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + layerSlds[i].f1[i1 + layerSlds[i].f1.size(0) * b_i] = layerSld[i1 + + layerSld.size(0) * b_i]; + } + } + + chis[i] = thisChiSquared; + backgs[i] = thisBackground; + qshifts[i] = thisQshift; + sfs[i] = thisSf; + nbas[i] = thisNba; + nbss[i] = thisNbs; + resols[i] = thisResol; + allRoughs[i] = problemDef->params[0]; + loop_ub = resampledLayers.size(1); + allLayers[i].f1.set_size(resampledLayers.size(0), resampledLayers.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = resampledLayers.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + allLayers[i].f1[i1 + allLayers[i].f1.size(0) * b_i] = + resampledLayers[i1 + resampledLayers.size(0) * b_i]; + } + } + } + } +} + +// End of code generation (standardTFStandardLayersParallelContrasts.cpp) diff --git a/RAT/standardTFStandardLayersParallelContrasts.h b/RAT/standardTFStandardLayersParallelContrasts.h new file mode 100644 index 00000000..af0de32c --- /dev/null +++ b/RAT/standardTFStandardLayersParallelContrasts.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFStandardLayersParallelContrasts.h +// +// Code generation for function 'standardTFStandardLayersParallelContrasts' +// +#ifndef STANDARDTFSTANDARDLAYERSPARALLELCONTRASTS_H +#define STANDARDTFSTANDARDLAYERSPARALLELCONTRASTS_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFStandardLayersParallelContrasts(const struct0_T *problemDef, + const cell_19 *problemDefCells, const struct2_T *controls, ::coder::array< + real_T, 1U> &outSsubs, ::coder::array &backgs, ::coder::array< + real_T, 1U> &qshifts, ::coder::array &sfs, ::coder::array &nbas, ::coder::array &nbss, ::coder::array + &resols, ::coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); +} + +#endif + +// End of code generation (standardTFStandardLayersParallelContrasts.h) diff --git a/RAT/standardTFStandardLayersParallelPoints.cpp b/RAT/standardTFStandardLayersParallelPoints.cpp new file mode 100644 index 00000000..00aeb3da --- /dev/null +++ b/RAT/standardTFStandardLayersParallelPoints.cpp @@ -0,0 +1,204 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFStandardLayersParallelPoints.cpp +// +// Code generation for function 'standardTFStandardLayersParallelPoints' +// + +// Include files +#include "standardTFStandardLayersParallelPoints.h" +#include "allocateLayersForContrast.h" +#include "allocateParamsToLayers.h" +#include "backSort.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "standardTFLayersCore.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + void standardTFStandardLayersParallelPoints(const struct0_T *problemDef, const + cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) + { + ::coder::array outParameterisedLayers; + ::coder::array b_thisContrastLayers_data; + ::coder::array layerSld; + ::coder::array resampledLayers; + ::coder::array shifted_dat; + ::coder::array sldProfile; + real_T thisContrastLayers_data[6000]; + real_T thisBackground; + real_T thisNba; + real_T thisNbs; + real_T thisQshift; + real_T thisResol; + real_T thisSf; + int32_T i; + boolean_T useImaginary; + + // Standard Layers calculation paralelised over the inner loop + // This is the main reflectivity calculation of the standard layers + // calculation type. It extracts the required paramters for the contrasts + // from the input arrays, then passes the main calculation to + // 'standardLayersCore', which carries out the calculation iteslf. + // The core calculation is common for both standard and custom layers. + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // The min input array 'problemDefCells' is a master array where + // all the cell arrays are grouped together. There are + // repeatLayers - controls repeating of the layers stack + // allData - Array of all the data arrays + // dataLimits - Min max limits in q for the data arrays + // simLimits - Limits in Q for the reflkectivity simulations + // Layers details - Master array of all available layers + // contrastLayers - Which specific combination of arrays are needed for + // each contrast. + // Custom files - Filenames and path for any custom files used + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + useImaginary = problemDef->useImaginary; + + // Allocate the memory for the output arrays before the main loop + i = static_cast(problemDef->numberOfContrasts); + backgs.set_size(i); + + // end memory allocation. + // First we need to allocate the absolute values of the input + // parameters to all the layers in the layers list. This only needs + // to be done once, and so is done outside the contrasts loop + allocateParamsToLayers(problemDef->params, problemDefCells->f6, + outParameterisedLayers); + + // Resample params if requiired + // Loop over all the contrasts + outSsubs.set_size(i); + sldProfiles.set_size(i); + reflectivity.set_size(i); + Simulation.set_size(i); + shifted_data.set_size(i); + layerSlds.set_size(i); + chis.set_size(i); + qshifts.set_size(i); + sfs.set_size(i); + nbas.set_size(i); + nbss.set_size(i); + resols.set_size(i); + allRoughs.set_size(i); + allLayers.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T dv[2]; + real_T dv1[2]; + int32_T thisContrastLayers_size[2]; + int32_T b_loop_ub; + int32_T loop_ub; + + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], + problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], + problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], + problemDef->backs, problemDef->shifts, problemDef->sf, + problemDef->nba, problemDef->nbs, problemDef->res, + &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, + &thisResol); + + // Also need to determine which layers from the overall layers list + // are required for this contrast, and put them in the correct order + // according to geometry + allocateLayersForContrast(problemDefCells->f5[b_i].f1, + outParameterisedLayers, useImaginary, thisContrastLayers_data, + thisContrastLayers_size); + // For the other parameters, we extract the correct ones from the input + // arrays + // Substrate roughness is always first parameter for standard layers + // Now call the core standardTF_stanlay reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the core layers calculation + b_thisContrastLayers_data.set(&thisContrastLayers_data[0], + thisContrastLayers_size[0], thisContrastLayers_size[1]); + dv[0] = problemDefCells->f3[b_i].f1[0]; + dv[1] = problemDefCells->f3[b_i].f1[1]; + dv1[0] = problemDefCells->f1[b_i].f1[0]; + dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_standardTFLayersCore(b_thisContrastLayers_data, problemDef->params[0], + problemDef->geometry.data, problemDef->geometry.size, thisNba, thisNbs, + problemDef->resample[b_i], controls->calcSld, thisSf, thisQshift, + problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, dv, (const + real_T *)((::coder::array *)&problemDefCells->f4[b_i].f1) + ->data(), dv1, thisBackground, thisResol, problemDef-> + contrastBacksType[b_i], static_cast(problemDef->params.size(1)), + controls->resamPars, useImaginary, sldProfile, reflectivity[b_i].f1, + Simulation[b_i].f1, shifted_dat, layerSld, resampledLayers, &chis[b_i], + &outSsubs[b_i]); + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + loop_ub = sldProfile.size(1); + sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = sldProfile.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = + sldProfile[i2 + sldProfile.size(0) * i1]; + } + } + + loop_ub = shifted_dat.size(1); + shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shifted_dat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1] = + shifted_dat[i2 + shifted_dat.size(0) * i1]; + } + } + + loop_ub = layerSld.size(1); + layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = layerSld.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = layerSld[i2 + + layerSld.size(0) * i1]; + } + } + + backgs[b_i] = thisBackground; + qshifts[b_i] = thisQshift; + sfs[b_i] = thisSf; + nbas[b_i] = thisNba; + nbss[b_i] = thisNbs; + resols[b_i] = thisResol; + allRoughs[b_i] = problemDef->params[0]; + loop_ub = resampledLayers.size(1); + allLayers[b_i].f1.set_size(resampledLayers.size(0), resampledLayers.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = resampledLayers.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + resampledLayers[i2 + resampledLayers.size(0) * i1]; + } + } + } + } +} + +// End of code generation (standardTFStandardLayersParallelPoints.cpp) diff --git a/RAT/standardTFStandardLayersParallelPoints.h b/RAT/standardTFStandardLayersParallelPoints.h new file mode 100644 index 00000000..01a031aa --- /dev/null +++ b/RAT/standardTFStandardLayersParallelPoints.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFStandardLayersParallelPoints.h +// +// Code generation for function 'standardTFStandardLayersParallelPoints' +// +#ifndef STANDARDTFSTANDARDLAYERSPARALLELPOINTS_H +#define STANDARDTFSTANDARDLAYERSPARALLELPOINTS_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFStandardLayersParallelPoints(const struct0_T *problemDef, const + cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); +} + +#endif + +// End of code generation (standardTFStandardLayersParallelPoints.h) diff --git a/RAT/standardTFStandardLayersReflectivityCalculation.cpp b/RAT/standardTFStandardLayersReflectivityCalculation.cpp new file mode 100644 index 00000000..c6417f59 --- /dev/null +++ b/RAT/standardTFStandardLayersReflectivityCalculation.cpp @@ -0,0 +1,154 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFStandardLayersReflectivityCalculation.cpp +// +// Code generation for function 'standardTFStandardLayersReflectivityCalculation' +// + +// Include files +#include "standardTFStandardLayersReflectivityCalculation.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "standardTFStandardLayersParallelContrasts.h" +#include "standardTFStandardLayersParallelPoints.h" +#include "standardTFStandardLayersSingle.h" +#include "strcmp.h" +#include "sum.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + void standardTFStandardLayersReflectivityCalculation(const struct0_T + *problemDef, const cell_19 *problemDefCells, const struct2_T *controls, + struct4_T *problem, ::coder::array &reflectivity, ::coder:: + array &Simulation, ::coder::array + &shifted_data, ::coder::array &layerSlds, ::coder::array< + cell_wrap_15, 1U> &sldProfiles, ::coder::array &allLayers) + { + int32_T loop_ub_tmp; + + // Standard layers reflectivity calculation for standardTF + // This function decides on parallelisation options before calling the + // relevant version ofthe main standard layers calculation. Parallelisation + // is either over the outer loop ('contrasts'), or the inner loop + // ('points'). The easiest way to do this is to have multiple versions of + // the same core calculation, rather than trying to make the parallel + // for loops conditional (although that would be much neater) There are: + // points - parallelise over points in the reflectivity calculation + // contrasts - parallelise over contrasts (outer for loop) + // Pre-allocation - It's necessary to + // pre-define the types for all the arrays + // for compilation, so do this in this block. + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgrounds.set_size(loop_ub_tmp); + problem->qshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->nbairs.set_size(loop_ub_tmp); + problem->nbsubs.set_size(loop_ub_tmp); + problem->calculations.all_chis.set_size(loop_ub_tmp); + problem->resolutions.set_size(loop_ub_tmp); + problem->allSubRough.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + Simulation.set_size(loop_ub_tmp); + shifted_data.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + sldProfiles.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgrounds[i] = 0.0; + problem->qshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->nbairs[i] = 0.0; + problem->nbsubs[i] = 0.0; + problem->calculations.all_chis[i] = 0.0; + problem->resolutions[i] = 0.0; + problem->allSubRough[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + Simulation[i].f1.set_size(2, 2); + Simulation[i].f1[0] = 1.0; + Simulation[i].f1[1] = 1.0; + Simulation[i].f1[Simulation[i].f1.size(0)] = 1.0; + Simulation[i].f1[Simulation[i].f1.size(0) + 1] = 1.0; + shifted_data[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + sldProfiles[i].f1.set_size(2, 2); + sldProfiles[i].f1[0] = 1.0; + sldProfiles[i].f1[1] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; + allLayers[i].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i] = 1.0; + shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; + } + } + + // ------- End type definitions ------------- + if (coder::internal::f_strcmp(controls->para.data, controls->para.size)) { + loop_ub_tmp = 0; + } else if (coder::internal::g_strcmp(controls->para.data, + controls->para.size)) { + loop_ub_tmp = 1; + } else if (coder::internal::h_strcmp(controls->para.data, + controls->para.size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + standardTFStandardLayersSingle(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgrounds, problem->qshifts, + problem->scalefactors, problem->nbairs, problem->nbsubs, + problem->resolutions, problem->calculations.all_chis, reflectivity, + Simulation, shifted_data, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + + case 1: + standardTFStandardLayersParallelPoints(problemDef, problemDefCells, + controls, problem->ssubs, problem->backgrounds, problem->qshifts, + problem->scalefactors, problem->nbairs, problem->nbsubs, + problem->resolutions, problem->calculations.all_chis, reflectivity, + Simulation, shifted_data, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + + case 2: + standardTFStandardLayersParallelContrasts(problemDef, problemDefCells, + controls, problem->ssubs, problem->backgrounds, problem->qshifts, + problem->scalefactors, problem->nbairs, problem->nbsubs, + problem->resolutions, problem->calculations.all_chis, reflectivity, + Simulation, shifted_data, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + } + + // Package everything into one array for tidy output + problem->calculations.sum_chi = coder::sum(problem->calculations.all_chis); + problem->resample.set_size(1, problemDef->resample.size(1)); + loop_ub_tmp = problemDef->resample.size(1); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + problem->resample[b_i] = problemDef->resample[b_i]; + } + } +} + +// End of code generation (standardTFStandardLayersReflectivityCalculation.cpp) diff --git a/RAT/standardTFStandardLayersReflectivityCalculation.h b/RAT/standardTFStandardLayersReflectivityCalculation.h new file mode 100644 index 00000000..6cd3a8b2 --- /dev/null +++ b/RAT/standardTFStandardLayersReflectivityCalculation.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFStandardLayersReflectivityCalculation.h +// +// Code generation for function 'standardTFStandardLayersReflectivityCalculation' +// +#ifndef STANDARDTFSTANDARDLAYERSREFLECTIVITYCALCULATION_H +#define STANDARDTFSTANDARDLAYERSREFLECTIVITYCALCULATION_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFStandardLayersReflectivityCalculation(const struct0_T + *problemDef, const cell_19 *problemDefCells, const struct2_T *controls, + struct4_T *problem, ::coder::array &reflectivity, ::coder:: + array &Simulation, ::coder::array + &shifted_data, ::coder::array &layerSlds, ::coder::array< + cell_wrap_15, 1U> &sldProfiles, ::coder::array &allLayers); +} + +#endif + +// End of code generation (standardTFStandardLayersReflectivityCalculation.h) diff --git a/RAT/standardTFStandardLayersSingle.cpp b/RAT/standardTFStandardLayersSingle.cpp new file mode 100644 index 00000000..107a7949 --- /dev/null +++ b/RAT/standardTFStandardLayersSingle.cpp @@ -0,0 +1,208 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFStandardLayersSingle.cpp +// +// Code generation for function 'standardTFStandardLayersSingle' +// + +// Include files +#include "standardTFStandardLayersSingle.h" +#include "allocateLayersForContrast.h" +#include "allocateParamsToLayers.h" +#include "backSort.h" +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "standardTFLayersCore.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + void standardTFStandardLayersSingle(const struct0_T *problemDef, const cell_19 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) + { + ::coder::array outParameterisedLayers; + ::coder::array b_thisContrastLayers_data; + ::coder::array layerSld; + ::coder::array resampledLayers; + ::coder::array shifted_dat; + ::coder::array sldProfile; + real_T thisContrastLayers_data[6000]; + real_T thisBackground; + real_T thisNba; + real_T thisNbs; + real_T thisQshift; + real_T thisResol; + real_T thisSf; + int32_T i; + boolean_T useImaginary; + + // Single theraded version of the Standard Layers calculation + // This is the main reflectivity calculation of the standard layers + // calculation type. It extracts the required paramters for the contrasts + // from the input arrays, then passes the main calculation to + // 'standardLayersCore', which carries out the calculation iteslf. + // The core calculation is common for both standard and custom layers. + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // The min input array 'problemDefCells' is a master array where + // all the cell arrays are grouped together. There are + // repeatLayers - controls repeating of the layers stack + // allData - Array of all the data arrays + // dataLimits - Min max limits in q for the data arrays + // simLimits - Limits in Q for the reflkectivity simulations + // Layers details - Master array of all available layers + // contrastLayers - Which specific combination of arrays are needed for + // each contrast. + // Custom files - Filenames and path for any custom files used + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + useImaginary = problemDef->useImaginary; + + // Allocate the memory for the output arrays before the main loop + i = static_cast(problemDef->numberOfContrasts); + backgs.set_size(i); + + // end memory allocation. + // First we need to allocate the absolute values of the input + // parameters to all the layers in the layers list. This only needs + // to be done once, and so is done outside the contrasts loop + allocateParamsToLayers(problemDef->params, problemDefCells->f6, + outParameterisedLayers); + + // Resample params if requiired + // Loop over all the contrasts + outSsubs.set_size(i); + sldProfiles.set_size(i); + reflectivity.set_size(i); + Simulation.set_size(i); + shifted_data.set_size(i); + layerSlds.set_size(i); + chis.set_size(i); + qshifts.set_size(i); + sfs.set_size(i); + nbas.set_size(i); + nbss.set_size(i); + resols.set_size(i); + allRoughs.set_size(i); + allLayers.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T dv[2]; + real_T dv1[2]; + int32_T thisContrastLayers_size[2]; + int32_T b_loop_ub; + int32_T loop_ub; + + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], + problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], + problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], + problemDef->backs, problemDef->shifts, problemDef->sf, + problemDef->nba, problemDef->nbs, problemDef->res, + &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, + &thisResol); + + // Also need to determine which layers from the overall layers list + // are required for this contrast, and put them in the correct order + // according to geometry + allocateLayersForContrast(problemDefCells->f5[b_i].f1, + outParameterisedLayers, useImaginary, thisContrastLayers_data, + thisContrastLayers_size); + + // For the other parameters, we extract the correct ones from the input + // arrays + // Substrate roughness is always first parameter for standard layers + // Now call the core standardTF_stanlay reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the core layers calculation + b_thisContrastLayers_data.set(&thisContrastLayers_data[0], + thisContrastLayers_size[0], thisContrastLayers_size[1]); + dv[0] = problemDefCells->f3[b_i].f1[0]; + dv[1] = problemDefCells->f3[b_i].f1[1]; + dv1[0] = problemDefCells->f1[b_i].f1[0]; + dv1[1] = problemDefCells->f1[b_i].f1[1]; + standardTFLayersCore(b_thisContrastLayers_data, problemDef->params[0], + problemDef->geometry.data, problemDef->geometry.size, + thisNba, thisNbs, problemDef->resample[b_i], + controls->calcSld, thisSf, thisQshift, + problemDef->dataPresent[b_i], problemDefCells->f2[b_i] + .f1, dv, (const real_T *)((::coder::array + *)&problemDefCells->f4[b_i].f1)->data(), dv1, thisBackground, thisResol, + problemDef->contrastBacksType[b_i], + static_cast(problemDef->params.size(1)), + controls->resamPars, useImaginary, sldProfile, + reflectivity[b_i].f1, Simulation[b_i].f1, shifted_dat, + layerSld, resampledLayers, &chis[b_i], &outSsubs[b_i]); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + loop_ub = sldProfile.size(1); + sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = sldProfile.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = + sldProfile[i2 + sldProfile.size(0) * i1]; + } + } + + loop_ub = shifted_dat.size(1); + shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shifted_dat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1] = + shifted_dat[i2 + shifted_dat.size(0) * i1]; + } + } + + loop_ub = layerSld.size(1); + layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = layerSld.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = layerSld[i2 + + layerSld.size(0) * i1]; + } + } + + backgs[b_i] = thisBackground; + qshifts[b_i] = thisQshift; + sfs[b_i] = thisSf; + nbas[b_i] = thisNba; + nbss[b_i] = thisNbs; + resols[b_i] = thisResol; + allRoughs[b_i] = problemDef->params[0]; + loop_ub = resampledLayers.size(1); + allLayers[b_i].f1.set_size(resampledLayers.size(0), resampledLayers.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = resampledLayers.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + resampledLayers[i2 + resampledLayers.size(0) * i1]; + } + } + } + } +} + +// End of code generation (standardTFStandardLayersSingle.cpp) diff --git a/RAT/standardTFStandardLayersSingle.h b/RAT/standardTFStandardLayersSingle.h new file mode 100644 index 00000000..366b5869 --- /dev/null +++ b/RAT/standardTFStandardLayersSingle.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// standardTFStandardLayersSingle.h +// +// Code generation for function 'standardTFStandardLayersSingle' +// +#ifndef STANDARDTFSTANDARDLAYERSSINGLE_H +#define STANDARDTFSTANDARDLAYERSSINGLE_H + +// Include files +#include "reflectivityCalculation_internal_types.h" +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void standardTFStandardLayersSingle(const struct0_T *problemDef, const cell_19 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgs, ::coder::array + &qshifts, ::coder::array &sfs, ::coder::array &nbas, + ::coder::array &nbss, ::coder::array &resols, :: + coder::array &chis, ::coder::array + &reflectivity, ::coder::array &Simulation, ::coder::array< + cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); +} + +#endif + +// End of code generation (standardTFStandardLayersSingle.h) diff --git a/RAT/strcmp.cpp b/RAT/strcmp.cpp new file mode 100644 index 00000000..73e719e1 --- /dev/null +++ b/RAT/strcmp.cpp @@ -0,0 +1,341 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// strcmp.cpp +// +// Code generation for function 'strcmp' +// + +// Include files +#include "strcmp.h" +#include "reflectivityCalculation_data.h" +#include "rt_nonfinite.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T b_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[13]{ 'n', 'o', 'n', ' ', 'p', 'o', 'l', 'a', + 'r', 'i', 's', 'e', 'd' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 13) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 13) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T c_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[15]{ 's', 't', 'a', 'n', 'd', 'a', 'r', 'd', + ' ', 'l', 'a', 'y', 'e', 'r', 's' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 15) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 15) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T d_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[13]{ 'c', 'u', 's', 't', 'o', 'm', ' ', 'l', + 'a', 'y', 'e', 'r', 's' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 13) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 13) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T e_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[9]{ 'c', 'u', 's', 't', 'o', 'm', ' ', 'x', 'y' + }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 9) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 9) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T f_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[6]{ 's', 'i', 'n', 'g', 'l', 'e' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 6) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 6) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T g_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[6]{ 'p', 'o', 'i', 'n', 't', 's' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 6) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 6) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T h_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[9]{ 'c', 'o', 'n', 't', 'r', 'a', 's', 't', 's' + }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 9) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 9) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T i_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[13]{ 'a', 'i', 'r', '/', 's', 'u', 'b', 's', + 't', 'r', 'a', 't', 'e' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 13) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 13) { + if (cv[static_cast(a_data[kstr]) & 127] != cv[ + static_cast(b_cv[kstr])]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T j_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[6]{ 'm', 'a', 't', 'l', 'a', 'b' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 6) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 6) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T k_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[3]{ 'c', 'p', 'p' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 3) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 3) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T l_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[6]{ 'p', 'y', 't', 'h', 'o', 'n' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 6) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 6) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + } + } +} + +// End of code generation (strcmp.cpp) diff --git a/RAT/strcmp.h b/RAT/strcmp.h new file mode 100644 index 00000000..24cf38a0 --- /dev/null +++ b/RAT/strcmp.h @@ -0,0 +1,42 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// strcmp.h +// +// Code generation for function 'strcmp' +// +#ifndef STRCMP_H +#define STRCMP_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T b_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T c_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T d_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T e_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T f_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T g_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T h_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T i_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T j_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T k_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T l_strcmp(const char_T a_data[], const int32_T a_size[2]); + } + } +} + +#endif + +// End of code generation (strcmp.h) diff --git a/RAT/sum.cpp b/RAT/sum.cpp new file mode 100644 index 00000000..677accac --- /dev/null +++ b/RAT/sum.cpp @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sum.cpp +// +// Code generation for function 'sum' +// + +// Include files +#include "sum.h" +#include "blockedSummation.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + real_T sum(const ::coder::array &x) + { + real_T y; + if (x.size(0) == 0) { + y = 0.0; + } else { + y = nestedIter(x, x.size(0)); + } + + return y; + } + } +} + +// End of code generation (sum.cpp) diff --git a/RAT/sum.h b/RAT/sum.h new file mode 100644 index 00000000..68b8481d --- /dev/null +++ b/RAT/sum.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sum.h +// +// Code generation for function 'sum' +// +#ifndef SUM_H +#define SUM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + real_T sum(const ::coder::array &x); + } +} + +#endif + +// End of code generation (sum.h) diff --git a/RAT/tmwtypes.h b/RAT/tmwtypes.h new file mode 100644 index 00000000..e7f52fc3 --- /dev/null +++ b/RAT/tmwtypes.h @@ -0,0 +1,888 @@ +/* + * Copyright 1984-2018 The MathWorks, Inc. + */ + +#if defined(_MSC_VER) +# pragma once +#endif +#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)) +# pragma once +#endif + +#ifndef tmwtypes_h +#define tmwtypes_h + +#ifndef __TMWTYPES__ +#define __TMWTYPES__ +/* + * File : tmwtypes.h + * Abstract: + * Data types for use with MATLAB/SIMULINK and the Real-Time Workshop. + * + * When compiling stand-alone model code, data types can be overridden + * via compiler switches. + * + * Define NO_FLOATS to eliminate reference to real_T, etc. + */ + +#ifdef MW_LIBTOOLING +#include "mwstdint.h" +#endif + +#include + +/* __STDC_VERSION__ version check below means "check for a C99 compiler". + + Visual Studio (checked on versions 2015 and 2017) does + not define __STDC_VERSION__, however it has stdbool.h available, + thus a separate check for _MSC_VER below. + */ +#if defined(__APPLE_CC__) \ + || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) \ + || (defined(_MSC_VER) && (_MSC_VER >= 1900)) +#ifndef tmwtypes_do_not_include_stdbool +#include +#endif +#endif + +#define LOGICAL_IS_A_TYPE +#define SPARSE_GENERALIZATION + +#ifdef NO_FLOATS +# define double double_not_allowed +# define float float_not_allowed +#endif /*NO_FLOATS*/ + +#ifndef NO_FLOATS + +#ifndef __MWERKS__ +# ifdef __STDC__ +# include +# else +# ifndef FLT_MANT_DIG +# define FLT_MANT_DIG 24 +# endif +# ifndef DBL_MANT_DIG +# define DBL_MANT_DIG 53 +# endif +# endif +#endif + +#endif /*NO_FLOATS*/ + +/* + * The following data types cannot be overridden when building MEX files. + */ +#ifdef MATLAB_MEX_FILE +# undef CHARACTER_T +# undef INTEGER_T +# undef BOOLEAN_T +# undef REAL_T +# undef TIME_T +#endif + +/* + * The uchar_T, ushort_T and ulong_T types are needed for compilers which do + * not allow defines to be specified, at the command line, with spaces in them. + */ + +typedef unsigned char uchar_T; +typedef unsigned short ushort_T; +typedef unsigned long ulong_T; + +#if (defined(_MSC_VER) && _MSC_VER >= 1500) \ + || defined(__x86_64__) || defined(__LP64__) \ + || defined(__LCC64__) + +typedef unsigned long long ulonglong_T; +#endif + + + +/*=======================================================================* + * Fixed width word size data types: * + * int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers * + * uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers * + * real32_T, real64_T - 32 and 64 bit floating point numbers * + *=======================================================================*/ + +/* When used with Real Time Workshop generated code, this + * header file can be used with a variety of compilers. + * + * The compiler could be for an 8 bit embedded processor that + * only had 8 bits per integer and 16 bits per long. + * In that example, a 32 bit integer size is not even available. + * This header file should be robust to that. + * + * For the case of an 8 bit processor, the preprocessor + * may be limited to 16 bit math like its target. That limitation + * would mean that 32 bit comparisons can't be done accurately. + * To increase robustness to this, comparisons are done against + * smaller values first. An inaccurate 32 bit comparison isn't + * attempted if the 16 bit comparison has already succeeded. + * + * Limitations on preprocessor math can also be stricter than + * for the target. There are known cases where a compiler + * targeting processors with 64 bit longs can't do accurate + * preprocessor comparisons on more than 32 bits. + */ + +/* Determine the number of bits for int, long, short, and char. + * If one fails to be determined, set the number of bits to -1 + */ + +#ifndef TMW_BITS_PER_INT +# if INT_MAX == 0x7FL +# define TMW_BITS_PER_INT 8 +# elif INT_MAX == 0x7FFFL +# define TMW_BITS_PER_INT 16 +# elif INT_MAX == 0x7FFFFFFFL +# define TMW_BITS_PER_INT 32 +# else +# define TMW_BITS_PER_INT -1 +# endif +#endif + +#ifndef TMW_BITS_PER_LONG +# if LONG_MAX == 0x7FL +# define TMW_BITS_PER_LONG 8 +# elif LONG_MAX == 0x7FFFL +# define TMW_BITS_PER_LONG 16 +# elif LONG_MAX == 0x7FFFFFFFL +# define TMW_BITS_PER_LONG 32 +# else +# define TMW_BITS_PER_LONG -1 +# endif +#endif + +#ifndef TMW_BITS_PER_SHRT +# if SHRT_MAX == 0x7FL +# define TMW_BITS_PER_SHRT 8 +# elif SHRT_MAX == 0x7FFFL +# define TMW_BITS_PER_SHRT 16 +# elif SHRT_MAX == 0x7FFFFFFFL +# define TMW_BITS_PER_SHRT 32 +# else +# define TMW_BITS_PER_SHRT -1 +# endif +#endif + +#ifndef TMW_BITS_PER_SCHAR +# if SCHAR_MAX == 0x7FL +# define TMW_BITS_PER_SCHAR 8 +# elif SCHAR_MAX == 0x7FFFL +# define TMW_BITS_PER_SCHAR 16 +# elif SCHAR_MAX == 0x7FFFFFFFL +# define TMW_BITS_PER_SCHAR 32 +# else +# define TMW_BITS_PER_SCHAR -1 +# endif +#endif + +#ifndef TMW_CHAR_SIGNED +# if SCHAR_MAX == CHAR_MAX +# define TMW_CHAR_SIGNED 1 +# else +# define TMW_CHAR_SIGNED 0 +# endif +#endif + +/* It is common for one or more of the integer types + * to be the same size. For example, on many embedded + * processors, both shorts and ints are 16 bits. On + * processors used for workstations, it is quite common + * for both int and long to be 32 bits. + * When there is more than one choice for typdef'ing + * a portable type like int16_T or uint32_T, in + * concept, it should not matter which choice is made. + * However, some style guides and some code checking + * tools do identify and complain about seemingly + * irrelevant differences. For example, a code + * checking tool may complain about an implicit + * conversion from int to short even though both + * are 16 bits. To reduce these types of + * complaints, it is best to make int the + * preferred choice when more than one is available. + */ + +#ifndef INT8_T +# if defined(MW_LIBTOOLING) +# define INT8_T int8_t +# elif TMW_BITS_PER_INT == 8 +# define INT8_T int +# elif TMW_BITS_PER_LONG == 8 +# define INT8_T long +# elif TMW_BITS_PER_SCHAR == 8 +# define INT8_T signed char +# elif TMW_BITS_PER_SHRT == 8 +# define INT8_T short +# endif +#endif +#ifdef INT8_T + typedef INT8_T int8_T; +#endif + +#ifndef UINT8_T +# if defined(MW_LIBTOOLING) +# define UINT8_T uint8_t +# elif TMW_BITS_PER_INT == 8 +# define UINT8_T unsigned int +# elif TMW_BITS_PER_LONG == 8 +# define UINT8_T unsigned long +# elif TMW_BITS_PER_SCHAR == 8 +# define UINT8_T unsigned char +# elif TMW_BITS_PER_SHRT == 8 +# define UINT8_T unsigned short +# endif +#endif +#ifdef UINT8_T + typedef UINT8_T uint8_T; +#endif + + +#ifndef INT16_T +# if defined(MW_LIBTOOLING) +# define INT16_T int16_t +# elif TMW_BITS_PER_INT == 16 +# define INT16_T int +# elif TMW_BITS_PER_LONG == 16 +# define INT16_T long +# elif TMW_BITS_PER_SCHAR == 16 +# define INT16_T signed char +# elif TMW_BITS_PER_SHRT == 16 +# define INT16_T short +# endif +#endif +#ifdef INT16_T + typedef INT16_T int16_T; +#endif + + +#ifndef UINT16_T +# if defined(MW_LIBTOOLING) +# define UINT16_T uint16_t +# elif TMW_BITS_PER_INT == 16 +# define UINT16_T unsigned int +# elif TMW_BITS_PER_LONG == 16 +# define UINT16_T unsigned long +# elif TMW_BITS_PER_SCHAR == 16 +# define UINT16_T unsigned char +# elif TMW_BITS_PER_SHRT == 16 +# define UINT16_T unsigned short +# endif +#endif +#ifdef UINT16_T + typedef UINT16_T uint16_T; +#endif + + +#ifndef INT32_T +# if defined(MW_LIBTOOLING) +# define INT32_T int32_t +# elif TMW_BITS_PER_INT == 32 +# define INT32_T int +# elif TMW_BITS_PER_LONG == 32 +# define INT32_T long +# elif TMW_BITS_PER_SCHAR == 32 +# define INT32_T signed char +# elif TMW_BITS_PER_SHRT == 32 +# define INT32_T short +# endif +#endif +#ifdef INT32_T + typedef INT32_T int32_T; +#endif + + +#ifndef UINT32_T +# if defined(MW_LIBTOOLING) +# define UINT32_T uint32_t +# elif TMW_BITS_PER_INT == 32 +# define UINT32_T unsigned int +# elif TMW_BITS_PER_LONG == 32 +# define UINT32_T unsigned long +# elif TMW_BITS_PER_SCHAR == 32 +# define UINT32_T unsigned char +# elif TMW_BITS_PER_SHRT == 32 +# define UINT32_T unsigned short +# endif +#endif +#ifdef UINT32_T + typedef UINT32_T uint32_T; +#endif + +/* The following is used to emulate smaller integer types when only + * larger types are available. For example, compilers for TI C3x/C4x DSPs + * define char and short to be 32 bits, so 8 and 16 bits are not directly + * available. This target is commonly used with RTW rapid prototyping. + * Other DSPs define char to be 16 bits, so 8 bits is not directly + * available. + */ +#ifndef INT8_T +# ifdef INT16_T +# define INT8_T INT16_T + typedef INT8_T int8_T; +# else +# ifdef INT32_T +# define INT8_T INT32_T + typedef INT8_T int8_T; +# endif +# endif +#endif + +#ifndef UINT8_T +# ifdef UINT16_T +# define UINT8_T UINT16_T + typedef UINT8_T uint8_T; +# else +# ifdef UINT32_T +# define UINT8_T UINT32_T + typedef UINT8_T uint8_T; +# endif +# endif +#endif + +#ifndef INT16_T +# ifdef INT32_T +# define INT16_T INT32_T + typedef INT16_T int16_T; +# endif +#endif + +#ifndef UINT16_T +# ifdef UINT32_T +# define UINT16_T UINT32_T + typedef UINT16_T uint16_T; +# endif +#endif + + +#ifndef NO_FLOATS + +#ifndef REAL32_T +# ifndef __MWERKS__ +# if FLT_MANT_DIG >= 23 +# define REAL32_T float +# endif +# else +# define REAL32_T float +# endif +#endif +#ifdef REAL32_T + typedef REAL32_T real32_T; +#endif + + +#ifndef REAL64_T +# ifndef __MWERKS__ +# if DBL_MANT_DIG >= 52 +# define REAL64_T double +# endif +# else +# define REAL64_T double +# endif +#endif +#ifdef REAL64_T + typedef REAL64_T real64_T; +#endif + +#endif /* NO_FLOATS*/ + +/*=======================================================================* + * Fixed width word size data types: * + * int64_T - signed 64 bit integers * + * uint64_T - unsigned 64 bit integers * + *=======================================================================*/ + +# if defined(MW_LIBTOOLING) +# ifdef INT64_T +# undef INT64_T +# endif +# define INT64_T int64_t +# ifdef UINT64_T +# undef UINT64_T +# endif +# define UINT64_T uint64_t +# endif +#if !defined(INT64_T) || !defined(UINT64_T) || !defined(FMT64) +# if defined(__APPLE__) || defined(__clang__) +# ifndef INT64_T +# define INT64_T long long +# endif +# ifndef UINT64_T +# define UINT64_T unsigned long long +# endif +# ifndef FMT64 +# define FMT64 "ll" +# endif +# if defined(__LP64__) && !defined(INT_TYPE_64_IS_LONG) +# define INT_TYPE_64_IS_LONG +# endif +# elif (defined(__x86_64__) || defined(__LP64__))&& !defined(__MINGW64__) +# ifndef INT64_T +# define INT64_T long +# endif +# ifndef UINT64_T +# define UINT64_T unsigned long +# endif +# ifndef FMT64 +# define FMT64 "l" +# endif +# if !defined(INT_TYPE_64_IS_LONG) +# define INT_TYPE_64_IS_LONG +# endif +# elif defined(_MSC_VER) || (defined(__BORLANDC__) && __BORLANDC__ >= 0x530) \ + || (defined(__WATCOMC__) && __WATCOMC__ >= 1100) +# ifndef INT64_T +# define INT64_T __int64 +# endif +# ifndef UINT64_T +# define UINT64_T unsigned __int64 +# endif +# ifndef FMT64 +# define FMT64 "I64" +# endif +# elif defined(__GNUC__) || defined(TMW_ENABLE_INT64) \ + || defined(__LCC64__) +# ifndef INT64_T +# define INT64_T long long +# endif +# ifndef UINT64_T +# define UINT64_T unsigned long long +# endif +# ifndef FMT64 +# define FMT64 "ll" +# endif +# endif + +#endif + +#if defined(INT64_T) +# if defined(__GNUC__) && \ + ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >=9))) + __extension__ +# endif + typedef INT64_T int64_T; +#endif + +#if defined(_WIN64) || (defined(__APPLE__) && defined(__LP64__)) \ + || defined(__x86_64__) \ + || defined(__LP64__) +# define INT_TYPE_64_IS_SUPPORTED +#endif + +#if defined(UINT64_T) +# if defined(__GNUC__) && \ + ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >=9))) + __extension__ +# endif + typedef UINT64_T uint64_T; +#endif + +/*===========================================================================* + * Format string modifiers for using size_t variables in printf statements. * + *===========================================================================*/ + +#ifndef FMT_SIZE_T +# if (defined( __GNUC__ ) || defined(_STDC_C99))&& !defined(__MINGW64__) +# define FMT_SIZE_T "z" +# elif defined (__WATCOMC__) +# define FMT_SIZE_T "l" +# elif defined (_WIN32 ) +# define FMT_SIZE_T "I" +# else +# define FMT_SIZE_T "l" +# endif +#endif + +#ifndef FMT_PTRDIFF_T +# if defined(__APPLE__) +# define FMT_PTRDIFF_T "l" +# elif defined( __GNUC__ ) || defined(_STDC_C99) +# define FMT_PTRDIFF_T "t" +# elif defined (__WATCOMC__) +# define FMT_PTRDIFF_T "l" +# elif defined (_WIN32 ) +# define FMT_PTRDIFF_T "I" +# else +# define FMT_PTRDIFF_T "l" +# endif +#endif + +/*===========================================================================* + * General or logical data types where the word size is not guaranteed. * + * real_T - possible settings include real32_T or real64_T * + * time_T - possible settings include real32_T or real64_T * + * boolean_T * + * char_T * + * int_T * + * uint_T * + * byte_T * + *===========================================================================*/ + +#ifndef NO_FLOATS + +#ifndef REAL_T +# ifdef REAL64_T +# define REAL_T real64_T +# else +# ifdef REAL32_T +# define REAL_T real32_T +# endif +# endif +#endif +#ifdef REAL_T + typedef REAL_T real_T; +#endif + +#ifndef TIME_T +# ifdef REAL_T +# define TIME_T real_T +# endif +#endif +#ifdef TIME_T + typedef TIME_T time_T; +#endif + +#endif /* NO_FLOATS */ + +#ifndef BOOLEAN_T +# if defined(UINT8_T) +# define BOOLEAN_T UINT8_T +# else +# define BOOLEAN_T unsigned int +# endif +#endif +typedef BOOLEAN_T boolean_T; + + +#ifndef CHARACTER_T +# define CHARACTER_T char +#endif +typedef CHARACTER_T char_T; + + +#ifndef INTEGER_T +# define INTEGER_T int +#endif +typedef INTEGER_T int_T; + + +#ifndef UINTEGER_T +# define UINTEGER_T unsigned +#endif +typedef UINTEGER_T uint_T; + + +#ifndef BYTE_T +# define BYTE_T unsigned char +#endif +typedef BYTE_T byte_T; + + +/*===========================================================================* + * Define Complex Structures * + *===========================================================================*/ +#ifndef NO_FLOATS + +#ifndef CREAL32_T +# ifdef REAL32_T + typedef struct { + real32_T re, im; + } creal32_T; +# define CREAL32_T creal32_T +# endif +#endif + +#ifndef CREAL64_T +# ifdef REAL64_T + typedef struct { + real64_T re, im; + } creal64_T; +# define CREAL64_T creal64_T +# endif +#endif + +#ifndef CREAL_T +# ifdef REAL_T + typedef struct { + real_T re, im; + } creal_T; +# define CREAL_T creal_T +# endif +#endif + +#endif /* NO_FLOATS */ + +#ifndef CINT8_T +# ifdef INT8_T + typedef struct { + int8_T re, im; + } cint8_T; +# define CINT8_T cint8_T +# endif +#endif + +#ifndef CUINT8_T +# ifdef UINT8_T + typedef struct { + uint8_T re, im; + } cuint8_T; +# define CUINT8_T cuint8_T +# endif +#endif + +#ifndef CINT16_T +# ifdef INT16_T + typedef struct { + int16_T re, im; + } cint16_T; +# define CINT16_T cint16_T +# endif +#endif + +#ifndef CUINT16_T +# ifdef UINT16_T + typedef struct { + uint16_T re, im; + } cuint16_T; +# define CUINT16_T cuint16_T +# endif +#endif + +#ifndef CINT32_T +# ifdef INT32_T + typedef struct { + int32_T re, im; + } cint32_T; +# define CINT32_T cint32_T +# endif +#endif + +#ifndef CUINT32_T +# ifdef UINT32_T + typedef struct { + uint32_T re, im; + } cuint32_T; +# define CUINT32_T cuint32_T +# endif +#endif + +#ifndef CINT64_T +# ifdef INT64_T + typedef struct { + int64_T re, im; + } cint64_T; +# define CINT64_T cint64_T +# endif +#endif + +#ifndef CUINT64_T +# ifdef UINT64_T + typedef struct { + uint64_T re, im; + } cuint64_T; +# define CUINT64_T cuint64_T +# endif +#endif + +/*=======================================================================* + * Min and Max: * + * int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers * + * uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers * + *=======================================================================*/ + +#define MAX_int8_T ((int8_T)(127)) /* 127 */ +#define MIN_int8_T ((int8_T)(-128)) /* -128 */ +#define MAX_uint8_T ((uint8_T)(255)) /* 255 */ +#define MIN_uint8_T ((uint8_T)(0)) + +#define MAX_int16_T ((int16_T)(32767)) /* 32767 */ +#define MIN_int16_T ((int16_T)(-32768)) /* -32768 */ +#define MAX_uint16_T ((uint16_T)(65535)) /* 65535 */ +#define MIN_uint16_T ((uint16_T)(0)) + +#define MAX_int32_T ((int32_T)(2147483647)) /* 2147483647 */ +#define MIN_int32_T ((int32_T)(-2147483647-1)) /* -2147483648 */ +#define MAX_uint32_T ((uint32_T)(0xFFFFFFFFU)) /* 4294967295 */ +#define MIN_uint32_T ((uint32_T)(0)) + +#if defined(_MSC_VER) || (defined(__BORLANDC__) && __BORLANDC__ >= 0x530) \ + || (defined(__WATCOMC__) && __WATCOMC__ >= 1100) \ + || defined(__LCC64__) +# ifdef INT64_T +# define MAX_int64_T ((int64_T)(9223372036854775807LL)) +# define MIN_int64_T ((int64_T)(-9223372036854775807LL-1LL)) +# endif +# ifdef UINT64_T +# define MAX_uint64_T ((uint64_T)(0xFFFFFFFFFFFFFFFFULL)) +# define MIN_uint64_T ((uint64_T)(0)) +# endif +#else +# ifdef INT64_T +# ifdef INT_TYPE_64_IS_LONG +# define MAX_int64_T ((int64_T)(9223372036854775807L)) +# define MIN_int64_T ((int64_T)(-9223372036854775807L-1L)) +# else +# define MAX_int64_T ((int64_T)(9223372036854775807LL)) +# define MIN_int64_T ((int64_T)(-9223372036854775807LL-1LL)) +# endif +# endif +# ifdef UINT64_T +# ifdef INT_TYPE_64_IS_LONG +# define MAX_uint64_T ((uint64_T)(0xFFFFFFFFFFFFFFFFUL)) +# define MIN_uint64_T ((uint64_T)(0)) +# else +# define MAX_uint64_T ((uint64_T)(0xFFFFFFFFFFFFFFFFULL)) +# define MIN_uint64_T ((uint64_T)(0)) +# endif +# endif +#endif + +#if (defined(_MSC_VER) && !defined(__clang__)) + +/* Conversion from unsigned __int64 to double is not implemented in Visual Studio + * and results in a compile error, thus the value must first be cast to + * signed __int64, and then to double. + * + * If the 64 bit int value is greater than 2^63-1, which is the signed int64 max, + * the macro below provides a workaround for casting a uint64 value to a double + * in windows. + */ +# define uint64_to_double(u) ( ((u) > _I64_MAX) ? \ + (double)(__int64)((u) - _I64_MAX - 1) + (double)_I64_MAX + 1: \ + (double)(__int64)(u) ) + +/* The following inline function should only be used in the macro double_to_uint64, + * as it only handles the specfic range of double between 2^63 and 2^64-1 */ +__forceinline +uint64_T double_to_uint64_helper(double d) { + union double_to_uint64_union_type { + double dd; + uint64_T i64; + } di; + di.dd = d; + return (((di.i64 & 0x000fffffffffffff) | 0x0010000000000000) << 11); +} + +/* The largest double value that can be cast to uint64 in windows is the + * signed int64 max, which is 2^63-1. The macro below provides + * a workaround for casting large double values to uint64 in windows. + */ +/* The magic number 18446744073709551616.0 is 2^64 */ +/* The magic number 9223372036854775808.0 is 2^63 */ +# define double_to_uint64(d) ( ((d) >= 18446744073709551616.0) ? \ + 0xffffffffffffffffULL : \ + ((d) >= 0.0) ? \ + ((d) >= 9223372036854775808.0) ? \ + double_to_uint64_helper(d) : \ + (unsigned __int64)(d) : \ + 0ULL ) +#else +# define uint64_to_double(u) ((double)(u)) +# if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__TICCSC__) +/* double_to_uint64 defined only for MSVC and UNIX */ +# else +# define double_to_uint64(d) ( ((d) >= 18446744073709551616.0) ? \ + (unsigned long long) 0xffffffffffffffffULL : \ + ((d) >= 0) ? (unsigned long long)(d) : (unsigned long long) 0 ) +# endif +#endif + +#if !defined(__cplusplus) && !defined(__bool_true_false_are_defined) + +#ifndef _bool_T +#define _bool_T + +typedef boolean_T bool; + +#ifndef false +#define false (0) +#endif +#ifndef true +#define true (1) +#endif + +#endif /* _bool_T */ + +#endif /* !__cplusplus */ + +/* + * This software assumes that the code is being compiled on a target using a + * 2's complement representation for signed integer values. + */ +#if ((SCHAR_MIN + 1) != -SCHAR_MAX) +#error "This code must be compiled using a 2's complement representation for signed integer values" +#endif + +/* + * Maximum length of a MATLAB identifier (function/variable/model) + * including the null-termination character. + */ +#define TMW_NAME_LENGTH_MAX 64 + +/* + * Maximum values for indices and dimensions + */ +#include + +#ifdef MX_COMPAT_32 +typedef int mwSize; +typedef int mwIndex; +typedef int mwSignedIndex; +#else +typedef size_t mwSize; /* unsigned pointer-width integer */ +typedef size_t mwIndex; /* unsigned pointer-width integer */ +typedef ptrdiff_t mwSignedIndex; /* a signed pointer-width integer */ +#endif + + /* for the individual dim */ +/* If updating SLSize or SLIndex, update defintions in sl_types_def.h + as well. */ +#ifndef SLSIZE_SLINDEX + #define SLSIZE_SLINDEX + #ifdef INT_TYPE_64_IS_SUPPORTED + typedef int64_T SLIndex; + typedef int64_T SLSize; + #else + typedef int SLIndex; + typedef int SLSize; + #endif +#endif + +/* for the total size */ +#define SLIndexType size_t +#define INVALID_SIZET_VALUE (std::numeric_limits::max()) +#define MAX_VALID_SIZET_VALUE (std::numeric_limits::max() -1) + + +#if (defined(_LP64) || defined(_WIN64)) && !defined(MX_COMPAT_32) +/* Currently 2^48 based on hardware limitations */ +# define MWSIZE_MAX 281474976710655UL +# define MWINDEX_MAX 281474976710655UL +# define MWSINDEX_MAX 281474976710655L +# define MWSINDEX_MIN -281474976710655L +#else +# define MWSIZE_MAX 2147483647UL +# define MWINDEX_MAX 2147483647UL +# define MWSINDEX_MAX 2147483647L +# define MWSINDEX_MIN -2147483647L +#endif +#define MWSIZE_MIN 0UL +#define MWINDEX_MIN 0UL + +/** UTF-16 character type */ + +#if (defined(__cplusplus) && (__cplusplus >= 201103L)) || (defined(_HAS_CHAR16_T_LANGUAGE_SUPPORT) && _HAS_CHAR16_T_LANGUAGE_SUPPORT) +typedef char16_t CHAR16_T; +#define U16_STRING_LITERAL_PREFIX u +#elif defined(_MSC_VER) +typedef wchar_t CHAR16_T; +#define U16_STRING_LITERAL_PREFIX L +#else +typedef UINT16_T CHAR16_T; +#endif + +#endif /* __TMWTYPES__ */ + +#endif /* tmwtypes_h */ diff --git a/RAT/triggerEvent.cpp b/RAT/triggerEvent.cpp new file mode 100644 index 00000000..f4e17660 --- /dev/null +++ b/RAT/triggerEvent.cpp @@ -0,0 +1,253 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// triggerEvent.cpp +// +// Code generation for function 'triggerEvent' +// + +// Include files +#include "triggerEvent.h" +#include "getenv.h" +#include "reflectivityCalculation_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "eventHelper.hpp" +#include +#include + +// Variable Definitions +namespace RAT +{ + static boolean_T notified; + static boolean_T helper_not_empty; +} + +// Function Declarations +namespace RAT +{ + static void packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts); + static void packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts); +} + +// Function Definitions +namespace RAT +{ + static void packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts) + { + real_T rowSize; + real_T start; + int32_T b_rowSize; + int32_T i; + + // Packs a cell array with different sized arrays into a single row + // array and an array of counts for each cell. For the example below + // reflect will be [1, 2, 3, 4, 5, 6, 7] and nReflect will be [3, 4] + // + // [reflect, nReflect] = packCellArray({[1, 2, 3], [4, 5, 6, 7]}); + rowSize = 0.0; + counts.set_size(cellArray.size(0)); + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T d; + d = static_cast(cellArray[b_i].f1.size(0)) * 2.0; + counts[b_i] = d; + rowSize += d; + } + + b_rowSize = static_cast(rowSize); + packedArray.set_size(b_rowSize); + for (i = 0; i < b_rowSize; i++) { + packedArray[i] = 0.0; + } + + start = 1.0; + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T stop; + int32_T i1; + stop = start + counts[b_i]; + if (start > stop - 1.0) { + i1 = 1; + } else { + i1 = static_cast(start); + } + + b_rowSize = cellArray[b_i].f1.size(0) << 1; + for (int32_T i2{0}; i2 < b_rowSize; i2++) { + packedArray[(i1 + i2) - 1] = cellArray[b_i].f1[i2]; + } + + start = stop; + } + } + + static void packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts) + { + real_T rowSize; + real_T start; + int32_T b_rowSize; + int32_T i; + + // Packs a cell array with different sized arrays into a single row + // array and an array of counts for each cell. For the example below + // reflect will be [1, 2, 3, 4, 5, 6, 7] and nReflect will be [3, 4] + // + // [reflect, nReflect] = packCellArray({[1, 2, 3], [4, 5, 6, 7]}); + rowSize = 0.0; + counts.set_size(cellArray.size(0)); + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T d; + d = static_cast(cellArray[b_i].f1.size(0)) * 3.0; + counts[b_i] = d; + rowSize += d; + } + + b_rowSize = static_cast(rowSize); + packedArray.set_size(b_rowSize); + for (i = 0; i < b_rowSize; i++) { + packedArray[i] = 0.0; + } + + start = 1.0; + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T stop; + int32_T i1; + stop = start + counts[b_i]; + if (start > stop - 1.0) { + i1 = 1; + } else { + i1 = static_cast(start); + } + + b_rowSize = cellArray[b_i].f1.size(0) * 3; + for (int32_T i2{0}; i2 < b_rowSize; i2++) { + packedArray[(i1 + i2) - 1] = cellArray[b_i].f1[i2]; + } + + start = stop; + } + } + + void helper_not_empty_init() + { + helper_not_empty = false; + } + + void triggerEvent(const ::coder::array &data_f1_f1, const :: + coder::array &data_f1_f3, const ::coder:: + array &data_f1_f5, const ::coder::array< + cell_wrap_13, 1U> &data_f1_f6, const ::coder::array &data_f2, const ::coder::array + &data_f3_resample, const ::coder::array + &data_f3_dataPresent, const char_T data_f3_modelType_data[], + const int32_T data_f3_modelType_size[2]) + { + static eventHelper helper; + ::coder::array dataPresent; + ::coder::array resample; + ::coder::array layers; + ::coder::array nLayers; + ::coder::array nReflect; + ::coder::array nShiftedData; + ::coder::array nSldProfiles; + ::coder::array reflect; + ::coder::array shiftedData; + ::coder::array sldProfiles; + ::coder::array ssubs; + ::coder::array path; + ::coder::array r; + int32_T loop_ub; + char_T modelType_data[10001]; + boolean_T initialised; + + // Triggers the event type with the given data. The supported event types are + // 'message' and 'plot'. The data for message is a char array while for + // the plot it is a cell array containing the result cell, problem.ssubs + // and problemDef + // + // triggerEvent('message', 'Hello world'); + if (!helper_not_empty) { + // Declaration for coder + helper_not_empty = true; + + // Make an instance + helper = eventHelper(); + coder::b_getenv(r); + path.set_size(1, r.size(1) + 1); + loop_ub = r.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + path[i] = r[i]; + } + + path[r.size(1)] = '\x00'; + std::mem_fn(&eventHelper::init)(helper, &path[0]); + } + + initialised = std::mem_fn(&eventHelper::isInitialised)(helper); + if (initialised) { + packCellArray(data_f1_f1, reflect, nReflect); + + // reflectivity + packCellArray(data_f1_f3, shiftedData, nShiftedData); + packCellArray(data_f1_f5, sldProfiles, nSldProfiles); + packCellArray(data_f1_f6, layers, nLayers); + + // All Layers + ssubs.set_size(data_f2.size(0)); + loop_ub = data_f2.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + ssubs[i] = data_f2[i]; + } + + // ssubs + loop_ub = data_f3_modelType_size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&data_f3_modelType_data[0], &data_f3_modelType_data[loop_ub], + &modelType_data[0]); + } + + modelType_data[data_f3_modelType_size[1]] = '\x00'; + resample.set_size(1, data_f3_resample.size(1)); + loop_ub = data_f3_resample.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + resample[i] = data_f3_resample[i]; + } + + dataPresent.set_size(1, data_f3_dataPresent.size(1)); + loop_ub = data_f3_dataPresent.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + dataPresent[i] = data_f3_dataPresent[i]; + } + + std::mem_fn(&eventHelper::updatePlot)(helper, static_cast + (data_f1_f1.size(0)), &(reflect.data())[0], &(nReflect.data())[0], + &(shiftedData.data())[0], &(nShiftedData.data())[0], &(sldProfiles.data()) + [0], &(nSldProfiles.data())[0], &(layers.data())[0], &(nLayers.data())[0], + &(ssubs.data())[0], &resample[0], &dataPresent[0], &modelType_data[0]); + notified = false; + + // This avoids printing the error message multiple times during the optimization. + } else if (!notified) { + fprintf(stderr, + "\neventManager library coult be loaded. Check that the dynamic library is present in the compile/events folder.\n"); + fflush(stderr); + notified = true; + } + } + + void triggerEvent_init() + { + notified = false; + } +} + +// End of code generation (triggerEvent.cpp) diff --git a/RAT/triggerEvent.h b/RAT/triggerEvent.h new file mode 100644 index 00000000..65df73ea --- /dev/null +++ b/RAT/triggerEvent.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// triggerEvent.h +// +// Code generation for function 'triggerEvent' +// +#ifndef TRIGGEREVENT_H +#define TRIGGEREVENT_H + +// Include files +#include "reflectivityCalculation_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void helper_not_empty_init(); + void triggerEvent(const ::coder::array &data_f1_f1, const :: + coder::array &data_f1_f3, const ::coder:: + array &data_f1_f5, const ::coder::array< + cell_wrap_13, 1U> &data_f1_f6, const ::coder::array &data_f2, const ::coder::array + &data_f3_resample, const ::coder::array + &data_f3_dataPresent, const char_T data_f3_modelType_data[], + const int32_T data_f3_modelType_size[2]); + void triggerEvent_init(); +} + +#endif + +// End of code generation (triggerEvent.h) diff --git a/RAT/unsafeSxfun.cpp b/RAT/unsafeSxfun.cpp new file mode 100644 index 00000000..4f734255 --- /dev/null +++ b/RAT/unsafeSxfun.cpp @@ -0,0 +1,67 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// unsafeSxfun.cpp +// +// Code generation for function 'unsafeSxfun' +// + +// Include files +#include "unsafeSxfun.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in3, const ::coder::array &in4) + { + ::coder::array b_in3; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + int32_T stride_2_0; + if (in3.size(0) == 1) { + if (in4.size(0) == 1) { + i = in3.size(0); + } else { + i = in4.size(0); + } + } else { + i = in3.size(0); + } + + b_in3.set_size(i); + stride_0_0 = (in3.size(0) != 1); + stride_1_0 = (in4.size(0) != 1); + stride_2_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + if (in4.size(0) == 1) { + loop_ub = in3.size(0); + } else { + loop_ub = in4.size(0); + } + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + b_in3[i] = (in3[i * stride_0_0 + in3.size(0)] - in4[i * stride_1_0 + + in4.size(0)]) / in3[i * stride_2_0 + in3.size(0) * 2]; + } + + in1.set_size(b_in3.size(0)); + loop_ub = b_in3.size(0); + for (i = 0; i < loop_ub; i++) { + real_T varargin_1; + varargin_1 = b_in3[i]; + in1[i] = varargin_1 * varargin_1; + } + } +} + +// End of code generation (unsafeSxfun.cpp) diff --git a/RAT/unsafeSxfun.h b/RAT/unsafeSxfun.h new file mode 100644 index 00000000..f524dc40 --- /dev/null +++ b/RAT/unsafeSxfun.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// unsafeSxfun.h +// +// Code generation for function 'unsafeSxfun' +// +#ifndef UNSAFESXFUN_H +#define UNSAFESXFUN_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in3, const ::coder::array &in4); +} + +#endif + +// End of code generation (unsafeSxfun.h) diff --git a/README.md b/README.md new file mode 100644 index 00000000..1249b1d9 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +RAT PyBind Demo +=============== +This is a demonstration of using the generated C++ from MATLAB to create a python extension with PyBind11 + +Build +===== +This has been tested using python 3.8, a c++ compiler is required to run the code. Install the requirement then run the example, if the +compiler can be found, the python extension (*.pyd) will be built and the example will run diff --git a/data/data1.csv b/data/data1.csv new file mode 100644 index 00000000..69e6272f --- /dev/null +++ b/data/data1.csv @@ -0,0 +1,82 @@ +0.011403,0.10063,0.0019003 +0.011973,0.11082,0.001883 +0.012572,0.10766,0.0016413 +0.013201,0.10652,0.0014669 +0.013861,0.090118,0.0011774 +0.014554,0.034255,0.00048888 +0.015281,0.017209,0.00026267 +0.016045,0.010465,0.00017551 +0.016848,0.0070455,0.00013083 +0.01769,0.0045958,9.72E-05 +0.018575,0.0034925,8.09E-05 +0.019503,0.002451,6.45E-05 +0.020479,0.0017544,5.13E-05 +0.021502,0.0013384,4.27E-05 +0.022578,0.0010447,3.59E-05 +0.023706,0.00076523,2.93E-05 +0.024892,0.00064257,2.62E-05 +0.026136,0.00050024,1.37E-05 +0.027443,0.00039982,1.16E-05 +0.028815,0.00034301,1.01E-05 +0.030256,0.00027746,8.58E-06 +0.031769,0.00026396,8.28E-06 +0.033357,0.00023596,7.89E-06 +0.035025,0.0002028,1.00E-05 +0.036777,0.00018591,4.94E-06 +0.038615,0.00015427,4.31E-06 +0.040546,0.00014273,3.96E-06 +0.042573,0.00012868,3.66E-06 +0.044702,0.00011002,3.26E-06 +0.046937,9.11E-05,2.82E-06 +0.049284,9.12E-05,2.72E-06 +0.051748,7.63E-05,2.37E-06 +0.054336,6.67E-05,2.14E-06 +0.057052,6.46E-05,2.46E-06 +0.059905,6.10E-05,1.32E-06 +0.0629,6.31E-05,1.29E-06 +0.066045,6.07E-05,1.18E-06 +0.069348,6.00E-05,1.11E-06 +0.072815,6.10E-05,1.10E-06 +0.076456,5.68E-05,1.04E-06 +0.080279,5.88E-05,1.56E-06 +0.084292,5.41E-05,9.53E-07 +0.088507,4.70E-05,8.44E-07 +0.092932,4.26E-05,7.71E-07 +0.097579,3.27E-05,6.53E-07 +0.10246,2.54E-05,5.46E-07 +0.10758,1.71E-05,4.22E-07 +0.11296,1.22E-05,3.41E-07 +0.11861,7.82E-06,2.59E-07 +0.12454,5.09E-06,2.02E-07 +0.13077,4.16E-06,1.76E-07 +0.1373,3.63E-06,1.62E-07 +0.14417,3.35E-06,1.51E-07 +0.15138,2.73E-06,1.32E-07 +0.15895,1.82E-06,1.07E-07 +0.16689,1.22E-06,8.76E-08 +0.17524,4.93E-07,5.67E-08 +0.184,2.40E-07,4.13E-08 +0.1932,3.38E-07,5.32E-08 +0.20286,3.20E-07,5.50E-08 +0.213,4.19E-07,6.85E-08 +0.22365,3.15E-07,6.34E-08 +0.23484,2.32E-07,5.60E-08 +0.24658,3.34E-07,6.84E-08 +0.25891,3.99E-07,8.21E-08 +0.27185,2.51E-07,6.27E-08 +0.28544,2.25E-07,6.33E-08 +0.29972,2.09E-07,6.06E-08 +0.3147,2.09E-07,6.14E-08 +0.33044,3.34E-07,7.72E-08 +0.34696,1.84E-07,6.05E-08 +0.36431,2.35E-07,6.62E-08 +0.38252,2.12E-07,6.31E-08 +0.40165,2.47E-07,6.66E-08 +0.42173,2.02E-07,6.24E-08 +0.44282,2.46E-07,6.91E-08 +0.46496,1.99E-07,6.08E-08 +0.48821,2.86E-07,7.39E-08 +0.51262,1.95E-07,6.18E-08 +0.53825,2.88E-07,7.54E-08 +0.56516,2.38E-07,7.06E-08 +0.59342,2.18E-07,6.69E-08 diff --git a/data/data2.csv b/data/data2.csv new file mode 100644 index 00000000..57709af5 --- /dev/null +++ b/data/data2.csv @@ -0,0 +1,82 @@ +0.011403,0.0018074,0.00010983 +0.011973,0.0014774,9.06E-05 +0.012572,0.001325,7.70E-05 +0.013201,0.0012216,6.64E-05 +0.013861,0.0010077,5.58E-05 +0.014554,0.0010266,5.14E-05 +0.015281,0.00091489,4.52E-05 +0.016045,0.00080921,4.00E-05 +0.016848,0.00061576,3.35E-05 +0.01769,0.00060308,3.16E-05 +0.018575,0.00046074,2.68E-05 +0.019503,0.00040453,2.44E-05 +0.020479,0.00036496,2.20E-05 +0.021502,0.00032468,2.00E-05 +0.022578,0.0002479,1.66E-05 +0.023706,0.00027709,1.70E-05 +0.024892,0.00021141,1.44E-05 +0.026136,0.00017034,7.51E-06 +0.027443,0.00015127,6.71E-06 +0.028815,0.00013632,5.95E-06 +0.030256,0.00011151,5.25E-06 +0.031769,9.58E-05,4.77E-06 +0.033357,7.59E-05,4.22E-06 +0.035025,6.92E-05,6.20E-06 +0.036777,5.27E-05,2.39E-06 +0.038615,3.92E-05,1.98E-06 +0.040546,2.94E-05,1.64E-06 +0.042573,2.23E-05,1.39E-06 +0.044702,1.47E-05,1.09E-06 +0.046937,8.20E-06,7.77E-07 +0.049284,6.49E-06,6.66E-07 +0.051748,3.09E-06,4.36E-07 +0.054336,2.60E-06,3.89E-07 +0.057052,2.73E-06,5.00E-07 +0.059905,4.36E-06,3.20E-07 +0.0629,5.49E-06,3.45E-07 +0.066045,7.29E-06,3.70E-07 +0.069348,8.91E-06,3.89E-07 +0.072815,1.06E-05,4.19E-07 +0.076456,1.24E-05,4.42E-07 +0.080279,1.46E-05,7.02E-07 +0.084292,1.48E-05,4.56E-07 +0.088507,1.40E-05,4.24E-07 +0.092932,1.16E-05,3.73E-07 +0.097579,1.06E-05,3.48E-07 +0.10246,7.77E-06,2.85E-07 +0.10758,6.43E-06,2.46E-07 +0.11296,4.95E-06,2.07E-07 +0.11861,2.90E-06,1.51E-07 +0.12454,1.98E-06,1.21E-07 +0.13077,1.18E-06,9.06E-08 +0.1373,9.56E-07,8.03E-08 +0.14417,9.92E-07,7.95E-08 +0.15138,8.10E-07,6.93E-08 +0.15895,7.82E-07,6.76E-08 +0.16689,6.04E-07,5.99E-08 +0.17524,4.86E-07,5.49E-08 +0.184,4.14E-07,5.29E-08 +0.1932,4.38E-07,5.92E-08 +0.20286,3.00E-07,5.16E-08 +0.213,4.95E-07,7.11E-08 +0.22365,2.80E-07,5.78E-08 +0.23484,2.39E-07,5.49E-08 +0.24658,2.18E-07,5.37E-08 +0.25891,2.57E-07,6.37E-08 +0.27185,5.80E-07,9.35E-08 +0.28544,3.27E-07,7.46E-08 +0.29972,3.05E-07,7.16E-08 +0.3147,3.36E-07,7.63E-08 +0.33044,3.86E-07,8.11E-08 +0.34696,2.94E-07,7.29E-08 +0.36431,3.03E-07,7.30E-08 +0.38252,4.10E-07,8.57E-08 +0.40165,4.06E-07,8.34E-08 +0.42173,5.31E-07,9.75E-08 +0.44282,4.95E-07,9.56E-08 +0.46496,3.54E-07,7.87E-08 +0.48821,3.56E-07,8.00E-08 +0.51262,3.76E-07,8.34E-08 +0.53825,5.89E-07,1.05E-07 +0.56516,3.26E-07,7.97E-08 +0.59342,3.07E-07,7.71E-08 diff --git a/rat.cpp b/rat.cpp new file mode 100644 index 00000000..db52c9e0 --- /dev/null +++ b/rat.cpp @@ -0,0 +1,762 @@ +/*<% +cfg['include_dirs'] = ['D:/Anaconda/lib/site-packages/pybind11/include'] +import glob +cfg['sources'] = glob.glob('RAT/*.cpp') +cfg['parallel'] = True +setup_pybind11(cfg) +%>*/ + +#include +#include +#include "RAT/reflectivityCalculation.h" +#include "RAT/reflectivityCalculation_types.h" + +namespace py = pybind11; + + +struct Checks { + py::array_t params_fitYesNo; + py::array_t backs_fitYesNo; + py::array_t shifts_fitYesNo; + py::array_t scales_fitYesNo; + py::array_t nbairs_fitYesNo; + py::array_t nbsubs_fitYesNo; + py::array_t resol_fitYesNo; + py::array_t domainRatio_fitYesNo; +}; + +struct Calculation +{ + py::array_t all_chis; + real_T sum_chi; +}; + +struct OutputProblem +{ + py::array_t ssubs; + py::array_t backgrounds; + py::array_t qshifts; + py::array_t scalefactors; + py::array_t nbairs; + py::array_t nbsubs; + py::array_t resolutions; + Calculation calculations {}; + py::array_t allSubRough; + py::array_t resample; +}; + +struct OutputResult { + py::list f1; + py::list f2; + py::list f3; + py::list f4; + py::list f5; + py::list f6; +}; + +struct Limits { + py::array_t params; + py::array_t backs; + py::array_t scales; + py::array_t shifts; + py::array_t nba; + py::array_t nbs; + py::array_t res; + py::array_t domainRatio; +}; + +struct Cells { + py::list f1; + py::list f2; + py::list f3; + py::list f4; + py::list f5; + py::list f6; + py::list f7; + py::list f8; + py::list f9; + py::list f10; + py::list f11; + py::list f12; + py::list f13; + py::list f14; + py::list f15; + py::list f16; + py::list f17; + py::list f18; + py::list f19; + py::list f20; +}; + +struct ProblemDefinition { + py::array_t contrastBacks; + py::array_t contrastBacksType; + std::string TF {}; + py::array_t resample; + py::array_t dataPresent; + py::array_t oilChiDataPresent; + real_T numberOfContrasts; + std::string geometry {}; + bool useImaginary {}; + py::array_t contrastShifts; + py::array_t contrastScales; + py::array_t contrastNbas; + py::array_t contrastNbss; + py::array_t contrastRes; + py::array_t backs; + py::array_t shifts; + py::array_t sf; + py::array_t nba; + py::array_t nbs; + py::array_t res; + py::array_t params; + real_T numberOfLayers {}; + std::string modelType {}; + py::array_t contrastCustomFiles; + py::array_t contrastDomainRatios; + py::array_t domainRatio; + real_T numberOfDomainContrasts {}; + py::array_t domainContrastCustomFiles; + py::array_t fitpars; + py::array_t otherpars; + py::array_t fitconstr; + py::array_t otherconstr; +}; + +struct Control { + std::string para {}; + std::string proc {}; + std::string display {}; + real_T tolX {}; + real_T tolFun {}; + real_T maxFunEvals {}; + real_T maxIter {}; + real_T populationSize {}; + real_T fWeight {}; + real_T F_CR {}; + real_T VTR {}; + real_T numGen {}; + real_T strategy {}; + real_T Nlive {}; + real_T nmcmc {}; + real_T propScale {}; + real_T nsTolerance {}; + real_T calcSld {}; + py::array_t resamPars; + real_T updateFreq {}; + real_T updatePlotFreq {}; + real_T nSamples {}; + real_T nChains {}; + real_T lambda {}; + real_T pUnitGamma {}; + std::string boundHandling {}; + Checks checks {}; +}; + + +void string_to_rat_array(std::string value, char_T result_data[], int32_T result_size[2]) +{ + result_size[0] = 1; + result_size[1] = value.length(); + + // Loop over the array to initialize each element. + for (int32_T idx1{0}; idx1 < value.length(); idx1++) { + result_data[idx1] = value[idx1]; + } +} + +coder::array py_array_to_rat_1d_array(py::array_t value) +{ + coder::array result; + + py::buffer_info buffer_info = value.request(); + + if (buffer_info.size == 0) + return result; + + if (buffer_info.ndim != 1) + throw std::runtime_error("Number of dimensions must be 1"); + + result.set_size(1, buffer_info.shape[0]); + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < buffer_info.shape[0]; idx0++) { + result[idx0] = value.at(idx0); + } + + return result; +} + +coder::bounded_array py_array_to_rat_bounded_array2(py::array_t value) +{ + coder::bounded_array result {}; + + py::buffer_info buffer_info = value.request(); + + if (buffer_info.size == 0) + return result; + + if (buffer_info.ndim != 1) + throw std::runtime_error("Number of dimensions must be 1"); + + result.size[0] = 1; + result.size[1] = buffer_info.shape[0]; + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < buffer_info.shape[0]; idx0++) { + result.data[idx0] = value.at(idx0); + } + + return result; +} + +coder::bounded_array py_array_to_rat_bounded_array1(py::array_t value) +{ + coder::bounded_array result {}; + + py::buffer_info buffer_info = value.request(); + + if (buffer_info.size == 0) + return result; + + if (buffer_info.ndim != 1) + throw std::runtime_error("Number of dimensions must be 1"); + + result.size[0] = 1; + result.size[1] = buffer_info.shape[0]; + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < buffer_info.shape[0]; idx0++) { + result.data[idx0] = value.at(idx0); + } + + return result; +} + +coder::array py_array_to_rat_2d_array(py::array_t value) +{ + coder::array result; + + py::buffer_info buffer_info = value.request(); + + if (buffer_info.size == 0) + return result; + + if (buffer_info.ndim != 2) + throw std::runtime_error("Number of dimensions must be 2"); + + result.set_size(buffer_info.shape[0], buffer_info.shape[1]); + + int32_T idx {0}; + // Loop over the array to initialize each element. + for (int32_T idx0{0}; idx0 < buffer_info.shape[0]; idx0++) { + for (int32_T idx1{0}; idx1 < buffer_info.shape[1]; idx1++) { + idx = idx0 + result.size(0) * idx1; + result[idx] = value.at(idx0, idx1); + } + } + + return result; +} + +RAT::struct0_T create_struct0_T(const ProblemDefinition& problem) +{ + RAT::struct0_T problem_struct; + + problem_struct.useImaginary = problem.useImaginary; + + problem_struct.numberOfLayers = problem.numberOfLayers; + problem_struct.numberOfDomainContrasts = problem.numberOfDomainContrasts; + problem_struct.numberOfContrasts = problem.numberOfContrasts; + + string_to_rat_array(problem.modelType, problem_struct.modelType.data, problem_struct.modelType.size); + string_to_rat_array(problem.geometry, problem_struct.geometry.data, problem_struct.geometry.size); + string_to_rat_array(problem.TF, problem_struct.TF.data, problem_struct.TF.size); + + problem_struct.contrastBacks = py_array_to_rat_1d_array(problem.contrastBacks); + problem_struct.contrastBacksType = py_array_to_rat_1d_array(problem.contrastBacksType); + problem_struct.resample = py_array_to_rat_1d_array(problem.resample); + problem_struct.dataPresent = py_array_to_rat_1d_array(problem.dataPresent); + problem_struct.oilChiDataPresent = py_array_to_rat_1d_array(problem.oilChiDataPresent); + problem_struct.contrastShifts = py_array_to_rat_1d_array(problem.contrastShifts); + problem_struct.contrastScales = py_array_to_rat_1d_array(problem.contrastScales); + problem_struct.contrastNbas = py_array_to_rat_1d_array(problem.contrastNbas); + problem_struct.contrastNbss = py_array_to_rat_1d_array(problem.contrastNbss); + problem_struct.contrastRes = py_array_to_rat_1d_array(problem.contrastRes); + problem_struct.backs = py_array_to_rat_1d_array(problem.backs); + problem_struct.shifts = py_array_to_rat_1d_array(problem.shifts); + problem_struct.sf = py_array_to_rat_1d_array(problem.sf); + problem_struct.nba = py_array_to_rat_1d_array(problem.nba); + problem_struct.nbs = py_array_to_rat_1d_array(problem.nbs); + problem_struct.res = py_array_to_rat_1d_array(problem.res); + problem_struct.params = py_array_to_rat_1d_array(problem.params); + + problem_struct.contrastCustomFiles = py_array_to_rat_1d_array(problem.contrastCustomFiles); + problem_struct.contrastDomainRatios = py_array_to_rat_1d_array(problem.contrastDomainRatios); + problem_struct.domainRatio = py_array_to_rat_1d_array(problem.domainRatio); + problem_struct.domainContrastCustomFiles = py_array_to_rat_1d_array(problem.domainContrastCustomFiles); + + problem_struct.fitpars = py_array_to_rat_1d_array(problem.fitpars); + problem_struct.otherpars = py_array_to_rat_1d_array(problem.otherpars); + problem_struct.fitconstr = py_array_to_rat_2d_array(problem.fitconstr); + problem_struct.otherconstr = py_array_to_rat_2d_array(problem.otherconstr); + + return problem_struct; +} + +RAT::struct1_T create_struct1_T(const Limits& limits) +{ + RAT::struct1_T limits_struct; + limits_struct.params = py_array_to_rat_2d_array(limits.params); + limits_struct.backs = py_array_to_rat_2d_array(limits.backs); + limits_struct.shifts = py_array_to_rat_2d_array(limits.shifts); + limits_struct.scales = py_array_to_rat_2d_array(limits.scales); + limits_struct.nba = py_array_to_rat_2d_array(limits.nba); + limits_struct.nbs = py_array_to_rat_2d_array(limits.nbs); + limits_struct.res = py_array_to_rat_2d_array(limits.res); + limits_struct.domainRatio = py_array_to_rat_2d_array(limits.domainRatio); + + return limits_struct; +} + +RAT::struct3_T create_struct3_T(const Checks& checks) +{ + RAT::struct3_T checks_struct; + checks_struct.params_fitYesNo = py_array_to_rat_1d_array(checks.params_fitYesNo); + checks_struct.backs_fitYesNo = py_array_to_rat_1d_array(checks.backs_fitYesNo); + checks_struct.shifts_fitYesNo = py_array_to_rat_1d_array(checks.shifts_fitYesNo); + checks_struct.scales_fitYesNo = py_array_to_rat_1d_array(checks.scales_fitYesNo); + checks_struct.nbairs_fitYesNo = py_array_to_rat_1d_array(checks.nbairs_fitYesNo); + checks_struct.nbsubs_fitYesNo = py_array_to_rat_1d_array(checks.nbsubs_fitYesNo); + checks_struct.resol_fitYesNo = py_array_to_rat_1d_array(checks.resol_fitYesNo); + checks_struct.domainRatio_fitYesNo = py_array_to_rat_1d_array(checks.domainRatio_fitYesNo); + + return checks_struct; +} + +coder::array py_array_to_rat_cell_wrap_0(py::list values) +{ + coder::array result; + result.set_size(1, values.size()); + int32_T idx {0}; + for (py::handle array: values) + { + py::array_t casted_array = py::cast(array); + result[idx].f1[0] = casted_array.at(0); + result[idx].f1[1] = casted_array.at(1); + idx++; + } + + return result; +} + +coder::array py_array_to_rat_cell_wrap_1(py::list values) +{ + coder::array result; + result.set_size(1, values.size()); + int32_T idx {0}; + for (py::handle array: values) + { + py::array_t casted_array = py::cast(array); + result[idx].f1 = py_array_to_rat_2d_array(casted_array); + idx++; + } + + return result; +} + +coder::array py_array_to_rat_cell_wrap_2(py::list values) +{ + coder::array result; + result.set_size(1, values.size()); + int32_T idx {0}; + for (py::handle array: values) + { + py::array_t casted_array = py::cast(array); + result[idx].f1 = py_array_to_rat_bounded_array2(casted_array); + idx++; + } + + return result; +} + +coder::array py_array_to_rat_cell_wrap_3(py::list values) +{ + coder::array result; + result.set_size(1, values.size()); + int32_T idx {0}; + for (py::handle array: values) + { + py::array_t casted_array = py::cast(array); + RAT::cell_wrap_3 temp; + result[idx].f1 = py_array_to_rat_1d_array(casted_array); + idx++; + } + + return result; +} + +coder::array py_array_to_rat_cell_wrap_4(py::list values) +{ + coder::array result; + result.set_size(values.size()); + int32_T idx {0}; + for (py::handle array: values) + { + py::array_t casted_array = py::cast(array); + result[idx].f1 = py_array_to_rat_bounded_array1(casted_array); + idx++; + } + + return result; +} + +coder::array py_array_to_rat_cell_wrap_5(py::list values) +{ + coder::array result; + result.set_size(1, values.size()); + int32_T idx {0}; + for (py::handle array: values) + { + std::string name = py::cast(array); + string_to_rat_array(name, result[idx].f1.data, result[idx].f1.size); + idx++; + } + + return result; +} + +coder::array py_array_to_rat_cell_wrap_6(py::list values) +{ + coder::array result; + result.set_size(1, values.size()); + int32_T idx {0}; + for (py::handle array: values) + { + std::string name = py::cast(array); + string_to_rat_array(name, result[idx].f1.data, result[idx].f1.size); + idx++; + } + + return result; +} + +coder::array py_array_to_rat_cell_wrap_7(py::list values) +{ + coder::array result; + result.set_size(1, values.size()); + int32_T idx {0}; + for (py::handle value: values) + { + py::list casted_array = py::cast(value); + + int32_T idx1 {0}; + for (py::handle array: casted_array) + { + std::string name = py::cast(array); + string_to_rat_array(name, result[idx].f1[idx1].f1.data, result[idx].f1[idx1].f1.size); + idx1++; + } + idx++; + } + + return result; +} + +RAT::cell_8 create_cell_8(const Cells& cells) +{ + RAT::cell_8 cells_struct; + cells_struct.f1 = py_array_to_rat_cell_wrap_0(cells.f1); + cells_struct.f2 = py_array_to_rat_cell_wrap_1(cells.f2); + cells_struct.f3 = py_array_to_rat_cell_wrap_0(cells.f3); + cells_struct.f4 = py_array_to_rat_cell_wrap_2(cells.f4); + cells_struct.f5 = py_array_to_rat_cell_wrap_3(cells.f5); + cells_struct.f6 = py_array_to_rat_cell_wrap_4(cells.f6); + cells_struct.f7 = py_array_to_rat_cell_wrap_5(cells.f7); + cells_struct.f8 = py_array_to_rat_cell_wrap_6(cells.f8); + cells_struct.f9 = py_array_to_rat_cell_wrap_6(cells.f9); + cells_struct.f10 = py_array_to_rat_cell_wrap_6(cells.f10); + cells_struct.f11 = py_array_to_rat_cell_wrap_6(cells.f11); + cells_struct.f12 = py_array_to_rat_cell_wrap_6(cells.f12); + cells_struct.f13 = py_array_to_rat_cell_wrap_6(cells.f13); + cells_struct.f14 = py_array_to_rat_cell_wrap_7(cells.f14); + cells_struct.f15 = py_array_to_rat_cell_wrap_5(cells.f15); + cells_struct.f16 = py_array_to_rat_cell_wrap_5(cells.f16); + cells_struct.f17 = py_array_to_rat_cell_wrap_1(cells.f17); + cells_struct.f18 = py_array_to_rat_cell_wrap_0(cells.f18); + cells_struct.f19 = py_array_to_rat_cell_wrap_3(cells.f19); + cells_struct.f20 = py_array_to_rat_cell_wrap_6(cells.f20); + + return cells_struct; +} + +RAT::struct2_T create_struct2_T(const Control& control) +{ + RAT::struct2_T control_struct; + control_struct.tolFun = control.tolFun; + control_struct.maxFunEvals = control.maxFunEvals; + control_struct.maxIter = control.maxIter; + control_struct.populationSize = control.populationSize; + control_struct.fWeight = control.fWeight; + control_struct.F_CR = control.F_CR; + control_struct.VTR = control.VTR; + control_struct.numGen = control.numGen; + control_struct.strategy = control.strategy; + control_struct.Nlive = control.Nlive; + control_struct.nmcmc = control.nmcmc; + control_struct.propScale = control.propScale; + control_struct.nsTolerance = control.nsTolerance; + control_struct.calcSld = control.calcSld; + control_struct.updateFreq = control.updateFreq; + control_struct.updatePlotFreq = control.updatePlotFreq; + control_struct.nSamples = control.nSamples; + control_struct.nChains = control.nChains; + control_struct.lambda = control.lambda; + control_struct.pUnitGamma = control.pUnitGamma; + string_to_rat_array(control.para, control_struct.para.data, control_struct.para.size); + string_to_rat_array(control.proc, control_struct.proc.data, control_struct.proc.size); + string_to_rat_array(control.display, control_struct.display.data, control_struct.display.size); + control_struct.tolX = control.tolX; + control_struct.resamPars[0] = control.resamPars.at(0); + control_struct.resamPars[1] = control.resamPars.at(1); + string_to_rat_array(control.boundHandling, control_struct.boundHandling.data, control_struct.boundHandling.size); + control_struct.checks = create_struct3_T(control.checks); + + return control_struct; +} + +py::tuple reflectivityCalculation(const ProblemDefinition& problem_def, const Cells& cells, const Limits& limits, const Control& control) +{ + RAT::struct0_T problem_def_struct = create_struct0_T(problem_def); + RAT::cell_8 cells_struct = create_cell_8(cells); + RAT::struct1_T limits_struct = create_struct1_T(limits); + RAT::struct2_T control_struct = create_struct2_T(control); + + RAT::cell_11 result; + RAT::struct4_T problem; + + // Call the entry-point 'reflectivityCalculation'. + RAT::reflectivityCalculation(&problem_def_struct, &cells_struct, &limits_struct, &control_struct, &problem, &result); + + // Copy problem to output + OutputProblem output_problem; + output_problem.ssubs = py::array_t(problem.ssubs.size(0)); + auto buffer = output_problem.ssubs.request(); + std::memcpy(buffer.ptr, problem.ssubs.data(), output_problem.ssubs.size()*sizeof(real_T)); + + output_problem.backgrounds = py::array_t(problem.backgrounds.size(0)); + buffer = output_problem.backgrounds.request(); + std::memcpy(buffer.ptr, problem.backgrounds.data(), output_problem.backgrounds.size()*sizeof(real_T)); + + output_problem.qshifts = py::array_t(problem.qshifts.size(0)); + buffer = output_problem.qshifts.request(); + std::memcpy(buffer.ptr, problem.qshifts.data(), output_problem.qshifts.size()*sizeof(real_T)); + + output_problem.scalefactors = py::array_t(problem.scalefactors.size(0)); + buffer = output_problem.scalefactors.request(); + std::memcpy(buffer.ptr, problem.scalefactors.data(), output_problem.scalefactors.size()*sizeof(real_T)); + + output_problem.nbairs = py::array_t(problem.nbairs.size(0)); + buffer = output_problem.nbairs.request(); + std::memcpy(buffer.ptr, problem.nbairs.data(), output_problem.nbairs.size()*sizeof(real_T)); + + output_problem.nbsubs = py::array_t(problem.nbsubs.size(0)); + buffer = output_problem.nbsubs.request(); + std::memcpy(buffer.ptr, problem.nbsubs.data(), output_problem.nbsubs.size()*sizeof(real_T)); + + output_problem.resolutions = py::array_t(problem.resolutions.size(0)); + buffer = output_problem.resolutions.request(); + std::memcpy(buffer.ptr, problem.resolutions.data(), output_problem.resolutions.size()*sizeof(real_T)); + + output_problem.calculations.sum_chi = problem.calculations.sum_chi; + output_problem.calculations.all_chis = py::array_t(problem.calculations.all_chis.size(0)); + buffer = output_problem.calculations.all_chis.request(); + std::memcpy(buffer.ptr, problem.calculations.all_chis.data(), output_problem.calculations.all_chis.size()*sizeof(real_T)); + + output_problem.allSubRough = py::array_t(problem.allSubRough.size(0)); + buffer = output_problem.allSubRough.request(); + std::memcpy(buffer.ptr, problem.allSubRough.data(), output_problem.allSubRough.size()*sizeof(real_T)); + + output_problem.resample = py::array_t(problem.resample.size(1)); + buffer = output_problem.resample.request(); + std::memcpy(buffer.ptr, problem.resample.data(), output_problem.resample.size()*sizeof(real_T)); + + // Copy result to output + OutputResult output_result; + + for (int32_T idx{0}; idx < result.f1.size(0); idx++) { + auto array = py::array_t({result.f1[idx].f1.size(0), result.f1[idx].f1.size(1)}); + std::memcpy(array.request().ptr, result.f1[idx].f1.data(), array.nbytes()); + output_result.f1.append(array); + } + + for (int32_T idx{0}; idx < result.f2.size(0); idx++) { + auto array = py::array_t({result.f2[idx].f1.size(0), result.f2[idx].f1.size(1)}); + std::memcpy(array.request().ptr, result.f2[idx].f1.data(), array.nbytes()); + output_result.f2.append(array); + } + + for (int32_T idx{0}; idx < result.f3.size(0); idx++) { + auto array = py::array_t({result.f3[idx].f1.size(0), result.f3[idx].f1.size(1)}); + std::memcpy(array.request().ptr, result.f3[idx].f1.data(), array.nbytes()); + output_result.f3.append(array); + } + + for (int32_T idx{0}; idx < result.f4.size(0); idx++) { + auto array = py::array_t({result.f4[idx].f1.size(0), result.f4[idx].f1.size(1)}); + std::memcpy(array.request().ptr, result.f4[idx].f1.data(), array.nbytes()); + output_result.f4.append(array); + } + + for (int32_T idx{0}; idx < result.f5.size(0); idx++) { + auto array = py::array_t({result.f5[idx].f1.size(0), result.f5[idx].f1.size(1)}); + std::memcpy(array.request().ptr, result.f5[idx].f1.data(), array.nbytes()); + output_result.f5.append(array); + } + + for (int32_T idx{0}; idx < result.f6.size(0); idx++) { + auto array = py::array_t({result.f6[idx].f1.size(0), result.f6[idx].f1.size(1)}); + std::memcpy(array.request().ptr, result.f6[idx].f1.data(), array.nbytes()); + output_result.f6.append(array); + } + + return py::make_tuple(output_problem, output_result); +} + +PYBIND11_MODULE(rat, m) { + py::class_(m, "Calculation") + .def(py::init<>()) + .def_readwrite("all_chis", &Calculation::all_chis) + .def_readwrite("sum_chi", &Calculation::sum_chi); + + py::class_(m, "OutputProblem") + .def(py::init<>()) + .def_readwrite("ssubs", &OutputProblem::ssubs) + .def_readwrite("backgrounds", &OutputProblem::backgrounds) + .def_readwrite("qshifts", &OutputProblem::qshifts) + .def_readwrite("scalefactors", &OutputProblem::scalefactors) + .def_readwrite("nbairs", &OutputProblem::nbairs) + .def_readwrite("nbsubs", &OutputProblem::nbsubs) + .def_readwrite("resolutions", &OutputProblem::resolutions) + .def_readwrite("calculations", &OutputProblem::calculations) + .def_readwrite("allSubRough", &OutputProblem::allSubRough) + .def_readwrite("resample", &OutputProblem::resample); + + py::class_(m, "OutputResult") + .def(py::init<>()) + .def_readwrite("f1", &OutputResult::f1) + .def_readwrite("f2", &OutputResult::f2) + .def_readwrite("f3", &OutputResult::f3) + .def_readwrite("f4", &OutputResult::f4) + .def_readwrite("f5", &OutputResult::f5) + .def_readwrite("f6", &OutputResult::f6); + + py::class_(m, "Checks") + .def(py::init<>()) + .def_readwrite("params_fitYesNo", &Checks::params_fitYesNo) + .def_readwrite("backs_fitYesNo", &Checks::backs_fitYesNo) + .def_readwrite("shifts_fitYesNo", &Checks::shifts_fitYesNo) + .def_readwrite("scales_fitYesNo", &Checks::scales_fitYesNo) + .def_readwrite("nbairs_fitYesNo", &Checks::nbairs_fitYesNo) + .def_readwrite("nbsubs_fitYesNo", &Checks::nbsubs_fitYesNo) + .def_readwrite("resol_fitYesNo", &Checks::resol_fitYesNo) + .def_readwrite("domainRatio_fitYesNo", &Checks::domainRatio_fitYesNo); + + py::class_(m, "Limits") + .def(py::init<>()) + .def_readwrite("params", &Limits::params) + .def_readwrite("backs", &Limits::backs) + .def_readwrite("shifts", &Limits::shifts) + .def_readwrite("scales", &Limits::scales) + .def_readwrite("nba", &Limits::nba) + .def_readwrite("nbs", &Limits::nbs) + .def_readwrite("res", &Limits::res) + .def_readwrite("domainRatio", &Limits::domainRatio); + + py::class_(m, "Cells") + .def(py::init<>()) + .def_readwrite("f1", &Cells::f1) + .def_readwrite("f2", &Cells::f2) + .def_readwrite("f3", &Cells::f3) + .def_readwrite("f4", &Cells::f4) + .def_readwrite("f5", &Cells::f5) + .def_readwrite("f6", &Cells::f6) + .def_readwrite("f7", &Cells::f7) + .def_readwrite("f8", &Cells::f8) + .def_readwrite("f9", &Cells::f9) + .def_readwrite("f10", &Cells::f10) + .def_readwrite("f11", &Cells::f11) + .def_readwrite("f12", &Cells::f12) + .def_readwrite("f13", &Cells::f13) + .def_readwrite("f14", &Cells::f14) + .def_readwrite("f15", &Cells::f15) + .def_readwrite("f16", &Cells::f16) + .def_readwrite("f17", &Cells::f17) + .def_readwrite("f18", &Cells::f18) + .def_readwrite("f19", &Cells::f19) + .def_readwrite("f20", &Cells::f20); + + py::class_(m, "Control") + .def(py::init<>()) + .def_readwrite("para", &Control::para) + .def_readwrite("proc", &Control::proc) + .def_readwrite("display", &Control::display) + .def_readwrite("tolX", &Control::tolX) + .def_readwrite("tolFun", &Control::tolFun) + .def_readwrite("maxFunEvals", &Control::maxFunEvals) + .def_readwrite("maxIter", &Control::maxIter) + .def_readwrite("populationSize", &Control::populationSize) + .def_readwrite("fWeight", &Control::fWeight) + .def_readwrite("F_CR", &Control::F_CR) + .def_readwrite("VTR", &Control::VTR) + .def_readwrite("numGen", &Control::numGen) + .def_readwrite("strategy", &Control::strategy) + .def_readwrite("Nlive", &Control::Nlive) + .def_readwrite("nmcmc", &Control::nmcmc) + .def_readwrite("propScale", &Control::propScale) + .def_readwrite("nsTolerance", &Control::nsTolerance) + .def_readwrite("calcSld", &Control::calcSld) + .def_readwrite("resamPars", &Control::resamPars) + .def_readwrite("updateFreq", &Control::updateFreq) + .def_readwrite("updatePlotFreq", &Control::updatePlotFreq) + .def_readwrite("nSamples", &Control::nSamples) + .def_readwrite("nChains", &Control::nChains) + .def_readwrite("lambda", &Control::lambda) + .def_readwrite("pUnitGamma", &Control::pUnitGamma) + .def_readwrite("boundHandling", &Control::boundHandling) + .def_readwrite("checks", &Control::checks); + + py::class_(m, "ProblemDefinition") + .def(py::init<>()) + .def_readwrite("contrastBacks", &ProblemDefinition::contrastBacks) + .def_readwrite("contrastBacksType", &ProblemDefinition::contrastBacksType) + .def_readwrite("TF", &ProblemDefinition::TF) + .def_readwrite("resample", &ProblemDefinition::resample) + .def_readwrite("dataPresent", &ProblemDefinition::dataPresent) + .def_readwrite("oilChiDataPresent", &ProblemDefinition::oilChiDataPresent) + .def_readwrite("numberOfContrasts", &ProblemDefinition::numberOfContrasts) + .def_readwrite("geometry", &ProblemDefinition::geometry) + .def_readwrite("useImaginary", &ProblemDefinition::useImaginary) + .def_readwrite("contrastShifts", &ProblemDefinition::contrastShifts) + .def_readwrite("contrastScales", &ProblemDefinition::contrastScales) + .def_readwrite("contrastNbas", &ProblemDefinition::contrastNbas) + .def_readwrite("contrastNbss", &ProblemDefinition::contrastNbss) + .def_readwrite("contrastRes", &ProblemDefinition::contrastRes) + .def_readwrite("backs", &ProblemDefinition::backs) + .def_readwrite("shifts", &ProblemDefinition::shifts) + .def_readwrite("sf", &ProblemDefinition::sf) + .def_readwrite("nba", &ProblemDefinition::nba) + .def_readwrite("nbs", &ProblemDefinition::nbs) + .def_readwrite("res", &ProblemDefinition::res) + .def_readwrite("params", &ProblemDefinition::params) + .def_readwrite("numberOfLayers", &ProblemDefinition::numberOfLayers) + .def_readwrite("modelType", &ProblemDefinition::modelType) + .def_readwrite("contrastCustomFiles", &ProblemDefinition::contrastCustomFiles) + .def_readwrite("contrastDomainRatios", &ProblemDefinition::contrastDomainRatios) + .def_readwrite("domainRatio", &ProblemDefinition::domainRatio) + .def_readwrite("numberOfDomainContrasts", &ProblemDefinition::numberOfDomainContrasts) + .def_readwrite("domainContrastCustomFiles", &ProblemDefinition::domainContrastCustomFiles) + .def_readwrite("fitpars", &ProblemDefinition::fitpars) + .def_readwrite("otherpars", &ProblemDefinition::otherpars) + .def_readwrite("fitconstr", &ProblemDefinition::fitconstr) + .def_readwrite("otherconstr", &ProblemDefinition::otherconstr); + + m.def("reflectivityCalculation", &reflectivityCalculation, "A demo for Python RAT"); +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..9baee760 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +cppimport +numpy +pybind11 \ No newline at end of file From de50de3c8a7aa3538cfa78411eb3466f0c1f7866 Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Mon, 15 Jan 2024 16:26:54 +0000 Subject: [PATCH 2/8] Extends demo to call RATMAin entry point --- DSPC_bilayer_example.py | 167 ++- RAT/CoderTimeAPI.cpp | 25 + ...tyCalculation_rtwutil.h => CoderTimeAPI.h} | 12 +- RAT/DREAMWrapper.cpp | 62 + RAT/DREAMWrapper.h | 38 + RAT/RATMain.cpp | 1093 ++++++++++++++++ RAT/RATMain.h | 31 + RAT/RATMain_data.cpp | 177 +++ RAT/RATMain_data.h | 38 + RAT/RATMain_initialize.cpp | 43 + ...ation_terminate.h => RATMain_initialize.h} | 12 +- RAT/RATMain_internal_types.h | 182 +++ RAT/RATMain_rtwutil.cpp | 248 ++++ RAT/RATMain_rtwutil.h | 43 + RAT/RATMain_terminate.cpp | 28 + RAT/RATMain_terminate.h | 26 + RAT/RATMain_types.h | 411 ++++++ RAT/SLDFunction.cpp | 91 +- RAT/SLDFunction.h | 8 +- RAT/abelesParallelPoints.cpp | 43 +- RAT/abelesSingle.cpp | 336 +++-- RAT/abs.cpp | 67 + RAT/abs.h | 35 + RAT/acos.cpp | 4 +- RAT/adaptPCR.cpp | 68 + RAT/adaptPCR.h | 36 + RAT/adaptive.cpp | 435 ++++--- RAT/adaptive.h | 9 +- RAT/all.cpp | 45 + RAT/all.h | 31 + RAT/allOrAny.cpp | 38 + RAT/allOrAny.h | 3 + RAT/allocateLayersForContrast.cpp | 9 +- RAT/allocateLayersForContrast.h | 4 +- RAT/allocateParamsToLayers.cpp | 10 +- RAT/allocateParamsToLayers.h | 4 +- RAT/anyNonFinite.cpp | 44 + RAT/anyNonFinite.h | 33 + RAT/applyBackgroundCorrection.cpp | 28 +- RAT/applyBackgroundCorrection.h | 4 +- RAT/applyHydrationImag.cpp | 97 ++ RAT/applyHydrationImag.h | 28 + RAT/applyHydrationReal.cpp | 90 ++ RAT/applyHydrationReal.h | 28 + RAT/averageReflectivity.cpp | 67 + RAT/averageReflectivity.h | 33 + RAT/backSort.cpp | 95 +- RAT/backSort.h | 17 +- RAT/blockedSummation.cpp | 310 +++++ RAT/blockedSummation.h | 9 + RAT/boundaryHandling.cpp | 282 ++++ RAT/boundaryHandling.h | 31 + RAT/bsearch.cpp | 37 + RAT/bsearch.h | 2 + RAT/bsxfun.cpp | 372 ++++++ RAT/bsxfun.h | 47 + RAT/calcDensity.cpp | 165 +++ RAT/calcDensity.h | 37 + RAT/calcEllipsoid.cpp | 220 ++++ RAT/calcEllipsoid.h | 29 + RAT/calcProposal.cpp | 580 +++++++++ RAT/calcProposal.h | 39 + RAT/calculate.cpp | 165 +++ RAT/calculate.h | 47 + RAT/calculate1.cpp | 163 +++ RAT/calculate1.h | 47 + RAT/calculate2.cpp | 163 +++ RAT/calculate2.h | 47 + RAT/calculate3.cpp | 246 ++++ RAT/calculate3.h | 47 + RAT/calculate4.cpp | 209 +++ RAT/calculate4.h | 48 + RAT/calculate5.cpp | 209 +++ RAT/calculate5.h | 48 + RAT/callCppFunc.cpp | 85 -- RAT/callCppFunc.h | 32 - RAT/callCppFunction.cpp | 168 +++ RAT/callCppFunction.h | 36 + RAT/callReflectivity.cpp | 299 +++-- RAT/callReflectivity.h | 20 +- RAT/cat.cpp | 61 + RAT/cat.h | 29 + RAT/chiSquared.cpp | 5 +- RAT/classHandle.hpp | 57 + RAT/coder_posix_time.c | 162 +++ RAT/coder_posix_time.h | 73 ++ RAT/colon.cpp | 21 + RAT/colon.h | 1 + RAT/combineVectorElements.cpp | 186 +++ RAT/combineVectorElements.h | 40 + RAT/complexTimes.cpp | 8 +- RAT/coreLayersCalculation.cpp | 692 ++++++++++ RAT/coreLayersCalculation.h | 53 + RAT/cov.cpp | 149 +++ RAT/cov.h | 30 + RAT/customModelClass.cpp | 483 ------- RAT/customModelClass.h | 59 - RAT/deopt.cpp | 833 ++++++++++++ RAT/deopt.h | 47 + RAT/det.cpp | 68 + RAT/det.h | 30 + RAT/diag.cpp | 132 ++ RAT/diag.h | 33 + RAT/div.cpp | 69 + RAT/div.h | 31 + RAT/drawCR.cpp | 124 ++ RAT/drawCR.h | 34 + RAT/drawEllipsoidPoints.cpp | 146 +++ RAT/drawEllipsoidPoints.h | 28 + RAT/drawMCMC.cpp | 331 +++++ RAT/drawMCMC.h | 39 + RAT/drawMultiNest.cpp | 152 +++ RAT/drawMultiNest.h | 40 + RAT/eig.cpp | 101 ++ RAT/eig.h | 31 + RAT/eigHermitianStandard.cpp | 35 + ...on_initialize.h => eigHermitianStandard.h} | 16 +- RAT/eigRealSkewSymmetricStandard.cpp | 122 ++ RAT/eigRealSkewSymmetricStandard.h | 33 + RAT/eigSkewHermitianStandard.cpp | 35 + RAT/eigSkewHermitianStandard.h | 31 + RAT/eml_erfcore.cpp | 53 +- RAT/eml_mtimes_helper.cpp | 110 ++ RAT/eml_mtimes_helper.h | 9 + RAT/eml_rand_mt19937ar.cpp | 170 +++ RAT/eml_rand_mt19937ar.h | 31 + RAT/eml_rand_mt19937ar_stateful.cpp | 35 + RAT/eml_rand_mt19937ar_stateful.h | 26 + RAT/eml_setop.cpp | 112 ++ RAT/eml_setop.h | 32 + RAT/eps.cpp | 41 + RAT/eps.h | 29 + RAT/evaluateModel.cpp | 69 + RAT/evaluateModel.h | 39 + RAT/eventHelper.hpp | 17 +- RAT/examples/main.cpp | 368 +++--- RAT/examples/main.h | 2 +- RAT/eye.cpp | 41 + RAT/eye.h | 30 + RAT/fMinSearch.cpp | 1131 +++++++++++++++++ RAT/fMinSearch.h | 48 + RAT/fileManager.cpp | 57 + RAT/fileManager.h | 31 + RAT/find.cpp | 256 ++++ RAT/find.h | 11 + RAT/gamma.cpp | 93 ++ RAT/gamma.h | 29 + RAT/gelman.cpp | 190 +++ RAT/gelman.h | 34 + RAT/getFittedPriors.cpp | 85 ++ RAT/getFittedPriors.h | 32 + RAT/getTime.cpp | 43 + RAT/getTime.h | 35 + RAT/groupLayersMod.cpp | 43 +- RAT/groupLayersMod.h | 2 +- RAT/groupLayersModImaginary.cpp | 103 +- RAT/groupLayersModImaginary.h | 2 +- RAT/histc.cpp | 115 ++ RAT/histc.h | 33 + RAT/ifWhileCond.cpp | 71 ++ RAT/ifWhileCond.h | 33 + RAT/inEllipsoids.cpp | 219 ++++ RAT/inEllipsoids.h | 29 + RAT/initializeDREAM.cpp | 419 ++++++ RAT/initializeDREAM.h | 50 + RAT/interp1.cpp | 221 ++++ RAT/interp1.h | 6 + RAT/ishermitian.cpp | 97 ++ RAT/ishermitian.h | 31 + RAT/isrow.cpp | 28 + RAT/isrow.h | 30 + RAT/ixamax.cpp | 80 ++ RAT/ixamax.h | 39 + RAT/ixfun.cpp | 72 ++ RAT/ixfun.h | 34 + RAT/kmeans.cpp | 316 +++++ RAT/kmeans.h | 28 + RAT/leftWin.cpp | 51 + RAT/leftWin.h | 26 + RAT/libManager.h | 48 - RAT/log2.cpp | 15 + RAT/log2.h | 3 + RAT/logPlus.cpp | 43 + RAT/logPlus.h | 26 + RAT/lower.cpp | 4 +- RAT/lusolve.cpp | 74 ++ RAT/lusolve.h | 34 + RAT/makeCell.cpp | 194 +++ RAT/makeCell.h | 34 + RAT/makeD.cpp | 111 ++ RAT/makeD.h | 31 + RAT/makeEmptyBayesResultsStruct.cpp | 646 ++++++++++ RAT/makeEmptyBayesResultsStruct.h | 65 + RAT/makeSLDProfileXY.cpp | 91 +- RAT/makeSLDProfileXY.h | 6 +- RAT/makeSLDProfiles.cpp | 8 +- RAT/makeSLDProfiles.h | 6 +- RAT/matrix_to_integer_power.cpp | 213 ++++ RAT/matrix_to_integer_power.h | 30 + RAT/mchol.cpp | 476 +++++++ RAT/mchol.h | 28 + RAT/mean.cpp | 89 ++ RAT/mean.h | 32 + RAT/mergesort.cpp | 234 ++++ RAT/mergesort.h | 5 + RAT/metropolisRule.cpp | 185 +++ RAT/metropolisRule.h | 38 + RAT/minOrMax.cpp | 349 ++++- RAT/minOrMax.h | 15 +- RAT/mod.cpp | 56 + RAT/mod.h | 30 + RAT/mrdivide_helper.cpp | 204 +++ RAT/mrdivide_helper.h | 42 + RAT/mtimes.cpp | 174 +++ RAT/mtimes.h | 48 + RAT/multrnd.cpp | 200 +++ RAT/multrnd.h | 27 + RAT/nest2pos.cpp | 246 ++++ RAT/nest2pos.h | 28 + RAT/nestedSampler.cpp | 687 ++++++++++ RAT/nestedSampler.h | 39 + RAT/nonSingletonDim.cpp | 48 + RAT/nonSingletonDim.h | 34 + RAT/norm.cpp | 131 ++ RAT/norm.h | 32 + RAT/nsIntraFun.cpp | 74 ++ RAT/nsIntraFun.h | 38 + RAT/nullAssignment.cpp | 68 + RAT/nullAssignment.h | 3 + RAT/optimalEllipsoids.cpp | 449 +++++++ RAT/optimalEllipsoids.h | 29 + RAT/packParams.cpp | 333 +++++ RAT/packParams.h | 37 + RAT/parallelContrasts.cpp | 262 ++++ RAT/parallelContrasts.h | 50 + RAT/parallelContrasts1.cpp | 250 ++++ RAT/parallelContrasts1.h | 50 + RAT/parallelContrasts2.cpp | 250 ++++ RAT/parallelContrasts2.h | 50 + RAT/parallelContrasts3.cpp | 392 ++++++ RAT/parallelContrasts3.h | 50 + RAT/parallelContrasts4.cpp | 367 ++++++ RAT/parallelContrasts4.h | 50 + RAT/parallelContrasts5.cpp | 405 ++++++ RAT/parallelContrasts5.h | 50 + RAT/parallelPoints.cpp | 205 +++ RAT/parallelPoints.h | 54 + RAT/parallelPoints1.cpp | 206 +++ RAT/parallelPoints1.h | 54 + RAT/parallelPoints2.cpp | 225 ++++ RAT/parallelPoints2.h | 54 + RAT/parallelPoints3.cpp | 348 +++++ RAT/parallelPoints3.h | 54 + RAT/parallelPoints4.cpp | 340 +++++ RAT/parallelPoints4.h | 54 + RAT/parallelPoints5.cpp | 411 ++++++ RAT/parallelPoints5.h | 54 + RAT/pow2.cpp | 36 + RAT/pow2.h | 30 + RAT/prctile.cpp | 371 ++++++ RAT/prctile.h | 36 + RAT/prctileConfInts.cpp | 32 + RAT/prctileConfInts.h | 30 + RAT/processBayes.cpp | 252 ++++ RAT/processBayes.h | 53 + RAT/processCustomFunction.cpp | 169 +++ RAT/processCustomFunction.h | 46 + RAT/processCustomFunction1.cpp | 146 +++ RAT/processCustomFunction1.h | 46 + RAT/processCustomFunction2.cpp | 270 ++++ RAT/processCustomFunction2.h | 46 + RAT/processCustomFunction3.cpp | 173 +++ RAT/processCustomFunction3.h | 46 + RAT/qrsolve.cpp | 175 +++ RAT/qrsolve.h | 39 + RAT/rand.cpp | 383 ++++++ RAT/rand.h | 38 + RAT/randn.cpp | 132 ++ RAT/randn.h | 34 + RAT/randperm.cpp | 38 + RAT/randperm.h | 30 + RAT/randsample.cpp | 82 ++ RAT/randsample.h | 33 + RAT/ratDREAM.cpp | 820 ++++++++++++ RAT/ratDREAM.h | 46 + RAT/rcond.cpp | 239 ++++ RAT/rcond.h | 30 + RAT/rdivide_helper.cpp | 47 + RAT/rdivide_helper.h | 28 + RAT/refPrctileConfInts.cpp | 387 ++++++ RAT/refPrctileConfInts.h | 38 + RAT/reflectivityCalculation.cpp | 652 ++++++---- RAT/reflectivityCalculation.h | 17 +- RAT/reflectivityCalculation1.cpp | 153 +++ RAT/reflectivityCalculation1.h | 43 + RAT/reflectivityCalculation2.cpp | 229 ++++ RAT/reflectivityCalculation2.h | 43 + RAT/reflectivityCalculation_data.cpp | 32 - RAT/reflectivityCalculation_data.h | 28 - RAT/reflectivityCalculation_initialize.cpp | 29 - RAT/reflectivityCalculation_internal_types.h | 64 - RAT/reflectivityCalculation_rtwutil.cpp | 42 - RAT/reflectivityCalculation_terminate.cpp | 26 - RAT/reflectivityCalculation_types.h | 220 ---- RAT/relop.cpp | 14 + RAT/relop.h | 1 + RAT/removeOutlier.cpp | 261 ++++ RAT/removeOutlier.h | 36 + RAT/repmat.cpp | 61 + RAT/repmat.h | 13 + RAT/resampleLayers.cpp | 4 +- RAT/resampleLayersReIm.cpp | 65 +- RAT/resampleLayersReIm.h | 9 +- RAT/rescale.cpp | 133 ++ RAT/rescale.h | 34 + RAT/rescaleKernel.cpp | 953 ++++++++++++++ RAT/rescaleKernel.h | 32 + RAT/rescaleParameters.cpp | 62 + RAT/rescaleParameters.h | 28 + RAT/reshapeSizeChecks.cpp | 42 + RAT/reshapeSizeChecks.h | 32 + RAT/rng.cpp | 38 + RAT/rng.h | 29 + RAT/rtGetInf.cpp | 2 +- RAT/rtGetInf.h | 2 +- RAT/rtGetNaN.cpp | 2 +- RAT/rtGetNaN.h | 2 +- RAT/rt_defines.h | 2 +- RAT/rt_nonfinite.cpp | 2 +- RAT/rt_nonfinite.h | 2 +- RAT/rtwtypes.h | 2 +- RAT/runDE.cpp | 361 ++++++ RAT/runDE.h | 51 + RAT/runDREAM.cpp | 328 +++++ RAT/runDREAM.h | 42 + RAT/runNestedSampler.cpp | 273 ++++ RAT/runNestedSampler.h | 43 + RAT/runSimplex.cpp | 324 +++++ RAT/runSimplex.h | 39 + RAT/scaleParameters.cpp | 78 ++ RAT/scaleParameters.h | 29 + RAT/scaledGaussPrior.cpp | 156 +++ RAT/scaledGaussPrior.h | 29 + RAT/schur.cpp | 84 ++ RAT/schur.h | 31 + RAT/setupDREAM.cpp | 274 ++++ RAT/setupDREAM.h | 40 + RAT/shiftData.cpp | 54 +- RAT/shiftData.h | 5 +- RAT/simplexIntrafun.cpp | 113 ++ RAT/simplexIntrafun.h | 47 + RAT/simplexXTransform.cpp | 62 + RAT/simplexXTransform.h | 30 + RAT/single.cpp | 207 +++ RAT/single.h | 52 + RAT/single1.cpp | 207 +++ RAT/single1.h | 52 + RAT/single2.cpp | 221 ++++ RAT/single2.h | 52 + RAT/single3.cpp | 346 +++++ RAT/single3.h | 52 + RAT/single4.cpp | 336 +++++ RAT/single4.h | 52 + RAT/single5.cpp | 407 ++++++ RAT/single5.h | 52 + RAT/sort.cpp | 338 +++++ RAT/sort.h | 36 + RAT/sortIdx.cpp | 619 +++++++++ RAT/sortIdx.h | 12 + RAT/sortLE.cpp | 44 + RAT/sortLE.h | 5 + RAT/splitEllipsoid.cpp | 550 ++++++++ RAT/splitEllipsoid.h | 30 + RAT/sprintf.cpp | 73 ++ RAT/sprintf.h | 33 + RAT/sqrt.cpp | 4 +- RAT/sqrt.h | 2 +- RAT/sqrt1.cpp | 46 + RAT/sqrt1.h | 31 + ...tandardTFCustomLayersParallelContrasts.cpp | 227 ---- RAT/standardTFCustomLayersParallelContrasts.h | 38 - RAT/standardTFCustomLayersParallelPoints.cpp | 191 --- RAT/standardTFCustomLayersParallelPoints.h | 38 - ...dTFCustomLayersReflectivityCalculation.cpp | 152 --- ...ardTFCustomLayersReflectivityCalculation.h | 34 - RAT/standardTFCustomLayersSingle.cpp | 193 --- RAT/standardTFCustomLayersSingle.h | 38 - RAT/standardTFCustomXYParallelContrasts.cpp | 232 ---- RAT/standardTFCustomXYParallelContrasts.h | 38 - RAT/standardTFCustomXYParallelPoints.cpp | 204 --- RAT/standardTFCustomXYParallelPoints.h | 38 - ...ndardTFCustomXYReflectivityCalculation.cpp | 152 --- ...tandardTFCustomXYReflectivityCalculation.h | 34 - RAT/standardTFCustomXYSingle.cpp | 202 --- RAT/standardTFCustomXYSingle.h | 38 - RAT/standardTFLayersCore.cpp | 683 ---------- RAT/standardTFLayersCore.h | 48 - RAT/standardTFReflectivityCalculation.cpp | 151 --- RAT/standardTFReflectivityCalculation.h | 34 - ...ndardTFStandardLayersParallelContrasts.cpp | 241 ---- ...tandardTFStandardLayersParallelContrasts.h | 38 - ...standardTFStandardLayersParallelPoints.cpp | 204 --- RAT/standardTFStandardLayersParallelPoints.h | 38 - ...FStandardLayersReflectivityCalculation.cpp | 154 --- ...dTFStandardLayersReflectivityCalculation.h | 34 - RAT/standardTFStandardLayersSingle.cpp | 208 --- RAT/standardTFStandardLayersSingle.h | 38 - RAT/std.cpp | 59 + RAT/std.h | 31 + RAT/str2double.cpp | 98 ++ RAT/str2double.h | 29 + RAT/str2double1.cpp | 478 +++++++ RAT/str2double1.h | 38 + RAT/strcmp.cpp | 573 ++++++++- RAT/strcmp.h | 26 + RAT/structConstructorHelper.cpp | 105 ++ RAT/structConstructorHelper.h | 51 + RAT/sum.cpp | 39 + RAT/sum.h | 3 + RAT/textProgressBar.cpp | 89 ++ RAT/textProgressBar.h | 27 + RAT/tic.cpp | 37 + RAT/tic.h | 29 + RAT/timeKeeper.cpp | 62 + RAT/timeKeeper.h | 41 + RAT/toc.cpp | 36 + RAT/toc.h | 29 + RAT/triggerEvent.cpp | 372 +++++- RAT/triggerEvent.h | 13 +- RAT/triu.cpp | 71 ++ RAT/triu.h | 31 + RAT/unpackParams.cpp | 276 ++++ RAT/unpackParams.h | 42 + RAT/unsafeSxfun.cpp | 298 +++++ RAT/unsafeSxfun.h | 10 + RAT/useConstantDim.cpp | 63 + RAT/useConstantDim.h | 34 + RAT/vAllOrAny.cpp | 93 ++ RAT/vAllOrAny.h | 36 + RAT/validate_print_arguments.cpp | 44 + RAT/validate_print_arguments.h | 36 + RAT/var.cpp | 58 + RAT/var.h | 30 + RAT/varstd.cpp | 80 ++ RAT/varstd.h | 31 + RAT/xdhseqr.cpp | 388 ++++++ RAT/xdhseqr.h | 37 + RAT/xdlanv2.cpp | 179 +++ RAT/xdlanv2.h | 37 + RAT/xgehrd.cpp | 78 ++ RAT/xgehrd.h | 37 + RAT/xgemm.cpp | 84 ++ RAT/xgemm.h | 41 + RAT/xgemv.cpp | 125 ++ RAT/xgemv.h | 44 + RAT/xgeqp3.cpp | 89 ++ RAT/xgeqp3.h | 37 + RAT/xgerc.cpp | 76 ++ RAT/xgerc.h | 41 + RAT/xgeru.cpp | 50 + RAT/xgeru.h | 37 + RAT/xgetrf.cpp | 172 +++ RAT/xgetrf.h | 41 + RAT/xnrm2.cpp | 235 ++++ RAT/xnrm2.h | 42 + RAT/xrot.cpp | 63 + RAT/xrot.h | 39 + RAT/xswap.cpp | 59 + RAT/xswap.h | 39 + RAT/xtrsm.cpp | 89 ++ RAT/xtrsm.h | 39 + RAT/xtrsv.cpp | 102 ++ RAT/xtrsv.h | 43 + RAT/xungorghr.cpp | 74 ++ RAT/xungorghr.h | 37 + RAT/xunormqr.cpp | 102 ++ RAT/xunormqr.h | 39 + RAT/xzgeev.cpp | 83 ++ RAT/xzgeev.h | 38 + RAT/xzgeqp3.cpp | 220 ++++ RAT/xzgeqp3.h | 39 + RAT/xzggbak.cpp | 72 ++ RAT/xzggbak.h | 37 + RAT/xzggbal.cpp | 202 +++ RAT/xzggbal.h | 37 + RAT/xzggev.cpp | 153 +++ RAT/xzggev.h | 38 + RAT/xzgghrd.cpp | 125 ++ RAT/xzgghrd.h | 37 + RAT/xzhgeqz.cpp | 654 ++++++++++ RAT/xzhgeqz.h | 38 + RAT/xzlangeM.cpp | 63 + RAT/xzlangeM.h | 36 + RAT/xzlanhs.cpp | 96 ++ RAT/xzlanhs.h | 37 + RAT/xzlarf.cpp | 198 +++ RAT/xzlarf.h | 44 + RAT/xzlarfg.cpp | 214 ++++ RAT/xzlarfg.h | 39 + RAT/xzlartg.cpp | 282 ++++ RAT/xzlartg.h | 37 + RAT/xzlascl.cpp | 102 ++ RAT/xzlascl.h | 37 + RAT/xztgevc.cpp | 338 +++++ RAT/xztgevc.h | 37 + RAT/xzungqr.cpp | 86 ++ RAT/xzungqr.h | 38 + README.md | 8 + rat.cpp | 1051 ++++++++++----- 509 files changed, 51151 insertions(+), 6679 deletions(-) create mode 100644 RAT/CoderTimeAPI.cpp rename RAT/{reflectivityCalculation_rtwutil.h => CoderTimeAPI.h} (51%) create mode 100644 RAT/DREAMWrapper.cpp create mode 100644 RAT/DREAMWrapper.h create mode 100644 RAT/RATMain.cpp create mode 100644 RAT/RATMain.h create mode 100644 RAT/RATMain_data.cpp create mode 100644 RAT/RATMain_data.h create mode 100644 RAT/RATMain_initialize.cpp rename RAT/{reflectivityCalculation_terminate.h => RATMain_initialize.h} (50%) create mode 100644 RAT/RATMain_internal_types.h create mode 100644 RAT/RATMain_rtwutil.cpp create mode 100644 RAT/RATMain_rtwutil.h create mode 100644 RAT/RATMain_terminate.cpp create mode 100644 RAT/RATMain_terminate.h create mode 100644 RAT/RATMain_types.h create mode 100644 RAT/abs.cpp create mode 100644 RAT/abs.h create mode 100644 RAT/adaptPCR.cpp create mode 100644 RAT/adaptPCR.h create mode 100644 RAT/all.cpp create mode 100644 RAT/all.h create mode 100644 RAT/anyNonFinite.cpp create mode 100644 RAT/anyNonFinite.h create mode 100644 RAT/applyHydrationImag.cpp create mode 100644 RAT/applyHydrationImag.h create mode 100644 RAT/applyHydrationReal.cpp create mode 100644 RAT/applyHydrationReal.h create mode 100644 RAT/averageReflectivity.cpp create mode 100644 RAT/averageReflectivity.h create mode 100644 RAT/boundaryHandling.cpp create mode 100644 RAT/boundaryHandling.h create mode 100644 RAT/bsxfun.cpp create mode 100644 RAT/bsxfun.h create mode 100644 RAT/calcDensity.cpp create mode 100644 RAT/calcDensity.h create mode 100644 RAT/calcEllipsoid.cpp create mode 100644 RAT/calcEllipsoid.h create mode 100644 RAT/calcProposal.cpp create mode 100644 RAT/calcProposal.h create mode 100644 RAT/calculate.cpp create mode 100644 RAT/calculate.h create mode 100644 RAT/calculate1.cpp create mode 100644 RAT/calculate1.h create mode 100644 RAT/calculate2.cpp create mode 100644 RAT/calculate2.h create mode 100644 RAT/calculate3.cpp create mode 100644 RAT/calculate3.h create mode 100644 RAT/calculate4.cpp create mode 100644 RAT/calculate4.h create mode 100644 RAT/calculate5.cpp create mode 100644 RAT/calculate5.h delete mode 100644 RAT/callCppFunc.cpp delete mode 100644 RAT/callCppFunc.h create mode 100644 RAT/callCppFunction.cpp create mode 100644 RAT/callCppFunction.h create mode 100644 RAT/cat.cpp create mode 100644 RAT/cat.h create mode 100644 RAT/classHandle.hpp create mode 100644 RAT/coder_posix_time.c create mode 100644 RAT/coder_posix_time.h create mode 100644 RAT/combineVectorElements.cpp create mode 100644 RAT/combineVectorElements.h create mode 100644 RAT/coreLayersCalculation.cpp create mode 100644 RAT/coreLayersCalculation.h create mode 100644 RAT/cov.cpp create mode 100644 RAT/cov.h delete mode 100644 RAT/customModelClass.cpp delete mode 100644 RAT/customModelClass.h create mode 100644 RAT/deopt.cpp create mode 100644 RAT/deopt.h create mode 100644 RAT/det.cpp create mode 100644 RAT/det.h create mode 100644 RAT/diag.cpp create mode 100644 RAT/diag.h create mode 100644 RAT/div.cpp create mode 100644 RAT/div.h create mode 100644 RAT/drawCR.cpp create mode 100644 RAT/drawCR.h create mode 100644 RAT/drawEllipsoidPoints.cpp create mode 100644 RAT/drawEllipsoidPoints.h create mode 100644 RAT/drawMCMC.cpp create mode 100644 RAT/drawMCMC.h create mode 100644 RAT/drawMultiNest.cpp create mode 100644 RAT/drawMultiNest.h create mode 100644 RAT/eig.cpp create mode 100644 RAT/eig.h create mode 100644 RAT/eigHermitianStandard.cpp rename RAT/{reflectivityCalculation_initialize.h => eigHermitianStandard.h} (50%) create mode 100644 RAT/eigRealSkewSymmetricStandard.cpp create mode 100644 RAT/eigRealSkewSymmetricStandard.h create mode 100644 RAT/eigSkewHermitianStandard.cpp create mode 100644 RAT/eigSkewHermitianStandard.h create mode 100644 RAT/eml_rand_mt19937ar.cpp create mode 100644 RAT/eml_rand_mt19937ar.h create mode 100644 RAT/eml_rand_mt19937ar_stateful.cpp create mode 100644 RAT/eml_rand_mt19937ar_stateful.h create mode 100644 RAT/eml_setop.cpp create mode 100644 RAT/eml_setop.h create mode 100644 RAT/eps.cpp create mode 100644 RAT/eps.h create mode 100644 RAT/evaluateModel.cpp create mode 100644 RAT/evaluateModel.h create mode 100644 RAT/eye.cpp create mode 100644 RAT/eye.h create mode 100644 RAT/fMinSearch.cpp create mode 100644 RAT/fMinSearch.h create mode 100644 RAT/fileManager.cpp create mode 100644 RAT/fileManager.h create mode 100644 RAT/gamma.cpp create mode 100644 RAT/gamma.h create mode 100644 RAT/gelman.cpp create mode 100644 RAT/gelman.h create mode 100644 RAT/getFittedPriors.cpp create mode 100644 RAT/getFittedPriors.h create mode 100644 RAT/getTime.cpp create mode 100644 RAT/getTime.h create mode 100644 RAT/histc.cpp create mode 100644 RAT/histc.h create mode 100644 RAT/ifWhileCond.cpp create mode 100644 RAT/ifWhileCond.h create mode 100644 RAT/inEllipsoids.cpp create mode 100644 RAT/inEllipsoids.h create mode 100644 RAT/initializeDREAM.cpp create mode 100644 RAT/initializeDREAM.h create mode 100644 RAT/ishermitian.cpp create mode 100644 RAT/ishermitian.h create mode 100644 RAT/isrow.cpp create mode 100644 RAT/isrow.h create mode 100644 RAT/ixamax.cpp create mode 100644 RAT/ixamax.h create mode 100644 RAT/ixfun.cpp create mode 100644 RAT/ixfun.h create mode 100644 RAT/kmeans.cpp create mode 100644 RAT/kmeans.h create mode 100644 RAT/leftWin.cpp create mode 100644 RAT/leftWin.h delete mode 100644 RAT/libManager.h create mode 100644 RAT/logPlus.cpp create mode 100644 RAT/logPlus.h create mode 100644 RAT/lusolve.cpp create mode 100644 RAT/lusolve.h create mode 100644 RAT/makeCell.cpp create mode 100644 RAT/makeCell.h create mode 100644 RAT/makeD.cpp create mode 100644 RAT/makeD.h create mode 100644 RAT/makeEmptyBayesResultsStruct.cpp create mode 100644 RAT/makeEmptyBayesResultsStruct.h create mode 100644 RAT/matrix_to_integer_power.cpp create mode 100644 RAT/matrix_to_integer_power.h create mode 100644 RAT/mchol.cpp create mode 100644 RAT/mchol.h create mode 100644 RAT/mean.cpp create mode 100644 RAT/mean.h create mode 100644 RAT/metropolisRule.cpp create mode 100644 RAT/metropolisRule.h create mode 100644 RAT/mod.cpp create mode 100644 RAT/mod.h create mode 100644 RAT/mrdivide_helper.cpp create mode 100644 RAT/mrdivide_helper.h create mode 100644 RAT/mtimes.cpp create mode 100644 RAT/mtimes.h create mode 100644 RAT/multrnd.cpp create mode 100644 RAT/multrnd.h create mode 100644 RAT/nest2pos.cpp create mode 100644 RAT/nest2pos.h create mode 100644 RAT/nestedSampler.cpp create mode 100644 RAT/nestedSampler.h create mode 100644 RAT/nonSingletonDim.cpp create mode 100644 RAT/nonSingletonDim.h create mode 100644 RAT/norm.cpp create mode 100644 RAT/norm.h create mode 100644 RAT/nsIntraFun.cpp create mode 100644 RAT/nsIntraFun.h create mode 100644 RAT/optimalEllipsoids.cpp create mode 100644 RAT/optimalEllipsoids.h create mode 100644 RAT/packParams.cpp create mode 100644 RAT/packParams.h create mode 100644 RAT/parallelContrasts.cpp create mode 100644 RAT/parallelContrasts.h create mode 100644 RAT/parallelContrasts1.cpp create mode 100644 RAT/parallelContrasts1.h create mode 100644 RAT/parallelContrasts2.cpp create mode 100644 RAT/parallelContrasts2.h create mode 100644 RAT/parallelContrasts3.cpp create mode 100644 RAT/parallelContrasts3.h create mode 100644 RAT/parallelContrasts4.cpp create mode 100644 RAT/parallelContrasts4.h create mode 100644 RAT/parallelContrasts5.cpp create mode 100644 RAT/parallelContrasts5.h create mode 100644 RAT/parallelPoints.cpp create mode 100644 RAT/parallelPoints.h create mode 100644 RAT/parallelPoints1.cpp create mode 100644 RAT/parallelPoints1.h create mode 100644 RAT/parallelPoints2.cpp create mode 100644 RAT/parallelPoints2.h create mode 100644 RAT/parallelPoints3.cpp create mode 100644 RAT/parallelPoints3.h create mode 100644 RAT/parallelPoints4.cpp create mode 100644 RAT/parallelPoints4.h create mode 100644 RAT/parallelPoints5.cpp create mode 100644 RAT/parallelPoints5.h create mode 100644 RAT/pow2.cpp create mode 100644 RAT/pow2.h create mode 100644 RAT/prctile.cpp create mode 100644 RAT/prctile.h create mode 100644 RAT/prctileConfInts.cpp create mode 100644 RAT/prctileConfInts.h create mode 100644 RAT/processBayes.cpp create mode 100644 RAT/processBayes.h create mode 100644 RAT/processCustomFunction.cpp create mode 100644 RAT/processCustomFunction.h create mode 100644 RAT/processCustomFunction1.cpp create mode 100644 RAT/processCustomFunction1.h create mode 100644 RAT/processCustomFunction2.cpp create mode 100644 RAT/processCustomFunction2.h create mode 100644 RAT/processCustomFunction3.cpp create mode 100644 RAT/processCustomFunction3.h create mode 100644 RAT/qrsolve.cpp create mode 100644 RAT/qrsolve.h create mode 100644 RAT/rand.cpp create mode 100644 RAT/rand.h create mode 100644 RAT/randn.cpp create mode 100644 RAT/randn.h create mode 100644 RAT/randperm.cpp create mode 100644 RAT/randperm.h create mode 100644 RAT/randsample.cpp create mode 100644 RAT/randsample.h create mode 100644 RAT/ratDREAM.cpp create mode 100644 RAT/ratDREAM.h create mode 100644 RAT/rcond.cpp create mode 100644 RAT/rcond.h create mode 100644 RAT/rdivide_helper.cpp create mode 100644 RAT/rdivide_helper.h create mode 100644 RAT/refPrctileConfInts.cpp create mode 100644 RAT/refPrctileConfInts.h create mode 100644 RAT/reflectivityCalculation1.cpp create mode 100644 RAT/reflectivityCalculation1.h create mode 100644 RAT/reflectivityCalculation2.cpp create mode 100644 RAT/reflectivityCalculation2.h delete mode 100644 RAT/reflectivityCalculation_data.cpp delete mode 100644 RAT/reflectivityCalculation_data.h delete mode 100644 RAT/reflectivityCalculation_initialize.cpp delete mode 100644 RAT/reflectivityCalculation_internal_types.h delete mode 100644 RAT/reflectivityCalculation_rtwutil.cpp delete mode 100644 RAT/reflectivityCalculation_terminate.cpp delete mode 100644 RAT/reflectivityCalculation_types.h create mode 100644 RAT/removeOutlier.cpp create mode 100644 RAT/removeOutlier.h create mode 100644 RAT/rescale.cpp create mode 100644 RAT/rescale.h create mode 100644 RAT/rescaleKernel.cpp create mode 100644 RAT/rescaleKernel.h create mode 100644 RAT/rescaleParameters.cpp create mode 100644 RAT/rescaleParameters.h create mode 100644 RAT/reshapeSizeChecks.cpp create mode 100644 RAT/reshapeSizeChecks.h create mode 100644 RAT/rng.cpp create mode 100644 RAT/rng.h create mode 100644 RAT/runDE.cpp create mode 100644 RAT/runDE.h create mode 100644 RAT/runDREAM.cpp create mode 100644 RAT/runDREAM.h create mode 100644 RAT/runNestedSampler.cpp create mode 100644 RAT/runNestedSampler.h create mode 100644 RAT/runSimplex.cpp create mode 100644 RAT/runSimplex.h create mode 100644 RAT/scaleParameters.cpp create mode 100644 RAT/scaleParameters.h create mode 100644 RAT/scaledGaussPrior.cpp create mode 100644 RAT/scaledGaussPrior.h create mode 100644 RAT/schur.cpp create mode 100644 RAT/schur.h create mode 100644 RAT/setupDREAM.cpp create mode 100644 RAT/setupDREAM.h create mode 100644 RAT/simplexIntrafun.cpp create mode 100644 RAT/simplexIntrafun.h create mode 100644 RAT/simplexXTransform.cpp create mode 100644 RAT/simplexXTransform.h create mode 100644 RAT/single.cpp create mode 100644 RAT/single.h create mode 100644 RAT/single1.cpp create mode 100644 RAT/single1.h create mode 100644 RAT/single2.cpp create mode 100644 RAT/single2.h create mode 100644 RAT/single3.cpp create mode 100644 RAT/single3.h create mode 100644 RAT/single4.cpp create mode 100644 RAT/single4.h create mode 100644 RAT/single5.cpp create mode 100644 RAT/single5.h create mode 100644 RAT/sort.cpp create mode 100644 RAT/sort.h create mode 100644 RAT/splitEllipsoid.cpp create mode 100644 RAT/splitEllipsoid.h create mode 100644 RAT/sprintf.cpp create mode 100644 RAT/sprintf.h create mode 100644 RAT/sqrt1.cpp create mode 100644 RAT/sqrt1.h delete mode 100644 RAT/standardTFCustomLayersParallelContrasts.cpp delete mode 100644 RAT/standardTFCustomLayersParallelContrasts.h delete mode 100644 RAT/standardTFCustomLayersParallelPoints.cpp delete mode 100644 RAT/standardTFCustomLayersParallelPoints.h delete mode 100644 RAT/standardTFCustomLayersReflectivityCalculation.cpp delete mode 100644 RAT/standardTFCustomLayersReflectivityCalculation.h delete mode 100644 RAT/standardTFCustomLayersSingle.cpp delete mode 100644 RAT/standardTFCustomLayersSingle.h delete mode 100644 RAT/standardTFCustomXYParallelContrasts.cpp delete mode 100644 RAT/standardTFCustomXYParallelContrasts.h delete mode 100644 RAT/standardTFCustomXYParallelPoints.cpp delete mode 100644 RAT/standardTFCustomXYParallelPoints.h delete mode 100644 RAT/standardTFCustomXYReflectivityCalculation.cpp delete mode 100644 RAT/standardTFCustomXYReflectivityCalculation.h delete mode 100644 RAT/standardTFCustomXYSingle.cpp delete mode 100644 RAT/standardTFCustomXYSingle.h delete mode 100644 RAT/standardTFLayersCore.cpp delete mode 100644 RAT/standardTFLayersCore.h delete mode 100644 RAT/standardTFReflectivityCalculation.cpp delete mode 100644 RAT/standardTFReflectivityCalculation.h delete mode 100644 RAT/standardTFStandardLayersParallelContrasts.cpp delete mode 100644 RAT/standardTFStandardLayersParallelContrasts.h delete mode 100644 RAT/standardTFStandardLayersParallelPoints.cpp delete mode 100644 RAT/standardTFStandardLayersParallelPoints.h delete mode 100644 RAT/standardTFStandardLayersReflectivityCalculation.cpp delete mode 100644 RAT/standardTFStandardLayersReflectivityCalculation.h delete mode 100644 RAT/standardTFStandardLayersSingle.cpp delete mode 100644 RAT/standardTFStandardLayersSingle.h create mode 100644 RAT/std.cpp create mode 100644 RAT/std.h create mode 100644 RAT/str2double.cpp create mode 100644 RAT/str2double.h create mode 100644 RAT/str2double1.cpp create mode 100644 RAT/str2double1.h create mode 100644 RAT/structConstructorHelper.cpp create mode 100644 RAT/structConstructorHelper.h create mode 100644 RAT/textProgressBar.cpp create mode 100644 RAT/textProgressBar.h create mode 100644 RAT/tic.cpp create mode 100644 RAT/tic.h create mode 100644 RAT/timeKeeper.cpp create mode 100644 RAT/timeKeeper.h create mode 100644 RAT/toc.cpp create mode 100644 RAT/toc.h create mode 100644 RAT/triu.cpp create mode 100644 RAT/triu.h create mode 100644 RAT/unpackParams.cpp create mode 100644 RAT/unpackParams.h create mode 100644 RAT/useConstantDim.cpp create mode 100644 RAT/useConstantDim.h create mode 100644 RAT/vAllOrAny.cpp create mode 100644 RAT/vAllOrAny.h create mode 100644 RAT/validate_print_arguments.cpp create mode 100644 RAT/validate_print_arguments.h create mode 100644 RAT/var.cpp create mode 100644 RAT/var.h create mode 100644 RAT/varstd.cpp create mode 100644 RAT/varstd.h create mode 100644 RAT/xdhseqr.cpp create mode 100644 RAT/xdhseqr.h create mode 100644 RAT/xdlanv2.cpp create mode 100644 RAT/xdlanv2.h create mode 100644 RAT/xgehrd.cpp create mode 100644 RAT/xgehrd.h create mode 100644 RAT/xgemm.cpp create mode 100644 RAT/xgemm.h create mode 100644 RAT/xgemv.cpp create mode 100644 RAT/xgemv.h create mode 100644 RAT/xgeqp3.cpp create mode 100644 RAT/xgeqp3.h create mode 100644 RAT/xgerc.cpp create mode 100644 RAT/xgerc.h create mode 100644 RAT/xgeru.cpp create mode 100644 RAT/xgeru.h create mode 100644 RAT/xgetrf.cpp create mode 100644 RAT/xgetrf.h create mode 100644 RAT/xnrm2.cpp create mode 100644 RAT/xnrm2.h create mode 100644 RAT/xrot.cpp create mode 100644 RAT/xrot.h create mode 100644 RAT/xswap.cpp create mode 100644 RAT/xswap.h create mode 100644 RAT/xtrsm.cpp create mode 100644 RAT/xtrsm.h create mode 100644 RAT/xtrsv.cpp create mode 100644 RAT/xtrsv.h create mode 100644 RAT/xungorghr.cpp create mode 100644 RAT/xungorghr.h create mode 100644 RAT/xunormqr.cpp create mode 100644 RAT/xunormqr.h create mode 100644 RAT/xzgeev.cpp create mode 100644 RAT/xzgeev.h create mode 100644 RAT/xzgeqp3.cpp create mode 100644 RAT/xzgeqp3.h create mode 100644 RAT/xzggbak.cpp create mode 100644 RAT/xzggbak.h create mode 100644 RAT/xzggbal.cpp create mode 100644 RAT/xzggbal.h create mode 100644 RAT/xzggev.cpp create mode 100644 RAT/xzggev.h create mode 100644 RAT/xzgghrd.cpp create mode 100644 RAT/xzgghrd.h create mode 100644 RAT/xzhgeqz.cpp create mode 100644 RAT/xzhgeqz.h create mode 100644 RAT/xzlangeM.cpp create mode 100644 RAT/xzlangeM.h create mode 100644 RAT/xzlanhs.cpp create mode 100644 RAT/xzlanhs.h create mode 100644 RAT/xzlarf.cpp create mode 100644 RAT/xzlarf.h create mode 100644 RAT/xzlarfg.cpp create mode 100644 RAT/xzlarfg.h create mode 100644 RAT/xzlartg.cpp create mode 100644 RAT/xzlartg.h create mode 100644 RAT/xzlascl.cpp create mode 100644 RAT/xzlascl.h create mode 100644 RAT/xztgevc.cpp create mode 100644 RAT/xztgevc.h create mode 100644 RAT/xzungqr.cpp create mode 100644 RAT/xzungqr.h diff --git a/DSPC_bilayer_example.py b/DSPC_bilayer_example.py index af8b3b55..5788f4ee 100644 --- a/DSPC_bilayer_example.py +++ b/DSPC_bilayer_example.py @@ -4,31 +4,63 @@ rat = cppimport.imp("rat") if __name__ == '__main__': - #------------------------------------------------------------------------------------ - # Control + control = rat.Control() problem = rat.ProblemDefinition() limits = rat.Limits() cells = rat.Cells() - - control.proc = 'calculate' - control.para = 'points' + priors = rat.Priors() + + #------------------------------------------------------------------------------------ + # Control + control.procedure = 'calculate' + control.parallel = 'single' control.display = 'iter' - control.calcSld = False + control.calcSldDuringFit = False control.resamPars = [0.9000, 50] + + # control.procedure = 'simplex' + # control.tolX = 1e-6 + # control.tolFun = 1e-6 + # control.maxFunEvals = 10000 + # control.maxIter = 1 + # control.updateFreq = -1 + # control.updatePlotFreq = 1 + + # control.procedure = 'dream' + # control.nSamples = 100 + # control.nChains = 10 + # control.jumpProbability = 0.5 + # control.pUnitGamma = 0.2 + # control.boundHandling = 'fold' + # control.adaptPCR = False; - control.checks.params_fitYesNo = [1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1] - control.checks.backs_fitYesNo = np.ones((2)) - control.checks.shifts_fitYesNo = [0] - control.checks.scales_fitYesNo = [0, 0] - control.checks.nbairs_fitYesNo = [0] - control.checks.nbsubs_fitYesNo = [0, 0] - control.checks.resol_fitYesNo = [0] + # control.procedure = 'de' + # control.populationSize = 10 + # control.fWeight = 0.5 + # control.crossoverProbability = 0.8 + # control.strategy = 4 + # control.targetValue = 1 + # control.numGenerations = 500 + + # control.procedure = 'ns' + # control.Nlive = 150 + # control.Nmcmc = 0 + # control.propScale = 0.1 + # control.nsTolerance = 0.1 + + control.checks.fitParam = [1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1] + control.checks.fitBackgroundParam = np.ones((2)) + control.checks.fitQzshift = [0] + control.checks.fitScalefactor = [0, 0] + control.checks.fitBulkIn = [0] + control.checks.fitBulkOut = [0, 0] + control.checks.fitResolutionParam = [0] #------------------------------------------------------------------------------------ # ProblemDef - problem.contrastBacks = [1, 2] - problem.contrastBacksType = [1, 1] + problem.contrastBackgrounds = [1, 2] + problem.contrastBackgroundsType = [1, 1] problem.TF = 'non polarised' problem.resample = [0, 0] problem.dataPresent = [1, 1] @@ -36,17 +68,17 @@ problem.numberOfContrasts = 2 problem.geometry = 'substrate/liquid' problem.useImaginary = False - problem.contrastShifts = [1, 1] - problem.contrastScales = [1, 1] - problem.contrastNbas = [1, 1] - problem.contrastNbss = [1, 2] - problem.contrastRes = [1, 1] - problem.backs = [2.28525214157571e-06, 3.10246417982706e-06] - problem.shifts = [0] - problem.sf = [0.102860901766649, 0.151378164199993] - problem.nba = [2.07399989449186e-06] - problem.nbs = [5.98067802097389e-06, 2.21000000000000e-06] - problem.res = [0.0300] + problem.contrastQzshifts = [1, 1] + problem.contrastScalefactors = [1, 1] + problem.contrastBulkIns = [1, 1] + problem.contrastBulkOuts = [1, 2] + problem.contrastResolutions = [1, 1] + problem.backgroundParams = [2.28525214157571e-06, 3.10246417982706e-06] + problem.qzshifts = [0] + problem.scalefactors = [0.102860901766649, 0.151378164199993] + problem.bulkIn = [2.07399989449186e-06] + problem.bulkOut = [5.98067802097389e-06, 2.21000000000000e-06] + problem.resolutionParams = [0.0300] problem.params = [5.08929897223891, 19.2830495317839, 3.39317612702561e-06, 21.5451088784623, -4.01001212540204e-07, 1.24963548580913, 8.09797576127018, 20.3854719276630, 0, 5.79580504624961, 1.75686012656988e-06, 10.0916971312704, 11.7066921282983, 1.47000000000000e-06, 5.63694566866001, 17.8733566725932, -4.61089672942576e-07, 17.8556570737753, 41.4142113901161, 100, 25.6893163532023] @@ -56,31 +88,30 @@ problem.contrastDomainRatios = [0, 0] problem.domainRatio = [] problem.numberOfDomainContrasts = 0 - problem.domainContrastCustomFiles = [] - problem.fitpars = [5.08929897223891, 19.2830495317839, 21.5451088784623, 1.24963548580913, 8.09797576127018, + problem.fitParams = [5.08929897223891, 19.2830495317839, 21.5451088784623, 1.24963548580913, 8.09797576127018, 20.3854719276630, 5.79580504624961, 10.0916971312704, 11.7066921282983, 5.63694566866001, 17.8733566725932, 17.8556570737753, 41.4142113901161, 25.6893163532023, 2.28525214157571e-06, 3.10246417982706e-06] - problem.otherpars = [3.39317612702561e-06, -4.01001212540204e-07, 0, 1.75686012656988e-06, 1.47e-06, -4.61089672942576e-07, + problem.otherParams = [3.39317612702561e-06, -4.01001212540204e-07, 0, 1.75686012656988e-06, 1.47e-06, -4.61089672942576e-07, 100, 0.102860901766649, 0.151378164199993,0, 2.07399989449186e-06, 5.98067802097389e-06, 2.21e-06, 0.030] - problem.fitconstr = [[2, 8], [5, 60], [15, 35], [1, 50], [1, 15], [10, 28], [5, 17], + problem.fitLimits = [[2, 8], [5, 60], [15, 35], [1, 50], [1, 15], [10, 28], [5, 17], [10, 50], [7, 17], [2, 15], [14, 22], [10, 50], [10, 50], [0, 60], [5.0e-10, 7.0e-06], [1.0e-10, 4.99999987368938e-06]] - problem.otherconstr = [[3.39e-06, 3.41e-06], [-5.0e-07, -3.0e-07], [0, 1.0e-09], [1.0e-07, 2.0e-06], [5.0e-07, 1.5e-06], + problem.otherLimits = [[3.39e-06, 3.41e-06], [-5.0e-07, -3.0e-07], [0, 1.0e-09], [1.0e-07, 2.0e-06], [5.0e-07, 1.5e-06], [-5.0e-07, 0], [99.9, 100], [0.050, 0.20], [0.050, 0.20], [-0.00010, 0.00010], [2.0e-06, 2.1e-06], [5.50000004295725e-06, 6.4e-06], [2.0e-06, 4.99999987368938e-06], [0.010, 0.050]] #------------------------------------------------------------------------------------ # Limits - limits.params = [[2, 8], [5, 60], [0, 0], [15, 35], [-0, -0], [1, 50], [1, 15], + limits.param = [[2, 8], [5, 60], [0, 0], [15, 35], [-0, -0], [1, 50], [1, 15], [10, 28], [0, 0], [5, 17], [0, 0], [10, 50], [7, 17], [0, 0], [2, 15], [14, 22], [-0, 0], [10, 50], [10, 50], [99.9,100], [0, 60]] - limits.backs = [[5.0000e-10, 7.0000e-06], [1.0000e-10, 5.0000e-06]] - limits.scales = [[0.0500, 0.2000], [0.0500, 0.2000]] - limits.shifts = [[-1.0000e-04, 1.0000e-04]] - limits.nba = [[2.0000e-06, 2.1000e-06]] - limits.nbs = [[5.5000e-06, 6.4000e-06], [2.0000e-06, 5.0000e-06]] - limits.res = [[0.0100, 0.0500]] + limits.backgroundParam = [[5.0000e-10, 7.0000e-06], [1.0000e-10, 5.0000e-06]] + limits.scalefactor = [[0.0500, 0.2000], [0.0500, 0.2000]] + limits.qzshift = [[-1.0000e-04, 1.0000e-04]] + limits.bulkIn = [[2.0000e-06, 2.1000e-06]] + limits.bulkOut = [[5.5000e-06, 6.4000e-06], [2.0000e-06, 5.0000e-06]] + limits.resolutionParam = [[0.0100, 0.0500]] limits.domainRatio = [] #------------------------------------------------------------------------------------- @@ -115,17 +146,61 @@ # cells.f19 = [] # cells.f20 = [] - problem, output = rat.reflectivityCalculation(problem, cells, limits, control) + #------------------------------------------------------------------------------------ + # Priors + priors.param = [['Substrate Roughness', 'uniform', 0, np.Inf], + ['Oxide thick', 'uniform', 0, np.Inf], + ['Oxide SLD', 'uniform', 0, np.Inf], + ['Sam tails thick', 'uniform', 0, np.Inf], + ['Sam tails SLD', 'uniform', 0, np.Inf], + ['Sam tails hydra…', 'uniform', 0, np.Inf], + ['Sam rough', 'uniform', 0, np.Inf], + ['cw thick', 'uniform', 0, np.Inf], + ['cw SLD', 'uniform', 0, np.Inf], + ['SAM head thick', 'uniform', 0, np.Inf], + ['SAM head SLD', 'uniform', 0, np.Inf], + ['SAM head hydrat…', 'uniform', 0, np.Inf], + ['Bilayer head th…', 'uniform', 0, np.Inf], + ['Bilayer head SLD', 'uniform', 0, np.Inf], + ['Bilayer rough', 'uniform', 0, np.Inf], + ['Bilayer tails t…', 'uniform', 0, np.Inf], + ['Bilayer tails SLD', 'uniform', 0, np.Inf], + ['Bilayer tails h…', 'uniform', 0, np.Inf], + ['Bilayer heads h…', 'uniform', 0, np.Inf], + ['cw hydration', 'uniform', 0, np.Inf], + ['Oxide Hydration', 'uniform', 0, np.Inf]] + priors.backgroundParam = [['Backs parameter 1', 'uniform', 0, np.Inf], ['Backs parameter 2', 'uniform', 0, np.Inf]] + priors.scalefactor = [['Scalefactor 1', 'uniform', 0, np.Inf], ['Scalefactor 2', 'uniform', 0, np.Inf]] + priors.qzshift = [['Qz shift 1', 'uniform', 0, np.Inf]] + priors.bulkIn = [['Air', 'uniform', 0, np.Inf]] + priors.bulkOut = [['D2O', 'uniform', 0, np.Inf], ['SMW', 'uniform', 0, np.Inf]] + priors.resolutionParam = [['Resolution par 1', 'uniform', 0, np.Inf]] + priors.priorNames = ['Substrate Roughness', 'Oxide thick', 'Oxide SLD', + 'Sam tails thick', 'Sam tails SLD', 'Sam tails hydration', 'Sam rough', + 'cw thick', 'cw SLD', 'SAM head thick', 'SAM head SLD', 'SAM head hydration', + 'Bilayer head thick', 'Bilayer head SLD', 'Bilayer rough', 'Bilayer tails thick', + 'Bilayer tails SLD', 'Bilayer tails hydr', 'Bilayer heads hydr', 'cw hydration', + 'Oxide Hydration','Backs parameter 1', 'Backs parameter 2', 'Resolution par 1', + 'Air', 'D2O', 'SMW', 'Qz shift 1', 'Scalefactor 1', 'Scalefactor 2'] + priors.priorValues = [[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], + [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], + [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], + [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], + [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], + [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf]] + + pdef, problem, output, bayes_result = rat.RATMain(problem, cells, limits, control, priors) print(problem.ssubs) - print(problem.backgrounds) - print(problem.qshifts) + print(problem.backgroundParams) + print(problem.qzshifts) print(problem.scalefactors) - print(problem.nbairs) - print(problem.nbsubs) - print(problem.resolutions) - print(problem.calculations.all_chis) - print(problem.calculations.sum_chi) + print(problem.bulkIn) + print(problem.bulkOut) + print(problem.resolutionParams) + print(problem.calculations.allChis) + print(problem.calculations.sumChi) print(problem.allSubRough) print(problem.resample) + #print(output) \ No newline at end of file diff --git a/RAT/CoderTimeAPI.cpp b/RAT/CoderTimeAPI.cpp new file mode 100644 index 00000000..6b3135c8 --- /dev/null +++ b/RAT/CoderTimeAPI.cpp @@ -0,0 +1,25 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// CoderTimeAPI.cpp +// +// Code generation for function 'CoderTimeAPI' +// + +// Include files +#include "CoderTimeAPI.h" +#include "RATMain_data.h" +#include "rt_nonfinite.h" + +// Function Definitions +namespace RAT +{ + void freq_not_empty_init() + { + freq_not_empty = false; + } +} + +// End of code generation (CoderTimeAPI.cpp) diff --git a/RAT/reflectivityCalculation_rtwutil.h b/RAT/CoderTimeAPI.h similarity index 51% rename from RAT/reflectivityCalculation_rtwutil.h rename to RAT/CoderTimeAPI.h index a9aedba0..1c2dc886 100644 --- a/RAT/reflectivityCalculation_rtwutil.h +++ b/RAT/CoderTimeAPI.h @@ -3,12 +3,12 @@ // granting, nonprofit, education, and research organizations only. Not // for commercial or industrial use. // -// reflectivityCalculation_rtwutil.h +// CoderTimeAPI.h // -// Code generation for function 'reflectivityCalculation_rtwutil' +// Code generation for function 'CoderTimeAPI' // -#ifndef REFLECTIVITYCALCULATION_RTWUTIL_H -#define REFLECTIVITYCALCULATION_RTWUTIL_H +#ifndef CODERTIMEAPI_H +#define CODERTIMEAPI_H // Include files #include "rtwtypes.h" @@ -18,9 +18,9 @@ // Function Declarations namespace RAT { - extern real_T rt_hypotd_snf(real_T u0, real_T u1); + void freq_not_empty_init(); } #endif -// End of code generation (reflectivityCalculation_rtwutil.h) +// End of code generation (CoderTimeAPI.h) diff --git a/RAT/DREAMWrapper.cpp b/RAT/DREAMWrapper.cpp new file mode 100644 index 00000000..fd34f7df --- /dev/null +++ b/RAT/DREAMWrapper.cpp @@ -0,0 +1,62 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// DREAMWrapper.cpp +// +// Code generation for function 'DREAMWrapper' +// + +// Include files +#include "DREAMWrapper.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "reflectivityCalculation.h" +#include "rt_nonfinite.h" +#include "unpackParams.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + real_T DREAMWrapper(const ::coder::array &pars, const struct5_T + *ratInputs_problemDef, const cell_14 + *ratInputs_problemDefCells, const struct2_T + *ratInputs_controls) + { + cell_13 a__1; + struct5_T problem; + struct_T outProblem; + int32_T loop_ub; + + // Get the inputs for Reflectivity Calculation + problem = *ratInputs_problemDef; + + // Put the current parameters into problem + problem.fitParams.set_size(1, pars.size(1)); + loop_ub = pars.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + problem.fitParams[problem.fitParams.size(0) * i] = pars[i]; + } + + // Distribute them to the right parts + unpackParams(&problem, ratInputs_controls->checks.fitParam, + ratInputs_controls->checks.fitBackgroundParam, + ratInputs_controls->checks.fitQzshift, + ratInputs_controls->checks.fitScalefactor, + ratInputs_controls->checks.fitBulkIn, + ratInputs_controls->checks.fitBulkOut, + ratInputs_controls->checks.fitResolutionParam, + ratInputs_controls->checks.fitDomainRatio); + + // Calculate.... + reflectivityCalculation(&problem, ratInputs_problemDefCells, + ratInputs_controls, &outProblem, &a__1); + + // Function value is chi-squared.... + return -outProblem.calculations.sumChi / 2.0; + } +} + +// End of code generation (DREAMWrapper.cpp) diff --git a/RAT/DREAMWrapper.h b/RAT/DREAMWrapper.h new file mode 100644 index 00000000..48014b70 --- /dev/null +++ b/RAT/DREAMWrapper.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// DREAMWrapper.h +// +// Code generation for function 'DREAMWrapper' +// +#ifndef DREAMWRAPPER_H +#define DREAMWRAPPER_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct cell_14; + struct struct2_T; +} + +// Function Declarations +namespace RAT +{ + real_T DREAMWrapper(const ::coder::array &pars, const struct5_T + *ratInputs_problemDef, const cell_14 + *ratInputs_problemDefCells, const struct2_T + *ratInputs_controls); +} + +#endif + +// End of code generation (DREAMWrapper.h) diff --git a/RAT/RATMain.cpp b/RAT/RATMain.cpp new file mode 100644 index 00000000..b63393f1 --- /dev/null +++ b/RAT/RATMain.cpp @@ -0,0 +1,1093 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// RATMain.cpp +// +// Code generation for function 'RATMain' +// + +// Include files +#include "RATMain.h" +#include "RATMain_data.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "lower.h" +#include "makeEmptyBayesResultsStruct.h" +#include "reflectivityCalculation.h" +#include "repmat.h" +#include "rt_nonfinite.h" +#include "runDE.h" +#include "runDREAM.h" +#include "runNestedSampler.h" +#include "runSimplex.h" +#include "strcmp.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + static void cast(const struct0_T *r, struct5_T *r1); + static void cast(const cell_7 *r, cell_14 *r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_1, 2U> &r1); +} + +// Function Definitions +namespace RAT +{ + static void cast(const struct0_T *r, struct5_T *r1) + { + int32_T b_loop_ub; + int32_T loop_ub; + r1->contrastBackgrounds.set_size(1, r->contrastBackgrounds.size(1)); + loop_ub = r->contrastBackgrounds.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastBackgrounds[i] = r->contrastBackgrounds[i]; + } + + r1->contrastBackgroundsType.set_size(1, r->contrastBackgroundsType.size(1)); + loop_ub = r->contrastBackgroundsType.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastBackgroundsType[i] = r->contrastBackgroundsType[i]; + } + + r1->TF.size[0] = 1; + r1->TF.size[1] = r->TF.size[1]; + loop_ub = r->TF.size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&r->TF.data[0], &r->TF.data[loop_ub], &r1->TF.data[0]); + } + + r1->resample.set_size(1, r->resample.size(1)); + loop_ub = r->resample.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->resample[i] = r->resample[i]; + } + + r1->dataPresent.set_size(1, r->dataPresent.size(1)); + loop_ub = r->dataPresent.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->dataPresent[i] = r->dataPresent[i]; + } + + r1->oilChiDataPresent.set_size(1, r->oilChiDataPresent.size(1)); + loop_ub = r->oilChiDataPresent.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->oilChiDataPresent[i] = r->oilChiDataPresent[i]; + } + + r1->numberOfContrasts = r->numberOfContrasts; + r1->geometry.size[0] = 1; + r1->geometry.size[1] = r->geometry.size[1]; + loop_ub = r->geometry.size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&r->geometry.data[0], &r->geometry.data[loop_ub], + &r1->geometry.data[0]); + } + + r1->useImaginary = r->useImaginary; + r1->contrastQzshifts.set_size(1, r->contrastQzshifts.size(1)); + loop_ub = r->contrastQzshifts.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastQzshifts[i] = r->contrastQzshifts[i]; + } + + r1->contrastScalefactors.set_size(1, r->contrastScalefactors.size(1)); + loop_ub = r->contrastScalefactors.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastScalefactors[i] = r->contrastScalefactors[i]; + } + + r1->contrastBulkIns.set_size(1, r->contrastBulkIns.size(1)); + loop_ub = r->contrastBulkIns.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastBulkIns[i] = r->contrastBulkIns[i]; + } + + r1->contrastBulkOuts.set_size(1, r->contrastBulkOuts.size(1)); + loop_ub = r->contrastBulkOuts.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastBulkOuts[i] = r->contrastBulkOuts[i]; + } + + r1->contrastResolutions.set_size(1, r->contrastResolutions.size(1)); + loop_ub = r->contrastResolutions.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastResolutions[i] = r->contrastResolutions[i]; + } + + r1->backgroundParams.set_size(1, r->backgroundParams.size(1)); + loop_ub = r->backgroundParams.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->backgroundParams[i] = r->backgroundParams[i]; + } + + r1->qzshifts.set_size(1, r->qzshifts.size(1)); + loop_ub = r->qzshifts.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->qzshifts[i] = r->qzshifts[i]; + } + + r1->scalefactors.set_size(1, r->scalefactors.size(1)); + loop_ub = r->scalefactors.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->scalefactors[i] = r->scalefactors[i]; + } + + r1->bulkIn.set_size(1, r->bulkIn.size(1)); + loop_ub = r->bulkIn.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->bulkIn[i] = r->bulkIn[i]; + } + + r1->bulkOut.set_size(1, r->bulkOut.size(1)); + loop_ub = r->bulkOut.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->bulkOut[i] = r->bulkOut[i]; + } + + r1->resolutionParams.set_size(1, r->resolutionParams.size(1)); + loop_ub = r->resolutionParams.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->resolutionParams[i] = r->resolutionParams[i]; + } + + r1->params.set_size(1, r->params.size(1)); + loop_ub = r->params.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->params[i] = r->params[i]; + } + + r1->numberOfLayers = r->numberOfLayers; + r1->modelType.size[0] = 1; + r1->modelType.size[1] = r->modelType.size[1]; + loop_ub = r->modelType.size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&r->modelType.data[0], &r->modelType.data[loop_ub], + &r1->modelType.data[0]); + } + + r1->contrastCustomFiles.set_size(1, r->contrastCustomFiles.size(1)); + loop_ub = r->contrastCustomFiles.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastCustomFiles[i] = r->contrastCustomFiles[i]; + } + + r1->contrastDomainRatios.set_size(1, r->contrastDomainRatios.size(1)); + loop_ub = r->contrastDomainRatios.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastDomainRatios[i] = r->contrastDomainRatios[i]; + } + + r1->domainRatio.set_size(1, r->domainRatio.size(1)); + loop_ub = r->domainRatio.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->domainRatio[i] = r->domainRatio[i]; + } + + r1->numberOfDomainContrasts = r->numberOfDomainContrasts; + r1->fitParams.set_size(r->fitParams.size(0), r->fitParams.size(1)); + loop_ub = r->fitParams.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = r->fitParams.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r1->fitParams[i1 + r1->fitParams.size(0) * i] = r->fitParams[i1 + + r->fitParams.size(0) * i]; + } + } + + r1->otherParams.set_size(r->otherParams.size(0), r->otherParams.size(1)); + loop_ub = r->otherParams.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = r->otherParams.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r1->otherParams[i1 + r1->otherParams.size(0) * i] = r->otherParams[i1 + + r->otherParams.size(0) * i]; + } + } + + r1->fitLimits.set_size(r->fitLimits.size(0), r->fitLimits.size(1)); + loop_ub = r->fitLimits.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = r->fitLimits.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r1->fitLimits[i1 + r1->fitLimits.size(0) * i] = r->fitLimits[i1 + + r->fitLimits.size(0) * i]; + } + } + + r1->otherLimits.set_size(r->otherLimits.size(0), r->otherLimits.size(1)); + loop_ub = r->otherLimits.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = r->otherLimits.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r1->otherLimits[i1 + r1->otherLimits.size(0) * i] = r->otherLimits[i1 + + r->otherLimits.size(0) * i]; + } + } + } + + static void cast(const cell_7 *r, cell_14 *r1) + { + int32_T loop_ub; + r1->f1.set_size(1, r->f1.size(1)); + loop_ub = r->f1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f1[i] = r->f1[i]; + } + + cast(r->f2, r1->f2); + r1->f3.set_size(1, r->f3.size(1)); + loop_ub = r->f3.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f3[i] = r->f3[i]; + } + + r1->f4.set_size(1, r->f4.size(1)); + loop_ub = r->f4.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f4[i] = r->f4[i]; + } + + cast(r->f5, r1->f5); + cast(r->f6, r1->f6); + cast(r->f7, r1->f7); + cast(r->f8, r1->f8); + cast(r->f9, r1->f9); + cast(r->f10, r1->f10); + cast(r->f11, r1->f11); + cast(r->f12, r1->f12); + cast(r->f13, r1->f13); + cast(r->f14, r1->f14); + cast(r->f15, r1->f15); + cast(r->f16, r1->f16); + cast(r->f17, r1->f17); + r1->f18.set_size(1, r->f18.size(1)); + loop_ub = r->f18.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->f18[i] = r->f18[i]; + } + + cast(r->f19, r1->f19); + cast(r->f20, r1->f20); + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size[1]; + r1[i1].f1.set_size(r[i1].f1.size[0], r[i1].f1.size[1]); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size[0]; + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[r1[i1].f1.size(0) * i2] = r[i1].f1.data[r[i1].f1.size[0] * + i2]; + } + } + } + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1) + { + int32_T i; + r1.set_size(1, r.size(1)); + i = r.size(1) - 1; + for (int32_T i1{0}; i1 <= i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[r1.size(0) * i1].f1.set_size(r[r.size(0) * i1].f1.size(0), r[r.size(0) * + i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1) + { + int32_T i; + r1.set_size(1, r.size(1)); + i = r.size(1) - 1; + for (int32_T i1{0}; i1 <= i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[r1.size(0) * i1].f1.set_size(r[r.size(0) * i1].f1.size(0), r[r.size(0) * + i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[r1[i1].f1.size(0) * i2] = r[i1].f1[r[i1].f1.size(0) * i2]; + } + } + } + } + + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_1, 2U> &r1) + { + int32_T i; + r1.set_size(1, r.size(1)); + i = r.size(1) - 1; + for (int32_T i1{0}; i1 <= i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size[1]; + r1[r1.size(0) * i1].f1.set_size(1, r[r.size(0) * i1].f1.size[1]); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + r1[i1].f1[i2] = r[i1].f1.data[i2]; + } + } + } + + void RATMain(const struct0_T *problemDef, const cell_7 *problemDefCells, const + struct1_T *problemDefLimits, struct2_T *controls, const struct4_T + *priors, struct5_T *outProblemDef, struct6_T *problem, + cell_wrap_9 results[6], struct8_T *bayesResults) + { + static d_struct_T b_bayesResults; + static struct5_T outProblemDef_tmp; + ::coder::array t19_calculations_allChis; + cell_13 b_results; + cell_14 r; + struct_T b_problem; + int32_T switch_expression_size[2]; + int32_T b_loop_ub; + int32_T loop_ub; + int32_T loop_ub_tmp; + char_T switch_expression_data[10000]; + coder::repmat(results); + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + t19_calculations_allChis.set_size(loop_ub_tmp); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgroundParams.set_size(loop_ub_tmp); + problem->qzshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->bulkIn.set_size(loop_ub_tmp); + problem->bulkOut.set_size(loop_ub_tmp); + problem->resolutionParams.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + t19_calculations_allChis[i] = 0; + problem->ssubs[i] = 0.0; + problem->backgroundParams[i] = 0.0; + problem->qzshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->bulkIn[i] = 0.0; + problem->bulkOut[i] = 0.0; + problem->resolutionParams[i] = 0.0; + } + + problem->calculations.allChis.set_size(t19_calculations_allChis.size(0)); + loop_ub = t19_calculations_allChis.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->calculations.allChis[i] = 0.0; + } + + problem->calculations.sumChi = 0.0; + problem->allSubRough.set_size(loop_ub_tmp); + problem->resample.set_size(loop_ub_tmp, 1); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->allSubRough[i] = 0.0; + problem->resample[i] = 0.0; + } + + makeEmptyBayesResultsStruct(problemDef->numberOfContrasts, coder::internal:: + b_strcmp(problemDef->TF.data, problemDef->TF.size), controls->nChains, + bayesResults->bestFitsMean.ref, bayesResults->bestFitsMean.sld, + &bayesResults->bestFitsMean.chi, bayesResults->bestFitsMean.data, + bayesResults->predlims.refPredInts, bayesResults->predlims.sldPredInts, + bayesResults->predlims.refXdata, bayesResults->predlims.sldXdata, + bayesResults->predlims.sampleChi.data, + &bayesResults->predlims.sampleChi.size[0], bayesResults->parConfInts.par95, + bayesResults->parConfInts.par65, bayesResults->parConfInts.mean, + bayesResults->bestPars, &b_bayesResults.bayesRes, bayesResults->chain); + bayesResults->bayesRes.allChains.set_size + (b_bayesResults.bayesRes.allChains.size(0), + b_bayesResults.bayesRes.allChains.size(1), + b_bayesResults.bayesRes.allChains.size(2)); + loop_ub = b_bayesResults.bayesRes.allChains.size(2); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_bayesResults.bayesRes.allChains.size(1); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + b_loop_ub = b_bayesResults.bayesRes.allChains.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + bayesResults->bayesRes.allChains[(i2 + + bayesResults->bayesRes.allChains.size(0) * i1) + + bayesResults->bayesRes.allChains.size(0) * + bayesResults->bayesRes.allChains.size(1) * i] = + b_bayesResults.bayesRes.allChains[(i2 + + b_bayesResults.bayesRes.allChains.size(0) * i1) + + b_bayesResults.bayesRes.allChains.size(0) * + b_bayesResults.bayesRes.allChains.size(1) * i]; + } + } + } + + bayesResults->bayesRes.dreamOutput = b_bayesResults.bayesRes.dreamOutput; + bayesResults->bayesRes.nestOutput.LogZ = + b_bayesResults.bayesRes.nestOutput.LogZ; + bayesResults->bayesRes.nestOutput.nestSamples.set_size(1, 2); + bayesResults->bayesRes.nestOutput.postSamples.set_size(1, 2); + bayesResults->bayesRes.nestOutput.nestSamples[0] = + b_bayesResults.bayesRes.nestOutput.nestSamples.data[0]; + bayesResults->bayesRes.nestOutput.postSamples[0] = + b_bayesResults.bayesRes.nestOutput.postSamples.data[0]; + bayesResults->bayesRes.nestOutput.nestSamples + [bayesResults->bayesRes.nestOutput.nestSamples.size(0)] = + b_bayesResults.bayesRes.nestOutput.nestSamples.data[1]; + bayesResults->bayesRes.nestOutput.postSamples + [bayesResults->bayesRes.nestOutput.postSamples.size(0)] = + b_bayesResults.bayesRes.nestOutput.postSamples.data[1]; + + // bayesResults = struct('bayesRes',[],... + // 'chain',[],... + // 's2chain',[],... + // 'ssChain',[],... + // 'bestPars_Mean',[],... + // 'bestFitsMean',[],... + // 'predLims',[],... + // 'parConfInts',[]); + cast(problemDef, &outProblemDef_tmp); + *outProblemDef = outProblemDef_tmp; + + // Decide what we are doing.... + coder::lower(controls->procedure.data, controls->procedure.size, + switch_expression_data, switch_expression_size); + if (coder::internal::c_strcmp(switch_expression_data, switch_expression_size)) + { + loop_ub_tmp = 0; + } else if (coder::internal::e_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 1; + } else if (coder::internal::f_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 2; + } else if (coder::internal::g_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 3; + } else if (coder::internal::h_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 4; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + // Just a single reflectivity calculation + cast(problemDef, &outProblemDef_tmp); + cast(problemDefCells, &r); + reflectivityCalculation(&outProblemDef_tmp, &r, controls, &b_problem, + &b_results); + problem->ssubs.set_size(b_problem.ssubs.size(0)); + loop_ub = b_problem.ssubs.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->ssubs[i] = b_problem.ssubs[i]; + } + + problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); + loop_ub = b_problem.backgroundParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->backgroundParams[i] = b_problem.backgroundParams[i]; + } + + problem->qzshifts.set_size(b_problem.qzshifts.size(0)); + loop_ub = b_problem.qzshifts.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->qzshifts[i] = b_problem.qzshifts[i]; + } + + problem->scalefactors.set_size(b_problem.scalefactors.size(0)); + loop_ub = b_problem.scalefactors.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->scalefactors[i] = b_problem.scalefactors[i]; + } + + problem->bulkIn.set_size(b_problem.bulkIn.size(0)); + loop_ub = b_problem.bulkIn.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkIn[i] = b_problem.bulkIn[i]; + } + + problem->bulkOut.set_size(b_problem.bulkOut.size(0)); + loop_ub = b_problem.bulkOut.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkOut[i] = b_problem.bulkOut[i]; + } + + problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); + loop_ub = b_problem.resolutionParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resolutionParams[i] = b_problem.resolutionParams[i]; + } + + problem->calculations = b_problem.calculations; + problem->allSubRough.set_size(b_problem.allSubRough.size(0)); + loop_ub = b_problem.allSubRough.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->allSubRough[i] = b_problem.allSubRough[i]; + } + + problem->resample.set_size(1, b_problem.resample.size(1)); + loop_ub = b_problem.resample.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; + } + + results[0].f1.set_size(b_results.f1.size(0), 1); + loop_ub_tmp = b_results.f1.size(0); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + loop_ub = b_results.f1[i].f1.size(0); + results[0].f1[i].f1.set_size(b_results.f1[i].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + results[0].f1[i].f1[i2 + results[0].f1[i].f1.size(0) * i1] = + b_results.f1[i].f1[i2 + b_results.f1[i].f1.size(0) * i1]; + } + } + } + + results[1].f1.set_size(b_results.f2.size(0), 1); + loop_ub_tmp = b_results.f2.size(0); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + loop_ub = b_results.f2[i].f1.size(0); + results[1].f1[i].f1.set_size(b_results.f2[i].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + results[1].f1[i].f1[i2 + results[1].f1[i].f1.size(0) * i1] = + b_results.f2[i].f1[i2 + b_results.f2[i].f1.size(0) * i1]; + } + } + } + + results[2].f1.set_size(b_results.f3.size(0), 1); + loop_ub_tmp = b_results.f3.size(0); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + loop_ub = b_results.f3[i].f1.size(0); + results[2].f1[i].f1.set_size(b_results.f3[i].f1.size(0), 3); + for (int32_T i1{0}; i1 < 3; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + results[2].f1[i].f1[i2 + results[2].f1[i].f1.size(0) * i1] = + b_results.f3[i].f1[i2 + b_results.f3[i].f1.size(0) * i1]; + } + } + } + + results[3].f1.set_size(b_results.f4.size(0), b_results.f4.size(1)); + loop_ub = b_results.f4.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_results.f4.size(0); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + results[3].f1[i1 + results[3].f1.size(0) * i] = b_results.f4[i1 + + b_results.f4.size(0) * i]; + } + } + + results[4].f1.set_size(b_results.f5.size(0), b_results.f5.size(1)); + loop_ub = b_results.f5.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_results.f5.size(0); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + results[4].f1[i1 + results[4].f1.size(0) * i] = b_results.f5[i1 + + b_results.f5.size(0) * i]; + } + } + + results[5].f1.set_size(b_results.f6.size(0), b_results.f6.size(1)); + loop_ub = b_results.f6.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_results.f6.size(0); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + results[5].f1[i1 + results[5].f1.size(0) * i] = b_results.f6[i1 + + b_results.f6.size(0) * i]; + } + } + break; + + case 1: + if (!coder::internal::d_strcmp(controls->display.data, + controls->display.size)) { + printf("\nRunning simplex\n\n"); + fflush(stdout); + } + + cast(problemDefCells, &r); + runSimplex(outProblemDef, &r, problemDefLimits, controls, &b_problem, + results); + problem->ssubs.set_size(b_problem.ssubs.size(0)); + loop_ub = b_problem.ssubs.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->ssubs[i] = b_problem.ssubs[i]; + } + + problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); + loop_ub = b_problem.backgroundParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->backgroundParams[i] = b_problem.backgroundParams[i]; + } + + problem->qzshifts.set_size(b_problem.qzshifts.size(0)); + loop_ub = b_problem.qzshifts.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->qzshifts[i] = b_problem.qzshifts[i]; + } + + problem->scalefactors.set_size(b_problem.scalefactors.size(0)); + loop_ub = b_problem.scalefactors.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->scalefactors[i] = b_problem.scalefactors[i]; + } + + problem->bulkIn.set_size(b_problem.bulkIn.size(0)); + loop_ub = b_problem.bulkIn.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkIn[i] = b_problem.bulkIn[i]; + } + + problem->bulkOut.set_size(b_problem.bulkOut.size(0)); + loop_ub = b_problem.bulkOut.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkOut[i] = b_problem.bulkOut[i]; + } + + problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); + loop_ub = b_problem.resolutionParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resolutionParams[i] = b_problem.resolutionParams[i]; + } + + problem->calculations = b_problem.calculations; + problem->allSubRough.set_size(b_problem.allSubRough.size(0)); + loop_ub = b_problem.allSubRough.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->allSubRough[i] = b_problem.allSubRough[i]; + } + + problem->resample.set_size(1, b_problem.resample.size(1)); + loop_ub = b_problem.resample.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; + } + break; + + case 2: + if (!coder::internal::d_strcmp(controls->display.data, + controls->display.size)) { + printf("\nRunning Differential Evolution\n\n"); + fflush(stdout); + } + + cast(problemDefCells, &r); + runDE(outProblemDef, &r, problemDefLimits, controls, &b_problem, results); + problem->ssubs.set_size(b_problem.ssubs.size(0)); + loop_ub = b_problem.ssubs.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->ssubs[i] = b_problem.ssubs[i]; + } + + problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); + loop_ub = b_problem.backgroundParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->backgroundParams[i] = b_problem.backgroundParams[i]; + } + + problem->qzshifts.set_size(b_problem.qzshifts.size(0)); + loop_ub = b_problem.qzshifts.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->qzshifts[i] = b_problem.qzshifts[i]; + } + + problem->scalefactors.set_size(b_problem.scalefactors.size(0)); + loop_ub = b_problem.scalefactors.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->scalefactors[i] = b_problem.scalefactors[i]; + } + + problem->bulkIn.set_size(b_problem.bulkIn.size(0)); + loop_ub = b_problem.bulkIn.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkIn[i] = b_problem.bulkIn[i]; + } + + problem->bulkOut.set_size(b_problem.bulkOut.size(0)); + loop_ub = b_problem.bulkOut.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkOut[i] = b_problem.bulkOut[i]; + } + + problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); + loop_ub = b_problem.resolutionParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resolutionParams[i] = b_problem.resolutionParams[i]; + } + + problem->calculations = b_problem.calculations; + problem->allSubRough.set_size(b_problem.allSubRough.size(0)); + loop_ub = b_problem.allSubRough.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->allSubRough[i] = b_problem.allSubRough[i]; + } + + problem->resample.set_size(1, b_problem.resample.size(1)); + loop_ub = b_problem.resample.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; + } + break; + + case 3: + if (!coder::internal::d_strcmp(controls->display.data, + controls->display.size)) { + printf("\nRunning Nested Sampler\n\n"); + fflush(stdout); + } + + cast(problemDefCells, &r); + runNestedSampler(outProblemDef, &r, problemDefLimits, controls, priors, + &b_problem, results, bayesResults); + problem->ssubs.set_size(b_problem.ssubs.size(0)); + loop_ub = b_problem.ssubs.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->ssubs[i] = b_problem.ssubs[i]; + } + + problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); + loop_ub = b_problem.backgroundParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->backgroundParams[i] = b_problem.backgroundParams[i]; + } + + problem->qzshifts.set_size(b_problem.qzshifts.size(0)); + loop_ub = b_problem.qzshifts.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->qzshifts[i] = b_problem.qzshifts[i]; + } + + problem->scalefactors.set_size(b_problem.scalefactors.size(0)); + loop_ub = b_problem.scalefactors.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->scalefactors[i] = b_problem.scalefactors[i]; + } + + problem->bulkIn.set_size(b_problem.bulkIn.size(0)); + loop_ub = b_problem.bulkIn.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkIn[i] = b_problem.bulkIn[i]; + } + + problem->bulkOut.set_size(b_problem.bulkOut.size(0)); + loop_ub = b_problem.bulkOut.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkOut[i] = b_problem.bulkOut[i]; + } + + problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); + loop_ub = b_problem.resolutionParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resolutionParams[i] = b_problem.resolutionParams[i]; + } + + problem->calculations = b_problem.calculations; + problem->allSubRough.set_size(b_problem.allSubRough.size(0)); + loop_ub = b_problem.allSubRough.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->allSubRough[i] = b_problem.allSubRough[i]; + } + + problem->resample.set_size(1, b_problem.resample.size(1)); + loop_ub = b_problem.resample.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; + } + break; + + case 4: + if (!coder::internal::d_strcmp(controls->display.data, + controls->display.size)) { + printf("\nRunning DREAM\n\n"); + fflush(stdout); + } + + cast(problemDef, &outProblemDef_tmp); + cast(problemDefCells, &r); + runDREAM(&outProblemDef_tmp, &r, problemDefLimits, controls, priors, + outProblemDef, &b_problem, results, &b_bayesResults); + bayesResults->bestFitsMean = b_bayesResults.bestFitsMean; + bayesResults->predlims = b_bayesResults.predlims; + bayesResults->parConfInts = b_bayesResults.parConfInts; + bayesResults->bestPars.set_size(1, b_bayesResults.bestPars.size(1)); + loop_ub = b_bayesResults.bestPars.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + bayesResults->bestPars[i] = b_bayesResults.bestPars[i]; + } + + bayesResults->chain.set_size(b_bayesResults.chain.size(0), + b_bayesResults.chain.size(1)); + loop_ub = b_bayesResults.chain.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_bayesResults.chain.size(0); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + bayesResults->chain[i1 + bayesResults->chain.size(0) * i] = + b_bayesResults.chain[i1 + b_bayesResults.chain.size(0) * i]; + } + } + + problem->ssubs.set_size(b_problem.ssubs.size(0)); + loop_ub = b_problem.ssubs.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->ssubs[i] = b_problem.ssubs[i]; + } + + problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); + loop_ub = b_problem.backgroundParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->backgroundParams[i] = b_problem.backgroundParams[i]; + } + + problem->qzshifts.set_size(b_problem.qzshifts.size(0)); + loop_ub = b_problem.qzshifts.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->qzshifts[i] = b_problem.qzshifts[i]; + } + + problem->scalefactors.set_size(b_problem.scalefactors.size(0)); + loop_ub = b_problem.scalefactors.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->scalefactors[i] = b_problem.scalefactors[i]; + } + + problem->bulkIn.set_size(b_problem.bulkIn.size(0)); + loop_ub = b_problem.bulkIn.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkIn[i] = b_problem.bulkIn[i]; + } + + problem->bulkOut.set_size(b_problem.bulkOut.size(0)); + loop_ub = b_problem.bulkOut.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkOut[i] = b_problem.bulkOut[i]; + } + + problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); + loop_ub = b_problem.resolutionParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resolutionParams[i] = b_problem.resolutionParams[i]; + } + + problem->calculations = b_problem.calculations; + problem->allSubRough.set_size(b_problem.allSubRough.size(0)); + loop_ub = b_problem.allSubRough.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->allSubRough[i] = b_problem.allSubRough[i]; + } + + problem->resample.set_size(1, b_problem.resample.size(1)); + loop_ub = b_problem.resample.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; + } + + bayesResults->bayesRes.allChains.set_size + (b_bayesResults.bayesRes.allChains.size(0), + b_bayesResults.bayesRes.allChains.size(1), + b_bayesResults.bayesRes.allChains.size(2)); + loop_ub = b_bayesResults.bayesRes.allChains.size(2); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_bayesResults.bayesRes.allChains.size(1); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + b_loop_ub = b_bayesResults.bayesRes.allChains.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + bayesResults->bayesRes.allChains[(i2 + + bayesResults->bayesRes.allChains.size(0) * i1) + + bayesResults->bayesRes.allChains.size(0) * + bayesResults->bayesRes.allChains.size(1) * i] = + b_bayesResults.bayesRes.allChains[(i2 + + b_bayesResults.bayesRes.allChains.size(0) * i1) + + b_bayesResults.bayesRes.allChains.size(0) * + b_bayesResults.bayesRes.allChains.size(1) * i]; + } + } + } + + bayesResults->bayesRes.dreamOutput = b_bayesResults.bayesRes.dreamOutput; + bayesResults->bayesRes.nestOutput.LogZ = + b_bayesResults.bayesRes.nestOutput.LogZ; + bayesResults->bayesRes.nestOutput.nestSamples.set_size(1, 2); + bayesResults->bayesRes.nestOutput.postSamples.set_size(1, 2); + bayesResults->bayesRes.nestOutput.nestSamples[0] = + b_bayesResults.bayesRes.nestOutput.nestSamples.data[0]; + bayesResults->bayesRes.nestOutput.postSamples[0] = + b_bayesResults.bayesRes.nestOutput.postSamples.data[0]; + bayesResults->bayesRes.nestOutput.nestSamples + [bayesResults->bayesRes.nestOutput.nestSamples.size(0)] = + b_bayesResults.bayesRes.nestOutput.nestSamples.data[1]; + bayesResults->bayesRes.nestOutput.postSamples + [bayesResults->bayesRes.nestOutput.postSamples.size(0)] = + b_bayesResults.bayesRes.nestOutput.postSamples.data[1]; + break; + } + + // Then just do a final calculation to fill in SLD if necessary + // (i.e. if calcSLD is no for fit) + if (!controls->calcSldDuringFit) { + controls->calcSldDuringFit = true; + controls->procedure.size[0] = 1; + controls->procedure.size[1] = 9; + for (int32_T i{0}; i < 9; i++) { + controls->procedure.data[i] = cv[i]; + } + + cast(problemDefCells, &r); + reflectivityCalculation(outProblemDef, &r, controls, &b_problem, + &b_results); + problem->ssubs.set_size(b_problem.ssubs.size(0)); + loop_ub = b_problem.ssubs.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->ssubs[i] = b_problem.ssubs[i]; + } + + problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); + loop_ub = b_problem.backgroundParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->backgroundParams[i] = b_problem.backgroundParams[i]; + } + + problem->qzshifts.set_size(b_problem.qzshifts.size(0)); + loop_ub = b_problem.qzshifts.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->qzshifts[i] = b_problem.qzshifts[i]; + } + + problem->scalefactors.set_size(b_problem.scalefactors.size(0)); + loop_ub = b_problem.scalefactors.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->scalefactors[i] = b_problem.scalefactors[i]; + } + + problem->bulkIn.set_size(b_problem.bulkIn.size(0)); + loop_ub = b_problem.bulkIn.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkIn[i] = b_problem.bulkIn[i]; + } + + problem->bulkOut.set_size(b_problem.bulkOut.size(0)); + loop_ub = b_problem.bulkOut.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->bulkOut[i] = b_problem.bulkOut[i]; + } + + problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); + loop_ub = b_problem.resolutionParams.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resolutionParams[i] = b_problem.resolutionParams[i]; + } + + problem->calculations = b_problem.calculations; + problem->allSubRough.set_size(b_problem.allSubRough.size(0)); + loop_ub = b_problem.allSubRough.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + problem->allSubRough[i] = b_problem.allSubRough[i]; + } + + problem->resample.set_size(1, b_problem.resample.size(1)); + loop_ub = b_problem.resample.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; + } + + results[0].f1.set_size(b_results.f1.size(0), 1); + loop_ub_tmp = b_results.f1.size(0); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + loop_ub = b_results.f1[i].f1.size(0); + results[0].f1[i].f1.set_size(b_results.f1[i].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + results[0].f1[i].f1[i2 + results[0].f1[i].f1.size(0) * i1] = + b_results.f1[i].f1[i2 + b_results.f1[i].f1.size(0) * i1]; + } + } + } + + results[1].f1.set_size(b_results.f2.size(0), 1); + loop_ub_tmp = b_results.f2.size(0); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + loop_ub = b_results.f2[i].f1.size(0); + results[1].f1[i].f1.set_size(b_results.f2[i].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + results[1].f1[i].f1[i2 + results[1].f1[i].f1.size(0) * i1] = + b_results.f2[i].f1[i2 + b_results.f2[i].f1.size(0) * i1]; + } + } + } + + results[2].f1.set_size(b_results.f3.size(0), 1); + loop_ub_tmp = b_results.f3.size(0); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + loop_ub = b_results.f3[i].f1.size(0); + results[2].f1[i].f1.set_size(b_results.f3[i].f1.size(0), 3); + for (int32_T i1{0}; i1 < 3; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + results[2].f1[i].f1[i2 + results[2].f1[i].f1.size(0) * i1] = + b_results.f3[i].f1[i2 + b_results.f3[i].f1.size(0) * i1]; + } + } + } + + results[3].f1.set_size(b_results.f4.size(0), b_results.f4.size(1)); + loop_ub = b_results.f4.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_results.f4.size(0); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + results[3].f1[i1 + results[3].f1.size(0) * i] = b_results.f4[i1 + + b_results.f4.size(0) * i]; + } + } + + results[4].f1.set_size(b_results.f5.size(0), b_results.f5.size(1)); + loop_ub = b_results.f5.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_results.f5.size(0); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + results[4].f1[i1 + results[4].f1.size(0) * i] = b_results.f5[i1 + + b_results.f5.size(0) * i]; + } + } + + results[5].f1.set_size(b_results.f6.size(0), b_results.f6.size(1)); + loop_ub = b_results.f6.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_results.f6.size(0); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + results[5].f1[i1 + results[5].f1.size(0) * i] = b_results.f6[i1 + + b_results.f6.size(0) * i]; + } + } + } + } +} + +// End of code generation (RATMain.cpp) diff --git a/RAT/RATMain.h b/RAT/RATMain.h new file mode 100644 index 00000000..533ad963 --- /dev/null +++ b/RAT/RATMain.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// RATMain.h +// +// Code generation for function 'RATMain' +// +#ifndef RATMAIN_H +#define RATMAIN_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + extern void RATMain(const struct0_T *problemDef, const cell_7 *problemDefCells, + const struct1_T *problemDefLimits, struct2_T *controls, + const struct4_T *priors, struct5_T *outProblemDef, + struct6_T *problem, cell_wrap_9 results[6], struct8_T + *bayesResults); +} + +#endif + +// End of code generation (RATMain.h) diff --git a/RAT/RATMain_data.cpp b/RAT/RATMain_data.cpp new file mode 100644 index 00000000..33bb8d40 --- /dev/null +++ b/RAT/RATMain_data.cpp @@ -0,0 +1,177 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// RATMain_data.cpp +// +// Code generation for function 'RATMain_data' +// + +// Include files +#include "RATMain_data.h" +#include "rt_nonfinite.h" + +// Variable Definitions +namespace RAT +{ + uint32_T state[625]; + real_T verbose; + real_T DEBUG; + real_T lastNchar; + boolean_T lastNchar_not_empty; + real_T freq; + boolean_T freq_not_empty; + omp_nest_lock_t RATMain_nestLockGlobal; + const char_T cv[9]{ 'c', 'a', 'l', 'c', 'u', 'l', 'a', 't', 'e' }; + + const char_T cv1[128]{ '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', + '\x07', '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f', + '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', + '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', ' ', '!', '\"', '#', + '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', + '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', + 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', + 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\\', ']', '^', '_', + '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', + '~', '\x7f' }; + + const real_T dv[257]{ 0.0, 0.215241895984875, 0.286174591792068, + 0.335737519214422, 0.375121332878378, 0.408389134611989, 0.43751840220787, + 0.46363433679088, 0.487443966139235, 0.50942332960209, 0.529909720661557, + 0.549151702327164, 0.567338257053817, 0.584616766106378, 0.601104617755991, + 0.61689699000775, 0.63207223638606, 0.646695714894993, 0.660822574244419, + 0.674499822837293, 0.687767892795788, 0.700661841106814, 0.713212285190975, + 0.725446140909999, 0.737387211434295, 0.749056662017815, 0.760473406430107, + 0.771654424224568, 0.782615023307232, 0.793369058840623, 0.80392911698997, + 0.814306670135215, 0.824512208752291, 0.834555354086381, 0.844444954909153, + 0.854189171008163, 0.863795545553308, 0.87327106808886, 0.882622229585165, + 0.891855070732941, 0.900975224461221, 0.909987953496718, 0.91889818364959, + 0.927710533401999, 0.936429340286575, 0.945058684468165, 0.953602409881086, + 0.96206414322304, 0.970447311064224, 0.978755155294224, 0.986990747099062, + 0.99515699963509, 1.00325667954467, 1.01129241744, 1.01926671746548, + 1.02718196603564, 1.03504043983344, 1.04284431314415, 1.05059566459093, + 1.05829648333067, 1.06594867476212, 1.07355406579244, 1.0811144097034, + 1.08863139065398, 1.09610662785202, 1.10354167942464, 1.11093804601357, + 1.11829717411934, 1.12562045921553, 1.13290924865253, 1.14016484436815, + 1.14738850542085, 1.15458145035993, 1.16174485944561, 1.16887987673083, + 1.17598761201545, 1.18306914268269, 1.19012551542669, 1.19715774787944, + 1.20416683014438, 1.2111537262437, 1.21811937548548, 1.22506469375653, + 1.23199057474614, 1.23889789110569, 1.24578749554863, 1.2526602218949, + 1.25951688606371, 1.26635828701823, 1.27318520766536, 1.27999841571382, + 1.28679866449324, 1.29358669373695, 1.30036323033084, 1.30712898903073, + 1.31388467315022, 1.32063097522106, 1.32736857762793, 1.33409815321936, + 1.3408203658964, 1.34753587118059, 1.35424531676263, 1.36094934303328, + 1.36764858359748, 1.37434366577317, 1.38103521107586, 1.38772383568998, + 1.39441015092814, 1.40109476367925, 1.4077782768464, 1.41446128977547, + 1.42114439867531, 1.42782819703026, 1.43451327600589, 1.44120022484872, + 1.44788963128058, 1.45458208188841, 1.46127816251028, 1.46797845861808, + 1.47468355569786, 1.48139403962819, 1.48811049705745, 1.49483351578049, + 1.50156368511546, 1.50830159628131, 1.51504784277671, 1.521803020761, + 1.52856772943771, 1.53534257144151, 1.542128153229, 1.54892508547417, + 1.55573398346918, 1.56255546753104, 1.56939016341512, 1.57623870273591, + 1.58310172339603, 1.58997987002419, 1.59687379442279, 1.60378415602609, + 1.61071162236983, 1.61765686957301, 1.62462058283303, 1.63160345693487, + 1.63860619677555, 1.64562951790478, 1.65267414708306, 1.65974082285818, + 1.66683029616166, 1.67394333092612, 1.68108070472517, 1.68824320943719, + 1.69543165193456, 1.70264685479992, 1.7098896570713, 1.71716091501782, + 1.72446150294804, 1.73179231405296, 1.73915426128591, 1.74654827828172, + 1.75397532031767, 1.76143636531891, 1.76893241491127, 1.77646449552452, + 1.78403365954944, 1.79164098655216, 1.79928758454972, 1.80697459135082, + 1.81470317596628, 1.82247454009388, 1.83028991968276, 1.83815058658281, + 1.84605785028518, 1.8540130597602, 1.86201760539967, 1.87007292107127, + 1.878180486293, 1.88634182853678, 1.8945585256707, 1.90283220855043, + 1.91116456377125, 1.91955733659319, 1.92801233405266, 1.93653142827569, + 1.94511656000868, 1.95376974238465, 1.96249306494436, 1.97128869793366, + 1.98015889690048, 1.98910600761744, 1.99813247135842, 2.00724083056053, + 2.0164337349062, 2.02571394786385, 2.03508435372962, 2.04454796521753, + 2.05410793165065, 2.06376754781173, 2.07353026351874, 2.0833996939983, + 2.09337963113879, 2.10347405571488, 2.11368715068665, 2.12402331568952, + 2.13448718284602, 2.14508363404789, 2.15581781987674, 2.16669518035431, + 2.17772146774029, 2.18890277162636, 2.20024554661128, 2.21175664288416, + 2.22344334009251, 2.23531338492992, 2.24737503294739, 2.25963709517379, + 2.27210899022838, 2.28480080272449, 2.29772334890286, 2.31088825060137, + 2.32430801887113, 2.33799614879653, 2.35196722737914, 2.36623705671729, + 2.38082279517208, 2.39574311978193, 2.41101841390112, 2.42667098493715, + 2.44272531820036, 2.4592083743347, 2.47614993967052, 2.49358304127105, + 2.51154444162669, 2.53007523215985, 2.54922155032478, 2.56903545268184, + 2.58957598670829, 2.61091051848882, 2.63311639363158, 2.65628303757674, + 2.68051464328574, 2.70593365612306, 2.73268535904401, 2.76094400527999, + 2.79092117400193, 2.82287739682644, 2.85713873087322, 2.89412105361341, + 2.93436686720889, 2.97860327988184, 3.02783779176959, 3.08352613200214, + 3.147889289518, 3.2245750520478, 3.32024473383983, 3.44927829856143, + 3.65415288536101, 3.91075795952492 }; + + const real_T dv1[257]{ 1.0, 0.977101701267673, 0.959879091800108, + 0.9451989534423, 0.932060075959231, 0.919991505039348, 0.908726440052131, + 0.898095921898344, 0.887984660755834, 0.878309655808918, 0.869008688036857, + 0.860033621196332, 0.851346258458678, 0.842915653112205, 0.834716292986884, + 0.826726833946222, 0.818929191603703, 0.811307874312656, 0.803849483170964, + 0.796542330422959, 0.789376143566025, 0.782341832654803, 0.775431304981187, + 0.768637315798486, 0.761953346836795, 0.755373506507096, 0.748892447219157, + 0.742505296340151, 0.736207598126863, 0.729995264561476, 0.72386453346863, + 0.717811932630722, 0.711834248878248, 0.705928501332754, 0.700091918136512, + 0.694321916126117, 0.688616083004672, 0.682972161644995, 0.677388036218774, + 0.671861719897082, 0.66639134390875, 0.660975147776663, 0.655611470579697, + 0.650298743110817, 0.645035480820822, 0.639820277453057, 0.634651799287624, + 0.629528779924837, 0.624450015547027, 0.619414360605834, 0.614420723888914, + 0.609468064925773, 0.604555390697468, 0.599681752619125, 0.594846243767987, + 0.590047996332826, 0.585286179263371, 0.580559996100791, 0.575868682972354, + 0.571211506735253, 0.566587763256165, 0.561996775814525, 0.557437893618766, + 0.552910490425833, 0.548413963255266, 0.543947731190026, 0.539511234256952, + 0.535103932380458, 0.530725304403662, 0.526374847171684, 0.522052074672322, + 0.517756517229756, 0.513487720747327, 0.509245245995748, 0.505028667943468, + 0.500837575126149, 0.49667156905249, 0.492530263643869, 0.488413284705458, + 0.484320269426683, 0.480250865909047, 0.476204732719506, 0.47218153846773, + 0.468180961405694, 0.464202689048174, 0.460246417812843, 0.456311852678716, + 0.452398706861849, 0.448506701507203, 0.444635565395739, 0.440785034665804, + 0.436954852547985, 0.433144769112652, 0.429354541029442, 0.425583931338022, + 0.421832709229496, 0.418100649837848, 0.414387534040891, 0.410693148270188, + 0.407017284329473, 0.403359739221114, 0.399720314980197, 0.396098818515832, + 0.392495061459315, 0.388908860018789, 0.385340034840077, 0.381788410873393, + 0.378253817245619, 0.374736087137891, 0.371235057668239, 0.367750569779032, + 0.364282468129004, 0.360830600989648, 0.357394820145781, 0.353974980800077, + 0.350570941481406, 0.347182563956794, 0.343809713146851, 0.340452257044522, + 0.337110066637006, 0.333783015830718, 0.330470981379163, 0.327173842813601, + 0.323891482376391, 0.320623784956905, 0.317370638029914, 0.314131931596337, + 0.310907558126286, 0.307697412504292, 0.30450139197665, 0.301319396100803, + 0.298151326696685, 0.294997087799962, 0.291856585617095, 0.288729728482183, + 0.285616426815502, 0.282516593083708, 0.279430141761638, 0.276356989295668, + 0.273297054068577, 0.270250256365875, 0.267216518343561, 0.264195763997261, + 0.261187919132721, 0.258192911337619, 0.255210669954662, 0.252241126055942, + 0.249284212418529, 0.246339863501264, 0.24340801542275, 0.240488605940501, + 0.237581574431238, 0.23468686187233, 0.231804410824339, 0.228934165414681, + 0.226076071322381, 0.223230075763918, 0.220396127480152, 0.217574176724331, + 0.214764175251174, 0.211966076307031, 0.209179834621125, 0.206405406397881, + 0.203642749310335, 0.200891822494657, 0.198152586545776, 0.195425003514135, + 0.192709036903589, 0.190004651670465, 0.187311814223801, 0.1846304924268, + 0.181960655599523, 0.179302274522848, 0.176655321443735, 0.174019770081839, + 0.171395595637506, 0.168782774801212, 0.166181285764482, 0.163591108232366, + 0.161012223437511, 0.158444614155925, 0.15588826472448, 0.153343161060263, + 0.150809290681846, 0.148286642732575, 0.145775208005994, 0.143274978973514, + 0.140785949814445, 0.138308116448551, 0.135841476571254, 0.133386029691669, + 0.130941777173644, 0.12850872228, 0.126086870220186, 0.123676228201597, + 0.12127680548479, 0.11888861344291, 0.116511665625611, 0.114145977827839, + 0.111791568163838, 0.109448457146812, 0.107116667774684, 0.104796225622487, + 0.102487158941935, 0.10018949876881, 0.0979032790388625, 0.095628536713009, + 0.093365311912691, 0.0911136480663738, 0.0888735920682759, + 0.0866451944505581, 0.0844285095703535, 0.082223595813203, + 0.0800305158146631, 0.0778493367020961, 0.0756801303589272, + 0.0735229737139814, 0.0713779490588905, 0.0692451443970068, + 0.0671246538277886, 0.065016577971243, 0.0629210244377582, 0.06083810834954, + 0.0587679529209339, 0.0567106901062031, 0.0546664613248891, + 0.0526354182767924, 0.0506177238609479, 0.0486135532158687, + 0.0466230949019305, 0.0446465522512946, 0.0426841449164746, + 0.0407361106559411, 0.0388027074045262, 0.0368842156885674, + 0.0349809414617162, 0.0330932194585786, 0.0312214171919203, + 0.0293659397581334, 0.0275272356696031, 0.0257058040085489, + 0.0239022033057959, 0.0221170627073089, 0.0203510962300445, + 0.0186051212757247, 0.0168800831525432, 0.0151770883079353, + 0.0134974506017399, 0.0118427578579079, 0.0102149714397015, + 0.00861658276939875, 0.00705087547137324, 0.00552240329925101, + 0.00403797259336304, 0.00260907274610216, 0.0012602859304986, + 0.000477467764609386 }; +} + +// End of code generation (RATMain_data.cpp) diff --git a/RAT/RATMain_data.h b/RAT/RATMain_data.h new file mode 100644 index 00000000..44fd1366 --- /dev/null +++ b/RAT/RATMain_data.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// RATMain_data.h +// +// Code generation for function 'RATMain_data' +// +#ifndef RATMAIN_DATA_H +#define RATMAIN_DATA_H + +// Include files +#include "rtwtypes.h" +#include "omp.h" +#include +#include + +// Variable Declarations +namespace RAT +{ + extern uint32_T state[625]; + extern real_T verbose; + extern real_T DEBUG; + extern real_T lastNchar; + extern boolean_T lastNchar_not_empty; + extern real_T freq; + extern boolean_T freq_not_empty; + extern omp_nest_lock_t RATMain_nestLockGlobal; + extern const char_T cv[9]; + extern const char_T cv1[128]; + extern const real_T dv[257]; + extern const real_T dv1[257]; +} + +#endif + +// End of code generation (RATMain_data.h) diff --git a/RAT/RATMain_initialize.cpp b/RAT/RATMain_initialize.cpp new file mode 100644 index 00000000..b8312c33 --- /dev/null +++ b/RAT/RATMain_initialize.cpp @@ -0,0 +1,43 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// RATMain_initialize.cpp +// +// Code generation for function 'RATMain_initialize' +// + +// Include files +#include "RATMain_initialize.h" +#include "CoderTimeAPI.h" +#include "RATMain_data.h" +#include "RATMain_rtwutil.h" +#include "eml_rand_mt19937ar_stateful.h" +#include "fileManager.h" +#include "rt_nonfinite.h" +#include "textProgressBar.h" +#include "timeKeeper.h" +#include "triggerEvent.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + void RATMain_initialize() + { + omp_init_nest_lock(&RATMain_nestLockGlobal); + savedTime_not_empty_init(); + freq_not_empty_init(); + lastNchar_not_empty_init(); + DEBUG = 0.0; + verbose = 1.0; + helper_not_empty_init(); + triggerEvent_init(); + eml_rand_mt19937ar_stateful_init(); + filedata_init(); + emlrtInitThreadStackData(); + } +} + +// End of code generation (RATMain_initialize.cpp) diff --git a/RAT/reflectivityCalculation_terminate.h b/RAT/RATMain_initialize.h similarity index 50% rename from RAT/reflectivityCalculation_terminate.h rename to RAT/RATMain_initialize.h index 7f574928..903aca7d 100644 --- a/RAT/reflectivityCalculation_terminate.h +++ b/RAT/RATMain_initialize.h @@ -3,12 +3,12 @@ // granting, nonprofit, education, and research organizations only. Not // for commercial or industrial use. // -// reflectivityCalculation_terminate.h +// RATMain_initialize.h // -// Code generation for function 'reflectivityCalculation_terminate' +// Code generation for function 'RATMain_initialize' // -#ifndef REFLECTIVITYCALCULATION_TERMINATE_H -#define REFLECTIVITYCALCULATION_TERMINATE_H +#ifndef RATMAIN_INITIALIZE_H +#define RATMAIN_INITIALIZE_H // Include files #include "rtwtypes.h" @@ -18,9 +18,9 @@ // Function Declarations namespace RAT { - extern void reflectivityCalculation_terminate(); + extern void RATMain_initialize(); } #endif -// End of code generation (reflectivityCalculation_terminate.h) +// End of code generation (RATMain_initialize.h) diff --git a/RAT/RATMain_internal_types.h b/RAT/RATMain_internal_types.h new file mode 100644 index 00000000..3e937962 --- /dev/null +++ b/RAT/RATMain_internal_types.h @@ -0,0 +1,182 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// RATMain_internal_types.h +// +// Code generation for function 'RATMain' +// +#ifndef RATMAIN_INTERNAL_TYPES_H +#define RATMAIN_INTERNAL_TYPES_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Type Definitions +namespace RAT +{ + struct cell_13 + { + ::coder::array f1; + ::coder::array f2; + ::coder::array f3; + ::coder::array f4; + ::coder::array f5; + ::coder::array f6; + }; + + struct struct_T + { + ::coder::array ssubs; + ::coder::array backgroundParams; + ::coder::array qzshifts; + ::coder::array scalefactors; + ::coder::array bulkIn; + ::coder::array bulkOut; + ::coder::array resolutionParams; + struct7_T calculations; + ::coder::array allSubRough; + ::coder::array resample; + }; + + struct b_struct_T + { + real_T LogZ; + ::coder::bounded_array nestSamples; + ::coder::bounded_array postSamples; + }; + + struct c_struct_T + { + ::coder::array allChains; + struct13_T dreamOutput; + b_struct_T nestOutput; + }; + + struct d_struct_T + { + struct9_T bestFitsMean; + struct10_T predlims; + struct11_T parConfInts; + ::coder::array bestPars; + c_struct_T bayesRes; + ::coder::array chain; + }; + + struct cell_14 + { + ::coder::array f1; + ::coder::array f2; + ::coder::array f3; + ::coder::array f4; + ::coder::array f5; + ::coder::array f6; + ::coder::array f7; + ::coder::array f8; + ::coder::array f9; + ::coder::array f10; + ::coder::array f11; + ::coder::array f12; + ::coder::array f13; + ::coder::array f14; + ::coder::array f15; + ::coder::array f16; + ::coder::array f17; + ::coder::array f18; + ::coder::array f19; + ::coder::array f20; + }; + + struct cell_wrap_15 + { + ::coder::array f1; + }; + + struct cell_wrap_17 + { + ::coder::array f1; + }; + + struct cell_wrap_36 + { + ::coder::array f1; + }; + + struct cell_wrap_37 + { + cell_wrap_8 f1[2]; + }; + + struct e_struct_T + { + ::coder::array ref; + ::coder::array sld; + real_T chi; + ::coder::array data; + }; + + struct f_struct_T + { + ::coder::array refPredInts; + ::coder::array sldPredInts; + ::coder::array refXdata; + ::coder::array sldXdata; + real_T sampleChi[1000]; + }; + + struct h_struct_T + { + real_T iterations; + real_T funcCount; + char_T algorithm[33]; + ::coder::array message; + }; + + struct i_struct_T + { + ::coder::bounded_array I_lentol; + ::coder::bounded_array FVr_x; + ::coder::bounded_array FVr_lim_up; + ::coder::bounded_array FVr_lim_lo; + real_T I_NP; + real_T fWeight; + real_T F_CR; + real_T I_D; + ::coder::array FVr_minbound; + ::coder::array FVr_maxbound; + real_T I_bnd_constr; + real_T I_itermax; + real_T F_VTR; + real_T I_strategy; + real_T I_refresh; + real_T I_plotting; + ::coder::array FM_pop; + ::coder::array FVr_bestmem; + }; + + struct cell_27 + { + ::coder::array f1; + }; + + struct j_struct_T + { + ::coder::array LB; + ::coder::array UB; + ::coder::array BoundClass; + }; + + struct k_struct_T + { + real_T I_no; + real_T FVr_oa; + }; +} + +#endif + +// End of code generation (RATMain_internal_types.h) diff --git a/RAT/RATMain_rtwutil.cpp b/RAT/RATMain_rtwutil.cpp new file mode 100644 index 00000000..ede48b37 --- /dev/null +++ b/RAT/RATMain_rtwutil.cpp @@ -0,0 +1,248 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// RATMain_rtwutil.cpp +// +// Code generation for function 'RATMain_rtwutil' +// + +// Include files +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "omp.h" +#include +#include +#include + +// Variable Definitions +namespace RAT +{ + static RATMainTLS *RATMainTLSGlobal; + +#pragma omp threadprivate (RATMainTLSGlobal) + +} + +// Function Definitions +namespace RAT +{ + void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(5, r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + for (int32_T i3{0}; i3 < 5; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + 5 * i2]; + } + } + } + } + + void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(1, r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + r1[i1].f1[r1[i1].f1.size(0) * i2] = r[i1].f1[i2]; + } + } + } + + void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(0); + r1[i1].f1.set_size(r[i1].f1.size(0), 2); + for (int32_T i2{0}; i2 < 2; i2++) { + for (int32_T i3{0}; i3 < loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(0); + r1[i1].f1.set_size(r[i1].f1.size(0), 3); + for (int32_T i2{0}; i2 < 3; i2++) { + for (int32_T i3{0}; i3 < loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1) + { + int32_T i; + r1.set_size(r.size(0), 2); + i = r.size(0) << 1; + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + void emlrtFreeThreadStackData() + { + int32_T b; + b = omp_get_max_threads(); + +#pragma omp parallel for schedule(static)\ + num_threads(omp_get_max_threads()) + + for (int32_T i = 1; i <= b; i++) { + delete RATMainTLSGlobal; + } + } + + RATMainTLS *emlrtGetThreadStackData() + { + return RATMainTLSGlobal; + } + + void emlrtInitThreadStackData() + { + int32_T b; + b = omp_get_max_threads(); + +#pragma omp parallel for schedule(static)\ + num_threads(omp_get_max_threads()) + + for (int32_T i = 1; i <= b; i++) { + RATMainTLSGlobal = static_cast(new RATMainTLS); + } + } + + real_T rt_hypotd_snf(real_T u0, real_T u1) + { + real_T a; + real_T b; + real_T y; + a = std::abs(u0); + b = std::abs(u1); + if (a < b) { + a /= b; + y = b * std::sqrt(a * a + 1.0); + } else if (a > b) { + b /= a; + y = a * std::sqrt(b * b + 1.0); + } else if (std::isnan(b)) { + y = rtNaN; + } else { + y = a * 1.4142135623730951; + } + + return y; + } + + real_T rt_powd_snf(real_T u0, real_T u1) + { + real_T y; + if (std::isnan(u0) || std::isnan(u1)) { + y = rtNaN; + } else { + real_T d; + real_T d1; + d = std::abs(u0); + d1 = std::abs(u1); + if (std::isinf(u1)) { + if (d == 1.0) { + y = 1.0; + } else if (d > 1.0) { + if (u1 > 0.0) { + y = rtInf; + } else { + y = 0.0; + } + } else if (u1 > 0.0) { + y = 0.0; + } else { + y = rtInf; + } + } else if (d1 == 0.0) { + y = 1.0; + } else if (d1 == 1.0) { + if (u1 > 0.0) { + y = u0; + } else { + y = 1.0 / u0; + } + } else if (u1 == 2.0) { + y = u0 * u0; + } else if ((u1 == 0.5) && (u0 >= 0.0)) { + y = std::sqrt(u0); + } else if ((u0 < 0.0) && (u1 > std::floor(u1))) { + y = rtNaN; + } else { + y = std::pow(u0, u1); + } + } + + return y; + } + + real_T rt_remd_snf(real_T u0, real_T u1) + { + real_T y; + if (std::isnan(u0) || std::isnan(u1) || std::isinf(u0)) { + y = rtNaN; + } else if (std::isinf(u1)) { + y = u0; + } else if ((u1 != 0.0) && (u1 != std::trunc(u1))) { + real_T q; + q = std::abs(u0 / u1); + if (!(std::abs(q - std::floor(q + 0.5)) > DBL_EPSILON * q)) { + y = 0.0 * u0; + } else { + y = std::fmod(u0, u1); + } + } else { + y = std::fmod(u0, u1); + } + + return y; + } +} + +// End of code generation (RATMain_rtwutil.cpp) diff --git a/RAT/RATMain_rtwutil.h b/RAT/RATMain_rtwutil.h new file mode 100644 index 00000000..c53ef8e1 --- /dev/null +++ b/RAT/RATMain_rtwutil.h @@ -0,0 +1,43 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// RATMain_rtwutil.h +// +// Code generation for function 'RATMain_rtwutil' +// +#ifndef RATMAIN_RTWUTIL_H +#define RATMAIN_RTWUTIL_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + extern void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1); + extern void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1); + extern void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1); + extern void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1); + extern void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1); + extern void emlrtFreeThreadStackData(); + extern RATMainTLS *emlrtGetThreadStackData(); + extern void emlrtInitThreadStackData(); + extern real_T rt_hypotd_snf(real_T u0, real_T u1); + extern real_T rt_powd_snf(real_T u0, real_T u1); + extern real_T rt_remd_snf(real_T u0, real_T u1); +} + +#endif + +// End of code generation (RATMain_rtwutil.h) diff --git a/RAT/RATMain_terminate.cpp b/RAT/RATMain_terminate.cpp new file mode 100644 index 00000000..73060f92 --- /dev/null +++ b/RAT/RATMain_terminate.cpp @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// RATMain_terminate.cpp +// +// Code generation for function 'RATMain_terminate' +// + +// Include files +#include "RATMain_terminate.h" +#include "RATMain_data.h" +#include "RATMain_rtwutil.h" +#include "rt_nonfinite.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + void RATMain_terminate() + { + emlrtFreeThreadStackData(); + omp_destroy_nest_lock(&RATMain_nestLockGlobal); + } +} + +// End of code generation (RATMain_terminate.cpp) diff --git a/RAT/RATMain_terminate.h b/RAT/RATMain_terminate.h new file mode 100644 index 00000000..321b33aa --- /dev/null +++ b/RAT/RATMain_terminate.h @@ -0,0 +1,26 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// RATMain_terminate.h +// +// Code generation for function 'RATMain_terminate' +// +#ifndef RATMAIN_TERMINATE_H +#define RATMAIN_TERMINATE_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + extern void RATMain_terminate(); +} + +#endif + +// End of code generation (RATMain_terminate.h) diff --git a/RAT/RATMain_types.h b/RAT/RATMain_types.h new file mode 100644 index 00000000..90b06705 --- /dev/null +++ b/RAT/RATMain_types.h @@ -0,0 +1,411 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// RATMain_types.h +// +// Code generation for function 'RATMain' +// +#ifndef RATMAIN_TYPES_H +#define RATMAIN_TYPES_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#define MAX_THREADS omp_get_max_threads() + +// Type Definitions +namespace RAT +{ + struct struct15_T + { + real_T Y; + real_T N; + }; + + struct cell_wrap_2 + { + real_T f1[2]; + }; + + struct struct0_T + { + ::coder::array contrastBackgrounds; + ::coder::array contrastBackgroundsType; + ::coder::bounded_array TF; + ::coder::array resample; + ::coder::array dataPresent; + ::coder::array oilChiDataPresent; + real_T numberOfContrasts; + ::coder::bounded_array geometry; + boolean_T useImaginary; + ::coder::array contrastQzshifts; + ::coder::array contrastScalefactors; + ::coder::array contrastBulkIns; + ::coder::array contrastBulkOuts; + ::coder::array contrastResolutions; + ::coder::array backgroundParams; + ::coder::array qzshifts; + ::coder::array scalefactors; + ::coder::array bulkIn; + ::coder::array bulkOut; + ::coder::array resolutionParams; + ::coder::array params; + real_T numberOfLayers; + ::coder::bounded_array modelType; + ::coder::array contrastCustomFiles; + ::coder::array contrastDomainRatios; + ::coder::array domainRatio; + real_T numberOfDomainContrasts; + ::coder::array fitParams; + ::coder::array otherParams; + ::coder::array fitLimits; + ::coder::array otherLimits; + }; + + struct cell_wrap_3 + { + ::coder::array f1; + }; + + struct cell_wrap_4 + { + ::coder::array f1; + }; + + struct cell_wrap_5 + { + ::coder::bounded_array f1; + }; + + struct cell_wrap_6 + { + ::coder::bounded_array f1; + }; + + struct cell_7 + { + ::coder::array f1; + ::coder::array f2; + ::coder::array f3; + ::coder::array f4; + ::coder::array f5; + ::coder::array f6; + ::coder::array f7; + ::coder::array f8; + ::coder::array f9; + ::coder::array f10; + ::coder::array f11; + ::coder::array f12; + ::coder::array f13; + ::coder::array f14; + ::coder::array f15; + ::coder::array f16; + ::coder::array f17; + ::coder::array f18; + ::coder::array f19; + ::coder::array f20; + }; + + struct struct1_T + { + ::coder::array param; + ::coder::array backgroundParam; + ::coder::array scalefactor; + ::coder::array qzshift; + ::coder::array bulkIn; + ::coder::array bulkOut; + ::coder::array resolutionParam; + ::coder::array domainRatio; + }; + + struct struct3_T + { + ::coder::array fitParam; + ::coder::array fitBackgroundParam; + ::coder::array fitQzshift; + ::coder::array fitScalefactor; + ::coder::array fitBulkIn; + ::coder::array fitBulkOut; + ::coder::array fitResolutionParam; + ::coder::array fitDomainRatio; + }; + + struct struct2_T + { + ::coder::bounded_array procedure; + ::coder::bounded_array parallel; + real_T resamPars[2]; + boolean_T calcSldDuringFit; + ::coder::bounded_array display; + real_T tolX; + real_T tolFun; + real_T maxFunEvals; + real_T maxIter; + real_T updateFreq; + real_T updatePlotFreq; + real_T populationSize; + real_T fWeight; + real_T crossoverProbability; + real_T strategy; + real_T targetValue; + real_T numGenerations; + real_T Nlive; + real_T Nmcmc; + real_T propScale; + real_T nsTolerance; + real_T nSamples; + real_T nChains; + real_T jumpProbability; + real_T pUnitGamma; + ::coder::bounded_array boundHandling; + boolean_T adaptPCR; + struct3_T checks; + }; + + struct cell_0 + { + ::coder::array f1; + ::coder::array f2; + real_T f3; + real_T f4; + }; + + struct cell_wrap_1 + { + ::coder::array f1; + }; + + struct struct4_T + { + ::coder::array param; + ::coder::array backgroundParam; + ::coder::array resolutionParam; + ::coder::array bulkIn; + ::coder::array bulkOut; + ::coder::array qzshift; + ::coder::array scalefactor; + ::coder::array domainRatio; + ::coder::array priorNames; + ::coder::array priorValues; + }; + + struct struct5_T + { + ::coder::array contrastBackgrounds; + ::coder::array contrastBackgroundsType; + ::coder::bounded_array TF; + ::coder::array resample; + ::coder::array dataPresent; + ::coder::array oilChiDataPresent; + real_T numberOfContrasts; + ::coder::bounded_array geometry; + boolean_T useImaginary; + ::coder::array contrastQzshifts; + ::coder::array contrastScalefactors; + ::coder::array contrastBulkIns; + ::coder::array contrastBulkOuts; + ::coder::array contrastResolutions; + ::coder::array backgroundParams; + ::coder::array qzshifts; + ::coder::array scalefactors; + ::coder::array bulkIn; + ::coder::array bulkOut; + ::coder::array resolutionParams; + ::coder::array params; + real_T numberOfLayers; + ::coder::bounded_array modelType; + ::coder::array contrastCustomFiles; + ::coder::array contrastDomainRatios; + ::coder::array domainRatio; + real_T numberOfDomainContrasts; + ::coder::array fitParams; + ::coder::array otherParams; + ::coder::array fitLimits; + ::coder::array otherLimits; + }; + + struct struct7_T + { + ::coder::array allChis; + real_T sumChi; + }; + + struct struct6_T + { + ::coder::array ssubs; + ::coder::array backgroundParams; + ::coder::array qzshifts; + ::coder::array scalefactors; + ::coder::array bulkIn; + ::coder::array bulkOut; + ::coder::array resolutionParams; + struct7_T calculations; + ::coder::array allSubRough; + ::coder::array resample; + }; + + struct cell_wrap_8 + { + ::coder::array f1; + }; + + struct cell_wrap_9 + { + ::coder::array f1; + }; + + struct struct9_T + { + ::coder::array ref; + ::coder::array sld; + real_T chi; + ::coder::array data; + }; + + struct struct10_T + { + ::coder::array refPredInts; + ::coder::array sldPredInts; + ::coder::array refXdata; + ::coder::array sldXdata; + ::coder::bounded_array sampleChi; + }; + + struct struct11_T + { + ::coder::array par95; + ::coder::array par65; + ::coder::array mean; + }; + + struct struct14_T + { + real_T d; + real_T N; + real_T T; + boolean_T parallel; + real_T CPU; + real_T lambda; + real_T pUnitGamma; + real_T nCR; + real_T delta; + real_T steps; + real_T zeta; + char_T outlier[3]; + boolean_T adaptPCR; + real_T thinning; + real_T epsilon; + boolean_T ABC; + boolean_T IO; + boolean_T modout; + boolean_T restart; + boolean_T save; + ::coder::array R; + }; + + struct struct13_T + { + ::coder::bounded_array outlier; + real_T RunTime; + struct14_T DREAMPar; + struct15_T Meas_info; + real_T iteration; + real_T iloc; + real_T fx; + ::coder::bounded_array AR; + ::coder::array R_stat; + ::coder::array CR; + }; + + struct struct16_T + { + real_T LogZ; + ::coder::array nestSamples; + ::coder::array postSamples; + }; + + struct struct12_T + { + ::coder::array allChains; + struct13_T dreamOutput; + struct16_T nestOutput; + }; + + struct struct8_T + { + struct9_T bestFitsMean; + struct10_T predlims; + struct11_T parConfInts; + ::coder::array bestPars; + struct12_T bayesRes; + ::coder::array chain; + }; + + struct cell_wrap_11 + { + ::coder::array f1; + }; + + struct cell_wrap_20 + { + ::coder::array f1; + }; + + struct cell_wrap_21 + { + ::coder::array f1; + }; + + struct cell_wrap_24 + { + ::coder::array f1; + }; + + struct cell_wrap_50 + { + ::coder::array f1; + }; + + struct SLDFunction + { + int32_T belowVals_data[10000]; + }; + + struct normalizeFunction + { + real_T tmp_data[6000]; + }; + + struct resampleLayersReIm + { + real_T sldProfileIm_data[6000]; + real_T b_sldProfileIm_data[6000]; + }; + + struct parallelContrasts + { + real_T thisContrastLayers2_data[6000]; + real_T thisContrastLayers1_data[6000]; + }; + + struct b_parallelContrasts + { + real_T thisContrastLayers_data[6000]; + }; + + struct RATMainTLS + { + SLDFunction f0; + normalizeFunction f1; + resampleLayersReIm f2; + parallelContrasts f3; + b_parallelContrasts f4; + }; +} + +#endif + +// End of code generation (RATMain_types.h) diff --git a/RAT/SLDFunction.cpp b/RAT/SLDFunction.cpp index 8ea4073a..47dd6ae8 100644 --- a/RAT/SLDFunction.cpp +++ b/RAT/SLDFunction.cpp @@ -10,6 +10,8 @@ // Include files #include "SLDFunction.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" #include "find.h" #include "rt_nonfinite.h" #include "coder_array.h" @@ -18,19 +20,20 @@ // Function Definitions namespace RAT { - void SLDFunction(real_T x, const real_T SLD_data[], const int32_T SLD_size[2], - real_T sldVal_data[], int32_T *sldVal_size) + void b_SLDFunction(real_T x, const ::coder::array &SLD, real_T + sldVal_data[], int32_T *sldVal_size) { ::coder::array b_i; ::coder::array c_i; ::coder::array r; + ::coder::array b_SLD_data; ::coder::array c_SLD_data; ::coder::array d_SLD_data; ::coder::array e_SLD_data; ::coder::array f_SLD_data; - ::coder::array g_SLD_data; + int32_T SLD_size; int32_T loop_ub; - boolean_T b_SLD_data[1000]; + boolean_T SLD_data[6000]; // sldVal = SLDFunction(x,SLD) // SLD = [x rho;....xn rho] @@ -48,13 +51,14 @@ namespace RAT // // SLD = sldProfile; // SLD = getappdata(0,'SLDFunctionSLD'); - loop_ub = SLD_size[0]; + SLD_size = SLD.size(0); + loop_ub = SLD.size(0); for (int32_T i{0}; i < loop_ub; i++) { - b_SLD_data[i] = (SLD_data[i] == x); + SLD_data[i] = (SLD[i] == x); } - c_SLD_data.set(&b_SLD_data[0], SLD_size[0]); - coder::eml_find(c_SLD_data, r); + b_SLD_data.set(&SLD_data[0], SLD_size); + coder::eml_find(b_SLD_data, r); b_i.set_size(r.size(0)); loop_ub = r.size(0); for (int32_T i{0}; i < loop_ub; i++) { @@ -65,79 +69,80 @@ namespace RAT *sldVal_size = b_i.size(0); loop_ub = b_i.size(0); for (int32_T i{0}; i < loop_ub; i++) { - sldVal_data[i] = SLD_data[(b_i[i] + SLD_size[0]) - 1]; + sldVal_data[i] = SLD[(b_i[i] + SLD.size(0)) - 1]; } } else { real_T deltaY; - int32_T belowVals_data[1000]; + int32_T belowVals_data[6000]; int32_T belowVals_size; - loop_ub = SLD_size[0]; + SLD_size = SLD.size(0); + loop_ub = SLD.size(0); for (int32_T i{0}; i < loop_ub; i++) { - b_SLD_data[i] = (x > SLD_data[i]); + SLD_data[i] = (x > SLD[i]); } - d_SLD_data.set(&b_SLD_data[0], SLD_size[0]); - coder::eml_find(d_SLD_data, r); + c_SLD_data.set(&SLD_data[0], SLD_size); + coder::eml_find(c_SLD_data, r); b_i.set_size(r.size(0)); loop_ub = r.size(0); for (int32_T i{0}; i < loop_ub; i++) { b_i[i] = r[i]; } - loop_ub = SLD_size[0]; + SLD_size = SLD.size(0); + loop_ub = SLD.size(0); for (int32_T i{0}; i < loop_ub; i++) { - b_SLD_data[i] = (x > SLD_data[i]); + SLD_data[i] = (x > SLD[i]); } - e_SLD_data.set(&b_SLD_data[0], SLD_size[0]); - coder::eml_find(e_SLD_data, r); + d_SLD_data.set(&SLD_data[0], SLD_size); + coder::eml_find(d_SLD_data, r); belowVals_size = r.size(0); loop_ub = r.size(0); for (int32_T i{0}; i < loop_ub; i++) { belowVals_data[i] = r[i]; } - loop_ub = SLD_size[0]; + SLD_size = SLD.size(0); + loop_ub = SLD.size(0); for (int32_T i{0}; i < loop_ub; i++) { - b_SLD_data[i] = (x < SLD_data[i]); + SLD_data[i] = (x < SLD[i]); } - f_SLD_data.set(&b_SLD_data[0], SLD_size[0]); - coder::eml_find(f_SLD_data, r); + e_SLD_data.set(&SLD_data[0], SLD_size); + coder::eml_find(e_SLD_data, r); c_i.set_size(r.size(0)); loop_ub = r.size(0); for (int32_T i{0}; i < loop_ub; i++) { c_i[i] = r[i]; } - loop_ub = SLD_size[0]; + SLD_size = SLD.size(0); + loop_ub = SLD.size(0); for (int32_T i{0}; i < loop_ub; i++) { - b_SLD_data[i] = (x < SLD_data[i]); + SLD_data[i] = (x < SLD[i]); } - g_SLD_data.set(&b_SLD_data[0], SLD_size[0]); - coder::eml_find(g_SLD_data, r); - belowVals_size = belowVals_data[belowVals_size - 1]; - deltaY = (x - SLD_data[b_i[b_i.size(0) - 1] - 1]) * (std::abs(SLD_data[(r - [0] + SLD_size[0]) - 1] - SLD_data[(belowVals_size + SLD_size[0]) - 1]) / - (SLD_data[r[0] - 1] - SLD_data[belowVals_size - 1])); - if (SLD_data[(b_i[b_i.size(0) - 1] + SLD_size[0]) - 1] < SLD_data[(c_i[0] - + SLD_size[0]) - 1]) { + f_SLD_data.set(&SLD_data[0], SLD_size); + coder::eml_find(f_SLD_data, r); + deltaY = (x - SLD[b_i[b_i.size(0) - 1] - 1]) * (std::abs(SLD[(r[0] + + SLD.size(0)) - 1] - SLD[(belowVals_data[belowVals_size - 1] + SLD.size(0)) + - 1]) / (SLD[r[0] - 1] - SLD[belowVals_data[belowVals_size - 1] - 1])); + if (SLD[(b_i[b_i.size(0) - 1] + SLD.size(0)) - 1] < SLD[(c_i[0] + SLD.size + (0)) - 1]) { *sldVal_size = 1; - sldVal_data[0] = SLD_data[(b_i[b_i.size(0) - 1] + SLD_size[0]) - 1] + - deltaY; + sldVal_data[0] = SLD[(b_i[b_i.size(0) - 1] + SLD.size(0)) - 1] + deltaY; } else { *sldVal_size = 1; - sldVal_data[0] = SLD_data[(b_i[b_i.size(0) - 1] + SLD_size[0]) - 1] - - deltaY; + sldVal_data[0] = SLD[(b_i[b_i.size(0) - 1] + SLD.size(0)) - 1] - deltaY; } // sldVal = interp1(z,rho,x); } } - void SLDFunction(real_T x, const ::coder::array &SLD, ::coder:: - array &sldVal) + void b_SLDFunction(real_T x, const ::coder::array &SLD, ::coder:: + array &sldVal) { ::coder::array b_i; ::coder::array c_i; @@ -147,9 +152,11 @@ namespace RAT ::coder::array d_SLD_data; ::coder::array e_SLD_data; ::coder::array f_SLD_data; + RATMainTLS *RATMainTLSThread; int32_T SLD_size; int32_T loop_ub; boolean_T SLD_data[10000]; + RATMainTLSThread = emlrtGetThreadStackData(); // sldVal = SLDFunction(x,SLD) // SLD = [x rho;....xn rho] @@ -189,7 +196,6 @@ namespace RAT } } else { real_T deltaY; - int32_T belowVals_data[10000]; int32_T belowVals_size; SLD_size = SLD.size(0); loop_ub = SLD.size(0); @@ -216,7 +222,7 @@ namespace RAT belowVals_size = r.size(0); loop_ub = r.size(0); for (int32_T i{0}; i < loop_ub; i++) { - belowVals_data[i] = r[i]; + RATMainTLSThread->f0.belowVals_data[i] = r[i]; } SLD_size = SLD.size(0); @@ -242,8 +248,9 @@ namespace RAT f_SLD_data.set(&SLD_data[0], SLD_size); coder::eml_find(f_SLD_data, r); deltaY = (x - SLD[b_i[b_i.size(0) - 1] - 1]) * (std::abs(SLD[(r[0] + - SLD.size(0)) - 1] - SLD[(belowVals_data[belowVals_size - 1] + SLD.size(0)) - - 1]) / (SLD[r[0] - 1] - SLD[belowVals_data[belowVals_size - 1] - 1])); + SLD.size(0)) - 1] - SLD[(RATMainTLSThread-> + f0.belowVals_data[belowVals_size - 1] + SLD.size(0)) - 1]) / (SLD[r[0] - + 1] - SLD[RATMainTLSThread->f0.belowVals_data[belowVals_size - 1] - 1])); if (SLD[(b_i[b_i.size(0) - 1] + SLD.size(0)) - 1] < SLD[(c_i[0] + SLD.size (0)) - 1]) { sldVal.set_size(1); diff --git a/RAT/SLDFunction.h b/RAT/SLDFunction.h index 4e9625fd..84254dcf 100644 --- a/RAT/SLDFunction.h +++ b/RAT/SLDFunction.h @@ -19,10 +19,10 @@ // Function Declarations namespace RAT { - void SLDFunction(real_T x, const real_T SLD_data[], const int32_T SLD_size[2], - real_T sldVal_data[], int32_T *sldVal_size); - void SLDFunction(real_T x, const ::coder::array &SLD, ::coder:: - array &sldVal); + void b_SLDFunction(real_T x, const ::coder::array &SLD, real_T + sldVal_data[], int32_T *sldVal_size); + void b_SLDFunction(real_T x, const ::coder::array &SLD, ::coder:: + array &sldVal); } #endif diff --git a/RAT/abelesParallelPoints.cpp b/RAT/abelesParallelPoints.cpp index cc2a77e7..b5b9035d 100644 --- a/RAT/abelesParallelPoints.cpp +++ b/RAT/abelesParallelPoints.cpp @@ -10,9 +10,9 @@ // Include files #include "abelesParallelPoints.h" +#include "RATMain_data.h" +#include "RATMain_rtwutil.h" #include "exp.h" -#include "reflectivityCalculation_data.h" -#include "reflectivityCalculation_rtwutil.h" #include "rt_nonfinite.h" #include "sqrt.h" #include "coder_array.h" @@ -30,10 +30,43 @@ namespace RAT { static creal_T findkn(real_T k0, const creal_T sld) { + creal_T dc; + creal_T dc1; creal_T kn; - kn.re = k0 * k0 - 12.566370614359172 * sld.re; - kn.im = 0.0 - 12.566370614359172 * sld.im; - coder::internal::scalar::b_sqrt(&kn); + real_T k0_im; + real_T k0_re; + real_T re; + + // sqrt function with branch cut in zarg from 0 to infinity along a ray + // at angle theta (in radians) measured from the +x axis in the usual way, + // with -pi<=theta<=pi. theta = pi is the usual square root. + // for zarg on the +x axis, sqrt behavior is conserved, + // i.e. sqrtbc(theta,zarg) is positive and real for any theta. + // + // y = sqrtbc(theta,zarg) + dc.re = 0.0; + dc.im = -0.78539816339744828; + coder::b_exp(&dc); + dc1.re = 0.0; + dc1.im = 1.5707963267948966; + coder::b_exp(&dc1); + k0_re = k0 * k0 - 12.566370614359172 * sld.re; + k0_im = 0.0 - 12.566370614359172 * sld.im; + re = k0_re * dc1.re - k0_im * dc1.im; + k0_re = k0_re * dc1.im + k0_im * dc1.re; + dc1.re = re; + dc1.im = k0_re; + coder::internal::scalar::d_sqrt(&dc1); + kn.re = dc.re * dc1.re - dc.im * dc1.im; + kn.im = dc.re * dc1.im + dc.im * dc1.re; + + // translations: sqrtbc(theta, z-b) has branch cut in the z plane from + // branch point z = b out to infinity, along a ray at angle theta. + // + // for the usual square root with branch cut along -x, + // the real part of sqrt(z) is positive (or 0) for all z. + // for the modified square root with branch cut along +x, + // the imaginary part of sqrt(z) is positive (or 0) for all z. return kn; } diff --git a/RAT/abelesSingle.cpp b/RAT/abelesSingle.cpp index ce69f4bc..043a3f53 100644 --- a/RAT/abelesSingle.cpp +++ b/RAT/abelesSingle.cpp @@ -10,9 +10,9 @@ // Include files #include "abelesSingle.h" +#include "RATMain_data.h" +#include "RATMain_rtwutil.h" #include "exp.h" -#include "reflectivityCalculation_data.h" -#include "reflectivityCalculation_rtwutil.h" #include "rt_nonfinite.h" #include "sqrt.h" #include "coder_array.h" @@ -30,8 +30,7 @@ namespace RAT creal_T M_res[2][2]; creal_T M_tot[2][2]; creal_T M_n_tmp; - creal_T k1; - creal_T knp1; + creal_T dc; real_T kn_ptr_im; real_T kn_ptr_re; int32_T i; @@ -62,12 +61,12 @@ namespace RAT i = q.size(0); for (int32_T points{0}; points < i; points++) { - real_T M_n_tmp_tmp; real_T brm; real_T bulk_in_SLD_im; real_T bulk_in_SLD_re; real_T k0; - real_T re; + real_T k0_im; + real_T sgnbr; bulk_in_SLD_re = layers_rho[0].re; bulk_in_SLD_im = layers_rho[0].im + 1.0E-30; k0 = q[points] / 2.0; @@ -75,70 +74,101 @@ namespace RAT for (int32_T n{0}; n < loop_ub; n++) { if (static_cast(n) + 1U == 1U) { real_T ar; - real_T im; + real_T br; + real_T d; + real_T k0_re; + real_T k1_im; + real_T k1_re; real_T r01_im; real_T r01_re; + real_T re; // Find k1.. - k1.re = k0 * k0 - 12.566370614359172 * (layers_rho[1].re - + // sqrt function with branch cut in zarg from 0 to infinity along a ray + // at angle theta (in radians) measured from the +x axis in the usual way, + // with -pi<=theta<=pi. theta = pi is the usual square root. + // for zarg on the +x axis, sqrt behavior is conserved, + // i.e. sqrtbc(theta,zarg) is positive and real for any theta. + // + // y = sqrtbc(theta,zarg) + dc.re = 0.0; + dc.im = -0.78539816339744828; + coder::b_exp(&dc); + M_n_tmp.re = 0.0; + M_n_tmp.im = 1.5707963267948966; + coder::b_exp(&M_n_tmp); + k0_re = k0 * k0 - 12.566370614359172 * (layers_rho[1].re - bulk_in_SLD_re); - k1.im = 0.0 - 12.566370614359172 * (layers_rho[1].im - bulk_in_SLD_im); - coder::internal::scalar::b_sqrt(&k1); + k0_im = 0.0 - 12.566370614359172 * (layers_rho[1].im - bulk_in_SLD_im); + re = k0_re * M_n_tmp.re - k0_im * M_n_tmp.im; + k0_im = k0_re * M_n_tmp.im + k0_im * M_n_tmp.re; + M_n_tmp.re = re; + M_n_tmp.im = k0_im; + coder::internal::scalar::d_sqrt(&M_n_tmp); + k1_re = dc.re * M_n_tmp.re - dc.im * M_n_tmp.im; + k1_im = dc.re * M_n_tmp.im + dc.im * M_n_tmp.re; + // translations: sqrtbc(theta, z-b) has branch cut in the z plane from + // branch point z = b out to infinity, along a ray at angle theta. + // + // for the usual square root with branch cut along -x, + // the real part of sqrt(z) is positive (or 0) for all z. + // for the modified square root with branch cut along +x, + // the imaginary part of sqrt(z) is positive (or 0) for all z. // Find r01 - M_n_tmp_tmp = layers_sig[1] * layers_sig[1]; - M_n_tmp.re = M_n_tmp_tmp * (k0 * (-2.0 * k1.re)); - M_n_tmp.im = M_n_tmp_tmp * (k0 * (-2.0 * k1.im)); - coder::b_exp(&M_n_tmp); - ar = k0 - k1.re; - im = k0 + k1.re; - if (k1.im == 0.0) { - im = ar / im; - re = 0.0; - } else if (im == 0.0) { + d = layers_sig[1] * layers_sig[1]; + dc.re = d * (k0 * (-2.0 * k1_re)); + dc.im = d * (k0 * (-2.0 * k1_im)); + coder::b_exp(&dc); + ar = k0 - k1_re; + br = k0 + k1_re; + if (k1_im == 0.0) { + k0_re = ar / br; + k0_im = 0.0; + } else if (br == 0.0) { if (ar == 0.0) { - im = (0.0 - k1.im) / k1.im; - re = 0.0; - } else if (0.0 - k1.im == 0.0) { - im = 0.0; - re = -(ar / k1.im); + k0_re = (0.0 - k1_im) / k1_im; + k0_im = 0.0; + } else if (0.0 - k1_im == 0.0) { + k0_re = 0.0; + k0_im = -(ar / k1_im); } else { - im = (0.0 - k1.im) / k1.im; - re = -(ar / k1.im); + k0_re = (0.0 - k1_im) / k1_im; + k0_im = -(ar / k1_im); } } else { - brm = std::abs(im); - re = std::abs(k1.im); - if (brm > re) { - M_n_tmp_tmp = k1.im / im; - re = im + M_n_tmp_tmp * k1.im; - im = (ar + M_n_tmp_tmp * (0.0 - k1.im)) / re; - re = ((0.0 - k1.im) - M_n_tmp_tmp * ar) / re; - } else if (re == brm) { - if (im > 0.0) { - M_n_tmp_tmp = 0.5; + brm = std::abs(br); + k0_im = std::abs(k1_im); + if (brm > k0_im) { + brm = k1_im / br; + k0_im = br + brm * k1_im; + k0_re = (ar + brm * (0.0 - k1_im)) / k0_im; + k0_im = ((0.0 - k1_im) - brm * ar) / k0_im; + } else if (k0_im == brm) { + if (br > 0.0) { + sgnbr = 0.5; } else { - M_n_tmp_tmp = -0.5; + sgnbr = -0.5; } - if (k1.im > 0.0) { - re = 0.5; + if (k1_im > 0.0) { + k0_im = 0.5; } else { - re = -0.5; + k0_im = -0.5; } - im = (ar * M_n_tmp_tmp + (0.0 - k1.im) * re) / brm; - re = ((0.0 - k1.im) * M_n_tmp_tmp - ar * re) / brm; + k0_re = (ar * sgnbr + (0.0 - k1_im) * k0_im) / brm; + k0_im = ((0.0 - k1_im) * sgnbr - ar * k0_im) / brm; } else { - M_n_tmp_tmp = im / k1.im; - re = k1.im + M_n_tmp_tmp * im; - im = (M_n_tmp_tmp * ar + (0.0 - k1.im)) / re; - re = (M_n_tmp_tmp * (0.0 - k1.im) - ar) / re; + brm = br / k1_im; + k0_im = k1_im + brm * br; + k0_re = (brm * ar + (0.0 - k1_im)) / k0_im; + k0_im = (brm * (0.0 - k1_im) - ar) / k0_im; } } - r01_re = im * M_n_tmp.re - re * M_n_tmp.im; - r01_im = im * M_n_tmp.im + re * M_n_tmp.re; + r01_re = k0_re * dc.re - k0_im * dc.im; + r01_im = k0_re * dc.im + k0_im * dc.re; // Generate the M1 matrix: M_tot[0][0].re = 1.0; @@ -149,95 +179,123 @@ namespace RAT M_tot[0][1].im = r01_im; M_tot[1][1].re = 1.0; M_tot[1][1].im = 0.0; - kn_ptr_re = k1.re; - kn_ptr_im = k1.im; + kn_ptr_re = k1_re; + kn_ptr_im = k1_im; } else { real_T ai; real_T ar; - real_T b_kn_ptr_re; real_T beta_im; real_T beta_re; - real_T bi; + real_T br; real_T d; real_T d1; - real_T im; + real_T k0_re; + real_T knp1_im; + real_T knp1_re; real_T r_n_np1_im; real_T r_n_np1_re; + real_T re; // Find kn and k_n+1 (ex. k1 and k2 for n=1): _/ - knp1.re = k0 * k0 - 12.566370614359172 * (layers_rho[n + 1].re - + // sqrt function with branch cut in zarg from 0 to infinity along a ray + // at angle theta (in radians) measured from the +x axis in the usual way, + // with -pi<=theta<=pi. theta = pi is the usual square root. + // for zarg on the +x axis, sqrt behavior is conserved, + // i.e. sqrtbc(theta,zarg) is positive and real for any theta. + // + // y = sqrtbc(theta,zarg) + dc.re = 0.0; + dc.im = -0.78539816339744828; + coder::b_exp(&dc); + M_n_tmp.re = 0.0; + M_n_tmp.im = 1.5707963267948966; + coder::b_exp(&M_n_tmp); + k0_re = k0 * k0 - 12.566370614359172 * (layers_rho[n + 1].re - bulk_in_SLD_re); - knp1.im = 0.0 - 12.566370614359172 * (layers_rho[n + 1].im - + k0_im = 0.0 - 12.566370614359172 * (layers_rho[n + 1].im - bulk_in_SLD_im); - coder::internal::scalar::b_sqrt(&knp1); + re = k0_re * M_n_tmp.re - k0_im * M_n_tmp.im; + k0_im = k0_re * M_n_tmp.im + k0_im * M_n_tmp.re; + M_n_tmp.re = re; + M_n_tmp.im = k0_im; + coder::internal::scalar::d_sqrt(&M_n_tmp); + knp1_re = dc.re * M_n_tmp.re - dc.im * M_n_tmp.im; + knp1_im = dc.re * M_n_tmp.im + dc.im * M_n_tmp.re; + // translations: sqrtbc(theta, z-b) has branch cut in the z plane from + // branch point z = b out to infinity, along a ray at angle theta. + // + // for the usual square root with branch cut along -x, + // the real part of sqrt(z) is positive (or 0) for all z. + // for the modified square root with branch cut along +x, + // the imaginary part of sqrt(z) is positive (or 0) for all z. // Find r_n,n+1: re = -2.0 * kn_ptr_re; - im = -2.0 * kn_ptr_im; - M_n_tmp_tmp = layers_sig[n + 1]; - M_n_tmp_tmp *= M_n_tmp_tmp; - M_n_tmp.re = M_n_tmp_tmp * (re * knp1.re - im * knp1.im); - M_n_tmp.im = M_n_tmp_tmp * (re * knp1.im + im * knp1.re); - coder::b_exp(&M_n_tmp); - ar = kn_ptr_re - knp1.re; - ai = kn_ptr_im - knp1.im; - im = kn_ptr_re + knp1.re; - bi = kn_ptr_im + knp1.im; - if (bi == 0.0) { + k0_im = -2.0 * kn_ptr_im; + d = layers_sig[n + 1]; + d *= d; + dc.re = d * (re * knp1_re - k0_im * knp1_im); + dc.im = d * (re * knp1_im + k0_im * knp1_re); + coder::b_exp(&dc); + ar = kn_ptr_re - knp1_re; + ai = kn_ptr_im - knp1_im; + br = kn_ptr_re + knp1_re; + re = kn_ptr_im + knp1_im; + if (re == 0.0) { if (ai == 0.0) { - b_kn_ptr_re = ar / im; - re = 0.0; + k0_re = ar / br; + k0_im = 0.0; } else if (ar == 0.0) { - b_kn_ptr_re = 0.0; - re = ai / im; + k0_re = 0.0; + k0_im = ai / br; } else { - b_kn_ptr_re = ar / im; - re = ai / im; + k0_re = ar / br; + k0_im = ai / br; } - } else if (im == 0.0) { + } else if (br == 0.0) { if (ar == 0.0) { - b_kn_ptr_re = ai / bi; - re = 0.0; + k0_re = ai / re; + k0_im = 0.0; } else if (ai == 0.0) { - b_kn_ptr_re = 0.0; - re = -(ar / bi); + k0_re = 0.0; + k0_im = -(ar / re); } else { - b_kn_ptr_re = ai / bi; - re = -(ar / bi); + k0_re = ai / re; + k0_im = -(ar / re); } } else { - brm = std::abs(im); - re = std::abs(bi); - if (brm > re) { - M_n_tmp_tmp = bi / im; - re = im + M_n_tmp_tmp * bi; - b_kn_ptr_re = (ar + M_n_tmp_tmp * ai) / re; - re = (ai - M_n_tmp_tmp * ar) / re; - } else if (re == brm) { - if (im > 0.0) { - M_n_tmp_tmp = 0.5; + brm = std::abs(br); + k0_im = std::abs(re); + if (brm > k0_im) { + brm = re / br; + k0_im = br + brm * re; + k0_re = (ar + brm * ai) / k0_im; + k0_im = (ai - brm * ar) / k0_im; + } else if (k0_im == brm) { + if (br > 0.0) { + sgnbr = 0.5; } else { - M_n_tmp_tmp = -0.5; + sgnbr = -0.5; } - if (bi > 0.0) { - re = 0.5; + if (re > 0.0) { + k0_im = 0.5; } else { - re = -0.5; + k0_im = -0.5; } - b_kn_ptr_re = (ar * M_n_tmp_tmp + ai * re) / brm; - re = (ai * M_n_tmp_tmp - ar * re) / brm; + k0_re = (ar * sgnbr + ai * k0_im) / brm; + k0_im = (ai * sgnbr - ar * k0_im) / brm; } else { - M_n_tmp_tmp = im / bi; - re = bi + M_n_tmp_tmp * im; - b_kn_ptr_re = (M_n_tmp_tmp * ar + ai) / re; - re = (M_n_tmp_tmp * ai - ar) / re; + brm = br / re; + k0_im = re + brm * br; + k0_re = (brm * ar + ai) / k0_im; + k0_im = (brm * ai - ar) / k0_im; } } - r_n_np1_re = b_kn_ptr_re * M_n_tmp.re - re * M_n_tmp.im; - r_n_np1_im = b_kn_ptr_re * M_n_tmp.im + re * M_n_tmp.re; + r_n_np1_re = k0_re * dc.re - k0_im * dc.im; + r_n_np1_im = k0_re * dc.im + k0_im * dc.re; // Find the Phase Factor = (k_n * d_n) kn_ptr_re *= layers_thick[n]; @@ -257,23 +315,23 @@ namespace RAT coder::b_exp(&M_n_tmp); // Multiply the matrices - ar = M_n[0][0].re; - d = M_n[0][0].im; + d = M_n[0][0].re; + ar = M_n[0][0].im; d1 = r_n_np1_re * M_n_tmp.re - r_n_np1_im * M_n_tmp.im; - re = r_n_np1_re * M_n_tmp.im + r_n_np1_im * M_n_tmp.re; - im = M_n[1][0].re; - M_n_tmp_tmp = M_n[1][0].im; + k0_im = r_n_np1_re * M_n_tmp.im + r_n_np1_im * M_n_tmp.re; + re = M_n[1][0].re; + k0_re = M_n[1][0].im; for (int32_T i1{0}; i1 < 2; i1++) { - bi = M_tot[0][i1].re; + br = M_tot[0][i1].re; brm = M_tot[0][i1].im; - ai = M_tot[1][i1].re; - b_kn_ptr_re = M_tot[1][i1].im; - M_res[0][i1].re = (bi * ar - brm * d) + (ai * d1 - b_kn_ptr_re * re); - M_res[0][i1].im = (bi * d + brm * ar) + (ai * re + b_kn_ptr_re * d1); - M_res[1][i1].re = (bi * im - brm * M_n_tmp_tmp) + (ai * M_n_tmp.re - - b_kn_ptr_re * M_n_tmp.im); - M_res[1][i1].im = (bi * M_n_tmp_tmp + brm * im) + (ai * M_n_tmp.im + - b_kn_ptr_re * M_n_tmp.re); + sgnbr = M_tot[1][i1].re; + ai = M_tot[1][i1].im; + M_res[0][i1].re = (br * d - brm * ar) + (sgnbr * d1 - ai * k0_im); + M_res[0][i1].im = (br * ar + brm * d) + (sgnbr * k0_im + ai * d1); + M_res[1][i1].re = (br * re - brm * k0_re) + (sgnbr * M_n_tmp.re - ai + * M_n_tmp.im); + M_res[1][i1].im = (br * k0_re + brm * re) + (sgnbr * M_n_tmp.im + ai + * M_n_tmp.re); } // Reassign the values back to M_tot: @@ -283,8 +341,8 @@ namespace RAT M_tot[1][1] = M_res[1][1]; // Point to k_n+1 and sld_n+1 via kn_ptr sld_n_ptr: - kn_ptr_re = knp1.re; - kn_ptr_im = knp1.im; + kn_ptr_re = knp1_re; + kn_ptr_im = knp1_im; } } @@ -312,39 +370,37 @@ namespace RAT } } else { brm = std::abs(M_res[0][0].re); - re = std::abs(M_res[0][0].im); - if (brm > re) { - M_n_tmp_tmp = M_res[0][0].im / M_res[0][0].re; - re = M_res[0][0].re + M_n_tmp_tmp * M_res[0][0].im; - M_n_tmp.re = (M_res[0][1].re + M_n_tmp_tmp * M_res[0][1].im) / re; - M_n_tmp.im = (M_res[0][1].im - M_n_tmp_tmp * M_res[0][1].re) / re; - } else if (re == brm) { + k0_im = std::abs(M_res[0][0].im); + if (brm > k0_im) { + brm = M_res[0][0].im / M_res[0][0].re; + k0_im = M_res[0][0].re + brm * M_res[0][0].im; + M_n_tmp.re = (M_res[0][1].re + brm * M_res[0][1].im) / k0_im; + M_n_tmp.im = (M_res[0][1].im - brm * M_res[0][1].re) / k0_im; + } else if (k0_im == brm) { if (M_res[0][0].re > 0.0) { - M_n_tmp_tmp = 0.5; + sgnbr = 0.5; } else { - M_n_tmp_tmp = -0.5; + sgnbr = -0.5; } if (M_res[0][0].im > 0.0) { - re = 0.5; + k0_im = 0.5; } else { - re = -0.5; + k0_im = -0.5; } - M_n_tmp.re = (M_res[0][1].re * M_n_tmp_tmp + M_res[0][1].im * re) / - brm; - M_n_tmp.im = (M_res[0][1].im * M_n_tmp_tmp - M_res[0][1].re * re) / - brm; + M_n_tmp.re = (M_res[0][1].re * sgnbr + M_res[0][1].im * k0_im) / brm; + M_n_tmp.im = (M_res[0][1].im * sgnbr - M_res[0][1].re * k0_im) / brm; } else { - M_n_tmp_tmp = M_res[0][0].re / M_res[0][0].im; - re = M_res[0][0].im + M_n_tmp_tmp * M_res[0][0].re; - M_n_tmp.re = (M_n_tmp_tmp * M_res[0][1].re + M_res[0][1].im) / re; - M_n_tmp.im = (M_n_tmp_tmp * M_res[0][1].im - M_res[0][1].re) / re; + brm = M_res[0][0].re / M_res[0][0].im; + k0_im = M_res[0][0].im + brm * M_res[0][0].re; + M_n_tmp.re = (brm * M_res[0][1].re + M_res[0][1].im) / k0_im; + M_n_tmp.im = (brm * M_res[0][1].im - M_res[0][1].re) / k0_im; } } - re = rt_hypotd_snf(M_n_tmp.re, M_n_tmp.im); - ref[points] = re * re; + k0_im = rt_hypotd_snf(M_n_tmp.re, M_n_tmp.im); + ref[points] = k0_im * k0_im; } } } diff --git a/RAT/abs.cpp b/RAT/abs.cpp new file mode 100644 index 00000000..8bb6e574 --- /dev/null +++ b/RAT/abs.cpp @@ -0,0 +1,67 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// abs.cpp +// +// Code generation for function 'abs' +// + +// Include files +#include "abs.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_abs(const ::coder::array &x, ::coder::array + &y) + { + y.set_size(1, x.size(1)); + if (x.size(1) != 0) { + int32_T i; + i = x.size(1); + for (int32_T k{0}; k < i; k++) { + y[k] = std::abs(x[k]); + } + } + } + + void b_abs(const ::coder::array &x, ::coder::array + &y) + { + y.set_size(x.size(0)); + if (x.size(0) != 0) { + int32_T i; + i = x.size(0); + for (int32_T k{0}; k < i; k++) { + y[k] = std::abs(x[k]); + } + } + } + + void c_abs(const ::coder::array &x, ::coder::array + &y) + { + y.set_size(x.size(0), x.size(1)); + if ((x.size(0) != 0) && (x.size(1) != 0)) { + int32_T i; + i = x.size(1); + for (int32_T k{0}; k < i; k++) { + int32_T i1; + i1 = y.size(0); + for (int32_T b_k{0}; b_k < i1; b_k++) { + y[b_k + y.size(0) * k] = std::abs(x[b_k + x.size(0) * k]); + } + } + } + } + } +} + +// End of code generation (abs.cpp) diff --git a/RAT/abs.h b/RAT/abs.h new file mode 100644 index 00000000..1edafb19 --- /dev/null +++ b/RAT/abs.h @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// abs.h +// +// Code generation for function 'abs' +// +#ifndef ABS_H +#define ABS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_abs(const ::coder::array &x, ::coder::array + &y); + void b_abs(const ::coder::array &x, ::coder::array + &y); + void c_abs(const ::coder::array &x, ::coder::array + &y); + } +} + +#endif + +// End of code generation (abs.h) diff --git a/RAT/acos.cpp b/RAT/acos.cpp index 92d14680..ff480ee9 100644 --- a/RAT/acos.cpp +++ b/RAT/acos.cpp @@ -79,10 +79,10 @@ namespace RAT } else { v.re = x->re + 1.0; v.im = x->im; - b_sqrt(&v); + d_sqrt(&v); u.re = 1.0 - x->re; u.im = 0.0 - x->im; - b_sqrt(&u); + d_sqrt(&u); d = complexTimes(v.re, -v.im, u.re, u.im); b_asinh(&d); x->re = 2.0 * rt_atan2d_snf(u.re, v.re); diff --git a/RAT/adaptPCR.cpp b/RAT/adaptPCR.cpp new file mode 100644 index 00000000..4483c9c2 --- /dev/null +++ b/RAT/adaptPCR.cpp @@ -0,0 +1,68 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// adaptPCR.cpp +// +// Code generation for function 'adaptPCR' +// + +// Include files +#include "adaptPCR.h" +#include "RATMain_types.h" +#include "find.h" +#include "rt_nonfinite.h" +#include "sum.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void adaptPCR(const struct14_T *DREAMPar, const ::coder::array &CR, + const real_T delta_tot_data[], const real_T lCRold_data[], + real_T pCR_data[], int32_T pCR_size[2], real_T lCR_data[], + int32_T lCR_size[2]) + { + ::coder::array y; + ::coder::array r; + ::coder::array c_CR; + real_T b_zz; + int32_T b_CR; + + // Updates the probabilities of the various crossover values + // Make CR to be a single vector + // Determine lCR + lCR_size[0] = 1; + lCR_size[1] = 3; + + // Adapt pCR using information from averaged normalized jumping distance + y.set_size(1, 3); + b_CR = CR.size(0) * CR.size(1); + for (int32_T zz{0}; zz < 3; zz++) { + // Determine how many times a particular CR value is used + // This is used to weight delta_tot + b_zz = (static_cast(zz) + 1.0) / 3.0; + c_CR.set_size(b_CR); + for (int32_T i{0}; i < b_CR; i++) { + c_CR[i] = (CR[i] == b_zz); + } + + coder::eml_find(c_CR, r); + b_zz = lCRold_data[zz] + static_cast(r.size(0)); + lCR_data[zz] = b_zz; + y[zz] = DREAMPar->N * (delta_tot_data[zz] / b_zz); + } + + // / sum(delta_tot); + // Normalize pCR so that selection probabilities add up to 1 + b_zz = coder::sum(y); + pCR_size[0] = 1; + pCR_size[1] = 3; + for (int32_T i{0}; i < 3; i++) { + pCR_data[i] = y[i] / b_zz; + } + } +} + +// End of code generation (adaptPCR.cpp) diff --git a/RAT/adaptPCR.h b/RAT/adaptPCR.h new file mode 100644 index 00000000..8f4b4a92 --- /dev/null +++ b/RAT/adaptPCR.h @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// adaptPCR.h +// +// Code generation for function 'adaptPCR' +// +#ifndef ADAPTPCR_H +#define ADAPTPCR_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct14_T; +} + +// Function Declarations +namespace RAT +{ + void adaptPCR(const struct14_T *DREAMPar, const ::coder::array &CR, + const real_T delta_tot_data[], const real_T lCRold_data[], + real_T pCR_data[], int32_T pCR_size[2], real_T lCR_data[], + int32_T lCR_size[2]); +} + +#endif + +// End of code generation (adaptPCR.h) diff --git a/RAT/adaptive.cpp b/RAT/adaptive.cpp index 7e611163..3f1057c0 100644 --- a/RAT/adaptive.cpp +++ b/RAT/adaptive.cpp @@ -10,13 +10,15 @@ // Include files #include "adaptive.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" #include "SLDFunction.h" #include "acos.h" #include "allOrAny.h" #include "eml_mtimes_helper.h" #include "linspace.h" #include "minOrMax.h" -#include "reflectivityCalculation_internal_types.h" #include "repmat.h" #include "rt_nonfinite.h" #include "sortrows.h" @@ -27,10 +29,12 @@ namespace RAT { static void b_binary_expand_op(::coder::array &in1, const - cell_24 *in2, const ::coder::array &in3, real_T in4); + cell_27 *in2, const ::coder::array &in3, real_T in4); static void b_increaseSampling(::coder::array &dataPoints, const :: - coder::array &segmentsToSplit, const real_T sldProfile_data[], - const int32_T sldProfile_size[2]); + coder::array &segmentsToSplit, const ::coder::array &sldProfile); + static void b_normalizeFunction(const ::coder::array &x, const :: + coder::array &sldProfile, ::coder::array &y); static void binary_expand_op(const ::coder::array &in1, const :: coder::array &in2, const ::coder::array &in3, :: coder::array &in4, ::coder::array &in5, ::coder:: @@ -43,6 +47,8 @@ namespace RAT array &in2, const ::coder::array &in3, const ::coder:: array &in4, const ::coder::array &in5, const ::coder:: array &in6); + static void c_normalizeFunction(const ::coder::array &x, const :: + coder::array &sldProfile, ::coder::array &y); static void calculateCentralAngles(const ::coder::array &XYdata, const real_T dataBoxSize[2], ::coder::array &cornerAngle); static void calculateTrianglesSides(const ::coder::array &XYdata, :: @@ -51,11 +57,6 @@ namespace RAT static void increaseSampling(::coder::array &dataPoints, const :: coder::array &segmentsToSplit, const ::coder::array &sldProfile); - static void normalizeFunction(const ::coder::array &x, const - real_T sldProfile_data[], const int32_T sldProfile_size[2], ::coder::array< - real_T, 1U> &y); - static void normalizeFunction(const ::coder::array &x, const :: - coder::array &sldProfile, ::coder::array &y); static void times(::coder::array &in1, const ::coder::array &in2, const ::coder::array &in3); } @@ -64,7 +65,7 @@ namespace RAT namespace RAT { static void b_binary_expand_op(::coder::array &in1, const - cell_24 *in2, const ::coder::array &in3, real_T in4) + cell_27 *in2, const ::coder::array &in3, real_T in4) { int32_T i; int32_T in2_idx_0; @@ -88,8 +89,8 @@ namespace RAT } static void b_increaseSampling(::coder::array &dataPoints, const :: - coder::array &segmentsToSplit, const real_T sldProfile_data[], - const int32_T sldProfile_size[2]) + coder::array &segmentsToSplit, const ::coder::array &sldProfile) { ::coder::array b_dataPoints; ::coder::array newDataPoints; @@ -99,76 +100,77 @@ namespace RAT ::coder::array r3; ::coder::array r; ::coder::array r1; - int32_T end; + int32_T b_i; int32_T input_sizes_idx_0; + int32_T trueCount; // increaseSampling increase the sampling of an input function - end = segmentsToSplit.size(0); - input_sizes_idx_0 = 0; - for (int32_T i{0}; i < end; i++) { + input_sizes_idx_0 = segmentsToSplit.size(0); + trueCount = 0; + for (int32_T i{0}; i < input_sizes_idx_0; i++) { if (segmentsToSplit[i]) { - input_sizes_idx_0++; + trueCount++; } } - newDataPoints.set_size(input_sizes_idx_0, 2); + newDataPoints.set_size(trueCount, 2); for (int32_T i{0}; i < 2; i++) { - for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { + for (b_i = 0; b_i < trueCount; b_i++) { newDataPoints[b_i + newDataPoints.size(0) * i] = 0.0; } } r.set_size(segmentsToSplit.size(0) + 1); - input_sizes_idx_0 = segmentsToSplit.size(0); - for (int32_T i{0}; i < input_sizes_idx_0; i++) { + trueCount = segmentsToSplit.size(0); + for (int32_T i{0}; i < trueCount; i++) { r[i] = segmentsToSplit[i]; } r[segmentsToSplit.size(0)] = false; r1.set_size(segmentsToSplit.size(0) + 1); r1[0] = false; - input_sizes_idx_0 = segmentsToSplit.size(0); - for (int32_T i{0}; i < input_sizes_idx_0; i++) { + trueCount = segmentsToSplit.size(0); + for (int32_T i{0}; i < trueCount; i++) { r1[i + 1] = segmentsToSplit[i]; } - end = r.size(0) - 1; - input_sizes_idx_0 = 0; - for (int32_T i{0}; i <= end; i++) { + input_sizes_idx_0 = r.size(0) - 1; + trueCount = 0; + for (int32_T i{0}; i <= input_sizes_idx_0; i++) { if (r[i]) { - input_sizes_idx_0++; + trueCount++; } } - r2.set_size(input_sizes_idx_0); - input_sizes_idx_0 = 0; - for (int32_T i{0}; i <= end; i++) { + r2.set_size(trueCount); + trueCount = 0; + for (int32_T i{0}; i <= input_sizes_idx_0; i++) { if (r[i]) { - r2[input_sizes_idx_0] = i + 1; - input_sizes_idx_0++; + r2[trueCount] = i + 1; + trueCount++; } } - end = r1.size(0) - 1; - input_sizes_idx_0 = 0; - for (int32_T i{0}; i <= end; i++) { + input_sizes_idx_0 = r1.size(0) - 1; + trueCount = 0; + for (int32_T i{0}; i <= input_sizes_idx_0; i++) { if (r1[i]) { - input_sizes_idx_0++; + trueCount++; } } - r3.set_size(input_sizes_idx_0); - input_sizes_idx_0 = 0; - for (int32_T i{0}; i <= end; i++) { + r3.set_size(trueCount); + trueCount = 0; + for (int32_T i{0}; i <= input_sizes_idx_0; i++) { if (r1[i]) { - r3[input_sizes_idx_0] = i + 1; - input_sizes_idx_0++; + r3[trueCount] = i + 1; + trueCount++; } } if (r2.size(0) == r3.size(0)) { - input_sizes_idx_0 = r2.size(0); - for (int32_T i{0}; i < input_sizes_idx_0; i++) { + trueCount = r2.size(0); + for (int32_T i{0}; i < trueCount; i++) { newDataPoints[i] = 0.5 * (dataPoints[r2[i] - 1] + dataPoints[r3[i] - 1]); } } else { @@ -176,47 +178,55 @@ namespace RAT } b_newDataPoints.set_size(newDataPoints.size(0)); - input_sizes_idx_0 = newDataPoints.size(0); - for (int32_T i{0}; i < input_sizes_idx_0; i++) { + trueCount = newDataPoints.size(0); + for (int32_T i{0}; i < trueCount; i++) { b_newDataPoints[i] = newDataPoints[i]; } - normalizeFunction(b_newDataPoints, sldProfile_data, sldProfile_size, r4); - input_sizes_idx_0 = r4.size(0); - for (int32_T i{0}; i < input_sizes_idx_0; i++) { + c_normalizeFunction(b_newDataPoints, sldProfile, r4); + trueCount = r4.size(0); + for (int32_T i{0}; i < trueCount; i++) { newDataPoints[i + newDataPoints.size(0)] = r4[i]; } // For simplicity append the new points at the end and then sort. + if (dataPoints.size(0) != 0) { + trueCount = dataPoints.size(0); + } else { + trueCount = 0; + } + if (newDataPoints.size(0) != 0) { input_sizes_idx_0 = newDataPoints.size(0); } else { input_sizes_idx_0 = 0; } - if (dataPoints.size(0) != 0) { - end = dataPoints.size(0); + if (newDataPoints.size(0) != 0) { + b_i = newDataPoints.size(0); } else { - end = 0; + b_i = 0; } - b_dataPoints.set_size(end + input_sizes_idx_0, 2); + b_dataPoints.set_size(trueCount + b_i, 2); for (int32_T i{0}; i < 2; i++) { - for (int32_T b_i{0}; b_i < end; b_i++) { + for (b_i = 0; b_i < trueCount; b_i++) { b_dataPoints[b_i + b_dataPoints.size(0) * i] = dataPoints[b_i + - dataPoints.size(0) * i]; + trueCount * i]; } + } - for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { - b_dataPoints[(b_i + end) + b_dataPoints.size(0) * i] = newDataPoints[b_i - + newDataPoints.size(0) * i]; + for (int32_T i{0}; i < 2; i++) { + for (b_i = 0; b_i < input_sizes_idx_0; b_i++) { + b_dataPoints[(b_i + trueCount) + b_dataPoints.size(0) * i] = + newDataPoints[b_i + input_sizes_idx_0 * i]; } } dataPoints.set_size(b_dataPoints.size(0), 2); - input_sizes_idx_0 = b_dataPoints.size(0); + trueCount = b_dataPoints.size(0); for (int32_T i{0}; i < 2; i++) { - for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { + for (b_i = 0; b_i < trueCount; b_i++) { dataPoints[b_i + dataPoints.size(0) * i] = b_dataPoints[b_i + b_dataPoints.size(0) * i]; } @@ -225,6 +235,44 @@ namespace RAT coder::sortrows(dataPoints); } + static void b_normalizeFunction(const ::coder::array &x, const :: + coder::array &sldProfile, ::coder::array &y) + { + ::coder::array r; + int32_T i; + + // Subfunctions + // NORMALIZEFUNCTION evaluates a function and returns a NxM array, where N + // is the number of elements of x and M is the number of outputs of func. + // All the outputs of func must be scalar. + // The optional parameter 'vectorizable' (default false) allows to specify + // that the input function can be vectorized. + // Modified by AVH for use with coder + // if (~exist('vectorizable','var') || isempty(vectorizable)) + // end + // abs(nargout(func)); %for anonymous functions nargout<0 + y.set_size(x.size(0)); + + // if vectorizable + // % For uniformity reasons, transform the 'x' array into a column vector. + // % In this way it does not matter if it is given as a column or a row + // % vector. + // [newValues{:}] = func(x(:)); + // y = cell2mat(newValues); + // else + i = x.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + // Remove cell array so no need for cell2mat + // which won't compile - AVH + // [newValues{:}] = func(x(i)); + // y(i,:) = cell2mat(newValues); + b_SLDFunction(x[b_i], sldProfile, r); + y[b_i] = r[0]; + } + + // end + } + static void binary_expand_op(const ::coder::array &in1, const :: coder::array &in2, const ::coder::array &in3, :: coder::array &in4, ::coder::array &in5, ::coder:: @@ -384,6 +432,46 @@ namespace RAT } } + static void c_normalizeFunction(const ::coder::array &x, const :: + coder::array &sldProfile, ::coder::array &y) + { + RATMainTLS *RATMainTLSThread; + int32_T i; + int32_T tmp_size; + RATMainTLSThread = emlrtGetThreadStackData(); + + // Subfunctions + // NORMALIZEFUNCTION evaluates a function and returns a NxM array, where N + // is the number of elements of x and M is the number of outputs of func. + // All the outputs of func must be scalar. + // The optional parameter 'vectorizable' (default false) allows to specify + // that the input function can be vectorized. + // Modified by AVH for use with coder + // if (~exist('vectorizable','var') || isempty(vectorizable)) + // end + // abs(nargout(func)); %for anonymous functions nargout<0 + y.set_size(x.size(0)); + + // if vectorizable + // % For uniformity reasons, transform the 'x' array into a column vector. + // % In this way it does not matter if it is given as a column or a row + // % vector. + // [newValues{:}] = func(x(:)); + // y = cell2mat(newValues); + // else + i = x.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + // Remove cell array so no need for cell2mat + // which won't compile - AVH + // [newValues{:}] = func(x(i)); + // y(i,:) = cell2mat(newValues); + b_SLDFunction(x[b_i], sldProfile, RATMainTLSThread->f1.tmp_data, &tmp_size); + y[b_i] = RATMainTLSThread->f1.tmp_data[0]; + } + + // end + } + static void calculateCentralAngles(const ::coder::array &XYdata, const real_T dataBoxSize[2], ::coder::array &cornerAngle) { @@ -398,7 +486,7 @@ namespace RAT ::coder::array r2; ::coder::array r3; ::coder::array secondStepSquared; - real_T dv[2]; + real_T b_dv[2]; real_T varargin_1; int32_T i; int32_T i1; @@ -410,8 +498,8 @@ namespace RAT // Normalize data, because angles depend on scaling. // calculate cosine of central angles coder::repmat(dataBoxSize, static_cast(XYdata.size(0)), b_XYdata); - coder::internal::minimum(XYdata, dv); - coder::repmat(dv, static_cast(XYdata.size(0)), r); + coder::internal::minimum(XYdata, b_dv); + coder::repmat(b_dv, static_cast(XYdata.size(0)), r); if (XYdata.size(0) == 1) { i = b_XYdata.size(0); } else { @@ -653,76 +741,77 @@ namespace RAT ::coder::array r3; ::coder::array r; ::coder::array r1; - int32_T end; + int32_T b_i; int32_T input_sizes_idx_0; + int32_T trueCount; // increaseSampling increase the sampling of an input function - end = segmentsToSplit.size(0); - input_sizes_idx_0 = 0; - for (int32_T i{0}; i < end; i++) { + input_sizes_idx_0 = segmentsToSplit.size(0); + trueCount = 0; + for (int32_T i{0}; i < input_sizes_idx_0; i++) { if (segmentsToSplit[i]) { - input_sizes_idx_0++; + trueCount++; } } - newDataPoints.set_size(input_sizes_idx_0, 2); + newDataPoints.set_size(trueCount, 2); for (int32_T i{0}; i < 2; i++) { - for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { + for (b_i = 0; b_i < trueCount; b_i++) { newDataPoints[b_i + newDataPoints.size(0) * i] = 0.0; } } r.set_size(segmentsToSplit.size(0) + 1); - input_sizes_idx_0 = segmentsToSplit.size(0); - for (int32_T i{0}; i < input_sizes_idx_0; i++) { + trueCount = segmentsToSplit.size(0); + for (int32_T i{0}; i < trueCount; i++) { r[i] = segmentsToSplit[i]; } r[segmentsToSplit.size(0)] = false; r1.set_size(segmentsToSplit.size(0) + 1); r1[0] = false; - input_sizes_idx_0 = segmentsToSplit.size(0); - for (int32_T i{0}; i < input_sizes_idx_0; i++) { + trueCount = segmentsToSplit.size(0); + for (int32_T i{0}; i < trueCount; i++) { r1[i + 1] = segmentsToSplit[i]; } - end = r.size(0) - 1; - input_sizes_idx_0 = 0; - for (int32_T i{0}; i <= end; i++) { + input_sizes_idx_0 = r.size(0) - 1; + trueCount = 0; + for (int32_T i{0}; i <= input_sizes_idx_0; i++) { if (r[i]) { - input_sizes_idx_0++; + trueCount++; } } - r2.set_size(input_sizes_idx_0); - input_sizes_idx_0 = 0; - for (int32_T i{0}; i <= end; i++) { + r2.set_size(trueCount); + trueCount = 0; + for (int32_T i{0}; i <= input_sizes_idx_0; i++) { if (r[i]) { - r2[input_sizes_idx_0] = i + 1; - input_sizes_idx_0++; + r2[trueCount] = i + 1; + trueCount++; } } - end = r1.size(0) - 1; - input_sizes_idx_0 = 0; - for (int32_T i{0}; i <= end; i++) { + input_sizes_idx_0 = r1.size(0) - 1; + trueCount = 0; + for (int32_T i{0}; i <= input_sizes_idx_0; i++) { if (r1[i]) { - input_sizes_idx_0++; + trueCount++; } } - r3.set_size(input_sizes_idx_0); - input_sizes_idx_0 = 0; - for (int32_T i{0}; i <= end; i++) { + r3.set_size(trueCount); + trueCount = 0; + for (int32_T i{0}; i <= input_sizes_idx_0; i++) { if (r1[i]) { - r3[input_sizes_idx_0] = i + 1; - input_sizes_idx_0++; + r3[trueCount] = i + 1; + trueCount++; } } if (r2.size(0) == r3.size(0)) { - input_sizes_idx_0 = r2.size(0); - for (int32_T i{0}; i < input_sizes_idx_0; i++) { + trueCount = r2.size(0); + for (int32_T i{0}; i < trueCount; i++) { newDataPoints[i] = 0.5 * (dataPoints[r2[i] - 1] + dataPoints[r3[i] - 1]); } } else { @@ -730,47 +819,55 @@ namespace RAT } b_newDataPoints.set_size(newDataPoints.size(0)); - input_sizes_idx_0 = newDataPoints.size(0); - for (int32_T i{0}; i < input_sizes_idx_0; i++) { + trueCount = newDataPoints.size(0); + for (int32_T i{0}; i < trueCount; i++) { b_newDataPoints[i] = newDataPoints[i]; } - normalizeFunction(b_newDataPoints, sldProfile, r4); - input_sizes_idx_0 = r4.size(0); - for (int32_T i{0}; i < input_sizes_idx_0; i++) { + b_normalizeFunction(b_newDataPoints, sldProfile, r4); + trueCount = r4.size(0); + for (int32_T i{0}; i < trueCount; i++) { newDataPoints[i + newDataPoints.size(0)] = r4[i]; } // For simplicity append the new points at the end and then sort. + if (dataPoints.size(0) != 0) { + trueCount = dataPoints.size(0); + } else { + trueCount = 0; + } + if (newDataPoints.size(0) != 0) { input_sizes_idx_0 = newDataPoints.size(0); } else { input_sizes_idx_0 = 0; } - if (dataPoints.size(0) != 0) { - end = dataPoints.size(0); + if (newDataPoints.size(0) != 0) { + b_i = newDataPoints.size(0); } else { - end = 0; + b_i = 0; } - b_dataPoints.set_size(end + input_sizes_idx_0, 2); + b_dataPoints.set_size(trueCount + b_i, 2); for (int32_T i{0}; i < 2; i++) { - for (int32_T b_i{0}; b_i < end; b_i++) { + for (b_i = 0; b_i < trueCount; b_i++) { b_dataPoints[b_i + b_dataPoints.size(0) * i] = dataPoints[b_i + - dataPoints.size(0) * i]; + trueCount * i]; } + } - for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { - b_dataPoints[(b_i + end) + b_dataPoints.size(0) * i] = newDataPoints[b_i - + newDataPoints.size(0) * i]; + for (int32_T i{0}; i < 2; i++) { + for (b_i = 0; b_i < input_sizes_idx_0; b_i++) { + b_dataPoints[(b_i + trueCount) + b_dataPoints.size(0) * i] = + newDataPoints[b_i + input_sizes_idx_0 * i]; } } dataPoints.set_size(b_dataPoints.size(0), 2); - input_sizes_idx_0 = b_dataPoints.size(0); + trueCount = b_dataPoints.size(0); for (int32_T i{0}; i < 2; i++) { - for (int32_T b_i{0}; b_i < input_sizes_idx_0; b_i++) { + for (b_i = 0; b_i < trueCount; b_i++) { dataPoints[b_i + dataPoints.size(0) * i] = b_dataPoints[b_i + b_dataPoints.size(0) * i]; } @@ -779,84 +876,6 @@ namespace RAT coder::sortrows(dataPoints); } - static void normalizeFunction(const ::coder::array &x, const - real_T sldProfile_data[], const int32_T sldProfile_size[2], ::coder::array< - real_T, 1U> &y) - { - real_T tmp_data[1000]; - int32_T i; - int32_T tmp_size; - - // Subfunctions - // NORMALIZEFUNCTION evaluates a function and returns a NxM array, where N - // is the number of elements of x and M is the number of outputs of func. - // All the outputs of func must be scalar. - // The optional parameter 'vectorizable' (default false) allows to specify - // that the input function can be vectorized. - // Modified by AVH for use with coder - // if (~exist('vectorizable','var') || isempty(vectorizable)) - // end - // abs(nargout(func)); %for anonymous functions nargout<0 - y.set_size(x.size(0)); - - // if vectorizable - // % For uniformity reasons, transform the 'x' array into a column vector. - // % In this way it does not matter if it is given as a column or a row - // % vector. - // [newValues{:}] = func(x(:)); - // y = cell2mat(newValues); - // else - i = x.size(0); - for (int32_T b_i{0}; b_i < i; b_i++) { - // Remove cell array so no need for cell2mat - // which won't compile - AVH - // [newValues{:}] = func(x(i)); - // y(i,:) = cell2mat(newValues); - SLDFunction(x[b_i], sldProfile_data, sldProfile_size, tmp_data, &tmp_size); - y[b_i] = tmp_data[0]; - } - - // end - } - - static void normalizeFunction(const ::coder::array &x, const :: - coder::array &sldProfile, ::coder::array &y) - { - ::coder::array r; - int32_T i; - - // Subfunctions - // NORMALIZEFUNCTION evaluates a function and returns a NxM array, where N - // is the number of elements of x and M is the number of outputs of func. - // All the outputs of func must be scalar. - // The optional parameter 'vectorizable' (default false) allows to specify - // that the input function can be vectorized. - // Modified by AVH for use with coder - // if (~exist('vectorizable','var') || isempty(vectorizable)) - // end - // abs(nargout(func)); %for anonymous functions nargout<0 - y.set_size(x.size(0)); - - // if vectorizable - // % For uniformity reasons, transform the 'x' array into a column vector. - // % In this way it does not matter if it is given as a column or a row - // % vector. - // [newValues{:}] = func(x(:)); - // y = cell2mat(newValues); - // else - i = x.size(0); - for (int32_T b_i{0}; b_i < i; b_i++) { - // Remove cell array so no need for cell2mat - // which won't compile - AVH - // [newValues{:}] = func(x(i)); - // y(i,:) = cell2mat(newValues); - SLDFunction(x[b_i], sldProfile, r); - y[b_i] = r[0]; - } - - // end - } - static void times(::coder::array &in1, const ::coder::array &in2, const ::coder::array &in3) { @@ -884,9 +903,8 @@ namespace RAT } } - void adaptive(const real_T sldProfile_data[], const int32_T sldProfile_size[2], - const real_T startDomain[2], real_T minAngle, real_T nPoints, - cell_24 *out) + void adaptive(const ::coder::array &sldProfile, const real_T + startDomain[2], real_T minAngle, real_T nPoints, cell_27 *out) { ::coder::array b_out; ::coder::array r; @@ -1123,7 +1141,7 @@ namespace RAT // Remove this syntax for compile - AVH // func = @(x) normalizeFunction(x,sldProfile,vectorizable); // Evaluate the input function on the initial set of points. - normalizeFunction(newDomain, sldProfile_data, sldProfile_size, hiVal); + b_normalizeFunction(newDomain, sldProfile, hiVal); // dataPoints = [initialDomain(:), func(initialDomain(:))]; out->f1.set_size(newDomain.size(0), 2); @@ -1146,8 +1164,8 @@ namespace RAT nRefinements = 0; exitg1 = false; while ((!exitg1) && (nRefinements < 10)) { - real_T dv[2]; - real_T dv1[2]; + real_T b_dv[2]; + real_T b_dv1[2]; boolean_T y; // calculate the box which encloses the current data points: @@ -1168,7 +1186,7 @@ namespace RAT } } - coder::internal::maximum(b_out, dv); + coder::internal::maximum(b_out, b_dv); b_out.set_size(out->f1.size(0), 2); loop_ub = out->f1.size(0); for (int32_T i{0}; i < 2; i++) { @@ -1177,7 +1195,7 @@ namespace RAT } } - coder::internal::minimum(b_out, dv1); + coder::internal::minimum(b_out, b_dv1); b_out.set_size(out->f1.size(0), 2); loop_ub = out->f1.size(0); for (int32_T i{0}; i < 2; i++) { @@ -1185,10 +1203,10 @@ namespace RAT b_out[i1 + b_out.size(0) * i] = out->f1[i1 + out->f1.size(0) * i]; } - dv[i] -= dv1[i]; + b_dv[i] -= b_dv1[i]; } - calculateCentralAngles(b_out, dv, cornerAngle); + calculateCentralAngles(b_out, b_dv, cornerAngle); if (out->f1.size(0) - 2 == cornerAngle.size(0)) { trianglesToRefine.set_size(out->f1.size(0) - 2); loop_ub = out->f1.size(0) - 2; @@ -1238,8 +1256,7 @@ namespace RAT y = coder::internal::allOrAny_anonFcn3(segmentsToSplit.size(0), segmentsToSplit); if (y) { - b_increaseSampling(out->f1, segmentsToSplit, sldProfile_data, - sldProfile_size); + increaseSampling(out->f1, segmentsToSplit, sldProfile); // Removed waitbar for compile - AVH // if displayWaitbar @@ -1270,8 +1287,8 @@ namespace RAT // end } - void adaptive(const ::coder::array &sldProfile, const real_T - startDomain[2], real_T minAngle, real_T nPoints, cell_24 *out) + void b_adaptive(const ::coder::array &sldProfile, const real_T + startDomain[2], real_T minAngle, real_T nPoints, cell_27 *out) { ::coder::array b_out; ::coder::array r; @@ -1508,7 +1525,7 @@ namespace RAT // Remove this syntax for compile - AVH // func = @(x) normalizeFunction(x,sldProfile,vectorizable); // Evaluate the input function on the initial set of points. - normalizeFunction(newDomain, sldProfile, hiVal); + c_normalizeFunction(newDomain, sldProfile, hiVal); // dataPoints = [initialDomain(:), func(initialDomain(:))]; out->f1.set_size(newDomain.size(0), 2); @@ -1531,8 +1548,8 @@ namespace RAT nRefinements = 0; exitg1 = false; while ((!exitg1) && (nRefinements < 10)) { - real_T dv[2]; - real_T dv1[2]; + real_T b_dv[2]; + real_T b_dv1[2]; boolean_T y; // calculate the box which encloses the current data points: @@ -1553,7 +1570,7 @@ namespace RAT } } - coder::internal::maximum(b_out, dv); + coder::internal::maximum(b_out, b_dv); b_out.set_size(out->f1.size(0), 2); loop_ub = out->f1.size(0); for (int32_T i{0}; i < 2; i++) { @@ -1562,7 +1579,7 @@ namespace RAT } } - coder::internal::minimum(b_out, dv1); + coder::internal::minimum(b_out, b_dv1); b_out.set_size(out->f1.size(0), 2); loop_ub = out->f1.size(0); for (int32_T i{0}; i < 2; i++) { @@ -1570,10 +1587,10 @@ namespace RAT b_out[i1 + b_out.size(0) * i] = out->f1[i1 + out->f1.size(0) * i]; } - dv[i] -= dv1[i]; + b_dv[i] -= b_dv1[i]; } - calculateCentralAngles(b_out, dv, cornerAngle); + calculateCentralAngles(b_out, b_dv, cornerAngle); if (out->f1.size(0) - 2 == cornerAngle.size(0)) { trianglesToRefine.set_size(out->f1.size(0) - 2); loop_ub = out->f1.size(0) - 2; @@ -1623,7 +1640,7 @@ namespace RAT y = coder::internal::allOrAny_anonFcn3(segmentsToSplit.size(0), segmentsToSplit); if (y) { - increaseSampling(out->f1, segmentsToSplit, sldProfile); + b_increaseSampling(out->f1, segmentsToSplit, sldProfile); // Removed waitbar for compile - AVH // if displayWaitbar diff --git a/RAT/adaptive.h b/RAT/adaptive.h index 1103dc68..14f558aa 100644 --- a/RAT/adaptive.h +++ b/RAT/adaptive.h @@ -19,17 +19,16 @@ // Type Declarations namespace RAT { - struct cell_24; + struct cell_27; } // Function Declarations namespace RAT { - void adaptive(const real_T sldProfile_data[], const int32_T sldProfile_size[2], - const real_T startDomain[2], real_T minAngle, real_T nPoints, - cell_24 *out); void adaptive(const ::coder::array &sldProfile, const real_T - startDomain[2], real_T minAngle, real_T nPoints, cell_24 *out); + startDomain[2], real_T minAngle, real_T nPoints, cell_27 *out); + void b_adaptive(const ::coder::array &sldProfile, const real_T + startDomain[2], real_T minAngle, real_T nPoints, cell_27 *out); } #endif diff --git a/RAT/all.cpp b/RAT/all.cpp new file mode 100644 index 00000000..fbb05473 --- /dev/null +++ b/RAT/all.cpp @@ -0,0 +1,45 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// all.cpp +// +// Code generation for function 'all' +// + +// Include files +#include "all.h" +#include "allOrAny.h" +#include "rt_nonfinite.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void all(const boolean_T x_data[], const int32_T x_size[2], boolean_T + y_data[], int32_T y_size[2]) + { + int32_T loop_ub; + y_size[0] = 1; + y_size[1] = static_cast(x_size[1]); + loop_ub = static_cast(x_size[1]); + if (loop_ub - 1 >= 0) { + y_data[0] = false; + } + + loop_ub = x_size[1]; + for (int32_T k{0}; k < loop_ub; k++) { + internal::b_allOrAny_anonFcn2(x_size[0], x_data, y_data); + } + } + + boolean_T b_all(const boolean_T x_data[], const int32_T x_size[2]) + { + return internal::allOrAny_anonFcn2(x_size[1], x_data); + } + } +} + +// End of code generation (all.cpp) diff --git a/RAT/all.h b/RAT/all.h new file mode 100644 index 00000000..720f7b5d --- /dev/null +++ b/RAT/all.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// all.h +// +// Code generation for function 'all' +// +#ifndef ALL_H +#define ALL_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void all(const boolean_T x_data[], const int32_T x_size[2], boolean_T + y_data[], int32_T y_size[2]); + boolean_T b_all(const boolean_T x_data[], const int32_T x_size[2]); + } +} + +#endif + +// End of code generation (all.h) diff --git a/RAT/allOrAny.cpp b/RAT/allOrAny.cpp index efd9eaed..2b40e675 100644 --- a/RAT/allOrAny.cpp +++ b/RAT/allOrAny.cpp @@ -20,6 +20,26 @@ namespace RAT { namespace internal { + boolean_T allOrAny_anonFcn2(int32_T n, const boolean_T X_data[]) + { + int32_T k; + boolean_T exitg1; + boolean_T varargout_1; + varargout_1 = true; + k = 0; + exitg1 = false; + while ((!exitg1) && (k <= static_cast(n) - 1)) { + if (!X_data[0]) { + varargout_1 = false; + exitg1 = true; + } else { + k++; + } + } + + return varargout_1; + } + boolean_T allOrAny_anonFcn3(int32_T n, const ::coder::array &X) { @@ -40,6 +60,24 @@ namespace RAT return varargout_1; } + + void b_allOrAny_anonFcn2(int32_T n, const boolean_T X_data[], boolean_T + Y_data[]) + { + int32_T k; + boolean_T exitg1; + Y_data[0] = true; + k = 0; + exitg1 = false; + while ((!exitg1) && (k <= static_cast(n) - 1)) { + if (!X_data[0]) { + Y_data[0] = false; + exitg1 = true; + } else { + k++; + } + } + } } } } diff --git a/RAT/allOrAny.h b/RAT/allOrAny.h index 9bcd4449..72a06df4 100644 --- a/RAT/allOrAny.h +++ b/RAT/allOrAny.h @@ -23,8 +23,11 @@ namespace RAT { namespace internal { + boolean_T allOrAny_anonFcn2(int32_T n, const boolean_T X_data[]); boolean_T allOrAny_anonFcn3(int32_T n, const ::coder::array &X); + void b_allOrAny_anonFcn2(int32_T n, const boolean_T X_data[], boolean_T + Y_data[]); } } } diff --git a/RAT/allocateLayersForContrast.cpp b/RAT/allocateLayersForContrast.cpp index b2410788..5461ca3b 100644 --- a/RAT/allocateLayersForContrast.cpp +++ b/RAT/allocateLayersForContrast.cpp @@ -10,18 +10,17 @@ // Include files #include "allocateLayersForContrast.h" +#include "RATMain_types.h" #include "length.h" #include "nullAssignment.h" -#include "reflectivityCalculation_internal_types.h" #include "rt_nonfinite.h" #include "coder_array.h" -#include "coder_bounded_array.h" // Function Definitions namespace RAT { void allocateLayersForContrast(const ::coder::array - &contrastLayers, const ::coder::array + &contrastLayers, const ::coder::array &outParameterisedLayers, boolean_T useImaginary, real_T thisContrastLayers_data[], int32_T thisContrastLayers_size[2]) { @@ -69,11 +68,11 @@ namespace RAT // thisLayer = [thisLayer(1) compSLD thisLayer(4:end)]; // end n = outParameterisedLayers[static_cast(contrastLayers[b_i]) - 1] - .f1.size[1]; + .f1.size(1); for (int32_T i1{0}; i1 < n; i1++) { thisContrastLayers_data[b_i + thisContrastLayers_size[0] * i1] = outParameterisedLayers[static_cast(contrastLayers[b_i]) - 1] - .f1.data[i1]; + .f1[i1]; } } else { coder::internal::nullAssignment(thisContrastLayers_data, diff --git a/RAT/allocateLayersForContrast.h b/RAT/allocateLayersForContrast.h index fb9a622b..0a6eaf83 100644 --- a/RAT/allocateLayersForContrast.h +++ b/RAT/allocateLayersForContrast.h @@ -11,7 +11,7 @@ #define ALLOCATELAYERSFORCONTRAST_H // Include files -#include "reflectivityCalculation_internal_types.h" +#include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include @@ -21,7 +21,7 @@ namespace RAT { void allocateLayersForContrast(const ::coder::array - &contrastLayers, const ::coder::array + &contrastLayers, const ::coder::array &outParameterisedLayers, boolean_T useImaginary, real_T thisContrastLayers_data[], int32_T thisContrastLayers_size[2]); } diff --git a/RAT/allocateParamsToLayers.cpp b/RAT/allocateParamsToLayers.cpp index 07841532..9c23e686 100644 --- a/RAT/allocateParamsToLayers.cpp +++ b/RAT/allocateParamsToLayers.cpp @@ -10,11 +10,10 @@ // Include files #include "allocateParamsToLayers.h" +#include "RATMain_types.h" #include "length.h" -#include "reflectivityCalculation_internal_types.h" #include "rt_nonfinite.h" #include "coder_array.h" -#include "coder_bounded_array.h" #include #include @@ -22,7 +21,7 @@ namespace RAT { void allocateParamsToLayers(const ::coder::array ¶ms, const :: - coder::array &layersDetails, ::coder::array &layersDetails, ::coder::array &outLayers) { real_T thisOutLayer_data[10]; @@ -60,10 +59,9 @@ namespace RAT thisOutLayer_data[coder::internal::intlength(layersDetails[b_i].f1.size(0), layersDetails[b_i].f1.size(1)) - 1] = layersDetails[b_i] .f1[layersDetails[b_i].f1.size(0) * layersDetails[b_i].f1.size(1) - 1]; - outLayers[b_i].f1.size[0] = 1; - outLayers[b_i].f1.size[1] = n; + outLayers[outLayers.size(0) * b_i].f1.set_size(1, n); for (i1 = 0; i1 < n; i1++) { - outLayers[b_i].f1.data[i1] = thisOutLayer_data[i1]; + outLayers[b_i].f1[i1] = thisOutLayer_data[i1]; } } } diff --git a/RAT/allocateParamsToLayers.h b/RAT/allocateParamsToLayers.h index 358372b8..e9678a54 100644 --- a/RAT/allocateParamsToLayers.h +++ b/RAT/allocateParamsToLayers.h @@ -11,7 +11,7 @@ #define ALLOCATEPARAMSTOLAYERS_H // Include files -#include "reflectivityCalculation_internal_types.h" +#include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include @@ -21,7 +21,7 @@ namespace RAT { void allocateParamsToLayers(const ::coder::array ¶ms, const :: - coder::array &layersDetails, ::coder::array &layersDetails, ::coder::array &outLayers); } diff --git a/RAT/anyNonFinite.cpp b/RAT/anyNonFinite.cpp new file mode 100644 index 00000000..d593d06d --- /dev/null +++ b/RAT/anyNonFinite.cpp @@ -0,0 +1,44 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// anyNonFinite.cpp +// +// Code generation for function 'anyNonFinite' +// + +// Include files +#include "anyNonFinite.h" +#include "rt_nonfinite.h" +#include "vAllOrAny.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T anyNonFinite(const ::coder::array &x) + { + int32_T i; + boolean_T p; + p = true; + i = x.size(1); + for (int32_T k{0}; k < i; k++) { + int32_T i1; + i1 = x.size(0); + for (int32_T b_k{0}; b_k < i1; b_k++) { + b_genloops(x, &p, b_k + 1, k + 1); + } + } + + return !p; + } + } + } +} + +// End of code generation (anyNonFinite.cpp) diff --git a/RAT/anyNonFinite.h b/RAT/anyNonFinite.h new file mode 100644 index 00000000..baa14c76 --- /dev/null +++ b/RAT/anyNonFinite.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// anyNonFinite.h +// +// Code generation for function 'anyNonFinite' +// +#ifndef ANYNONFINITE_H +#define ANYNONFINITE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T anyNonFinite(const ::coder::array &x); + } + } +} + +#endif + +// End of code generation (anyNonFinite.h) diff --git a/RAT/applyBackgroundCorrection.cpp b/RAT/applyBackgroundCorrection.cpp index 6248d64e..6206f76a 100644 --- a/RAT/applyBackgroundCorrection.cpp +++ b/RAT/applyBackgroundCorrection.cpp @@ -17,11 +17,11 @@ namespace RAT { void applyBackgroundCorrection(::coder::array &reflect, ::coder:: - array &Simul, ::coder::array &shifted_dat, real_T - backg, real_T backsType) + array &simul, ::coder::array &shiftedData, real_T + backgroundParams, real_T contrastBackgroundsType) { ::coder::array b_reflect; - switch (static_cast(backsType)) { + switch (static_cast(contrastBackgroundsType)) { case 1: { int32_T loop_ub; @@ -30,7 +30,7 @@ namespace RAT b_reflect.set_size(reflect.size(0)); loop_ub = reflect.size(0); for (int32_T i{0}; i < loop_ub; i++) { - b_reflect[i] = reflect[i + reflect.size(0)] + backg; + b_reflect[i] = reflect[i + reflect.size(0)] + backgroundParams; } loop_ub = b_reflect.size(0); @@ -38,15 +38,15 @@ namespace RAT reflect[i + reflect.size(0)] = b_reflect[i]; } - b_reflect.set_size(Simul.size(0)); - loop_ub = Simul.size(0); + b_reflect.set_size(simul.size(0)); + loop_ub = simul.size(0); for (int32_T i{0}; i < loop_ub; i++) { - b_reflect[i] = Simul[i + Simul.size(0)] + backg; + b_reflect[i] = simul[i + simul.size(0)] + backgroundParams; } loop_ub = b_reflect.size(0); for (int32_T i{0}; i < loop_ub; i++) { - Simul[i + Simul.size(0)] = b_reflect[i]; + simul[i + simul.size(0)] = b_reflect[i]; } } break; @@ -55,19 +55,19 @@ namespace RAT { int32_T loop_ub; - // %Subtract the background from the data.. - b_reflect.set_size(shifted_dat.size(0)); - loop_ub = shifted_dat.size(0); + // Subtract the background from the data.. + b_reflect.set_size(shiftedData.size(0)); + loop_ub = shiftedData.size(0); for (int32_T i{0}; i < loop_ub; i++) { - b_reflect[i] = shifted_dat[i + shifted_dat.size(0)] - backg; + b_reflect[i] = shiftedData[i + shiftedData.size(0)] - backgroundParams; } loop_ub = b_reflect.size(0); for (int32_T i{0}; i < loop_ub; i++) { - shifted_dat[i + shifted_dat.size(0)] = b_reflect[i]; + shiftedData[i + shiftedData.size(0)] = b_reflect[i]; } - // shifted_dat(:,3) = shifted_dat(:,3) - backg; + // shiftedData(:,3) = shiftedData(:,3) - backgroundParams; } break; } diff --git a/RAT/applyBackgroundCorrection.h b/RAT/applyBackgroundCorrection.h index 984865b1..01828f5a 100644 --- a/RAT/applyBackgroundCorrection.h +++ b/RAT/applyBackgroundCorrection.h @@ -20,8 +20,8 @@ namespace RAT { void applyBackgroundCorrection(::coder::array &reflect, ::coder:: - array &Simul, ::coder::array &shifted_dat, real_T - backg, real_T backsType); + array &simul, ::coder::array &shiftedData, real_T + backgroundParams, real_T contrastBackgroundsType); } #endif diff --git a/RAT/applyHydrationImag.cpp b/RAT/applyHydrationImag.cpp new file mode 100644 index 00000000..bbf85351 --- /dev/null +++ b/RAT/applyHydrationImag.cpp @@ -0,0 +1,97 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// applyHydrationImag.cpp +// +// Code generation for function 'applyHydrationImag' +// + +// Include files +#include "applyHydrationImag.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void applyHydrationImag(::coder::array &thisContrastLayers, real_T + bulkIn, real_T bulkOut) + { + ::coder::array newOutLayers; + int16_T outSize_idx_0; + + // Applies the hydration correction to real value of layers + // if it is necessary.. (This is for when im(SLD) is used) + // The only guidance we have to whether the user is using hydration + // in their custom model is the number of columns of the output + outSize_idx_0 = static_cast(thisContrastLayers.size(0)); + + // [nlayers x nCols] + if (static_cast(thisContrastLayers.size(1)) == 6) { + int32_T i; + int32_T loop_ub; + + // we need to calculate the hydrated SLD + newOutLayers.set_size(static_cast(outSize_idx_0), 4); + loop_ub = outSize_idx_0; + for (i = 0; i < 4; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + newOutLayers[i1 + newOutLayers.size(0) * i] = 0.0; + } + } + + loop_ub = thisContrastLayers.size(0); + for (i = 0; i < loop_ub; i++) { + newOutLayers[i] = thisContrastLayers[i]; + } + + // Thickness' + loop_ub = thisContrastLayers.size(0); + for (i = 0; i < loop_ub; i++) { + newOutLayers[i + newOutLayers.size(0) * 2] = thisContrastLayers[i + + thisContrastLayers.size(0) * 2]; + } + + // We never hydrate im(SLD) + loop_ub = thisContrastLayers.size(0); + for (i = 0; i < loop_ub; i++) { + newOutLayers[i + newOutLayers.size(0) * 3] = thisContrastLayers[i + + thisContrastLayers.size(0) * 3]; + } + + // Roughness + i = outSize_idx_0; + for (int32_T n{0}; n < i; n++) { + real_T d; + real_T thisHydration; + thisHydration = thisContrastLayers[n + thisContrastLayers.size(0) * 4] / + 100.0; + + // Assume percent for backwards compatability + if (thisContrastLayers[n + thisContrastLayers.size(0) * 5] == 0.0) { + d = bulkIn; + } else { + d = bulkOut; + } + + newOutLayers[n + newOutLayers.size(0)] = thisHydration * d + (1.0 - + thisHydration) * thisContrastLayers[n + thisContrastLayers.size(0)]; + + // Reassignment to keep codegen happy + } + + thisContrastLayers.set_size(newOutLayers.size(0), 4); + loop_ub = newOutLayers.size(0); + for (i = 0; i < 4; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + thisContrastLayers[i1 + thisContrastLayers.size(0) * i] = + newOutLayers[i1 + newOutLayers.size(0) * i]; + } + } + } + } +} + +// End of code generation (applyHydrationImag.cpp) diff --git a/RAT/applyHydrationImag.h b/RAT/applyHydrationImag.h new file mode 100644 index 00000000..334d78fd --- /dev/null +++ b/RAT/applyHydrationImag.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// applyHydrationImag.h +// +// Code generation for function 'applyHydrationImag' +// +#ifndef APPLYHYDRATIONIMAG_H +#define APPLYHYDRATIONIMAG_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void applyHydrationImag(::coder::array &thisContrastLayers, real_T + bulkIn, real_T bulkOut); +} + +#endif + +// End of code generation (applyHydrationImag.h) diff --git a/RAT/applyHydrationReal.cpp b/RAT/applyHydrationReal.cpp new file mode 100644 index 00000000..c819f885 --- /dev/null +++ b/RAT/applyHydrationReal.cpp @@ -0,0 +1,90 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// applyHydrationReal.cpp +// +// Code generation for function 'applyHydrationReal' +// + +// Include files +#include "applyHydrationReal.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void applyHydrationReal(::coder::array &thisContrastLayers, real_T + bulkIn, real_T bulkOut) + { + ::coder::array newOutLayers; + int16_T outSize_idx_0; + + // Applies the hydration correction to real value of layers + // if it is necessary.. (This is for when im(SLD) is not used) + // The only guidance we have to whether the user is using hydration + // in their custom model is the numbre of columns of the output + outSize_idx_0 = static_cast(thisContrastLayers.size(0)); + + // [nlayers x nCols] + if (static_cast(thisContrastLayers.size(1)) == 5) { + int32_T i; + int32_T loop_ub; + + // we need to calculate the hydrated SLD + newOutLayers.set_size(static_cast(outSize_idx_0), 3); + loop_ub = outSize_idx_0; + for (i = 0; i < 3; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + newOutLayers[i1 + newOutLayers.size(0) * i] = 0.0; + } + } + + loop_ub = thisContrastLayers.size(0); + for (i = 0; i < loop_ub; i++) { + newOutLayers[i] = thisContrastLayers[i]; + } + + // Thickness' + loop_ub = thisContrastLayers.size(0); + for (i = 0; i < loop_ub; i++) { + newOutLayers[i + newOutLayers.size(0) * 2] = thisContrastLayers[i + + thisContrastLayers.size(0) * 2]; + } + + // Roughness + i = outSize_idx_0; + for (int32_T n{0}; n < i; n++) { + real_T d; + real_T thisHydration; + thisHydration = thisContrastLayers[n + thisContrastLayers.size(0) * 3] / + 100.0; + + // Assume percent for backwards compatability + if (thisContrastLayers[n + thisContrastLayers.size(0) * 4] == 0.0) { + d = bulkIn; + } else { + d = bulkOut; + } + + newOutLayers[n + newOutLayers.size(0)] = thisHydration * d + (1.0 - + thisHydration) * thisContrastLayers[n + thisContrastLayers.size(0)]; + + // Reassignment to keep codegen happy + } + + thisContrastLayers.set_size(newOutLayers.size(0), 3); + loop_ub = newOutLayers.size(0); + for (i = 0; i < 3; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + thisContrastLayers[i1 + thisContrastLayers.size(0) * i] = + newOutLayers[i1 + newOutLayers.size(0) * i]; + } + } + } + } +} + +// End of code generation (applyHydrationReal.cpp) diff --git a/RAT/applyHydrationReal.h b/RAT/applyHydrationReal.h new file mode 100644 index 00000000..5a2e41c6 --- /dev/null +++ b/RAT/applyHydrationReal.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// applyHydrationReal.h +// +// Code generation for function 'applyHydrationReal' +// +#ifndef APPLYHYDRATIONREAL_H +#define APPLYHYDRATIONREAL_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void applyHydrationReal(::coder::array &thisContrastLayers, real_T + bulkIn, real_T bulkOut); +} + +#endif + +// End of code generation (applyHydrationReal.h) diff --git a/RAT/averageReflectivity.cpp b/RAT/averageReflectivity.cpp new file mode 100644 index 00000000..3d87dd8c --- /dev/null +++ b/RAT/averageReflectivity.cpp @@ -0,0 +1,67 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// averageReflectivity.cpp +// +// Code generation for function 'averageReflectivity' +// + +// Include files +#include "averageReflectivity.h" +#include "cat.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + void averageReflectivity(const ::coder::array &reflect1, const :: + coder::array &reflect2, const ::coder::array + &simul1, const ::coder::array &simul2, real_T domainRatio, :: + coder::array &totReflect, ::coder::array &totSimul) + { + int32_T loop_ub; + + // Calculates the avereaged reflectivity for domains samples (incoherent + // sum) + if (reflect1.size(0) == reflect2.size(0)) { + totReflect.set_size(reflect1.size(0), 2); + loop_ub = reflect1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + totReflect[i] = reflect1[i]; + } + + loop_ub = reflect1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + totReflect[i + totReflect.size(0)] = domainRatio * reflect1[i + + reflect1.size(0)] + (1.0 - domainRatio) * reflect2[i + reflect2.size + (0)]; + } + } else { + binary_expand_op(totReflect, reflect1, domainRatio, reflect2); + } + + if (simul1.size(0) == simul2.size(0)) { + totSimul.set_size(simul1.size(0), 2); + loop_ub = simul1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + totSimul[i] = simul1[i]; + } + + loop_ub = simul1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + totSimul[i + totSimul.size(0)] = domainRatio * simul1[i + simul1.size + (0)] + (1.0 - domainRatio) * simul2[i + simul2.size(0)]; + } + } else { + binary_expand_op(totSimul, simul1, domainRatio, simul2); + } + } + } +} + +// End of code generation (averageReflectivity.cpp) diff --git a/RAT/averageReflectivity.h b/RAT/averageReflectivity.h new file mode 100644 index 00000000..29d82d55 --- /dev/null +++ b/RAT/averageReflectivity.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// averageReflectivity.h +// +// Code generation for function 'averageReflectivity' +// +#ifndef AVERAGEREFLECTIVITY_H +#define AVERAGEREFLECTIVITY_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + void averageReflectivity(const ::coder::array &reflect1, const :: + coder::array &reflect2, const ::coder::array + &simul1, const ::coder::array &simul2, real_T domainRatio, :: + coder::array &totReflect, ::coder::array &totSimul); + } +} + +#endif + +// End of code generation (averageReflectivity.h) diff --git a/RAT/backSort.cpp b/RAT/backSort.cpp index 03d13668..813bd48f 100644 --- a/RAT/backSort.cpp +++ b/RAT/backSort.cpp @@ -16,63 +16,68 @@ // Function Definitions namespace RAT { - void backSort(real_T cBacks, real_T cShifts, real_T cScales, real_T cNbas, - real_T cNbss, real_T cRes, const ::coder::array - &backs, const ::coder::array &shifts, const ::coder:: - array &sf, const ::coder::array &nba, - const ::coder::array &nbs, const ::coder::array< - real_T, 2U> &res, real_T *backg, real_T *qshift, real_T *b_sf, - real_T *b_nba, real_T *b_nbs, real_T *resol) + void backSort(real_T contrastBackgrounds, real_T contrastQzshifts, real_T + contrastScalefactors, real_T contrastBulkIns, real_T + contrastBulkOuts, real_T contrastResolutions, const ::coder:: + array &backgroundParams, const ::coder::array &qzshifts, const ::coder::array &scalefactors, + const ::coder::array &bulkIn, const ::coder::array< + real_T, 2U> &bulkOut, const ::coder::array + &resolutionParams, real_T *outBackgroundParam, real_T + *outQzshift, real_T *outScalefactor, real_T *outBulkIn, real_T + *outBulkOut, real_T *outResolutionParam) { - // Distributes the background and shift values among the different contrasts + // Distributes the background and shift values among the different contrasts // - // USAGE:: + // USAGE:: // - // [backg,qshift,sf,nba,nbs,resol] = backsort(cBacks,cShifts,cScales,cNbas,cNbss,cRes,backs,shifts,sf,nba,nbs,res) + // [backgroundParams,qzshift,scalefactor,bulkIn,bulkOut,resolutionParams] = backsort(contrastBackgrounds,contrastQzshifts,contrastScalefactors,contrastBulkIns,contrastBulkOuts,contrastResolutions,backs,qzshifts,scalefactor,bulkIn,bulkOut,res) // - // INPUTS: - // * cBacks : Which backround value is associated with each contrast - // * cShifts : Which qz_shift value is associated with each contrast - // * cScales : Which scalefactor value is associated with each contrast - // * cNbas : Which NBa value is associated with each contrast - // * cNbss : Which Nbs value is associated with each contrast - // * cRes : Which resolution value is associated with each contrast - // * backs : List of all background values. - // * shifts : List of all qz-shift values - // * sf : List of all scalefactor values - // * nba : List of all nba values - // * nbs : List of all nbs values - // * res : List of all resolution values - // - // OUTPUTS: - // * backgs : list of actual background values for each contrast - // * qshifts : list of actual shift values for each contrast - // * sfs : list of actual shift values for each contrast - // * nbas : list of actual shift values for each contrast - // * nbss : list of actual shift values for each contrast - // * nbss : list of actual shift values for each contrast + // INPUTS: + // * contrastBackgrounds: Which background value is associated with each contrast + // * contrastQzshifts: Which qz_shift value is associated with each contrast + // * contrastScalefactors: Which scalefactor value is associated with each contrast + // * contrastBulkIns: Which BulkIn value is associated with each contrast + // * contrastBulkOuts: Which BulkOut value is associated with each contrast + // * contrastResolutions: Which resolution value is associated with each contrast + // * backgroundParams: List of all background values. + // * qzshifts: List of all qzshift values + // * scalefactors: List of all scalefactor values + // * bulkIn: List of all bulkIn values + // * bulkOut: List of all bulkOut values + // * resolutionParams: List of all resolution values // + // OUTPUTS: + // * outBackground: list of actual background values for each contrast + // * outQzshift: list of actual qzshift values for each contrast + // * outScalefactor: list of actual scalefactor values for each contrast + // * outBulkIn: list of actual bulkIn values for each contrast + // * outBulkOut: list of actual bulkOut values for each contrast + // * outResolution: list of actual resolution for each contrast // for i = 1:nc - // thisBack = cBacks(i); - *backg = backs[static_cast(cBacks) - 1]; + // thisBack = contrastBackgrounds(i); + *outBackgroundParam = backgroundParams[static_cast + (contrastBackgrounds) - 1]; - // thisShift = cShifts(i); - *qshift = shifts[static_cast(cShifts) - 1]; + // thisShift = contrastQzshifts(i); + *outQzshift = qzshifts[static_cast(contrastQzshifts) - 1]; - // thisScale = cScales(i); - *b_sf = sf[static_cast(cScales) - 1]; + // thisScale = contrastScalefactors(i); + *outScalefactor = scalefactors[static_cast(contrastScalefactors) - + 1]; - // thisNbair = cNbas(i); - *b_nba = nba[static_cast(cNbas) - 1]; + // thisBulkIn = contrastBulkIns(i); + *outBulkIn = bulkIn[static_cast(contrastBulkIns) - 1]; - // thisNbsub = cNbss(i); - *b_nbs = nbs[static_cast(cNbss) - 1]; + // thisBulkOut = contrastBulkOuts(i); + *outBulkOut = bulkOut[static_cast(contrastBulkOuts) - 1]; - // thisResol = cRes(i); - if (cRes != -1.0) { - *resol = res[static_cast(cRes) - 1]; + // thisResol = contrastResolutions(i); + if (contrastResolutions != -1.0) { + *outResolutionParam = resolutionParams[static_cast + (contrastResolutions) - 1]; } else { - *resol = -1.0; + *outResolutionParam = -1.0; // Negative value means we have a data resolution.. } diff --git a/RAT/backSort.h b/RAT/backSort.h index cb95c8ee..3d03ba60 100644 --- a/RAT/backSort.h +++ b/RAT/backSort.h @@ -19,13 +19,16 @@ // Function Declarations namespace RAT { - void backSort(real_T cBacks, real_T cShifts, real_T cScales, real_T cNbas, - real_T cNbss, real_T cRes, const ::coder::array - &backs, const ::coder::array &shifts, const ::coder:: - array &sf, const ::coder::array &nba, - const ::coder::array &nbs, const ::coder::array< - real_T, 2U> &res, real_T *backg, real_T *qshift, real_T *b_sf, - real_T *b_nba, real_T *b_nbs, real_T *resol); + void backSort(real_T contrastBackgrounds, real_T contrastQzshifts, real_T + contrastScalefactors, real_T contrastBulkIns, real_T + contrastBulkOuts, real_T contrastResolutions, const ::coder:: + array &backgroundParams, const ::coder::array &qzshifts, const ::coder::array &scalefactors, + const ::coder::array &bulkIn, const ::coder::array< + real_T, 2U> &bulkOut, const ::coder::array + &resolutionParams, real_T *outBackgroundParam, real_T + *outQzshift, real_T *outScalefactor, real_T *outBulkIn, real_T + *outBulkOut, real_T *outResolutionParam); } #endif diff --git a/RAT/blockedSummation.cpp b/RAT/blockedSummation.cpp index 19b360a5..d161e65c 100644 --- a/RAT/blockedSummation.cpp +++ b/RAT/blockedSummation.cpp @@ -18,6 +18,7 @@ namespace RAT { namespace coder { + static real_T b_nestedIter(const ::coder::array &x, int32_T vlen); static void nestedIter(const ::coder::array &x, int32_T vlen, :: coder::array &y); } @@ -28,6 +29,57 @@ namespace RAT { namespace coder { + static real_T b_nestedIter(const ::coder::array &x, int32_T vlen) + { + real_T y; + int32_T firstBlockLength; + int32_T lastBlockLength; + int32_T nblocks; + if (vlen <= 1024) { + firstBlockLength = vlen; + lastBlockLength = 0; + nblocks = 1; + } else { + firstBlockLength = 1024; + nblocks = vlen / 1024; + lastBlockLength = vlen - (nblocks << 10); + if (lastBlockLength > 0) { + nblocks++; + } else { + lastBlockLength = 1024; + } + } + + y = x[0]; + for (int32_T k{2}; k <= firstBlockLength; k++) { + if (vlen >= 2) { + y += x[k - 1]; + } + } + + for (int32_T ib{2}; ib <= nblocks; ib++) { + real_T bsum; + int32_T hi; + firstBlockLength = (ib - 1) << 10; + bsum = x[firstBlockLength]; + if (ib == nblocks) { + hi = lastBlockLength; + } else { + hi = 1024; + } + + for (int32_T k{2}; k <= hi; k++) { + if (vlen >= 2) { + bsum += x[(firstBlockLength + k) - 1]; + } + } + + y += bsum; + } + + return y; + } + static void nestedIter(const ::coder::array &x, int32_T vlen, :: coder::array &y) { @@ -104,6 +156,33 @@ namespace RAT } } + real_T blockedSummation(const ::coder::array &x, int32_T vlen) + { + real_T y; + if ((x.size(1) == 0) || (vlen == 0)) { + y = 0.0; + } else { + y = b_nestedIter(x, vlen); + } + + return y; + } + + void blockedSummation(const ::coder::array &x, int32_T vlen, :: + coder::array &y) + { + if ((x.size(0) == 0) || (x.size(1) == 0) || (vlen == 0)) { + int32_T loop_ub; + y.set_size(1, x.size(1)); + loop_ub = x.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + y[i] = 0.0; + } + } else { + nestedIter(x, vlen, y); + } + } + void blockedSummation(const ::coder::array &x, int32_T vlen, :: coder::array &y) { @@ -119,6 +198,237 @@ namespace RAT } } + creal_T nestedIter(const ::coder::array &x, int32_T vlen) + { + creal_T y; + int32_T firstBlockLength; + int32_T lastBlockLength; + int32_T nblocks; + if (vlen <= 1024) { + firstBlockLength = vlen; + lastBlockLength = 0; + nblocks = 1; + } else { + firstBlockLength = 1024; + nblocks = vlen / 1024; + lastBlockLength = vlen - (nblocks << 10); + if (lastBlockLength > 0) { + nblocks++; + } else { + lastBlockLength = 1024; + } + } + + y = x[0]; + for (int32_T k{2}; k <= firstBlockLength; k++) { + if (vlen >= 2) { + y.re += x[k - 1].re; + y.im += x[k - 1].im; + } + } + + for (int32_T ib{2}; ib <= nblocks; ib++) { + real_T xk_im; + real_T xk_re; + int32_T hi; + firstBlockLength = (ib - 1) << 10; + xk_re = x[firstBlockLength].re; + xk_im = x[firstBlockLength].im; + if (ib == nblocks) { + hi = lastBlockLength; + } else { + hi = 1024; + } + + for (int32_T k{2}; k <= hi; k++) { + if (vlen >= 2) { + int32_T xk_re_tmp; + xk_re_tmp = (firstBlockLength + k) - 1; + xk_re += x[xk_re_tmp].re; + xk_im += x[xk_re_tmp].im; + } + } + + y.re += xk_re; + y.im += xk_im; + } + + return y; + } + + real_T nestedIter(const ::coder::array &x, int32_T vlen) + { + real_T y; + int32_T firstBlockLength; + int32_T lastBlockLength; + int32_T nblocks; + if (vlen <= 1024) { + firstBlockLength = vlen; + lastBlockLength = 0; + nblocks = 1; + } else { + firstBlockLength = 1024; + nblocks = vlen / 1024; + lastBlockLength = vlen - (nblocks << 10); + if (lastBlockLength > 0) { + nblocks++; + } else { + lastBlockLength = 1024; + } + } + + y = x[0]; + for (int32_T k{2}; k <= firstBlockLength; k++) { + if (vlen >= 2) { + y += x[k - 1]; + } + } + + for (int32_T ib{2}; ib <= nblocks; ib++) { + real_T bsum; + int32_T hi; + firstBlockLength = (ib - 1) << 10; + bsum = x[firstBlockLength]; + if (ib == nblocks) { + hi = lastBlockLength; + } else { + hi = 1024; + } + + for (int32_T k{2}; k <= hi; k++) { + if (vlen >= 2) { + bsum += x[(firstBlockLength + k) - 1]; + } + } + + y += bsum; + } + + return y; + } + + void nestedIter(const ::coder::array &x, int32_T vlen, ::coder:: + array &y) + { + int32_T firstBlockLength; + int32_T i; + int32_T i1; + int32_T lastBlockLength; + int32_T nblocks; + y.set_size(1, x.size(1), x.size(2)); + i = x.size(2); + if (x.size(2) - 1 >= 0) { + i1 = x.size(1); + if (x.size(1) - 1 >= 0) { + if (vlen <= 1024) { + firstBlockLength = vlen; + lastBlockLength = 0; + nblocks = 1; + } else { + firstBlockLength = 1024; + nblocks = vlen / 1024; + lastBlockLength = vlen - (nblocks << 10); + if (lastBlockLength > 0) { + nblocks++; + } else { + lastBlockLength = 1024; + } + } + } + } + + for (int32_T k{0}; k < i; k++) { + for (int32_T b_k{0}; b_k < i1; b_k++) { + y[b_k + y.size(1) * k] = x[x.size(0) * b_k + x.size(0) * x.size(1) * k]; + for (int32_T c_k{2}; c_k <= firstBlockLength; c_k++) { + if (vlen >= 2) { + y[b_k + y.size(1) * k] = y[b_k + y.size(1) * k] + x[((c_k + x.size + (0) * b_k) + x.size(0) * x.size(1) * k) - 1]; + } + } + + for (int32_T ib{2}; ib <= nblocks; ib++) { + real_T bsum; + int32_T hi; + int32_T offset; + offset = (ib - 1) << 10; + bsum = x[(offset + x.size(0) * b_k) + x.size(0) * x.size(1) * k]; + if (ib == nblocks) { + hi = lastBlockLength; + } else { + hi = 1024; + } + + for (int32_T c_k{2}; c_k <= hi; c_k++) { + if (vlen >= 2) { + bsum += x[(((offset + c_k) + x.size(0) * b_k) + x.size(0) * + x.size(1) * k) - 1]; + } + } + + y[b_k + y.size(1) * k] = y[b_k + y.size(1) * k] + bsum; + } + } + } + } + + void nestedIter(const ::coder::array &x, int32_T vlen, ::coder:: + array &y) + { + int32_T firstBlockLength; + int32_T i; + int32_T lastBlockLength; + int32_T nblocks; + y.set_size(1, x.size(1)); + i = x.size(1); + if (x.size(1) - 1 >= 0) { + if (vlen <= 1024) { + firstBlockLength = vlen; + lastBlockLength = 0; + nblocks = 1; + } else { + firstBlockLength = 1024; + nblocks = vlen / 1024; + lastBlockLength = vlen - (nblocks << 10); + if (lastBlockLength > 0) { + nblocks++; + } else { + lastBlockLength = 1024; + } + } + } + + for (int32_T k{0}; k < i; k++) { + y[k] = x[x.size(0) * k]; + for (int32_T b_k{2}; b_k <= firstBlockLength; b_k++) { + if (vlen >= 2) { + y[k] = y[k] + x[(b_k + x.size(0) * k) - 1]; + } + } + + for (int32_T ib{2}; ib <= nblocks; ib++) { + real_T bsum; + int32_T hi; + int32_T offset; + offset = (ib - 1) << 10; + bsum = x[offset + x.size(0) * k]; + if (ib == nblocks) { + hi = lastBlockLength; + } else { + hi = 1024; + } + + for (int32_T b_k{2}; b_k <= hi; b_k++) { + if (vlen >= 2) { + bsum += x[((offset + b_k) + x.size(0) * k) - 1]; + } + } + + y[k] = y[k] + bsum; + } + } + } + real_T nestedIter(const ::coder::array &x, int32_T vlen) { real_T y; diff --git a/RAT/blockedSummation.h b/RAT/blockedSummation.h index 07b8280f..90942c08 100644 --- a/RAT/blockedSummation.h +++ b/RAT/blockedSummation.h @@ -21,8 +21,17 @@ namespace RAT { namespace coder { + real_T blockedSummation(const ::coder::array &x, int32_T vlen); + void blockedSummation(const ::coder::array &x, int32_T vlen, :: + coder::array &y); void blockedSummation(const ::coder::array &x, int32_T vlen, :: coder::array &y); + creal_T nestedIter(const ::coder::array &x, int32_T vlen); + real_T nestedIter(const ::coder::array &x, int32_T vlen); + void nestedIter(const ::coder::array &x, int32_T vlen, ::coder:: + array &y); + void nestedIter(const ::coder::array &x, int32_T vlen, ::coder:: + array &y); real_T nestedIter(const ::coder::array &x, int32_T vlen); } } diff --git a/RAT/boundaryHandling.cpp b/RAT/boundaryHandling.cpp new file mode 100644 index 00000000..00ee09fe --- /dev/null +++ b/RAT/boundaryHandling.cpp @@ -0,0 +1,282 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// boundaryHandling.cpp +// +// Code generation for function 'boundaryHandling' +// + +// Include files +#include "boundaryHandling.h" +#include "find.h" +#include "rand.h" +#include "repmat.h" +#include "rt_nonfinite.h" +#include "strcmp.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const :: + coder::array &in4, const ::coder::array &in5); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const :: + coder::array &in4, const ::coder::array &in5) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + int32_T stride_2_0; + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in4.size(0) != 1); + stride_2_0 = (in2.size(0) != 1); + if (in2.size(0) == 1) { + i = in4.size(0); + } else { + i = in2.size(0); + } + + if (i == 1) { + loop_ub = in2.size(0); + } else if (in2.size(0) == 1) { + loop_ub = in4.size(0); + } else { + loop_ub = in2.size(0); + } + + for (i = 0; i < loop_ub; i++) { + int32_T i1; + i1 = in2[i * stride_2_0] - 1; + in1[in2[i] - 1] = in3[in2[i * stride_0_0] - 1] + in4[i * stride_1_0] * + (in5[i1] - in3[i1]); + } + } + + void boundaryHandling(::coder::array &x, const ::coder::array< + real_T, 2U> &Par_info_min, const ::coder::array &Par_info_max, const char_T + Par_info_boundhandling_data[], const int32_T + Par_info_boundhandling_size[2]) + { + ::coder::array max_d; + ::coder::array min_d; + ::coder::array b_max_d; + ::coder::array ii_low; + ::coder::array ii_up; + ::coder::array b_x; + real_T b_ii_low[2]; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + + // Function to check whether parameter values remain within prior bounds + // First determine the size of new + // Now replicate min and max + coder::repmat(Par_info_min, static_cast(x.size(0)), min_d); + coder::repmat(Par_info_max, static_cast(x.size(0)), max_d); + + // Now find which elements of x are smaller than their respective bound + if ((x.size(0) == min_d.size(0)) && (x.size(1) == min_d.size(1))) { + b_x.set_size(x.size(0), x.size(1)); + loop_ub = x.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = x.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + b_x[i1 + b_x.size(0) * i] = (x[i1 + x.size(0) * i] < min_d[i1 + + min_d.size(0) * i]); + } + } + + coder::c_eml_find(b_x, ii_up); + } else { + c_binary_expand_op(ii_up, x, min_d); + } + + ii_low.set_size(ii_up.size(0)); + loop_ub = ii_up.size(0); + for (i = 0; i < loop_ub; i++) { + ii_low[i] = ii_up[i]; + } + + // Now find which elements of x are larger than their respective bound + if ((x.size(0) == max_d.size(0)) && (x.size(1) == max_d.size(1))) { + b_x.set_size(x.size(0), x.size(1)); + loop_ub = x.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = x.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + b_x[i1 + b_x.size(0) * i] = (x[i1 + x.size(0) * i] > max_d[i1 + + max_d.size(0) * i]); + } + } + + coder::c_eml_find(b_x, ii_up); + } else { + binary_expand_op(ii_up, x, max_d); + } + + // Reflection + if (coder::internal::y_strcmp(Par_info_boundhandling_data, + Par_info_boundhandling_size)) { + // reflect in min + b_max_d.set_size(ii_low.size(0)); + loop_ub = ii_low.size(0); + for (i = 0; i < loop_ub; i++) { + b_max_d[i] = 2.0 * min_d[ii_low[i] - 1] - x[ii_low[i] - 1]; + } + + loop_ub = b_max_d.size(0); + for (i = 0; i < loop_ub; i++) { + x[ii_low[i] - 1] = b_max_d[i]; + } + + // reflect in max + b_max_d.set_size(ii_up.size(0)); + loop_ub = ii_up.size(0); + for (i = 0; i < loop_ub; i++) { + b_max_d[i] = 2.0 * max_d[ii_up[i] - 1] - x[ii_up[i] - 1]; + } + + loop_ub = b_max_d.size(0); + for (i = 0; i < loop_ub; i++) { + x[ii_up[i] - 1] = b_max_d[i]; + } + } + + // Bound + if (coder::internal::ab_strcmp(Par_info_boundhandling_data, + Par_info_boundhandling_size)) { + // set lower values to min + loop_ub = ii_low.size(0); + for (i = 0; i < loop_ub; i++) { + x[ii_low[i] - 1] = min_d[ii_low[i] - 1]; + } + + // set upper values to max + loop_ub = ii_up.size(0); + for (i = 0; i < loop_ub; i++) { + x[ii_up[i] - 1] = max_d[ii_up[i] - 1]; + } + } + + // Folding + if (coder::internal::bb_strcmp(Par_info_boundhandling_data, + Par_info_boundhandling_size)) { + // Fold parameter space lower values + b_max_d.set_size(ii_low.size(0)); + loop_ub = ii_low.size(0); + for (i = 0; i < loop_ub; i++) { + b_max_d[i] = max_d[ii_low[i] - 1] - (min_d[ii_low[i] - 1] - x[ii_low[i] + - 1]); + } + + loop_ub = b_max_d.size(0); + for (i = 0; i < loop_ub; i++) { + x[ii_low[i] - 1] = b_max_d[i]; + } + + // Fold parameter space upper values + b_max_d.set_size(ii_up.size(0)); + loop_ub = ii_up.size(0); + for (i = 0; i < loop_ub; i++) { + b_max_d[i] = min_d[ii_up[i] - 1] + (x[ii_up[i] - 1] - max_d[ii_up[i] - 1]); + } + + loop_ub = b_max_d.size(0); + for (i = 0; i < loop_ub; i++) { + x[ii_up[i] - 1] = b_max_d[i]; + } + } + + // Now double check in case elements are still out of bound -- this is + // theoretically possible if values are very small or large + // Now double check if all elements are within bounds + if ((x.size(0) == min_d.size(0)) && (x.size(1) == min_d.size(1))) { + b_x.set_size(x.size(0), x.size(1)); + loop_ub = x.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = x.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + b_x[i1 + b_x.size(0) * i] = (x[i1 + x.size(0) * i] < min_d[i1 + + min_d.size(0) * i]); + } + } + + coder::c_eml_find(b_x, ii_up); + } else { + c_binary_expand_op(ii_up, x, min_d); + } + + ii_low.set_size(ii_up.size(0)); + loop_ub = ii_up.size(0); + for (i = 0; i < loop_ub; i++) { + ii_low[i] = ii_up[i]; + } + + b_ii_low[0] = ii_low.size(0); + b_ii_low[1] = 1.0; + coder::b_rand(b_ii_low, b_max_d); + if (b_max_d.size(0) == 1) { + i = ii_low.size(0); + } else { + i = b_max_d.size(0); + } + + if ((b_max_d.size(0) == ii_low.size(0)) && (ii_low.size(0) == i)) { + loop_ub = ii_low.size(0); + for (i = 0; i < loop_ub; i++) { + x[ii_low[i] - 1] = min_d[ii_low[i] - 1] + b_max_d[i] * (max_d[ii_low[i] + - 1] - min_d[ii_low[i] - 1]); + } + } else { + binary_expand_op(x, ii_low, min_d, b_max_d, max_d); + } + + if ((x.size(0) == max_d.size(0)) && (x.size(1) == max_d.size(1))) { + b_x.set_size(x.size(0), x.size(1)); + loop_ub = x.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = x.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + b_x[i1 + b_x.size(0) * i] = (x[i1 + x.size(0) * i] > max_d[i1 + + max_d.size(0) * i]); + } + } + + coder::c_eml_find(b_x, ii_up); + } else { + binary_expand_op(ii_up, x, max_d); + } + + b_ii_low[0] = ii_up.size(0); + b_ii_low[1] = 1.0; + coder::b_rand(b_ii_low, b_max_d); + if (b_max_d.size(0) == 1) { + i = ii_up.size(0); + } else { + i = b_max_d.size(0); + } + + if ((b_max_d.size(0) == ii_up.size(0)) && (ii_up.size(0) == i)) { + loop_ub = ii_up.size(0); + for (i = 0; i < loop_ub; i++) { + x[ii_up[i] - 1] = min_d[ii_up[i] - 1] + b_max_d[i] * (max_d[ii_up[i] - 1] + - min_d[ii_up[i] - 1]); + } + } else { + binary_expand_op(x, ii_up, min_d, b_max_d, max_d); + } + } +} + +// End of code generation (boundaryHandling.cpp) diff --git a/RAT/boundaryHandling.h b/RAT/boundaryHandling.h new file mode 100644 index 00000000..91869c69 --- /dev/null +++ b/RAT/boundaryHandling.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// boundaryHandling.h +// +// Code generation for function 'boundaryHandling' +// +#ifndef BOUNDARYHANDLING_H +#define BOUNDARYHANDLING_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void boundaryHandling(::coder::array &x, const ::coder::array< + real_T, 2U> &Par_info_min, const ::coder::array &Par_info_max, const char_T + Par_info_boundhandling_data[], const int32_T + Par_info_boundhandling_size[2]); +} + +#endif + +// End of code generation (boundaryHandling.h) diff --git a/RAT/bsearch.cpp b/RAT/bsearch.cpp index 9298e8e0..55e620a4 100644 --- a/RAT/bsearch.cpp +++ b/RAT/bsearch.cpp @@ -20,6 +20,32 @@ namespace RAT { namespace internal { + int32_T b_bsearch(const real_T x_data[], real_T xi) + { + int32_T high_i; + int32_T low_ip1; + int32_T n; + n = 1; + low_ip1 = 2; + high_i = 4; + while (high_i > low_ip1) { + int32_T mid_i; + mid_i = (n >> 1) + (high_i >> 1); + if (((n & 1) == 1) && ((high_i & 1) == 1)) { + mid_i++; + } + + if (xi >= x_data[mid_i - 1]) { + n = mid_i; + low_ip1 = mid_i + 1; + } else { + high_i = mid_i; + } + } + + return n; + } + int32_T b_bsearch(const ::coder::array &x, real_T xi) { int32_T high_i; @@ -45,6 +71,17 @@ namespace RAT return n; } + + int32_T c_bsearch(const real_T x[3], real_T xi) + { + int32_T n; + n = 1; + if (xi >= x[1]) { + n = 2; + } + + return n; + } } } } diff --git a/RAT/bsearch.h b/RAT/bsearch.h index 65fddb75..37316d8e 100644 --- a/RAT/bsearch.h +++ b/RAT/bsearch.h @@ -23,7 +23,9 @@ namespace RAT { namespace internal { + int32_T b_bsearch(const real_T x_data[], real_T xi); int32_T b_bsearch(const ::coder::array &x, real_T xi); + int32_T c_bsearch(const real_T x[3], real_T xi); } } } diff --git a/RAT/bsxfun.cpp b/RAT/bsxfun.cpp new file mode 100644 index 00000000..f42b9d9c --- /dev/null +++ b/RAT/bsxfun.cpp @@ -0,0 +1,372 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// bsxfun.cpp +// +// Code generation for function 'bsxfun' +// + +// Include files +#include "bsxfun.h" +#include "rescale.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_bsxfun(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c) + { + int32_T acoef; + int32_T csz_idx_0; + int32_T u0; + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + csz_idx_0 = a.size(0); + } else if (a.size(0) == 1) { + csz_idx_0 = b.size(0); + } else if (a.size(0) == b.size(0)) { + csz_idx_0 = a.size(0); + } else { + csz_idx_0 = acoef; + } + + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + acoef = a.size(0); + } else if (a.size(0) == 1) { + acoef = b.size(0); + } else if (a.size(0) == b.size(0)) { + acoef = a.size(0); + } + + c.set_size(acoef); + if (csz_idx_0 != 0) { + int32_T bcoef; + acoef = (a.size(0) != 1); + bcoef = (b.size(0) != 1); + u0 = csz_idx_0 - 1; + for (csz_idx_0 = 0; csz_idx_0 <= u0; csz_idx_0++) { + c[csz_idx_0] = rescale_anonFcn2(a[acoef * csz_idx_0], b[bcoef * + csz_idx_0]); + } + } + } + + void b_bsxfun(const ::coder::array &a, ::coder::array + &c) + { + c.set_size(a.size(0)); + if (a.size(0) != 0) { + int32_T acoef; + int32_T i; + acoef = (a.size(0) != 1); + i = a.size(0) - 1; + for (int32_T k{0}; k <= i; k++) { + real_T x; + x = a[acoef * k]; + if ((!std::isnan(x)) && (x < 0.0)) { + c[k] = 0.0; + } else { + c[k] = x; + } + } + } + } + + void bsxfun(const ::coder::array &a, const ::coder::array &b, ::coder::array &c) + { + int32_T acoef; + int32_T csz_idx_0; + int32_T u0; + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + csz_idx_0 = a.size(0); + } else if (a.size(0) == 1) { + csz_idx_0 = b.size(0); + } else if (a.size(0) == b.size(0)) { + csz_idx_0 = a.size(0); + } else { + csz_idx_0 = acoef; + } + + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + acoef = a.size(0); + } else if (a.size(0) == 1) { + acoef = b.size(0); + } else if (a.size(0) == b.size(0)) { + acoef = a.size(0); + } + + c.set_size(acoef); + if (csz_idx_0 != 0) { + int32_T bcoef; + acoef = (a.size(0) != 1); + bcoef = (b.size(0) != 1); + u0 = csz_idx_0 - 1; + for (csz_idx_0 = 0; csz_idx_0 <= u0; csz_idx_0++) { + c[csz_idx_0] = rescale_anonFcn1(a[acoef * csz_idx_0], b[bcoef * + csz_idx_0]); + } + } + } + + void bsxfun(const ::coder::array &a, ::coder::array + &c) + { + c.set_size(a.size(0)); + if (a.size(0) != 0) { + int32_T acoef; + int32_T i; + acoef = (a.size(0) != 1); + i = a.size(0) - 1; + for (int32_T k{0}; k <= i; k++) { + c[k] = a[acoef * k]; + } + } + } + + void c_bsxfun(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c) + { + int32_T acoef; + int32_T csz_idx_0; + int32_T u0; + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + csz_idx_0 = a.size(0); + } else if (a.size(0) == 1) { + csz_idx_0 = b.size(0); + } else if (a.size(0) == b.size(0)) { + csz_idx_0 = a.size(0); + } else { + csz_idx_0 = acoef; + } + + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + acoef = a.size(0); + } else if (a.size(0) == 1) { + acoef = b.size(0); + } else if (a.size(0) == b.size(0)) { + acoef = a.size(0); + } + + c.set_size(acoef); + if (csz_idx_0 != 0) { + int32_T bcoef; + acoef = (a.size(0) != 1); + bcoef = (b.size(0) != 1); + u0 = csz_idx_0 - 1; + for (csz_idx_0 = 0; csz_idx_0 <= u0; csz_idx_0++) { + c[csz_idx_0] = std::fmax(a[acoef * csz_idx_0], b[bcoef * csz_idx_0]); + } + } + } + + void c_bsxfun(const ::coder::array &a, ::coder::array + &c) + { + c.set_size(a.size(0)); + if (a.size(0) != 0) { + int32_T acoef; + int32_T i; + acoef = (a.size(0) != 1); + i = a.size(0) - 1; + for (int32_T k{0}; k <= i; k++) { + real_T x; + x = a[acoef * k]; + if ((!std::isnan(x)) && (x > 1.0)) { + c[k] = 1.0; + } else { + c[k] = x; + } + } + } + } + + void d_bsxfun(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c) + { + int32_T acoef; + int32_T csz_idx_0; + int32_T u0; + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + csz_idx_0 = a.size(0); + } else if (a.size(0) == 1) { + csz_idx_0 = b.size(0); + } else if (a.size(0) == b.size(0)) { + csz_idx_0 = a.size(0); + } else { + csz_idx_0 = acoef; + } + + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + acoef = a.size(0); + } else if (a.size(0) == 1) { + acoef = b.size(0); + } else if (a.size(0) == b.size(0)) { + acoef = a.size(0); + } + + c.set_size(acoef); + if (csz_idx_0 != 0) { + int32_T bcoef; + acoef = (a.size(0) != 1); + bcoef = (b.size(0) != 1); + u0 = csz_idx_0 - 1; + for (csz_idx_0 = 0; csz_idx_0 <= u0; csz_idx_0++) { + c[csz_idx_0] = a[acoef * csz_idx_0] - b[bcoef * csz_idx_0]; + } + } + } + + void e_bsxfun(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c) + { + int32_T acoef; + int32_T csz_idx_0; + int32_T u0; + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + csz_idx_0 = a.size(0); + } else if (a.size(0) == 1) { + csz_idx_0 = b.size(0); + } else if (a.size(0) == b.size(0)) { + csz_idx_0 = a.size(0); + } else { + csz_idx_0 = acoef; + } + + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + acoef = a.size(0); + } else if (a.size(0) == 1) { + acoef = b.size(0); + } else if (a.size(0) == b.size(0)) { + acoef = a.size(0); + } + + c.set_size(acoef); + if (csz_idx_0 != 0) { + int32_T bcoef; + acoef = (a.size(0) != 1); + bcoef = (b.size(0) != 1); + u0 = csz_idx_0 - 1; + for (csz_idx_0 = 0; csz_idx_0 <= u0; csz_idx_0++) { + c[csz_idx_0] = a[acoef * csz_idx_0] * b[bcoef * csz_idx_0]; + } + } + } + + void f_bsxfun(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c) + { + int32_T acoef; + int32_T csz_idx_0; + int32_T u0; + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + csz_idx_0 = a.size(0); + } else if (a.size(0) == 1) { + csz_idx_0 = b.size(0); + } else if (a.size(0) == b.size(0)) { + csz_idx_0 = a.size(0); + } else { + csz_idx_0 = acoef; + } + + u0 = b.size(0); + acoef = a.size(0); + if (u0 <= acoef) { + acoef = u0; + } + + if (b.size(0) == 1) { + acoef = a.size(0); + } else if (a.size(0) == 1) { + acoef = b.size(0); + } else if (a.size(0) == b.size(0)) { + acoef = a.size(0); + } + + c.set_size(acoef); + if (csz_idx_0 != 0) { + int32_T bcoef; + acoef = (a.size(0) != 1); + bcoef = (b.size(0) != 1); + u0 = csz_idx_0 - 1; + for (csz_idx_0 = 0; csz_idx_0 <= u0; csz_idx_0++) { + c[csz_idx_0] = a[acoef * csz_idx_0] + b[bcoef * csz_idx_0]; + } + } + } + } +} + +// End of code generation (bsxfun.cpp) diff --git a/RAT/bsxfun.h b/RAT/bsxfun.h new file mode 100644 index 00000000..5c9b7852 --- /dev/null +++ b/RAT/bsxfun.h @@ -0,0 +1,47 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// bsxfun.h +// +// Code generation for function 'bsxfun' +// +#ifndef BSXFUN_H +#define BSXFUN_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_bsxfun(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c); + void b_bsxfun(const ::coder::array &a, ::coder::array + &c); + void bsxfun(const ::coder::array &a, const ::coder::array &b, ::coder::array &c); + void bsxfun(const ::coder::array &a, ::coder::array + &c); + void c_bsxfun(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c); + void c_bsxfun(const ::coder::array &a, ::coder::array + &c); + void d_bsxfun(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c); + void e_bsxfun(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c); + void f_bsxfun(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c); + } +} + +#endif + +// End of code generation (bsxfun.h) diff --git a/RAT/calcDensity.cpp b/RAT/calcDensity.cpp new file mode 100644 index 00000000..432c1f3a --- /dev/null +++ b/RAT/calcDensity.cpp @@ -0,0 +1,165 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calcDensity.cpp +// +// Code generation for function 'calcDensity' +// + +// Include files +#include "calcDensity.h" +#include "RATMain_types.h" +#include "rt_nonfinite.h" +#include "scaledGaussPrior.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void calcDensity(const ::coder::array &x, const ::coder::array< + real_T, 2U> &fx, const struct14_T *DREAMPar, const ::coder:: + array &ratInputs_problemDef_fitLimits, const :: + coder::array &ratInputs_priors, ::coder::array< + real_T, 1U> &log_L, ::coder::array &log_PR) + { + ::coder::array PR; + ::coder::array b_x; + int32_T i; + int32_T loop_ub; + int32_T loop_ub_tmp; + + // Now calculate the likelihood (not used) and log-likelihood (used) + // --------------------------------------- + // For RAT, all the calculations are of the mvnpdf type, so remove the + // other options. + // ------------------------------------ AVH + // % If number of measurements larger than 0 --> simulation + // if Meas_info.N > 0 + // + // % Initialize "res" (residual matrix) + // res = NaN(Meas_info.N,DREAMPar.N); + // + // % Loop over each model realization + // for ii = 1 : DREAMPar.N + // + // % We now calculate the error residual + // res(:,ii) = (Meas_info.Y(:) - fx(1:Meas_info.N,ii)); + // + // end + // + // else + // + // % Do nothing, fx is a density or log-density returned by the PDF handle + // + // end + // ----------------------- Calculate log-prior ---------------------------- + // No ABC --> regular priors (pdfs) + // if ~DREAMPar.ABC + // + // % Calculate the log-prior + // if isfield(Par_info,'prior_marginal') + // + // % Compute prior densities for each parameter in each sequence + // for qq = 1 : DREAMPar.d + // for zz = 1 : DREAMPar.N + // % Compute prior density of proposal + // PR(zz,qq) = max ( eval(char(strrep(Par_info.prior_marginal(qq),'rnd(','pdf(x(zz,qq),'))) , 1e-299 ); + // end + // end + // + // % Take the log of the densities and their sum + // log_PR = sum ( log ( PR ) , 2 ); + // + // elseif isfield(Par_info,'mvnpdf') + // RAT specific prior funtion (mvnpdf) + loop_ub_tmp = static_cast(DREAMPar->N); + PR.set_size(1, loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { + PR[i] = 0.0; + } + + if (loop_ub_tmp - 1 >= 0) { + loop_ub = x.size(1); + } + + // Take log of any non-zero values.. + log_PR.set_size(loop_ub_tmp); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + // Loop over all the chains.. + b_x.set_size(1, x.size(1)); + for (i = 0; i < loop_ub; i++) { + b_x[i] = x[b_i + x.size(0) * i]; + } + + PR[b_i] = scaledGaussPrior(b_x, ratInputs_problemDef_fitLimits, + ratInputs_priors); + + // mvnpdf automatically goes over all pars + log_PR[b_i] = 0.0; + } + + i = PR.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T d; + d = PR[b_i]; + if (d != 0.0) { + log_PR[b_i] = d; + + // log(PR(i)); % Does it even need to be log? + } else { + // Otherwise keep the zero values + log_PR[b_i] = 0.0; + } + } + + // log_PR = sum(log_PR(:)); % Enforce column vector + // else + // No use of prior --> set log-prior to zero (no effect in Metropolis) + // log_PR = zeros ( DREAMPar.N , 1 ); + // + // end + // + // + // else + // + // Diagnostic Bayes --> if summary metric is defined as prior + // if isfield(DREAMPar,'prior_handle') + // + // Evaluate distance between observed and simulated summary metrics + // for ii = 1 : DREAMPar.N + // + // Calculate summary metrics for "fx" + // S_sim = DREAMPar.prior_handle ( fx(:,ii) ); + // + // Now calculate log-density (not a true log-density! - but does not matter) + // log_PR(ii,1) = max ( abs ( Meas_info.S(:) - S_sim(:) ) ); + // + // end + // + // Regular ABC with summary metrics as likelihood function + // else + // + // log_PR = zeros ( DREAMPar.N , 1 ); + // + // end + // + // end + // --------------------- End Calculate log-prior --------------------------- + // -------------------- Calculate log-likelihood --------------------------- + // Loop over each model realization and calculate log-likelihood of each fx + log_L.set_size(loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { + log_L[i] = 0.0; + } + + for (int32_T ii{0}; ii < loop_ub_tmp; ii++) { + log_L[ii] = fx[ii]; + } + + // ------------------ End Calculate log-likelihood ------------------------- + } +} + +// End of code generation (calcDensity.cpp) diff --git a/RAT/calcDensity.h b/RAT/calcDensity.h new file mode 100644 index 00000000..18d66d09 --- /dev/null +++ b/RAT/calcDensity.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calcDensity.h +// +// Code generation for function 'calcDensity' +// +#ifndef CALCDENSITY_H +#define CALCDENSITY_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct14_T; +} + +// Function Declarations +namespace RAT +{ + void calcDensity(const ::coder::array &x, const ::coder::array< + real_T, 2U> &fx, const struct14_T *DREAMPar, const ::coder:: + array &ratInputs_problemDef_fitLimits, const :: + coder::array &ratInputs_priors, ::coder::array< + real_T, 1U> &log_L, ::coder::array &log_PR); +} + +#endif + +// End of code generation (calcDensity.h) diff --git a/RAT/calcEllipsoid.cpp b/RAT/calcEllipsoid.cpp new file mode 100644 index 00000000..5db84c27 --- /dev/null +++ b/RAT/calcEllipsoid.cpp @@ -0,0 +1,220 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calcEllipsoid.cpp +// +// Code generation for function 'calcEllipsoid' +// + +// Include files +#include "calcEllipsoid.h" +#include "RATMain_data.h" +#include "RATMain_rtwutil.h" +#include "cov.h" +#include "det.h" +#include "eml_mtimes_helper.h" +#include "gamma.h" +#include "ifWhileCond.h" +#include "matrix_to_integer_power.h" +#include "mean.h" +#include "mrdivide_helper.h" +#include "mtimes.h" +#include "rcond.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include +#include + +// Function Definitions +namespace RAT +{ + void calcEllipsoid(const ::coder::array &u, real_T VS, ::coder:: + array &B, ::coder::array &mu, + real_T VE_data[], int32_T VE_size[2], real_T *flag) + { + ::coder::array C; + ::coder::array b_u; + ::coder::array r; + ::coder::array y; + ::coder::array c_y_data; + ::coder::array d_y_data; + real_T b; + real_T y_data; + int32_T y_size[2]; + int32_T b_flag; + boolean_T b_y_data; + + // + // calculate properties of ellipsoid given a set of points u + // + // Inputs: + // u: Nxndims array where N is the number point and ndims is the + // number of dimensions + // VS: minimum volume that the bounding ellipsoid should have + // + // Outputs: + // B: bounding matrix for ellipsoid including scale factor + // for mininimum volume + // mu: centroid + // VE: volume of ellipsoid + // flag: = 1 if number of points too small or bounding matrix + // has bad condition number; otherwise = 0 + // + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // default values + B.set_size(0, 0); + mu.set_size(0, 0); + VE_size[0] = 0; + VE_size[1] = 0; + b_flag = 0; + + // extract number of points and number of dimensions + // check that total number of points is large enough + if (static_cast(u.size(0)) < static_cast(u.size(1)) + 1U) + { + if (DEBUG != 0.0) { + printf("number of samples too small to calculate bounding matrix for ellipsoid\n"); + fflush(stdout); + } + + b_flag = 1; + } else { + real_T x; + + // constant factor for volume of ellipsoid + b = static_cast(u.size(1)) / 2.0 + 1.0; + coder::b_gamma(&b); + + // calculate covariance matrix and centroid + coder::cov(u, C); + coder::mean(u, mu); + + // check condition number of C (eps = 2.2204e-16) + x = coder::rcond(C); + if ((x < 2.2204460492503131E-16) || std::isnan(x)) { + if (DEBUG != 0.0) { + printf("bad condition number!\n"); + fflush(stdout); + } + + b_flag = 1; + } else { + real_T fB; + real_T fV_data; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + + // find scale factor for bounding ellipsoid E + fB = 0.0; + + // coder.varsize('fB'); + i = u.size(0); + loop_ub = u.size(1); + b_loop_ub = u.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + int32_T c_loop_ub; + if (u.size(1) == mu.size(1)) { + b_u.set_size(1, u.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_u[b_u.size(0) * i1] = u[b_i + u.size(0) * i1] - mu[mu.size(0) * + i1]; + } + + coder::internal::mrdiv(b_u, C, r); + } else { + binary_expand_op(r, u, b_i, mu, C); + } + + if (u.size(1) == mu.size(1)) { + b_u.set_size(1, u.size(1)); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + b_u[b_u.size(0) * i1] = u[b_i + u.size(0) * i1] - mu[mu.size(0) * + i1]; + } + + coder::internal::blas::mtimes(r, b_u, (real_T *)&y_data, y_size); + } else { + binary_expand_op((real_T *)&y_data, y_size, r, u, b_i, mu); + } + + c_loop_ub = y_size[1]; + for (int32_T i1{0}; i1 < c_loop_ub; i1++) { + int32_T d_loop_ub; + d_loop_ub = y_size[0]; + for (int32_T i2{0}; i2 < d_loop_ub; i2++) { + b_y_data = (y_data > fB); + } + } + + c_y_data.set(&b_y_data, y_size[0], y_size[1]); + if (coder::internal::ifWhileCond(c_y_data)) { + fB = y_data; + } + } + + // calculate volume of bounding ellipsoid E + y.set_size(C.size(0), C.size(1)); + loop_ub = C.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = C.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + y[i1 + y.size(0) * i] = fB * C[i1 + C.size(0) * i]; + } + } + + VE_size[0] = 1; + VE_size[1] = 1; + x = rt_powd_snf(3.1415926535897931, static_cast(u.size(1)) / 2.0) + / b * std::sqrt(coder::det(y)); + VE_data[0] = x; + + // expand volume of bounding ellipsoid to VS if necessary + fV_data = 1.0; + b_y_data = (x < VS); + d_y_data.set(&b_y_data, 1, 1); + if (coder::internal::ifWhileCond(d_y_data)) { + b = 2.0 / static_cast(u.size(1)); + if (std::floor(b) == b) { + x = VS / x; + coder::matrix_to_integer_power((const real_T *)&x, b, (real_T *) + &fV_data, y_size); + } + + VE_size[0] = 1; + VE_size[1] = 1; + VE_data[0] = VS; + } + + // scale C to get bounding matrix B + // Again emphasise the scalar for the inner mutiplication + // matlab error in compiled code..... + // + // Error using eml_mtimes_helper>dynamic_size_checks + // Inner dimensions must agree. Generated code for a general matrix multiplication at this call site. If this should have been a scalar times a variable-size matrix, the + // scalar input must be fixed-size. + // + // Error in eml_mtimes_helper (line 69) + // dynamic_size_checks(a, b, innerDimA, innerDimB); + // + // Error in calcEllipsoid (line 73) + // B = fV * fB * C; + x = fV_data * fB; + B.set_size(C.size(0), C.size(1)); + loop_ub = C.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = C.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + B[i1 + B.size(0) * i] = x * C[i1 + C.size(0) * i]; + } + } + } + } + + *flag = b_flag; + } +} + +// End of code generation (calcEllipsoid.cpp) diff --git a/RAT/calcEllipsoid.h b/RAT/calcEllipsoid.h new file mode 100644 index 00000000..4a95dce5 --- /dev/null +++ b/RAT/calcEllipsoid.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calcEllipsoid.h +// +// Code generation for function 'calcEllipsoid' +// +#ifndef CALCELLIPSOID_H +#define CALCELLIPSOID_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void calcEllipsoid(const ::coder::array &u, real_T VS, ::coder:: + array &B, ::coder::array &mu, + real_T VE_data[], int32_T VE_size[2], real_T *flag); +} + +#endif + +// End of code generation (calcEllipsoid.h) diff --git a/RAT/calcProposal.cpp b/RAT/calcProposal.cpp new file mode 100644 index 00000000..8c26288e --- /dev/null +++ b/RAT/calcProposal.cpp @@ -0,0 +1,580 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calcProposal.cpp +// +// Code generation for function 'calcProposal' +// + +// Include files +#include "calcProposal.h" +#include "RATMain_types.h" +#include "blockedSummation.h" +#include "boundaryHandling.h" +#include "combineVectorElements.h" +#include "find.h" +#include "rand.h" +#include "randn.h" +#include "randperm.h" +#include "randsample.h" +#include "rt_nonfinite.h" +#include "sort.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, int32_T in2, + const ::coder::array &in3, const ::coder::array &in4, + real_T in5, const ::coder::array &in6, const ::coder::array< + real_T, 2U> &in7); + static void binary_expand_op(::coder::array &in1, int32_T in2, + const ::coder::array &in4, int32_T in5, const ::coder::array< + real_T, 2U> &in6, const ::coder::array &in7, int32_T in8); + static void plus(::coder::array &in1, const ::coder::array &in2, const ::coder::array &in3); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, int32_T in2, + const ::coder::array &in3, const ::coder::array &in4, + real_T in5, const ::coder::array &in6, const ::coder::array< + real_T, 2U> &in7) + { + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + int32_T stride_2_1; + stride_0_1 = (in3.size(0) != 1); + stride_1_1 = (in6.size(1) != 1); + stride_2_1 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + if (in6.size(1) == 1) { + loop_ub = in3.size(0); + } else { + loop_ub = in6.size(1); + } + } else { + loop_ub = in3.size(0); + } + + for (int32_T i{0}; i < loop_ub; i++) { + in1[in2 + in1.size(0) * (static_cast(in3[i]) - 1)] = (in4[in2 + + in4.size(0) * (static_cast(in3[i * stride_0_1]) - 1)] + 1.0) * + in5 * in6[i * stride_1_1] + in7[in2 + in7.size(0) * (static_cast + (in3[i * stride_2_1]) - 1)]; + } + } + + static void binary_expand_op(::coder::array &in1, int32_T in2, + const ::coder::array &in4, int32_T in5, const ::coder::array< + real_T, 2U> &in6, const ::coder::array &in7, int32_T in8) + { + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + int32_T stride_2_1; + stride_0_1 = (in5 + 1 != 1); + stride_1_1 = (in6.size(1) != 1); + stride_2_1 = (in8 + 1 != 1); + if (in8 + 1 == 1) { + if (in6.size(1) == 1) { + loop_ub = in5 + 1; + } else { + loop_ub = in6.size(1); + } + } else { + loop_ub = in8 + 1; + } + + for (int32_T i{0}; i < loop_ub; i++) { + in1[in2 + in1.size(0) * i] = (in4[in2 + in4.size(0) * (i * stride_0_1)] + + 1.0) * in6[i * stride_1_1] + in7[in2 + in7.size(0) * (i * stride_2_1)]; + } + } + + static void plus(::coder::array &in1, const ::coder::array &in2, const ::coder::array &in3) + { + int32_T aux_0_1; + int32_T aux_1_1; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_0_1; + int32_T stride_1_0; + int32_T stride_1_1; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + if (in3.size(1) == 1) { + i1 = in2.size(1); + } else { + i1 = in3.size(1); + } + + in1.set_size(i, i1); + stride_0_0 = (in2.size(0) != 1); + stride_0_1 = (in2.size(1) != 1); + stride_1_0 = (in3.size(0) != 1); + stride_1_1 = (in3.size(1) != 1); + aux_0_1 = 0; + aux_1_1 = 0; + if (in3.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(1); + } + + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + i1 = in3.size(0); + if (i1 == 1) { + b_loop_ub = in2.size(0); + } else { + b_loop_ub = i1; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + in1[i1 + in1.size(0) * i] = in2[i1 * stride_0_0 + in2.size(0) * aux_0_1] + + in3[i1 * stride_1_0 + in3.size(0) * aux_1_1]; + } + + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + } + + void calcProposal(const ::coder::array &X, real_T CR_data[], const + struct14_T *DREAMPar, const ::coder::array + &Table_gamma, const ::coder::array &Par_info_min, + const ::coder::array &Par_info_max, const char_T + Par_info_boundhandling_data[], const int32_T + Par_info_boundhandling_size[2], ::coder::array + &x_new) + { + ::coder::array A; + ::coder::array a; + ::coder::array b; + ::coder::array b_gamma; + ::coder::array dx; + ::coder::array eps; + ::coder::array r; + ::coder::array r1; + ::coder::array r4; + ::coder::array r5; + ::coder::array r6; + ::coder::array rnd_cr; + ::coder::array rnd_jump; + ::coder::array DE_pairs; + ::coder::array r3; + ::coder::array draw; + ::coder::array r2; + ::coder::array b_rnd_cr; + int32_T b_loop_ub; + int32_T b_loop_ub_tmp; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T loop_ub_tmp; + + // Calculate candidate points using discrete proposal distribution + // % % % Calculate the ergodicity perturbation + // % % eps = DREAMPar.zeta * randn(DREAMPar.N,DREAMPar.d); + // % % + // % % % Determine which sequences to evolve with what DE strategy + // % % DE_pairs = randsample( [1:DREAMPar.delta ] , DREAMPar.N , true , [ 1/DREAMPar.delta*ones(1,DREAMPar.delta) ])'; + // % % + // % % % Generate series of permutations of chains + // % % [dummy,tt] = sort(rand(DREAMPar.N-1,DREAMPar.N)); + // % % + // % % % Generate uniform random numbers for each chain to determine which dimension to update + // % % D = rand(DREAMPar.N,DREAMPar.d); + // % % + // % % % Ergodicity for each individual chain + // % % noise_x = DREAMPar.lambda * (2 * rand(DREAMPar.N,DREAMPar.d) - 1); + // % % + // % % % Initialize the delta update to zero + // % % delta_x = zeros(DREAMPar.N,DREAMPar.d); + // % % + // % % % Each chain evolves using information from other chains to create offspring + // % % for qq = 1:DREAMPar.N, + // % % + // % % % Define ii and remove current member as an option + // % % ii = ones(DREAMPar.N,1); ii(qq) = 0; idx = find(ii > 0); + // % % + // % % % randomly select two members of ii that have value == 1 + // % % rr = idx(tt(1:2*DE_pairs(qq,1),qq)); + // % % + // % % % --- WHICH DIMENSIONS TO UPDATE? DO SOMETHING WITH CROSSOVER ---- + // % % [i] = find(D(qq,1:DREAMPar.d) > (1-CR(qq,1))); + // % % + // % % % Update at least one dimension + // % % if isempty(i), i = randperm(DREAMPar.d); i = i(1); end; + // % % % ---------------------------------------------------------------- + // % % + // % % % Determine the associated JumpRate and compute the jump + // % % if (rand < (1 - DREAMPar.pJumpRate_one)), + // % % + // % % % % Now determine gamma, the jump factor + // % % % if ~DREAMPar.ABC + // % % % + // % % % Select the JumpRate (dependent of NrDim and number of pairs) + // % % NrDim = size(i,2); JumpRate = Table_gamma(NrDim,DE_pairs(qq,1)); + // % % + // % % % else + // % % % + // % % % % Turner (2012) paper -- CU[0.5,1] but needs scaling if + // % % % % more than 1 pair is used! + // % % % JumpRate = (0.5 + rand/2) * sqrt(1/DREAMPar.delta); + // % % + // % % % end; + // % % + // % % % Produce the difference of the pairs used for population evolution + // % % delta = sum(X(rr(1:DE_pairs(qq,1)),1:DREAMPar.d) - X(rr(DE_pairs(qq,1)+1:2*DE_pairs(qq,1)),1:DREAMPar.d),1); + // % % + // % % % Then fill update the dimension + // % % delta_x(qq,i) = (1 + noise_x(qq,i)) * JumpRate.*delta(1,i); + // % % + // % % else + // % % + // % % % Set the JumpRate to 1 and overwrite CR and DE_pairs + // % % JumpRate = 1; CR(qq,1) = -1; + // % % + // % % % Compute delta from one pair + // % % delta = X(rr(1),1:DREAMPar.d) - X(rr(2),1:DREAMPar.d); + // % % + // % % % Now jumprate to facilitate jumping from one mode to the other in all dimensions + // % % delta_x(qq,1:DREAMPar.d) = JumpRate * delta; + // % % + // % % end; + // % % + // % % % Check this line to avoid that jump = 0 and x_new is similar to X + // % % if (sum(delta_x(qq,1:DREAMPar.d).^2,2) == 0), + // % % + // % % % Compute the Cholesky Decomposition of X + // % % R = (2.38/sqrt(DREAMPar.d)) * chol(cov(X(1:end,1:DREAMPar.d)) + 1e-5*eye(DREAMPar.d)); + // % % + // % % % Generate jump using multinormal distribution + // % % delta_x(qq,1:DREAMPar.d) = randn(1,DREAMPar.d) * R; + // % % disp('hello'); + // % % end; + // % % + // % % end; + // % % + // % % % Generate candidate points by perturbing the current X values with jump and eps + // % % x_new = X + delta_x + eps; + // % % + // % % % If specified do boundary handling ( "Bound","Reflect","Fold") + // % % if isfield(Par_info,'boundhandling'), + // % % [x_new] = BoundaryHandling(x_new,Par_info,Par_info.boundhandling); + // % % end; + // % % + // ################################################## + // Calculate the ergodicity perturbation + coder::randn(DREAMPar->N, DREAMPar->d, b); + eps.set_size(b.size(0), b.size(1)); + loop_ub = b.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = b.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + eps[i1 + eps.size(0) * i] = 1.0E-12 * b[i1 + b.size(0) * i]; + } + } + + real_T tmp_data[3]; + + // Determine how many chain pairs to use for each individual chain + r.set_size(1, 3); + r[0] = 1.0; + tmp_data[0] = 0.33333333333333331; + r[1] = 2.0; + tmp_data[1] = 0.33333333333333331; + r[2] = 3.0; + tmp_data[2] = 0.33333333333333331; + coder::randsample((const real_T *)r.data(), DREAMPar->N, tmp_data, r1); + DE_pairs.set_size(r1.size(1)); + loop_ub = r1.size(1); + for (i = 0; i < loop_ub; i++) { + DE_pairs[i] = r1[i]; + } + + // Generate uniform random numbers for each chain to determine which dimension to update + coder::b_rand(DREAMPar->N, DREAMPar->d, rnd_cr); + + // Ergodicity for each individual chain + coder::b_rand(DREAMPar->N, DREAMPar->d, b); + rnd_jump.set_size(b.size(0), b.size(1)); + loop_ub = b.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = b.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + rnd_jump[i1 + rnd_jump.size(0) * i] = DREAMPar->lambda * (2.0 * b[i1 + + b.size(0) * i] - 1.0); + } + } + + // rnd_jump = DREAMPar.lambda * (2 * rand(DREAMPar.N,1) - 1); + // Randomly permute numbers [1,...,N-1] N times + coder::b_rand(DREAMPar->N - 1.0, DREAMPar->N, b); + coder::internal::b_sort(b, draw); + + // Set jump vectors equal to zero + loop_ub_tmp = static_cast(DREAMPar->N); + b_loop_ub_tmp = static_cast(DREAMPar->d); + dx.set_size(loop_ub_tmp, b_loop_ub_tmp); + for (i = 0; i < b_loop_ub_tmp; i++) { + for (i1 = 0; i1 < loop_ub_tmp; i1++) { + dx[i1 + dx.size(0) * i] = 0.0; + } + } + + real_T b_dv[2]; + + // Determine when jumprate is 1 + b_dv[0] = 1.0 - DREAMPar->pUnitGamma; + b_dv[1] = DREAMPar->pUnitGamma; + coder::randsample(DREAMPar->N, b_dv, b_gamma); + + // Create N proposals + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + real_T r2_data[6]; + real_T r1_data[3]; + real_T CR; + int32_T D; + int32_T i2; + + // Derive vector r1 + b_loop_ub_tmp = static_cast(DE_pairs[b_i]); + for (i = 0; i < b_loop_ub_tmp; i++) { + r1_data[i] = DREAMPar->R[b_i + DREAMPar->R.size(0) * (draw[i + draw.size + (0) * b_i] - 1)]; + } + + // Derive vector r2 + CR = 2.0 * DE_pairs[b_i]; + if (DE_pairs[b_i] + 1.0 > CR) { + i = 0; + i1 = 0; + } else { + i = static_cast(DE_pairs[b_i] + 1.0) - 1; + i1 = static_cast(CR); + } + + loop_ub = i1 - i; + for (i2 = 0; i2 < loop_ub; i2++) { + r2_data[i2] = DREAMPar->R[b_i + DREAMPar->R.size(0) * (draw[(i + i2) + + draw.size(0) * b_i] - 1)]; + } + + // Derive subset A with dimensions to sample + if (DREAMPar->d < 1.0) { + b_loop_ub = 0; + } else { + b_loop_ub = static_cast(DREAMPar->d); + } + + CR = CR_data[b_i]; + b_rnd_cr.set_size(1, b_loop_ub); + for (i2 = 0; i2 < b_loop_ub; i2++) { + b_rnd_cr[i2] = (rnd_cr[b_i + rnd_cr.size(0) * i2] < CR); + } + + coder::d_eml_find(b_rnd_cr, r2); + A.set_size(1, r2.size(1)); + b_loop_ub = r2.size(1); + for (i2 = 0; i2 < b_loop_ub; i2++) { + A[i2] = r2[i2]; + } + + // How many dimensions are sampled? + D = A.size(1); + + // Make sure that at least one dimension is selected! + if (A.size(1) == 0) { + coder::randperm(DREAMPar->d, a); + A.set_size(1, 1); + A[0] = a[0]; + D = 1; + } + + // Which gamma to use? + if (b_gamma[b_i] == 1.0) { + int32_T c_loop_ub; + int32_T dx_tmp; + + // Calculate direct jump + if (DREAMPar->d < 1.0) { + b_loop_ub = 0; + c_loop_ub = 0; + dx_tmp = 0; + } else { + b_loop_ub = static_cast(DREAMPar->d); + c_loop_ub = static_cast(DREAMPar->d); + dx_tmp = static_cast(DREAMPar->d); + } + + b.set_size(b_loop_ub_tmp, c_loop_ub); + for (i2 = 0; i2 < c_loop_ub; i2++) { + for (int32_T i3{0}; i3 < b_loop_ub_tmp; i3++) { + b[i3 + b.size(0) * i2] = X[(static_cast(r1_data[i3]) + + X.size(0) * i2) - 1]; + } + } + + r5.set_size(loop_ub, dx_tmp); + for (i2 = 0; i2 < dx_tmp; i2++) { + for (int32_T i3{0}; i3 < loop_ub; i3++) { + r5[i3 + r5.size(0) * i2] = X[(static_cast(r2_data[i3]) + + X.size(0) * i2) - 1]; + } + } + + if (DREAMPar->d < 1.0) { + i2 = 0; + } else { + i2 = static_cast(DREAMPar->d); + } + + if ((b.size(0) == r5.size(0)) && (b.size(1) == r5.size(1))) { + loop_ub = b.size(1); + for (int32_T i3{0}; i3 < loop_ub; i3++) { + c_loop_ub = b.size(0); + for (dx_tmp = 0; dx_tmp < c_loop_ub; dx_tmp++) { + b[dx_tmp + b.size(0) * i3] = b[dx_tmp + b.size(0) * i3] - + r5[dx_tmp + r5.size(0) * i3]; + } + } + + if (static_cast(DE_pairs[b_i]) == 1) { + i = i1 - i; + } else { + i = static_cast(DE_pairs[b_i]); + } + + coder::blockedSummation(b, i, r1); + } else { + binary_expand_op(r1, b, r5, DE_pairs, b_i, i1, i); + } + + if (b_loop_ub == 1) { + i = r1.size(1); + } else { + i = b_loop_ub; + } + + if ((b_loop_ub == r1.size(1)) && (i == i2)) { + for (i = 0; i < b_loop_ub; i++) { + dx[b_i + dx.size(0) * i] = (rnd_jump[b_i + rnd_jump.size(0) * i] + + 1.0) * r1[i] + eps[b_i + eps.size(0) * i]; + } + } else { + binary_expand_op(dx, b_i, rnd_jump, b_loop_ub - 1, r1, eps, i2 - 1); + } + + // Set CR to -1 so that this jump does not count for calculation of pCR + CR_data[b_i] = -1.0; + } else { + real_T gamma_D; + + // Unpack jump rate + gamma_D = Table_gamma[(D + Table_gamma.size(0) * (b_loop_ub_tmp - 1)) - + 1]; + + // Calculate jump + r3.set_size(A.size(1)); + b_loop_ub = A.size(1); + for (i2 = 0; i2 < b_loop_ub; i2++) { + r3[i2] = A[i2]; + } + + r4.set_size(b_loop_ub_tmp, r3.size(0)); + b_loop_ub = r3.size(0); + for (i2 = 0; i2 < b_loop_ub; i2++) { + for (int32_T i3{0}; i3 < b_loop_ub_tmp; i3++) { + r4[i3 + r4.size(0) * i2] = X[(static_cast(r1_data[i3]) + + X.size(0) * (static_cast(r3[i2]) - 1)) - 1]; + } + } + + r6.set_size(loop_ub, r3.size(0)); + b_loop_ub = r3.size(0); + for (i2 = 0; i2 < b_loop_ub; i2++) { + for (int32_T i3{0}; i3 < loop_ub; i3++) { + r6[i3 + r6.size(0) * i2] = X[(static_cast(r2_data[i3]) + + X.size(0) * (static_cast(r3[i2]) - 1)) - 1]; + } + } + + if (r4.size(0) == r6.size(0)) { + r5.set_size(r4.size(0), r4.size(1)); + loop_ub = r4.size(1); + b_loop_ub = r4.size(0); + for (i2 = 0; i2 < loop_ub; i2++) { + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r5[i3 + r5.size(0) * i2] = r4[i3 + r4.size(0) * i2] - r6[i3 + + r6.size(0) * i2]; + } + } + + if (static_cast(DE_pairs[b_i]) == 1) { + i = i1 - i; + } else { + i = static_cast(DE_pairs[b_i]); + } + + coder::blockedSummation(r5, i, r1); + } else { + c_binary_expand_op(r1, r4, r6, DE_pairs, b_i, i1, i); + } + + if (r3.size(0) == 1) { + i = r1.size(1); + } else { + i = r3.size(0); + } + + if ((r3.size(0) == r1.size(1)) && (i == r3.size(0))) { + loop_ub = r3.size(0); + for (i = 0; i < loop_ub; i++) { + int32_T dx_tmp; + dx_tmp = static_cast(r3[i]) - 1; + dx[b_i + dx.size(0) * dx_tmp] = (rnd_jump[b_i + rnd_jump.size(0) * + dx_tmp] + 1.0) * gamma_D * r1[i] + eps[b_i + eps.size(0) * dx_tmp]; + } + } else { + binary_expand_op(dx, b_i, r3, rnd_jump, gamma_D, r1, eps); + } + } + } + + // Generate candidate points by perturbing the current X values with jump and eps + // If specified do boundary handling ( "Bound","Reflect","Fold") + if ((X.size(0) == dx.size(0)) && (X.size(1) == dx.size(1))) { + x_new.set_size(X.size(0), X.size(1)); + loop_ub = X.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = X.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + x_new[i1 + x_new.size(0) * i] = X[i1 + X.size(0) * i] + dx[i1 + + dx.size(0) * i]; + } + } + } else { + plus(x_new, X, dx); + } + + boundaryHandling(x_new, Par_info_min, Par_info_max, + Par_info_boundhandling_data, Par_info_boundhandling_size); + } +} + +// End of code generation (calcProposal.cpp) diff --git a/RAT/calcProposal.h b/RAT/calcProposal.h new file mode 100644 index 00000000..27d17918 --- /dev/null +++ b/RAT/calcProposal.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calcProposal.h +// +// Code generation for function 'calcProposal' +// +#ifndef CALCPROPOSAL_H +#define CALCPROPOSAL_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct14_T; +} + +// Function Declarations +namespace RAT +{ + void calcProposal(const ::coder::array &X, real_T CR_data[], const + struct14_T *DREAMPar, const ::coder::array + &Table_gamma, const ::coder::array &Par_info_min, + const ::coder::array &Par_info_max, const char_T + Par_info_boundhandling_data[], const int32_T + Par_info_boundhandling_size[2], ::coder::array + &x_new); +} + +#endif + +// End of code generation (calcProposal.h) diff --git a/RAT/calculate.cpp b/RAT/calculate.cpp new file mode 100644 index 00000000..a8258400 --- /dev/null +++ b/RAT/calculate.cpp @@ -0,0 +1,165 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate.cpp +// +// Code generation for function 'calculate' +// + +// Include files +#include "calculate.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "parallelContrasts.h" +#include "parallelPoints.h" +#include "rt_nonfinite.h" +#include "single.h" +#include "strcmp.h" +#include "sum.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace standardLayers + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array &sldProfiles, :: + coder::array &allLayers) + { + int32_T loop_ub_tmp; + + // Standard layers reflectivity calculation for nonPolarisedTF + // This function decides on parallelisation options before calling the + // relevant version ofthe main standard layers calculation. Parallelisation + // is either over the outer loop ('contrasts'), or the inner loop + // ('points'). The easiest way to do this is to have multiple versions of + // the same core calculation, rather than trying to make the parallel + // for loops conditional (although that would be much neater) There are: + // points - parallelise over points in the reflectivity calculation + // contrasts - parallelise over contrasts (outer for loop) + // Pre-allocation - It's necessary to + // pre-define the types for all the arrays + // for compilation, so do this in this block. + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgroundParams.set_size(loop_ub_tmp); + problem->qzshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->bulkIn.set_size(loop_ub_tmp); + problem->bulkOut.set_size(loop_ub_tmp); + problem->calculations.allChis.set_size(loop_ub_tmp); + problem->resolutionParams.set_size(loop_ub_tmp); + problem->allSubRough.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + simulation.set_size(loop_ub_tmp); + shiftedData.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + sldProfiles.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgroundParams[i] = 0.0; + problem->qzshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->bulkIn[i] = 0.0; + problem->bulkOut[i] = 0.0; + problem->calculations.allChis[i] = 0.0; + problem->resolutionParams[i] = 0.0; + problem->allSubRough[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + simulation[i].f1.set_size(2, 2); + simulation[i].f1[0] = 1.0; + simulation[i].f1[1] = 1.0; + simulation[i].f1[simulation[i].f1.size(0)] = 1.0; + simulation[i].f1[simulation[i].f1.size(0) + 1] = 1.0; + shiftedData[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + sldProfiles[i].f1.set_size(2, 2); + sldProfiles[i].f1[0] = 1.0; + sldProfiles[i].f1[1] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; + allLayers[i].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i] = 1.0; + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; + } + } + + // ------- End type definitions ------------- + if (coder::internal::n_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 0; + } else if (coder::internal::o_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 1; + } else if (coder::internal::p_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + b_single(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, problem->bulkOut, + problem->resolutionParams, problem->calculations.allChis, + reflectivity, simulation, shiftedData, layerSlds, sldProfiles, + allLayers, problem->allSubRough); + break; + + case 1: + parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, + problem->bulkOut, problem->resolutionParams, + problem->calculations.allChis, reflectivity, simulation, + shiftedData, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + + case 2: + c_parallelContrasts(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgroundParams, + problem->qzshifts, problem->scalefactors, + problem->bulkIn, problem->bulkOut, + problem->resolutionParams, + problem->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, sldProfiles, + allLayers, problem->allSubRough); + break; + } + + // Package everything into one array for tidy output + problem->calculations.sumChi = coder::sum(problem->calculations.allChis); + problem->resample.set_size(1, problemDef->resample.size(1)); + loop_ub_tmp = problemDef->resample.size(1); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + problem->resample[b_i] = problemDef->resample[b_i]; + } + } + } + } +} + +// End of code generation (calculate.cpp) diff --git a/RAT/calculate.h b/RAT/calculate.h new file mode 100644 index 00000000..bff39bf2 --- /dev/null +++ b/RAT/calculate.h @@ -0,0 +1,47 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate.h +// +// Code generation for function 'calculate' +// +#ifndef CALCULATE_H +#define CALCULATE_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; + struct struct_T; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace standardLayers + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array &sldProfiles, :: + coder::array &allLayers); + } + } +} + +#endif + +// End of code generation (calculate.h) diff --git a/RAT/calculate1.cpp b/RAT/calculate1.cpp new file mode 100644 index 00000000..1d19ba9e --- /dev/null +++ b/RAT/calculate1.cpp @@ -0,0 +1,163 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate1.cpp +// +// Code generation for function 'calculate1' +// + +// Include files +#include "calculate1.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "parallelContrasts1.h" +#include "parallelPoints1.h" +#include "rt_nonfinite.h" +#include "single1.h" +#include "strcmp.h" +#include "sum.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customLayers + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array &sldProfiles, :: + coder::array &allLayers) + { + int32_T loop_ub_tmp; + + // Custom layers reflectivity calculation for nonPolarisedTF + // This function decides on parallelisation options before calling the + // relevant version of the main custom layers calculation. It is more + // efficient to have multiple versions of the core calculation, each dealing + // with a different scheme for parallelisation. These are: + // single - single threaded reflectivity calculation + // points - parallelise over points in the reflectivity calculation + // contrasts - parallelise over contrasts. + // Pre-allocation - It's necessary to + // pre-allocate the memory for all the arrays + // for compilation, so do this in this block. + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgroundParams.set_size(loop_ub_tmp); + problem->qzshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->bulkIn.set_size(loop_ub_tmp); + problem->bulkOut.set_size(loop_ub_tmp); + problem->calculations.allChis.set_size(loop_ub_tmp); + problem->resolutionParams.set_size(loop_ub_tmp); + problem->allSubRough.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + simulation.set_size(loop_ub_tmp); + shiftedData.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + sldProfiles.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgroundParams[i] = 0.0; + problem->qzshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->bulkIn[i] = 0.0; + problem->bulkOut[i] = 0.0; + problem->calculations.allChis[i] = 0.0; + problem->resolutionParams[i] = 0.0; + problem->allSubRough[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + simulation[i].f1.set_size(2, 2); + simulation[i].f1[0] = 1.0; + simulation[i].f1[1] = 1.0; + simulation[i].f1[simulation[i].f1.size(0)] = 1.0; + simulation[i].f1[simulation[i].f1.size(0) + 1] = 1.0; + shiftedData[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + sldProfiles[i].f1.set_size(2, 2); + sldProfiles[i].f1[0] = 1.0; + sldProfiles[i].f1[1] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; + allLayers[i].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i] = 1.0; + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; + } + } + + // End pre-allocation + if (coder::internal::n_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 0; + } else if (coder::internal::o_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 1; + } else if (coder::internal::p_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + b_single(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, problem->bulkOut, + problem->resolutionParams, problem->calculations.allChis, + reflectivity, simulation, shiftedData, layerSlds, sldProfiles, + allLayers, problem->allSubRough); + break; + + case 1: + parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, + problem->bulkOut, problem->resolutionParams, + problem->calculations.allChis, reflectivity, simulation, + shiftedData, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + + case 2: + c_parallelContrasts(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgroundParams, + problem->qzshifts, problem->scalefactors, + problem->bulkIn, problem->bulkOut, + problem->resolutionParams, + problem->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, sldProfiles, + allLayers, problem->allSubRough); + break; + } + + problem->calculations.sumChi = coder::sum(problem->calculations.allChis); + problem->resample.set_size(1, problemDef->resample.size(1)); + loop_ub_tmp = problemDef->resample.size(1); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + problem->resample[b_i] = problemDef->resample[b_i]; + } + } + } + } +} + +// End of code generation (calculate1.cpp) diff --git a/RAT/calculate1.h b/RAT/calculate1.h new file mode 100644 index 00000000..074e2d23 --- /dev/null +++ b/RAT/calculate1.h @@ -0,0 +1,47 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate1.h +// +// Code generation for function 'calculate1' +// +#ifndef CALCULATE1_H +#define CALCULATE1_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; + struct struct_T; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customLayers + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array &sldProfiles, :: + coder::array &allLayers); + } + } +} + +#endif + +// End of code generation (calculate1.h) diff --git a/RAT/calculate2.cpp b/RAT/calculate2.cpp new file mode 100644 index 00000000..7b525cab --- /dev/null +++ b/RAT/calculate2.cpp @@ -0,0 +1,163 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate2.cpp +// +// Code generation for function 'calculate2' +// + +// Include files +#include "calculate2.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "parallelContrasts2.h" +#include "parallelPoints2.h" +#include "rt_nonfinite.h" +#include "single2.h" +#include "strcmp.h" +#include "sum.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customXY + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array &sldProfiles, :: + coder::array &allLayers) + { + int32_T loop_ub_tmp; + + // Custom XP profile reflectivity calculation for nonPolarisedTF + // This function decides on parallelisation options before calling the + // relevant version of the main custom XY calculation. It is more + // efficient to have multiple versions of the core calculation, each dealing + // with a different scheme for parallelisation. These are: + // single - single threaded reflectivity calculation + // points - parallelise over points in the reflectivity calculation + // contrasts - parallelise over contrasts. + // Pre-allocation - It's necessary to + // pre-allocate the memory for all the arrays + // for compilation, so do this in this block. + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgroundParams.set_size(loop_ub_tmp); + problem->qzshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->bulkIn.set_size(loop_ub_tmp); + problem->bulkOut.set_size(loop_ub_tmp); + problem->calculations.allChis.set_size(loop_ub_tmp); + problem->resolutionParams.set_size(loop_ub_tmp); + problem->allSubRough.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + simulation.set_size(loop_ub_tmp); + shiftedData.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + sldProfiles.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgroundParams[i] = 0.0; + problem->qzshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->bulkIn[i] = 0.0; + problem->bulkOut[i] = 0.0; + problem->calculations.allChis[i] = 0.0; + problem->resolutionParams[i] = 0.0; + problem->allSubRough[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + simulation[i].f1.set_size(2, 2); + simulation[i].f1[0] = 1.0; + simulation[i].f1[1] = 1.0; + simulation[i].f1[simulation[i].f1.size(0)] = 1.0; + simulation[i].f1[simulation[i].f1.size(0) + 1] = 1.0; + shiftedData[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i] = 1.0; + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + } + + sldProfiles[i].f1.set_size(2, 2); + sldProfiles[i].f1[0] = 1.0; + sldProfiles[i].f1[1] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; + allLayers[i].f1.set_size(2, 1); + allLayers[i].f1[0] = 1.0; + allLayers[i].f1[1] = 1.0; + } + + if (coder::internal::n_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 0; + } else if (coder::internal::o_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 1; + } else if (coder::internal::p_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + b_single(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, problem->bulkOut, + problem->resolutionParams, problem->calculations.allChis, + reflectivity, simulation, shiftedData, layerSlds, sldProfiles, + allLayers, problem->allSubRough); + break; + + case 1: + parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, + problem->bulkOut, problem->resolutionParams, + problem->calculations.allChis, reflectivity, simulation, + shiftedData, layerSlds, sldProfiles, allLayers, + problem->allSubRough); + break; + + case 2: + c_parallelContrasts(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgroundParams, + problem->qzshifts, problem->scalefactors, + problem->bulkIn, problem->bulkOut, + problem->resolutionParams, + problem->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, sldProfiles, + allLayers, problem->allSubRough); + break; + } + + problem->calculations.sumChi = coder::sum(problem->calculations.allChis); + problem->resample.set_size(1, problem->allSubRough.size(0)); + loop_ub_tmp = problem->allSubRough.size(0); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + problem->resample[b_i] = 1.0; + } + } + } + } +} + +// End of code generation (calculate2.cpp) diff --git a/RAT/calculate2.h b/RAT/calculate2.h new file mode 100644 index 00000000..c1e710cb --- /dev/null +++ b/RAT/calculate2.h @@ -0,0 +1,47 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate2.h +// +// Code generation for function 'calculate2' +// +#ifndef CALCULATE2_H +#define CALCULATE2_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; + struct struct_T; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customXY + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array &sldProfiles, :: + coder::array &allLayers); + } + } +} + +#endif + +// End of code generation (calculate2.h) diff --git a/RAT/calculate3.cpp b/RAT/calculate3.cpp new file mode 100644 index 00000000..2ab91ed7 --- /dev/null +++ b/RAT/calculate3.cpp @@ -0,0 +1,246 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate3.cpp +// +// Code generation for function 'calculate3' +// + +// Include files +#include "calculate3.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "parallelContrasts3.h" +#include "parallelPoints3.h" +#include "rt_nonfinite.h" +#include "single3.h" +#include "strcmp.h" +#include "sum.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace standardLayers + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array &sldProfiles, :: + coder::array &allLayers) + { + ::coder::array b_allLayers; + ::coder::array b_layerSlds; + ::coder::array b_sldProfiles; + int32_T loop_ub_tmp; + + // Standard layers reflectivity calculation for nonPolarisedTF + // This function decides on parallelisation options before calling the + // relevant version of the main standard layers calculation. Parallelisation + // is either over the outer loop ('contrasts'), or the inner loop + // ('points'). The easiest way to do this is to have multiple versions of + // the same core calculation, rather than trying to make the parallel + // for loops conditional (although that would be much neater) There are: + // points - parallelise over points in the reflectivity calculation + // contrasts - parallelise over contrasts (outer for loop) + // Pre-allocation - It's necessary to + // pre-define the types for all the arrays + // for compilation, so do this in this block. + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgroundParams.set_size(loop_ub_tmp); + problem->qzshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->bulkIn.set_size(loop_ub_tmp); + problem->bulkOut.set_size(loop_ub_tmp); + problem->calculations.allChis.set_size(loop_ub_tmp); + problem->resolutionParams.set_size(loop_ub_tmp); + problem->allSubRough.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + simulation.set_size(loop_ub_tmp); + shiftedData.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp, 1); + sldProfiles.set_size(loop_ub_tmp, 1); + allLayers.set_size(loop_ub_tmp, 1); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgroundParams[i] = 0.0; + problem->qzshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->bulkIn[i] = 0.0; + problem->bulkOut[i] = 0.0; + problem->calculations.allChis[i] = 0.0; + problem->resolutionParams[i] = 0.0; + problem->allSubRough[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + simulation[i].f1.set_size(2, 2); + simulation[i].f1[0] = 1.0; + simulation[i].f1[1] = 1.0; + simulation[i].f1[simulation[i].f1.size(0)] = 1.0; + simulation[i].f1[simulation[i].f1.size(0) + 1] = 1.0; + shiftedData[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + sldProfiles[i].f1.set_size(2, 2); + sldProfiles[i].f1[0] = 1.0; + sldProfiles[i].f1[1] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; + allLayers[i].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i] = 1.0; + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; + } + } + + // ------- End type definitions ------------- + if (coder::internal::n_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 0; + } else if (coder::internal::o_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 1; + } else if (coder::internal::p_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + { + int32_T b_loop_ub; + int32_T loop_ub; + b_single(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, problem->bulkOut, + problem->resolutionParams, problem->calculations.allChis, + reflectivity, simulation, shiftedData, b_layerSlds, + b_sldProfiles, b_allLayers, problem->allSubRough); + layerSlds.set_size(b_layerSlds.size(0), 2); + sldProfiles.set_size(b_sldProfiles.size(0), 2); + allLayers.set_size(b_allLayers.size(0), 2); + loop_ub_tmp = b_layerSlds.size(0); + loop_ub = b_sldProfiles.size(0); + b_loop_ub = b_allLayers.size(0); + for (int32_T b_i{0}; b_i < 2; b_i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + layerSlds[i1 + layerSlds.size(0) * b_i] = b_layerSlds[i1 + + b_layerSlds.size(0) * b_i]; + } + + for (int32_T i1{0}; i1 < loop_ub; i1++) { + sldProfiles[i1 + sldProfiles.size(0) * b_i] = b_sldProfiles[i1 + + b_sldProfiles.size(0) * b_i]; + } + + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + allLayers[i1 + allLayers.size(0) * b_i] = b_allLayers[i1 + + b_allLayers.size(0) * b_i]; + } + } + } + break; + + case 1: + { + int32_T b_loop_ub; + int32_T loop_ub; + parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, + problem->bulkOut, problem->resolutionParams, + problem->calculations.allChis, reflectivity, + simulation, shiftedData, b_layerSlds, b_sldProfiles, + b_allLayers, problem->allSubRough); + layerSlds.set_size(b_layerSlds.size(0), 2); + sldProfiles.set_size(b_sldProfiles.size(0), 2); + allLayers.set_size(b_allLayers.size(0), 2); + loop_ub_tmp = b_layerSlds.size(0); + loop_ub = b_sldProfiles.size(0); + b_loop_ub = b_allLayers.size(0); + for (int32_T b_i{0}; b_i < 2; b_i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + layerSlds[i1 + layerSlds.size(0) * b_i] = b_layerSlds[i1 + + b_layerSlds.size(0) * b_i]; + } + + for (int32_T i1{0}; i1 < loop_ub; i1++) { + sldProfiles[i1 + sldProfiles.size(0) * b_i] = b_sldProfiles[i1 + + b_sldProfiles.size(0) * b_i]; + } + + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + allLayers[i1 + allLayers.size(0) * b_i] = b_allLayers[i1 + + b_allLayers.size(0) * b_i]; + } + } + } + break; + + case 2: + { + int32_T b_loop_ub; + int32_T loop_ub; + c_parallelContrasts(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgroundParams, + problem->qzshifts, problem->scalefactors, + problem->bulkIn, problem->bulkOut, + problem->resolutionParams, + problem->calculations.allChis, reflectivity, + simulation, shiftedData, b_layerSlds, + b_sldProfiles, b_allLayers, problem->allSubRough); + layerSlds.set_size(b_layerSlds.size(0), 2); + sldProfiles.set_size(b_sldProfiles.size(0), 2); + allLayers.set_size(b_allLayers.size(0), 2); + loop_ub_tmp = b_layerSlds.size(0); + loop_ub = b_sldProfiles.size(0); + b_loop_ub = b_allLayers.size(0); + for (int32_T b_i{0}; b_i < 2; b_i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + layerSlds[i1 + layerSlds.size(0) * b_i] = b_layerSlds[i1 + + b_layerSlds.size(0) * b_i]; + } + + for (int32_T i1{0}; i1 < loop_ub; i1++) { + sldProfiles[i1 + sldProfiles.size(0) * b_i] = b_sldProfiles[i1 + + b_sldProfiles.size(0) * b_i]; + } + + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + allLayers[i1 + allLayers.size(0) * b_i] = b_allLayers[i1 + + b_allLayers.size(0) * b_i]; + } + } + } + break; + } + + // Package everything into one array for tidy output + problem->calculations.sumChi = coder::sum(problem->calculations.allChis); + problem->resample.set_size(1, problemDef->resample.size(1)); + loop_ub_tmp = problemDef->resample.size(1); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + problem->resample[b_i] = problemDef->resample[b_i]; + } + } + } + } +} + +// End of code generation (calculate3.cpp) diff --git a/RAT/calculate3.h b/RAT/calculate3.h new file mode 100644 index 00000000..e8c76692 --- /dev/null +++ b/RAT/calculate3.h @@ -0,0 +1,47 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate3.h +// +// Code generation for function 'calculate3' +// +#ifndef CALCULATE3_H +#define CALCULATE3_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; + struct struct_T; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace standardLayers + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array &sldProfiles, :: + coder::array &allLayers); + } + } +} + +#endif + +// End of code generation (calculate3.h) diff --git a/RAT/calculate4.cpp b/RAT/calculate4.cpp new file mode 100644 index 00000000..2e8ae3d7 --- /dev/null +++ b/RAT/calculate4.cpp @@ -0,0 +1,209 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate4.cpp +// +// Code generation for function 'calculate4' +// + +// Include files +#include "calculate4.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "parallelContrasts4.h" +#include "parallelPoints4.h" +#include "rt_nonfinite.h" +#include "single4.h" +#include "strcmp.h" +#include "sum.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace customLayers + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array + &domainSldProfiles, ::coder::array + &allLayers) + { + ::coder::array b_allLayers; + int32_T loop_ub_tmp; + + // Custom layers reflectivity calculation for domainsTF + // This function decides on parallelisation options before calling the + // relevant version of the main custom layers calculation. It is more + // efficient to have multiple versions of the core calculation, each dealing + // with a different scheme for parallelisation. These are: + // single - single threaded reflectivity calculation + // points - parallelise over points in the reflectivity calculation + // contrasts - parallelise over contrasts. + // Pre-allocation - It's necessary to + // pre-allocate the memory for all the arrays + // for compilation, so do this in this block. + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgroundParams.set_size(loop_ub_tmp); + problem->qzshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->bulkIn.set_size(loop_ub_tmp); + problem->bulkOut.set_size(loop_ub_tmp); + problem->calculations.allChis.set_size(loop_ub_tmp); + problem->resolutionParams.set_size(loop_ub_tmp); + problem->allSubRough.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + simulation.set_size(loop_ub_tmp); + shiftedData.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp, 2); + domainSldProfiles.set_size(loop_ub_tmp, 2); + allLayers.set_size(loop_ub_tmp, 2); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgroundParams[i] = 0.0; + problem->qzshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->bulkIn[i] = 0.0; + problem->bulkOut[i] = 0.0; + problem->calculations.allChis[i] = 0.0; + problem->resolutionParams[i] = 0.0; + problem->allSubRough[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + simulation[i].f1.set_size(2, 2); + simulation[i].f1[0] = 1.0; + simulation[i].f1[1] = 1.0; + simulation[i].f1[simulation[i].f1.size(0)] = 1.0; + simulation[i].f1[simulation[i].f1.size(0) + 1] = 1.0; + shiftedData[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + layerSlds[i + layerSlds.size(0)].f1.set_size(2, 3); + domainSldProfiles[i].f1.set_size(2, 2); + domainSldProfiles[i + domainSldProfiles.size(0)].f1.set_size(2, 2); + domainSldProfiles[i].f1[0] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)].f1[0] = 1.0; + domainSldProfiles[i].f1[1] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)].f1[1] = 1.0; + domainSldProfiles[i].f1[domainSldProfiles[i].f1.size(0)] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)] + .f1[domainSldProfiles[i + domainSldProfiles.size(0)].f1.size(0)] = + 1.0; + domainSldProfiles[i].f1[domainSldProfiles[i].f1.size(0) + 1] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)] + .f1[domainSldProfiles[i + domainSldProfiles.size(0)].f1.size(0) + 1] + = 1.0; + allLayers[i].f1.set_size(2, 3); + allLayers[i + allLayers.size(0)].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i] = 1.0; + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i + layerSlds.size(0)].f1[layerSlds[i + layerSlds.size(0)] + .f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i + layerSlds.size(0)].f1[layerSlds[i + layerSlds.size(0)] + .f1.size(0) * b_i + 1] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; + allLayers[i + allLayers.size(0)].f1[allLayers[i + allLayers.size(0)] + .f1.size(0) * b_i] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; + allLayers[i + allLayers.size(0)].f1[allLayers[i + allLayers.size(0)] + .f1.size(0) * b_i + 1] = 1.0; + } + } + + // End pre-allocation + if (coder::internal::n_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 0; + } else if (coder::internal::o_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 1; + } else if (coder::internal::p_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + b_single(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, problem->bulkOut, + problem->resolutionParams, problem->calculations.allChis, + reflectivity, simulation, shiftedData, layerSlds, + domainSldProfiles, b_allLayers, problem->allSubRough); + allLayers.set_size(b_allLayers.size(0), 2); + loop_ub_tmp = b_allLayers.size(0); + for (int32_T b_i{0}; b_i < 2; b_i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + allLayers[i1 + allLayers.size(0) * b_i] = b_allLayers[i1 + + b_allLayers.size(0) * b_i]; + } + } + break; + + case 1: + parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, + problem->bulkOut, problem->resolutionParams, + problem->calculations.allChis, reflectivity, simulation, + shiftedData, layerSlds, domainSldProfiles, b_allLayers, + problem->allSubRough); + allLayers.set_size(b_allLayers.size(0), 2); + loop_ub_tmp = b_allLayers.size(0); + for (int32_T b_i{0}; b_i < 2; b_i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + allLayers[i1 + allLayers.size(0) * b_i] = b_allLayers[i1 + + b_allLayers.size(0) * b_i]; + } + } + break; + + case 2: + c_parallelContrasts(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgroundParams, + problem->qzshifts, problem->scalefactors, + problem->bulkIn, problem->bulkOut, + problem->resolutionParams, + problem->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, + domainSldProfiles, b_allLayers, + problem->allSubRough); + allLayers.set_size(b_allLayers.size(0), 2); + loop_ub_tmp = b_allLayers.size(0); + for (int32_T b_i{0}; b_i < 2; b_i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + allLayers[i1 + allLayers.size(0) * b_i] = b_allLayers[i1 + + b_allLayers.size(0) * b_i]; + } + } + break; + } + + problem->calculations.sumChi = coder::sum(problem->calculations.allChis); + problem->resample.set_size(1, problemDef->resample.size(1)); + loop_ub_tmp = problemDef->resample.size(1); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + problem->resample[b_i] = problemDef->resample[b_i]; + } + } + } + } +} + +// End of code generation (calculate4.cpp) diff --git a/RAT/calculate4.h b/RAT/calculate4.h new file mode 100644 index 00000000..afa1b9db --- /dev/null +++ b/RAT/calculate4.h @@ -0,0 +1,48 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate4.h +// +// Code generation for function 'calculate4' +// +#ifndef CALCULATE4_H +#define CALCULATE4_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; + struct struct_T; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace customLayers + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array + &domainSldProfiles, ::coder::array + &allLayers); + } + } +} + +#endif + +// End of code generation (calculate4.h) diff --git a/RAT/calculate5.cpp b/RAT/calculate5.cpp new file mode 100644 index 00000000..436d7e15 --- /dev/null +++ b/RAT/calculate5.cpp @@ -0,0 +1,209 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate5.cpp +// +// Code generation for function 'calculate5' +// + +// Include files +#include "calculate5.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "parallelContrasts5.h" +#include "parallelPoints5.h" +#include "rt_nonfinite.h" +#include "single5.h" +#include "strcmp.h" +#include "sum.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace customXY + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array + &domainSldProfiles, ::coder::array + &allLayers) + { + ::coder::array b_allLayers; + int32_T loop_ub_tmp; + + // Custom layers reflectivity calculation for domainsTF + // This function decides on parallelisation options before calling the + // relevant version of the main custom layers calculation. It is more + // efficient to have multiple versions of the core calculation, each dealing + // with a different scheme for parallelisation. These are: + // single - single threaded reflectivity calculation + // points - parallelise over points in the reflectivity calculation + // contrasts - parallelise over contrasts. + // Pre-allocation - It's necessary to + // pre-allocate the memory for all the arrays + // for compilation, so do this in this block. + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgroundParams.set_size(loop_ub_tmp); + problem->qzshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->bulkIn.set_size(loop_ub_tmp); + problem->bulkOut.set_size(loop_ub_tmp); + problem->calculations.allChis.set_size(loop_ub_tmp); + problem->resolutionParams.set_size(loop_ub_tmp); + problem->allSubRough.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + simulation.set_size(loop_ub_tmp); + shiftedData.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp, 2); + domainSldProfiles.set_size(loop_ub_tmp, 2); + allLayers.set_size(loop_ub_tmp, 2); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgroundParams[i] = 0.0; + problem->qzshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->bulkIn[i] = 0.0; + problem->bulkOut[i] = 0.0; + problem->calculations.allChis[i] = 0.0; + problem->resolutionParams[i] = 0.0; + problem->allSubRough[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + simulation[i].f1.set_size(2, 2); + simulation[i].f1[0] = 1.0; + simulation[i].f1[1] = 1.0; + simulation[i].f1[simulation[i].f1.size(0)] = 1.0; + simulation[i].f1[simulation[i].f1.size(0) + 1] = 1.0; + shiftedData[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + layerSlds[i + layerSlds.size(0)].f1.set_size(2, 3); + domainSldProfiles[i].f1.set_size(2, 2); + domainSldProfiles[i + domainSldProfiles.size(0)].f1.set_size(2, 2); + domainSldProfiles[i].f1[0] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)].f1[0] = 1.0; + domainSldProfiles[i].f1[1] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)].f1[1] = 1.0; + domainSldProfiles[i].f1[domainSldProfiles[i].f1.size(0)] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)] + .f1[domainSldProfiles[i + domainSldProfiles.size(0)].f1.size(0)] = + 1.0; + domainSldProfiles[i].f1[domainSldProfiles[i].f1.size(0) + 1] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)] + .f1[domainSldProfiles[i + domainSldProfiles.size(0)].f1.size(0) + 1] + = 1.0; + allLayers[i].f1.set_size(2, 3); + allLayers[i + allLayers.size(0)].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i] = 1.0; + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i + layerSlds.size(0)].f1[layerSlds[i + layerSlds.size(0)] + .f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i + layerSlds.size(0)].f1[layerSlds[i + layerSlds.size(0)] + .f1.size(0) * b_i + 1] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; + allLayers[i + allLayers.size(0)].f1[allLayers[i + allLayers.size(0)] + .f1.size(0) * b_i] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; + allLayers[i + allLayers.size(0)].f1[allLayers[i + allLayers.size(0)] + .f1.size(0) * b_i + 1] = 1.0; + } + } + + // End pre-allocation + if (coder::internal::n_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 0; + } else if (coder::internal::o_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 1; + } else if (coder::internal::p_strcmp(controls->parallel.data, + controls->parallel.size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + b_single(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, problem->bulkOut, + problem->resolutionParams, problem->calculations.allChis, + reflectivity, simulation, shiftedData, layerSlds, + domainSldProfiles, b_allLayers, problem->allSubRough); + allLayers.set_size(b_allLayers.size(0), 2); + loop_ub_tmp = b_allLayers.size(0); + for (int32_T b_i{0}; b_i < 2; b_i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + allLayers[i1 + allLayers.size(0) * b_i] = b_allLayers[i1 + + b_allLayers.size(0) * b_i]; + } + } + break; + + case 1: + parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, + problem->backgroundParams, problem->qzshifts, + problem->scalefactors, problem->bulkIn, + problem->bulkOut, problem->resolutionParams, + problem->calculations.allChis, reflectivity, simulation, + shiftedData, layerSlds, domainSldProfiles, b_allLayers, + problem->allSubRough); + allLayers.set_size(b_allLayers.size(0), 2); + loop_ub_tmp = b_allLayers.size(0); + for (int32_T b_i{0}; b_i < 2; b_i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + allLayers[i1 + allLayers.size(0) * b_i] = b_allLayers[i1 + + b_allLayers.size(0) * b_i]; + } + } + break; + + case 2: + c_parallelContrasts(problemDef, problemDefCells, controls, + problem->ssubs, problem->backgroundParams, + problem->qzshifts, problem->scalefactors, + problem->bulkIn, problem->bulkOut, + problem->resolutionParams, + problem->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, + domainSldProfiles, b_allLayers, + problem->allSubRough); + allLayers.set_size(b_allLayers.size(0), 2); + loop_ub_tmp = b_allLayers.size(0); + for (int32_T b_i{0}; b_i < 2; b_i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + allLayers[i1 + allLayers.size(0) * b_i] = b_allLayers[i1 + + b_allLayers.size(0) * b_i]; + } + } + break; + } + + problem->calculations.sumChi = coder::sum(problem->calculations.allChis); + problem->resample.set_size(1, problemDef->resample.size(1)); + loop_ub_tmp = problemDef->resample.size(1); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + problem->resample[b_i] = problemDef->resample[b_i]; + } + } + } + } +} + +// End of code generation (calculate5.cpp) diff --git a/RAT/calculate5.h b/RAT/calculate5.h new file mode 100644 index 00000000..f294b7c9 --- /dev/null +++ b/RAT/calculate5.h @@ -0,0 +1,48 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// calculate5.h +// +// Code generation for function 'calculate5' +// +#ifndef CALCULATE5_H +#define CALCULATE5_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; + struct struct_T; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace customXY + { + void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array + &layerSlds, ::coder::array + &domainSldProfiles, ::coder::array + &allLayers); + } + } +} + +#endif + +// End of code generation (calculate5.h) diff --git a/RAT/callCppFunc.cpp b/RAT/callCppFunc.cpp deleted file mode 100644 index 9590f374..00000000 --- a/RAT/callCppFunc.cpp +++ /dev/null @@ -1,85 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// callCppFunc.cpp -// -// Code generation for function 'callCppFunc' -// - -// Include files -#include "callCppFunc.h" -#include "rt_nonfinite.h" -#include "coder_array.h" -#include "libManager.h" -#include -#include -#include -#include -#include -#include -#include - -// Function Definitions -namespace RAT -{ - void callCppFunc(::coder::array ¶ms, real_T nba, real_T nbs, - real_T numberOfContrasts, const char_T libraryName_data[], - const int32_T libraryName_size[2], const char_T - functionName_data[], const int32_T functionName_size[2], - real_T output_data[], int32_T output_size[2], real_T - *subRough) - { - Library p; - real_T tempOutput[1000][3]; - real_T nLayers; - int32_T loop_ub; - char_T b_functionName_data[10001]; - char_T b_libraryName_data[10001]; - - // Use 3rd party 'dylib.hpp' to implement a cross-platform Cpp runtime - // class loader.... https://github.com/martin-olivier/dylib - // coder.varsize('output',[1000 1],[1 0]); - // Make an instance - p = Library(); - - // We need to add a null terminator to the library names in order for - // them to match C/C++ format. See.... - // https://uk.mathworks.com/help/coder/ug/c-strings-for-null-terminated-matlab-strings.html - loop_ub = libraryName_size[1]; - if (loop_ub - 1 >= 0) { - std::copy(&libraryName_data[0], &libraryName_data[loop_ub], - &b_libraryName_data[0]); - } - - b_libraryName_data[libraryName_size[1]] = '\x00'; - loop_ub = functionName_size[1]; - if (loop_ub - 1 >= 0) { - std::copy(&functionName_data[0], &functionName_data[loop_ub], - &b_functionName_data[0]); - } - - b_functionName_data[functionName_size[1]] = '\x00'; - - // call the class method in libManager.h - std::mem_fn(&Library::loadRunner)(p, ¶ms[0], &nba, &nbs, - numberOfContrasts, &tempOutput[0][0], subRough, &nLayers, - &b_libraryName_data[0], &b_functionName_data[0]); - if (nLayers < 1.0) { - loop_ub = 0; - } else { - loop_ub = static_cast(nLayers); - } - - output_size[0] = loop_ub; - output_size[1] = 3; - for (int32_T i{0}; i < 3; i++) { - for (int32_T i1{0}; i1 < loop_ub; i1++) { - output_data[i1 + loop_ub * i] = tempOutput[i1][i]; - } - } - } -} - -// End of code generation (callCppFunc.cpp) diff --git a/RAT/callCppFunc.h b/RAT/callCppFunc.h deleted file mode 100644 index 8b56ae64..00000000 --- a/RAT/callCppFunc.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// callCppFunc.h -// -// Code generation for function 'callCppFunc' -// -#ifndef CALLCPPFUNC_H -#define CALLCPPFUNC_H - -// Include files -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void callCppFunc(::coder::array ¶ms, real_T nba, real_T nbs, - real_T numberOfContrasts, const char_T libraryName_data[], - const int32_T libraryName_size[2], const char_T - functionName_data[], const int32_T functionName_size[2], - real_T output_data[], int32_T output_size[2], real_T - *subRough); -} - -#endif - -// End of code generation (callCppFunc.h) diff --git a/RAT/callCppFunction.cpp b/RAT/callCppFunction.cpp new file mode 100644 index 00000000..cb948c5a --- /dev/null +++ b/RAT/callCppFunction.cpp @@ -0,0 +1,168 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// callCppFunction.cpp +// +// Code generation for function 'callCppFunction' +// + +// Include files +#include "callCppFunction.h" +#include "rt_nonfinite.h" +#include "classHandle.hpp" +#include "coder_array.h" +#include +#include + +// Function Definitions +namespace RAT +{ + void b_callCppFunction(::coder::array ¶ms, real_T bulkIn, + real_T bulkOut, real_T contrast, const char_T pointer_data[], const int32_T + pointer_size[2], ::coder::array &output, real_T *subRough) + { + static real_T tempOutput[6000]; + static real_T tempOutput_data[6000]; + CallbackInterface * callback; + ClassHandle * callbackHandle; + real_T outputSize[2]; + real_T size; + int32_T loop_ub; + int32_T loop_ub_tmp; + char_T b_pointer_data[10000]; + loop_ub = pointer_size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&pointer_data[0], &pointer_data[loop_ub], &b_pointer_data[0]); + } + + callbackHandle = convertString2HandlePtr(&b_pointer_data + [0]); + callback = std::mem_fn(&ClassHandle::ptr)(callbackHandle); + + // This is not ideal, it needs to be fixed + // domain should either before 0 or 1. A value less than zero indicates no domains + std::mem_fn(&CallbackInterface::invoke)(callback, ¶ms[0], + &bulkIn, &bulkOut, contrast, 0.0, &tempOutput[0], &outputSize[0], subRough); + size = outputSize[0] * outputSize[1]; + if (size < 1.0) { + loop_ub = 0; + } else { + loop_ub = static_cast(size); + } + + if (loop_ub - 1 >= 0) { + std::copy(&tempOutput[0], &tempOutput[loop_ub], &tempOutput_data[0]); + } + + loop_ub_tmp = static_cast(outputSize[1]); + loop_ub = static_cast(outputSize[0]); + output.set_size(loop_ub, loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + output[i1 + output.size(0) * i] = tempOutput_data[i + loop_ub_tmp * i1]; + } + } + } + + void c_callCppFunction(::coder::array ¶ms, real_T bulkIn, + real_T bulkOut, real_T contrast, const char_T pointer_data[], const int32_T + pointer_size[2], ::coder::array &output, real_T *subRough) + { + static real_T tempOutput[6000]; + static real_T tempOutput_data[6000]; + CallbackInterface * callback; + ClassHandle * callbackHandle; + real_T outputSize[2]; + real_T size; + int32_T loop_ub; + int32_T loop_ub_tmp; + char_T b_pointer_data[10000]; + loop_ub = pointer_size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&pointer_data[0], &pointer_data[loop_ub], &b_pointer_data[0]); + } + + callbackHandle = convertString2HandlePtr(&b_pointer_data + [0]); + callback = std::mem_fn(&ClassHandle::ptr)(callbackHandle); + + // This is not ideal, it needs to be fixed + // domain should either before 0 or 1. A value less than zero indicates no domains + std::mem_fn(&CallbackInterface::invoke)(callback, ¶ms[0], + &bulkIn, &bulkOut, contrast, 1.0, &tempOutput[0], &outputSize[0], subRough); + size = outputSize[0] * outputSize[1]; + if (size < 1.0) { + loop_ub = 0; + } else { + loop_ub = static_cast(size); + } + + if (loop_ub - 1 >= 0) { + std::copy(&tempOutput[0], &tempOutput[loop_ub], &tempOutput_data[0]); + } + + loop_ub_tmp = static_cast(outputSize[1]); + loop_ub = static_cast(outputSize[0]); + output.set_size(loop_ub, loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + output[i1 + output.size(0) * i] = tempOutput_data[i + loop_ub_tmp * i1]; + } + } + } + + void callCppFunction(::coder::array ¶ms, real_T bulkIn, real_T + bulkOut, real_T contrast, const char_T pointer_data[], + const int32_T pointer_size[2], ::coder::array + &output, real_T *subRough) + { + static real_T tempOutput[6000]; + static real_T tempOutput_data[6000]; + CallbackInterface * callback; + ClassHandle * callbackHandle; + real_T outputSize[2]; + real_T size; + int32_T loop_ub; + int32_T loop_ub_tmp; + char_T b_pointer_data[10000]; + loop_ub = pointer_size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&pointer_data[0], &pointer_data[loop_ub], &b_pointer_data[0]); + } + + callbackHandle = convertString2HandlePtr(&b_pointer_data + [0]); + callback = std::mem_fn(&ClassHandle::ptr)(callbackHandle); + + // This is not ideal, it needs to be fixed + // domain should either before 0 or 1. A value less than zero indicates no domains + std::mem_fn + (&CallbackInterface::invoke)(callback, ¶ms[0], &bulkIn, &bulkOut, + contrast, &tempOutput[0], &outputSize[0], subRough); + size = outputSize[0] * outputSize[1]; + if (size < 1.0) { + loop_ub = 0; + } else { + loop_ub = static_cast(size); + } + + if (loop_ub - 1 >= 0) { + std::copy(&tempOutput[0], &tempOutput[loop_ub], &tempOutput_data[0]); + } + + loop_ub_tmp = static_cast(outputSize[1]); + loop_ub = static_cast(outputSize[0]); + output.set_size(loop_ub, loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + output[i1 + output.size(0) * i] = tempOutput_data[i + loop_ub_tmp * i1]; + } + } + } +} + +// End of code generation (callCppFunction.cpp) diff --git a/RAT/callCppFunction.h b/RAT/callCppFunction.h new file mode 100644 index 00000000..8564e057 --- /dev/null +++ b/RAT/callCppFunction.h @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// callCppFunction.h +// +// Code generation for function 'callCppFunction' +// +#ifndef CALLCPPFUNCTION_H +#define CALLCPPFUNCTION_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void b_callCppFunction(::coder::array ¶ms, real_T bulkIn, + real_T bulkOut, real_T contrast, const char_T pointer_data[], const int32_T + pointer_size[2], ::coder::array &output, real_T *subRough); + void c_callCppFunction(::coder::array ¶ms, real_T bulkIn, + real_T bulkOut, real_T contrast, const char_T pointer_data[], const int32_T + pointer_size[2], ::coder::array &output, real_T *subRough); + void callCppFunction(::coder::array ¶ms, real_T bulkIn, real_T + bulkOut, real_T contrast, const char_T pointer_data[], + const int32_T pointer_size[2], ::coder::array + &output, real_T *subRough); +} + +#endif + +// End of code generation (callCppFunction.h) diff --git a/RAT/callReflectivity.cpp b/RAT/callReflectivity.cpp index 26ae241b..de5eaa5b 100644 --- a/RAT/callReflectivity.cpp +++ b/RAT/callReflectivity.cpp @@ -18,18 +18,15 @@ #include "rt_nonfinite.h" #include "coder_array.h" #include -#include - -namespace py = pybind11; // Function Definitions namespace RAT { - void b_callReflectivity(real_T nbairs, real_T nbsubs, const real_T - simLimits_data[], const real_T repeatLayers[2], const ::coder::array &this_data, ::coder::array &layers, real_T ssubs, real_T res, - boolean_T useImaginary, ::coder::array &reflectivity, ::coder:: - array &Simulation) + void b_callReflectivity(real_T bulkIns, real_T bulkOuts, const real_T + simLimits[2], const real_T repeatLayers[2], const ::coder::array + &thisData, ::coder::array &layers, real_T ssubs, real_T + resolution, boolean_T useImaginary, ::coder::array &reflectivity, + ::coder::array &simulation) { ::coder::array slds; ::coder::array firstSection; @@ -44,10 +41,10 @@ namespace RAT real_T nLayersTot; real_T nRepeats; real_T step; - int32_T b_nLayersTot; int32_T i; int32_T i1; int32_T loop_ub; + int32_T loop_ub_tmp; uint32_T layerCount; uint32_T splits_idx_1; if (repeatLayers[0] != 0.0) { @@ -61,7 +58,7 @@ namespace RAT // No layers defined. Make a zeros dummy zero layer layers.set_size(1, 3); layers[0] = 0.0; - layers[layers.size(0)] = nbairs; + layers[layers.size(0)] = bulkIns; layers[layers.size(0) * 2] = 0.0; } @@ -69,23 +66,23 @@ namespace RAT nLayersTot = static_cast(layers.size(0)) * nRepeats + 2.0; // Make arrays for thick, sld, rough - b_nLayersTot = static_cast(nLayersTot); - thicks.set_size(b_nLayersTot); - roughs.set_size(b_nLayersTot); - for (i = 0; i < b_nLayersTot; i++) { + loop_ub_tmp = static_cast(nLayersTot); + thicks.set_size(loop_ub_tmp); + roughs.set_size(loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { thicks[i] = 0.0; roughs[i] = 0.0; } if (useImaginary) { - slds.set_size(b_nLayersTot); - for (i = 0; i < b_nLayersTot; i++) { + slds.set_size(loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { slds[i].re = 0.0; slds[i].im = 0.0; } } else { - slds.set_size(b_nLayersTot); - for (i = 0; i < b_nLayersTot; i++) { + slds.set_size(loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { slds[i].re = 0.0; slds[i].im = 0.0; } @@ -98,19 +95,19 @@ namespace RAT i1 = layers.size(0); for (int32_T n{0}; n < i1; n++) { if (!useImaginary) { - b_nLayersTot = static_cast(layerCount + static_cast + loop_ub_tmp = static_cast(layerCount + static_cast (n)) - 1; - thicks[b_nLayersTot] = layers[n]; - slds[b_nLayersTot].re = layers[n + layers.size(0)]; - slds[b_nLayersTot].im = 0.0; - roughs[b_nLayersTot] = layers[n + layers.size(0) * 2]; + thicks[loop_ub_tmp] = layers[n]; + slds[loop_ub_tmp].re = layers[n + layers.size(0)]; + slds[loop_ub_tmp].im = 0.0; + roughs[loop_ub_tmp] = layers[n + layers.size(0) * 2]; } else { - b_nLayersTot = static_cast(layerCount + static_cast + loop_ub_tmp = static_cast(layerCount + static_cast (n)) - 1; - thicks[b_nLayersTot] = layers[n]; - slds[b_nLayersTot].re = layers[n + layers.size(0)]; - slds[b_nLayersTot].im = layers[n + layers.size(0) * 2]; - roughs[b_nLayersTot] = layers[n + layers.size(0) * 3]; + thicks[loop_ub_tmp] = layers[n]; + slds[loop_ub_tmp].re = layers[n + layers.size(0)]; + slds[loop_ub_tmp].im = layers[n + layers.size(0) * 2]; + roughs[loop_ub_tmp] = layers[n + layers.size(0) * 3]; } } @@ -118,101 +115,101 @@ namespace RAT } // Add the air and substrate parameters - slds[0].re = nbairs; + slds[0].re = bulkIns; slds[0].im = 0.0; - slds[slds.size(0) - 1].re = nbsubs; + slds[slds.size(0) - 1].re = bulkOuts; slds[slds.size(0) - 1].im = 0.0; roughs[roughs.size(0) - 1] = ssubs; - if (simLimits_data[0] < this_data[0]) { - step = this_data[1] - this_data[0]; - b = this_data[0] - step; + if (simLimits[0] < thisData[0]) { + step = thisData[1] - thisData[0]; + b = thisData[0] - step; if (std::isnan(step) || std::isnan(b)) { firstSection.set_size(1, 1); firstSection[0] = rtNaN; - } else if ((step == 0.0) || ((simLimits_data[0] < b) && (step < 0.0)) || - ((b < simLimits_data[0]) && (step > 0.0))) { + } else if ((step == 0.0) || ((simLimits[0] < b) && (step < 0.0)) || ((b < + simLimits[0]) && (step > 0.0))) { firstSection.set_size(1, 0); - } else if ((std::isinf(simLimits_data[0]) || std::isinf(b)) && (std::isinf - (step) || (simLimits_data[0] == b))) { + } else if ((std::isinf(simLimits[0]) || std::isinf(b)) && (std::isinf(step) + || (simLimits[0] == b))) { firstSection.set_size(1, 1); firstSection[0] = rtNaN; } else if (std::isinf(step)) { firstSection.set_size(1, 1); - firstSection[0] = simLimits_data[0]; - } else if ((std::floor(simLimits_data[0]) == simLimits_data[0]) && (std:: - floor(step) == step)) { - loop_ub = static_cast((b - simLimits_data[0]) / step); + firstSection[0] = simLimits[0]; + } else if ((std::floor(simLimits[0]) == simLimits[0]) && (std::floor(step) + == step)) { + loop_ub = static_cast((b - simLimits[0]) / step); firstSection.set_size(1, loop_ub + 1); for (i = 0; i <= loop_ub; i++) { - firstSection[i] = simLimits_data[0] + step * static_cast(i); + firstSection[i] = simLimits[0] + step * static_cast(i); } } else { - coder::eml_float_colon(simLimits_data[0], step, b, firstSection); + coder::eml_float_colon(simLimits[0], step, b, firstSection); } } else { firstSection.set_size(1, 0); } - if (simLimits_data[1] > this_data[this_data.size(0) - 1]) { - step = this_data[this_data.size(0) - 1] - this_data[this_data.size(0) - 2]; - b = this_data[this_data.size(0) - 1] + step; + if (simLimits[1] > thisData[thisData.size(0) - 1]) { + step = thisData[thisData.size(0) - 1] - thisData[thisData.size(0) - 2]; + b = thisData[thisData.size(0) - 1] + step; if (std::isnan(b) || std::isnan(step)) { lastSection.set_size(1, 1); lastSection[0] = rtNaN; - } else if ((step == 0.0) || ((b < simLimits_data[1]) && (step < 0.0)) || - ((simLimits_data[1] < b) && (step > 0.0))) { + } else if ((step == 0.0) || ((b < simLimits[1]) && (step < 0.0)) || + ((simLimits[1] < b) && (step > 0.0))) { lastSection.set_size(1, 0); - } else if ((std::isinf(b) || std::isinf(simLimits_data[1])) && (std::isinf - (step) || (b == simLimits_data[1]))) { + } else if ((std::isinf(b) || std::isinf(simLimits[1])) && (std::isinf(step) + || (b == simLimits[1]))) { lastSection.set_size(1, 1); lastSection[0] = rtNaN; } else if (std::isinf(step)) { lastSection.set_size(1, 1); lastSection[0] = b; } else if ((std::floor(b) == b) && (std::floor(step) == step)) { - loop_ub = static_cast((simLimits_data[1] - b) / step); + loop_ub = static_cast((simLimits[1] - b) / step); lastSection.set_size(1, loop_ub + 1); for (i = 0; i <= loop_ub; i++) { lastSection[i] = b + step * static_cast(i); } } else { - coder::eml_float_colon(b, step, simLimits_data[1], lastSection); + coder::eml_float_colon(b, step, simLimits[1], lastSection); } } else { lastSection.set_size(1, 0); } - b_nLayersTot = firstSection.size(1); - simXdata.set_size((this_data.size(0) + firstSection.size(1)) + + loop_ub_tmp = firstSection.size(1); + simXdata.set_size((thisData.size(0) + firstSection.size(1)) + lastSection.size(1)); loop_ub = firstSection.size(1); for (i = 0; i < loop_ub; i++) { simXdata[i] = firstSection[i]; } - loop_ub = this_data.size(0); + loop_ub = thisData.size(0); for (i = 0; i < loop_ub; i++) { - simXdata[i + b_nLayersTot] = this_data[i]; + simXdata[i + loop_ub_tmp] = thisData[i]; } loop_ub = lastSection.size(1); for (i = 0; i < loop_ub; i++) { - simXdata[(i + b_nLayersTot) + this_data.size(0)] = lastSection[i]; + simXdata[(i + loop_ub_tmp) + thisData.size(0)] = lastSection[i]; } splits_idx_1 = static_cast(firstSection.size(1)) + - static_cast(this_data.size(0)); - Simulation.set_size(simXdata.size(0), 2); + static_cast(thisData.size(0)); + simulation.set_size(simXdata.size(0), 2); loop_ub = simXdata.size(0); for (i = 0; i < 2; i++) { for (i1 = 0; i1 < loop_ub; i1++) { - Simulation[i1 + Simulation.size(0) * i] = 0.0; + simulation[i1 + simulation.size(0) * i] = 0.0; } } loop_ub = simXdata.size(0); for (i = 0; i < loop_ub; i++) { - Simulation[i] = simXdata[i]; + simulation[i] = simXdata[i]; } // If we are using data resolutions, then we also need to adjust the length @@ -220,24 +217,24 @@ namespace RAT // values at the ends of the curve. simResolData.set_size(1); simResolData[0] = 0.0; - if (res == -1.0) { - b_nLayersTot = firstSection.size(1); - simResolData.set_size((this_data.size(0) + firstSection.size(1)) + + if (resolution == -1.0) { + loop_ub_tmp = firstSection.size(1); + simResolData.set_size((thisData.size(0) + firstSection.size(1)) + lastSection.size(1)); loop_ub = firstSection.size(1); for (i = 0; i < loop_ub; i++) { - simResolData[i] = this_data[this_data.size(0) * 3]; + simResolData[i] = thisData[thisData.size(0) * 3]; } - loop_ub = this_data.size(0); + loop_ub = thisData.size(0); for (i = 0; i < loop_ub; i++) { - simResolData[i + b_nLayersTot] = this_data[i + this_data.size(0) * 3]; + simResolData[i + loop_ub_tmp] = thisData[i + thisData.size(0) * 3]; } loop_ub = lastSection.size(1); for (i = 0; i < loop_ub; i++) { - simResolData[(i + b_nLayersTot) + this_data.size(0)] = this_data - [(this_data.size(0) + this_data.size(0) * 3) - 1]; + simResolData[(i + loop_ub_tmp) + thisData.size(0)] = thisData + [(thisData.size(0) + thisData.size(0) * 3) - 1]; } } @@ -248,21 +245,21 @@ namespace RAT // Apply resolution // Note: paraPoints gives an error during valifation, so use // single cored resolution as a workaround for now. - if (res == -1.0) { + if (resolution == -1.0) { // simRef = dataResolutionPollyParallelPoints(simXdata,simRef,simResolData,length(simXdata)); dataResolutionPolly(simXdata, simRef, simResolData, static_cast (simXdata.size(0)), r); loop_ub = r.size(0); for (i = 0; i < loop_ub; i++) { - Simulation[i + Simulation.size(0)] = r[i]; + simulation[i + simulation.size(0)] = r[i]; } } else { // simRef = resolutionPollyParallelPoints(simXdata,simRef,res,length(simXdata)); - resolutionPolly(simXdata, simRef, res, static_cast(simXdata.size(0)), - r); + resolutionPolly(simXdata, simRef, resolution, static_cast + (simXdata.size(0)), r); loop_ub = r.size(0); for (i = 0; i < loop_ub; i++) { - Simulation[i + Simulation.size(0)] = r[i]; + simulation[i + simulation.size(0)] = r[i]; } } @@ -277,19 +274,19 @@ namespace RAT loop_ub = i1 - i; reflectivity.set_size(loop_ub, 2); for (i1 = 0; i1 < 2; i1++) { - for (b_nLayersTot = 0; b_nLayersTot < loop_ub; b_nLayersTot++) { - reflectivity[b_nLayersTot + reflectivity.size(0) * i1] = Simulation[(i + - b_nLayersTot) + Simulation.size(0) * i1]; + for (loop_ub_tmp = 0; loop_ub_tmp < loop_ub; loop_ub_tmp++) { + reflectivity[loop_ub_tmp + reflectivity.size(0) * i1] = simulation[(i + + loop_ub_tmp) + simulation.size(0) * i1]; } } } - void callReflectivity(real_T nbairs, real_T nbsubs, const real_T - simLimits_data[], const real_T repeatLayers[2], const :: - coder::array &this_data, ::coder::array< - real_T, 2U> &layers, real_T ssubs, real_T res, boolean_T + void callReflectivity(real_T bulkIns, real_T bulkOuts, const real_T simLimits + [2], const real_T repeatLayers[2], const ::coder::array< + real_T, 2U> &thisData, ::coder::array + &layers, real_T ssubs, real_T resolution, boolean_T useImaginary, ::coder::array &reflectivity, :: - coder::array &Simulation) + coder::array &simulation) { ::coder::array slds; ::coder::array firstSection; @@ -304,10 +301,10 @@ namespace RAT real_T nLayersTot; real_T nRepeats; real_T step; - int32_T b_nLayersTot; int32_T i; int32_T i1; int32_T loop_ub; + int32_T loop_ub_tmp; uint32_T layerCount; uint32_T splits_idx_1; if (repeatLayers[0] != 0.0) { @@ -321,7 +318,7 @@ namespace RAT // No layers defined. Make a zeros dummy zero layer layers.set_size(1, 3); layers[0] = 0.0; - layers[layers.size(0)] = nbairs; + layers[layers.size(0)] = bulkIns; layers[layers.size(0) * 2] = 0.0; } @@ -329,23 +326,23 @@ namespace RAT nLayersTot = static_cast(layers.size(0)) * nRepeats + 2.0; // Make arrays for thick, sld, rough - b_nLayersTot = static_cast(nLayersTot); - thicks.set_size(b_nLayersTot); - roughs.set_size(b_nLayersTot); - for (i = 0; i < b_nLayersTot; i++) { + loop_ub_tmp = static_cast(nLayersTot); + thicks.set_size(loop_ub_tmp); + roughs.set_size(loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { thicks[i] = 0.0; roughs[i] = 0.0; } if (useImaginary) { - slds.set_size(b_nLayersTot); - for (i = 0; i < b_nLayersTot; i++) { + slds.set_size(loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { slds[i].re = 0.0; slds[i].im = 0.0; } } else { - slds.set_size(b_nLayersTot); - for (i = 0; i < b_nLayersTot; i++) { + slds.set_size(loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { slds[i].re = 0.0; slds[i].im = 0.0; } @@ -358,19 +355,19 @@ namespace RAT i1 = layers.size(0); for (int32_T n{0}; n < i1; n++) { if (!useImaginary) { - b_nLayersTot = static_cast(layerCount + static_cast + loop_ub_tmp = static_cast(layerCount + static_cast (n)) - 1; - thicks[b_nLayersTot] = layers[n]; - slds[b_nLayersTot].re = layers[n + layers.size(0)]; - slds[b_nLayersTot].im = 0.0; - roughs[b_nLayersTot] = layers[n + layers.size(0) * 2]; + thicks[loop_ub_tmp] = layers[n]; + slds[loop_ub_tmp].re = layers[n + layers.size(0)]; + slds[loop_ub_tmp].im = 0.0; + roughs[loop_ub_tmp] = layers[n + layers.size(0) * 2]; } else { - b_nLayersTot = static_cast(layerCount + static_cast + loop_ub_tmp = static_cast(layerCount + static_cast (n)) - 1; - thicks[b_nLayersTot] = layers[n]; - slds[b_nLayersTot].re = layers[n + layers.size(0)]; - slds[b_nLayersTot].im = layers[n + layers.size(0) * 2]; - roughs[b_nLayersTot] = layers[n + layers.size(0) * 3]; + thicks[loop_ub_tmp] = layers[n]; + slds[loop_ub_tmp].re = layers[n + layers.size(0)]; + slds[loop_ub_tmp].im = layers[n + layers.size(0) * 2]; + roughs[loop_ub_tmp] = layers[n + layers.size(0) * 3]; } } @@ -378,101 +375,101 @@ namespace RAT } // Add the air and substrate parameters - slds[0].re = nbairs; + slds[0].re = bulkIns; slds[0].im = 0.0; - slds[slds.size(0) - 1].re = nbsubs; + slds[slds.size(0) - 1].re = bulkOuts; slds[slds.size(0) - 1].im = 0.0; roughs[roughs.size(0) - 1] = ssubs; - if (simLimits_data[0] < this_data[0]) { - step = this_data[1] - this_data[0]; - b = this_data[0] - step; + if (simLimits[0] < thisData[0]) { + step = thisData[1] - thisData[0]; + b = thisData[0] - step; if (std::isnan(step) || std::isnan(b)) { firstSection.set_size(1, 1); firstSection[0] = rtNaN; - } else if ((step == 0.0) || ((simLimits_data[0] < b) && (step < 0.0)) || - ((b < simLimits_data[0]) && (step > 0.0))) { + } else if ((step == 0.0) || ((simLimits[0] < b) && (step < 0.0)) || ((b < + simLimits[0]) && (step > 0.0))) { firstSection.set_size(1, 0); - } else if ((std::isinf(simLimits_data[0]) || std::isinf(b)) && (std::isinf - (step) || (simLimits_data[0] == b))) { + } else if ((std::isinf(simLimits[0]) || std::isinf(b)) && (std::isinf(step) + || (simLimits[0] == b))) { firstSection.set_size(1, 1); firstSection[0] = rtNaN; } else if (std::isinf(step)) { firstSection.set_size(1, 1); - firstSection[0] = simLimits_data[0]; - } else if ((std::floor(simLimits_data[0]) == simLimits_data[0]) && (std:: - floor(step) == step)) { - loop_ub = static_cast((b - simLimits_data[0]) / step); + firstSection[0] = simLimits[0]; + } else if ((std::floor(simLimits[0]) == simLimits[0]) && (std::floor(step) + == step)) { + loop_ub = static_cast((b - simLimits[0]) / step); firstSection.set_size(1, loop_ub + 1); for (i = 0; i <= loop_ub; i++) { - firstSection[i] = simLimits_data[0] + step * static_cast(i); + firstSection[i] = simLimits[0] + step * static_cast(i); } } else { - coder::eml_float_colon(simLimits_data[0], step, b, firstSection); + coder::eml_float_colon(simLimits[0], step, b, firstSection); } } else { firstSection.set_size(1, 0); } - if (simLimits_data[1] > this_data[this_data.size(0) - 1]) { - step = this_data[this_data.size(0) - 1] - this_data[this_data.size(0) - 2]; - b = this_data[this_data.size(0) - 1] + step; + if (simLimits[1] > thisData[thisData.size(0) - 1]) { + step = thisData[thisData.size(0) - 1] - thisData[thisData.size(0) - 2]; + b = thisData[thisData.size(0) - 1] + step; if (std::isnan(b) || std::isnan(step)) { lastSection.set_size(1, 1); lastSection[0] = rtNaN; - } else if ((step == 0.0) || ((b < simLimits_data[1]) && (step < 0.0)) || - ((simLimits_data[1] < b) && (step > 0.0))) { + } else if ((step == 0.0) || ((b < simLimits[1]) && (step < 0.0)) || + ((simLimits[1] < b) && (step > 0.0))) { lastSection.set_size(1, 0); - } else if ((std::isinf(b) || std::isinf(simLimits_data[1])) && (std::isinf - (step) || (b == simLimits_data[1]))) { + } else if ((std::isinf(b) || std::isinf(simLimits[1])) && (std::isinf(step) + || (b == simLimits[1]))) { lastSection.set_size(1, 1); lastSection[0] = rtNaN; } else if (std::isinf(step)) { lastSection.set_size(1, 1); lastSection[0] = b; } else if ((std::floor(b) == b) && (std::floor(step) == step)) { - loop_ub = static_cast((simLimits_data[1] - b) / step); + loop_ub = static_cast((simLimits[1] - b) / step); lastSection.set_size(1, loop_ub + 1); for (i = 0; i <= loop_ub; i++) { lastSection[i] = b + step * static_cast(i); } } else { - coder::eml_float_colon(b, step, simLimits_data[1], lastSection); + coder::eml_float_colon(b, step, simLimits[1], lastSection); } } else { lastSection.set_size(1, 0); } - b_nLayersTot = firstSection.size(1); - simXdata.set_size((this_data.size(0) + firstSection.size(1)) + + loop_ub_tmp = firstSection.size(1); + simXdata.set_size((thisData.size(0) + firstSection.size(1)) + lastSection.size(1)); loop_ub = firstSection.size(1); for (i = 0; i < loop_ub; i++) { simXdata[i] = firstSection[i]; } - loop_ub = this_data.size(0); + loop_ub = thisData.size(0); for (i = 0; i < loop_ub; i++) { - simXdata[i + b_nLayersTot] = this_data[i]; + simXdata[i + loop_ub_tmp] = thisData[i]; } loop_ub = lastSection.size(1); for (i = 0; i < loop_ub; i++) { - simXdata[(i + b_nLayersTot) + this_data.size(0)] = lastSection[i]; + simXdata[(i + loop_ub_tmp) + thisData.size(0)] = lastSection[i]; } splits_idx_1 = static_cast(firstSection.size(1)) + - static_cast(this_data.size(0)); - Simulation.set_size(simXdata.size(0), 2); + static_cast(thisData.size(0)); + simulation.set_size(simXdata.size(0), 2); loop_ub = simXdata.size(0); for (i = 0; i < 2; i++) { for (i1 = 0; i1 < loop_ub; i1++) { - Simulation[i1 + Simulation.size(0) * i] = 0.0; + simulation[i1 + simulation.size(0) * i] = 0.0; } } loop_ub = simXdata.size(0); for (i = 0; i < loop_ub; i++) { - Simulation[i] = simXdata[i]; + simulation[i] = simXdata[i]; } // If we are using data resolutions, then we also need to adjust the length @@ -480,24 +477,24 @@ namespace RAT // values at the ends of the curve. simResolData.set_size(1); simResolData[0] = 0.0; - if (res == -1.0) { - b_nLayersTot = firstSection.size(1); - simResolData.set_size((this_data.size(0) + firstSection.size(1)) + + if (resolution == -1.0) { + loop_ub_tmp = firstSection.size(1); + simResolData.set_size((thisData.size(0) + firstSection.size(1)) + lastSection.size(1)); loop_ub = firstSection.size(1); for (i = 0; i < loop_ub; i++) { - simResolData[i] = this_data[this_data.size(0) * 3]; + simResolData[i] = thisData[thisData.size(0) * 3]; } - loop_ub = this_data.size(0); + loop_ub = thisData.size(0); for (i = 0; i < loop_ub; i++) { - simResolData[i + b_nLayersTot] = this_data[i + this_data.size(0) * 3]; + simResolData[i + loop_ub_tmp] = thisData[i + thisData.size(0) * 3]; } loop_ub = lastSection.size(1); for (i = 0; i < loop_ub; i++) { - simResolData[(i + b_nLayersTot) + this_data.size(0)] = this_data - [(this_data.size(0) + this_data.size(0) * 3) - 1]; + simResolData[(i + loop_ub_tmp) + thisData.size(0)] = thisData + [(thisData.size(0) + thisData.size(0) * 3) - 1]; } } @@ -506,19 +503,19 @@ namespace RAT abelesSingle(simXdata, nLayersTot, thicks, slds, roughs, simRef); // Apply resolution correction... - if (res == -1.0) { + if (resolution == -1.0) { dataResolutionPolly(simXdata, simRef, simResolData, static_cast (simXdata.size(0)), r); loop_ub = r.size(0); for (i = 0; i < loop_ub; i++) { - Simulation[i + Simulation.size(0)] = r[i]; + simulation[i + simulation.size(0)] = r[i]; } } else { - resolutionPolly(simXdata, simRef, res, static_cast(simXdata.size(0)), - r); + resolutionPolly(simXdata, simRef, resolution, static_cast + (simXdata.size(0)), r); loop_ub = r.size(0); for (i = 0; i < loop_ub; i++) { - Simulation[i + Simulation.size(0)] = r[i]; + simulation[i + simulation.size(0)] = r[i]; } } @@ -533,9 +530,9 @@ namespace RAT loop_ub = i1 - i; reflectivity.set_size(loop_ub, 2); for (i1 = 0; i1 < 2; i1++) { - for (b_nLayersTot = 0; b_nLayersTot < loop_ub; b_nLayersTot++) { - reflectivity[b_nLayersTot + reflectivity.size(0) * i1] = Simulation[(i + - b_nLayersTot) + Simulation.size(0) * i1]; + for (loop_ub_tmp = 0; loop_ub_tmp < loop_ub; loop_ub_tmp++) { + reflectivity[loop_ub_tmp + reflectivity.size(0) * i1] = simulation[(i + + loop_ub_tmp) + simulation.size(0) * i1]; } } } diff --git a/RAT/callReflectivity.h b/RAT/callReflectivity.h index dcd13405..550331ae 100644 --- a/RAT/callReflectivity.h +++ b/RAT/callReflectivity.h @@ -19,17 +19,17 @@ // Function Declarations namespace RAT { - void b_callReflectivity(real_T nbairs, real_T nbsubs, const real_T - simLimits_data[], const real_T repeatLayers[2], const ::coder::array &this_data, ::coder::array &layers, real_T ssubs, real_T res, - boolean_T useImaginary, ::coder::array &reflectivity, ::coder:: - array &Simulation); - void callReflectivity(real_T nbairs, real_T nbsubs, const real_T - simLimits_data[], const real_T repeatLayers[2], const :: - coder::array &this_data, ::coder::array< - real_T, 2U> &layers, real_T ssubs, real_T res, boolean_T + void b_callReflectivity(real_T bulkIns, real_T bulkOuts, const real_T + simLimits[2], const real_T repeatLayers[2], const ::coder::array + &thisData, ::coder::array &layers, real_T ssubs, real_T + resolution, boolean_T useImaginary, ::coder::array &reflectivity, + ::coder::array &simulation); + void callReflectivity(real_T bulkIns, real_T bulkOuts, const real_T simLimits + [2], const real_T repeatLayers[2], const ::coder::array< + real_T, 2U> &thisData, ::coder::array + &layers, real_T ssubs, real_T resolution, boolean_T useImaginary, ::coder::array &reflectivity, :: - coder::array &Simulation); + coder::array &simulation); } #endif diff --git a/RAT/cat.cpp b/RAT/cat.cpp new file mode 100644 index 00000000..1c12a541 --- /dev/null +++ b/RAT/cat.cpp @@ -0,0 +1,61 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// cat.cpp +// +// Code generation for function 'cat' +// + +// Include files +#include "cat.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, real_T in3, const ::coder::array< + real_T, 2U> &in4) + { + ::coder::array b_in3; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + if (in4.size(0) == 1) { + i = in2.size(0); + } else { + i = in4.size(0); + } + + b_in3.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in4.size(0) != 1); + if (in4.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in4.size(0); + } + + for (i = 0; i < loop_ub; i++) { + b_in3[i] = in3 * in2[i * stride_0_0 + in2.size(0)] + (1.0 - in3) * in4[i * + stride_1_0 + in4.size(0)]; + } + + in1.set_size(in2.size(0), 2); + loop_ub = in2.size(0); + for (i = 0; i < loop_ub; i++) { + in1[i] = in2[i]; + } + + loop_ub = b_in3.size(0); + for (i = 0; i < loop_ub; i++) { + in1[i + in1.size(0)] = b_in3[i]; + } + } +} + +// End of code generation (cat.cpp) diff --git a/RAT/cat.h b/RAT/cat.h new file mode 100644 index 00000000..eab1a742 --- /dev/null +++ b/RAT/cat.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// cat.h +// +// Code generation for function 'cat' +// +#ifndef CAT_H +#define CAT_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, real_T in3, const ::coder::array< + real_T, 2U> &in4); +} + +#endif + +// End of code generation (cat.h) diff --git a/RAT/chiSquared.cpp b/RAT/chiSquared.cpp index 5efef94d..e63d8da5 100644 --- a/RAT/chiSquared.cpp +++ b/RAT/chiSquared.cpp @@ -16,9 +16,7 @@ #include "sum.h" #include "unsafeSxfun.h" #include "coder_array.h" -#include -namespace py = pybind11; // Function Definitions namespace RAT { @@ -40,8 +38,7 @@ namespace RAT // thisFit = allFits{i}; b_thisData[0] = thisData.size(0); b_thisData[1] = 1.0; - N = coder::internal::b_maximum(b_thisData); - + N = coder::internal::maximum(b_thisData); if (N <= P) { N = P + 1.0; } diff --git a/RAT/classHandle.hpp b/RAT/classHandle.hpp new file mode 100644 index 00000000..667d55e2 --- /dev/null +++ b/RAT/classHandle.hpp @@ -0,0 +1,57 @@ +/* +Adapted from https://github.com/ojwoodford/mex_class_wrapper + +* The class handle is used to hold a pointer with a method to validate the ptr is valid +* The callback interface is provides the interface for domain and non-domain custom function +*/ +#ifndef __CLASS_HANDLE_HPP__ +#define __CLASS_HANDLE_HPP__ + +#include +#include +#include +#include +#include + +#define CLASS_HANDLE_SIGNATURE 0xFF00F0A5 +template class ClassHandle +{ +public: + ClassHandle(base *ptr) : signature_m(CLASS_HANDLE_SIGNATURE), name_m(typeid(base).name()), ptr_m(ptr) {} + ~ClassHandle() { signature_m = 0; delete ptr_m; } + bool isValid() { return ((signature_m == CLASS_HANDLE_SIGNATURE) && !strcmp(name_m.c_str(), typeid(base).name())); } + base* ptr() { return ptr_m; } + +private: + uint32_t signature_m; + const std::string name_m; + base* const ptr_m; +}; + + +class CallbackInterface +{ +public: + virtual void invoke(double* params,double *bulk_in,double *bulk_out, int contrast, + double *tempOutput,double *outputSize,double *roughness)=0; + virtual void invoke(double* params,double *bulk_in,double *bulk_out, int contrast, int domainNumber, + double *tempOutput,double *outputSize,double *roughness)=0; +}; + + +template inline std::string convertPtr2String(base *ptr) +{ + auto handle = reinterpret_cast(new ClassHandle(ptr)); + return std::to_string(handle); +} + +template inline ClassHandle *convertString2HandlePtr(const char* in) +{ + uint64_t value = stoull(std::string(in)); + ClassHandle *ptr = reinterpret_cast *>(value); + if (!ptr->isValid()) + throw std::invalid_argument("callback handle is not valid"); + return ptr; +} + +#endif // __CLASS_HANDLE_HPP__ diff --git a/RAT/coder_posix_time.c b/RAT/coder_posix_time.c new file mode 100644 index 00000000..1d83c1ce --- /dev/null +++ b/RAT/coder_posix_time.c @@ -0,0 +1,162 @@ +/* MATLAB Coder time APIs */ +/* Copyright 2020-2022 The MathWorks, Inc. */ + +/* Sort out the defines early before any headers are included + * to avoid includes with inconsistent defines + */ +#if (!defined(CODER_WINAPI)) && (defined(_WIN32)) +#define CODER_WINAPI +#endif + +/* Ensure we get the right _POSIX_C_SOURCE and isolate our define to just this C file */ +#if !defined(CODER_WINAPI) +#undef _POSIX_C_SOURCE +#if defined(__QNX__) +/* QNX wants a newer POSIX version to make CLOCK_MONOTONIC available */ +#define _POSIX_C_SOURCE 200112L +#else +#define _POSIX_C_SOURCE 199309L +#endif /* defined(__QNX__) */ +#endif /* !defined(CODER_WINAPI) */ + +#ifdef CODER_WINAPI +#define NOMINMAX +#include +#endif /* CODER_WINAPI */ + +#include "coder_posix_time.h" +#include +#include +#include + +/* Prototypes */ +#ifndef CODER_WINAPI +/** + * @brief Convert coderTimeSpec to POSIX timespec + * + */ +static void coderToPOSIXTimespec(coderTimespec const * const aCoderTimespec, + struct timespec* const aTimespec); + +/** + * @brief Convert POSIX timespec to coderTimeSpec + * + */ +static void posixToCoderTimespec(const struct timespec* const aTimespec, + coderTimespec* const aCoderTimespec); + +static void coderToPOSIXTimespec(coderTimespec const * const aCoderTimespec, + struct timespec* const aTimespec) { + aTimespec->tv_sec = (time_t)(aCoderTimespec->tv_sec); + aTimespec->tv_nsec = (long)(aCoderTimespec->tv_nsec); +} + +static void posixToCoderTimespec(const struct timespec* const aTimespec, + coderTimespec* const aCoderTimespec) { + aCoderTimespec->tv_sec = (double)(aTimespec->tv_sec); + aCoderTimespec->tv_nsec = (double)(aTimespec->tv_nsec); +} +#endif /* CODER_WINAPI */ + +int coderInitTimeFunctions(double* const aFrequency) { +#ifdef CODER_WINAPI + LARGE_INTEGER freqL; + int status; + status = QueryPerformanceFrequency(&freqL); + *aFrequency = (double)freqL.QuadPart; + /* Invert status since in Windows, 0 means failure */ + return status == 0; +#else + *aFrequency = 0.0; + return 0; +#endif +} + +int coderTimeClockGettimeMonotonic(coderTimespec* const aCoderTimespec, double aFrequency) { +#ifdef CODER_WINAPI + static const double BILLION = 1e9; + LARGE_INTEGER timeL; + double timeDouble, timeRemainder, seconds, nanoseconds; + BOOL status = QueryPerformanceCounter(&timeL); + timeDouble = (double)timeL.QuadPart; + timeRemainder = fmod(timeDouble, aFrequency); + seconds = (timeDouble - timeRemainder) / aFrequency; + nanoseconds = (timeRemainder * BILLION) / aFrequency; + aCoderTimespec->tv_sec = seconds; + aCoderTimespec->tv_nsec = nanoseconds; + + /* Invert status since in Windows, 0 means failure */ + return status == 0; +#else + struct timespec tspec; + int status; + (void) aFrequency; + status = clock_gettime(CLOCK_MONOTONIC, &tspec); + posixToCoderTimespec(&tspec, aCoderTimespec); + return status; +#endif /* defined(_WIN32) || defined(WIN32) */ +} + +int coderTimeSleep(coderTimespec const * const aCoderTimespec) { +#ifdef CODER_WINAPI + /* WIndows */ + static const double MILLI = 1e3; + static const double BILLION = 1e9; + double delayMilli, delay; + DWORD delayUint32; + delayMilli = floor(aCoderTimespec->tv_nsec / (BILLION / MILLI)); + delay = MILLI * aCoderTimespec->tv_sec + delayMilli; + delayUint32 = (DWORD)ceil(delay); + Sleep(delayUint32); + return 0; +#else + /* POSIX */ + struct timespec ts; + coderToPOSIXTimespec(aCoderTimespec, &ts); + return nanosleep(&ts, NULL); +#endif +} + +int coderLocalTime(coderTm* const aTm) { +#ifdef CODER_WINAPI + /* WIndows */ + SYSTEMTIME sysTime; + TIME_ZONE_INFORMATION tzInfo; + DWORD dstInfo; + GetLocalTime(&sysTime); + aTm->tm_nsec = ((long)sysTime.wMilliseconds) * 1000000; + aTm->tm_sec = sysTime.wSecond; + aTm->tm_min = sysTime.wMinute; + aTm->tm_hour = sysTime.wHour; + aTm->tm_mday = sysTime.wDay; + aTm->tm_mon = sysTime.wMonth; + aTm->tm_year = sysTime.wYear; + aTm->tm_wday = 0; + aTm->tm_yday = 0; + + dstInfo = GetTimeZoneInformation(&tzInfo); + aTm->tm_isdst = dstInfo == TIME_ZONE_ID_DAYLIGHT; + return 0; +#else + /* POSIX */ + struct timespec ts; + struct tm* tmVal; + int status; + const int YEAR_OFFSET = 1900; /* +1900 for human year */ + const int MONTH_OFFSET = 1; /* +1 for 1-based month */ + status = clock_gettime(CLOCK_REALTIME, &ts); + tmVal = localtime(&ts.tv_sec); + aTm->tm_nsec = ts.tv_nsec; + aTm->tm_sec = tmVal->tm_sec; + aTm->tm_min = tmVal->tm_min; + aTm->tm_hour = tmVal->tm_hour; + aTm->tm_mday = tmVal->tm_mday; + aTm->tm_mon = tmVal->tm_mon + MONTH_OFFSET; + aTm->tm_year = tmVal->tm_year + YEAR_OFFSET; + aTm->tm_wday = tmVal->tm_wday; + aTm->tm_yday = tmVal->tm_yday; + aTm->tm_isdst = tmVal->tm_isdst; + + return status; +#endif +} diff --git a/RAT/coder_posix_time.h b/RAT/coder_posix_time.h new file mode 100644 index 00000000..d5cbdc8f --- /dev/null +++ b/RAT/coder_posix_time.h @@ -0,0 +1,73 @@ +/* Copyright 2020-2021 The MathWorks, Inc. */ +/* Wrapper file for time.h that ensures the proper POSIX defines for MATLAB Coder */ +#ifndef CODER_POSIX_TIME_H +#define CODER_POSIX_TIME_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Represents generic timestamps + * + */ +typedef struct coderTimespec_tag { + double tv_sec; + double tv_nsec; +} coderTimespec; + +/** + * @brief Represents a localized time + * + */ +typedef struct coderTm_tag { + long tm_nsec; /* nanoseconds */ + int tm_sec; /* seconds */ + int tm_min; /* minutes */ + int tm_hour; /* hours */ + int tm_mday; /* day of the month */ + int tm_mon; /* month */ + int tm_year; /* year */ + int tm_wday; /* day of the week */ + int tm_yday; /* day in the year */ + int tm_isdst; /* daylight saving time */ +} coderTm; + +/** + * @brief Initialize state for time functions + * + * @param aFrequency Returned clock frequency for Windows APIs + * @return int Status code. 0 for success. Non-zero for failure + */ +int coderInitTimeFunctions(double* const aFrequency); + +/** + * @brief Returns a timestamp from a monotonic clock + * + * @param aCoderTimespec The returned timestamp + * @param aFrequency Frequency obtained from coderInitTimeFunctions + * @return int Status code. 0 for success. Non-zero for failure + */ +int coderTimeClockGettimeMonotonic(coderTimespec* const aCoderTimespec, double aFrequency); + +/** + * @brief Sleep for a specified duration + * + * @param aCoderTimespec Amount of time to sleep for + * @return int Status code. 0 for success. Non-zero for failure + */ +int coderTimeSleep(coderTimespec const * const aCoderTimespec); + +/** + * @brief Query the local time + * + * @param aTm Returned local time + * @return int Status code. 0 for success. Non-zero for failure + */ +int coderLocalTime(coderTm* const aTm); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CODER_POSIX_TIME_H */ diff --git a/RAT/colon.cpp b/RAT/colon.cpp index 9ff4e5e8..63c9594b 100644 --- a/RAT/colon.cpp +++ b/RAT/colon.cpp @@ -93,6 +93,27 @@ namespace RAT } } } + + void eml_integer_colon_dispatcher(int32_T b, ::coder::array &y) + { + int32_T n; + if (b < 1) { + n = 0; + } else { + n = b; + } + + y.set_size(1, n); + if (n > 0) { + int32_T yk; + y[0] = 1; + yk = 1; + for (int32_T k{2}; k <= n; k++) { + yk++; + y[k - 1] = yk; + } + } + } } } diff --git a/RAT/colon.h b/RAT/colon.h index 42070349..8cdede94 100644 --- a/RAT/colon.h +++ b/RAT/colon.h @@ -23,6 +23,7 @@ namespace RAT { void eml_float_colon(real_T a, real_T d, real_T b, ::coder::array &y); + void eml_integer_colon_dispatcher(int32_T b, ::coder::array &y); } } diff --git a/RAT/combineVectorElements.cpp b/RAT/combineVectorElements.cpp new file mode 100644 index 00000000..0f937db2 --- /dev/null +++ b/RAT/combineVectorElements.cpp @@ -0,0 +1,186 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// combineVectorElements.cpp +// +// Code generation for function 'combineVectorElements' +// + +// Include files +#include "combineVectorElements.h" +#include "blockedSummation.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3, + const ::coder::array &in4, int32_T in5, + int32_T in6, int32_T in7) + { + ::coder::array b_in2; + int32_T aux_0_1; + int32_T aux_1_1; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_0_1; + int32_T stride_1_0; + int32_T stride_1_1; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + if (in3.size(1) == 1) { + i1 = in2.size(1); + } else { + i1 = in3.size(1); + } + + b_in2.set_size(i, i1); + stride_0_0 = (in2.size(0) != 1); + stride_0_1 = (in2.size(1) != 1); + stride_1_0 = (in3.size(0) != 1); + stride_1_1 = (in3.size(1) != 1); + aux_0_1 = 0; + aux_1_1 = 0; + if (in3.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(1); + } + + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + i1 = in3.size(0); + if (i1 == 1) { + b_loop_ub = in2.size(0); + } else { + b_loop_ub = i1; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_in2[i1 + b_in2.size(0) * i] = in2[i1 * stride_0_0 + in2.size(0) * + aux_0_1] - in3[i1 * stride_1_0 + in3.size(0) * aux_1_1]; + } + + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + + if (static_cast(in4[in5]) == 1) { + i = in6 - in7; + } else { + i = static_cast(in4[in5]); + } + + coder::blockedSummation(b_in2, i, in1); + } + + void c_binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3, const ::coder:: + array &in4, int32_T in5, int32_T in6, int32_T in7) + { + ::coder::array b_in2; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + b_in2.set_size(i, in2.size(1)); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + loop_ub = in2.size(1); + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + int32_T i1; + i1 = in3.size(0); + if (i1 == 1) { + b_loop_ub = in2.size(0); + } else { + b_loop_ub = i1; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_in2[i1 + b_in2.size(0) * i] = in2[i1 * stride_0_0 + in2.size(0) * i] - + in3[i1 * stride_1_0 + in3.size(0) * i]; + } + } + + if (static_cast(in4[in5]) == 1) { + i = in6 - in7; + } else { + i = static_cast(in4[in5]); + } + + coder::blockedSummation(b_in2, i, in1); + } + + namespace coder + { + real_T b_combineVectorElements(const ::coder::array &x, int32_T + vlen) + { + real_T y; + if ((x.size(0) == 0) || (vlen == 0)) { + y = 0.0; + } else { + y = nestedIter(x, vlen); + } + + return y; + } + + int32_T c_combineVectorElements(const ::coder::array &x) + { + int32_T vlen; + int32_T y; + vlen = x.size(0); + if (x.size(0) == 0) { + y = 0; + } else { + y = x[0]; + for (int32_T k{2}; k <= vlen; k++) { + if (vlen >= 2) { + y += x[k - 1]; + } + } + } + + return y; + } + + int32_T combineVectorElements(const ::coder::array &x) + { + int32_T vlen; + int32_T y; + vlen = x.size(1); + if (x.size(1) == 0) { + y = 0; + } else { + y = x[0]; + for (int32_T k{2}; k <= vlen; k++) { + if (vlen >= 2) { + y += x[k - 1]; + } + } + } + + return y; + } + } +} + +// End of code generation (combineVectorElements.cpp) diff --git a/RAT/combineVectorElements.h b/RAT/combineVectorElements.h new file mode 100644 index 00000000..a811ef95 --- /dev/null +++ b/RAT/combineVectorElements.h @@ -0,0 +1,40 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// combineVectorElements.h +// +// Code generation for function 'combineVectorElements' +// +#ifndef COMBINEVECTORELEMENTS_H +#define COMBINEVECTORELEMENTS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3, + const ::coder::array &in4, int32_T in5, + int32_T in6, int32_T in7); + void c_binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3, const ::coder:: + array &in4, int32_T in5, int32_T in6, int32_T in7); + namespace coder + { + real_T b_combineVectorElements(const ::coder::array &x, int32_T + vlen); + int32_T c_combineVectorElements(const ::coder::array &x); + int32_T combineVectorElements(const ::coder::array &x); + } +} + +#endif + +// End of code generation (combineVectorElements.h) diff --git a/RAT/complexTimes.cpp b/RAT/complexTimes.cpp index 5c2ade80..3634df04 100644 --- a/RAT/complexTimes.cpp +++ b/RAT/complexTimes.cpp @@ -22,7 +22,7 @@ namespace RAT { namespace scalar { - static real_T rescale(real_T *re, real_T *im); + static real_T b_rescale(real_T *re, real_T *im); } } } @@ -37,7 +37,7 @@ namespace RAT { namespace scalar { - static real_T rescale(real_T *re, real_T *im) + static real_T b_rescale(real_T *re, real_T *im) { real_T absim; real_T scale; @@ -99,10 +99,10 @@ namespace RAT boolean_T finiteScale; sar = ar; sai = ai; - scaleA = rescale(&sar, &sai); + scaleA = b_rescale(&sar, &sai); sbr = br; sbi = bi; - scaleB = rescale(&sbr, &sbi); + scaleB = b_rescale(&sbr, &sbi); if ((!std::isinf(scaleA)) && (!std::isnan(scaleA)) && ((!std:: isinf(scaleB)) && (!std::isnan(scaleB)))) { finiteScale = true; diff --git a/RAT/coreLayersCalculation.cpp b/RAT/coreLayersCalculation.cpp new file mode 100644 index 00000000..262b2481 --- /dev/null +++ b/RAT/coreLayersCalculation.cpp @@ -0,0 +1,692 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// coreLayersCalculation.cpp +// +// Code generation for function 'coreLayersCalculation' +// + +// Include files +#include "coreLayersCalculation.h" +#include "applyBackgroundCorrection.h" +#include "callReflectivity.h" +#include "chiSquared.h" +#include "groupLayersMod.h" +#include "groupLayersModImaginary.h" +#include "makeSLDProfiles.h" +#include "resampleLayers.h" +#include "resampleLayersReIm.h" +#include "rt_nonfinite.h" +#include "shiftData.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + void b_coreLayersCalculation(const ::coder::array + &contrastLayers, real_T rough, const char_T geometry_data[], const int32_T + geometry_size[2], real_T bulkIn, real_T bulkOut, real_T resample, + boolean_T calcSld, real_T scalefactor, real_T qzshift, real_T dataPresent, + const ::coder::array &data, const real_T dataLimits[2], const + real_T simLimits[2], const real_T repeatLayers[2], real_T background, + real_T resolution, real_T contrastBackgroundsType, real_T params, const + real_T resamPars[2], boolean_T useImaginary, ::coder::array + &sldProfile, ::coder::array &reflect, ::coder::array &simulation, ::coder::array &shiftedData, ::coder::array< + real_T, 2U> &theseLayers, ::coder::array &resamLayers, real_T * + chiSq, real_T *ssubs) + { + ::coder::array b_data; + ::coder::array b_theseLayers; + ::coder::array c_theseLayers; + ::coder::array layerSld; + ::coder::array sldProfileIm; + ::coder::array thisSldLays; + ::coder::array thisSldLaysIm; + ::coder::array d_theseLayers; + int32_T b_loop_ub; + int32_T i; + int32_T i1; + int32_T loop_ub; + + // This is the main reflectivity calculation for all Layers models in the + // non polarised target function. + // + // The function first arranges the + // roughness' in the correct order according + // to geometry. Then, if required it calculates the SLD profile and if + // requested resamples this into a number of zero-roughness layers + // (roughness resampling). It the applies any scalefactors and qz shifts + // the data requires. This is done before calculating the reflectivity to + // ensure that the reflectivity is calculated over the same range in qz as + // the shifted datapoints. The main reflectivity calculation is then + // called, including the resolution function. The calculation outputs two + // profiles - 'reflect' which is the same range as the points, and + // 'simulation' which can be a different range to allow extrapolation. + // The background correction is the applied, and finally chi-squared is + // calculated. + // + // Inputs: + // contrastLayers : + // rough : + // geometry : + // bulkIn : + // bulkOut : + // resample : + // calcSld : + // scalefactor : + // qzshift : + // dataPresent : + // data : + // dataLimits : + // simLimits : + // repeatLayers : + // background : + // resol : + // contrastBackgroundsType : + // params : + // parallelPoints : + // + // Outputs: + // + // ------------------------------------------------------------------------ + // + // (c) Arwel Hughes - 12/1/21 + // + // Last Modified: 12/1/21 by Arwel Hughes. + // + // ------------------------------------------------------------------------ + // Pre-definition for Coder + thisSldLaysIm.set_size(1, 2); + sldProfileIm.set_size(1, 2); + thisSldLaysIm[0] = 0.0; + sldProfileIm[0] = 0.0; + thisSldLaysIm[thisSldLaysIm.size(0)] = 0.0; + sldProfileIm[sldProfileIm.size(0)] = 0.0; + + // Bulid up the layers matrix for this contrast + if (!useImaginary) { + groupLayersMod(contrastLayers, rough, geometry_data, geometry_size, + bulkIn, bulkOut, layerSld, ssubs); + theseLayers.set_size(layerSld.size(0), 3); + loop_ub = layerSld.size(0); + for (i = 0; i < 3; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } else { + groupLayersModImaginary(contrastLayers, rough, geometry_data, + geometry_size, bulkIn, bulkOut, layerSld, ssubs); + theseLayers.set_size(layerSld.size(0), 4); + loop_ub = layerSld.size(0); + for (i = 0; i < 4; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } + + // Make the SLD profiles. + // If resampling is needed, then enforce the calcSLD flag, so as to catch + // the error af trying to resample a non-existent profile. + if ((resample == 1.0) && (!calcSld)) { + calcSld = true; + } + + // If calc SLD flag is set, then calculate the SLD profile + if (calcSld) { + // If we need them both, we process real and imaginary parts of the SLD + // seperately... + if (useImaginary) { + int32_T result; + int8_T input_sizes_idx_1; + int8_T sizes_idx_1; + boolean_T empty_non_axis_sizes; + if (theseLayers.size(1) < 4) { + i = 0; + i1 = 0; + } else { + i = 3; + i1 = 4; + } + + if (theseLayers.size(0) != 0) { + result = theseLayers.size(0); + } else { + result = 0; + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + input_sizes_idx_1 = 2; + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || ((theseLayers.size(0) != 0) && (i1 - i != + 0))) { + sizes_idx_1 = static_cast(i1 - i); + } else { + sizes_idx_1 = 0; + } + + b_theseLayers.set_size(theseLayers.size(0), 2); + loop_ub = theseLayers.size(0); + for (int32_T i2{0}; i2 < 2; i2++) { + for (b_loop_ub = 0; b_loop_ub < loop_ub; b_loop_ub++) { + b_theseLayers[b_loop_ub + b_theseLayers.size(0) * i2] = + theseLayers[b_loop_ub + theseLayers.size(0) * i2]; + } + } + + loop_ub = i1 - i; + c_theseLayers.set_size(theseLayers.size(0), loop_ub); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = theseLayers.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + c_theseLayers[i2 + c_theseLayers.size(0) * i1] = theseLayers[i2 + + theseLayers.size(0) * (i + i1)]; + } + } + + thisSldLays.set_size(result, input_sizes_idx_1 + sizes_idx_1); + loop_ub = input_sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * i] = b_theseLayers[i1 + + result * i]; + } + } + + loop_ub = sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * (i + input_sizes_idx_1)] = + c_theseLayers[i1 + result * i]; + } + } + + if (theseLayers.size(0) != 0) { + result = theseLayers.size(0); + } else { + result = 0; + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + input_sizes_idx_1 = 1; + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + sizes_idx_1 = static_cast(theseLayers.size(1) - 2); + } else { + sizes_idx_1 = 0; + } + + d_theseLayers.set_size(theseLayers.size(0)); + loop_ub = theseLayers.size(0); + for (i = 0; i < loop_ub; i++) { + d_theseLayers[i] = theseLayers[i]; + } + + c_theseLayers.set_size(theseLayers.size(0), theseLayers.size(1) - 2); + loop_ub = theseLayers.size(1); + b_loop_ub = theseLayers.size(0); + for (i = 0; i <= loop_ub - 3; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + c_theseLayers[i1 + c_theseLayers.size(0) * i] = theseLayers[i1 + + theseLayers.size(0) * (i + 2)]; + } + } + + thisSldLaysIm.set_size(result, input_sizes_idx_1 + sizes_idx_1); + loop_ub = input_sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLaysIm[i1] = d_theseLayers[i1]; + } + } + + loop_ub = sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLaysIm[i1 + thisSldLaysIm.size(0) * (i + input_sizes_idx_1)] + = c_theseLayers[i1 + result * i]; + } + } + } else { + thisSldLays.set_size(theseLayers.size(0), theseLayers.size(1)); + loop_ub = theseLayers.size(1); + b_loop_ub = theseLayers.size(0); + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * i] = theseLayers[i1 + + theseLayers.size(0) * i]; + } + } + } + + makeSLDProfiles(bulkIn, bulkOut, thisSldLays, *ssubs, repeatLayers, + b_theseLayers); + sldProfile.set_size(b_theseLayers.size(0), 2); + loop_ub = b_theseLayers.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + sldProfile[i1 + sldProfile.size(0) * i] = b_theseLayers[i1 + + b_theseLayers.size(0) * i]; + } + } + + // If we have imaginary, we are also + // going to need an SLD profile for the imaginary part + if (useImaginary) { + // Note bulkIn and bulkOut = 0 since there is never any imaginary part for + // the bulk phases.. + makeSLDProfiles(thisSldLaysIm, *ssubs, repeatLayers, b_theseLayers); + sldProfileIm.set_size(b_theseLayers.size(0), 2); + loop_ub = b_theseLayers.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + sldProfileIm[i1 + sldProfileIm.size(0) * i] = b_theseLayers[i1 + + b_theseLayers.size(0) * i]; + } + } + } + } else { + sldProfile.set_size(1, 2); + sldProfile[0] = 0.0; + sldProfile[sldProfile.size(0)] = 0.0; + } + + // If required, then resample the SLD + if (resample == 1.0) { + if (!useImaginary) { + resampleLayers(sldProfile, resamPars, layerSld); + } else { + b_resampleLayersReIm(sldProfile, sldProfileIm, resamPars, layerSld); + } + + resamLayers.set_size(layerSld.size(0), layerSld.size(1)); + loop_ub = layerSld.size(1); + b_loop_ub = layerSld.size(0); + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + resamLayers[i1 + resamLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } else { + resamLayers.set_size(1, 3); + resamLayers[0] = 0.0; + resamLayers[resamLayers.size(0)] = 0.0; + resamLayers[resamLayers.size(0) * 2] = 0.0; + } + + // Apply scale factors and q shifts to the data + b_data.set_size(data.size(0), data.size(1)); + loop_ub = data.size(1) - 1; + for (i = 0; i <= loop_ub; i++) { + b_loop_ub = data.size(0) - 1; + for (i1 = 0; i1 <= b_loop_ub; i1++) { + b_data[i1 + b_data.size(0) * i] = data[i1 + data.size(0) * i]; + } + } + + shiftData(scalefactor, qzshift, dataPresent, b_data, dataLimits, simLimits, + shiftedData); + + // Calculate the reflectivity + b_callReflectivity(bulkIn, bulkOut, simLimits, repeatLayers, shiftedData, + layerSld, *ssubs, resolution, useImaginary, reflect, + simulation); + + // Apply background correction, either to the simulation or the data + applyBackgroundCorrection(reflect, simulation, shiftedData, background, + contrastBackgroundsType); + + // Calculate chi squared. + *chiSq = chiSquared(shiftedData, reflect, params); + } + + void coreLayersCalculation(const ::coder::array &contrastLayers, + real_T rough, const char_T geometry_data[], const int32_T geometry_size[2], + real_T bulkIn, real_T bulkOut, real_T resample, boolean_T calcSld, real_T + scalefactor, real_T qzshift, real_T dataPresent, const ::coder::array< + real_T, 2U> &data, const real_T dataLimits[2], const real_T simLimits[2], + const real_T repeatLayers[2], real_T background, real_T resolution, real_T + contrastBackgroundsType, real_T params, const real_T resamPars[2], + boolean_T useImaginary, ::coder::array &sldProfile, ::coder:: + array &reflect, ::coder::array &simulation, :: + coder::array &shiftedData, ::coder::array + &theseLayers, ::coder::array &resamLayers, real_T *chiSq, + real_T *ssubs) + { + ::coder::array b_data; + ::coder::array b_theseLayers; + ::coder::array c_theseLayers; + ::coder::array layerSld; + ::coder::array sldProfileIm; + ::coder::array thisSldLays; + ::coder::array thisSldLaysIm; + ::coder::array d_theseLayers; + int32_T b_loop_ub; + int32_T i; + int32_T i1; + int32_T loop_ub; + + // This is the main reflectivity calculation for all Layers models in the + // non polarised target function. + // + // The function first arranges the + // roughness' in the correct order according + // to geometry. Then, if required it calculates the SLD profile and if + // requested resamples this into a number of zero-roughness layers + // (roughness resampling). It the applies any scalefactors and qz shifts + // the data requires. This is done before calculating the reflectivity to + // ensure that the reflectivity is calculated over the same range in qz as + // the shifted datapoints. The main reflectivity calculation is then + // called, including the resolution function. The calculation outputs two + // profiles - 'reflect' which is the same range as the points, and + // 'simulation' which can be a different range to allow extrapolation. + // The background correction is the applied, and finally chi-squared is + // calculated. + // + // Inputs: + // contrastLayers : + // rough : + // geometry : + // bulkIn : + // bulkOut : + // resample : + // calcSld : + // scalefactor : + // qzshift : + // dataPresent : + // data : + // dataLimits : + // simLimits : + // repeatLayers : + // background : + // resol : + // contrastBackgroundsType : + // params : + // parallelPoints : + // + // Outputs: + // + // ------------------------------------------------------------------------ + // + // (c) Arwel Hughes - 12/1/21 + // + // Last Modified: 12/1/21 by Arwel Hughes. + // + // ------------------------------------------------------------------------ + // Pre-definition for Coder + thisSldLaysIm.set_size(1, 2); + sldProfileIm.set_size(1, 2); + thisSldLaysIm[0] = 0.0; + sldProfileIm[0] = 0.0; + thisSldLaysIm[thisSldLaysIm.size(0)] = 0.0; + sldProfileIm[sldProfileIm.size(0)] = 0.0; + + // Bulid up the layers matrix for this contrast + if (!useImaginary) { + groupLayersMod(contrastLayers, rough, geometry_data, geometry_size, + bulkIn, bulkOut, layerSld, ssubs); + theseLayers.set_size(layerSld.size(0), 3); + loop_ub = layerSld.size(0); + for (i = 0; i < 3; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } else { + groupLayersModImaginary(contrastLayers, rough, geometry_data, + geometry_size, bulkIn, bulkOut, layerSld, ssubs); + theseLayers.set_size(layerSld.size(0), 4); + loop_ub = layerSld.size(0); + for (i = 0; i < 4; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } + + // Make the SLD profiles. + // If resampling is needed, then enforce the calcSLD flag, so as to catch + // the error af trying to resample a non-existent profile. + if ((resample == 1.0) && (!calcSld)) { + calcSld = true; + } + + // If calc SLD flag is set, then calculate the SLD profile + if (calcSld) { + // If we need them both, we process real and imaginary parts of the SLD + // seperately... + if (useImaginary) { + int32_T result; + int8_T input_sizes_idx_1; + int8_T sizes_idx_1; + boolean_T empty_non_axis_sizes; + if (theseLayers.size(1) < 4) { + i = 0; + i1 = 0; + } else { + i = 3; + i1 = 4; + } + + if (theseLayers.size(0) != 0) { + result = theseLayers.size(0); + } else { + result = 0; + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + input_sizes_idx_1 = 2; + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || ((theseLayers.size(0) != 0) && (i1 - i != + 0))) { + sizes_idx_1 = static_cast(i1 - i); + } else { + sizes_idx_1 = 0; + } + + b_theseLayers.set_size(theseLayers.size(0), 2); + loop_ub = theseLayers.size(0); + for (int32_T i2{0}; i2 < 2; i2++) { + for (b_loop_ub = 0; b_loop_ub < loop_ub; b_loop_ub++) { + b_theseLayers[b_loop_ub + b_theseLayers.size(0) * i2] = + theseLayers[b_loop_ub + theseLayers.size(0) * i2]; + } + } + + loop_ub = i1 - i; + c_theseLayers.set_size(theseLayers.size(0), loop_ub); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = theseLayers.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + c_theseLayers[i2 + c_theseLayers.size(0) * i1] = theseLayers[i2 + + theseLayers.size(0) * (i + i1)]; + } + } + + thisSldLays.set_size(result, input_sizes_idx_1 + sizes_idx_1); + loop_ub = input_sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * i] = b_theseLayers[i1 + + result * i]; + } + } + + loop_ub = sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * (i + input_sizes_idx_1)] = + c_theseLayers[i1 + result * i]; + } + } + + if (theseLayers.size(0) != 0) { + result = theseLayers.size(0); + } else { + result = 0; + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + input_sizes_idx_1 = 1; + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { + sizes_idx_1 = static_cast(theseLayers.size(1) - 2); + } else { + sizes_idx_1 = 0; + } + + d_theseLayers.set_size(theseLayers.size(0)); + loop_ub = theseLayers.size(0); + for (i = 0; i < loop_ub; i++) { + d_theseLayers[i] = theseLayers[i]; + } + + c_theseLayers.set_size(theseLayers.size(0), theseLayers.size(1) - 2); + loop_ub = theseLayers.size(1); + b_loop_ub = theseLayers.size(0); + for (i = 0; i <= loop_ub - 3; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + c_theseLayers[i1 + c_theseLayers.size(0) * i] = theseLayers[i1 + + theseLayers.size(0) * (i + 2)]; + } + } + + thisSldLaysIm.set_size(result, input_sizes_idx_1 + sizes_idx_1); + loop_ub = input_sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLaysIm[i1] = d_theseLayers[i1]; + } + } + + loop_ub = sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < result; i1++) { + thisSldLaysIm[i1 + thisSldLaysIm.size(0) * (i + input_sizes_idx_1)] + = c_theseLayers[i1 + result * i]; + } + } + } else { + thisSldLays.set_size(theseLayers.size(0), theseLayers.size(1)); + loop_ub = theseLayers.size(1); + b_loop_ub = theseLayers.size(0); + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + thisSldLays[i1 + thisSldLays.size(0) * i] = theseLayers[i1 + + theseLayers.size(0) * i]; + } + } + } + + makeSLDProfiles(bulkIn, bulkOut, thisSldLays, *ssubs, repeatLayers, + b_theseLayers); + sldProfile.set_size(b_theseLayers.size(0), 2); + loop_ub = b_theseLayers.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + sldProfile[i1 + sldProfile.size(0) * i] = b_theseLayers[i1 + + b_theseLayers.size(0) * i]; + } + } + + // If we have imaginary, we are also + // going to need an SLD profile for the imaginary part + if (useImaginary) { + // Note bulkIn and bulkOut = 0 since there is never any imaginary part for + // the bulk phases.. + makeSLDProfiles(thisSldLaysIm, *ssubs, repeatLayers, b_theseLayers); + sldProfileIm.set_size(b_theseLayers.size(0), 2); + loop_ub = b_theseLayers.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + sldProfileIm[i1 + sldProfileIm.size(0) * i] = b_theseLayers[i1 + + b_theseLayers.size(0) * i]; + } + } + } + } else { + sldProfile.set_size(1, 2); + sldProfile[0] = 0.0; + sldProfile[sldProfile.size(0)] = 0.0; + } + + // If required, then resample the SLD + if (resample == 1.0) { + if (!useImaginary) { + resampleLayers(sldProfile, resamPars, layerSld); + } else { + b_resampleLayersReIm(sldProfile, sldProfileIm, resamPars, layerSld); + } + + resamLayers.set_size(layerSld.size(0), layerSld.size(1)); + loop_ub = layerSld.size(1); + b_loop_ub = layerSld.size(0); + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + resamLayers[i1 + resamLayers.size(0) * i] = layerSld[i1 + + layerSld.size(0) * i]; + } + } + } else { + resamLayers.set_size(1, 3); + resamLayers[0] = 0.0; + resamLayers[resamLayers.size(0)] = 0.0; + resamLayers[resamLayers.size(0) * 2] = 0.0; + } + + // Apply scale factors and q shifts to the data + b_data.set_size(data.size(0), data.size(1)); + loop_ub = data.size(1) - 1; + for (i = 0; i <= loop_ub; i++) { + b_loop_ub = data.size(0) - 1; + for (i1 = 0; i1 <= b_loop_ub; i1++) { + b_data[i1 + b_data.size(0) * i] = data[i1 + data.size(0) * i]; + } + } + + shiftData(scalefactor, qzshift, dataPresent, b_data, dataLimits, simLimits, + shiftedData); + + // Calculate the reflectivity + callReflectivity(bulkIn, bulkOut, simLimits, repeatLayers, shiftedData, + layerSld, *ssubs, resolution, useImaginary, reflect, + simulation); + + // Apply background correction, either to the simulation or the data + applyBackgroundCorrection(reflect, simulation, shiftedData, background, + contrastBackgroundsType); + + // Calculate chi squared. + *chiSq = chiSquared(shiftedData, reflect, params); + } + } +} + +// End of code generation (coreLayersCalculation.cpp) diff --git a/RAT/coreLayersCalculation.h b/RAT/coreLayersCalculation.h new file mode 100644 index 00000000..6bc8b3a1 --- /dev/null +++ b/RAT/coreLayersCalculation.h @@ -0,0 +1,53 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// coreLayersCalculation.h +// +// Code generation for function 'coreLayersCalculation' +// +#ifndef CORELAYERSCALCULATION_H +#define CORELAYERSCALCULATION_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + void b_coreLayersCalculation(const ::coder::array + &contrastLayers, real_T rough, const char_T geometry_data[], const int32_T + geometry_size[2], real_T bulkIn, real_T bulkOut, real_T resample, + boolean_T calcSld, real_T scalefactor, real_T qzshift, real_T dataPresent, + const ::coder::array &data, const real_T dataLimits[2], const + real_T simLimits[2], const real_T repeatLayers[2], real_T background, + real_T resolution, real_T contrastBackgroundsType, real_T params, const + real_T resamPars[2], boolean_T useImaginary, ::coder::array + &sldProfile, ::coder::array &reflect, ::coder::array &simulation, ::coder::array &shiftedData, ::coder::array< + real_T, 2U> &theseLayers, ::coder::array &resamLayers, real_T * + chiSq, real_T *ssubs); + void coreLayersCalculation(const ::coder::array &contrastLayers, + real_T rough, const char_T geometry_data[], const int32_T geometry_size[2], + real_T bulkIn, real_T bulkOut, real_T resample, boolean_T calcSld, real_T + scalefactor, real_T qzshift, real_T dataPresent, const ::coder::array< + real_T, 2U> &data, const real_T dataLimits[2], const real_T simLimits[2], + const real_T repeatLayers[2], real_T background, real_T resolution, real_T + contrastBackgroundsType, real_T params, const real_T resamPars[2], + boolean_T useImaginary, ::coder::array &sldProfile, ::coder:: + array &reflect, ::coder::array &simulation, :: + coder::array &shiftedData, ::coder::array + &theseLayers, ::coder::array &resamLayers, real_T *chiSq, + real_T *ssubs); + } +} + +#endif + +// End of code generation (coreLayersCalculation.h) diff --git a/RAT/cov.cpp b/RAT/cov.cpp new file mode 100644 index 00000000..754b8303 --- /dev/null +++ b/RAT/cov.cpp @@ -0,0 +1,149 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// cov.cpp +// +// Code generation for function 'cov' +// + +// Include files +#include "cov.h" +#include "isrow.h" +#include "rt_nonfinite.h" +#include "xgemm.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + namespace coder + { + static void local_cov(::coder::array &x, ::coder::array &c); + static real_T local_cov(::coder::array &x); + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + static void local_cov(::coder::array &x, ::coder::array &c) + { + int32_T b_i; + int32_T j; + int32_T m; + int32_T n; + m = x.size(0); + n = x.size(1); + c.set_size(x.size(1), x.size(1)); + j = x.size(1); + for (int32_T i{0}; i < j; i++) { + b_i = x.size(1); + for (int32_T i1{0}; i1 < b_i; i1++) { + c[i1 + c.size(0) * i] = 0.0; + } + } + + if ((x.size(0) == 0) || (x.size(1) == 0)) { + c.set_size(x.size(1), x.size(1)); + j = x.size(1); + for (int32_T i{0}; i < j; i++) { + b_i = x.size(1); + for (int32_T i1{0}; i1 < b_i; i1++) { + c[i1 + c.size(0) * i] = rtNaN; + } + } + } else if (x.size(0) >= 2) { + for (j = 0; j < n; j++) { + real_T muj; + muj = 0.0; + for (b_i = 0; b_i < m; b_i++) { + muj += x[b_i + x.size(0) * j]; + } + + muj /= static_cast(m); + for (b_i = 0; b_i < m; b_i++) { + x[b_i + x.size(0) * j] = x[b_i + x.size(0) * j] - muj; + } + } + + c.set_size(x.size(1), x.size(1)); + j = x.size(1); + b_i = x.size(1); + for (int32_T i{0}; i < j; i++) { + for (int32_T i1{0}; i1 < b_i; i1++) { + c[i1 + c.size(0) * i] = 0.0; + } + } + + internal::blas::xgemm(x.size(1), x.size(1), x.size(0), 1.0 / ( + static_cast(x.size(0)) - 1.0), x, x.size(0), x, x.size(0), c, + x.size(1)); + } + } + + static real_T local_cov(::coder::array &x) + { + real_T c; + int32_T m; + m = x.size(0) - 1; + c = 0.0; + if (x.size(0) == 0) { + c = rtNaN; + } else if (x.size(0) >= 2) { + real_T muj; + muj = 0.0; + for (int32_T i{0}; i <= m; i++) { + muj += x[i]; + } + + muj /= static_cast(x.size(0)); + for (int32_T i{0}; i <= m; i++) { + x[i] = x[i] - muj; + } + + c = internal::blas::xgemm(x.size(0), 1.0 / (static_cast(x.size(0)) + - 1.0), x, x); + } + + return c; + } + + void cov(const ::coder::array &x, ::coder::array &xy) + { + ::coder::array b_x; + ::coder::array c_x; + if (isrow(x)) { + int32_T loop_ub; + c_x.set_size(x.size(1)); + loop_ub = x.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + c_x[i] = x[x.size(0) * i]; + } + + xy.set_size(1, 1); + xy[0] = local_cov(c_x); + } else { + int32_T loop_ub; + b_x.set_size(x.size(0), x.size(1)); + loop_ub = x.size(1) - 1; + for (int32_T i{0}; i <= loop_ub; i++) { + int32_T b_loop_ub; + b_loop_ub = x.size(0) - 1; + for (int32_T i1{0}; i1 <= b_loop_ub; i1++) { + b_x[i1 + b_x.size(0) * i] = x[i1 + x.size(0) * i]; + } + } + + local_cov(b_x, xy); + } + } + } +} + +// End of code generation (cov.cpp) diff --git a/RAT/cov.h b/RAT/cov.h new file mode 100644 index 00000000..59091130 --- /dev/null +++ b/RAT/cov.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// cov.h +// +// Code generation for function 'cov' +// +#ifndef COV_H +#define COV_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void cov(const ::coder::array &x, ::coder::array &xy); + } +} + +#endif + +// End of code generation (cov.h) diff --git a/RAT/customModelClass.cpp b/RAT/customModelClass.cpp deleted file mode 100644 index 408a7ad3..00000000 --- a/RAT/customModelClass.cpp +++ /dev/null @@ -1,483 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// customModelClass.cpp -// -// Code generation for function 'customModelClass' -// - -// Include files -#include "customModelClass.h" -#include "backSort.h" -#include "callCppFunc.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rt_nonfinite.h" -#include "strcmp.h" -#include "coder_array.h" -#include "coder_bounded_array.h" - -// Type Definitions -namespace RAT -{ - struct cell_wrap_34 - { - ::coder::array f1; - }; - - struct cell_wrap_35 - { - ::coder::array f1; - }; -} - -// Function Declarations -namespace RAT -{ - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 1U> &r1); - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 1U> &r1); -} - -// Function Definitions -namespace RAT -{ - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 1U> &r1) - { - int32_T i; - r1.set_size(r.size(0)); - i = r.size(0); - for (int32_T i1{0}; i1 < i; i1++) { - int32_T loop_ub; - loop_ub = r[i1].f1.size(1); - r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); - for (int32_T i2{0}; i2 < loop_ub; i2++) { - int32_T b_loop_ub; - b_loop_ub = r[i1].f1.size(0); - for (int32_T i3{0}; i3 < b_loop_ub; i3++) { - r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) - * i2]; - } - } - } - } - - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 1U> &r1) - { - int32_T i; - r1.set_size(r.size(0)); - i = r.size(0); - for (int32_T i1{0}; i1 < i; i1++) { - int32_T loop_ub; - loop_ub = r[i1].f1.size(1); - r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); - for (int32_T i2{0}; i2 < loop_ub; i2++) { - int32_T b_loop_ub; - b_loop_ub = r[i1].f1.size(0); - for (int32_T i3{0}; i3 < b_loop_ub; i3++) { - r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) - * i2]; - } - } - } - } - - void customModelClass::processCustomLayers(const ::coder::array - &cBacks, const ::coder::array &cShifts, const ::coder::array< - real_T, 2U> &cScales, const ::coder::array &cNbas, const ::coder:: - array &cNbss, const ::coder::array &cRes, const :: - coder::array &backs, const ::coder::array &shifts, - const ::coder::array &sf, const ::coder::array &nba, - const ::coder::array &nbs, const ::coder::array &res, - const ::coder::array &cCustFiles, real_T numberOfContrasts, - const ::coder::array &customFiles, const ::coder::array< - real_T, 2U> ¶ms, boolean_T useImaginary, ::coder::array - &allLayers, ::coder::array &allRoughs) - { - ::coder::array tempAllLayers; - ::coder::array b_params; - ::coder::array thisContrastLayers; - real_T a__1; - real_T a__2; - real_T a__3; - real_T a__4; - real_T bulkIn; - real_T bulkOut; - real_T d1; - int32_T loop_ub_tmp; - - // Top-level function for processing custom layers for all the - // contrasts. - // Do some pre-definitions to keep the compiler happy... - loop_ub_tmp = static_cast(numberOfContrasts); - allRoughs.set_size(loop_ub_tmp); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - allRoughs[i] = 0.0; - } - - tempAllLayers.set_size(loop_ub_tmp); - for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - real_T d; - int32_T b_index; - - // TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's.. - // Choose which custom file is associated with this contrast - // Check what language it is.... - // ... and path - // ....also file. - // Find values of 'bulkIn' and 'bulkOut' for this - // contrast... - backSort(cBacks[b_i], cShifts[b_i], cScales[b_i], cNbas[b_i], cNbss[b_i], - cRes[b_i], backs, shifts, sf, nba, nbs, res, &a__1, &a__2, &a__3, - &bulkIn, &bulkOut, &a__4); - thisContrastLayers.set_size(1, 3); - thisContrastLayers[0] = 1.0; - thisContrastLayers[thisContrastLayers.size(0)] = 1.0; - thisContrastLayers[thisContrastLayers.size(0) * 2] = 1.0; - - // typeDef - d = cCustFiles[b_i]; - if (coder::internal::j_strcmp(customFiles[static_cast(d) - 1].f1 - [1].f1.data, customFiles[static_cast(d) - 1].f1[1].f1.size)) - { - b_index = 0; - } else if (coder::internal::k_strcmp(customFiles[static_cast(d) - - 1].f1[1].f1.data, customFiles[static_cast(d) - 1].f1 - [1].f1.size)) { - b_index = 1; - } else if (coder::internal::l_strcmp(customFiles[static_cast(d) - - 1].f1[1].f1.data, customFiles[static_cast(d) - 1].f1 - [1].f1.size)) { - b_index = 2; - } else { - b_index = -1; - } - - switch (b_index) { - case 0: - // Excecute a custom model function in the base Matlab workspace. - // This function uses feval to cause Matlab coder to pass excecution - // of the function named in 'fname' back to the base Matlab workspace, - // 'feval' generates an automatic coder.extrinsic call. - // Use a coder.extrinsic call here, so Coder will - // pass the excecution of the function back to the calling Matlab - // session. There is no need to explicitly declare the extrinsic - // as Coder automatically does this when it encounters 'feval' - // https://uk.mathworks.com/help/simulink/ug/use-matlab-engine-to-execute-a-function-call-in-generated-code.html - // Pre-define the outputs to keep the compiler happy - // Need to define the size of the outputs with coder preprocessor - // directives - // This maybe should be a 'coder.typeof' instead? - // - // % Because it is feval, coder sends this call to - // % the base Matlab workspace. The outputs of feval are mxArrays, - // % so we need to do some work afterwards casting these to doubles (below) - // - // % For backwards compatability with Rascal1... - // bulkOuts = zeros(nContrasts,1); - // bulkOuts(contrast) = bulkOut; - // - // % Feval is automatic call to base Matlab workspace.... - // [tempOut,tempRough] = feval(funcName,params,bulkIn,bulkOuts,contrast); - // - // % Tell coder n is doubles by defining it (otherwise 'size(n)' seems to return - // % [mxArray mxArray] not [double double]!), fill n with the size of the mxArray - // % 'tempOut', and use n to allocate the correct number of elements to 'output' - // % by filling output with zeros (i.e. output is an array of doubles) - // n = size(tempOut); - // - // % Copy the mxArrays to our doubles arrays, which then makes coder cast - // % the mxArrays to double. - // sRough = tempRough; - // output = tempOut; - thisContrastLayers.set_size(0, 0); - allRoughs[b_i] = 3.0; - break; - - case 1: - { - b_params.set_size(1, params.size(1)); - b_index = params.size(1) - 1; - for (int32_T i{0}; i <= b_index; i++) { - b_params[i] = params[i]; - } - - int32_T iv[2]; - int32_T iv1[2]; - int32_T iv2[2]; - thisContrastLayers.reserve(3000); - iv[0] = customFiles[static_cast(d) - 1].f1[0].f1.size[0]; - iv[1] = customFiles[static_cast(d) - 1].f1[0].f1.size[1]; - iv1[0] = customFiles[static_cast(d) - 1].f1[0].f1.size[0]; - iv1[1] = customFiles[static_cast(d) - 1].f1[0].f1.size[1]; - callCppFunc(b_params, bulkIn, bulkOut, static_cast(b_i) + 1.0, - customFiles[static_cast(d) - 1].f1[0].f1.data, iv, - customFiles[static_cast(d) - 1].f1[0].f1.data, - iv1, (real_T *)thisContrastLayers.data(), iv2, &d1); - allRoughs[b_i] = d1; - (*(int32_T (*)[2])thisContrastLayers.size())[0] = iv2[0]; - (*(int32_T (*)[2])thisContrastLayers.size())[1] = iv2[1]; - } - break; - - case 2: - // Excecute a python custom model function in the base Matlab workspace. - // This function uses feval to cause Matlab coder to execute - // 'callPythonFunction' in the base Matlab workspace. - // 'feval' generates an automatic coder.extrinsic call... - // Use a coder.extrinsic call here, so Coder will - // pass the excecution of the function back to the calling Matlab - // session. There is no need to explicitly declare the extrinsic - // as Coder automatically does this when it encounters 'feval' - // https://uk.mathworks.com/help/simulink/ug/use-matlab-engine-to-execute-a-function-call-in-generated-code.html - // Pre-define the outputs to keep the compiler happy - // Need to define the size of the outputs with coder preprocessor - // directives - // This maybe should be a 'coder.typeof' instead? - // Because it is feval, coder sends this call to - // the base Matlab workspace. The outputs of feval are mxArrays, - // so we need to do some work afterwards casting these to doubles (below) - // [tempOut,tempRough] = feval('callPythonFunction',funcName,params,bulkIn,bulkOut,contrast); - // Tell coder n is doubles by defining it (otherwise 'size(n)' seems to return - // [mxArray mxArray] not [double double]!), fill n with the size of the mxArray - // 'tempOut', and use n to allocate the correct number of elements to 'output' - // by filling output with zeros (i.e. output is an array of doubles) - // n = size(tempOut); - // Copy the mxArrays to our doubles arrays, which then makes coder cast - // the mxArrays to double. - // sRough = tempRough; - // output = tempOut; - thisContrastLayers.set_size(0, 0); - allRoughs[b_i] = 3.0; - break; - } - - // If the output layers has 5 columns, then we need to do - // the hydration correction (the user has not done it in the - // custom function). Do that here.... - if (!useImaginary) { - // Applies the hydration correction to real value of layers - // if it is necessary.. (This is for when im(SLD) is not used) - // The only guidance we have to whether the user is using hydration - // in their custom model is the numbre of columns of the output - // [nlayers x nCols] - tempAllLayers[b_i].f1.set_size(thisContrastLayers.size(0), - thisContrastLayers.size(1)); - b_index = thisContrastLayers.size(1); - for (int32_T i{0}; i < b_index; i++) { - int32_T loop_ub; - loop_ub = thisContrastLayers.size(0); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - tempAllLayers[b_i].f1[i1 + tempAllLayers[b_i].f1.size(0) * i] = - thisContrastLayers[i1 + thisContrastLayers.size(0) * i]; - } - } - } else { - // Applies the hydration correction to real value of layers - // if it is necessary.. (This is for when im(SLD) is used) - // The only guidance we have to whether the user is using hydration - // in their custom model is the number of columns of the output - // [nlayers x nCols] - tempAllLayers[b_i].f1.set_size(thisContrastLayers.size(0), - thisContrastLayers.size(1)); - b_index = thisContrastLayers.size(1); - for (int32_T i{0}; i < b_index; i++) { - int32_T loop_ub; - loop_ub = thisContrastLayers.size(0); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - tempAllLayers[b_i].f1[i1 + tempAllLayers[b_i].f1.size(0) * i] = - thisContrastLayers[i1 + thisContrastLayers.size(0) * i]; - } - } - } - } - - cast(tempAllLayers, allLayers); - } - - void customModelClass::processCustomXY(const ::coder::array - &cBacks, const ::coder::array &cShifts, const ::coder::array< - real_T, 2U> &cScales, const ::coder::array &cNbas, const ::coder:: - array &cNbss, const ::coder::array &cRes, const :: - coder::array &backs, const ::coder::array &shifts, - const ::coder::array &sf, const ::coder::array &nba, - const ::coder::array &nbs, const ::coder::array &res, - const ::coder::array &cCustFiles, real_T numberOfContrasts, - const ::coder::array &customFiles, const ::coder::array< - real_T, 2U> ¶ms, ::coder::array &allSLDs, ::coder:: - array &allRoughs) - { - ::coder::array tempAllSLDs; - ::coder::array b_params; - real_T tmp_data[3000]; - real_T a__5; - real_T a__6; - real_T a__7; - real_T a__8; - real_T bulkIn; - real_T bulkOut; - real_T d1; - int32_T loop_ub_tmp; - - // Top-level function for processing custom XY profiles for all the - // contrasts. - // Do some pre-definitions to keep the compiler happy... - loop_ub_tmp = static_cast(numberOfContrasts); - allRoughs.set_size(loop_ub_tmp); - tempAllSLDs.set_size(loop_ub_tmp); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - allRoughs[i] = 0.0; - - // Type def as double (size not important) - tempAllSLDs[i].f1.set_size(1, 2); - tempAllSLDs[i].f1[0] = 0.0; - tempAllSLDs[i].f1[tempAllSLDs[i].f1.size(0)] = 0.0; - } - - // 3 columns to allow for potential imaginary curve - for (int32_T i{0}; i < loop_ub_tmp; i++) { - real_T d; - int32_T b_index; - - // TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's.. - // Choose which custom file is associated with this contrast - // Check what language it is.... - // ... and path - // ....also file. - // Find values of 'bulkIn' and 'bulkOut' for thid - // contrast... - backSort(cBacks[i], cShifts[i], cScales[i], cNbas[i], cNbss[i], cRes[i], - backs, shifts, sf, nba, nbs, res, &a__5, &a__6, &a__7, &bulkIn, - &bulkOut, &a__8); - d = cCustFiles[i]; - if (coder::internal::j_strcmp(customFiles[static_cast(d) - 1].f1 - [1].f1.data, customFiles[static_cast(d) - 1].f1[1].f1.size)) - { - b_index = 0; - } else if (coder::internal::k_strcmp(customFiles[static_cast(d) - - 1].f1[1].f1.data, customFiles[static_cast(d) - 1].f1 - [1].f1.size)) { - b_index = 1; - } else if (coder::internal::l_strcmp(customFiles[static_cast(d) - - 1].f1[1].f1.data, customFiles[static_cast(d) - 1].f1 - [1].f1.size)) { - b_index = 2; - } else { - b_index = -1; - } - - switch (b_index) { - case 0: - // Excecute a custom model function in the base Matlab workspace. - // This function uses feval to cause Matlab coder to pass excecution - // of the function named in 'fname' back to the base Matlab workspace, - // 'feval' generates an automatic coder.extrinsic call. - // Use a coder.extrinsic call here, so Coder will - // pass the excecution of the function back to the calling Matlab - // session. There is no need to explicitly declare the extrinsic - // as Coder automatically does this when it encounters 'feval' - // https://uk.mathworks.com/help/simulink/ug/use-matlab-engine-to-execute-a-function-call-in-generated-code.html - // Pre-define the outputs to keep the compiler happy - // Need to define the size of the outputs with coder preprocessor - // directives - // This maybe should be a 'coder.typeof' instead? - // - // % Because it is feval, coder sends this call to - // % the base Matlab workspace. The outputs of feval are mxArrays, - // % so we need to do some work afterwards casting these to doubles (below) - // - // % For backwards compatability with Rascal1... - // bulkOuts = zeros(nContrasts,1); - // bulkOuts(contrast) = bulkOut; - // - // % Feval is automatic call to base Matlab workspace.... - // [tempOut,tempRough] = feval(funcName,params,bulkIn,bulkOuts,contrast); - // - // % Tell coder n is doubles by defining it (otherwise 'size(n)' seems to return - // % [mxArray mxArray] not [double double]!), fill n with the size of the mxArray - // % 'tempOut', and use n to allocate the correct number of elements to 'output' - // % by filling output with zeros (i.e. output is an array of doubles) - // n = size(tempOut); - // - // % Copy the mxArrays to our doubles arrays, which then makes coder cast - // % the mxArrays to double. - // sRough = tempRough; - // output = tempOut; - tempAllSLDs[i].f1.set_size(0, 0); - allRoughs[i] = 3.0; - break; - - case 1: - { - int32_T tmp_size[2]; - b_params.set_size(1, params.size(1)); - b_index = params.size(1) - 1; - for (int32_T b_i{0}; b_i <= b_index; b_i++) { - b_params[b_i] = params[b_i]; - } - - int32_T iv[2]; - int32_T iv1[2]; - iv[0] = customFiles[static_cast(d) - 1].f1[0].f1.size[0]; - iv[1] = customFiles[static_cast(d) - 1].f1[0].f1.size[1]; - iv1[0] = customFiles[static_cast(d) - 1].f1[0].f1.size[0]; - iv1[1] = customFiles[static_cast(d) - 1].f1[0].f1.size[1]; - callCppFunc(b_params, bulkIn, bulkOut, static_cast(i) + 1.0, - customFiles[static_cast(d) - 1].f1[0].f1.data, iv, - customFiles[static_cast(d) - 1].f1[0].f1.data, - iv1, tmp_data, tmp_size, &d1); - allRoughs[i] = d1; - b_index = tmp_size[0]; - tempAllSLDs[i].f1.set_size(tmp_size[0], 3); - for (int32_T b_i{0}; b_i < 3; b_i++) { - for (int32_T i1{0}; i1 < b_index; i1++) { - tempAllSLDs[i].f1[i1 + tempAllSLDs[i].f1.size(0) * b_i] = - tmp_data[i1 + tmp_size[0] * b_i]; - } - } - } - break; - - case 2: - // Excecute a python custom model function in the base Matlab workspace. - // This function uses feval to cause Matlab coder to execute - // 'callPythonFunction' in the base Matlab workspace. - // 'feval' generates an automatic coder.extrinsic call... - // Use a coder.extrinsic call here, so Coder will - // pass the excecution of the function back to the calling Matlab - // session. There is no need to explicitly declare the extrinsic - // as Coder automatically does this when it encounters 'feval' - // https://uk.mathworks.com/help/simulink/ug/use-matlab-engine-to-execute-a-function-call-in-generated-code.html - // Pre-define the outputs to keep the compiler happy - // Need to define the size of the outputs with coder preprocessor - // directives - // This maybe should be a 'coder.typeof' instead? - // Because it is feval, coder sends this call to - // the base Matlab workspace. The outputs of feval are mxArrays, - // so we need to do some work afterwards casting these to doubles (below) - // [tempOut,tempRough] = feval('callPythonFunction',funcName,params,bulkIn,bulkOut,contrast); - // Tell coder n is doubles by defining it (otherwise 'size(n)' seems to return - // [mxArray mxArray] not [double double]!), fill n with the size of the mxArray - // 'tempOut', and use n to allocate the correct number of elements to 'output' - // by filling output with zeros (i.e. output is an array of doubles) - // n = size(tempOut); - // Copy the mxArrays to our doubles arrays, which then makes coder cast - // the mxArrays to double. - // sRough = tempRough; - // output = tempOut; - tempAllSLDs[i].f1.set_size(0, 0); - allRoughs[i] = 3.0; - break; - } - } - - cast(tempAllSLDs, allSLDs); - } -} - -// End of code generation (customModelClass.cpp) diff --git a/RAT/customModelClass.h b/RAT/customModelClass.h deleted file mode 100644 index 86c43f46..00000000 --- a/RAT/customModelClass.h +++ /dev/null @@ -1,59 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// customModelClass.h -// -// Code generation for function 'customModelClass' -// -#ifndef CUSTOMMODELCLASS_H -#define CUSTOMMODELCLASS_H - -// Include files -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Type Declarations -namespace RAT -{ - struct cell_wrap_7; - struct cell_wrap_15; -} - -// Type Definitions -namespace RAT -{ - class customModelClass - { - public: - static void processCustomLayers(const ::coder::array &cBacks, - const ::coder::array &cShifts, const ::coder::array - &cScales, const ::coder::array &cNbas, const ::coder::array< - real_T, 2U> &cNbss, const ::coder::array &cRes, const ::coder:: - array &backs, const ::coder::array &shifts, const :: - coder::array &sf, const ::coder::array &nba, const - ::coder::array &nbs, const ::coder::array &res, - const ::coder::array &cCustFiles, real_T numberOfContrasts, - const ::coder::array &customFiles, const ::coder::array< - real_T, 2U> ¶ms, boolean_T useImaginary, ::coder::array &allLayers, ::coder::array &allRoughs); - static void processCustomXY(const ::coder::array &cBacks, const :: - coder::array &cShifts, const ::coder::array - &cScales, const ::coder::array &cNbas, const ::coder::array< - real_T, 2U> &cNbss, const ::coder::array &cRes, const ::coder:: - array &backs, const ::coder::array &shifts, const :: - coder::array &sf, const ::coder::array &nba, const - ::coder::array &nbs, const ::coder::array &res, - const ::coder::array &cCustFiles, real_T numberOfContrasts, - const ::coder::array &customFiles, const ::coder::array< - real_T, 2U> ¶ms, ::coder::array &allSLDs, ::coder:: - array &allRoughs); - }; -} - -#endif - -// End of code generation (customModelClass.h) diff --git a/RAT/deopt.cpp b/RAT/deopt.cpp new file mode 100644 index 00000000..c4ab08f3 --- /dev/null +++ b/RAT/deopt.cpp @@ -0,0 +1,833 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// deopt.cpp +// +// Code generation for function 'deopt' +// + +// Include files +#include "deopt.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "leftWin.h" +#include "mergesort.h" +#include "rand.h" +#include "randperm.h" +#include "repmat.h" +#include "rt_nonfinite.h" +#include "runDE.h" +#include "strcmp.h" +#include "validate_print_arguments.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, int32_T in2, + const i_struct_T *in3, const ::coder::array &in4); + static void h_binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const :: + coder::array &in4, const ::coder::array &in5, const :: + coder::array &in6, const int32_T in7[2], real_T in8); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, int32_T in2, + const i_struct_T *in3, const ::coder::array &in4) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + int32_T stride_2_1; + int32_T stride_3_1; + stride_0_1 = (in3->FVr_minbound.size(1) != 1); + stride_1_1 = (in4.size(1) != 1); + stride_2_1 = (in3->FVr_maxbound.size(1) != 1); + stride_3_1 = (in3->FVr_minbound.size(1) != 1); + if (in3->FVr_minbound.size(1) == 1) { + i = in3->FVr_maxbound.size(1); + } else { + i = in3->FVr_minbound.size(1); + } + + if (i == 1) { + i = in4.size(1); + } else if (in3->FVr_minbound.size(1) == 1) { + i = in3->FVr_maxbound.size(1); + } else { + i = in3->FVr_minbound.size(1); + } + + if (i == 1) { + loop_ub = in3->FVr_minbound.size(1); + } else { + if (in3->FVr_minbound.size(1) == 1) { + i = in3->FVr_maxbound.size(1); + } else { + i = in3->FVr_minbound.size(1); + } + + if (i == 1) { + loop_ub = in4.size(1); + } else if (in3->FVr_minbound.size(1) == 1) { + loop_ub = in3->FVr_maxbound.size(1); + } else { + loop_ub = in3->FVr_minbound.size(1); + } + } + + for (i = 0; i < loop_ub; i++) { + in1[in2 + in1.size(0) * i] = in3->FVr_minbound[i * stride_0_1] + in4[i * + stride_1_1] * (in3->FVr_maxbound[i * stride_2_1] - in3->FVr_minbound[i * + stride_3_1]); + } + } + + static void h_binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const :: + coder::array &in4, const ::coder::array &in5, const :: + coder::array &in6, const int32_T in7[2], real_T in8) + { + int32_T aux_0_1; + int32_T aux_1_1; + int32_T aux_2_1; + int32_T aux_3_1; + int32_T aux_4_1; + int32_T aux_5_1; + int32_T b_in5; + int32_T b_in7; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_0_1; + int32_T stride_1_0; + int32_T stride_1_1; + int32_T stride_2_0; + int32_T stride_2_1; + int32_T stride_3_0; + int32_T stride_3_1; + int32_T stride_4_0; + int32_T stride_4_1; + int32_T stride_5_0; + int32_T stride_5_1; + b_in5 = in5.size(1); + b_in7 = in7[1]; + if (b_in7 == 1) { + i = b_in5; + } else { + i = b_in7; + } + + if (in3.size(0) == 1) { + if (i == 1) { + i = in4.size(0); + } else if (b_in7 == 1) { + i = b_in5; + } else { + i = b_in7; + } + } else { + i = in3.size(0); + } + + if (b_in7 == 1) { + i1 = b_in5; + } else { + i1 = b_in7; + } + + if (i == 1) { + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + } else if (in3.size(0) == 1) { + if (i1 == 1) { + i = in4.size(0); + } else if (b_in7 == 1) { + i = b_in5; + } else { + i = b_in7; + } + } else { + i = in3.size(0); + } + + if (in3.size(1) == 1) { + if (in2.size(1) == 1) { + i1 = in4.size(1); + } else { + i1 = in2.size(1); + } + } else { + i1 = in3.size(1); + } + + if (i1 == 1) { + if (in3.size(1) == 1) { + i1 = in2.size(1); + } else { + i1 = in3.size(1); + } + } else if (in3.size(1) == 1) { + if (in2.size(1) == 1) { + i1 = in4.size(1); + } else { + i1 = in2.size(1); + } + } else { + i1 = in3.size(1); + } + + in1.set_size(i, i1); + stride_0_0 = (in2.size(0) != 1); + stride_0_1 = (in2.size(1) != 1); + stride_1_0 = (in3.size(0) != 1); + stride_1_1 = (in3.size(1) != 1); + stride_2_0 = (in4.size(0) != 1); + stride_2_1 = (in4.size(1) != 1); + stride_3_0 = (b_in5 != 1); + stride_3_1 = (in2.size(1) != 1); + stride_4_0 = (b_in7 != 1); + stride_4_1 = (in2.size(1) != 1); + stride_5_0 = (in3.size(0) != 1); + stride_5_1 = (in3.size(1) != 1); + aux_0_1 = 0; + aux_1_1 = 0; + aux_2_1 = 0; + aux_3_1 = 0; + aux_4_1 = 0; + aux_5_1 = 0; + if (in3.size(1) == 1) { + if (in2.size(1) == 1) { + i = in4.size(1); + } else { + i = in2.size(1); + } + } else { + i = in3.size(1); + } + + if (i == 1) { + if (in3.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(1); + } + } else if (in3.size(1) == 1) { + if (in2.size(1) == 1) { + loop_ub = in4.size(1); + } else { + loop_ub = in2.size(1); + } + } else { + loop_ub = in3.size(1); + } + + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + int32_T i2; + i1 = in3.size(0); + b_loop_ub = in4.size(0); + if (b_in7 == 1) { + i2 = b_in5; + } else { + i2 = b_in7; + } + + if (i1 == 1) { + if (i2 == 1) { + i2 = b_loop_ub; + } else if (b_in7 == 1) { + i2 = b_in5; + } else { + i2 = b_in7; + } + } else { + i2 = i1; + } + + if (i2 == 1) { + if (i1 == 1) { + b_loop_ub = in2.size(0); + } else { + b_loop_ub = i1; + } + } else if (i1 == 1) { + if (b_in7 == 1) { + i1 = b_in5; + } else { + i1 = b_in7; + } + + if (i1 != 1) { + if (b_in7 == 1) { + b_loop_ub = b_in5; + } else { + b_loop_ub = b_in7; + } + } + } else { + b_loop_ub = i1; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + in1[i1 + in1.size(0) * i] = in2[i1 * stride_0_0 + in2.size(0) * aux_0_1] + * static_cast(static_cast(in3[i1 * stride_1_0 + + in3.size(0) * aux_1_1]) < 0.5) + (in4[i1 * stride_2_0 + in4.size(0) * + aux_2_1] + (in2[(static_cast(in5[i1 * stride_3_0]) + in2.size + (0) * aux_3_1) - 1] - in2[(static_cast + (in6[i1 * stride_4_0]) + in2.size(0) * aux_4_1) - 1]) * in8) * + static_cast(in3[i1 * stride_5_0 + in3.size(0) * aux_5_1]); + } + + aux_5_1 += stride_5_1; + aux_4_1 += stride_4_1; + aux_3_1 += stride_3_1; + aux_2_1 += stride_2_1; + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + } + + void deopt(const struct5_T *problem, const ::coder::array + &problemDefCells_f1, const ::coder::array + &problemDefCells_f2, const ::coder::array + &problemDefCells_f3, const ::coder::array + &problemDefCells_f4, const ::coder::array + &problemDefCells_f5, const ::coder::array + &problemDefCells_f6, const ::coder::array + &problemDefCells_f14, const ::coder::array + &problemDefCells_f19, const char_T controls_parallel_data[], const + int32_T controls_parallel_size[2], const real_T controls_resamPars + [2], boolean_T controls_calcSldDuringFit, const char_T + controls_display_data[], const int32_T controls_display_size[2], + const struct3_T *controls_checks, const i_struct_T *S_struct, :: + coder::array &FVr_bestmem) + { + ::coder::array S_val; + ::coder::array FM_pm3; + ::coder::array FM_pop; + ::coder::array FM_ui; + ::coder::array FVr_a1; + ::coder::array FVr_a2; + ::coder::array FVr_a3; + ::coder::array b_FM_pop; + ::coder::array r; + ::coder::array r1; + ::coder::array FM_mui; + struct5_T b_problem; + real_T F_CR; + real_T I_D; + real_T I_NP; + real_T I_iter; + real_T I_itermax; + real_T S_bestval_FVr_oa; + real_T b; + real_T fWeight; + int32_T b_loop_ub_tmp; + int32_T i; + int32_T i1; + int32_T i2; + int32_T loop_ub; + int32_T loop_ub_tmp; + + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // Function: [FVr_bestmem,S_bestval,I_nfeval] = deopt(fname,S_struct) + // + // Author: Rainer Storn, Ken Price, Arnold Neumaier, Jim Van Zandt + // Description: Minimization of a user-supplied function with respect to x(1:I_D), + // using the differential evolution (DE) algorithm. + // DE works best if [FVr_minbound,FVr_maxbound] covers the region where the + // global minimum is expected. DE is also somewhat sensitive to + // the choice of the stepsize fWeight. A good initial guess is to + // choose fWeight from interval [0.5, 1], e.g. 0.8. F_CR, the crossover + // probability constant from interval [0, 1] helps to maintain + // the diversity of the population but should be close to 1 for most. + // practical cases. Only separable problems do better with CR close to 0. + // If the parameters are correlated, high values of F_CR work better. + // The reverse is true for no correlation. + // + // The number of population members I_NP is also not very critical. A + // good initial guess is 10*I_D. Depending on the difficulty of the + // problem I_NP can be lower than 10*I_D or must be higher than 10*I_D + // to achieve convergence. + // + // deopt is a vectorized variant of DE which, however, has a + // property which differs from the original version of DE: + // The random selection of vectors is performed by shuffling the + // population array. Hence a certain vector can't be chosen twice + // in the same term of the perturbation expression. + // Due to the vectorized expressions deopt executes fairly fast + // in MATLAB's interpreter environment. + // + // Parameters: fname (I) String naming a function f(x,y) to minimize. + // S_struct (I) Problem data vector (must remain fixed during the + // minimization). For details see Rundeopt.m. + // ---------members of S_struct---------------------------------------------------- + // F_VTR (I) "Value To Reach". deopt will stop its minimization + // if either the maximum number of iterations "I_itermax" + // is reached or the best parameter vector "FVr_bestmem" + // has found a value f(FVr_bestmem,y) <= F_VTR. + // FVr_minbound (I) Vector of lower bounds FVr_minbound(1) ... FVr_minbound(I_D) + // of initial population. + // *** note: these are not bound constraints!! *** + // FVr_maxbound (I) Vector of upper bounds FVr_maxbound(1) ... FVr_maxbound(I_D) + // of initial population. + // I_D (I) Number of parameters of the objective function. + // I_NP (I) Number of population members. + // I_itermax (I) Maximum number of iterations (generations). + // fWeight (I) DE-stepsize fWeight from interval [0, 2]. + // F_CR (I) Crossover probability constant from interval [0, 1]. + // I_strategy (I) 1 --> DE/rand/1 + // 2 --> DE/local-to-best/1 + // 3 --> DE/best/1 with jitter + // 4 --> DE/rand/1 with per-vector-dither + // 5 --> DE/rand/1 with per-generation-dither + // 6 --> DE/rand/1 either-or-algorithm + // I_refresh (I) Intermediate output will be produced after "I_refresh" + // iterations. No intermediate output will be produced + // if I_refresh is < 1. + // + // Return value: FVr_bestmem (O) Best parameter vector. + // S_bestval.I_nc (O) Number of constraints + // S_bestval.FVr_ca (O) Constraint values. 0 means the constraints + // are met. Values > 0 measure the distance + // to a particular constraint. + // S_bestval.I_no (O) Number of objectives. + // S_bestval.FVr_oa (O) Objective function values. + // I_nfeval (O) Number of function evaluations. + // + // Note: + // This program is free software; you can redistribute it and/or modify + // it under the terms of the GNU General Public License as published by + // the Free Software Foundation; either version 1, or (at your option) + // any later version. + // + // This program is distributed in the hope that it will be useful, + // but WITHOUT ANY WARRANTY; without even the implied warranty of + // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + // GNU General Public License for more details. A copy of the GNU + // General Public License can be obtained from the + // Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // -----This is just for notational convenience and to keep the code uncluttered.-------- + I_NP = S_struct->I_NP; + fWeight = S_struct->fWeight; + F_CR = S_struct->F_CR; + I_D = S_struct->I_D; + I_itermax = S_struct->I_itermax; + + // -----Check input variables--------------------------------------------- + if (S_struct->I_NP < 5.0) { + I_NP = 5.0; + printf(" I_NP increased to minimal value 5\n"); + fflush(stdout); + } + + if ((S_struct->F_CR < 0.0) || (S_struct->F_CR > 1.0)) { + F_CR = 0.5; + printf("F_CR should be from interval [0,1]; set to default value 0.5\n"); + fflush(stdout); + } + + if (S_struct->I_itermax <= 0.0) { + I_itermax = 200.0; + printf("I_itermax should be > 0; set to default value 200\n"); + fflush(stdout); + } + + // -----Initialize population and some arrays------------------------------- + i = static_cast(I_NP); + loop_ub_tmp = static_cast(S_struct->I_D); + FM_pop.set_size(i, loop_ub_tmp); + + // initialize FM_pop to gain speed + // ----FM_pop is a matrix of size I_NPx(I_D+1). It will be initialized------ + // ----with random values between the min and max values of the------------- + // ----parameters----------------------------------------------------------- + loop_ub = S_struct->FVr_minbound.size(1); + for (int32_T k{0}; k < i; k++) { + coder::b_rand(I_D, r); + if (S_struct->FVr_maxbound.size(1) == 1) { + i1 = S_struct->FVr_minbound.size(1); + } else { + i1 = S_struct->FVr_maxbound.size(1); + } + + if (r.size(1) == 1) { + if (S_struct->FVr_maxbound.size(1) == 1) { + i2 = S_struct->FVr_minbound.size(1); + } else { + i2 = S_struct->FVr_maxbound.size(1); + } + } else { + i2 = r.size(1); + } + + if ((S_struct->FVr_maxbound.size(1) == S_struct->FVr_minbound.size(1)) && + (r.size(1) == i1) && (S_struct->FVr_minbound.size(1) == i2)) { + for (i1 = 0; i1 < loop_ub; i1++) { + b = S_struct->FVr_minbound[i1]; + FM_pop[k + FM_pop.size(0) * i1] = b + r[i1] * (S_struct-> + FVr_maxbound[i1] - b); + } + } else { + binary_expand_op(FM_pop, k, S_struct, r); + } + } + + // number of function evaluations + // ------Evaluate the best member after initialization---------------------- + coder::repmat(I_NP, S_val); + + // start with first population member + b_FM_pop.set_size(1, FM_pop.size(1)); + loop_ub = FM_pop.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + b_FM_pop[i1] = FM_pop[FM_pop.size(0) * i1]; + } + + b_problem = *problem; + S_val[0] = intrafun(b_FM_pop, &b_problem, controls_parallel_data, + controls_parallel_size, controls_resamPars, + controls_calcSldDuringFit, controls_checks, + problemDefCells_f1, problemDefCells_f2, + problemDefCells_f3, problemDefCells_f4, + problemDefCells_f5, problemDefCells_f6, + problemDefCells_f14, problemDefCells_f19); + S_bestval_FVr_oa = S_val[0].FVr_oa; + + // best objective function value so far + b_loop_ub_tmp = static_cast(I_NP - 1.0); + loop_ub = FM_pop.size(1); + for (int32_T k{0}; k < b_loop_ub_tmp; k++) { + k_struct_T expl_temp; + + // check the remaining members + b_FM_pop.set_size(1, FM_pop.size(1)); + for (i1 = 0; i1 < loop_ub; i1++) { + b_FM_pop[i1] = FM_pop[(k + FM_pop.size(0) * i1) + 1]; + } + + b_problem = *problem; + expl_temp = intrafun(b_FM_pop, &b_problem, controls_parallel_data, + controls_parallel_size, controls_resamPars, + controls_calcSldDuringFit, controls_checks, + problemDefCells_f1, problemDefCells_f2, + problemDefCells_f3, problemDefCells_f4, + problemDefCells_f5, problemDefCells_f6, + problemDefCells_f14, problemDefCells_f19); + S_val[k + 1] = expl_temp; + if (leftWin(expl_temp.I_no, expl_temp.FVr_oa, S_bestval_FVr_oa) == 1.0) { + // save its location + S_bestval_FVr_oa = expl_temp.FVr_oa; + } + } + + // best member of current iteration + // best member ever + // ------DE-Minimization--------------------------------------------- + // ------FM_popold is the population which has to compete. It is-------- + // ------static through one iteration. FM_pop is the newly-------------- + // ------emerging population.---------------------------------------- + // initialize population matrix 1 + // initialize population matrix 2 + // initialize population matrix 3 + // initialize population matrix 4 + // initialize population matrix 5 + // initialize FVr_bestmember matrix + // intermediate population of perturbed vectors + // mask for intermediate population + // mask for old population + // rotating index array (size I_NP) + // rotating index array (size I_D) + // another rotating index array + // rotating index array for exponential crossover + // index array + FVr_bestmem.set_size(1, loop_ub_tmp); + for (i1 = 0; i1 < loop_ub_tmp; i1++) { + FVr_bestmem[i1] = 0.0; + } + + // + // FM_pop = zeros(I_NP,2); + I_iter = 1.0; + while ((I_iter < I_itermax) && (S_bestval_FVr_oa > S_struct->F_VTR)) { + real_T p[4]; + int32_T iv[4]; + int32_T FVr_rt_size[2]; + int32_T b_FVr_a1; + + // save the old population + // S_struct.FM_pop = FM_pop; + coder::b_rand(p); + iv[0] = 0; + iv[1] = 0; + iv[2] = 0; + iv[3] = 0; + coder::internal::b_mergesort(iv, p); + p[0] = iv[0]; + p[1] = iv[1]; + + // index pointer array + coder::randperm(I_NP, r); + FVr_a1.set_size(1, r.size(1)); + loop_ub = r.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + FVr_a1[FVr_a1.size(0) * i1] = r[i1]; + } + + // shuffle locations of vectors + r.set_size(1, static_cast(I_NP - 1.0) + 1); + for (i1 = 0; i1 <= b_loop_ub_tmp; i1++) { + r[i1] = rt_remd_snf(static_cast(i1) + p[0], I_NP); + } + + FVr_rt_size[0] = 1; + FVr_rt_size[1] = r.size(1); + + // rotate indices by ind(1) positions + r.set_size(1, static_cast(I_NP - 1.0) + 1); + for (i1 = 0; i1 <= b_loop_ub_tmp; i1++) { + r[i1] = rt_remd_snf(static_cast(i1) + p[0], I_NP); + } + + FVr_a2.set_size(1, r.size(1)); + loop_ub = r.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + FVr_a2[FVr_a2.size(0) * i1] = FVr_a1[static_cast(r[i1] + 1.0) - + 1]; + } + + // rotate vector locations + r.set_size(1, static_cast(I_NP - 1.0) + 1); + for (i1 = 0; i1 <= b_loop_ub_tmp; i1++) { + r[i1] = rt_remd_snf(static_cast(i1) + p[1], I_NP); + } + + FVr_a3.set_size(1, r.size(1)); + loop_ub = r.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + FVr_a3[FVr_a3.size(0) * i1] = FVr_a2[static_cast(r[i1] + 1.0) - + 1]; + } + + // shuffled population 1 + // shuffled population 2 + r.set_size(1, static_cast(I_NP - 1.0) + 1); + for (i1 = 0; i1 <= b_loop_ub_tmp; i1++) { + r[i1] = rt_remd_snf(static_cast(i1) + p[1], I_NP); + } + + b_FVr_a1 = r.size(1); + FM_pm3.set_size(r.size(1), FM_pop.size(1)); + loop_ub = FM_pop.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + for (i2 = 0; i2 < b_FVr_a1; i2++) { + FM_pm3[i2 + FM_pm3.size(0) * i1] = FM_pop[(static_cast + (FVr_a3[i2]) + FM_pop.size(0) * i1) - 1]; + } + } + + // shuffled population 3 + // shuffled population 4 + // shuffled population 5 + coder::b_rand(I_NP, I_D, r1); + FM_mui.set_size(r1.size(0), r1.size(1)); + loop_ub = r1.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + b_FVr_a1 = r1.size(0); + for (i2 = 0; i2 < b_FVr_a1; i2++) { + FM_mui[i2 + FM_mui.size(0) * i1] = (r1[i2 + r1.size(0) * i1] < F_CR); + } + } + + // all random numbers < F_CR are 1, 0 otherwise + // ----Insert this if you want exponential crossover.---------------- + // FM_mui = sort(FM_mui'); % transpose, collect 1's in each column + // for k = 1:I_NP + // n = floor(rand*I_D); + // if (n > 0) + // FVr_rtd = rem(FVr_rotd+n,I_D); + // FM_mui(:,k) = FM_mui(FVr_rtd+1,k); %rotate column k by n + // end + // end + // FM_mui = FM_mui'; % transpose back + // ----End: exponential crossover------------------------------------ + // inverse mask to FM_mui + // DE/rand/1 with per-vector-dither + b = (1.0 - fWeight) * coder::b_rand() + fWeight; + + // differential variation + if (FM_pm3.size(0) == 1) { + i1 = FVr_a1.size(1); + } else { + i1 = FM_pm3.size(0); + } + + if (FM_pm3.size(1) == 1) { + i2 = FM_pop.size(1); + } else { + i2 = FM_pm3.size(1); + } + + if (FM_pop.size(1) == 1) { + b_FVr_a1 = FM_mui.size(1); + } else { + b_FVr_a1 = FM_pop.size(1); + } + + if (FM_pm3.size(1) == 1) { + loop_ub = FM_pop.size(1); + } else { + loop_ub = FM_pm3.size(1); + } + + if (loop_ub == 1) { + loop_ub = FM_mui.size(1); + } else if (FM_pm3.size(1) == 1) { + loop_ub = FM_pop.size(1); + } else { + loop_ub = FM_pm3.size(1); + } + + if ((FM_pop.size(1) == FM_mui.size(1)) && (FVr_a1.size(1) == FVr_rt_size[1]) + && (FM_pm3.size(0) == FVr_a1.size(1)) && (FM_pm3.size(1) == + FM_pop.size(1)) && (i1 == FM_mui.size(0)) && (i2 == FM_mui.size(1)) && + (FM_pop.size(0) == FM_mui.size(0)) && (b_FVr_a1 == loop_ub)) { + FM_ui.set_size(FM_pop.size(0), FM_pop.size(1)); + loop_ub = FM_pop.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + b_FVr_a1 = FM_pop.size(0); + for (i2 = 0; i2 < b_FVr_a1; i2++) { + boolean_T b_b; + b_b = FM_mui[i2 + FM_mui.size(0) * i1]; + FM_ui[i2 + FM_ui.size(0) * i1] = FM_pop[i2 + FM_pop.size(0) * i1] * + static_cast(static_cast(b_b) < 0.5) + (FM_pm3[i2 + + FM_pm3.size(0) * i1] + (FM_pop[(static_cast(FVr_a1[i2]) + + FM_pop.size(0) * i1) - 1] - FM_pop[(static_cast(FVr_a2[i2]) + + FM_pop.size(0) * i1) - 1]) * b) * static_cast(b_b); + } + } + } else { + h_binary_expand_op(FM_ui, FM_pop, FM_mui, FM_pm3, FVr_a1, FVr_a2, + FVr_rt_size, b); + } + + // crossover + // -----Optional parent+child selection----------------------------------------- + // -----Select which vectors are allowed to enter the new population------------ + for (int32_T k{0}; k < i; k++) { + k_struct_T S_tempval; + + // =====Only use this if boundary constraints are needed================== + for (int32_T j{0}; j < loop_ub_tmp; j++) { + real_T d; + + // ----boundary constraints via bounce back------- + b = FM_ui[k + FM_ui.size(0) * j]; + d = S_struct->FVr_maxbound[j]; + if (b > d) { + b = d + coder::b_rand() * (FM_pm3[k + FM_pm3.size(0) * j] - d); + FM_ui[k + FM_ui.size(0) * j] = b; + } + + d = S_struct->FVr_minbound[j]; + if (b < d) { + b = d + coder::b_rand() * (FM_pm3[k + FM_pm3.size(0) * j] - d); + FM_ui[k + FM_ui.size(0) * j] = b; + } + } + + // =====End boundary constraints========================================== + loop_ub = FM_ui.size(1); + b_FM_pop.set_size(1, FM_ui.size(1)); + for (i1 = 0; i1 < loop_ub; i1++) { + b_FM_pop[i1] = FM_ui[k + FM_ui.size(0) * i1]; + } + + b_problem = *problem; + S_tempval = intrafun(b_FM_pop, &b_problem, controls_parallel_data, + controls_parallel_size, controls_resamPars, + controls_calcSldDuringFit, controls_checks, + problemDefCells_f1, problemDefCells_f2, + problemDefCells_f3, problemDefCells_f4, + problemDefCells_f5, problemDefCells_f6, + problemDefCells_f14, problemDefCells_f19); + + // check cost of competitor + if (leftWin(S_tempval.I_no, S_tempval.FVr_oa, S_val[k].FVr_oa) == 1.0) { + loop_ub = FM_ui.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + FM_pop[k + FM_pop.size(0) * i1] = FM_ui[k + FM_ui.size(0) * i1]; + } + + // replace old vector with new one (for new iteration) + S_val[k] = S_tempval; + + // save value in "cost array" + // ----we update S_bestval only in case of success to save time----------- + if (leftWin(S_tempval.I_no, S_tempval.FVr_oa, S_bestval_FVr_oa) == 1.0) + { + S_bestval_FVr_oa = S_tempval.FVr_oa; + + // new best value + loop_ub = FM_ui.size(1); + FVr_bestmem.set_size(1, FM_ui.size(1)); + for (i1 = 0; i1 < loop_ub; i1++) { + FVr_bestmem[i1] = FM_ui[k + FM_ui.size(0) * i1]; + } + + // new best parameter vector ever + } + } + } + + // for k = 1:NP + // freeze the best member of this iteration for the coming + // iteration. This is needed for some of the strategies. + // ----Output section---------------------------------------------------------- + if (((rt_remd_snf(I_iter, 1.0) == 0.0) || (I_iter == 1.0)) && coder:: + internal::w_strcmp(controls_display_data, controls_display_size)) { + real_T validatedHoleFilling[5]; + coder::internal::validate_print_arguments(I_iter, S_bestval_FVr_oa, + fWeight, F_CR, I_NP, validatedHoleFilling); + printf("Iteration: %g, Best: %f, fWeight: %f, F_CR: %f, I_NP: %g\n\n", + validatedHoleFilling[0], validatedHoleFilling[1], + validatedHoleFilling[2], validatedHoleFilling[3], + validatedHoleFilling[4]); + fflush(stdout); + + // disp(S_bestval); + // var(FM_pop) + // format long e; + // for n=1:I_D + // fprintf('best(%d) = %g\n',n,FVr_bestmem(n)); + // end + // if (I_plotting == 1) + // PlotIt(FVr_bestmem,problem); + // end + } + + I_iter++; + } + + // ---end while ((I_iter < I_itermax) ... + // problemDef.fitParams = x; + // problemDef = unpackParams(problemDef,controls); + // [problem,res] = reflectivityCalculation(problemDef,problemDefCells,controls); + } +} + +// End of code generation (deopt.cpp) diff --git a/RAT/deopt.h b/RAT/deopt.h new file mode 100644 index 00000000..a010cb7a --- /dev/null +++ b/RAT/deopt.h @@ -0,0 +1,47 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// deopt.h +// +// Code generation for function 'deopt' +// +#ifndef DEOPT_H +#define DEOPT_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct i_struct_T; +} + +// Function Declarations +namespace RAT +{ + void deopt(const struct5_T *problem, const ::coder::array + &problemDefCells_f1, const ::coder::array + &problemDefCells_f2, const ::coder::array + &problemDefCells_f3, const ::coder::array + &problemDefCells_f4, const ::coder::array + &problemDefCells_f5, const ::coder::array + &problemDefCells_f6, const ::coder::array + &problemDefCells_f14, const ::coder::array + &problemDefCells_f19, const char_T controls_parallel_data[], const + int32_T controls_parallel_size[2], const real_T controls_resamPars + [2], boolean_T controls_calcSldDuringFit, const char_T + controls_display_data[], const int32_T controls_display_size[2], + const struct3_T *controls_checks, const i_struct_T *S_struct, :: + coder::array &FVr_bestmem); +} + +#endif + +// End of code generation (deopt.h) diff --git a/RAT/det.cpp b/RAT/det.cpp new file mode 100644 index 00000000..c110a55a --- /dev/null +++ b/RAT/det.cpp @@ -0,0 +1,68 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// det.cpp +// +// Code generation for function 'det' +// + +// Include files +#include "det.h" +#include "rt_nonfinite.h" +#include "xgetrf.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + real_T det(const ::coder::array &x) + { + ::coder::array b_x; + ::coder::array ipiv; + real_T y; + if ((x.size(0) == 0) || (x.size(1) == 0)) { + y = 1.0; + } else { + int32_T i; + int32_T k; + int32_T loop_ub; + boolean_T isodd; + b_x.set_size(x.size(0), x.size(1)); + k = x.size(1); + loop_ub = x.size(0); + for (i = 0; i < k; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_x[i1 + b_x.size(0) * i] = x[i1 + x.size(0) * i]; + } + } + + internal::lapack::xgetrf(x.size(0), x.size(1), b_x, x.size(0), ipiv); + y = b_x[0]; + i = b_x.size(0); + for (k = 0; k <= i - 2; k++) { + y *= b_x[(k + b_x.size(0) * (k + 1)) + 1]; + } + + isodd = false; + i = ipiv.size(1); + for (k = 0; k <= i - 2; k++) { + if (ipiv[k] > k + 1) { + isodd = !isodd; + } + } + + if (isodd) { + y = -y; + } + } + + return y; + } + } +} + +// End of code generation (det.cpp) diff --git a/RAT/det.h b/RAT/det.h new file mode 100644 index 00000000..07affd96 --- /dev/null +++ b/RAT/det.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// det.h +// +// Code generation for function 'det' +// +#ifndef DET_H +#define DET_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + real_T det(const ::coder::array &x); + } +} + +#endif + +// End of code generation (det.h) diff --git a/RAT/diag.cpp b/RAT/diag.cpp new file mode 100644 index 00000000..c35a5995 --- /dev/null +++ b/RAT/diag.cpp @@ -0,0 +1,132 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// diag.cpp +// +// Code generation for function 'diag' +// + +// Include files +#include "diag.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + namespace coder + { + static void calclen(const ::coder::array &A, int32_T *dlen, + int32_T *i, int32_T *j); + static void calclen(const ::coder::array &A, int32_T *dlen, + int32_T *i, int32_T *j); + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + static void calclen(const ::coder::array &A, int32_T *dlen, + int32_T *i, int32_T *j) + { + if (A.size(1) > 0) { + int32_T u0; + u0 = A.size(0); + *dlen = A.size(1); + if (u0 <= *dlen) { + *dlen = u0; + } + + *i = 1; + *j = 1; + } else { + *dlen = 0; + *i = 1; + *j = 1; + } + } + + static void calclen(const ::coder::array &A, int32_T *dlen, + int32_T *i, int32_T *j) + { + if (A.size(1) > 0) { + int32_T u0; + u0 = A.size(0); + *dlen = A.size(1); + if (u0 <= *dlen) { + *dlen = u0; + } + + *i = 1; + *j = 1; + } else { + *dlen = 0; + *i = 1; + *j = 1; + } + } + + void diag(const ::coder::array &v, ::coder::array + &d) + { + int32_T dlen; + int32_T j; + int32_T k; + if ((v.size(0) == 1) && (v.size(1) == 1)) { + d.set_size(1); + d[0] = v[0]; + } else { + calclen(v, &dlen, &k, &j); + d.set_size(dlen); + dlen--; + for (k = 0; k <= dlen; k++) { + d[k] = v[k + v.size(0) * k]; + } + } + } + + void diag(const ::coder::array &v, ::coder::array &d) + { + int32_T j; + int32_T nv; + nv = v.size(0); + d.set_size(v.size(0), v.size(0)); + j = v.size(0); + for (int32_T i{0}; i < j; i++) { + int32_T loop_ub; + loop_ub = v.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + d[i1 + d.size(0) * i] = 0.0; + } + } + + for (j = 0; j < nv; j++) { + d[j + d.size(0) * j] = v[j]; + } + } + + void diag(const ::coder::array &v, ::coder::array &d) + { + int32_T dlen; + int32_T j; + int32_T k; + if ((v.size(0) == 1) && (v.size(1) == 1)) { + d.set_size(1); + d[0] = v[0]; + } else { + calclen(v, &dlen, &k, &j); + d.set_size(dlen); + dlen--; + for (k = 0; k <= dlen; k++) { + d[k] = v[k + v.size(0) * k]; + } + } + } + } +} + +// End of code generation (diag.cpp) diff --git a/RAT/diag.h b/RAT/diag.h new file mode 100644 index 00000000..ed397b01 --- /dev/null +++ b/RAT/diag.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// diag.h +// +// Code generation for function 'diag' +// +#ifndef DIAG_H +#define DIAG_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void diag(const ::coder::array &v, ::coder::array + &d); + void diag(const ::coder::array &v, ::coder::array &d); + void diag(const ::coder::array &v, ::coder::array &d); + } +} + +#endif + +// End of code generation (diag.h) diff --git a/RAT/div.cpp b/RAT/div.cpp new file mode 100644 index 00000000..6656f217 --- /dev/null +++ b/RAT/div.cpp @@ -0,0 +1,69 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// div.cpp +// +// Code generation for function 'div' +// + +// Include files +#include "div.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void binary_expand_op(::coder::array &in1, int32_T in2, const :: + coder::array &in3, const ::coder::array< + real_T, 2U> &in4, const ::coder::array &in5) + { + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + stride_0_1 = (in3.size(0) != 1); + stride_1_1 = (in5.size(0) != 1); + if (in5.size(0) == 1) { + loop_ub = in3.size(0); + } else { + loop_ub = in5.size(0); + } + + for (int32_T i{0}; i < loop_ub; i++) { + in1[in2 + in1.size(0) * (static_cast(in3[i]) - 1)] = in4[in2 + + in4.size(0) * (static_cast(in3[i * stride_0_1]) - 1)] / in5[i * + stride_1_1]; + } + } + + void rdivide(::coder::array &in1, const ::coder::array + &in2, const ::coder::array &in3) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = in2[i * stride_0_0] / in3[i * stride_1_0]; + } + } +} + +// End of code generation (div.cpp) diff --git a/RAT/div.h b/RAT/div.h new file mode 100644 index 00000000..5b3aac16 --- /dev/null +++ b/RAT/div.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// div.h +// +// Code generation for function 'div' +// +#ifndef DIV_H +#define DIV_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void binary_expand_op(::coder::array &in1, int32_T in2, const :: + coder::array &in3, const ::coder::array< + real_T, 2U> &in4, const ::coder::array &in5); + void rdivide(::coder::array &in1, const ::coder::array + &in2, const ::coder::array &in3); +} + +#endif + +// End of code generation (div.h) diff --git a/RAT/drawCR.cpp b/RAT/drawCR.cpp new file mode 100644 index 00000000..0f762d94 --- /dev/null +++ b/RAT/drawCR.cpp @@ -0,0 +1,124 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// drawCR.cpp +// +// Code generation for function 'drawCR' +// + +// Include files +#include "drawCR.h" +#include "RATMain_types.h" +#include "multrnd.h" +#include "randperm.h" +#include "randsample.h" +#include "reshapeSizeChecks.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void drawCR(const struct14_T *DREAMPar, const real_T pCR_data[], const int32_T + pCR_size[2], ::coder::array &CR) + { + ::coder::array b_r; + ::coder::array r; + ::coder::array cCR; + ::coder::array r1; + real_T L_data[3]; + + // Generates CR values based on current crossover probabilities + if (DREAMPar->adaptPCR) { + real_T L2_data[4]; + int32_T L_size[2]; + int32_T DREAMPar_idx_0_tmp; + int32_T i; + int32_T i1; + int32_T loop_ub; + + // If crossover probabilities are updated + // How many candidate points for each crossover value? + multrnd(DREAMPar->N * DREAMPar->steps, pCR_data, pCR_size, L_data, L_size); + L_data[1] += L_data[0]; + L_data[2] += L_data[1]; + L2_data[0] = 0.0; + L2_data[1] = L_data[0]; + L2_data[2] = L_data[1]; + L2_data[3] = L_data[2]; + + // Then select which candidate points are selected with what CR + coder::randperm(DREAMPar->N * DREAMPar->steps, b_r); + + // Then generate CR values for each chain + cCR.set_size(1000000); + for (i = 0; i < 1000000; i++) { + cCR[i] = 0.0; + } + + for (int32_T zz{0}; zz < 3; zz++) { + real_T d; + real_T d1; + + // Define start and end + // Take the appropriate elements of r + d = L2_data[zz + 1]; + d1 = L2_data[zz]; + if (d1 + 1.0 > d) { + i = 0; + i1 = 0; + } else { + i = static_cast(d1 + 1.0) - 1; + i1 = static_cast(d); + } + + // Assign these indices DREAMPar.CR(zz) + loop_ub = i1 - i; + r1.set_size(loop_ub); + for (i1 = 0; i1 < loop_ub; i1++) { + r1[i1] = static_cast(b_r[i + i1]); + } + + loop_ub = r1.size(0); + for (i = 0; i < loop_ub; i++) { + cCR[r1[i] - 1] = (static_cast(zz) + 1.0) / 3.0; + } + } + + // Now reshape CR + // CR = reshape(cCR,DREAMPar.N,DREAMPar.steps); + loop_ub = coder::internal::computeDimsData(DREAMPar->N); + DREAMPar_idx_0_tmp = static_cast(DREAMPar->N); + CR.set_size(static_cast(DREAMPar->N), loop_ub); + for (i = 0; i < loop_ub; i++) { + int32_T DREAMPar_tmp_tmp; + DREAMPar_tmp_tmp = static_cast(DREAMPar->N); + for (i1 = 0; i1 < DREAMPar_tmp_tmp; i1++) { + CR[i1 + CR.size(0) * i] = cCR[i1 + DREAMPar_idx_0_tmp * i]; + } + } + } else { + real_T tmp_data[3]; + int32_T DREAMPar_idx_0_tmp; + int32_T DREAMPar_tmp_tmp; + + // If crossover probabilities are not updated + tmp_data[0] = 0.33333333333333331; + tmp_data[1] = 0.66666666666666663; + tmp_data[2] = 1.0; + coder::randsample(tmp_data, DREAMPar->steps * DREAMPar->N, pCR_data, r); + DREAMPar_idx_0_tmp = static_cast(DREAMPar->N); + DREAMPar_tmp_tmp = static_cast(DREAMPar->steps); + CR.set_size(DREAMPar_idx_0_tmp, DREAMPar_tmp_tmp); + for (int32_T i{0}; i < DREAMPar_tmp_tmp; i++) { + for (int32_T i1{0}; i1 < DREAMPar_idx_0_tmp; i1++) { + CR[i1 + CR.size(0) * i] = r[i1 + DREAMPar_idx_0_tmp * i]; + } + } + } + } +} + +// End of code generation (drawCR.cpp) diff --git a/RAT/drawCR.h b/RAT/drawCR.h new file mode 100644 index 00000000..ce2bf36c --- /dev/null +++ b/RAT/drawCR.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// drawCR.h +// +// Code generation for function 'drawCR' +// +#ifndef DRAWCR_H +#define DRAWCR_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct14_T; +} + +// Function Declarations +namespace RAT +{ + void drawCR(const struct14_T *DREAMPar, const real_T pCR_data[], const int32_T + pCR_size[2], ::coder::array &CR); +} + +#endif + +// End of code generation (drawCR.h) diff --git a/RAT/drawEllipsoidPoints.cpp b/RAT/drawEllipsoidPoints.cpp new file mode 100644 index 00000000..dec165cb --- /dev/null +++ b/RAT/drawEllipsoidPoints.cpp @@ -0,0 +1,146 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// drawEllipsoidPoints.cpp +// +// Code generation for function 'drawEllipsoidPoints' +// + +// Include files +#include "drawEllipsoidPoints.h" +#include "RATMain_rtwutil.h" +#include "blockedSummation.h" +#include "diag.h" +#include "eig.h" +#include "eml_mtimes_helper.h" +#include "mtimes.h" +#include "rand.h" +#include "randn.h" +#include "rt_nonfinite.h" +#include "sqrt.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3) + { + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + stride_0_1 = (in2.size(1) != 1); + stride_1_1 = (in3.size(1) != 1); + if (in3.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(1); + } + + for (int32_T i{0}; i < loop_ub; i++) { + in1[i] = in2[i * stride_0_1].re + in3[i * stride_1_1]; + } + } + + void drawEllipsoidPoints(const ::coder::array &B, const ::coder:: + array &mu, ::coder::array &pnts) + { + ::coder::array E; + ::coder::array V; + ::coder::array b_pnts; + ::coder::array r1; + ::coder::array r; + ::coder::array pt; + ::coder::array x; + real_T a; + int32_T i; + int32_T k; + + // function pnts = drawEllipsoidPoints(B, mu, N ) + // + // This function draws points uniformly from an ndims-dimensional ellipsoid + // with edges and orientation defined by the the bounding matrix B and + // centroid mu. The output is a Nxndims dimensional array pnts. + // + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // get number of dimensions from the bounding matrix B + // calculate eigenvalues and vectors of the bounding matrix + coder::eig(B, V, E); + + // check size of mu and transpose if necessary + // generate radii of hyperspheres + a = coder::b_rand(); + + // generate points + coder::randn(static_cast(B.size(0)), pt); + + // get scalings for each point onto the surface of a unit hypersphere + x.set_size(1, pt.size(1)); + k = pt.size(1); + for (i = 0; i < k; i++) { + real_T varargin_1; + varargin_1 = pt[i]; + x[i] = rt_powd_snf(varargin_1, 2.0); + } + + // calculate scaling for each point to be within the unit hypersphere + // with radii rs + a = rt_powd_snf(a, 1.0 / static_cast(B.size(0))) / std::sqrt(coder:: + blockedSummation(x, x.size(1))); + pnts.set_size(1, B.size(0)); + k = B.size(0); + for (i = 0; i < k; i++) { + pnts[i] = 0.0; + } + + // scale points to the ellipsoid using the eigenvalues and rotate with + // the eigenvectors and add centroid + // scale points to a uniform distribution within unit hypersphere + k = pt.size(1); + for (i = 0; i < k; i++) { + pnts[i] = a * pt[i]; + } + + // scale and rotate to ellipsoid + // ('real' needed for compile....) + coder::diag(E, r); + i = r.size(0); + for (k = 0; k < i; k++) { + coder::internal::scalar::d_sqrt(&r[k]); + } + + if (r.size(0) == pnts.size(1)) { + b_pnts.set_size(1, pnts.size(1)); + k = pnts.size(1); + for (i = 0; i < k; i++) { + b_pnts[i].re = pnts[i] * r[i].re; + b_pnts[i].im = pnts[i] * -r[i].im; + } + + coder::internal::blas::mtimes(b_pnts, V, r1); + } else { + binary_expand_op(r1, pnts, r, V); + } + + if (r1.size(1) == mu.size(1)) { + k = r1.size(1); + for (i = 0; i < k; i++) { + pnts[i] = r1[i].re + mu[i]; + } + } else { + binary_expand_op(pnts, r1, mu); + } + } +} + +// End of code generation (drawEllipsoidPoints.cpp) diff --git a/RAT/drawEllipsoidPoints.h b/RAT/drawEllipsoidPoints.h new file mode 100644 index 00000000..892edcd7 --- /dev/null +++ b/RAT/drawEllipsoidPoints.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// drawEllipsoidPoints.h +// +// Code generation for function 'drawEllipsoidPoints' +// +#ifndef DRAWELLIPSOIDPOINTS_H +#define DRAWELLIPSOIDPOINTS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void drawEllipsoidPoints(const ::coder::array &B, const ::coder:: + array &mu, ::coder::array &pnts); +} + +#endif + +// End of code generation (drawEllipsoidPoints.h) diff --git a/RAT/drawMCMC.cpp b/RAT/drawMCMC.cpp new file mode 100644 index 00000000..dbffc645 --- /dev/null +++ b/RAT/drawMCMC.cpp @@ -0,0 +1,331 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// drawMCMC.cpp +// +// Code generation for function 'drawMCMC' +// + +// Include files +#include "drawMCMC.h" +#include "RATMain_data.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "logPlus.h" +#include "mtimes.h" +#include "nsIntraFun.h" +#include "rand.h" +#include "randn.h" +#include "rescaleParameters.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, real_T in4, + real_T in5); + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, real_T in4); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, real_T in4, + real_T in5) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in3.size(1) == 1) { + i = in2.size(1); + } else { + i = in3.size(1); + } + + in1.set_size(1, i); + stride_0_1 = (in2.size(1) != 1); + stride_1_1 = (in3.size(1) != 1); + if (in3.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(1); + } + + for (i = 0; i < loop_ub; i++) { + int32_T i1; + i1 = i * stride_1_1; + in1[i] = in2[i * stride_0_1] + (in3[(static_cast(in4) + in3.size + (0) * i1) - 1] - in3[(static_cast(in5) + in3.size(0) * i1) - 1]); + } + } + + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, real_T in4) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in3.size(0) == 1) { + i = in2.size(1); + } else { + i = in3.size(0); + } + + in1.set_size(1, i); + stride_0_1 = (in2.size(1) != 1); + stride_1_1 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = in2[i * stride_0_1] + in3[i * stride_1_1] * in4; + } + } + + void drawMCMC(const ::coder::array &livepoints, const ::coder:: + array &cholmat, real_T logLmin, const ::coder::array< + real_T, 2U> &prior, const struct5_T *data_f1, const struct2_T + *data_f2, const cell_14 *data_f4, real_T Nmcmc, ::coder::array< + real_T, 2U> &sample, real_T *logL) + { + ::coder::array sampletmp; + ::coder::array gasdevs; + ::coder::array r; + real_T Ntimes; + real_T acc; + int32_T Nlive; + int32_T Npars; + int32_T i; + int32_T loop_ub; + + // This function will draw a multi-dimensional sample from the prior volume + // for use in the nested sampling algorithm. The new point will have a + // likelihood greater than the value logLmin. The new point will be found by + // evolving a random multi-dimensional sample from within the sample array, + // livepoints, using an MCMC with Nmcmc iterations. The MCMC will use a + // Students-t (with N=2 degrees of freedom) proposal distribution based on + // the Cholesky decomposed covariance matrix of the array, cholmat. 10% of + // the samples will actually be drawn using differential evolution by taking + // two random points from the current live points. extraparvals is a vector + // of additional parameters needed by the model. + // + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + *logL = logLmin; + + // useful constant + Nlive = livepoints.size(0); + Npars = livepoints.size(1) - 1; + + // degrees of freedom of Students't distribution + // initialize counters + Ntimes = 1.0; + loop_ub = livepoints.size(1); + i = static_cast(Nmcmc); + real_T sampidx; + int32_T exitg1; + do { + real_T currentPrior; + real_T priortype; + real_T pv_tmp; + int32_T j; + exitg1 = 0; + acc = 0.0; + + // get random point from live point array + sampidx = coder::b_rand() * static_cast(Nlive); + sampidx = std::ceil(sampidx); + sample.set_size(1, livepoints.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + sample[i1] = livepoints[(static_cast(sampidx) + livepoints.size + (0) * i1) - 1]; + } + + // get the sample prior + currentPrior = rtMinusInf; + for (j = 0; j <= Npars; j++) { + priortype = prior[j]; + + // p3 = prior{j,3}; + // p4 = prior{j,4}; + if (priortype == 1.0) { + currentPrior = logPlus(currentPrior, -std::log(prior[j + prior.size(0) + * 4] - prior[j + prior.size(0) * 3])); + } else if (priortype == 2.0) { + real_T p4; + p4 = prior[j + prior.size(0) * 2]; + pv_tmp = sample[j] - prior[j + prior.size(0)]; + currentPrior = logPlus(currentPrior, (-0.91893853320467267 - std::log + (p4)) - pv_tmp * pv_tmp / (2.0 * (p4 * p4))); + } else if (priortype == 3.0) { + pv_tmp = std::log10(prior[j + prior.size(0)]); + currentPrior = logPlus(currentPrior, -std::log(rt_powd_snf(10.0, + sample[j] * (std::log10(prior[j + prior.size(0) * 2]) - pv_tmp) + + pv_tmp))); + } + } + + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T newPrior; + int32_T b_loop_ub; + boolean_T exitg2; + if (coder::b_rand() < 0.9) { + real_T a[2]; + + // use Students-t proposal + // draw points from mulitvariate Gaussian distribution + coder::randn(static_cast(Npars + 1), gasdevs); + + // calculate chi-square distributed value + coder::randn(a); + + // add value onto old sample + pv_tmp = std::sqrt(2.0 / (rt_powd_snf(a[0], 2.0) + rt_powd_snf(a[1], + 2.0))); + coder::internal::blas::mtimes(cholmat, gasdevs, r); + b_loop_ub = sample.size(1); + if (r.size(0) == sample.size(1)) { + sampletmp.set_size(1, sample.size(1)); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + sampletmp[i1] = sample[i1] + r[i1] * pv_tmp; + } + } else { + binary_expand_op(sampletmp, sample, r, pv_tmp); + } + } else { + real_T idx1; + real_T idx2; + + // use differential evolution + // draw two random (different points) A and B and add (B-A) to + // the current sample + idx1 = coder::b_rand() * static_cast(Nlive); + idx1 = std::ceil(idx1); + idx2 = idx1; + while (idx2 == idx1) { + idx2 = coder::b_rand() * static_cast(Nlive); + idx2 = std::ceil(idx2); + } + + b_loop_ub = sample.size(1); + if (sample.size(1) == livepoints.size(1)) { + sampletmp.set_size(1, sample.size(1)); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + sampletmp[i1] = sample[i1] + (livepoints[(static_cast + (idx2) + livepoints.size(0) * i1) - 1] - livepoints[( + static_cast(idx1) + livepoints.size(0) * i1) - 1]); + } + } else { + binary_expand_op(sampletmp, sample, livepoints, idx2, idx1); + } + } + + // check sample is within the (scaled) prior + newPrior = rtMinusInf; + j = 0; + exitg2 = false; + while ((!exitg2) && (j <= Npars)) { + priortype = prior[j]; + + // p3 = prior{j,3}; + // p4 = prior{j,4}; + if (priortype == 1.0) { + // uniform + if ((sampletmp[j] < 0.0) || (sampletmp[j] > 1.0)) { + // wrap parameter from one side to the other + while (sampletmp[j] > 1.0) { + sampletmp[j] = sampletmp[j] - 1.0; + } + + while (sampletmp[j] < 0.0) { + sampletmp[j] = sampletmp[j] + 1.0; + } + } + + newPrior = logPlus(newPrior, -std::log(prior[j + prior.size(0) * 4] + - prior[j + prior.size(0) * 3])); + j++; + } else if (priortype == 2.0) { + // gaussian + newPrior = logPlus(newPrior, -0.91893853320467267 - sampletmp[j] * + sampletmp[j] / 2.0); + j++; + } else if (priortype == 3.0) { + // 'jeffreys' + // behaviour = char(prior(j,5)); + if ((sampletmp[j] < 0.0) || (sampletmp[j] > 1.0)) { + newPrior = rtMinusInf; + exitg2 = true; + } else { + pv_tmp = std::log10(prior[j + prior.size(0)]); + newPrior = logPlus(newPrior, -std::log(rt_powd_snf(10.0, + sampletmp[j] * (std::log10(prior[j + prior.size(0) * 2]) - + pv_tmp) + pv_tmp))); + j++; + } + } else { + j++; + } + } + + pv_tmp = coder::b_rand(); + if (!(std::log(pv_tmp) > newPrior - currentPrior)) { + real_T logLnew; + + // rescale sample back to its proper range for likelihood + // get the likelihood of the new sample + // likestart = tic; + // logLnew = likelihood(data, model, parnames, ... + // loopCell(sc)); + rescaleParameters(prior, sampletmp, r); + logLnew = nsIntraFun(data_f1, data_f2, data_f4, r); + + // likedur = toc(likestart); + // fprintf(1, 'liketime = %.6f\n', likedur); + // if logLnew is greater than logLmin accept point + if (logLnew > logLmin) { + acc++; + currentPrior = newPrior; + sample.set_size(1, sampletmp.size(1)); + b_loop_ub = sampletmp.size(1); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + sample[i1] = sampletmp[i1]; + } + + *logL = logLnew; + } + } else { + // reject point + } + } + + // only break if at least one point was accepted otherwise try again + if (acc > 0.0) { + exitg1 = 1; + } else { + Ntimes++; + } + } while (exitg1 == 0); + + // print out acceptance ratio + if (verbose != 0.0) { + printf("Acceptance ratio: %1.4f, \n\n", acc / (Ntimes * Nmcmc)); + fflush(stdout); + } + } +} + +// End of code generation (drawMCMC.cpp) diff --git a/RAT/drawMCMC.h b/RAT/drawMCMC.h new file mode 100644 index 00000000..104a4d6a --- /dev/null +++ b/RAT/drawMCMC.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// drawMCMC.h +// +// Code generation for function 'drawMCMC' +// +#ifndef DRAWMCMC_H +#define DRAWMCMC_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct struct2_T; + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + void drawMCMC(const ::coder::array &livepoints, const ::coder:: + array &cholmat, real_T logLmin, const ::coder::array< + real_T, 2U> &prior, const struct5_T *data_f1, const struct2_T + *data_f2, const cell_14 *data_f4, real_T Nmcmc, ::coder::array< + real_T, 2U> &sample, real_T *logL); +} + +#endif + +// End of code generation (drawMCMC.h) diff --git a/RAT/drawMultiNest.cpp b/RAT/drawMultiNest.cpp new file mode 100644 index 00000000..ccc5a33a --- /dev/null +++ b/RAT/drawMultiNest.cpp @@ -0,0 +1,152 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// drawMultiNest.cpp +// +// Code generation for function 'drawMultiNest' +// + +// Include files +#include "drawMultiNest.h" +#include "RATMain_data.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "drawEllipsoidPoints.h" +#include "inEllipsoids.h" +#include "nsIntraFun.h" +#include "rand.h" +#include "rescaleParameters.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void drawMultiNest(const ::coder::array &fracvol, const ::coder:: + array &Bs, const ::coder::array + &mus, real_T logLmin, const ::coder::array + &prior, const struct5_T *data_f1, const struct2_T *data_f2, + const cell_14 *data_f4, ::coder::array &sample, + real_T *logL) + { + ::coder::array B; + ::coder::array mu; + ::coder::array pnt; + ::coder::array r; + int32_T b_loop_ub; + int32_T loop_ub; + int32_T ndims; + + // This function draws a multi-dimensional sample from the prior volume + // for use in the nested sampling algorithm. The new point will have a + // likelihood greater than the value logLmin. The new point will be found by + // drawing a random multi-dimensional sample from within the set of optimal + // ellipsoids constructed using the MultiNest algorithm. The bounding + // ellipsoids are defined by their bounding matrices Bs and centroids mus. + // extraparvals is a vector of additional parameters needed by the model. + // + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // extra number of ellipsoids, number of dimensions + ndims = mus.size(1); + pnt.set_size(1, 2); + pnt[0] = 1.0; + pnt[1] = 1.0; + sample.set_size(1, 0); + loop_ub = Bs.size(1); + b_loop_ub = mus.size(1); + real_T inN; + real_T rval; + int32_T k; + int32_T k0; + boolean_T exitg1; + do { + int32_T c_loop_ub; + int32_T i; + int32_T i1; + + // find the ellipsoid from which to draw a new point + rval = coder::b_rand(); + k0 = 0; + k = 0; + exitg1 = false; + while ((!exitg1) && (k <= mus.size(0) - 1)) { + k0 = k; + if (rval < fracvol[k]) { + k++; + } else { + exitg1 = true; + } + } + + // extract bounding matrix and centroid for that ellipsoid + i = k0 * ndims; + i1 = (k0 + 1) * ndims; + if (i + 1 > i1) { + i = 0; + i1 = 0; + } + + c_loop_ub = i1 - i; + B.set_size(c_loop_ub, Bs.size(1)); + for (i1 = 0; i1 < loop_ub; i1++) { + for (int32_T i2{0}; i2 < c_loop_ub; i2++) { + B[i2 + B.size(0) * i1] = Bs[(i + i2) + Bs.size(0) * i1]; + } + } + + mu.set_size(1, mus.size(1)); + for (i = 0; i < b_loop_ub; i++) { + mu[i] = mus[k0 + mus.size(0) * i]; + } + + // draw points from that ellipsoid until logL >= logLmin + *logL = rtMinusInf; + while (*logL < logLmin) { + int32_T in_range; + in_range = 1; + + // default value + // draw one point from the ellipsoid + drawEllipsoidPoints(B, mu, pnt); + + // make sure that the point lies in unit hypercube + for (int32_T ii{0}; ii < ndims; ii++) { + real_T d; + d = pnt[ii]; + if ((d < 0.0) || (d > 1.0)) { + in_range = 0; + if (DEBUG != 0.0) { + printf("new point not in range!!!!\n"); + fflush(stdout); + } + } + } + + if (in_range != 0) { + // assign as candidate replacement live point + sample.set_size(1, pnt.size(1)); + c_loop_ub = pnt.size(1); + for (i = 0; i < c_loop_ub; i++) { + sample[sample.size(0) * i] = pnt[i]; + } + + // rescale point back to full range + // get new likelihood + // logL = likelihood(data, model, parnames, loopCell(rescaledpnt)); + rescaleParameters(prior, pnt, r); + *logL = nsIntraFun(data_f1, data_f2, data_f4, r); + } + } + + // check how many ellipsoids this point lies in + inN = inEllipsoids(pnt, Bs, mus); + + // only accept sample with 1/inN probability + } while (!(coder::b_rand() < 1.0 / inN)); + } +} + +// End of code generation (drawMultiNest.cpp) diff --git a/RAT/drawMultiNest.h b/RAT/drawMultiNest.h new file mode 100644 index 00000000..1492021c --- /dev/null +++ b/RAT/drawMultiNest.h @@ -0,0 +1,40 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// drawMultiNest.h +// +// Code generation for function 'drawMultiNest' +// +#ifndef DRAWMULTINEST_H +#define DRAWMULTINEST_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct struct2_T; + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + void drawMultiNest(const ::coder::array &fracvol, const ::coder:: + array &Bs, const ::coder::array + &mus, real_T logLmin, const ::coder::array + &prior, const struct5_T *data_f1, const struct2_T *data_f2, + const cell_14 *data_f4, ::coder::array &sample, + real_T *logL); +} + +#endif + +// End of code generation (drawMultiNest.h) diff --git a/RAT/eig.cpp b/RAT/eig.cpp new file mode 100644 index 00000000..d17c1093 --- /dev/null +++ b/RAT/eig.cpp @@ -0,0 +1,101 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eig.cpp +// +// Code generation for function 'eig' +// + +// Include files +#include "eig.h" +#include "anyNonFinite.h" +#include "eigHermitianStandard.h" +#include "eigSkewHermitianStandard.h" +#include "ishermitian.h" +#include "makeD.h" +#include "rt_nonfinite.h" +#include "schur.h" +#include "xzgeev.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void eig(const ::coder::array &A, ::coder::array &V, + ::coder::array &D) + { + ::coder::array alpha1; + ::coder::array beta1; + ::coder::array b_D; + ::coder::array b_V; + int32_T info; + int32_T n; + n = A.size(0); + V.set_size(A.size(0), A.size(0)); + D.set_size(A.size(0), A.size(0)); + if ((A.size(0) != 0) && (A.size(1) != 0)) { + if (internal::anyNonFinite(A)) { + int32_T loop_ub; + info = A.size(0); + loop_ub = A.size(0); + V.set_size(A.size(0), A.size(0)); + for (int32_T i{0}; i < loop_ub; i++) { + for (int32_T i1{0}; i1 < info; i1++) { + V[i1 + V.size(0) * i].re = rtNaN; + V[i1 + V.size(0) * i].im = 0.0; + } + } + + info = A.size(0); + loop_ub = A.size(0); + D.set_size(A.size(0), A.size(0)); + for (int32_T i{0}; i < loop_ub; i++) { + for (int32_T i1{0}; i1 < info; i1++) { + D[i1 + D.size(0) * i].re = 0.0; + D[i1 + D.size(0) * i].im = 0.0; + } + } + + for (info = 0; info < n; info++) { + D[info + D.size(0) * info].re = rtNaN; + D[info + D.size(0) * info].im = 0.0; + } + } else if (ishermitian(A)) { + int32_T loop_ub; + schur(A, b_V, b_D); + V.set_size(b_V.size(0), b_V.size(1)); + info = b_V.size(1); + for (int32_T i{0}; i < info; i++) { + loop_ub = b_V.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + V[i1 + V.size(0) * i].re = b_V[i1 + b_V.size(0) * i]; + V[i1 + V.size(0) * i].im = 0.0; + } + } + + diagDiagUpperHessNoImag(b_D); + D.set_size(b_D.size(0), b_D.size(1)); + info = b_D.size(1); + for (int32_T i{0}; i < info; i++) { + loop_ub = b_D.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + D[i1 + D.size(0) * i].re = b_D[i1 + b_D.size(0) * i]; + D[i1 + D.size(0) * i].im = 0.0; + } + } + } else if (b_ishermitian(A)) { + eigSkewHermitianStandard(A, V, D); + } else { + internal::reflapack::xzgeev(A, &info, alpha1, beta1, V); + makeD(alpha1, beta1, D); + } + } + } + } +} + +// End of code generation (eig.cpp) diff --git a/RAT/eig.h b/RAT/eig.h new file mode 100644 index 00000000..9d4d7232 --- /dev/null +++ b/RAT/eig.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eig.h +// +// Code generation for function 'eig' +// +#ifndef EIG_H +#define EIG_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void eig(const ::coder::array &A, ::coder::array &V, + ::coder::array &D); + } +} + +#endif + +// End of code generation (eig.h) diff --git a/RAT/eigHermitianStandard.cpp b/RAT/eigHermitianStandard.cpp new file mode 100644 index 00000000..41009cb3 --- /dev/null +++ b/RAT/eigHermitianStandard.cpp @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eigHermitianStandard.cpp +// +// Code generation for function 'eigHermitianStandard' +// + +// Include files +#include "eigHermitianStandard.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void diagDiagUpperHessNoImag(::coder::array &D) + { + int32_T n; + n = D.size(0); + for (int32_T j{2}; j <= n; j++) { + D[(j + D.size(0) * (j - 2)) - 1] = 0.0; + for (int32_T i{0}; i <= j - 2; i++) { + D[i + D.size(0) * (j - 1)] = 0.0; + } + } + } + } +} + +// End of code generation (eigHermitianStandard.cpp) diff --git a/RAT/reflectivityCalculation_initialize.h b/RAT/eigHermitianStandard.h similarity index 50% rename from RAT/reflectivityCalculation_initialize.h rename to RAT/eigHermitianStandard.h index 500e9df2..aad79a49 100644 --- a/RAT/reflectivityCalculation_initialize.h +++ b/RAT/eigHermitianStandard.h @@ -3,24 +3,28 @@ // granting, nonprofit, education, and research organizations only. Not // for commercial or industrial use. // -// reflectivityCalculation_initialize.h +// eigHermitianStandard.h // -// Code generation for function 'reflectivityCalculation_initialize' +// Code generation for function 'eigHermitianStandard' // -#ifndef REFLECTIVITYCALCULATION_INITIALIZE_H -#define REFLECTIVITYCALCULATION_INITIALIZE_H +#ifndef EIGHERMITIANSTANDARD_H +#define EIGHERMITIANSTANDARD_H // Include files #include "rtwtypes.h" +#include "coder_array.h" #include #include // Function Declarations namespace RAT { - extern void reflectivityCalculation_initialize(); + namespace coder + { + void diagDiagUpperHessNoImag(::coder::array &D); + } } #endif -// End of code generation (reflectivityCalculation_initialize.h) +// End of code generation (eigHermitianStandard.h) diff --git a/RAT/eigRealSkewSymmetricStandard.cpp b/RAT/eigRealSkewSymmetricStandard.cpp new file mode 100644 index 00000000..d2d26dfb --- /dev/null +++ b/RAT/eigRealSkewSymmetricStandard.cpp @@ -0,0 +1,122 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eigRealSkewSymmetricStandard.cpp +// +// Code generation for function 'eigRealSkewSymmetricStandard' +// + +// Include files +#include "eigRealSkewSymmetricStandard.h" +#include "RATMain_data.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void extractEigenValues(const ::coder::array &T, ::coder::array< + creal_T, 2U> &D) + { + int32_T i; + int32_T n; + n = T.size(0); + D.set_size(T.size(0), T.size(0)); + i = T.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + int32_T loop_ub; + loop_ub = T.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + D[i1 + D.size(0) * b_i].re = 0.0; + D[i1 + D.size(0) * b_i].im = 0.0; + } + } + + i = 1; + int32_T exitg1; + do { + exitg1 = 0; + if (i <= n) { + if (i != n) { + real_T lambda; + lambda = T[i + T.size(0) * (i - 1)]; + if (lambda != 0.0) { + lambda = std::abs(lambda); + D[(i + D.size(0) * (i - 1)) - 1].re = 0.0; + D[(i + D.size(0) * (i - 1)) - 1].im = lambda; + D[i + D.size(0) * i].re = 0.0; + D[i + D.size(0) * i].im = -lambda; + i += 2; + } else { + i++; + } + } else { + i++; + } + } else { + exitg1 = 1; + } + } while (exitg1 == 0); + } + + void extractEigenVectors(const ::coder::array &U, const ::coder:: + array &T, ::coder::array &V) + { + int32_T j; + int32_T n; + int32_T sgn; + V.set_size(U.size(0), U.size(1)); + j = U.size(1); + for (sgn = 0; sgn < j; sgn++) { + n = U.size(0); + for (int32_T i{0}; i < n; i++) { + V[i + V.size(0) * sgn].re = U[i + U.size(0) * sgn]; + V[i + V.size(0) * sgn].im = 0.0; + } + } + + j = 1; + n = T.size(0); + while (j <= n) { + if ((j != n) && (T[j + T.size(0) * (j - 1)] != 0.0)) { + if (T[j + T.size(0) * (j - 1)] < 0.0) { + sgn = 1; + } else { + sgn = -1; + } + + for (int32_T i{0}; i < n; i++) { + real_T ai; + real_T ar; + ar = V[i + V.size(0) * (j - 1)].re; + ai = static_cast(sgn) * V[i + V.size(0) * j].re; + if (ai == 0.0) { + V[i + V.size(0) * (j - 1)].re = ar / 1.4142135623730951; + V[i + V.size(0) * (j - 1)].im = 0.0; + } else if (ar == 0.0) { + V[i + V.size(0) * (j - 1)].re = 0.0; + V[i + V.size(0) * (j - 1)].im = ai / 1.4142135623730951; + } else { + V[i + V.size(0) * (j - 1)].re = ar / 1.4142135623730951; + V[i + V.size(0) * (j - 1)].im = ai / 1.4142135623730951; + } + + V[i + V.size(0) * j].re = V[i + V.size(0) * (j - 1)].re; + V[i + V.size(0) * j].im = -V[i + V.size(0) * (j - 1)].im; + } + + j += 2; + } else { + j++; + } + } + } + } +} + +// End of code generation (eigRealSkewSymmetricStandard.cpp) diff --git a/RAT/eigRealSkewSymmetricStandard.h b/RAT/eigRealSkewSymmetricStandard.h new file mode 100644 index 00000000..8545709e --- /dev/null +++ b/RAT/eigRealSkewSymmetricStandard.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eigRealSkewSymmetricStandard.h +// +// Code generation for function 'eigRealSkewSymmetricStandard' +// +#ifndef EIGREALSKEWSYMMETRICSTANDARD_H +#define EIGREALSKEWSYMMETRICSTANDARD_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void extractEigenValues(const ::coder::array &T, ::coder::array< + creal_T, 2U> &D); + void extractEigenVectors(const ::coder::array &U, const ::coder:: + array &T, ::coder::array &V); + } +} + +#endif + +// End of code generation (eigRealSkewSymmetricStandard.h) diff --git a/RAT/eigSkewHermitianStandard.cpp b/RAT/eigSkewHermitianStandard.cpp new file mode 100644 index 00000000..b1a04554 --- /dev/null +++ b/RAT/eigSkewHermitianStandard.cpp @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eigSkewHermitianStandard.cpp +// +// Code generation for function 'eigSkewHermitianStandard' +// + +// Include files +#include "eigSkewHermitianStandard.h" +#include "eigRealSkewSymmetricStandard.h" +#include "rt_nonfinite.h" +#include "schur.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void eigSkewHermitianStandard(const ::coder::array &A, ::coder:: + array &V, ::coder::array &D) + { + ::coder::array T; + ::coder::array U; + schur(A, U, T); + extractEigenValues(T, D); + extractEigenVectors(U, T, V); + } + } +} + +// End of code generation (eigSkewHermitianStandard.cpp) diff --git a/RAT/eigSkewHermitianStandard.h b/RAT/eigSkewHermitianStandard.h new file mode 100644 index 00000000..9efe73fa --- /dev/null +++ b/RAT/eigSkewHermitianStandard.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eigSkewHermitianStandard.h +// +// Code generation for function 'eigSkewHermitianStandard' +// +#ifndef EIGSKEWHERMITIANSTANDARD_H +#define EIGSKEWHERMITIANSTANDARD_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void eigSkewHermitianStandard(const ::coder::array &A, ::coder:: + array &V, ::coder::array &D); + } +} + +#endif + +// End of code generation (eigSkewHermitianStandard.h) diff --git a/RAT/eml_erfcore.cpp b/RAT/eml_erfcore.cpp index 0ad76f38..f2ca84d3 100644 --- a/RAT/eml_erfcore.cpp +++ b/RAT/eml_erfcore.cpp @@ -10,65 +10,14 @@ // Include files #include "eml_erfcore.h" +#include "RATMain_rtwutil.h" #include "log2.h" #include "rt_nonfinite.h" #include -// Function Declarations -namespace RAT -{ - static real_T rt_powd_snf(real_T u0, real_T u1); -} - // Function Definitions namespace RAT { - static real_T rt_powd_snf(real_T u0, real_T u1) - { - real_T y; - if (std::isnan(u0) || std::isnan(u1)) { - y = rtNaN; - } else { - real_T d; - real_T d1; - d = std::abs(u0); - d1 = std::abs(u1); - if (std::isinf(u1)) { - if (d == 1.0) { - y = 1.0; - } else if (d > 1.0) { - if (u1 > 0.0) { - y = rtInf; - } else { - y = 0.0; - } - } else if (u1 > 0.0) { - y = 0.0; - } else { - y = rtInf; - } - } else if (d1 == 0.0) { - y = 1.0; - } else if (d1 == 1.0) { - if (u1 > 0.0) { - y = u0; - } else { - y = 1.0 / u0; - } - } else if (u1 == 2.0) { - y = u0 * u0; - } else if ((u1 == 0.5) && (u0 >= 0.0)) { - y = std::sqrt(u0); - } else if ((u0 < 0.0) && (u1 > std::floor(u1))) { - y = rtNaN; - } else { - y = std::pow(u0, u1); - } - } - - return y; - } - namespace coder { real_T scalar_erf(real_T x) diff --git a/RAT/eml_mtimes_helper.cpp b/RAT/eml_mtimes_helper.cpp index 795b35b0..fdb86586 100644 --- a/RAT/eml_mtimes_helper.cpp +++ b/RAT/eml_mtimes_helper.cpp @@ -10,12 +10,79 @@ // Include files #include "eml_mtimes_helper.h" +#include "mtimes.h" #include "rt_nonfinite.h" #include "coder_array.h" // Function Definitions namespace RAT { + void binary_expand_op(real_T in1_data[], int32_T in1_size[2], const ::coder:: + array &in2, const ::coder::array + &in3, int32_T in4, const ::coder::array &in5) + { + ::coder::array b_in3; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in5.size(1) == 1) { + i = in3.size(1); + } else { + i = in5.size(1); + } + + b_in3.set_size(1, i); + stride_0_1 = (in3.size(1) != 1); + stride_1_1 = (in5.size(1) != 1); + if (in5.size(1) == 1) { + loop_ub = in3.size(1); + } else { + loop_ub = in5.size(1); + } + + for (i = 0; i < loop_ub; i++) { + b_in3[b_in3.size(0) * i] = in3[in4 + in3.size(0) * (i * stride_0_1)] - + in5[in5.size(0) * (i * stride_1_1)]; + } + + coder::internal::blas::mtimes(in2, b_in3, in1_data, in1_size); + } + + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3, + const ::coder::array &in4) + { + ::coder::array b_in2; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in3.size(0) == 1) { + i = in2.size(1); + } else { + i = in3.size(0); + } + + b_in2.set_size(1, i); + stride_0_1 = (in2.size(1) != 1); + stride_1_1 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + int32_T in3_re_tmp; + in3_re_tmp = i * stride_1_1; + b_in2[i].re = in2[i * stride_0_1] * in3[in3_re_tmp].re; + b_in2[i].im = in2[i * stride_0_1] * -in3[in3_re_tmp].im; + } + + coder::internal::blas::mtimes(b_in2, in4, in1); + } + void binary_expand_op(::coder::array &in1, real_T in2, const :: coder::array &in3, const ::coder::array< real_T, 2U> &in4) @@ -90,6 +157,49 @@ namespace RAT in1[i] = 0.5 * (in3[in4[i * stride_0_0] - 1] + in3[in5[i * stride_1_0] - 1]); } } + + void c_binary_expand_op(real_T in1_data[], int32_T in1_size[2], const ::coder:: + array &in2, const ::coder::array &in3, int32_T in4, + const ::coder::array &in5) + { + ::coder::array b_in3; + int32_T aux_0_1; + int32_T aux_1_1; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in5.size(1) == 1) { + i = in3.size(1); + } else { + i = in5.size(1); + } + + b_in3.set_size(in5.size(0), i); + stride_0_1 = (in3.size(1) != 1); + stride_1_1 = (in5.size(1) != 1); + aux_0_1 = 0; + aux_1_1 = 0; + if (in5.size(1) == 1) { + loop_ub = in3.size(1); + } else { + loop_ub = in5.size(1); + } + + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + b_loop_ub = in5.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + b_in3[b_in3.size(0) * i] = in3[in4 + in3.size(0) * aux_0_1] - + in5[in5.size(0) * aux_1_1]; + } + + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + + coder::internal::blas::mtimes(in2, b_in3, in1_data, in1_size); + } } // End of code generation (eml_mtimes_helper.cpp) diff --git a/RAT/eml_mtimes_helper.h b/RAT/eml_mtimes_helper.h index 55ab18c9..bfd57829 100644 --- a/RAT/eml_mtimes_helper.h +++ b/RAT/eml_mtimes_helper.h @@ -19,6 +19,12 @@ // Function Declarations namespace RAT { + void binary_expand_op(real_T in1_data[], int32_T in1_size[2], const ::coder:: + array &in2, const ::coder::array + &in3, int32_T in4, const ::coder::array &in5); + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3, + const ::coder::array &in4); void binary_expand_op(::coder::array &in1, real_T in2, const :: coder::array &in3, const ::coder::array< real_T, 2U> &in4); @@ -27,6 +33,9 @@ namespace RAT void binary_expand_op(::coder::array &in1, const ::coder::array< real_T, 2U> &in3, const ::coder::array &in4, const ::coder::array &in5); + void c_binary_expand_op(real_T in1_data[], int32_T in1_size[2], const ::coder:: + array &in2, const ::coder::array &in3, int32_T in4, + const ::coder::array &in5); } #endif diff --git a/RAT/eml_rand_mt19937ar.cpp b/RAT/eml_rand_mt19937ar.cpp new file mode 100644 index 00000000..92830b29 --- /dev/null +++ b/RAT/eml_rand_mt19937ar.cpp @@ -0,0 +1,170 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eml_rand_mt19937ar.cpp +// +// Code generation for function 'eml_rand_mt19937ar' +// + +// Include files +#include "eml_rand_mt19937ar.h" +#include "RATMain_data.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + real_T b_eml_rand_mt19937ar(uint32_T b_state[625]) + { + real_T r; + int32_T exitg1; + int32_T i; + uint32_T u32[2]; + do { + exitg1 = 0; + genrand_uint32_vector(b_state, u32); + i = static_cast((u32[1] >> 24U) + 1U); + r = ((static_cast(u32[0] >> 3U) * 1.6777216E+7 + + static_cast(static_cast(u32[1]) & 16777215)) * + 2.2204460492503131E-16 - 1.0) * dv[i]; + if (std::abs(r) <= dv[i - 1]) { + exitg1 = 1; + } else if (i < 256) { + real_T u; + u = eml_rand_mt19937ar(b_state); + if (dv1[i] + u * (dv1[i - 1] - dv1[i]) < std::exp(-0.5 * r * r)) { + exitg1 = 1; + } + } else { + real_T u; + real_T x; + do { + u = eml_rand_mt19937ar(b_state); + x = std::log(u) * 0.273661237329758; + u = eml_rand_mt19937ar(b_state); + } while (!(-2.0 * std::log(u) > x * x)); + + if (r < 0.0) { + r = x - 3.65415288536101; + } else { + r = 3.65415288536101 - x; + } + + exitg1 = 1; + } + } while (exitg1 == 0); + + return r; + } + + real_T eml_rand_mt19937ar(uint32_T b_state[625]) + { + real_T r; + + // ========================= COPYRIGHT NOTICE ============================ + // This is a uniform (0,1) pseudorandom number generator based on: + // + // A C-program for MT19937, with initialization improved 2002/1/26. + // Coded by Takuji Nishimura and Makoto Matsumoto. + // + // Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + // All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions + // are met: + // + // 1. Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // + // 2. Redistributions in binary form must reproduce the above copyright + // notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // + // 3. The names of its contributors may not be used to endorse or + // promote products derived from this software without specific + // prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + // + // ============================= END ================================= + uint32_T u[2]; + do { + genrand_uint32_vector(b_state, u); + u[0] >>= 5U; + u[1] >>= 6U; + r = 1.1102230246251565E-16 * (static_cast(u[0]) * 6.7108864E+7 + + static_cast(u[1])); + } while (r == 0.0); + + return r; + } + + void genrand_uint32_vector(uint32_T mt[625], uint32_T u[2]) + { + for (int32_T j{0}; j < 2; j++) { + uint32_T mti; + uint32_T y; + mti = mt[624] + 1U; + if (mti >= 625U) { + for (int32_T kk{0}; kk < 227; kk++) { + y = (mt[kk] & 2147483648U) | (mt[kk + 1] & 2147483647U); + if ((y & 1U) == 0U) { + y >>= 1U; + } else { + y = y >> 1U ^ 2567483615U; + } + + mt[kk] = mt[kk + 397] ^ y; + } + + for (int32_T kk{0}; kk < 396; kk++) { + y = (mt[kk + 227] & 2147483648U) | (mt[kk + 228] & 2147483647U); + if ((y & 1U) == 0U) { + y >>= 1U; + } else { + y = y >> 1U ^ 2567483615U; + } + + mt[kk + 227] = mt[kk] ^ y; + } + + y = (mt[623] & 2147483648U) | (mt[0] & 2147483647U); + if ((y & 1U) == 0U) { + y >>= 1U; + } else { + y = y >> 1U ^ 2567483615U; + } + + mt[623] = mt[396] ^ y; + mti = 1U; + } + + y = mt[static_cast(mti) - 1]; + mt[624] = mti; + y ^= y >> 11U; + y ^= y << 7U & 2636928640U; + y ^= y << 15U & 4022730752U; + u[j] = y ^ y >> 18U; + } + } + } +} + +// End of code generation (eml_rand_mt19937ar.cpp) diff --git a/RAT/eml_rand_mt19937ar.h b/RAT/eml_rand_mt19937ar.h new file mode 100644 index 00000000..293ffc95 --- /dev/null +++ b/RAT/eml_rand_mt19937ar.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eml_rand_mt19937ar.h +// +// Code generation for function 'eml_rand_mt19937ar' +// +#ifndef EML_RAND_MT19937AR_H +#define EML_RAND_MT19937AR_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + real_T b_eml_rand_mt19937ar(uint32_T b_state[625]); + real_T eml_rand_mt19937ar(uint32_T b_state[625]); + void genrand_uint32_vector(uint32_T mt[625], uint32_T u[2]); + } +} + +#endif + +// End of code generation (eml_rand_mt19937ar.h) diff --git a/RAT/eml_rand_mt19937ar_stateful.cpp b/RAT/eml_rand_mt19937ar_stateful.cpp new file mode 100644 index 00000000..a7687a91 --- /dev/null +++ b/RAT/eml_rand_mt19937ar_stateful.cpp @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eml_rand_mt19937ar_stateful.cpp +// +// Code generation for function 'eml_rand_mt19937ar_stateful' +// + +// Include files +#include "eml_rand_mt19937ar_stateful.h" +#include "RATMain_data.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + void eml_rand_mt19937ar_stateful_init() + { + uint32_T r; + std::memset(&state[0], 0, 625U * sizeof(uint32_T)); + r = 5489U; + state[0] = 5489U; + for (int32_T mti{0}; mti < 623; mti++) { + r = ((r ^ r >> 30U) * 1812433253U + static_cast(mti)) + 1U; + state[mti + 1] = r; + } + + state[624] = 624U; + } +} + +// End of code generation (eml_rand_mt19937ar_stateful.cpp) diff --git a/RAT/eml_rand_mt19937ar_stateful.h b/RAT/eml_rand_mt19937ar_stateful.h new file mode 100644 index 00000000..e059c204 --- /dev/null +++ b/RAT/eml_rand_mt19937ar_stateful.h @@ -0,0 +1,26 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eml_rand_mt19937ar_stateful.h +// +// Code generation for function 'eml_rand_mt19937ar_stateful' +// +#ifndef EML_RAND_MT19937AR_STATEFUL_H +#define EML_RAND_MT19937AR_STATEFUL_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void eml_rand_mt19937ar_stateful_init(); +} + +#endif + +// End of code generation (eml_rand_mt19937ar_stateful.h) diff --git a/RAT/eml_setop.cpp b/RAT/eml_setop.cpp new file mode 100644 index 00000000..c386a1e3 --- /dev/null +++ b/RAT/eml_setop.cpp @@ -0,0 +1,112 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eml_setop.cpp +// +// Code generation for function 'eml_setop' +// + +// Include files +#include "eml_setop.h" +#include "relop.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + namespace coder + { + static real_T skip_to_last_equal_value(int32_T *k, const ::coder::array< + real_T, 2U> &x); + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + static real_T skip_to_last_equal_value(int32_T *k, const ::coder::array< + real_T, 2U> &x) + { + real_T xk; + xk = x[*k - 1]; + while ((*k < x.size(1)) && (x[*k] == xk)) { + (*k)++; + } + + return xk; + } + + void do_vectors(const ::coder::array &a, real_T b, ::coder:: + array &c, ::coder::array &ia, + int32_T *ib_size) + { + real_T ak; + int32_T b_ialast; + int32_T iafirst; + int32_T ialast; + int32_T iblast; + int32_T na; + int32_T nc; + int32_T nia; + na = a.size(1); + c.set_size(1, a.size(1)); + ia.set_size(a.size(1)); + *ib_size = 0; + nc = 0; + nia = 0; + iafirst = 0; + ialast = 1; + iblast = 1; + while ((ialast <= na) && (iblast <= 1)) { + b_ialast = ialast; + ak = skip_to_last_equal_value(&b_ialast, a); + ialast = b_ialast; + if (ak == b) { + ialast = b_ialast + 1; + iafirst = b_ialast; + iblast = 2; + } else if (internal::c_relop(ak, b)) { + nc++; + nia++; + c[nc - 1] = ak; + ia[nia - 1] = iafirst + 1; + ialast = b_ialast + 1; + iafirst = b_ialast; + } else { + iblast = 2; + } + } + + while (ialast <= na) { + iblast = ialast; + ak = skip_to_last_equal_value(&iblast, a); + nc++; + nia++; + c[nc - 1] = ak; + ia[nia - 1] = iafirst + 1; + ialast = iblast + 1; + iafirst = iblast; + } + + if (a.size(1) > 0) { + if (nia < 1) { + nia = 0; + } + + ia.set_size(nia); + if (nc < 1) { + nc = 0; + } + + c.set_size(c.size(0), nc); + } + } + } +} + +// End of code generation (eml_setop.cpp) diff --git a/RAT/eml_setop.h b/RAT/eml_setop.h new file mode 100644 index 00000000..a14b8dd9 --- /dev/null +++ b/RAT/eml_setop.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eml_setop.h +// +// Code generation for function 'eml_setop' +// +#ifndef EML_SETOP_H +#define EML_SETOP_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void do_vectors(const ::coder::array &a, real_T b, ::coder:: + array &c, ::coder::array &ia, + int32_T *ib_size); + } +} + +#endif + +// End of code generation (eml_setop.h) diff --git a/RAT/eps.cpp b/RAT/eps.cpp new file mode 100644 index 00000000..7aca6740 --- /dev/null +++ b/RAT/eps.cpp @@ -0,0 +1,41 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eps.cpp +// +// Code generation for function 'eps' +// + +// Include files +#include "eps.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + real_T eps(real_T x) + { + real_T absx; + real_T r; + int32_T exponent; + absx = std::abs(x); + if (std::isinf(absx) || std::isnan(absx)) { + r = rtNaN; + } else if (absx < 4.4501477170144028E-308) { + r = 4.94065645841247E-324; + } else { + std::frexp(absx, &exponent); + r = std::ldexp(1.0, exponent - 53); + } + + return r; + } + } +} + +// End of code generation (eps.cpp) diff --git a/RAT/eps.h b/RAT/eps.h new file mode 100644 index 00000000..eb9cda19 --- /dev/null +++ b/RAT/eps.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eps.h +// +// Code generation for function 'eps' +// +#ifndef EPS_H +#define EPS_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + real_T eps(real_T x); + } +} + +#endif + +// End of code generation (eps.h) diff --git a/RAT/evaluateModel.cpp b/RAT/evaluateModel.cpp new file mode 100644 index 00000000..05249396 --- /dev/null +++ b/RAT/evaluateModel.cpp @@ -0,0 +1,69 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// evaluateModel.cpp +// +// Code generation for function 'evaluateModel' +// + +// Include files +#include "evaluateModel.h" +#include "DREAMWrapper.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void evaluateModel(const ::coder::array &x, const struct14_T + *DREAMPar, const struct5_T *ratInputs_problemDef, const + cell_14 *ratInputs_problemDefCells, const struct2_T + *ratInputs_controls, ::coder::array &fx) + { + ::coder::array b_x; + int32_T loop_ub_tmp; + + // This function computes the likelihood and log-likelihood of each d-vector + // of x values + // + // Code both for sequential and parallel evaluation of model ( = pdf ) + // + // Written by Jasper A. Vrugt + // Check whether to store the output of each model evaluation (function call) + // if DREAMPar.modout && ( Meas_info.N > 0 ) + // + // % Create initial fx of size model output by DREAMPar.N + // fx = NaN(Meas_info.N,DREAMPar.N); + // + // end + // Now evaluate the model + loop_ub_tmp = static_cast(DREAMPar->N); + fx.set_size(1, loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + fx[i] = 0.0; + } + + // Sequential evaluation + // Loop over each d-vector of parameter values of x using 1 worker + for (int32_T ii{0}; ii < loop_ub_tmp; ii++) { + int32_T loop_ub; + + // Execute the model and return the model simulation + // fx(:,ii) = f_handle(x(ii,:), ratInputs); + loop_ub = x.size(1); + b_x.set_size(1, x.size(1)); + for (int32_T i{0}; i < loop_ub; i++) { + b_x[i] = x[ii + x.size(0) * i]; + } + + fx[ii] = DREAMWrapper(b_x, ratInputs_problemDef, ratInputs_problemDefCells, + ratInputs_controls); + } + } +} + +// End of code generation (evaluateModel.cpp) diff --git a/RAT/evaluateModel.h b/RAT/evaluateModel.h new file mode 100644 index 00000000..d73fbeaa --- /dev/null +++ b/RAT/evaluateModel.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// evaluateModel.h +// +// Code generation for function 'evaluateModel' +// +#ifndef EVALUATEMODEL_H +#define EVALUATEMODEL_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct14_T; + struct struct5_T; + struct cell_14; + struct struct2_T; +} + +// Function Declarations +namespace RAT +{ + void evaluateModel(const ::coder::array &x, const struct14_T + *DREAMPar, const struct5_T *ratInputs_problemDef, const + cell_14 *ratInputs_problemDefCells, const struct2_T + *ratInputs_controls, ::coder::array &fx); +} + +#endif + +// End of code generation (evaluateModel.h) diff --git a/RAT/eventHelper.hpp b/RAT/eventHelper.hpp index a1ab809c..9a9c2241 100644 --- a/RAT/eventHelper.hpp +++ b/RAT/eventHelper.hpp @@ -51,7 +51,7 @@ class eventHelper this->initialised = false; } }; - + void sendMessage(const char* msg) { auto sendMessage = library->get_function("sendMessage"); @@ -60,18 +60,29 @@ class eventHelper return sendMessage(msg); }; + + bool hasPlotHandler(void) + { + auto hasPlotHandler = library->get_function("hasPlotHandler"); + + // pass the arguments to the function + return hasPlotHandler(); + }; void updatePlot(int nContrast, double* reflect, double* nReflect, double* shiftedData, double* nShiftedData, - double* sldProfiles, double* nSldProfiles, double* layers, double* nLayers, double* ssubs, + double* sldProfiles, double* nSldProfiles, double* layers, double* nLayers, + double* sldProfiles2, double* nSldProfiles2, double* layers2, double* nLayers2, double* ssubs, double* resample, double* dataPresent, const char* modelType) { auto updatePlot = library->get_function("updatePlot"); // pass the arguments to the function return updatePlot(nContrast, reflect, nReflect, shiftedData, nShiftedData, sldProfiles, nSldProfiles, - layers, nLayers, ssubs, resample, dataPresent, modelType); + layers, nLayers, sldProfiles2, nSldProfiles2, layers2, nLayers2, ssubs, resample, + dataPresent, modelType); }; }; diff --git a/RAT/examples/main.cpp b/RAT/examples/main.cpp index 7d85384f..7222e94b 100644 --- a/RAT/examples/main.cpp +++ b/RAT/examples/main.cpp @@ -35,47 +35,47 @@ // Include files #include "main.h" -#include "reflectivityCalculation.h" -#include "reflectivityCalculation_initialize.h" -#include "reflectivityCalculation_terminate.h" -#include "reflectivityCalculation_types.h" +#include "RATMain.h" +#include "RATMain_initialize.h" +#include "RATMain_terminate.h" +#include "RATMain_types.h" #include "rt_nonfinite.h" #include "coder_array.h" #include "coder_bounded_array.h" // Function Declarations static void argInit_1x2_real_T(real_T result[2]); -static void argInit_1x3_cell_wrap_6(RAT::cell_wrap_6 result[3]); -static coder::array argInit_1xd10000_cell_wrap_0(); -static coder::array argInit_1xd10000_cell_wrap_1(); +static coder::array argInit_1xUnbounded_char_T(); static coder::array argInit_1xd10000_cell_wrap_2(); static coder::array argInit_1xd10000_cell_wrap_3(); -static coder::array argInit_1xd10000_cell_wrap_5(); +static coder::array argInit_1xd10000_cell_wrap_4(); static coder::array argInit_1xd10000_cell_wrap_6(); -static coder::array argInit_1xd10000_cell_wrap_7(); static void argInit_1xd10000_char_T(char_T result_data[], int32_T result_size[2]); static coder::array argInit_1xd10000_real_T(); +static coder::array argInit_Unboundedx1_cell_0(); +static coder::array argInit_Unboundedx1_cell_wrap_1(); +static coder::array argInit_Unboundedx3_real_T(); static boolean_T argInit_boolean_T(); -static void argInit_cell_8(RAT::cell_8 *result); -static RAT::cell_wrap_0 argInit_cell_wrap_0(); +static void argInit_cell_0(RAT::cell_0 *result); +static void argInit_cell_7(RAT::cell_7 *result); static RAT::cell_wrap_1 argInit_cell_wrap_1(); static RAT::cell_wrap_2 argInit_cell_wrap_2(); static RAT::cell_wrap_3 argInit_cell_wrap_3(); -static void argInit_cell_wrap_4(RAT::cell_wrap_4 *result); +static RAT::cell_wrap_4 argInit_cell_wrap_4(); static void argInit_cell_wrap_5(RAT::cell_wrap_5 *result); static void argInit_cell_wrap_6(RAT::cell_wrap_6 *result); -static void argInit_cell_wrap_7(RAT::cell_wrap_7 *result); static char_T argInit_char_T(); -static coder::array argInit_d10000x1_cell_wrap_4(); +static coder::array argInit_d10000x1_cell_wrap_5(); static coder::array argInit_d10000x2_real_T(); static coder::array argInit_d10000xd10000_real_T(); static coder::array argInit_d1xd10000_real_T(); -static void argInit_d1xd2_real_T(real_T result_data[], int32_T result_size[2]); +static void argInit_d1xd10_real_T(real_T result_data[], int32_T result_size[2]); static real_T argInit_real_T(); static void argInit_struct0_T(RAT::struct0_T *result); static void argInit_struct1_T(RAT::struct1_T *result); static void argInit_struct2_T(RAT::struct2_T *result); static void argInit_struct3_T(RAT::struct3_T *result); +static void argInit_struct4_T(RAT::struct4_T *result); // Function Definitions static void argInit_1x2_real_T(real_T result[2]) @@ -88,19 +88,9 @@ static void argInit_1x2_real_T(real_T result[2]) } } -static void argInit_1x3_cell_wrap_6(RAT::cell_wrap_6 result[3]) +static coder::array argInit_1xUnbounded_char_T() { - // Loop over the array to initialize each element. - for (int32_T idx1{0}; idx1 < 3; idx1++) { - // Set the value of the array element. - // Change this value to the value that the application requires. - argInit_cell_wrap_6(&result[idx1]); - } -} - -static coder::array argInit_1xd10000_cell_wrap_0() -{ - coder::array result; + coder::array result; // Set the size of the array. // Change this size to the value that the application requires. @@ -111,16 +101,16 @@ static coder::array argInit_1xd10000_cell_wrap_0() for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { // Set the value of the array element. // Change this value to the value that the application requires. - result[idx1] = argInit_cell_wrap_0(); + result[idx1] = argInit_char_T(); } } return result; } -static coder::array argInit_1xd10000_cell_wrap_1() +static coder::array argInit_1xd10000_cell_wrap_2() { - coder::array result; + coder::array result; // Set the size of the array. // Change this size to the value that the application requires. @@ -131,16 +121,16 @@ static coder::array argInit_1xd10000_cell_wrap_1() for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { // Set the value of the array element. // Change this value to the value that the application requires. - result[idx1] = argInit_cell_wrap_1(); + result[idx1] = argInit_cell_wrap_2(); } } return result; } -static coder::array argInit_1xd10000_cell_wrap_2() +static coder::array argInit_1xd10000_cell_wrap_3() { - coder::array result; + coder::array result; // Set the size of the array. // Change this size to the value that the application requires. @@ -151,16 +141,16 @@ static coder::array argInit_1xd10000_cell_wrap_2() for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { // Set the value of the array element. // Change this value to the value that the application requires. - result[idx1] = argInit_cell_wrap_2(); + result[idx1] = argInit_cell_wrap_3(); } } return result; } -static coder::array argInit_1xd10000_cell_wrap_3() +static coder::array argInit_1xd10000_cell_wrap_4() { - coder::array result; + coder::array result; // Set the size of the array. // Change this size to the value that the application requires. @@ -171,16 +161,16 @@ static coder::array argInit_1xd10000_cell_wrap_3() for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { // Set the value of the array element. // Change this value to the value that the application requires. - result[idx1] = argInit_cell_wrap_3(); + result[idx1] = argInit_cell_wrap_4(); } } return result; } -static coder::array argInit_1xd10000_cell_wrap_5() +static coder::array argInit_1xd10000_cell_wrap_6() { - coder::array result; + coder::array result; // Set the size of the array. // Change this size to the value that the application requires. @@ -191,16 +181,31 @@ static coder::array argInit_1xd10000_cell_wrap_5() for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { // Set the value of the array element. // Change this value to the value that the application requires. - argInit_cell_wrap_5(&result[idx1]); + argInit_cell_wrap_6(&result[idx1]); } } return result; } -static coder::array argInit_1xd10000_cell_wrap_6() +static void argInit_1xd10000_char_T(char_T result_data[], int32_T result_size[2]) { - coder::array result; + // Set the size of the array. + // Change this size to the value that the application requires. + result_size[0] = 1; + result_size[1] = 2; + + // Loop over the array to initialize each element. + for (int32_T idx1{0}; idx1 < 2; idx1++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result_data[idx1] = argInit_char_T(); + } +} + +static coder::array argInit_1xd10000_real_T() +{ + coder::array result; // Set the size of the array. // Change this size to the value that the application requires. @@ -211,62 +216,63 @@ static coder::array argInit_1xd10000_cell_wrap_6() for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { // Set the value of the array element. // Change this value to the value that the application requires. - argInit_cell_wrap_6(&result[idx1]); + result[idx1] = argInit_real_T(); } } return result; } -static coder::array argInit_1xd10000_cell_wrap_7() +static coder::array argInit_Unboundedx1_cell_0() { - coder::array result; + coder::array result; // Set the size of the array. // Change this size to the value that the application requires. - result.set_size(1, 2); + result.set_size(2); // Loop over the array to initialize each element. - for (int32_T idx0{0}; idx0 < 1; idx0++) { - for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { - // Set the value of the array element. - // Change this value to the value that the application requires. - argInit_cell_wrap_7(&result[idx1]); - } + for (int32_T idx0{0}; idx0 < result.size(0); idx0++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + argInit_cell_0(&result[idx0]); } return result; } -static void argInit_1xd10000_char_T(char_T result_data[], int32_T result_size[2]) +static coder::array argInit_Unboundedx1_cell_wrap_1() { + coder::array result; + // Set the size of the array. // Change this size to the value that the application requires. - result_size[0] = 1; - result_size[1] = 2; + result.set_size(2); // Loop over the array to initialize each element. - for (int32_T idx1{0}; idx1 < 2; idx1++) { + for (int32_T idx0{0}; idx0 < result.size(0); idx0++) { // Set the value of the array element. // Change this value to the value that the application requires. - result_data[idx1] = argInit_char_T(); + result[idx0] = argInit_cell_wrap_1(); } + + return result; } -static coder::array argInit_1xd10000_real_T() +static coder::array argInit_Unboundedx3_real_T() { coder::array result; // Set the size of the array. // Change this size to the value that the application requires. - result.set_size(1, 2); + result.set_size(2, 3); // Loop over the array to initialize each element. - for (int32_T idx0{0}; idx0 < 1; idx0++) { - for (int32_T idx1{0}; idx1 < result.size(1); idx1++) { + for (int32_T idx0{0}; idx0 < result.size(0); idx0++) { + for (int32_T idx1{0}; idx1 < 3; idx1++) { // Set the value of the array element. // Change this value to the value that the application requires. - result[idx1] = argInit_real_T(); + result[idx0 + result.size(0) * idx1] = argInit_real_T(); } } @@ -278,51 +284,54 @@ static boolean_T argInit_boolean_T() return false; } -static void argInit_cell_8(RAT::cell_8 *result) +static void argInit_cell_0(RAT::cell_0 *result) { - coder::array result_tmp; - coder::array b_result_tmp; - coder::array c_result_tmp; - coder::array d_result_tmp; - coder::array e_result_tmp; + coder::array b_result_tmp; + real_T result_tmp; // Set the value of each structure field. // Change this value to the value that the application requires. - result_tmp = argInit_1xd10000_cell_wrap_0(); + result_tmp = argInit_real_T(); + result->f4 = result_tmp; + b_result_tmp = argInit_1xUnbounded_char_T(); + result->f1 = b_result_tmp; + result->f2 = b_result_tmp; + result->f3 = result_tmp; +} + +static void argInit_cell_7(RAT::cell_7 *result) +{ + coder::array result_tmp; + coder::array b_result_tmp; + coder::array c_result_tmp; + coder::array d_result_tmp; + + // Set the value of each structure field. + // Change this value to the value that the application requires. + result_tmp = argInit_1xd10000_cell_wrap_2(); result->f1 = result_tmp; - b_result_tmp = argInit_1xd10000_cell_wrap_1(); + b_result_tmp = argInit_1xd10000_cell_wrap_3(); result->f2 = b_result_tmp; result->f3 = result_tmp; - result->f4 = argInit_1xd10000_cell_wrap_2(); - c_result_tmp = argInit_1xd10000_cell_wrap_3(); + result->f4 = result_tmp; + c_result_tmp = argInit_1xd10000_cell_wrap_4(); result->f5 = c_result_tmp; - result->f6 = argInit_d10000x1_cell_wrap_4(); - d_result_tmp = argInit_1xd10000_cell_wrap_5(); + result->f6 = argInit_d10000x1_cell_wrap_5(); + d_result_tmp = argInit_1xd10000_cell_wrap_6(); result->f7 = d_result_tmp; - e_result_tmp = argInit_1xd10000_cell_wrap_6(); - result->f8 = e_result_tmp; - result->f9 = e_result_tmp; - result->f10 = e_result_tmp; - result->f11 = e_result_tmp; - result->f12 = e_result_tmp; - result->f13 = e_result_tmp; - result->f14 = argInit_1xd10000_cell_wrap_7(); + result->f8 = d_result_tmp; + result->f9 = d_result_tmp; + result->f10 = d_result_tmp; + result->f11 = d_result_tmp; + result->f12 = d_result_tmp; + result->f13 = d_result_tmp; + result->f14 = d_result_tmp; result->f15 = d_result_tmp; result->f16 = d_result_tmp; result->f17 = b_result_tmp; result->f18 = result_tmp; result->f19 = c_result_tmp; - result->f20 = e_result_tmp; -} - -static RAT::cell_wrap_0 argInit_cell_wrap_0() -{ - RAT::cell_wrap_0 result; - - // Set the value of each structure field. - // Change this value to the value that the application requires. - argInit_1x2_real_T(result.f1); - return result; + result->f20 = d_result_tmp; } static RAT::cell_wrap_1 argInit_cell_wrap_1() @@ -331,7 +340,7 @@ static RAT::cell_wrap_1 argInit_cell_wrap_1() // Set the value of each structure field. // Change this value to the value that the application requires. - result.f1 = argInit_d10000xd10000_real_T(); + result.f1 = argInit_1xUnbounded_char_T(); return result; } @@ -341,7 +350,7 @@ static RAT::cell_wrap_2 argInit_cell_wrap_2() // Set the value of each structure field. // Change this value to the value that the application requires. - argInit_d1xd2_real_T(result.f1.data, result.f1.size); + argInit_1x2_real_T(result.f1); return result; } @@ -351,22 +360,25 @@ static RAT::cell_wrap_3 argInit_cell_wrap_3() // Set the value of each structure field. // Change this value to the value that the application requires. - result.f1 = argInit_d1xd10000_real_T(); + result.f1 = argInit_d10000xd10000_real_T(); return result; } -static void argInit_cell_wrap_4(RAT::cell_wrap_4 *result) +static RAT::cell_wrap_4 argInit_cell_wrap_4() { + RAT::cell_wrap_4 result; + // Set the value of each structure field. // Change this value to the value that the application requires. - argInit_d1xd2_real_T(result->f1.data, result->f1.size); + result.f1 = argInit_d1xd10000_real_T(); + return result; } static void argInit_cell_wrap_5(RAT::cell_wrap_5 *result) { // Set the value of each structure field. // Change this value to the value that the application requires. - argInit_1xd10000_char_T(result->f1.data, result->f1.size); + argInit_d1xd10_real_T(result->f1.data, result->f1.size); } static void argInit_cell_wrap_6(RAT::cell_wrap_6 *result) @@ -376,21 +388,14 @@ static void argInit_cell_wrap_6(RAT::cell_wrap_6 *result) argInit_1xd10000_char_T(result->f1.data, result->f1.size); } -static void argInit_cell_wrap_7(RAT::cell_wrap_7 *result) -{ - // Set the value of each structure field. - // Change this value to the value that the application requires. - argInit_1x3_cell_wrap_6(result->f1); -} - static char_T argInit_char_T() { return '?'; } -static coder::array argInit_d10000x1_cell_wrap_4() +static coder::array argInit_d10000x1_cell_wrap_5() { - coder::array result; + coder::array result; // Set the size of the array. // Change this size to the value that the application requires. @@ -400,7 +405,7 @@ static coder::array argInit_d10000x1_cell_wrap_4() for (int32_T idx0{0}; idx0 < result.size(0); idx0++) { // Set the value of the array element. // Change this value to the value that the application requires. - argInit_cell_wrap_4(&result[idx0]); + argInit_cell_wrap_5(&result[idx0]); } return result; @@ -466,7 +471,7 @@ static coder::array argInit_d1xd10000_real_T() return result; } -static void argInit_d1xd2_real_T(real_T result_data[], int32_T result_size[2]) +static void argInit_d1xd10_real_T(real_T result_data[], int32_T result_size[2]) { // Set the size of the array. // Change this size to the value that the application requires. @@ -497,8 +502,8 @@ static void argInit_struct0_T(RAT::struct0_T *result) result->numberOfLayers = result_tmp; result->numberOfDomainContrasts = result_tmp; b_result_tmp = argInit_1xd10000_real_T(); - result->contrastBacks = b_result_tmp; - result->contrastBacksType = b_result_tmp; + result->contrastBackgrounds = b_result_tmp; + result->contrastBackgroundsType = b_result_tmp; argInit_1xd10000_char_T(result->TF.data, result->TF.size); result->resample = b_result_tmp; result->dataPresent = b_result_tmp; @@ -506,28 +511,27 @@ static void argInit_struct0_T(RAT::struct0_T *result) result->numberOfContrasts = result_tmp; argInit_1xd10000_char_T(result->geometry.data, result->geometry.size); result->useImaginary = argInit_boolean_T(); - result->contrastShifts = b_result_tmp; - result->contrastScales = b_result_tmp; - result->contrastNbas = b_result_tmp; - result->contrastNbss = b_result_tmp; - result->contrastRes = b_result_tmp; - result->backs = b_result_tmp; - result->shifts = b_result_tmp; - result->sf = b_result_tmp; - result->nba = b_result_tmp; - result->nbs = b_result_tmp; - result->res = b_result_tmp; + result->contrastQzshifts = b_result_tmp; + result->contrastScalefactors = b_result_tmp; + result->contrastBulkIns = b_result_tmp; + result->contrastBulkOuts = b_result_tmp; + result->contrastResolutions = b_result_tmp; + result->backgroundParams = b_result_tmp; + result->qzshifts = b_result_tmp; + result->scalefactors = b_result_tmp; + result->bulkIn = b_result_tmp; + result->bulkOut = b_result_tmp; + result->resolutionParams = b_result_tmp; result->params = b_result_tmp; argInit_1xd10000_char_T(result->modelType.data, result->modelType.size); result->contrastCustomFiles = b_result_tmp; result->contrastDomainRatios = b_result_tmp; result->domainRatio = b_result_tmp; - result->domainContrastCustomFiles = b_result_tmp; b_result_tmp = argInit_d10000xd10000_real_T(); - result->fitpars = b_result_tmp; - result->otherpars = b_result_tmp; - result->fitconstr = b_result_tmp; - result->otherconstr = b_result_tmp; + result->fitParams = b_result_tmp; + result->otherParams = b_result_tmp; + result->fitLimits = b_result_tmp; + result->otherLimits = b_result_tmp; } static void argInit_struct1_T(RAT::struct1_T *result) @@ -537,19 +541,20 @@ static void argInit_struct1_T(RAT::struct1_T *result) // Set the value of each structure field. // Change this value to the value that the application requires. result_tmp = argInit_d10000x2_real_T(); - result->params = result_tmp; - result->backs = result_tmp; - result->scales = result_tmp; - result->shifts = result_tmp; - result->nba = result_tmp; - result->nbs = result_tmp; - result->res = result_tmp; + result->param = result_tmp; + result->backgroundParam = result_tmp; + result->scalefactor = result_tmp; + result->qzshift = result_tmp; + result->bulkIn = result_tmp; + result->bulkOut = result_tmp; + result->resolutionParam = result_tmp; result->domainRatio = result_tmp; } static void argInit_struct2_T(RAT::struct2_T *result) { real_T result_tmp; + boolean_T b_result_tmp; // Set the value of each structure field. // Change this value to the value that the application requires. @@ -557,28 +562,30 @@ static void argInit_struct2_T(RAT::struct2_T *result) result->tolFun = result_tmp; result->maxFunEvals = result_tmp; result->maxIter = result_tmp; + result->updateFreq = result_tmp; + result->updatePlotFreq = result_tmp; result->populationSize = result_tmp; result->fWeight = result_tmp; - result->F_CR = result_tmp; - result->VTR = result_tmp; - result->numGen = result_tmp; + result->crossoverProbability = result_tmp; result->strategy = result_tmp; + result->targetValue = result_tmp; + result->numGenerations = result_tmp; result->Nlive = result_tmp; - result->nmcmc = result_tmp; + result->Nmcmc = result_tmp; result->propScale = result_tmp; result->nsTolerance = result_tmp; - result->calcSld = result_tmp; - result->updateFreq = result_tmp; - result->updatePlotFreq = result_tmp; result->nSamples = result_tmp; result->nChains = result_tmp; - result->lambda = result_tmp; + result->jumpProbability = result_tmp; result->pUnitGamma = result_tmp; - argInit_1xd10000_char_T(result->para.data, result->para.size); - argInit_1xd10000_char_T(result->proc.data, result->proc.size); + b_result_tmp = argInit_boolean_T(); + result->adaptPCR = b_result_tmp; + argInit_1xd10000_char_T(result->procedure.data, result->procedure.size); + argInit_1xd10000_char_T(result->parallel.data, result->parallel.size); + argInit_1x2_real_T(result->resamPars); + result->calcSldDuringFit = b_result_tmp; argInit_1xd10000_char_T(result->display.data, result->display.size); result->tolX = result_tmp; - argInit_1x2_real_T(result->resamPars); argInit_1xd10000_char_T(result->boundHandling.data, result->boundHandling.size); argInit_struct3_T(&result->checks); } @@ -590,47 +597,69 @@ static void argInit_struct3_T(RAT::struct3_T *result) // Set the value of each structure field. // Change this value to the value that the application requires. result_tmp = argInit_1xd10000_real_T(); - result->params_fitYesNo = result_tmp; - result->backs_fitYesNo = result_tmp; - result->shifts_fitYesNo = result_tmp; - result->scales_fitYesNo = result_tmp; - result->nbairs_fitYesNo = result_tmp; - result->nbsubs_fitYesNo = result_tmp; - result->resol_fitYesNo = result_tmp; - result->domainRatio_fitYesNo = result_tmp; + result->fitParam = result_tmp; + result->fitBackgroundParam = result_tmp; + result->fitQzshift = result_tmp; + result->fitScalefactor = result_tmp; + result->fitBulkIn = result_tmp; + result->fitBulkOut = result_tmp; + result->fitResolutionParam = result_tmp; + result->fitDomainRatio = result_tmp; +} + +static void argInit_struct4_T(RAT::struct4_T *result) +{ + coder::array result_tmp; + + // Set the value of each structure field. + // Change this value to the value that the application requires. + result_tmp = argInit_Unboundedx1_cell_0(); + result->param = result_tmp; + result->backgroundParam = result_tmp; + result->resolutionParam = result_tmp; + result->bulkIn = result_tmp; + result->bulkOut = result_tmp; + result->qzshift = result_tmp; + result->scalefactor = result_tmp; + result->domainRatio = result_tmp; + result->priorNames = argInit_Unboundedx1_cell_wrap_1(); + result->priorValues = argInit_Unboundedx3_real_T(); } int32_T main(int32_T, char **) { // Initialize the application. // You do not need to do this more than one time. - RAT::reflectivityCalculation_initialize(); + RAT::RATMain_initialize(); // Invoke the entry-point functions. // You can call entry-point functions multiple times. - main_reflectivityCalculation(); + main_RATMain(); // Terminate the application. // You do not need to do this more than one time. - RAT::reflectivityCalculation_terminate(); + RAT::RATMain_terminate(); return 0; } -void main_reflectivityCalculation() +void main_RATMain() { - RAT::cell_11 result; - RAT::cell_8 problemDefCells; - RAT::struct0_T problemDef; + static RAT::struct0_T problemDef; + static RAT::struct2_T controls; + static RAT::struct5_T outProblemDef; + static RAT::struct8_T bayesResults; + RAT::cell_7 problemDefCells; + RAT::cell_wrap_9 results[6]; RAT::struct1_T problemDefLimits; - RAT::struct2_T controls; - RAT::struct4_T problem; + RAT::struct4_T priors; + RAT::struct6_T problem; - // Initialize function 'reflectivityCalculation' input arguments. + // Initialize function 'RATMain' input arguments. // Initialize function input argument 'problemDef'. argInit_struct0_T(&problemDef); // Initialize function input argument 'problemDefCells'. - argInit_cell_8(&problemDefCells); + argInit_cell_7(&problemDefCells); // Initialize function input argument 'problemDefLimits'. argInit_struct1_T(&problemDefLimits); @@ -638,9 +667,12 @@ void main_reflectivityCalculation() // Initialize function input argument 'controls'. argInit_struct2_T(&controls); - // Call the entry-point 'reflectivityCalculation'. - RAT::reflectivityCalculation(&problemDef, &problemDefCells, &problemDefLimits, - &controls, &problem, &result); + // Initialize function input argument 'priors'. + argInit_struct4_T(&priors); + + // Call the entry-point 'RATMain'. + RAT::RATMain(&problemDef, &problemDefCells, &problemDefLimits, &controls, + &priors, &outProblemDef, &problem, results, &bayesResults); } // End of code generation (main.cpp) diff --git a/RAT/examples/main.h b/RAT/examples/main.h index 5462f7f0..a9288805 100644 --- a/RAT/examples/main.h +++ b/RAT/examples/main.h @@ -42,7 +42,7 @@ // Function Declarations extern int32_T main(int32_T argc, char **argv); -extern void main_reflectivityCalculation(); +extern void main_RATMain(); #endif diff --git a/RAT/eye.cpp b/RAT/eye.cpp new file mode 100644 index 00000000..dba0b0a6 --- /dev/null +++ b/RAT/eye.cpp @@ -0,0 +1,41 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eye.cpp +// +// Code generation for function 'eye' +// + +// Include files +#include "eye.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void eye(int32_T varargin_1, ::coder::array &b_I) + { + b_I.set_size(varargin_1, varargin_1); + for (int32_T k{0}; k < varargin_1; k++) { + for (int32_T i{0}; i < varargin_1; i++) { + b_I[i + b_I.size(0) * k].re = 0.0; + b_I[i + b_I.size(0) * k].im = 0.0; + } + } + + if (varargin_1 > 0) { + for (int32_T k{0}; k < varargin_1; k++) { + b_I[k + b_I.size(0) * k].re = 1.0; + b_I[k + b_I.size(0) * k].im = 0.0; + } + } + } + } +} + +// End of code generation (eye.cpp) diff --git a/RAT/eye.h b/RAT/eye.h new file mode 100644 index 00000000..ecd70a41 --- /dev/null +++ b/RAT/eye.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// eye.h +// +// Code generation for function 'eye' +// +#ifndef EYE_H +#define EYE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void eye(int32_T varargin_1, ::coder::array &b_I); + } +} + +#endif + +// End of code generation (eye.h) diff --git a/RAT/fMinSearch.cpp b/RAT/fMinSearch.cpp new file mode 100644 index 00000000..68a43521 --- /dev/null +++ b/RAT/fMinSearch.cpp @@ -0,0 +1,1131 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// fMinSearch.cpp +// +// Code generation for function 'fMinSearch' +// + +// Include files +#include "fMinSearch.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "abs.h" +#include "blockedSummation.h" +#include "eps.h" +#include "minOrMax.h" +#include "rt_nonfinite.h" +#include "simplexIntrafun.h" +#include "sort.h" +#include "sprintf.h" +#include "strcmp.h" +#include "triggerEvent.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3); + static void c_binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, int32_T in3, int32_T in4, int32_T in5); + static void c_binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3); + static void f_binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3); + static void g_binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3) + { + int32_T b_in3; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + b_in3 = in3.size(1); + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = 3.0 * in2[i * stride_0_0] - 2.0 * in3[i * stride_1_0 + in3.size(0) + * (b_in3 - 1)]; + } + } + + static void c_binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, int32_T in3, int32_T in4, int32_T in5) + { + ::coder::array b_in2; + int32_T aux_0_1; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + if (in5 == 1) { + i = (in4 - in3) + 1; + } else { + i = in5; + } + + b_in2.set_size(in2.size(0), i); + stride_0_1 = ((in4 - in3) + 1 != 1); + aux_0_1 = 0; + if (in5 == 1) { + loop_ub = (in4 - in3) + 1; + } else { + loop_ub = in5; + } + + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + b_loop_ub = in2.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + b_in2[i1 + b_in2.size(0) * i] = in2[i1 + in2.size(0) * (in3 + aux_0_1)] + - in2[i1]; + } + + aux_0_1 += stride_0_1; + } + + coder::c_abs(b_in2, in1); + } + + static void c_binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3) + { + int32_T b_in3; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + b_in3 = in3.size(1); + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = 1.5 * in2[i * stride_0_0] - 0.5 * in3[i * stride_1_0 + in3.size(0) + * (b_in3 - 1)]; + } + } + + static void f_binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3) + { + int32_T b_in3; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + b_in3 = in3.size(1); + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = 0.5 * in2[i * stride_0_0] + 0.5 * in3[i * stride_1_0 + in3.size(0) + * (b_in3 - 1)]; + } + } + + static void g_binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3) + { + int32_T b_in3; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + b_in3 = in3.size(1); + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = 2.0 * in2[i * stride_0_0] - in3[i * stride_1_0 + in3.size(0) * + (b_in3 - 1)]; + } + } + + void fMinSearch(::coder::array &x, real_T options_MaxIter, real_T + options_MaxFunEvals, real_T options_TolX, real_T + options_TolFun, const char_T dis_data[], const int32_T + dis_size[2], const struct5_T *varargin_1, const ::coder::array< + cell_wrap_2, 2U> &varargin_2_f1, const ::coder::array< + cell_wrap_8, 2U> &varargin_2_f2, const ::coder::array< + cell_wrap_2, 2U> &varargin_2_f3, const ::coder::array< + cell_wrap_2, 2U> &varargin_2_f4, const ::coder::array< + cell_wrap_8, 2U> &varargin_2_f5, const ::coder::array< + cell_wrap_8, 1U> &varargin_2_f6, const ::coder::array< + cell_wrap_1, 2U> &varargin_2_f14, const ::coder::array< + cell_wrap_8, 2U> &varargin_2_f19, const struct2_T *varargin_3, + const j_struct_T *varargin_4, real_T *fval, real_T *exitflag, + h_struct_T *output) + { + static const char_T cv6[33]{ 'N', 'e', 'l', 'd', 'e', 'r', '-', 'M', 'e', + 'a', 'd', ' ', 's', 'i', 'm', 'p', 'l', 'e', 'x', ' ', 'd', 'i', 'r', 'e', + 'c', 't', ' ', 's', 'e', 'a', 'r', 'c', 'h' }; + + static const char_T cv11[16]{ 'c', 'o', 'n', 't', 'r', 'a', 'c', 't', ' ', + 'o', 'u', 't', 's', 'i', 'd', 'e' }; + + static const char_T cv10[15]{ 'c', 'o', 'n', 't', 'r', 'a', 'c', 't', ' ', + 'i', 'n', 's', 'i', 'd', 'e' }; + + static const char_T cv5[15]{ 'i', 'n', 'i', 't', 'i', 'a', 'l', ' ', 's', + 'i', 'm', 'p', 'l', 'e', 'x' }; + + static const char_T cv7[7]{ 'r', 'e', 'f', 'l', 'e', 'c', 't' }; + + static const char_T b_cv[6]{ 'n', 'o', 't', 'i', 'f', 'y' }; + + static const char_T cv8[6]{ 'e', 'x', 'p', 'a', 'n', 'd' }; + + static const char_T cv9[6]{ 's', 'h', 'r', 'i', 'n', 'k' }; + + static const char_T cv4[5]{ 'f', 'i', 'n', 'a', 'l' }; + + static const char_T b_cv1[4]{ 'n', 'o', 'n', 'e' }; + + static const char_T cv3[4]{ 'i', 't', 'e', 'r' }; + + static const char_T cv2[3]{ 'o', 'f', 'f' }; + + ::coder::array b_v; + ::coder::array c_fv; + ::coder::array fv; + ::coder::array r; + ::coder::array r1; + ::coder::array r3; + ::coder::array v; + ::coder::array c_v; + ::coder::array r2; + ::coder::array xbar; + ::coder::array xc; + ::coder::array xcc; + ::coder::array xe; + ::coder::array xr; + ::coder::array y; + ::coder::array iidx; + ::coder::array b_varargin_4; + cell_13 result; + struct_T problem; + real_T func_evals; + real_T fxc; + real_T fxcc; + real_T fxe; + real_T fxr; + real_T itercount; + int32_T how_size[2]; + int32_T b_index; + int32_T i; + int32_T i1; + int32_T n; + int32_T prnt; + int32_T x_idx_1; + boolean_T exitg1; + boolean_T printMsg; + + // FMINSEARCH Multidimensional unconstrained nonlinear minimization (Nelder-Mead). + // X = FMINSEARCH(FUN,X0) starts at X0 and attempts to find a local minimizer + // X of the function FUN. FUN is a function handle. FUN accepts input X and + // returns a scalar function value F evaluated at X. X0 can be a scalar, vector + // or matrix. + // + // X = FMINSEARCH(FUN,X0,OPTIONS) minimizes with the default optimization + // parameters replaced by values in the structure OPTIONS, created + // with the OPTIMSET function. See OPTIMSET for details. FMINSEARCH uses + // these options: Display, TolX, TolFun, MaxFunEvals, MaxIter, FunValCheck, + // PlotFcns, and OutputFcn. + // + // X = FMINSEARCH(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a + // structure with the function FUN in PROBLEM.objective, the start point + // in PROBLEM.x0, the options structure in PROBLEM.options, and solver + // name 'fminsearch' in PROBLEM.solver. + // + // [X,FVAL]= FMINSEARCH(...) returns the value of the objective function, + // described in FUN, at X. + // + // [X,FVAL,EXITFLAG] = FMINSEARCH(...) returns an EXITFLAG that describes + // the exit condition. Possible values of EXITFLAG and the corresponding + // exit conditions are + // + // 1 Maximum coordinate difference between current best point and other + // points in simplex is less than or equal to TolX, and corresponding + // difference in function values is less than or equal to TolFun. + // 0 Maximum number of function evaluations or iterations reached. + // -1 Algorithm terminated by the output function. + // + // [X,FVAL,EXITFLAG,OUTPUT] = FMINSEARCH(...) returns a structure + // OUTPUT with the number of iterations taken in OUTPUT.iterations, the + // number of function evaluations in OUTPUT.funcCount, the algorithm name + // in OUTPUT.algorithm, and the exit message in OUTPUT.message. + // + // Examples + // FUN can be specified using @: + // X = fminsearch(@sin,3) + // finds a minimum of the SIN function near 3. + // In this case, SIN is a function that returns a scalar function value + // SIN evaluated at X. + // + // FUN can be an anonymous function: + // X = fminsearch(@(x) norm(x),[1;2;3]) + // returns a point near the minimizer [0;0;0]. + // + // FUN can be a parameterized function. Use an anonymous function to + // capture the problem-dependent parameters: + // f = @(x,c) x(1).^2+c.*x(2).^2; % The parameterized function. + // c = 1.5; % The parameter. + // X = fminsearch(@(x) f(x,c),[0.3;1]) + // + // FMINSEARCH uses the Nelder-Mead simplex (direct search) method. + // + // See also OPTIMSET, FMINBND, FUNCTION_HANDLE. + // Reference: Jeffrey C. Lagarias, James A. Reeds, Margaret H. Wright, + // Paul E. Wright, "Convergence Properties of the Nelder-Mead Simplex + // Method in Low Dimensions", SIAM Journal of Optimization, 9(1): + // p.112-147, 1998. + // Copyright 1984-2018 The MathWorks, Inc. + output->message.set_size(1, 2); + output->message[0] = 'o'; + output->message[1] = 'k'; + + // If just 'defaults' passed in, return the default options in X + // -------- Inputs are standardised for RAT, so no need to check --------- + // Detect problem structure input + // if nargin == 1 + // if isa(funfcn,'struct') + // [funfcn,x,options] = separateOptimStruct(funfcn); + // else % Single input and non-structure + // error('MATLAB:fminsearch:InputArg',... + // sprintf('MATLAB:optimfun:fminsearch:InputArg')); + // end + // end + // + // if nargin == 0 + // error('MATLAB:fminsearch:NotEnoughInputs',... + // sprintf('MATLAB:optimfun:fminsearch:NotEnoughInputs')); + // end + // + // % Check for non-double inputs + // if ~isa(x,'double') + // error('MATLAB:fminsearch:NonDoubleInput',... + // sprintf('MATLAB:optimfun:fminsearch:NonDoubleInput')); + // end + // ------------------------------------------------------------------- + // n = numel(x); + // numberOfVariables = n; + // ------------- Check is done upstream ---------------- + // Check that options is a struct + // if ~isempty(options) && ~isa(options,'struct') + // error('MATLAB:fminsearch:ArgNotStruct',... + // getString(message('MATLAB:optimfun:commonMessages:ArgNotStruct', 3))); + // end + // ------------------- AVH ----------------------------- + // printtype = optimget(options,'Display',defaultopt,'fast'); + // In case the defaults were gathered from calling: optimset('fminsearch'): + // if ischar(maxfun) || isstring(maxfun) + // if strcmpi(maxfun,'200*numberofvariables') + // maxfun = 200*numberOfVariables; + // else + // error('MATLAB:fminsearch:OptMaxFunEvalsNotInteger',... + // getString(message('MATLAB:optimfun:fminsearch:OptMaxFunEvalsNotInteger'))); + // end + // end + // if ischar(maxiter) || isstring(maxiter) + // if strcmpi(maxiter,'200*numberofvariables') + // maxiter = 200*numberOfVariables; + // else + // error('MATLAB:fminsearch:OptMaxIterNotInteger',... + // getString(message('MATLAB:optimfun:fminsearch:OptMaxIterNotInteger'))); + // end + // end + if (coder::internal::b_strcmp(dis_data, dis_size, b_cv)) { + b_index = 0; + } else if (coder::internal::c_strcmp(dis_data, dis_size, b_cv1)) { + b_index = 1; + } else if (coder::internal::d_strcmp(dis_data, dis_size, cv2)) { + b_index = 1; + } else if (coder::internal::c_strcmp(dis_data, dis_size, cv3)) { + b_index = 2; + } else if (coder::internal::e_strcmp(dis_data, dis_size, cv4)) { + b_index = 3; + } else { + b_index = -1; + } + + switch (b_index) { + case 0: + // Changed from TMW fminsearch + prnt = 1; + break; + + case 1: + prnt = 0; + break; + + case 2: + prnt = 3; + break; + + case 3: + prnt = 2; + + // case 'simplex' + // prnt = 4; + break; + + default: + prnt = 1; + break; + } + + // ----------------- Not using output functions for RAT --------- + // % Handle the output + // outputfcn = optimget(options,'OutputFcn',defaultopt,'fast'); + // if isempty(outputfcn) + // haveoutputfcn = false; + // else + // haveoutputfcn = true; + // xOutputfcn = x; % Last x passed to outputfcn; has the input x's shape + // % Parse OutputFcn which is needed to support cell array syntax for OutputFcn. + // outputfcn = createCellArrayOfFunctions(outputfcn,'OutputFcn'); + // end + // + // % Handle the plot + // plotfcns = optimget(options,'PlotFcns',defaultopt,'fast'); + // if isempty(plotfcns) + // haveplotfcn = false; + // else + // haveplotfcn = true; + // xOutputfcn = x; % Last x passed to plotfcns; has the input x's shape + // % Parse PlotFcns which is needed to support cell array syntax for PlotFcns. + // plotfcns = createCellArrayOfFunctions(plotfcns,'PlotFcns'); + // end + // ---------------------- AVH ------------------------------ + // Convert to function handle as needed. + // funfcn = fcnchk(funfcn,length(varargin)); + // Add a wrapper function to check for Inf/NaN/complex values + // + n = x.size(0); + + // Initialize parameters + // two2np1 = 2:n+1; + // one2n = 1:n; + // Set up a simplex near the initial guess. + // Force xin to be a column vector + b_index = x.size(0); + x_idx_1 = x.size(0) + 1; + v.set_size(b_index, x_idx_1); + for (i = 0; i < x_idx_1; i++) { + for (i1 = 0; i1 < b_index; i1++) { + v[i1 + v.size(0) * i] = 0.0; + } + } + + x_idx_1 = x.size(0) + 1; + fv.set_size(1, x_idx_1); + for (i = 0; i < x_idx_1; i++) { + fv[i] = 0.0; + } + + x_idx_1 = x.size(0); + for (i = 0; i < x_idx_1; i++) { + v[i] = x[i]; + } + + // Place input guess in the simplex! (credit L.Pfeffer at Stanford) + // Change x to the form expected by funfcn + simplexIntrafun(x, varargin_1, varargin_2_f1, varargin_2_f2, varargin_2_f3, + varargin_2_f4, varargin_2_f5, varargin_2_f6, varargin_2_f14, + varargin_2_f19, varargin_3, varargin_4, &fv[0], &problem, + &result); + + // Initial simplex setup continues later + // Initialize the output and plot functions. + // + // ---------------------------------------- + // RAT doesn't use output or plot functions... + // + // --------------------- AVH ----------- + // if haveoutputfcn || haveplotfcn + // [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'init',itercount, ... + // func_evals, how, fv(:,1),varargin{:}); + // if stop + // [x,fval,exitflag,output] = cleanUpInterrupt(xOutputfcn,optimValues); + // if prnt > 0 + // fprintf('%s \n', output.message) + // end + // return; + // end + // end + // Print out initial f(x) as 0th iteration + if (prnt == 3) { + printf("\n%s\n", " Iteration Func-count min f(x) Procedure"); + fflush(stdout); + b_varargin_4.set_size(1, 1); + b_varargin_4[0] = '\x00'; + printf(" %5.0f %5.0f %12.6g %s\n", 0.0, 1.0, fv[0], + &b_varargin_4[0]); + fflush(stdout); + + // elseif prnt == 4 + // Option never used in RAT + // formatsave.format = get(0,'format'); + // formatsave.formatspacing = get(0,'formatspacing'); + // % reset format when done + // oc1 = onCleanup(@()set(0,'format',formatsave.format)); + // oc2 = onCleanup(@()set(0,'formatspacing',formatsave.formatspacing)); + // format compact + // format short e + // fprintf('%s \n', ' ') + // fprintf('%s \n', how) + // fprintf('%s \n', 'v = ') + // fprintf('%g \n', v) + // fprintf('%s \n', 'fv = ') + // fprintf('%g \n', fv) + // fprintf('%s \n', 'func_evals = ') + // fprintf('%g \n', func_evals) + } + + triggerEvent(result.f1, result.f3, result.f5, result.f6, problem.ssubs, + varargin_1->TF.data, varargin_1->TF.size, varargin_1->resample, + varargin_1->dataPresent, varargin_1->modelType.data, + varargin_1->modelType.size); + + // OutputFcn and PlotFcns call + // if haveoutputfcn || haveplotfcn + // [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'iter',itercount, ... + // func_evals, how, fv(:,1),varargin{:}); + // if stop % Stop per user request. + // [x,fval,exitflag,output] = cleanUpInterrupt(xOutputfcn,optimValues); + // if prnt > 0 + // fprintf('%s \n', output.message) + // end + // return; + // end + // end + // Continue setting up the initial simplex. + // Following improvement suggested by L.Pfeffer at Stanford + // 5 percent deltas for non-zero terms + // Even smaller delta for zero elements of x + i = x.size(0); + for (int32_T j{0}; j < i; j++) { + x_idx_1 = x.size(0); + y.set_size(x_idx_1); + for (i1 = 0; i1 < x_idx_1; i1++) { + y[i1] = x[i1]; + } + + if (x[j] != 0.0) { + y[j] = 1.05 * x[j]; + } else { + y[j] = 0.00025; + } + + x_idx_1 = y.size(0); + for (i1 = 0; i1 < x_idx_1; i1++) { + v[i1 + v.size(0) * (j + 1)] = y[i1]; + } + + simplexIntrafun(y, varargin_1, varargin_2_f1, varargin_2_f2, varargin_2_f3, + varargin_2_f4, varargin_2_f5, varargin_2_f6, + varargin_2_f14, varargin_2_f19, varargin_3, varargin_4, + &fv[j + 1], &problem, &result); + } + + // sort so v(1,:) has the lowest function value + coder::internal::sort(fv, iidx); + b_index = v.size(0); + b_v.set_size(v.size(0), iidx.size(1)); + x_idx_1 = iidx.size(1); + for (i = 0; i < x_idx_1; i++) { + for (i1 = 0; i1 < b_index; i1++) { + b_v[i1 + b_v.size(0) * i] = v[i1 + v.size(0) * (iidx[i] - 1)]; + } + } + + v.set_size(b_v.size(0), b_v.size(1)); + x_idx_1 = b_v.size(1); + for (i = 0; i < x_idx_1; i++) { + b_index = b_v.size(0); + for (i1 = 0; i1 < b_index; i1++) { + v[i1 + v.size(0) * i] = b_v[i1 + b_v.size(0) * i]; + } + } + + itercount = 1.0; + func_evals = static_cast(x.size(0)) + 1.0; + if (prnt == 3) { + b_varargin_4.set_size(1, 16); + for (i = 0; i < 15; i++) { + b_varargin_4[i] = cv5[i]; + } + + b_varargin_4[15] = '\x00'; + printf(" %5.0f %5.0f %12.6g %s\n", 1.0, + static_cast(x.size(0)) + 1.0, fv[0], &b_varargin_4[0]); + fflush(stdout); + + // elseif prnt == 4 + // fprintf('%s \n', ' ') + // fprintf('%s \n', how) + // fprintf('%s \n', 'v = ') + // fprintf('%g \n', v) + // fprintf('%s \n', 'fv = ') + // fprintf('%g \n', fv) + // fprintf('%s \n', 'func_evals = ') + // fprintf('%g \n', func_evals) + } + + if (rt_remd_snf(1.0, varargin_3->updatePlotFreq) == 0.0) { + triggerEvent(result.f1, result.f3, result.f5, result.f6, problem.ssubs, + varargin_1->TF.data, varargin_1->TF.size, + varargin_1->resample, varargin_1->dataPresent, + varargin_1->modelType.data, varargin_1->modelType.size); + } + + // OutputFcn and PlotFcns call + // if haveoutputfcn || haveplotfcn + // [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'iter',itercount, ... + // func_evals, how, fv(:,1),varargin{:}); + // if stop % Stop per user request. + // [x,fval,exitflag,output] = cleanUpInterrupt(xOutputfcn,optimValues); + // if prnt > 0 + // fprintf('%s \n', output.message) + // end + // return; + // end + // end + // exitflag = 1; + // Main algorithm: iterate until + // (a) the maximum coordinate difference between the current best point and the + // other points in the simplex is less than or equal to TolX. Specifically, + // until max(||v2-v1||,||v3-v1||,...,||v(n+1)-v1||) <= TolX, + // where ||.|| is the infinity-norm, and v1 holds the + // vertex with the current lowest value; AND + // (b) the corresponding difference in function values is less than or equal + // to TolFun. (Cannot use OR instead of AND.) + // The iteration stops if the maximum number of iterations or function evaluations + // are exceeded + exitg1 = false; + while ((!exitg1) && ((func_evals < options_MaxFunEvals) && (itercount < + options_MaxIter))) { + real_T b_fv; + boolean_T guard1; + if (n + 1 < 2) { + i = 0; + i1 = -1; + } else { + i = 1; + i1 = n; + } + + b_fv = fv[0]; + x_idx_1 = i1 - i; + c_fv.set_size(1, x_idx_1 + 1); + for (i1 = 0; i1 <= x_idx_1; i1++) { + c_fv[i1] = b_fv - fv[i + i1]; + } + + coder::b_abs(c_fv, r); + guard1 = false; + if (coder::internal::maximum(r) <= std::fmax(options_TolFun, 10.0 * coder:: + eps(fv[0]))) { + if (n + 1 < 2) { + i = 0; + i1 = -1; + } else { + i = 1; + i1 = n; + } + + x_idx_1 = i1 - i; + if (x_idx_1 + 1 == n) { + b_v.set_size(v.size(0), x_idx_1 + 1); + for (i1 = 0; i1 <= x_idx_1; i1++) { + b_index = v.size(0); + for (int32_T i2{0}; i2 < b_index; i2++) { + b_v[i2 + b_v.size(0) * i1] = v[i2 + v.size(0) * (i + i1)] - v[i2]; + } + } + + coder::c_abs(b_v, r1); + } else { + c_binary_expand_op(r1, v, i, i1, n); + } + + c_v.set_size(v.size(0)); + x_idx_1 = v.size(0); + for (i = 0; i < x_idx_1; i++) { + c_v[i] = v[i]; + } + + coder::internal::maximum(r1, r3); + if (coder::internal::maximum(r3) <= std::fmax(options_TolX, 10.0 * coder:: + eps(coder::internal::maximum(c_v)))) { + exitg1 = true; + } else { + guard1 = true; + } + } else { + guard1 = true; + } + + if (guard1) { + char_T how_data[16]; + + // Compute the reflection point + // xbar = average of the n (NOT n+1) best points + if (n < 1) { + x_idx_1 = 0; + } else { + x_idx_1 = n; + } + + b_v.set_size(v.size(0), x_idx_1); + for (i = 0; i < x_idx_1; i++) { + b_index = v.size(0); + for (i1 = 0; i1 < b_index; i1++) { + b_v[i1 + b_v.size(0) * i] = v[i1 + v.size(0) * i]; + } + } + + coder::blockedSummation(b_v, x_idx_1, r2); + xbar.set_size(r2.size(0)); + x_idx_1 = r2.size(0); + for (i = 0; i < x_idx_1; i++) { + xbar[i] = r2[i] / static_cast(n); + } + + if (xbar.size(0) == v.size(0)) { + xr.set_size(xbar.size(0)); + x_idx_1 = xbar.size(0); + for (i = 0; i < x_idx_1; i++) { + xr[i] = 2.0 * xbar[i] - v[i + v.size(0) * (v.size(1) - 1)]; + } + } else { + g_binary_expand_op(xr, xbar, v); + } + + simplexIntrafun(xr, varargin_1, varargin_2_f1, varargin_2_f2, + varargin_2_f3, varargin_2_f4, varargin_2_f5, + varargin_2_f6, varargin_2_f14, varargin_2_f19, + varargin_3, varargin_4, &fxr, &problem, &result); + func_evals++; + if (fxr < fv[0]) { + // Calculate the expansion point + if (xbar.size(0) == v.size(0)) { + xe.set_size(xbar.size(0)); + x_idx_1 = xbar.size(0); + for (i = 0; i < x_idx_1; i++) { + xe[i] = 3.0 * xbar[i] - 2.0 * v[i + v.size(0) * (v.size(1) - 1)]; + } + } else { + binary_expand_op(xe, xbar, v); + } + + simplexIntrafun(xe, varargin_1, varargin_2_f1, varargin_2_f2, + varargin_2_f3, varargin_2_f4, varargin_2_f5, + varargin_2_f6, varargin_2_f14, varargin_2_f19, + varargin_3, varargin_4, &fxe, &problem, &result); + func_evals++; + if (fxe < fxr) { + x_idx_1 = xe.size(0); + for (i = 0; i < x_idx_1; i++) { + v[i + v.size(0) * (v.size(1) - 1)] = xe[i]; + } + + fv[fv.size(1) - 1] = fxe; + how_size[1] = 6; + for (i = 0; i < 6; i++) { + how_data[i] = cv8[i]; + } + } else { + x_idx_1 = xr.size(0); + for (i = 0; i < x_idx_1; i++) { + v[i + v.size(0) * (v.size(1) - 1)] = xr[i]; + } + + fv[fv.size(1) - 1] = fxr; + how_size[1] = 7; + for (i = 0; i < 7; i++) { + how_data[i] = cv7[i]; + } + } + + // fv(:,1) <= fxr + } else if (fxr < fv[n - 1]) { + x_idx_1 = xr.size(0); + for (i = 0; i < x_idx_1; i++) { + v[i + v.size(0) * (v.size(1) - 1)] = xr[i]; + } + + fv[fv.size(1) - 1] = fxr; + how_size[1] = 7; + for (i = 0; i < 7; i++) { + how_data[i] = cv7[i]; + } + } else { + // fxr >= fv(:,n) + // Perform contraction + if (fxr < fv[fv.size(1) - 1]) { + // Perform an outside contraction + if (xbar.size(0) == v.size(0)) { + xc.set_size(xbar.size(0)); + x_idx_1 = xbar.size(0); + for (i = 0; i < x_idx_1; i++) { + xc[i] = 1.5 * xbar[i] - 0.5 * v[i + v.size(0) * (v.size(1) - 1)]; + } + } else { + c_binary_expand_op(xc, xbar, v); + } + + simplexIntrafun(xc, varargin_1, varargin_2_f1, varargin_2_f2, + varargin_2_f3, varargin_2_f4, varargin_2_f5, + varargin_2_f6, varargin_2_f14, varargin_2_f19, + varargin_3, varargin_4, &fxc, &problem, &result); + func_evals++; + if (fxc <= fxr) { + x_idx_1 = xc.size(0); + for (i = 0; i < x_idx_1; i++) { + v[i + v.size(0) * (v.size(1) - 1)] = xc[i]; + } + + fv[fv.size(1) - 1] = fxc; + how_size[0] = 1; + how_size[1] = 16; + for (i = 0; i < 16; i++) { + how_data[i] = cv11[i]; + } + } else { + // perform a shrink + how_size[0] = 1; + how_size[1] = 6; + for (i = 0; i < 6; i++) { + how_data[i] = cv9[i]; + } + } + } else { + // Perform an inside contraction + if (xbar.size(0) == v.size(0)) { + xcc.set_size(xbar.size(0)); + x_idx_1 = xbar.size(0); + for (i = 0; i < x_idx_1; i++) { + xcc[i] = 0.5 * xbar[i] + 0.5 * v[i + v.size(0) * (v.size(1) - 1)]; + } + } else { + f_binary_expand_op(xcc, xbar, v); + } + + simplexIntrafun(xcc, varargin_1, varargin_2_f1, varargin_2_f2, + varargin_2_f3, varargin_2_f4, varargin_2_f5, + varargin_2_f6, varargin_2_f14, varargin_2_f19, + varargin_3, varargin_4, &fxcc, &problem, &result); + func_evals++; + if (fxcc < fv[fv.size(1) - 1]) { + x_idx_1 = xcc.size(0); + for (i = 0; i < x_idx_1; i++) { + v[i + v.size(0) * (v.size(1) - 1)] = xcc[i]; + } + + fv[fv.size(1) - 1] = fxcc; + how_size[0] = 1; + how_size[1] = 15; + for (i = 0; i < 15; i++) { + how_data[i] = cv10[i]; + } + } else { + // perform a shrink + how_size[0] = 1; + how_size[1] = 6; + for (i = 0; i < 6; i++) { + how_data[i] = cv9[i]; + } + } + } + + if (coder::internal::v_strcmp(how_data, how_size)) { + for (int32_T j{0}; j < n; j++) { + x_idx_1 = v.size(0); + c_v.set_size(v.size(0)); + for (i = 0; i < x_idx_1; i++) { + b_fv = v[i]; + c_v[i] = b_fv + 0.5 * (v[i + v.size(0) * (j + 1)] - b_fv); + } + + x_idx_1 = c_v.size(0); + for (i = 0; i < x_idx_1; i++) { + v[i + v.size(0) * (j + 1)] = c_v[i]; + } + + x_idx_1 = v.size(0); + c_v.set_size(v.size(0)); + for (i = 0; i < x_idx_1; i++) { + c_v[i] = v[i + v.size(0) * (j + 1)]; + } + + simplexIntrafun(c_v, varargin_1, varargin_2_f1, varargin_2_f2, + varargin_2_f3, varargin_2_f4, varargin_2_f5, + varargin_2_f6, varargin_2_f14, varargin_2_f19, + varargin_3, varargin_4, &fv[j + 1], &problem, + &result); + } + + func_evals += static_cast(n); + } + } + + coder::internal::sort(fv, iidx); + b_index = v.size(0); + b_v.set_size(v.size(0), iidx.size(1)); + x_idx_1 = iidx.size(1); + for (i = 0; i < x_idx_1; i++) { + for (i1 = 0; i1 < b_index; i1++) { + b_v[i1 + b_v.size(0) * i] = v[i1 + v.size(0) * (iidx[i] - 1)]; + } + } + + v.set_size(b_v.size(0), b_v.size(1)); + x_idx_1 = b_v.size(1); + for (i = 0; i < x_idx_1; i++) { + b_index = b_v.size(0); + for (i1 = 0; i1 < b_index; i1++) { + v[i1 + v.size(0) * i] = b_v[i1 + b_v.size(0) * i]; + } + } + + itercount++; + if (prnt == 3) { + b_varargin_4.set_size(1, how_size[1] + 1); + x_idx_1 = how_size[1]; + for (i = 0; i < x_idx_1; i++) { + b_varargin_4[i] = how_data[i]; + } + + b_varargin_4[how_size[1]] = '\x00'; + printf(" %5.0f %5.0f %12.6g %s\n", itercount, + func_evals, fv[0], &b_varargin_4[0]); + fflush(stdout); + + // elseif prnt == 4 + // fprintf('%s \n', ' ') + // fprintf('%s \n', num2str(how)) + // fprintf('%s \n', 'v = ') + // fprintf('%s \n', v) + // fprintf('%s \n', 'fv = ') + // fprintf('%s \n', fv) + // fprintf('%s \n', 'func_evals = ') + // fprintf('%s \n', num2str(func_evals)) + } + + if (rt_remd_snf(itercount, varargin_3->updatePlotFreq) == 0.0) { + triggerEvent(result.f1, result.f3, result.f5, result.f6, problem.ssubs, + varargin_1->TF.data, varargin_1->TF.size, + varargin_1->resample, varargin_1->dataPresent, + varargin_1->modelType.data, varargin_1->modelType.size); + } + + // OutputFcn and PlotFcns call + // if haveoutputfcn || haveplotfcn + // [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'iter',itercount, ... + // func_evals, how, fv(:,1),varargin{:}); + // if stop % Stop per user request. + // [x,fval,exitflag,output] = cleanUpInterrupt(xOutputfcn,optimValues); + // if prnt > 0 + // fprintf('%s \n', output.message) + // end + // return; + // end + // end + } + } + + // while + x.set_size(v.size(0)); + x_idx_1 = v.size(0); + for (i = 0; i < x_idx_1; i++) { + x[i] = v[i]; + } + + *fval = fv[0]; + + // OutputFcn and PlotFcns call + // if haveoutputfcn || haveplotfcn + // callOutputAndPlotFcns(outputfcn,plotfcns,x,xOutputfcn,'done',itercount, func_evals, how, fval, varargin{:}); + // end + if (func_evals >= options_MaxFunEvals) { + printMsg = (prnt > 0); + + // msg = getString(message('MATLAB:optimfun:fminsearch:ExitingMaxFunctionEvals', sprintf('%f',fval))); + b_index = 0; + } else if (itercount >= options_MaxIter) { + printMsg = (prnt > 0); + + // msg = getString(message('MATLAB:optimfun:fminsearch:ExitingMaxIterations', sprintf('%f',fval))); + b_index = 0; + } else { + printMsg = (prnt > 1); + coder::b_sprintf(options_TolX, options_TolFun, output->message); + b_index = 1; + } + + output->iterations = itercount; + output->funcCount = func_evals; + for (i = 0; i < 33; i++) { + output->algorithm[i] = cv6[i]; + } + + if (printMsg) { + b_varargin_4.set_size(1, output->message.size(1) + 1); + x_idx_1 = output->message.size(1); + for (i = 0; i < x_idx_1; i++) { + b_varargin_4[i] = output->message[i]; + } + + b_varargin_4[output->message.size(1)] = '\x00'; + printf("\n%s\n", &b_varargin_4[0]); + fflush(stdout); + } + + // -------------------------------------------------------------------------- + // function [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,x,xOutputfcn,state,iter,... + // numf,how,f,varargin) + // CALLOUTPUTANDPLOTFCNS assigns values to the struct OptimValues and then calls the + // outputfcn/plotfcns. + // + // state - can have the values 'init','iter', or 'done'. + // For the 'done' state we do not check the value of 'stop' because the + // optimization is already done. + // optimValues.iteration = iter; + // optimValues.funccount = numf; + // optimValues.fval = f; + // optimValues.procedure = how; + // xOutputfcn(:) = x; % Set x to have user expected size + // stop = false; + // state = char(state); + // Call output functions + // ---- Remove these from function for compile - AVH + // if ~isempty(outputfcn) + // switch state + // case {'iter','init'} + // stop = callAllOptimOutputFcns(outputfcn,xOutputfcn,optimValues,state,varargin{:}) || stop; + // case 'done' + // callAllOptimOutputFcns(outputfcn,xOutputfcn,optimValues,state,varargin{:}); + // end + // end + // % Call plot functions + // if ~isempty(plotfcns) + // switch state + // case {'iter','init'} + // stop = callAllOptimPlotFcns(plotfcns,xOutputfcn,optimValues,state,varargin{:}) || stop; + // case 'done' + // callAllOptimPlotFcns(plotfcns,xOutputfcn,optimValues,state,varargin{:}); + // end + // end + // ----------------------------------- + // -------------------------------------------------------------------------- + // function [x,FVAL,EXITFLAG,OUTPUT] = cleanUpInterrupt(xOutputfcn,optimValues) + // CLEANUPINTERRUPT updates or sets all the output arguments of FMINBND when the optimization + // is interrupted. + // Call plot function driver to finalize the plot function figure window. If + // no plot functions have been specified or the plot function figure no + // longer exists, this call just returns. + // callAllOptimPlotFcns('cleanuponstopsignal'); + // x = xOutputfcn; + // FVAL = optimValues.fval; + // EXITFLAG = -1; + // OUTPUT.iterations = optimValues.iteration; + // OUTPUT.funcCount = optimValues.funccount; + // OUTPUT.algorithm = 'Nelder-Mead simplex direct search'; + // OUTPUT.message = fprintf('Optimisation terminated by user'); %getString(message('MATLAB:optimfun:fminsearch:OptimizationTerminatedPrematurelyByUser')); + // -------------------------------------------------------------------------- + // function f = checkfun(x,userfcn,varargin) + // CHECKFUN checks for complex or NaN results from userfcn. + // f = userfcn(x,varargin{:}); + // Note: we do not check for Inf as FMINSEARCH handles it naturally. + // if isnan(f) + // error('MATLAB:fminsearch:checkfun:NaNFval','Target function is NaN'); + // elseif ~isreal(f) + // error('MATLAB:fminsearch:checkfun:ComplexFval',... + // getString(message('MATLAB:optimfun:fminsearch:checkfun:ComplexFval', localChar( userfcn )))); + // error(sprintf('Target function is complex')); + // end + // -------------------------------------------------------------------------- + // function strfcn = localChar(fcn) + // % Convert the fcn to a character array for printing + // + // if ischar(fcn) + // strfcn = fcn; + // elseif isstring(fcn) || isa(fcn,'inline') + // strfcn = char(fcn); + // elseif isa(fcn,'function_handle') + // strfcn = func2str(fcn); + // else + // try + // strfcn = char(fcn); + // catch + // strfcn = getString(message('MATLAB:optimfun:fminsearch:NameNotPrintable')); + // end + // end + *exitflag = b_index; + } +} + +// End of code generation (fMinSearch.cpp) diff --git a/RAT/fMinSearch.h b/RAT/fMinSearch.h new file mode 100644 index 00000000..f75297aa --- /dev/null +++ b/RAT/fMinSearch.h @@ -0,0 +1,48 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// fMinSearch.h +// +// Code generation for function 'fMinSearch' +// +#ifndef FMINSEARCH_H +#define FMINSEARCH_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct j_struct_T; + struct h_struct_T; +} + +// Function Declarations +namespace RAT +{ + void fMinSearch(::coder::array &x, real_T options_MaxIter, real_T + options_MaxFunEvals, real_T options_TolX, real_T + options_TolFun, const char_T dis_data[], const int32_T + dis_size[2], const struct5_T *varargin_1, const ::coder::array< + cell_wrap_2, 2U> &varargin_2_f1, const ::coder::array< + cell_wrap_8, 2U> &varargin_2_f2, const ::coder::array< + cell_wrap_2, 2U> &varargin_2_f3, const ::coder::array< + cell_wrap_2, 2U> &varargin_2_f4, const ::coder::array< + cell_wrap_8, 2U> &varargin_2_f5, const ::coder::array< + cell_wrap_8, 1U> &varargin_2_f6, const ::coder::array< + cell_wrap_1, 2U> &varargin_2_f14, const ::coder::array< + cell_wrap_8, 2U> &varargin_2_f19, const struct2_T *varargin_3, + const j_struct_T *varargin_4, real_T *fval, real_T *exitflag, + h_struct_T *output); +} + +#endif + +// End of code generation (fMinSearch.h) diff --git a/RAT/fileManager.cpp b/RAT/fileManager.cpp new file mode 100644 index 00000000..603a3660 --- /dev/null +++ b/RAT/fileManager.cpp @@ -0,0 +1,57 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// fileManager.cpp +// +// Code generation for function 'fileManager' +// + +// Include files +#include "fileManager.h" +#include "rt_nonfinite.h" +#include + +// Variable Definitions +namespace RAT +{ + static FILE* eml_openfiles[20]; +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + int32_T fileManager() + { + int32_T f; + f = 0; + for (int32_T j{0}; j < 20; j++) { + if (eml_openfiles[j] != NULL) { + int32_T cst; + cst = fclose(eml_openfiles[j]); + if (cst == 0) { + eml_openfiles[j] = NULL; + } else { + f = -1; + } + } + } + + return f; + } + } + + void filedata_init() + { + FILE* a; + a = NULL; + for (int32_T i{0}; i < 20; i++) { + eml_openfiles[i] = a; + } + } +} + +// End of code generation (fileManager.cpp) diff --git a/RAT/fileManager.h b/RAT/fileManager.h new file mode 100644 index 00000000..e81a98b6 --- /dev/null +++ b/RAT/fileManager.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// fileManager.h +// +// Code generation for function 'fileManager' +// +#ifndef FILEMANAGER_H +#define FILEMANAGER_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + int32_T fileManager(); + } + + void filedata_init(); +} + +#endif + +// End of code generation (fileManager.h) diff --git a/RAT/find.cpp b/RAT/find.cpp index 0498c26f..3322d1b1 100644 --- a/RAT/find.cpp +++ b/RAT/find.cpp @@ -16,8 +16,264 @@ // Function Definitions namespace RAT { + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 1U> &in2, const ::coder::array &in3) + { + ::coder::array b_in2; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + b_in2.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + b_in2[i] = (in2[i * stride_0_0] > in3[i * stride_1_0]); + } + + coder::eml_find(b_in2, in1); + } + + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3) + { + ::coder::array b_in2; + int32_T aux_0_1; + int32_T aux_1_1; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_0_1; + int32_T stride_1_0; + int32_T stride_1_1; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + if (in3.size(1) == 1) { + i1 = in2.size(1); + } else { + i1 = in3.size(1); + } + + b_in2.set_size(i, i1); + stride_0_0 = (in2.size(0) != 1); + stride_0_1 = (in2.size(1) != 1); + stride_1_0 = (in3.size(0) != 1); + stride_1_1 = (in3.size(1) != 1); + aux_0_1 = 0; + aux_1_1 = 0; + if (in3.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(1); + } + + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + i1 = in3.size(0); + if (i1 == 1) { + b_loop_ub = in2.size(0); + } else { + b_loop_ub = i1; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_in2[i1 + b_in2.size(0) * i] = (in2[i1 * stride_0_0 + in2.size(0) * + aux_0_1] > in3[i1 * stride_1_0 + in3.size(0) * aux_1_1]); + } + + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + + coder::c_eml_find(b_in2, in1); + } + + void c_binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3) + { + ::coder::array b_in2; + int32_T aux_0_1; + int32_T aux_1_1; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_0_1; + int32_T stride_1_0; + int32_T stride_1_1; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + if (in3.size(1) == 1) { + i1 = in2.size(1); + } else { + i1 = in3.size(1); + } + + b_in2.set_size(i, i1); + stride_0_0 = (in2.size(0) != 1); + stride_0_1 = (in2.size(1) != 1); + stride_1_0 = (in3.size(0) != 1); + stride_1_1 = (in3.size(1) != 1); + aux_0_1 = 0; + aux_1_1 = 0; + if (in3.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(1); + } + + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + i1 = in3.size(0); + if (i1 == 1) { + b_loop_ub = in2.size(0); + } else { + b_loop_ub = i1; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_in2[i1 + b_in2.size(0) * i] = (in2[i1 * stride_0_0 + in2.size(0) * + aux_0_1] < in3[i1 * stride_1_0 + in3.size(0) * aux_1_1]); + } + + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + + coder::c_eml_find(b_in2, in1); + } + namespace coder { + void b_eml_find(const boolean_T x[2], int32_T i_data[], int32_T i_size[2]) + { + int32_T idx; + int32_T ii; + boolean_T exitg1; + idx = 0; + i_size[0] = 1; + ii = 0; + exitg1 = false; + while ((!exitg1) && (ii < 2)) { + if (x[ii]) { + idx++; + i_data[idx - 1] = ii + 1; + if (idx >= 2) { + exitg1 = true; + } else { + ii++; + } + } else { + ii++; + } + } + + if (idx < 1) { + i_size[1] = 0; + } else { + i_size[1] = idx; + } + } + + void c_eml_find(const ::coder::array &x, ::coder::array< + int32_T, 1U> &i) + { + int32_T idx; + int32_T ii; + int32_T nx; + boolean_T exitg1; + nx = x.size(0) * x.size(1); + idx = 0; + i.set_size(nx); + ii = 0; + exitg1 = false; + while ((!exitg1) && (ii <= nx - 1)) { + if (x[ii]) { + idx++; + i[idx - 1] = ii + 1; + if (idx >= nx) { + exitg1 = true; + } else { + ii++; + } + } else { + ii++; + } + } + + if (nx == 1) { + if (idx == 0) { + i.set_size(0); + } + } else { + if (idx < 1) { + idx = 0; + } + + i.set_size(idx); + } + } + + void d_eml_find(const ::coder::array &x, ::coder::array< + int32_T, 2U> &i) + { + int32_T idx; + int32_T ii; + int32_T nx; + boolean_T exitg1; + nx = x.size(1); + idx = 0; + i.set_size(1, x.size(1)); + ii = 0; + exitg1 = false; + while ((!exitg1) && (ii <= nx - 1)) { + if (x[ii]) { + idx++; + i[idx - 1] = ii + 1; + if (idx >= nx) { + exitg1 = true; + } else { + ii++; + } + } else { + ii++; + } + } + + if (x.size(1) == 1) { + if (idx == 0) { + i.set_size(1, 0); + } + } else { + if (idx < 1) { + idx = 0; + } + + i.set_size(i.size(0), idx); + } + } + void eml_find(const ::coder::array &x, ::coder::array &i) { diff --git a/RAT/find.h b/RAT/find.h index d6c079e5..8f62d5b3 100644 --- a/RAT/find.h +++ b/RAT/find.h @@ -19,8 +19,19 @@ // Function Declarations namespace RAT { + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 1U> &in2, const ::coder::array &in3); + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3); + void c_binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3); namespace coder { + void b_eml_find(const boolean_T x[2], int32_T i_data[], int32_T i_size[2]); + void c_eml_find(const ::coder::array &x, ::coder::array< + int32_T, 1U> &i); + void d_eml_find(const ::coder::array &x, ::coder::array< + int32_T, 2U> &i); void eml_find(const ::coder::array &x, ::coder::array &i); } diff --git a/RAT/gamma.cpp b/RAT/gamma.cpp new file mode 100644 index 00000000..0a15a479 --- /dev/null +++ b/RAT/gamma.cpp @@ -0,0 +1,93 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// gamma.cpp +// +// Code generation for function 'gamma' +// + +// Include files +#include "gamma.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_gamma(real_T *x) + { + static const real_T gam[23]{ 1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0, + 5040.0, 40320.0, 362880.0, 3.6288E+6, 3.99168E+7, 4.790016E+8, + 6.2270208E+9, 8.71782912E+10, 1.307674368E+12, 2.0922789888E+13, + 3.55687428096E+14, 6.402373705728E+15, 1.21645100408832E+17, + 2.43290200817664E+18, 5.109094217170944E+19, 1.1240007277776077E+21 }; + + static const real_T p[8]{ -1.716185138865495, 24.76565080557592, + -379.80425647094563, 629.3311553128184, 866.96620279041326, + -31451.272968848367, -36144.413418691176, 66456.143820240541 }; + + static const real_T q[8]{ -30.840230011973897, 315.35062697960416, + -1015.1563674902192, -3107.7716715723109, 22538.11842098015, + 4755.8462775278813, -134659.95986496931, -115132.25967555349 }; + + static const real_T c[7]{ -0.001910444077728, 0.00084171387781295, + -0.00059523799130430121, 0.0007936507935003503, -0.0027777777777776816, + 0.083333333333333329, 0.0057083835261 }; + + if ((*x <= 23.0) && (*x == std::floor(*x))) { + *x = gam[static_cast(*x) - 1]; + } else if (std::isnan(*x)) { + *x = rtNaN; + } else if (std::isinf(*x)) { + *x = rtInf; + } else { + real_T ysq; + if (*x < 12.0) { + real_T b_sum; + real_T b_x; + real_T xkold; + int32_T i; + xkold = *x; + b_x = std::floor(*x); + *x -= b_x - 1.0; + ysq = 0.0 * (*x - 1.0); + b_sum = 1.0; + for (i = 0; i < 8; i++) { + ysq = (ysq + p[i]) * (*x - 1.0); + b_sum = b_sum * (*x - 1.0) + q[i]; + } + + ysq = ysq / b_sum + 1.0; + if (xkold < *x) { + ysq /= xkold; + } else if (xkold > *x) { + i = static_cast(b_x - 1.0); + for (int32_T j{0}; j < i; j++) { + ysq *= *x; + (*x)++; + } + } + } else { + real_T b_sum; + ysq = *x * *x; + b_sum = 0.0057083835261; + for (int32_T i{0}; i < 6; i++) { + b_sum = b_sum / ysq + c[i]; + } + + b_sum = (b_sum / *x - *x) + 0.91893853320467278; + b_sum += (*x - 0.5) * std::log(*x); + ysq = std::exp(b_sum); + } + + *x = ysq; + } + } + } +} + +// End of code generation (gamma.cpp) diff --git a/RAT/gamma.h b/RAT/gamma.h new file mode 100644 index 00000000..8696f6bd --- /dev/null +++ b/RAT/gamma.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// gamma.h +// +// Code generation for function 'gamma' +// +#ifndef GAMMA_H +#define GAMMA_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_gamma(real_T *x); + } +} + +#endif + +// End of code generation (gamma.h) diff --git a/RAT/gelman.cpp b/RAT/gelman.cpp new file mode 100644 index 00000000..6f7b4834 --- /dev/null +++ b/RAT/gelman.cpp @@ -0,0 +1,190 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// gelman.cpp +// +// Code generation for function 'gelman' +// + +// Include files +#include "gelman.h" +#include "RATMain_types.h" +#include "mean.h" +#include "rt_nonfinite.h" +#include "sqrt1.h" +#include "var.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, real_T in2, + real_T in3, const ::coder::array &in4, real_T in5, const ::coder:: + array &in6, const ::coder::array &in7); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, real_T in2, + real_T in3, const ::coder::array &in4, real_T in5, const ::coder:: + array &in6, const ::coder::array &in7) + { + real_T c_in6; + int32_T b_in6; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + int32_T stride_2_1; + b_in6 = in6.size(0); + c_in6 = (static_cast(in6.size(0)) - 1.0) / static_cast + (in6.size(2)) / static_cast(in6.size(0)); + if (in4.size(1) == 1) { + if (in7.size(1) == 1) { + i = in4.size(1); + } else { + i = in7.size(1); + } + } else { + i = in4.size(1); + } + + in1.set_size(1, i); + stride_0_1 = (in4.size(1) != 1); + stride_1_1 = (in7.size(1) != 1); + stride_2_1 = (in4.size(1) != 1); + if (in4.size(1) == 1) { + if (in7.size(1) == 1) { + loop_ub = in4.size(1); + } else { + loop_ub = in7.size(1); + } + } else { + loop_ub = in4.size(1); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = in2 * (in3 * in4[i * stride_0_1] + in5 * (static_cast + (b_in6) * in7[i * stride_1_1])) / in4[i * stride_2_1] - c_in6; + } + } + + void gelman(const ::coder::array &chain, const struct14_T + *DREAMPar, ::coder::array &R_stat) + { + ::coder::array r1; + ::coder::array W; + ::coder::array b_chain; + ::coder::array r; + ::coder::array var_chain; + int32_T b_loop_ub_tmp; + int32_T i; + int32_T loop_ub_tmp; + + // Calculates the R-statistic convergence diagnostic + // ---------------------------------------------------- + // For more information please refer to: Gelman, A. and D.R. Rubin, 1992. + // Inference from Iterative Simulation Using Multiple chain, + // Statistical Science, Volume 7, Issue 4, 457-472. + // + // Written by Jasper A. Vrugt + // Los Alamos, August 2007 + // ---------------------------------------------------- + // Compute the dimensions of chain + loop_ub_tmp = static_cast(DREAMPar->N); + b_loop_ub_tmp = static_cast(DREAMPar->d); + var_chain.set_size(loop_ub_tmp, b_loop_ub_tmp); + for (i = 0; i < b_loop_ub_tmp; i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + var_chain[i1 + var_chain.size(0) * i] = 0.0; + } + } + + if (chain.size(0) < 10) { + // Set the R-statistic to a large value + R_stat.set_size(1, b_loop_ub_tmp); + for (i = 0; i < b_loop_ub_tmp; i++) { + R_stat[i] = rtNaN; + } + } else { + real_T a; + real_T b_a; + real_T c_a; + int32_T loop_ub; + + // Step 1: Determine the _chainuence means + // Step 1: Determine the variance between the _chainuence means + // Step 2: Compute the variance of the various chain + for (int32_T zz{0}; zz < loop_ub_tmp; zz++) { + loop_ub = chain.size(1); + b_chain.set_size(chain.size(0), chain.size(1)); + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + b_loop_ub = chain.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + b_chain[i1 + b_chain.size(0) * i] = chain[(i1 + chain.size(0) * i) + + chain.size(0) * chain.size(1) * zz]; + } + } + + coder::var(b_chain, r); + loop_ub = r.size(1); + for (i = 0; i < loop_ub; i++) { + var_chain[zz + var_chain.size(0) * i] = r[i]; + } + } + + // Step 2: Calculate the average of the within _chainuence variances + coder::mean(var_chain, W); + + // Step 3: Estimate the target mean + // mu = mean(mean_chain); + // Step 4: Estimate the target variance + a = (static_cast(chain.size(0)) - 1.0) / static_cast + (chain.size(0)); + b_a = 1.0 / static_cast(chain.size(0)); + + // Step 5: Compute the R-statistic + c_a = (static_cast(chain.size(2)) + 1.0) / static_cast + (chain.size(2)); + coder::mean(chain, r1); + loop_ub_tmp = chain.size(2); + b_chain.set_size(chain.size(2), b_loop_ub_tmp); + for (i = 0; i < b_loop_ub_tmp; i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + b_chain[i1 + b_chain.size(0) * i] = r1[i + b_loop_ub_tmp * i1]; + } + } + + coder::var(b_chain, r); + if (W.size(1) == 1) { + i = r.size(1); + } else { + i = W.size(1); + } + + if ((W.size(1) == r.size(1)) && (i == W.size(1))) { + real_T c_chain; + c_chain = (static_cast(chain.size(0)) - 1.0) / + static_cast(chain.size(2)) / static_cast(chain.size(0)); + R_stat.set_size(1, W.size(1)); + loop_ub = W.size(1); + for (i = 0; i < loop_ub; i++) { + real_T d; + d = W[i]; + R_stat[i] = c_a * (a * d + b_a * (static_cast(chain.size(0)) * + r[i])) / d - c_chain; + } + } else { + binary_expand_op(R_stat, c_a, a, W, b_a, chain, r); + } + + coder::c_sqrt(R_stat); + } + } +} + +// End of code generation (gelman.cpp) diff --git a/RAT/gelman.h b/RAT/gelman.h new file mode 100644 index 00000000..fcea566f --- /dev/null +++ b/RAT/gelman.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// gelman.h +// +// Code generation for function 'gelman' +// +#ifndef GELMAN_H +#define GELMAN_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct14_T; +} + +// Function Declarations +namespace RAT +{ + void gelman(const ::coder::array &chain, const struct14_T + *DREAMPar, ::coder::array &R_stat); +} + +#endif + +// End of code generation (gelman.h) diff --git a/RAT/getFittedPriors.cpp b/RAT/getFittedPriors.cpp new file mode 100644 index 00000000..969a491f --- /dev/null +++ b/RAT/getFittedPriors.cpp @@ -0,0 +1,85 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// getFittedPriors.cpp +// +// Code generation for function 'getFittedPriors' +// + +// Include files +#include "getFittedPriors.h" +#include "RATMain_types.h" +#include "find.h" +#include "rt_nonfinite.h" +#include "strcmp.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void getFittedPriors(const ::coder::array ¶mNames, const :: + coder::array &priors_priorNames, const :: + coder::array &priors_priorValues, const :: + coder::array &fitLimits, ::coder::array< + real_T, 2U> &priorFitList) + { + ::coder::array indices; + ::coder::array f1; + ::coder::array r1; + cell_wrap_1 r; + int32_T i; + int32_T loop_ub; + + // Get the list of all the priors.. + // Find the values for fitParams + // priorFitList = cell(numberOfParams,5); + // for i = 1:numberOfParams + // priorFitList{i,1} = 0; + // priorFitList{i,2} = 0; + // priorFitList{i,3} = 0; + // priorFitList{i,4} = 0; + // priorFitList{i,5} = 0; + // end + priorFitList.set_size(paramNames.size(0), 5); + loop_ub = paramNames.size(0); + for (i = 0; i < 5; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + priorFitList[i1 + priorFitList.size(0) * i] = 0.0; + } + } + + // In order to keep 'priorFitList' homogenous (otherwise we would need to + // use a struct), we change the prior type to a numeric flag. So.... + // 'uniform' = 1 + // 'gaussian' = 2 + // 'jeffreys' = 3 + i = paramNames.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + loop_ub = paramNames[b_i].f1.size(1); + f1.set_size(1, paramNames[b_i].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + f1[i1] = paramNames[b_i].f1[i1]; + } + + r.f1 = f1; + coder::internal::x_strcmp(&r, priors_priorNames, r1); + coder::eml_find(r1, indices); + if (indices.size(0) != 0) { + priorFitList[b_i] = priors_priorValues[indices[0] - 1]; + priorFitList[b_i + priorFitList.size(0)] = priors_priorValues[(indices[0] + + priors_priorValues.size(0)) - 1]; + priorFitList[b_i + priorFitList.size(0) * 2] = priors_priorValues + [(indices[0] + priors_priorValues.size(0) * 2) - 1]; + priorFitList[b_i + priorFitList.size(0) * 3] = fitLimits[b_i]; + priorFitList[b_i + priorFitList.size(0) * 4] = fitLimits[b_i + + fitLimits.size(0)]; + } else { + priorFitList[b_i] = 1.0; + } + } + } +} + +// End of code generation (getFittedPriors.cpp) diff --git a/RAT/getFittedPriors.h b/RAT/getFittedPriors.h new file mode 100644 index 00000000..c740875f --- /dev/null +++ b/RAT/getFittedPriors.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// getFittedPriors.h +// +// Code generation for function 'getFittedPriors' +// +#ifndef GETFITTEDPRIORS_H +#define GETFITTEDPRIORS_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void getFittedPriors(const ::coder::array ¶mNames, const :: + coder::array &priors_priorNames, const :: + coder::array &priors_priorValues, const :: + coder::array &fitLimits, ::coder::array< + real_T, 2U> &priorFitList); +} + +#endif + +// End of code generation (getFittedPriors.h) diff --git a/RAT/getTime.cpp b/RAT/getTime.cpp new file mode 100644 index 00000000..6936f7e8 --- /dev/null +++ b/RAT/getTime.cpp @@ -0,0 +1,43 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// getTime.cpp +// +// Code generation for function 'getTime' +// + +// Include files +#include "getTime.h" +#include "RATMain_data.h" +#include "rt_nonfinite.h" +#include "coder_posix_time.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace time + { + void getTime(real_T *t_tv_sec, real_T *t_tv_nsec) + { + coderTimespec b_timespec; + if (!freq_not_empty) { + freq_not_empty = true; + coderInitTimeFunctions(&freq); + } + + coderTimeClockGettimeMonotonic(&b_timespec, freq); + *t_tv_sec = b_timespec.tv_sec; + *t_tv_nsec = b_timespec.tv_nsec; + } + } + } + } +} + +// End of code generation (getTime.cpp) diff --git a/RAT/getTime.h b/RAT/getTime.h new file mode 100644 index 00000000..2a7552f1 --- /dev/null +++ b/RAT/getTime.h @@ -0,0 +1,35 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// getTime.h +// +// Code generation for function 'getTime' +// +#ifndef GETTIME_H +#define GETTIME_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace time + { + void getTime(real_T *t_tv_sec, real_T *t_tv_nsec); + } + } + } +} + +#endif + +// End of code generation (getTime.h) diff --git a/RAT/groupLayersMod.cpp b/RAT/groupLayersMod.cpp index 3a8ce628..f8563ff7 100644 --- a/RAT/groupLayersMod.cpp +++ b/RAT/groupLayersMod.cpp @@ -20,7 +20,7 @@ namespace RAT { void groupLayersMod(const ::coder::array &allLayers, real_T allRoughs, const char_T geometry_data[], const int32_T - geometry_size[2], real_T nbair, real_T nbsubs, ::coder:: + geometry_size[2], real_T bulkIns, real_T bulkOuts, ::coder:: array &outLayers, real_T *outSsubs) { ::coder::array layers; @@ -30,35 +30,26 @@ namespace RAT int32_T loop_ub; uint32_T unnamed_idx_0; - // Arrange layers according to geometry and apply any coverage correction. + // Arrange layers according to geometry and apply any coverage correction. The paratt calculation proceeds through the + // z,rho,rough stack, and the parameter 'ssub' in callParatt is the final roughness encountered. + // + // * For air liquid 'ssub' is therefore the substrate roughness. + // * For solid liquid, the substrate roughness is the first roughness encountered, and 'ssub' is then the roughness of the outermost layer // // USAGE:: // - // [outLayers, outSsubs] = groupLayersMod(allLayers,allRoughs,numberOfContrasts,geometry,nbairs,nbsubs) + // [outLayers, outSsubs] = groupLayersMod(allLayers,allRoughs,geometry,bulkIns,bulkOuts) // // INPUTS: - // - // * allLayers = cell array, one for each contrast. Each cell is the list of layer values for each contrast. - // * allRoughs = Double of substrate roughness for each contrast. - // * numberOfContrasts = double. - // * geometry = 'Air / Liquid (or solid)' or 'Solid / Liquid' - // * nbairs = vector of nbair values. - // * nbsubs = vector of nbsub values. - // - // The paratt calculation procedds through the - // z,rho,rough stack, and the parameter 'ssub' in - // callParatt is the final roughness encountered. - // - // * For air liquid 'ssub' is therefore the substrate roughness. - // - // * For solid liquid, the substrate roughness is the first roughness encountered, and 'ssub' is then the roughness of the outermost layer + // * allLayers: cell array, one for each contrast. Each cell is the list of layer values for each contrast. + // * allRoughs: Double of substrate roughness for each contrast. + // * geometry: 'Air / Liquid (or solid)' or 'Solid / Liquid' + // * bulkIns: vector of bulkIn values. + // * bulkOuts: vector of bulkOut values. // // Outputs: - // - // * outLayers = cell array of layers param values for each contrast. - // - // * outSsubs = vector of substrate roughness values. - // + // * outLayers: cell array of layers param values for each contrast. + // * outSsubs: vector of substrate roughness values. // outLayers = cell(1,numberOfContrasts); // outSsubs = zeros(1,numberOfContrasts); // for i = 1:numberOfContrasts @@ -74,7 +65,7 @@ namespace RAT } if ((allLayers.size(0) != 0) && (allLayers.size(1) != 0)) { - if (coder::internal::i_strcmp(geometry_data, geometry_size)) { + if (coder::internal::q_strcmp(geometry_data, geometry_size)) { layers.set_size(allLayers.size(0), allLayers.size(1)); loop_ub = allLayers.size(1); b_loop_ub = allLayers.size(0); @@ -149,9 +140,9 @@ namespace RAT if (!std::isnan(this_pcw)) { real_T d; if (allLayers[j + allLayers.size(0) * 4] == 1.0) { - d = nbair; + d = bulkIns; } else { - d = nbsubs; + d = bulkOuts; } layers[j + layers.size(0)] = d * (this_pcw / 100.0) + (1.0 - diff --git a/RAT/groupLayersMod.h b/RAT/groupLayersMod.h index 9cb79841..d6631fd5 100644 --- a/RAT/groupLayersMod.h +++ b/RAT/groupLayersMod.h @@ -21,7 +21,7 @@ namespace RAT { void groupLayersMod(const ::coder::array &allLayers, real_T allRoughs, const char_T geometry_data[], const int32_T - geometry_size[2], real_T nbair, real_T nbsubs, ::coder:: + geometry_size[2], real_T bulkIns, real_T bulkOuts, ::coder:: array &outLayers, real_T *outSsubs); } diff --git a/RAT/groupLayersModImaginary.cpp b/RAT/groupLayersModImaginary.cpp index 36b5652e..792e1ba0 100644 --- a/RAT/groupLayersModImaginary.cpp +++ b/RAT/groupLayersModImaginary.cpp @@ -20,46 +20,39 @@ namespace RAT { void groupLayersModImaginary(const ::coder::array &allLayers, real_T allRoughs, const char_T geometry_data[], const int32_T geometry_size - [2], real_T nbair, real_T nbsubs, ::coder::array &outLayers, + [2], real_T bulkIns, real_T bulkOuts, ::coder::array &outLayers, real_T *outSsubs) { ::coder::array layers; ::coder::array sldss; + ::coder::array b_allLayers; + ::coder::array c_allLayers; ::coder::array roughs; int32_T b_loop_ub; int32_T i; int32_T loop_ub; uint32_T unnamed_idx_0; - // Arrange layers according to geometry and apply any coverage correction. + // Arrange layers according to geometry and apply any coverage correction. The paratt calculation proceeds through the + // z,rho,rough stack, and the parameter 'ssub' in callParatt is the final roughness encountered. + // + // * For air liquid 'ssub' is therefore the substrate roughness. + // * For solid liquid, the substrate roughness is the first roughness encountered, and 'ssub' is then the roughness of the outermost layer // // USAGE:: // - // [outLayers, outSsubs] = groupLayersMod(allLayers,allRoughs,numberOfContrasts,geometry,nbairs,nbsubs) + // [outLayers, outSsubs] = groupLayersModImaginary(allLayers,allRoughs,geometry,bulkIns,bulkOuts) // // INPUTS: - // - // * allLayers = cell array, one for each contrast. Each cell is the list of layer values for each contrast. - // * allRoughs = Double of substrate roughness for each contrast. - // * numberOfContrasts = double. - // * geometry = 'Air / Liquid (or solid)' or 'Solid / Liquid' - // * nbairs = vector of nbair values. - // * nbsubs = vector of nbsub values. - // - // The paratt calculation procedds through the - // z,rho,rough stack, and the parameter 'ssub' in - // callParatt is the final roughness encountered. - // - // * For air liquid 'ssub' is therefore the substrate roughness. - // - // * For solid liquid, the substrate roughness is the first roughness encountered, and 'ssub' is then the roughness of the outermost layer + // * allLayers: cell array, one for each contrast. Each cell is the list of layer values for each contrast. + // * allRoughs: Double of substrate roughness for each contrast. + // * geometry: 'Air / Liquid (or solid)' or 'Solid / Liquid' + // * bulkIns: vector of bulkIn values. + // * bulkOuts: vector of bulkOut values. // // Outputs: - // - // * outLayers = cell array of layers param values for each contrast. - // - // * outSsubs = vector of substrate roughness values. - // + // * outLayers: cell array of layers param values for each contrast. + // * outSsubs: vector of substrate roughness values. // outLayers = cell(1,numberOfContrasts); // outSsubs = zeros(1,numberOfContrasts); // for i = 1:numberOfContrasts @@ -75,7 +68,7 @@ namespace RAT } if ((allLayers.size(0) != 0) && (allLayers.size(1) != 0)) { - if (coder::internal::i_strcmp(geometry_data, geometry_size)) { + if (coder::internal::q_strcmp(geometry_data, geometry_size)) { layers.set_size(allLayers.size(0), allLayers.size(1)); loop_ub = allLayers.size(1); b_loop_ub = allLayers.size(0); @@ -111,41 +104,67 @@ namespace RAT } if (allLayers.size(1) == 5) { - b_loop_ub = allLayers.size(0) << 1; - layers.set_size(allLayers.size(0), 4); + int32_T b_sizes_idx_0; + int32_T sizes_idx_0; + b_allLayers.set_size(allLayers.size(0)); + loop_ub = allLayers.size(0); + for (i = 0; i < loop_ub; i++) { + b_allLayers[i] = allLayers[i]; + } + + b_loop_ub = allLayers.size(0); + sizes_idx_0 = allLayers.size(0); + b_sizes_idx_0 = allLayers.size(0); + c_allLayers.set_size(allLayers.size(0)); loop_ub = allLayers.size(0); for (i = 0; i < loop_ub; i++) { - layers[i] = allLayers[i]; + c_allLayers[i] = allLayers[i + allLayers.size(0) * 4]; } + loop_ub = allLayers.size(0); + layers.set_size(allLayers.size(0), 5); for (i = 0; i < b_loop_ub; i++) { - layers[i + layers.size(0)] = sldss[i]; + layers[i] = b_allLayers[i]; } - loop_ub = roughs.size(0); - for (i = 0; i < loop_ub; i++) { - layers[i + layers.size(0) * 2] = roughs[i]; + for (i = 0; i < 2; i++) { + for (int32_T i1{0}; i1 < sizes_idx_0; i1++) { + layers[i1 + layers.size(0) * (i + 1)] = sldss[i1 + sizes_idx_0 * i]; + } + } + + for (i = 0; i < b_sizes_idx_0; i++) { + layers[i + layers.size(0) * 3] = roughs[i]; } - loop_ub = allLayers.size(0); for (i = 0; i < loop_ub; i++) { - layers[i + layers.size(0) * 3] = allLayers[i + allLayers.size(0) * 4]; + layers[i + layers.size(0) * 4] = c_allLayers[i]; } } else { - b_loop_ub = allLayers.size(0) << 1; - layers.set_size(allLayers.size(0), 3); + int32_T b_sizes_idx_0; + int32_T sizes_idx_0; + b_allLayers.set_size(allLayers.size(0)); loop_ub = allLayers.size(0); for (i = 0; i < loop_ub; i++) { - layers[i] = allLayers[i]; + b_allLayers[i] = allLayers[i]; } + b_loop_ub = allLayers.size(0); + sizes_idx_0 = allLayers.size(0); + b_sizes_idx_0 = allLayers.size(0); + layers.set_size(allLayers.size(0), 4); for (i = 0; i < b_loop_ub; i++) { - layers[i + layers.size(0)] = sldss[i]; + layers[i] = b_allLayers[i]; } - loop_ub = roughs.size(0); - for (i = 0; i < loop_ub; i++) { - layers[i + layers.size(0) * 2] = roughs[i]; + for (i = 0; i < 2; i++) { + for (int32_T i1{0}; i1 < sizes_idx_0; i1++) { + layers[i1 + layers.size(0) * (i + 1)] = sldss[i1 + sizes_idx_0 * i]; + } + } + + for (i = 0; i < b_sizes_idx_0; i++) { + layers[i + layers.size(0) * 3] = roughs[i]; } } } @@ -159,9 +178,9 @@ namespace RAT if (!std::isnan(d)) { real_T d1; if (d == 1.0) { - d1 = nbair; + d1 = bulkIns; } else { - d1 = nbsubs; + d1 = bulkOuts; } layers[j + layers.size(0)] = d1 * (d / 100.0) + (1.0 - d / 100.0) * diff --git a/RAT/groupLayersModImaginary.h b/RAT/groupLayersModImaginary.h index 2fc57d8b..9e03c660 100644 --- a/RAT/groupLayersModImaginary.h +++ b/RAT/groupLayersModImaginary.h @@ -21,7 +21,7 @@ namespace RAT { void groupLayersModImaginary(const ::coder::array &allLayers, real_T allRoughs, const char_T geometry_data[], const int32_T geometry_size - [2], real_T nbair, real_T nbsubs, ::coder::array &outLayers, + [2], real_T bulkIns, real_T bulkOuts, ::coder::array &outLayers, real_T *outSsubs); } diff --git a/RAT/histc.cpp b/RAT/histc.cpp new file mode 100644 index 00000000..1cce4094 --- /dev/null +++ b/RAT/histc.cpp @@ -0,0 +1,115 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// histc.cpp +// +// Code generation for function 'histc' +// + +// Include files +#include "histc.h" +#include "bsearch.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + static int32_T b_findbin(real_T x, const real_T bin_edges[3]); + static int32_T findbin(real_T x, const real_T bin_edges_data[]); + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + static int32_T b_findbin(real_T x, const real_T bin_edges[3]) + { + int32_T k; + k = 0; + if (!std::isnan(x)) { + k = internal::c_bsearch(bin_edges, x); + } + + return k; + } + + static int32_T findbin(real_T x, const real_T bin_edges_data[]) + { + int32_T k; + k = 0; + if (!std::isnan(x)) { + if ((x >= bin_edges_data[0]) && (x < bin_edges_data[3])) { + k = internal::b_bsearch(bin_edges_data, x); + } + + if (x == bin_edges_data[3]) { + k = 4; + } + } + + return k; + } + + void histc(const ::coder::array &X, const real_T edges[3], + real_T N[3], ::coder::array &BIN) + { + int32_T bin; + int32_T i; + N[0] = 0.0; + N[1] = 0.0; + N[2] = 0.0; + BIN.set_size(X.size(0)); + bin = X.size(0); + for (i = 0; i < bin; i++) { + BIN[i] = 0.0; + } + + i = X.size(0); + for (int32_T k{0}; k < i; k++) { + bin = b_findbin(X[k], edges); + if (bin > 0) { + N[bin - 1]++; + } + + BIN[k] = bin; + } + } + + void histc(const ::coder::array &X, const real_T edges_data[], + real_T N_data[], int32_T *N_size, ::coder::array &BIN) + { + int32_T bin; + int32_T i; + *N_size = 4; + N_data[0] = 0.0; + N_data[1] = 0.0; + N_data[2] = 0.0; + N_data[3] = 0.0; + BIN.set_size(X.size(0)); + bin = X.size(0); + for (i = 0; i < bin; i++) { + BIN[i] = 0.0; + } + + i = X.size(0); + for (int32_T k{0}; k < i; k++) { + bin = findbin(X[k], edges_data); + if (bin > 0) { + N_data[bin - 1]++; + } + + BIN[k] = bin; + } + } + } +} + +// End of code generation (histc.cpp) diff --git a/RAT/histc.h b/RAT/histc.h new file mode 100644 index 00000000..3fd3eddf --- /dev/null +++ b/RAT/histc.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// histc.h +// +// Code generation for function 'histc' +// +#ifndef HISTC_H +#define HISTC_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void histc(const ::coder::array &X, const real_T edges[3], + real_T N[3], ::coder::array &BIN); + void histc(const ::coder::array &X, const real_T edges_data[], + real_T N_data[], int32_T *N_size, ::coder::array &BIN); + } +} + +#endif + +// End of code generation (histc.h) diff --git a/RAT/ifWhileCond.cpp b/RAT/ifWhileCond.cpp new file mode 100644 index 00000000..d9791160 --- /dev/null +++ b/RAT/ifWhileCond.cpp @@ -0,0 +1,71 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// ifWhileCond.cpp +// +// Code generation for function 'ifWhileCond' +// + +// Include files +#include "ifWhileCond.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + static boolean_T checkNoNaNs(const ::coder::array &x); + } + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + static boolean_T checkNoNaNs(const ::coder::array &x) + { + int32_T i; + int32_T k; + boolean_T exitg1; + boolean_T y; + y = true; + i = x.size(0) * x.size(1); + k = 0; + exitg1 = false; + while ((!exitg1) && (k <= i - 1)) { + if (!x[k]) { + y = false; + exitg1 = true; + } else { + k++; + } + } + + return y; + } + + boolean_T ifWhileCond(const ::coder::array &x) + { + boolean_T y; + y = ((x.size(0) != 0) && (x.size(1) != 0)); + if (y) { + y = checkNoNaNs(x); + } + + return y; + } + } + } +} + +// End of code generation (ifWhileCond.cpp) diff --git a/RAT/ifWhileCond.h b/RAT/ifWhileCond.h new file mode 100644 index 00000000..597b1ee5 --- /dev/null +++ b/RAT/ifWhileCond.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// ifWhileCond.h +// +// Code generation for function 'ifWhileCond' +// +#ifndef IFWHILECOND_H +#define IFWHILECOND_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + boolean_T ifWhileCond(const ::coder::array &x); + } + } +} + +#endif + +// End of code generation (ifWhileCond.h) diff --git a/RAT/inEllipsoids.cpp b/RAT/inEllipsoids.cpp new file mode 100644 index 00000000..68cf5df8 --- /dev/null +++ b/RAT/inEllipsoids.cpp @@ -0,0 +1,219 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// inEllipsoids.cpp +// +// Code generation for function 'inEllipsoids' +// + +// Include files +#include "inEllipsoids.h" +#include "RATMain_data.h" +#include "diag.h" +#include "eig.h" +#include "rt_nonfinite.h" +#include "sqrt.h" +#include "sum.h" +#include "unsafeSxfun.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + real_T inEllipsoids(const ::coder::array &pnt, const ::coder:: + array &Bs, const ::coder::array + &mus) + { + ::coder::array E; + ::coder::array V; + ::coder::array b_pnt; + ::coder::array c_pnt; + ::coder::array r; + ::coder::array b_Bs; + creal_T varargin_1; + real_T N; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + int32_T ndims; + + // function N = inEllipsoids(pnt, Bs, mus) + // + // This function works out how many of the ellipsoids (defined by the + // bounding matrices Bs and centroids mus) contain the point pnt. + // This number is returned in N. + // + // Bs is a [(Kxndims) x ndims] array, where K=total number of ellipsoids + // and ndims = dimension of the parameter space. + // mus is a [K x ndims] array. + // pnt is a ndims-dimensional vector. + // + // NOTE: in the future it may be quicker to input precalculated eigenvalues + // and eigenvectors into this function rather than the bounding matrices + // + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + N = 0.0; + + // total number of ellipsoids and number of dimensions + ndims = mus.size(1); + + // loop over number of ellipsiods and work out whether it contains the point + i = mus.size(0); + if (i - 1 >= 0) { + loop_ub = Bs.size(1); + b_loop_ub = pnt.size(1); + } + + for (int32_T k{0}; k < i; k++) { + int32_T b_k; + int32_T c_loop_ub; + int32_T i1; + int32_T i2; + + // set the point to have the same origin as the ellipsoid + // extract the bounding matrix + i1 = k * ndims; + i2 = (k + 1) * ndims; + if (i1 + 1 > i2) { + i1 = 0; + i2 = 0; + } + + // get the eigenvalues and eigenvectors of the ellipsoid + c_loop_ub = i2 - i1; + b_Bs.set_size(c_loop_ub, Bs.size(1)); + for (i2 = 0; i2 < loop_ub; i2++) { + for (b_k = 0; b_k < c_loop_ub; b_k++) { + b_Bs[b_k + b_Bs.size(0) * i2] = Bs[(i1 + b_k) + Bs.size(0) * i2]; + } + } + + coder::eig(b_Bs, V, E); + + // V is matrix of eigenvectors (as columns) + // rotate points to be on coordinate axes of the ellipsiod + // scale points so that it's equivalent to having unit hyper-spheroids + // rather than ellipsiods + // get distance to point from centre of hyper-sphere + coder::diag(E, r); + i1 = r.size(0); + for (b_k = 0; b_k < i1; b_k++) { + coder::internal::scalar::d_sqrt(&r[b_k]); + } + + if ((pnt.size(1) == mus.size(1)) && (r.size(0) == V.size(1))) { + real_T pnt_re_tmp; + c_pnt.set_size(1, pnt.size(1)); + for (i1 = 0; i1 < b_loop_ub; i1++) { + c_pnt[i1].re = pnt[i1] - mus[k + mus.size(0) * i1]; + c_pnt[i1].im = 0.0; + } + + c_loop_ub = V.size(1); + b_pnt.set_size(1, V.size(1)); + for (i1 = 0; i1 < c_loop_ub; i1++) { + real_T b_pnt_re_tmp; + real_T c_pnt_re_tmp; + real_T d_pnt_re_tmp; + real_T im; + real_T re; + re = 0.0; + im = 0.0; + b_k = c_pnt.size(1); + for (i2 = 0; i2 < b_k; i2++) { + pnt_re_tmp = c_pnt[i2].re; + d_pnt_re_tmp = V[i2 + V.size(0) * i1].im; + b_pnt_re_tmp = c_pnt[i2].im; + c_pnt_re_tmp = V[i2 + V.size(0) * i1].re; + re += pnt_re_tmp * c_pnt_re_tmp - b_pnt_re_tmp * d_pnt_re_tmp; + im += pnt_re_tmp * d_pnt_re_tmp + b_pnt_re_tmp * c_pnt_re_tmp; + } + + b_pnt_re_tmp = r[i1].re; + c_pnt_re_tmp = -r[i1].im; + if (c_pnt_re_tmp == 0.0) { + if (im == 0.0) { + b_pnt[i1].re = re / b_pnt_re_tmp; + b_pnt[i1].im = 0.0; + } else if (re == 0.0) { + b_pnt[i1].re = 0.0; + b_pnt[i1].im = im / b_pnt_re_tmp; + } else { + b_pnt[i1].re = re / b_pnt_re_tmp; + b_pnt[i1].im = im / b_pnt_re_tmp; + } + } else if (b_pnt_re_tmp == 0.0) { + if (re == 0.0) { + b_pnt[i1].re = im / c_pnt_re_tmp; + b_pnt[i1].im = 0.0; + } else if (im == 0.0) { + b_pnt[i1].re = 0.0; + b_pnt[i1].im = -(re / c_pnt_re_tmp); + } else { + b_pnt[i1].re = im / c_pnt_re_tmp; + b_pnt[i1].im = -(re / c_pnt_re_tmp); + } + } else { + real_T brm; + brm = std::abs(b_pnt_re_tmp); + pnt_re_tmp = std::abs(c_pnt_re_tmp); + if (brm > pnt_re_tmp) { + d_pnt_re_tmp = c_pnt_re_tmp / b_pnt_re_tmp; + pnt_re_tmp = b_pnt_re_tmp + d_pnt_re_tmp * c_pnt_re_tmp; + b_pnt[i1].re = (re + d_pnt_re_tmp * im) / pnt_re_tmp; + b_pnt[i1].im = (im - d_pnt_re_tmp * re) / pnt_re_tmp; + } else if (pnt_re_tmp == brm) { + if (b_pnt_re_tmp > 0.0) { + d_pnt_re_tmp = 0.5; + } else { + d_pnt_re_tmp = -0.5; + } + + if (c_pnt_re_tmp > 0.0) { + pnt_re_tmp = 0.5; + } else { + pnt_re_tmp = -0.5; + } + + b_pnt[i1].re = (re * d_pnt_re_tmp + im * pnt_re_tmp) / brm; + b_pnt[i1].im = (im * d_pnt_re_tmp - re * pnt_re_tmp) / brm; + } else { + d_pnt_re_tmp = b_pnt_re_tmp / c_pnt_re_tmp; + pnt_re_tmp = c_pnt_re_tmp + d_pnt_re_tmp * b_pnt_re_tmp; + b_pnt[i1].re = (d_pnt_re_tmp * re + im) / pnt_re_tmp; + b_pnt[i1].im = (d_pnt_re_tmp * im - re) / pnt_re_tmp; + } + } + } + + b_pnt.set_size(1, b_pnt.size(1)); + c_loop_ub = b_pnt.size(1); + for (i1 = 0; i1 < c_loop_ub; i1++) { + creal_T varargout_1; + varargin_1 = b_pnt[i1]; + varargout_1.re = varargin_1.re * varargin_1.re - varargin_1.im * + varargin_1.im; + pnt_re_tmp = varargin_1.re * varargin_1.im; + varargout_1.im = pnt_re_tmp + pnt_re_tmp; + b_pnt[i1] = varargout_1; + } + } else { + binary_expand_op(b_pnt, pnt, mus, k, V, r); + } + + varargin_1 = coder::sum(b_pnt); + coder::internal::scalar::d_sqrt(&varargin_1); + if (varargin_1.re <= 1.0) { + // values is within the ellipsiod + N++; + } + } + + return N; + } +} + +// End of code generation (inEllipsoids.cpp) diff --git a/RAT/inEllipsoids.h b/RAT/inEllipsoids.h new file mode 100644 index 00000000..d8b23ed6 --- /dev/null +++ b/RAT/inEllipsoids.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// inEllipsoids.h +// +// Code generation for function 'inEllipsoids' +// +#ifndef INELLIPSOIDS_H +#define INELLIPSOIDS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + real_T inEllipsoids(const ::coder::array &pnt, const ::coder:: + array &Bs, const ::coder::array + &mus); +} + +#endif + +// End of code generation (inEllipsoids.h) diff --git a/RAT/initializeDREAM.cpp b/RAT/initializeDREAM.cpp new file mode 100644 index 00000000..add103df --- /dev/null +++ b/RAT/initializeDREAM.cpp @@ -0,0 +1,419 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// initializeDREAM.cpp +// +// Code generation for function 'initializeDREAM' +// + +// Include files +#include "initializeDREAM.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "boundaryHandling.h" +#include "calcDensity.h" +#include "drawCR.h" +#include "evaluateModel.h" +#include "rand.h" +#include "repmat.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const + struct14_T *in4); + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const ::coder:: + array &in4); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const + struct14_T *in4) + { + ::coder::array b_in2; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in3.size(1) == 1) { + i = in2.size(1); + } else { + i = in3.size(1); + } + + b_in2.set_size(1, i); + stride_0_1 = (in2.size(1) != 1); + stride_1_1 = (in3.size(1) != 1); + if (in3.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(1); + } + + for (i = 0; i < loop_ub; i++) { + b_in2[i] = in2[i * stride_0_1] - in3[i * stride_1_1]; + } + + coder::repmat(b_in2, in4->N, in1); + } + + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const ::coder:: + array &in4) + { + int32_T aux_0_1; + int32_T aux_1_1; + int32_T aux_2_1; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_0_1; + int32_T stride_1_0; + int32_T stride_1_1; + int32_T stride_2_0; + int32_T stride_2_1; + if (in4.size(0) == 1) { + i = in3.size(0); + } else { + i = in4.size(0); + } + + if (i == 1) { + i = in2.size(0); + } else if (in4.size(0) == 1) { + i = in3.size(0); + } else { + i = in4.size(0); + } + + if (in4.size(1) == 1) { + i1 = in3.size(1); + } else { + i1 = in4.size(1); + } + + if (i1 == 1) { + i1 = in2.size(1); + } else if (in4.size(1) == 1) { + i1 = in3.size(1); + } else { + i1 = in4.size(1); + } + + in1.set_size(i, i1); + stride_0_0 = (in2.size(0) != 1); + stride_0_1 = (in2.size(1) != 1); + stride_1_0 = (in3.size(0) != 1); + stride_1_1 = (in3.size(1) != 1); + stride_2_0 = (in4.size(0) != 1); + stride_2_1 = (in4.size(1) != 1); + aux_0_1 = 0; + aux_1_1 = 0; + aux_2_1 = 0; + if (in4.size(1) == 1) { + i = in3.size(1); + } else { + i = in4.size(1); + } + + if (i == 1) { + loop_ub = in2.size(1); + } else if (in4.size(1) == 1) { + loop_ub = in3.size(1); + } else { + loop_ub = in4.size(1); + } + + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + int32_T i2; + i1 = in4.size(0); + b_loop_ub = in3.size(0); + if (i1 == 1) { + i2 = b_loop_ub; + } else { + i2 = i1; + } + + if (i2 == 1) { + b_loop_ub = in2.size(0); + } else if (i1 != 1) { + b_loop_ub = i1; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + in1[i1 + in1.size(0) * i] = in2[i1 * stride_0_0 + in2.size(0) * aux_0_1] + + in3[i1 * stride_1_0 + in3.size(0) * aux_1_1] * in4[i1 * stride_2_0 + + in4.size(0) * aux_2_1]; + } + + aux_2_1 += stride_2_1; + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + } + + void initializeDREAM(const struct14_T *DREAMPar, const ::coder::array &Par_info_min, const ::coder::array + &Par_info_max, const char_T Par_info_boundhandling_data[], + const int32_T Par_info_boundhandling_size[2], ::coder:: + array &chain, struct13_T *output, ::coder:: + array &log_L, const struct5_T + *ratInputs_problemDef, const cell_14 + *ratInputs_problemDefCells, const struct2_T + *ratInputs_controls, const ::coder::array + &ratInputs_priors, ::coder::array &X, ::coder:: + array &fx, ::coder::array &CR, + real_T pCR_data[], int32_T pCR_size[2], real_T lCR_data[], + int32_T lCR_size[2], real_T delta_tot_data[], int32_T + delta_tot_size[2]) + { + ::coder::array b_Par_info_max; + ::coder::array b_X; + ::coder::array r; + ::coder::array r1; + ::coder::array x; + ::coder::array log_L_x; + ::coder::array log_PR_x; + int32_T b_loop_ub; + int32_T i; + int32_T i1; + int32_T input_sizes_idx_1; + int32_T loop_ub; + int8_T b_input_sizes_idx_1; + int8_T sizes_idx_1; + boolean_T empty_non_axis_sizes; + + // Initializes the starting positions of the Markov chains + // Create the initial positions of the chains + // switch Par_info.prior + // + // case {'uniform'} + // Random sampling + coder::b_rand(DREAMPar->N, DREAMPar->d, b_X); + if (Par_info_max.size(1) == Par_info_min.size(1)) { + b_Par_info_max.set_size(1, Par_info_max.size(1)); + loop_ub = Par_info_max.size(1); + for (i = 0; i < loop_ub; i++) { + b_Par_info_max[i] = Par_info_max[i] - Par_info_min[i]; + } + + coder::repmat(b_Par_info_max, DREAMPar->N, r); + } else { + binary_expand_op(r, Par_info_max, Par_info_min, DREAMPar); + } + + coder::repmat(Par_info_min, DREAMPar->N, r1); + + // case {'latin'} + // % Initialize chains with latinHypercubeSampling hypercube sampling + // if isfield(Par_info,'min_initial') && isfield(Par_info,'max_initial') + // [x] = latinHypercubeSampling(Par_info.min_initial,Par_info.max_initial,DREAMPar.N); + // else + // [x] = latinHypercubeSampling(Par_info.min,Par_info.max,DREAMPar.N); + // end + // case {'normal'} + // + // % Initialize chains with (multi)-normal distribution + // [x] = repmat(Par_info.mu,DREAMPar.N,1) + randn(DREAMPar.N,DREAMPar.d) * chol(Par_info.cov); + // + // case {'prior'} + // + // % Create the initial position of each chain by drawing each parameter individually from the prior + // for qq = 1:DREAMPar.d + // for zz = 1:DREAMPar.N + // x(zz,qq) = eval(char(Par_info.prior_marginal(qq))); + // end + // end + // + // otherwise + // + // error('unknown initial sampling method'); + // end + // If specified do boundary handling ( "Bound","Reflect","Fold") + if (b_X.size(0) == 1) { + i = r.size(0); + } else { + i = b_X.size(0); + } + + if (b_X.size(1) == 1) { + i1 = r.size(1); + } else { + i1 = b_X.size(1); + } + + if ((b_X.size(0) == r.size(0)) && (b_X.size(1) == r.size(1)) && (r1.size(0) == + i) && (r1.size(1) == i1)) { + x.set_size(r1.size(0), r1.size(1)); + loop_ub = r1.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = r1.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + x[i1 + x.size(0) * i] = r1[i1 + r1.size(0) * i] + b_X[i1 + b_X.size(0) + * i] * r[i1 + r.size(0) * i]; + } + } + } else { + binary_expand_op(x, r1, b_X, r); + } + + boundaryHandling(x, Par_info_min, Par_info_max, Par_info_boundhandling_data, + Par_info_boundhandling_size); + + // Now evaluate the model ( = pdf ) and return fx + evaluateModel(x, DREAMPar, ratInputs_problemDef, ratInputs_problemDefCells, + ratInputs_controls, fx); + + // Calculate the log-likelihood and log-prior of x (fx) + calcDensity(x, fx, DREAMPar, ratInputs_problemDef->fitLimits, + ratInputs_priors, log_L_x, log_PR_x); + + // Define starting x values, corresponding density, log densty and simulations (Xfx) + if ((x.size(0) != 0) && (x.size(1) != 0)) { + b_loop_ub = x.size(0); + } else if (log_PR_x.size(0) != 0) { + b_loop_ub = log_PR_x.size(0); + } else if (log_L_x.size(0) != 0) { + b_loop_ub = log_L_x.size(0); + } else { + b_loop_ub = x.size(0); + } + + empty_non_axis_sizes = (b_loop_ub == 0); + if (empty_non_axis_sizes || ((x.size(0) != 0) && (x.size(1) != 0))) { + input_sizes_idx_1 = x.size(1); + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || (log_PR_x.size(0) != 0)) { + b_input_sizes_idx_1 = 1; + } else { + b_input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || (log_L_x.size(0) != 0)) { + sizes_idx_1 = 1; + } else { + sizes_idx_1 = 0; + } + + X.set_size(b_loop_ub, (input_sizes_idx_1 + b_input_sizes_idx_1) + + sizes_idx_1); + for (i = 0; i < input_sizes_idx_1; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + X[i1 + X.size(0) * i] = x[i1 + b_loop_ub * i]; + } + } + + loop_ub = b_input_sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + X[i1 + X.size(0) * input_sizes_idx_1] = log_PR_x[i1]; + } + } + + loop_ub = sizes_idx_1; + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + X[i1 + X.size(0) * (input_sizes_idx_1 + b_input_sizes_idx_1)] = + log_L_x[i1]; + } + } + + // Store the model simulations (if appropriate) + // storeDREAMResults(DREAMPar,fx,Meas_info,'w+'); + // Set the first point of each of the DREAMPar.N chain equal to the initial X values + b_X.set_size(X.size(1), X.size(0)); + loop_ub = X.size(0); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = X.size(1); + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_X[i1 + b_X.size(0) * i] = X[i + X.size(0) * i1]; + } + } + + b_loop_ub = static_cast(DREAMPar->d + 2.0); + loop_ub = static_cast(DREAMPar->N); + for (i = 0; i < loop_ub; i++) { + for (i1 = 0; i1 < b_loop_ub; i1++) { + chain[chain.size(0) * i1 + chain.size(0) * chain.size(1) * i] = b_X[i1 + + b_loop_ub * i]; + } + } + + int32_T iv[2]; + + // Define selection probability of each crossover + b_Par_info_max.set_size(1, 3); + pCR_size[0] = 1; + pCR_size[1] = 3; + b_Par_info_max[0] = 0.33333333333333331; + pCR_data[0] = 0.33333333333333331; + b_Par_info_max[1] = 0.33333333333333331; + pCR_data[1] = 0.33333333333333331; + b_Par_info_max[2] = 0.33333333333333331; + pCR_data[2] = 0.33333333333333331; + + // Generate the actula CR value, lCR and delta_tot + iv[0] = (*(int32_T (*)[2])b_Par_info_max.size())[0]; + iv[1] = (*(int32_T (*)[2])b_Par_info_max.size())[1]; + drawCR(DREAMPar, (const real_T *)b_Par_info_max.data(), iv, CR); + + // coder.varsize('CR',[100 1e4],[1 1]); + lCR_size[0] = 1; + lCR_size[1] = 3; + delta_tot_size[0] = 1; + delta_tot_size[1] = 3; + lCR_data[0] = 0.0; + delta_tot_data[0] = 0.0; + lCR_data[1] = 0.0; + delta_tot_data[1] = 0.0; + lCR_data[2] = 0.0; + delta_tot_data[2] = 0.0; + + // Save pCR values in memory + output->CR[0] = DREAMPar->N; + for (i = 0; i < 3; i++) { + output->CR[output->CR.size(0) * (i + 1)] = 0.33333333333333331; + } + + // Save history log density of individual chains + log_L[0] = DREAMPar->N; + loop_ub = log_L_x.size(0); + for (i = 0; i < loop_ub; i++) { + log_L[log_L.size(0) * (i + 1)] = log_L_x[i]; + } + + // Compute the R-statistic + // Calculates the R-statistic convergence diagnostic + // ---------------------------------------------------- + // For more information please refer to: Gelman, A. and D.R. Rubin, 1992. + // Inference from Iterative Simulation Using Multiple chain, + // Statistical Science, Volume 7, Issue 4, 457-472. + // + // Written by Jasper A. Vrugt + // Los Alamos, August 2007 + // ---------------------------------------------------- + // Compute the dimensions of chain + // Set the R-statistic to a large value + output->R_stat[0] = DREAMPar->N; + loop_ub = static_cast(DREAMPar->d); + for (i = 0; i < loop_ub; i++) { + output->R_stat[output->R_stat.size(0) * (i + 1)] = rtNaN; + } + } +} + +// End of code generation (initializeDREAM.cpp) diff --git a/RAT/initializeDREAM.h b/RAT/initializeDREAM.h new file mode 100644 index 00000000..1cf70066 --- /dev/null +++ b/RAT/initializeDREAM.h @@ -0,0 +1,50 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// initializeDREAM.h +// +// Code generation for function 'initializeDREAM' +// +#ifndef INITIALIZEDREAM_H +#define INITIALIZEDREAM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct14_T; + struct struct13_T; + struct struct5_T; + struct cell_14; + struct struct2_T; +} + +// Function Declarations +namespace RAT +{ + void initializeDREAM(const struct14_T *DREAMPar, const ::coder::array &Par_info_min, const ::coder::array + &Par_info_max, const char_T Par_info_boundhandling_data[], + const int32_T Par_info_boundhandling_size[2], ::coder:: + array &chain, struct13_T *output, ::coder:: + array &log_L, const struct5_T + *ratInputs_problemDef, const cell_14 + *ratInputs_problemDefCells, const struct2_T + *ratInputs_controls, const ::coder::array + &ratInputs_priors, ::coder::array &X, ::coder:: + array &fx, ::coder::array &CR, + real_T pCR_data[], int32_T pCR_size[2], real_T lCR_data[], + int32_T lCR_size[2], real_T delta_tot_data[], int32_T + delta_tot_size[2]); +} + +#endif + +// End of code generation (initializeDREAM.h) diff --git a/RAT/interp1.cpp b/RAT/interp1.cpp index 93637384..d3eb7e16 100644 --- a/RAT/interp1.cpp +++ b/RAT/interp1.cpp @@ -22,6 +22,12 @@ namespace RAT { namespace coder { + static void interp1Linear(const ::coder::array &y, int32_T + nyrows, const ::coder::array &xi, ::coder::array + &yi, const ::coder::array &varargin_1); + static void interp1Linear(const ::coder::array &y, const ::coder:: + array &xi, ::coder::array &yi, const ::coder:: + array &varargin_1); static void interp1Linear(const ::coder::array &y, const ::coder:: array &xi, ::coder::array &yi, const ::coder:: array &varargin_1); @@ -33,6 +39,97 @@ namespace RAT { namespace coder { + static void interp1Linear(const ::coder::array &y, int32_T + nyrows, const ::coder::array &xi, ::coder::array + &yi, const ::coder::array &varargin_1) + { + real_T d; + real_T maxx; + real_T minx; + real_T penx; + real_T r; + int32_T n; + int32_T ub_loop; + minx = varargin_1[0]; + penx = varargin_1[varargin_1.size(0) - 2]; + maxx = varargin_1[varargin_1.size(0) - 1]; + ub_loop = xi.size(1) - 1; + +#pragma omp parallel for \ + num_threads(omp_get_max_threads()) \ + private(d,r,n) + + for (int32_T k = 0; k <= ub_loop; k++) { + d = xi[k]; + if (std::isnan(d)) { + yi[k] = rtNaN; + } else if (d > maxx) { + if (nyrows > 1) { + r = y[nyrows - 1]; + yi[k] = r + (d - maxx) / (maxx - penx) * (r - y[nyrows - 2]); + } + } else if (d < minx) { + yi[k] = y[0] + (d - minx) / (varargin_1[1] - minx) * (y[1] - y[0]); + } else { + n = internal::b_bsearch(varargin_1, d) - 1; + r = (d - varargin_1[n]) / (varargin_1[n + 1] - varargin_1[n]); + if (r == 0.0) { + yi[k] = y[n]; + } else if (r == 1.0) { + yi[k] = y[n + 1]; + } else { + d = y[n + 1]; + if (y[n] == d) { + yi[k] = y[n]; + } else { + yi[k] = (1.0 - r) * y[n] + r * d; + } + } + } + } + } + + static void interp1Linear(const ::coder::array &y, const ::coder:: + array &xi, ::coder::array &yi, const ::coder:: + array &varargin_1) + { + real_T d; + real_T maxx; + real_T minx; + real_T r; + int32_T n; + int32_T ub_loop; + minx = varargin_1[0]; + maxx = varargin_1[varargin_1.size(0) - 1]; + ub_loop = xi.size(1) - 1; + +#pragma omp parallel for \ + num_threads(omp_get_max_threads()) \ + private(d,n,r) + + for (int32_T k = 0; k <= ub_loop; k++) { + d = xi[k]; + if (std::isnan(d)) { + yi[k] = rtNaN; + } else if ((!(d > maxx)) && (!(d < minx))) { + n = internal::b_bsearch(varargin_1, d) - 1; + r = (d - varargin_1[n]) / (varargin_1[n + 1] - varargin_1[n]); + if (r == 0.0) { + yi[k] = y[n]; + } else if (r == 1.0) { + yi[k] = y[n + 1]; + } else { + d = y[n + 1]; + if (y[n] == d) { + yi[k] = y[n]; + } else { + yi[k] = (1.0 - r) * y[n] + r * d; + } + } + } + } + } + static void interp1Linear(const ::coder::array &y, const ::coder:: array &xi, ::coder::array &yi, const ::coder:: array &varargin_1) @@ -69,6 +166,130 @@ namespace RAT } } + void b_interp1(const ::coder::array &varargin_1, const ::coder:: + array &varargin_2, const ::coder::array &varargin_3, ::coder::array &Vq) + { + ::coder::array x; + ::coder::array y; + int32_T i; + int32_T k; + int32_T nx; + boolean_T b; + y.set_size(varargin_2.size(0)); + k = varargin_2.size(0); + for (i = 0; i < k; i++) { + y[i] = varargin_2[i]; + } + + x.set_size(varargin_1.size(0)); + k = varargin_1.size(0); + for (i = 0; i < k; i++) { + x[i] = varargin_1[i]; + } + + nx = varargin_1.size(0) - 1; + Vq.set_size(1, static_cast(static_cast(varargin_3.size(1)))); + k = static_cast(varargin_3.size(1)); + for (i = 0; i < k; i++) { + Vq[i] = rtNaN; + } + + b = (varargin_3.size(1) == 0); + if (!b) { + k = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (k <= nx) { + if (std::isnan(varargin_1[k])) { + exitg1 = 1; + } else { + k++; + } + } else { + if (varargin_1[1] < varargin_1[0]) { + i = (nx + 1) >> 1; + for (int32_T b_j1{0}; b_j1 < i; b_j1++) { + real_T xtmp; + xtmp = x[b_j1]; + k = nx - b_j1; + x[b_j1] = x[k]; + x[k] = xtmp; + } + + flip(y); + } + + interp1Linear(y, varargin_3, Vq, x); + exitg1 = 1; + } + } while (exitg1 == 0); + } + } + + void interp1(const ::coder::array &varargin_1, const ::coder:: + array &varargin_2, const ::coder::array + &varargin_3, ::coder::array &Vq) + { + ::coder::array x; + ::coder::array y; + int32_T i; + int32_T k; + int32_T nx; + boolean_T b; + y.set_size(varargin_2.size(0)); + k = varargin_2.size(0); + for (i = 0; i < k; i++) { + y[i] = varargin_2[i]; + } + + x.set_size(varargin_1.size(0)); + k = varargin_1.size(0); + for (i = 0; i < k; i++) { + x[i] = varargin_1[i]; + } + + nx = varargin_1.size(0) - 1; + Vq.set_size(1, static_cast(static_cast(varargin_3.size(1)))); + k = static_cast(varargin_3.size(1)); + for (i = 0; i < k; i++) { + Vq[i] = 0.0; + } + + b = (varargin_3.size(1) == 0); + if (!b) { + k = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (k <= nx) { + if (std::isnan(varargin_1[k])) { + exitg1 = 1; + } else { + k++; + } + } else { + if (varargin_1[1] < varargin_1[0]) { + i = (nx + 1) >> 1; + for (int32_T b_j1{0}; b_j1 < i; b_j1++) { + real_T xtmp; + xtmp = x[b_j1]; + k = nx - b_j1; + x[b_j1] = x[k]; + x[k] = xtmp; + } + + flip(y); + } + + interp1Linear(y, varargin_2.size(0), varargin_3, Vq, x); + exitg1 = 1; + } + } while (exitg1 == 0); + } + } + void interp1(const ::coder::array &varargin_1, const ::coder:: array &varargin_2, const ::coder::array &varargin_3, ::coder::array &Vq) diff --git a/RAT/interp1.h b/RAT/interp1.h index d9767ea6..4c367cea 100644 --- a/RAT/interp1.h +++ b/RAT/interp1.h @@ -21,6 +21,12 @@ namespace RAT { namespace coder { + void b_interp1(const ::coder::array &varargin_1, const ::coder:: + array &varargin_2, const ::coder::array &varargin_3, ::coder::array &Vq); + void interp1(const ::coder::array &varargin_1, const ::coder:: + array &varargin_2, const ::coder::array + &varargin_3, ::coder::array &Vq); void interp1(const ::coder::array &varargin_1, const ::coder:: array &varargin_2, const ::coder::array &varargin_3, ::coder::array &Vq); diff --git a/RAT/ishermitian.cpp b/RAT/ishermitian.cpp new file mode 100644 index 00000000..ddbd31cf --- /dev/null +++ b/RAT/ishermitian.cpp @@ -0,0 +1,97 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// ishermitian.cpp +// +// Code generation for function 'ishermitian' +// + +// Include files +#include "ishermitian.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + boolean_T b_ishermitian(const ::coder::array &A) + { + boolean_T p; + p = (A.size(0) == A.size(1)); + if (p) { + int32_T j; + boolean_T exitg2; + j = 0; + exitg2 = false; + while ((!exitg2) && (j <= A.size(1) - 1)) { + int32_T exitg1; + int32_T i; + i = 0; + do { + exitg1 = 0; + if (i <= j) { + if (!(A[i + A.size(0) * j] == -A[j + A.size(0) * i])) { + p = false; + exitg1 = 1; + } else { + i++; + } + } else { + j++; + exitg1 = 2; + } + } while (exitg1 == 0); + + if (exitg1 == 1) { + exitg2 = true; + } + } + } + + return p; + } + + boolean_T ishermitian(const ::coder::array &A) + { + boolean_T p; + p = (A.size(0) == A.size(1)); + if (p) { + int32_T j; + boolean_T exitg2; + j = 0; + exitg2 = false; + while ((!exitg2) && (j <= A.size(1) - 1)) { + int32_T exitg1; + int32_T i; + i = 0; + do { + exitg1 = 0; + if (i <= j) { + if (!(A[i + A.size(0) * j] == A[j + A.size(0) * i])) { + p = false; + exitg1 = 1; + } else { + i++; + } + } else { + j++; + exitg1 = 2; + } + } while (exitg1 == 0); + + if (exitg1 == 1) { + exitg2 = true; + } + } + } + + return p; + } + } +} + +// End of code generation (ishermitian.cpp) diff --git a/RAT/ishermitian.h b/RAT/ishermitian.h new file mode 100644 index 00000000..dd2c94ac --- /dev/null +++ b/RAT/ishermitian.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// ishermitian.h +// +// Code generation for function 'ishermitian' +// +#ifndef ISHERMITIAN_H +#define ISHERMITIAN_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + boolean_T b_ishermitian(const ::coder::array &A); + boolean_T ishermitian(const ::coder::array &A); + } +} + +#endif + +// End of code generation (ishermitian.h) diff --git a/RAT/isrow.cpp b/RAT/isrow.cpp new file mode 100644 index 00000000..8b3cf3f5 --- /dev/null +++ b/RAT/isrow.cpp @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// isrow.cpp +// +// Code generation for function 'isrow' +// + +// Include files +#include "isrow.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + boolean_T isrow(const ::coder::array &x) + { + return x.size(0) == 1; + } + } +} + +// End of code generation (isrow.cpp) diff --git a/RAT/isrow.h b/RAT/isrow.h new file mode 100644 index 00000000..52f3a6cf --- /dev/null +++ b/RAT/isrow.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// isrow.h +// +// Code generation for function 'isrow' +// +#ifndef ISROW_H +#define ISROW_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + boolean_T isrow(const ::coder::array &x); + } +} + +#endif + +// End of code generation (isrow.h) diff --git a/RAT/ixamax.cpp b/RAT/ixamax.cpp new file mode 100644 index 00000000..07d2c047 --- /dev/null +++ b/RAT/ixamax.cpp @@ -0,0 +1,80 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// ixamax.cpp +// +// Code generation for function 'ixamax' +// + +// Include files +#include "ixamax.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + int32_T ixamax(int32_T n, const ::coder::array &x, int32_T + ix0) + { + int32_T idxmax; + if (n < 1) { + idxmax = 0; + } else { + idxmax = 1; + if (n > 1) { + real_T smax; + smax = std::abs(x[ix0 - 1]); + for (int32_T k{2}; k <= n; k++) { + real_T s; + s = std::abs(x[(ix0 + k) - 2]); + if (s > smax) { + idxmax = k; + smax = s; + } + } + } + } + + return idxmax; + } + + int32_T ixamax(int32_T n, const ::coder::array &x, int32_T + ix0) + { + int32_T idxmax; + if (n < 1) { + idxmax = 0; + } else { + idxmax = 1; + if (n > 1) { + real_T smax; + smax = std::abs(x[ix0 - 1]); + for (int32_T k{2}; k <= n; k++) { + real_T s; + s = std::abs(x[(ix0 + k) - 2]); + if (s > smax) { + idxmax = k; + smax = s; + } + } + } + } + + return idxmax; + } + } + } + } +} + +// End of code generation (ixamax.cpp) diff --git a/RAT/ixamax.h b/RAT/ixamax.h new file mode 100644 index 00000000..7a005d91 --- /dev/null +++ b/RAT/ixamax.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// ixamax.h +// +// Code generation for function 'ixamax' +// +#ifndef IXAMAX_H +#define IXAMAX_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + int32_T ixamax(int32_T n, const ::coder::array &x, int32_T + ix0); + int32_T ixamax(int32_T n, const ::coder::array &x, int32_T + ix0); + } + } + } +} + +#endif + +// End of code generation (ixamax.h) diff --git a/RAT/ixfun.cpp b/RAT/ixfun.cpp new file mode 100644 index 00000000..3a8b6725 --- /dev/null +++ b/RAT/ixfun.cpp @@ -0,0 +1,72 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// ixfun.cpp +// +// Code generation for function 'ixfun' +// + +// Include files +#include "ixfun.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + void expand_max(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c) + { + int32_T csz_idx_0; + int32_T k; + int32_T u0; + u0 = a.size(0); + k = b.size(0); + if (u0 <= k) { + k = u0; + } + + if (b.size(0) == 1) { + csz_idx_0 = a.size(0); + } else if (a.size(0) == 1) { + csz_idx_0 = b.size(0); + } else { + csz_idx_0 = k; + } + + u0 = a.size(0); + k = b.size(0); + if (u0 <= k) { + k = u0; + } + + if (b.size(0) == 1) { + k = a.size(0); + } else if (a.size(0) == 1) { + k = b.size(0); + } + + c.set_size(k); + if (csz_idx_0 != 0) { + boolean_T b1; + boolean_T b_b; + b_b = (a.size(0) != 1); + b1 = (b.size(0) != 1); + u0 = csz_idx_0 - 1; + for (k = 0; k <= u0; k++) { + c[k] = std::fmax(a[b_b * k], b[b1 * k]); + } + } + } + } + } +} + +// End of code generation (ixfun.cpp) diff --git a/RAT/ixfun.h b/RAT/ixfun.h new file mode 100644 index 00000000..3fc94c07 --- /dev/null +++ b/RAT/ixfun.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// ixfun.h +// +// Code generation for function 'ixfun' +// +#ifndef IXFUN_H +#define IXFUN_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void expand_max(const ::coder::array &a, const ::coder::array< + real_T, 1U> &b, ::coder::array &c); + } + } +} + +#endif + +// End of code generation (ixfun.h) diff --git a/RAT/kmeans.cpp b/RAT/kmeans.cpp new file mode 100644 index 00000000..a92081f5 --- /dev/null +++ b/RAT/kmeans.cpp @@ -0,0 +1,316 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// kmeans.cpp +// +// Code generation for function 'kmeans' +// + +// Include files +#include "kmeans.h" +#include "find.h" +#include "mean.h" +#include "minOrMax.h" +#include "norm.h" +#include "rand.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static real_T binary_expand_op(const ::coder::array &in1, int32_T + in2, const ::coder::array &in3, int32_T in4); + static void binary_expand_op(::coder::array &in1, const int32_T + in2_data[], real_T in3, const ::coder::array &in4, int32_T in5); + static real_T binary_expand_op(const ::coder::array &in1, int32_T + in2, const ::coder::array &in3); +} + +// Function Definitions +namespace RAT +{ + static real_T binary_expand_op(const ::coder::array &in1, int32_T + in2, const ::coder::array &in3, int32_T in4) + { + ::coder::array b_in1; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in3.size(1) == 1) { + i = in1.size(1); + } else { + i = in3.size(1); + } + + b_in1.set_size(1, i); + stride_0_1 = (in1.size(1) != 1); + stride_1_1 = (in3.size(1) != 1); + if (in3.size(1) == 1) { + loop_ub = in1.size(1); + } else { + loop_ub = in3.size(1); + } + + for (i = 0; i < loop_ub; i++) { + b_in1[i] = in1[in2 + in1.size(0) * (i * stride_0_1)] - in3[in4 + 2 * (i * + stride_1_1)]; + } + + return coder::c_norm(b_in1); + } + + static void binary_expand_op(::coder::array &in1, const int32_T + in2_data[], real_T in3, const ::coder::array &in4, int32_T in5) + { + ::coder::array b_in1; + int32_T i; + int32_T in2_tmp; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + in2_tmp = in2_data[static_cast(in3) - 1]; + if (in4.size(1) == 1) { + i = in1.size(1); + } else { + i = in4.size(1); + } + + b_in1.set_size(1, i); + stride_0_1 = (in1.size(1) != 1); + stride_1_1 = (in4.size(1) != 1); + if (in4.size(1) == 1) { + loop_ub = in1.size(1); + } else { + loop_ub = in4.size(1); + } + + for (i = 0; i < loop_ub; i++) { + b_in1[i] = in1[(in2_tmp + 2 * (i * stride_0_1)) - 1] + in4[in5 + in4.size + (0) * (i * stride_1_1)]; + } + + loop_ub = b_in1.size(1); + for (i = 0; i < loop_ub; i++) { + in1[(in2_tmp + 2 * i) - 1] = b_in1[i]; + } + } + + static real_T binary_expand_op(const ::coder::array &in1, int32_T + in2, const ::coder::array &in3) + { + ::coder::array b_in1; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in3.size(1) == 1) { + i = in1.size(1); + } else { + i = in3.size(1); + } + + b_in1.set_size(1, i); + stride_0_1 = (in1.size(1) != 1); + stride_1_1 = (in3.size(1) != 1); + if (in3.size(1) == 1) { + loop_ub = in1.size(1); + } else { + loop_ub = in3.size(1); + } + + for (i = 0; i < loop_ub; i++) { + b_in1[i] = in1[in2 + 2 * (i * stride_0_1)] - in3[in2 + 2 * (i * stride_1_1)]; + } + + return coder::c_norm(b_in1); + } + + void kmeans(const ::coder::array &X, ::coder::array + &means, real_T Nmeans[2]) + { + ::coder::array b_X; + ::coder::array b_class; + ::coder::array c_X; + real_T cmp; + int32_T index_min_data[2]; + int32_T b_loop_ub; + int32_T i; + int32_T i1; + int32_T index_min_tmp; + int32_T loop_ub; + + // Finds K prototypes representing the samples in data matrix X, + // where each row of X represents a sample. + // Iterates until maximum norm difference between + // prototypes found in successive iterations is < maxerr + // + // This script uses square Euclidean distance, + // but can be easily modified to use other metrics + // + // Output arguments + // means: matrix with each row a cluster prototype + // Nmeans: Number of samples in each cluster + // membership: Assigned class for each sample + // + // Example: + // X = [randn(100,1) ; 2+randn(100,1)]; + // K = 2; + // [means Nmeans] = kmeans(X,K,0) + // + // Mauricio Martinez-Garcia, 2003, 2007, 2016 + Nmeans[0] = 0.0; + Nmeans[1] = 0.0; + + // coder.varsize('Nclass'); + // coder.varsize('class'); + means.set_size(2, X.size(1)); + loop_ub = X.size(1); + for (i = 0; i < loop_ub; i++) { + means[2 * i] = 0.0; + means[2 * i + 1] = 0.0; + } + + // Initial prototype assignment (arbitrary) + loop_ub = X.size(1); + for (i = 0; i < loop_ub; i++) { + means[2 * i] = X[X.size(0) * i]; + } + + if (X.size(0) < 2) { + i = 0; + i1 = 0; + } else { + i = 1; + i1 = X.size(0); + } + + loop_ub = i1 - i; + b_X.set_size(loop_ub, X.size(1)); + b_loop_ub = X.size(1); + for (i1 = 0; i1 < b_loop_ub; i1++) { + for (index_min_tmp = 0; index_min_tmp < loop_ub; index_min_tmp++) { + b_X[index_min_tmp + b_X.size(0) * i1] = X[(i + index_min_tmp) + X.size(0) + * i1]; + } + } + + coder::mean(b_X, c_X); + loop_ub = c_X.size(1); + for (i = 0; i < loop_ub; i++) { + means[2 * i + 1] = c_X[i]; + } + + loop_ub = X.size(1); + i = X.size(0); + cmp = 1.0; + while (cmp > 0.0) { + // Sums (class) and data counters (Nclass) initialization + b_class.set_size(2, X.size(1)); + for (i1 = 0; i1 < loop_ub; i1++) { + b_class[2 * i1] = 0.0; + b_class[2 * i1 + 1] = 0.0; + } + + Nmeans[0] = 0.0; + Nmeans[1] = 0.0; + + // Groups each elements to the nearest prototype + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T dist[2]; + real_T a; + b_loop_ub = X.size(1); + for (int32_T j{0}; j < 2; j++) { + // Euclidean distance from data to each prototype + if (X.size(1) == means.size(1)) { + c_X.set_size(1, X.size(1)); + for (i1 = 0; i1 < b_loop_ub; i1++) { + c_X[i1] = X[b_i + X.size(0) * i1] - means[j + 2 * i1]; + } + + a = coder::c_norm(c_X); + } else { + a = binary_expand_op(X, b_i, means, j); + } + + dist[j] = a * a; + } + + int32_T index_min_size[2]; + boolean_T b_dist[2]; + + // Find indices of minimum distance + a = coder::internal::minimum(dist); + b_dist[0] = !(dist[0] - a != 0.0); + b_dist[1] = !(dist[1] - a != 0.0); + coder::b_eml_find(b_dist, index_min_data, index_min_size); + + // If there are multiple min distances, decide randomly + a = static_cast(index_min_size[1]) * coder::b_rand(); + a = std::ceil(a); + b_loop_ub = b_class.size(1); + if (b_class.size(1) == X.size(1)) { + index_min_tmp = index_min_data[static_cast(a) - 1]; + c_X.set_size(1, b_class.size(1)); + for (i1 = 0; i1 < b_loop_ub; i1++) { + c_X[i1] = b_class[(index_min_tmp + 2 * i1) - 1] + X[b_i + X.size(0) * + i1]; + } + + b_loop_ub = c_X.size(1); + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_class[(index_min_tmp + 2 * i1) - 1] = c_X[i1]; + } + } else { + binary_expand_op(b_class, index_min_data, a, X, b_i); + } + + index_min_tmp = index_min_data[static_cast(a) - 1] - 1; + Nmeans[index_min_tmp]++; + } + + for (int32_T b_i{0}; b_i < 2; b_i++) { + b_loop_ub = b_class.size(1); + c_X.set_size(1, b_class.size(1)); + for (i1 = 0; i1 < b_loop_ub; i1++) { + c_X[i1] = b_class[b_i + 2 * i1] / Nmeans[b_i]; + } + + b_loop_ub = c_X.size(1); + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_class[b_i + 2 * i1] = c_X[i1]; + } + } + + // Compare results with previous iteration + cmp = 0.0; + b_loop_ub = b_class.size(1); + for (int32_T b_i{0}; b_i < 2; b_i++) { + if (b_class.size(1) == means.size(1)) { + c_X.set_size(1, b_class.size(1)); + for (i1 = 0; i1 < b_loop_ub; i1++) { + c_X[i1] = b_class[b_i + 2 * i1] - means[b_i + 2 * i1]; + } + + cmp = coder::c_norm(c_X); + } else { + cmp = binary_expand_op(b_class, b_i, means); + } + } + + // Prototype update + means.set_size(2, b_class.size(1)); + b_loop_ub = b_class.size(1); + for (i1 = 0; i1 < b_loop_ub; i1++) { + means[2 * i1] = b_class[2 * i1]; + means[2 * i1 + 1] = b_class[2 * i1 + 1]; + } + } + } +} + +// End of code generation (kmeans.cpp) diff --git a/RAT/kmeans.h b/RAT/kmeans.h new file mode 100644 index 00000000..6ea19ffb --- /dev/null +++ b/RAT/kmeans.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// kmeans.h +// +// Code generation for function 'kmeans' +// +#ifndef KMEANS_H +#define KMEANS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void kmeans(const ::coder::array &X, ::coder::array + &means, real_T Nmeans[2]); +} + +#endif + +// End of code generation (kmeans.h) diff --git a/RAT/leftWin.cpp b/RAT/leftWin.cpp new file mode 100644 index 00000000..221543e4 --- /dev/null +++ b/RAT/leftWin.cpp @@ -0,0 +1,51 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// leftWin.cpp +// +// Code generation for function 'leftWin' +// + +// Include files +#include "leftWin.h" +#include "rt_nonfinite.h" + +// Function Definitions +namespace RAT +{ + real_T leftWin(real_T S_x_I_no, real_T S_x_FVr_oa, real_T S_y_FVr_oa) + { + real_T I_z; + + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // Function: I_z = left_win(S_x,S_y) + // Author: Rainer Storn + // Description: left_win(S_x,S_y) takes structures S_x and S_y as an argument. + // The function returns 1 if the left structure of the input structures, + // i.e. S_x, wins. If the right structure, S_y, wins, the result is 0. + // Parameters: S_x.I_nc (I) Number of constraints (must be the same for x and y). + // S_x.I_no (I) Number of objectives (must be the same for x and y). + // S_x.FVr_ca (I) Constraint array containing the constraint violation values. + // If the value is 0 the constraint is met. If it is > 0 it is + // still violated. + // S_x.FVr_oa (I) Objective array containing cost values which are supposed to be + // minimized. + // Return value: I_z (O) If S_x wins over S_y then I_z=1 else I_z=0. + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + I_z = 1.0; + + // start with I_z=1 + // ----deal with the constraints first. If constraints are not met------ + // ----S_x can't win.--------------------------------------------------- + if ((S_x_I_no > 0.0) && (S_x_FVr_oa > S_y_FVr_oa)) { + // if just one objective of S_x is less + I_z = 0.0; + } + + return I_z; + } +} + +// End of code generation (leftWin.cpp) diff --git a/RAT/leftWin.h b/RAT/leftWin.h new file mode 100644 index 00000000..6f63e5a7 --- /dev/null +++ b/RAT/leftWin.h @@ -0,0 +1,26 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// leftWin.h +// +// Code generation for function 'leftWin' +// +#ifndef LEFTWIN_H +#define LEFTWIN_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + real_T leftWin(real_T S_x_I_no, real_T S_x_FVr_oa, real_T S_y_FVr_oa); +} + +#endif + +// End of code generation (leftWin.h) diff --git a/RAT/libManager.h b/RAT/libManager.h deleted file mode 100644 index 3c3afcb7..00000000 --- a/RAT/libManager.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef WRAPPER_H -#define WRAPPER_H - - -#include -#include -#include -#include -#include -#include -#include "dylib.hpp" // dylib.hpp is a header file that contains the dylib class that extracts a function from dll - -class Library -{ - public: - std::string functionName; - std::string libName; - - Library(void){}; - ~Library(void){}; - - void loadInfo(std::string libName, std::string functionName) - { - this->libName = libName; - this->functionName = functionName; - }; - - // coder.ref(params),coder.ref(nba),coder.ref(nbs),numberOfContrasts,coder.ref(output),coder.ref(subrough)); - void loadRunner(double* params,double *bulk_in,double *bulk_out,int contrast,double *tempOutput,double *roughness,double *nLayers,char* libName,char* functionName) - - { - // create an instance of dylib - dylib library; - - // load the library with libName - library = dylib (libName,dylib::extension); - - // store the function pointer in func - auto func = library.get_function(functionName); - - // pass the arguments to the function - func(params, bulk_in, bulk_out, contrast, tempOutput, roughness, nLayers); - - }; -}; - -#endif - diff --git a/RAT/log2.cpp b/RAT/log2.cpp index 6a12a4a1..9eff7e8f 100644 --- a/RAT/log2.cpp +++ b/RAT/log2.cpp @@ -11,6 +11,7 @@ // Include files #include "log2.h" #include "rt_nonfinite.h" +#include "coder_array.h" #include // Function Definitions @@ -18,6 +19,20 @@ namespace RAT { namespace coder { + void b_log2(const ::coder::array &x, ::coder::array + &f, ::coder::array &e) + { + f.set_size(x.size(0)); + e.set_size(x.size(0)); + if (x.size(0) != 0) { + int32_T i; + i = x.size(0); + for (int32_T k{0}; k < i; k++) { + b_log2(x[k], &f[k], &e[k]); + } + } + } + void b_log2(real_T x, real_T *f, real_T *e) { int32_T eint; diff --git a/RAT/log2.h b/RAT/log2.h index 4c2d136c..3198b204 100644 --- a/RAT/log2.h +++ b/RAT/log2.h @@ -12,6 +12,7 @@ // Include files #include "rtwtypes.h" +#include "coder_array.h" #include #include @@ -20,6 +21,8 @@ namespace RAT { namespace coder { + void b_log2(const ::coder::array &x, ::coder::array + &f, ::coder::array &e); void b_log2(real_T x, real_T *f, real_T *e); } } diff --git a/RAT/logPlus.cpp b/RAT/logPlus.cpp new file mode 100644 index 00000000..2ba15119 --- /dev/null +++ b/RAT/logPlus.cpp @@ -0,0 +1,43 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// logPlus.cpp +// +// Code generation for function 'logPlus' +// + +// Include files +#include "logPlus.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + real_T logPlus(real_T logx, real_T logy) + { + real_T logz; + + // + // logz = logPlus(logx, logy) + // + // Given logx and logy, this function returns logz=log(x+y). + // It avoids problems of dynamic range when the + // exponentiated values of x or y are very large or small. + // + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + if (std::isinf(logx) && std::isinf(logy)) { + logz = rtMinusInf; + } else if (logx > logy) { + logz = logx + std::log(std::exp(logy - logx) + 1.0); + } else { + logz = logy + std::log(std::exp(logx - logy) + 1.0); + } + + return logz; + } +} + +// End of code generation (logPlus.cpp) diff --git a/RAT/logPlus.h b/RAT/logPlus.h new file mode 100644 index 00000000..532712f8 --- /dev/null +++ b/RAT/logPlus.h @@ -0,0 +1,26 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// logPlus.h +// +// Code generation for function 'logPlus' +// +#ifndef LOGPLUS_H +#define LOGPLUS_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + real_T logPlus(real_T logx, real_T logy); +} + +#endif + +// End of code generation (logPlus.h) diff --git a/RAT/lower.cpp b/RAT/lower.cpp index 00cd66ca..d1ccaaa3 100644 --- a/RAT/lower.cpp +++ b/RAT/lower.cpp @@ -10,7 +10,7 @@ // Include files #include "lower.h" -#include "reflectivityCalculation_data.h" +#include "RATMain_data.h" #include "rt_nonfinite.h" // Function Definitions @@ -26,7 +26,7 @@ namespace RAT y_size[1] = x_size[1]; i = x_size[1]; for (int32_T k{0}; k < i; k++) { - y_data[k] = cv[static_cast(x_data[k]) & 127]; + y_data[k] = cv1[static_cast(x_data[k]) & 127]; } } } diff --git a/RAT/lusolve.cpp b/RAT/lusolve.cpp new file mode 100644 index 00000000..1879f52d --- /dev/null +++ b/RAT/lusolve.cpp @@ -0,0 +1,74 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// lusolve.cpp +// +// Code generation for function 'lusolve' +// + +// Include files +#include "lusolve.h" +#include "rt_nonfinite.h" +#include "xgetrf.h" +#include "xtrsm.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + void lusolve(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &X) + { + ::coder::array b_A; + ::coder::array ipiv; + int32_T b_i; + int32_T i; + int32_T i1; + int32_T info; + int32_T nb; + b_A.set_size(A.size(0), A.size(1)); + info = A.size(1); + for (i = 0; i < info; i++) { + b_i = A.size(0); + for (i1 = 0; i1 < b_i; i1++) { + b_A[i1 + b_A.size(0) * i] = A[i1 + A.size(0) * i]; + } + } + + lapack::xgetrf(A.size(1), A.size(1), b_A, A.size(1), ipiv, &info); + nb = B.size(0); + X.set_size(B.size(0), B.size(1)); + info = B.size(1); + for (i = 0; i < info; i++) { + b_i = B.size(0); + for (i1 = 0; i1 < b_i; i1++) { + X[X.size(0) * i] = B[B.size(0) * i]; + } + } + + blas::xtrsm(B.size(0), A.size(1), b_A, A.size(1), X, B.size(0)); + blas::b_xtrsm(B.size(0), A.size(1), b_A, A.size(1), X, B.size(0)); + i = A.size(1) - 1; + for (info = i; info >= 1; info--) { + i1 = ipiv[info - 1]; + if (i1 != info) { + for (b_i = 0; b_i < nb; b_i++) { + real_T temp; + temp = X[X.size(0) * (info - 1)]; + X[X.size(0) * (info - 1)] = X[X.size(0) * (i1 - 1)]; + X[X.size(0) * (i1 - 1)] = temp; + } + } + } + } + } + } +} + +// End of code generation (lusolve.cpp) diff --git a/RAT/lusolve.h b/RAT/lusolve.h new file mode 100644 index 00000000..8c3118a3 --- /dev/null +++ b/RAT/lusolve.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// lusolve.h +// +// Code generation for function 'lusolve' +// +#ifndef LUSOLVE_H +#define LUSOLVE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void lusolve(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &X); + } + } +} + +#endif + +// End of code generation (lusolve.h) diff --git a/RAT/makeCell.cpp b/RAT/makeCell.cpp new file mode 100644 index 00000000..9d17458c --- /dev/null +++ b/RAT/makeCell.cpp @@ -0,0 +1,194 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// makeCell.cpp +// +// Code generation for function 'makeCell' +// + +// Include files +#include "makeCell.h" +#include "RATMain_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void b_makeCell(real_T m, const real_T vals_data[], ::coder::array &x) + { + int32_T i; + + // Creates a m by n cell array and initialise each cell with given + // value + // + // array = makeCell(5, 2, [1, 1]) + i = static_cast(m); + x.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T d; + real_T d1; + real_T d2; + d = vals_data[0]; + d1 = vals_data[1]; + d2 = vals_data[2]; + for (int32_T j{0}; j < 2; j++) { + x[b_i + x.size(0) * j].f1.set_size(1, 3); + x[b_i + x.size(0) * j].f1[0] = d; + x[b_i + x.size(0) * j].f1[x[b_i + x.size(0) * j].f1.size(0)] = d1; + x[b_i + x.size(0) * j].f1[x[b_i + x.size(0) * j].f1.size(0) * 2] = d2; + } + } + } + + void makeCell(cell_wrap_8 x[50]) + { + // Creates a m by n cell array and initialise each cell with given + // value + // + // array = makeCell(5, 2, [1, 1]) + x[0].f1.set_size(1, 1); + x[0].f1[0] = 1.0; + x[1].f1.set_size(1, 1); + x[1].f1[0] = 1.0; + x[2].f1.set_size(1, 1); + x[2].f1[0] = 1.0; + x[3].f1.set_size(1, 1); + x[3].f1[0] = 1.0; + x[4].f1.set_size(1, 1); + x[4].f1[0] = 1.0; + x[5].f1.set_size(1, 1); + x[5].f1[0] = 1.0; + x[6].f1.set_size(1, 1); + x[6].f1[0] = 1.0; + x[7].f1.set_size(1, 1); + x[7].f1[0] = 1.0; + x[8].f1.set_size(1, 1); + x[8].f1[0] = 1.0; + x[9].f1.set_size(1, 1); + x[9].f1[0] = 1.0; + x[10].f1.set_size(1, 1); + x[10].f1[0] = 1.0; + x[11].f1.set_size(1, 1); + x[11].f1[0] = 1.0; + x[12].f1.set_size(1, 1); + x[12].f1[0] = 1.0; + x[13].f1.set_size(1, 1); + x[13].f1[0] = 1.0; + x[14].f1.set_size(1, 1); + x[14].f1[0] = 1.0; + x[15].f1.set_size(1, 1); + x[15].f1[0] = 1.0; + x[16].f1.set_size(1, 1); + x[16].f1[0] = 1.0; + x[17].f1.set_size(1, 1); + x[17].f1[0] = 1.0; + x[18].f1.set_size(1, 1); + x[18].f1[0] = 1.0; + x[19].f1.set_size(1, 1); + x[19].f1[0] = 1.0; + x[20].f1.set_size(1, 1); + x[20].f1[0] = 1.0; + x[21].f1.set_size(1, 1); + x[21].f1[0] = 1.0; + x[22].f1.set_size(1, 1); + x[22].f1[0] = 1.0; + x[23].f1.set_size(1, 1); + x[23].f1[0] = 1.0; + x[24].f1.set_size(1, 1); + x[24].f1[0] = 1.0; + x[25].f1.set_size(1, 1); + x[25].f1[0] = 1.0; + x[26].f1.set_size(1, 1); + x[26].f1[0] = 1.0; + x[27].f1.set_size(1, 1); + x[27].f1[0] = 1.0; + x[28].f1.set_size(1, 1); + x[28].f1[0] = 1.0; + x[29].f1.set_size(1, 1); + x[29].f1[0] = 1.0; + x[30].f1.set_size(1, 1); + x[30].f1[0] = 1.0; + x[31].f1.set_size(1, 1); + x[31].f1[0] = 1.0; + x[32].f1.set_size(1, 1); + x[32].f1[0] = 1.0; + x[33].f1.set_size(1, 1); + x[33].f1[0] = 1.0; + x[34].f1.set_size(1, 1); + x[34].f1[0] = 1.0; + x[35].f1.set_size(1, 1); + x[35].f1[0] = 1.0; + x[36].f1.set_size(1, 1); + x[36].f1[0] = 1.0; + x[37].f1.set_size(1, 1); + x[37].f1[0] = 1.0; + x[38].f1.set_size(1, 1); + x[38].f1[0] = 1.0; + x[39].f1.set_size(1, 1); + x[39].f1[0] = 1.0; + x[40].f1.set_size(1, 1); + x[40].f1[0] = 1.0; + x[41].f1.set_size(1, 1); + x[41].f1[0] = 1.0; + x[42].f1.set_size(1, 1); + x[42].f1[0] = 1.0; + x[43].f1.set_size(1, 1); + x[43].f1[0] = 1.0; + x[44].f1.set_size(1, 1); + x[44].f1[0] = 1.0; + x[45].f1.set_size(1, 1); + x[45].f1[0] = 1.0; + x[46].f1.set_size(1, 1); + x[46].f1[0] = 1.0; + x[47].f1.set_size(1, 1); + x[47].f1[0] = 1.0; + x[48].f1.set_size(1, 1); + x[48].f1[0] = 1.0; + x[49].f1.set_size(1, 1); + x[49].f1[0] = 1.0; + } + + void makeCell(real_T m, const real_T vals_data[], ::coder::array &x) + { + int32_T i; + + // Creates a m by n cell array and initialise each cell with given + // value + // + // array = makeCell(5, 2, [1, 1]) + i = static_cast(m); + x.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + x[b_i].f1.set_size(1, 3); + x[b_i].f1[0] = vals_data[0]; + x[b_i].f1[1] = vals_data[1]; + x[b_i].f1[2] = vals_data[2]; + } + } + + void makeCell(real_T m, const real_T vals_data[], ::coder::array &x) + { + int32_T i; + + // Creates a m by n cell array and initialise each cell with given + // value + // + // array = makeCell(5, 2, [1, 1]) + i = static_cast(m); + x.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + x[b_i].f1.set_size(1, 3); + x[b_i].f1[0] = vals_data[0]; + x[b_i].f1[x[b_i].f1.size(0)] = vals_data[1]; + x[b_i].f1[x[b_i].f1.size(0) * 2] = vals_data[2]; + } + } +} + +// End of code generation (makeCell.cpp) diff --git a/RAT/makeCell.h b/RAT/makeCell.h new file mode 100644 index 00000000..0ad4e9b6 --- /dev/null +++ b/RAT/makeCell.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// makeCell.h +// +// Code generation for function 'makeCell' +// +#ifndef MAKECELL_H +#define MAKECELL_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void b_makeCell(real_T m, const real_T vals_data[], ::coder::array &x); + void makeCell(cell_wrap_8 x[50]); + void makeCell(real_T m, const real_T vals_data[], ::coder::array &x); + void makeCell(real_T m, const real_T vals_data[], ::coder::array &x); +} + +#endif + +// End of code generation (makeCell.h) diff --git a/RAT/makeD.cpp b/RAT/makeD.cpp new file mode 100644 index 00000000..af7dab86 --- /dev/null +++ b/RAT/makeD.cpp @@ -0,0 +1,111 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// makeD.cpp +// +// Code generation for function 'makeD' +// + +// Include files +#include "makeD.h" +#include "RATMain_data.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void makeD(const ::coder::array &alpha1, const ::coder::array< + creal_T, 1U> &beta1, ::coder::array &D) + { + int32_T i; + int32_T k; + D.set_size(alpha1.size(0), alpha1.size(0)); + k = alpha1.size(0); + for (i = 0; i < k; i++) { + int32_T loop_ub; + loop_ub = alpha1.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + D[i1 + D.size(0) * i].re = 0.0; + D[i1 + D.size(0) * i].im = 0.0; + } + } + + i = alpha1.size(0); + for (k = 0; k < i; k++) { + real_T ai; + real_T ar; + real_T bi; + real_T br; + ar = alpha1[k].re; + ai = alpha1[k].im; + br = beta1[k].re; + bi = beta1[k].im; + if (bi == 0.0) { + if (ai == 0.0) { + D[k + D.size(0) * k].re = ar / br; + D[k + D.size(0) * k].im = 0.0; + } else if (ar == 0.0) { + D[k + D.size(0) * k].re = 0.0; + D[k + D.size(0) * k].im = ai / br; + } else { + D[k + D.size(0) * k].re = ar / br; + D[k + D.size(0) * k].im = ai / br; + } + } else if (br == 0.0) { + if (ar == 0.0) { + D[k + D.size(0) * k].re = ai / bi; + D[k + D.size(0) * k].im = 0.0; + } else if (ai == 0.0) { + D[k + D.size(0) * k].re = 0.0; + D[k + D.size(0) * k].im = -(ar / bi); + } else { + D[k + D.size(0) * k].re = ai / bi; + D[k + D.size(0) * k].im = -(ar / bi); + } + } else { + real_T bim; + real_T brm; + brm = std::abs(br); + bim = std::abs(bi); + if (brm > bim) { + real_T s; + s = bi / br; + bim = br + s * bi; + D[k + D.size(0) * k].re = (ar + s * ai) / bim; + D[k + D.size(0) * k].im = (ai - s * ar) / bim; + } else if (bim == brm) { + real_T s; + if (br > 0.0) { + s = 0.5; + } else { + s = -0.5; + } + + if (bi > 0.0) { + bim = 0.5; + } else { + bim = -0.5; + } + + D[k + D.size(0) * k].re = (ar * s + ai * bim) / brm; + D[k + D.size(0) * k].im = (ai * s - ar * bim) / brm; + } else { + real_T s; + s = br / bi; + bim = bi + s * br; + D[k + D.size(0) * k].re = (s * ar + ai) / bim; + D[k + D.size(0) * k].im = (s * ai - ar) / bim; + } + } + } + } + } +} + +// End of code generation (makeD.cpp) diff --git a/RAT/makeD.h b/RAT/makeD.h new file mode 100644 index 00000000..e3b2e8e8 --- /dev/null +++ b/RAT/makeD.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// makeD.h +// +// Code generation for function 'makeD' +// +#ifndef MAKED_H +#define MAKED_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void makeD(const ::coder::array &alpha1, const ::coder::array< + creal_T, 1U> &beta1, ::coder::array &D); + } +} + +#endif + +// End of code generation (makeD.h) diff --git a/RAT/makeEmptyBayesResultsStruct.cpp b/RAT/makeEmptyBayesResultsStruct.cpp new file mode 100644 index 00000000..1632c55a --- /dev/null +++ b/RAT/makeEmptyBayesResultsStruct.cpp @@ -0,0 +1,646 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// makeEmptyBayesResultsStruct.cpp +// +// Code generation for function 'makeEmptyBayesResultsStruct' +// + +// Include files +#include "makeEmptyBayesResultsStruct.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "rt_nonfinite.h" +#include "structConstructorHelper.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Declarations +namespace RAT +{ + static void cast(const ::coder::array &t3_outlier, const + struct14_T *t3_DREAMPar, const struct15_T t3_Meas_info, const + ::coder::array &t3_AR, const ::coder::array< + real_T, 2U> &t3_R_stat, const ::coder::array + &t3_CR, struct13_T *r); + static void cast(const real_T t1_par95_data[], const int32_T t1_par95_size[2], + const real_T t1_par65_data[], const int32_T t1_par65_size[2], + const real_T t1_mean_data[], const int32_T t1_mean_size[2], :: + coder::array &t2_par95, ::coder::array + &t2_par65, ::coder::array &t2_mean); +} + +// Function Definitions +namespace RAT +{ + static void cast(const ::coder::array &t3_outlier, const + struct14_T *t3_DREAMPar, const struct15_T t3_Meas_info, const + ::coder::array &t3_AR, const ::coder::array< + real_T, 2U> &t3_R_stat, const ::coder::array + &t3_CR, struct13_T *r) + { + int32_T b_loop_ub; + int32_T loop_ub; + r->outlier.size[0] = t3_outlier.size(0); + r->outlier.size[1] = t3_outlier.size(1); + loop_ub = t3_outlier.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = t3_outlier.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r->outlier.data[i1 + r->outlier.size[0] * i] = t3_outlier[i1 + + t3_outlier.size(0) * i]; + } + } + + r->RunTime = 100.0; + r->DREAMPar = *t3_DREAMPar; + r->Meas_info = t3_Meas_info; + r->iteration = 0.0; + r->iloc = 0.0; + r->fx = 0.0; + r->AR.size[0] = t3_AR.size(0); + r->AR.size[1] = t3_AR.size(1); + loop_ub = t3_AR.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = t3_AR.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r->AR.data[i1 + r->AR.size[0] * i] = t3_AR[i1 + t3_AR.size(0) * i]; + } + } + + r->R_stat.set_size(t3_R_stat.size(0), t3_R_stat.size(1)); + loop_ub = t3_R_stat.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = t3_R_stat.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r->R_stat[i1 + r->R_stat.size(0) * i] = t3_R_stat[i1 + t3_R_stat.size(0) + * i]; + } + } + + r->CR.set_size(t3_CR.size(0), t3_CR.size(1)); + loop_ub = t3_CR.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = t3_CR.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r->CR[i1 + r->CR.size(0) * i] = t3_CR[i1 + t3_CR.size(0) * i]; + } + } + } + + static void cast(const real_T t1_par95_data[], const int32_T t1_par95_size[2], + const real_T t1_par65_data[], const int32_T t1_par65_size[2], + const real_T t1_mean_data[], const int32_T t1_mean_size[2], :: + coder::array &t2_par95, ::coder::array + &t2_par65, ::coder::array &t2_mean) + { + int32_T loop_ub; + t2_par95.set_size(2, t1_par95_size[1]); + loop_ub = t1_par95_size[1]; + for (int32_T i{0}; i < loop_ub; i++) { + t2_par95[2 * i] = t1_par95_data[2 * i]; + t2_par95[2 * i + 1] = t1_par95_data[2 * i + 1]; + } + + t2_par65.set_size(2, t1_par65_size[1]); + loop_ub = t1_par65_size[1]; + for (int32_T i{0}; i < loop_ub; i++) { + t2_par65[2 * i] = t1_par65_data[2 * i]; + t2_par65[2 * i + 1] = t1_par65_data[2 * i + 1]; + } + + t2_mean.set_size(1, t1_mean_size[1]); + loop_ub = t1_mean_size[1]; + for (int32_T i{0}; i < loop_ub; i++) { + t2_mean[i] = t1_mean_data[i]; + } + } + + void b_makeEmptyBayesResultsStruct(real_T nContrasts, boolean_T isDomains, :: + coder::array &bayesResults_bestFitsMean_ref, ::coder::array< + cell_wrap_8, 2U> &bayesResults_bestFitsMean_sld, real_T + *bayesResults_bestFitsMean_chi, ::coder::array + &bayesResults_bestFitsMean_data, ::coder::array + &bayesResults_predlims_refPredInts, ::coder::array + &bayesResults_predlims_sldPredInts, ::coder::array + &bayesResults_predlims_refXdata, ::coder::array + &bayesResults_predlims_sldXdata, real_T + bayesResults_predlims_sampleChi_data[], int32_T + *bayesResults_predlims_sampleChi_size, ::coder::array + &bayesResults_parConfInts_par95, ::coder::array + &bayesResults_parConfInts_par65, ::coder::array + &bayesResults_parConfInts_mean, ::coder::array + &bayesResults_bestPars, c_struct_T *bayesResults_bayesRes, ::coder::array< + real_T, 2U> &bayesResults_chain) + { + ::coder::array b_f1; + ::coder::array g_f1; + ::coder::array c_f1; + ::coder::array d_f1; + ::coder::array e_f1; + ::coder::array f1; + ::coder::array f_f1; + ::coder::array t6_AR; + ::coder::array t6_CR; + ::coder::array t6_R_stat; + ::coder::array t6_outlier; + ::coder::array h_f1; + cell_wrap_15 r; + cell_wrap_15 r2; + cell_wrap_15 r3; + cell_wrap_17 r4; + cell_wrap_9 r1; + struct14_T expl_temp; + struct15_T b_expl_temp; + real_T t7_par65_data[2000]; + real_T t7_par95_data[2000]; + real_T t7_mean_data[1000]; + int32_T t7_mean_size[2]; + int32_T t7_par65_size[2]; + int32_T t7_par95_size[2]; + int32_T i; + + // A function to make an empty container to hold the results of bayes + // calculations. The struct has the following format: + // + // nPar = number of fitted parameters + // nContrasts = number of contrasts + // + // bayesResults = + // + // struct with fields: + // + // bestFitsMean: [1×1 struct] + // predlims: [1×1 struct] + // parConfInts: [1×1 struct] + // bestPars: [1xnPars double] + // bayesRes: [1×1 struct] + // chain: [1000000xnPars double] + // ----------------------------------------------------------- + // Make the individual structs.... + // (1) bayesResults.bestFitsMean + i = static_cast(nContrasts); + f1.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + f1[b_i].f1.set_size(1, 3); + f1[b_i].f1[0] = 1.0; + f1[b_i].f1[f1[b_i].f1.size(0)] = 1.0; + f1[b_i].f1[f1[b_i].f1.size(0) * 2] = 1.0; + } + + if (isDomains) { + b_f1.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + b_f1[b_i].f1.set_size(2, 2); + b_f1[b_i + b_f1.size(0)].f1.set_size(2, 2); + b_f1[b_i].f1[0] = 1.0; + b_f1[b_i + b_f1.size(0)].f1[0] = 1.0; + b_f1[b_i].f1[1] = 1.0; + b_f1[b_i + b_f1.size(0)].f1[1] = 1.0; + b_f1[b_i].f1[b_f1[b_i].f1.size(0)] = 1.0; + b_f1[b_i + b_f1.size(0)].f1[b_f1[b_i + b_f1.size(0)].f1.size(0)] = 1.0; + b_f1[b_i].f1[b_f1[b_i].f1.size(0) + 1] = 1.0; + b_f1[b_i + b_f1.size(0)].f1[b_f1[b_i + b_f1.size(0)].f1.size(0) + 1] = + 1.0; + } + } else { + b_f1.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + b_f1[b_i].f1.set_size(1, 2); + b_f1[b_i].f1[0] = 1.0; + b_f1[b_i].f1[b_f1[b_i].f1.size(0)] = 1.0; + } + } + + c_f1.set_size(i); + + // -------------------------------------------------------------------- + // (2) bayesResults.predlims + d_f1.set_size(i); + e_f1.set_size(i); + f_f1.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + c_f1[b_i].f1.set_size(1, 3); + c_f1[b_i].f1[0] = 1.0; + c_f1[b_i].f1[c_f1[b_i].f1.size(0)] = 1.0; + c_f1[b_i].f1[c_f1[b_i].f1.size(0) * 2] = 1.0; + d_f1[b_i].f1.set_size(1, 3); + d_f1[b_i].f1[0] = 1.0; + d_f1[b_i].f1[d_f1[b_i].f1.size(0)] = 1.0; + d_f1[b_i].f1[d_f1[b_i].f1.size(0) * 2] = 1.0; + e_f1[b_i].f1.set_size(1, 3); + e_f1[b_i].f1[0] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0)] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0) * 2] = 1.0; + f_f1[b_i].f1.set_size(1, 3); + f_f1[b_i].f1[0] = 1.0; + f_f1[b_i].f1[f_f1[b_i].f1.size(0)] = 1.0; + f_f1[b_i].f1[f_f1[b_i].f1.size(0) * 2] = 1.0; + } + + if (isDomains) { + g_f1.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + g_f1[b_i].f1.set_size(2, 3); + g_f1[b_i + g_f1.size(0)].f1.set_size(2, 3); + for (int32_T i1{0}; i1 < 3; i1++) { + g_f1[b_i].f1[g_f1[b_i].f1.size(0) * i1] = 1.0; + g_f1[b_i + g_f1.size(0)].f1[g_f1[b_i + g_f1.size(0)].f1.size(0) * i1] = + 1.0; + g_f1[b_i].f1[g_f1[b_i].f1.size(0) * i1 + 1] = 1.0; + g_f1[b_i + g_f1.size(0)].f1[g_f1[b_i + g_f1.size(0)].f1.size(0) * i1 + + 1] = 1.0; + } + } + } else { + g_f1.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + g_f1[b_i].f1.set_size(1, 3); + g_f1[b_i].f1[0] = 1.0; + g_f1[b_i].f1[g_f1[b_i].f1.size(0)] = 1.0; + g_f1[b_i].f1[g_f1[b_i].f1.size(0) * 2] = 1.0; + } + } + + // ------------------------------------------------------------------ + // (3) bayesResults.parConfInts + t7_par95_size[0] = 2; + t7_par95_size[1] = 1; + t7_par65_size[0] = 2; + t7_par65_size[1] = 1; + t7_mean_size[0] = 1; + t7_mean_size[1] = 1; + t7_mean_data[0] = 0.0; + + // ------------------------------------------------------------------- + // (4) bayesResults.bestPars + // ------------------------------------------------------------------- + // (5) bayesResults.bayesRes + t6_outlier.set_size(1, 2); + t6_AR.set_size(1, 2); + t6_R_stat.set_size(1, 2); + t6_CR.set_size(1, 2); + + // Nested Sampler + t7_par95_data[0] = 0.0; + t7_par65_data[0] = 0.0; + t6_outlier[0] = 1.0; + t6_AR[0] = 0.0; + t6_R_stat[0] = 0.0; + t6_CR[0] = 0.0; + t7_par95_data[1] = 0.0; + t7_par65_data[1] = 0.0; + t6_outlier[t6_outlier.size(0)] = 1.0; + t6_AR[t6_AR.size(0)] = 0.0; + t6_R_stat[t6_R_stat.size(0)] = 0.0; + t6_CR[t6_CR.size(0)] = 0.0; + expl_temp.R.set_size(1, 1); + expl_temp.R[0] = 0.0; + expl_temp.save = false; + expl_temp.restart = false; + expl_temp.modout = false; + expl_temp.IO = false; + expl_temp.ABC = false; + expl_temp.epsilon = 0.025; + expl_temp.thinning = 1.0; + expl_temp.adaptPCR = false; + expl_temp.outlier[0] = 'i'; + expl_temp.outlier[1] = 'q'; + expl_temp.outlier[2] = 'r'; + expl_temp.zeta = 1.0E-12; + expl_temp.steps = 50.0; + expl_temp.delta = 3.0; + expl_temp.nCR = 3.0; + expl_temp.pUnitGamma = 0.2; + expl_temp.lambda = 0.5; + expl_temp.CPU = 1.0; + expl_temp.parallel = false; + expl_temp.T = 1000.0; + expl_temp.N = 10.0; + expl_temp.d = 17.0; + b_expl_temp.N = 0.0; + b_expl_temp.Y = 0.0; + cast(t6_outlier, &expl_temp, b_expl_temp, t6_AR, t6_R_stat, t6_CR, + &bayesResults_bayesRes->dreamOutput); + + // ------------------------------------------------------------------ + // (6) chain + // ------------------------------------------------------------------- + // Make the final structure... + r.f1 = f1; + r1.f1 = b_f1; + r2.f1 = c_f1; + coder::internal::structConstructorHelper(&r, &r1, &r2, + bayesResults_bestFitsMean_ref, bayesResults_bestFitsMean_sld, + bayesResults_bestFitsMean_chi, bayesResults_bestFitsMean_data); + h_f1.set_size(1); + h_f1[0] = 0.0; + r.f1 = d_f1; + r2.f1 = e_f1; + r3.f1 = f_f1; + r1.f1 = g_f1; + r4.f1 = h_f1; + coder::internal::structConstructorHelper(&r, &r2, &r3, &r1, &r4, + bayesResults_predlims_refPredInts, bayesResults_predlims_sldPredInts, + bayesResults_predlims_refXdata, bayesResults_predlims_sldXdata, + bayesResults_predlims_sampleChi_data, bayesResults_predlims_sampleChi_size); + cast(t7_par95_data, t7_par95_size, t7_par65_data, t7_par65_size, + t7_mean_data, t7_mean_size, bayesResults_parConfInts_par95, + bayesResults_parConfInts_par65, bayesResults_parConfInts_mean); + bayesResults_bestPars.set_size(1, 1); + bayesResults_bestPars[0] = 1.0; + bayesResults_bayesRes->allChains.set_size(1, 3, 1); + for (i = 0; i < 3; i++) { + bayesResults_bayesRes->allChains[bayesResults_bayesRes->allChains.size(0) * + i] = 1.0; + } + + bayesResults_bayesRes->nestOutput.LogZ = 0.0; + bayesResults_bayesRes->nestOutput.nestSamples.size[0] = 1; + bayesResults_bayesRes->nestOutput.nestSamples.size[1] = 2; + bayesResults_bayesRes->nestOutput.postSamples.size[0] = 1; + bayesResults_bayesRes->nestOutput.postSamples.size[1] = 2; + bayesResults_chain.set_size(1, 2); + bayesResults_bayesRes->nestOutput.nestSamples.data[0] = 0.0; + bayesResults_bayesRes->nestOutput.postSamples.data[0] = 0.0; + bayesResults_chain[0] = 0.0; + bayesResults_bayesRes->nestOutput.nestSamples.data[1] = 0.0; + bayesResults_bayesRes->nestOutput.postSamples.data[1] = 0.0; + bayesResults_chain[bayesResults_chain.size(0)] = 0.0; + } + + void makeEmptyBayesResultsStruct(real_T nContrasts, boolean_T isDomains, + real_T nChains, ::coder::array + &bayesResults_bestFitsMean_ref, ::coder::array + &bayesResults_bestFitsMean_sld, real_T *bayesResults_bestFitsMean_chi, :: + coder::array &bayesResults_bestFitsMean_data, ::coder:: + array &bayesResults_predlims_refPredInts, ::coder::array< + cell_wrap_8, 1U> &bayesResults_predlims_sldPredInts, ::coder::array< + cell_wrap_8, 1U> &bayesResults_predlims_refXdata, ::coder::array &bayesResults_predlims_sldXdata, real_T + bayesResults_predlims_sampleChi_data[], int32_T + *bayesResults_predlims_sampleChi_size, ::coder::array + &bayesResults_parConfInts_par95, ::coder::array + &bayesResults_parConfInts_par65, ::coder::array + &bayesResults_parConfInts_mean, ::coder::array + &bayesResults_bestPars, c_struct_T *bayesResults_bayesRes, ::coder::array< + real_T, 2U> &bayesResults_chain) + { + ::coder::array b_f1; + ::coder::array g_f1; + ::coder::array c_f1; + ::coder::array d_f1; + ::coder::array e_f1; + ::coder::array f1; + ::coder::array f_f1; + ::coder::array t16_AR; + ::coder::array t16_CR; + ::coder::array t16_R_stat; + ::coder::array t16_outlier; + ::coder::array h_f1; + ::coder::array t16_DREAMPar_R; + cell_wrap_15 r; + cell_wrap_15 r2; + cell_wrap_15 r3; + cell_wrap_17 r4; + cell_wrap_9 r1; + struct14_T expl_temp; + struct15_T b_expl_temp; + real_T t17_par65_data[2000]; + real_T t17_par95_data[2000]; + real_T t17_mean_data[1000]; + int32_T t17_mean_size[2]; + int32_T t17_par65_size[2]; + int32_T t17_par95_size[2]; + int32_T i; + int32_T loop_ub_tmp; + + // A function to make an empty container to hold the results of bayes + // calculations. The struct has the following format: + // + // nPar = number of fitted parameters + // nContrasts = number of contrasts + // + // bayesResults = + // + // struct with fields: + // + // bestFitsMean: [1×1 struct] + // predlims: [1×1 struct] + // parConfInts: [1×1 struct] + // bestPars: [1xnPars double] + // bayesRes: [1×1 struct] + // chain: [1000000xnPars double] + // ----------------------------------------------------------- + // Make the individual structs.... + // (1) bayesResults.bestFitsMean + i = static_cast(nContrasts); + f1.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + f1[b_i].f1.set_size(1, 3); + f1[b_i].f1[0] = 1.0; + f1[b_i].f1[f1[b_i].f1.size(0)] = 1.0; + f1[b_i].f1[f1[b_i].f1.size(0) * 2] = 1.0; + } + + if (isDomains) { + b_f1.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + b_f1[b_i].f1.set_size(2, 2); + b_f1[b_i + b_f1.size(0)].f1.set_size(2, 2); + b_f1[b_i].f1[0] = 1.0; + b_f1[b_i + b_f1.size(0)].f1[0] = 1.0; + b_f1[b_i].f1[1] = 1.0; + b_f1[b_i + b_f1.size(0)].f1[1] = 1.0; + b_f1[b_i].f1[b_f1[b_i].f1.size(0)] = 1.0; + b_f1[b_i + b_f1.size(0)].f1[b_f1[b_i + b_f1.size(0)].f1.size(0)] = 1.0; + b_f1[b_i].f1[b_f1[b_i].f1.size(0) + 1] = 1.0; + b_f1[b_i + b_f1.size(0)].f1[b_f1[b_i + b_f1.size(0)].f1.size(0) + 1] = + 1.0; + } + } else { + b_f1.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + b_f1[b_i].f1.set_size(1, 2); + b_f1[b_i].f1[0] = 1.0; + b_f1[b_i].f1[b_f1[b_i].f1.size(0)] = 1.0; + } + } + + c_f1.set_size(i); + + // -------------------------------------------------------------------- + // (2) bayesResults.predlims + d_f1.set_size(i); + e_f1.set_size(i); + f_f1.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + c_f1[b_i].f1.set_size(1, 3); + c_f1[b_i].f1[0] = 1.0; + c_f1[b_i].f1[c_f1[b_i].f1.size(0)] = 1.0; + c_f1[b_i].f1[c_f1[b_i].f1.size(0) * 2] = 1.0; + d_f1[b_i].f1.set_size(1, 3); + d_f1[b_i].f1[0] = 1.0; + d_f1[b_i].f1[d_f1[b_i].f1.size(0)] = 1.0; + d_f1[b_i].f1[d_f1[b_i].f1.size(0) * 2] = 1.0; + e_f1[b_i].f1.set_size(1, 3); + e_f1[b_i].f1[0] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0)] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0) * 2] = 1.0; + f_f1[b_i].f1.set_size(1, 3); + f_f1[b_i].f1[0] = 1.0; + f_f1[b_i].f1[f_f1[b_i].f1.size(0)] = 1.0; + f_f1[b_i].f1[f_f1[b_i].f1.size(0) * 2] = 1.0; + } + + if (isDomains) { + g_f1.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + g_f1[b_i].f1.set_size(2, 3); + g_f1[b_i + g_f1.size(0)].f1.set_size(2, 3); + for (int32_T i1{0}; i1 < 3; i1++) { + g_f1[b_i].f1[g_f1[b_i].f1.size(0) * i1] = 1.0; + g_f1[b_i + g_f1.size(0)].f1[g_f1[b_i + g_f1.size(0)].f1.size(0) * i1] = + 1.0; + g_f1[b_i].f1[g_f1[b_i].f1.size(0) * i1 + 1] = 1.0; + g_f1[b_i + g_f1.size(0)].f1[g_f1[b_i + g_f1.size(0)].f1.size(0) * i1 + + 1] = 1.0; + } + } + } else { + g_f1.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + g_f1[b_i].f1.set_size(1, 3); + g_f1[b_i].f1[0] = 1.0; + g_f1[b_i].f1[g_f1[b_i].f1.size(0)] = 1.0; + g_f1[b_i].f1[g_f1[b_i].f1.size(0) * 2] = 1.0; + } + } + + // ------------------------------------------------------------------ + // (3) bayesResults.parConfInts + t17_par95_size[0] = 2; + t17_par95_size[1] = 1; + t17_par65_size[0] = 2; + t17_par65_size[1] = 1; + t17_mean_size[0] = 1; + t17_mean_size[1] = 1; + t17_mean_data[0] = 0.0; + + // ------------------------------------------------------------------- + // (4) bayesResults.bestPars + // ------------------------------------------------------------------- + // (5) bayesResults.bayesRes + t16_outlier.set_size(1, 2); + t17_par95_data[0] = 0.0; + t17_par65_data[0] = 0.0; + t16_outlier[0] = 1.0; + t17_par95_data[1] = 0.0; + t17_par65_data[1] = 0.0; + t16_outlier[t16_outlier.size(0)] = 1.0; + loop_ub_tmp = static_cast(nChains); + t16_DREAMPar_R.set_size(loop_ub_tmp, loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + t16_DREAMPar_R[i1 + t16_DREAMPar_R.size(0) * i] = 0; + } + } + + t16_AR.set_size(1, 2); + t16_R_stat.set_size(1, 2); + t16_CR.set_size(1, 2); + + // Nested Sampler + t16_AR[0] = 0.0; + t16_R_stat[0] = 0.0; + t16_CR[0] = 0.0; + t16_AR[t16_AR.size(0)] = 0.0; + t16_R_stat[t16_R_stat.size(0)] = 0.0; + t16_CR[t16_CR.size(0)] = 0.0; + expl_temp.R.set_size(t16_DREAMPar_R.size(0), t16_DREAMPar_R.size(1)); + loop_ub_tmp = t16_DREAMPar_R.size(1); + for (i = 0; i < loop_ub_tmp; i++) { + int32_T loop_ub; + loop_ub = t16_DREAMPar_R.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + expl_temp.R[i1 + expl_temp.R.size(0) * i] = 0.0; + } + } + + expl_temp.save = false; + expl_temp.restart = false; + expl_temp.modout = false; + expl_temp.IO = false; + expl_temp.ABC = false; + expl_temp.epsilon = 0.025; + expl_temp.thinning = 1.0; + expl_temp.adaptPCR = false; + expl_temp.outlier[0] = 'i'; + expl_temp.outlier[1] = 'q'; + expl_temp.outlier[2] = 'r'; + expl_temp.zeta = 1.0E-12; + expl_temp.steps = 50.0; + expl_temp.delta = 3.0; + expl_temp.nCR = 3.0; + expl_temp.pUnitGamma = 0.2; + expl_temp.lambda = 0.5; + expl_temp.CPU = 1.0; + expl_temp.parallel = false; + expl_temp.T = 1000.0; + expl_temp.N = 10.0; + expl_temp.d = 17.0; + b_expl_temp.N = 0.0; + b_expl_temp.Y = 0.0; + cast(t16_outlier, &expl_temp, b_expl_temp, t16_AR, t16_R_stat, t16_CR, + &bayesResults_bayesRes->dreamOutput); + + // ------------------------------------------------------------------ + // (6) chain + // ------------------------------------------------------------------- + // Make the final structure... + r.f1 = f1; + r1.f1 = b_f1; + r2.f1 = c_f1; + coder::internal::structConstructorHelper(&r, &r1, &r2, + bayesResults_bestFitsMean_ref, bayesResults_bestFitsMean_sld, + bayesResults_bestFitsMean_chi, bayesResults_bestFitsMean_data); + h_f1.set_size(1); + h_f1[0] = 0.0; + r.f1 = d_f1; + r2.f1 = e_f1; + r3.f1 = f_f1; + r1.f1 = g_f1; + r4.f1 = h_f1; + coder::internal::structConstructorHelper(&r, &r2, &r3, &r1, &r4, + bayesResults_predlims_refPredInts, bayesResults_predlims_sldPredInts, + bayesResults_predlims_refXdata, bayesResults_predlims_sldXdata, + bayesResults_predlims_sampleChi_data, bayesResults_predlims_sampleChi_size); + cast(t17_par95_data, t17_par95_size, t17_par65_data, t17_par65_size, + t17_mean_data, t17_mean_size, bayesResults_parConfInts_par95, + bayesResults_parConfInts_par65, bayesResults_parConfInts_mean); + bayesResults_bestPars.set_size(1, 1); + bayesResults_bestPars[0] = 1.0; + bayesResults_bayesRes->allChains.set_size(1, 3, 1); + for (i = 0; i < 3; i++) { + bayesResults_bayesRes->allChains[bayesResults_bayesRes->allChains.size(0) * + i] = 1.0; + } + + bayesResults_bayesRes->nestOutput.LogZ = 0.0; + bayesResults_bayesRes->nestOutput.nestSamples.size[0] = 1; + bayesResults_bayesRes->nestOutput.nestSamples.size[1] = 2; + bayesResults_bayesRes->nestOutput.postSamples.size[0] = 1; + bayesResults_bayesRes->nestOutput.postSamples.size[1] = 2; + bayesResults_chain.set_size(1, 2); + bayesResults_bayesRes->nestOutput.nestSamples.data[0] = 0.0; + bayesResults_bayesRes->nestOutput.postSamples.data[0] = 0.0; + bayesResults_chain[0] = 0.0; + bayesResults_bayesRes->nestOutput.nestSamples.data[1] = 0.0; + bayesResults_bayesRes->nestOutput.postSamples.data[1] = 0.0; + bayesResults_chain[bayesResults_chain.size(0)] = 0.0; + } +} + +// End of code generation (makeEmptyBayesResultsStruct.cpp) diff --git a/RAT/makeEmptyBayesResultsStruct.h b/RAT/makeEmptyBayesResultsStruct.h new file mode 100644 index 00000000..c08b88ce --- /dev/null +++ b/RAT/makeEmptyBayesResultsStruct.h @@ -0,0 +1,65 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// makeEmptyBayesResultsStruct.h +// +// Code generation for function 'makeEmptyBayesResultsStruct' +// +#ifndef MAKEEMPTYBAYESRESULTSSTRUCT_H +#define MAKEEMPTYBAYESRESULTSSTRUCT_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct c_struct_T; +} + +// Function Declarations +namespace RAT +{ + void b_makeEmptyBayesResultsStruct(real_T nContrasts, boolean_T isDomains, :: + coder::array &bayesResults_bestFitsMean_ref, ::coder::array< + cell_wrap_8, 2U> &bayesResults_bestFitsMean_sld, real_T + *bayesResults_bestFitsMean_chi, ::coder::array + &bayesResults_bestFitsMean_data, ::coder::array + &bayesResults_predlims_refPredInts, ::coder::array + &bayesResults_predlims_sldPredInts, ::coder::array + &bayesResults_predlims_refXdata, ::coder::array + &bayesResults_predlims_sldXdata, real_T + bayesResults_predlims_sampleChi_data[], int32_T + *bayesResults_predlims_sampleChi_size, ::coder::array + &bayesResults_parConfInts_par95, ::coder::array + &bayesResults_parConfInts_par65, ::coder::array + &bayesResults_parConfInts_mean, ::coder::array + &bayesResults_bestPars, c_struct_T *bayesResults_bayesRes, ::coder::array< + real_T, 2U> &bayesResults_chain); + void makeEmptyBayesResultsStruct(real_T nContrasts, boolean_T isDomains, + real_T nChains, ::coder::array + &bayesResults_bestFitsMean_ref, ::coder::array + &bayesResults_bestFitsMean_sld, real_T *bayesResults_bestFitsMean_chi, :: + coder::array &bayesResults_bestFitsMean_data, ::coder:: + array &bayesResults_predlims_refPredInts, ::coder::array< + cell_wrap_8, 1U> &bayesResults_predlims_sldPredInts, ::coder::array< + cell_wrap_8, 1U> &bayesResults_predlims_refXdata, ::coder::array &bayesResults_predlims_sldXdata, real_T + bayesResults_predlims_sampleChi_data[], int32_T + *bayesResults_predlims_sampleChi_size, ::coder::array + &bayesResults_parConfInts_par95, ::coder::array + &bayesResults_parConfInts_par65, ::coder::array + &bayesResults_parConfInts_mean, ::coder::array + &bayesResults_bestPars, c_struct_T *bayesResults_bayesRes, ::coder::array< + real_T, 2U> &bayesResults_chain); +} + +#endif + +// End of code generation (makeEmptyBayesResultsStruct.h) diff --git a/RAT/makeSLDProfileXY.cpp b/RAT/makeSLDProfileXY.cpp index 552e5f8a..a7b9e6a9 100644 --- a/RAT/makeSLDProfileXY.cpp +++ b/RAT/makeSLDProfileXY.cpp @@ -21,9 +21,9 @@ // Function Definitions namespace RAT { - void makeSLDProfileXY(real_T nbair, real_T nbsub, real_T ssub, const ::coder:: - array &layers, real_T numberOfLayers, real_T - nrepeats, ::coder::array &out) + void makeSLDProfileXY(real_T bulkIn, real_T bulkOut, real_T ssub, const :: + coder::array &layers, real_T numberOfLayers, + real_T nrepeats, ::coder::array &out) { ::coder::array Lays; ::coder::array SLD; @@ -38,9 +38,9 @@ namespace RAT int32_T i; int32_T loop_ub; if (numberOfLayers > 0.0) { - real_T b; real_T lastBoxEdge; real_T nextLayRough; + real_T subsBoxCen_tmp; int32_T i1; b_layers.set_size(layers.size(0)); loop_ub = layers.size(0); @@ -48,23 +48,23 @@ namespace RAT b_layers[i] = layers[i]; } - b = coder::sum(b_layers) * nrepeats + 150.0; - if (std::isnan(b)) { + subsBoxCen_tmp = coder::sum(b_layers) * nrepeats + 150.0; + if (std::isnan(subsBoxCen_tmp)) { x.set_size(1, 1); x[0] = rtNaN; - } else if (b < 0.0) { + } else if (subsBoxCen_tmp < 0.0) { x.set_size(1, 0); } else { - x.set_size(1, static_cast(b) + 1); - loop_ub = static_cast(b); + x.set_size(1, static_cast(subsBoxCen_tmp) + 1); + loop_ub = static_cast(subsBoxCen_tmp); for (i = 0; i <= loop_ub; i++) { x[i] = i; } } - b = numberOfLayers * nrepeats; - Lays.set_size(x.size(1), static_cast(b + 2.0)); - loop_ub = static_cast(b + 2.0); + subsBoxCen_tmp = numberOfLayers * nrepeats; + Lays.set_size(x.size(1), static_cast(subsBoxCen_tmp + 2.0)); + loop_ub = static_cast(subsBoxCen_tmp + 2.0); for (i = 0; i < loop_ub; i++) { b_loop_ub = x.size(1); for (i1 = 0; i1 < b_loop_ub; i1++) { @@ -73,7 +73,7 @@ namespace RAT } nextLayRough = layers[layers.size(0) * 2]; - asymconvstep(x, 100.0, 0.0, nextLayRough, nextLayRough, nbair, airBox); + asymconvstep(x, 100.0, 0.0, nextLayRough, nextLayRough, bulkIn, airBox); lastBoxEdge = 50.0; i = static_cast(nrepeats); for (int32_T n{0}; n < i; n++) { @@ -109,16 +109,18 @@ namespace RAT // layers(end,3); asymconvstep(x, (x[x.size(1) - 1] - lastBoxEdge) * 2.0, x[x.size(1) - 1], - nextLayRough, ssub, nbsub, r1); + nextLayRough, ssub, bulkOut, r1); loop_ub = Lays.size(0); for (i = 0; i < loop_ub; i++) { - Lays[i + Lays.size(0) * (static_cast(b + 1.0) - 1)] = r1[i]; + Lays[i + Lays.size(0) * (static_cast(subsBoxCen_tmp + 1.0) - 1)] + = r1[i]; } // plot(x,Lays(:,(numberOfLayers*nrepeats)+1)) loop_ub = Lays.size(0); for (i = 0; i < loop_ub; i++) { - Lays[i + Lays.size(0) * (static_cast(b + 2.0) - 1)] = airBox[i]; + Lays[i + Lays.size(0) * (static_cast(subsBoxCen_tmp + 2.0) - 1)] + = airBox[i]; } // plot(x,Lays(:,(numberOfLayers*nrepeats)+2)) @@ -129,26 +131,27 @@ namespace RAT SLD[i] = b_SLD[i]; } } else { - real_T tmp_data[101]; - real_T widths; + real_T subsBoxCen_tmp; x.set_size(1, 101); r.set_size(1, 101); for (i = 0; i < 101; i++) { x[i] = i; - tmp_data[i] = i; r[i] = i; } - widths = coder::internal::maximum(tmp_data); - asymconvstep(r, widths, 0.0, ssub, ssub, nbair, r1); + subsBoxCen_tmp = coder::internal::maximum(r); r.set_size(1, 101); for (i = 0; i < 101; i++) { - tmp_data[i] = i; r[i] = i; } - asymconvstep(r, widths, coder::internal::maximum(tmp_data), ssub, ssub, - nbsub, r2); + asymconvstep(r, subsBoxCen_tmp, 0.0, ssub, ssub, bulkIn, r1); + r.set_size(1, 101); + for (i = 0; i < 101; i++) { + r[i] = i; + } + + asymconvstep(r, subsBoxCen_tmp, subsBoxCen_tmp, ssub, ssub, bulkOut, r2); SLD.set_size(1, r1.size(1)); loop_ub = r1.size(1); for (i = 0; i < loop_ub; i++) { @@ -186,9 +189,9 @@ namespace RAT int32_T i; int32_T loop_ub; if (numberOfLayers > 0.0) { - real_T b; real_T lastBoxEdge; real_T nextLayRough; + real_T subsBoxCen_tmp; int32_T i1; b_layers.set_size(layers.size(0)); loop_ub = layers.size(0); @@ -196,23 +199,23 @@ namespace RAT b_layers[i] = layers[i]; } - b = coder::sum(b_layers) * nrepeats + 150.0; - if (std::isnan(b)) { + subsBoxCen_tmp = coder::sum(b_layers) * nrepeats + 150.0; + if (std::isnan(subsBoxCen_tmp)) { x.set_size(1, 1); x[0] = rtNaN; - } else if (b < 0.0) { + } else if (subsBoxCen_tmp < 0.0) { x.set_size(1, 0); } else { - x.set_size(1, static_cast(b) + 1); - loop_ub = static_cast(b); + x.set_size(1, static_cast(subsBoxCen_tmp) + 1); + loop_ub = static_cast(subsBoxCen_tmp); for (i = 0; i <= loop_ub; i++) { x[i] = i; } } - b = numberOfLayers * nrepeats; - Lays.set_size(x.size(1), static_cast(b + 2.0)); - loop_ub = static_cast(b + 2.0); + subsBoxCen_tmp = numberOfLayers * nrepeats; + Lays.set_size(x.size(1), static_cast(subsBoxCen_tmp + 2.0)); + loop_ub = static_cast(subsBoxCen_tmp + 2.0); for (i = 0; i < loop_ub; i++) { b_loop_ub = x.size(1); for (i1 = 0; i1 < b_loop_ub; i1++) { @@ -260,13 +263,15 @@ namespace RAT nextLayRough, ssub, r1); loop_ub = Lays.size(0); for (i = 0; i < loop_ub; i++) { - Lays[i + Lays.size(0) * (static_cast(b + 1.0) - 1)] = r1[i]; + Lays[i + Lays.size(0) * (static_cast(subsBoxCen_tmp + 1.0) - 1)] + = r1[i]; } // plot(x,Lays(:,(numberOfLayers*nrepeats)+1)) loop_ub = Lays.size(0); for (i = 0; i < loop_ub; i++) { - Lays[i + Lays.size(0) * (static_cast(b + 2.0) - 1)] = airBox[i]; + Lays[i + Lays.size(0) * (static_cast(subsBoxCen_tmp + 2.0) - 1)] + = airBox[i]; } // plot(x,Lays(:,(numberOfLayers*nrepeats)+2)) @@ -277,25 +282,27 @@ namespace RAT SLD[i] = b_SLD[i]; } } else { - real_T tmp_data[101]; - real_T widths; + real_T subsBoxCen_tmp; x.set_size(1, 101); r.set_size(1, 101); for (i = 0; i < 101; i++) { x[i] = i; - tmp_data[i] = i; r[i] = i; } - widths = coder::internal::maximum(tmp_data); - asymconvstep(r, widths, 0.0, ssub, ssub, r1); + subsBoxCen_tmp = coder::internal::maximum(r); + r.set_size(1, 101); + for (i = 0; i < 101; i++) { + r[i] = i; + } + + asymconvstep(r, subsBoxCen_tmp, 0.0, ssub, ssub, r1); r.set_size(1, 101); for (i = 0; i < 101; i++) { - tmp_data[i] = i; r[i] = i; } - asymconvstep(r, widths, coder::internal::maximum(tmp_data), ssub, ssub, r2); + asymconvstep(r, subsBoxCen_tmp, subsBoxCen_tmp, ssub, ssub, r2); SLD.set_size(1, r1.size(1)); loop_ub = r1.size(1); for (i = 0; i < loop_ub; i++) { diff --git a/RAT/makeSLDProfileXY.h b/RAT/makeSLDProfileXY.h index 226d1efe..981e5289 100644 --- a/RAT/makeSLDProfileXY.h +++ b/RAT/makeSLDProfileXY.h @@ -19,9 +19,9 @@ // Function Declarations namespace RAT { - void makeSLDProfileXY(real_T nbair, real_T nbsub, real_T ssub, const ::coder:: - array &layers, real_T numberOfLayers, real_T - nrepeats, ::coder::array &out); + void makeSLDProfileXY(real_T bulkIn, real_T bulkOut, real_T ssub, const :: + coder::array &layers, real_T numberOfLayers, + real_T nrepeats, ::coder::array &out); void makeSLDProfileXY(real_T ssub, const ::coder::array &layers, real_T numberOfLayers, real_T nrepeats, ::coder::array< real_T, 2U> &out); diff --git a/RAT/makeSLDProfiles.cpp b/RAT/makeSLDProfiles.cpp index 93a50afc..b6f5b78c 100644 --- a/RAT/makeSLDProfiles.cpp +++ b/RAT/makeSLDProfiles.cpp @@ -17,9 +17,9 @@ // Function Definitions namespace RAT { - void makeSLDProfiles(real_T nbair, real_T nbsub, const ::coder::array &sld, real_T ssub, const real_T repeats[2], ::coder:: - array &sldProfile) + void makeSLDProfiles(real_T bulkIn, real_T bulkOut, const ::coder::array< + real_T, 2U> &sld, real_T ssub, const real_T repeats[2], :: + coder::array &sldProfile) { real_T d; if (repeats[0] == 0.0) { @@ -28,7 +28,7 @@ namespace RAT d = repeats[1]; } - makeSLDProfileXY(nbair, nbsub, ssub, sld, static_cast(sld.size(0)), + makeSLDProfileXY(bulkIn, bulkOut, ssub, sld, static_cast(sld.size(0)), d, sldProfile); } diff --git a/RAT/makeSLDProfiles.h b/RAT/makeSLDProfiles.h index a73ccffc..9baad4d9 100644 --- a/RAT/makeSLDProfiles.h +++ b/RAT/makeSLDProfiles.h @@ -19,9 +19,9 @@ // Function Declarations namespace RAT { - void makeSLDProfiles(real_T nbair, real_T nbsub, const ::coder::array &sld, real_T ssub, const real_T repeats[2], ::coder:: - array &sldProfile); + void makeSLDProfiles(real_T bulkIn, real_T bulkOut, const ::coder::array< + real_T, 2U> &sld, real_T ssub, const real_T repeats[2], :: + coder::array &sldProfile); void makeSLDProfiles(const ::coder::array &sld, real_T ssub, const real_T repeats[2], ::coder::array &sldProfile); } diff --git a/RAT/matrix_to_integer_power.cpp b/RAT/matrix_to_integer_power.cpp new file mode 100644 index 00000000..aa597826 --- /dev/null +++ b/RAT/matrix_to_integer_power.cpp @@ -0,0 +1,213 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// matrix_to_integer_power.cpp +// +// Code generation for function 'matrix_to_integer_power' +// + +// Include files +#include "matrix_to_integer_power.h" +#include "rt_nonfinite.h" +#include "vAllOrAny.h" +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + static void matrix_to_large_integer_power(real_T a_data[], real_T b, real_T + c_data[], int32_T c_size[2]); + static void matrix_to_small_integer_power(real_T a_data[], real_T b, real_T + c_data[], int32_T c_size[2]); + static void nbits(int32_T n, int32_T *log2n, int32_T *nbitson); + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + static void matrix_to_large_integer_power(real_T a_data[], real_T b, real_T + c_data[], int32_T c_size[2]) + { + c_size[0] = 1; + c_size[1] = 1; + if ((!std::isinf(b)) && (!std::isnan(b))) { + real_T e; + boolean_T firstmult; + e = std::abs(b); + firstmult = true; + real_T ed2; + int32_T exitg1; + do { + exitg1 = 0; + ed2 = std::floor(e / 2.0); + if (2.0 * ed2 != e) { + if (firstmult) { + c_size[0] = 1; + c_size[1] = 1; + c_data[0] = a_data[0]; + firstmult = false; + } else { + e = c_data[0]; + c_size[0] = 1; + c_size[1] = 1; + c_data[0] = e * a_data[0]; + } + } + + if (ed2 == 0.0) { + exitg1 = 1; + } else { + e = ed2; + a_data[0] *= a_data[0]; + } + } while (exitg1 == 0); + } else { + c_size[0] = 1; + c_size[1] = 1; + c_data[0] = rtNaN; + } + } + + static void matrix_to_small_integer_power(real_T a_data[], real_T b, real_T + c_data[], int32_T c_size[2]) + { + real_T aBuffer_data; + int32_T n; + int32_T nb; + int32_T nbitson; + boolean_T b_first; + aBuffer_data = std::abs(b); + n = static_cast(aBuffer_data); + nbits(static_cast(aBuffer_data), &nb, &nbitson); + if (static_cast(aBuffer_data) <= 2) { + if (b == 2.0) { + c_size[0] = 1; + c_size[1] = 1; + c_data[0] = a_data[0] * a_data[0]; + } else if (b == 1.0) { + c_size[0] = 1; + c_size[1] = 1; + c_data[0] = a_data[0]; + } else { + b_first = false; + internal::c_genloops(a_data, &b_first); + if (b_first) { + c_size[0] = 1; + c_size[1] = 1; + c_data[0] = rtNaN; + } else { + c_size[0] = 1; + c_size[1] = 1; + c_data[0] = 1.0; + } + } + } else { + real_T cBuffer_data; + boolean_T aBufferInUse; + boolean_T cBufferInUse; + b_first = true; + aBufferInUse = false; + cBufferInUse = ((nbitson & 1) == 0); + for (nbitson = 0; nbitson <= nb - 2; nbitson++) { + if ((n & 1) != 0) { + if (b_first) { + b_first = false; + if (cBufferInUse) { + if (aBufferInUse) { + cBuffer_data = aBuffer_data; + } else { + cBuffer_data = a_data[0]; + } + } else if (aBufferInUse) { + c_data[0] = aBuffer_data; + } else { + c_data[0] = a_data[0]; + } + } else { + if (aBufferInUse) { + if (cBufferInUse) { + c_data[0] = cBuffer_data * aBuffer_data; + } else { + cBuffer_data = c_data[0] * aBuffer_data; + } + } else if (cBufferInUse) { + c_data[0] = cBuffer_data * a_data[0]; + } else { + cBuffer_data = c_data[0] * a_data[0]; + } + + cBufferInUse = !cBufferInUse; + } + } + + n >>= 1; + if (aBufferInUse) { + a_data[0] = aBuffer_data * aBuffer_data; + } else { + aBuffer_data = a_data[0]; + aBuffer_data *= aBuffer_data; + } + + aBufferInUse = !aBufferInUse; + } + + if (b_first) { + if (aBufferInUse) { + c_size[0] = 1; + c_size[1] = 1; + c_data[0] = aBuffer_data; + } else { + c_size[0] = 1; + c_size[1] = 1; + c_data[0] = a_data[0]; + } + } else if (aBufferInUse) { + c_size[0] = 1; + c_size[1] = 1; + c_data[0] = cBuffer_data * aBuffer_data; + } else { + c_size[0] = 1; + c_size[1] = 1; + c_data[0] = cBuffer_data * a_data[0]; + } + } + } + + static void nbits(int32_T n, int32_T *log2n, int32_T *nbitson) + { + *nbitson = 0; + *log2n = 0; + while (n > 0) { + (*log2n)++; + if ((n & 1) != 0) { + (*nbitson)++; + } + + n >>= 1; + } + } + + void matrix_to_integer_power(const real_T a_data[], real_T b, real_T c_data[], + int32_T c_size[2]) + { + if (std::abs(b) <= 2.147483647E+9) { + real_T b_a_data; + b_a_data = a_data[0]; + matrix_to_small_integer_power((real_T *)&b_a_data, b, c_data, c_size); + } else { + real_T b_a_data; + b_a_data = a_data[0]; + matrix_to_large_integer_power((real_T *)&b_a_data, b, c_data, c_size); + } + } + } +} + +// End of code generation (matrix_to_integer_power.cpp) diff --git a/RAT/matrix_to_integer_power.h b/RAT/matrix_to_integer_power.h new file mode 100644 index 00000000..7991af26 --- /dev/null +++ b/RAT/matrix_to_integer_power.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// matrix_to_integer_power.h +// +// Code generation for function 'matrix_to_integer_power' +// +#ifndef MATRIX_TO_INTEGER_POWER_H +#define MATRIX_TO_INTEGER_POWER_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void matrix_to_integer_power(const real_T a_data[], real_T b, real_T c_data[], + int32_T c_size[2]); + } +} + +#endif + +// End of code generation (matrix_to_integer_power.h) diff --git a/RAT/mchol.cpp b/RAT/mchol.cpp new file mode 100644 index 00000000..c2ed71eb --- /dev/null +++ b/RAT/mchol.cpp @@ -0,0 +1,476 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mchol.cpp +// +// Code generation for function 'mchol' +// + +// Include files +#include "mchol.h" +#include "abs.h" +#include "diag.h" +#include "div.h" +#include "minOrMax.h" +#include "mtimes.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, int32_T in3, const ::coder::array &in4, + const ::coder::array &in5); + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, real_T in3, const ::coder::array &in4); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, int32_T in3, const ::coder::array &in4, + const ::coder::array &in5) + { + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in5.size(1) != 1); + if (in5.size(1) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in5.size(1); + } + + for (int32_T i{0}; i < loop_ub; i++) { + in1[(static_cast(in2[i]) + in1.size(0) * in3) - 1] = in4[( + static_cast(in2[i * stride_0_0]) + in4.size(0) * in3) - 1] - + in5[i * stride_1_0]; + } + } + + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, real_T in3, const ::coder::array &in4) + { + ::coder::array b_in1; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + if (in4.size(0) == 1) { + i = in2.size(0); + } else { + i = in4.size(0); + } + + b_in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in4.size(0) != 1); + if (in4.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in4.size(0); + } + + for (i = 0; i < loop_ub; i++) { + b_in1[i] = in1[static_cast(in2[i * stride_0_0]) - 1] - in3 * + in4[i * stride_1_0]; + } + + loop_ub = b_in1.size(0); + for (i = 0; i < loop_ub; i++) { + in1[static_cast(in2[i]) - 1] = b_in1[i]; + } + } + + void mchol(const ::coder::array &G, ::coder::array &L, + ::coder::array &D) + { + ::coder::array C; + ::coder::array b_G; + ::coder::array b_L; + ::coder::array ee; + ::coder::array r; + ::coder::array theta; + ::coder::array y; + ::coder::array ind; + ::coder::array r2; + ::coder::array varargin_1_tmp; + ::coder::array bb; + ::coder::array r1; + real_T b_dv1[3]; + real_T dv2[3]; + real_T b_dv[2]; + real_T b; + real_T beta2; + int32_T b_loop_ub; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T n; + + // + // [L,D,E,pneg]=mchol(G) + // + // Given a symmetric matrix G, find a matrix E of "small" norm and c + // L, and D such that G+E is Positive Definite, and + // + // G+E = L*D*L' + // + // Also, calculate a direction pneg, such that if G is not PD, then + // + // pneg'*G*pneg < 0 + // + // Note that if G is PD, then the routine will return pneg=[]. + // + // Reference: Gill, Murray, and Wright, "Practical Optimization", p111. + // Author: Brian Borchers (borchers@nmt.edu) + // + // Copyright (c) 2009, Brian Borchers + // All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions are + // met: + // + // * Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // * Redistributions in binary form must reproduce the above copyright + // notice, this list of conditions and the following disclaimer in + // the documentation and/or other materials provided with the distribution + // * Neither the name of the New Mexico Inst of Mining & Tech nor the names + // of its contributors may be used to endorse or promote products derived + // from this software without specific prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + // POSSIBILITY OF SUCH DAMAGE. + // + // n gives the size of the matrix. + // + n = G.size(0); + + // + // gamma, zi, nu, and beta2 are quantities used by the algorithm. + // + coder::diag(G, varargin_1_tmp); + coder::diag(varargin_1_tmp, r); + if ((G.size(0) == r.size(0)) && (G.size(1) == r.size(1))) { + b_G.set_size(G.size(0), G.size(1)); + loop_ub = G.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = G.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_G[i1 + b_G.size(0) * i] = G[i1 + G.size(0) * i] - r[i1 + r.size(0) * + i]; + } + } + + coder::internal::maximum(b_G, y); + } else { + c_binary_expand_op(y, G, r); + } + + b_dv[0] = 1.0; + b_dv[1] = std::sqrt(static_cast(G.size(0)) * static_cast + (G.size(0)) - 1.0); + b_dv1[0] = coder::internal::maximum(varargin_1_tmp); + b_dv1[1] = coder::internal::maximum(y) / coder::internal::maximum(b_dv); + b_dv1[2] = 1.0E-15; + beta2 = coder::internal::b_maximum(b_dv1); + + // + // Initialize diag(C) to diag(G). + // + C.set_size(r.size(0), r.size(1)); + loop_ub = r.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = r.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + C[i1 + C.size(0) * i] = r[i1 + r.size(0) * i]; + } + } + + // + // Loop through, calculating column j of L for j=1:n + // + L.set_size(G.size(0), G.size(0)); + loop_ub = G.size(0); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = G.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + L[i1 + L.size(0) * i] = 0.0; + } + } + + D.set_size(G.size(0), G.size(0)); + loop_ub = G.size(0); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = G.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + D[i1 + D.size(0) * i] = 0.0; + } + } + + theta.set_size(G.size(0), G.size(0)); + loop_ub = G.size(0); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = G.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + theta[i1 + theta.size(0) * i] = 0.0; + } + } + + i = G.size(0); + if (G.size(0) - 1 >= 0) { + dv2[0] = 2.2204460492503131E-16; + b = static_cast(G.size(0)) * static_cast(G.size(0)); + } + + for (int32_T j{0}; j < i; j++) { + real_T a; + if (j < 1) { + bb.set_size(1, 0); + } else { + bb.set_size(1, j); + for (i1 = 0; i1 < j; i1++) { + bb[i1] = i1 + 1; + } + } + + if (static_cast(n) < static_cast(j) + 2U) { + ee.set_size(1, 0); + } else { + i1 = n - j; + ee.set_size(1, i1 - 1); + loop_ub = i1 - 2; + for (i1 = 0; i1 <= loop_ub; i1++) { + ee[i1] = (static_cast(j) + static_cast(i1)) + 2U; + } + } + + // + // Calculate the jth row of L. + // + if (j + 1 > 1) { + r2.set_size(bb.size(1)); + loop_ub = bb.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + r2[i1] = bb[i1]; + } + + b_G.set_size(r2.size(0), r2.size(0)); + loop_ub = r2.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = r2.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + b_G[i2 + b_G.size(0) * i1] = D[(static_cast(r2[i2]) + + D.size(0) * (static_cast(r2[i1]) - 1)) - 1]; + } + } + + coder::diag(b_G, varargin_1_tmp); + if (r2.size(0) == varargin_1_tmp.size(0)) { + loop_ub = r2.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = static_cast(r2[i1]) - 1; + L[j + L.size(0) * b_loop_ub] = C[j + C.size(0) * b_loop_ub] / + varargin_1_tmp[i1]; + } + } else { + binary_expand_op(L, j, r2, C, varargin_1_tmp); + } + } + + // + // Update the jth column of C. + // + if (j + 1 >= 2) { + if (j + 1 < n) { + r2.set_size(bb.size(1)); + loop_ub = bb.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + r2[i1] = bb[i1]; + } + + r.set_size(ee.size(1), r2.size(0)); + loop_ub = r2.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = ee.size(1); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + r[i2 + r.size(0) * i1] = C[(static_cast(ee[i2]) + C.size + (0) * (static_cast(r2[i1]) - 1)) - 1]; + } + } + + varargin_1_tmp.set_size(ee.size(1)); + loop_ub = ee.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + varargin_1_tmp[i1] = ee[i1]; + } + + b_L.set_size(1, r2.size(0)); + loop_ub = r2.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_L[i1] = L[j + L.size(0) * (static_cast(r2[i1]) - 1)]; + } + + coder::internal::blas::mtimes(b_L, r, y); + if (varargin_1_tmp.size(0) == y.size(1)) { + loop_ub = varargin_1_tmp.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = static_cast(varargin_1_tmp[i1]) - 1; + C[b_loop_ub + C.size(0) * j] = G[b_loop_ub + G.size(0) * j] - y[i1]; + } + } else { + binary_expand_op(C, varargin_1_tmp, j, G, y); + } + } + } else { + r2.set_size(ee.size(1)); + loop_ub = ee.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + r2[i1] = ee[i1]; + } + + loop_ub = r2.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = static_cast(r2[i1]) - 1; + C[b_loop_ub] = G[b_loop_ub]; + } + } + + // + // Update theta. + // + if (j + 1 == n) { + theta[j] = 0.0; + } else { + varargin_1_tmp.set_size(ee.size(1)); + loop_ub = ee.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + varargin_1_tmp[i1] = C[(static_cast(ee[i1]) + C.size(0) * j) + - 1]; + } + + coder::b_abs(varargin_1_tmp, r2); + theta[j] = coder::internal::maximum(r2); + } + + // + // Update D + // + dv2[1] = std::abs(C[j + C.size(0) * j]); + dv2[2] = theta[j] * theta[j] / beta2; + D[j + D.size(0) * j] = coder::internal::b_maximum(dv2); + + // + // Update E. + // + // Update C again... + // + // %%%%%%% M.Zibulevsky: begin of changes, old version is commented %%%%%%%%%%%%% + // for i=j+1:n, + // C(i,i)=C(i,i)-C(i,j)^2/D(j,j); + // end; + a = (static_cast(j) + 1.0) * (static_cast(n) + 1.0) + 1.0; + if (b < a) { + y.set_size(1, 0); + } else { + loop_ub = static_cast((b - a) / (static_cast(n) + 1.0)); + y.set_size(1, loop_ub + 1); + for (i1 = 0; i1 <= loop_ub; i1++) { + y[i1] = a + (static_cast(n) + 1.0) * static_cast(i1); + } + } + + ind.set_size(y.size(1)); + loop_ub = y.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + ind[i1] = y[i1]; + } + + a = 1.0 / D[j + D.size(0) * j]; + varargin_1_tmp.set_size(ee.size(1)); + loop_ub = ee.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + varargin_1_tmp[i1] = C[(static_cast(ee[i1]) + C.size(0) * j) - + 1]; + } + + r2.set_size(varargin_1_tmp.size(0)); + loop_ub = varargin_1_tmp.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + real_T varargin_1; + varargin_1 = varargin_1_tmp[i1]; + r2[i1] = varargin_1 * varargin_1; + } + + if (ind.size(0) == r2.size(0)) { + varargin_1_tmp.set_size(ind.size(0)); + loop_ub = ind.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + varargin_1_tmp[i1] = C[static_cast(ind[i1]) - 1] - a * r2[i1]; + } + + loop_ub = varargin_1_tmp.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + C[static_cast(ind[i1]) - 1] = varargin_1_tmp[i1]; + } + } else { + binary_expand_op(C, ind, a, r2); + } + } + + // + // Put 1's on the diagonal of L + // + // for j=1:n, + // L(j,j)=1; + // end; + b = static_cast(G.size(0)) * static_cast(G.size(0)); + if (b < 1.0) { + y.set_size(1, 0); + } else { + y.set_size(1, static_cast((b - 1.0) / (static_cast(G.size + (0)) + 1.0)) + 1); + loop_ub = static_cast((b - 1.0) / (static_cast(G.size(0)) + + 1.0)); + for (i = 0; i <= loop_ub; i++) { + y[i] = (static_cast(G.size(0)) + 1.0) * static_cast(i) + + 1.0; + } + } + + r1.set_size(y.size(1)); + loop_ub = y.size(1); + for (i = 0; i < loop_ub; i++) { + r1[i] = static_cast(y[i]); + } + + loop_ub = r1.size(0); + for (i = 0; i < loop_ub; i++) { + L[r1[i] - 1] = 1.0; + } + + // %%%%%%%%%%%%%%%%%%%%%%% M.Zibulevsky: end of changes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // + // if needed, find a descent direction. + // + } +} + +// End of code generation (mchol.cpp) diff --git a/RAT/mchol.h b/RAT/mchol.h new file mode 100644 index 00000000..5816e53d --- /dev/null +++ b/RAT/mchol.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mchol.h +// +// Code generation for function 'mchol' +// +#ifndef MCHOL_H +#define MCHOL_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void mchol(const ::coder::array &G, ::coder::array &L, + ::coder::array &D); +} + +#endif + +// End of code generation (mchol.h) diff --git a/RAT/mean.cpp b/RAT/mean.cpp new file mode 100644 index 00000000..10af6d20 --- /dev/null +++ b/RAT/mean.cpp @@ -0,0 +1,89 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mean.cpp +// +// Code generation for function 'mean' +// + +// Include files +#include "mean.h" +#include "blockedSummation.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void mean(const ::coder::array &x, ::coder::array &y) + { + int32_T b_loop_ub; + int32_T loop_ub; + if ((x.size(0) == 0) || (x.size(1) == 0) || (x.size(2) == 0)) { + uint32_T sz_idx_1; + sz_idx_1 = static_cast(x.size(1)); + y.set_size(1, x.size(1), x.size(2)); + loop_ub = x.size(2); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = static_cast(sz_idx_1); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + y[i1 + y.size(1) * i] = 0.0; + } + } + } else { + nestedIter(x, x.size(0), y); + } + + y.set_size(1, y.size(1), y.size(2)); + loop_ub = y.size(2); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = y.size(1); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + y[i1 + y.size(1) * i] = y[i1 + y.size(1) * i] / static_cast + (x.size(0)); + } + } + } + + void mean(const ::coder::array &x, ::coder::array &y) + { + int32_T loop_ub; + if ((x.size(0) == 0) || (x.size(1) == 0)) { + y.set_size(1, x.size(1)); + loop_ub = x.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + y[i] = 0.0; + } + } else { + nestedIter(x, x.size(0), y); + } + + y.set_size(1, y.size(1)); + loop_ub = y.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + y[i] = y[i] / static_cast(x.size(0)); + } + } + + real_T mean(const real_T x_data[], int32_T x_size) + { + ::coder::array b_x_data; + real_T y; + if (x_size == 0) { + y = 0.0; + } else { + b_x_data.set((real_T *)&x_data[0], x_size); + y = nestedIter(b_x_data, x_size); + } + + y /= static_cast(x_size); + return y; + } + } +} + +// End of code generation (mean.cpp) diff --git a/RAT/mean.h b/RAT/mean.h new file mode 100644 index 00000000..d9008516 --- /dev/null +++ b/RAT/mean.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mean.h +// +// Code generation for function 'mean' +// +#ifndef MEAN_H +#define MEAN_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void mean(const ::coder::array &x, ::coder::array &y); + void mean(const ::coder::array &x, ::coder::array &y); + real_T mean(const real_T x_data[], int32_T x_size); + } +} + +#endif + +// End of code generation (mean.h) diff --git a/RAT/mergesort.cpp b/RAT/mergesort.cpp index 672589e8..cc3f8a68 100644 --- a/RAT/mergesort.cpp +++ b/RAT/mergesort.cpp @@ -21,6 +21,240 @@ namespace RAT { namespace internal { + void b_mergesort(int32_T idx[4], const real_T x[4]) + { + int32_T iwork[4]; + int32_T j; + int32_T qEnd; + if (sortLE(x, 1, 2)) { + idx[0] = 1; + idx[1] = 2; + } else { + idx[0] = 2; + idx[1] = 1; + } + + if (sortLE(x, 3, 4)) { + idx[2] = 3; + idx[3] = 4; + } else { + idx[2] = 4; + idx[3] = 3; + } + + j = 1; + for (int32_T pEnd{3}; pEnd < 5; pEnd = qEnd + 2) { + int32_T k; + int32_T p; + int32_T q; + p = j; + q = pEnd; + qEnd = j + 4; + k = 0; + while (k + 1 <= 4) { + int32_T i; + int32_T i1; + i = idx[q - 1]; + i1 = idx[p - 1]; + if (sortLE(x, i1, i)) { + iwork[k] = i1; + p++; + if (p == pEnd) { + while (q < j + 4) { + k++; + iwork[k] = idx[q - 1]; + q++; + } + } + } else { + iwork[k] = i; + q++; + if (q == j + 4) { + while (p < pEnd) { + k++; + iwork[k] = idx[p - 1]; + p++; + } + } + } + + k++; + } + + for (k = 0; k < 4; k++) { + idx[(j + k) - 1] = iwork[k]; + } + + j += 4; + } + } + + void b_mergesort(::coder::array &idx, const ::coder::array< + real_T, 2U> &x, int32_T n) + { + ::coder::array iwork; + int32_T b_i; + int32_T i; + int32_T k; + int32_T qEnd; + iwork.set_size(idx.size(1)); + i = n - 1; + for (k = 1; k <= i; k += 2) { + if (sortLE(x, k, k + 1)) { + idx[k - 1] = k; + idx[k] = k + 1; + } else { + idx[k - 1] = k + 1; + idx[k] = k; + } + } + + if ((n & 1) != 0) { + idx[n - 1] = n; + } + + b_i = 2; + while (b_i < n) { + int32_T i2; + int32_T j; + i2 = b_i << 1; + j = 1; + for (int32_T pEnd{b_i + 1}; pEnd < n + 1; pEnd = qEnd + b_i) { + int32_T kEnd; + int32_T p; + int32_T q; + p = j; + q = pEnd; + qEnd = j + i2; + if (qEnd > n + 1) { + qEnd = n + 1; + } + + k = 0; + kEnd = qEnd - j; + while (k + 1 <= kEnd) { + int32_T i1; + i = idx[q - 1]; + i1 = idx[p - 1]; + if (sortLE(x, i1, i)) { + iwork[k] = i1; + p++; + if (p == pEnd) { + while (q < qEnd) { + k++; + iwork[k] = idx[q - 1]; + q++; + } + } + } else { + iwork[k] = i; + q++; + if (q == qEnd) { + while (p < pEnd) { + k++; + iwork[k] = idx[p - 1]; + p++; + } + } + } + + k++; + } + + for (k = 0; k < kEnd; k++) { + idx[(j + k) - 1] = iwork[k]; + } + + j = qEnd; + } + + b_i = i2; + } + } + + void b_mergesort(::coder::array &idx, const ::coder::array< + real_T, 1U> &x, int32_T n) + { + ::coder::array iwork; + int32_T b_i; + int32_T i; + int32_T k; + int32_T qEnd; + iwork.set_size(idx.size(0)); + i = n - 1; + for (k = 1; k <= i; k += 2) { + if (sortLE(x, k, k + 1)) { + idx[k - 1] = k; + idx[k] = k + 1; + } else { + idx[k - 1] = k + 1; + idx[k] = k; + } + } + + if ((n & 1) != 0) { + idx[n - 1] = n; + } + + b_i = 2; + while (b_i < n) { + int32_T i2; + int32_T j; + i2 = b_i << 1; + j = 1; + for (int32_T pEnd{b_i + 1}; pEnd < n + 1; pEnd = qEnd + b_i) { + int32_T kEnd; + int32_T p; + int32_T q; + p = j; + q = pEnd; + qEnd = j + i2; + if (qEnd > n + 1) { + qEnd = n + 1; + } + + k = 0; + kEnd = qEnd - j; + while (k + 1 <= kEnd) { + int32_T i1; + i = idx[q - 1]; + i1 = idx[p - 1]; + if (sortLE(x, i1, i)) { + iwork[k] = i1; + p++; + if (p == pEnd) { + while (q < qEnd) { + k++; + iwork[k] = idx[q - 1]; + q++; + } + } + } else { + iwork[k] = i; + q++; + if (q == qEnd) { + while (p < pEnd) { + k++; + iwork[k] = idx[p - 1]; + p++; + } + } + } + + k++; + } + + for (k = 0; k < kEnd; k++) { + idx[(j + k) - 1] = iwork[k]; + } + + j = qEnd; + } + + b_i = i2; + } + } + void b_mergesort(::coder::array &idx, const ::coder::array< real_T, 2U> &x, const int32_T dir_data[], int32_T n) { diff --git a/RAT/mergesort.h b/RAT/mergesort.h index 320ab5e4..34034cf9 100644 --- a/RAT/mergesort.h +++ b/RAT/mergesort.h @@ -23,6 +23,11 @@ namespace RAT { namespace internal { + void b_mergesort(int32_T idx[4], const real_T x[4]); + void b_mergesort(::coder::array &idx, const ::coder::array< + real_T, 2U> &x, int32_T n); + void b_mergesort(::coder::array &idx, const ::coder::array< + real_T, 1U> &x, int32_T n); void b_mergesort(::coder::array &idx, const ::coder::array< real_T, 2U> &x, const int32_T dir_data[], int32_T n); } diff --git a/RAT/metropolisRule.cpp b/RAT/metropolisRule.cpp new file mode 100644 index 00000000..5539caec --- /dev/null +++ b/RAT/metropolisRule.cpp @@ -0,0 +1,185 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// metropolisRule.cpp +// +// Code generation for function 'metropolisRule' +// + +// Include files +#include "metropolisRule.h" +#include "RATMain_types.h" +#include "find.h" +#include "rand.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void e_binary_expand_op(::coder::array &in1, const :: + coder::array &in2, const ::coder::array &in3, const :: + coder::array &in4); + static void minus(::coder::array &in1, const ::coder::array &in2, const ::coder::array &in3); +} + +// Function Definitions +namespace RAT +{ + static void e_binary_expand_op(::coder::array &in1, const :: + coder::array &in2, const ::coder::array &in3, const :: + coder::array &in4) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + int32_T stride_2_0; + if (in4.size(0) == 1) { + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + } else { + i = in4.size(0); + } + + in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + stride_2_0 = (in4.size(0) != 1); + if (in4.size(0) == 1) { + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); + } + } else { + loop_ub = in4.size(0); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = (in2[i * stride_0_0] * in3[i * stride_1_0] > in4[i * stride_2_0]); + } + } + + static void minus(::coder::array &in1, const ::coder::array &in2, const ::coder::array &in3) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = in2[i * stride_0_0] - in3[i * stride_1_0]; + } + } + + void metropolisRule(const struct14_T *DREAMPar, const ::coder::array &log_L_xnew, const ::coder::array + &log_PR_xnew, const ::coder::array &log_L_xold, + const ::coder::array &log_PR_xold, ::coder:: + array &accept, ::coder::array + &idx_accept) + { + ::coder::array Z; + ::coder::array r; + ::coder::array r1; + ::coder::array r2; + ::coder::array b_accept; + int32_T i; + int32_T k; + + // Metropolis rule for acceptance or rejection + // No ABC --> regular MCMC with prior and likelihood + // Calculate the likelihood ratio + // Calculate the prior ration + // Calculate product of two probabily ratios + // Generate random numbers + coder::b_rand(DREAMPar->N, Z); + + // Find which alfa's are greater than Z + if (log_L_xnew.size(0) == log_L_xold.size(0)) { + r.set_size(log_L_xnew.size(0)); + k = log_L_xnew.size(0); + for (i = 0; i < k; i++) { + r[i] = log_L_xnew[i] - log_L_xold[i]; + } + } else { + minus(r, log_L_xnew, log_L_xold); + } + + i = r.size(0); + for (k = 0; k < i; k++) { + r[k] = std::exp(r[k]); + } + + if (log_PR_xnew.size(0) == log_PR_xold.size(0)) { + r1.set_size(log_PR_xnew.size(0)); + k = log_PR_xnew.size(0); + for (i = 0; i < k; i++) { + r1[i] = log_PR_xnew[i] - log_PR_xold[i]; + } + } else { + minus(r1, log_PR_xnew, log_PR_xold); + } + + i = r1.size(0); + for (k = 0; k < i; k++) { + r1[k] = std::exp(r1[k]); + } + + if (r.size(0) == 1) { + i = r1.size(0); + } else { + i = r.size(0); + } + + if ((r.size(0) == r1.size(0)) && (i == Z.size(0))) { + accept.set_size(r.size(0)); + k = r.size(0); + for (i = 0; i < k; i++) { + accept[i] = (r[i] * r1[i] > Z[i]); + } + } else { + e_binary_expand_op(accept, r, r1, Z); + } + + // ABC --> check if summary metrics as prior (diagnostic Bayes) or likelihood (regular ABC) + // Now derive which proposals to accept (row numbers of X) + b_accept.set_size(accept.size(0)); + k = accept.size(0); + for (i = 0; i < k; i++) { + b_accept[i] = accept[i]; + } + + coder::eml_find(b_accept, r2); + idx_accept.set_size(r2.size(0)); + k = r2.size(0); + for (i = 0; i < k; i++) { + idx_accept[i] = r2[i]; + } + } +} + +// End of code generation (metropolisRule.cpp) diff --git a/RAT/metropolisRule.h b/RAT/metropolisRule.h new file mode 100644 index 00000000..f5d6ffc3 --- /dev/null +++ b/RAT/metropolisRule.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// metropolisRule.h +// +// Code generation for function 'metropolisRule' +// +#ifndef METROPOLISRULE_H +#define METROPOLISRULE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct14_T; +} + +// Function Declarations +namespace RAT +{ + void metropolisRule(const struct14_T *DREAMPar, const ::coder::array &log_L_xnew, const ::coder::array + &log_PR_xnew, const ::coder::array &log_L_xold, + const ::coder::array &log_PR_xold, ::coder:: + array &accept, ::coder::array + &idx_accept); +} + +#endif + +// End of code generation (metropolisRule.h) diff --git a/RAT/minOrMax.cpp b/RAT/minOrMax.cpp index 252f1fc8..fdcc444c 100644 --- a/RAT/minOrMax.cpp +++ b/RAT/minOrMax.cpp @@ -10,6 +10,7 @@ // Include files #include "minOrMax.h" +#include "ixfun.h" #include "relop.h" #include "rt_nonfinite.h" #include "coder_array.h" @@ -18,36 +19,83 @@ // Function Definitions namespace RAT { - namespace coder + void c_binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3) { - namespace internal - { - real_T b_maximum(const real_T x[2]) - { - real_T ex; - if ((x[0] < x[1]) || (std::isnan(x[0]) && (!std::isnan(x[1])))) { - ex = x[1]; - } else { - ex = x[0]; - } + ::coder::array b_in2; + int32_T aux_0_1; + int32_T aux_1_1; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_0_1; + int32_T stride_1_0; + int32_T stride_1_1; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } - return ex; + if (in3.size(1) == 1) { + i1 = in2.size(1); + } else { + i1 = in3.size(1); + } + + b_in2.set_size(i, i1); + stride_0_0 = (in2.size(0) != 1); + stride_0_1 = (in2.size(1) != 1); + stride_1_0 = (in3.size(0) != 1); + stride_1_1 = (in3.size(1) != 1); + aux_0_1 = 0; + aux_1_1 = 0; + if (in3.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in3.size(1); + } + + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + i1 = in3.size(0); + if (i1 == 1) { + b_loop_ub = in2.size(0); + } else { + b_loop_ub = i1; } - real_T maximum(const real_T x_data[]) + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_in2[i1 + b_in2.size(0) * i] = in2[i1 * stride_0_0 + in2.size(0) * + aux_0_1] - in3[i1 * stride_1_0 + in3.size(0) * aux_1_1]; + } + + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + + coder::internal::maximum(b_in2, in1); + } + + namespace coder + { + namespace internal + { + real_T b_maximum(const real_T x[3]) { real_T ex; int32_T idx; int32_T k; - if (!std::isnan(x_data[0])) { + if (!std::isnan(x[0])) { idx = 1; } else { boolean_T exitg1; idx = 0; k = 2; exitg1 = false; - while ((!exitg1) && (k < 102)) { - if (!std::isnan(x_data[k - 1])) { + while ((!exitg1) && (k <= 3)) { + if (!std::isnan(x[k - 1])) { idx = k; exitg1 = true; } else { @@ -57,13 +105,13 @@ namespace RAT } if (idx == 0) { - ex = x_data[0]; + ex = x[0]; } else { - ex = x_data[idx - 1]; + ex = x[idx - 1]; idx++; - for (k = idx; k < 102; k++) { + for (k = idx; k < 4; k++) { real_T d; - d = x_data[k - 1]; + d = x[k - 1]; if (ex < d) { ex = d; } @@ -73,6 +121,132 @@ namespace RAT return ex; } + void maximum(const ::coder::array &x, ::coder::array &ex) + { + int32_T m; + int32_T n; + m = x.size(0); + n = x.size(1); + ex.set_size(1, x.size(1)); + if (x.size(1) >= 1) { + for (int32_T j{0}; j < n; j++) { + ex[j] = x[x.size(0) * j]; + for (int32_T i{2}; i <= m; i++) { + real_T d; + d = x[(i + x.size(0) * j) - 1]; + if (relop(ex[j], d)) { + ex[j] = d; + } + } + } + } + } + + real_T maximum(const ::coder::array &x) + { + real_T ex; + int32_T last; + last = x.size(0); + if (x.size(0) <= 2) { + if (x.size(0) == 1) { + ex = x[0]; + } else if ((x[0] < x[x.size(0) - 1]) || (std::isnan(x[0]) && (!std:: + isnan(x[x.size(0) - 1])))) { + ex = x[x.size(0) - 1]; + } else { + ex = x[0]; + } + } else { + int32_T idx; + int32_T k; + if (!std::isnan(x[0])) { + idx = 1; + } else { + boolean_T exitg1; + idx = 0; + k = 2; + exitg1 = false; + while ((!exitg1) && (k <= last)) { + if (!std::isnan(x[k - 1])) { + idx = k; + exitg1 = true; + } else { + k++; + } + } + } + + if (idx == 0) { + ex = x[0]; + } else { + ex = x[idx - 1]; + idx++; + for (k = idx; k <= last; k++) { + real_T d; + d = x[k - 1]; + if (ex < d) { + ex = d; + } + } + } + } + + return ex; + } + + real_T maximum(const ::coder::array &x) + { + real_T ex; + int32_T last; + last = x.size(1); + if (x.size(1) <= 2) { + if (x.size(1) == 1) { + ex = x[0]; + } else if ((x[0] < x[x.size(1) - 1]) || (std::isnan(x[0]) && (!std:: + isnan(x[x.size(1) - 1])))) { + ex = x[x.size(1) - 1]; + } else { + ex = x[0]; + } + } else { + int32_T idx; + int32_T k; + if (!std::isnan(x[0])) { + idx = 1; + } else { + boolean_T exitg1; + idx = 0; + k = 2; + exitg1 = false; + while ((!exitg1) && (k <= last)) { + if (!std::isnan(x[k - 1])) { + idx = k; + exitg1 = true; + } else { + k++; + } + } + } + + if (idx == 0) { + ex = x[0]; + } else { + ex = x[idx - 1]; + idx++; + for (k = idx; k <= last; k++) { + real_T d; + d = x[k - 1]; + if (ex < d) { + ex = d; + } + } + } + } + + return ex; + } + void maximum(const ::coder::array &x, real_T ex[2]) { int32_T m; @@ -89,6 +263,141 @@ namespace RAT } } + real_T maximum(const real_T x[2]) + { + real_T ex; + if ((x[0] < x[1]) || (std::isnan(x[0]) && (!std::isnan(x[1])))) { + ex = x[1]; + } else { + ex = x[0]; + } + + return ex; + } + + void maximum2(const ::coder::array &x, const ::coder::array< + real_T, 1U> &y, ::coder::array &ex) + { + if (x.size(0) == y.size(0)) { + int32_T loop_ub; + ex.set_size(x.size(0)); + loop_ub = x.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + real_T varargin_1; + real_T varargin_2; + varargin_1 = x[i]; + varargin_2 = y[i]; + ex[i] = std::fmax(varargin_1, varargin_2); + } + } else { + expand_max(x, y, ex); + } + } + + void minimum(const ::coder::array &x, real_T *ex, int32_T *idx) + { + int32_T last; + last = x.size(0); + if (x.size(0) <= 2) { + if (x.size(0) == 1) { + *ex = x[0]; + *idx = 1; + } else if ((x[0] > x[x.size(0) - 1]) || (std::isnan(x[0]) && (!std:: + isnan(x[x.size(0) - 1])))) { + *ex = x[x.size(0) - 1]; + *idx = x.size(0); + } else { + *ex = x[0]; + *idx = 1; + } + } else { + int32_T k; + if (!std::isnan(x[0])) { + *idx = 1; + } else { + boolean_T exitg1; + *idx = 0; + k = 2; + exitg1 = false; + while ((!exitg1) && (k <= last)) { + if (!std::isnan(x[k - 1])) { + *idx = k; + exitg1 = true; + } else { + k++; + } + } + } + + if (*idx == 0) { + *ex = x[0]; + *idx = 1; + } else { + int32_T i; + *ex = x[*idx - 1]; + i = *idx + 1; + for (k = i; k <= last; k++) { + real_T d; + d = x[k - 1]; + if (*ex > d) { + *ex = d; + *idx = k; + } + } + } + } + } + + real_T minimum(const real_T x[2]) + { + real_T ex; + if ((x[0] > x[1]) || (std::isnan(x[0]) && (!std::isnan(x[1])))) { + ex = x[1]; + } else { + ex = x[0]; + } + + return ex; + } + + void minimum(const real_T x[50], real_T *ex, int32_T *idx) + { + int32_T k; + if (!std::isnan(x[0])) { + *idx = 1; + } else { + boolean_T exitg1; + *idx = 0; + k = 2; + exitg1 = false; + while ((!exitg1) && (k < 51)) { + if (!std::isnan(x[k - 1])) { + *idx = k; + exitg1 = true; + } else { + k++; + } + } + } + + if (*idx == 0) { + *ex = x[0]; + *idx = 1; + } else { + int32_T i; + *ex = x[*idx - 1]; + i = *idx + 1; + for (k = i; k < 51; k++) { + real_T d; + d = x[k - 1]; + if (*ex > d) { + *ex = d; + *idx = k; + } + } + } + } + void minimum(const ::coder::array &x, real_T ex[2]) { int32_T m; diff --git a/RAT/minOrMax.h b/RAT/minOrMax.h index d6fe0317..149b9b65 100644 --- a/RAT/minOrMax.h +++ b/RAT/minOrMax.h @@ -19,13 +19,24 @@ // Function Declarations namespace RAT { + void c_binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, const ::coder::array &in3); namespace coder { namespace internal { - real_T b_maximum(const real_T x[2]); - real_T maximum(const real_T x_data[]); + real_T b_maximum(const real_T x[3]); + void maximum(const ::coder::array &x, ::coder::array &ex); + real_T maximum(const ::coder::array &x); + real_T maximum(const ::coder::array &x); void maximum(const ::coder::array &x, real_T ex[2]); + real_T maximum(const real_T x[2]); + void maximum2(const ::coder::array &x, const ::coder::array< + real_T, 1U> &y, ::coder::array &ex); + void minimum(const ::coder::array &x, real_T *ex, int32_T *idx); + real_T minimum(const real_T x[2]); + void minimum(const real_T x[50], real_T *ex, int32_T *idx); void minimum(const ::coder::array &x, real_T ex[2]); } } diff --git a/RAT/mod.cpp b/RAT/mod.cpp new file mode 100644 index 00000000..31595d58 --- /dev/null +++ b/RAT/mod.cpp @@ -0,0 +1,56 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mod.cpp +// +// Code generation for function 'mod' +// + +// Include files +#include "mod.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + real_T b_mod(real_T x) + { + real_T r; + if (std::isnan(x) || std::isinf(x)) { + r = rtNaN; + } else if (x == 0.0) { + r = 0.0; + } else { + r = std::fmod(x, 100.0); + if (r == 0.0) { + r = 0.0; + } + } + + return r; + } + + real_T b_mod(real_T x, real_T y) + { + real_T r; + r = x; + if (std::isnan(x) || std::isnan(y) || std::isinf(x)) { + r = rtNaN; + } else if (!std::isinf(y)) { + r = std::fmod(x, y); + if (r == 0.0) { + r = y * 0.0; + } + } + + return r; + } + } +} + +// End of code generation (mod.cpp) diff --git a/RAT/mod.h b/RAT/mod.h new file mode 100644 index 00000000..016dae9b --- /dev/null +++ b/RAT/mod.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mod.h +// +// Code generation for function 'mod' +// +#ifndef MOD_H +#define MOD_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + real_T b_mod(real_T x); + real_T b_mod(real_T x, real_T y); + } +} + +#endif + +// End of code generation (mod.h) diff --git a/RAT/mrdivide_helper.cpp b/RAT/mrdivide_helper.cpp new file mode 100644 index 00000000..31a3ae86 --- /dev/null +++ b/RAT/mrdivide_helper.cpp @@ -0,0 +1,204 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mrdivide_helper.cpp +// +// Code generation for function 'mrdivide_helper' +// + +// Include files +#include "mrdivide_helper.h" +#include "lusolve.h" +#include "qrsolve.h" +#include "rt_nonfinite.h" +#include "xgeqp3.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, int32_T in3, const ::coder::array< + real_T, 2U> &in4, const ::coder::array &in5) + { + ::coder::array b_in2; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in4.size(1) == 1) { + i = in2.size(1); + } else { + i = in4.size(1); + } + + b_in2.set_size(1, i); + stride_0_1 = (in2.size(1) != 1); + stride_1_1 = (in4.size(1) != 1); + if (in4.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in4.size(1); + } + + for (i = 0; i < loop_ub; i++) { + b_in2[b_in2.size(0) * i] = in2[in3 + in2.size(0) * (i * stride_0_1)] - + in4[in4.size(0) * (i * stride_1_1)]; + } + + coder::internal::mrdiv(b_in2, in5, in1); + } + + void c_binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, int32_T in3, const ::coder::array &in4, const :: + coder::array &in5) + { + ::coder::array b_in2; + int32_T aux_0_1; + int32_T aux_1_1; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in4.size(1) == 1) { + i = in2.size(1); + } else { + i = in4.size(1); + } + + b_in2.set_size(in4.size(0), i); + stride_0_1 = (in2.size(1) != 1); + stride_1_1 = (in4.size(1) != 1); + aux_0_1 = 0; + aux_1_1 = 0; + if (in4.size(1) == 1) { + loop_ub = in2.size(1); + } else { + loop_ub = in4.size(1); + } + + for (i = 0; i < loop_ub; i++) { + int32_T b_loop_ub; + b_loop_ub = in4.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + b_in2[b_in2.size(0) * i] = in2[in3 + in2.size(0) * aux_0_1] - + in4[in4.size(0) * aux_1_1]; + } + + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + + coder::internal::mrdiv(b_in2, in5, in1); + } + + namespace coder + { + namespace internal + { + void mrdiv(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &Y) + { + ::coder::array b_A; + ::coder::array c_A; + ::coder::array r; + ::coder::array tau; + ::coder::array jpvt; + if ((A.size(0) == 0) || (A.size(1) == 0) || ((B.size(0) == 0) || (B.size + (1) == 0))) { + int32_T loop_ub; + Y.set_size(A.size(0), B.size(0)); + loop_ub = B.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + int32_T b_loop_ub; + b_loop_ub = A.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + Y[Y.size(0) * i] = 0.0; + } + } + } else if (B.size(0) == B.size(1)) { + lusolve(B, A, Y); + } else { + int32_T b_loop_ub; + int32_T loop_ub; + b_A.set_size(B.size(1), B.size(0)); + loop_ub = B.size(0); + b_loop_ub = B.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + b_A[i1 + b_A.size(0) * i] = B[i + B.size(0) * i1]; + } + } + + lapack::xgeqp3(b_A, tau, jpvt); + c_A.set_size(A.size(1), 1); + loop_ub = A.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + c_A[i] = A[A.size(0) * i]; + } + + LSQFromQR(b_A, tau, jpvt, c_A, rankFromQR(b_A), r); + Y.set_size(r.size(1), r.size(0)); + loop_ub = r.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = r.size(1); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + Y[Y.size(0) * i] = r[i]; + } + } + } + } + + void mrdiv(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &Y) + { + ::coder::array b_A; + ::coder::array r; + ::coder::array b_B; + if ((A.size(0) == 0) || (A.size(1) == 0) || (B.size(1) == 0)) { + int32_T loop_ub; + Y.set_size(A.size(0)); + loop_ub = A.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + Y[i] = 0.0; + } + } else if (B.size(1) == 1) { + int32_T loop_ub; + Y.set_size(A.size(0)); + loop_ub = A.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + Y[i] = A[i] / B[0]; + } + } else { + int32_T b_loop_ub; + int32_T loop_ub; + b_B.set_size(B.size(1)); + loop_ub = B.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_B[i] = B[i]; + } + + b_A.set_size(A.size(1), A.size(0)); + loop_ub = A.size(0); + b_loop_ub = A.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + b_A[i1 + b_A.size(0) * i] = A[i + A.size(0) * i1]; + } + } + + qrsolve(b_B, b_A, r); + Y.set_size(r.size(1)); + loop_ub = r.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + Y[i] = r[i]; + } + } + } + } + } +} + +// End of code generation (mrdivide_helper.cpp) diff --git a/RAT/mrdivide_helper.h b/RAT/mrdivide_helper.h new file mode 100644 index 00000000..bf66ce47 --- /dev/null +++ b/RAT/mrdivide_helper.h @@ -0,0 +1,42 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mrdivide_helper.h +// +// Code generation for function 'mrdivide_helper' +// +#ifndef MRDIVIDE_HELPER_H +#define MRDIVIDE_HELPER_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, int32_T in3, const ::coder::array< + real_T, 2U> &in4, const ::coder::array &in5); + void c_binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in2, int32_T in3, const ::coder::array &in4, const :: + coder::array &in5); + namespace coder + { + namespace internal + { + void mrdiv(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &Y); + void mrdiv(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &Y); + } + } +} + +#endif + +// End of code generation (mrdivide_helper.h) diff --git a/RAT/mtimes.cpp b/RAT/mtimes.cpp new file mode 100644 index 00000000..7be121b4 --- /dev/null +++ b/RAT/mtimes.cpp @@ -0,0 +1,174 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mtimes.cpp +// +// Code generation for function 'mtimes' +// + +// Include files +#include "mtimes.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void b_mtimes(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &C) + { + int32_T inner; + int32_T mc; + int32_T nc; + mc = A.size(1) - 1; + inner = A.size(0); + nc = B.size(1); + C.set_size(A.size(1), B.size(1)); + for (int32_T j{0}; j < nc; j++) { + for (int32_T i{0}; i <= mc; i++) { + C[i + C.size(0) * j] = 0.0; + } + + for (int32_T k{0}; k < inner; k++) { + real_T bkj; + bkj = B[k + B.size(0) * j]; + for (int32_T i{0}; i <= mc; i++) { + C[i + C.size(0) * j] = C[i + C.size(0) * j] + A[k + A.size(0) * + i] * bkj; + } + } + } + } + + void mtimes(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, real_T C_data[], int32_T C_size[2]) + { + int32_T inner; + int32_T mc; + int32_T nc; + mc = A.size(0) - 1; + inner = A.size(1); + nc = B.size(0); + C_size[0] = A.size(0); + C_size[1] = B.size(0); + for (int32_T j{0}; j < nc; j++) { + if (mc >= 0) { + C_data[0] = 0.0; + } + + for (int32_T k{0}; k < inner; k++) { + real_T bkj; + bkj = B[B.size(0) * k]; + for (int32_T i{0}; i <= mc; i++) { + C_data[0] += A[A.size(0) * k] * bkj; + } + } + } + } + + void mtimes(const real_T A_data[], const int32_T A_size[2], const real_T + B_data[], const int32_T B_size[2], real_T C_data[], int32_T + C_size[2]) + { + int32_T inner; + int32_T mc; + int32_T nc; + mc = A_size[0] - 1; + inner = A_size[1]; + nc = B_size[1]; + C_size[0] = A_size[0]; + C_size[1] = B_size[1]; + for (int32_T j{0}; j < nc; j++) { + if (mc >= 0) { + C_data[0] = 0.0; + } + + for (int32_T k{0}; k < inner; k++) { + real_T bkj; + bkj = B_data[0]; + for (int32_T i{0}; i <= mc; i++) { + C_data[0] += A_data[0] * bkj; + } + } + } + } + + void mtimes(const ::coder::array &A, const ::coder::array< + creal_T, 2U> &B, ::coder::array &C) + { + int32_T inner; + int32_T n; + inner = A.size(1); + n = B.size(0); + C.set_size(1, B.size(0)); + for (int32_T j{0}; j < n; j++) { + real_T s_im; + real_T s_re; + s_re = 0.0; + s_im = 0.0; + for (int32_T k{0}; k < inner; k++) { + real_T A_re_tmp; + real_T B_im; + real_T B_re; + real_T b_A_re_tmp; + B_re = B[j + B.size(0) * k].re; + B_im = -B[j + B.size(0) * k].im; + A_re_tmp = A[k].re; + b_A_re_tmp = A[k].im; + s_re += A_re_tmp * B_re - b_A_re_tmp * B_im; + s_im += A_re_tmp * B_im + b_A_re_tmp * B_re; + } + + C[j].re = s_re; + C[j].im = s_im; + } + } + + void mtimes(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &C) + { + int32_T inner; + int32_T nc; + inner = A.size(1); + nc = B.size(0); + C.set_size(1, B.size(0)); + for (int32_T j{0}; j < nc; j++) { + C[j] = 0.0; + for (int32_T k{0}; k < inner; k++) { + C[j] = C[j] + A[k] * B[j + B.size(0) * k]; + } + } + } + + void mtimes(const ::coder::array &A, const ::coder::array< + real_T, 1U> &B, ::coder::array &C) + { + int32_T inner; + int32_T mc; + mc = A.size(0) - 1; + inner = A.size(1); + C.set_size(A.size(0)); + for (int32_T i{0}; i <= mc; i++) { + C[i] = 0.0; + } + + for (int32_T k{0}; k < inner; k++) { + for (int32_T i{0}; i <= mc; i++) { + C[i] = C[i] + A[i + A.size(0) * k] * B[k]; + } + } + } + } + } + } +} + +// End of code generation (mtimes.cpp) diff --git a/RAT/mtimes.h b/RAT/mtimes.h new file mode 100644 index 00000000..d856edb1 --- /dev/null +++ b/RAT/mtimes.h @@ -0,0 +1,48 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// mtimes.h +// +// Code generation for function 'mtimes' +// +#ifndef MTIMES_H +#define MTIMES_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void b_mtimes(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &C); + void mtimes(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, real_T C_data[], int32_T C_size[2]); + void mtimes(const real_T A_data[], const int32_T A_size[2], const real_T + B_data[], const int32_T B_size[2], real_T C_data[], int32_T + C_size[2]); + void mtimes(const ::coder::array &A, const ::coder::array< + creal_T, 2U> &B, ::coder::array &C); + void mtimes(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &C); + void mtimes(const ::coder::array &A, const ::coder::array< + real_T, 1U> &B, ::coder::array &C); + } + } + } +} + +#endif + +// End of code generation (mtimes.h) diff --git a/RAT/multrnd.cpp b/RAT/multrnd.cpp new file mode 100644 index 00000000..bb42fb11 --- /dev/null +++ b/RAT/multrnd.cpp @@ -0,0 +1,200 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// multrnd.cpp +// +// Code generation for function 'multrnd' +// + +// Include files +#include "multrnd.h" +#include "combineVectorElements.h" +#include "rand.h" +#include "rt_nonfinite.h" +#include "sum.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const real_T in3_data[], int32_T in4); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const real_T in3_data[], int32_T in4) + { + ::coder::array b_in1; + real_T in3; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + in3 = in3_data[in4]; + if (in2.size(1) == 1) { + i = in1.size(1); + } else { + i = in2.size(1); + } + + b_in1.set_size(1, i); + stride_0_1 = (in1.size(1) != 1); + stride_1_1 = (in2.size(1) != 1); + if (in2.size(1) == 1) { + loop_ub = in1.size(1); + } else { + loop_ub = in2.size(1); + } + + for (i = 0; i < loop_ub; i++) { + b_in1[i] = in1[i * stride_0_1] + static_cast(in2[i * stride_1_1] > + in3); + } + + in1.set_size(1, b_in1.size(1)); + loop_ub = b_in1.size(1); + for (i = 0; i < loop_ub; i++) { + in1[i] = b_in1[i]; + } + } + + void multrnd(real_T n, const real_T p_data[], const int32_T p_size[2], real_T + X_data[], int32_T X_size[2]) + { + ::coder::array b_p_data; + ::coder::array o; + ::coder::array r; + ::coder::array b_o; + real_T s_data[3]; + real_T P; + int32_T loop_ub_tmp; + + // MULTRND Multinomial random sequence of m simulations of k outcomes with p probabiltites + // in n trials. + // Y = MULTRND(N,P,M) generates a random sequence of m simulations of k integers from a + // multinomial distribution with n trials and k outcomes, where the probability for each + // simulation is, + // n! + // ---------------------- × p1^n1 × p2^n2 × . . . × pk^nk . + // n1! × n2! × . . . × nk! + // + // Then, a single sample {n1, n2, . . . , nk} have a multinomial joint distribution with + // parameters n and p1, p2, . . . , pk. The parameter n is called the number of trials; + // the parameters p1, p2, . . . , pk are called the category probabilities; k is called + // the number of categories. + // + // Syntax: function [X,Y] = multrnd(n,p,m) + // + // Inputs: + // n - number of trials. + // p - vector of associated probabilities. + // m - number of simulations (default = 1). + // Outputs: + // X - multinomial random deviates (default). + // Y - multinomial probabilities of the generated random deviates (optional). + // + // Example. We are interested to get a multinomial random values of 4 outcomes with + // associated probabilities p=[0.1 0.06 .7 .14] with 2678 trials in 10 simulations. + // + // Calling on Matlab the function: + // [X Y] = multrnd(n,p,m) + // + // where n = 2678, p = [0.1 0.06 .7 .14] and m = 10 + // + // Answer is: + // + // X = + // 271 152 1873 382 + // 249 154 1890 385 + // 266 172 1862 378 + // 290 147 1882 359 + // 247 153 1873 405 + // 291 155 1842 390 + // 268 141 1900 369 + // 248 158 1899 373 + // 267 181 1855 375 + // 259 175 1884 360 + // + // Y = + // 0.1012 0.0568 0.6994 0.1426 + // 0.0930 0.0575 0.7058 0.1438 + // 0.0993 0.0642 0.6953 0.1412 + // 0.1083 0.0549 0.7028 0.1341 + // 0.0922 0.0571 0.6994 0.1512 + // 0.1087 0.0579 0.6878 0.1456 + // 0.1001 0.0527 0.7095 0.1378 + // 0.0926 0.0590 0.7091 0.1393 + // 0.0997 0.0676 0.6927 0.1400 + // 0.0967 0.0653 0.7035 0.1344 + // + // Created by A. Trujillo-Ortiz, R. Hernandez-Walls and A. Castro-Perez + // Facultad de Ciencias Marinas + // Universidad Autonoma de Baja California + // Apdo. Postal 453 + // Ensenada, Baja California + // Mexico. + // atrujo@uabc.mx + // Copyright (C) January 12, 2005. + // + // To cite this file, this would be an appropriate format: + // Trujillo-Ortiz, A., R. Hernandez-Walls and A. Castro-Perez. (2005). multrnd: + // Multinomial random sequence. A MATLAB file. [WWW document]. URL http:// + // www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=6788 + // + // References: + // + // Abramowitz, M. and Stegun,I. A. (1964), Handbook of Mathematical + // Functions, Government Printing Office, 26.1.20. Available on + // Internet at the URL address http://hcohl.shell42.com/as/frameindex.htm + // + b_p_data.set((real_T *)&p_data[0], p_size[0], p_size[1]); + P = coder::sum(b_p_data); + + // if P ~= 1, + // error('The sum of the input probabilities must be equal 1.') + // return, + // end; + loop_ub_tmp = static_cast(n); + o.set_size(1, loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + o[i] = 1.0; + } + + s_data[0] = p_data[0] / P; + s_data[1] = p_data[1] / P; + s_data[2] = p_data[2] / P; + s_data[1] += s_data[0]; + s_data[2] += s_data[1]; + coder::b_rand(n, r); + for (int32_T j{0}; j < 3; j++) { + loop_ub_tmp = o.size(1); + if (o.size(1) == r.size(1)) { + o.set_size(1, o.size(1)); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + o[i] = o[i] + static_cast(r[i] > s_data[j]); + } + } else { + binary_expand_op(o, r, s_data, j); + } + } + + X_size[0] = 1; + X_size[1] = 3; + loop_ub_tmp = o.size(1); + for (int32_T j{0}; j < 3; j++) { + b_o.set_size(1, o.size(1)); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + b_o[i] = (o[i] == static_cast(j) + 1.0); + } + + X_data[j] = coder::combineVectorElements(b_o); + } + } +} + +// End of code generation (multrnd.cpp) diff --git a/RAT/multrnd.h b/RAT/multrnd.h new file mode 100644 index 00000000..43dc78a2 --- /dev/null +++ b/RAT/multrnd.h @@ -0,0 +1,27 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// multrnd.h +// +// Code generation for function 'multrnd' +// +#ifndef MULTRND_H +#define MULTRND_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void multrnd(real_T n, const real_T p_data[], const int32_T p_size[2], real_T + X_data[], int32_T X_size[2]); +} + +#endif + +// End of code generation (multrnd.h) diff --git a/RAT/nest2pos.cpp b/RAT/nest2pos.cpp new file mode 100644 index 00000000..3713cf8a --- /dev/null +++ b/RAT/nest2pos.cpp @@ -0,0 +1,246 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// nest2pos.cpp +// +// Code generation for function 'nest2pos' +// + +// Include files +#include "nest2pos.h" +#include "find.h" +#include "minOrMax.h" +#include "rand.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const int32_T + in4[2], real_T in5, real_T in6); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const int32_T + in4[2], real_T in5, real_T in6) + { + ::coder::array c_in2; + int32_T b_in2; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + b_in2 = in2.size(1); + in1.set_size(static_cast(in5) + in4[1]); + loop_ub = in4[1]; + for (i = 0; i < loop_ub; i++) { + in1[i] = -in3[i] / in5; + } + + loop_ub = static_cast(in5); + for (i = 0; i < loop_ub; i++) { + in1[i + in4[1]] = -in6 / in5; + } + + if (in1.size(0) == 1) { + i = in2.size(0); + } else { + i = in1.size(0); + } + + c_in2.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in1.size(0) != 1); + if (in1.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in1.size(0); + } + + for (i = 0; i < loop_ub; i++) { + c_in2[i] = in2[i * stride_0_0 + in2.size(0) * (b_in2 - 1)] + in1[i * + stride_1_0]; + } + + in1.set_size(c_in2.size(0)); + loop_ub = c_in2.size(0); + for (i = 0; i < loop_ub; i++) { + in1[i] = c_in2[i]; + } + } + + void nest2pos(const ::coder::array &nest_samples, real_T Nlive, :: + coder::array &post_samples) + { + ::coder::array b_nest_samples; + ::coder::array y; + ::coder::array b_y; + ::coder::array logWt; + ::coder::array idx; + ::coder::array b_logWt; + real_T b; + real_T logWtmax; + int32_T sizes[2]; + int32_T i; + int32_T k; + int32_T result; + int8_T input_sizes_idx_1; + boolean_T empty_non_axis_sizes; + + // + // post_samples = nest2pos(nest_samples, Nlive) + // + // Convert nested samples with Nlive livepoints + // to samples from the posterior distribution + // (logL values in last column of nest_samples) + // + // John Veitch 2009 (modified by J. Romano 2012) + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // calculate logWt = log(L*w) = logL + logw = logL - i/Nlive + b = static_cast(nest_samples.size(0)) - Nlive; + if (std::isnan(b)) { + sizes[0] = 1; + sizes[1] = 1; + } else if (b < 1.0) { + sizes[0] = 1; + sizes[1] = 0; + } else { + sizes[0] = 1; + sizes[1] = static_cast(b - 1.0) + 1; + } + + b = static_cast(nest_samples.size(0)) - Nlive; + if (std::isnan(b)) { + y.set_size(1, 1); + y[0] = rtNaN; + } else if (b < 1.0) { + y.set_size(1, 0); + } else { + y.set_size(1, static_cast(b - 1.0) + 1); + k = static_cast(b - 1.0); + for (i = 0; i <= k; i++) { + y[i] = static_cast(i) + 1.0; + } + } + + b = static_cast(nest_samples.size(0)) - Nlive; + i = static_cast(Nlive) + sizes[1]; + if (nest_samples.size(0) == i) { + b_y.set_size(i); + k = sizes[1]; + for (i = 0; i < k; i++) { + b_y[i] = -y[i] / Nlive; + } + + k = static_cast(Nlive); + for (i = 0; i < k; i++) { + b_y[i + sizes[1]] = -b / Nlive; + } + + logWt.set_size(nest_samples.size(0)); + k = nest_samples.size(0); + for (i = 0; i < k; i++) { + logWt[i] = nest_samples[i + nest_samples.size(0) * (nest_samples.size(1) + - 1)] + b_y[i]; + } + } else { + binary_expand_op(logWt, nest_samples, y, sizes, Nlive, b); + } + + // posterior samples are given by the normalized weight + logWtmax = coder::internal::maximum(logWt); + k = logWt.size(0); + for (i = 0; i < k; i++) { + logWt[i] = logWt[i] - logWtmax; + } + + // Wt -> Wt/Wtmax + // accept a nested sample as a posterior sample only if its + // value is > than a random number drawn from a unif distribution + coder::b_rand(static_cast(nest_samples.size(0)), b_y); + i = b_y.size(0); + for (k = 0; k < i; k++) { + b_y[k] = std::log(b_y[k]); + } + + if (logWt.size(0) == b_y.size(0)) { + b_logWt.set_size(logWt.size(0)); + k = logWt.size(0); + for (i = 0; i < k; i++) { + b_logWt[i] = (logWt[i] > b_y[i]); + } + + coder::eml_find(b_logWt, idx); + } else { + binary_expand_op(idx, logWt, b_y); + } + + // attach log of posterior probabilities as final column of + // the posterior samples + // post_samples(:,Ncol+1) = logWt(idx); + if ((idx.size(0) != 0) && (nest_samples.size(1) != 0)) { + result = idx.size(0); + } else if (idx.size(0) != 0) { + result = idx.size(0); + } else { + result = 0; + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || ((idx.size(0) != 0) && (nest_samples.size(1) != + 0))) { + input_sizes_idx_1 = static_cast(nest_samples.size(1)); + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || (idx.size(0) != 0)) { + sizes[1] = 1; + } else { + sizes[1] = 0; + } + + b_nest_samples.set_size(idx.size(0), nest_samples.size(1)); + k = nest_samples.size(1); + for (i = 0; i < k; i++) { + int32_T loop_ub; + loop_ub = idx.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_nest_samples[i1 + b_nest_samples.size(0) * i] = nest_samples[(idx[i1] + + nest_samples.size(0) * i) - 1]; + } + } + + b_y.set_size(idx.size(0)); + k = idx.size(0); + for (i = 0; i < k; i++) { + b_y[i] = logWt[idx[i] - 1]; + } + + post_samples.set_size(result, input_sizes_idx_1 + sizes[1]); + k = input_sizes_idx_1; + for (i = 0; i < k; i++) { + for (int32_T i1{0}; i1 < result; i1++) { + post_samples[i1 + post_samples.size(0) * i] = b_nest_samples[i1 + result + * i]; + } + } + + k = sizes[1]; + for (i = 0; i < k; i++) { + for (int32_T i1{0}; i1 < result; i1++) { + post_samples[i1 + post_samples.size(0) * input_sizes_idx_1] = b_y[i1]; + } + } + } +} + +// End of code generation (nest2pos.cpp) diff --git a/RAT/nest2pos.h b/RAT/nest2pos.h new file mode 100644 index 00000000..20b37c1a --- /dev/null +++ b/RAT/nest2pos.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// nest2pos.h +// +// Code generation for function 'nest2pos' +// +#ifndef NEST2POS_H +#define NEST2POS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void nest2pos(const ::coder::array &nest_samples, real_T Nlive, :: + coder::array &post_samples); +} + +#endif + +// End of code generation (nest2pos.h) diff --git a/RAT/nestedSampler.cpp b/RAT/nestedSampler.cpp new file mode 100644 index 00000000..92b74b32 --- /dev/null +++ b/RAT/nestedSampler.cpp @@ -0,0 +1,687 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// nestedSampler.cpp +// +// Code generation for function 'nestedSampler' +// + +// Include files +#include "nestedSampler.h" +#include "RATMain_data.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "cov.h" +#include "drawMCMC.h" +#include "drawMultiNest.h" +#include "ifWhileCond.h" +#include "length.h" +#include "logPlus.h" +#include "mchol.h" +#include "minOrMax.h" +#include "mod.h" +#include "mrdivide_helper.h" +#include "mtimes.h" +#include "nest2pos.h" +#include "nonSingletonDim.h" +#include "nsIntraFun.h" +#include "optimalEllipsoids.h" +#include "rand.h" +#include "randn.h" +#include "rescaleParameters.h" +#include "rt_nonfinite.h" +#include "scaleParameters.h" +#include "sort.h" +#include "sqrt1.h" +#include "sum.h" +#include "useConstantDim.h" +#include "coder_array.h" +#include +#include + +// Function Definitions +namespace RAT +{ + void nestedSampler(const struct5_T *data_f1, const struct2_T *data_f2, const + cell_14 *data_f4, real_T Nlive, real_T Nmcmc, real_T + tolerance, const ::coder::array &prior, real_T * + logZ, ::coder::array &nest_samples, ::coder:: + array &post_samples, real_T *H) + { + ::coder::array Bs; + ::coder::array FS; + ::coder::array VEs; + ::coder::array Vtot; + ::coder::array b_Bs; + ::coder::array b_livepoints; + ::coder::array b_nest_samples; + ::coder::array b_nest_samples_data; + ::coder::array cholmat; + ::coder::array l; + ::coder::array livepoints; + ::coder::array livepoints_sorted; + ::coder::array mus; + ::coder::array ns; + ::coder::array r; + ::coder::array result; + ::coder::array toAdd; + ::coder::array b; + ::coder::array logL; + ::coder::array iidx; + ::coder::array b_FS; + real_T nest_samples_data[49]; + real_T b_dv[2]; + real_T a; + real_T a_tmp; + real_T d; + real_T j; + real_T logLmax; + real_T logLmin; + real_T logw; + real_T tol; + real_T varargin_2; + int32_T D; + int32_T K; + int32_T i; + int32_T i1; + int32_T i2; + int32_T iindx; + int32_T input_sizes_idx_1; + int32_T loop_ub_tmp; + int32_T sizes_idx_1; + boolean_T empty_non_axis_sizes; + + // function [logZ, nest_samples, post_samples] = nestedSampler(data, ... + // Nlive, Nmcmc, tolerance, likelihood, model, prior, extraparams) + // + // This function performs nested sampling of the likelihood function from + // the given prior (given a set of data, a model, and a set of extra model + // parameters). + // + // If Nmcmc > 0, new samples will be drawn from a proposal using an MCMC + // and differential evolution. The sampling will stop once the + // tolerance critereon has been reached. This method is that of Veitch & + // Vecchio. + // + // If Nmcmc = 0, new samples will be drawn from a set of bounding ellipsoids + // constructed using the MultiNest algorithm for partitioning live points. + // + // The likelihood should be the function handle of a likelihood function to + // use. This should return the log likelihood of the model parameters given + // the data. + // + // The model should be the function handle of the model function to be + // passed to the likelihood function. + // + // ------------------- STRUCTURE OF PRIOR CHANGED FOR RAT ---------------- + // The prior should be a cell array with each cell containing five values: + // parameter name (string) + // prior type (string) e.g. 'uniform', 'gaussian' of 'jeffreys' + // minimum value (for uniform prior), or mean value (for Gaussian prior) + // maximum value (for uniform prior), or width (for Gaussian prior) + // parameter behaviour (string): + // 'reflect' - if the parameters reflect off the boundaries + // 'cyclic' - if the parameter space is cyclic + // 'fixed' - if the parameters have fixe boundaries + // '' - for gaussian priors + // e.g., prior = {'h0', 'uniform', 0, 1, 'reflect'; + // 'r', 'gaussian', 0, 5, ''; + // 'phi', 'uniform', 0, 2*pi, 'cyclic'}; + // + // ----------------------------------------------------------------------- + // + // extraparams is a cell array of fixed extra parameters (in addition + // to those specified by prior) used by the model + // e.g. extraparams = {'phi', 2; + // 'x', 4}; + // + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + verbose = 1.0; + DEBUG = 0.0; + + // get the number of parameters from the prior array + ns.set_size(1, 1); + ns[0] = 1.0; + + // coder.varsize('ns'); + mus.set_size(1, 1); + mus[0] = 1.0; + + // coder.varsize('mus'); + cholmat.set_size(1, 1); + cholmat[0] = 1.0; + + // get the number of parameters from the prior array + D = prior.size(0); + + // initialize array of samples for posterior + nest_samples.set_size(1, prior.size(0) + 1); + sizes_idx_1 = prior.size(0) + 1; + for (i = 0; i < sizes_idx_1; i++) { + nest_samples[nest_samples.size(0) * i] = 0.0; + } + + // draw the set of initial live points from the prior + loop_ub_tmp = static_cast(Nlive); + livepoints.set_size(loop_ub_tmp, prior.size(0)); + sizes_idx_1 = prior.size(0); + for (i = 0; i < sizes_idx_1; i++) { + for (i1 = 0; i1 < loop_ub_tmp; i1++) { + livepoints[i1 + livepoints.size(0) * i] = 0.0; + } + } + + i = prior.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T priortype; + priortype = prior[b_i]; + if (priortype == 1.0) { + real_T p3; + + // uniform + p3 = prior[b_i + prior.size(0) * 3]; + a = prior[b_i + prior.size(0) * 4] - p3; + coder::b_rand(Nlive, b); + sizes_idx_1 = b.size(0); + for (i1 = 0; i1 < sizes_idx_1; i1++) { + livepoints[i1 + livepoints.size(0) * b_i] = p3 + a * b[i1]; + } + } else if (priortype == 2.0) { + real_T p3; + + // gaussian + p3 = prior[b_i + prior.size(0)]; + a = prior[b_i + prior.size(0) * 2]; + coder::randn(Nlive, b); + sizes_idx_1 = b.size(0); + for (i1 = 0; i1 < sizes_idx_1; i1++) { + livepoints[i1 + livepoints.size(0) * b_i] = p3 + a * b[i1]; + } + } else if (priortype == 3.0) { + // jeffreys + a_tmp = std::log10(prior[b_i + prior.size(0)]); + a = std::log10(prior[b_i + prior.size(0) * 2]) - a_tmp; + coder::b_rand(Nlive, b); + sizes_idx_1 = b.size(0); + for (i1 = 0; i1 < sizes_idx_1; i1++) { + varargin_2 = a_tmp + a * b[i1]; + livepoints[i1 + livepoints.size(0) * b_i] = rt_powd_snf(10.0, + varargin_2); + } + } + } + + // calculate the log likelihood of all the live points + logL.set_size(loop_ub_tmp); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + // parvals = loopCell(livepoints(i,:)); + sizes_idx_1 = livepoints.size(1); + b_livepoints.set_size(1, livepoints.size(1)); + for (i = 0; i < sizes_idx_1; i++) { + b_livepoints[i] = livepoints[b_i + livepoints.size(0) * i]; + } + + logL[b_i] = nsIntraFun(data_f1, data_f2, data_f4, b_livepoints); + } + + // now scale the parameters, so that uniform parameters range from 0->1, + // and Gaussian parameters have a mean of zero and unit standard deviation + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + sizes_idx_1 = livepoints.size(1); + b_livepoints.set_size(1, livepoints.size(1)); + for (i = 0; i < sizes_idx_1; i++) { + b_livepoints[i] = livepoints[b_i + livepoints.size(0) * i]; + } + + scaleParameters(prior, b_livepoints, b); + sizes_idx_1 = livepoints.size(1); + for (i = 0; i < sizes_idx_1; i++) { + livepoints[b_i + livepoints.size(0) * i] = b[i]; + } + } + + // initial tolerance + tol = rtInf; + + // initial width of prior volume (from X_0=1 to X_1=exp(-1/N)) + logw = std::log(1.0 - std::exp(-1.0 / Nlive)); + + // initial log evidence (Z=0) + *logZ = rtMinusInf; + + // initial information + *H = 0.0; + + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // some initial values if MCMC nested sampling is used + // value to scale down the covariance matrix - CAN CHANGE THIS IF REQUIRED + // %%%%%%%%%%%%%% + // some initial values if MultiNest sampling is used + // h values from bottom of p. 1605 of Feroz and Hobson + FS.set_size(1, 1); + FS[0] = 1.1; + + // start FS at h, so ellipsoidal partitioning is done first time + K = 1; + + // start with one cluster of live points + // get maximum likelihood + logLmax = coder::internal::maximum(logL); + Bs.set_size(prior.size(0), prior.size(0)); + sizes_idx_1 = prior.size(0); + for (i = 0; i < sizes_idx_1; i++) { + input_sizes_idx_1 = prior.size(0); + for (i1 = 0; i1 < input_sizes_idx_1; i1++) { + Bs[i1 + Bs.size(0) * i] = 0.0; + } + } + + VEs.set_size(prior.size(0), 1); + sizes_idx_1 = prior.size(0); + for (i = 0; i < sizes_idx_1; i++) { + VEs[i] = 0.0; + } + + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // initialize iteration counter + j = 1.0; + + // MAIN LOOP + while ((tol > tolerance) || (j <= Nlive)) { + real_T VS; + real_T logWt; + real_T logZold; + + // expected value of true remaining prior volume X + VS = std::exp(-j / Nlive); + + // find minimum of likelihoods + coder::internal::minimum(logL, &logLmin, &iindx); + + // set the sample to the minimum value + // (Need to do some work brcause we are growing nest_samples in a loop) + if (j == 1.0) { + sizes_idx_1 = livepoints.size(1); + for (i = 0; i < sizes_idx_1; i++) { + nest_samples[nest_samples.size(0) * i] = livepoints[(iindx + + livepoints.size(0) * i) - 1]; + } + + nest_samples[nest_samples.size(0) * livepoints.size(1)] = logLmin; + } else { + toAdd.set_size(1, livepoints.size(1) + 1); + sizes_idx_1 = livepoints.size(1); + for (i = 0; i < sizes_idx_1; i++) { + toAdd[i] = livepoints[(iindx + livepoints.size(0) * i) - 1]; + } + + toAdd[livepoints.size(1)] = logLmin; + if (nest_samples.size(1) != 0) { + input_sizes_idx_1 = nest_samples.size(1); + } else { + input_sizes_idx_1 = toAdd.size(1); + } + + if (nest_samples.size(1) != 0) { + sizes_idx_1 = nest_samples.size(0); + } else { + sizes_idx_1 = 0; + } + + if (nest_samples.size(1) != 0) { + i = nest_samples.size(0); + } else { + i = 0; + } + + b_nest_samples.set_size(i + 1, input_sizes_idx_1); + for (i = 0; i < input_sizes_idx_1; i++) { + for (i1 = 0; i1 < sizes_idx_1; i1++) { + b_nest_samples[i1 + b_nest_samples.size(0) * i] = nest_samples[i1 + + sizes_idx_1 * i]; + } + } + + for (i = 0; i < input_sizes_idx_1; i++) { + b_nest_samples[sizes_idx_1 + b_nest_samples.size(0) * i] = toAdd[i]; + } + + nest_samples.set_size(b_nest_samples.size(0), b_nest_samples.size(1)); + sizes_idx_1 = b_nest_samples.size(1); + for (i = 0; i < sizes_idx_1; i++) { + input_sizes_idx_1 = b_nest_samples.size(0); + for (i1 = 0; i1 < input_sizes_idx_1; i1++) { + nest_samples[i1 + nest_samples.size(0) * i] = b_nest_samples[i1 + + b_nest_samples.size(0) * i]; + } + } + } + + // get the log weight (Wt = L*w) + logWt = logLmin + logw; + + // save old evidence and information + logZold = *logZ; + + // update evidence, information, and width + *logZ = logPlus(*logZ, logWt); + if (std::isnan(*H)) { + a = 0.0; + } else { + a = *H; + } + + *H = (std::exp(logWt - *logZ) * logLmin + std::exp(logZold - *logZ) * (a + + logZold)) - *logZ; + + // logw = logw - logt(Nlive); + logw -= 1.0 / Nlive; + + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + if (Nmcmc > 0.0) { + // do MCMC nested sampling + // get the Cholesky decomposed covariance of the live points + // (do every 100th iteration - CAN CHANGE THIS IF REQUIRED) + if (coder::b_mod(j - 1.0) == 0.0) { + // NOTE that for numbers of parameters >~10 covariances are often + // not positive definite and cholcov will have "problems". + // cholmat = cholcov(propscale*cov(livepoints)); + // use modified Cholesky decomposition, which works even for + // matrices that are not quite positive definite + // from http://infohost.nmt.edu/~borchers/ldlt.html + // (via http://stats.stackexchange.com/questions/6364 + // /making-square-root-of-covariance-matrix-positive-definite-matlab + coder::cov(livepoints, result); + b_Bs.set_size(result.size(0), result.size(1)); + sizes_idx_1 = result.size(1); + for (i = 0; i < sizes_idx_1; i++) { + input_sizes_idx_1 = result.size(0); + for (i1 = 0; i1 < input_sizes_idx_1; i1++) { + b_Bs[i1 + b_Bs.size(0) * i] = 0.1 * result[i1 + result.size(0) * i]; + } + } + + mchol(b_Bs, l, result); + coder::b_sqrt(result); + coder::internal::blas::b_mtimes(l, result, cholmat); + + // plot3(livepoints(:,1), livepoints(:,2), livepoints(:,3), 'r.'); + // drawnow(); + } + + // draw a new sample using mcmc algorithm + drawMCMC(livepoints, cholmat, logLmin, prior, data_f1, data_f2, data_f4, + Nmcmc, b_livepoints, &logL[iindx - 1]); + sizes_idx_1 = b_livepoints.size(1); + for (i = 0; i < sizes_idx_1; i++) { + livepoints[(iindx + livepoints.size(0) * i) - 1] = b_livepoints[i]; + } + } else { + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // do MultiNest nested sampling + // separate out ellipsoids + b_FS.set_size(1, FS.size(1)); + sizes_idx_1 = FS.size(1); + for (i = 0; i < sizes_idx_1; i++) { + b_FS[b_FS.size(0) * i] = (FS[i] >= 1.1); + } + + if (coder::internal::ifWhileCond(b_FS)) { + // NOTE: THIS CODE IS GUARANTEED TO RUN THE 1ST TIME THROUGH + // calculate optimal ellipsoids + optimalEllipsoids(livepoints, VS, Bs, mus, VEs, ns); + K = coder::internal::intlength(VEs.size(0), VEs.size(1)); + + // number of ellipsoids (subclusters) + } else { + // simply rescale the bounding ellipsoids + if (K - 1 >= 0) { + d = std::exp(-(j + 1.0) / Nlive); + b_dv[0] = 1.0; + } + + for (int32_T k{0}; k < K; k++) { + real_T scalefac; + b_dv[1] = d * ns[k] / Nlive / VEs[k]; + scalefac = coder::internal::maximum(b_dv); + + // scale bounding matrix and volume + if (scalefac != 1.0) { + a_tmp = ((static_cast(k) + 1.0) - 1.0) * + static_cast(D) + 1.0; + varargin_2 = (static_cast(k) + 1.0) * static_cast + (D); + if (a_tmp > varargin_2) { + i = 0; + i1 = 0; + i2 = 1; + } else { + i = static_cast(a_tmp) - 1; + i1 = static_cast(varargin_2); + i2 = static_cast(a_tmp); + } + + a_tmp = rt_powd_snf(scalefac, 2.0 / static_cast(D)); + sizes_idx_1 = i1 - i; + input_sizes_idx_1 = Bs.size(1); + b_Bs.set_size(sizes_idx_1, Bs.size(1)); + for (i1 = 0; i1 < input_sizes_idx_1; i1++) { + for (int32_T i3{0}; i3 < sizes_idx_1; i3++) { + b_Bs[i3 + b_Bs.size(0) * i1] = Bs[(i + i3) + Bs.size(0) * i1] * + a_tmp; + } + } + + sizes_idx_1 = b_Bs.size(1); + for (i = 0; i < sizes_idx_1; i++) { + input_sizes_idx_1 = b_Bs.size(0); + for (i1 = 0; i1 < input_sizes_idx_1; i1++) { + Bs[((i2 + i1) + Bs.size(0) * i) - 1] = b_Bs[i1 + b_Bs.size(0) * + i]; + } + } + + VEs[k] = scalefac * VEs[k]; + } + } + } + + // calculate ratio of volumes (FS>=1) and cumulative fractional volume + coder::sum(VEs, Vtot); + FS.set_size(1, Vtot.size(1)); + sizes_idx_1 = Vtot.size(1); + for (i = 0; i < sizes_idx_1; i++) { + FS[i] = Vtot[i] / VS; + } + + // draw a new sample using multinest algorithm + result.set_size(VEs.size(0), VEs.size(1)); + sizes_idx_1 = VEs.size(1); + for (i = 0; i < sizes_idx_1; i++) { + input_sizes_idx_1 = VEs.size(0); + for (i1 = 0; i1 < input_sizes_idx_1; i1++) { + result[i1 + result.size(0) * i] = VEs[i1 + VEs.size(0) * i]; + } + } + + coder::internal::useConstantDim(result, coder::internal::nonSingletonDim + (VEs)); + coder::internal::mrdiv(result, Vtot, b); + drawMultiNest(b, Bs, mus, logLmin, prior, data_f1, data_f2, data_f4, r, + &logL[iindx - 1]); + sizes_idx_1 = r.size(1); + for (i = 0; i < sizes_idx_1; i++) { + input_sizes_idx_1 = r.size(0); + for (i1 = 0; i1 < input_sizes_idx_1; i1++) { + livepoints[(iindx + livepoints.size(0) * i) - 1] = r[r.size(0) * i]; + } + } + } + + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // update maximum likelihood if appropriate + a_tmp = logL[iindx - 1]; + if (a_tmp > logLmax) { + logLmax = a_tmp; + } + + // work out tolerance for stopping criterion + tol = logPlus(*logZ, logLmax - j / Nlive) - *logZ; + + // display progress (optional) + if (verbose != 0.0) { + if (j < 2.147483648E+9) { + i = static_cast(j); + } else { + i = MAX_int32_T; + } + + printf("log(Z): %.5e, tol = %.5e, K = %d, iteration = %d, H = %.5e\n", + *logZ, tol, K, i, *H); + fflush(stdout); + } + + // update counter + j++; + } + + // sort the remaining points (in order of likelihood) and add them on to + // the evidence + coder::internal::sort(logL, iidx); + livepoints_sorted.set_size(iidx.size(0), livepoints.size(1)); + sizes_idx_1 = livepoints.size(1); + for (i = 0; i < sizes_idx_1; i++) { + input_sizes_idx_1 = iidx.size(0); + for (i1 = 0; i1 < input_sizes_idx_1; i1++) { + livepoints_sorted[i1 + livepoints_sorted.size(0) * i] = livepoints + [(iidx[i1] + livepoints.size(0) * i) - 1]; + } + } + + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + *logZ = logPlus(*logZ, logL[b_i] + logw); + } + + // append the additional livepoints to the nested samples + if ((iidx.size(0) != 0) && (livepoints.size(1) != 0)) { + iindx = iidx.size(0); + } else if (logL.size(0) != 0) { + iindx = logL.size(0); + } else { + iindx = iidx.size(0); + } + + empty_non_axis_sizes = (iindx == 0); + if (empty_non_axis_sizes || ((iidx.size(0) != 0) && (livepoints.size(1) != 0))) + { + input_sizes_idx_1 = livepoints.size(1); + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || (logL.size(0) != 0)) { + sizes_idx_1 = 1; + } else { + sizes_idx_1 = 0; + } + + result.set_size(iindx, input_sizes_idx_1 + sizes_idx_1); + for (i = 0; i < input_sizes_idx_1; i++) { + for (i1 = 0; i1 < iindx; i1++) { + result[i1 + result.size(0) * i] = livepoints_sorted[i1 + iindx * i]; + } + } + + for (i = 0; i < sizes_idx_1; i++) { + for (i1 = 0; i1 < iindx; i1++) { + result[i1 + result.size(0) * input_sizes_idx_1] = logL[i1]; + } + } + + if (nest_samples.size(1) != 0) { + iindx = nest_samples.size(1); + } else if ((result.size(0) != 0) && (result.size(1) != 0)) { + iindx = result.size(1); + } else { + iindx = 0; + if (result.size(1) > 0) { + iindx = result.size(1); + } + } + + empty_non_axis_sizes = (iindx == 0); + if (empty_non_axis_sizes || (nest_samples.size(1) != 0)) { + sizes_idx_1 = nest_samples.size(0); + } else { + sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || ((result.size(0) != 0) && (result.size(1) != 0))) + { + input_sizes_idx_1 = result.size(0); + } else { + input_sizes_idx_1 = 0; + } + + i = sizes_idx_1 + input_sizes_idx_1; + b_nest_samples.set_size(i, iindx); + for (i1 = 0; i1 < iindx; i1++) { + for (i2 = 0; i2 < sizes_idx_1; i2++) { + b_nest_samples[i2 + b_nest_samples.size(0) * i1] = nest_samples[i2 + + sizes_idx_1 * i1]; + } + } + + for (i1 = 0; i1 < iindx; i1++) { + for (i2 = 0; i2 < input_sizes_idx_1; i2++) { + b_nest_samples[(i2 + sizes_idx_1) + b_nest_samples.size(0) * i1] = + result[i2 + input_sizes_idx_1 * i1]; + } + } + + nest_samples.set_size(b_nest_samples.size(0), b_nest_samples.size(1)); + sizes_idx_1 = b_nest_samples.size(1); + for (i1 = 0; i1 < sizes_idx_1; i1++) { + input_sizes_idx_1 = b_nest_samples.size(0); + for (i2 = 0; i2 < input_sizes_idx_1; i2++) { + nest_samples[i2 + nest_samples.size(0) * i1] = b_nest_samples[i2 + + b_nest_samples.size(0) * i1]; + } + } + + // rescale the samples back to their true ranges + i = coder::internal::intlength(i, iindx); + for (int32_T b_i{0}; b_i < i; b_i++) { + if (nest_samples.size(1) - 1 < 1) { + sizes_idx_1 = 0; + } else { + sizes_idx_1 = nest_samples.size(1) - 1; + } + + for (i1 = 0; i1 < sizes_idx_1; i1++) { + nest_samples_data[i1] = nest_samples[b_i + nest_samples.size(0) * i1]; + } + + b_nest_samples_data.set(&nest_samples_data[0], 1, sizes_idx_1); + rescaleParameters(prior, b_nest_samples_data, b); + if (nest_samples.size(1) - 1 < 1) { + sizes_idx_1 = 0; + } else { + sizes_idx_1 = nest_samples.size(1) - 1; + } + + for (i1 = 0; i1 < sizes_idx_1; i1++) { + nest_samples[b_i + nest_samples.size(0) * i1] = b[i1]; + } + } + + // convert nested samples into posterior samples - nest2pos assumes that the + // final column in the sample chain is the log likelihood + nest2pos(nest_samples, Nlive, post_samples); + } +} + +// End of code generation (nestedSampler.cpp) diff --git a/RAT/nestedSampler.h b/RAT/nestedSampler.h new file mode 100644 index 00000000..5c7d5260 --- /dev/null +++ b/RAT/nestedSampler.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// nestedSampler.h +// +// Code generation for function 'nestedSampler' +// +#ifndef NESTEDSAMPLER_H +#define NESTEDSAMPLER_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct struct2_T; + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + void nestedSampler(const struct5_T *data_f1, const struct2_T *data_f2, const + cell_14 *data_f4, real_T Nlive, real_T Nmcmc, real_T + tolerance, const ::coder::array &prior, real_T * + logZ, ::coder::array &nest_samples, ::coder:: + array &post_samples, real_T *H); +} + +#endif + +// End of code generation (nestedSampler.h) diff --git a/RAT/nonSingletonDim.cpp b/RAT/nonSingletonDim.cpp new file mode 100644 index 00000000..d8b4b533 --- /dev/null +++ b/RAT/nonSingletonDim.cpp @@ -0,0 +1,48 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// nonSingletonDim.cpp +// +// Code generation for function 'nonSingletonDim' +// + +// Include files +#include "nonSingletonDim.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + int32_T nonSingletonDim(const ::coder::array &x) + { + int32_T dim; + dim = 2; + if (x.size(0) != 1) { + dim = 1; + } + + return dim; + } + + int32_T nonSingletonDim(const ::coder::array &x) + { + int32_T dim; + dim = 2; + if (x.size(0) != 1) { + dim = 1; + } + + return dim; + } + } + } +} + +// End of code generation (nonSingletonDim.cpp) diff --git a/RAT/nonSingletonDim.h b/RAT/nonSingletonDim.h new file mode 100644 index 00000000..58601492 --- /dev/null +++ b/RAT/nonSingletonDim.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// nonSingletonDim.h +// +// Code generation for function 'nonSingletonDim' +// +#ifndef NONSINGLETONDIM_H +#define NONSINGLETONDIM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + int32_T nonSingletonDim(const ::coder::array &x); + int32_T nonSingletonDim(const ::coder::array &x); + } + } +} + +#endif + +// End of code generation (nonSingletonDim.h) diff --git a/RAT/norm.cpp b/RAT/norm.cpp new file mode 100644 index 00000000..bb7d8371 --- /dev/null +++ b/RAT/norm.cpp @@ -0,0 +1,131 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// norm.cpp +// +// Code generation for function 'norm' +// + +// Include files +#include "norm.h" +#include "rt_nonfinite.h" +#include "xnrm2.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + static real_T mat1norm(const ::coder::array &x); + static real_T vecpnorm(const ::coder::array &x); + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + static real_T mat1norm(const ::coder::array &x) + { + real_T y; + int32_T j; + boolean_T exitg1; + y = 0.0; + j = 0; + exitg1 = false; + while ((!exitg1) && (j <= x.size(1) - 1)) { + real_T s; + int32_T i; + s = 0.0; + i = x.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + s += std::abs(x[b_i + x.size(0) * j]); + } + + if (std::isnan(s)) { + y = rtNaN; + exitg1 = true; + } else { + if (s > y) { + y = s; + } + + j++; + } + } + + return y; + } + + static real_T vecpnorm(const ::coder::array &x) + { + real_T y; + int32_T i; + y = 0.0; + i = x.size(0) * x.size(1); + for (int32_T k{0}; k < i; k++) { + y += std::abs(x[k]); + } + + return y; + } + + real_T b_norm(const ::coder::array &x) + { + real_T y; + boolean_T MATRIX_INPUT_AND_P_IS_ONE; + boolean_T VECTOR_INPUT_AND_P_IS_NUMERIC; + VECTOR_INPUT_AND_P_IS_NUMERIC = false; + MATRIX_INPUT_AND_P_IS_ONE = false; + if ((x.size(0) == 1) || (x.size(1) == 1)) { + VECTOR_INPUT_AND_P_IS_NUMERIC = true; + } else { + MATRIX_INPUT_AND_P_IS_ONE = true; + } + + if ((x.size(0) == 0) || (x.size(1) == 0)) { + y = 0.0; + } else if (MATRIX_INPUT_AND_P_IS_ONE) { + y = mat1norm(x); + } else if (VECTOR_INPUT_AND_P_IS_NUMERIC) { + y = vecpnorm(x); + } else { + y = rtNaN; + } + + return y; + } + + real_T b_norm(const ::coder::array &x) + { + real_T y; + int32_T i; + y = 0.0; + i = x.size(0); + for (int32_T k{0}; k < i; k++) { + y += std::abs(x[k]); + } + + return y; + } + + real_T c_norm(const ::coder::array &x) + { + real_T y; + if (x.size(1) == 0) { + y = 0.0; + } else { + y = internal::blas::xnrm2(x.size(1), x); + } + + return y; + } + } +} + +// End of code generation (norm.cpp) diff --git a/RAT/norm.h b/RAT/norm.h new file mode 100644 index 00000000..9a6d8303 --- /dev/null +++ b/RAT/norm.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// norm.h +// +// Code generation for function 'norm' +// +#ifndef NORM_H +#define NORM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + real_T b_norm(const ::coder::array &x); + real_T b_norm(const ::coder::array &x); + real_T c_norm(const ::coder::array &x); + } +} + +#endif + +// End of code generation (norm.h) diff --git a/RAT/nsIntraFun.cpp b/RAT/nsIntraFun.cpp new file mode 100644 index 00000000..2c78f5c0 --- /dev/null +++ b/RAT/nsIntraFun.cpp @@ -0,0 +1,74 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// nsIntraFun.cpp +// +// Code generation for function 'nsIntraFun' +// + +// Include files +#include "nsIntraFun.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "reflectivityCalculation.h" +#include "rt_nonfinite.h" +#include "unpackParams.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + real_T nsIntraFun(const struct5_T *data_f1, const struct2_T *data_f2, const + cell_14 *data_f4, const ::coder::array &p) + { + cell_13 a__1; + struct5_T problemDef; + struct_T b_problemDef; + int32_T loop_ub; + problemDef = *data_f1; + + // Removed use of cells.... + problemDef.fitParams.set_size(1, p.size(1)); + loop_ub = p.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + problemDef.fitParams[problemDef.fitParams.size(0) * i] = p[i]; + } + + unpackParams(&problemDef, data_f2->checks.fitParam, + data_f2->checks.fitBackgroundParam, data_f2->checks.fitQzshift, + data_f2->checks.fitScalefactor, data_f2->checks.fitBulkIn, + data_f2->checks.fitBulkOut, data_f2->checks.fitResolutionParam, + data_f2->checks.fitDomainRatio); + reflectivityCalculation(&problemDef, data_f4, data_f2, &b_problemDef, &a__1); + return -b_problemDef.calculations.sumChi / 2.0; + } + + real_T nsIntraFun(const struct5_T *data_f1, const struct2_T *data_f2, const + cell_14 *data_f4, const ::coder::array &p) + { + cell_13 a__1; + struct5_T problemDef; + struct_T b_problemDef; + int32_T p_idx_0; + problemDef = *data_f1; + + // Removed use of cells.... + p_idx_0 = p.size(0); + problemDef.fitParams.set_size(p.size(0), 1); + for (int32_T i{0}; i < p_idx_0; i++) { + problemDef.fitParams[i] = p[i]; + } + + unpackParams(&problemDef, data_f2->checks.fitParam, + data_f2->checks.fitBackgroundParam, data_f2->checks.fitQzshift, + data_f2->checks.fitScalefactor, data_f2->checks.fitBulkIn, + data_f2->checks.fitBulkOut, data_f2->checks.fitResolutionParam, + data_f2->checks.fitDomainRatio); + reflectivityCalculation(&problemDef, data_f4, data_f2, &b_problemDef, &a__1); + return -b_problemDef.calculations.sumChi / 2.0; + } +} + +// End of code generation (nsIntraFun.cpp) diff --git a/RAT/nsIntraFun.h b/RAT/nsIntraFun.h new file mode 100644 index 00000000..2b1bc6b8 --- /dev/null +++ b/RAT/nsIntraFun.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// nsIntraFun.h +// +// Code generation for function 'nsIntraFun' +// +#ifndef NSINTRAFUN_H +#define NSINTRAFUN_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct struct2_T; + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + real_T nsIntraFun(const struct5_T *data_f1, const struct2_T *data_f2, const + cell_14 *data_f4, const ::coder::array &p); + real_T nsIntraFun(const struct5_T *data_f1, const struct2_T *data_f2, const + cell_14 *data_f4, const ::coder::array &p); +} + +#endif + +// End of code generation (nsIntraFun.h) diff --git a/RAT/nullAssignment.cpp b/RAT/nullAssignment.cpp index ae317642..4c1138ac 100644 --- a/RAT/nullAssignment.cpp +++ b/RAT/nullAssignment.cpp @@ -11,6 +11,21 @@ // Include files #include "nullAssignment.h" #include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + static void make_bitarray(int32_T n, const ::coder::array + &idx, ::coder::array &b); + static int32_T num_true(const ::coder::array &b); + } + } +} // Function Definitions namespace RAT @@ -19,6 +34,59 @@ namespace RAT { namespace internal { + static void make_bitarray(int32_T n, const ::coder::array + &idx, ::coder::array &b) + { + int32_T i; + b.set_size(1, n); + for (i = 0; i < n; i++) { + b[i] = false; + } + + i = idx.size(1); + for (int32_T k{0}; k < i; k++) { + b[idx[k] - 1] = true; + } + } + + static int32_T num_true(const ::coder::array &b) + { + int32_T i; + int32_T n; + n = 0; + i = b.size(1); + for (int32_T k{0}; k < i; k++) { + n += b[k]; + } + + return n; + } + + void nullAssignment(::coder::array &x, const ::coder::array< + int32_T, 2U> &idx) + { + ::coder::array b; + int32_T k0; + int32_T nxin; + int32_T nxout; + nxin = x.size(1); + make_bitarray(x.size(1), idx, b); + nxout = x.size(1) - num_true(b); + k0 = -1; + for (int32_T k{0}; k < nxin; k++) { + if ((k + 1 > b.size(1)) || (!b[k])) { + k0++; + x[k0] = x[k]; + } + } + + if (nxout < 1) { + nxout = 0; + } + + x.set_size(x.size(0), nxout); + } + void nullAssignment(real_T x_data[], int32_T x_size[2]) { int32_T i; diff --git a/RAT/nullAssignment.h b/RAT/nullAssignment.h index 0e49f6e7..9456f2fe 100644 --- a/RAT/nullAssignment.h +++ b/RAT/nullAssignment.h @@ -12,6 +12,7 @@ // Include files #include "rtwtypes.h" +#include "coder_array.h" #include #include @@ -22,6 +23,8 @@ namespace RAT { namespace internal { + void nullAssignment(::coder::array &x, const ::coder::array< + int32_T, 2U> &idx); void nullAssignment(real_T x_data[], int32_T x_size[2]); } } diff --git a/RAT/optimalEllipsoids.cpp b/RAT/optimalEllipsoids.cpp new file mode 100644 index 00000000..283b2298 --- /dev/null +++ b/RAT/optimalEllipsoids.cpp @@ -0,0 +1,449 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// optimalEllipsoids.cpp +// +// Code generation for function 'optimalEllipsoids' +// + +// Include files +#include "optimalEllipsoids.h" +#include "RATMain_data.h" +#include "all.h" +#include "calcEllipsoid.h" +#include "rt_nonfinite.h" +#include "splitEllipsoid.h" +#include "validate_print_arguments.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void d_binary_expand_op(boolean_T in1_data[], int32_T in1_size[2], + const real_T in2_data[], const int32_T in2_size[2], const real_T in3_data[], + const int32_T in3_size[2], const ::coder::array &in4); +} + +// Function Definitions +namespace RAT +{ + static void d_binary_expand_op(boolean_T in1_data[], int32_T in1_size[2], + const real_T in2_data[], const int32_T in2_size[2], const real_T in3_data[], + const int32_T in3_size[2], const ::coder::array &in4) + { + int32_T b_in2_size[2]; + int32_T aux_0_1; + int32_T aux_1_1; + int32_T aux_2_1; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_0_1; + int32_T stride_1_0; + int32_T stride_1_1; + int32_T stride_2_0; + int32_T stride_2_1; + boolean_T b_in2_data; + if (in4.size(0) == 1) { + if (in3_size[0] == 1) { + b_in2_size[0] = in2_size[0]; + } else { + b_in2_size[0] = in3_size[0]; + } + } else { + b_in2_size[0] = in4.size(0); + } + + if (in4.size(1) == 1) { + if (in3_size[1] == 1) { + b_in2_size[1] = in2_size[1]; + } else { + b_in2_size[1] = in3_size[1]; + } + } else { + b_in2_size[1] = in4.size(1); + } + + stride_0_0 = (in2_size[0] != 1); + stride_0_1 = (in2_size[1] != 1); + stride_1_0 = (in3_size[0] != 1); + stride_1_1 = (in3_size[1] != 1); + stride_2_0 = (in4.size(0) != 1); + stride_2_1 = (in4.size(1) != 1); + aux_0_1 = 0; + aux_1_1 = 0; + aux_2_1 = 0; + if (in4.size(1) == 1) { + if (in3_size[1] == 1) { + loop_ub = in2_size[1]; + } else { + loop_ub = in3_size[1]; + } + } else { + loop_ub = in4.size(1); + } + + for (int32_T i{0}; i < loop_ub; i++) { + int32_T b_loop_ub; + int32_T i1; + i1 = in4.size(0); + b_loop_ub = in3_size[0]; + if (i1 == 1) { + if (b_loop_ub == 1) { + b_loop_ub = in2_size[0]; + } + } else { + b_loop_ub = i1; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_in2_data = (in2_data[i1 * stride_0_0 + in2_size[0] * aux_0_1] + + in3_data[i1 * stride_1_0 + in3_size[0] * aux_1_1] < in4[i1 + * stride_2_0 + in4.size(0) * aux_2_1]); + } + + aux_2_1 += stride_2_1; + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + + coder::all((const boolean_T *)&b_in2_data, b_in2_size, in1_data, in1_size); + } + + void optimalEllipsoids(const ::coder::array &u, real_T VS, ::coder:: + array &Bs, ::coder::array &mus, ::coder::array< + real_T, 2U> &VEs, ::coder::array &ns) + { + ::coder::array B1; + ::coder::array B2; + ::coder::array VE1; + ::coder::array VE2; + ::coder::array mu; + ::coder::array mu1; + ::coder::array mu2; + ::coder::array n1; + ::coder::array n2; + ::coder::array u1; + ::coder::array u2; + real_T VE1_data; + real_T VE2_data; + real_T flag; + real_T nosplit; + int32_T VE1_size[2]; + int32_T VE2_size[2]; + int32_T b_VE1_size[2]; + int32_T tmp_size[2]; + boolean_T empty_non_axis_sizes; + + // function [Bs, mus, VEs, ns] = optimalEllipsoids(u, VS) + // + // This function attempts to optimally partition the multi-dimensional + // samples u (uniformly distributed within the sample volume VS), into + // a set of subclusters enclosed by bounding ellipsoids. The algorithm + // is based on Algorithm 1 of the MULTINEST paper by Feroz, Hobson, + // and Bridges, MNRAS, 398, 1601-1614 (2009). + // + // Output: + // Bs: an array of bounding matrices for the ellipsoids enclosing + // the subclusters, scaled to have at least the minimum volume + // required by the subclusters. ( (K x ndims) x ndims ) + // mus: an array of centroids for the bounding ellipsoids (K x ndims) + // VEs: an array of volumes for the bounding ellipsoids (K x 1) + // ns: an array containing the number of points for each subcluster (K x 1) + // + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // number of samples in multi-dimensional space + // number of dimensions + // calculate bounding matrix, etc. for bounding ellipsoid associated + // with the original set of points u + VEs.reserve(1); + calcEllipsoid(u, VS, Bs, mu, (real_T *)VEs.data(), VEs.size(), &flag); + + // attempt to split u into two subclusters + splitEllipsoid(u, VS, u1, u2, (real_T *)&VE1_data, VE1_size, (real_T *) + &VE2_data, VE2_size, &nosplit); + if ((nosplit != 0.0) || (static_cast(u1.size(0)) < + static_cast(u.size(1)) + 1U) || (static_cast + (u2.size(0)) < static_cast(u.size(1)) + 1U)) { + int32_T input_sizes_idx_0; + + // couldn't split the cluster + mus.set_size(mu.size(0), mu.size(1)); + input_sizes_idx_0 = mu.size(1); + for (int32_T i{0}; i < input_sizes_idx_0; i++) { + int32_T loop_ub; + loop_ub = mu.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + mus[mus.size(0) * i] = mu[mu.size(0) * i]; + } + } + + ns.set_size(1, 1); + ns[0] = u.size(0); + } else { + int32_T validatedHoleFilling[3]; + int32_T i; + int32_T i1; + int32_T input_sizes_idx_0; + int32_T loop_ub; + boolean_T b_VE1_data; + boolean_T guard1; + + // check if we should keep the partitioning of S + // if (all(VE1 + VE2 < VE) || all(VE > 2*VS)) + if (VE1_size[0] == 1) { + i = VE2_size[0]; + } else { + i = VE1_size[0]; + } + + if (VE1_size[1] == 1) { + i1 = VE2_size[1]; + } else { + i1 = VE1_size[1]; + } + + if ((VE1_size[0] == VE2_size[0]) && (VE1_size[1] == VE2_size[1]) && (i == + VEs.size(0)) && (i1 == VEs.size(1))) { + b_VE1_size[0] = VE1_size[0]; + b_VE1_size[1] = VE1_size[1]; + input_sizes_idx_0 = VE1_size[1]; + for (i = 0; i < input_sizes_idx_0; i++) { + loop_ub = VE1_size[0]; + for (i1 = 0; i1 < loop_ub; i1++) { + b_VE1_data = (VE1_data + VE2_data < VEs[0]); + } + } + + coder::all((const boolean_T *)&b_VE1_data, b_VE1_size, (boolean_T *) + &empty_non_axis_sizes, tmp_size); + } else { + d_binary_expand_op((boolean_T *)&empty_non_axis_sizes, tmp_size, (const + real_T *)&VE1_data, VE1_size, (const real_T *)&VE2_data, VE2_size, VEs); + } + + guard1 = false; + if (coder::b_all((const boolean_T *)&empty_non_axis_sizes, tmp_size)) { + guard1 = true; + } else { + flag = 2.0 * VS; + b_VE1_size[0] = VEs.size(0); + b_VE1_size[1] = VEs.size(1); + input_sizes_idx_0 = VEs.size(1); + for (i = 0; i < input_sizes_idx_0; i++) { + loop_ub = VEs.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_VE1_data = (VEs[i1 + VEs.size(0) * i] > flag); + } + } + + coder::all((const boolean_T *)&b_VE1_data, b_VE1_size, (boolean_T *) + &empty_non_axis_sizes, tmp_size); + if (coder::b_all((const boolean_T *)&empty_non_axis_sizes, tmp_size)) { + guard1 = true; + } else { + if (DEBUG != 0.0) { + coder::internal::validate_print_arguments(u.size(0), u1.size(0), + u2.size(0), validatedHoleFilling); + printf("PARTITION REJECTED: N=%d doesnt split into n1=%d and n2=%d\n", + validatedHoleFilling[0], validatedHoleFilling[1], + validatedHoleFilling[2]); + fflush(stdout); + } + + mus.set_size(mu.size(0), mu.size(1)); + input_sizes_idx_0 = mu.size(1); + for (i = 0; i < input_sizes_idx_0; i++) { + loop_ub = mu.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + mus[mus.size(0) * i] = mu[mu.size(0) * i]; + } + } + + ns.set_size(1, 1); + ns[0] = u.size(0); + } + } + + if (guard1) { + int32_T result; + int32_T sizes_idx_0; + int16_T b_input_sizes_idx_0; + if (DEBUG != 0.0) { + coder::internal::validate_print_arguments(u.size(0), u1.size(0), + u2.size(0), validatedHoleFilling); + printf("PARTITION ACCEPTED: N=%d splits to n1=%d, n2=%d\n", + validatedHoleFilling[0], validatedHoleFilling[1], + validatedHoleFilling[2]); + fflush(stdout); + } + + optimalEllipsoids(u1, static_cast(u1.size(0)) * VS / + static_cast(u.size(0)), B1, mu1, VE1, n1); + optimalEllipsoids(u2, static_cast(u2.size(0)) * VS / + static_cast(u.size(0)), B2, mu2, VE2, n2); + if ((B1.size(0) != 0) && (B1.size(1) != 0)) { + result = B1.size(1); + } else if ((B2.size(0) != 0) && (B2.size(1) != 0)) { + result = B2.size(1); + } else { + result = B1.size(1); + if (B2.size(1) > B1.size(1)) { + result = B2.size(1); + } + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || ((B1.size(0) != 0) && (B1.size(1) != 0))) { + input_sizes_idx_0 = B1.size(0); + } else { + input_sizes_idx_0 = 0; + } + + if (empty_non_axis_sizes || ((B2.size(0) != 0) && (B2.size(1) != 0))) { + sizes_idx_0 = B2.size(0); + } else { + sizes_idx_0 = 0; + } + + Bs.set_size(input_sizes_idx_0 + sizes_idx_0, result); + for (i = 0; i < result; i++) { + for (i1 = 0; i1 < input_sizes_idx_0; i1++) { + Bs[i1 + Bs.size(0) * i] = B1[i1 + input_sizes_idx_0 * i]; + } + } + + for (i = 0; i < result; i++) { + for (i1 = 0; i1 < sizes_idx_0; i1++) { + Bs[(i1 + input_sizes_idx_0) + Bs.size(0) * i] = B2[i1 + sizes_idx_0 * + i]; + } + } + + if ((mu1.size(0) != 0) && (mu1.size(1) != 0)) { + result = mu1.size(1); + } else if ((mu2.size(0) != 0) && (mu2.size(1) != 0)) { + result = mu2.size(1); + } else { + result = mu1.size(1); + if (mu2.size(1) > mu1.size(1)) { + result = mu2.size(1); + } + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || ((mu1.size(0) != 0) && (mu1.size(1) != 0))) + { + b_input_sizes_idx_0 = static_cast(mu1.size(0)); + } else { + b_input_sizes_idx_0 = 0; + } + + if (empty_non_axis_sizes || ((mu2.size(0) != 0) && (mu2.size(1) != 0))) + { + sizes_idx_0 = mu2.size(0); + } else { + sizes_idx_0 = 0; + } + + loop_ub = b_input_sizes_idx_0; + mus.set_size(b_input_sizes_idx_0 + sizes_idx_0, result); + for (i = 0; i < result; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + mus[i1 + mus.size(0) * i] = mu1[i1 + b_input_sizes_idx_0 * i]; + } + } + + for (i = 0; i < result; i++) { + for (i1 = 0; i1 < sizes_idx_0; i1++) { + mus[(i1 + b_input_sizes_idx_0) + mus.size(0) * i] = mu2[i1 + + sizes_idx_0 * i]; + } + } + + if ((VE1.size(0) != 0) && (VE1.size(1) != 0)) { + result = VE1.size(1); + } else if ((VE2.size(0) != 0) && (VE2.size(1) != 0)) { + result = VE2.size(1); + } else { + result = VE1.size(1); + if (VE2.size(1) > VE1.size(1)) { + result = VE2.size(1); + } + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || ((VE1.size(0) != 0) && (VE1.size(1) != 0))) + { + input_sizes_idx_0 = VE1.size(0); + } else { + input_sizes_idx_0 = 0; + } + + if (empty_non_axis_sizes || ((VE2.size(0) != 0) && (VE2.size(1) != 0))) + { + sizes_idx_0 = VE2.size(0); + } else { + sizes_idx_0 = 0; + } + + VEs.set_size(input_sizes_idx_0 + sizes_idx_0, result); + for (i = 0; i < result; i++) { + for (i1 = 0; i1 < input_sizes_idx_0; i1++) { + VEs[i1 + VEs.size(0) * i] = VE1[i1 + input_sizes_idx_0 * i]; + } + } + + for (i = 0; i < result; i++) { + for (i1 = 0; i1 < sizes_idx_0; i1++) { + VEs[(i1 + input_sizes_idx_0) + VEs.size(0) * i] = VE2[i1 + + sizes_idx_0 * i]; + } + } + + if ((n1.size(0) != 0) && (n1.size(1) != 0)) { + result = n1.size(1); + } else if ((n2.size(0) != 0) && (n2.size(1) != 0)) { + result = n2.size(1); + } else { + result = (n1.size(1) > 0); + if (n2.size(1) > result) { + result = 1; + } + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || ((n1.size(0) != 0) && (n1.size(1) != 0))) { + b_input_sizes_idx_0 = static_cast(n1.size(0)); + } else { + b_input_sizes_idx_0 = 0; + } + + if (empty_non_axis_sizes || ((n2.size(0) != 0) && (n2.size(1) != 0))) { + sizes_idx_0 = n2.size(0); + } else { + sizes_idx_0 = 0; + } + + loop_ub = b_input_sizes_idx_0; + ns.set_size(b_input_sizes_idx_0 + sizes_idx_0, result); + for (i = 0; i < result; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + ns[i1 + ns.size(0) * i] = n1[i1 + b_input_sizes_idx_0 * i]; + } + } + + for (i = 0; i < result; i++) { + for (i1 = 0; i1 < sizes_idx_0; i1++) { + ns[(i1 + b_input_sizes_idx_0) + ns.size(0) * i] = n2[i1 + + sizes_idx_0 * i]; + } + } + } + } + } +} + +// End of code generation (optimalEllipsoids.cpp) diff --git a/RAT/optimalEllipsoids.h b/RAT/optimalEllipsoids.h new file mode 100644 index 00000000..292f1944 --- /dev/null +++ b/RAT/optimalEllipsoids.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// optimalEllipsoids.h +// +// Code generation for function 'optimalEllipsoids' +// +#ifndef OPTIMALELLIPSOIDS_H +#define OPTIMALELLIPSOIDS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void optimalEllipsoids(const ::coder::array &u, real_T VS, ::coder:: + array &Bs, ::coder::array &mus, ::coder::array< + real_T, 2U> &VEs, ::coder::array &ns); +} + +#endif + +// End of code generation (optimalEllipsoids.h) diff --git a/RAT/packParams.cpp b/RAT/packParams.cpp new file mode 100644 index 00000000..9bcd101f --- /dev/null +++ b/RAT/packParams.cpp @@ -0,0 +1,333 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// packParams.cpp +// +// Code generation for function 'packParams' +// + +// Include files +#include "packParams.h" +#include "RATMain_types.h" +#include "rt_nonfinite.h" +#include "sum.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void packParams(struct5_T *problemDef, const ::coder::array + &problemDefCells_f7, const ::coder::array + &problemDefCells_f8, const ::coder::array + &problemDefCells_f9, const ::coder::array + &problemDefCells_f10, const ::coder::array + &problemDefCells_f11, const ::coder::array + &problemDefCells_f12, const ::coder::array + &problemDefCells_f13, const ::coder::array + &problemDefCells_f20, const struct1_T *limits, const struct3_T + *checks, ::coder::array &fitNames) + { + ::coder::array fitLimits; + ::coder::array fitParams; + ::coder::array otherLimits; + ::coder::array otherParams; + real_T numberOfFitted; + int32_T b_loop_ub; + int32_T fitCounter; + int32_T i; + int32_T loop_ub; + int32_T numberOfTotal; + int32_T otherCounter; + + // We need to pack the parameters into separate vectors + // of those that are being fitted, and those that are + // held constant. + numberOfFitted = ((((((coder::sum(checks->fitParam) + coder::sum + (checks->fitBackgroundParam)) + coder::sum(checks->fitScalefactor)) + + coder::sum(checks->fitQzshift)) + coder::sum + (checks->fitBulkIn)) + coder::sum(checks->fitBulkOut)) + + coder::sum(checks->fitResolutionParam)) + coder::sum + (checks->fitDomainRatio); + numberOfTotal = ((((((problemDef->params.size(1) + + problemDef->backgroundParams.size(1)) + + problemDef->scalefactors.size(1)) + + problemDef->qzshifts.size(1)) + problemDef->bulkIn.size + (1)) + problemDef->bulkOut.size(1)) + + problemDef->resolutionParams.size(1)) + + problemDef->domainRatio.size(1); + fitParams.set_size(problemDef->fitParams.size(0), problemDef->fitParams.size + (1)); + loop_ub = problemDef->fitParams.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = problemDef->fitParams.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + fitParams[i1 + fitParams.size(0) * i] = problemDef->fitParams[i1 + + problemDef->fitParams.size(0) * i]; + } + } + + // zeros(numberOfFitted,1); + b_loop_ub = static_cast(static_cast(numberOfTotal) - + numberOfFitted); + otherParams.set_size(b_loop_ub); + for (i = 0; i < b_loop_ub; i++) { + otherParams[i] = 0.0; + } + + loop_ub = static_cast(numberOfFitted); + fitLimits.set_size(loop_ub, 2); + otherLimits.set_size(b_loop_ub, 2); + for (i = 0; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + fitLimits[i1 + fitLimits.size(0) * i] = 0.0; + } + + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + otherLimits[i1 + otherLimits.size(0) * i] = 0.0; + } + } + + // limits = problemDef.limits; + fitNames.set_size(loop_ub); + for (int32_T b_i{0}; b_i < loop_ub; b_i++) { + fitNames[b_i].f1.set_size(1, 0); + } + + fitCounter = 0; + otherCounter = 0; + i = checks->fitParam.size(1); + for (int32_T n{0}; n < i; n++) { + if (checks->fitParam[n] == 1.0) { + fitParams[fitCounter] = problemDef->params[n]; + fitLimits[fitCounter] = limits->param[n]; + fitLimits[fitCounter + fitLimits.size(0)] = limits->param[n + + limits->param.size(0)]; + loop_ub = problemDefCells_f7[n].f1.size(1); + fitNames[fitCounter].f1.set_size(1, + problemDefCells_f7[problemDefCells_f7.size(0) * n].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + fitNames[fitCounter].f1[i1] = problemDefCells_f7[n].f1[i1]; + } + + fitCounter++; + } else { + otherParams[otherCounter] = problemDef->params[n]; + otherLimits[otherCounter] = limits->param[n]; + otherLimits[otherCounter + otherLimits.size(0)] = limits->param[n + + limits->param.size(0)]; + otherCounter++; + } + } + + // Also do the same for backgrounds... + i = checks->fitBackgroundParam.size(1); + for (int32_T n{0}; n < i; n++) { + if (checks->fitBackgroundParam[n] == 1.0) { + fitParams[fitCounter] = problemDef->backgroundParams[n]; + fitLimits[fitCounter] = limits->backgroundParam[n]; + fitLimits[fitCounter + fitLimits.size(0)] = limits->backgroundParam[n + + limits->backgroundParam.size(0)]; + loop_ub = problemDefCells_f8[n].f1.size(1); + fitNames[fitCounter].f1.set_size(1, + problemDefCells_f8[problemDefCells_f8.size(0) * n].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + fitNames[fitCounter].f1[i1] = problemDefCells_f8[n].f1[i1]; + } + + fitCounter++; + } else { + otherParams[otherCounter] = problemDef->backgroundParams[n]; + otherLimits[otherCounter] = limits->backgroundParam[n]; + otherLimits[otherCounter + otherLimits.size(0)] = + limits->backgroundParam[n + limits->backgroundParam.size(0)]; + otherCounter++; + } + } + + // ..also for the scale factors + i = checks->fitScalefactor.size(1); + for (int32_T n{0}; n < i; n++) { + if (checks->fitScalefactor[n] == 1.0) { + fitParams[fitCounter] = problemDef->scalefactors[n]; + fitLimits[fitCounter] = limits->scalefactor[n]; + fitLimits[fitCounter + fitLimits.size(0)] = limits->scalefactor[n + + limits->scalefactor.size(0)]; + loop_ub = problemDefCells_f9[n].f1.size(1); + fitNames[fitCounter].f1.set_size(1, + problemDefCells_f9[problemDefCells_f9.size(0) * n].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + fitNames[fitCounter].f1[i1] = problemDefCells_f9[n].f1[i1]; + } + + fitCounter++; + } else { + otherParams[otherCounter] = problemDef->scalefactors[n]; + otherLimits[otherCounter] = limits->scalefactor[n]; + otherLimits[otherCounter + otherLimits.size(0)] = limits->scalefactor[n + + limits->scalefactor.size(0)]; + otherCounter++; + } + } + + // Need qzshifts + i = checks->fitQzshift.size(1); + for (int32_T n{0}; n < i; n++) { + if (checks->fitQzshift[n] == 1.0) { + fitParams[fitCounter] = problemDef->qzshifts[n]; + fitLimits[fitCounter] = limits->qzshift[n]; + fitLimits[fitCounter + fitLimits.size(0)] = limits->qzshift[n + + limits->qzshift.size(0)]; + loop_ub = problemDefCells_f10[n].f1.size(1); + fitNames[fitCounter].f1.set_size(1, + problemDefCells_f10[problemDefCells_f10.size(0) * n].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + fitNames[fitCounter].f1[i1] = problemDefCells_f10[n].f1[i1]; + } + + fitCounter++; + } else { + otherParams[otherCounter] = problemDef->qzshifts[n]; + otherLimits[otherCounter] = limits->qzshift[n]; + otherLimits[otherCounter + otherLimits.size(0)] = limits->qzshift[n + + limits->qzshift.size(0)]; + otherCounter++; + } + } + + // Bulk In + i = checks->fitBulkIn.size(1); + for (int32_T n{0}; n < i; n++) { + if (checks->fitBulkIn[n] == 1.0) { + fitParams[fitCounter] = problemDef->bulkIn[n]; + fitLimits[fitCounter] = limits->bulkIn[n]; + fitLimits[fitCounter + fitLimits.size(0)] = limits->bulkIn[n + + limits->bulkIn.size(0)]; + loop_ub = problemDefCells_f11[n].f1.size(1); + fitNames[fitCounter].f1.set_size(1, + problemDefCells_f11[problemDefCells_f11.size(0) * n].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + fitNames[fitCounter].f1[i1] = problemDefCells_f11[n].f1[i1]; + } + + fitCounter++; + } else { + otherParams[otherCounter] = problemDef->bulkIn[n]; + otherLimits[otherCounter] = limits->bulkIn[n]; + otherLimits[otherCounter + otherLimits.size(0)] = limits->bulkIn[n + + limits->bulkIn.size(0)]; + otherCounter++; + } + } + + // Bulk Out + i = checks->fitBulkOut.size(1); + for (int32_T n{0}; n < i; n++) { + if (checks->fitBulkOut[n] == 1.0) { + fitParams[fitCounter] = problemDef->bulkOut[n]; + fitLimits[fitCounter] = limits->bulkOut[n]; + fitLimits[fitCounter + fitLimits.size(0)] = limits->bulkOut[n + + limits->bulkOut.size(0)]; + loop_ub = problemDefCells_f12[n].f1.size(1); + fitNames[fitCounter].f1.set_size(1, + problemDefCells_f12[problemDefCells_f12.size(0) * n].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + fitNames[fitCounter].f1[i1] = problemDefCells_f12[n].f1[i1]; + } + + fitCounter++; + } else { + otherParams[otherCounter] = problemDef->bulkOut[n]; + otherLimits[otherCounter] = limits->bulkOut[n]; + otherLimits[otherCounter + otherLimits.size(0)] = limits->bulkOut[n + + limits->bulkOut.size(0)]; + otherCounter++; + } + } + + // Resolution..... + i = checks->fitResolutionParam.size(1); + for (int32_T n{0}; n < i; n++) { + if (checks->fitResolutionParam[n] == 1.0) { + fitParams[fitCounter] = problemDef->resolutionParams[n]; + fitLimits[fitCounter] = limits->resolutionParam[n]; + fitLimits[fitCounter + fitLimits.size(0)] = limits->resolutionParam[n + + limits->resolutionParam.size(0)]; + loop_ub = problemDefCells_f13[n].f1.size(1); + fitNames[fitCounter].f1.set_size(1, + problemDefCells_f13[problemDefCells_f13.size(0) * n].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + fitNames[fitCounter].f1[i1] = problemDefCells_f13[n].f1[i1]; + } + + fitCounter++; + } else { + otherParams[otherCounter] = problemDef->resolutionParams[n]; + otherLimits[otherCounter] = limits->resolutionParam[n]; + otherLimits[otherCounter + otherLimits.size(0)] = + limits->resolutionParam[n + limits->resolutionParam.size(0)]; + otherCounter++; + } + } + + // Domain Ratio + i = checks->fitDomainRatio.size(1); + for (int32_T n{0}; n < i; n++) { + if (checks->fitDomainRatio[n] == 1.0) { + fitParams[fitCounter] = problemDef->domainRatio[n]; + fitLimits[fitCounter] = limits->domainRatio[n]; + fitLimits[fitCounter + fitLimits.size(0)] = limits->domainRatio[n + + limits->domainRatio.size(0)]; + loop_ub = problemDefCells_f20[n].f1.size(1); + fitNames[fitCounter].f1.set_size(1, + problemDefCells_f20[problemDefCells_f20.size(0) * n].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + fitNames[fitCounter].f1[i1] = problemDefCells_f20[n].f1[i1]; + } + + fitCounter++; + } else { + otherParams[otherCounter] = problemDef->domainRatio[n]; + otherLimits[otherCounter] = limits->domainRatio[n]; + otherLimits[otherCounter + otherLimits.size(0)] = limits->domainRatio[n + + limits->domainRatio.size(0)]; + otherCounter++; + } + } + + problemDef->fitParams.set_size(fitParams.size(0), fitParams.size(1)); + loop_ub = fitParams.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = fitParams.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + problemDef->fitParams[i1 + problemDef->fitParams.size(0) * i] = + fitParams[i1 + fitParams.size(0) * i]; + } + } + + b_loop_ub = otherParams.size(0); + problemDef->otherParams.set_size(otherParams.size(0), 1); + for (i = 0; i < b_loop_ub; i++) { + problemDef->otherParams[i] = otherParams[i]; + } + + problemDef->fitLimits.set_size(fitLimits.size(0), 2); + problemDef->otherLimits.set_size(otherLimits.size(0), 2); + loop_ub = fitLimits.size(0); + b_loop_ub = otherLimits.size(0); + for (i = 0; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + problemDef->fitLimits[i1 + problemDef->fitLimits.size(0) * i] = + fitLimits[i1 + fitLimits.size(0) * i]; + } + + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + problemDef->otherLimits[i1 + problemDef->otherLimits.size(0) * i] = + otherLimits[i1 + otherLimits.size(0) * i]; + } + } + } +} + +// End of code generation (packParams.cpp) diff --git a/RAT/packParams.h b/RAT/packParams.h new file mode 100644 index 00000000..a832444e --- /dev/null +++ b/RAT/packParams.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// packParams.h +// +// Code generation for function 'packParams' +// +#ifndef PACKPARAMS_H +#define PACKPARAMS_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void packParams(struct5_T *problemDef, const ::coder::array + &problemDefCells_f7, const ::coder::array + &problemDefCells_f8, const ::coder::array + &problemDefCells_f9, const ::coder::array + &problemDefCells_f10, const ::coder::array + &problemDefCells_f11, const ::coder::array + &problemDefCells_f12, const ::coder::array + &problemDefCells_f13, const ::coder::array + &problemDefCells_f20, const struct1_T *limits, const struct3_T + *checks, ::coder::array &fitNames); +} + +#endif + +// End of code generation (packParams.h) diff --git a/RAT/parallelContrasts.cpp b/RAT/parallelContrasts.cpp new file mode 100644 index 00000000..3b55d863 --- /dev/null +++ b/RAT/parallelContrasts.cpp @@ -0,0 +1,262 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts.cpp +// +// Code generation for function 'parallelContrasts' +// + +// Include files +#include "parallelContrasts.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "allocateLayersForContrast.h" +#include "allocateParamsToLayers.h" +#include "backSort.h" +#include "coreLayersCalculation.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace standardLayers + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs) + { + ::coder::array outParameterisedLayers; + ::coder::array reflect; + ::coder::array resampledLayers; + ::coder::array shiftedDat; + ::coder::array simul; + ::coder::array sldProfile; + ::coder::array thisContrastLayers_data; + RATMainTLS *RATMainTLSThread; + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisChiSquared; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + real_T thisSsubs; + int32_T thisContrastLayers_size[2]; + int32_T b_i; + int32_T b_loop_ub; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T nParams; + int32_T ub_loop; + boolean_T calcSld; + boolean_T useImaginary; + RATMainTLSThread = emlrtGetThreadStackData(); + + // Standard Layers calculation paralelised over the outer loop + // This is the main reflectivity calculation of the standard layers + // calculation type. It extracts the required parameters for the contrasts + // from the input arrays, then passes the main calculation to + // 'standardLayersCore', which carries out the calculation iteself. + // The core calculation is common for both standard and custom layers. + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + calcSld = controls->calcSldDuringFit; + useImaginary = problemDef->useImaginary; + + // Allocate the memory for the output arrays before the main loop + backgroundParams.set_size(static_cast + (problemDef->numberOfContrasts)); + + // end memory allocation. + // First we need to allocate the absolute values of the input + // parameters to all the layers in the layers list. This only needs + // to be done once, and so is done outside the contrasts loop + allocateParamsToLayers(problemDef->params, problemDefCells->f6, + outParameterisedLayers); + + // Resample parameters if required + // Loop over all the contrasts + outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); + sldProfiles.set_size(static_cast(problemDef->numberOfContrasts)); + reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); + simulation.set_size(static_cast(problemDef->numberOfContrasts)); + shiftedData.set_size(static_cast(problemDef->numberOfContrasts)); + layerSlds.set_size(static_cast(problemDef->numberOfContrasts)); + chis.set_size(static_cast(problemDef->numberOfContrasts)); + qzshifts.set_size(static_cast(problemDef->numberOfContrasts)); + scalefactors.set_size(static_cast(problemDef->numberOfContrasts)); + bulkIns.set_size(static_cast(problemDef->numberOfContrasts)); + bulkOuts.set_size(static_cast(problemDef->numberOfContrasts)); + resolutionParams.set_size(static_cast + (problemDef->numberOfContrasts)); + allRoughs.set_size(static_cast(problemDef->numberOfContrasts)); + allLayers.set_size(static_cast(problemDef->numberOfContrasts)); + ub_loop = static_cast(problemDef->numberOfContrasts) - 1; + +#pragma omp parallel \ + num_threads(omp_get_max_threads()) \ + private(RATMainTLSThread,sldProfile,reflect,simul,shiftedDat,resampledLayers,thisSsubs,thisChiSquared,thisContrastLayers_size,thisResol,thisBulkOut,thisBulkIn,thisScalefactor,thisQzshift,thisBackground,b_dv,b_dv1,dv2,loop_ub,b_i,b_loop_ub,i1) \ + firstprivate(thisContrastLayers_data) + + { + RATMainTLSThread = emlrtGetThreadStackData(); + +#pragma omp for nowait + + for (i = 0; i <= ub_loop; i++) { + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[i], + problemDef->contrastQzshifts[i], + problemDef->contrastScalefactors[i], + problemDef->contrastBulkIns[i], + problemDef->contrastBulkOuts[i], + problemDef->contrastResolutions[i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, + &thisBulkIn, &thisBulkOut, &thisResol); + + // Also need to determine which layers from the overall layers list + // are required for this contrast, and put them in the correct order + // according to geometry + allocateLayersForContrast(problemDefCells->f5[i].f1, + outParameterisedLayers, useImaginary, + RATMainTLSThread->f4.thisContrastLayers_data, + thisContrastLayers_size); + + // For the other parameters, we extract the correct ones from the input + // arrays + // Substrate roughness is always first parameter for standard layers + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the core layers calculation + thisContrastLayers_data.set + (&RATMainTLSThread->f4.thisContrastLayers_data[0], + thisContrastLayers_size[0], thisContrastLayers_size[1]); + b_dv[0] = problemDefCells->f3[i].f1[0]; + b_dv[1] = problemDefCells->f3[i].f1[1]; + b_dv1[0] = problemDefCells->f4[i].f1[0]; + b_dv1[1] = problemDefCells->f4[i].f1[1]; + dv2[0] = problemDefCells->f1[i].f1[0]; + dv2[1] = problemDefCells->f1[i].f1[1]; + coreLayersCalculation(thisContrastLayers_data, problemDef->params[0], + problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, + thisBulkOut, problemDef->resample[i], calcSld, + thisScalefactor, thisQzshift, + problemDef->dataPresent[i], + problemDefCells->f2[i].f1, b_dv, b_dv1, dv2, + thisBackground, thisResol, + problemDef->contrastBackgroundsType[i], + static_cast(nParams), + controls->resamPars, useImaginary, sldProfile, + reflect, simul, shiftedDat, layerSlds[i].f1, + resampledLayers, &thisChiSquared, &thisSsubs); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + outSsubs[i] = thisSsubs; + loop_ub = sldProfile.size(1); + sldProfiles[i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = sldProfile.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + sldProfiles[i].f1[i1 + sldProfiles[i].f1.size(0) * b_i] = + sldProfile[i1 + sldProfile.size(0) * b_i]; + } + } + + loop_ub = reflect.size(0); + reflectivity[i].f1.set_size(reflect.size(0), 2); + b_loop_ub = simul.size(0); + simulation[i].f1.set_size(simul.size(0), 2); + for (b_i = 0; b_i < 2; b_i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + reflectivity[i].f1[i1 + reflectivity[i].f1.size(0) * b_i] = + reflect[i1 + reflect.size(0) * b_i]; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + simulation[i].f1[i1 + simulation[i].f1.size(0) * b_i] = simul[i1 + + simul.size(0) * b_i]; + } + } + + loop_ub = shiftedDat.size(1); + shiftedData[i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = shiftedDat.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + shiftedData[i].f1[i1 + shiftedData[i].f1.size(0) * b_i] = + shiftedDat[i1 + shiftedDat.size(0) * b_i]; + } + } + + chis[i] = thisChiSquared; + backgroundParams[i] = thisBackground; + qzshifts[i] = thisQzshift; + scalefactors[i] = thisScalefactor; + bulkIns[i] = thisBulkIn; + bulkOuts[i] = thisBulkOut; + resolutionParams[i] = thisResol; + allRoughs[i] = problemDef->params[0]; + loop_ub = resampledLayers.size(1); + allLayers[i].f1.set_size(resampledLayers.size(0), + resampledLayers.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = resampledLayers.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + allLayers[i].f1[i1 + allLayers[i].f1.size(0) * b_i] = + resampledLayers[i1 + resampledLayers.size(0) * b_i]; + } + } + } + } + } + } + } +} + +// End of code generation (parallelContrasts.cpp) diff --git a/RAT/parallelContrasts.h b/RAT/parallelContrasts.h new file mode 100644 index 00000000..1534146a --- /dev/null +++ b/RAT/parallelContrasts.h @@ -0,0 +1,50 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts.h +// +// Code generation for function 'parallelContrasts' +// +#ifndef PARALLELCONTRASTS_H +#define PARALLELCONTRASTS_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace standardLayers + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelContrasts.h) diff --git a/RAT/parallelContrasts1.cpp b/RAT/parallelContrasts1.cpp new file mode 100644 index 00000000..a2a8edb0 --- /dev/null +++ b/RAT/parallelContrasts1.cpp @@ -0,0 +1,250 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts1.cpp +// +// Code generation for function 'parallelContrasts1' +// + +// Include files +#include "parallelContrasts1.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "backSort.h" +#include "coreLayersCalculation.h" +#include "processCustomFunction.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customLayers + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs) + { + ::coder::array layerSld; + ::coder::array reflect; + ::coder::array resamLayers; + ::coder::array shiftedDat; + ::coder::array simul; + ::coder::array sldProfile; + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisChiSquared; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + real_T thisSsubs; + int32_T b_i; + int32_T b_loop_ub; + int32_T i1; + int32_T loop_ub; + int32_T nParams; + int32_T ub_loop; + boolean_T calcSld; + boolean_T useImaginary; + + // Multi threaded version of the custom layers, nonPolarisedTF reflectivity + // calculation. The function extracts the relevant parameters from the input + // arrays, allocates these on a pre-contrast basis, then calls the 'core' + // calculation (the core layers nonPolarisedTF calc is shared between + // multiple calculation types). + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + calcSld = controls->calcSldDuringFit; + useImaginary = problemDef->useImaginary; + + // Pre-Allocation of output arrays... + backgroundParams.set_size(static_cast + (problemDef->numberOfContrasts)); + + // --- End Memory Allocation --- + // Resampling parameters + // Process the custom models.... + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + problemDef->useImaginary, allLayers, allRoughs); + + // Multi cored over all contrasts + outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); + sldProfiles.set_size(static_cast(problemDef->numberOfContrasts)); + reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); + simulation.set_size(static_cast(problemDef->numberOfContrasts)); + shiftedData.set_size(static_cast(problemDef->numberOfContrasts)); + layerSlds.set_size(static_cast(problemDef->numberOfContrasts)); + chis.set_size(static_cast(problemDef->numberOfContrasts)); + qzshifts.set_size(static_cast(problemDef->numberOfContrasts)); + scalefactors.set_size(static_cast(problemDef->numberOfContrasts)); + bulkIns.set_size(static_cast(problemDef->numberOfContrasts)); + bulkOuts.set_size(static_cast(problemDef->numberOfContrasts)); + resolutionParams.set_size(static_cast + (problemDef->numberOfContrasts)); + ub_loop = static_cast(problemDef->numberOfContrasts) - 1; + +#pragma omp parallel for \ + num_threads(omp_get_max_threads()) \ + private(sldProfile,reflect,simul,shiftedDat,layerSld,resamLayers,thisSsubs,thisChiSquared,thisResol,thisBulkOut,thisBulkIn,thisScalefactor,thisQzshift,thisBackground,b_dv,b_dv1,dv2,loop_ub,b_i,b_loop_ub,i1) + + for (int32_T i = 0; i <= ub_loop; i++) { + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[i], + problemDef->contrastQzshifts[i], + problemDef->contrastScalefactors[i], + problemDef->contrastBulkIns[i], problemDef-> + contrastBulkOuts[i], problemDef->contrastResolutions[i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, + &thisBulkOut, &thisResol); + + // Get the custom layers output for this contrast + // For the other parameters, we extract the correct ones from the input + // arrays + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the reflectivity calculation + b_dv[0] = problemDefCells->f3[i].f1[0]; + b_dv[1] = problemDefCells->f3[i].f1[1]; + b_dv1[0] = problemDefCells->f4[i].f1[0]; + b_dv1[1] = problemDefCells->f4[i].f1[1]; + dv2[0] = problemDefCells->f1[i].f1[0]; + dv2[1] = problemDefCells->f1[i].f1[1]; + coreLayersCalculation(allLayers[i].f1, allRoughs[i], + problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, + thisBulkOut, problemDef->resample[i], calcSld, + thisScalefactor, thisQzshift, + problemDef->dataPresent[i], problemDefCells-> + f2[i].f1, b_dv, b_dv1, dv2, thisBackground, + thisResol, problemDef->contrastBackgroundsType[i], + static_cast(nParams), + controls->resamPars, useImaginary, sldProfile, + reflect, simul, shiftedDat, layerSld, + resamLayers, &thisChiSquared, &thisSsubs); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + outSsubs[i] = thisSsubs; + loop_ub = sldProfile.size(1); + sldProfiles[i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = sldProfile.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + sldProfiles[i].f1[i1 + sldProfiles[i].f1.size(0) * b_i] = + sldProfile[i1 + sldProfile.size(0) * b_i]; + } + } + + loop_ub = reflect.size(0); + reflectivity[i].f1.set_size(reflect.size(0), 2); + b_loop_ub = simul.size(0); + simulation[i].f1.set_size(simul.size(0), 2); + for (b_i = 0; b_i < 2; b_i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + reflectivity[i].f1[i1 + reflectivity[i].f1.size(0) * b_i] = + reflect[i1 + reflect.size(0) * b_i]; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + simulation[i].f1[i1 + simulation[i].f1.size(0) * b_i] = simul[i1 + + simul.size(0) * b_i]; + } + } + + loop_ub = shiftedDat.size(1); + shiftedData[i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = shiftedDat.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + shiftedData[i].f1[i1 + shiftedData[i].f1.size(0) * b_i] = + shiftedDat[i1 + shiftedDat.size(0) * b_i]; + } + } + + loop_ub = layerSld.size(1); + layerSlds[i].f1.set_size(layerSld.size(0), layerSld.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = layerSld.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + layerSlds[i].f1[i1 + layerSlds[i].f1.size(0) * b_i] = layerSld[i1 + + layerSld.size(0) * b_i]; + } + } + + loop_ub = resamLayers.size(1); + allLayers[i].f1.set_size(resamLayers.size(0), resamLayers.size(1)); + for (b_i = 0; b_i < loop_ub; b_i++) { + b_loop_ub = resamLayers.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + allLayers[i].f1[i1 + allLayers[i].f1.size(0) * b_i] = + resamLayers[i1 + resamLayers.size(0) * b_i]; + } + } + + chis[i] = thisChiSquared; + backgroundParams[i] = thisBackground; + qzshifts[i] = thisQzshift; + scalefactors[i] = thisScalefactor; + bulkIns[i] = thisBulkIn; + bulkOuts[i] = thisBulkOut; + resolutionParams[i] = thisResol; + } + } + } + } +} + +// End of code generation (parallelContrasts1.cpp) diff --git a/RAT/parallelContrasts1.h b/RAT/parallelContrasts1.h new file mode 100644 index 00000000..faa38a70 --- /dev/null +++ b/RAT/parallelContrasts1.h @@ -0,0 +1,50 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts1.h +// +// Code generation for function 'parallelContrasts1' +// +#ifndef PARALLELCONTRASTS1_H +#define PARALLELCONTRASTS1_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customLayers + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelContrasts1.h) diff --git a/RAT/parallelContrasts2.cpp b/RAT/parallelContrasts2.cpp new file mode 100644 index 00000000..e9af908c --- /dev/null +++ b/RAT/parallelContrasts2.cpp @@ -0,0 +1,250 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts2.cpp +// +// Code generation for function 'parallelContrasts2' +// + +// Include files +#include "parallelContrasts2.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "applyBackgroundCorrection.h" +#include "backSort.h" +#include "callReflectivity.h" +#include "chiSquared.h" +#include "processCustomFunction1.h" +#include "resampleLayers.h" +#include "resampleLayersReIm.h" +#include "rt_nonfinite.h" +#include "shiftData.h" +#include "coder_array.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customXY + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs) + { + ::coder::array b_problemDefCells; + ::coder::array b_sldProfiles; + ::coder::array layerSld; + ::coder::array reSLD; + ::coder::array reflect; + ::coder::array shiftedDat; + ::coder::array simul; + real_T b_dv[2]; + real_T b_dv1[2]; + real_T d; + real_T d1; + real_T d2; + real_T d3; + real_T d4; + real_T d5; + int32_T b_loop_ub; + int32_T i1; + int32_T i2; + int32_T loop_ub; + int32_T loop_ub_tmp; + int32_T nParams; + boolean_T useImaginary; + + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // % Layers details N/A + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + + // Pre-Allocation... + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(loop_ub_tmp); + outSsubs.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + outSsubs[i] = 0.0; + } + + // Resampling parameters + useImaginary = problemDef->useImaginary; + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + sldProfiles, allRoughs); + qzshifts.set_size(loop_ub_tmp); + scalefactors.set_size(loop_ub_tmp); + bulkIns.set_size(loop_ub_tmp); + bulkOuts.set_size(loop_ub_tmp); + resolutionParams.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + shiftedData.set_size(loop_ub_tmp); + chis.set_size(loop_ub_tmp); + simulation.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + loop_ub_tmp--; + +#pragma omp parallel for \ + num_threads(omp_get_max_threads()) \ + private(b_sldProfiles,b_problemDefCells,reSLD,layerSld,reflect,simul,shiftedDat,d,d1,d2,d3,d4,d5,loop_ub,b_loop_ub,i1,i2,b_dv,b_dv1) + + for (int32_T b_i = 0; b_i <= loop_ub_tmp; b_i++) { + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, &d5, &d4, + &d3, &d2, &d1, &d); + backgroundParams[b_i] = d5; + qzshifts[b_i] = d4; + scalefactors[b_i] = d3; + bulkIns[b_i] = d2; + bulkOuts[b_i] = d1; + resolutionParams[b_i] = d; + + // Resample the layers + if (!useImaginary) { + resampleLayers(sldProfiles[b_i].f1, controls->resamPars, layerSld); + } else { + loop_ub = sldProfiles[b_i].f1.size(0); + reSLD.set_size(sldProfiles[b_i].f1.size(0), 2); + for (i1 = 0; i1 < 2; i1++) { + for (i2 = 0; i2 < loop_ub; i2++) { + reSLD[i2 + reSLD.size(0) * i1] = sldProfiles[b_i].f1[i2 + + sldProfiles[b_i].f1.size(0) * i1]; + } + } + + loop_ub = sldProfiles[b_i].f1.size(0); + b_sldProfiles.set_size(sldProfiles[b_i].f1.size(0), 2); + for (i1 = 0; i1 < loop_ub; i1++) { + b_sldProfiles[i1] = sldProfiles[b_i].f1[i1]; + b_sldProfiles[i1 + b_sldProfiles.size(0)] = sldProfiles[b_i].f1[i1 + + sldProfiles[b_i].f1.size(0) * 2]; + } + + c_resampleLayersReIm(reSLD, b_sldProfiles, controls->resamPars, + layerSld); + } + + layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + loop_ub = layerSld.size(1); + allLayers[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + b_loop_ub = layerSld.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + for (i2 = 0; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = + layerSld[i2 + layerSld.size(0) * i1]; + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + layerSld[i2 + layerSld.size(0) * i1]; + } + } + + b_problemDefCells.set_size(problemDefCells->f2 + [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> + f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); + loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + for (i1 = 0; i1 <= loop_ub; i1++) { + b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + for (i2 = 0; i2 <= b_loop_ub; i2++) { + b_problemDefCells[i2 + b_problemDefCells.size(0) * i1] = + problemDefCells->f2[b_i].f1[i2 + problemDefCells->f2[b_i]. + f1.size(0) * i1]; + } + } + + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> + dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + loop_ub = shiftedDat.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (i2 = 0; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + b_dv[0] = problemDefCells->f4[b_i].f1[0]; + b_dv[1] = problemDefCells->f4[b_i].f1[1]; + b_dv1[0] = problemDefCells->f1[b_i].f1[0]; + b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, + layerSld, 0.0, resolutionParams[b_i], useImaginary, + reflect, simul); + applyBackgroundCorrection(reflect, simul, shiftedDat, + backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + loop_ub = reflect.size(0); + reflectivity[b_i].f1.set_size(reflect.size(0), 2); + b_loop_ub = simul.size(0); + simulation[b_i].f1.set_size(simul.size(0), 2); + for (i1 = 0; i1 < 2; i1++) { + for (i2 = 0; i2 < loop_ub; i2++) { + reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1] = + reflect[i2 + reflect.size(0) * i1]; + } + + for (i2 = 0; i2 < b_loop_ub; i2++) { + simulation[b_i].f1[i2 + simulation[b_i].f1.size(0) * i1] = + simul[i2 + simul.size(0) * i1]; + } + } + + if (problemDef->dataPresent[b_i] != 0.0) { + chis[b_i] = chiSquared(shiftedDat, reflect, static_cast + (nParams)); + } else { + chis[b_i] = 0.0; + } + } + } + } + } +} + +// End of code generation (parallelContrasts2.cpp) diff --git a/RAT/parallelContrasts2.h b/RAT/parallelContrasts2.h new file mode 100644 index 00000000..546f46f1 --- /dev/null +++ b/RAT/parallelContrasts2.h @@ -0,0 +1,50 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts2.h +// +// Code generation for function 'parallelContrasts2' +// +#ifndef PARALLELCONTRASTS2_H +#define PARALLELCONTRASTS2_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customXY + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelContrasts2.h) diff --git a/RAT/parallelContrasts3.cpp b/RAT/parallelContrasts3.cpp new file mode 100644 index 00000000..bd73ec09 --- /dev/null +++ b/RAT/parallelContrasts3.cpp @@ -0,0 +1,392 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts3.cpp +// +// Code generation for function 'parallelContrasts3' +// + +// Include files +#include "parallelContrasts3.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "allocateLayersForContrast.h" +#include "allocateParamsToLayers.h" +#include "averageReflectivity.h" +#include "backSort.h" +#include "chiSquared.h" +#include "coreLayersCalculation.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace standardLayers + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs) + { + ::coder::array outParameterisedLayers; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; + ::coder::array a__6; + ::coder::array reflect1; + ::coder::array reflect2; + ::coder::array shiftedDat; + ::coder::array simul1; + ::coder::array simul2; + ::coder::array thisContrastLayers1_data; + ::coder::array thisContrastLayers2_data; + ::coder::array totReflect; + ::coder::array totSimul; + RATMainTLS *RATMainTLSThread; + cell_wrap_8 r; + cell_wrap_8 r1; + cell_wrap_8 r2; + cell_wrap_8 r3; + cell_wrap_8 r4; + cell_wrap_8 r5; + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + real_T a__5; + real_T a__7; + real_T a__8; + real_T numberOfContrasts; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisChiSquared; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + real_T thisSsubs; + int32_T thisContrastLayers1_size[2]; + int32_T thisContrastLayers2_size[2]; + int32_T b_i; + int32_T b_loop_ub; + int32_T c_i; + int32_T c_loop_ub; + int32_T d_loop_ub; + int32_T i; + int32_T i1; + int32_T i2; + int32_T i3; + int32_T loop_ub; + int32_T nParams; + int32_T ub_loop; + boolean_T calcSld; + boolean_T useImaginary; + RATMainTLSThread = emlrtGetThreadStackData(); + + // Single threaded version of the Standard Layers calculation + // This is the main reflectivity calculation of the standard layers + // calculation type. It extracts the required parameters for the contrasts + // from the input arrays, then passes the main calculation to + // 'standardLayersCore', which carries out the calculation itself. + // The core calculation is common for both standard and custom layers. + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Additionally extract the additional domain layers details + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + numberOfContrasts = problemDef->numberOfContrasts; + calcSld = controls->calcSldDuringFit; + useImaginary = problemDef->useImaginary; + + // Default for compile. + // Allocate the memory for the output arrays before the main loop + backgroundParams.set_size(static_cast + (problemDef->numberOfContrasts)); + + // end memory allocation. + // First we need to allocate the absolute values of the input + // parameters to all the layers in the layers list. This only needs + // to be done once, and so is done outside the contrasts loop + allocateParamsToLayers(problemDef->params, problemDefCells->f6, + outParameterisedLayers); + + // Resample params if requiired + // Loop over all the contrasts + outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); + tempSldProfiles.set_size(static_cast + (problemDef->numberOfContrasts)); + reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); + simulation.set_size(static_cast(problemDef->numberOfContrasts)); + shiftedData.set_size(static_cast(problemDef->numberOfContrasts)); + tempLayerSlds.set_size(static_cast + (problemDef->numberOfContrasts)); + tempAllLayers.set_size(static_cast + (problemDef->numberOfContrasts)); + chis.set_size(static_cast(problemDef->numberOfContrasts)); + qzshifts.set_size(static_cast(problemDef->numberOfContrasts)); + scalefactors.set_size(static_cast(problemDef->numberOfContrasts)); + bulkIns.set_size(static_cast(problemDef->numberOfContrasts)); + bulkOuts.set_size(static_cast(problemDef->numberOfContrasts)); + resolutionParams.set_size(static_cast + (problemDef->numberOfContrasts)); + allRoughs.set_size(static_cast(problemDef->numberOfContrasts)); + layerSlds.set_size(static_cast(problemDef->numberOfContrasts), + 2); + allLayers.set_size(static_cast(problemDef->numberOfContrasts), + 2); + domainSldProfiles.set_size(static_cast + (problemDef->numberOfContrasts), 2); + ub_loop = static_cast(problemDef->numberOfContrasts) - 1; + +#pragma omp parallel \ + num_threads(omp_get_max_threads()) \ + private(RATMainTLSThread,r,r1,r2,r3,reflect1,simul1,shiftedDat,r4,reflect2,simul2,a__6,r5,totReflect,totSimul,thisChiSquared,a__8,a__7,thisSsubs,a__5,thisContrastLayers2_size,thisContrastLayers1_size,thisResol,thisBulkOut,thisBulkIn,thisScalefactor,thisQzshift,thisBackground,b_dv,b_dv1,dv2,c_loop_ub,d_loop_ub,i2,i3) \ + firstprivate(thisContrastLayers1_data,thisContrastLayers2_data) + + { + RATMainTLSThread = emlrtGetThreadStackData(); + +#pragma omp for nowait + + for (i = 0; i <= ub_loop; i++) { + // Get the domain ratio for this contrast + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[i], + problemDef->contrastQzshifts[i], + problemDef->contrastScalefactors[i], + problemDef->contrastBulkIns[i], + problemDef->contrastBulkOuts[i], + problemDef->contrastResolutions[i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, + &thisBulkIn, &thisBulkOut, &thisResol); + + // Also need to determine which layers from the overall layers list + // are required for this contrast, and put them in the correct order + // according to geometry. We run it twice, once for each domain... + allocateLayersForContrast(problemDefCells->f19[0].f1, + outParameterisedLayers, useImaginary, + RATMainTLSThread->f3.thisContrastLayers1_data, + thisContrastLayers1_size); + allocateLayersForContrast(problemDefCells->f19[1].f1, + outParameterisedLayers, useImaginary, + RATMainTLSThread->f3.thisContrastLayers2_data, + thisContrastLayers2_size); + + // For the other parameters, we extract the correct ones from the input + // arrays + // Substrate roughness is always first parameter for standard layers + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the core layers calculation - need to do this once for each + // domain + thisContrastLayers1_data.set + (&RATMainTLSThread->f3.thisContrastLayers1_data[0], + thisContrastLayers1_size[0], thisContrastLayers1_size[1]); + b_dv[0] = problemDefCells->f3[i].f1[0]; + b_dv[1] = problemDefCells->f3[i].f1[1]; + b_dv1[0] = problemDefCells->f4[i].f1[0]; + b_dv1[1] = problemDefCells->f4[i].f1[1]; + dv2[0] = problemDefCells->f1[i].f1[0]; + dv2[1] = problemDefCells->f1[i].f1[1]; + nonPolarisedTF::coreLayersCalculation(thisContrastLayers1_data, + problemDef->params[0], problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, thisBulkOut, + problemDef->resample[i], calcSld, thisScalefactor, thisQzshift, + problemDef->dataPresent[i], problemDefCells->f2[i].f1, b_dv, b_dv1, + dv2, thisBackground, thisResol, + problemDef->contrastBackgroundsType[i], static_cast + (nParams), controls->resamPars, useImaginary, r3.f1, reflect1, + simul1, shiftedDat, r2.f1, r4.f1, &a__5, &thisSsubs); + thisContrastLayers2_data.set + (&RATMainTLSThread->f3.thisContrastLayers2_data[0], + thisContrastLayers2_size[0], thisContrastLayers2_size[1]); + b_dv[0] = problemDefCells->f3[i].f1[0]; + b_dv[1] = problemDefCells->f3[i].f1[1]; + b_dv1[0] = problemDefCells->f4[i].f1[0]; + b_dv1[1] = problemDefCells->f4[i].f1[1]; + dv2[0] = problemDefCells->f1[i].f1[0]; + dv2[1] = problemDefCells->f1[i].f1[1]; + nonPolarisedTF::coreLayersCalculation(thisContrastLayers2_data, + problemDef->params[0], problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, thisBulkOut, + problemDef->resample[i], calcSld, thisScalefactor, thisQzshift, + problemDef->dataPresent[i], problemDefCells->f2[i].f1, b_dv, b_dv1, + dv2, thisBackground, thisResol, + problemDef->contrastBackgroundsType[i], static_cast + (nParams), controls->resamPars, useImaginary, r1.f1, reflect2, + simul2, a__6, r.f1, r5.f1, &a__7, &a__8); + + // Calculate the average reflectivities.... + averageReflectivity(reflect1, reflect2, simul1, simul2, + problemDef->domainRatio[static_cast + (problemDef->contrastDomainRatios[i]) - 1], + totReflect, totSimul); + + // Get an overall chi-squared for the new averaged curve.. + thisChiSquared = chiSquared(shiftedDat, totReflect, static_cast< + real_T>(problemDef->params.size(1))); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + outSsubs[i] = thisSsubs; + tempSldProfiles[i].f1[0] = r3; + tempSldProfiles[i].f1[1] = r1; + reflectivity[i].f1.set_size(totReflect.size(0), 2); + c_loop_ub = totSimul.size(0); + simulation[i].f1.set_size(totSimul.size(0), 2); + d_loop_ub = totReflect.size(0); + for (i2 = 0; i2 < 2; i2++) { + for (i3 = 0; i3 < d_loop_ub; i3++) { + reflectivity[i].f1[i3 + reflectivity[i].f1.size(0) * i2] = + totReflect[i3 + totReflect.size(0) * i2]; + } + + for (i3 = 0; i3 < c_loop_ub; i3++) { + simulation[i].f1[i3 + simulation[i].f1.size(0) * i2] = + totSimul[i3 + totSimul.size(0) * i2]; + } + } + + shiftedData[i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + c_loop_ub = shiftedDat.size(1); + for (i2 = 0; i2 < c_loop_ub; i2++) { + d_loop_ub = shiftedDat.size(0); + for (i3 = 0; i3 < d_loop_ub; i3++) { + shiftedData[i].f1[i3 + shiftedData[i].f1.size(0) * i2] = + shiftedDat[i3 + shiftedDat.size(0) * i2]; + } + } + + tempLayerSlds[i].f1[0] = r2; + tempLayerSlds[i].f1[1] = r; + tempAllLayers[i].f1[0] = r4; + tempAllLayers[i].f1[1] = r5; + chis[i] = thisChiSquared; + backgroundParams[i] = thisBackground; + qzshifts[i] = thisQzshift; + scalefactors[i] = thisScalefactor; + bulkIns[i] = thisBulkIn; + bulkOuts[i] = thisBulkOut; + resolutionParams[i] = thisResol; + allRoughs[i] = problemDef->params[0]; + } + } + + ub_loop = static_cast(numberOfContrasts); + for (b_i = 0; b_i < ub_loop; b_i++) { + loop_ub = tempSldProfiles[b_i].f1[0].f1.size(1); + domainSldProfiles[b_i].f1.set_size(tempSldProfiles[b_i].f1[0].f1.size + (0), tempSldProfiles[b_i].f1[0].f1.size(1)); + for (c_i = 0; c_i < loop_ub; c_i++) { + b_loop_ub = tempSldProfiles[b_i].f1[0].f1.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + domainSldProfiles[b_i].f1[i1 + domainSldProfiles[b_i].f1.size(0) * + c_i] = tempSldProfiles[b_i].f1[0].f1[i1 + tempSldProfiles[b_i]. + f1[0].f1.size(0) * c_i]; + } + } + + loop_ub = tempSldProfiles[b_i].f1[1].f1.size(1); + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.set_size + (tempSldProfiles[b_i].f1[1].f1.size(0), tempSldProfiles[b_i].f1[1]. + f1.size(1)); + for (c_i = 0; c_i < loop_ub; c_i++) { + b_loop_ub = tempSldProfiles[b_i].f1[1].f1.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i1 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + c_i] = tempSldProfiles[b_i].f1[1].f1[i1 + tempSldProfiles[b_i]. + f1[1].f1.size(0) * c_i]; + } + } + + loop_ub = tempAllLayers[b_i].f1[0].f1.size(1); + allLayers[b_i].f1.set_size(tempAllLayers[b_i].f1[0].f1.size(0), + tempAllLayers[b_i].f1[0].f1.size(1)); + for (c_i = 0; c_i < loop_ub; c_i++) { + b_loop_ub = tempAllLayers[b_i].f1[0].f1.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + allLayers[b_i].f1[i1 + allLayers[b_i].f1.size(0) * c_i] = + tempAllLayers[b_i].f1[0].f1[i1 + tempAllLayers[b_i].f1[0]. + f1.size(0) * c_i]; + } + } + + loop_ub = tempAllLayers[b_i].f1[1].f1.size(1); + allLayers[b_i + allLayers.size(0)].f1.set_size(tempAllLayers[b_i].f1[1] + .f1.size(0), tempAllLayers[b_i].f1[1].f1.size(1)); + for (c_i = 0; c_i < loop_ub; c_i++) { + b_loop_ub = tempAllLayers[b_i].f1[1].f1.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + allLayers[b_i + allLayers.size(0)].f1[i1 + allLayers[b_i + + allLayers.size(0)].f1.size(0) * c_i] = tempAllLayers[b_i].f1[1]. + f1[i1 + tempAllLayers[b_i].f1[1].f1.size(0) * c_i]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[0].f1.size(1); + layerSlds[b_i].f1.set_size(tempLayerSlds[b_i].f1[0].f1.size(0), + tempLayerSlds[b_i].f1[0].f1.size(1)); + for (c_i = 0; c_i < loop_ub; c_i++) { + b_loop_ub = tempLayerSlds[b_i].f1[0].f1.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + layerSlds[b_i].f1[i1 + layerSlds[b_i].f1.size(0) * c_i] = + tempLayerSlds[b_i].f1[0].f1[i1 + tempLayerSlds[b_i].f1[0]. + f1.size(0) * c_i]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[1].f1.size(1); + layerSlds[b_i + layerSlds.size(0)].f1.set_size(tempLayerSlds[b_i].f1[1] + .f1.size(0), tempLayerSlds[b_i].f1[1].f1.size(1)); + for (c_i = 0; c_i < loop_ub; c_i++) { + b_loop_ub = tempLayerSlds[b_i].f1[1].f1.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + layerSlds[b_i + layerSlds.size(0)].f1[i1 + layerSlds[b_i + + layerSlds.size(0)].f1.size(0) * c_i] = tempLayerSlds[b_i].f1[1]. + f1[i1 + tempLayerSlds[b_i].f1[1].f1.size(0) * c_i]; + } + } + } + } + } + } +} + +// End of code generation (parallelContrasts3.cpp) diff --git a/RAT/parallelContrasts3.h b/RAT/parallelContrasts3.h new file mode 100644 index 00000000..272bc2da --- /dev/null +++ b/RAT/parallelContrasts3.h @@ -0,0 +1,50 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts3.h +// +// Code generation for function 'parallelContrasts3' +// +#ifndef PARALLELCONTRASTS3_H +#define PARALLELCONTRASTS3_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace standardLayers + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelContrasts3.h) diff --git a/RAT/parallelContrasts4.cpp b/RAT/parallelContrasts4.cpp new file mode 100644 index 00000000..0e0a21ea --- /dev/null +++ b/RAT/parallelContrasts4.cpp @@ -0,0 +1,367 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts4.cpp +// +// Code generation for function 'parallelContrasts4' +// + +// Include files +#include "parallelContrasts4.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "averageReflectivity.h" +#include "backSort.h" +#include "chiSquared.h" +#include "coreLayersCalculation.h" +#include "processCustomFunction2.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include "omp.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace customLayers + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs) + { + ::coder::array r; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; + ::coder::array calcAllLayers; + ::coder::array a__5; + ::coder::array reflect1; + ::coder::array reflect2; + ::coder::array shiftedDat; + ::coder::array simul1; + ::coder::array simul2; + ::coder::array totReflect; + ::coder::array totSimul; + cell_wrap_8 r1; + cell_wrap_8 r2; + cell_wrap_8 r3; + cell_wrap_8 r4; + cell_wrap_8 r5; + cell_wrap_8 r6; + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + real_T a__4; + real_T a__6; + real_T a__7; + real_T numberOfContrasts; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisChiSquared; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + real_T thisSsubs; + int32_T c_loop_ub; + int32_T d_loop_ub; + int32_T i2; + int32_T i3; + int32_T nParams; + int32_T ub_loop; + boolean_T calcSld; + boolean_T useImaginary; + + // Single threaded version of the custom layers, domainsTF reflectivity + // calculation. The function extracts the relevant parameters from the input + // arrays, allocates these on a pre-contrast basis, then calls the 'core' + // calculation (the core layers domainsTF calc is shared between multiple + // calculation types). + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + numberOfContrasts = problemDef->numberOfContrasts; + calcSld = controls->calcSldDuringFit; + useImaginary = problemDef->useImaginary; + + // Default for compile. + // Pre-Allocation of output arrays... + backgroundParams.set_size(static_cast + (problemDef->numberOfContrasts)); + + // Resampling parameters + // Process the custom models.... + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + problemDef->useImaginary, r, allRoughs); + cast(r, calcAllLayers); + + // Parallel over all contrasts + // layersCounter = 1; + outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); + tempSldProfiles.set_size(static_cast + (problemDef->numberOfContrasts)); + reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); + simulation.set_size(static_cast(problemDef->numberOfContrasts)); + shiftedData.set_size(static_cast(problemDef->numberOfContrasts)); + tempLayerSlds.set_size(static_cast + (problemDef->numberOfContrasts)); + tempAllLayers.set_size(static_cast + (problemDef->numberOfContrasts)); + chis.set_size(static_cast(problemDef->numberOfContrasts)); + qzshifts.set_size(static_cast(problemDef->numberOfContrasts)); + scalefactors.set_size(static_cast(problemDef->numberOfContrasts)); + bulkIns.set_size(static_cast(problemDef->numberOfContrasts)); + bulkOuts.set_size(static_cast(problemDef->numberOfContrasts)); + resolutionParams.set_size(static_cast + (problemDef->numberOfContrasts)); + layerSlds.set_size(static_cast(problemDef->numberOfContrasts), + 2); + allLayers.set_size(static_cast(problemDef->numberOfContrasts), + 2); + domainSldProfiles.set_size(static_cast + (problemDef->numberOfContrasts), 2); + ub_loop = static_cast(problemDef->numberOfContrasts) - 1; + +#pragma omp parallel for \ + num_threads(omp_get_max_threads()) \ + private(r1,r2,reflect1,simul1,shiftedDat,r3,r4,reflect2,simul2,a__5,r5,r6,totReflect,totSimul,thisChiSquared,a__7,a__6,thisSsubs,a__4,thisResol,thisBulkOut,thisBulkIn,thisScalefactor,thisQzshift,thisBackground,b_dv,b_dv1,dv2,c_loop_ub,d_loop_ub,i2,i3) + + for (int32_T i = 0; i <= ub_loop; i++) { + // Get the domain ratio for this contrast + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[i], + problemDef->contrastQzshifts[i], + problemDef->contrastScalefactors[i], + problemDef->contrastBulkIns[i], problemDef-> + contrastBulkOuts[i], problemDef->contrastResolutions[i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, + &thisBulkOut, &thisResol); + + // Get the custom layers output for this contrast + // We have two for each contrast - one for each domain + // For the other parameters, we extract the correct ones from the input + // arrays + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the reflectivity calculation for each domain + // Domain 1 + b_dv[0] = problemDefCells->f3[i].f1[0]; + b_dv[1] = problemDefCells->f3[i].f1[1]; + b_dv1[0] = problemDefCells->f4[i].f1[0]; + b_dv1[1] = problemDefCells->f4[i].f1[1]; + dv2[0] = problemDefCells->f1[i].f1[0]; + dv2[1] = problemDefCells->f1[i].f1[1]; + nonPolarisedTF::coreLayersCalculation(calcAllLayers[i].f1, allRoughs[i], + problemDef->geometry.data, problemDef->geometry.size, thisBulkIn, + thisBulkOut, problemDef->resample[i], calcSld, thisScalefactor, + thisQzshift, problemDef->dataPresent[i], problemDefCells->f2[i].f1, + b_dv, b_dv1, dv2, thisBackground, thisResol, + problemDef->contrastBackgroundsType[i], static_cast(nParams), + controls->resamPars, useImaginary, r2.f1, reflect1, simul1, + shiftedDat, r3.f1, r4.f1, &a__4, &thisSsubs); + + // Domain 2 + b_dv[0] = problemDefCells->f3[i].f1[0]; + b_dv[1] = problemDefCells->f3[i].f1[1]; + b_dv1[0] = problemDefCells->f4[i].f1[0]; + b_dv1[1] = problemDefCells->f4[i].f1[1]; + dv2[0] = problemDefCells->f1[i].f1[0]; + dv2[1] = problemDefCells->f1[i].f1[1]; + nonPolarisedTF::coreLayersCalculation(calcAllLayers[i + + calcAllLayers.size(0)].f1, allRoughs[i], problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, thisBulkOut, + problemDef->resample[i], calcSld, thisScalefactor, thisQzshift, + problemDef->dataPresent[i], problemDefCells->f2[i].f1, b_dv, b_dv1, + dv2, thisBackground, thisResol, problemDef-> + contrastBackgroundsType[i], static_cast(nParams), + controls->resamPars, useImaginary, r1.f1, reflect2, simul2, a__5, + r5.f1, r6.f1, &a__6, &a__7); + + // Calculate the average reflectivities.... + averageReflectivity(reflect1, reflect2, simul1, simul2, + problemDef->domainRatio[static_cast + (problemDef->contrastDomainRatios[i]) - 1], + totReflect, totSimul); + + // Get an overall chi-squared for the new averaged curve.. + thisChiSquared = chiSquared(shiftedDat, totReflect, static_cast + (problemDef->params.size(1))); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + outSsubs[i] = thisSsubs; + + // domainSldProfiles{i,1} = sldProfile1; + // domainSldProfiles{i,2} = sldProfile2; + tempSldProfiles[i].f1[0] = r2; + tempSldProfiles[i].f1[1] = r1; + reflectivity[i].f1.set_size(totReflect.size(0), 2); + c_loop_ub = totSimul.size(0); + simulation[i].f1.set_size(totSimul.size(0), 2); + d_loop_ub = totReflect.size(0); + for (i2 = 0; i2 < 2; i2++) { + for (i3 = 0; i3 < d_loop_ub; i3++) { + reflectivity[i].f1[i3 + reflectivity[i].f1.size(0) * i2] = + totReflect[i3 + totReflect.size(0) * i2]; + } + + for (i3 = 0; i3 < c_loop_ub; i3++) { + simulation[i].f1[i3 + simulation[i].f1.size(0) * i2] = totSimul[i3 + + totSimul.size(0) * i2]; + } + } + + shiftedData[i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + c_loop_ub = shiftedDat.size(1); + for (i2 = 0; i2 < c_loop_ub; i2++) { + d_loop_ub = shiftedDat.size(0); + for (i3 = 0; i3 < d_loop_ub; i3++) { + shiftedData[i].f1[i3 + shiftedData[i].f1.size(0) * i2] = + shiftedDat[i3 + shiftedDat.size(0) * i2]; + } + } + + tempLayerSlds[i].f1[0] = r3; + tempLayerSlds[i].f1[1] = r5; + tempAllLayers[i].f1[0] = r4; + tempAllLayers[i].f1[1] = r6; + chis[i] = thisChiSquared; + backgroundParams[i] = thisBackground; + qzshifts[i] = thisQzshift; + scalefactors[i] = thisScalefactor; + bulkIns[i] = thisBulkIn; + bulkOuts[i] = thisBulkOut; + resolutionParams[i] = thisResol; + } + + ub_loop = static_cast(numberOfContrasts); + for (int32_T b_i{0}; b_i < ub_loop; b_i++) { + int32_T b_loop_ub; + int32_T loop_ub; + loop_ub = tempSldProfiles[b_i].f1[0].f1.size(1); + domainSldProfiles[b_i].f1.set_size(tempSldProfiles[b_i].f1[0].f1.size + (0), tempSldProfiles[b_i].f1[0].f1.size(1)); + for (int32_T c_i{0}; c_i < loop_ub; c_i++) { + b_loop_ub = tempSldProfiles[b_i].f1[0].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + domainSldProfiles[b_i].f1[i1 + domainSldProfiles[b_i].f1.size(0) * + c_i] = tempSldProfiles[b_i].f1[0].f1[i1 + tempSldProfiles[b_i]. + f1[0].f1.size(0) * c_i]; + } + } + + loop_ub = tempSldProfiles[b_i].f1[1].f1.size(1); + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.set_size + (tempSldProfiles[b_i].f1[1].f1.size(0), tempSldProfiles[b_i].f1[1]. + f1.size(1)); + for (int32_T c_i{0}; c_i < loop_ub; c_i++) { + b_loop_ub = tempSldProfiles[b_i].f1[1].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i1 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + c_i] = tempSldProfiles[b_i].f1[1].f1[i1 + tempSldProfiles[b_i]. + f1[1].f1.size(0) * c_i]; + } + } + + loop_ub = tempAllLayers[b_i].f1[0].f1.size(1); + allLayers[b_i].f1.set_size(tempAllLayers[b_i].f1[0].f1.size(0), + tempAllLayers[b_i].f1[0].f1.size(1)); + for (int32_T c_i{0}; c_i < loop_ub; c_i++) { + b_loop_ub = tempAllLayers[b_i].f1[0].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + allLayers[b_i].f1[i1 + allLayers[b_i].f1.size(0) * c_i] = + tempAllLayers[b_i].f1[0].f1[i1 + tempAllLayers[b_i].f1[0]. + f1.size(0) * c_i]; + } + } + + loop_ub = tempAllLayers[b_i].f1[1].f1.size(1); + allLayers[b_i + allLayers.size(0)].f1.set_size(tempAllLayers[b_i].f1[1] + .f1.size(0), tempAllLayers[b_i].f1[1].f1.size(1)); + for (int32_T c_i{0}; c_i < loop_ub; c_i++) { + b_loop_ub = tempAllLayers[b_i].f1[1].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + allLayers[b_i + allLayers.size(0)].f1[i1 + allLayers[b_i + + allLayers.size(0)].f1.size(0) * c_i] = tempAllLayers[b_i].f1[1]. + f1[i1 + tempAllLayers[b_i].f1[1].f1.size(0) * c_i]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[0].f1.size(1); + layerSlds[b_i].f1.set_size(tempLayerSlds[b_i].f1[0].f1.size(0), + tempLayerSlds[b_i].f1[0].f1.size(1)); + for (int32_T c_i{0}; c_i < loop_ub; c_i++) { + b_loop_ub = tempLayerSlds[b_i].f1[0].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + layerSlds[b_i].f1[i1 + layerSlds[b_i].f1.size(0) * c_i] = + tempLayerSlds[b_i].f1[0].f1[i1 + tempLayerSlds[b_i].f1[0]. + f1.size(0) * c_i]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[1].f1.size(1); + layerSlds[b_i + layerSlds.size(0)].f1.set_size(tempLayerSlds[b_i].f1[1] + .f1.size(0), tempLayerSlds[b_i].f1[1].f1.size(1)); + for (int32_T c_i{0}; c_i < loop_ub; c_i++) { + b_loop_ub = tempLayerSlds[b_i].f1[1].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + layerSlds[b_i + layerSlds.size(0)].f1[i1 + layerSlds[b_i + + layerSlds.size(0)].f1.size(0) * c_i] = tempLayerSlds[b_i].f1[1]. + f1[i1 + tempLayerSlds[b_i].f1[1].f1.size(0) * c_i]; + } + } + } + } + } + } +} + +// End of code generation (parallelContrasts4.cpp) diff --git a/RAT/parallelContrasts4.h b/RAT/parallelContrasts4.h new file mode 100644 index 00000000..1632d70e --- /dev/null +++ b/RAT/parallelContrasts4.h @@ -0,0 +1,50 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts4.h +// +// Code generation for function 'parallelContrasts4' +// +#ifndef PARALLELCONTRASTS4_H +#define PARALLELCONTRASTS4_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace customLayers + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelContrasts4.h) diff --git a/RAT/parallelContrasts5.cpp b/RAT/parallelContrasts5.cpp new file mode 100644 index 00000000..67f09a6f --- /dev/null +++ b/RAT/parallelContrasts5.cpp @@ -0,0 +1,405 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts5.cpp +// +// Code generation for function 'parallelContrasts5' +// + +// Include files +#include "parallelContrasts5.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "applyBackgroundCorrection.h" +#include "averageReflectivity.h" +#include "backSort.h" +#include "callReflectivity.h" +#include "chiSquared.h" +#include "processCustomFunction3.h" +#include "resampleLayers.h" +#include "resampleLayersReIm.h" +#include "rt_nonfinite.h" +#include "shiftData.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace customXY + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs) + { + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; + ::coder::array b_domainSldProfiles; + ::coder::array b_problemDefCells; + ::coder::array c_domainSldProfiles; + ::coder::array r4; + ::coder::array reflect1; + ::coder::array reflect2; + ::coder::array shiftedDat; + ::coder::array simul1; + ::coder::array simul2; + ::coder::array totReflect; + cell_wrap_8 r; + cell_wrap_8 r1; + cell_wrap_8 r2; + cell_wrap_8 r3; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + boolean_T useImaginary; + + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // % Layers details N/A + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + // Pre-Allocation... + i = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(i); + + // Resampling parameters + useImaginary = problemDef->useImaginary; + + // Default for compile. + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + domainSldProfiles, allRoughs); + outSsubs.set_size(i); + qzshifts.set_size(i); + scalefactors.set_size(i); + bulkIns.set_size(i); + bulkOuts.set_size(i); + resolutionParams.set_size(i); + tempLayerSlds.set_size(i); + tempAllLayers.set_size(i); + tempSldProfiles.set_size(i); + shiftedData.set_size(i); + reflectivity.set_size(i); + simulation.set_size(i); + chis.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T b_dv[2]; + real_T b_dv1[2]; + outSsubs[b_i] = allRoughs[b_i]; + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &backgroundParams[b_i], &qzshifts[b_i], &scalefactors[b_i], + &bulkIns[b_i], &bulkOuts[b_i], &resolutionParams[b_i]); + + // Get the domain ratio for this contrast + // Resample the sld profiles + if (!useImaginary) { + resampleLayers(domainSldProfiles[0].f1, controls->resamPars, r.f1); + r1.f1.set_size(r.f1.size(0), 3); + for (int32_T i1{0}; i1 < 3; i1++) { + loop_ub = r.f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + r1.f1[i2 + r1.f1.size(0) * i1] = r.f1[i2 + r.f1.size(0) * i1]; + } + } + + resampleLayers(domainSldProfiles[1].f1, controls->resamPars, r.f1); + } else { + loop_ub = domainSldProfiles[0].f1.size(0); + b_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = + domainSldProfiles[0].f1[i2 + domainSldProfiles[0].f1.size(0) * + i1]; + } + } + + loop_ub = domainSldProfiles[0].f1.size(0); + b_loop_ub = domainSldProfiles[0].f1.size(0); + c_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[0].f1[i1]; + } + + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = + domainSldProfiles[0].f1[i1 + domainSldProfiles[0].f1.size(0) * 2]; + } + + c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + controls->resamPars, r.f1); + r1.f1.set_size(r.f1.size(0), 4); + for (int32_T i1{0}; i1 < 4; i1++) { + loop_ub = r.f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + r1.f1[i2 + r1.f1.size(0) * i1] = r.f1[i2 + r.f1.size(0) * i1]; + } + } + + loop_ub = domainSldProfiles[1].f1.size(0); + b_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = + domainSldProfiles[1].f1[i2 + domainSldProfiles[1].f1.size(0) * + i1]; + } + } + + loop_ub = domainSldProfiles[1].f1.size(0); + b_loop_ub = domainSldProfiles[1].f1.size(0); + c_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[1].f1[i1]; + } + + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = + domainSldProfiles[1].f1[i1 + domainSldProfiles[1].f1.size(0) * 2]; + } + + c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + controls->resamPars, r.f1); + } + + tempLayerSlds[b_i].f1[0] = r1; + tempLayerSlds[b_i].f1[1] = r; + tempAllLayers[b_i].f1[0] = r1; + tempAllLayers[b_i].f1[1] = r; + r2.f1.set_size(domainSldProfiles[0].f1.size(0), domainSldProfiles[0]. + f1.size(1)); + loop_ub = domainSldProfiles[0].f1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = domainSldProfiles[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + r2.f1[i2 + r2.f1.size(0) * i1] = domainSldProfiles[0].f1[i2 + + domainSldProfiles[0].f1.size(0) * i1]; + } + } + + r3.f1.set_size(domainSldProfiles[1].f1.size(0), domainSldProfiles[1]. + f1.size(1)); + loop_ub = domainSldProfiles[1].f1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = domainSldProfiles[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + r3.f1[i2 + r3.f1.size(0) * i1] = domainSldProfiles[1].f1[i2 + + domainSldProfiles[1].f1.size(0) * i1]; + } + } + + tempSldProfiles[b_i].f1[0] = r2; + tempSldProfiles[b_i].f1[1] = r3; + b_problemDefCells.set_size(problemDefCells->f2 + [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> + f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); + loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { + b_problemDefCells[i2 + b_problemDefCells.size(0) * i1] = + problemDefCells->f2[b_i].f1[i2 + problemDefCells->f2[b_i]. + f1.size(0) * i1]; + } + } + + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> + dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + loop_ub = shiftedDat.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + r4.set_size(r1.f1.size(0), r1.f1.size(1)); + loop_ub = r1.f1.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_loop_ub = r1.f1.size(0) - 1; + for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { + r4[i2 + r4.size(0) * i1] = r1.f1[i2 + r1.f1.size(0) * i1]; + } + } + + b_dv[0] = problemDefCells->f4[b_i].f1[0]; + b_dv[1] = problemDefCells->f4[b_i].f1[1]; + b_dv1[0] = problemDefCells->f1[b_i].f1[0]; + b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, + r4, allRoughs[b_i], resolutionParams[b_i], + useImaginary, reflect1, simul1); + r4.set_size(r.f1.size(0), r.f1.size(1)); + loop_ub = r.f1.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_loop_ub = r.f1.size(0) - 1; + for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { + r4[i2 + r4.size(0) * i1] = r.f1[i2 + r.f1.size(0) * i1]; + } + } + + b_dv[0] = problemDefCells->f4[b_i].f1[0]; + b_dv[1] = problemDefCells->f4[b_i].f1[1]; + b_dv1[0] = problemDefCells->f1[b_i].f1[0]; + b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, + r4, allRoughs[b_i], resolutionParams[b_i], + useImaginary, reflect2, simul2); + applyBackgroundCorrection(reflect1, simul1, shiftedDat, + backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + applyBackgroundCorrection(reflect2, simul2, shiftedDat, + backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + + // Calculate the average reflectivities.... + averageReflectivity(reflect1, reflect2, simul1, simul2, + problemDef->domainRatio[static_cast + (problemDef->contrastDomainRatios[b_i]) - 1], + totReflect, simulation[b_i].f1); + loop_ub = totReflect.size(0); + reflectivity[b_i].f1.set_size(totReflect.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1] = + totReflect[i2 + totReflect.size(0) * i1]; + } + } + + if (problemDef->dataPresent[b_i] != 0.0) { + chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast + (problemDef->params.size(1))); + } else { + chis[b_i] = 0.0; + } + } + + allLayers.set_size(i, 2); + layerSlds.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + loop_ub = tempSldProfiles[b_i].f1[0].f1.size(1); + domainSldProfiles[b_i].f1.set_size(tempSldProfiles[b_i].f1[0].f1.size + (0), tempSldProfiles[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i].f1[i2 + domainSldProfiles[b_i].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[0].f1[i2 + tempSldProfiles[b_i] + .f1[0].f1.size(0) * i1]; + } + } + + loop_ub = tempSldProfiles[b_i].f1[1].f1.size(1); + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.set_size + (tempSldProfiles[b_i].f1[1].f1.size(0), tempSldProfiles[b_i].f1[1]. + f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i2 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[1].f1[i2 + tempSldProfiles[b_i] + .f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[0].f1.size(1); + allLayers[b_i].f1.set_size(tempAllLayers[b_i].f1[0].f1.size(0), + tempAllLayers[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + tempAllLayers[b_i].f1[0].f1[i2 + tempAllLayers[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[1].f1.size(1); + allLayers[b_i + allLayers.size(0)].f1.set_size(tempAllLayers[b_i].f1[1] + .f1.size(0), tempAllLayers[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i + allLayers.size(0)].f1[i2 + allLayers[b_i + + allLayers.size(0)].f1.size(0) * i1] = tempAllLayers[b_i].f1[1]. + f1[i2 + tempAllLayers[b_i].f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[0].f1.size(1); + layerSlds[b_i].f1.set_size(tempLayerSlds[b_i].f1[0].f1.size(0), + tempLayerSlds[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = + tempLayerSlds[b_i].f1[0].f1[i2 + tempLayerSlds[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[1].f1.size(1); + layerSlds[b_i + layerSlds.size(0)].f1.set_size(tempLayerSlds[b_i].f1[1] + .f1.size(0), tempLayerSlds[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i + layerSlds.size(0)].f1[i2 + layerSlds[b_i + + layerSlds.size(0)].f1.size(0) * i1] = tempLayerSlds[b_i].f1[1]. + f1[i2 + tempLayerSlds[b_i].f1[1].f1.size(0) * i1]; + } + } + } + } + } + } +} + +// End of code generation (parallelContrasts5.cpp) diff --git a/RAT/parallelContrasts5.h b/RAT/parallelContrasts5.h new file mode 100644 index 00000000..ec38d939 --- /dev/null +++ b/RAT/parallelContrasts5.h @@ -0,0 +1,50 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelContrasts5.h +// +// Code generation for function 'parallelContrasts5' +// +#ifndef PARALLELCONTRASTS5_H +#define PARALLELCONTRASTS5_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace customXY + { + void c_parallelContrasts(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, ::coder::array< + real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: + array &bulkIns, ::coder::array &bulkOuts, :: + coder::array &resolutionParams, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array + &allLayers, ::coder::array &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelContrasts5.h) diff --git a/RAT/parallelPoints.cpp b/RAT/parallelPoints.cpp new file mode 100644 index 00000000..078f77b6 --- /dev/null +++ b/RAT/parallelPoints.cpp @@ -0,0 +1,205 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints.cpp +// +// Code generation for function 'parallelPoints' +// + +// Include files +#include "parallelPoints.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "allocateLayersForContrast.h" +#include "allocateParamsToLayers.h" +#include "backSort.h" +#include "coreLayersCalculation.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace standardLayers + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 1U> &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs) + { + static real_T thisContrastLayers_data[6000]; + ::coder::array outParameterisedLayers; + ::coder::array b_thisContrastLayers_data; + ::coder::array shiftedDat; + ::coder::array sldProfile; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + int32_T i; + boolean_T useImaginary; + + // Standard Layers calculation paralelised over the inner loop + // This is the main reflectivity calculation of the standard layers + // calculation type. It extracts the required parameters for the contrasts + // from the input arrays, then passes the main calculation to + // 'standardLayersCore', which carries out the calculation iteself. + // The core calculation is common for both standard and custom layers. + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + useImaginary = problemDef->useImaginary; + + // Allocate the memory for the output arrays before the main loop + i = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(i); + + // end memory allocation. + // First we need to allocate the absolute values of the input + // parameters to all the layers in the layers list. This only needs + // to be done once, and so is done outside the contrasts loop + allocateParamsToLayers(problemDef->params, problemDefCells->f6, + outParameterisedLayers); + + // Resample params if requiired + // Loop over all the contrasts + outSsubs.set_size(i); + sldProfiles.set_size(i); + reflectivity.set_size(i); + simulation.set_size(i); + shiftedData.set_size(i); + layerSlds.set_size(i); + chis.set_size(i); + qzshifts.set_size(i); + scalefactors.set_size(i); + bulkIns.set_size(i); + bulkOuts.set_size(i); + resolutionParams.set_size(i); + allRoughs.set_size(i); + allLayers.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + int32_T thisContrastLayers_size[2]; + int32_T b_loop_ub; + int32_T loop_ub; + + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, + &thisBulkOut, &thisResol); + + // Also need to determine which layers from the overall layers list + // are required for this contrast, and put them in the correct order + // according to geometry + allocateLayersForContrast(problemDefCells->f5[b_i].f1, + outParameterisedLayers, useImaginary, thisContrastLayers_data, + thisContrastLayers_size); + + // For the other parameters, we extract the correct ones from the input + // arrays + // Substrate roughness is always first parameter for standard layers + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the core layers calculation + b_thisContrastLayers_data.set(&thisContrastLayers_data[0], + thisContrastLayers_size[0], thisContrastLayers_size[1]); + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_coreLayersCalculation(b_thisContrastLayers_data, problemDef->params + [0], problemDef->geometry.data, problemDef->geometry.size, + thisBulkIn, thisBulkOut, problemDef->resample[b_i], + controls->calcSldDuringFit, thisScalefactor, thisQzshift, + problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, + b_dv1, dv2, thisBackground, thisResol, + problemDef->contrastBackgroundsType[b_i], static_cast + (problemDef->params.size(1)), controls->resamPars, useImaginary, + sldProfile, reflectivity[b_i].f1, simulation[b_i].f1, shiftedDat, + layerSlds[b_i].f1, allLayers[b_i].f1, &chis[b_i], &outSsubs[b_i]); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + loop_ub = sldProfile.size(1); + sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = sldProfile.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = + sldProfile[i2 + sldProfile.size(0) * i1]; + } + } + + loop_ub = shiftedDat.size(1); + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + backgroundParams[b_i] = thisBackground; + qzshifts[b_i] = thisQzshift; + scalefactors[b_i] = thisScalefactor; + bulkIns[b_i] = thisBulkIn; + bulkOuts[b_i] = thisBulkOut; + resolutionParams[b_i] = thisResol; + allRoughs[b_i] = problemDef->params[0]; + } + } + } + } +} + +// End of code generation (parallelPoints.cpp) diff --git a/RAT/parallelPoints.h b/RAT/parallelPoints.h new file mode 100644 index 00000000..4609a17f --- /dev/null +++ b/RAT/parallelPoints.h @@ -0,0 +1,54 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints.h +// +// Code generation for function 'parallelPoints' +// +#ifndef PARALLELPOINTS_H +#define PARALLELPOINTS_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace standardLayers + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 1U> &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelPoints.h) diff --git a/RAT/parallelPoints1.cpp b/RAT/parallelPoints1.cpp new file mode 100644 index 00000000..6b5be494 --- /dev/null +++ b/RAT/parallelPoints1.cpp @@ -0,0 +1,206 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints1.cpp +// +// Code generation for function 'parallelPoints1' +// + +// Include files +#include "parallelPoints1.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "backSort.h" +#include "coreLayersCalculation.h" +#include "processCustomFunction.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customLayers + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 1U> &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs) + { + ::coder::array b_allLayers; + ::coder::array shiftedDat; + ::coder::array sldProfile; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + int32_T i; + + // Multi threaded version of the custom layers over reflectivity poimnts + // for nonPolarisedTF reflectivity calculation. + // The function extracts the relevant parameters from the input + // arrays, allocates these on a pre-contrast basis, then calls the 'core' + // calculation (the core layers nonPolarisedTF calc is shared between + // multiple calculation types). + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + // Pre-Allocation of output arrays... + i = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(i); + + // --- End Memory Allocation --- + // Resampling parameters + // Process the custom models.... + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + problemDef->useImaginary, allLayers, allRoughs); + + // Single cored over all contrasts + outSsubs.set_size(i); + sldProfiles.set_size(i); + reflectivity.set_size(i); + simulation.set_size(i); + shiftedData.set_size(i); + layerSlds.set_size(i); + chis.set_size(i); + qzshifts.set_size(i); + scalefactors.set_size(i); + bulkIns.set_size(i); + bulkOuts.set_size(i); + resolutionParams.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + int32_T b_loop_ub; + int32_T loop_ub; + + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, + &thisBulkOut, &thisResol); + + // Get the custom layers output for this contrast + // For the other parameters, we extract the correct ones from the input + // arrays + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the reflectivity calculation + b_allLayers.set_size(allLayers[b_i].f1.size(0), allLayers[b_i].f1.size + (1)); + loop_ub = allLayers[b_i].f1.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_loop_ub = allLayers[b_i].f1.size(0) - 1; + for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { + b_allLayers[i2 + b_allLayers.size(0) * i1] = allLayers[b_i].f1[i2 + + allLayers[b_i].f1.size(0) * i1]; + } + } + + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_coreLayersCalculation(b_allLayers, allRoughs[b_i], + problemDef->geometry.data, problemDef->geometry.size, thisBulkIn, + thisBulkOut, problemDef->resample[b_i], controls->calcSldDuringFit, + thisScalefactor, thisQzshift, problemDef->dataPresent[b_i], + problemDefCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, + thisResol, problemDef->contrastBackgroundsType[b_i], + static_cast(problemDef->params.size(1)), controls->resamPars, + problemDef->useImaginary, sldProfile, reflectivity[b_i].f1, + simulation[b_i].f1, shiftedDat, layerSlds[b_i].f1, allLayers[b_i].f1, + &chis[b_i], &outSsubs[b_i]); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + loop_ub = sldProfile.size(1); + sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = sldProfile.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = + sldProfile[i2 + sldProfile.size(0) * i1]; + } + } + + loop_ub = shiftedDat.size(1); + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + backgroundParams[b_i] = thisBackground; + qzshifts[b_i] = thisQzshift; + scalefactors[b_i] = thisScalefactor; + bulkIns[b_i] = thisBulkIn; + bulkOuts[b_i] = thisBulkOut; + resolutionParams[b_i] = thisResol; + } + } + } + } +} + +// End of code generation (parallelPoints1.cpp) diff --git a/RAT/parallelPoints1.h b/RAT/parallelPoints1.h new file mode 100644 index 00000000..18f9d4c4 --- /dev/null +++ b/RAT/parallelPoints1.h @@ -0,0 +1,54 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints1.h +// +// Code generation for function 'parallelPoints1' +// +#ifndef PARALLELPOINTS1_H +#define PARALLELPOINTS1_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customLayers + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 1U> &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelPoints1.h) diff --git a/RAT/parallelPoints2.cpp b/RAT/parallelPoints2.cpp new file mode 100644 index 00000000..dd99ad64 --- /dev/null +++ b/RAT/parallelPoints2.cpp @@ -0,0 +1,225 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints2.cpp +// +// Code generation for function 'parallelPoints2' +// + +// Include files +#include "parallelPoints2.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "applyBackgroundCorrection.h" +#include "backSort.h" +#include "callReflectivity.h" +#include "chiSquared.h" +#include "processCustomFunction1.h" +#include "resampleLayers.h" +#include "resampleLayersReIm.h" +#include "rt_nonfinite.h" +#include "shiftData.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customXY + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 1U> &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs) + { + ::coder::array b_problemDefCells; + ::coder::array b_sldProfiles; + ::coder::array c_sldProfiles; + ::coder::array layerSld; + ::coder::array reflect; + ::coder::array shiftedDat; + int32_T loop_ub_tmp; + boolean_T useImaginary; + + // Multi threaded version of the custom XY profile over reflectivity points + // for nonPolarisedTF reflectivity calculation. + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // % Layers details N/A + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + // Pre-Allocation... + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(loop_ub_tmp); + outSsubs.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + outSsubs[i] = 0.0; + } + + // Resampling parameters + useImaginary = problemDef->useImaginary; + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + sldProfiles, allRoughs); + qzshifts.set_size(loop_ub_tmp); + scalefactors.set_size(loop_ub_tmp); + bulkIns.set_size(loop_ub_tmp); + bulkOuts.set_size(loop_ub_tmp); + resolutionParams.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + shiftedData.set_size(loop_ub_tmp); + chis.set_size(loop_ub_tmp); + simulation.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + real_T b_dv[2]; + real_T b_dv1[2]; + int32_T b_loop_ub; + int32_T loop_ub; + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &backgroundParams[b_i], &qzshifts[b_i], &scalefactors[b_i], + &bulkIns[b_i], &bulkOuts[b_i], &resolutionParams[b_i]); + + // Resample the layers + if (!useImaginary) { + resampleLayers(sldProfiles[b_i].f1, controls->resamPars, layerSld); + } else { + loop_ub = sldProfiles[b_i].f1.size(0); + b_sldProfiles.set_size(sldProfiles[b_i].f1.size(0), 2); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_sldProfiles[i1 + b_sldProfiles.size(0) * i] = sldProfiles[b_i] + .f1[i1 + sldProfiles[b_i].f1.size(0) * i]; + } + } + + loop_ub = sldProfiles[b_i].f1.size(0); + c_sldProfiles.set_size(sldProfiles[b_i].f1.size(0), 2); + for (int32_T i{0}; i < loop_ub; i++) { + c_sldProfiles[i] = sldProfiles[b_i].f1[i]; + c_sldProfiles[i + c_sldProfiles.size(0)] = sldProfiles[b_i].f1[i + + sldProfiles[b_i].f1.size(0) * 2]; + } + + c_resampleLayersReIm(b_sldProfiles, c_sldProfiles, + controls->resamPars, layerSld); + } + + layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + loop_ub = layerSld.size(1); + allLayers[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + b_loop_ub = layerSld.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + layerSlds[b_i].f1[i1 + layerSlds[b_i].f1.size(0) * i] = + layerSld[i1 + layerSld.size(0) * i]; + allLayers[b_i].f1[i1 + allLayers[b_i].f1.size(0) * i] = + layerSld[i1 + layerSld.size(0) * i]; + } + } + + b_problemDefCells.set_size(problemDefCells->f2 + [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> + f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); + loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + for (int32_T i{0}; i <= loop_ub; i++) { + b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + for (int32_T i1{0}; i1 <= b_loop_ub; i1++) { + b_problemDefCells[i1 + b_problemDefCells.size(0) * i] = + problemDefCells->f2[b_i].f1[i1 + problemDefCells->f2[b_i]. + f1.size(0) * i]; + } + } + + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> + dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + loop_ub = shiftedDat.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + shiftedData[b_i].f1[i1 + shiftedData[b_i].f1.size(0) * i] = + shiftedDat[i1 + shiftedDat.size(0) * i]; + } + } + + b_dv[0] = problemDefCells->f4[b_i].f1[0]; + b_dv[1] = problemDefCells->f4[b_i].f1[1]; + b_dv1[0] = problemDefCells->f1[b_i].f1[0]; + b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, + shiftedDat, layerSld, 0.0, resolutionParams[b_i], + useImaginary, reflect, simulation[b_i].f1); + applyBackgroundCorrection(reflect, simulation[b_i].f1, shiftedDat, + backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + loop_ub = reflect.size(0); + reflectivity[b_i].f1.set_size(reflect.size(0), 2); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + reflectivity[b_i].f1[i1 + reflectivity[b_i].f1.size(0) * i] = + reflect[i1 + reflect.size(0) * i]; + } + } + + if (problemDef->dataPresent[b_i] != 0.0) { + chis[b_i] = chiSquared(shiftedDat, reflect, static_cast + (problemDef->params.size(1))); + } else { + chis[b_i] = 0.0; + } + } + } + } + } +} + +// End of code generation (parallelPoints2.cpp) diff --git a/RAT/parallelPoints2.h b/RAT/parallelPoints2.h new file mode 100644 index 00000000..00c50874 --- /dev/null +++ b/RAT/parallelPoints2.h @@ -0,0 +1,54 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints2.h +// +// Code generation for function 'parallelPoints2' +// +#ifndef PARALLELPOINTS2_H +#define PARALLELPOINTS2_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customXY + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 1U> &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelPoints2.h) diff --git a/RAT/parallelPoints3.cpp b/RAT/parallelPoints3.cpp new file mode 100644 index 00000000..63b28112 --- /dev/null +++ b/RAT/parallelPoints3.cpp @@ -0,0 +1,348 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints3.cpp +// +// Code generation for function 'parallelPoints3' +// + +// Include files +#include "parallelPoints3.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "allocateLayersForContrast.h" +#include "allocateParamsToLayers.h" +#include "averageReflectivity.h" +#include "backSort.h" +#include "chiSquared.h" +#include "coreLayersCalculation.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace standardLayers + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 2U> &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< + cell_wrap_8, 2U> &allLayers, ::coder::array + &allRoughs) + { + static real_T thisContrastLayers1_data[6000]; + static real_T thisContrastLayers2_data[6000]; + ::coder::array outParameterisedLayers; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; + ::coder::array a__6; + ::coder::array b_thisContrastLayers1_data; + ::coder::array b_thisContrastLayers2_data; + ::coder::array reflect1; + ::coder::array reflect2; + ::coder::array shiftedDat; + ::coder::array simul1; + ::coder::array simul2; + ::coder::array totReflect; + cell_wrap_8 r; + cell_wrap_8 r1; + cell_wrap_8 r2; + cell_wrap_8 r3; + cell_wrap_8 r4; + cell_wrap_8 r5; + real_T a__5; + real_T a__7; + real_T a__8; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + int32_T nParams; + boolean_T calcSld; + boolean_T useImaginary; + + // Single threaded version of the Standard Layers calculation + // This is the main reflectivity calculation of the standard layers + // calculation type. It extracts the required parameters for the contrasts + // from the input arrays, then passes the main calculation to + // 'standardLayersCore', which carries out the calculation itself. + // The core calculation is common for both standard and custom layers. + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Additionally extract the additional domain layers details + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + calcSld = controls->calcSldDuringFit; + useImaginary = problemDef->useImaginary; + + // Default for compile. + // Allocate the memory for the output arrays before the main loop + i = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(i); + + // end memory allocation. + // First we need to allocate the absolute values of the input + // parameters to all the layers in the layers list. This only needs + // to be done once, and so is done outside the contrasts loop + allocateParamsToLayers(problemDef->params, problemDefCells->f6, + outParameterisedLayers); + + // Resample params if requiired + // Loop over all the contrasts + outSsubs.set_size(i); + tempSldProfiles.set_size(i); + reflectivity.set_size(i); + simulation.set_size(i); + shiftedData.set_size(i); + tempLayerSlds.set_size(i); + tempAllLayers.set_size(i); + chis.set_size(i); + qzshifts.set_size(i); + scalefactors.set_size(i); + bulkIns.set_size(i); + bulkOuts.set_size(i); + resolutionParams.set_size(i); + allRoughs.set_size(i); + layerSlds.set_size(i, 2); + domainSldProfiles.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + int32_T thisContrastLayers1_size[2]; + int32_T thisContrastLayers2_size[2]; + + // Get the domain ratio for this contrast + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, + &thisBulkOut, &thisResol); + + // Also need to determine which layers from the overall layers list + // are required for this contrast, and put them in the correct order + // according to geometry. We run it twice, once for each domain... + allocateLayersForContrast(problemDefCells->f19[0].f1, + outParameterisedLayers, useImaginary, thisContrastLayers1_data, + thisContrastLayers1_size); + allocateLayersForContrast(problemDefCells->f19[1].f1, + outParameterisedLayers, useImaginary, thisContrastLayers2_data, + thisContrastLayers2_size); + + // For the other parameters, we extract the correct ones from the input + // arrays + // Substrate roughness is always first parameter for standard layers + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the core layers calculation - need to do this once for each + // domain + b_thisContrastLayers1_data.set(&thisContrastLayers1_data[0], + thisContrastLayers1_size[0], thisContrastLayers1_size[1]); + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + nonPolarisedTF::b_coreLayersCalculation(b_thisContrastLayers1_data, + problemDef->params[0], problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, thisBulkOut, + problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, + b_dv1, dv2, thisBackground, thisResol, + problemDef->contrastBackgroundsType[b_i], static_cast + (nParams), controls->resamPars, useImaginary, r.f1, reflect1, simul1, + shiftedDat, r1.f1, r2.f1, &a__5, &outSsubs[b_i]); + b_thisContrastLayers2_data.set(&thisContrastLayers2_data[0], + thisContrastLayers2_size[0], thisContrastLayers2_size[1]); + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + nonPolarisedTF::b_coreLayersCalculation(b_thisContrastLayers2_data, + problemDef->params[0], problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, thisBulkOut, + problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, + b_dv1, dv2, thisBackground, thisResol, + problemDef->contrastBackgroundsType[b_i], static_cast + (nParams), controls->resamPars, useImaginary, r3.f1, reflect2, + simul2, a__6, r4.f1, r5.f1, &a__7, &a__8); + + // Calculate the average reflectivities.... + averageReflectivity(reflect1, reflect2, simul1, simul2, + problemDef->domainRatio[static_cast + (problemDef->contrastDomainRatios[b_i]) - 1], + totReflect, simulation[b_i].f1); + + // Get an overall chi-squared for the new averaged curve.. + chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast + (problemDef->params.size(1))); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + tempSldProfiles[b_i].f1[0] = r; + tempSldProfiles[b_i].f1[1] = r3; + reflectivity[b_i].f1.set_size(totReflect.size(0), 2); + loop_ub = totReflect.size(0); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1] = + totReflect[i2 + totReflect.size(0) * i1]; + } + } + + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + loop_ub = shiftedDat.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + tempLayerSlds[b_i].f1[0] = r1; + tempLayerSlds[b_i].f1[1] = r4; + tempAllLayers[b_i].f1[0] = r2; + tempAllLayers[b_i].f1[1] = r5; + backgroundParams[b_i] = thisBackground; + qzshifts[b_i] = thisQzshift; + scalefactors[b_i] = thisScalefactor; + bulkIns[b_i] = thisBulkIn; + bulkOuts[b_i] = thisBulkOut; + resolutionParams[b_i] = thisResol; + allRoughs[b_i] = problemDef->params[0]; + } + + allLayers.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + loop_ub = tempSldProfiles[b_i].f1[0].f1.size(1); + domainSldProfiles[b_i].f1.set_size(tempSldProfiles[b_i].f1[0].f1.size + (0), tempSldProfiles[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i].f1[i2 + domainSldProfiles[b_i].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[0].f1[i2 + tempSldProfiles[b_i] + .f1[0].f1.size(0) * i1]; + } + } + + loop_ub = tempSldProfiles[b_i].f1[1].f1.size(1); + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.set_size + (tempSldProfiles[b_i].f1[1].f1.size(0), tempSldProfiles[b_i].f1[1]. + f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i2 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[1].f1[i2 + tempSldProfiles[b_i] + .f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[0].f1.size(1); + allLayers[b_i].f1.set_size(tempAllLayers[b_i].f1[0].f1.size(0), + tempAllLayers[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + tempAllLayers[b_i].f1[0].f1[i2 + tempAllLayers[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[1].f1.size(1); + allLayers[b_i + allLayers.size(0)].f1.set_size(tempAllLayers[b_i].f1[1] + .f1.size(0), tempAllLayers[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i + allLayers.size(0)].f1[i2 + allLayers[b_i + + allLayers.size(0)].f1.size(0) * i1] = tempAllLayers[b_i].f1[1]. + f1[i2 + tempAllLayers[b_i].f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[0].f1.size(1); + layerSlds[b_i].f1.set_size(tempLayerSlds[b_i].f1[0].f1.size(0), + tempLayerSlds[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = + tempLayerSlds[b_i].f1[0].f1[i2 + tempLayerSlds[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[1].f1.size(1); + layerSlds[b_i + layerSlds.size(0)].f1.set_size(tempLayerSlds[b_i].f1[1] + .f1.size(0), tempLayerSlds[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i + layerSlds.size(0)].f1[i2 + layerSlds[b_i + + layerSlds.size(0)].f1.size(0) * i1] = tempLayerSlds[b_i].f1[1]. + f1[i2 + tempLayerSlds[b_i].f1[1].f1.size(0) * i1]; + } + } + } + } + } + } +} + +// End of code generation (parallelPoints3.cpp) diff --git a/RAT/parallelPoints3.h b/RAT/parallelPoints3.h new file mode 100644 index 00000000..c8ee2830 --- /dev/null +++ b/RAT/parallelPoints3.h @@ -0,0 +1,54 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints3.h +// +// Code generation for function 'parallelPoints3' +// +#ifndef PARALLELPOINTS3_H +#define PARALLELPOINTS3_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace standardLayers + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 2U> &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< + cell_wrap_8, 2U> &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelPoints3.h) diff --git a/RAT/parallelPoints4.cpp b/RAT/parallelPoints4.cpp new file mode 100644 index 00000000..cf910a8a --- /dev/null +++ b/RAT/parallelPoints4.cpp @@ -0,0 +1,340 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints4.cpp +// +// Code generation for function 'parallelPoints4' +// + +// Include files +#include "parallelPoints4.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "averageReflectivity.h" +#include "backSort.h" +#include "chiSquared.h" +#include "coreLayersCalculation.h" +#include "processCustomFunction2.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace customLayers + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 2U> &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< + cell_wrap_8, 2U> &allLayers, ::coder::array + &allRoughs) + { + ::coder::array r; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; + ::coder::array calcAllLayers; + ::coder::array a__5; + ::coder::array reflect1; + ::coder::array reflect2; + ::coder::array shiftedDat; + ::coder::array simul1; + ::coder::array simul2; + ::coder::array totReflect; + cell_wrap_8 r1; + cell_wrap_8 r2; + cell_wrap_8 r3; + cell_wrap_8 r4; + cell_wrap_8 r5; + cell_wrap_8 r6; + real_T a__4; + real_T a__6; + real_T a__7; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + int32_T nParams; + boolean_T calcSld; + boolean_T useImaginary; + + // Single threaded version of the custom layers, domainsTF reflectivity + // calculation. The function extracts the relevant parameters from the input + // arrays, allocates these on a pre-contrast basis, then calls the 'core' + // calculation (the core layers nonPolarisedTF calc is shared between + // multiple calculation types). + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + calcSld = controls->calcSldDuringFit; + useImaginary = problemDef->useImaginary; + + // Default for compile. + // Pre-Allocation of output arrays... + i = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(i); + + // Resampling parameters + // Process the custom models.... + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + problemDef->useImaginary, r, allRoughs); + cast(r, calcAllLayers); + + // Parallel over all contrasts + // layersCounter = 1; + outSsubs.set_size(i); + tempSldProfiles.set_size(i); + reflectivity.set_size(i); + simulation.set_size(i); + shiftedData.set_size(i); + tempLayerSlds.set_size(i); + tempAllLayers.set_size(i); + chis.set_size(i); + qzshifts.set_size(i); + scalefactors.set_size(i); + bulkIns.set_size(i); + bulkOuts.set_size(i); + resolutionParams.set_size(i); + layerSlds.set_size(i, 2); + domainSldProfiles.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + + // Get the domain ratio for this contrast + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, + &thisBulkOut, &thisResol); + + // Get the custom layers output for this contrast + // We have two for each contrast - one for each domain + // For the other parameters, we extract the correct ones from the input + // arrays + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the reflectivity calculation for each domain + // Domain 1 + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + nonPolarisedTF::b_coreLayersCalculation(calcAllLayers[b_i].f1, + allRoughs[b_i], problemDef->geometry.data, problemDef->geometry.size, + thisBulkIn, thisBulkOut, problemDef->resample[b_i], calcSld, + thisScalefactor, thisQzshift, problemDef->dataPresent[b_i], + problemDefCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, + thisResol, problemDef->contrastBackgroundsType[b_i], + static_cast(nParams), controls->resamPars, useImaginary, + r1.f1, reflect1, simul1, shiftedDat, r2.f1, r3.f1, &a__4, + &outSsubs[b_i]); + + // Domain 2 + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + nonPolarisedTF::b_coreLayersCalculation(calcAllLayers[b_i + + calcAllLayers.size(0)].f1, allRoughs[b_i], problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, thisBulkOut, + problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, + b_dv1, dv2, thisBackground, thisResol, + problemDef->contrastBackgroundsType[b_i], static_cast + (nParams), controls->resamPars, useImaginary, r4.f1, reflect2, + simul2, a__5, r5.f1, r6.f1, &a__6, &a__7); + + // Calculate the average reflectivities.... + averageReflectivity(reflect1, reflect2, simul1, simul2, + problemDef->domainRatio[static_cast + (problemDef->contrastDomainRatios[b_i]) - 1], + totReflect, simulation[b_i].f1); + + // Get an overall chi-squared for the new averaged curve.. + chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast + (problemDef->params.size(1))); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + // domainSldProfiles{i,1} = sldProfile1; + // domainSldProfiles{i,2} = sldProfile2; + tempSldProfiles[b_i].f1[0] = r1; + tempSldProfiles[b_i].f1[1] = r4; + reflectivity[b_i].f1.set_size(totReflect.size(0), 2); + loop_ub = totReflect.size(0); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1] = + totReflect[i2 + totReflect.size(0) * i1]; + } + } + + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + loop_ub = shiftedDat.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + tempLayerSlds[b_i].f1[0] = r2; + tempLayerSlds[b_i].f1[1] = r5; + tempAllLayers[b_i].f1[0] = r3; + tempAllLayers[b_i].f1[1] = r6; + backgroundParams[b_i] = thisBackground; + qzshifts[b_i] = thisQzshift; + scalefactors[b_i] = thisScalefactor; + bulkIns[b_i] = thisBulkIn; + bulkOuts[b_i] = thisBulkOut; + resolutionParams[b_i] = thisResol; + } + + allLayers.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + loop_ub = tempSldProfiles[b_i].f1[0].f1.size(1); + domainSldProfiles[b_i].f1.set_size(tempSldProfiles[b_i].f1[0].f1.size + (0), tempSldProfiles[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i].f1[i2 + domainSldProfiles[b_i].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[0].f1[i2 + tempSldProfiles[b_i] + .f1[0].f1.size(0) * i1]; + } + } + + loop_ub = tempSldProfiles[b_i].f1[1].f1.size(1); + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.set_size + (tempSldProfiles[b_i].f1[1].f1.size(0), tempSldProfiles[b_i].f1[1]. + f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i2 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[1].f1[i2 + tempSldProfiles[b_i] + .f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[0].f1.size(1); + allLayers[b_i].f1.set_size(tempAllLayers[b_i].f1[0].f1.size(0), + tempAllLayers[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + tempAllLayers[b_i].f1[0].f1[i2 + tempAllLayers[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[1].f1.size(1); + allLayers[b_i + allLayers.size(0)].f1.set_size(tempAllLayers[b_i].f1[1] + .f1.size(0), tempAllLayers[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i + allLayers.size(0)].f1[i2 + allLayers[b_i + + allLayers.size(0)].f1.size(0) * i1] = tempAllLayers[b_i].f1[1]. + f1[i2 + tempAllLayers[b_i].f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[0].f1.size(1); + layerSlds[b_i].f1.set_size(tempLayerSlds[b_i].f1[0].f1.size(0), + tempLayerSlds[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = + tempLayerSlds[b_i].f1[0].f1[i2 + tempLayerSlds[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[1].f1.size(1); + layerSlds[b_i + layerSlds.size(0)].f1.set_size(tempLayerSlds[b_i].f1[1] + .f1.size(0), tempLayerSlds[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i + layerSlds.size(0)].f1[i2 + layerSlds[b_i + + layerSlds.size(0)].f1.size(0) * i1] = tempLayerSlds[b_i].f1[1]. + f1[i2 + tempLayerSlds[b_i].f1[1].f1.size(0) * i1]; + } + } + } + } + } + } +} + +// End of code generation (parallelPoints4.cpp) diff --git a/RAT/parallelPoints4.h b/RAT/parallelPoints4.h new file mode 100644 index 00000000..2089fb72 --- /dev/null +++ b/RAT/parallelPoints4.h @@ -0,0 +1,54 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints4.h +// +// Code generation for function 'parallelPoints4' +// +#ifndef PARALLELPOINTS4_H +#define PARALLELPOINTS4_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace customLayers + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 2U> &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< + cell_wrap_8, 2U> &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelPoints4.h) diff --git a/RAT/parallelPoints5.cpp b/RAT/parallelPoints5.cpp new file mode 100644 index 00000000..183c0292 --- /dev/null +++ b/RAT/parallelPoints5.cpp @@ -0,0 +1,411 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints5.cpp +// +// Code generation for function 'parallelPoints5' +// + +// Include files +#include "parallelPoints5.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "applyBackgroundCorrection.h" +#include "averageReflectivity.h" +#include "backSort.h" +#include "callReflectivity.h" +#include "chiSquared.h" +#include "processCustomFunction3.h" +#include "resampleLayers.h" +#include "resampleLayersReIm.h" +#include "rt_nonfinite.h" +#include "shiftData.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace customXY + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 2U> &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< + cell_wrap_8, 2U> &allLayers, ::coder::array + &allRoughs) + { + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; + ::coder::array b_domainSldProfiles; + ::coder::array b_problemDefCells; + ::coder::array c_domainSldProfiles; + ::coder::array r4; + ::coder::array reflect1; + ::coder::array reflect2; + ::coder::array shiftedDat; + ::coder::array simul1; + ::coder::array simul2; + ::coder::array totReflect; + cell_wrap_8 r; + cell_wrap_8 r1; + cell_wrap_8 r2; + cell_wrap_8 r3; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + boolean_T useImaginary; + + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // % Layers details N/A + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + // Pre-Allocation... + i = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(i); + + // Resampling parameters + useImaginary = problemDef->useImaginary; + + // Default for compile. + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + domainSldProfiles, allRoughs); + outSsubs.set_size(i); + qzshifts.set_size(i); + scalefactors.set_size(i); + bulkIns.set_size(i); + bulkOuts.set_size(i); + resolutionParams.set_size(i); + tempLayerSlds.set_size(i); + tempAllLayers.set_size(i); + tempSldProfiles.set_size(i); + shiftedData.set_size(i); + reflectivity.set_size(i); + simulation.set_size(i); + chis.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T b_dv[2]; + real_T b_dv1[2]; + outSsubs[b_i] = allRoughs[b_i]; + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &backgroundParams[b_i], &qzshifts[b_i], &scalefactors[b_i], + &bulkIns[b_i], &bulkOuts[b_i], &resolutionParams[b_i]); + + // Get the domain ratio for this contrast + // Resample the sld profiles + if (!useImaginary) { + resampleLayers(domainSldProfiles[0].f1, controls->resamPars, r.f1); + r1.f1.set_size(r.f1.size(0), 3); + for (int32_T i1{0}; i1 < 3; i1++) { + loop_ub = r.f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + r1.f1[i2 + r1.f1.size(0) * i1] = r.f1[i2 + r.f1.size(0) * i1]; + } + } + + resampleLayers(domainSldProfiles[1].f1, controls->resamPars, r.f1); + } else { + loop_ub = domainSldProfiles[0].f1.size(0); + b_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = + domainSldProfiles[0].f1[i2 + domainSldProfiles[0].f1.size(0) * + i1]; + } + } + + loop_ub = domainSldProfiles[0].f1.size(0); + b_loop_ub = domainSldProfiles[0].f1.size(0); + c_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[0].f1[i1]; + } + + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = + domainSldProfiles[0].f1[i1 + domainSldProfiles[0].f1.size(0) * 2]; + } + + c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + controls->resamPars, r.f1); + r1.f1.set_size(r.f1.size(0), 4); + for (int32_T i1{0}; i1 < 4; i1++) { + loop_ub = r.f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + r1.f1[i2 + r1.f1.size(0) * i1] = r.f1[i2 + r.f1.size(0) * i1]; + } + } + + loop_ub = domainSldProfiles[1].f1.size(0); + b_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = + domainSldProfiles[1].f1[i2 + domainSldProfiles[1].f1.size(0) * + i1]; + } + } + + loop_ub = domainSldProfiles[1].f1.size(0); + b_loop_ub = domainSldProfiles[1].f1.size(0); + c_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[1].f1[i1]; + } + + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = + domainSldProfiles[1].f1[i1 + domainSldProfiles[1].f1.size(0) * 2]; + } + + c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + controls->resamPars, r.f1); + } + + tempLayerSlds[b_i].f1[0] = r1; + tempLayerSlds[b_i].f1[1] = r; + tempAllLayers[b_i].f1[0] = r1; + tempAllLayers[b_i].f1[1] = r; + r2.f1.set_size(domainSldProfiles[0].f1.size(0), domainSldProfiles[0]. + f1.size(1)); + loop_ub = domainSldProfiles[0].f1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = domainSldProfiles[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + r2.f1[i2 + r2.f1.size(0) * i1] = domainSldProfiles[0].f1[i2 + + domainSldProfiles[0].f1.size(0) * i1]; + } + } + + r3.f1.set_size(domainSldProfiles[1].f1.size(0), domainSldProfiles[1]. + f1.size(1)); + loop_ub = domainSldProfiles[1].f1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = domainSldProfiles[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + r3.f1[i2 + r3.f1.size(0) * i1] = domainSldProfiles[1].f1[i2 + + domainSldProfiles[1].f1.size(0) * i1]; + } + } + + tempSldProfiles[b_i].f1[0] = r2; + tempSldProfiles[b_i].f1[1] = r3; + b_problemDefCells.set_size(problemDefCells->f2 + [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> + f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); + loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { + b_problemDefCells[i2 + b_problemDefCells.size(0) * i1] = + problemDefCells->f2[b_i].f1[i2 + problemDefCells->f2[b_i]. + f1.size(0) * i1]; + } + } + + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> + dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + loop_ub = shiftedDat.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + r4.set_size(r1.f1.size(0), r1.f1.size(1)); + loop_ub = r1.f1.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_loop_ub = r1.f1.size(0) - 1; + for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { + r4[i2 + r4.size(0) * i1] = r1.f1[i2 + r1.f1.size(0) * i1]; + } + } + + b_dv[0] = problemDefCells->f4[b_i].f1[0]; + b_dv[1] = problemDefCells->f4[b_i].f1[1]; + b_dv1[0] = problemDefCells->f1[b_i].f1[0]; + b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, + shiftedDat, r4, allRoughs[b_i], + resolutionParams[b_i], useImaginary, reflect1, + simul1); + r4.set_size(r.f1.size(0), r.f1.size(1)); + loop_ub = r.f1.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_loop_ub = r.f1.size(0) - 1; + for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { + r4[i2 + r4.size(0) * i1] = r.f1[i2 + r.f1.size(0) * i1]; + } + } + + b_dv[0] = problemDefCells->f4[b_i].f1[0]; + b_dv[1] = problemDefCells->f4[b_i].f1[1]; + b_dv1[0] = problemDefCells->f1[b_i].f1[0]; + b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, + shiftedDat, r4, allRoughs[b_i], + resolutionParams[b_i], useImaginary, reflect2, + simul2); + applyBackgroundCorrection(reflect1, simul1, shiftedDat, + backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + applyBackgroundCorrection(reflect2, simul2, shiftedDat, + backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + + // Calculate the average reflectivities.... + averageReflectivity(reflect1, reflect2, simul1, simul2, + problemDef->domainRatio[static_cast + (problemDef->contrastDomainRatios[b_i]) - 1], + totReflect, simulation[b_i].f1); + loop_ub = totReflect.size(0); + reflectivity[b_i].f1.set_size(totReflect.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1] = + totReflect[i2 + totReflect.size(0) * i1]; + } + } + + if (problemDef->dataPresent[b_i] != 0.0) { + chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast + (problemDef->params.size(1))); + } else { + chis[b_i] = 0.0; + } + } + + allLayers.set_size(i, 2); + layerSlds.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + loop_ub = tempSldProfiles[b_i].f1[0].f1.size(1); + domainSldProfiles[b_i].f1.set_size(tempSldProfiles[b_i].f1[0].f1.size + (0), tempSldProfiles[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i].f1[i2 + domainSldProfiles[b_i].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[0].f1[i2 + tempSldProfiles[b_i] + .f1[0].f1.size(0) * i1]; + } + } + + loop_ub = tempSldProfiles[b_i].f1[1].f1.size(1); + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.set_size + (tempSldProfiles[b_i].f1[1].f1.size(0), tempSldProfiles[b_i].f1[1]. + f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i2 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[1].f1[i2 + tempSldProfiles[b_i] + .f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[0].f1.size(1); + allLayers[b_i].f1.set_size(tempAllLayers[b_i].f1[0].f1.size(0), + tempAllLayers[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + tempAllLayers[b_i].f1[0].f1[i2 + tempAllLayers[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[1].f1.size(1); + allLayers[b_i + allLayers.size(0)].f1.set_size(tempAllLayers[b_i].f1[1] + .f1.size(0), tempAllLayers[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i + allLayers.size(0)].f1[i2 + allLayers[b_i + + allLayers.size(0)].f1.size(0) * i1] = tempAllLayers[b_i].f1[1]. + f1[i2 + tempAllLayers[b_i].f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[0].f1.size(1); + layerSlds[b_i].f1.set_size(tempLayerSlds[b_i].f1[0].f1.size(0), + tempLayerSlds[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = + tempLayerSlds[b_i].f1[0].f1[i2 + tempLayerSlds[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[1].f1.size(1); + layerSlds[b_i + layerSlds.size(0)].f1.set_size(tempLayerSlds[b_i].f1[1] + .f1.size(0), tempLayerSlds[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i + layerSlds.size(0)].f1[i2 + layerSlds[b_i + + layerSlds.size(0)].f1.size(0) * i1] = tempLayerSlds[b_i].f1[1]. + f1[i2 + tempLayerSlds[b_i].f1[1].f1.size(0) * i1]; + } + } + } + } + } + } +} + +// End of code generation (parallelPoints5.cpp) diff --git a/RAT/parallelPoints5.h b/RAT/parallelPoints5.h new file mode 100644 index 00000000..7a4b5224 --- /dev/null +++ b/RAT/parallelPoints5.h @@ -0,0 +1,54 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parallelPoints5.h +// +// Code generation for function 'parallelPoints5' +// +#ifndef PARALLELPOINTS5_H +#define PARALLELPOINTS5_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace customXY + { + void parallelPoints(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, ::coder:: + array &outSsubs, ::coder::array + &backgroundParams, ::coder::array + &qzshifts, ::coder::array &scalefactors, :: + coder::array &bulkIns, ::coder::array< + real_T, 1U> &bulkOuts, ::coder::array + &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< + cell_wrap_8, 1U> &shiftedData, ::coder::array< + cell_wrap_8, 2U> &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< + cell_wrap_8, 2U> &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (parallelPoints5.h) diff --git a/RAT/pow2.cpp b/RAT/pow2.cpp new file mode 100644 index 00000000..703bf929 --- /dev/null +++ b/RAT/pow2.cpp @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// pow2.cpp +// +// Code generation for function 'pow2' +// + +// Include files +#include "pow2.h" +#include "RATMain_rtwutil.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void pow2(const ::coder::array &a, ::coder::array &y) + { + y.set_size(a.size(0)); + if (a.size(0) != 0) { + int32_T i; + i = a.size(0); + for (int32_T k{0}; k < i; k++) { + y[k] = rt_powd_snf(2.0, a[k]); + } + } + } + } +} + +// End of code generation (pow2.cpp) diff --git a/RAT/pow2.h b/RAT/pow2.h new file mode 100644 index 00000000..0b764461 --- /dev/null +++ b/RAT/pow2.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// pow2.h +// +// Code generation for function 'pow2' +// +#ifndef POW2_H +#define POW2_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void pow2(const ::coder::array &a, ::coder::array &y); + } +} + +#endif + +// End of code generation (pow2.h) diff --git a/RAT/prctile.cpp b/RAT/prctile.cpp new file mode 100644 index 00000000..d7471254 --- /dev/null +++ b/RAT/prctile.cpp @@ -0,0 +1,371 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// prctile.cpp +// +// Code generation for function 'prctile' +// + +// Include files +#include "prctile.h" +#include "rt_nonfinite.h" +#include "sortIdx.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + static void b_percentile_vector(const ::coder::array &x, real_T + pct[2]); + static void percentile_vector(const ::coder::array &x, real_T + pct[2]); + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + static void b_percentile_vector(const ::coder::array &x, real_T + pct[2]) + { + ::coder::array idx; + if (x.size(0) == 0) { + pct[0] = rtNaN; + pct[1] = rtNaN; + } else { + int32_T nj; + internal::sortIdx(x, idx); + nj = x.size(0); + while ((nj > 0) && std::isnan(x[idx[nj - 1] - 1])) { + nj--; + } + + if (nj < 1) { + pct[0] = rtNaN; + pct[1] = rtNaN; + } else if (nj == 1) { + real_T r; + r = x[idx[0] - 1]; + pct[0] = r; + pct[1] = r; + } else { + real_T r; + int32_T i; + r = 0.175 * static_cast(nj); + i = static_cast(std::round(r)); + if (i < 1) { + pct[0] = x[idx[0] - 1]; + } else if (i >= nj) { + pct[0] = x[idx[nj - 1] - 1]; + } else { + r -= static_cast(i); + pct[0] = (0.5 - r) * x[idx[i - 1] - 1] + (r + 0.5) * x[idx[i] - 1]; + } + + r = 0.825 * static_cast(nj); + i = static_cast(std::round(r)); + if (i >= nj) { + pct[1] = x[idx[nj - 1] - 1]; + } else { + r -= static_cast(i); + pct[1] = (0.5 - r) * x[idx[i - 1] - 1] + (r + 0.5) * x[idx[i] - 1]; + } + } + } + } + + static void percentile_vector(const ::coder::array &x, real_T + pct[2]) + { + ::coder::array idx; + if (x.size(0) == 0) { + pct[0] = rtNaN; + pct[1] = rtNaN; + } else { + int32_T nj; + internal::sortIdx(x, idx); + nj = x.size(0); + while ((nj > 0) && std::isnan(x[idx[nj - 1] - 1])) { + nj--; + } + + if (nj < 1) { + pct[0] = rtNaN; + pct[1] = rtNaN; + } else if (nj == 1) { + real_T r; + r = x[idx[0] - 1]; + pct[0] = r; + pct[1] = r; + } else { + real_T r; + int32_T i; + r = 0.025 * static_cast(nj); + i = static_cast(std::round(r)); + if (i < 1) { + pct[0] = x[idx[0] - 1]; + } else if (i >= nj) { + pct[0] = x[idx[nj - 1] - 1]; + } else { + r -= static_cast(i); + pct[0] = (0.5 - r) * x[idx[i - 1] - 1] + (r + 0.5) * x[idx[i] - 1]; + } + + r = 0.975 * static_cast(nj); + i = static_cast(std::round(r)); + if (i >= nj) { + pct[1] = x[idx[nj - 1] - 1]; + } else { + r -= static_cast(i); + pct[1] = (0.5 - r) * x[idx[i - 1] - 1] + (r + 0.5) * x[idx[i] - 1]; + } + } + } + } + + void b_prctile(const ::coder::array &x, ::coder::array &y) + { + ::coder::array wk; + y.set_size(2, x.size(1)); + if ((x.size(0) == 0) || (x.size(1) == 0)) { + int32_T vlen; + vlen = x.size(1); + y.set_size(2, x.size(1)); + for (int32_T k{0}; k < vlen; k++) { + y[2 * k] = rtNaN; + y[2 * k + 1] = rtNaN; + } + } else { + int32_T ix; + int32_T npages; + int32_T vlen; + vlen = x.size(0); + wk.set_size(x.size(0)); + npages = x.size(1); + ix = -1; + for (int32_T xi{0}; xi < npages; xi++) { + real_T pctv[2]; + int32_T k; + wk[0] = x[ix + 1]; + for (k = 2; k <= vlen; k++) { + wk[k - 1] = x[ix + k]; + } + + if (vlen < 2) { + ix++; + } else { + ix += vlen; + } + + b_percentile_vector(wk, pctv); + k = xi << 1; + y[k] = pctv[0]; + y[k + 1] = pctv[1]; + } + } + } + + void b_prctile(const real_T x_data[], int32_T x_size, real_T y[2]) + { + ::coder::array b_x_data; + ::coder::array idx; + if (x_size == 0) { + y[0] = rtNaN; + y[1] = rtNaN; + } else { + int32_T nj; + b_x_data.set((real_T *)&x_data[0], x_size); + internal::sortIdx(b_x_data, idx); + nj = x_size; + while ((nj > 0) && std::isnan(x_data[idx[nj - 1] - 1])) { + nj--; + } + + if (nj < 1) { + y[0] = rtNaN; + y[1] = rtNaN; + } else if (nj == 1) { + real_T r; + r = x_data[idx[0] - 1]; + y[0] = r; + y[1] = r; + } else { + real_T r; + int32_T i; + r = 0.175 * static_cast(nj); + i = static_cast(std::round(r)); + if (i < 1) { + y[0] = x_data[idx[0] - 1]; + } else if (i >= nj) { + y[0] = x_data[idx[nj - 1] - 1]; + } else { + r -= static_cast(i); + y[0] = (0.5 - r) * x_data[idx[i - 1] - 1] + (r + 0.5) * x_data[idx[i] + - 1]; + } + + r = 0.825 * static_cast(nj); + i = static_cast(std::round(r)); + if (i >= nj) { + y[1] = x_data[idx[nj - 1] - 1]; + } else { + r -= static_cast(i); + y[1] = (0.5 - r) * x_data[idx[i - 1] - 1] + (r + 0.5) * x_data[idx[i] + - 1]; + } + } + } + } + + void prctile(const ::coder::array &x, real_T y[2]) + { + ::coder::array idx; + if (x.size(1) == 0) { + y[0] = rtNaN; + y[1] = rtNaN; + } else { + int32_T nj; + internal::sortIdx(x, idx); + nj = x.size(1); + while ((nj > 0) && std::isnan(x[idx[nj - 1] - 1])) { + nj--; + } + + if (nj < 1) { + y[0] = rtNaN; + y[1] = rtNaN; + } else if (nj == 1) { + real_T r; + r = x[idx[0] - 1]; + y[0] = r; + y[1] = r; + } else { + real_T r; + int32_T i; + r = 0.75 * static_cast(nj); + i = static_cast(std::round(r)); + if (i >= nj) { + y[0] = x[idx[nj - 1] - 1]; + } else { + r -= static_cast(i); + y[0] = (0.5 - r) * x[idx[i - 1] - 1] + (r + 0.5) * x[idx[i] - 1]; + } + + r = 0.25 * static_cast(nj); + i = static_cast(std::round(r)); + if (i >= nj) { + y[1] = x[idx[nj - 1] - 1]; + } else { + r -= static_cast(i); + y[1] = (0.5 - r) * x[idx[i - 1] - 1] + (r + 0.5) * x[idx[i] - 1]; + } + } + } + } + + void prctile(const ::coder::array &x, ::coder::array + &y) + { + ::coder::array wk; + y.set_size(2, x.size(1)); + if ((x.size(0) == 0) || (x.size(1) == 0)) { + int32_T vlen; + vlen = x.size(1); + y.set_size(2, x.size(1)); + for (int32_T k{0}; k < vlen; k++) { + y[2 * k] = rtNaN; + y[2 * k + 1] = rtNaN; + } + } else { + int32_T ix; + int32_T npages; + int32_T vlen; + vlen = x.size(0); + wk.set_size(x.size(0)); + npages = x.size(1); + ix = -1; + for (int32_T xi{0}; xi < npages; xi++) { + real_T pctv[2]; + int32_T k; + wk[0] = x[ix + 1]; + for (k = 2; k <= vlen; k++) { + wk[k - 1] = x[ix + k]; + } + + if (vlen < 2) { + ix++; + } else { + ix += vlen; + } + + percentile_vector(wk, pctv); + k = xi << 1; + y[k] = pctv[0]; + y[k + 1] = pctv[1]; + } + } + } + + void prctile(const real_T x_data[], int32_T x_size, real_T y[2]) + { + ::coder::array b_x_data; + ::coder::array idx; + if (x_size == 0) { + y[0] = rtNaN; + y[1] = rtNaN; + } else { + int32_T nj; + b_x_data.set((real_T *)&x_data[0], x_size); + internal::sortIdx(b_x_data, idx); + nj = x_size; + while ((nj > 0) && std::isnan(x_data[idx[nj - 1] - 1])) { + nj--; + } + + if (nj < 1) { + y[0] = rtNaN; + y[1] = rtNaN; + } else if (nj == 1) { + real_T r; + r = x_data[idx[0] - 1]; + y[0] = r; + y[1] = r; + } else { + real_T r; + int32_T i; + r = 0.025 * static_cast(nj); + i = static_cast(std::round(r)); + if (i < 1) { + y[0] = x_data[idx[0] - 1]; + } else if (i >= nj) { + y[0] = x_data[idx[nj - 1] - 1]; + } else { + r -= static_cast(i); + y[0] = (0.5 - r) * x_data[idx[i - 1] - 1] + (r + 0.5) * x_data[idx[i] + - 1]; + } + + r = 0.975 * static_cast(nj); + i = static_cast(std::round(r)); + if (i >= nj) { + y[1] = x_data[idx[nj - 1] - 1]; + } else { + r -= static_cast(i); + y[1] = (0.5 - r) * x_data[idx[i - 1] - 1] + (r + 0.5) * x_data[idx[i] + - 1]; + } + } + } + } + } +} + +// End of code generation (prctile.cpp) diff --git a/RAT/prctile.h b/RAT/prctile.h new file mode 100644 index 00000000..ebbb1cd6 --- /dev/null +++ b/RAT/prctile.h @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// prctile.h +// +// Code generation for function 'prctile' +// +#ifndef PRCTILE_H +#define PRCTILE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_prctile(const ::coder::array &x, ::coder::array &y); + void b_prctile(const real_T x_data[], int32_T x_size, real_T y[2]); + void prctile(const ::coder::array &x, real_T y[2]); + void prctile(const ::coder::array &x, ::coder::array + &y); + void prctile(const real_T x_data[], int32_T x_size, real_T y[2]); + } +} + +#endif + +// End of code generation (prctile.h) diff --git a/RAT/prctileConfInts.cpp b/RAT/prctileConfInts.cpp new file mode 100644 index 00000000..b692e8f5 --- /dev/null +++ b/RAT/prctileConfInts.cpp @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// prctileConfInts.cpp +// +// Code generation for function 'prctileConfInts' +// + +// Include files +#include "prctileConfInts.h" +#include "mean.h" +#include "prctile.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void prctileConfInts(const ::coder::array &chain, ::coder::array< + real_T, 2U> &parConfInts_par95, ::coder::array + &parConfInts_par65, ::coder::array + &parConfInts_mean) + { + coder::prctile(chain, parConfInts_par95); + coder::b_prctile(chain, parConfInts_par65); + coder::mean(chain, parConfInts_mean); + } +} + +// End of code generation (prctileConfInts.cpp) diff --git a/RAT/prctileConfInts.h b/RAT/prctileConfInts.h new file mode 100644 index 00000000..61596525 --- /dev/null +++ b/RAT/prctileConfInts.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// prctileConfInts.h +// +// Code generation for function 'prctileConfInts' +// +#ifndef PRCTILECONFINTS_H +#define PRCTILECONFINTS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void prctileConfInts(const ::coder::array &chain, ::coder::array< + real_T, 2U> &parConfInts_par95, ::coder::array + &parConfInts_par65, ::coder::array + &parConfInts_mean); +} + +#endif + +// End of code generation (prctileConfInts.h) diff --git a/RAT/processBayes.cpp b/RAT/processBayes.cpp new file mode 100644 index 00000000..95e46dce --- /dev/null +++ b/RAT/processBayes.cpp @@ -0,0 +1,252 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// processBayes.cpp +// +// Code generation for function 'processBayes' +// + +// Include files +#include "processBayes.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "prctileConfInts.h" +#include "refPrctileConfInts.h" +#include "reflectivityCalculation.h" +#include "rt_nonfinite.h" +#include "unpackParams.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void processBayes(const real_T bayesOutputs_bestPars_data[], const int32_T + bayesOutputs_bestPars_size[2], const ::coder::array &bayesOutputs_chain, const struct5_T *allProblem_f1, + const struct2_T *allProblem_f2, const cell_14 *allProblem_f4, + struct5_T *problemDef, struct_T *outProblem, cell_13 *result, + e_struct_T *bayesResults_bestFitsMean, f_struct_T + *bayesResults_predlims, struct11_T *bayesResults_parConfInts) + { + static struct2_T controlsStruct; + struct5_T b_problemDef; + int32_T loop_ub; + + // problem = {problemDef ; controls ; problemDefLimits ; problemDefCells}; + *problemDef = *allProblem_f1; + controlsStruct = *allProblem_f2; + + // Need to impose that we calculate the SLD.. + controlsStruct.calcSldDuringFit = true; + + // ... and use the Bayes bestpars + problemDef->fitParams.set_size(1, bayesOutputs_bestPars_size[1]); + loop_ub = bayesOutputs_bestPars_size[1]; + for (int32_T i{0}; i < loop_ub; i++) { + problemDef->fitParams[problemDef->fitParams.size(0) * i] = + bayesOutputs_bestPars_data[i]; + } + + unpackParams(problemDef, allProblem_f2->checks.fitParam, + allProblem_f2->checks.fitBackgroundParam, + allProblem_f2->checks.fitQzshift, + allProblem_f2->checks.fitScalefactor, + allProblem_f2->checks.fitBulkIn, + allProblem_f2->checks.fitBulkOut, + allProblem_f2->checks.fitResolutionParam, + allProblem_f2->checks.fitDomainRatio); + prctileConfInts(bayesOutputs_chain, bayesResults_parConfInts->par95, + bayesResults_parConfInts->par65, + bayesResults_parConfInts->mean); + + // iterShortest(output.chain,length(fitNames),[],0.95); + // % 2. Find maximum values of posteriors. Store the max and mean posterior + // % values, and calculate the best fit and SLD's from these. + // [bestPars_max,posteriors] = findPosteriorsMax(output.chain); + // bestPars_mean = output.results.mean; + // % Calculate Max best fit curves + // controls.calcSldDuringFit = true; + // problemDef.fitParams = bestPars_max; + // problemDef = unpackParams(problemDef,controls); + // [outProblem,result] = reflectivityCalculation(problemDef,problemDefCells,controls); + // bestFitMax_Ref = result(1); + // bestFitMax_Sld = result(5); + // bestFitMax_chi = outProblem.calculations.sumChi; + // Calculate 'mean' best fit curves + // problemDef.fitParams = parConfInts.mean; + // problemDef = unpackParams(problemDef,controlsStruct); + reflectivityCalculation(problemDef, allProblem_f4, &controlsStruct, + outProblem, result); + + // Reflectivity art points + // Reflectivity between sim limits + // Data corrected for sfs + // Layers if defined (i.e. not customXY) + // Calculated SLD profiles + // Resampled layers + // For compile, we can't remove a field, so just clear it for now... + // problem = rmfield(problem,'calculations'); + bayesResults_bestFitsMean->ref.set_size(result->f1.size(0)); + loop_ub = result->f1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + bayesResults_bestFitsMean->ref[i] = result->f1[i]; + } + + bayesResults_bestFitsMean->sld.set_size(result->f5.size(0), result->f5.size + (1)); + loop_ub = result->f5.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + int32_T b_loop_ub; + b_loop_ub = result->f5.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + bayesResults_bestFitsMean->sld[i1 + bayesResults_bestFitsMean->sld.size + (0) * i] = result->f5[i1 + result->f5.size(0) * i]; + } + } + + bayesResults_bestFitsMean->chi = outProblem->calculations.sumChi; + bayesResults_bestFitsMean->data.set_size(result->f3.size(0)); + loop_ub = result->f3.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + bayesResults_bestFitsMean->data[i] = result->f3[i]; + } + + // 2. Reflectivity and SLD shading + // predIntRef = mcmcpred_compile(output.results,output.chain,[],output.data,problem,500); + // predIntRef = predIntRef.predlims; + // + // predIntSld_calcs = mcmcpred_compile_sld(output.results,output.chain,bestFitMean_Sld,[],output.data,problem,500); + // predIntSld = predIntSld_calcs.predlims; + // predIntSld_xdata = predIntSld_calcs.data; + b_problemDef = *problemDef; + refPrctileConfInts(bayesOutputs_chain, &b_problemDef, allProblem_f4, + &controlsStruct, bayesResults_predlims); + + // --------------------------------- + // bayesResults.chain = bayesOutputs.chain; + // bayesResults.bestPars_Max = bestPars_max; + // bayesResults.bayesData = bayesOutputs.data; + // bayesResults.bestFitsMax = {bestFitMax_Ref, bestFitMax_Sld, bestFitMax_chi}; + // bayesResults.bestFitsMean = bestFitMean; + // bayesResults.predlims = allPredInts; + // bayesResults.parConfInts = parConfInts; + // bayesResults.bestPars = bayesOutputs.bestPars; + } + + void processBayes(const ::coder::array &bayesOutputs_bestPars, + const ::coder::array &bayesOutputs_chain, const + struct5_T *allProblem_f1, const struct2_T *allProblem_f2, + const cell_14 *allProblem_f4, struct5_T *problemDef, + struct_T *outProblem, cell_13 *result, e_struct_T + *bayesResults_bestFitsMean, f_struct_T + *bayesResults_predlims, struct11_T *bayesResults_parConfInts) + { + struct2_T controlsStruct; + struct5_T b_problemDef; + int32_T loop_ub; + + // problem = {problemDef ; controls ; problemDefLimits ; problemDefCells}; + *problemDef = *allProblem_f1; + controlsStruct = *allProblem_f2; + + // Need to impose that we calculate the SLD.. + controlsStruct.calcSldDuringFit = true; + + // ... and use the Bayes bestpars + problemDef->fitParams.set_size(1, bayesOutputs_bestPars.size(1)); + loop_ub = bayesOutputs_bestPars.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + problemDef->fitParams[problemDef->fitParams.size(0) * i] = + bayesOutputs_bestPars[i]; + } + + unpackParams(problemDef, allProblem_f2->checks.fitParam, + allProblem_f2->checks.fitBackgroundParam, + allProblem_f2->checks.fitQzshift, + allProblem_f2->checks.fitScalefactor, + allProblem_f2->checks.fitBulkIn, + allProblem_f2->checks.fitBulkOut, + allProblem_f2->checks.fitResolutionParam, + allProblem_f2->checks.fitDomainRatio); + prctileConfInts(bayesOutputs_chain, bayesResults_parConfInts->par95, + bayesResults_parConfInts->par65, + bayesResults_parConfInts->mean); + + // iterShortest(output.chain,length(fitNames),[],0.95); + // % 2. Find maximum values of posteriors. Store the max and mean posterior + // % values, and calculate the best fit and SLD's from these. + // [bestPars_max,posteriors] = findPosteriorsMax(output.chain); + // bestPars_mean = output.results.mean; + // % Calculate Max best fit curves + // controls.calcSldDuringFit = true; + // problemDef.fitParams = bestPars_max; + // problemDef = unpackParams(problemDef,controls); + // [outProblem,result] = reflectivityCalculation(problemDef,problemDefCells,controls); + // bestFitMax_Ref = result(1); + // bestFitMax_Sld = result(5); + // bestFitMax_chi = outProblem.calculations.sumChi; + // Calculate 'mean' best fit curves + // problemDef.fitParams = parConfInts.mean; + // problemDef = unpackParams(problemDef,controlsStruct); + reflectivityCalculation(problemDef, allProblem_f4, &controlsStruct, + outProblem, result); + + // Reflectivity art points + // Reflectivity between sim limits + // Data corrected for sfs + // Layers if defined (i.e. not customXY) + // Calculated SLD profiles + // Resampled layers + // For compile, we can't remove a field, so just clear it for now... + // problem = rmfield(problem,'calculations'); + bayesResults_bestFitsMean->ref.set_size(result->f1.size(0)); + loop_ub = result->f1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + bayesResults_bestFitsMean->ref[i] = result->f1[i]; + } + + bayesResults_bestFitsMean->sld.set_size(result->f5.size(0), result->f5.size + (1)); + loop_ub = result->f5.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + int32_T b_loop_ub; + b_loop_ub = result->f5.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + bayesResults_bestFitsMean->sld[i1 + bayesResults_bestFitsMean->sld.size + (0) * i] = result->f5[i1 + result->f5.size(0) * i]; + } + } + + bayesResults_bestFitsMean->chi = outProblem->calculations.sumChi; + bayesResults_bestFitsMean->data.set_size(result->f3.size(0)); + loop_ub = result->f3.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + bayesResults_bestFitsMean->data[i] = result->f3[i]; + } + + // 2. Reflectivity and SLD shading + // predIntRef = mcmcpred_compile(output.results,output.chain,[],output.data,problem,500); + // predIntRef = predIntRef.predlims; + // + // predIntSld_calcs = mcmcpred_compile_sld(output.results,output.chain,bestFitMean_Sld,[],output.data,problem,500); + // predIntSld = predIntSld_calcs.predlims; + // predIntSld_xdata = predIntSld_calcs.data; + b_problemDef = *problemDef; + refPrctileConfInts(bayesOutputs_chain, &b_problemDef, allProblem_f4, + &controlsStruct, bayesResults_predlims); + + // --------------------------------- + // bayesResults.chain = bayesOutputs.chain; + // bayesResults.bestPars_Max = bestPars_max; + // bayesResults.bayesData = bayesOutputs.data; + // bayesResults.bestFitsMax = {bestFitMax_Ref, bestFitMax_Sld, bestFitMax_chi}; + // bayesResults.bestFitsMean = bestFitMean; + // bayesResults.predlims = allPredInts; + // bayesResults.parConfInts = parConfInts; + // bayesResults.bestPars = bayesOutputs.bestPars; + } +} + +// End of code generation (processBayes.cpp) diff --git a/RAT/processBayes.h b/RAT/processBayes.h new file mode 100644 index 00000000..2352b2b7 --- /dev/null +++ b/RAT/processBayes.h @@ -0,0 +1,53 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// processBayes.h +// +// Code generation for function 'processBayes' +// +#ifndef PROCESSBAYES_H +#define PROCESSBAYES_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct struct2_T; + struct cell_14; + struct struct_T; + struct cell_13; + struct e_struct_T; + struct f_struct_T; + struct struct11_T; +} + +// Function Declarations +namespace RAT +{ + void processBayes(const real_T bayesOutputs_bestPars_data[], const int32_T + bayesOutputs_bestPars_size[2], const ::coder::array &bayesOutputs_chain, const struct5_T *allProblem_f1, + const struct2_T *allProblem_f2, const cell_14 *allProblem_f4, + struct5_T *problemDef, struct_T *outProblem, cell_13 *result, + e_struct_T *bayesResults_bestFitsMean, f_struct_T + *bayesResults_predlims, struct11_T *bayesResults_parConfInts); + void processBayes(const ::coder::array &bayesOutputs_bestPars, + const ::coder::array &bayesOutputs_chain, const + struct5_T *allProblem_f1, const struct2_T *allProblem_f2, + const cell_14 *allProblem_f4, struct5_T *problemDef, + struct_T *outProblem, cell_13 *result, e_struct_T + *bayesResults_bestFitsMean, f_struct_T + *bayesResults_predlims, struct11_T *bayesResults_parConfInts); +} + +#endif + +// End of code generation (processBayes.h) diff --git a/RAT/processCustomFunction.cpp b/RAT/processCustomFunction.cpp new file mode 100644 index 00000000..10140260 --- /dev/null +++ b/RAT/processCustomFunction.cpp @@ -0,0 +1,169 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// processCustomFunction.cpp +// +// Code generation for function 'processCustomFunction' +// + +// Include files +#include "processCustomFunction.h" +#include "RATMain_types.h" +#include "applyHydrationImag.h" +#include "applyHydrationReal.h" +#include "backSort.h" +#include "callCppFunction.h" +#include "rt_nonfinite.h" +#include "str2double.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1); +} + +// Function Definitions +namespace RAT +{ + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + namespace nonPolarisedTF + { + namespace customLayers + { + void processCustomFunction(const ::coder::array + &contrastBackgrounds, const ::coder::array &contrastQzshifts, + const ::coder::array &contrastScalefactors, const ::coder:: + array &contrastBulkIns, const ::coder::array + &contrastBulkOuts, const ::coder::array &contrastResolutions, + const ::coder::array &backgroundParam, const ::coder::array< + real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: + array &cCustFiles, real_T numberOfContrasts, const ::coder:: + array &customFiles, const ::coder::array + ¶ms, boolean_T useImaginary, ::coder::array + &allLayers, ::coder::array &allRoughs) + { + ::coder::array tempAllLayers; + ::coder::array b_params; + ::coder::array b_thisContrastLayers; + ::coder::array thisContrastLayers; + real_T a__1; + real_T a__2; + real_T a__3; + real_T a__4; + real_T thisBulkIn; + real_T thisBulkOut; + int32_T i; + + // Top-level function for processing custom layers for all the + // contrasts. + // Do some pre-definitions to keep the compiler happy... + i = static_cast(numberOfContrasts); + allRoughs.set_size(i); + tempAllLayers.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + creal_T x; + real_T d; + int32_T iv[2]; + int32_T b_loop_ub; + int32_T loop_ub; + + // TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's.. + // Choose which custom file is associated with this contrast + // Find values of 'bulkIn' and 'bulkOut' for this + // contrast... + backSort(contrastBackgrounds[b_i], contrastQzshifts[b_i], + contrastScalefactors[b_i], contrastBulkIns[b_i], + contrastBulkOuts[b_i], contrastResolutions[b_i], + backgroundParam, qzshifts, scalefactor, bulkIn, bulkOut, res, + &a__1, &a__2, &a__3, &thisBulkIn, &thisBulkOut, &a__4); + + // typeDef + d = cCustFiles[b_i]; + iv[0] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ + static_cast(d) - 1].f1)->size())[0]; + iv[1] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ + static_cast(d) - 1].f1)->size())[1]; + x = coder::str2double((const char_T *)((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->data(), iv); + if ((!std::isnan(x.re)) && (!std::isnan(x.im))) { + b_params.set_size(1, params.size(1)); + loop_ub = params.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_params[i1] = params[i1]; + } + + iv[0] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->size())[0]; + iv[1] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->size())[1]; + callCppFunction(b_params, thisBulkIn, thisBulkOut, + static_cast(b_i) + 1.0, (const char_T *)((:: + coder::array *)&customFiles[static_cast(d) - + 1].f1)->data(), iv, b_thisContrastLayers, &allRoughs[b_i]); + loop_ub = b_thisContrastLayers.size(1); + thisContrastLayers.set_size(b_thisContrastLayers.size(0), + b_thisContrastLayers.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = b_thisContrastLayers.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + thisContrastLayers[i2 + thisContrastLayers.size(0) * i1] = + b_thisContrastLayers[i2 + b_thisContrastLayers.size(0) * i1]; + } + } + } + + // If the output layers has 5 columns, then we need to do + // the hydration correction (the user has not done it in the + // custom function). Do that here.... + if (!useImaginary) { + applyHydrationReal(thisContrastLayers, thisBulkIn, thisBulkOut); + } else { + applyHydrationImag(thisContrastLayers, thisBulkIn, thisBulkOut); + } + + tempAllLayers[b_i].f1.set_size(thisContrastLayers.size(0), + thisContrastLayers.size(1)); + loop_ub = thisContrastLayers.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = thisContrastLayers.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + tempAllLayers[b_i].f1[i2 + tempAllLayers[b_i].f1.size(0) * i1] = + thisContrastLayers[i2 + thisContrastLayers.size(0) * i1]; + } + } + } + + cast(tempAllLayers, allLayers); + } + } + } +} + +// End of code generation (processCustomFunction.cpp) diff --git a/RAT/processCustomFunction.h b/RAT/processCustomFunction.h new file mode 100644 index 00000000..bf909b8b --- /dev/null +++ b/RAT/processCustomFunction.h @@ -0,0 +1,46 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// processCustomFunction.h +// +// Code generation for function 'processCustomFunction' +// +#ifndef PROCESSCUSTOMFUNCTION_H +#define PROCESSCUSTOMFUNCTION_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customLayers + { + void processCustomFunction(const ::coder::array + &contrastBackgrounds, const ::coder::array &contrastQzshifts, + const ::coder::array &contrastScalefactors, const ::coder:: + array &contrastBulkIns, const ::coder::array + &contrastBulkOuts, const ::coder::array &contrastResolutions, + const ::coder::array &backgroundParam, const ::coder::array< + real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: + array &cCustFiles, real_T numberOfContrasts, const ::coder:: + array &customFiles, const ::coder::array + ¶ms, boolean_T useImaginary, ::coder::array + &allLayers, ::coder::array &allRoughs); + } + } +} + +#endif + +// End of code generation (processCustomFunction.h) diff --git a/RAT/processCustomFunction1.cpp b/RAT/processCustomFunction1.cpp new file mode 100644 index 00000000..ab897761 --- /dev/null +++ b/RAT/processCustomFunction1.cpp @@ -0,0 +1,146 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// processCustomFunction1.cpp +// +// Code generation for function 'processCustomFunction1' +// + +// Include files +#include "processCustomFunction1.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "backSort.h" +#include "callCppFunction.h" +#include "rt_nonfinite.h" +#include "str2double.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1); +} + +// Function Definitions +namespace RAT +{ + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 1U> &r1) + { + int32_T i; + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + namespace nonPolarisedTF + { + namespace customXY + { + void processCustomFunction(const ::coder::array + &contrastBackgrounds, const ::coder::array &contrastQzshifts, + const ::coder::array &contrastScalefactors, const ::coder:: + array &contrastBulkIns, const ::coder::array + &contrastBulkOuts, const ::coder::array &contrastResolutions, + const ::coder::array &backgroundParams, const ::coder::array< + real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: + array &cCustFiles, real_T numberOfContrasts, const ::coder:: + array &customFiles, const ::coder::array + ¶ms, ::coder::array &allSLDs, ::coder::array &allRoughs) + { + ::coder::array tempAllSLDs; + ::coder::array b_params; + ::coder::array r; + real_T a__1; + real_T a__2; + real_T a__3; + real_T a__4; + real_T thisBulkIn; + real_T thisBulkOut; + int32_T i; + + // Top-level function for processing custom XY profiles for all the + // contrasts. + // Do some pre-definitions to keep the compiler happy... + i = static_cast(numberOfContrasts); + allRoughs.set_size(i); + + // 3 columns to allow for potential imaginary curve + tempAllSLDs.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + creal_T x; + real_T d; + int32_T iv[2]; + + // TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's.. + // Choose which custom file is associated with this contrast + // Find values of 'bulkIn' and 'bulkOut' for this + // contrast... + backSort(contrastBackgrounds[b_i], contrastQzshifts[b_i], + contrastScalefactors[b_i], contrastBulkIns[b_i], + contrastBulkOuts[b_i], contrastResolutions[b_i], + backgroundParams, qzshifts, scalefactor, bulkIn, bulkOut, res, + &a__1, &a__2, &a__3, &thisBulkIn, &thisBulkOut, &a__4); + d = cCustFiles[b_i]; + iv[0] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ + static_cast(d) - 1].f1)->size())[0]; + iv[1] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ + static_cast(d) - 1].f1)->size())[1]; + x = coder::str2double((const char_T *)((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->data(), iv); + if ((!std::isnan(x.re)) && (!std::isnan(x.im))) { + int32_T loop_ub; + b_params.set_size(1, params.size(1)); + loop_ub = params.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_params[i1] = params[i1]; + } + + iv[0] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->size())[0]; + iv[1] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->size())[1]; + callCppFunction(b_params, thisBulkIn, thisBulkOut, + static_cast(b_i) + 1.0, (const char_T *)((:: + coder::array *)&customFiles[static_cast(d) - + 1].f1)->data(), iv, r, &allRoughs[b_i]); + loop_ub = r.size(1); + tempAllSLDs[b_i].f1.set_size(r.size(0), r.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + int32_T b_loop_ub; + b_loop_ub = r.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + tempAllSLDs[b_i].f1[i2 + tempAllSLDs[b_i].f1.size(0) * i1] = + r[i2 + r.size(0) * i1]; + } + } + } + } + + cast(tempAllSLDs, allSLDs); + } + } + } +} + +// End of code generation (processCustomFunction1.cpp) diff --git a/RAT/processCustomFunction1.h b/RAT/processCustomFunction1.h new file mode 100644 index 00000000..59f10e75 --- /dev/null +++ b/RAT/processCustomFunction1.h @@ -0,0 +1,46 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// processCustomFunction1.h +// +// Code generation for function 'processCustomFunction1' +// +#ifndef PROCESSCUSTOMFUNCTION1_H +#define PROCESSCUSTOMFUNCTION1_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customXY + { + void processCustomFunction(const ::coder::array + &contrastBackgrounds, const ::coder::array &contrastQzshifts, + const ::coder::array &contrastScalefactors, const ::coder:: + array &contrastBulkIns, const ::coder::array + &contrastBulkOuts, const ::coder::array &contrastResolutions, + const ::coder::array &backgroundParams, const ::coder::array< + real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: + array &cCustFiles, real_T numberOfContrasts, const ::coder:: + array &customFiles, const ::coder::array + ¶ms, ::coder::array &allSLDs, ::coder::array &allRoughs); + } + } +} + +#endif + +// End of code generation (processCustomFunction1.h) diff --git a/RAT/processCustomFunction2.cpp b/RAT/processCustomFunction2.cpp new file mode 100644 index 00000000..e1907960 --- /dev/null +++ b/RAT/processCustomFunction2.cpp @@ -0,0 +1,270 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// processCustomFunction2.cpp +// +// Code generation for function 'processCustomFunction2' +// + +// Include files +#include "processCustomFunction2.h" +#include "RATMain_types.h" +#include "applyHydrationImag.h" +#include "applyHydrationReal.h" +#include "backSort.h" +#include "callCppFunction.h" +#include "rt_nonfinite.h" +#include "str2double.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace customLayers + { + void processCustomFunction(const ::coder::array + &contrastBackgrounds, const ::coder::array &contrastQzshifts, + const ::coder::array &contrastScalefactors, const ::coder:: + array &contrastBulkIns, const ::coder::array + &contrastBulkOuts, const ::coder::array &contrastResolutions, + const ::coder::array &backgroundParams, const ::coder::array< + real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &resolutionParams, const :: + coder::array &cCustFiles, real_T numberOfContrasts, const :: + coder::array &customFiles, const ::coder::array ¶ms, boolean_T useImaginary, ::coder::array + &allLayers, ::coder::array &allRoughs) + { + ::coder::array b_params; + ::coder::array b_thisContrastLayers1; + ::coder::array c_thisContrastLayers1; + ::coder::array thisContrastLayers1; + ::coder::array thisContrastLayers2; + real_T a__1; + real_T a__2; + real_T a__3; + real_T a__4; + real_T a__6; + real_T thisBulkIn; + real_T thisBulkOut; + int32_T i; + + // Top-level function for processing custom layers for all the + // contrasts. + // Do some pre-definitions to keep the compiler happy... + // totNumCalcs = numberOfContrasts * 2; + i = static_cast(numberOfContrasts); + allRoughs.set_size(i); + allLayers.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + creal_T x; + real_T d; + int32_T iv[2]; + int32_T b_loop_ub; + int32_T loop_ub; + + // Choose which custom file is associated with this contrast + // Find values of 'bulkIn' and 'bulkOut' for this + // contrast... + backSort(contrastBackgrounds[b_i], contrastQzshifts[b_i], + contrastScalefactors[b_i], contrastBulkIns[b_i], + contrastBulkOuts[b_i], contrastResolutions[b_i], + backgroundParams, qzshifts, scalefactor, bulkIn, bulkOut, + resolutionParams, &a__1, &a__2, &a__3, &thisBulkIn, + &thisBulkOut, &a__4); + + // typeDef + d = cCustFiles[b_i]; + iv[0] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ + static_cast(d) - 1].f1)->size())[0]; + iv[1] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ + static_cast(d) - 1].f1)->size())[1]; + x = coder::str2double((const char_T *)((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->data(), iv); + if ((!std::isnan(x.re)) && (!std::isnan(x.im))) { + b_params.set_size(1, params.size(1)); + loop_ub = params.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_params[i1] = params[i1]; + } + + iv[0] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->size())[0]; + iv[1] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->size())[1]; + b_callCppFunction(b_params, thisBulkIn, thisBulkOut, + static_cast(b_i) + 1.0, (const char_T *)((:: + coder::array *)&customFiles[static_cast(d) - + 1].f1)->data(), iv, c_thisContrastLayers1, &allRoughs[b_i]); + loop_ub = c_thisContrastLayers1.size(1); + b_thisContrastLayers1.set_size(c_thisContrastLayers1.size(0), + c_thisContrastLayers1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = c_thisContrastLayers1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1] = + c_thisContrastLayers1[i2 + c_thisContrastLayers1.size(0) * i1]; + } + } + + b_params.set_size(1, params.size(1)); + loop_ub = params.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_params[i1] = params[i1]; + } + + iv[0] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(cCustFiles[b_i]) - 1].f1) + ->size())[0]; + iv[1] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(cCustFiles[b_i]) - 1].f1) + ->size())[1]; + c_callCppFunction(b_params, thisBulkIn, thisBulkOut, + static_cast(b_i) + 1.0, (const char_T *)((:: + coder::array *)&customFiles[static_cast + (cCustFiles[b_i]) - 1].f1)->data(), iv, c_thisContrastLayers1, + &a__6); + loop_ub = c_thisContrastLayers1.size(1); + thisContrastLayers2.set_size(c_thisContrastLayers1.size(0), + c_thisContrastLayers1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = c_thisContrastLayers1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + thisContrastLayers2[i2 + thisContrastLayers2.size(0) * i1] = + c_thisContrastLayers1[i2 + c_thisContrastLayers1.size(0) * i1]; + } + } + } + + // If the output layers has 5 columns, then we need to do + // the hydration correction (the user has not done it in the + // custom function). Do that here.... + if (!useImaginary) { + thisContrastLayers1.set_size(b_thisContrastLayers1.size(0), + b_thisContrastLayers1.size(1)); + loop_ub = b_thisContrastLayers1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = b_thisContrastLayers1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1] = + b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1]; + } + } + + applyHydrationReal(thisContrastLayers1, thisBulkIn, thisBulkOut); + b_thisContrastLayers1.set_size(thisContrastLayers1.size(0), + thisContrastLayers1.size(1)); + loop_ub = thisContrastLayers1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = thisContrastLayers1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1] = + thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1]; + } + } + + thisContrastLayers1.set_size(thisContrastLayers2.size(0), + thisContrastLayers2.size(1)); + loop_ub = thisContrastLayers2.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = thisContrastLayers2.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1] = + thisContrastLayers2[i2 + thisContrastLayers2.size(0) * i1]; + } + } + + applyHydrationReal(thisContrastLayers1, thisBulkIn, thisBulkOut); + thisContrastLayers2.set_size(thisContrastLayers1.size(0), + thisContrastLayers1.size(1)); + loop_ub = thisContrastLayers1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = thisContrastLayers1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + thisContrastLayers2[i2 + thisContrastLayers2.size(0) * i1] = + thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1]; + } + } + } else { + thisContrastLayers1.set_size(b_thisContrastLayers1.size(0), + b_thisContrastLayers1.size(1)); + loop_ub = b_thisContrastLayers1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = b_thisContrastLayers1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1] = + b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1]; + } + } + + applyHydrationImag(thisContrastLayers1, thisBulkIn, thisBulkOut); + b_thisContrastLayers1.set_size(thisContrastLayers1.size(0), + thisContrastLayers1.size(1)); + loop_ub = thisContrastLayers1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = thisContrastLayers1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1] = + thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1]; + } + } + + thisContrastLayers1.set_size(thisContrastLayers2.size(0), + thisContrastLayers2.size(1)); + loop_ub = thisContrastLayers2.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = thisContrastLayers2.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1] = + thisContrastLayers2[i2 + thisContrastLayers2.size(0) * i1]; + } + } + + applyHydrationImag(thisContrastLayers1, thisBulkIn, thisBulkOut); + thisContrastLayers2.set_size(thisContrastLayers1.size(0), + thisContrastLayers1.size(1)); + loop_ub = thisContrastLayers1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = thisContrastLayers1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + thisContrastLayers2[i2 + thisContrastLayers2.size(0) * i1] = + thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1]; + } + } + } + + allLayers[b_i].f1.set_size(b_thisContrastLayers1.size(0), + b_thisContrastLayers1.size(1)); + loop_ub = b_thisContrastLayers1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = b_thisContrastLayers1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1]; + } + } + + allLayers[b_i + allLayers.size(0)].f1.set_size + (thisContrastLayers2.size(0), thisContrastLayers2.size(1)); + loop_ub = thisContrastLayers2.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = thisContrastLayers2.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i + allLayers.size(0)].f1[i2 + allLayers[b_i + + allLayers.size(0)].f1.size(0) * i1] = thisContrastLayers2[i2 + + thisContrastLayers2.size(0) * i1]; + } + } + } + } + } + } +} + +// End of code generation (processCustomFunction2.cpp) diff --git a/RAT/processCustomFunction2.h b/RAT/processCustomFunction2.h new file mode 100644 index 00000000..39775c0d --- /dev/null +++ b/RAT/processCustomFunction2.h @@ -0,0 +1,46 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// processCustomFunction2.h +// +// Code generation for function 'processCustomFunction2' +// +#ifndef PROCESSCUSTOMFUNCTION2_H +#define PROCESSCUSTOMFUNCTION2_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace customLayers + { + void processCustomFunction(const ::coder::array + &contrastBackgrounds, const ::coder::array &contrastQzshifts, + const ::coder::array &contrastScalefactors, const ::coder:: + array &contrastBulkIns, const ::coder::array + &contrastBulkOuts, const ::coder::array &contrastResolutions, + const ::coder::array &backgroundParams, const ::coder::array< + real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &resolutionParams, const :: + coder::array &cCustFiles, real_T numberOfContrasts, const :: + coder::array &customFiles, const ::coder::array ¶ms, boolean_T useImaginary, ::coder::array + &allLayers, ::coder::array &allRoughs); + } + } +} + +#endif + +// End of code generation (processCustomFunction2.h) diff --git a/RAT/processCustomFunction3.cpp b/RAT/processCustomFunction3.cpp new file mode 100644 index 00000000..c2796f54 --- /dev/null +++ b/RAT/processCustomFunction3.cpp @@ -0,0 +1,173 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// processCustomFunction3.cpp +// +// Code generation for function 'processCustomFunction3' +// + +// Include files +#include "processCustomFunction3.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "backSort.h" +#include "callCppFunction.h" +#include "rt_nonfinite.h" +#include "str2double.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1); +} + +// Function Definitions +namespace RAT +{ + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1) + { + int32_T i; + r1.set_size(r.size(0), 2); + i = r.size(0) << 1; + for (int32_T i1{0}; i1 < i; i1++) { + int32_T loop_ub; + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; + } + } + } + } + + namespace domainsTF + { + namespace customXY + { + void processCustomFunction(const ::coder::array + &contrastBackgrounds, const ::coder::array &contrastQzshifts, + const ::coder::array &contrastScalefactors, const ::coder:: + array &contrastBulkIns, const ::coder::array + &contrastBulkOuts, const ::coder::array &contrastResolutions, + const ::coder::array &backgroundParams, const ::coder::array< + real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: + array &cCustFiles, real_T numberOfContrasts, const ::coder:: + array &customFiles, const ::coder::array + ¶ms, ::coder::array &allSLDs, ::coder::array &allRoughs) + { + ::coder::array tempAllSLDs; + ::coder::array b_params; + ::coder::array r; + real_T a__1; + real_T a__2; + real_T a__3; + real_T a__4; + real_T a__6; + real_T thisBulkIn; + real_T thisBulkOut; + int32_T i; + + // Top-level function for processing custom XY profiles for all the + // contrasts. + // Do some pre-definitions to keep the compiler happy... + i = static_cast(numberOfContrasts); + allRoughs.set_size(i); + + // 3 columns to allow for potential imaginary curve + tempAllSLDs.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + creal_T x; + real_T d; + int32_T iv[2]; + + // TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's.. + // Choose which custom file is associated with this contrast + // Find values of 'bulkIn' and 'bulkOut' for this contrast... + backSort(contrastBackgrounds[b_i], contrastQzshifts[b_i], + contrastScalefactors[b_i], contrastBulkIns[b_i], + contrastBulkOuts[b_i], contrastResolutions[b_i], + backgroundParams, qzshifts, scalefactor, bulkIn, bulkOut, res, + &a__1, &a__2, &a__3, &thisBulkIn, &thisBulkOut, &a__4); + d = cCustFiles[b_i]; + iv[0] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ + static_cast(d) - 1].f1)->size())[0]; + iv[1] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ + static_cast(d) - 1].f1)->size())[1]; + x = coder::str2double((const char_T *)((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->data(), iv); + if ((!std::isnan(x.re)) && (!std::isnan(x.im))) { + int32_T b_loop_ub; + int32_T loop_ub; + b_params.set_size(1, params.size(1)); + loop_ub = params.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_params[i1] = params[i1]; + } + + iv[0] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->size())[0]; + iv[1] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->size())[1]; + b_callCppFunction(b_params, thisBulkIn, thisBulkOut, + static_cast(b_i) + 1.0, (const char_T *)((:: + coder::array *)&customFiles[static_cast(d) - + 1].f1)->data(), iv, r, &allRoughs[b_i]); + loop_ub = r.size(1); + tempAllSLDs[b_i].f1.set_size(r.size(0), r.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = r.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + tempAllSLDs[b_i].f1[i2 + tempAllSLDs[b_i].f1.size(0) * i1] = + r[i2 + r.size(0) * i1]; + } + } + + b_params.set_size(1, params.size(1)); + loop_ub = params.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_params[i1] = params[i1]; + } + + iv[0] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(cCustFiles[b_i]) - 1].f1) + ->size())[0]; + iv[1] = (*(int32_T (*)[2])((::coder::array *) + &customFiles[static_cast(cCustFiles[b_i]) - 1].f1) + ->size())[1]; + c_callCppFunction(b_params, thisBulkIn, thisBulkOut, + static_cast(b_i) + 1.0, (const char_T *)((:: + coder::array *)&customFiles[static_cast + (cCustFiles[b_i]) - 1].f1)->data(), iv, r, &a__6); + loop_ub = r.size(1); + tempAllSLDs[b_i + tempAllSLDs.size(0)].f1.set_size(r.size(0), r.size + (1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = r.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + tempAllSLDs[b_i + tempAllSLDs.size(0)].f1[i2 + tempAllSLDs[b_i + + tempAllSLDs.size(0)].f1.size(0) * i1] = r[i2 + r.size(0) * i1]; + } + } + } + } + + cast(tempAllSLDs, allSLDs); + } + } + } +} + +// End of code generation (processCustomFunction3.cpp) diff --git a/RAT/processCustomFunction3.h b/RAT/processCustomFunction3.h new file mode 100644 index 00000000..3caa6a8b --- /dev/null +++ b/RAT/processCustomFunction3.h @@ -0,0 +1,46 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// processCustomFunction3.h +// +// Code generation for function 'processCustomFunction3' +// +#ifndef PROCESSCUSTOMFUNCTION3_H +#define PROCESSCUSTOMFUNCTION3_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace customXY + { + void processCustomFunction(const ::coder::array + &contrastBackgrounds, const ::coder::array &contrastQzshifts, + const ::coder::array &contrastScalefactors, const ::coder:: + array &contrastBulkIns, const ::coder::array + &contrastBulkOuts, const ::coder::array &contrastResolutions, + const ::coder::array &backgroundParams, const ::coder::array< + real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: + array &cCustFiles, real_T numberOfContrasts, const ::coder:: + array &customFiles, const ::coder::array + ¶ms, ::coder::array &allSLDs, ::coder::array &allRoughs); + } + } +} + +#endif + +// End of code generation (processCustomFunction3.h) diff --git a/RAT/qrsolve.cpp b/RAT/qrsolve.cpp new file mode 100644 index 00000000..55947edf --- /dev/null +++ b/RAT/qrsolve.cpp @@ -0,0 +1,175 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// qrsolve.cpp +// +// Code generation for function 'qrsolve' +// + +// Include files +#include "qrsolve.h" +#include "rt_nonfinite.h" +#include "xunormqr.h" +#include "xzgeqp3.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + static void LSQFromQR(const ::coder::array &A, const real_T + tau_data[], ::coder::array &B, int32_T + rankA, ::coder::array &Y); + static int32_T rankFromQR(const ::coder::array &A); + } + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + static void LSQFromQR(const ::coder::array &A, const real_T + tau_data[], ::coder::array &B, int32_T + rankA, ::coder::array &Y) + { + int32_T k; + int32_T nb; + nb = B.size(1); + Y.set_size(1, B.size(1)); + k = B.size(1); + for (int32_T j{0}; j < k; j++) { + Y[j] = 0.0; + } + + lapack::xunormqr(A, B, tau_data); + for (k = 0; k < nb; k++) { + if (static_cast(rankA) - 1 >= 0) { + Y[k] = B[B.size(0) * k]; + } + + for (int32_T j{rankA}; j >= 1; j--) { + Y[k] = Y[k] / A[0]; + } + } + } + + static int32_T rankFromQR(const ::coder::array &A) + { + int32_T r; + r = 0; + if (A.size(0) >= 1) { + real_T tol_tmp; + tol_tmp = std::abs(A[0]); + if (!(tol_tmp <= std::fmin(1.4901161193847656E-8, + 2.2204460492503131E-15 * static_cast(A.size(0))) * + tol_tmp)) { + r = 1; + } + } + + return r; + } + + void LSQFromQR(const ::coder::array &A, const ::coder::array< + real_T, 1U> &tau, const ::coder::array &jpvt, :: + coder::array &B, int32_T rankA, ::coder::array< + real_T, 2U> &Y) + { + int32_T b_i; + int32_T i; + int32_T k; + int32_T nb; + nb = B.size(1); + Y.set_size(A.size(1), B.size(1)); + i = B.size(1); + for (b_i = 0; b_i < i; b_i++) { + k = A.size(1); + for (int32_T j{0}; j < k; j++) { + Y[j] = 0.0; + } + } + + lapack::xunormqr(A, B, tau); + for (k = 0; k < nb; k++) { + for (i = 0; i < rankA; i++) { + Y[jpvt[i] - 1] = B[i]; + } + + for (int32_T j{rankA}; j >= 1; j--) { + b_i = jpvt[j - 1]; + Y[b_i - 1] = Y[b_i - 1] / A[(j + A.size(0) * (j - 1)) - 1]; + for (i = 0; i <= j - 2; i++) { + Y[jpvt[i] - 1] = Y[jpvt[i] - 1] - Y[jpvt[j - 1] - 1] * A[i + + A.size(0) * (j - 1)]; + } + } + } + } + + void qrsolve(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &Y) + { + ::coder::array b_B; + ::coder::array b_A; + real_T tau_data; + int32_T jpvt; + int32_T loop_ub; + b_A.set_size(A.size(0)); + loop_ub = A.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_A[i] = A[i]; + } + + reflapack::xzgeqp3(b_A, A.size(0), (real_T *)&tau_data, &loop_ub, &jpvt); + b_B.set_size(B.size(0), B.size(1)); + loop_ub = B.size(1) - 1; + for (int32_T i{0}; i <= loop_ub; i++) { + jpvt = B.size(0) - 1; + for (int32_T i1{0}; i1 <= jpvt; i1++) { + b_B[i1 + b_B.size(0) * i] = B[i1 + B.size(0) * i]; + } + } + + LSQFromQR(b_A, (const real_T *)&tau_data, b_B, rankFromQR(b_A), Y); + } + + int32_T rankFromQR(const ::coder::array &A) + { + int32_T maxmn; + int32_T minmn; + int32_T r; + r = 0; + if (A.size(0) < A.size(1)) { + minmn = A.size(0); + maxmn = A.size(1); + } else { + minmn = A.size(1); + maxmn = A.size(0); + } + + if (minmn > 0) { + real_T tol; + tol = std::fmin(1.4901161193847656E-8, 2.2204460492503131E-15 * + static_cast(maxmn)) * std::abs(A[0]); + while ((r < minmn) && (!(std::abs(A[r + A.size(0) * r]) <= tol))) { + r++; + } + } + + return r; + } + } + } +} + +// End of code generation (qrsolve.cpp) diff --git a/RAT/qrsolve.h b/RAT/qrsolve.h new file mode 100644 index 00000000..028a3643 --- /dev/null +++ b/RAT/qrsolve.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// qrsolve.h +// +// Code generation for function 'qrsolve' +// +#ifndef QRSOLVE_H +#define QRSOLVE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void LSQFromQR(const ::coder::array &A, const ::coder::array< + real_T, 1U> &tau, const ::coder::array &jpvt, :: + coder::array &B, int32_T rankA, ::coder::array< + real_T, 2U> &Y); + void qrsolve(const ::coder::array &A, const ::coder::array< + real_T, 2U> &B, ::coder::array &Y); + int32_T rankFromQR(const ::coder::array &A); + } + } +} + +#endif + +// End of code generation (qrsolve.h) diff --git a/RAT/rand.cpp b/RAT/rand.cpp new file mode 100644 index 00000000..6c5d8df5 --- /dev/null +++ b/RAT/rand.cpp @@ -0,0 +1,383 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rand.cpp +// +// Code generation for function 'rand' +// + +// Include files +#include "rand.h" +#include "RATMain_data.h" +#include "eml_rand_mt19937ar.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_rand(real_T r[4]) + { + real_T b_r; + uint32_T u[2]; + + // ========================= COPYRIGHT NOTICE ============================ + // This is a uniform (0,1) pseudorandom number generator based on: + // + // A C-program for MT19937, with initialization improved 2002/1/26. + // Coded by Takuji Nishimura and Makoto Matsumoto. + // + // Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + // All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions + // are met: + // + // 1. Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // + // 2. Redistributions in binary form must reproduce the above copyright + // notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // + // 3. The names of its contributors may not be used to endorse or + // promote products derived from this software without specific + // prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + // + // ============================= END ================================= + do { + genrand_uint32_vector(state, u); + u[0] >>= 5U; + u[1] >>= 6U; + b_r = 1.1102230246251565E-16 * (static_cast(u[0]) * 6.7108864E+7 + + static_cast(u[1])); + } while (b_r == 0.0); + + r[0] = b_r; + + // ========================= COPYRIGHT NOTICE ============================ + // This is a uniform (0,1) pseudorandom number generator based on: + // + // A C-program for MT19937, with initialization improved 2002/1/26. + // Coded by Takuji Nishimura and Makoto Matsumoto. + // + // Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + // All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions + // are met: + // + // 1. Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // + // 2. Redistributions in binary form must reproduce the above copyright + // notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // + // 3. The names of its contributors may not be used to endorse or + // promote products derived from this software without specific + // prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + // + // ============================= END ================================= + do { + genrand_uint32_vector(state, u); + u[0] >>= 5U; + u[1] >>= 6U; + b_r = 1.1102230246251565E-16 * (static_cast(u[0]) * 6.7108864E+7 + + static_cast(u[1])); + } while (b_r == 0.0); + + r[1] = b_r; + + // ========================= COPYRIGHT NOTICE ============================ + // This is a uniform (0,1) pseudorandom number generator based on: + // + // A C-program for MT19937, with initialization improved 2002/1/26. + // Coded by Takuji Nishimura and Makoto Matsumoto. + // + // Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + // All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions + // are met: + // + // 1. Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // + // 2. Redistributions in binary form must reproduce the above copyright + // notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // + // 3. The names of its contributors may not be used to endorse or + // promote products derived from this software without specific + // prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + // + // ============================= END ================================= + do { + genrand_uint32_vector(state, u); + u[0] >>= 5U; + u[1] >>= 6U; + b_r = 1.1102230246251565E-16 * (static_cast(u[0]) * 6.7108864E+7 + + static_cast(u[1])); + } while (b_r == 0.0); + + r[2] = b_r; + + // ========================= COPYRIGHT NOTICE ============================ + // This is a uniform (0,1) pseudorandom number generator based on: + // + // A C-program for MT19937, with initialization improved 2002/1/26. + // Coded by Takuji Nishimura and Makoto Matsumoto. + // + // Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + // All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions + // are met: + // + // 1. Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // + // 2. Redistributions in binary form must reproduce the above copyright + // notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // + // 3. The names of its contributors may not be used to endorse or + // promote products derived from this software without specific + // prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + // + // ============================= END ================================= + do { + genrand_uint32_vector(state, u); + u[0] >>= 5U; + u[1] >>= 6U; + b_r = 1.1102230246251565E-16 * (static_cast(u[0]) * 6.7108864E+7 + + static_cast(u[1])); + } while (b_r == 0.0); + + r[3] = b_r; + } + + real_T b_rand() + { + real_T r; + + // ========================= COPYRIGHT NOTICE ============================ + // This is a uniform (0,1) pseudorandom number generator based on: + // + // A C-program for MT19937, with initialization improved 2002/1/26. + // Coded by Takuji Nishimura and Makoto Matsumoto. + // + // Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + // All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions + // are met: + // + // 1. Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // + // 2. Redistributions in binary form must reproduce the above copyright + // notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // + // 3. The names of its contributors may not be used to endorse or + // promote products derived from this software without specific + // prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + // + // ============================= END ================================= + uint32_T u[2]; + do { + genrand_uint32_vector(state, u); + u[0] >>= 5U; + u[1] >>= 6U; + r = 1.1102230246251565E-16 * (static_cast(u[0]) * 6.7108864E+7 + + static_cast(u[1])); + } while (r == 0.0); + + return r; + } + + void b_rand(real_T varargin_1, real_T varargin_2, ::coder::array + &r) + { + int32_T i; + r.set_size(static_cast(varargin_1), static_cast + (varargin_2)); + i = static_cast(varargin_1) * static_cast(varargin_2); + for (int32_T k{0}; k < i; k++) { + r[k] = eml_rand_mt19937ar(state); + } + } + + void b_rand(const real_T varargin_1[2], ::coder::array &r) + { + int32_T i; + i = static_cast(varargin_1[0]); + r.set_size(i); + for (int32_T k{0}; k < i; k++) { + r[k] = eml_rand_mt19937ar(state); + } + } + + void b_rand(real_T varargin_1, ::coder::array &r) + { + int32_T i; + i = static_cast(varargin_1); + r.set_size(i); + for (int32_T k{0}; k < i; k++) { + r[k] = eml_rand_mt19937ar(state); + } + } + + void b_rand(int32_T varargin_1, ::coder::array &r) + { + r.set_size(varargin_1); + for (int32_T k{0}; k < varargin_1; k++) { + r[k] = eml_rand_mt19937ar(state); + } + } + + void b_rand(real_T varargin_2, ::coder::array &r) + { + int32_T i; + i = static_cast(varargin_2); + r.set_size(1, i); + for (int32_T k{0}; k < i; k++) { + r[k] = eml_rand_mt19937ar(state); + } + } + + void c_rand(real_T r[1000]) + { + for (int32_T k{0}; k < 1000; k++) { + real_T b_r; + + // ========================= COPYRIGHT NOTICE ============================ + // This is a uniform (0,1) pseudorandom number generator based on: + // + // A C-program for MT19937, with initialization improved 2002/1/26. + // Coded by Takuji Nishimura and Makoto Matsumoto. + // + // Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + // All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions + // are met: + // + // 1. Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // + // 2. Redistributions in binary form must reproduce the above copyright + // notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // + // 3. The names of its contributors may not be used to endorse or + // promote products derived from this software without specific + // prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + // + // ============================= END ================================= + uint32_T u[2]; + do { + genrand_uint32_vector(state, u); + u[0] >>= 5U; + u[1] >>= 6U; + b_r = 1.1102230246251565E-16 * (static_cast(u[0]) * + 6.7108864E+7 + static_cast(u[1])); + } while (b_r == 0.0); + + r[k] = b_r; + } + } + } +} + +// End of code generation (rand.cpp) diff --git a/RAT/rand.h b/RAT/rand.h new file mode 100644 index 00000000..220270c1 --- /dev/null +++ b/RAT/rand.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rand.h +// +// Code generation for function 'rand' +// +#ifndef RAND_H +#define RAND_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_rand(real_T r[4]); + real_T b_rand(); + void b_rand(real_T varargin_1, real_T varargin_2, ::coder::array + &r); + void b_rand(const real_T varargin_1[2], ::coder::array &r); + void b_rand(real_T varargin_1, ::coder::array &r); + void b_rand(int32_T varargin_1, ::coder::array &r); + void b_rand(real_T varargin_2, ::coder::array &r); + void c_rand(real_T r[1000]); + } +} + +#endif + +// End of code generation (rand.h) diff --git a/RAT/randn.cpp b/RAT/randn.cpp new file mode 100644 index 00000000..0fef26b7 --- /dev/null +++ b/RAT/randn.cpp @@ -0,0 +1,132 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// randn.cpp +// +// Code generation for function 'randn' +// + +// Include files +#include "randn.h" +#include "RATMain_data.h" +#include "eml_rand_mt19937ar.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void randn(real_T varargin_2, ::coder::array &r) + { + int32_T i; + i = static_cast(varargin_2); + r.set_size(1, i); + for (int32_T k{0}; k < i; k++) { + r[k] = b_eml_rand_mt19937ar(state); + } + } + + void randn(real_T varargin_1, ::coder::array &r) + { + int32_T i; + i = static_cast(varargin_1); + r.set_size(i); + for (int32_T k{0}; k < i; k++) { + r[k] = b_eml_rand_mt19937ar(state); + } + } + + void randn(real_T r[2]) + { + real_T b_r; + real_T u; + real_T x; + int32_T exitg1; + int32_T i; + uint32_T u32[2]; + do { + exitg1 = 0; + genrand_uint32_vector(state, u32); + i = static_cast((u32[1] >> 24U) + 1U); + b_r = ((static_cast(u32[0] >> 3U) * 1.6777216E+7 + + static_cast(static_cast(u32[1]) & 16777215)) * + 2.2204460492503131E-16 - 1.0) * dv[i]; + if (std::abs(b_r) <= dv[i - 1]) { + exitg1 = 1; + } else if (i < 256) { + u = eml_rand_mt19937ar(state); + if (dv1[i] + u * (dv1[i - 1] - dv1[i]) < std::exp(-0.5 * b_r * b_r)) { + exitg1 = 1; + } + } else { + do { + u = eml_rand_mt19937ar(state); + x = std::log(u) * 0.273661237329758; + u = eml_rand_mt19937ar(state); + } while (!(-2.0 * std::log(u) > x * x)); + + if (b_r < 0.0) { + b_r = x - 3.65415288536101; + } else { + b_r = 3.65415288536101 - x; + } + + exitg1 = 1; + } + } while (exitg1 == 0); + + r[0] = b_r; + do { + exitg1 = 0; + genrand_uint32_vector(state, u32); + i = static_cast((u32[1] >> 24U) + 1U); + b_r = ((static_cast(u32[0] >> 3U) * 1.6777216E+7 + + static_cast(static_cast(u32[1]) & 16777215)) * + 2.2204460492503131E-16 - 1.0) * dv[i]; + if (std::abs(b_r) <= dv[i - 1]) { + exitg1 = 1; + } else if (i < 256) { + u = eml_rand_mt19937ar(state); + if (dv1[i] + u * (dv1[i - 1] - dv1[i]) < std::exp(-0.5 * b_r * b_r)) { + exitg1 = 1; + } + } else { + do { + u = eml_rand_mt19937ar(state); + x = std::log(u) * 0.273661237329758; + u = eml_rand_mt19937ar(state); + } while (!(-2.0 * std::log(u) > x * x)); + + if (b_r < 0.0) { + b_r = x - 3.65415288536101; + } else { + b_r = 3.65415288536101 - x; + } + + exitg1 = 1; + } + } while (exitg1 == 0); + + r[1] = b_r; + } + + void randn(real_T varargin_1, real_T varargin_2, ::coder::array + &r) + { + int32_T i; + r.set_size(static_cast(varargin_1), static_cast + (varargin_2)); + i = static_cast(varargin_1) * static_cast(varargin_2); + for (int32_T k{0}; k < i; k++) { + r[k] = b_eml_rand_mt19937ar(state); + } + } + } +} + +// End of code generation (randn.cpp) diff --git a/RAT/randn.h b/RAT/randn.h new file mode 100644 index 00000000..cf81a7bb --- /dev/null +++ b/RAT/randn.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// randn.h +// +// Code generation for function 'randn' +// +#ifndef RANDN_H +#define RANDN_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void randn(real_T varargin_2, ::coder::array &r); + void randn(real_T varargin_1, ::coder::array &r); + void randn(real_T r[2]); + void randn(real_T varargin_1, real_T varargin_2, ::coder::array + &r); + } +} + +#endif + +// End of code generation (randn.h) diff --git a/RAT/randperm.cpp b/RAT/randperm.cpp new file mode 100644 index 00000000..ca838e2a --- /dev/null +++ b/RAT/randperm.cpp @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// randperm.cpp +// +// Code generation for function 'randperm' +// + +// Include files +#include "randperm.h" +#include "rand.h" +#include "rt_nonfinite.h" +#include "sortIdx.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void randperm(real_T n, ::coder::array &p) + { + ::coder::array idx; + int32_T p_idx_1; + b_rand(n, p); + internal::sortIdx(p, idx); + p_idx_1 = p.size(1); + p.set_size(1, p_idx_1); + for (int32_T i{0}; i < p_idx_1; i++) { + p[i] = idx[i]; + } + } + } +} + +// End of code generation (randperm.cpp) diff --git a/RAT/randperm.h b/RAT/randperm.h new file mode 100644 index 00000000..2865100d --- /dev/null +++ b/RAT/randperm.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// randperm.h +// +// Code generation for function 'randperm' +// +#ifndef RANDPERM_H +#define RANDPERM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void randperm(real_T n, ::coder::array &p); + } +} + +#endif + +// End of code generation (randperm.h) diff --git a/RAT/randsample.cpp b/RAT/randsample.cpp new file mode 100644 index 00000000..b23e53a1 --- /dev/null +++ b/RAT/randsample.cpp @@ -0,0 +1,82 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// randsample.cpp +// +// Code generation for function 'randsample' +// + +// Include files +#include "randsample.h" +#include "histc.h" +#include "rand.h" +#include "rt_nonfinite.h" +#include "sum.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void randsample(real_T varargin_2, const real_T varargin_4[2], ::coder:: + array &y) + { + ::coder::array idx; + ::coder::array r; + real_T a__1[3]; + real_T edges[3]; + real_T x; + x = std::floor(varargin_2); + edges[0] = 0.0; + edges[2] = 1.0; + edges[1] = std::fmin(varargin_4[0] / (varargin_4[0] + varargin_4[1]), 1.0); + y.set_size(1, static_cast(x)); + if (static_cast(x) > 0) { + int32_T y_idx_1; + b_rand(static_cast(x), r); + histc(r, edges, a__1, idx); + y_idx_1 = static_cast(x); + y.set_size(1, static_cast(x)); + for (int32_T i{0}; i < y_idx_1; i++) { + y[i] = static_cast(static_cast(idx[i]) - 1); + } + } + } + + void randsample(const real_T varargin_1_data[], real_T varargin_2, const + real_T varargin_4_data[], ::coder::array &y) + { + ::coder::array b_varargin_4_data; + ::coder::array idx; + ::coder::array r; + real_T a__1_data[4]; + real_T edges_data[4]; + real_T sumw; + real_T x; + int32_T a__1_size; + x = std::floor(varargin_2); + b_varargin_4_data.set((real_T *)&varargin_4_data[0], 3); + sumw = sum(b_varargin_4_data); + edges_data[0] = 0.0; + edges_data[3] = 1.0; + edges_data[1] = std::fmin(varargin_4_data[0] / sumw, 1.0); + edges_data[2] = std::fmin(edges_data[1] + varargin_4_data[1] / sumw, 1.0); + y.set_size(1, static_cast(x)); + if (static_cast(x) > 0) { + b_rand(static_cast(x), r); + histc(r, edges_data, a__1_data, &a__1_size, idx); + a__1_size = static_cast(x); + y.set_size(1, static_cast(x)); + for (int32_T i{0}; i < a__1_size; i++) { + y[i] = varargin_1_data[static_cast(idx[i]) - 1]; + } + } + } + } +} + +// End of code generation (randsample.cpp) diff --git a/RAT/randsample.h b/RAT/randsample.h new file mode 100644 index 00000000..986ed1a2 --- /dev/null +++ b/RAT/randsample.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// randsample.h +// +// Code generation for function 'randsample' +// +#ifndef RANDSAMPLE_H +#define RANDSAMPLE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void randsample(real_T varargin_2, const real_T varargin_4[2], ::coder:: + array &y); + void randsample(const real_T varargin_1_data[], real_T varargin_2, const + real_T varargin_4_data[], ::coder::array &y); + } +} + +#endif + +// End of code generation (randsample.h) diff --git a/RAT/ratDREAM.cpp b/RAT/ratDREAM.cpp new file mode 100644 index 00000000..6b6d347a --- /dev/null +++ b/RAT/ratDREAM.cpp @@ -0,0 +1,820 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// ratDREAM.cpp +// +// Code generation for function 'ratDREAM' +// + +// Include files +#include "ratDREAM.h" +#include "RATMain_data.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "adaptPCR.h" +#include "blockedSummation.h" +#include "calcDensity.h" +#include "calcProposal.h" +#include "combineVectorElements.h" +#include "drawCR.h" +#include "evaluateModel.h" +#include "fileManager.h" +#include "find.h" +#include "gelman.h" +#include "initializeDREAM.h" +#include "metropolisRule.h" +#include "mod.h" +#include "removeOutlier.h" +#include "repmat.h" +#include "rt_nonfinite.h" +#include "setupDREAM.h" +#include "std.h" +#include "sum.h" +#include "textProgressBar.h" +#include "tic.h" +#include "toc.h" +#include "unsafeSxfun.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include +#include +#include + +// Type Definitions +namespace RAT +{ + struct g_struct_T + { + char_T prior[7]; + ::coder::array min; + ::coder::array max; + ::coder::bounded_array boundhandling; + boolean_T mvnpdf; + }; +} + +// Function Definitions +namespace RAT +{ + void ratDREAM(real_T dreamVariables_d, real_T dreamVariables_N, real_T + dreamVariables_T, real_T dreamVariables_lambda, real_T + dreamVariables_pUnitGamma, boolean_T dreamVariables_adaptPCR, + const ::coder::array &Par_info_min, const ::coder:: + array &Par_info_max, const char_T + Par_info_boundhandling_data[], const int32_T + Par_info_boundhandling_size[2], const struct5_T + *ratInputs_problemDef, const cell_14 *ratInputs_problemDefCells, + const struct2_T *ratInputs_controls, const ::coder::array &ratInputs_priors, ::coder::array &chain, + struct13_T *output, ::coder::array &fx) + { + ::coder::array b_chain; + ::coder::array CR; + ::coder::array Table_gamma; + ::coder::array X; + ::coder::array b_r; + ::coder::array b_xnew; + ::coder::array fx_new; + ::coder::array log_L; + ::coder::array r; + ::coder::array r1; + ::coder::array x; + ::coder::array xnew; + ::coder::array xold; + ::coder::array b_X; + ::coder::array c_X; + ::coder::array delta_normX; + ::coder::array idx_ac; + ::coder::array log_L_xnew; + ::coder::array log_PR_xnew; + ::coder::array r2; + ::coder::array accept; + ::coder::array b_CR_data; + g_struct_T Par_info; + struct14_T DREAMPar; + struct15_T Meas_info; + real_T delta_tot_data[3]; + real_T lCR_data[3]; + real_T pCR_data[3]; + real_T totaccept; + int32_T delta_tot_size[2]; + int32_T lCR_size[2]; + int32_T pCR_size[2]; + int32_T gen; + int32_T i; + int32_T iteration; + int32_T loop_ub; + uint32_T iloc; + boolean_T CR_data[100]; + + // Modified version of Vrugt DREAm algorithm to be specific for RAT.... + // ----------------------------------------------------------------------------------------------% + // % + // DDDDDDDDDDDDDDD RRRRRRRRRRRRRR EEEEEEEEEEEEEEEE AAAAA MMM MMM % + // DDDDDDDDDDDDDDDD RRRRRRRRRRRRRRR EEEEEEEEEEEEEEEE AAAAA MMMM MMMM % + // DDD DDD RRR RRR EEE AAA AAA MMMMM MMMMM % + // DDD DDD RRR RRR EEE AAA AAA MMMMMM MMMMMM % + // DDD DDD RRR RRR EEE AAA AAA MMM MMM MMM MMM % + // DDD DDD RRR RRR EEE AAA AAA MMM MMM MMM MMM % + // DDD DDD RRRRRRRRRRRRRRR EEEEEEEEEEEEEEEE AAA AAA MMM MMM MMM MMM % + // DDD DDD RRRRRRRRRRRRRR EEEEEEEEEEEEEEEE AAAAAAAAAAA MMM MMMM MMM % + // DDD DDD RRR RR EEE AAA AAA MMM MMM % + // DDD DDD RRR RRR EEE AAA AAA MMM MMM % + // DDD DDD RRR RRR EEE AAA AAA MMM MMM % + // DDDDDDDDDDDDDDDD RRR RRR EEEEEEEEEEEEEEEE AAA AAA MMM MMM % + // DDDDDDDDDDDDDDD RRR RRR EEEEEEEEEEEEEEEE AAA AAA MMM MMM % + // % + // ----------------------------------------------------------------------------------------------% + // ----------------- DiffeRential Evolution Adaptive Metropolis algorithm -----------------------% + // % + // DREAM runs multiple different chains simultaneously for global exploration, and automatically % + // tunes the scale and orientation of the proposal distribution using differential evolution. % + // The algorithm maintains detailed balance and ergodicity and works well and efficient for a % + // large range of problems, especially in the presence of high-dimensionality and % + // multimodality. % + // % + // DREAM developed by Jasper A. Vrugt and Cajo ter Braak % + // % + // --------------------------------------------------------------------------------------------- % + // % + // SYNOPSIS: [chain,output,fx,log_L] = DREAM(Func_name,DREAMPar) % + // [chain,output,fx,log_L] = DREAM(Func_name,DREAMPar,Par_info) % + // [chain,output,fx,log_L] = DREAM(Func_name,DREAMPar,Par_info,Meas_info) % + // % + // Input: Func_name = name of the function ( = model ) that returns density of proposal % + // DREAMPar = structure with algorithmic / computatinal settings of DREAM % + // Par_info = structure with parameter ranges, prior distribution, boundary handling % + // Meas_info = optional structure with measurements to be evaluated against % + // % + // Output: chain = 3D array with chain trajectories, log-prior and log-likelihood values % + // output = structure with convergence properties, acceptance rate, CR values, etc. % + // fx = matrix with model simulations % + // log_L = matrix with log-likelihood values sampled chains % + // % + // The directory \PostProcessing contains a script "PostProcMCMC" that will compute various % + // posterior statistics (MEAN, STD, MAP, CORR) and create create various plots including, % + // marginal posterior parameter distributions, R_stat convergence diagnostic, two-dimensional % + // correlation plots of the posterior parameter samples, chain convergence plots, and parameter % + // and total posterior simulation uncertainty ranges (interval can be specified) % + // % + // --------------------------------------------------------------------------------------------- % + // % + // This algorithm has been described in: % + // % + // Vrugt, J.A., C.J.F. ter Braak, M.P. Clark, J.M. Hyman, and B.A. Robinson, Treatment of % + // input uncertainty in hydrologic modeling: Doing hydrology backward with Markov chain % + // Monte Carlo simulation, Water Resources Research, 44, W00B09, doi:10.1029/2007WR006720, % + // 2008. % + // % + // Vrugt, J.A., C.J.F. ter Braak, C.G.H. Diks, D. Higdon, B.A. Robinson, and J.M. Hyman, % + // Accelerating Markov chain Monte Carlo simulation by differential evolution with % + // self-adaptive randomized subspace sampling, International Journal of Nonlinear % + // Sciences and Numerical Simulation, 10(3), 271-288, 2009. % + // % + // Vrugt, J.A., C.J.F. ter Braak, H.V. Gupta, and B.A. Robinson, Equifinality of formal % + // (DREAM) and informal (GLUE) Bayesian approaches in hydrologic modeling?, Stochastic % + // Environmental Research and Risk Assessment, 23(7), 1011-1026, % + // doi:10.1007/s00477-008-0274-y, 2009 % + // % + // Laloy, E., and J.A. Vrugt, High-dimensional posterior exploration of hydrologic models % + // using multiple-try DREAM_(ZS) and high-performance computing, Water Resources Research, % + // 48, W01526, doi:10.1029/2011WR010608, 2012. % + // % + // Vrugt, J.A., and M. Sadegh, Toward diagnostic model calibration and evaluation: % + // Approximate Bayesian computation, Water Resources Research, 49, 4335�4345, % + // doi:10.1002/wrcr.20354, 2013. % + // % + // Sadegh, M., and J.A. Vrugt, Approximate Bayesian computation using Markov chain Monte % + // Carlo simulation: DREAM_(ABC), Water Resources Research, doi:10.1002/2014WR015386, % + // 2014. % + // % + // For more information please read: % + // % + // Ter Braak, C.J.F., A Markov Chain Monte Carlo version of the genetic algorithm Differential % + // Evolution: easy Bayesian computing for real parameter spaces, Stat. Comput., 16, % + // 239 - 249, doi:10.1007/s11222-006-8769-1, 2006. % + // % + // Vrugt, J.A., H.V. Gupta, W. Bouten and S. Sorooshian, A Shuffled Complex Evolution % + // Metropolis algorithm for optimization and uncertainty assessment of hydrologic model % + // parameters, Water Resour. Res., 39 (8), 1201, doi:10.1029/2002WR001642, 2003. % + // % + // Ter Braak, C.J.F., and J.A. Vrugt, Differential Evolution Markov Chain with snooker updater % + // and fewer chains, Statistics and Computing, 10.1007/s11222-008-9104-9, 2008. % + // % + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // % + // Copyright (C) 2011-2012 the authors % + // % + // This program is free software: you can modify it under the terms of the GNU General % + // Public License as published by the Free Software Foundation, either version 3 of the % + // License, or (at your option) any later version. % + // % + // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; % + // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. % + // See the GNU General Public License for more details. % + // % + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // % + // MATLAB code written by Jasper A. Vrugt, University of California Irvine, jasper@uci.edu % + // % + // Version 0.5: June 2008 % + // Version 1.0: October 2008 Adaption updated and generalized CR implementation % + // Version 1.1: January 2010 Restart run and new AR-1 likelihood function with model error % + // Version 1.2: August 2010 Generalized likelihood function and prior distribution % + // Version 1.3: September 2010 Explicit treatment of prior distribution % + // Version 1.4: October 2010 Limits of acceptability (GLUE) and few small changes % + // Version 1.5: April 2011 Small maintenance updates -- 2 external executables % + // Version 1.6: August 2011 whittle likelihood function (SPECTRAL ANALYSIS !!) % + // Version 1.7: April 2012 Simplified code (removed variables) + graphical interface % + // Version 1.8: May 2012 Added new option for Approximate Bayesian Computation % + // Version 1.9: June 2012 Simulations stored, new example, and updated likelihood func. % + // Version 2.0: January 2013 Simplification of metrop.m and DREAM.m % + // Version 2.1: September 2013 Added inference of measurement error as new option % + // Version 2.4: May 2014 Parallellization using parfor (done if CPU > 1) % + // % + // --------------------------------------------------------------------------------------------- % + // ------ AVH -- Always will have consistent variable numbers ------- + // Check how many input variables + // if nargin < 4, Meas_info.Y = []; end; + // if isempty(Meas_info), Meas_info.Y = []; end; + // ------------------------------------------------------------------------ + // if ~isfield(dreamVariables,'restart') || ~dreamVariables.restart + // Initialize the main variables used in DREAM + Par_info.min.set_size(1, Par_info_min.size(1)); + loop_ub = Par_info_min.size(1); + for (i = 0; i < loop_ub; i++) { + Par_info.min[i] = Par_info_min[i]; + } + + Par_info.max.set_size(1, Par_info_max.size(1)); + loop_ub = Par_info_max.size(1); + for (i = 0; i < loop_ub; i++) { + Par_info.max[i] = Par_info_max[i]; + } + + Par_info.boundhandling.size[0] = 1; + Par_info.boundhandling.size[1] = Par_info_boundhandling_size[1]; + loop_ub = Par_info_boundhandling_size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&Par_info_boundhandling_data[0], + &Par_info_boundhandling_data[loop_ub], + &Par_info.boundhandling.data[0]); + } + + setupDREAM(dreamVariables_d, dreamVariables_N, dreamVariables_T, + dreamVariables_lambda, dreamVariables_pUnitGamma, + dreamVariables_adaptPCR, &DREAMPar, &Meas_info, chain, output, + log_L, Table_gamma); + iloc = 1U; + iteration = 1; + gen = 1; + + // Check for setup errors + // [stop,fid] = checkDREAM(DREAMPar,Par_info,Meas_info); + // Check for setup errors + // Assign stop to be No + // First close all files + coder::fileManager(); + + // ----------------------REMOVE warning file - AVH + // open an output file with warnings + // fid = fopen('warning_file.txt','w'); + // fprintf(fid,'-------------- DREAM warning file --------------\n'); + // ------------------------------------------------ + // Check number of chains + // Check parameter ranges + // % Check prior distribution + // if ( strcmp(lower(DREAMPar.prior),'yes') ) || ( strcmp(lower(Par_info),'prior') ), + // % Error -- if explicit prior is used --> marginals need to be defined + // if ~isfield(Par_info,'prior_marginal'); + // evalstr = char('DREAM ERROR: Prior chosen but no marginal distribution specified to sample from -> Define Par_info.prior_marginal!!\n'); + // % Now print warning to screen and to file + // fprintf(evalstr); fprintf(fid,evalstr); + // % Stop DREAM + // stop = true; + // end; + // end; + // Check whether we specified measurement sigma correctly + // if ( DREAMPar.lik == 12 || DREAMPar.lik == 13 ) && ( isfield(Meas_info,'Sigma') == 0 ) + // % Error -- Meas_info.Sigma needs to be specified!! + // error('DREAM ERROR: Meas_info.Sigma needs to be specified either as inline function or one or multiple numerical values!!\n'); + // end + // Check whether the length of the user specified sigma is correct + // Return to main program + // if stop; return; end + // Create computing environment (depending whether multi-core is used) + // Sets up sequential / parallel + // global DREAM_dir EXAMPLE_dir; + // Now create the function handle + // Currently using a function handle for RAT - AVH + // if isa(Func_name,'function_handle') + // f_handle = Func_name; + // else + // f_handle = eval(['@(x)',char(Func_name),'(x)']); + // end + // Now check if we want parallel execution of chains or not? + // We use 1 CPU (processor) + DREAMPar.CPU = 1.0; + + // Now print to screen all the settings + // Now check how the measurement sigma is arranged (estimated or defined) + // + // ----------------------------------------- + // We do not have user inputted sigma in this form for the RAT + // implementation - Measurement Error is dealt with downstream in the + // likelihood function. So, we can remove the check for sigma. + // --------------- AVH ------------------------- + // Meas_info = checkSigma(Meas_info); + // Create the initial states of each of the chains (initial population) + initializeDREAM(&DREAMPar, Par_info.min, Par_info.max, + Par_info.boundhandling.data, Par_info.boundhandling.size, + chain, output, log_L, ratInputs_problemDef, + ratInputs_problemDefCells, ratInputs_controls, + ratInputs_priors, X, fx, CR, pCR_data, pCR_size, lCR_data, + lCR_size, delta_tot_data, delta_tot_size); + + // elseif DREAMPar.restart + // + // % Print to screen restart run + // disp('Restart run'); + // % If a restart run is being done: just load the output from the previous ongoing trial + // load DREAM.mat; [CR] = drawCR(DREAMPar,pCR); DREAMPar.T = 2 * DREAMPar.T; + // % And make sure we add zeros to "chain" array + // chain = [chain ; nan(size(chain,1)-1,size(chain,2),size(chain,3))]; + // % Open warning file and set T_start + // fid = fopen('warning_file.txt','a+'); T_start = t + 1; + // end + // Initialize waitbar. + // fprintf('\n'); + lastNchar = 0.0; + lastNchar_not_empty = true; + + // h = waitbar(0,'Running DREAM - Please wait...'); + totaccept = 0.0; + coder::tic(); + + // Now start iteration ... + i = static_cast(DREAMPar.T - 1.0); + for (int32_T t{0}; t < i; t++) { + real_T tmp_data[100]; + real_T varargin_1; + int32_T b_loop_ub; + int32_T i1; + int32_T i2; + int32_T input_sizes_idx_1; + int32_T result; + int32_T tmp_size; + int8_T b_input_sizes_idx_1; + int8_T sizes_idx_1; + boolean_T empty_non_axis_sizes; + + // Unoack current state of chain and associated log-likelihood and log-prior values + if (X.size(1) - 2 < 1) { + loop_ub = 0; + } else { + loop_ub = X.size(1) - 2; + } + + xold.set_size(X.size(0), loop_ub); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = X.size(0); + for (i2 = 0; i2 < b_loop_ub; i2++) { + xold[i2 + xold.size(0) * i1] = X[i2 + X.size(0) * i1]; + } + } + + // Now generate candidate in each sequence using current point and members of X + loop_ub = CR.size(0); + tmp_size = CR.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + tmp_data[i1] = CR[i1 + CR.size(0) * gen]; + } + + calcProposal(xold, tmp_data, &DREAMPar, Table_gamma, Par_info.min, + Par_info.max, Par_info.boundhandling.data, + Par_info.boundhandling.size, xnew); + for (i1 = 0; i1 < tmp_size; i1++) { + CR[i1 + CR.size(0) * gen] = tmp_data[i1]; + } + + // Now evaluate the model ( = pdf ) and return fx + evaluateModel(xnew, &DREAMPar, ratInputs_problemDef, + ratInputs_problemDefCells, ratInputs_controls, fx_new); + + // Calculate the log-likelihood and log-prior of x (fx) + calcDensity(xnew, fx_new, &DREAMPar, ratInputs_problemDef->fitLimits, + ratInputs_priors, log_L_xnew, log_PR_xnew); + + // Calculate the Metropolis ratio + tmp_size = X.size(1); + loop_ub = X.size(0); + b_X.set_size(X.size(0)); + c_X.set_size(X.size(0)); + for (i1 = 0; i1 < loop_ub; i1++) { + b_X[i1] = X[i1 + X.size(0) * (tmp_size - 1)]; + c_X[i1] = X[i1 + X.size(0) * (tmp_size - 2)]; + } + + metropolisRule(&DREAMPar, log_L_xnew, log_PR_xnew, b_X, c_X, accept, + idx_ac); + + // And update X and the model simulation + if (DREAMPar.d < 1.0) { + loop_ub = 0; + } else { + loop_ub = static_cast(DREAMPar.d); + } + + if ((idx_ac.size(0) != 0) && (loop_ub != 0)) { + result = idx_ac.size(0); + } else if (idx_ac.size(0) != 0) { + result = idx_ac.size(0); + } else { + result = 0; + } + + empty_non_axis_sizes = (result == 0); + if (empty_non_axis_sizes || ((idx_ac.size(0) != 0) && (loop_ub != 0))) { + input_sizes_idx_1 = loop_ub; + } else { + input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || (idx_ac.size(0) != 0)) { + b_input_sizes_idx_1 = 1; + } else { + b_input_sizes_idx_1 = 0; + } + + if (empty_non_axis_sizes || (idx_ac.size(0) != 0)) { + sizes_idx_1 = 1; + } else { + sizes_idx_1 = 0; + } + + b_xnew.set_size(idx_ac.size(0), loop_ub); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = idx_ac.size(0); + for (i2 = 0; i2 < b_loop_ub; i2++) { + b_xnew[i2 + b_xnew.size(0) * i1] = xnew[(static_cast + (idx_ac[i2]) + xnew.size(0) * i1) - 1]; + } + } + + loop_ub = idx_ac.size(0); + c_X.set_size(idx_ac.size(0)); + b_X.set_size(idx_ac.size(0)); + for (i1 = 0; i1 < loop_ub; i1++) { + tmp_size = static_cast(idx_ac[i1]) - 1; + c_X[i1] = log_PR_xnew[tmp_size]; + b_X[i1] = log_L_xnew[tmp_size]; + } + + for (i1 = 0; i1 < input_sizes_idx_1; i1++) { + for (i2 = 0; i2 < result; i2++) { + X[(static_cast(idx_ac[i2]) + X.size(0) * i1) - 1] = b_xnew[i2 + + result * i1]; + } + } + + loop_ub = b_input_sizes_idx_1; + for (i1 = 0; i1 < loop_ub; i1++) { + for (i2 = 0; i2 < result; i2++) { + X[(static_cast(idx_ac[i2]) + X.size(0) * input_sizes_idx_1) - + 1] = c_X[i2]; + } + } + + loop_ub = sizes_idx_1; + for (i1 = 0; i1 < loop_ub; i1++) { + for (i2 = 0; i2 < result; i2++) { + X[(static_cast(idx_ac[i2]) + X.size(0) * (input_sizes_idx_1 + + b_input_sizes_idx_1)) - 1] = b_X[i2]; + } + } + + loop_ub = idx_ac.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + tmp_size = static_cast(idx_ac[i1]) - 1; + fx[tmp_size] = fx_new[tmp_size]; + } + + // Check whether to add the current points to the chains or not? + if (coder::b_mod(static_cast(t) + 2.0, 1.0) == 0.0) { + // Store the current sample in chain + iloc++; + loop_ub = X.size(0); + b_xnew.set_size(X.size(1), X.size(0)); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = X.size(1); + for (i2 = 0; i2 < b_loop_ub; i2++) { + b_xnew[i2 + b_xnew.size(0) * i1] = X[i1 + X.size(0) * i2]; + } + } + + tmp_size = static_cast(DREAMPar.d + 2.0); + loop_ub = static_cast(DREAMPar.N); + for (i1 = 0; i1 < loop_ub; i1++) { + for (i2 = 0; i2 < tmp_size; i2++) { + chain[((static_cast(iloc) + chain.size(0) * i2) + + chain.size(0) * chain.size(1) * i1) - 1] = b_xnew[i2 + + tmp_size * i1]; + } + } + + // kf added 16/10/2015 + // store the distance between the simualted and observed signatures + // Store the model simulations (if appropriate) + // storeDREAMResults(DREAMPar,fx,Meas_info,'a+'); + } + + // Check whether we update the crossover values + if (DREAMPar.adaptPCR) { + // Calculate the standard deviation of each dimension of X + if (DREAMPar.N < 1.0) { + loop_ub = 0; + } else { + loop_ub = static_cast(DREAMPar.N); + } + + if (DREAMPar.d < 1.0) { + b_loop_ub = 0; + } else { + b_loop_ub = static_cast(DREAMPar.d); + } + + b_xnew.set_size(loop_ub, b_loop_ub); + for (i1 = 0; i1 < b_loop_ub; i1++) { + for (i2 = 0; i2 < loop_ub; i2++) { + b_xnew[i2 + b_xnew.size(0) * i1] = X[i2 + X.size(0) * i1]; + } + } + + coder::b_std(b_xnew, r); + coder::repmat(r, DREAMPar.N, b_r); + + // Compute the Euclidean distance between new X and old X + if (xold.size(0) < 1) { + loop_ub = 0; + } else { + loop_ub = xold.size(0); + } + + if (DREAMPar.d < 1.0) { + b_loop_ub = 0; + } else { + b_loop_ub = static_cast(DREAMPar.d); + } + + if (X.size(0) < 1) { + i1 = 0; + } else { + i1 = X.size(0); + } + + if (DREAMPar.d < 1.0) { + i2 = 0; + } else { + i2 = static_cast(DREAMPar.d); + } + + if (loop_ub == 1) { + tmp_size = i1; + } else { + tmp_size = loop_ub; + } + + if (b_loop_ub == 1) { + result = i2; + } else { + result = b_loop_ub; + } + + if ((loop_ub == i1) && (b_loop_ub == i2) && (tmp_size == b_r.size(0)) && + (result == b_r.size(1))) { + x.set_size(loop_ub, b_loop_ub); + for (i1 = 0; i1 < b_loop_ub; i1++) { + for (i2 = 0; i2 < loop_ub; i2++) { + varargin_1 = (xold[i2 + xold.size(0) * i1] - X[i2 + X.size(0) * i1]) + / b_r[i2 + b_r.size(0) * i1]; + x[i2 + x.size(0) * i1] = rt_powd_snf(varargin_1, 2.0); + } + } + } else { + binary_expand_op(x, xold, loop_ub - 1, b_loop_ub - 1, X, i1 - 1, i2 - + 1, b_r); + } + + // Use this information to update sum_p2 to update N_CR + if (DREAMPar.N < 1.0) { + loop_ub = 0; + } else { + loop_ub = static_cast(DREAMPar.N); + } + + coder::blockedSummation(x, x.size(1), b_X); + + // Calculate total normalized Euclidean distance for each crossover value + // Derive sum_p2 for each different CR value + for (int32_T j{0}; j < 3; j++) { + // Find which chains are updated with j/DREAMPar.nCR + // Add the normalized squared distance tot the current delta_tot; + varargin_1 = (static_cast(j) + 1.0) / 3.0; + for (i1 = 0; i1 < loop_ub; i1++) { + CR_data[i1] = (CR[i1 + CR.size(0) * gen] == varargin_1); + } + + b_CR_data.set(&CR_data[0], loop_ub); + coder::eml_find(b_CR_data, r2); + delta_normX.set_size(r2.size(0)); + b_loop_ub = r2.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + delta_normX[i1] = b_X[r2[i1] - 1]; + } + + delta_tot_data[j] += coder::sum(delta_normX); + } + } + + // Update gen + gen++; + + // How many candidate points have been accepted -- to calculate acceptance rate + totaccept += static_cast(coder::c_combineVectorElements(accept)); + + // Update log_L + if (DREAMPar.N < 1.0) { + loop_ub = 0; + } else { + loop_ub = static_cast(DREAMPar.N); + } + + varargin_1 = (static_cast(t) + 2.0) * DREAMPar.N; + log_L[t + 1] = varargin_1; + for (i1 = 0; i1 < loop_ub; i1++) { + log_L[(t + log_L.size(0) * (i1 + 1)) + 1] = X[i1 + X.size(0) * ( + static_cast(DREAMPar.d + 2.0) - 1)]; + } + + // Update the waitbar. TJP Edit to check for graphical enviro + // waitbar(t/DREAMPar.T,h); + textProgressBar((static_cast(t) + 2.0) / DREAMPar.T); + + // If t equal to MCMC.steps then convergence checks and updates + if (coder::b_mod(static_cast(t) + 2.0, DREAMPar.steps) == 0.0) { + int32_T start_idx; + + // Save some important output -- Acceptance Rate + output->AR.data[iteration] = varargin_1; + output->AR.data[iteration + output->AR.size[0]] = 100.0 * totaccept / + (DREAMPar.N * DREAMPar.steps); + + // Check whether to update individual pCR values + if (static_cast(t) + 2.0 <= DREAMPar.T / 10.0) { + if (DREAMPar.adaptPCR) { + real_T b_lCR_data[3]; + + // Update pCR values + for (i1 = 0; i1 < 3; i1++) { + b_lCR_data[i1] = lCR_data[i1]; + } + + adaptPCR(&DREAMPar, CR, delta_tot_data, b_lCR_data, pCR_data, + pCR_size, lCR_data, lCR_size); + } + } else { + // See whether there are any outlier chains, and remove them to current best value of X + if (DREAMPar.N + 1.0 < 2.0) { + i1 = 0; + i2 = 0; + } else { + i1 = 1; + i2 = static_cast(DREAMPar.N + 1.0); + } + + loop_ub = i2 - i1; + x.set_size(t + 2, loop_ub); + for (i2 = 0; i2 < loop_ub; i2++) { + for (result = 0; result <= t + 1; result++) { + x[result + x.size(0) * i2] = log_L[result + log_L.size(0) * (i1 + + i2)]; + } + } + + removeOutlier(X, x, output->outlier.data, output->outlier.size, + &DREAMPar, r1); + output->outlier.size[0] = r1.size(0); + output->outlier.size[1] = r1.size(1); + loop_ub = r1.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = r1.size(0); + for (i2 = 0; i2 < b_loop_ub; i2++) { + output->outlier.data[i2 + output->outlier.size[0] * i1] = r1[i2 + + r1.size(0) * i1]; + } + } + + i1 = !(DREAMPar.N + 1.0 < 2.0); + loop_ub = x.size(1); + for (i2 = 0; i2 < loop_ub; i2++) { + b_loop_ub = x.size(0); + for (result = 0; result < b_loop_ub; result++) { + log_L[result + log_L.size(0) * (i1 + i2)] = x[result + x.size(0) * + i2]; + } + } + } + + // Store diagnostic information -- Probability of individual crossover values + output->CR[iteration] = varargin_1; + output->CR[iteration + output->CR.size(0)] = pCR_data[0]; + output->CR[iteration + output->CR.size(0) * 2] = pCR_data[1]; + output->CR[iteration + output->CR.size(0) * 3] = pCR_data[2]; + + // Generate new crossover values + drawCR(&DREAMPar, pCR_data, pCR_size, CR); + + // Calculate Gelman and Rubin Convergence Diagnostic + start_idx = static_cast(std::fmax(1.0, std::floor + (static_cast(iloc) / 2.0))); + + // Compute the R-statistic using 50% burn-in from chain + if (start_idx > static_cast(iloc)) { + i1 = 0; + i2 = 0; + } else { + i1 = start_idx - 1; + i2 = static_cast(iloc); + } + + if (DREAMPar.d < 1.0) { + loop_ub = 0; + } else { + loop_ub = static_cast(DREAMPar.d); + } + + if (DREAMPar.N < 1.0) { + b_loop_ub = 0; + } else { + b_loop_ub = static_cast(DREAMPar.N); + } + + tmp_size = i2 - i1; + b_chain.set_size(tmp_size, loop_ub, b_loop_ub); + for (i2 = 0; i2 < b_loop_ub; i2++) { + for (result = 0; result < loop_ub; result++) { + for (input_sizes_idx_1 = 0; input_sizes_idx_1 < tmp_size; + input_sizes_idx_1++) { + b_chain[(input_sizes_idx_1 + b_chain.size(0) * result) + + b_chain.size(0) * b_chain.size(1) * i2] = chain[((i1 + + input_sizes_idx_1) + chain.size(0) * result) + chain.size(0) * + chain.size(1) * i2]; + } + } + } + + gelman(b_chain, &DREAMPar, r); + output->R_stat[iteration] = varargin_1; + loop_ub = r.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + output->R_stat[iteration + output->R_stat.size(0) * (i1 + 1)] = r[i1]; + } + + // Update the iteration, set gen back to 1 and totaccept to zero + iteration++; + gen = 0; + totaccept = 0.0; + + // Save the output or not? + // if DREAMPar.save + // + // % Store in memory + // save DREAM.mat + // end + } + } + + // ------------------------------------------------------------------------- + // Determine total run time + output->RunTime = coder::toc(); + + // Variables have been pre-allocated --> need to remove zeros at end + // [chain,output,fx] = DREAMEnd(DREAMPar,Meas_info,chain,output,iteration,iloc); + // Place everything in output to do diagnostics later (outside C++) + output->DREAMPar = DREAMPar; + output->Meas_info = Meas_info; + output->iteration = iteration + 1; + output->iloc = iloc; + + // Close the waitbar + printf("\n"); + fflush(stdout); + + // close(h); + } +} + +// End of code generation (ratDREAM.cpp) diff --git a/RAT/ratDREAM.h b/RAT/ratDREAM.h new file mode 100644 index 00000000..a723bc18 --- /dev/null +++ b/RAT/ratDREAM.h @@ -0,0 +1,46 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// ratDREAM.h +// +// Code generation for function 'ratDREAM' +// +#ifndef RATDREAM_H +#define RATDREAM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct cell_14; + struct struct2_T; + struct struct13_T; +} + +// Function Declarations +namespace RAT +{ + void ratDREAM(real_T dreamVariables_d, real_T dreamVariables_N, real_T + dreamVariables_T, real_T dreamVariables_lambda, real_T + dreamVariables_pUnitGamma, boolean_T dreamVariables_adaptPCR, + const ::coder::array &Par_info_min, const ::coder:: + array &Par_info_max, const char_T + Par_info_boundhandling_data[], const int32_T + Par_info_boundhandling_size[2], const struct5_T + *ratInputs_problemDef, const cell_14 *ratInputs_problemDefCells, + const struct2_T *ratInputs_controls, const ::coder::array &ratInputs_priors, ::coder::array &chain, + struct13_T *output, ::coder::array &fx); +} + +#endif + +// End of code generation (ratDREAM.h) diff --git a/RAT/rcond.cpp b/RAT/rcond.cpp new file mode 100644 index 00000000..b94d2d9d --- /dev/null +++ b/RAT/rcond.cpp @@ -0,0 +1,239 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rcond.cpp +// +// Code generation for function 'rcond' +// + +// Include files +#include "rcond.h" +#include "norm.h" +#include "rt_nonfinite.h" +#include "vAllOrAny.h" +#include "xgetrf.h" +#include "xtrsv.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + real_T rcond(const ::coder::array &A) + { + ::coder::array b_A; + ::coder::array x; + real_T result; + int32_T n; + n = A.size(0); + result = 0.0; + if (n == 0) { + result = rtInf; + } else if (n == 1) { + real_T temp; + temp = std::abs(A[0]); + if (!std::isinf(temp)) { + if (std::isnan(temp)) { + result = rtNaN; + } else if (temp != 0.0) { + result = 1.0; + } + } + } else { + real_T normA; + normA = b_norm(A); + if (!(normA == 0.0)) { + int32_T i; + int32_T jlast; + int32_T jump; + int32_T kase; + b_A.set_size(A.size(0), A.size(1)); + kase = A.size(1); + for (i = 0; i < kase; i++) { + jump = A.size(0); + for (jlast = 0; jlast < jump; jlast++) { + b_A[jlast + b_A.size(0) * i] = A[jlast + A.size(0) * i]; + } + } + + internal::lapack::xgetrf(n, n, b_A, n); + kase = n; + int32_T exitg1; + do { + exitg1 = 0; + if (kase > 0) { + if (b_A[(kase + b_A.size(0) * (kase - 1)) - 1] == 0.0) { + exitg1 = 1; + } else { + kase--; + } + } else { + real_T ainvnm; + int32_T iter; + int32_T j; + ainvnm = 0.0; + iter = 2; + kase = 1; + jump = 1; + j = 0; + x.set_size(n); + for (i = 0; i < n; i++) { + x[i] = 1.0 / static_cast(n); + } + + while (kase != 0) { + if (kase == 1) { + internal::blas::xtrsv(n, b_A, n, x); + internal::blas::b_xtrsv(n, b_A, n, x); + } else { + internal::blas::c_xtrsv(n, b_A, n, x); + internal::blas::d_xtrsv(n, b_A, n, x); + } + + if (jump == 1) { + ainvnm = b_norm(x); + if ((!std::isinf(ainvnm)) && (!std::isnan(ainvnm))) { + i = x.size(0); + for (kase = 0; kase < i; kase++) { + real_T temp; + temp = std::abs(x[kase]); + if (temp > 2.2250738585072014E-308) { + x[kase] = x[kase] / temp; + } else { + x[kase] = 1.0; + } + } + + kase = 2; + jump = 2; + } else { + kase = 0; + } + } else if (jump == 2) { + real_T temp; + j = 0; + temp = std::abs(x[0]); + i = x.size(0); + for (kase = 0; kase <= i - 2; kase++) { + real_T absrexk; + absrexk = std::abs(x[kase + 1]); + if (!(absrexk <= temp)) { + j = kase + 1; + temp = absrexk; + } + } + + iter = 2; + kase = x.size(0); + x.set_size(kase); + for (i = 0; i < kase; i++) { + x[i] = 0.0; + } + + x[j] = 1.0; + kase = 1; + jump = 3; + } else if (jump == 3) { + ainvnm = b_norm(x); + if (ainvnm <= x[0]) { + real_T temp; + temp = 1.0; + i = x.size(0); + for (kase = 0; kase < i; kase++) { + x[kase] = temp * (((static_cast(kase) + 1.0) - 1.0) + / (static_cast(x.size(0)) - 1.0) + + 1.0); + temp = -temp; + } + + kase = 1; + jump = 5; + } else { + i = x.size(0); + for (kase = 0; kase < i; kase++) { + real_T temp; + temp = std::abs(x[kase]); + if (temp > 2.2250738585072014E-308) { + x[kase] = x[kase] / temp; + } else { + x[kase] = 1.0; + } + } + + kase = 2; + jump = 4; + } + } else if (jump == 4) { + real_T temp; + jlast = j; + j = 0; + temp = std::abs(x[0]); + i = x.size(0); + for (kase = 0; kase <= i - 2; kase++) { + real_T absrexk; + absrexk = std::abs(x[kase + 1]); + if (!(absrexk <= temp)) { + j = kase + 1; + temp = absrexk; + } + } + + if ((std::abs(x[jlast]) != std::abs(x[j])) && (iter <= 5)) { + iter++; + kase = x.size(0); + x.set_size(kase); + for (i = 0; i < kase; i++) { + x[i] = 0.0; + } + + x[j] = 1.0; + kase = 1; + jump = 3; + } else { + temp = 1.0; + i = x.size(0); + for (kase = 0; kase < i; kase++) { + x[kase] = temp * (((static_cast(kase) + 1.0) - 1.0) + / (static_cast(x.size(0)) - 1.0) + + 1.0); + temp = -temp; + } + + kase = 1; + jump = 5; + } + } else if (jump == 5) { + real_T temp; + temp = 2.0 * b_norm(x) / 3.0 / static_cast(n); + if (temp > ainvnm) { + ainvnm = temp; + } + + kase = 0; + } + } + + if (ainvnm != 0.0) { + result = 1.0 / ainvnm / normA; + } + + if (std::isnan(result) && (!internal::vAllOrAny(b_A))) { + result = 0.0; + } + + exitg1 = 1; + } + } while (exitg1 == 0); + } + } + + return result; + } + } +} + +// End of code generation (rcond.cpp) diff --git a/RAT/rcond.h b/RAT/rcond.h new file mode 100644 index 00000000..a127abdf --- /dev/null +++ b/RAT/rcond.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rcond.h +// +// Code generation for function 'rcond' +// +#ifndef RCOND_H +#define RCOND_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + real_T rcond(const ::coder::array &A); + } +} + +#endif + +// End of code generation (rcond.h) diff --git a/RAT/rdivide_helper.cpp b/RAT/rdivide_helper.cpp new file mode 100644 index 00000000..9777623b --- /dev/null +++ b/RAT/rdivide_helper.cpp @@ -0,0 +1,47 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rdivide_helper.cpp +// +// Code generation for function 'rdivide_helper' +// + +// Include files +#include "rdivide_helper.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 1U> &in2, const ::coder::array &in3) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); + } + + in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); + } + + for (i = 0; i < loop_ub; i++) { + in1[i] = static_cast(in2[i * stride_0_0] == in3[i * stride_1_0]); + } + } +} + +// End of code generation (rdivide_helper.cpp) diff --git a/RAT/rdivide_helper.h b/RAT/rdivide_helper.h new file mode 100644 index 00000000..ee8a45d3 --- /dev/null +++ b/RAT/rdivide_helper.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rdivide_helper.h +// +// Code generation for function 'rdivide_helper' +// +#ifndef RDIVIDE_HELPER_H +#define RDIVIDE_HELPER_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 1U> &in2, const ::coder::array &in3); +} + +#endif + +// End of code generation (rdivide_helper.h) diff --git a/RAT/refPrctileConfInts.cpp b/RAT/refPrctileConfInts.cpp new file mode 100644 index 00000000..84e65563 --- /dev/null +++ b/RAT/refPrctileConfInts.cpp @@ -0,0 +1,387 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// refPrctileConfInts.cpp +// +// Code generation for function 'refPrctileConfInts' +// + +// Include files +#include "refPrctileConfInts.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "interp1.h" +#include "makeCell.h" +#include "mean.h" +#include "prctile.h" +#include "rand.h" +#include "reflectivityCalculation.h" +#include "rt_nonfinite.h" +#include "strcmp.h" +#include "unpackParams.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include + +// Function Definitions +namespace RAT +{ + void refPrctileConfInts(const ::coder::array &bayesOutputs_chain, + struct5_T *problemDef, const cell_14 *problemDefCells, const struct2_T + *controlsStruct, f_struct_T *allPredInts) + { + ::coder::array r; + ::coder::array ref_yVals; + ::coder::array sld_yVals; + ::coder::array r1; + ::coder::array refArray; + ::coder::array rowVals; + ::coder::array sldArray; + ::coder::array vals; + ::coder::array b_calcResult; + ::coder::array c_calcResult; + cell_13 calcResult; + struct_T calcProblem; + real_T a[1000]; + real_T isample[1000]; + real_T thisCol_data[1000]; + real_T CI_65[2]; + real_T CI_95[2]; + int32_T b_loop_ub; + int32_T b_thisCol_size; + int32_T c_loop_ub; + int32_T i; + int32_T i1; + int32_T k; + int32_T loop_ub; + int32_T thisCol_size; + boolean_T domains; + + // Need to deal slightly differently with SLDs if there are domains + domains = coder::internal::b_strcmp(problemDef->TF.data, problemDef->TF.size); + + // Calc the ref and SLD for the first row of the chain. This 'sticks' the x + // values of each that we then interpolate the values from the rest of the + // cain onto.... + problemDef->fitParams.set_size(1, bayesOutputs_chain.size(1)); + loop_ub = bayesOutputs_chain.size(1); + for (i = 0; i < loop_ub; i++) { + problemDef->fitParams[problemDef->fitParams.size(0) * i] = + bayesOutputs_chain[bayesOutputs_chain.size(0) * i]; + } + + unpackParams(problemDef, controlsStruct->checks.fitParam, + controlsStruct->checks.fitBackgroundParam, + controlsStruct->checks.fitQzshift, + controlsStruct->checks.fitScalefactor, + controlsStruct->checks.fitBulkIn, + controlsStruct->checks.fitBulkOut, + controlsStruct->checks.fitResolutionParam, + controlsStruct->checks.fitDomainRatio); + + // Calc the reflectivities.... + reflectivityCalculation(problemDef, problemDefCells, controlsStruct, + &calcProblem, &calcResult); + + // 'result' is currently a cell array. Convert this to a struct because it's + // easier to work with fieldnames... + // Reflectivity art points + // Reflectivity between sim limits + // Data corrected for sfs + // Layers if defined (i.e. not customXY) + // Calculated SLD profiles + // Resampled layers + // For compile, we can't remove a field, so just clear it for now... + // problem = rmfield(problem,'calculations'); + // so each is a {n x 1} cell array, because of n contrasts. + // Prepare some arrays to hold the SLD's and Refs for all the chain, keeping only the Y vales. + // We'll save x values in a separate array + vals.set_size(1, 3); + rowVals.set_size(1, 3); + vals[0] = 0.0; + rowVals[0] = 0.0; + vals[vals.size(0)] = 0.0; + rowVals[1] = 0.0; + vals[vals.size(0) * 2] = 0.0; + rowVals[2] = 0.0; + makeCell(problemDef->numberOfContrasts, (const real_T *)rowVals.data(), + allPredInts->refXdata); + + // cell(numberOfContrasts,1); + makeCell(problemDef->numberOfContrasts, (const real_T *)vals.data(), + ref_yVals); + + // cell(numberOfContrasts,1); + makeCell(problemDef->numberOfContrasts, (const real_T *)rowVals.data(), + allPredInts->sldXdata); + if (!domains) { + makeCell(problemDef->numberOfContrasts, (const real_T *)vals.data(), r); + sld_yVals.set_size(r.size(0), 1); + loop_ub = r.size(0); + for (i = 0; i < loop_ub; i++) { + sld_yVals[i] = r[i]; + } + } else { + b_makeCell(problemDef->numberOfContrasts, (const real_T *)vals.data(), r); + sld_yVals.set_size(r.size(0), 2); + loop_ub = r.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + sld_yVals[i1 + sld_yVals.size(0) * i] = r[i1 + r.size(0) * i]; + } + } + } + + // We need to have the yvals interpolated onto the same xvals when we + // calculate the sample. So, take the current reflectivity value from above + // to get the 'base' x for ref and SLD, then all following + // interpelations are onto these x values.... + i = static_cast(problemDef->numberOfContrasts); + for (int32_T b_i{0}; b_i < i; b_i++) { + loop_ub = calcResult.f1[b_i].f1.size(0); + allPredInts->refXdata[b_i].f1.set_size(1, calcResult.f1[b_i].f1.size(0)); + for (i1 = 0; i1 < loop_ub; i1++) { + allPredInts->refXdata[b_i].f1[i1] = calcResult.f1[b_i].f1[i1]; + } + + // Transpose these into rows for storage + if (!domains) { + loop_ub = calcResult.f5[b_i].f1.size(0); + allPredInts->sldXdata[b_i].f1.set_size(1, calcResult.f5[b_i].f1.size(0)); + for (i1 = 0; i1 < loop_ub; i1++) { + allPredInts->sldXdata[b_i].f1[i1] = calcResult.f5[b_i].f1[i1]; + } + } else { + loop_ub = calcResult.f5[b_i].f1.size(0); + for (int32_T m{0}; m < 2; m++) { + allPredInts->sldXdata[b_i].f1.set_size(1, loop_ub); + for (i1 = 0; i1 < loop_ub; i1++) { + allPredInts->sldXdata[b_i].f1[i1] = calcResult.f5[b_i].f1[i1]; + } + } + } + } + + // Loop over the whole chain, collecting the Sld's and Refs together into + // one array for each contrast. + // will be = nsimu + // To speed things up, we'll take a random sample of the chain, rather than + // calculating >20000 reflectivities... + coder::c_rand(a); + for (k = 0; k < 1000; k++) { + isample[k] = std::ceil(a[k] * static_cast(bayesOutputs_chain.size + (0))); + } + + // First, we populate the yVals arrays with zero arrays of the correct size... + for (int32_T b_i{0}; b_i < i; b_i++) { + ref_yVals[b_i].f1.set_size(1000, calcResult.f1[b_i].f1.size(0)); + loop_ub = calcResult.f1[b_i].f1.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + for (k = 0; k < 1000; k++) { + ref_yVals[b_i].f1[k + ref_yVals[b_i].f1.size(0) * i1] = 0.0; + } + } + + sld_yVals[b_i].f1.set_size(1000, calcResult.f5[b_i].f1.size(0)); + loop_ub = calcResult.f5[b_i].f1.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + for (k = 0; k < 1000; k++) { + sld_yVals[b_i].f1[k + sld_yVals[b_i].f1.size(0) * i1] = 0.0; + } + } + } + + // Calculate all the samples.... + loop_ub = bayesOutputs_chain.size(1); + for (int32_T b_i{0}; b_i < 1000; b_i++) { + problemDef->fitParams.set_size(1, bayesOutputs_chain.size(1)); + for (i1 = 0; i1 < loop_ub; i1++) { + problemDef->fitParams[problemDef->fitParams.size(0) * i1] = + bayesOutputs_chain[(static_cast(isample[b_i]) + + bayesOutputs_chain.size(0) * i1) - 1]; + } + + unpackParams(problemDef, controlsStruct->checks.fitParam, + controlsStruct->checks.fitBackgroundParam, + controlsStruct->checks.fitQzshift, + controlsStruct->checks.fitScalefactor, + controlsStruct->checks.fitBulkIn, + controlsStruct->checks.fitBulkOut, + controlsStruct->checks.fitResolutionParam, + controlsStruct->checks.fitDomainRatio); + + // Calc the reflectivities.... + reflectivityCalculation(problemDef, problemDefCells, controlsStruct, + &calcProblem, &calcResult); + + // 'result' is currently a cell array. Convert this to a struct because it's + // easier to work with fieldnames... + // Reflectivity art points + // Reflectivity between sim limits + // Data corrected for sfs + // Layers if defined (i.e. not customXY) + // Calculated SLD profiles + // Resampled layers + // For compile, we can't remove a field, so just clear it for now... + // problem = rmfield(problem,'calculations'); + allPredInts->sampleChi[b_i] = calcProblem.calculations.sumChi; + for (int32_T n{0}; n < i; n++) { + k = calcResult.f1[n].f1.size(0); + b_calcResult.set_size(calcResult.f1[n].f1.size(0)); + for (i1 = 0; i1 < k; i1++) { + b_calcResult[i1] = calcResult.f1[n].f1[i1]; + } + + k = calcResult.f1[n].f1.size(0); + c_calcResult.set_size(calcResult.f1[n].f1.size(0)); + for (i1 = 0; i1 < k; i1++) { + c_calcResult[i1] = calcResult.f1[n].f1[i1 + calcResult.f1[n].f1.size(0)]; + } + + coder::interp1(b_calcResult, c_calcResult, allPredInts->refXdata[n].f1, + r1); + k = r1.size(1); + for (i1 = 0; i1 < k; i1++) { + ref_yVals[n].f1[b_i + ref_yVals[n].f1.size(0) * i1] = r1[i1]; + } + + // Automatically comes back as a row from inpterp1 + if (!domains) { + k = calcResult.f5[n].f1.size(0); + b_calcResult.set_size(calcResult.f5[n].f1.size(0)); + for (i1 = 0; i1 < k; i1++) { + b_calcResult[i1] = calcResult.f5[n].f1[i1]; + } + + k = calcResult.f5[n].f1.size(0); + c_calcResult.set_size(calcResult.f5[n].f1.size(0)); + for (i1 = 0; i1 < k; i1++) { + c_calcResult[i1] = calcResult.f5[n].f1[i1 + calcResult.f5[n].f1.size + (0)]; + } + + coder::b_interp1(b_calcResult, c_calcResult, allPredInts->sldXdata[n]. + f1, r1); + k = r1.size(1); + for (i1 = 0; i1 < k; i1++) { + sld_yVals[n].f1[b_i + sld_yVals[n].f1.size(0) * i1] = r1[i1]; + } + } else { + int32_T d_loop_ub; + k = calcResult.f5[n].f1.size(0); + d_loop_ub = calcResult.f5[n].f1.size(0); + for (int32_T m{0}; m < 2; m++) { + int32_T e_loop_ub; + b_calcResult.set_size(k); + for (i1 = 0; i1 < k; i1++) { + b_calcResult[i1] = calcResult.f5[n].f1[i1]; + } + + c_calcResult.set_size(d_loop_ub); + for (i1 = 0; i1 < d_loop_ub; i1++) { + c_calcResult[i1] = calcResult.f5[n].f1[i1 + calcResult.f5[n]. + f1.size(0)]; + } + + coder::b_interp1(b_calcResult, c_calcResult, allPredInts->sldXdata[n] + .f1, r1); + e_loop_ub = r1.size(1); + for (i1 = 0; i1 < e_loop_ub; i1++) { + sld_yVals[n].f1[b_i + sld_yVals[n].f1.size(0) * i1] = r1[i1]; + } + } + } + } + } + + // Calculate the percentiles across all the calculated samples for each + // point in x... We calculate 95% and 65% CI's for each set of curves + allPredInts->refPredInts.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + refArray.set_size(5, ref_yVals[b_i].f1.size(1)); + loop_ub = ref_yVals[b_i].f1.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + for (k = 0; k < 5; k++) { + refArray[k + 5 * i1] = 0.0; + } + } + + // We could possibly use CIFn in one shot here (rather than loop over + // points....) + i1 = ref_yVals[b_i].f1.size(1); + if (ref_yVals[b_i].f1.size(1) - 1 >= 0) { + thisCol_size = ref_yVals[b_i].f1.size(0); + b_loop_ub = ref_yVals[b_i].f1.size(0); + } + + for (int32_T points{0}; points < i1; points++) { + for (k = 0; k < b_loop_ub; k++) { + thisCol_data[k] = ref_yVals[b_i].f1[k + ref_yVals[b_i].f1.size(0) * + points]; + } + + coder::prctile(thisCol_data, thisCol_size, CI_95); + coder::b_prctile(thisCol_data, thisCol_size, CI_65); + refArray[5 * points] = CI_95[0]; + refArray[5 * points + 1] = CI_65[0]; + refArray[5 * points + 2] = coder::mean(thisCol_data, thisCol_size); + refArray[5 * points + 3] = CI_65[1]; + refArray[5 * points + 4] = CI_95[1]; + } + + allPredInts->refPredInts[b_i].f1.set_size(5, refArray.size(1)); + loop_ub = refArray.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + for (k = 0; k < 5; k++) { + allPredInts->refPredInts[b_i].f1[k + 5 * i1] = refArray[k + 5 * i1]; + } + } + } + + // TODO: need to add domains here.... + allPredInts->sldPredInts.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + sldArray.set_size(5, sld_yVals[b_i].f1.size(1)); + loop_ub = sld_yVals[b_i].f1.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + for (k = 0; k < 5; k++) { + sldArray[k + 5 * i1] = 0.0; + } + } + + i1 = sld_yVals[b_i].f1.size(1); + if (sld_yVals[b_i].f1.size(1) - 1 >= 0) { + b_thisCol_size = sld_yVals[b_i].f1.size(0); + c_loop_ub = sld_yVals[b_i].f1.size(0); + } + + for (int32_T points{0}; points < i1; points++) { + for (k = 0; k < c_loop_ub; k++) { + thisCol_data[k] = sld_yVals[b_i].f1[k + sld_yVals[b_i].f1.size(0) * + points]; + } + + coder::prctile(thisCol_data, b_thisCol_size, CI_95); + coder::b_prctile(thisCol_data, b_thisCol_size, CI_65); + sldArray[5 * points] = CI_95[0]; + sldArray[5 * points + 1] = CI_65[0]; + sldArray[5 * points + 2] = coder::mean(thisCol_data, b_thisCol_size); + sldArray[5 * points + 3] = CI_65[1]; + sldArray[5 * points + 4] = CI_95[1]; + } + + allPredInts->sldPredInts[b_i].f1.set_size(5, sldArray.size(1)); + loop_ub = sldArray.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + for (k = 0; k < 5; k++) { + allPredInts->sldPredInts[b_i].f1[k + 5 * i1] = sldArray[k + 5 * i1]; + } + } + } + } +} + +// End of code generation (refPrctileConfInts.cpp) diff --git a/RAT/refPrctileConfInts.h b/RAT/refPrctileConfInts.h new file mode 100644 index 00000000..899d3701 --- /dev/null +++ b/RAT/refPrctileConfInts.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// refPrctileConfInts.h +// +// Code generation for function 'refPrctileConfInts' +// +#ifndef REFPRCTILECONFINTS_H +#define REFPRCTILECONFINTS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct cell_14; + struct struct2_T; + struct f_struct_T; +} + +// Function Declarations +namespace RAT +{ + void refPrctileConfInts(const ::coder::array &bayesOutputs_chain, + struct5_T *problemDef, const cell_14 *problemDefCells, const struct2_T + *controlsStruct, f_struct_T *allPredInts); +} + +#endif + +// End of code generation (refPrctileConfInts.h) diff --git a/RAT/reflectivityCalculation.cpp b/RAT/reflectivityCalculation.cpp index d30e904b..77a17eae 100644 --- a/RAT/reflectivityCalculation.cpp +++ b/RAT/reflectivityCalculation.cpp @@ -10,19 +10,19 @@ // Include files #include "reflectivityCalculation.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "reflectivityCalculation1.h" +#include "reflectivityCalculation2.h" #include "rt_nonfinite.h" -#include "standardTFReflectivityCalculation.h" #include "strcmp.h" -#include "triggerEvent.h" #include "coder_array.h" #include "coder_bounded_array.h" // Type Definitions namespace RAT { - struct cell_wrap_12 + struct cell_wrap_19 { ::coder::array f1; }; @@ -31,178 +31,79 @@ namespace RAT // Function Declarations namespace RAT { - static void cast(const cell_8 *r, cell_19 *r1); - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 2U> &r1); - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 1U> &r1); - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 2U> &r1); - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 2U> &r1); - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_12, 1U> &r1); - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_12, 1U> &r1); - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_13, 1U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_21, 1U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_19, 1U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_19, 1U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_20, 1U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_21, 2U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_36, 2U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_20, 2U> &r1); } // Function Definitions namespace RAT { - static void cast(const cell_8 *r, cell_19 *r1) - { - int32_T loop_ub; - r1->f1.set_size(1, r->f1.size(1)); - loop_ub = r->f1.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f1[i] = r->f1[i]; - } - - cast(r->f2, r1->f2); - r1->f3.set_size(1, r->f3.size(1)); - loop_ub = r->f3.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f3[i] = r->f3[i]; - } - - cast(r->f4, r1->f4); - cast(r->f5, r1->f5); - cast(r->f6, r1->f6); - r1->f7.set_size(1, r->f7.size(1)); - loop_ub = r->f7.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f7[i] = r->f7[i]; - } - - r1->f8.set_size(1, r->f8.size(1)); - loop_ub = r->f8.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f8[i] = r->f8[i]; - } - - r1->f9.set_size(1, r->f9.size(1)); - loop_ub = r->f9.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f9[i] = r->f9[i]; - } - - r1->f10.set_size(1, r->f10.size(1)); - loop_ub = r->f10.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f10[i] = r->f10[i]; - } - - r1->f11.set_size(1, r->f11.size(1)); - loop_ub = r->f11.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f11[i] = r->f11[i]; - } - - r1->f12.set_size(1, r->f12.size(1)); - loop_ub = r->f12.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f12[i] = r->f12[i]; - } - - r1->f13.set_size(1, r->f13.size(1)); - loop_ub = r->f13.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f13[i] = r->f13[i]; - } - - r1->f14.set_size(1, r->f14.size(1)); - loop_ub = r->f14.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f14[i] = r->f14[i]; - } - - r1->f15.set_size(1, r->f15.size(1)); - loop_ub = r->f15.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f15[i] = r->f15[i]; - } - - r1->f16.set_size(1, r->f16.size(1)); - loop_ub = r->f16.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f16[i] = r->f16[i]; - } - - cast(r->f17, r1->f17); - r1->f18.set_size(1, r->f18.size(1)); - loop_ub = r->f18.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f18[i] = r->f18[i]; - } - - cast(r->f19, r1->f19); - r1->f20.set_size(1, r->f20.size(1)); - loop_ub = r->f20.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - r1->f20[i] = r->f20[i]; - } - } - - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 2U> &r1) + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_21, 1U> &r1) { int32_T i; - r1.set_size(1, r.size(1)); - i = r.size(1) - 1; - for (int32_T i1{0}; i1 <= i; i1++) { + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { int32_T loop_ub; - loop_ub = r[i1].f1.size[1]; - r1[r1.size(0) * i1].f1.set_size(r[r.size(0) * i1].f1.size[0], r[r.size(0) * - i1].f1.size[1]); + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); for (int32_T i2{0}; i2 < loop_ub; i2++) { int32_T b_loop_ub; - b_loop_ub = r[i1].f1.size[0]; + b_loop_ub = r[i1].f1.size(0); for (int32_T i3{0}; i3 < b_loop_ub; i3++) { - r1[i1].f1[r1[i1].f1.size(0) * i2] = r[i1].f1.data[r[i1].f1.size[0] * - i2]; + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; } } } } - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 1U> &r1) + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_19, 1U> &r1) { int32_T i; r1.set_size(r.size(0)); i = r.size(0); for (int32_T i1{0}; i1 < i; i1++) { int32_T loop_ub; - loop_ub = r[i1].f1.size[1]; - r1[i1].f1.set_size(r[i1].f1.size[0], r[i1].f1.size[1]); + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); for (int32_T i2{0}; i2 < loop_ub; i2++) { int32_T b_loop_ub; - b_loop_ub = r[i1].f1.size[0]; + b_loop_ub = r[i1].f1.size(0); for (int32_T i3{0}; i3 < b_loop_ub; i3++) { - r1[i1].f1[r1[i1].f1.size(0) * i2] = r[i1].f1.data[r[i1].f1.size[0] * - i2]; + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; } } } } - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 2U> &r1) + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_19, 1U> &r1) { int32_T i; - r1.set_size(1, r.size(1)); - i = r.size(1) - 1; - for (int32_T i1{0}; i1 <= i; i1++) { + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { int32_T loop_ub; - loop_ub = r[i1].f1.size(1); - r1[r1.size(0) * i1].f1.set_size(r[r.size(0) * i1].f1.size(0), r[r.size(0) * - i1].f1.size(1)); - for (int32_T i2{0}; i2 < loop_ub; i2++) { - int32_T b_loop_ub; - b_loop_ub = r[i1].f1.size(0); - for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + loop_ub = r[i1].f1.size(0); + r1[i1].f1.set_size(r[i1].f1.size(0), 2); + for (int32_T i2{0}; i2 < 2; i2++) { + for (int32_T i3{0}; i3 < loop_ub; i3++) { r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) * i2]; } @@ -210,39 +111,41 @@ namespace RAT } } - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_15, 2U> &r1) + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_20, 1U> &r1) { int32_T i; - r1.set_size(1, r.size(1)); - i = r.size(1) - 1; - for (int32_T i1{0}; i1 <= i; i1++) { + r1.set_size(r.size(0)); + i = r.size(0); + for (int32_T i1{0}; i1 < i; i1++) { int32_T loop_ub; loop_ub = r[i1].f1.size(1); - r1[r1.size(0) * i1].f1.set_size(r[r.size(0) * i1].f1.size(0), r[r.size(0) * - i1].f1.size(1)); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); for (int32_T i2{0}; i2 < loop_ub; i2++) { int32_T b_loop_ub; b_loop_ub = r[i1].f1.size(0); for (int32_T i3{0}; i3 < b_loop_ub; i3++) { - r1[i1].f1[r1[i1].f1.size(0) * i2] = r[i1].f1[r[i1].f1.size(0) * i2]; + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) + * i2]; } } } } - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_12, 1U> &r1) + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_21, 2U> &r1) { int32_T i; - r1.set_size(r.size(0)); - i = r.size(0); + r1.set_size(r.size(0), r.size(1)); + i = r.size(0) * r.size(1); for (int32_T i1{0}; i1 < i; i1++) { int32_T loop_ub; - loop_ub = r[i1].f1.size(0); - r1[i1].f1.set_size(r[i1].f1.size(0), 2); - for (int32_T i2{0}; i2 < 2; i2++) { - for (int32_T i3{0}; i3 < loop_ub; i3++) { + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(r[i1].f1.size(0), r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + int32_T b_loop_ub; + b_loop_ub = r[i1].f1.size(0); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) * i2]; } @@ -250,12 +153,12 @@ namespace RAT } } - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_12, 1U> &r1) + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_36, 2U> &r1) { int32_T i; - r1.set_size(r.size(0)); - i = r.size(0); + r1.set_size(r.size(0), r.size(1)); + i = r.size(0) * r.size(1); for (int32_T i1{0}; i1 < i; i1++) { int32_T loop_ub; loop_ub = r[i1].f1.size(1); @@ -271,12 +174,12 @@ namespace RAT } } - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_13, 1U> &r1) + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_20, 2U> &r1) { int32_T i; - r1.set_size(r.size(0)); - i = r.size(0); + r1.set_size(r.size(0), r.size(1)); + i = r.size(0) * r.size(1); for (int32_T i1{0}; i1 < i; i1++) { int32_T loop_ub; loop_ub = r[i1].f1.size(1); @@ -292,25 +195,38 @@ namespace RAT } } - void reflectivityCalculation(const struct0_T *problemDef, const cell_8 - *problemDefCells, const struct1_T *, const struct2_T *controls, struct4_T - *problem, cell_11 *result) + void reflectivityCalculation(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, struct_T *problem, cell_13 + *result) { - ::coder::array Simulation; - ::coder::array reflectivity; - ::coder::array sldProfiles; - ::coder::array allLayers; - ::coder::array layerSlds; - ::coder::array shifted_data; - ::coder::array b_allLayers; - ::coder::array b_layerSlds; - ::coder::array b_shifted_data; - ::coder::array b_sldProfiles; - ::coder::array b_Simulation; - ::coder::array b_reflectivity; - cell_19 r; + ::coder::array b_reflectivity; + ::coder::array b_simulation; + ::coder::array reflectivity; + ::coder::array simulation; + ::coder::array sldProfiles; + ::coder::array domainAllLayers; + ::coder::array r2; + ::coder::array allLayers; + ::coder::array shiftedData; + ::coder::array domainLayerSlds; + ::coder::array r; + ::coder::array layerSlds; + ::coder::array domainSldProfiles; + ::coder::array r1; + ::coder::array b_domainAllLayers; + ::coder::array b_domainLayerSlds; + ::coder::array b_domainSldProfiles; + ::coder::array cell4; + ::coder::array cell5; + ::coder::array cell6; + ::coder::array b_allLayers; + ::coder::array b_layerSlds; + ::coder::array b_shiftedData; + ::coder::array b_sldProfiles; + int32_T b_index; int32_T i; int32_T i1; + int32_T loop_ub; // Main entry point into the reflectivity calculation for the toolbox. // This is the main function that is called by any of the minimisers or @@ -333,21 +249,21 @@ namespace RAT // Setting these parameters in the struct defines them as doubles problem->ssubs.set_size(1); problem->ssubs[0] = 0.0; - problem->backgrounds.set_size(1); - problem->backgrounds[0] = 0.0; - problem->qshifts.set_size(1); - problem->qshifts[0] = 0.0; + problem->backgroundParams.set_size(1); + problem->backgroundParams[0] = 0.0; + problem->qzshifts.set_size(1); + problem->qzshifts[0] = 0.0; problem->scalefactors.set_size(1); problem->scalefactors[0] = 0.0; - problem->nbairs.set_size(1); - problem->nbairs[0] = 0.0; - problem->nbsubs.set_size(1); - problem->nbsubs[0] = 0.0; - problem->resolutions.set_size(1); - problem->resolutions[0] = 0.0; - problem->calculations.all_chis.set_size(1); - problem->calculations.all_chis[0] = 0.0; - problem->calculations.sum_chi = 0.0; + problem->bulkIn.set_size(1); + problem->bulkIn[0] = 0.0; + problem->bulkOut.set_size(1); + problem->bulkOut[0] = 0.0; + problem->resolutionParams.set_size(1); + problem->resolutionParams[0] = 0.0; + problem->calculations.allChis.set_size(1); + problem->calculations.allChis[0] = 0.0; + problem->calculations.sumChi = 0.0; problem->allSubRough.set_size(1); problem->allSubRough[0] = 0.0; problem->resample.set_size(1, 1); @@ -360,55 +276,90 @@ namespace RAT // TODO: Find out which is necessary and tidy this up. i = static_cast(problemDef->numberOfContrasts); reflectivity.set_size(i); - Simulation.set_size(i); - shifted_data.set_size(i); + simulation.set_size(i); + shiftedData.set_size(i); layerSlds.set_size(i); + domainLayerSlds.set_size(i, 2); sldProfiles.set_size(i); + domainSldProfiles.set_size(i, 2); allLayers.set_size(i); + domainAllLayers.set_size(i, 2); for (int32_T b_i{0}; b_i < i; b_i++) { reflectivity[b_i].f1.set_size(2, 2); reflectivity[b_i].f1[0] = 1.0; reflectivity[b_i].f1[1] = 1.0; reflectivity[b_i].f1[reflectivity[b_i].f1.size(0)] = 1.0; reflectivity[b_i].f1[reflectivity[b_i].f1.size(0) + 1] = 1.0; - Simulation[b_i].f1.set_size(2, 2); - Simulation[b_i].f1[0] = 1.0; - Simulation[b_i].f1[1] = 1.0; - Simulation[b_i].f1[Simulation[b_i].f1.size(0)] = 1.0; - Simulation[b_i].f1[Simulation[b_i].f1.size(0) + 1] = 1.0; - shifted_data[b_i].f1.set_size(2, 3); + simulation[b_i].f1.set_size(2, 2); + simulation[b_i].f1[0] = 1.0; + simulation[b_i].f1[1] = 1.0; + simulation[b_i].f1[simulation[b_i].f1.size(0)] = 1.0; + simulation[b_i].f1[simulation[b_i].f1.size(0) + 1] = 1.0; + shiftedData[b_i].f1.set_size(2, 3); layerSlds[b_i].f1.set_size(2, 3); + domainLayerSlds[b_i].f1.set_size(2, 3); + domainLayerSlds[b_i + domainLayerSlds.size(0)].f1.set_size(2, 3); sldProfiles[b_i].f1.set_size(2, 2); sldProfiles[b_i].f1[0] = 1.0; sldProfiles[b_i].f1[1] = 1.0; sldProfiles[b_i].f1[sldProfiles[b_i].f1.size(0)] = 1.0; sldProfiles[b_i].f1[sldProfiles[b_i].f1.size(0) + 1] = 1.0; + domainSldProfiles[b_i].f1.set_size(2, 2); + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.set_size(2, 2); + domainSldProfiles[b_i].f1[0] = 1.0; + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[0] = 1.0; + domainSldProfiles[b_i].f1[1] = 1.0; + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[1] = 1.0; + domainSldProfiles[b_i].f1[domainSldProfiles[b_i].f1.size(0)] = 1.0; + domainSldProfiles[b_i + domainSldProfiles.size(0)] + .f1[domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0)] = 1.0; + domainSldProfiles[b_i].f1[domainSldProfiles[b_i].f1.size(0) + 1] = 1.0; + domainSldProfiles[b_i + domainSldProfiles.size(0)] + .f1[domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) + 1] = + 1.0; allLayers[b_i].f1.set_size(2, 3); + domainAllLayers[b_i].f1.set_size(2, 3); + domainAllLayers[b_i + domainAllLayers.size(0)].f1.set_size(2, 3); for (i1 = 0; i1 < 3; i1++) { - shifted_data[b_i].f1[shifted_data[b_i].f1.size(0) * i1] = 1.0; - shifted_data[b_i].f1[shifted_data[b_i].f1.size(0) * i1 + 1] = 1.0; + shiftedData[b_i].f1[shiftedData[b_i].f1.size(0) * i1] = 1.0; + shiftedData[b_i].f1[shiftedData[b_i].f1.size(0) * i1 + 1] = 1.0; layerSlds[b_i].f1[layerSlds[b_i].f1.size(0) * i1] = 1.0; layerSlds[b_i].f1[layerSlds[b_i].f1.size(0) * i1 + 1] = 1.0; + domainLayerSlds[b_i].f1[domainLayerSlds[b_i].f1.size(0) * i1] = 1.0; + domainLayerSlds[b_i + domainLayerSlds.size(0)].f1[domainLayerSlds[b_i + + domainLayerSlds.size(0)].f1.size(0) * i1] = 1.0; + domainLayerSlds[b_i].f1[domainLayerSlds[b_i].f1.size(0) * i1 + 1] = 1.0; + domainLayerSlds[b_i + domainLayerSlds.size(0)].f1[domainLayerSlds[b_i + + domainLayerSlds.size(0)].f1.size(0) * i1 + 1] = 1.0; allLayers[b_i].f1[allLayers[b_i].f1.size(0) * i1] = 1.0; allLayers[b_i].f1[allLayers[b_i].f1.size(0) * i1 + 1] = 1.0; + domainAllLayers[b_i].f1[domainAllLayers[b_i].f1.size(0) * i1] = 1.0; + domainAllLayers[b_i + domainAllLayers.size(0)].f1[domainAllLayers[b_i + + domainAllLayers.size(0)].f1.size(0) * i1] = 1.0; + domainAllLayers[b_i].f1[domainAllLayers[b_i].f1.size(0) * i1 + 1] = 1.0; + domainAllLayers[b_i + domainAllLayers.size(0)].f1[domainAllLayers[b_i + + domainAllLayers.size(0)].f1.size(0) * i1 + 1] = 1.0; } } // Decide which target function we are calling and call the relevant routines - if (coder::internal::b_strcmp(problemDef->TF.data, problemDef->TF.size)) { - i1 = 0; + if (coder::internal::i_strcmp(problemDef->TF.data, problemDef->TF.size)) { + b_index = 0; + } else if (coder::internal::j_strcmp(problemDef->TF.data, + problemDef->TF.size)) { + b_index = 1; } else { - i1 = -1; + b_index = -1; } - if (i1 == 0) { - cast(problemDefCells, &r); - standardTFReflectivityCalculation(problemDef, &r, controls, problem, - b_reflectivity, b_Simulation, b_shifted_data, b_layerSlds, b_sldProfiles, - b_allLayers); + switch (b_index) { + case 0: + nonPolarisedTF::b_reflectivityCalculation(problemDef, problemDefCells, + controls, problem, b_reflectivity, b_simulation, b_shiftedData, + b_layerSlds, b_sldProfiles, b_allLayers); cast(b_reflectivity, reflectivity); - cast(b_Simulation, Simulation); - cast(b_shifted_data, shifted_data); + cast(b_simulation, simulation); + cast(b_shiftedData, shiftedData); cast(b_layerSlds, layerSlds); cast(b_sldProfiles, sldProfiles); cast(b_allLayers, allLayers); @@ -417,86 +368,265 @@ namespace RAT // problem = oilWaterTF_reflectivityCalculation(problemDef,problemDefCells,controls); // case 'magnetic' // problem = polarisedTF_reflectivityCalculation(problemDef,problemDefCells,controls); - // case 'domains' - // [problem,reflectivity,Simulation,shifted_data,layerSlds,sldProfiles,allLayers] = domainsTF_reflectivityCalculation(problemDef,problemDefCells,problemDefLimits,controls); - // otherwise - // error('The calculation type "%s" is not supported', whichTF); + break; + + case 1: + domainsTF::b_reflectivityCalculation(problemDef, problemDefCells, controls, + problem, b_reflectivity, b_simulation, b_shiftedData, b_domainLayerSlds, + b_domainSldProfiles, b_domainAllLayers); + cast(b_reflectivity, reflectivity); + cast(b_simulation, simulation); + cast(b_shiftedData, shiftedData); + cast(b_domainLayerSlds, r); + domainLayerSlds.set_size(r.size(0), r.size(1)); + b_index = r.size(1); + for (i1 = 0; i1 < b_index; i1++) { + loop_ub = r.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + domainLayerSlds[i2 + domainLayerSlds.size(0) * i1] = r[i2 + r.size(0) * + i1]; + } + } + + cast(b_domainSldProfiles, r1); + domainSldProfiles.set_size(r1.size(0), r1.size(1)); + b_index = r1.size(1); + for (i1 = 0; i1 < b_index; i1++) { + loop_ub = r1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + domainSldProfiles[i2 + domainSldProfiles.size(0) * i1] = r1[i2 + + r1.size(0) * i1]; + } + } + + cast(b_domainAllLayers, r2); + domainAllLayers.set_size(r2.size(0), r2.size(1)); + b_index = r2.size(1); + for (i1 = 0; i1 < b_index; i1++) { + loop_ub = r2.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + domainAllLayers[i2 + domainAllLayers.size(0) * i1] = r2[i2 + r2.size(0) + * i1]; + } + } + + // otherwise + // error('The calculation type "%s" is not supported', whichTF); + break; } result->f1.set_size(i); result->f2.set_size(i); result->f3.set_size(i); - result->f4.set_size(i); - result->f5.set_size(i); - result->f6.set_size(i); for (int32_T b_i{0}; b_i < i; b_i++) { - int32_T b_loop_ub; - int32_T loop_ub; - loop_ub = reflectivity[b_i].f1.size(0); + b_index = reflectivity[b_i].f1.size(0); result->f1[b_i].f1.set_size(reflectivity[b_i].f1.size(0), 2); - b_loop_ub = Simulation[b_i].f1.size(0); - result->f2[b_i].f1.set_size(Simulation[b_i].f1.size(0), 2); + loop_ub = simulation[b_i].f1.size(0); + result->f2[b_i].f1.set_size(simulation[b_i].f1.size(0), 2); for (i1 = 0; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { + for (int32_T i2{0}; i2 < b_index; i2++) { result->f1[b_i].f1[i2 + result->f1[b_i].f1.size(0) * i1] = reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1]; } - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { result->f2[b_i].f1[i2 + result->f2[b_i].f1.size(0) * i1] = - Simulation[b_i].f1[i2 + Simulation[b_i].f1.size(0) * i1]; + simulation[b_i].f1[i2 + simulation[b_i].f1.size(0) * i1]; } } - loop_ub = shifted_data[b_i].f1.size(0); - result->f3[b_i].f1.set_size(shifted_data[b_i].f1.size(0), 3); - b_loop_ub = layerSlds[b_i].f1.size(0); - result->f4[b_i].f1.set_size(layerSlds[b_i].f1.size(0), 3); + b_index = shiftedData[b_i].f1.size(0); + result->f3[b_i].f1.set_size(shiftedData[b_i].f1.size(0), 3); for (i1 = 0; i1 < 3; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { + for (int32_T i2{0}; i2 < b_index; i2++) { result->f3[b_i].f1[i2 + result->f3[b_i].f1.size(0) * i1] = - shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1]; + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1]; + } + } + } + + // The size of this array now varies depending on TF + if (coder::internal::j_strcmp(problemDef->TF.data, problemDef->TF.size)) { + i1 = 0; + } else { + i1 = -1; + } + + if (i1 == 0) { + cell4.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + b_index = domainLayerSlds[b_i].f1.size(1); + cell4[b_i].f1.set_size(domainLayerSlds[b_i].f1.size(0), + domainLayerSlds[b_i].f1.size(1)); + for (i1 = 0; i1 < b_index; i1++) { + loop_ub = domainLayerSlds[b_i].f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + cell4[b_i].f1[i2 + cell4[b_i].f1.size(0) * i1] = domainLayerSlds[b_i] + .f1[i2 + domainLayerSlds[b_i].f1.size(0) * i1]; + } } - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - result->f4[b_i].f1[i2 + result->f4[b_i].f1.size(0) * i1] = - layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1]; + b_index = domainLayerSlds[b_i + domainLayerSlds.size(0)].f1.size(1); + cell4[b_i + cell4.size(0)].f1.set_size(domainLayerSlds[b_i + + domainLayerSlds.size(0)].f1.size(0), domainLayerSlds[b_i + + domainLayerSlds.size(0)].f1.size(1)); + for (i1 = 0; i1 < b_index; i1++) { + loop_ub = domainLayerSlds[b_i + domainLayerSlds.size(0)].f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + cell4[b_i + cell4.size(0)].f1[i2 + cell4[b_i + cell4.size(0)]. + f1.size(0) * i1] = domainLayerSlds[b_i + domainLayerSlds.size(0)]. + f1[i2 + domainLayerSlds[b_i + domainLayerSlds.size(0)].f1.size(0) * + i1]; + } } } - loop_ub = sldProfiles[b_i].f1.size(0); - result->f5[b_i].f1.set_size(sldProfiles[b_i].f1.size(0), 2); + result->f4.set_size(cell4.size(0), 2); + b_index = cell4.size(0); for (i1 = 0; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - result->f5[b_i].f1[i2 + result->f5[b_i].f1.size(0) * i1] = - sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1]; + for (int32_T i2{0}; i2 < b_index; i2++) { + result->f4[i2 + result->f4.size(0) * i1] = cell4[i2 + cell4.size(0) * + i1]; } } - loop_ub = allLayers[b_i].f1.size(0); - result->f6[b_i].f1.set_size(allLayers[b_i].f1.size(0), 3); - for (i1 = 0; i1 < 3; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - result->f6[b_i].f1[i2 + result->f6[b_i].f1.size(0) * i1] = - allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1]; + cell5.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + b_index = domainSldProfiles[b_i].f1.size(1); + cell5[b_i].f1.set_size(domainSldProfiles[b_i].f1.size(0), + domainSldProfiles[b_i].f1.size(1)); + for (i1 = 0; i1 < b_index; i1++) { + loop_ub = domainSldProfiles[b_i].f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + cell5[b_i].f1[i2 + cell5[b_i].f1.size(0) * i1] = + domainSldProfiles[b_i].f1[i2 + domainSldProfiles[b_i].f1.size(0) * + i1]; + } + } + + b_index = domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(1); + cell5[b_i + cell5.size(0)].f1.set_size(domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(0), domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(1)); + for (i1 = 0; i1 < b_index; i1++) { + loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + cell5[b_i + cell5.size(0)].f1[i2 + cell5[b_i + cell5.size(0)]. + f1.size(0) * i1] = domainSldProfiles[b_i + domainSldProfiles.size + (0)].f1[i2 + domainSldProfiles[b_i + domainSldProfiles.size(0)]. + f1.size(0) * i1]; + } + } + } + + result->f5.set_size(cell5.size(0), 2); + b_index = cell5.size(0); + for (i1 = 0; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < b_index; i2++) { + result->f5[i2 + result->f5.size(0) * i1] = cell5[i2 + cell5.size(0) * + i1]; } } - } - // Send plot event - triggerEvent(result->f1, result->f3, result->f5, result->f6, problem->ssubs, - problemDef->resample, problemDef->dataPresent, - problemDef->modelType.data, problemDef->modelType.size); + cell6.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + b_index = domainAllLayers[b_i].f1.size(0); + cell6[b_i].f1.set_size(domainAllLayers[b_i].f1.size(0), 3); + loop_ub = domainAllLayers[b_i + domainAllLayers.size(0)].f1.size(0); + cell6[b_i + cell6.size(0)].f1.set_size(domainAllLayers[b_i + + domainAllLayers.size(0)].f1.size(0), 3); + for (i1 = 0; i1 < 3; i1++) { + for (int32_T i2{0}; i2 < b_index; i2++) { + cell6[b_i].f1[i2 + cell6[b_i].f1.size(0) * i1] = domainAllLayers[b_i] + .f1[i2 + domainAllLayers[b_i].f1.size(0) * i1]; + } + + for (int32_T i2{0}; i2 < loop_ub; i2++) { + cell6[b_i + cell6.size(0)].f1[i2 + cell6[b_i + cell6.size(0)]. + f1.size(0) * i1] = domainAllLayers[b_i + domainAllLayers.size(0)]. + f1[i2 + domainAllLayers[b_i + domainAllLayers.size(0)].f1.size(0) * + i1]; + } + } + } + + result->f6.set_size(cell6.size(0), 2); + b_index = cell6.size(0); + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < b_index; i1++) { + result->f6[i1 + result->f6.size(0) * i] = cell6[i1 + cell6.size(0) * i]; + } + } + } else { + cell4.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + b_index = layerSlds[b_i].f1.size(1); + cell4[b_i].f1.set_size(layerSlds[b_i].f1.size(0), layerSlds[b_i].f1.size + (1)); + for (i1 = 0; i1 < b_index; i1++) { + loop_ub = layerSlds[b_i].f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + cell4[b_i].f1[i2 + cell4[b_i].f1.size(0) * i1] = layerSlds[b_i] + .f1[i2 + layerSlds[b_i].f1.size(0) * i1]; + } + } + } + + result->f4.set_size(cell4.size(0), 1); + b_index = cell4.size(0); + for (i1 = 0; i1 < b_index; i1++) { + result->f4[i1] = cell4[i1]; + } + + cell5.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + b_index = sldProfiles[b_i].f1.size(0); + cell5[b_i].f1.set_size(sldProfiles[b_i].f1.size(0), 2); + for (i1 = 0; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < b_index; i2++) { + cell5[b_i].f1[i2 + cell5[b_i].f1.size(0) * i1] = sldProfiles[b_i] + .f1[i2 + sldProfiles[b_i].f1.size(0) * i1]; + } + } + } + + result->f5.set_size(cell5.size(0), 1); + b_index = cell5.size(0); + for (i1 = 0; i1 < b_index; i1++) { + result->f5[i1] = cell5[i1]; + } + + cell6.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + b_index = allLayers[b_i].f1.size(0); + cell6[b_i].f1.set_size(allLayers[b_i].f1.size(0), 3); + for (i1 = 0; i1 < 3; i1++) { + for (int32_T i2{0}; i2 < b_index; i2++) { + cell6[b_i].f1[i2 + cell6[b_i].f1.size(0) * i1] = allLayers[b_i] + .f1[i2 + allLayers[b_i].f1.size(0) * i1]; + } + } + } + + result->f6.set_size(cell6.size(0), 1); + b_index = cell6.size(0); + for (i = 0; i < b_index; i++) { + result->f6[i] = cell6[i]; + } + } // Pre-processor directives for Matlab Coder // to define the size of the output array // Result coder definitions.... // Reflectivity - // Simulatin + // simulation // Shifted data - // Layers slds - // Sld profiles - // All layers (resampled) + // coder.varsize('result{4}',[Inf 2],[1 1]); %Layers slds + // coder.varsize('result{4}{:}',[Inf 6],[1 1]); + // coder.varsize('result{5}',[Inf 2],[1 1]); %Sld profiles + // coder.varsize('results{5}{:}',[Inf 2],[1 2]); + // coder.varsize('result{6}',[Inf 2],[1 1]); %All layers (resampled) + // coder.varsize('result{6}{:}',[Inf 3],[1 0]); } } diff --git a/RAT/reflectivityCalculation.h b/RAT/reflectivityCalculation.h index f18bc96f..70b75e0c 100644 --- a/RAT/reflectivityCalculation.h +++ b/RAT/reflectivityCalculation.h @@ -11,17 +11,26 @@ #define REFLECTIVITYCALCULATION_H // Include files -#include "reflectivityCalculation_types.h" #include "rtwtypes.h" #include #include +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct cell_14; + struct struct2_T; + struct struct_T; + struct cell_13; +} + // Function Declarations namespace RAT { - extern void reflectivityCalculation(const struct0_T *problemDef, const cell_8 * - problemDefCells, const struct1_T *problemDefLimits, const struct2_T - *controls, struct4_T *problem, cell_11 *result); + void reflectivityCalculation(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, struct_T *problem, cell_13 + *result); } #endif diff --git a/RAT/reflectivityCalculation1.cpp b/RAT/reflectivityCalculation1.cpp new file mode 100644 index 00000000..d937733b --- /dev/null +++ b/RAT/reflectivityCalculation1.cpp @@ -0,0 +1,153 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation1.cpp +// +// Code generation for function 'reflectivityCalculation1' +// + +// Include files +#include "reflectivityCalculation1.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "calculate.h" +#include "calculate1.h" +#include "calculate2.h" +#include "lower.h" +#include "rt_nonfinite.h" +#include "strcmp.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + void b_reflectivityCalculation(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array + &simulation, ::coder::array &shiftedData, ::coder::array< + cell_wrap_8, 1U> &layerSlds, ::coder::array &sldProfiles, + ::coder::array &allLayers) + { + int32_T switch_expression_size[2]; + int32_T loop_ub_tmp; + char_T switch_expression_data[10000]; + + // Main function for the nonPolarisedTF reflectivity calculation + // This function decides what type of model is being analysed and barnches + // to the correct one. The main options are: + // layers - This is the equivalent of Standard Layers in RasCAL + // Custom Layers - This is also a layers calculation, but the + // specification of the layers is dne using a user defined + // function. + // Custom XY - This also has a model described by a user supplied + // function, but in this case the function generates an + // SLD profile (i.e. XY function) rather than a list of + // layers. + // Find out the model type from the input structs + // Pre-allocate the output arrays.. this is necessary because otherwise + // the compiler complains with 'Output argument <....> is not assigned on + // some execution paths' error. + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgroundParams.set_size(loop_ub_tmp); + problem->qzshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->bulkIn.set_size(loop_ub_tmp); + problem->bulkOut.set_size(loop_ub_tmp); + problem->resolutionParams.set_size(loop_ub_tmp); + problem->calculations.allChis.set_size(loop_ub_tmp); + problem->calculations.sumChi = 0.0; + problem->allSubRough.set_size(loop_ub_tmp); + problem->resample.set_size(1, loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + simulation.set_size(loop_ub_tmp); + shiftedData.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + sldProfiles.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgroundParams[i] = 0.0; + problem->qzshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->bulkIn[i] = 0.0; + problem->bulkOut[i] = 0.0; + problem->resolutionParams[i] = 0.0; + problem->calculations.allChis[i] = 0.0; + problem->allSubRough[i] = 0.0; + problem->resample[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + simulation[i].f1.set_size(2, 2); + simulation[i].f1[0] = 1.0; + simulation[i].f1[1] = 1.0; + simulation[i].f1[simulation[i].f1.size(0)] = 1.0; + simulation[i].f1[simulation[i].f1.size(0) + 1] = 1.0; + shiftedData[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + sldProfiles[i].f1.set_size(2, 2); + sldProfiles[i].f1[0] = 1.0; + sldProfiles[i].f1[1] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; + sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; + allLayers[i].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i] = 1.0; + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; + } + } + + coder::lower(problemDef->modelType.data, problemDef->modelType.size, + switch_expression_data, switch_expression_size); + if (coder::internal::k_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 0; + } else if (coder::internal::l_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 1; + } else if (coder::internal::m_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + // Standard layers calculation + standardLayers::calculate(problemDef, problemDefCells, controls, problem, + reflectivity, simulation, shiftedData, layerSlds, sldProfiles, + allLayers); + break; + + case 1: + // Custom layers with user supplied custom model file + customLayers::calculate(problemDef, problemDefCells, controls, problem, + reflectivity, simulation, shiftedData, layerSlds, sldProfiles, + allLayers); + break; + + case 2: + // Custom SLD profile with user defined model file + customXY::calculate(problemDef, problemDefCells, controls, problem, + reflectivity, simulation, shiftedData, layerSlds, + sldProfiles, allLayers); + break; + } + } + } +} + +// End of code generation (reflectivityCalculation1.cpp) diff --git a/RAT/reflectivityCalculation1.h b/RAT/reflectivityCalculation1.h new file mode 100644 index 00000000..5c2b8a53 --- /dev/null +++ b/RAT/reflectivityCalculation1.h @@ -0,0 +1,43 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation1.h +// +// Code generation for function 'reflectivityCalculation1' +// +#ifndef REFLECTIVITYCALCULATION1_H +#define REFLECTIVITYCALCULATION1_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; + struct struct_T; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + void b_reflectivityCalculation(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array + &simulation, ::coder::array &shiftedData, ::coder::array< + cell_wrap_8, 1U> &layerSlds, ::coder::array &sldProfiles, + ::coder::array &allLayers); + } +} + +#endif + +// End of code generation (reflectivityCalculation1.h) diff --git a/RAT/reflectivityCalculation2.cpp b/RAT/reflectivityCalculation2.cpp new file mode 100644 index 00000000..73d615a4 --- /dev/null +++ b/RAT/reflectivityCalculation2.cpp @@ -0,0 +1,229 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation2.cpp +// +// Code generation for function 'reflectivityCalculation2' +// + +// Include files +#include "reflectivityCalculation2.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "calculate3.h" +#include "calculate4.h" +#include "calculate5.h" +#include "lower.h" +#include "rt_nonfinite.h" +#include "strcmp.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + void b_reflectivityCalculation(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array + &simulation, ::coder::array &shiftedData, ::coder::array< + cell_wrap_8, 2U> &layerSlds, ::coder::array + &domainSldProfiles, ::coder::array &allLayers) + { + ::coder::array b_domainSldProfiles; + ::coder::array b_layerSlds; + ::coder::array r; + int32_T switch_expression_size[2]; + int32_T loop_ub_tmp; + char_T switch_expression_data[10000]; + + // Main function for the domainsTF reflectivity calculation + // This function decides what type of model is being analysed and barnches + // to the correct one. The main options are: + // layers - This is the equivalent of Standard Layers in RasCAL + // Custom Layers - This is also a layers calculation, but the + // specification of the layers is dne using a user defined + // function. + // Custom XY - This also has a model described by a user supplied + // function, but in this case the function generates an + // SLD profile (i.e. XY function) rather than a list of + // layers. + // Find out the model type from the input structs + // Pre-allocate the output arrays.. this is necessary because otherwise + // the compiler complains with 'Output argument <....> is not assigned on + // some execution paths' error. + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + problem->ssubs.set_size(loop_ub_tmp); + problem->backgroundParams.set_size(loop_ub_tmp); + problem->qzshifts.set_size(loop_ub_tmp); + problem->scalefactors.set_size(loop_ub_tmp); + problem->bulkIn.set_size(loop_ub_tmp); + problem->bulkOut.set_size(loop_ub_tmp); + problem->resolutionParams.set_size(loop_ub_tmp); + problem->calculations.allChis.set_size(loop_ub_tmp); + problem->calculations.sumChi = 0.0; + problem->allSubRough.set_size(loop_ub_tmp); + problem->resample.set_size(1, loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + simulation.set_size(loop_ub_tmp); + shiftedData.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp, 2); + domainSldProfiles.set_size(loop_ub_tmp, 2); + allLayers.set_size(loop_ub_tmp, 2); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + problem->ssubs[i] = 0.0; + problem->backgroundParams[i] = 0.0; + problem->qzshifts[i] = 0.0; + problem->scalefactors[i] = 0.0; + problem->bulkIn[i] = 0.0; + problem->bulkOut[i] = 0.0; + problem->resolutionParams[i] = 0.0; + problem->calculations.allChis[i] = 0.0; + problem->allSubRough[i] = 0.0; + problem->resample[i] = 0.0; + reflectivity[i].f1.set_size(2, 2); + reflectivity[i].f1[0] = 1.0; + reflectivity[i].f1[1] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; + reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; + simulation[i].f1.set_size(2, 2); + simulation[i].f1[0] = 1.0; + simulation[i].f1[1] = 1.0; + simulation[i].f1[simulation[i].f1.size(0)] = 1.0; + simulation[i].f1[simulation[i].f1.size(0) + 1] = 1.0; + shiftedData[i].f1.set_size(2, 3); + layerSlds[i].f1.set_size(2, 3); + layerSlds[i + layerSlds.size(0)].f1.set_size(2, 3); + domainSldProfiles[i].f1.set_size(2, 2); + domainSldProfiles[i + domainSldProfiles.size(0)].f1.set_size(2, 2); + domainSldProfiles[i].f1[0] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)].f1[0] = 1.0; + domainSldProfiles[i].f1[1] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)].f1[1] = 1.0; + domainSldProfiles[i].f1[domainSldProfiles[i].f1.size(0)] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)].f1[domainSldProfiles[i + + domainSldProfiles.size(0)].f1.size(0)] = 1.0; + domainSldProfiles[i].f1[domainSldProfiles[i].f1.size(0) + 1] = 1.0; + domainSldProfiles[i + domainSldProfiles.size(0)].f1[domainSldProfiles[i + + domainSldProfiles.size(0)].f1.size(0) + 1] = 1.0; + allLayers[i].f1.set_size(2, 3); + allLayers[i + allLayers.size(0)].f1.set_size(2, 3); + for (int32_T b_i{0}; b_i < 3; b_i++) { + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i] = 1.0; + shiftedData[i].f1[shiftedData[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; + layerSlds[i + layerSlds.size(0)].f1[layerSlds[i + layerSlds.size(0)]. + f1.size(0) * b_i] = 1.0; + layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; + layerSlds[i + layerSlds.size(0)].f1[layerSlds[i + layerSlds.size(0)]. + f1.size(0) * b_i + 1] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; + allLayers[i + allLayers.size(0)].f1[allLayers[i + allLayers.size(0)]. + f1.size(0) * b_i] = 1.0; + allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; + allLayers[i + allLayers.size(0)].f1[allLayers[i + allLayers.size(0)]. + f1.size(0) * b_i + 1] = 1.0; + } + } + + coder::lower(problemDef->modelType.data, problemDef->modelType.size, + switch_expression_data, switch_expression_size); + if (coder::internal::k_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 0; + } else if (coder::internal::l_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 1; + } else if (coder::internal::m_strcmp(switch_expression_data, + switch_expression_size)) { + loop_ub_tmp = 2; + } else { + loop_ub_tmp = -1; + } + + switch (loop_ub_tmp) { + case 0: + // Standard layers calculation + standardLayers::calculate(problemDef, problemDefCells, controls, problem, + reflectivity, simulation, shiftedData, layerSlds, domainSldProfiles, + allLayers); + break; + + case 1: + { + int32_T loop_ub; + + // Custom layers with user supplied custom model file + customLayers::calculate(problemDef, problemDefCells, controls, problem, + reflectivity, simulation, shiftedData, b_layerSlds, + b_domainSldProfiles, r); + layerSlds.set_size(b_layerSlds.size(0), 2); + domainSldProfiles.set_size(b_domainSldProfiles.size(0), 2); + loop_ub_tmp = b_layerSlds.size(0); + loop_ub = b_domainSldProfiles.size(0); + for (int32_T b_i{0}; b_i < 2; b_i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + layerSlds[i1 + layerSlds.size(0) * b_i] = b_layerSlds[i1 + + b_layerSlds.size(0) * b_i]; + } + + for (int32_T i1{0}; i1 < loop_ub; i1++) { + domainSldProfiles[i1 + domainSldProfiles.size(0) * b_i] = + b_domainSldProfiles[i1 + b_domainSldProfiles.size(0) * b_i]; + } + } + + allLayers.set_size(r.size(0), r.size(1)); + loop_ub_tmp = r.size(1); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + loop_ub = r.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + allLayers[i1 + allLayers.size(0) * b_i] = r[i1 + r.size(0) * b_i]; + } + } + } + break; + + case 2: + { + int32_T loop_ub; + + // Custom SLD profile with user defined model file + customXY::calculate(problemDef, problemDefCells, controls, problem, + reflectivity, simulation, shiftedData, b_layerSlds, + b_domainSldProfiles, r); + layerSlds.set_size(b_layerSlds.size(0), 2); + domainSldProfiles.set_size(b_domainSldProfiles.size(0), 2); + loop_ub_tmp = b_layerSlds.size(0); + loop_ub = b_domainSldProfiles.size(0); + for (int32_T b_i{0}; b_i < 2; b_i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + layerSlds[i1 + layerSlds.size(0) * b_i] = b_layerSlds[i1 + + b_layerSlds.size(0) * b_i]; + } + + for (int32_T i1{0}; i1 < loop_ub; i1++) { + domainSldProfiles[i1 + domainSldProfiles.size(0) * b_i] = + b_domainSldProfiles[i1 + b_domainSldProfiles.size(0) * b_i]; + } + } + + allLayers.set_size(r.size(0), r.size(1)); + loop_ub_tmp = r.size(1); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + loop_ub = r.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + allLayers[i1 + allLayers.size(0) * b_i] = r[i1 + r.size(0) * b_i]; + } + } + } + break; + } + } + } +} + +// End of code generation (reflectivityCalculation2.cpp) diff --git a/RAT/reflectivityCalculation2.h b/RAT/reflectivityCalculation2.h new file mode 100644 index 00000000..1024a1b8 --- /dev/null +++ b/RAT/reflectivityCalculation2.h @@ -0,0 +1,43 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reflectivityCalculation2.h +// +// Code generation for function 'reflectivityCalculation2' +// +#ifndef REFLECTIVITYCALCULATION2_H +#define REFLECTIVITYCALCULATION2_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; + struct struct_T; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + void b_reflectivityCalculation(const struct5_T *problemDef, const cell_14 + *problemDefCells, const struct2_T *controls, struct_T *problem, ::coder:: + array &reflectivity, ::coder::array + &simulation, ::coder::array &shiftedData, ::coder::array< + cell_wrap_8, 2U> &layerSlds, ::coder::array + &domainSldProfiles, ::coder::array &allLayers); + } +} + +#endif + +// End of code generation (reflectivityCalculation2.h) diff --git a/RAT/reflectivityCalculation_data.cpp b/RAT/reflectivityCalculation_data.cpp deleted file mode 100644 index 7c7a3b9e..00000000 --- a/RAT/reflectivityCalculation_data.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// reflectivityCalculation_data.cpp -// -// Code generation for function 'reflectivityCalculation_data' -// - -// Include files -#include "reflectivityCalculation_data.h" -#include "rt_nonfinite.h" - -// Variable Definitions -namespace RAT -{ - omp_nest_lock_t reflectivityCalculation_nestLockGlobal; - const char_T cv[128]{ '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', - '\x07', '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f', - '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', - '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', ' ', '!', '\"', '#', - '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', - '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', - 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', - 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\\', ']', '^', '_', - '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', - '~', '\x7f' }; -} - -// End of code generation (reflectivityCalculation_data.cpp) diff --git a/RAT/reflectivityCalculation_data.h b/RAT/reflectivityCalculation_data.h deleted file mode 100644 index 3866071f..00000000 --- a/RAT/reflectivityCalculation_data.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// reflectivityCalculation_data.h -// -// Code generation for function 'reflectivityCalculation_data' -// -#ifndef REFLECTIVITYCALCULATION_DATA_H -#define REFLECTIVITYCALCULATION_DATA_H - -// Include files -#include "rtwtypes.h" -#include "omp.h" -#include -#include - -// Variable Declarations -namespace RAT -{ - extern omp_nest_lock_t reflectivityCalculation_nestLockGlobal; - extern const char_T cv[128]; -} - -#endif - -// End of code generation (reflectivityCalculation_data.h) diff --git a/RAT/reflectivityCalculation_initialize.cpp b/RAT/reflectivityCalculation_initialize.cpp deleted file mode 100644 index 60d0d597..00000000 --- a/RAT/reflectivityCalculation_initialize.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// reflectivityCalculation_initialize.cpp -// -// Code generation for function 'reflectivityCalculation_initialize' -// - -// Include files -#include "reflectivityCalculation_initialize.h" -#include "reflectivityCalculation_data.h" -#include "rt_nonfinite.h" -#include "triggerEvent.h" -#include "omp.h" - -// Function Definitions -namespace RAT -{ - void reflectivityCalculation_initialize() - { - omp_init_nest_lock(&reflectivityCalculation_nestLockGlobal); - helper_not_empty_init(); - triggerEvent_init(); - } -} - -// End of code generation (reflectivityCalculation_initialize.cpp) diff --git a/RAT/reflectivityCalculation_internal_types.h b/RAT/reflectivityCalculation_internal_types.h deleted file mode 100644 index df95bd78..00000000 --- a/RAT/reflectivityCalculation_internal_types.h +++ /dev/null @@ -1,64 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// reflectivityCalculation_internal_types.h -// -// Code generation for function 'reflectivityCalculation' -// -#ifndef REFLECTIVITYCALCULATION_INTERNAL_TYPES_H -#define REFLECTIVITYCALCULATION_INTERNAL_TYPES_H - -// Include files -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include "coder_bounded_array.h" - -// Type Definitions -namespace RAT -{ - struct cell_wrap_15 - { - ::coder::array f1; - }; - - struct cell_19 - { - ::coder::array f1; - ::coder::array f2; - ::coder::array f3; - ::coder::array f4; - ::coder::array f5; - ::coder::array f6; - ::coder::array f7; - ::coder::array f8; - ::coder::array f9; - ::coder::array f10; - ::coder::array f11; - ::coder::array f12; - ::coder::array f13; - ::coder::array f14; - ::coder::array f15; - ::coder::array f16; - ::coder::array f17; - ::coder::array f18; - ::coder::array f19; - ::coder::array f20; - }; - - struct cell_wrap_20 - { - ::coder::bounded_array f1; - }; - - struct cell_24 - { - ::coder::array f1; - }; -} - -#endif - -// End of code generation (reflectivityCalculation_internal_types.h) diff --git a/RAT/reflectivityCalculation_rtwutil.cpp b/RAT/reflectivityCalculation_rtwutil.cpp deleted file mode 100644 index 800d352d..00000000 --- a/RAT/reflectivityCalculation_rtwutil.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// reflectivityCalculation_rtwutil.cpp -// -// Code generation for function 'reflectivityCalculation_rtwutil' -// - -// Include files -#include "reflectivityCalculation_rtwutil.h" -#include "rt_nonfinite.h" -#include - -// Function Definitions -namespace RAT -{ - real_T rt_hypotd_snf(real_T u0, real_T u1) - { - real_T a; - real_T b; - real_T y; - a = std::abs(u0); - b = std::abs(u1); - if (a < b) { - a /= b; - y = b * std::sqrt(a * a + 1.0); - } else if (a > b) { - b /= a; - y = a * std::sqrt(b * b + 1.0); - } else if (std::isnan(b)) { - y = rtNaN; - } else { - y = a * 1.4142135623730951; - } - - return y; - } -} - -// End of code generation (reflectivityCalculation_rtwutil.cpp) diff --git a/RAT/reflectivityCalculation_terminate.cpp b/RAT/reflectivityCalculation_terminate.cpp deleted file mode 100644 index 11f8c636..00000000 --- a/RAT/reflectivityCalculation_terminate.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// reflectivityCalculation_terminate.cpp -// -// Code generation for function 'reflectivityCalculation_terminate' -// - -// Include files -#include "reflectivityCalculation_terminate.h" -#include "reflectivityCalculation_data.h" -#include "rt_nonfinite.h" -#include "omp.h" - -// Function Definitions -namespace RAT -{ - void reflectivityCalculation_terminate() - { - omp_destroy_nest_lock(&reflectivityCalculation_nestLockGlobal); - } -} - -// End of code generation (reflectivityCalculation_terminate.cpp) diff --git a/RAT/reflectivityCalculation_types.h b/RAT/reflectivityCalculation_types.h deleted file mode 100644 index e75b6034..00000000 --- a/RAT/reflectivityCalculation_types.h +++ /dev/null @@ -1,220 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// reflectivityCalculation_types.h -// -// Code generation for function 'reflectivityCalculation' -// -#ifndef REFLECTIVITYCALCULATION_TYPES_H -#define REFLECTIVITYCALCULATION_TYPES_H - -// Include files -#include "rtwtypes.h" -#include "coder_array.h" -#include "coder_bounded_array.h" -#define MAX_THREADS omp_get_max_threads() - -// Type Definitions -namespace RAT -{ - struct cell_wrap_0 - { - real_T f1[2]; - }; - - struct struct0_T - { - ::coder::array contrastBacks; - ::coder::array contrastBacksType; - ::coder::bounded_array TF; - ::coder::array resample; - ::coder::array dataPresent; - ::coder::array oilChiDataPresent; - real_T numberOfContrasts; - ::coder::bounded_array geometry; - boolean_T useImaginary; - ::coder::array contrastShifts; - ::coder::array contrastScales; - ::coder::array contrastNbas; - ::coder::array contrastNbss; - ::coder::array contrastRes; - ::coder::array backs; - ::coder::array shifts; - ::coder::array sf; - ::coder::array nba; - ::coder::array nbs; - ::coder::array res; - ::coder::array params; - real_T numberOfLayers; - ::coder::bounded_array modelType; - ::coder::array contrastCustomFiles; - ::coder::array contrastDomainRatios; - ::coder::array domainRatio; - real_T numberOfDomainContrasts; - ::coder::array domainContrastCustomFiles; - ::coder::array fitpars; - ::coder::array otherpars; - ::coder::array fitconstr; - ::coder::array otherconstr; - }; - - struct cell_wrap_1 - { - ::coder::array f1; - }; - - struct cell_wrap_2 - { - ::coder::bounded_array f1; - }; - - struct cell_wrap_3 - { - ::coder::array f1; - }; - - struct cell_wrap_4 - { - ::coder::bounded_array f1; - }; - - struct cell_wrap_5 - { - ::coder::bounded_array f1; - }; - - struct cell_wrap_6 - { - ::coder::bounded_array f1; - }; - - struct cell_wrap_7 - { - cell_wrap_6 f1[3]; - }; - - struct cell_8 - { - ::coder::array f1; - ::coder::array f2; - ::coder::array f3; - ::coder::array f4; - ::coder::array f5; - ::coder::array f6; - ::coder::array f7; - ::coder::array f8; - ::coder::array f9; - ::coder::array f10; - ::coder::array f11; - ::coder::array f12; - ::coder::array f13; - ::coder::array f14; - ::coder::array f15; - ::coder::array f16; - ::coder::array f17; - ::coder::array f18; - ::coder::array f19; - ::coder::array f20; - }; - - struct struct1_T - { - ::coder::array params; - ::coder::array backs; - ::coder::array scales; - ::coder::array shifts; - ::coder::array nba; - ::coder::array nbs; - ::coder::array res; - ::coder::array domainRatio; - }; - - struct struct3_T - { - ::coder::array params_fitYesNo; - ::coder::array backs_fitYesNo; - ::coder::array shifts_fitYesNo; - ::coder::array scales_fitYesNo; - ::coder::array nbairs_fitYesNo; - ::coder::array nbsubs_fitYesNo; - ::coder::array resol_fitYesNo; - ::coder::array domainRatio_fitYesNo; - }; - - struct struct2_T - { - ::coder::bounded_array para; - ::coder::bounded_array proc; - ::coder::bounded_array display; - real_T tolX; - real_T tolFun; - real_T maxFunEvals; - real_T maxIter; - real_T populationSize; - real_T fWeight; - real_T F_CR; - real_T VTR; - real_T numGen; - real_T strategy; - real_T Nlive; - real_T nmcmc; - real_T propScale; - real_T nsTolerance; - real_T calcSld; - real_T resamPars[2]; - real_T updateFreq; - real_T updatePlotFreq; - real_T nSamples; - real_T nChains; - real_T lambda; - real_T pUnitGamma; - ::coder::bounded_array boundHandling; - struct3_T checks; - }; - - struct struct5_T - { - ::coder::array all_chis; - real_T sum_chi; - }; - - struct struct4_T - { - ::coder::array ssubs; - ::coder::array backgrounds; - ::coder::array qshifts; - ::coder::array scalefactors; - ::coder::array nbairs; - ::coder::array nbsubs; - ::coder::array resolutions; - struct5_T calculations; - ::coder::array allSubRough; - ::coder::array resample; - }; - - struct cell_wrap_9 - { - ::coder::array f1; - }; - - struct cell_wrap_13 - { - ::coder::array f1; - }; - - struct cell_11 - { - ::coder::array f1; - ::coder::array f2; - ::coder::array f3; - ::coder::array f4; - ::coder::array f5; - ::coder::array f6; - }; -} - -#endif - -// End of code generation (reflectivityCalculation_types.h) diff --git a/RAT/relop.cpp b/RAT/relop.cpp index 02eb3396..66b9f412 100644 --- a/RAT/relop.cpp +++ b/RAT/relop.cpp @@ -34,6 +34,20 @@ namespace RAT return p; } + boolean_T c_relop(real_T a, real_T b) + { + boolean_T p; + if (std::isnan(b)) { + p = !std::isnan(a); + } else if (std::isnan(a)) { + p = false; + } else { + p = (a < b); + } + + return p; + } + boolean_T relop(real_T a, real_T b) { boolean_T p; diff --git a/RAT/relop.h b/RAT/relop.h index 53147759..f0a74ef6 100644 --- a/RAT/relop.h +++ b/RAT/relop.h @@ -23,6 +23,7 @@ namespace RAT namespace internal { boolean_T b_relop(real_T a, real_T b); + boolean_T c_relop(real_T a, real_T b); boolean_T relop(real_T a, real_T b); } } diff --git a/RAT/removeOutlier.cpp b/RAT/removeOutlier.cpp new file mode 100644 index 00000000..040b77c3 --- /dev/null +++ b/RAT/removeOutlier.cpp @@ -0,0 +1,261 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// removeOutlier.cpp +// +// Code generation for function 'removeOutlier' +// + +// Include files +#include "removeOutlier.h" +#include "RATMain_types.h" +#include "find.h" +#include "mean.h" +#include "nullAssignment.h" +#include "prctile.h" +#include "randperm.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void iqr(const ::coder::array &log_L, ::coder::array &idx_outlier); +} + +// Function Definitions +namespace RAT +{ + static void iqr(const ::coder::array &log_L, ::coder::array &idx_outlier) + { + ::coder::array r; + ::coder::array b_log_L; + real_T Q[2]; + real_T b_Q; + int32_T loop_ub; + + // Secondary functions used by this function + // ------------------------------------------------------------------------- + // ------------------- Interquartie range diagnostic ----------------------- + // ------------------------------------------------------------------------- + // Derive the upper and lower quantile of the data + coder::prctile(log_L, Q); + + // Derive the inter quartile range + // Are there any outlier chains ( 2 * IQR is liberal - normal is 1.5 * IQR) + b_Q = Q[1] - 2.0 * (Q[0] - Q[1]); + b_log_L.set_size(1, log_L.size(1)); + loop_ub = log_L.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_log_L[i] = (log_L[i] < b_Q); + } + + coder::d_eml_find(b_log_L, r); + idx_outlier.set_size(1, r.size(1)); + loop_ub = r.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + idx_outlier[i] = r[i]; + } + } + + void removeOutlier(::coder::array &X, ::coder::array + &log_L, const real_T outlier_data[], const int32_T + outlier_size[2], const struct14_T *DREAMPar, ::coder::array< + real_T, 2U> &outputOutlier) + { + ::coder::array b_chain_select; + ::coder::array b_log_L; + ::coder::array b_outputOutlier; + ::coder::array chain_id; + ::coder::array chain_select; + ::coder::array r; + ::coder::array c_log_L; + ::coder::array b_chain_id; + int32_T b_loop_ub; + int32_T chain_select_tmp; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T t_half; + + // Finds outlier chains and removes them when needed + // Determine the number of elements of L_density + t_half = static_cast(std::floor(static_cast(log_L.size(0)) / + 2.0)); + + // Then determine the mean log density of the active chains + if (t_half > log_L.size(0)) { + i = 0; + i1 = 0; + } else { + i = t_half - 1; + i1 = log_L.size(0); + } + + if (DREAMPar->N < 1.0) { + loop_ub = 0; + } else { + loop_ub = static_cast(DREAMPar->N); + } + + // ------------------------------ + // Always use the same outlier check (to remove eval) + // ---------------------------------- AVH + b_loop_ub = i1 - i; + b_log_L.set_size(b_loop_ub, loop_ub); + for (i1 = 0; i1 < loop_ub; i1++) { + for (chain_select_tmp = 0; chain_select_tmp < b_loop_ub; chain_select_tmp + ++) { + b_log_L[chain_select_tmp + b_log_L.size(0) * i1] = log_L[(i + + chain_select_tmp) + log_L.size(0) * i1]; + } + } + + coder::mean(b_log_L, chain_select); + iqr(chain_select, chain_id); + + // % Create outlier handle + // evalstr = strcat('chain_id=',DREAMPar.outlier,'(mean_log_L);'); + // + // % Now evaluate outlier handle + // try + // eval(evalstr); + // catch + // % Warning -- not enough chains to do sampling -- increase number of chains! + // fprintf('DREAM WARNING: Unknown outlier detection test at %d generations \n',t); + // % Now print warning to screen and to file + // %fprintf(evalstr); % fprintf(fid,evalstr); + // % No outlier detected + // outlier = []; + // return + // end + outputOutlier.set_size(outlier_size[0], 2); + loop_ub = outlier_size[0]; + for (i = 0; i < 2; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + outputOutlier[i1 + outputOutlier.size(0) * i] = outlier_data[i1 + + outlier_size[0] * i]; + } + } + + // How many outliers? + // If at least one outlier chain has been found --> reset its state + if (chain_id.size(1) > 0) { + // Re-initialize ecah outlier chain to current state random other chain + if (std::isnan(DREAMPar->N)) { + b_chain_select.set_size(1, 1); + b_chain_select[0] = rtNaN; + } else if (DREAMPar->N < 1.0) { + b_chain_select.set_size(1, 0); + } else { + b_chain_select.set_size(1, static_cast(DREAMPar->N - 1.0) + 1); + loop_ub = static_cast(DREAMPar->N - 1.0); + for (i = 0; i <= loop_ub; i++) { + b_chain_select[i] = static_cast(i) + 1.0; + } + } + + b_chain_id.set_size(1, chain_id.size(1)); + loop_ub = chain_id.size(1); + for (i = 0; i < loop_ub; i++) { + b_chain_id[i] = static_cast(chain_id[i]); + } + + coder::internal::nullAssignment(b_chain_select, b_chain_id); + + // Randomly permute these available chains + coder::randperm(DREAMPar->N - static_cast(chain_id.size(1)), r); + chain_select.set_size(1, r.size(1)); + loop_ub = r.size(1); + for (i = 0; i < loop_ub; i++) { + chain_select[i] = b_chain_select[static_cast(r[i]) - 1]; + } + + b_chain_select.set_size(1, chain_select.size(1)); + loop_ub = chain_select.size(1); + for (i = 0; i < loop_ub; i++) { + b_chain_select[i] = chain_select[i]; + } + + // Loop over each outlier chain + i = chain_id.size(1); + loop_ub = static_cast(DREAMPar->d + 2.0); + for (int32_T j{0}; j < i; j++) { + int32_T chain_id_tmp; + int16_T i2; + + // Added -- update log_L -- chain will not be considered as an outlier chain then + chain_select_tmp = static_cast(b_chain_select[j]); + chain_id_tmp = static_cast(chain_id[j]); + b_loop_ub = log_L.size(0); + c_log_L.set_size(b_loop_ub); + for (i1 = 0; i1 < b_loop_ub; i1++) { + c_log_L[i1] = log_L[i1 + log_L.size(0) * (chain_select_tmp - 1)]; + } + + b_loop_ub = c_log_L.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + log_L[i1 + log_L.size(0) * (chain_id_tmp - 1)] = c_log_L[i1]; + } + + // Jump outlier chain to r_idx -- X + chain_select.set_size(1, loop_ub); + for (i1 = 0; i1 < loop_ub; i1++) { + chain_select[i1] = X[(chain_select_tmp + X.size(0) * i1) - 1]; + } + + b_loop_ub = chain_select.size(1); + for (i1 = 0; i1 < b_loop_ub; i1++) { + X[(chain_id_tmp + X.size(0) * i1) - 1] = chain_select[i1]; + } + + // Add to chain_outlier and print to screen + if (outputOutlier.size(0) != 0) { + i2 = static_cast(outputOutlier.size(0)); + } else { + i2 = 0; + } + + if (outputOutlier.size(0) != 0) { + b_loop_ub = static_cast(outputOutlier.size(0)); + } else { + b_loop_ub = 0; + } + + b_outputOutlier.set_size(i2 + 1, 2); + for (i1 = 0; i1 < 2; i1++) { + for (chain_select_tmp = 0; chain_select_tmp < b_loop_ub; + chain_select_tmp++) { + b_outputOutlier[chain_select_tmp + b_outputOutlier.size(0) * i1] = + outputOutlier[chain_select_tmp + i2 * i1]; + } + } + + b_outputOutlier[static_cast(i2)] = log_L.size(0); + b_outputOutlier[i2 + b_outputOutlier.size(0)] = chain_id[j]; + outputOutlier.set_size(b_outputOutlier.size(0), 2); + b_loop_ub = b_outputOutlier.size(0); + for (i1 = 0; i1 < 2; i1++) { + for (chain_select_tmp = 0; chain_select_tmp < b_loop_ub; + chain_select_tmp++) { + outputOutlier[chain_select_tmp + outputOutlier.size(0) * i1] = + b_outputOutlier[chain_select_tmp + b_outputOutlier.size(0) * i1]; + } + } + + // Warning -- not enough chains to do sampling -- increase number of chains! + // evalstr = char(strcat('DREAM WARNING: Irreversible jump chain',{' '},num2str(chain_id(j)),{' '},'at',{' '},num2str(t),{' '},'generations \n')); + // fprintf(' DREAM WARNING: Irreversible jump chain %0.2f at %0.2f generations \n \n \n',chain_id(j),t) + // Now print warning to screen and to file + // fprintf(evalstr); % fprintf(fid,evalstr); + } + } + } +} + +// End of code generation (removeOutlier.cpp) diff --git a/RAT/removeOutlier.h b/RAT/removeOutlier.h new file mode 100644 index 00000000..e2ed7a34 --- /dev/null +++ b/RAT/removeOutlier.h @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// removeOutlier.h +// +// Code generation for function 'removeOutlier' +// +#ifndef REMOVEOUTLIER_H +#define REMOVEOUTLIER_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct14_T; +} + +// Function Declarations +namespace RAT +{ + void removeOutlier(::coder::array &X, ::coder::array + &log_L, const real_T outlier_data[], const int32_T + outlier_size[2], const struct14_T *DREAMPar, ::coder::array< + real_T, 2U> &outputOutlier); +} + +#endif + +// End of code generation (removeOutlier.h) diff --git a/RAT/repmat.cpp b/RAT/repmat.cpp index 0ae77f39..2fbba03e 100644 --- a/RAT/repmat.cpp +++ b/RAT/repmat.cpp @@ -10,6 +10,8 @@ // Include files #include "repmat.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" #include "rt_nonfinite.h" #include "coder_array.h" @@ -18,6 +20,65 @@ namespace RAT { namespace coder { + void b_repmat(real_T varargin_2, ::coder::array &b) + { + int32_T loop_ub_tmp; + loop_ub_tmp = static_cast(varargin_2); + b.set_size(1, loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + b[i] = '.'; + } + } + + void repmat(cell_wrap_9 b[6]) + { + cell_wrap_8 r; + r.f1.set_size(1, 1); + r.f1[0] = 1.0; + for (int32_T jtilecol{0}; jtilecol < 6; jtilecol++) { + b[jtilecol].f1.set_size(1, 1); + b[jtilecol].f1[0] = r; + } + } + + void repmat(real_T varargin_1, ::coder::array &b) + { + int32_T loop_ub_tmp; + loop_ub_tmp = static_cast(varargin_1); + b.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + b[i].I_no = 0.0; + b[i].FVr_oa = 0.0; + } + } + + void repmat(const ::coder::array &a, real_T varargin_1, ::coder:: + array &b) + { + b.set_size(static_cast(varargin_1), a.size(1)); + if ((static_cast(varargin_1) != 0) && (a.size(1) != 0)) { + int32_T i; + int32_T na; + na = a.size(1); + i = static_cast(varargin_1) - 1; + for (int32_T k{0}; k < na; k++) { + for (int32_T t{0}; t <= i; t++) { + b[t + b.size(0) * k] = a[k]; + } + } + } + } + + void repmat(real_T varargin_2, ::coder::array &b) + { + int32_T loop_ub_tmp; + loop_ub_tmp = static_cast(varargin_2); + b.set_size(1, loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + b[i] = '*'; + } + } + void repmat(const real_T a[2], real_T varargin_1, ::coder::array &b) { diff --git a/RAT/repmat.h b/RAT/repmat.h index 7806ff69..0e65e9b0 100644 --- a/RAT/repmat.h +++ b/RAT/repmat.h @@ -11,16 +11,29 @@ #define REPMAT_H // Include files +#include "RATMain_internal_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include +// Type Declarations +namespace RAT +{ + struct cell_wrap_9; +} + // Function Declarations namespace RAT { namespace coder { + void b_repmat(real_T varargin_2, ::coder::array &b); + void repmat(cell_wrap_9 b[6]); + void repmat(real_T varargin_1, ::coder::array &b); + void repmat(const ::coder::array &a, real_T varargin_1, ::coder:: + array &b); + void repmat(real_T varargin_2, ::coder::array &b); void repmat(const real_T a[2], real_T varargin_1, ::coder::array &b); } diff --git a/RAT/resampleLayers.cpp b/RAT/resampleLayers.cpp index 17ae4137..0e0e698f 100644 --- a/RAT/resampleLayers.cpp +++ b/RAT/resampleLayers.cpp @@ -10,9 +10,9 @@ // Include files #include "resampleLayers.h" +#include "RATMain_internal_types.h" #include "adaptive.h" #include "length.h" -#include "reflectivityCalculation_internal_types.h" #include "rt_nonfinite.h" #include "coder_array.h" @@ -22,7 +22,7 @@ namespace RAT void resampleLayers(const ::coder::array &sldProfile, const real_T resamPars[2], ::coder::array &newSLD) { - cell_24 expl_temp; + cell_27 expl_temp; real_T b_sldProfile[2]; int32_T i; int32_T n; diff --git a/RAT/resampleLayersReIm.cpp b/RAT/resampleLayersReIm.cpp index 389dab08..dd4d7ba8 100644 --- a/RAT/resampleLayersReIm.cpp +++ b/RAT/resampleLayersReIm.cpp @@ -10,17 +10,18 @@ // Include files #include "resampleLayersReIm.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" #include "adaptive.h" #include "interp1.h" -#include "reflectivityCalculation_internal_types.h" #include "rt_nonfinite.h" #include "coder_array.h" -#include // Function Definitions namespace RAT { - void resampleLayersReIm(const ::coder::array &sldProfile, const :: + void b_resampleLayersReIm(const ::coder::array &sldProfile, const :: coder::array &sldProfileIm, const real_T resamPars[2], ::coder:: array &newSLD) { @@ -28,7 +29,7 @@ namespace RAT ::coder::array b_sldProfileIm; ::coder::array c_sldProfileIm; ::coder::array newYIm; - cell_24 expl_temp; + cell_27 expl_temp; real_T b_sldProfile[2]; int32_T i; int32_T loop_ub; @@ -104,21 +105,22 @@ namespace RAT } } - void resampleLayersReIm(const real_T sldProfile_data[], const int32_T - sldProfile_size[2], const real_T sldProfileIm_data[], const int32_T - sldProfileIm_size[2], const real_T resamPars[2], ::coder::array - &newSLD) + void c_resampleLayersReIm(const ::coder::array &sldProfile, const :: + coder::array &sldProfileIm, const real_T resamPars[2], ::coder:: + array &newSLD) { ::coder::array b_expl_temp; - ::coder::array d_sldProfileIm_data; - ::coder::array e_sldProfileIm_data; + ::coder::array b_sldProfileIm_data; ::coder::array newYIm; - cell_24 expl_temp; - real_T b_sldProfileIm_data[1000]; - real_T c_sldProfileIm_data[1000]; - real_T sldProfile[2]; + ::coder::array sldProfileIm_data; + RATMainTLS *RATMainTLSThread; + cell_27 expl_temp; + real_T b_sldProfile[2]; + int32_T b_sldProfileIm_size; int32_T i; int32_T loop_ub; + int32_T sldProfileIm_size; + RATMainTLSThread = emlrtGetThreadStackData(); // Resample the SLD profile. In this case we have an imaginary SLD also, and // so we resample that onto the same points as the real one.. @@ -128,22 +130,24 @@ namespace RAT // Keep points and minangle as constants for now // will fix later // newX = linspace(xstart,xend,100); - sldProfile[0] = sldProfile_data[0]; - sldProfile[1] = sldProfile_data[sldProfile_size[0] - 1]; - adaptive(sldProfile_data, sldProfile_size, sldProfile, resamPars[0] * - 3.1415926535897931, resamPars[1], &expl_temp); + b_sldProfile[0] = sldProfile[0]; + b_sldProfile[1] = sldProfile[sldProfile.size(0) - 1]; + b_adaptive(sldProfile, b_sldProfile, resamPars[0] * 3.1415926535897931, + resamPars[1], &expl_temp); // Now interpolate the imaginary profile so that it is on the same x points // as the resampled real one.... - loop_ub = sldProfileIm_size[0]; - if (loop_ub - 1 >= 0) { - std::copy(&sldProfileIm_data[0], &sldProfileIm_data[loop_ub], - &b_sldProfileIm_data[0]); + sldProfileIm_size = sldProfileIm.size(0); + loop_ub = sldProfileIm.size(0); + for (i = 0; i < loop_ub; i++) { + RATMainTLSThread->f2.sldProfileIm_data[i] = sldProfileIm[i]; } - loop_ub = sldProfileIm_size[0]; + b_sldProfileIm_size = sldProfileIm.size(0); + loop_ub = sldProfileIm.size(0); for (i = 0; i < loop_ub; i++) { - c_sldProfileIm_data[i] = sldProfileIm_data[i + sldProfileIm_size[0]]; + RATMainTLSThread->f2.b_sldProfileIm_data[i] = sldProfileIm[i + + sldProfileIm.size(0)]; } b_expl_temp.set_size(expl_temp.f1.size(0)); @@ -152,14 +156,17 @@ namespace RAT b_expl_temp[i] = expl_temp.f1[i]; } - d_sldProfileIm_data.set(&b_sldProfileIm_data[0], sldProfileIm_size[0]); - e_sldProfileIm_data.set(&c_sldProfileIm_data[0], sldProfileIm_size[0]); - coder::interp1(d_sldProfileIm_data, e_sldProfileIm_data, b_expl_temp, newYIm); + sldProfileIm_data.set(&RATMainTLSThread->f2.sldProfileIm_data[0], + sldProfileIm_size); + b_sldProfileIm_data.set(&RATMainTLSThread->f2.b_sldProfileIm_data[0], + b_sldProfileIm_size); + coder::interp1(sldProfileIm_data, b_sldProfileIm_data, b_expl_temp, newYIm); newSLD.set_size(expl_temp.f1.size(0) - 1, 4); loop_ub = expl_temp.f1.size(0) - 1; for (i = 0; i < 4; i++) { - for (int32_T i1{0}; i1 < loop_ub; i1++) { - newSLD[i1 + newSLD.size(0) * i] = 0.0; + for (sldProfileIm_size = 0; sldProfileIm_size < loop_ub; sldProfileIm_size + ++) { + newSLD[sldProfileIm_size + newSLD.size(0) * i] = 0.0; } } diff --git a/RAT/resampleLayersReIm.h b/RAT/resampleLayersReIm.h index 6c966241..8df0be4b 100644 --- a/RAT/resampleLayersReIm.h +++ b/RAT/resampleLayersReIm.h @@ -19,13 +19,12 @@ // Function Declarations namespace RAT { - void resampleLayersReIm(const ::coder::array &sldProfile, const :: + void b_resampleLayersReIm(const ::coder::array &sldProfile, const :: + coder::array &sldProfileIm, const real_T resamPars[2], ::coder:: + array &newSLD); + void c_resampleLayersReIm(const ::coder::array &sldProfile, const :: coder::array &sldProfileIm, const real_T resamPars[2], ::coder:: array &newSLD); - void resampleLayersReIm(const real_T sldProfile_data[], const int32_T - sldProfile_size[2], const real_T sldProfileIm_data[], const int32_T - sldProfileIm_size[2], const real_T resamPars[2], ::coder::array - &newSLD); } #endif diff --git a/RAT/rescale.cpp b/RAT/rescale.cpp new file mode 100644 index 00000000..faa00820 --- /dev/null +++ b/RAT/rescale.cpp @@ -0,0 +1,133 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rescale.cpp +// +// Code generation for function 'rescale' +// + +// Include files +#include "rescale.h" +#include "bsxfun.h" +#include "rescaleKernel.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void rescale(::coder::array &A, const ::coder::array + &varargin_2, const ::coder::array &varargin_4, :: + coder::array &R) + { + ::coder::array b_A; + real_T b_varargin_2; + real_T varargin_1; + int32_T loop_ub; + boolean_T p; + if (varargin_2.size(0) == 1) { + loop_ub = A.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + varargin_1 = A[i]; + b_varargin_2 = varargin_2[0]; + if (std::isnan(b_varargin_2)) { + p = !std::isnan(varargin_1); + } else if (std::isnan(varargin_1)) { + p = false; + } else { + p = (varargin_1 < b_varargin_2); + } + + if (p) { + A[i] = b_varargin_2; + } else { + A[i] = varargin_1; + } + } + } else { + b_A.set_size(A.size(0)); + loop_ub = A.size(0) - 1; + for (int32_T i{0}; i <= loop_ub; i++) { + b_A[i] = A[i]; + } + + bsxfun(b_A, varargin_2, A); + } + + if (varargin_4.size(0) == 1) { + R.set_size(A.size(0)); + loop_ub = A.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + varargin_1 = A[i]; + b_varargin_2 = varargin_4[0]; + if (std::isnan(b_varargin_2)) { + p = !std::isnan(varargin_1); + } else if (std::isnan(varargin_1)) { + p = false; + } else { + p = (varargin_1 > b_varargin_2); + } + + if (p) { + R[i] = b_varargin_2; + } else { + R[i] = varargin_1; + } + } + } else { + b_bsxfun(A, varargin_4, R); + } + + rescaleKernel(R, varargin_2, varargin_4); + } + + real_T rescale_anonFcn1(real_T x, real_T y) + { + real_T varargout_1; + boolean_T p; + if (std::isnan(y)) { + p = !std::isnan(x); + } else if (std::isnan(x)) { + p = false; + } else { + p = (x < y); + } + + if (p) { + varargout_1 = y; + } else { + varargout_1 = x; + } + + return varargout_1; + } + + real_T rescale_anonFcn2(real_T x, real_T y) + { + real_T varargout_1; + boolean_T p; + if (std::isnan(y)) { + p = !std::isnan(x); + } else if (std::isnan(x)) { + p = false; + } else { + p = (x > y); + } + + if (p) { + varargout_1 = y; + } else { + varargout_1 = x; + } + + return varargout_1; + } + } +} + +// End of code generation (rescale.cpp) diff --git a/RAT/rescale.h b/RAT/rescale.h new file mode 100644 index 00000000..8a6dd769 --- /dev/null +++ b/RAT/rescale.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rescale.h +// +// Code generation for function 'rescale' +// +#ifndef RESCALE_H +#define RESCALE_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void rescale(::coder::array &A, const ::coder::array + &varargin_2, const ::coder::array &varargin_4, :: + coder::array &R); + real_T rescale_anonFcn1(real_T x, real_T y); + real_T rescale_anonFcn2(real_T x, real_T y); + } +} + +#endif + +// End of code generation (rescale.h) diff --git a/RAT/rescaleKernel.cpp b/RAT/rescaleKernel.cpp new file mode 100644 index 00000000..0315c72e --- /dev/null +++ b/RAT/rescaleKernel.cpp @@ -0,0 +1,953 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rescaleKernel.cpp +// +// Code generation for function 'rescaleKernel' +// + +// Include files +#include "rescaleKernel.h" +#include "abs.h" +#include "bsxfun.h" +#include "div.h" +#include "log2.h" +#include "minOrMax.h" +#include "pow2.h" +#include "rdivide_helper.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const ::coder:: + array &in4, const ::coder::array &in5, const ::coder:: + array &in6); + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const ::coder:: + array &in4, const ::coder::array &in5, const ::coder:: + array &in6, const ::coder::array &in7); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const ::coder:: + array &in4, const ::coder::array &in5, const ::coder:: + array &in6) + { + ::coder::array r; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + int32_T stride_2_0; + int32_T stride_3_0; + int32_T stride_4_0; + int32_T stride_5_0; + int32_T stride_6_0; + if (in4.size(0) == 1) { + i = in6.size(0); + stride_0_0 = in5.size(0); + if (i == 1) { + if (stride_0_0 == 1) { + if (in4.size(0) == 1) { + i = in3.size(0); + } else { + i = in4.size(0); + } + } else if (in4.size(0) == 1) { + i = in5.size(0); + } else { + i = in4.size(0); + } + } else if (in4.size(0) == 1) { + i = in6.size(0); + } else { + i = in4.size(0); + } + } else { + i = in4.size(0); + } + + r.set_size(i); + stride_0_0 = (in3.size(0) != 1); + stride_1_0 = (in4.size(0) != 1); + stride_2_0 = (in5.size(0) != 1); + stride_3_0 = (in4.size(0) != 1); + stride_4_0 = (in6.size(0) != 1); + stride_5_0 = (in4.size(0) != 1); + stride_6_0 = (in4.size(0) != 1); + if (in4.size(0) == 1) { + i = in6.size(0); + if (i == 1) { + if (in4.size(0) == 1) { + i = in5.size(0); + } else { + i = in4.size(0); + } + + if (i == 1) { + if (in4.size(0) == 1) { + loop_ub = in3.size(0); + } else { + loop_ub = in4.size(0); + } + } else if (in4.size(0) == 1) { + loop_ub = in5.size(0); + } else { + loop_ub = in4.size(0); + } + } else if (in4.size(0) == 1) { + loop_ub = in6.size(0); + } else { + loop_ub = in4.size(0); + } + } else { + loop_ub = in4.size(0); + } + + for (i = 0; i < loop_ub; i++) { + r[i] = 1.0 / ((in3[i * stride_0_0] / in4[i * stride_1_0] - in5[i * + stride_2_0] / in4[i * stride_3_0]) + static_cast + (in6[i * stride_4_0]) / in4[i * stride_5_0]) / in4[i * + stride_6_0]; + } + + coder::e_bsxfun(in2, r, in1); + } + + static void binary_expand_op(::coder::array &in1, const ::coder:: + array &in2, const ::coder::array &in3, const ::coder:: + array &in4, const ::coder::array &in5, const ::coder:: + array &in6, const ::coder::array &in7) + { + ::coder::array b_in3; + int32_T i; + int32_T i1; + int32_T i2; + int32_T i3; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_10_0; + int32_T stride_11_0; + int32_T stride_1_0; + int32_T stride_2_0; + int32_T stride_3_0; + int32_T stride_4_0; + int32_T stride_5_0; + int32_T stride_6_0; + int32_T stride_7_0; + int32_T stride_8_0; + int32_T stride_9_0; + if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + + if (i == 1) { + if (in5.size(0) == 1) { + i = in1.size(0); + } else { + i = in5.size(0); + } + } else if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + + if (in4.size(0) == 1) { + if (in7.size(0) == 1) { + i1 = in6.size(0); + } else { + i1 = in7.size(0); + } + } else { + i1 = in4.size(0); + } + + if (in3.size(0) == 1) { + i2 = in5.size(0); + } else { + i2 = in3.size(0); + } + + if (in7.size(0) == 1) { + i3 = in6.size(0); + } else { + i3 = in7.size(0); + } + + if (i == 1) { + if (i1 == 1) { + if (i2 == 1) { + if (in4.size(0) == 1) { + i = in1.size(0); + } else { + i = in4.size(0); + } + } else if (in3.size(0) == 1) { + i = in5.size(0); + } else { + i = in3.size(0); + } + } else if (in4.size(0) == 1) { + if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + } else { + i = in4.size(0); + } + } else if (i3 == 1) { + if (in5.size(0) == 1) { + i = in1.size(0); + } else { + i = in5.size(0); + } + } else if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + + if (in7.size(0) == 1) { + i1 = in6.size(0); + } else { + i1 = in7.size(0); + } + + if (i1 == 1) { + if (in5.size(0) == 1) { + i1 = in1.size(0); + } else { + i1 = in5.size(0); + } + } else if (in7.size(0) == 1) { + i1 = in6.size(0); + } else { + i1 = in7.size(0); + } + + if (in4.size(0) == 1) { + if (in7.size(0) == 1) { + i2 = in6.size(0); + } else { + i2 = in7.size(0); + } + } else { + i2 = in4.size(0); + } + + if (in3.size(0) == 1) { + i3 = in5.size(0); + } else { + i3 = in3.size(0); + } + + if (in7.size(0) == 1) { + loop_ub = in6.size(0); + } else { + loop_ub = in7.size(0); + } + + if (i == 1) { + i = in3.size(0); + } else if (i1 == 1) { + if (i2 == 1) { + if (i3 == 1) { + if (in4.size(0) == 1) { + i = in1.size(0); + } else { + i = in4.size(0); + } + } else if (in3.size(0) == 1) { + i = in5.size(0); + } else { + i = in3.size(0); + } + } else if (in4.size(0) == 1) { + if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + } else { + i = in4.size(0); + } + } else if (loop_ub == 1) { + if (in5.size(0) == 1) { + i = in1.size(0); + } else { + i = in5.size(0); + } + } else if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + + b_in3.set_size(i); + stride_0_0 = (in3.size(0) != 1); + stride_1_0 = (in1.size(0) != 1); + stride_2_0 = (in4.size(0) != 1); + stride_3_0 = (in5.size(0) != 1); + stride_4_0 = (in3.size(0) != 1); + stride_5_0 = (in6.size(0) != 1); + stride_6_0 = (in7.size(0) != 1); + stride_7_0 = (in4.size(0) != 1); + stride_8_0 = (in1.size(0) != 1); + stride_9_0 = (in5.size(0) != 1); + stride_10_0 = (in6.size(0) != 1); + stride_11_0 = (in7.size(0) != 1); + if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + + if (i == 1) { + if (in5.size(0) == 1) { + i = in1.size(0); + } else { + i = in5.size(0); + } + } else if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + + if (in4.size(0) == 1) { + if (in7.size(0) == 1) { + i1 = in6.size(0); + } else { + i1 = in7.size(0); + } + } else { + i1 = in4.size(0); + } + + if (in3.size(0) == 1) { + i2 = in5.size(0); + } else { + i2 = in3.size(0); + } + + if (in7.size(0) == 1) { + i3 = in6.size(0); + } else { + i3 = in7.size(0); + } + + if (i == 1) { + if (i1 == 1) { + if (i2 == 1) { + if (in4.size(0) == 1) { + i = in1.size(0); + } else { + i = in4.size(0); + } + } else if (in3.size(0) == 1) { + i = in5.size(0); + } else { + i = in3.size(0); + } + } else if (in4.size(0) == 1) { + if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + } else { + i = in4.size(0); + } + } else if (i3 == 1) { + if (in5.size(0) == 1) { + i = in1.size(0); + } else { + i = in5.size(0); + } + } else if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + + if (i == 1) { + loop_ub = in3.size(0); + } else { + if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + + if (i == 1) { + if (in5.size(0) == 1) { + i = in1.size(0); + } else { + i = in5.size(0); + } + } else if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + + if (i == 1) { + if (in4.size(0) == 1) { + if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + } else { + i = in4.size(0); + } + + if (i == 1) { + if (in3.size(0) == 1) { + i = in5.size(0); + } else { + i = in3.size(0); + } + + if (i == 1) { + if (in4.size(0) == 1) { + loop_ub = in1.size(0); + } else { + loop_ub = in4.size(0); + } + } else if (in3.size(0) == 1) { + loop_ub = in5.size(0); + } else { + loop_ub = in3.size(0); + } + } else if (in4.size(0) == 1) { + if (in7.size(0) == 1) { + loop_ub = in6.size(0); + } else { + loop_ub = in7.size(0); + } + } else { + loop_ub = in4.size(0); + } + } else { + if (in7.size(0) == 1) { + i = in6.size(0); + } else { + i = in7.size(0); + } + + if (i == 1) { + if (in5.size(0) == 1) { + loop_ub = in1.size(0); + } else { + loop_ub = in5.size(0); + } + } else if (in7.size(0) == 1) { + loop_ub = in6.size(0); + } else { + loop_ub = in7.size(0); + } + } + } + + for (i = 0; i < loop_ub; i++) { + b_in3[i] = in3[i * stride_0_0] * (((in1[i * stride_1_0] * in4[i * + stride_2_0] - in5[i * stride_3_0] * (1.0 / in3[i * stride_4_0])) + + static_cast(in6[i * stride_5_0]) / in7[i * stride_6_0] * in4[i * + stride_7_0]) / ((in1[i * stride_8_0] - in5[i * stride_9_0]) + + static_cast(in6[i * stride_10_0]) / in7[i * + stride_11_0])); + } + + coder::f_bsxfun(in2, b_in3, in1); + } + + namespace coder + { + void rescaleKernel(::coder::array &A, const ::coder::array< + real_T, 1U> &inputMin, const ::coder::array + &inputMax) + { + ::coder::array b_r1; + ::coder::array e1; + ::coder::array iMax; + ::coder::array iMin; + ::coder::array r; + ::coder::array r1; + ::coder::array r3; + ::coder::array sigma; + ::coder::array x_tmp; + if (A.size(0) != 0) { + real_T varargin_2; + int32_T i; + int32_T i1; + int32_T i10; + int32_T i11; + int32_T i12; + int32_T i2; + int32_T i3; + int32_T i4; + int32_T i5; + int32_T i6; + int32_T i7; + int32_T i8; + int32_T i9; + int32_T k; + r.set_size(inputMax.size(0)); + k = inputMax.size(0); + for (i = 0; i < k; i++) { + varargin_2 = inputMax[i]; + r[i] = std::fmin(0.0, varargin_2); + } + + c_bsxfun(r, inputMin, sigma); + e1.set_size(A.size(0)); + k = A.size(0) - 1; + for (i = 0; i <= k; i++) { + e1[i] = A[i]; + } + + d_bsxfun(e1, sigma, A); + d_bsxfun(inputMin, sigma, iMin); + d_bsxfun(inputMax, sigma, iMax); + b_abs(iMax, r); + b_abs(iMin, e1); + internal::maximum2(r, e1, r1); + b_log2(r1, sigma, e1); + r3.set_size(e1.size(0)); + k = e1.size(0); + for (i = 0; i < k; i++) { + r3[i] = e1[i] - 1.0; + } + + pow2(r3, b_r1); + k = e1.size(0); + for (i = 0; i < k; i++) { + e1[i] = (e1[i] + 1.0) / 2.0; + } + + i = e1.size(0); + for (k = 0; k < i; k++) { + e1[k] = std::trunc(e1[k]); + } + + k = e1.size(0); + for (i = 0; i < k; i++) { + e1[i] = e1[i] - 1.0; + } + + pow2(e1, r3); + if (iMax.size(0) == b_r1.size(0)) { + r.set_size(iMax.size(0)); + k = iMax.size(0); + for (i = 0; i < k; i++) { + r[i] = iMax[i] / b_r1[i]; + } + } else { + rdivide(r, iMax, b_r1); + } + + e1.set_size(r3.size(0)); + k = r3.size(0); + for (i = 0; i < k; i++) { + e1[i] = 0.0 / r3[i]; + } + + if (iMin.size(0) == b_r1.size(0)) { + r1.set_size(iMin.size(0)); + k = iMin.size(0); + for (i = 0; i < k; i++) { + r1[i] = iMin[i] / b_r1[i]; + } + } else { + rdivide(r1, iMin, b_r1); + } + + if (iMin.size(0) == iMax.size(0)) { + x_tmp.set_size(iMin.size(0)); + k = iMin.size(0); + for (i = 0; i < k; i++) { + x_tmp[i] = static_cast(iMin[i] == iMax[i]); + } + } else { + binary_expand_op(x_tmp, iMin, iMax); + } + + if (iMax.size(0) == 1) { + i = r3.size(0); + } else { + i = iMax.size(0); + } + + if (iMin.size(0) == 1) { + k = r3.size(0); + } else { + k = iMin.size(0); + } + + if (iMax.size(0) == 1) { + i1 = r3.size(0); + } else { + i1 = iMax.size(0); + } + + if (i1 == 1) { + if (iMin.size(0) == 1) { + i1 = r3.size(0); + } else { + i1 = iMin.size(0); + } + } else if (iMax.size(0) == 1) { + i1 = r3.size(0); + } else { + i1 = iMax.size(0); + } + + if (x_tmp.size(0) == 1) { + i2 = r3.size(0); + } else { + i2 = x_tmp.size(0); + } + + if (iMax.size(0) == 1) { + i3 = r3.size(0); + } else { + i3 = iMax.size(0); + } + + if (i3 == 1) { + if (iMin.size(0) == 1) { + i3 = r3.size(0); + } else { + i3 = iMin.size(0); + } + } else if (iMax.size(0) == 1) { + i3 = r3.size(0); + } else { + i3 = iMax.size(0); + } + + if (iMax.size(0) == 1) { + i4 = r3.size(0); + } else { + i4 = iMax.size(0); + } + + if (i3 == 1) { + if (x_tmp.size(0) == 1) { + i3 = r3.size(0); + } else { + i3 = x_tmp.size(0); + } + } else if (i4 == 1) { + if (iMin.size(0) == 1) { + i3 = r3.size(0); + } else { + i3 = iMin.size(0); + } + } else if (iMax.size(0) == 1) { + i3 = r3.size(0); + } else { + i3 = iMax.size(0); + } + + if ((iMax.size(0) == r3.size(0)) && (iMin.size(0) == r3.size(0)) && (i == + k) && (x_tmp.size(0) == r3.size(0)) && (i1 == i2) && (i3 == r3.size + (0))) { + k = iMax.size(0); + for (i = 0; i < k; i++) { + iMax[i] = 1.0 / ((iMax[i] / r3[i] - iMin[i] / r3[i]) + + static_cast(x_tmp[i]) / r3[i]) / r3[i]; + } + + e_bsxfun(A, iMax, sigma); + } else { + binary_expand_op(sigma, A, iMax, r3, iMin, x_tmp); + } + + if (r.size(0) == 1) { + i = e1.size(0); + } else { + i = r.size(0); + } + + if (r1.size(0) == 1) { + k = r3.size(0); + } else { + k = r1.size(0); + } + + if (x_tmp.size(0) == 1) { + i1 = b_r1.size(0); + } else { + i1 = x_tmp.size(0); + } + + if (r.size(0) == 1) { + i2 = e1.size(0); + } else { + i2 = r.size(0); + } + + if (i2 == 1) { + if (r1.size(0) == 1) { + i2 = r3.size(0); + } else { + i2 = r1.size(0); + } + } else if (r.size(0) == 1) { + i2 = e1.size(0); + } else { + i2 = r.size(0); + } + + if (x_tmp.size(0) == 1) { + i3 = b_r1.size(0); + } else { + i3 = x_tmp.size(0); + } + + if (i3 == 1) { + i3 = e1.size(0); + } else if (x_tmp.size(0) == 1) { + i3 = b_r1.size(0); + } else { + i3 = x_tmp.size(0); + } + + if (r.size(0) == 1) { + i4 = r1.size(0); + } else { + i4 = r.size(0); + } + + if (x_tmp.size(0) == 1) { + i5 = b_r1.size(0); + } else { + i5 = x_tmp.size(0); + } + + if (r.size(0) == 1) { + i6 = e1.size(0); + } else { + i6 = r.size(0); + } + + if (i6 == 1) { + if (r1.size(0) == 1) { + i6 = r3.size(0); + } else { + i6 = r1.size(0); + } + } else if (r.size(0) == 1) { + i6 = e1.size(0); + } else { + i6 = r.size(0); + } + + if (x_tmp.size(0) == 1) { + i7 = b_r1.size(0); + } else { + i7 = x_tmp.size(0); + } + + if (r.size(0) == 1) { + i8 = e1.size(0); + } else { + i8 = r.size(0); + } + + if (i6 == 1) { + if (i7 == 1) { + i6 = e1.size(0); + } else if (x_tmp.size(0) == 1) { + i6 = b_r1.size(0); + } else { + i6 = x_tmp.size(0); + } + } else if (i8 == 1) { + if (r1.size(0) == 1) { + i6 = r3.size(0); + } else { + i6 = r1.size(0); + } + } else if (r.size(0) == 1) { + i6 = e1.size(0); + } else { + i6 = r.size(0); + } + + if (r.size(0) == 1) { + i7 = r1.size(0); + } else { + i7 = r.size(0); + } + + if (i7 == 1) { + if (x_tmp.size(0) == 1) { + i7 = b_r1.size(0); + } else { + i7 = x_tmp.size(0); + } + } else if (r.size(0) == 1) { + i7 = r1.size(0); + } else { + i7 = r.size(0); + } + + if (r.size(0) == 1) { + i8 = e1.size(0); + } else { + i8 = r.size(0); + } + + if (i8 == 1) { + if (r1.size(0) == 1) { + i8 = r3.size(0); + } else { + i8 = r1.size(0); + } + } else if (r.size(0) == 1) { + i8 = e1.size(0); + } else { + i8 = r.size(0); + } + + if (x_tmp.size(0) == 1) { + i9 = b_r1.size(0); + } else { + i9 = x_tmp.size(0); + } + + if (r.size(0) == 1) { + i10 = e1.size(0); + } else { + i10 = r.size(0); + } + + if (i8 == 1) { + if (i9 == 1) { + i8 = e1.size(0); + } else if (x_tmp.size(0) == 1) { + i8 = b_r1.size(0); + } else { + i8 = x_tmp.size(0); + } + } else if (i10 == 1) { + if (r1.size(0) == 1) { + i8 = r3.size(0); + } else { + i8 = r1.size(0); + } + } else if (r.size(0) == 1) { + i8 = e1.size(0); + } else { + i8 = r.size(0); + } + + if (r.size(0) == 1) { + i9 = r1.size(0); + } else { + i9 = r.size(0); + } + + if (r.size(0) == 1) { + i10 = e1.size(0); + } else { + i10 = r.size(0); + } + + if (i10 == 1) { + if (r1.size(0) == 1) { + i10 = r3.size(0); + } else { + i10 = r1.size(0); + } + } else if (r.size(0) == 1) { + i10 = e1.size(0); + } else { + i10 = r.size(0); + } + + if (x_tmp.size(0) == 1) { + i11 = b_r1.size(0); + } else { + i11 = x_tmp.size(0); + } + + if (r.size(0) == 1) { + i12 = e1.size(0); + } else { + i12 = r.size(0); + } + + if (i8 == 1) { + if (i9 == 1) { + if (x_tmp.size(0) == 1) { + i8 = b_r1.size(0); + } else { + i8 = x_tmp.size(0); + } + } else if (r.size(0) == 1) { + i8 = r1.size(0); + } else { + i8 = r.size(0); + } + } else if (i10 == 1) { + if (i11 == 1) { + i8 = e1.size(0); + } else if (x_tmp.size(0) == 1) { + i8 = b_r1.size(0); + } else { + i8 = x_tmp.size(0); + } + } else if (i12 == 1) { + if (r1.size(0) == 1) { + i8 = r3.size(0); + } else { + i8 = r1.size(0); + } + } else if (r.size(0) == 1) { + i8 = e1.size(0); + } else { + i8 = r.size(0); + } + + if ((r.size(0) == e1.size(0)) && (r1.size(0) == r3.size(0)) && (i == k) && + (x_tmp.size(0) == b_r1.size(0)) && (i1 == e1.size(0)) && (i2 == i3) && + (r.size(0) == r1.size(0)) && (x_tmp.size(0) == b_r1.size(0)) && (i4 == + i5) && (i6 == i7) && (r3.size(0) == i8)) { + k = r3.size(0); + for (i = 0; i < k; i++) { + varargin_2 = static_cast(x_tmp[i]) / b_r1[i]; + r3[i] = r3[i] * (((r[i] * e1[i] - r1[i] * (1.0 / r3[i])) + + varargin_2 * e1[i]) / ((r[i] - r1[i]) + varargin_2)); + } + + f_bsxfun(sigma, r3, r); + } else { + binary_expand_op(r, sigma, r3, e1, r1, x_tmp, b_r1); + } + + bsxfun(r, e1); + b_bsxfun(e1, r); + c_bsxfun(r, A); + } + } + } +} + +// End of code generation (rescaleKernel.cpp) diff --git a/RAT/rescaleKernel.h b/RAT/rescaleKernel.h new file mode 100644 index 00000000..27e3d72d --- /dev/null +++ b/RAT/rescaleKernel.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rescaleKernel.h +// +// Code generation for function 'rescaleKernel' +// +#ifndef RESCALEKERNEL_H +#define RESCALEKERNEL_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void rescaleKernel(::coder::array &A, const ::coder::array< + real_T, 1U> &inputMin, const ::coder::array + &inputMax); + } +} + +#endif + +// End of code generation (rescaleKernel.h) diff --git a/RAT/rescaleParameters.cpp b/RAT/rescaleParameters.cpp new file mode 100644 index 00000000..d022fb48 --- /dev/null +++ b/RAT/rescaleParameters.cpp @@ -0,0 +1,62 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rescaleParameters.cpp +// +// Code generation for function 'rescaleParameters' +// + +// Include files +#include "rescaleParameters.h" +#include "RATMain_rtwutil.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void rescaleParameters(const ::coder::array &prior, const ::coder:: + array ¶ms, ::coder::array &scaled) + { + int32_T i; + int32_T loop_ub; + + // scaled = rescaleParameters(prior, params) + // + // This function will do the reverse of scaleParameters. + scaled.set_size(params.size(1)); + loop_ub = params.size(1); + for (i = 0; i < loop_ub; i++) { + scaled[i] = 0.0; + } + + i = params.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T priortype; + priortype = prior[b_i]; + if (priortype == 1.0) { + real_T p3; + + // uniform + p3 = prior[b_i + prior.size(0) * 3]; + scaled[b_i] = params[b_i] * (prior[b_i + prior.size(0) * 4] - p3) + p3; + } else if (priortype == 2.0) { + // gaussian + scaled[b_i] = params[b_i] * prior[b_i + prior.size(0) * 2] + prior[b_i + + prior.size(0)]; + } else if (priortype == 3.0) { + real_T scaled_tmp; + + // jeffreys + scaled_tmp = std::log10(prior[b_i + prior.size(0)]); + scaled[b_i] = rt_powd_snf(10.0, params[b_i] * (std::log10(prior[b_i + + prior.size(0) * 2]) - scaled_tmp) + scaled_tmp); + } + } + } +} + +// End of code generation (rescaleParameters.cpp) diff --git a/RAT/rescaleParameters.h b/RAT/rescaleParameters.h new file mode 100644 index 00000000..2016b69f --- /dev/null +++ b/RAT/rescaleParameters.h @@ -0,0 +1,28 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rescaleParameters.h +// +// Code generation for function 'rescaleParameters' +// +#ifndef RESCALEPARAMETERS_H +#define RESCALEPARAMETERS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void rescaleParameters(const ::coder::array &prior, const ::coder:: + array ¶ms, ::coder::array &scaled); +} + +#endif + +// End of code generation (rescaleParameters.h) diff --git a/RAT/reshapeSizeChecks.cpp b/RAT/reshapeSizeChecks.cpp new file mode 100644 index 00000000..462d71c8 --- /dev/null +++ b/RAT/reshapeSizeChecks.cpp @@ -0,0 +1,42 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reshapeSizeChecks.cpp +// +// Code generation for function 'reshapeSizeChecks' +// + +// Include files +#include "reshapeSizeChecks.h" +#include "rt_nonfinite.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + int32_T computeDimsData(real_T varargin_1) + { + int32_T b_calclen; + if (static_cast(varargin_1) > 0) { + if (static_cast(static_cast(varargin_1)) == 0U) { + b_calclen = MAX_int32_T; + } else { + b_calclen = static_cast(1000000U / static_cast( + static_cast(varargin_1))); + } + } else { + b_calclen = 0; + } + + return b_calclen; + } + } + } +} + +// End of code generation (reshapeSizeChecks.cpp) diff --git a/RAT/reshapeSizeChecks.h b/RAT/reshapeSizeChecks.h new file mode 100644 index 00000000..2bb4f96e --- /dev/null +++ b/RAT/reshapeSizeChecks.h @@ -0,0 +1,32 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// reshapeSizeChecks.h +// +// Code generation for function 'reshapeSizeChecks' +// +#ifndef RESHAPESIZECHECKS_H +#define RESHAPESIZECHECKS_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + int32_T computeDimsData(real_T varargin_1); + } + } +} + +#endif + +// End of code generation (reshapeSizeChecks.h) diff --git a/RAT/rng.cpp b/RAT/rng.cpp new file mode 100644 index 00000000..e30212e3 --- /dev/null +++ b/RAT/rng.cpp @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rng.cpp +// +// Code generation for function 'rng' +// + +// Include files +#include "rng.h" +#include "RATMain_data.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void rng() + { + uint32_T r; + std::memset(&state[0], 0, 625U * sizeof(uint32_T)); + r = 5489U; + state[0] = 5489U; + for (int32_T mti{0}; mti < 623; mti++) { + r = ((r ^ r >> 30U) * 1812433253U + static_cast(mti)) + 1U; + state[mti + 1] = r; + } + + state[624] = 624U; + } + } +} + +// End of code generation (rng.cpp) diff --git a/RAT/rng.h b/RAT/rng.h new file mode 100644 index 00000000..e70796c2 --- /dev/null +++ b/RAT/rng.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// rng.h +// +// Code generation for function 'rng' +// +#ifndef RNG_H +#define RNG_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void rng(); + } +} + +#endif + +// End of code generation (rng.h) diff --git a/RAT/rtGetInf.cpp b/RAT/rtGetInf.cpp index 475dc669..169f0848 100644 --- a/RAT/rtGetInf.cpp +++ b/RAT/rtGetInf.cpp @@ -5,7 +5,7 @@ // // rtGetInf.cpp // -// Code generation for function 'reflectivityCalculation' +// Code generation for function 'RATMain' // // Abstract: diff --git a/RAT/rtGetInf.h b/RAT/rtGetInf.h index bd5175cd..ec33c0ba 100644 --- a/RAT/rtGetInf.h +++ b/RAT/rtGetInf.h @@ -5,7 +5,7 @@ // // rtGetInf.h // -// Code generation for function 'reflectivityCalculation' +// Code generation for function 'RATMain' // #ifndef RTGETINF_H #define RTGETINF_H diff --git a/RAT/rtGetNaN.cpp b/RAT/rtGetNaN.cpp index e82ce1d1..57d67f72 100644 --- a/RAT/rtGetNaN.cpp +++ b/RAT/rtGetNaN.cpp @@ -5,7 +5,7 @@ // // rtGetNaN.cpp // -// Code generation for function 'reflectivityCalculation' +// Code generation for function 'RATMain' // // Abstract: diff --git a/RAT/rtGetNaN.h b/RAT/rtGetNaN.h index 828e4593..27cd60fd 100644 --- a/RAT/rtGetNaN.h +++ b/RAT/rtGetNaN.h @@ -5,7 +5,7 @@ // // rtGetNaN.h // -// Code generation for function 'reflectivityCalculation' +// Code generation for function 'RATMain' // #ifndef RTGETNAN_H #define RTGETNAN_H diff --git a/RAT/rt_defines.h b/RAT/rt_defines.h index bbc6a3d5..833437e5 100644 --- a/RAT/rt_defines.h +++ b/RAT/rt_defines.h @@ -5,7 +5,7 @@ // // rt_defines.h // -// Code generation for function 'reflectivityCalculation' +// Code generation for function 'RATMain' // #ifndef RT_DEFINES_H #define RT_DEFINES_H diff --git a/RAT/rt_nonfinite.cpp b/RAT/rt_nonfinite.cpp index 8915df2c..5a37904c 100644 --- a/RAT/rt_nonfinite.cpp +++ b/RAT/rt_nonfinite.cpp @@ -5,7 +5,7 @@ // // rt_nonfinite.cpp // -// Code generation for function 'reflectivityCalculation' +// Code generation for function 'RATMain' // // Abstract: diff --git a/RAT/rt_nonfinite.h b/RAT/rt_nonfinite.h index 712242fb..3d779da1 100644 --- a/RAT/rt_nonfinite.h +++ b/RAT/rt_nonfinite.h @@ -5,7 +5,7 @@ // // rt_nonfinite.h // -// Code generation for function 'reflectivityCalculation' +// Code generation for function 'RATMain' // #ifndef RT_NONFINITE_H #define RT_NONFINITE_H diff --git a/RAT/rtwtypes.h b/RAT/rtwtypes.h index a71b5fd2..30d76340 100644 --- a/RAT/rtwtypes.h +++ b/RAT/rtwtypes.h @@ -5,7 +5,7 @@ // // rtwtypes.h // -// Code generation for function 'reflectivityCalculation' +// Code generation for function 'RATMain' // #ifndef RTWTYPES_H #define RTWTYPES_H diff --git a/RAT/runDE.cpp b/RAT/runDE.cpp new file mode 100644 index 00000000..64fe92fc --- /dev/null +++ b/RAT/runDE.cpp @@ -0,0 +1,361 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// runDE.cpp +// +// Code generation for function 'runDE' +// + +// Include files +#include "runDE.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "deopt.h" +#include "length.h" +#include "packParams.h" +#include "reflectivityCalculation.h" +#include "rt_nonfinite.h" +#include "strcmp.h" +#include "unpackParams.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include +#include + +// Function Definitions +namespace RAT +{ + k_struct_T intrafun(const ::coder::array &p, struct5_T *problemDef, + const char_T controls_parallel_data[], const int32_T + controls_parallel_size[2], const real_T + controls_resamPars[2], boolean_T controls_calcSldDuringFit, + const struct3_T *controls_checks, const ::coder::array< + cell_wrap_2, 2U> &problemDefCells_f1, const ::coder::array< + cell_wrap_8, 2U> &problemDefCells_f2, const ::coder::array< + cell_wrap_2, 2U> &problemDefCells_f3, const ::coder::array< + cell_wrap_2, 2U> &problemDefCells_f4, const ::coder::array< + cell_wrap_8, 2U> &problemDefCells_f5, const ::coder::array< + cell_wrap_8, 1U> &problemDefCells_f6, const ::coder::array< + cell_wrap_1, 2U> &problemDefCells_f14, const ::coder:: + array &problemDefCells_f19) + { + cell_13 a__2; + cell_14 expl_temp; + k_struct_T S_MSE; + struct2_T b_expl_temp; + struct_T b_problemDef; + int32_T loop_ub; + problemDef->fitParams.set_size(1, p.size(1)); + loop_ub = p.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + problemDef->fitParams[problemDef->fitParams.size(0) * i] = p[i]; + } + + unpackParams(problemDef, controls_checks->fitParam, + controls_checks->fitBackgroundParam, + controls_checks->fitQzshift, controls_checks->fitScalefactor, + controls_checks->fitBulkIn, controls_checks->fitBulkOut, + controls_checks->fitResolutionParam, + controls_checks->fitDomainRatio); + expl_temp.f19.set_size(1, problemDefCells_f19.size(1)); + loop_ub = problemDefCells_f19.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + expl_temp.f19[i] = problemDefCells_f19[i]; + } + + expl_temp.f14.set_size(1, problemDefCells_f14.size(1)); + loop_ub = problemDefCells_f14.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + expl_temp.f14[i] = problemDefCells_f14[i]; + } + + expl_temp.f6.set_size(problemDefCells_f6.size(0)); + loop_ub = problemDefCells_f6.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + expl_temp.f6[i] = problemDefCells_f6[i]; + } + + expl_temp.f5.set_size(1, problemDefCells_f5.size(1)); + loop_ub = problemDefCells_f5.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + expl_temp.f5[i] = problemDefCells_f5[i]; + } + + expl_temp.f4.set_size(1, problemDefCells_f4.size(1)); + loop_ub = problemDefCells_f4.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + expl_temp.f4[i] = problemDefCells_f4[i]; + } + + expl_temp.f3.set_size(1, problemDefCells_f3.size(1)); + loop_ub = problemDefCells_f3.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + expl_temp.f3[i] = problemDefCells_f3[i]; + } + + expl_temp.f2.set_size(1, problemDefCells_f2.size(1)); + loop_ub = problemDefCells_f2.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + expl_temp.f2[i] = problemDefCells_f2[i]; + } + + expl_temp.f1.set_size(1, problemDefCells_f1.size(1)); + loop_ub = problemDefCells_f1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + expl_temp.f1[i] = problemDefCells_f1[i]; + } + + b_expl_temp.checks = *controls_checks; + b_expl_temp.calcSldDuringFit = controls_calcSldDuringFit; + b_expl_temp.resamPars[0] = controls_resamPars[0]; + b_expl_temp.resamPars[1] = controls_resamPars[1]; + b_expl_temp.parallel.size[0] = 1; + b_expl_temp.parallel.size[1] = controls_parallel_size[1]; + loop_ub = controls_parallel_size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&controls_parallel_data[0], &controls_parallel_data[loop_ub], + &b_expl_temp.parallel.data[0]); + } + + reflectivityCalculation(problemDef, &expl_temp, &b_expl_temp, &b_problemDef, + &a__2); + S_MSE.FVr_oa = b_problemDef.calculations.sumChi; + + // no constraints THESE FIRST FEW VALS MAY BE WRONG + // no constraint array + S_MSE.I_no = 1.0; + + // number of objectives (costs) + return S_MSE; + } + + void runDE(struct5_T *problemDef, const cell_14 *problemDefCells, const + struct1_T *problemDefLimits, const struct2_T *controls, struct_T + *problem, cell_wrap_9 result[6]) + { + static const real_T FVr_x[50]{ -1.0, -0.95918367346938771, + -0.91836734693877542, -0.87755102040816324, -0.836734693877551, + -0.79591836734693866, -0.75510204081632648, -0.71428571428571419, + -0.673469387755102, -0.63265306122448972, -0.59183673469387754, + -0.55102040816326525, -0.51020408163265307, -0.46938775510204078, + -0.42857142857142855, -0.38775510204081631, -0.34693877551020408, + -0.30612244897959179, -0.26530612244897955, -0.22448979591836732, + -0.18367346938775508, -0.14285714285714285, -0.1020408163265306, + -0.061224489795918366, -0.020408163265306121, 0.020408163265306121, + 0.061224489795918366, 0.1020408163265306, 0.14285714285714285, + 0.18367346938775508, 0.22448979591836732, 0.26530612244897955, + 0.30612244897959179, 0.34693877551020408, 0.38775510204081631, + 0.42857142857142855, 0.46938775510204078, 0.51020408163265307, + 0.55102040816326525, 0.59183673469387754, 0.63265306122448972, + 0.673469387755102, 0.71428571428571419, 0.75510204081632648, + 0.79591836734693866, 0.836734693877551, 0.87755102040816324, + 0.91836734693877542, 0.95918367346938771, 1.0 }; + + ::coder::array b_problemDef; + ::coder::array res; + ::coder::array S_struct_FM_pop; + cell_13 b_result; + i_struct_T expl_temp; + int32_T loop_ub; + int32_T loop_ub_tmp; + packParams(problemDef, problemDefCells->f7, problemDefCells->f8, + problemDefCells->f9, problemDefCells->f10, problemDefCells->f11, + problemDefCells->f12, problemDefCells->f13, problemDefCells->f20, + problemDefLimits, &controls->checks, b_problemDef); + + // Check the bounds on all the selected + // out = checkBounds(problemDef,controls); + // if strcmp(out{1},'fail') + // return + // end + // Value to reach + expl_temp.FVr_minbound.set_size(1, problemDef->fitLimits.size(0)); + loop_ub = problemDef->fitLimits.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + expl_temp.FVr_minbound[i] = problemDef->fitLimits[i]; + } + + expl_temp.FVr_maxbound.set_size(1, problemDef->fitLimits.size(0)); + loop_ub = problemDef->fitLimits.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + expl_temp.FVr_maxbound[i] = problemDef->fitLimits[i + + problemDef->fitLimits.size(0)]; + } + + // 1: use bounds as bound constraints, 0: no bound constraints + // I_NP number of population members + // I_itermax maximum number of iterations (generations) + // fWeight DE-stepsize fWeight ex [0, 2] + // F_CR crossover probability constant ex [0, 1] + // I_strategy 1 --> DE/rand/1: + // the classical version of DE. + // 2 --> DE/local-to-best/1: + // a version which has been used by quite a number + // of scientists. Attempts a balance between robustness + // and fast convergence. + // 3 --> DE/best/1 with jitter: + // taylored for small population sizes and fast convergence. + // Dimensionality should not be too high. + // 4 --> DE/rand/1 with per-vector-dither: + // Classical DE with dither to become even more robust. + // 5 --> DE/rand/1 with per-generation-dither: + // Classical DE with dither to become even more robust. + // Choosing fWeight = 0.3 is a good start here. + // 6 --> DE/rand/1 either-or-algorithm: + // Alternates between differential mutation and three-point- + // recombination. + // I_refresh intermediate output will be produced after "I_refresh" + // iterations. No intermediate output will be produced + // if I_refresh is < 1 + // I_plotting Will use plotting if set to 1. Will skip plotting otherwise. + // -----Definition of tolerance scheme-------------------------------------- + // -----The scheme is sampled at I_lentol points---------------------------- + // ordinate running from -1 to +1 + // upper limit is 1 + // lower limit is -1 + // Tell compiler abut variable sizes + // -----tie all important values to a structure that can be passed along---- + expl_temp.FVr_x.size[0] = 1; + expl_temp.FVr_x.size[1] = 50; + std::copy(&FVr_x[0], &FVr_x[50], &expl_temp.FVr_x.data[0]); + loop_ub_tmp = static_cast(controls->populationSize); + S_struct_FM_pop.set_size(loop_ub_tmp, 2); + expl_temp.FVr_bestmem.set_size(1, 2); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + S_struct_FM_pop[i1 + S_struct_FM_pop.size(0) * i] = 0; + } + + expl_temp.FVr_bestmem[i] = 0.0; + } + + expl_temp.FM_pop.set_size(S_struct_FM_pop.size(0), 2); + loop_ub = S_struct_FM_pop.size(0); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + expl_temp.FM_pop[i1 + expl_temp.FM_pop.size(0) * i] = 0.0; + } + } + + expl_temp.I_plotting = 0.0; + expl_temp.I_refresh = 1.0; + expl_temp.I_strategy = 5.0; + expl_temp.F_VTR = controls->targetValue; + expl_temp.I_itermax = controls->numGenerations; + expl_temp.I_bnd_constr = 1.0; + expl_temp.I_D = coder::internal::intlength(problemDef->fitParams.size(0), + problemDef->fitParams.size(1)); + expl_temp.F_CR = controls->crossoverProbability; + expl_temp.fWeight = controls->fWeight; + expl_temp.I_NP = controls->populationSize; + expl_temp.FVr_lim_lo.size[0] = 1; + expl_temp.FVr_lim_lo.size[1] = 50; + expl_temp.FVr_lim_up.size[0] = 1; + expl_temp.FVr_lim_up.size[1] = 50; + for (int32_T i{0}; i < 50; i++) { + expl_temp.FVr_lim_lo.data[i] = -1.0; + expl_temp.FVr_lim_up.data[i] = 1.0; + } + + expl_temp.I_lentol.size[0] = 1; + expl_temp.I_lentol.data[0] = 50.0; + deopt(problemDef, problemDefCells->f1, problemDefCells->f2, + problemDefCells->f3, problemDefCells->f4, problemDefCells->f5, + problemDefCells->f6, problemDefCells->f14, problemDefCells->f19, + controls->parallel.data, controls->parallel.size, controls->resamPars, + controls->calcSldDuringFit, controls->display.data, + controls->display.size, &controls->checks, &expl_temp, res); + problemDef->fitParams.set_size(1, res.size(1)); + loop_ub = res.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + problemDef->fitParams[problemDef->fitParams.size(0) * i] = res[i]; + } + + unpackParams(problemDef, controls->checks.fitParam, + controls->checks.fitBackgroundParam, + controls->checks.fitQzshift, controls->checks.fitScalefactor, + controls->checks.fitBulkIn, controls->checks.fitBulkOut, + controls->checks.fitResolutionParam, + controls->checks.fitDomainRatio); + reflectivityCalculation(problemDef, problemDefCells, controls, problem, + &b_result); + result[0].f1.set_size(b_result.f1.size(0), 1); + loop_ub_tmp = b_result.f1.size(0); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + loop_ub = b_result.f1[i].f1.size(0); + result[0].f1[i].f1.set_size(b_result.f1[i].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + result[0].f1[i].f1[i2 + result[0].f1[i].f1.size(0) * i1] = + b_result.f1[i].f1[i2 + b_result.f1[i].f1.size(0) * i1]; + } + } + } + + result[1].f1.set_size(b_result.f2.size(0), 1); + loop_ub_tmp = b_result.f2.size(0); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + loop_ub = b_result.f2[i].f1.size(0); + result[1].f1[i].f1.set_size(b_result.f2[i].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + result[1].f1[i].f1[i2 + result[1].f1[i].f1.size(0) * i1] = + b_result.f2[i].f1[i2 + b_result.f2[i].f1.size(0) * i1]; + } + } + } + + result[2].f1.set_size(b_result.f3.size(0), 1); + loop_ub_tmp = b_result.f3.size(0); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + loop_ub = b_result.f3[i].f1.size(0); + result[2].f1[i].f1.set_size(b_result.f3[i].f1.size(0), 3); + for (int32_T i1{0}; i1 < 3; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + result[2].f1[i].f1[i2 + result[2].f1[i].f1.size(0) * i1] = + b_result.f3[i].f1[i2 + b_result.f3[i].f1.size(0) * i1]; + } + } + } + + result[3].f1.set_size(b_result.f4.size(0), b_result.f4.size(1)); + loop_ub = b_result.f4.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_result.f4.size(0); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + result[3].f1[i1 + result[3].f1.size(0) * i] = b_result.f4[i1 + + b_result.f4.size(0) * i]; + } + } + + result[4].f1.set_size(b_result.f5.size(0), b_result.f5.size(1)); + loop_ub = b_result.f5.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_result.f5.size(0); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + result[4].f1[i1 + result[4].f1.size(0) * i] = b_result.f5[i1 + + b_result.f5.size(0) * i]; + } + } + + result[5].f1.set_size(b_result.f6.size(0), b_result.f6.size(1)); + loop_ub = b_result.f6.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + loop_ub_tmp = b_result.f6.size(0); + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + result[5].f1[i1 + result[5].f1.size(0) * i] = b_result.f6[i1 + + b_result.f6.size(0) * i]; + } + } + + if (!coder::internal::d_strcmp(controls->display.data, + controls->display.size)) { + printf("Final chi squared is %g\n", problem->calculations.sumChi); + fflush(stdout); + } + } +} + +// End of code generation (runDE.cpp) diff --git a/RAT/runDE.h b/RAT/runDE.h new file mode 100644 index 00000000..e1366278 --- /dev/null +++ b/RAT/runDE.h @@ -0,0 +1,51 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// runDE.h +// +// Code generation for function 'runDE' +// +#ifndef RUNDE_H +#define RUNDE_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct k_struct_T; + struct cell_14; + struct struct_T; +} + +// Function Declarations +namespace RAT +{ + k_struct_T intrafun(const ::coder::array &p, struct5_T *problemDef, + const char_T controls_parallel_data[], const int32_T + controls_parallel_size[2], const real_T + controls_resamPars[2], boolean_T controls_calcSldDuringFit, + const struct3_T *controls_checks, const ::coder::array< + cell_wrap_2, 2U> &problemDefCells_f1, const ::coder::array< + cell_wrap_8, 2U> &problemDefCells_f2, const ::coder::array< + cell_wrap_2, 2U> &problemDefCells_f3, const ::coder::array< + cell_wrap_2, 2U> &problemDefCells_f4, const ::coder::array< + cell_wrap_8, 2U> &problemDefCells_f5, const ::coder::array< + cell_wrap_8, 1U> &problemDefCells_f6, const ::coder::array< + cell_wrap_1, 2U> &problemDefCells_f14, const ::coder:: + array &problemDefCells_f19); + void runDE(struct5_T *problemDef, const cell_14 *problemDefCells, const + struct1_T *problemDefLimits, const struct2_T *controls, struct_T + *problem, cell_wrap_9 result[6]); +} + +#endif + +// End of code generation (runDE.h) diff --git a/RAT/runDREAM.cpp b/RAT/runDREAM.cpp new file mode 100644 index 00000000..c499dc3e --- /dev/null +++ b/RAT/runDREAM.cpp @@ -0,0 +1,328 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// runDREAM.cpp +// +// Code generation for function 'runDREAM' +// + +// Include files +#include "runDREAM.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "getFittedPriors.h" +#include "makeEmptyBayesResultsStruct.h" +#include "mean.h" +#include "packParams.h" +#include "processBayes.h" +#include "ratDREAM.h" +#include "rt_nonfinite.h" +#include "strcmp.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include +#include + +// Function Definitions +namespace RAT +{ + void runDREAM(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct1_T *problemDefLimits, const struct2_T *controls, + const struct4_T *priors, struct5_T *outProblemDef, struct_T + *outProblem, cell_wrap_9 result[6], d_struct_T *bayesResults) + { + ::coder::array fitParamNames; + ::coder::array Par_info_max; + ::coder::array Par_info_min; + ::coder::array a__1; + ::coder::array b_bayesResults; + ::coder::array c_bayesResults; + ::coder::array r; + cell_13 b_result; + e_struct_T dreamResults_bestFitsMean; + f_struct_T dreamResults_predlims; + struct5_T b_problemDef; + int32_T b_loop_ub; + int32_T c_result; + int32_T i; + int32_T i1; + int32_T i2; + int32_T loop_ub; + + // Make an empty struct for bayesResults to hold the outputs of the + // calculation + makeEmptyBayesResultsStruct(problemDef->numberOfContrasts, coder::internal:: + b_strcmp(problemDef->TF.data, problemDef->TF.size), controls->nChains, + bayesResults->bestFitsMean.ref, bayesResults->bestFitsMean.sld, + &bayesResults->bestFitsMean.chi, bayesResults->bestFitsMean.data, + bayesResults->predlims.refPredInts, bayesResults->predlims.sldPredInts, + bayesResults->predlims.refXdata, bayesResults->predlims.sldXdata, + bayesResults->predlims.sampleChi.data, + &bayesResults->predlims.sampleChi.size[0], bayesResults->parConfInts.par95, + bayesResults->parConfInts.par65, bayesResults->parConfInts.mean, + bayesResults->bestPars, &bayesResults->bayesRes, bayesResults->chain); + + // Pre-allocation + b_problemDef = *problemDef; + packParams(&b_problemDef, problemDefCells->f7, problemDefCells->f8, + problemDefCells->f9, problemDefCells->f10, problemDefCells->f11, + problemDefCells->f12, problemDefCells->f13, problemDefCells->f20, + problemDefLimits, &controls->checks, fitParamNames); + + // Get the priors for the fitted parameters... + // Put all the RAT parameters together into one array... + // + // Get the parameters from the user + // Total number of generations + // Number of chains + // Set the relevant parameters for the DREAM sampler.... + // Dimension of the problem + // Number of Markov Chains + // Number of generations per chain + // DREAMPar.lik = 1; % Model output is likelihood + // Parallel or not... + // Jump probabilities... + // This will change... + // Initial sampling and parameter range + Par_info_min.set_size(1, b_problemDef.fitLimits.size(0)); + loop_ub = b_problemDef.fitLimits.size(0); + for (i = 0; i < loop_ub; i++) { + Par_info_min[i] = b_problemDef.fitLimits[i]; + } + + Par_info_max.set_size(1, b_problemDef.fitLimits.size(0)); + loop_ub = b_problemDef.fitLimits.size(0); + for (i = 0; i < loop_ub; i++) { + Par_info_max[i] = b_problemDef.fitLimits[i + b_problemDef.fitLimits.size(0)]; + } + + // if dreamC.prior + // end + // Run the sampler.... + // [chain,output,fx] = rat_DREAM(DREAMPar,Par_info,[],ratInputs); + // Func_name = @DREAMWrapper; + getFittedPriors(fitParamNames, priors->priorNames, priors->priorValues, + b_problemDef.fitLimits, r); + ratDREAM(static_cast(fitParamNames.size(0)), controls->nChains, std:: + ceil(controls->nSamples / controls->nChains), + controls->jumpProbability, controls->pUnitGamma, controls->adaptPCR, + Par_info_min, Par_info_max, controls->boundHandling.data, + controls->boundHandling.size, &b_problemDef, problemDefCells, + controls, r, bayesResults->bayesRes.allChains, + &bayesResults->bayesRes.dreamOutput, a__1); + + // Combine all chains.... + bayesResults->chain.set_size(0, 0); + i = static_cast(controls->nChains); + if (i - 1 >= 0) { + int32_T cutoff; + if (fitParamNames.size(0) < 1) { + b_loop_ub = 0; + } else { + b_loop_ub = fitParamNames.size(0); + } + + cutoff = static_cast(std::floor(static_cast + (bayesResults->bayesRes.allChains.size(0)) * 0.25)); + if (cutoff > bayesResults->bayesRes.allChains.size(0)) { + i1 = 0; + i2 = 0; + } else { + i1 = cutoff - 1; + i2 = bayesResults->bayesRes.allChains.size(0); + } + } + + for (int32_T b_i{0}; b_i < i; b_i++) { + int32_T c_loop_ub; + int32_T sizes_idx_0; + boolean_T empty_non_axis_sizes; + + // Keep only the last 75% of the chain.. + // Combine the parallel chains into one.... + if ((bayesResults->chain.size(0) != 0) && (bayesResults->chain.size(1) != + 0)) { + c_result = bayesResults->chain.size(1); + } else if ((i2 - i1 != 0) && (b_loop_ub != 0)) { + c_result = b_loop_ub; + } else { + c_result = bayesResults->chain.size(1); + if (b_loop_ub > bayesResults->chain.size(1)) { + c_result = b_loop_ub; + } + } + + empty_non_axis_sizes = (c_result == 0); + if (empty_non_axis_sizes || ((bayesResults->chain.size(0) != 0) && + (bayesResults->chain.size(1) != 0))) { + loop_ub = bayesResults->chain.size(0); + } else { + loop_ub = 0; + } + + if (empty_non_axis_sizes || ((i2 - i1 != 0) && (b_loop_ub != 0))) { + sizes_idx_0 = i2 - i1; + } else { + sizes_idx_0 = 0; + } + + c_loop_ub = i2 - i1; + b_bayesResults.set_size(c_loop_ub, b_loop_ub); + for (int32_T i3{0}; i3 < b_loop_ub; i3++) { + for (int32_T i4{0}; i4 < c_loop_ub; i4++) { + b_bayesResults[i4 + b_bayesResults.size(0) * i3] = + bayesResults->bayesRes.allChains[((i1 + i4) + + bayesResults->bayesRes.allChains.size(0) * i3) + + bayesResults->bayesRes.allChains.size(0) * + bayesResults->bayesRes.allChains.size(1) * b_i]; + } + } + + c_bayesResults.set_size(loop_ub + sizes_idx_0, c_result); + for (int32_T i3{0}; i3 < c_result; i3++) { + for (int32_T i4{0}; i4 < loop_ub; i4++) { + c_bayesResults[i4 + c_bayesResults.size(0) * i3] = bayesResults-> + chain[i4 + loop_ub * i3]; + } + } + + for (int32_T i3{0}; i3 < c_result; i3++) { + for (int32_T i4{0}; i4 < sizes_idx_0; i4++) { + c_bayesResults[(i4 + loop_ub) + c_bayesResults.size(0) * i3] = + b_bayesResults[i4 + sizes_idx_0 * i3]; + } + } + + bayesResults->chain.set_size(c_bayesResults.size(0), c_bayesResults.size(1)); + loop_ub = c_bayesResults.size(1); + for (int32_T i3{0}; i3 < loop_ub; i3++) { + c_loop_ub = c_bayesResults.size(0); + for (int32_T i4{0}; i4 < c_loop_ub; i4++) { + bayesResults->chain[i4 + bayesResults->chain.size(0) * i3] = + c_bayesResults[i4 + c_bayesResults.size(0) * i3]; + } + } + } + + coder::mean(bayesResults->chain, bayesResults->bestPars); + processBayes(bayesResults->bestPars, bayesResults->chain, &b_problemDef, + controls, problemDefCells, outProblemDef, outProblem, &b_result, + &dreamResults_bestFitsMean, &dreamResults_predlims, + &bayesResults->parConfInts); + result[0].f1.set_size(b_result.f1.size(0), 1); + c_result = b_result.f1.size(0); + for (i = 0; i < c_result; i++) { + loop_ub = b_result.f1[i].f1.size(0); + result[0].f1[i].f1.set_size(b_result.f1[i].f1.size(0), 2); + for (i1 = 0; i1 < 2; i1++) { + for (i2 = 0; i2 < loop_ub; i2++) { + result[0].f1[i].f1[i2 + result[0].f1[i].f1.size(0) * i1] = + b_result.f1[i].f1[i2 + b_result.f1[i].f1.size(0) * i1]; + } + } + } + + result[1].f1.set_size(b_result.f2.size(0), 1); + c_result = b_result.f2.size(0); + for (i = 0; i < c_result; i++) { + loop_ub = b_result.f2[i].f1.size(0); + result[1].f1[i].f1.set_size(b_result.f2[i].f1.size(0), 2); + for (i1 = 0; i1 < 2; i1++) { + for (i2 = 0; i2 < loop_ub; i2++) { + result[1].f1[i].f1[i2 + result[1].f1[i].f1.size(0) * i1] = + b_result.f2[i].f1[i2 + b_result.f2[i].f1.size(0) * i1]; + } + } + } + + result[2].f1.set_size(b_result.f3.size(0), 1); + c_result = b_result.f3.size(0); + for (i = 0; i < c_result; i++) { + loop_ub = b_result.f3[i].f1.size(0); + result[2].f1[i].f1.set_size(b_result.f3[i].f1.size(0), 3); + for (i1 = 0; i1 < 3; i1++) { + for (i2 = 0; i2 < loop_ub; i2++) { + result[2].f1[i].f1[i2 + result[2].f1[i].f1.size(0) * i1] = + b_result.f3[i].f1[i2 + b_result.f3[i].f1.size(0) * i1]; + } + } + } + + result[3].f1.set_size(b_result.f4.size(0), b_result.f4.size(1)); + loop_ub = b_result.f4.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = b_result.f4.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + result[3].f1[i1 + result[3].f1.size(0) * i] = b_result.f4[i1 + + b_result.f4.size(0) * i]; + } + } + + result[4].f1.set_size(b_result.f5.size(0), b_result.f5.size(1)); + loop_ub = b_result.f5.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = b_result.f5.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + result[4].f1[i1 + result[4].f1.size(0) * i] = b_result.f5[i1 + + b_result.f5.size(0) * i]; + } + } + + result[5].f1.set_size(b_result.f6.size(0), b_result.f6.size(1)); + loop_ub = b_result.f6.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = b_result.f6.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + result[5].f1[i1 + result[5].f1.size(0) * i] = b_result.f6[i1 + + b_result.f6.size(0) * i]; + } + } + + // Populate the output struct + // bayesResults.bayesRes.allChains = chain; + cast(dreamResults_predlims.refPredInts, bayesResults->predlims.refPredInts); + cast(dreamResults_predlims.sldPredInts, bayesResults->predlims.sldPredInts); + cast(dreamResults_predlims.refXdata, bayesResults->predlims.refXdata); + bayesResults->predlims.sldXdata.set_size(dreamResults_predlims.sldXdata.size + (0), 1); + for (i = 0; i < dreamResults_predlims.sldXdata.size(0); i++) { + bayesResults->predlims.sldXdata[i].f1.set_size(1, + dreamResults_predlims.sldXdata[i].f1.size(1)); + loop_ub = dreamResults_predlims.sldXdata[i].f1.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + bayesResults->predlims.sldXdata[i].f1[bayesResults->predlims.sldXdata[i] + .f1.size(0) * i1] = dreamResults_predlims.sldXdata[i].f1[i1]; + } + } + + bayesResults->predlims.sampleChi.size[0] = 1000; + std::copy(&dreamResults_predlims.sampleChi[0], + &dreamResults_predlims.sampleChi[1000], + &bayesResults->predlims.sampleChi.data[0]); + cast(dreamResults_bestFitsMean.ref, bayesResults->bestFitsMean.ref); + bayesResults->bestFitsMean.sld.set_size(dreamResults_bestFitsMean.sld.size(0), + dreamResults_bestFitsMean.sld.size(1)); + loop_ub = dreamResults_bestFitsMean.sld.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = dreamResults_bestFitsMean.sld.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + bayesResults->bestFitsMean.sld[i1 + bayesResults->bestFitsMean.sld.size + (0) * i] = dreamResults_bestFitsMean.sld[i1 + + dreamResults_bestFitsMean.sld.size(0) * i]; + } + } + + bayesResults->bestFitsMean.chi = dreamResults_bestFitsMean.chi; + cast(dreamResults_bestFitsMean.data, bayesResults->bestFitsMean.data); + + // These are not defined in makeEmptyBayesResultsStruct + // bayesResults.bayesRes.DREAMPar = DREAMPar; + // bayesResults.bayesRes.Meas_info = Meas_info; + // bayesResults.bayesRes.dreamOutput = output; + } +} + +// End of code generation (runDREAM.cpp) diff --git a/RAT/runDREAM.h b/RAT/runDREAM.h new file mode 100644 index 00000000..997eab1b --- /dev/null +++ b/RAT/runDREAM.h @@ -0,0 +1,42 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// runDREAM.h +// +// Code generation for function 'runDREAM' +// +#ifndef RUNDREAM_H +#define RUNDREAM_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct cell_14; + struct struct1_T; + struct struct2_T; + struct struct4_T; + struct struct_T; + struct cell_wrap_9; + struct d_struct_T; +} + +// Function Declarations +namespace RAT +{ + void runDREAM(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct1_T *problemDefLimits, const struct2_T *controls, + const struct4_T *priors, struct5_T *outProblemDef, struct_T + *outProblem, cell_wrap_9 result[6], d_struct_T *bayesResults); +} + +#endif + +// End of code generation (runDREAM.h) diff --git a/RAT/runNestedSampler.cpp b/RAT/runNestedSampler.cpp new file mode 100644 index 00000000..f46bd8d0 --- /dev/null +++ b/RAT/runNestedSampler.cpp @@ -0,0 +1,273 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// runNestedSampler.cpp +// +// Code generation for function 'runNestedSampler' +// + +// Include files +#include "runNestedSampler.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "blockedSummation.h" +#include "getFittedPriors.h" +#include "makeEmptyBayesResultsStruct.h" +#include "mean.h" +#include "nestedSampler.h" +#include "packParams.h" +#include "processBayes.h" +#include "rt_nonfinite.h" +#include "strcmp.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include + +// Function Definitions +namespace RAT +{ + void runNestedSampler(struct5_T *problemDef, const cell_14 *problemDefCells, + const struct1_T *problemDefLimits, const struct2_T + *controls, const struct4_T *inPriors, struct_T + *outProblem, cell_wrap_9 result[6], struct8_T + *bayesResults) + { + ::coder::array fitNames; + ::coder::array expl_temp_sld; + ::coder::array expl_temp_data; + ::coder::array expl_temp_ref; + ::coder::array t9_predlims_refPredInts; + ::coder::array t9_predlims_refXdata; + ::coder::array t9_predlims_sldPredInts; + ::coder::array b_expl_temp; + ::coder::array bayesOutputs_chain; + ::coder::array chain; + ::coder::array expl_temp; + ::coder::array expl_temp_mean; + ::coder::array expl_temp_par65; + ::coder::array expl_temp_par95; + ::coder::array r; + ::coder::array r1; + c_struct_T t9_bayesRes; + cell_13 b_result; + e_struct_T nestResults_bestFitsMean; + f_struct_T nestResults_predlims; + struct5_T b_problemDef; + real_T t9_predlims_sampleChi_data[1000]; + real_T H; + real_T expl_temp_chi; + real_T logZ; + int32_T b_loop_ub; + int32_T loop_ub; + int32_T t9_predlims_sampleChi_size; + packParams(problemDef, problemDefCells->f7, problemDefCells->f8, + problemDefCells->f9, problemDefCells->f10, problemDefCells->f11, + problemDefCells->f12, problemDefCells->f13, problemDefCells->f20, + problemDefLimits, &controls->checks, fitNames); + + // Make an empty struct for bayesResults to hold the outputs of the + // calculation + b_makeEmptyBayesResultsStruct(problemDef->numberOfContrasts, coder::internal:: + b_strcmp(problemDef->TF.data, problemDef->TF.size), expl_temp_ref, + expl_temp_sld, &expl_temp_chi, expl_temp_data, t9_predlims_refPredInts, + t9_predlims_sldPredInts, t9_predlims_refXdata, + bayesResults->predlims.sldXdata, t9_predlims_sampleChi_data, + &t9_predlims_sampleChi_size, expl_temp_par95, expl_temp_par65, + expl_temp_mean, expl_temp, &t9_bayesRes, b_expl_temp); + bayesResults->bayesRes.allChains.set_size(t9_bayesRes.allChains.size(0), + t9_bayesRes.allChains.size(1), t9_bayesRes.allChains.size(2)); + loop_ub = t9_bayesRes.allChains.size(2); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = t9_bayesRes.allChains.size(1); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + t9_predlims_sampleChi_size = t9_bayesRes.allChains.size(0); + for (int32_T i2{0}; i2 < t9_predlims_sampleChi_size; i2++) { + bayesResults->bayesRes.allChains[(i2 + + bayesResults->bayesRes.allChains.size(0) * i1) + + bayesResults->bayesRes.allChains.size(0) * + bayesResults->bayesRes.allChains.size(1) * i] = + t9_bayesRes.allChains[(i2 + t9_bayesRes.allChains.size(0) * i1) + + t9_bayesRes.allChains.size(0) * t9_bayesRes.allChains.size(1) * i]; + } + } + } + + bayesResults->bayesRes.dreamOutput = t9_bayesRes.dreamOutput; + + // Deal with priors. + // Tuning Parameters + getFittedPriors(fitNames, inPriors->priorNames, inPriors->priorValues, + problemDef->fitLimits, r); + nestedSampler(problemDef, controls, problemDefCells, controls->Nlive, + controls->Nmcmc, controls->nsTolerance, r, &logZ, + bayesResults->bayesRes.nestOutput.nestSamples, + bayesResults->bayesRes.nestOutput.postSamples, &H); + + // Process the results... + // chain = nest_samples(:,1:end-1); + if (fitNames.size(0) < 1) { + loop_ub = 0; + } else { + loop_ub = fitNames.size(0); + } + + chain.set_size(bayesResults->bayesRes.nestOutput.postSamples.size(0), + loop_ub); + bayesOutputs_chain.set_size + (bayesResults->bayesRes.nestOutput.postSamples.size(0), loop_ub); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = bayesResults->bayesRes.nestOutput.postSamples.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + chain[i1 + chain.size(0) * i] = + bayesResults->bayesRes.nestOutput.postSamples[i1 + + bayesResults->bayesRes.nestOutput.postSamples.size(0) * i]; + } + + b_loop_ub = bayesResults->bayesRes.nestOutput.postSamples.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + bayesOutputs_chain[i1 + bayesOutputs_chain.size(0) * i] = + bayesResults->bayesRes.nestOutput.postSamples[i1 + + bayesResults->bayesRes.nestOutput.postSamples.size(0) * i]; + } + } + + int32_T iv[2]; + coder::mean(chain, r1); + b_problemDef = *problemDef; + iv[0] = (*(int32_T (*)[2])r1.size())[0]; + iv[1] = (*(int32_T (*)[2])r1.size())[1]; + processBayes((const real_T *)r1.data(), iv, bayesOutputs_chain, + &b_problemDef, controls, problemDefCells, problemDef, + outProblem, &b_result, &nestResults_bestFitsMean, + &nestResults_predlims, &bayesResults->parConfInts); + result[0].f1.set_size(b_result.f1.size(0), 1); + t9_predlims_sampleChi_size = b_result.f1.size(0); + for (int32_T i{0}; i < t9_predlims_sampleChi_size; i++) { + b_loop_ub = b_result.f1[i].f1.size(0); + result[0].f1[i].f1.set_size(b_result.f1[i].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + result[0].f1[i].f1[i2 + result[0].f1[i].f1.size(0) * i1] = + b_result.f1[i].f1[i2 + b_result.f1[i].f1.size(0) * i1]; + } + } + } + + result[1].f1.set_size(b_result.f2.size(0), 1); + t9_predlims_sampleChi_size = b_result.f2.size(0); + for (int32_T i{0}; i < t9_predlims_sampleChi_size; i++) { + b_loop_ub = b_result.f2[i].f1.size(0); + result[1].f1[i].f1.set_size(b_result.f2[i].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + result[1].f1[i].f1[i2 + result[1].f1[i].f1.size(0) * i1] = + b_result.f2[i].f1[i2 + b_result.f2[i].f1.size(0) * i1]; + } + } + } + + result[2].f1.set_size(b_result.f3.size(0), 1); + t9_predlims_sampleChi_size = b_result.f3.size(0); + for (int32_T i{0}; i < t9_predlims_sampleChi_size; i++) { + b_loop_ub = b_result.f3[i].f1.size(0); + result[2].f1[i].f1.set_size(b_result.f3[i].f1.size(0), 3); + for (int32_T i1{0}; i1 < 3; i1++) { + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + result[2].f1[i].f1[i2 + result[2].f1[i].f1.size(0) * i1] = + b_result.f3[i].f1[i2 + b_result.f3[i].f1.size(0) * i1]; + } + } + } + + result[3].f1.set_size(b_result.f4.size(0), b_result.f4.size(1)); + b_loop_ub = b_result.f4.size(1); + for (int32_T i{0}; i < b_loop_ub; i++) { + t9_predlims_sampleChi_size = b_result.f4.size(0); + for (int32_T i1{0}; i1 < t9_predlims_sampleChi_size; i1++) { + result[3].f1[i1 + result[3].f1.size(0) * i] = b_result.f4[i1 + + b_result.f4.size(0) * i]; + } + } + + result[4].f1.set_size(b_result.f5.size(0), b_result.f5.size(1)); + b_loop_ub = b_result.f5.size(1); + for (int32_T i{0}; i < b_loop_ub; i++) { + t9_predlims_sampleChi_size = b_result.f5.size(0); + for (int32_T i1{0}; i1 < t9_predlims_sampleChi_size; i1++) { + result[4].f1[i1 + result[4].f1.size(0) * i] = b_result.f5[i1 + + b_result.f5.size(0) * i]; + } + } + + result[5].f1.set_size(b_result.f6.size(0), b_result.f6.size(1)); + b_loop_ub = b_result.f6.size(1); + for (int32_T i{0}; i < b_loop_ub; i++) { + t9_predlims_sampleChi_size = b_result.f6.size(0); + for (int32_T i1{0}; i1 < t9_predlims_sampleChi_size; i1++) { + result[5].f1[i1 + result[5].f1.size(0) * i] = b_result.f6[i1 + + b_result.f6.size(0) * i]; + } + } + + cast(nestResults_predlims.refPredInts, bayesResults->predlims.refPredInts); + cast(nestResults_predlims.sldPredInts, bayesResults->predlims.sldPredInts); + cast(nestResults_predlims.refXdata, bayesResults->predlims.refXdata); + bayesResults->predlims.sldXdata.set_size(nestResults_predlims.sldXdata.size + (0), 1); + for (int32_T i{0}; i < nestResults_predlims.sldXdata.size(0); i++) { + bayesResults->predlims.sldXdata[i].f1.set_size(1, + nestResults_predlims.sldXdata[i].f1.size(1)); + b_loop_ub = nestResults_predlims.sldXdata[i].f1.size(1); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + bayesResults->predlims.sldXdata[i].f1[bayesResults->predlims.sldXdata[i] + .f1.size(0) * i1] = nestResults_predlims.sldXdata[i].f1[i1]; + } + } + + bayesResults->predlims.sampleChi.size[0] = 1000; + std::copy(&nestResults_predlims.sampleChi[0], + &nestResults_predlims.sampleChi[1000], + &bayesResults->predlims.sampleChi.data[0]); + cast(nestResults_bestFitsMean.ref, bayesResults->bestFitsMean.ref); + bayesResults->bestFitsMean.sld.set_size(nestResults_bestFitsMean.sld.size(0), + nestResults_bestFitsMean.sld.size(1)); + b_loop_ub = nestResults_bestFitsMean.sld.size(1); + for (int32_T i{0}; i < b_loop_ub; i++) { + t9_predlims_sampleChi_size = nestResults_bestFitsMean.sld.size(0); + for (int32_T i1{0}; i1 < t9_predlims_sampleChi_size; i1++) { + bayesResults->bestFitsMean.sld[i1 + bayesResults->bestFitsMean.sld.size + (0) * i] = nestResults_bestFitsMean.sld[i1 + + nestResults_bestFitsMean.sld.size(0) * i]; + } + } + + bayesResults->bestFitsMean.chi = nestResults_bestFitsMean.chi; + cast(nestResults_bestFitsMean.data, bayesResults->bestFitsMean.data); + coder::blockedSummation(chain, + bayesResults->bayesRes.nestOutput.postSamples.size(0), r1); + bayesResults->bestPars.set_size(1, r1.size(1)); + b_loop_ub = r1.size(1); + for (int32_T i{0}; i < b_loop_ub; i++) { + bayesResults->bestPars[i] = r1[i] / static_cast + (bayesResults->bayesRes.nestOutput.postSamples.size(0)); + } + + bayesResults->chain.set_size + (bayesResults->bayesRes.nestOutput.postSamples.size(0), loop_ub); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = bayesResults->bayesRes.nestOutput.postSamples.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + bayesResults->chain[i1 + bayesResults->chain.size(0) * i] = + bayesResults->bayesRes.nestOutput.postSamples[i1 + + bayesResults->bayesRes.nestOutput.postSamples.size(0) * i]; + } + } + + bayesResults->bayesRes.nestOutput.LogZ = logZ; + } +} + +// End of code generation (runNestedSampler.cpp) diff --git a/RAT/runNestedSampler.h b/RAT/runNestedSampler.h new file mode 100644 index 00000000..245a3fc5 --- /dev/null +++ b/RAT/runNestedSampler.h @@ -0,0 +1,43 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// runNestedSampler.h +// +// Code generation for function 'runNestedSampler' +// +#ifndef RUNNESTEDSAMPLER_H +#define RUNNESTEDSAMPLER_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct cell_14; + struct struct1_T; + struct struct2_T; + struct struct4_T; + struct struct_T; + struct cell_wrap_9; + struct struct8_T; +} + +// Function Declarations +namespace RAT +{ + void runNestedSampler(struct5_T *problemDef, const cell_14 *problemDefCells, + const struct1_T *problemDefLimits, const struct2_T + *controls, const struct4_T *inPriors, struct_T + *outProblem, cell_wrap_9 result[6], struct8_T + *bayesResults); +} + +#endif + +// End of code generation (runNestedSampler.h) diff --git a/RAT/runSimplex.cpp b/RAT/runSimplex.cpp new file mode 100644 index 00000000..15979c21 --- /dev/null +++ b/RAT/runSimplex.cpp @@ -0,0 +1,324 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// runSimplex.cpp +// +// Code generation for function 'runSimplex' +// + +// Include files +#include "runSimplex.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "fMinSearch.h" +#include "packParams.h" +#include "reflectivityCalculation.h" +#include "rt_nonfinite.h" +#include "simplexXTransform.h" +#include "strcmp.h" +#include "unpackParams.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include + +// Function Definitions +namespace RAT +{ + void runSimplex(struct5_T *problemDef, const cell_14 *problemDefCells, const + struct1_T *problemDefLimits, const struct2_T *controls, + struct_T *problem, cell_wrap_9 result[6]) + { + static const char_T b_cv1[6]{ 'n', 'o', 't', 'i', 'f', 'y' }; + + static const char_T b_cv[5]{ 'f', 'i', 'n', 'a', 'l' }; + + ::coder::array b_problemDef; + ::coder::array x; + ::coder::array x0u; + cell_13 b_result; + h_struct_T a__4; + j_struct_T expl_temp; + real_T a__2; + real_T a__3; + int32_T dis_size[2]; + int32_T i; + int32_T loop_ub; + int32_T outsize_idx_0; + char_T dis_data[6]; + packParams(problemDef, problemDefCells->f7, problemDefCells->f8, + problemDefCells->f9, problemDefCells->f10, problemDefCells->f11, + problemDefCells->f12, problemDefCells->f13, problemDefCells->f20, + problemDefLimits, &controls->checks, b_problemDef); + + // Check the bounds on all the selected + // out = checkBounds(problemDef,controls); + // if strcmp(out{1},'fail') + // return + // end + if (coder::internal::r_strcmp(controls->display.data, controls->display.size)) + { + outsize_idx_0 = 0; + } else if (coder::internal::s_strcmp(controls->display.data, + controls->display.size)) { + outsize_idx_0 = 1; + } else if (coder::internal::t_strcmp(controls->display.data, + controls->display.size)) { + outsize_idx_0 = 2; + } else if (coder::internal::u_strcmp(controls->display.data, + controls->display.size)) { + outsize_idx_0 = 3; + } else { + outsize_idx_0 = -1; + } + + switch (outsize_idx_0) { + case 0: + dis_size[0] = 1; + dis_size[1] = 4; + dis_data[0] = 'n'; + dis_data[1] = 'o'; + dis_data[2] = 'n'; + dis_data[3] = 'e'; + break; + + case 1: + dis_size[0] = 1; + dis_size[1] = 4; + dis_data[0] = 'i'; + dis_data[1] = 't'; + dis_data[2] = 'e'; + dis_data[3] = 'r'; + break; + + case 2: + dis_size[0] = 1; + dis_size[1] = 6; + for (i = 0; i < 6; i++) { + dis_data[i] = b_cv1[i]; + } + break; + + case 3: + dis_size[0] = 1; + dis_size[1] = 5; + for (i = 0; i < 5; i++) { + dis_data[i] = b_cv[i]; + } + break; + + default: + dis_size[0] = 1; + dis_size[1] = 5; + for (i = 0; i < 5; i++) { + dis_data[i] = b_cv[i]; + } + break; + } + + expl_temp.LB.set_size(problemDef->fitLimits.size(0)); + loop_ub = problemDef->fitLimits.size(0); + for (i = 0; i < loop_ub; i++) { + expl_temp.LB[i] = problemDef->fitLimits[i]; + } + + expl_temp.UB.set_size(problemDef->fitLimits.size(0)); + loop_ub = problemDef->fitLimits.size(0); + for (i = 0; i < loop_ub; i++) { + expl_temp.UB[i] = problemDef->fitLimits[i + problemDef->fitLimits.size(0)]; + } + + // size checks + if (problemDef->fitLimits.size(0) == 0) { + outsize_idx_0 = problemDef->fitParams.size(0) * problemDef->fitParams.size + (1); + expl_temp.LB.set_size(outsize_idx_0); + for (i = 0; i < outsize_idx_0; i++) { + expl_temp.LB[i] = rtMinusInf; + } + } + + if (problemDef->fitLimits.size(0) == 0) { + outsize_idx_0 = problemDef->fitParams.size(0) * problemDef->fitParams.size + (1); + expl_temp.UB.set_size(outsize_idx_0); + for (i = 0; i < outsize_idx_0; i++) { + expl_temp.UB[i] = rtInf; + } + } + + // stuff into a struct to pass around + // varargin; + // problemDef.modelFilename;%fun; + // 0 --> unconstrained variable + // 1 --> lower bound only + // 2 --> upper bound only + // 3 --> dual finite bounds + outsize_idx_0 = problemDef->fitParams.size(0) * problemDef->fitParams.size(1); + expl_temp.BoundClass.set_size(outsize_idx_0); + for (i = 0; i < outsize_idx_0; i++) { + expl_temp.BoundClass[i] = 0.0; + } + + i = problemDef->fitParams.size(0) * problemDef->fitParams.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + expl_temp.BoundClass[b_i] = static_cast((!std::isinf + (expl_temp.LB[b_i])) && (!std::isnan(expl_temp.LB[b_i]))) + static_cast< + real_T>(((!std::isinf(expl_temp.UB[b_i])) && (!std::isnan + (expl_temp.UB[b_i]))) << 1); + } + + // transform starting values into their unconstrained + // surrogates. Check for infeasible starting guesses. + outsize_idx_0 = problemDef->fitParams.size(0) * problemDef->fitParams.size(1); + x0u.set_size(outsize_idx_0); + for (i = 0; i < outsize_idx_0; i++) { + x0u[i] = problemDef->fitParams[i]; + } + + i = problemDef->fitParams.size(0) * problemDef->fitParams.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + switch (static_cast(expl_temp.BoundClass[b_i])) { + case 1: + // lower bound only + if (problemDef->fitParams[b_i] <= expl_temp.LB[b_i]) { + // infeasible starting value. Use bound. + x0u[b_i] = 0.0; + } else { + x0u[b_i] = std::sqrt(problemDef->fitParams[b_i] - expl_temp.LB[b_i]); + } + break; + + case 2: + // upper bound only + if (problemDef->fitParams[b_i] >= expl_temp.UB[b_i]) { + // infeasible starting value. use bound. + x0u[b_i] = 0.0; + } else { + x0u[b_i] = std::sqrt(expl_temp.UB[b_i] - problemDef->fitParams[b_i]); + } + break; + + case 3: + // lower and upper bounds + if (problemDef->fitParams[b_i] <= expl_temp.LB[b_i]) { + // infeasible starting value + x0u[b_i] = -1.5707963267948966; + } else if (problemDef->fitParams[b_i] >= expl_temp.UB[b_i]) { + // infeasible starting value + x0u[b_i] = 1.5707963267948966; + } else { + x0u[b_i] = std::asin(std::fmax(-1.0, std::fmin(1.0, 2.0 * + (problemDef->fitParams[b_i] - expl_temp.LB[b_i]) / (expl_temp.UB[b_i] + - expl_temp.LB[b_i]) - 1.0))); + } + break; + + default: + // unconstrained variable. x0u(i) is set. + break; + } + } + + // now we can call fminsearch, but with our own + // intra-objective function. + fMinSearch(x0u, controls->maxIter, controls->maxFunEvals, controls->tolX, + controls->tolFun, dis_data, dis_size, problemDef, + problemDefCells->f1, problemDefCells->f2, problemDefCells->f3, + problemDefCells->f4, problemDefCells->f5, problemDefCells->f6, + problemDefCells->f14, problemDefCells->f19, controls, &expl_temp, + &a__2, &a__3, &a__4); + + // [xu,fval,exitflag,output] = simplex(@simplexIntrafun,x0u,problemDef,problemDefCells,problemDefLimits,controls,options,params,300); + // undo the variable transformations into the original space + simplexXTransform(x0u, expl_temp.LB, expl_temp.UB, expl_temp.BoundClass, x); + + // final reshape + // x = reshape(x,xsize); + outsize_idx_0 = x.size(0); + problemDef->fitParams.set_size(x.size(0), 1); + for (i = 0; i < outsize_idx_0; i++) { + problemDef->fitParams[i] = x[i]; + } + + unpackParams(problemDef, controls->checks.fitParam, + controls->checks.fitBackgroundParam, + controls->checks.fitQzshift, controls->checks.fitScalefactor, + controls->checks.fitBulkIn, controls->checks.fitBulkOut, + controls->checks.fitResolutionParam, + controls->checks.fitDomainRatio); + reflectivityCalculation(problemDef, problemDefCells, controls, problem, + &b_result); + result[0].f1.set_size(b_result.f1.size(0), 1); + outsize_idx_0 = b_result.f1.size(0); + for (i = 0; i < outsize_idx_0; i++) { + loop_ub = b_result.f1[i].f1.size(0); + result[0].f1[i].f1.set_size(b_result.f1[i].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + result[0].f1[i].f1[i2 + result[0].f1[i].f1.size(0) * i1] = + b_result.f1[i].f1[i2 + b_result.f1[i].f1.size(0) * i1]; + } + } + } + + result[1].f1.set_size(b_result.f2.size(0), 1); + outsize_idx_0 = b_result.f2.size(0); + for (i = 0; i < outsize_idx_0; i++) { + loop_ub = b_result.f2[i].f1.size(0); + result[1].f1[i].f1.set_size(b_result.f2[i].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + result[1].f1[i].f1[i2 + result[1].f1[i].f1.size(0) * i1] = + b_result.f2[i].f1[i2 + b_result.f2[i].f1.size(0) * i1]; + } + } + } + + result[2].f1.set_size(b_result.f3.size(0), 1); + outsize_idx_0 = b_result.f3.size(0); + for (i = 0; i < outsize_idx_0; i++) { + loop_ub = b_result.f3[i].f1.size(0); + result[2].f1[i].f1.set_size(b_result.f3[i].f1.size(0), 3); + for (int32_T i1{0}; i1 < 3; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + result[2].f1[i].f1[i2 + result[2].f1[i].f1.size(0) * i1] = + b_result.f3[i].f1[i2 + b_result.f3[i].f1.size(0) * i1]; + } + } + } + + result[3].f1.set_size(b_result.f4.size(0), b_result.f4.size(1)); + loop_ub = b_result.f4.size(1); + for (i = 0; i < loop_ub; i++) { + outsize_idx_0 = b_result.f4.size(0); + for (int32_T i1{0}; i1 < outsize_idx_0; i1++) { + result[3].f1[i1 + result[3].f1.size(0) * i] = b_result.f4[i1 + + b_result.f4.size(0) * i]; + } + } + + result[4].f1.set_size(b_result.f5.size(0), b_result.f5.size(1)); + loop_ub = b_result.f5.size(1); + for (i = 0; i < loop_ub; i++) { + outsize_idx_0 = b_result.f5.size(0); + for (int32_T i1{0}; i1 < outsize_idx_0; i1++) { + result[4].f1[i1 + result[4].f1.size(0) * i] = b_result.f5[i1 + + b_result.f5.size(0) * i]; + } + } + + result[5].f1.set_size(b_result.f6.size(0), b_result.f6.size(1)); + loop_ub = b_result.f6.size(1); + for (i = 0; i < loop_ub; i++) { + outsize_idx_0 = b_result.f6.size(0); + for (int32_T i1{0}; i1 < outsize_idx_0; i1++) { + result[5].f1[i1 + result[5].f1.size(0) * i] = b_result.f6[i1 + + b_result.f6.size(0) * i]; + } + } + } +} + +// End of code generation (runSimplex.cpp) diff --git a/RAT/runSimplex.h b/RAT/runSimplex.h new file mode 100644 index 00000000..f293b5ab --- /dev/null +++ b/RAT/runSimplex.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// runSimplex.h +// +// Code generation for function 'runSimplex' +// +#ifndef RUNSIMPLEX_H +#define RUNSIMPLEX_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; + struct cell_14; + struct struct1_T; + struct struct2_T; + struct struct_T; + struct cell_wrap_9; +} + +// Function Declarations +namespace RAT +{ + void runSimplex(struct5_T *problemDef, const cell_14 *problemDefCells, const + struct1_T *problemDefLimits, const struct2_T *controls, + struct_T *problem, cell_wrap_9 result[6]); +} + +#endif + +// End of code generation (runSimplex.h) diff --git a/RAT/scaleParameters.cpp b/RAT/scaleParameters.cpp new file mode 100644 index 00000000..14313a3a --- /dev/null +++ b/RAT/scaleParameters.cpp @@ -0,0 +1,78 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// scaleParameters.cpp +// +// Code generation for function 'scaleParameters' +// + +// Include files +#include "scaleParameters.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void scaleParameters(const ::coder::array &prior, const ::coder:: + array ¶ms, ::coder::array + &scaled) + { + int32_T i; + int32_T loop_ub; + + // scaled = scaleParameters(prior, params) + // + // This function will scale parameters based on their priors. If a prior is + // uniform over a range then the parameter will be scaled, such that the + // range covers 0->1. If a prior is Gaussian then the parameter will be + // scaled such that it will be a Gaussian with zero mean and unit variance. + scaled.set_size(params.size(1)); + loop_ub = params.size(1); + for (i = 0; i < loop_ub; i++) { + scaled[i] = 0.0; + } + + i = params.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T priortype; + priortype = prior[b_i]; + if (priortype == 1.0) { + real_T p3; + + // uniform + p3 = prior[b_i + prior.size(0) * 3]; + scaled[b_i] = (params[b_i] - p3) / (prior[b_i + prior.size(0) * 4] - p3); + } else if (priortype == 2.0) { + // gaussian + scaled[b_i] = (params[b_i] - prior[b_i + prior.size(0)]) / prior[b_i + + prior.size(0) * 2]; + } else if (priortype == 3.0) { + real_T scaled_tmp; + + // jeffreys + scaled_tmp = std::log10(prior[b_i + prior.size(0)]); + scaled[b_i] = (std::log10(params[b_i]) - scaled_tmp) / (std::log10 + (prior[b_i + prior.size(0) * 2]) - scaled_tmp); + } + } + + // priortype = char(prior(i,2)); + // p3 = prior{i,3}; + // p4 = prior{i,4}; + // + // % currently only handles uniform or Gaussian priors + // if strcmp(priortype, 'uniform') + // scaled(i) = (params(i) - p3)/(p4 - p3); + // elseif strcmp(priortype, 'gaussian') + // scaled(i) = (params(i) - p3)/p4; + // elseif strcmp(priortype, 'jeffreys') + // scaled(i) = (log10(params(i)) - log10(p3))/(log10(p4) - log10(p3)); + // end + } +} + +// End of code generation (scaleParameters.cpp) diff --git a/RAT/scaleParameters.h b/RAT/scaleParameters.h new file mode 100644 index 00000000..f17bcf29 --- /dev/null +++ b/RAT/scaleParameters.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// scaleParameters.h +// +// Code generation for function 'scaleParameters' +// +#ifndef SCALEPARAMETERS_H +#define SCALEPARAMETERS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void scaleParameters(const ::coder::array &prior, const ::coder:: + array ¶ms, ::coder::array + &scaled); +} + +#endif + +// End of code generation (scaleParameters.h) diff --git a/RAT/scaledGaussPrior.cpp b/RAT/scaledGaussPrior.cpp new file mode 100644 index 00000000..29ec49cd --- /dev/null +++ b/RAT/scaledGaussPrior.cpp @@ -0,0 +1,156 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// scaledGaussPrior.cpp +// +// Code generation for function 'scaledGaussPrior' +// + +// Include files +#include "scaledGaussPrior.h" +#include "find.h" +#include "rescale.h" +#include "rt_nonfinite.h" +#include "sum.h" +#include "unsafeSxfun.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + real_T scaledGaussPrior(const ::coder::array &m, const ::coder:: + array &extras_problemDef_fitLimits, const ::coder::array &extras_priors) + { + ::coder::array usedConstr; + ::coder::array usedPriors; + ::coder::array b_m; + ::coder::array b_usedConstr; + ::coder::array c_usedConstr; + ::coder::array r; + ::coder::array r1; + ::coder::array r2; + ::coder::array usedPriorInd; + ::coder::array b_extras_priors; + real_T pVal2; + int32_T i; + int32_T loop_ub; + + // All are in range, so check for Gaussian priors.... + // We pick out any priors that are Gaussians and calculate the mvnpdf + // Find all the Gaussian priors.... + // usedPriorInd = find(strcmpi(priorList(:,1),'gaussian')); + b_extras_priors.set_size(extras_priors.size(0)); + loop_ub = extras_priors.size(0); + for (i = 0; i < loop_ub; i++) { + b_extras_priors[i] = (extras_priors[i] == 2.0); + } + + coder::eml_find(b_extras_priors, usedPriorInd); + usedPriors.set_size(usedPriorInd.size(0), 5); + loop_ub = usedPriorInd.size(0); + for (i = 0; i < 5; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + usedPriors[i1 + usedPriors.size(0) * i] = extras_priors[(usedPriorInd[i1] + + extras_priors.size(0) * i) - 1]; + } + } + + usedConstr.set_size(usedPriorInd.size(0), 2); + loop_ub = usedPriorInd.size(0); + for (i = 0; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + usedConstr[i1 + usedConstr.size(0) * i] = extras_problemDef_fitLimits + [(usedPriorInd[i1] + extras_problemDef_fitLimits.size(0) * i) - 1]; + } + } + + if (usedPriorInd.size(0) != 0) { + // There may be no Gaussian priors defined! + // Scale (minVal+prior) will give scaled sigma since minVal goes to 0... + b_m.set_size(usedPriorInd.size(0)); + loop_ub = usedPriorInd.size(0); + for (i = 0; i < loop_ub; i++) { + b_m[i] = m[usedPriorInd[i] - 1]; + } + + b_usedConstr.set_size(usedPriorInd.size(0)); + loop_ub = usedPriorInd.size(0); + for (i = 0; i < loop_ub; i++) { + b_usedConstr[i] = usedConstr[i]; + } + + c_usedConstr.set_size(usedPriorInd.size(0)); + loop_ub = usedPriorInd.size(0); + for (i = 0; i < loop_ub; i++) { + c_usedConstr[i] = usedConstr[i + usedConstr.size(0)]; + } + + coder::rescale(b_m, b_usedConstr, c_usedConstr, r); + b_m.set_size(usedPriorInd.size(0)); + loop_ub = usedPriorInd.size(0); + for (i = 0; i < loop_ub; i++) { + b_m[i] = usedPriors[i + usedPriors.size(0)]; + } + + b_usedConstr.set_size(usedPriorInd.size(0)); + loop_ub = usedPriorInd.size(0); + for (i = 0; i < loop_ub; i++) { + b_usedConstr[i] = usedConstr[i]; + } + + c_usedConstr.set_size(usedPriorInd.size(0)); + loop_ub = usedPriorInd.size(0); + for (i = 0; i < loop_ub; i++) { + c_usedConstr[i] = usedConstr[i + usedConstr.size(0)]; + } + + coder::rescale(b_m, b_usedConstr, c_usedConstr, r1); + b_m.set_size(usedPriorInd.size(0)); + loop_ub = usedPriorInd.size(0); + for (i = 0; i < loop_ub; i++) { + b_m[i] = usedPriors[i + usedPriors.size(0) * 2] + usedConstr[i]; + } + + b_usedConstr.set_size(usedPriorInd.size(0)); + loop_ub = usedPriorInd.size(0); + for (i = 0; i < loop_ub; i++) { + b_usedConstr[i] = usedConstr[i]; + } + + c_usedConstr.set_size(usedPriorInd.size(0)); + loop_ub = usedPriorInd.size(0); + for (i = 0; i < loop_ub; i++) { + c_usedConstr[i] = usedConstr[i + usedConstr.size(0)]; + } + + coder::rescale(b_m, b_usedConstr, c_usedConstr, r2); + if (r.size(0) == 1) { + i = r1.size(0); + } else { + i = r.size(0); + } + + if ((r.size(0) == r1.size(0)) && (i == r2.size(0))) { + loop_ub = r.size(0); + for (i = 0; i < loop_ub; i++) { + real_T varargin_1; + varargin_1 = (r[i] - r1[i]) / r2[i]; + r[i] = varargin_1 * varargin_1; + } + } else { + binary_expand_op(r, r1, r2); + } + + pVal2 = -coder::sum(r); + } else { + pVal2 = 0.0; + } + + return pVal2; + } +} + +// End of code generation (scaledGaussPrior.cpp) diff --git a/RAT/scaledGaussPrior.h b/RAT/scaledGaussPrior.h new file mode 100644 index 00000000..dc27991a --- /dev/null +++ b/RAT/scaledGaussPrior.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// scaledGaussPrior.h +// +// Code generation for function 'scaledGaussPrior' +// +#ifndef SCALEDGAUSSPRIOR_H +#define SCALEDGAUSSPRIOR_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + real_T scaledGaussPrior(const ::coder::array &m, const ::coder:: + array &extras_problemDef_fitLimits, const ::coder::array &extras_priors); +} + +#endif + +// End of code generation (scaledGaussPrior.h) diff --git a/RAT/schur.cpp b/RAT/schur.cpp new file mode 100644 index 00000000..25771d0e --- /dev/null +++ b/RAT/schur.cpp @@ -0,0 +1,84 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// schur.cpp +// +// Code generation for function 'schur' +// + +// Include files +#include "schur.h" +#include "anyNonFinite.h" +#include "rt_nonfinite.h" +#include "triu.h" +#include "xdhseqr.h" +#include "xgehrd.h" +#include "xungorghr.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void schur(const ::coder::array &A, ::coder::array + &V, ::coder::array &T) + { + ::coder::array tau; + if (internal::anyNonFinite(A)) { + int32_T b_loop_ub; + int32_T loop_ub; + uint32_T unnamed_idx_0; + unnamed_idx_0 = static_cast(A.size(0)); + V.set_size(A.size(0), A.size(1)); + loop_ub = A.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = static_cast(unnamed_idx_0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + V[i1 + V.size(0) * i] = rtNaN; + } + } + + triu(V); + unnamed_idx_0 = static_cast(A.size(0)); + T.set_size(A.size(0), A.size(1)); + loop_ub = A.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = static_cast(unnamed_idx_0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + T[i1 + T.size(0) * i] = rtNaN; + } + } + } else { + int32_T b_loop_ub; + int32_T loop_ub; + T.set_size(A.size(0), A.size(1)); + loop_ub = A.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = A.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + T[i1 + T.size(0) * i] = A[i1 + A.size(0) * i]; + } + } + + internal::lapack::xgehrd(T, tau); + V.set_size(T.size(0), T.size(1)); + loop_ub = T.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = T.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + V[i1 + V.size(0) * i] = T[i1 + T.size(0) * i]; + } + } + + internal::lapack::xungorghr(A.size(0), A.size(0), V, A.size(0), tau); + internal::reflapack::eml_dlahqr(T, V); + b_triu(T); + } + } + } +} + +// End of code generation (schur.cpp) diff --git a/RAT/schur.h b/RAT/schur.h new file mode 100644 index 00000000..ad1feed3 --- /dev/null +++ b/RAT/schur.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// schur.h +// +// Code generation for function 'schur' +// +#ifndef SCHUR_H +#define SCHUR_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void schur(const ::coder::array &A, ::coder::array + &V, ::coder::array &T); + } +} + +#endif + +// End of code generation (schur.h) diff --git a/RAT/setupDREAM.cpp b/RAT/setupDREAM.cpp new file mode 100644 index 00000000..90314123 --- /dev/null +++ b/RAT/setupDREAM.cpp @@ -0,0 +1,274 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// setupDREAM.cpp +// +// Code generation for function 'setupDREAM' +// + +// Include files +#include "setupDREAM.h" +#include "RATMain_types.h" +#include "eml_setop.h" +#include "rng.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" +#include + +// Function Definitions +namespace RAT +{ + void setupDREAM(real_T DREAMPar_d, real_T DREAMPar_N, real_T DREAMPar_T, + real_T DREAMPar_lambda, real_T DREAMPar_pUnitGamma, boolean_T + DREAMPar_adaptPCR, struct14_T *outDREAMPar, struct15_T + *Meas_info, ::coder::array &chain, struct13_T + *output, ::coder::array &log_L, ::coder::array< + real_T, 2U> &Table_gamma) + { + ::coder::array c; + ::coder::array y; + ::coder::array r; + ::coder::array ia; + real_T value_f3_tmp; + int32_T b_loop_ub_tmp; + int32_T i; + int32_T k; + int32_T loop_ub; + int32_T loop_ub_tmp; + Meas_info->Y = 0.0; + Meas_info->N = 0.0; + + // Initializes the main variables used in DREAM + // To keep coder happy, we have to define the full version of DREAMPar here + // fieldNames = {'d','N','T','parallel','CPU','lambda','pUnitGamma','nCR','delta','steps',... + // 'zeta','outlier','adaptPCR','thinning','epsilon','ABC','IO','modout','restart','save','R'}; + // values = cell(length(fieldNames),1); + // outDREAMPar = cell2struct(values,fieldNames); + loop_ub_tmp = static_cast(DREAMPar_N); + outDREAMPar->R.set_size(loop_ub_tmp, loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + outDREAMPar->R[i1 + outDREAMPar->R.size(0) * i] = 0.0; + } + } + + // Generate new seed + coder::rng(); + + // randn('state', sum(100*clock)); % random number generator state + // Now make sure that all strings are lower case --> **TURNS OUT THIS BREAKS + // THINGS IF IMPLEMENTED!** + // for i = 1 : numel(field_names) + // % evalstr = strcat('DREAMPar.',field_names(i),' = lower(DREAMPar.',field_names(i),');'); + // % Now evaluate + // %eval(char(evalstr)); + // DREAMPar = lowerCaseStruct(DREAMPar); + // end + // Do an initial copy of all set fields from DREAMPar to outDREAMPar.... + outDREAMPar->d = DREAMPar_d; + outDREAMPar->N = DREAMPar_N; + outDREAMPar->T = DREAMPar_T; + outDREAMPar->CPU = 1.0; + + // Set default values algorithmic variables DREAM - if not specified + value_f3_tmp = std::fmax(std::fmax(std::floor(DREAMPar_T / 50.0), 1.0), 50.0); + + // Name variable + // Set variable of DREAMPar to "No" + // evalstr = strcat('DREAMPar.',char(name(j)),'=',value(j),';'); eval(char(evalstr)); + outDREAMPar->nCR = 3.0; + + // Set variable of DREAMPar to "No" + // evalstr = strcat('DREAMPar.',char(name(j)),'=',value(j),';'); eval(char(evalstr)); + outDREAMPar->delta = 3.0; + + // Set variable of DREAMPar to "No" + // evalstr = strcat('DREAMPar.',char(name(j)),'=',value(j),';'); eval(char(evalstr)); + outDREAMPar->steps = value_f3_tmp; + outDREAMPar->lambda = DREAMPar_lambda; + + // Set variable of DREAMPar to "No" + // evalstr = strcat('DREAMPar.',char(name(j)),'=',value(j),';'); eval(char(evalstr)); + outDREAMPar->zeta = 1.0E-12; + + // Set variable of DREAMPar to "No" + // evalstr = strcat('DREAMPar.',char(name(j)),'=',value(j),';'); eval(char(evalstr)); + outDREAMPar->outlier[0] = 'i'; + outDREAMPar->outlier[1] = 'q'; + outDREAMPar->outlier[2] = 'r'; + outDREAMPar->pUnitGamma = DREAMPar_pUnitGamma; + outDREAMPar->adaptPCR = DREAMPar_adaptPCR; + + // Set variable of DREAMPar to "No" + // evalstr = strcat('DREAMPar.',char(name(j)),'=',value(j),';'); eval(char(evalstr)); + outDREAMPar->thinning = 1.0; + + // Set variable of DREAMPar to "No" + // evalstr = strcat('DREAMPar.',char(name(j)),'=',value(j),';'); eval(char(evalstr)); + outDREAMPar->epsilon = 0.025; + + // Set default value to 'No' if not specified + // Set variable of DREAMPar to false + // evalstr = strcat('DREAMPar.',char(default(j)),'=false',';'); eval(evalstr); + outDREAMPar->ABC = false; + outDREAMPar->parallel = false; + + // Set variable of DREAMPar to false + // evalstr = strcat('DREAMPar.',char(default(j)),'=false',';'); eval(evalstr); + outDREAMPar->IO = false; + + // Set variable of DREAMPar to false + // evalstr = strcat('DREAMPar.',char(default(j)),'=false',';'); eval(evalstr); + outDREAMPar->modout = false; + + // Set variable of DREAMPar to false + // evalstr = strcat('DREAMPar.',char(default(j)),'=false',';'); eval(evalstr); + outDREAMPar->restart = false; + + // Set variable of DREAMPar to false + // evalstr = strcat('DREAMPar.',char(default(j)),'=false',';'); eval(evalstr); + outDREAMPar->save = false; + + // Matrix DREAMPar.R: Store for each chain (as row) the index of all other chains available for DE + if (static_cast(DREAMPar_N) - 1 >= 0) { + if (DREAMPar_N < 1.0) { + y.set_size(1, 0); + } else { + y.set_size(1, static_cast(DREAMPar_N - 1.0) + 1); + loop_ub = static_cast(DREAMPar_N - 1.0); + for (i = 0; i <= loop_ub; i++) { + y[i] = static_cast(i) + 1.0; + } + } + } + + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + coder::do_vectors(y, static_cast(b_i) + 1.0, c, ia, &k); + loop_ub = c.size(1); + for (i = 0; i < loop_ub; i++) { + outDREAMPar->R[b_i + outDREAMPar->R.size(0) * i] = c[i]; + } + } + + // Check whether parameter ranges have been defined or not + // Initialize output information -- Outlier chains + output->outlier.size[0] = 1; + output->outlier.size[1] = 2; + output->outlier.data[0] = 0.0; + output->outlier.data[output->outlier.size[0]] = 0.0; + + // ..also run time + output->RunTime = 0.0; + output->DREAMPar = *outDREAMPar; + output->Meas_info = *Meas_info; + output->iteration = 1.0; + output->iloc = 0.0; + output->fx = 0.0; + + // Initialize matrix with log_likelihood of each chain + loop_ub = static_cast(DREAMPar_T); + b_loop_ub_tmp = static_cast(DREAMPar_N + 1.0); + log_L.set_size(loop_ub, b_loop_ub_tmp); + for (i = 0; i < b_loop_ub_tmp; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + log_L[i1 + log_L.size(0) * i] = rtNaN; + } + } + + // Initialize vector with acceptance rates + b_loop_ub_tmp = static_cast(std::floor(DREAMPar_T / value_f3_tmp) + + 1.0); + output->AR.size[0] = static_cast(std::floor(DREAMPar_T / + value_f3_tmp) + 1.0); + output->AR.size[1] = 2; + for (i = 0; i < 2; i++) { + for (int32_T i1{0}; i1 < b_loop_ub_tmp; i1++) { + output->AR.data[i1 + output->AR.size[0] * i] = rtNaN; + } + } + + // NaN(floor(outDREAMPar.T/outDREAMPar.steps)+1,2); + output->AR.data[0] = DREAMPar_N; + + // Initialize matrix with potential scale reduction convergence diagnostic + k = static_cast(DREAMPar_d + 1.0); + output->R_stat.set_size(b_loop_ub_tmp, k); + for (i = 0; i < k; i++) { + for (int32_T i1{0}; i1 < b_loop_ub_tmp; i1++) { + output->R_stat[i1 + output->R_stat.size(0) * i] = rtNaN; + } + } + + // Initialize matix with crossover values + output->CR.set_size(b_loop_ub_tmp, 4); + for (i = 0; i < 4; i++) { + for (int32_T i1{0}; i1 < b_loop_ub_tmp; i1++) { + output->CR[i1 + output->CR.size(0) * i] = rtNaN; + } + } + + // Initialize array (3D-matrix) of chain trajectories + b_loop_ub_tmp = static_cast(DREAMPar_d + 2.0); + chain.set_size(loop_ub, b_loop_ub_tmp, loop_ub_tmp); + for (i = 0; i < loop_ub_tmp; i++) { + for (int32_T i1{0}; i1 < b_loop_ub_tmp; i1++) { + for (k = 0; k < loop_ub; k++) { + chain[(k + chain.size(0) * i1) + chain.size(0) * chain.size(1) * i] = + rtNaN; + } + } + } + + // Generate Table with jump rates (dependent on DREAMPar.d and DREAMPar.delta) + // More efficient to read from Table + loop_ub_tmp = static_cast(DREAMPar_d); + Table_gamma.set_size(loop_ub_tmp, 3); + for (i = 0; i < 3; i++) { + for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + Table_gamma[i1 + Table_gamma.size(0) * i] = 0.0; + } + } + + if (std::isnan(DREAMPar_d)) { + y.set_size(1, 1); + y[0] = rtNaN; + } else if (DREAMPar_d < 1.0) { + y.set_size(1, 0); + } else { + y.set_size(1, static_cast(DREAMPar_d - 1.0) + 1); + loop_ub = static_cast(DREAMPar_d - 1.0); + for (i = 0; i <= loop_ub; i++) { + y[i] = static_cast(i) + 1.0; + } + } + + loop_ub = y.size(1); + for (int32_T zz{0}; zz < 3; zz++) { + k = (zz + 1) << 1; + r.set_size(y.size(1)); + for (i = 0; i < loop_ub; i++) { + r[i] = static_cast(k) * y[i]; + } + + i = r.size(0); + for (k = 0; k < i; k++) { + r[k] = std::sqrt(r[k]); + } + + k = r.size(0); + for (i = 0; i < k; i++) { + Table_gamma[i + Table_gamma.size(0) * zz] = 2.38 / r[i]; + } + } + + // First calculate the number of calibration data measurements + Meas_info->N = 0.0; + + // Initialize few important counters + } +} + +// End of code generation (setupDREAM.cpp) diff --git a/RAT/setupDREAM.h b/RAT/setupDREAM.h new file mode 100644 index 00000000..2d63541b --- /dev/null +++ b/RAT/setupDREAM.h @@ -0,0 +1,40 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// setupDREAM.h +// +// Code generation for function 'setupDREAM' +// +#ifndef SETUPDREAM_H +#define SETUPDREAM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct14_T; + struct struct15_T; + struct struct13_T; +} + +// Function Declarations +namespace RAT +{ + void setupDREAM(real_T DREAMPar_d, real_T DREAMPar_N, real_T DREAMPar_T, + real_T DREAMPar_lambda, real_T DREAMPar_pUnitGamma, boolean_T + DREAMPar_adaptPCR, struct14_T *outDREAMPar, struct15_T + *Meas_info, ::coder::array &chain, struct13_T + *output, ::coder::array &log_L, ::coder::array< + real_T, 2U> &Table_gamma); +} + +#endif + +// End of code generation (setupDREAM.h) diff --git a/RAT/shiftData.cpp b/RAT/shiftData.cpp index d979968a..546b3e28 100644 --- a/RAT/shiftData.cpp +++ b/RAT/shiftData.cpp @@ -14,33 +14,33 @@ #include "linspace.h" #include "rt_nonfinite.h" #include "coder_array.h" -#include -namespace py = pybind11; // Function Definitions namespace RAT { - void shiftData(real_T scalefac, real_T horshift, real_T dataPresent, ::coder:: + void shiftData(real_T scalefactor, real_T qzshift, real_T dataPresent, ::coder:: array &data, const real_T dataLimits[2], const - real_T simLimits_data[], ::coder::array - &shifted_data) + real_T simLimits[2], ::coder::array &shiftedData) { ::coder::array b_data; ::coder::array b_i; ::coder::array b_data_data; ::coder::array c_data_data; boolean_T data_data[10000]; + // Shifts the data according to scale factor. If there is no data, makes // x-data over the simulation range. // // INPUTS: + // * scalefactor: problem.scalefactors + // * qzshift: problem.qzhifts + // * dataPresent: problem.dataPresent + // * data: problem.data + // * dataLimits: problem.dataLimits + // * simLimits: problem.simLimits // - // * scalefac = problem.scalefactors; - // * horshift = problem.qshifts; - // * numberOfContrasts = problem.numberOfContrasts; - // * dataPresent = problem.dataPresent; - // * allData = problem.data; - // * dataLimits = problem.dataLimits; + // OUTPUTS: + // * shiftedData: Data shifted using given scale factor if (static_cast(dataPresent) == 1) { int32_T data_size; int32_T hiIndex; @@ -48,14 +48,14 @@ namespace RAT int32_T i1; int32_T loop_ub; int32_T lowIndex; - if (scalefac == 0.0) { - scalefac = 1.0E-30; + if (scalefactor == 0.0) { + scalefactor = 1.0E-30; } b_data.set_size(data.size(0)); loop_ub = data.size(0); for (i = 0; i < loop_ub; i++) { - b_data[i] = data[i] + horshift; + b_data[i] = data[i] + qzshift; } loop_ub = b_data.size(0); @@ -66,7 +66,7 @@ namespace RAT b_data.set_size(data.size(0)); loop_ub = data.size(0); for (i = 0; i < loop_ub; i++) { - b_data[i] = data[i + data.size(0)] / scalefac; + b_data[i] = data[i + data.size(0)] / scalefactor; } loop_ub = b_data.size(0); @@ -77,7 +77,7 @@ namespace RAT b_data.set_size(data.size(0)); loop_ub = data.size(0); for (i = 0; i < loop_ub; i++) { - b_data[i] = data[i + data.size(0) * 2] / scalefac; + b_data[i] = data[i + data.size(0) * 2] / scalefactor; } loop_ub = b_data.size(0); @@ -122,28 +122,28 @@ namespace RAT } loop_ub = i1 - i; - shifted_data.set_size(loop_ub, data.size(1)); + shiftedData.set_size(loop_ub, data.size(1)); data_size = data.size(1); for (i1 = 0; i1 < data_size; i1++) { for (int32_T i2{0}; i2 < loop_ub; i2++) { - shifted_data[i2 + shifted_data.size(0) * i1] = data[(i + i2) + - data.size(0) * i1]; + shiftedData[i2 + shiftedData.size(0) * i1] = data[(i + i2) + data.size + (0) * i1]; } } } else { - real_T dv1[3][500]; - real_T dv[500]; - coder::linspace(simLimits_data[0], simLimits_data[1], dv); + real_T b_dv1[3][500]; + real_T b_dv[500]; + coder::linspace(simLimits[0], simLimits[1], b_dv); for (int32_T i{0}; i < 500; i++) { - dv1[0][i] = dv[i]; - dv1[1][i] = 0.0; - dv1[2][i] = 0.0; + b_dv1[0][i] = b_dv[i]; + b_dv1[1][i] = 0.0; + b_dv1[2][i] = 0.0; } - shifted_data.set_size(500, 3); + shiftedData.set_size(500, 3); for (int32_T i{0}; i < 3; i++) { for (int32_T i1{0}; i1 < 500; i1++) { - shifted_data[i1 + shifted_data.size(0) * i] = dv1[i][i1]; + shiftedData[i1 + shiftedData.size(0) * i] = b_dv1[i][i1]; } } } diff --git a/RAT/shiftData.h b/RAT/shiftData.h index fb4f93c5..67fbe177 100644 --- a/RAT/shiftData.h +++ b/RAT/shiftData.h @@ -19,10 +19,9 @@ // Function Declarations namespace RAT { - void shiftData(real_T scalefac, real_T horshift, real_T dataPresent, ::coder:: + void shiftData(real_T scalefactor, real_T qzshift, real_T dataPresent, ::coder:: array &data, const real_T dataLimits[2], const - real_T simLimits_data[], ::coder::array - &shifted_data); + real_T simLimits[2], ::coder::array &shiftedData); } #endif diff --git a/RAT/simplexIntrafun.cpp b/RAT/simplexIntrafun.cpp new file mode 100644 index 00000000..052ba07a --- /dev/null +++ b/RAT/simplexIntrafun.cpp @@ -0,0 +1,113 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// simplexIntrafun.cpp +// +// Code generation for function 'simplexIntrafun' +// + +// Include files +#include "simplexIntrafun.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "reflectivityCalculation.h" +#include "rt_nonfinite.h" +#include "simplexXTransform.h" +#include "unpackParams.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void simplexIntrafun(const ::coder::array &x, const struct5_T + *problemDef, const ::coder::array + &problemDefCells_f1, const ::coder::array + &problemDefCells_f2, const ::coder::array + &problemDefCells_f3, const ::coder::array + &problemDefCells_f4, const ::coder::array + &problemDefCells_f5, const ::coder::array + &problemDefCells_f6, const ::coder::array + &problemDefCells_f14, const ::coder::array &problemDefCells_f19, const struct2_T *controls, + const j_struct_T *params, real_T *fval, struct_T + *b_problemDef, cell_13 *result) + { + ::coder::array xtrans; + cell_14 expl_temp; + struct5_T c_problemDef; + int32_T xtrans_idx_0; + c_problemDef = *problemDef; + + // transform variables, then call original function + simplexXTransform(x, params->LB, params->UB, params->BoundClass, xtrans); + + // Unpck the params.. + xtrans_idx_0 = xtrans.size(0); + c_problemDef.fitParams.set_size(xtrans.size(0), 1); + for (int32_T i{0}; i < xtrans_idx_0; i++) { + c_problemDef.fitParams[i] = xtrans[i]; + } + + unpackParams(&c_problemDef, controls->checks.fitParam, + controls->checks.fitBackgroundParam, + controls->checks.fitQzshift, controls->checks.fitScalefactor, + controls->checks.fitBulkIn, controls->checks.fitBulkOut, + controls->checks.fitResolutionParam, + controls->checks.fitDomainRatio); + expl_temp.f19.set_size(1, problemDefCells_f19.size(1)); + xtrans_idx_0 = problemDefCells_f19.size(1); + for (int32_T i{0}; i < xtrans_idx_0; i++) { + expl_temp.f19[i] = problemDefCells_f19[i]; + } + + expl_temp.f14.set_size(1, problemDefCells_f14.size(1)); + xtrans_idx_0 = problemDefCells_f14.size(1); + for (int32_T i{0}; i < xtrans_idx_0; i++) { + expl_temp.f14[i] = problemDefCells_f14[i]; + } + + expl_temp.f6.set_size(problemDefCells_f6.size(0)); + xtrans_idx_0 = problemDefCells_f6.size(0); + for (int32_T i{0}; i < xtrans_idx_0; i++) { + expl_temp.f6[i] = problemDefCells_f6[i]; + } + + expl_temp.f5.set_size(1, problemDefCells_f5.size(1)); + xtrans_idx_0 = problemDefCells_f5.size(1); + for (int32_T i{0}; i < xtrans_idx_0; i++) { + expl_temp.f5[i] = problemDefCells_f5[i]; + } + + expl_temp.f4.set_size(1, problemDefCells_f4.size(1)); + xtrans_idx_0 = problemDefCells_f4.size(1); + for (int32_T i{0}; i < xtrans_idx_0; i++) { + expl_temp.f4[i] = problemDefCells_f4[i]; + } + + expl_temp.f3.set_size(1, problemDefCells_f3.size(1)); + xtrans_idx_0 = problemDefCells_f3.size(1); + for (int32_T i{0}; i < xtrans_idx_0; i++) { + expl_temp.f3[i] = problemDefCells_f3[i]; + } + + expl_temp.f2.set_size(1, problemDefCells_f2.size(1)); + xtrans_idx_0 = problemDefCells_f2.size(1); + for (int32_T i{0}; i < xtrans_idx_0; i++) { + expl_temp.f2[i] = problemDefCells_f2[i]; + } + + expl_temp.f1.set_size(1, problemDefCells_f1.size(1)); + xtrans_idx_0 = problemDefCells_f1.size(1); + for (int32_T i{0}; i < xtrans_idx_0; i++) { + expl_temp.f1[i] = problemDefCells_f1[i]; + } + + reflectivityCalculation(&c_problemDef, &expl_temp, controls, b_problemDef, + result); + *fval = b_problemDef->calculations.sumChi; + } +} + +// End of code generation (simplexIntrafun.cpp) diff --git a/RAT/simplexIntrafun.h b/RAT/simplexIntrafun.h new file mode 100644 index 00000000..6c09bdc9 --- /dev/null +++ b/RAT/simplexIntrafun.h @@ -0,0 +1,47 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// simplexIntrafun.h +// +// Code generation for function 'simplexIntrafun' +// +#ifndef SIMPLEXINTRAFUN_H +#define SIMPLEXINTRAFUN_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct j_struct_T; + struct struct_T; + struct cell_13; +} + +// Function Declarations +namespace RAT +{ + void simplexIntrafun(const ::coder::array &x, const struct5_T + *problemDef, const ::coder::array + &problemDefCells_f1, const ::coder::array + &problemDefCells_f2, const ::coder::array + &problemDefCells_f3, const ::coder::array + &problemDefCells_f4, const ::coder::array + &problemDefCells_f5, const ::coder::array + &problemDefCells_f6, const ::coder::array + &problemDefCells_f14, const ::coder::array &problemDefCells_f19, const struct2_T *controls, + const j_struct_T *params, real_T *fval, struct_T + *b_problemDef, cell_13 *result); +} + +#endif + +// End of code generation (simplexIntrafun.h) diff --git a/RAT/simplexXTransform.cpp b/RAT/simplexXTransform.cpp new file mode 100644 index 00000000..fbe69a40 --- /dev/null +++ b/RAT/simplexXTransform.cpp @@ -0,0 +1,62 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// simplexXTransform.cpp +// +// Code generation for function 'simplexXTransform' +// + +// Include files +#include "simplexXTransform.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + void simplexXTransform(const ::coder::array &x, const ::coder:: + array ¶ms_LB, const ::coder::array ¶ms_UB, + const ::coder::array ¶ms_BoundClass, ::coder::array &xtrans) + { + int32_T i; + int32_T loop_ub; + + // converts unconstrained variables into their original domains + xtrans.set_size(x.size(0)); + loop_ub = x.size(0); + for (i = 0; i < loop_ub; i++) { + xtrans[i] = x[i]; + } + + i = x.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + switch (static_cast(params_BoundClass[b_i])) { + case 1: + // lower bound only + xtrans[b_i] = params_LB[b_i] + x[b_i] * x[b_i]; + break; + + case 2: + // upper bound only + xtrans[b_i] = params_UB[b_i] - x[b_i] * x[b_i]; + break; + + case 3: + // lower and upper bounds + xtrans[b_i] = (std::sin(x[b_i]) + 1.0) / 2.0 * (params_UB[b_i] - + params_LB[b_i]) + params_LB[b_i]; + break; + + default: + // unconstrained variable. xtrans(i) is set. + break; + } + } + } +} + +// End of code generation (simplexXTransform.cpp) diff --git a/RAT/simplexXTransform.h b/RAT/simplexXTransform.h new file mode 100644 index 00000000..1325c969 --- /dev/null +++ b/RAT/simplexXTransform.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// simplexXTransform.h +// +// Code generation for function 'simplexXTransform' +// +#ifndef SIMPLEXXTRANSFORM_H +#define SIMPLEXXTRANSFORM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void simplexXTransform(const ::coder::array &x, const ::coder:: + array ¶ms_LB, const ::coder::array ¶ms_UB, + const ::coder::array ¶ms_BoundClass, ::coder::array &xtrans); +} + +#endif + +// End of code generation (simplexXTransform.h) diff --git a/RAT/single.cpp b/RAT/single.cpp new file mode 100644 index 00000000..cc084ade --- /dev/null +++ b/RAT/single.cpp @@ -0,0 +1,207 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single.cpp +// +// Code generation for function 'single' +// + +// Include files +#include "single.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "allocateLayersForContrast.h" +#include "allocateParamsToLayers.h" +#include "backSort.h" +#include "coreLayersCalculation.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace standardLayers + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs) + { + static real_T thisContrastLayers_data[6000]; + ::coder::array outParameterisedLayers; + ::coder::array b_thisContrastLayers_data; + ::coder::array shiftedDat; + ::coder::array sldProfile; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + int32_T i; + boolean_T useImaginary; + + // Single threaded version of the Standard Layers calculation + // This is the main reflectivity calculation of the standard layers + // calculation type. It extracts the required parameters for the contrasts + // from the input arrays, then passes the main calculation to + // 'standardLayersCore', which carries out the calculation itself. + // The core calculation is common for both standard and custom layers. + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + useImaginary = problemDef->useImaginary; + + // Allocate the memory for the output arrays before the main loop + i = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(i); + + // end memory allocation. + // First we need to allocate the absolute values of the input + // parameters to all the layers in the layers list. This only needs + // to be done once, and so is done outside the contrasts loop + allocateParamsToLayers(problemDef->params, problemDefCells->f6, + outParameterisedLayers); + + // Resample params if requiired + // Loop over all the contrasts + outSsubs.set_size(i); + sldProfiles.set_size(i); + reflectivity.set_size(i); + simulation.set_size(i); + shiftedData.set_size(i); + layerSlds.set_size(i); + chis.set_size(i); + qzshifts.set_size(i); + scalefactors.set_size(i); + bulkIns.set_size(i); + bulkOuts.set_size(i); + resolutionParams.set_size(i); + allRoughs.set_size(i); + allLayers.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + int32_T thisContrastLayers_size[2]; + int32_T b_loop_ub; + int32_T loop_ub; + + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, + &thisBulkOut, &thisResol); + + // Also need to determine which layers from the overall layers list + // are required for this contrast, and put them in the correct order + // according to geometry + allocateLayersForContrast(problemDefCells->f5[b_i].f1, + outParameterisedLayers, useImaginary, thisContrastLayers_data, + thisContrastLayers_size); + + // For the other parameters, we extract the correct ones from the input + // arrays + // Substrate roughness is always first parameter for standard layers + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the core layers calculation + b_thisContrastLayers_data.set(&thisContrastLayers_data[0], + thisContrastLayers_size[0], thisContrastLayers_size[1]); + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + coreLayersCalculation(b_thisContrastLayers_data, problemDef->params[0], + problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, + thisBulkOut, problemDef->resample[b_i], + controls->calcSldDuringFit, thisScalefactor, + thisQzshift, problemDef->dataPresent[b_i], + problemDefCells->f2[b_i].f1, b_dv, b_dv1, dv2, + thisBackground, thisResol, + problemDef->contrastBackgroundsType[b_i], + static_cast(problemDef->params.size(1)), + controls->resamPars, useImaginary, sldProfile, + reflectivity[b_i].f1, simulation[b_i].f1, + shiftedDat, layerSlds[b_i].f1, allLayers[b_i].f1, + &chis[b_i], &outSsubs[b_i]); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + loop_ub = sldProfile.size(1); + sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = sldProfile.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = + sldProfile[i2 + sldProfile.size(0) * i1]; + } + } + + loop_ub = shiftedDat.size(1); + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + backgroundParams[b_i] = thisBackground; + qzshifts[b_i] = thisQzshift; + scalefactors[b_i] = thisScalefactor; + bulkIns[b_i] = thisBulkIn; + bulkOuts[b_i] = thisBulkOut; + resolutionParams[b_i] = thisResol; + allRoughs[b_i] = problemDef->params[0]; + } + } + } + } +} + +// End of code generation (single.cpp) diff --git a/RAT/single.h b/RAT/single.h new file mode 100644 index 00000000..e558dfb9 --- /dev/null +++ b/RAT/single.h @@ -0,0 +1,52 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single.h +// +// Code generation for function 'single' +// +#ifndef SINGLE_H +#define SINGLE_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace standardLayers + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (single.h) diff --git a/RAT/single1.cpp b/RAT/single1.cpp new file mode 100644 index 00000000..c593edd3 --- /dev/null +++ b/RAT/single1.cpp @@ -0,0 +1,207 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single1.cpp +// +// Code generation for function 'single1' +// + +// Include files +#include "single1.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "backSort.h" +#include "coreLayersCalculation.h" +#include "processCustomFunction.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customLayers + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs) + { + ::coder::array b_allLayers; + ::coder::array shiftedDat; + ::coder::array sldProfile; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + int32_T i; + + // Single threaded version of the custom layers, nonPolarisedTF reflectivity + // calculation. The function extracts the relevant parameters from the input + // arrays, allocates these on a pre-contrast basis, then calls the 'core' + // calculation (the core layers nonPolarisedTF calc is shared between + // multiple calculation types). + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + // Pre-Allocation of output arrays... + i = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(i); + + // --- End Memory Allocation --- + // Resampling parameters + // Process the custom models.... + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + problemDef->useImaginary, allLayers, allRoughs); + + // Single cored over all contrasts + outSsubs.set_size(i); + sldProfiles.set_size(i); + reflectivity.set_size(i); + simulation.set_size(i); + shiftedData.set_size(i); + layerSlds.set_size(i); + chis.set_size(i); + qzshifts.set_size(i); + scalefactors.set_size(i); + bulkIns.set_size(i); + bulkOuts.set_size(i); + resolutionParams.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { + int32_T b_loop_ub; + int32_T loop_ub; + + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, + &thisBulkOut, &thisResol); + + // Get the custom layers output for this contrast + // For the other parameters, we extract the correct ones from the input + // arrays + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the reflectivity calculation + b_allLayers.set_size(allLayers[b_i].f1.size(0), allLayers[b_i].f1.size + (1)); + loop_ub = allLayers[b_i].f1.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_loop_ub = allLayers[b_i].f1.size(0) - 1; + for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { + b_allLayers[i2 + b_allLayers.size(0) * i1] = allLayers[b_i].f1[i2 + + allLayers[b_i].f1.size(0) * i1]; + } + } + + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + coreLayersCalculation(b_allLayers, allRoughs[b_i], + problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, + thisBulkOut, problemDef->resample[b_i], + controls->calcSldDuringFit, thisScalefactor, + thisQzshift, problemDef->dataPresent[b_i], + problemDefCells->f2[b_i].f1, b_dv, b_dv1, dv2, + thisBackground, thisResol, + problemDef->contrastBackgroundsType[b_i], + static_cast(problemDef->params.size(1)), + controls->resamPars, problemDef->useImaginary, + sldProfile, reflectivity[b_i].f1, simulation[b_i] + .f1, shiftedDat, layerSlds[b_i].f1, + allLayers[b_i].f1, &chis[b_i], &outSsubs[b_i]); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + loop_ub = sldProfile.size(1); + sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = sldProfile.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = + sldProfile[i2 + sldProfile.size(0) * i1]; + } + } + + loop_ub = shiftedDat.size(1); + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + backgroundParams[b_i] = thisBackground; + qzshifts[b_i] = thisQzshift; + scalefactors[b_i] = thisScalefactor; + bulkIns[b_i] = thisBulkIn; + bulkOuts[b_i] = thisBulkOut; + resolutionParams[b_i] = thisResol; + } + } + } + } +} + +// End of code generation (single1.cpp) diff --git a/RAT/single1.h b/RAT/single1.h new file mode 100644 index 00000000..6579cfa6 --- /dev/null +++ b/RAT/single1.h @@ -0,0 +1,52 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single1.h +// +// Code generation for function 'single1' +// +#ifndef SINGLE1_H +#define SINGLE1_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customLayers + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (single1.h) diff --git a/RAT/single2.cpp b/RAT/single2.cpp new file mode 100644 index 00000000..5a0f1dd6 --- /dev/null +++ b/RAT/single2.cpp @@ -0,0 +1,221 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single2.cpp +// +// Code generation for function 'single2' +// + +// Include files +#include "single2.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "applyBackgroundCorrection.h" +#include "backSort.h" +#include "callReflectivity.h" +#include "chiSquared.h" +#include "processCustomFunction1.h" +#include "resampleLayers.h" +#include "resampleLayersReIm.h" +#include "rt_nonfinite.h" +#include "shiftData.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customXY + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs) + { + ::coder::array b_problemDefCells; + ::coder::array b_sldProfiles; + ::coder::array c_sldProfiles; + ::coder::array layerSld; + ::coder::array reflect; + ::coder::array shiftedDat; + int32_T loop_ub_tmp; + boolean_T useImaginary; + + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // % Layers details N/A + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + // Pre-Allocation... + loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(loop_ub_tmp); + outSsubs.set_size(loop_ub_tmp); + for (int32_T i{0}; i < loop_ub_tmp; i++) { + outSsubs[i] = 0.0; + } + + // Resampling parameters + useImaginary = problemDef->useImaginary; + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + sldProfiles, allRoughs); + qzshifts.set_size(loop_ub_tmp); + scalefactors.set_size(loop_ub_tmp); + bulkIns.set_size(loop_ub_tmp); + bulkOuts.set_size(loop_ub_tmp); + resolutionParams.set_size(loop_ub_tmp); + layerSlds.set_size(loop_ub_tmp); + allLayers.set_size(loop_ub_tmp); + shiftedData.set_size(loop_ub_tmp); + chis.set_size(loop_ub_tmp); + simulation.set_size(loop_ub_tmp); + reflectivity.set_size(loop_ub_tmp); + for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { + real_T b_dv[2]; + real_T b_dv1[2]; + int32_T b_loop_ub; + int32_T loop_ub; + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &backgroundParams[b_i], &qzshifts[b_i], &scalefactors[b_i], + &bulkIns[b_i], &bulkOuts[b_i], &resolutionParams[b_i]); + + // Resample the layers + if (!useImaginary) { + resampleLayers(sldProfiles[b_i].f1, controls->resamPars, layerSld); + } else { + loop_ub = sldProfiles[b_i].f1.size(0); + b_sldProfiles.set_size(sldProfiles[b_i].f1.size(0), 2); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_sldProfiles[i1 + b_sldProfiles.size(0) * i] = sldProfiles[b_i] + .f1[i1 + sldProfiles[b_i].f1.size(0) * i]; + } + } + + loop_ub = sldProfiles[b_i].f1.size(0); + c_sldProfiles.set_size(sldProfiles[b_i].f1.size(0), 2); + for (int32_T i{0}; i < loop_ub; i++) { + c_sldProfiles[i] = sldProfiles[b_i].f1[i]; + c_sldProfiles[i + c_sldProfiles.size(0)] = sldProfiles[b_i].f1[i + + sldProfiles[b_i].f1.size(0) * 2]; + } + + c_resampleLayersReIm(b_sldProfiles, c_sldProfiles, + controls->resamPars, layerSld); + } + + layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + loop_ub = layerSld.size(1); + allLayers[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); + b_loop_ub = layerSld.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + layerSlds[b_i].f1[i1 + layerSlds[b_i].f1.size(0) * i] = + layerSld[i1 + layerSld.size(0) * i]; + allLayers[b_i].f1[i1 + allLayers[b_i].f1.size(0) * i] = + layerSld[i1 + layerSld.size(0) * i]; + } + } + + b_problemDefCells.set_size(problemDefCells->f2 + [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> + f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); + loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + for (int32_T i{0}; i <= loop_ub; i++) { + b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + for (int32_T i1{0}; i1 <= b_loop_ub; i1++) { + b_problemDefCells[i1 + b_problemDefCells.size(0) * i] = + problemDefCells->f2[b_i].f1[i1 + problemDefCells->f2[b_i]. + f1.size(0) * i]; + } + } + + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> + dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + loop_ub = shiftedDat.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + shiftedData[b_i].f1[i1 + shiftedData[b_i].f1.size(0) * i] = + shiftedDat[i1 + shiftedDat.size(0) * i]; + } + } + + b_dv[0] = problemDefCells->f4[b_i].f1[0]; + b_dv[1] = problemDefCells->f4[b_i].f1[1]; + b_dv1[0] = problemDefCells->f1[b_i].f1[0]; + b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, + layerSld, 0.0, resolutionParams[b_i], useImaginary, + reflect, simulation[b_i].f1); + applyBackgroundCorrection(reflect, simulation[b_i].f1, shiftedDat, + backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + loop_ub = reflect.size(0); + reflectivity[b_i].f1.set_size(reflect.size(0), 2); + for (int32_T i{0}; i < 2; i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + reflectivity[b_i].f1[i1 + reflectivity[b_i].f1.size(0) * i] = + reflect[i1 + reflect.size(0) * i]; + } + } + + if (problemDef->dataPresent[b_i] != 0.0) { + chis[b_i] = chiSquared(shiftedDat, reflect, static_cast + (problemDef->params.size(1))); + } else { + chis[b_i] = 0.0; + } + } + } + } + } +} + +// End of code generation (single2.cpp) diff --git a/RAT/single2.h b/RAT/single2.h new file mode 100644 index 00000000..261073de --- /dev/null +++ b/RAT/single2.h @@ -0,0 +1,52 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single2.h +// +// Code generation for function 'single2' +// +#ifndef SINGLE2_H +#define SINGLE2_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace nonPolarisedTF + { + namespace customXY + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &sldProfiles, ::coder::array< + cell_wrap_8, 1U> &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (single2.h) diff --git a/RAT/single3.cpp b/RAT/single3.cpp new file mode 100644 index 00000000..a6ec6b33 --- /dev/null +++ b/RAT/single3.cpp @@ -0,0 +1,346 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single3.cpp +// +// Code generation for function 'single3' +// + +// Include files +#include "single3.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "allocateLayersForContrast.h" +#include "allocateParamsToLayers.h" +#include "averageReflectivity.h" +#include "backSort.h" +#include "chiSquared.h" +#include "coreLayersCalculation.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace standardLayers + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &domainSldProfiles, ::coder:: + array &allLayers, ::coder::array + &allRoughs) + { + static real_T thisContrastLayers1_data[6000]; + static real_T thisContrastLayers2_data[6000]; + ::coder::array outParameterisedLayers; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; + ::coder::array a__6; + ::coder::array b_thisContrastLayers1_data; + ::coder::array b_thisContrastLayers2_data; + ::coder::array reflect1; + ::coder::array reflect2; + ::coder::array shiftedDat; + ::coder::array simul1; + ::coder::array simul2; + ::coder::array totReflect; + cell_wrap_8 r; + cell_wrap_8 r1; + cell_wrap_8 r2; + cell_wrap_8 r3; + cell_wrap_8 r4; + cell_wrap_8 r5; + real_T a__5; + real_T a__7; + real_T a__8; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + int32_T nParams; + boolean_T calcSld; + boolean_T useImaginary; + + // Single threaded version of the Standard Layers calculation + // This is the main reflectivity calculation of the standard layers + // calculation type. It extracts the required parameters for the contrasts + // from the input arrays, then passes the main calculation to + // 'standardLayersCore', which carries out the calculation itself. + // The core calculation is common for both standard and custom layers. + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Additionally extract the additional domain layers details + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + calcSld = controls->calcSldDuringFit; + useImaginary = problemDef->useImaginary; + + // Default for compile. + // Allocate the memory for the output arrays before the main loop + i = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(i); + + // end memory allocation. + // First we need to allocate the absolute values of the input + // parameters to all the layers in the layers list. This only needs + // to be done once, and so is done outside the contrasts loop + allocateParamsToLayers(problemDef->params, problemDefCells->f6, + outParameterisedLayers); + + // Resample params if requiired + // Loop over all the contrasts + outSsubs.set_size(i); + tempSldProfiles.set_size(i); + reflectivity.set_size(i); + simulation.set_size(i); + shiftedData.set_size(i); + tempLayerSlds.set_size(i); + tempAllLayers.set_size(i); + chis.set_size(i); + qzshifts.set_size(i); + scalefactors.set_size(i); + bulkIns.set_size(i); + bulkOuts.set_size(i); + resolutionParams.set_size(i); + allRoughs.set_size(i); + layerSlds.set_size(i, 2); + domainSldProfiles.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + int32_T thisContrastLayers1_size[2]; + int32_T thisContrastLayers2_size[2]; + + // Get the domain ratio for this contrast + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, + &thisBulkOut, &thisResol); + + // Also need to determine which layers from the overall layers list + // are required for this contrast, and put them in the correct order + // according to geometry. We run it twice, once for each domain... + allocateLayersForContrast(problemDefCells->f19[0].f1, + outParameterisedLayers, useImaginary, thisContrastLayers1_data, + thisContrastLayers1_size); + allocateLayersForContrast(problemDefCells->f19[1].f1, + outParameterisedLayers, useImaginary, thisContrastLayers2_data, + thisContrastLayers2_size); + + // For the other parameters, we extract the correct ones from the input + // arrays + // Substrate roughness is always first parameter for standard layers + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the core layers calculation - need to do this once for each + // domain + b_thisContrastLayers1_data.set(&thisContrastLayers1_data[0], + thisContrastLayers1_size[0], thisContrastLayers1_size[1]); + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + nonPolarisedTF::coreLayersCalculation(b_thisContrastLayers1_data, + problemDef->params[0], problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, thisBulkOut, + problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, + b_dv1, dv2, thisBackground, thisResol, + problemDef->contrastBackgroundsType[b_i], static_cast + (nParams), controls->resamPars, useImaginary, r.f1, reflect1, simul1, + shiftedDat, r1.f1, r2.f1, &a__5, &outSsubs[b_i]); + b_thisContrastLayers2_data.set(&thisContrastLayers2_data[0], + thisContrastLayers2_size[0], thisContrastLayers2_size[1]); + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + nonPolarisedTF::coreLayersCalculation(b_thisContrastLayers2_data, + problemDef->params[0], problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, thisBulkOut, + problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, + b_dv1, dv2, thisBackground, thisResol, + problemDef->contrastBackgroundsType[b_i], static_cast + (nParams), controls->resamPars, useImaginary, r3.f1, reflect2, + simul2, a__6, r4.f1, r5.f1, &a__7, &a__8); + + // Calculate the average reflectivities.... + averageReflectivity(reflect1, reflect2, simul1, simul2, + problemDef->domainRatio[static_cast + (problemDef->contrastDomainRatios[b_i]) - 1], + totReflect, simulation[b_i].f1); + + // Get an overall chi-squared for the new averaged curve.. + chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast + (problemDef->params.size(1))); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + tempSldProfiles[b_i].f1[0] = r; + tempSldProfiles[b_i].f1[1] = r3; + reflectivity[b_i].f1.set_size(totReflect.size(0), 2); + loop_ub = totReflect.size(0); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1] = + totReflect[i2 + totReflect.size(0) * i1]; + } + } + + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + loop_ub = shiftedDat.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + tempLayerSlds[b_i].f1[0] = r1; + tempLayerSlds[b_i].f1[1] = r4; + tempAllLayers[b_i].f1[0] = r2; + tempAllLayers[b_i].f1[1] = r5; + backgroundParams[b_i] = thisBackground; + qzshifts[b_i] = thisQzshift; + scalefactors[b_i] = thisScalefactor; + bulkIns[b_i] = thisBulkIn; + bulkOuts[b_i] = thisBulkOut; + resolutionParams[b_i] = thisResol; + allRoughs[b_i] = problemDef->params[0]; + } + + allLayers.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + loop_ub = tempSldProfiles[b_i].f1[0].f1.size(1); + domainSldProfiles[b_i].f1.set_size(tempSldProfiles[b_i].f1[0].f1.size + (0), tempSldProfiles[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i].f1[i2 + domainSldProfiles[b_i].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[0].f1[i2 + tempSldProfiles[b_i] + .f1[0].f1.size(0) * i1]; + } + } + + loop_ub = tempSldProfiles[b_i].f1[1].f1.size(1); + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.set_size + (tempSldProfiles[b_i].f1[1].f1.size(0), tempSldProfiles[b_i].f1[1]. + f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i2 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[1].f1[i2 + tempSldProfiles[b_i] + .f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[0].f1.size(1); + allLayers[b_i].f1.set_size(tempAllLayers[b_i].f1[0].f1.size(0), + tempAllLayers[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + tempAllLayers[b_i].f1[0].f1[i2 + tempAllLayers[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[1].f1.size(1); + allLayers[b_i + allLayers.size(0)].f1.set_size(tempAllLayers[b_i].f1[1] + .f1.size(0), tempAllLayers[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i + allLayers.size(0)].f1[i2 + allLayers[b_i + + allLayers.size(0)].f1.size(0) * i1] = tempAllLayers[b_i].f1[1]. + f1[i2 + tempAllLayers[b_i].f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[0].f1.size(1); + layerSlds[b_i].f1.set_size(tempLayerSlds[b_i].f1[0].f1.size(0), + tempLayerSlds[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = + tempLayerSlds[b_i].f1[0].f1[i2 + tempLayerSlds[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[1].f1.size(1); + layerSlds[b_i + layerSlds.size(0)].f1.set_size(tempLayerSlds[b_i].f1[1] + .f1.size(0), tempLayerSlds[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i + layerSlds.size(0)].f1[i2 + layerSlds[b_i + + layerSlds.size(0)].f1.size(0) * i1] = tempLayerSlds[b_i].f1[1]. + f1[i2 + tempLayerSlds[b_i].f1[1].f1.size(0) * i1]; + } + } + } + } + } + } +} + +// End of code generation (single3.cpp) diff --git a/RAT/single3.h b/RAT/single3.h new file mode 100644 index 00000000..467d5b17 --- /dev/null +++ b/RAT/single3.h @@ -0,0 +1,52 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single3.h +// +// Code generation for function 'single3' +// +#ifndef SINGLE3_H +#define SINGLE3_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace standardLayers + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &domainSldProfiles, ::coder:: + array &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (single3.h) diff --git a/RAT/single4.cpp b/RAT/single4.cpp new file mode 100644 index 00000000..dd717479 --- /dev/null +++ b/RAT/single4.cpp @@ -0,0 +1,336 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single4.cpp +// +// Code generation for function 'single4' +// + +// Include files +#include "single4.h" +#include "RATMain_internal_types.h" +#include "RATMain_rtwutil.h" +#include "RATMain_types.h" +#include "averageReflectivity.h" +#include "backSort.h" +#include "chiSquared.h" +#include "coreLayersCalculation.h" +#include "processCustomFunction2.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include "coder_bounded_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace customLayers + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &domainSldProfiles, ::coder:: + array &allLayers, ::coder::array + &allRoughs) + { + ::coder::array r; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; + ::coder::array calcAllLayers; + ::coder::array a__5; + ::coder::array reflect1; + ::coder::array reflect2; + ::coder::array shiftedDat; + ::coder::array simul1; + ::coder::array simul2; + ::coder::array totReflect; + cell_wrap_8 r1; + cell_wrap_8 r2; + cell_wrap_8 r3; + cell_wrap_8 r4; + cell_wrap_8 r5; + cell_wrap_8 r6; + real_T a__4; + real_T a__6; + real_T a__7; + real_T thisBackground; + real_T thisBulkIn; + real_T thisBulkOut; + real_T thisQzshift; + real_T thisResol; + real_T thisScalefactor; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + int32_T nParams; + boolean_T calcSld; + boolean_T useImaginary; + + // Single threaded version of the custom layers, domainsTF reflectivity + // calculation. The function extracts the relevant parameters from the input + // arrays, allocates these on a pre-contrast basis, then calls the 'core' + // calculation (the core layers domainsTF calc is shared between multiple + // calculation types). + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + nParams = problemDef->params.size(1); + calcSld = controls->calcSldDuringFit; + useImaginary = problemDef->useImaginary; + + // Default for compile. + // Pre-Allocation of output arrays... + i = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(i); + + // Resampling parameters + // Process the custom models.... + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + problemDef->useImaginary, r, allRoughs); + cast(r, calcAllLayers); + + // Parallel over all contrasts + // layersCounter = 1; + outSsubs.set_size(i); + tempSldProfiles.set_size(i); + reflectivity.set_size(i); + simulation.set_size(i); + shiftedData.set_size(i); + tempLayerSlds.set_size(i); + tempAllLayers.set_size(i); + chis.set_size(i); + qzshifts.set_size(i); + scalefactors.set_size(i); + bulkIns.set_size(i); + bulkOuts.set_size(i); + resolutionParams.set_size(i); + layerSlds.set_size(i, 2); + domainSldProfiles.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T b_dv[2]; + real_T b_dv1[2]; + real_T dv2[2]; + + // Get the domain ratio for this contrast + // Extract the relevant parameter values for this contrast + // from the input arrays. + // First need to decide which values of the backgrounds, scalefactors + // data shifts and bulk contrasts are associated with this contrast + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, + &thisBulkOut, &thisResol); + + // Get the custom layers output for this contrast + // We have two for each contrast - one for each domain + // For the other parameters, we extract the correct ones from the input + // arrays + // Now call the core layers reflectivity calculation + // In this case we are single cored, so we do not parallelise over + // points + // Call the reflectivity calculation for each domain + // Domain 1 + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + nonPolarisedTF::coreLayersCalculation(calcAllLayers[b_i].f1, + allRoughs[b_i], problemDef->geometry.data, problemDef->geometry.size, + thisBulkIn, thisBulkOut, problemDef->resample[b_i], calcSld, + thisScalefactor, thisQzshift, problemDef->dataPresent[b_i], + problemDefCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, + thisResol, problemDef->contrastBackgroundsType[b_i], + static_cast(nParams), controls->resamPars, useImaginary, + r1.f1, reflect1, simul1, shiftedDat, r2.f1, r3.f1, &a__4, + &outSsubs[b_i]); + + // Domain 2 + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + dv2[0] = problemDefCells->f1[b_i].f1[0]; + dv2[1] = problemDefCells->f1[b_i].f1[1]; + nonPolarisedTF::coreLayersCalculation(calcAllLayers[b_i + + calcAllLayers.size(0)].f1, allRoughs[b_i], problemDef->geometry.data, + problemDef->geometry.size, thisBulkIn, thisBulkOut, + problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, + b_dv1, dv2, thisBackground, thisResol, + problemDef->contrastBackgroundsType[b_i], static_cast + (nParams), controls->resamPars, useImaginary, r4.f1, reflect2, + simul2, a__5, r5.f1, r6.f1, &a__6, &a__7); + + // Calculate the average reflectivities.... + averageReflectivity(reflect1, reflect2, simul1, simul2, + problemDef->domainRatio[static_cast + (problemDef->contrastDomainRatios[b_i]) - 1], + totReflect, simulation[b_i].f1); + + // Get an overall chi-squared for the new averaged curve.. + chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast + (problemDef->params.size(1))); + + // Store returned values for this contrast in the output arrays. + // As well as the calculated profiles, we also store a record of + // the other values (background, scalefactors etc) for each contrast + // for future use. + tempSldProfiles[b_i].f1[0] = r1; + tempSldProfiles[b_i].f1[1] = r4; + reflectivity[b_i].f1.set_size(totReflect.size(0), 2); + loop_ub = totReflect.size(0); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1] = + totReflect[i2 + totReflect.size(0) * i1]; + } + } + + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + loop_ub = shiftedDat.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + tempLayerSlds[b_i].f1[0] = r2; + tempLayerSlds[b_i].f1[1] = r5; + tempAllLayers[b_i].f1[0] = r3; + tempAllLayers[b_i].f1[1] = r6; + backgroundParams[b_i] = thisBackground; + qzshifts[b_i] = thisQzshift; + scalefactors[b_i] = thisScalefactor; + bulkIns[b_i] = thisBulkIn; + bulkOuts[b_i] = thisBulkOut; + resolutionParams[b_i] = thisResol; + } + + allLayers.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + loop_ub = tempSldProfiles[b_i].f1[0].f1.size(1); + domainSldProfiles[b_i].f1.set_size(tempSldProfiles[b_i].f1[0].f1.size + (0), tempSldProfiles[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i].f1[i2 + domainSldProfiles[b_i].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[0].f1[i2 + tempSldProfiles[b_i] + .f1[0].f1.size(0) * i1]; + } + } + + loop_ub = tempSldProfiles[b_i].f1[1].f1.size(1); + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.set_size + (tempSldProfiles[b_i].f1[1].f1.size(0), tempSldProfiles[b_i].f1[1]. + f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i2 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[1].f1[i2 + tempSldProfiles[b_i] + .f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[0].f1.size(1); + allLayers[b_i].f1.set_size(tempAllLayers[b_i].f1[0].f1.size(0), + tempAllLayers[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + tempAllLayers[b_i].f1[0].f1[i2 + tempAllLayers[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[1].f1.size(1); + allLayers[b_i + allLayers.size(0)].f1.set_size(tempAllLayers[b_i].f1[1] + .f1.size(0), tempAllLayers[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i + allLayers.size(0)].f1[i2 + allLayers[b_i + + allLayers.size(0)].f1.size(0) * i1] = tempAllLayers[b_i].f1[1]. + f1[i2 + tempAllLayers[b_i].f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[0].f1.size(1); + layerSlds[b_i].f1.set_size(tempLayerSlds[b_i].f1[0].f1.size(0), + tempLayerSlds[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = + tempLayerSlds[b_i].f1[0].f1[i2 + tempLayerSlds[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[1].f1.size(1); + layerSlds[b_i + layerSlds.size(0)].f1.set_size(tempLayerSlds[b_i].f1[1] + .f1.size(0), tempLayerSlds[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i + layerSlds.size(0)].f1[i2 + layerSlds[b_i + + layerSlds.size(0)].f1.size(0) * i1] = tempLayerSlds[b_i].f1[1]. + f1[i2 + tempLayerSlds[b_i].f1[1].f1.size(0) * i1]; + } + } + } + } + } + } +} + +// End of code generation (single4.cpp) diff --git a/RAT/single4.h b/RAT/single4.h new file mode 100644 index 00000000..9cbb4ced --- /dev/null +++ b/RAT/single4.h @@ -0,0 +1,52 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single4.h +// +// Code generation for function 'single4' +// +#ifndef SINGLE4_H +#define SINGLE4_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace customLayers + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &domainSldProfiles, ::coder:: + array &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (single4.h) diff --git a/RAT/single5.cpp b/RAT/single5.cpp new file mode 100644 index 00000000..38116f98 --- /dev/null +++ b/RAT/single5.cpp @@ -0,0 +1,407 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single5.cpp +// +// Code generation for function 'single5' +// + +// Include files +#include "single5.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "applyBackgroundCorrection.h" +#include "averageReflectivity.h" +#include "backSort.h" +#include "callReflectivity.h" +#include "chiSquared.h" +#include "processCustomFunction3.h" +#include "resampleLayers.h" +#include "resampleLayersReIm.h" +#include "rt_nonfinite.h" +#include "shiftData.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace domainsTF + { + namespace customXY + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &domainSldProfiles, ::coder:: + array &allLayers, ::coder::array + &allRoughs) + { + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; + ::coder::array b_domainSldProfiles; + ::coder::array b_problemDefCells; + ::coder::array c_domainSldProfiles; + ::coder::array r4; + ::coder::array reflect1; + ::coder::array reflect2; + ::coder::array shiftedDat; + ::coder::array simul1; + ::coder::array simul2; + ::coder::array totReflect; + cell_wrap_8 r; + cell_wrap_8 r1; + cell_wrap_8 r2; + cell_wrap_8 r3; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + boolean_T useImaginary; + + // Extract individual cell arrays + // Splits up the master input list of all arrays into separate arrays + // + // INPUTS: + // * problemDefCells: cell array where all the project data is grouped together. + // + // OUTPUTS: + // * repeatLayers: controls repeating of the layers stack. + // * allData: Array of all the data arrays. + // * dataLimits: Min max limits in q for the data arrays. + // * simLimits: Limits in Q for the reflectivity simulations. + // * layersDetails: Master array of all available layers. + // * contrastLayers: Which specific combination of arrays are needed for each contrast. + // * customFiles:Filenames and path for any custom files used. + // % Layers details N/A + // Extract individual parameters from problemDef struct + // Extract individual parameters from problemDef + // Pre-Allocation... + i = static_cast(problemDef->numberOfContrasts); + backgroundParams.set_size(i); + + // Resampling parameters + useImaginary = problemDef->useImaginary; + + // Default for compile. + processCustomFunction(problemDef->contrastBackgrounds, + problemDef->contrastQzshifts, + problemDef->contrastScalefactors, + problemDef->contrastBulkIns, + problemDef->contrastBulkOuts, + problemDef->contrastResolutions, + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + problemDef->contrastCustomFiles, + problemDef->numberOfContrasts, + problemDefCells->f14, problemDef->params, + domainSldProfiles, allRoughs); + outSsubs.set_size(i); + qzshifts.set_size(i); + scalefactors.set_size(i); + bulkIns.set_size(i); + bulkOuts.set_size(i); + resolutionParams.set_size(i); + tempLayerSlds.set_size(i); + tempAllLayers.set_size(i); + tempSldProfiles.set_size(i); + shiftedData.set_size(i); + reflectivity.set_size(i); + simulation.set_size(i); + chis.set_size(i); + layerSlds.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T b_dv[2]; + real_T b_dv1[2]; + outSsubs[b_i] = allRoughs[b_i]; + backSort(problemDef->contrastBackgrounds[b_i], + problemDef->contrastQzshifts[b_i], + problemDef->contrastScalefactors[b_i], + problemDef->contrastBulkIns[b_i], + problemDef->contrastBulkOuts[b_i], + problemDef->contrastResolutions[b_i], + problemDef->backgroundParams, problemDef->qzshifts, + problemDef->scalefactors, problemDef->bulkIn, + problemDef->bulkOut, problemDef->resolutionParams, + &backgroundParams[b_i], &qzshifts[b_i], &scalefactors[b_i], + &bulkIns[b_i], &bulkOuts[b_i], &resolutionParams[b_i]); + + // Get the domain ratio for this contrast + // Resample the sld profiles + if (!useImaginary) { + resampleLayers(domainSldProfiles[0].f1, controls->resamPars, r.f1); + r1.f1.set_size(r.f1.size(0), 3); + for (int32_T i1{0}; i1 < 3; i1++) { + loop_ub = r.f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + r1.f1[i2 + r1.f1.size(0) * i1] = r.f1[i2 + r.f1.size(0) * i1]; + } + } + + resampleLayers(domainSldProfiles[1].f1, controls->resamPars, r.f1); + } else { + loop_ub = domainSldProfiles[0].f1.size(0); + b_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = + domainSldProfiles[0].f1[i2 + domainSldProfiles[0].f1.size(0) * + i1]; + } + } + + loop_ub = domainSldProfiles[0].f1.size(0); + b_loop_ub = domainSldProfiles[0].f1.size(0); + c_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[0].f1[i1]; + } + + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = + domainSldProfiles[0].f1[i1 + domainSldProfiles[0].f1.size(0) * 2]; + } + + c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + controls->resamPars, r.f1); + r1.f1.set_size(r.f1.size(0), 4); + for (int32_T i1{0}; i1 < 4; i1++) { + loop_ub = r.f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + r1.f1[i2 + r1.f1.size(0) * i1] = r.f1[i2 + r.f1.size(0) * i1]; + } + } + + loop_ub = domainSldProfiles[1].f1.size(0); + b_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = + domainSldProfiles[1].f1[i2 + domainSldProfiles[1].f1.size(0) * + i1]; + } + } + + loop_ub = domainSldProfiles[1].f1.size(0); + b_loop_ub = domainSldProfiles[1].f1.size(0); + c_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[1].f1[i1]; + } + + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = + domainSldProfiles[1].f1[i1 + domainSldProfiles[1].f1.size(0) * 2]; + } + + c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + controls->resamPars, r.f1); + } + + tempLayerSlds[b_i].f1[0] = r1; + tempLayerSlds[b_i].f1[1] = r; + tempAllLayers[b_i].f1[0] = r1; + tempAllLayers[b_i].f1[1] = r; + r2.f1.set_size(domainSldProfiles[0].f1.size(0), domainSldProfiles[0]. + f1.size(1)); + loop_ub = domainSldProfiles[0].f1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = domainSldProfiles[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + r2.f1[i2 + r2.f1.size(0) * i1] = domainSldProfiles[0].f1[i2 + + domainSldProfiles[0].f1.size(0) * i1]; + } + } + + r3.f1.set_size(domainSldProfiles[1].f1.size(0), domainSldProfiles[1]. + f1.size(1)); + loop_ub = domainSldProfiles[1].f1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = domainSldProfiles[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + r3.f1[i2 + r3.f1.size(0) * i1] = domainSldProfiles[1].f1[i2 + + domainSldProfiles[1].f1.size(0) * i1]; + } + } + + tempSldProfiles[b_i].f1[0] = r2; + tempSldProfiles[b_i].f1[1] = r3; + b_problemDefCells.set_size(problemDefCells->f2 + [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> + f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); + loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { + b_problemDefCells[i2 + b_problemDefCells.size(0) * i1] = + problemDefCells->f2[b_i].f1[i2 + problemDefCells->f2[b_i]. + f1.size(0) * i1]; + } + } + + b_dv[0] = problemDefCells->f3[b_i].f1[0]; + b_dv[1] = problemDefCells->f3[b_i].f1[1]; + b_dv1[0] = problemDefCells->f4[b_i].f1[0]; + b_dv1[1] = problemDefCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> + dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); + loop_ub = shiftedDat.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = shiftedDat.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1] = + shiftedDat[i2 + shiftedDat.size(0) * i1]; + } + } + + r4.set_size(r1.f1.size(0), r1.f1.size(1)); + loop_ub = r1.f1.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_loop_ub = r1.f1.size(0) - 1; + for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { + r4[i2 + r4.size(0) * i1] = r1.f1[i2 + r1.f1.size(0) * i1]; + } + } + + b_dv[0] = problemDefCells->f4[b_i].f1[0]; + b_dv[1] = problemDefCells->f4[b_i].f1[1]; + b_dv1[0] = problemDefCells->f1[b_i].f1[0]; + b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, + r4, allRoughs[b_i], resolutionParams[b_i], + useImaginary, reflect1, simul1); + r4.set_size(r.f1.size(0), r.f1.size(1)); + loop_ub = r.f1.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_loop_ub = r.f1.size(0) - 1; + for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { + r4[i2 + r4.size(0) * i1] = r.f1[i2 + r.f1.size(0) * i1]; + } + } + + b_dv[0] = problemDefCells->f4[b_i].f1[0]; + b_dv[1] = problemDefCells->f4[b_i].f1[1]; + b_dv1[0] = problemDefCells->f1[b_i].f1[0]; + b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, + r4, allRoughs[b_i], resolutionParams[b_i], + useImaginary, reflect2, simul2); + applyBackgroundCorrection(reflect1, simul1, shiftedDat, + backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + applyBackgroundCorrection(reflect2, simul2, shiftedDat, + backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + + // Calculate the average reflectivities.... + averageReflectivity(reflect1, reflect2, simul1, simul2, + problemDef->domainRatio[static_cast + (problemDef->contrastDomainRatios[b_i]) - 1], + totReflect, simulation[b_i].f1); + loop_ub = totReflect.size(0); + reflectivity[b_i].f1.set_size(totReflect.size(0), 2); + for (int32_T i1{0}; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < loop_ub; i2++) { + reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1] = + totReflect[i2 + totReflect.size(0) * i1]; + } + } + + if (problemDef->dataPresent[b_i] != 0.0) { + chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast + (problemDef->params.size(1))); + } else { + chis[b_i] = 0.0; + } + } + + allLayers.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + loop_ub = tempSldProfiles[b_i].f1[0].f1.size(1); + domainSldProfiles[b_i].f1.set_size(tempSldProfiles[b_i].f1[0].f1.size + (0), tempSldProfiles[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i].f1[i2 + domainSldProfiles[b_i].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[0].f1[i2 + tempSldProfiles[b_i] + .f1[0].f1.size(0) * i1]; + } + } + + loop_ub = tempSldProfiles[b_i].f1[1].f1.size(1); + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.set_size + (tempSldProfiles[b_i].f1[1].f1.size(0), tempSldProfiles[b_i].f1[1]. + f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempSldProfiles[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i2 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + i1] = tempSldProfiles[b_i].f1[1].f1[i2 + tempSldProfiles[b_i] + .f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[0].f1.size(1); + allLayers[b_i].f1.set_size(tempAllLayers[b_i].f1[0].f1.size(0), + tempAllLayers[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = + tempAllLayers[b_i].f1[0].f1[i2 + tempAllLayers[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempAllLayers[b_i].f1[1].f1.size(1); + allLayers[b_i + allLayers.size(0)].f1.set_size(tempAllLayers[b_i].f1[1] + .f1.size(0), tempAllLayers[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempAllLayers[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + allLayers[b_i + allLayers.size(0)].f1[i2 + allLayers[b_i + + allLayers.size(0)].f1.size(0) * i1] = tempAllLayers[b_i].f1[1]. + f1[i2 + tempAllLayers[b_i].f1[1].f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[0].f1.size(1); + layerSlds[b_i].f1.set_size(tempLayerSlds[b_i].f1[0].f1.size(0), + tempLayerSlds[b_i].f1[0].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[0].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = + tempLayerSlds[b_i].f1[0].f1[i2 + tempLayerSlds[b_i].f1[0]. + f1.size(0) * i1]; + } + } + + loop_ub = tempLayerSlds[b_i].f1[1].f1.size(1); + layerSlds[b_i + layerSlds.size(0)].f1.set_size(tempLayerSlds[b_i].f1[1] + .f1.size(0), tempLayerSlds[b_i].f1[1].f1.size(1)); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = tempLayerSlds[b_i].f1[1].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + layerSlds[b_i + layerSlds.size(0)].f1[i2 + layerSlds[b_i + + layerSlds.size(0)].f1.size(0) * i1] = tempLayerSlds[b_i].f1[1]. + f1[i2 + tempLayerSlds[b_i].f1[1].f1.size(0) * i1]; + } + } + } + } + } + } +} + +// End of code generation (single5.cpp) diff --git a/RAT/single5.h b/RAT/single5.h new file mode 100644 index 00000000..139729ec --- /dev/null +++ b/RAT/single5.h @@ -0,0 +1,52 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// single5.h +// +// Code generation for function 'single5' +// +#ifndef SINGLE5_H +#define SINGLE5_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_14; +} + +// Function Declarations +namespace RAT +{ + namespace domainsTF + { + namespace customXY + { + void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + const struct2_T *controls, ::coder::array + &outSsubs, ::coder::array &backgroundParams, :: + coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: + coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: + coder::array &reflectivity, ::coder::array< + cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, + ::coder::array &domainSldProfiles, ::coder:: + array &allLayers, ::coder::array + &allRoughs); + } + } +} + +#endif + +// End of code generation (single5.h) diff --git a/RAT/sort.cpp b/RAT/sort.cpp new file mode 100644 index 00000000..74681592 --- /dev/null +++ b/RAT/sort.cpp @@ -0,0 +1,338 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sort.cpp +// +// Code generation for function 'sort' +// + +// Include files +#include "sort.h" +#include "nonSingletonDim.h" +#include "rt_nonfinite.h" +#include "sortIdx.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + void b_sort(::coder::array &x, ::coder::array + &idx) + { + ::coder::array vwork; + ::coder::array iidx; + int32_T dim; + int32_T i; + int32_T lowerDim; + int32_T npages; + int32_T vlen; + int32_T vstride; + dim = nonSingletonDim(x) - 1; + vlen = x.size(dim) - 1; + vwork.set_size(x.size(dim)); + idx.set_size(x.size(0), x.size(1)); + vstride = 1; + i = static_cast(dim); + for (int32_T k{0}; k < i; k++) { + vstride *= x.size(0); + } + + npages = 1; + lowerDim = dim + 2; + for (int32_T k{lowerDim}; k < 3; k++) { + npages *= x.size(1); + } + + lowerDim = x.size(dim) * vstride; + for (int32_T b_i{0}; b_i < npages; b_i++) { + dim = b_i * lowerDim; + for (int32_T j{0}; j < vstride; j++) { + int32_T idx0; + idx0 = dim + j; + for (int32_T k{0}; k <= vlen; k++) { + vwork[k] = x[idx0 + k * vstride]; + } + + b_sortIdx(vwork, iidx); + for (int32_T k{0}; k <= vlen; k++) { + i = idx0 + k * vstride; + x[i] = vwork[k]; + idx[i] = iidx[k]; + } + } + } + } + + void sort(::coder::array &x, ::coder::array &idx) + { + ::coder::array xwork; + ::coder::array iwork; + real_T x4[4]; + int32_T idx4[4]; + int32_T i1; + int32_T i3; + int32_T i4; + int32_T ib; + int32_T n; + int32_T nNaNs; + int32_T quartetOffset; + ib = x.size(1); + idx.set_size(1, ib); + for (i1 = 0; i1 < ib; i1++) { + idx[i1] = 0; + } + + n = x.size(1); + x4[0] = 0.0; + idx4[0] = 0; + x4[1] = 0.0; + idx4[1] = 0; + x4[2] = 0.0; + idx4[2] = 0; + x4[3] = 0.0; + idx4[3] = 0; + ib = x.size(1); + iwork.set_size(ib); + for (i1 = 0; i1 < ib; i1++) { + iwork[i1] = 0; + } + + ib = x.size(1); + xwork.set_size(ib); + for (i1 = 0; i1 < ib; i1++) { + xwork[i1] = 0.0; + } + + nNaNs = 0; + ib = 0; + for (int32_T k{0}; k < n; k++) { + if (std::isnan(x[k])) { + i3 = (n - nNaNs) - 1; + idx[i3] = k + 1; + xwork[i3] = x[k]; + nNaNs++; + } else { + ib++; + idx4[ib - 1] = k + 1; + x4[ib - 1] = x[k]; + if (ib == 4) { + real_T d; + real_T d1; + int8_T b_i1; + int8_T b_i3; + int8_T i; + int8_T i2; + quartetOffset = k - nNaNs; + if (x4[0] <= x4[1]) { + i1 = 1; + ib = 2; + } else { + i1 = 2; + ib = 1; + } + + if (x4[2] <= x4[3]) { + i3 = 3; + i4 = 4; + } else { + i3 = 4; + i4 = 3; + } + + d = x4[i1 - 1]; + d1 = x4[i3 - 1]; + if (d <= d1) { + d = x4[ib - 1]; + if (d <= d1) { + i = static_cast(i1); + b_i1 = static_cast(ib); + i2 = static_cast(i3); + b_i3 = static_cast(i4); + } else if (d <= x4[i4 - 1]) { + i = static_cast(i1); + b_i1 = static_cast(i3); + i2 = static_cast(ib); + b_i3 = static_cast(i4); + } else { + i = static_cast(i1); + b_i1 = static_cast(i3); + i2 = static_cast(i4); + b_i3 = static_cast(ib); + } + } else { + d1 = x4[i4 - 1]; + if (d <= d1) { + if (x4[ib - 1] <= d1) { + i = static_cast(i3); + b_i1 = static_cast(i1); + i2 = static_cast(ib); + b_i3 = static_cast(i4); + } else { + i = static_cast(i3); + b_i1 = static_cast(i1); + i2 = static_cast(i4); + b_i3 = static_cast(ib); + } + } else { + i = static_cast(i3); + b_i1 = static_cast(i4); + i2 = static_cast(i1); + b_i3 = static_cast(ib); + } + } + + idx[quartetOffset - 3] = idx4[i - 1]; + idx[quartetOffset - 2] = idx4[b_i1 - 1]; + idx[quartetOffset - 1] = idx4[i2 - 1]; + idx[quartetOffset] = idx4[b_i3 - 1]; + x[quartetOffset - 3] = x4[i - 1]; + x[quartetOffset - 2] = x4[b_i1 - 1]; + x[quartetOffset - 1] = x4[i2 - 1]; + x[quartetOffset] = x4[b_i3 - 1]; + ib = 0; + } + } + } + + i4 = x.size(1) - nNaNs; + if (ib > 0) { + int8_T perm[4]; + perm[1] = 0; + perm[2] = 0; + perm[3] = 0; + if (ib == 1) { + perm[0] = 1; + } else if (ib == 2) { + if (x4[0] <= x4[1]) { + perm[0] = 1; + perm[1] = 2; + } else { + perm[0] = 2; + perm[1] = 1; + } + } else if (x4[0] <= x4[1]) { + if (x4[1] <= x4[2]) { + perm[0] = 1; + perm[1] = 2; + perm[2] = 3; + } else if (x4[0] <= x4[2]) { + perm[0] = 1; + perm[1] = 3; + perm[2] = 2; + } else { + perm[0] = 3; + perm[1] = 1; + perm[2] = 2; + } + } else if (x4[0] <= x4[2]) { + perm[0] = 2; + perm[1] = 1; + perm[2] = 3; + } else if (x4[1] <= x4[2]) { + perm[0] = 2; + perm[1] = 3; + perm[2] = 1; + } else { + perm[0] = 3; + perm[1] = 2; + perm[2] = 1; + } + + i1 = static_cast(ib); + for (int32_T k{0}; k < i1; k++) { + i3 = perm[k] - 1; + quartetOffset = (i4 - ib) + k; + idx[quartetOffset] = idx4[i3]; + x[quartetOffset] = x4[i3]; + } + } + + ib = nNaNs >> 1; + for (int32_T k{0}; k < ib; k++) { + quartetOffset = i4 + k; + i1 = idx[quartetOffset]; + i3 = (n - k) - 1; + idx[quartetOffset] = idx[i3]; + idx[i3] = i1; + x[quartetOffset] = xwork[i3]; + x[i3] = xwork[quartetOffset]; + } + + if ((nNaNs & 1) != 0) { + i1 = i4 + ib; + x[i1] = xwork[i1]; + } + + i1 = x.size(1) - nNaNs; + ib = 2; + if (i1 > 1) { + if (x.size(1) >= 256) { + quartetOffset = i1 >> 8; + if (quartetOffset > 0) { + for (ib = 0; ib < quartetOffset; ib++) { + merge_pow2_block(idx, x, ib << 8); + } + + ib = quartetOffset << 8; + quartetOffset = i1 - ib; + if (quartetOffset > 0) { + merge_block(idx, x, ib, quartetOffset, 2, iwork, xwork); + } + + ib = 8; + } + } + + merge_block(idx, x, 0, i1, ib, iwork, xwork); + } + } + + void sort(::coder::array &x, ::coder::array &idx) + { + ::coder::array vwork; + ::coder::array iidx; + int32_T dim; + int32_T i; + int32_T vlen; + int32_T vstride; + dim = nonSingletonDim(x); + if (dim <= 1) { + i = x.size(0); + } else { + i = 1; + } + + vlen = i - 1; + vwork.set_size(i); + idx.set_size(x.size(0)); + vstride = 1; + i = static_cast(dim - 1); + for (dim = 0; dim < i; dim++) { + vstride *= x.size(0); + } + + for (int32_T j{0}; j < vstride; j++) { + for (dim = 0; dim <= vlen; dim++) { + vwork[dim] = x[j + dim * vstride]; + } + + b_sortIdx(vwork, iidx); + for (dim = 0; dim <= vlen; dim++) { + i = j + dim * vstride; + x[i] = vwork[dim]; + idx[i] = iidx[dim]; + } + } + } + } + } +} + +// End of code generation (sort.cpp) diff --git a/RAT/sort.h b/RAT/sort.h new file mode 100644 index 00000000..de2ea93a --- /dev/null +++ b/RAT/sort.h @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sort.h +// +// Code generation for function 'sort' +// +#ifndef SORT_H +#define SORT_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void b_sort(::coder::array &x, ::coder::array + &idx); + void sort(::coder::array &x, ::coder::array &idx); + void sort(::coder::array &x, ::coder::array &idx); + } + } +} + +#endif + +// End of code generation (sort.h) diff --git a/RAT/sortIdx.cpp b/RAT/sortIdx.cpp index 18880f58..807c17d2 100644 --- a/RAT/sortIdx.cpp +++ b/RAT/sortIdx.cpp @@ -13,6 +13,31 @@ #include "mergesort.h" #include "rt_nonfinite.h" #include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + static void merge(::coder::array &idx, ::coder::array &x, int32_T offset, int32_T np, int32_T nq, ::coder:: + array &iwork, ::coder::array + &xwork); + static void merge(::coder::array &idx, ::coder::array &x, int32_T offset, int32_T np, int32_T nq, ::coder:: + array &iwork, ::coder::array + &xwork); + static void merge_block(::coder::array &idx, ::coder::array< + real_T, 1U> &x, int32_T offset, int32_T n, int32_T preSortLevel, ::coder:: + array &iwork, ::coder::array &xwork); + static void merge_pow2_block(::coder::array &idx, ::coder:: + array &x, int32_T offset); + } + } +} // Function Definitions namespace RAT @@ -21,6 +46,600 @@ namespace RAT { namespace internal { + static void merge(::coder::array &idx, ::coder::array &x, int32_T offset, int32_T np, int32_T nq, ::coder:: + array &iwork, ::coder::array + &xwork) + { + if (nq != 0) { + int32_T iout; + int32_T n_tmp; + int32_T p; + int32_T q; + n_tmp = np + nq; + for (int32_T j{0}; j < n_tmp; j++) { + iout = offset + j; + iwork[j] = idx[iout]; + xwork[j] = x[iout]; + } + + p = 0; + q = np; + iout = offset - 1; + int32_T exitg1; + do { + exitg1 = 0; + iout++; + if (xwork[p] <= xwork[q]) { + idx[iout] = iwork[p]; + x[iout] = xwork[p]; + if (p + 1 < np) { + p++; + } else { + exitg1 = 1; + } + } else { + idx[iout] = iwork[q]; + x[iout] = xwork[q]; + if (q + 1 < n_tmp) { + q++; + } else { + q = iout - p; + for (int32_T j{p + 1}; j <= np; j++) { + iout = q + j; + idx[iout] = iwork[j - 1]; + x[iout] = xwork[j - 1]; + } + + exitg1 = 1; + } + } + } while (exitg1 == 0); + } + } + + static void merge(::coder::array &idx, ::coder::array &x, int32_T offset, int32_T np, int32_T nq, ::coder:: + array &iwork, ::coder::array + &xwork) + { + if (nq != 0) { + int32_T iout; + int32_T n_tmp; + int32_T p; + int32_T q; + n_tmp = np + nq; + for (int32_T j{0}; j < n_tmp; j++) { + iout = offset + j; + iwork[j] = idx[iout]; + xwork[j] = x[iout]; + } + + p = 0; + q = np; + iout = offset - 1; + int32_T exitg1; + do { + exitg1 = 0; + iout++; + if (xwork[p] <= xwork[q]) { + idx[iout] = iwork[p]; + x[iout] = xwork[p]; + if (p + 1 < np) { + p++; + } else { + exitg1 = 1; + } + } else { + idx[iout] = iwork[q]; + x[iout] = xwork[q]; + if (q + 1 < n_tmp) { + q++; + } else { + q = iout - p; + for (int32_T j{p + 1}; j <= np; j++) { + iout = q + j; + idx[iout] = iwork[j - 1]; + x[iout] = xwork[j - 1]; + } + + exitg1 = 1; + } + } + } while (exitg1 == 0); + } + } + + static void merge_block(::coder::array &idx, ::coder::array< + real_T, 1U> &x, int32_T offset, int32_T n, int32_T preSortLevel, ::coder:: + array &iwork, ::coder::array &xwork) + { + int32_T bLen; + int32_T nPairs; + nPairs = n >> preSortLevel; + bLen = 1 << preSortLevel; + while (nPairs > 1) { + int32_T nTail; + int32_T tailOffset; + if ((nPairs & 1) != 0) { + nPairs--; + tailOffset = bLen * nPairs; + nTail = n - tailOffset; + if (nTail > bLen) { + merge(idx, x, offset + tailOffset, bLen, nTail - bLen, iwork, + xwork); + } + } + + tailOffset = bLen << 1; + nPairs >>= 1; + for (nTail = 0; nTail < nPairs; nTail++) { + merge(idx, x, offset + nTail * tailOffset, bLen, bLen, iwork, xwork); + } + + bLen = tailOffset; + } + + if (n > bLen) { + merge(idx, x, offset, bLen, n - bLen, iwork, xwork); + } + } + + static void merge_pow2_block(::coder::array &idx, ::coder:: + array &x, int32_T offset) + { + real_T xwork[256]; + int32_T iwork[256]; + for (int32_T b{0}; b < 6; b++) { + int32_T bLen; + int32_T bLen2; + int32_T i; + bLen = 1 << (b + 2); + bLen2 = bLen << 1; + i = 256 >> (b + 3); + for (int32_T k{0}; k < i; k++) { + int32_T blockOffset; + int32_T iout; + int32_T p; + int32_T q; + blockOffset = offset + k * bLen2; + for (int32_T j{0}; j < bLen2; j++) { + iout = blockOffset + j; + iwork[j] = idx[iout]; + xwork[j] = x[iout]; + } + + p = 0; + q = bLen; + iout = blockOffset - 1; + int32_T exitg1; + do { + exitg1 = 0; + iout++; + if (xwork[p] <= xwork[q]) { + idx[iout] = iwork[p]; + x[iout] = xwork[p]; + if (p + 1 < bLen) { + p++; + } else { + exitg1 = 1; + } + } else { + idx[iout] = iwork[q]; + x[iout] = xwork[q]; + if (q + 1 < bLen2) { + q++; + } else { + iout -= p; + for (int32_T j{p + 1}; j <= bLen; j++) { + q = iout + j; + idx[q] = iwork[j - 1]; + x[q] = xwork[j - 1]; + } + + exitg1 = 1; + } + } + } while (exitg1 == 0); + } + } + } + + void b_sortIdx(::coder::array &x, ::coder::array + &idx) + { + ::coder::array b_x; + ::coder::array xwork; + ::coder::array b_idx; + ::coder::array iwork; + int32_T i1; + int32_T ib; + uint32_T unnamed_idx_0; + unnamed_idx_0 = static_cast(x.size(0)); + idx.set_size(static_cast(unnamed_idx_0)); + ib = static_cast(unnamed_idx_0); + for (i1 = 0; i1 < ib; i1++) { + idx[i1] = 0; + } + + if (x.size(0) != 0) { + real_T x4[4]; + int32_T idx4[4]; + int32_T i3; + int32_T i4; + int32_T n; + int32_T nNaNs; + int32_T quartetOffset; + ib = static_cast(unnamed_idx_0); + b_idx.set_size(static_cast(unnamed_idx_0)); + for (i1 = 0; i1 < ib; i1++) { + b_idx[i1] = 0; + } + + b_x.set_size(x.size(0)); + ib = x.size(0); + for (i1 = 0; i1 < ib; i1++) { + b_x[i1] = x[i1]; + } + + n = x.size(0); + x4[0] = 0.0; + idx4[0] = 0; + x4[1] = 0.0; + idx4[1] = 0; + x4[2] = 0.0; + idx4[2] = 0; + x4[3] = 0.0; + idx4[3] = 0; + iwork.set_size(static_cast(unnamed_idx_0)); + ib = static_cast(unnamed_idx_0); + for (i1 = 0; i1 < ib; i1++) { + iwork[i1] = 0; + } + + ib = x.size(0); + xwork.set_size(ib); + for (i1 = 0; i1 < ib; i1++) { + xwork[i1] = 0.0; + } + + nNaNs = 0; + ib = 0; + for (int32_T k{0}; k < n; k++) { + if (std::isnan(b_x[k])) { + i3 = (n - nNaNs) - 1; + b_idx[i3] = k + 1; + xwork[i3] = b_x[k]; + nNaNs++; + } else { + ib++; + idx4[ib - 1] = k + 1; + x4[ib - 1] = b_x[k]; + if (ib == 4) { + real_T d; + real_T d1; + int8_T b_i1; + int8_T b_i3; + int8_T i; + int8_T i2; + quartetOffset = k - nNaNs; + if (x4[0] <= x4[1]) { + i1 = 1; + ib = 2; + } else { + i1 = 2; + ib = 1; + } + + if (x4[2] <= x4[3]) { + i3 = 3; + i4 = 4; + } else { + i3 = 4; + i4 = 3; + } + + d = x4[i1 - 1]; + d1 = x4[i3 - 1]; + if (d <= d1) { + d = x4[ib - 1]; + if (d <= d1) { + i = static_cast(i1); + b_i1 = static_cast(ib); + i2 = static_cast(i3); + b_i3 = static_cast(i4); + } else if (d <= x4[i4 - 1]) { + i = static_cast(i1); + b_i1 = static_cast(i3); + i2 = static_cast(ib); + b_i3 = static_cast(i4); + } else { + i = static_cast(i1); + b_i1 = static_cast(i3); + i2 = static_cast(i4); + b_i3 = static_cast(ib); + } + } else { + d1 = x4[i4 - 1]; + if (d <= d1) { + if (x4[ib - 1] <= d1) { + i = static_cast(i3); + b_i1 = static_cast(i1); + i2 = static_cast(ib); + b_i3 = static_cast(i4); + } else { + i = static_cast(i3); + b_i1 = static_cast(i1); + i2 = static_cast(i4); + b_i3 = static_cast(ib); + } + } else { + i = static_cast(i3); + b_i1 = static_cast(i4); + i2 = static_cast(i1); + b_i3 = static_cast(ib); + } + } + + b_idx[quartetOffset - 3] = idx4[i - 1]; + b_idx[quartetOffset - 2] = idx4[b_i1 - 1]; + b_idx[quartetOffset - 1] = idx4[i2 - 1]; + b_idx[quartetOffset] = idx4[b_i3 - 1]; + b_x[quartetOffset - 3] = x4[i - 1]; + b_x[quartetOffset - 2] = x4[b_i1 - 1]; + b_x[quartetOffset - 1] = x4[i2 - 1]; + b_x[quartetOffset] = x4[b_i3 - 1]; + ib = 0; + } + } + } + + i4 = b_x.size(0) - nNaNs; + if (ib > 0) { + int8_T perm[4]; + perm[1] = 0; + perm[2] = 0; + perm[3] = 0; + if (ib == 1) { + perm[0] = 1; + } else if (ib == 2) { + if (x4[0] <= x4[1]) { + perm[0] = 1; + perm[1] = 2; + } else { + perm[0] = 2; + perm[1] = 1; + } + } else if (x4[0] <= x4[1]) { + if (x4[1] <= x4[2]) { + perm[0] = 1; + perm[1] = 2; + perm[2] = 3; + } else if (x4[0] <= x4[2]) { + perm[0] = 1; + perm[1] = 3; + perm[2] = 2; + } else { + perm[0] = 3; + perm[1] = 1; + perm[2] = 2; + } + } else if (x4[0] <= x4[2]) { + perm[0] = 2; + perm[1] = 1; + perm[2] = 3; + } else if (x4[1] <= x4[2]) { + perm[0] = 2; + perm[1] = 3; + perm[2] = 1; + } else { + perm[0] = 3; + perm[1] = 2; + perm[2] = 1; + } + + i1 = static_cast(ib); + for (int32_T k{0}; k < i1; k++) { + i3 = perm[k] - 1; + quartetOffset = (i4 - ib) + k; + b_idx[quartetOffset] = idx4[i3]; + b_x[quartetOffset] = x4[i3]; + } + } + + ib = nNaNs >> 1; + for (int32_T k{0}; k < ib; k++) { + quartetOffset = i4 + k; + i1 = b_idx[quartetOffset]; + i3 = (n - k) - 1; + b_idx[quartetOffset] = b_idx[i3]; + b_idx[i3] = i1; + b_x[quartetOffset] = xwork[i3]; + b_x[i3] = xwork[quartetOffset]; + } + + if ((nNaNs & 1) != 0) { + ib += i4; + b_x[ib] = xwork[ib]; + } + + i1 = b_x.size(0) - nNaNs; + ib = 2; + if (i1 > 1) { + if (b_x.size(0) >= 256) { + quartetOffset = i1 >> 8; + if (quartetOffset > 0) { + for (ib = 0; ib < quartetOffset; ib++) { + merge_pow2_block(b_idx, b_x, ib << 8); + } + + ib = quartetOffset << 8; + quartetOffset = i1 - ib; + if (quartetOffset > 0) { + merge_block(b_idx, b_x, ib, quartetOffset, 2, iwork, xwork); + } + + ib = 8; + } + } + + merge_block(b_idx, b_x, 0, i1, ib, iwork, xwork); + } + + ib = b_idx.size(0); + for (i1 = 0; i1 < ib; i1++) { + idx[i1] = b_idx[i1]; + } + + ib = b_x.size(0); + for (i1 = 0; i1 < ib; i1++) { + x[i1] = b_x[i1]; + } + } + } + + void merge_block(::coder::array &idx, ::coder::array &x, int32_T offset, int32_T n, int32_T preSortLevel, :: + coder::array &iwork, ::coder::array &xwork) + { + int32_T bLen; + int32_T nPairs; + nPairs = n >> preSortLevel; + bLen = 1 << preSortLevel; + while (nPairs > 1) { + int32_T nTail; + int32_T tailOffset; + if ((nPairs & 1) != 0) { + nPairs--; + tailOffset = bLen * nPairs; + nTail = n - tailOffset; + if (nTail > bLen) { + merge(idx, x, offset + tailOffset, bLen, nTail - bLen, iwork, + xwork); + } + } + + tailOffset = bLen << 1; + nPairs >>= 1; + for (nTail = 0; nTail < nPairs; nTail++) { + merge(idx, x, offset + nTail * tailOffset, bLen, bLen, iwork, xwork); + } + + bLen = tailOffset; + } + + if (n > bLen) { + merge(idx, x, offset, bLen, n - bLen, iwork, xwork); + } + } + + void merge_pow2_block(::coder::array &idx, ::coder::array< + real_T, 2U> &x, int32_T offset) + { + real_T xwork[256]; + int32_T iwork[256]; + for (int32_T b{0}; b < 6; b++) { + int32_T bLen; + int32_T bLen2; + int32_T i; + bLen = 1 << (b + 2); + bLen2 = bLen << 1; + i = 256 >> (b + 3); + for (int32_T k{0}; k < i; k++) { + int32_T blockOffset; + int32_T iout; + int32_T p; + int32_T q; + blockOffset = offset + k * bLen2; + for (int32_T j{0}; j < bLen2; j++) { + iout = blockOffset + j; + iwork[j] = idx[iout]; + xwork[j] = x[iout]; + } + + p = 0; + q = bLen; + iout = blockOffset - 1; + int32_T exitg1; + do { + exitg1 = 0; + iout++; + if (xwork[p] <= xwork[q]) { + idx[iout] = iwork[p]; + x[iout] = xwork[p]; + if (p + 1 < bLen) { + p++; + } else { + exitg1 = 1; + } + } else { + idx[iout] = iwork[q]; + x[iout] = xwork[q]; + if (q + 1 < bLen2) { + q++; + } else { + iout -= p; + for (int32_T j{p + 1}; j <= bLen; j++) { + q = iout + j; + idx[q] = iwork[j - 1]; + x[q] = xwork[j - 1]; + } + + exitg1 = 1; + } + } + } while (exitg1 == 0); + } + } + } + + void sortIdx(const ::coder::array &x, ::coder::array &idx) + { + int32_T loop_ub; + idx.set_size(1, x.size(1)); + loop_ub = x.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + idx[i] = 0; + } + + if (x.size(1) != 0) { + b_mergesort(idx, x, x.size(1)); + } + } + + void sortIdx(const ::coder::array &x, ::coder::array &idx) + { + ::coder::array b_x; + ::coder::array r; + int32_T loop_ub; + idx.set_size(x.size(0)); + loop_ub = x.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + idx[i] = 0; + } + + loop_ub = x.size(0); + r.set_size(x.size(0)); + for (int32_T i{0}; i < loop_ub; i++) { + r[i] = 0; + } + + b_x.set_size(x.size(0)); + loop_ub = x.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + b_x[i] = x[i]; + } + + b_mergesort(r, b_x, x.size(0)); + loop_ub = r.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + idx[i] = r[i]; + } + } + void sortIdx(const ::coder::array &x, const int32_T col_data[], ::coder::array &idx) { diff --git a/RAT/sortIdx.h b/RAT/sortIdx.h index 07071381..1c967d5f 100644 --- a/RAT/sortIdx.h +++ b/RAT/sortIdx.h @@ -23,6 +23,18 @@ namespace RAT { namespace internal { + void b_sortIdx(::coder::array &x, ::coder::array + &idx); + void merge_block(::coder::array &idx, ::coder::array &x, int32_T offset, int32_T n, int32_T preSortLevel, :: + coder::array &iwork, ::coder::array &xwork); + void merge_pow2_block(::coder::array &idx, ::coder::array< + real_T, 2U> &x, int32_T offset); + void sortIdx(const ::coder::array &x, ::coder::array &idx); + void sortIdx(const ::coder::array &x, ::coder::array &idx); void sortIdx(const ::coder::array &x, const int32_T col_data[], ::coder::array &idx); } diff --git a/RAT/sortLE.cpp b/RAT/sortLE.cpp index a861eebb..5f667c05 100644 --- a/RAT/sortLE.cpp +++ b/RAT/sortLE.cpp @@ -22,6 +22,50 @@ namespace RAT { namespace internal { + boolean_T sortLE(const real_T v[4], int32_T idx1, int32_T idx2) + { + real_T d; + boolean_T p; + d = v[idx2 - 1]; + if ((v[idx1 - 1] <= d) || std::isnan(d)) { + p = true; + } else { + p = false; + } + + return p; + } + + boolean_T sortLE(const ::coder::array &v, int32_T idx1, + int32_T idx2) + { + real_T d; + boolean_T p; + d = v[idx2 - 1]; + if ((v[idx1 - 1] <= d) || std::isnan(d)) { + p = true; + } else { + p = false; + } + + return p; + } + + boolean_T sortLE(const ::coder::array &v, int32_T idx1, + int32_T idx2) + { + real_T d; + boolean_T p; + d = v[idx2 - 1]; + if ((v[idx1 - 1] <= d) || std::isnan(d)) { + p = true; + } else { + p = false; + } + + return p; + } + boolean_T sortLE(const ::coder::array &v, const int32_T dir_data[], int32_T idx1, int32_T idx2) { diff --git a/RAT/sortLE.h b/RAT/sortLE.h index a65cb4d6..c0db007b 100644 --- a/RAT/sortLE.h +++ b/RAT/sortLE.h @@ -23,6 +23,11 @@ namespace RAT { namespace internal { + boolean_T sortLE(const real_T v[4], int32_T idx1, int32_T idx2); + boolean_T sortLE(const ::coder::array &v, int32_T idx1, + int32_T idx2); + boolean_T sortLE(const ::coder::array &v, int32_T idx1, + int32_T idx2); boolean_T sortLE(const ::coder::array &v, const int32_T dir_data[], int32_T idx1, int32_T idx2); } diff --git a/RAT/splitEllipsoid.cpp b/RAT/splitEllipsoid.cpp new file mode 100644 index 00000000..9b08aa4e --- /dev/null +++ b/RAT/splitEllipsoid.cpp @@ -0,0 +1,550 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// splitEllipsoid.cpp +// +// Code generation for function 'splitEllipsoid' +// + +// Include files +#include "splitEllipsoid.h" +#include "RATMain_data.h" +#include "RATMain_types.h" +#include "calcEllipsoid.h" +#include "eml_mtimes_helper.h" +#include "ifWhileCond.h" +#include "kmeans.h" +#include "makeCell.h" +#include "minOrMax.h" +#include "mrdivide_helper.h" +#include "mtimes.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + static void binary_expand_op(real_T in1[50], int32_T in2, const real_T + in3_data[], const int32_T in3_size[2], const real_T in4_data[], const + int32_T in4_size[2], real_T in5); +} + +// Function Definitions +namespace RAT +{ + static void binary_expand_op(real_T in1[50], int32_T in2, const real_T + in3_data[], const int32_T in3_size[2], const real_T in4_data[], const + int32_T in4_size[2], real_T in5) + { + real_T b_in3_data; + int32_T aux_0_1; + int32_T aux_1_1; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + stride_0_1 = (in3_size[1] != 1); + stride_1_1 = (in4_size[1] != 1); + aux_0_1 = 0; + aux_1_1 = 0; + if (in4_size[1] == 1) { + loop_ub = in3_size[1]; + } else { + loop_ub = in4_size[1]; + } + + for (int32_T i{0}; i < loop_ub; i++) { + int32_T b_loop_ub; + int32_T i1; + i1 = in4_size[0]; + if (i1 == 1) { + b_loop_ub = in3_size[0]; + } else { + b_loop_ub = i1; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_in3_data = in3_data[in3_size[0] * aux_0_1] + in4_data[in4_size[0] * + aux_1_1]; + } + + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + + in1[in2] = b_in3_data / in5; + } + + void splitEllipsoid(const ::coder::array &u, real_T VS, ::coder:: + array &u1, ::coder::array &u2, + real_T VE1_data[], int32_T VE1_size[2], real_T VE2_data[], + int32_T VE2_size[2], real_T *nosplit) + { + ::coder::array B1; + ::coder::array B2; + ::coder::array b_u; + ::coder::array idx; + ::coder::array mu1; + ::coder::array mu2; + ::coder::array r2; + ::coder::array u1new; + ::coder::array u2new; + ::coder::array r; + ::coder::array r1; + ::coder::array d_tmp_data; + cell_wrap_8 temp_u1_tmp[50]; + real_T mu[2]; + real_T VE1_tmp_data; + real_T b_tmp_data; + real_T flag1; + real_T flag2; + real_T minFS; + real_T tmp_data; + int32_T VE1_tmp_size[2]; + int32_T D; + int32_T N; + int32_T b_nosplit; + int32_T iindx; + boolean_T c_tmp_data; + + // function [u1, u2, VE1, VE2, nosplit] = split_ellipsiod(u, VS) + // + // This function takes in a set of multi-dimensional data points u and the + // sample volume (VS) that they occupy. It uses the k-means algorthim to + // split the points into two sub-clusters and uses an optimisation scheme to + // re-assign points, if necessary, between the sub-clusters. This is based + // on the description in Algorithm 1 of the MULTINEST paper by Feroz, + // Hobson, and Bridges, MNRAS, 398, 1601-1614 (2009). + // + // The function returns the points in the two sub-cluster u1 and u2, and + // the volumes of the ellipsoid subclusters VE1 and VE2. The flag nosplit + // is set to 1 if the splitting cannot be done; otherwise = 0. + // + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // maximum number of attempts to recluster points + // default return values + b_nosplit = 0; + VE1_tmp_size[0] = 0; + VE1_tmp_size[1] = 0; + VE1_size[0] = 0; + VE1_size[1] = 0; + VE2_size[0] = 0; + VE2_size[1] = 0; + u1.set_size(0, 0); + u2.set_size(0, 0); + + // extract number of samples and number of dimensions + N = u.size(0); + D = u.size(1); + + // check total number of samples + if (u.size(0) < 2.0 * (static_cast(u.size(1)) + 1.0)) { + if (DEBUG != 0.0) { + printf("CANT SPLIT: total number of samples is too small! N = %d\n", + u.size(0)); + fflush(stdout); + } + + b_nosplit = 1; + } else { + int32_T b_loop_ub; + int32_T end; + int32_T loop_ub; + int32_T n1; + int32_T n2; + + // use kmeans to separate the data points into two sub-clusters + kmeans(u, idx, mu); + end = (idx.size(1) << 1) - 1; + iindx = 0; + for (int32_T i{0}; i <= end; i++) { + if (idx[i] == 1.0) { + iindx++; + } + } + + r.set_size(iindx); + iindx = 0; + for (int32_T i{0}; i <= end; i++) { + if (idx[i] == 1.0) { + r[iindx] = i + 1; + iindx++; + } + } + + u1.set_size(r.size(0), u.size(1)); + loop_ub = u.size(1); + for (int32_T b_i{0}; b_i < loop_ub; b_i++) { + b_loop_ub = r.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + u1[i1 + u1.size(0) * b_i] = u[(r[i1] + u.size(0) * b_i) - 1]; + } + } + + end = (idx.size(1) << 1) - 1; + iindx = 0; + for (int32_T i{0}; i <= end; i++) { + if (idx[i] == 2.0) { + iindx++; + } + } + + r1.set_size(iindx); + iindx = 0; + for (int32_T i{0}; i <= end; i++) { + if (idx[i] == 2.0) { + r1[iindx] = i + 1; + iindx++; + } + } + + u2.set_size(r1.size(0), u.size(1)); + loop_ub = u.size(1); + for (int32_T b_i{0}; b_i < loop_ub; b_i++) { + b_loop_ub = r1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + u2[i1 + u2.size(0) * b_i] = u[(r1[i1] + u.size(0) * b_i) - 1]; + } + } + + n1 = r.size(0); + + // number of samples in S1 + n2 = r1.size(0); + + // number of samples in S2 + // check number of points in subclusters + if ((static_cast(r.size(0)) < static_cast(u.size(1)) + + 1U) || (static_cast(r1.size(0)) < static_cast + (u.size(1)) + 1U)) { + if (DEBUG != 0.0) { + printf("CANT SPLIT: number of samples in subclusters is too small! n1 = %d, n2 = %d\n", + r.size(0), r1.size(0)); + fflush(stdout); + } + + b_nosplit = 1; + } else { + cell_wrap_8 temp_u2[50]; + real_T FS[50]; + real_T temp_VE1[50]; + real_T temp_VE2[50]; + int32_T counter; + + // preallocate temp arrays + makeCell(temp_u1_tmp); + for (int32_T i{0}; i < 50; i++) { + temp_u2[i] = temp_u1_tmp[i]; + temp_VE1[i] = 0.0; + temp_VE2[i] = 0.0; + FS[i] = 0.0; + } + + // %%%%%%%%%%%%%%%%%%%%%%%%% + counter = 0; + real_T VS1; + real_T VS2; + int32_T exitg1; + do { + exitg1 = 0; + + // calculate minimum volume of ellipsoids + VS1 = VS * static_cast(n1) / static_cast(N); + VS2 = VS * static_cast(n2) / static_cast(N); + + // calculate properties of bounding ellipsoids for the two subclusters + calcEllipsoid(u1, VS1, B1, mu1, VE1_data, VE1_size, &flag1); + calcEllipsoid(u2, VS2, B2, mu2, VE2_data, VE2_size, &flag2); + + // check flags + if ((flag1 != 0.0) || (flag2 != 0.0)) { + if (DEBUG != 0.0) { + printf("CANT SPLIT!!\n"); + fflush(stdout); + } + + b_nosplit = 1; + exitg1 = 1; + } else { + int32_T reassign; + uint32_T m1; + uint32_T m2; + + // construct temporary arrays and cell arrays containing results for + // each pass through the loop + temp_u1_tmp[counter].f1.set_size(u1.size(0), u1.size(1)); + loop_ub = u1.size(1); + for (int32_T b_i{0}; b_i < loop_ub; b_i++) { + b_loop_ub = u1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + temp_u1_tmp[counter].f1[i1 + temp_u1_tmp[counter].f1.size(0) * + b_i] = u1[i1 + u1.size(0) * b_i]; + } + } + + temp_u2[counter].f1.set_size(u2.size(0), u2.size(1)); + loop_ub = u2.size(1); + for (int32_T b_i{0}; b_i < loop_ub; b_i++) { + b_loop_ub = u2.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + temp_u2[counter].f1[i1 + temp_u2[counter].f1.size(0) * b_i] = + u2[i1 + u2.size(0) * b_i]; + } + } + + temp_VE1[counter] = VE1_data[0]; + temp_VE2[counter] = VE2_data[0]; + if ((VE1_size[0] == VE2_size[0]) && (VE1_size[1] == VE2_size[1])) { + FS[counter] = (VE1_data[0] + VE2_data[0]) / VS; + } else { + binary_expand_op(FS, counter, VE1_data, VE1_size, VE2_data, + VE2_size, VS); + } + + // DEBUG print statement + // if DEBUG + // fprintf('SPLIT ELLIPSOID: counter = %d, numreassigned = %d\n', ... + // int32(counter), int32(numreassigned)); + // end + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + // check if points need to be reassigned to the other subcluster + reassign = 0; + m1 = 0U; + m2 = 0U; + u1new.set_size(N, D); + u2new.set_size(N, D); + for (int32_T b_i{0}; b_i < D; b_i++) { + for (int32_T i1{0}; i1 < N; i1++) { + u1new[i1 + u1new.size(0) * b_i] = 0.0; + u2new[i1 + u2new.size(0) * b_i] = 0.0; + } + } + + // for all points get the Mahalanobis distance between each point and + // the centroid of each ellipse and assign accordingly + loop_ub = u.size(1); + b_loop_ub = u.size(1); + iindx = u.size(1); + end = u.size(1); + for (int32_T i{0}; i < N; i++) { + int32_T b_tmp_size[2]; + int32_T tmp_size[2]; + int32_T c_loop_ub; + int32_T tmp_size_idx_0; + int32_T tmp_size_idx_1; + + // get d = (u-mu)^T * B^-1 * (u-mu) + // calculate hk = VEk * duk / VSk; + if (u.size(1) == mu1.size(1)) { + b_u.set_size(mu1.size(0), u.size(1)); + for (int32_T b_i{0}; b_i < loop_ub; b_i++) { + c_loop_ub = mu1.size(0); + for (int32_T i1{0}; i1 < c_loop_ub; i1++) { + b_u[b_u.size(0) * b_i] = u[i + u.size(0) * b_i] - + mu1[mu1.size(0) * b_i]; + } + } + + coder::internal::mrdiv(b_u, B1, r2); + } else { + c_binary_expand_op(r2, u, i, mu1, B1); + } + + if (u.size(1) == mu1.size(1)) { + b_u.set_size(mu1.size(0), u.size(1)); + for (int32_T b_i{0}; b_i < b_loop_ub; b_i++) { + c_loop_ub = mu1.size(0); + for (int32_T i1{0}; i1 < c_loop_ub; i1++) { + b_u[b_u.size(0) * b_i] = u[i + u.size(0) * b_i] - + mu1[mu1.size(0) * b_i]; + } + } + + coder::internal::blas::mtimes(r2, b_u, (real_T *)&VE1_tmp_data, + VE1_tmp_size); + } else { + c_binary_expand_op((real_T *)&VE1_tmp_data, VE1_tmp_size, r2, u, + i, mu1); + } + + coder::internal::blas::mtimes(VE1_data, VE1_size, (const real_T *) + &VE1_tmp_data, VE1_tmp_size, (real_T *)&tmp_data, tmp_size); + if (u.size(1) == mu2.size(1)) { + b_u.set_size(mu2.size(0), u.size(1)); + for (int32_T b_i{0}; b_i < iindx; b_i++) { + c_loop_ub = mu2.size(0); + for (int32_T i1{0}; i1 < c_loop_ub; i1++) { + b_u[b_u.size(0) * b_i] = u[i + u.size(0) * b_i] - + mu2[mu2.size(0) * b_i]; + } + } + + coder::internal::mrdiv(b_u, B2, r2); + } else { + c_binary_expand_op(r2, u, i, mu2, B2); + } + + if (u.size(1) == mu2.size(1)) { + b_u.set_size(mu2.size(0), u.size(1)); + for (int32_T b_i{0}; b_i < end; b_i++) { + c_loop_ub = mu2.size(0); + for (int32_T i1{0}; i1 < c_loop_ub; i1++) { + b_u[b_u.size(0) * b_i] = u[i + u.size(0) * b_i] - + mu2[mu2.size(0) * b_i]; + } + } + + coder::internal::blas::mtimes(r2, b_u, (real_T *)&VE1_tmp_data, + VE1_tmp_size); + } else { + c_binary_expand_op((real_T *)&VE1_tmp_data, VE1_tmp_size, r2, u, + i, mu2); + } + + coder::internal::blas::mtimes(VE2_data, VE2_size, (const real_T *) + &VE1_tmp_data, VE1_tmp_size, (real_T *)&b_tmp_data, b_tmp_size); + if (b_tmp_size[0] == 1) { + tmp_size_idx_0 = tmp_size[0]; + } else { + tmp_size_idx_0 = b_tmp_size[0]; + } + + if (b_tmp_size[1] == 1) { + tmp_size_idx_1 = tmp_size[1]; + c_loop_ub = tmp_size[1]; + } else { + tmp_size_idx_1 = b_tmp_size[1]; + c_loop_ub = b_tmp_size[1]; + } + + for (int32_T b_i{0}; b_i < c_loop_ub; b_i++) { + int32_T d_loop_ub; + if (b_tmp_size[0] == 1) { + d_loop_ub = tmp_size[0]; + } else { + d_loop_ub = b_tmp_size[0]; + } + + for (int32_T i1{0}; i1 < d_loop_ub; i1++) { + c_tmp_data = (tmp_data / VS1 < b_tmp_data / VS2); + } + } + + d_tmp_data.set(&c_tmp_data, tmp_size_idx_0, tmp_size_idx_1); + if (coder::internal::ifWhileCond(d_tmp_data)) { + m1++; + c_loop_ub = u.size(1); + for (int32_T b_i{0}; b_i < c_loop_ub; b_i++) { + u1new[(static_cast(m1) + u1new.size(0) * b_i) - 1] = + u[i + u.size(0) * b_i]; + } + + // check if point has been reassigned or not + if (idx[i] != 1.0) { + reassign = 1; + idx[i] = 1.0; + } + } else { + m2++; + c_loop_ub = u.size(1); + for (int32_T b_i{0}; b_i < c_loop_ub; b_i++) { + u2new[(static_cast(m2) + u2new.size(0) * b_i) - 1] = + u[i + u.size(0) * b_i]; + } + + // check if point has been reassigned or not + if (idx[i] != 2.0) { + reassign = 1; + idx[i] = 2.0; + } + } + } + + n1 = static_cast(m1); + n2 = static_cast(m2); + if (static_cast(m1) < 1) { + loop_ub = 0; + } else { + loop_ub = static_cast(m1); + } + + u1.set_size(loop_ub, u1new.size(1)); + b_loop_ub = u1new.size(1); + for (int32_T b_i{0}; b_i < b_loop_ub; b_i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + u1[i1 + u1.size(0) * b_i] = u1new[i1 + u1new.size(0) * b_i]; + } + } + + if (static_cast(m2) < 1) { + loop_ub = 0; + } else { + loop_ub = static_cast(m2); + } + + u2.set_size(loop_ub, u2new.size(1)); + b_loop_ub = u2new.size(1); + for (int32_T b_i{0}; b_i < b_loop_ub; b_i++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { + u2[i1 + u2.size(0) * b_i] = u2new[i1 + u2new.size(0) * b_i]; + } + } + + // update counter + counter++; + if ((reassign == 0) || (counter + 1 > 50)) { + // DEBUG print statement + // if DEBUG + // %fprintf('SPLIT ELLIPSOID: counter = %d, FS = %f, numreassigned = %d\n', counter, (VE1+VE2)/VS, numreassigned); + // if counter > max_attempt + // fprintf('SPLIT ELLIPSOID: exceeded maximum attempts; take min F(S).\n'); + // end + // end + exitg1 = 1; + } + } + } while (exitg1 == 0); + + // find minimum F(S) and return + coder::internal::minimum(FS, &minFS, &iindx); + u1.set_size(temp_u1_tmp[iindx - 1].f1.size(0), temp_u1_tmp[iindx - 1]. + f1.size(1)); + loop_ub = temp_u1_tmp[iindx - 1].f1.size(1); + for (int32_T b_i{0}; b_i < loop_ub; b_i++) { + b_loop_ub = temp_u1_tmp[iindx - 1].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + u1[i1 + u1.size(0) * b_i] = temp_u1_tmp[iindx - 1].f1[i1 + + temp_u1_tmp[iindx - 1].f1.size(0) * b_i]; + } + } + + u2.set_size(temp_u2[iindx - 1].f1.size(0), temp_u2[iindx - 1].f1.size(1)); + loop_ub = temp_u2[iindx - 1].f1.size(1); + for (int32_T b_i{0}; b_i < loop_ub; b_i++) { + b_loop_ub = temp_u2[iindx - 1].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + u2[i1 + u2.size(0) * b_i] = temp_u2[iindx - 1].f1[i1 + temp_u2[iindx + - 1].f1.size(0) * b_i]; + } + } + + VE1_size[0] = 1; + VE1_size[1] = 1; + VE1_data[0] = temp_VE1[iindx - 1]; + VE2_size[0] = 1; + VE2_size[1] = 1; + VE2_data[0] = temp_VE2[iindx - 1]; + if (DEBUG != 0.0) { + printf("SPLIT ELLIPSOID: min F(S) = %f\n", minFS); + fflush(stdout); + } + } + } + + *nosplit = b_nosplit; + } +} + +// End of code generation (splitEllipsoid.cpp) diff --git a/RAT/splitEllipsoid.h b/RAT/splitEllipsoid.h new file mode 100644 index 00000000..23c5f1f9 --- /dev/null +++ b/RAT/splitEllipsoid.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// splitEllipsoid.h +// +// Code generation for function 'splitEllipsoid' +// +#ifndef SPLITELLIPSOID_H +#define SPLITELLIPSOID_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void splitEllipsoid(const ::coder::array &u, real_T VS, ::coder:: + array &u1, ::coder::array &u2, + real_T VE1_data[], int32_T VE1_size[2], real_T VE2_data[], + int32_T VE2_size[2], real_T *nosplit); +} + +#endif + +// End of code generation (splitEllipsoid.h) diff --git a/RAT/sprintf.cpp b/RAT/sprintf.cpp new file mode 100644 index 00000000..524788c2 --- /dev/null +++ b/RAT/sprintf.cpp @@ -0,0 +1,73 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sprintf.cpp +// +// Code generation for function 'sprintf' +// + +// Include files +#include "sprintf.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_sprintf(real_T varargin_1, real_T varargin_2, ::coder::array &str) + { + int32_T nbytes; + nbytes = snprintf(nullptr, 0, + "Exiting - X satisfies termination criteria: TolX %e, TolF %e", + varargin_1, varargin_2); + str.set_size(1, nbytes + 1); + snprintf(&str[0], (size_t)(nbytes + 1), + "Exiting - X satisfies termination criteria: TolX %e, TolF %e", + varargin_1, varargin_2); + if (nbytes < 1) { + nbytes = 0; + } + + str.set_size(str.size(0), nbytes); + } + + void snPrint(real_T varargin_2, const ::coder::array &varargin_3, + ::coder::array &str) + { + ::coder::array b_varargin_3; + int32_T loop_ub; + int32_T nbytes; + b_varargin_3.set_size(1, varargin_3.size(1)); + loop_ub = varargin_3.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_varargin_3[i] = varargin_3[i]; + } + + nbytes = snprintf(nullptr, 0, "\n %s %5.1f%% %s", "DREAM: ", varargin_2, + &b_varargin_3[0]); + str.set_size(1, nbytes + 1); + b_varargin_3.set_size(1, varargin_3.size(1)); + loop_ub = varargin_3.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_varargin_3[i] = varargin_3[i]; + } + + snprintf(&str[0], (size_t)(nbytes + 1), "\n %s %5.1f%% %s", "DREAM: ", + varargin_2, &b_varargin_3[0]); + if (nbytes < 1) { + nbytes = 0; + } + + str.set_size(str.size(0), nbytes); + } + } +} + +// End of code generation (sprintf.cpp) diff --git a/RAT/sprintf.h b/RAT/sprintf.h new file mode 100644 index 00000000..cf1bcf69 --- /dev/null +++ b/RAT/sprintf.h @@ -0,0 +1,33 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sprintf.h +// +// Code generation for function 'sprintf' +// +#ifndef SPRINTF_H +#define SPRINTF_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_sprintf(real_T varargin_1, real_T varargin_2, ::coder::array &str); + void snPrint(real_T varargin_2, const ::coder::array &varargin_3, + ::coder::array &str); + } +} + +#endif + +// End of code generation (sprintf.h) diff --git a/RAT/sqrt.cpp b/RAT/sqrt.cpp index e37f343d..01dcb5b8 100644 --- a/RAT/sqrt.cpp +++ b/RAT/sqrt.cpp @@ -10,7 +10,7 @@ // Include files #include "sqrt.h" -#include "reflectivityCalculation_rtwutil.h" +#include "RATMain_rtwutil.h" #include "rt_nonfinite.h" #include @@ -23,7 +23,7 @@ namespace RAT { namespace scalar { - void b_sqrt(creal_T *x) + void d_sqrt(creal_T *x) { real_T absxi; real_T absxr; diff --git a/RAT/sqrt.h b/RAT/sqrt.h index 6348c3b6..3c640d1c 100644 --- a/RAT/sqrt.h +++ b/RAT/sqrt.h @@ -24,7 +24,7 @@ namespace RAT { namespace scalar { - void b_sqrt(creal_T *x); + void d_sqrt(creal_T *x); } } } diff --git a/RAT/sqrt1.cpp b/RAT/sqrt1.cpp new file mode 100644 index 00000000..4402a245 --- /dev/null +++ b/RAT/sqrt1.cpp @@ -0,0 +1,46 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sqrt1.cpp +// +// Code generation for function 'sqrt1' +// + +// Include files +#include "sqrt1.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_sqrt(::coder::array &x) + { + int32_T i; + i = x.size(1); + for (int32_T k{0}; k < i; k++) { + int32_T i1; + i1 = x.size(0); + for (int32_T b_k{0}; b_k < i1; b_k++) { + x[b_k + x.size(0) * k] = std::sqrt(x[b_k + x.size(0) * k]); + } + } + } + + void c_sqrt(::coder::array &x) + { + int32_T i; + i = x.size(1); + for (int32_T k{0}; k < i; k++) { + x[k] = std::sqrt(x[k]); + } + } + } +} + +// End of code generation (sqrt1.cpp) diff --git a/RAT/sqrt1.h b/RAT/sqrt1.h new file mode 100644 index 00000000..ded682bd --- /dev/null +++ b/RAT/sqrt1.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// sqrt1.h +// +// Code generation for function 'sqrt1' +// +#ifndef SQRT1_H +#define SQRT1_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_sqrt(::coder::array &x); + void c_sqrt(::coder::array &x); + } +} + +#endif + +// End of code generation (sqrt1.h) diff --git a/RAT/standardTFCustomLayersParallelContrasts.cpp b/RAT/standardTFCustomLayersParallelContrasts.cpp deleted file mode 100644 index f636eed2..00000000 --- a/RAT/standardTFCustomLayersParallelContrasts.cpp +++ /dev/null @@ -1,227 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomLayersParallelContrasts.cpp -// -// Code generation for function 'standardTFCustomLayersParallelContrasts' -// - -// Include files -#include "standardTFCustomLayersParallelContrasts.h" -#include "backSort.h" -#include "customModelClass.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rt_nonfinite.h" -#include "standardTFLayersCore.h" -#include "coder_array.h" -#include "coder_bounded_array.h" -#include "omp.h" - -// Function Definitions -namespace RAT -{ - void standardTFCustomLayersParallelContrasts(const struct0_T *problemDef, - const cell_19 *problemDefCells, const struct2_T *controls, ::coder::array< - real_T, 1U> &outSsubs, ::coder::array &backgs, ::coder::array< - real_T, 1U> &qshifts, ::coder::array &sfs, ::coder::array &nbas, ::coder::array &nbss, ::coder::array - &resols, ::coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) - { - ::coder::array Simul; - ::coder::array layerSld; - ::coder::array reflect; - ::coder::array resamLayers; - ::coder::array shifted_dat; - ::coder::array sldProfile; - real_T dv[2]; - real_T dv1[2]; - real_T calcSld; - real_T thisBackground; - real_T thisChiSquared; - real_T thisNba; - real_T thisNbs; - real_T thisQshift; - real_T thisResol; - real_T thisSf; - real_T thisSsubs; - int32_T b_i; - int32_T b_loop_ub; - int32_T i1; - int32_T loop_ub; - int32_T nParams; - int32_T ub_loop; - boolean_T useImaginary; - - // Multi threaded version of the custom layers, standardTF reflectivity - // calculation. The function extracts the relevant parameters from the input - // arrays, allocates these on a pre-contrast basis, then calls the 'core' - // calculation (the core layers standardTf calc is shared between multiple - // calculation types). - // Extract individual cell arrays - // Splits up the master input list of all arrays into separate arrays - // The min input array 'problemDefCells' is a master array where - // all the cell arrays are grouped together. There are - // repeatLayers - controls repeating of the layers stack - // allData - Array of all the data arrays - // dataLimits - Min max limits in q for the data arrays - // simLimits - Limits in Q for the reflkectivity simulations - // Layers details - Master array of all available layers - // contrastLayers - Which specific combination of arrays are needed for - // each contrast. - // Custom files - Filenames and path for any custom files used - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); - calcSld = controls->calcSld; - useImaginary = problemDef->useImaginary; - - // Pre-Allocation of output arrays... - backgs.set_size(static_cast(problemDef->numberOfContrasts)); - - // --- End Memory Allocation --- - // Resampling parameters - // Process the custom models.... - customModelClass::processCustomLayers(problemDef->contrastBacks, - problemDef->contrastShifts, problemDef->contrastScales, - problemDef->contrastNbas, problemDef->contrastNbss, - problemDef->contrastRes, problemDef->backs, problemDef->shifts, - problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, - problemDef->contrastCustomFiles, problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, problemDef->useImaginary, - allLayers, allRoughs); - - // Multi cored over all contrasts - outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); - sldProfiles.set_size(static_cast(problemDef->numberOfContrasts)); - reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); - Simulation.set_size(static_cast(problemDef->numberOfContrasts)); - shifted_data.set_size(static_cast(problemDef->numberOfContrasts)); - layerSlds.set_size(static_cast(problemDef->numberOfContrasts)); - chis.set_size(static_cast(problemDef->numberOfContrasts)); - qshifts.set_size(static_cast(problemDef->numberOfContrasts)); - sfs.set_size(static_cast(problemDef->numberOfContrasts)); - nbas.set_size(static_cast(problemDef->numberOfContrasts)); - nbss.set_size(static_cast(problemDef->numberOfContrasts)); - resols.set_size(static_cast(problemDef->numberOfContrasts)); - ub_loop = static_cast(problemDef->numberOfContrasts) - 1; - -#pragma omp parallel for \ - num_threads(omp_get_max_threads()) \ - private(sldProfile,reflect,Simul,shifted_dat,layerSld,resamLayers,thisSsubs,thisChiSquared,thisResol,thisNbs,thisNba,thisSf,thisQshift,thisBackground,dv,dv1,loop_ub,b_i,b_loop_ub,i1) - - for (int32_T i = 0; i <= ub_loop; i++) { - // Extract the relevant parameter values for this contrast - // from the input arrays. - // First need to decide which values of the backrounds, scalefactors - // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBacks[i], problemDef->contrastShifts[i], - problemDef->contrastScales[i], problemDef->contrastNbas[i], - problemDef->contrastNbss[i], problemDef->contrastRes[i], - problemDef->backs, problemDef->shifts, problemDef->sf, - problemDef->nba, problemDef->nbs, problemDef->res, - &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, - &thisResol); - - // Get the custom layers output for this contrast - // For the other parameters, we extract the correct ones from the input - // arrays - // Now call the core standardTF_stanlay reflectivity calculation - // In this case we are single cored, so we do not parallelise over - // points - // Call the reflectivity calculation - dv[0] = problemDefCells->f3[i].f1[0]; - dv[1] = problemDefCells->f3[i].f1[1]; - dv1[0] = problemDefCells->f1[i].f1[0]; - dv1[1] = problemDefCells->f1[i].f1[1]; - standardTFLayersCore(allLayers[i].f1, allRoughs[i], - problemDef->geometry.data, problemDef->geometry.size, - thisNba, thisNbs, problemDef->resample[i], calcSld, - thisSf, thisQshift, problemDef->dataPresent[i], - problemDefCells->f2[i].f1, dv, (const real_T *)((:: - coder::array *)&problemDefCells->f4[i].f1)->data(), dv1, - thisBackground, thisResol, - problemDef->contrastBacksType[i], static_cast - (nParams), controls->resamPars, useImaginary, - sldProfile, reflect, Simul, shifted_dat, layerSld, - resamLayers, &thisChiSquared, &thisSsubs); - - // Store returned values for this contrast in the output arrays. - // As well as the calculated profiles, we also store a record of - // the other values (background, scalefactors etc) for each contrast - // for future use. - outSsubs[i] = thisSsubs; - loop_ub = sldProfile.size(1); - sldProfiles[i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); - for (b_i = 0; b_i < loop_ub; b_i++) { - b_loop_ub = sldProfile.size(0); - for (i1 = 0; i1 < b_loop_ub; i1++) { - sldProfiles[i].f1[i1 + sldProfiles[i].f1.size(0) * b_i] = - sldProfile[i1 + sldProfile.size(0) * b_i]; - } - } - - loop_ub = reflect.size(0); - reflectivity[i].f1.set_size(reflect.size(0), 2); - b_loop_ub = Simul.size(0); - Simulation[i].f1.set_size(Simul.size(0), 2); - for (b_i = 0; b_i < 2; b_i++) { - for (i1 = 0; i1 < loop_ub; i1++) { - reflectivity[i].f1[i1 + reflectivity[i].f1.size(0) * b_i] = reflect[i1 - + reflect.size(0) * b_i]; - } - - for (i1 = 0; i1 < b_loop_ub; i1++) { - Simulation[i].f1[i1 + Simulation[i].f1.size(0) * b_i] = Simul[i1 + - Simul.size(0) * b_i]; - } - } - - loop_ub = shifted_dat.size(1); - shifted_data[i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); - for (b_i = 0; b_i < loop_ub; b_i++) { - b_loop_ub = shifted_dat.size(0); - for (i1 = 0; i1 < b_loop_ub; i1++) { - shifted_data[i].f1[i1 + shifted_data[i].f1.size(0) * b_i] = - shifted_dat[i1 + shifted_dat.size(0) * b_i]; - } - } - - loop_ub = layerSld.size(1); - layerSlds[i].f1.set_size(layerSld.size(0), layerSld.size(1)); - for (b_i = 0; b_i < loop_ub; b_i++) { - b_loop_ub = layerSld.size(0); - for (i1 = 0; i1 < b_loop_ub; i1++) { - layerSlds[i].f1[i1 + layerSlds[i].f1.size(0) * b_i] = layerSld[i1 + - layerSld.size(0) * b_i]; - } - } - - loop_ub = resamLayers.size(1); - allLayers[i].f1.set_size(resamLayers.size(0), resamLayers.size(1)); - for (b_i = 0; b_i < loop_ub; b_i++) { - b_loop_ub = resamLayers.size(0); - for (i1 = 0; i1 < b_loop_ub; i1++) { - allLayers[i].f1[i1 + allLayers[i].f1.size(0) * b_i] = resamLayers[i1 + - resamLayers.size(0) * b_i]; - } - } - - chis[i] = thisChiSquared; - backgs[i] = thisBackground; - qshifts[i] = thisQshift; - sfs[i] = thisSf; - nbas[i] = thisNba; - nbss[i] = thisNbs; - resols[i] = thisResol; - } - } -} - -// End of code generation (standardTFCustomLayersParallelContrasts.cpp) diff --git a/RAT/standardTFCustomLayersParallelContrasts.h b/RAT/standardTFCustomLayersParallelContrasts.h deleted file mode 100644 index 1787781f..00000000 --- a/RAT/standardTFCustomLayersParallelContrasts.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomLayersParallelContrasts.h -// -// Code generation for function 'standardTFCustomLayersParallelContrasts' -// -#ifndef STANDARDTFCUSTOMLAYERSPARALLELCONTRASTS_H -#define STANDARDTFCUSTOMLAYERSPARALLELCONTRASTS_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFCustomLayersParallelContrasts(const struct0_T *problemDef, - const cell_19 *problemDefCells, const struct2_T *controls, ::coder::array< - real_T, 1U> &outSsubs, ::coder::array &backgs, ::coder::array< - real_T, 1U> &qshifts, ::coder::array &sfs, ::coder::array &nbas, ::coder::array &nbss, ::coder::array - &resols, ::coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); -} - -#endif - -// End of code generation (standardTFCustomLayersParallelContrasts.h) diff --git a/RAT/standardTFCustomLayersParallelPoints.cpp b/RAT/standardTFCustomLayersParallelPoints.cpp deleted file mode 100644 index e6ec909a..00000000 --- a/RAT/standardTFCustomLayersParallelPoints.cpp +++ /dev/null @@ -1,191 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomLayersParallelPoints.cpp -// -// Code generation for function 'standardTFCustomLayersParallelPoints' -// - -// Include files -#include "standardTFCustomLayersParallelPoints.h" -#include "backSort.h" -#include "customModelClass.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rt_nonfinite.h" -#include "standardTFLayersCore.h" -#include "coder_array.h" -#include "coder_bounded_array.h" - -// Function Definitions -namespace RAT -{ - void standardTFCustomLayersParallelPoints(const struct0_T *problemDef, const - cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) - { - ::coder::array layerSld; - ::coder::array resamLayers; - ::coder::array shifted_dat; - ::coder::array sldProfile; - real_T thisBackground; - real_T thisNba; - real_T thisNbs; - real_T thisQshift; - real_T thisResol; - real_T thisSf; - int32_T i; - - // Multi threaded version of the custom layers over reflectivity poimnts - // for standardTF reflectivity calculation. - // The function extracts the relevant parameters from the input - // arrays, allocates these on a pre-contrast basis, then calls the 'core' - // calculation (the core layers standardTf calc is shared between multiple - // calculation types). - // Extract individual cell arrays - // Splits up the master input list of all arrays into separate arrays - // The min input array 'problemDefCells' is a master array where - // all the cell arrays are grouped together. There are - // repeatLayers - controls repeating of the layers stack - // allData - Array of all the data arrays - // dataLimits - Min max limits in q for the data arrays - // simLimits - Limits in Q for the reflkectivity simulations - // Layers details - Master array of all available layers - // contrastLayers - Which specific combination of arrays are needed for - // each contrast. - // Custom files - Filenames and path for any custom files used - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - // Pre-Allocation of output arrays... - i = static_cast(problemDef->numberOfContrasts); - backgs.set_size(i); - - // --- End Memory Allocation --- - // Resampling parameters - // Process the custom models.... - customModelClass::processCustomLayers(problemDef->contrastBacks, - problemDef->contrastShifts, problemDef->contrastScales, - problemDef->contrastNbas, problemDef->contrastNbss, - problemDef->contrastRes, problemDef->backs, problemDef->shifts, - problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, - problemDef->contrastCustomFiles, problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, problemDef->useImaginary, - allLayers, allRoughs); - - // Single cored over all contrasts - outSsubs.set_size(i); - sldProfiles.set_size(i); - reflectivity.set_size(i); - Simulation.set_size(i); - shifted_data.set_size(i); - layerSlds.set_size(i); - chis.set_size(i); - qshifts.set_size(i); - sfs.set_size(i); - nbas.set_size(i); - nbss.set_size(i); - resols.set_size(i); - for (int32_T b_i{0}; b_i < i; b_i++) { - real_T dv[2]; - real_T dv1[2]; - int32_T b_loop_ub; - int32_T loop_ub; - - // Extract the relevant parameter values for this contrast - // from the input arrays. - // First need to decide which values of the backrounds, scalefactors - // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], - problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], - problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], - problemDef->backs, problemDef->shifts, problemDef->sf, - problemDef->nba, problemDef->nbs, problemDef->res, - &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, - &thisResol); - - // Get the custom layers output for this contrast - // For the other parameters, we extract the correct ones from the input - // arrays - // Now call the core standardTF_stanlay reflectivity calculation - // In this case we are single cored, so we do not parallelise over - // points - // Call the reflectivity calculation - dv[0] = problemDefCells->f3[b_i].f1[0]; - dv[1] = problemDefCells->f3[b_i].f1[1]; - dv1[0] = problemDefCells->f1[b_i].f1[0]; - dv1[1] = problemDefCells->f1[b_i].f1[1]; - b_standardTFLayersCore(allLayers[b_i].f1, allRoughs[b_i], - problemDef->geometry.data, problemDef->geometry.size, thisNba, thisNbs, - problemDef->resample[b_i], controls->calcSld, thisSf, thisQshift, - problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, dv, (const - real_T *)((::coder::array *)&problemDefCells->f4[b_i].f1) - ->data(), dv1, thisBackground, thisResol, problemDef-> - contrastBacksType[b_i], static_cast(problemDef->params.size(1)), - controls->resamPars, problemDef->useImaginary, sldProfile, - reflectivity[b_i].f1, Simulation[b_i].f1, shifted_dat, layerSld, - resamLayers, &chis[b_i], &outSsubs[b_i]); - - // Store returned values for this contrast in the output arrays. - // As well as the calculated profiles, we also store a record of - // the other values (background, scalefactors etc) for each contrast - // for future use. - loop_ub = sldProfile.size(1); - sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = sldProfile.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = - sldProfile[i2 + sldProfile.size(0) * i1]; - } - } - - loop_ub = shifted_dat.size(1); - shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = shifted_dat.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1] = - shifted_dat[i2 + shifted_dat.size(0) * i1]; - } - } - - loop_ub = layerSld.size(1); - layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = layerSld.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = layerSld[i2 + - layerSld.size(0) * i1]; - } - } - - loop_ub = resamLayers.size(1); - allLayers[b_i].f1.set_size(resamLayers.size(0), resamLayers.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = resamLayers.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = - resamLayers[i2 + resamLayers.size(0) * i1]; - } - } - - backgs[b_i] = thisBackground; - qshifts[b_i] = thisQshift; - sfs[b_i] = thisSf; - nbas[b_i] = thisNba; - nbss[b_i] = thisNbs; - resols[b_i] = thisResol; - } - } -} - -// End of code generation (standardTFCustomLayersParallelPoints.cpp) diff --git a/RAT/standardTFCustomLayersParallelPoints.h b/RAT/standardTFCustomLayersParallelPoints.h deleted file mode 100644 index 7b78d985..00000000 --- a/RAT/standardTFCustomLayersParallelPoints.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomLayersParallelPoints.h -// -// Code generation for function 'standardTFCustomLayersParallelPoints' -// -#ifndef STANDARDTFCUSTOMLAYERSPARALLELPOINTS_H -#define STANDARDTFCUSTOMLAYERSPARALLELPOINTS_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFCustomLayersParallelPoints(const struct0_T *problemDef, const - cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); -} - -#endif - -// End of code generation (standardTFCustomLayersParallelPoints.h) diff --git a/RAT/standardTFCustomLayersReflectivityCalculation.cpp b/RAT/standardTFCustomLayersReflectivityCalculation.cpp deleted file mode 100644 index 5080ad99..00000000 --- a/RAT/standardTFCustomLayersReflectivityCalculation.cpp +++ /dev/null @@ -1,152 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomLayersReflectivityCalculation.cpp -// -// Code generation for function 'standardTFCustomLayersReflectivityCalculation' -// - -// Include files -#include "standardTFCustomLayersReflectivityCalculation.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rt_nonfinite.h" -#include "standardTFCustomLayersParallelContrasts.h" -#include "standardTFCustomLayersParallelPoints.h" -#include "standardTFCustomLayersSingle.h" -#include "strcmp.h" -#include "sum.h" -#include "coder_array.h" -#include "coder_bounded_array.h" - -// Function Definitions -namespace RAT -{ - void standardTFCustomLayersReflectivityCalculation(const struct0_T *problemDef, - const cell_19 *problemDefCells, const struct2_T *controls, struct4_T - *problem, ::coder::array &reflectivity, ::coder::array< - cell_wrap_9, 1U> &Simulation, ::coder::array &shifted_data, - ::coder::array &layerSlds, ::coder::array - &sldProfiles, ::coder::array &allLayers) - { - int32_T loop_ub_tmp; - - // Custom layers reflectivity calculation for standardTF - // This function decides on parallelisation options before calling the - // relevant version of the main custom layers calculation. It is more - // efficient to have multiple versions of the core calculation, each dealing - // with a different scheme for parallelisation. These are: - // single - single threaded teflectivity calculation - // points - parallelise over points in the reflectivity calculation - // contrasts - parallelise over contrasts. - // Pre-allocation - It's necessary to - // pre-allocate the memory for all the arrays - // for compilation, so do this in this block. - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgrounds.set_size(loop_ub_tmp); - problem->qshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->nbairs.set_size(loop_ub_tmp); - problem->nbsubs.set_size(loop_ub_tmp); - problem->calculations.all_chis.set_size(loop_ub_tmp); - problem->resolutions.set_size(loop_ub_tmp); - problem->allSubRough.set_size(loop_ub_tmp); - reflectivity.set_size(loop_ub_tmp); - Simulation.set_size(loop_ub_tmp); - shifted_data.set_size(loop_ub_tmp); - layerSlds.set_size(loop_ub_tmp); - sldProfiles.set_size(loop_ub_tmp); - allLayers.set_size(loop_ub_tmp); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgrounds[i] = 0.0; - problem->qshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->nbairs[i] = 0.0; - problem->nbsubs[i] = 0.0; - problem->calculations.all_chis[i] = 0.0; - problem->resolutions[i] = 0.0; - problem->allSubRough[i] = 0.0; - reflectivity[i].f1.set_size(2, 2); - reflectivity[i].f1[0] = 1.0; - reflectivity[i].f1[1] = 1.0; - reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; - reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; - Simulation[i].f1.set_size(2, 2); - Simulation[i].f1[0] = 1.0; - Simulation[i].f1[1] = 1.0; - Simulation[i].f1[Simulation[i].f1.size(0)] = 1.0; - Simulation[i].f1[Simulation[i].f1.size(0) + 1] = 1.0; - shifted_data[i].f1.set_size(2, 3); - layerSlds[i].f1.set_size(2, 3); - sldProfiles[i].f1.set_size(2, 2); - sldProfiles[i].f1[0] = 1.0; - sldProfiles[i].f1[1] = 1.0; - sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; - sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; - allLayers[i].f1.set_size(2, 3); - for (int32_T b_i{0}; b_i < 3; b_i++) { - shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i] = 1.0; - shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i + 1] = 1.0; - layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; - layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; - allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; - allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; - } - } - - // End pre-allocation - if (coder::internal::f_strcmp(controls->para.data, controls->para.size)) { - loop_ub_tmp = 0; - } else if (coder::internal::g_strcmp(controls->para.data, - controls->para.size)) { - loop_ub_tmp = 1; - } else if (coder::internal::h_strcmp(controls->para.data, - controls->para.size)) { - loop_ub_tmp = 2; - } else { - loop_ub_tmp = -1; - } - - switch (loop_ub_tmp) { - case 0: - standardTFCustomLayersSingle(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgrounds, problem->qshifts, - problem->scalefactors, problem->nbairs, problem->nbsubs, - problem->resolutions, problem->calculations.all_chis, reflectivity, - Simulation, shifted_data, layerSlds, sldProfiles, allLayers, - problem->allSubRough); - break; - - case 1: - standardTFCustomLayersParallelPoints(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgrounds, problem->qshifts, - problem->scalefactors, problem->nbairs, problem->nbsubs, - problem->resolutions, problem->calculations.all_chis, reflectivity, - Simulation, shifted_data, layerSlds, sldProfiles, allLayers, - problem->allSubRough); - break; - - case 2: - standardTFCustomLayersParallelContrasts(problemDef, problemDefCells, - controls, problem->ssubs, problem->backgrounds, problem->qshifts, - problem->scalefactors, problem->nbairs, problem->nbsubs, - problem->resolutions, problem->calculations.all_chis, reflectivity, - Simulation, shifted_data, layerSlds, sldProfiles, allLayers, - problem->allSubRough); - break; - } - - problem->calculations.sum_chi = coder::sum(problem->calculations.all_chis); - problem->resample.set_size(1, problemDef->resample.size(1)); - loop_ub_tmp = problemDef->resample.size(1); - for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - problem->resample[b_i] = problemDef->resample[b_i]; - } - } -} - -// End of code generation (standardTFCustomLayersReflectivityCalculation.cpp) diff --git a/RAT/standardTFCustomLayersReflectivityCalculation.h b/RAT/standardTFCustomLayersReflectivityCalculation.h deleted file mode 100644 index 913dcd12..00000000 --- a/RAT/standardTFCustomLayersReflectivityCalculation.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomLayersReflectivityCalculation.h -// -// Code generation for function 'standardTFCustomLayersReflectivityCalculation' -// -#ifndef STANDARDTFCUSTOMLAYERSREFLECTIVITYCALCULATION_H -#define STANDARDTFCUSTOMLAYERSREFLECTIVITYCALCULATION_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFCustomLayersReflectivityCalculation(const struct0_T *problemDef, - const cell_19 *problemDefCells, const struct2_T *controls, struct4_T - *problem, ::coder::array &reflectivity, ::coder::array< - cell_wrap_9, 1U> &Simulation, ::coder::array &shifted_data, - ::coder::array &layerSlds, ::coder::array - &sldProfiles, ::coder::array &allLayers); -} - -#endif - -// End of code generation (standardTFCustomLayersReflectivityCalculation.h) diff --git a/RAT/standardTFCustomLayersSingle.cpp b/RAT/standardTFCustomLayersSingle.cpp deleted file mode 100644 index 470d6556..00000000 --- a/RAT/standardTFCustomLayersSingle.cpp +++ /dev/null @@ -1,193 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomLayersSingle.cpp -// -// Code generation for function 'standardTFCustomLayersSingle' -// - -// Include files -#include "standardTFCustomLayersSingle.h" -#include "backSort.h" -#include "customModelClass.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rt_nonfinite.h" -#include "standardTFLayersCore.h" -#include "coder_array.h" -#include "coder_bounded_array.h" - -// Function Definitions -namespace RAT -{ - void standardTFCustomLayersSingle(const struct0_T *problemDef, const cell_19 - *problemDefCells, const struct2_T *controls, ::coder::array - &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) - { - ::coder::array layerSld; - ::coder::array resamLayers; - ::coder::array shifted_dat; - ::coder::array sldProfile; - real_T thisBackground; - real_T thisNba; - real_T thisNbs; - real_T thisQshift; - real_T thisResol; - real_T thisSf; - int32_T i; - - // Single threaded version of the custom layers, standardTF reflectivity - // calculation. The function extracts the relevant parameters from the input - // arrays, allocates these on a pre-contrast basis, then calls the 'core' - // calculation (the core layers standardTf calc is shared between multiple - // calculation types). - // Extract individual cell arrays - // Splits up the master input list of all arrays into separate arrays - // The min input array 'problemDefCells' is a master array where - // all the cell arrays are grouped together. There are - // repeatLayers - controls repeating of the layers stack - // allData - Array of all the data arrays - // dataLimits - Min max limits in q for the data arrays - // simLimits - Limits in Q for the reflkectivity simulations - // Layers details - Master array of all available layers - // contrastLayers - Which specific combination of arrays are needed for - // each contrast. - // Custom files - Filenames and path for any custom files used - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - // Pre-Allocation of output arrays... - i = static_cast(problemDef->numberOfContrasts); - backgs.set_size(i); - - // --- End Memory Allocation --- - // Resampling parameters - // Process the custom models.... - customModelClass::processCustomLayers(problemDef->contrastBacks, - problemDef->contrastShifts, problemDef->contrastScales, - problemDef->contrastNbas, problemDef->contrastNbss, - problemDef->contrastRes, problemDef->backs, problemDef->shifts, - problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, - problemDef->contrastCustomFiles, problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, problemDef->useImaginary, - allLayers, allRoughs); - - // Single cored over all contrasts - outSsubs.set_size(i); - sldProfiles.set_size(i); - reflectivity.set_size(i); - Simulation.set_size(i); - shifted_data.set_size(i); - layerSlds.set_size(i); - chis.set_size(i); - qshifts.set_size(i); - sfs.set_size(i); - nbas.set_size(i); - nbss.set_size(i); - resols.set_size(i); - for (int32_T b_i{0}; b_i < i; b_i++) { - real_T dv[2]; - real_T dv1[2]; - int32_T b_loop_ub; - int32_T loop_ub; - - // Extract the relevant parameter values for this contrast - // from the input arrays. - // First need to decide which values of the backrounds, scalefactors - // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], - problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], - problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], - problemDef->backs, problemDef->shifts, problemDef->sf, - problemDef->nba, problemDef->nbs, problemDef->res, - &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, - &thisResol); - - // Get the custom layers output for this contrast - // For the other parameters, we extract the correct ones from the input - // arrays - // Now call the core standardTF_stanlay reflectivity calculation - // In this case we are single cored, so we do not parallelise over - // points - // Call the reflectivity calculation - dv[0] = problemDefCells->f3[b_i].f1[0]; - dv[1] = problemDefCells->f3[b_i].f1[1]; - dv1[0] = problemDefCells->f1[b_i].f1[0]; - dv1[1] = problemDefCells->f1[b_i].f1[1]; - standardTFLayersCore(allLayers[b_i].f1, allRoughs[b_i], - problemDef->geometry.data, problemDef->geometry.size, - thisNba, thisNbs, problemDef->resample[b_i], - controls->calcSld, thisSf, thisQshift, - problemDef->dataPresent[b_i], problemDefCells->f2[b_i] - .f1, dv, (const real_T *)((::coder::array - *)&problemDefCells->f4[b_i].f1)->data(), dv1, thisBackground, thisResol, - problemDef->contrastBacksType[b_i], - static_cast(problemDef->params.size(1)), - controls->resamPars, problemDef->useImaginary, - sldProfile, reflectivity[b_i].f1, Simulation[b_i].f1, - shifted_dat, layerSld, resamLayers, &chis[b_i], - &outSsubs[b_i]); - - // Store returned values for this contrast in the output arrays. - // As well as the calculated profiles, we also store a record of - // the other values (background, scalefactors etc) for each contrast - // for future use. - loop_ub = sldProfile.size(1); - sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = sldProfile.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = - sldProfile[i2 + sldProfile.size(0) * i1]; - } - } - - loop_ub = shifted_dat.size(1); - shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = shifted_dat.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1] = - shifted_dat[i2 + shifted_dat.size(0) * i1]; - } - } - - loop_ub = layerSld.size(1); - layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = layerSld.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = layerSld[i2 + - layerSld.size(0) * i1]; - } - } - - loop_ub = resamLayers.size(1); - allLayers[b_i].f1.set_size(resamLayers.size(0), resamLayers.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = resamLayers.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = - resamLayers[i2 + resamLayers.size(0) * i1]; - } - } - - backgs[b_i] = thisBackground; - qshifts[b_i] = thisQshift; - sfs[b_i] = thisSf; - nbas[b_i] = thisNba; - nbss[b_i] = thisNbs; - resols[b_i] = thisResol; - } - } -} - -// End of code generation (standardTFCustomLayersSingle.cpp) diff --git a/RAT/standardTFCustomLayersSingle.h b/RAT/standardTFCustomLayersSingle.h deleted file mode 100644 index c1e645c4..00000000 --- a/RAT/standardTFCustomLayersSingle.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomLayersSingle.h -// -// Code generation for function 'standardTFCustomLayersSingle' -// -#ifndef STANDARDTFCUSTOMLAYERSSINGLE_H -#define STANDARDTFCUSTOMLAYERSSINGLE_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFCustomLayersSingle(const struct0_T *problemDef, const cell_19 - *problemDefCells, const struct2_T *controls, ::coder::array - &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); -} - -#endif - -// End of code generation (standardTFCustomLayersSingle.h) diff --git a/RAT/standardTFCustomXYParallelContrasts.cpp b/RAT/standardTFCustomXYParallelContrasts.cpp deleted file mode 100644 index fb08a7f1..00000000 --- a/RAT/standardTFCustomXYParallelContrasts.cpp +++ /dev/null @@ -1,232 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomXYParallelContrasts.cpp -// -// Code generation for function 'standardTFCustomXYParallelContrasts' -// - -// Include files -#include "standardTFCustomXYParallelContrasts.h" -#include "applyBackgroundCorrection.h" -#include "backSort.h" -#include "callReflectivity.h" -#include "chiSquared.h" -#include "customModelClass.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "resampleLayers.h" -#include "resampleLayersReIm.h" -#include "rt_nonfinite.h" -#include "shiftData.h" -#include "coder_array.h" -#include "omp.h" - -// Function Definitions -namespace RAT -{ - void standardTFCustomXYParallelContrasts(const struct0_T *problemDef, const - cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) - { - ::coder::array Simul; - ::coder::array b_problemDefCells; - ::coder::array b_sldProfiles; - ::coder::array layerSld; - ::coder::array reflect; - ::coder::array shifted_dat; - real_T reSLD_data[2000]; - real_T dv[2]; - real_T d; - real_T d1; - real_T d2; - real_T d3; - real_T d4; - real_T d5; - int32_T iv[2]; - int32_T reSLD_size[2]; - int32_T b_loop_ub; - int32_T i1; - int32_T i2; - int32_T loop_ub; - int32_T loop_ub_tmp; - int32_T nParams; - boolean_T useImaginary; - - // Extract individual cell arrays - // Splits up the master input list of all arrays into separate arrays - // The min input array 'problemDefCells' is a master array where - // all the cell arrays are grouped together. There are - // repeatLayers - controls repeating of the layers stack - // allData - Array of all the data arrays - // dataLimits - Min max limits in q for the data arrays - // simLimits - Limits in Q for the reflkectivity simulations - // Layers details - Master array of all available layers - // contrastLayers - Which specific combination of arrays are needed for - // each contrast. - // Custom files - Filenames and path for any custom files used - // % Layers details N/A - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); - - // Pre-Allocation... - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - backgs.set_size(loop_ub_tmp); - outSsubs.set_size(loop_ub_tmp); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - outSsubs[i] = 0.0; - } - - // Resampling parameters - useImaginary = problemDef->useImaginary; - customModelClass::processCustomXY(problemDef->contrastBacks, - problemDef->contrastShifts, problemDef->contrastScales, - problemDef->contrastNbas, problemDef->contrastNbss, - problemDef->contrastRes, problemDef->backs, problemDef->shifts, - problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, - problemDef->contrastCustomFiles, problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, sldProfiles, allRoughs); - qshifts.set_size(loop_ub_tmp); - sfs.set_size(loop_ub_tmp); - nbas.set_size(loop_ub_tmp); - nbss.set_size(loop_ub_tmp); - resols.set_size(loop_ub_tmp); - layerSlds.set_size(loop_ub_tmp); - allLayers.set_size(loop_ub_tmp); - shifted_data.set_size(loop_ub_tmp); - chis.set_size(loop_ub_tmp); - Simulation.set_size(loop_ub_tmp); - reflectivity.set_size(loop_ub_tmp); - loop_ub_tmp--; - -#pragma omp parallel for \ - num_threads(omp_get_max_threads()) \ - private(b_sldProfiles,b_problemDefCells,layerSld,reflect,Simul,shifted_dat,reSLD_data,reSLD_size,d,d1,d2,d3,d4,d5,loop_ub,b_loop_ub,i1,i2,dv,iv) - - for (int32_T b_i = 0; b_i <= loop_ub_tmp; b_i++) { - backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], - problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], - problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], - problemDef->backs, problemDef->shifts, problemDef->sf, - problemDef->nba, problemDef->nbs, problemDef->res, &d5, &d4, &d3, - &d2, &d1, &d); - backgs[b_i] = d5; - qshifts[b_i] = d4; - sfs[b_i] = d3; - nbas[b_i] = d2; - nbss[b_i] = d1; - resols[b_i] = d; - - // Resample the layers - if (!useImaginary) { - resampleLayers(sldProfiles[b_i].f1, controls->resamPars, layerSld); - } else { - loop_ub = sldProfiles[b_i].f1.size(0); - reSLD_size[0] = sldProfiles[b_i].f1.size(0); - reSLD_size[1] = 2; - for (i1 = 0; i1 < 2; i1++) { - for (i2 = 0; i2 < loop_ub; i2++) { - reSLD_data[i2 + reSLD_size[0] * i1] = sldProfiles[b_i].f1[i2 + - sldProfiles[b_i].f1.size(0) * i1]; - } - } - - loop_ub = sldProfiles[b_i].f1.size(0); - b_sldProfiles.set_size(sldProfiles[b_i].f1.size(0), 2); - for (i1 = 0; i1 < loop_ub; i1++) { - b_sldProfiles[i1] = sldProfiles[b_i].f1[i1]; - b_sldProfiles[i1 + b_sldProfiles.size(0)] = sldProfiles[b_i].f1[i1 + - sldProfiles[b_i].f1.size(0) * 2]; - } - - iv[0] = (*(int32_T (*)[2])b_sldProfiles.size())[0]; - iv[1] = (*(int32_T (*)[2])b_sldProfiles.size())[1]; - resampleLayersReIm(reSLD_data, reSLD_size, (const real_T *) - b_sldProfiles.data(), iv, controls->resamPars, - layerSld); - } - - layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); - loop_ub = layerSld.size(1); - allLayers[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); - b_loop_ub = layerSld.size(0); - for (i1 = 0; i1 < loop_ub; i1++) { - for (i2 = 0; i2 < b_loop_ub; i2++) { - layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = layerSld[i2 + - layerSld.size(0) * i1]; - allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = layerSld[i2 + - layerSld.size(0) * i1]; - } - } - - b_problemDefCells.set_size(problemDefCells->f2[problemDefCells->f2.size(0) - * b_i].f1.size(0), problemDefCells->f2[problemDefCells->f2.size(0) * b_i] - .f1.size(1)); - loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; - for (i1 = 0; i1 <= loop_ub; i1++) { - b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; - for (i2 = 0; i2 <= b_loop_ub; i2++) { - b_problemDefCells[i2 + b_problemDefCells.size(0) * i1] = - problemDefCells->f2[b_i].f1[i2 + problemDefCells->f2[b_i].f1.size(0) - * i1]; - } - } - - dv[0] = problemDefCells->f3[b_i].f1[0]; - dv[1] = problemDefCells->f3[b_i].f1[1]; - shiftData(sfs[b_i], qshifts[b_i], problemDef->dataPresent[b_i], - b_problemDefCells, dv, (const real_T *)((::coder::array *)&problemDefCells->f4[b_i].f1)->data(), shifted_dat); - shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); - loop_ub = shifted_dat.size(1); - for (i1 = 0; i1 < loop_ub; i1++) { - b_loop_ub = shifted_dat.size(0); - for (i2 = 0; i2 < b_loop_ub; i2++) { - shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1] = - shifted_dat[i2 + shifted_dat.size(0) * i1]; - } - } - - dv[0] = problemDefCells->f1[b_i].f1[0]; - dv[1] = problemDefCells->f1[b_i].f1[1]; - callReflectivity(nbas[b_i], nbss[b_i], (const real_T *)((::coder::array< - real_T, 2U> *)&problemDefCells->f4[b_i].f1)->data(), dv, shifted_dat, - layerSld, 0.0, resols[b_i], useImaginary, reflect, Simul); - applyBackgroundCorrection(reflect, Simul, shifted_dat, backgs[b_i], - problemDef->contrastBacksType[b_i]); - loop_ub = reflect.size(0); - reflectivity[b_i].f1.set_size(reflect.size(0), 2); - b_loop_ub = Simul.size(0); - Simulation[b_i].f1.set_size(Simul.size(0), 2); - for (i1 = 0; i1 < 2; i1++) { - for (i2 = 0; i2 < loop_ub; i2++) { - reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1] = - reflect[i2 + reflect.size(0) * i1]; - } - - for (i2 = 0; i2 < b_loop_ub; i2++) { - Simulation[b_i].f1[i2 + Simulation[b_i].f1.size(0) * i1] = Simul[i2 + - Simul.size(0) * i1]; - } - } - - if (problemDef->dataPresent[b_i] != 0.0) { - chis[b_i] = chiSquared(shifted_dat, reflect, static_cast(nParams)); - } else { - chis[b_i] = 0.0; - } - } - } -} - -// End of code generation (standardTFCustomXYParallelContrasts.cpp) diff --git a/RAT/standardTFCustomXYParallelContrasts.h b/RAT/standardTFCustomXYParallelContrasts.h deleted file mode 100644 index dbad9e56..00000000 --- a/RAT/standardTFCustomXYParallelContrasts.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomXYParallelContrasts.h -// -// Code generation for function 'standardTFCustomXYParallelContrasts' -// -#ifndef STANDARDTFCUSTOMXYPARALLELCONTRASTS_H -#define STANDARDTFCUSTOMXYPARALLELCONTRASTS_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFCustomXYParallelContrasts(const struct0_T *problemDef, const - cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); -} - -#endif - -// End of code generation (standardTFCustomXYParallelContrasts.h) diff --git a/RAT/standardTFCustomXYParallelPoints.cpp b/RAT/standardTFCustomXYParallelPoints.cpp deleted file mode 100644 index f36d7ad8..00000000 --- a/RAT/standardTFCustomXYParallelPoints.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomXYParallelPoints.cpp -// -// Code generation for function 'standardTFCustomXYParallelPoints' -// - -// Include files -#include "standardTFCustomXYParallelPoints.h" -#include "applyBackgroundCorrection.h" -#include "backSort.h" -#include "callReflectivity.h" -#include "chiSquared.h" -#include "customModelClass.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "resampleLayers.h" -#include "resampleLayersReIm.h" -#include "rt_nonfinite.h" -#include "shiftData.h" -#include "coder_array.h" - -// Function Definitions -namespace RAT -{ - void standardTFCustomXYParallelPoints(const struct0_T *problemDef, const - cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) - { - ::coder::array b_problemDefCells; - ::coder::array b_sldProfiles; - ::coder::array layerSld; - ::coder::array reflect; - ::coder::array shifted_dat; - int32_T sldProfiles_size[2]; - int32_T loop_ub_tmp; - boolean_T useImaginary; - - // Multi threaded version of the custom XY profile over reflectivity points - // for standardTF reflectivity calculation. - // Extract individual cell arrays - // Splits up the master input list of all arrays into separate arrays - // The min input array 'problemDefCells' is a master array where - // all the cell arrays are grouped together. There are - // repeatLayers - controls repeating of the layers stack - // allData - Array of all the data arrays - // dataLimits - Min max limits in q for the data arrays - // simLimits - Limits in Q for the reflkectivity simulations - // Layers details - Master array of all available layers - // contrastLayers - Which specific combination of arrays are needed for - // each contrast. - // Custom files - Filenames and path for any custom files used - // % Layers details N/A - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - // Pre-Allocation... - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - backgs.set_size(loop_ub_tmp); - outSsubs.set_size(loop_ub_tmp); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - outSsubs[i] = 0.0; - } - - // Resampling parameters - useImaginary = problemDef->useImaginary; - customModelClass::processCustomXY(problemDef->contrastBacks, - problemDef->contrastShifts, problemDef->contrastScales, - problemDef->contrastNbas, problemDef->contrastNbss, - problemDef->contrastRes, problemDef->backs, problemDef->shifts, - problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, - problemDef->contrastCustomFiles, problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, sldProfiles, allRoughs); - qshifts.set_size(loop_ub_tmp); - sfs.set_size(loop_ub_tmp); - nbas.set_size(loop_ub_tmp); - nbss.set_size(loop_ub_tmp); - resols.set_size(loop_ub_tmp); - layerSlds.set_size(loop_ub_tmp); - allLayers.set_size(loop_ub_tmp); - shifted_data.set_size(loop_ub_tmp); - chis.set_size(loop_ub_tmp); - Simulation.set_size(loop_ub_tmp); - reflectivity.set_size(loop_ub_tmp); - for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - real_T dv[2]; - int32_T b_loop_ub; - int32_T loop_ub; - backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], - problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], - problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], - problemDef->backs, problemDef->shifts, problemDef->sf, - problemDef->nba, problemDef->nbs, problemDef->res, &backgs[b_i], - &qshifts[b_i], &sfs[b_i], &nbas[b_i], &nbss[b_i], &resols[b_i]); - - // Resample the layers - if (!useImaginary) { - resampleLayers(sldProfiles[b_i].f1, controls->resamPars, layerSld); - } else { - real_T sldProfiles_data[2000]; - loop_ub = sldProfiles[b_i].f1.size(0); - sldProfiles_size[0] = sldProfiles[b_i].f1.size(0); - sldProfiles_size[1] = 2; - for (int32_T i{0}; i < 2; i++) { - for (int32_T i1{0}; i1 < loop_ub; i1++) { - sldProfiles_data[i1 + sldProfiles_size[0] * i] = sldProfiles[b_i] - .f1[i1 + sldProfiles[b_i].f1.size(0) * i]; - } - } - - loop_ub = sldProfiles[b_i].f1.size(0); - b_sldProfiles.set_size(sldProfiles[b_i].f1.size(0), 2); - for (int32_T i{0}; i < loop_ub; i++) { - b_sldProfiles[i] = sldProfiles[b_i].f1[i]; - b_sldProfiles[i + b_sldProfiles.size(0)] = sldProfiles[b_i].f1[i + - sldProfiles[b_i].f1.size(0) * 2]; - } - - int32_T iv[2]; - iv[0] = (*(int32_T (*)[2])b_sldProfiles.size())[0]; - iv[1] = (*(int32_T (*)[2])b_sldProfiles.size())[1]; - resampleLayersReIm(sldProfiles_data, sldProfiles_size, (const real_T *) - b_sldProfiles.data(), iv, controls->resamPars, - layerSld); - } - - layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); - loop_ub = layerSld.size(1); - allLayers[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); - b_loop_ub = layerSld.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - layerSlds[b_i].f1[i1 + layerSlds[b_i].f1.size(0) * i] = layerSld[i1 + - layerSld.size(0) * i]; - allLayers[b_i].f1[i1 + allLayers[b_i].f1.size(0) * i] = layerSld[i1 + - layerSld.size(0) * i]; - } - } - - b_problemDefCells.set_size(problemDefCells->f2[problemDefCells->f2.size(0) - * b_i].f1.size(0), problemDefCells->f2[problemDefCells->f2.size(0) * b_i] - .f1.size(1)); - loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; - for (int32_T i{0}; i <= loop_ub; i++) { - b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; - for (int32_T i1{0}; i1 <= b_loop_ub; i1++) { - b_problemDefCells[i1 + b_problemDefCells.size(0) * i] = - problemDefCells->f2[b_i].f1[i1 + problemDefCells->f2[b_i].f1.size(0) - * i]; - } - } - - dv[0] = problemDefCells->f3[b_i].f1[0]; - dv[1] = problemDefCells->f3[b_i].f1[1]; - shiftData(sfs[b_i], qshifts[b_i], problemDef->dataPresent[b_i], - b_problemDefCells, dv, (const real_T *)((::coder::array *)&problemDefCells->f4[b_i].f1)->data(), shifted_dat); - shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); - loop_ub = shifted_dat.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - b_loop_ub = shifted_dat.size(0); - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - shifted_data[b_i].f1[i1 + shifted_data[b_i].f1.size(0) * i] = - shifted_dat[i1 + shifted_dat.size(0) * i]; - } - } - - dv[0] = problemDefCells->f1[b_i].f1[0]; - dv[1] = problemDefCells->f1[b_i].f1[1]; - b_callReflectivity(nbas[b_i], nbss[b_i], (const real_T *)((::coder::array< - real_T, 2U> *)&problemDefCells->f4[b_i].f1)->data(), dv, shifted_dat, - layerSld, 0.0, resols[b_i], useImaginary, reflect, - Simulation[b_i].f1); - applyBackgroundCorrection(reflect, Simulation[b_i].f1, shifted_dat, - backgs[b_i], problemDef->contrastBacksType[b_i]); - loop_ub = reflect.size(0); - reflectivity[b_i].f1.set_size(reflect.size(0), 2); - for (int32_T i{0}; i < 2; i++) { - for (int32_T i1{0}; i1 < loop_ub; i1++) { - reflectivity[b_i].f1[i1 + reflectivity[b_i].f1.size(0) * i] = - reflect[i1 + reflect.size(0) * i]; - } - } - - if (problemDef->dataPresent[b_i] != 0.0) { - chis[b_i] = chiSquared(shifted_dat, reflect, static_cast - (problemDef->params.size(1))); - } else { - chis[b_i] = 0.0; - } - } - } -} - -// End of code generation (standardTFCustomXYParallelPoints.cpp) diff --git a/RAT/standardTFCustomXYParallelPoints.h b/RAT/standardTFCustomXYParallelPoints.h deleted file mode 100644 index 7c9a3fb1..00000000 --- a/RAT/standardTFCustomXYParallelPoints.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomXYParallelPoints.h -// -// Code generation for function 'standardTFCustomXYParallelPoints' -// -#ifndef STANDARDTFCUSTOMXYPARALLELPOINTS_H -#define STANDARDTFCUSTOMXYPARALLELPOINTS_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFCustomXYParallelPoints(const struct0_T *problemDef, const - cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); -} - -#endif - -// End of code generation (standardTFCustomXYParallelPoints.h) diff --git a/RAT/standardTFCustomXYReflectivityCalculation.cpp b/RAT/standardTFCustomXYReflectivityCalculation.cpp deleted file mode 100644 index d4ffcaf0..00000000 --- a/RAT/standardTFCustomXYReflectivityCalculation.cpp +++ /dev/null @@ -1,152 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomXYReflectivityCalculation.cpp -// -// Code generation for function 'standardTFCustomXYReflectivityCalculation' -// - -// Include files -#include "standardTFCustomXYReflectivityCalculation.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rt_nonfinite.h" -#include "standardTFCustomXYParallelContrasts.h" -#include "standardTFCustomXYParallelPoints.h" -#include "standardTFCustomXYSingle.h" -#include "strcmp.h" -#include "sum.h" -#include "coder_array.h" -#include "coder_bounded_array.h" - -// Function Definitions -namespace RAT -{ - void standardTFCustomXYReflectivityCalculation(const struct0_T *problemDef, - const cell_19 *problemDefCells, const struct2_T *controls, struct4_T - *problem, ::coder::array &reflectivity, ::coder::array< - cell_wrap_9, 1U> &Simulation, ::coder::array &shifted_data, - ::coder::array &layerSlds, ::coder::array - &sldProfiles, ::coder::array &allLayers) - { - int32_T loop_ub_tmp; - - // Custom XP profile reflectivity calculation for standardTF - // This function decides on parallelisation options before calling the - // relevant version of the main custom XY calculation. It is more - // efficient to have multiple versions of the core calculation, each dealing - // with a different scheme for parallelisation. These are: - // single - single threaded teflectivity calculation - // points - parallelise over points in the reflectivity calculation - // contrasts - parallelise over contrasts. - // Pre-allocation - It's necessary to - // pre-allocate the memory for all the arrays - // for compilation, so do this in this block. - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgrounds.set_size(loop_ub_tmp); - problem->qshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->nbairs.set_size(loop_ub_tmp); - problem->nbsubs.set_size(loop_ub_tmp); - problem->calculations.all_chis.set_size(loop_ub_tmp); - problem->resolutions.set_size(loop_ub_tmp); - problem->allSubRough.set_size(loop_ub_tmp); - reflectivity.set_size(loop_ub_tmp); - Simulation.set_size(loop_ub_tmp); - shifted_data.set_size(loop_ub_tmp); - layerSlds.set_size(loop_ub_tmp); - sldProfiles.set_size(loop_ub_tmp); - allLayers.set_size(loop_ub_tmp); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgrounds[i] = 0.0; - problem->qshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->nbairs[i] = 0.0; - problem->nbsubs[i] = 0.0; - problem->calculations.all_chis[i] = 0.0; - problem->resolutions[i] = 0.0; - problem->allSubRough[i] = 0.0; - reflectivity[i].f1.set_size(2, 2); - reflectivity[i].f1[0] = 1.0; - reflectivity[i].f1[1] = 1.0; - reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; - reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; - Simulation[i].f1.set_size(2, 2); - Simulation[i].f1[0] = 1.0; - Simulation[i].f1[1] = 1.0; - Simulation[i].f1[Simulation[i].f1.size(0)] = 1.0; - Simulation[i].f1[Simulation[i].f1.size(0) + 1] = 1.0; - shifted_data[i].f1.set_size(2, 3); - layerSlds[i].f1.set_size(2, 3); - for (int32_T b_i{0}; b_i < 3; b_i++) { - shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i] = 1.0; - shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i + 1] = 1.0; - layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; - layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; - } - - sldProfiles[i].f1.set_size(2, 2); - sldProfiles[i].f1[0] = 1.0; - sldProfiles[i].f1[1] = 1.0; - sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; - sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; - allLayers[i].f1.set_size(2, 1); - allLayers[i].f1[0] = 1.0; - allLayers[i].f1[1] = 1.0; - } - - if (coder::internal::f_strcmp(controls->para.data, controls->para.size)) { - loop_ub_tmp = 0; - } else if (coder::internal::g_strcmp(controls->para.data, - controls->para.size)) { - loop_ub_tmp = 1; - } else if (coder::internal::h_strcmp(controls->para.data, - controls->para.size)) { - loop_ub_tmp = 2; - } else { - loop_ub_tmp = -1; - } - - switch (loop_ub_tmp) { - case 0: - standardTFCustomXYSingle(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgrounds, problem->qshifts, - problem->scalefactors, problem->nbairs, problem->nbsubs, - problem->resolutions, problem->calculations.all_chis, reflectivity, - Simulation, shifted_data, layerSlds, sldProfiles, allLayers, - problem->allSubRough); - break; - - case 1: - standardTFCustomXYParallelPoints(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgrounds, problem->qshifts, - problem->scalefactors, problem->nbairs, problem->nbsubs, - problem->resolutions, problem->calculations.all_chis, reflectivity, - Simulation, shifted_data, layerSlds, sldProfiles, allLayers, - problem->allSubRough); - break; - - case 2: - standardTFCustomXYParallelContrasts(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgrounds, problem->qshifts, - problem->scalefactors, problem->nbairs, problem->nbsubs, - problem->resolutions, problem->calculations.all_chis, reflectivity, - Simulation, shifted_data, layerSlds, sldProfiles, allLayers, - problem->allSubRough); - break; - } - - problem->calculations.sum_chi = coder::sum(problem->calculations.all_chis); - problem->resample.set_size(1, problem->allSubRough.size(0)); - loop_ub_tmp = problem->allSubRough.size(0); - for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - problem->resample[b_i] = 1.0; - } - } -} - -// End of code generation (standardTFCustomXYReflectivityCalculation.cpp) diff --git a/RAT/standardTFCustomXYReflectivityCalculation.h b/RAT/standardTFCustomXYReflectivityCalculation.h deleted file mode 100644 index 81d5f624..00000000 --- a/RAT/standardTFCustomXYReflectivityCalculation.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomXYReflectivityCalculation.h -// -// Code generation for function 'standardTFCustomXYReflectivityCalculation' -// -#ifndef STANDARDTFCUSTOMXYREFLECTIVITYCALCULATION_H -#define STANDARDTFCUSTOMXYREFLECTIVITYCALCULATION_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFCustomXYReflectivityCalculation(const struct0_T *problemDef, - const cell_19 *problemDefCells, const struct2_T *controls, struct4_T - *problem, ::coder::array &reflectivity, ::coder::array< - cell_wrap_9, 1U> &Simulation, ::coder::array &shifted_data, - ::coder::array &layerSlds, ::coder::array - &sldProfiles, ::coder::array &allLayers); -} - -#endif - -// End of code generation (standardTFCustomXYReflectivityCalculation.h) diff --git a/RAT/standardTFCustomXYSingle.cpp b/RAT/standardTFCustomXYSingle.cpp deleted file mode 100644 index 83ad5d70..00000000 --- a/RAT/standardTFCustomXYSingle.cpp +++ /dev/null @@ -1,202 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomXYSingle.cpp -// -// Code generation for function 'standardTFCustomXYSingle' -// - -// Include files -#include "standardTFCustomXYSingle.h" -#include "applyBackgroundCorrection.h" -#include "backSort.h" -#include "callReflectivity.h" -#include "chiSquared.h" -#include "customModelClass.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "resampleLayers.h" -#include "resampleLayersReIm.h" -#include "rt_nonfinite.h" -#include "shiftData.h" -#include "coder_array.h" - -// Function Definitions -namespace RAT -{ - void standardTFCustomXYSingle(const struct0_T *problemDef, const cell_19 - *problemDefCells, const struct2_T *controls, ::coder::array - &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) - { - ::coder::array b_problemDefCells; - ::coder::array b_sldProfiles; - ::coder::array layerSld; - ::coder::array reflect; - ::coder::array shifted_dat; - int32_T sldProfiles_size[2]; - int32_T loop_ub_tmp; - boolean_T useImaginary; - - // Extract individual cell arrays - // Splits up the master input list of all arrays into separate arrays - // The min input array 'problemDefCells' is a master array where - // all the cell arrays are grouped together. There are - // repeatLayers - controls repeating of the layers stack - // allData - Array of all the data arrays - // dataLimits - Min max limits in q for the data arrays - // simLimits - Limits in Q for the reflkectivity simulations - // Layers details - Master array of all available layers - // contrastLayers - Which specific combination of arrays are needed for - // each contrast. - // Custom files - Filenames and path for any custom files used - // % Layers details N/A - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - // Pre-Allocation... - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - backgs.set_size(loop_ub_tmp); - outSsubs.set_size(loop_ub_tmp); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - outSsubs[i] = 0.0; - } - - // Resampling parameters - useImaginary = problemDef->useImaginary; - customModelClass::processCustomXY(problemDef->contrastBacks, - problemDef->contrastShifts, problemDef->contrastScales, - problemDef->contrastNbas, problemDef->contrastNbss, - problemDef->contrastRes, problemDef->backs, problemDef->shifts, - problemDef->sf, problemDef->nba, problemDef->nbs, problemDef->res, - problemDef->contrastCustomFiles, problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, sldProfiles, allRoughs); - qshifts.set_size(loop_ub_tmp); - sfs.set_size(loop_ub_tmp); - nbas.set_size(loop_ub_tmp); - nbss.set_size(loop_ub_tmp); - resols.set_size(loop_ub_tmp); - layerSlds.set_size(loop_ub_tmp); - allLayers.set_size(loop_ub_tmp); - shifted_data.set_size(loop_ub_tmp); - chis.set_size(loop_ub_tmp); - Simulation.set_size(loop_ub_tmp); - reflectivity.set_size(loop_ub_tmp); - for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - real_T dv[2]; - int32_T b_loop_ub; - int32_T loop_ub; - backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], - problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], - problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], - problemDef->backs, problemDef->shifts, problemDef->sf, - problemDef->nba, problemDef->nbs, problemDef->res, &backgs[b_i], - &qshifts[b_i], &sfs[b_i], &nbas[b_i], &nbss[b_i], &resols[b_i]); - - // Resample the layers - if (!useImaginary) { - resampleLayers(sldProfiles[b_i].f1, controls->resamPars, layerSld); - } else { - real_T sldProfiles_data[2000]; - loop_ub = sldProfiles[b_i].f1.size(0); - sldProfiles_size[0] = sldProfiles[b_i].f1.size(0); - sldProfiles_size[1] = 2; - for (int32_T i{0}; i < 2; i++) { - for (int32_T i1{0}; i1 < loop_ub; i1++) { - sldProfiles_data[i1 + sldProfiles_size[0] * i] = sldProfiles[b_i] - .f1[i1 + sldProfiles[b_i].f1.size(0) * i]; - } - } - - loop_ub = sldProfiles[b_i].f1.size(0); - b_sldProfiles.set_size(sldProfiles[b_i].f1.size(0), 2); - for (int32_T i{0}; i < loop_ub; i++) { - b_sldProfiles[i] = sldProfiles[b_i].f1[i]; - b_sldProfiles[i + b_sldProfiles.size(0)] = sldProfiles[b_i].f1[i + - sldProfiles[b_i].f1.size(0) * 2]; - } - - int32_T iv[2]; - iv[0] = (*(int32_T (*)[2])b_sldProfiles.size())[0]; - iv[1] = (*(int32_T (*)[2])b_sldProfiles.size())[1]; - resampleLayersReIm(sldProfiles_data, sldProfiles_size, (const real_T *) - b_sldProfiles.data(), iv, controls->resamPars, - layerSld); - } - - layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); - loop_ub = layerSld.size(1); - allLayers[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); - b_loop_ub = layerSld.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - layerSlds[b_i].f1[i1 + layerSlds[b_i].f1.size(0) * i] = layerSld[i1 + - layerSld.size(0) * i]; - allLayers[b_i].f1[i1 + allLayers[b_i].f1.size(0) * i] = layerSld[i1 + - layerSld.size(0) * i]; - } - } - - b_problemDefCells.set_size(problemDefCells->f2[problemDefCells->f2.size(0) - * b_i].f1.size(0), problemDefCells->f2[problemDefCells->f2.size(0) * b_i] - .f1.size(1)); - loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; - for (int32_T i{0}; i <= loop_ub; i++) { - b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; - for (int32_T i1{0}; i1 <= b_loop_ub; i1++) { - b_problemDefCells[i1 + b_problemDefCells.size(0) * i] = - problemDefCells->f2[b_i].f1[i1 + problemDefCells->f2[b_i].f1.size(0) - * i]; - } - } - - dv[0] = problemDefCells->f3[b_i].f1[0]; - dv[1] = problemDefCells->f3[b_i].f1[1]; - shiftData(sfs[b_i], qshifts[b_i], problemDef->dataPresent[b_i], - b_problemDefCells, dv, (const real_T *)((::coder::array *)&problemDefCells->f4[b_i].f1)->data(), shifted_dat); - shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); - loop_ub = shifted_dat.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - b_loop_ub = shifted_dat.size(0); - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - shifted_data[b_i].f1[i1 + shifted_data[b_i].f1.size(0) * i] = - shifted_dat[i1 + shifted_dat.size(0) * i]; - } - } - - dv[0] = problemDefCells->f1[b_i].f1[0]; - dv[1] = problemDefCells->f1[b_i].f1[1]; - callReflectivity(nbas[b_i], nbss[b_i], (const real_T *)((::coder::array< - real_T, 2U> *)&problemDefCells->f4[b_i].f1)->data(), dv, shifted_dat, - layerSld, 0.0, resols[b_i], useImaginary, reflect, - Simulation[b_i].f1); - applyBackgroundCorrection(reflect, Simulation[b_i].f1, shifted_dat, - backgs[b_i], problemDef->contrastBacksType[b_i]); - loop_ub = reflect.size(0); - reflectivity[b_i].f1.set_size(reflect.size(0), 2); - for (int32_T i{0}; i < 2; i++) { - for (int32_T i1{0}; i1 < loop_ub; i1++) { - reflectivity[b_i].f1[i1 + reflectivity[b_i].f1.size(0) * i] = - reflect[i1 + reflect.size(0) * i]; - } - } - - if (problemDef->dataPresent[b_i] != 0.0) { - chis[b_i] = chiSquared(shifted_dat, reflect, static_cast - (problemDef->params.size(1))); - } else { - chis[b_i] = 0.0; - } - } - } -} - -// End of code generation (standardTFCustomXYSingle.cpp) diff --git a/RAT/standardTFCustomXYSingle.h b/RAT/standardTFCustomXYSingle.h deleted file mode 100644 index 7d88a55f..00000000 --- a/RAT/standardTFCustomXYSingle.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFCustomXYSingle.h -// -// Code generation for function 'standardTFCustomXYSingle' -// -#ifndef STANDARDTFCUSTOMXYSINGLE_H -#define STANDARDTFCUSTOMXYSINGLE_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFCustomXYSingle(const struct0_T *problemDef, const cell_19 - *problemDefCells, const struct2_T *controls, ::coder::array - &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); -} - -#endif - -// End of code generation (standardTFCustomXYSingle.h) diff --git a/RAT/standardTFLayersCore.cpp b/RAT/standardTFLayersCore.cpp deleted file mode 100644 index c28e51c6..00000000 --- a/RAT/standardTFLayersCore.cpp +++ /dev/null @@ -1,683 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFLayersCore.cpp -// -// Code generation for function 'standardTFLayersCore' -// - -// Include files -#include "standardTFLayersCore.h" -#include "applyBackgroundCorrection.h" -#include "callReflectivity.h" -#include "chiSquared.h" -#include "groupLayersMod.h" -#include "groupLayersModImaginary.h" -#include "makeSLDProfiles.h" -#include "resampleLayers.h" -#include "resampleLayersReIm.h" -#include "rt_nonfinite.h" -#include "shiftData.h" -#include "coder_array.h" -#include - -namespace py = pybind11; -// Function Definitions -namespace RAT -{ - void b_standardTFLayersCore(const ::coder::array &contrastLayers, - real_T rough, const char_T geometry_data[], const int32_T geometry_size[2], - real_T nba, real_T nbs, real_T resample, real_T calcSld, real_T sf, real_T - qshift, real_T dataPresent, const ::coder::array &data, const - real_T dataLimits[2], const real_T simLimits_data[], const real_T - repeatLayers[2], real_T background, real_T resol, real_T backsType, real_T - params, const real_T resamPars[2], boolean_T useImaginary, ::coder::array< - real_T, 2U> &sldProfile, ::coder::array &reflect, ::coder::array< - real_T, 2U> &Simul, ::coder::array &shifted_dat, ::coder::array< - real_T, 2U> &theseLayers, ::coder::array &resamLayers, real_T - *chiSq, real_T *ssubs) - { - ::coder::array b_data; - ::coder::array b_theseLayers; - ::coder::array c_theseLayers; - ::coder::array layerSld; - ::coder::array sldProfileIm; - ::coder::array thisSldLays; - ::coder::array thisSldLaysIm; - ::coder::array d_theseLayers; - int32_T b_loop_ub; - int32_T i; - int32_T i1; - int32_T loop_ub; - - // This is the main reflectivity calculation for all Layers models in the - // standard target function. - // - // The function first arranges the - // roughness' in the correct order according - // to geometry. Then, if required it calculates the SLD profile and if - // requested resamples this into a number of zero-roughness layers - // (roughness resampling). It the applies any scalefactors and qz shifts - // the data requires. This is done before calculating the reflectivity to - // ensure that the reflectivity is calculated over the same range in qz as - // the shifted datapoints. The main reflectivity calculation is then - // called, including the resolution function. The calculation outputs two - // profiles - 'reflect' which is the same range as the points, and - // 'Simulation' which can be a different range to allow extrapolation. - // The background correction is the applied, and finally chi-squared is - // calculated. - // - // Inputs: - // contrastLayers : - // rough : - // geometry : - // nba : - // nbs : - // resample : - // calcSld : - // sf : - // qshift : - // dataPresent : - // data : - // dataLimits : - // simLimits : - // repeatLayers : - // background : - // resol : - // backsType : - // params : - // parallelPoints : - // - // Outputs: - // - // ------------------------------------------------------------------------ - // - // (c) Arwel Hughes - 12/1/21 - // - // Last Modified: 12/1/21 by Arwel Hughes. - // - // ------------------------------------------------------------------------ - // Pre-definition for Coder.. - thisSldLaysIm.set_size(1, 2); - sldProfileIm.set_size(1, 2); - thisSldLaysIm[0] = 0.0; - sldProfileIm[0] = 0.0; - thisSldLaysIm[thisSldLaysIm.size(0)] = 0.0; - sldProfileIm[sldProfileIm.size(0)] = 0.0; - - // Bulid up the layers matrix for this contrast - if (!useImaginary) { - groupLayersMod(contrastLayers, rough, geometry_data, geometry_size, nba, - nbs, layerSld, ssubs); - theseLayers.set_size(layerSld.size(0), 3); - loop_ub = layerSld.size(0); - for (i = 0; i < 3; i++) { - for (i1 = 0; i1 < loop_ub; i1++) { - theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + - layerSld.size(0) * i]; - } - } - } else { - groupLayersModImaginary(contrastLayers, rough, geometry_data, - geometry_size, nba, nbs, layerSld, ssubs); - theseLayers.set_size(layerSld.size(0), 4); - loop_ub = layerSld.size(0); - for (i = 0; i < 4; i++) { - for (i1 = 0; i1 < loop_ub; i1++) { - theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + - layerSld.size(0) * i]; - } - } - } - - // Make the SLD profiles. - // If resampling is needed, then enforce the calcSLD flag, so as to catch - // the error af trying to resample a non-existent profile. - if ((resample == 1.0) && (calcSld == 0.0)) { - calcSld = 1.0; - } - - // If calc SLD flag is set, then calculate the SLD profile - if (calcSld == 1.0) { - // If we need them both, we process real and imaginary parts of the SLD - // seperately... - if (useImaginary) { - int32_T result; - int8_T input_sizes_idx_1; - int8_T sizes_idx_1; - boolean_T empty_non_axis_sizes; - if (theseLayers.size(1) < 4) { - i = 0; - i1 = 0; - } else { - i = 3; - i1 = 4; - } - - if (theseLayers.size(0) != 0) { - result = theseLayers.size(0); - } else { - result = 0; - } - - empty_non_axis_sizes = (result == 0); - if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { - input_sizes_idx_1 = 2; - } else { - input_sizes_idx_1 = 0; - } - - if (empty_non_axis_sizes || ((theseLayers.size(0) != 0) && (i1 - i != 0))) - { - sizes_idx_1 = static_cast(i1 - i); - } else { - sizes_idx_1 = 0; - } - - b_theseLayers.set_size(theseLayers.size(0), 2); - loop_ub = theseLayers.size(0); - for (int32_T i2{0}; i2 < 2; i2++) { - for (b_loop_ub = 0; b_loop_ub < loop_ub; b_loop_ub++) { - b_theseLayers[b_loop_ub + b_theseLayers.size(0) * i2] = - theseLayers[b_loop_ub + theseLayers.size(0) * i2]; - } - } - - loop_ub = i1 - i; - c_theseLayers.set_size(theseLayers.size(0), loop_ub); - for (i1 = 0; i1 < loop_ub; i1++) { - b_loop_ub = theseLayers.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - c_theseLayers[i2 + c_theseLayers.size(0) * i1] = theseLayers[i2 + - theseLayers.size(0) * (i + i1)]; - } - } - - thisSldLays.set_size(result, input_sizes_idx_1 + sizes_idx_1); - loop_ub = input_sizes_idx_1; - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < result; i1++) { - thisSldLays[i1 + thisSldLays.size(0) * i] = b_theseLayers[i1 + - result * i]; - } - } - - loop_ub = sizes_idx_1; - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < result; i1++) { - thisSldLays[i1 + thisSldLays.size(0) * (i + input_sizes_idx_1)] = - c_theseLayers[i1 + result * i]; - } - } - - if (theseLayers.size(0) != 0) { - result = theseLayers.size(0); - } else { - result = 0; - } - - empty_non_axis_sizes = (result == 0); - if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { - input_sizes_idx_1 = 1; - } else { - input_sizes_idx_1 = 0; - } - - if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { - sizes_idx_1 = static_cast(theseLayers.size(1) - 2); - } else { - sizes_idx_1 = 0; - } - - d_theseLayers.set_size(theseLayers.size(0)); - loop_ub = theseLayers.size(0); - for (i = 0; i < loop_ub; i++) { - d_theseLayers[i] = theseLayers[i]; - } - - c_theseLayers.set_size(theseLayers.size(0), theseLayers.size(1) - 2); - loop_ub = theseLayers.size(1); - b_loop_ub = theseLayers.size(0); - for (i = 0; i <= loop_ub - 3; i++) { - for (i1 = 0; i1 < b_loop_ub; i1++) { - c_theseLayers[i1 + c_theseLayers.size(0) * i] = theseLayers[i1 + - theseLayers.size(0) * (i + 2)]; - } - } - - thisSldLaysIm.set_size(result, input_sizes_idx_1 + sizes_idx_1); - loop_ub = input_sizes_idx_1; - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < result; i1++) { - thisSldLaysIm[i1] = d_theseLayers[i1]; - } - } - - loop_ub = sizes_idx_1; - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < result; i1++) { - thisSldLaysIm[i1 + thisSldLaysIm.size(0) * (i + input_sizes_idx_1)] = - c_theseLayers[i1 + result * i]; - } - } - } else { - thisSldLays.set_size(theseLayers.size(0), theseLayers.size(1)); - loop_ub = theseLayers.size(1); - b_loop_ub = theseLayers.size(0); - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < b_loop_ub; i1++) { - thisSldLays[i1 + thisSldLays.size(0) * i] = theseLayers[i1 + - theseLayers.size(0) * i]; - } - } - } - - makeSLDProfiles(nba, nbs, thisSldLays, *ssubs, repeatLayers, b_theseLayers); - sldProfile.set_size(b_theseLayers.size(0), 2); - loop_ub = b_theseLayers.size(0); - for (i = 0; i < 2; i++) { - for (i1 = 0; i1 < loop_ub; i1++) { - sldProfile[i1 + sldProfile.size(0) * i] = b_theseLayers[i1 + - b_theseLayers.size(0) * i]; - } - } - - // If we have imaginary, we are also - // going to need an SLD profile for the imaginary part - if (useImaginary) { - // Note nba and nbs = 0 since there is never any imaginary part for - // the bulk phases.. - makeSLDProfiles(thisSldLaysIm, *ssubs, repeatLayers, b_theseLayers); - sldProfileIm.set_size(b_theseLayers.size(0), 2); - loop_ub = b_theseLayers.size(0); - for (i = 0; i < 2; i++) { - for (i1 = 0; i1 < loop_ub; i1++) { - sldProfileIm[i1 + sldProfileIm.size(0) * i] = b_theseLayers[i1 + - b_theseLayers.size(0) * i]; - } - } - } - } else { - sldProfile.set_size(1, 2); - sldProfile[0] = 0.0; - sldProfile[sldProfile.size(0)] = 0.0; - } - - // If required, then resample the SLD - if (resample == 1.0) { - if (!useImaginary) { - resampleLayers(sldProfile, resamPars, layerSld); - } else { - resampleLayersReIm(sldProfile, sldProfileIm, resamPars, layerSld); - } - - resamLayers.set_size(layerSld.size(0), layerSld.size(1)); - loop_ub = layerSld.size(1); - b_loop_ub = layerSld.size(0); - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < b_loop_ub; i1++) { - resamLayers[i1 + resamLayers.size(0) * i] = layerSld[i1 + - layerSld.size(0) * i]; - } - } - } else { - resamLayers.set_size(1, 3); - resamLayers[0] = 0.0; - resamLayers[resamLayers.size(0)] = 0.0; - resamLayers[resamLayers.size(0) * 2] = 0.0; - } - - // Apply scale factors and q shifts to the data - b_data.set_size(data.size(0), data.size(1)); - loop_ub = data.size(1) - 1; - for (i = 0; i <= loop_ub; i++) { - b_loop_ub = data.size(0) - 1; - for (i1 = 0; i1 <= b_loop_ub; i1++) { - b_data[i1 + b_data.size(0) * i] = data[i1 + data.size(0) * i]; - } - } - - shiftData(sf, qshift, dataPresent, b_data, dataLimits, simLimits_data, - shifted_dat); - - // Calculate the reflectivity - b_callReflectivity(nba, nbs, simLimits_data, repeatLayers, shifted_dat, - layerSld, *ssubs, resol, useImaginary, reflect, Simul); - - // Apply background correction, either to the simulation or the data - applyBackgroundCorrection(reflect, Simul, shifted_dat, background, backsType); - - // Calculate chi squared. - *chiSq = chiSquared(shifted_dat, reflect, params); - } - - void standardTFLayersCore(const ::coder::array &contrastLayers, - real_T rough, const char_T geometry_data[], const int32_T geometry_size[2], - real_T nba, real_T nbs, real_T resample, real_T calcSld, real_T sf, real_T - qshift, real_T dataPresent, const ::coder::array &data, const - real_T dataLimits[2], const real_T simLimits_data[], const real_T - repeatLayers[2], real_T background, real_T resol, real_T backsType, real_T - params, const real_T resamPars[2], boolean_T useImaginary, ::coder::array< - real_T, 2U> &sldProfile, ::coder::array &reflect, ::coder::array< - real_T, 2U> &Simul, ::coder::array &shifted_dat, ::coder::array< - real_T, 2U> &theseLayers, ::coder::array &resamLayers, real_T - *chiSq, real_T *ssubs) - { - ::coder::array b_data; - ::coder::array b_theseLayers; - ::coder::array c_theseLayers; - ::coder::array layerSld; - ::coder::array sldProfileIm; - ::coder::array thisSldLays; - ::coder::array thisSldLaysIm; - ::coder::array d_theseLayers; - int32_T b_loop_ub; - int32_T i; - int32_T i1; - int32_T loop_ub; - - // This is the main reflectivity calculation for all Layers models in the - // standard target function. - // - // The function first arranges the - // roughness' in the correct order according - // to geometry. Then, if required it calculates the SLD profile and if - // requested resamples this into a number of zero-roughness layers - // (roughness resampling). It the applies any scalefactors and qz shifts - // the data requires. This is done before calculating the reflectivity to - // ensure that the reflectivity is calculated over the same range in qz as - // the shifted datapoints. The main reflectivity calculation is then - // called, including the resolution function. The calculation outputs two - // profiles - 'reflect' which is the same range as the points, and - // 'Simulation' which can be a different range to allow extrapolation. - // The background correction is the applied, and finally chi-squared is - // calculated. - // - // Inputs: - // contrastLayers : - // rough : - // geometry : - // nba : - // nbs : - // resample : - // calcSld : - // sf : - // qshift : - // dataPresent : - // data : - // dataLimits : - // simLimits : - // repeatLayers : - // background : - // resol : - // backsType : - // params : - // parallelPoints : - // - // Outputs: - // - // ------------------------------------------------------------------------ - // - // (c) Arwel Hughes - 12/1/21 - // - // Last Modified: 12/1/21 by Arwel Hughes. - // - // ------------------------------------------------------------------------ - // Pre-definition for Coder.. - thisSldLaysIm.set_size(1, 2); - sldProfileIm.set_size(1, 2); - thisSldLaysIm[0] = 0.0; - sldProfileIm[0] = 0.0; - thisSldLaysIm[thisSldLaysIm.size(0)] = 0.0; - sldProfileIm[sldProfileIm.size(0)] = 0.0; - - // Bulid up the layers matrix for this contrast - if (!useImaginary) { - groupLayersMod(contrastLayers, rough, geometry_data, geometry_size, nba, - nbs, layerSld, ssubs); - theseLayers.set_size(layerSld.size(0), 3); - loop_ub = layerSld.size(0); - for (i = 0; i < 3; i++) { - for (i1 = 0; i1 < loop_ub; i1++) { - theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + - layerSld.size(0) * i]; - } - } - } else { - groupLayersModImaginary(contrastLayers, rough, geometry_data, - geometry_size, nba, nbs, layerSld, ssubs); - theseLayers.set_size(layerSld.size(0), 4); - loop_ub = layerSld.size(0); - for (i = 0; i < 4; i++) { - for (i1 = 0; i1 < loop_ub; i1++) { - theseLayers[i1 + theseLayers.size(0) * i] = layerSld[i1 + - layerSld.size(0) * i]; - } - } - } - - // Make the SLD profiles. - // If resampling is needed, then enforce the calcSLD flag, so as to catch - // the error af trying to resample a non-existent profile. - if ((resample == 1.0) && (calcSld == 0.0)) { - calcSld = 1.0; - } - - // If calc SLD flag is set, then calculate the SLD profile - if (calcSld == 1.0) { - // If we need them both, we process real and imaginary parts of the SLD - // seperately... - if (useImaginary) { - int32_T result; - int8_T input_sizes_idx_1; - int8_T sizes_idx_1; - boolean_T empty_non_axis_sizes; - if (theseLayers.size(1) < 4) { - i = 0; - i1 = 0; - } else { - i = 3; - i1 = 4; - } - - if (theseLayers.size(0) != 0) { - result = theseLayers.size(0); - } else { - result = 0; - } - - empty_non_axis_sizes = (result == 0); - if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { - input_sizes_idx_1 = 2; - } else { - input_sizes_idx_1 = 0; - } - - if (empty_non_axis_sizes || ((theseLayers.size(0) != 0) && (i1 - i != 0))) - { - sizes_idx_1 = static_cast(i1 - i); - } else { - sizes_idx_1 = 0; - } - - b_theseLayers.set_size(theseLayers.size(0), 2); - loop_ub = theseLayers.size(0); - for (int32_T i2{0}; i2 < 2; i2++) { - for (b_loop_ub = 0; b_loop_ub < loop_ub; b_loop_ub++) { - b_theseLayers[b_loop_ub + b_theseLayers.size(0) * i2] = - theseLayers[b_loop_ub + theseLayers.size(0) * i2]; - } - } - - loop_ub = i1 - i; - c_theseLayers.set_size(theseLayers.size(0), loop_ub); - for (i1 = 0; i1 < loop_ub; i1++) { - b_loop_ub = theseLayers.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - c_theseLayers[i2 + c_theseLayers.size(0) * i1] = theseLayers[i2 + - theseLayers.size(0) * (i + i1)]; - } - } - - thisSldLays.set_size(result, input_sizes_idx_1 + sizes_idx_1); - loop_ub = input_sizes_idx_1; - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < result; i1++) { - thisSldLays[i1 + thisSldLays.size(0) * i] = b_theseLayers[i1 + - result * i]; - } - } - - loop_ub = sizes_idx_1; - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < result; i1++) { - thisSldLays[i1 + thisSldLays.size(0) * (i + input_sizes_idx_1)] = - c_theseLayers[i1 + result * i]; - } - } - - if (theseLayers.size(0) != 0) { - result = theseLayers.size(0); - } else { - result = 0; - } - - empty_non_axis_sizes = (result == 0); - if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { - input_sizes_idx_1 = 1; - } else { - input_sizes_idx_1 = 0; - } - - if (empty_non_axis_sizes || (theseLayers.size(0) != 0)) { - sizes_idx_1 = static_cast(theseLayers.size(1) - 2); - } else { - sizes_idx_1 = 0; - } - - d_theseLayers.set_size(theseLayers.size(0)); - loop_ub = theseLayers.size(0); - for (i = 0; i < loop_ub; i++) { - d_theseLayers[i] = theseLayers[i]; - } - - c_theseLayers.set_size(theseLayers.size(0), theseLayers.size(1) - 2); - loop_ub = theseLayers.size(1); - b_loop_ub = theseLayers.size(0); - for (i = 0; i <= loop_ub - 3; i++) { - for (i1 = 0; i1 < b_loop_ub; i1++) { - c_theseLayers[i1 + c_theseLayers.size(0) * i] = theseLayers[i1 + - theseLayers.size(0) * (i + 2)]; - } - } - - thisSldLaysIm.set_size(result, input_sizes_idx_1 + sizes_idx_1); - loop_ub = input_sizes_idx_1; - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < result; i1++) { - thisSldLaysIm[i1] = d_theseLayers[i1]; - } - } - - loop_ub = sizes_idx_1; - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < result; i1++) { - thisSldLaysIm[i1 + thisSldLaysIm.size(0) * (i + input_sizes_idx_1)] = - c_theseLayers[i1 + result * i]; - } - } - } else { - thisSldLays.set_size(theseLayers.size(0), theseLayers.size(1)); - loop_ub = theseLayers.size(1); - b_loop_ub = theseLayers.size(0); - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < b_loop_ub; i1++) { - thisSldLays[i1 + thisSldLays.size(0) * i] = theseLayers[i1 + - theseLayers.size(0) * i]; - } - } - } - - makeSLDProfiles(nba, nbs, thisSldLays, *ssubs, repeatLayers, b_theseLayers); - sldProfile.set_size(b_theseLayers.size(0), 2); - loop_ub = b_theseLayers.size(0); - for (i = 0; i < 2; i++) { - for (i1 = 0; i1 < loop_ub; i1++) { - sldProfile[i1 + sldProfile.size(0) * i] = b_theseLayers[i1 + - b_theseLayers.size(0) * i]; - } - } - - // If we have imaginary, we are also - // going to need an SLD profile for the imaginary part - if (useImaginary) { - // Note nba and nbs = 0 since there is never any imaginary part for - // the bulk phases.. - makeSLDProfiles(thisSldLaysIm, *ssubs, repeatLayers, b_theseLayers); - sldProfileIm.set_size(b_theseLayers.size(0), 2); - loop_ub = b_theseLayers.size(0); - for (i = 0; i < 2; i++) { - for (i1 = 0; i1 < loop_ub; i1++) { - sldProfileIm[i1 + sldProfileIm.size(0) * i] = b_theseLayers[i1 + - b_theseLayers.size(0) * i]; - } - } - } - } else { - sldProfile.set_size(1, 2); - sldProfile[0] = 0.0; - sldProfile[sldProfile.size(0)] = 0.0; - } - - // If required, then resample the SLD - if (resample == 1.0) { - if (!useImaginary) { - resampleLayers(sldProfile, resamPars, layerSld); - } else { - resampleLayersReIm(sldProfile, sldProfileIm, resamPars, layerSld); - } - - resamLayers.set_size(layerSld.size(0), layerSld.size(1)); - loop_ub = layerSld.size(1); - b_loop_ub = layerSld.size(0); - for (i = 0; i < loop_ub; i++) { - for (i1 = 0; i1 < b_loop_ub; i1++) { - resamLayers[i1 + resamLayers.size(0) * i] = layerSld[i1 + - layerSld.size(0) * i]; - } - } - } else { - resamLayers.set_size(1, 3); - resamLayers[0] = 0.0; - resamLayers[resamLayers.size(0)] = 0.0; - resamLayers[resamLayers.size(0) * 2] = 0.0; - } - - // Apply scale factors and q shifts to the data - b_data.set_size(data.size(0), data.size(1)); - loop_ub = data.size(1) - 1; - for (i = 0; i <= loop_ub; i++) { - b_loop_ub = data.size(0) - 1; - for (i1 = 0; i1 <= b_loop_ub; i1++) { - b_data[i1 + b_data.size(0) * i] = data[i1 + data.size(0) * i]; - } - } - - shiftData(sf, qshift, dataPresent, b_data, dataLimits, simLimits_data, - shifted_dat); - - // Calculate the reflectivity - callReflectivity(nba, nbs, simLimits_data, repeatLayers, shifted_dat, - layerSld, *ssubs, resol, useImaginary, reflect, Simul); - - // Apply background correction, either to the simulation or the data - applyBackgroundCorrection(reflect, Simul, shifted_dat, background, backsType); - - // Calculate chi squared. - *chiSq = chiSquared(shifted_dat, reflect, params); - } -} - -// End of code generation (standardTFLayersCore.cpp) diff --git a/RAT/standardTFLayersCore.h b/RAT/standardTFLayersCore.h deleted file mode 100644 index 75eb4694..00000000 --- a/RAT/standardTFLayersCore.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFLayersCore.h -// -// Code generation for function 'standardTFLayersCore' -// -#ifndef STANDARDTFLAYERSCORE_H -#define STANDARDTFLAYERSCORE_H - -// Include files -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void b_standardTFLayersCore(const ::coder::array &contrastLayers, - real_T rough, const char_T geometry_data[], const int32_T geometry_size[2], - real_T nba, real_T nbs, real_T resample, real_T calcSld, real_T sf, real_T - qshift, real_T dataPresent, const ::coder::array &data, const - real_T dataLimits[2], const real_T simLimits_data[], const real_T - repeatLayers[2], real_T background, real_T resol, real_T backsType, real_T - params, const real_T resamPars[2], boolean_T useImaginary, ::coder::array< - real_T, 2U> &sldProfile, ::coder::array &reflect, ::coder::array< - real_T, 2U> &Simul, ::coder::array &shifted_dat, ::coder::array< - real_T, 2U> &theseLayers, ::coder::array &resamLayers, real_T - *chiSq, real_T *ssubs); - void standardTFLayersCore(const ::coder::array &contrastLayers, - real_T rough, const char_T geometry_data[], const int32_T geometry_size[2], - real_T nba, real_T nbs, real_T resample, real_T calcSld, real_T sf, real_T - qshift, real_T dataPresent, const ::coder::array &data, const - real_T dataLimits[2], const real_T simLimits_data[], const real_T - repeatLayers[2], real_T background, real_T resol, real_T backsType, real_T - params, const real_T resamPars[2], boolean_T useImaginary, ::coder::array< - real_T, 2U> &sldProfile, ::coder::array &reflect, ::coder::array< - real_T, 2U> &Simul, ::coder::array &shifted_dat, ::coder::array< - real_T, 2U> &theseLayers, ::coder::array &resamLayers, real_T - *chiSq, real_T *ssubs); -} - -#endif - -// End of code generation (standardTFLayersCore.h) diff --git a/RAT/standardTFReflectivityCalculation.cpp b/RAT/standardTFReflectivityCalculation.cpp deleted file mode 100644 index 7f212a51..00000000 --- a/RAT/standardTFReflectivityCalculation.cpp +++ /dev/null @@ -1,151 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFReflectivityCalculation.cpp -// -// Code generation for function 'standardTFReflectivityCalculation' -// - -// Include files -#include "standardTFReflectivityCalculation.h" -#include "lower.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rt_nonfinite.h" -#include "standardTFCustomLayersReflectivityCalculation.h" -#include "standardTFCustomXYReflectivityCalculation.h" -#include "standardTFStandardLayersReflectivityCalculation.h" -#include "strcmp.h" -#include "coder_array.h" -#include "coder_bounded_array.h" - -// Function Definitions -namespace RAT -{ - void standardTFReflectivityCalculation(const struct0_T *problemDef, const - cell_19 *problemDefCells, const struct2_T *controls, struct4_T *problem, :: - coder::array &reflectivity, ::coder::array - &Simulation, ::coder::array &shifted_data, ::coder::array< - cell_wrap_15, 1U> &layerSlds, ::coder::array &sldProfiles, - ::coder::array &allLayers) - { - int32_T switch_expression_size[2]; - int32_T loop_ub_tmp; - char_T switch_expression_data[10000]; - - // Main function for the standardTF reflectivity calculation - // This function decides what type of model is being analysed and barnches - // to the correct one. The main options are: - // layers - This is the equivalent of Standard Layers in RasCAL - // Custom Layers - This is also a layers calculation, but the - // specification of the layers is dne using a user defined - // function. - // Custom XY - This also has a model described by a user supplied - // function, but in this case the function generates an - // SLD profile (i.e. XY function) rather than a list of - // layers. - // Find out the model type from the input structs - // Pre-allocate the output arrays.. this is necessary because otherwise - // the compiler complains with 'Output argument <....> is not assigned on - // some execution paths' error - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgrounds.set_size(loop_ub_tmp); - problem->qshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->nbairs.set_size(loop_ub_tmp); - problem->nbsubs.set_size(loop_ub_tmp); - problem->resolutions.set_size(loop_ub_tmp); - problem->calculations.all_chis.set_size(loop_ub_tmp); - problem->calculations.sum_chi = 0.0; - problem->allSubRough.set_size(loop_ub_tmp); - problem->resample.set_size(1, loop_ub_tmp); - reflectivity.set_size(loop_ub_tmp); - Simulation.set_size(loop_ub_tmp); - shifted_data.set_size(loop_ub_tmp); - layerSlds.set_size(loop_ub_tmp); - sldProfiles.set_size(loop_ub_tmp); - allLayers.set_size(loop_ub_tmp); - - for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgrounds[i] = 0.0; - problem->qshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->nbairs[i] = 0.0; - problem->nbsubs[i] = 0.0; - problem->resolutions[i] = 0.0; - problem->calculations.all_chis[i] = 0.0; - problem->allSubRough[i] = 0.0; - problem->resample[i] = 0.0; - reflectivity[i].f1.set_size(2, 2); - reflectivity[i].f1[0] = 1.0; - reflectivity[i].f1[1] = 1.0; - reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; - reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; - Simulation[i].f1.set_size(2, 2); - Simulation[i].f1[0] = 1.0; - Simulation[i].f1[1] = 1.0; - Simulation[i].f1[Simulation[i].f1.size(0)] = 1.0; - Simulation[i].f1[Simulation[i].f1.size(0) + 1] = 1.0; - shifted_data[i].f1.set_size(2, 3); - layerSlds[i].f1.set_size(2, 3); - sldProfiles[i].f1.set_size(2, 2); - sldProfiles[i].f1[0] = 1.0; - sldProfiles[i].f1[1] = 1.0; - sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; - sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; - allLayers[i].f1.set_size(2, 3); - for (int32_T b_i{0}; b_i < 3; b_i++) { - shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i] = 1.0; - shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i + 1] = 1.0; - layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; - layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; - allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; - allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; - } - } - - coder::lower(problemDef->modelType.data, problemDef->modelType.size, - switch_expression_data, switch_expression_size); - if (coder::internal::c_strcmp(switch_expression_data, switch_expression_size)) - { - loop_ub_tmp = 0; - } else if (coder::internal::d_strcmp(switch_expression_data, - switch_expression_size)) { - loop_ub_tmp = 1; - } else if (coder::internal::e_strcmp(switch_expression_data, - switch_expression_size)) { - loop_ub_tmp = 2; - } else { - loop_ub_tmp = -1; - } - - switch (loop_ub_tmp) { - case 0: - // Standard layers calculation - standardTFStandardLayersReflectivityCalculation(problemDef, - problemDefCells, controls, problem, reflectivity, Simulation, - shifted_data, layerSlds, sldProfiles, allLayers); - break; - - case 1: - // Custom layers with user supplied custom model file - standardTFCustomLayersReflectivityCalculation(problemDef, problemDefCells, - controls, problem, reflectivity, Simulation, shifted_data, layerSlds, - sldProfiles, allLayers); - break; - - case 2: - // Custom SLD profile with user defined model file - standardTFCustomXYReflectivityCalculation(problemDef, problemDefCells, - controls, problem, reflectivity, Simulation, shifted_data, layerSlds, - sldProfiles, allLayers); - break; - } - } -} - -// End of code generation (standardTFReflectivityCalculation.cpp) diff --git a/RAT/standardTFReflectivityCalculation.h b/RAT/standardTFReflectivityCalculation.h deleted file mode 100644 index 80289017..00000000 --- a/RAT/standardTFReflectivityCalculation.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFReflectivityCalculation.h -// -// Code generation for function 'standardTFReflectivityCalculation' -// -#ifndef STANDARDTFREFLECTIVITYCALCULATION_H -#define STANDARDTFREFLECTIVITYCALCULATION_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFReflectivityCalculation(const struct0_T *problemDef, const - cell_19 *problemDefCells, const struct2_T *controls, struct4_T *problem, :: - coder::array &reflectivity, ::coder::array - &Simulation, ::coder::array &shifted_data, ::coder::array< - cell_wrap_15, 1U> &layerSlds, ::coder::array &sldProfiles, - ::coder::array &allLayers); -} - -#endif - -// End of code generation (standardTFReflectivityCalculation.h) diff --git a/RAT/standardTFStandardLayersParallelContrasts.cpp b/RAT/standardTFStandardLayersParallelContrasts.cpp deleted file mode 100644 index b3aba987..00000000 --- a/RAT/standardTFStandardLayersParallelContrasts.cpp +++ /dev/null @@ -1,241 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFStandardLayersParallelContrasts.cpp -// -// Code generation for function 'standardTFStandardLayersParallelContrasts' -// - -// Include files -#include "standardTFStandardLayersParallelContrasts.h" -#include "allocateLayersForContrast.h" -#include "allocateParamsToLayers.h" -#include "backSort.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rt_nonfinite.h" -#include "standardTFLayersCore.h" -#include "coder_array.h" -#include "coder_bounded_array.h" -#include "omp.h" - -// Function Definitions -namespace RAT -{ - void standardTFStandardLayersParallelContrasts(const struct0_T *problemDef, - const cell_19 *problemDefCells, const struct2_T *controls, ::coder::array< - real_T, 1U> &outSsubs, ::coder::array &backgs, ::coder::array< - real_T, 1U> &qshifts, ::coder::array &sfs, ::coder::array &nbas, ::coder::array &nbss, ::coder::array - &resols, ::coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) - { - ::coder::array outParameterisedLayers; - ::coder::array Simul; - ::coder::array b_thisContrastLayers_data; - ::coder::array layerSld; - ::coder::array reflect; - ::coder::array resampledLayers; - ::coder::array shifted_dat; - ::coder::array sldProfile; - real_T thisContrastLayers_data[6000]; - real_T dv[2]; - real_T dv1[2]; - real_T calcSld; - real_T thisBackground; - real_T thisChiSquared; - real_T thisNba; - real_T thisNbs; - real_T thisQshift; - real_T thisResol; - real_T thisSf; - real_T thisSsubs; - int32_T thisContrastLayers_size[2]; - int32_T b_i; - int32_T b_loop_ub; - int32_T i1; - int32_T loop_ub; - int32_T nParams; - int32_T ub_loop; - boolean_T useImaginary; - - // Standard Layers calculation paralelised over the outer loop - // This is the main reflectivity calculation of the standard layers - // calculation type. It extracts the required paramters for the contrasts - // from the input arrays, then passes the main calculation to - // 'standardLayersCore', which carries out the calculation iteslf. - // The core calculation is common for both standard and custom layers. - // Extract individual cell arrays - // Splits up the master input list of all arrays into separate arrays - // The min input array 'problemDefCells' is a master array where - // all the cell arrays are grouped together. There are - // repeatLayers - controls repeating of the layers stack - // allData - Array of all the data arrays - // dataLimits - Min max limits in q for the data arrays - // simLimits - Limits in Q for the reflkectivity simulations - // Layers details - Master array of all available layers - // contrastLayers - Which specific combination of arrays are needed for - // each contrast. - // Custom files - Filenames and path for any custom files used - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); - calcSld = controls->calcSld; - useImaginary = problemDef->useImaginary; - - // Allocate the memory for the output arrays before the main loop - backgs.set_size(static_cast(problemDef->numberOfContrasts)); - - // end memory allocation. - // First we need to allocate the absolute values of the input - // parameters to all the layers in the layers list. This only needs - // to be done once, and so is done outside the contrasts loop - allocateParamsToLayers(problemDef->params, problemDefCells->f6, - outParameterisedLayers); - - // Resample parameters if required - // Loop over all the contrasts - outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); - sldProfiles.set_size(static_cast(problemDef->numberOfContrasts)); - reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); - Simulation.set_size(static_cast(problemDef->numberOfContrasts)); - shifted_data.set_size(static_cast(problemDef->numberOfContrasts)); - layerSlds.set_size(static_cast(problemDef->numberOfContrasts)); - chis.set_size(static_cast(problemDef->numberOfContrasts)); - qshifts.set_size(static_cast(problemDef->numberOfContrasts)); - sfs.set_size(static_cast(problemDef->numberOfContrasts)); - nbas.set_size(static_cast(problemDef->numberOfContrasts)); - nbss.set_size(static_cast(problemDef->numberOfContrasts)); - resols.set_size(static_cast(problemDef->numberOfContrasts)); - allRoughs.set_size(static_cast(problemDef->numberOfContrasts)); - allLayers.set_size(static_cast(problemDef->numberOfContrasts)); - ub_loop = static_cast(problemDef->numberOfContrasts) - 1; - -#pragma omp parallel for \ - num_threads(omp_get_max_threads()) \ - private(sldProfile,reflect,Simul,shifted_dat,layerSld,resampledLayers,thisSsubs,thisChiSquared,thisContrastLayers_data,thisContrastLayers_size,thisResol,thisNbs,thisNba,thisSf,thisQshift,thisBackground,dv,dv1,loop_ub,b_i,b_loop_ub,i1) \ - firstprivate(b_thisContrastLayers_data) - - for (int32_T i = 0; i <= ub_loop; i++) { - // Extract the relevant parameter values for this contrast - // from the input arrays. - // First need to decide which values of the backrounds, scalefactors - // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBacks[i], problemDef->contrastShifts[i], - problemDef->contrastScales[i], problemDef->contrastNbas[i], - problemDef->contrastNbss[i], problemDef->contrastRes[i], - problemDef->backs, problemDef->shifts, problemDef->sf, - problemDef->nba, problemDef->nbs, problemDef->res, - &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, - &thisResol); - - // Also need to determine which layers from the overall layers list - // are required for this contrast, and put them in the correct order - // according to geometry - allocateLayersForContrast(problemDefCells->f5[i].f1, - outParameterisedLayers, useImaginary, thisContrastLayers_data, - thisContrastLayers_size); - - // For the other parameters, we extract the correct ones from the input - // arrays - // Substrate roughness is always first parameter for standard layers - // Now call the core standardTF_stanlay reflectivity calculation - // In this case we are single cored, so we do not parallelise over - // points - // Call the core layers calculation - b_thisContrastLayers_data.set(&thisContrastLayers_data[0], - thisContrastLayers_size[0], thisContrastLayers_size[1]); - dv[0] = problemDefCells->f3[i].f1[0]; - dv[1] = problemDefCells->f3[i].f1[1]; - dv1[0] = problemDefCells->f1[i].f1[0]; - dv1[1] = problemDefCells->f1[i].f1[1]; - standardTFLayersCore(b_thisContrastLayers_data, problemDef->params[0], - problemDef->geometry.data, problemDef->geometry.size, - thisNba, thisNbs, problemDef->resample[i], calcSld, - thisSf, thisQshift, problemDef->dataPresent[i], - problemDefCells->f2[i].f1, dv, (const real_T *)((:: - coder::array *)&problemDefCells->f4[i].f1)->data(), dv1, - thisBackground, thisResol, - problemDef->contrastBacksType[i], static_cast - (nParams), controls->resamPars, useImaginary, - sldProfile, reflect, Simul, shifted_dat, layerSld, - resampledLayers, &thisChiSquared, &thisSsubs); - - // Store returned values for this contrast in the output arrays. - // As well as the calculated profiles, we also store a record of - // the other values (background, scalefactors etc) for each contrast - // for future use. - outSsubs[i] = thisSsubs; - loop_ub = sldProfile.size(1); - sldProfiles[i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); - for (b_i = 0; b_i < loop_ub; b_i++) { - b_loop_ub = sldProfile.size(0); - for (i1 = 0; i1 < b_loop_ub; i1++) { - sldProfiles[i].f1[i1 + sldProfiles[i].f1.size(0) * b_i] = - sldProfile[i1 + sldProfile.size(0) * b_i]; - } - } - - loop_ub = reflect.size(0); - reflectivity[i].f1.set_size(reflect.size(0), 2); - b_loop_ub = Simul.size(0); - Simulation[i].f1.set_size(Simul.size(0), 2); - for (b_i = 0; b_i < 2; b_i++) { - for (i1 = 0; i1 < loop_ub; i1++) { - reflectivity[i].f1[i1 + reflectivity[i].f1.size(0) * b_i] = reflect[i1 - + reflect.size(0) * b_i]; - } - - for (i1 = 0; i1 < b_loop_ub; i1++) { - Simulation[i].f1[i1 + Simulation[i].f1.size(0) * b_i] = Simul[i1 + - Simul.size(0) * b_i]; - } - } - - loop_ub = shifted_dat.size(1); - shifted_data[i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); - for (b_i = 0; b_i < loop_ub; b_i++) { - b_loop_ub = shifted_dat.size(0); - for (i1 = 0; i1 < b_loop_ub; i1++) { - shifted_data[i].f1[i1 + shifted_data[i].f1.size(0) * b_i] = - shifted_dat[i1 + shifted_dat.size(0) * b_i]; - } - } - - loop_ub = layerSld.size(1); - layerSlds[i].f1.set_size(layerSld.size(0), layerSld.size(1)); - for (b_i = 0; b_i < loop_ub; b_i++) { - b_loop_ub = layerSld.size(0); - for (i1 = 0; i1 < b_loop_ub; i1++) { - layerSlds[i].f1[i1 + layerSlds[i].f1.size(0) * b_i] = layerSld[i1 + - layerSld.size(0) * b_i]; - } - } - - chis[i] = thisChiSquared; - backgs[i] = thisBackground; - qshifts[i] = thisQshift; - sfs[i] = thisSf; - nbas[i] = thisNba; - nbss[i] = thisNbs; - resols[i] = thisResol; - allRoughs[i] = problemDef->params[0]; - loop_ub = resampledLayers.size(1); - allLayers[i].f1.set_size(resampledLayers.size(0), resampledLayers.size(1)); - for (b_i = 0; b_i < loop_ub; b_i++) { - b_loop_ub = resampledLayers.size(0); - for (i1 = 0; i1 < b_loop_ub; i1++) { - allLayers[i].f1[i1 + allLayers[i].f1.size(0) * b_i] = - resampledLayers[i1 + resampledLayers.size(0) * b_i]; - } - } - } - } -} - -// End of code generation (standardTFStandardLayersParallelContrasts.cpp) diff --git a/RAT/standardTFStandardLayersParallelContrasts.h b/RAT/standardTFStandardLayersParallelContrasts.h deleted file mode 100644 index af0de32c..00000000 --- a/RAT/standardTFStandardLayersParallelContrasts.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFStandardLayersParallelContrasts.h -// -// Code generation for function 'standardTFStandardLayersParallelContrasts' -// -#ifndef STANDARDTFSTANDARDLAYERSPARALLELCONTRASTS_H -#define STANDARDTFSTANDARDLAYERSPARALLELCONTRASTS_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFStandardLayersParallelContrasts(const struct0_T *problemDef, - const cell_19 *problemDefCells, const struct2_T *controls, ::coder::array< - real_T, 1U> &outSsubs, ::coder::array &backgs, ::coder::array< - real_T, 1U> &qshifts, ::coder::array &sfs, ::coder::array &nbas, ::coder::array &nbss, ::coder::array - &resols, ::coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); -} - -#endif - -// End of code generation (standardTFStandardLayersParallelContrasts.h) diff --git a/RAT/standardTFStandardLayersParallelPoints.cpp b/RAT/standardTFStandardLayersParallelPoints.cpp deleted file mode 100644 index 00aeb3da..00000000 --- a/RAT/standardTFStandardLayersParallelPoints.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFStandardLayersParallelPoints.cpp -// -// Code generation for function 'standardTFStandardLayersParallelPoints' -// - -// Include files -#include "standardTFStandardLayersParallelPoints.h" -#include "allocateLayersForContrast.h" -#include "allocateParamsToLayers.h" -#include "backSort.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rt_nonfinite.h" -#include "standardTFLayersCore.h" -#include "coder_array.h" -#include "coder_bounded_array.h" - -// Function Definitions -namespace RAT -{ - void standardTFStandardLayersParallelPoints(const struct0_T *problemDef, const - cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) - { - ::coder::array outParameterisedLayers; - ::coder::array b_thisContrastLayers_data; - ::coder::array layerSld; - ::coder::array resampledLayers; - ::coder::array shifted_dat; - ::coder::array sldProfile; - real_T thisContrastLayers_data[6000]; - real_T thisBackground; - real_T thisNba; - real_T thisNbs; - real_T thisQshift; - real_T thisResol; - real_T thisSf; - int32_T i; - boolean_T useImaginary; - - // Standard Layers calculation paralelised over the inner loop - // This is the main reflectivity calculation of the standard layers - // calculation type. It extracts the required paramters for the contrasts - // from the input arrays, then passes the main calculation to - // 'standardLayersCore', which carries out the calculation iteslf. - // The core calculation is common for both standard and custom layers. - // Extract individual cell arrays - // Splits up the master input list of all arrays into separate arrays - // The min input array 'problemDefCells' is a master array where - // all the cell arrays are grouped together. There are - // repeatLayers - controls repeating of the layers stack - // allData - Array of all the data arrays - // dataLimits - Min max limits in q for the data arrays - // simLimits - Limits in Q for the reflkectivity simulations - // Layers details - Master array of all available layers - // contrastLayers - Which specific combination of arrays are needed for - // each contrast. - // Custom files - Filenames and path for any custom files used - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - useImaginary = problemDef->useImaginary; - - // Allocate the memory for the output arrays before the main loop - i = static_cast(problemDef->numberOfContrasts); - backgs.set_size(i); - - // end memory allocation. - // First we need to allocate the absolute values of the input - // parameters to all the layers in the layers list. This only needs - // to be done once, and so is done outside the contrasts loop - allocateParamsToLayers(problemDef->params, problemDefCells->f6, - outParameterisedLayers); - - // Resample params if requiired - // Loop over all the contrasts - outSsubs.set_size(i); - sldProfiles.set_size(i); - reflectivity.set_size(i); - Simulation.set_size(i); - shifted_data.set_size(i); - layerSlds.set_size(i); - chis.set_size(i); - qshifts.set_size(i); - sfs.set_size(i); - nbas.set_size(i); - nbss.set_size(i); - resols.set_size(i); - allRoughs.set_size(i); - allLayers.set_size(i); - for (int32_T b_i{0}; b_i < i; b_i++) { - real_T dv[2]; - real_T dv1[2]; - int32_T thisContrastLayers_size[2]; - int32_T b_loop_ub; - int32_T loop_ub; - - // Extract the relevant parameter values for this contrast - // from the input arrays. - // First need to decide which values of the backrounds, scalefactors - // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], - problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], - problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], - problemDef->backs, problemDef->shifts, problemDef->sf, - problemDef->nba, problemDef->nbs, problemDef->res, - &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, - &thisResol); - - // Also need to determine which layers from the overall layers list - // are required for this contrast, and put them in the correct order - // according to geometry - allocateLayersForContrast(problemDefCells->f5[b_i].f1, - outParameterisedLayers, useImaginary, thisContrastLayers_data, - thisContrastLayers_size); - // For the other parameters, we extract the correct ones from the input - // arrays - // Substrate roughness is always first parameter for standard layers - // Now call the core standardTF_stanlay reflectivity calculation - // In this case we are single cored, so we do not parallelise over - // points - // Call the core layers calculation - b_thisContrastLayers_data.set(&thisContrastLayers_data[0], - thisContrastLayers_size[0], thisContrastLayers_size[1]); - dv[0] = problemDefCells->f3[b_i].f1[0]; - dv[1] = problemDefCells->f3[b_i].f1[1]; - dv1[0] = problemDefCells->f1[b_i].f1[0]; - dv1[1] = problemDefCells->f1[b_i].f1[1]; - b_standardTFLayersCore(b_thisContrastLayers_data, problemDef->params[0], - problemDef->geometry.data, problemDef->geometry.size, thisNba, thisNbs, - problemDef->resample[b_i], controls->calcSld, thisSf, thisQshift, - problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, dv, (const - real_T *)((::coder::array *)&problemDefCells->f4[b_i].f1) - ->data(), dv1, thisBackground, thisResol, problemDef-> - contrastBacksType[b_i], static_cast(problemDef->params.size(1)), - controls->resamPars, useImaginary, sldProfile, reflectivity[b_i].f1, - Simulation[b_i].f1, shifted_dat, layerSld, resampledLayers, &chis[b_i], - &outSsubs[b_i]); - // Store returned values for this contrast in the output arrays. - // As well as the calculated profiles, we also store a record of - // the other values (background, scalefactors etc) for each contrast - // for future use. - loop_ub = sldProfile.size(1); - sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = sldProfile.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = - sldProfile[i2 + sldProfile.size(0) * i1]; - } - } - - loop_ub = shifted_dat.size(1); - shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = shifted_dat.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1] = - shifted_dat[i2 + shifted_dat.size(0) * i1]; - } - } - - loop_ub = layerSld.size(1); - layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = layerSld.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = layerSld[i2 + - layerSld.size(0) * i1]; - } - } - - backgs[b_i] = thisBackground; - qshifts[b_i] = thisQshift; - sfs[b_i] = thisSf; - nbas[b_i] = thisNba; - nbss[b_i] = thisNbs; - resols[b_i] = thisResol; - allRoughs[b_i] = problemDef->params[0]; - loop_ub = resampledLayers.size(1); - allLayers[b_i].f1.set_size(resampledLayers.size(0), resampledLayers.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = resampledLayers.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = - resampledLayers[i2 + resampledLayers.size(0) * i1]; - } - } - } - } -} - -// End of code generation (standardTFStandardLayersParallelPoints.cpp) diff --git a/RAT/standardTFStandardLayersParallelPoints.h b/RAT/standardTFStandardLayersParallelPoints.h deleted file mode 100644 index 01a031aa..00000000 --- a/RAT/standardTFStandardLayersParallelPoints.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFStandardLayersParallelPoints.h -// -// Code generation for function 'standardTFStandardLayersParallelPoints' -// -#ifndef STANDARDTFSTANDARDLAYERSPARALLELPOINTS_H -#define STANDARDTFSTANDARDLAYERSPARALLELPOINTS_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFStandardLayersParallelPoints(const struct0_T *problemDef, const - cell_19 *problemDefCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); -} - -#endif - -// End of code generation (standardTFStandardLayersParallelPoints.h) diff --git a/RAT/standardTFStandardLayersReflectivityCalculation.cpp b/RAT/standardTFStandardLayersReflectivityCalculation.cpp deleted file mode 100644 index c6417f59..00000000 --- a/RAT/standardTFStandardLayersReflectivityCalculation.cpp +++ /dev/null @@ -1,154 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFStandardLayersReflectivityCalculation.cpp -// -// Code generation for function 'standardTFStandardLayersReflectivityCalculation' -// - -// Include files -#include "standardTFStandardLayersReflectivityCalculation.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rt_nonfinite.h" -#include "standardTFStandardLayersParallelContrasts.h" -#include "standardTFStandardLayersParallelPoints.h" -#include "standardTFStandardLayersSingle.h" -#include "strcmp.h" -#include "sum.h" -#include "coder_array.h" -#include "coder_bounded_array.h" - -// Function Definitions -namespace RAT -{ - void standardTFStandardLayersReflectivityCalculation(const struct0_T - *problemDef, const cell_19 *problemDefCells, const struct2_T *controls, - struct4_T *problem, ::coder::array &reflectivity, ::coder:: - array &Simulation, ::coder::array - &shifted_data, ::coder::array &layerSlds, ::coder::array< - cell_wrap_15, 1U> &sldProfiles, ::coder::array &allLayers) - { - int32_T loop_ub_tmp; - - // Standard layers reflectivity calculation for standardTF - // This function decides on parallelisation options before calling the - // relevant version ofthe main standard layers calculation. Parallelisation - // is either over the outer loop ('contrasts'), or the inner loop - // ('points'). The easiest way to do this is to have multiple versions of - // the same core calculation, rather than trying to make the parallel - // for loops conditional (although that would be much neater) There are: - // points - parallelise over points in the reflectivity calculation - // contrasts - parallelise over contrasts (outer for loop) - // Pre-allocation - It's necessary to - // pre-define the types for all the arrays - // for compilation, so do this in this block. - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgrounds.set_size(loop_ub_tmp); - problem->qshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->nbairs.set_size(loop_ub_tmp); - problem->nbsubs.set_size(loop_ub_tmp); - problem->calculations.all_chis.set_size(loop_ub_tmp); - problem->resolutions.set_size(loop_ub_tmp); - problem->allSubRough.set_size(loop_ub_tmp); - reflectivity.set_size(loop_ub_tmp); - Simulation.set_size(loop_ub_tmp); - shifted_data.set_size(loop_ub_tmp); - layerSlds.set_size(loop_ub_tmp); - sldProfiles.set_size(loop_ub_tmp); - allLayers.set_size(loop_ub_tmp); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgrounds[i] = 0.0; - problem->qshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->nbairs[i] = 0.0; - problem->nbsubs[i] = 0.0; - problem->calculations.all_chis[i] = 0.0; - problem->resolutions[i] = 0.0; - problem->allSubRough[i] = 0.0; - reflectivity[i].f1.set_size(2, 2); - reflectivity[i].f1[0] = 1.0; - reflectivity[i].f1[1] = 1.0; - reflectivity[i].f1[reflectivity[i].f1.size(0)] = 1.0; - reflectivity[i].f1[reflectivity[i].f1.size(0) + 1] = 1.0; - Simulation[i].f1.set_size(2, 2); - Simulation[i].f1[0] = 1.0; - Simulation[i].f1[1] = 1.0; - Simulation[i].f1[Simulation[i].f1.size(0)] = 1.0; - Simulation[i].f1[Simulation[i].f1.size(0) + 1] = 1.0; - shifted_data[i].f1.set_size(2, 3); - layerSlds[i].f1.set_size(2, 3); - sldProfiles[i].f1.set_size(2, 2); - sldProfiles[i].f1[0] = 1.0; - sldProfiles[i].f1[1] = 1.0; - sldProfiles[i].f1[sldProfiles[i].f1.size(0)] = 1.0; - sldProfiles[i].f1[sldProfiles[i].f1.size(0) + 1] = 1.0; - allLayers[i].f1.set_size(2, 3); - for (int32_T b_i{0}; b_i < 3; b_i++) { - shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i] = 1.0; - shifted_data[i].f1[shifted_data[i].f1.size(0) * b_i + 1] = 1.0; - layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i] = 1.0; - layerSlds[i].f1[layerSlds[i].f1.size(0) * b_i + 1] = 1.0; - allLayers[i].f1[allLayers[i].f1.size(0) * b_i] = 1.0; - allLayers[i].f1[allLayers[i].f1.size(0) * b_i + 1] = 1.0; - } - } - - // ------- End type definitions ------------- - if (coder::internal::f_strcmp(controls->para.data, controls->para.size)) { - loop_ub_tmp = 0; - } else if (coder::internal::g_strcmp(controls->para.data, - controls->para.size)) { - loop_ub_tmp = 1; - } else if (coder::internal::h_strcmp(controls->para.data, - controls->para.size)) { - loop_ub_tmp = 2; - } else { - loop_ub_tmp = -1; - } - - switch (loop_ub_tmp) { - case 0: - standardTFStandardLayersSingle(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgrounds, problem->qshifts, - problem->scalefactors, problem->nbairs, problem->nbsubs, - problem->resolutions, problem->calculations.all_chis, reflectivity, - Simulation, shifted_data, layerSlds, sldProfiles, allLayers, - problem->allSubRough); - break; - - case 1: - standardTFStandardLayersParallelPoints(problemDef, problemDefCells, - controls, problem->ssubs, problem->backgrounds, problem->qshifts, - problem->scalefactors, problem->nbairs, problem->nbsubs, - problem->resolutions, problem->calculations.all_chis, reflectivity, - Simulation, shifted_data, layerSlds, sldProfiles, allLayers, - problem->allSubRough); - break; - - case 2: - standardTFStandardLayersParallelContrasts(problemDef, problemDefCells, - controls, problem->ssubs, problem->backgrounds, problem->qshifts, - problem->scalefactors, problem->nbairs, problem->nbsubs, - problem->resolutions, problem->calculations.all_chis, reflectivity, - Simulation, shifted_data, layerSlds, sldProfiles, allLayers, - problem->allSubRough); - break; - } - - // Package everything into one array for tidy output - problem->calculations.sum_chi = coder::sum(problem->calculations.all_chis); - problem->resample.set_size(1, problemDef->resample.size(1)); - loop_ub_tmp = problemDef->resample.size(1); - for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - problem->resample[b_i] = problemDef->resample[b_i]; - } - } -} - -// End of code generation (standardTFStandardLayersReflectivityCalculation.cpp) diff --git a/RAT/standardTFStandardLayersReflectivityCalculation.h b/RAT/standardTFStandardLayersReflectivityCalculation.h deleted file mode 100644 index 6cd3a8b2..00000000 --- a/RAT/standardTFStandardLayersReflectivityCalculation.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFStandardLayersReflectivityCalculation.h -// -// Code generation for function 'standardTFStandardLayersReflectivityCalculation' -// -#ifndef STANDARDTFSTANDARDLAYERSREFLECTIVITYCALCULATION_H -#define STANDARDTFSTANDARDLAYERSREFLECTIVITYCALCULATION_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFStandardLayersReflectivityCalculation(const struct0_T - *problemDef, const cell_19 *problemDefCells, const struct2_T *controls, - struct4_T *problem, ::coder::array &reflectivity, ::coder:: - array &Simulation, ::coder::array - &shifted_data, ::coder::array &layerSlds, ::coder::array< - cell_wrap_15, 1U> &sldProfiles, ::coder::array &allLayers); -} - -#endif - -// End of code generation (standardTFStandardLayersReflectivityCalculation.h) diff --git a/RAT/standardTFStandardLayersSingle.cpp b/RAT/standardTFStandardLayersSingle.cpp deleted file mode 100644 index 107a7949..00000000 --- a/RAT/standardTFStandardLayersSingle.cpp +++ /dev/null @@ -1,208 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFStandardLayersSingle.cpp -// -// Code generation for function 'standardTFStandardLayersSingle' -// - -// Include files -#include "standardTFStandardLayersSingle.h" -#include "allocateLayersForContrast.h" -#include "allocateParamsToLayers.h" -#include "backSort.h" -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rt_nonfinite.h" -#include "standardTFLayersCore.h" -#include "coder_array.h" -#include "coder_bounded_array.h" - -// Function Definitions -namespace RAT -{ - void standardTFStandardLayersSingle(const struct0_T *problemDef, const cell_19 - *problemDefCells, const struct2_T *controls, ::coder::array - &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) - { - ::coder::array outParameterisedLayers; - ::coder::array b_thisContrastLayers_data; - ::coder::array layerSld; - ::coder::array resampledLayers; - ::coder::array shifted_dat; - ::coder::array sldProfile; - real_T thisContrastLayers_data[6000]; - real_T thisBackground; - real_T thisNba; - real_T thisNbs; - real_T thisQshift; - real_T thisResol; - real_T thisSf; - int32_T i; - boolean_T useImaginary; - - // Single theraded version of the Standard Layers calculation - // This is the main reflectivity calculation of the standard layers - // calculation type. It extracts the required paramters for the contrasts - // from the input arrays, then passes the main calculation to - // 'standardLayersCore', which carries out the calculation iteslf. - // The core calculation is common for both standard and custom layers. - // Extract individual cell arrays - // Splits up the master input list of all arrays into separate arrays - // The min input array 'problemDefCells' is a master array where - // all the cell arrays are grouped together. There are - // repeatLayers - controls repeating of the layers stack - // allData - Array of all the data arrays - // dataLimits - Min max limits in q for the data arrays - // simLimits - Limits in Q for the reflkectivity simulations - // Layers details - Master array of all available layers - // contrastLayers - Which specific combination of arrays are needed for - // each contrast. - // Custom files - Filenames and path for any custom files used - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - useImaginary = problemDef->useImaginary; - - // Allocate the memory for the output arrays before the main loop - i = static_cast(problemDef->numberOfContrasts); - backgs.set_size(i); - - // end memory allocation. - // First we need to allocate the absolute values of the input - // parameters to all the layers in the layers list. This only needs - // to be done once, and so is done outside the contrasts loop - allocateParamsToLayers(problemDef->params, problemDefCells->f6, - outParameterisedLayers); - - // Resample params if requiired - // Loop over all the contrasts - outSsubs.set_size(i); - sldProfiles.set_size(i); - reflectivity.set_size(i); - Simulation.set_size(i); - shifted_data.set_size(i); - layerSlds.set_size(i); - chis.set_size(i); - qshifts.set_size(i); - sfs.set_size(i); - nbas.set_size(i); - nbss.set_size(i); - resols.set_size(i); - allRoughs.set_size(i); - allLayers.set_size(i); - for (int32_T b_i{0}; b_i < i; b_i++) { - real_T dv[2]; - real_T dv1[2]; - int32_T thisContrastLayers_size[2]; - int32_T b_loop_ub; - int32_T loop_ub; - - // Extract the relevant parameter values for this contrast - // from the input arrays. - // First need to decide which values of the backrounds, scalefactors - // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBacks[b_i], problemDef->contrastShifts[b_i], - problemDef->contrastScales[b_i], problemDef->contrastNbas[b_i], - problemDef->contrastNbss[b_i], problemDef->contrastRes[b_i], - problemDef->backs, problemDef->shifts, problemDef->sf, - problemDef->nba, problemDef->nbs, problemDef->res, - &thisBackground, &thisQshift, &thisSf, &thisNba, &thisNbs, - &thisResol); - - // Also need to determine which layers from the overall layers list - // are required for this contrast, and put them in the correct order - // according to geometry - allocateLayersForContrast(problemDefCells->f5[b_i].f1, - outParameterisedLayers, useImaginary, thisContrastLayers_data, - thisContrastLayers_size); - - // For the other parameters, we extract the correct ones from the input - // arrays - // Substrate roughness is always first parameter for standard layers - // Now call the core standardTF_stanlay reflectivity calculation - // In this case we are single cored, so we do not parallelise over - // points - // Call the core layers calculation - b_thisContrastLayers_data.set(&thisContrastLayers_data[0], - thisContrastLayers_size[0], thisContrastLayers_size[1]); - dv[0] = problemDefCells->f3[b_i].f1[0]; - dv[1] = problemDefCells->f3[b_i].f1[1]; - dv1[0] = problemDefCells->f1[b_i].f1[0]; - dv1[1] = problemDefCells->f1[b_i].f1[1]; - standardTFLayersCore(b_thisContrastLayers_data, problemDef->params[0], - problemDef->geometry.data, problemDef->geometry.size, - thisNba, thisNbs, problemDef->resample[b_i], - controls->calcSld, thisSf, thisQshift, - problemDef->dataPresent[b_i], problemDefCells->f2[b_i] - .f1, dv, (const real_T *)((::coder::array - *)&problemDefCells->f4[b_i].f1)->data(), dv1, thisBackground, thisResol, - problemDef->contrastBacksType[b_i], - static_cast(problemDef->params.size(1)), - controls->resamPars, useImaginary, sldProfile, - reflectivity[b_i].f1, Simulation[b_i].f1, shifted_dat, - layerSld, resampledLayers, &chis[b_i], &outSsubs[b_i]); - - // Store returned values for this contrast in the output arrays. - // As well as the calculated profiles, we also store a record of - // the other values (background, scalefactors etc) for each contrast - // for future use. - loop_ub = sldProfile.size(1); - sldProfiles[b_i].f1.set_size(sldProfile.size(0), sldProfile.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = sldProfile.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - sldProfiles[b_i].f1[i2 + sldProfiles[b_i].f1.size(0) * i1] = - sldProfile[i2 + sldProfile.size(0) * i1]; - } - } - - loop_ub = shifted_dat.size(1); - shifted_data[b_i].f1.set_size(shifted_dat.size(0), shifted_dat.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = shifted_dat.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - shifted_data[b_i].f1[i2 + shifted_data[b_i].f1.size(0) * i1] = - shifted_dat[i2 + shifted_dat.size(0) * i1]; - } - } - - loop_ub = layerSld.size(1); - layerSlds[b_i].f1.set_size(layerSld.size(0), layerSld.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = layerSld.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - layerSlds[b_i].f1[i2 + layerSlds[b_i].f1.size(0) * i1] = layerSld[i2 + - layerSld.size(0) * i1]; - } - } - - backgs[b_i] = thisBackground; - qshifts[b_i] = thisQshift; - sfs[b_i] = thisSf; - nbas[b_i] = thisNba; - nbss[b_i] = thisNbs; - resols[b_i] = thisResol; - allRoughs[b_i] = problemDef->params[0]; - loop_ub = resampledLayers.size(1); - allLayers[b_i].f1.set_size(resampledLayers.size(0), resampledLayers.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = resampledLayers.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = - resampledLayers[i2 + resampledLayers.size(0) * i1]; - } - } - } - } -} - -// End of code generation (standardTFStandardLayersSingle.cpp) diff --git a/RAT/standardTFStandardLayersSingle.h b/RAT/standardTFStandardLayersSingle.h deleted file mode 100644 index 366b5869..00000000 --- a/RAT/standardTFStandardLayersSingle.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Non-Degree Granting Education License -- for use at non-degree -// granting, nonprofit, education, and research organizations only. Not -// for commercial or industrial use. -// -// standardTFStandardLayersSingle.h -// -// Code generation for function 'standardTFStandardLayersSingle' -// -#ifndef STANDARDTFSTANDARDLAYERSSINGLE_H -#define STANDARDTFSTANDARDLAYERSSINGLE_H - -// Include files -#include "reflectivityCalculation_internal_types.h" -#include "reflectivityCalculation_types.h" -#include "rtwtypes.h" -#include "coder_array.h" -#include -#include - -// Function Declarations -namespace RAT -{ - void standardTFStandardLayersSingle(const struct0_T *problemDef, const cell_19 - *problemDefCells, const struct2_T *controls, ::coder::array - &outSsubs, ::coder::array &backgs, ::coder::array - &qshifts, ::coder::array &sfs, ::coder::array &nbas, - ::coder::array &nbss, ::coder::array &resols, :: - coder::array &chis, ::coder::array - &reflectivity, ::coder::array &Simulation, ::coder::array< - cell_wrap_15, 1U> &shifted_data, ::coder::array &layerSlds, - ::coder::array &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); -} - -#endif - -// End of code generation (standardTFStandardLayersSingle.h) diff --git a/RAT/std.cpp b/RAT/std.cpp new file mode 100644 index 00000000..c8fd25e6 --- /dev/null +++ b/RAT/std.cpp @@ -0,0 +1,59 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// std.cpp +// +// Code generation for function 'std' +// + +// Include files +#include "std.h" +#include "rt_nonfinite.h" +#include "varstd.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_std(const ::coder::array &x, ::coder::array + &y) + { + ::coder::array xv; + int32_T hi; + int32_T loop_ub; + int32_T nx; + int32_T outsize_idx_0; + y.set_size(1, x.size(1)); + hi = x.size(1); + for (int32_T k{0}; k < hi; k++) { + y[k] = 0.0; + } + + hi = x.size(1); + if (x.size(1) - 1 >= 0) { + nx = x.size(0); + outsize_idx_0 = x.size(0); + loop_ub = x.size(0); + } + + for (int32_T b_k{0}; b_k < hi; b_k++) { + xv.set_size(outsize_idx_0); + for (int32_T k{0}; k < loop_ub; k++) { + xv[k] = 0.0; + } + + for (int32_T k{0}; k < nx; k++) { + xv[k] = x[k + x.size(0) * b_k]; + } + + y[b_k] = varstd_anonFcn3(x.size(0), xv); + } + } + } +} + +// End of code generation (std.cpp) diff --git a/RAT/std.h b/RAT/std.h new file mode 100644 index 00000000..23ae5d28 --- /dev/null +++ b/RAT/std.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// std.h +// +// Code generation for function 'std' +// +#ifndef STD_H +#define STD_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_std(const ::coder::array &x, ::coder::array + &y); + } +} + +#endif + +// End of code generation (std.h) diff --git a/RAT/str2double.cpp b/RAT/str2double.cpp new file mode 100644 index 00000000..9234d0d5 --- /dev/null +++ b/RAT/str2double.cpp @@ -0,0 +1,98 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// str2double.cpp +// +// Code generation for function 'str2double' +// + +// Include files +#include "str2double.h" +#include "rt_nonfinite.h" +#include "str2double1.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + creal_T str2double(const char_T s_data[], const int32_T s_size[2]) + { + creal_T x; + real_T v1; + real_T v2; + int32_T idx; + int32_T k; + char_T s1_data[10002]; + boolean_T a__1; + boolean_T foundsign; + boolean_T isfinite1; + boolean_T isfinite2; + boolean_T isimag1; + boolean_T success; + x.re = rtNaN; + x.im = 0.0; + if (s_size[1] >= 1) { + int32_T ntoread; + ntoread = 0; + k = s_size[1] + 2; + std::memset(&s1_data[0], 0, static_cast(k) * sizeof(char_T)); + idx = 1; + k = internal::skipspaces(s_data, s_size[1]); + internal::readfloat(s1_data, &idx, s_data, &k, s_size[1], &isimag1, + &isfinite1, &v1, &a__1, &success); + if (isfinite1) { + ntoread = 1; + } + + if (success && (k <= s_size[1])) { + s1_data[idx - 1] = ' '; + idx++; + internal::readfloat(s1_data, &idx, s_data, &k, s_size[1], &a__1, + &isfinite2, &v2, &foundsign, &success); + if (isfinite2) { + ntoread++; + } + + if (success && (k > s_size[1]) && (isimag1 ^ a__1) && foundsign) { + success = true; + } else { + success = false; + } + } else { + v2 = 0.0; + } + + if (success) { + s1_data[idx - 1] = '\x00'; + if (ntoread == 2) { + internal::sscanfd(s1_data, &v1, &v2); + } else if (ntoread == 1) { + real_T a; + a = internal::sscanfd(s1_data); + if (isfinite1) { + v1 = a; + } else { + v2 = a; + } + } + + if (isimag1) { + x.re = v2; + x.im = v1; + } else { + x.re = v1; + x.im = v2; + } + } + } + + return x; + } + } +} + +// End of code generation (str2double.cpp) diff --git a/RAT/str2double.h b/RAT/str2double.h new file mode 100644 index 00000000..4f7fb9ea --- /dev/null +++ b/RAT/str2double.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// str2double.h +// +// Code generation for function 'str2double' +// +#ifndef STR2DOUBLE_H +#define STR2DOUBLE_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + creal_T str2double(const char_T s_data[], const int32_T s_size[2]); + } +} + +#endif + +// End of code generation (str2double.h) diff --git a/RAT/str2double1.cpp b/RAT/str2double1.cpp new file mode 100644 index 00000000..4ccb9d97 --- /dev/null +++ b/RAT/str2double1.cpp @@ -0,0 +1,478 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// str2double1.cpp +// +// Code generation for function 'str2double1' +// + +// Include files +#include "str2double1.h" +#include "rt_nonfinite.h" +#include + +// Variable Definitions +namespace RAT +{ + static const boolean_T bv[128]{ false, false, false, false, false, false, + false, false, false, true, true, true, true, true, false, false, false, + false, false, false, false, false, false, false, false, false, false, false, + true, true, true, true, true, false, false, false, false, false, false, + false, false, false, false, false, false, false, false, false, false, false, + false, false, false, false, false, false, false, false, false, false, false, + false, false, false, false, false, false, false, false, false, false, false, + false, false, false, false, false, false, false, false, false, false, false, + false, false, false, false, false, false, false, false, false, false, false, + false, false, false, false, false, false, false, false, false, false, false, + false, false, false, false, false, false, false, false, false, false, false, + false, false, false, false, false, false, false, false, false, false, false, + false }; +} + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + static void b_copysign(char_T s1_data[], int32_T *idx, const char_T + s_data[], int32_T *k, int32_T n, boolean_T *foundsign, boolean_T + *success); + static void b_readNonFinite(const char_T s_data[], int32_T *k, int32_T n, + boolean_T *b_finite, real_T *fv); + static void b_readfloat(char_T s1_data[], int32_T *idx, const char_T + s_data[], int32_T *k, int32_T n, boolean_T *isimag, boolean_T *b_finite, + real_T *nfv, boolean_T *foundsign, boolean_T *success); + static boolean_T copydigits(char_T s1_data[], int32_T *idx, const char_T + s_data[], int32_T *k, int32_T n, boolean_T allowpoint); + static boolean_T copyexponent(char_T s1_data[], int32_T *idx, const char_T + s_data[], int32_T *k, int32_T n); + static boolean_T isUnitImag(const char_T s_data[], int32_T k, int32_T n); + static boolean_T readNonFinite(const char_T s_data[], int32_T k, int32_T n); + static void skipspaces(const char_T s_data[], int32_T *k, int32_T n); + } + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + static void b_copysign(char_T s1_data[], int32_T *idx, const char_T + s_data[], int32_T *k, int32_T n, boolean_T *foundsign, boolean_T + *success) + { + boolean_T exitg1; + boolean_T isneg; + isneg = false; + *foundsign = false; + exitg1 = false; + while ((!exitg1) && (*k <= n)) { + char_T c; + c = s_data[*k - 1]; + if (c == '-') { + isneg = !isneg; + *foundsign = true; + (*k)++; + } else if (c == ',') { + (*k)++; + } else if (c == '+') { + *foundsign = true; + (*k)++; + } else if (!bv[static_cast(c) & 127]) { + exitg1 = true; + } else { + (*k)++; + } + } + + *success = (*k <= n); + if ((*success) && isneg) { + if ((*idx >= 2) && (s1_data[*idx - 2] == '-')) { + s1_data[*idx - 2] = ' '; + } else { + s1_data[*idx - 1] = '-'; + (*idx)++; + } + } + } + + static void b_readNonFinite(const char_T s_data[], int32_T *k, int32_T n, + boolean_T *b_finite, real_T *fv) + { + int32_T ksaved; + char_T c_idx_0; + char_T c_idx_1; + char_T c_idx_2; + ksaved = *k; + c_idx_0 = '\x00'; + while ((*k <= n) && (s_data[*k - 1] == ',')) { + (*k)++; + } + + if (*k <= n) { + c_idx_0 = s_data[*k - 1]; + } + + (*k)++; + c_idx_1 = '\x00'; + while ((*k <= n) && (s_data[*k - 1] == ',')) { + (*k)++; + } + + if (*k <= n) { + c_idx_1 = s_data[*k - 1]; + } + + (*k)++; + c_idx_2 = '\x00'; + while ((*k <= n) && (s_data[*k - 1] == ',')) { + (*k)++; + } + + if (*k <= n) { + c_idx_2 = s_data[*k - 1]; + } + + (*k)++; + if (((c_idx_0 == 'I') || (c_idx_0 == 'i')) && ((c_idx_1 == 'N') || + (c_idx_1 == 'n')) && ((c_idx_2 == 'F') || (c_idx_2 == 'f'))) { + *b_finite = false; + *fv = rtInf; + } else if (((c_idx_0 == 'N') || (c_idx_0 == 'n')) && ((c_idx_1 == 'A') || + (c_idx_1 == 'a')) && ((c_idx_2 == 'N') || (c_idx_2 == 'n'))) + { + *b_finite = false; + *fv = rtNaN; + } else { + *b_finite = true; + *fv = 0.0; + *k = ksaved; + } + } + + static void b_readfloat(char_T s1_data[], int32_T *idx, const char_T + s_data[], int32_T *k, int32_T n, boolean_T *isimag, boolean_T *b_finite, + real_T *nfv, boolean_T *foundsign, boolean_T *success) + { + int32_T b_idx; + *isimag = false; + *b_finite = true; + *nfv = 0.0; + b_idx = *idx; + b_copysign(s1_data, &b_idx, s_data, k, n, foundsign, success); + *idx = b_idx; + if (*success) { + if (isUnitImag(s_data, *k, n)) { + *success = false; + } else { + b_readNonFinite(s_data, k, n, b_finite, nfv); + if (*b_finite) { + *success = copydigits(s1_data, idx, s_data, k, n, true); + if (*success) { + *success = copyexponent(s1_data, idx, s_data, k, n); + } + } else if ((b_idx >= 2) && (s1_data[b_idx - 2] == '-')) { + *idx = b_idx - 1; + s1_data[b_idx - 2] = ' '; + *nfv = -*nfv; + } + + skipspaces(s_data, k, n); + if ((*k <= n) && (s_data[*k - 1] == '*')) { + (*k)++; + skipspaces(s_data, k, n); + } + + if (*k <= n) { + char_T c; + c = s_data[*k - 1]; + if ((c == 'i') || (c == 'j')) { + (*k)++; + *isimag = true; + } + } + } + + skipspaces(s_data, k, n); + } + } + + static boolean_T copydigits(char_T s1_data[], int32_T *idx, const char_T + s_data[], int32_T *k, int32_T n, boolean_T allowpoint) + { + boolean_T exitg1; + boolean_T haspoint; + boolean_T success; + success = (*k <= n); + haspoint = false; + exitg1 = false; + while ((!exitg1) && (success && (*k <= n))) { + char_T c; + c = s_data[*k - 1]; + if ((c >= '0') && (c <= '9')) { + s1_data[*idx - 1] = c; + (*idx)++; + (*k)++; + } else if (c == '.') { + if (allowpoint && (!haspoint)) { + success = true; + } else { + success = false; + } + + if (success) { + s1_data[*idx - 1] = '.'; + (*idx)++; + haspoint = true; + } + + (*k)++; + } else if (c == ',') { + (*k)++; + } else { + exitg1 = true; + } + } + + return success; + } + + static boolean_T copyexponent(char_T s1_data[], int32_T *idx, const char_T + s_data[], int32_T *k, int32_T n) + { + boolean_T success; + success = true; + if (*k <= n) { + char_T c; + c = s_data[*k - 1]; + if ((c == 'E') || (c == 'e')) { + int32_T kexp; + boolean_T b_success; + s1_data[*idx - 1] = 'e'; + (*idx)++; + (*k)++; + while ((*k <= n) && (s_data[*k - 1] == ',')) { + (*k)++; + } + + if (*k <= n) { + if (s_data[*k - 1] == '-') { + s1_data[*idx - 1] = '-'; + (*idx)++; + (*k)++; + } else if (s_data[*k - 1] == '+') { + (*k)++; + } + } + + kexp = *k; + b_success = copydigits(s1_data, idx, s_data, k, n, false); + if ((!b_success) || (*k <= kexp)) { + success = false; + } + } + } + + return success; + } + + static boolean_T isUnitImag(const char_T s_data[], int32_T k, int32_T n) + { + boolean_T p; + p = false; + if (k <= n) { + char_T c; + c = s_data[k - 1]; + if (c == 'j') { + p = true; + } else if (c == 'i') { + if (k >= n - 1) { + p = true; + } else { + p = readNonFinite(s_data, k, n); + } + } + } + + return p; + } + + static boolean_T readNonFinite(const char_T s_data[], int32_T k, int32_T n) + { + int32_T b_k; + char_T c_idx_0; + char_T c_idx_1; + char_T c_idx_2; + boolean_T b_finite; + b_k = k; + c_idx_0 = '\x00'; + while ((b_k <= n) && (s_data[b_k - 1] == ',')) { + b_k++; + } + + if (b_k <= n) { + c_idx_0 = s_data[b_k - 1]; + } + + b_k++; + c_idx_1 = '\x00'; + while ((b_k <= n) && (s_data[b_k - 1] == ',')) { + b_k++; + } + + if (b_k <= n) { + c_idx_1 = s_data[b_k - 1]; + } + + b_k++; + c_idx_2 = '\x00'; + while ((b_k <= n) && (s_data[b_k - 1] == ',')) { + b_k++; + } + + if (b_k <= n) { + c_idx_2 = s_data[b_k - 1]; + } + + if (((c_idx_0 == 'I') || (c_idx_0 == 'i')) && ((c_idx_1 == 'N') || + (c_idx_1 == 'n')) && ((c_idx_2 == 'F') || (c_idx_2 == 'f'))) { + b_finite = false; + } else if (((c_idx_0 == 'N') || (c_idx_0 == 'n')) && ((c_idx_1 == 'A') || + (c_idx_1 == 'a')) && ((c_idx_2 == 'N') || (c_idx_2 == 'n'))) + { + b_finite = false; + } else { + b_finite = true; + } + + return b_finite; + } + + static void skipspaces(const char_T s_data[], int32_T *k, int32_T n) + { + boolean_T exitg1; + exitg1 = false; + while ((!exitg1) && (*k <= n)) { + char_T c; + c = s_data[*k - 1]; + if (bv[static_cast(c) & 127] || (c == '\x00') || (c == ',')) + { + (*k)++; + } else { + exitg1 = true; + } + } + } + + void readfloat(char_T s1_data[], int32_T *idx, const char_T s_data[], + int32_T *k, int32_T n, boolean_T *isimag, boolean_T + *b_finite, real_T *nfv, boolean_T *foundsign, boolean_T + *success) + { + int32_T b_idx; + boolean_T a__2; + boolean_T a__3; + *isimag = false; + *b_finite = true; + *nfv = 0.0; + b_idx = *idx; + b_copysign(s1_data, &b_idx, s_data, k, n, foundsign, success); + *idx = b_idx; + if (*success) { + if (isUnitImag(s_data, *k, n)) { + *isimag = true; + (*k)++; + skipspaces(s_data, k, n); + if ((*k <= n) && (s_data[*k - 1] == '*')) { + (*k)++; + b_readfloat(s1_data, idx, s_data, k, n, &a__2, b_finite, nfv, + &a__3, success); + } else { + s1_data[b_idx - 1] = '1'; + *idx = b_idx + 1; + } + } else { + b_readNonFinite(s_data, k, n, b_finite, nfv); + if (*b_finite) { + *success = copydigits(s1_data, idx, s_data, k, n, true); + if (*success) { + *success = copyexponent(s1_data, idx, s_data, k, n); + } + } else if ((b_idx >= 2) && (s1_data[b_idx - 2] == '-')) { + *idx = b_idx - 1; + s1_data[b_idx - 2] = ' '; + *nfv = -*nfv; + } + + skipspaces(s_data, k, n); + if ((*k <= n) && (s_data[*k - 1] == '*')) { + (*k)++; + skipspaces(s_data, k, n); + } + + if (*k <= n) { + char_T c; + c = s_data[*k - 1]; + if ((c == 'i') || (c == 'j')) { + (*k)++; + *isimag = true; + } + } + } + + skipspaces(s_data, k, n); + } + } + + int32_T skipspaces(const char_T s_data[], int32_T n) + { + int32_T k; + boolean_T exitg1; + k = 1; + exitg1 = false; + while ((!exitg1) && (k <= n)) { + char_T c; + c = s_data[k - 1]; + if (bv[static_cast(c) & 127] || (c == '\x00')) { + k++; + } else { + exitg1 = true; + } + } + + return k; + } + + real_T sscanfd(const char_T s_data[]) + { + real_T out1; + int32_T nread; + nread = sscanf(&s_data[0], "%lf", &out1); + if (nread != 1) { + out1 = rtNaN; + } + + return out1; + } + + void sscanfd(const char_T s_data[], real_T *out1, real_T *out2) + { + int32_T nread; + nread = sscanf(&s_data[0], "%lf %lf", out1, out2); + if (nread != 2) { + *out1 = rtNaN; + *out2 = rtNaN; + } + } + } + } +} + +// End of code generation (str2double1.cpp) diff --git a/RAT/str2double1.h b/RAT/str2double1.h new file mode 100644 index 00000000..ebe9877e --- /dev/null +++ b/RAT/str2double1.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// str2double1.h +// +// Code generation for function 'str2double1' +// +#ifndef STR2DOUBLE1_H +#define STR2DOUBLE1_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void readfloat(char_T s1_data[], int32_T *idx, const char_T s_data[], + int32_T *k, int32_T n, boolean_T *isimag, boolean_T + *b_finite, real_T *nfv, boolean_T *foundsign, boolean_T + *success); + int32_T skipspaces(const char_T s_data[], int32_T n); + real_T sscanfd(const char_T s_data[]); + void sscanfd(const char_T s_data[], real_T *out1, real_T *out2); + } + } +} + +#endif + +// End of code generation (str2double1.h) diff --git a/RAT/strcmp.cpp b/RAT/strcmp.cpp index 73e719e1..e93ec1f9 100644 --- a/RAT/strcmp.cpp +++ b/RAT/strcmp.cpp @@ -10,8 +10,10 @@ // Include files #include "strcmp.h" -#include "reflectivityCalculation_data.h" +#include "RATMain_data.h" +#include "RATMain_types.h" #include "rt_nonfinite.h" +#include "coder_array.h" // Function Definitions namespace RAT @@ -20,7 +22,367 @@ namespace RAT { namespace internal { + boolean_T ab_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[5]{ 'b', 'o', 'u', 'n', 'd' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 5) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 5) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T b_strcmp(const char_T a_data[], const int32_T a_size[2], const + char_T b[6]) + { + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 6) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 6) { + if (a_data[kstr] != b[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + boolean_T b_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[7]{ 'd', 'o', 'm', 'a', 'i', 'n', 's' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 7) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 7) { + if (cv1[static_cast(a_data[kstr]) & 127] != cv1[ + static_cast(b_cv[kstr])]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T bb_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[4]{ 'f', 'o', 'l', 'd' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 4) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 4) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T c_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 9) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 9) { + if (a_data[kstr] != cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T c_strcmp(const char_T a_data[], const int32_T a_size[2], const + char_T b[4]) + { + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 4) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 4) { + if (a_data[kstr] != b[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T d_strcmp(const char_T a_data[], const int32_T a_size[2], const + char_T b[3]) + { + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 3) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 3) { + if (a_data[kstr] != b[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T d_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[3]{ 'o', 'f', 'f' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 3) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 3) { + if (cv1[static_cast(a_data[kstr]) & 127] != cv1[ + static_cast(b_cv[kstr])]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T e_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[7]{ 's', 'i', 'm', 'p', 'l', 'e', 'x' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 7) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 7) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T e_strcmp(const char_T a_data[], const int32_T a_size[2], const + char_T b[5]) + { + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 5) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 5) { + if (a_data[kstr] != b[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T f_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[2]{ 'd', 'e' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 2) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 2) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T g_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[2]{ 'n', 's' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 2) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 2) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T h_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[5]{ 'd', 'r', 'e', 'a', 'm' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 5) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 5) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T i_strcmp(const char_T a_data[], const int32_T a_size[2]) { static const char_T b_cv[13]{ 'n', 'o', 'n', ' ', 'p', 'o', 'l', 'a', 'r', 'i', 's', 'e', 'd' }; @@ -49,7 +411,35 @@ namespace RAT return b_bool; } - boolean_T c_strcmp(const char_T a_data[], const int32_T a_size[2]) + boolean_T j_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[7]{ 'd', 'o', 'm', 'a', 'i', 'n', 's' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 7) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 7) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T k_strcmp(const char_T a_data[], const int32_T a_size[2]) { static const char_T b_cv[15]{ 's', 't', 'a', 'n', 'd', 'a', 'r', 'd', ' ', 'l', 'a', 'y', 'e', 'r', 's' }; @@ -78,7 +468,7 @@ namespace RAT return b_bool; } - boolean_T d_strcmp(const char_T a_data[], const int32_T a_size[2]) + boolean_T l_strcmp(const char_T a_data[], const int32_T a_size[2]) { static const char_T b_cv[13]{ 'c', 'u', 's', 't', 'o', 'm', ' ', 'l', 'a', 'y', 'e', 'r', 's' }; @@ -107,7 +497,7 @@ namespace RAT return b_bool; } - boolean_T e_strcmp(const char_T a_data[], const int32_T a_size[2]) + boolean_T m_strcmp(const char_T a_data[], const int32_T a_size[2]) { static const char_T b_cv[9]{ 'c', 'u', 's', 't', 'o', 'm', ' ', 'x', 'y' }; @@ -136,7 +526,7 @@ namespace RAT return b_bool; } - boolean_T f_strcmp(const char_T a_data[], const int32_T a_size[2]) + boolean_T n_strcmp(const char_T a_data[], const int32_T a_size[2]) { static const char_T b_cv[6]{ 's', 'i', 'n', 'g', 'l', 'e' }; @@ -164,7 +554,7 @@ namespace RAT return b_bool; } - boolean_T g_strcmp(const char_T a_data[], const int32_T a_size[2]) + boolean_T o_strcmp(const char_T a_data[], const int32_T a_size[2]) { static const char_T b_cv[6]{ 'p', 'o', 'i', 'n', 't', 's' }; @@ -192,7 +582,7 @@ namespace RAT return b_bool; } - boolean_T h_strcmp(const char_T a_data[], const int32_T a_size[2]) + boolean_T p_strcmp(const char_T a_data[], const int32_T a_size[2]) { static const char_T b_cv[9]{ 'c', 'o', 'n', 't', 'r', 'a', 's', 't', 's' }; @@ -221,7 +611,7 @@ namespace RAT return b_bool; } - boolean_T i_strcmp(const char_T a_data[], const int32_T a_size[2]) + boolean_T q_strcmp(const char_T a_data[], const int32_T a_size[2]) { static const char_T b_cv[13]{ 'a', 'i', 'r', '/', 's', 'u', 'b', 's', 't', 'r', 'a', 't', 'e' }; @@ -235,7 +625,7 @@ namespace RAT do { exitg1 = 0; if (kstr < 13) { - if (cv[static_cast(a_data[kstr]) & 127] != cv[ + if (cv1[static_cast(a_data[kstr]) & 127] != cv1[ static_cast(b_cv[kstr])]) { exitg1 = 1; } else { @@ -251,9 +641,65 @@ namespace RAT return b_bool; } - boolean_T j_strcmp(const char_T a_data[], const int32_T a_size[2]) + boolean_T r_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[3]{ 'o', 'f', 'f' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 3) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 3) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T s_strcmp(const char_T a_data[], const int32_T a_size[2]) { - static const char_T b_cv[6]{ 'm', 'a', 't', 'l', 'a', 'b' }; + static const char_T b_cv[4]{ 'i', 't', 'e', 'r' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 4) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 4) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + boolean_T t_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[6]{ 'n', 'o', 't', 'i', 'f', 'y' }; boolean_T b_bool; b_bool = false; @@ -279,19 +725,19 @@ namespace RAT return b_bool; } - boolean_T k_strcmp(const char_T a_data[], const int32_T a_size[2]) + boolean_T u_strcmp(const char_T a_data[], const int32_T a_size[2]) { - static const char_T b_cv[3]{ 'c', 'p', 'p' }; + static const char_T b_cv[5]{ 'f', 'i', 'n', 'a', 'l' }; boolean_T b_bool; b_bool = false; - if (a_size[1] == 3) { + if (a_size[1] == 5) { int32_T kstr; kstr = 0; int32_T exitg1; do { exitg1 = 0; - if (kstr < 3) { + if (kstr < 5) { if (a_data[kstr] != b_cv[kstr]) { exitg1 = 1; } else { @@ -307,9 +753,9 @@ namespace RAT return b_bool; } - boolean_T l_strcmp(const char_T a_data[], const int32_T a_size[2]) + boolean_T v_strcmp(const char_T a_data[], const int32_T a_size[2]) { - static const char_T b_cv[6]{ 'p', 'y', 't', 'h', 'o', 'n' }; + static const char_T b_cv[6]{ 's', 'h', 'r', 'i', 'n', 'k' }; boolean_T b_bool; b_bool = false; @@ -334,6 +780,99 @@ namespace RAT return b_bool; } + + boolean_T w_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[4]{ 'i', 't', 'e', 'r' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 4) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 4) { + if (cv1[static_cast(a_data[kstr]) & 127] != cv1[ + static_cast(b_cv[kstr])]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } + + void x_strcmp(const cell_wrap_1 *a, const ::coder::array + &b, ::coder::array &b_bool) + { + int32_T nb; + b_bool.set_size(b.size(0)); + nb = b.size(0); + for (int32_T k{0}; k < nb; k++) { + int32_T i; + boolean_T b_b; + b_bool[k] = false; + i = b[k].f1.size(1); + b_b = (a->f1.size(1) == 0); + if (b_b && (i == 0)) { + b_bool[k] = true; + } else if (a->f1.size(1) == i) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr <= i - 1) { + if (cv1[static_cast(a->f1[kstr]) & 127] != cv1[ + static_cast(b[k].f1[kstr]) & 127]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool[k] = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + } + } + + boolean_T y_strcmp(const char_T a_data[], const int32_T a_size[2]) + { + static const char_T b_cv[7]{ 'r', 'e', 'f', 'l', 'e', 'c', 't' }; + + boolean_T b_bool; + b_bool = false; + if (a_size[1] == 7) { + int32_T kstr; + kstr = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (kstr < 7) { + if (a_data[kstr] != b_cv[kstr]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } + + return b_bool; + } } } } diff --git a/RAT/strcmp.h b/RAT/strcmp.h index 24cf38a0..78d6f01a 100644 --- a/RAT/strcmp.h +++ b/RAT/strcmp.h @@ -11,7 +11,9 @@ #define STRCMP_H // Include files +#include "RATMain_types.h" #include "rtwtypes.h" +#include "coder_array.h" #include #include @@ -22,10 +24,20 @@ namespace RAT { namespace internal { + boolean_T ab_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T b_strcmp(const char_T a_data[], const int32_T a_size[2], const + char_T b[6]); boolean_T b_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T bb_strcmp(const char_T a_data[], const int32_T a_size[2]); boolean_T c_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T c_strcmp(const char_T a_data[], const int32_T a_size[2], const + char_T b[4]); + boolean_T d_strcmp(const char_T a_data[], const int32_T a_size[2], const + char_T b[3]); boolean_T d_strcmp(const char_T a_data[], const int32_T a_size[2]); boolean_T e_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T e_strcmp(const char_T a_data[], const int32_T a_size[2], const + char_T b[5]); boolean_T f_strcmp(const char_T a_data[], const int32_T a_size[2]); boolean_T g_strcmp(const char_T a_data[], const int32_T a_size[2]); boolean_T h_strcmp(const char_T a_data[], const int32_T a_size[2]); @@ -33,6 +45,20 @@ namespace RAT boolean_T j_strcmp(const char_T a_data[], const int32_T a_size[2]); boolean_T k_strcmp(const char_T a_data[], const int32_T a_size[2]); boolean_T l_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T m_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T n_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T o_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T p_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T q_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T r_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T s_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T t_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T u_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T v_strcmp(const char_T a_data[], const int32_T a_size[2]); + boolean_T w_strcmp(const char_T a_data[], const int32_T a_size[2]); + void x_strcmp(const cell_wrap_1 *a, const ::coder::array + &b, ::coder::array &b_bool); + boolean_T y_strcmp(const char_T a_data[], const int32_T a_size[2]); } } } diff --git a/RAT/structConstructorHelper.cpp b/RAT/structConstructorHelper.cpp new file mode 100644 index 00000000..d8e47d13 --- /dev/null +++ b/RAT/structConstructorHelper.cpp @@ -0,0 +1,105 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// structConstructorHelper.cpp +// +// Code generation for function 'structConstructorHelper' +// + +// Include files +#include "structConstructorHelper.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + void structConstructorHelper(const cell_wrap_15 *varargin_2, const + cell_wrap_9 *varargin_4, const cell_wrap_15 *varargin_8, ::coder::array< + cell_wrap_8, 1U> &s_ref, ::coder::array &s_sld, real_T * + s_chi, ::coder::array &s_data) + { + int32_T loop_ub; + s_ref.set_size(varargin_2->f1.size(0)); + loop_ub = varargin_2->f1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + s_ref[i] = varargin_2->f1[i]; + } + + s_sld.set_size(varargin_4->f1.size(0), varargin_4->f1.size(1)); + loop_ub = varargin_4->f1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + int32_T b_loop_ub; + b_loop_ub = varargin_4->f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + s_sld[i1 + s_sld.size(0) * i] = varargin_4->f1[i1 + + varargin_4->f1.size(0) * i]; + } + } + + s_data.set_size(varargin_8->f1.size(0)); + loop_ub = varargin_8->f1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + s_data[i] = varargin_8->f1[i]; + } + + *s_chi = 0.0; + } + + void structConstructorHelper(const cell_wrap_15 *varargin_2, const + cell_wrap_15 *varargin_4, const cell_wrap_15 *varargin_6, const + cell_wrap_9 *varargin_8, const cell_wrap_17 *varargin_10, ::coder::array< + cell_wrap_8, 1U> &s_refPredInts, ::coder::array + &s_sldPredInts, ::coder::array &s_refXdata, ::coder:: + array &s_sldXdata, real_T s_sampleChi_data[], int32_T + *s_sampleChi_size) + { + int32_T loop_ub; + s_refPredInts.set_size(varargin_2->f1.size(0)); + loop_ub = varargin_2->f1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + s_refPredInts[i] = varargin_2->f1[i]; + } + + s_sldPredInts.set_size(varargin_4->f1.size(0)); + loop_ub = varargin_4->f1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + s_sldPredInts[i] = varargin_4->f1[i]; + } + + s_refXdata.set_size(varargin_6->f1.size(0)); + loop_ub = varargin_6->f1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + s_refXdata[i] = varargin_6->f1[i]; + } + + s_sldXdata.set_size(varargin_8->f1.size(0), varargin_8->f1.size(1)); + loop_ub = varargin_8->f1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + int32_T b_loop_ub; + b_loop_ub = varargin_8->f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + s_sldXdata[i1 + s_sldXdata.size(0) * i] = varargin_8->f1[i1 + + varargin_8->f1.size(0) * i]; + } + } + + *s_sampleChi_size = varargin_10->f1.size(0); + loop_ub = varargin_10->f1.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + s_sampleChi_data[i] = varargin_10->f1[i]; + } + } + } + } +} + +// End of code generation (structConstructorHelper.cpp) diff --git a/RAT/structConstructorHelper.h b/RAT/structConstructorHelper.h new file mode 100644 index 00000000..ef392cce --- /dev/null +++ b/RAT/structConstructorHelper.h @@ -0,0 +1,51 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// structConstructorHelper.h +// +// Code generation for function 'structConstructorHelper' +// +#ifndef STRUCTCONSTRUCTORHELPER_H +#define STRUCTCONSTRUCTORHELPER_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct cell_wrap_15; + struct cell_wrap_17; +} + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void structConstructorHelper(const cell_wrap_15 *varargin_2, const + cell_wrap_9 *varargin_4, const cell_wrap_15 *varargin_8, ::coder::array< + cell_wrap_8, 1U> &s_ref, ::coder::array &s_sld, real_T * + s_chi, ::coder::array &s_data); + void structConstructorHelper(const cell_wrap_15 *varargin_2, const + cell_wrap_15 *varargin_4, const cell_wrap_15 *varargin_6, const + cell_wrap_9 *varargin_8, const cell_wrap_17 *varargin_10, ::coder::array< + cell_wrap_8, 1U> &s_refPredInts, ::coder::array + &s_sldPredInts, ::coder::array &s_refXdata, ::coder:: + array &s_sldXdata, real_T s_sampleChi_data[], int32_T + *s_sampleChi_size); + } + } +} + +#endif + +// End of code generation (structConstructorHelper.h) diff --git a/RAT/sum.cpp b/RAT/sum.cpp index 677accac..a3ae1a5e 100644 --- a/RAT/sum.cpp +++ b/RAT/sum.cpp @@ -19,6 +19,45 @@ namespace RAT { namespace coder { + void sum(const ::coder::array &x, ::coder::array &y) + { + if ((x.size(0) == 0) || (x.size(1) == 0)) { + int32_T loop_ub; + y.set_size(1, x.size(1)); + loop_ub = x.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + y[i] = 0.0; + } + } else { + nestedIter(x, x.size(0), y); + } + } + + creal_T sum(const ::coder::array &x) + { + creal_T y; + if (x.size(1) == 0) { + y.re = 0.0; + y.im = 0.0; + } else { + y = nestedIter(x, x.size(1)); + } + + return y; + } + + real_T sum(const ::coder::array &x) + { + real_T y; + if (x.size(1) == 0) { + y = 0.0; + } else { + y = nestedIter(x, x.size(1)); + } + + return y; + } + real_T sum(const ::coder::array &x) { real_T y; diff --git a/RAT/sum.h b/RAT/sum.h index 68b8481d..b8a0e338 100644 --- a/RAT/sum.h +++ b/RAT/sum.h @@ -21,6 +21,9 @@ namespace RAT { namespace coder { + void sum(const ::coder::array &x, ::coder::array &y); + creal_T sum(const ::coder::array &x); + real_T sum(const ::coder::array &x); real_T sum(const ::coder::array &x); } } diff --git a/RAT/textProgressBar.cpp b/RAT/textProgressBar.cpp new file mode 100644 index 00000000..d844c995 --- /dev/null +++ b/RAT/textProgressBar.cpp @@ -0,0 +1,89 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// textProgressBar.cpp +// +// Code generation for function 'textProgressBar' +// + +// Include files +#include "textProgressBar.h" +#include "RATMain_data.h" +#include "repmat.h" +#include "rt_nonfinite.h" +#include "sprintf.h" +#include "coder_array.h" +#include +#include + +// Function Definitions +namespace RAT +{ + void lastNchar_not_empty_init() + { + lastNchar_not_empty = false; + } + + void textProgressBar(real_T pct) + { + ::coder::array progressmsg; + ::coder::array varargin_1; + ::coder::array varargin_2; + real_T nDots; + int32_T loop_ub; + if (!lastNchar_not_empty) { + lastNchar = 0.0; + lastNchar_not_empty = true; + } + + // curm = 'progress'; + nDots = std::floor(pct * 40.0); + coder::repmat(nDots, varargin_1); + coder::b_repmat(40.0 - nDots, varargin_2); + progressmsg.set_size(1, (varargin_1.size(1) + varargin_2.size(1)) + 2); + progressmsg[0] = '['; + loop_ub = varargin_1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + progressmsg[i + 1] = varargin_1[i]; + } + + loop_ub = varargin_2.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + progressmsg[(i + varargin_1.size(1)) + 1] = varargin_2[i]; + } + + progressmsg[(varargin_1.size(1) + varargin_2.size(1)) + 1] = ']'; + + // progressmsg=[183-uint16((1:40)<=(pct*40)).*(183-'*') '']; + // %curmtxt=sprintf('% 9.3g\n',curm(1:min(end,20),1)); + varargin_1.set_size(1, progressmsg.size(1) + 1); + loop_ub = progressmsg.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + varargin_1[i] = progressmsg[i]; + } + + varargin_1[progressmsg.size(1)] = '\x00'; + coder::snPrint(pct * 100.0, varargin_1, progressmsg); + varargin_1.set_size(1, static_cast(lastNchar) + 1); + loop_ub = static_cast(lastNchar); + for (int32_T i{0}; i < loop_ub; i++) { + varargin_1[i] = '\x08'; + } + + varargin_1[static_cast(lastNchar)] = '\x00'; + varargin_2.set_size(1, progressmsg.size(1) + 1); + loop_ub = progressmsg.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + varargin_2[i] = progressmsg[i]; + } + + varargin_2[progressmsg.size(1)] = '\x00'; + printf("%s%s", &varargin_1[0], &varargin_2[0]); + fflush(stdout); + lastNchar = progressmsg.size(1); + } +} + +// End of code generation (textProgressBar.cpp) diff --git a/RAT/textProgressBar.h b/RAT/textProgressBar.h new file mode 100644 index 00000000..9ac452e2 --- /dev/null +++ b/RAT/textProgressBar.h @@ -0,0 +1,27 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// textProgressBar.h +// +// Code generation for function 'textProgressBar' +// +#ifndef TEXTPROGRESSBAR_H +#define TEXTPROGRESSBAR_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + void lastNchar_not_empty_init(); + void textProgressBar(real_T pct); +} + +#endif + +// End of code generation (textProgressBar.h) diff --git a/RAT/tic.cpp b/RAT/tic.cpp new file mode 100644 index 00000000..4c0c2cb5 --- /dev/null +++ b/RAT/tic.cpp @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// tic.cpp +// +// Code generation for function 'tic' +// + +// Include files +#include "tic.h" +#include "RATMain_data.h" +#include "rt_nonfinite.h" +#include "timeKeeper.h" +#include "coder_posix_time.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void tic() + { + coderTimespec b_timespec; + if (!freq_not_empty) { + freq_not_empty = true; + coderInitTimeFunctions(&freq); + } + + coderTimeClockGettimeMonotonic(&b_timespec, freq); + internal::time::impl::timeKeeper(b_timespec.tv_sec, b_timespec.tv_nsec); + } + } +} + +// End of code generation (tic.cpp) diff --git a/RAT/tic.h b/RAT/tic.h new file mode 100644 index 00000000..0189e9df --- /dev/null +++ b/RAT/tic.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// tic.h +// +// Code generation for function 'tic' +// +#ifndef TIC_H +#define TIC_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void tic(); + } +} + +#endif + +// End of code generation (tic.h) diff --git a/RAT/timeKeeper.cpp b/RAT/timeKeeper.cpp new file mode 100644 index 00000000..5af83d98 --- /dev/null +++ b/RAT/timeKeeper.cpp @@ -0,0 +1,62 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// timeKeeper.cpp +// +// Code generation for function 'timeKeeper' +// + +// Include files +#include "timeKeeper.h" +#include "getTime.h" +#include "rt_nonfinite.h" +#include "coder_posix_time.h" + +// Variable Definitions +namespace RAT +{ + static coderTimespec savedTime; + static boolean_T savedTime_not_empty; +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace time + { + namespace impl + { + void timeKeeper(real_T newTime_tv_sec, real_T newTime_tv_nsec) + { + if (!savedTime_not_empty) { + getTime(&savedTime.tv_sec, &savedTime.tv_nsec); + savedTime_not_empty = true; + } + + savedTime.tv_sec = newTime_tv_sec; + savedTime.tv_nsec = newTime_tv_nsec; + } + + void timeKeeper(real_T *outTime_tv_sec, real_T *outTime_tv_nsec) + { + *outTime_tv_sec = savedTime.tv_sec; + *outTime_tv_nsec = savedTime.tv_nsec; + } + } + } + } + } + + void savedTime_not_empty_init() + { + savedTime_not_empty = false; + } +} + +// End of code generation (timeKeeper.cpp) diff --git a/RAT/timeKeeper.h b/RAT/timeKeeper.h new file mode 100644 index 00000000..eb06a9de --- /dev/null +++ b/RAT/timeKeeper.h @@ -0,0 +1,41 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// timeKeeper.h +// +// Code generation for function 'timeKeeper' +// +#ifndef TIMEKEEPER_H +#define TIMEKEEPER_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace time + { + namespace impl + { + void timeKeeper(real_T newTime_tv_sec, real_T newTime_tv_nsec); + void timeKeeper(real_T *outTime_tv_sec, real_T *outTime_tv_nsec); + } + } + } + } + + void savedTime_not_empty_init(); +} + +#endif + +// End of code generation (timeKeeper.h) diff --git a/RAT/toc.cpp b/RAT/toc.cpp new file mode 100644 index 00000000..fd472805 --- /dev/null +++ b/RAT/toc.cpp @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// toc.cpp +// +// Code generation for function 'toc' +// + +// Include files +#include "toc.h" +#include "getTime.h" +#include "rt_nonfinite.h" +#include "timeKeeper.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + real_T toc() + { + real_T tnow_tv_nsec; + real_T tnow_tv_sec; + real_T tstart_tv_nsec; + real_T tstart_tv_sec; + internal::time::impl::timeKeeper(&tstart_tv_sec, &tstart_tv_nsec); + internal::time::getTime(&tnow_tv_sec, &tnow_tv_nsec); + return (tnow_tv_sec - tstart_tv_sec) + (tnow_tv_nsec - tstart_tv_nsec) / + 1.0E+9; + } + } +} + +// End of code generation (toc.cpp) diff --git a/RAT/toc.h b/RAT/toc.h new file mode 100644 index 00000000..3eef1cb6 --- /dev/null +++ b/RAT/toc.h @@ -0,0 +1,29 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// toc.h +// +// Code generation for function 'toc' +// +#ifndef TOC_H +#define TOC_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + real_T toc(); + } +} + +#endif + +// End of code generation (toc.h) diff --git a/RAT/triggerEvent.cpp b/RAT/triggerEvent.cpp index f4e17660..debbb97e 100644 --- a/RAT/triggerEvent.cpp +++ b/RAT/triggerEvent.cpp @@ -10,9 +10,10 @@ // Include files #include "triggerEvent.h" +#include "RATMain_types.h" #include "getenv.h" -#include "reflectivityCalculation_types.h" #include "rt_nonfinite.h" +#include "strcmp.h" #include "coder_array.h" #include "eventHelper.hpp" #include @@ -28,16 +29,177 @@ namespace RAT // Function Declarations namespace RAT { - static void packCellArray(const ::coder::array &cellArray, :: + static void b_packCellArray(const ::coder::array &cellArray, :: coder::array &packedArray, ::coder::array &counts); - static void packCellArray(const ::coder::array &cellArray, :: + static void c_packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts); + static void d_packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts); + static void packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts); + static void packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts); + static void packCellArray(const ::coder::array &cellArray, :: coder::array &packedArray, ::coder::array &counts); } // Function Definitions namespace RAT { - static void packCellArray(const ::coder::array &cellArray, :: + static void b_packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts) + { + real_T rowSize; + real_T start; + int32_T b_rowSize; + int32_T i; + + // Packs a specified column of a cell array with different sized arrays into a + // single row array and an array of counts for each cell. For the example below + // reflect will be [1, 2, 3, 4, 5, 6, 7] and nReflect will be [3, 4] + // + // [reflect, nReflect] = packCellArray({[1; 2; 3], [4; 5; 6; 7]}, 1); + rowSize = 0.0; + counts.set_size(cellArray.size(0)); + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T d; + d = static_cast(cellArray[b_i].f1.size(0)) * 3.0; + counts[b_i] = d; + rowSize += d; + } + + b_rowSize = static_cast(rowSize); + packedArray.set_size(b_rowSize); + for (i = 0; i < b_rowSize; i++) { + packedArray[i] = 0.0; + } + + start = 1.0; + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T stop; + int32_T i1; + stop = start + counts[b_i]; + if (start > stop - 1.0) { + i1 = 1; + } else { + i1 = static_cast(start); + } + + b_rowSize = cellArray[b_i].f1.size(0) * 3; + for (int32_T i2{0}; i2 < b_rowSize; i2++) { + packedArray[(i1 + i2) - 1] = cellArray[b_i].f1[i2]; + } + + start = stop; + } + } + + static void c_packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts) + { + real_T rowSize; + real_T start; + int32_T b_rowSize; + int32_T i; + + // Packs a specified column of a cell array with different sized arrays into a + // single row array and an array of counts for each cell. For the example below + // reflect will be [1, 2, 3, 4, 5, 6, 7] and nReflect will be [3, 4] + // + // [reflect, nReflect] = packCellArray({[1; 2; 3], [4; 5; 6; 7]}, 1); + rowSize = 0.0; + counts.set_size(cellArray.size(0)); + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T d; + d = static_cast(cellArray[b_i + cellArray.size(0)].f1.size(0)) * + static_cast(cellArray[b_i + cellArray.size(0)].f1.size(1)); + counts[b_i] = d; + rowSize += d; + } + + b_rowSize = static_cast(rowSize); + packedArray.set_size(b_rowSize); + for (i = 0; i < b_rowSize; i++) { + packedArray[i] = 0.0; + } + + start = 1.0; + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T stop; + int32_T i1; + stop = start + counts[b_i]; + if (start > stop - 1.0) { + i1 = 1; + } else { + i1 = static_cast(start); + } + + b_rowSize = cellArray[b_i + cellArray.size(0)].f1.size(0) * cellArray[b_i + + cellArray.size(0)].f1.size(1); + for (int32_T i2{0}; i2 < b_rowSize; i2++) { + packedArray[(i1 + i2) - 1] = cellArray[b_i + cellArray.size(0)].f1[i2]; + } + + start = stop; + } + } + + static void d_packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts) + { + real_T rowSize; + real_T start; + int32_T b_rowSize; + int32_T i; + + // Packs a specified column of a cell array with different sized arrays into a + // single row array and an array of counts for each cell. For the example below + // reflect will be [1, 2, 3, 4, 5, 6, 7] and nReflect will be [3, 4] + // + // [reflect, nReflect] = packCellArray({[1; 2; 3], [4; 5; 6; 7]}, 1); + rowSize = 0.0; + counts.set_size(cellArray.size(0)); + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T d; + d = static_cast(cellArray[b_i + cellArray.size(0)].f1.size(0)) * + 3.0; + counts[b_i] = d; + rowSize += d; + } + + b_rowSize = static_cast(rowSize); + packedArray.set_size(b_rowSize); + for (i = 0; i < b_rowSize; i++) { + packedArray[i] = 0.0; + } + + start = 1.0; + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T stop; + int32_T i1; + stop = start + counts[b_i]; + if (start > stop - 1.0) { + i1 = 1; + } else { + i1 = static_cast(start); + } + + b_rowSize = cellArray[b_i + cellArray.size(0)].f1.size(0) * 3; + for (int32_T i2{0}; i2 < b_rowSize; i2++) { + packedArray[(i1 + i2) - 1] = cellArray[b_i + cellArray.size(0)].f1[i2]; + } + + start = stop; + } + } + + static void packCellArray(const ::coder::array &cellArray, :: coder::array &packedArray, ::coder::array &counts) { real_T rowSize; @@ -45,11 +207,11 @@ namespace RAT int32_T b_rowSize; int32_T i; - // Packs a cell array with different sized arrays into a single row - // array and an array of counts for each cell. For the example below + // Packs a specified column of a cell array with different sized arrays into a + // single row array and an array of counts for each cell. For the example below // reflect will be [1, 2, 3, 4, 5, 6, 7] and nReflect will be [3, 4] // - // [reflect, nReflect] = packCellArray({[1, 2, 3], [4, 5, 6, 7]}); + // [reflect, nReflect] = packCellArray({[1; 2; 3], [4; 5; 6; 7]}, 1); rowSize = 0.0; counts.set_size(cellArray.size(0)); i = cellArray.size(0); @@ -87,7 +249,7 @@ namespace RAT } } - static void packCellArray(const ::coder::array &cellArray, :: + static void packCellArray(const ::coder::array &cellArray, :: coder::array &packedArray, ::coder::array &counts) { real_T rowSize; @@ -95,11 +257,11 @@ namespace RAT int32_T b_rowSize; int32_T i; - // Packs a cell array with different sized arrays into a single row - // array and an array of counts for each cell. For the example below + // Packs a specified column of a cell array with different sized arrays into a + // single row array and an array of counts for each cell. For the example below // reflect will be [1, 2, 3, 4, 5, 6, 7] and nReflect will be [3, 4] // - // [reflect, nReflect] = packCellArray({[1, 2, 3], [4, 5, 6, 7]}); + // [reflect, nReflect] = packCellArray({[1; 2; 3], [4; 5; 6; 7]}, 1); rowSize = 0.0; counts.set_size(cellArray.size(0)); i = cellArray.size(0); @@ -137,34 +299,93 @@ namespace RAT } } + static void packCellArray(const ::coder::array &cellArray, :: + coder::array &packedArray, ::coder::array &counts) + { + real_T rowSize; + real_T start; + int32_T b_rowSize; + int32_T i; + + // Packs a specified column of a cell array with different sized arrays into a + // single row array and an array of counts for each cell. For the example below + // reflect will be [1, 2, 3, 4, 5, 6, 7] and nReflect will be [3, 4] + // + // [reflect, nReflect] = packCellArray({[1; 2; 3], [4; 5; 6; 7]}, 1); + rowSize = 0.0; + counts.set_size(cellArray.size(0)); + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T d; + d = static_cast(cellArray[b_i].f1.size(0)) * static_cast + (cellArray[b_i].f1.size(1)); + counts[b_i] = d; + rowSize += d; + } + + b_rowSize = static_cast(rowSize); + packedArray.set_size(b_rowSize); + for (i = 0; i < b_rowSize; i++) { + packedArray[i] = 0.0; + } + + start = 1.0; + i = cellArray.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T stop; + int32_T i1; + stop = start + counts[b_i]; + if (start > stop - 1.0) { + i1 = 1; + } else { + i1 = static_cast(start); + } + + b_rowSize = cellArray[b_i].f1.size(0) * cellArray[b_i].f1.size(1); + for (int32_T i2{0}; i2 < b_rowSize; i2++) { + packedArray[(i1 + i2) - 1] = cellArray[b_i].f1[i2]; + } + + start = stop; + } + } + void helper_not_empty_init() { helper_not_empty = false; } - void triggerEvent(const ::coder::array &data_f1_f1, const :: - coder::array &data_f1_f3, const ::coder:: - array &data_f1_f5, const ::coder::array< - cell_wrap_13, 1U> &data_f1_f6, const ::coder::array &data_f2, const ::coder::array + void triggerEvent(const ::coder::array &data_f1_f1, const :: + coder::array &data_f1_f3, const ::coder:: + array &data_f1_f5, const ::coder::array< + cell_wrap_8, 2U> &data_f1_f6, const ::coder::array &data_f2, const char_T data_f3_TF_data[], const int32_T + data_f3_TF_size[2], const ::coder::array &data_f3_resample, const ::coder::array &data_f3_dataPresent, const char_T data_f3_modelType_data[], const int32_T data_f3_modelType_size[2]) { static eventHelper helper; + ::coder::array b_nSldProfiles2; ::coder::array dataPresent; + ::coder::array layers2; + ::coder::array nLayers2; ::coder::array resample; + ::coder::array sldProfiles2; + ::coder::array b_sldProfiles2; ::coder::array layers; ::coder::array nLayers; ::coder::array nReflect; ::coder::array nShiftedData; ::coder::array nSldProfiles; + ::coder::array nSldProfiles2; ::coder::array reflect; ::coder::array shiftedData; ::coder::array sldProfiles; ::coder::array ssubs; ::coder::array path; ::coder::array r; + int32_T i; int32_T loop_ub; char_T modelType_data[10001]; boolean_T initialised; @@ -184,7 +405,7 @@ namespace RAT coder::b_getenv(r); path.set_size(1, r.size(1) + 1); loop_ub = r.size(1); - for (int32_T i{0}; i < loop_ub; i++) { + for (i = 0; i < loop_ub; i++) { path[i] = r[i]; } @@ -194,51 +415,94 @@ namespace RAT initialised = std::mem_fn(&eventHelper::isInitialised)(helper); if (initialised) { - packCellArray(data_f1_f1, reflect, nReflect); - - // reflectivity - packCellArray(data_f1_f3, shiftedData, nShiftedData); - packCellArray(data_f1_f5, sldProfiles, nSldProfiles); - packCellArray(data_f1_f6, layers, nLayers); - - // All Layers - ssubs.set_size(data_f2.size(0)); - loop_ub = data_f2.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - ssubs[i] = data_f2[i]; - } + boolean_T hasPlotHandler; + hasPlotHandler = std::mem_fn(&eventHelper::hasPlotHandler)(helper); + if (hasPlotHandler) { + packCellArray(data_f1_f1, reflect, nReflect); - // ssubs - loop_ub = data_f3_modelType_size[1]; - if (loop_ub - 1 >= 0) { - std::copy(&data_f3_modelType_data[0], &data_f3_modelType_data[loop_ub], - &modelType_data[0]); - } + // reflectivity + packCellArray(data_f1_f3, shiftedData, nShiftedData); + packCellArray(data_f1_f5, sldProfiles, nSldProfiles); + b_packCellArray(data_f1_f6, layers, nLayers); + if (coder::internal::j_strcmp(data_f3_TF_data, data_f3_TF_size)) { + i = 0; + } else { + i = -1; + } - modelType_data[data_f3_modelType_size[1]] = '\x00'; - resample.set_size(1, data_f3_resample.size(1)); - loop_ub = data_f3_resample.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - resample[i] = data_f3_resample[i]; - } + if (i == 0) { + c_packCellArray(data_f1_f5, b_sldProfiles2, nSldProfiles2); + loop_ub = b_sldProfiles2.size(0); + sldProfiles2.set_size(b_sldProfiles2.size(0), 1); + for (i = 0; i < loop_ub; i++) { + sldProfiles2[i] = b_sldProfiles2[i]; + } - dataPresent.set_size(1, data_f3_dataPresent.size(1)); - loop_ub = data_f3_dataPresent.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - dataPresent[i] = data_f3_dataPresent[i]; - } + loop_ub = nSldProfiles2.size(0); + b_nSldProfiles2.set_size(nSldProfiles2.size(0), 1); + for (i = 0; i < loop_ub; i++) { + b_nSldProfiles2[i] = nSldProfiles2[i]; + } + + d_packCellArray(data_f1_f6, b_sldProfiles2, nSldProfiles2); + loop_ub = b_sldProfiles2.size(0); + layers2.set_size(b_sldProfiles2.size(0), 1); + for (i = 0; i < loop_ub; i++) { + layers2[i] = b_sldProfiles2[i]; + } - std::mem_fn(&eventHelper::updatePlot)(helper, static_cast - (data_f1_f1.size(0)), &(reflect.data())[0], &(nReflect.data())[0], - &(shiftedData.data())[0], &(nShiftedData.data())[0], &(sldProfiles.data()) - [0], &(nSldProfiles.data())[0], &(layers.data())[0], &(nLayers.data())[0], - &(ssubs.data())[0], &resample[0], &dataPresent[0], &modelType_data[0]); - notified = false; + loop_ub = nSldProfiles2.size(0); + nLayers2.set_size(nSldProfiles2.size(0), 1); + for (i = 0; i < loop_ub; i++) { + nLayers2[i] = nSldProfiles2[i]; + } + } else { + sldProfiles2.set_size(0, 0); + b_nSldProfiles2.set_size(0, 0); + layers2.set_size(0, 0); + nLayers2.set_size(0, 0); + } + + ssubs.set_size(data_f2.size(0)); + loop_ub = data_f2.size(0); + for (i = 0; i < loop_ub; i++) { + ssubs[i] = data_f2[i]; + } + + // ssubs + loop_ub = data_f3_modelType_size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&data_f3_modelType_data[0], &data_f3_modelType_data[loop_ub], + &modelType_data[0]); + } + + modelType_data[data_f3_modelType_size[1]] = '\x00'; + resample.set_size(1, data_f3_resample.size(1)); + loop_ub = data_f3_resample.size(1); + for (i = 0; i < loop_ub; i++) { + resample[i] = data_f3_resample[i]; + } + + dataPresent.set_size(1, data_f3_dataPresent.size(1)); + loop_ub = data_f3_dataPresent.size(1); + for (i = 0; i < loop_ub; i++) { + dataPresent[i] = data_f3_dataPresent[i]; + } + + std::mem_fn(&eventHelper::updatePlot)(helper, static_cast + (data_f1_f1.size(0)), &(reflect.data())[0], &(nReflect.data())[0], + &(shiftedData.data())[0], &(nShiftedData.data())[0], + &(sldProfiles.data())[0], &(nSldProfiles.data())[0], &(layers.data()) + [0], &(nLayers.data())[0], &sldProfiles2[0], &b_nSldProfiles2[0], + &layers2[0], &nLayers2[0], &(ssubs.data())[0], &resample[0], + &dataPresent[0], &modelType_data[0]); + notified = false; + } // This avoids printing the error message multiple times during the optimization. } else if (!notified) { fprintf(stderr, - "\neventManager library coult be loaded. Check that the dynamic library is present in the compile/events folder.\n"); + "\neventManager library could be loaded. Check that the dynamic library is present in the compile/events folder.\n"); fflush(stderr); notified = true; } diff --git a/RAT/triggerEvent.h b/RAT/triggerEvent.h index 65df73ea..5734cc57 100644 --- a/RAT/triggerEvent.h +++ b/RAT/triggerEvent.h @@ -11,7 +11,7 @@ #define TRIGGEREVENT_H // Include files -#include "reflectivityCalculation_types.h" +#include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include @@ -21,11 +21,12 @@ namespace RAT { void helper_not_empty_init(); - void triggerEvent(const ::coder::array &data_f1_f1, const :: - coder::array &data_f1_f3, const ::coder:: - array &data_f1_f5, const ::coder::array< - cell_wrap_13, 1U> &data_f1_f6, const ::coder::array &data_f2, const ::coder::array + void triggerEvent(const ::coder::array &data_f1_f1, const :: + coder::array &data_f1_f3, const ::coder:: + array &data_f1_f5, const ::coder::array< + cell_wrap_8, 2U> &data_f1_f6, const ::coder::array &data_f2, const char_T data_f3_TF_data[], const int32_T + data_f3_TF_size[2], const ::coder::array &data_f3_resample, const ::coder::array &data_f3_dataPresent, const char_T data_f3_modelType_data[], const int32_T data_f3_modelType_size[2]); diff --git a/RAT/triu.cpp b/RAT/triu.cpp new file mode 100644 index 00000000..67b01f06 --- /dev/null +++ b/RAT/triu.cpp @@ -0,0 +1,71 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// triu.cpp +// +// Code generation for function 'triu' +// + +// Include files +#include "triu.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void b_triu(::coder::array &x) + { + int32_T m; + m = x.size(0); + if ((x.size(0) != 0) && (x.size(1) != 0) && (x.size(0) > 3)) { + int32_T istart; + int32_T jend; + istart = 4; + if (x.size(0) - 4 < x.size(1) - 1) { + jend = x.size(0) - 3; + } else { + jend = x.size(1); + } + + for (int32_T j{0}; j < jend; j++) { + for (int32_T i{istart}; i <= m; i++) { + x[(i + x.size(0) * j) - 1] = 0.0; + } + + istart++; + } + } + } + + void triu(::coder::array &x) + { + int32_T m; + m = x.size(0); + if ((x.size(0) != 0) && (x.size(1) != 0) && (x.size(0) > 1)) { + int32_T istart; + int32_T jend; + istart = 2; + if (x.size(0) - 2 < x.size(1) - 1) { + jend = x.size(0) - 1; + } else { + jend = x.size(1); + } + + for (int32_T j{0}; j < jend; j++) { + for (int32_T i{istart}; i <= m; i++) { + x[(i + x.size(0) * j) - 1] = 0.0; + } + + istart++; + } + } + } + } +} + +// End of code generation (triu.cpp) diff --git a/RAT/triu.h b/RAT/triu.h new file mode 100644 index 00000000..64348754 --- /dev/null +++ b/RAT/triu.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// triu.h +// +// Code generation for function 'triu' +// +#ifndef TRIU_H +#define TRIU_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void b_triu(::coder::array &x); + void triu(::coder::array &x); + } +} + +#endif + +// End of code generation (triu.h) diff --git a/RAT/unpackParams.cpp b/RAT/unpackParams.cpp new file mode 100644 index 00000000..d8fef2e1 --- /dev/null +++ b/RAT/unpackParams.cpp @@ -0,0 +1,276 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// unpackParams.cpp +// +// Code generation for function 'unpackParams' +// + +// Include files +#include "unpackParams.h" +#include "RATMain_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void unpackParams(struct5_T *problemDef, const ::coder::array + &controls_checks_fitParam, const ::coder::array + &controls_checks_fitBackgroundParam, const ::coder::array< + real_T, 2U> &controls_checks_fitQzshift, const ::coder:: + array &controls_checks_fitScalefactor, const :: + coder::array &controls_checks_fitBulkIn, const :: + coder::array &controls_checks_fitBulkOut, const :: + coder::array &controls_checks_fitResolutionParam, + const ::coder::array + &controls_checks_fitDomainRatio) + { + ::coder::array uppars; + int32_T i; + int32_T unnamed_idx_1; + int32_T uppars_counter; + uint32_T packed_counter; + uint32_T unpacked_counter; + + // Unpack the params out of the fitParams and otherParams arrays + // back into problem.params + // problem = getappdata(0,'problem'); + unpacked_counter = 1U; + packed_counter = 1U; + uppars_counter = 0; + unnamed_idx_1 = problemDef->params.size(1); + uppars.set_size(1, unnamed_idx_1); + for (i = 0; i < unnamed_idx_1; i++) { + uppars[i] = 0.0; + } + + i = controls_checks_fitParam.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + if (controls_checks_fitParam[b_i] == 1.0) { + uppars[uppars_counter] = problemDef->fitParams[static_cast + (unpacked_counter) - 1]; + unpacked_counter++; + uppars_counter++; + } else { + uppars[uppars_counter] = problemDef->otherParams[static_cast + (packed_counter) - 1]; + packed_counter++; + uppars_counter++; + } + } + + problemDef->params.set_size(1, uppars.size(1)); + unnamed_idx_1 = uppars.size(1); + for (i = 0; i < unnamed_idx_1; i++) { + problemDef->params[i] = uppars[i]; + } + + // Also the backgrounds + unnamed_idx_1 = problemDef->backgroundParams.size(1); + uppars.set_size(1, unnamed_idx_1); + for (i = 0; i < unnamed_idx_1; i++) { + uppars[i] = 0.0; + } + + uppars_counter = 0; + i = controls_checks_fitBackgroundParam.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + if (controls_checks_fitBackgroundParam[b_i] == 1.0) { + uppars[uppars_counter] = problemDef->fitParams[static_cast + (unpacked_counter) - 1]; + unpacked_counter++; + uppars_counter++; + } else { + uppars[uppars_counter] = problemDef->otherParams[static_cast + (packed_counter) - 1]; + packed_counter++; + uppars_counter++; + } + } + + problemDef->backgroundParams.set_size(1, uppars.size(1)); + unnamed_idx_1 = uppars.size(1); + for (i = 0; i < unnamed_idx_1; i++) { + problemDef->backgroundParams[i] = uppars[i]; + } + + // Scalefactors + unnamed_idx_1 = problemDef->scalefactors.size(1); + uppars.set_size(1, unnamed_idx_1); + for (i = 0; i < unnamed_idx_1; i++) { + uppars[i] = 0.0; + } + + uppars_counter = 0; + i = controls_checks_fitScalefactor.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + if (controls_checks_fitScalefactor[b_i] == 1.0) { + uppars[uppars_counter] = problemDef->fitParams[static_cast + (unpacked_counter) - 1]; + unpacked_counter++; + uppars_counter++; + } else { + uppars[uppars_counter] = problemDef->otherParams[static_cast + (packed_counter) - 1]; + packed_counter++; + uppars_counter++; + } + } + + problemDef->scalefactors.set_size(1, uppars.size(1)); + unnamed_idx_1 = uppars.size(1); + for (i = 0; i < unnamed_idx_1; i++) { + problemDef->scalefactors[i] = uppars[i]; + } + + // qzshifts + unnamed_idx_1 = problemDef->qzshifts.size(1); + uppars.set_size(1, unnamed_idx_1); + for (i = 0; i < unnamed_idx_1; i++) { + uppars[i] = 0.0; + } + + uppars_counter = 0; + i = controls_checks_fitQzshift.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + if (controls_checks_fitQzshift[b_i] == 1.0) { + uppars[uppars_counter] = problemDef->fitParams[static_cast + (unpacked_counter) - 1]; + unpacked_counter++; + uppars_counter++; + } else { + uppars[uppars_counter] = problemDef->otherParams[static_cast + (packed_counter) - 1]; + packed_counter++; + uppars_counter++; + } + } + + problemDef->qzshifts.set_size(1, uppars.size(1)); + unnamed_idx_1 = uppars.size(1); + for (i = 0; i < unnamed_idx_1; i++) { + problemDef->qzshifts[i] = uppars[i]; + } + + // Bulk In + unnamed_idx_1 = problemDef->bulkIn.size(1); + uppars.set_size(1, unnamed_idx_1); + for (i = 0; i < unnamed_idx_1; i++) { + uppars[i] = 0.0; + } + + uppars_counter = 0; + i = controls_checks_fitBulkIn.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + if (controls_checks_fitBulkIn[b_i] == 1.0) { + uppars[uppars_counter] = problemDef->fitParams[static_cast + (unpacked_counter) - 1]; + unpacked_counter++; + uppars_counter++; + } else { + uppars[uppars_counter] = problemDef->otherParams[static_cast + (packed_counter) - 1]; + packed_counter++; + uppars_counter++; + } + } + + problemDef->bulkIn.set_size(1, uppars.size(1)); + unnamed_idx_1 = uppars.size(1); + for (i = 0; i < unnamed_idx_1; i++) { + problemDef->bulkIn[i] = uppars[i]; + } + + // Bulk Out + unnamed_idx_1 = problemDef->bulkOut.size(1); + uppars.set_size(1, unnamed_idx_1); + for (i = 0; i < unnamed_idx_1; i++) { + uppars[i] = 0.0; + } + + uppars_counter = 0; + i = controls_checks_fitBulkOut.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + if (controls_checks_fitBulkOut[b_i] == 1.0) { + uppars[uppars_counter] = problemDef->fitParams[static_cast + (unpacked_counter) - 1]; + unpacked_counter++; + uppars_counter++; + } else { + uppars[uppars_counter] = problemDef->otherParams[static_cast + (packed_counter) - 1]; + packed_counter++; + uppars_counter++; + } + } + + problemDef->bulkOut.set_size(1, uppars.size(1)); + unnamed_idx_1 = uppars.size(1); + for (i = 0; i < unnamed_idx_1; i++) { + problemDef->bulkOut[i] = uppars[i]; + } + + // Resolutions + unnamed_idx_1 = problemDef->resolutionParams.size(1); + uppars.set_size(1, unnamed_idx_1); + for (i = 0; i < unnamed_idx_1; i++) { + uppars[i] = 0.0; + } + + uppars_counter = 0; + i = controls_checks_fitResolutionParam.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + if (controls_checks_fitResolutionParam[b_i] == 1.0) { + uppars[uppars_counter] = problemDef->fitParams[static_cast + (unpacked_counter) - 1]; + unpacked_counter++; + uppars_counter++; + } else { + uppars[uppars_counter] = problemDef->otherParams[static_cast + (packed_counter) - 1]; + packed_counter++; + uppars_counter++; + } + } + + problemDef->resolutionParams.set_size(1, uppars.size(1)); + unnamed_idx_1 = uppars.size(1); + for (i = 0; i < unnamed_idx_1; i++) { + problemDef->resolutionParams[i] = uppars[i]; + } + + // Domain Ratios + unnamed_idx_1 = problemDef->domainRatio.size(1); + uppars.set_size(1, unnamed_idx_1); + for (i = 0; i < unnamed_idx_1; i++) { + uppars[i] = 0.0; + } + + uppars_counter = 0; + i = controls_checks_fitDomainRatio.size(1); + for (int32_T b_i{0}; b_i < i; b_i++) { + if (controls_checks_fitDomainRatio[b_i] == 1.0) { + uppars[uppars_counter] = problemDef->fitParams[static_cast + (unpacked_counter) - 1]; + unpacked_counter++; + uppars_counter++; + } else { + uppars[uppars_counter] = problemDef->otherParams[static_cast + (packed_counter) - 1]; + packed_counter++; + uppars_counter++; + } + } + + problemDef->domainRatio.set_size(1, uppars.size(1)); + unnamed_idx_1 = uppars.size(1); + for (i = 0; i < unnamed_idx_1; i++) { + problemDef->domainRatio[i] = uppars[i]; + } + } +} + +// End of code generation (unpackParams.cpp) diff --git a/RAT/unpackParams.h b/RAT/unpackParams.h new file mode 100644 index 00000000..8ea53381 --- /dev/null +++ b/RAT/unpackParams.h @@ -0,0 +1,42 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// unpackParams.h +// +// Code generation for function 'unpackParams' +// +#ifndef UNPACKPARAMS_H +#define UNPACKPARAMS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct struct5_T; +} + +// Function Declarations +namespace RAT +{ + void unpackParams(struct5_T *problemDef, const ::coder::array + &controls_checks_fitParam, const ::coder::array + &controls_checks_fitBackgroundParam, const ::coder::array< + real_T, 2U> &controls_checks_fitQzshift, const ::coder:: + array &controls_checks_fitScalefactor, const :: + coder::array &controls_checks_fitBulkIn, const :: + coder::array &controls_checks_fitBulkOut, const :: + coder::array &controls_checks_fitResolutionParam, + const ::coder::array + &controls_checks_fitDomainRatio); +} + +#endif + +// End of code generation (unpackParams.h) diff --git a/RAT/unsafeSxfun.cpp b/RAT/unsafeSxfun.cpp index 4f734255..5e945531 100644 --- a/RAT/unsafeSxfun.cpp +++ b/RAT/unsafeSxfun.cpp @@ -10,12 +10,310 @@ // Include files #include "unsafeSxfun.h" +#include "RATMain_data.h" +#include "RATMain_rtwutil.h" #include "rt_nonfinite.h" #include "coder_array.h" +#include // Function Definitions namespace RAT { + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in3, const ::coder::array &in4, + int32_T in5, const ::coder::array &in6, + const ::coder::array &in7) + { + ::coder::array b_in3; + ::coder::array c_in3; + ::coder::array d_in3; + real_T b_in3_re_tmp; + real_T c_in3_re_tmp; + real_T d_in3_re_tmp; + real_T in3_re_tmp; + int32_T b_loop_ub; + int32_T i; + int32_T loop_ub; + int32_T stride_0_1; + int32_T stride_1_1; + if (in4.size(1) == 1) { + i = in3.size(1); + } else { + i = in4.size(1); + } + + b_in3.set_size(1, i); + stride_0_1 = (in3.size(1) != 1); + stride_1_1 = (in4.size(1) != 1); + if (in4.size(1) == 1) { + loop_ub = in3.size(1); + } else { + loop_ub = in4.size(1); + } + + for (i = 0; i < loop_ub; i++) { + b_in3[i].re = in3[i * stride_0_1] - in4[in5 + in4.size(0) * (i * + stride_1_1)]; + b_in3[i].im = 0.0; + } + + c_in3.set_size(1, in6.size(1)); + loop_ub = in6.size(1); + for (i = 0; i < loop_ub; i++) { + c_in3[i].re = 0.0; + c_in3[i].im = 0.0; + b_loop_ub = b_in3.size(1); + for (stride_0_1 = 0; stride_0_1 < b_loop_ub; stride_0_1++) { + in3_re_tmp = b_in3[stride_0_1].re; + b_in3_re_tmp = in6[stride_0_1 + in6.size(0) * i].im; + c_in3_re_tmp = b_in3[stride_0_1].im; + d_in3_re_tmp = in6[stride_0_1 + in6.size(0) * i].re; + c_in3[i].re = c_in3[i].re + (in3_re_tmp * d_in3_re_tmp - c_in3_re_tmp * + b_in3_re_tmp); + c_in3[i].im = c_in3[i].im + (in3_re_tmp * b_in3_re_tmp + c_in3_re_tmp * + d_in3_re_tmp); + } + } + + if (in7.size(0) == 1) { + i = c_in3.size(1); + } else { + i = in7.size(0); + } + + d_in3.set_size(1, i); + stride_0_1 = (c_in3.size(1) != 1); + stride_1_1 = (in7.size(0) != 1); + if (in7.size(0) == 1) { + loop_ub = c_in3.size(1); + } else { + loop_ub = in7.size(0); + } + + for (i = 0; i < loop_ub; i++) { + real_T ai; + real_T ar; + b_loop_ub = i * stride_0_1; + ar = c_in3[b_loop_ub].re; + ai = c_in3[b_loop_ub].im; + b_loop_ub = i * stride_1_1; + c_in3_re_tmp = in7[b_loop_ub].re; + d_in3_re_tmp = -in7[b_loop_ub].im; + if (d_in3_re_tmp == 0.0) { + if (ai == 0.0) { + d_in3[i].re = ar / c_in3_re_tmp; + d_in3[i].im = 0.0; + } else if (ar == 0.0) { + d_in3[i].re = 0.0; + d_in3[i].im = ai / c_in3_re_tmp; + } else { + d_in3[i].re = ar / c_in3_re_tmp; + d_in3[i].im = ai / c_in3_re_tmp; + } + } else if (c_in3_re_tmp == 0.0) { + if (ar == 0.0) { + d_in3[i].re = ai / d_in3_re_tmp; + d_in3[i].im = 0.0; + } else if (ai == 0.0) { + d_in3[i].re = 0.0; + d_in3[i].im = -(ar / d_in3_re_tmp); + } else { + d_in3[i].re = ai / d_in3_re_tmp; + d_in3[i].im = -(ar / d_in3_re_tmp); + } + } else { + real_T brm; + brm = std::abs(c_in3_re_tmp); + in3_re_tmp = std::abs(d_in3_re_tmp); + if (brm > in3_re_tmp) { + b_in3_re_tmp = d_in3_re_tmp / c_in3_re_tmp; + in3_re_tmp = c_in3_re_tmp + b_in3_re_tmp * d_in3_re_tmp; + d_in3[i].re = (ar + b_in3_re_tmp * ai) / in3_re_tmp; + d_in3[i].im = (ai - b_in3_re_tmp * ar) / in3_re_tmp; + } else if (in3_re_tmp == brm) { + if (c_in3_re_tmp > 0.0) { + b_in3_re_tmp = 0.5; + } else { + b_in3_re_tmp = -0.5; + } + + if (d_in3_re_tmp > 0.0) { + in3_re_tmp = 0.5; + } else { + in3_re_tmp = -0.5; + } + + d_in3[i].re = (ar * b_in3_re_tmp + ai * in3_re_tmp) / brm; + d_in3[i].im = (ai * b_in3_re_tmp - ar * in3_re_tmp) / brm; + } else { + b_in3_re_tmp = c_in3_re_tmp / d_in3_re_tmp; + in3_re_tmp = d_in3_re_tmp + b_in3_re_tmp * c_in3_re_tmp; + d_in3[i].re = (b_in3_re_tmp * ar + ai) / in3_re_tmp; + d_in3[i].im = (b_in3_re_tmp * ai - ar) / in3_re_tmp; + } + } + } + + in1.set_size(1, d_in3.size(1)); + loop_ub = d_in3.size(1); + for (i = 0; i < loop_ub; i++) { + creal_T varargin_1; + creal_T varargout_1; + varargin_1 = d_in3[i]; + varargout_1.re = varargin_1.re * varargin_1.re - varargin_1.im * + varargin_1.im; + in3_re_tmp = varargin_1.re * varargin_1.im; + varargout_1.im = in3_re_tmp + in3_re_tmp; + in1[i] = varargout_1; + } + } + + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 1U> &in3, const ::coder::array &in4) + { + ::coder::array b_in1; + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + int32_T stride_2_0; + if (in4.size(0) == 1) { + if (in3.size(0) == 1) { + i = in1.size(0); + } else { + i = in3.size(0); + } + } else { + i = in4.size(0); + } + + b_in1.set_size(i); + stride_0_0 = (in1.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + stride_2_0 = (in4.size(0) != 1); + if (in4.size(0) == 1) { + if (in3.size(0) == 1) { + loop_ub = in1.size(0); + } else { + loop_ub = in3.size(0); + } + } else { + loop_ub = in4.size(0); + } + + for (i = 0; i < loop_ub; i++) { + b_in1[i] = (in1[i * stride_0_0] - in3[i * stride_1_0]) / in4[i * + stride_2_0]; + } + + in1.set_size(b_in1.size(0)); + loop_ub = b_in1.size(0); + for (i = 0; i < loop_ub; i++) { + in1[i] = b_in1[i]; + } + + loop_ub = in1.size(0); + for (i = 0; i < loop_ub; i++) { + real_T varargin_1; + varargin_1 = in1[i]; + in1[i] = varargin_1 * varargin_1; + } + } + + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in3, int32_T in4, int32_T in5, const :: + coder::array &in6, int32_T in7, int32_T in8, + const ::coder::array &in9) + { + ::coder::array b_in3; + int32_T aux_0_1; + int32_T aux_1_1; + int32_T aux_2_1; + int32_T b_loop_ub; + int32_T i; + int32_T i1; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_0_1; + int32_T stride_1_0; + int32_T stride_1_1; + int32_T stride_2_0; + int32_T stride_2_1; + if (in9.size(0) == 1) { + if (in7 + 1 == 1) { + i = in4 + 1; + } else { + i = in7 + 1; + } + } else { + i = in9.size(0); + } + + if (in9.size(1) == 1) { + if (in8 + 1 == 1) { + i1 = in5 + 1; + } else { + i1 = in8 + 1; + } + } else { + i1 = in9.size(1); + } + + b_in3.set_size(i, i1); + stride_0_0 = (in4 + 1 != 1); + stride_0_1 = (in5 + 1 != 1); + stride_1_0 = (in7 + 1 != 1); + stride_1_1 = (in8 + 1 != 1); + stride_2_0 = (in9.size(0) != 1); + stride_2_1 = (in9.size(1) != 1); + aux_0_1 = 0; + aux_1_1 = 0; + aux_2_1 = 0; + if (in9.size(1) == 1) { + if (in8 + 1 == 1) { + loop_ub = in5 + 1; + } else { + loop_ub = in8 + 1; + } + } else { + loop_ub = in9.size(1); + } + + for (i = 0; i < loop_ub; i++) { + i1 = in9.size(0); + if (i1 == 1) { + if (in7 + 1 == 1) { + b_loop_ub = in4 + 1; + } else { + b_loop_ub = in7 + 1; + } + } else { + b_loop_ub = i1; + } + + for (i1 = 0; i1 < b_loop_ub; i1++) { + b_in3[i1 + b_in3.size(0) * i] = (in3[i1 * stride_0_0 + in3.size(0) * + aux_0_1] - in6[i1 * stride_1_0 + in6.size(0) * aux_1_1]) / in9[i1 * + stride_2_0 + in9.size(0) * aux_2_1]; + } + + aux_2_1 += stride_2_1; + aux_1_1 += stride_1_1; + aux_0_1 += stride_0_1; + } + + in1.set_size(b_in3.size(0), b_in3.size(1)); + loop_ub = b_in3.size(1); + for (i = 0; i < loop_ub; i++) { + b_loop_ub = b_in3.size(0); + for (i1 = 0; i1 < b_loop_ub; i1++) { + real_T varargin_1; + varargin_1 = b_in3[i1 + b_in3.size(0) * i]; + in1[i1 + in1.size(0) * i] = rt_powd_snf(varargin_1, 2.0); + } + } + } + void binary_expand_op(::coder::array &in1, const ::coder::array< real_T, 2U> &in3, const ::coder::array &in4) { diff --git a/RAT/unsafeSxfun.h b/RAT/unsafeSxfun.h index f524dc40..e16458a4 100644 --- a/RAT/unsafeSxfun.h +++ b/RAT/unsafeSxfun.h @@ -19,6 +19,16 @@ // Function Declarations namespace RAT { + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in3, const ::coder::array &in4, + int32_T in5, const ::coder::array &in6, + const ::coder::array &in7); + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 1U> &in3, const ::coder::array &in4); + void binary_expand_op(::coder::array &in1, const ::coder::array< + real_T, 2U> &in3, int32_T in4, int32_T in5, const :: + coder::array &in6, int32_T in7, int32_T in8, + const ::coder::array &in9); void binary_expand_op(::coder::array &in1, const ::coder::array< real_T, 2U> &in3, const ::coder::array &in4); } diff --git a/RAT/useConstantDim.cpp b/RAT/useConstantDim.cpp new file mode 100644 index 00000000..cd168815 --- /dev/null +++ b/RAT/useConstantDim.cpp @@ -0,0 +1,63 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// useConstantDim.cpp +// +// Code generation for function 'useConstantDim' +// + +// Include files +#include "useConstantDim.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + void useConstantDim(::coder::array &varargin_2, int32_T + varargin_3) + { + int32_T subsb_idx_1; + if (varargin_3 == 1) { + if ((varargin_2.size(0) != 0) && (varargin_2.size(1) != 0)) { + int32_T i; + i = varargin_2.size(1); + for (int32_T k{0}; k < i; k++) { + int32_T i1; + i1 = varargin_2.size(0); + if (i1 - 2 >= 0) { + subsb_idx_1 = k + 1; + } + + for (int32_T b_k{0}; b_k <= i1 - 2; b_k++) { + varargin_2[(b_k + varargin_2.size(0) * (subsb_idx_1 - 1)) + 1] = + varargin_2[b_k + varargin_2.size(0) * k] + varargin_2[(b_k + + varargin_2.size(0) * (subsb_idx_1 - 1)) + 1]; + } + } + } + } else if ((varargin_2.size(0) != 0) && (varargin_2.size(1) != 0)) { + int32_T i; + i = varargin_2.size(1); + for (int32_T k{0}; k <= i - 2; k++) { + int32_T i1; + i1 = varargin_2.size(0); + for (int32_T b_k{0}; b_k < i1; b_k++) { + varargin_2[b_k + varargin_2.size(0) * (k + 1)] = varargin_2[b_k + + varargin_2.size(0) * k] + varargin_2[b_k + varargin_2.size(0) * + (k + 1)]; + } + } + } + } + } + } +} + +// End of code generation (useConstantDim.cpp) diff --git a/RAT/useConstantDim.h b/RAT/useConstantDim.h new file mode 100644 index 00000000..c9d5d1bd --- /dev/null +++ b/RAT/useConstantDim.h @@ -0,0 +1,34 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// useConstantDim.h +// +// Code generation for function 'useConstantDim' +// +#ifndef USECONSTANTDIM_H +#define USECONSTANTDIM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void useConstantDim(::coder::array &varargin_2, int32_T + varargin_3); + } + } +} + +#endif + +// End of code generation (useConstantDim.h) diff --git a/RAT/vAllOrAny.cpp b/RAT/vAllOrAny.cpp new file mode 100644 index 00000000..07c4218e --- /dev/null +++ b/RAT/vAllOrAny.cpp @@ -0,0 +1,93 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// vAllOrAny.cpp +// +// Code generation for function 'vAllOrAny' +// + +// Include files +#include "vAllOrAny.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + static void genloops(const ::coder::array &x, boolean_T *p, + int32_T varargin_1, int32_T varargin_2); + } + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + static void genloops(const ::coder::array &x, boolean_T *p, + int32_T varargin_1, int32_T varargin_2) + { + if ((*p) || std::isnan(x[(varargin_1 + x.size(0) * (varargin_2 - 1)) - 1])) + { + *p = true; + } else { + *p = false; + } + } + + void b_genloops(const ::coder::array &x, boolean_T *p, int32_T + varargin_1, int32_T varargin_2) + { + if (*p) { + real_T b_x; + b_x = x[(varargin_1 + x.size(0) * (varargin_2 - 1)) - 1]; + if ((!std::isinf(b_x)) && (!std::isnan(b_x))) { + *p = true; + } else { + *p = false; + } + } else { + *p = false; + } + } + + void c_genloops(const real_T x_data[], boolean_T *p) + { + if ((*p) || std::isnan(x_data[0])) { + *p = true; + } else { + *p = false; + } + } + + boolean_T vAllOrAny(const ::coder::array &x) + { + int32_T i; + boolean_T p; + p = false; + i = x.size(1); + for (int32_T k{0}; k < i; k++) { + int32_T i1; + i1 = x.size(0); + for (int32_T b_k{0}; b_k < i1; b_k++) { + genloops(x, &p, b_k + 1, k + 1); + } + } + + return p; + } + } + } +} + +// End of code generation (vAllOrAny.cpp) diff --git a/RAT/vAllOrAny.h b/RAT/vAllOrAny.h new file mode 100644 index 00000000..20f79b0a --- /dev/null +++ b/RAT/vAllOrAny.h @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// vAllOrAny.h +// +// Code generation for function 'vAllOrAny' +// +#ifndef VALLORANY_H +#define VALLORANY_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void b_genloops(const ::coder::array &x, boolean_T *p, int32_T + varargin_1, int32_T varargin_2); + void c_genloops(const real_T x_data[], boolean_T *p); + boolean_T vAllOrAny(const ::coder::array &x); + } + } +} + +#endif + +// End of code generation (vAllOrAny.h) diff --git a/RAT/validate_print_arguments.cpp b/RAT/validate_print_arguments.cpp new file mode 100644 index 00000000..f6474505 --- /dev/null +++ b/RAT/validate_print_arguments.cpp @@ -0,0 +1,44 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// validate_print_arguments.cpp +// +// Code generation for function 'validate_print_arguments' +// + +// Include files +#include "validate_print_arguments.h" +#include "rt_nonfinite.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + void validate_print_arguments(real_T varargin_1, real_T varargin_2, real_T + varargin_3, real_T varargin_4, real_T varargin_5, real_T + validatedArguments[5]) + { + validatedArguments[0] = varargin_1; + validatedArguments[1] = varargin_2; + validatedArguments[2] = varargin_3; + validatedArguments[3] = varargin_4; + validatedArguments[4] = varargin_5; + } + + void validate_print_arguments(int32_T varargin_1, int32_T varargin_2, + int32_T varargin_3, int32_T validatedArguments[3]) + { + validatedArguments[0] = varargin_1; + validatedArguments[1] = varargin_2; + validatedArguments[2] = varargin_3; + } + } + } +} + +// End of code generation (validate_print_arguments.cpp) diff --git a/RAT/validate_print_arguments.h b/RAT/validate_print_arguments.h new file mode 100644 index 00000000..62db5460 --- /dev/null +++ b/RAT/validate_print_arguments.h @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// validate_print_arguments.h +// +// Code generation for function 'validate_print_arguments' +// +#ifndef VALIDATE_PRINT_ARGUMENTS_H +#define VALIDATE_PRINT_ARGUMENTS_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + void validate_print_arguments(real_T varargin_1, real_T varargin_2, real_T + varargin_3, real_T varargin_4, real_T varargin_5, real_T + validatedArguments[5]); + void validate_print_arguments(int32_T varargin_1, int32_T varargin_2, + int32_T varargin_3, int32_T validatedArguments[3]); + } + } +} + +#endif + +// End of code generation (validate_print_arguments.h) diff --git a/RAT/var.cpp b/RAT/var.cpp new file mode 100644 index 00000000..57c5b905 --- /dev/null +++ b/RAT/var.cpp @@ -0,0 +1,58 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// var.cpp +// +// Code generation for function 'var' +// + +// Include files +#include "var.h" +#include "rt_nonfinite.h" +#include "varstd.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + void var(const ::coder::array &x, ::coder::array &y) + { + ::coder::array xv; + int32_T hi; + int32_T loop_ub; + int32_T nx; + int32_T outsize_idx_0; + y.set_size(1, x.size(1)); + hi = x.size(1); + for (int32_T k{0}; k < hi; k++) { + y[k] = 0.0; + } + + hi = x.size(1); + if (x.size(1) - 1 >= 0) { + nx = x.size(0); + outsize_idx_0 = x.size(0); + loop_ub = x.size(0); + } + + for (int32_T b_k{0}; b_k < hi; b_k++) { + xv.set_size(outsize_idx_0); + for (int32_T k{0}; k < loop_ub; k++) { + xv[k] = 0.0; + } + + for (int32_T k{0}; k < nx; k++) { + xv[k] = x[k + x.size(0) * b_k]; + } + + y[b_k] = b_varstd_anonFcn3(x.size(0), xv); + } + } + } +} + +// End of code generation (var.cpp) diff --git a/RAT/var.h b/RAT/var.h new file mode 100644 index 00000000..baf60459 --- /dev/null +++ b/RAT/var.h @@ -0,0 +1,30 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// var.h +// +// Code generation for function 'var' +// +#ifndef VAR_H +#define VAR_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + void var(const ::coder::array &x, ::coder::array &y); + } +} + +#endif + +// End of code generation (var.h) diff --git a/RAT/varstd.cpp b/RAT/varstd.cpp new file mode 100644 index 00000000..153eff88 --- /dev/null +++ b/RAT/varstd.cpp @@ -0,0 +1,80 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// varstd.cpp +// +// Code generation for function 'varstd' +// + +// Include files +#include "varstd.h" +#include "combineVectorElements.h" +#include "rt_nonfinite.h" +#include "xnrm2.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + real_T b_varstd_anonFcn3(int32_T n, const ::coder::array &x) + { + real_T varargout_1; + if (n == 0) { + varargout_1 = rtNaN; + } else if (n == 1) { + if ((!std::isinf(x[0])) && (!std::isnan(x[0]))) { + varargout_1 = 0.0; + } else { + varargout_1 = rtNaN; + } + } else { + real_T xbar; + xbar = b_combineVectorElements(x, n) / static_cast(n); + varargout_1 = 0.0; + for (int32_T k{0}; k < n; k++) { + real_T t; + t = x[k] - xbar; + varargout_1 += t * t; + } + + varargout_1 /= static_cast(n - 1); + } + + return varargout_1; + } + + real_T varstd_anonFcn3(int32_T n, const ::coder::array &x) + { + ::coder::array absdiff; + real_T varargout_1; + if (n == 0) { + varargout_1 = rtNaN; + } else if (n == 1) { + if ((!std::isinf(x[0])) && (!std::isnan(x[0]))) { + varargout_1 = 0.0; + } else { + varargout_1 = rtNaN; + } + } else { + real_T xbar; + xbar = b_combineVectorElements(x, n) / static_cast(n); + absdiff.set_size(x.size(0)); + for (int32_T k{0}; k < n; k++) { + absdiff[k] = std::abs(x[k] - xbar); + } + + varargout_1 = internal::blas::xnrm2(n, absdiff) / std::sqrt(static_cast< + real_T>(n - 1)); + } + + return varargout_1; + } + } +} + +// End of code generation (varstd.cpp) diff --git a/RAT/varstd.h b/RAT/varstd.h new file mode 100644 index 00000000..c7036f84 --- /dev/null +++ b/RAT/varstd.h @@ -0,0 +1,31 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// varstd.h +// +// Code generation for function 'varstd' +// +#ifndef VARSTD_H +#define VARSTD_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + real_T b_varstd_anonFcn3(int32_T n, const ::coder::array &x); + real_T varstd_anonFcn3(int32_T n, const ::coder::array &x); + } +} + +#endif + +// End of code generation (varstd.h) diff --git a/RAT/xdhseqr.cpp b/RAT/xdhseqr.cpp new file mode 100644 index 00000000..e4b1ddd0 --- /dev/null +++ b/RAT/xdhseqr.cpp @@ -0,0 +1,388 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xdhseqr.cpp +// +// Code generation for function 'xdhseqr' +// + +// Include files +#include "xdhseqr.h" +#include "rt_nonfinite.h" +#include "xdlanv2.h" +#include "xrot.h" +#include "xzlarfg.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + int32_T eml_dlahqr(::coder::array &h, ::coder::array &z) + { + real_T aa; + real_T ab; + real_T ba; + real_T bb; + real_T d; + real_T rt1r; + real_T rt2r; + real_T s; + real_T tst; + int32_T info; + int32_T ldh; + int32_T ldz; + int32_T n; + n = h.size(0); + ldh = h.size(0); + ldz = z.size(0); + info = 0; + if ((n != 0) && (n != 1)) { + real_T v[3]; + real_T SMLNUM; + int32_T i; + int32_T itmax; + int32_T kdefl; + boolean_T exitg1; + v[0] = 0.0; + v[1] = 0.0; + v[2] = 0.0; + for (int32_T j{0}; j <= n - 4; j++) { + h[(j + h.size(0) * j) + 2] = 0.0; + h[(j + h.size(0) * j) + 3] = 0.0; + } + + if (n - 2 >= 1) { + h[(n + h.size(0) * (n - 3)) - 1] = 0.0; + } + + if (n <= 10) { + itmax = 10; + } else { + itmax = n; + } + + itmax *= 30; + kdefl = 0; + SMLNUM = 2.2250738585072014E-308 * (static_cast(n) / + 2.2204460492503131E-16); + i = n - 1; + exitg1 = false; + while ((!exitg1) && (i + 1 >= 1)) { + int32_T L; + int32_T its; + int32_T nr; + boolean_T exitg2; + boolean_T goto150; + L = 1; + goto150 = false; + its = 0; + exitg2 = false; + while ((!exitg2) && (its <= itmax)) { + int32_T k; + boolean_T exitg3; + k = i; + exitg3 = false; + while ((!exitg3) && (k + 1 > L)) { + ba = std::abs(h[k + h.size(0) * (k - 1)]); + if (ba <= SMLNUM) { + exitg3 = true; + } else { + bb = std::abs(h[k + h.size(0) * k]); + tst = std::abs(h[(k + h.size(0) * (k - 1)) - 1]) + bb; + if (tst == 0.0) { + if (k - 1 >= 1) { + tst = std::abs(h[(k + h.size(0) * (k - 2)) - 1]); + } + + if (k + 2 <= n) { + tst += std::abs(h[(k + h.size(0) * k) + 1]); + } + } + + if (ba <= 2.2204460492503131E-16 * tst) { + tst = std::abs(h[(k + h.size(0) * k) - 1]); + if (ba > tst) { + ab = ba; + ba = tst; + } else { + ab = tst; + } + + tst = std::abs(h[(k + h.size(0) * (k - 1)) - 1] - h[k + + h.size(0) * k]); + if (bb > tst) { + aa = bb; + bb = tst; + } else { + aa = tst; + } + + s = aa + ab; + if (ba * (ab / s) <= std::fmax(SMLNUM, + 2.2204460492503131E-16 * (bb * (aa / s)))) { + exitg3 = true; + } else { + k--; + } + } else { + k--; + } + } + } + + L = k + 1; + if (k + 1 > 1) { + h[k + h.size(0) * (k - 1)] = 0.0; + } + + if (k + 1 >= i) { + goto150 = true; + exitg2 = true; + } else { + int32_T m; + kdefl++; + if (kdefl - kdefl / 20 * 20 == 0) { + s = std::abs(h[i + h.size(0) * (i - 1)]) + std::abs(h[(i + + h.size(0) * (i - 2)) - 1]); + tst = 0.75 * s + h[i + h.size(0) * i]; + aa = -0.4375 * s; + ab = s; + bb = tst; + } else if (kdefl - kdefl / 10 * 10 == 0) { + s = std::abs(h[(k + h.size(0) * k) + 1]) + std::abs(h[(k + + h.size(0) * (k + 1)) + 2]); + tst = 0.75 * s + h[k + h.size(0) * k]; + aa = -0.4375 * s; + ab = s; + bb = tst; + } else { + tst = h[(i + h.size(0) * (i - 1)) - 1]; + ab = h[i + h.size(0) * (i - 1)]; + aa = h[(i + h.size(0) * i) - 1]; + bb = h[i + h.size(0) * i]; + } + + s = ((std::abs(tst) + std::abs(aa)) + std::abs(ab)) + std::abs + (bb); + if (s == 0.0) { + rt1r = 0.0; + ab = 0.0; + rt2r = 0.0; + aa = 0.0; + } else { + tst /= s; + ab /= s; + aa /= s; + bb /= s; + ba = (tst + bb) / 2.0; + tst = (tst - ba) * (bb - ba) - aa * ab; + ab = std::sqrt(std::abs(tst)); + if (tst >= 0.0) { + rt1r = ba * s; + rt2r = rt1r; + ab *= s; + aa = -ab; + } else { + rt1r = ba + ab; + rt2r = ba - ab; + if (std::abs(rt1r - bb) <= std::abs(rt2r - bb)) { + rt1r *= s; + rt2r = rt1r; + } else { + rt2r *= s; + rt1r = rt2r; + } + + ab = 0.0; + aa = 0.0; + } + } + + m = i - 1; + exitg3 = false; + while ((!exitg3) && (m >= k + 1)) { + tst = h[m + h.size(0) * (m - 1)]; + ba = h[(m + h.size(0) * (m - 1)) - 1]; + bb = ba - rt2r; + s = (std::abs(bb) + std::abs(aa)) + std::abs(tst); + tst /= s; + v[0] = (tst * h[(m + h.size(0) * m) - 1] + (ba - rt1r) * (bb + / s)) - ab * (aa / s); + v[1] = tst * (((ba + h[m + h.size(0) * m]) - rt1r) - rt2r); + v[2] = tst * h[(m + h.size(0) * m) + 1]; + s = (std::abs(v[0]) + std::abs(v[1])) + std::abs(v[2]); + v[0] /= s; + v[1] /= s; + v[2] /= s; + if ((m == k + 1) || (std::abs(h[(m + h.size(0) * (m - 2)) - + 1]) * (std::abs(v[1]) + std::abs(v[2])) <= + 2.2204460492503131E-16 * std::abs(v[0]) + * ((std::abs(h[(m + h.size(0) * (m - 2)) + - 2]) + std::abs(ba)) + std::abs(h[m + h.size(0) * m])))) + { + exitg3 = true; + } else { + m--; + } + } + + for (int32_T b_k{m}; b_k <= i; b_k++) { + nr = (i - b_k) + 2; + if (nr >= 3) { + nr = 3; + } + + if (b_k > m) { + int32_T hoffset; + hoffset = (b_k + ldh * (b_k - 2)) - 1; + for (int32_T j{0}; j < nr; j++) { + v[j] = h[j + hoffset]; + } + } + + tst = v[0]; + rt2r = xzlarfg(nr, &tst, v); + v[0] = tst; + if (b_k > m) { + h[(b_k + h.size(0) * (b_k - 2)) - 1] = tst; + h[b_k + h.size(0) * (b_k - 2)] = 0.0; + if (b_k < i) { + h[(b_k + h.size(0) * (b_k - 2)) + 1] = 0.0; + } + } else if (m > k + 1) { + h[(b_k + h.size(0) * (b_k - 2)) - 1] = h[(b_k + h.size(0) * + (b_k - 2)) - 1] * (1.0 - rt2r); + } + + rt1r = v[1]; + tst = rt2r * v[1]; + if (nr == 3) { + s = v[2]; + aa = rt2r * v[2]; + for (int32_T j{b_k}; j <= n; j++) { + d = h[(b_k + h.size(0) * (j - 1)) - 1]; + ba = h[b_k + h.size(0) * (j - 1)]; + bb = h[(b_k + h.size(0) * (j - 1)) + 1]; + ab = (d + rt1r * ba) + s * bb; + d -= ab * rt2r; + h[(b_k + h.size(0) * (j - 1)) - 1] = d; + ba -= ab * tst; + h[b_k + h.size(0) * (j - 1)] = ba; + bb -= ab * aa; + h[(b_k + h.size(0) * (j - 1)) + 1] = bb; + } + + if (b_k + 3 <= i + 1) { + nr = b_k + 2; + } else { + nr = i; + } + + for (int32_T j{0}; j <= nr; j++) { + d = h[j + h.size(0) * (b_k - 1)]; + ba = h[j + h.size(0) * b_k]; + bb = h[j + h.size(0) * (b_k + 1)]; + ab = (d + rt1r * ba) + s * bb; + d -= ab * rt2r; + h[j + h.size(0) * (b_k - 1)] = d; + ba -= ab * tst; + h[j + h.size(0) * b_k] = ba; + bb -= ab * aa; + h[j + h.size(0) * (b_k + 1)] = bb; + } + + for (int32_T j{0}; j < n; j++) { + d = z[j + z.size(0) * (b_k - 1)]; + ba = z[j + z.size(0) * b_k]; + bb = z[j + z.size(0) * (b_k + 1)]; + ab = (d + rt1r * ba) + s * bb; + d -= ab * rt2r; + z[j + z.size(0) * (b_k - 1)] = d; + ba -= ab * tst; + z[j + z.size(0) * b_k] = ba; + bb -= ab * aa; + z[j + z.size(0) * (b_k + 1)] = bb; + } + } else if (nr == 2) { + for (int32_T j{b_k}; j <= n; j++) { + s = h[(b_k + h.size(0) * (j - 1)) - 1]; + d = h[b_k + h.size(0) * (j - 1)]; + ab = s + rt1r * d; + s -= ab * rt2r; + h[(b_k + h.size(0) * (j - 1)) - 1] = s; + d -= ab * tst; + h[b_k + h.size(0) * (j - 1)] = d; + } + + for (int32_T j{0}; j <= i; j++) { + s = h[j + h.size(0) * (b_k - 1)]; + d = h[j + h.size(0) * b_k]; + ab = s + rt1r * d; + s -= ab * rt2r; + h[j + h.size(0) * (b_k - 1)] = s; + d -= ab * tst; + h[j + h.size(0) * b_k] = d; + } + + for (int32_T j{0}; j < n; j++) { + s = z[j + z.size(0) * (b_k - 1)]; + d = z[j + z.size(0) * b_k]; + ab = s + rt1r * d; + s -= ab * rt2r; + z[j + z.size(0) * (b_k - 1)] = s; + d -= ab * tst; + z[j + z.size(0) * b_k] = d; + } + } + } + + its++; + } + } + + if (!goto150) { + info = i + 1; + exitg1 = true; + } else { + if ((L != i + 1) && (L == i)) { + rt1r = h[(i + h.size(0) * i) - 1]; + s = h[i + h.size(0) * (i - 1)]; + d = h[i + h.size(0) * i]; + xdlanv2(&h[(i + h.size(0) * (i - 1)) - 1], &rt1r, &s, &d, &tst, + &ab, &aa, &ba, &bb, &rt2r); + h[(i + h.size(0) * i) - 1] = rt1r; + h[i + h.size(0) * (i - 1)] = s; + h[i + h.size(0) * i] = d; + if (n > i + 1) { + nr = i + (i + 1) * ldh; + blas::xrot((n - i) - 1, h, nr, ldh, nr + 1, ldh, bb, rt2r); + } + + blas::xrot(i - 1, h, (i - 1) * ldh + 1, i * ldh + 1, bb, rt2r); + blas::xrot(n, z, (i - 1) * ldz + 1, i * ldz + 1, bb, rt2r); + } + + kdefl = 0; + i = L - 2; + } + } + } + + return info; + } + } + } + } +} + +// End of code generation (xdhseqr.cpp) diff --git a/RAT/xdhseqr.h b/RAT/xdhseqr.h new file mode 100644 index 00000000..e6d74ed0 --- /dev/null +++ b/RAT/xdhseqr.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xdhseqr.h +// +// Code generation for function 'xdhseqr' +// +#ifndef XDHSEQR_H +#define XDHSEQR_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + int32_T eml_dlahqr(::coder::array &h, ::coder::array &z); + } + } + } +} + +#endif + +// End of code generation (xdhseqr.h) diff --git a/RAT/xdlanv2.cpp b/RAT/xdlanv2.cpp new file mode 100644 index 00000000..82e0c692 --- /dev/null +++ b/RAT/xdlanv2.cpp @@ -0,0 +1,179 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xdlanv2.cpp +// +// Code generation for function 'xdlanv2' +// + +// Include files +#include "xdlanv2.h" +#include "RATMain_rtwutil.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xdlanv2(real_T *a, real_T *b, real_T *c, real_T *d, real_T *rt1r, + real_T *rt1i, real_T *rt2r, real_T *rt2i, real_T *cs, + real_T *sn) + { + if (*c == 0.0) { + *cs = 1.0; + *sn = 0.0; + } else if (*b == 0.0) { + real_T temp; + *cs = 0.0; + *sn = 1.0; + temp = *d; + *d = *a; + *a = temp; + *b = -*c; + *c = 0.0; + } else { + real_T temp; + temp = *a - *d; + if ((temp == 0.0) && ((*b < 0.0) != (*c < 0.0))) { + *cs = 1.0; + *sn = 0.0; + } else { + real_T bcmax; + real_T bcmis; + real_T p; + real_T scale; + real_T z; + int32_T count; + int32_T i; + p = 0.5 * temp; + bcmis = std::abs(*b); + scale = std::abs(*c); + bcmax = std::fmax(bcmis, scale); + if (!(*b < 0.0)) { + count = 1; + } else { + count = -1; + } + + if (!(*c < 0.0)) { + i = 1; + } else { + i = -1; + } + + bcmis = std::fmin(bcmis, scale) * static_cast(count) * + static_cast(i); + scale = std::fmax(std::abs(p), bcmax); + z = p / scale * p + bcmax / scale * bcmis; + if (z >= 8.8817841970012523E-16) { + real_T tau; + *a = std::sqrt(scale) * std::sqrt(z); + if (p < 0.0) { + *a = -*a; + } + + z = p + *a; + *a = *d + z; + *d -= bcmax / z * bcmis; + tau = rt_hypotd_snf(*c, z); + *cs = z / tau; + *sn = *c / tau; + *b -= *c; + *c = 0.0; + } else { + real_T tau; + bcmis = *b + *c; + scale = std::fmax(std::abs(temp), std::abs(bcmis)); + count = 0; + while ((scale >= 7.4428285367870146E+137) && (count <= 20)) { + bcmis *= 1.3435752215134178E-138; + temp *= 1.3435752215134178E-138; + scale = std::fmax(std::abs(temp), std::abs(bcmis)); + count++; + } + + while ((scale <= 1.3435752215134178E-138) && (count <= 20)) { + bcmis *= 7.4428285367870146E+137; + temp *= 7.4428285367870146E+137; + scale = std::fmax(std::abs(temp), std::abs(bcmis)); + count++; + } + + tau = rt_hypotd_snf(bcmis, temp); + *cs = std::sqrt(0.5 * (std::abs(bcmis) / tau + 1.0)); + if (!(bcmis < 0.0)) { + count = 1; + } else { + count = -1; + } + + *sn = -(0.5 * temp / (tau * *cs)) * static_cast(count); + bcmax = *a * *cs + *b * *sn; + scale = -*a * *sn + *b * *cs; + z = *c * *cs + *d * *sn; + bcmis = -*c * *sn + *d * *cs; + *b = scale * *cs + bcmis * *sn; + *c = -bcmax * *sn + z * *cs; + temp = 0.5 * ((bcmax * *cs + z * *sn) + (-scale * *sn + bcmis * * + cs)); + *a = temp; + *d = temp; + if (*c != 0.0) { + if (*b != 0.0) { + if ((*b < 0.0) == (*c < 0.0)) { + bcmis = std::sqrt(std::abs(*b)); + scale = std::sqrt(std::abs(*c)); + *a = bcmis * scale; + if (!(*c < 0.0)) { + p = *a; + } else { + p = -*a; + } + + tau = 1.0 / std::sqrt(std::abs(*b + *c)); + *a = temp + p; + *d = temp - p; + *b -= *c; + *c = 0.0; + bcmax = bcmis * tau; + bcmis = scale * tau; + temp = *cs * bcmax - *sn * bcmis; + *sn = *cs * bcmis + *sn * bcmax; + *cs = temp; + } + } else { + *b = -*c; + *c = 0.0; + temp = *cs; + *cs = -*sn; + *sn = temp; + } + } + } + } + } + + *rt1r = *a; + *rt2r = *d; + if (*c == 0.0) { + *rt1i = 0.0; + *rt2i = 0.0; + } else { + *rt1i = std::sqrt(std::abs(*b)) * std::sqrt(std::abs(*c)); + *rt2i = -*rt1i; + } + } + } + } + } +} + +// End of code generation (xdlanv2.cpp) diff --git a/RAT/xdlanv2.h b/RAT/xdlanv2.h new file mode 100644 index 00000000..a27ccefd --- /dev/null +++ b/RAT/xdlanv2.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xdlanv2.h +// +// Code generation for function 'xdlanv2' +// +#ifndef XDLANV2_H +#define XDLANV2_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xdlanv2(real_T *a, real_T *b, real_T *c, real_T *d, real_T *rt1r, + real_T *rt1i, real_T *rt2r, real_T *rt2i, real_T *cs, + real_T *sn); + } + } + } +} + +#endif + +// End of code generation (xdlanv2.h) diff --git a/RAT/xgehrd.cpp b/RAT/xgehrd.cpp new file mode 100644 index 00000000..1b585568 --- /dev/null +++ b/RAT/xgehrd.cpp @@ -0,0 +1,78 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgehrd.cpp +// +// Code generation for function 'xgehrd' +// + +// Include files +#include "xgehrd.h" +#include "rt_nonfinite.h" +#include "xzlarf.h" +#include "xzlarfg.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace lapack + { + void xgehrd(::coder::array &a, ::coder::array + &tau) + { + ::coder::array work; + real_T alpha1; + int32_T i; + int32_T n; + int32_T unnamed_idx_0; + n = a.size(0); + if (a.size(0) < 1) { + i = 0; + } else { + i = a.size(0) - 1; + } + + tau.set_size(i); + unnamed_idx_0 = a.size(0); + work.set_size(unnamed_idx_0); + for (i = 0; i < unnamed_idx_0; i++) { + work[i] = 0.0; + } + + i = a.size(0); + for (int32_T b_i{0}; b_i <= i - 2; b_i++) { + real_T d; + int32_T i1; + int32_T in; + in = (b_i + 1) * n; + alpha1 = a[(b_i + a.size(0) * b_i) + 1]; + unnamed_idx_0 = b_i + 3; + if (unnamed_idx_0 > n) { + unnamed_idx_0 = n; + } + + d = reflapack::xzlarfg((n - b_i) - 1, &alpha1, a, unnamed_idx_0 + + b_i * n); + tau[b_i] = d; + a[(b_i + a.size(0) * b_i) + 1] = 1.0; + unnamed_idx_0 = (n - b_i) - 1; + i1 = (b_i + b_i * n) + 2; + reflapack::b_xzlarf(n, unnamed_idx_0, i1, d, a, in + 1, n, work); + reflapack::c_xzlarf(unnamed_idx_0, unnamed_idx_0, i1, d, a, (b_i + + in) + 2, n, work); + a[(b_i + a.size(0) * b_i) + 1] = alpha1; + } + } + } + } + } +} + +// End of code generation (xgehrd.cpp) diff --git a/RAT/xgehrd.h b/RAT/xgehrd.h new file mode 100644 index 00000000..4303f942 --- /dev/null +++ b/RAT/xgehrd.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgehrd.h +// +// Code generation for function 'xgehrd' +// +#ifndef XGEHRD_H +#define XGEHRD_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace lapack + { + void xgehrd(::coder::array &a, ::coder::array + &tau); + } + } + } +} + +#endif + +// End of code generation (xgehrd.h) diff --git a/RAT/xgemm.cpp b/RAT/xgemm.cpp new file mode 100644 index 00000000..81e24dcd --- /dev/null +++ b/RAT/xgemm.cpp @@ -0,0 +1,84 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgemm.cpp +// +// Code generation for function 'xgemm' +// + +// Include files +#include "xgemm.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void xgemm(int32_T m, int32_T n, int32_T k, real_T alpha1, const ::coder:: + array &A, int32_T lda, const ::coder::array< + real_T, 2U> &B, int32_T ldb, ::coder::array &C, + int32_T ldc) + { + if ((m != 0) && (n != 0)) { + int32_T br; + int32_T i; + int32_T i1; + int32_T lastColC; + lastColC = ldc * (n - 1); + for (int32_T cr{0}; ldc < 0 ? cr >= lastColC : cr <= lastColC; cr += + ldc) { + i = cr + 1; + i1 = cr + m; + for (int32_T ic{i}; ic <= i1; ic++) { + C[ic - 1] = 0.0; + } + } + + br = -1; + for (int32_T cr{0}; ldc < 0 ? cr >= lastColC : cr <= lastColC; cr += + ldc) { + int32_T ar; + ar = -1; + i = cr + 1; + i1 = cr + m; + for (int32_T ic{i}; ic <= i1; ic++) { + real_T temp; + temp = 0.0; + for (int32_T w{0}; w < k; w++) { + temp += A[(w + ar) + 1] * B[(w + br) + 1]; + } + + C[ic - 1] = C[ic - 1] + alpha1 * temp; + ar += lda; + } + + br += ldb; + } + } + } + + real_T xgemm(int32_T k, real_T alpha1, const ::coder::array + &A, const ::coder::array &B) + { + real_T temp; + temp = 0.0; + for (int32_T w{0}; w < k; w++) { + temp += A[w] * B[w]; + } + + return alpha1 * temp; + } + } + } + } +} + +// End of code generation (xgemm.cpp) diff --git a/RAT/xgemm.h b/RAT/xgemm.h new file mode 100644 index 00000000..13a5cbce --- /dev/null +++ b/RAT/xgemm.h @@ -0,0 +1,41 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgemm.h +// +// Code generation for function 'xgemm' +// +#ifndef XGEMM_H +#define XGEMM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void xgemm(int32_T m, int32_T n, int32_T k, real_T alpha1, const ::coder:: + array &A, int32_T lda, const ::coder::array< + real_T, 2U> &B, int32_T ldb, ::coder::array &C, + int32_T ldc); + real_T xgemm(int32_T k, real_T alpha1, const ::coder::array + &A, const ::coder::array &B); + } + } + } +} + +#endif + +// End of code generation (xgemm.h) diff --git a/RAT/xgemv.cpp b/RAT/xgemv.cpp new file mode 100644 index 00000000..ebd8e6dc --- /dev/null +++ b/RAT/xgemv.cpp @@ -0,0 +1,125 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgemv.cpp +// +// Code generation for function 'xgemv' +// + +// Include files +#include "xgemv.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void b_xgemv(int32_T m, int32_T n, const ::coder::array &A, + int32_T ia0, int32_T lda, const ::coder::array + &x, int32_T ix0, ::coder::array &y) + { + if (m != 0) { + int32_T i; + int32_T ix; + for (ix = 0; ix < m; ix++) { + y[ix] = 0.0; + } + + ix = ix0; + i = ia0 + lda * (n - 1); + for (int32_T iac{ia0}; lda < 0 ? iac >= i : iac <= i; iac += lda) { + int32_T i1; + i1 = (iac + m) - 1; + for (int32_T ia{iac}; ia <= i1; ia++) { + int32_T i2; + i2 = ia - iac; + y[i2] = y[i2] + A[ia - 1] * x[ix - 1]; + } + + ix++; + } + } + } + + void c_xgemv(int32_T m, int32_T n, const ::coder::array &A, + int32_T ia0, int32_T lda, const ::coder::array + &x, int32_T ix0, ::coder::array &y) + { + ::coder::array b_y; + int32_T i; + int32_T loop_ub; + b_y.set_size(y.size(0)); + loop_ub = y.size(0); + for (i = 0; i < loop_ub; i++) { + b_y[i] = y[i]; + } + + if (n != 0) { + int32_T iy; + for (iy = 0; iy < n; iy++) { + b_y[iy] = 0.0; + } + + iy = 0; + i = ia0 + lda * (n - 1); + for (int32_T iac{ia0}; lda < 0 ? iac >= i : iac <= i; iac += lda) { + real_T c; + c = 0.0; + loop_ub = (iac + m) - 1; + for (int32_T ia{iac}; ia <= loop_ub; ia++) { + c += A[ia - 1] * x[((ix0 + ia) - iac) - 1]; + } + + b_y[iy] = b_y[iy] + c; + iy++; + } + } + + y.set_size(b_y.size(0)); + loop_ub = b_y.size(0); + for (i = 0; i < loop_ub; i++) { + y[i] = b_y[i]; + } + } + + void xgemv(int32_T m, int32_T n, const ::coder::array &A, + int32_T ia0, int32_T lda, const ::coder::array &x, + int32_T ix0, ::coder::array &y) + { + if (n != 0) { + int32_T i; + int32_T iy; + for (iy = 0; iy < n; iy++) { + y[iy] = 0.0; + } + + iy = 0; + i = ia0 + lda * (n - 1); + for (int32_T iac{ia0}; lda < 0 ? iac >= i : iac <= i; iac += lda) { + real_T c; + int32_T i1; + c = 0.0; + i1 = (iac + m) - 1; + for (int32_T ia{iac}; ia <= i1; ia++) { + c += A[ia - 1] * x[((ix0 + ia) - iac) - 1]; + } + + y[iy] = y[iy] + c; + iy++; + } + } + } + } + } + } +} + +// End of code generation (xgemv.cpp) diff --git a/RAT/xgemv.h b/RAT/xgemv.h new file mode 100644 index 00000000..c781e106 --- /dev/null +++ b/RAT/xgemv.h @@ -0,0 +1,44 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgemv.h +// +// Code generation for function 'xgemv' +// +#ifndef XGEMV_H +#define XGEMV_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void b_xgemv(int32_T m, int32_T n, const ::coder::array &A, + int32_T ia0, int32_T lda, const ::coder::array + &x, int32_T ix0, ::coder::array &y); + void c_xgemv(int32_T m, int32_T n, const ::coder::array &A, + int32_T ia0, int32_T lda, const ::coder::array + &x, int32_T ix0, ::coder::array &y); + void xgemv(int32_T m, int32_T n, const ::coder::array &A, + int32_T ia0, int32_T lda, const ::coder::array &x, + int32_T ix0, ::coder::array &y); + } + } + } +} + +#endif + +// End of code generation (xgemv.h) diff --git a/RAT/xgeqp3.cpp b/RAT/xgeqp3.cpp new file mode 100644 index 00000000..ea093131 --- /dev/null +++ b/RAT/xgeqp3.cpp @@ -0,0 +1,89 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgeqp3.cpp +// +// Code generation for function 'xgeqp3' +// + +// Include files +#include "xgeqp3.h" +#include "rt_nonfinite.h" +#include "xzgeqp3.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace lapack + { + void xgeqp3(::coder::array &A, ::coder::array + &tau, ::coder::array &jpvt) + { + int32_T k; + int32_T minmana; + int32_T n; + boolean_T guard1; + n = A.size(1) - 1; + k = A.size(0); + minmana = A.size(1); + if (k <= minmana) { + minmana = k; + } + + tau.set_size(minmana); + for (k = 0; k < minmana; k++) { + tau[k] = 0.0; + } + + guard1 = false; + if ((A.size(0) == 0) || (A.size(1) == 0)) { + guard1 = true; + } else { + k = A.size(0); + minmana = A.size(1); + if (k <= minmana) { + minmana = k; + } + + if (minmana < 1) { + guard1 = true; + } else { + minmana = A.size(1); + jpvt.set_size(1, minmana); + for (k = 0; k < minmana; k++) { + jpvt[k] = 0; + } + + for (k = 0; k <= n; k++) { + jpvt[k] = k + 1; + } + + reflapack::qrpf(A, A.size(0), A.size(1), tau, jpvt); + } + } + + if (guard1) { + minmana = A.size(1); + jpvt.set_size(1, minmana); + for (k = 0; k < minmana; k++) { + jpvt[k] = 0; + } + + for (minmana = 0; minmana <= n; minmana++) { + jpvt[minmana] = minmana + 1; + } + } + } + } + } + } +} + +// End of code generation (xgeqp3.cpp) diff --git a/RAT/xgeqp3.h b/RAT/xgeqp3.h new file mode 100644 index 00000000..be9d901c --- /dev/null +++ b/RAT/xgeqp3.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgeqp3.h +// +// Code generation for function 'xgeqp3' +// +#ifndef XGEQP3_H +#define XGEQP3_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace lapack + { + void xgeqp3(::coder::array &A, ::coder::array + &tau, ::coder::array &jpvt); + } + } + } +} + +#endif + +// End of code generation (xgeqp3.h) diff --git a/RAT/xgerc.cpp b/RAT/xgerc.cpp new file mode 100644 index 00000000..12da5e30 --- /dev/null +++ b/RAT/xgerc.cpp @@ -0,0 +1,76 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgerc.cpp +// +// Code generation for function 'xgerc' +// + +// Include files +#include "xgerc.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void xgerc(int32_T m, int32_T n, real_T alpha1, const ::coder::array< + real_T, 1U> &x, int32_T iy0, ::coder::array &A, + int32_T ia0, int32_T lda) + { + if (!(alpha1 == 0.0)) { + int32_T jA; + jA = ia0; + for (int32_T j{0}; j < n; j++) { + int32_T i; + i = (iy0 + j) - 1; + if (A[i] != 0.0) { + real_T temp; + temp = A[i] * alpha1; + i = m + jA; + for (int32_T ijA{jA}; ijA < i; ijA++) { + A[ijA - 1] = A[ijA - 1] + x[ijA - jA] * temp; + } + } + + jA += lda; + } + } + } + + void xgerc(int32_T m, int32_T n, real_T alpha1, int32_T ix0, const :: + coder::array &y, ::coder::array &A, + int32_T ia0, int32_T lda) + { + if (!(alpha1 == 0.0)) { + int32_T jA; + jA = ia0; + for (int32_T j{0}; j < n; j++) { + if (y[j] != 0.0) { + real_T temp; + int32_T i; + temp = y[j] * alpha1; + i = m + jA; + for (int32_T ijA{jA}; ijA < i; ijA++) { + A[ijA - 1] = A[ijA - 1] + A[((ix0 + ijA) - jA) - 1] * temp; + } + } + + jA += lda; + } + } + } + } + } + } +} + +// End of code generation (xgerc.cpp) diff --git a/RAT/xgerc.h b/RAT/xgerc.h new file mode 100644 index 00000000..5f9b904b --- /dev/null +++ b/RAT/xgerc.h @@ -0,0 +1,41 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgerc.h +// +// Code generation for function 'xgerc' +// +#ifndef XGERC_H +#define XGERC_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void xgerc(int32_T m, int32_T n, real_T alpha1, const ::coder::array< + real_T, 1U> &x, int32_T iy0, ::coder::array &A, + int32_T ia0, int32_T lda); + void xgerc(int32_T m, int32_T n, real_T alpha1, int32_T ix0, const :: + coder::array &y, ::coder::array &A, + int32_T ia0, int32_T lda); + } + } + } +} + +#endif + +// End of code generation (xgerc.h) diff --git a/RAT/xgeru.cpp b/RAT/xgeru.cpp new file mode 100644 index 00000000..1398374b --- /dev/null +++ b/RAT/xgeru.cpp @@ -0,0 +1,50 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgeru.cpp +// +// Code generation for function 'xgeru' +// + +// Include files +#include "xgeru.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void xgeru(int32_T m, int32_T n, int32_T ix0, int32_T iy0, int32_T incy, + ::coder::array &A, int32_T ia0, int32_T lda) + { + int32_T jA; + jA = ia0; + for (int32_T j{0}; j < n; j++) { + real_T yjy; + int32_T yjy_tmp; + yjy_tmp = (iy0 + j * incy) - 1; + yjy = A[yjy_tmp]; + if (A[yjy_tmp] != 0.0) { + yjy_tmp = m + jA; + for (int32_T ijA{jA}; ijA < yjy_tmp; ijA++) { + A[ijA - 1] = A[ijA - 1] + A[((ix0 + ijA) - jA) - 1] * -yjy; + } + } + + jA += lda; + } + } + } + } + } +} + +// End of code generation (xgeru.cpp) diff --git a/RAT/xgeru.h b/RAT/xgeru.h new file mode 100644 index 00000000..8e8addc6 --- /dev/null +++ b/RAT/xgeru.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgeru.h +// +// Code generation for function 'xgeru' +// +#ifndef XGERU_H +#define XGERU_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void xgeru(int32_T m, int32_T n, int32_T ix0, int32_T iy0, int32_T incy, + ::coder::array &A, int32_T ia0, int32_T lda); + } + } + } +} + +#endif + +// End of code generation (xgeru.h) diff --git a/RAT/xgetrf.cpp b/RAT/xgetrf.cpp new file mode 100644 index 00000000..17f0358c --- /dev/null +++ b/RAT/xgetrf.cpp @@ -0,0 +1,172 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgetrf.cpp +// +// Code generation for function 'xgetrf' +// + +// Include files +#include "xgetrf.h" +#include "colon.h" +#include "ixamax.h" +#include "rt_nonfinite.h" +#include "xgeru.h" +#include "xswap.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace lapack + { + void xgetrf(int32_T m, int32_T n, ::coder::array &A, int32_T + lda) + { + if ((m >= 1) && (n >= 1)) { + int32_T u0; + u0 = m - 1; + if (u0 > n) { + u0 = n; + } + + for (int32_T j{0}; j < u0; j++) { + int32_T b_tmp; + int32_T jp1j; + int32_T jpiv_offset; + int32_T mmj; + mmj = m - j; + b_tmp = j * (lda + 1); + jp1j = b_tmp + 2; + jpiv_offset = blas::ixamax(mmj, A, b_tmp + 1) - 1; + if (A[b_tmp + jpiv_offset] != 0.0) { + if (blas::ixamax(mmj, A, b_tmp + 1) - 1 != 0) { + blas::xswap(n, A, j + 1, lda, (j + jpiv_offset) + 1, lda); + } + + jpiv_offset = b_tmp + mmj; + for (int32_T i{jp1j}; i <= jpiv_offset; i++) { + A[i - 1] = A[i - 1] / A[b_tmp]; + } + } + + jpiv_offset = b_tmp + lda; + blas::xgeru(mmj - 1, (n - j) - 1, b_tmp + 2, jpiv_offset + 1, lda, + A, jpiv_offset + 2, lda); + } + } + } + + void xgetrf(int32_T m, int32_T n, ::coder::array &A, int32_T + lda, ::coder::array &ipiv) + { + int32_T y; + if (m <= n) { + y = m; + } else { + y = n; + } + + eml_integer_colon_dispatcher(y, ipiv); + if ((m >= 1) && (n >= 1)) { + int32_T u0; + u0 = m - 1; + if (u0 > n) { + u0 = n; + } + + for (int32_T j{0}; j < u0; j++) { + int32_T b_tmp; + int32_T jp1j; + int32_T jpiv_offset; + int32_T mmj; + mmj = m - j; + b_tmp = j * (lda + 1); + jp1j = b_tmp + 2; + y = blas::ixamax(mmj, A, b_tmp + 1); + jpiv_offset = blas::ixamax(mmj, A, b_tmp + 1); + if (A[(b_tmp + jpiv_offset) - 1] != 0.0) { + if (y - 1 != 0) { + ipiv[j] = j + y; + blas::xswap(n, A, j + 1, lda, j + jpiv_offset, lda); + } + + y = b_tmp + mmj; + for (jpiv_offset = jp1j; jpiv_offset <= y; jpiv_offset++) { + A[jpiv_offset - 1] = A[jpiv_offset - 1] / A[b_tmp]; + } + } + + y = b_tmp + lda; + blas::xgeru(mmj - 1, (n - j) - 1, b_tmp + 2, y + 1, lda, A, y + 2, + lda); + } + } + } + + void xgetrf(int32_T m, int32_T n, ::coder::array &A, int32_T + lda, ::coder::array &ipiv, int32_T *info) + { + int32_T y; + if (m <= n) { + y = m; + } else { + y = n; + } + + eml_integer_colon_dispatcher(y, ipiv); + *info = 0; + if ((m >= 1) && (n >= 1)) { + int32_T u0; + u0 = m - 1; + if (u0 > n) { + u0 = n; + } + + for (int32_T j{0}; j < u0; j++) { + int32_T b_tmp; + int32_T jp1j; + int32_T jpiv_offset; + int32_T mmj; + mmj = m - j; + b_tmp = j * (lda + 1); + jp1j = b_tmp + 2; + y = blas::ixamax(mmj, A, b_tmp + 1); + jpiv_offset = blas::ixamax(mmj, A, b_tmp + 1) - 1; + if (A[b_tmp + jpiv_offset] != 0.0) { + if (y - 1 != 0) { + ipiv[j] = j + y; + blas::xswap(n, A, j + 1, lda, (j + jpiv_offset) + 1, lda); + } + + y = b_tmp + mmj; + for (jpiv_offset = jp1j; jpiv_offset <= y; jpiv_offset++) { + A[jpiv_offset - 1] = A[jpiv_offset - 1] / A[b_tmp]; + } + } else { + *info = j + 1; + } + + y = b_tmp + lda; + blas::xgeru(mmj - 1, (n - j) - 1, b_tmp + 2, y + 1, lda, A, y + 2, + lda); + } + + if ((*info == 0) && (m <= n) && (!(A[(m + A.size(0) * (m - 1)) - 1] + != 0.0))) { + *info = m; + } + } + } + } + } + } +} + +// End of code generation (xgetrf.cpp) diff --git a/RAT/xgetrf.h b/RAT/xgetrf.h new file mode 100644 index 00000000..79d06dde --- /dev/null +++ b/RAT/xgetrf.h @@ -0,0 +1,41 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xgetrf.h +// +// Code generation for function 'xgetrf' +// +#ifndef XGETRF_H +#define XGETRF_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace lapack + { + void xgetrf(int32_T m, int32_T n, ::coder::array &A, int32_T + lda); + void xgetrf(int32_T m, int32_T n, ::coder::array &A, int32_T + lda, ::coder::array &ipiv); + void xgetrf(int32_T m, int32_T n, ::coder::array &A, int32_T + lda, ::coder::array &ipiv, int32_T *info); + } + } + } +} + +#endif + +// End of code generation (xgetrf.h) diff --git a/RAT/xnrm2.cpp b/RAT/xnrm2.cpp new file mode 100644 index 00000000..08777e8e --- /dev/null +++ b/RAT/xnrm2.cpp @@ -0,0 +1,235 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xnrm2.cpp +// +// Code generation for function 'xnrm2' +// + +// Include files +#include "xnrm2.h" +#include "RATMain_rtwutil.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + real_T b_xnrm2(int32_T n, const ::coder::array &x) + { + real_T y; + y = 0.0; + if (n >= 1) { + if (n == 1) { + y = std::abs(x[1]); + } else { + real_T scale; + int32_T kend; + scale = 3.3121686421112381E-170; + kend = n + 1; + for (int32_T k{2}; k <= kend; k++) { + real_T absxk; + absxk = std::abs(x[k - 1]); + if (absxk > scale) { + real_T t; + t = scale / absxk; + y = y * t * t + 1.0; + scale = absxk; + } else { + real_T t; + t = absxk / scale; + y += t * t; + } + } + + y = scale * std::sqrt(y); + } + } + + return y; + } + + real_T xnrm2(int32_T n, const ::coder::array &x) + { + real_T y; + y = 0.0; + if (n >= 1) { + if (n == 1) { + y = std::abs(x[0]); + } else { + real_T scale; + scale = 3.3121686421112381E-170; + for (int32_T k{0}; k < n; k++) { + real_T absxk; + absxk = std::abs(x[k]); + if (absxk > scale) { + real_T t; + t = scale / absxk; + y = y * t * t + 1.0; + scale = absxk; + } else { + real_T t; + t = absxk / scale; + y += t * t; + } + } + + y = scale * std::sqrt(y); + } + } + + return y; + } + + real_T xnrm2(int32_T n, const ::coder::array &x, int32_T + ix0) + { + real_T y; + y = 0.0; + if (n == 1) { + y = rt_hypotd_snf(x[ix0 - 1].re, x[ix0 - 1].im); + } else { + real_T scale; + int32_T kend; + scale = 3.3121686421112381E-170; + kend = (ix0 + n) - 1; + for (int32_T k{ix0}; k <= kend; k++) { + real_T absxk; + real_T t; + absxk = std::abs(x[k - 1].re); + if (absxk > scale) { + t = scale / absxk; + y = y * t * t + 1.0; + scale = absxk; + } else { + t = absxk / scale; + y += t * t; + } + + absxk = std::abs(x[k - 1].im); + if (absxk > scale) { + t = scale / absxk; + y = y * t * t + 1.0; + scale = absxk; + } else { + t = absxk / scale; + y += t * t; + } + } + + y = scale * std::sqrt(y); + } + + return y; + } + + real_T xnrm2(int32_T n, const ::coder::array &x, int32_T ix0) + { + real_T y; + y = 0.0; + if (n >= 1) { + if (n == 1) { + y = std::abs(x[ix0 - 1]); + } else { + real_T scale; + int32_T kend; + scale = 3.3121686421112381E-170; + kend = (ix0 + n) - 1; + for (int32_T k{ix0}; k <= kend; k++) { + real_T absxk; + absxk = std::abs(x[k - 1]); + if (absxk > scale) { + real_T t; + t = scale / absxk; + y = y * t * t + 1.0; + scale = absxk; + } else { + real_T t; + t = absxk / scale; + y += t * t; + } + } + + y = scale * std::sqrt(y); + } + } + + return y; + } + + real_T xnrm2(int32_T n, const real_T x[3]) + { + real_T y; + y = 0.0; + if (n >= 1) { + if (n == 1) { + y = std::abs(x[1]); + } else { + real_T absxk; + real_T scale; + real_T t; + scale = 3.3121686421112381E-170; + absxk = std::abs(x[1]); + if (absxk > 3.3121686421112381E-170) { + y = 1.0; + scale = absxk; + } else { + t = absxk / 3.3121686421112381E-170; + y = t * t; + } + + absxk = std::abs(x[2]); + if (absxk > scale) { + t = scale / absxk; + y = y * t * t + 1.0; + scale = absxk; + } else { + t = absxk / scale; + y += t * t; + } + + y = scale * std::sqrt(y); + } + } + + return y; + } + + real_T xnrm2(int32_T n, const ::coder::array &x) + { + real_T scale; + real_T y; + y = 0.0; + scale = 3.3121686421112381E-170; + for (int32_T k{0}; k < n; k++) { + real_T absxk; + absxk = std::abs(x[k]); + if (absxk > scale) { + real_T t; + t = scale / absxk; + y = y * t * t + 1.0; + scale = absxk; + } else { + real_T t; + t = absxk / scale; + y += t * t; + } + } + + return scale * std::sqrt(y); + } + } + } + } +} + +// End of code generation (xnrm2.cpp) diff --git a/RAT/xnrm2.h b/RAT/xnrm2.h new file mode 100644 index 00000000..054b891a --- /dev/null +++ b/RAT/xnrm2.h @@ -0,0 +1,42 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xnrm2.h +// +// Code generation for function 'xnrm2' +// +#ifndef XNRM2_H +#define XNRM2_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + real_T b_xnrm2(int32_T n, const ::coder::array &x); + real_T xnrm2(int32_T n, const ::coder::array &x); + real_T xnrm2(int32_T n, const ::coder::array &x, int32_T + ix0); + real_T xnrm2(int32_T n, const ::coder::array &x, int32_T ix0); + real_T xnrm2(int32_T n, const real_T x[3]); + real_T xnrm2(int32_T n, const ::coder::array &x); + } + } + } +} + +#endif + +// End of code generation (xnrm2.h) diff --git a/RAT/xrot.cpp b/RAT/xrot.cpp new file mode 100644 index 00000000..a468b02d --- /dev/null +++ b/RAT/xrot.cpp @@ -0,0 +1,63 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xrot.cpp +// +// Code generation for function 'xrot' +// + +// Include files +#include "xrot.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void xrot(int32_T n, ::coder::array &x, int32_T ix0, int32_T + incx, int32_T iy0, int32_T incy, real_T c, real_T s) + { + if (n >= 1) { + for (int32_T k{0}; k < n; k++) { + real_T temp; + int32_T b_temp_tmp; + int32_T temp_tmp; + temp_tmp = (iy0 + k * incx) - 1; + b_temp_tmp = (ix0 + k * incy) - 1; + temp = c * x[b_temp_tmp] + s * x[temp_tmp]; + x[temp_tmp] = c * x[temp_tmp] - s * x[b_temp_tmp]; + x[b_temp_tmp] = temp; + } + } + } + + void xrot(int32_T n, ::coder::array &x, int32_T ix0, int32_T + iy0, real_T c, real_T s) + { + if (n >= 1) { + for (int32_T k{0}; k < n; k++) { + real_T temp; + int32_T b_temp_tmp; + int32_T temp_tmp; + temp_tmp = (iy0 + k) - 1; + b_temp_tmp = (ix0 + k) - 1; + temp = c * x[b_temp_tmp] + s * x[temp_tmp]; + x[temp_tmp] = c * x[temp_tmp] - s * x[b_temp_tmp]; + x[b_temp_tmp] = temp; + } + } + } + } + } + } +} + +// End of code generation (xrot.cpp) diff --git a/RAT/xrot.h b/RAT/xrot.h new file mode 100644 index 00000000..65a233d0 --- /dev/null +++ b/RAT/xrot.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xrot.h +// +// Code generation for function 'xrot' +// +#ifndef XROT_H +#define XROT_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void xrot(int32_T n, ::coder::array &x, int32_T ix0, int32_T + incx, int32_T iy0, int32_T incy, real_T c, real_T s); + void xrot(int32_T n, ::coder::array &x, int32_T ix0, int32_T + iy0, real_T c, real_T s); + } + } + } +} + +#endif + +// End of code generation (xrot.h) diff --git a/RAT/xswap.cpp b/RAT/xswap.cpp new file mode 100644 index 00000000..3064ff68 --- /dev/null +++ b/RAT/xswap.cpp @@ -0,0 +1,59 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xswap.cpp +// +// Code generation for function 'xswap' +// + +// Include files +#include "xswap.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void xswap(int32_T n, ::coder::array &x, int32_T ix0, + int32_T iy0) + { + for (int32_T k{0}; k < n; k++) { + real_T temp; + int32_T i; + int32_T temp_tmp; + temp_tmp = (ix0 + k) - 1; + temp = x[temp_tmp]; + i = (iy0 + k) - 1; + x[temp_tmp] = x[i]; + x[i] = temp; + } + } + + void xswap(int32_T n, ::coder::array &x, int32_T ix0, + int32_T incx, int32_T iy0, int32_T incy) + { + for (int32_T k{0}; k < n; k++) { + real_T temp; + int32_T i; + int32_T temp_tmp; + temp_tmp = (ix0 + k * incx) - 1; + temp = x[temp_tmp]; + i = (iy0 + k * incy) - 1; + x[temp_tmp] = x[i]; + x[i] = temp; + } + } + } + } + } +} + +// End of code generation (xswap.cpp) diff --git a/RAT/xswap.h b/RAT/xswap.h new file mode 100644 index 00000000..d63fe545 --- /dev/null +++ b/RAT/xswap.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xswap.h +// +// Code generation for function 'xswap' +// +#ifndef XSWAP_H +#define XSWAP_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void xswap(int32_T n, ::coder::array &x, int32_T ix0, + int32_T iy0); + void xswap(int32_T n, ::coder::array &x, int32_T ix0, + int32_T incx, int32_T iy0, int32_T incy); + } + } + } +} + +#endif + +// End of code generation (xswap.h) diff --git a/RAT/xtrsm.cpp b/RAT/xtrsm.cpp new file mode 100644 index 00000000..05d348aa --- /dev/null +++ b/RAT/xtrsm.cpp @@ -0,0 +1,89 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xtrsm.cpp +// +// Code generation for function 'xtrsm' +// + +// Include files +#include "xtrsm.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void b_xtrsm(int32_T m, int32_T n, const ::coder::array &A, + int32_T lda, ::coder::array &B, int32_T ldb) + { + if ((n != 0) && ((B.size(0) != 0) && (B.size(1) != 0))) { + for (int32_T j{n}; j >= 1; j--) { + int32_T i; + int32_T jAcol; + int32_T jBcol; + jBcol = ldb * (j - 1); + jAcol = lda * (j - 1) - 1; + i = j + 1; + for (int32_T k{i}; k <= n; k++) { + int32_T i1; + int32_T kBcol; + kBcol = ldb * (k - 1); + i1 = k + jAcol; + if (A[i1] != 0.0) { + int32_T i2; + i2 = static_cast(m); + for (int32_T b_i{0}; b_i < i2; b_i++) { + B[jBcol] = B[jBcol] - A[i1] * B[kBcol]; + } + } + } + } + } + } + + void xtrsm(int32_T m, int32_T n, const ::coder::array &A, + int32_T lda, ::coder::array &B, int32_T ldb) + { + if ((n != 0) && ((B.size(0) != 0) && (B.size(1) != 0))) { + int32_T i; + i = static_cast(m); + for (int32_T j{0}; j < n; j++) { + real_T temp; + int32_T jAcol; + int32_T jBcol; + jBcol = ldb * j; + jAcol = lda * j; + for (int32_T k{0}; k < j; k++) { + int32_T i1; + int32_T kBcol; + kBcol = ldb * k; + i1 = k + jAcol; + if (A[i1] != 0.0) { + for (int32_T b_i{0}; b_i < i; b_i++) { + B[jBcol] = B[jBcol] - A[i1] * B[kBcol]; + } + } + } + + temp = 1.0 / A[j + jAcol]; + for (int32_T b_i{0}; b_i < i; b_i++) { + B[jBcol] = temp * B[jBcol]; + } + } + } + } + } + } + } +} + +// End of code generation (xtrsm.cpp) diff --git a/RAT/xtrsm.h b/RAT/xtrsm.h new file mode 100644 index 00000000..b05294b1 --- /dev/null +++ b/RAT/xtrsm.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xtrsm.h +// +// Code generation for function 'xtrsm' +// +#ifndef XTRSM_H +#define XTRSM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void b_xtrsm(int32_T m, int32_T n, const ::coder::array &A, + int32_T lda, ::coder::array &B, int32_T ldb); + void xtrsm(int32_T m, int32_T n, const ::coder::array &A, + int32_T lda, ::coder::array &B, int32_T ldb); + } + } + } +} + +#endif + +// End of code generation (xtrsm.h) diff --git a/RAT/xtrsv.cpp b/RAT/xtrsv.cpp new file mode 100644 index 00000000..ed4e49b1 --- /dev/null +++ b/RAT/xtrsv.cpp @@ -0,0 +1,102 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xtrsv.cpp +// +// Code generation for function 'xtrsv' +// + +// Include files +#include "xtrsv.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void b_xtrsv(int32_T n, const ::coder::array &A, int32_T lda, + ::coder::array &x) + { + if ((A.size(0) != 0) && (A.size(1) != 0)) { + for (int32_T j{n}; j >= 1; j--) { + int32_T jjA; + jjA = (j + (j - 1) * lda) - 1; + x[j - 1] = x[j - 1] / A[jjA]; + for (int32_T i{0}; i <= j - 2; i++) { + int32_T ix; + ix = (j - i) - 2; + x[ix] = x[ix] - x[j - 1] * A[(jjA - i) - 1]; + } + } + } + } + + void c_xtrsv(int32_T n, const ::coder::array &A, int32_T lda, + ::coder::array &x) + { + if ((A.size(0) != 0) && (A.size(1) != 0)) { + for (int32_T j{0}; j < n; j++) { + real_T temp; + int32_T jA; + jA = j * lda; + temp = x[j]; + for (int32_T i{0}; i < j; i++) { + temp -= A[jA + i] * x[i]; + } + + x[j] = temp / A[jA + j]; + } + } + } + + void d_xtrsv(int32_T n, const ::coder::array &A, int32_T lda, + ::coder::array &x) + { + if ((A.size(0) != 0) && (A.size(1) != 0)) { + for (int32_T j{n}; j >= 1; j--) { + real_T temp; + int32_T i; + int32_T jA; + jA = (j - 1) * lda; + temp = x[j - 1]; + i = j + 1; + for (int32_T b_i{n}; b_i >= i; b_i--) { + temp -= A[(jA + b_i) - 1] * x[b_i - 1]; + } + + x[j - 1] = temp; + } + } + } + + void xtrsv(int32_T n, const ::coder::array &A, int32_T lda, :: + coder::array &x) + { + if ((A.size(0) != 0) && (A.size(1) != 0)) { + for (int32_T j{0}; j < n; j++) { + int32_T i; + int32_T jjA; + jjA = j + j * lda; + i = n - j; + for (int32_T b_i{0}; b_i <= i - 2; b_i++) { + int32_T ix; + ix = (j + b_i) + 1; + x[ix] = x[ix] - x[j] * A[(jjA + b_i) + 1]; + } + } + } + } + } + } + } +} + +// End of code generation (xtrsv.cpp) diff --git a/RAT/xtrsv.h b/RAT/xtrsv.h new file mode 100644 index 00000000..f63320e8 --- /dev/null +++ b/RAT/xtrsv.h @@ -0,0 +1,43 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xtrsv.h +// +// Code generation for function 'xtrsv' +// +#ifndef XTRSV_H +#define XTRSV_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace blas + { + void b_xtrsv(int32_T n, const ::coder::array &A, int32_T lda, + ::coder::array &x); + void c_xtrsv(int32_T n, const ::coder::array &A, int32_T lda, + ::coder::array &x); + void d_xtrsv(int32_T n, const ::coder::array &A, int32_T lda, + ::coder::array &x); + void xtrsv(int32_T n, const ::coder::array &A, int32_T lda, :: + coder::array &x); + } + } + } +} + +#endif + +// End of code generation (xtrsv.h) diff --git a/RAT/xungorghr.cpp b/RAT/xungorghr.cpp new file mode 100644 index 00000000..d00065fc --- /dev/null +++ b/RAT/xungorghr.cpp @@ -0,0 +1,74 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xungorghr.cpp +// +// Code generation for function 'xungorghr' +// + +// Include files +#include "xungorghr.h" +#include "rt_nonfinite.h" +#include "xzungqr.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace lapack + { + void xungorghr(int32_T n, int32_T ihi, ::coder::array &A, + int32_T lda, const ::coder::array &tau) + { + if (n != 0) { + int32_T b_i; + int32_T ia; + for (int32_T j{ihi}; j >= 2; j--) { + int32_T iajm1; + ia = (j - 1) * lda - 1; + for (int32_T i{0}; i <= j - 2; i++) { + A[(ia + i) + 1] = 0.0; + } + + iajm1 = ia - lda; + b_i = j + 1; + for (int32_T i{b_i}; i <= ihi; i++) { + A[ia + i] = A[iajm1 + i]; + } + + b_i = ihi + 1; + for (int32_T i{b_i}; i <= n; i++) { + A[ia + i] = 0.0; + } + } + + for (int32_T i{0}; i < n; i++) { + A[i] = 0.0; + } + + A[0] = 1.0; + b_i = ihi + 1; + for (int32_T j{b_i}; j <= n; j++) { + ia = (j - 1) * lda; + for (int32_T i{0}; i < n; i++) { + A[ia + i] = 0.0; + } + + A[(ia + j) - 1] = 1.0; + } + + reflapack::xzungqr(ihi - 1, ihi - 1, ihi - 1, A, lda + 2, lda, tau); + } + } + } + } + } +} + +// End of code generation (xungorghr.cpp) diff --git a/RAT/xungorghr.h b/RAT/xungorghr.h new file mode 100644 index 00000000..687d951b --- /dev/null +++ b/RAT/xungorghr.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xungorghr.h +// +// Code generation for function 'xungorghr' +// +#ifndef XUNGORGHR_H +#define XUNGORGHR_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace lapack + { + void xungorghr(int32_T n, int32_T ihi, ::coder::array &A, + int32_T lda, const ::coder::array &tau); + } + } + } +} + +#endif + +// End of code generation (xungorghr.h) diff --git a/RAT/xunormqr.cpp b/RAT/xunormqr.cpp new file mode 100644 index 00000000..f986b78a --- /dev/null +++ b/RAT/xunormqr.cpp @@ -0,0 +1,102 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xunormqr.cpp +// +// Code generation for function 'xunormqr' +// + +// Include files +#include "xunormqr.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace lapack + { + void xunormqr(const ::coder::array &Q, ::coder::array &C, const ::coder::array &tau) + { + int32_T m; + int32_T mn; + int32_T nb; + int32_T u0; + m = Q.size(0); + nb = C.size(1); + u0 = Q.size(0); + mn = Q.size(1); + if (u0 <= mn) { + mn = u0; + } + + for (int32_T j{0}; j < mn; j++) { + if (tau[j] != 0.0) { + for (int32_T k{0}; k < nb; k++) { + real_T wj; + wj = C[j]; + u0 = j + 2; + for (int32_T i{u0}; i <= m; i++) { + wj += Q[(i + Q.size(0) * j) - 1] * C[i - 1]; + } + + wj *= tau[j]; + if (wj != 0.0) { + C[j] = C[j] - wj; + for (int32_T i{u0}; i <= m; i++) { + C[i - 1] = C[i - 1] - Q[(i + Q.size(0) * j) - 1] * wj; + } + } + } + } + } + } + + void xunormqr(const ::coder::array &Q, ::coder::array &C, const real_T tau_data[]) + { + int32_T i; + int32_T m; + int32_T nb; + m = Q.size(0); + nb = C.size(1); + if (Q.size(0) < 1) { + i = -1; + } else { + i = 0; + } + + for (int32_T j{0}; j <= i; j++) { + if (tau_data[0] != 0.0) { + for (int32_T k{0}; k < nb; k++) { + real_T wj; + wj = C[C.size(0) * k]; + for (int32_T b_i{2}; b_i <= m; b_i++) { + wj += Q[b_i - 1] * C[(b_i + C.size(0) * k) - 1]; + } + + wj *= tau_data[0]; + if (wj != 0.0) { + C[C.size(0) * k] = C[C.size(0) * k] - wj; + for (int32_T b_i{2}; b_i <= m; b_i++) { + C[(b_i + C.size(0) * k) - 1] = C[(b_i + C.size(0) * k) - 1] + - Q[b_i - 1] * wj; + } + } + } + } + } + } + } + } + } +} + +// End of code generation (xunormqr.cpp) diff --git a/RAT/xunormqr.h b/RAT/xunormqr.h new file mode 100644 index 00000000..340e1313 --- /dev/null +++ b/RAT/xunormqr.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xunormqr.h +// +// Code generation for function 'xunormqr' +// +#ifndef XUNORMQR_H +#define XUNORMQR_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace lapack + { + void xunormqr(const ::coder::array &Q, ::coder::array &C, const ::coder::array &tau); + void xunormqr(const ::coder::array &Q, ::coder::array &C, const real_T tau_data[]); + } + } + } +} + +#endif + +// End of code generation (xunormqr.h) diff --git a/RAT/xzgeev.cpp b/RAT/xzgeev.cpp new file mode 100644 index 00000000..4fda97f3 --- /dev/null +++ b/RAT/xzgeev.cpp @@ -0,0 +1,83 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzgeev.cpp +// +// Code generation for function 'xzgeev' +// + +// Include files +#include "xzgeev.h" +#include "RATMain_data.h" +#include "rt_nonfinite.h" +#include "xnrm2.h" +#include "xzggev.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzgeev(const ::coder::array &A, int32_T *info, ::coder:: + array &alpha1, ::coder::array + &beta1, ::coder::array &V) + { + ::coder::array At; + int32_T i; + int32_T lastcol; + int32_T n; + At.set_size(A.size(0), A.size(1)); + n = A.size(1); + for (i = 0; i < n; i++) { + lastcol = A.size(0); + for (int32_T coltop{0}; coltop < lastcol; coltop++) { + At[coltop + At.size(0) * i].re = A[coltop + A.size(0) * i]; + At[coltop + At.size(0) * i].im = 0.0; + } + } + + xzggev(At, info, alpha1, beta1, V); + n = A.size(0); + if (A.size(0) > 0) { + lastcol = (A.size(0) - 1) * A.size(0) + 1; + for (int32_T coltop{1}; n < 0 ? coltop >= lastcol : coltop <= + lastcol; coltop += n) { + real_T colnorm; + colnorm = blas::xnrm2(n, V, coltop); + i = (coltop + n) - 1; + for (int32_T j{coltop}; j <= i; j++) { + real_T ai; + real_T im; + real_T re; + im = V[j - 1].re; + ai = V[j - 1].im; + if (ai == 0.0) { + re = im / colnorm; + im = 0.0; + } else if (im == 0.0) { + re = 0.0; + im = ai / colnorm; + } else { + re = im / colnorm; + im = ai / colnorm; + } + + V[j - 1].re = re; + V[j - 1].im = im; + } + } + } + } + } + } + } +} + +// End of code generation (xzgeev.cpp) diff --git a/RAT/xzgeev.h b/RAT/xzgeev.h new file mode 100644 index 00000000..8e4fdee0 --- /dev/null +++ b/RAT/xzgeev.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzgeev.h +// +// Code generation for function 'xzgeev' +// +#ifndef XZGEEV_H +#define XZGEEV_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzgeev(const ::coder::array &A, int32_T *info, ::coder:: + array &alpha1, ::coder::array + &beta1, ::coder::array &V); + } + } + } +} + +#endif + +// End of code generation (xzgeev.h) diff --git a/RAT/xzgeqp3.cpp b/RAT/xzgeqp3.cpp new file mode 100644 index 00000000..363ddca7 --- /dev/null +++ b/RAT/xzgeqp3.cpp @@ -0,0 +1,220 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzgeqp3.cpp +// +// Code generation for function 'xzgeqp3' +// + +// Include files +#include "xzgeqp3.h" +#include "ixamax.h" +#include "rt_nonfinite.h" +#include "xnrm2.h" +#include "xswap.h" +#include "xzlarf.h" +#include "xzlarfg.h" +#include "coder_array.h" +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + static int32_T qrpf(::coder::array &A, int32_T m, real_T + tau_data[]); + } + } + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + static int32_T qrpf(::coder::array &A, int32_T m, real_T + tau_data[]) + { + real_T atmp; + int32_T jpvt; + int32_T y; + jpvt = 1; + if (m <= 1) { + y = m; + } else { + y = 1; + } + + y = static_cast(y); + for (int32_T i{0}; i < y; i++) { + if (m > 1) { + atmp = A[0]; + tau_data[0] = xzlarfg(m, &atmp, A); + A[0] = atmp; + } else { + tau_data[0] = 0.0; + } + } + + return jpvt; + } + + void qrpf(::coder::array &A, int32_T m, int32_T n, ::coder:: + array &tau, ::coder::array &jpvt) + { + ::coder::array vn1; + ::coder::array vn2; + ::coder::array work; + real_T d; + real_T temp1; + int32_T itemp; + int32_T j; + int32_T ma; + int32_T minmn; + ma = A.size(0); + if (m <= n) { + minmn = m; + } else { + minmn = n; + } + + itemp = A.size(1); + work.set_size(itemp); + for (j = 0; j < itemp; j++) { + work[j] = 0.0; + } + + itemp = A.size(1); + vn1.set_size(itemp); + for (j = 0; j < itemp; j++) { + vn1[j] = 0.0; + } + + itemp = A.size(1); + vn2.set_size(itemp); + for (j = 0; j < itemp; j++) { + vn2[j] = 0.0; + } + + for (j = 0; j < n; j++) { + d = blas::xnrm2(m, A, j * ma + 1); + vn1[j] = d; + vn2[j] = d; + } + + for (int32_T i{0}; i < minmn; i++) { + int32_T ii; + int32_T ip1; + int32_T mmi; + int32_T nmi; + int32_T pvt; + ip1 = i + 2; + j = i * ma; + ii = j + i; + nmi = n - i; + mmi = m - i; + pvt = (i + blas::ixamax(nmi, vn1, i + 1)) - 1; + if (pvt + 1 != i + 1) { + blas::xswap(m, A, pvt * ma + 1, j + 1); + itemp = jpvt[pvt]; + jpvt[pvt] = jpvt[i]; + jpvt[i] = itemp; + vn1[pvt] = vn1[i]; + vn2[pvt] = vn2[i]; + } + + if (i + 1 < m) { + temp1 = A[ii]; + d = xzlarfg(mmi, &temp1, A, ii + 2); + tau[i] = d; + A[ii] = temp1; + } else { + d = 0.0; + tau[i] = 0.0; + } + + if (i + 1 < n) { + temp1 = A[ii]; + A[ii] = 1.0; + xzlarf(mmi, nmi - 1, ii + 1, d, A, (ii + ma) + 1, ma, work); + A[ii] = temp1; + } + + for (j = ip1; j <= n; j++) { + itemp = i + (j - 1) * ma; + d = vn1[j - 1]; + if (d != 0.0) { + real_T temp2; + temp1 = std::abs(A[itemp]) / d; + temp1 = 1.0 - temp1 * temp1; + if (temp1 < 0.0) { + temp1 = 0.0; + } + + temp2 = d / vn2[j - 1]; + temp2 = temp1 * (temp2 * temp2); + if (temp2 <= 1.4901161193847656E-8) { + if (i + 1 < m) { + d = blas::xnrm2(mmi - 1, A, itemp + 2); + vn1[j - 1] = d; + vn2[j - 1] = d; + } else { + vn1[j - 1] = 0.0; + vn2[j - 1] = 0.0; + } + } else { + vn1[j - 1] = d * std::sqrt(temp1); + } + } + } + } + } + + void xzgeqp3(::coder::array &A, int32_T m, real_T tau_data[], + int32_T *tau_size, int32_T *jpvt) + { + *tau_size = A.size(0); + if (*tau_size > 1) { + *tau_size = 1; + } + + if (*tau_size - 1 >= 0) { + tau_data[0] = 0.0; + } + + if (A.size(0) == 0) { + *jpvt = 1; + } else { + int32_T y; + if (m <= 1) { + y = m; + } else { + y = 1; + } + + if (y < 1) { + *jpvt = 1; + } else { + qrpf(A, m, tau_data); + *jpvt = 1; + } + } + } + } + } + } +} + +// End of code generation (xzgeqp3.cpp) diff --git a/RAT/xzgeqp3.h b/RAT/xzgeqp3.h new file mode 100644 index 00000000..aad7bd63 --- /dev/null +++ b/RAT/xzgeqp3.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzgeqp3.h +// +// Code generation for function 'xzgeqp3' +// +#ifndef XZGEQP3_H +#define XZGEQP3_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void qrpf(::coder::array &A, int32_T m, int32_T n, ::coder:: + array &tau, ::coder::array &jpvt); + void xzgeqp3(::coder::array &A, int32_T m, real_T tau_data[], + int32_T *tau_size, int32_T *jpvt); + } + } + } +} + +#endif + +// End of code generation (xzgeqp3.h) diff --git a/RAT/xzggbak.cpp b/RAT/xzggbak.cpp new file mode 100644 index 00000000..f8825d9b --- /dev/null +++ b/RAT/xzggbak.cpp @@ -0,0 +1,72 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzggbak.cpp +// +// Code generation for function 'xzggbak' +// + +// Include files +#include "xzggbak.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzggbak(::coder::array &V, int32_T ilo, int32_T ihi, + const ::coder::array &rscale) + { + real_T tmp_im; + real_T tmp_re; + int32_T k; + int32_T m; + int32_T n; + n = V.size(0); + m = V.size(1) - 1; + if (ilo > 1) { + for (int32_T i{ilo - 2}; i + 1 >= 1; i--) { + k = rscale[i] - 1; + if (rscale[i] != i + 1) { + for (int32_T j{0}; j <= m; j++) { + tmp_re = V[i + V.size(0) * j].re; + tmp_im = V[i + V.size(0) * j].im; + V[i + V.size(0) * j] = V[k + V.size(0) * j]; + V[k + V.size(0) * j].re = tmp_re; + V[k + V.size(0) * j].im = tmp_im; + } + } + } + } + + if (ihi < V.size(0)) { + k = ihi + 1; + for (int32_T i{k}; i <= n; i++) { + int32_T b_i; + b_i = rscale[i - 1]; + if (b_i != i) { + for (int32_T j{0}; j <= m; j++) { + tmp_re = V[(i + V.size(0) * j) - 1].re; + tmp_im = V[(i + V.size(0) * j) - 1].im; + V[(i + V.size(0) * j) - 1] = V[(b_i + V.size(0) * j) - 1]; + V[(b_i + V.size(0) * j) - 1].re = tmp_re; + V[(b_i + V.size(0) * j) - 1].im = tmp_im; + } + } + } + } + } + } + } + } +} + +// End of code generation (xzggbak.cpp) diff --git a/RAT/xzggbak.h b/RAT/xzggbak.h new file mode 100644 index 00000000..db7f8a4d --- /dev/null +++ b/RAT/xzggbak.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzggbak.h +// +// Code generation for function 'xzggbak' +// +#ifndef XZGGBAK_H +#define XZGGBAK_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzggbak(::coder::array &V, int32_T ilo, int32_T ihi, + const ::coder::array &rscale); + } + } + } +} + +#endif + +// End of code generation (xzggbak.h) diff --git a/RAT/xzggbal.cpp b/RAT/xzggbal.cpp new file mode 100644 index 00000000..0c1338c1 --- /dev/null +++ b/RAT/xzggbal.cpp @@ -0,0 +1,202 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzggbal.cpp +// +// Code generation for function 'xzggbal' +// + +// Include files +#include "xzggbal.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzggbal(::coder::array &A, int32_T *ilo, int32_T *ihi, + ::coder::array &rscale) + { + int32_T ii; + int32_T nzcount; + nzcount = A.size(0); + rscale.set_size(nzcount); + for (ii = 0; ii < nzcount; ii++) { + rscale[ii] = 1; + } + + *ilo = 1; + *ihi = A.size(0); + if (A.size(0) <= 1) { + *ihi = 1; + } else { + real_T atmp_im; + real_T atmp_re; + int32_T exitg2; + int32_T i; + int32_T j; + int32_T jj; + boolean_T exitg3; + boolean_T exitg4; + boolean_T found; + do { + exitg2 = 0; + i = 0; + j = 0; + found = false; + ii = *ihi; + exitg3 = false; + while ((!exitg3) && (ii > 0)) { + nzcount = 0; + i = ii; + j = *ihi; + jj = 0; + exitg4 = false; + while ((!exitg4) && (jj <= *ihi - 1)) { + if ((A[(ii + A.size(0) * jj) - 1].re != 0.0) || (A[(ii + + A.size(0) * jj) - 1].im != 0.0) || (ii == jj + 1)) { + if (nzcount == 0) { + j = jj + 1; + nzcount = 1; + jj++; + } else { + nzcount = 2; + exitg4 = true; + } + } else { + jj++; + } + } + + if (nzcount < 2) { + found = true; + exitg3 = true; + } else { + ii--; + } + } + + if (!found) { + exitg2 = 2; + } else { + nzcount = A.size(0); + if (i != *ihi) { + for (ii = 1; ii <= nzcount; ii++) { + atmp_re = A[(i + A.size(0) * (ii - 1)) - 1].re; + atmp_im = A[(i + A.size(0) * (ii - 1)) - 1].im; + A[(i + A.size(0) * (ii - 1)) - 1] = A[(*ihi + A.size(0) * + (ii - 1)) - 1]; + A[(*ihi + A.size(0) * (ii - 1)) - 1].re = atmp_re; + A[(*ihi + A.size(0) * (ii - 1)) - 1].im = atmp_im; + } + } + + if (j != *ihi) { + for (ii = 0; ii < *ihi; ii++) { + atmp_re = A[ii + A.size(0) * (j - 1)].re; + atmp_im = A[ii + A.size(0) * (j - 1)].im; + A[ii + A.size(0) * (j - 1)] = A[ii + A.size(0) * (*ihi - 1)]; + A[ii + A.size(0) * (*ihi - 1)].re = atmp_re; + A[ii + A.size(0) * (*ihi - 1)].im = atmp_im; + } + } + + rscale[*ihi - 1] = j; + (*ihi)--; + if (*ihi == 1) { + rscale[0] = 1; + exitg2 = 1; + } + } + } while (exitg2 == 0); + + if (exitg2 != 1) { + int32_T exitg1; + do { + exitg1 = 0; + i = 0; + j = 0; + found = false; + jj = *ilo; + exitg3 = false; + while ((!exitg3) && (jj <= *ihi)) { + nzcount = 0; + i = *ihi; + j = jj; + ii = *ilo; + exitg4 = false; + while ((!exitg4) && (ii <= *ihi)) { + if ((A[(ii + A.size(0) * (jj - 1)) - 1].re != 0.0) || (A[(ii + + A.size(0) * (jj - 1)) - 1].im != 0.0) || (ii == jj)) + { + if (nzcount == 0) { + i = ii; + nzcount = 1; + ii++; + } else { + nzcount = 2; + exitg4 = true; + } + } else { + ii++; + } + } + + if (nzcount < 2) { + found = true; + exitg3 = true; + } else { + jj++; + } + } + + if (!found) { + exitg1 = 1; + } else { + nzcount = A.size(0); + if (i != *ilo) { + for (ii = *ilo; ii <= nzcount; ii++) { + atmp_re = A[(i + A.size(0) * (ii - 1)) - 1].re; + atmp_im = A[(i + A.size(0) * (ii - 1)) - 1].im; + A[(i + A.size(0) * (ii - 1)) - 1] = A[(*ilo + A.size(0) * + (ii - 1)) - 1]; + A[(*ilo + A.size(0) * (ii - 1)) - 1].re = atmp_re; + A[(*ilo + A.size(0) * (ii - 1)) - 1].im = atmp_im; + } + } + + if (j != *ilo) { + for (ii = 0; ii < *ihi; ii++) { + atmp_re = A[ii + A.size(0) * (j - 1)].re; + atmp_im = A[ii + A.size(0) * (j - 1)].im; + A[ii + A.size(0) * (j - 1)] = A[ii + A.size(0) * (*ilo - 1)]; + A[ii + A.size(0) * (*ilo - 1)].re = atmp_re; + A[ii + A.size(0) * (*ilo - 1)].im = atmp_im; + } + } + + rscale[*ilo - 1] = j; + (*ilo)++; + if (*ilo == *ihi) { + rscale[*ilo - 1] = *ilo; + exitg1 = 1; + } + } + } while (exitg1 == 0); + } + } + } + } + } + } +} + +// End of code generation (xzggbal.cpp) diff --git a/RAT/xzggbal.h b/RAT/xzggbal.h new file mode 100644 index 00000000..75b9ae89 --- /dev/null +++ b/RAT/xzggbal.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzggbal.h +// +// Code generation for function 'xzggbal' +// +#ifndef XZGGBAL_H +#define XZGGBAL_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzggbal(::coder::array &A, int32_T *ilo, int32_T *ihi, + ::coder::array &rscale); + } + } + } +} + +#endif + +// End of code generation (xzggbal.h) diff --git a/RAT/xzggev.cpp b/RAT/xzggev.cpp new file mode 100644 index 00000000..cb15c0de --- /dev/null +++ b/RAT/xzggev.cpp @@ -0,0 +1,153 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzggev.cpp +// +// Code generation for function 'xzggev' +// + +// Include files +#include "xzggev.h" +#include "rt_nonfinite.h" +#include "xzggbak.h" +#include "xzggbal.h" +#include "xzgghrd.h" +#include "xzhgeqz.h" +#include "xzlangeM.h" +#include "xzlascl.h" +#include "xztgevc.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzggev(::coder::array &A, int32_T *info, ::coder:: + array &alpha1, ::coder::array + &beta1, ::coder::array &V) + { + ::coder::array rscale; + int32_T ihi; + int32_T ilo; + int32_T n; + *info = 0; + n = A.size(0) - 1; + ilo = A.size(0); + alpha1.set_size(ilo); + for (int32_T i{0}; i < ilo; i++) { + alpha1[i].re = 0.0; + alpha1[i].im = 0.0; + } + + ilo = A.size(0); + beta1.set_size(ilo); + for (int32_T i{0}; i < ilo; i++) { + beta1[i].re = 0.0; + beta1[i].im = 0.0; + } + + ilo = A.size(0); + ihi = A.size(0); + V.set_size(ilo, ihi); + for (int32_T i{0}; i < ihi; i++) { + for (int32_T i1{0}; i1 < ilo; i1++) { + V[i1 + V.size(0) * i].re = 0.0; + V[i1 + V.size(0) * i].im = 0.0; + } + } + + if ((A.size(0) != 0) && (A.size(1) != 0)) { + real_T anrm; + anrm = xzlangeM(A); + if (std::isinf(anrm) || std::isnan(anrm)) { + ilo = A.size(0); + alpha1.set_size(ilo); + for (int32_T i{0}; i < ilo; i++) { + alpha1[i].re = rtNaN; + alpha1[i].im = 0.0; + } + + ilo = A.size(0); + beta1.set_size(ilo); + for (int32_T i{0}; i < ilo; i++) { + beta1[i].re = rtNaN; + beta1[i].im = 0.0; + } + + ilo = A.size(0); + ihi = A.size(0); + V.set_size(ilo, ihi); + for (int32_T i{0}; i < ihi; i++) { + for (int32_T i1{0}; i1 < ilo; i1++) { + V[i1 + V.size(0) * i].re = rtNaN; + V[i1 + V.size(0) * i].im = 0.0; + } + } + } else { + real_T anrmto; + boolean_T ilascl; + ilascl = false; + anrmto = anrm; + if ((anrm > 0.0) && (anrm < 6.7178761075670888E-139)) { + anrmto = 6.7178761075670888E-139; + ilascl = true; + xzlascl(anrm, anrmto, A); + } else if (anrm > 1.4885657073574029E+138) { + anrmto = 1.4885657073574029E+138; + ilascl = true; + xzlascl(anrm, anrmto, A); + } + + xzggbal(A, &ilo, &ihi, rscale); + xzgghrd(ilo, ihi, A, V); + xzhgeqz(A, ilo, ihi, V, info, alpha1, beta1); + if (*info == 0) { + xztgevc(A, V); + xzggbak(V, ilo, ihi, rscale); + for (ilo = 0; ilo <= n; ilo++) { + real_T vtemp; + vtemp = std::abs(V[V.size(0) * ilo].re) + std::abs(V[V.size(0) + * ilo].im); + if (n + 1 > 1) { + for (ihi = 0; ihi < n; ihi++) { + real_T y; + y = std::abs(V[(ihi + V.size(0) * ilo) + 1].re) + std::abs + (V[(ihi + V.size(0) * ilo) + 1].im); + if (y > vtemp) { + vtemp = y; + } + } + } + + if (vtemp >= 6.7178761075670888E-139) { + vtemp = 1.0 / vtemp; + for (ihi = 0; ihi <= n; ihi++) { + V[ihi + V.size(0) * ilo].re = vtemp * V[ihi + V.size(0) * + ilo].re; + V[ihi + V.size(0) * ilo].im = vtemp * V[ihi + V.size(0) * + ilo].im; + } + } + } + + if (ilascl) { + xzlascl(anrmto, anrm, alpha1); + } + } + } + } + } + } + } + } +} + +// End of code generation (xzggev.cpp) diff --git a/RAT/xzggev.h b/RAT/xzggev.h new file mode 100644 index 00000000..02de1130 --- /dev/null +++ b/RAT/xzggev.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzggev.h +// +// Code generation for function 'xzggev' +// +#ifndef XZGGEV_H +#define XZGGEV_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzggev(::coder::array &A, int32_T *info, ::coder:: + array &alpha1, ::coder::array + &beta1, ::coder::array &V); + } + } + } +} + +#endif + +// End of code generation (xzggev.h) diff --git a/RAT/xzgghrd.cpp b/RAT/xzgghrd.cpp new file mode 100644 index 00000000..58163c82 --- /dev/null +++ b/RAT/xzgghrd.cpp @@ -0,0 +1,125 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzgghrd.cpp +// +// Code generation for function 'xzgghrd' +// + +// Include files +#include "xzgghrd.h" +#include "eye.h" +#include "rt_nonfinite.h" +#include "xzlartg.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzgghrd(int32_T ilo, int32_T ihi, ::coder::array &A, :: + coder::array &Z) + { + ::coder::array b_A; + creal_T s; + real_T c; + int32_T n; + n = A.size(0); + eye(A.size(0), Z); + if ((A.size(0) > 1) && (ihi >= ilo + 2)) { + for (int32_T jcol{ilo - 1}; jcol + 1 < ihi - 1; jcol++) { + int32_T jcolp1; + jcolp1 = jcol + 2; + for (int32_T jrow{ihi - 1}; jrow + 1 > jcol + 2; jrow--) { + real_T b_s_re_tmp; + real_T s_re_tmp; + real_T stemp_im_tmp; + real_T stemp_re_tmp; + int32_T j; + int32_T loop_ub; + xzlartg(A[(jrow + A.size(0) * jcol) - 1], A[jrow + A.size(0) * + jcol], &c, &s, &A[(jrow + A.size(0) * jcol) - 1]); + A[jrow + A.size(0) * jcol].re = 0.0; + A[jrow + A.size(0) * jcol].im = 0.0; + for (j = jcolp1; j <= n; j++) { + s_re_tmp = A[jrow + A.size(0) * (j - 1)].im; + b_s_re_tmp = A[jrow + A.size(0) * (j - 1)].re; + stemp_re_tmp = A[(jrow + A.size(0) * (j - 1)) - 1].re; + stemp_im_tmp = A[(jrow + A.size(0) * (j - 1)) - 1].im; + A[jrow + A.size(0) * (j - 1)].re = c * b_s_re_tmp - (s.re * + stemp_re_tmp + s.im * stemp_im_tmp); + A[jrow + A.size(0) * (j - 1)].im = c * A[jrow + A.size(0) * (j + - 1)].im - (s.re * stemp_im_tmp - s.im * stemp_re_tmp); + A[(jrow + A.size(0) * (j - 1)) - 1].re = c * stemp_re_tmp + + (s.re * b_s_re_tmp - s.im * s_re_tmp); + A[(jrow + A.size(0) * (j - 1)) - 1].im = c * stemp_im_tmp + + (s.re * s_re_tmp + s.im * b_s_re_tmp); + } + + s.re = -s.re; + s.im = -s.im; + for (j = 1; j <= ihi; j++) { + s_re_tmp = A[(j + A.size(0) * (jrow - 1)) - 1].im; + b_s_re_tmp = A[(j + A.size(0) * (jrow - 1)) - 1].re; + stemp_re_tmp = A[(j + A.size(0) * jrow) - 1].re; + stemp_im_tmp = A[(j + A.size(0) * jrow) - 1].im; + A[(j + A.size(0) * (jrow - 1)) - 1].re = c * b_s_re_tmp - + (s.re * stemp_re_tmp + s.im * stemp_im_tmp); + A[(j + A.size(0) * (jrow - 1)) - 1].im = c * A[(j + A.size(0) * + (jrow - 1)) - 1].im - (s.re * stemp_im_tmp - s.im * + stemp_re_tmp); + A[(j + A.size(0) * jrow) - 1].re = c * stemp_re_tmp + (s.re * + b_s_re_tmp - s.im * s_re_tmp); + A[(j + A.size(0) * jrow) - 1].im = c * stemp_im_tmp + (s.re * + s_re_tmp + s.im * b_s_re_tmp); + } + + b_A.set_size(Z.size(0), Z.size(1)); + j = Z.size(1); + for (int32_T i{0}; i < j; i++) { + loop_ub = Z.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_A[i1 + b_A.size(0) * i] = Z[i1 + Z.size(0) * i]; + } + } + + for (j = 1; j <= n; j++) { + s_re_tmp = b_A[(j + b_A.size(0) * (jrow - 1)) - 1].im; + b_s_re_tmp = b_A[(j + b_A.size(0) * (jrow - 1)) - 1].re; + stemp_re_tmp = b_A[(j + b_A.size(0) * jrow) - 1].re; + stemp_im_tmp = b_A[(j + b_A.size(0) * jrow) - 1].im; + b_A[(j + b_A.size(0) * (jrow - 1)) - 1].re = c * b_s_re_tmp - + (s.re * stemp_re_tmp + s.im * stemp_im_tmp); + b_A[(j + b_A.size(0) * (jrow - 1)) - 1].im = c * s_re_tmp - + (s.re * stemp_im_tmp - s.im * stemp_re_tmp); + b_A[(j + b_A.size(0) * jrow) - 1].re = c * stemp_re_tmp + + (s.re * b_s_re_tmp - s.im * s_re_tmp); + b_A[(j + b_A.size(0) * jrow) - 1].im = c * stemp_im_tmp + + (s.re * s_re_tmp + s.im * b_s_re_tmp); + } + + Z.set_size(b_A.size(0), b_A.size(1)); + j = b_A.size(1); + for (int32_T i{0}; i < j; i++) { + loop_ub = b_A.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + Z[i1 + Z.size(0) * i] = b_A[i1 + b_A.size(0) * i]; + } + } + } + } + } + } + } + } + } +} + +// End of code generation (xzgghrd.cpp) diff --git a/RAT/xzgghrd.h b/RAT/xzgghrd.h new file mode 100644 index 00000000..edeb9227 --- /dev/null +++ b/RAT/xzgghrd.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzgghrd.h +// +// Code generation for function 'xzgghrd' +// +#ifndef XZGGHRD_H +#define XZGGHRD_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzgghrd(int32_T ilo, int32_T ihi, ::coder::array &A, :: + coder::array &Z); + } + } + } +} + +#endif + +// End of code generation (xzgghrd.h) diff --git a/RAT/xzhgeqz.cpp b/RAT/xzhgeqz.cpp new file mode 100644 index 00000000..97b6a6a0 --- /dev/null +++ b/RAT/xzhgeqz.cpp @@ -0,0 +1,654 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzhgeqz.cpp +// +// Code generation for function 'xzhgeqz' +// + +// Include files +#include "xzhgeqz.h" +#include "RATMain_data.h" +#include "rt_nonfinite.h" +#include "sqrt.h" +#include "xzlanhs.h" +#include "xzlartg.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzhgeqz(::coder::array &A, int32_T ilo, int32_T ihi, :: + coder::array &Z, int32_T *info, ::coder::array< + creal_T, 1U> &alpha1, ::coder::array &beta1) + { + ::coder::array b_A; + creal_T ctemp; + creal_T stemp; + creal_T y; + real_T anorm; + real_T ascale; + real_T b_atol; + real_T bscale; + real_T eshift_im; + real_T eshift_re; + real_T temp; + real_T tempr; + int32_T i; + int32_T ilast; + int32_T j; + int32_T jm1; + int32_T jp1; + int32_T n; + boolean_T compz; + boolean_T failed; + boolean_T guard1; + boolean_T guard2; + *info = 0; + compz = ((Z.size(0) != 0) && (Z.size(1) != 0)); + if ((A.size(0) == 1) && (A.size(1) == 1)) { + ihi = 1; + } + + n = A.size(0); + jm1 = A.size(0); + alpha1.set_size(jm1); + for (i = 0; i < jm1; i++) { + alpha1[i].re = 0.0; + alpha1[i].im = 0.0; + } + + jm1 = A.size(0); + beta1.set_size(jm1); + for (i = 0; i < jm1; i++) { + beta1[i].re = 1.0; + beta1[i].im = 0.0; + } + + eshift_re = 0.0; + eshift_im = 0.0; + ctemp.re = 0.0; + ctemp.im = 0.0; + anorm = xzlanhs(A, ilo, ihi); + tempr = 2.2204460492503131E-16 * anorm; + b_atol = 2.2250738585072014E-308; + if (tempr > 2.2250738585072014E-308) { + b_atol = tempr; + } + + tempr = 2.2250738585072014E-308; + if (anorm > 2.2250738585072014E-308) { + tempr = anorm; + } + + ascale = 1.0 / tempr; + bscale = 1.0 / std::sqrt(static_cast(A.size(0))); + failed = true; + i = ihi + 1; + for (j = i; j <= n; j++) { + alpha1[j - 1] = A[(j + A.size(0) * (j - 1)) - 1]; + } + + guard1 = false; + guard2 = false; + if (ihi >= ilo) { + int32_T ifirst; + int32_T ifrstm; + int32_T iiter; + int32_T ilastm; + int32_T ilastm1; + int32_T istart; + int32_T jiter; + boolean_T goto60; + boolean_T goto70; + boolean_T goto90; + ifirst = ilo; + istart = ilo; + ilast = ihi - 1; + ilastm1 = ihi - 2; + if (compz) { + ifrstm = 1; + ilastm = n; + } else { + ifrstm = ilo; + ilastm = ihi; + } + + iiter = 0; + goto60 = false; + goto70 = false; + goto90 = false; + jiter = 0; + int32_T exitg1; + do { + exitg1 = 0; + if (jiter <= 30 * ((ihi - ilo) + 1) - 1) { + boolean_T b_guard1; + boolean_T exitg2; + b_guard1 = false; + if (ilast + 1 == ilo) { + goto60 = true; + b_guard1 = true; + } else if (std::abs(A[ilast + A.size(0) * ilastm1].re) + std:: + abs(A[ilast + A.size(0) * ilastm1].im) <= std::fmax + (2.2250738585072014E-308, 2.2204460492503131E-16 * + ((std::abs(A[ilast + A.size(0) * ilast].re) + std:: + abs(A[ilast + A.size(0) * ilast].im)) + (std::abs + (A[ilastm1 + A.size(0) * ilastm1].re) + std::abs + (A[ilastm1 + A.size(0) * ilastm1].im))))) { + A[ilast + A.size(0) * ilastm1].re = 0.0; + A[ilast + A.size(0) * ilastm1].im = 0.0; + goto60 = true; + b_guard1 = true; + } else { + boolean_T guard3; + j = ilastm1; + guard3 = false; + exitg2 = false; + while ((!exitg2) && (j + 1 >= ilo)) { + if (j + 1 == ilo) { + guard3 = true; + exitg2 = true; + } else if (std::abs(A[j + A.size(0) * (j - 1)].re) + std:: + abs(A[j + A.size(0) * (j - 1)].im) <= std::fmax + (2.2250738585072014E-308, 2.2204460492503131E-16 * + ((std::abs(A[j + A.size(0) * j].re) + std::abs + (A[j + A.size(0) * j].im)) + (std::abs(A[(j + + A.size(0) * (j - 1)) - 1].re) + std::abs(A[(j + A.size(0) + * (j - 1)) - 1].im))))) { + A[j + A.size(0) * (j - 1)].re = 0.0; + A[j + A.size(0) * (j - 1)].im = 0.0; + guard3 = true; + exitg2 = true; + } else { + j--; + guard3 = false; + } + } + + if (guard3) { + ifirst = j + 1; + goto70 = true; + } + + if (goto70) { + b_guard1 = true; + } else { + jm1 = alpha1.size(0); + alpha1.set_size(jm1); + for (i = 0; i < jm1; i++) { + alpha1[i].re = rtNaN; + alpha1[i].im = 0.0; + } + + jm1 = beta1.size(0); + beta1.set_size(jm1); + for (i = 0; i < jm1; i++) { + beta1[i].re = rtNaN; + beta1[i].im = 0.0; + } + + if (compz) { + jm1 = Z.size(0); + jp1 = Z.size(1); + Z.set_size(jm1, jp1); + for (i = 0; i < jp1; i++) { + for (int32_T i1{0}; i1 < jm1; i1++) { + Z[i1 + Z.size(0) * i].re = rtNaN; + Z[i1 + Z.size(0) * i].im = 0.0; + } + } + } + + *info = 1; + exitg1 = 1; + } + } + + if (b_guard1) { + if (goto60) { + goto60 = false; + alpha1[ilast] = A[ilast + A.size(0) * ilast]; + ilast = ilastm1; + ilastm1--; + if (ilast + 1 < ilo) { + failed = false; + guard2 = true; + exitg1 = 1; + } else { + iiter = 0; + eshift_re = 0.0; + eshift_im = 0.0; + if (!compz) { + ilastm = ilast + 1; + if (ifrstm > ilast + 1) { + ifrstm = ilo; + } + } + + jiter++; + } + } else { + if (goto70) { + real_T ad22_im; + real_T ad22_re; + real_T temp2; + real_T y_im_tmp; + goto70 = false; + iiter++; + if (!compz) { + ifrstm = ifirst; + } + + if (iiter - iiter / 10 * 10 != 0) { + tempr = ascale * A[ilast + A.size(0) * ilast].re; + anorm = ascale * A[ilast + A.size(0) * ilast].im; + if (anorm == 0.0) { + ad22_re = tempr / bscale; + ad22_im = 0.0; + } else if (tempr == 0.0) { + ad22_re = 0.0; + ad22_im = anorm / bscale; + } else { + ad22_re = tempr / bscale; + ad22_im = anorm / bscale; + } + + tempr = ascale * A[ilastm1 + A.size(0) * ilast].re; + anorm = ascale * A[ilastm1 + A.size(0) * ilast].im; + if (anorm == 0.0) { + stemp.re = tempr / bscale; + stemp.im = 0.0; + } else if (tempr == 0.0) { + stemp.re = 0.0; + stemp.im = anorm / bscale; + } else { + stemp.re = tempr / bscale; + stemp.im = anorm / bscale; + } + + scalar::d_sqrt(&stemp); + tempr = ascale * A[ilast + A.size(0) * ilastm1].re; + anorm = ascale * A[ilast + A.size(0) * ilastm1].im; + if (anorm == 0.0) { + y.re = tempr / bscale; + y.im = 0.0; + } else if (tempr == 0.0) { + y.re = 0.0; + y.im = anorm / bscale; + } else { + y.re = tempr / bscale; + y.im = anorm / bscale; + } + + scalar::d_sqrt(&y); + ctemp.re = stemp.re * y.re - stemp.im * y.im; + ctemp.im = stemp.re * y.im + stemp.im * y.re; + if ((ctemp.re != 0.0) || (ctemp.im != 0.0)) { + real_T x_im; + real_T x_re; + tempr = ascale * A[ilastm1 + A.size(0) * ilastm1].re; + anorm = ascale * A[ilastm1 + A.size(0) * ilastm1].im; + if (anorm == 0.0) { + tempr /= bscale; + anorm = 0.0; + } else if (tempr == 0.0) { + tempr = 0.0; + anorm /= bscale; + } else { + tempr /= bscale; + anorm /= bscale; + } + + x_re = 0.5 * (tempr - ad22_re); + x_im = 0.5 * (anorm - ad22_im); + temp2 = std::abs(x_re) + std::abs(x_im); + temp = std::fmax(std::abs(ctemp.re) + std::abs + (ctemp.im), temp2); + if (x_im == 0.0) { + stemp.re = x_re / temp; + stemp.im = 0.0; + } else if (x_re == 0.0) { + stemp.re = 0.0; + stemp.im = x_im / temp; + } else { + stemp.re = x_re / temp; + stemp.im = x_im / temp; + } + + if (ctemp.im == 0.0) { + y.re = ctemp.re / temp; + y.im = 0.0; + } else if (ctemp.re == 0.0) { + y.re = 0.0; + y.im = ctemp.im / temp; + } else { + y.re = ctemp.re / temp; + y.im = ctemp.im / temp; + } + + anorm = stemp.re * stemp.re - stemp.im * stemp.im; + tempr = stemp.re * stemp.im; + y_im_tmp = y.re * y.im; + stemp.re = anorm + (y.re * y.re - y.im * y.im); + stemp.im = (tempr + tempr) + (y_im_tmp + y_im_tmp); + scalar::d_sqrt(&stemp); + y.re = temp * stemp.re; + y.im = temp * stemp.im; + if (temp2 > 0.0) { + if (x_im == 0.0) { + tempr = x_re / temp2; + anorm = 0.0; + } else { + if (x_re == 0.0) { + tempr = 0.0; + } else { + tempr = x_re / temp2; + } + + anorm = x_im / temp2; + } + + if (tempr * y.re + anorm * y.im < 0.0) { + y.re = -y.re; + y.im = -y.im; + } + } + + tempr = x_re + y.re; + temp = x_im + y.im; + if (temp == 0.0) { + if (ctemp.im == 0.0) { + y_im_tmp = ctemp.re / tempr; + tempr = 0.0; + } else if (ctemp.re == 0.0) { + y_im_tmp = 0.0; + tempr = ctemp.im / tempr; + } else { + y_im_tmp = ctemp.re / tempr; + tempr = ctemp.im / tempr; + } + } else if (tempr == 0.0) { + if (ctemp.re == 0.0) { + y_im_tmp = ctemp.im / temp; + tempr = 0.0; + } else if (ctemp.im == 0.0) { + y_im_tmp = 0.0; + tempr = -(ctemp.re / temp); + } else { + y_im_tmp = ctemp.im / temp; + tempr = -(ctemp.re / temp); + } + } else { + temp2 = std::abs(tempr); + anorm = std::abs(temp); + if (temp2 > anorm) { + anorm = temp / tempr; + tempr += anorm * temp; + y_im_tmp = (ctemp.re + anorm * ctemp.im) / tempr; + tempr = (ctemp.im - anorm * ctemp.re) / tempr; + } else if (anorm == temp2) { + if (tempr > 0.0) { + tempr = 0.5; + } else { + tempr = -0.5; + } + + if (temp > 0.0) { + anorm = 0.5; + } else { + anorm = -0.5; + } + + y_im_tmp = (ctemp.re * tempr + ctemp.im * anorm) / + temp2; + tempr = (ctemp.im * tempr - ctemp.re * anorm) / + temp2; + } else { + anorm = tempr / temp; + tempr = temp + anorm * tempr; + y_im_tmp = (anorm * ctemp.re + ctemp.im) / tempr; + tempr = (anorm * ctemp.im - ctemp.re) / tempr; + } + } + + ad22_re -= ctemp.re * y_im_tmp - ctemp.im * tempr; + ad22_im -= ctemp.re * tempr + ctemp.im * y_im_tmp; + } + } else { + if (iiter - iiter / 20 * 20 == 0) { + tempr = ascale * A[ilast + A.size(0) * ilast].re; + anorm = ascale * A[ilast + A.size(0) * ilast].im; + if (anorm == 0.0) { + tempr /= bscale; + anorm = 0.0; + } else if (tempr == 0.0) { + tempr = 0.0; + anorm /= bscale; + } else { + tempr /= bscale; + anorm /= bscale; + } + + eshift_re += tempr; + eshift_im += anorm; + } else { + tempr = ascale * A[ilast + A.size(0) * ilastm1].re; + anorm = ascale * A[ilast + A.size(0) * ilastm1].im; + if (anorm == 0.0) { + tempr /= bscale; + anorm = 0.0; + } else if (tempr == 0.0) { + tempr = 0.0; + anorm /= bscale; + } else { + tempr /= bscale; + anorm /= bscale; + } + + eshift_re += tempr; + eshift_im += anorm; + } + + ad22_re = eshift_re; + ad22_im = eshift_im; + } + + j = ilastm1; + jp1 = ilastm1 + 1; + exitg2 = false; + while ((!exitg2) && (j + 1 > ifirst)) { + istart = j + 1; + ctemp.re = ascale * A[j + A.size(0) * j].re - ad22_re * + bscale; + ctemp.im = ascale * A[j + A.size(0) * j].im - ad22_im * + bscale; + temp = std::abs(ctemp.re) + std::abs(ctemp.im); + temp2 = ascale * (std::abs(A[jp1 + A.size(0) * j].re) + + std::abs(A[jp1 + A.size(0) * j].im)); + tempr = temp; + if (temp2 > temp) { + tempr = temp2; + } + + if ((tempr < 1.0) && (tempr != 0.0)) { + temp /= tempr; + temp2 /= tempr; + } + + if ((std::abs(A[j + A.size(0) * (j - 1)].re) + std::abs + (A[j + A.size(0) * (j - 1)].im)) * temp2 <= temp * + b_atol) { + goto90 = true; + exitg2 = true; + } else { + jp1 = j; + j--; + } + } + + if (!goto90) { + istart = ifirst; + ctemp.re = ascale * A[(ifirst + A.size(0) * (ifirst - 1)) + - 1].re - ad22_re * bscale; + ctemp.im = ascale * A[(ifirst + A.size(0) * (ifirst - 1)) + - 1].im - ad22_im * bscale; + } + + goto90 = false; + stemp.re = ascale * A[istart + A.size(0) * (istart - 1)]. + re; + stemp.im = ascale * A[istart + A.size(0) * (istart - 1)]. + im; + xzlartg(ctemp, stemp, &temp, &y); + j = istart; + jm1 = istart - 2; + while (j < ilast + 1) { + if (j > istart) { + xzlartg(A[(j + A.size(0) * jm1) - 1], A[j + A.size(0) * + jm1], &temp, &y, &A[(j + A.size(0) * jm1) - 1]); + A[j + A.size(0) * jm1].re = 0.0; + A[j + A.size(0) * jm1].im = 0.0; + } + + for (jp1 = j; jp1 <= ilastm; jp1++) { + anorm = A[j + A.size(0) * (jp1 - 1)].im; + tempr = A[j + A.size(0) * (jp1 - 1)].re; + temp2 = A[(j + A.size(0) * (jp1 - 1)) - 1].re; + stemp.re = temp * temp2 + (y.re * tempr - y.im * anorm); + y_im_tmp = A[(j + A.size(0) * (jp1 - 1)) - 1].im; + stemp.im = temp * y_im_tmp + (y.re * anorm + y.im * + tempr); + A[j + A.size(0) * (jp1 - 1)].re = temp * tempr - (y.re + * temp2 + y.im * y_im_tmp); + A[j + A.size(0) * (jp1 - 1)].im = temp * A[j + A.size + (0) * (jp1 - 1)].im - (y.re * y_im_tmp - y.im * + temp2); + A[(j + A.size(0) * (jp1 - 1)) - 1] = stemp; + } + + y.re = -y.re; + y.im = -y.im; + jp1 = j; + if (ilast + 1 < j + 2) { + jp1 = ilast - 1; + } + + for (jm1 = ifrstm; jm1 <= jp1 + 2; jm1++) { + anorm = A[(jm1 + A.size(0) * (j - 1)) - 1].im; + tempr = A[(jm1 + A.size(0) * (j - 1)) - 1].re; + temp2 = A[(jm1 + A.size(0) * j) - 1].re; + stemp.re = temp * temp2 + (y.re * tempr - y.im * anorm); + stemp.im = temp * A[(jm1 + A.size(0) * j) - 1].im + + (y.re * anorm + y.im * tempr); + tempr = A[(jm1 + A.size(0) * j) - 1].im; + anorm = A[(jm1 + A.size(0) * j) - 1].re; + A[(jm1 + A.size(0) * (j - 1)) - 1].re = temp * A[(jm1 + + A.size(0) * (j - 1)) - 1].re - (y.re * temp2 + + y.im * tempr); + A[(jm1 + A.size(0) * (j - 1)) - 1].im = temp * A[(jm1 + + A.size(0) * (j - 1)) - 1].im - (y.re * tempr - + y.im * anorm); + A[(jm1 + A.size(0) * j) - 1] = stemp; + } + + if (compz) { + b_A.set_size(Z.size(0), Z.size(1)); + jp1 = Z.size(1); + for (i = 0; i < jp1; i++) { + jm1 = Z.size(0); + for (int32_T i1{0}; i1 < jm1; i1++) { + b_A[i1 + b_A.size(0) * i] = Z[i1 + Z.size(0) * i]; + } + } + + for (jm1 = 1; jm1 <= n; jm1++) { + anorm = b_A[(jm1 + b_A.size(0) * (j - 1)) - 1].im; + tempr = b_A[(jm1 + b_A.size(0) * (j - 1)) - 1].re; + temp2 = b_A[(jm1 + b_A.size(0) * j) - 1].re; + stemp.re = temp * temp2 + (y.re * tempr - y.im * + anorm); + y_im_tmp = b_A[(jm1 + b_A.size(0) * j) - 1].im; + stemp.im = temp * y_im_tmp + (y.re * anorm + y.im * + tempr); + b_A[(jm1 + b_A.size(0) * (j - 1)) - 1].re = temp * + tempr - (y.re * temp2 + y.im * y_im_tmp); + b_A[(jm1 + b_A.size(0) * (j - 1)) - 1].im = temp * + anorm - (y.re * y_im_tmp - y.im * temp2); + b_A[(jm1 + b_A.size(0) * j) - 1] = stemp; + } + + Z.set_size(b_A.size(0), b_A.size(1)); + jp1 = b_A.size(1); + for (i = 0; i < jp1; i++) { + jm1 = b_A.size(0); + for (int32_T i1{0}; i1 < jm1; i1++) { + Z[i1 + Z.size(0) * i] = b_A[i1 + b_A.size(0) * i]; + } + } + } + + jm1 = j - 1; + j++; + } + } + + jiter++; + } + } + } else { + guard2 = true; + exitg1 = 1; + } + } while (exitg1 == 0); + } else { + guard1 = true; + } + + if (guard2) { + if (failed) { + *info = ilast + 1; + for (jm1 = 0; jm1 <= ilast; jm1++) { + alpha1[jm1].re = rtNaN; + alpha1[jm1].im = 0.0; + beta1[jm1].re = rtNaN; + beta1[jm1].im = 0.0; + } + + if (compz) { + jm1 = Z.size(0); + jp1 = Z.size(1); + Z.set_size(jm1, jp1); + for (i = 0; i < jp1; i++) { + for (int32_T i1{0}; i1 < jm1; i1++) { + Z[i1 + Z.size(0) * i].re = rtNaN; + Z[i1 + Z.size(0) * i].im = 0.0; + } + } + } + } else { + guard1 = true; + } + } + + if (guard1) { + for (j = 0; j <= ilo - 2; j++) { + alpha1[j] = A[j + A.size(0) * j]; + } + } + } + } + } + } +} + +// End of code generation (xzhgeqz.cpp) diff --git a/RAT/xzhgeqz.h b/RAT/xzhgeqz.h new file mode 100644 index 00000000..53d9519d --- /dev/null +++ b/RAT/xzhgeqz.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzhgeqz.h +// +// Code generation for function 'xzhgeqz' +// +#ifndef XZHGEQZ_H +#define XZHGEQZ_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzhgeqz(::coder::array &A, int32_T ilo, int32_T ihi, :: + coder::array &Z, int32_T *info, ::coder::array< + creal_T, 1U> &alpha1, ::coder::array &beta1); + } + } + } +} + +#endif + +// End of code generation (xzhgeqz.h) diff --git a/RAT/xzlangeM.cpp b/RAT/xzlangeM.cpp new file mode 100644 index 00000000..c93c43aa --- /dev/null +++ b/RAT/xzlangeM.cpp @@ -0,0 +1,63 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlangeM.cpp +// +// Code generation for function 'xzlangeM' +// + +// Include files +#include "xzlangeM.h" +#include "RATMain_rtwutil.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + real_T xzlangeM(const ::coder::array &x) + { + real_T y; + boolean_T b; + boolean_T b1; + y = 0.0; + b = (x.size(0) == 0); + b1 = (x.size(1) == 0); + if ((!b) && (!b1)) { + int32_T k; + boolean_T exitg1; + k = 0; + exitg1 = false; + while ((!exitg1) && (k <= x.size(0) * x.size(1) - 1)) { + real_T absxk; + absxk = rt_hypotd_snf(x[k].re, x[k].im); + if (std::isnan(absxk)) { + y = rtNaN; + exitg1 = true; + } else { + if (absxk > y) { + y = absxk; + } + + k++; + } + } + } + + return y; + } + } + } + } +} + +// End of code generation (xzlangeM.cpp) diff --git a/RAT/xzlangeM.h b/RAT/xzlangeM.h new file mode 100644 index 00000000..0128c89a --- /dev/null +++ b/RAT/xzlangeM.h @@ -0,0 +1,36 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlangeM.h +// +// Code generation for function 'xzlangeM' +// +#ifndef XZLANGEM_H +#define XZLANGEM_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + real_T xzlangeM(const ::coder::array &x); + } + } + } +} + +#endif + +// End of code generation (xzlangeM.h) diff --git a/RAT/xzlanhs.cpp b/RAT/xzlanhs.cpp new file mode 100644 index 00000000..db5838d1 --- /dev/null +++ b/RAT/xzlanhs.cpp @@ -0,0 +1,96 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlanhs.cpp +// +// Code generation for function 'xzlanhs' +// + +// Include files +#include "xzlanhs.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + real_T xzlanhs(const ::coder::array &A, int32_T ilo, + int32_T ihi) + { + real_T f; + f = 0.0; + if (ilo <= ihi) { + real_T scale; + real_T ssq; + int32_T nm1; + scale = 3.3121686421112381E-170; + ssq = 0.0; + nm1 = ihi - ilo; + for (int32_T j{0}; j <= nm1; j++) { + real_T absxk; + real_T colscale; + real_T colssq; + int32_T col; + int32_T u0; + colscale = 3.3121686421112381E-170; + colssq = 0.0; + col = (ilo + j) - 1; + u0 = j + 1; + if (u0 > nm1) { + u0 = nm1; + } + + u0 += ilo; + for (int32_T row{ilo}; row <= u0; row++) { + real_T t; + absxk = std::abs(A[(row + A.size(0) * col) - 1].re); + if (absxk > colscale) { + t = colscale / absxk; + colssq = colssq * t * t + 1.0; + colscale = absxk; + } else { + t = absxk / colscale; + colssq += t * t; + } + + absxk = std::abs(A[(row + A.size(0) * col) - 1].im); + if (absxk > colscale) { + t = colscale / absxk; + colssq = colssq * t * t + 1.0; + colscale = absxk; + } else { + t = absxk / colscale; + colssq += t * t; + } + } + + if (scale >= colscale) { + absxk = colscale / scale; + ssq += absxk * absxk * colssq; + } else { + absxk = scale / colscale; + ssq = colssq + absxk * absxk * ssq; + scale = colscale; + } + } + + f = scale * std::sqrt(ssq); + } + + return f; + } + } + } + } +} + +// End of code generation (xzlanhs.cpp) diff --git a/RAT/xzlanhs.h b/RAT/xzlanhs.h new file mode 100644 index 00000000..9628bf23 --- /dev/null +++ b/RAT/xzlanhs.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlanhs.h +// +// Code generation for function 'xzlanhs' +// +#ifndef XZLANHS_H +#define XZLANHS_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + real_T xzlanhs(const ::coder::array &A, int32_T ilo, + int32_T ihi); + } + } + } +} + +#endif + +// End of code generation (xzlanhs.h) diff --git a/RAT/xzlarf.cpp b/RAT/xzlarf.cpp new file mode 100644 index 00000000..ef2fab20 --- /dev/null +++ b/RAT/xzlarf.cpp @@ -0,0 +1,198 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlarf.cpp +// +// Code generation for function 'xzlarf' +// + +// Include files +#include "xzlarf.h" +#include "rt_nonfinite.h" +#include "xgemv.h" +#include "xgerc.h" +#include "coder_array.h" + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + static int32_T ilazlc(int32_T m, int32_T n, const ::coder::array &A, int32_T ia0, int32_T lda); + static int32_T ilazlr(int32_T m, int32_T n, const ::coder::array &A, int32_T ia0, int32_T lda); + } + } + } +} + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + static int32_T ilazlc(int32_T m, int32_T n, const ::coder::array &A, int32_T ia0, int32_T lda) + { + int32_T j; + boolean_T exitg2; + j = n; + exitg2 = false; + while ((!exitg2) && (j > 0)) { + int32_T coltop; + int32_T exitg1; + int32_T ia; + coltop = ia0 + (j - 1) * lda; + ia = coltop; + do { + exitg1 = 0; + if (ia <= (coltop + m) - 1) { + if (A[ia - 1] != 0.0) { + exitg1 = 1; + } else { + ia++; + } + } else { + j--; + exitg1 = 2; + } + } while (exitg1 == 0); + + if (exitg1 == 1) { + exitg2 = true; + } + } + + return j; + } + + static int32_T ilazlr(int32_T m, int32_T n, const ::coder::array &A, int32_T ia0, int32_T lda) + { + int32_T i; + boolean_T exitg2; + i = m; + exitg2 = false; + while ((!exitg2) && (i > 0)) { + int32_T exitg1; + int32_T rowleft; + int32_T rowright; + rowleft = (ia0 + i) - 1; + rowright = rowleft + (n - 1) * lda; + do { + exitg1 = 0; + if (((lda > 0) && (rowleft <= rowright)) || ((lda < 0) && (rowleft + >= rowright))) { + if (A[rowleft - 1] != 0.0) { + exitg1 = 1; + } else { + rowleft += lda; + } + } else { + i--; + exitg1 = 2; + } + } while (exitg1 == 0); + + if (exitg1 == 1) { + exitg2 = true; + } + } + + return i; + } + + void b_xzlarf(int32_T m, int32_T n, int32_T iv0, real_T tau, ::coder:: + array &C, int32_T ic0, int32_T ldc, ::coder:: + array &work) + { + int32_T lastc; + int32_T lastv; + if (tau != 0.0) { + lastv = n; + lastc = iv0 + n; + while ((lastv > 0) && (C[lastc - 2] == 0.0)) { + lastv--; + lastc--; + } + + lastc = ilazlr(m, lastv, C, ic0, ldc); + } else { + lastv = 0; + lastc = 0; + } + + if (lastv > 0) { + blas::b_xgemv(lastc, lastv, C, ic0, ldc, C, iv0, work); + blas::xgerc(lastc, lastv, -tau, work, iv0, C, ic0, ldc); + } + } + + void c_xzlarf(int32_T m, int32_T n, int32_T iv0, real_T tau, ::coder:: + array &C, int32_T ic0, int32_T ldc, ::coder:: + array &work) + { + int32_T lastc; + int32_T lastv; + if (tau != 0.0) { + lastv = m; + lastc = iv0 + m; + while ((lastv > 0) && (C[lastc - 2] == 0.0)) { + lastv--; + lastc--; + } + + lastc = ilazlc(lastv, n, C, ic0, ldc); + } else { + lastv = 0; + lastc = 0; + } + + if (lastv > 0) { + blas::c_xgemv(lastv, lastc, C, ic0, ldc, C, iv0, work); + blas::xgerc(lastv, lastc, -tau, iv0, work, C, ic0, ldc); + } + } + + void xzlarf(int32_T m, int32_T n, int32_T iv0, real_T tau, ::coder:: + array &C, int32_T ic0, int32_T ldc, ::coder:: + array &work) + { + int32_T lastc; + int32_T lastv; + if (tau != 0.0) { + lastv = m; + lastc = iv0 + m; + while ((lastv > 0) && (C[lastc - 2] == 0.0)) { + lastv--; + lastc--; + } + + lastc = ilazlc(lastv, n, C, ic0, ldc); + } else { + lastv = 0; + lastc = 0; + } + + if (lastv > 0) { + blas::xgemv(lastv, lastc, C, ic0, ldc, C, iv0, work); + blas::xgerc(lastv, lastc, -tau, iv0, work, C, ic0, ldc); + } + } + } + } + } +} + +// End of code generation (xzlarf.cpp) diff --git a/RAT/xzlarf.h b/RAT/xzlarf.h new file mode 100644 index 00000000..feaff388 --- /dev/null +++ b/RAT/xzlarf.h @@ -0,0 +1,44 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlarf.h +// +// Code generation for function 'xzlarf' +// +#ifndef XZLARF_H +#define XZLARF_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void b_xzlarf(int32_T m, int32_T n, int32_T iv0, real_T tau, ::coder:: + array &C, int32_T ic0, int32_T ldc, ::coder:: + array &work); + void c_xzlarf(int32_T m, int32_T n, int32_T iv0, real_T tau, ::coder:: + array &C, int32_T ic0, int32_T ldc, ::coder:: + array &work); + void xzlarf(int32_T m, int32_T n, int32_T iv0, real_T tau, ::coder:: + array &C, int32_T ic0, int32_T ldc, ::coder:: + array &work); + } + } + } +} + +#endif + +// End of code generation (xzlarf.h) diff --git a/RAT/xzlarfg.cpp b/RAT/xzlarfg.cpp new file mode 100644 index 00000000..378304eb --- /dev/null +++ b/RAT/xzlarfg.cpp @@ -0,0 +1,214 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlarfg.cpp +// +// Code generation for function 'xzlarfg' +// + +// Include files +#include "xzlarfg.h" +#include "RATMain_rtwutil.h" +#include "rt_nonfinite.h" +#include "xnrm2.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + real_T xzlarfg(int32_T n, real_T *alpha1, ::coder::array &x) + { + real_T tau; + tau = 0.0; + if (n > 0) { + real_T xnorm; + xnorm = blas::b_xnrm2(n - 1, x); + if (xnorm != 0.0) { + real_T beta1; + beta1 = rt_hypotd_snf(*alpha1, xnorm); + if (*alpha1 >= 0.0) { + beta1 = -beta1; + } + + if (std::abs(beta1) < 1.0020841800044864E-292) { + int32_T knt; + knt = 0; + do { + knt++; + for (int32_T k{2}; k <= n; k++) { + x[k - 1] = 9.9792015476736E+291 * x[k - 1]; + } + + beta1 *= 9.9792015476736E+291; + *alpha1 *= 9.9792015476736E+291; + } while ((std::abs(beta1) < 1.0020841800044864E-292) && (knt < + 20)); + + beta1 = rt_hypotd_snf(*alpha1, blas::b_xnrm2(n - 1, x)); + if (*alpha1 >= 0.0) { + beta1 = -beta1; + } + + tau = (beta1 - *alpha1) / beta1; + xnorm = 1.0 / (*alpha1 - beta1); + for (int32_T k{2}; k <= n; k++) { + x[k - 1] = xnorm * x[k - 1]; + } + + for (int32_T k{0}; k < knt; k++) { + beta1 *= 1.0020841800044864E-292; + } + + *alpha1 = beta1; + } else { + tau = (beta1 - *alpha1) / beta1; + xnorm = 1.0 / (*alpha1 - beta1); + for (int32_T k{2}; k <= n; k++) { + x[k - 1] = xnorm * x[k - 1]; + } + + *alpha1 = beta1; + } + } + } + + return tau; + } + + real_T xzlarfg(int32_T n, real_T *alpha1, ::coder::array &x, + int32_T ix0) + { + real_T tau; + tau = 0.0; + if (n > 0) { + real_T xnorm; + xnorm = blas::xnrm2(n - 1, x, ix0); + if (xnorm != 0.0) { + real_T beta1; + beta1 = rt_hypotd_snf(*alpha1, xnorm); + if (*alpha1 >= 0.0) { + beta1 = -beta1; + } + + if (std::abs(beta1) < 1.0020841800044864E-292) { + int32_T i; + int32_T knt; + knt = 0; + i = (ix0 + n) - 2; + do { + knt++; + for (int32_T k{ix0}; k <= i; k++) { + x[k - 1] = 9.9792015476736E+291 * x[k - 1]; + } + + beta1 *= 9.9792015476736E+291; + *alpha1 *= 9.9792015476736E+291; + } while ((std::abs(beta1) < 1.0020841800044864E-292) && (knt < + 20)); + + beta1 = rt_hypotd_snf(*alpha1, blas::xnrm2(n - 1, x, ix0)); + if (*alpha1 >= 0.0) { + beta1 = -beta1; + } + + tau = (beta1 - *alpha1) / beta1; + xnorm = 1.0 / (*alpha1 - beta1); + for (int32_T k{ix0}; k <= i; k++) { + x[k - 1] = xnorm * x[k - 1]; + } + + for (int32_T k{0}; k < knt; k++) { + beta1 *= 1.0020841800044864E-292; + } + + *alpha1 = beta1; + } else { + int32_T i; + tau = (beta1 - *alpha1) / beta1; + xnorm = 1.0 / (*alpha1 - beta1); + i = (ix0 + n) - 2; + for (int32_T k{ix0}; k <= i; k++) { + x[k - 1] = xnorm * x[k - 1]; + } + + *alpha1 = beta1; + } + } + } + + return tau; + } + + real_T xzlarfg(int32_T n, real_T *alpha1, real_T x[3]) + { + real_T tau; + tau = 0.0; + if (n > 0) { + real_T xnorm; + xnorm = blas::xnrm2(n - 1, x); + if (xnorm != 0.0) { + real_T beta1; + beta1 = rt_hypotd_snf(*alpha1, xnorm); + if (*alpha1 >= 0.0) { + beta1 = -beta1; + } + + if (std::abs(beta1) < 1.0020841800044864E-292) { + int32_T knt; + knt = 0; + do { + knt++; + for (int32_T k{2}; k <= n; k++) { + x[k - 1] *= 9.9792015476736E+291; + } + + beta1 *= 9.9792015476736E+291; + *alpha1 *= 9.9792015476736E+291; + } while ((std::abs(beta1) < 1.0020841800044864E-292) && (knt < + 20)); + + beta1 = rt_hypotd_snf(*alpha1, blas::xnrm2(n - 1, x)); + if (*alpha1 >= 0.0) { + beta1 = -beta1; + } + + tau = (beta1 - *alpha1) / beta1; + xnorm = 1.0 / (*alpha1 - beta1); + for (int32_T k{2}; k <= n; k++) { + x[k - 1] *= xnorm; + } + + for (int32_T k{0}; k < knt; k++) { + beta1 *= 1.0020841800044864E-292; + } + + *alpha1 = beta1; + } else { + tau = (beta1 - *alpha1) / beta1; + xnorm = 1.0 / (*alpha1 - beta1); + for (int32_T k{2}; k <= n; k++) { + x[k - 1] *= xnorm; + } + + *alpha1 = beta1; + } + } + } + + return tau; + } + } + } + } +} + +// End of code generation (xzlarfg.cpp) diff --git a/RAT/xzlarfg.h b/RAT/xzlarfg.h new file mode 100644 index 00000000..02267ebf --- /dev/null +++ b/RAT/xzlarfg.h @@ -0,0 +1,39 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlarfg.h +// +// Code generation for function 'xzlarfg' +// +#ifndef XZLARFG_H +#define XZLARFG_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + real_T xzlarfg(int32_T n, real_T *alpha1, ::coder::array &x); + real_T xzlarfg(int32_T n, real_T *alpha1, ::coder::array &x, + int32_T ix0); + real_T xzlarfg(int32_T n, real_T *alpha1, real_T x[3]); + } + } + } +} + +#endif + +// End of code generation (xzlarfg.h) diff --git a/RAT/xzlartg.cpp b/RAT/xzlartg.cpp new file mode 100644 index 00000000..225797ae --- /dev/null +++ b/RAT/xzlartg.cpp @@ -0,0 +1,282 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlartg.cpp +// +// Code generation for function 'xzlartg' +// + +// Include files +#include "xzlartg.h" +#include "RATMain_rtwutil.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzlartg(const creal_T f, const creal_T g, real_T *cs, creal_T *sn) + { + real_T f2; + real_T fs_im; + real_T fs_re; + real_T gs_im; + real_T gs_re; + real_T scale; + real_T scale_tmp; + int32_T count; + boolean_T guard1; + scale_tmp = std::abs(f.re); + f2 = std::abs(f.im); + if (f2 > scale_tmp) { + scale_tmp = f2; + } + + f2 = std::abs(g.re); + scale = std::abs(g.im); + if (scale > f2) { + f2 = scale; + } + + scale = scale_tmp; + if (f2 > scale_tmp) { + scale = f2; + } + + fs_re = f.re; + fs_im = f.im; + gs_re = g.re; + gs_im = g.im; + count = 0; + guard1 = false; + if (scale >= 7.4428285367870146E+137) { + do { + count++; + fs_re *= 1.3435752215134178E-138; + fs_im *= 1.3435752215134178E-138; + gs_re *= 1.3435752215134178E-138; + gs_im *= 1.3435752215134178E-138; + scale *= 1.3435752215134178E-138; + } while ((scale >= 7.4428285367870146E+137) && (count < 20)); + + guard1 = true; + } else if (scale <= 1.3435752215134178E-138) { + if (((g.re == 0.0) && (g.im == 0.0)) || (std::isnan(g.re) || std:: + isnan(g.im))) { + *cs = 1.0; + sn->re = 0.0; + sn->im = 0.0; + } else { + do { + fs_re *= 7.4428285367870146E+137; + fs_im *= 7.4428285367870146E+137; + gs_re *= 7.4428285367870146E+137; + gs_im *= 7.4428285367870146E+137; + scale *= 7.4428285367870146E+137; + } while (!!(scale <= 1.3435752215134178E-138)); + + guard1 = true; + } + } else { + guard1 = true; + } + + if (guard1) { + real_T g2; + f2 = fs_re * fs_re + fs_im * fs_im; + g2 = gs_re * gs_re + gs_im * gs_im; + scale = g2; + if (g2 < 1.0) { + scale = 1.0; + } + + if (f2 <= scale * 2.0041683600089728E-292) { + if ((f.re == 0.0) && (f.im == 0.0)) { + *cs = 0.0; + g2 = rt_hypotd_snf(gs_re, gs_im); + sn->re = gs_re / g2; + sn->im = -gs_im / g2; + } else { + real_T g2s; + g2s = std::sqrt(g2); + *cs = rt_hypotd_snf(fs_re, fs_im) / g2s; + if (scale_tmp > 1.0) { + g2 = rt_hypotd_snf(f.re, f.im); + fs_re = f.re / g2; + fs_im = f.im / g2; + } else { + f2 = 7.4428285367870146E+137 * f.re; + scale = 7.4428285367870146E+137 * f.im; + g2 = rt_hypotd_snf(f2, scale); + fs_re = f2 / g2; + fs_im = scale / g2; + } + + gs_re /= g2s; + gs_im = -gs_im / g2s; + sn->re = fs_re * gs_re - fs_im * gs_im; + sn->im = fs_re * gs_im + fs_im * gs_re; + } + } else { + scale = std::sqrt(g2 / f2 + 1.0); + *cs = 1.0 / scale; + g2 += f2; + fs_re = scale * fs_re / g2; + fs_im = scale * fs_im / g2; + sn->re = fs_re * gs_re - fs_im * -gs_im; + sn->im = fs_re * -gs_im + fs_im * gs_re; + } + } + } + + void xzlartg(const creal_T f, const creal_T g, real_T *cs, creal_T *sn, + creal_T *r) + { + real_T f2s; + real_T fs_im; + real_T fs_re; + real_T gs_im; + real_T gs_re; + real_T scale; + real_T scale_tmp; + int32_T count; + int8_T rescaledir; + boolean_T guard1; + scale_tmp = std::abs(f.re); + f2s = std::abs(f.im); + if (f2s > scale_tmp) { + scale_tmp = f2s; + } + + f2s = std::abs(g.re); + scale = std::abs(g.im); + if (scale > f2s) { + f2s = scale; + } + + scale = scale_tmp; + if (f2s > scale_tmp) { + scale = f2s; + } + + fs_re = f.re; + fs_im = f.im; + gs_re = g.re; + gs_im = g.im; + count = -1; + rescaledir = 0; + guard1 = false; + if (scale >= 7.4428285367870146E+137) { + do { + count++; + fs_re *= 1.3435752215134178E-138; + fs_im *= 1.3435752215134178E-138; + gs_re *= 1.3435752215134178E-138; + gs_im *= 1.3435752215134178E-138; + scale *= 1.3435752215134178E-138; + } while ((scale >= 7.4428285367870146E+137) && (count + 1 < 20)); + + rescaledir = 1; + guard1 = true; + } else if (scale <= 1.3435752215134178E-138) { + if (((g.re == 0.0) && (g.im == 0.0)) || (std::isnan(g.re) || std:: + isnan(g.im))) { + *cs = 1.0; + sn->re = 0.0; + sn->im = 0.0; + *r = f; + } else { + do { + count++; + fs_re *= 7.4428285367870146E+137; + fs_im *= 7.4428285367870146E+137; + gs_re *= 7.4428285367870146E+137; + gs_im *= 7.4428285367870146E+137; + scale *= 7.4428285367870146E+137; + } while (!!(scale <= 1.3435752215134178E-138)); + + rescaledir = -1; + guard1 = true; + } + } else { + guard1 = true; + } + + if (guard1) { + real_T f2; + real_T g2; + f2 = fs_re * fs_re + fs_im * fs_im; + g2 = gs_re * gs_re + gs_im * gs_im; + scale = g2; + if (g2 < 1.0) { + scale = 1.0; + } + + if (f2 <= scale * 2.0041683600089728E-292) { + if ((f.re == 0.0) && (f.im == 0.0)) { + *cs = 0.0; + r->re = rt_hypotd_snf(g.re, g.im); + r->im = 0.0; + f2 = rt_hypotd_snf(gs_re, gs_im); + sn->re = gs_re / f2; + sn->im = -gs_im / f2; + } else { + g2 = std::sqrt(g2); + *cs = rt_hypotd_snf(fs_re, fs_im) / g2; + if (scale_tmp > 1.0) { + f2 = rt_hypotd_snf(f.re, f.im); + fs_re = f.re / f2; + fs_im = f.im / f2; + } else { + scale = 7.4428285367870146E+137 * f.re; + f2s = 7.4428285367870146E+137 * f.im; + f2 = rt_hypotd_snf(scale, f2s); + fs_re = scale / f2; + fs_im = f2s / f2; + } + + gs_re /= g2; + gs_im = -gs_im / g2; + sn->re = fs_re * gs_re - fs_im * gs_im; + sn->im = fs_re * gs_im + fs_im * gs_re; + r->re = *cs * f.re + (sn->re * g.re - sn->im * g.im); + r->im = *cs * f.im + (sn->re * g.im + sn->im * g.re); + } + } else { + f2s = std::sqrt(g2 / f2 + 1.0); + r->re = f2s * fs_re; + r->im = f2s * fs_im; + *cs = 1.0 / f2s; + f2 += g2; + f2s = r->re / f2; + scale = r->im / f2; + sn->re = f2s * gs_re - scale * -gs_im; + sn->im = f2s * -gs_im + scale * gs_re; + if (rescaledir > 0) { + for (int32_T i{0}; i <= count; i++) { + r->re *= 7.4428285367870146E+137; + r->im *= 7.4428285367870146E+137; + } + } else if (rescaledir < 0) { + for (int32_T i{0}; i <= count; i++) { + r->re *= 1.3435752215134178E-138; + r->im *= 1.3435752215134178E-138; + } + } + } + } + } + } + } + } +} + +// End of code generation (xzlartg.cpp) diff --git a/RAT/xzlartg.h b/RAT/xzlartg.h new file mode 100644 index 00000000..cefbef82 --- /dev/null +++ b/RAT/xzlartg.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlartg.h +// +// Code generation for function 'xzlartg' +// +#ifndef XZLARTG_H +#define XZLARTG_H + +// Include files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzlartg(const creal_T f, const creal_T g, real_T *cs, creal_T *sn); + void xzlartg(const creal_T f, const creal_T g, real_T *cs, creal_T *sn, + creal_T *r); + } + } + } +} + +#endif + +// End of code generation (xzlartg.h) diff --git a/RAT/xzlascl.cpp b/RAT/xzlascl.cpp new file mode 100644 index 00000000..43ff0991 --- /dev/null +++ b/RAT/xzlascl.cpp @@ -0,0 +1,102 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlascl.cpp +// +// Code generation for function 'xzlascl' +// + +// Include files +#include "xzlascl.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzlascl(real_T cfrom, real_T cto, ::coder::array &A) + { + real_T cfromc; + real_T ctoc; + boolean_T notdone; + cfromc = cfrom; + ctoc = cto; + notdone = true; + while (notdone) { + real_T a; + real_T cfrom1; + real_T cto1; + int32_T loop_ub; + cfrom1 = cfromc * 2.0041683600089728E-292; + cto1 = ctoc / 4.9896007738368E+291; + if ((std::abs(cfrom1) > std::abs(ctoc)) && (ctoc != 0.0)) { + a = 2.0041683600089728E-292; + cfromc = cfrom1; + } else if (std::abs(cto1) > std::abs(cfromc)) { + a = 4.9896007738368E+291; + ctoc = cto1; + } else { + a = ctoc / cfromc; + notdone = false; + } + + loop_ub = A.size(0); + for (int32_T i{0}; i < loop_ub; i++) { + A[i].re = a * A[i].re; + A[i].im = a * A[i].im; + } + } + } + + void xzlascl(real_T cfrom, real_T cto, ::coder::array &A) + { + real_T cfromc; + real_T ctoc; + boolean_T notdone; + cfromc = cfrom; + ctoc = cto; + notdone = true; + while (notdone) { + real_T a; + real_T cfrom1; + real_T cto1; + int32_T loop_ub; + cfrom1 = cfromc * 2.0041683600089728E-292; + cto1 = ctoc / 4.9896007738368E+291; + if ((std::abs(cfrom1) > std::abs(ctoc)) && (ctoc != 0.0)) { + a = 2.0041683600089728E-292; + cfromc = cfrom1; + } else if (std::abs(cto1) > std::abs(cfromc)) { + a = 4.9896007738368E+291; + ctoc = cto1; + } else { + a = ctoc / cfromc; + notdone = false; + } + + loop_ub = A.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + int32_T b_loop_ub; + b_loop_ub = A.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + A[i1 + A.size(0) * i].re = a * A[i1 + A.size(0) * i].re; + A[i1 + A.size(0) * i].im = a * A[i1 + A.size(0) * i].im; + } + } + } + } + } + } + } +} + +// End of code generation (xzlascl.cpp) diff --git a/RAT/xzlascl.h b/RAT/xzlascl.h new file mode 100644 index 00000000..e394a31a --- /dev/null +++ b/RAT/xzlascl.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzlascl.h +// +// Code generation for function 'xzlascl' +// +#ifndef XZLASCL_H +#define XZLASCL_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzlascl(real_T cfrom, real_T cto, ::coder::array &A); + void xzlascl(real_T cfrom, real_T cto, ::coder::array &A); + } + } + } +} + +#endif + +// End of code generation (xzlascl.h) diff --git a/RAT/xztgevc.cpp b/RAT/xztgevc.cpp new file mode 100644 index 00000000..750f16c7 --- /dev/null +++ b/RAT/xztgevc.cpp @@ -0,0 +1,338 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xztgevc.cpp +// +// Code generation for function 'xztgevc' +// + +// Include files +#include "xztgevc.h" +#include "RATMain_data.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xztgevc(const ::coder::array &A, ::coder::array< + creal_T, 2U> &V) + { + ::coder::array work1; + ::coder::array work2; + ::coder::array rworka; + real_T BIG; + real_T BIGNUM; + real_T NSAFMIN; + real_T SMALL; + real_T anorm; + real_T ascale; + real_T x; + real_T y; + int32_T b_i; + int32_T i; + int32_T n; + n = A.size(0); + work1.set_size(A.size(0)); + i = A.size(0); + for (b_i = 0; b_i < i; b_i++) { + work1[b_i].re = 0.0; + work1[b_i].im = 0.0; + } + + work2.set_size(A.size(0)); + i = A.size(0); + for (b_i = 0; b_i < i; b_i++) { + work2[b_i].re = 0.0; + work2[b_i].im = 0.0; + } + + NSAFMIN = 2.2250738585072014E-308 * static_cast(A.size(0)); + SMALL = NSAFMIN / 2.2204460492503131E-16; + BIG = 1.0 / SMALL; + BIGNUM = 1.0 / NSAFMIN; + rworka.set_size(A.size(0)); + i = A.size(0); + for (b_i = 0; b_i < i; b_i++) { + rworka[b_i] = 0.0; + } + + anorm = std::abs(A[0].re) + std::abs(A[0].im); + for (int32_T j{2}; j <= n; j++) { + for (i = 0; i <= j - 2; i++) { + rworka[j - 1] = rworka[j - 1] + (std::abs(A[i + A.size(0) * (j - 1)] + .re) + std::abs(A[i + A.size(0) * (j - 1)].im)); + } + + y = rworka[j - 1] + (std::abs(A[(j + A.size(0) * (j - 1)) - 1].re) + + std::abs(A[(j + A.size(0) * (j - 1)) - 1].im)); + if (y > anorm) { + anorm = y; + } + } + + x = anorm; + if (anorm < 2.2250738585072014E-308) { + x = 2.2250738585072014E-308; + } + + ascale = 1.0 / x; + for (int32_T je{n}; je >= 1; je--) { + real_T acoeff; + real_T dmin; + real_T salpha_im; + real_T salpha_re; + real_T scale; + real_T temp; + boolean_T lscalea; + boolean_T lscaleb; + NSAFMIN = A[(je + A.size(0) * (je - 1)) - 1].re; + y = A[(je + A.size(0) * (je - 1)) - 1].im; + x = (std::abs(NSAFMIN) + std::abs(y)) * ascale; + if (x < 1.0) { + x = 1.0; + } + + temp = 1.0 / x; + salpha_re = ascale * (temp * NSAFMIN); + salpha_im = ascale * (temp * y); + acoeff = temp * ascale; + if ((temp >= 2.2250738585072014E-308) && (acoeff < SMALL)) { + lscalea = true; + } else { + lscalea = false; + } + + NSAFMIN = std::abs(salpha_re) + std::abs(salpha_im); + if ((NSAFMIN >= 2.2250738585072014E-308) && (NSAFMIN < SMALL)) { + lscaleb = true; + } else { + lscaleb = false; + } + + scale = 1.0; + if (lscalea) { + x = anorm; + if (BIG < anorm) { + x = BIG; + } + + scale = SMALL / temp * x; + } + + if (lscaleb) { + y = SMALL / NSAFMIN; + if (y > scale) { + scale = y; + } + } + + if (lscalea || lscaleb) { + x = acoeff; + if (acoeff < 1.0) { + x = 1.0; + } + + if (NSAFMIN > x) { + x = NSAFMIN; + } + + y = 1.0 / (2.2250738585072014E-308 * x); + if (y < scale) { + scale = y; + } + + if (lscalea) { + acoeff = ascale * (scale * temp); + } else { + acoeff *= scale; + } + + salpha_re *= scale; + salpha_im *= scale; + } + + for (int32_T jr{0}; jr < n; jr++) { + work1[jr].re = 0.0; + work1[jr].im = 0.0; + } + + work1[je - 1].re = 1.0; + work1[je - 1].im = 0.0; + dmin = 2.2204460492503131E-16 * acoeff * anorm; + y = 2.2204460492503131E-16 * (std::abs(salpha_re) + std::abs + (salpha_im)); + if (y > dmin) { + dmin = y; + } + + if (dmin < 2.2250738585072014E-308) { + dmin = 2.2250738585072014E-308; + } + + for (int32_T jr{0}; jr <= je - 2; jr++) { + work1[jr].re = acoeff * A[jr + A.size(0) * (je - 1)].re; + work1[jr].im = acoeff * A[jr + A.size(0) * (je - 1)].im; + } + + work1[je - 1].re = 1.0; + work1[je - 1].im = 0.0; + b_i = je - 1; + for (int32_T j{b_i}; j >= 1; j--) { + real_T brm; + real_T d_im; + real_T d_re; + d_re = acoeff * A[(j + A.size(0) * (j - 1)) - 1].re - salpha_re; + d_im = acoeff * A[(j + A.size(0) * (j - 1)) - 1].im - salpha_im; + if (std::abs(d_re) + std::abs(d_im) <= dmin) { + d_re = dmin; + d_im = 0.0; + } + + brm = std::abs(d_re); + y = std::abs(d_im); + NSAFMIN = brm + y; + if (NSAFMIN < 1.0) { + scale = std::abs(work1[j - 1].re) + std::abs(work1[j - 1].im); + if (scale >= BIGNUM * NSAFMIN) { + temp = 1.0 / scale; + for (int32_T jr{0}; jr < je; jr++) { + work1[jr].re = temp * work1[jr].re; + work1[jr].im = temp * work1[jr].im; + } + } + } + + NSAFMIN = work1[j - 1].re; + x = -work1[j - 1].re; + scale = work1[j - 1].im; + temp = -work1[j - 1].im; + if (d_im == 0.0) { + if (-scale == 0.0) { + y = -NSAFMIN / d_re; + NSAFMIN = 0.0; + } else if (-NSAFMIN == 0.0) { + y = 0.0; + NSAFMIN = -scale / d_re; + } else { + y = -NSAFMIN / d_re; + NSAFMIN = -scale / d_re; + } + } else if (d_re == 0.0) { + if (-NSAFMIN == 0.0) { + y = -scale / d_im; + NSAFMIN = 0.0; + } else if (-scale == 0.0) { + y = 0.0; + NSAFMIN = -(-NSAFMIN / d_im); + } else { + y = -scale / d_im; + NSAFMIN = -(-NSAFMIN / d_im); + } + } else if (brm > y) { + scale = d_im / d_re; + NSAFMIN = d_re + scale * d_im; + y = (x + scale * temp) / NSAFMIN; + NSAFMIN = (temp - scale * x) / NSAFMIN; + } else if (y == brm) { + if (d_re > 0.0) { + scale = 0.5; + } else { + scale = -0.5; + } + + if (d_im > 0.0) { + NSAFMIN = 0.5; + } else { + NSAFMIN = -0.5; + } + + y = (x * scale + temp * NSAFMIN) / brm; + NSAFMIN = (temp * scale - x * NSAFMIN) / brm; + } else { + scale = d_re / d_im; + NSAFMIN = d_im + scale * d_re; + y = (scale * x + temp) / NSAFMIN; + NSAFMIN = (scale * temp - x) / NSAFMIN; + } + + work1[j - 1].re = y; + work1[j - 1].im = NSAFMIN; + if (j > 1) { + NSAFMIN = std::abs(y) + std::abs(NSAFMIN); + if (NSAFMIN > 1.0) { + temp = 1.0 / NSAFMIN; + if (acoeff * rworka[j - 1] >= BIGNUM * temp) { + for (int32_T jr{0}; jr < je; jr++) { + work1[jr].re = temp * work1[jr].re; + work1[jr].im = temp * work1[jr].im; + } + } + } + + d_re = acoeff * work1[j - 1].re; + d_im = acoeff * work1[j - 1].im; + for (int32_T jr{0}; jr <= j - 2; jr++) { + NSAFMIN = A[jr + A.size(0) * (j - 1)].im; + x = A[jr + A.size(0) * (j - 1)].re; + work1[jr].re = work1[jr].re + (d_re * x - d_im * NSAFMIN); + work1[jr].im = work1[jr].im + (d_re * NSAFMIN + d_im * x); + } + } + } + + for (int32_T jr{0}; jr < n; jr++) { + work2[jr].re = 0.0; + work2[jr].im = 0.0; + } + + for (i = 0; i < je; i++) { + for (int32_T jr{0}; jr < n; jr++) { + NSAFMIN = V[jr + V.size(0) * i].re; + y = work1[i].im; + scale = V[jr + V.size(0) * i].im; + x = work1[i].re; + work2[jr].re = work2[jr].re + (NSAFMIN * x - scale * y); + work2[jr].im = work2[jr].im + (NSAFMIN * y + scale * x); + } + } + + NSAFMIN = std::abs(work2[0].re) + std::abs(work2[0].im); + if (n > 1) { + for (int32_T jr{2}; jr <= n; jr++) { + y = std::abs(work2[jr - 1].re) + std::abs(work2[jr - 1].im); + if (y > NSAFMIN) { + NSAFMIN = y; + } + } + } + + if (NSAFMIN > 2.2250738585072014E-308) { + temp = 1.0 / NSAFMIN; + for (int32_T jr{0}; jr < n; jr++) { + V[jr + V.size(0) * (je - 1)].re = temp * work2[jr].re; + V[jr + V.size(0) * (je - 1)].im = temp * work2[jr].im; + } + } else { + for (int32_T jr{0}; jr < n; jr++) { + V[jr + V.size(0) * (je - 1)].re = 0.0; + V[jr + V.size(0) * (je - 1)].im = 0.0; + } + } + } + } + } + } + } +} + +// End of code generation (xztgevc.cpp) diff --git a/RAT/xztgevc.h b/RAT/xztgevc.h new file mode 100644 index 00000000..af942c9c --- /dev/null +++ b/RAT/xztgevc.h @@ -0,0 +1,37 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xztgevc.h +// +// Code generation for function 'xztgevc' +// +#ifndef XZTGEVC_H +#define XZTGEVC_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xztgevc(const ::coder::array &A, ::coder::array< + creal_T, 2U> &V); + } + } + } +} + +#endif + +// End of code generation (xztgevc.h) diff --git a/RAT/xzungqr.cpp b/RAT/xzungqr.cpp new file mode 100644 index 00000000..280f49f4 --- /dev/null +++ b/RAT/xzungqr.cpp @@ -0,0 +1,86 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzungqr.cpp +// +// Code generation for function 'xzungqr' +// + +// Include files +#include "xzungqr.h" +#include "rt_nonfinite.h" +#include "xzlarf.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzungqr(int32_T m, int32_T n, int32_T k, ::coder::array + &A, int32_T ia0, int32_T lda, const ::coder::array &tau) + { + ::coder::array work; + if (n >= 1) { + int32_T i; + int32_T ia; + int32_T iaii; + int32_T itau; + i = n - 1; + for (int32_T j{k}; j <= i; j++) { + ia = (ia0 + j * lda) - 1; + iaii = m - 1; + for (int32_T b_i{0}; b_i <= iaii; b_i++) { + A[ia + b_i] = 0.0; + } + + A[ia + j] = 1.0; + } + + uint32_T unnamed_idx_0; + itau = k - 1; + unnamed_idx_0 = static_cast(A.size(1)); + work.set_size(static_cast(unnamed_idx_0)); + ia = static_cast(unnamed_idx_0); + for (i = 0; i < ia; i++) { + work[i] = 0.0; + } + + for (int32_T b_i{k}; b_i >= 1; b_i--) { + iaii = ((ia0 + b_i) + (b_i - 1) * lda) - 1; + if (b_i < n) { + A[iaii - 1] = 1.0; + c_xzlarf((m - b_i) + 1, n - b_i, iaii, tau[itau], A, iaii + lda, + lda, work); + } + + if (b_i < m) { + ia = iaii + 1; + i = (iaii + m) - b_i; + for (int32_T j{ia}; j <= i; j++) { + A[j - 1] = -tau[itau] * A[j - 1]; + } + } + + A[iaii - 1] = 1.0 - tau[itau]; + for (int32_T j{0}; j <= b_i - 2; j++) { + A[(iaii - j) - 2] = 0.0; + } + + itau--; + } + } + } + } + } + } +} + +// End of code generation (xzungqr.cpp) diff --git a/RAT/xzungqr.h b/RAT/xzungqr.h new file mode 100644 index 00000000..16f17d79 --- /dev/null +++ b/RAT/xzungqr.h @@ -0,0 +1,38 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// xzungqr.h +// +// Code generation for function 'xzungqr' +// +#ifndef XZUNGQR_H +#define XZUNGQR_H + +// Include files +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +namespace RAT +{ + namespace coder + { + namespace internal + { + namespace reflapack + { + void xzungqr(int32_T m, int32_T n, int32_T k, ::coder::array + &A, int32_T ia0, int32_T lda, const ::coder::array &tau); + } + } + } +} + +#endif + +// End of code generation (xzungqr.h) diff --git a/README.md b/README.md index 1249b1d9..e510c89e 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,11 @@ Build ===== This has been tested using python 3.8, a c++ compiler is required to run the code. Install the requirement then run the example, if the compiler can be found, the python extension (*.pyd) will be built and the example will run + +Notes +===== +The following files need to be copied to the generated c++ + +1. tmwtypes.h from matlabroot\extern\include +2. eventHelper.hpp from compile/events +3. dylib.hpp, classHandle.hpp from compile/customWrapper \ No newline at end of file diff --git a/rat.cpp b/rat.cpp index db52c9e0..86cb57d7 100644 --- a/rat.cpp +++ b/rat.cpp @@ -1,45 +1,153 @@ /*<% -cfg['include_dirs'] = ['D:/Anaconda/lib/site-packages/pybind11/include'] import glob -cfg['sources'] = glob.glob('RAT/*.cpp') +cfg['sources'] = [*glob.glob('RAT/*.cpp'), *glob.glob('RAT/*.c')] cfg['parallel'] = True setup_pybind11(cfg) %>*/ #include #include -#include "RAT/reflectivityCalculation.h" -#include "RAT/reflectivityCalculation_types.h" +#include "RAT/RATMain.h" +#include "RAT/RATMain_initialize.h" +#include "RAT/RATMain_terminate.h" +#include "RAT/RATMain_types.h" namespace py = pybind11; +struct Predlims +{ + py::list refPredInts; + py::list sldPredInts; + py::list refXdata; + py::list sldXdata; + py::array_t sampleChi; +}; + +struct BestFitsMean +{ + py::list ref; + py::list sld; + real_T chi; + py::list data; +}; + +struct ParConfInts +{ + py::array_t par95; + py::array_t par65; + py::array_t mean; +}; + +struct NestOutput +{ + real_T logZ; + py::array_t nestSamples; + py::array_t postSamples; +}; + +struct DREAMPars +{ + real_T d; + real_T N; + real_T T; + boolean_T parallel; + real_T CPU; + real_T lambda; + real_T pUnitGamma; + real_T nCR; + real_T delta; + real_T steps; + real_T zeta; + std::string outlier; + boolean_T adaptPCR; + real_T thinning; + real_T epsilon; + boolean_T ABC; + boolean_T IO; + boolean_T modout; + boolean_T restart; + boolean_T save; + py::array_t R; +}; + +struct MeasInfo +{ + real_T Y; + real_T N; +}; + +struct DreamOutput +{ + py::array_t outlier; + real_T runtime; + DREAMPars DREAMPar; + MeasInfo Meas_info; + real_T iteration; + real_T iloc; + real_T fx; + py::array_t AR; + py::array_t R_stat; + py::array_t CR; +}; + +struct BayesOutput +{ + py::array_t allChains; + DreamOutput dreamOutput; + NestOutput nestOutput; +}; + +struct BayesResults +{ + BestFitsMean bestFitsMean; + Predlims predlims; + ParConfInts parConfInts; + py::array_t bestPars; + BayesOutput bayesRes; + py::array_t chain; +}; + +struct Priors +{ + py::list param; + py::list backgroundParam; + py::list resolutionParam; + py::list bulkIn; + py::list bulkOut; + py::list qzshift; + py::list scalefactor; + py::list domainRatio; + py::list priorNames; + py::array_t priorValues; +}; + struct Checks { - py::array_t params_fitYesNo; - py::array_t backs_fitYesNo; - py::array_t shifts_fitYesNo; - py::array_t scales_fitYesNo; - py::array_t nbairs_fitYesNo; - py::array_t nbsubs_fitYesNo; - py::array_t resol_fitYesNo; - py::array_t domainRatio_fitYesNo; + py::array_t fitParam; + py::array_t fitBackgroundParam; + py::array_t fitQzshift; + py::array_t fitScalefactor; + py::array_t fitBulkIn; + py::array_t fitBulkOut; + py::array_t fitResolutionParam; + py::array_t fitDomainRatio; }; struct Calculation { - py::array_t all_chis; - real_T sum_chi; + py::array_t allChis; + real_T sumChi; }; struct OutputProblem { py::array_t ssubs; - py::array_t backgrounds; - py::array_t qshifts; + py::array_t backgroundParams; + py::array_t qzshifts; py::array_t scalefactors; - py::array_t nbairs; - py::array_t nbsubs; - py::array_t resolutions; + py::array_t bulkIn; + py::array_t bulkOut; + py::array_t resolutionParams; Calculation calculations {}; py::array_t allSubRough; py::array_t resample; @@ -55,13 +163,13 @@ struct OutputResult { }; struct Limits { - py::array_t params; - py::array_t backs; - py::array_t scales; - py::array_t shifts; - py::array_t nba; - py::array_t nbs; - py::array_t res; + py::array_t param; + py::array_t backgroundParam; + py::array_t scalefactor; + py::array_t qzshift; + py::array_t bulkIn; + py::array_t bulkOut; + py::array_t resolutionParam; py::array_t domainRatio; }; @@ -89,8 +197,8 @@ struct Cells { }; struct ProblemDefinition { - py::array_t contrastBacks; - py::array_t contrastBacksType; + py::array_t contrastBackgrounds; + py::array_t contrastBackgroundsType; std::string TF {}; py::array_t resample; py::array_t dataPresent; @@ -98,17 +206,17 @@ struct ProblemDefinition { real_T numberOfContrasts; std::string geometry {}; bool useImaginary {}; - py::array_t contrastShifts; - py::array_t contrastScales; - py::array_t contrastNbas; - py::array_t contrastNbss; - py::array_t contrastRes; - py::array_t backs; - py::array_t shifts; - py::array_t sf; - py::array_t nba; - py::array_t nbs; - py::array_t res; + py::array_t contrastQzshifts; + py::array_t contrastScalefactors; + py::array_t contrastBulkIns; + py::array_t contrastBulkOuts; + py::array_t contrastResolutions; + py::array_t backgroundParams; + py::array_t qzshifts; + py::array_t scalefactors; + py::array_t bulkIn; + py::array_t bulkOut; + py::array_t resolutionParams; py::array_t params; real_T numberOfLayers {}; std::string modelType {}; @@ -116,16 +224,15 @@ struct ProblemDefinition { py::array_t contrastDomainRatios; py::array_t domainRatio; real_T numberOfDomainContrasts {}; - py::array_t domainContrastCustomFiles; - py::array_t fitpars; - py::array_t otherpars; - py::array_t fitconstr; - py::array_t otherconstr; + py::array_t fitParams; + py::array_t otherParams; + py::array_t fitLimits; + py::array_t otherLimits; }; struct Control { - std::string para {}; - std::string proc {}; + std::string parallel {}; + std::string procedure {}; std::string display {}; real_T tolX {}; real_T tolFun {}; @@ -133,23 +240,24 @@ struct Control { real_T maxIter {}; real_T populationSize {}; real_T fWeight {}; - real_T F_CR {}; - real_T VTR {}; - real_T numGen {}; + real_T crossoverProbability {}; + real_T targetValue {}; + real_T numGenerations {}; real_T strategy {}; real_T Nlive {}; - real_T nmcmc {}; + real_T Nmcmc {}; real_T propScale {}; real_T nsTolerance {}; - real_T calcSld {}; + boolean_T calcSldDuringFit {}; py::array_t resamPars; real_T updateFreq {}; real_T updatePlotFreq {}; real_T nSamples {}; real_T nChains {}; - real_T lambda {}; + real_T jumpProbability {}; real_T pUnitGamma {}; std::string boundHandling {}; + boolean_T adaptPCR; Checks checks {}; }; @@ -159,12 +267,20 @@ void string_to_rat_array(std::string value, char_T result_data[], int32_T result result_size[0] = 1; result_size[1] = value.length(); - // Loop over the array to initialize each element. for (int32_T idx1{0}; idx1 < value.length(); idx1++) { result_data[idx1] = value[idx1]; } } +void string_to_rat_char_array(std::string value, coder::array& result) +{ + result.set_size(1, value.length()); + + for (int32_T idx{0}; idx < value.length(); idx++) { + result[idx] = value[idx]; + } +} + coder::array py_array_to_rat_1d_array(py::array_t value) { coder::array result; @@ -178,7 +294,6 @@ coder::array py_array_to_rat_1d_array(py::array_t value) throw std::runtime_error("Number of dimensions must be 1"); result.set_size(1, buffer_info.shape[0]); - // Loop over the array to initialize each element. for (int32_T idx0{0}; idx0 < buffer_info.shape[0]; idx0++) { result[idx0] = value.at(idx0); } @@ -186,29 +301,28 @@ coder::array py_array_to_rat_1d_array(py::array_t value) return result; } -coder::bounded_array py_array_to_rat_bounded_array2(py::array_t value) -{ - coder::bounded_array result {}; +// coder::bounded_array py_array_to_rat_bounded_array2(py::array_t value) +// { +// coder::bounded_array result {}; - py::buffer_info buffer_info = value.request(); +// py::buffer_info buffer_info = value.request(); - if (buffer_info.size == 0) - return result; +// if (buffer_info.size == 0) +// return result; - if (buffer_info.ndim != 1) - throw std::runtime_error("Number of dimensions must be 1"); +// if (buffer_info.ndim != 1) +// throw std::runtime_error("Number of dimensions must be 1"); - result.size[0] = 1; - result.size[1] = buffer_info.shape[0]; - // Loop over the array to initialize each element. - for (int32_T idx0{0}; idx0 < buffer_info.shape[0]; idx0++) { - result.data[idx0] = value.at(idx0); - } +// result.size[0] = 1; +// result.size[1] = buffer_info.shape[0]; +// for (int32_T idx0{0}; idx0 < buffer_info.shape[0]; idx0++) { +// result.data[idx0] = value.at(idx0); +// } - return result; -} +// return result; +// } -coder::bounded_array py_array_to_rat_bounded_array1(py::array_t value) +coder::bounded_array py_array_to_rat_bounded_array(py::array_t value) { coder::bounded_array result {}; @@ -222,7 +336,6 @@ coder::bounded_array py_array_to_rat_bounded_array1(py::array_t result.size[0] = 1; result.size[1] = buffer_info.shape[0]; - // Loop over the array to initialize each element. for (int32_T idx0{0}; idx0 < buffer_info.shape[0]; idx0++) { result.data[idx0] = value.at(idx0); } @@ -245,7 +358,6 @@ coder::array py_array_to_rat_2d_array(py::array_t value) result.set_size(buffer_info.shape[0], buffer_info.shape[1]); int32_T idx {0}; - // Loop over the array to initialize each element. for (int32_T idx0{0}; idx0 < buffer_info.shape[0]; idx0++) { for (int32_T idx1{0}; idx1 < buffer_info.shape[1]; idx1++) { idx = idx0 + result.size(0) * idx1; @@ -256,6 +368,42 @@ coder::array py_array_to_rat_2d_array(py::array_t value) return result; } +coder::array py_array_to_unboundedx1_cell_0(py::list values) +{ + coder::array result; + result.set_size(values.size()); + int32_T idx {0}; + for (py::handle list: values) + { + py::list value = py::cast(list); + if (py::len(list) != 4) + throw std::runtime_error("Number of dimensions for each row must be 4"); + string_to_rat_char_array(value[0].cast(), result[idx].f1); + string_to_rat_char_array(value[1].cast(), result[idx].f2); + result[idx].f3 = value[2].cast(); + result[idx].f4 = value[3].cast(); + idx++; + } + + return result; +} + +coder::array py_array_to_unboundedx1_cell_1(py::list values) +{ + coder::array result; + result.set_size(values.size()); + int32_T idx {0}; + for (py::handle list: values) + { + std::string value = py::cast(list); + //TODO: validate dimension + string_to_rat_char_array(value, result[idx].f1); + idx++; + } + + return result; +} + RAT::struct0_T create_struct0_T(const ProblemDefinition& problem) { RAT::struct0_T problem_struct; @@ -270,33 +418,32 @@ RAT::struct0_T create_struct0_T(const ProblemDefinition& problem) string_to_rat_array(problem.geometry, problem_struct.geometry.data, problem_struct.geometry.size); string_to_rat_array(problem.TF, problem_struct.TF.data, problem_struct.TF.size); - problem_struct.contrastBacks = py_array_to_rat_1d_array(problem.contrastBacks); - problem_struct.contrastBacksType = py_array_to_rat_1d_array(problem.contrastBacksType); + problem_struct.contrastBackgrounds = py_array_to_rat_1d_array(problem.contrastBackgrounds); + problem_struct.contrastBackgroundsType = py_array_to_rat_1d_array(problem.contrastBackgroundsType); problem_struct.resample = py_array_to_rat_1d_array(problem.resample); problem_struct.dataPresent = py_array_to_rat_1d_array(problem.dataPresent); problem_struct.oilChiDataPresent = py_array_to_rat_1d_array(problem.oilChiDataPresent); - problem_struct.contrastShifts = py_array_to_rat_1d_array(problem.contrastShifts); - problem_struct.contrastScales = py_array_to_rat_1d_array(problem.contrastScales); - problem_struct.contrastNbas = py_array_to_rat_1d_array(problem.contrastNbas); - problem_struct.contrastNbss = py_array_to_rat_1d_array(problem.contrastNbss); - problem_struct.contrastRes = py_array_to_rat_1d_array(problem.contrastRes); - problem_struct.backs = py_array_to_rat_1d_array(problem.backs); - problem_struct.shifts = py_array_to_rat_1d_array(problem.shifts); - problem_struct.sf = py_array_to_rat_1d_array(problem.sf); - problem_struct.nba = py_array_to_rat_1d_array(problem.nba); - problem_struct.nbs = py_array_to_rat_1d_array(problem.nbs); - problem_struct.res = py_array_to_rat_1d_array(problem.res); + problem_struct.contrastQzshifts = py_array_to_rat_1d_array(problem.contrastQzshifts); + problem_struct.contrastScalefactors = py_array_to_rat_1d_array(problem.contrastScalefactors); + problem_struct.contrastBulkIns = py_array_to_rat_1d_array(problem.contrastBulkIns); + problem_struct.contrastBulkOuts = py_array_to_rat_1d_array(problem.contrastBulkOuts); + problem_struct.contrastResolutions = py_array_to_rat_1d_array(problem.contrastResolutions); + problem_struct.backgroundParams = py_array_to_rat_1d_array(problem.backgroundParams); + problem_struct.qzshifts = py_array_to_rat_1d_array(problem.qzshifts); + problem_struct.scalefactors = py_array_to_rat_1d_array(problem.scalefactors); + problem_struct.bulkIn = py_array_to_rat_1d_array(problem.bulkIn); + problem_struct.bulkOut = py_array_to_rat_1d_array(problem.bulkOut); + problem_struct.resolutionParams = py_array_to_rat_1d_array(problem.resolutionParams); problem_struct.params = py_array_to_rat_1d_array(problem.params); problem_struct.contrastCustomFiles = py_array_to_rat_1d_array(problem.contrastCustomFiles); problem_struct.contrastDomainRatios = py_array_to_rat_1d_array(problem.contrastDomainRatios); problem_struct.domainRatio = py_array_to_rat_1d_array(problem.domainRatio); - problem_struct.domainContrastCustomFiles = py_array_to_rat_1d_array(problem.domainContrastCustomFiles); - problem_struct.fitpars = py_array_to_rat_1d_array(problem.fitpars); - problem_struct.otherpars = py_array_to_rat_1d_array(problem.otherpars); - problem_struct.fitconstr = py_array_to_rat_2d_array(problem.fitconstr); - problem_struct.otherconstr = py_array_to_rat_2d_array(problem.otherconstr); + problem_struct.fitParams = py_array_to_rat_1d_array(problem.fitParams); + problem_struct.otherParams = py_array_to_rat_1d_array(problem.otherParams); + problem_struct.fitLimits = py_array_to_rat_2d_array(problem.fitLimits); + problem_struct.otherLimits = py_array_to_rat_2d_array(problem.otherLimits); return problem_struct; } @@ -304,13 +451,13 @@ RAT::struct0_T create_struct0_T(const ProblemDefinition& problem) RAT::struct1_T create_struct1_T(const Limits& limits) { RAT::struct1_T limits_struct; - limits_struct.params = py_array_to_rat_2d_array(limits.params); - limits_struct.backs = py_array_to_rat_2d_array(limits.backs); - limits_struct.shifts = py_array_to_rat_2d_array(limits.shifts); - limits_struct.scales = py_array_to_rat_2d_array(limits.scales); - limits_struct.nba = py_array_to_rat_2d_array(limits.nba); - limits_struct.nbs = py_array_to_rat_2d_array(limits.nbs); - limits_struct.res = py_array_to_rat_2d_array(limits.res); + limits_struct.param = py_array_to_rat_2d_array(limits.param); + limits_struct.backgroundParam = py_array_to_rat_2d_array(limits.backgroundParam); + limits_struct.qzshift = py_array_to_rat_2d_array(limits.qzshift); + limits_struct.scalefactor = py_array_to_rat_2d_array(limits.scalefactor); + limits_struct.bulkIn = py_array_to_rat_2d_array(limits.bulkIn); + limits_struct.bulkOut = py_array_to_rat_2d_array(limits.bulkOut); + limits_struct.resolutionParam = py_array_to_rat_2d_array(limits.resolutionParam); limits_struct.domainRatio = py_array_to_rat_2d_array(limits.domainRatio); return limits_struct; @@ -319,47 +466,33 @@ RAT::struct1_T create_struct1_T(const Limits& limits) RAT::struct3_T create_struct3_T(const Checks& checks) { RAT::struct3_T checks_struct; - checks_struct.params_fitYesNo = py_array_to_rat_1d_array(checks.params_fitYesNo); - checks_struct.backs_fitYesNo = py_array_to_rat_1d_array(checks.backs_fitYesNo); - checks_struct.shifts_fitYesNo = py_array_to_rat_1d_array(checks.shifts_fitYesNo); - checks_struct.scales_fitYesNo = py_array_to_rat_1d_array(checks.scales_fitYesNo); - checks_struct.nbairs_fitYesNo = py_array_to_rat_1d_array(checks.nbairs_fitYesNo); - checks_struct.nbsubs_fitYesNo = py_array_to_rat_1d_array(checks.nbsubs_fitYesNo); - checks_struct.resol_fitYesNo = py_array_to_rat_1d_array(checks.resol_fitYesNo); - checks_struct.domainRatio_fitYesNo = py_array_to_rat_1d_array(checks.domainRatio_fitYesNo); + checks_struct.fitParam = py_array_to_rat_1d_array(checks.fitParam); + checks_struct.fitBackgroundParam = py_array_to_rat_1d_array(checks.fitBackgroundParam); + checks_struct.fitQzshift = py_array_to_rat_1d_array(checks.fitQzshift); + checks_struct.fitScalefactor = py_array_to_rat_1d_array(checks.fitScalefactor); + checks_struct.fitBulkIn = py_array_to_rat_1d_array(checks.fitBulkIn); + checks_struct.fitBulkOut = py_array_to_rat_1d_array(checks.fitBulkOut); + checks_struct.fitResolutionParam = py_array_to_rat_1d_array(checks.fitResolutionParam); + checks_struct.fitDomainRatio = py_array_to_rat_1d_array(checks.fitDomainRatio); return checks_struct; } -coder::array py_array_to_rat_cell_wrap_0(py::list values) -{ - coder::array result; - result.set_size(1, values.size()); - int32_T idx {0}; - for (py::handle array: values) - { - py::array_t casted_array = py::cast(array); - result[idx].f1[0] = casted_array.at(0); - result[idx].f1[1] = casted_array.at(1); - idx++; - } - - return result; -} - -coder::array py_array_to_rat_cell_wrap_1(py::list values) +RAT::struct4_T create_struct4_T(const Priors& priors) { - coder::array result; - result.set_size(1, values.size()); - int32_T idx {0}; - for (py::handle array: values) - { - py::array_t casted_array = py::cast(array); - result[idx].f1 = py_array_to_rat_2d_array(casted_array); - idx++; - } - - return result; + RAT::struct4_T priors_struct; + priors_struct.param = py_array_to_unboundedx1_cell_0(priors.param); + priors_struct.backgroundParam = py_array_to_unboundedx1_cell_0(priors.backgroundParam); + priors_struct.resolutionParam = py_array_to_unboundedx1_cell_0(priors.resolutionParam); + priors_struct.qzshift = py_array_to_unboundedx1_cell_0(priors.qzshift); + priors_struct.scalefactor = py_array_to_unboundedx1_cell_0(priors.scalefactor); + priors_struct.bulkIn = py_array_to_unboundedx1_cell_0(priors.bulkIn); + priors_struct.bulkOut = py_array_to_unboundedx1_cell_0(priors.bulkOut); + priors_struct.domainRatio = py_array_to_unboundedx1_cell_0(priors.domainRatio); + priors_struct.priorNames = py_array_to_unboundedx1_cell_1(priors.priorNames); + priors_struct.priorValues = py_array_to_rat_2d_array(priors.priorValues); + + return priors_struct; } coder::array py_array_to_rat_cell_wrap_2(py::list values) @@ -370,7 +503,8 @@ coder::array py_array_to_rat_cell_wrap_2(py::list values) for (py::handle array: values) { py::array_t casted_array = py::cast(array); - result[idx].f1 = py_array_to_rat_bounded_array2(casted_array); + result[idx].f1[0] = casted_array.at(0); + result[idx].f1[1] = casted_array.at(1); idx++; } @@ -385,38 +519,37 @@ coder::array py_array_to_rat_cell_wrap_3(py::list values) for (py::handle array: values) { py::array_t casted_array = py::cast(array); - RAT::cell_wrap_3 temp; - result[idx].f1 = py_array_to_rat_1d_array(casted_array); + result[idx].f1 = py_array_to_rat_2d_array(casted_array); idx++; } return result; } -coder::array py_array_to_rat_cell_wrap_4(py::list values) +coder::array py_array_to_rat_cell_wrap_4(py::list values) { - coder::array result; - result.set_size(values.size()); + coder::array result; + result.set_size(1, values.size()); int32_T idx {0}; for (py::handle array: values) { py::array_t casted_array = py::cast(array); - result[idx].f1 = py_array_to_rat_bounded_array1(casted_array); + result[idx].f1 = py_array_to_rat_1d_array(casted_array); idx++; } return result; } -coder::array py_array_to_rat_cell_wrap_5(py::list values) +coder::array py_array_to_rat_cell_wrap_5(py::list values) { - coder::array result; - result.set_size(1, values.size()); + coder::array result; + result.set_size(values.size()); int32_T idx {0}; for (py::handle array: values) { - std::string name = py::cast(array); - string_to_rat_array(name, result[idx].f1.data, result[idx].f1.size); + py::array_t casted_array = py::cast(array); + result[idx].f1 = py_array_to_rat_bounded_array(casted_array); idx++; } @@ -438,50 +571,28 @@ coder::array py_array_to_rat_cell_wrap_6(py::list values) return result; } -coder::array py_array_to_rat_cell_wrap_7(py::list values) -{ - coder::array result; - result.set_size(1, values.size()); - int32_T idx {0}; - for (py::handle value: values) - { - py::list casted_array = py::cast(value); - - int32_T idx1 {0}; - for (py::handle array: casted_array) - { - std::string name = py::cast(array); - string_to_rat_array(name, result[idx].f1[idx1].f1.data, result[idx].f1[idx1].f1.size); - idx1++; - } - idx++; - } - - return result; -} - -RAT::cell_8 create_cell_8(const Cells& cells) +RAT::cell_7 create_cell_7(const Cells& cells) { - RAT::cell_8 cells_struct; - cells_struct.f1 = py_array_to_rat_cell_wrap_0(cells.f1); - cells_struct.f2 = py_array_to_rat_cell_wrap_1(cells.f2); - cells_struct.f3 = py_array_to_rat_cell_wrap_0(cells.f3); + RAT::cell_7 cells_struct; + cells_struct.f1 = py_array_to_rat_cell_wrap_2(cells.f1); + cells_struct.f2 = py_array_to_rat_cell_wrap_3(cells.f2); + cells_struct.f3 = py_array_to_rat_cell_wrap_2(cells.f3); cells_struct.f4 = py_array_to_rat_cell_wrap_2(cells.f4); - cells_struct.f5 = py_array_to_rat_cell_wrap_3(cells.f5); - cells_struct.f6 = py_array_to_rat_cell_wrap_4(cells.f6); - cells_struct.f7 = py_array_to_rat_cell_wrap_5(cells.f7); + cells_struct.f5 = py_array_to_rat_cell_wrap_4(cells.f5); + cells_struct.f6 = py_array_to_rat_cell_wrap_5(cells.f6); + cells_struct.f7 = py_array_to_rat_cell_wrap_6(cells.f7); cells_struct.f8 = py_array_to_rat_cell_wrap_6(cells.f8); cells_struct.f9 = py_array_to_rat_cell_wrap_6(cells.f9); cells_struct.f10 = py_array_to_rat_cell_wrap_6(cells.f10); cells_struct.f11 = py_array_to_rat_cell_wrap_6(cells.f11); cells_struct.f12 = py_array_to_rat_cell_wrap_6(cells.f12); cells_struct.f13 = py_array_to_rat_cell_wrap_6(cells.f13); - cells_struct.f14 = py_array_to_rat_cell_wrap_7(cells.f14); - cells_struct.f15 = py_array_to_rat_cell_wrap_5(cells.f15); - cells_struct.f16 = py_array_to_rat_cell_wrap_5(cells.f16); - cells_struct.f17 = py_array_to_rat_cell_wrap_1(cells.f17); - cells_struct.f18 = py_array_to_rat_cell_wrap_0(cells.f18); - cells_struct.f19 = py_array_to_rat_cell_wrap_3(cells.f19); + cells_struct.f14 = py_array_to_rat_cell_wrap_6(cells.f14); + cells_struct.f15 = py_array_to_rat_cell_wrap_6(cells.f15); + cells_struct.f16 = py_array_to_rat_cell_wrap_6(cells.f16); + cells_struct.f17 = py_array_to_rat_cell_wrap_3(cells.f17); + cells_struct.f18 = py_array_to_rat_cell_wrap_2(cells.f18); + cells_struct.f19 = py_array_to_rat_cell_wrap_4(cells.f19); cells_struct.f20 = py_array_to_rat_cell_wrap_6(cells.f20); return cells_struct; @@ -495,80 +606,171 @@ RAT::struct2_T create_struct2_T(const Control& control) control_struct.maxIter = control.maxIter; control_struct.populationSize = control.populationSize; control_struct.fWeight = control.fWeight; - control_struct.F_CR = control.F_CR; - control_struct.VTR = control.VTR; - control_struct.numGen = control.numGen; + control_struct.crossoverProbability = control.crossoverProbability; + control_struct.targetValue = control.targetValue; + control_struct.numGenerations = control.numGenerations; control_struct.strategy = control.strategy; control_struct.Nlive = control.Nlive; - control_struct.nmcmc = control.nmcmc; + control_struct.Nmcmc = control.Nmcmc; control_struct.propScale = control.propScale; control_struct.nsTolerance = control.nsTolerance; - control_struct.calcSld = control.calcSld; + control_struct.calcSldDuringFit = control.calcSldDuringFit; control_struct.updateFreq = control.updateFreq; control_struct.updatePlotFreq = control.updatePlotFreq; control_struct.nSamples = control.nSamples; control_struct.nChains = control.nChains; - control_struct.lambda = control.lambda; + control_struct.jumpProbability = control.jumpProbability; control_struct.pUnitGamma = control.pUnitGamma; - string_to_rat_array(control.para, control_struct.para.data, control_struct.para.size); - string_to_rat_array(control.proc, control_struct.proc.data, control_struct.proc.size); + string_to_rat_array(control.parallel, control_struct.parallel.data, control_struct.parallel.size); + string_to_rat_array(control.procedure, control_struct.procedure.data, control_struct.procedure.size); string_to_rat_array(control.display, control_struct.display.data, control_struct.display.size); control_struct.tolX = control.tolX; control_struct.resamPars[0] = control.resamPars.at(0); control_struct.resamPars[1] = control.resamPars.at(1); string_to_rat_array(control.boundHandling, control_struct.boundHandling.data, control_struct.boundHandling.size); + control_struct.adaptPCR = control.adaptPCR; control_struct.checks = create_struct3_T(control.checks); return control_struct; } -py::tuple reflectivityCalculation(const ProblemDefinition& problem_def, const Cells& cells, const Limits& limits, const Control& control) +py::array_t rat_array_1d_to_py_array(coder::array array) { - RAT::struct0_T problem_def_struct = create_struct0_T(problem_def); - RAT::cell_8 cells_struct = create_cell_8(cells); - RAT::struct1_T limits_struct = create_struct1_T(limits); - RAT::struct2_T control_struct = create_struct2_T(control); + auto size = (array.size(0) > 1) ? array.size(0) : array.size(1); + auto result_array = py::array_t(size); + std::memcpy(result_array.request().ptr, array.data(), result_array.nbytes()); - RAT::cell_11 result; - RAT::struct4_T problem; + return result_array; +} - // Call the entry-point 'reflectivityCalculation'. - RAT::reflectivityCalculation(&problem_def_struct, &cells_struct, &limits_struct, &control_struct, &problem, &result); - +py::array_t rat_array_2d_to_py_array(coder::array array) +{ + auto result_array = py::array_t({array.size(0), array.size(1)}); + std::memcpy(result_array.request().ptr, array.data(), result_array.nbytes()); + + return result_array; +} + +py::list result_to_list(const RAT::cell_wrap_9 results[]) +{ + py::list outer_list_1; + for (int32_T idx0{0}; idx0 < results[0].f1.size(0); idx0++) { + py::list inner_list; + for (int32_T idx1{0}; idx1 < results[0].f1.size(1); idx1++) { + auto tmp = results[0].f1[idx0 + results[0].f1.size(0) * idx1]; + auto array = py::array_t({tmp.f1.size(0), tmp.f1.size(1)}); + std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes()); + inner_list.append(array); + } + outer_list_1.append(inner_list); + } + + py::list outer_list_2; + for (int32_T idx0{0}; idx0 < results[1].f1.size(0); idx0++) { + py::list inner_list; + for (int32_T idx1{0}; idx1 < results[1].f1.size(1); idx1++) { + auto tmp = results[1].f1[idx0 + results[1].f1.size(0) * idx1]; + auto array = py::array_t({tmp.f1.size(0), tmp.f1.size(1)}); + std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes()); + inner_list.append(array); + } + outer_list_2.append(inner_list); + } + + py::list outer_list_3; + for (int32_T idx0{0}; idx0 < results[2].f1.size(0); idx0++) { + py::list inner_list; + for (int32_T idx1{0}; idx1 < results[2].f1.size(1); idx1++) { + auto tmp = results[2].f1[idx0 + results[2].f1.size(0) * idx1]; + auto array = py::array_t({tmp.f1.size(0), tmp.f1.size(1)}); + std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes()); + inner_list.append(array); + } + outer_list_3.append(inner_list); + } + + py::list outer_list_4; + for (int32_T idx0{0}; idx0 < results[3].f1.size(0); idx0++) { + py::list inner_list; + for (int32_T idx1{0}; idx1 < results[3].f1.size(1); idx1++) { + auto tmp = results[3].f1[idx0 + results[3].f1.size(0) * idx1]; + auto array = py::array_t({tmp.f1.size(0), tmp.f1.size(1)}); + std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes()); + inner_list.append(array); + } + outer_list_4.append(inner_list); + } + + py::list outer_list_5; + for (int32_T idx0{0}; idx0 < results[4].f1.size(0); idx0++) { + py::list inner_list; + for (int32_T idx1{0}; idx1 < results[4].f1.size(1); idx1++) { + auto tmp = results[4].f1[idx0 + results[4].f1.size(0) * idx1]; + auto array = py::array_t({tmp.f1.size(0), tmp.f1.size(1)}); + std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes()); + inner_list.append(array); + } + outer_list_5.append(inner_list); + } + + py::list outer_list_6; + for (int32_T idx0{0}; idx0 < results[5].f1.size(0); idx0++) { + py::list inner_list; + for (int32_T idx1{0}; idx1 < results[5].f1.size(1); idx1++) { + auto tmp = results[5].f1[idx0 + results[5].f1.size(0) * idx1]; + auto array = py::array_t({tmp.f1.size(0), tmp.f1.size(1)}); + std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes()); + inner_list.append(array); + } + outer_list_6.append(inner_list); + } + py::list output_result; + output_result.append(outer_list_1); + output_result.append(outer_list_2); + output_result.append(outer_list_3); + output_result.append(outer_list_4); + output_result.append(outer_list_5); + output_result.append(outer_list_6); + + return output_result; +} + +OutputProblem struct6_T_to_OutputProblem(const RAT::struct6_T problem) +{ // Copy problem to output OutputProblem output_problem; output_problem.ssubs = py::array_t(problem.ssubs.size(0)); auto buffer = output_problem.ssubs.request(); std::memcpy(buffer.ptr, problem.ssubs.data(), output_problem.ssubs.size()*sizeof(real_T)); - output_problem.backgrounds = py::array_t(problem.backgrounds.size(0)); - buffer = output_problem.backgrounds.request(); - std::memcpy(buffer.ptr, problem.backgrounds.data(), output_problem.backgrounds.size()*sizeof(real_T)); + output_problem.backgroundParams = py::array_t(problem.backgroundParams.size(0)); + buffer = output_problem.backgroundParams.request(); + std::memcpy(buffer.ptr, problem.backgroundParams.data(), output_problem.backgroundParams.size()*sizeof(real_T)); - output_problem.qshifts = py::array_t(problem.qshifts.size(0)); - buffer = output_problem.qshifts.request(); - std::memcpy(buffer.ptr, problem.qshifts.data(), output_problem.qshifts.size()*sizeof(real_T)); + output_problem.qzshifts = py::array_t(problem.qzshifts.size(0)); + buffer = output_problem.qzshifts.request(); + std::memcpy(buffer.ptr, problem.qzshifts.data(), output_problem.qzshifts.size()*sizeof(real_T)); output_problem.scalefactors = py::array_t(problem.scalefactors.size(0)); buffer = output_problem.scalefactors.request(); std::memcpy(buffer.ptr, problem.scalefactors.data(), output_problem.scalefactors.size()*sizeof(real_T)); - output_problem.nbairs = py::array_t(problem.nbairs.size(0)); - buffer = output_problem.nbairs.request(); - std::memcpy(buffer.ptr, problem.nbairs.data(), output_problem.nbairs.size()*sizeof(real_T)); + output_problem.bulkIn = py::array_t(problem.bulkIn.size(0)); + buffer = output_problem.bulkIn.request(); + std::memcpy(buffer.ptr, problem.bulkIn.data(), output_problem.bulkIn.size()*sizeof(real_T)); - output_problem.nbsubs = py::array_t(problem.nbsubs.size(0)); - buffer = output_problem.nbsubs.request(); - std::memcpy(buffer.ptr, problem.nbsubs.data(), output_problem.nbsubs.size()*sizeof(real_T)); + output_problem.bulkOut = py::array_t(problem.bulkOut.size(0)); + buffer = output_problem.bulkOut.request(); + std::memcpy(buffer.ptr, problem.bulkOut.data(), output_problem.bulkOut.size()*sizeof(real_T)); - output_problem.resolutions = py::array_t(problem.resolutions.size(0)); - buffer = output_problem.resolutions.request(); - std::memcpy(buffer.ptr, problem.resolutions.data(), output_problem.resolutions.size()*sizeof(real_T)); + output_problem.resolutionParams = py::array_t(problem.resolutionParams.size(0)); + buffer = output_problem.resolutionParams.request(); + std::memcpy(buffer.ptr, problem.resolutionParams.data(), output_problem.resolutionParams.size()*sizeof(real_T)); - output_problem.calculations.sum_chi = problem.calculations.sum_chi; - output_problem.calculations.all_chis = py::array_t(problem.calculations.all_chis.size(0)); - buffer = output_problem.calculations.all_chis.request(); - std::memcpy(buffer.ptr, problem.calculations.all_chis.data(), output_problem.calculations.all_chis.size()*sizeof(real_T)); + output_problem.calculations.sumChi = problem.calculations.sumChi; + output_problem.calculations.allChis = py::array_t(problem.calculations.allChis.size(0)); + buffer = output_problem.calculations.allChis.request(); + std::memcpy(buffer.ptr, problem.calculations.allChis.data(), output_problem.calculations.allChis.size()*sizeof(real_T)); output_problem.allSubRough = py::array_t(problem.allSubRough.size(0)); buffer = output_problem.allSubRough.request(); @@ -578,63 +780,302 @@ py::tuple reflectivityCalculation(const ProblemDefinition& problem_def, const Ce buffer = output_problem.resample.request(); std::memcpy(buffer.ptr, problem.resample.data(), output_problem.resample.size()*sizeof(real_T)); - // Copy result to output - OutputResult output_result; + return output_problem; +} - for (int32_T idx{0}; idx < result.f1.size(0); idx++) { - auto array = py::array_t({result.f1[idx].f1.size(0), result.f1[idx].f1.size(1)}); - std::memcpy(array.request().ptr, result.f1[idx].f1.data(), array.nbytes()); - output_result.f1.append(array); - } +ProblemDefinition struct5_T_to_ProblemDefinition(const RAT::struct5_T problem) +{ + ProblemDefinition problem_def; + + problem_def.useImaginary = problem.useImaginary; + + problem_def.numberOfLayers = problem.numberOfLayers; + problem_def.numberOfDomainContrasts = problem.numberOfDomainContrasts; + problem_def.numberOfContrasts = problem.numberOfContrasts; + + problem_def.modelType.resize(problem.modelType.size[1]); + memcpy(&problem_def.modelType[0], problem.modelType.data, problem.modelType.size[1]); + problem_def.geometry.resize(problem.geometry.size[1]); + memcpy(&problem_def.geometry[0], problem.geometry.data, problem.geometry.size[1]); + problem_def.TF.resize(problem.TF.size[1]); + memcpy(&problem_def.TF[0], problem.TF.data, problem.TF.size[1]); + + problem_def.contrastBackgrounds = rat_array_1d_to_py_array(problem.contrastBackgrounds); + problem_def.contrastBackgroundsType = rat_array_1d_to_py_array(problem.contrastBackgroundsType); + problem_def.resample = rat_array_1d_to_py_array(problem.resample); + problem_def.dataPresent = rat_array_1d_to_py_array(problem.dataPresent); + problem_def.oilChiDataPresent = rat_array_1d_to_py_array(problem.oilChiDataPresent); + problem_def.contrastQzshifts = rat_array_1d_to_py_array(problem.contrastQzshifts); + problem_def.contrastScalefactors = rat_array_1d_to_py_array(problem.contrastScalefactors); + problem_def.contrastBulkIns = rat_array_1d_to_py_array(problem.contrastBulkIns); + problem_def.contrastBulkOuts = rat_array_1d_to_py_array(problem.contrastBulkOuts); + problem_def.contrastResolutions = rat_array_1d_to_py_array(problem.contrastResolutions); + problem_def.backgroundParams = rat_array_1d_to_py_array(problem.backgroundParams); + problem_def.qzshifts = rat_array_1d_to_py_array(problem.qzshifts); + problem_def.scalefactors = rat_array_1d_to_py_array(problem.scalefactors); + problem_def.bulkIn = rat_array_1d_to_py_array(problem.bulkIn); + problem_def.bulkOut = rat_array_1d_to_py_array(problem.bulkOut); + problem_def.resolutionParams = rat_array_1d_to_py_array(problem.resolutionParams); + problem_def.params = rat_array_1d_to_py_array(problem.params); + + problem_def.contrastCustomFiles = rat_array_1d_to_py_array(problem.contrastCustomFiles); + problem_def.contrastDomainRatios = rat_array_1d_to_py_array(problem.contrastDomainRatios); + problem_def.domainRatio = rat_array_1d_to_py_array(problem.domainRatio); + + problem_def.fitParams = rat_array_1d_to_py_array(problem.fitParams); + problem_def.otherParams = rat_array_1d_to_py_array(problem.otherParams); + problem_def.fitLimits = rat_array_2d_to_py_array(problem.fitLimits); + problem_def.otherLimits = rat_array_2d_to_py_array(problem.otherLimits); + + return problem_def; +} - for (int32_T idx{0}; idx < result.f2.size(0); idx++) { - auto array = py::array_t({result.f2[idx].f1.size(0), result.f2[idx].f1.size(1)}); - std::memcpy(array.request().ptr, result.f2[idx].f1.data(), array.nbytes()); - output_result.f2.append(array); +py::list rat_cell_wrap_8_to_py_list(const coder::array& values) +{ + py::list result; + + for (int32_T idx0{0}; idx0 < values.size(0); idx0++) { + result.append(rat_array_2d_to_py_array(values[idx0].f1)); } - for (int32_T idx{0}; idx < result.f3.size(0); idx++) { - auto array = py::array_t({result.f3[idx].f1.size(0), result.f3[idx].f1.size(1)}); - std::memcpy(array.request().ptr, result.f3[idx].f1.data(), array.nbytes()); - output_result.f3.append(array); - } + return result; +} - for (int32_T idx{0}; idx < result.f4.size(0); idx++) { - auto array = py::array_t({result.f4[idx].f1.size(0), result.f4[idx].f1.size(1)}); - std::memcpy(array.request().ptr, result.f4[idx].f1.data(), array.nbytes()); - output_result.f4.append(array); +py::list rat_cell_wrap_8_2d_to_py_list(const coder::array& values) +{ + py::list result; + int32_T idx {0}; + for (int32_T idx0{0}; idx0 < values.size(0); idx0++) { + py::list inner; + for (int32_T idx1{0}; idx1 < values.size(1); idx1++) { + idx = idx0 + values.size(0) * idx1; + inner.append(rat_array_2d_to_py_array(values[idx].f1)); + } + result.append(inner); } - for (int32_T idx{0}; idx < result.f5.size(0); idx++) { - auto array = py::array_t({result.f5[idx].f1.size(0), result.f5[idx].f1.size(1)}); - std::memcpy(array.request().ptr, result.f5[idx].f1.data(), array.nbytes()); - output_result.f5.append(array); - } + return result; +} - for (int32_T idx{0}; idx < result.f6.size(0); idx++) { - auto array = py::array_t({result.f6[idx].f1.size(0), result.f6[idx].f1.size(1)}); - std::memcpy(array.request().ptr, result.f6[idx].f1.data(), array.nbytes()); - output_result.f6.append(array); - } +template +py::array_t bounded_array_to_py_array(const T& array) +{ + auto result_array = py::array_t({array.size[0], array.size[1]}); + std::memcpy(result_array.request().ptr, array.data, result_array.nbytes()); + + return result_array; +} + +py::array_t rat_array_3d_to_py_array(coder::array array) +{ + auto result_array = py::array_t({array.size(0), array.size(1), array.size(2)}); + std::memcpy(result_array.request().ptr, array.data(), result_array.nbytes()); + + return result_array; +} + +BayesResults struct8_T_to_BayesResults(const RAT::struct8_T results) +{ + BayesResults bayesResults; + + bayesResults.bestPars = rat_array_2d_to_py_array(results.bestPars); + bayesResults.chain = rat_array_2d_to_py_array(results.chain); + + bayesResults.bestFitsMean.ref = rat_cell_wrap_8_to_py_list(results.bestFitsMean.ref); + bayesResults.bestFitsMean.sld = rat_cell_wrap_8_2d_to_py_list(results.bestFitsMean.sld); + bayesResults.bestFitsMean.chi = results.bestFitsMean.chi; + bayesResults.bestFitsMean.data = rat_cell_wrap_8_to_py_list(results.bestFitsMean.data); + + bayesResults.predlims.refPredInts = rat_cell_wrap_8_to_py_list(results.predlims.refPredInts); + bayesResults.predlims.sldPredInts = rat_cell_wrap_8_to_py_list(results.predlims.sldPredInts); + bayesResults.predlims.refXdata = rat_cell_wrap_8_to_py_list(results.predlims.refXdata); + bayesResults.predlims.sldXdata = rat_cell_wrap_8_2d_to_py_list(results.predlims.sldXdata); + bayesResults.predlims.sampleChi = bounded_array_to_py_array>(results.predlims.sampleChi); + + bayesResults.parConfInts.par95 = rat_array_2d_to_py_array(results.parConfInts.par95); + bayesResults.parConfInts.par65 = rat_array_2d_to_py_array(results.parConfInts.par65); + bayesResults.parConfInts.mean = rat_array_2d_to_py_array(results.parConfInts.mean); + + bayesResults.bayesRes.allChains = rat_array_3d_to_py_array(results.bayesRes.allChains); + + bayesResults.bayesRes.nestOutput.logZ = results.bayesRes.nestOutput.LogZ; + bayesResults.bayesRes.nestOutput.nestSamples = rat_array_2d_to_py_array(results.bayesRes.nestOutput.nestSamples); + bayesResults.bayesRes.nestOutput.postSamples = rat_array_2d_to_py_array(results.bayesRes.nestOutput.postSamples); + + bayesResults.bayesRes.dreamOutput.runtime = results.bayesRes.dreamOutput.RunTime; + bayesResults.bayesRes.dreamOutput.iteration = results.bayesRes.dreamOutput.iteration; + bayesResults.bayesRes.dreamOutput.iloc = results.bayesRes.dreamOutput.iloc; + bayesResults.bayesRes.dreamOutput.fx = results.bayesRes.dreamOutput.fx; + bayesResults.bayesRes.dreamOutput.R_stat = rat_array_2d_to_py_array(results.bayesRes.dreamOutput.R_stat); + bayesResults.bayesRes.dreamOutput.CR = rat_array_2d_to_py_array(results.bayesRes.dreamOutput.CR); + bayesResults.bayesRes.dreamOutput.AR = bounded_array_to_py_array>(results.bayesRes.dreamOutput.AR); + bayesResults.bayesRes.dreamOutput.outlier = bounded_array_to_py_array>(results.bayesRes.dreamOutput.outlier); + + bayesResults.bayesRes.dreamOutput.Meas_info.Y = results.bayesRes.dreamOutput.Meas_info.Y; + bayesResults.bayesRes.dreamOutput.Meas_info.N = results.bayesRes.dreamOutput.Meas_info.N; + + bayesResults.bayesRes.dreamOutput.DREAMPar.d = results.bayesRes.dreamOutput.DREAMPar.d; + bayesResults.bayesRes.dreamOutput.DREAMPar.N = results.bayesRes.dreamOutput.DREAMPar.N; + bayesResults.bayesRes.dreamOutput.DREAMPar.T = results.bayesRes.dreamOutput.DREAMPar.T; + bayesResults.bayesRes.dreamOutput.DREAMPar.parallel = results.bayesRes.dreamOutput.DREAMPar.parallel; + bayesResults.bayesRes.dreamOutput.DREAMPar.CPU = results.bayesRes.dreamOutput.DREAMPar.CPU; + bayesResults.bayesRes.dreamOutput.DREAMPar.lambda = results.bayesRes.dreamOutput.DREAMPar.lambda; + bayesResults.bayesRes.dreamOutput.DREAMPar.pUnitGamma = results.bayesRes.dreamOutput.DREAMPar.pUnitGamma; + bayesResults.bayesRes.dreamOutput.DREAMPar.nCR = results.bayesRes.dreamOutput.DREAMPar.nCR; + bayesResults.bayesRes.dreamOutput.DREAMPar.delta = results.bayesRes.dreamOutput.DREAMPar.delta; + bayesResults.bayesRes.dreamOutput.DREAMPar.steps = results.bayesRes.dreamOutput.DREAMPar.steps; + bayesResults.bayesRes.dreamOutput.DREAMPar.zeta = results.bayesRes.dreamOutput.DREAMPar.zeta; + bayesResults.bayesRes.dreamOutput.DREAMPar.outlier = std::string(results.bayesRes.dreamOutput.DREAMPar.outlier); + bayesResults.bayesRes.dreamOutput.DREAMPar.adaptPCR = results.bayesRes.dreamOutput.DREAMPar.adaptPCR; + bayesResults.bayesRes.dreamOutput.DREAMPar.thinning = results.bayesRes.dreamOutput.DREAMPar.thinning; + bayesResults.bayesRes.dreamOutput.DREAMPar.epsilon = results.bayesRes.dreamOutput.DREAMPar.epsilon; + bayesResults.bayesRes.dreamOutput.DREAMPar.ABC = results.bayesRes.dreamOutput.DREAMPar.ABC; + bayesResults.bayesRes.dreamOutput.DREAMPar.IO = results.bayesRes.dreamOutput.DREAMPar.IO; + bayesResults.bayesRes.dreamOutput.DREAMPar.modout = results.bayesRes.dreamOutput.DREAMPar.modout; + bayesResults.bayesRes.dreamOutput.DREAMPar.restart = results.bayesRes.dreamOutput.DREAMPar.restart; + bayesResults.bayesRes.dreamOutput.DREAMPar.save = results.bayesRes.dreamOutput.DREAMPar.save; + bayesResults.bayesRes.dreamOutput.DREAMPar.R = rat_array_2d_to_py_array(results.bayesRes.dreamOutput.DREAMPar.R); + + return bayesResults; +} + +py::tuple RATMain(const ProblemDefinition& problem_def, const Cells& cells, const Limits& limits, const Control& control, + const Priors& priors) +{ + RAT::struct0_T problem_def_struct = create_struct0_T(problem_def); + RAT::cell_7 cells_struct = create_cell_7(cells); + RAT::struct1_T limits_struct = create_struct1_T(limits); + RAT::struct2_T control_struct = create_struct2_T(control); + RAT::struct4_T priors_struct = create_struct4_T(priors); - return py::make_tuple(output_problem, output_result); + RAT::struct5_T outProblemDef; + RAT::cell_wrap_9 results[6]; + RAT::struct6_T problem; + RAT::struct8_T bayesResults; + + // Call the entry-point + RAT::RATMain(&problem_def_struct, &cells_struct, &limits_struct, &control_struct, + &priors_struct, &outProblemDef, &problem, results, &bayesResults); + + // Copy result to output + return py::make_tuple(struct5_T_to_ProblemDefinition(outProblemDef), + struct6_T_to_OutputProblem(problem), result_to_list(results), + struct8_T_to_BayesResults(bayesResults)); } +class Module +{ +public: + Module() + { + RAT::RATMain_initialize(); + } + ~Module() + { + RAT::RATMain_terminate(); + } +}; + PYBIND11_MODULE(rat, m) { + static Module module; + py::class_(m, "Predlims") + .def(py::init<>()) + .def_readwrite("refPredInts", &Predlims::refPredInts) + .def_readwrite("sldPredInts", &Predlims::sldPredInts) + .def_readwrite("refXdata", &Predlims::refXdata) + .def_readwrite("sldXdata", &Predlims::sldXdata) + .def_readwrite("sampleChi", &Predlims::sampleChi); + + py::class_(m, "BestFitsMean") + .def(py::init<>()) + .def_readwrite("ref", &BestFitsMean::ref) + .def_readwrite("sld", &BestFitsMean::sld) + .def_readwrite("chi", &BestFitsMean::chi) + .def_readwrite("data", &BestFitsMean::data); + + py::class_(m, "ParConfInts") + .def(py::init<>()) + .def_readwrite("par95", &ParConfInts::par95) + .def_readwrite("par65", &ParConfInts::par65) + .def_readwrite("mean", &ParConfInts::mean); + + py::class_(m, "MeasInfo") + .def(py::init<>()) + .def_readwrite("Y", &MeasInfo::Y) + .def_readwrite("N", &MeasInfo::N); + + py::class_(m, "DREAMPars") + .def(py::init<>()) + .def_readwrite("d", &DREAMPars::d) + .def_readwrite("N", &DREAMPars::N) + .def_readwrite("T", &DREAMPars::T) + .def_readwrite("parallel", &DREAMPars::parallel) + .def_readwrite("CPU", &DREAMPars::CPU) + .def_readwrite("lambda_", &DREAMPars::lambda) + .def_readwrite("pUnitGamma", &DREAMPars::pUnitGamma) + .def_readwrite("nCR", &DREAMPars::nCR) + .def_readwrite("delta", &DREAMPars::delta) + .def_readwrite("steps", &DREAMPars::steps) + .def_readwrite("zeta", &DREAMPars::zeta) + .def_readwrite("outlier", &DREAMPars::outlier) + .def_readwrite("adaptPCR", &DREAMPars::adaptPCR) + .def_readwrite("thinning", &DREAMPars::thinning) + .def_readwrite("epsilon", &DREAMPars::epsilon) + .def_readwrite("ABC", &DREAMPars::ABC) + .def_readwrite("IO", &DREAMPars::IO) + .def_readwrite("modout", &DREAMPars::modout) + .def_readwrite("restart", &DREAMPars::restart) + .def_readwrite("save", &DREAMPars::save) + .def_readwrite("R", &DREAMPars::R); + + py::class_(m, "NestOutput") + .def(py::init<>()) + .def_readwrite("logZ", &NestOutput::logZ) + .def_readwrite("nestSamples", &NestOutput::nestSamples) + .def_readwrite("postSamples", &NestOutput::postSamples); + + py::class_(m, "DreamOutput") + .def(py::init<>()) + .def_readwrite("outlier", &DreamOutput::outlier) + .def_readwrite("runtime", &DreamOutput::runtime) + .def_readwrite("DREAMPar", &DreamOutput::DREAMPar) + .def_readwrite("Meas_info", &DreamOutput::Meas_info) + .def_readwrite("iteration", &DreamOutput::iteration) + .def_readwrite("iloc", &DreamOutput::iloc) + .def_readwrite("fx", &DreamOutput::fx) + .def_readwrite("AR", &DreamOutput::AR) + .def_readwrite("R_stat", &DreamOutput::R_stat) + .def_readwrite("CR", &DreamOutput::CR); + + py::class_(m, "BayesOutput") + .def(py::init<>()) + .def_readwrite("allChains", &BayesOutput::allChains) + .def_readwrite("dreamOutput", &BayesOutput::dreamOutput) + .def_readwrite("nestOutput", &BayesOutput::nestOutput); + + py::class_(m, "BayesResults") + .def(py::init<>()) + .def_readwrite("bestFitsMean", &BayesResults::bestFitsMean) + .def_readwrite("predlims", &BayesResults::predlims) + .def_readwrite("parConfInts", &BayesResults::parConfInts) + .def_readwrite("bestPars", &BayesResults::bestPars) + .def_readwrite("bayesRes", &BayesResults::bayesRes) + .def_readwrite("chain", &BayesResults::chain); + py::class_(m, "Calculation") .def(py::init<>()) - .def_readwrite("all_chis", &Calculation::all_chis) - .def_readwrite("sum_chi", &Calculation::sum_chi); + .def_readwrite("allChis", &Calculation::allChis) + .def_readwrite("sumChi", &Calculation::sumChi); py::class_(m, "OutputProblem") .def(py::init<>()) .def_readwrite("ssubs", &OutputProblem::ssubs) - .def_readwrite("backgrounds", &OutputProblem::backgrounds) - .def_readwrite("qshifts", &OutputProblem::qshifts) + .def_readwrite("backgroundParams", &OutputProblem::backgroundParams) + .def_readwrite("qzshifts", &OutputProblem::qzshifts) .def_readwrite("scalefactors", &OutputProblem::scalefactors) - .def_readwrite("nbairs", &OutputProblem::nbairs) - .def_readwrite("nbsubs", &OutputProblem::nbsubs) - .def_readwrite("resolutions", &OutputProblem::resolutions) + .def_readwrite("bulkIn", &OutputProblem::bulkIn) + .def_readwrite("bulkOut", &OutputProblem::bulkOut) + .def_readwrite("resolutionParams", &OutputProblem::resolutionParams) .def_readwrite("calculations", &OutputProblem::calculations) .def_readwrite("allSubRough", &OutputProblem::allSubRough) .def_readwrite("resample", &OutputProblem::resample); @@ -650,26 +1091,38 @@ PYBIND11_MODULE(rat, m) { py::class_(m, "Checks") .def(py::init<>()) - .def_readwrite("params_fitYesNo", &Checks::params_fitYesNo) - .def_readwrite("backs_fitYesNo", &Checks::backs_fitYesNo) - .def_readwrite("shifts_fitYesNo", &Checks::shifts_fitYesNo) - .def_readwrite("scales_fitYesNo", &Checks::scales_fitYesNo) - .def_readwrite("nbairs_fitYesNo", &Checks::nbairs_fitYesNo) - .def_readwrite("nbsubs_fitYesNo", &Checks::nbsubs_fitYesNo) - .def_readwrite("resol_fitYesNo", &Checks::resol_fitYesNo) - .def_readwrite("domainRatio_fitYesNo", &Checks::domainRatio_fitYesNo); + .def_readwrite("fitParam", &Checks::fitParam) + .def_readwrite("fitBackgroundParam", &Checks::fitBackgroundParam) + .def_readwrite("fitQzshift", &Checks::fitQzshift) + .def_readwrite("fitScalefactor", &Checks::fitScalefactor) + .def_readwrite("fitBulkIn", &Checks::fitBulkIn) + .def_readwrite("fitBulkOut", &Checks::fitBulkOut) + .def_readwrite("fitResolutionParam", &Checks::fitResolutionParam) + .def_readwrite("fitDomainRatio", &Checks::fitDomainRatio); py::class_(m, "Limits") .def(py::init<>()) - .def_readwrite("params", &Limits::params) - .def_readwrite("backs", &Limits::backs) - .def_readwrite("shifts", &Limits::shifts) - .def_readwrite("scales", &Limits::scales) - .def_readwrite("nba", &Limits::nba) - .def_readwrite("nbs", &Limits::nbs) - .def_readwrite("res", &Limits::res) + .def_readwrite("param", &Limits::param) + .def_readwrite("backgroundParam", &Limits::backgroundParam) + .def_readwrite("qzshift", &Limits::qzshift) + .def_readwrite("scalefactor", &Limits::scalefactor) + .def_readwrite("bulkIn", &Limits::bulkIn) + .def_readwrite("bulkOut", &Limits::bulkOut) + .def_readwrite("resolutionParam", &Limits::resolutionParam) .def_readwrite("domainRatio", &Limits::domainRatio); + py::class_(m, "Priors") + .def(py::init<>()) + .def_readwrite("param", &Priors::param) + .def_readwrite("backgroundParam", &Priors::backgroundParam) + .def_readwrite("qzshift", &Priors::qzshift) + .def_readwrite("scalefactor", &Priors::scalefactor) + .def_readwrite("bulkIn", &Priors::bulkIn) + .def_readwrite("bulkOut", &Priors::bulkOut) + .def_readwrite("resolutionParam", &Priors::resolutionParam) + .def_readwrite("priorNames", &Priors::priorNames) + .def_readwrite("priorValues", &Priors::priorValues); + py::class_(m, "Cells") .def(py::init<>()) .def_readwrite("f1", &Cells::f1) @@ -695,8 +1148,8 @@ PYBIND11_MODULE(rat, m) { py::class_(m, "Control") .def(py::init<>()) - .def_readwrite("para", &Control::para) - .def_readwrite("proc", &Control::proc) + .def_readwrite("parallel", &Control::parallel) + .def_readwrite("procedure", &Control::procedure) .def_readwrite("display", &Control::display) .def_readwrite("tolX", &Control::tolX) .def_readwrite("tolFun", &Control::tolFun) @@ -704,29 +1157,30 @@ PYBIND11_MODULE(rat, m) { .def_readwrite("maxIter", &Control::maxIter) .def_readwrite("populationSize", &Control::populationSize) .def_readwrite("fWeight", &Control::fWeight) - .def_readwrite("F_CR", &Control::F_CR) - .def_readwrite("VTR", &Control::VTR) - .def_readwrite("numGen", &Control::numGen) + .def_readwrite("crossoverProbability", &Control::crossoverProbability) + .def_readwrite("targetValue", &Control::targetValue) + .def_readwrite("numGenerations", &Control::numGenerations) .def_readwrite("strategy", &Control::strategy) .def_readwrite("Nlive", &Control::Nlive) - .def_readwrite("nmcmc", &Control::nmcmc) + .def_readwrite("Nmcmc", &Control::Nmcmc) .def_readwrite("propScale", &Control::propScale) .def_readwrite("nsTolerance", &Control::nsTolerance) - .def_readwrite("calcSld", &Control::calcSld) + .def_readwrite("calcSldDuringFit", &Control::calcSldDuringFit) .def_readwrite("resamPars", &Control::resamPars) .def_readwrite("updateFreq", &Control::updateFreq) .def_readwrite("updatePlotFreq", &Control::updatePlotFreq) .def_readwrite("nSamples", &Control::nSamples) .def_readwrite("nChains", &Control::nChains) - .def_readwrite("lambda", &Control::lambda) + .def_readwrite("jumpProbability", &Control::jumpProbability) .def_readwrite("pUnitGamma", &Control::pUnitGamma) .def_readwrite("boundHandling", &Control::boundHandling) + .def_readwrite("adaptPCR", &Control::adaptPCR) .def_readwrite("checks", &Control::checks); py::class_(m, "ProblemDefinition") .def(py::init<>()) - .def_readwrite("contrastBacks", &ProblemDefinition::contrastBacks) - .def_readwrite("contrastBacksType", &ProblemDefinition::contrastBacksType) + .def_readwrite("contrastBackgrounds", &ProblemDefinition::contrastBackgrounds) + .def_readwrite("contrastBackgroundsType", &ProblemDefinition::contrastBackgroundsType) .def_readwrite("TF", &ProblemDefinition::TF) .def_readwrite("resample", &ProblemDefinition::resample) .def_readwrite("dataPresent", &ProblemDefinition::dataPresent) @@ -734,17 +1188,17 @@ PYBIND11_MODULE(rat, m) { .def_readwrite("numberOfContrasts", &ProblemDefinition::numberOfContrasts) .def_readwrite("geometry", &ProblemDefinition::geometry) .def_readwrite("useImaginary", &ProblemDefinition::useImaginary) - .def_readwrite("contrastShifts", &ProblemDefinition::contrastShifts) - .def_readwrite("contrastScales", &ProblemDefinition::contrastScales) - .def_readwrite("contrastNbas", &ProblemDefinition::contrastNbas) - .def_readwrite("contrastNbss", &ProblemDefinition::contrastNbss) - .def_readwrite("contrastRes", &ProblemDefinition::contrastRes) - .def_readwrite("backs", &ProblemDefinition::backs) - .def_readwrite("shifts", &ProblemDefinition::shifts) - .def_readwrite("sf", &ProblemDefinition::sf) - .def_readwrite("nba", &ProblemDefinition::nba) - .def_readwrite("nbs", &ProblemDefinition::nbs) - .def_readwrite("res", &ProblemDefinition::res) + .def_readwrite("contrastQzshifts", &ProblemDefinition::contrastQzshifts) + .def_readwrite("contrastScalefactors", &ProblemDefinition::contrastScalefactors) + .def_readwrite("contrastBulkIns", &ProblemDefinition::contrastBulkIns) + .def_readwrite("contrastBulkOuts", &ProblemDefinition::contrastBulkOuts) + .def_readwrite("contrastResolutions", &ProblemDefinition::contrastResolutions) + .def_readwrite("backgroundParams", &ProblemDefinition::backgroundParams) + .def_readwrite("qzshifts", &ProblemDefinition::qzshifts) + .def_readwrite("scalefactors", &ProblemDefinition::scalefactors) + .def_readwrite("bulkIn", &ProblemDefinition::bulkIn) + .def_readwrite("bulkOut", &ProblemDefinition::bulkOut) + .def_readwrite("resolutionParams", &ProblemDefinition::resolutionParams) .def_readwrite("params", &ProblemDefinition::params) .def_readwrite("numberOfLayers", &ProblemDefinition::numberOfLayers) .def_readwrite("modelType", &ProblemDefinition::modelType) @@ -752,11 +1206,10 @@ PYBIND11_MODULE(rat, m) { .def_readwrite("contrastDomainRatios", &ProblemDefinition::contrastDomainRatios) .def_readwrite("domainRatio", &ProblemDefinition::domainRatio) .def_readwrite("numberOfDomainContrasts", &ProblemDefinition::numberOfDomainContrasts) - .def_readwrite("domainContrastCustomFiles", &ProblemDefinition::domainContrastCustomFiles) - .def_readwrite("fitpars", &ProblemDefinition::fitpars) - .def_readwrite("otherpars", &ProblemDefinition::otherpars) - .def_readwrite("fitconstr", &ProblemDefinition::fitconstr) - .def_readwrite("otherconstr", &ProblemDefinition::otherconstr); + .def_readwrite("fitParams", &ProblemDefinition::fitParams) + .def_readwrite("otherParams", &ProblemDefinition::otherParams) + .def_readwrite("fitLimits", &ProblemDefinition::fitLimits) + .def_readwrite("otherLimits", &ProblemDefinition::otherLimits); - m.def("reflectivityCalculation", &reflectivityCalculation, "A demo for Python RAT"); + m.def("RATMain", &RATMain, "A demo for Python RAT"); } From 82bbd268b969963e974f0068470040a2707f7c09 Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Thu, 1 Feb 2024 09:43:57 +0000 Subject: [PATCH 3/8] Adds support for matlab, dylib, and python custom functions --- .gitignore | 8 +- DSPC_bilayer_example.py | 28 +- DSPC_custom_layers_example.py | 189 ++++++ RAT/DREAMWrapper.cpp | 26 +- RAT/DREAMWrapper.h | 10 +- RAT/RATMain.cpp | 877 +++++++++++++++------------- RAT/RATMain.h | 9 +- RAT/RATMain_data.cpp | 6 +- RAT/RATMain_data.h | 4 +- RAT/RATMain_internal_types.h | 134 +++-- RAT/RATMain_rtwutil.cpp | 54 +- RAT/RATMain_rtwutil.h | 14 +- RAT/RATMain_types.h | 366 +++++------- RAT/SLDFunction.cpp | 121 ---- RAT/SLDFunction.h | 2 - RAT/adaptPCR.cpp | 2 +- RAT/adaptPCR.h | 4 +- RAT/adaptive.cpp | 698 ++-------------------- RAT/adaptive.h | 6 +- RAT/allocateLayersForContrast.cpp | 2 +- RAT/allocateLayersForContrast.h | 2 +- RAT/allocateParamsToLayers.cpp | 2 +- RAT/allocateParamsToLayers.h | 2 +- RAT/calcDensity.cpp | 6 +- RAT/calcDensity.h | 6 +- RAT/calcProposal.cpp | 2 +- RAT/calcProposal.h | 4 +- RAT/calculate.cpp | 106 ++-- RAT/calculate.h | 23 +- RAT/calculate1.cpp | 106 ++-- RAT/calculate1.h | 23 +- RAT/calculate2.cpp | 106 ++-- RAT/calculate2.h | 23 +- RAT/calculate3.cpp | 110 ++-- RAT/calculate3.h | 23 +- RAT/calculate4.cpp | 107 ++-- RAT/calculate4.h | 24 +- RAT/calculate5.cpp | 107 ++-- RAT/calculate5.h | 24 +- RAT/callCppFunction.cpp | 158 +++-- RAT/callCppFunction.h | 22 +- RAT/classHandle.hpp | 20 +- RAT/coreLayersCalculation.cpp | 4 +- RAT/deopt.cpp | 59 +- RAT/deopt.h | 23 +- RAT/drawCR.cpp | 2 +- RAT/drawCR.h | 4 +- RAT/drawMCMC.cpp | 4 +- RAT/drawMCMC.h | 8 +- RAT/drawMultiNest.cpp | 4 +- RAT/drawMultiNest.h | 8 +- RAT/evaluateModel.cpp | 8 +- RAT/evaluateModel.h | 12 +- RAT/examples/main.cpp | 29 +- RAT/fMinSearch.cpp | 49 +- RAT/fMinSearch.h | 13 +- RAT/gelman.cpp | 2 +- RAT/gelman.h | 4 +- RAT/groupLayersMod.cpp | 2 - RAT/groupLayersModImaginary.cpp | 2 - RAT/initializeDREAM.cpp | 18 +- RAT/initializeDREAM.h | 16 +- RAT/lower.cpp | 2 +- RAT/makeCell.cpp | 33 +- RAT/makeCell.h | 6 +- RAT/makeEmptyBayesResultsStruct.cpp | 294 ++++++---- RAT/makeEmptyBayesResultsStruct.h | 10 +- RAT/metropolisRule.cpp | 2 +- RAT/metropolisRule.h | 4 +- RAT/nestedSampler.cpp | 4 +- RAT/nestedSampler.h | 8 +- RAT/nsIntraFun.cpp | 46 +- RAT/nsIntraFun.h | 12 +- RAT/packParams.cpp | 150 ++--- RAT/packParams.h | 24 +- RAT/parallelContrasts.cpp | 113 ++-- RAT/parallelContrasts.h | 15 +- RAT/parallelContrasts1.cpp | 111 ++-- RAT/parallelContrasts1.h | 15 +- RAT/parallelContrasts2.cpp | 104 ++-- RAT/parallelContrasts2.h | 15 +- RAT/parallelContrasts3.cpp | 156 ++--- RAT/parallelContrasts3.h | 15 +- RAT/parallelContrasts4.cpp | 165 +++--- RAT/parallelContrasts4.h | 15 +- RAT/parallelContrasts5.cpp | 201 ++++--- RAT/parallelContrasts5.h | 15 +- RAT/parallelPoints.cpp | 77 +-- RAT/parallelPoints.h | 15 +- RAT/parallelPoints1.cpp | 81 ++- RAT/parallelPoints1.h | 15 +- RAT/parallelPoints2.cpp | 99 ++-- RAT/parallelPoints2.h | 15 +- RAT/parallelPoints3.cpp | 104 ++-- RAT/parallelPoints3.h | 15 +- RAT/parallelPoints4.cpp | 128 ++-- RAT/parallelPoints4.h | 15 +- RAT/parallelPoints5.cpp | 201 ++++--- RAT/parallelPoints5.h | 15 +- RAT/parseResultToStruct.cpp | 110 ++++ RAT/parseResultToStruct.h | 40 ++ RAT/processBayes.cpp | 190 ++---- RAT/processBayes.h | 31 +- RAT/processCustomFunction.cpp | 84 ++- RAT/processCustomFunction.h | 17 +- RAT/processCustomFunction1.cpp | 60 +- RAT/processCustomFunction1.h | 16 +- RAT/processCustomFunction2.cpp | 219 +++---- RAT/processCustomFunction2.h | 17 +- RAT/processCustomFunction3.cpp | 75 +-- RAT/processCustomFunction3.h | 16 +- RAT/ratDREAM.cpp | 28 +- RAT/ratDREAM.h | 12 +- RAT/refPrctileConfInts.cpp | 445 +++++++++----- RAT/refPrctileConfInts.h | 6 +- RAT/reflectivityCalculation.cpp | 225 ++++--- RAT/reflectivityCalculation.h | 14 +- RAT/reflectivityCalculation1.cpp | 76 +-- RAT/reflectivityCalculation1.h | 20 +- RAT/reflectivityCalculation2.cpp | 75 +-- RAT/reflectivityCalculation2.h | 21 +- RAT/removeOutlier.cpp | 2 +- RAT/removeOutlier.h | 4 +- RAT/repmat.cpp | 2 +- RAT/repmat.h | 2 +- RAT/resampleLayers.cpp | 2 +- RAT/resampleLayersReIm.cpp | 40 +- RAT/resampleLayersReIm.h | 2 +- RAT/runDE.cpp | 228 +++----- RAT/runDE.h | 35 +- RAT/runDREAM.cpp | 201 +++---- RAT/runDREAM.h | 16 +- RAT/runNestedSampler.cpp | 256 ++++---- RAT/runNestedSampler.h | 16 +- RAT/runSimplex.cpp | 177 ++---- RAT/runSimplex.h | 12 +- RAT/scaledGaussPrior.cpp | 9 +- RAT/scaledGaussPrior.h | 4 +- RAT/setupDREAM.cpp | 4 +- RAT/setupDREAM.h | 8 +- RAT/shiftData.cpp | 12 +- RAT/simplexIntrafun.cpp | 90 +-- RAT/simplexIntrafun.h | 30 +- RAT/single.cpp | 70 +-- RAT/single.h | 13 +- RAT/single1.cpp | 80 ++- RAT/single1.h | 13 +- RAT/single2.cpp | 97 ++- RAT/single2.h | 13 +- RAT/single3.cpp | 102 ++-- RAT/single3.h | 13 +- RAT/single4.cpp | 126 ++-- RAT/single4.h | 13 +- RAT/single5.cpp | 199 ++++--- RAT/single5.h | 13 +- RAT/strcmp.cpp | 12 +- RAT/structConstructorHelper.cpp | 24 +- RAT/structConstructorHelper.h | 16 +- RAT/triggerEvent.cpp | 105 +--- RAT/triggerEvent.h | 12 +- RAT/unpackParams.cpp | 84 +-- RAT/unpackParams.h | 4 +- alloyDomains.cpp | 48 ++ alloyDomains.m | 29 + alloyDomains.py | 29 + customBilayer.m | 66 +++ customBilayer.py | 73 +++ data/{ => dspc_bilayer}/data1.csv | 0 data/{ => dspc_bilayer}/data2.csv | 0 data/dspc_custom/data1.csv | 146 +++++ data/dspc_custom/data2.csv | 97 +++ data/dspc_custom/data3.csv | 104 ++++ domains_custom_layers_example.py | 187 ++++++ misc.py | 47 ++ rat.cpp | 224 +++++-- requirements.txt | 3 +- 176 files changed, 5749 insertions(+), 5414 deletions(-) create mode 100644 DSPC_custom_layers_example.py create mode 100644 RAT/parseResultToStruct.cpp create mode 100644 RAT/parseResultToStruct.h create mode 100644 alloyDomains.cpp create mode 100644 alloyDomains.m create mode 100644 alloyDomains.py create mode 100644 customBilayer.m create mode 100644 customBilayer.py rename data/{ => dspc_bilayer}/data1.csv (100%) rename data/{ => dspc_bilayer}/data2.csv (100%) create mode 100644 data/dspc_custom/data1.csv create mode 100644 data/dspc_custom/data2.csv create mode 100644 data/dspc_custom/data3.csv create mode 100644 domains_custom_layers_example.py create mode 100644 misc.py diff --git a/.gitignore b/.gitignore index dd0d153c..db5c3afb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,10 @@ __pycache__/ .vscode # Build -*.rat.cpp \ No newline at end of file +*.rat.cpp +*.so +*.dll +*.dylib +*.obj +*.exp +*.lib diff --git a/DSPC_bilayer_example.py b/DSPC_bilayer_example.py index 5788f4ee..c20000db 100644 --- a/DSPC_bilayer_example.py +++ b/DSPC_bilayer_example.py @@ -117,8 +117,8 @@ #------------------------------------------------------------------------------------- # Cells cells.f1 = [[0, 1], [0, 1]] - cells.f2 = [np.loadtxt('data/data1.csv', delimiter=','), - np.loadtxt('data/data2.csv', delimiter=',')] + cells.f2 = [np.loadtxt('data/dspc_bilayer/data1.csv', delimiter=','), + np.loadtxt('data/dspc_bilayer/data2.csv', delimiter=',')] cells.f3 = [[0.011403, 0.59342], [0.011403, 0.59342]] cells.f4 = [[0.011403, 0.70956], [0.011403, 0.59342]] cells.f5 = [[1, 2, 3, 4, 5, 6, 6, 5], [1, 2, 3, 4, 5, 6, 6, 5]] @@ -189,18 +189,18 @@ [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf]] - pdef, problem, output, bayes_result = rat.RATMain(problem, cells, limits, control, priors) + problem, contrast_params, result, bayes_results = rat.RATMain(problem, cells, limits, control, priors) - print(problem.ssubs) - print(problem.backgroundParams) - print(problem.qzshifts) - print(problem.scalefactors) - print(problem.bulkIn) - print(problem.bulkOut) - print(problem.resolutionParams) - print(problem.calculations.allChis) - print(problem.calculations.sumChi) - print(problem.allSubRough) - print(problem.resample) + print(contrast_params.ssubs) + print(contrast_params.backgroundParams) + print(contrast_params.qzshifts) + print(contrast_params.scalefactors) + print(contrast_params.bulkIn) + print(contrast_params.bulkOut) + print(contrast_params.resolutionParams) + print(contrast_params.calculations.allChis) + print(contrast_params.calculations.sumChi) + print(contrast_params.allSubRough) + print(contrast_params.resample) #print(output) \ No newline at end of file diff --git a/DSPC_custom_layers_example.py b/DSPC_custom_layers_example.py new file mode 100644 index 00000000..9fe82dc4 --- /dev/null +++ b/DSPC_custom_layers_example.py @@ -0,0 +1,189 @@ +import faulthandler +import cppimport +import numpy as np +from customBilayer import customBilayer +from misc import MatlabWrapper, DylibWrapper + +faulthandler.enable() + +rat = cppimport.imp("rat") + + +if __name__ == '__main__': + + control = rat.Control() + problem = rat.ProblemDefinition() + limits = rat.Limits() + cells = rat.Cells() + priors = rat.Priors() + + #------------------------------------------------------------------------------------ + # Control + control.procedure = 'calculate' + control.parallel = 'single' + control.display = 'iter' + control.calcSldDuringFit = False + control.resamPars = [0.9000, 50] + + # control.procedure = 'simplex' + # control.tolX = 1e-6 + # control.tolFun = 1e-6 + # control.maxFunEvals = 10000 + # control.maxIter = 1 + # control.updateFreq = -1 + # control.updatePlotFreq = 1 + + # control.procedure = 'dream' + # control.nSamples = 100 + # control.nChains = 10 + # control.jumpProbability = 0.5 + # control.pUnitGamma = 0.2 + # control.boundHandling = 'fold' + # control.adaptPCR = False; + + # control.procedure = 'de' + # control.populationSize = 10 + # control.fWeight = 0.5 + # control.crossoverProbability = 0.8 + # control.strategy = 4 + # control.targetValue = 1 + # control.numGenerations = 500 + + # control.procedure = 'ns' + # control.Nlive = 150 + # control.Nmcmc = 0 + # control.propScale = 0.1 + # control.nsTolerance = 0.1 + + control.checks.fitParam = [1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1] + control.checks.fitBackgroundParam = np.ones((2)) + control.checks.fitQzshift = [0] + control.checks.fitScalefactor = [0, 0] + control.checks.fitBulkIn = [0] + control.checks.fitBulkOut = [0, 0] + control.checks.fitResolutionParam = [0] + + #------------------------------------------------------------------------------------ + # ProblemDef + problem.contrastBackgrounds = [1, 2, 3] + problem.contrastBackgroundsType = [1, 1, 1] + problem.TF = 'non polarised' + problem.resample = [0, 0, 0] + problem.dataPresent = [1, 1, 1] + problem.oilChiDataPresent = [0, 0, 0] + problem.numberOfContrasts = 3 + problem.geometry = 'substrate/liquid' + problem.useImaginary = False + problem.contrastQzshifts = [1, 1, 1] + problem.contrastScalefactors = [1, 1, 1] + problem.contrastBulkIns = [1, 1, 1] + problem.contrastBulkOuts = [1, 2, 3] + problem.contrastResolutions = [1, 1, 1] + problem.backgroundParams = [1.0e-07, 1.0e-07, 1.0e-07] + problem.qzshifts = [0] + problem.scalefactors = [1] + problem.bulkIn = [2.073e-06] + problem.bulkOut = [6.35e-06, 2.073e-06, -5.6e-07] + problem.resolutionParams = [0.0300] + problem.params = [3, 20, 0.2, 55, 0.2, 0.1, 4, 2] + problem.numberOfLayers = 0 + problem.modelType = 'custom layers' + problem.contrastCustomFiles = [1, 1, 1] + problem.contrastDomainRatios = [0, 0, 0] + problem.domainRatio = [] + problem.numberOfDomainContrasts = 0 + problem.fitParams = [] + problem.otherParams = [] + problem.fitLimits = [] + problem.otherLimits = [] + + #------------------------------------------------------------------------------------ + # Limits + limits.param = [[1, 10], [5, 60], [0, 0.5], [45, 65], + [0, 0.5], [0, 0.2], [2, 8], [0, 10]] + limits.backgroundParam = [[1.0000e-10, 1.0000e-05], [1.0000e-10, 1.0000e-05], [1.0000e-10, 1.0000e-05]] + limits.scalefactor = [[0.500, 2]] + limits.qzshift = [[-0.0001, 0.0001]] + limits.bulkIn = [[2.070e-06, 2.080e-06]] + limits.bulkOut = [[5.0000e-06, 6.3500e-06], [1.0000e-06, 3.0000e-06], [-6.0000e-07, -3.0000e-07]] + limits.resolutionParam = [[0.0100, 0.0500]] + limits.domainRatio = [] + + #------------------------------------------------------------------------------------- + # Cells + cells.f1 = [[0, 1], [0, 1], [0, 1]] + cells.f2 = [np.loadtxt('data/dspc_custom/data1.csv', delimiter=','), + np.loadtxt('data/dspc_custom/data2.csv', delimiter=','), + np.loadtxt('data/dspc_custom/data3.csv', delimiter=',')] + cells.f3 = [[0.0130, 0.370], [0.0130, 0.370], [0.0130, 0.370]] + cells.f4 = [[0.00571180, 0.396060], [0.00760290, 0.329960], [0.00633740, 0.330480]] + cells.f5 = [[0, 0, 0]] + cells.f6 = [[0]] + cells.f7 = ['Substrate Roughness', 'Oxide thick', 'Oxide Hydration', 'Lipid APM', + 'Head Hydration', 'Bilayer Hydration', 'Bilayer Roughness', 'Water Thickness'] + cells.f8 = ['Backs par D2O', 'Backs par SMW', 'Backs par H2O'] + cells.f9 = ['Scalefactor 1'] + cells.f10 = ['Qz shift 1'] + cells.f11 = ['Silicon'] + cells.f12 = ['SLD D2O', 'SLD SMW', 'SLD H2O'] + cells.f13 = ['Resolution par 1'] + + dylib_wrapper = DylibWrapper('customBilayer.dll', 'customBilayer') + cells.f14 = [dylib_wrapper.getHandle()] # C++ callback + + # matlab_wrapper = MatlabWrapper('customBilayer.m') + # cells.f14 = [matlab_wrapper.getHandle()] # Matlab callback + + # cells.f14 = [customBilayer] # Python callback + + cells.f15 = ['constant', 'constant', 'constant'] + cells.f16 = ['constant'] + cells.f17 = [[], [], []] + cells.f18 = [] + cells.f19 = [] + cells.f20 = [] + + #------------------------------------------------------------------------------------ + # Priors + priors.param = [['Substrate Roughness', 'uniform', 0, np.Inf], + ['Oxide thick', 'uniform', 0, np.Inf], + ['Oxide Hydration', 'uniform', 0, np.Inf], + ['Lipid APM', 'uniform', 0, np.Inf], + ['Head Hydration', 'uniform', 0, np.Inf], + ['Bilayer Hydration', 'uniform', 0, np.Inf], + ['Bilayer Roughness', 'uniform', 0, np.Inf], + ['Water Thickness', 'uniform', 0, np.Inf]] + priors.backgroundParam = [['Backs par D2O', 'uniform', 0, np.Inf], ['Backs par SMW', 'uniform', 0, np.Inf], ['Backs par H20', 'uniform', 0, np.Inf]] + priors.scalefactor = [['Scalefactor 1', 'uniform', 0, np.Inf]] + priors.qzshift = [['Qz shift 1', 'uniform', 0, np.Inf]] + priors.bulkIn = [['Silicon', 'uniform', 0, np.Inf]] + priors.bulkOut = [['SLD D2O', 'uniform', 0, np.Inf], ['SLD SMW', 'uniform', 0, np.Inf], ['SLD H20', 'uniform', 0, np.Inf]] + priors.resolutionParam = [['Resolution par 1', 'uniform', 0, np.Inf]] + priors.priorNames = ['Substrate Roughness', 'Oxide thick', 'Oxide Hydration', + 'Lipid APM', 'Head Hydration', 'Bilayer Hydration', + 'Bilayer Roughness', 'Water Thickness', 'Backs par D2O', 'Backs par SMW', + 'Backs par H2O', 'Resolution par 1', 'Silicon', 'SLD D2O', 'SLD SMW', + 'SLD H2O', 'Qz shift 1','Scalefactor 1'] + priors.priorValues = [[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], + [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], + [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], + [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf]] + + + import time + start = time.perf_counter() + problem, contrast_params, result, bayes_results = rat.RATMain(problem, cells, limits, control, priors) + print(time.perf_counter() - start, 'sec') + # print(contrast_params.ssubs) + # print(contrast_params.backgroundParams) + # print(contrast_params.qzshifts) + # print(contrast_params.scalefactors) + # print(contrast_params.bulkIn) + # print(contrast_params.bulkOut) + # print(contrast_params.resolutionParams) + print(contrast_params.calculations.allChis) + print(contrast_params.calculations.sumChi) + # print(contrast_params.allSubRough) + # print(contrast_params.resample) + #print(output) + \ No newline at end of file diff --git a/RAT/DREAMWrapper.cpp b/RAT/DREAMWrapper.cpp index fd34f7df..60d62e2b 100644 --- a/RAT/DREAMWrapper.cpp +++ b/RAT/DREAMWrapper.cpp @@ -20,28 +20,28 @@ // Function Definitions namespace RAT { - real_T DREAMWrapper(const ::coder::array &pars, const struct5_T - *ratInputs_problemDef, const cell_14 - *ratInputs_problemDefCells, const struct2_T + real_T DREAMWrapper(const ::coder::array &pars, const c_struct_T + *ratInputs_problemStruct, const cell_11 + *ratInputs_problemCells, const struct2_T *ratInputs_controls) { - cell_13 a__1; - struct5_T problem; - struct_T outProblem; + c_struct_T problemStruct; + cell_wrap_9 a__1[6]; + d_struct_T contrastParams; int32_T loop_ub; // Get the inputs for Reflectivity Calculation - problem = *ratInputs_problemDef; + problemStruct = *ratInputs_problemStruct; // Put the current parameters into problem - problem.fitParams.set_size(1, pars.size(1)); + problemStruct.fitParams.set_size(1, pars.size(1)); loop_ub = pars.size(1); for (int32_T i{0}; i < loop_ub; i++) { - problem.fitParams[problem.fitParams.size(0) * i] = pars[i]; + problemStruct.fitParams[problemStruct.fitParams.size(0) * i] = pars[i]; } // Distribute them to the right parts - unpackParams(&problem, ratInputs_controls->checks.fitParam, + unpackParams(&problemStruct, ratInputs_controls->checks.fitParam, ratInputs_controls->checks.fitBackgroundParam, ratInputs_controls->checks.fitQzshift, ratInputs_controls->checks.fitScalefactor, @@ -51,11 +51,11 @@ namespace RAT ratInputs_controls->checks.fitDomainRatio); // Calculate.... - reflectivityCalculation(&problem, ratInputs_problemDefCells, - ratInputs_controls, &outProblem, &a__1); + reflectivityCalculation(&problemStruct, ratInputs_problemCells, + ratInputs_controls, &contrastParams, a__1); // Function value is chi-squared.... - return -outProblem.calculations.sumChi / 2.0; + return -contrastParams.calculations.sumChi / 2.0; } } diff --git a/RAT/DREAMWrapper.h b/RAT/DREAMWrapper.h index 48014b70..1450cea8 100644 --- a/RAT/DREAMWrapper.h +++ b/RAT/DREAMWrapper.h @@ -19,17 +19,17 @@ // Type Declarations namespace RAT { - struct struct5_T; - struct cell_14; + struct c_struct_T; + struct cell_11; struct struct2_T; } // Function Declarations namespace RAT { - real_T DREAMWrapper(const ::coder::array &pars, const struct5_T - *ratInputs_problemDef, const cell_14 - *ratInputs_problemDefCells, const struct2_T + real_T DREAMWrapper(const ::coder::array &pars, const c_struct_T + *ratInputs_problemStruct, const cell_11 + *ratInputs_problemCells, const struct2_T *ratInputs_controls); } diff --git a/RAT/RATMain.cpp b/RAT/RATMain.cpp index b63393f1..106d8b0f 100644 --- a/RAT/RATMain.cpp +++ b/RAT/RATMain.cpp @@ -31,8 +31,9 @@ // Function Declarations namespace RAT { - static void cast(const struct0_T *r, struct5_T *r1); - static void cast(const cell_7 *r, cell_14 *r1); + static void cast(const c_struct_T *r, struct0_T *r1); + static void cast(const struct0_T *r, c_struct_T *r1); + static void cast(const cell_7 *r, cell_11 *r1); static void cast(const ::coder::array &r, ::coder::array< cell_wrap_8, 1U> &r1); static void cast(const ::coder::array &r, ::coder::array< @@ -46,7 +47,7 @@ namespace RAT // Function Definitions namespace RAT { - static void cast(const struct0_T *r, struct5_T *r1) + static void cast(const c_struct_T *r, struct0_T *r1) { int32_T b_loop_ub; int32_T loop_ub; @@ -238,7 +239,199 @@ namespace RAT } } - static void cast(const cell_7 *r, cell_14 *r1) + static void cast(const struct0_T *r, c_struct_T *r1) + { + int32_T b_loop_ub; + int32_T loop_ub; + r1->contrastBackgrounds.set_size(1, r->contrastBackgrounds.size(1)); + loop_ub = r->contrastBackgrounds.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastBackgrounds[i] = r->contrastBackgrounds[i]; + } + + r1->contrastBackgroundsType.set_size(1, r->contrastBackgroundsType.size(1)); + loop_ub = r->contrastBackgroundsType.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastBackgroundsType[i] = r->contrastBackgroundsType[i]; + } + + r1->TF.size[0] = 1; + r1->TF.size[1] = r->TF.size[1]; + loop_ub = r->TF.size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&r->TF.data[0], &r->TF.data[loop_ub], &r1->TF.data[0]); + } + + r1->resample.set_size(1, r->resample.size(1)); + loop_ub = r->resample.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->resample[i] = r->resample[i]; + } + + r1->dataPresent.set_size(1, r->dataPresent.size(1)); + loop_ub = r->dataPresent.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->dataPresent[i] = r->dataPresent[i]; + } + + r1->oilChiDataPresent.set_size(1, r->oilChiDataPresent.size(1)); + loop_ub = r->oilChiDataPresent.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->oilChiDataPresent[i] = r->oilChiDataPresent[i]; + } + + r1->numberOfContrasts = r->numberOfContrasts; + r1->geometry.size[0] = 1; + r1->geometry.size[1] = r->geometry.size[1]; + loop_ub = r->geometry.size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&r->geometry.data[0], &r->geometry.data[loop_ub], + &r1->geometry.data[0]); + } + + r1->useImaginary = r->useImaginary; + r1->contrastQzshifts.set_size(1, r->contrastQzshifts.size(1)); + loop_ub = r->contrastQzshifts.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastQzshifts[i] = r->contrastQzshifts[i]; + } + + r1->contrastScalefactors.set_size(1, r->contrastScalefactors.size(1)); + loop_ub = r->contrastScalefactors.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastScalefactors[i] = r->contrastScalefactors[i]; + } + + r1->contrastBulkIns.set_size(1, r->contrastBulkIns.size(1)); + loop_ub = r->contrastBulkIns.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastBulkIns[i] = r->contrastBulkIns[i]; + } + + r1->contrastBulkOuts.set_size(1, r->contrastBulkOuts.size(1)); + loop_ub = r->contrastBulkOuts.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastBulkOuts[i] = r->contrastBulkOuts[i]; + } + + r1->contrastResolutions.set_size(1, r->contrastResolutions.size(1)); + loop_ub = r->contrastResolutions.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastResolutions[i] = r->contrastResolutions[i]; + } + + r1->backgroundParams.set_size(1, r->backgroundParams.size(1)); + loop_ub = r->backgroundParams.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->backgroundParams[i] = r->backgroundParams[i]; + } + + r1->qzshifts.set_size(1, r->qzshifts.size(1)); + loop_ub = r->qzshifts.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->qzshifts[i] = r->qzshifts[i]; + } + + r1->scalefactors.set_size(1, r->scalefactors.size(1)); + loop_ub = r->scalefactors.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->scalefactors[i] = r->scalefactors[i]; + } + + r1->bulkIn.set_size(1, r->bulkIn.size(1)); + loop_ub = r->bulkIn.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->bulkIn[i] = r->bulkIn[i]; + } + + r1->bulkOut.set_size(1, r->bulkOut.size(1)); + loop_ub = r->bulkOut.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->bulkOut[i] = r->bulkOut[i]; + } + + r1->resolutionParams.set_size(1, r->resolutionParams.size(1)); + loop_ub = r->resolutionParams.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->resolutionParams[i] = r->resolutionParams[i]; + } + + r1->params.set_size(1, r->params.size(1)); + loop_ub = r->params.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->params[i] = r->params[i]; + } + + r1->numberOfLayers = r->numberOfLayers; + r1->modelType.size[0] = 1; + r1->modelType.size[1] = r->modelType.size[1]; + loop_ub = r->modelType.size[1]; + if (loop_ub - 1 >= 0) { + std::copy(&r->modelType.data[0], &r->modelType.data[loop_ub], + &r1->modelType.data[0]); + } + + r1->contrastCustomFiles.set_size(1, r->contrastCustomFiles.size(1)); + loop_ub = r->contrastCustomFiles.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastCustomFiles[i] = r->contrastCustomFiles[i]; + } + + r1->contrastDomainRatios.set_size(1, r->contrastDomainRatios.size(1)); + loop_ub = r->contrastDomainRatios.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->contrastDomainRatios[i] = r->contrastDomainRatios[i]; + } + + r1->domainRatio.set_size(1, r->domainRatio.size(1)); + loop_ub = r->domainRatio.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + r1->domainRatio[i] = r->domainRatio[i]; + } + + r1->numberOfDomainContrasts = r->numberOfDomainContrasts; + r1->fitParams.set_size(r->fitParams.size(0), r->fitParams.size(1)); + loop_ub = r->fitParams.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = r->fitParams.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r1->fitParams[i1 + r1->fitParams.size(0) * i] = r->fitParams[i1 + + r->fitParams.size(0) * i]; + } + } + + r1->otherParams.set_size(r->otherParams.size(0), r->otherParams.size(1)); + loop_ub = r->otherParams.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = r->otherParams.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r1->otherParams[i1 + r1->otherParams.size(0) * i] = r->otherParams[i1 + + r->otherParams.size(0) * i]; + } + } + + r1->fitLimits.set_size(r->fitLimits.size(0), r->fitLimits.size(1)); + loop_ub = r->fitLimits.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = r->fitLimits.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r1->fitLimits[i1 + r1->fitLimits.size(0) * i] = r->fitLimits[i1 + + r->fitLimits.size(0) * i]; + } + } + + r1->otherLimits.set_size(r->otherLimits.size(0), r->otherLimits.size(1)); + loop_ub = r->otherLimits.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = r->otherLimits.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + r1->otherLimits[i1 + r1->otherLimits.size(0) * i] = r->otherLimits[i1 + + r->otherLimits.size(0) * i]; + } + } + } + + static void cast(const cell_7 *r, cell_11 *r1) { int32_T loop_ub; r1->f1.set_size(1, r->f1.size(1)); @@ -363,64 +556,66 @@ namespace RAT } } - void RATMain(const struct0_T *problemDef, const cell_7 *problemDefCells, const - struct1_T *problemDefLimits, struct2_T *controls, const struct4_T - *priors, struct5_T *outProblemDef, struct6_T *problem, - cell_wrap_9 results[6], struct8_T *bayesResults) + void RATMain(struct0_T *problemStruct, const cell_7 *problemCells, const + struct1_T *problemLimits, struct2_T *controls, const struct4_T + *priors, struct5_T *contrastParams, cell_wrap_9 resultCells[6], + struct7_T *bayesResults) { - static d_struct_T b_bayesResults; - static struct5_T outProblemDef_tmp; + static c_struct_T b_problemStruct; + static c_struct_T r; + static g_struct_T b_bayesResults; ::coder::array t19_calculations_allChis; - cell_13 b_results; - cell_14 r; - struct_T b_problem; + cell_11 r1; + d_struct_T b_contrastParams; int32_T switch_expression_size[2]; int32_T b_loop_ub; int32_T loop_ub; - int32_T loop_ub_tmp; + int32_T problemStruct_idx_0_tmp; char_T switch_expression_data[10000]; - coder::repmat(results); - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - t19_calculations_allChis.set_size(loop_ub_tmp); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgroundParams.set_size(loop_ub_tmp); - problem->qzshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->bulkIn.set_size(loop_ub_tmp); - problem->bulkOut.set_size(loop_ub_tmp); - problem->resolutionParams.set_size(loop_ub_tmp); - for (int32_T i{0}; i < loop_ub_tmp; i++) { + coder::repmat(resultCells); + problemStruct_idx_0_tmp = static_cast + (problemStruct->numberOfContrasts); + t19_calculations_allChis.set_size(problemStruct_idx_0_tmp); + contrastParams->ssubs.set_size(problemStruct_idx_0_tmp); + contrastParams->backgroundParams.set_size(problemStruct_idx_0_tmp); + contrastParams->qzshifts.set_size(problemStruct_idx_0_tmp); + contrastParams->scalefactors.set_size(problemStruct_idx_0_tmp); + contrastParams->bulkIn.set_size(problemStruct_idx_0_tmp); + contrastParams->bulkOut.set_size(problemStruct_idx_0_tmp); + contrastParams->resolutionParams.set_size(problemStruct_idx_0_tmp); + for (int32_T i{0}; i < problemStruct_idx_0_tmp; i++) { t19_calculations_allChis[i] = 0; - problem->ssubs[i] = 0.0; - problem->backgroundParams[i] = 0.0; - problem->qzshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->bulkIn[i] = 0.0; - problem->bulkOut[i] = 0.0; - problem->resolutionParams[i] = 0.0; + contrastParams->ssubs[i] = 0.0; + contrastParams->backgroundParams[i] = 0.0; + contrastParams->qzshifts[i] = 0.0; + contrastParams->scalefactors[i] = 0.0; + contrastParams->bulkIn[i] = 0.0; + contrastParams->bulkOut[i] = 0.0; + contrastParams->resolutionParams[i] = 0.0; } - problem->calculations.allChis.set_size(t19_calculations_allChis.size(0)); + contrastParams->calculations.allChis.set_size(t19_calculations_allChis.size + (0)); loop_ub = t19_calculations_allChis.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->calculations.allChis[i] = 0.0; + contrastParams->calculations.allChis[i] = 0.0; } - problem->calculations.sumChi = 0.0; - problem->allSubRough.set_size(loop_ub_tmp); - problem->resample.set_size(loop_ub_tmp, 1); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->allSubRough[i] = 0.0; - problem->resample[i] = 0.0; + contrastParams->calculations.sumChi = 0.0; + contrastParams->allSubRough.set_size(problemStruct_idx_0_tmp); + contrastParams->resample.set_size(problemStruct_idx_0_tmp, 1); + for (int32_T i{0}; i < problemStruct_idx_0_tmp; i++) { + contrastParams->allSubRough[i] = 0.0; + contrastParams->resample[i] = 0.0; } - makeEmptyBayesResultsStruct(problemDef->numberOfContrasts, coder::internal:: - b_strcmp(problemDef->TF.data, problemDef->TF.size), controls->nChains, - bayesResults->bestFitsMean.ref, bayesResults->bestFitsMean.sld, - &bayesResults->bestFitsMean.chi, bayesResults->bestFitsMean.data, - bayesResults->predlims.refPredInts, bayesResults->predlims.sldPredInts, - bayesResults->predlims.refXdata, bayesResults->predlims.sldXdata, - bayesResults->predlims.sampleChi.data, + makeEmptyBayesResultsStruct(problemStruct->numberOfContrasts, coder:: + internal::b_strcmp(problemStruct->TF.data, problemStruct->TF.size), + controls->nChains, bayesResults->bestFitsMean.ref, + bayesResults->bestFitsMean.sld, &bayesResults->bestFitsMean.chi, + bayesResults->bestFitsMean.data, bayesResults->predlims.refPredInts, + bayesResults->predlims.sldPredInts, bayesResults->predlims.refXdata, + bayesResults->predlims.sldXdata, bayesResults->predlims.sampleChi.data, &bayesResults->predlims.sampleChi.size[0], bayesResults->parConfInts.par95, bayesResults->parConfInts.par65, bayesResults->parConfInts.mean, bayesResults->bestPars, &b_bayesResults.bayesRes, bayesResults->chain); @@ -430,8 +625,8 @@ namespace RAT b_bayesResults.bayesRes.allChains.size(2)); loop_ub = b_bayesResults.bayesRes.allChains.size(2); for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_bayesResults.bayesRes.allChains.size(1); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + problemStruct_idx_0_tmp = b_bayesResults.bayesRes.allChains.size(1); + for (int32_T i1{0}; i1 < problemStruct_idx_0_tmp; i1++) { b_loop_ub = b_bayesResults.bayesRes.allChains.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { bayesResults->bayesRes.allChains[(i2 + @@ -462,168 +657,92 @@ namespace RAT [bayesResults->bayesRes.nestOutput.postSamples.size(0)] = b_bayesResults.bayesRes.nestOutput.postSamples.data[1]; - // bayesResults = struct('bayesRes',[],... - // 'chain',[],... - // 's2chain',[],... - // 'ssChain',[],... - // 'bestPars_Mean',[],... - // 'bestFitsMean',[],... - // 'predLims',[],... - // 'parConfInts',[]); - cast(problemDef, &outProblemDef_tmp); - *outProblemDef = outProblemDef_tmp; - // Decide what we are doing.... coder::lower(controls->procedure.data, controls->procedure.size, switch_expression_data, switch_expression_size); if (coder::internal::c_strcmp(switch_expression_data, switch_expression_size)) { - loop_ub_tmp = 0; + problemStruct_idx_0_tmp = 0; } else if (coder::internal::e_strcmp(switch_expression_data, switch_expression_size)) { - loop_ub_tmp = 1; + problemStruct_idx_0_tmp = 1; } else if (coder::internal::f_strcmp(switch_expression_data, switch_expression_size)) { - loop_ub_tmp = 2; + problemStruct_idx_0_tmp = 2; } else if (coder::internal::g_strcmp(switch_expression_data, switch_expression_size)) { - loop_ub_tmp = 3; + problemStruct_idx_0_tmp = 3; } else if (coder::internal::h_strcmp(switch_expression_data, switch_expression_size)) { - loop_ub_tmp = 4; + problemStruct_idx_0_tmp = 4; } else { - loop_ub_tmp = -1; + problemStruct_idx_0_tmp = -1; } - switch (loop_ub_tmp) { + switch (problemStruct_idx_0_tmp) { case 0: // Just a single reflectivity calculation - cast(problemDef, &outProblemDef_tmp); - cast(problemDefCells, &r); - reflectivityCalculation(&outProblemDef_tmp, &r, controls, &b_problem, - &b_results); - problem->ssubs.set_size(b_problem.ssubs.size(0)); - loop_ub = b_problem.ssubs.size(0); + cast(problemStruct, &r); + cast(problemCells, &r1); + reflectivityCalculation(&r, &r1, controls, &b_contrastParams, resultCells); + contrastParams->ssubs.set_size(b_contrastParams.ssubs.size(0)); + loop_ub = b_contrastParams.ssubs.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->ssubs[i] = b_problem.ssubs[i]; + contrastParams->ssubs[i] = b_contrastParams.ssubs[i]; } - problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); - loop_ub = b_problem.backgroundParams.size(0); + contrastParams->backgroundParams.set_size + (b_contrastParams.backgroundParams.size(0)); + loop_ub = b_contrastParams.backgroundParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->backgroundParams[i] = b_problem.backgroundParams[i]; + contrastParams->backgroundParams[i] = + b_contrastParams.backgroundParams[i]; } - problem->qzshifts.set_size(b_problem.qzshifts.size(0)); - loop_ub = b_problem.qzshifts.size(0); + contrastParams->qzshifts.set_size(b_contrastParams.qzshifts.size(0)); + loop_ub = b_contrastParams.qzshifts.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->qzshifts[i] = b_problem.qzshifts[i]; + contrastParams->qzshifts[i] = b_contrastParams.qzshifts[i]; } - problem->scalefactors.set_size(b_problem.scalefactors.size(0)); - loop_ub = b_problem.scalefactors.size(0); + contrastParams->scalefactors.set_size(b_contrastParams.scalefactors.size(0)); + loop_ub = b_contrastParams.scalefactors.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->scalefactors[i] = b_problem.scalefactors[i]; + contrastParams->scalefactors[i] = b_contrastParams.scalefactors[i]; } - problem->bulkIn.set_size(b_problem.bulkIn.size(0)); - loop_ub = b_problem.bulkIn.size(0); + contrastParams->bulkIn.set_size(b_contrastParams.bulkIn.size(0)); + loop_ub = b_contrastParams.bulkIn.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkIn[i] = b_problem.bulkIn[i]; + contrastParams->bulkIn[i] = b_contrastParams.bulkIn[i]; } - problem->bulkOut.set_size(b_problem.bulkOut.size(0)); - loop_ub = b_problem.bulkOut.size(0); + contrastParams->bulkOut.set_size(b_contrastParams.bulkOut.size(0)); + loop_ub = b_contrastParams.bulkOut.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkOut[i] = b_problem.bulkOut[i]; + contrastParams->bulkOut[i] = b_contrastParams.bulkOut[i]; } - problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); - loop_ub = b_problem.resolutionParams.size(0); + contrastParams->resolutionParams.set_size + (b_contrastParams.resolutionParams.size(0)); + loop_ub = b_contrastParams.resolutionParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->resolutionParams[i] = b_problem.resolutionParams[i]; + contrastParams->resolutionParams[i] = + b_contrastParams.resolutionParams[i]; } - problem->calculations = b_problem.calculations; - problem->allSubRough.set_size(b_problem.allSubRough.size(0)); - loop_ub = b_problem.allSubRough.size(0); + contrastParams->calculations = b_contrastParams.calculations; + contrastParams->allSubRough.set_size(b_contrastParams.allSubRough.size(0)); + loop_ub = b_contrastParams.allSubRough.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->allSubRough[i] = b_problem.allSubRough[i]; + contrastParams->allSubRough[i] = b_contrastParams.allSubRough[i]; } - problem->resample.set_size(1, b_problem.resample.size(1)); - loop_ub = b_problem.resample.size(1); + contrastParams->resample.set_size(1, b_contrastParams.resample.size(1)); + loop_ub = b_contrastParams.resample.size(1); for (int32_T i{0}; i < loop_ub; i++) { - problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; - } - - results[0].f1.set_size(b_results.f1.size(0), 1); - loop_ub_tmp = b_results.f1.size(0); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - loop_ub = b_results.f1[i].f1.size(0); - results[0].f1[i].f1.set_size(b_results.f1[i].f1.size(0), 2); - for (int32_T i1{0}; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - results[0].f1[i].f1[i2 + results[0].f1[i].f1.size(0) * i1] = - b_results.f1[i].f1[i2 + b_results.f1[i].f1.size(0) * i1]; - } - } - } - - results[1].f1.set_size(b_results.f2.size(0), 1); - loop_ub_tmp = b_results.f2.size(0); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - loop_ub = b_results.f2[i].f1.size(0); - results[1].f1[i].f1.set_size(b_results.f2[i].f1.size(0), 2); - for (int32_T i1{0}; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - results[1].f1[i].f1[i2 + results[1].f1[i].f1.size(0) * i1] = - b_results.f2[i].f1[i2 + b_results.f2[i].f1.size(0) * i1]; - } - } - } - - results[2].f1.set_size(b_results.f3.size(0), 1); - loop_ub_tmp = b_results.f3.size(0); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - loop_ub = b_results.f3[i].f1.size(0); - results[2].f1[i].f1.set_size(b_results.f3[i].f1.size(0), 3); - for (int32_T i1{0}; i1 < 3; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - results[2].f1[i].f1[i2 + results[2].f1[i].f1.size(0) * i1] = - b_results.f3[i].f1[i2 + b_results.f3[i].f1.size(0) * i1]; - } - } - } - - results[3].f1.set_size(b_results.f4.size(0), b_results.f4.size(1)); - loop_ub = b_results.f4.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_results.f4.size(0); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { - results[3].f1[i1 + results[3].f1.size(0) * i] = b_results.f4[i1 + - b_results.f4.size(0) * i]; - } - } - - results[4].f1.set_size(b_results.f5.size(0), b_results.f5.size(1)); - loop_ub = b_results.f5.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_results.f5.size(0); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { - results[4].f1[i1 + results[4].f1.size(0) * i] = b_results.f5[i1 + - b_results.f5.size(0) * i]; - } - } - - results[5].f1.set_size(b_results.f6.size(0), b_results.f6.size(1)); - loop_ub = b_results.f6.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_results.f6.size(0); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { - results[5].f1[i1 + results[5].f1.size(0) * i] = b_results.f6[i1 + - b_results.f6.size(0) * i]; - } + contrastParams->resample[contrastParams->resample.size(0) * i] = + b_contrastParams.resample[i]; } break; @@ -634,62 +753,69 @@ namespace RAT fflush(stdout); } - cast(problemDefCells, &r); - runSimplex(outProblemDef, &r, problemDefLimits, controls, &b_problem, - results); - problem->ssubs.set_size(b_problem.ssubs.size(0)); - loop_ub = b_problem.ssubs.size(0); + cast(problemStruct, &b_problemStruct); + cast(problemCells, &r1); + runSimplex(&b_problemStruct, &r1, problemLimits, controls, + &b_contrastParams, resultCells); + cast(&b_problemStruct, problemStruct); + contrastParams->ssubs.set_size(b_contrastParams.ssubs.size(0)); + loop_ub = b_contrastParams.ssubs.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->ssubs[i] = b_problem.ssubs[i]; + contrastParams->ssubs[i] = b_contrastParams.ssubs[i]; } - problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); - loop_ub = b_problem.backgroundParams.size(0); + contrastParams->backgroundParams.set_size + (b_contrastParams.backgroundParams.size(0)); + loop_ub = b_contrastParams.backgroundParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->backgroundParams[i] = b_problem.backgroundParams[i]; + contrastParams->backgroundParams[i] = + b_contrastParams.backgroundParams[i]; } - problem->qzshifts.set_size(b_problem.qzshifts.size(0)); - loop_ub = b_problem.qzshifts.size(0); + contrastParams->qzshifts.set_size(b_contrastParams.qzshifts.size(0)); + loop_ub = b_contrastParams.qzshifts.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->qzshifts[i] = b_problem.qzshifts[i]; + contrastParams->qzshifts[i] = b_contrastParams.qzshifts[i]; } - problem->scalefactors.set_size(b_problem.scalefactors.size(0)); - loop_ub = b_problem.scalefactors.size(0); + contrastParams->scalefactors.set_size(b_contrastParams.scalefactors.size(0)); + loop_ub = b_contrastParams.scalefactors.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->scalefactors[i] = b_problem.scalefactors[i]; + contrastParams->scalefactors[i] = b_contrastParams.scalefactors[i]; } - problem->bulkIn.set_size(b_problem.bulkIn.size(0)); - loop_ub = b_problem.bulkIn.size(0); + contrastParams->bulkIn.set_size(b_contrastParams.bulkIn.size(0)); + loop_ub = b_contrastParams.bulkIn.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkIn[i] = b_problem.bulkIn[i]; + contrastParams->bulkIn[i] = b_contrastParams.bulkIn[i]; } - problem->bulkOut.set_size(b_problem.bulkOut.size(0)); - loop_ub = b_problem.bulkOut.size(0); + contrastParams->bulkOut.set_size(b_contrastParams.bulkOut.size(0)); + loop_ub = b_contrastParams.bulkOut.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkOut[i] = b_problem.bulkOut[i]; + contrastParams->bulkOut[i] = b_contrastParams.bulkOut[i]; } - problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); - loop_ub = b_problem.resolutionParams.size(0); + contrastParams->resolutionParams.set_size + (b_contrastParams.resolutionParams.size(0)); + loop_ub = b_contrastParams.resolutionParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->resolutionParams[i] = b_problem.resolutionParams[i]; + contrastParams->resolutionParams[i] = + b_contrastParams.resolutionParams[i]; } - problem->calculations = b_problem.calculations; - problem->allSubRough.set_size(b_problem.allSubRough.size(0)); - loop_ub = b_problem.allSubRough.size(0); + contrastParams->calculations = b_contrastParams.calculations; + contrastParams->allSubRough.set_size(b_contrastParams.allSubRough.size(0)); + loop_ub = b_contrastParams.allSubRough.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->allSubRough[i] = b_problem.allSubRough[i]; + contrastParams->allSubRough[i] = b_contrastParams.allSubRough[i]; } - problem->resample.set_size(1, b_problem.resample.size(1)); - loop_ub = b_problem.resample.size(1); + contrastParams->resample.set_size(1, b_contrastParams.resample.size(1)); + loop_ub = b_contrastParams.resample.size(1); for (int32_T i{0}; i < loop_ub; i++) { - problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; + contrastParams->resample[contrastParams->resample.size(0) * i] = + b_contrastParams.resample[i]; } break; @@ -700,61 +826,69 @@ namespace RAT fflush(stdout); } - cast(problemDefCells, &r); - runDE(outProblemDef, &r, problemDefLimits, controls, &b_problem, results); - problem->ssubs.set_size(b_problem.ssubs.size(0)); - loop_ub = b_problem.ssubs.size(0); + cast(problemStruct, &b_problemStruct); + cast(problemCells, &r1); + runDE(&b_problemStruct, &r1, problemLimits, controls, &b_contrastParams, + resultCells); + cast(&b_problemStruct, problemStruct); + contrastParams->ssubs.set_size(b_contrastParams.ssubs.size(0)); + loop_ub = b_contrastParams.ssubs.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->ssubs[i] = b_problem.ssubs[i]; + contrastParams->ssubs[i] = b_contrastParams.ssubs[i]; } - problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); - loop_ub = b_problem.backgroundParams.size(0); + contrastParams->backgroundParams.set_size + (b_contrastParams.backgroundParams.size(0)); + loop_ub = b_contrastParams.backgroundParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->backgroundParams[i] = b_problem.backgroundParams[i]; + contrastParams->backgroundParams[i] = + b_contrastParams.backgroundParams[i]; } - problem->qzshifts.set_size(b_problem.qzshifts.size(0)); - loop_ub = b_problem.qzshifts.size(0); + contrastParams->qzshifts.set_size(b_contrastParams.qzshifts.size(0)); + loop_ub = b_contrastParams.qzshifts.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->qzshifts[i] = b_problem.qzshifts[i]; + contrastParams->qzshifts[i] = b_contrastParams.qzshifts[i]; } - problem->scalefactors.set_size(b_problem.scalefactors.size(0)); - loop_ub = b_problem.scalefactors.size(0); + contrastParams->scalefactors.set_size(b_contrastParams.scalefactors.size(0)); + loop_ub = b_contrastParams.scalefactors.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->scalefactors[i] = b_problem.scalefactors[i]; + contrastParams->scalefactors[i] = b_contrastParams.scalefactors[i]; } - problem->bulkIn.set_size(b_problem.bulkIn.size(0)); - loop_ub = b_problem.bulkIn.size(0); + contrastParams->bulkIn.set_size(b_contrastParams.bulkIn.size(0)); + loop_ub = b_contrastParams.bulkIn.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkIn[i] = b_problem.bulkIn[i]; + contrastParams->bulkIn[i] = b_contrastParams.bulkIn[i]; } - problem->bulkOut.set_size(b_problem.bulkOut.size(0)); - loop_ub = b_problem.bulkOut.size(0); + contrastParams->bulkOut.set_size(b_contrastParams.bulkOut.size(0)); + loop_ub = b_contrastParams.bulkOut.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkOut[i] = b_problem.bulkOut[i]; + contrastParams->bulkOut[i] = b_contrastParams.bulkOut[i]; } - problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); - loop_ub = b_problem.resolutionParams.size(0); + contrastParams->resolutionParams.set_size + (b_contrastParams.resolutionParams.size(0)); + loop_ub = b_contrastParams.resolutionParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->resolutionParams[i] = b_problem.resolutionParams[i]; + contrastParams->resolutionParams[i] = + b_contrastParams.resolutionParams[i]; } - problem->calculations = b_problem.calculations; - problem->allSubRough.set_size(b_problem.allSubRough.size(0)); - loop_ub = b_problem.allSubRough.size(0); + contrastParams->calculations = b_contrastParams.calculations; + contrastParams->allSubRough.set_size(b_contrastParams.allSubRough.size(0)); + loop_ub = b_contrastParams.allSubRough.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->allSubRough[i] = b_problem.allSubRough[i]; + contrastParams->allSubRough[i] = b_contrastParams.allSubRough[i]; } - problem->resample.set_size(1, b_problem.resample.size(1)); - loop_ub = b_problem.resample.size(1); + contrastParams->resample.set_size(1, b_contrastParams.resample.size(1)); + loop_ub = b_contrastParams.resample.size(1); for (int32_T i{0}; i < loop_ub; i++) { - problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; + contrastParams->resample[contrastParams->resample.size(0) * i] = + b_contrastParams.resample[i]; } break; @@ -765,62 +899,69 @@ namespace RAT fflush(stdout); } - cast(problemDefCells, &r); - runNestedSampler(outProblemDef, &r, problemDefLimits, controls, priors, - &b_problem, results, bayesResults); - problem->ssubs.set_size(b_problem.ssubs.size(0)); - loop_ub = b_problem.ssubs.size(0); + cast(problemStruct, &b_problemStruct); + cast(problemCells, &r1); + runNestedSampler(&b_problemStruct, &r1, problemLimits, controls, priors, + &b_contrastParams, resultCells, bayesResults); + cast(&b_problemStruct, problemStruct); + contrastParams->ssubs.set_size(b_contrastParams.ssubs.size(0)); + loop_ub = b_contrastParams.ssubs.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->ssubs[i] = b_problem.ssubs[i]; + contrastParams->ssubs[i] = b_contrastParams.ssubs[i]; } - problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); - loop_ub = b_problem.backgroundParams.size(0); + contrastParams->backgroundParams.set_size + (b_contrastParams.backgroundParams.size(0)); + loop_ub = b_contrastParams.backgroundParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->backgroundParams[i] = b_problem.backgroundParams[i]; + contrastParams->backgroundParams[i] = + b_contrastParams.backgroundParams[i]; } - problem->qzshifts.set_size(b_problem.qzshifts.size(0)); - loop_ub = b_problem.qzshifts.size(0); + contrastParams->qzshifts.set_size(b_contrastParams.qzshifts.size(0)); + loop_ub = b_contrastParams.qzshifts.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->qzshifts[i] = b_problem.qzshifts[i]; + contrastParams->qzshifts[i] = b_contrastParams.qzshifts[i]; } - problem->scalefactors.set_size(b_problem.scalefactors.size(0)); - loop_ub = b_problem.scalefactors.size(0); + contrastParams->scalefactors.set_size(b_contrastParams.scalefactors.size(0)); + loop_ub = b_contrastParams.scalefactors.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->scalefactors[i] = b_problem.scalefactors[i]; + contrastParams->scalefactors[i] = b_contrastParams.scalefactors[i]; } - problem->bulkIn.set_size(b_problem.bulkIn.size(0)); - loop_ub = b_problem.bulkIn.size(0); + contrastParams->bulkIn.set_size(b_contrastParams.bulkIn.size(0)); + loop_ub = b_contrastParams.bulkIn.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkIn[i] = b_problem.bulkIn[i]; + contrastParams->bulkIn[i] = b_contrastParams.bulkIn[i]; } - problem->bulkOut.set_size(b_problem.bulkOut.size(0)); - loop_ub = b_problem.bulkOut.size(0); + contrastParams->bulkOut.set_size(b_contrastParams.bulkOut.size(0)); + loop_ub = b_contrastParams.bulkOut.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkOut[i] = b_problem.bulkOut[i]; + contrastParams->bulkOut[i] = b_contrastParams.bulkOut[i]; } - problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); - loop_ub = b_problem.resolutionParams.size(0); + contrastParams->resolutionParams.set_size + (b_contrastParams.resolutionParams.size(0)); + loop_ub = b_contrastParams.resolutionParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->resolutionParams[i] = b_problem.resolutionParams[i]; + contrastParams->resolutionParams[i] = + b_contrastParams.resolutionParams[i]; } - problem->calculations = b_problem.calculations; - problem->allSubRough.set_size(b_problem.allSubRough.size(0)); - loop_ub = b_problem.allSubRough.size(0); + contrastParams->calculations = b_contrastParams.calculations; + contrastParams->allSubRough.set_size(b_contrastParams.allSubRough.size(0)); + loop_ub = b_contrastParams.allSubRough.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->allSubRough[i] = b_problem.allSubRough[i]; + contrastParams->allSubRough[i] = b_contrastParams.allSubRough[i]; } - problem->resample.set_size(1, b_problem.resample.size(1)); - loop_ub = b_problem.resample.size(1); + contrastParams->resample.set_size(1, b_contrastParams.resample.size(1)); + loop_ub = b_contrastParams.resample.size(1); for (int32_T i{0}; i < loop_ub; i++) { - problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; + contrastParams->resample[contrastParams->resample.size(0) * i] = + b_contrastParams.resample[i]; } break; @@ -831,10 +972,10 @@ namespace RAT fflush(stdout); } - cast(problemDef, &outProblemDef_tmp); - cast(problemDefCells, &r); - runDREAM(&outProblemDef_tmp, &r, problemDefLimits, controls, priors, - outProblemDef, &b_problem, results, &b_bayesResults); + cast(problemStruct, &r); + cast(problemCells, &r1); + runDREAM(&r, &r1, problemLimits, controls, priors, &b_problemStruct, + &b_contrastParams, resultCells, &b_bayesResults); bayesResults->bestFitsMean = b_bayesResults.bestFitsMean; bayesResults->predlims = b_bayesResults.predlims; bayesResults->parConfInts = b_bayesResults.parConfInts; @@ -848,66 +989,72 @@ namespace RAT b_bayesResults.chain.size(1)); loop_ub = b_bayesResults.chain.size(1); for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_bayesResults.chain.size(0); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + problemStruct_idx_0_tmp = b_bayesResults.chain.size(0); + for (int32_T i1{0}; i1 < problemStruct_idx_0_tmp; i1++) { bayesResults->chain[i1 + bayesResults->chain.size(0) * i] = b_bayesResults.chain[i1 + b_bayesResults.chain.size(0) * i]; } } - problem->ssubs.set_size(b_problem.ssubs.size(0)); - loop_ub = b_problem.ssubs.size(0); + cast(&b_problemStruct, problemStruct); + contrastParams->ssubs.set_size(b_contrastParams.ssubs.size(0)); + loop_ub = b_contrastParams.ssubs.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->ssubs[i] = b_problem.ssubs[i]; + contrastParams->ssubs[i] = b_contrastParams.ssubs[i]; } - problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); - loop_ub = b_problem.backgroundParams.size(0); + contrastParams->backgroundParams.set_size + (b_contrastParams.backgroundParams.size(0)); + loop_ub = b_contrastParams.backgroundParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->backgroundParams[i] = b_problem.backgroundParams[i]; + contrastParams->backgroundParams[i] = + b_contrastParams.backgroundParams[i]; } - problem->qzshifts.set_size(b_problem.qzshifts.size(0)); - loop_ub = b_problem.qzshifts.size(0); + contrastParams->qzshifts.set_size(b_contrastParams.qzshifts.size(0)); + loop_ub = b_contrastParams.qzshifts.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->qzshifts[i] = b_problem.qzshifts[i]; + contrastParams->qzshifts[i] = b_contrastParams.qzshifts[i]; } - problem->scalefactors.set_size(b_problem.scalefactors.size(0)); - loop_ub = b_problem.scalefactors.size(0); + contrastParams->scalefactors.set_size(b_contrastParams.scalefactors.size(0)); + loop_ub = b_contrastParams.scalefactors.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->scalefactors[i] = b_problem.scalefactors[i]; + contrastParams->scalefactors[i] = b_contrastParams.scalefactors[i]; } - problem->bulkIn.set_size(b_problem.bulkIn.size(0)); - loop_ub = b_problem.bulkIn.size(0); + contrastParams->bulkIn.set_size(b_contrastParams.bulkIn.size(0)); + loop_ub = b_contrastParams.bulkIn.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkIn[i] = b_problem.bulkIn[i]; + contrastParams->bulkIn[i] = b_contrastParams.bulkIn[i]; } - problem->bulkOut.set_size(b_problem.bulkOut.size(0)); - loop_ub = b_problem.bulkOut.size(0); + contrastParams->bulkOut.set_size(b_contrastParams.bulkOut.size(0)); + loop_ub = b_contrastParams.bulkOut.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkOut[i] = b_problem.bulkOut[i]; + contrastParams->bulkOut[i] = b_contrastParams.bulkOut[i]; } - problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); - loop_ub = b_problem.resolutionParams.size(0); + contrastParams->resolutionParams.set_size + (b_contrastParams.resolutionParams.size(0)); + loop_ub = b_contrastParams.resolutionParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->resolutionParams[i] = b_problem.resolutionParams[i]; + contrastParams->resolutionParams[i] = + b_contrastParams.resolutionParams[i]; } - problem->calculations = b_problem.calculations; - problem->allSubRough.set_size(b_problem.allSubRough.size(0)); - loop_ub = b_problem.allSubRough.size(0); + contrastParams->calculations = b_contrastParams.calculations; + contrastParams->allSubRough.set_size(b_contrastParams.allSubRough.size(0)); + loop_ub = b_contrastParams.allSubRough.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->allSubRough[i] = b_problem.allSubRough[i]; + contrastParams->allSubRough[i] = b_contrastParams.allSubRough[i]; } - problem->resample.set_size(1, b_problem.resample.size(1)); - loop_ub = b_problem.resample.size(1); + contrastParams->resample.set_size(1, b_contrastParams.resample.size(1)); + loop_ub = b_contrastParams.resample.size(1); for (int32_T i{0}; i < loop_ub; i++) { - problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; + contrastParams->resample[contrastParams->resample.size(0) * i] = + b_contrastParams.resample[i]; } bayesResults->bayesRes.allChains.set_size @@ -916,8 +1063,8 @@ namespace RAT b_bayesResults.bayesRes.allChains.size(2)); loop_ub = b_bayesResults.bayesRes.allChains.size(2); for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_bayesResults.bayesRes.allChains.size(1); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + problemStruct_idx_0_tmp = b_bayesResults.bayesRes.allChains.size(1); + for (int32_T i1{0}; i1 < problemStruct_idx_0_tmp; i1++) { b_loop_ub = b_bayesResults.bayesRes.allChains.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { bayesResults->bayesRes.allChains[(i2 + @@ -957,134 +1104,70 @@ namespace RAT controls->procedure.size[0] = 1; controls->procedure.size[1] = 9; for (int32_T i{0}; i < 9; i++) { - controls->procedure.data[i] = cv[i]; + controls->procedure.data[i] = cv1[i]; } - cast(problemDefCells, &r); - reflectivityCalculation(outProblemDef, &r, controls, &b_problem, - &b_results); - problem->ssubs.set_size(b_problem.ssubs.size(0)); - loop_ub = b_problem.ssubs.size(0); + cast(problemStruct, &r); + cast(problemCells, &r1); + reflectivityCalculation(&r, &r1, controls, &b_contrastParams, resultCells); + contrastParams->ssubs.set_size(b_contrastParams.ssubs.size(0)); + loop_ub = b_contrastParams.ssubs.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->ssubs[i] = b_problem.ssubs[i]; + contrastParams->ssubs[i] = b_contrastParams.ssubs[i]; } - problem->backgroundParams.set_size(b_problem.backgroundParams.size(0)); - loop_ub = b_problem.backgroundParams.size(0); + contrastParams->backgroundParams.set_size + (b_contrastParams.backgroundParams.size(0)); + loop_ub = b_contrastParams.backgroundParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->backgroundParams[i] = b_problem.backgroundParams[i]; + contrastParams->backgroundParams[i] = + b_contrastParams.backgroundParams[i]; } - problem->qzshifts.set_size(b_problem.qzshifts.size(0)); - loop_ub = b_problem.qzshifts.size(0); + contrastParams->qzshifts.set_size(b_contrastParams.qzshifts.size(0)); + loop_ub = b_contrastParams.qzshifts.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->qzshifts[i] = b_problem.qzshifts[i]; + contrastParams->qzshifts[i] = b_contrastParams.qzshifts[i]; } - problem->scalefactors.set_size(b_problem.scalefactors.size(0)); - loop_ub = b_problem.scalefactors.size(0); + contrastParams->scalefactors.set_size(b_contrastParams.scalefactors.size(0)); + loop_ub = b_contrastParams.scalefactors.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->scalefactors[i] = b_problem.scalefactors[i]; + contrastParams->scalefactors[i] = b_contrastParams.scalefactors[i]; } - problem->bulkIn.set_size(b_problem.bulkIn.size(0)); - loop_ub = b_problem.bulkIn.size(0); + contrastParams->bulkIn.set_size(b_contrastParams.bulkIn.size(0)); + loop_ub = b_contrastParams.bulkIn.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkIn[i] = b_problem.bulkIn[i]; + contrastParams->bulkIn[i] = b_contrastParams.bulkIn[i]; } - problem->bulkOut.set_size(b_problem.bulkOut.size(0)); - loop_ub = b_problem.bulkOut.size(0); + contrastParams->bulkOut.set_size(b_contrastParams.bulkOut.size(0)); + loop_ub = b_contrastParams.bulkOut.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->bulkOut[i] = b_problem.bulkOut[i]; + contrastParams->bulkOut[i] = b_contrastParams.bulkOut[i]; } - problem->resolutionParams.set_size(b_problem.resolutionParams.size(0)); - loop_ub = b_problem.resolutionParams.size(0); + contrastParams->resolutionParams.set_size + (b_contrastParams.resolutionParams.size(0)); + loop_ub = b_contrastParams.resolutionParams.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->resolutionParams[i] = b_problem.resolutionParams[i]; + contrastParams->resolutionParams[i] = + b_contrastParams.resolutionParams[i]; } - problem->calculations = b_problem.calculations; - problem->allSubRough.set_size(b_problem.allSubRough.size(0)); - loop_ub = b_problem.allSubRough.size(0); + contrastParams->calculations = b_contrastParams.calculations; + contrastParams->allSubRough.set_size(b_contrastParams.allSubRough.size(0)); + loop_ub = b_contrastParams.allSubRough.size(0); for (int32_T i{0}; i < loop_ub; i++) { - problem->allSubRough[i] = b_problem.allSubRough[i]; + contrastParams->allSubRough[i] = b_contrastParams.allSubRough[i]; } - problem->resample.set_size(1, b_problem.resample.size(1)); - loop_ub = b_problem.resample.size(1); + contrastParams->resample.set_size(1, b_contrastParams.resample.size(1)); + loop_ub = b_contrastParams.resample.size(1); for (int32_T i{0}; i < loop_ub; i++) { - problem->resample[problem->resample.size(0) * i] = b_problem.resample[i]; - } - - results[0].f1.set_size(b_results.f1.size(0), 1); - loop_ub_tmp = b_results.f1.size(0); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - loop_ub = b_results.f1[i].f1.size(0); - results[0].f1[i].f1.set_size(b_results.f1[i].f1.size(0), 2); - for (int32_T i1{0}; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - results[0].f1[i].f1[i2 + results[0].f1[i].f1.size(0) * i1] = - b_results.f1[i].f1[i2 + b_results.f1[i].f1.size(0) * i1]; - } - } - } - - results[1].f1.set_size(b_results.f2.size(0), 1); - loop_ub_tmp = b_results.f2.size(0); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - loop_ub = b_results.f2[i].f1.size(0); - results[1].f1[i].f1.set_size(b_results.f2[i].f1.size(0), 2); - for (int32_T i1{0}; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - results[1].f1[i].f1[i2 + results[1].f1[i].f1.size(0) * i1] = - b_results.f2[i].f1[i2 + b_results.f2[i].f1.size(0) * i1]; - } - } - } - - results[2].f1.set_size(b_results.f3.size(0), 1); - loop_ub_tmp = b_results.f3.size(0); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - loop_ub = b_results.f3[i].f1.size(0); - results[2].f1[i].f1.set_size(b_results.f3[i].f1.size(0), 3); - for (int32_T i1{0}; i1 < 3; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - results[2].f1[i].f1[i2 + results[2].f1[i].f1.size(0) * i1] = - b_results.f3[i].f1[i2 + b_results.f3[i].f1.size(0) * i1]; - } - } - } - - results[3].f1.set_size(b_results.f4.size(0), b_results.f4.size(1)); - loop_ub = b_results.f4.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_results.f4.size(0); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { - results[3].f1[i1 + results[3].f1.size(0) * i] = b_results.f4[i1 + - b_results.f4.size(0) * i]; - } - } - - results[4].f1.set_size(b_results.f5.size(0), b_results.f5.size(1)); - loop_ub = b_results.f5.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_results.f5.size(0); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { - results[4].f1[i1 + results[4].f1.size(0) * i] = b_results.f5[i1 + - b_results.f5.size(0) * i]; - } - } - - results[5].f1.set_size(b_results.f6.size(0), b_results.f6.size(1)); - loop_ub = b_results.f6.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_results.f6.size(0); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { - results[5].f1[i1 + results[5].f1.size(0) * i] = b_results.f6[i1 + - b_results.f6.size(0) * i]; - } + contrastParams->resample[contrastParams->resample.size(0) * i] = + b_contrastParams.resample[i]; } } } diff --git a/RAT/RATMain.h b/RAT/RATMain.h index 533ad963..3907ecfd 100644 --- a/RAT/RATMain.h +++ b/RAT/RATMain.h @@ -19,11 +19,10 @@ // Function Declarations namespace RAT { - extern void RATMain(const struct0_T *problemDef, const cell_7 *problemDefCells, - const struct1_T *problemDefLimits, struct2_T *controls, - const struct4_T *priors, struct5_T *outProblemDef, - struct6_T *problem, cell_wrap_9 results[6], struct8_T - *bayesResults); + extern void RATMain(struct0_T *problemStruct, const cell_7 *problemCells, + const struct1_T *problemLimits, struct2_T *controls, const + struct4_T *priors, struct5_T *contrastParams, cell_wrap_9 + resultCells[6], struct7_T *bayesResults); } #endif diff --git a/RAT/RATMain_data.cpp b/RAT/RATMain_data.cpp index 33bb8d40..64bc66a1 100644 --- a/RAT/RATMain_data.cpp +++ b/RAT/RATMain_data.cpp @@ -23,9 +23,7 @@ namespace RAT real_T freq; boolean_T freq_not_empty; omp_nest_lock_t RATMain_nestLockGlobal; - const char_T cv[9]{ 'c', 'a', 'l', 'c', 'u', 'l', 'a', 't', 'e' }; - - const char_T cv1[128]{ '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', + const char_T cv[128]{ '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', ' ', '!', '\"', '#', @@ -172,6 +170,8 @@ namespace RAT 0.00861658276939875, 0.00705087547137324, 0.00552240329925101, 0.00403797259336304, 0.00260907274610216, 0.0012602859304986, 0.000477467764609386 }; + + const char_T cv1[9]{ 'c', 'a', 'l', 'c', 'u', 'l', 'a', 't', 'e' }; } // End of code generation (RATMain_data.cpp) diff --git a/RAT/RATMain_data.h b/RAT/RATMain_data.h index 44fd1366..9ad8933d 100644 --- a/RAT/RATMain_data.h +++ b/RAT/RATMain_data.h @@ -27,10 +27,10 @@ namespace RAT extern real_T freq; extern boolean_T freq_not_empty; extern omp_nest_lock_t RATMain_nestLockGlobal; - extern const char_T cv[9]; - extern const char_T cv1[128]; + extern const char_T cv[128]; extern const real_T dv[257]; extern const real_T dv1[257]; + extern const char_T cv1[9]; } #endif diff --git a/RAT/RATMain_internal_types.h b/RAT/RATMain_internal_types.h index 3e937962..88ccad69 100644 --- a/RAT/RATMain_internal_types.h +++ b/RAT/RATMain_internal_types.h @@ -19,55 +19,66 @@ // Type Definitions namespace RAT { - struct cell_13 - { - ::coder::array f1; - ::coder::array f2; - ::coder::array f3; - ::coder::array f4; - ::coder::array f5; - ::coder::array f6; - }; - struct struct_T - { - ::coder::array ssubs; - ::coder::array backgroundParams; - ::coder::array qzshifts; - ::coder::array scalefactors; - ::coder::array bulkIn; - ::coder::array bulkOut; - ::coder::array resolutionParams; - struct7_T calculations; - ::coder::array allSubRough; - ::coder::array resample; - }; - - struct b_struct_T { real_T LogZ; ::coder::bounded_array nestSamples; ::coder::bounded_array postSamples; }; - struct c_struct_T + struct b_struct_T { ::coder::array allChains; - struct13_T dreamOutput; - b_struct_T nestOutput; + struct12_T dreamOutput; + struct_T nestOutput; }; - struct d_struct_T + struct cell_wrap_12 { - struct9_T bestFitsMean; - struct10_T predlims; - struct11_T parConfInts; - ::coder::array bestPars; - c_struct_T bayesRes; - ::coder::array chain; + ::coder::array f1; + }; + + struct cell_wrap_14 + { + ::coder::array f1; }; - struct cell_14 + struct c_struct_T + { + ::coder::array contrastBackgrounds; + ::coder::array contrastBackgroundsType; + ::coder::bounded_array TF; + ::coder::array resample; + ::coder::array dataPresent; + ::coder::array oilChiDataPresent; + real_T numberOfContrasts; + ::coder::bounded_array geometry; + boolean_T useImaginary; + ::coder::array contrastQzshifts; + ::coder::array contrastScalefactors; + ::coder::array contrastBulkIns; + ::coder::array contrastBulkOuts; + ::coder::array contrastResolutions; + ::coder::array backgroundParams; + ::coder::array qzshifts; + ::coder::array scalefactors; + ::coder::array bulkIn; + ::coder::array bulkOut; + ::coder::array resolutionParams; + ::coder::array params; + real_T numberOfLayers; + ::coder::bounded_array modelType; + ::coder::array contrastCustomFiles; + ::coder::array contrastDomainRatios; + ::coder::array domainRatio; + real_T numberOfDomainContrasts; + ::coder::array fitParams; + ::coder::array otherParams; + ::coder::array fitLimits; + ::coder::array otherLimits; + }; + + struct cell_11 { ::coder::array f1; ::coder::array f2; @@ -91,44 +102,63 @@ namespace RAT ::coder::array f20; }; - struct cell_wrap_15 + struct d_struct_T { - ::coder::array f1; + ::coder::array ssubs; + ::coder::array backgroundParams; + ::coder::array qzshifts; + ::coder::array scalefactors; + ::coder::array bulkIn; + ::coder::array bulkOut; + ::coder::array resolutionParams; + struct6_T calculations; + ::coder::array allSubRough; + ::coder::array resample; }; - struct cell_wrap_17 + struct cell_wrap_34 { - ::coder::array f1; + ::coder::array f1; }; - struct cell_wrap_36 + struct cell_wrap_20 { ::coder::array f1; }; - struct cell_wrap_37 + struct cell_wrap_35 { cell_wrap_8 f1[2]; }; struct e_struct_T { - ::coder::array ref; + ::coder::array ref; ::coder::array sld; real_T chi; - ::coder::array data; + ::coder::array data; }; struct f_struct_T { - ::coder::array refPredInts; - ::coder::array sldPredInts; - ::coder::array refXdata; - ::coder::array sldXdata; + ::coder::array refPredInts; + ::coder::array sldPredInts; + ::coder::array refXdata; + ::coder::array sldXdata; real_T sampleChi[1000]; }; - struct h_struct_T + struct g_struct_T + { + struct8_T bestFitsMean; + struct9_T predlims; + struct10_T parConfInts; + ::coder::array bestPars; + b_struct_T bayesRes; + ::coder::array chain; + }; + + struct i_struct_T { real_T iterations; real_T funcCount; @@ -136,7 +166,7 @@ namespace RAT ::coder::array message; }; - struct i_struct_T + struct j_struct_T { ::coder::bounded_array I_lentol; ::coder::bounded_array FVr_x; @@ -158,19 +188,19 @@ namespace RAT ::coder::array FVr_bestmem; }; - struct cell_27 + struct cell_25 { ::coder::array f1; }; - struct j_struct_T + struct k_struct_T { ::coder::array LB; ::coder::array UB; ::coder::array BoundClass; }; - struct k_struct_T + struct l_struct_T { real_T I_no; real_T FVr_oa; diff --git a/RAT/RATMain_rtwutil.cpp b/RAT/RATMain_rtwutil.cpp index ede48b37..d8967461 100644 --- a/RAT/RATMain_rtwutil.cpp +++ b/RAT/RATMain_rtwutil.cpp @@ -30,7 +30,7 @@ namespace RAT // Function Definitions namespace RAT { - void cast(const ::coder::array &r, ::coder::array< + void cast(const ::coder::array &r, ::coder::array< cell_wrap_8, 1U> &r1) { int32_T i; @@ -48,61 +48,41 @@ namespace RAT } } - void cast(const ::coder::array &r, ::coder::array< - cell_wrap_8, 1U> &r1) + void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1) { int32_T i; - r1.set_size(r.size(0)); - i = r.size(0); + r1.set_size(r.size(0), r.size(1)); + i = r.size(0) * r.size(1); for (int32_T i1{0}; i1 < i; i1++) { int32_T loop_ub; loop_ub = r[i1].f1.size(1); - r1[i1].f1.set_size(1, r[i1].f1.size(1)); + r1[i1].f1.set_size(5, r[i1].f1.size(1)); for (int32_T i2{0}; i2 < loop_ub; i2++) { - r1[i1].f1[r1[i1].f1.size(0) * i2] = r[i1].f1[i2]; - } - } - } - - void cast(const ::coder::array &r, ::coder::array< - cell_wrap_8, 1U> &r1) - { - int32_T i; - r1.set_size(r.size(0)); - i = r.size(0); - for (int32_T i1{0}; i1 < i; i1++) { - int32_T loop_ub; - loop_ub = r[i1].f1.size(0); - r1[i1].f1.set_size(r[i1].f1.size(0), 2); - for (int32_T i2{0}; i2 < 2; i2++) { - for (int32_T i3{0}; i3 < loop_ub; i3++) { - r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) - * i2]; + for (int32_T i3{0}; i3 < 5; i3++) { + r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + 5 * i2]; } } } } - void cast(const ::coder::array &r, ::coder::array< - cell_wrap_8, 1U> &r1) + void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1) { int32_T i; - r1.set_size(r.size(0)); - i = r.size(0); + r1.set_size(r.size(0), r.size(1)); + i = r.size(0) * r.size(1); for (int32_T i1{0}; i1 < i; i1++) { int32_T loop_ub; - loop_ub = r[i1].f1.size(0); - r1[i1].f1.set_size(r[i1].f1.size(0), 3); - for (int32_T i2{0}; i2 < 3; i2++) { - for (int32_T i3{0}; i3 < loop_ub; i3++) { - r1[i1].f1[i3 + r1[i1].f1.size(0) * i2] = r[i1].f1[i3 + r[i1].f1.size(0) - * i2]; - } + loop_ub = r[i1].f1.size(1); + r1[i1].f1.set_size(1, r[i1].f1.size(1)); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + r1[i1].f1[r1[i1].f1.size(0) * i2] = r[i1].f1[i2]; } } } - void cast(const ::coder::array &r, ::coder::array< + void cast(const ::coder::array &r, ::coder::array< cell_wrap_8, 2U> &r1) { int32_T i; diff --git a/RAT/RATMain_rtwutil.h b/RAT/RATMain_rtwutil.h index c53ef8e1..b0747c4d 100644 --- a/RAT/RATMain_rtwutil.h +++ b/RAT/RATMain_rtwutil.h @@ -20,15 +20,13 @@ // Function Declarations namespace RAT { - extern void cast(const ::coder::array &r, ::coder::array< + extern void cast(const ::coder::array &r, ::coder::array< cell_wrap_8, 1U> &r1); - extern void cast(const ::coder::array &r, ::coder::array< - cell_wrap_8, 1U> &r1); - extern void cast(const ::coder::array &r, ::coder::array< - cell_wrap_8, 1U> &r1); - extern void cast(const ::coder::array &r, ::coder::array< - cell_wrap_8, 1U> &r1); - extern void cast(const ::coder::array &r, ::coder::array< + extern void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1); + extern void cast(const ::coder::array &r, ::coder::array< + cell_wrap_8, 2U> &r1); + extern void cast(const ::coder::array &r, ::coder::array< cell_wrap_8, 2U> &r1); extern void emlrtFreeThreadStackData(); extern RATMainTLS *emlrtGetThreadStackData(); diff --git a/RAT/RATMain_types.h b/RAT/RATMain_types.h index 90b06705..3310a603 100644 --- a/RAT/RATMain_types.h +++ b/RAT/RATMain_types.h @@ -19,7 +19,7 @@ // Type Definitions namespace RAT { - struct struct15_T + struct struct14_T { real_T Y; real_T N; @@ -30,95 +30,58 @@ namespace RAT real_T f1[2]; }; - struct struct0_T - { - ::coder::array contrastBackgrounds; - ::coder::array contrastBackgroundsType; - ::coder::bounded_array TF; - ::coder::array resample; - ::coder::array dataPresent; - ::coder::array oilChiDataPresent; - real_T numberOfContrasts; - ::coder::bounded_array geometry; - boolean_T useImaginary; - ::coder::array contrastQzshifts; - ::coder::array contrastScalefactors; - ::coder::array contrastBulkIns; - ::coder::array contrastBulkOuts; - ::coder::array contrastResolutions; - ::coder::array backgroundParams; - ::coder::array qzshifts; - ::coder::array scalefactors; - ::coder::array bulkIn; - ::coder::array bulkOut; - ::coder::array resolutionParams; - ::coder::array params; - real_T numberOfLayers; - ::coder::bounded_array modelType; - ::coder::array contrastCustomFiles; - ::coder::array contrastDomainRatios; - ::coder::array domainRatio; - real_T numberOfDomainContrasts; - ::coder::array fitParams; - ::coder::array otherParams; - ::coder::array fitLimits; - ::coder::array otherLimits; - }; - - struct cell_wrap_3 - { - ::coder::array f1; - }; - - struct cell_wrap_4 + struct cell_wrap_8 { ::coder::array f1; }; - struct cell_wrap_5 + struct cell_wrap_9 { - ::coder::bounded_array f1; + ::coder::array f1; }; - struct cell_wrap_6 + struct struct13_T { - ::coder::bounded_array f1; + real_T d; + real_T N; + real_T T; + boolean_T parallel; + real_T CPU; + real_T lambda; + real_T pUnitGamma; + real_T nCR; + real_T delta; + real_T steps; + real_T zeta; + char_T outlier[3]; + boolean_T adaptPCR; + real_T thinning; + real_T epsilon; + boolean_T ABC; + boolean_T IO; + boolean_T modout; + boolean_T restart; + boolean_T save; + ::coder::array R; }; - struct cell_7 + struct struct12_T { - ::coder::array f1; - ::coder::array f2; - ::coder::array f3; - ::coder::array f4; - ::coder::array f5; - ::coder::array f6; - ::coder::array f7; - ::coder::array f8; - ::coder::array f9; - ::coder::array f10; - ::coder::array f11; - ::coder::array f12; - ::coder::array f13; - ::coder::array f14; - ::coder::array f15; - ::coder::array f16; - ::coder::array f17; - ::coder::array f18; - ::coder::array f19; - ::coder::array f20; + ::coder::bounded_array outlier; + real_T RunTime; + struct13_T DREAMPar; + struct14_T Meas_info; + real_T iteration; + real_T iloc; + real_T fx; + ::coder::bounded_array AR; + ::coder::array R_stat; + ::coder::array CR; }; - struct struct1_T + struct cell_wrap_1 { - ::coder::array param; - ::coder::array backgroundParam; - ::coder::array scalefactor; - ::coder::array qzshift; - ::coder::array bulkIn; - ::coder::array bulkOut; - ::coder::array resolutionParam; - ::coder::array domainRatio; + ::coder::array f1; }; struct struct3_T @@ -165,6 +128,46 @@ namespace RAT struct3_T checks; }; + struct struct6_T + { + ::coder::array allChis; + real_T sumChi; + }; + + struct cell_wrap_18 + { + ::coder::array f1; + }; + + struct cell_wrap_22 + { + ::coder::array f1; + }; + + struct cell_wrap_48 + { + ::coder::array f1; + }; + + struct struct10_T + { + ::coder::array par95; + ::coder::array par65; + ::coder::array mean; + }; + + struct struct1_T + { + ::coder::array param; + ::coder::array backgroundParam; + ::coder::array scalefactor; + ::coder::array qzshift; + ::coder::array bulkIn; + ::coder::array bulkOut; + ::coder::array resolutionParam; + ::coder::array domainRatio; + }; + struct cell_0 { ::coder::array f1; @@ -173,11 +176,6 @@ namespace RAT real_T f4; }; - struct cell_wrap_1 - { - ::coder::array f1; - }; - struct struct4_T { ::coder::array param; @@ -192,7 +190,68 @@ namespace RAT ::coder::array priorValues; }; - struct struct5_T + struct struct8_T + { + ::coder::array ref; + ::coder::array sld; + real_T chi; + ::coder::array data; + }; + + struct struct9_T + { + ::coder::array refPredInts; + ::coder::array sldPredInts; + ::coder::array refXdata; + ::coder::array sldXdata; + ::coder::bounded_array sampleChi; + }; + + struct cell_wrap_3 + { + ::coder::array f1; + }; + + struct cell_wrap_4 + { + ::coder::array f1; + }; + + struct cell_wrap_5 + { + ::coder::bounded_array f1; + }; + + struct cell_wrap_6 + { + ::coder::bounded_array f1; + }; + + struct cell_7 + { + ::coder::array f1; + ::coder::array f2; + ::coder::array f3; + ::coder::array f4; + ::coder::array f5; + ::coder::array f6; + ::coder::array f7; + ::coder::array f8; + ::coder::array f9; + ::coder::array f10; + ::coder::array f11; + ::coder::array f12; + ::coder::array f13; + ::coder::array f14; + ::coder::array f15; + ::coder::array f16; + ::coder::array f17; + ::coder::array f18; + ::coder::array f19; + ::coder::array f20; + }; + + struct struct0_T { ::coder::array contrastBackgrounds; ::coder::array contrastBackgroundsType; @@ -227,13 +286,7 @@ namespace RAT ::coder::array otherLimits; }; - struct struct7_T - { - ::coder::array allChis; - real_T sumChi; - }; - - struct struct6_T + struct struct5_T { ::coder::array ssubs; ::coder::array backgroundParams; @@ -242,149 +295,40 @@ namespace RAT ::coder::array bulkIn; ::coder::array bulkOut; ::coder::array resolutionParams; - struct7_T calculations; + struct6_T calculations; ::coder::array allSubRough; ::coder::array resample; }; - struct cell_wrap_8 - { - ::coder::array f1; - }; - - struct cell_wrap_9 - { - ::coder::array f1; - }; - - struct struct9_T - { - ::coder::array ref; - ::coder::array sld; - real_T chi; - ::coder::array data; - }; - - struct struct10_T - { - ::coder::array refPredInts; - ::coder::array sldPredInts; - ::coder::array refXdata; - ::coder::array sldXdata; - ::coder::bounded_array sampleChi; - }; - - struct struct11_T - { - ::coder::array par95; - ::coder::array par65; - ::coder::array mean; - }; - - struct struct14_T - { - real_T d; - real_T N; - real_T T; - boolean_T parallel; - real_T CPU; - real_T lambda; - real_T pUnitGamma; - real_T nCR; - real_T delta; - real_T steps; - real_T zeta; - char_T outlier[3]; - boolean_T adaptPCR; - real_T thinning; - real_T epsilon; - boolean_T ABC; - boolean_T IO; - boolean_T modout; - boolean_T restart; - boolean_T save; - ::coder::array R; - }; - - struct struct13_T - { - ::coder::bounded_array outlier; - real_T RunTime; - struct14_T DREAMPar; - struct15_T Meas_info; - real_T iteration; - real_T iloc; - real_T fx; - ::coder::bounded_array AR; - ::coder::array R_stat; - ::coder::array CR; - }; - - struct struct16_T + struct struct15_T { real_T LogZ; ::coder::array nestSamples; ::coder::array postSamples; }; - struct struct12_T + struct struct11_T { ::coder::array allChains; - struct13_T dreamOutput; - struct16_T nestOutput; + struct12_T dreamOutput; + struct15_T nestOutput; }; - struct struct8_T + struct struct7_T { - struct9_T bestFitsMean; - struct10_T predlims; - struct11_T parConfInts; + struct8_T bestFitsMean; + struct9_T predlims; + struct10_T parConfInts; ::coder::array bestPars; - struct12_T bayesRes; + struct11_T bayesRes; ::coder::array chain; }; - struct cell_wrap_11 - { - ::coder::array f1; - }; - - struct cell_wrap_20 - { - ::coder::array f1; - }; - - struct cell_wrap_21 - { - ::coder::array f1; - }; - - struct cell_wrap_24 - { - ::coder::array f1; - }; - - struct cell_wrap_50 - { - ::coder::array f1; - }; - struct SLDFunction { int32_T belowVals_data[10000]; }; - struct normalizeFunction - { - real_T tmp_data[6000]; - }; - - struct resampleLayersReIm - { - real_T sldProfileIm_data[6000]; - real_T b_sldProfileIm_data[6000]; - }; - struct parallelContrasts { real_T thisContrastLayers2_data[6000]; @@ -399,10 +343,8 @@ namespace RAT struct RATMainTLS { SLDFunction f0; - normalizeFunction f1; - resampleLayersReIm f2; - parallelContrasts f3; - b_parallelContrasts f4; + parallelContrasts f1; + b_parallelContrasts f2; }; } diff --git a/RAT/SLDFunction.cpp b/RAT/SLDFunction.cpp index 47dd6ae8..20778a0f 100644 --- a/RAT/SLDFunction.cpp +++ b/RAT/SLDFunction.cpp @@ -20,127 +20,6 @@ // Function Definitions namespace RAT { - void b_SLDFunction(real_T x, const ::coder::array &SLD, real_T - sldVal_data[], int32_T *sldVal_size) - { - ::coder::array b_i; - ::coder::array c_i; - ::coder::array r; - ::coder::array b_SLD_data; - ::coder::array c_SLD_data; - ::coder::array d_SLD_data; - ::coder::array e_SLD_data; - ::coder::array f_SLD_data; - int32_T SLD_size; - int32_T loop_ub; - boolean_T SLD_data[6000]; - - // sldVal = SLDFunction(x,SLD) - // SLD = [x rho;....xn rho] - // x = value in Angstrom. - // - // This function returns the SLD (y) value associated with the - // supplied value of x. SLD is a two column, XY array defining an - // SLD profile. This function interpolates the SLD profile - // to return the SLD at the specific value of X. X can be a vector of - // multiple points. - // - // (c) Arwel Hughes 2019. - // Last modified - AVH, 26/11/19. - // global sldProfile - // - // SLD = sldProfile; - // SLD = getappdata(0,'SLDFunctionSLD'); - SLD_size = SLD.size(0); - loop_ub = SLD.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - SLD_data[i] = (SLD[i] == x); - } - - b_SLD_data.set(&SLD_data[0], SLD_size); - coder::eml_find(b_SLD_data, r); - b_i.set_size(r.size(0)); - loop_ub = r.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - b_i[i] = r[i]; - } - - if (b_i.size(0) != 0) { - *sldVal_size = b_i.size(0); - loop_ub = b_i.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - sldVal_data[i] = SLD[(b_i[i] + SLD.size(0)) - 1]; - } - } else { - real_T deltaY; - int32_T belowVals_data[6000]; - int32_T belowVals_size; - SLD_size = SLD.size(0); - loop_ub = SLD.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - SLD_data[i] = (x > SLD[i]); - } - - c_SLD_data.set(&SLD_data[0], SLD_size); - coder::eml_find(c_SLD_data, r); - b_i.set_size(r.size(0)); - loop_ub = r.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - b_i[i] = r[i]; - } - - SLD_size = SLD.size(0); - loop_ub = SLD.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - SLD_data[i] = (x > SLD[i]); - } - - d_SLD_data.set(&SLD_data[0], SLD_size); - coder::eml_find(d_SLD_data, r); - belowVals_size = r.size(0); - loop_ub = r.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - belowVals_data[i] = r[i]; - } - - SLD_size = SLD.size(0); - loop_ub = SLD.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - SLD_data[i] = (x < SLD[i]); - } - - e_SLD_data.set(&SLD_data[0], SLD_size); - coder::eml_find(e_SLD_data, r); - c_i.set_size(r.size(0)); - loop_ub = r.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - c_i[i] = r[i]; - } - - SLD_size = SLD.size(0); - loop_ub = SLD.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - SLD_data[i] = (x < SLD[i]); - } - - f_SLD_data.set(&SLD_data[0], SLD_size); - coder::eml_find(f_SLD_data, r); - deltaY = (x - SLD[b_i[b_i.size(0) - 1] - 1]) * (std::abs(SLD[(r[0] + - SLD.size(0)) - 1] - SLD[(belowVals_data[belowVals_size - 1] + SLD.size(0)) - - 1]) / (SLD[r[0] - 1] - SLD[belowVals_data[belowVals_size - 1] - 1])); - if (SLD[(b_i[b_i.size(0) - 1] + SLD.size(0)) - 1] < SLD[(c_i[0] + SLD.size - (0)) - 1]) { - *sldVal_size = 1; - sldVal_data[0] = SLD[(b_i[b_i.size(0) - 1] + SLD.size(0)) - 1] + deltaY; - } else { - *sldVal_size = 1; - sldVal_data[0] = SLD[(b_i[b_i.size(0) - 1] + SLD.size(0)) - 1] - deltaY; - } - - // sldVal = interp1(z,rho,x); - } - } - void b_SLDFunction(real_T x, const ::coder::array &SLD, ::coder:: array &sldVal) { diff --git a/RAT/SLDFunction.h b/RAT/SLDFunction.h index 84254dcf..d77c1b72 100644 --- a/RAT/SLDFunction.h +++ b/RAT/SLDFunction.h @@ -19,8 +19,6 @@ // Function Declarations namespace RAT { - void b_SLDFunction(real_T x, const ::coder::array &SLD, real_T - sldVal_data[], int32_T *sldVal_size); void b_SLDFunction(real_T x, const ::coder::array &SLD, ::coder:: array &sldVal); } diff --git a/RAT/adaptPCR.cpp b/RAT/adaptPCR.cpp index 4483c9c2..b96e4784 100644 --- a/RAT/adaptPCR.cpp +++ b/RAT/adaptPCR.cpp @@ -19,7 +19,7 @@ // Function Definitions namespace RAT { - void adaptPCR(const struct14_T *DREAMPar, const ::coder::array &CR, + void adaptPCR(const struct13_T *DREAMPar, const ::coder::array &CR, const real_T delta_tot_data[], const real_T lCRold_data[], real_T pCR_data[], int32_T pCR_size[2], real_T lCR_data[], int32_T lCR_size[2]) diff --git a/RAT/adaptPCR.h b/RAT/adaptPCR.h index 8f4b4a92..5cc6f842 100644 --- a/RAT/adaptPCR.h +++ b/RAT/adaptPCR.h @@ -19,13 +19,13 @@ // Type Declarations namespace RAT { - struct struct14_T; + struct struct13_T; } // Function Declarations namespace RAT { - void adaptPCR(const struct14_T *DREAMPar, const ::coder::array &CR, + void adaptPCR(const struct13_T *DREAMPar, const ::coder::array &CR, const real_T delta_tot_data[], const real_T lCRold_data[], real_T pCR_data[], int32_T pCR_size[2], real_T lCR_data[], int32_T lCR_size[2]); diff --git a/RAT/adaptive.cpp b/RAT/adaptive.cpp index 3f1057c0..235b6213 100644 --- a/RAT/adaptive.cpp +++ b/RAT/adaptive.cpp @@ -11,8 +11,6 @@ // Include files #include "adaptive.h" #include "RATMain_internal_types.h" -#include "RATMain_rtwutil.h" -#include "RATMain_types.h" #include "SLDFunction.h" #include "acos.h" #include "allOrAny.h" @@ -29,12 +27,7 @@ namespace RAT { static void b_binary_expand_op(::coder::array &in1, const - cell_27 *in2, const ::coder::array &in3, real_T in4); - static void b_increaseSampling(::coder::array &dataPoints, const :: - coder::array &segmentsToSplit, const ::coder::array &sldProfile); - static void b_normalizeFunction(const ::coder::array &x, const :: - coder::array &sldProfile, ::coder::array &y); + cell_25 *in2, const ::coder::array &in3, real_T in4); static void binary_expand_op(const ::coder::array &in1, const :: coder::array &in2, const ::coder::array &in3, :: coder::array &in4, ::coder::array &in5, ::coder:: @@ -47,8 +40,6 @@ namespace RAT array &in2, const ::coder::array &in3, const ::coder:: array &in4, const ::coder::array &in5, const ::coder:: array &in6); - static void c_normalizeFunction(const ::coder::array &x, const :: - coder::array &sldProfile, ::coder::array &y); static void calculateCentralAngles(const ::coder::array &XYdata, const real_T dataBoxSize[2], ::coder::array &cornerAngle); static void calculateTrianglesSides(const ::coder::array &XYdata, :: @@ -57,6 +48,8 @@ namespace RAT static void increaseSampling(::coder::array &dataPoints, const :: coder::array &segmentsToSplit, const ::coder::array &sldProfile); + static void normalizeFunction(const ::coder::array &x, const :: + coder::array &sldProfile, ::coder::array &y); static void times(::coder::array &in1, const ::coder::array &in2, const ::coder::array &in3); } @@ -65,7 +58,7 @@ namespace RAT namespace RAT { static void b_binary_expand_op(::coder::array &in1, const - cell_27 *in2, const ::coder::array &in3, real_T in4) + cell_25 *in2, const ::coder::array &in3, real_T in4) { int32_T i; int32_T in2_idx_0; @@ -88,191 +81,6 @@ namespace RAT } } - static void b_increaseSampling(::coder::array &dataPoints, const :: - coder::array &segmentsToSplit, const ::coder::array &sldProfile) - { - ::coder::array b_dataPoints; - ::coder::array newDataPoints; - ::coder::array b_newDataPoints; - ::coder::array r4; - ::coder::array r2; - ::coder::array r3; - ::coder::array r; - ::coder::array r1; - int32_T b_i; - int32_T input_sizes_idx_0; - int32_T trueCount; - - // increaseSampling increase the sampling of an input function - input_sizes_idx_0 = segmentsToSplit.size(0); - trueCount = 0; - for (int32_T i{0}; i < input_sizes_idx_0; i++) { - if (segmentsToSplit[i]) { - trueCount++; - } - } - - newDataPoints.set_size(trueCount, 2); - for (int32_T i{0}; i < 2; i++) { - for (b_i = 0; b_i < trueCount; b_i++) { - newDataPoints[b_i + newDataPoints.size(0) * i] = 0.0; - } - } - - r.set_size(segmentsToSplit.size(0) + 1); - trueCount = segmentsToSplit.size(0); - for (int32_T i{0}; i < trueCount; i++) { - r[i] = segmentsToSplit[i]; - } - - r[segmentsToSplit.size(0)] = false; - r1.set_size(segmentsToSplit.size(0) + 1); - r1[0] = false; - trueCount = segmentsToSplit.size(0); - for (int32_T i{0}; i < trueCount; i++) { - r1[i + 1] = segmentsToSplit[i]; - } - - input_sizes_idx_0 = r.size(0) - 1; - trueCount = 0; - for (int32_T i{0}; i <= input_sizes_idx_0; i++) { - if (r[i]) { - trueCount++; - } - } - - r2.set_size(trueCount); - trueCount = 0; - for (int32_T i{0}; i <= input_sizes_idx_0; i++) { - if (r[i]) { - r2[trueCount] = i + 1; - trueCount++; - } - } - - input_sizes_idx_0 = r1.size(0) - 1; - trueCount = 0; - for (int32_T i{0}; i <= input_sizes_idx_0; i++) { - if (r1[i]) { - trueCount++; - } - } - - r3.set_size(trueCount); - trueCount = 0; - for (int32_T i{0}; i <= input_sizes_idx_0; i++) { - if (r1[i]) { - r3[trueCount] = i + 1; - trueCount++; - } - } - - if (r2.size(0) == r3.size(0)) { - trueCount = r2.size(0); - for (int32_T i{0}; i < trueCount; i++) { - newDataPoints[i] = 0.5 * (dataPoints[r2[i] - 1] + dataPoints[r3[i] - 1]); - } - } else { - binary_expand_op(newDataPoints, dataPoints, r2, r3); - } - - b_newDataPoints.set_size(newDataPoints.size(0)); - trueCount = newDataPoints.size(0); - for (int32_T i{0}; i < trueCount; i++) { - b_newDataPoints[i] = newDataPoints[i]; - } - - c_normalizeFunction(b_newDataPoints, sldProfile, r4); - trueCount = r4.size(0); - for (int32_T i{0}; i < trueCount; i++) { - newDataPoints[i + newDataPoints.size(0)] = r4[i]; - } - - // For simplicity append the new points at the end and then sort. - if (dataPoints.size(0) != 0) { - trueCount = dataPoints.size(0); - } else { - trueCount = 0; - } - - if (newDataPoints.size(0) != 0) { - input_sizes_idx_0 = newDataPoints.size(0); - } else { - input_sizes_idx_0 = 0; - } - - if (newDataPoints.size(0) != 0) { - b_i = newDataPoints.size(0); - } else { - b_i = 0; - } - - b_dataPoints.set_size(trueCount + b_i, 2); - for (int32_T i{0}; i < 2; i++) { - for (b_i = 0; b_i < trueCount; b_i++) { - b_dataPoints[b_i + b_dataPoints.size(0) * i] = dataPoints[b_i + - trueCount * i]; - } - } - - for (int32_T i{0}; i < 2; i++) { - for (b_i = 0; b_i < input_sizes_idx_0; b_i++) { - b_dataPoints[(b_i + trueCount) + b_dataPoints.size(0) * i] = - newDataPoints[b_i + input_sizes_idx_0 * i]; - } - } - - dataPoints.set_size(b_dataPoints.size(0), 2); - trueCount = b_dataPoints.size(0); - for (int32_T i{0}; i < 2; i++) { - for (b_i = 0; b_i < trueCount; b_i++) { - dataPoints[b_i + dataPoints.size(0) * i] = b_dataPoints[b_i + - b_dataPoints.size(0) * i]; - } - } - - coder::sortrows(dataPoints); - } - - static void b_normalizeFunction(const ::coder::array &x, const :: - coder::array &sldProfile, ::coder::array &y) - { - ::coder::array r; - int32_T i; - - // Subfunctions - // NORMALIZEFUNCTION evaluates a function and returns a NxM array, where N - // is the number of elements of x and M is the number of outputs of func. - // All the outputs of func must be scalar. - // The optional parameter 'vectorizable' (default false) allows to specify - // that the input function can be vectorized. - // Modified by AVH for use with coder - // if (~exist('vectorizable','var') || isempty(vectorizable)) - // end - // abs(nargout(func)); %for anonymous functions nargout<0 - y.set_size(x.size(0)); - - // if vectorizable - // % For uniformity reasons, transform the 'x' array into a column vector. - // % In this way it does not matter if it is given as a column or a row - // % vector. - // [newValues{:}] = func(x(:)); - // y = cell2mat(newValues); - // else - i = x.size(0); - for (int32_T b_i{0}; b_i < i; b_i++) { - // Remove cell array so no need for cell2mat - // which won't compile - AVH - // [newValues{:}] = func(x(i)); - // y(i,:) = cell2mat(newValues); - b_SLDFunction(x[b_i], sldProfile, r); - y[b_i] = r[0]; - } - - // end - } - static void binary_expand_op(const ::coder::array &in1, const :: coder::array &in2, const ::coder::array &in3, :: coder::array &in4, ::coder::array &in5, ::coder:: @@ -432,46 +240,6 @@ namespace RAT } } - static void c_normalizeFunction(const ::coder::array &x, const :: - coder::array &sldProfile, ::coder::array &y) - { - RATMainTLS *RATMainTLSThread; - int32_T i; - int32_T tmp_size; - RATMainTLSThread = emlrtGetThreadStackData(); - - // Subfunctions - // NORMALIZEFUNCTION evaluates a function and returns a NxM array, where N - // is the number of elements of x and M is the number of outputs of func. - // All the outputs of func must be scalar. - // The optional parameter 'vectorizable' (default false) allows to specify - // that the input function can be vectorized. - // Modified by AVH for use with coder - // if (~exist('vectorizable','var') || isempty(vectorizable)) - // end - // abs(nargout(func)); %for anonymous functions nargout<0 - y.set_size(x.size(0)); - - // if vectorizable - // % For uniformity reasons, transform the 'x' array into a column vector. - // % In this way it does not matter if it is given as a column or a row - // % vector. - // [newValues{:}] = func(x(:)); - // y = cell2mat(newValues); - // else - i = x.size(0); - for (int32_T b_i{0}; b_i < i; b_i++) { - // Remove cell array so no need for cell2mat - // which won't compile - AVH - // [newValues{:}] = func(x(i)); - // y(i,:) = cell2mat(newValues); - b_SLDFunction(x[b_i], sldProfile, RATMainTLSThread->f1.tmp_data, &tmp_size); - y[b_i] = RATMainTLSThread->f1.tmp_data[0]; - } - - // end - } - static void calculateCentralAngles(const ::coder::array &XYdata, const real_T dataBoxSize[2], ::coder::array &cornerAngle) { @@ -824,7 +592,7 @@ namespace RAT b_newDataPoints[i] = newDataPoints[i]; } - b_normalizeFunction(b_newDataPoints, sldProfile, r4); + normalizeFunction(b_newDataPoints, sldProfile, r4); trueCount = r4.size(0); for (int32_T i{0}; i < trueCount; i++) { newDataPoints[i + newDataPoints.size(0)] = r4[i]; @@ -876,419 +644,73 @@ namespace RAT coder::sortrows(dataPoints); } - static void times(::coder::array &in1, const ::coder::array &in2, const ::coder::array &in3) + static void normalizeFunction(const ::coder::array &x, const :: + coder::array &sldProfile, ::coder::array &y) { + ::coder::array r; int32_T i; - int32_T loop_ub; - int32_T stride_0_0; - int32_T stride_1_0; - if (in3.size(0) == 1) { - i = in2.size(0); - } else { - i = in3.size(0); - } - in1.set_size(i); - stride_0_0 = (in2.size(0) != 1); - stride_1_0 = (in3.size(0) != 1); - if (in3.size(0) == 1) { - loop_ub = in2.size(0); - } else { - loop_ub = in3.size(0); - } + // Subfunctions + // NORMALIZEFUNCTION evaluates a function and returns a NxM array, where N + // is the number of elements of x and M is the number of outputs of func. + // All the outputs of func must be scalar. + // The optional parameter 'vectorizable' (default false) allows to specify + // that the input function can be vectorized. + // Modified by AVH for use with coder + // if (~exist('vectorizable','var') || isempty(vectorizable)) + // end + // abs(nargout(func)); %for anonymous functions nargout<0 + y.set_size(x.size(0)); - for (i = 0; i < loop_ub; i++) { - in1[i] = in2[i * stride_0_0] * in3[i * stride_1_0]; - } - } - - void adaptive(const ::coder::array &sldProfile, const real_T - startDomain[2], real_T minAngle, real_T nPoints, cell_27 *out) - { - ::coder::array b_out; - ::coder::array r; - ::coder::array cornerAngle; - ::coder::array hiVal; - ::coder::array newDomain; - ::coder::array b_trianglesToRefine; - ::coder::array r1; - ::coder::array segmentsToSplit; - ::coder::array trianglesToRefine; - int32_T loop_ub; - int32_T nRefinements; - boolean_T exitg1; - - // adaptive: evaluates a matlab function on a given range - // - // 'adaptive.m' allows to sample a function using a reduced number of - // points. It works iteratively adding new points where needed. - // It is especially useful for functions which are computationally intensive - // (e.g. involve solving a differential equation). - // - // Usage: - // XY = adaptive(func, [xstart, xend]) - // evaluates 'func' in the range [xstart, xend]. Key-value arguments are - // used to control the function evaluation. If the function 'func' returns - // multiple output values, only the first one is used for the refinement - // process, but all of them are calculated and returned as additional - // columns in the output matrix. The output matrix XY contains the new - // domain points in the first column and the output values in the other - // columns. - // [x,yy] = adaptive(func, [xstart, xend]) - // as before but separately returns the array with the domain points and - // the array/matrix with the function output values. - // [x,yy] = adaptive(func, xarray, ...) - // as before but explicitly provide an initial array of domain points. - // - // Methods: - // 'adaptive' provides three methods for refining the function evaluation: - // 1) add more points near the sharp corners, which are found by - // considering the triangles formed by three successive points and - // measuring the central angle. - // 2) measure the area of the same triangles and add more points when the - // area is bigger than a threshold. - // 3) measure the length of the segments formed by pairs of successive - // and split the segments which are longer than a threshold. - // If no methods is explicitly specified, the 'angle' method is used. - // - // Input parameters - // - func: input function (function handle) - // - initialDomain: initial domain points (1D array) - // - // Optional key-value input parameters - // - 'nPoints': (default 20) - // initial number of domain points, only used if an initial domain - // array is not excplitely provided. - // - 'maxRefinements': (default 10) - // Specifies the maximum number of refinement steps. - // - 'minAngle': (default 0.8*pi) - // Refine near the points which forms, together with their left and right - // neighbours, a triangle with central angle smaller than a given value. - // - 'maxArea': (default 5e-4) - // Refine near the points which forms, together with their left and right - // neighbours, a triangle with area larger than a threshold. The threshold - // in normalized to the area enclosing th graph: - // threshold==maxArea*(max(x)-min(x))*(max(f(x))-min(f(x))) - // - 'maxLength': (default Inf) - // Refine all the sements which are longer than a given threshold. The - // threshold is relative to the input and output ranges. Specifically, - // before applying the threshold, the data are normalized so that - // max(x)-min(x)==1 and max(f(x))-min(f(x))==1. - // - 'minLength': (default 0) - // Exclude from the refinement process the segments which are shorter - // than a given threshold. The threshold is relative to the input and - // output ranges. Specifically, before applying the threshold, the - // data are normalized so that max(x)-min(x)==1 and max(f(x))-min(f(x))==1. - // - 'minSignal': (default 0.2) - // Exclude from the refinement process the points where the function is - // below a threshold. The threshold is relative to the output range: In - // this example threshold == 0.01*(max(f(x))-min(f(x))). - // - 'vectorizable': (default false) - // Specifies whether the input function accepts arrays as input - // (e.g. f(x)==x.^2). - // - 'waitbar': (default false) - // Display a waitbar. - // - // Output parameters - // - a NxM array where N is the number of domain points and M is the number - // of output parameters of the input function. - // - // Examples: - // - // % Refine a function near sharp corners. The option 'minAngle' is useful - // % for having more points near the peaks of the function. - // f = @(x) exp(-x.^2/4).*sin(3*x); - // % for test-purpose also evaluate the function directly - // x2 = -10:0.01:10; - // y2 = f(x2); - // y = adaptive(f, [-5,5], 'minAngle',0.8*pi); - // figure(1); plot(x2,f(x2),'k--',y(:,1),y(:,2),'o-'); - // legend('high sampling','adaptive') - // title('y = adaptive(f, [xstart, xend], ''minAngle'',0.8*pi)') - // % as before but starting with an inital array of domain points - // x = -5:5; - // y = adaptive(f, x, 'minAngle',0.8*pi); - // figure(2); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); - // legend('initial sampling','high sampling','adaptive') - // title('y = adaptive(f, x, ''minAngle'',0.8*pi)') - // - // % Refine a function near sharp corners, but do not split segments which - // % are already shorter than 'minLength'. - // y = adaptive(f, x, 'minAngle',0.8*pi, 'minLength',0.05); - // figure(3); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); - // legend('initial sampling','high sampling','adaptive') - // title('y = adaptive(f, x, ''minAngle'',0.8*pi, ''minLength'',0.05)'); - // - // % Refine a function until the areas of the triangles formed by - // % triplets of successive points are smaller than 'maxArea'. - // y = adaptive(f, x, 'maxArea',1e-3); - // figure(4); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); - // legend('initial sampling','high sampling','adaptive') - // title('y = adaptive(f, x, ''maxArea'',1e-3)') - // - // % Refine a function until the segments formed by pairs of successive - // % points are shorter than 'maxLength'. - // y = adaptive(f, x, 'maxLength',0.1); - // figure(5); plot(x,f(x),'s-',x2,f(x2),'k--',y(:,1),y(:,2),'o-'); - // legend('initial sampling','high sampling','adaptive') - // title('y = adaptive(f, x, ''maxLength'',0.1)'); - // Copyright - // 2017, Alberto Comin - LMU Muenchen - // Version changes: - // - // 24/01/2017: 1) new default: when no optional argument is given, use the - // 'angle' method as default 2) it is now possible to provide just the - // start and the end of the function domain, instead of having to - // explicitly provide an initial array 3) a new key-word argument - // 'nPoints' controls the number of initial domain points in the cases when - // the initial array is not explicitly provided. 4) it is now possible to - // return the domain points and the function values either as a single 2D - // array or as two separate arrays. - // 25/01/2017: fixed defaults for the case when no method is specified - // Default settings - // nPoints = 20; - // minAngle = 0.8*pi; - // units normalized to data range - // Test-mode - // The test mode is activated by calling 'adaptive.m' with no input. - // if nargin==0 - // initialDomain = -10:10; - // input_func = @(x) 100*exp(-(x+5.2).^2) + 50*exp(-5*(x-0.5).^2)+ 20*exp(-10*(x-5.8).^2); - // thresholdingAngles = true; - // minAngle = 0.8*pi; - // thresholdingLength = true; - // minLength = 0.02; - // disp('Running adaptive.m in test mode'); - // fprintf('input function: %s\n',func2str(input_func)); - // disp('Plotting the function on a initial set of points'); - // testFigureHandle = figure(); - // plot(initialDomain, input_func(initialDomain),'bs-','LineWidth',1.5); - // grid on; xlabel('x'); ylabel('y'); title('adaptive.m example'); - // end - // Processing input arguments - // assert(isa(input_func,'function_handle'),'adaptiveFunctionEvaluation:ArgChk',... - // 'the first argument must be a function handle'); - // assert(isnumeric(initialDomain) && isvector(initialDomain),... - // 'adaptiveFunctionEvaluation:ArgChk','initial points must be specified as a numeric vector'); - // - // nExtraArgIn = numel(varargin); - // if mod(nExtraArgIn,2)==1 - // error('adaptiveFunctionEvaluation:ArgChk', ... - // 'At least a key or a value is missing in the key-value arguments list.'); - // end - // usingDefaultMethod = true; - // n = 1; - // minAngle = 0.7 * pi; - // thresholdingAngles = true; - // nPoints = 50; - // while n < nExtraArgIn - // switch lower(varargin{n}) - // case 'minangle' - // minAngle = varargin{n+1}; - // n = n+2; - // case 'maxarea' - // maxArea = varargin{n+1}; - // thresholdingArea = true; - // usingDefaultMethod = false; - // n = n+2; - // case 'maxlength' - // maxLength = varargin{n+1}; - // thresholdingLength = true; - // usingDefaultMethod = false; - // n = n+2; - // case 'minlength' - // minLength = varargin{n+1}; - // thresholdingLength = true; - // n = n+2; - // case 'minsignal' - // minSignal = varargin{n+1}; - // thresholdingSignal = true; - // n = n+2; - // case 'npoints' - // nPoints = varargin{n+1}; - // n = n+2; - // case 'vectorize' - // vectorizable = varargin{n+1}; - // n = n+2; - // case 'maxrefinements' - // maxRefinements = varargin{n+1}; - // n = n+2; - // case 'waitbar' - // displayWaitbar = varargin{n+1}; - // n = n+2; - // otherwise - // error('adaptiveFunctionEvaluation:ArgChk',... - // ['unknown keyword argument: ', varargin{n}]); - // end - // end - // if no method is specified use the 'angle' method as default - // if usingDefaultMethod - // thresholdingAngles = true; - // end - // Initial function evaluation - // if initialDomain only contains the start and the end points, create a new - // array with 'nPoints' points. - coder::linspace(startDomain[0], startDomain[1], nPoints, r); - newDomain.set_size(r.size(1)); - loop_ub = r.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - newDomain[i] = r[i]; + // if vectorizable + // % For uniformity reasons, transform the 'x' array into a column vector. + // % In this way it does not matter if it is given as a column or a row + // % vector. + // [newValues{:}] = func(x(:)); + // y = cell2mat(newValues); + // else + i = x.size(0); + for (int32_T b_i{0}; b_i < i; b_i++) { + // Remove cell array so no need for cell2mat + // which won't compile - AVH + // [newValues{:}] = func(x(i)); + // y(i,:) = cell2mat(newValues); + b_SLDFunction(x[b_i], sldProfile, r); + y[b_i] = r[0]; } - // Normalize the input function: This step allows to use the same syntax for - // functions with single or multiple output parameters. - // Remove this syntax for compile - AVH - // func = @(x) normalizeFunction(x,sldProfile,vectorizable); - // Evaluate the input function on the initial set of points. - b_normalizeFunction(newDomain, sldProfile, hiVal); + // end + } - // dataPoints = [initialDomain(:), func(initialDomain(:))]; - out->f1.set_size(newDomain.size(0), 2); - loop_ub = newDomain.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - out->f1[i] = newDomain[i]; + static void times(::coder::array &in1, const ::coder::array &in2, const ::coder::array &in3) + { + int32_T i; + int32_T loop_ub; + int32_T stride_0_0; + int32_T stride_1_0; + if (in3.size(0) == 1) { + i = in2.size(0); + } else { + i = in3.size(0); } - loop_ub = hiVal.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - out->f1[i + out->f1.size(0)] = hiVal[i]; + in1.set_size(i); + stride_0_0 = (in2.size(0) != 1); + stride_1_0 = (in3.size(0) != 1); + if (in3.size(0) == 1) { + loop_ub = in2.size(0); + } else { + loop_ub = in3.size(0); } - // Iterative function refinement - // if displayWaitbar - // refinementWaitbar = waitbar(0,['Evaluating function ',func2str(func)],... - // 'CreateCancelBtn','setappdata(gcbf,''canceling'',true)'); - // setappdata(refinementWaitbar,'canceling',false) - // end - nRefinements = 0; - exitg1 = false; - while ((!exitg1) && (nRefinements < 10)) { - real_T b_dv[2]; - real_T b_dv1[2]; - boolean_T y; - - // calculate the box which encloses the current data points: - // Each point is considered as the central corner of the triangle formed - // with its left and right hand side neighbours. The first and the last - // points are not the central corner of any triangle, so for N points - // there are only N-2 triangles. - // if thresholdingArea - // triangleArea = calculateTrianglesArea(dataPoints(:,1:2)); - // bigTriangles = triangleArea > (maxArea * dataBoxArea); - // trianglesToRefine = trianglesToRefine | bigTriangles; - // end - b_out.set_size(out->f1.size(0), 2); - loop_ub = out->f1.size(0); - for (int32_T i{0}; i < 2; i++) { - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_out[i1 + b_out.size(0) * i] = out->f1[i1 + out->f1.size(0) * i]; - } - } - - coder::internal::maximum(b_out, b_dv); - b_out.set_size(out->f1.size(0), 2); - loop_ub = out->f1.size(0); - for (int32_T i{0}; i < 2; i++) { - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_out[i1 + b_out.size(0) * i] = out->f1[i1 + out->f1.size(0) * i]; - } - } - - coder::internal::minimum(b_out, b_dv1); - b_out.set_size(out->f1.size(0), 2); - loop_ub = out->f1.size(0); - for (int32_T i{0}; i < 2; i++) { - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_out[i1 + b_out.size(0) * i] = out->f1[i1 + out->f1.size(0) * i]; - } - - b_dv[i] -= b_dv1[i]; - } - - calculateCentralAngles(b_out, b_dv, cornerAngle); - if (out->f1.size(0) - 2 == cornerAngle.size(0)) { - trianglesToRefine.set_size(out->f1.size(0) - 2); - loop_ub = out->f1.size(0) - 2; - for (int32_T i{0}; i < loop_ub; i++) { - trianglesToRefine[i] = (cornerAngle[i] < minAngle); - } - } else { - b_binary_expand_op(trianglesToRefine, out, cornerAngle, minAngle); - } - - // For N points there are N-2 triangles and N-1 triangle sides. Each - // triangle side is a segment, which can be split or not depending on the - // refinement parameters. - b_trianglesToRefine.set_size(trianglesToRefine.size(0) + 1); - loop_ub = trianglesToRefine.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - b_trianglesToRefine[i] = trianglesToRefine[i]; - } - - b_trianglesToRefine[trianglesToRefine.size(0)] = false; - r1.set_size(trianglesToRefine.size(0) + 1); - r1[0] = false; - loop_ub = trianglesToRefine.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - r1[i + 1] = trianglesToRefine[i]; - } - - segmentsToSplit.set_size(b_trianglesToRefine.size(0)); - loop_ub = b_trianglesToRefine.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - segmentsToSplit[i] = (b_trianglesToRefine[i] || r1[i]); - } - - // if thresholdingLength - // dataSegments = diff(dataPoints(:,1:2)); - // normalizedSegments = bsxfun(@rdivide, dataSegments, dataBoxSize); - // segmentsLengthNormalized = hypot(normalizedSegments(:,1), normalizedSegments(:,2)); - // tooLongSegments = segmentsLengthNormalized > maxLength; - // longEnoughSegments = segmentsLengthNormalized > minLength; - // segmentsToSplit = (segmentsToSplit | tooLongSegments) & longEnoughSegments; - // end - // if thresholdingSignal - // segmentsCenters = (dataPoints(1:end-1,2)+dataPoints(2:end,2))/2; - // centerAboveThreshold = segmentsCenters > minSignal * max(abs(dataPoints(:,2))); - // segmentsToSplit = segmentsToSplit & centerAboveThreshold; - // end - y = coder::internal::allOrAny_anonFcn3(segmentsToSplit.size(0), - segmentsToSplit); - if (y) { - increaseSampling(out->f1, segmentsToSplit, sldProfile); - - // Removed waitbar for compile - AVH - // if displayWaitbar - // if getappdata(refinementWaitbar,'canceling'), break; end - // waitbar(nRefinements/maxRefinements,refinementWaitbar); - // end - nRefinements++; - } else { - exitg1 = true; - } + for (i = 0; i < loop_ub; i++) { + in1[i] = in2[i * stride_0_0] * in3[i * stride_1_0]; } - - // if displayWaitbar - // delete(refinementWaitbar); - // end - // Plotting refined function - // Removed for compile - AVH - // if nargin==0 % test mode - // figure(testFigureHandle); - // hold on; - // plot(dataPoints(:,1), dataPoints(:,2),'ro-'); - // legend('initial', 'refiniment'); - // end - // if nargout==1 - // elseif nargout>1 - // out{1} = dataPoints(:,1); - // out{2} = dataPoints(:,2:end); - // end } - void b_adaptive(const ::coder::array &sldProfile, const real_T - startDomain[2], real_T minAngle, real_T nPoints, cell_27 *out) + void adaptive(const ::coder::array &sldProfile, const real_T + startDomain[2], real_T minAngle, real_T nPoints, cell_25 *out) { ::coder::array b_out; ::coder::array r; @@ -1525,7 +947,7 @@ namespace RAT // Remove this syntax for compile - AVH // func = @(x) normalizeFunction(x,sldProfile,vectorizable); // Evaluate the input function on the initial set of points. - c_normalizeFunction(newDomain, sldProfile, hiVal); + normalizeFunction(newDomain, sldProfile, hiVal); // dataPoints = [initialDomain(:), func(initialDomain(:))]; out->f1.set_size(newDomain.size(0), 2); @@ -1640,7 +1062,7 @@ namespace RAT y = coder::internal::allOrAny_anonFcn3(segmentsToSplit.size(0), segmentsToSplit); if (y) { - b_increaseSampling(out->f1, segmentsToSplit, sldProfile); + increaseSampling(out->f1, segmentsToSplit, sldProfile); // Removed waitbar for compile - AVH // if displayWaitbar diff --git a/RAT/adaptive.h b/RAT/adaptive.h index 14f558aa..3aaef93b 100644 --- a/RAT/adaptive.h +++ b/RAT/adaptive.h @@ -19,16 +19,14 @@ // Type Declarations namespace RAT { - struct cell_27; + struct cell_25; } // Function Declarations namespace RAT { void adaptive(const ::coder::array &sldProfile, const real_T - startDomain[2], real_T minAngle, real_T nPoints, cell_27 *out); - void b_adaptive(const ::coder::array &sldProfile, const real_T - startDomain[2], real_T minAngle, real_T nPoints, cell_27 *out); + startDomain[2], real_T minAngle, real_T nPoints, cell_25 *out); } #endif diff --git a/RAT/allocateLayersForContrast.cpp b/RAT/allocateLayersForContrast.cpp index 5461ca3b..7080b9d8 100644 --- a/RAT/allocateLayersForContrast.cpp +++ b/RAT/allocateLayersForContrast.cpp @@ -20,7 +20,7 @@ namespace RAT { void allocateLayersForContrast(const ::coder::array - &contrastLayers, const ::coder::array + &contrastLayers, const ::coder::array &outParameterisedLayers, boolean_T useImaginary, real_T thisContrastLayers_data[], int32_T thisContrastLayers_size[2]) { diff --git a/RAT/allocateLayersForContrast.h b/RAT/allocateLayersForContrast.h index 0a6eaf83..cb7cbd3d 100644 --- a/RAT/allocateLayersForContrast.h +++ b/RAT/allocateLayersForContrast.h @@ -21,7 +21,7 @@ namespace RAT { void allocateLayersForContrast(const ::coder::array - &contrastLayers, const ::coder::array + &contrastLayers, const ::coder::array &outParameterisedLayers, boolean_T useImaginary, real_T thisContrastLayers_data[], int32_T thisContrastLayers_size[2]); } diff --git a/RAT/allocateParamsToLayers.cpp b/RAT/allocateParamsToLayers.cpp index 9c23e686..400eeb5a 100644 --- a/RAT/allocateParamsToLayers.cpp +++ b/RAT/allocateParamsToLayers.cpp @@ -21,7 +21,7 @@ namespace RAT { void allocateParamsToLayers(const ::coder::array ¶ms, const :: - coder::array &layersDetails, ::coder::array &layersDetails, ::coder::array &outLayers) { real_T thisOutLayer_data[10]; diff --git a/RAT/allocateParamsToLayers.h b/RAT/allocateParamsToLayers.h index e9678a54..a618db78 100644 --- a/RAT/allocateParamsToLayers.h +++ b/RAT/allocateParamsToLayers.h @@ -21,7 +21,7 @@ namespace RAT { void allocateParamsToLayers(const ::coder::array ¶ms, const :: - coder::array &layersDetails, ::coder::array &layersDetails, ::coder::array &outLayers); } diff --git a/RAT/calcDensity.cpp b/RAT/calcDensity.cpp index 432c1f3a..86985526 100644 --- a/RAT/calcDensity.cpp +++ b/RAT/calcDensity.cpp @@ -19,8 +19,8 @@ namespace RAT { void calcDensity(const ::coder::array &x, const ::coder::array< - real_T, 2U> &fx, const struct14_T *DREAMPar, const ::coder:: - array &ratInputs_problemDef_fitLimits, const :: + real_T, 2U> &fx, const struct13_T *DREAMPar, const ::coder:: + array &ratInputs_problemStruct_fitLimits, const :: coder::array &ratInputs_priors, ::coder::array< real_T, 1U> &log_L, ::coder::array &log_PR) { @@ -93,7 +93,7 @@ namespace RAT b_x[i] = x[b_i + x.size(0) * i]; } - PR[b_i] = scaledGaussPrior(b_x, ratInputs_problemDef_fitLimits, + PR[b_i] = scaledGaussPrior(b_x, ratInputs_problemStruct_fitLimits, ratInputs_priors); // mvnpdf automatically goes over all pars diff --git a/RAT/calcDensity.h b/RAT/calcDensity.h index 18d66d09..ccfe4a62 100644 --- a/RAT/calcDensity.h +++ b/RAT/calcDensity.h @@ -19,15 +19,15 @@ // Type Declarations namespace RAT { - struct struct14_T; + struct struct13_T; } // Function Declarations namespace RAT { void calcDensity(const ::coder::array &x, const ::coder::array< - real_T, 2U> &fx, const struct14_T *DREAMPar, const ::coder:: - array &ratInputs_problemDef_fitLimits, const :: + real_T, 2U> &fx, const struct13_T *DREAMPar, const ::coder:: + array &ratInputs_problemStruct_fitLimits, const :: coder::array &ratInputs_priors, ::coder::array< real_T, 1U> &log_L, ::coder::array &log_PR); } diff --git a/RAT/calcProposal.cpp b/RAT/calcProposal.cpp index 8c26288e..025b107c 100644 --- a/RAT/calcProposal.cpp +++ b/RAT/calcProposal.cpp @@ -154,7 +154,7 @@ namespace RAT } void calcProposal(const ::coder::array &X, real_T CR_data[], const - struct14_T *DREAMPar, const ::coder::array + struct13_T *DREAMPar, const ::coder::array &Table_gamma, const ::coder::array &Par_info_min, const ::coder::array &Par_info_max, const char_T Par_info_boundhandling_data[], const int32_T diff --git a/RAT/calcProposal.h b/RAT/calcProposal.h index 27d17918..4b4d3bff 100644 --- a/RAT/calcProposal.h +++ b/RAT/calcProposal.h @@ -19,14 +19,14 @@ // Type Declarations namespace RAT { - struct struct14_T; + struct struct13_T; } // Function Declarations namespace RAT { void calcProposal(const ::coder::array &X, real_T CR_data[], const - struct14_T *DREAMPar, const ::coder::array + struct13_T *DREAMPar, const ::coder::array &Table_gamma, const ::coder::array &Par_info_min, const ::coder::array &Par_info_max, const char_T Par_info_boundhandling_data[], const int32_T diff --git a/RAT/calculate.cpp b/RAT/calculate.cpp index a8258400..2b1adb37 100644 --- a/RAT/calculate.cpp +++ b/RAT/calculate.cpp @@ -28,13 +28,14 @@ namespace RAT { namespace standardLayers { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array &sldProfiles, :: - coder::array &allLayers) + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers) { int32_T loop_ub_tmp; @@ -50,16 +51,16 @@ namespace RAT // Pre-allocation - It's necessary to // pre-define the types for all the arrays // for compilation, so do this in this block. - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgroundParams.set_size(loop_ub_tmp); - problem->qzshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->bulkIn.set_size(loop_ub_tmp); - problem->bulkOut.set_size(loop_ub_tmp); - problem->calculations.allChis.set_size(loop_ub_tmp); - problem->resolutionParams.set_size(loop_ub_tmp); - problem->allSubRough.set_size(loop_ub_tmp); + loop_ub_tmp = static_cast(problemStruct->numberOfContrasts); + contrastParams->ssubs.set_size(loop_ub_tmp); + contrastParams->backgroundParams.set_size(loop_ub_tmp); + contrastParams->qzshifts.set_size(loop_ub_tmp); + contrastParams->scalefactors.set_size(loop_ub_tmp); + contrastParams->bulkIn.set_size(loop_ub_tmp); + contrastParams->bulkOut.set_size(loop_ub_tmp); + contrastParams->calculations.allChis.set_size(loop_ub_tmp); + contrastParams->resolutionParams.set_size(loop_ub_tmp); + contrastParams->allSubRough.set_size(loop_ub_tmp); reflectivity.set_size(loop_ub_tmp); simulation.set_size(loop_ub_tmp); shiftedData.set_size(loop_ub_tmp); @@ -67,15 +68,15 @@ namespace RAT sldProfiles.set_size(loop_ub_tmp); allLayers.set_size(loop_ub_tmp); for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgroundParams[i] = 0.0; - problem->qzshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->bulkIn[i] = 0.0; - problem->bulkOut[i] = 0.0; - problem->calculations.allChis[i] = 0.0; - problem->resolutionParams[i] = 0.0; - problem->allSubRough[i] = 0.0; + contrastParams->ssubs[i] = 0.0; + contrastParams->backgroundParams[i] = 0.0; + contrastParams->qzshifts[i] = 0.0; + contrastParams->scalefactors[i] = 0.0; + contrastParams->bulkIn[i] = 0.0; + contrastParams->bulkOut[i] = 0.0; + contrastParams->calculations.allChis[i] = 0.0; + contrastParams->resolutionParams[i] = 0.0; + contrastParams->allSubRough[i] = 0.0; reflectivity[i].f1.set_size(2, 2); reflectivity[i].f1[0] = 1.0; reflectivity[i].f1[1] = 1.0; @@ -120,42 +121,47 @@ namespace RAT switch (loop_ub_tmp) { case 0: - b_single(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, problem->bulkOut, - problem->resolutionParams, problem->calculations.allChis, - reflectivity, simulation, shiftedData, layerSlds, sldProfiles, - allLayers, problem->allSubRough); + b_single(problemStruct, problemCells, controls, contrastParams->ssubs, + contrastParams->backgroundParams, contrastParams->qzshifts, + contrastParams->scalefactors, contrastParams->bulkIn, + contrastParams->bulkOut, contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, sldProfiles, allLayers, + contrastParams->allSubRough); break; case 1: - parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, - problem->bulkOut, problem->resolutionParams, - problem->calculations.allChis, reflectivity, simulation, - shiftedData, layerSlds, sldProfiles, allLayers, - problem->allSubRough); + parallelPoints(problemStruct, problemCells, controls, + contrastParams->ssubs, contrastParams->backgroundParams, + contrastParams->qzshifts, contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, sldProfiles, + allLayers, contrastParams->allSubRough); break; case 2: - c_parallelContrasts(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgroundParams, - problem->qzshifts, problem->scalefactors, - problem->bulkIn, problem->bulkOut, - problem->resolutionParams, - problem->calculations.allChis, reflectivity, + c_parallelContrasts(problemStruct, problemCells, controls, + contrastParams->ssubs, + contrastParams->backgroundParams, + contrastParams->qzshifts, + contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, simulation, shiftedData, layerSlds, sldProfiles, - allLayers, problem->allSubRough); + allLayers, contrastParams->allSubRough); break; } // Package everything into one array for tidy output - problem->calculations.sumChi = coder::sum(problem->calculations.allChis); - problem->resample.set_size(1, problemDef->resample.size(1)); - loop_ub_tmp = problemDef->resample.size(1); + contrastParams->calculations.sumChi = coder::sum + (contrastParams->calculations.allChis); + contrastParams->resample.set_size(1, problemStruct->resample.size(1)); + loop_ub_tmp = problemStruct->resample.size(1); for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - problem->resample[b_i] = problemDef->resample[b_i]; + contrastParams->resample[b_i] = problemStruct->resample[b_i]; } } } diff --git a/RAT/calculate.h b/RAT/calculate.h index bff39bf2..32ce782d 100644 --- a/RAT/calculate.h +++ b/RAT/calculate.h @@ -11,19 +11,13 @@ #define CALCULATE_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; - struct struct_T; -} - // Function Declarations namespace RAT { @@ -31,13 +25,14 @@ namespace RAT { namespace standardLayers { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array &sldProfiles, :: - coder::array &allLayers); + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers); } } } diff --git a/RAT/calculate1.cpp b/RAT/calculate1.cpp index 1d19ba9e..2a020fb0 100644 --- a/RAT/calculate1.cpp +++ b/RAT/calculate1.cpp @@ -28,13 +28,14 @@ namespace RAT { namespace customLayers { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array &sldProfiles, :: - coder::array &allLayers) + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers) { int32_T loop_ub_tmp; @@ -49,16 +50,16 @@ namespace RAT // Pre-allocation - It's necessary to // pre-allocate the memory for all the arrays // for compilation, so do this in this block. - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgroundParams.set_size(loop_ub_tmp); - problem->qzshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->bulkIn.set_size(loop_ub_tmp); - problem->bulkOut.set_size(loop_ub_tmp); - problem->calculations.allChis.set_size(loop_ub_tmp); - problem->resolutionParams.set_size(loop_ub_tmp); - problem->allSubRough.set_size(loop_ub_tmp); + loop_ub_tmp = static_cast(problemStruct->numberOfContrasts); + contrastParams->ssubs.set_size(loop_ub_tmp); + contrastParams->backgroundParams.set_size(loop_ub_tmp); + contrastParams->qzshifts.set_size(loop_ub_tmp); + contrastParams->scalefactors.set_size(loop_ub_tmp); + contrastParams->bulkIn.set_size(loop_ub_tmp); + contrastParams->bulkOut.set_size(loop_ub_tmp); + contrastParams->calculations.allChis.set_size(loop_ub_tmp); + contrastParams->resolutionParams.set_size(loop_ub_tmp); + contrastParams->allSubRough.set_size(loop_ub_tmp); reflectivity.set_size(loop_ub_tmp); simulation.set_size(loop_ub_tmp); shiftedData.set_size(loop_ub_tmp); @@ -66,15 +67,15 @@ namespace RAT sldProfiles.set_size(loop_ub_tmp); allLayers.set_size(loop_ub_tmp); for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgroundParams[i] = 0.0; - problem->qzshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->bulkIn[i] = 0.0; - problem->bulkOut[i] = 0.0; - problem->calculations.allChis[i] = 0.0; - problem->resolutionParams[i] = 0.0; - problem->allSubRough[i] = 0.0; + contrastParams->ssubs[i] = 0.0; + contrastParams->backgroundParams[i] = 0.0; + contrastParams->qzshifts[i] = 0.0; + contrastParams->scalefactors[i] = 0.0; + contrastParams->bulkIn[i] = 0.0; + contrastParams->bulkOut[i] = 0.0; + contrastParams->calculations.allChis[i] = 0.0; + contrastParams->resolutionParams[i] = 0.0; + contrastParams->allSubRough[i] = 0.0; reflectivity[i].f1.set_size(2, 2); reflectivity[i].f1[0] = 1.0; reflectivity[i].f1[1] = 1.0; @@ -119,41 +120,46 @@ namespace RAT switch (loop_ub_tmp) { case 0: - b_single(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, problem->bulkOut, - problem->resolutionParams, problem->calculations.allChis, - reflectivity, simulation, shiftedData, layerSlds, sldProfiles, - allLayers, problem->allSubRough); + b_single(problemStruct, problemCells, controls, contrastParams->ssubs, + contrastParams->backgroundParams, contrastParams->qzshifts, + contrastParams->scalefactors, contrastParams->bulkIn, + contrastParams->bulkOut, contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, sldProfiles, allLayers, + contrastParams->allSubRough); break; case 1: - parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, - problem->bulkOut, problem->resolutionParams, - problem->calculations.allChis, reflectivity, simulation, - shiftedData, layerSlds, sldProfiles, allLayers, - problem->allSubRough); + parallelPoints(problemStruct, problemCells, controls, + contrastParams->ssubs, contrastParams->backgroundParams, + contrastParams->qzshifts, contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, sldProfiles, + allLayers, contrastParams->allSubRough); break; case 2: - c_parallelContrasts(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgroundParams, - problem->qzshifts, problem->scalefactors, - problem->bulkIn, problem->bulkOut, - problem->resolutionParams, - problem->calculations.allChis, reflectivity, + c_parallelContrasts(problemStruct, problemCells, controls, + contrastParams->ssubs, + contrastParams->backgroundParams, + contrastParams->qzshifts, + contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, simulation, shiftedData, layerSlds, sldProfiles, - allLayers, problem->allSubRough); + allLayers, contrastParams->allSubRough); break; } - problem->calculations.sumChi = coder::sum(problem->calculations.allChis); - problem->resample.set_size(1, problemDef->resample.size(1)); - loop_ub_tmp = problemDef->resample.size(1); + contrastParams->calculations.sumChi = coder::sum + (contrastParams->calculations.allChis); + contrastParams->resample.set_size(1, problemStruct->resample.size(1)); + loop_ub_tmp = problemStruct->resample.size(1); for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - problem->resample[b_i] = problemDef->resample[b_i]; + contrastParams->resample[b_i] = problemStruct->resample[b_i]; } } } diff --git a/RAT/calculate1.h b/RAT/calculate1.h index 074e2d23..ffd0507c 100644 --- a/RAT/calculate1.h +++ b/RAT/calculate1.h @@ -11,19 +11,13 @@ #define CALCULATE1_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; - struct struct_T; -} - // Function Declarations namespace RAT { @@ -31,13 +25,14 @@ namespace RAT { namespace customLayers { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array &sldProfiles, :: - coder::array &allLayers); + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers); } } } diff --git a/RAT/calculate2.cpp b/RAT/calculate2.cpp index 7b525cab..d22d049c 100644 --- a/RAT/calculate2.cpp +++ b/RAT/calculate2.cpp @@ -28,13 +28,14 @@ namespace RAT { namespace customXY { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array &sldProfiles, :: - coder::array &allLayers) + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers) { int32_T loop_ub_tmp; @@ -49,16 +50,16 @@ namespace RAT // Pre-allocation - It's necessary to // pre-allocate the memory for all the arrays // for compilation, so do this in this block. - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgroundParams.set_size(loop_ub_tmp); - problem->qzshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->bulkIn.set_size(loop_ub_tmp); - problem->bulkOut.set_size(loop_ub_tmp); - problem->calculations.allChis.set_size(loop_ub_tmp); - problem->resolutionParams.set_size(loop_ub_tmp); - problem->allSubRough.set_size(loop_ub_tmp); + loop_ub_tmp = static_cast(problemStruct->numberOfContrasts); + contrastParams->ssubs.set_size(loop_ub_tmp); + contrastParams->backgroundParams.set_size(loop_ub_tmp); + contrastParams->qzshifts.set_size(loop_ub_tmp); + contrastParams->scalefactors.set_size(loop_ub_tmp); + contrastParams->bulkIn.set_size(loop_ub_tmp); + contrastParams->bulkOut.set_size(loop_ub_tmp); + contrastParams->calculations.allChis.set_size(loop_ub_tmp); + contrastParams->resolutionParams.set_size(loop_ub_tmp); + contrastParams->allSubRough.set_size(loop_ub_tmp); reflectivity.set_size(loop_ub_tmp); simulation.set_size(loop_ub_tmp); shiftedData.set_size(loop_ub_tmp); @@ -66,15 +67,15 @@ namespace RAT sldProfiles.set_size(loop_ub_tmp); allLayers.set_size(loop_ub_tmp); for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgroundParams[i] = 0.0; - problem->qzshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->bulkIn[i] = 0.0; - problem->bulkOut[i] = 0.0; - problem->calculations.allChis[i] = 0.0; - problem->resolutionParams[i] = 0.0; - problem->allSubRough[i] = 0.0; + contrastParams->ssubs[i] = 0.0; + contrastParams->backgroundParams[i] = 0.0; + contrastParams->qzshifts[i] = 0.0; + contrastParams->scalefactors[i] = 0.0; + contrastParams->bulkIn[i] = 0.0; + contrastParams->bulkOut[i] = 0.0; + contrastParams->calculations.allChis[i] = 0.0; + contrastParams->resolutionParams[i] = 0.0; + contrastParams->allSubRough[i] = 0.0; reflectivity[i].f1.set_size(2, 2); reflectivity[i].f1[0] = 1.0; reflectivity[i].f1[1] = 1.0; @@ -119,41 +120,46 @@ namespace RAT switch (loop_ub_tmp) { case 0: - b_single(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, problem->bulkOut, - problem->resolutionParams, problem->calculations.allChis, - reflectivity, simulation, shiftedData, layerSlds, sldProfiles, - allLayers, problem->allSubRough); + b_single(problemStruct, problemCells, controls, contrastParams->ssubs, + contrastParams->backgroundParams, contrastParams->qzshifts, + contrastParams->scalefactors, contrastParams->bulkIn, + contrastParams->bulkOut, contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, sldProfiles, allLayers, + contrastParams->allSubRough); break; case 1: - parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, - problem->bulkOut, problem->resolutionParams, - problem->calculations.allChis, reflectivity, simulation, - shiftedData, layerSlds, sldProfiles, allLayers, - problem->allSubRough); + parallelPoints(problemStruct, problemCells, controls, + contrastParams->ssubs, contrastParams->backgroundParams, + contrastParams->qzshifts, contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, sldProfiles, + allLayers, contrastParams->allSubRough); break; case 2: - c_parallelContrasts(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgroundParams, - problem->qzshifts, problem->scalefactors, - problem->bulkIn, problem->bulkOut, - problem->resolutionParams, - problem->calculations.allChis, reflectivity, + c_parallelContrasts(problemStruct, problemCells, controls, + contrastParams->ssubs, + contrastParams->backgroundParams, + contrastParams->qzshifts, + contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, simulation, shiftedData, layerSlds, sldProfiles, - allLayers, problem->allSubRough); + allLayers, contrastParams->allSubRough); break; } - problem->calculations.sumChi = coder::sum(problem->calculations.allChis); - problem->resample.set_size(1, problem->allSubRough.size(0)); - loop_ub_tmp = problem->allSubRough.size(0); + contrastParams->calculations.sumChi = coder::sum + (contrastParams->calculations.allChis); + contrastParams->resample.set_size(1, contrastParams->allSubRough.size(0)); + loop_ub_tmp = contrastParams->allSubRough.size(0); for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - problem->resample[b_i] = 1.0; + contrastParams->resample[b_i] = 1.0; } } } diff --git a/RAT/calculate2.h b/RAT/calculate2.h index c1e710cb..023721e9 100644 --- a/RAT/calculate2.h +++ b/RAT/calculate2.h @@ -11,19 +11,13 @@ #define CALCULATE2_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; - struct struct_T; -} - // Function Declarations namespace RAT { @@ -31,13 +25,14 @@ namespace RAT { namespace customXY { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array &sldProfiles, :: - coder::array &allLayers); + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers); } } } diff --git a/RAT/calculate3.cpp b/RAT/calculate3.cpp index 2ab91ed7..5d4ec9d1 100644 --- a/RAT/calculate3.cpp +++ b/RAT/calculate3.cpp @@ -28,13 +28,14 @@ namespace RAT { namespace standardLayers { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array &sldProfiles, :: - coder::array &allLayers) + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &sldProfiles, ::coder::array &allLayers) { ::coder::array b_allLayers; ::coder::array b_layerSlds; @@ -53,16 +54,16 @@ namespace RAT // Pre-allocation - It's necessary to // pre-define the types for all the arrays // for compilation, so do this in this block. - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgroundParams.set_size(loop_ub_tmp); - problem->qzshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->bulkIn.set_size(loop_ub_tmp); - problem->bulkOut.set_size(loop_ub_tmp); - problem->calculations.allChis.set_size(loop_ub_tmp); - problem->resolutionParams.set_size(loop_ub_tmp); - problem->allSubRough.set_size(loop_ub_tmp); + loop_ub_tmp = static_cast(problemStruct->numberOfContrasts); + contrastParams->ssubs.set_size(loop_ub_tmp); + contrastParams->backgroundParams.set_size(loop_ub_tmp); + contrastParams->qzshifts.set_size(loop_ub_tmp); + contrastParams->scalefactors.set_size(loop_ub_tmp); + contrastParams->bulkIn.set_size(loop_ub_tmp); + contrastParams->bulkOut.set_size(loop_ub_tmp); + contrastParams->calculations.allChis.set_size(loop_ub_tmp); + contrastParams->resolutionParams.set_size(loop_ub_tmp); + contrastParams->allSubRough.set_size(loop_ub_tmp); reflectivity.set_size(loop_ub_tmp); simulation.set_size(loop_ub_tmp); shiftedData.set_size(loop_ub_tmp); @@ -70,15 +71,15 @@ namespace RAT sldProfiles.set_size(loop_ub_tmp, 1); allLayers.set_size(loop_ub_tmp, 1); for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgroundParams[i] = 0.0; - problem->qzshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->bulkIn[i] = 0.0; - problem->bulkOut[i] = 0.0; - problem->calculations.allChis[i] = 0.0; - problem->resolutionParams[i] = 0.0; - problem->allSubRough[i] = 0.0; + contrastParams->ssubs[i] = 0.0; + contrastParams->backgroundParams[i] = 0.0; + contrastParams->qzshifts[i] = 0.0; + contrastParams->scalefactors[i] = 0.0; + contrastParams->bulkIn[i] = 0.0; + contrastParams->bulkOut[i] = 0.0; + contrastParams->calculations.allChis[i] = 0.0; + contrastParams->resolutionParams[i] = 0.0; + contrastParams->allSubRough[i] = 0.0; reflectivity[i].f1.set_size(2, 2); reflectivity[i].f1[0] = 1.0; reflectivity[i].f1[1] = 1.0; @@ -126,12 +127,14 @@ namespace RAT { int32_T b_loop_ub; int32_T loop_ub; - b_single(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, problem->bulkOut, - problem->resolutionParams, problem->calculations.allChis, - reflectivity, simulation, shiftedData, b_layerSlds, - b_sldProfiles, b_allLayers, problem->allSubRough); + b_single(problemStruct, problemCells, controls, + contrastParams->ssubs, contrastParams->backgroundParams, + contrastParams->qzshifts, contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, + simulation, shiftedData, b_layerSlds, b_sldProfiles, + b_allLayers, contrastParams->allSubRough); layerSlds.set_size(b_layerSlds.size(0), 2); sldProfiles.set_size(b_sldProfiles.size(0), 2); allLayers.set_size(b_allLayers.size(0), 2); @@ -161,13 +164,16 @@ namespace RAT { int32_T b_loop_ub; int32_T loop_ub; - parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, - problem->bulkOut, problem->resolutionParams, - problem->calculations.allChis, reflectivity, + parallelPoints(problemStruct, problemCells, controls, + contrastParams->ssubs, + contrastParams->backgroundParams, + contrastParams->qzshifts, + contrastParams->scalefactors, contrastParams->bulkIn, + contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, simulation, shiftedData, b_layerSlds, b_sldProfiles, - b_allLayers, problem->allSubRough); + b_allLayers, contrastParams->allSubRough); layerSlds.set_size(b_layerSlds.size(0), 2); sldProfiles.set_size(b_sldProfiles.size(0), 2); allLayers.set_size(b_allLayers.size(0), 2); @@ -197,14 +203,17 @@ namespace RAT { int32_T b_loop_ub; int32_T loop_ub; - c_parallelContrasts(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgroundParams, - problem->qzshifts, problem->scalefactors, - problem->bulkIn, problem->bulkOut, - problem->resolutionParams, - problem->calculations.allChis, reflectivity, - simulation, shiftedData, b_layerSlds, - b_sldProfiles, b_allLayers, problem->allSubRough); + c_parallelContrasts(problemStruct, problemCells, controls, + contrastParams->ssubs, + contrastParams->backgroundParams, + contrastParams->qzshifts, + contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, + reflectivity, simulation, shiftedData, + b_layerSlds, b_sldProfiles, b_allLayers, + contrastParams->allSubRough); layerSlds.set_size(b_layerSlds.size(0), 2); sldProfiles.set_size(b_sldProfiles.size(0), 2); allLayers.set_size(b_allLayers.size(0), 2); @@ -232,11 +241,12 @@ namespace RAT } // Package everything into one array for tidy output - problem->calculations.sumChi = coder::sum(problem->calculations.allChis); - problem->resample.set_size(1, problemDef->resample.size(1)); - loop_ub_tmp = problemDef->resample.size(1); + contrastParams->calculations.sumChi = coder::sum + (contrastParams->calculations.allChis); + contrastParams->resample.set_size(1, problemStruct->resample.size(1)); + loop_ub_tmp = problemStruct->resample.size(1); for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - problem->resample[b_i] = problemDef->resample[b_i]; + contrastParams->resample[b_i] = problemStruct->resample[b_i]; } } } diff --git a/RAT/calculate3.h b/RAT/calculate3.h index e8c76692..3efdf953 100644 --- a/RAT/calculate3.h +++ b/RAT/calculate3.h @@ -11,19 +11,13 @@ #define CALCULATE3_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; - struct struct_T; -} - // Function Declarations namespace RAT { @@ -31,13 +25,14 @@ namespace RAT { namespace standardLayers { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array &sldProfiles, :: - coder::array &allLayers); + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &sldProfiles, ::coder::array &allLayers); } } } diff --git a/RAT/calculate4.cpp b/RAT/calculate4.cpp index 2e8ae3d7..3197e637 100644 --- a/RAT/calculate4.cpp +++ b/RAT/calculate4.cpp @@ -28,14 +28,14 @@ namespace RAT { namespace customLayers { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array - &domainSldProfiles, ::coder::array - &allLayers) + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< + cell_wrap_8, 2U> &allLayers) { ::coder::array b_allLayers; int32_T loop_ub_tmp; @@ -51,16 +51,16 @@ namespace RAT // Pre-allocation - It's necessary to // pre-allocate the memory for all the arrays // for compilation, so do this in this block. - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgroundParams.set_size(loop_ub_tmp); - problem->qzshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->bulkIn.set_size(loop_ub_tmp); - problem->bulkOut.set_size(loop_ub_tmp); - problem->calculations.allChis.set_size(loop_ub_tmp); - problem->resolutionParams.set_size(loop_ub_tmp); - problem->allSubRough.set_size(loop_ub_tmp); + loop_ub_tmp = static_cast(problemStruct->numberOfContrasts); + contrastParams->ssubs.set_size(loop_ub_tmp); + contrastParams->backgroundParams.set_size(loop_ub_tmp); + contrastParams->qzshifts.set_size(loop_ub_tmp); + contrastParams->scalefactors.set_size(loop_ub_tmp); + contrastParams->bulkIn.set_size(loop_ub_tmp); + contrastParams->bulkOut.set_size(loop_ub_tmp); + contrastParams->calculations.allChis.set_size(loop_ub_tmp); + contrastParams->resolutionParams.set_size(loop_ub_tmp); + contrastParams->allSubRough.set_size(loop_ub_tmp); reflectivity.set_size(loop_ub_tmp); simulation.set_size(loop_ub_tmp); shiftedData.set_size(loop_ub_tmp); @@ -68,15 +68,15 @@ namespace RAT domainSldProfiles.set_size(loop_ub_tmp, 2); allLayers.set_size(loop_ub_tmp, 2); for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgroundParams[i] = 0.0; - problem->qzshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->bulkIn[i] = 0.0; - problem->bulkOut[i] = 0.0; - problem->calculations.allChis[i] = 0.0; - problem->resolutionParams[i] = 0.0; - problem->allSubRough[i] = 0.0; + contrastParams->ssubs[i] = 0.0; + contrastParams->backgroundParams[i] = 0.0; + contrastParams->qzshifts[i] = 0.0; + contrastParams->scalefactors[i] = 0.0; + contrastParams->bulkIn[i] = 0.0; + contrastParams->bulkOut[i] = 0.0; + contrastParams->calculations.allChis[i] = 0.0; + contrastParams->resolutionParams[i] = 0.0; + contrastParams->allSubRough[i] = 0.0; reflectivity[i].f1.set_size(2, 2); reflectivity[i].f1[0] = 1.0; reflectivity[i].f1[1] = 1.0; @@ -140,12 +140,13 @@ namespace RAT switch (loop_ub_tmp) { case 0: - b_single(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, problem->bulkOut, - problem->resolutionParams, problem->calculations.allChis, - reflectivity, simulation, shiftedData, layerSlds, - domainSldProfiles, b_allLayers, problem->allSubRough); + b_single(problemStruct, problemCells, controls, contrastParams->ssubs, + contrastParams->backgroundParams, contrastParams->qzshifts, + contrastParams->scalefactors, contrastParams->bulkIn, + contrastParams->bulkOut, contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, domainSldProfiles, + b_allLayers, contrastParams->allSubRough); allLayers.set_size(b_allLayers.size(0), 2); loop_ub_tmp = b_allLayers.size(0); for (int32_T b_i{0}; b_i < 2; b_i++) { @@ -157,13 +158,14 @@ namespace RAT break; case 1: - parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, - problem->bulkOut, problem->resolutionParams, - problem->calculations.allChis, reflectivity, simulation, - shiftedData, layerSlds, domainSldProfiles, b_allLayers, - problem->allSubRough); + parallelPoints(problemStruct, problemCells, controls, + contrastParams->ssubs, contrastParams->backgroundParams, + contrastParams->qzshifts, contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, domainSldProfiles, + b_allLayers, contrastParams->allSubRough); allLayers.set_size(b_allLayers.size(0), 2); loop_ub_tmp = b_allLayers.size(0); for (int32_T b_i{0}; b_i < 2; b_i++) { @@ -175,15 +177,17 @@ namespace RAT break; case 2: - c_parallelContrasts(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgroundParams, - problem->qzshifts, problem->scalefactors, - problem->bulkIn, problem->bulkOut, - problem->resolutionParams, - problem->calculations.allChis, reflectivity, + c_parallelContrasts(problemStruct, problemCells, controls, + contrastParams->ssubs, + contrastParams->backgroundParams, + contrastParams->qzshifts, + contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, simulation, shiftedData, layerSlds, domainSldProfiles, b_allLayers, - problem->allSubRough); + contrastParams->allSubRough); allLayers.set_size(b_allLayers.size(0), 2); loop_ub_tmp = b_allLayers.size(0); for (int32_T b_i{0}; b_i < 2; b_i++) { @@ -195,11 +199,12 @@ namespace RAT break; } - problem->calculations.sumChi = coder::sum(problem->calculations.allChis); - problem->resample.set_size(1, problemDef->resample.size(1)); - loop_ub_tmp = problemDef->resample.size(1); + contrastParams->calculations.sumChi = coder::sum + (contrastParams->calculations.allChis); + contrastParams->resample.set_size(1, problemStruct->resample.size(1)); + loop_ub_tmp = problemStruct->resample.size(1); for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - problem->resample[b_i] = problemDef->resample[b_i]; + contrastParams->resample[b_i] = problemStruct->resample[b_i]; } } } diff --git a/RAT/calculate4.h b/RAT/calculate4.h index afa1b9db..98a05479 100644 --- a/RAT/calculate4.h +++ b/RAT/calculate4.h @@ -11,19 +11,13 @@ #define CALCULATE4_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; - struct struct_T; -} - // Function Declarations namespace RAT { @@ -31,14 +25,14 @@ namespace RAT { namespace customLayers { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array - &domainSldProfiles, ::coder::array - &allLayers); + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< + cell_wrap_8, 2U> &allLayers); } } } diff --git a/RAT/calculate5.cpp b/RAT/calculate5.cpp index 436d7e15..79a7ecd3 100644 --- a/RAT/calculate5.cpp +++ b/RAT/calculate5.cpp @@ -28,14 +28,14 @@ namespace RAT { namespace customXY { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array - &domainSldProfiles, ::coder::array - &allLayers) + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< + cell_wrap_8, 2U> &allLayers) { ::coder::array b_allLayers; int32_T loop_ub_tmp; @@ -51,16 +51,16 @@ namespace RAT // Pre-allocation - It's necessary to // pre-allocate the memory for all the arrays // for compilation, so do this in this block. - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgroundParams.set_size(loop_ub_tmp); - problem->qzshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->bulkIn.set_size(loop_ub_tmp); - problem->bulkOut.set_size(loop_ub_tmp); - problem->calculations.allChis.set_size(loop_ub_tmp); - problem->resolutionParams.set_size(loop_ub_tmp); - problem->allSubRough.set_size(loop_ub_tmp); + loop_ub_tmp = static_cast(problemStruct->numberOfContrasts); + contrastParams->ssubs.set_size(loop_ub_tmp); + contrastParams->backgroundParams.set_size(loop_ub_tmp); + contrastParams->qzshifts.set_size(loop_ub_tmp); + contrastParams->scalefactors.set_size(loop_ub_tmp); + contrastParams->bulkIn.set_size(loop_ub_tmp); + contrastParams->bulkOut.set_size(loop_ub_tmp); + contrastParams->calculations.allChis.set_size(loop_ub_tmp); + contrastParams->resolutionParams.set_size(loop_ub_tmp); + contrastParams->allSubRough.set_size(loop_ub_tmp); reflectivity.set_size(loop_ub_tmp); simulation.set_size(loop_ub_tmp); shiftedData.set_size(loop_ub_tmp); @@ -68,15 +68,15 @@ namespace RAT domainSldProfiles.set_size(loop_ub_tmp, 2); allLayers.set_size(loop_ub_tmp, 2); for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgroundParams[i] = 0.0; - problem->qzshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->bulkIn[i] = 0.0; - problem->bulkOut[i] = 0.0; - problem->calculations.allChis[i] = 0.0; - problem->resolutionParams[i] = 0.0; - problem->allSubRough[i] = 0.0; + contrastParams->ssubs[i] = 0.0; + contrastParams->backgroundParams[i] = 0.0; + contrastParams->qzshifts[i] = 0.0; + contrastParams->scalefactors[i] = 0.0; + contrastParams->bulkIn[i] = 0.0; + contrastParams->bulkOut[i] = 0.0; + contrastParams->calculations.allChis[i] = 0.0; + contrastParams->resolutionParams[i] = 0.0; + contrastParams->allSubRough[i] = 0.0; reflectivity[i].f1.set_size(2, 2); reflectivity[i].f1[0] = 1.0; reflectivity[i].f1[1] = 1.0; @@ -140,12 +140,13 @@ namespace RAT switch (loop_ub_tmp) { case 0: - b_single(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, problem->bulkOut, - problem->resolutionParams, problem->calculations.allChis, - reflectivity, simulation, shiftedData, layerSlds, - domainSldProfiles, b_allLayers, problem->allSubRough); + b_single(problemStruct, problemCells, controls, contrastParams->ssubs, + contrastParams->backgroundParams, contrastParams->qzshifts, + contrastParams->scalefactors, contrastParams->bulkIn, + contrastParams->bulkOut, contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, domainSldProfiles, + b_allLayers, contrastParams->allSubRough); allLayers.set_size(b_allLayers.size(0), 2); loop_ub_tmp = b_allLayers.size(0); for (int32_T b_i{0}; b_i < 2; b_i++) { @@ -157,13 +158,14 @@ namespace RAT break; case 1: - parallelPoints(problemDef, problemDefCells, controls, problem->ssubs, - problem->backgroundParams, problem->qzshifts, - problem->scalefactors, problem->bulkIn, - problem->bulkOut, problem->resolutionParams, - problem->calculations.allChis, reflectivity, simulation, - shiftedData, layerSlds, domainSldProfiles, b_allLayers, - problem->allSubRough); + parallelPoints(problemStruct, problemCells, controls, + contrastParams->ssubs, contrastParams->backgroundParams, + contrastParams->qzshifts, contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, + simulation, shiftedData, layerSlds, domainSldProfiles, + b_allLayers, contrastParams->allSubRough); allLayers.set_size(b_allLayers.size(0), 2); loop_ub_tmp = b_allLayers.size(0); for (int32_T b_i{0}; b_i < 2; b_i++) { @@ -175,15 +177,17 @@ namespace RAT break; case 2: - c_parallelContrasts(problemDef, problemDefCells, controls, - problem->ssubs, problem->backgroundParams, - problem->qzshifts, problem->scalefactors, - problem->bulkIn, problem->bulkOut, - problem->resolutionParams, - problem->calculations.allChis, reflectivity, + c_parallelContrasts(problemStruct, problemCells, controls, + contrastParams->ssubs, + contrastParams->backgroundParams, + contrastParams->qzshifts, + contrastParams->scalefactors, + contrastParams->bulkIn, contrastParams->bulkOut, + contrastParams->resolutionParams, + contrastParams->calculations.allChis, reflectivity, simulation, shiftedData, layerSlds, domainSldProfiles, b_allLayers, - problem->allSubRough); + contrastParams->allSubRough); allLayers.set_size(b_allLayers.size(0), 2); loop_ub_tmp = b_allLayers.size(0); for (int32_T b_i{0}; b_i < 2; b_i++) { @@ -195,11 +199,12 @@ namespace RAT break; } - problem->calculations.sumChi = coder::sum(problem->calculations.allChis); - problem->resample.set_size(1, problemDef->resample.size(1)); - loop_ub_tmp = problemDef->resample.size(1); + contrastParams->calculations.sumChi = coder::sum + (contrastParams->calculations.allChis); + contrastParams->resample.set_size(1, problemStruct->resample.size(1)); + loop_ub_tmp = problemStruct->resample.size(1); for (int32_T b_i{0}; b_i < loop_ub_tmp; b_i++) { - problem->resample[b_i] = problemDef->resample[b_i]; + contrastParams->resample[b_i] = problemStruct->resample[b_i]; } } } diff --git a/RAT/calculate5.h b/RAT/calculate5.h index f294b7c9..7c2fe788 100644 --- a/RAT/calculate5.h +++ b/RAT/calculate5.h @@ -11,19 +11,13 @@ #define CALCULATE5_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; - struct struct_T; -} - // Function Declarations namespace RAT { @@ -31,14 +25,14 @@ namespace RAT { namespace customXY { - void calculate(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &shiftedData, ::coder::array - &layerSlds, ::coder::array - &domainSldProfiles, ::coder::array - &allLayers); + void calculate(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array + &reflectivity, ::coder::array &simulation, + ::coder::array &shiftedData, ::coder:: + array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< + cell_wrap_8, 2U> &allLayers); } } } diff --git a/RAT/callCppFunction.cpp b/RAT/callCppFunction.cpp index cb948c5a..b7f165d3 100644 --- a/RAT/callCppFunction.cpp +++ b/RAT/callCppFunction.cpp @@ -14,21 +14,26 @@ #include "classHandle.hpp" #include "coder_array.h" #include +#include #include // Function Definitions namespace RAT { - void b_callCppFunction(::coder::array ¶ms, real_T bulkIn, - real_T bulkOut, real_T contrast, const char_T pointer_data[], const int32_T - pointer_size[2], ::coder::array &output, real_T *subRough) + void b_callCppFunction(const char_T pointer_data[], const int32_T + pointer_size[2], ::coder::array ¶ms, real_T bulkIn, ::coder:: + array &bulkOut, real_T contrast, ::coder::array + &output, real_T *subRough) { - static real_T tempOutput[6000]; - static real_T tempOutput_data[6000]; CallbackInterface * callback; ClassHandle * callbackHandle; + std::vector bulkInArray; + std::vector bulkOutArray; + std::vector outArray; + std::vector paramsArray; + ::coder::array tempOutput; real_T outputSize[2]; - real_T size; + real_T d; int32_T loop_ub; int32_T loop_ub_tmp; char_T b_pointer_data[10000]; @@ -40,43 +45,61 @@ namespace RAT callbackHandle = convertString2HandlePtr(&b_pointer_data [0]); callback = std::mem_fn(&ClassHandle::ptr)(callbackHandle); + paramsArray = convertPtr2Vector(¶ms[0], static_cast(params.size + (1))); + bulkInArray = convertPtr2Vector(&bulkIn, 1.0); + bulkOutArray = convertPtr2Vector(&bulkOut[0], static_cast + (bulkOut.size(1))); + outArray = { }; - // This is not ideal, it needs to be fixed // domain should either before 0 or 1. A value less than zero indicates no domains - std::mem_fn(&CallbackInterface::invoke)(callback, ¶ms[0], - &bulkIn, &bulkOut, contrast, 0.0, &tempOutput[0], &outputSize[0], subRough); - size = outputSize[0] * outputSize[1]; - if (size < 1.0) { - loop_ub = 0; + std::mem_fn&, std::vector&, std::vector< + double>&, int, int, std::vector&, double*, double*)> + (&CallbackInterface::invoke)(callback, paramsArray, bulkInArray, + bulkOutArray, contrast, 0.0, outArray, &outputSize[0], subRough); + d = std::round(outputSize[0] * outputSize[1]); + if (d < 2.147483648E+9) { + if (d >= -2.147483648E+9) { + loop_ub = static_cast(d); + } else { + loop_ub = MIN_int32_T; + } + } else if (d >= 2.147483648E+9) { + loop_ub = MAX_int32_T; } else { - loop_ub = static_cast(size); + loop_ub = 0; } - if (loop_ub - 1 >= 0) { - std::copy(&tempOutput[0], &tempOutput[loop_ub], &tempOutput_data[0]); + tempOutput.set_size(1, loop_ub); + for (int32_T i{0}; i < loop_ub; i++) { + tempOutput[i] = 0.0; } + convertVector2Ptr(outArray, &tempOutput[0]); loop_ub_tmp = static_cast(outputSize[1]); loop_ub = static_cast(outputSize[0]); output.set_size(loop_ub, loop_ub_tmp); for (int32_T i{0}; i < loop_ub_tmp; i++) { for (int32_T i1{0}; i1 < loop_ub; i1++) { - output[i1 + output.size(0) * i] = tempOutput_data[i + loop_ub_tmp * i1]; + output[i1 + output.size(0) * i] = tempOutput[i + loop_ub_tmp * i1]; } } } - void c_callCppFunction(::coder::array ¶ms, real_T bulkIn, - real_T bulkOut, real_T contrast, const char_T pointer_data[], const int32_T - pointer_size[2], ::coder::array &output, real_T *subRough) + void c_callCppFunction(const char_T pointer_data[], const int32_T + pointer_size[2], ::coder::array ¶ms, real_T bulkIn, ::coder:: + array &bulkOut, real_T contrast, ::coder::array + &output, real_T *subRough) { - static real_T tempOutput[6000]; - static real_T tempOutput_data[6000]; CallbackInterface * callback; ClassHandle * callbackHandle; + std::vector bulkInArray; + std::vector bulkOutArray; + std::vector outArray; + std::vector paramsArray; + ::coder::array tempOutput; real_T outputSize[2]; - real_T size; + real_T d; int32_T loop_ub; int32_T loop_ub_tmp; char_T b_pointer_data[10000]; @@ -88,44 +111,61 @@ namespace RAT callbackHandle = convertString2HandlePtr(&b_pointer_data [0]); callback = std::mem_fn(&ClassHandle::ptr)(callbackHandle); + paramsArray = convertPtr2Vector(¶ms[0], static_cast(params.size + (1))); + bulkInArray = convertPtr2Vector(&bulkIn, 1.0); + bulkOutArray = convertPtr2Vector(&bulkOut[0], static_cast + (bulkOut.size(1))); + outArray = { }; - // This is not ideal, it needs to be fixed // domain should either before 0 or 1. A value less than zero indicates no domains - std::mem_fn(&CallbackInterface::invoke)(callback, ¶ms[0], - &bulkIn, &bulkOut, contrast, 1.0, &tempOutput[0], &outputSize[0], subRough); - size = outputSize[0] * outputSize[1]; - if (size < 1.0) { - loop_ub = 0; + std::mem_fn&, std::vector&, std::vector< + double>&, int, int, std::vector&, double*, double*)> + (&CallbackInterface::invoke)(callback, paramsArray, bulkInArray, + bulkOutArray, contrast, 1.0, outArray, &outputSize[0], subRough); + d = std::round(outputSize[0] * outputSize[1]); + if (d < 2.147483648E+9) { + if (d >= -2.147483648E+9) { + loop_ub = static_cast(d); + } else { + loop_ub = MIN_int32_T; + } + } else if (d >= 2.147483648E+9) { + loop_ub = MAX_int32_T; } else { - loop_ub = static_cast(size); + loop_ub = 0; } - if (loop_ub - 1 >= 0) { - std::copy(&tempOutput[0], &tempOutput[loop_ub], &tempOutput_data[0]); + tempOutput.set_size(1, loop_ub); + for (int32_T i{0}; i < loop_ub; i++) { + tempOutput[i] = 0.0; } + convertVector2Ptr(outArray, &tempOutput[0]); loop_ub_tmp = static_cast(outputSize[1]); loop_ub = static_cast(outputSize[0]); output.set_size(loop_ub, loop_ub_tmp); for (int32_T i{0}; i < loop_ub_tmp; i++) { for (int32_T i1{0}; i1 < loop_ub; i1++) { - output[i1 + output.size(0) * i] = tempOutput_data[i + loop_ub_tmp * i1]; + output[i1 + output.size(0) * i] = tempOutput[i + loop_ub_tmp * i1]; } } } - void callCppFunction(::coder::array ¶ms, real_T bulkIn, real_T - bulkOut, real_T contrast, const char_T pointer_data[], - const int32_T pointer_size[2], ::coder::array - &output, real_T *subRough) + void callCppFunction(const char_T pointer_data[], const int32_T pointer_size[2], + ::coder::array ¶ms, real_T bulkIn, :: + coder::array &bulkOut, real_T contrast, :: + coder::array &output, real_T *subRough) { - static real_T tempOutput[6000]; - static real_T tempOutput_data[6000]; CallbackInterface * callback; ClassHandle * callbackHandle; + std::vector bulkInArray; + std::vector bulkOutArray; + std::vector outArray; + std::vector paramsArray; + ::coder::array tempOutput; real_T outputSize[2]; - real_T size; + real_T d; int32_T loop_ub; int32_T loop_ub_tmp; char_T b_pointer_data[10000]; @@ -137,29 +177,43 @@ namespace RAT callbackHandle = convertString2HandlePtr(&b_pointer_data [0]); callback = std::mem_fn(&ClassHandle::ptr)(callbackHandle); + paramsArray = convertPtr2Vector(¶ms[0], static_cast(params.size + (1))); + bulkInArray = convertPtr2Vector(&bulkIn, 1.0); + bulkOutArray = convertPtr2Vector(&bulkOut[0], static_cast + (bulkOut.size(1))); + outArray = { }; - // This is not ideal, it needs to be fixed // domain should either before 0 or 1. A value less than zero indicates no domains - std::mem_fn - (&CallbackInterface::invoke)(callback, ¶ms[0], &bulkIn, &bulkOut, - contrast, &tempOutput[0], &outputSize[0], subRough); - size = outputSize[0] * outputSize[1]; - if (size < 1.0) { - loop_ub = 0; + std::mem_fn&, std::vector&, std::vector< + double>&, int, std::vector&, double*, double*)> + (&CallbackInterface::invoke)(callback, paramsArray, bulkInArray, + bulkOutArray, contrast, outArray, &outputSize[0], subRough); + d = std::round(outputSize[0] * outputSize[1]); + if (d < 2.147483648E+9) { + if (d >= -2.147483648E+9) { + loop_ub = static_cast(d); + } else { + loop_ub = MIN_int32_T; + } + } else if (d >= 2.147483648E+9) { + loop_ub = MAX_int32_T; } else { - loop_ub = static_cast(size); + loop_ub = 0; } - if (loop_ub - 1 >= 0) { - std::copy(&tempOutput[0], &tempOutput[loop_ub], &tempOutput_data[0]); + tempOutput.set_size(1, loop_ub); + for (int32_T i{0}; i < loop_ub; i++) { + tempOutput[i] = 0.0; } + convertVector2Ptr(outArray, &tempOutput[0]); loop_ub_tmp = static_cast(outputSize[1]); loop_ub = static_cast(outputSize[0]); output.set_size(loop_ub, loop_ub_tmp); for (int32_T i{0}; i < loop_ub_tmp; i++) { for (int32_T i1{0}; i1 < loop_ub; i1++) { - output[i1 + output.size(0) * i] = tempOutput_data[i + loop_ub_tmp * i1]; + output[i1 + output.size(0) * i] = tempOutput[i + loop_ub_tmp * i1]; } } } diff --git a/RAT/callCppFunction.h b/RAT/callCppFunction.h index 8564e057..7ce9ecbe 100644 --- a/RAT/callCppFunction.h +++ b/RAT/callCppFunction.h @@ -19,16 +19,18 @@ // Function Declarations namespace RAT { - void b_callCppFunction(::coder::array ¶ms, real_T bulkIn, - real_T bulkOut, real_T contrast, const char_T pointer_data[], const int32_T - pointer_size[2], ::coder::array &output, real_T *subRough); - void c_callCppFunction(::coder::array ¶ms, real_T bulkIn, - real_T bulkOut, real_T contrast, const char_T pointer_data[], const int32_T - pointer_size[2], ::coder::array &output, real_T *subRough); - void callCppFunction(::coder::array ¶ms, real_T bulkIn, real_T - bulkOut, real_T contrast, const char_T pointer_data[], - const int32_T pointer_size[2], ::coder::array - &output, real_T *subRough); + void b_callCppFunction(const char_T pointer_data[], const int32_T + pointer_size[2], ::coder::array ¶ms, real_T bulkIn, ::coder:: + array &bulkOut, real_T contrast, ::coder::array + &output, real_T *subRough); + void c_callCppFunction(const char_T pointer_data[], const int32_T + pointer_size[2], ::coder::array ¶ms, real_T bulkIn, ::coder:: + array &bulkOut, real_T contrast, ::coder::array + &output, real_T *subRough); + void callCppFunction(const char_T pointer_data[], const int32_T pointer_size[2], + ::coder::array ¶ms, real_T bulkIn, :: + coder::array &bulkOut, real_T contrast, :: + coder::array &output, real_T *subRough); } #endif diff --git a/RAT/classHandle.hpp b/RAT/classHandle.hpp index 667d55e2..ca08e2e7 100644 --- a/RAT/classHandle.hpp +++ b/RAT/classHandle.hpp @@ -10,6 +10,7 @@ Adapted from https://github.com/ojwoodford/mex_class_wrapper #include #include #include +#include #include #include @@ -32,12 +33,23 @@ template class ClassHandle class CallbackInterface { public: - virtual void invoke(double* params,double *bulk_in,double *bulk_out, int contrast, - double *tempOutput,double *outputSize,double *roughness)=0; - virtual void invoke(double* params,double *bulk_in,double *bulk_out, int contrast, int domainNumber, - double *tempOutput,double *outputSize,double *roughness)=0; + virtual void invoke(std::vector& params, std::vector& bulk_in, std::vector& bulk_out, + int contrast, std::vector& tempOutput, double *outputSize, double *roughness)=0; + virtual void invoke(std::vector& params, std::vector& bulk_in, std::vector& bulk_out, + int contrast, int domainNumber, std::vector& tempOutput, double *outputSize, double *roughness)=0; }; +inline std::vector convertPtr2Vector(double* ptr, int size) +{ + std::vector array(ptr, ptr + size); + return array; +} + +inline std::size_t convertVector2Ptr(std::vector& array, double* ptr) +{ + std::memcpy(ptr, array.data(), array.size()*sizeof(double)); + return array.size(); +} template inline std::string convertPtr2String(base *ptr) { diff --git a/RAT/coreLayersCalculation.cpp b/RAT/coreLayersCalculation.cpp index 262b2481..b536645f 100644 --- a/RAT/coreLayersCalculation.cpp +++ b/RAT/coreLayersCalculation.cpp @@ -312,7 +312,7 @@ namespace RAT if (!useImaginary) { resampleLayers(sldProfile, resamPars, layerSld); } else { - b_resampleLayersReIm(sldProfile, sldProfileIm, resamPars, layerSld); + resampleLayersReIm(sldProfile, sldProfileIm, resamPars, layerSld); } resamLayers.set_size(layerSld.size(0), layerSld.size(1)); @@ -642,7 +642,7 @@ namespace RAT if (!useImaginary) { resampleLayers(sldProfile, resamPars, layerSld); } else { - b_resampleLayersReIm(sldProfile, sldProfileIm, resamPars, layerSld); + resampleLayersReIm(sldProfile, sldProfileIm, resamPars, layerSld); } resamLayers.set_size(layerSld.size(0), layerSld.size(1)); diff --git a/RAT/deopt.cpp b/RAT/deopt.cpp index c4ab08f3..b6ad7115 100644 --- a/RAT/deopt.cpp +++ b/RAT/deopt.cpp @@ -29,7 +29,7 @@ namespace RAT { static void binary_expand_op(::coder::array &in1, int32_T in2, - const i_struct_T *in3, const ::coder::array &in4); + const j_struct_T *in3, const ::coder::array &in4); static void h_binary_expand_op(::coder::array &in1, const ::coder:: array &in2, const ::coder::array &in3, const :: coder::array &in4, const ::coder::array &in5, const :: @@ -40,7 +40,7 @@ namespace RAT namespace RAT { static void binary_expand_op(::coder::array &in1, int32_T in2, - const i_struct_T *in3, const ::coder::array &in4) + const j_struct_T *in3, const ::coder::array &in4) { int32_T i; int32_T loop_ub; @@ -300,22 +300,22 @@ namespace RAT } } - void deopt(const struct5_T *problem, const ::coder::array - &problemDefCells_f1, const ::coder::array - &problemDefCells_f2, const ::coder::array - &problemDefCells_f3, const ::coder::array - &problemDefCells_f4, const ::coder::array - &problemDefCells_f5, const ::coder::array - &problemDefCells_f6, const ::coder::array - &problemDefCells_f14, const ::coder::array - &problemDefCells_f19, const char_T controls_parallel_data[], const + void deopt(const c_struct_T *problem, const ::coder::array + &problemCells_f1, const ::coder::array + &problemCells_f2, const ::coder::array + &problemCells_f3, const ::coder::array + &problemCells_f4, const ::coder::array + &problemCells_f5, const ::coder::array + &problemCells_f6, const ::coder::array + &problemCells_f14, const ::coder::array + &problemCells_f19, const char_T controls_parallel_data[], const int32_T controls_parallel_size[2], const real_T controls_resamPars [2], boolean_T controls_calcSldDuringFit, const char_T controls_display_data[], const int32_T controls_display_size[2], - const struct3_T *controls_checks, const i_struct_T *S_struct, :: + const struct3_T *controls_checks, const j_struct_T *S_struct, :: coder::array &FVr_bestmem) { - ::coder::array S_val; + ::coder::array S_val; ::coder::array FM_pm3; ::coder::array FM_pop; ::coder::array FM_ui; @@ -326,7 +326,7 @@ namespace RAT ::coder::array r; ::coder::array r1; ::coder::array FM_mui; - struct5_T b_problem; + c_struct_T b_problem; real_T F_CR; real_T I_D; real_T I_NP; @@ -502,17 +502,16 @@ namespace RAT S_val[0] = intrafun(b_FM_pop, &b_problem, controls_parallel_data, controls_parallel_size, controls_resamPars, controls_calcSldDuringFit, controls_checks, - problemDefCells_f1, problemDefCells_f2, - problemDefCells_f3, problemDefCells_f4, - problemDefCells_f5, problemDefCells_f6, - problemDefCells_f14, problemDefCells_f19); + problemCells_f1, problemCells_f2, problemCells_f3, + problemCells_f4, problemCells_f5, problemCells_f6, + problemCells_f14, problemCells_f19); S_bestval_FVr_oa = S_val[0].FVr_oa; // best objective function value so far b_loop_ub_tmp = static_cast(I_NP - 1.0); loop_ub = FM_pop.size(1); for (int32_T k{0}; k < b_loop_ub_tmp; k++) { - k_struct_T expl_temp; + l_struct_T expl_temp; // check the remaining members b_FM_pop.set_size(1, FM_pop.size(1)); @@ -524,10 +523,9 @@ namespace RAT expl_temp = intrafun(b_FM_pop, &b_problem, controls_parallel_data, controls_parallel_size, controls_resamPars, controls_calcSldDuringFit, controls_checks, - problemDefCells_f1, problemDefCells_f2, - problemDefCells_f3, problemDefCells_f4, - problemDefCells_f5, problemDefCells_f6, - problemDefCells_f14, problemDefCells_f19); + problemCells_f1, problemCells_f2, problemCells_f3, + problemCells_f4, problemCells_f5, problemCells_f6, + problemCells_f14, problemCells_f19); S_val[k + 1] = expl_temp; if (leftWin(expl_temp.I_no, expl_temp.FVr_oa, S_bestval_FVr_oa) == 1.0) { // save its location @@ -729,7 +727,7 @@ namespace RAT // -----Optional parent+child selection----------------------------------------- // -----Select which vectors are allowed to enter the new population------------ for (int32_T k{0}; k < i; k++) { - k_struct_T S_tempval; + l_struct_T S_tempval; // =====Only use this if boundary constraints are needed================== for (int32_T j{0}; j < loop_ub_tmp; j++) { @@ -761,10 +759,9 @@ namespace RAT S_tempval = intrafun(b_FM_pop, &b_problem, controls_parallel_data, controls_parallel_size, controls_resamPars, controls_calcSldDuringFit, controls_checks, - problemDefCells_f1, problemDefCells_f2, - problemDefCells_f3, problemDefCells_f4, - problemDefCells_f5, problemDefCells_f6, - problemDefCells_f14, problemDefCells_f19); + problemCells_f1, problemCells_f2, problemCells_f3, + problemCells_f4, problemCells_f5, problemCells_f6, + problemCells_f14, problemCells_f19); // check cost of competitor if (leftWin(S_tempval.I_no, S_tempval.FVr_oa, S_val[k].FVr_oa) == 1.0) { @@ -824,9 +821,9 @@ namespace RAT } // ---end while ((I_iter < I_itermax) ... - // problemDef.fitParams = x; - // problemDef = unpackParams(problemDef,controls); - // [problem,res] = reflectivityCalculation(problemDef,problemDefCells,controls); + // problemStruct.fitParams = x; + // problemStruct = unpackParams(problemStruct,controls); + // [problem,res] = reflectivityCalculation(problemStruct,problemCells,controls); } } diff --git a/RAT/deopt.h b/RAT/deopt.h index a010cb7a..cd162a1a 100644 --- a/RAT/deopt.h +++ b/RAT/deopt.h @@ -20,25 +20,26 @@ // Type Declarations namespace RAT { - struct i_struct_T; + struct c_struct_T; + struct j_struct_T; } // Function Declarations namespace RAT { - void deopt(const struct5_T *problem, const ::coder::array - &problemDefCells_f1, const ::coder::array - &problemDefCells_f2, const ::coder::array - &problemDefCells_f3, const ::coder::array - &problemDefCells_f4, const ::coder::array - &problemDefCells_f5, const ::coder::array - &problemDefCells_f6, const ::coder::array - &problemDefCells_f14, const ::coder::array - &problemDefCells_f19, const char_T controls_parallel_data[], const + void deopt(const c_struct_T *problem, const ::coder::array + &problemCells_f1, const ::coder::array + &problemCells_f2, const ::coder::array + &problemCells_f3, const ::coder::array + &problemCells_f4, const ::coder::array + &problemCells_f5, const ::coder::array + &problemCells_f6, const ::coder::array + &problemCells_f14, const ::coder::array + &problemCells_f19, const char_T controls_parallel_data[], const int32_T controls_parallel_size[2], const real_T controls_resamPars [2], boolean_T controls_calcSldDuringFit, const char_T controls_display_data[], const int32_T controls_display_size[2], - const struct3_T *controls_checks, const i_struct_T *S_struct, :: + const struct3_T *controls_checks, const j_struct_T *S_struct, :: coder::array &FVr_bestmem); } diff --git a/RAT/drawCR.cpp b/RAT/drawCR.cpp index 0f762d94..3c853d24 100644 --- a/RAT/drawCR.cpp +++ b/RAT/drawCR.cpp @@ -21,7 +21,7 @@ // Function Definitions namespace RAT { - void drawCR(const struct14_T *DREAMPar, const real_T pCR_data[], const int32_T + void drawCR(const struct13_T *DREAMPar, const real_T pCR_data[], const int32_T pCR_size[2], ::coder::array &CR) { ::coder::array b_r; diff --git a/RAT/drawCR.h b/RAT/drawCR.h index ce2bf36c..35690faa 100644 --- a/RAT/drawCR.h +++ b/RAT/drawCR.h @@ -19,13 +19,13 @@ // Type Declarations namespace RAT { - struct struct14_T; + struct struct13_T; } // Function Declarations namespace RAT { - void drawCR(const struct14_T *DREAMPar, const real_T pCR_data[], const int32_T + void drawCR(const struct13_T *DREAMPar, const real_T pCR_data[], const int32_T pCR_size[2], ::coder::array &CR); } diff --git a/RAT/drawMCMC.cpp b/RAT/drawMCMC.cpp index dbffc645..2d09e649 100644 --- a/RAT/drawMCMC.cpp +++ b/RAT/drawMCMC.cpp @@ -98,8 +98,8 @@ namespace RAT void drawMCMC(const ::coder::array &livepoints, const ::coder:: array &cholmat, real_T logLmin, const ::coder::array< - real_T, 2U> &prior, const struct5_T *data_f1, const struct2_T - *data_f2, const cell_14 *data_f4, real_T Nmcmc, ::coder::array< + real_T, 2U> &prior, const c_struct_T *data_f1, const struct2_T + *data_f2, const cell_11 *data_f4, real_T Nmcmc, ::coder::array< real_T, 2U> &sample, real_T *logL) { ::coder::array sampletmp; diff --git a/RAT/drawMCMC.h b/RAT/drawMCMC.h index 104a4d6a..5a73f152 100644 --- a/RAT/drawMCMC.h +++ b/RAT/drawMCMC.h @@ -19,9 +19,9 @@ // Type Declarations namespace RAT { - struct struct5_T; + struct c_struct_T; struct struct2_T; - struct cell_14; + struct cell_11; } // Function Declarations @@ -29,8 +29,8 @@ namespace RAT { void drawMCMC(const ::coder::array &livepoints, const ::coder:: array &cholmat, real_T logLmin, const ::coder::array< - real_T, 2U> &prior, const struct5_T *data_f1, const struct2_T - *data_f2, const cell_14 *data_f4, real_T Nmcmc, ::coder::array< + real_T, 2U> &prior, const c_struct_T *data_f1, const struct2_T + *data_f2, const cell_11 *data_f4, real_T Nmcmc, ::coder::array< real_T, 2U> &sample, real_T *logL); } diff --git a/RAT/drawMultiNest.cpp b/RAT/drawMultiNest.cpp index ccc5a33a..d6f8e757 100644 --- a/RAT/drawMultiNest.cpp +++ b/RAT/drawMultiNest.cpp @@ -28,8 +28,8 @@ namespace RAT void drawMultiNest(const ::coder::array &fracvol, const ::coder:: array &Bs, const ::coder::array &mus, real_T logLmin, const ::coder::array - &prior, const struct5_T *data_f1, const struct2_T *data_f2, - const cell_14 *data_f4, ::coder::array &sample, + &prior, const c_struct_T *data_f1, const struct2_T *data_f2, + const cell_11 *data_f4, ::coder::array &sample, real_T *logL) { ::coder::array B; diff --git a/RAT/drawMultiNest.h b/RAT/drawMultiNest.h index 1492021c..b350db67 100644 --- a/RAT/drawMultiNest.h +++ b/RAT/drawMultiNest.h @@ -19,9 +19,9 @@ // Type Declarations namespace RAT { - struct struct5_T; + struct c_struct_T; struct struct2_T; - struct cell_14; + struct cell_11; } // Function Declarations @@ -30,8 +30,8 @@ namespace RAT void drawMultiNest(const ::coder::array &fracvol, const ::coder:: array &Bs, const ::coder::array &mus, real_T logLmin, const ::coder::array - &prior, const struct5_T *data_f1, const struct2_T *data_f2, - const cell_14 *data_f4, ::coder::array &sample, + &prior, const c_struct_T *data_f1, const struct2_T *data_f2, + const cell_11 *data_f4, ::coder::array &sample, real_T *logL); } diff --git a/RAT/evaluateModel.cpp b/RAT/evaluateModel.cpp index 05249396..e3dd81a2 100644 --- a/RAT/evaluateModel.cpp +++ b/RAT/evaluateModel.cpp @@ -19,9 +19,9 @@ // Function Definitions namespace RAT { - void evaluateModel(const ::coder::array &x, const struct14_T - *DREAMPar, const struct5_T *ratInputs_problemDef, const - cell_14 *ratInputs_problemDefCells, const struct2_T + void evaluateModel(const ::coder::array &x, const struct13_T + *DREAMPar, const c_struct_T *ratInputs_problemStruct, const + cell_11 *ratInputs_problemCells, const struct2_T *ratInputs_controls, ::coder::array &fx) { ::coder::array b_x; @@ -60,7 +60,7 @@ namespace RAT b_x[i] = x[ii + x.size(0) * i]; } - fx[ii] = DREAMWrapper(b_x, ratInputs_problemDef, ratInputs_problemDefCells, + fx[ii] = DREAMWrapper(b_x, ratInputs_problemStruct, ratInputs_problemCells, ratInputs_controls); } } diff --git a/RAT/evaluateModel.h b/RAT/evaluateModel.h index d73fbeaa..ca3e877e 100644 --- a/RAT/evaluateModel.h +++ b/RAT/evaluateModel.h @@ -19,18 +19,18 @@ // Type Declarations namespace RAT { - struct struct14_T; - struct struct5_T; - struct cell_14; + struct struct13_T; + struct c_struct_T; + struct cell_11; struct struct2_T; } // Function Declarations namespace RAT { - void evaluateModel(const ::coder::array &x, const struct14_T - *DREAMPar, const struct5_T *ratInputs_problemDef, const - cell_14 *ratInputs_problemDefCells, const struct2_T + void evaluateModel(const ::coder::array &x, const struct13_T + *DREAMPar, const c_struct_T *ratInputs_problemStruct, const + cell_11 *ratInputs_problemCells, const struct2_T *ratInputs_controls, ::coder::array &fx); } diff --git a/RAT/examples/main.cpp b/RAT/examples/main.cpp index 7222e94b..11165b6a 100644 --- a/RAT/examples/main.cpp +++ b/RAT/examples/main.cpp @@ -644,25 +644,24 @@ int32_T main(int32_T, char **) void main_RATMain() { - static RAT::struct0_T problemDef; + static RAT::struct0_T problemStruct; static RAT::struct2_T controls; - static RAT::struct5_T outProblemDef; - static RAT::struct8_T bayesResults; - RAT::cell_7 problemDefCells; - RAT::cell_wrap_9 results[6]; - RAT::struct1_T problemDefLimits; + static RAT::struct7_T bayesResults; + RAT::cell_7 problemCells; + RAT::cell_wrap_9 resultCells[6]; + RAT::struct1_T problemLimits; RAT::struct4_T priors; - RAT::struct6_T problem; + RAT::struct5_T contrastParams; // Initialize function 'RATMain' input arguments. - // Initialize function input argument 'problemDef'. - argInit_struct0_T(&problemDef); + // Initialize function input argument 'problemStruct'. + argInit_struct0_T(&problemStruct); - // Initialize function input argument 'problemDefCells'. - argInit_cell_7(&problemDefCells); + // Initialize function input argument 'problemCells'. + argInit_cell_7(&problemCells); - // Initialize function input argument 'problemDefLimits'. - argInit_struct1_T(&problemDefLimits); + // Initialize function input argument 'problemLimits'. + argInit_struct1_T(&problemLimits); // Initialize function input argument 'controls'. argInit_struct2_T(&controls); @@ -671,8 +670,8 @@ void main_RATMain() argInit_struct4_T(&priors); // Call the entry-point 'RATMain'. - RAT::RATMain(&problemDef, &problemDefCells, &problemDefLimits, &controls, - &priors, &outProblemDef, &problem, results, &bayesResults); + RAT::RATMain(&problemStruct, &problemCells, &problemLimits, &controls, &priors, + &contrastParams, resultCells, &bayesResults); } // End of code generation (main.cpp) diff --git a/RAT/fMinSearch.cpp b/RAT/fMinSearch.cpp index 68a43521..088c33e5 100644 --- a/RAT/fMinSearch.cpp +++ b/RAT/fMinSearch.cpp @@ -206,8 +206,8 @@ namespace RAT void fMinSearch(::coder::array &x, real_T options_MaxIter, real_T options_MaxFunEvals, real_T options_TolX, real_T options_TolFun, const char_T dis_data[], const int32_T - dis_size[2], const struct5_T *varargin_1, const ::coder::array< - cell_wrap_2, 2U> &varargin_2_f1, const ::coder::array< + dis_size[2], const c_struct_T *varargin_1, const ::coder:: + array &varargin_2_f1, const ::coder::array< cell_wrap_8, 2U> &varargin_2_f2, const ::coder::array< cell_wrap_2, 2U> &varargin_2_f3, const ::coder::array< cell_wrap_2, 2U> &varargin_2_f4, const ::coder::array< @@ -215,8 +215,8 @@ namespace RAT cell_wrap_8, 1U> &varargin_2_f6, const ::coder::array< cell_wrap_1, 2U> &varargin_2_f14, const ::coder::array< cell_wrap_8, 2U> &varargin_2_f19, const struct2_T *varargin_3, - const j_struct_T *varargin_4, real_T *fval, real_T *exitflag, - h_struct_T *output) + const k_struct_T *varargin_4, real_T *fval, real_T *exitflag, + i_struct_T *output) { static const char_T cv6[33]{ 'N', 'e', 'l', 'd', 'e', 'r', '-', 'M', 'e', 'a', 'd', ' ', 's', 'i', 'm', 'p', 'l', 'e', 'x', ' ', 'd', 'i', 'r', 'e', @@ -264,8 +264,8 @@ namespace RAT ::coder::array y; ::coder::array iidx; ::coder::array b_varargin_4; - cell_13 result; - struct_T problem; + cell_wrap_9 result[6]; + d_struct_T problem; real_T func_evals; real_T fxc; real_T fxcc; @@ -495,7 +495,7 @@ namespace RAT simplexIntrafun(x, varargin_1, varargin_2_f1, varargin_2_f2, varargin_2_f3, varargin_2_f4, varargin_2_f5, varargin_2_f6, varargin_2_f14, varargin_2_f19, varargin_3, varargin_4, &fv[0], &problem, - &result); + result); // Initial simplex setup continues later // Initialize the output and plot functions. @@ -544,10 +544,9 @@ namespace RAT // fprintf('%g \n', func_evals) } - triggerEvent(result.f1, result.f3, result.f5, result.f6, problem.ssubs, - varargin_1->TF.data, varargin_1->TF.size, varargin_1->resample, - varargin_1->dataPresent, varargin_1->modelType.data, - varargin_1->modelType.size); + triggerEvent(result, problem.ssubs, varargin_1->TF.data, varargin_1->TF.size, + varargin_1->resample, varargin_1->dataPresent, + varargin_1->modelType.data, varargin_1->modelType.size); // OutputFcn and PlotFcns call // if haveoutputfcn || haveplotfcn @@ -587,7 +586,7 @@ namespace RAT simplexIntrafun(y, varargin_1, varargin_2_f1, varargin_2_f2, varargin_2_f3, varargin_2_f4, varargin_2_f5, varargin_2_f6, varargin_2_f14, varargin_2_f19, varargin_3, varargin_4, - &fv[j + 1], &problem, &result); + &fv[j + 1], &problem, result); } // sort so v(1,:) has the lowest function value @@ -635,10 +634,10 @@ namespace RAT } if (rt_remd_snf(1.0, varargin_3->updatePlotFreq) == 0.0) { - triggerEvent(result.f1, result.f3, result.f5, result.f6, problem.ssubs, - varargin_1->TF.data, varargin_1->TF.size, - varargin_1->resample, varargin_1->dataPresent, - varargin_1->modelType.data, varargin_1->modelType.size); + triggerEvent(result, problem.ssubs, varargin_1->TF.data, + varargin_1->TF.size, varargin_1->resample, + varargin_1->dataPresent, varargin_1->modelType.data, + varargin_1->modelType.size); } // OutputFcn and PlotFcns call @@ -767,7 +766,7 @@ namespace RAT simplexIntrafun(xr, varargin_1, varargin_2_f1, varargin_2_f2, varargin_2_f3, varargin_2_f4, varargin_2_f5, varargin_2_f6, varargin_2_f14, varargin_2_f19, - varargin_3, varargin_4, &fxr, &problem, &result); + varargin_3, varargin_4, &fxr, &problem, result); func_evals++; if (fxr < fv[0]) { // Calculate the expansion point @@ -784,7 +783,7 @@ namespace RAT simplexIntrafun(xe, varargin_1, varargin_2_f1, varargin_2_f2, varargin_2_f3, varargin_2_f4, varargin_2_f5, varargin_2_f6, varargin_2_f14, varargin_2_f19, - varargin_3, varargin_4, &fxe, &problem, &result); + varargin_3, varargin_4, &fxe, &problem, result); func_evals++; if (fxe < fxr) { x_idx_1 = xe.size(0); @@ -840,7 +839,7 @@ namespace RAT simplexIntrafun(xc, varargin_1, varargin_2_f1, varargin_2_f2, varargin_2_f3, varargin_2_f4, varargin_2_f5, varargin_2_f6, varargin_2_f14, varargin_2_f19, - varargin_3, varargin_4, &fxc, &problem, &result); + varargin_3, varargin_4, &fxc, &problem, result); func_evals++; if (fxc <= fxr) { x_idx_1 = xc.size(0); @@ -877,7 +876,7 @@ namespace RAT simplexIntrafun(xcc, varargin_1, varargin_2_f1, varargin_2_f2, varargin_2_f3, varargin_2_f4, varargin_2_f5, varargin_2_f6, varargin_2_f14, varargin_2_f19, - varargin_3, varargin_4, &fxcc, &problem, &result); + varargin_3, varargin_4, &fxcc, &problem, result); func_evals++; if (fxcc < fv[fv.size(1) - 1]) { x_idx_1 = xcc.size(0); @@ -925,7 +924,7 @@ namespace RAT varargin_2_f3, varargin_2_f4, varargin_2_f5, varargin_2_f6, varargin_2_f14, varargin_2_f19, varargin_3, varargin_4, &fv[j + 1], &problem, - &result); + result); } func_evals += static_cast(n); @@ -976,10 +975,10 @@ namespace RAT } if (rt_remd_snf(itercount, varargin_3->updatePlotFreq) == 0.0) { - triggerEvent(result.f1, result.f3, result.f5, result.f6, problem.ssubs, - varargin_1->TF.data, varargin_1->TF.size, - varargin_1->resample, varargin_1->dataPresent, - varargin_1->modelType.data, varargin_1->modelType.size); + triggerEvent(result, problem.ssubs, varargin_1->TF.data, + varargin_1->TF.size, varargin_1->resample, + varargin_1->dataPresent, varargin_1->modelType.data, + varargin_1->modelType.size); } // OutputFcn and PlotFcns call diff --git a/RAT/fMinSearch.h b/RAT/fMinSearch.h index f75297aa..2e7b5a03 100644 --- a/RAT/fMinSearch.h +++ b/RAT/fMinSearch.h @@ -20,8 +20,9 @@ // Type Declarations namespace RAT { - struct j_struct_T; - struct h_struct_T; + struct c_struct_T; + struct k_struct_T; + struct i_struct_T; } // Function Declarations @@ -30,8 +31,8 @@ namespace RAT void fMinSearch(::coder::array &x, real_T options_MaxIter, real_T options_MaxFunEvals, real_T options_TolX, real_T options_TolFun, const char_T dis_data[], const int32_T - dis_size[2], const struct5_T *varargin_1, const ::coder::array< - cell_wrap_2, 2U> &varargin_2_f1, const ::coder::array< + dis_size[2], const c_struct_T *varargin_1, const ::coder:: + array &varargin_2_f1, const ::coder::array< cell_wrap_8, 2U> &varargin_2_f2, const ::coder::array< cell_wrap_2, 2U> &varargin_2_f3, const ::coder::array< cell_wrap_2, 2U> &varargin_2_f4, const ::coder::array< @@ -39,8 +40,8 @@ namespace RAT cell_wrap_8, 1U> &varargin_2_f6, const ::coder::array< cell_wrap_1, 2U> &varargin_2_f14, const ::coder::array< cell_wrap_8, 2U> &varargin_2_f19, const struct2_T *varargin_3, - const j_struct_T *varargin_4, real_T *fval, real_T *exitflag, - h_struct_T *output); + const k_struct_T *varargin_4, real_T *fval, real_T *exitflag, + i_struct_T *output); } #endif diff --git a/RAT/gelman.cpp b/RAT/gelman.cpp index 6f7b4834..6b830dd5 100644 --- a/RAT/gelman.cpp +++ b/RAT/gelman.cpp @@ -72,7 +72,7 @@ namespace RAT } } - void gelman(const ::coder::array &chain, const struct14_T + void gelman(const ::coder::array &chain, const struct13_T *DREAMPar, ::coder::array &R_stat) { ::coder::array r1; diff --git a/RAT/gelman.h b/RAT/gelman.h index fcea566f..db085b8d 100644 --- a/RAT/gelman.h +++ b/RAT/gelman.h @@ -19,13 +19,13 @@ // Type Declarations namespace RAT { - struct struct14_T; + struct struct13_T; } // Function Declarations namespace RAT { - void gelman(const ::coder::array &chain, const struct14_T + void gelman(const ::coder::array &chain, const struct13_T *DREAMPar, ::coder::array &R_stat); } diff --git a/RAT/groupLayersMod.cpp b/RAT/groupLayersMod.cpp index f8563ff7..c59325f3 100644 --- a/RAT/groupLayersMod.cpp +++ b/RAT/groupLayersMod.cpp @@ -152,8 +152,6 @@ namespace RAT } } - // problem.layers{i} = layers; - // problem.ssubs(i) = s_sub; if ((layers.size(0) != 0) && (layers.size(1) != 0)) { outLayers.set_size(layers.size(0), 3); loop_ub = layers.size(0); diff --git a/RAT/groupLayersModImaginary.cpp b/RAT/groupLayersModImaginary.cpp index 792e1ba0..ea722b9c 100644 --- a/RAT/groupLayersModImaginary.cpp +++ b/RAT/groupLayersModImaginary.cpp @@ -192,8 +192,6 @@ namespace RAT } } - // problem.layers{i} = layers; - // problem.ssubs(i) = s_sub; if ((layers.size(0) != 0) && (layers.size(1) != 0)) { outLayers.set_size(layers.size(0), 4); loop_ub = layers.size(0); diff --git a/RAT/initializeDREAM.cpp b/RAT/initializeDREAM.cpp index add103df..2f0dfffd 100644 --- a/RAT/initializeDREAM.cpp +++ b/RAT/initializeDREAM.cpp @@ -26,7 +26,7 @@ namespace RAT { static void binary_expand_op(::coder::array &in1, const ::coder:: array &in2, const ::coder::array &in3, const - struct14_T *in4); + struct13_T *in4); static void binary_expand_op(::coder::array &in1, const ::coder:: array &in2, const ::coder::array &in3, const ::coder:: array &in4); @@ -37,7 +37,7 @@ namespace RAT { static void binary_expand_op(::coder::array &in1, const ::coder:: array &in2, const ::coder::array &in3, const - struct14_T *in4) + struct13_T *in4) { ::coder::array b_in2; int32_T i; @@ -163,14 +163,14 @@ namespace RAT } } - void initializeDREAM(const struct14_T *DREAMPar, const ::coder::array &Par_info_min, const ::coder::array &Par_info_max, const char_T Par_info_boundhandling_data[], const int32_T Par_info_boundhandling_size[2], ::coder:: - array &chain, struct13_T *output, ::coder:: - array &log_L, const struct5_T - *ratInputs_problemDef, const cell_14 - *ratInputs_problemDefCells, const struct2_T + array &chain, struct12_T *output, ::coder:: + array &log_L, const c_struct_T + *ratInputs_problemStruct, const cell_11 + *ratInputs_problemCells, const struct2_T *ratInputs_controls, const ::coder::array &ratInputs_priors, ::coder::array &X, ::coder:: array &fx, ::coder::array &CR, @@ -272,11 +272,11 @@ namespace RAT Par_info_boundhandling_size); // Now evaluate the model ( = pdf ) and return fx - evaluateModel(x, DREAMPar, ratInputs_problemDef, ratInputs_problemDefCells, + evaluateModel(x, DREAMPar, ratInputs_problemStruct, ratInputs_problemCells, ratInputs_controls, fx); // Calculate the log-likelihood and log-prior of x (fx) - calcDensity(x, fx, DREAMPar, ratInputs_problemDef->fitLimits, + calcDensity(x, fx, DREAMPar, ratInputs_problemStruct->fitLimits, ratInputs_priors, log_L_x, log_PR_x); // Define starting x values, corresponding density, log densty and simulations (Xfx) diff --git a/RAT/initializeDREAM.h b/RAT/initializeDREAM.h index 1cf70066..4a6354d4 100644 --- a/RAT/initializeDREAM.h +++ b/RAT/initializeDREAM.h @@ -19,24 +19,24 @@ // Type Declarations namespace RAT { - struct struct14_T; struct struct13_T; - struct struct5_T; - struct cell_14; + struct struct12_T; + struct c_struct_T; + struct cell_11; struct struct2_T; } // Function Declarations namespace RAT { - void initializeDREAM(const struct14_T *DREAMPar, const ::coder::array &Par_info_min, const ::coder::array &Par_info_max, const char_T Par_info_boundhandling_data[], const int32_T Par_info_boundhandling_size[2], ::coder:: - array &chain, struct13_T *output, ::coder:: - array &log_L, const struct5_T - *ratInputs_problemDef, const cell_14 - *ratInputs_problemDefCells, const struct2_T + array &chain, struct12_T *output, ::coder:: + array &log_L, const c_struct_T + *ratInputs_problemStruct, const cell_11 + *ratInputs_problemCells, const struct2_T *ratInputs_controls, const ::coder::array &ratInputs_priors, ::coder::array &X, ::coder:: array &fx, ::coder::array &CR, diff --git a/RAT/lower.cpp b/RAT/lower.cpp index d1ccaaa3..573d2626 100644 --- a/RAT/lower.cpp +++ b/RAT/lower.cpp @@ -26,7 +26,7 @@ namespace RAT y_size[1] = x_size[1]; i = x_size[1]; for (int32_T k{0}; k < i; k++) { - y_data[k] = cv1[static_cast(x_data[k]) & 127]; + y_data[k] = cv[static_cast(x_data[k]) & 127]; } } } diff --git a/RAT/makeCell.cpp b/RAT/makeCell.cpp index 9d17458c..81cf1310 100644 --- a/RAT/makeCell.cpp +++ b/RAT/makeCell.cpp @@ -17,6 +17,33 @@ // Function Definitions namespace RAT { + void b_makeCell(real_T m, const real_T vals_data[], ::coder::array< + cell_wrap_22, 2U> &x) + { + int32_T i; + + // Creates a m by n cell array and initialise each cell with given + // value + // + // array = makeCell(5, 2, [1, 1]) + i = static_cast(m); + x.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + real_T d; + real_T d1; + real_T d2; + d = vals_data[0]; + d1 = vals_data[1]; + d2 = vals_data[2]; + for (int32_T j{0}; j < 2; j++) { + x[b_i + x.size(0) * j].f1.set_size(1, 3); + x[b_i + x.size(0) * j].f1[0] = d; + x[b_i + x.size(0) * j].f1[1] = d1; + x[b_i + x.size(0) * j].f1[2] = d2; + } + } + } + void b_makeCell(real_T m, const real_T vals_data[], ::coder::array &x) { @@ -152,8 +179,8 @@ namespace RAT x[49].f1[0] = 1.0; } - void makeCell(real_T m, const real_T vals_data[], ::coder::array &x) + void makeCell(real_T m, const real_T vals_data[], ::coder::array &x) { int32_T i; @@ -162,7 +189,7 @@ namespace RAT // // array = makeCell(5, 2, [1, 1]) i = static_cast(m); - x.set_size(i); + x.set_size(i, 1); for (int32_T b_i{0}; b_i < i; b_i++) { x[b_i].f1.set_size(1, 3); x[b_i].f1[0] = vals_data[0]; diff --git a/RAT/makeCell.h b/RAT/makeCell.h index 0ad4e9b6..84429f32 100644 --- a/RAT/makeCell.h +++ b/RAT/makeCell.h @@ -20,11 +20,13 @@ // Function Declarations namespace RAT { + void b_makeCell(real_T m, const real_T vals_data[], ::coder::array< + cell_wrap_22, 2U> &x); void b_makeCell(real_T m, const real_T vals_data[], ::coder::array &x); void makeCell(cell_wrap_8 x[50]); - void makeCell(real_T m, const real_T vals_data[], ::coder::array &x); + void makeCell(real_T m, const real_T vals_data[], ::coder::array &x); void makeCell(real_T m, const real_T vals_data[], ::coder::array &x); } diff --git a/RAT/makeEmptyBayesResultsStruct.cpp b/RAT/makeEmptyBayesResultsStruct.cpp index 1632c55a..e502ad91 100644 --- a/RAT/makeEmptyBayesResultsStruct.cpp +++ b/RAT/makeEmptyBayesResultsStruct.cpp @@ -20,101 +20,101 @@ // Function Declarations namespace RAT { - static void cast(const ::coder::array &t3_outlier, const - struct14_T *t3_DREAMPar, const struct15_T t3_Meas_info, const - ::coder::array &t3_AR, const ::coder::array< - real_T, 2U> &t3_R_stat, const ::coder::array - &t3_CR, struct13_T *r); - static void cast(const real_T t1_par95_data[], const int32_T t1_par95_size[2], - const real_T t1_par65_data[], const int32_T t1_par65_size[2], - const real_T t1_mean_data[], const int32_T t1_mean_size[2], :: - coder::array &t2_par95, ::coder::array - &t2_par65, ::coder::array &t2_mean); + static void cast(const ::coder::array &t2_outlier, const + struct13_T *t2_DREAMPar, const struct14_T t2_Meas_info, const + ::coder::array &t2_AR, const ::coder::array< + real_T, 2U> &t2_R_stat, const ::coder::array + &t2_CR, struct12_T *r); + static void cast(const real_T t0_par95_data[], const int32_T t0_par95_size[2], + const real_T t0_par65_data[], const int32_T t0_par65_size[2], + const real_T t0_mean_data[], const int32_T t0_mean_size[2], :: + coder::array &t1_par95, ::coder::array + &t1_par65, ::coder::array &t1_mean); } // Function Definitions namespace RAT { - static void cast(const ::coder::array &t3_outlier, const - struct14_T *t3_DREAMPar, const struct15_T t3_Meas_info, const - ::coder::array &t3_AR, const ::coder::array< - real_T, 2U> &t3_R_stat, const ::coder::array - &t3_CR, struct13_T *r) + static void cast(const ::coder::array &t2_outlier, const + struct13_T *t2_DREAMPar, const struct14_T t2_Meas_info, const + ::coder::array &t2_AR, const ::coder::array< + real_T, 2U> &t2_R_stat, const ::coder::array + &t2_CR, struct12_T *r) { int32_T b_loop_ub; int32_T loop_ub; - r->outlier.size[0] = t3_outlier.size(0); - r->outlier.size[1] = t3_outlier.size(1); - loop_ub = t3_outlier.size(1); + r->outlier.size[0] = t2_outlier.size(0); + r->outlier.size[1] = t2_outlier.size(1); + loop_ub = t2_outlier.size(1); for (int32_T i{0}; i < loop_ub; i++) { - b_loop_ub = t3_outlier.size(0); + b_loop_ub = t2_outlier.size(0); for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - r->outlier.data[i1 + r->outlier.size[0] * i] = t3_outlier[i1 + - t3_outlier.size(0) * i]; + r->outlier.data[i1 + r->outlier.size[0] * i] = t2_outlier[i1 + + t2_outlier.size(0) * i]; } } r->RunTime = 100.0; - r->DREAMPar = *t3_DREAMPar; - r->Meas_info = t3_Meas_info; + r->DREAMPar = *t2_DREAMPar; + r->Meas_info = t2_Meas_info; r->iteration = 0.0; r->iloc = 0.0; r->fx = 0.0; - r->AR.size[0] = t3_AR.size(0); - r->AR.size[1] = t3_AR.size(1); - loop_ub = t3_AR.size(1); + r->AR.size[0] = t2_AR.size(0); + r->AR.size[1] = t2_AR.size(1); + loop_ub = t2_AR.size(1); for (int32_T i{0}; i < loop_ub; i++) { - b_loop_ub = t3_AR.size(0); + b_loop_ub = t2_AR.size(0); for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - r->AR.data[i1 + r->AR.size[0] * i] = t3_AR[i1 + t3_AR.size(0) * i]; + r->AR.data[i1 + r->AR.size[0] * i] = t2_AR[i1 + t2_AR.size(0) * i]; } } - r->R_stat.set_size(t3_R_stat.size(0), t3_R_stat.size(1)); - loop_ub = t3_R_stat.size(1); + r->R_stat.set_size(t2_R_stat.size(0), t2_R_stat.size(1)); + loop_ub = t2_R_stat.size(1); for (int32_T i{0}; i < loop_ub; i++) { - b_loop_ub = t3_R_stat.size(0); + b_loop_ub = t2_R_stat.size(0); for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - r->R_stat[i1 + r->R_stat.size(0) * i] = t3_R_stat[i1 + t3_R_stat.size(0) + r->R_stat[i1 + r->R_stat.size(0) * i] = t2_R_stat[i1 + t2_R_stat.size(0) * i]; } } - r->CR.set_size(t3_CR.size(0), t3_CR.size(1)); - loop_ub = t3_CR.size(1); + r->CR.set_size(t2_CR.size(0), t2_CR.size(1)); + loop_ub = t2_CR.size(1); for (int32_T i{0}; i < loop_ub; i++) { - b_loop_ub = t3_CR.size(0); + b_loop_ub = t2_CR.size(0); for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - r->CR[i1 + r->CR.size(0) * i] = t3_CR[i1 + t3_CR.size(0) * i]; + r->CR[i1 + r->CR.size(0) * i] = t2_CR[i1 + t2_CR.size(0) * i]; } } } - static void cast(const real_T t1_par95_data[], const int32_T t1_par95_size[2], - const real_T t1_par65_data[], const int32_T t1_par65_size[2], - const real_T t1_mean_data[], const int32_T t1_mean_size[2], :: - coder::array &t2_par95, ::coder::array - &t2_par65, ::coder::array &t2_mean) + static void cast(const real_T t0_par95_data[], const int32_T t0_par95_size[2], + const real_T t0_par65_data[], const int32_T t0_par65_size[2], + const real_T t0_mean_data[], const int32_T t0_mean_size[2], :: + coder::array &t1_par95, ::coder::array + &t1_par65, ::coder::array &t1_mean) { int32_T loop_ub; - t2_par95.set_size(2, t1_par95_size[1]); - loop_ub = t1_par95_size[1]; + t1_par95.set_size(2, t0_par95_size[1]); + loop_ub = t0_par95_size[1]; for (int32_T i{0}; i < loop_ub; i++) { - t2_par95[2 * i] = t1_par95_data[2 * i]; - t2_par95[2 * i + 1] = t1_par95_data[2 * i + 1]; + t1_par95[2 * i] = t0_par95_data[2 * i]; + t1_par95[2 * i + 1] = t0_par95_data[2 * i + 1]; } - t2_par65.set_size(2, t1_par65_size[1]); - loop_ub = t1_par65_size[1]; + t1_par65.set_size(2, t0_par65_size[1]); + loop_ub = t0_par65_size[1]; for (int32_T i{0}; i < loop_ub; i++) { - t2_par65[2 * i] = t1_par65_data[2 * i]; - t2_par65[2 * i + 1] = t1_par65_data[2 * i + 1]; + t1_par65[2 * i] = t0_par65_data[2 * i]; + t1_par65[2 * i + 1] = t0_par65_data[2 * i + 1]; } - t2_mean.set_size(1, t1_mean_size[1]); - loop_ub = t1_mean_size[1]; + t1_mean.set_size(1, t0_mean_size[1]); + loop_ub = t0_mean_size[1]; for (int32_T i{0}; i < loop_ub; i++) { - t2_mean[i] = t1_mean_data[i]; + t1_mean[i] = t0_mean_data[i]; } } @@ -123,7 +123,7 @@ namespace RAT cell_wrap_8, 2U> &bayesResults_bestFitsMean_sld, real_T *bayesResults_bestFitsMean_chi, ::coder::array &bayesResults_bestFitsMean_data, ::coder::array - &bayesResults_predlims_refPredInts, ::coder::array + &bayesResults_predlims_refPredInts, ::coder::array &bayesResults_predlims_sldPredInts, ::coder::array &bayesResults_predlims_refXdata, ::coder::array &bayesResults_predlims_sldXdata, real_T @@ -132,34 +132,34 @@ namespace RAT &bayesResults_parConfInts_par95, ::coder::array &bayesResults_parConfInts_par65, ::coder::array &bayesResults_parConfInts_mean, ::coder::array - &bayesResults_bestPars, c_struct_T *bayesResults_bayesRes, ::coder::array< + &bayesResults_bestPars, b_struct_T *bayesResults_bayesRes, ::coder::array< real_T, 2U> &bayesResults_chain) { ::coder::array b_f1; + ::coder::array e_f1; ::coder::array g_f1; ::coder::array c_f1; ::coder::array d_f1; - ::coder::array e_f1; ::coder::array f1; ::coder::array f_f1; - ::coder::array t6_AR; - ::coder::array t6_CR; - ::coder::array t6_R_stat; - ::coder::array t6_outlier; + ::coder::array t5_AR; + ::coder::array t5_CR; + ::coder::array t5_R_stat; + ::coder::array t5_outlier; ::coder::array h_f1; - cell_wrap_15 r; - cell_wrap_15 r2; - cell_wrap_15 r3; - cell_wrap_17 r4; + cell_wrap_12 r; + cell_wrap_12 r2; + cell_wrap_14 r4; cell_wrap_9 r1; - struct14_T expl_temp; - struct15_T b_expl_temp; - real_T t7_par65_data[2000]; - real_T t7_par95_data[2000]; - real_T t7_mean_data[1000]; - int32_T t7_mean_size[2]; - int32_T t7_par65_size[2]; - int32_T t7_par95_size[2]; + cell_wrap_9 r3; + struct13_T expl_temp; + struct14_T b_expl_temp; + real_T t6_par65_data[2000]; + real_T t6_par95_data[2000]; + real_T t6_mean_data[1000]; + int32_T t6_mean_size[2]; + int32_T t6_par65_size[2]; + int32_T t6_par95_size[2]; int32_T i; // A function to make an empty container to hold the results of bayes @@ -219,8 +219,6 @@ namespace RAT // -------------------------------------------------------------------- // (2) bayesResults.predlims d_f1.set_size(i); - e_f1.set_size(i); - f_f1.set_size(i); for (int32_T b_i{0}; b_i < i; b_i++) { c_f1[b_i].f1.set_size(1, 3); c_f1[b_i].f1[0] = 1.0; @@ -230,10 +228,33 @@ namespace RAT d_f1[b_i].f1[0] = 1.0; d_f1[b_i].f1[d_f1[b_i].f1.size(0)] = 1.0; d_f1[b_i].f1[d_f1[b_i].f1.size(0) * 2] = 1.0; - e_f1[b_i].f1.set_size(1, 3); - e_f1[b_i].f1[0] = 1.0; - e_f1[b_i].f1[e_f1[b_i].f1.size(0)] = 1.0; - e_f1[b_i].f1[e_f1[b_i].f1.size(0) * 2] = 1.0; + } + + if (isDomains) { + e_f1.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + e_f1[b_i].f1.set_size(1, 3); + e_f1[b_i + e_f1.size(0)].f1.set_size(1, 3); + e_f1[b_i].f1[0] = 1.0; + e_f1[b_i + e_f1.size(0)].f1[0] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0)] = 1.0; + e_f1[b_i + e_f1.size(0)].f1[e_f1[b_i + e_f1.size(0)].f1.size(0)] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0) * 2] = 1.0; + e_f1[b_i + e_f1.size(0)].f1[e_f1[b_i + e_f1.size(0)].f1.size(0) * 2] = + 1.0; + } + } else { + e_f1.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + e_f1[b_i].f1.set_size(1, 3); + e_f1[b_i].f1[0] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0)] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0) * 2] = 1.0; + } + } + + f_f1.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { f_f1[b_i].f1.set_size(1, 3); f_f1[b_i].f1[0] = 1.0; f_f1[b_i].f1[f_f1[b_i].f1.size(0)] = 1.0; @@ -266,36 +287,36 @@ namespace RAT // ------------------------------------------------------------------ // (3) bayesResults.parConfInts - t7_par95_size[0] = 2; - t7_par95_size[1] = 1; - t7_par65_size[0] = 2; - t7_par65_size[1] = 1; - t7_mean_size[0] = 1; - t7_mean_size[1] = 1; - t7_mean_data[0] = 0.0; + t6_par95_size[0] = 2; + t6_par95_size[1] = 1; + t6_par65_size[0] = 2; + t6_par65_size[1] = 1; + t6_mean_size[0] = 1; + t6_mean_size[1] = 1; + t6_mean_data[0] = 0.0; // ------------------------------------------------------------------- // (4) bayesResults.bestPars // ------------------------------------------------------------------- // (5) bayesResults.bayesRes - t6_outlier.set_size(1, 2); - t6_AR.set_size(1, 2); - t6_R_stat.set_size(1, 2); - t6_CR.set_size(1, 2); + t5_outlier.set_size(1, 2); + t5_AR.set_size(1, 2); + t5_R_stat.set_size(1, 2); + t5_CR.set_size(1, 2); // Nested Sampler - t7_par95_data[0] = 0.0; - t7_par65_data[0] = 0.0; - t6_outlier[0] = 1.0; - t6_AR[0] = 0.0; - t6_R_stat[0] = 0.0; - t6_CR[0] = 0.0; - t7_par95_data[1] = 0.0; - t7_par65_data[1] = 0.0; - t6_outlier[t6_outlier.size(0)] = 1.0; - t6_AR[t6_AR.size(0)] = 0.0; - t6_R_stat[t6_R_stat.size(0)] = 0.0; - t6_CR[t6_CR.size(0)] = 0.0; + t6_par95_data[0] = 0.0; + t6_par65_data[0] = 0.0; + t5_outlier[0] = 1.0; + t5_AR[0] = 0.0; + t5_R_stat[0] = 0.0; + t5_CR[0] = 0.0; + t6_par95_data[1] = 0.0; + t6_par65_data[1] = 0.0; + t5_outlier[t5_outlier.size(0)] = 1.0; + t5_AR[t5_AR.size(0)] = 0.0; + t5_R_stat[t5_R_stat.size(0)] = 0.0; + t5_CR[t5_CR.size(0)] = 0.0; expl_temp.R.set_size(1, 1); expl_temp.R[0] = 0.0; expl_temp.save = false; @@ -322,7 +343,7 @@ namespace RAT expl_temp.d = 17.0; b_expl_temp.N = 0.0; b_expl_temp.Y = 0.0; - cast(t6_outlier, &expl_temp, b_expl_temp, t6_AR, t6_R_stat, t6_CR, + cast(t5_outlier, &expl_temp, b_expl_temp, t5_AR, t5_R_stat, t5_CR, &bayesResults_bayesRes->dreamOutput); // ------------------------------------------------------------------ @@ -338,16 +359,16 @@ namespace RAT h_f1.set_size(1); h_f1[0] = 0.0; r.f1 = d_f1; - r2.f1 = e_f1; - r3.f1 = f_f1; - r1.f1 = g_f1; + r1.f1 = e_f1; + r2.f1 = f_f1; + r3.f1 = g_f1; r4.f1 = h_f1; - coder::internal::structConstructorHelper(&r, &r2, &r3, &r1, &r4, + coder::internal::structConstructorHelper(&r, &r1, &r2, &r3, &r4, bayesResults_predlims_refPredInts, bayesResults_predlims_sldPredInts, bayesResults_predlims_refXdata, bayesResults_predlims_sldXdata, bayesResults_predlims_sampleChi_data, bayesResults_predlims_sampleChi_size); - cast(t7_par95_data, t7_par95_size, t7_par65_data, t7_par65_size, - t7_mean_data, t7_mean_size, bayesResults_parConfInts_par95, + cast(t6_par95_data, t6_par95_size, t6_par65_data, t6_par65_size, + t6_mean_data, t6_mean_size, bayesResults_parConfInts_par95, bayesResults_parConfInts_par65, bayesResults_parConfInts_mean); bayesResults_bestPars.set_size(1, 1); bayesResults_bestPars[0] = 1.0; @@ -377,7 +398,7 @@ namespace RAT &bayesResults_bestFitsMean_sld, real_T *bayesResults_bestFitsMean_chi, :: coder::array &bayesResults_bestFitsMean_data, ::coder:: array &bayesResults_predlims_refPredInts, ::coder::array< - cell_wrap_8, 1U> &bayesResults_predlims_sldPredInts, ::coder::array< + cell_wrap_8, 2U> &bayesResults_predlims_sldPredInts, ::coder::array< cell_wrap_8, 1U> &bayesResults_predlims_refXdata, ::coder::array &bayesResults_predlims_sldXdata, real_T bayesResults_predlims_sampleChi_data[], int32_T @@ -385,14 +406,14 @@ namespace RAT &bayesResults_parConfInts_par95, ::coder::array &bayesResults_parConfInts_par65, ::coder::array &bayesResults_parConfInts_mean, ::coder::array - &bayesResults_bestPars, c_struct_T *bayesResults_bayesRes, ::coder::array< + &bayesResults_bestPars, b_struct_T *bayesResults_bayesRes, ::coder::array< real_T, 2U> &bayesResults_chain) { ::coder::array b_f1; + ::coder::array e_f1; ::coder::array g_f1; ::coder::array c_f1; ::coder::array d_f1; - ::coder::array e_f1; ::coder::array f1; ::coder::array f_f1; ::coder::array t16_AR; @@ -401,13 +422,13 @@ namespace RAT ::coder::array t16_outlier; ::coder::array h_f1; ::coder::array t16_DREAMPar_R; - cell_wrap_15 r; - cell_wrap_15 r2; - cell_wrap_15 r3; - cell_wrap_17 r4; + cell_wrap_12 r; + cell_wrap_12 r2; + cell_wrap_14 r4; cell_wrap_9 r1; - struct14_T expl_temp; - struct15_T b_expl_temp; + cell_wrap_9 r3; + struct13_T expl_temp; + struct14_T b_expl_temp; real_T t17_par65_data[2000]; real_T t17_par95_data[2000]; real_T t17_mean_data[1000]; @@ -474,8 +495,6 @@ namespace RAT // -------------------------------------------------------------------- // (2) bayesResults.predlims d_f1.set_size(i); - e_f1.set_size(i); - f_f1.set_size(i); for (int32_T b_i{0}; b_i < i; b_i++) { c_f1[b_i].f1.set_size(1, 3); c_f1[b_i].f1[0] = 1.0; @@ -485,10 +504,33 @@ namespace RAT d_f1[b_i].f1[0] = 1.0; d_f1[b_i].f1[d_f1[b_i].f1.size(0)] = 1.0; d_f1[b_i].f1[d_f1[b_i].f1.size(0) * 2] = 1.0; - e_f1[b_i].f1.set_size(1, 3); - e_f1[b_i].f1[0] = 1.0; - e_f1[b_i].f1[e_f1[b_i].f1.size(0)] = 1.0; - e_f1[b_i].f1[e_f1[b_i].f1.size(0) * 2] = 1.0; + } + + if (isDomains) { + e_f1.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + e_f1[b_i].f1.set_size(1, 3); + e_f1[b_i + e_f1.size(0)].f1.set_size(1, 3); + e_f1[b_i].f1[0] = 1.0; + e_f1[b_i + e_f1.size(0)].f1[0] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0)] = 1.0; + e_f1[b_i + e_f1.size(0)].f1[e_f1[b_i + e_f1.size(0)].f1.size(0)] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0) * 2] = 1.0; + e_f1[b_i + e_f1.size(0)].f1[e_f1[b_i + e_f1.size(0)].f1.size(0) * 2] = + 1.0; + } + } else { + e_f1.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + e_f1[b_i].f1.set_size(1, 3); + e_f1[b_i].f1[0] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0)] = 1.0; + e_f1[b_i].f1[e_f1[b_i].f1.size(0) * 2] = 1.0; + } + } + + f_f1.set_size(i); + for (int32_T b_i{0}; b_i < i; b_i++) { f_f1[b_i].f1.set_size(1, 3); f_f1[b_i].f1[0] = 1.0; f_f1[b_i].f1[f_f1[b_i].f1.size(0)] = 1.0; @@ -609,11 +651,11 @@ namespace RAT h_f1.set_size(1); h_f1[0] = 0.0; r.f1 = d_f1; - r2.f1 = e_f1; - r3.f1 = f_f1; - r1.f1 = g_f1; + r1.f1 = e_f1; + r2.f1 = f_f1; + r3.f1 = g_f1; r4.f1 = h_f1; - coder::internal::structConstructorHelper(&r, &r2, &r3, &r1, &r4, + coder::internal::structConstructorHelper(&r, &r1, &r2, &r3, &r4, bayesResults_predlims_refPredInts, bayesResults_predlims_sldPredInts, bayesResults_predlims_refXdata, bayesResults_predlims_sldXdata, bayesResults_predlims_sampleChi_data, bayesResults_predlims_sampleChi_size); diff --git a/RAT/makeEmptyBayesResultsStruct.h b/RAT/makeEmptyBayesResultsStruct.h index c08b88ce..d9e8566f 100644 --- a/RAT/makeEmptyBayesResultsStruct.h +++ b/RAT/makeEmptyBayesResultsStruct.h @@ -20,7 +20,7 @@ // Type Declarations namespace RAT { - struct c_struct_T; + struct b_struct_T; } // Function Declarations @@ -31,7 +31,7 @@ namespace RAT cell_wrap_8, 2U> &bayesResults_bestFitsMean_sld, real_T *bayesResults_bestFitsMean_chi, ::coder::array &bayesResults_bestFitsMean_data, ::coder::array - &bayesResults_predlims_refPredInts, ::coder::array + &bayesResults_predlims_refPredInts, ::coder::array &bayesResults_predlims_sldPredInts, ::coder::array &bayesResults_predlims_refXdata, ::coder::array &bayesResults_predlims_sldXdata, real_T @@ -40,7 +40,7 @@ namespace RAT &bayesResults_parConfInts_par95, ::coder::array &bayesResults_parConfInts_par65, ::coder::array &bayesResults_parConfInts_mean, ::coder::array - &bayesResults_bestPars, c_struct_T *bayesResults_bayesRes, ::coder::array< + &bayesResults_bestPars, b_struct_T *bayesResults_bayesRes, ::coder::array< real_T, 2U> &bayesResults_chain); void makeEmptyBayesResultsStruct(real_T nContrasts, boolean_T isDomains, real_T nChains, ::coder::array @@ -48,7 +48,7 @@ namespace RAT &bayesResults_bestFitsMean_sld, real_T *bayesResults_bestFitsMean_chi, :: coder::array &bayesResults_bestFitsMean_data, ::coder:: array &bayesResults_predlims_refPredInts, ::coder::array< - cell_wrap_8, 1U> &bayesResults_predlims_sldPredInts, ::coder::array< + cell_wrap_8, 2U> &bayesResults_predlims_sldPredInts, ::coder::array< cell_wrap_8, 1U> &bayesResults_predlims_refXdata, ::coder::array &bayesResults_predlims_sldXdata, real_T bayesResults_predlims_sampleChi_data[], int32_T @@ -56,7 +56,7 @@ namespace RAT &bayesResults_parConfInts_par95, ::coder::array &bayesResults_parConfInts_par65, ::coder::array &bayesResults_parConfInts_mean, ::coder::array - &bayesResults_bestPars, c_struct_T *bayesResults_bayesRes, ::coder::array< + &bayesResults_bestPars, b_struct_T *bayesResults_bayesRes, ::coder::array< real_T, 2U> &bayesResults_chain); } diff --git a/RAT/metropolisRule.cpp b/RAT/metropolisRule.cpp index 5539caec..d98517fd 100644 --- a/RAT/metropolisRule.cpp +++ b/RAT/metropolisRule.cpp @@ -95,7 +95,7 @@ namespace RAT } } - void metropolisRule(const struct14_T *DREAMPar, const ::coder::array &log_L_xnew, const ::coder::array &log_PR_xnew, const ::coder::array &log_L_xold, const ::coder::array &log_PR_xold, ::coder:: diff --git a/RAT/metropolisRule.h b/RAT/metropolisRule.h index f5d6ffc3..845cc8cd 100644 --- a/RAT/metropolisRule.h +++ b/RAT/metropolisRule.h @@ -19,13 +19,13 @@ // Type Declarations namespace RAT { - struct struct14_T; + struct struct13_T; } // Function Declarations namespace RAT { - void metropolisRule(const struct14_T *DREAMPar, const ::coder::array &log_L_xnew, const ::coder::array &log_PR_xnew, const ::coder::array &log_L_xold, const ::coder::array &log_PR_xold, ::coder:: diff --git a/RAT/nestedSampler.cpp b/RAT/nestedSampler.cpp index 92b74b32..8c16065e 100644 --- a/RAT/nestedSampler.cpp +++ b/RAT/nestedSampler.cpp @@ -45,8 +45,8 @@ // Function Definitions namespace RAT { - void nestedSampler(const struct5_T *data_f1, const struct2_T *data_f2, const - cell_14 *data_f4, real_T Nlive, real_T Nmcmc, real_T + void nestedSampler(const c_struct_T *data_f1, const struct2_T *data_f2, const + cell_11 *data_f4, real_T Nlive, real_T Nmcmc, real_T tolerance, const ::coder::array &prior, real_T * logZ, ::coder::array &nest_samples, ::coder:: array &post_samples, real_T *H) diff --git a/RAT/nestedSampler.h b/RAT/nestedSampler.h index 5c7d5260..b0d629d4 100644 --- a/RAT/nestedSampler.h +++ b/RAT/nestedSampler.h @@ -19,16 +19,16 @@ // Type Declarations namespace RAT { - struct struct5_T; + struct c_struct_T; struct struct2_T; - struct cell_14; + struct cell_11; } // Function Declarations namespace RAT { - void nestedSampler(const struct5_T *data_f1, const struct2_T *data_f2, const - cell_14 *data_f4, real_T Nlive, real_T Nmcmc, real_T + void nestedSampler(const c_struct_T *data_f1, const struct2_T *data_f2, const + cell_11 *data_f4, real_T Nlive, real_T Nmcmc, real_T tolerance, const ::coder::array &prior, real_T * logZ, ::coder::array &nest_samples, ::coder:: array &post_samples, real_T *H); diff --git a/RAT/nsIntraFun.cpp b/RAT/nsIntraFun.cpp index 2c78f5c0..007efcec 100644 --- a/RAT/nsIntraFun.cpp +++ b/RAT/nsIntraFun.cpp @@ -20,54 +20,56 @@ // Function Definitions namespace RAT { - real_T nsIntraFun(const struct5_T *data_f1, const struct2_T *data_f2, const - cell_14 *data_f4, const ::coder::array &p) + real_T nsIntraFun(const c_struct_T *data_f1, const struct2_T *data_f2, const + cell_11 *data_f4, const ::coder::array &p) { - cell_13 a__1; - struct5_T problemDef; - struct_T b_problemDef; + c_struct_T problemStruct; + cell_wrap_9 a__1[6]; + d_struct_T b_problemStruct; int32_T loop_ub; - problemDef = *data_f1; + problemStruct = *data_f1; // Removed use of cells.... - problemDef.fitParams.set_size(1, p.size(1)); + problemStruct.fitParams.set_size(1, p.size(1)); loop_ub = p.size(1); for (int32_T i{0}; i < loop_ub; i++) { - problemDef.fitParams[problemDef.fitParams.size(0) * i] = p[i]; + problemStruct.fitParams[problemStruct.fitParams.size(0) * i] = p[i]; } - unpackParams(&problemDef, data_f2->checks.fitParam, + unpackParams(&problemStruct, data_f2->checks.fitParam, data_f2->checks.fitBackgroundParam, data_f2->checks.fitQzshift, data_f2->checks.fitScalefactor, data_f2->checks.fitBulkIn, data_f2->checks.fitBulkOut, data_f2->checks.fitResolutionParam, data_f2->checks.fitDomainRatio); - reflectivityCalculation(&problemDef, data_f4, data_f2, &b_problemDef, &a__1); - return -b_problemDef.calculations.sumChi / 2.0; + reflectivityCalculation(&problemStruct, data_f4, data_f2, &b_problemStruct, + a__1); + return -b_problemStruct.calculations.sumChi / 2.0; } - real_T nsIntraFun(const struct5_T *data_f1, const struct2_T *data_f2, const - cell_14 *data_f4, const ::coder::array &p) + real_T nsIntraFun(const c_struct_T *data_f1, const struct2_T *data_f2, const + cell_11 *data_f4, const ::coder::array &p) { - cell_13 a__1; - struct5_T problemDef; - struct_T b_problemDef; + c_struct_T problemStruct; + cell_wrap_9 a__1[6]; + d_struct_T b_problemStruct; int32_T p_idx_0; - problemDef = *data_f1; + problemStruct = *data_f1; // Removed use of cells.... p_idx_0 = p.size(0); - problemDef.fitParams.set_size(p.size(0), 1); + problemStruct.fitParams.set_size(p.size(0), 1); for (int32_T i{0}; i < p_idx_0; i++) { - problemDef.fitParams[i] = p[i]; + problemStruct.fitParams[i] = p[i]; } - unpackParams(&problemDef, data_f2->checks.fitParam, + unpackParams(&problemStruct, data_f2->checks.fitParam, data_f2->checks.fitBackgroundParam, data_f2->checks.fitQzshift, data_f2->checks.fitScalefactor, data_f2->checks.fitBulkIn, data_f2->checks.fitBulkOut, data_f2->checks.fitResolutionParam, data_f2->checks.fitDomainRatio); - reflectivityCalculation(&problemDef, data_f4, data_f2, &b_problemDef, &a__1); - return -b_problemDef.calculations.sumChi / 2.0; + reflectivityCalculation(&problemStruct, data_f4, data_f2, &b_problemStruct, + a__1); + return -b_problemStruct.calculations.sumChi / 2.0; } } diff --git a/RAT/nsIntraFun.h b/RAT/nsIntraFun.h index 2b1bc6b8..f26f8ebf 100644 --- a/RAT/nsIntraFun.h +++ b/RAT/nsIntraFun.h @@ -19,18 +19,18 @@ // Type Declarations namespace RAT { - struct struct5_T; + struct c_struct_T; struct struct2_T; - struct cell_14; + struct cell_11; } // Function Declarations namespace RAT { - real_T nsIntraFun(const struct5_T *data_f1, const struct2_T *data_f2, const - cell_14 *data_f4, const ::coder::array &p); - real_T nsIntraFun(const struct5_T *data_f1, const struct2_T *data_f2, const - cell_14 *data_f4, const ::coder::array &p); + real_T nsIntraFun(const c_struct_T *data_f1, const struct2_T *data_f2, const + cell_11 *data_f4, const ::coder::array &p); + real_T nsIntraFun(const c_struct_T *data_f1, const struct2_T *data_f2, const + cell_11 *data_f4, const ::coder::array &p); } #endif diff --git a/RAT/packParams.cpp b/RAT/packParams.cpp index 9bcd101f..2d12d0a4 100644 --- a/RAT/packParams.cpp +++ b/RAT/packParams.cpp @@ -10,6 +10,7 @@ // Include files #include "packParams.h" +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rt_nonfinite.h" #include "sum.h" @@ -18,15 +19,15 @@ // Function Definitions namespace RAT { - void packParams(struct5_T *problemDef, const ::coder::array - &problemDefCells_f7, const ::coder::array - &problemDefCells_f8, const ::coder::array - &problemDefCells_f9, const ::coder::array - &problemDefCells_f10, const ::coder::array - &problemDefCells_f11, const ::coder::array - &problemDefCells_f12, const ::coder::array - &problemDefCells_f13, const ::coder::array - &problemDefCells_f20, const struct1_T *limits, const struct3_T + void packParams(c_struct_T *problemStruct, const ::coder::array &problemCells_f7, const ::coder::array + &problemCells_f8, const ::coder::array + &problemCells_f9, const ::coder::array + &problemCells_f10, const ::coder::array + &problemCells_f11, const ::coder::array + &problemCells_f12, const ::coder::array + &problemCells_f13, const ::coder::array + &problemCells_f20, const struct1_T *limits, const struct3_T *checks, ::coder::array &fitNames) { ::coder::array fitLimits; @@ -50,21 +51,22 @@ namespace RAT (checks->fitBulkIn)) + coder::sum(checks->fitBulkOut)) + coder::sum(checks->fitResolutionParam)) + coder::sum (checks->fitDomainRatio); - numberOfTotal = ((((((problemDef->params.size(1) + - problemDef->backgroundParams.size(1)) + - problemDef->scalefactors.size(1)) + - problemDef->qzshifts.size(1)) + problemDef->bulkIn.size - (1)) + problemDef->bulkOut.size(1)) + - problemDef->resolutionParams.size(1)) + - problemDef->domainRatio.size(1); - fitParams.set_size(problemDef->fitParams.size(0), problemDef->fitParams.size - (1)); - loop_ub = problemDef->fitParams.size(1); + numberOfTotal = ((((((problemStruct->params.size(1) + + problemStruct->backgroundParams.size(1)) + + problemStruct->scalefactors.size(1)) + + problemStruct->qzshifts.size(1)) + + problemStruct->bulkIn.size(1)) + + problemStruct->bulkOut.size(1)) + + problemStruct->resolutionParams.size(1)) + + problemStruct->domainRatio.size(1); + fitParams.set_size(problemStruct->fitParams.size(0), + problemStruct->fitParams.size(1)); + loop_ub = problemStruct->fitParams.size(1); for (i = 0; i < loop_ub; i++) { - b_loop_ub = problemDef->fitParams.size(0); + b_loop_ub = problemStruct->fitParams.size(0); for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - fitParams[i1 + fitParams.size(0) * i] = problemDef->fitParams[i1 + - problemDef->fitParams.size(0) * i]; + fitParams[i1 + fitParams.size(0) * i] = problemStruct->fitParams[i1 + + problemStruct->fitParams.size(0) * i]; } } @@ -89,7 +91,7 @@ namespace RAT } } - // limits = problemDef.limits; + // limits = problemStruct.limits; fitNames.set_size(loop_ub); for (int32_T b_i{0}; b_i < loop_ub; b_i++) { fitNames[b_i].f1.set_size(1, 0); @@ -100,20 +102,20 @@ namespace RAT i = checks->fitParam.size(1); for (int32_T n{0}; n < i; n++) { if (checks->fitParam[n] == 1.0) { - fitParams[fitCounter] = problemDef->params[n]; + fitParams[fitCounter] = problemStruct->params[n]; fitLimits[fitCounter] = limits->param[n]; fitLimits[fitCounter + fitLimits.size(0)] = limits->param[n + limits->param.size(0)]; - loop_ub = problemDefCells_f7[n].f1.size(1); - fitNames[fitCounter].f1.set_size(1, - problemDefCells_f7[problemDefCells_f7.size(0) * n].f1.size(1)); + loop_ub = problemCells_f7[n].f1.size(1); + fitNames[fitCounter].f1.set_size(1, problemCells_f7[problemCells_f7.size + (0) * n].f1.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { - fitNames[fitCounter].f1[i1] = problemDefCells_f7[n].f1[i1]; + fitNames[fitCounter].f1[i1] = problemCells_f7[n].f1[i1]; } fitCounter++; } else { - otherParams[otherCounter] = problemDef->params[n]; + otherParams[otherCounter] = problemStruct->params[n]; otherLimits[otherCounter] = limits->param[n]; otherLimits[otherCounter + otherLimits.size(0)] = limits->param[n + limits->param.size(0)]; @@ -125,20 +127,20 @@ namespace RAT i = checks->fitBackgroundParam.size(1); for (int32_T n{0}; n < i; n++) { if (checks->fitBackgroundParam[n] == 1.0) { - fitParams[fitCounter] = problemDef->backgroundParams[n]; + fitParams[fitCounter] = problemStruct->backgroundParams[n]; fitLimits[fitCounter] = limits->backgroundParam[n]; fitLimits[fitCounter + fitLimits.size(0)] = limits->backgroundParam[n + limits->backgroundParam.size(0)]; - loop_ub = problemDefCells_f8[n].f1.size(1); - fitNames[fitCounter].f1.set_size(1, - problemDefCells_f8[problemDefCells_f8.size(0) * n].f1.size(1)); + loop_ub = problemCells_f8[n].f1.size(1); + fitNames[fitCounter].f1.set_size(1, problemCells_f8[problemCells_f8.size + (0) * n].f1.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { - fitNames[fitCounter].f1[i1] = problemDefCells_f8[n].f1[i1]; + fitNames[fitCounter].f1[i1] = problemCells_f8[n].f1[i1]; } fitCounter++; } else { - otherParams[otherCounter] = problemDef->backgroundParams[n]; + otherParams[otherCounter] = problemStruct->backgroundParams[n]; otherLimits[otherCounter] = limits->backgroundParam[n]; otherLimits[otherCounter + otherLimits.size(0)] = limits->backgroundParam[n + limits->backgroundParam.size(0)]; @@ -150,20 +152,20 @@ namespace RAT i = checks->fitScalefactor.size(1); for (int32_T n{0}; n < i; n++) { if (checks->fitScalefactor[n] == 1.0) { - fitParams[fitCounter] = problemDef->scalefactors[n]; + fitParams[fitCounter] = problemStruct->scalefactors[n]; fitLimits[fitCounter] = limits->scalefactor[n]; fitLimits[fitCounter + fitLimits.size(0)] = limits->scalefactor[n + limits->scalefactor.size(0)]; - loop_ub = problemDefCells_f9[n].f1.size(1); - fitNames[fitCounter].f1.set_size(1, - problemDefCells_f9[problemDefCells_f9.size(0) * n].f1.size(1)); + loop_ub = problemCells_f9[n].f1.size(1); + fitNames[fitCounter].f1.set_size(1, problemCells_f9[problemCells_f9.size + (0) * n].f1.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { - fitNames[fitCounter].f1[i1] = problemDefCells_f9[n].f1[i1]; + fitNames[fitCounter].f1[i1] = problemCells_f9[n].f1[i1]; } fitCounter++; } else { - otherParams[otherCounter] = problemDef->scalefactors[n]; + otherParams[otherCounter] = problemStruct->scalefactors[n]; otherLimits[otherCounter] = limits->scalefactor[n]; otherLimits[otherCounter + otherLimits.size(0)] = limits->scalefactor[n + limits->scalefactor.size(0)]; @@ -175,20 +177,20 @@ namespace RAT i = checks->fitQzshift.size(1); for (int32_T n{0}; n < i; n++) { if (checks->fitQzshift[n] == 1.0) { - fitParams[fitCounter] = problemDef->qzshifts[n]; + fitParams[fitCounter] = problemStruct->qzshifts[n]; fitLimits[fitCounter] = limits->qzshift[n]; fitLimits[fitCounter + fitLimits.size(0)] = limits->qzshift[n + limits->qzshift.size(0)]; - loop_ub = problemDefCells_f10[n].f1.size(1); + loop_ub = problemCells_f10[n].f1.size(1); fitNames[fitCounter].f1.set_size(1, - problemDefCells_f10[problemDefCells_f10.size(0) * n].f1.size(1)); + problemCells_f10[problemCells_f10.size(0) * n].f1.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { - fitNames[fitCounter].f1[i1] = problemDefCells_f10[n].f1[i1]; + fitNames[fitCounter].f1[i1] = problemCells_f10[n].f1[i1]; } fitCounter++; } else { - otherParams[otherCounter] = problemDef->qzshifts[n]; + otherParams[otherCounter] = problemStruct->qzshifts[n]; otherLimits[otherCounter] = limits->qzshift[n]; otherLimits[otherCounter + otherLimits.size(0)] = limits->qzshift[n + limits->qzshift.size(0)]; @@ -200,20 +202,20 @@ namespace RAT i = checks->fitBulkIn.size(1); for (int32_T n{0}; n < i; n++) { if (checks->fitBulkIn[n] == 1.0) { - fitParams[fitCounter] = problemDef->bulkIn[n]; + fitParams[fitCounter] = problemStruct->bulkIn[n]; fitLimits[fitCounter] = limits->bulkIn[n]; fitLimits[fitCounter + fitLimits.size(0)] = limits->bulkIn[n + limits->bulkIn.size(0)]; - loop_ub = problemDefCells_f11[n].f1.size(1); + loop_ub = problemCells_f11[n].f1.size(1); fitNames[fitCounter].f1.set_size(1, - problemDefCells_f11[problemDefCells_f11.size(0) * n].f1.size(1)); + problemCells_f11[problemCells_f11.size(0) * n].f1.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { - fitNames[fitCounter].f1[i1] = problemDefCells_f11[n].f1[i1]; + fitNames[fitCounter].f1[i1] = problemCells_f11[n].f1[i1]; } fitCounter++; } else { - otherParams[otherCounter] = problemDef->bulkIn[n]; + otherParams[otherCounter] = problemStruct->bulkIn[n]; otherLimits[otherCounter] = limits->bulkIn[n]; otherLimits[otherCounter + otherLimits.size(0)] = limits->bulkIn[n + limits->bulkIn.size(0)]; @@ -225,20 +227,20 @@ namespace RAT i = checks->fitBulkOut.size(1); for (int32_T n{0}; n < i; n++) { if (checks->fitBulkOut[n] == 1.0) { - fitParams[fitCounter] = problemDef->bulkOut[n]; + fitParams[fitCounter] = problemStruct->bulkOut[n]; fitLimits[fitCounter] = limits->bulkOut[n]; fitLimits[fitCounter + fitLimits.size(0)] = limits->bulkOut[n + limits->bulkOut.size(0)]; - loop_ub = problemDefCells_f12[n].f1.size(1); + loop_ub = problemCells_f12[n].f1.size(1); fitNames[fitCounter].f1.set_size(1, - problemDefCells_f12[problemDefCells_f12.size(0) * n].f1.size(1)); + problemCells_f12[problemCells_f12.size(0) * n].f1.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { - fitNames[fitCounter].f1[i1] = problemDefCells_f12[n].f1[i1]; + fitNames[fitCounter].f1[i1] = problemCells_f12[n].f1[i1]; } fitCounter++; } else { - otherParams[otherCounter] = problemDef->bulkOut[n]; + otherParams[otherCounter] = problemStruct->bulkOut[n]; otherLimits[otherCounter] = limits->bulkOut[n]; otherLimits[otherCounter + otherLimits.size(0)] = limits->bulkOut[n + limits->bulkOut.size(0)]; @@ -250,20 +252,20 @@ namespace RAT i = checks->fitResolutionParam.size(1); for (int32_T n{0}; n < i; n++) { if (checks->fitResolutionParam[n] == 1.0) { - fitParams[fitCounter] = problemDef->resolutionParams[n]; + fitParams[fitCounter] = problemStruct->resolutionParams[n]; fitLimits[fitCounter] = limits->resolutionParam[n]; fitLimits[fitCounter + fitLimits.size(0)] = limits->resolutionParam[n + limits->resolutionParam.size(0)]; - loop_ub = problemDefCells_f13[n].f1.size(1); + loop_ub = problemCells_f13[n].f1.size(1); fitNames[fitCounter].f1.set_size(1, - problemDefCells_f13[problemDefCells_f13.size(0) * n].f1.size(1)); + problemCells_f13[problemCells_f13.size(0) * n].f1.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { - fitNames[fitCounter].f1[i1] = problemDefCells_f13[n].f1[i1]; + fitNames[fitCounter].f1[i1] = problemCells_f13[n].f1[i1]; } fitCounter++; } else { - otherParams[otherCounter] = problemDef->resolutionParams[n]; + otherParams[otherCounter] = problemStruct->resolutionParams[n]; otherLimits[otherCounter] = limits->resolutionParam[n]; otherLimits[otherCounter + otherLimits.size(0)] = limits->resolutionParam[n + limits->resolutionParam.size(0)]; @@ -275,20 +277,20 @@ namespace RAT i = checks->fitDomainRatio.size(1); for (int32_T n{0}; n < i; n++) { if (checks->fitDomainRatio[n] == 1.0) { - fitParams[fitCounter] = problemDef->domainRatio[n]; + fitParams[fitCounter] = problemStruct->domainRatio[n]; fitLimits[fitCounter] = limits->domainRatio[n]; fitLimits[fitCounter + fitLimits.size(0)] = limits->domainRatio[n + limits->domainRatio.size(0)]; - loop_ub = problemDefCells_f20[n].f1.size(1); + loop_ub = problemCells_f20[n].f1.size(1); fitNames[fitCounter].f1.set_size(1, - problemDefCells_f20[problemDefCells_f20.size(0) * n].f1.size(1)); + problemCells_f20[problemCells_f20.size(0) * n].f1.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { - fitNames[fitCounter].f1[i1] = problemDefCells_f20[n].f1[i1]; + fitNames[fitCounter].f1[i1] = problemCells_f20[n].f1[i1]; } fitCounter++; } else { - otherParams[otherCounter] = problemDef->domainRatio[n]; + otherParams[otherCounter] = problemStruct->domainRatio[n]; otherLimits[otherCounter] = limits->domainRatio[n]; otherLimits[otherCounter + otherLimits.size(0)] = limits->domainRatio[n + limits->domainRatio.size(0)]; @@ -296,34 +298,34 @@ namespace RAT } } - problemDef->fitParams.set_size(fitParams.size(0), fitParams.size(1)); + problemStruct->fitParams.set_size(fitParams.size(0), fitParams.size(1)); loop_ub = fitParams.size(1); for (i = 0; i < loop_ub; i++) { b_loop_ub = fitParams.size(0); for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - problemDef->fitParams[i1 + problemDef->fitParams.size(0) * i] = + problemStruct->fitParams[i1 + problemStruct->fitParams.size(0) * i] = fitParams[i1 + fitParams.size(0) * i]; } } b_loop_ub = otherParams.size(0); - problemDef->otherParams.set_size(otherParams.size(0), 1); + problemStruct->otherParams.set_size(otherParams.size(0), 1); for (i = 0; i < b_loop_ub; i++) { - problemDef->otherParams[i] = otherParams[i]; + problemStruct->otherParams[i] = otherParams[i]; } - problemDef->fitLimits.set_size(fitLimits.size(0), 2); - problemDef->otherLimits.set_size(otherLimits.size(0), 2); + problemStruct->fitLimits.set_size(fitLimits.size(0), 2); + problemStruct->otherLimits.set_size(otherLimits.size(0), 2); loop_ub = fitLimits.size(0); b_loop_ub = otherLimits.size(0); for (i = 0; i < 2; i++) { for (int32_T i1{0}; i1 < loop_ub; i1++) { - problemDef->fitLimits[i1 + problemDef->fitLimits.size(0) * i] = + problemStruct->fitLimits[i1 + problemStruct->fitLimits.size(0) * i] = fitLimits[i1 + fitLimits.size(0) * i]; } for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - problemDef->otherLimits[i1 + problemDef->otherLimits.size(0) * i] = + problemStruct->otherLimits[i1 + problemStruct->otherLimits.size(0) * i] = otherLimits[i1 + otherLimits.size(0) * i]; } } diff --git a/RAT/packParams.h b/RAT/packParams.h index a832444e..7798f997 100644 --- a/RAT/packParams.h +++ b/RAT/packParams.h @@ -17,18 +17,24 @@ #include #include +// Type Declarations +namespace RAT +{ + struct c_struct_T; +} + // Function Declarations namespace RAT { - void packParams(struct5_T *problemDef, const ::coder::array - &problemDefCells_f7, const ::coder::array - &problemDefCells_f8, const ::coder::array - &problemDefCells_f9, const ::coder::array - &problemDefCells_f10, const ::coder::array - &problemDefCells_f11, const ::coder::array - &problemDefCells_f12, const ::coder::array - &problemDefCells_f13, const ::coder::array - &problemDefCells_f20, const struct1_T *limits, const struct3_T + void packParams(c_struct_T *problemStruct, const ::coder::array &problemCells_f7, const ::coder::array + &problemCells_f8, const ::coder::array + &problemCells_f9, const ::coder::array + &problemCells_f10, const ::coder::array + &problemCells_f11, const ::coder::array + &problemCells_f12, const ::coder::array + &problemCells_f13, const ::coder::array + &problemCells_f20, const struct1_T *limits, const struct3_T *checks, ::coder::array &fitNames); } diff --git a/RAT/parallelContrasts.cpp b/RAT/parallelContrasts.cpp index 3b55d863..15007351 100644 --- a/RAT/parallelContrasts.cpp +++ b/RAT/parallelContrasts.cpp @@ -29,19 +29,19 @@ namespace RAT { namespace standardLayers { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) { - ::coder::array outParameterisedLayers; + ::coder::array outParameterisedLayers; ::coder::array reflect; ::coder::array resampledLayers; ::coder::array shiftedDat; @@ -82,7 +82,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -92,41 +92,46 @@ namespace RAT // * layersDetails: Master array of all available layers. // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); + // Extract individual parameters from problemStruct + // Extract individual parameters from problem + nParams = problemStruct->params.size(1); calcSld = controls->calcSldDuringFit; - useImaginary = problemDef->useImaginary; + useImaginary = problemStruct->useImaginary; // Allocate the memory for the output arrays before the main loop backgroundParams.set_size(static_cast - (problemDef->numberOfContrasts)); + (problemStruct->numberOfContrasts)); // end memory allocation. // First we need to allocate the absolute values of the input // parameters to all the layers in the layers list. This only needs // to be done once, and so is done outside the contrasts loop - allocateParamsToLayers(problemDef->params, problemDefCells->f6, + allocateParamsToLayers(problemStruct->params, problemCells->f6, outParameterisedLayers); // Resample parameters if required // Loop over all the contrasts - outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); - sldProfiles.set_size(static_cast(problemDef->numberOfContrasts)); - reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); - simulation.set_size(static_cast(problemDef->numberOfContrasts)); - shiftedData.set_size(static_cast(problemDef->numberOfContrasts)); - layerSlds.set_size(static_cast(problemDef->numberOfContrasts)); - chis.set_size(static_cast(problemDef->numberOfContrasts)); - qzshifts.set_size(static_cast(problemDef->numberOfContrasts)); - scalefactors.set_size(static_cast(problemDef->numberOfContrasts)); - bulkIns.set_size(static_cast(problemDef->numberOfContrasts)); - bulkOuts.set_size(static_cast(problemDef->numberOfContrasts)); + outSsubs.set_size(static_cast(problemStruct->numberOfContrasts)); + sldProfiles.set_size(static_cast + (problemStruct->numberOfContrasts)); + reflectivity.set_size(static_cast + (problemStruct->numberOfContrasts)); + simulation.set_size(static_cast + (problemStruct->numberOfContrasts)); + shiftedData.set_size(static_cast + (problemStruct->numberOfContrasts)); + layerSlds.set_size(static_cast(problemStruct->numberOfContrasts)); + chis.set_size(static_cast(problemStruct->numberOfContrasts)); + qzshifts.set_size(static_cast(problemStruct->numberOfContrasts)); + scalefactors.set_size(static_cast + (problemStruct->numberOfContrasts)); + bulkIns.set_size(static_cast(problemStruct->numberOfContrasts)); + bulkOuts.set_size(static_cast(problemStruct->numberOfContrasts)); resolutionParams.set_size(static_cast - (problemDef->numberOfContrasts)); - allRoughs.set_size(static_cast(problemDef->numberOfContrasts)); - allLayers.set_size(static_cast(problemDef->numberOfContrasts)); - ub_loop = static_cast(problemDef->numberOfContrasts) - 1; + (problemStruct->numberOfContrasts)); + allRoughs.set_size(static_cast(problemStruct->numberOfContrasts)); + allLayers.set_size(static_cast(problemStruct->numberOfContrasts)); + ub_loop = static_cast(problemStruct->numberOfContrasts) - 1; #pragma omp parallel \ num_threads(omp_get_max_threads()) \ @@ -143,24 +148,24 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[i], - problemDef->contrastQzshifts[i], - problemDef->contrastScalefactors[i], - problemDef->contrastBulkIns[i], - problemDef->contrastBulkOuts[i], - problemDef->contrastResolutions[i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[i], + problemStruct->contrastQzshifts[i], + problemStruct->contrastScalefactors[i], + problemStruct->contrastBulkIns[i], + problemStruct->contrastBulkOuts[i], + problemStruct->contrastResolutions[i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); // Also need to determine which layers from the overall layers list // are required for this contrast, and put them in the correct order // according to geometry - allocateLayersForContrast(problemDefCells->f5[i].f1, + allocateLayersForContrast(problemCells->f5[i].f1, outParameterisedLayers, useImaginary, - RATMainTLSThread->f4.thisContrastLayers_data, + RATMainTLSThread->f2.thisContrastLayers_data, thisContrastLayers_size); // For the other parameters, we extract the correct ones from the input @@ -171,23 +176,23 @@ namespace RAT // points // Call the core layers calculation thisContrastLayers_data.set - (&RATMainTLSThread->f4.thisContrastLayers_data[0], + (&RATMainTLSThread->f2.thisContrastLayers_data[0], thisContrastLayers_size[0], thisContrastLayers_size[1]); - b_dv[0] = problemDefCells->f3[i].f1[0]; - b_dv[1] = problemDefCells->f3[i].f1[1]; - b_dv1[0] = problemDefCells->f4[i].f1[0]; - b_dv1[1] = problemDefCells->f4[i].f1[1]; - dv2[0] = problemDefCells->f1[i].f1[0]; - dv2[1] = problemDefCells->f1[i].f1[1]; - coreLayersCalculation(thisContrastLayers_data, problemDef->params[0], - problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, - thisBulkOut, problemDef->resample[i], calcSld, - thisScalefactor, thisQzshift, - problemDef->dataPresent[i], - problemDefCells->f2[i].f1, b_dv, b_dv1, dv2, + b_dv[0] = problemCells->f3[i].f1[0]; + b_dv[1] = problemCells->f3[i].f1[1]; + b_dv1[0] = problemCells->f4[i].f1[0]; + b_dv1[1] = problemCells->f4[i].f1[1]; + dv2[0] = problemCells->f1[i].f1[0]; + dv2[1] = problemCells->f1[i].f1[1]; + coreLayersCalculation(thisContrastLayers_data, problemStruct-> + params[0], problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, + thisBulkOut, problemStruct->resample[i], + calcSld, thisScalefactor, thisQzshift, + problemStruct->dataPresent[i], + problemCells->f2[i].f1, b_dv, b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[i], + problemStruct->contrastBackgroundsType[i], static_cast(nParams), controls->resamPars, useImaginary, sldProfile, reflect, simul, shiftedDat, layerSlds[i].f1, @@ -241,7 +246,7 @@ namespace RAT bulkIns[i] = thisBulkIn; bulkOuts[i] = thisBulkOut; resolutionParams[i] = thisResol; - allRoughs[i] = problemDef->params[0]; + allRoughs[i] = problemStruct->params[0]; loop_ub = resampledLayers.size(1); allLayers[i].f1.set_size(resampledLayers.size(0), resampledLayers.size(1)); diff --git a/RAT/parallelContrasts.h b/RAT/parallelContrasts.h index 1534146a..c1433049 100644 --- a/RAT/parallelContrasts.h +++ b/RAT/parallelContrasts.h @@ -11,18 +11,13 @@ #define PARALLELCONTRASTS_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,14 +25,14 @@ namespace RAT { namespace standardLayers { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); diff --git a/RAT/parallelContrasts1.cpp b/RAT/parallelContrasts1.cpp index a2a8edb0..1dc300ca 100644 --- a/RAT/parallelContrasts1.cpp +++ b/RAT/parallelContrasts1.cpp @@ -27,14 +27,14 @@ namespace RAT { namespace customLayers { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) @@ -74,7 +74,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -84,48 +84,47 @@ namespace RAT // * layersDetails: Master array of all available layers. // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); + // Extract individual parameters from problemStruct + // Extract individual parameters from problem + nParams = problemStruct->params.size(1); calcSld = controls->calcSldDuringFit; - useImaginary = problemDef->useImaginary; + useImaginary = problemStruct->useImaginary; // Pre-Allocation of output arrays... backgroundParams.set_size(static_cast - (problemDef->numberOfContrasts)); + (problemStruct->numberOfContrasts)); // --- End Memory Allocation --- // Resampling parameters // Process the custom models.... - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, - problemDef->useImaginary, allLayers, allRoughs); + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, + problemStruct->useImaginary, allLayers, allRoughs); // Multi cored over all contrasts - outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); - sldProfiles.set_size(static_cast(problemDef->numberOfContrasts)); - reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); - simulation.set_size(static_cast(problemDef->numberOfContrasts)); - shiftedData.set_size(static_cast(problemDef->numberOfContrasts)); - layerSlds.set_size(static_cast(problemDef->numberOfContrasts)); - chis.set_size(static_cast(problemDef->numberOfContrasts)); - qzshifts.set_size(static_cast(problemDef->numberOfContrasts)); - scalefactors.set_size(static_cast(problemDef->numberOfContrasts)); - bulkIns.set_size(static_cast(problemDef->numberOfContrasts)); - bulkOuts.set_size(static_cast(problemDef->numberOfContrasts)); + outSsubs.set_size(static_cast(problemStruct->numberOfContrasts)); + sldProfiles.set_size(static_cast + (problemStruct->numberOfContrasts)); + reflectivity.set_size(static_cast + (problemStruct->numberOfContrasts)); + simulation.set_size(static_cast + (problemStruct->numberOfContrasts)); + shiftedData.set_size(static_cast + (problemStruct->numberOfContrasts)); + layerSlds.set_size(static_cast(problemStruct->numberOfContrasts)); + chis.set_size(static_cast(problemStruct->numberOfContrasts)); + qzshifts.set_size(static_cast(problemStruct->numberOfContrasts)); + scalefactors.set_size(static_cast + (problemStruct->numberOfContrasts)); + bulkIns.set_size(static_cast(problemStruct->numberOfContrasts)); + bulkOuts.set_size(static_cast(problemStruct->numberOfContrasts)); resolutionParams.set_size(static_cast - (problemDef->numberOfContrasts)); - ub_loop = static_cast(problemDef->numberOfContrasts) - 1; + (problemStruct->numberOfContrasts)); + ub_loop = static_cast(problemStruct->numberOfContrasts) - 1; #pragma omp parallel for \ num_threads(omp_get_max_threads()) \ @@ -136,14 +135,15 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[i], - problemDef->contrastQzshifts[i], - problemDef->contrastScalefactors[i], - problemDef->contrastBulkIns[i], problemDef-> - contrastBulkOuts[i], problemDef->contrastResolutions[i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[i], + problemStruct->contrastQzshifts[i], + problemStruct->contrastScalefactors[i], + problemStruct->contrastBulkIns[i], + problemStruct->contrastBulkOuts[i], + problemStruct->contrastResolutions[i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); @@ -154,20 +154,21 @@ namespace RAT // In this case we are single cored, so we do not parallelise over // points // Call the reflectivity calculation - b_dv[0] = problemDefCells->f3[i].f1[0]; - b_dv[1] = problemDefCells->f3[i].f1[1]; - b_dv1[0] = problemDefCells->f4[i].f1[0]; - b_dv1[1] = problemDefCells->f4[i].f1[1]; - dv2[0] = problemDefCells->f1[i].f1[0]; - dv2[1] = problemDefCells->f1[i].f1[1]; + b_dv[0] = problemCells->f3[i].f1[0]; + b_dv[1] = problemCells->f3[i].f1[1]; + b_dv1[0] = problemCells->f4[i].f1[0]; + b_dv1[1] = problemCells->f4[i].f1[1]; + dv2[0] = problemCells->f1[i].f1[0]; + dv2[1] = problemCells->f1[i].f1[1]; coreLayersCalculation(allLayers[i].f1, allRoughs[i], - problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, - thisBulkOut, problemDef->resample[i], calcSld, + problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, + thisBulkOut, problemStruct->resample[i], calcSld, thisScalefactor, thisQzshift, - problemDef->dataPresent[i], problemDefCells-> + problemStruct->dataPresent[i], problemCells-> f2[i].f1, b_dv, b_dv1, dv2, thisBackground, - thisResol, problemDef->contrastBackgroundsType[i], + thisResol, + problemStruct->contrastBackgroundsType[i], static_cast(nParams), controls->resamPars, useImaginary, sldProfile, reflect, simul, shiftedDat, layerSld, diff --git a/RAT/parallelContrasts1.h b/RAT/parallelContrasts1.h index faa38a70..93313e6b 100644 --- a/RAT/parallelContrasts1.h +++ b/RAT/parallelContrasts1.h @@ -11,18 +11,13 @@ #define PARALLELCONTRASTS1_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,14 +25,14 @@ namespace RAT { namespace customLayers { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); diff --git a/RAT/parallelContrasts2.cpp b/RAT/parallelContrasts2.cpp index e9af908c..17f26748 100644 --- a/RAT/parallelContrasts2.cpp +++ b/RAT/parallelContrasts2.cpp @@ -31,19 +31,19 @@ namespace RAT { namespace customXY { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) { - ::coder::array b_problemDefCells; + ::coder::array b_problemCells; ::coder::array b_sldProfiles; ::coder::array layerSld; ::coder::array reSLD; @@ -70,7 +70,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -81,12 +81,12 @@ namespace RAT // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. // % Layers details N/A - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); + // Extract individual parameters from problemStruct + // Extract individual parameters from problem + nParams = problemStruct->params.size(1); // Pre-Allocation... - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + loop_ub_tmp = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(loop_ub_tmp); outSsubs.set_size(loop_ub_tmp); for (int32_T i{0}; i < loop_ub_tmp; i++) { @@ -94,19 +94,13 @@ namespace RAT } // Resampling parameters - useImaginary = problemDef->useImaginary; - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, + useImaginary = problemStruct->useImaginary; + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, sldProfiles, allRoughs); qzshifts.set_size(loop_ub_tmp); scalefactors.set_size(loop_ub_tmp); @@ -123,19 +117,19 @@ namespace RAT #pragma omp parallel for \ num_threads(omp_get_max_threads()) \ - private(b_sldProfiles,b_problemDefCells,reSLD,layerSld,reflect,simul,shiftedDat,d,d1,d2,d3,d4,d5,loop_ub,b_loop_ub,i1,i2,b_dv,b_dv1) + private(b_sldProfiles,b_problemCells,reSLD,layerSld,reflect,simul,shiftedDat,d,d1,d2,d3,d4,d5,loop_ub,b_loop_ub,i1,i2,b_dv,b_dv1) for (int32_T b_i = 0; b_i <= loop_ub_tmp; b_i++) { - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, &d5, &d4, - &d3, &d2, &d1, &d); + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &d5, + &d4, &d3, &d2, &d1, &d); backgroundParams[b_i] = d5; qzshifts[b_i] = d4; scalefactors[b_i] = d3; @@ -164,7 +158,7 @@ namespace RAT + sldProfiles[b_i].f1.size(0) * 2]; } - c_resampleLayersReIm(reSLD, b_sldProfiles, controls->resamPars, + b_resampleLayersReIm(reSLD, b_sldProfiles, controls->resamPars, layerSld); } @@ -181,25 +175,25 @@ namespace RAT } } - b_problemDefCells.set_size(problemDefCells->f2 - [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> - f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); - loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + b_problemCells.set_size(problemCells->f2[problemCells->f2.size(0) * + b_i].f1.size(0), problemCells->f2[problemCells->f2.size(0) * b_i]. + f1.size(1)); + loop_ub = problemCells->f2[b_i].f1.size(1) - 1; for (i1 = 0; i1 <= loop_ub; i1++) { - b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + b_loop_ub = problemCells->f2[b_i].f1.size(0) - 1; for (i2 = 0; i2 <= b_loop_ub; i2++) { - b_problemDefCells[i2 + b_problemDefCells.size(0) * i1] = - problemDefCells->f2[b_i].f1[i2 + problemDefCells->f2[b_i]. - f1.size(0) * i1]; + b_problemCells[i2 + b_problemCells.size(0) * i1] = + problemCells->f2[b_i].f1[i2 + problemCells->f2[b_i].f1.size(0) * + i1]; } } - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> - dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemStruct-> + dataPresent[b_i], b_problemCells, b_dv, b_dv1, shiftedDat); shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); loop_ub = shiftedDat.size(1); for (i1 = 0; i1 < loop_ub; i1++) { @@ -210,15 +204,15 @@ namespace RAT } } - b_dv[0] = problemDefCells->f4[b_i].f1[0]; - b_dv[1] = problemDefCells->f4[b_i].f1[1]; - b_dv1[0] = problemDefCells->f1[b_i].f1[0]; - b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f4[b_i].f1[0]; + b_dv[1] = problemCells->f4[b_i].f1[1]; + b_dv1[0] = problemCells->f1[b_i].f1[0]; + b_dv1[1] = problemCells->f1[b_i].f1[1]; callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, layerSld, 0.0, resolutionParams[b_i], useImaginary, reflect, simul); applyBackgroundCorrection(reflect, simul, shiftedDat, - backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + backgroundParams[b_i], problemStruct->contrastBackgroundsType[b_i]); loop_ub = reflect.size(0); reflectivity[b_i].f1.set_size(reflect.size(0), 2); b_loop_ub = simul.size(0); @@ -235,7 +229,7 @@ namespace RAT } } - if (problemDef->dataPresent[b_i] != 0.0) { + if (problemStruct->dataPresent[b_i] != 0.0) { chis[b_i] = chiSquared(shiftedDat, reflect, static_cast (nParams)); } else { diff --git a/RAT/parallelContrasts2.h b/RAT/parallelContrasts2.h index 546f46f1..09d8febb 100644 --- a/RAT/parallelContrasts2.h +++ b/RAT/parallelContrasts2.h @@ -11,18 +11,13 @@ #define PARALLELCONTRASTS2_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,14 +25,14 @@ namespace RAT { namespace customXY { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); diff --git a/RAT/parallelContrasts3.cpp b/RAT/parallelContrasts3.cpp index bd73ec09..cefdb72b 100644 --- a/RAT/parallelContrasts3.cpp +++ b/RAT/parallelContrasts3.cpp @@ -31,22 +31,22 @@ namespace RAT { namespace standardLayers { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) { - ::coder::array outParameterisedLayers; - ::coder::array tempAllLayers; - ::coder::array tempLayerSlds; - ::coder::array tempSldProfiles; + ::coder::array outParameterisedLayers; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; ::coder::array a__6; ::coder::array reflect1; ::coder::array reflect2; @@ -107,7 +107,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -118,52 +118,56 @@ namespace RAT // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. // Additionally extract the additional domain layers details - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); - numberOfContrasts = problemDef->numberOfContrasts; + // Extract individual parameters from problemStruct + // Extract individual parameters from problem + nParams = problemStruct->params.size(1); + numberOfContrasts = problemStruct->numberOfContrasts; calcSld = controls->calcSldDuringFit; - useImaginary = problemDef->useImaginary; + useImaginary = problemStruct->useImaginary; // Default for compile. // Allocate the memory for the output arrays before the main loop backgroundParams.set_size(static_cast - (problemDef->numberOfContrasts)); + (problemStruct->numberOfContrasts)); // end memory allocation. // First we need to allocate the absolute values of the input // parameters to all the layers in the layers list. This only needs // to be done once, and so is done outside the contrasts loop - allocateParamsToLayers(problemDef->params, problemDefCells->f6, + allocateParamsToLayers(problemStruct->params, problemCells->f6, outParameterisedLayers); // Resample params if requiired // Loop over all the contrasts - outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); + outSsubs.set_size(static_cast(problemStruct->numberOfContrasts)); tempSldProfiles.set_size(static_cast - (problemDef->numberOfContrasts)); - reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); - simulation.set_size(static_cast(problemDef->numberOfContrasts)); - shiftedData.set_size(static_cast(problemDef->numberOfContrasts)); + (problemStruct->numberOfContrasts)); + reflectivity.set_size(static_cast + (problemStruct->numberOfContrasts)); + simulation.set_size(static_cast + (problemStruct->numberOfContrasts)); + shiftedData.set_size(static_cast + (problemStruct->numberOfContrasts)); tempLayerSlds.set_size(static_cast - (problemDef->numberOfContrasts)); + (problemStruct->numberOfContrasts)); tempAllLayers.set_size(static_cast - (problemDef->numberOfContrasts)); - chis.set_size(static_cast(problemDef->numberOfContrasts)); - qzshifts.set_size(static_cast(problemDef->numberOfContrasts)); - scalefactors.set_size(static_cast(problemDef->numberOfContrasts)); - bulkIns.set_size(static_cast(problemDef->numberOfContrasts)); - bulkOuts.set_size(static_cast(problemDef->numberOfContrasts)); + (problemStruct->numberOfContrasts)); + chis.set_size(static_cast(problemStruct->numberOfContrasts)); + qzshifts.set_size(static_cast(problemStruct->numberOfContrasts)); + scalefactors.set_size(static_cast + (problemStruct->numberOfContrasts)); + bulkIns.set_size(static_cast(problemStruct->numberOfContrasts)); + bulkOuts.set_size(static_cast(problemStruct->numberOfContrasts)); resolutionParams.set_size(static_cast - (problemDef->numberOfContrasts)); - allRoughs.set_size(static_cast(problemDef->numberOfContrasts)); - layerSlds.set_size(static_cast(problemDef->numberOfContrasts), + (problemStruct->numberOfContrasts)); + allRoughs.set_size(static_cast(problemStruct->numberOfContrasts)); + layerSlds.set_size(static_cast(problemStruct->numberOfContrasts), 2); - allLayers.set_size(static_cast(problemDef->numberOfContrasts), + allLayers.set_size(static_cast(problemStruct->numberOfContrasts), 2); domainSldProfiles.set_size(static_cast - (problemDef->numberOfContrasts), 2); - ub_loop = static_cast(problemDef->numberOfContrasts) - 1; + (problemStruct->numberOfContrasts), 2); + ub_loop = static_cast(problemStruct->numberOfContrasts) - 1; #pragma omp parallel \ num_threads(omp_get_max_threads()) \ @@ -181,28 +185,28 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[i], - problemDef->contrastQzshifts[i], - problemDef->contrastScalefactors[i], - problemDef->contrastBulkIns[i], - problemDef->contrastBulkOuts[i], - problemDef->contrastResolutions[i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[i], + problemStruct->contrastQzshifts[i], + problemStruct->contrastScalefactors[i], + problemStruct->contrastBulkIns[i], + problemStruct->contrastBulkOuts[i], + problemStruct->contrastResolutions[i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); // Also need to determine which layers from the overall layers list // are required for this contrast, and put them in the correct order // according to geometry. We run it twice, once for each domain... - allocateLayersForContrast(problemDefCells->f19[0].f1, + allocateLayersForContrast(problemCells->f19[0].f1, outParameterisedLayers, useImaginary, - RATMainTLSThread->f3.thisContrastLayers1_data, + RATMainTLSThread->f1.thisContrastLayers1_data, thisContrastLayers1_size); - allocateLayersForContrast(problemDefCells->f19[1].f1, + allocateLayersForContrast(problemCells->f19[1].f1, outParameterisedLayers, useImaginary, - RATMainTLSThread->f3.thisContrastLayers2_data, + RATMainTLSThread->f1.thisContrastLayers2_data, thisContrastLayers2_size); // For the other parameters, we extract the correct ones from the input @@ -214,51 +218,51 @@ namespace RAT // Call the core layers calculation - need to do this once for each // domain thisContrastLayers1_data.set - (&RATMainTLSThread->f3.thisContrastLayers1_data[0], + (&RATMainTLSThread->f1.thisContrastLayers1_data[0], thisContrastLayers1_size[0], thisContrastLayers1_size[1]); - b_dv[0] = problemDefCells->f3[i].f1[0]; - b_dv[1] = problemDefCells->f3[i].f1[1]; - b_dv1[0] = problemDefCells->f4[i].f1[0]; - b_dv1[1] = problemDefCells->f4[i].f1[1]; - dv2[0] = problemDefCells->f1[i].f1[0]; - dv2[1] = problemDefCells->f1[i].f1[1]; + b_dv[0] = problemCells->f3[i].f1[0]; + b_dv[1] = problemCells->f3[i].f1[1]; + b_dv1[0] = problemCells->f4[i].f1[0]; + b_dv1[1] = problemCells->f4[i].f1[1]; + dv2[0] = problemCells->f1[i].f1[0]; + dv2[1] = problemCells->f1[i].f1[1]; nonPolarisedTF::coreLayersCalculation(thisContrastLayers1_data, - problemDef->params[0], problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, thisBulkOut, - problemDef->resample[i], calcSld, thisScalefactor, thisQzshift, - problemDef->dataPresent[i], problemDefCells->f2[i].f1, b_dv, b_dv1, + problemStruct->params[0], problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, thisBulkOut, + problemStruct->resample[i], calcSld, thisScalefactor, thisQzshift, + problemStruct->dataPresent[i], problemCells->f2[i].f1, b_dv, b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[i], static_cast + problemStruct->contrastBackgroundsType[i], static_cast (nParams), controls->resamPars, useImaginary, r3.f1, reflect1, simul1, shiftedDat, r2.f1, r4.f1, &a__5, &thisSsubs); thisContrastLayers2_data.set - (&RATMainTLSThread->f3.thisContrastLayers2_data[0], + (&RATMainTLSThread->f1.thisContrastLayers2_data[0], thisContrastLayers2_size[0], thisContrastLayers2_size[1]); - b_dv[0] = problemDefCells->f3[i].f1[0]; - b_dv[1] = problemDefCells->f3[i].f1[1]; - b_dv1[0] = problemDefCells->f4[i].f1[0]; - b_dv1[1] = problemDefCells->f4[i].f1[1]; - dv2[0] = problemDefCells->f1[i].f1[0]; - dv2[1] = problemDefCells->f1[i].f1[1]; + b_dv[0] = problemCells->f3[i].f1[0]; + b_dv[1] = problemCells->f3[i].f1[1]; + b_dv1[0] = problemCells->f4[i].f1[0]; + b_dv1[1] = problemCells->f4[i].f1[1]; + dv2[0] = problemCells->f1[i].f1[0]; + dv2[1] = problemCells->f1[i].f1[1]; nonPolarisedTF::coreLayersCalculation(thisContrastLayers2_data, - problemDef->params[0], problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, thisBulkOut, - problemDef->resample[i], calcSld, thisScalefactor, thisQzshift, - problemDef->dataPresent[i], problemDefCells->f2[i].f1, b_dv, b_dv1, + problemStruct->params[0], problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, thisBulkOut, + problemStruct->resample[i], calcSld, thisScalefactor, thisQzshift, + problemStruct->dataPresent[i], problemCells->f2[i].f1, b_dv, b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[i], static_cast + problemStruct->contrastBackgroundsType[i], static_cast (nParams), controls->resamPars, useImaginary, r1.f1, reflect2, simul2, a__6, r.f1, r5.f1, &a__7, &a__8); // Calculate the average reflectivities.... averageReflectivity(reflect1, reflect2, simul1, simul2, - problemDef->domainRatio[static_cast - (problemDef->contrastDomainRatios[i]) - 1], + problemStruct->domainRatio[static_cast + (problemStruct->contrastDomainRatios[i]) - 1], totReflect, totSimul); // Get an overall chi-squared for the new averaged curve.. - thisChiSquared = chiSquared(shiftedDat, totReflect, static_cast< - real_T>(problemDef->params.size(1))); + thisChiSquared = chiSquared(shiftedDat, totReflect, + static_cast(problemStruct->params.size(1))); // Store returned values for this contrast in the output arrays. // As well as the calculated profiles, we also store a record of @@ -304,7 +308,7 @@ namespace RAT bulkIns[i] = thisBulkIn; bulkOuts[i] = thisBulkOut; resolutionParams[i] = thisResol; - allRoughs[i] = problemDef->params[0]; + allRoughs[i] = problemStruct->params[0]; } } diff --git a/RAT/parallelContrasts3.h b/RAT/parallelContrasts3.h index 272bc2da..8c2d981f 100644 --- a/RAT/parallelContrasts3.h +++ b/RAT/parallelContrasts3.h @@ -11,18 +11,13 @@ #define PARALLELCONTRASTS3_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,14 +25,14 @@ namespace RAT { namespace standardLayers { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); diff --git a/RAT/parallelContrasts4.cpp b/RAT/parallelContrasts4.cpp index 0e0a21ea..1b6cd166 100644 --- a/RAT/parallelContrasts4.cpp +++ b/RAT/parallelContrasts4.cpp @@ -30,22 +30,22 @@ namespace RAT { namespace customLayers { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) { - ::coder::array r; - ::coder::array tempAllLayers; - ::coder::array tempLayerSlds; - ::coder::array tempSldProfiles; + ::coder::array r; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; ::coder::array calcAllLayers; ::coder::array a__5; ::coder::array reflect1; @@ -94,7 +94,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -104,61 +104,59 @@ namespace RAT // * layersDetails: Master array of all available layers. // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); - numberOfContrasts = problemDef->numberOfContrasts; + // Extract individual parameters from problemStruct + // Extract individual parameters from problem + nParams = problemStruct->params.size(1); + numberOfContrasts = problemStruct->numberOfContrasts; calcSld = controls->calcSldDuringFit; - useImaginary = problemDef->useImaginary; + useImaginary = problemStruct->useImaginary; // Default for compile. // Pre-Allocation of output arrays... backgroundParams.set_size(static_cast - (problemDef->numberOfContrasts)); + (problemStruct->numberOfContrasts)); // Resampling parameters // Process the custom models.... - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, - problemDef->useImaginary, r, allRoughs); + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, + problemStruct->useImaginary, r, allRoughs); cast(r, calcAllLayers); // Parallel over all contrasts // layersCounter = 1; - outSsubs.set_size(static_cast(problemDef->numberOfContrasts)); + outSsubs.set_size(static_cast(problemStruct->numberOfContrasts)); tempSldProfiles.set_size(static_cast - (problemDef->numberOfContrasts)); - reflectivity.set_size(static_cast(problemDef->numberOfContrasts)); - simulation.set_size(static_cast(problemDef->numberOfContrasts)); - shiftedData.set_size(static_cast(problemDef->numberOfContrasts)); + (problemStruct->numberOfContrasts)); + reflectivity.set_size(static_cast + (problemStruct->numberOfContrasts)); + simulation.set_size(static_cast + (problemStruct->numberOfContrasts)); + shiftedData.set_size(static_cast + (problemStruct->numberOfContrasts)); tempLayerSlds.set_size(static_cast - (problemDef->numberOfContrasts)); + (problemStruct->numberOfContrasts)); tempAllLayers.set_size(static_cast - (problemDef->numberOfContrasts)); - chis.set_size(static_cast(problemDef->numberOfContrasts)); - qzshifts.set_size(static_cast(problemDef->numberOfContrasts)); - scalefactors.set_size(static_cast(problemDef->numberOfContrasts)); - bulkIns.set_size(static_cast(problemDef->numberOfContrasts)); - bulkOuts.set_size(static_cast(problemDef->numberOfContrasts)); + (problemStruct->numberOfContrasts)); + chis.set_size(static_cast(problemStruct->numberOfContrasts)); + qzshifts.set_size(static_cast(problemStruct->numberOfContrasts)); + scalefactors.set_size(static_cast + (problemStruct->numberOfContrasts)); + bulkIns.set_size(static_cast(problemStruct->numberOfContrasts)); + bulkOuts.set_size(static_cast(problemStruct->numberOfContrasts)); resolutionParams.set_size(static_cast - (problemDef->numberOfContrasts)); - layerSlds.set_size(static_cast(problemDef->numberOfContrasts), + (problemStruct->numberOfContrasts)); + layerSlds.set_size(static_cast(problemStruct->numberOfContrasts), 2); - allLayers.set_size(static_cast(problemDef->numberOfContrasts), + allLayers.set_size(static_cast(problemStruct->numberOfContrasts), 2); domainSldProfiles.set_size(static_cast - (problemDef->numberOfContrasts), 2); - ub_loop = static_cast(problemDef->numberOfContrasts) - 1; + (problemStruct->numberOfContrasts), 2); + ub_loop = static_cast(problemStruct->numberOfContrasts) - 1; #pragma omp parallel for \ num_threads(omp_get_max_threads()) \ @@ -170,14 +168,15 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[i], - problemDef->contrastQzshifts[i], - problemDef->contrastScalefactors[i], - problemDef->contrastBulkIns[i], problemDef-> - contrastBulkOuts[i], problemDef->contrastResolutions[i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[i], + problemStruct->contrastQzshifts[i], + problemStruct->contrastScalefactors[i], + problemStruct->contrastBulkIns[i], + problemStruct->contrastBulkOuts[i], + problemStruct->contrastResolutions[i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); @@ -190,47 +189,47 @@ namespace RAT // points // Call the reflectivity calculation for each domain // Domain 1 - b_dv[0] = problemDefCells->f3[i].f1[0]; - b_dv[1] = problemDefCells->f3[i].f1[1]; - b_dv1[0] = problemDefCells->f4[i].f1[0]; - b_dv1[1] = problemDefCells->f4[i].f1[1]; - dv2[0] = problemDefCells->f1[i].f1[0]; - dv2[1] = problemDefCells->f1[i].f1[1]; + b_dv[0] = problemCells->f3[i].f1[0]; + b_dv[1] = problemCells->f3[i].f1[1]; + b_dv1[0] = problemCells->f4[i].f1[0]; + b_dv1[1] = problemCells->f4[i].f1[1]; + dv2[0] = problemCells->f1[i].f1[0]; + dv2[1] = problemCells->f1[i].f1[1]; nonPolarisedTF::coreLayersCalculation(calcAllLayers[i].f1, allRoughs[i], - problemDef->geometry.data, problemDef->geometry.size, thisBulkIn, - thisBulkOut, problemDef->resample[i], calcSld, thisScalefactor, - thisQzshift, problemDef->dataPresent[i], problemDefCells->f2[i].f1, - b_dv, b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[i], static_cast(nParams), - controls->resamPars, useImaginary, r2.f1, reflect1, simul1, - shiftedDat, r3.f1, r4.f1, &a__4, &thisSsubs); + problemStruct->geometry.data, problemStruct->geometry.size, + thisBulkIn, thisBulkOut, problemStruct->resample[i], calcSld, + thisScalefactor, thisQzshift, problemStruct->dataPresent[i], + problemCells->f2[i].f1, b_dv, b_dv1, dv2, thisBackground, thisResol, + problemStruct->contrastBackgroundsType[i], static_cast + (nParams), controls->resamPars, useImaginary, r2.f1, reflect1, + simul1, shiftedDat, r3.f1, r4.f1, &a__4, &thisSsubs); // Domain 2 - b_dv[0] = problemDefCells->f3[i].f1[0]; - b_dv[1] = problemDefCells->f3[i].f1[1]; - b_dv1[0] = problemDefCells->f4[i].f1[0]; - b_dv1[1] = problemDefCells->f4[i].f1[1]; - dv2[0] = problemDefCells->f1[i].f1[0]; - dv2[1] = problemDefCells->f1[i].f1[1]; + b_dv[0] = problemCells->f3[i].f1[0]; + b_dv[1] = problemCells->f3[i].f1[1]; + b_dv1[0] = problemCells->f4[i].f1[0]; + b_dv1[1] = problemCells->f4[i].f1[1]; + dv2[0] = problemCells->f1[i].f1[0]; + dv2[1] = problemCells->f1[i].f1[1]; nonPolarisedTF::coreLayersCalculation(calcAllLayers[i + - calcAllLayers.size(0)].f1, allRoughs[i], problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, thisBulkOut, - problemDef->resample[i], calcSld, thisScalefactor, thisQzshift, - problemDef->dataPresent[i], problemDefCells->f2[i].f1, b_dv, b_dv1, - dv2, thisBackground, thisResol, problemDef-> - contrastBackgroundsType[i], static_cast(nParams), - controls->resamPars, useImaginary, r1.f1, reflect2, simul2, a__5, - r5.f1, r6.f1, &a__6, &a__7); + calcAllLayers.size(0)].f1, allRoughs[i], + problemStruct->geometry.data, problemStruct->geometry.size, + thisBulkIn, thisBulkOut, problemStruct->resample[i], calcSld, + thisScalefactor, thisQzshift, problemStruct->dataPresent[i], + problemCells->f2[i].f1, b_dv, b_dv1, dv2, thisBackground, thisResol, + problemStruct->contrastBackgroundsType[i], static_cast + (nParams), controls->resamPars, useImaginary, r1.f1, reflect2, + simul2, a__5, r5.f1, r6.f1, &a__6, &a__7); // Calculate the average reflectivities.... averageReflectivity(reflect1, reflect2, simul1, simul2, - problemDef->domainRatio[static_cast - (problemDef->contrastDomainRatios[i]) - 1], + problemStruct->domainRatio[static_cast + (problemStruct->contrastDomainRatios[i]) - 1], totReflect, totSimul); // Get an overall chi-squared for the new averaged curve.. thisChiSquared = chiSquared(shiftedDat, totReflect, static_cast - (problemDef->params.size(1))); + (problemStruct->params.size(1))); // Store returned values for this contrast in the output arrays. // As well as the calculated profiles, we also store a record of diff --git a/RAT/parallelContrasts4.h b/RAT/parallelContrasts4.h index 1632d70e..54b907e7 100644 --- a/RAT/parallelContrasts4.h +++ b/RAT/parallelContrasts4.h @@ -11,18 +11,13 @@ #define PARALLELCONTRASTS4_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,14 +25,14 @@ namespace RAT { namespace customLayers { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); diff --git a/RAT/parallelContrasts5.cpp b/RAT/parallelContrasts5.cpp index 67f09a6f..f0e1c9db 100644 --- a/RAT/parallelContrasts5.cpp +++ b/RAT/parallelContrasts5.cpp @@ -31,23 +31,23 @@ namespace RAT { namespace customXY { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs) { - ::coder::array tempAllLayers; - ::coder::array tempLayerSlds; - ::coder::array tempSldProfiles; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; ::coder::array b_domainSldProfiles; - ::coder::array b_problemDefCells; + ::coder::array b_problemCells; ::coder::array c_domainSldProfiles; ::coder::array r4; ::coder::array reflect1; @@ -69,7 +69,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -80,28 +80,22 @@ namespace RAT // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. // % Layers details N/A - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef + // Extract individual parameters from problemStruct + // Extract individual parameters from problem // Pre-Allocation... - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(i); // Resampling parameters - useImaginary = problemDef->useImaginary; + useImaginary = problemStruct->useImaginary; // Default for compile. - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, domainSldProfiles, allRoughs); outSsubs.set_size(i); qzshifts.set_size(i); @@ -120,22 +114,22 @@ namespace RAT real_T b_dv[2]; real_T b_dv1[2]; outSsubs[b_i] = allRoughs[b_i]; - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &backgroundParams[b_i], &qzshifts[b_i], &scalefactors[b_i], &bulkIns[b_i], &bulkOuts[b_i], &resolutionParams[b_i]); // Get the domain ratio for this contrast // Resample the sld profiles if (!useImaginary) { - resampleLayers(domainSldProfiles[0].f1, controls->resamPars, r.f1); + resampleLayers(domainSldProfiles[b_i].f1, controls->resamPars, r.f1); r1.f1.set_size(r.f1.size(0), 3); for (int32_T i1{0}; i1 < 3; i1++) { loop_ub = r.f1.size(0); @@ -144,31 +138,29 @@ namespace RAT } } - resampleLayers(domainSldProfiles[1].f1, controls->resamPars, r.f1); + resampleLayers(domainSldProfiles[b_i + domainSldProfiles.size(0)].f1, + controls->resamPars, r.f1); } else { - loop_ub = domainSldProfiles[0].f1.size(0); - b_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i].f1.size(0); + b_domainSldProfiles.set_size(domainSldProfiles[b_i].f1.size(0), 2); for (int32_T i1{0}; i1 < 2; i1++) { for (int32_T i2{0}; i2 < loop_ub; i2++) { b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = - domainSldProfiles[0].f1[i2 + domainSldProfiles[0].f1.size(0) * - i1]; + domainSldProfiles[b_i].f1[i2 + domainSldProfiles[b_i].f1.size + (0) * i1]; } } - loop_ub = domainSldProfiles[0].f1.size(0); - b_loop_ub = domainSldProfiles[0].f1.size(0); - c_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i].f1.size(0); + c_domainSldProfiles.set_size(domainSldProfiles[b_i].f1.size(0), 2); for (int32_T i1{0}; i1 < loop_ub; i1++) { - c_domainSldProfiles[i1] = domainSldProfiles[0].f1[i1]; - } - - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[b_i].f1[i1]; c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = - domainSldProfiles[0].f1[i1 + domainSldProfiles[0].f1.size(0) * 2]; + domainSldProfiles[b_i].f1[i1 + domainSldProfiles[b_i].f1.size(0) + * 2]; } - c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + b_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, controls->resamPars, r.f1); r1.f1.set_size(r.f1.size(0), 4); for (int32_T i1{0}; i1 < 4; i1++) { @@ -178,29 +170,33 @@ namespace RAT } } - loop_ub = domainSldProfiles[1].f1.size(0); - b_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size + (0); + b_domainSldProfiles.set_size(domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(0), 2); for (int32_T i1{0}; i1 < 2; i1++) { for (int32_T i2{0}; i2 < loop_ub; i2++) { b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = - domainSldProfiles[1].f1[i2 + domainSldProfiles[1].f1.size(0) * + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i2 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * i1]; } } - loop_ub = domainSldProfiles[1].f1.size(0); - b_loop_ub = domainSldProfiles[1].f1.size(0); - c_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size + (0); + c_domainSldProfiles.set_size(domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(0), 2); for (int32_T i1{0}; i1 < loop_ub; i1++) { - c_domainSldProfiles[i1] = domainSldProfiles[1].f1[i1]; - } - - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1[i1]; c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = - domainSldProfiles[1].f1[i1 + domainSldProfiles[1].f1.size(0) * 2]; + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i1 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + 2]; } - c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + b_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, controls->resamPars, r.f1); } @@ -208,49 +204,52 @@ namespace RAT tempLayerSlds[b_i].f1[1] = r; tempAllLayers[b_i].f1[0] = r1; tempAllLayers[b_i].f1[1] = r; - r2.f1.set_size(domainSldProfiles[0].f1.size(0), domainSldProfiles[0]. - f1.size(1)); - loop_ub = domainSldProfiles[0].f1.size(1); + r2.f1.set_size(domainSldProfiles[b_i].f1.size(0), + domainSldProfiles[b_i].f1.size(1)); + loop_ub = domainSldProfiles[b_i].f1.size(1); for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = domainSldProfiles[0].f1.size(0); + b_loop_ub = domainSldProfiles[b_i].f1.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - r2.f1[i2 + r2.f1.size(0) * i1] = domainSldProfiles[0].f1[i2 + - domainSldProfiles[0].f1.size(0) * i1]; + r2.f1[i2 + r2.f1.size(0) * i1] = domainSldProfiles[b_i].f1[i2 + + domainSldProfiles[b_i].f1.size(0) * i1]; } } - r3.f1.set_size(domainSldProfiles[1].f1.size(0), domainSldProfiles[1]. - f1.size(1)); - loop_ub = domainSldProfiles[1].f1.size(1); + r3.f1.set_size(domainSldProfiles[b_i + domainSldProfiles.size(0)]. + f1.size(0), domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(1)); + loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(1); for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = domainSldProfiles[1].f1.size(0); + b_loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)]. + f1.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - r3.f1[i2 + r3.f1.size(0) * i1] = domainSldProfiles[1].f1[i2 + - domainSldProfiles[1].f1.size(0) * i1]; + r3.f1[i2 + r3.f1.size(0) * i1] = domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1[i2 + domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(0) * i1]; } } tempSldProfiles[b_i].f1[0] = r2; tempSldProfiles[b_i].f1[1] = r3; - b_problemDefCells.set_size(problemDefCells->f2 - [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> - f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); - loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + b_problemCells.set_size(problemCells->f2[problemCells->f2.size(0) * + b_i].f1.size(0), problemCells->f2[problemCells->f2.size(0) * b_i]. + f1.size(1)); + loop_ub = problemCells->f2[b_i].f1.size(1) - 1; for (int32_T i1{0}; i1 <= loop_ub; i1++) { - b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + b_loop_ub = problemCells->f2[b_i].f1.size(0) - 1; for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { - b_problemDefCells[i2 + b_problemDefCells.size(0) * i1] = - problemDefCells->f2[b_i].f1[i2 + problemDefCells->f2[b_i]. - f1.size(0) * i1]; + b_problemCells[i2 + b_problemCells.size(0) * i1] = + problemCells->f2[b_i].f1[i2 + problemCells->f2[b_i].f1.size(0) * + i1]; } } - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> - dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemStruct-> + dataPresent[b_i], b_problemCells, b_dv, b_dv1, shiftedDat); shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); loop_ub = shiftedDat.size(1); for (int32_T i1{0}; i1 < loop_ub; i1++) { @@ -270,10 +269,10 @@ namespace RAT } } - b_dv[0] = problemDefCells->f4[b_i].f1[0]; - b_dv[1] = problemDefCells->f4[b_i].f1[1]; - b_dv1[0] = problemDefCells->f1[b_i].f1[0]; - b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f4[b_i].f1[0]; + b_dv[1] = problemCells->f4[b_i].f1[1]; + b_dv1[0] = problemCells->f1[b_i].f1[0]; + b_dv1[1] = problemCells->f1[b_i].f1[1]; callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, r4, allRoughs[b_i], resolutionParams[b_i], useImaginary, reflect1, simul1); @@ -286,22 +285,22 @@ namespace RAT } } - b_dv[0] = problemDefCells->f4[b_i].f1[0]; - b_dv[1] = problemDefCells->f4[b_i].f1[1]; - b_dv1[0] = problemDefCells->f1[b_i].f1[0]; - b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f4[b_i].f1[0]; + b_dv[1] = problemCells->f4[b_i].f1[1]; + b_dv1[0] = problemCells->f1[b_i].f1[0]; + b_dv1[1] = problemCells->f1[b_i].f1[1]; callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, r4, allRoughs[b_i], resolutionParams[b_i], useImaginary, reflect2, simul2); applyBackgroundCorrection(reflect1, simul1, shiftedDat, - backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + backgroundParams[b_i], problemStruct->contrastBackgroundsType[b_i]); applyBackgroundCorrection(reflect2, simul2, shiftedDat, - backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + backgroundParams[b_i], problemStruct->contrastBackgroundsType[b_i]); // Calculate the average reflectivities.... averageReflectivity(reflect1, reflect2, simul1, simul2, - problemDef->domainRatio[static_cast - (problemDef->contrastDomainRatios[b_i]) - 1], + problemStruct->domainRatio[static_cast + (problemStruct->contrastDomainRatios[b_i]) - 1], totReflect, simulation[b_i].f1); loop_ub = totReflect.size(0); reflectivity[b_i].f1.set_size(totReflect.size(0), 2); @@ -312,9 +311,9 @@ namespace RAT } } - if (problemDef->dataPresent[b_i] != 0.0) { + if (problemStruct->dataPresent[b_i] != 0.0) { chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast - (problemDef->params.size(1))); + (problemStruct->params.size(1))); } else { chis[b_i] = 0.0; } diff --git a/RAT/parallelContrasts5.h b/RAT/parallelContrasts5.h index ec38d939..cbe763fb 100644 --- a/RAT/parallelContrasts5.h +++ b/RAT/parallelContrasts5.h @@ -11,18 +11,13 @@ #define PARALLELCONTRASTS5_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,14 +25,14 @@ namespace RAT { namespace customXY { - void c_parallelContrasts(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder::array + void c_parallelContrasts(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, ::coder::array< real_T, 1U> &qzshifts, ::coder::array &scalefactors, ::coder:: array &bulkIns, ::coder::array &bulkOuts, :: coder::array &resolutionParams, ::coder::array - &chis, ::coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array + &chis, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array &allLayers, ::coder::array &allRoughs); diff --git a/RAT/parallelPoints.cpp b/RAT/parallelPoints.cpp index 078f77b6..c88bba59 100644 --- a/RAT/parallelPoints.cpp +++ b/RAT/parallelPoints.cpp @@ -27,16 +27,16 @@ namespace RAT { namespace standardLayers { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 1U> &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array< @@ -44,7 +44,7 @@ namespace RAT &allRoughs) { static real_T thisContrastLayers_data[6000]; - ::coder::array outParameterisedLayers; + ::coder::array outParameterisedLayers; ::coder::array b_thisContrastLayers_data; ::coder::array shiftedDat; ::coder::array sldProfile; @@ -67,7 +67,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -77,19 +77,19 @@ namespace RAT // * layersDetails: Master array of all available layers. // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - useImaginary = problemDef->useImaginary; + // Extract individual parameters from problemStruct + // Extract individual parameters from problem + useImaginary = problemStruct->useImaginary; // Allocate the memory for the output arrays before the main loop - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(i); // end memory allocation. // First we need to allocate the absolute values of the input // parameters to all the layers in the layers list. This only needs // to be done once, and so is done outside the contrasts loop - allocateParamsToLayers(problemDef->params, problemDefCells->f6, + allocateParamsToLayers(problemStruct->params, problemCells->f6, outParameterisedLayers); // Resample params if requiired @@ -120,22 +120,22 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); // Also need to determine which layers from the overall layers list // are required for this contrast, and put them in the correct order // according to geometry - allocateLayersForContrast(problemDefCells->f5[b_i].f1, + allocateLayersForContrast(problemCells->f5[b_i].f1, outParameterisedLayers, useImaginary, thisContrastLayers_data, thisContrastLayers_size); @@ -148,22 +148,23 @@ namespace RAT // Call the core layers calculation b_thisContrastLayers_data.set(&thisContrastLayers_data[0], thisContrastLayers_size[0], thisContrastLayers_size[1]); - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; - b_coreLayersCalculation(b_thisContrastLayers_data, problemDef->params - [0], problemDef->geometry.data, problemDef->geometry.size, - thisBulkIn, thisBulkOut, problemDef->resample[b_i], - controls->calcSldDuringFit, thisScalefactor, thisQzshift, - problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, - b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[b_i], static_cast - (problemDef->params.size(1)), controls->resamPars, useImaginary, - sldProfile, reflectivity[b_i].f1, simulation[b_i].f1, shiftedDat, - layerSlds[b_i].f1, allLayers[b_i].f1, &chis[b_i], &outSsubs[b_i]); + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; + b_coreLayersCalculation(b_thisContrastLayers_data, + problemStruct->params[0], problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, thisBulkOut, + problemStruct->resample[b_i], controls->calcSldDuringFit, + thisScalefactor, thisQzshift, problemStruct->dataPresent[b_i], + problemCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, + thisResol, problemStruct->contrastBackgroundsType[b_i], static_cast< + real_T>(problemStruct->params.size(1)), controls->resamPars, + useImaginary, sldProfile, reflectivity[b_i].f1, simulation[b_i].f1, + shiftedDat, layerSlds[b_i].f1, allLayers[b_i].f1, &chis[b_i], + &outSsubs[b_i]); // Store returned values for this contrast in the output arrays. // As well as the calculated profiles, we also store a record of @@ -195,7 +196,7 @@ namespace RAT bulkIns[b_i] = thisBulkIn; bulkOuts[b_i] = thisBulkOut; resolutionParams[b_i] = thisResol; - allRoughs[b_i] = problemDef->params[0]; + allRoughs[b_i] = problemStruct->params[0]; } } } diff --git a/RAT/parallelPoints.h b/RAT/parallelPoints.h index 4609a17f..f2e92571 100644 --- a/RAT/parallelPoints.h +++ b/RAT/parallelPoints.h @@ -11,18 +11,13 @@ #define PARALLELPOINTS_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,16 +25,16 @@ namespace RAT { namespace standardLayers { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 1U> &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array< diff --git a/RAT/parallelPoints1.cpp b/RAT/parallelPoints1.cpp index 6b5be494..550f431d 100644 --- a/RAT/parallelPoints1.cpp +++ b/RAT/parallelPoints1.cpp @@ -26,16 +26,16 @@ namespace RAT { namespace customLayers { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 1U> &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array< @@ -63,7 +63,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -73,28 +73,22 @@ namespace RAT // * layersDetails: Master array of all available layers. // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef + // Extract individual parameters from problemStruct + // Extract individual parameters from problem // Pre-Allocation of output arrays... - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(i); // --- End Memory Allocation --- // Resampling parameters // Process the custom models.... - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, - problemDef->useImaginary, allLayers, allRoughs); + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, + problemStruct->useImaginary, allLayers, allRoughs); // Single cored over all contrasts outSsubs.set_size(i); @@ -117,15 +111,15 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); @@ -150,20 +144,21 @@ namespace RAT real_T b_dv[2]; real_T b_dv1[2]; real_T dv2[2]; - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; b_coreLayersCalculation(b_allLayers, allRoughs[b_i], - problemDef->geometry.data, problemDef->geometry.size, thisBulkIn, - thisBulkOut, problemDef->resample[b_i], controls->calcSldDuringFit, - thisScalefactor, thisQzshift, problemDef->dataPresent[b_i], - problemDefCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, - thisResol, problemDef->contrastBackgroundsType[b_i], - static_cast(problemDef->params.size(1)), controls->resamPars, - problemDef->useImaginary, sldProfile, reflectivity[b_i].f1, + problemStruct->geometry.data, problemStruct->geometry.size, + thisBulkIn, thisBulkOut, problemStruct->resample[b_i], + controls->calcSldDuringFit, thisScalefactor, thisQzshift, + problemStruct->dataPresent[b_i], problemCells->f2[b_i].f1, b_dv, + b_dv1, dv2, thisBackground, thisResol, + problemStruct->contrastBackgroundsType[b_i], static_cast + (problemStruct->params.size(1)), controls->resamPars, + problemStruct->useImaginary, sldProfile, reflectivity[b_i].f1, simulation[b_i].f1, shiftedDat, layerSlds[b_i].f1, allLayers[b_i].f1, &chis[b_i], &outSsubs[b_i]); diff --git a/RAT/parallelPoints1.h b/RAT/parallelPoints1.h index 18f9d4c4..0d0e84ed 100644 --- a/RAT/parallelPoints1.h +++ b/RAT/parallelPoints1.h @@ -11,18 +11,13 @@ #define PARALLELPOINTS1_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,16 +25,16 @@ namespace RAT { namespace customLayers { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 1U> &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array< diff --git a/RAT/parallelPoints2.cpp b/RAT/parallelPoints2.cpp index dd99ad64..a7b88816 100644 --- a/RAT/parallelPoints2.cpp +++ b/RAT/parallelPoints2.cpp @@ -30,23 +30,23 @@ namespace RAT { namespace customXY { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 1U> &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array< cell_wrap_8, 1U> &allLayers, ::coder::array &allRoughs) { - ::coder::array b_problemDefCells; + ::coder::array b_problemCells; ::coder::array b_sldProfiles; ::coder::array c_sldProfiles; ::coder::array layerSld; @@ -61,7 +61,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -72,10 +72,10 @@ namespace RAT // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. // % Layers details N/A - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef + // Extract individual parameters from problemStruct + // Extract individual parameters from problem // Pre-Allocation... - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + loop_ub_tmp = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(loop_ub_tmp); outSsubs.set_size(loop_ub_tmp); for (int32_T i{0}; i < loop_ub_tmp; i++) { @@ -83,19 +83,13 @@ namespace RAT } // Resampling parameters - useImaginary = problemDef->useImaginary; - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, + useImaginary = problemStruct->useImaginary; + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, sldProfiles, allRoughs); qzshifts.set_size(loop_ub_tmp); scalefactors.set_size(loop_ub_tmp); @@ -113,15 +107,15 @@ namespace RAT real_T b_dv1[2]; int32_T b_loop_ub; int32_T loop_ub; - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &backgroundParams[b_i], &qzshifts[b_i], &scalefactors[b_i], &bulkIns[b_i], &bulkOuts[b_i], &resolutionParams[b_i]); @@ -146,7 +140,7 @@ namespace RAT sldProfiles[b_i].f1.size(0) * 2]; } - c_resampleLayersReIm(b_sldProfiles, c_sldProfiles, + b_resampleLayersReIm(b_sldProfiles, c_sldProfiles, controls->resamPars, layerSld); } @@ -163,25 +157,24 @@ namespace RAT } } - b_problemDefCells.set_size(problemDefCells->f2 - [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> - f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); - loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + b_problemCells.set_size(problemCells->f2[problemCells->f2.size(0) * + b_i].f1.size(0), problemCells->f2[problemCells->f2.size(0) * b_i]. + f1.size(1)); + loop_ub = problemCells->f2[b_i].f1.size(1) - 1; for (int32_T i{0}; i <= loop_ub; i++) { - b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + b_loop_ub = problemCells->f2[b_i].f1.size(0) - 1; for (int32_T i1{0}; i1 <= b_loop_ub; i1++) { - b_problemDefCells[i1 + b_problemDefCells.size(0) * i] = - problemDefCells->f2[b_i].f1[i1 + problemDefCells->f2[b_i]. - f1.size(0) * i]; + b_problemCells[i1 + b_problemCells.size(0) * i] = problemCells-> + f2[b_i].f1[i1 + problemCells->f2[b_i].f1.size(0) * i]; } } - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> - dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemStruct-> + dataPresent[b_i], b_problemCells, b_dv, b_dv1, shiftedDat); shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); loop_ub = shiftedDat.size(1); for (int32_T i{0}; i < loop_ub; i++) { @@ -192,15 +185,15 @@ namespace RAT } } - b_dv[0] = problemDefCells->f4[b_i].f1[0]; - b_dv[1] = problemDefCells->f4[b_i].f1[1]; - b_dv1[0] = problemDefCells->f1[b_i].f1[0]; - b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f4[b_i].f1[0]; + b_dv[1] = problemCells->f4[b_i].f1[1]; + b_dv1[0] = problemCells->f1[b_i].f1[0]; + b_dv1[1] = problemCells->f1[b_i].f1[1]; b_callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, layerSld, 0.0, resolutionParams[b_i], useImaginary, reflect, simulation[b_i].f1); applyBackgroundCorrection(reflect, simulation[b_i].f1, shiftedDat, - backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + backgroundParams[b_i], problemStruct->contrastBackgroundsType[b_i]); loop_ub = reflect.size(0); reflectivity[b_i].f1.set_size(reflect.size(0), 2); for (int32_T i{0}; i < 2; i++) { @@ -210,9 +203,9 @@ namespace RAT } } - if (problemDef->dataPresent[b_i] != 0.0) { + if (problemStruct->dataPresent[b_i] != 0.0) { chis[b_i] = chiSquared(shiftedDat, reflect, static_cast - (problemDef->params.size(1))); + (problemStruct->params.size(1))); } else { chis[b_i] = 0.0; } diff --git a/RAT/parallelPoints2.h b/RAT/parallelPoints2.h index 00c50874..734a0729 100644 --- a/RAT/parallelPoints2.h +++ b/RAT/parallelPoints2.h @@ -11,18 +11,13 @@ #define PARALLELPOINTS2_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,16 +25,16 @@ namespace RAT { namespace customXY { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 1U> &layerSlds, ::coder::array< cell_wrap_8, 1U> &sldProfiles, ::coder::array< diff --git a/RAT/parallelPoints3.cpp b/RAT/parallelPoints3.cpp index 63b28112..d0792e2e 100644 --- a/RAT/parallelPoints3.cpp +++ b/RAT/parallelPoints3.cpp @@ -29,16 +29,16 @@ namespace RAT { namespace standardLayers { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 2U> &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< @@ -47,10 +47,10 @@ namespace RAT { static real_T thisContrastLayers1_data[6000]; static real_T thisContrastLayers2_data[6000]; - ::coder::array outParameterisedLayers; - ::coder::array tempAllLayers; - ::coder::array tempLayerSlds; - ::coder::array tempSldProfiles; + ::coder::array outParameterisedLayers; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; ::coder::array a__6; ::coder::array b_thisContrastLayers1_data; ::coder::array b_thisContrastLayers2_data; @@ -92,7 +92,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -103,22 +103,22 @@ namespace RAT // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. // Additionally extract the additional domain layers details - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); + // Extract individual parameters from problemStruct + // Extract individual parameters from problem + nParams = problemStruct->params.size(1); calcSld = controls->calcSldDuringFit; - useImaginary = problemDef->useImaginary; + useImaginary = problemStruct->useImaginary; // Default for compile. // Allocate the memory for the output arrays before the main loop - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(i); // end memory allocation. // First we need to allocate the absolute values of the input // parameters to all the layers in the layers list. This only needs // to be done once, and so is done outside the contrasts loop - allocateParamsToLayers(problemDef->params, problemDefCells->f6, + allocateParamsToLayers(problemStruct->params, problemCells->f6, outParameterisedLayers); // Resample params if requiired @@ -151,25 +151,25 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); // Also need to determine which layers from the overall layers list // are required for this contrast, and put them in the correct order // according to geometry. We run it twice, once for each domain... - allocateLayersForContrast(problemDefCells->f19[0].f1, + allocateLayersForContrast(problemCells->f19[0].f1, outParameterisedLayers, useImaginary, thisContrastLayers1_data, thisContrastLayers1_size); - allocateLayersForContrast(problemDefCells->f19[1].f1, + allocateLayersForContrast(problemCells->f19[1].f1, outParameterisedLayers, useImaginary, thisContrastLayers2_data, thisContrastLayers2_size); @@ -183,48 +183,48 @@ namespace RAT // domain b_thisContrastLayers1_data.set(&thisContrastLayers1_data[0], thisContrastLayers1_size[0], thisContrastLayers1_size[1]); - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; nonPolarisedTF::b_coreLayersCalculation(b_thisContrastLayers1_data, - problemDef->params[0], problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, thisBulkOut, - problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, - problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, + problemStruct->params[0], problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, thisBulkOut, + problemStruct->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemStruct->dataPresent[b_i], problemCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[b_i], static_cast + problemStruct->contrastBackgroundsType[b_i], static_cast (nParams), controls->resamPars, useImaginary, r.f1, reflect1, simul1, shiftedDat, r1.f1, r2.f1, &a__5, &outSsubs[b_i]); b_thisContrastLayers2_data.set(&thisContrastLayers2_data[0], thisContrastLayers2_size[0], thisContrastLayers2_size[1]); - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; nonPolarisedTF::b_coreLayersCalculation(b_thisContrastLayers2_data, - problemDef->params[0], problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, thisBulkOut, - problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, - problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, + problemStruct->params[0], problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, thisBulkOut, + problemStruct->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemStruct->dataPresent[b_i], problemCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[b_i], static_cast + problemStruct->contrastBackgroundsType[b_i], static_cast (nParams), controls->resamPars, useImaginary, r3.f1, reflect2, simul2, a__6, r4.f1, r5.f1, &a__7, &a__8); // Calculate the average reflectivities.... averageReflectivity(reflect1, reflect2, simul1, simul2, - problemDef->domainRatio[static_cast - (problemDef->contrastDomainRatios[b_i]) - 1], + problemStruct->domainRatio[static_cast + (problemStruct->contrastDomainRatios[b_i]) - 1], totReflect, simulation[b_i].f1); // Get an overall chi-squared for the new averaged curve.. chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast - (problemDef->params.size(1))); + (problemStruct->params.size(1))); // Store returned values for this contrast in the output arrays. // As well as the calculated profiles, we also store a record of @@ -261,7 +261,7 @@ namespace RAT bulkIns[b_i] = thisBulkIn; bulkOuts[b_i] = thisBulkOut; resolutionParams[b_i] = thisResol; - allRoughs[b_i] = problemDef->params[0]; + allRoughs[b_i] = problemStruct->params[0]; } allLayers.set_size(i, 2); diff --git a/RAT/parallelPoints3.h b/RAT/parallelPoints3.h index c8ee2830..dbb8cf9b 100644 --- a/RAT/parallelPoints3.h +++ b/RAT/parallelPoints3.h @@ -11,18 +11,13 @@ #define PARALLELPOINTS3_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,16 +25,16 @@ namespace RAT { namespace standardLayers { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 2U> &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< diff --git a/RAT/parallelPoints4.cpp b/RAT/parallelPoints4.cpp index cf910a8a..ef8fce80 100644 --- a/RAT/parallelPoints4.cpp +++ b/RAT/parallelPoints4.cpp @@ -29,26 +29,26 @@ namespace RAT { namespace customLayers { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 2U> &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< cell_wrap_8, 2U> &allLayers, ::coder::array &allRoughs) { - ::coder::array r; - ::coder::array tempAllLayers; - ::coder::array tempLayerSlds; - ::coder::array tempSldProfiles; + ::coder::array r; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; ::coder::array calcAllLayers; ::coder::array a__5; ::coder::array reflect1; @@ -88,7 +88,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -98,32 +98,26 @@ namespace RAT // * layersDetails: Master array of all available layers. // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); + // Extract individual parameters from problemStruct + // Extract individual parameters from problem + nParams = problemStruct->params.size(1); calcSld = controls->calcSldDuringFit; - useImaginary = problemDef->useImaginary; + useImaginary = problemStruct->useImaginary; // Default for compile. // Pre-Allocation of output arrays... - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(i); // Resampling parameters // Process the custom models.... - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, - problemDef->useImaginary, r, allRoughs); + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, + problemStruct->useImaginary, r, allRoughs); cast(r, calcAllLayers); // Parallel over all contrasts @@ -153,15 +147,15 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); @@ -174,48 +168,48 @@ namespace RAT // points // Call the reflectivity calculation for each domain // Domain 1 - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; nonPolarisedTF::b_coreLayersCalculation(calcAllLayers[b_i].f1, - allRoughs[b_i], problemDef->geometry.data, problemDef->geometry.size, - thisBulkIn, thisBulkOut, problemDef->resample[b_i], calcSld, - thisScalefactor, thisQzshift, problemDef->dataPresent[b_i], - problemDefCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, - thisResol, problemDef->contrastBackgroundsType[b_i], - static_cast(nParams), controls->resamPars, useImaginary, - r1.f1, reflect1, simul1, shiftedDat, r2.f1, r3.f1, &a__4, - &outSsubs[b_i]); + allRoughs[b_i], problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, thisBulkOut, + problemStruct->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemStruct->dataPresent[b_i], problemCells->f2[b_i].f1, b_dv, + b_dv1, dv2, thisBackground, thisResol, + problemStruct->contrastBackgroundsType[b_i], static_cast + (nParams), controls->resamPars, useImaginary, r1.f1, reflect1, + simul1, shiftedDat, r2.f1, r3.f1, &a__4, &outSsubs[b_i]); // Domain 2 - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; nonPolarisedTF::b_coreLayersCalculation(calcAllLayers[b_i + - calcAllLayers.size(0)].f1, allRoughs[b_i], problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, thisBulkOut, - problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, - problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, - b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[b_i], static_cast - (nParams), controls->resamPars, useImaginary, r4.f1, reflect2, - simul2, a__5, r5.f1, r6.f1, &a__6, &a__7); + calcAllLayers.size(0)].f1, allRoughs[b_i], + problemStruct->geometry.data, problemStruct->geometry.size, + thisBulkIn, thisBulkOut, problemStruct->resample[b_i], calcSld, + thisScalefactor, thisQzshift, problemStruct->dataPresent[b_i], + problemCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, + thisResol, problemStruct->contrastBackgroundsType[b_i], + static_cast(nParams), controls->resamPars, useImaginary, + r4.f1, reflect2, simul2, a__5, r5.f1, r6.f1, &a__6, &a__7); // Calculate the average reflectivities.... averageReflectivity(reflect1, reflect2, simul1, simul2, - problemDef->domainRatio[static_cast - (problemDef->contrastDomainRatios[b_i]) - 1], + problemStruct->domainRatio[static_cast + (problemStruct->contrastDomainRatios[b_i]) - 1], totReflect, simulation[b_i].f1); // Get an overall chi-squared for the new averaged curve.. chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast - (problemDef->params.size(1))); + (problemStruct->params.size(1))); // Store returned values for this contrast in the output arrays. // As well as the calculated profiles, we also store a record of diff --git a/RAT/parallelPoints4.h b/RAT/parallelPoints4.h index 2089fb72..f16b3105 100644 --- a/RAT/parallelPoints4.h +++ b/RAT/parallelPoints4.h @@ -11,18 +11,13 @@ #define PARALLELPOINTS4_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,16 +25,16 @@ namespace RAT { namespace customLayers { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 2U> &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< diff --git a/RAT/parallelPoints5.cpp b/RAT/parallelPoints5.cpp index 183c0292..4bc34bbd 100644 --- a/RAT/parallelPoints5.cpp +++ b/RAT/parallelPoints5.cpp @@ -31,27 +31,27 @@ namespace RAT { namespace customXY { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 2U> &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< cell_wrap_8, 2U> &allLayers, ::coder::array &allRoughs) { - ::coder::array tempAllLayers; - ::coder::array tempLayerSlds; - ::coder::array tempSldProfiles; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; ::coder::array b_domainSldProfiles; - ::coder::array b_problemDefCells; + ::coder::array b_problemCells; ::coder::array c_domainSldProfiles; ::coder::array r4; ::coder::array reflect1; @@ -73,7 +73,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -84,28 +84,22 @@ namespace RAT // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. // % Layers details N/A - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef + // Extract individual parameters from problemStruct + // Extract individual parameters from problem // Pre-Allocation... - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(i); // Resampling parameters - useImaginary = problemDef->useImaginary; + useImaginary = problemStruct->useImaginary; // Default for compile. - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, domainSldProfiles, allRoughs); outSsubs.set_size(i); qzshifts.set_size(i); @@ -124,22 +118,22 @@ namespace RAT real_T b_dv[2]; real_T b_dv1[2]; outSsubs[b_i] = allRoughs[b_i]; - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &backgroundParams[b_i], &qzshifts[b_i], &scalefactors[b_i], &bulkIns[b_i], &bulkOuts[b_i], &resolutionParams[b_i]); // Get the domain ratio for this contrast // Resample the sld profiles if (!useImaginary) { - resampleLayers(domainSldProfiles[0].f1, controls->resamPars, r.f1); + resampleLayers(domainSldProfiles[b_i].f1, controls->resamPars, r.f1); r1.f1.set_size(r.f1.size(0), 3); for (int32_T i1{0}; i1 < 3; i1++) { loop_ub = r.f1.size(0); @@ -148,31 +142,29 @@ namespace RAT } } - resampleLayers(domainSldProfiles[1].f1, controls->resamPars, r.f1); + resampleLayers(domainSldProfiles[b_i + domainSldProfiles.size(0)].f1, + controls->resamPars, r.f1); } else { - loop_ub = domainSldProfiles[0].f1.size(0); - b_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i].f1.size(0); + b_domainSldProfiles.set_size(domainSldProfiles[b_i].f1.size(0), 2); for (int32_T i1{0}; i1 < 2; i1++) { for (int32_T i2{0}; i2 < loop_ub; i2++) { b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = - domainSldProfiles[0].f1[i2 + domainSldProfiles[0].f1.size(0) * - i1]; + domainSldProfiles[b_i].f1[i2 + domainSldProfiles[b_i].f1.size + (0) * i1]; } } - loop_ub = domainSldProfiles[0].f1.size(0); - b_loop_ub = domainSldProfiles[0].f1.size(0); - c_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i].f1.size(0); + c_domainSldProfiles.set_size(domainSldProfiles[b_i].f1.size(0), 2); for (int32_T i1{0}; i1 < loop_ub; i1++) { - c_domainSldProfiles[i1] = domainSldProfiles[0].f1[i1]; - } - - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[b_i].f1[i1]; c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = - domainSldProfiles[0].f1[i1 + domainSldProfiles[0].f1.size(0) * 2]; + domainSldProfiles[b_i].f1[i1 + domainSldProfiles[b_i].f1.size(0) + * 2]; } - c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + b_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, controls->resamPars, r.f1); r1.f1.set_size(r.f1.size(0), 4); for (int32_T i1{0}; i1 < 4; i1++) { @@ -182,29 +174,33 @@ namespace RAT } } - loop_ub = domainSldProfiles[1].f1.size(0); - b_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size + (0); + b_domainSldProfiles.set_size(domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(0), 2); for (int32_T i1{0}; i1 < 2; i1++) { for (int32_T i2{0}; i2 < loop_ub; i2++) { b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = - domainSldProfiles[1].f1[i2 + domainSldProfiles[1].f1.size(0) * + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i2 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * i1]; } } - loop_ub = domainSldProfiles[1].f1.size(0); - b_loop_ub = domainSldProfiles[1].f1.size(0); - c_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size + (0); + c_domainSldProfiles.set_size(domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(0), 2); for (int32_T i1{0}; i1 < loop_ub; i1++) { - c_domainSldProfiles[i1] = domainSldProfiles[1].f1[i1]; - } - - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1[i1]; c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = - domainSldProfiles[1].f1[i1 + domainSldProfiles[1].f1.size(0) * 2]; + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i1 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + 2]; } - c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + b_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, controls->resamPars, r.f1); } @@ -212,49 +208,52 @@ namespace RAT tempLayerSlds[b_i].f1[1] = r; tempAllLayers[b_i].f1[0] = r1; tempAllLayers[b_i].f1[1] = r; - r2.f1.set_size(domainSldProfiles[0].f1.size(0), domainSldProfiles[0]. - f1.size(1)); - loop_ub = domainSldProfiles[0].f1.size(1); + r2.f1.set_size(domainSldProfiles[b_i].f1.size(0), + domainSldProfiles[b_i].f1.size(1)); + loop_ub = domainSldProfiles[b_i].f1.size(1); for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = domainSldProfiles[0].f1.size(0); + b_loop_ub = domainSldProfiles[b_i].f1.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - r2.f1[i2 + r2.f1.size(0) * i1] = domainSldProfiles[0].f1[i2 + - domainSldProfiles[0].f1.size(0) * i1]; + r2.f1[i2 + r2.f1.size(0) * i1] = domainSldProfiles[b_i].f1[i2 + + domainSldProfiles[b_i].f1.size(0) * i1]; } } - r3.f1.set_size(domainSldProfiles[1].f1.size(0), domainSldProfiles[1]. - f1.size(1)); - loop_ub = domainSldProfiles[1].f1.size(1); + r3.f1.set_size(domainSldProfiles[b_i + domainSldProfiles.size(0)]. + f1.size(0), domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(1)); + loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(1); for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = domainSldProfiles[1].f1.size(0); + b_loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)]. + f1.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - r3.f1[i2 + r3.f1.size(0) * i1] = domainSldProfiles[1].f1[i2 + - domainSldProfiles[1].f1.size(0) * i1]; + r3.f1[i2 + r3.f1.size(0) * i1] = domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1[i2 + domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(0) * i1]; } } tempSldProfiles[b_i].f1[0] = r2; tempSldProfiles[b_i].f1[1] = r3; - b_problemDefCells.set_size(problemDefCells->f2 - [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> - f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); - loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + b_problemCells.set_size(problemCells->f2[problemCells->f2.size(0) * + b_i].f1.size(0), problemCells->f2[problemCells->f2.size(0) * b_i]. + f1.size(1)); + loop_ub = problemCells->f2[b_i].f1.size(1) - 1; for (int32_T i1{0}; i1 <= loop_ub; i1++) { - b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + b_loop_ub = problemCells->f2[b_i].f1.size(0) - 1; for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { - b_problemDefCells[i2 + b_problemDefCells.size(0) * i1] = - problemDefCells->f2[b_i].f1[i2 + problemDefCells->f2[b_i]. - f1.size(0) * i1]; + b_problemCells[i2 + b_problemCells.size(0) * i1] = + problemCells->f2[b_i].f1[i2 + problemCells->f2[b_i].f1.size(0) * + i1]; } } - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> - dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemStruct-> + dataPresent[b_i], b_problemCells, b_dv, b_dv1, shiftedDat); shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); loop_ub = shiftedDat.size(1); for (int32_T i1{0}; i1 < loop_ub; i1++) { @@ -274,10 +273,10 @@ namespace RAT } } - b_dv[0] = problemDefCells->f4[b_i].f1[0]; - b_dv[1] = problemDefCells->f4[b_i].f1[1]; - b_dv1[0] = problemDefCells->f1[b_i].f1[0]; - b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f4[b_i].f1[0]; + b_dv[1] = problemCells->f4[b_i].f1[1]; + b_dv1[0] = problemCells->f1[b_i].f1[0]; + b_dv1[1] = problemCells->f1[b_i].f1[1]; b_callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, r4, allRoughs[b_i], resolutionParams[b_i], useImaginary, reflect1, @@ -291,23 +290,23 @@ namespace RAT } } - b_dv[0] = problemDefCells->f4[b_i].f1[0]; - b_dv[1] = problemDefCells->f4[b_i].f1[1]; - b_dv1[0] = problemDefCells->f1[b_i].f1[0]; - b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f4[b_i].f1[0]; + b_dv[1] = problemCells->f4[b_i].f1[1]; + b_dv1[0] = problemCells->f1[b_i].f1[0]; + b_dv1[1] = problemCells->f1[b_i].f1[1]; b_callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, r4, allRoughs[b_i], resolutionParams[b_i], useImaginary, reflect2, simul2); applyBackgroundCorrection(reflect1, simul1, shiftedDat, - backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + backgroundParams[b_i], problemStruct->contrastBackgroundsType[b_i]); applyBackgroundCorrection(reflect2, simul2, shiftedDat, - backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + backgroundParams[b_i], problemStruct->contrastBackgroundsType[b_i]); // Calculate the average reflectivities.... averageReflectivity(reflect1, reflect2, simul1, simul2, - problemDef->domainRatio[static_cast - (problemDef->contrastDomainRatios[b_i]) - 1], + problemStruct->domainRatio[static_cast + (problemStruct->contrastDomainRatios[b_i]) - 1], totReflect, simulation[b_i].f1); loop_ub = totReflect.size(0); reflectivity[b_i].f1.set_size(totReflect.size(0), 2); @@ -318,9 +317,9 @@ namespace RAT } } - if (problemDef->dataPresent[b_i] != 0.0) { + if (problemStruct->dataPresent[b_i] != 0.0) { chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast - (problemDef->params.size(1))); + (problemStruct->params.size(1))); } else { chis[b_i] = 0.0; } diff --git a/RAT/parallelPoints5.h b/RAT/parallelPoints5.h index 7a4b5224..740599d7 100644 --- a/RAT/parallelPoints5.h +++ b/RAT/parallelPoints5.h @@ -11,18 +11,13 @@ #define PARALLELPOINTS5_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,16 +25,16 @@ namespace RAT { namespace customXY { - void parallelPoints(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, ::coder:: + void parallelPoints(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, ::coder:: array &outSsubs, ::coder::array &backgroundParams, ::coder::array &qzshifts, ::coder::array &scalefactors, :: coder::array &bulkIns, ::coder::array< real_T, 1U> &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder:: - array &simulation, ::coder::array< + coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array< cell_wrap_8, 1U> &shiftedData, ::coder::array< cell_wrap_8, 2U> &layerSlds, ::coder::array< cell_wrap_8, 2U> &domainSldProfiles, ::coder::array< diff --git a/RAT/parseResultToStruct.cpp b/RAT/parseResultToStruct.cpp new file mode 100644 index 00000000..7f92d87f --- /dev/null +++ b/RAT/parseResultToStruct.cpp @@ -0,0 +1,110 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parseResultToStruct.cpp +// +// Code generation for function 'parseResultToStruct' +// + +// Include files +#include "parseResultToStruct.h" +#include "RATMain_internal_types.h" +#include "RATMain_types.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +namespace RAT +{ + void parseResultToStruct(const d_struct_T *contrastParams, const cell_wrap_9 + resultCells[6], ::coder::array &result_reflectivity, :: + coder::array &result_simulation, ::coder::array &result_shiftedData, ::coder::array &result_layerSlds, :: + coder::array &result_sldProfiles, ::coder::array< + cell_wrap_8, 2U> &result_allLayers, real_T *result_calculationResults_sumChi, + d_struct_T *result_contrastParams) + { + int32_T b_loop_ub; + int32_T loop_ub; + result_reflectivity.set_size(resultCells[0].f1.size(0), resultCells[0]. + f1.size(1)); + loop_ub = resultCells[0].f1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = resultCells[0].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + result_reflectivity[i1 + result_reflectivity.size(0) * i] = resultCells + [0].f1[i1 + resultCells[0].f1.size(0) * i]; + } + } + + // Reflectivity art points + result_simulation.set_size(resultCells[1].f1.size(0), resultCells[1].f1.size + (1)); + loop_ub = resultCells[1].f1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = resultCells[1].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + result_simulation[i1 + result_simulation.size(0) * i] = resultCells[1]. + f1[i1 + resultCells[1].f1.size(0) * i]; + } + } + + // Reflectivity between sim limits + result_shiftedData.set_size(resultCells[2].f1.size(0), resultCells[2]. + f1.size(1)); + loop_ub = resultCells[2].f1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = resultCells[2].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + result_shiftedData[i1 + result_shiftedData.size(0) * i] = resultCells[2] + .f1[i1 + resultCells[2].f1.size(0) * i]; + } + } + + // Data corrected for sfs + result_layerSlds.set_size(resultCells[3].f1.size(0), resultCells[3].f1.size + (1)); + loop_ub = resultCells[3].f1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = resultCells[3].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + result_layerSlds[i1 + result_layerSlds.size(0) * i] = resultCells[3] + .f1[i1 + resultCells[3].f1.size(0) * i]; + } + } + + // Layers if defined (i.e. not customXY) + result_sldProfiles.set_size(resultCells[4].f1.size(0), resultCells[4]. + f1.size(1)); + loop_ub = resultCells[4].f1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = resultCells[4].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + result_sldProfiles[i1 + result_sldProfiles.size(0) * i] = resultCells[4] + .f1[i1 + resultCells[4].f1.size(0) * i]; + } + } + + // Calculated SLD profiles + result_allLayers.set_size(resultCells[5].f1.size(0), resultCells[5].f1.size + (1)); + loop_ub = resultCells[5].f1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = resultCells[5].f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + result_allLayers[i1 + result_allLayers.size(0) * i] = resultCells[5] + .f1[i1 + resultCells[5].f1.size(0) * i]; + } + } + + // Resampled layers + // For compile, we can't remove a field, so just clear it for now... + // contrastParams = rmfield(contrastParams,'calculations'); + *result_contrastParams = *contrastParams; + *result_calculationResults_sumChi = contrastParams->calculations.sumChi; + } +} + +// End of code generation (parseResultToStruct.cpp) diff --git a/RAT/parseResultToStruct.h b/RAT/parseResultToStruct.h new file mode 100644 index 00000000..f12dd732 --- /dev/null +++ b/RAT/parseResultToStruct.h @@ -0,0 +1,40 @@ +// +// Non-Degree Granting Education License -- for use at non-degree +// granting, nonprofit, education, and research organizations only. Not +// for commercial or industrial use. +// +// parseResultToStruct.h +// +// Code generation for function 'parseResultToStruct' +// +#ifndef PARSERESULTTOSTRUCT_H +#define PARSERESULTTOSTRUCT_H + +// Include files +#include "RATMain_types.h" +#include "rtwtypes.h" +#include "coder_array.h" +#include +#include + +// Type Declarations +namespace RAT +{ + struct d_struct_T; +} + +// Function Declarations +namespace RAT +{ + void parseResultToStruct(const d_struct_T *contrastParams, const cell_wrap_9 + resultCells[6], ::coder::array &result_reflectivity, :: + coder::array &result_simulation, ::coder::array &result_shiftedData, ::coder::array &result_layerSlds, :: + coder::array &result_sldProfiles, ::coder::array< + cell_wrap_8, 2U> &result_allLayers, real_T *result_calculationResults_sumChi, + d_struct_T *result_contrastParams); +} + +#endif + +// End of code generation (parseResultToStruct.h) diff --git a/RAT/processBayes.cpp b/RAT/processBayes.cpp index 95e46dce..d942c8d3 100644 --- a/RAT/processBayes.cpp +++ b/RAT/processBayes.cpp @@ -12,6 +12,7 @@ #include "processBayes.h" #include "RATMain_internal_types.h" #include "RATMain_types.h" +#include "parseResultToStruct.h" #include "prctileConfInts.h" #include "refPrctileConfInts.h" #include "reflectivityCalculation.h" @@ -24,32 +25,38 @@ namespace RAT { void processBayes(const real_T bayesOutputs_bestPars_data[], const int32_T bayesOutputs_bestPars_size[2], const ::coder::array &bayesOutputs_chain, const struct5_T *allProblem_f1, - const struct2_T *allProblem_f2, const cell_14 *allProblem_f4, - struct5_T *problemDef, struct_T *outProblem, cell_13 *result, - e_struct_T *bayesResults_bestFitsMean, f_struct_T - *bayesResults_predlims, struct11_T *bayesResults_parConfInts) + 2U> &bayesOutputs_chain, const c_struct_T *allProblem_f1, + const struct2_T *allProblem_f2, const cell_11 *allProblem_f4, + c_struct_T *problemStruct, d_struct_T *contrastParams, + cell_wrap_9 result[6], e_struct_T *bayesResults_bestFitsMean, + f_struct_T *bayesResults_predlims, struct10_T + *bayesResults_parConfInts) { static struct2_T controlsStruct; - struct5_T b_problemDef; + ::coder::array b_expl_temp; + ::coder::array c_expl_temp; + ::coder::array expl_temp; + c_struct_T b_problemStruct; + d_struct_T d_expl_temp; + real_T p_calculationResults_sumChi; int32_T loop_ub; - // problem = {problemDef ; controls ; problemDefLimits ; problemDefCells}; - *problemDef = *allProblem_f1; + // problem = {problemStruct ; controls ; problemLimits ; problemCells}; + *problemStruct = *allProblem_f1; controlsStruct = *allProblem_f2; // Need to impose that we calculate the SLD.. controlsStruct.calcSldDuringFit = true; // ... and use the Bayes bestpars - problemDef->fitParams.set_size(1, bayesOutputs_bestPars_size[1]); + problemStruct->fitParams.set_size(1, bayesOutputs_bestPars_size[1]); loop_ub = bayesOutputs_bestPars_size[1]; for (int32_T i{0}; i < loop_ub; i++) { - problemDef->fitParams[problemDef->fitParams.size(0) * i] = + problemStruct->fitParams[problemStruct->fitParams.size(0) * i] = bayesOutputs_bestPars_data[i]; } - unpackParams(problemDef, allProblem_f2->checks.fitParam, + unpackParams(problemStruct, allProblem_f2->checks.fitParam, allProblem_f2->checks.fitBackgroundParam, allProblem_f2->checks.fitQzshift, allProblem_f2->checks.fitScalefactor, @@ -62,66 +69,18 @@ namespace RAT bayesResults_parConfInts->mean); // iterShortest(output.chain,length(fitNames),[],0.95); - // % 2. Find maximum values of posteriors. Store the max and mean posterior - // % values, and calculate the best fit and SLD's from these. - // [bestPars_max,posteriors] = findPosteriorsMax(output.chain); - // bestPars_mean = output.results.mean; - // % Calculate Max best fit curves - // controls.calcSldDuringFit = true; - // problemDef.fitParams = bestPars_max; - // problemDef = unpackParams(problemDef,controls); - // [outProblem,result] = reflectivityCalculation(problemDef,problemDefCells,controls); - // bestFitMax_Ref = result(1); - // bestFitMax_Sld = result(5); - // bestFitMax_chi = outProblem.calculations.sumChi; // Calculate 'mean' best fit curves - // problemDef.fitParams = parConfInts.mean; - // problemDef = unpackParams(problemDef,controlsStruct); - reflectivityCalculation(problemDef, allProblem_f4, &controlsStruct, - outProblem, result); - - // Reflectivity art points - // Reflectivity between sim limits - // Data corrected for sfs - // Layers if defined (i.e. not customXY) - // Calculated SLD profiles - // Resampled layers - // For compile, we can't remove a field, so just clear it for now... - // problem = rmfield(problem,'calculations'); - bayesResults_bestFitsMean->ref.set_size(result->f1.size(0)); - loop_ub = result->f1.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - bayesResults_bestFitsMean->ref[i] = result->f1[i]; - } - - bayesResults_bestFitsMean->sld.set_size(result->f5.size(0), result->f5.size - (1)); - loop_ub = result->f5.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - int32_T b_loop_ub; - b_loop_ub = result->f5.size(0); - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - bayesResults_bestFitsMean->sld[i1 + bayesResults_bestFitsMean->sld.size - (0) * i] = result->f5[i1 + result->f5.size(0) * i]; - } - } - - bayesResults_bestFitsMean->chi = outProblem->calculations.sumChi; - bayesResults_bestFitsMean->data.set_size(result->f3.size(0)); - loop_ub = result->f3.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - bayesResults_bestFitsMean->data[i] = result->f3[i]; - } + reflectivityCalculation(problemStruct, allProblem_f4, &controlsStruct, + contrastParams, result); + parseResultToStruct(contrastParams, result, bayesResults_bestFitsMean->ref, + expl_temp, bayesResults_bestFitsMean->data, b_expl_temp, + bayesResults_bestFitsMean->sld, c_expl_temp, + &p_calculationResults_sumChi, &d_expl_temp); + bayesResults_bestFitsMean->chi = p_calculationResults_sumChi; // 2. Reflectivity and SLD shading - // predIntRef = mcmcpred_compile(output.results,output.chain,[],output.data,problem,500); - // predIntRef = predIntRef.predlims; - // - // predIntSld_calcs = mcmcpred_compile_sld(output.results,output.chain,bestFitMean_Sld,[],output.data,problem,500); - // predIntSld = predIntSld_calcs.predlims; - // predIntSld_xdata = predIntSld_calcs.data; - b_problemDef = *problemDef; - refPrctileConfInts(bayesOutputs_chain, &b_problemDef, allProblem_f4, + b_problemStruct = *problemStruct; + refPrctileConfInts(bayesOutputs_chain, &b_problemStruct, allProblem_f4, &controlsStruct, bayesResults_predlims); // --------------------------------- @@ -137,32 +96,37 @@ namespace RAT void processBayes(const ::coder::array &bayesOutputs_bestPars, const ::coder::array &bayesOutputs_chain, const - struct5_T *allProblem_f1, const struct2_T *allProblem_f2, - const cell_14 *allProblem_f4, struct5_T *problemDef, - struct_T *outProblem, cell_13 *result, e_struct_T - *bayesResults_bestFitsMean, f_struct_T - *bayesResults_predlims, struct11_T *bayesResults_parConfInts) + c_struct_T *allProblem_f1, const struct2_T *allProblem_f2, + const cell_11 *allProblem_f4, c_struct_T *problemStruct, + d_struct_T *contrastParams, cell_wrap_9 result[6], + e_struct_T *bayesResults_bestFitsMean, f_struct_T + *bayesResults_predlims, struct10_T *bayesResults_parConfInts) { - struct2_T controlsStruct; - struct5_T b_problemDef; + static struct2_T controlsStruct; + ::coder::array b_expl_temp; + ::coder::array c_expl_temp; + ::coder::array expl_temp; + c_struct_T b_problemStruct; + d_struct_T d_expl_temp; + real_T p_calculationResults_sumChi; int32_T loop_ub; - // problem = {problemDef ; controls ; problemDefLimits ; problemDefCells}; - *problemDef = *allProblem_f1; + // problem = {problemStruct ; controls ; problemLimits ; problemCells}; + *problemStruct = *allProblem_f1; controlsStruct = *allProblem_f2; // Need to impose that we calculate the SLD.. controlsStruct.calcSldDuringFit = true; // ... and use the Bayes bestpars - problemDef->fitParams.set_size(1, bayesOutputs_bestPars.size(1)); + problemStruct->fitParams.set_size(1, bayesOutputs_bestPars.size(1)); loop_ub = bayesOutputs_bestPars.size(1); for (int32_T i{0}; i < loop_ub; i++) { - problemDef->fitParams[problemDef->fitParams.size(0) * i] = + problemStruct->fitParams[problemStruct->fitParams.size(0) * i] = bayesOutputs_bestPars[i]; } - unpackParams(problemDef, allProblem_f2->checks.fitParam, + unpackParams(problemStruct, allProblem_f2->checks.fitParam, allProblem_f2->checks.fitBackgroundParam, allProblem_f2->checks.fitQzshift, allProblem_f2->checks.fitScalefactor, @@ -175,66 +139,18 @@ namespace RAT bayesResults_parConfInts->mean); // iterShortest(output.chain,length(fitNames),[],0.95); - // % 2. Find maximum values of posteriors. Store the max and mean posterior - // % values, and calculate the best fit and SLD's from these. - // [bestPars_max,posteriors] = findPosteriorsMax(output.chain); - // bestPars_mean = output.results.mean; - // % Calculate Max best fit curves - // controls.calcSldDuringFit = true; - // problemDef.fitParams = bestPars_max; - // problemDef = unpackParams(problemDef,controls); - // [outProblem,result] = reflectivityCalculation(problemDef,problemDefCells,controls); - // bestFitMax_Ref = result(1); - // bestFitMax_Sld = result(5); - // bestFitMax_chi = outProblem.calculations.sumChi; // Calculate 'mean' best fit curves - // problemDef.fitParams = parConfInts.mean; - // problemDef = unpackParams(problemDef,controlsStruct); - reflectivityCalculation(problemDef, allProblem_f4, &controlsStruct, - outProblem, result); - - // Reflectivity art points - // Reflectivity between sim limits - // Data corrected for sfs - // Layers if defined (i.e. not customXY) - // Calculated SLD profiles - // Resampled layers - // For compile, we can't remove a field, so just clear it for now... - // problem = rmfield(problem,'calculations'); - bayesResults_bestFitsMean->ref.set_size(result->f1.size(0)); - loop_ub = result->f1.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - bayesResults_bestFitsMean->ref[i] = result->f1[i]; - } - - bayesResults_bestFitsMean->sld.set_size(result->f5.size(0), result->f5.size - (1)); - loop_ub = result->f5.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - int32_T b_loop_ub; - b_loop_ub = result->f5.size(0); - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - bayesResults_bestFitsMean->sld[i1 + bayesResults_bestFitsMean->sld.size - (0) * i] = result->f5[i1 + result->f5.size(0) * i]; - } - } - - bayesResults_bestFitsMean->chi = outProblem->calculations.sumChi; - bayesResults_bestFitsMean->data.set_size(result->f3.size(0)); - loop_ub = result->f3.size(0); - for (int32_T i{0}; i < loop_ub; i++) { - bayesResults_bestFitsMean->data[i] = result->f3[i]; - } + reflectivityCalculation(problemStruct, allProblem_f4, &controlsStruct, + contrastParams, result); + parseResultToStruct(contrastParams, result, bayesResults_bestFitsMean->ref, + expl_temp, bayesResults_bestFitsMean->data, b_expl_temp, + bayesResults_bestFitsMean->sld, c_expl_temp, + &p_calculationResults_sumChi, &d_expl_temp); + bayesResults_bestFitsMean->chi = p_calculationResults_sumChi; // 2. Reflectivity and SLD shading - // predIntRef = mcmcpred_compile(output.results,output.chain,[],output.data,problem,500); - // predIntRef = predIntRef.predlims; - // - // predIntSld_calcs = mcmcpred_compile_sld(output.results,output.chain,bestFitMean_Sld,[],output.data,problem,500); - // predIntSld = predIntSld_calcs.predlims; - // predIntSld_xdata = predIntSld_calcs.data; - b_problemDef = *problemDef; - refPrctileConfInts(bayesOutputs_chain, &b_problemDef, allProblem_f4, + b_problemStruct = *problemStruct; + refPrctileConfInts(bayesOutputs_chain, &b_problemStruct, allProblem_f4, &controlsStruct, bayesResults_predlims); // --------------------------------- diff --git a/RAT/processBayes.h b/RAT/processBayes.h index 2352b2b7..070fb069 100644 --- a/RAT/processBayes.h +++ b/RAT/processBayes.h @@ -19,14 +19,14 @@ // Type Declarations namespace RAT { - struct struct5_T; + struct c_struct_T; struct struct2_T; - struct cell_14; - struct struct_T; - struct cell_13; + struct cell_11; + struct d_struct_T; + struct cell_wrap_9; struct e_struct_T; struct f_struct_T; - struct struct11_T; + struct struct10_T; } // Function Declarations @@ -34,18 +34,19 @@ namespace RAT { void processBayes(const real_T bayesOutputs_bestPars_data[], const int32_T bayesOutputs_bestPars_size[2], const ::coder::array &bayesOutputs_chain, const struct5_T *allProblem_f1, - const struct2_T *allProblem_f2, const cell_14 *allProblem_f4, - struct5_T *problemDef, struct_T *outProblem, cell_13 *result, - e_struct_T *bayesResults_bestFitsMean, f_struct_T - *bayesResults_predlims, struct11_T *bayesResults_parConfInts); + 2U> &bayesOutputs_chain, const c_struct_T *allProblem_f1, + const struct2_T *allProblem_f2, const cell_11 *allProblem_f4, + c_struct_T *problemStruct, d_struct_T *contrastParams, + cell_wrap_9 result[6], e_struct_T *bayesResults_bestFitsMean, + f_struct_T *bayesResults_predlims, struct10_T + *bayesResults_parConfInts); void processBayes(const ::coder::array &bayesOutputs_bestPars, const ::coder::array &bayesOutputs_chain, const - struct5_T *allProblem_f1, const struct2_T *allProblem_f2, - const cell_14 *allProblem_f4, struct5_T *problemDef, - struct_T *outProblem, cell_13 *result, e_struct_T - *bayesResults_bestFitsMean, f_struct_T - *bayesResults_predlims, struct11_T *bayesResults_parConfInts); + c_struct_T *allProblem_f1, const struct2_T *allProblem_f2, + const cell_11 *allProblem_f4, c_struct_T *problemStruct, + d_struct_T *contrastParams, cell_wrap_9 result[6], + e_struct_T *bayesResults_bestFitsMean, f_struct_T + *bayesResults_predlims, struct10_T *bayesResults_parConfInts); } #endif diff --git a/RAT/processCustomFunction.cpp b/RAT/processCustomFunction.cpp index 10140260..30166525 100644 --- a/RAT/processCustomFunction.cpp +++ b/RAT/processCustomFunction.cpp @@ -13,7 +13,6 @@ #include "RATMain_types.h" #include "applyHydrationImag.h" #include "applyHydrationReal.h" -#include "backSort.h" #include "callCppFunction.h" #include "rt_nonfinite.h" #include "str2double.h" @@ -23,14 +22,14 @@ // Function Declarations namespace RAT { - static void cast(const ::coder::array &r, ::coder::array< + static void cast(const ::coder::array &r, ::coder::array< cell_wrap_8, 1U> &r1); } // Function Definitions namespace RAT { - static void cast(const ::coder::array &r, ::coder::array< + static void cast(const ::coder::array &r, ::coder::array< cell_wrap_8, 1U> &r1) { int32_T i; @@ -56,54 +55,44 @@ namespace RAT namespace customLayers { void processCustomFunction(const ::coder::array - &contrastBackgrounds, const ::coder::array &contrastQzshifts, - const ::coder::array &contrastScalefactors, const ::coder:: - array &contrastBulkIns, const ::coder::array - &contrastBulkOuts, const ::coder::array &contrastResolutions, - const ::coder::array &backgroundParam, const ::coder::array< - real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + &contrastBulkIns, const ::coder::array &contrastBulkOuts, const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: - array &cCustFiles, real_T numberOfContrasts, const ::coder:: - array &customFiles, const ::coder::array - ¶ms, boolean_T useImaginary, ::coder::array - &allLayers, ::coder::array &allRoughs) + 2U> &bulkOut, const ::coder::array &cCustFiles, real_T + numberOfContrasts, const ::coder::array &customFiles, + const ::coder::array ¶ms, boolean_T useImaginary, :: + coder::array &allLayers, ::coder::array + &allRoughs) { - ::coder::array tempAllLayers; + ::coder::array tempAllLayers; + ::coder::array allBulkOuts; + ::coder::array b_allBulkOuts; ::coder::array b_params; - ::coder::array b_thisContrastLayers; ::coder::array thisContrastLayers; - real_T a__1; - real_T a__2; - real_T a__3; - real_T a__4; - real_T thisBulkIn; - real_T thisBulkOut; int32_T i; + int32_T loop_ub; // Top-level function for processing custom layers for all the // contrasts. // Do some pre-definitions to keep the compiler happy... i = static_cast(numberOfContrasts); allRoughs.set_size(i); + allBulkOuts.set_size(1, contrastBulkOuts.size(1)); + loop_ub = contrastBulkOuts.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + allBulkOuts[i1] = bulkOut[static_cast(contrastBulkOuts[i1]) - + 1]; + } + tempAllLayers.set_size(i); for (int32_T b_i{0}; b_i < i; b_i++) { creal_T x; real_T d; int32_T iv[2]; - int32_T b_loop_ub; - int32_T loop_ub; // TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's.. // Choose which custom file is associated with this contrast // Find values of 'bulkIn' and 'bulkOut' for this // contrast... - backSort(contrastBackgrounds[b_i], contrastQzshifts[b_i], - contrastScalefactors[b_i], contrastBulkIns[b_i], - contrastBulkOuts[b_i], contrastResolutions[b_i], - backgroundParam, qzshifts, scalefactor, bulkIn, bulkOut, res, - &a__1, &a__2, &a__3, &thisBulkIn, &thisBulkOut, &a__4); - // typeDef d = cCustFiles[b_i]; iv[0] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ @@ -119,39 +108,40 @@ namespace RAT b_params[i1] = params[i1]; } + b_allBulkOuts.set_size(1, allBulkOuts.size(1)); + loop_ub = allBulkOuts.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_allBulkOuts[i1] = allBulkOuts[i1]; + } + iv[0] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(d) - 1].f1)->size())[0]; iv[1] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(d) - 1].f1)->size())[1]; - callCppFunction(b_params, thisBulkIn, thisBulkOut, - static_cast(b_i) + 1.0, (const char_T *)((:: - coder::array *)&customFiles[static_cast(d) - - 1].f1)->data(), iv, b_thisContrastLayers, &allRoughs[b_i]); - loop_ub = b_thisContrastLayers.size(1); - thisContrastLayers.set_size(b_thisContrastLayers.size(0), - b_thisContrastLayers.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = b_thisContrastLayers.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - thisContrastLayers[i2 + thisContrastLayers.size(0) * i1] = - b_thisContrastLayers[i2 + b_thisContrastLayers.size(0) * i1]; - } - } + callCppFunction((const char_T *)((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->data(), iv, + b_params, bulkIn[static_cast + (contrastBulkIns[b_i]) - 1], b_allBulkOuts, ( + static_cast(b_i) + 1.0) - 1.0, thisContrastLayers, + &allRoughs[b_i]); } // If the output layers has 5 columns, then we need to do // the hydration correction (the user has not done it in the // custom function). Do that here.... if (!useImaginary) { - applyHydrationReal(thisContrastLayers, thisBulkIn, thisBulkOut); + applyHydrationReal(thisContrastLayers, bulkIn[static_cast + (contrastBulkIns[b_i]) - 1], allBulkOuts[b_i]); } else { - applyHydrationImag(thisContrastLayers, thisBulkIn, thisBulkOut); + applyHydrationImag(thisContrastLayers, bulkIn[static_cast + (contrastBulkIns[b_i]) - 1], allBulkOuts[b_i]); } + loop_ub = thisContrastLayers.size(1); tempAllLayers[b_i].f1.set_size(thisContrastLayers.size(0), thisContrastLayers.size(1)); - loop_ub = thisContrastLayers.size(1); for (int32_T i1{0}; i1 < loop_ub; i1++) { + int32_T b_loop_ub; b_loop_ub = thisContrastLayers.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { tempAllLayers[b_i].f1[i2 + tempAllLayers[b_i].f1.size(0) * i1] = diff --git a/RAT/processCustomFunction.h b/RAT/processCustomFunction.h index bf909b8b..630d6f28 100644 --- a/RAT/processCustomFunction.h +++ b/RAT/processCustomFunction.h @@ -25,18 +25,13 @@ namespace RAT namespace customLayers { void processCustomFunction(const ::coder::array - &contrastBackgrounds, const ::coder::array &contrastQzshifts, - const ::coder::array &contrastScalefactors, const ::coder:: - array &contrastBulkIns, const ::coder::array - &contrastBulkOuts, const ::coder::array &contrastResolutions, - const ::coder::array &backgroundParam, const ::coder::array< - real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + &contrastBulkIns, const ::coder::array &contrastBulkOuts, const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: - array &cCustFiles, real_T numberOfContrasts, const ::coder:: - array &customFiles, const ::coder::array - ¶ms, boolean_T useImaginary, ::coder::array - &allLayers, ::coder::array &allRoughs); + 2U> &bulkOut, const ::coder::array &cCustFiles, real_T + numberOfContrasts, const ::coder::array &customFiles, + const ::coder::array ¶ms, boolean_T useImaginary, :: + coder::array &allLayers, ::coder::array + &allRoughs); } } } diff --git a/RAT/processCustomFunction1.cpp b/RAT/processCustomFunction1.cpp index ab897761..2bf9c06b 100644 --- a/RAT/processCustomFunction1.cpp +++ b/RAT/processCustomFunction1.cpp @@ -12,7 +12,6 @@ #include "processCustomFunction1.h" #include "RATMain_internal_types.h" #include "RATMain_types.h" -#include "backSort.h" #include "callCppFunction.h" #include "rt_nonfinite.h" #include "str2double.h" @@ -22,14 +21,14 @@ // Function Declarations namespace RAT { - static void cast(const ::coder::array &r, ::coder::array< + static void cast(const ::coder::array &r, ::coder::array< cell_wrap_8, 1U> &r1); } // Function Definitions namespace RAT { - static void cast(const ::coder::array &r, ::coder::array< + static void cast(const ::coder::array &r, ::coder::array< cell_wrap_8, 1U> &r1) { int32_T i; @@ -55,29 +54,20 @@ namespace RAT namespace customXY { void processCustomFunction(const ::coder::array - &contrastBackgrounds, const ::coder::array &contrastQzshifts, - const ::coder::array &contrastScalefactors, const ::coder:: - array &contrastBulkIns, const ::coder::array - &contrastBulkOuts, const ::coder::array &contrastResolutions, - const ::coder::array &backgroundParams, const ::coder::array< - real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + &contrastBulkIns, const ::coder::array &contrastBulkOuts, const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: - array &cCustFiles, real_T numberOfContrasts, const ::coder:: - array &customFiles, const ::coder::array - ¶ms, ::coder::array &allSLDs, ::coder::array &allRoughs) + 2U> &bulkOut, const ::coder::array &cCustFiles, real_T + numberOfContrasts, const ::coder::array &customFiles, + const ::coder::array ¶ms, ::coder::array + &allSLDs, ::coder::array &allRoughs) { - ::coder::array tempAllSLDs; + ::coder::array tempAllSLDs; + ::coder::array allBulkOuts; + ::coder::array b_allBulkOuts; ::coder::array b_params; ::coder::array r; - real_T a__1; - real_T a__2; - real_T a__3; - real_T a__4; - real_T thisBulkIn; - real_T thisBulkOut; int32_T i; + int32_T loop_ub; // Top-level function for processing custom XY profiles for all the // contrasts. @@ -86,6 +76,13 @@ namespace RAT allRoughs.set_size(i); // 3 columns to allow for potential imaginary curve + allBulkOuts.set_size(1, contrastBulkOuts.size(1)); + loop_ub = contrastBulkOuts.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + allBulkOuts[i1] = bulkOut[static_cast(contrastBulkOuts[i1]) - + 1]; + } + tempAllSLDs.set_size(i); for (int32_T b_i{0}; b_i < i; b_i++) { creal_T x; @@ -96,11 +93,6 @@ namespace RAT // Choose which custom file is associated with this contrast // Find values of 'bulkIn' and 'bulkOut' for this // contrast... - backSort(contrastBackgrounds[b_i], contrastQzshifts[b_i], - contrastScalefactors[b_i], contrastBulkIns[b_i], - contrastBulkOuts[b_i], contrastResolutions[b_i], - backgroundParams, qzshifts, scalefactor, bulkIn, bulkOut, res, - &a__1, &a__2, &a__3, &thisBulkIn, &thisBulkOut, &a__4); d = cCustFiles[b_i]; iv[0] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ static_cast(d) - 1].f1)->size())[0]; @@ -109,21 +101,27 @@ namespace RAT x = coder::str2double((const char_T *)((::coder::array *) &customFiles[static_cast(d) - 1].f1)->data(), iv); if ((!std::isnan(x.re)) && (!std::isnan(x.im))) { - int32_T loop_ub; b_params.set_size(1, params.size(1)); loop_ub = params.size(1) - 1; for (int32_T i1{0}; i1 <= loop_ub; i1++) { b_params[i1] = params[i1]; } + b_allBulkOuts.set_size(1, allBulkOuts.size(1)); + loop_ub = allBulkOuts.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_allBulkOuts[i1] = allBulkOuts[i1]; + } + iv[0] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(d) - 1].f1)->size())[0]; iv[1] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(d) - 1].f1)->size())[1]; - callCppFunction(b_params, thisBulkIn, thisBulkOut, - static_cast(b_i) + 1.0, (const char_T *)((:: - coder::array *)&customFiles[static_cast(d) - - 1].f1)->data(), iv, r, &allRoughs[b_i]); + callCppFunction((const char_T *)((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->data(), iv, + b_params, bulkIn[static_cast + (contrastBulkIns[b_i]) - 1], b_allBulkOuts, ( + static_cast(b_i) + 1.0) - 1.0, r, &allRoughs[b_i]); loop_ub = r.size(1); tempAllSLDs[b_i].f1.set_size(r.size(0), r.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { diff --git a/RAT/processCustomFunction1.h b/RAT/processCustomFunction1.h index 59f10e75..be19a812 100644 --- a/RAT/processCustomFunction1.h +++ b/RAT/processCustomFunction1.h @@ -25,18 +25,12 @@ namespace RAT namespace customXY { void processCustomFunction(const ::coder::array - &contrastBackgrounds, const ::coder::array &contrastQzshifts, - const ::coder::array &contrastScalefactors, const ::coder:: - array &contrastBulkIns, const ::coder::array - &contrastBulkOuts, const ::coder::array &contrastResolutions, - const ::coder::array &backgroundParams, const ::coder::array< - real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + &contrastBulkIns, const ::coder::array &contrastBulkOuts, const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: - array &cCustFiles, real_T numberOfContrasts, const ::coder:: - array &customFiles, const ::coder::array - ¶ms, ::coder::array &allSLDs, ::coder::array &allRoughs); + 2U> &bulkOut, const ::coder::array &cCustFiles, real_T + numberOfContrasts, const ::coder::array &customFiles, + const ::coder::array ¶ms, ::coder::array + &allSLDs, ::coder::array &allRoughs); } } } diff --git a/RAT/processCustomFunction2.cpp b/RAT/processCustomFunction2.cpp index e1907960..f3fbc9cd 100644 --- a/RAT/processCustomFunction2.cpp +++ b/RAT/processCustomFunction2.cpp @@ -13,7 +13,6 @@ #include "RATMain_types.h" #include "applyHydrationImag.h" #include "applyHydrationReal.h" -#include "backSort.h" #include "callCppFunction.h" #include "rt_nonfinite.h" #include "str2double.h" @@ -28,32 +27,22 @@ namespace RAT namespace customLayers { void processCustomFunction(const ::coder::array - &contrastBackgrounds, const ::coder::array &contrastQzshifts, - const ::coder::array &contrastScalefactors, const ::coder:: - array &contrastBulkIns, const ::coder::array - &contrastBulkOuts, const ::coder::array &contrastResolutions, - const ::coder::array &backgroundParams, const ::coder::array< - real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + &contrastBulkIns, const ::coder::array &contrastBulkOuts, const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &resolutionParams, const :: - coder::array &cCustFiles, real_T numberOfContrasts, const :: - coder::array &customFiles, const ::coder::array ¶ms, boolean_T useImaginary, ::coder::array - &allLayers, ::coder::array &allRoughs) + 2U> &bulkOut, const ::coder::array &cCustFiles, real_T + numberOfContrasts, const ::coder::array &customFiles, + const ::coder::array ¶ms, boolean_T useImaginary, :: + coder::array &allLayers, ::coder::array + &allRoughs) { + ::coder::array allBulkOuts; + ::coder::array b_allBulkOuts; ::coder::array b_params; ::coder::array b_thisContrastLayers1; - ::coder::array c_thisContrastLayers1; ::coder::array thisContrastLayers1; - ::coder::array thisContrastLayers2; - real_T a__1; real_T a__2; - real_T a__3; - real_T a__4; - real_T a__6; - real_T thisBulkIn; - real_T thisBulkOut; int32_T i; + int32_T loop_ub; // Top-level function for processing custom layers for all the // contrasts. @@ -61,24 +50,23 @@ namespace RAT // totNumCalcs = numberOfContrasts * 2; i = static_cast(numberOfContrasts); allRoughs.set_size(i); + allBulkOuts.set_size(1, contrastBulkOuts.size(1)); + loop_ub = contrastBulkOuts.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + allBulkOuts[i1] = bulkOut[static_cast(contrastBulkOuts[i1]) - + 1]; + } + allLayers.set_size(i, 2); for (int32_T b_i{0}; b_i < i; b_i++) { creal_T x; real_T d; int32_T iv[2]; int32_T b_loop_ub; - int32_T loop_ub; // Choose which custom file is associated with this contrast // Find values of 'bulkIn' and 'bulkOut' for this // contrast... - backSort(contrastBackgrounds[b_i], contrastQzshifts[b_i], - contrastScalefactors[b_i], contrastBulkIns[b_i], - contrastBulkOuts[b_i], contrastResolutions[b_i], - backgroundParams, qzshifts, scalefactor, bulkIn, bulkOut, - resolutionParams, &a__1, &a__2, &a__3, &thisBulkIn, - &thisBulkOut, &a__4); - // typeDef d = cCustFiles[b_i]; iv[0] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ @@ -94,22 +82,30 @@ namespace RAT b_params[i1] = params[i1]; } + b_allBulkOuts.set_size(1, allBulkOuts.size(1)); + loop_ub = allBulkOuts.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_allBulkOuts[i1] = allBulkOuts[i1]; + } + iv[0] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(d) - 1].f1)->size())[0]; iv[1] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(d) - 1].f1)->size())[1]; - b_callCppFunction(b_params, thisBulkIn, thisBulkOut, - static_cast(b_i) + 1.0, (const char_T *)((:: - coder::array *)&customFiles[static_cast(d) - - 1].f1)->data(), iv, c_thisContrastLayers1, &allRoughs[b_i]); - loop_ub = c_thisContrastLayers1.size(1); - b_thisContrastLayers1.set_size(c_thisContrastLayers1.size(0), - c_thisContrastLayers1.size(1)); + b_callCppFunction((const char_T *)((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->data(), iv, + b_params, bulkIn[static_cast + (contrastBulkIns[b_i]) - 1], b_allBulkOuts, ( + static_cast(b_i) + 1.0) - 1.0, b_thisContrastLayers1, + &allRoughs[b_i]); + loop_ub = b_thisContrastLayers1.size(1); + thisContrastLayers1.set_size(b_thisContrastLayers1.size(0), + b_thisContrastLayers1.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = c_thisContrastLayers1.size(0); + b_loop_ub = b_thisContrastLayers1.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1] = - c_thisContrastLayers1[i2 + c_thisContrastLayers1.size(0) * i1]; + thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1] = + b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1]; } } @@ -119,146 +115,63 @@ namespace RAT b_params[i1] = params[i1]; } + b_allBulkOuts.set_size(1, allBulkOuts.size(1)); + loop_ub = allBulkOuts.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_allBulkOuts[i1] = allBulkOuts[i1]; + } + iv[0] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(cCustFiles[b_i]) - 1].f1) ->size())[0]; iv[1] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(cCustFiles[b_i]) - 1].f1) ->size())[1]; - c_callCppFunction(b_params, thisBulkIn, thisBulkOut, - static_cast(b_i) + 1.0, (const char_T *)((:: - coder::array *)&customFiles[static_cast - (cCustFiles[b_i]) - 1].f1)->data(), iv, c_thisContrastLayers1, - &a__6); - loop_ub = c_thisContrastLayers1.size(1); - thisContrastLayers2.set_size(c_thisContrastLayers1.size(0), - c_thisContrastLayers1.size(1)); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = c_thisContrastLayers1.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - thisContrastLayers2[i2 + thisContrastLayers2.size(0) * i1] = - c_thisContrastLayers1[i2 + c_thisContrastLayers1.size(0) * i1]; - } - } + c_callCppFunction((const char_T *)((::coder::array *) + &customFiles[static_cast(cCustFiles[b_i]) - 1].f1)->data(), + iv, b_params, bulkIn[static_cast + (contrastBulkIns[b_i]) - 1], b_allBulkOuts, ( + static_cast(b_i) + 1.0) - 1.0, b_thisContrastLayers1, + &a__2); } // If the output layers has 5 columns, then we need to do // the hydration correction (the user has not done it in the // custom function). Do that here.... if (!useImaginary) { - thisContrastLayers1.set_size(b_thisContrastLayers1.size(0), - b_thisContrastLayers1.size(1)); - loop_ub = b_thisContrastLayers1.size(1); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = b_thisContrastLayers1.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1] = - b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1]; - } - } - - applyHydrationReal(thisContrastLayers1, thisBulkIn, thisBulkOut); - b_thisContrastLayers1.set_size(thisContrastLayers1.size(0), - thisContrastLayers1.size(1)); - loop_ub = thisContrastLayers1.size(1); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = thisContrastLayers1.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1] = - thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1]; - } - } - - thisContrastLayers1.set_size(thisContrastLayers2.size(0), - thisContrastLayers2.size(1)); - loop_ub = thisContrastLayers2.size(1); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = thisContrastLayers2.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1] = - thisContrastLayers2[i2 + thisContrastLayers2.size(0) * i1]; - } - } - - applyHydrationReal(thisContrastLayers1, thisBulkIn, thisBulkOut); - thisContrastLayers2.set_size(thisContrastLayers1.size(0), - thisContrastLayers1.size(1)); - loop_ub = thisContrastLayers1.size(1); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = thisContrastLayers1.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - thisContrastLayers2[i2 + thisContrastLayers2.size(0) * i1] = - thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1]; - } - } + d = contrastBulkIns[b_i]; + applyHydrationReal(thisContrastLayers1, bulkIn[static_cast + (d) - 1], allBulkOuts[b_i]); + applyHydrationReal(b_thisContrastLayers1, bulkIn[static_cast + (d) - 1], allBulkOuts[b_i]); } else { - thisContrastLayers1.set_size(b_thisContrastLayers1.size(0), - b_thisContrastLayers1.size(1)); - loop_ub = b_thisContrastLayers1.size(1); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = b_thisContrastLayers1.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1] = - b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1]; - } - } - - applyHydrationImag(thisContrastLayers1, thisBulkIn, thisBulkOut); - b_thisContrastLayers1.set_size(thisContrastLayers1.size(0), - thisContrastLayers1.size(1)); - loop_ub = thisContrastLayers1.size(1); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = thisContrastLayers1.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1] = - thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1]; - } - } - - thisContrastLayers1.set_size(thisContrastLayers2.size(0), - thisContrastLayers2.size(1)); - loop_ub = thisContrastLayers2.size(1); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = thisContrastLayers2.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1] = - thisContrastLayers2[i2 + thisContrastLayers2.size(0) * i1]; - } - } - - applyHydrationImag(thisContrastLayers1, thisBulkIn, thisBulkOut); - thisContrastLayers2.set_size(thisContrastLayers1.size(0), - thisContrastLayers1.size(1)); - loop_ub = thisContrastLayers1.size(1); - for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = thisContrastLayers1.size(0); - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - thisContrastLayers2[i2 + thisContrastLayers2.size(0) * i1] = - thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1]; - } - } + d = contrastBulkIns[b_i]; + applyHydrationImag(thisContrastLayers1, bulkIn[static_cast + (d) - 1], allBulkOuts[b_i]); + applyHydrationImag(b_thisContrastLayers1, bulkIn[static_cast + (d) - 1], allBulkOuts[b_i]); } - allLayers[b_i].f1.set_size(b_thisContrastLayers1.size(0), - b_thisContrastLayers1.size(1)); - loop_ub = b_thisContrastLayers1.size(1); + allLayers[b_i].f1.set_size(thisContrastLayers1.size(0), + thisContrastLayers1.size(1)); + loop_ub = thisContrastLayers1.size(1); for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = b_thisContrastLayers1.size(0); + b_loop_ub = thisContrastLayers1.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { allLayers[b_i].f1[i2 + allLayers[b_i].f1.size(0) * i1] = - b_thisContrastLayers1[i2 + b_thisContrastLayers1.size(0) * i1]; + thisContrastLayers1[i2 + thisContrastLayers1.size(0) * i1]; } } + loop_ub = b_thisContrastLayers1.size(1); allLayers[b_i + allLayers.size(0)].f1.set_size - (thisContrastLayers2.size(0), thisContrastLayers2.size(1)); - loop_ub = thisContrastLayers2.size(1); + (b_thisContrastLayers1.size(0), b_thisContrastLayers1.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = thisContrastLayers2.size(0); + b_loop_ub = b_thisContrastLayers1.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { allLayers[b_i + allLayers.size(0)].f1[i2 + allLayers[b_i + - allLayers.size(0)].f1.size(0) * i1] = thisContrastLayers2[i2 + - thisContrastLayers2.size(0) * i1]; + allLayers.size(0)].f1.size(0) * i1] = b_thisContrastLayers1[i2 + + b_thisContrastLayers1.size(0) * i1]; } } } diff --git a/RAT/processCustomFunction2.h b/RAT/processCustomFunction2.h index 39775c0d..1e5d765a 100644 --- a/RAT/processCustomFunction2.h +++ b/RAT/processCustomFunction2.h @@ -25,18 +25,13 @@ namespace RAT namespace customLayers { void processCustomFunction(const ::coder::array - &contrastBackgrounds, const ::coder::array &contrastQzshifts, - const ::coder::array &contrastScalefactors, const ::coder:: - array &contrastBulkIns, const ::coder::array - &contrastBulkOuts, const ::coder::array &contrastResolutions, - const ::coder::array &backgroundParams, const ::coder::array< - real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + &contrastBulkIns, const ::coder::array &contrastBulkOuts, const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &resolutionParams, const :: - coder::array &cCustFiles, real_T numberOfContrasts, const :: - coder::array &customFiles, const ::coder::array ¶ms, boolean_T useImaginary, ::coder::array - &allLayers, ::coder::array &allRoughs); + 2U> &bulkOut, const ::coder::array &cCustFiles, real_T + numberOfContrasts, const ::coder::array &customFiles, + const ::coder::array ¶ms, boolean_T useImaginary, :: + coder::array &allLayers, ::coder::array + &allRoughs); } } } diff --git a/RAT/processCustomFunction3.cpp b/RAT/processCustomFunction3.cpp index c2796f54..92d2838b 100644 --- a/RAT/processCustomFunction3.cpp +++ b/RAT/processCustomFunction3.cpp @@ -12,7 +12,6 @@ #include "processCustomFunction3.h" #include "RATMain_internal_types.h" #include "RATMain_types.h" -#include "backSort.h" #include "callCppFunction.h" #include "rt_nonfinite.h" #include "str2double.h" @@ -22,14 +21,14 @@ // Function Declarations namespace RAT { - static void cast(const ::coder::array &r, ::coder::array< + static void cast(const ::coder::array &r, ::coder::array< cell_wrap_8, 2U> &r1); } // Function Definitions namespace RAT { - static void cast(const ::coder::array &r, ::coder::array< + static void cast(const ::coder::array &r, ::coder::array< cell_wrap_8, 2U> &r1) { int32_T i; @@ -55,30 +54,21 @@ namespace RAT namespace customXY { void processCustomFunction(const ::coder::array - &contrastBackgrounds, const ::coder::array &contrastQzshifts, - const ::coder::array &contrastScalefactors, const ::coder:: - array &contrastBulkIns, const ::coder::array - &contrastBulkOuts, const ::coder::array &contrastResolutions, - const ::coder::array &backgroundParams, const ::coder::array< - real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + &contrastBulkIns, const ::coder::array &contrastBulkOuts, const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: - array &cCustFiles, real_T numberOfContrasts, const ::coder:: - array &customFiles, const ::coder::array - ¶ms, ::coder::array &allSLDs, ::coder::array &allRoughs) + 2U> &bulkOut, const ::coder::array &cCustFiles, real_T + numberOfContrasts, const ::coder::array &customFiles, + const ::coder::array ¶ms, ::coder::array + &allSLDs, ::coder::array &allRoughs) { - ::coder::array tempAllSLDs; + ::coder::array tempAllSLDs; + ::coder::array allBulkOuts; + ::coder::array b_allBulkOuts; ::coder::array b_params; ::coder::array r; - real_T a__1; real_T a__2; - real_T a__3; - real_T a__4; - real_T a__6; - real_T thisBulkIn; - real_T thisBulkOut; int32_T i; + int32_T loop_ub; // Top-level function for processing custom XY profiles for all the // contrasts. @@ -87,6 +77,13 @@ namespace RAT allRoughs.set_size(i); // 3 columns to allow for potential imaginary curve + allBulkOuts.set_size(1, contrastBulkOuts.size(1)); + loop_ub = contrastBulkOuts.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + allBulkOuts[i1] = bulkOut[static_cast(contrastBulkOuts[i1]) - + 1]; + } + tempAllSLDs.set_size(i, 2); for (int32_T b_i{0}; b_i < i; b_i++) { creal_T x; @@ -96,11 +93,6 @@ namespace RAT // TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's.. // Choose which custom file is associated with this contrast // Find values of 'bulkIn' and 'bulkOut' for this contrast... - backSort(contrastBackgrounds[b_i], contrastQzshifts[b_i], - contrastScalefactors[b_i], contrastBulkIns[b_i], - contrastBulkOuts[b_i], contrastResolutions[b_i], - backgroundParams, qzshifts, scalefactor, bulkIn, bulkOut, res, - &a__1, &a__2, &a__3, &thisBulkIn, &thisBulkOut, &a__4); d = cCustFiles[b_i]; iv[0] = (*(int32_T (*)[2])((::coder::array *)&customFiles[ static_cast(d) - 1].f1)->size())[0]; @@ -110,21 +102,27 @@ namespace RAT &customFiles[static_cast(d) - 1].f1)->data(), iv); if ((!std::isnan(x.re)) && (!std::isnan(x.im))) { int32_T b_loop_ub; - int32_T loop_ub; b_params.set_size(1, params.size(1)); loop_ub = params.size(1) - 1; for (int32_T i1{0}; i1 <= loop_ub; i1++) { b_params[i1] = params[i1]; } + b_allBulkOuts.set_size(1, allBulkOuts.size(1)); + loop_ub = allBulkOuts.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_allBulkOuts[i1] = allBulkOuts[i1]; + } + iv[0] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(d) - 1].f1)->size())[0]; iv[1] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(d) - 1].f1)->size())[1]; - b_callCppFunction(b_params, thisBulkIn, thisBulkOut, - static_cast(b_i) + 1.0, (const char_T *)((:: - coder::array *)&customFiles[static_cast(d) - - 1].f1)->data(), iv, r, &allRoughs[b_i]); + b_callCppFunction((const char_T *)((::coder::array *) + &customFiles[static_cast(d) - 1].f1)->data(), iv, + b_params, bulkIn[static_cast + (contrastBulkIns[b_i]) - 1], b_allBulkOuts, ( + static_cast(b_i) + 1.0) - 1.0, r, &allRoughs[b_i]); loop_ub = r.size(1); tempAllSLDs[b_i].f1.set_size(r.size(0), r.size(1)); for (int32_T i1{0}; i1 < loop_ub; i1++) { @@ -141,16 +139,23 @@ namespace RAT b_params[i1] = params[i1]; } + b_allBulkOuts.set_size(1, allBulkOuts.size(1)); + loop_ub = allBulkOuts.size(1) - 1; + for (int32_T i1{0}; i1 <= loop_ub; i1++) { + b_allBulkOuts[i1] = allBulkOuts[i1]; + } + iv[0] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(cCustFiles[b_i]) - 1].f1) ->size())[0]; iv[1] = (*(int32_T (*)[2])((::coder::array *) &customFiles[static_cast(cCustFiles[b_i]) - 1].f1) ->size())[1]; - c_callCppFunction(b_params, thisBulkIn, thisBulkOut, - static_cast(b_i) + 1.0, (const char_T *)((:: - coder::array *)&customFiles[static_cast - (cCustFiles[b_i]) - 1].f1)->data(), iv, r, &a__6); + c_callCppFunction((const char_T *)((::coder::array *) + &customFiles[static_cast(cCustFiles[b_i]) - 1].f1)->data(), + iv, b_params, bulkIn[static_cast + (contrastBulkIns[b_i]) - 1], b_allBulkOuts, ( + static_cast(b_i) + 1.0) - 1.0, r, &a__2); loop_ub = r.size(1); tempAllSLDs[b_i + tempAllSLDs.size(0)].f1.set_size(r.size(0), r.size (1)); diff --git a/RAT/processCustomFunction3.h b/RAT/processCustomFunction3.h index 3caa6a8b..2302fcae 100644 --- a/RAT/processCustomFunction3.h +++ b/RAT/processCustomFunction3.h @@ -25,18 +25,12 @@ namespace RAT namespace customXY { void processCustomFunction(const ::coder::array - &contrastBackgrounds, const ::coder::array &contrastQzshifts, - const ::coder::array &contrastScalefactors, const ::coder:: - array &contrastBulkIns, const ::coder::array - &contrastBulkOuts, const ::coder::array &contrastResolutions, - const ::coder::array &backgroundParams, const ::coder::array< - real_T, 2U> &qzshifts, const ::coder::array &scalefactor, + &contrastBulkIns, const ::coder::array &contrastBulkOuts, const ::coder::array &bulkIn, const ::coder::array &bulkOut, const ::coder::array &res, const ::coder:: - array &cCustFiles, real_T numberOfContrasts, const ::coder:: - array &customFiles, const ::coder::array - ¶ms, ::coder::array &allSLDs, ::coder::array &allRoughs); + 2U> &bulkOut, const ::coder::array &cCustFiles, real_T + numberOfContrasts, const ::coder::array &customFiles, + const ::coder::array ¶ms, ::coder::array + &allSLDs, ::coder::array &allRoughs); } } } diff --git a/RAT/ratDREAM.cpp b/RAT/ratDREAM.cpp index 6b6d347a..f7a9d4bb 100644 --- a/RAT/ratDREAM.cpp +++ b/RAT/ratDREAM.cpp @@ -46,7 +46,7 @@ // Type Definitions namespace RAT { - struct g_struct_T + struct h_struct_T { char_T prior[7]; ::coder::array min; @@ -65,11 +65,11 @@ namespace RAT const ::coder::array &Par_info_min, const ::coder:: array &Par_info_max, const char_T Par_info_boundhandling_data[], const int32_T - Par_info_boundhandling_size[2], const struct5_T - *ratInputs_problemDef, const cell_14 *ratInputs_problemDefCells, + Par_info_boundhandling_size[2], const c_struct_T + *ratInputs_problemStruct, const cell_11 *ratInputs_problemCells, const struct2_T *ratInputs_controls, const ::coder::array &ratInputs_priors, ::coder::array &chain, - struct13_T *output, ::coder::array &fx) + struct12_T *output, ::coder::array &fx) { ::coder::array b_chain; ::coder::array CR; @@ -93,9 +93,9 @@ namespace RAT ::coder::array r2; ::coder::array accept; ::coder::array b_CR_data; - g_struct_T Par_info; - struct14_T DREAMPar; - struct15_T Meas_info; + h_struct_T Par_info; + struct13_T DREAMPar; + struct14_T Meas_info; real_T delta_tot_data[3]; real_T lCR_data[3]; real_T pCR_data[3]; @@ -331,10 +331,10 @@ namespace RAT // Create the initial states of each of the chains (initial population) initializeDREAM(&DREAMPar, Par_info.min, Par_info.max, Par_info.boundhandling.data, Par_info.boundhandling.size, - chain, output, log_L, ratInputs_problemDef, - ratInputs_problemDefCells, ratInputs_controls, - ratInputs_priors, X, fx, CR, pCR_data, pCR_size, lCR_data, - lCR_size, delta_tot_data, delta_tot_size); + chain, output, log_L, ratInputs_problemStruct, + ratInputs_problemCells, ratInputs_controls, ratInputs_priors, + X, fx, CR, pCR_data, pCR_size, lCR_data, lCR_size, + delta_tot_data, delta_tot_size); // elseif DREAMPar.restart // @@ -401,11 +401,11 @@ namespace RAT } // Now evaluate the model ( = pdf ) and return fx - evaluateModel(xnew, &DREAMPar, ratInputs_problemDef, - ratInputs_problemDefCells, ratInputs_controls, fx_new); + evaluateModel(xnew, &DREAMPar, ratInputs_problemStruct, + ratInputs_problemCells, ratInputs_controls, fx_new); // Calculate the log-likelihood and log-prior of x (fx) - calcDensity(xnew, fx_new, &DREAMPar, ratInputs_problemDef->fitLimits, + calcDensity(xnew, fx_new, &DREAMPar, ratInputs_problemStruct->fitLimits, ratInputs_priors, log_L_xnew, log_PR_xnew); // Calculate the Metropolis ratio diff --git a/RAT/ratDREAM.h b/RAT/ratDREAM.h index a723bc18..43cbc38f 100644 --- a/RAT/ratDREAM.h +++ b/RAT/ratDREAM.h @@ -19,10 +19,10 @@ // Type Declarations namespace RAT { - struct struct5_T; - struct cell_14; + struct c_struct_T; + struct cell_11; struct struct2_T; - struct struct13_T; + struct struct12_T; } // Function Declarations @@ -34,11 +34,11 @@ namespace RAT const ::coder::array &Par_info_min, const ::coder:: array &Par_info_max, const char_T Par_info_boundhandling_data[], const int32_T - Par_info_boundhandling_size[2], const struct5_T - *ratInputs_problemDef, const cell_14 *ratInputs_problemDefCells, + Par_info_boundhandling_size[2], const c_struct_T + *ratInputs_problemStruct, const cell_11 *ratInputs_problemCells, const struct2_T *ratInputs_controls, const ::coder::array &ratInputs_priors, ::coder::array &chain, - struct13_T *output, ::coder::array &fx); + struct12_T *output, ::coder::array &fx); } #endif diff --git a/RAT/refPrctileConfInts.cpp b/RAT/refPrctileConfInts.cpp index 84e65563..3c13cef4 100644 --- a/RAT/refPrctileConfInts.cpp +++ b/RAT/refPrctileConfInts.cpp @@ -15,6 +15,7 @@ #include "interp1.h" #include "makeCell.h" #include "mean.h" +#include "parseResultToStruct.h" #include "prctile.h" #include "rand.h" #include "reflectivityCalculation.h" @@ -29,26 +30,37 @@ namespace RAT { void refPrctileConfInts(const ::coder::array &bayesOutputs_chain, - struct5_T *problemDef, const cell_14 *problemDefCells, const struct2_T + c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controlsStruct, f_struct_T *allPredInts) { - ::coder::array r; - ::coder::array ref_yVals; - ::coder::array sld_yVals; - ::coder::array r1; + ::coder::array r; + ::coder::array b_expl_temp; + ::coder::array c_expl_temp; + ::coder::array calcResult_reflectivity; + ::coder::array calcResult_sldProfiles; + ::coder::array d_expl_temp; + ::coder::array expl_temp; + ::coder::array r1; + ::coder::array refYVals; + ::coder::array sldYVals; + ::coder::array r2; ::coder::array refArray; ::coder::array rowVals; ::coder::array sldArray; + ::coder::array sldArray1; + ::coder::array sldArray2; ::coder::array vals; - ::coder::array b_calcResult; - ::coder::array c_calcResult; - cell_13 calcResult; - struct_T calcProblem; + ::coder::array b_calcResult_reflectivity; + ::coder::array c_calcResult_reflectivity; + cell_wrap_9 calcResult[6]; + d_struct_T calcContrastParams; + d_struct_T e_expl_temp; real_T a[1000]; real_T isample[1000]; real_T thisCol_data[1000]; - real_T CI_65[2]; - real_T CI_95[2]; + real_T ci65[2]; + real_T ci95[2]; + real_T calcResult_calculationResults_sumChi; int32_T b_loop_ub; int32_T b_thisCol_size; int32_T c_loop_ub; @@ -60,19 +72,20 @@ namespace RAT boolean_T domains; // Need to deal slightly differently with SLDs if there are domains - domains = coder::internal::b_strcmp(problemDef->TF.data, problemDef->TF.size); + domains = coder::internal::b_strcmp(problemStruct->TF.data, + problemStruct->TF.size); // Calc the ref and SLD for the first row of the chain. This 'sticks' the x // values of each that we then interpolate the values from the rest of the // cain onto.... - problemDef->fitParams.set_size(1, bayesOutputs_chain.size(1)); + problemStruct->fitParams.set_size(1, bayesOutputs_chain.size(1)); loop_ub = bayesOutputs_chain.size(1); for (i = 0; i < loop_ub; i++) { - problemDef->fitParams[problemDef->fitParams.size(0) * i] = + problemStruct->fitParams[problemStruct->fitParams.size(0) * i] = bayesOutputs_chain[bayesOutputs_chain.size(0) * i]; } - unpackParams(problemDef, controlsStruct->checks.fitParam, + unpackParams(problemStruct, controlsStruct->checks.fitParam, controlsStruct->checks.fitBackgroundParam, controlsStruct->checks.fitQzshift, controlsStruct->checks.fitScalefactor, @@ -82,19 +95,16 @@ namespace RAT controlsStruct->checks.fitDomainRatio); // Calc the reflectivities.... - reflectivityCalculation(problemDef, problemDefCells, controlsStruct, - &calcProblem, &calcResult); + reflectivityCalculation(problemStruct, problemCells, controlsStruct, + &calcContrastParams, calcResult); // 'result' is currently a cell array. Convert this to a struct because it's // easier to work with fieldnames... - // Reflectivity art points - // Reflectivity between sim limits - // Data corrected for sfs - // Layers if defined (i.e. not customXY) - // Calculated SLD profiles - // Resampled layers - // For compile, we can't remove a field, so just clear it for now... - // problem = rmfield(problem,'calculations'); + parseResultToStruct(&calcContrastParams, calcResult, calcResult_reflectivity, + expl_temp, b_expl_temp, c_expl_temp, + calcResult_sldProfiles, d_expl_temp, + &calcResult_calculationResults_sumChi, &e_expl_temp); + // so each is a {n x 1} cell array, because of n contrasts. // Prepare some arrays to hold the SLD's and Refs for all the chain, keeping only the Y vales. // We'll save x values in a separate array @@ -106,30 +116,46 @@ namespace RAT rowVals[1] = 0.0; vals[vals.size(0) * 2] = 0.0; rowVals[2] = 0.0; - makeCell(problemDef->numberOfContrasts, (const real_T *)rowVals.data(), + makeCell(problemStruct->numberOfContrasts, (const real_T *)rowVals.data(), allPredInts->refXdata); // cell(numberOfContrasts,1); - makeCell(problemDef->numberOfContrasts, (const real_T *)vals.data(), - ref_yVals); + makeCell(problemStruct->numberOfContrasts, (const real_T *)vals.data(), + refYVals); // cell(numberOfContrasts,1); - makeCell(problemDef->numberOfContrasts, (const real_T *)rowVals.data(), - allPredInts->sldXdata); if (!domains) { - makeCell(problemDef->numberOfContrasts, (const real_T *)vals.data(), r); - sld_yVals.set_size(r.size(0), 1); + makeCell(problemStruct->numberOfContrasts, (const real_T *)rowVals.data(), + r); + allPredInts->sldXdata.set_size(r.size(0), 1); loop_ub = r.size(0); for (i = 0; i < loop_ub; i++) { - sld_yVals[i] = r[i]; + allPredInts->sldXdata[i] = r[i]; + } + + makeCell(problemStruct->numberOfContrasts, (const real_T *)vals.data(), r1); + sldYVals.set_size(r1.size(0), 1); + loop_ub = r1.size(0); + for (i = 0; i < loop_ub; i++) { + sldYVals[i] = r1[i]; } } else { - b_makeCell(problemDef->numberOfContrasts, (const real_T *)vals.data(), r); - sld_yVals.set_size(r.size(0), 2); + b_makeCell(problemStruct->numberOfContrasts, (const real_T *)rowVals.data(), + r); + allPredInts->sldXdata.set_size(r.size(0), 2); + b_makeCell(problemStruct->numberOfContrasts, (const real_T *)vals.data(), + r1); + sldYVals.set_size(r1.size(0), 2); loop_ub = r.size(0); + k = r1.size(0); for (i = 0; i < 2; i++) { for (i1 = 0; i1 < loop_ub; i1++) { - sld_yVals[i1 + sld_yVals.size(0) * i] = r[i1 + r.size(0) * i]; + allPredInts->sldXdata[i1 + allPredInts->sldXdata.size(0) * i] = r[i1 + + r.size(0) * i]; + } + + for (i1 = 0; i1 < k; i1++) { + sldYVals[i1 + sldYVals.size(0) * i] = r1[i1 + r1.size(0) * i]; } } } @@ -138,27 +164,34 @@ namespace RAT // calculate the sample. So, take the current reflectivity value from above // to get the 'base' x for ref and SLD, then all following // interpelations are onto these x values.... - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); for (int32_T b_i{0}; b_i < i; b_i++) { - loop_ub = calcResult.f1[b_i].f1.size(0); - allPredInts->refXdata[b_i].f1.set_size(1, calcResult.f1[b_i].f1.size(0)); + loop_ub = calcResult_reflectivity[b_i].f1.size(0); + allPredInts->refXdata[b_i].f1.set_size(1, calcResult_reflectivity[b_i]. + f1.size(0)); for (i1 = 0; i1 < loop_ub; i1++) { - allPredInts->refXdata[b_i].f1[i1] = calcResult.f1[b_i].f1[i1]; + allPredInts->refXdata[b_i].f1[i1] = calcResult_reflectivity[b_i].f1[i1]; } // Transpose these into rows for storage if (!domains) { - loop_ub = calcResult.f5[b_i].f1.size(0); - allPredInts->sldXdata[b_i].f1.set_size(1, calcResult.f5[b_i].f1.size(0)); + loop_ub = calcResult_sldProfiles[b_i].f1.size(0); + allPredInts->sldXdata[b_i].f1.set_size(1, calcResult_sldProfiles[b_i]. + f1.size(0)); for (i1 = 0; i1 < loop_ub; i1++) { - allPredInts->sldXdata[b_i].f1[i1] = calcResult.f5[b_i].f1[i1]; + allPredInts->sldXdata[b_i].f1[i1] = calcResult_sldProfiles[b_i].f1[i1]; } } else { - loop_ub = calcResult.f5[b_i].f1.size(0); for (int32_T m{0}; m < 2; m++) { - allPredInts->sldXdata[b_i].f1.set_size(1, loop_ub); + loop_ub = calcResult_sldProfiles[b_i + calcResult_sldProfiles.size(0) * + m].f1.size(0); + allPredInts->sldXdata[b_i + allPredInts->sldXdata.size(0) * m]. + f1.set_size(1, calcResult_sldProfiles[b_i + + calcResult_sldProfiles.size(0) * m].f1.size(0)); for (i1 = 0; i1 < loop_ub; i1++) { - allPredInts->sldXdata[b_i].f1[i1] = calcResult.f5[b_i].f1[i1]; + allPredInts->sldXdata[b_i + allPredInts->sldXdata.size(0) * m].f1[i1] + = calcResult_sldProfiles[b_i + calcResult_sldProfiles.size(0) * m] + .f1[i1]; } } } @@ -177,19 +210,40 @@ namespace RAT // First, we populate the yVals arrays with zero arrays of the correct size... for (int32_T b_i{0}; b_i < i; b_i++) { - ref_yVals[b_i].f1.set_size(1000, calcResult.f1[b_i].f1.size(0)); - loop_ub = calcResult.f1[b_i].f1.size(0); + refYVals[b_i].f1.set_size(1000, calcResult_reflectivity[b_i].f1.size(0)); + loop_ub = calcResult_reflectivity[b_i].f1.size(0); for (i1 = 0; i1 < loop_ub; i1++) { - for (k = 0; k < 1000; k++) { - ref_yVals[b_i].f1[k + ref_yVals[b_i].f1.size(0) * i1] = 0.0; + for (int32_T i2{0}; i2 < 1000; i2++) { + refYVals[b_i].f1[i2 + refYVals[b_i].f1.size(0) * i1] = 0.0; } } - sld_yVals[b_i].f1.set_size(1000, calcResult.f5[b_i].f1.size(0)); - loop_ub = calcResult.f5[b_i].f1.size(0); - for (i1 = 0; i1 < loop_ub; i1++) { - for (k = 0; k < 1000; k++) { - sld_yVals[b_i].f1[k + sld_yVals[b_i].f1.size(0) * i1] = 0.0; + if (!domains) { + sldYVals[b_i].f1.set_size(1000, calcResult_sldProfiles[b_i].f1.size(0)); + loop_ub = calcResult_sldProfiles[b_i].f1.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + for (int32_T i2{0}; i2 < 1000; i2++) { + sldYVals[b_i].f1[i2 + sldYVals[b_i].f1.size(0) * i1] = 0.0; + } + } + } else { + sldYVals[b_i].f1.set_size(1000, calcResult_sldProfiles[b_i].f1.size(0)); + loop_ub = calcResult_sldProfiles[b_i].f1.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + for (int32_T i2{0}; i2 < 1000; i2++) { + sldYVals[b_i].f1[i2 + sldYVals[b_i].f1.size(0) * i1] = 0.0; + } + } + + sldYVals[b_i + sldYVals.size(0)].f1.set_size(1000, + calcResult_sldProfiles[b_i + calcResult_sldProfiles.size(0)].f1.size(0)); + loop_ub = calcResult_sldProfiles[b_i + calcResult_sldProfiles.size(0)]. + f1.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + for (int32_T i2{0}; i2 < 1000; i2++) { + sldYVals[b_i + sldYVals.size(0)].f1[i2 + sldYVals[b_i + + sldYVals.size(0)].f1.size(0) * i1] = 0.0; + } } } } @@ -197,14 +251,14 @@ namespace RAT // Calculate all the samples.... loop_ub = bayesOutputs_chain.size(1); for (int32_T b_i{0}; b_i < 1000; b_i++) { - problemDef->fitParams.set_size(1, bayesOutputs_chain.size(1)); + problemStruct->fitParams.set_size(1, bayesOutputs_chain.size(1)); for (i1 = 0; i1 < loop_ub; i1++) { - problemDef->fitParams[problemDef->fitParams.size(0) * i1] = + problemStruct->fitParams[problemStruct->fitParams.size(0) * i1] = bayesOutputs_chain[(static_cast(isample[b_i]) + bayesOutputs_chain.size(0) * i1) - 1]; } - unpackParams(problemDef, controlsStruct->checks.fitParam, + unpackParams(problemStruct, controlsStruct->checks.fitParam, controlsStruct->checks.fitBackgroundParam, controlsStruct->checks.fitQzshift, controlsStruct->checks.fitScalefactor, @@ -214,83 +268,87 @@ namespace RAT controlsStruct->checks.fitDomainRatio); // Calc the reflectivities.... - reflectivityCalculation(problemDef, problemDefCells, controlsStruct, - &calcProblem, &calcResult); + reflectivityCalculation(problemStruct, problemCells, controlsStruct, + &calcContrastParams, calcResult); // 'result' is currently a cell array. Convert this to a struct because it's // easier to work with fieldnames... - // Reflectivity art points - // Reflectivity between sim limits - // Data corrected for sfs - // Layers if defined (i.e. not customXY) - // Calculated SLD profiles - // Resampled layers - // For compile, we can't remove a field, so just clear it for now... - // problem = rmfield(problem,'calculations'); - allPredInts->sampleChi[b_i] = calcProblem.calculations.sumChi; + parseResultToStruct(&calcContrastParams, calcResult, + calcResult_reflectivity, expl_temp, b_expl_temp, + c_expl_temp, calcResult_sldProfiles, d_expl_temp, + &calcResult_calculationResults_sumChi, &e_expl_temp); + allPredInts->sampleChi[b_i] = calcResult_calculationResults_sumChi; for (int32_T n{0}; n < i; n++) { - k = calcResult.f1[n].f1.size(0); - b_calcResult.set_size(calcResult.f1[n].f1.size(0)); + k = calcResult_reflectivity[n].f1.size(0); + b_calcResult_reflectivity.set_size(calcResult_reflectivity[n].f1.size(0)); for (i1 = 0; i1 < k; i1++) { - b_calcResult[i1] = calcResult.f1[n].f1[i1]; + b_calcResult_reflectivity[i1] = calcResult_reflectivity[n].f1[i1]; } - k = calcResult.f1[n].f1.size(0); - c_calcResult.set_size(calcResult.f1[n].f1.size(0)); + k = calcResult_reflectivity[n].f1.size(0); + c_calcResult_reflectivity.set_size(calcResult_reflectivity[n].f1.size(0)); for (i1 = 0; i1 < k; i1++) { - c_calcResult[i1] = calcResult.f1[n].f1[i1 + calcResult.f1[n].f1.size(0)]; + c_calcResult_reflectivity[i1] = calcResult_reflectivity[n].f1[i1 + + calcResult_reflectivity[n].f1.size(0)]; } - coder::interp1(b_calcResult, c_calcResult, allPredInts->refXdata[n].f1, - r1); - k = r1.size(1); + coder::interp1(b_calcResult_reflectivity, c_calcResult_reflectivity, + allPredInts->refXdata[n].f1, r2); + k = r2.size(1); for (i1 = 0; i1 < k; i1++) { - ref_yVals[n].f1[b_i + ref_yVals[n].f1.size(0) * i1] = r1[i1]; + refYVals[n].f1[b_i + refYVals[n].f1.size(0) * i1] = r2[i1]; } // Automatically comes back as a row from inpterp1 if (!domains) { - k = calcResult.f5[n].f1.size(0); - b_calcResult.set_size(calcResult.f5[n].f1.size(0)); + k = calcResult_sldProfiles[n].f1.size(0); + b_calcResult_reflectivity.set_size(calcResult_sldProfiles[n].f1.size(0)); for (i1 = 0; i1 < k; i1++) { - b_calcResult[i1] = calcResult.f5[n].f1[i1]; + b_calcResult_reflectivity[i1] = calcResult_sldProfiles[n].f1[i1]; } - k = calcResult.f5[n].f1.size(0); - c_calcResult.set_size(calcResult.f5[n].f1.size(0)); + k = calcResult_sldProfiles[n].f1.size(0); + c_calcResult_reflectivity.set_size(calcResult_sldProfiles[n].f1.size(0)); for (i1 = 0; i1 < k; i1++) { - c_calcResult[i1] = calcResult.f5[n].f1[i1 + calcResult.f5[n].f1.size - (0)]; + c_calcResult_reflectivity[i1] = calcResult_sldProfiles[n].f1[i1 + + calcResult_sldProfiles[n].f1.size(0)]; } - coder::b_interp1(b_calcResult, c_calcResult, allPredInts->sldXdata[n]. - f1, r1); - k = r1.size(1); + coder::b_interp1(b_calcResult_reflectivity, c_calcResult_reflectivity, + allPredInts->sldXdata[n].f1, r2); + k = r2.size(1); for (i1 = 0; i1 < k; i1++) { - sld_yVals[n].f1[b_i + sld_yVals[n].f1.size(0) * i1] = r1[i1]; + sldYVals[n].f1[b_i + sldYVals[n].f1.size(0) * i1] = r2[i1]; } } else { - int32_T d_loop_ub; - k = calcResult.f5[n].f1.size(0); - d_loop_ub = calcResult.f5[n].f1.size(0); for (int32_T m{0}; m < 2; m++) { - int32_T e_loop_ub; - b_calcResult.set_size(k); + k = calcResult_sldProfiles[n + calcResult_sldProfiles.size(0) * m]. + f1.size(0); + b_calcResult_reflectivity.set_size(calcResult_sldProfiles[n + + calcResult_sldProfiles.size(0) * m].f1.size(0)); for (i1 = 0; i1 < k; i1++) { - b_calcResult[i1] = calcResult.f5[n].f1[i1]; + b_calcResult_reflectivity[i1] = calcResult_sldProfiles[n + + calcResult_sldProfiles.size(0) * m].f1[i1]; } - c_calcResult.set_size(d_loop_ub); - for (i1 = 0; i1 < d_loop_ub; i1++) { - c_calcResult[i1] = calcResult.f5[n].f1[i1 + calcResult.f5[n]. + k = calcResult_sldProfiles[n + calcResult_sldProfiles.size(0) * m]. + f1.size(0); + c_calcResult_reflectivity.set_size(calcResult_sldProfiles[n + + calcResult_sldProfiles.size(0) * m].f1.size(0)); + for (i1 = 0; i1 < k; i1++) { + c_calcResult_reflectivity[i1] = calcResult_sldProfiles[n + + calcResult_sldProfiles.size(0) * m].f1[i1 + + calcResult_sldProfiles[n + calcResult_sldProfiles.size(0) * m]. f1.size(0)]; } - coder::b_interp1(b_calcResult, c_calcResult, allPredInts->sldXdata[n] - .f1, r1); - e_loop_ub = r1.size(1); - for (i1 = 0; i1 < e_loop_ub; i1++) { - sld_yVals[n].f1[b_i + sld_yVals[n].f1.size(0) * i1] = r1[i1]; + coder::b_interp1(b_calcResult_reflectivity, + c_calcResult_reflectivity, allPredInts->sldXdata[n + + allPredInts->sldXdata.size(0) * m].f1, r2); + k = r2.size(1); + for (i1 = 0; i1 < k; i1++) { + sldYVals[n + sldYVals.size(0) * m].f1[b_i + sldYVals[n + + sldYVals.size(0) * m].f1.size(0) * i1] = r2[i1]; } } } @@ -299,85 +357,168 @@ namespace RAT // Calculate the percentiles across all the calculated samples for each // point in x... We calculate 95% and 65% CI's for each set of curves + // Reflectivity.. allPredInts->refPredInts.set_size(i); for (int32_T b_i{0}; b_i < i; b_i++) { - refArray.set_size(5, ref_yVals[b_i].f1.size(1)); - loop_ub = ref_yVals[b_i].f1.size(1); + refArray.set_size(5, refYVals[b_i].f1.size(1)); + loop_ub = refYVals[b_i].f1.size(1); for (i1 = 0; i1 < loop_ub; i1++) { - for (k = 0; k < 5; k++) { - refArray[k + 5 * i1] = 0.0; + for (int32_T i2{0}; i2 < 5; i2++) { + refArray[i2 + 5 * i1] = 0.0; } } // We could possibly use CIFn in one shot here (rather than loop over // points....) - i1 = ref_yVals[b_i].f1.size(1); - if (ref_yVals[b_i].f1.size(1) - 1 >= 0) { - thisCol_size = ref_yVals[b_i].f1.size(0); - b_loop_ub = ref_yVals[b_i].f1.size(0); + i1 = refYVals[b_i].f1.size(1); + if (refYVals[b_i].f1.size(1) - 1 >= 0) { + thisCol_size = refYVals[b_i].f1.size(0); + b_loop_ub = refYVals[b_i].f1.size(0); } for (int32_T points{0}; points < i1; points++) { - for (k = 0; k < b_loop_ub; k++) { - thisCol_data[k] = ref_yVals[b_i].f1[k + ref_yVals[b_i].f1.size(0) * + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + thisCol_data[i2] = refYVals[b_i].f1[i2 + refYVals[b_i].f1.size(0) * points]; } - coder::prctile(thisCol_data, thisCol_size, CI_95); - coder::b_prctile(thisCol_data, thisCol_size, CI_65); - refArray[5 * points] = CI_95[0]; - refArray[5 * points + 1] = CI_65[0]; + coder::prctile(thisCol_data, thisCol_size, ci95); + coder::b_prctile(thisCol_data, thisCol_size, ci65); + refArray[5 * points] = ci95[0]; + refArray[5 * points + 1] = ci65[0]; refArray[5 * points + 2] = coder::mean(thisCol_data, thisCol_size); - refArray[5 * points + 3] = CI_65[1]; - refArray[5 * points + 4] = CI_95[1]; + refArray[5 * points + 3] = ci65[1]; + refArray[5 * points + 4] = ci95[1]; } allPredInts->refPredInts[b_i].f1.set_size(5, refArray.size(1)); loop_ub = refArray.size(1); for (i1 = 0; i1 < loop_ub; i1++) { - for (k = 0; k < 5; k++) { - allPredInts->refPredInts[b_i].f1[k + 5 * i1] = refArray[k + 5 * i1]; + for (int32_T i2{0}; i2 < 5; i2++) { + allPredInts->refPredInts[b_i].f1[i2 + 5 * i1] = refArray[i2 + 5 * i1]; } } } - // TODO: need to add domains here.... - allPredInts->sldPredInts.set_size(i); - for (int32_T b_i{0}; b_i < i; b_i++) { - sldArray.set_size(5, sld_yVals[b_i].f1.size(1)); - loop_ub = sld_yVals[b_i].f1.size(1); - for (i1 = 0; i1 < loop_ub; i1++) { - for (k = 0; k < 5; k++) { - sldArray[k + 5 * i1] = 0.0; + // Also the SLD's + if (!domains) { + allPredInts->sldPredInts.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + sldArray.set_size(5, sldYVals[b_i].f1.size(1)); + loop_ub = sldYVals[b_i].f1.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + for (int32_T i2{0}; i2 < 5; i2++) { + sldArray[i2 + 5 * i1] = 0.0; + } } - } - i1 = sld_yVals[b_i].f1.size(1); - if (sld_yVals[b_i].f1.size(1) - 1 >= 0) { - b_thisCol_size = sld_yVals[b_i].f1.size(0); - c_loop_ub = sld_yVals[b_i].f1.size(0); - } + i1 = sldYVals[b_i].f1.size(1); + if (sldYVals[b_i].f1.size(1) - 1 >= 0) { + b_thisCol_size = sldYVals[b_i].f1.size(0); + c_loop_ub = sldYVals[b_i].f1.size(0); + } - for (int32_T points{0}; points < i1; points++) { - for (k = 0; k < c_loop_ub; k++) { - thisCol_data[k] = sld_yVals[b_i].f1[k + sld_yVals[b_i].f1.size(0) * - points]; + for (int32_T points{0}; points < i1; points++) { + for (int32_T i2{0}; i2 < c_loop_ub; i2++) { + thisCol_data[i2] = sldYVals[b_i].f1[i2 + sldYVals[b_i].f1.size(0) * + points]; + } + + coder::prctile(thisCol_data, b_thisCol_size, ci95); + coder::b_prctile(thisCol_data, b_thisCol_size, ci65); + sldArray[5 * points] = ci95[0]; + sldArray[5 * points + 1] = ci65[0]; + sldArray[5 * points + 2] = coder::mean(thisCol_data, b_thisCol_size); + sldArray[5 * points + 3] = ci65[1]; + sldArray[5 * points + 4] = ci95[1]; } - coder::prctile(thisCol_data, b_thisCol_size, CI_95); - coder::b_prctile(thisCol_data, b_thisCol_size, CI_65); - sldArray[5 * points] = CI_95[0]; - sldArray[5 * points + 1] = CI_65[0]; - sldArray[5 * points + 2] = coder::mean(thisCol_data, b_thisCol_size); - sldArray[5 * points + 3] = CI_65[1]; - sldArray[5 * points + 4] = CI_95[1]; + allPredInts->sldPredInts[b_i].f1.set_size(5, sldArray.size(1)); + loop_ub = sldArray.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + for (int32_T i2{0}; i2 < 5; i2++) { + allPredInts->sldPredInts[b_i].f1[i2 + 5 * i1] = sldArray[i2 + 5 * i1]; + } + } } + } else { + allPredInts->sldPredInts.set_size(i, 2); + for (int32_T b_i{0}; b_i < i; b_i++) { + sldArray1.set_size(5, sldYVals[b_i].f1.size(1)); + loop_ub = sldYVals[b_i].f1.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + for (int32_T i2{0}; i2 < 5; i2++) { + sldArray1[i2 + 5 * i1] = 0.0; + } + } - allPredInts->sldPredInts[b_i].f1.set_size(5, sldArray.size(1)); - loop_ub = sldArray.size(1); - for (i1 = 0; i1 < loop_ub; i1++) { - for (k = 0; k < 5; k++) { - allPredInts->sldPredInts[b_i].f1[k + 5 * i1] = sldArray[k + 5 * i1]; + sldArray2.set_size(5, sldYVals[b_i + sldYVals.size(0)].f1.size(1)); + loop_ub = sldYVals[b_i + sldYVals.size(0)].f1.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + for (int32_T i2{0}; i2 < 5; i2++) { + sldArray2[i2 + 5 * i1] = 0.0; + } + } + + i1 = sldYVals[b_i].f1.size(1); + for (int32_T points{0}; points < i1; points++) { + real_T thisCol1_data[1000]; + loop_ub = sldYVals[b_i].f1.size(0); + k = sldYVals[b_i].f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + thisCol1_data[i2] = sldYVals[b_i].f1[i2 + sldYVals[b_i].f1.size(0) * + points]; + } + + real_T ci651[2]; + real_T ci951[2]; + coder::prctile(thisCol1_data, k, ci951); + coder::b_prctile(thisCol1_data, k, ci651); + sldArray1[5 * points] = ci951[0]; + sldArray1[5 * points + 1] = ci651[0]; + sldArray1[5 * points + 2] = coder::mean(thisCol1_data, k); + sldArray1[5 * points + 3] = ci651[1]; + sldArray1[5 * points + 4] = ci951[1]; + } + + i1 = sldYVals[b_i + sldYVals.size(0)].f1.size(1); + for (int32_T points{0}; points < i1; points++) { + real_T thisCol2_data[1000]; + loop_ub = sldYVals[b_i + sldYVals.size(0)].f1.size(0); + k = sldYVals[b_i + sldYVals.size(0)].f1.size(0); + for (int32_T i2{0}; i2 < loop_ub; i2++) { + thisCol2_data[i2] = sldYVals[b_i + sldYVals.size(0)].f1[i2 + + sldYVals[b_i + sldYVals.size(0)].f1.size(0) * points]; + } + + real_T ci652[2]; + real_T ci952[2]; + coder::prctile(thisCol2_data, k, ci952); + coder::b_prctile(thisCol2_data, k, ci652); + sldArray2[5 * points] = ci952[0]; + sldArray2[5 * points + 1] = ci652[0]; + sldArray2[5 * points + 2] = coder::mean(thisCol2_data, k); + sldArray2[5 * points + 3] = ci652[1]; + sldArray2[5 * points + 4] = ci952[1]; + } + + allPredInts->sldPredInts[b_i].f1.set_size(5, sldArray1.size(1)); + loop_ub = sldArray1.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + for (int32_T i2{0}; i2 < 5; i2++) { + allPredInts->sldPredInts[b_i].f1[i2 + 5 * i1] = sldArray1[i2 + 5 * + i1]; + } + } + + allPredInts->sldPredInts[b_i + allPredInts->sldPredInts.size(0)]. + f1.set_size(5, sldArray2.size(1)); + loop_ub = sldArray2.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + for (int32_T i2{0}; i2 < 5; i2++) { + allPredInts->sldPredInts[b_i + allPredInts->sldPredInts.size(0)] + .f1[i2 + 5 * i1] = sldArray2[i2 + 5 * i1]; + } } } } diff --git a/RAT/refPrctileConfInts.h b/RAT/refPrctileConfInts.h index 899d3701..ba8743fa 100644 --- a/RAT/refPrctileConfInts.h +++ b/RAT/refPrctileConfInts.h @@ -19,8 +19,8 @@ // Type Declarations namespace RAT { - struct struct5_T; - struct cell_14; + struct c_struct_T; + struct cell_11; struct struct2_T; struct f_struct_T; } @@ -29,7 +29,7 @@ namespace RAT namespace RAT { void refPrctileConfInts(const ::coder::array &bayesOutputs_chain, - struct5_T *problemDef, const cell_14 *problemDefCells, const struct2_T + c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controlsStruct, f_struct_T *allPredInts); } diff --git a/RAT/reflectivityCalculation.cpp b/RAT/reflectivityCalculation.cpp index 77a17eae..6aa224ac 100644 --- a/RAT/reflectivityCalculation.cpp +++ b/RAT/reflectivityCalculation.cpp @@ -22,7 +22,12 @@ // Type Definitions namespace RAT { - struct cell_wrap_19 + struct cell_wrap_16 + { + ::coder::array f1; + }; + + struct cell_wrap_17 { ::coder::array f1; }; @@ -32,26 +37,26 @@ namespace RAT namespace RAT { static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_21, 1U> &r1); + cell_wrap_18, 1U> &r1); static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_19, 1U> &r1); - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_19, 1U> &r1); + cell_wrap_16, 1U> &r1); + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_16, 1U> &r1); static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_20, 1U> &r1); + cell_wrap_17, 1U> &r1); static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_21, 2U> &r1); + cell_wrap_18, 2U> &r1); static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_36, 2U> &r1); + cell_wrap_34, 2U> &r1); static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_20, 2U> &r1); + cell_wrap_17, 2U> &r1); } // Function Definitions namespace RAT { static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_21, 1U> &r1) + cell_wrap_18, 1U> &r1) { int32_T i; r1.set_size(r.size(0)); @@ -72,7 +77,7 @@ namespace RAT } static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_19, 1U> &r1) + cell_wrap_16, 1U> &r1) { int32_T i; r1.set_size(r.size(0)); @@ -92,8 +97,8 @@ namespace RAT } } - static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_19, 1U> &r1) + static void cast(const ::coder::array &r, ::coder::array< + cell_wrap_16, 1U> &r1) { int32_T i; r1.set_size(r.size(0)); @@ -112,7 +117,7 @@ namespace RAT } static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_20, 1U> &r1) + cell_wrap_17, 1U> &r1) { int32_T i; r1.set_size(r.size(0)); @@ -133,7 +138,7 @@ namespace RAT } static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_21, 2U> &r1) + cell_wrap_18, 2U> &r1) { int32_T i; r1.set_size(r.size(0), r.size(1)); @@ -154,7 +159,7 @@ namespace RAT } static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_36, 2U> &r1) + cell_wrap_34, 2U> &r1) { int32_T i; r1.set_size(r.size(0), r.size(1)); @@ -175,7 +180,7 @@ namespace RAT } static void cast(const ::coder::array &r, ::coder::array< - cell_wrap_20, 2U> &r1) + cell_wrap_17, 2U> &r1) { int32_T i; r1.set_size(r.size(0), r.size(1)); @@ -195,27 +200,30 @@ namespace RAT } } - void reflectivityCalculation(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, struct_T *problem, cell_13 - *result) + void reflectivityCalculation(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T *contrastParams, + cell_wrap_9 resultCells[6]) { - ::coder::array b_reflectivity; - ::coder::array b_simulation; - ::coder::array reflectivity; - ::coder::array simulation; - ::coder::array sldProfiles; - ::coder::array domainAllLayers; - ::coder::array r2; - ::coder::array allLayers; - ::coder::array shiftedData; - ::coder::array domainLayerSlds; - ::coder::array r; - ::coder::array layerSlds; - ::coder::array domainSldProfiles; - ::coder::array r1; + ::coder::array reflectivity; + ::coder::array simulation; + ::coder::array sldProfiles; + ::coder::array domainAllLayers; + ::coder::array r2; + ::coder::array allLayers; + ::coder::array shiftedData; + ::coder::array domainLayerSlds; + ::coder::array r; + ::coder::array layerSlds; + ::coder::array b_reflectivity; + ::coder::array b_simulation; + ::coder::array domainSldProfiles; + ::coder::array r1; ::coder::array b_domainAllLayers; ::coder::array b_domainLayerSlds; ::coder::array b_domainSldProfiles; + ::coder::array cell1; + ::coder::array cell2; + ::coder::array cell3; ::coder::array cell4; ::coder::array cell5; ::coder::array cell6; @@ -247,34 +255,34 @@ namespace RAT // triggerEvent('message', 'Running reflectivity calculation...'); // for compilation, we have to preallocate memory for the output arrays // Setting these parameters in the struct defines them as doubles - problem->ssubs.set_size(1); - problem->ssubs[0] = 0.0; - problem->backgroundParams.set_size(1); - problem->backgroundParams[0] = 0.0; - problem->qzshifts.set_size(1); - problem->qzshifts[0] = 0.0; - problem->scalefactors.set_size(1); - problem->scalefactors[0] = 0.0; - problem->bulkIn.set_size(1); - problem->bulkIn[0] = 0.0; - problem->bulkOut.set_size(1); - problem->bulkOut[0] = 0.0; - problem->resolutionParams.set_size(1); - problem->resolutionParams[0] = 0.0; - problem->calculations.allChis.set_size(1); - problem->calculations.allChis[0] = 0.0; - problem->calculations.sumChi = 0.0; - problem->allSubRough.set_size(1); - problem->allSubRough[0] = 0.0; - problem->resample.set_size(1, 1); - problem->resample[0] = 0.0; + contrastParams->ssubs.set_size(1); + contrastParams->ssubs[0] = 0.0; + contrastParams->backgroundParams.set_size(1); + contrastParams->backgroundParams[0] = 0.0; + contrastParams->qzshifts.set_size(1); + contrastParams->qzshifts[0] = 0.0; + contrastParams->scalefactors.set_size(1); + contrastParams->scalefactors[0] = 0.0; + contrastParams->bulkIn.set_size(1); + contrastParams->bulkIn[0] = 0.0; + contrastParams->bulkOut.set_size(1); + contrastParams->bulkOut[0] = 0.0; + contrastParams->resolutionParams.set_size(1); + contrastParams->resolutionParams[0] = 0.0; + contrastParams->calculations.allChis.set_size(1); + contrastParams->calculations.allChis[0] = 0.0; + contrastParams->calculations.sumChi = 0.0; + contrastParams->allSubRough.set_size(1); + contrastParams->allSubRough[0] = 0.0; + contrastParams->resample.set_size(1, 1); + contrastParams->resample[0] = 0.0; // We also foll the results arrays to define their // type and size. (NOTE: at the moment we have a 'coder.varsize' // pre-processor directives for the compiler here and at the // end for the results block. We are unlikely to need both // TODO: Find out which is necessary and tidy this up. - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); reflectivity.set_size(i); simulation.set_size(i); shiftedData.set_size(i); @@ -343,10 +351,11 @@ namespace RAT } // Decide which target function we are calling and call the relevant routines - if (coder::internal::i_strcmp(problemDef->TF.data, problemDef->TF.size)) { + if (coder::internal::i_strcmp(problemStruct->TF.data, problemStruct->TF.size)) + { b_index = 0; - } else if (coder::internal::j_strcmp(problemDef->TF.data, - problemDef->TF.size)) { + } else if (coder::internal::j_strcmp(problemStruct->TF.data, + problemStruct->TF.size)) { b_index = 1; } else { b_index = -1; @@ -354,8 +363,8 @@ namespace RAT switch (b_index) { case 0: - nonPolarisedTF::b_reflectivityCalculation(problemDef, problemDefCells, - controls, problem, b_reflectivity, b_simulation, b_shiftedData, + nonPolarisedTF::b_reflectivityCalculation(problemStruct, problemCells, + controls, contrastParams, b_reflectivity, b_simulation, b_shiftedData, b_layerSlds, b_sldProfiles, b_allLayers); cast(b_reflectivity, reflectivity); cast(b_simulation, simulation); @@ -365,15 +374,15 @@ namespace RAT cast(b_allLayers, allLayers); // case 'oil water' - // problem = oilWaterTF_reflectivityCalculation(problemDef,problemDefCells,controls); + // contrastParams = oilWaterTFReflectivityCalculation(problemStruct,problemCells,controls); // case 'magnetic' - // problem = polarisedTF_reflectivityCalculation(problemDef,problemDefCells,controls); + // contrastParams = polarisedTFReflectivityCalculation(problemStruct,problemCells,controls); break; case 1: - domainsTF::b_reflectivityCalculation(problemDef, problemDefCells, controls, - problem, b_reflectivity, b_simulation, b_shiftedData, b_domainLayerSlds, - b_domainSldProfiles, b_domainAllLayers); + domainsTF::b_reflectivityCalculation(problemStruct, problemCells, controls, + contrastParams, b_reflectivity, b_simulation, b_shiftedData, + b_domainLayerSlds, b_domainSldProfiles, b_domainAllLayers); cast(b_reflectivity, reflectivity); cast(b_simulation, simulation); cast(b_shiftedData, shiftedData); @@ -415,38 +424,63 @@ namespace RAT break; } - result->f1.set_size(i); - result->f2.set_size(i); - result->f3.set_size(i); + cell1.set_size(i, 1); for (int32_T b_i{0}; b_i < i; b_i++) { b_index = reflectivity[b_i].f1.size(0); - result->f1[b_i].f1.set_size(reflectivity[b_i].f1.size(0), 2); - loop_ub = simulation[b_i].f1.size(0); - result->f2[b_i].f1.set_size(simulation[b_i].f1.size(0), 2); + cell1[b_i].f1.set_size(reflectivity[b_i].f1.size(0), 2); for (i1 = 0; i1 < 2; i1++) { for (int32_T i2{0}; i2 < b_index; i2++) { - result->f1[b_i].f1[i2 + result->f1[b_i].f1.size(0) * i1] = - reflectivity[b_i].f1[i2 + reflectivity[b_i].f1.size(0) * i1]; + cell1[b_i].f1[i2 + cell1[b_i].f1.size(0) * i1] = reflectivity[b_i] + .f1[i2 + reflectivity[b_i].f1.size(0) * i1]; } + } + } - for (int32_T i2{0}; i2 < loop_ub; i2++) { - result->f2[b_i].f1[i2 + result->f2[b_i].f1.size(0) * i1] = - simulation[b_i].f1[i2 + simulation[b_i].f1.size(0) * i1]; + resultCells[0].f1.set_size(cell1.size(0), 1); + b_index = cell1.size(0); + for (i1 = 0; i1 < b_index; i1++) { + resultCells[0].f1[i1] = cell1[i1]; + } + + cell2.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { + b_index = simulation[b_i].f1.size(0); + cell2[b_i].f1.set_size(simulation[b_i].f1.size(0), 2); + for (i1 = 0; i1 < 2; i1++) { + for (int32_T i2{0}; i2 < b_index; i2++) { + cell2[b_i].f1[i2 + cell2[b_i].f1.size(0) * i1] = simulation[b_i].f1[i2 + + simulation[b_i].f1.size(0) * i1]; } } + } + + resultCells[1].f1.set_size(cell2.size(0), 1); + b_index = cell2.size(0); + for (i1 = 0; i1 < b_index; i1++) { + resultCells[1].f1[i1] = cell2[i1]; + } + cell3.set_size(i, 1); + for (int32_T b_i{0}; b_i < i; b_i++) { b_index = shiftedData[b_i].f1.size(0); - result->f3[b_i].f1.set_size(shiftedData[b_i].f1.size(0), 3); + cell3[b_i].f1.set_size(shiftedData[b_i].f1.size(0), 3); for (i1 = 0; i1 < 3; i1++) { for (int32_T i2{0}; i2 < b_index; i2++) { - result->f3[b_i].f1[i2 + result->f3[b_i].f1.size(0) * i1] = - shiftedData[b_i].f1[i2 + shiftedData[b_i].f1.size(0) * i1]; + cell3[b_i].f1[i2 + cell3[b_i].f1.size(0) * i1] = shiftedData[b_i] + .f1[i2 + shiftedData[b_i].f1.size(0) * i1]; } } } + resultCells[2].f1.set_size(cell3.size(0), 1); + b_index = cell3.size(0); + for (i1 = 0; i1 < b_index; i1++) { + resultCells[2].f1[i1] = cell3[i1]; + } + // The size of this array now varies depending on TF - if (coder::internal::j_strcmp(problemDef->TF.data, problemDef->TF.size)) { + if (coder::internal::j_strcmp(problemStruct->TF.data, problemStruct->TF.size)) + { i1 = 0; } else { i1 = -1; @@ -481,12 +515,12 @@ namespace RAT } } - result->f4.set_size(cell4.size(0), 2); + resultCells[3].f1.set_size(cell4.size(0), 2); b_index = cell4.size(0); for (i1 = 0; i1 < 2; i1++) { for (int32_T i2{0}; i2 < b_index; i2++) { - result->f4[i2 + result->f4.size(0) * i1] = cell4[i2 + cell4.size(0) * - i1]; + resultCells[3].f1[i2 + resultCells[3].f1.size(0) * i1] = cell4[i2 + + cell4.size(0) * i1]; } } @@ -519,12 +553,12 @@ namespace RAT } } - result->f5.set_size(cell5.size(0), 2); + resultCells[4].f1.set_size(cell5.size(0), 2); b_index = cell5.size(0); for (i1 = 0; i1 < 2; i1++) { for (int32_T i2{0}; i2 < b_index; i2++) { - result->f5[i2 + result->f5.size(0) * i1] = cell5[i2 + cell5.size(0) * - i1]; + resultCells[4].f1[i2 + resultCells[4].f1.size(0) * i1] = cell5[i2 + + cell5.size(0) * i1]; } } @@ -550,11 +584,12 @@ namespace RAT } } - result->f6.set_size(cell6.size(0), 2); + resultCells[5].f1.set_size(cell6.size(0), 2); b_index = cell6.size(0); for (i = 0; i < 2; i++) { for (i1 = 0; i1 < b_index; i1++) { - result->f6[i1 + result->f6.size(0) * i] = cell6[i1 + cell6.size(0) * i]; + resultCells[5].f1[i1 + resultCells[5].f1.size(0) * i] = cell6[i1 + + cell6.size(0) * i]; } } } else { @@ -572,10 +607,10 @@ namespace RAT } } - result->f4.set_size(cell4.size(0), 1); + resultCells[3].f1.set_size(cell4.size(0), 1); b_index = cell4.size(0); for (i1 = 0; i1 < b_index; i1++) { - result->f4[i1] = cell4[i1]; + resultCells[3].f1[i1] = cell4[i1]; } cell5.set_size(i, 1); @@ -590,10 +625,10 @@ namespace RAT } } - result->f5.set_size(cell5.size(0), 1); + resultCells[4].f1.set_size(cell5.size(0), 1); b_index = cell5.size(0); for (i1 = 0; i1 < b_index; i1++) { - result->f5[i1] = cell5[i1]; + resultCells[4].f1[i1] = cell5[i1]; } cell6.set_size(i, 1); @@ -608,10 +643,10 @@ namespace RAT } } - result->f6.set_size(cell6.size(0), 1); + resultCells[5].f1.set_size(cell6.size(0), 1); b_index = cell6.size(0); for (i = 0; i < b_index; i++) { - result->f6[i] = cell6[i]; + resultCells[5].f1[i] = cell6[i]; } } diff --git a/RAT/reflectivityCalculation.h b/RAT/reflectivityCalculation.h index 70b75e0c..d82580bb 100644 --- a/RAT/reflectivityCalculation.h +++ b/RAT/reflectivityCalculation.h @@ -18,19 +18,19 @@ // Type Declarations namespace RAT { - struct struct5_T; - struct cell_14; + struct c_struct_T; + struct cell_11; struct struct2_T; - struct struct_T; - struct cell_13; + struct d_struct_T; + struct cell_wrap_9; } // Function Declarations namespace RAT { - void reflectivityCalculation(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, struct_T *problem, cell_13 - *result); + void reflectivityCalculation(const c_struct_T *problemStruct, const cell_11 + *problemCells, const struct2_T *controls, d_struct_T *contrastParams, + cell_wrap_9 resultCells[6]); } #endif diff --git a/RAT/reflectivityCalculation1.cpp b/RAT/reflectivityCalculation1.cpp index d937733b..a7cc5e3f 100644 --- a/RAT/reflectivityCalculation1.cpp +++ b/RAT/reflectivityCalculation1.cpp @@ -26,12 +26,12 @@ namespace RAT { namespace nonPolarisedTF { - void b_reflectivityCalculation(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array - &simulation, ::coder::array &shiftedData, ::coder::array< - cell_wrap_8, 1U> &layerSlds, ::coder::array &sldProfiles, - ::coder::array &allLayers) + void b_reflectivityCalculation(const c_struct_T *problemStruct, const + cell_11 *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers) { int32_T switch_expression_size[2]; int32_T loop_ub_tmp; @@ -52,18 +52,18 @@ namespace RAT // Pre-allocate the output arrays.. this is necessary because otherwise // the compiler complains with 'Output argument <....> is not assigned on // some execution paths' error. - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgroundParams.set_size(loop_ub_tmp); - problem->qzshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->bulkIn.set_size(loop_ub_tmp); - problem->bulkOut.set_size(loop_ub_tmp); - problem->resolutionParams.set_size(loop_ub_tmp); - problem->calculations.allChis.set_size(loop_ub_tmp); - problem->calculations.sumChi = 0.0; - problem->allSubRough.set_size(loop_ub_tmp); - problem->resample.set_size(1, loop_ub_tmp); + loop_ub_tmp = static_cast(problemStruct->numberOfContrasts); + contrastParams->ssubs.set_size(loop_ub_tmp); + contrastParams->backgroundParams.set_size(loop_ub_tmp); + contrastParams->qzshifts.set_size(loop_ub_tmp); + contrastParams->scalefactors.set_size(loop_ub_tmp); + contrastParams->bulkIn.set_size(loop_ub_tmp); + contrastParams->bulkOut.set_size(loop_ub_tmp); + contrastParams->resolutionParams.set_size(loop_ub_tmp); + contrastParams->calculations.allChis.set_size(loop_ub_tmp); + contrastParams->calculations.sumChi = 0.0; + contrastParams->allSubRough.set_size(loop_ub_tmp); + contrastParams->resample.set_size(1, loop_ub_tmp); reflectivity.set_size(loop_ub_tmp); simulation.set_size(loop_ub_tmp); shiftedData.set_size(loop_ub_tmp); @@ -71,16 +71,16 @@ namespace RAT sldProfiles.set_size(loop_ub_tmp); allLayers.set_size(loop_ub_tmp); for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgroundParams[i] = 0.0; - problem->qzshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->bulkIn[i] = 0.0; - problem->bulkOut[i] = 0.0; - problem->resolutionParams[i] = 0.0; - problem->calculations.allChis[i] = 0.0; - problem->allSubRough[i] = 0.0; - problem->resample[i] = 0.0; + contrastParams->ssubs[i] = 0.0; + contrastParams->backgroundParams[i] = 0.0; + contrastParams->qzshifts[i] = 0.0; + contrastParams->scalefactors[i] = 0.0; + contrastParams->bulkIn[i] = 0.0; + contrastParams->bulkOut[i] = 0.0; + contrastParams->resolutionParams[i] = 0.0; + contrastParams->calculations.allChis[i] = 0.0; + contrastParams->allSubRough[i] = 0.0; + contrastParams->resample[i] = 0.0; reflectivity[i].f1.set_size(2, 2); reflectivity[i].f1[0] = 1.0; reflectivity[i].f1[1] = 1.0; @@ -109,7 +109,7 @@ namespace RAT } } - coder::lower(problemDef->modelType.data, problemDef->modelType.size, + coder::lower(problemStruct->modelType.data, problemStruct->modelType.size, switch_expression_data, switch_expression_size); if (coder::internal::k_strcmp(switch_expression_data, switch_expression_size)) { @@ -127,23 +127,23 @@ namespace RAT switch (loop_ub_tmp) { case 0: // Standard layers calculation - standardLayers::calculate(problemDef, problemDefCells, controls, problem, - reflectivity, simulation, shiftedData, layerSlds, sldProfiles, - allLayers); + standardLayers::calculate(problemStruct, problemCells, controls, + contrastParams, reflectivity, simulation, shiftedData, layerSlds, + sldProfiles, allLayers); break; case 1: // Custom layers with user supplied custom model file - customLayers::calculate(problemDef, problemDefCells, controls, problem, - reflectivity, simulation, shiftedData, layerSlds, sldProfiles, - allLayers); + customLayers::calculate(problemStruct, problemCells, controls, + contrastParams, reflectivity, simulation, shiftedData, layerSlds, + sldProfiles, allLayers); break; case 2: // Custom SLD profile with user defined model file - customXY::calculate(problemDef, problemDefCells, controls, problem, - reflectivity, simulation, shiftedData, layerSlds, - sldProfiles, allLayers); + customXY::calculate(problemStruct, problemCells, controls, + contrastParams, reflectivity, simulation, + shiftedData, layerSlds, sldProfiles, allLayers); break; } } diff --git a/RAT/reflectivityCalculation1.h b/RAT/reflectivityCalculation1.h index 5c2b8a53..4d2dc677 100644 --- a/RAT/reflectivityCalculation1.h +++ b/RAT/reflectivityCalculation1.h @@ -11,30 +11,24 @@ #define REFLECTIVITYCALCULATION1_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; - struct struct_T; -} - // Function Declarations namespace RAT { namespace nonPolarisedTF { - void b_reflectivityCalculation(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array - &simulation, ::coder::array &shiftedData, ::coder::array< - cell_wrap_8, 1U> &layerSlds, ::coder::array &sldProfiles, - ::coder::array &allLayers); + void b_reflectivityCalculation(const c_struct_T *problemStruct, const + cell_11 *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 1U> &sldProfiles, ::coder::array &allLayers); } } diff --git a/RAT/reflectivityCalculation2.cpp b/RAT/reflectivityCalculation2.cpp index 73d615a4..58048bf6 100644 --- a/RAT/reflectivityCalculation2.cpp +++ b/RAT/reflectivityCalculation2.cpp @@ -26,12 +26,13 @@ namespace RAT { namespace domainsTF { - void b_reflectivityCalculation(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array - &simulation, ::coder::array &shiftedData, ::coder::array< - cell_wrap_8, 2U> &layerSlds, ::coder::array - &domainSldProfiles, ::coder::array &allLayers) + void b_reflectivityCalculation(const c_struct_T *problemStruct, const + cell_11 *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array + &allLayers) { ::coder::array b_domainSldProfiles; ::coder::array b_layerSlds; @@ -55,18 +56,18 @@ namespace RAT // Pre-allocate the output arrays.. this is necessary because otherwise // the compiler complains with 'Output argument <....> is not assigned on // some execution paths' error. - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); - problem->ssubs.set_size(loop_ub_tmp); - problem->backgroundParams.set_size(loop_ub_tmp); - problem->qzshifts.set_size(loop_ub_tmp); - problem->scalefactors.set_size(loop_ub_tmp); - problem->bulkIn.set_size(loop_ub_tmp); - problem->bulkOut.set_size(loop_ub_tmp); - problem->resolutionParams.set_size(loop_ub_tmp); - problem->calculations.allChis.set_size(loop_ub_tmp); - problem->calculations.sumChi = 0.0; - problem->allSubRough.set_size(loop_ub_tmp); - problem->resample.set_size(1, loop_ub_tmp); + loop_ub_tmp = static_cast(problemStruct->numberOfContrasts); + contrastParams->ssubs.set_size(loop_ub_tmp); + contrastParams->backgroundParams.set_size(loop_ub_tmp); + contrastParams->qzshifts.set_size(loop_ub_tmp); + contrastParams->scalefactors.set_size(loop_ub_tmp); + contrastParams->bulkIn.set_size(loop_ub_tmp); + contrastParams->bulkOut.set_size(loop_ub_tmp); + contrastParams->resolutionParams.set_size(loop_ub_tmp); + contrastParams->calculations.allChis.set_size(loop_ub_tmp); + contrastParams->calculations.sumChi = 0.0; + contrastParams->allSubRough.set_size(loop_ub_tmp); + contrastParams->resample.set_size(1, loop_ub_tmp); reflectivity.set_size(loop_ub_tmp); simulation.set_size(loop_ub_tmp); shiftedData.set_size(loop_ub_tmp); @@ -74,16 +75,16 @@ namespace RAT domainSldProfiles.set_size(loop_ub_tmp, 2); allLayers.set_size(loop_ub_tmp, 2); for (int32_T i{0}; i < loop_ub_tmp; i++) { - problem->ssubs[i] = 0.0; - problem->backgroundParams[i] = 0.0; - problem->qzshifts[i] = 0.0; - problem->scalefactors[i] = 0.0; - problem->bulkIn[i] = 0.0; - problem->bulkOut[i] = 0.0; - problem->resolutionParams[i] = 0.0; - problem->calculations.allChis[i] = 0.0; - problem->allSubRough[i] = 0.0; - problem->resample[i] = 0.0; + contrastParams->ssubs[i] = 0.0; + contrastParams->backgroundParams[i] = 0.0; + contrastParams->qzshifts[i] = 0.0; + contrastParams->scalefactors[i] = 0.0; + contrastParams->bulkIn[i] = 0.0; + contrastParams->bulkOut[i] = 0.0; + contrastParams->resolutionParams[i] = 0.0; + contrastParams->calculations.allChis[i] = 0.0; + contrastParams->allSubRough[i] = 0.0; + contrastParams->resample[i] = 0.0; reflectivity[i].f1.set_size(2, 2); reflectivity[i].f1[0] = 1.0; reflectivity[i].f1[1] = 1.0; @@ -129,7 +130,7 @@ namespace RAT } } - coder::lower(problemDef->modelType.data, problemDef->modelType.size, + coder::lower(problemStruct->modelType.data, problemStruct->modelType.size, switch_expression_data, switch_expression_size); if (coder::internal::k_strcmp(switch_expression_data, switch_expression_size)) { @@ -147,9 +148,9 @@ namespace RAT switch (loop_ub_tmp) { case 0: // Standard layers calculation - standardLayers::calculate(problemDef, problemDefCells, controls, problem, - reflectivity, simulation, shiftedData, layerSlds, domainSldProfiles, - allLayers); + standardLayers::calculate(problemStruct, problemCells, controls, + contrastParams, reflectivity, simulation, shiftedData, layerSlds, + domainSldProfiles, allLayers); break; case 1: @@ -157,8 +158,8 @@ namespace RAT int32_T loop_ub; // Custom layers with user supplied custom model file - customLayers::calculate(problemDef, problemDefCells, controls, problem, - reflectivity, simulation, shiftedData, b_layerSlds, + customLayers::calculate(problemStruct, problemCells, controls, + contrastParams, reflectivity, simulation, shiftedData, b_layerSlds, b_domainSldProfiles, r); layerSlds.set_size(b_layerSlds.size(0), 2); domainSldProfiles.set_size(b_domainSldProfiles.size(0), 2); @@ -192,9 +193,9 @@ namespace RAT int32_T loop_ub; // Custom SLD profile with user defined model file - customXY::calculate(problemDef, problemDefCells, controls, problem, - reflectivity, simulation, shiftedData, b_layerSlds, - b_domainSldProfiles, r); + customXY::calculate(problemStruct, problemCells, controls, + contrastParams, reflectivity, simulation, + shiftedData, b_layerSlds, b_domainSldProfiles, r); layerSlds.set_size(b_layerSlds.size(0), 2); domainSldProfiles.set_size(b_domainSldProfiles.size(0), 2); loop_ub_tmp = b_layerSlds.size(0); diff --git a/RAT/reflectivityCalculation2.h b/RAT/reflectivityCalculation2.h index 1024a1b8..57b89647 100644 --- a/RAT/reflectivityCalculation2.h +++ b/RAT/reflectivityCalculation2.h @@ -11,30 +11,25 @@ #define REFLECTIVITYCALCULATION2_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; - struct struct_T; -} - // Function Declarations namespace RAT { namespace domainsTF { - void b_reflectivityCalculation(const struct5_T *problemDef, const cell_14 - *problemDefCells, const struct2_T *controls, struct_T *problem, ::coder:: - array &reflectivity, ::coder::array - &simulation, ::coder::array &shiftedData, ::coder::array< - cell_wrap_8, 2U> &layerSlds, ::coder::array - &domainSldProfiles, ::coder::array &allLayers); + void b_reflectivityCalculation(const c_struct_T *problemStruct, const + cell_11 *problemCells, const struct2_T *controls, d_struct_T + *contrastParams, ::coder::array &reflectivity, ::coder:: + array &simulation, ::coder::array + &shiftedData, ::coder::array &layerSlds, ::coder::array< + cell_wrap_8, 2U> &domainSldProfiles, ::coder::array + &allLayers); } } diff --git a/RAT/removeOutlier.cpp b/RAT/removeOutlier.cpp index 040b77c3..67e71574 100644 --- a/RAT/removeOutlier.cpp +++ b/RAT/removeOutlier.cpp @@ -65,7 +65,7 @@ namespace RAT void removeOutlier(::coder::array &X, ::coder::array &log_L, const real_T outlier_data[], const int32_T - outlier_size[2], const struct14_T *DREAMPar, ::coder::array< + outlier_size[2], const struct13_T *DREAMPar, ::coder::array< real_T, 2U> &outputOutlier) { ::coder::array b_chain_select; diff --git a/RAT/removeOutlier.h b/RAT/removeOutlier.h index e2ed7a34..a7365419 100644 --- a/RAT/removeOutlier.h +++ b/RAT/removeOutlier.h @@ -19,7 +19,7 @@ // Type Declarations namespace RAT { - struct struct14_T; + struct struct13_T; } // Function Declarations @@ -27,7 +27,7 @@ namespace RAT { void removeOutlier(::coder::array &X, ::coder::array &log_L, const real_T outlier_data[], const int32_T - outlier_size[2], const struct14_T *DREAMPar, ::coder::array< + outlier_size[2], const struct13_T *DREAMPar, ::coder::array< real_T, 2U> &outputOutlier); } diff --git a/RAT/repmat.cpp b/RAT/repmat.cpp index 2fbba03e..5879c34d 100644 --- a/RAT/repmat.cpp +++ b/RAT/repmat.cpp @@ -41,7 +41,7 @@ namespace RAT } } - void repmat(real_T varargin_1, ::coder::array &b) + void repmat(real_T varargin_1, ::coder::array &b) { int32_T loop_ub_tmp; loop_ub_tmp = static_cast(varargin_1); diff --git a/RAT/repmat.h b/RAT/repmat.h index 0e65e9b0..6f35398c 100644 --- a/RAT/repmat.h +++ b/RAT/repmat.h @@ -30,7 +30,7 @@ namespace RAT { void b_repmat(real_T varargin_2, ::coder::array &b); void repmat(cell_wrap_9 b[6]); - void repmat(real_T varargin_1, ::coder::array &b); + void repmat(real_T varargin_1, ::coder::array &b); void repmat(const ::coder::array &a, real_T varargin_1, ::coder:: array &b); void repmat(real_T varargin_2, ::coder::array &b); diff --git a/RAT/resampleLayers.cpp b/RAT/resampleLayers.cpp index 0e0e698f..0c086b40 100644 --- a/RAT/resampleLayers.cpp +++ b/RAT/resampleLayers.cpp @@ -22,7 +22,7 @@ namespace RAT void resampleLayers(const ::coder::array &sldProfile, const real_T resamPars[2], ::coder::array &newSLD) { - cell_27 expl_temp; + cell_25 expl_temp; real_T b_sldProfile[2]; int32_T i; int32_T n; diff --git a/RAT/resampleLayersReIm.cpp b/RAT/resampleLayersReIm.cpp index dd4d7ba8..fe78e640 100644 --- a/RAT/resampleLayersReIm.cpp +++ b/RAT/resampleLayersReIm.cpp @@ -11,8 +11,6 @@ // Include files #include "resampleLayersReIm.h" #include "RATMain_internal_types.h" -#include "RATMain_rtwutil.h" -#include "RATMain_types.h" #include "adaptive.h" #include "interp1.h" #include "rt_nonfinite.h" @@ -29,7 +27,7 @@ namespace RAT ::coder::array b_sldProfileIm; ::coder::array c_sldProfileIm; ::coder::array newYIm; - cell_27 expl_temp; + cell_25 expl_temp; real_T b_sldProfile[2]; int32_T i; int32_T loop_ub; @@ -105,22 +103,18 @@ namespace RAT } } - void c_resampleLayersReIm(const ::coder::array &sldProfile, const :: + void resampleLayersReIm(const ::coder::array &sldProfile, const :: coder::array &sldProfileIm, const real_T resamPars[2], ::coder:: array &newSLD) { ::coder::array b_expl_temp; - ::coder::array b_sldProfileIm_data; + ::coder::array b_sldProfileIm; + ::coder::array c_sldProfileIm; ::coder::array newYIm; - ::coder::array sldProfileIm_data; - RATMainTLS *RATMainTLSThread; - cell_27 expl_temp; + cell_25 expl_temp; real_T b_sldProfile[2]; - int32_T b_sldProfileIm_size; int32_T i; int32_T loop_ub; - int32_T sldProfileIm_size; - RATMainTLSThread = emlrtGetThreadStackData(); // Resample the SLD profile. In this case we have an imaginary SLD also, and // so we resample that onto the same points as the real one.. @@ -132,22 +126,21 @@ namespace RAT // newX = linspace(xstart,xend,100); b_sldProfile[0] = sldProfile[0]; b_sldProfile[1] = sldProfile[sldProfile.size(0) - 1]; - b_adaptive(sldProfile, b_sldProfile, resamPars[0] * 3.1415926535897931, - resamPars[1], &expl_temp); + adaptive(sldProfile, b_sldProfile, resamPars[0] * 3.1415926535897931, + resamPars[1], &expl_temp); // Now interpolate the imaginary profile so that it is on the same x points // as the resampled real one.... - sldProfileIm_size = sldProfileIm.size(0); + b_sldProfileIm.set_size(sldProfileIm.size(0)); loop_ub = sldProfileIm.size(0); for (i = 0; i < loop_ub; i++) { - RATMainTLSThread->f2.sldProfileIm_data[i] = sldProfileIm[i]; + b_sldProfileIm[i] = sldProfileIm[i]; } - b_sldProfileIm_size = sldProfileIm.size(0); + c_sldProfileIm.set_size(sldProfileIm.size(0)); loop_ub = sldProfileIm.size(0); for (i = 0; i < loop_ub; i++) { - RATMainTLSThread->f2.b_sldProfileIm_data[i] = sldProfileIm[i + - sldProfileIm.size(0)]; + c_sldProfileIm[i] = sldProfileIm[i + sldProfileIm.size(0)]; } b_expl_temp.set_size(expl_temp.f1.size(0)); @@ -156,17 +149,12 @@ namespace RAT b_expl_temp[i] = expl_temp.f1[i]; } - sldProfileIm_data.set(&RATMainTLSThread->f2.sldProfileIm_data[0], - sldProfileIm_size); - b_sldProfileIm_data.set(&RATMainTLSThread->f2.b_sldProfileIm_data[0], - b_sldProfileIm_size); - coder::interp1(sldProfileIm_data, b_sldProfileIm_data, b_expl_temp, newYIm); + coder::interp1(b_sldProfileIm, c_sldProfileIm, b_expl_temp, newYIm); newSLD.set_size(expl_temp.f1.size(0) - 1, 4); loop_ub = expl_temp.f1.size(0) - 1; for (i = 0; i < 4; i++) { - for (sldProfileIm_size = 0; sldProfileIm_size < loop_ub; sldProfileIm_size - ++) { - newSLD[sldProfileIm_size + newSLD.size(0) * i] = 0.0; + for (int32_T i1{0}; i1 < loop_ub; i1++) { + newSLD[i1 + newSLD.size(0) * i] = 0.0; } } diff --git a/RAT/resampleLayersReIm.h b/RAT/resampleLayersReIm.h index 8df0be4b..a943e3dc 100644 --- a/RAT/resampleLayersReIm.h +++ b/RAT/resampleLayersReIm.h @@ -22,7 +22,7 @@ namespace RAT void b_resampleLayersReIm(const ::coder::array &sldProfile, const :: coder::array &sldProfileIm, const real_T resamPars[2], ::coder:: array &newSLD); - void c_resampleLayersReIm(const ::coder::array &sldProfile, const :: + void resampleLayersReIm(const ::coder::array &sldProfile, const :: coder::array &sldProfileIm, const real_T resamPars[2], ::coder:: array &newSLD); } diff --git a/RAT/runDE.cpp b/RAT/runDE.cpp index 64fe92fc..103c6aa0 100644 --- a/RAT/runDE.cpp +++ b/RAT/runDE.cpp @@ -27,84 +27,84 @@ // Function Definitions namespace RAT { - k_struct_T intrafun(const ::coder::array &p, struct5_T *problemDef, - const char_T controls_parallel_data[], const int32_T - controls_parallel_size[2], const real_T + l_struct_T intrafun(const ::coder::array &p, c_struct_T + *problemStruct, const char_T controls_parallel_data[], + const int32_T controls_parallel_size[2], const real_T controls_resamPars[2], boolean_T controls_calcSldDuringFit, const struct3_T *controls_checks, const ::coder::array< - cell_wrap_2, 2U> &problemDefCells_f1, const ::coder::array< - cell_wrap_8, 2U> &problemDefCells_f2, const ::coder::array< - cell_wrap_2, 2U> &problemDefCells_f3, const ::coder::array< - cell_wrap_2, 2U> &problemDefCells_f4, const ::coder::array< - cell_wrap_8, 2U> &problemDefCells_f5, const ::coder::array< - cell_wrap_8, 1U> &problemDefCells_f6, const ::coder::array< - cell_wrap_1, 2U> &problemDefCells_f14, const ::coder:: - array &problemDefCells_f19) + cell_wrap_2, 2U> &problemCells_f1, const ::coder::array< + cell_wrap_8, 2U> &problemCells_f2, const ::coder::array< + cell_wrap_2, 2U> &problemCells_f3, const ::coder::array< + cell_wrap_2, 2U> &problemCells_f4, const ::coder::array< + cell_wrap_8, 2U> &problemCells_f5, const ::coder::array< + cell_wrap_8, 1U> &problemCells_f6, const ::coder::array< + cell_wrap_1, 2U> &problemCells_f14, const ::coder::array< + cell_wrap_8, 2U> &problemCells_f19) { - cell_13 a__2; - cell_14 expl_temp; - k_struct_T S_MSE; + cell_11 expl_temp; + cell_wrap_9 a__2[6]; + d_struct_T b_problemStruct; + l_struct_T S_MSE; struct2_T b_expl_temp; - struct_T b_problemDef; int32_T loop_ub; - problemDef->fitParams.set_size(1, p.size(1)); + problemStruct->fitParams.set_size(1, p.size(1)); loop_ub = p.size(1); for (int32_T i{0}; i < loop_ub; i++) { - problemDef->fitParams[problemDef->fitParams.size(0) * i] = p[i]; + problemStruct->fitParams[problemStruct->fitParams.size(0) * i] = p[i]; } - unpackParams(problemDef, controls_checks->fitParam, + unpackParams(problemStruct, controls_checks->fitParam, controls_checks->fitBackgroundParam, controls_checks->fitQzshift, controls_checks->fitScalefactor, controls_checks->fitBulkIn, controls_checks->fitBulkOut, controls_checks->fitResolutionParam, controls_checks->fitDomainRatio); - expl_temp.f19.set_size(1, problemDefCells_f19.size(1)); - loop_ub = problemDefCells_f19.size(1); + expl_temp.f19.set_size(1, problemCells_f19.size(1)); + loop_ub = problemCells_f19.size(1); for (int32_T i{0}; i < loop_ub; i++) { - expl_temp.f19[i] = problemDefCells_f19[i]; + expl_temp.f19[i] = problemCells_f19[i]; } - expl_temp.f14.set_size(1, problemDefCells_f14.size(1)); - loop_ub = problemDefCells_f14.size(1); + expl_temp.f14.set_size(1, problemCells_f14.size(1)); + loop_ub = problemCells_f14.size(1); for (int32_T i{0}; i < loop_ub; i++) { - expl_temp.f14[i] = problemDefCells_f14[i]; + expl_temp.f14[i] = problemCells_f14[i]; } - expl_temp.f6.set_size(problemDefCells_f6.size(0)); - loop_ub = problemDefCells_f6.size(0); + expl_temp.f6.set_size(problemCells_f6.size(0)); + loop_ub = problemCells_f6.size(0); for (int32_T i{0}; i < loop_ub; i++) { - expl_temp.f6[i] = problemDefCells_f6[i]; + expl_temp.f6[i] = problemCells_f6[i]; } - expl_temp.f5.set_size(1, problemDefCells_f5.size(1)); - loop_ub = problemDefCells_f5.size(1); + expl_temp.f5.set_size(1, problemCells_f5.size(1)); + loop_ub = problemCells_f5.size(1); for (int32_T i{0}; i < loop_ub; i++) { - expl_temp.f5[i] = problemDefCells_f5[i]; + expl_temp.f5[i] = problemCells_f5[i]; } - expl_temp.f4.set_size(1, problemDefCells_f4.size(1)); - loop_ub = problemDefCells_f4.size(1); + expl_temp.f4.set_size(1, problemCells_f4.size(1)); + loop_ub = problemCells_f4.size(1); for (int32_T i{0}; i < loop_ub; i++) { - expl_temp.f4[i] = problemDefCells_f4[i]; + expl_temp.f4[i] = problemCells_f4[i]; } - expl_temp.f3.set_size(1, problemDefCells_f3.size(1)); - loop_ub = problemDefCells_f3.size(1); + expl_temp.f3.set_size(1, problemCells_f3.size(1)); + loop_ub = problemCells_f3.size(1); for (int32_T i{0}; i < loop_ub; i++) { - expl_temp.f3[i] = problemDefCells_f3[i]; + expl_temp.f3[i] = problemCells_f3[i]; } - expl_temp.f2.set_size(1, problemDefCells_f2.size(1)); - loop_ub = problemDefCells_f2.size(1); + expl_temp.f2.set_size(1, problemCells_f2.size(1)); + loop_ub = problemCells_f2.size(1); for (int32_T i{0}; i < loop_ub; i++) { - expl_temp.f2[i] = problemDefCells_f2[i]; + expl_temp.f2[i] = problemCells_f2[i]; } - expl_temp.f1.set_size(1, problemDefCells_f1.size(1)); - loop_ub = problemDefCells_f1.size(1); + expl_temp.f1.set_size(1, problemCells_f1.size(1)); + loop_ub = problemCells_f1.size(1); for (int32_T i{0}; i < loop_ub; i++) { - expl_temp.f1[i] = problemDefCells_f1[i]; + expl_temp.f1[i] = problemCells_f1[i]; } b_expl_temp.checks = *controls_checks; @@ -119,9 +119,9 @@ namespace RAT &b_expl_temp.parallel.data[0]); } - reflectivityCalculation(problemDef, &expl_temp, &b_expl_temp, &b_problemDef, - &a__2); - S_MSE.FVr_oa = b_problemDef.calculations.sumChi; + reflectivityCalculation(problemStruct, &expl_temp, &b_expl_temp, + &b_problemStruct, a__2); + S_MSE.FVr_oa = b_problemStruct.calculations.sumChi; // no constraints THESE FIRST FEW VALS MAY BE WRONG // no constraint array @@ -131,9 +131,9 @@ namespace RAT return S_MSE; } - void runDE(struct5_T *problemDef, const cell_14 *problemDefCells, const - struct1_T *problemDefLimits, const struct2_T *controls, struct_T - *problem, cell_wrap_9 result[6]) + void runDE(c_struct_T *problemStruct, const cell_11 *problemCells, const + struct1_T *problemLimits, const struct2_T *controls, d_struct_T + *contrastParams, cell_wrap_9 result[6]) { static const real_T FVr_x[50]{ -1.0, -0.95918367346938771, -0.91836734693877542, -0.87755102040816324, -0.836734693877551, @@ -153,35 +153,28 @@ namespace RAT 0.79591836734693866, 0.836734693877551, 0.87755102040816324, 0.91836734693877542, 0.95918367346938771, 1.0 }; - ::coder::array b_problemDef; + ::coder::array b_problemStruct; ::coder::array res; ::coder::array S_struct_FM_pop; - cell_13 b_result; - i_struct_T expl_temp; + j_struct_T expl_temp; int32_T loop_ub; - int32_T loop_ub_tmp; - packParams(problemDef, problemDefCells->f7, problemDefCells->f8, - problemDefCells->f9, problemDefCells->f10, problemDefCells->f11, - problemDefCells->f12, problemDefCells->f13, problemDefCells->f20, - problemDefLimits, &controls->checks, b_problemDef); + packParams(problemStruct, problemCells->f7, problemCells->f8, + problemCells->f9, problemCells->f10, problemCells->f11, + problemCells->f12, problemCells->f13, problemCells->f20, + problemLimits, &controls->checks, b_problemStruct); - // Check the bounds on all the selected - // out = checkBounds(problemDef,controls); - // if strcmp(out{1},'fail') - // return - // end // Value to reach - expl_temp.FVr_minbound.set_size(1, problemDef->fitLimits.size(0)); - loop_ub = problemDef->fitLimits.size(0); + expl_temp.FVr_minbound.set_size(1, problemStruct->fitLimits.size(0)); + loop_ub = problemStruct->fitLimits.size(0); for (int32_T i{0}; i < loop_ub; i++) { - expl_temp.FVr_minbound[i] = problemDef->fitLimits[i]; + expl_temp.FVr_minbound[i] = problemStruct->fitLimits[i]; } - expl_temp.FVr_maxbound.set_size(1, problemDef->fitLimits.size(0)); - loop_ub = problemDef->fitLimits.size(0); + expl_temp.FVr_maxbound.set_size(1, problemStruct->fitLimits.size(0)); + loop_ub = problemStruct->fitLimits.size(0); for (int32_T i{0}; i < loop_ub; i++) { - expl_temp.FVr_maxbound[i] = problemDef->fitLimits[i + - problemDef->fitLimits.size(0)]; + expl_temp.FVr_maxbound[i] = problemStruct->fitLimits[i + + problemStruct->fitLimits.size(0)]; } // 1: use bounds as bound constraints, 0: no bound constraints @@ -220,11 +213,11 @@ namespace RAT expl_temp.FVr_x.size[0] = 1; expl_temp.FVr_x.size[1] = 50; std::copy(&FVr_x[0], &FVr_x[50], &expl_temp.FVr_x.data[0]); - loop_ub_tmp = static_cast(controls->populationSize); - S_struct_FM_pop.set_size(loop_ub_tmp, 2); + loop_ub = static_cast(controls->populationSize); + S_struct_FM_pop.set_size(loop_ub, 2); expl_temp.FVr_bestmem.set_size(1, 2); for (int32_T i{0}; i < 2; i++) { - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { + for (int32_T i1{0}; i1 < loop_ub; i1++) { S_struct_FM_pop[i1 + S_struct_FM_pop.size(0) * i] = 0; } @@ -245,8 +238,8 @@ namespace RAT expl_temp.F_VTR = controls->targetValue; expl_temp.I_itermax = controls->numGenerations; expl_temp.I_bnd_constr = 1.0; - expl_temp.I_D = coder::internal::intlength(problemDef->fitParams.size(0), - problemDef->fitParams.size(1)); + expl_temp.I_D = coder::internal::intlength(problemStruct->fitParams.size(0), + problemStruct->fitParams.size(1)); expl_temp.F_CR = controls->crossoverProbability; expl_temp.fWeight = controls->fWeight; expl_temp.I_NP = controls->populationSize; @@ -261,98 +254,29 @@ namespace RAT expl_temp.I_lentol.size[0] = 1; expl_temp.I_lentol.data[0] = 50.0; - deopt(problemDef, problemDefCells->f1, problemDefCells->f2, - problemDefCells->f3, problemDefCells->f4, problemDefCells->f5, - problemDefCells->f6, problemDefCells->f14, problemDefCells->f19, - controls->parallel.data, controls->parallel.size, controls->resamPars, + deopt(problemStruct, problemCells->f1, problemCells->f2, problemCells->f3, + problemCells->f4, problemCells->f5, problemCells->f6, + problemCells->f14, problemCells->f19, controls->parallel.data, + controls->parallel.size, controls->resamPars, controls->calcSldDuringFit, controls->display.data, controls->display.size, &controls->checks, &expl_temp, res); - problemDef->fitParams.set_size(1, res.size(1)); + problemStruct->fitParams.set_size(1, res.size(1)); loop_ub = res.size(1); for (int32_T i{0}; i < loop_ub; i++) { - problemDef->fitParams[problemDef->fitParams.size(0) * i] = res[i]; + problemStruct->fitParams[problemStruct->fitParams.size(0) * i] = res[i]; } - unpackParams(problemDef, controls->checks.fitParam, + unpackParams(problemStruct, controls->checks.fitParam, controls->checks.fitBackgroundParam, controls->checks.fitQzshift, controls->checks.fitScalefactor, controls->checks.fitBulkIn, controls->checks.fitBulkOut, controls->checks.fitResolutionParam, controls->checks.fitDomainRatio); - reflectivityCalculation(problemDef, problemDefCells, controls, problem, - &b_result); - result[0].f1.set_size(b_result.f1.size(0), 1); - loop_ub_tmp = b_result.f1.size(0); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - loop_ub = b_result.f1[i].f1.size(0); - result[0].f1[i].f1.set_size(b_result.f1[i].f1.size(0), 2); - for (int32_T i1{0}; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - result[0].f1[i].f1[i2 + result[0].f1[i].f1.size(0) * i1] = - b_result.f1[i].f1[i2 + b_result.f1[i].f1.size(0) * i1]; - } - } - } - - result[1].f1.set_size(b_result.f2.size(0), 1); - loop_ub_tmp = b_result.f2.size(0); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - loop_ub = b_result.f2[i].f1.size(0); - result[1].f1[i].f1.set_size(b_result.f2[i].f1.size(0), 2); - for (int32_T i1{0}; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - result[1].f1[i].f1[i2 + result[1].f1[i].f1.size(0) * i1] = - b_result.f2[i].f1[i2 + b_result.f2[i].f1.size(0) * i1]; - } - } - } - - result[2].f1.set_size(b_result.f3.size(0), 1); - loop_ub_tmp = b_result.f3.size(0); - for (int32_T i{0}; i < loop_ub_tmp; i++) { - loop_ub = b_result.f3[i].f1.size(0); - result[2].f1[i].f1.set_size(b_result.f3[i].f1.size(0), 3); - for (int32_T i1{0}; i1 < 3; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - result[2].f1[i].f1[i2 + result[2].f1[i].f1.size(0) * i1] = - b_result.f3[i].f1[i2 + b_result.f3[i].f1.size(0) * i1]; - } - } - } - - result[3].f1.set_size(b_result.f4.size(0), b_result.f4.size(1)); - loop_ub = b_result.f4.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_result.f4.size(0); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { - result[3].f1[i1 + result[3].f1.size(0) * i] = b_result.f4[i1 + - b_result.f4.size(0) * i]; - } - } - - result[4].f1.set_size(b_result.f5.size(0), b_result.f5.size(1)); - loop_ub = b_result.f5.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_result.f5.size(0); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { - result[4].f1[i1 + result[4].f1.size(0) * i] = b_result.f5[i1 + - b_result.f5.size(0) * i]; - } - } - - result[5].f1.set_size(b_result.f6.size(0), b_result.f6.size(1)); - loop_ub = b_result.f6.size(1); - for (int32_T i{0}; i < loop_ub; i++) { - loop_ub_tmp = b_result.f6.size(0); - for (int32_T i1{0}; i1 < loop_ub_tmp; i1++) { - result[5].f1[i1 + result[5].f1.size(0) * i] = b_result.f6[i1 + - b_result.f6.size(0) * i]; - } - } - + reflectivityCalculation(problemStruct, problemCells, controls, + contrastParams, result); if (!coder::internal::d_strcmp(controls->display.data, controls->display.size)) { - printf("Final chi squared is %g\n", problem->calculations.sumChi); + printf("Final chi squared is %g\n", contrastParams->calculations.sumChi); fflush(stdout); } } diff --git a/RAT/runDE.h b/RAT/runDE.h index e1366278..5fa529ba 100644 --- a/RAT/runDE.h +++ b/RAT/runDE.h @@ -20,30 +20,31 @@ // Type Declarations namespace RAT { - struct k_struct_T; - struct cell_14; - struct struct_T; + struct c_struct_T; + struct l_struct_T; + struct cell_11; + struct d_struct_T; } // Function Declarations namespace RAT { - k_struct_T intrafun(const ::coder::array &p, struct5_T *problemDef, - const char_T controls_parallel_data[], const int32_T - controls_parallel_size[2], const real_T + l_struct_T intrafun(const ::coder::array &p, c_struct_T + *problemStruct, const char_T controls_parallel_data[], + const int32_T controls_parallel_size[2], const real_T controls_resamPars[2], boolean_T controls_calcSldDuringFit, const struct3_T *controls_checks, const ::coder::array< - cell_wrap_2, 2U> &problemDefCells_f1, const ::coder::array< - cell_wrap_8, 2U> &problemDefCells_f2, const ::coder::array< - cell_wrap_2, 2U> &problemDefCells_f3, const ::coder::array< - cell_wrap_2, 2U> &problemDefCells_f4, const ::coder::array< - cell_wrap_8, 2U> &problemDefCells_f5, const ::coder::array< - cell_wrap_8, 1U> &problemDefCells_f6, const ::coder::array< - cell_wrap_1, 2U> &problemDefCells_f14, const ::coder:: - array &problemDefCells_f19); - void runDE(struct5_T *problemDef, const cell_14 *problemDefCells, const - struct1_T *problemDefLimits, const struct2_T *controls, struct_T - *problem, cell_wrap_9 result[6]); + cell_wrap_2, 2U> &problemCells_f1, const ::coder::array< + cell_wrap_8, 2U> &problemCells_f2, const ::coder::array< + cell_wrap_2, 2U> &problemCells_f3, const ::coder::array< + cell_wrap_2, 2U> &problemCells_f4, const ::coder::array< + cell_wrap_8, 2U> &problemCells_f5, const ::coder::array< + cell_wrap_8, 1U> &problemCells_f6, const ::coder::array< + cell_wrap_1, 2U> &problemCells_f14, const ::coder::array< + cell_wrap_8, 2U> &problemCells_f19); + void runDE(c_struct_T *problemStruct, const cell_11 *problemCells, const + struct1_T *problemLimits, const struct2_T *controls, d_struct_T + *contrastParams, cell_wrap_9 result[6]); } #endif diff --git a/RAT/runDREAM.cpp b/RAT/runDREAM.cpp index c499dc3e..2ba2514d 100644 --- a/RAT/runDREAM.cpp +++ b/RAT/runDREAM.cpp @@ -29,10 +29,10 @@ // Function Definitions namespace RAT { - void runDREAM(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct1_T *problemDefLimits, const struct2_T *controls, - const struct4_T *priors, struct5_T *outProblemDef, struct_T - *outProblem, cell_wrap_9 result[6], d_struct_T *bayesResults) + void runDREAM(const c_struct_T *problemStruct, const cell_11 *problemCells, + const struct1_T *problemLimits, const struct2_T *controls, const + struct4_T *priors, c_struct_T *outProblemStruct, d_struct_T + *contrastParams, cell_wrap_9 result[6], g_struct_T *bayesResults) { ::coder::array fitParamNames; ::coder::array Par_info_max; @@ -41,12 +41,10 @@ namespace RAT ::coder::array b_bayesResults; ::coder::array c_bayesResults; ::coder::array r; - cell_13 b_result; + c_struct_T b_problemStruct; e_struct_T dreamResults_bestFitsMean; f_struct_T dreamResults_predlims; - struct5_T b_problemDef; int32_T b_loop_ub; - int32_T c_result; int32_T i; int32_T i1; int32_T i2; @@ -54,27 +52,26 @@ namespace RAT // Make an empty struct for bayesResults to hold the outputs of the // calculation - makeEmptyBayesResultsStruct(problemDef->numberOfContrasts, coder::internal:: - b_strcmp(problemDef->TF.data, problemDef->TF.size), controls->nChains, - bayesResults->bestFitsMean.ref, bayesResults->bestFitsMean.sld, - &bayesResults->bestFitsMean.chi, bayesResults->bestFitsMean.data, - bayesResults->predlims.refPredInts, bayesResults->predlims.sldPredInts, - bayesResults->predlims.refXdata, bayesResults->predlims.sldXdata, - bayesResults->predlims.sampleChi.data, + makeEmptyBayesResultsStruct(problemStruct->numberOfContrasts, coder:: + internal::b_strcmp(problemStruct->TF.data, problemStruct->TF.size), + controls->nChains, bayesResults->bestFitsMean.ref, + bayesResults->bestFitsMean.sld, &bayesResults->bestFitsMean.chi, + bayesResults->bestFitsMean.data, bayesResults->predlims.refPredInts, + bayesResults->predlims.sldPredInts, bayesResults->predlims.refXdata, + bayesResults->predlims.sldXdata, bayesResults->predlims.sampleChi.data, &bayesResults->predlims.sampleChi.size[0], bayesResults->parConfInts.par95, bayesResults->parConfInts.par65, bayesResults->parConfInts.mean, bayesResults->bestPars, &bayesResults->bayesRes, bayesResults->chain); // Pre-allocation - b_problemDef = *problemDef; - packParams(&b_problemDef, problemDefCells->f7, problemDefCells->f8, - problemDefCells->f9, problemDefCells->f10, problemDefCells->f11, - problemDefCells->f12, problemDefCells->f13, problemDefCells->f20, - problemDefLimits, &controls->checks, fitParamNames); + b_problemStruct = *problemStruct; + packParams(&b_problemStruct, problemCells->f7, problemCells->f8, + problemCells->f9, problemCells->f10, problemCells->f11, + problemCells->f12, problemCells->f13, problemCells->f20, + problemLimits, &controls->checks, fitParamNames); // Get the priors for the fitted parameters... // Put all the RAT parameters together into one array... - // // Get the parameters from the user // Total number of generations // Number of chains @@ -87,16 +84,17 @@ namespace RAT // Jump probabilities... // This will change... // Initial sampling and parameter range - Par_info_min.set_size(1, b_problemDef.fitLimits.size(0)); - loop_ub = b_problemDef.fitLimits.size(0); + Par_info_min.set_size(1, b_problemStruct.fitLimits.size(0)); + loop_ub = b_problemStruct.fitLimits.size(0); for (i = 0; i < loop_ub; i++) { - Par_info_min[i] = b_problemDef.fitLimits[i]; + Par_info_min[i] = b_problemStruct.fitLimits[i]; } - Par_info_max.set_size(1, b_problemDef.fitLimits.size(0)); - loop_ub = b_problemDef.fitLimits.size(0); + Par_info_max.set_size(1, b_problemStruct.fitLimits.size(0)); + loop_ub = b_problemStruct.fitLimits.size(0); for (i = 0; i < loop_ub; i++) { - Par_info_max[i] = b_problemDef.fitLimits[i + b_problemDef.fitLimits.size(0)]; + Par_info_max[i] = b_problemStruct.fitLimits[i + + b_problemStruct.fitLimits.size(0)]; } // if dreamC.prior @@ -105,12 +103,12 @@ namespace RAT // [chain,output,fx] = rat_DREAM(DREAMPar,Par_info,[],ratInputs); // Func_name = @DREAMWrapper; getFittedPriors(fitParamNames, priors->priorNames, priors->priorValues, - b_problemDef.fitLimits, r); + b_problemStruct.fitLimits, r); ratDREAM(static_cast(fitParamNames.size(0)), controls->nChains, std:: ceil(controls->nSamples / controls->nChains), controls->jumpProbability, controls->pUnitGamma, controls->adaptPCR, Par_info_min, Par_info_max, controls->boundHandling.data, - controls->boundHandling.size, &b_problemDef, problemDefCells, + controls->boundHandling.size, &b_problemStruct, problemCells, controls, r, bayesResults->bayesRes.allChains, &bayesResults->bayesRes.dreamOutput, a__1); @@ -137,6 +135,7 @@ namespace RAT } for (int32_T b_i{0}; b_i < i; b_i++) { + int32_T b_result; int32_T c_loop_ub; int32_T sizes_idx_0; boolean_T empty_non_axis_sizes; @@ -145,17 +144,17 @@ namespace RAT // Combine the parallel chains into one.... if ((bayesResults->chain.size(0) != 0) && (bayesResults->chain.size(1) != 0)) { - c_result = bayesResults->chain.size(1); + b_result = bayesResults->chain.size(1); } else if ((i2 - i1 != 0) && (b_loop_ub != 0)) { - c_result = b_loop_ub; + b_result = b_loop_ub; } else { - c_result = bayesResults->chain.size(1); + b_result = bayesResults->chain.size(1); if (b_loop_ub > bayesResults->chain.size(1)) { - c_result = b_loop_ub; + b_result = b_loop_ub; } } - empty_non_axis_sizes = (c_result == 0); + empty_non_axis_sizes = (b_result == 0); if (empty_non_axis_sizes || ((bayesResults->chain.size(0) != 0) && (bayesResults->chain.size(1) != 0))) { loop_ub = bayesResults->chain.size(0); @@ -181,15 +180,15 @@ namespace RAT } } - c_bayesResults.set_size(loop_ub + sizes_idx_0, c_result); - for (int32_T i3{0}; i3 < c_result; i3++) { + c_bayesResults.set_size(loop_ub + sizes_idx_0, b_result); + for (int32_T i3{0}; i3 < b_result; i3++) { for (int32_T i4{0}; i4 < loop_ub; i4++) { c_bayesResults[i4 + c_bayesResults.size(0) * i3] = bayesResults-> chain[i4 + loop_ub * i3]; } } - for (int32_T i3{0}; i3 < c_result; i3++) { + for (int32_T i3{0}; i3 < b_result; i3++) { for (int32_T i4{0}; i4 < sizes_idx_0; i4++) { c_bayesResults[(i4 + loop_ub) + c_bayesResults.size(0) * i3] = b_bayesResults[i4 + sizes_idx_0 * i3]; @@ -208,101 +207,50 @@ namespace RAT } coder::mean(bayesResults->chain, bayesResults->bestPars); - processBayes(bayesResults->bestPars, bayesResults->chain, &b_problemDef, - controls, problemDefCells, outProblemDef, outProblem, &b_result, - &dreamResults_bestFitsMean, &dreamResults_predlims, + processBayes(bayesResults->bestPars, bayesResults->chain, &b_problemStruct, + controls, problemCells, outProblemStruct, contrastParams, + result, &dreamResults_bestFitsMean, &dreamResults_predlims, &bayesResults->parConfInts); - result[0].f1.set_size(b_result.f1.size(0), 1); - c_result = b_result.f1.size(0); - for (i = 0; i < c_result; i++) { - loop_ub = b_result.f1[i].f1.size(0); - result[0].f1[i].f1.set_size(b_result.f1[i].f1.size(0), 2); - for (i1 = 0; i1 < 2; i1++) { - for (i2 = 0; i2 < loop_ub; i2++) { - result[0].f1[i].f1[i2 + result[0].f1[i].f1.size(0) * i1] = - b_result.f1[i].f1[i2 + b_result.f1[i].f1.size(0) * i1]; - } - } - } - - result[1].f1.set_size(b_result.f2.size(0), 1); - c_result = b_result.f2.size(0); - for (i = 0; i < c_result; i++) { - loop_ub = b_result.f2[i].f1.size(0); - result[1].f1[i].f1.set_size(b_result.f2[i].f1.size(0), 2); - for (i1 = 0; i1 < 2; i1++) { - for (i2 = 0; i2 < loop_ub; i2++) { - result[1].f1[i].f1[i2 + result[1].f1[i].f1.size(0) * i1] = - b_result.f2[i].f1[i2 + b_result.f2[i].f1.size(0) * i1]; - } - } - } - - result[2].f1.set_size(b_result.f3.size(0), 1); - c_result = b_result.f3.size(0); - for (i = 0; i < c_result; i++) { - loop_ub = b_result.f3[i].f1.size(0); - result[2].f1[i].f1.set_size(b_result.f3[i].f1.size(0), 3); - for (i1 = 0; i1 < 3; i1++) { - for (i2 = 0; i2 < loop_ub; i2++) { - result[2].f1[i].f1[i2 + result[2].f1[i].f1.size(0) * i1] = - b_result.f3[i].f1[i2 + b_result.f3[i].f1.size(0) * i1]; - } - } - } - - result[3].f1.set_size(b_result.f4.size(0), b_result.f4.size(1)); - loop_ub = b_result.f4.size(1); - for (i = 0; i < loop_ub; i++) { - b_loop_ub = b_result.f4.size(0); - for (i1 = 0; i1 < b_loop_ub; i1++) { - result[3].f1[i1 + result[3].f1.size(0) * i] = b_result.f4[i1 + - b_result.f4.size(0) * i]; - } - } - - result[4].f1.set_size(b_result.f5.size(0), b_result.f5.size(1)); - loop_ub = b_result.f5.size(1); - for (i = 0; i < loop_ub; i++) { - b_loop_ub = b_result.f5.size(0); - for (i1 = 0; i1 < b_loop_ub; i1++) { - result[4].f1[i1 + result[4].f1.size(0) * i] = b_result.f5[i1 + - b_result.f5.size(0) * i]; - } - } - - result[5].f1.set_size(b_result.f6.size(0), b_result.f6.size(1)); - loop_ub = b_result.f6.size(1); - for (i = 0; i < loop_ub; i++) { - b_loop_ub = b_result.f6.size(0); - for (i1 = 0; i1 < b_loop_ub; i1++) { - result[5].f1[i1 + result[5].f1.size(0) * i] = b_result.f6[i1 + - b_result.f6.size(0) * i]; - } - } // Populate the output struct // bayesResults.bayesRes.allChains = chain; cast(dreamResults_predlims.refPredInts, bayesResults->predlims.refPredInts); cast(dreamResults_predlims.sldPredInts, bayesResults->predlims.sldPredInts); - cast(dreamResults_predlims.refXdata, bayesResults->predlims.refXdata); - bayesResults->predlims.sldXdata.set_size(dreamResults_predlims.sldXdata.size - (0), 1); - for (i = 0; i < dreamResults_predlims.sldXdata.size(0); i++) { - bayesResults->predlims.sldXdata[i].f1.set_size(1, - dreamResults_predlims.sldXdata[i].f1.size(1)); - loop_ub = dreamResults_predlims.sldXdata[i].f1.size(1); + bayesResults->predlims.refXdata.set_size(dreamResults_predlims.refXdata.size + (0)); + for (i = 0; i < dreamResults_predlims.refXdata.size(0); i++) { + bayesResults->predlims.refXdata[i].f1.set_size(1, + dreamResults_predlims.refXdata[i].f1.size(1)); + loop_ub = dreamResults_predlims.refXdata[i].f1.size(1); for (i1 = 0; i1 < loop_ub; i1++) { - bayesResults->predlims.sldXdata[i].f1[bayesResults->predlims.sldXdata[i] - .f1.size(0) * i1] = dreamResults_predlims.sldXdata[i].f1[i1]; + bayesResults->predlims.refXdata[i].f1[bayesResults->predlims.refXdata[i] + .f1.size(0) * i1] = dreamResults_predlims.refXdata[i].f1[i1]; } } + cast(dreamResults_predlims.sldXdata, bayesResults->predlims.sldXdata); bayesResults->predlims.sampleChi.size[0] = 1000; std::copy(&dreamResults_predlims.sampleChi[0], &dreamResults_predlims.sampleChi[1000], &bayesResults->predlims.sampleChi.data[0]); - cast(dreamResults_bestFitsMean.ref, bayesResults->bestFitsMean.ref); + bayesResults->bestFitsMean.ref.set_size(dreamResults_bestFitsMean.ref.size(0)); + for (i = 0; i < dreamResults_bestFitsMean.ref.size(0) * + dreamResults_bestFitsMean.ref.size(1); i++) { + bayesResults->bestFitsMean.ref[i].f1.set_size + (dreamResults_bestFitsMean.ref[i].f1.size(0), + dreamResults_bestFitsMean.ref[i].f1.size(1)); + loop_ub = dreamResults_bestFitsMean.ref[i].f1.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = dreamResults_bestFitsMean.ref[i].f1.size(0); + for (i2 = 0; i2 < b_loop_ub; i2++) { + bayesResults->bestFitsMean.ref[i].f1[i2 + + bayesResults->bestFitsMean.ref[i].f1.size(0) * i1] = + dreamResults_bestFitsMean.ref[i].f1[i2 + + dreamResults_bestFitsMean.ref[i].f1.size(0) * i1]; + } + } + } + bayesResults->bestFitsMean.sld.set_size(dreamResults_bestFitsMean.sld.size(0), dreamResults_bestFitsMean.sld.size(1)); loop_ub = dreamResults_bestFitsMean.sld.size(1); @@ -316,7 +264,24 @@ namespace RAT } bayesResults->bestFitsMean.chi = dreamResults_bestFitsMean.chi; - cast(dreamResults_bestFitsMean.data, bayesResults->bestFitsMean.data); + bayesResults->bestFitsMean.data.set_size(dreamResults_bestFitsMean.data.size + (0)); + for (i = 0; i < dreamResults_bestFitsMean.data.size(0) * + dreamResults_bestFitsMean.data.size(1); i++) { + bayesResults->bestFitsMean.data[i].f1.set_size + (dreamResults_bestFitsMean.data[i].f1.size(0), + dreamResults_bestFitsMean.data[i].f1.size(1)); + loop_ub = dreamResults_bestFitsMean.data[i].f1.size(1); + for (i1 = 0; i1 < loop_ub; i1++) { + b_loop_ub = dreamResults_bestFitsMean.data[i].f1.size(0); + for (i2 = 0; i2 < b_loop_ub; i2++) { + bayesResults->bestFitsMean.data[i].f1[i2 + + bayesResults->bestFitsMean.data[i].f1.size(0) * i1] = + dreamResults_bestFitsMean.data[i].f1[i2 + + dreamResults_bestFitsMean.data[i].f1.size(0) * i1]; + } + } + } // These are not defined in makeEmptyBayesResultsStruct // bayesResults.bayesRes.DREAMPar = DREAMPar; diff --git a/RAT/runDREAM.h b/RAT/runDREAM.h index 997eab1b..603d72ba 100644 --- a/RAT/runDREAM.h +++ b/RAT/runDREAM.h @@ -18,23 +18,23 @@ // Type Declarations namespace RAT { - struct struct5_T; - struct cell_14; + struct c_struct_T; + struct cell_11; struct struct1_T; struct struct2_T; struct struct4_T; - struct struct_T; - struct cell_wrap_9; struct d_struct_T; + struct cell_wrap_9; + struct g_struct_T; } // Function Declarations namespace RAT { - void runDREAM(const struct5_T *problemDef, const cell_14 *problemDefCells, - const struct1_T *problemDefLimits, const struct2_T *controls, - const struct4_T *priors, struct5_T *outProblemDef, struct_T - *outProblem, cell_wrap_9 result[6], d_struct_T *bayesResults); + void runDREAM(const c_struct_T *problemStruct, const cell_11 *problemCells, + const struct1_T *problemLimits, const struct2_T *controls, const + struct4_T *priors, c_struct_T *outProblemStruct, d_struct_T + *contrastParams, cell_wrap_9 result[6], g_struct_T *bayesResults); } #endif diff --git a/RAT/runNestedSampler.cpp b/RAT/runNestedSampler.cpp index f46bd8d0..8db4c48e 100644 --- a/RAT/runNestedSampler.cpp +++ b/RAT/runNestedSampler.cpp @@ -29,19 +29,18 @@ // Function Definitions namespace RAT { - void runNestedSampler(struct5_T *problemDef, const cell_14 *problemDefCells, - const struct1_T *problemDefLimits, const struct2_T - *controls, const struct4_T *inPriors, struct_T - *outProblem, cell_wrap_9 result[6], struct8_T + void runNestedSampler(c_struct_T *problemStruct, const cell_11 *problemCells, + const struct1_T *problemLimits, const struct2_T + *controls, const struct4_T *inPriors, d_struct_T + *contrastParams, cell_wrap_9 result[6], struct7_T *bayesResults) { + static b_struct_T t8_bayesRes; ::coder::array fitNames; - ::coder::array expl_temp_sld; - ::coder::array expl_temp_data; - ::coder::array expl_temp_ref; - ::coder::array t9_predlims_refPredInts; - ::coder::array t9_predlims_refXdata; - ::coder::array t9_predlims_sldPredInts; + ::coder::array t8_bestFitsMean_sld; + ::coder::array t8_predlims_sldPredInts; + ::coder::array t8_predlims_sldXdata; + ::coder::array t8_predlims_refPredInts; ::coder::array b_expl_temp; ::coder::array bayesOutputs_chain; ::coder::array chain; @@ -51,83 +50,83 @@ namespace RAT ::coder::array expl_temp_par95; ::coder::array r; ::coder::array r1; - c_struct_T t9_bayesRes; - cell_13 b_result; + c_struct_T b_problemStruct; e_struct_T nestResults_bestFitsMean; f_struct_T nestResults_predlims; - struct5_T b_problemDef; - real_T t9_predlims_sampleChi_data[1000]; - real_T H; - real_T expl_temp_chi; + real_T t8_predlims_sampleChi_data[1000]; real_T logZ; + real_T t8_bestFitsMean_chi; int32_T b_loop_ub; int32_T loop_ub; - int32_T t9_predlims_sampleChi_size; - packParams(problemDef, problemDefCells->f7, problemDefCells->f8, - problemDefCells->f9, problemDefCells->f10, problemDefCells->f11, - problemDefCells->f12, problemDefCells->f13, problemDefCells->f20, - problemDefLimits, &controls->checks, fitNames); + int32_T t8_predlims_sampleChi_size; + packParams(problemStruct, problemCells->f7, problemCells->f8, + problemCells->f9, problemCells->f10, problemCells->f11, + problemCells->f12, problemCells->f13, problemCells->f20, + problemLimits, &controls->checks, fitNames); // Make an empty struct for bayesResults to hold the outputs of the // calculation - b_makeEmptyBayesResultsStruct(problemDef->numberOfContrasts, coder::internal:: - b_strcmp(problemDef->TF.data, problemDef->TF.size), expl_temp_ref, - expl_temp_sld, &expl_temp_chi, expl_temp_data, t9_predlims_refPredInts, - t9_predlims_sldPredInts, t9_predlims_refXdata, - bayesResults->predlims.sldXdata, t9_predlims_sampleChi_data, - &t9_predlims_sampleChi_size, expl_temp_par95, expl_temp_par65, - expl_temp_mean, expl_temp, &t9_bayesRes, b_expl_temp); - bayesResults->bayesRes.allChains.set_size(t9_bayesRes.allChains.size(0), - t9_bayesRes.allChains.size(1), t9_bayesRes.allChains.size(2)); - loop_ub = t9_bayesRes.allChains.size(2); - for (int32_T i{0}; i < loop_ub; i++) { - b_loop_ub = t9_bayesRes.allChains.size(1); - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - t9_predlims_sampleChi_size = t9_bayesRes.allChains.size(0); - for (int32_T i2{0}; i2 < t9_predlims_sampleChi_size; i2++) { + b_makeEmptyBayesResultsStruct(problemStruct->numberOfContrasts, coder:: + internal::b_strcmp(problemStruct->TF.data, problemStruct->TF.size), + bayesResults->bestFitsMean.ref, t8_bestFitsMean_sld, &t8_bestFitsMean_chi, + bayesResults->bestFitsMean.data, t8_predlims_refPredInts, + t8_predlims_sldPredInts, bayesResults->predlims.refXdata, + t8_predlims_sldXdata, t8_predlims_sampleChi_data, + &t8_predlims_sampleChi_size, expl_temp_par95, expl_temp_par65, + expl_temp_mean, expl_temp, &t8_bayesRes, b_expl_temp); + bayesResults->bayesRes.allChains.set_size(t8_bayesRes.allChains.size(0), + t8_bayesRes.allChains.size(1), t8_bayesRes.allChains.size(2)); + t8_predlims_sampleChi_size = t8_bayesRes.allChains.size(2); + for (int32_T i{0}; i < t8_predlims_sampleChi_size; i++) { + loop_ub = t8_bayesRes.allChains.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = t8_bayesRes.allChains.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { bayesResults->bayesRes.allChains[(i2 + bayesResults->bayesRes.allChains.size(0) * i1) + bayesResults->bayesRes.allChains.size(0) * bayesResults->bayesRes.allChains.size(1) * i] = - t9_bayesRes.allChains[(i2 + t9_bayesRes.allChains.size(0) * i1) + - t9_bayesRes.allChains.size(0) * t9_bayesRes.allChains.size(1) * i]; + t8_bayesRes.allChains[(i2 + t8_bayesRes.allChains.size(0) * i1) + + t8_bayesRes.allChains.size(0) * t8_bayesRes.allChains.size(1) * i]; } } } - bayesResults->bayesRes.dreamOutput = t9_bayesRes.dreamOutput; + bayesResults->bayesRes.dreamOutput = t8_bayesRes.dreamOutput; // Deal with priors. // Tuning Parameters getFittedPriors(fitNames, inPriors->priorNames, inPriors->priorValues, - problemDef->fitLimits, r); - nestedSampler(problemDef, controls, problemDefCells, controls->Nlive, + problemStruct->fitLimits, r); + nestedSampler(problemStruct, controls, problemCells, controls->Nlive, controls->Nmcmc, controls->nsTolerance, r, &logZ, bayesResults->bayesRes.nestOutput.nestSamples, - bayesResults->bayesRes.nestOutput.postSamples, &H); + bayesResults->bayesRes.nestOutput.postSamples, + &t8_bestFitsMean_chi); // Process the results... // chain = nest_samples(:,1:end-1); if (fitNames.size(0) < 1) { - loop_ub = 0; + t8_predlims_sampleChi_size = 0; } else { - loop_ub = fitNames.size(0); + t8_predlims_sampleChi_size = fitNames.size(0); } chain.set_size(bayesResults->bayesRes.nestOutput.postSamples.size(0), - loop_ub); + t8_predlims_sampleChi_size); bayesOutputs_chain.set_size - (bayesResults->bayesRes.nestOutput.postSamples.size(0), loop_ub); - for (int32_T i{0}; i < loop_ub; i++) { - b_loop_ub = bayesResults->bayesRes.nestOutput.postSamples.size(0); - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + (bayesResults->bayesRes.nestOutput.postSamples.size(0), + t8_predlims_sampleChi_size); + for (int32_T i{0}; i < t8_predlims_sampleChi_size; i++) { + loop_ub = bayesResults->bayesRes.nestOutput.postSamples.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { chain[i1 + chain.size(0) * i] = bayesResults->bayesRes.nestOutput.postSamples[i1 + bayesResults->bayesRes.nestOutput.postSamples.size(0) * i]; } - b_loop_ub = bayesResults->bayesRes.nestOutput.postSamples.size(0); - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + loop_ub = bayesResults->bayesRes.nestOutput.postSamples.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { bayesOutputs_chain[i1 + bayesOutputs_chain.size(0) * i] = bayesResults->bayesRes.nestOutput.postSamples[i1 + bayesResults->bayesRes.nestOutput.postSamples.size(0) * i]; @@ -136,108 +135,56 @@ namespace RAT int32_T iv[2]; coder::mean(chain, r1); - b_problemDef = *problemDef; + b_problemStruct = *problemStruct; iv[0] = (*(int32_T (*)[2])r1.size())[0]; iv[1] = (*(int32_T (*)[2])r1.size())[1]; processBayes((const real_T *)r1.data(), iv, bayesOutputs_chain, - &b_problemDef, controls, problemDefCells, problemDef, - outProblem, &b_result, &nestResults_bestFitsMean, + &b_problemStruct, controls, problemCells, problemStruct, + contrastParams, result, &nestResults_bestFitsMean, &nestResults_predlims, &bayesResults->parConfInts); - result[0].f1.set_size(b_result.f1.size(0), 1); - t9_predlims_sampleChi_size = b_result.f1.size(0); - for (int32_T i{0}; i < t9_predlims_sampleChi_size; i++) { - b_loop_ub = b_result.f1[i].f1.size(0); - result[0].f1[i].f1.set_size(b_result.f1[i].f1.size(0), 2); - for (int32_T i1{0}; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - result[0].f1[i].f1[i2 + result[0].f1[i].f1.size(0) * i1] = - b_result.f1[i].f1[i2 + b_result.f1[i].f1.size(0) * i1]; - } - } - } - - result[1].f1.set_size(b_result.f2.size(0), 1); - t9_predlims_sampleChi_size = b_result.f2.size(0); - for (int32_T i{0}; i < t9_predlims_sampleChi_size; i++) { - b_loop_ub = b_result.f2[i].f1.size(0); - result[1].f1[i].f1.set_size(b_result.f2[i].f1.size(0), 2); - for (int32_T i1{0}; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - result[1].f1[i].f1[i2 + result[1].f1[i].f1.size(0) * i1] = - b_result.f2[i].f1[i2 + b_result.f2[i].f1.size(0) * i1]; - } - } - } - - result[2].f1.set_size(b_result.f3.size(0), 1); - t9_predlims_sampleChi_size = b_result.f3.size(0); - for (int32_T i{0}; i < t9_predlims_sampleChi_size; i++) { - b_loop_ub = b_result.f3[i].f1.size(0); - result[2].f1[i].f1.set_size(b_result.f3[i].f1.size(0), 3); - for (int32_T i1{0}; i1 < 3; i1++) { - for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - result[2].f1[i].f1[i2 + result[2].f1[i].f1.size(0) * i1] = - b_result.f3[i].f1[i2 + b_result.f3[i].f1.size(0) * i1]; - } - } - } - - result[3].f1.set_size(b_result.f4.size(0), b_result.f4.size(1)); - b_loop_ub = b_result.f4.size(1); - for (int32_T i{0}; i < b_loop_ub; i++) { - t9_predlims_sampleChi_size = b_result.f4.size(0); - for (int32_T i1{0}; i1 < t9_predlims_sampleChi_size; i1++) { - result[3].f1[i1 + result[3].f1.size(0) * i] = b_result.f4[i1 + - b_result.f4.size(0) * i]; - } - } - - result[4].f1.set_size(b_result.f5.size(0), b_result.f5.size(1)); - b_loop_ub = b_result.f5.size(1); - for (int32_T i{0}; i < b_loop_ub; i++) { - t9_predlims_sampleChi_size = b_result.f5.size(0); - for (int32_T i1{0}; i1 < t9_predlims_sampleChi_size; i1++) { - result[4].f1[i1 + result[4].f1.size(0) * i] = b_result.f5[i1 + - b_result.f5.size(0) * i]; - } - } - - result[5].f1.set_size(b_result.f6.size(0), b_result.f6.size(1)); - b_loop_ub = b_result.f6.size(1); - for (int32_T i{0}; i < b_loop_ub; i++) { - t9_predlims_sampleChi_size = b_result.f6.size(0); - for (int32_T i1{0}; i1 < t9_predlims_sampleChi_size; i1++) { - result[5].f1[i1 + result[5].f1.size(0) * i] = b_result.f6[i1 + - b_result.f6.size(0) * i]; - } - } - cast(nestResults_predlims.refPredInts, bayesResults->predlims.refPredInts); cast(nestResults_predlims.sldPredInts, bayesResults->predlims.sldPredInts); - cast(nestResults_predlims.refXdata, bayesResults->predlims.refXdata); - bayesResults->predlims.sldXdata.set_size(nestResults_predlims.sldXdata.size - (0), 1); - for (int32_T i{0}; i < nestResults_predlims.sldXdata.size(0); i++) { - bayesResults->predlims.sldXdata[i].f1.set_size(1, - nestResults_predlims.sldXdata[i].f1.size(1)); - b_loop_ub = nestResults_predlims.sldXdata[i].f1.size(1); - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { - bayesResults->predlims.sldXdata[i].f1[bayesResults->predlims.sldXdata[i] - .f1.size(0) * i1] = nestResults_predlims.sldXdata[i].f1[i1]; + bayesResults->predlims.refXdata.set_size(nestResults_predlims.refXdata.size + (0)); + for (int32_T i{0}; i < nestResults_predlims.refXdata.size(0); i++) { + bayesResults->predlims.refXdata[i].f1.set_size(1, + nestResults_predlims.refXdata[i].f1.size(1)); + loop_ub = nestResults_predlims.refXdata[i].f1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + bayesResults->predlims.refXdata[i].f1[bayesResults->predlims.refXdata[i] + .f1.size(0) * i1] = nestResults_predlims.refXdata[i].f1[i1]; } } + cast(nestResults_predlims.sldXdata, bayesResults->predlims.sldXdata); bayesResults->predlims.sampleChi.size[0] = 1000; std::copy(&nestResults_predlims.sampleChi[0], &nestResults_predlims.sampleChi[1000], &bayesResults->predlims.sampleChi.data[0]); - cast(nestResults_bestFitsMean.ref, bayesResults->bestFitsMean.ref); + bayesResults->bestFitsMean.ref.set_size(nestResults_bestFitsMean.ref.size(0)); + for (int32_T i{0}; i < nestResults_bestFitsMean.ref.size(0) * + nestResults_bestFitsMean.ref.size(1); i++) { + bayesResults->bestFitsMean.ref[i].f1.set_size + (nestResults_bestFitsMean.ref[i].f1.size(0), + nestResults_bestFitsMean.ref[i].f1.size(1)); + loop_ub = nestResults_bestFitsMean.ref[i].f1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = nestResults_bestFitsMean.ref[i].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + bayesResults->bestFitsMean.ref[i].f1[i2 + + bayesResults->bestFitsMean.ref[i].f1.size(0) * i1] = + nestResults_bestFitsMean.ref[i].f1[i2 + + nestResults_bestFitsMean.ref[i].f1.size(0) * i1]; + } + } + } + bayesResults->bestFitsMean.sld.set_size(nestResults_bestFitsMean.sld.size(0), nestResults_bestFitsMean.sld.size(1)); - b_loop_ub = nestResults_bestFitsMean.sld.size(1); - for (int32_T i{0}; i < b_loop_ub; i++) { - t9_predlims_sampleChi_size = nestResults_bestFitsMean.sld.size(0); - for (int32_T i1{0}; i1 < t9_predlims_sampleChi_size; i1++) { + loop_ub = nestResults_bestFitsMean.sld.size(1); + for (int32_T i{0}; i < loop_ub; i++) { + b_loop_ub = nestResults_bestFitsMean.sld.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { bayesResults->bestFitsMean.sld[i1 + bayesResults->bestFitsMean.sld.size (0) * i] = nestResults_bestFitsMean.sld[i1 + nestResults_bestFitsMean.sld.size(0) * i]; @@ -245,21 +192,40 @@ namespace RAT } bayesResults->bestFitsMean.chi = nestResults_bestFitsMean.chi; - cast(nestResults_bestFitsMean.data, bayesResults->bestFitsMean.data); + bayesResults->bestFitsMean.data.set_size(nestResults_bestFitsMean.data.size + (0)); + for (int32_T i{0}; i < nestResults_bestFitsMean.data.size(0) * + nestResults_bestFitsMean.data.size(1); i++) { + bayesResults->bestFitsMean.data[i].f1.set_size + (nestResults_bestFitsMean.data[i].f1.size(0), + nestResults_bestFitsMean.data[i].f1.size(1)); + loop_ub = nestResults_bestFitsMean.data[i].f1.size(1); + for (int32_T i1{0}; i1 < loop_ub; i1++) { + b_loop_ub = nestResults_bestFitsMean.data[i].f1.size(0); + for (int32_T i2{0}; i2 < b_loop_ub; i2++) { + bayesResults->bestFitsMean.data[i].f1[i2 + + bayesResults->bestFitsMean.data[i].f1.size(0) * i1] = + nestResults_bestFitsMean.data[i].f1[i2 + + nestResults_bestFitsMean.data[i].f1.size(0) * i1]; + } + } + } + coder::blockedSummation(chain, bayesResults->bayesRes.nestOutput.postSamples.size(0), r1); bayesResults->bestPars.set_size(1, r1.size(1)); - b_loop_ub = r1.size(1); - for (int32_T i{0}; i < b_loop_ub; i++) { + loop_ub = r1.size(1); + for (int32_T i{0}; i < loop_ub; i++) { bayesResults->bestPars[i] = r1[i] / static_cast (bayesResults->bayesRes.nestOutput.postSamples.size(0)); } bayesResults->chain.set_size - (bayesResults->bayesRes.nestOutput.postSamples.size(0), loop_ub); - for (int32_T i{0}; i < loop_ub; i++) { - b_loop_ub = bayesResults->bayesRes.nestOutput.postSamples.size(0); - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + (bayesResults->bayesRes.nestOutput.postSamples.size(0), + t8_predlims_sampleChi_size); + for (int32_T i{0}; i < t8_predlims_sampleChi_size; i++) { + loop_ub = bayesResults->bayesRes.nestOutput.postSamples.size(0); + for (int32_T i1{0}; i1 < loop_ub; i1++) { bayesResults->chain[i1 + bayesResults->chain.size(0) * i] = bayesResults->bayesRes.nestOutput.postSamples[i1 + bayesResults->bayesRes.nestOutput.postSamples.size(0) * i]; diff --git a/RAT/runNestedSampler.h b/RAT/runNestedSampler.h index 245a3fc5..653ac381 100644 --- a/RAT/runNestedSampler.h +++ b/RAT/runNestedSampler.h @@ -18,23 +18,23 @@ // Type Declarations namespace RAT { - struct struct5_T; - struct cell_14; + struct c_struct_T; + struct cell_11; struct struct1_T; struct struct2_T; struct struct4_T; - struct struct_T; + struct d_struct_T; struct cell_wrap_9; - struct struct8_T; + struct struct7_T; } // Function Declarations namespace RAT { - void runNestedSampler(struct5_T *problemDef, const cell_14 *problemDefCells, - const struct1_T *problemDefLimits, const struct2_T - *controls, const struct4_T *inPriors, struct_T - *outProblem, cell_wrap_9 result[6], struct8_T + void runNestedSampler(c_struct_T *problemStruct, const cell_11 *problemCells, + const struct1_T *problemLimits, const struct2_T + *controls, const struct4_T *inPriors, d_struct_T + *contrastParams, cell_wrap_9 result[6], struct7_T *bayesResults); } diff --git a/RAT/runSimplex.cpp b/RAT/runSimplex.cpp index 15979c21..8caae4c0 100644 --- a/RAT/runSimplex.cpp +++ b/RAT/runSimplex.cpp @@ -26,37 +26,29 @@ // Function Definitions namespace RAT { - void runSimplex(struct5_T *problemDef, const cell_14 *problemDefCells, const - struct1_T *problemDefLimits, const struct2_T *controls, - struct_T *problem, cell_wrap_9 result[6]) + void runSimplex(c_struct_T *problemStruct, const cell_11 *problemCells, const + struct1_T *problemLimits, const struct2_T *controls, + d_struct_T *contrastParams, cell_wrap_9 result[6]) { static const char_T b_cv1[6]{ 'n', 'o', 't', 'i', 'f', 'y' }; static const char_T b_cv[5]{ 'f', 'i', 'n', 'a', 'l' }; - ::coder::array b_problemDef; + ::coder::array b_problemStruct; ::coder::array x; ::coder::array x0u; - cell_13 b_result; - h_struct_T a__4; - j_struct_T expl_temp; + i_struct_T a__4; + k_struct_T expl_temp; real_T a__2; real_T a__3; int32_T dis_size[2]; int32_T i; - int32_T loop_ub; int32_T outsize_idx_0; char_T dis_data[6]; - packParams(problemDef, problemDefCells->f7, problemDefCells->f8, - problemDefCells->f9, problemDefCells->f10, problemDefCells->f11, - problemDefCells->f12, problemDefCells->f13, problemDefCells->f20, - problemDefLimits, &controls->checks, b_problemDef); - - // Check the bounds on all the selected - // out = checkBounds(problemDef,controls); - // if strcmp(out{1},'fail') - // return - // end + packParams(problemStruct, problemCells->f7, problemCells->f8, + problemCells->f9, problemCells->f10, problemCells->f11, + problemCells->f12, problemCells->f13, problemCells->f20, + problemLimits, &controls->checks, b_problemStruct); if (coder::internal::r_strcmp(controls->display.data, controls->display.size)) { outsize_idx_0 = 0; @@ -117,31 +109,32 @@ namespace RAT break; } - expl_temp.LB.set_size(problemDef->fitLimits.size(0)); - loop_ub = problemDef->fitLimits.size(0); - for (i = 0; i < loop_ub; i++) { - expl_temp.LB[i] = problemDef->fitLimits[i]; + expl_temp.LB.set_size(problemStruct->fitLimits.size(0)); + outsize_idx_0 = problemStruct->fitLimits.size(0); + for (i = 0; i < outsize_idx_0; i++) { + expl_temp.LB[i] = problemStruct->fitLimits[i]; } - expl_temp.UB.set_size(problemDef->fitLimits.size(0)); - loop_ub = problemDef->fitLimits.size(0); - for (i = 0; i < loop_ub; i++) { - expl_temp.UB[i] = problemDef->fitLimits[i + problemDef->fitLimits.size(0)]; + expl_temp.UB.set_size(problemStruct->fitLimits.size(0)); + outsize_idx_0 = problemStruct->fitLimits.size(0); + for (i = 0; i < outsize_idx_0; i++) { + expl_temp.UB[i] = problemStruct->fitLimits[i + + problemStruct->fitLimits.size(0)]; } // size checks - if (problemDef->fitLimits.size(0) == 0) { - outsize_idx_0 = problemDef->fitParams.size(0) * problemDef->fitParams.size - (1); + if (problemStruct->fitLimits.size(0) == 0) { + outsize_idx_0 = problemStruct->fitParams.size(0) * + problemStruct->fitParams.size(1); expl_temp.LB.set_size(outsize_idx_0); for (i = 0; i < outsize_idx_0; i++) { expl_temp.LB[i] = rtMinusInf; } } - if (problemDef->fitLimits.size(0) == 0) { - outsize_idx_0 = problemDef->fitParams.size(0) * problemDef->fitParams.size - (1); + if (problemStruct->fitLimits.size(0) == 0) { + outsize_idx_0 = problemStruct->fitParams.size(0) * + problemStruct->fitParams.size(1); expl_temp.UB.set_size(outsize_idx_0); for (i = 0; i < outsize_idx_0; i++) { expl_temp.UB[i] = rtInf; @@ -150,18 +143,19 @@ namespace RAT // stuff into a struct to pass around // varargin; - // problemDef.modelFilename;%fun; + // problemStruct.modelFilename;%fun; // 0 --> unconstrained variable // 1 --> lower bound only // 2 --> upper bound only // 3 --> dual finite bounds - outsize_idx_0 = problemDef->fitParams.size(0) * problemDef->fitParams.size(1); + outsize_idx_0 = problemStruct->fitParams.size(0) * + problemStruct->fitParams.size(1); expl_temp.BoundClass.set_size(outsize_idx_0); for (i = 0; i < outsize_idx_0; i++) { expl_temp.BoundClass[i] = 0.0; } - i = problemDef->fitParams.size(0) * problemDef->fitParams.size(1); + i = problemStruct->fitParams.size(0) * problemStruct->fitParams.size(1); for (int32_T b_i{0}; b_i < i; b_i++) { expl_temp.BoundClass[b_i] = static_cast((!std::isinf (expl_temp.LB[b_i])) && (!std::isnan(expl_temp.LB[b_i]))) + static_cast< @@ -171,47 +165,48 @@ namespace RAT // transform starting values into their unconstrained // surrogates. Check for infeasible starting guesses. - outsize_idx_0 = problemDef->fitParams.size(0) * problemDef->fitParams.size(1); + outsize_idx_0 = problemStruct->fitParams.size(0) * + problemStruct->fitParams.size(1); x0u.set_size(outsize_idx_0); for (i = 0; i < outsize_idx_0; i++) { - x0u[i] = problemDef->fitParams[i]; + x0u[i] = problemStruct->fitParams[i]; } - i = problemDef->fitParams.size(0) * problemDef->fitParams.size(1); + i = problemStruct->fitParams.size(0) * problemStruct->fitParams.size(1); for (int32_T b_i{0}; b_i < i; b_i++) { switch (static_cast(expl_temp.BoundClass[b_i])) { case 1: // lower bound only - if (problemDef->fitParams[b_i] <= expl_temp.LB[b_i]) { + if (problemStruct->fitParams[b_i] <= expl_temp.LB[b_i]) { // infeasible starting value. Use bound. x0u[b_i] = 0.0; } else { - x0u[b_i] = std::sqrt(problemDef->fitParams[b_i] - expl_temp.LB[b_i]); + x0u[b_i] = std::sqrt(problemStruct->fitParams[b_i] - expl_temp.LB[b_i]); } break; case 2: // upper bound only - if (problemDef->fitParams[b_i] >= expl_temp.UB[b_i]) { + if (problemStruct->fitParams[b_i] >= expl_temp.UB[b_i]) { // infeasible starting value. use bound. x0u[b_i] = 0.0; } else { - x0u[b_i] = std::sqrt(expl_temp.UB[b_i] - problemDef->fitParams[b_i]); + x0u[b_i] = std::sqrt(expl_temp.UB[b_i] - problemStruct->fitParams[b_i]); } break; case 3: // lower and upper bounds - if (problemDef->fitParams[b_i] <= expl_temp.LB[b_i]) { + if (problemStruct->fitParams[b_i] <= expl_temp.LB[b_i]) { // infeasible starting value x0u[b_i] = -1.5707963267948966; - } else if (problemDef->fitParams[b_i] >= expl_temp.UB[b_i]) { + } else if (problemStruct->fitParams[b_i] >= expl_temp.UB[b_i]) { // infeasible starting value x0u[b_i] = 1.5707963267948966; } else { x0u[b_i] = std::asin(std::fmax(-1.0, std::fmin(1.0, 2.0 * - (problemDef->fitParams[b_i] - expl_temp.LB[b_i]) / (expl_temp.UB[b_i] - - expl_temp.LB[b_i]) - 1.0))); + (problemStruct->fitParams[b_i] - expl_temp.LB[b_i]) / + (expl_temp.UB[b_i] - expl_temp.LB[b_i]) - 1.0))); } break; @@ -224,100 +219,32 @@ namespace RAT // now we can call fminsearch, but with our own // intra-objective function. fMinSearch(x0u, controls->maxIter, controls->maxFunEvals, controls->tolX, - controls->tolFun, dis_data, dis_size, problemDef, - problemDefCells->f1, problemDefCells->f2, problemDefCells->f3, - problemDefCells->f4, problemDefCells->f5, problemDefCells->f6, - problemDefCells->f14, problemDefCells->f19, controls, &expl_temp, - &a__2, &a__3, &a__4); + controls->tolFun, dis_data, dis_size, problemStruct, + problemCells->f1, problemCells->f2, problemCells->f3, + problemCells->f4, problemCells->f5, problemCells->f6, + problemCells->f14, problemCells->f19, controls, &expl_temp, &a__2, + &a__3, &a__4); - // [xu,fval,exitflag,output] = simplex(@simplexIntrafun,x0u,problemDef,problemDefCells,problemDefLimits,controls,options,params,300); + // [xu,fval,exitflag,output] = simplex(@simplexIntrafun,x0u,problemStruct,problemCells,problemLimits,controls,options,params,300); // undo the variable transformations into the original space simplexXTransform(x0u, expl_temp.LB, expl_temp.UB, expl_temp.BoundClass, x); // final reshape // x = reshape(x,xsize); outsize_idx_0 = x.size(0); - problemDef->fitParams.set_size(x.size(0), 1); + problemStruct->fitParams.set_size(x.size(0), 1); for (i = 0; i < outsize_idx_0; i++) { - problemDef->fitParams[i] = x[i]; + problemStruct->fitParams[i] = x[i]; } - unpackParams(problemDef, controls->checks.fitParam, + unpackParams(problemStruct, controls->checks.fitParam, controls->checks.fitBackgroundParam, controls->checks.fitQzshift, controls->checks.fitScalefactor, controls->checks.fitBulkIn, controls->checks.fitBulkOut, controls->checks.fitResolutionParam, controls->checks.fitDomainRatio); - reflectivityCalculation(problemDef, problemDefCells, controls, problem, - &b_result); - result[0].f1.set_size(b_result.f1.size(0), 1); - outsize_idx_0 = b_result.f1.size(0); - for (i = 0; i < outsize_idx_0; i++) { - loop_ub = b_result.f1[i].f1.size(0); - result[0].f1[i].f1.set_size(b_result.f1[i].f1.size(0), 2); - for (int32_T i1{0}; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - result[0].f1[i].f1[i2 + result[0].f1[i].f1.size(0) * i1] = - b_result.f1[i].f1[i2 + b_result.f1[i].f1.size(0) * i1]; - } - } - } - - result[1].f1.set_size(b_result.f2.size(0), 1); - outsize_idx_0 = b_result.f2.size(0); - for (i = 0; i < outsize_idx_0; i++) { - loop_ub = b_result.f2[i].f1.size(0); - result[1].f1[i].f1.set_size(b_result.f2[i].f1.size(0), 2); - for (int32_T i1{0}; i1 < 2; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - result[1].f1[i].f1[i2 + result[1].f1[i].f1.size(0) * i1] = - b_result.f2[i].f1[i2 + b_result.f2[i].f1.size(0) * i1]; - } - } - } - - result[2].f1.set_size(b_result.f3.size(0), 1); - outsize_idx_0 = b_result.f3.size(0); - for (i = 0; i < outsize_idx_0; i++) { - loop_ub = b_result.f3[i].f1.size(0); - result[2].f1[i].f1.set_size(b_result.f3[i].f1.size(0), 3); - for (int32_T i1{0}; i1 < 3; i1++) { - for (int32_T i2{0}; i2 < loop_ub; i2++) { - result[2].f1[i].f1[i2 + result[2].f1[i].f1.size(0) * i1] = - b_result.f3[i].f1[i2 + b_result.f3[i].f1.size(0) * i1]; - } - } - } - - result[3].f1.set_size(b_result.f4.size(0), b_result.f4.size(1)); - loop_ub = b_result.f4.size(1); - for (i = 0; i < loop_ub; i++) { - outsize_idx_0 = b_result.f4.size(0); - for (int32_T i1{0}; i1 < outsize_idx_0; i1++) { - result[3].f1[i1 + result[3].f1.size(0) * i] = b_result.f4[i1 + - b_result.f4.size(0) * i]; - } - } - - result[4].f1.set_size(b_result.f5.size(0), b_result.f5.size(1)); - loop_ub = b_result.f5.size(1); - for (i = 0; i < loop_ub; i++) { - outsize_idx_0 = b_result.f5.size(0); - for (int32_T i1{0}; i1 < outsize_idx_0; i1++) { - result[4].f1[i1 + result[4].f1.size(0) * i] = b_result.f5[i1 + - b_result.f5.size(0) * i]; - } - } - - result[5].f1.set_size(b_result.f6.size(0), b_result.f6.size(1)); - loop_ub = b_result.f6.size(1); - for (i = 0; i < loop_ub; i++) { - outsize_idx_0 = b_result.f6.size(0); - for (int32_T i1{0}; i1 < outsize_idx_0; i1++) { - result[5].f1[i1 + result[5].f1.size(0) * i] = b_result.f6[i1 + - b_result.f6.size(0) * i]; - } - } + reflectivityCalculation(problemStruct, problemCells, controls, + contrastParams, result); } } diff --git a/RAT/runSimplex.h b/RAT/runSimplex.h index f293b5ab..6712ec30 100644 --- a/RAT/runSimplex.h +++ b/RAT/runSimplex.h @@ -18,20 +18,20 @@ // Type Declarations namespace RAT { - struct struct5_T; - struct cell_14; + struct c_struct_T; + struct cell_11; struct struct1_T; struct struct2_T; - struct struct_T; + struct d_struct_T; struct cell_wrap_9; } // Function Declarations namespace RAT { - void runSimplex(struct5_T *problemDef, const cell_14 *problemDefCells, const - struct1_T *problemDefLimits, const struct2_T *controls, - struct_T *problem, cell_wrap_9 result[6]); + void runSimplex(c_struct_T *problemStruct, const cell_11 *problemCells, const + struct1_T *problemLimits, const struct2_T *controls, + d_struct_T *contrastParams, cell_wrap_9 result[6]); } #endif diff --git a/RAT/scaledGaussPrior.cpp b/RAT/scaledGaussPrior.cpp index 29ec49cd..2f20ba81 100644 --- a/RAT/scaledGaussPrior.cpp +++ b/RAT/scaledGaussPrior.cpp @@ -21,8 +21,8 @@ namespace RAT { real_T scaledGaussPrior(const ::coder::array &m, const ::coder:: - array &extras_problemDef_fitLimits, const ::coder::array &extras_priors) + array &extras_problemStruct_fitLimits, const ::coder::array< + real_T, 2U> &extras_priors) { ::coder::array usedConstr; ::coder::array usedPriors; @@ -62,8 +62,9 @@ namespace RAT loop_ub = usedPriorInd.size(0); for (i = 0; i < 2; i++) { for (int32_T i1{0}; i1 < loop_ub; i1++) { - usedConstr[i1 + usedConstr.size(0) * i] = extras_problemDef_fitLimits - [(usedPriorInd[i1] + extras_problemDef_fitLimits.size(0) * i) - 1]; + usedConstr[i1 + usedConstr.size(0) * i] = + extras_problemStruct_fitLimits[(usedPriorInd[i1] + + extras_problemStruct_fitLimits.size(0) * i) - 1]; } } diff --git a/RAT/scaledGaussPrior.h b/RAT/scaledGaussPrior.h index dc27991a..1c93780b 100644 --- a/RAT/scaledGaussPrior.h +++ b/RAT/scaledGaussPrior.h @@ -20,8 +20,8 @@ namespace RAT { real_T scaledGaussPrior(const ::coder::array &m, const ::coder:: - array &extras_problemDef_fitLimits, const ::coder::array &extras_priors); + array &extras_problemStruct_fitLimits, const ::coder::array< + real_T, 2U> &extras_priors); } #endif diff --git a/RAT/setupDREAM.cpp b/RAT/setupDREAM.cpp index 90314123..65232011 100644 --- a/RAT/setupDREAM.cpp +++ b/RAT/setupDREAM.cpp @@ -23,8 +23,8 @@ namespace RAT { void setupDREAM(real_T DREAMPar_d, real_T DREAMPar_N, real_T DREAMPar_T, real_T DREAMPar_lambda, real_T DREAMPar_pUnitGamma, boolean_T - DREAMPar_adaptPCR, struct14_T *outDREAMPar, struct15_T - *Meas_info, ::coder::array &chain, struct13_T + DREAMPar_adaptPCR, struct13_T *outDREAMPar, struct14_T + *Meas_info, ::coder::array &chain, struct12_T *output, ::coder::array &log_L, ::coder::array< real_T, 2U> &Table_gamma) { diff --git a/RAT/setupDREAM.h b/RAT/setupDREAM.h index 2d63541b..693e8502 100644 --- a/RAT/setupDREAM.h +++ b/RAT/setupDREAM.h @@ -19,9 +19,9 @@ // Type Declarations namespace RAT { - struct struct14_T; - struct struct15_T; struct struct13_T; + struct struct14_T; + struct struct12_T; } // Function Declarations @@ -29,8 +29,8 @@ namespace RAT { void setupDREAM(real_T DREAMPar_d, real_T DREAMPar_N, real_T DREAMPar_T, real_T DREAMPar_lambda, real_T DREAMPar_pUnitGamma, boolean_T - DREAMPar_adaptPCR, struct14_T *outDREAMPar, struct15_T - *Meas_info, ::coder::array &chain, struct13_T + DREAMPar_adaptPCR, struct13_T *outDREAMPar, struct14_T + *Meas_info, ::coder::array &chain, struct12_T *output, ::coder::array &log_L, ::coder::array< real_T, 2U> &Table_gamma); } diff --git a/RAT/shiftData.cpp b/RAT/shiftData.cpp index 546b3e28..f3baeb95 100644 --- a/RAT/shiftData.cpp +++ b/RAT/shiftData.cpp @@ -32,12 +32,12 @@ namespace RAT // x-data over the simulation range. // // INPUTS: - // * scalefactor: problem.scalefactors - // * qzshift: problem.qzhifts - // * dataPresent: problem.dataPresent - // * data: problem.data - // * dataLimits: problem.dataLimits - // * simLimits: problem.simLimits + // * scalefactor: problemStruct.scalefactors + // * qzshift: problemStruct.qzhifts + // * dataPresent: problemStruct.dataPresent + // * data: problemStruct.data + // * dataLimits: problemStruct.dataLimits + // * simLimits: problemStruct.simLimits // // OUTPUTS: // * shiftedData: Data shifted using given scale factor diff --git a/RAT/simplexIntrafun.cpp b/RAT/simplexIntrafun.cpp index 052ba07a..c07a7ab4 100644 --- a/RAT/simplexIntrafun.cpp +++ b/RAT/simplexIntrafun.cpp @@ -21,92 +21,92 @@ // Function Definitions namespace RAT { - void simplexIntrafun(const ::coder::array &x, const struct5_T - *problemDef, const ::coder::array - &problemDefCells_f1, const ::coder::array - &problemDefCells_f2, const ::coder::array - &problemDefCells_f3, const ::coder::array - &problemDefCells_f4, const ::coder::array - &problemDefCells_f5, const ::coder::array - &problemDefCells_f6, const ::coder::array - &problemDefCells_f14, const ::coder::array &problemDefCells_f19, const struct2_T *controls, - const j_struct_T *params, real_T *fval, struct_T - *b_problemDef, cell_13 *result) + void simplexIntrafun(const ::coder::array &x, const c_struct_T + *problemStruct, const ::coder::array + &problemCells_f1, const ::coder::array + &problemCells_f2, const ::coder::array + &problemCells_f3, const ::coder::array + &problemCells_f4, const ::coder::array + &problemCells_f5, const ::coder::array + &problemCells_f6, const ::coder::array + &problemCells_f14, const ::coder::array + &problemCells_f19, const struct2_T *controls, const + k_struct_T *params, real_T *fval, d_struct_T + *b_problemStruct, cell_wrap_9 result[6]) { ::coder::array xtrans; - cell_14 expl_temp; - struct5_T c_problemDef; + c_struct_T c_problemStruct; + cell_11 expl_temp; int32_T xtrans_idx_0; - c_problemDef = *problemDef; + c_problemStruct = *problemStruct; // transform variables, then call original function simplexXTransform(x, params->LB, params->UB, params->BoundClass, xtrans); // Unpck the params.. xtrans_idx_0 = xtrans.size(0); - c_problemDef.fitParams.set_size(xtrans.size(0), 1); + c_problemStruct.fitParams.set_size(xtrans.size(0), 1); for (int32_T i{0}; i < xtrans_idx_0; i++) { - c_problemDef.fitParams[i] = xtrans[i]; + c_problemStruct.fitParams[i] = xtrans[i]; } - unpackParams(&c_problemDef, controls->checks.fitParam, + unpackParams(&c_problemStruct, controls->checks.fitParam, controls->checks.fitBackgroundParam, controls->checks.fitQzshift, controls->checks.fitScalefactor, controls->checks.fitBulkIn, controls->checks.fitBulkOut, controls->checks.fitResolutionParam, controls->checks.fitDomainRatio); - expl_temp.f19.set_size(1, problemDefCells_f19.size(1)); - xtrans_idx_0 = problemDefCells_f19.size(1); + expl_temp.f19.set_size(1, problemCells_f19.size(1)); + xtrans_idx_0 = problemCells_f19.size(1); for (int32_T i{0}; i < xtrans_idx_0; i++) { - expl_temp.f19[i] = problemDefCells_f19[i]; + expl_temp.f19[i] = problemCells_f19[i]; } - expl_temp.f14.set_size(1, problemDefCells_f14.size(1)); - xtrans_idx_0 = problemDefCells_f14.size(1); + expl_temp.f14.set_size(1, problemCells_f14.size(1)); + xtrans_idx_0 = problemCells_f14.size(1); for (int32_T i{0}; i < xtrans_idx_0; i++) { - expl_temp.f14[i] = problemDefCells_f14[i]; + expl_temp.f14[i] = problemCells_f14[i]; } - expl_temp.f6.set_size(problemDefCells_f6.size(0)); - xtrans_idx_0 = problemDefCells_f6.size(0); + expl_temp.f6.set_size(problemCells_f6.size(0)); + xtrans_idx_0 = problemCells_f6.size(0); for (int32_T i{0}; i < xtrans_idx_0; i++) { - expl_temp.f6[i] = problemDefCells_f6[i]; + expl_temp.f6[i] = problemCells_f6[i]; } - expl_temp.f5.set_size(1, problemDefCells_f5.size(1)); - xtrans_idx_0 = problemDefCells_f5.size(1); + expl_temp.f5.set_size(1, problemCells_f5.size(1)); + xtrans_idx_0 = problemCells_f5.size(1); for (int32_T i{0}; i < xtrans_idx_0; i++) { - expl_temp.f5[i] = problemDefCells_f5[i]; + expl_temp.f5[i] = problemCells_f5[i]; } - expl_temp.f4.set_size(1, problemDefCells_f4.size(1)); - xtrans_idx_0 = problemDefCells_f4.size(1); + expl_temp.f4.set_size(1, problemCells_f4.size(1)); + xtrans_idx_0 = problemCells_f4.size(1); for (int32_T i{0}; i < xtrans_idx_0; i++) { - expl_temp.f4[i] = problemDefCells_f4[i]; + expl_temp.f4[i] = problemCells_f4[i]; } - expl_temp.f3.set_size(1, problemDefCells_f3.size(1)); - xtrans_idx_0 = problemDefCells_f3.size(1); + expl_temp.f3.set_size(1, problemCells_f3.size(1)); + xtrans_idx_0 = problemCells_f3.size(1); for (int32_T i{0}; i < xtrans_idx_0; i++) { - expl_temp.f3[i] = problemDefCells_f3[i]; + expl_temp.f3[i] = problemCells_f3[i]; } - expl_temp.f2.set_size(1, problemDefCells_f2.size(1)); - xtrans_idx_0 = problemDefCells_f2.size(1); + expl_temp.f2.set_size(1, problemCells_f2.size(1)); + xtrans_idx_0 = problemCells_f2.size(1); for (int32_T i{0}; i < xtrans_idx_0; i++) { - expl_temp.f2[i] = problemDefCells_f2[i]; + expl_temp.f2[i] = problemCells_f2[i]; } - expl_temp.f1.set_size(1, problemDefCells_f1.size(1)); - xtrans_idx_0 = problemDefCells_f1.size(1); + expl_temp.f1.set_size(1, problemCells_f1.size(1)); + xtrans_idx_0 = problemCells_f1.size(1); for (int32_T i{0}; i < xtrans_idx_0; i++) { - expl_temp.f1[i] = problemDefCells_f1[i]; + expl_temp.f1[i] = problemCells_f1[i]; } - reflectivityCalculation(&c_problemDef, &expl_temp, controls, b_problemDef, - result); - *fval = b_problemDef->calculations.sumChi; + reflectivityCalculation(&c_problemStruct, &expl_temp, controls, + b_problemStruct, result); + *fval = b_problemStruct->calculations.sumChi; } } diff --git a/RAT/simplexIntrafun.h b/RAT/simplexIntrafun.h index 6c09bdc9..3bca5bc8 100644 --- a/RAT/simplexIntrafun.h +++ b/RAT/simplexIntrafun.h @@ -20,26 +20,26 @@ // Type Declarations namespace RAT { - struct j_struct_T; - struct struct_T; - struct cell_13; + struct c_struct_T; + struct k_struct_T; + struct d_struct_T; } // Function Declarations namespace RAT { - void simplexIntrafun(const ::coder::array &x, const struct5_T - *problemDef, const ::coder::array - &problemDefCells_f1, const ::coder::array - &problemDefCells_f2, const ::coder::array - &problemDefCells_f3, const ::coder::array - &problemDefCells_f4, const ::coder::array - &problemDefCells_f5, const ::coder::array - &problemDefCells_f6, const ::coder::array - &problemDefCells_f14, const ::coder::array &problemDefCells_f19, const struct2_T *controls, - const j_struct_T *params, real_T *fval, struct_T - *b_problemDef, cell_13 *result); + void simplexIntrafun(const ::coder::array &x, const c_struct_T + *problemStruct, const ::coder::array + &problemCells_f1, const ::coder::array + &problemCells_f2, const ::coder::array + &problemCells_f3, const ::coder::array + &problemCells_f4, const ::coder::array + &problemCells_f5, const ::coder::array + &problemCells_f6, const ::coder::array + &problemCells_f14, const ::coder::array + &problemCells_f19, const struct2_T *controls, const + k_struct_T *params, real_T *fval, d_struct_T + *b_problemStruct, cell_wrap_9 result[6]); } #endif diff --git a/RAT/single.cpp b/RAT/single.cpp index cc084ade..86892148 100644 --- a/RAT/single.cpp +++ b/RAT/single.cpp @@ -27,22 +27,22 @@ namespace RAT { namespace standardLayers { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &sldProfiles, ::coder::array< cell_wrap_8, 1U> &allLayers, ::coder::array &allRoughs) { static real_T thisContrastLayers_data[6000]; - ::coder::array outParameterisedLayers; + ::coder::array outParameterisedLayers; ::coder::array b_thisContrastLayers_data; ::coder::array shiftedDat; ::coder::array sldProfile; @@ -65,7 +65,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -75,19 +75,19 @@ namespace RAT // * layersDetails: Master array of all available layers. // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - useImaginary = problemDef->useImaginary; + // Extract individual parameters from problemStruct + // Extract individual parameters from problem + useImaginary = problemStruct->useImaginary; // Allocate the memory for the output arrays before the main loop - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(i); // end memory allocation. // First we need to allocate the absolute values of the input // parameters to all the layers in the layers list. This only needs // to be done once, and so is done outside the contrasts loop - allocateParamsToLayers(problemDef->params, problemDefCells->f6, + allocateParamsToLayers(problemStruct->params, problemCells->f6, outParameterisedLayers); // Resample params if requiired @@ -118,22 +118,22 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); // Also need to determine which layers from the overall layers list // are required for this contrast, and put them in the correct order // according to geometry - allocateLayersForContrast(problemDefCells->f5[b_i].f1, + allocateLayersForContrast(problemCells->f5[b_i].f1, outParameterisedLayers, useImaginary, thisContrastLayers_data, thisContrastLayers_size); @@ -146,22 +146,22 @@ namespace RAT // Call the core layers calculation b_thisContrastLayers_data.set(&thisContrastLayers_data[0], thisContrastLayers_size[0], thisContrastLayers_size[1]); - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; - coreLayersCalculation(b_thisContrastLayers_data, problemDef->params[0], - problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, - thisBulkOut, problemDef->resample[b_i], + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; + coreLayersCalculation(b_thisContrastLayers_data, problemStruct-> + params[0], problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, + thisBulkOut, problemStruct->resample[b_i], controls->calcSldDuringFit, thisScalefactor, - thisQzshift, problemDef->dataPresent[b_i], - problemDefCells->f2[b_i].f1, b_dv, b_dv1, dv2, + thisQzshift, problemStruct->dataPresent[b_i], + problemCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[b_i], - static_cast(problemDef->params.size(1)), + problemStruct->contrastBackgroundsType[b_i], + static_cast(problemStruct->params.size(1)), controls->resamPars, useImaginary, sldProfile, reflectivity[b_i].f1, simulation[b_i].f1, shiftedDat, layerSlds[b_i].f1, allLayers[b_i].f1, @@ -197,7 +197,7 @@ namespace RAT bulkIns[b_i] = thisBulkIn; bulkOuts[b_i] = thisBulkOut; resolutionParams[b_i] = thisResol; - allRoughs[b_i] = problemDef->params[0]; + allRoughs[b_i] = problemStruct->params[0]; } } } diff --git a/RAT/single.h b/RAT/single.h index e558dfb9..ff1a6cac 100644 --- a/RAT/single.h +++ b/RAT/single.h @@ -11,18 +11,13 @@ #define SINGLE_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,15 +25,15 @@ namespace RAT { namespace standardLayers { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &sldProfiles, ::coder::array< cell_wrap_8, 1U> &allLayers, ::coder::array diff --git a/RAT/single1.cpp b/RAT/single1.cpp index c593edd3..b1ed81c6 100644 --- a/RAT/single1.cpp +++ b/RAT/single1.cpp @@ -26,15 +26,15 @@ namespace RAT { namespace customLayers { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &sldProfiles, ::coder::array< cell_wrap_8, 1U> &allLayers, ::coder::array @@ -60,7 +60,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -70,28 +70,22 @@ namespace RAT // * layersDetails: Master array of all available layers. // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef + // Extract individual parameters from problemStruct + // Extract individual parameters from problem // Pre-Allocation of output arrays... - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(i); // --- End Memory Allocation --- // Resampling parameters // Process the custom models.... - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, - problemDef->useImaginary, allLayers, allRoughs); + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, + problemStruct->useImaginary, allLayers, allRoughs); // Single cored over all contrasts outSsubs.set_size(i); @@ -114,15 +108,15 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); @@ -147,23 +141,23 @@ namespace RAT real_T b_dv[2]; real_T b_dv1[2]; real_T dv2[2]; - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; coreLayersCalculation(b_allLayers, allRoughs[b_i], - problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, - thisBulkOut, problemDef->resample[b_i], + problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, + thisBulkOut, problemStruct->resample[b_i], controls->calcSldDuringFit, thisScalefactor, - thisQzshift, problemDef->dataPresent[b_i], - problemDefCells->f2[b_i].f1, b_dv, b_dv1, dv2, + thisQzshift, problemStruct->dataPresent[b_i], + problemCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[b_i], - static_cast(problemDef->params.size(1)), - controls->resamPars, problemDef->useImaginary, + problemStruct->contrastBackgroundsType[b_i], + static_cast(problemStruct->params.size(1)), + controls->resamPars, problemStruct->useImaginary, sldProfile, reflectivity[b_i].f1, simulation[b_i] .f1, shiftedDat, layerSlds[b_i].f1, allLayers[b_i].f1, &chis[b_i], &outSsubs[b_i]); diff --git a/RAT/single1.h b/RAT/single1.h index 6579cfa6..43438148 100644 --- a/RAT/single1.h +++ b/RAT/single1.h @@ -11,18 +11,13 @@ #define SINGLE1_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,15 +25,15 @@ namespace RAT { namespace customLayers { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &sldProfiles, ::coder::array< cell_wrap_8, 1U> &allLayers, ::coder::array diff --git a/RAT/single2.cpp b/RAT/single2.cpp index 5a0f1dd6..a67e0233 100644 --- a/RAT/single2.cpp +++ b/RAT/single2.cpp @@ -30,21 +30,21 @@ namespace RAT { namespace customXY { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &sldProfiles, ::coder::array< cell_wrap_8, 1U> &allLayers, ::coder::array &allRoughs) { - ::coder::array b_problemDefCells; + ::coder::array b_problemCells; ::coder::array b_sldProfiles; ::coder::array c_sldProfiles; ::coder::array layerSld; @@ -57,7 +57,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -68,10 +68,10 @@ namespace RAT // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. // % Layers details N/A - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef + // Extract individual parameters from problemStruct + // Extract individual parameters from problem // Pre-Allocation... - loop_ub_tmp = static_cast(problemDef->numberOfContrasts); + loop_ub_tmp = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(loop_ub_tmp); outSsubs.set_size(loop_ub_tmp); for (int32_T i{0}; i < loop_ub_tmp; i++) { @@ -79,19 +79,13 @@ namespace RAT } // Resampling parameters - useImaginary = problemDef->useImaginary; - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, + useImaginary = problemStruct->useImaginary; + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, sldProfiles, allRoughs); qzshifts.set_size(loop_ub_tmp); scalefactors.set_size(loop_ub_tmp); @@ -109,15 +103,15 @@ namespace RAT real_T b_dv1[2]; int32_T b_loop_ub; int32_T loop_ub; - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &backgroundParams[b_i], &qzshifts[b_i], &scalefactors[b_i], &bulkIns[b_i], &bulkOuts[b_i], &resolutionParams[b_i]); @@ -142,7 +136,7 @@ namespace RAT sldProfiles[b_i].f1.size(0) * 2]; } - c_resampleLayersReIm(b_sldProfiles, c_sldProfiles, + b_resampleLayersReIm(b_sldProfiles, c_sldProfiles, controls->resamPars, layerSld); } @@ -159,25 +153,24 @@ namespace RAT } } - b_problemDefCells.set_size(problemDefCells->f2 - [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> - f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); - loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + b_problemCells.set_size(problemCells->f2[problemCells->f2.size(0) * + b_i].f1.size(0), problemCells->f2[problemCells->f2.size(0) * b_i]. + f1.size(1)); + loop_ub = problemCells->f2[b_i].f1.size(1) - 1; for (int32_T i{0}; i <= loop_ub; i++) { - b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + b_loop_ub = problemCells->f2[b_i].f1.size(0) - 1; for (int32_T i1{0}; i1 <= b_loop_ub; i1++) { - b_problemDefCells[i1 + b_problemDefCells.size(0) * i] = - problemDefCells->f2[b_i].f1[i1 + problemDefCells->f2[b_i]. - f1.size(0) * i]; + b_problemCells[i1 + b_problemCells.size(0) * i] = problemCells-> + f2[b_i].f1[i1 + problemCells->f2[b_i].f1.size(0) * i]; } } - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> - dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemStruct-> + dataPresent[b_i], b_problemCells, b_dv, b_dv1, shiftedDat); shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); loop_ub = shiftedDat.size(1); for (int32_T i{0}; i < loop_ub; i++) { @@ -188,15 +181,15 @@ namespace RAT } } - b_dv[0] = problemDefCells->f4[b_i].f1[0]; - b_dv[1] = problemDefCells->f4[b_i].f1[1]; - b_dv1[0] = problemDefCells->f1[b_i].f1[0]; - b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f4[b_i].f1[0]; + b_dv[1] = problemCells->f4[b_i].f1[1]; + b_dv1[0] = problemCells->f1[b_i].f1[0]; + b_dv1[1] = problemCells->f1[b_i].f1[1]; callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, layerSld, 0.0, resolutionParams[b_i], useImaginary, reflect, simulation[b_i].f1); applyBackgroundCorrection(reflect, simulation[b_i].f1, shiftedDat, - backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + backgroundParams[b_i], problemStruct->contrastBackgroundsType[b_i]); loop_ub = reflect.size(0); reflectivity[b_i].f1.set_size(reflect.size(0), 2); for (int32_T i{0}; i < 2; i++) { @@ -206,9 +199,9 @@ namespace RAT } } - if (problemDef->dataPresent[b_i] != 0.0) { + if (problemStruct->dataPresent[b_i] != 0.0) { chis[b_i] = chiSquared(shiftedDat, reflect, static_cast - (problemDef->params.size(1))); + (problemStruct->params.size(1))); } else { chis[b_i] = 0.0; } diff --git a/RAT/single2.h b/RAT/single2.h index 261073de..7cc63ce0 100644 --- a/RAT/single2.h +++ b/RAT/single2.h @@ -11,18 +11,13 @@ #define SINGLE2_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,15 +25,15 @@ namespace RAT { namespace customXY { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &sldProfiles, ::coder::array< cell_wrap_8, 1U> &allLayers, ::coder::array diff --git a/RAT/single3.cpp b/RAT/single3.cpp index a6ec6b33..f9146186 100644 --- a/RAT/single3.cpp +++ b/RAT/single3.cpp @@ -29,15 +29,15 @@ namespace RAT { namespace standardLayers { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &domainSldProfiles, ::coder:: array &allLayers, ::coder::array @@ -45,10 +45,10 @@ namespace RAT { static real_T thisContrastLayers1_data[6000]; static real_T thisContrastLayers2_data[6000]; - ::coder::array outParameterisedLayers; - ::coder::array tempAllLayers; - ::coder::array tempLayerSlds; - ::coder::array tempSldProfiles; + ::coder::array outParameterisedLayers; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; ::coder::array a__6; ::coder::array b_thisContrastLayers1_data; ::coder::array b_thisContrastLayers2_data; @@ -90,7 +90,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -101,22 +101,22 @@ namespace RAT // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. // Additionally extract the additional domain layers details - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); + // Extract individual parameters from problemStruct + // Extract individual parameters from problem + nParams = problemStruct->params.size(1); calcSld = controls->calcSldDuringFit; - useImaginary = problemDef->useImaginary; + useImaginary = problemStruct->useImaginary; // Default for compile. // Allocate the memory for the output arrays before the main loop - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(i); // end memory allocation. // First we need to allocate the absolute values of the input // parameters to all the layers in the layers list. This only needs // to be done once, and so is done outside the contrasts loop - allocateParamsToLayers(problemDef->params, problemDefCells->f6, + allocateParamsToLayers(problemStruct->params, problemCells->f6, outParameterisedLayers); // Resample params if requiired @@ -149,25 +149,25 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); // Also need to determine which layers from the overall layers list // are required for this contrast, and put them in the correct order // according to geometry. We run it twice, once for each domain... - allocateLayersForContrast(problemDefCells->f19[0].f1, + allocateLayersForContrast(problemCells->f19[0].f1, outParameterisedLayers, useImaginary, thisContrastLayers1_data, thisContrastLayers1_size); - allocateLayersForContrast(problemDefCells->f19[1].f1, + allocateLayersForContrast(problemCells->f19[1].f1, outParameterisedLayers, useImaginary, thisContrastLayers2_data, thisContrastLayers2_size); @@ -181,48 +181,48 @@ namespace RAT // domain b_thisContrastLayers1_data.set(&thisContrastLayers1_data[0], thisContrastLayers1_size[0], thisContrastLayers1_size[1]); - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; nonPolarisedTF::coreLayersCalculation(b_thisContrastLayers1_data, - problemDef->params[0], problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, thisBulkOut, - problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, - problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, + problemStruct->params[0], problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, thisBulkOut, + problemStruct->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemStruct->dataPresent[b_i], problemCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[b_i], static_cast + problemStruct->contrastBackgroundsType[b_i], static_cast (nParams), controls->resamPars, useImaginary, r.f1, reflect1, simul1, shiftedDat, r1.f1, r2.f1, &a__5, &outSsubs[b_i]); b_thisContrastLayers2_data.set(&thisContrastLayers2_data[0], thisContrastLayers2_size[0], thisContrastLayers2_size[1]); - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; nonPolarisedTF::coreLayersCalculation(b_thisContrastLayers2_data, - problemDef->params[0], problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, thisBulkOut, - problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, - problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, + problemStruct->params[0], problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, thisBulkOut, + problemStruct->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemStruct->dataPresent[b_i], problemCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[b_i], static_cast + problemStruct->contrastBackgroundsType[b_i], static_cast (nParams), controls->resamPars, useImaginary, r3.f1, reflect2, simul2, a__6, r4.f1, r5.f1, &a__7, &a__8); // Calculate the average reflectivities.... averageReflectivity(reflect1, reflect2, simul1, simul2, - problemDef->domainRatio[static_cast - (problemDef->contrastDomainRatios[b_i]) - 1], + problemStruct->domainRatio[static_cast + (problemStruct->contrastDomainRatios[b_i]) - 1], totReflect, simulation[b_i].f1); // Get an overall chi-squared for the new averaged curve.. chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast - (problemDef->params.size(1))); + (problemStruct->params.size(1))); // Store returned values for this contrast in the output arrays. // As well as the calculated profiles, we also store a record of @@ -259,7 +259,7 @@ namespace RAT bulkIns[b_i] = thisBulkIn; bulkOuts[b_i] = thisBulkOut; resolutionParams[b_i] = thisResol; - allRoughs[b_i] = problemDef->params[0]; + allRoughs[b_i] = problemStruct->params[0]; } allLayers.set_size(i, 2); diff --git a/RAT/single3.h b/RAT/single3.h index 467d5b17..3b11cbfa 100644 --- a/RAT/single3.h +++ b/RAT/single3.h @@ -11,18 +11,13 @@ #define SINGLE3_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,15 +25,15 @@ namespace RAT { namespace standardLayers { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &domainSldProfiles, ::coder:: array &allLayers, ::coder::array diff --git a/RAT/single4.cpp b/RAT/single4.cpp index dd717479..3f3685fe 100644 --- a/RAT/single4.cpp +++ b/RAT/single4.cpp @@ -29,24 +29,24 @@ namespace RAT { namespace customLayers { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &domainSldProfiles, ::coder:: array &allLayers, ::coder::array &allRoughs) { - ::coder::array r; - ::coder::array tempAllLayers; - ::coder::array tempLayerSlds; - ::coder::array tempSldProfiles; + ::coder::array r; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; ::coder::array calcAllLayers; ::coder::array a__5; ::coder::array reflect1; @@ -86,7 +86,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -96,32 +96,26 @@ namespace RAT // * layersDetails: Master array of all available layers. // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef - nParams = problemDef->params.size(1); + // Extract individual parameters from problemStruct + // Extract individual parameters from problem + nParams = problemStruct->params.size(1); calcSld = controls->calcSldDuringFit; - useImaginary = problemDef->useImaginary; + useImaginary = problemStruct->useImaginary; // Default for compile. // Pre-Allocation of output arrays... - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(i); // Resampling parameters // Process the custom models.... - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, - problemDef->useImaginary, r, allRoughs); + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, + problemStruct->useImaginary, r, allRoughs); cast(r, calcAllLayers); // Parallel over all contrasts @@ -151,15 +145,15 @@ namespace RAT // from the input arrays. // First need to decide which values of the backgrounds, scalefactors // data shifts and bulk contrasts are associated with this contrast - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &thisBackground, &thisQzshift, &thisScalefactor, &thisBulkIn, &thisBulkOut, &thisResol); @@ -172,48 +166,48 @@ namespace RAT // points // Call the reflectivity calculation for each domain // Domain 1 - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; nonPolarisedTF::coreLayersCalculation(calcAllLayers[b_i].f1, - allRoughs[b_i], problemDef->geometry.data, problemDef->geometry.size, - thisBulkIn, thisBulkOut, problemDef->resample[b_i], calcSld, - thisScalefactor, thisQzshift, problemDef->dataPresent[b_i], - problemDefCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, - thisResol, problemDef->contrastBackgroundsType[b_i], - static_cast(nParams), controls->resamPars, useImaginary, - r1.f1, reflect1, simul1, shiftedDat, r2.f1, r3.f1, &a__4, - &outSsubs[b_i]); + allRoughs[b_i], problemStruct->geometry.data, + problemStruct->geometry.size, thisBulkIn, thisBulkOut, + problemStruct->resample[b_i], calcSld, thisScalefactor, thisQzshift, + problemStruct->dataPresent[b_i], problemCells->f2[b_i].f1, b_dv, + b_dv1, dv2, thisBackground, thisResol, + problemStruct->contrastBackgroundsType[b_i], static_cast + (nParams), controls->resamPars, useImaginary, r1.f1, reflect1, + simul1, shiftedDat, r2.f1, r3.f1, &a__4, &outSsubs[b_i]); // Domain 2 - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - dv2[0] = problemDefCells->f1[b_i].f1[0]; - dv2[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + dv2[0] = problemCells->f1[b_i].f1[0]; + dv2[1] = problemCells->f1[b_i].f1[1]; nonPolarisedTF::coreLayersCalculation(calcAllLayers[b_i + - calcAllLayers.size(0)].f1, allRoughs[b_i], problemDef->geometry.data, - problemDef->geometry.size, thisBulkIn, thisBulkOut, - problemDef->resample[b_i], calcSld, thisScalefactor, thisQzshift, - problemDef->dataPresent[b_i], problemDefCells->f2[b_i].f1, b_dv, - b_dv1, dv2, thisBackground, thisResol, - problemDef->contrastBackgroundsType[b_i], static_cast - (nParams), controls->resamPars, useImaginary, r4.f1, reflect2, - simul2, a__5, r5.f1, r6.f1, &a__6, &a__7); + calcAllLayers.size(0)].f1, allRoughs[b_i], + problemStruct->geometry.data, problemStruct->geometry.size, + thisBulkIn, thisBulkOut, problemStruct->resample[b_i], calcSld, + thisScalefactor, thisQzshift, problemStruct->dataPresent[b_i], + problemCells->f2[b_i].f1, b_dv, b_dv1, dv2, thisBackground, + thisResol, problemStruct->contrastBackgroundsType[b_i], + static_cast(nParams), controls->resamPars, useImaginary, + r4.f1, reflect2, simul2, a__5, r5.f1, r6.f1, &a__6, &a__7); // Calculate the average reflectivities.... averageReflectivity(reflect1, reflect2, simul1, simul2, - problemDef->domainRatio[static_cast - (problemDef->contrastDomainRatios[b_i]) - 1], + problemStruct->domainRatio[static_cast + (problemStruct->contrastDomainRatios[b_i]) - 1], totReflect, simulation[b_i].f1); // Get an overall chi-squared for the new averaged curve.. chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast - (problemDef->params.size(1))); + (problemStruct->params.size(1))); // Store returned values for this contrast in the output arrays. // As well as the calculated profiles, we also store a record of diff --git a/RAT/single4.h b/RAT/single4.h index 9cbb4ced..331b6760 100644 --- a/RAT/single4.h +++ b/RAT/single4.h @@ -11,18 +11,13 @@ #define SINGLE4_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,15 +25,15 @@ namespace RAT { namespace customLayers { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &domainSldProfiles, ::coder:: array &allLayers, ::coder::array diff --git a/RAT/single5.cpp b/RAT/single5.cpp index 38116f98..6f49df04 100644 --- a/RAT/single5.cpp +++ b/RAT/single5.cpp @@ -31,25 +31,25 @@ namespace RAT { namespace customXY { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &domainSldProfiles, ::coder:: array &allLayers, ::coder::array &allRoughs) { - ::coder::array tempAllLayers; - ::coder::array tempLayerSlds; - ::coder::array tempSldProfiles; + ::coder::array tempAllLayers; + ::coder::array tempLayerSlds; + ::coder::array tempSldProfiles; ::coder::array b_domainSldProfiles; - ::coder::array b_problemDefCells; + ::coder::array b_problemCells; ::coder::array c_domainSldProfiles; ::coder::array r4; ::coder::array reflect1; @@ -71,7 +71,7 @@ namespace RAT // Splits up the master input list of all arrays into separate arrays // // INPUTS: - // * problemDefCells: cell array where all the project data is grouped together. + // * problemCells: cell array where all the project data is grouped together. // // OUTPUTS: // * repeatLayers: controls repeating of the layers stack. @@ -82,28 +82,22 @@ namespace RAT // * contrastLayers: Which specific combination of arrays are needed for each contrast. // * customFiles:Filenames and path for any custom files used. // % Layers details N/A - // Extract individual parameters from problemDef struct - // Extract individual parameters from problemDef + // Extract individual parameters from problemStruct + // Extract individual parameters from problem // Pre-Allocation... - i = static_cast(problemDef->numberOfContrasts); + i = static_cast(problemStruct->numberOfContrasts); backgroundParams.set_size(i); // Resampling parameters - useImaginary = problemDef->useImaginary; + useImaginary = problemStruct->useImaginary; // Default for compile. - processCustomFunction(problemDef->contrastBackgrounds, - problemDef->contrastQzshifts, - problemDef->contrastScalefactors, - problemDef->contrastBulkIns, - problemDef->contrastBulkOuts, - problemDef->contrastResolutions, - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, - problemDef->contrastCustomFiles, - problemDef->numberOfContrasts, - problemDefCells->f14, problemDef->params, + processCustomFunction(problemStruct->contrastBulkIns, + problemStruct->contrastBulkOuts, + problemStruct->bulkIn, problemStruct->bulkOut, + problemStruct->contrastCustomFiles, + problemStruct->numberOfContrasts, + problemCells->f14, problemStruct->params, domainSldProfiles, allRoughs); outSsubs.set_size(i); qzshifts.set_size(i); @@ -123,22 +117,22 @@ namespace RAT real_T b_dv[2]; real_T b_dv1[2]; outSsubs[b_i] = allRoughs[b_i]; - backSort(problemDef->contrastBackgrounds[b_i], - problemDef->contrastQzshifts[b_i], - problemDef->contrastScalefactors[b_i], - problemDef->contrastBulkIns[b_i], - problemDef->contrastBulkOuts[b_i], - problemDef->contrastResolutions[b_i], - problemDef->backgroundParams, problemDef->qzshifts, - problemDef->scalefactors, problemDef->bulkIn, - problemDef->bulkOut, problemDef->resolutionParams, + backSort(problemStruct->contrastBackgrounds[b_i], + problemStruct->contrastQzshifts[b_i], + problemStruct->contrastScalefactors[b_i], + problemStruct->contrastBulkIns[b_i], + problemStruct->contrastBulkOuts[b_i], + problemStruct->contrastResolutions[b_i], + problemStruct->backgroundParams, problemStruct->qzshifts, + problemStruct->scalefactors, problemStruct->bulkIn, + problemStruct->bulkOut, problemStruct->resolutionParams, &backgroundParams[b_i], &qzshifts[b_i], &scalefactors[b_i], &bulkIns[b_i], &bulkOuts[b_i], &resolutionParams[b_i]); // Get the domain ratio for this contrast // Resample the sld profiles if (!useImaginary) { - resampleLayers(domainSldProfiles[0].f1, controls->resamPars, r.f1); + resampleLayers(domainSldProfiles[b_i].f1, controls->resamPars, r.f1); r1.f1.set_size(r.f1.size(0), 3); for (int32_T i1{0}; i1 < 3; i1++) { loop_ub = r.f1.size(0); @@ -147,31 +141,29 @@ namespace RAT } } - resampleLayers(domainSldProfiles[1].f1, controls->resamPars, r.f1); + resampleLayers(domainSldProfiles[b_i + domainSldProfiles.size(0)].f1, + controls->resamPars, r.f1); } else { - loop_ub = domainSldProfiles[0].f1.size(0); - b_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i].f1.size(0); + b_domainSldProfiles.set_size(domainSldProfiles[b_i].f1.size(0), 2); for (int32_T i1{0}; i1 < 2; i1++) { for (int32_T i2{0}; i2 < loop_ub; i2++) { b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = - domainSldProfiles[0].f1[i2 + domainSldProfiles[0].f1.size(0) * - i1]; + domainSldProfiles[b_i].f1[i2 + domainSldProfiles[b_i].f1.size + (0) * i1]; } } - loop_ub = domainSldProfiles[0].f1.size(0); - b_loop_ub = domainSldProfiles[0].f1.size(0); - c_domainSldProfiles.set_size(domainSldProfiles[0].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i].f1.size(0); + c_domainSldProfiles.set_size(domainSldProfiles[b_i].f1.size(0), 2); for (int32_T i1{0}; i1 < loop_ub; i1++) { - c_domainSldProfiles[i1] = domainSldProfiles[0].f1[i1]; - } - - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[b_i].f1[i1]; c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = - domainSldProfiles[0].f1[i1 + domainSldProfiles[0].f1.size(0) * 2]; + domainSldProfiles[b_i].f1[i1 + domainSldProfiles[b_i].f1.size(0) + * 2]; } - c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + b_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, controls->resamPars, r.f1); r1.f1.set_size(r.f1.size(0), 4); for (int32_T i1{0}; i1 < 4; i1++) { @@ -181,29 +173,33 @@ namespace RAT } } - loop_ub = domainSldProfiles[1].f1.size(0); - b_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size + (0); + b_domainSldProfiles.set_size(domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(0), 2); for (int32_T i1{0}; i1 < 2; i1++) { for (int32_T i2{0}; i2 < loop_ub; i2++) { b_domainSldProfiles[i2 + b_domainSldProfiles.size(0) * i1] = - domainSldProfiles[1].f1[i2 + domainSldProfiles[1].f1.size(0) * + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i2 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * i1]; } } - loop_ub = domainSldProfiles[1].f1.size(0); - b_loop_ub = domainSldProfiles[1].f1.size(0); - c_domainSldProfiles.set_size(domainSldProfiles[1].f1.size(0), 2); + loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size + (0); + c_domainSldProfiles.set_size(domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(0), 2); for (int32_T i1{0}; i1 < loop_ub; i1++) { - c_domainSldProfiles[i1] = domainSldProfiles[1].f1[i1]; - } - - for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + c_domainSldProfiles[i1] = domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1[i1]; c_domainSldProfiles[i1 + c_domainSldProfiles.size(0)] = - domainSldProfiles[1].f1[i1 + domainSldProfiles[1].f1.size(0) * 2]; + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1[i1 + + domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(0) * + 2]; } - c_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, + b_resampleLayersReIm(b_domainSldProfiles, c_domainSldProfiles, controls->resamPars, r.f1); } @@ -211,49 +207,52 @@ namespace RAT tempLayerSlds[b_i].f1[1] = r; tempAllLayers[b_i].f1[0] = r1; tempAllLayers[b_i].f1[1] = r; - r2.f1.set_size(domainSldProfiles[0].f1.size(0), domainSldProfiles[0]. - f1.size(1)); - loop_ub = domainSldProfiles[0].f1.size(1); + r2.f1.set_size(domainSldProfiles[b_i].f1.size(0), + domainSldProfiles[b_i].f1.size(1)); + loop_ub = domainSldProfiles[b_i].f1.size(1); for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = domainSldProfiles[0].f1.size(0); + b_loop_ub = domainSldProfiles[b_i].f1.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - r2.f1[i2 + r2.f1.size(0) * i1] = domainSldProfiles[0].f1[i2 + - domainSldProfiles[0].f1.size(0) * i1]; + r2.f1[i2 + r2.f1.size(0) * i1] = domainSldProfiles[b_i].f1[i2 + + domainSldProfiles[b_i].f1.size(0) * i1]; } } - r3.f1.set_size(domainSldProfiles[1].f1.size(0), domainSldProfiles[1]. - f1.size(1)); - loop_ub = domainSldProfiles[1].f1.size(1); + r3.f1.set_size(domainSldProfiles[b_i + domainSldProfiles.size(0)]. + f1.size(0), domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(1)); + loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)].f1.size(1); for (int32_T i1{0}; i1 < loop_ub; i1++) { - b_loop_ub = domainSldProfiles[1].f1.size(0); + b_loop_ub = domainSldProfiles[b_i + domainSldProfiles.size(0)]. + f1.size(0); for (int32_T i2{0}; i2 < b_loop_ub; i2++) { - r3.f1[i2 + r3.f1.size(0) * i1] = domainSldProfiles[1].f1[i2 + - domainSldProfiles[1].f1.size(0) * i1]; + r3.f1[i2 + r3.f1.size(0) * i1] = domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1[i2 + domainSldProfiles[b_i + + domainSldProfiles.size(0)].f1.size(0) * i1]; } } tempSldProfiles[b_i].f1[0] = r2; tempSldProfiles[b_i].f1[1] = r3; - b_problemDefCells.set_size(problemDefCells->f2 - [problemDefCells->f2.size(0) * b_i].f1.size(0), problemDefCells-> - f2[problemDefCells->f2.size(0) * b_i].f1.size(1)); - loop_ub = problemDefCells->f2[b_i].f1.size(1) - 1; + b_problemCells.set_size(problemCells->f2[problemCells->f2.size(0) * + b_i].f1.size(0), problemCells->f2[problemCells->f2.size(0) * b_i]. + f1.size(1)); + loop_ub = problemCells->f2[b_i].f1.size(1) - 1; for (int32_T i1{0}; i1 <= loop_ub; i1++) { - b_loop_ub = problemDefCells->f2[b_i].f1.size(0) - 1; + b_loop_ub = problemCells->f2[b_i].f1.size(0) - 1; for (int32_T i2{0}; i2 <= b_loop_ub; i2++) { - b_problemDefCells[i2 + b_problemDefCells.size(0) * i1] = - problemDefCells->f2[b_i].f1[i2 + problemDefCells->f2[b_i]. - f1.size(0) * i1]; + b_problemCells[i2 + b_problemCells.size(0) * i1] = + problemCells->f2[b_i].f1[i2 + problemCells->f2[b_i].f1.size(0) * + i1]; } } - b_dv[0] = problemDefCells->f3[b_i].f1[0]; - b_dv[1] = problemDefCells->f3[b_i].f1[1]; - b_dv1[0] = problemDefCells->f4[b_i].f1[0]; - b_dv1[1] = problemDefCells->f4[b_i].f1[1]; - shiftData(scalefactors[b_i], qzshifts[b_i], problemDef-> - dataPresent[b_i], b_problemDefCells, b_dv, b_dv1, shiftedDat); + b_dv[0] = problemCells->f3[b_i].f1[0]; + b_dv[1] = problemCells->f3[b_i].f1[1]; + b_dv1[0] = problemCells->f4[b_i].f1[0]; + b_dv1[1] = problemCells->f4[b_i].f1[1]; + shiftData(scalefactors[b_i], qzshifts[b_i], problemStruct-> + dataPresent[b_i], b_problemCells, b_dv, b_dv1, shiftedDat); shiftedData[b_i].f1.set_size(shiftedDat.size(0), shiftedDat.size(1)); loop_ub = shiftedDat.size(1); for (int32_T i1{0}; i1 < loop_ub; i1++) { @@ -273,10 +272,10 @@ namespace RAT } } - b_dv[0] = problemDefCells->f4[b_i].f1[0]; - b_dv[1] = problemDefCells->f4[b_i].f1[1]; - b_dv1[0] = problemDefCells->f1[b_i].f1[0]; - b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f4[b_i].f1[0]; + b_dv[1] = problemCells->f4[b_i].f1[1]; + b_dv1[0] = problemCells->f1[b_i].f1[0]; + b_dv1[1] = problemCells->f1[b_i].f1[1]; callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, r4, allRoughs[b_i], resolutionParams[b_i], useImaginary, reflect1, simul1); @@ -289,22 +288,22 @@ namespace RAT } } - b_dv[0] = problemDefCells->f4[b_i].f1[0]; - b_dv[1] = problemDefCells->f4[b_i].f1[1]; - b_dv1[0] = problemDefCells->f1[b_i].f1[0]; - b_dv1[1] = problemDefCells->f1[b_i].f1[1]; + b_dv[0] = problemCells->f4[b_i].f1[0]; + b_dv[1] = problemCells->f4[b_i].f1[1]; + b_dv1[0] = problemCells->f1[b_i].f1[0]; + b_dv1[1] = problemCells->f1[b_i].f1[1]; callReflectivity(bulkIns[b_i], bulkOuts[b_i], b_dv, b_dv1, shiftedDat, r4, allRoughs[b_i], resolutionParams[b_i], useImaginary, reflect2, simul2); applyBackgroundCorrection(reflect1, simul1, shiftedDat, - backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + backgroundParams[b_i], problemStruct->contrastBackgroundsType[b_i]); applyBackgroundCorrection(reflect2, simul2, shiftedDat, - backgroundParams[b_i], problemDef->contrastBackgroundsType[b_i]); + backgroundParams[b_i], problemStruct->contrastBackgroundsType[b_i]); // Calculate the average reflectivities.... averageReflectivity(reflect1, reflect2, simul1, simul2, - problemDef->domainRatio[static_cast - (problemDef->contrastDomainRatios[b_i]) - 1], + problemStruct->domainRatio[static_cast + (problemStruct->contrastDomainRatios[b_i]) - 1], totReflect, simulation[b_i].f1); loop_ub = totReflect.size(0); reflectivity[b_i].f1.set_size(totReflect.size(0), 2); @@ -315,9 +314,9 @@ namespace RAT } } - if (problemDef->dataPresent[b_i] != 0.0) { + if (problemStruct->dataPresent[b_i] != 0.0) { chis[b_i] = chiSquared(shiftedDat, totReflect, static_cast - (problemDef->params.size(1))); + (problemStruct->params.size(1))); } else { chis[b_i] = 0.0; } diff --git a/RAT/single5.h b/RAT/single5.h index 139729ec..dcee3403 100644 --- a/RAT/single5.h +++ b/RAT/single5.h @@ -11,18 +11,13 @@ #define SINGLE5_H // Include files +#include "RATMain_internal_types.h" #include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include -// Type Declarations -namespace RAT -{ - struct cell_14; -} - // Function Declarations namespace RAT { @@ -30,15 +25,15 @@ namespace RAT { namespace customXY { - void b_single(const struct5_T *problemDef, const cell_14 *problemDefCells, + void b_single(const c_struct_T *problemStruct, const cell_11 *problemCells, const struct2_T *controls, ::coder::array &outSsubs, ::coder::array &backgroundParams, :: coder::array &qzshifts, ::coder::array &scalefactors, ::coder::array &bulkIns, :: coder::array &bulkOuts, ::coder::array &resolutionParams, ::coder::array &chis, :: - coder::array &reflectivity, ::coder::array< - cell_wrap_11, 1U> &simulation, ::coder::array &reflectivity, ::coder::array< + cell_wrap_20, 1U> &simulation, ::coder::array &shiftedData, ::coder::array &layerSlds, ::coder::array &domainSldProfiles, ::coder:: array &allLayers, ::coder::array diff --git a/RAT/strcmp.cpp b/RAT/strcmp.cpp index e93ec1f9..62b501d4 100644 --- a/RAT/strcmp.cpp +++ b/RAT/strcmp.cpp @@ -90,7 +90,7 @@ namespace RAT do { exitg1 = 0; if (kstr < 7) { - if (cv1[static_cast(a_data[kstr]) & 127] != cv1[ + if (cv[static_cast(a_data[kstr]) & 127] != cv[ static_cast(b_cv[kstr])]) { exitg1 = 1; } else { @@ -145,7 +145,7 @@ namespace RAT do { exitg1 = 0; if (kstr < 9) { - if (a_data[kstr] != cv[kstr]) { + if (a_data[kstr] != cv1[kstr]) { exitg1 = 1; } else { kstr++; @@ -227,7 +227,7 @@ namespace RAT do { exitg1 = 0; if (kstr < 3) { - if (cv1[static_cast(a_data[kstr]) & 127] != cv1[ + if (cv[static_cast(a_data[kstr]) & 127] != cv[ static_cast(b_cv[kstr])]) { exitg1 = 1; } else { @@ -625,7 +625,7 @@ namespace RAT do { exitg1 = 0; if (kstr < 13) { - if (cv1[static_cast(a_data[kstr]) & 127] != cv1[ + if (cv[static_cast(a_data[kstr]) & 127] != cv[ static_cast(b_cv[kstr])]) { exitg1 = 1; } else { @@ -794,7 +794,7 @@ namespace RAT do { exitg1 = 0; if (kstr < 4) { - if (cv1[static_cast(a_data[kstr]) & 127] != cv1[ + if (cv[static_cast(a_data[kstr]) & 127] != cv[ static_cast(b_cv[kstr])]) { exitg1 = 1; } else { @@ -831,7 +831,7 @@ namespace RAT do { exitg1 = 0; if (kstr <= i - 1) { - if (cv1[static_cast(a->f1[kstr]) & 127] != cv1[ + if (cv[static_cast(a->f1[kstr]) & 127] != cv[ static_cast(b[k].f1[kstr]) & 127]) { exitg1 = 1; } else { diff --git a/RAT/structConstructorHelper.cpp b/RAT/structConstructorHelper.cpp index d8e47d13..f931a836 100644 --- a/RAT/structConstructorHelper.cpp +++ b/RAT/structConstructorHelper.cpp @@ -22,8 +22,8 @@ namespace RAT { namespace internal { - void structConstructorHelper(const cell_wrap_15 *varargin_2, const - cell_wrap_9 *varargin_4, const cell_wrap_15 *varargin_8, ::coder::array< + void structConstructorHelper(const cell_wrap_12 *varargin_2, const + cell_wrap_9 *varargin_4, const cell_wrap_12 *varargin_8, ::coder::array< cell_wrap_8, 1U> &s_ref, ::coder::array &s_sld, real_T * s_chi, ::coder::array &s_data) { @@ -54,14 +54,15 @@ namespace RAT *s_chi = 0.0; } - void structConstructorHelper(const cell_wrap_15 *varargin_2, const - cell_wrap_15 *varargin_4, const cell_wrap_15 *varargin_6, const - cell_wrap_9 *varargin_8, const cell_wrap_17 *varargin_10, ::coder::array< - cell_wrap_8, 1U> &s_refPredInts, ::coder::array + void structConstructorHelper(const cell_wrap_12 *varargin_2, const + cell_wrap_9 *varargin_4, const cell_wrap_12 *varargin_6, const + cell_wrap_9 *varargin_8, const cell_wrap_14 *varargin_10, ::coder::array< + cell_wrap_8, 1U> &s_refPredInts, ::coder::array &s_sldPredInts, ::coder::array &s_refXdata, ::coder:: array &s_sldXdata, real_T s_sampleChi_data[], int32_T *s_sampleChi_size) { + int32_T b_loop_ub; int32_T loop_ub; s_refPredInts.set_size(varargin_2->f1.size(0)); loop_ub = varargin_2->f1.size(0); @@ -69,10 +70,14 @@ namespace RAT s_refPredInts[i] = varargin_2->f1[i]; } - s_sldPredInts.set_size(varargin_4->f1.size(0)); - loop_ub = varargin_4->f1.size(0); + s_sldPredInts.set_size(varargin_4->f1.size(0), varargin_4->f1.size(1)); + loop_ub = varargin_4->f1.size(1); for (int32_T i{0}; i < loop_ub; i++) { - s_sldPredInts[i] = varargin_4->f1[i]; + b_loop_ub = varargin_4->f1.size(0); + for (int32_T i1{0}; i1 < b_loop_ub; i1++) { + s_sldPredInts[i1 + s_sldPredInts.size(0) * i] = varargin_4->f1[i1 + + varargin_4->f1.size(0) * i]; + } } s_refXdata.set_size(varargin_6->f1.size(0)); @@ -84,7 +89,6 @@ namespace RAT s_sldXdata.set_size(varargin_8->f1.size(0), varargin_8->f1.size(1)); loop_ub = varargin_8->f1.size(1); for (int32_T i{0}; i < loop_ub; i++) { - int32_T b_loop_ub; b_loop_ub = varargin_8->f1.size(0); for (int32_T i1{0}; i1 < b_loop_ub; i1++) { s_sldXdata[i1 + s_sldXdata.size(0) * i] = varargin_8->f1[i1 + diff --git a/RAT/structConstructorHelper.h b/RAT/structConstructorHelper.h index ef392cce..f8014177 100644 --- a/RAT/structConstructorHelper.h +++ b/RAT/structConstructorHelper.h @@ -20,8 +20,8 @@ // Type Declarations namespace RAT { - struct cell_wrap_15; - struct cell_wrap_17; + struct cell_wrap_12; + struct cell_wrap_14; } // Function Declarations @@ -31,14 +31,14 @@ namespace RAT { namespace internal { - void structConstructorHelper(const cell_wrap_15 *varargin_2, const - cell_wrap_9 *varargin_4, const cell_wrap_15 *varargin_8, ::coder::array< + void structConstructorHelper(const cell_wrap_12 *varargin_2, const + cell_wrap_9 *varargin_4, const cell_wrap_12 *varargin_8, ::coder::array< cell_wrap_8, 1U> &s_ref, ::coder::array &s_sld, real_T * s_chi, ::coder::array &s_data); - void structConstructorHelper(const cell_wrap_15 *varargin_2, const - cell_wrap_15 *varargin_4, const cell_wrap_15 *varargin_6, const - cell_wrap_9 *varargin_8, const cell_wrap_17 *varargin_10, ::coder::array< - cell_wrap_8, 1U> &s_refPredInts, ::coder::array + void structConstructorHelper(const cell_wrap_12 *varargin_2, const + cell_wrap_9 *varargin_4, const cell_wrap_12 *varargin_6, const + cell_wrap_9 *varargin_8, const cell_wrap_14 *varargin_10, ::coder::array< + cell_wrap_8, 1U> &s_refPredInts, ::coder::array &s_sldPredInts, ::coder::array &s_refXdata, ::coder:: array &s_sldXdata, real_T s_sampleChi_data[], int32_T *s_sampleChi_size); diff --git a/RAT/triggerEvent.cpp b/RAT/triggerEvent.cpp index debbb97e..58796a40 100644 --- a/RAT/triggerEvent.cpp +++ b/RAT/triggerEvent.cpp @@ -35,9 +35,7 @@ namespace RAT coder::array &packedArray, ::coder::array &counts); static void d_packCellArray(const ::coder::array &cellArray, :: coder::array &packedArray, ::coder::array &counts); - static void packCellArray(const ::coder::array &cellArray, :: - coder::array &packedArray, ::coder::array &counts); - static void packCellArray(const ::coder::array &cellArray, :: + static void e_packCellArray(const ::coder::array &cellArray, :: coder::array &packedArray, ::coder::array &counts); static void packCellArray(const ::coder::array &cellArray, :: coder::array &packedArray, ::coder::array &counts); @@ -114,8 +112,8 @@ namespace RAT i = cellArray.size(0); for (int32_T b_i{0}; b_i < i; b_i++) { real_T d; - d = static_cast(cellArray[b_i + cellArray.size(0)].f1.size(0)) * - static_cast(cellArray[b_i + cellArray.size(0)].f1.size(1)); + d = static_cast(cellArray[b_i].f1.size(0)) * static_cast + (cellArray[b_i].f1.size(1)); counts[b_i] = d; rowSize += d; } @@ -138,10 +136,9 @@ namespace RAT i1 = static_cast(start); } - b_rowSize = cellArray[b_i + cellArray.size(0)].f1.size(0) * cellArray[b_i - + cellArray.size(0)].f1.size(1); + b_rowSize = cellArray[b_i].f1.size(0) * cellArray[b_i].f1.size(1); for (int32_T i2{0}; i2 < b_rowSize; i2++) { - packedArray[(i1 + i2) - 1] = cellArray[b_i + cellArray.size(0)].f1[i2]; + packedArray[(i1 + i2) - 1] = cellArray[b_i].f1[i2]; } start = stop; @@ -167,7 +164,7 @@ namespace RAT for (int32_T b_i{0}; b_i < i; b_i++) { real_T d; d = static_cast(cellArray[b_i + cellArray.size(0)].f1.size(0)) * - 3.0; + static_cast(cellArray[b_i + cellArray.size(0)].f1.size(1)); counts[b_i] = d; rowSize += d; } @@ -190,7 +187,8 @@ namespace RAT i1 = static_cast(start); } - b_rowSize = cellArray[b_i + cellArray.size(0)].f1.size(0) * 3; + b_rowSize = cellArray[b_i + cellArray.size(0)].f1.size(0) * cellArray[b_i + + cellArray.size(0)].f1.size(1); for (int32_T i2{0}; i2 < b_rowSize; i2++) { packedArray[(i1 + i2) - 1] = cellArray[b_i + cellArray.size(0)].f1[i2]; } @@ -199,57 +197,7 @@ namespace RAT } } - static void packCellArray(const ::coder::array &cellArray, :: - coder::array &packedArray, ::coder::array &counts) - { - real_T rowSize; - real_T start; - int32_T b_rowSize; - int32_T i; - - // Packs a specified column of a cell array with different sized arrays into a - // single row array and an array of counts for each cell. For the example below - // reflect will be [1, 2, 3, 4, 5, 6, 7] and nReflect will be [3, 4] - // - // [reflect, nReflect] = packCellArray({[1; 2; 3], [4; 5; 6; 7]}, 1); - rowSize = 0.0; - counts.set_size(cellArray.size(0)); - i = cellArray.size(0); - for (int32_T b_i{0}; b_i < i; b_i++) { - real_T d; - d = static_cast(cellArray[b_i].f1.size(0)) * 2.0; - counts[b_i] = d; - rowSize += d; - } - - b_rowSize = static_cast(rowSize); - packedArray.set_size(b_rowSize); - for (i = 0; i < b_rowSize; i++) { - packedArray[i] = 0.0; - } - - start = 1.0; - i = cellArray.size(0); - for (int32_T b_i{0}; b_i < i; b_i++) { - real_T stop; - int32_T i1; - stop = start + counts[b_i]; - if (start > stop - 1.0) { - i1 = 1; - } else { - i1 = static_cast(start); - } - - b_rowSize = cellArray[b_i].f1.size(0) << 1; - for (int32_T i2{0}; i2 < b_rowSize; i2++) { - packedArray[(i1 + i2) - 1] = cellArray[b_i].f1[i2]; - } - - start = stop; - } - } - - static void packCellArray(const ::coder::array &cellArray, :: + static void e_packCellArray(const ::coder::array &cellArray, :: coder::array &packedArray, ::coder::array &counts) { real_T rowSize; @@ -267,7 +215,8 @@ namespace RAT i = cellArray.size(0); for (int32_T b_i{0}; b_i < i; b_i++) { real_T d; - d = static_cast(cellArray[b_i].f1.size(0)) * 3.0; + d = static_cast(cellArray[b_i + cellArray.size(0)].f1.size(0)) * + 3.0; counts[b_i] = d; rowSize += d; } @@ -290,9 +239,9 @@ namespace RAT i1 = static_cast(start); } - b_rowSize = cellArray[b_i].f1.size(0) * 3; + b_rowSize = cellArray[b_i + cellArray.size(0)].f1.size(0) * 3; for (int32_T i2{0}; i2 < b_rowSize; i2++) { - packedArray[(i1 + i2) - 1] = cellArray[b_i].f1[i2]; + packedArray[(i1 + i2) - 1] = cellArray[b_i + cellArray.size(0)].f1[i2]; } start = stop; @@ -317,8 +266,7 @@ namespace RAT i = cellArray.size(0); for (int32_T b_i{0}; b_i < i; b_i++) { real_T d; - d = static_cast(cellArray[b_i].f1.size(0)) * static_cast - (cellArray[b_i].f1.size(1)); + d = static_cast(cellArray[b_i].f1.size(0)) * 2.0; counts[b_i] = d; rowSize += d; } @@ -341,7 +289,7 @@ namespace RAT i1 = static_cast(start); } - b_rowSize = cellArray[b_i].f1.size(0) * cellArray[b_i].f1.size(1); + b_rowSize = cellArray[b_i].f1.size(0) << 1; for (int32_T i2{0}; i2 < b_rowSize; i2++) { packedArray[(i1 + i2) - 1] = cellArray[b_i].f1[i2]; } @@ -355,10 +303,7 @@ namespace RAT helper_not_empty = false; } - void triggerEvent(const ::coder::array &data_f1_f1, const :: - coder::array &data_f1_f3, const ::coder:: - array &data_f1_f5, const ::coder::array< - cell_wrap_8, 2U> &data_f1_f6, const ::coder::array &data_f2, const char_T data_f3_TF_data[], const int32_T data_f3_TF_size[2], const ::coder::array &data_f3_resample, const ::coder::array @@ -392,8 +337,8 @@ namespace RAT // Triggers the event type with the given data. The supported event types are // 'message' and 'plot'. The data for message is a char array while for - // the plot it is a cell array containing the result cell, problem.ssubs - // and problemDef + // the plot it is a cell array containing the result cell, + // contrastParams.ssubs and problemStruct // // triggerEvent('message', 'Hello world'); if (!helper_not_empty) { @@ -418,12 +363,12 @@ namespace RAT boolean_T hasPlotHandler; hasPlotHandler = std::mem_fn(&eventHelper::hasPlotHandler)(helper); if (hasPlotHandler) { - packCellArray(data_f1_f1, reflect, nReflect); + packCellArray(data_f1[0].f1, reflect, nReflect); // reflectivity - packCellArray(data_f1_f3, shiftedData, nShiftedData); - packCellArray(data_f1_f5, sldProfiles, nSldProfiles); - b_packCellArray(data_f1_f6, layers, nLayers); + b_packCellArray(data_f1[2].f1, shiftedData, nShiftedData); + c_packCellArray(data_f1[4].f1, sldProfiles, nSldProfiles); + b_packCellArray(data_f1[5].f1, layers, nLayers); if (coder::internal::j_strcmp(data_f3_TF_data, data_f3_TF_size)) { i = 0; } else { @@ -431,7 +376,7 @@ namespace RAT } if (i == 0) { - c_packCellArray(data_f1_f5, b_sldProfiles2, nSldProfiles2); + d_packCellArray(data_f1[4].f1, b_sldProfiles2, nSldProfiles2); loop_ub = b_sldProfiles2.size(0); sldProfiles2.set_size(b_sldProfiles2.size(0), 1); for (i = 0; i < loop_ub; i++) { @@ -444,7 +389,7 @@ namespace RAT b_nSldProfiles2[i] = nSldProfiles2[i]; } - d_packCellArray(data_f1_f6, b_sldProfiles2, nSldProfiles2); + e_packCellArray(data_f1[5].f1, b_sldProfiles2, nSldProfiles2); loop_ub = b_sldProfiles2.size(0); layers2.set_size(b_sldProfiles2.size(0), 1); for (i = 0; i < loop_ub; i++) { @@ -490,7 +435,7 @@ namespace RAT } std::mem_fn(&eventHelper::updatePlot)(helper, static_cast - (data_f1_f1.size(0)), &(reflect.data())[0], &(nReflect.data())[0], + (data_f1[0].f1.size(0)), &(reflect.data())[0], &(nReflect.data())[0], &(shiftedData.data())[0], &(nShiftedData.data())[0], &(sldProfiles.data())[0], &(nSldProfiles.data())[0], &(layers.data()) [0], &(nLayers.data())[0], &sldProfiles2[0], &b_nSldProfiles2[0], diff --git a/RAT/triggerEvent.h b/RAT/triggerEvent.h index 5734cc57..01085973 100644 --- a/RAT/triggerEvent.h +++ b/RAT/triggerEvent.h @@ -11,20 +11,22 @@ #define TRIGGEREVENT_H // Include files -#include "RATMain_types.h" #include "rtwtypes.h" #include "coder_array.h" #include #include +// Type Declarations +namespace RAT +{ + struct cell_wrap_9; +} + // Function Declarations namespace RAT { void helper_not_empty_init(); - void triggerEvent(const ::coder::array &data_f1_f1, const :: - coder::array &data_f1_f3, const ::coder:: - array &data_f1_f5, const ::coder::array< - cell_wrap_8, 2U> &data_f1_f6, const ::coder::array &data_f2, const char_T data_f3_TF_data[], const int32_T data_f3_TF_size[2], const ::coder::array &data_f3_resample, const ::coder::array diff --git a/RAT/unpackParams.cpp b/RAT/unpackParams.cpp index d8fef2e1..aa9bce41 100644 --- a/RAT/unpackParams.cpp +++ b/RAT/unpackParams.cpp @@ -10,14 +10,14 @@ // Include files #include "unpackParams.h" -#include "RATMain_types.h" +#include "RATMain_internal_types.h" #include "rt_nonfinite.h" #include "coder_array.h" // Function Definitions namespace RAT { - void unpackParams(struct5_T *problemDef, const ::coder::array + void unpackParams(c_struct_T *problemStruct, const ::coder::array &controls_checks_fitParam, const ::coder::array &controls_checks_fitBackgroundParam, const ::coder::array< real_T, 2U> &controls_checks_fitQzshift, const ::coder:: @@ -41,7 +41,7 @@ namespace RAT unpacked_counter = 1U; packed_counter = 1U; uppars_counter = 0; - unnamed_idx_1 = problemDef->params.size(1); + unnamed_idx_1 = problemStruct->params.size(1); uppars.set_size(1, unnamed_idx_1); for (i = 0; i < unnamed_idx_1; i++) { uppars[i] = 0.0; @@ -50,26 +50,26 @@ namespace RAT i = controls_checks_fitParam.size(1); for (int32_T b_i{0}; b_i < i; b_i++) { if (controls_checks_fitParam[b_i] == 1.0) { - uppars[uppars_counter] = problemDef->fitParams[static_cast + uppars[uppars_counter] = problemStruct->fitParams[static_cast (unpacked_counter) - 1]; unpacked_counter++; uppars_counter++; } else { - uppars[uppars_counter] = problemDef->otherParams[static_cast + uppars[uppars_counter] = problemStruct->otherParams[static_cast (packed_counter) - 1]; packed_counter++; uppars_counter++; } } - problemDef->params.set_size(1, uppars.size(1)); + problemStruct->params.set_size(1, uppars.size(1)); unnamed_idx_1 = uppars.size(1); for (i = 0; i < unnamed_idx_1; i++) { - problemDef->params[i] = uppars[i]; + problemStruct->params[i] = uppars[i]; } // Also the backgrounds - unnamed_idx_1 = problemDef->backgroundParams.size(1); + unnamed_idx_1 = problemStruct->backgroundParams.size(1); uppars.set_size(1, unnamed_idx_1); for (i = 0; i < unnamed_idx_1; i++) { uppars[i] = 0.0; @@ -79,26 +79,26 @@ namespace RAT i = controls_checks_fitBackgroundParam.size(1); for (int32_T b_i{0}; b_i < i; b_i++) { if (controls_checks_fitBackgroundParam[b_i] == 1.0) { - uppars[uppars_counter] = problemDef->fitParams[static_cast + uppars[uppars_counter] = problemStruct->fitParams[static_cast (unpacked_counter) - 1]; unpacked_counter++; uppars_counter++; } else { - uppars[uppars_counter] = problemDef->otherParams[static_cast + uppars[uppars_counter] = problemStruct->otherParams[static_cast (packed_counter) - 1]; packed_counter++; uppars_counter++; } } - problemDef->backgroundParams.set_size(1, uppars.size(1)); + problemStruct->backgroundParams.set_size(1, uppars.size(1)); unnamed_idx_1 = uppars.size(1); for (i = 0; i < unnamed_idx_1; i++) { - problemDef->backgroundParams[i] = uppars[i]; + problemStruct->backgroundParams[i] = uppars[i]; } // Scalefactors - unnamed_idx_1 = problemDef->scalefactors.size(1); + unnamed_idx_1 = problemStruct->scalefactors.size(1); uppars.set_size(1, unnamed_idx_1); for (i = 0; i < unnamed_idx_1; i++) { uppars[i] = 0.0; @@ -108,26 +108,26 @@ namespace RAT i = controls_checks_fitScalefactor.size(1); for (int32_T b_i{0}; b_i < i; b_i++) { if (controls_checks_fitScalefactor[b_i] == 1.0) { - uppars[uppars_counter] = problemDef->fitParams[static_cast + uppars[uppars_counter] = problemStruct->fitParams[static_cast (unpacked_counter) - 1]; unpacked_counter++; uppars_counter++; } else { - uppars[uppars_counter] = problemDef->otherParams[static_cast + uppars[uppars_counter] = problemStruct->otherParams[static_cast (packed_counter) - 1]; packed_counter++; uppars_counter++; } } - problemDef->scalefactors.set_size(1, uppars.size(1)); + problemStruct->scalefactors.set_size(1, uppars.size(1)); unnamed_idx_1 = uppars.size(1); for (i = 0; i < unnamed_idx_1; i++) { - problemDef->scalefactors[i] = uppars[i]; + problemStruct->scalefactors[i] = uppars[i]; } // qzshifts - unnamed_idx_1 = problemDef->qzshifts.size(1); + unnamed_idx_1 = problemStruct->qzshifts.size(1); uppars.set_size(1, unnamed_idx_1); for (i = 0; i < unnamed_idx_1; i++) { uppars[i] = 0.0; @@ -137,26 +137,26 @@ namespace RAT i = controls_checks_fitQzshift.size(1); for (int32_T b_i{0}; b_i < i; b_i++) { if (controls_checks_fitQzshift[b_i] == 1.0) { - uppars[uppars_counter] = problemDef->fitParams[static_cast + uppars[uppars_counter] = problemStruct->fitParams[static_cast (unpacked_counter) - 1]; unpacked_counter++; uppars_counter++; } else { - uppars[uppars_counter] = problemDef->otherParams[static_cast + uppars[uppars_counter] = problemStruct->otherParams[static_cast (packed_counter) - 1]; packed_counter++; uppars_counter++; } } - problemDef->qzshifts.set_size(1, uppars.size(1)); + problemStruct->qzshifts.set_size(1, uppars.size(1)); unnamed_idx_1 = uppars.size(1); for (i = 0; i < unnamed_idx_1; i++) { - problemDef->qzshifts[i] = uppars[i]; + problemStruct->qzshifts[i] = uppars[i]; } // Bulk In - unnamed_idx_1 = problemDef->bulkIn.size(1); + unnamed_idx_1 = problemStruct->bulkIn.size(1); uppars.set_size(1, unnamed_idx_1); for (i = 0; i < unnamed_idx_1; i++) { uppars[i] = 0.0; @@ -166,26 +166,26 @@ namespace RAT i = controls_checks_fitBulkIn.size(1); for (int32_T b_i{0}; b_i < i; b_i++) { if (controls_checks_fitBulkIn[b_i] == 1.0) { - uppars[uppars_counter] = problemDef->fitParams[static_cast + uppars[uppars_counter] = problemStruct->fitParams[static_cast (unpacked_counter) - 1]; unpacked_counter++; uppars_counter++; } else { - uppars[uppars_counter] = problemDef->otherParams[static_cast + uppars[uppars_counter] = problemStruct->otherParams[static_cast (packed_counter) - 1]; packed_counter++; uppars_counter++; } } - problemDef->bulkIn.set_size(1, uppars.size(1)); + problemStruct->bulkIn.set_size(1, uppars.size(1)); unnamed_idx_1 = uppars.size(1); for (i = 0; i < unnamed_idx_1; i++) { - problemDef->bulkIn[i] = uppars[i]; + problemStruct->bulkIn[i] = uppars[i]; } // Bulk Out - unnamed_idx_1 = problemDef->bulkOut.size(1); + unnamed_idx_1 = problemStruct->bulkOut.size(1); uppars.set_size(1, unnamed_idx_1); for (i = 0; i < unnamed_idx_1; i++) { uppars[i] = 0.0; @@ -195,26 +195,26 @@ namespace RAT i = controls_checks_fitBulkOut.size(1); for (int32_T b_i{0}; b_i < i; b_i++) { if (controls_checks_fitBulkOut[b_i] == 1.0) { - uppars[uppars_counter] = problemDef->fitParams[static_cast + uppars[uppars_counter] = problemStruct->fitParams[static_cast (unpacked_counter) - 1]; unpacked_counter++; uppars_counter++; } else { - uppars[uppars_counter] = problemDef->otherParams[static_cast + uppars[uppars_counter] = problemStruct->otherParams[static_cast (packed_counter) - 1]; packed_counter++; uppars_counter++; } } - problemDef->bulkOut.set_size(1, uppars.size(1)); + problemStruct->bulkOut.set_size(1, uppars.size(1)); unnamed_idx_1 = uppars.size(1); for (i = 0; i < unnamed_idx_1; i++) { - problemDef->bulkOut[i] = uppars[i]; + problemStruct->bulkOut[i] = uppars[i]; } // Resolutions - unnamed_idx_1 = problemDef->resolutionParams.size(1); + unnamed_idx_1 = problemStruct->resolutionParams.size(1); uppars.set_size(1, unnamed_idx_1); for (i = 0; i < unnamed_idx_1; i++) { uppars[i] = 0.0; @@ -224,26 +224,26 @@ namespace RAT i = controls_checks_fitResolutionParam.size(1); for (int32_T b_i{0}; b_i < i; b_i++) { if (controls_checks_fitResolutionParam[b_i] == 1.0) { - uppars[uppars_counter] = problemDef->fitParams[static_cast + uppars[uppars_counter] = problemStruct->fitParams[static_cast (unpacked_counter) - 1]; unpacked_counter++; uppars_counter++; } else { - uppars[uppars_counter] = problemDef->otherParams[static_cast + uppars[uppars_counter] = problemStruct->otherParams[static_cast (packed_counter) - 1]; packed_counter++; uppars_counter++; } } - problemDef->resolutionParams.set_size(1, uppars.size(1)); + problemStruct->resolutionParams.set_size(1, uppars.size(1)); unnamed_idx_1 = uppars.size(1); for (i = 0; i < unnamed_idx_1; i++) { - problemDef->resolutionParams[i] = uppars[i]; + problemStruct->resolutionParams[i] = uppars[i]; } // Domain Ratios - unnamed_idx_1 = problemDef->domainRatio.size(1); + unnamed_idx_1 = problemStruct->domainRatio.size(1); uppars.set_size(1, unnamed_idx_1); for (i = 0; i < unnamed_idx_1; i++) { uppars[i] = 0.0; @@ -253,22 +253,22 @@ namespace RAT i = controls_checks_fitDomainRatio.size(1); for (int32_T b_i{0}; b_i < i; b_i++) { if (controls_checks_fitDomainRatio[b_i] == 1.0) { - uppars[uppars_counter] = problemDef->fitParams[static_cast + uppars[uppars_counter] = problemStruct->fitParams[static_cast (unpacked_counter) - 1]; unpacked_counter++; uppars_counter++; } else { - uppars[uppars_counter] = problemDef->otherParams[static_cast + uppars[uppars_counter] = problemStruct->otherParams[static_cast (packed_counter) - 1]; packed_counter++; uppars_counter++; } } - problemDef->domainRatio.set_size(1, uppars.size(1)); + problemStruct->domainRatio.set_size(1, uppars.size(1)); unnamed_idx_1 = uppars.size(1); for (i = 0; i < unnamed_idx_1; i++) { - problemDef->domainRatio[i] = uppars[i]; + problemStruct->domainRatio[i] = uppars[i]; } } } diff --git a/RAT/unpackParams.h b/RAT/unpackParams.h index 8ea53381..137a4ef7 100644 --- a/RAT/unpackParams.h +++ b/RAT/unpackParams.h @@ -19,13 +19,13 @@ // Type Declarations namespace RAT { - struct struct5_T; + struct c_struct_T; } // Function Declarations namespace RAT { - void unpackParams(struct5_T *problemDef, const ::coder::array + void unpackParams(c_struct_T *problemStruct, const ::coder::array &controls_checks_fitParam, const ::coder::array &controls_checks_fitBackgroundParam, const ::coder::array< real_T, 2U> &controls_checks_fitQzshift, const ::coder:: diff --git a/alloyDomains.cpp b/alloyDomains.cpp new file mode 100644 index 00000000..564cae4e --- /dev/null +++ b/alloyDomains.cpp @@ -0,0 +1,48 @@ +//alloyDomains.cpp + +#include + +#if defined(_WIN32) || defined(_WIN64) +#define LIB_EXPORT __declspec(dllexport) +#else +#define LIB_EXPORT +#endif + +// We user extern "C" decorator to avoid name mangling.... +extern "C" { + + LIB_EXPORT void alloyDomains(std::vector& params, std::vector& bulkIn, std::vector& bulkOut, int contrast, int domain, std::vector& output, double* outputSize, double* rough) + { + double subRough = params[0]; + double alloyThick = params[1]; + double alloySLDup = params[2]; + double alloySLDdn = params[3]; + double alloyRough = params[4]; + double goldThick = params[5]; + double goldSLD = params[6]; + double goldRough = params[7]; + + // Make the layers + if (domain == 0) { + // alloyUp + output.push_back(alloyThick); + output.push_back(alloySLDup); + output.push_back(alloyRough); + + }else { + // alloyDn + output.push_back(alloyThick); + output.push_back(alloySLDdn); + output.push_back(alloyRough); + } + // Gold + output.push_back(goldThick); + output.push_back(goldSLD); + output.push_back(goldRough); + + *rough = subRough; + + outputSize[0] = 2; // row - Necessary to ouptut how many layers in stack + outputSize[1] = 3; // col - Should be different depending on calculation + } +} // extern "C" \ No newline at end of file diff --git a/alloyDomains.m b/alloyDomains.m new file mode 100644 index 00000000..585eb0db --- /dev/null +++ b/alloyDomains.m @@ -0,0 +1,29 @@ + +function [output,subRough] = alloyDomains(params,bulkIn,bulkOut,contrast,domain) + +% Simple custom model for testing incoherent summing... +% Simple two layer of permalloy / gold, with up/down domains.. + +% Split up the parameters.... +subRough = params(1); +alloyThick = params(2); +alloySLDup = params(3); +alloySLDdn = params(4); +alloyRough = params(5); +goldThick = params(6); +goldSLD = params(7); +goldRough = params(8); + +% Make the layers.... +alloyUp = [alloyThick, alloySLDup, alloyRough]; +alloyDn = [alloyThick, alloySLDdn, alloyRough]; +gold = [goldThick, goldSLD, goldRough]; + +% Make the model dependiong on which domain we are looking at.. +if domain==1 + output = [alloyUp ; gold]; +else + output = [alloyDn ; gold]; +end + +end \ No newline at end of file diff --git a/alloyDomains.py b/alloyDomains.py new file mode 100644 index 00000000..7cbe771a --- /dev/null +++ b/alloyDomains.py @@ -0,0 +1,29 @@ +# alloyDomains.py +import numpy as np + +def alloyDomains(params, bulk_in, bulk_out, contrast, domain): + # Simple custom model for testing incoherent summing... + # Simple two layer of permalloy / gold, with up/down domains.. + + # Split up the parameters.... + subRough = params[0] + alloyThick = params[1] + alloySLDup = params[2] + alloySLDdn = params[3] + alloyRough = params[4] + goldThick = params[5] + goldSLD = params[6] + goldRough = params[7] + + # Make the layers.... + alloyUp = [alloyThick, alloySLDup, alloyRough] + alloyDn = [alloyThick, alloySLDdn, alloyRough] + gold = [goldThick, goldSLD, goldRough] + + # Make the model dependiong on which domain we are looking at.. + if domain == 0: + output = [alloyUp, gold] + else: + output = [alloyDn, gold] + + return output, subRough diff --git a/customBilayer.m b/customBilayer.m new file mode 100644 index 00000000..eea1ee6e --- /dev/null +++ b/customBilayer.m @@ -0,0 +1,66 @@ +%customBilayer.m +function [output, sub_rough] = customBilayer(params,bulk_in,bulk_out,contrast) + + sub_rough = params(1); + oxide_thick = params(2); + oxide_hydration = params(3); + lipidAPM = params(4); + headHydration = params(5); + bilayerHydration = params(6); + bilayerRough = params(7); + waterThick = params(8); + + % We have a constant SLD for the bilayer + oxide_SLD = 3.41e-6; + + % Now make the lipid layers.. + % Use known lipid volume and compositions + % to make the layers + + % define all the neutron b's. + bc = 0.6646e-4; %Carbon + bo = 0.5843e-4; %Oxygen + bh = -0.3739e-4; %Hydrogen + bp = 0.513e-4; %Phosphorus + bn = 0.936e-4; %Nitrogen + bd = 0.6671e-4; %Deuterium + + % Now make the lipid groups.. + COO = (4*bo) + (2*bc); + GLYC = (3*bc) + (5*bh); + CH3 = (2*bc) + (6*bh); + PO4 = (1*bp) + (4*bo); + CH2 = (1*bc) + (2*bh); + CHOL = (5*bc) + (12*bh) + (1*bn); + + % Group these into heads and tails: + Head = CHOL + PO4 + GLYC + COO; + Tails = (34*CH2) + (2*CH3); + + % We need volumes for each. + % Use literature values: + vHead = 319; + vTail = 782; + + % we use the volumes to calculate the SLD's + SLDhead = Head / vHead; + SLDtail = Tails / vTail; + + % We calculate the layer thickness' from + % the volumes and the APM... + headThick = vHead / lipidAPM; + tailThick = vTail / lipidAPM; + + % Manually deal with hydration for layers in + % this example. + oxSLD = (oxide_hydration * bulk_out(contrast)) + ((1 - oxide_hydration) * oxide_SLD); + headSLD = (headHydration * bulk_out(contrast)) + ((1 - headHydration) * SLDhead); + tailSLD = (bilayerHydration * bulk_out(contrast)) + ((1 - bilayerHydration) * SLDtail); + + % Make the layers + oxide = [oxide_thick oxSLD sub_rough]; + water = [waterThick bulk_out(contrast) bilayerRough]; + head = [headThick headSLD bilayerRough]; + tail = [tailThick tailSLD bilayerRough]; + + output = [oxide ; water ; head ; tail ; tail ; head]; diff --git a/customBilayer.py b/customBilayer.py new file mode 100644 index 00000000..86a1f378 --- /dev/null +++ b/customBilayer.py @@ -0,0 +1,73 @@ +# customBilayer.py +import numpy as np + +def customBilayer(params, bulk_in, bulk_out, contrast): + params = np.array(params) + bulk_in = np.array(bulk_in) + bulk_out = np.array(bulk_out) + + sub_rough = params[0] + oxide_thick = params[1] + oxide_hydration = params[2] + lipidAPM = params[3] + headHydration = params[4] + bilayerHydration = params[5] + bilayerRough = params[6] + waterThick = params[7] + + # We have a constant SLD for the bilayer + oxide_SLD = 3.41e-6 + + # Now make the lipid layers.. + # Use known lipid volume and compositions + # to make the layers + + # define all the neutron b's. + bc = 0.6646e-4 # Carbon + bo = 0.5843e-4 # Oxygen + bh = -0.3739e-4 # Hydrogen + bp = 0.513e-4 # Phosphorus + bn = 0.936e-4 # Nitrogen + bd = 0.6671e-4 # Deuterium + + # Now make the lipid groups.. + COO = (4*bo) + (2*bc) + GLYC = (3*bc) + (5*bh) + CH3 = (2*bc) + (6*bh) + PO4 = (1*bp) + (4*bo) + CH2 = (1*bc) + (2*bh) + CHOL = (5*bc) + (12*bh) + (1*bn) + + # Group these into heads and tails: + Head = CHOL + PO4 + GLYC + COO + Tails = (34*CH2) + (2*CH3) + + # We need volumes for each. + # Use literature values: + vHead = 319 + vTail = 782 + + # we use the volumes to calculate the SLD's + SLDhead = Head / vHead + SLDtail = Tails / vTail + + # We calculate the layer thickness' from + # the volumes and the APM... + headThick = vHead / lipidAPM + tailThick = vTail / lipidAPM + + # Manually deal with hydration for layers in + # this example. + oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD) + headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead) + tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail) + + # Make the layers + oxide = [oxide_thick, oxSLD, sub_rough] + water = [waterThick, bulk_out[contrast], bilayerRough] + head = [headThick, headSLD, bilayerRough] + tail = [tailThick, tailSLD, bilayerRough] + + output = np.array([oxide, water, head, tail, tail, head]) + + return output, sub_rough diff --git a/data/data1.csv b/data/dspc_bilayer/data1.csv similarity index 100% rename from data/data1.csv rename to data/dspc_bilayer/data1.csv diff --git a/data/data2.csv b/data/dspc_bilayer/data2.csv similarity index 100% rename from data/data2.csv rename to data/dspc_bilayer/data2.csv diff --git a/data/dspc_custom/data1.csv b/data/dspc_custom/data1.csv new file mode 100644 index 00000000..1856395a --- /dev/null +++ b/data/dspc_custom/data1.csv @@ -0,0 +1,146 @@ +0.0057118,0.80913,0.21163,0.00028795 +0.0058691,1.0752,0.23874,0.0002962 +0.0060315,1.0755,0.18897,0.00030471 +0.0061994,1.2951,0.22787,0.00031349 +0.0063727,1.3213,0.19994,0.00032256 +0.0065517,0.99676,0.12718,0.00033191 +0.0067366,1.3087,0.16472,0.00034156 +0.0069274,0.94947,0.097342,0.00035151 +0.0071244,0.98951,0.088681,0.00036178 +0.0073278,1.0361,0.080311,0.00037236 +0.0075376,0.97293,0.066768,0.00038328 +0.0077542,1.035,0.059054,0.00039454 +0.0079777,0.94479,0.049823,0.00040615 +0.0082083,1.0434,0.048259,0.00041813 +0.0084461,1.0045,0.039538,0.00043047 +0.0086915,0.9574,0.033601,0.0004432 +0.0089447,0.92857,0.029145,0.00045633 +0.0092057,0.95709,0.026996,0.00046986 +0.009475,0.96495,0.024872,0.00048381 +0.0097527,1.0356,0.024179,0.00049819 +0.010039,0.96068,0.020667,0.00051301 +0.010334,0.98929,0.019574,0.00052829 +0.010639,1.0348,0.019004,0.00054404 +0.010953,1.0228,0.017656,0.00056028 +0.011277,1.021,0.016143,0.00057701 +0.01161,1.0071,0.014936,0.00059426 +0.011954,0.99918,0.014062,0.00061204 +0.012309,1.0089,0.013298,0.00063036 +0.012675,1.0072,0.012407,0.00064925 +0.013052,0.98556,0.011377,0.00066871 +0.01344,0.98748,0.010934,0.00068877 +0.013841,0.98214,0.010377,0.00070944 +0.014254,0.87823,0.0091905,0.00073075 +0.014679,0.5477,0.0063914,0.00075271 +0.015118,0.29895,0.0042078,0.00077534 +0.01557,0.20403,0.0032352,0.00079865 +0.016036,0.15495,0.0026677,0.00082269 +0.016516,0.12663,0.0023018,0.00084745 +0.017011,0.092231,0.0019088,0.00087297 +0.017521,0.076761,0.0016965,0.00089927 +0.018046,0.062979,0.0014926,0.00092637 +0.018588,0.054176,0.0013568,0.0009543 +0.018959,0.049216,0.005119,0.0009825 +0.019517,0.033476,0.0027462,0.0010118 +0.020093,0.030784,0.0022798,0.001042 +0.020687,0.028541,0.0019449,0.0010732 +0.021299,0.026371,0.0017941,0.0011053 +0.02193,0.021513,0.0011848,0.0011384 +0.02258,0.018216,0.00090338,0.0011725 +0.023251,0.013495,0.00059985,0.0012076 +0.023942,0.014918,0.00061434,0.0012439 +0.024655,0.011625,0.00043752,0.0012812 +0.025389,0.010568,0.00038864,0.0013197 +0.026146,0.009357,0.00032322,0.0013594 +0.026926,0.0083579,0.00027507,0.0014003 +0.027731,0.0071568,0.00023078,0.0014424 +0.02856,0.0064795,0.00020002,0.0014859 +0.029414,0.0053461,0.00016428,0.0015306 +0.030295,0.0050876,0.00014855,0.0015768 +0.031202,0.004162,0.00012079,0.0016243 +0.032137,0.0037583,0.00010698,0.0016734 +0.033101,0.0033047,9.3559e-05,0.0017239 +0.034095,0.0030501,8.4502e-05,0.0017759 +0.035118,0.002803,7.6113e-05,0.0018296 +0.036173,0.0025113,6.6973e-05,0.0018849 +0.03726,0.0022857,6.0845e-05,0.0019419 +0.038381,0.0020586,5.3916e-05,0.0020006 +0.039535,0.0018433,4.8078e-05,0.0020612 +0.040725,0.0016424,4.3597e-05,0.0021236 +0.04195,0.0016172,4.1052e-05,0.0021879 +0.043214,0.0013918,3.5466e-05,0.0022542 +0.044515,0.0013502,3.3549e-05,0.0023225 +0.045856,0.0012032,3.0163e-05,0.002393 +0.047238,0.001153,2.8017e-05,0.0024656 +0.048662,0.0011496,2.68e-05,0.0025404 +0.05013,0.00099878,2.3916e-05,0.0026176 +0.051642,0.00090928,2.2253e-05,0.0026971 +0.052362,0.00093364,7.4057e-05,0.0026466 +0.053931,0.00085039,5.3373e-05,0.0027267 +0.055549,0.0007389,4.183e-05,0.0028093 +0.057216,0.00080543,4.0271e-05,0.0028944 +0.058934,0.00066525,3.0974e-05,0.0029822 +0.060705,0.00068005,2.8859e-05,0.0030727 +0.062529,0.00062689,2.3624e-05,0.0031661 +0.064409,0.00061871,2.139e-05,0.0032623 +0.066347,0.00057996,1.8549e-05,0.0033615 +0.068343,0.00057708,1.7363e-05,0.0034638 +0.070401,0.00047824,1.413e-05,0.0035693 +0.072521,0.00045306,1.2523e-05,0.0036781 +0.074705,0.00044581,1.1641e-05,0.0037903 +0.076956,0.00040641,1.0238e-05,0.003906 +0.079275,0.00037577,9.1872e-06,0.0040253 +0.081665,0.00037196,8.6233e-06,0.0041484 +0.084128,0.00032986,7.5105e-06,0.0042754 +0.086665,0.00030196,6.6373e-06,0.0044064 +0.08928,0.00028539,6.1e-06,0.0045415 +0.091974,0.00026766,5.5463e-06,0.0046809 +0.09475,0.00024604,5.0224e-06,0.0048248 +0.09761,0.00023099,4.5376e-06,0.0049732 +0.10056,0.000206,4.0827e-06,0.0051263 +0.10359,0.00018355,3.6626e-06,0.0052844 +0.10672,0.00015789,3.176e-06,0.0054476 +0.10995,0.0001401,2.8324e-06,0.005616 +0.11327,0.00012388,2.5242e-06,0.0057899 +0.11669,0.00010764,2.233e-06,0.0059694 +0.12022,9.1264e-05,1.9598e-06,0.0061548 +0.12385,7.7687e-05,1.7269e-06,0.0063462 +0.12759,6.6643e-05,1.5243e-06,0.006544 +0.13145,5.4644e-05,1.3232e-06,0.0067482 +0.13542,4.6118e-05,1.1597e-06,0.0069593 +0.13952,3.6927e-05,1.0042e-06,0.0071773 +0.14374,2.8406e-05,8.6519e-07,0.0074027 +0.14808,2.1887e-05,7.4033e-07,0.0076357 +0.15256,1.524e-05,6.1526e-07,0.0078765 +0.15717,1.1539e-05,5.3438e-07,0.0081256 +0.16193,7.3846e-06,4.4587e-07,0.0083832 +0.16682,4.8089e-06,3.7568e-07,0.0086496 +0.17187,3.1754e-06,3.272e-07,0.0089254 +0.17707,2.3124e-06,2.964e-07,0.0092107 +0.18243,5.9916e-07,2.3989e-07,0.0095061 +0.18795,2.2964e-07,2.3136e-07,0.009812 +0.19363,5.1747e-07,2.4632e-07,0.010129 +0.19949,9.1981e-07,2.547e-07,0.010457 +0.20553,8.5905e-07,2.5007e-07,0.010797 +0.21175,7.5717e-07,2.6728e-07,0.01115 +0.21815,1.2167e-06,2.6304e-07,0.011515 +0.22475,8.7884e-07,2.4686e-07,0.011895 +0.23156,8.6619e-07,2.5636e-07,0.012288 +0.23856,1.2552e-07,2.4662e-07,0.012697 +0.24578,6.9057e-07,2.7196e-07,0.013121 +0.25322,1.1345e-06,2.8793e-07,0.013561 +0.26088,1.0345e-06,2.6218e-07,0.014019 +0.26878,4.5589e-07,2.2887e-07,0.014495 +0.27692,3.3247e-07,2.4888e-07,0.01499 +0.2853,9.8265e-07,2.4589e-07,0.015505 +0.29393,2.0578e-07,2.3722e-07,0.016041 +0.30283,-2.5061e-07,2.2853e-07,0.0166 +0.312,1.2115e-07,2.1632e-07,0.017181 +0.32144,6.3574e-07,2.5362e-07,0.017787 +0.33117,4.7038e-07,2.6211e-07,0.018419 +0.34119,9.1473e-08,2.6771e-07,0.019079 +0.35152,-5.5708e-08,2.593e-07,0.019767 +0.36216,1.147e-06,2.9303e-07,0.020486 +0.37313,1.3574e-06,3.0051e-07,0.021237 +0.38442,3.4657e-07,3.467e-07,0.022023 +0.39606,1.6604e-06,3.6502e-07,0.022844 diff --git a/data/dspc_custom/data2.csv b/data/dspc_custom/data2.csv new file mode 100644 index 00000000..5be2a9e2 --- /dev/null +++ b/data/dspc_custom/data2.csv @@ -0,0 +1,97 @@ +0.0076029,0.0062655,0.0038663,0.00040889 +0.007894,0.0069654,0.003187,0.00042485 +0.0081974,0.0082745,0.003134,0.00044148 +0.0085137,0.0057798,0.0022367,0.0004588 +0.0088432,0.0035195,0.001416,0.00047683 +0.0091865,0.0077421,0.0017487,0.00049561 +0.0095441,0.0047236,0.0012403,0.00051516 +0.0099167,0.0030356,0.00086974,0.00053552 +0.010305,0.003415,0.00081503,0.00055671 +0.010709,0.0054965,0.00093727,0.00057878 +0.01113,0.0045413,0.00076479,0.00060175 +0.011568,0.0028372,0.00054933,0.00062566 +0.012024,0.0031035,0.00052609,0.00065055 +0.012499,0.002672,0.00045092,0.00067645 +0.012994,0.0025145,0.0003969,0.00070341 +0.013509,0.0028125,0.00039068,0.00073147 +0.014045,0.002698,0.00035172,0.00076068 +0.014603,0.0023755,0.00031076,0.00079107 +0.015183,0.002494,0.00029623,0.00082271 +0.015788,0.0021612,0.00025995,0.00085563 +0.016417,0.0017002,0.00022356,0.00088988 +0.017071,0.001607,0.00020864,0.00092553 +0.017753,0.0017224,0.00020812,0.00096263 +0.018462,0.0015332,0.00019088,0.0010012 +0.0192,0.0018212,0.0002031,0.0010414 +0.019968,0.0011565,0.00015702,0.0010832 +0.020767,0.0012404,0.00016011,0.0011267 +0.021598,0.0011897,0.0001589,0.001172 +0.022391,0.0010312,0.00011368,0.001231 +0.023284,0.00081551,8.6663e-05,0.0012805 +0.024214,0.0009776,8.5735e-05,0.0013321 +0.025183,0.00075386,6.647e-05,0.0013858 +0.026191,0.00077278,6.0941e-05,0.0014417 +0.027241,0.00076965,5.5878e-05,0.0014999 +0.028334,0.00084815,5.3499e-05,0.0015605 +0.029473,0.00063788,4.1181e-05,0.0016236 +0.030658,0.00058606,3.5868e-05,0.0016893 +0.031892,0.00052866,3.1423e-05,0.0017577 +0.033176,0.00047636,2.7461e-05,0.0018289 +0.034513,0.00050641,2.6685e-05,0.001903 +0.035905,0.00045356,2.2688e-05,0.0019802 +0.037355,0.00042316,2.0737e-05,0.0020606 +0.038863,0.0004082,1.8701e-05,0.0021442 +0.040433,0.00036221,1.6715e-05,0.0022314 +0.042068,0.00035441,1.5501e-05,0.0023221 +0.043769,0.00030534,1.3683e-05,0.0024165 +0.04554,0.0003157,1.306e-05,0.0025149 +0.047383,0.00026957,1.1336e-05,0.0026173 +0.049302,0.00026205,1.0508e-05,0.0027239 +0.051299,0.0002268,9.62e-06,0.002835 +0.053377,0.00023185,9.1028e-06,0.0029506 +0.055541,0.00020148,8.1413e-06,0.003071 +0.057792,0.00018161,7.6025e-06,0.0031964 +0.060135,0.00018774,7.4695e-06,0.0033271 +0.062071,0.00017184,9.7954e-06,0.0033352 +0.064577,0.000163,8.393e-06,0.0034712 +0.067187,0.0001529,7.2557e-06,0.0036128 +0.069903,0.00012821,6.0878e-06,0.0037603 +0.072729,0.00011498,5.2217e-06,0.0039141 +0.075672,0.00011787,4.6717e-06,0.0040742 +0.078735,0.00010904,4.1646e-06,0.0042411 +0.081923,9.6409e-05,3.5777e-06,0.004415 +0.085241,8.1921e-05,3.0563e-06,0.0045963 +0.088694,7.5479e-05,2.7418e-06,0.0047852 +0.092289,7.0579e-05,2.4511e-06,0.0049821 +0.09603,6.131e-05,2.1459e-06,0.0051874 +0.099924,5.9189e-05,1.9494e-06,0.0054014 +0.10398,4.8626e-05,1.6885e-06,0.0056247 +0.10819,4.2236e-05,1.4473e-06,0.0058574 +0.11258,3.4461e-05,1.2585e-06,0.0061003 +0.11715,2.8862e-05,1.1169e-06,0.0063536 +0.12191,2.3232e-05,9.5792e-07,0.006618 +0.12686,1.9011e-05,8.5326e-07,0.0068939 +0.13201,1.5334e-05,7.5287e-07,0.0071819 +0.13736,1.1405e-05,6.5758e-07,0.0074827 +0.14294,8.7894e-06,6.0684e-07,0.0077968 +0.14875,6.1254e-06,5.442e-07,0.008125 +0.15479,5.077e-06,4.9451e-07,0.008468 +0.16108,3.1418e-06,4.5961e-07,0.0088266 +0.16762,3.0271e-06,4.2547e-07,0.0092015 +0.17443,1.4175e-06,4.0724e-07,0.0095937 +0.18152,1.1026e-06,3.9399e-07,0.010004 +0.18889,4.922e-07,3.8718e-07,0.010434 +0.19657,3.8303e-07,3.9074e-07,0.010884 +0.20456,2.7507e-07,3.9658e-07,0.011356 +0.21287,5.1577e-07,3.9708e-07,0.01185 +0.22152,-1.4249e-07,3.9425e-07,0.012369 +0.23052,-3.5209e-07,4.0549e-07,0.012913 +0.23989,6.0464e-07,4.3519e-07,0.013484 +0.24964,4.3679e-07,4.5058e-07,0.014085 +0.25979,8.9286e-08,4.3952e-07,0.014716 +0.27035,6.2218e-07,4.4806e-07,0.015381 +0.28134,-2.7682e-07,4.49e-07,0.01608 +0.29278,3.2166e-07,4.5407e-07,0.016816 +0.30468,1.0896e-07,4.6808e-07,0.017593 +0.31707,-7.8017e-07,4.5974e-07,0.018413 +0.32996,1.0431e-06,5.1414e-07,0.019278 diff --git a/data/dspc_custom/data3.csv b/data/dspc_custom/data3.csv new file mode 100644 index 00000000..1869634d --- /dev/null +++ b/data/dspc_custom/data3.csv @@ -0,0 +1,104 @@ +0.0063374,0.12823,0.039385,0.00033914 +0.0065738,0.084726,0.024968,0.00035216 +0.0068204,0.068107,0.020754,0.00036572 +0.0070775,0.064598,0.016285,0.00037985 +0.0073457,0.10179,0.017018,0.00039457 +0.0076253,0.092242,0.013751,0.00040991 +0.0079168,0.067577,0.0097702,0.00042588 +0.0082206,0.088561,0.0097059,0.00044252 +0.0085371,0.07448,0.0072737,0.00045984 +0.008867,0.046379,0.0048195,0.00047789 +0.0092106,0.046316,0.0041631,0.00049667 +0.0095686,0.048837,0.0037936,0.00051623 +0.0099414,0.042241,0.0031407,0.00053659 +0.01033,0.040019,0.0027336,0.00055779 +0.010734,0.036485,0.0024038,0.00057986 +0.011155,0.028296,0.0019236,0.00060283 +0.011594,0.026965,0.0016661,0.00062674 +0.01205,0.026248,0.0014756,0.00065162 +0.012525,0.022186,0.0012518,0.00067752 +0.01302,0.019129,0.0010586,0.00070447 +0.013535,0.017201,0.00095089,0.00073252 +0.014071,0.016285,0.00086909,0.00076171 +0.014629,0.013296,0.00072488,0.00079209 +0.015209,0.011045,0.0006195,0.0008237 +0.015814,0.010244,0.00057647,0.0008566 +0.016443,0.008899,0.00051765,0.00089083 +0.017097,0.0090525,0.0004941,0.00092645 +0.017778,0.007198,0.00042364,0.00096351 +0.018487,0.0071734,0.000411,0.0010021 +0.019224,0.0053014,0.00034916,0.0010422 +0.019991,0.0040658,0.0002942,0.001084 +0.02079,0.0035737,0.00027823,0.0011274 +0.021141,0.0041702,0.00035516,0.0011576 +0.021972,0.0031769,0.00023015,0.0012036 +0.022838,0.0025278,0.00017246,0.0012515 +0.02374,0.002042,0.00013247,0.0013013 +0.024678,0.0018214,0.0001074,0.0013532 +0.025655,0.0018156,9.9405e-05,0.0014071 +0.026672,0.001493,8.0288e-05,0.0014633 +0.02773,0.0012242,6.5093e-05,0.0015218 +0.028831,0.0010878,5.5556e-05,0.0015826 +0.029977,0.0009494,4.767e-05,0.0016459 +0.03117,0.00075857,3.8051e-05,0.0017118 +0.032411,0.00071229,3.3606e-05,0.0017804 +0.033703,0.00058844,2.863e-05,0.0018518 +0.035047,0.00052981,2.4879e-05,0.001926 +0.036446,0.00041317,2.0072e-05,0.0020033 +0.037901,0.00033282,1.7052e-05,0.0020838 +0.039415,0.00028356,1.4507e-05,0.0021675 +0.040991,0.0002625,1.3357e-05,0.0022546 +0.04263,0.00020161,1.0789e-05,0.0023453 +0.044336,0.00019092,9.9916e-06,0.0024397 +0.04611,0.00013093,7.7505e-06,0.0025379 +0.047956,0.00013752,7.5144e-06,0.0026401 +0.049877,0.00011123,6.4842e-06,0.0027465 +0.051876,8.3709e-05,5.4462e-06,0.0028573 +0.053955,7.5738e-05,4.9643e-06,0.0029726 +0.056118,6.588e-05,4.4172e-06,0.0030926 +0.058368,6.0283e-05,4.2269e-06,0.0032176 +0.058514,5.6798e-05,6.7895e-06,0.0031323 +0.06085,4.3927e-05,5.3636e-06,0.0032585 +0.063279,4.6048e-05,4.5458e-06,0.0033898 +0.065808,3.4073e-05,3.7013e-06,0.0035266 +0.068438,4.0143e-05,3.5649e-06,0.003669 +0.071175,2.6662e-05,2.8241e-06,0.0038173 +0.074023,2.4083e-05,2.3545e-06,0.0039717 +0.076986,2.3309e-05,2.266e-06,0.0041325 +0.080068,2.8828e-05,2.1438e-06,0.0043001 +0.083276,1.9108e-05,1.7976e-06,0.0044746 +0.086612,1.8879e-05,1.6076e-06,0.0046564 +0.090084,1.7687e-05,1.4593e-06,0.0048458 +0.093695,1.9856e-05,1.3628e-06,0.0050431 +0.097452,1.5334e-05,1.2134e-06,0.0052488 +0.10136,1.6665e-05,1.1448e-06,0.0054631 +0.10543,1.375e-05,1.0325e-06,0.0056866 +0.10966,1.502e-05,9.7171e-07,0.0059195 +0.11406,1.3664e-05,8.8592e-07,0.0061624 +0.11864,1.3706e-05,8.2178e-07,0.0064157 +0.1234,1.1483e-05,7.5018e-07,0.0066799 +0.12836,1.1903e-05,6.9697e-07,0.0069556 +0.13351,7.5482e-06,6.225e-07,0.0072433 +0.13887,7.5468e-06,5.8373e-07,0.0075436 +0.14445,6.7379e-06,5.4847e-07,0.0078571 +0.15025,6.263e-06,5.1627e-07,0.0081845 +0.15629,4.3803e-06,4.7069e-07,0.0085265 +0.16257,3.0045e-06,4.4574e-07,0.008884 +0.1691,1.5888e-06,4.1655e-07,0.0092576 +0.1759,1.2506e-06,4.0119e-07,0.0096483 +0.18297,1.2114e-06,3.9518e-07,0.010057 +0.19032,5.2251e-07,3.8281e-07,0.010485 +0.19797,-2.0168e-07,3.7798e-07,0.010933 +0.20593,2.1403e-07,3.8461e-07,0.011402 +0.2142,-2.4472e-07,3.8796e-07,0.011893 +0.22282,3.7336e-07,4.076e-07,0.012409 +0.23177,1.371e-06,4.2292e-07,0.012949 +0.24109,9.7523e-07,4.4739e-07,0.013517 +0.25078,1.7962e-06,4.7723e-07,0.014113 +0.26087,1.5649e-06,4.6336e-07,0.014739 +0.27136,1.8752e-06,4.7594e-07,0.015398 +0.28227,2.1743e-06,4.729e-07,0.016091 +0.29362,-2.8282e-07,4.6128e-07,0.016821 +0.30542,1.2489e-06,4.7552e-07,0.01759 +0.31771,1.0352e-06,4.9121e-07,0.018401 +0.33048,-6.7397e-07,5.0658e-07,0.019257 diff --git a/domains_custom_layers_example.py b/domains_custom_layers_example.py new file mode 100644 index 00000000..af9490d9 --- /dev/null +++ b/domains_custom_layers_example.py @@ -0,0 +1,187 @@ +import faulthandler +import cppimport +import numpy as np +from alloyDomains import alloyDomains +from misc import MatlabWrapper, DylibWrapper + +faulthandler.enable() + +rat = cppimport.imp("rat") + + +if __name__ == '__main__': + + control = rat.Control() + problem = rat.ProblemDefinition() + limits = rat.Limits() + cells = rat.Cells() + priors = rat.Priors() + + #------------------------------------------------------------------------------------ + # Control + control.procedure = 'calculate' + control.parallel = 'single' + control.display = 'iter' + control.calcSldDuringFit = False + control.resamPars = [0.9000, 50] + + # control.procedure = 'simplex' + # control.tolX = 1e-6 + # control.tolFun = 1e-6 + # control.maxFunEvals = 10000 + # control.maxIter = 1 + # control.updateFreq = -1 + # control.updatePlotFreq = 1 + + # control.procedure = 'dream' + # control.nSamples = 100 + # control.nChains = 10 + # control.jumpProbability = 0.5 + # control.pUnitGamma = 0.2 + # control.boundHandling = 'fold' + # control.adaptPCR = False; + + # control.procedure = 'de' + # control.populationSize = 10 + # control.fWeight = 0.5 + # control.crossoverProbability = 0.8 + # control.strategy = 4 + # control.targetValue = 1 + # control.numGenerations = 500 + + # control.procedure = 'ns' + # control.Nlive = 150 + # control.Nmcmc = 0 + # control.propScale = 0.1 + # control.nsTolerance = 0.1 + + control.checks.fitParam = [1, 1, 1, 1, 1, 1, 1, 1] + control.checks.fitBackgroundParam = [0] + control.checks.fitQzshift = [0] + control.checks.fitScalefactor = [0] + control.checks.fitBulkIn = [0] + control.checks.fitBulkOut = [0] + control.checks.fitResolutionParam = [0] + + #------------------------------------------------------------------------------------ + # ProblemDef + problem.contrastBackgrounds = [1] + problem.contrastBackgroundsType = [1] + problem.TF = 'domains' + problem.resample = [0] + problem.dataPresent = [0] + problem.oilChiDataPresent = [0] + problem.numberOfContrasts = 1 + problem.geometry = 'substrate/liquid' + problem.useImaginary = False + problem.contrastQzshifts = [1] + problem.contrastScalefactors = [1] + problem.contrastBulkIns = [1] + problem.contrastBulkOuts = [1] + problem.contrastResolutions = [1] + problem.backgroundParams = [1.0e-06] + problem.qzshifts = [0] + problem.scalefactors = [0.23] + problem.bulkIn = [2.073e-06] + problem.bulkOut = [6.35e-06] + problem.resolutionParams = [0.0300] + problem.params = [3, 150, 1.1e-05, 7e-06, 7, 150, 4.5e-06, 7] + problem.numberOfLayers = 0 + problem.modelType = 'custom layers' + problem.contrastCustomFiles = [1] + problem.contrastDomainRatios = [1] + problem.domainRatio = [0.5] + problem.numberOfDomainContrasts = 0 + problem.fitParams = [] + problem.otherParams = [] + problem.fitLimits = [] + problem.otherLimits = [] + + #------------------------------------------------------------------------------------ + # Limits + limits.param = [[1, 5], [100, 200], [9e-06, 1.3e-05], [5e-06, 1e-05], + [5, 11], [100, 200], [4e-06, 5e-06], [5, 11]] + limits.backgroundParam = [[1.0000e-07, 1.0000e-05]] + limits.scalefactor = [[0.02, 0.25]] + limits.qzshift = [[-0.0001, 0.0001]] + limits.bulkIn = [[0, 0]] + limits.bulkOut = [[6.2000e-06, 6.3500e-06]] + limits.resolutionParam = [[0.01, 0.05]] + limits.domainRatio = [[0.4, 0.6]] + + #------------------------------------------------------------------------------------- + # Cells + cells.f1 = [[0, 1]] + cells.f2 = [[]] + cells.f3 = [[0, 0]] + cells.f4 = [[0.005, 0.7]] + cells.f5 = [[0]] + cells.f6 = [[0]] + cells.f7 = ['Substrate Roughness', 'Alloy thick', 'Alloy SLD up', 'Alloy SLD dn', + 'Alloy rough', 'Gold thick', 'Gold SLD', 'Gold Rough'] + cells.f8 = ['Background Param 1'] + cells.f9 = ['Scalefactor 1'] + cells.f10 = ['Qz shift 1'] + cells.f11 = ['Silicon'] + cells.f12 = ['SLD D2O'] + cells.f13 = ['Resolution par 1'] + + dylib_wrapper = DylibWrapper('alloyDomains.dll', 'alloyDomains') + cells.f14 = [dylib_wrapper.getHandle()] # C++ callback + + # matlab_wrapper = MatlabWrapper('alloyDomains.m') + # cells.f14 = [matlab_wrapper.getHandle()] # Matlab callback + + # cells.f14 = [alloyDomains] # Python callback + + cells.f15 = ['constant'] + cells.f16 = ['constant'] + cells.f17 = [[]] + cells.f18 = [] + cells.f19 = [] + cells.f20 = ['Domain Ratio 1'] + + #------------------------------------------------------------------------------------ + # Priors + priors.param = [['Substrate Roughness', 'uniform', 0, np.Inf], + ['Alloy thick', 'uniform', 0, np.Inf], + ['Alloy SLD up', 'uniform', 0, np.Inf], + ['Alloy SLD dn', 'uniform', 0, np.Inf], + ['Alloy rough', 'uniform', 0, np.Inf], + ['Gold thick', 'uniform', 0, np.Inf], + ['Gold SLD', 'uniform', 0, np.Inf], + ['Gold Rough', 'uniform', 0, np.Inf]] + priors.backgroundParam = [['Background Param 1', 'uniform', 0, np.Inf], ['Backs par SMW', 'uniform', 0, np.Inf], ['Backs par H20', 'uniform', 0, np.Inf]] + priors.scalefactor = [['Scalefactor 1', 'uniform', 0, np.Inf]] + priors.qzshift = [['Qz shift 1', 'uniform', 0, np.Inf]] + priors.bulkIn = [['Silicon', 'uniform', 0, np.Inf]] + priors.bulkOut = [['SLD D2O', 'uniform', 0, np.Inf]] + priors.domainRatio = [['Domain Ratio 1', 'uniform', 0, np.Inf]] + priors.resolutionParam = [['Resolution par 1', 'uniform', 0, np.Inf]] + priors.priorNames = ['Substrate Roughness', 'Alloy thick', 'Alloy SLD up', + 'Alloy SLD dn', 'Alloy rough', 'Gold thick', + 'Gold SLD', 'Gold Rough', 'Background Param 1', + 'Resolution par 1', 'Silicon', 'SLD D2O', 'Qz shift 1', + 'Scalefactor 1', 'Domain Ratio 1'] + priors.priorValues = [[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], + [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], + [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf]] + + + import time + start = time.perf_counter() + problem, contrast_params, result, bayes_results = rat.RATMain(problem, cells, limits, control, priors) + print(time.perf_counter() - start, 'sec') + # print(contrast_params.ssubs) + # print(contrast_params.backgroundParams) + # print(contrast_params.qzshifts) + # print(contrast_params.scalefactors) + # print(contrast_params.bulkIn) + # print(contrast_params.bulkOut) + # print(contrast_params.resolutionParams) + print(contrast_params.calculations.allChis) + print(contrast_params.calculations.sumChi) + # print(contrast_params.allSubRough) + # print(contrast_params.resample) + #print(output) + \ No newline at end of file diff --git a/misc.py b/misc.py new file mode 100644 index 00000000..1cbb3309 --- /dev/null +++ b/misc.py @@ -0,0 +1,47 @@ +import pathlib +import cppimport +import numpy as np +import matlab.engine + +rat = cppimport.imp("rat") + + +class MatlabWrapper: + def __init__(self, filename): + self.engine = matlab.engine.start_matlab() + path = pathlib.Path(filename) + self.engine.cd(str(path.parent), nargout=0) + self.function_name = path.stem + + def __del__(self): + self.engine.quit() + + def getHandle(self): + def handle(params, bulk_in, bulk_out, contrast, domain=-1): + if domain == -1: + output, sub_rough = getattr(self.engine, self.function_name)(np.array(params, 'float'), + np.array(bulk_in, 'float'), + np.array(bulk_out, 'float'), + float(contrast + 1), nargout=2) + else: + output, sub_rough = getattr(self.engine, self.function_name)(np.array(params, 'float'), + np.array(bulk_in, 'float'), + np.array(bulk_out, 'float'), + float(contrast + 1), float(domain + 1), nargout=2) + return output, sub_rough + return handle + + +class DylibWrapper: + def __init__(self, filename, function_name): + self.engine = rat.DylibEngine(filename, function_name) + + def getHandle(self): + def handle(params, bulk_in, bulk_out, contrast, domain=-1): + if domain == -1: + output, sub_rough = self.engine.invoke(params, bulk_in, bulk_out, contrast) + else: + output, sub_rough = self.engine.invoke(params, bulk_in, bulk_out, contrast, domain) + return output, sub_rough + return handle + \ No newline at end of file diff --git a/rat.cpp b/rat.cpp index 86cb57d7..50b0f81f 100644 --- a/rat.cpp +++ b/rat.cpp @@ -5,15 +5,127 @@ cfg['parallel'] = True setup_pybind11(cfg) %>*/ +#include +#include #include #include +#include +#include #include "RAT/RATMain.h" #include "RAT/RATMain_initialize.h" #include "RAT/RATMain_terminate.h" #include "RAT/RATMain_types.h" +#include "RAT/classHandle.hpp" +#include "RAT/dylib.hpp" namespace py = pybind11; +const int DEFAULT_DOMAIN = -1; + +class Library: public CallbackInterface +{ + public: + + py::function function; + + Library(const py::function function){ + this->function = function; + }; + + + void setOutput(py::tuple& result, std::vector& output, double *outputSize) + { + int n_rows = 0, idx = 0; + for (py::handle row_handle : result[0]) + { + py::list rows = py::cast(row_handle); + for (py::handle value : rows) + { + output.push_back(py::cast(value)); + idx++; + } + n_rows++; + } + + outputSize[0] = n_rows; + outputSize[1] = (n_rows == 0) ? 0 : idx / n_rows; + } + + // Domain overload + void invoke(std::vector& params, std::vector& bulk_in, std::vector& bulk_out, + int contrast, int domainNumber, std::vector& output, double *outputSize, double *roughness) + { + auto f = py::cast>(this->function); + auto result = f(py::cast(params), py::cast(bulk_in), py::cast(bulk_out), contrast, domainNumber); + *roughness = py::cast(result[1]); + setOutput(result, output, outputSize); + }; + + // Non-Domain overload + void invoke(std::vector& params, std::vector& bulk_in, std::vector& bulk_out, + int contrast, std::vector& output, double *outputSize, double *roughness) + { + auto f = py::cast>(this->function); + auto result = f(py::cast(params), py::cast(bulk_in), py::cast(bulk_out), contrast); + *roughness = py::cast(result[1]); + setOutput(result, output, outputSize); + }; +}; + +class DylibEngine +{ + public: + std::unique_ptr library; + std::string functionName; + + DylibEngine(std::string libName, std::string functionName) + { + this->functionName = functionName; + this->library = std::unique_ptr(new dylib(libName)); + if (!library) + { + std::cerr << "dynamic libray failed to load" << std::endl; + return; + } + }; + + ~DylibEngine(){}; + + py::tuple invoke(std::vector& params, std::vector& bulk_in, std::vector& bulk_out, int contrast, int domain=DEFAULT_DOMAIN) + { + try{ + std::vector tempOutput; + double *outputSize = new double[2]; + double roughness = 0.0; + + if (domain != -1) { + auto func = library->get_function&, std::vector&, std::vector&, + int, int, std::vector&, double*, double*)>(functionName); + func(params, bulk_in, bulk_out, contrast, domain, tempOutput, outputSize, &roughness); + } + else { + auto func = library->get_function&, std::vector&, std::vector&, + int, std::vector&, double*, double*)>(functionName); + func(params, bulk_in, bulk_out, contrast, tempOutput, outputSize, &roughness); + } + + py::list output; + for (int32_T idx1{0}; idx1 < outputSize[0]; idx1++) + { + py::list rows; + for (int32_T idx2{0}; idx2 < outputSize[1]; idx2++) + { + rows.append(tempOutput[(int32_T)outputSize[1] * idx1 + idx2]); + } + output.append(rows); + } + return py::make_tuple(output, roughness); + + }catch (const dylib::symbol_error &) { + throw std::runtime_error("failed to get dynamic libray symbol for ***functionName"); + } + }; +}; struct Predlims { @@ -139,7 +251,7 @@ struct Calculation real_T sumChi; }; -struct OutputProblem +struct ContrastParams { py::array_t ssubs; py::array_t backgroundParams; @@ -301,27 +413,6 @@ coder::array py_array_to_rat_1d_array(py::array_t value) return result; } -// coder::bounded_array py_array_to_rat_bounded_array2(py::array_t value) -// { -// coder::bounded_array result {}; - -// py::buffer_info buffer_info = value.request(); - -// if (buffer_info.size == 0) -// return result; - -// if (buffer_info.ndim != 1) -// throw std::runtime_error("Number of dimensions must be 1"); - -// result.size[0] = 1; -// result.size[1] = buffer_info.shape[0]; -// for (int32_T idx0{0}; idx0 < buffer_info.shape[0]; idx0++) { -// result.data[idx0] = value.at(idx0); -// } - -// return result; -// } - coder::bounded_array py_array_to_rat_bounded_array(py::array_t value) { coder::bounded_array result {}; @@ -571,6 +662,22 @@ coder::array py_array_to_rat_cell_wrap_6(py::list values) return result; } +coder::array py_function_array_to_rat_cell_wrap_6(py::list values) +{ + coder::array result; + result.set_size(1, values.size()); + int32_T idx {0}; + for (py::handle array: values) + { + auto func = py::cast(array); + std::string func_ptr = convertPtr2String(new Library(func)); + string_to_rat_array(func_ptr, result[idx].f1.data, result[idx].f1.size); + idx++; + } + + return result; +} + RAT::cell_7 create_cell_7(const Cells& cells) { RAT::cell_7 cells_struct; @@ -587,7 +694,7 @@ RAT::cell_7 create_cell_7(const Cells& cells) cells_struct.f11 = py_array_to_rat_cell_wrap_6(cells.f11); cells_struct.f12 = py_array_to_rat_cell_wrap_6(cells.f12); cells_struct.f13 = py_array_to_rat_cell_wrap_6(cells.f13); - cells_struct.f14 = py_array_to_rat_cell_wrap_6(cells.f14); + cells_struct.f14 = py_function_array_to_rat_cell_wrap_6(cells.f14); cells_struct.f15 = py_array_to_rat_cell_wrap_6(cells.f15); cells_struct.f16 = py_array_to_rat_cell_wrap_6(cells.f16); cells_struct.f17 = py_array_to_rat_cell_wrap_3(cells.f17); @@ -735,10 +842,10 @@ py::list result_to_list(const RAT::cell_wrap_9 results[]) return output_result; } -OutputProblem struct6_T_to_OutputProblem(const RAT::struct6_T problem) +ContrastParams struct5_T_to_ContrastParams(const RAT::struct5_T problem) { // Copy problem to output - OutputProblem output_problem; + ContrastParams output_problem; output_problem.ssubs = py::array_t(problem.ssubs.size(0)); auto buffer = output_problem.ssubs.request(); std::memcpy(buffer.ptr, problem.ssubs.data(), output_problem.ssubs.size()*sizeof(real_T)); @@ -783,7 +890,7 @@ OutputProblem struct6_T_to_OutputProblem(const RAT::struct6_T problem) return output_problem; } -ProblemDefinition struct5_T_to_ProblemDefinition(const RAT::struct5_T problem) +ProblemDefinition struct0_T_to_ProblemDefinition(const RAT::struct0_T problem) { ProblemDefinition problem_def; @@ -858,7 +965,16 @@ py::list rat_cell_wrap_8_2d_to_py_list(const coder::array& } template -py::array_t bounded_array_to_py_array(const T& array) +py::array_t bounded_array_1d_to_py_array(const T& array) +{ + auto result_array = py::array_t({array.size[0]}); + std::memcpy(result_array.request().ptr, array.data, result_array.nbytes()); + + return result_array; +} + +template +py::array_t bounded_array_2d_to_py_array(const T& array) { auto result_array = py::array_t({array.size[0], array.size[1]}); std::memcpy(result_array.request().ptr, array.data, result_array.nbytes()); @@ -874,7 +990,7 @@ py::array_t rat_array_3d_to_py_array(coder::array array) return result_array; } -BayesResults struct8_T_to_BayesResults(const RAT::struct8_T results) +BayesResults struct7_T_to_BayesResults(const RAT::struct7_T results) { BayesResults bayesResults; @@ -887,10 +1003,10 @@ BayesResults struct8_T_to_BayesResults(const RAT::struct8_T results) bayesResults.bestFitsMean.data = rat_cell_wrap_8_to_py_list(results.bestFitsMean.data); bayesResults.predlims.refPredInts = rat_cell_wrap_8_to_py_list(results.predlims.refPredInts); - bayesResults.predlims.sldPredInts = rat_cell_wrap_8_to_py_list(results.predlims.sldPredInts); + bayesResults.predlims.sldPredInts = rat_cell_wrap_8_2d_to_py_list(results.predlims.sldPredInts); bayesResults.predlims.refXdata = rat_cell_wrap_8_to_py_list(results.predlims.refXdata); bayesResults.predlims.sldXdata = rat_cell_wrap_8_2d_to_py_list(results.predlims.sldXdata); - bayesResults.predlims.sampleChi = bounded_array_to_py_array>(results.predlims.sampleChi); + bayesResults.predlims.sampleChi = bounded_array_1d_to_py_array>(results.predlims.sampleChi); bayesResults.parConfInts.par95 = rat_array_2d_to_py_array(results.parConfInts.par95); bayesResults.parConfInts.par65 = rat_array_2d_to_py_array(results.parConfInts.par65); @@ -908,8 +1024,8 @@ BayesResults struct8_T_to_BayesResults(const RAT::struct8_T results) bayesResults.bayesRes.dreamOutput.fx = results.bayesRes.dreamOutput.fx; bayesResults.bayesRes.dreamOutput.R_stat = rat_array_2d_to_py_array(results.bayesRes.dreamOutput.R_stat); bayesResults.bayesRes.dreamOutput.CR = rat_array_2d_to_py_array(results.bayesRes.dreamOutput.CR); - bayesResults.bayesRes.dreamOutput.AR = bounded_array_to_py_array>(results.bayesRes.dreamOutput.AR); - bayesResults.bayesRes.dreamOutput.outlier = bounded_array_to_py_array>(results.bayesRes.dreamOutput.outlier); + bayesResults.bayesRes.dreamOutput.AR = bounded_array_2d_to_py_array>(results.bayesRes.dreamOutput.AR); + bayesResults.bayesRes.dreamOutput.outlier = bounded_array_2d_to_py_array>(results.bayesRes.dreamOutput.outlier); bayesResults.bayesRes.dreamOutput.Meas_info.Y = results.bayesRes.dreamOutput.Meas_info.Y; bayesResults.bayesRes.dreamOutput.Meas_info.N = results.bayesRes.dreamOutput.Meas_info.N; @@ -948,19 +1064,18 @@ py::tuple RATMain(const ProblemDefinition& problem_def, const Cells& cells, cons RAT::struct2_T control_struct = create_struct2_T(control); RAT::struct4_T priors_struct = create_struct4_T(priors); - RAT::struct5_T outProblemDef; RAT::cell_wrap_9 results[6]; - RAT::struct6_T problem; - RAT::struct8_T bayesResults; + RAT::struct5_T problem; + RAT::struct7_T bayesResults; // Call the entry-point RAT::RATMain(&problem_def_struct, &cells_struct, &limits_struct, &control_struct, - &priors_struct, &outProblemDef, &problem, results, &bayesResults); + &priors_struct, &problem, results, &bayesResults); // Copy result to output - return py::make_tuple(struct5_T_to_ProblemDefinition(outProblemDef), - struct6_T_to_OutputProblem(problem), result_to_list(results), - struct8_T_to_BayesResults(bayesResults)); + return py::make_tuple(struct0_T_to_ProblemDefinition(problem_def_struct), + struct5_T_to_ContrastParams(problem), + result_to_list(results), struct7_T_to_BayesResults(bayesResults)); } class Module @@ -978,6 +1093,12 @@ class Module PYBIND11_MODULE(rat, m) { static Module module; + py::class_(m, "DylibEngine") + .def(py::init()) + .def("invoke", &DylibEngine::invoke, py::arg("params"), py::arg("bulk_in"), + py::arg("bulk_out"), py::arg("contrast"), + py::arg("domain") = DEFAULT_DOMAIN); + py::class_(m, "Predlims") .def(py::init<>()) .def_readwrite("refPredInts", &Predlims::refPredInts) @@ -1067,18 +1188,18 @@ PYBIND11_MODULE(rat, m) { .def_readwrite("allChis", &Calculation::allChis) .def_readwrite("sumChi", &Calculation::sumChi); - py::class_(m, "OutputProblem") + py::class_(m, "ContrastParams") .def(py::init<>()) - .def_readwrite("ssubs", &OutputProblem::ssubs) - .def_readwrite("backgroundParams", &OutputProblem::backgroundParams) - .def_readwrite("qzshifts", &OutputProblem::qzshifts) - .def_readwrite("scalefactors", &OutputProblem::scalefactors) - .def_readwrite("bulkIn", &OutputProblem::bulkIn) - .def_readwrite("bulkOut", &OutputProblem::bulkOut) - .def_readwrite("resolutionParams", &OutputProblem::resolutionParams) - .def_readwrite("calculations", &OutputProblem::calculations) - .def_readwrite("allSubRough", &OutputProblem::allSubRough) - .def_readwrite("resample", &OutputProblem::resample); + .def_readwrite("ssubs", &ContrastParams::ssubs) + .def_readwrite("backgroundParams", &ContrastParams::backgroundParams) + .def_readwrite("qzshifts", &ContrastParams::qzshifts) + .def_readwrite("scalefactors", &ContrastParams::scalefactors) + .def_readwrite("bulkIn", &ContrastParams::bulkIn) + .def_readwrite("bulkOut", &ContrastParams::bulkOut) + .def_readwrite("resolutionParams", &ContrastParams::resolutionParams) + .def_readwrite("calculations", &ContrastParams::calculations) + .def_readwrite("allSubRough", &ContrastParams::allSubRough) + .def_readwrite("resample", &ContrastParams::resample); py::class_(m, "OutputResult") .def(py::init<>()) @@ -1120,6 +1241,7 @@ PYBIND11_MODULE(rat, m) { .def_readwrite("bulkIn", &Priors::bulkIn) .def_readwrite("bulkOut", &Priors::bulkOut) .def_readwrite("resolutionParam", &Priors::resolutionParam) + .def_readwrite("domainRatio", &Priors::domainRatio) .def_readwrite("priorNames", &Priors::priorNames) .def_readwrite("priorValues", &Priors::priorValues); @@ -1211,5 +1333,5 @@ PYBIND11_MODULE(rat, m) { .def_readwrite("fitLimits", &ProblemDefinition::fitLimits) .def_readwrite("otherLimits", &ProblemDefinition::otherLimits); - m.def("RATMain", &RATMain, "A demo for Python RAT"); + m.def("RATMain", &RATMain, "A demo for Python RAT"); } diff --git a/requirements.txt b/requirements.txt index 9baee760..f8bd94e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ cppimport numpy -pybind11 \ No newline at end of file +pybind11 +matlabengine \ No newline at end of file From 31a66406cc7ed350fe2b55093fdfab66bc6392cf Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Tue, 6 Feb 2024 16:02:58 +0000 Subject: [PATCH 4/8] Adds implementation for the event manger --- DSPC_custom_layers_example.py | 38 +++++---- RAT/reflectivityCalculation.cpp | 1 - domains_custom_layers_example.py | 8 +- events.py | 30 +++++++ events/eventManager.cpp | 60 ++++++++++++++ events/eventManager.h | 35 ++++++++ events/eventManagerImpl.hpp | 102 +++++++++++++++++++++++ rat.cpp | 138 +++++++++++++++++++++++++++++++ 8 files changed, 392 insertions(+), 20 deletions(-) create mode 100644 events.py create mode 100644 events/eventManager.cpp create mode 100644 events/eventManager.h create mode 100644 events/eventManagerImpl.hpp diff --git a/DSPC_custom_layers_example.py b/DSPC_custom_layers_example.py index 9fe82dc4..c2e12a32 100644 --- a/DSPC_custom_layers_example.py +++ b/DSPC_custom_layers_example.py @@ -3,6 +3,7 @@ import numpy as np from customBilayer import customBilayer from misc import MatlabWrapper, DylibWrapper +import events faulthandler.enable() @@ -25,13 +26,13 @@ control.calcSldDuringFit = False control.resamPars = [0.9000, 50] - # control.procedure = 'simplex' - # control.tolX = 1e-6 - # control.tolFun = 1e-6 - # control.maxFunEvals = 10000 - # control.maxIter = 1 - # control.updateFreq = -1 - # control.updatePlotFreq = 1 + control.procedure = 'simplex' + control.tolX = 1e-6 + control.tolFun = 1e-6 + control.maxFunEvals = 10000 + control.maxIter = 1 + control.updateFreq = -1 + control.updatePlotFreq = 1 # control.procedure = 'dream' # control.nSamples = 100 @@ -55,12 +56,12 @@ # control.propScale = 0.1 # control.nsTolerance = 0.1 - control.checks.fitParam = [1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1] - control.checks.fitBackgroundParam = np.ones((2)) + control.checks.fitParam = [1, 1, 1, 1, 1, 1, 1, 1] + control.checks.fitBackgroundParam = np.ones((3)) control.checks.fitQzshift = [0] - control.checks.fitScalefactor = [0, 0] + control.checks.fitScalefactor = [1] control.checks.fitBulkIn = [0] - control.checks.fitBulkOut = [0, 0] + control.checks.fitBulkOut = [1, 1, 1] control.checks.fitResolutionParam = [0] #------------------------------------------------------------------------------------ @@ -92,10 +93,12 @@ problem.contrastDomainRatios = [0, 0, 0] problem.domainRatio = [] problem.numberOfDomainContrasts = 0 - problem.fitParams = [] - problem.otherParams = [] - problem.fitLimits = [] - problem.otherLimits = [] + problem.fitParams = [3, 20, 0.2, 55, 0.2, 0.1, 4, 2, 1.0e-07, 1.0e-07, 1.0e-07, 1, 6.35e-06, 2.073e-06, -5.6e-07] + problem.otherParams = [0, 2.073e-06, 0.03] + problem.fitLimits = [[1, 10], [5, 60], [0, 0.5], [45, 65], [0, 0.5], [0, 0.2], [2, 8], [0, 10], + [1.0e-10, 1.0e-05], [1.0e-10, 1.0e-05], [1.0e-10, 1.0e-05], [0.5, 2], [5.0e-06, 6.35e-06], + [1.0e-06, 3.0e-06], [-6.0e-07, -3.0e-07]] + problem.otherLimits = [[-0.0001, 0.0001], [2.07e-06, 2.08e-06], [0.01, 0.05]] #------------------------------------------------------------------------------------ # Limits @@ -170,9 +173,14 @@ [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf]] + def fakePlot(event): + print("Hello plotting") + import time start = time.perf_counter() + events.register(rat.EventTypes.Plot, fakePlot) problem, contrast_params, result, bayes_results = rat.RATMain(problem, cells, limits, control, priors) + events.clear() print(time.perf_counter() - start, 'sec') # print(contrast_params.ssubs) # print(contrast_params.backgroundParams) diff --git a/RAT/reflectivityCalculation.cpp b/RAT/reflectivityCalculation.cpp index 6aa224ac..d5626cdd 100644 --- a/RAT/reflectivityCalculation.cpp +++ b/RAT/reflectivityCalculation.cpp @@ -252,7 +252,6 @@ namespace RAT // // * magnetic - Target function for cases for polarised neutrons with polarisation analysis. // - // triggerEvent('message', 'Running reflectivity calculation...'); // for compilation, we have to preallocate memory for the output arrays // Setting these parameters in the struct defines them as doubles contrastParams->ssubs.set_size(1); diff --git a/domains_custom_layers_example.py b/domains_custom_layers_example.py index af9490d9..c1ab7134 100644 --- a/domains_custom_layers_example.py +++ b/domains_custom_layers_example.py @@ -92,10 +92,10 @@ problem.contrastDomainRatios = [1] problem.domainRatio = [0.5] problem.numberOfDomainContrasts = 0 - problem.fitParams = [] - problem.otherParams = [] - problem.fitLimits = [] - problem.otherLimits = [] + problem.fitParams = [3, 150, 1.1e-05, 7.0e-06, 7, 150, 4.5e-06, 7] + problem.otherParams = [1.0e-06, 0.23, 0, 2.073e-06, 6.35e-06, 0.03, 0.5] + problem.fitLimits = [[1, 5], [100, 200], [9.0e-06, 1.3e-05], [5.0e-06, 1.0e-05], [5, 11], [100, 200], [4.0e-06, 5.0e-06], [5, 11]] + problem.otherLimits = [[1.0e-07, 1.0e-05], [0.02, 0.25], [-0.0001, 0.0001], [0, 0], [6.2e-06, 6.35e-06], [0.01, 0.05], [0.4, 0.6]] #------------------------------------------------------------------------------------ # Limits diff --git a/events.py b/events.py new file mode 100644 index 00000000..f540022e --- /dev/null +++ b/events.py @@ -0,0 +1,30 @@ +import pathlib +import cppimport +import numpy as np +import matlab.engine + +rat = cppimport.imp("rat") + + +def nofiy(event_type, data): + callbacks = __event_callbacks[event_type] + for callback in callbacks: + callback(data) + + +def register(event_type, callback): + if not isinstance(event_type, rat.EventTypes): + raise ValueError("event_type must be a rat.EventTypes enum") + + if len(__event_callbacks[event_type]) == 0: + __event_impl.register(event_type) + __event_callbacks[event_type].add(callback) + + +def clear(): + __event_impl.clear() + __event_callbacks.clear() + + +__event_impl = rat.EventStuff(nofiy) +__event_callbacks = {rat.EventTypes.Message: set(), rat.EventTypes.Plot: set()} diff --git a/events/eventManager.cpp b/events/eventManager.cpp new file mode 100644 index 00000000..90a9047d --- /dev/null +++ b/events/eventManager.cpp @@ -0,0 +1,60 @@ +#include "eventManager.h" + +LIB_EXPORT void sendMessage(const char* msg) +{ + notify(messageEvent(msg)); +} + +LIB_EXPORT void updatePlot(int nContrast, double* reflect, double* nReflect, double* shiftedData, double* nShiftedData, + double* sldProfiles, double* nSldProfiles, double* layers, double* nLayers, + double* sldProfiles2, double* nSldProfiles2, double* layers2, double* nLayers2, double* ssubs, + double* resample, double* dataPresent, const char* modelType) +{ + plotData data; + data.nContrast = nContrast; + data.reflect = reflect; + data.nReflect = nReflect; + data.shiftedData = shiftedData; + data.nShiftedData = nShiftedData; + data.sldProfiles = sldProfiles; + data.nSldProfiles = nSldProfiles; + data.layers = layers; + data.nLayers = nLayers; + data.sldProfiles2 = sldProfiles2; + data.nSldProfiles2 = nSldProfiles2; + data.layers2 = layers2; + data.nLayers2 = nLayers2; + data.ssubs = ssubs; + data.resample = resample; + data.dataPresent = dataPresent; + data.modelType = modelType; + notify(plotEvent(&data)); +} + +LIB_EXPORT void notify(const baseEvent& event) +{ + eventManager::get_instance()->notify(event); +} + +LIB_EXPORT void addListener(EventTypes type, const std::function fn) +{ + if (type == EventTypes::Message) + eventManager::get_instance()->addListener(EventTypes::Message, fn); + else if (type == EventTypes::Plot) + eventManager::get_instance()->addListener(EventTypes::Plot, fn); +} + +LIB_EXPORT void clearListeners() +{ + eventManager::get_instance()->clear(); +} + +LIB_EXPORT bool hasPlotHandler() +{ + auto names = eventManager::get_instance()->getEventNames(); + for(unsigned i=0; i < names.size(); i++) { + if (names[i] == EventTypes::Plot) + return true; + } + return false; +} diff --git a/events/eventManager.h b/events/eventManager.h new file mode 100644 index 00000000..29a31676 --- /dev/null +++ b/events/eventManager.h @@ -0,0 +1,35 @@ +#include "eventManagerImpl.hpp" + +#ifndef EVENT_MANAGER_H +#define EVENT_MANAGER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) || defined(_WIN64) +#define LIB_EXPORT __declspec(dllexport) +#else +#define LIB_EXPORT +#endif + +LIB_EXPORT void updatePlot(int nContrast, double* reflect, double* nReflect, double* shiftedData, double* nShiftedData, + double* sldProfiles, double* nSldProfiles, double* layers, double* nLayers, + double* sldProfiles2, double* nSldProfiles2, double* layers2, double* nLayers2, double* ssubs, + double* resample, double* dataPresent, const char* modelType); + +LIB_EXPORT void sendMessage(const char* msg); + +LIB_EXPORT void notify(const baseEvent& event); + +LIB_EXPORT void addListener(EventTypes type, const std::function fn); + +LIB_EXPORT void clearListeners(); + +LIB_EXPORT bool hasPlotHandler(); + +#ifdef __cplusplus +} +#endif + +#endif // EVENT_MANAGER_H \ No newline at end of file diff --git a/events/eventManagerImpl.hpp b/events/eventManagerImpl.hpp new file mode 100644 index 00000000..8f10212d --- /dev/null +++ b/events/eventManagerImpl.hpp @@ -0,0 +1,102 @@ +#ifndef EVENT_MANAGER_IMPL_HPP +#define EVENT_MANAGER_IMPL_HPP + +#include +#include +#include + +/* + Implementation of a singleton event manager with support for multiple + event types. +*/ +enum class EventTypes { + Message, + Plot +}; + + +struct plotData { + int nContrast; + double* reflect; + double* nReflect; + double* shiftedData; + double* nShiftedData; + double* sldProfiles; + double* nSldProfiles; + double* layers; + double* nLayers; + double* sldProfiles2; + double* nSldProfiles2; + double* layers2; + double* nLayers2; + double* ssubs; + double* resample; + double* dataPresent; + const char* modelType; +}; + + +struct baseEvent { + EventTypes type; + baseEvent(EventTypes type) : type(type) {} + virtual ~baseEvent() {} +}; + +struct messageEvent : baseEvent { + const char* msg; + messageEvent(const char* msg) : baseEvent(EventTypes::Message), msg(msg) {} +}; + +struct plotEvent : baseEvent { + const plotData* data; + plotEvent(const plotData* data) : baseEvent(EventTypes::Plot), data(data) {} +}; + + +typedef void (*callback) (const baseEvent&); + + +class eventManager +{ +public: + + eventManager(eventManager const&) = delete; + eventManager& operator=(eventManager const&) = delete; + ~eventManager() {} + + const std::vector& getEventNames()const {return eventNames;} + + void addListener(EventTypes type, const std::function fn) { + std::lock_guard lock(m_mutex); + eventNames.push_back(type); + eventHandlers.push_back(fn); + } + + void notify(const baseEvent& event) { + for(unsigned i=0; i < eventNames.size(); i++) { + if (event.type == eventNames[i]) + eventHandlers[i] (event); + } + } + + void clear() { + eventNames.clear(); + eventHandlers.clear(); + } + + static eventManager* get_instance() + { + // Static local variable initialization is thread-safe + // and will be initialized only once. + static eventManager instance{}; + return &instance; + } + +private: + explicit eventManager() {} + std::vector eventNames; + std::vector> eventHandlers; + std::mutex m_mutex; +}; + +#endif // EVENT_MANAGER_IMPL_HPP \ No newline at end of file diff --git a/rat.cpp b/rat.cpp index 50b0f81f..022d8f11 100644 --- a/rat.cpp +++ b/rat.cpp @@ -5,6 +5,7 @@ cfg['parallel'] = True setup_pybind11(cfg) %>*/ +#include #include #include #include @@ -17,6 +18,7 @@ setup_pybind11(cfg) #include "RAT/RATMain_types.h" #include "RAT/classHandle.hpp" #include "RAT/dylib.hpp" +#include "events/eventManager.h" namespace py = pybind11; @@ -127,6 +129,122 @@ class DylibEngine }; }; + +struct PlotEventData +{ + py::list reflectivity; + py::list shiftedData; + py::list sldProfiles; + py::list allLayers; + py::array_t ssubs; + py::array_t resample; + py::array_t dataPresent; + std::string modelType; +}; + +class EventStuff +{ + public: + std::unique_ptr library; + py::function callback; + + EventStuff(py::function callback) + { + std::string filename = "eventManager" + std::string(dylib::extension); + this->library = std::unique_ptr(new dylib("", filename.c_str())); + if (!library) + { + std::cerr << "event manager dynamic libray failed to load" << std::endl; + return; + } + this->callback = callback; + }; + + py::list unpackDataToCell(int rows, int cols, double* data, double* nData, + double* data2, double* nData2, int dataCol) + { + py::list allResults; + int dims[2] = {0, dataCol}; + int offset = 0; + for (int i = 0; i < rows; i++){ + py::list rowList; + dims[0] = (int)nData[i] / dataCol; + auto result = py::array_t({dims[0], dims[1]}); + std::memcpy(result.request().ptr, data + offset, result.nbytes()); + offset += result.size(); + rowList.append(result); + allResults.append(rowList); + } + + if (data2 != NULL && nData2 != NULL) + { + // This is used to unpack the domains data into the second column + offset = 0; + for ( int i = 0; i < rows; i++){ + dims[0] = (int)nData2[i] / dataCol; + auto result = py::array_t({dims[0], dims[1]}); + std::memcpy(result.request().ptr, data2 + offset, result.nbytes()); + offset += result.size(); + auto rowList = allResults[i].cast(); + rowList.append(result); + } + } + + return allResults; + }; + + void eventCallback(const baseEvent& event) + { + if (event.type == EventTypes::Message) { + messageEvent* mEvent = (messageEvent*)&event; + this->callback(event.type, mEvent->msg); + } else if (event.type == EventTypes::Plot){ + plotEvent* pEvent = (plotEvent*)&event; + PlotEventData eventData; + + eventData.modelType = std::string(pEvent->data->modelType); + + eventData.ssubs = py::array_t(pEvent->data->nContrast); + std::memcpy(eventData.ssubs.request().ptr, pEvent->data->ssubs, eventData.ssubs.nbytes()); + + eventData.resample = py::array_t(pEvent->data->nContrast); + std::memcpy(eventData.resample.request().ptr, pEvent->data->resample, eventData.resample.nbytes()); + + eventData.dataPresent = py::array_t(pEvent->data->nContrast); + std::memcpy(eventData.dataPresent.request().ptr, pEvent->data->dataPresent, eventData.dataPresent.nbytes()); + + eventData.reflectivity = unpackDataToCell(pEvent->data->nContrast, 1, + pEvent->data->reflect, pEvent->data->nReflect, NULL, NULL, 2); + + eventData.shiftedData = unpackDataToCell(pEvent->data->nContrast, 1, + pEvent->data->shiftedData, pEvent->data->nShiftedData, NULL, NULL, 3); + + eventData.sldProfiles = unpackDataToCell(pEvent->data->nContrast, (pEvent->data->nSldProfiles2 == NULL) ? 1 : 2, + pEvent->data->sldProfiles, pEvent->data->nSldProfiles, + pEvent->data->sldProfiles2, pEvent->data->nSldProfiles2, 2); + + eventData.allLayers = unpackDataToCell(pEvent->data->nContrast, (pEvent->data->nLayers2 == NULL) ? 1 : 2, + pEvent->data->layers, pEvent->data->nLayers, + pEvent->data->layers2, pEvent->data->nLayers, 2); + this->callback(event.type, eventData); + } + }; + + + void registerEvent(EventTypes eventType) + { + std::function caller = std::bind(&EventStuff::eventCallback, this, std::placeholders::_1); + auto addListener = library->get_function)>("addListener"); + addListener(eventType, caller); + }; + + void clear() + { + auto clearListeners = library->get_function("clearListeners"); + clearListeners(); + }; +}; + struct Predlims { py::list refPredInts; @@ -1093,6 +1211,15 @@ class Module PYBIND11_MODULE(rat, m) { static Module module; + py::class_(m, "EventStuff") + .def(py::init()) + .def("register", &EventStuff::registerEvent) + .def("clear", &EventStuff::clear); + + py::enum_(m, "EventTypes") + .value("Message", EventTypes::Message) + .value("Plot", EventTypes::Plot); + py::class_(m, "DylibEngine") .def(py::init()) .def("invoke", &DylibEngine::invoke, py::arg("params"), py::arg("bulk_in"), @@ -1106,6 +1233,17 @@ PYBIND11_MODULE(rat, m) { .def_readwrite("refXdata", &Predlims::refXdata) .def_readwrite("sldXdata", &Predlims::sldXdata) .def_readwrite("sampleChi", &Predlims::sampleChi); + + py::class_(m, "PlotEventData") + .def(py::init<>()) + .def_readonly("reflectivity", &PlotEventData::reflectivity) + .def_readonly("shiftedData", &PlotEventData::shiftedData) + .def_readonly("sldProfiles", &PlotEventData::sldProfiles) + .def_readonly("allLayers", &PlotEventData::allLayers) + .def_readonly("ssubs", &PlotEventData::ssubs) + .def_readonly("resample", &PlotEventData::resample) + .def_readonly("dataPresent", &PlotEventData::dataPresent) + .def_readonly("modelType", &PlotEventData::modelType); py::class_(m, "BestFitsMean") .def(py::init<>()) From f95c6fefd3c5bdaa183a902a7035ca46343e8fb6 Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Wed, 14 Feb 2024 15:58:05 +0000 Subject: [PATCH 5/8] Adds setup.py --- .gitignore | 3 + README.md | 13 +- {RAT => cpp/RAT}/CoderTimeAPI.cpp | 0 {RAT => cpp/RAT}/CoderTimeAPI.h | 0 {RAT => cpp/RAT}/DREAMWrapper.cpp | 0 {RAT => cpp/RAT}/DREAMWrapper.h | 0 {RAT => cpp/RAT}/RATMain.cpp | 0 {RAT => cpp/RAT}/RATMain.h | 0 {RAT => cpp/RAT}/RATMain_data.cpp | 0 {RAT => cpp/RAT}/RATMain_data.h | 0 {RAT => cpp/RAT}/RATMain_initialize.cpp | 0 {RAT => cpp/RAT}/RATMain_initialize.h | 0 {RAT => cpp/RAT}/RATMain_internal_types.h | 0 {RAT => cpp/RAT}/RATMain_rtwutil.cpp | 0 {RAT => cpp/RAT}/RATMain_rtwutil.h | 0 {RAT => cpp/RAT}/RATMain_terminate.cpp | 0 {RAT => cpp/RAT}/RATMain_terminate.h | 0 {RAT => cpp/RAT}/RATMain_types.h | 0 {RAT => cpp/RAT}/SLDFunction.cpp | 0 {RAT => cpp/RAT}/SLDFunction.h | 0 {RAT => cpp/RAT}/abelesParallelPoints.cpp | 0 {RAT => cpp/RAT}/abelesParallelPoints.h | 0 {RAT => cpp/RAT}/abelesSingle.cpp | 0 {RAT => cpp/RAT}/abelesSingle.h | 0 {RAT => cpp/RAT}/abs.cpp | 0 {RAT => cpp/RAT}/abs.h | 0 {RAT => cpp/RAT}/acos.cpp | 0 {RAT => cpp/RAT}/acos.h | 0 {RAT => cpp/RAT}/adaptPCR.cpp | 0 {RAT => cpp/RAT}/adaptPCR.h | 0 {RAT => cpp/RAT}/adaptive.cpp | 0 {RAT => cpp/RAT}/adaptive.h | 0 {RAT => cpp/RAT}/all.cpp | 0 {RAT => cpp/RAT}/all.h | 0 {RAT => cpp/RAT}/allOrAny.cpp | 0 {RAT => cpp/RAT}/allOrAny.h | 0 .../RAT}/allocateLayersForContrast.cpp | 0 {RAT => cpp/RAT}/allocateLayersForContrast.h | 0 {RAT => cpp/RAT}/allocateParamsToLayers.cpp | 0 {RAT => cpp/RAT}/allocateParamsToLayers.h | 0 {RAT => cpp/RAT}/anyNonFinite.cpp | 0 {RAT => cpp/RAT}/anyNonFinite.h | 0 .../RAT}/applyBackgroundCorrection.cpp | 0 {RAT => cpp/RAT}/applyBackgroundCorrection.h | 0 {RAT => cpp/RAT}/applyHydrationImag.cpp | 0 {RAT => cpp/RAT}/applyHydrationImag.h | 0 {RAT => cpp/RAT}/applyHydrationReal.cpp | 0 {RAT => cpp/RAT}/applyHydrationReal.h | 0 {RAT => cpp/RAT}/asinh.cpp | 0 {RAT => cpp/RAT}/asinh.h | 0 {RAT => cpp/RAT}/asymconvstep.cpp | 0 {RAT => cpp/RAT}/asymconvstep.h | 0 {RAT => cpp/RAT}/averageReflectivity.cpp | 0 {RAT => cpp/RAT}/averageReflectivity.h | 0 {RAT => cpp/RAT}/backSort.cpp | 0 {RAT => cpp/RAT}/backSort.h | 0 {RAT => cpp/RAT}/blockedSummation.cpp | 0 {RAT => cpp/RAT}/blockedSummation.h | 0 {RAT => cpp/RAT}/boundaryHandling.cpp | 0 {RAT => cpp/RAT}/boundaryHandling.h | 0 {RAT => cpp/RAT}/bsearch.cpp | 0 {RAT => cpp/RAT}/bsearch.h | 0 {RAT => cpp/RAT}/bsxfun.cpp | 0 {RAT => cpp/RAT}/bsxfun.h | 0 {RAT => cpp/RAT}/calcDensity.cpp | 0 {RAT => cpp/RAT}/calcDensity.h | 0 {RAT => cpp/RAT}/calcEllipsoid.cpp | 0 {RAT => cpp/RAT}/calcEllipsoid.h | 0 {RAT => cpp/RAT}/calcProposal.cpp | 0 {RAT => cpp/RAT}/calcProposal.h | 0 {RAT => cpp/RAT}/calculate.cpp | 0 {RAT => cpp/RAT}/calculate.h | 0 {RAT => cpp/RAT}/calculate1.cpp | 0 {RAT => cpp/RAT}/calculate1.h | 0 {RAT => cpp/RAT}/calculate2.cpp | 0 {RAT => cpp/RAT}/calculate2.h | 0 {RAT => cpp/RAT}/calculate3.cpp | 0 {RAT => cpp/RAT}/calculate3.h | 0 {RAT => cpp/RAT}/calculate4.cpp | 0 {RAT => cpp/RAT}/calculate4.h | 0 {RAT => cpp/RAT}/calculate5.cpp | 0 {RAT => cpp/RAT}/calculate5.h | 0 {RAT => cpp/RAT}/callCppFunction.cpp | 0 {RAT => cpp/RAT}/callCppFunction.h | 0 {RAT => cpp/RAT}/callReflectivity.cpp | 0 {RAT => cpp/RAT}/callReflectivity.h | 0 {RAT => cpp/RAT}/cat.cpp | 0 {RAT => cpp/RAT}/cat.h | 0 {RAT => cpp/RAT}/chiSquared.cpp | 0 {RAT => cpp/RAT}/chiSquared.h | 0 {RAT => cpp/RAT}/classHandle.hpp | 0 {RAT => cpp/RAT}/coder_array.h | 0 {RAT => cpp/RAT}/coder_bounded_array.h | 0 {RAT => cpp/RAT}/coder_posix_time.c | 0 {RAT => cpp/RAT}/coder_posix_time.h | 0 {RAT => cpp/RAT}/coder_setenv.c | 0 {RAT => cpp/RAT}/coder_setenv.h | 0 {RAT => cpp/RAT}/colon.cpp | 0 {RAT => cpp/RAT}/colon.h | 0 {RAT => cpp/RAT}/combineVectorElements.cpp | 0 {RAT => cpp/RAT}/combineVectorElements.h | 0 {RAT => cpp/RAT}/complexTimes.cpp | 0 {RAT => cpp/RAT}/complexTimes.h | 0 {RAT => cpp/RAT}/coreLayersCalculation.cpp | 0 {RAT => cpp/RAT}/coreLayersCalculation.h | 0 {RAT => cpp/RAT}/cov.cpp | 0 {RAT => cpp/RAT}/cov.h | 0 {RAT => cpp/RAT}/dataResolutionPolly.cpp | 0 {RAT => cpp/RAT}/dataResolutionPolly.h | 0 {RAT => cpp/RAT}/deopt.cpp | 0 {RAT => cpp/RAT}/deopt.h | 0 {RAT => cpp/RAT}/det.cpp | 0 {RAT => cpp/RAT}/det.h | 0 {RAT => cpp/RAT}/diag.cpp | 0 {RAT => cpp/RAT}/diag.h | 0 {RAT => cpp/RAT}/div.cpp | 0 {RAT => cpp/RAT}/div.h | 0 {RAT => cpp/RAT}/drawCR.cpp | 0 {RAT => cpp/RAT}/drawCR.h | 0 {RAT => cpp/RAT}/drawEllipsoidPoints.cpp | 0 {RAT => cpp/RAT}/drawEllipsoidPoints.h | 0 {RAT => cpp/RAT}/drawMCMC.cpp | 0 {RAT => cpp/RAT}/drawMCMC.h | 0 {RAT => cpp/RAT}/drawMultiNest.cpp | 0 {RAT => cpp/RAT}/drawMultiNest.h | 0 {RAT => cpp/RAT}/dylib.hpp | 0 {RAT => cpp/RAT}/eig.cpp | 0 {RAT => cpp/RAT}/eig.h | 0 {RAT => cpp/RAT}/eigHermitianStandard.cpp | 0 {RAT => cpp/RAT}/eigHermitianStandard.h | 0 .../RAT}/eigRealSkewSymmetricStandard.cpp | 0 .../RAT}/eigRealSkewSymmetricStandard.h | 0 {RAT => cpp/RAT}/eigSkewHermitianStandard.cpp | 0 {RAT => cpp/RAT}/eigSkewHermitianStandard.h | 0 {RAT => cpp/RAT}/eml_erfcore.cpp | 0 {RAT => cpp/RAT}/eml_erfcore.h | 0 {RAT => cpp/RAT}/eml_mtimes_helper.cpp | 0 {RAT => cpp/RAT}/eml_mtimes_helper.h | 0 {RAT => cpp/RAT}/eml_rand_mt19937ar.cpp | 0 {RAT => cpp/RAT}/eml_rand_mt19937ar.h | 0 .../RAT}/eml_rand_mt19937ar_stateful.cpp | 0 .../RAT}/eml_rand_mt19937ar_stateful.h | 0 {RAT => cpp/RAT}/eml_setop.cpp | 0 {RAT => cpp/RAT}/eml_setop.h | 0 {RAT => cpp/RAT}/eps.cpp | 0 {RAT => cpp/RAT}/eps.h | 0 {RAT => cpp/RAT}/erf.cpp | 0 {RAT => cpp/RAT}/erf.h | 0 {RAT => cpp/RAT}/evaluateModel.cpp | 0 {RAT => cpp/RAT}/evaluateModel.h | 0 {RAT => cpp/RAT}/eventHelper.hpp | 0 {events => cpp/RAT/events}/eventManager.cpp | 0 {events => cpp/RAT/events}/eventManager.h | 0 .../RAT/events}/eventManagerImpl.hpp | 0 {RAT => cpp/RAT}/examples/main.cpp | 0 {RAT => cpp/RAT}/examples/main.h | 0 {RAT => cpp/RAT}/exp.cpp | 0 {RAT => cpp/RAT}/exp.h | 0 {RAT => cpp/RAT}/eye.cpp | 0 {RAT => cpp/RAT}/eye.h | 0 {RAT => cpp/RAT}/fMinSearch.cpp | 0 {RAT => cpp/RAT}/fMinSearch.h | 0 {RAT => cpp/RAT}/fileManager.cpp | 0 {RAT => cpp/RAT}/fileManager.h | 0 {RAT => cpp/RAT}/find.cpp | 0 {RAT => cpp/RAT}/find.h | 0 {RAT => cpp/RAT}/flip.cpp | 0 {RAT => cpp/RAT}/flip.h | 0 {RAT => cpp/RAT}/gamma.cpp | 0 {RAT => cpp/RAT}/gamma.h | 0 {RAT => cpp/RAT}/gelman.cpp | 0 {RAT => cpp/RAT}/gelman.h | 0 {RAT => cpp/RAT}/getFittedPriors.cpp | 0 {RAT => cpp/RAT}/getFittedPriors.h | 0 {RAT => cpp/RAT}/getTime.cpp | 0 {RAT => cpp/RAT}/getTime.h | 0 {RAT => cpp/RAT}/getenv.cpp | 0 {RAT => cpp/RAT}/getenv.h | 0 {RAT => cpp/RAT}/groupLayersMod.cpp | 0 {RAT => cpp/RAT}/groupLayersMod.h | 0 {RAT => cpp/RAT}/groupLayersModImaginary.cpp | 0 {RAT => cpp/RAT}/groupLayersModImaginary.h | 0 {RAT => cpp/RAT}/histc.cpp | 0 {RAT => cpp/RAT}/histc.h | 0 {RAT => cpp/RAT}/ifWhileCond.cpp | 0 {RAT => cpp/RAT}/ifWhileCond.h | 0 {RAT => cpp/RAT}/inEllipsoids.cpp | 0 {RAT => cpp/RAT}/inEllipsoids.h | 0 {RAT => cpp/RAT}/initializeDREAM.cpp | 0 {RAT => cpp/RAT}/initializeDREAM.h | 0 {RAT => cpp/RAT}/interp1.cpp | 0 {RAT => cpp/RAT}/interp1.h | 0 {RAT => cpp/RAT}/ishermitian.cpp | 0 {RAT => cpp/RAT}/ishermitian.h | 0 {RAT => cpp/RAT}/isrow.cpp | 0 {RAT => cpp/RAT}/isrow.h | 0 {RAT => cpp/RAT}/ixamax.cpp | 0 {RAT => cpp/RAT}/ixamax.h | 0 {RAT => cpp/RAT}/ixfun.cpp | 0 {RAT => cpp/RAT}/ixfun.h | 0 {RAT => cpp/RAT}/kmeans.cpp | 0 {RAT => cpp/RAT}/kmeans.h | 0 {RAT => cpp/RAT}/leftWin.cpp | 0 {RAT => cpp/RAT}/leftWin.h | 0 {RAT => cpp/RAT}/length.cpp | 0 {RAT => cpp/RAT}/length.h | 0 {RAT => cpp/RAT}/linspace.cpp | 0 {RAT => cpp/RAT}/linspace.h | 0 {RAT => cpp/RAT}/log1p.cpp | 0 {RAT => cpp/RAT}/log1p.h | 0 {RAT => cpp/RAT}/log2.cpp | 0 {RAT => cpp/RAT}/log2.h | 0 {RAT => cpp/RAT}/logPlus.cpp | 0 {RAT => cpp/RAT}/logPlus.h | 0 {RAT => cpp/RAT}/lower.cpp | 0 {RAT => cpp/RAT}/lower.h | 0 {RAT => cpp/RAT}/lusolve.cpp | 0 {RAT => cpp/RAT}/lusolve.h | 0 {RAT => cpp/RAT}/makeCell.cpp | 0 {RAT => cpp/RAT}/makeCell.h | 0 {RAT => cpp/RAT}/makeD.cpp | 0 {RAT => cpp/RAT}/makeD.h | 0 .../RAT}/makeEmptyBayesResultsStruct.cpp | 0 .../RAT}/makeEmptyBayesResultsStruct.h | 0 {RAT => cpp/RAT}/makeSLDProfileXY.cpp | 0 {RAT => cpp/RAT}/makeSLDProfileXY.h | 0 {RAT => cpp/RAT}/makeSLDProfiles.cpp | 0 {RAT => cpp/RAT}/makeSLDProfiles.h | 0 {RAT => cpp/RAT}/matrix_to_integer_power.cpp | 0 {RAT => cpp/RAT}/matrix_to_integer_power.h | 0 {RAT => cpp/RAT}/mchol.cpp | 0 {RAT => cpp/RAT}/mchol.h | 0 {RAT => cpp/RAT}/mean.cpp | 0 {RAT => cpp/RAT}/mean.h | 0 {RAT => cpp/RAT}/mergesort.cpp | 0 {RAT => cpp/RAT}/mergesort.h | 0 {RAT => cpp/RAT}/metropolisRule.cpp | 0 {RAT => cpp/RAT}/metropolisRule.h | 0 {RAT => cpp/RAT}/minOrMax.cpp | 0 {RAT => cpp/RAT}/minOrMax.h | 0 {RAT => cpp/RAT}/mod.cpp | 0 {RAT => cpp/RAT}/mod.h | 0 {RAT => cpp/RAT}/mrdivide_helper.cpp | 0 {RAT => cpp/RAT}/mrdivide_helper.h | 0 {RAT => cpp/RAT}/mtimes.cpp | 0 {RAT => cpp/RAT}/mtimes.h | 0 {RAT => cpp/RAT}/multrnd.cpp | 0 {RAT => cpp/RAT}/multrnd.h | 0 {RAT => cpp/RAT}/nest2pos.cpp | 0 {RAT => cpp/RAT}/nest2pos.h | 0 {RAT => cpp/RAT}/nestedSampler.cpp | 0 {RAT => cpp/RAT}/nestedSampler.h | 0 {RAT => cpp/RAT}/nonSingletonDim.cpp | 0 {RAT => cpp/RAT}/nonSingletonDim.h | 0 {RAT => cpp/RAT}/norm.cpp | 0 {RAT => cpp/RAT}/norm.h | 0 {RAT => cpp/RAT}/nsIntraFun.cpp | 0 {RAT => cpp/RAT}/nsIntraFun.h | 0 {RAT => cpp/RAT}/nullAssignment.cpp | 0 {RAT => cpp/RAT}/nullAssignment.h | 0 {RAT => cpp/RAT}/optimalEllipsoids.cpp | 0 {RAT => cpp/RAT}/optimalEllipsoids.h | 0 {RAT => cpp/RAT}/packParams.cpp | 0 {RAT => cpp/RAT}/packParams.h | 0 {RAT => cpp/RAT}/parallelContrasts.cpp | 0 {RAT => cpp/RAT}/parallelContrasts.h | 0 {RAT => cpp/RAT}/parallelContrasts1.cpp | 0 {RAT => cpp/RAT}/parallelContrasts1.h | 0 {RAT => cpp/RAT}/parallelContrasts2.cpp | 0 {RAT => cpp/RAT}/parallelContrasts2.h | 0 {RAT => cpp/RAT}/parallelContrasts3.cpp | 0 {RAT => cpp/RAT}/parallelContrasts3.h | 0 {RAT => cpp/RAT}/parallelContrasts4.cpp | 0 {RAT => cpp/RAT}/parallelContrasts4.h | 0 {RAT => cpp/RAT}/parallelContrasts5.cpp | 0 {RAT => cpp/RAT}/parallelContrasts5.h | 0 {RAT => cpp/RAT}/parallelPoints.cpp | 0 {RAT => cpp/RAT}/parallelPoints.h | 0 {RAT => cpp/RAT}/parallelPoints1.cpp | 0 {RAT => cpp/RAT}/parallelPoints1.h | 0 {RAT => cpp/RAT}/parallelPoints2.cpp | 0 {RAT => cpp/RAT}/parallelPoints2.h | 0 {RAT => cpp/RAT}/parallelPoints3.cpp | 0 {RAT => cpp/RAT}/parallelPoints3.h | 0 {RAT => cpp/RAT}/parallelPoints4.cpp | 0 {RAT => cpp/RAT}/parallelPoints4.h | 0 {RAT => cpp/RAT}/parallelPoints5.cpp | 0 {RAT => cpp/RAT}/parallelPoints5.h | 0 {RAT => cpp/RAT}/parseResultToStruct.cpp | 0 {RAT => cpp/RAT}/parseResultToStruct.h | 0 {RAT => cpp/RAT}/pow2.cpp | 0 {RAT => cpp/RAT}/pow2.h | 0 {RAT => cpp/RAT}/prctile.cpp | 0 {RAT => cpp/RAT}/prctile.h | 0 {RAT => cpp/RAT}/prctileConfInts.cpp | 0 {RAT => cpp/RAT}/prctileConfInts.h | 0 {RAT => cpp/RAT}/processBayes.cpp | 0 {RAT => cpp/RAT}/processBayes.h | 0 {RAT => cpp/RAT}/processCustomFunction.cpp | 0 {RAT => cpp/RAT}/processCustomFunction.h | 0 {RAT => cpp/RAT}/processCustomFunction1.cpp | 0 {RAT => cpp/RAT}/processCustomFunction1.h | 0 {RAT => cpp/RAT}/processCustomFunction2.cpp | 0 {RAT => cpp/RAT}/processCustomFunction2.h | 0 {RAT => cpp/RAT}/processCustomFunction3.cpp | 0 {RAT => cpp/RAT}/processCustomFunction3.h | 0 {RAT => cpp/RAT}/qrsolve.cpp | 0 {RAT => cpp/RAT}/qrsolve.h | 0 {RAT => cpp/RAT}/rand.cpp | 0 {RAT => cpp/RAT}/rand.h | 0 {RAT => cpp/RAT}/randn.cpp | 0 {RAT => cpp/RAT}/randn.h | 0 {RAT => cpp/RAT}/randperm.cpp | 0 {RAT => cpp/RAT}/randperm.h | 0 {RAT => cpp/RAT}/randsample.cpp | 0 {RAT => cpp/RAT}/randsample.h | 0 {RAT => cpp/RAT}/ratDREAM.cpp | 0 {RAT => cpp/RAT}/ratDREAM.h | 0 {RAT => cpp/RAT}/rcond.cpp | 0 {RAT => cpp/RAT}/rcond.h | 0 {RAT => cpp/RAT}/rdivide_helper.cpp | 0 {RAT => cpp/RAT}/rdivide_helper.h | 0 {RAT => cpp/RAT}/refPrctileConfInts.cpp | 0 {RAT => cpp/RAT}/refPrctileConfInts.h | 0 {RAT => cpp/RAT}/reflectivityCalculation.cpp | 0 {RAT => cpp/RAT}/reflectivityCalculation.h | 0 {RAT => cpp/RAT}/reflectivityCalculation1.cpp | 0 {RAT => cpp/RAT}/reflectivityCalculation1.h | 0 {RAT => cpp/RAT}/reflectivityCalculation2.cpp | 0 {RAT => cpp/RAT}/reflectivityCalculation2.h | 0 {RAT => cpp/RAT}/relop.cpp | 0 {RAT => cpp/RAT}/relop.h | 0 {RAT => cpp/RAT}/removeOutlier.cpp | 0 {RAT => cpp/RAT}/removeOutlier.h | 0 {RAT => cpp/RAT}/repmat.cpp | 0 {RAT => cpp/RAT}/repmat.h | 0 {RAT => cpp/RAT}/resampleLayers.cpp | 0 {RAT => cpp/RAT}/resampleLayers.h | 0 {RAT => cpp/RAT}/resampleLayersReIm.cpp | 0 {RAT => cpp/RAT}/resampleLayersReIm.h | 0 {RAT => cpp/RAT}/rescale.cpp | 0 {RAT => cpp/RAT}/rescale.h | 0 {RAT => cpp/RAT}/rescaleKernel.cpp | 0 {RAT => cpp/RAT}/rescaleKernel.h | 0 {RAT => cpp/RAT}/rescaleParameters.cpp | 0 {RAT => cpp/RAT}/rescaleParameters.h | 0 {RAT => cpp/RAT}/reshapeSizeChecks.cpp | 0 {RAT => cpp/RAT}/reshapeSizeChecks.h | 0 {RAT => cpp/RAT}/resolutionPolly.cpp | 0 {RAT => cpp/RAT}/resolutionPolly.h | 0 {RAT => cpp/RAT}/rng.cpp | 0 {RAT => cpp/RAT}/rng.h | 0 {RAT => cpp/RAT}/rtGetInf.cpp | 0 {RAT => cpp/RAT}/rtGetInf.h | 0 {RAT => cpp/RAT}/rtGetNaN.cpp | 0 {RAT => cpp/RAT}/rtGetNaN.h | 0 {RAT => cpp/RAT}/rt_defines.h | 0 {RAT => cpp/RAT}/rt_nonfinite.cpp | 0 {RAT => cpp/RAT}/rt_nonfinite.h | 0 {RAT => cpp/RAT}/rtwtypes.h | 0 {RAT => cpp/RAT}/runDE.cpp | 0 {RAT => cpp/RAT}/runDE.h | 0 {RAT => cpp/RAT}/runDREAM.cpp | 0 {RAT => cpp/RAT}/runDREAM.h | 0 {RAT => cpp/RAT}/runNestedSampler.cpp | 0 {RAT => cpp/RAT}/runNestedSampler.h | 0 {RAT => cpp/RAT}/runSimplex.cpp | 0 {RAT => cpp/RAT}/runSimplex.h | 0 {RAT => cpp/RAT}/scaleParameters.cpp | 0 {RAT => cpp/RAT}/scaleParameters.h | 0 {RAT => cpp/RAT}/scaledGaussPrior.cpp | 0 {RAT => cpp/RAT}/scaledGaussPrior.h | 0 {RAT => cpp/RAT}/schur.cpp | 0 {RAT => cpp/RAT}/schur.h | 0 {RAT => cpp/RAT}/setupDREAM.cpp | 0 {RAT => cpp/RAT}/setupDREAM.h | 0 {RAT => cpp/RAT}/shiftData.cpp | 0 {RAT => cpp/RAT}/shiftData.h | 0 {RAT => cpp/RAT}/simplexIntrafun.cpp | 0 {RAT => cpp/RAT}/simplexIntrafun.h | 0 {RAT => cpp/RAT}/simplexXTransform.cpp | 0 {RAT => cpp/RAT}/simplexXTransform.h | 0 {RAT => cpp/RAT}/single.cpp | 0 {RAT => cpp/RAT}/single.h | 0 {RAT => cpp/RAT}/single1.cpp | 0 {RAT => cpp/RAT}/single1.h | 0 {RAT => cpp/RAT}/single2.cpp | 0 {RAT => cpp/RAT}/single2.h | 0 {RAT => cpp/RAT}/single3.cpp | 0 {RAT => cpp/RAT}/single3.h | 0 {RAT => cpp/RAT}/single4.cpp | 0 {RAT => cpp/RAT}/single4.h | 0 {RAT => cpp/RAT}/single5.cpp | 0 {RAT => cpp/RAT}/single5.h | 0 {RAT => cpp/RAT}/sort.cpp | 0 {RAT => cpp/RAT}/sort.h | 0 {RAT => cpp/RAT}/sortAscendLE.cpp | 0 {RAT => cpp/RAT}/sortAscendLE.h | 0 {RAT => cpp/RAT}/sortIdx.cpp | 0 {RAT => cpp/RAT}/sortIdx.h | 0 {RAT => cpp/RAT}/sortLE.cpp | 0 {RAT => cpp/RAT}/sortLE.h | 0 {RAT => cpp/RAT}/sortrows.cpp | 0 {RAT => cpp/RAT}/sortrows.h | 0 {RAT => cpp/RAT}/splitEllipsoid.cpp | 0 {RAT => cpp/RAT}/splitEllipsoid.h | 0 {RAT => cpp/RAT}/sprintf.cpp | 0 {RAT => cpp/RAT}/sprintf.h | 0 {RAT => cpp/RAT}/sqrt.cpp | 0 {RAT => cpp/RAT}/sqrt.h | 0 {RAT => cpp/RAT}/sqrt1.cpp | 0 {RAT => cpp/RAT}/sqrt1.h | 0 {RAT => cpp/RAT}/std.cpp | 0 {RAT => cpp/RAT}/std.h | 0 {RAT => cpp/RAT}/str2double.cpp | 0 {RAT => cpp/RAT}/str2double.h | 0 {RAT => cpp/RAT}/str2double1.cpp | 0 {RAT => cpp/RAT}/str2double1.h | 0 {RAT => cpp/RAT}/strcmp.cpp | 0 {RAT => cpp/RAT}/strcmp.h | 0 {RAT => cpp/RAT}/structConstructorHelper.cpp | 0 {RAT => cpp/RAT}/structConstructorHelper.h | 0 {RAT => cpp/RAT}/sum.cpp | 0 {RAT => cpp/RAT}/sum.h | 0 {RAT => cpp/RAT}/textProgressBar.cpp | 0 {RAT => cpp/RAT}/textProgressBar.h | 0 {RAT => cpp/RAT}/tic.cpp | 0 {RAT => cpp/RAT}/tic.h | 0 {RAT => cpp/RAT}/timeKeeper.cpp | 0 {RAT => cpp/RAT}/timeKeeper.h | 0 {RAT => cpp/RAT}/tmwtypes.h | 0 {RAT => cpp/RAT}/toc.cpp | 0 {RAT => cpp/RAT}/toc.h | 0 {RAT => cpp/RAT}/triggerEvent.cpp | 0 {RAT => cpp/RAT}/triggerEvent.h | 0 {RAT => cpp/RAT}/triu.cpp | 0 {RAT => cpp/RAT}/triu.h | 0 {RAT => cpp/RAT}/unpackParams.cpp | 0 {RAT => cpp/RAT}/unpackParams.h | 0 {RAT => cpp/RAT}/unsafeSxfun.cpp | 0 {RAT => cpp/RAT}/unsafeSxfun.h | 0 {RAT => cpp/RAT}/useConstantDim.cpp | 0 {RAT => cpp/RAT}/useConstantDim.h | 0 {RAT => cpp/RAT}/vAllOrAny.cpp | 0 {RAT => cpp/RAT}/vAllOrAny.h | 0 {RAT => cpp/RAT}/validate_print_arguments.cpp | 0 {RAT => cpp/RAT}/validate_print_arguments.h | 0 {RAT => cpp/RAT}/var.cpp | 0 {RAT => cpp/RAT}/var.h | 0 {RAT => cpp/RAT}/varstd.cpp | 0 {RAT => cpp/RAT}/varstd.h | 0 {RAT => cpp/RAT}/xdhseqr.cpp | 0 {RAT => cpp/RAT}/xdhseqr.h | 0 {RAT => cpp/RAT}/xdlanv2.cpp | 0 {RAT => cpp/RAT}/xdlanv2.h | 0 {RAT => cpp/RAT}/xgehrd.cpp | 0 {RAT => cpp/RAT}/xgehrd.h | 0 {RAT => cpp/RAT}/xgemm.cpp | 0 {RAT => cpp/RAT}/xgemm.h | 0 {RAT => cpp/RAT}/xgemv.cpp | 0 {RAT => cpp/RAT}/xgemv.h | 0 {RAT => cpp/RAT}/xgeqp3.cpp | 0 {RAT => cpp/RAT}/xgeqp3.h | 0 {RAT => cpp/RAT}/xgerc.cpp | 0 {RAT => cpp/RAT}/xgerc.h | 0 {RAT => cpp/RAT}/xgeru.cpp | 0 {RAT => cpp/RAT}/xgeru.h | 0 {RAT => cpp/RAT}/xgetrf.cpp | 0 {RAT => cpp/RAT}/xgetrf.h | 0 {RAT => cpp/RAT}/xnrm2.cpp | 0 {RAT => cpp/RAT}/xnrm2.h | 0 {RAT => cpp/RAT}/xrot.cpp | 0 {RAT => cpp/RAT}/xrot.h | 0 {RAT => cpp/RAT}/xswap.cpp | 0 {RAT => cpp/RAT}/xswap.h | 0 {RAT => cpp/RAT}/xtrsm.cpp | 0 {RAT => cpp/RAT}/xtrsm.h | 0 {RAT => cpp/RAT}/xtrsv.cpp | 0 {RAT => cpp/RAT}/xtrsv.h | 0 {RAT => cpp/RAT}/xungorghr.cpp | 0 {RAT => cpp/RAT}/xungorghr.h | 0 {RAT => cpp/RAT}/xunormqr.cpp | 0 {RAT => cpp/RAT}/xunormqr.h | 0 {RAT => cpp/RAT}/xzgeev.cpp | 0 {RAT => cpp/RAT}/xzgeev.h | 0 {RAT => cpp/RAT}/xzgeqp3.cpp | 0 {RAT => cpp/RAT}/xzgeqp3.h | 0 {RAT => cpp/RAT}/xzggbak.cpp | 0 {RAT => cpp/RAT}/xzggbak.h | 0 {RAT => cpp/RAT}/xzggbal.cpp | 0 {RAT => cpp/RAT}/xzggbal.h | 0 {RAT => cpp/RAT}/xzggev.cpp | 0 {RAT => cpp/RAT}/xzggev.h | 0 {RAT => cpp/RAT}/xzgghrd.cpp | 0 {RAT => cpp/RAT}/xzgghrd.h | 0 {RAT => cpp/RAT}/xzhgeqz.cpp | 0 {RAT => cpp/RAT}/xzhgeqz.h | 0 {RAT => cpp/RAT}/xzlangeM.cpp | 0 {RAT => cpp/RAT}/xzlangeM.h | 0 {RAT => cpp/RAT}/xzlanhs.cpp | 0 {RAT => cpp/RAT}/xzlanhs.h | 0 {RAT => cpp/RAT}/xzlarf.cpp | 0 {RAT => cpp/RAT}/xzlarf.h | 0 {RAT => cpp/RAT}/xzlarfg.cpp | 0 {RAT => cpp/RAT}/xzlarfg.h | 0 {RAT => cpp/RAT}/xzlartg.cpp | 0 {RAT => cpp/RAT}/xzlartg.h | 0 {RAT => cpp/RAT}/xzlascl.cpp | 0 {RAT => cpp/RAT}/xzlascl.h | 0 {RAT => cpp/RAT}/xztgevc.cpp | 0 {RAT => cpp/RAT}/xztgevc.h | 0 {RAT => cpp/RAT}/xzungqr.cpp | 0 {RAT => cpp/RAT}/xzungqr.h | 0 rat.cpp => cpp/rat.cpp | 6 +- .../DSPC_bilayer_example.py | 16 +- .../DSPC_custom_layers_example.py | 25 ++- alloyDomains.cpp => examples/alloyDomains.cpp | 0 alloyDomains.m => examples/alloyDomains.m | 0 alloyDomains.py => examples/alloyDomains.py | 0 customBilayer.m => examples/customBilayer.m | 0 customBilayer.py => examples/customBilayer.py | 0 .../domains_custom_layers_example.py | 22 ++- pyproject.toml | 9 ++ rat/__init__.py | 4 + events.py => rat/events.py | 15 +- misc.py => rat/misc.py | 6 +- requirements.txt | 3 +- setup.py | 150 ++++++++++++++++++ 528 files changed, 211 insertions(+), 61 deletions(-) rename {RAT => cpp/RAT}/CoderTimeAPI.cpp (100%) rename {RAT => cpp/RAT}/CoderTimeAPI.h (100%) rename {RAT => cpp/RAT}/DREAMWrapper.cpp (100%) rename {RAT => cpp/RAT}/DREAMWrapper.h (100%) rename {RAT => cpp/RAT}/RATMain.cpp (100%) rename {RAT => cpp/RAT}/RATMain.h (100%) rename {RAT => cpp/RAT}/RATMain_data.cpp (100%) rename {RAT => cpp/RAT}/RATMain_data.h (100%) rename {RAT => cpp/RAT}/RATMain_initialize.cpp (100%) rename {RAT => cpp/RAT}/RATMain_initialize.h (100%) rename {RAT => cpp/RAT}/RATMain_internal_types.h (100%) rename {RAT => cpp/RAT}/RATMain_rtwutil.cpp (100%) rename {RAT => cpp/RAT}/RATMain_rtwutil.h (100%) rename {RAT => cpp/RAT}/RATMain_terminate.cpp (100%) rename {RAT => cpp/RAT}/RATMain_terminate.h (100%) rename {RAT => cpp/RAT}/RATMain_types.h (100%) rename {RAT => cpp/RAT}/SLDFunction.cpp (100%) rename {RAT => cpp/RAT}/SLDFunction.h (100%) rename {RAT => cpp/RAT}/abelesParallelPoints.cpp (100%) rename {RAT => cpp/RAT}/abelesParallelPoints.h (100%) rename {RAT => cpp/RAT}/abelesSingle.cpp (100%) rename {RAT => cpp/RAT}/abelesSingle.h (100%) rename {RAT => cpp/RAT}/abs.cpp (100%) rename {RAT => cpp/RAT}/abs.h (100%) rename {RAT => cpp/RAT}/acos.cpp (100%) rename {RAT => cpp/RAT}/acos.h (100%) rename {RAT => cpp/RAT}/adaptPCR.cpp (100%) rename {RAT => cpp/RAT}/adaptPCR.h (100%) rename {RAT => cpp/RAT}/adaptive.cpp (100%) rename {RAT => cpp/RAT}/adaptive.h (100%) rename {RAT => cpp/RAT}/all.cpp (100%) rename {RAT => cpp/RAT}/all.h (100%) rename {RAT => cpp/RAT}/allOrAny.cpp (100%) rename {RAT => cpp/RAT}/allOrAny.h (100%) rename {RAT => cpp/RAT}/allocateLayersForContrast.cpp (100%) rename {RAT => cpp/RAT}/allocateLayersForContrast.h (100%) rename {RAT => cpp/RAT}/allocateParamsToLayers.cpp (100%) rename {RAT => cpp/RAT}/allocateParamsToLayers.h (100%) rename {RAT => cpp/RAT}/anyNonFinite.cpp (100%) rename {RAT => cpp/RAT}/anyNonFinite.h (100%) rename {RAT => cpp/RAT}/applyBackgroundCorrection.cpp (100%) rename {RAT => cpp/RAT}/applyBackgroundCorrection.h (100%) rename {RAT => cpp/RAT}/applyHydrationImag.cpp (100%) rename {RAT => cpp/RAT}/applyHydrationImag.h (100%) rename {RAT => cpp/RAT}/applyHydrationReal.cpp (100%) rename {RAT => cpp/RAT}/applyHydrationReal.h (100%) rename {RAT => cpp/RAT}/asinh.cpp (100%) rename {RAT => cpp/RAT}/asinh.h (100%) rename {RAT => cpp/RAT}/asymconvstep.cpp (100%) rename {RAT => cpp/RAT}/asymconvstep.h (100%) rename {RAT => cpp/RAT}/averageReflectivity.cpp (100%) rename {RAT => cpp/RAT}/averageReflectivity.h (100%) rename {RAT => cpp/RAT}/backSort.cpp (100%) rename {RAT => cpp/RAT}/backSort.h (100%) rename {RAT => cpp/RAT}/blockedSummation.cpp (100%) rename {RAT => cpp/RAT}/blockedSummation.h (100%) rename {RAT => cpp/RAT}/boundaryHandling.cpp (100%) rename {RAT => cpp/RAT}/boundaryHandling.h (100%) rename {RAT => cpp/RAT}/bsearch.cpp (100%) rename {RAT => cpp/RAT}/bsearch.h (100%) rename {RAT => cpp/RAT}/bsxfun.cpp (100%) rename {RAT => cpp/RAT}/bsxfun.h (100%) rename {RAT => cpp/RAT}/calcDensity.cpp (100%) rename {RAT => cpp/RAT}/calcDensity.h (100%) rename {RAT => cpp/RAT}/calcEllipsoid.cpp (100%) rename {RAT => cpp/RAT}/calcEllipsoid.h (100%) rename {RAT => cpp/RAT}/calcProposal.cpp (100%) rename {RAT => cpp/RAT}/calcProposal.h (100%) rename {RAT => cpp/RAT}/calculate.cpp (100%) rename {RAT => cpp/RAT}/calculate.h (100%) rename {RAT => cpp/RAT}/calculate1.cpp (100%) rename {RAT => cpp/RAT}/calculate1.h (100%) rename {RAT => cpp/RAT}/calculate2.cpp (100%) rename {RAT => cpp/RAT}/calculate2.h (100%) rename {RAT => cpp/RAT}/calculate3.cpp (100%) rename {RAT => cpp/RAT}/calculate3.h (100%) rename {RAT => cpp/RAT}/calculate4.cpp (100%) rename {RAT => cpp/RAT}/calculate4.h (100%) rename {RAT => cpp/RAT}/calculate5.cpp (100%) rename {RAT => cpp/RAT}/calculate5.h (100%) rename {RAT => cpp/RAT}/callCppFunction.cpp (100%) rename {RAT => cpp/RAT}/callCppFunction.h (100%) rename {RAT => cpp/RAT}/callReflectivity.cpp (100%) rename {RAT => cpp/RAT}/callReflectivity.h (100%) rename {RAT => cpp/RAT}/cat.cpp (100%) rename {RAT => cpp/RAT}/cat.h (100%) rename {RAT => cpp/RAT}/chiSquared.cpp (100%) rename {RAT => cpp/RAT}/chiSquared.h (100%) rename {RAT => cpp/RAT}/classHandle.hpp (100%) rename {RAT => cpp/RAT}/coder_array.h (100%) rename {RAT => cpp/RAT}/coder_bounded_array.h (100%) rename {RAT => cpp/RAT}/coder_posix_time.c (100%) rename {RAT => cpp/RAT}/coder_posix_time.h (100%) rename {RAT => cpp/RAT}/coder_setenv.c (100%) rename {RAT => cpp/RAT}/coder_setenv.h (100%) rename {RAT => cpp/RAT}/colon.cpp (100%) rename {RAT => cpp/RAT}/colon.h (100%) rename {RAT => cpp/RAT}/combineVectorElements.cpp (100%) rename {RAT => cpp/RAT}/combineVectorElements.h (100%) rename {RAT => cpp/RAT}/complexTimes.cpp (100%) rename {RAT => cpp/RAT}/complexTimes.h (100%) rename {RAT => cpp/RAT}/coreLayersCalculation.cpp (100%) rename {RAT => cpp/RAT}/coreLayersCalculation.h (100%) rename {RAT => cpp/RAT}/cov.cpp (100%) rename {RAT => cpp/RAT}/cov.h (100%) rename {RAT => cpp/RAT}/dataResolutionPolly.cpp (100%) rename {RAT => cpp/RAT}/dataResolutionPolly.h (100%) rename {RAT => cpp/RAT}/deopt.cpp (100%) rename {RAT => cpp/RAT}/deopt.h (100%) rename {RAT => cpp/RAT}/det.cpp (100%) rename {RAT => cpp/RAT}/det.h (100%) rename {RAT => cpp/RAT}/diag.cpp (100%) rename {RAT => cpp/RAT}/diag.h (100%) rename {RAT => cpp/RAT}/div.cpp (100%) rename {RAT => cpp/RAT}/div.h (100%) rename {RAT => cpp/RAT}/drawCR.cpp (100%) rename {RAT => cpp/RAT}/drawCR.h (100%) rename {RAT => cpp/RAT}/drawEllipsoidPoints.cpp (100%) rename {RAT => cpp/RAT}/drawEllipsoidPoints.h (100%) rename {RAT => cpp/RAT}/drawMCMC.cpp (100%) rename {RAT => cpp/RAT}/drawMCMC.h (100%) rename {RAT => cpp/RAT}/drawMultiNest.cpp (100%) rename {RAT => cpp/RAT}/drawMultiNest.h (100%) rename {RAT => cpp/RAT}/dylib.hpp (100%) rename {RAT => cpp/RAT}/eig.cpp (100%) rename {RAT => cpp/RAT}/eig.h (100%) rename {RAT => cpp/RAT}/eigHermitianStandard.cpp (100%) rename {RAT => cpp/RAT}/eigHermitianStandard.h (100%) rename {RAT => cpp/RAT}/eigRealSkewSymmetricStandard.cpp (100%) rename {RAT => cpp/RAT}/eigRealSkewSymmetricStandard.h (100%) rename {RAT => cpp/RAT}/eigSkewHermitianStandard.cpp (100%) rename {RAT => cpp/RAT}/eigSkewHermitianStandard.h (100%) rename {RAT => cpp/RAT}/eml_erfcore.cpp (100%) rename {RAT => cpp/RAT}/eml_erfcore.h (100%) rename {RAT => cpp/RAT}/eml_mtimes_helper.cpp (100%) rename {RAT => cpp/RAT}/eml_mtimes_helper.h (100%) rename {RAT => cpp/RAT}/eml_rand_mt19937ar.cpp (100%) rename {RAT => cpp/RAT}/eml_rand_mt19937ar.h (100%) rename {RAT => cpp/RAT}/eml_rand_mt19937ar_stateful.cpp (100%) rename {RAT => cpp/RAT}/eml_rand_mt19937ar_stateful.h (100%) rename {RAT => cpp/RAT}/eml_setop.cpp (100%) rename {RAT => cpp/RAT}/eml_setop.h (100%) rename {RAT => cpp/RAT}/eps.cpp (100%) rename {RAT => cpp/RAT}/eps.h (100%) rename {RAT => cpp/RAT}/erf.cpp (100%) rename {RAT => cpp/RAT}/erf.h (100%) rename {RAT => cpp/RAT}/evaluateModel.cpp (100%) rename {RAT => cpp/RAT}/evaluateModel.h (100%) rename {RAT => cpp/RAT}/eventHelper.hpp (100%) rename {events => cpp/RAT/events}/eventManager.cpp (100%) rename {events => cpp/RAT/events}/eventManager.h (100%) rename {events => cpp/RAT/events}/eventManagerImpl.hpp (100%) rename {RAT => cpp/RAT}/examples/main.cpp (100%) rename {RAT => cpp/RAT}/examples/main.h (100%) rename {RAT => cpp/RAT}/exp.cpp (100%) rename {RAT => cpp/RAT}/exp.h (100%) rename {RAT => cpp/RAT}/eye.cpp (100%) rename {RAT => cpp/RAT}/eye.h (100%) rename {RAT => cpp/RAT}/fMinSearch.cpp (100%) rename {RAT => cpp/RAT}/fMinSearch.h (100%) rename {RAT => cpp/RAT}/fileManager.cpp (100%) rename {RAT => cpp/RAT}/fileManager.h (100%) rename {RAT => cpp/RAT}/find.cpp (100%) rename {RAT => cpp/RAT}/find.h (100%) rename {RAT => cpp/RAT}/flip.cpp (100%) rename {RAT => cpp/RAT}/flip.h (100%) rename {RAT => cpp/RAT}/gamma.cpp (100%) rename {RAT => cpp/RAT}/gamma.h (100%) rename {RAT => cpp/RAT}/gelman.cpp (100%) rename {RAT => cpp/RAT}/gelman.h (100%) rename {RAT => cpp/RAT}/getFittedPriors.cpp (100%) rename {RAT => cpp/RAT}/getFittedPriors.h (100%) rename {RAT => cpp/RAT}/getTime.cpp (100%) rename {RAT => cpp/RAT}/getTime.h (100%) rename {RAT => cpp/RAT}/getenv.cpp (100%) rename {RAT => cpp/RAT}/getenv.h (100%) rename {RAT => cpp/RAT}/groupLayersMod.cpp (100%) rename {RAT => cpp/RAT}/groupLayersMod.h (100%) rename {RAT => cpp/RAT}/groupLayersModImaginary.cpp (100%) rename {RAT => cpp/RAT}/groupLayersModImaginary.h (100%) rename {RAT => cpp/RAT}/histc.cpp (100%) rename {RAT => cpp/RAT}/histc.h (100%) rename {RAT => cpp/RAT}/ifWhileCond.cpp (100%) rename {RAT => cpp/RAT}/ifWhileCond.h (100%) rename {RAT => cpp/RAT}/inEllipsoids.cpp (100%) rename {RAT => cpp/RAT}/inEllipsoids.h (100%) rename {RAT => cpp/RAT}/initializeDREAM.cpp (100%) rename {RAT => cpp/RAT}/initializeDREAM.h (100%) rename {RAT => cpp/RAT}/interp1.cpp (100%) rename {RAT => cpp/RAT}/interp1.h (100%) rename {RAT => cpp/RAT}/ishermitian.cpp (100%) rename {RAT => cpp/RAT}/ishermitian.h (100%) rename {RAT => cpp/RAT}/isrow.cpp (100%) rename {RAT => cpp/RAT}/isrow.h (100%) rename {RAT => cpp/RAT}/ixamax.cpp (100%) rename {RAT => cpp/RAT}/ixamax.h (100%) rename {RAT => cpp/RAT}/ixfun.cpp (100%) rename {RAT => cpp/RAT}/ixfun.h (100%) rename {RAT => cpp/RAT}/kmeans.cpp (100%) rename {RAT => cpp/RAT}/kmeans.h (100%) rename {RAT => cpp/RAT}/leftWin.cpp (100%) rename {RAT => cpp/RAT}/leftWin.h (100%) rename {RAT => cpp/RAT}/length.cpp (100%) rename {RAT => cpp/RAT}/length.h (100%) rename {RAT => cpp/RAT}/linspace.cpp (100%) rename {RAT => cpp/RAT}/linspace.h (100%) rename {RAT => cpp/RAT}/log1p.cpp (100%) rename {RAT => cpp/RAT}/log1p.h (100%) rename {RAT => cpp/RAT}/log2.cpp (100%) rename {RAT => cpp/RAT}/log2.h (100%) rename {RAT => cpp/RAT}/logPlus.cpp (100%) rename {RAT => cpp/RAT}/logPlus.h (100%) rename {RAT => cpp/RAT}/lower.cpp (100%) rename {RAT => cpp/RAT}/lower.h (100%) rename {RAT => cpp/RAT}/lusolve.cpp (100%) rename {RAT => cpp/RAT}/lusolve.h (100%) rename {RAT => cpp/RAT}/makeCell.cpp (100%) rename {RAT => cpp/RAT}/makeCell.h (100%) rename {RAT => cpp/RAT}/makeD.cpp (100%) rename {RAT => cpp/RAT}/makeD.h (100%) rename {RAT => cpp/RAT}/makeEmptyBayesResultsStruct.cpp (100%) rename {RAT => cpp/RAT}/makeEmptyBayesResultsStruct.h (100%) rename {RAT => cpp/RAT}/makeSLDProfileXY.cpp (100%) rename {RAT => cpp/RAT}/makeSLDProfileXY.h (100%) rename {RAT => cpp/RAT}/makeSLDProfiles.cpp (100%) rename {RAT => cpp/RAT}/makeSLDProfiles.h (100%) rename {RAT => cpp/RAT}/matrix_to_integer_power.cpp (100%) rename {RAT => cpp/RAT}/matrix_to_integer_power.h (100%) rename {RAT => cpp/RAT}/mchol.cpp (100%) rename {RAT => cpp/RAT}/mchol.h (100%) rename {RAT => cpp/RAT}/mean.cpp (100%) rename {RAT => cpp/RAT}/mean.h (100%) rename {RAT => cpp/RAT}/mergesort.cpp (100%) rename {RAT => cpp/RAT}/mergesort.h (100%) rename {RAT => cpp/RAT}/metropolisRule.cpp (100%) rename {RAT => cpp/RAT}/metropolisRule.h (100%) rename {RAT => cpp/RAT}/minOrMax.cpp (100%) rename {RAT => cpp/RAT}/minOrMax.h (100%) rename {RAT => cpp/RAT}/mod.cpp (100%) rename {RAT => cpp/RAT}/mod.h (100%) rename {RAT => cpp/RAT}/mrdivide_helper.cpp (100%) rename {RAT => cpp/RAT}/mrdivide_helper.h (100%) rename {RAT => cpp/RAT}/mtimes.cpp (100%) rename {RAT => cpp/RAT}/mtimes.h (100%) rename {RAT => cpp/RAT}/multrnd.cpp (100%) rename {RAT => cpp/RAT}/multrnd.h (100%) rename {RAT => cpp/RAT}/nest2pos.cpp (100%) rename {RAT => cpp/RAT}/nest2pos.h (100%) rename {RAT => cpp/RAT}/nestedSampler.cpp (100%) rename {RAT => cpp/RAT}/nestedSampler.h (100%) rename {RAT => cpp/RAT}/nonSingletonDim.cpp (100%) rename {RAT => cpp/RAT}/nonSingletonDim.h (100%) rename {RAT => cpp/RAT}/norm.cpp (100%) rename {RAT => cpp/RAT}/norm.h (100%) rename {RAT => cpp/RAT}/nsIntraFun.cpp (100%) rename {RAT => cpp/RAT}/nsIntraFun.h (100%) rename {RAT => cpp/RAT}/nullAssignment.cpp (100%) rename {RAT => cpp/RAT}/nullAssignment.h (100%) rename {RAT => cpp/RAT}/optimalEllipsoids.cpp (100%) rename {RAT => cpp/RAT}/optimalEllipsoids.h (100%) rename {RAT => cpp/RAT}/packParams.cpp (100%) rename {RAT => cpp/RAT}/packParams.h (100%) rename {RAT => cpp/RAT}/parallelContrasts.cpp (100%) rename {RAT => cpp/RAT}/parallelContrasts.h (100%) rename {RAT => cpp/RAT}/parallelContrasts1.cpp (100%) rename {RAT => cpp/RAT}/parallelContrasts1.h (100%) rename {RAT => cpp/RAT}/parallelContrasts2.cpp (100%) rename {RAT => cpp/RAT}/parallelContrasts2.h (100%) rename {RAT => cpp/RAT}/parallelContrasts3.cpp (100%) rename {RAT => cpp/RAT}/parallelContrasts3.h (100%) rename {RAT => cpp/RAT}/parallelContrasts4.cpp (100%) rename {RAT => cpp/RAT}/parallelContrasts4.h (100%) rename {RAT => cpp/RAT}/parallelContrasts5.cpp (100%) rename {RAT => cpp/RAT}/parallelContrasts5.h (100%) rename {RAT => cpp/RAT}/parallelPoints.cpp (100%) rename {RAT => cpp/RAT}/parallelPoints.h (100%) rename {RAT => cpp/RAT}/parallelPoints1.cpp (100%) rename {RAT => cpp/RAT}/parallelPoints1.h (100%) rename {RAT => cpp/RAT}/parallelPoints2.cpp (100%) rename {RAT => cpp/RAT}/parallelPoints2.h (100%) rename {RAT => cpp/RAT}/parallelPoints3.cpp (100%) rename {RAT => cpp/RAT}/parallelPoints3.h (100%) rename {RAT => cpp/RAT}/parallelPoints4.cpp (100%) rename {RAT => cpp/RAT}/parallelPoints4.h (100%) rename {RAT => cpp/RAT}/parallelPoints5.cpp (100%) rename {RAT => cpp/RAT}/parallelPoints5.h (100%) rename {RAT => cpp/RAT}/parseResultToStruct.cpp (100%) rename {RAT => cpp/RAT}/parseResultToStruct.h (100%) rename {RAT => cpp/RAT}/pow2.cpp (100%) rename {RAT => cpp/RAT}/pow2.h (100%) rename {RAT => cpp/RAT}/prctile.cpp (100%) rename {RAT => cpp/RAT}/prctile.h (100%) rename {RAT => cpp/RAT}/prctileConfInts.cpp (100%) rename {RAT => cpp/RAT}/prctileConfInts.h (100%) rename {RAT => cpp/RAT}/processBayes.cpp (100%) rename {RAT => cpp/RAT}/processBayes.h (100%) rename {RAT => cpp/RAT}/processCustomFunction.cpp (100%) rename {RAT => cpp/RAT}/processCustomFunction.h (100%) rename {RAT => cpp/RAT}/processCustomFunction1.cpp (100%) rename {RAT => cpp/RAT}/processCustomFunction1.h (100%) rename {RAT => cpp/RAT}/processCustomFunction2.cpp (100%) rename {RAT => cpp/RAT}/processCustomFunction2.h (100%) rename {RAT => cpp/RAT}/processCustomFunction3.cpp (100%) rename {RAT => cpp/RAT}/processCustomFunction3.h (100%) rename {RAT => cpp/RAT}/qrsolve.cpp (100%) rename {RAT => cpp/RAT}/qrsolve.h (100%) rename {RAT => cpp/RAT}/rand.cpp (100%) rename {RAT => cpp/RAT}/rand.h (100%) rename {RAT => cpp/RAT}/randn.cpp (100%) rename {RAT => cpp/RAT}/randn.h (100%) rename {RAT => cpp/RAT}/randperm.cpp (100%) rename {RAT => cpp/RAT}/randperm.h (100%) rename {RAT => cpp/RAT}/randsample.cpp (100%) rename {RAT => cpp/RAT}/randsample.h (100%) rename {RAT => cpp/RAT}/ratDREAM.cpp (100%) rename {RAT => cpp/RAT}/ratDREAM.h (100%) rename {RAT => cpp/RAT}/rcond.cpp (100%) rename {RAT => cpp/RAT}/rcond.h (100%) rename {RAT => cpp/RAT}/rdivide_helper.cpp (100%) rename {RAT => cpp/RAT}/rdivide_helper.h (100%) rename {RAT => cpp/RAT}/refPrctileConfInts.cpp (100%) rename {RAT => cpp/RAT}/refPrctileConfInts.h (100%) rename {RAT => cpp/RAT}/reflectivityCalculation.cpp (100%) rename {RAT => cpp/RAT}/reflectivityCalculation.h (100%) rename {RAT => cpp/RAT}/reflectivityCalculation1.cpp (100%) rename {RAT => cpp/RAT}/reflectivityCalculation1.h (100%) rename {RAT => cpp/RAT}/reflectivityCalculation2.cpp (100%) rename {RAT => cpp/RAT}/reflectivityCalculation2.h (100%) rename {RAT => cpp/RAT}/relop.cpp (100%) rename {RAT => cpp/RAT}/relop.h (100%) rename {RAT => cpp/RAT}/removeOutlier.cpp (100%) rename {RAT => cpp/RAT}/removeOutlier.h (100%) rename {RAT => cpp/RAT}/repmat.cpp (100%) rename {RAT => cpp/RAT}/repmat.h (100%) rename {RAT => cpp/RAT}/resampleLayers.cpp (100%) rename {RAT => cpp/RAT}/resampleLayers.h (100%) rename {RAT => cpp/RAT}/resampleLayersReIm.cpp (100%) rename {RAT => cpp/RAT}/resampleLayersReIm.h (100%) rename {RAT => cpp/RAT}/rescale.cpp (100%) rename {RAT => cpp/RAT}/rescale.h (100%) rename {RAT => cpp/RAT}/rescaleKernel.cpp (100%) rename {RAT => cpp/RAT}/rescaleKernel.h (100%) rename {RAT => cpp/RAT}/rescaleParameters.cpp (100%) rename {RAT => cpp/RAT}/rescaleParameters.h (100%) rename {RAT => cpp/RAT}/reshapeSizeChecks.cpp (100%) rename {RAT => cpp/RAT}/reshapeSizeChecks.h (100%) rename {RAT => cpp/RAT}/resolutionPolly.cpp (100%) rename {RAT => cpp/RAT}/resolutionPolly.h (100%) rename {RAT => cpp/RAT}/rng.cpp (100%) rename {RAT => cpp/RAT}/rng.h (100%) rename {RAT => cpp/RAT}/rtGetInf.cpp (100%) rename {RAT => cpp/RAT}/rtGetInf.h (100%) rename {RAT => cpp/RAT}/rtGetNaN.cpp (100%) rename {RAT => cpp/RAT}/rtGetNaN.h (100%) rename {RAT => cpp/RAT}/rt_defines.h (100%) rename {RAT => cpp/RAT}/rt_nonfinite.cpp (100%) rename {RAT => cpp/RAT}/rt_nonfinite.h (100%) rename {RAT => cpp/RAT}/rtwtypes.h (100%) rename {RAT => cpp/RAT}/runDE.cpp (100%) rename {RAT => cpp/RAT}/runDE.h (100%) rename {RAT => cpp/RAT}/runDREAM.cpp (100%) rename {RAT => cpp/RAT}/runDREAM.h (100%) rename {RAT => cpp/RAT}/runNestedSampler.cpp (100%) rename {RAT => cpp/RAT}/runNestedSampler.h (100%) rename {RAT => cpp/RAT}/runSimplex.cpp (100%) rename {RAT => cpp/RAT}/runSimplex.h (100%) rename {RAT => cpp/RAT}/scaleParameters.cpp (100%) rename {RAT => cpp/RAT}/scaleParameters.h (100%) rename {RAT => cpp/RAT}/scaledGaussPrior.cpp (100%) rename {RAT => cpp/RAT}/scaledGaussPrior.h (100%) rename {RAT => cpp/RAT}/schur.cpp (100%) rename {RAT => cpp/RAT}/schur.h (100%) rename {RAT => cpp/RAT}/setupDREAM.cpp (100%) rename {RAT => cpp/RAT}/setupDREAM.h (100%) rename {RAT => cpp/RAT}/shiftData.cpp (100%) rename {RAT => cpp/RAT}/shiftData.h (100%) rename {RAT => cpp/RAT}/simplexIntrafun.cpp (100%) rename {RAT => cpp/RAT}/simplexIntrafun.h (100%) rename {RAT => cpp/RAT}/simplexXTransform.cpp (100%) rename {RAT => cpp/RAT}/simplexXTransform.h (100%) rename {RAT => cpp/RAT}/single.cpp (100%) rename {RAT => cpp/RAT}/single.h (100%) rename {RAT => cpp/RAT}/single1.cpp (100%) rename {RAT => cpp/RAT}/single1.h (100%) rename {RAT => cpp/RAT}/single2.cpp (100%) rename {RAT => cpp/RAT}/single2.h (100%) rename {RAT => cpp/RAT}/single3.cpp (100%) rename {RAT => cpp/RAT}/single3.h (100%) rename {RAT => cpp/RAT}/single4.cpp (100%) rename {RAT => cpp/RAT}/single4.h (100%) rename {RAT => cpp/RAT}/single5.cpp (100%) rename {RAT => cpp/RAT}/single5.h (100%) rename {RAT => cpp/RAT}/sort.cpp (100%) rename {RAT => cpp/RAT}/sort.h (100%) rename {RAT => cpp/RAT}/sortAscendLE.cpp (100%) rename {RAT => cpp/RAT}/sortAscendLE.h (100%) rename {RAT => cpp/RAT}/sortIdx.cpp (100%) rename {RAT => cpp/RAT}/sortIdx.h (100%) rename {RAT => cpp/RAT}/sortLE.cpp (100%) rename {RAT => cpp/RAT}/sortLE.h (100%) rename {RAT => cpp/RAT}/sortrows.cpp (100%) rename {RAT => cpp/RAT}/sortrows.h (100%) rename {RAT => cpp/RAT}/splitEllipsoid.cpp (100%) rename {RAT => cpp/RAT}/splitEllipsoid.h (100%) rename {RAT => cpp/RAT}/sprintf.cpp (100%) rename {RAT => cpp/RAT}/sprintf.h (100%) rename {RAT => cpp/RAT}/sqrt.cpp (100%) rename {RAT => cpp/RAT}/sqrt.h (100%) rename {RAT => cpp/RAT}/sqrt1.cpp (100%) rename {RAT => cpp/RAT}/sqrt1.h (100%) rename {RAT => cpp/RAT}/std.cpp (100%) rename {RAT => cpp/RAT}/std.h (100%) rename {RAT => cpp/RAT}/str2double.cpp (100%) rename {RAT => cpp/RAT}/str2double.h (100%) rename {RAT => cpp/RAT}/str2double1.cpp (100%) rename {RAT => cpp/RAT}/str2double1.h (100%) rename {RAT => cpp/RAT}/strcmp.cpp (100%) rename {RAT => cpp/RAT}/strcmp.h (100%) rename {RAT => cpp/RAT}/structConstructorHelper.cpp (100%) rename {RAT => cpp/RAT}/structConstructorHelper.h (100%) rename {RAT => cpp/RAT}/sum.cpp (100%) rename {RAT => cpp/RAT}/sum.h (100%) rename {RAT => cpp/RAT}/textProgressBar.cpp (100%) rename {RAT => cpp/RAT}/textProgressBar.h (100%) rename {RAT => cpp/RAT}/tic.cpp (100%) rename {RAT => cpp/RAT}/tic.h (100%) rename {RAT => cpp/RAT}/timeKeeper.cpp (100%) rename {RAT => cpp/RAT}/timeKeeper.h (100%) rename {RAT => cpp/RAT}/tmwtypes.h (100%) rename {RAT => cpp/RAT}/toc.cpp (100%) rename {RAT => cpp/RAT}/toc.h (100%) rename {RAT => cpp/RAT}/triggerEvent.cpp (100%) rename {RAT => cpp/RAT}/triggerEvent.h (100%) rename {RAT => cpp/RAT}/triu.cpp (100%) rename {RAT => cpp/RAT}/triu.h (100%) rename {RAT => cpp/RAT}/unpackParams.cpp (100%) rename {RAT => cpp/RAT}/unpackParams.h (100%) rename {RAT => cpp/RAT}/unsafeSxfun.cpp (100%) rename {RAT => cpp/RAT}/unsafeSxfun.h (100%) rename {RAT => cpp/RAT}/useConstantDim.cpp (100%) rename {RAT => cpp/RAT}/useConstantDim.h (100%) rename {RAT => cpp/RAT}/vAllOrAny.cpp (100%) rename {RAT => cpp/RAT}/vAllOrAny.h (100%) rename {RAT => cpp/RAT}/validate_print_arguments.cpp (100%) rename {RAT => cpp/RAT}/validate_print_arguments.h (100%) rename {RAT => cpp/RAT}/var.cpp (100%) rename {RAT => cpp/RAT}/var.h (100%) rename {RAT => cpp/RAT}/varstd.cpp (100%) rename {RAT => cpp/RAT}/varstd.h (100%) rename {RAT => cpp/RAT}/xdhseqr.cpp (100%) rename {RAT => cpp/RAT}/xdhseqr.h (100%) rename {RAT => cpp/RAT}/xdlanv2.cpp (100%) rename {RAT => cpp/RAT}/xdlanv2.h (100%) rename {RAT => cpp/RAT}/xgehrd.cpp (100%) rename {RAT => cpp/RAT}/xgehrd.h (100%) rename {RAT => cpp/RAT}/xgemm.cpp (100%) rename {RAT => cpp/RAT}/xgemm.h (100%) rename {RAT => cpp/RAT}/xgemv.cpp (100%) rename {RAT => cpp/RAT}/xgemv.h (100%) rename {RAT => cpp/RAT}/xgeqp3.cpp (100%) rename {RAT => cpp/RAT}/xgeqp3.h (100%) rename {RAT => cpp/RAT}/xgerc.cpp (100%) rename {RAT => cpp/RAT}/xgerc.h (100%) rename {RAT => cpp/RAT}/xgeru.cpp (100%) rename {RAT => cpp/RAT}/xgeru.h (100%) rename {RAT => cpp/RAT}/xgetrf.cpp (100%) rename {RAT => cpp/RAT}/xgetrf.h (100%) rename {RAT => cpp/RAT}/xnrm2.cpp (100%) rename {RAT => cpp/RAT}/xnrm2.h (100%) rename {RAT => cpp/RAT}/xrot.cpp (100%) rename {RAT => cpp/RAT}/xrot.h (100%) rename {RAT => cpp/RAT}/xswap.cpp (100%) rename {RAT => cpp/RAT}/xswap.h (100%) rename {RAT => cpp/RAT}/xtrsm.cpp (100%) rename {RAT => cpp/RAT}/xtrsm.h (100%) rename {RAT => cpp/RAT}/xtrsv.cpp (100%) rename {RAT => cpp/RAT}/xtrsv.h (100%) rename {RAT => cpp/RAT}/xungorghr.cpp (100%) rename {RAT => cpp/RAT}/xungorghr.h (100%) rename {RAT => cpp/RAT}/xunormqr.cpp (100%) rename {RAT => cpp/RAT}/xunormqr.h (100%) rename {RAT => cpp/RAT}/xzgeev.cpp (100%) rename {RAT => cpp/RAT}/xzgeev.h (100%) rename {RAT => cpp/RAT}/xzgeqp3.cpp (100%) rename {RAT => cpp/RAT}/xzgeqp3.h (100%) rename {RAT => cpp/RAT}/xzggbak.cpp (100%) rename {RAT => cpp/RAT}/xzggbak.h (100%) rename {RAT => cpp/RAT}/xzggbal.cpp (100%) rename {RAT => cpp/RAT}/xzggbal.h (100%) rename {RAT => cpp/RAT}/xzggev.cpp (100%) rename {RAT => cpp/RAT}/xzggev.h (100%) rename {RAT => cpp/RAT}/xzgghrd.cpp (100%) rename {RAT => cpp/RAT}/xzgghrd.h (100%) rename {RAT => cpp/RAT}/xzhgeqz.cpp (100%) rename {RAT => cpp/RAT}/xzhgeqz.h (100%) rename {RAT => cpp/RAT}/xzlangeM.cpp (100%) rename {RAT => cpp/RAT}/xzlangeM.h (100%) rename {RAT => cpp/RAT}/xzlanhs.cpp (100%) rename {RAT => cpp/RAT}/xzlanhs.h (100%) rename {RAT => cpp/RAT}/xzlarf.cpp (100%) rename {RAT => cpp/RAT}/xzlarf.h (100%) rename {RAT => cpp/RAT}/xzlarfg.cpp (100%) rename {RAT => cpp/RAT}/xzlarfg.h (100%) rename {RAT => cpp/RAT}/xzlartg.cpp (100%) rename {RAT => cpp/RAT}/xzlartg.h (100%) rename {RAT => cpp/RAT}/xzlascl.cpp (100%) rename {RAT => cpp/RAT}/xzlascl.h (100%) rename {RAT => cpp/RAT}/xztgevc.cpp (100%) rename {RAT => cpp/RAT}/xztgevc.h (100%) rename {RAT => cpp/RAT}/xzungqr.cpp (100%) rename {RAT => cpp/RAT}/xzungqr.h (100%) rename rat.cpp => cpp/rat.cpp (99%) rename DSPC_bilayer_example.py => examples/DSPC_bilayer_example.py (97%) rename DSPC_custom_layers_example.py => examples/DSPC_custom_layers_example.py (93%) rename alloyDomains.cpp => examples/alloyDomains.cpp (100%) rename alloyDomains.m => examples/alloyDomains.m (100%) rename alloyDomains.py => examples/alloyDomains.py (100%) rename customBilayer.m => examples/customBilayer.m (100%) rename customBilayer.py => examples/customBilayer.py (100%) rename domains_custom_layers_example.py => examples/domains_custom_layers_example.py (93%) create mode 100644 pyproject.toml create mode 100644 rat/__init__.py rename events.py => rat/events.py (53%) rename misc.py => rat/misc.py (94%) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index db5c3afb..495640e3 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ __pycache__/ *.obj *.exp *.lib +*.a +*.egg-info/ +build/* diff --git a/README.md b/README.md index e510c89e..aaac7eb1 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,12 @@ This is a demonstration of using the generated C++ from MATLAB to create a pytho Build ===== -This has been tested using python 3.8, a c++ compiler is required to run the code. Install the requirement then run the example, if the +This has been tested using python 3.9, a c++ compiler is required to run the code. Install the requirement then run the example, if the compiler can be found, the python extension (*.pyd) will be built and the example will run -Notes -===== -The following files need to be copied to the generated c++ -1. tmwtypes.h from matlabroot\extern\include -2. eventHelper.hpp from compile/events -3. dylib.hpp, classHandle.hpp from compile/customWrapper \ No newline at end of file +Install +======= +To install in local directory: + + pip install -e . diff --git a/RAT/CoderTimeAPI.cpp b/cpp/RAT/CoderTimeAPI.cpp similarity index 100% rename from RAT/CoderTimeAPI.cpp rename to cpp/RAT/CoderTimeAPI.cpp diff --git a/RAT/CoderTimeAPI.h b/cpp/RAT/CoderTimeAPI.h similarity index 100% rename from RAT/CoderTimeAPI.h rename to cpp/RAT/CoderTimeAPI.h diff --git a/RAT/DREAMWrapper.cpp b/cpp/RAT/DREAMWrapper.cpp similarity index 100% rename from RAT/DREAMWrapper.cpp rename to cpp/RAT/DREAMWrapper.cpp diff --git a/RAT/DREAMWrapper.h b/cpp/RAT/DREAMWrapper.h similarity index 100% rename from RAT/DREAMWrapper.h rename to cpp/RAT/DREAMWrapper.h diff --git a/RAT/RATMain.cpp b/cpp/RAT/RATMain.cpp similarity index 100% rename from RAT/RATMain.cpp rename to cpp/RAT/RATMain.cpp diff --git a/RAT/RATMain.h b/cpp/RAT/RATMain.h similarity index 100% rename from RAT/RATMain.h rename to cpp/RAT/RATMain.h diff --git a/RAT/RATMain_data.cpp b/cpp/RAT/RATMain_data.cpp similarity index 100% rename from RAT/RATMain_data.cpp rename to cpp/RAT/RATMain_data.cpp diff --git a/RAT/RATMain_data.h b/cpp/RAT/RATMain_data.h similarity index 100% rename from RAT/RATMain_data.h rename to cpp/RAT/RATMain_data.h diff --git a/RAT/RATMain_initialize.cpp b/cpp/RAT/RATMain_initialize.cpp similarity index 100% rename from RAT/RATMain_initialize.cpp rename to cpp/RAT/RATMain_initialize.cpp diff --git a/RAT/RATMain_initialize.h b/cpp/RAT/RATMain_initialize.h similarity index 100% rename from RAT/RATMain_initialize.h rename to cpp/RAT/RATMain_initialize.h diff --git a/RAT/RATMain_internal_types.h b/cpp/RAT/RATMain_internal_types.h similarity index 100% rename from RAT/RATMain_internal_types.h rename to cpp/RAT/RATMain_internal_types.h diff --git a/RAT/RATMain_rtwutil.cpp b/cpp/RAT/RATMain_rtwutil.cpp similarity index 100% rename from RAT/RATMain_rtwutil.cpp rename to cpp/RAT/RATMain_rtwutil.cpp diff --git a/RAT/RATMain_rtwutil.h b/cpp/RAT/RATMain_rtwutil.h similarity index 100% rename from RAT/RATMain_rtwutil.h rename to cpp/RAT/RATMain_rtwutil.h diff --git a/RAT/RATMain_terminate.cpp b/cpp/RAT/RATMain_terminate.cpp similarity index 100% rename from RAT/RATMain_terminate.cpp rename to cpp/RAT/RATMain_terminate.cpp diff --git a/RAT/RATMain_terminate.h b/cpp/RAT/RATMain_terminate.h similarity index 100% rename from RAT/RATMain_terminate.h rename to cpp/RAT/RATMain_terminate.h diff --git a/RAT/RATMain_types.h b/cpp/RAT/RATMain_types.h similarity index 100% rename from RAT/RATMain_types.h rename to cpp/RAT/RATMain_types.h diff --git a/RAT/SLDFunction.cpp b/cpp/RAT/SLDFunction.cpp similarity index 100% rename from RAT/SLDFunction.cpp rename to cpp/RAT/SLDFunction.cpp diff --git a/RAT/SLDFunction.h b/cpp/RAT/SLDFunction.h similarity index 100% rename from RAT/SLDFunction.h rename to cpp/RAT/SLDFunction.h diff --git a/RAT/abelesParallelPoints.cpp b/cpp/RAT/abelesParallelPoints.cpp similarity index 100% rename from RAT/abelesParallelPoints.cpp rename to cpp/RAT/abelesParallelPoints.cpp diff --git a/RAT/abelesParallelPoints.h b/cpp/RAT/abelesParallelPoints.h similarity index 100% rename from RAT/abelesParallelPoints.h rename to cpp/RAT/abelesParallelPoints.h diff --git a/RAT/abelesSingle.cpp b/cpp/RAT/abelesSingle.cpp similarity index 100% rename from RAT/abelesSingle.cpp rename to cpp/RAT/abelesSingle.cpp diff --git a/RAT/abelesSingle.h b/cpp/RAT/abelesSingle.h similarity index 100% rename from RAT/abelesSingle.h rename to cpp/RAT/abelesSingle.h diff --git a/RAT/abs.cpp b/cpp/RAT/abs.cpp similarity index 100% rename from RAT/abs.cpp rename to cpp/RAT/abs.cpp diff --git a/RAT/abs.h b/cpp/RAT/abs.h similarity index 100% rename from RAT/abs.h rename to cpp/RAT/abs.h diff --git a/RAT/acos.cpp b/cpp/RAT/acos.cpp similarity index 100% rename from RAT/acos.cpp rename to cpp/RAT/acos.cpp diff --git a/RAT/acos.h b/cpp/RAT/acos.h similarity index 100% rename from RAT/acos.h rename to cpp/RAT/acos.h diff --git a/RAT/adaptPCR.cpp b/cpp/RAT/adaptPCR.cpp similarity index 100% rename from RAT/adaptPCR.cpp rename to cpp/RAT/adaptPCR.cpp diff --git a/RAT/adaptPCR.h b/cpp/RAT/adaptPCR.h similarity index 100% rename from RAT/adaptPCR.h rename to cpp/RAT/adaptPCR.h diff --git a/RAT/adaptive.cpp b/cpp/RAT/adaptive.cpp similarity index 100% rename from RAT/adaptive.cpp rename to cpp/RAT/adaptive.cpp diff --git a/RAT/adaptive.h b/cpp/RAT/adaptive.h similarity index 100% rename from RAT/adaptive.h rename to cpp/RAT/adaptive.h diff --git a/RAT/all.cpp b/cpp/RAT/all.cpp similarity index 100% rename from RAT/all.cpp rename to cpp/RAT/all.cpp diff --git a/RAT/all.h b/cpp/RAT/all.h similarity index 100% rename from RAT/all.h rename to cpp/RAT/all.h diff --git a/RAT/allOrAny.cpp b/cpp/RAT/allOrAny.cpp similarity index 100% rename from RAT/allOrAny.cpp rename to cpp/RAT/allOrAny.cpp diff --git a/RAT/allOrAny.h b/cpp/RAT/allOrAny.h similarity index 100% rename from RAT/allOrAny.h rename to cpp/RAT/allOrAny.h diff --git a/RAT/allocateLayersForContrast.cpp b/cpp/RAT/allocateLayersForContrast.cpp similarity index 100% rename from RAT/allocateLayersForContrast.cpp rename to cpp/RAT/allocateLayersForContrast.cpp diff --git a/RAT/allocateLayersForContrast.h b/cpp/RAT/allocateLayersForContrast.h similarity index 100% rename from RAT/allocateLayersForContrast.h rename to cpp/RAT/allocateLayersForContrast.h diff --git a/RAT/allocateParamsToLayers.cpp b/cpp/RAT/allocateParamsToLayers.cpp similarity index 100% rename from RAT/allocateParamsToLayers.cpp rename to cpp/RAT/allocateParamsToLayers.cpp diff --git a/RAT/allocateParamsToLayers.h b/cpp/RAT/allocateParamsToLayers.h similarity index 100% rename from RAT/allocateParamsToLayers.h rename to cpp/RAT/allocateParamsToLayers.h diff --git a/RAT/anyNonFinite.cpp b/cpp/RAT/anyNonFinite.cpp similarity index 100% rename from RAT/anyNonFinite.cpp rename to cpp/RAT/anyNonFinite.cpp diff --git a/RAT/anyNonFinite.h b/cpp/RAT/anyNonFinite.h similarity index 100% rename from RAT/anyNonFinite.h rename to cpp/RAT/anyNonFinite.h diff --git a/RAT/applyBackgroundCorrection.cpp b/cpp/RAT/applyBackgroundCorrection.cpp similarity index 100% rename from RAT/applyBackgroundCorrection.cpp rename to cpp/RAT/applyBackgroundCorrection.cpp diff --git a/RAT/applyBackgroundCorrection.h b/cpp/RAT/applyBackgroundCorrection.h similarity index 100% rename from RAT/applyBackgroundCorrection.h rename to cpp/RAT/applyBackgroundCorrection.h diff --git a/RAT/applyHydrationImag.cpp b/cpp/RAT/applyHydrationImag.cpp similarity index 100% rename from RAT/applyHydrationImag.cpp rename to cpp/RAT/applyHydrationImag.cpp diff --git a/RAT/applyHydrationImag.h b/cpp/RAT/applyHydrationImag.h similarity index 100% rename from RAT/applyHydrationImag.h rename to cpp/RAT/applyHydrationImag.h diff --git a/RAT/applyHydrationReal.cpp b/cpp/RAT/applyHydrationReal.cpp similarity index 100% rename from RAT/applyHydrationReal.cpp rename to cpp/RAT/applyHydrationReal.cpp diff --git a/RAT/applyHydrationReal.h b/cpp/RAT/applyHydrationReal.h similarity index 100% rename from RAT/applyHydrationReal.h rename to cpp/RAT/applyHydrationReal.h diff --git a/RAT/asinh.cpp b/cpp/RAT/asinh.cpp similarity index 100% rename from RAT/asinh.cpp rename to cpp/RAT/asinh.cpp diff --git a/RAT/asinh.h b/cpp/RAT/asinh.h similarity index 100% rename from RAT/asinh.h rename to cpp/RAT/asinh.h diff --git a/RAT/asymconvstep.cpp b/cpp/RAT/asymconvstep.cpp similarity index 100% rename from RAT/asymconvstep.cpp rename to cpp/RAT/asymconvstep.cpp diff --git a/RAT/asymconvstep.h b/cpp/RAT/asymconvstep.h similarity index 100% rename from RAT/asymconvstep.h rename to cpp/RAT/asymconvstep.h diff --git a/RAT/averageReflectivity.cpp b/cpp/RAT/averageReflectivity.cpp similarity index 100% rename from RAT/averageReflectivity.cpp rename to cpp/RAT/averageReflectivity.cpp diff --git a/RAT/averageReflectivity.h b/cpp/RAT/averageReflectivity.h similarity index 100% rename from RAT/averageReflectivity.h rename to cpp/RAT/averageReflectivity.h diff --git a/RAT/backSort.cpp b/cpp/RAT/backSort.cpp similarity index 100% rename from RAT/backSort.cpp rename to cpp/RAT/backSort.cpp diff --git a/RAT/backSort.h b/cpp/RAT/backSort.h similarity index 100% rename from RAT/backSort.h rename to cpp/RAT/backSort.h diff --git a/RAT/blockedSummation.cpp b/cpp/RAT/blockedSummation.cpp similarity index 100% rename from RAT/blockedSummation.cpp rename to cpp/RAT/blockedSummation.cpp diff --git a/RAT/blockedSummation.h b/cpp/RAT/blockedSummation.h similarity index 100% rename from RAT/blockedSummation.h rename to cpp/RAT/blockedSummation.h diff --git a/RAT/boundaryHandling.cpp b/cpp/RAT/boundaryHandling.cpp similarity index 100% rename from RAT/boundaryHandling.cpp rename to cpp/RAT/boundaryHandling.cpp diff --git a/RAT/boundaryHandling.h b/cpp/RAT/boundaryHandling.h similarity index 100% rename from RAT/boundaryHandling.h rename to cpp/RAT/boundaryHandling.h diff --git a/RAT/bsearch.cpp b/cpp/RAT/bsearch.cpp similarity index 100% rename from RAT/bsearch.cpp rename to cpp/RAT/bsearch.cpp diff --git a/RAT/bsearch.h b/cpp/RAT/bsearch.h similarity index 100% rename from RAT/bsearch.h rename to cpp/RAT/bsearch.h diff --git a/RAT/bsxfun.cpp b/cpp/RAT/bsxfun.cpp similarity index 100% rename from RAT/bsxfun.cpp rename to cpp/RAT/bsxfun.cpp diff --git a/RAT/bsxfun.h b/cpp/RAT/bsxfun.h similarity index 100% rename from RAT/bsxfun.h rename to cpp/RAT/bsxfun.h diff --git a/RAT/calcDensity.cpp b/cpp/RAT/calcDensity.cpp similarity index 100% rename from RAT/calcDensity.cpp rename to cpp/RAT/calcDensity.cpp diff --git a/RAT/calcDensity.h b/cpp/RAT/calcDensity.h similarity index 100% rename from RAT/calcDensity.h rename to cpp/RAT/calcDensity.h diff --git a/RAT/calcEllipsoid.cpp b/cpp/RAT/calcEllipsoid.cpp similarity index 100% rename from RAT/calcEllipsoid.cpp rename to cpp/RAT/calcEllipsoid.cpp diff --git a/RAT/calcEllipsoid.h b/cpp/RAT/calcEllipsoid.h similarity index 100% rename from RAT/calcEllipsoid.h rename to cpp/RAT/calcEllipsoid.h diff --git a/RAT/calcProposal.cpp b/cpp/RAT/calcProposal.cpp similarity index 100% rename from RAT/calcProposal.cpp rename to cpp/RAT/calcProposal.cpp diff --git a/RAT/calcProposal.h b/cpp/RAT/calcProposal.h similarity index 100% rename from RAT/calcProposal.h rename to cpp/RAT/calcProposal.h diff --git a/RAT/calculate.cpp b/cpp/RAT/calculate.cpp similarity index 100% rename from RAT/calculate.cpp rename to cpp/RAT/calculate.cpp diff --git a/RAT/calculate.h b/cpp/RAT/calculate.h similarity index 100% rename from RAT/calculate.h rename to cpp/RAT/calculate.h diff --git a/RAT/calculate1.cpp b/cpp/RAT/calculate1.cpp similarity index 100% rename from RAT/calculate1.cpp rename to cpp/RAT/calculate1.cpp diff --git a/RAT/calculate1.h b/cpp/RAT/calculate1.h similarity index 100% rename from RAT/calculate1.h rename to cpp/RAT/calculate1.h diff --git a/RAT/calculate2.cpp b/cpp/RAT/calculate2.cpp similarity index 100% rename from RAT/calculate2.cpp rename to cpp/RAT/calculate2.cpp diff --git a/RAT/calculate2.h b/cpp/RAT/calculate2.h similarity index 100% rename from RAT/calculate2.h rename to cpp/RAT/calculate2.h diff --git a/RAT/calculate3.cpp b/cpp/RAT/calculate3.cpp similarity index 100% rename from RAT/calculate3.cpp rename to cpp/RAT/calculate3.cpp diff --git a/RAT/calculate3.h b/cpp/RAT/calculate3.h similarity index 100% rename from RAT/calculate3.h rename to cpp/RAT/calculate3.h diff --git a/RAT/calculate4.cpp b/cpp/RAT/calculate4.cpp similarity index 100% rename from RAT/calculate4.cpp rename to cpp/RAT/calculate4.cpp diff --git a/RAT/calculate4.h b/cpp/RAT/calculate4.h similarity index 100% rename from RAT/calculate4.h rename to cpp/RAT/calculate4.h diff --git a/RAT/calculate5.cpp b/cpp/RAT/calculate5.cpp similarity index 100% rename from RAT/calculate5.cpp rename to cpp/RAT/calculate5.cpp diff --git a/RAT/calculate5.h b/cpp/RAT/calculate5.h similarity index 100% rename from RAT/calculate5.h rename to cpp/RAT/calculate5.h diff --git a/RAT/callCppFunction.cpp b/cpp/RAT/callCppFunction.cpp similarity index 100% rename from RAT/callCppFunction.cpp rename to cpp/RAT/callCppFunction.cpp diff --git a/RAT/callCppFunction.h b/cpp/RAT/callCppFunction.h similarity index 100% rename from RAT/callCppFunction.h rename to cpp/RAT/callCppFunction.h diff --git a/RAT/callReflectivity.cpp b/cpp/RAT/callReflectivity.cpp similarity index 100% rename from RAT/callReflectivity.cpp rename to cpp/RAT/callReflectivity.cpp diff --git a/RAT/callReflectivity.h b/cpp/RAT/callReflectivity.h similarity index 100% rename from RAT/callReflectivity.h rename to cpp/RAT/callReflectivity.h diff --git a/RAT/cat.cpp b/cpp/RAT/cat.cpp similarity index 100% rename from RAT/cat.cpp rename to cpp/RAT/cat.cpp diff --git a/RAT/cat.h b/cpp/RAT/cat.h similarity index 100% rename from RAT/cat.h rename to cpp/RAT/cat.h diff --git a/RAT/chiSquared.cpp b/cpp/RAT/chiSquared.cpp similarity index 100% rename from RAT/chiSquared.cpp rename to cpp/RAT/chiSquared.cpp diff --git a/RAT/chiSquared.h b/cpp/RAT/chiSquared.h similarity index 100% rename from RAT/chiSquared.h rename to cpp/RAT/chiSquared.h diff --git a/RAT/classHandle.hpp b/cpp/RAT/classHandle.hpp similarity index 100% rename from RAT/classHandle.hpp rename to cpp/RAT/classHandle.hpp diff --git a/RAT/coder_array.h b/cpp/RAT/coder_array.h similarity index 100% rename from RAT/coder_array.h rename to cpp/RAT/coder_array.h diff --git a/RAT/coder_bounded_array.h b/cpp/RAT/coder_bounded_array.h similarity index 100% rename from RAT/coder_bounded_array.h rename to cpp/RAT/coder_bounded_array.h diff --git a/RAT/coder_posix_time.c b/cpp/RAT/coder_posix_time.c similarity index 100% rename from RAT/coder_posix_time.c rename to cpp/RAT/coder_posix_time.c diff --git a/RAT/coder_posix_time.h b/cpp/RAT/coder_posix_time.h similarity index 100% rename from RAT/coder_posix_time.h rename to cpp/RAT/coder_posix_time.h diff --git a/RAT/coder_setenv.c b/cpp/RAT/coder_setenv.c similarity index 100% rename from RAT/coder_setenv.c rename to cpp/RAT/coder_setenv.c diff --git a/RAT/coder_setenv.h b/cpp/RAT/coder_setenv.h similarity index 100% rename from RAT/coder_setenv.h rename to cpp/RAT/coder_setenv.h diff --git a/RAT/colon.cpp b/cpp/RAT/colon.cpp similarity index 100% rename from RAT/colon.cpp rename to cpp/RAT/colon.cpp diff --git a/RAT/colon.h b/cpp/RAT/colon.h similarity index 100% rename from RAT/colon.h rename to cpp/RAT/colon.h diff --git a/RAT/combineVectorElements.cpp b/cpp/RAT/combineVectorElements.cpp similarity index 100% rename from RAT/combineVectorElements.cpp rename to cpp/RAT/combineVectorElements.cpp diff --git a/RAT/combineVectorElements.h b/cpp/RAT/combineVectorElements.h similarity index 100% rename from RAT/combineVectorElements.h rename to cpp/RAT/combineVectorElements.h diff --git a/RAT/complexTimes.cpp b/cpp/RAT/complexTimes.cpp similarity index 100% rename from RAT/complexTimes.cpp rename to cpp/RAT/complexTimes.cpp diff --git a/RAT/complexTimes.h b/cpp/RAT/complexTimes.h similarity index 100% rename from RAT/complexTimes.h rename to cpp/RAT/complexTimes.h diff --git a/RAT/coreLayersCalculation.cpp b/cpp/RAT/coreLayersCalculation.cpp similarity index 100% rename from RAT/coreLayersCalculation.cpp rename to cpp/RAT/coreLayersCalculation.cpp diff --git a/RAT/coreLayersCalculation.h b/cpp/RAT/coreLayersCalculation.h similarity index 100% rename from RAT/coreLayersCalculation.h rename to cpp/RAT/coreLayersCalculation.h diff --git a/RAT/cov.cpp b/cpp/RAT/cov.cpp similarity index 100% rename from RAT/cov.cpp rename to cpp/RAT/cov.cpp diff --git a/RAT/cov.h b/cpp/RAT/cov.h similarity index 100% rename from RAT/cov.h rename to cpp/RAT/cov.h diff --git a/RAT/dataResolutionPolly.cpp b/cpp/RAT/dataResolutionPolly.cpp similarity index 100% rename from RAT/dataResolutionPolly.cpp rename to cpp/RAT/dataResolutionPolly.cpp diff --git a/RAT/dataResolutionPolly.h b/cpp/RAT/dataResolutionPolly.h similarity index 100% rename from RAT/dataResolutionPolly.h rename to cpp/RAT/dataResolutionPolly.h diff --git a/RAT/deopt.cpp b/cpp/RAT/deopt.cpp similarity index 100% rename from RAT/deopt.cpp rename to cpp/RAT/deopt.cpp diff --git a/RAT/deopt.h b/cpp/RAT/deopt.h similarity index 100% rename from RAT/deopt.h rename to cpp/RAT/deopt.h diff --git a/RAT/det.cpp b/cpp/RAT/det.cpp similarity index 100% rename from RAT/det.cpp rename to cpp/RAT/det.cpp diff --git a/RAT/det.h b/cpp/RAT/det.h similarity index 100% rename from RAT/det.h rename to cpp/RAT/det.h diff --git a/RAT/diag.cpp b/cpp/RAT/diag.cpp similarity index 100% rename from RAT/diag.cpp rename to cpp/RAT/diag.cpp diff --git a/RAT/diag.h b/cpp/RAT/diag.h similarity index 100% rename from RAT/diag.h rename to cpp/RAT/diag.h diff --git a/RAT/div.cpp b/cpp/RAT/div.cpp similarity index 100% rename from RAT/div.cpp rename to cpp/RAT/div.cpp diff --git a/RAT/div.h b/cpp/RAT/div.h similarity index 100% rename from RAT/div.h rename to cpp/RAT/div.h diff --git a/RAT/drawCR.cpp b/cpp/RAT/drawCR.cpp similarity index 100% rename from RAT/drawCR.cpp rename to cpp/RAT/drawCR.cpp diff --git a/RAT/drawCR.h b/cpp/RAT/drawCR.h similarity index 100% rename from RAT/drawCR.h rename to cpp/RAT/drawCR.h diff --git a/RAT/drawEllipsoidPoints.cpp b/cpp/RAT/drawEllipsoidPoints.cpp similarity index 100% rename from RAT/drawEllipsoidPoints.cpp rename to cpp/RAT/drawEllipsoidPoints.cpp diff --git a/RAT/drawEllipsoidPoints.h b/cpp/RAT/drawEllipsoidPoints.h similarity index 100% rename from RAT/drawEllipsoidPoints.h rename to cpp/RAT/drawEllipsoidPoints.h diff --git a/RAT/drawMCMC.cpp b/cpp/RAT/drawMCMC.cpp similarity index 100% rename from RAT/drawMCMC.cpp rename to cpp/RAT/drawMCMC.cpp diff --git a/RAT/drawMCMC.h b/cpp/RAT/drawMCMC.h similarity index 100% rename from RAT/drawMCMC.h rename to cpp/RAT/drawMCMC.h diff --git a/RAT/drawMultiNest.cpp b/cpp/RAT/drawMultiNest.cpp similarity index 100% rename from RAT/drawMultiNest.cpp rename to cpp/RAT/drawMultiNest.cpp diff --git a/RAT/drawMultiNest.h b/cpp/RAT/drawMultiNest.h similarity index 100% rename from RAT/drawMultiNest.h rename to cpp/RAT/drawMultiNest.h diff --git a/RAT/dylib.hpp b/cpp/RAT/dylib.hpp similarity index 100% rename from RAT/dylib.hpp rename to cpp/RAT/dylib.hpp diff --git a/RAT/eig.cpp b/cpp/RAT/eig.cpp similarity index 100% rename from RAT/eig.cpp rename to cpp/RAT/eig.cpp diff --git a/RAT/eig.h b/cpp/RAT/eig.h similarity index 100% rename from RAT/eig.h rename to cpp/RAT/eig.h diff --git a/RAT/eigHermitianStandard.cpp b/cpp/RAT/eigHermitianStandard.cpp similarity index 100% rename from RAT/eigHermitianStandard.cpp rename to cpp/RAT/eigHermitianStandard.cpp diff --git a/RAT/eigHermitianStandard.h b/cpp/RAT/eigHermitianStandard.h similarity index 100% rename from RAT/eigHermitianStandard.h rename to cpp/RAT/eigHermitianStandard.h diff --git a/RAT/eigRealSkewSymmetricStandard.cpp b/cpp/RAT/eigRealSkewSymmetricStandard.cpp similarity index 100% rename from RAT/eigRealSkewSymmetricStandard.cpp rename to cpp/RAT/eigRealSkewSymmetricStandard.cpp diff --git a/RAT/eigRealSkewSymmetricStandard.h b/cpp/RAT/eigRealSkewSymmetricStandard.h similarity index 100% rename from RAT/eigRealSkewSymmetricStandard.h rename to cpp/RAT/eigRealSkewSymmetricStandard.h diff --git a/RAT/eigSkewHermitianStandard.cpp b/cpp/RAT/eigSkewHermitianStandard.cpp similarity index 100% rename from RAT/eigSkewHermitianStandard.cpp rename to cpp/RAT/eigSkewHermitianStandard.cpp diff --git a/RAT/eigSkewHermitianStandard.h b/cpp/RAT/eigSkewHermitianStandard.h similarity index 100% rename from RAT/eigSkewHermitianStandard.h rename to cpp/RAT/eigSkewHermitianStandard.h diff --git a/RAT/eml_erfcore.cpp b/cpp/RAT/eml_erfcore.cpp similarity index 100% rename from RAT/eml_erfcore.cpp rename to cpp/RAT/eml_erfcore.cpp diff --git a/RAT/eml_erfcore.h b/cpp/RAT/eml_erfcore.h similarity index 100% rename from RAT/eml_erfcore.h rename to cpp/RAT/eml_erfcore.h diff --git a/RAT/eml_mtimes_helper.cpp b/cpp/RAT/eml_mtimes_helper.cpp similarity index 100% rename from RAT/eml_mtimes_helper.cpp rename to cpp/RAT/eml_mtimes_helper.cpp diff --git a/RAT/eml_mtimes_helper.h b/cpp/RAT/eml_mtimes_helper.h similarity index 100% rename from RAT/eml_mtimes_helper.h rename to cpp/RAT/eml_mtimes_helper.h diff --git a/RAT/eml_rand_mt19937ar.cpp b/cpp/RAT/eml_rand_mt19937ar.cpp similarity index 100% rename from RAT/eml_rand_mt19937ar.cpp rename to cpp/RAT/eml_rand_mt19937ar.cpp diff --git a/RAT/eml_rand_mt19937ar.h b/cpp/RAT/eml_rand_mt19937ar.h similarity index 100% rename from RAT/eml_rand_mt19937ar.h rename to cpp/RAT/eml_rand_mt19937ar.h diff --git a/RAT/eml_rand_mt19937ar_stateful.cpp b/cpp/RAT/eml_rand_mt19937ar_stateful.cpp similarity index 100% rename from RAT/eml_rand_mt19937ar_stateful.cpp rename to cpp/RAT/eml_rand_mt19937ar_stateful.cpp diff --git a/RAT/eml_rand_mt19937ar_stateful.h b/cpp/RAT/eml_rand_mt19937ar_stateful.h similarity index 100% rename from RAT/eml_rand_mt19937ar_stateful.h rename to cpp/RAT/eml_rand_mt19937ar_stateful.h diff --git a/RAT/eml_setop.cpp b/cpp/RAT/eml_setop.cpp similarity index 100% rename from RAT/eml_setop.cpp rename to cpp/RAT/eml_setop.cpp diff --git a/RAT/eml_setop.h b/cpp/RAT/eml_setop.h similarity index 100% rename from RAT/eml_setop.h rename to cpp/RAT/eml_setop.h diff --git a/RAT/eps.cpp b/cpp/RAT/eps.cpp similarity index 100% rename from RAT/eps.cpp rename to cpp/RAT/eps.cpp diff --git a/RAT/eps.h b/cpp/RAT/eps.h similarity index 100% rename from RAT/eps.h rename to cpp/RAT/eps.h diff --git a/RAT/erf.cpp b/cpp/RAT/erf.cpp similarity index 100% rename from RAT/erf.cpp rename to cpp/RAT/erf.cpp diff --git a/RAT/erf.h b/cpp/RAT/erf.h similarity index 100% rename from RAT/erf.h rename to cpp/RAT/erf.h diff --git a/RAT/evaluateModel.cpp b/cpp/RAT/evaluateModel.cpp similarity index 100% rename from RAT/evaluateModel.cpp rename to cpp/RAT/evaluateModel.cpp diff --git a/RAT/evaluateModel.h b/cpp/RAT/evaluateModel.h similarity index 100% rename from RAT/evaluateModel.h rename to cpp/RAT/evaluateModel.h diff --git a/RAT/eventHelper.hpp b/cpp/RAT/eventHelper.hpp similarity index 100% rename from RAT/eventHelper.hpp rename to cpp/RAT/eventHelper.hpp diff --git a/events/eventManager.cpp b/cpp/RAT/events/eventManager.cpp similarity index 100% rename from events/eventManager.cpp rename to cpp/RAT/events/eventManager.cpp diff --git a/events/eventManager.h b/cpp/RAT/events/eventManager.h similarity index 100% rename from events/eventManager.h rename to cpp/RAT/events/eventManager.h diff --git a/events/eventManagerImpl.hpp b/cpp/RAT/events/eventManagerImpl.hpp similarity index 100% rename from events/eventManagerImpl.hpp rename to cpp/RAT/events/eventManagerImpl.hpp diff --git a/RAT/examples/main.cpp b/cpp/RAT/examples/main.cpp similarity index 100% rename from RAT/examples/main.cpp rename to cpp/RAT/examples/main.cpp diff --git a/RAT/examples/main.h b/cpp/RAT/examples/main.h similarity index 100% rename from RAT/examples/main.h rename to cpp/RAT/examples/main.h diff --git a/RAT/exp.cpp b/cpp/RAT/exp.cpp similarity index 100% rename from RAT/exp.cpp rename to cpp/RAT/exp.cpp diff --git a/RAT/exp.h b/cpp/RAT/exp.h similarity index 100% rename from RAT/exp.h rename to cpp/RAT/exp.h diff --git a/RAT/eye.cpp b/cpp/RAT/eye.cpp similarity index 100% rename from RAT/eye.cpp rename to cpp/RAT/eye.cpp diff --git a/RAT/eye.h b/cpp/RAT/eye.h similarity index 100% rename from RAT/eye.h rename to cpp/RAT/eye.h diff --git a/RAT/fMinSearch.cpp b/cpp/RAT/fMinSearch.cpp similarity index 100% rename from RAT/fMinSearch.cpp rename to cpp/RAT/fMinSearch.cpp diff --git a/RAT/fMinSearch.h b/cpp/RAT/fMinSearch.h similarity index 100% rename from RAT/fMinSearch.h rename to cpp/RAT/fMinSearch.h diff --git a/RAT/fileManager.cpp b/cpp/RAT/fileManager.cpp similarity index 100% rename from RAT/fileManager.cpp rename to cpp/RAT/fileManager.cpp diff --git a/RAT/fileManager.h b/cpp/RAT/fileManager.h similarity index 100% rename from RAT/fileManager.h rename to cpp/RAT/fileManager.h diff --git a/RAT/find.cpp b/cpp/RAT/find.cpp similarity index 100% rename from RAT/find.cpp rename to cpp/RAT/find.cpp diff --git a/RAT/find.h b/cpp/RAT/find.h similarity index 100% rename from RAT/find.h rename to cpp/RAT/find.h diff --git a/RAT/flip.cpp b/cpp/RAT/flip.cpp similarity index 100% rename from RAT/flip.cpp rename to cpp/RAT/flip.cpp diff --git a/RAT/flip.h b/cpp/RAT/flip.h similarity index 100% rename from RAT/flip.h rename to cpp/RAT/flip.h diff --git a/RAT/gamma.cpp b/cpp/RAT/gamma.cpp similarity index 100% rename from RAT/gamma.cpp rename to cpp/RAT/gamma.cpp diff --git a/RAT/gamma.h b/cpp/RAT/gamma.h similarity index 100% rename from RAT/gamma.h rename to cpp/RAT/gamma.h diff --git a/RAT/gelman.cpp b/cpp/RAT/gelman.cpp similarity index 100% rename from RAT/gelman.cpp rename to cpp/RAT/gelman.cpp diff --git a/RAT/gelman.h b/cpp/RAT/gelman.h similarity index 100% rename from RAT/gelman.h rename to cpp/RAT/gelman.h diff --git a/RAT/getFittedPriors.cpp b/cpp/RAT/getFittedPriors.cpp similarity index 100% rename from RAT/getFittedPriors.cpp rename to cpp/RAT/getFittedPriors.cpp diff --git a/RAT/getFittedPriors.h b/cpp/RAT/getFittedPriors.h similarity index 100% rename from RAT/getFittedPriors.h rename to cpp/RAT/getFittedPriors.h diff --git a/RAT/getTime.cpp b/cpp/RAT/getTime.cpp similarity index 100% rename from RAT/getTime.cpp rename to cpp/RAT/getTime.cpp diff --git a/RAT/getTime.h b/cpp/RAT/getTime.h similarity index 100% rename from RAT/getTime.h rename to cpp/RAT/getTime.h diff --git a/RAT/getenv.cpp b/cpp/RAT/getenv.cpp similarity index 100% rename from RAT/getenv.cpp rename to cpp/RAT/getenv.cpp diff --git a/RAT/getenv.h b/cpp/RAT/getenv.h similarity index 100% rename from RAT/getenv.h rename to cpp/RAT/getenv.h diff --git a/RAT/groupLayersMod.cpp b/cpp/RAT/groupLayersMod.cpp similarity index 100% rename from RAT/groupLayersMod.cpp rename to cpp/RAT/groupLayersMod.cpp diff --git a/RAT/groupLayersMod.h b/cpp/RAT/groupLayersMod.h similarity index 100% rename from RAT/groupLayersMod.h rename to cpp/RAT/groupLayersMod.h diff --git a/RAT/groupLayersModImaginary.cpp b/cpp/RAT/groupLayersModImaginary.cpp similarity index 100% rename from RAT/groupLayersModImaginary.cpp rename to cpp/RAT/groupLayersModImaginary.cpp diff --git a/RAT/groupLayersModImaginary.h b/cpp/RAT/groupLayersModImaginary.h similarity index 100% rename from RAT/groupLayersModImaginary.h rename to cpp/RAT/groupLayersModImaginary.h diff --git a/RAT/histc.cpp b/cpp/RAT/histc.cpp similarity index 100% rename from RAT/histc.cpp rename to cpp/RAT/histc.cpp diff --git a/RAT/histc.h b/cpp/RAT/histc.h similarity index 100% rename from RAT/histc.h rename to cpp/RAT/histc.h diff --git a/RAT/ifWhileCond.cpp b/cpp/RAT/ifWhileCond.cpp similarity index 100% rename from RAT/ifWhileCond.cpp rename to cpp/RAT/ifWhileCond.cpp diff --git a/RAT/ifWhileCond.h b/cpp/RAT/ifWhileCond.h similarity index 100% rename from RAT/ifWhileCond.h rename to cpp/RAT/ifWhileCond.h diff --git a/RAT/inEllipsoids.cpp b/cpp/RAT/inEllipsoids.cpp similarity index 100% rename from RAT/inEllipsoids.cpp rename to cpp/RAT/inEllipsoids.cpp diff --git a/RAT/inEllipsoids.h b/cpp/RAT/inEllipsoids.h similarity index 100% rename from RAT/inEllipsoids.h rename to cpp/RAT/inEllipsoids.h diff --git a/RAT/initializeDREAM.cpp b/cpp/RAT/initializeDREAM.cpp similarity index 100% rename from RAT/initializeDREAM.cpp rename to cpp/RAT/initializeDREAM.cpp diff --git a/RAT/initializeDREAM.h b/cpp/RAT/initializeDREAM.h similarity index 100% rename from RAT/initializeDREAM.h rename to cpp/RAT/initializeDREAM.h diff --git a/RAT/interp1.cpp b/cpp/RAT/interp1.cpp similarity index 100% rename from RAT/interp1.cpp rename to cpp/RAT/interp1.cpp diff --git a/RAT/interp1.h b/cpp/RAT/interp1.h similarity index 100% rename from RAT/interp1.h rename to cpp/RAT/interp1.h diff --git a/RAT/ishermitian.cpp b/cpp/RAT/ishermitian.cpp similarity index 100% rename from RAT/ishermitian.cpp rename to cpp/RAT/ishermitian.cpp diff --git a/RAT/ishermitian.h b/cpp/RAT/ishermitian.h similarity index 100% rename from RAT/ishermitian.h rename to cpp/RAT/ishermitian.h diff --git a/RAT/isrow.cpp b/cpp/RAT/isrow.cpp similarity index 100% rename from RAT/isrow.cpp rename to cpp/RAT/isrow.cpp diff --git a/RAT/isrow.h b/cpp/RAT/isrow.h similarity index 100% rename from RAT/isrow.h rename to cpp/RAT/isrow.h diff --git a/RAT/ixamax.cpp b/cpp/RAT/ixamax.cpp similarity index 100% rename from RAT/ixamax.cpp rename to cpp/RAT/ixamax.cpp diff --git a/RAT/ixamax.h b/cpp/RAT/ixamax.h similarity index 100% rename from RAT/ixamax.h rename to cpp/RAT/ixamax.h diff --git a/RAT/ixfun.cpp b/cpp/RAT/ixfun.cpp similarity index 100% rename from RAT/ixfun.cpp rename to cpp/RAT/ixfun.cpp diff --git a/RAT/ixfun.h b/cpp/RAT/ixfun.h similarity index 100% rename from RAT/ixfun.h rename to cpp/RAT/ixfun.h diff --git a/RAT/kmeans.cpp b/cpp/RAT/kmeans.cpp similarity index 100% rename from RAT/kmeans.cpp rename to cpp/RAT/kmeans.cpp diff --git a/RAT/kmeans.h b/cpp/RAT/kmeans.h similarity index 100% rename from RAT/kmeans.h rename to cpp/RAT/kmeans.h diff --git a/RAT/leftWin.cpp b/cpp/RAT/leftWin.cpp similarity index 100% rename from RAT/leftWin.cpp rename to cpp/RAT/leftWin.cpp diff --git a/RAT/leftWin.h b/cpp/RAT/leftWin.h similarity index 100% rename from RAT/leftWin.h rename to cpp/RAT/leftWin.h diff --git a/RAT/length.cpp b/cpp/RAT/length.cpp similarity index 100% rename from RAT/length.cpp rename to cpp/RAT/length.cpp diff --git a/RAT/length.h b/cpp/RAT/length.h similarity index 100% rename from RAT/length.h rename to cpp/RAT/length.h diff --git a/RAT/linspace.cpp b/cpp/RAT/linspace.cpp similarity index 100% rename from RAT/linspace.cpp rename to cpp/RAT/linspace.cpp diff --git a/RAT/linspace.h b/cpp/RAT/linspace.h similarity index 100% rename from RAT/linspace.h rename to cpp/RAT/linspace.h diff --git a/RAT/log1p.cpp b/cpp/RAT/log1p.cpp similarity index 100% rename from RAT/log1p.cpp rename to cpp/RAT/log1p.cpp diff --git a/RAT/log1p.h b/cpp/RAT/log1p.h similarity index 100% rename from RAT/log1p.h rename to cpp/RAT/log1p.h diff --git a/RAT/log2.cpp b/cpp/RAT/log2.cpp similarity index 100% rename from RAT/log2.cpp rename to cpp/RAT/log2.cpp diff --git a/RAT/log2.h b/cpp/RAT/log2.h similarity index 100% rename from RAT/log2.h rename to cpp/RAT/log2.h diff --git a/RAT/logPlus.cpp b/cpp/RAT/logPlus.cpp similarity index 100% rename from RAT/logPlus.cpp rename to cpp/RAT/logPlus.cpp diff --git a/RAT/logPlus.h b/cpp/RAT/logPlus.h similarity index 100% rename from RAT/logPlus.h rename to cpp/RAT/logPlus.h diff --git a/RAT/lower.cpp b/cpp/RAT/lower.cpp similarity index 100% rename from RAT/lower.cpp rename to cpp/RAT/lower.cpp diff --git a/RAT/lower.h b/cpp/RAT/lower.h similarity index 100% rename from RAT/lower.h rename to cpp/RAT/lower.h diff --git a/RAT/lusolve.cpp b/cpp/RAT/lusolve.cpp similarity index 100% rename from RAT/lusolve.cpp rename to cpp/RAT/lusolve.cpp diff --git a/RAT/lusolve.h b/cpp/RAT/lusolve.h similarity index 100% rename from RAT/lusolve.h rename to cpp/RAT/lusolve.h diff --git a/RAT/makeCell.cpp b/cpp/RAT/makeCell.cpp similarity index 100% rename from RAT/makeCell.cpp rename to cpp/RAT/makeCell.cpp diff --git a/RAT/makeCell.h b/cpp/RAT/makeCell.h similarity index 100% rename from RAT/makeCell.h rename to cpp/RAT/makeCell.h diff --git a/RAT/makeD.cpp b/cpp/RAT/makeD.cpp similarity index 100% rename from RAT/makeD.cpp rename to cpp/RAT/makeD.cpp diff --git a/RAT/makeD.h b/cpp/RAT/makeD.h similarity index 100% rename from RAT/makeD.h rename to cpp/RAT/makeD.h diff --git a/RAT/makeEmptyBayesResultsStruct.cpp b/cpp/RAT/makeEmptyBayesResultsStruct.cpp similarity index 100% rename from RAT/makeEmptyBayesResultsStruct.cpp rename to cpp/RAT/makeEmptyBayesResultsStruct.cpp diff --git a/RAT/makeEmptyBayesResultsStruct.h b/cpp/RAT/makeEmptyBayesResultsStruct.h similarity index 100% rename from RAT/makeEmptyBayesResultsStruct.h rename to cpp/RAT/makeEmptyBayesResultsStruct.h diff --git a/RAT/makeSLDProfileXY.cpp b/cpp/RAT/makeSLDProfileXY.cpp similarity index 100% rename from RAT/makeSLDProfileXY.cpp rename to cpp/RAT/makeSLDProfileXY.cpp diff --git a/RAT/makeSLDProfileXY.h b/cpp/RAT/makeSLDProfileXY.h similarity index 100% rename from RAT/makeSLDProfileXY.h rename to cpp/RAT/makeSLDProfileXY.h diff --git a/RAT/makeSLDProfiles.cpp b/cpp/RAT/makeSLDProfiles.cpp similarity index 100% rename from RAT/makeSLDProfiles.cpp rename to cpp/RAT/makeSLDProfiles.cpp diff --git a/RAT/makeSLDProfiles.h b/cpp/RAT/makeSLDProfiles.h similarity index 100% rename from RAT/makeSLDProfiles.h rename to cpp/RAT/makeSLDProfiles.h diff --git a/RAT/matrix_to_integer_power.cpp b/cpp/RAT/matrix_to_integer_power.cpp similarity index 100% rename from RAT/matrix_to_integer_power.cpp rename to cpp/RAT/matrix_to_integer_power.cpp diff --git a/RAT/matrix_to_integer_power.h b/cpp/RAT/matrix_to_integer_power.h similarity index 100% rename from RAT/matrix_to_integer_power.h rename to cpp/RAT/matrix_to_integer_power.h diff --git a/RAT/mchol.cpp b/cpp/RAT/mchol.cpp similarity index 100% rename from RAT/mchol.cpp rename to cpp/RAT/mchol.cpp diff --git a/RAT/mchol.h b/cpp/RAT/mchol.h similarity index 100% rename from RAT/mchol.h rename to cpp/RAT/mchol.h diff --git a/RAT/mean.cpp b/cpp/RAT/mean.cpp similarity index 100% rename from RAT/mean.cpp rename to cpp/RAT/mean.cpp diff --git a/RAT/mean.h b/cpp/RAT/mean.h similarity index 100% rename from RAT/mean.h rename to cpp/RAT/mean.h diff --git a/RAT/mergesort.cpp b/cpp/RAT/mergesort.cpp similarity index 100% rename from RAT/mergesort.cpp rename to cpp/RAT/mergesort.cpp diff --git a/RAT/mergesort.h b/cpp/RAT/mergesort.h similarity index 100% rename from RAT/mergesort.h rename to cpp/RAT/mergesort.h diff --git a/RAT/metropolisRule.cpp b/cpp/RAT/metropolisRule.cpp similarity index 100% rename from RAT/metropolisRule.cpp rename to cpp/RAT/metropolisRule.cpp diff --git a/RAT/metropolisRule.h b/cpp/RAT/metropolisRule.h similarity index 100% rename from RAT/metropolisRule.h rename to cpp/RAT/metropolisRule.h diff --git a/RAT/minOrMax.cpp b/cpp/RAT/minOrMax.cpp similarity index 100% rename from RAT/minOrMax.cpp rename to cpp/RAT/minOrMax.cpp diff --git a/RAT/minOrMax.h b/cpp/RAT/minOrMax.h similarity index 100% rename from RAT/minOrMax.h rename to cpp/RAT/minOrMax.h diff --git a/RAT/mod.cpp b/cpp/RAT/mod.cpp similarity index 100% rename from RAT/mod.cpp rename to cpp/RAT/mod.cpp diff --git a/RAT/mod.h b/cpp/RAT/mod.h similarity index 100% rename from RAT/mod.h rename to cpp/RAT/mod.h diff --git a/RAT/mrdivide_helper.cpp b/cpp/RAT/mrdivide_helper.cpp similarity index 100% rename from RAT/mrdivide_helper.cpp rename to cpp/RAT/mrdivide_helper.cpp diff --git a/RAT/mrdivide_helper.h b/cpp/RAT/mrdivide_helper.h similarity index 100% rename from RAT/mrdivide_helper.h rename to cpp/RAT/mrdivide_helper.h diff --git a/RAT/mtimes.cpp b/cpp/RAT/mtimes.cpp similarity index 100% rename from RAT/mtimes.cpp rename to cpp/RAT/mtimes.cpp diff --git a/RAT/mtimes.h b/cpp/RAT/mtimes.h similarity index 100% rename from RAT/mtimes.h rename to cpp/RAT/mtimes.h diff --git a/RAT/multrnd.cpp b/cpp/RAT/multrnd.cpp similarity index 100% rename from RAT/multrnd.cpp rename to cpp/RAT/multrnd.cpp diff --git a/RAT/multrnd.h b/cpp/RAT/multrnd.h similarity index 100% rename from RAT/multrnd.h rename to cpp/RAT/multrnd.h diff --git a/RAT/nest2pos.cpp b/cpp/RAT/nest2pos.cpp similarity index 100% rename from RAT/nest2pos.cpp rename to cpp/RAT/nest2pos.cpp diff --git a/RAT/nest2pos.h b/cpp/RAT/nest2pos.h similarity index 100% rename from RAT/nest2pos.h rename to cpp/RAT/nest2pos.h diff --git a/RAT/nestedSampler.cpp b/cpp/RAT/nestedSampler.cpp similarity index 100% rename from RAT/nestedSampler.cpp rename to cpp/RAT/nestedSampler.cpp diff --git a/RAT/nestedSampler.h b/cpp/RAT/nestedSampler.h similarity index 100% rename from RAT/nestedSampler.h rename to cpp/RAT/nestedSampler.h diff --git a/RAT/nonSingletonDim.cpp b/cpp/RAT/nonSingletonDim.cpp similarity index 100% rename from RAT/nonSingletonDim.cpp rename to cpp/RAT/nonSingletonDim.cpp diff --git a/RAT/nonSingletonDim.h b/cpp/RAT/nonSingletonDim.h similarity index 100% rename from RAT/nonSingletonDim.h rename to cpp/RAT/nonSingletonDim.h diff --git a/RAT/norm.cpp b/cpp/RAT/norm.cpp similarity index 100% rename from RAT/norm.cpp rename to cpp/RAT/norm.cpp diff --git a/RAT/norm.h b/cpp/RAT/norm.h similarity index 100% rename from RAT/norm.h rename to cpp/RAT/norm.h diff --git a/RAT/nsIntraFun.cpp b/cpp/RAT/nsIntraFun.cpp similarity index 100% rename from RAT/nsIntraFun.cpp rename to cpp/RAT/nsIntraFun.cpp diff --git a/RAT/nsIntraFun.h b/cpp/RAT/nsIntraFun.h similarity index 100% rename from RAT/nsIntraFun.h rename to cpp/RAT/nsIntraFun.h diff --git a/RAT/nullAssignment.cpp b/cpp/RAT/nullAssignment.cpp similarity index 100% rename from RAT/nullAssignment.cpp rename to cpp/RAT/nullAssignment.cpp diff --git a/RAT/nullAssignment.h b/cpp/RAT/nullAssignment.h similarity index 100% rename from RAT/nullAssignment.h rename to cpp/RAT/nullAssignment.h diff --git a/RAT/optimalEllipsoids.cpp b/cpp/RAT/optimalEllipsoids.cpp similarity index 100% rename from RAT/optimalEllipsoids.cpp rename to cpp/RAT/optimalEllipsoids.cpp diff --git a/RAT/optimalEllipsoids.h b/cpp/RAT/optimalEllipsoids.h similarity index 100% rename from RAT/optimalEllipsoids.h rename to cpp/RAT/optimalEllipsoids.h diff --git a/RAT/packParams.cpp b/cpp/RAT/packParams.cpp similarity index 100% rename from RAT/packParams.cpp rename to cpp/RAT/packParams.cpp diff --git a/RAT/packParams.h b/cpp/RAT/packParams.h similarity index 100% rename from RAT/packParams.h rename to cpp/RAT/packParams.h diff --git a/RAT/parallelContrasts.cpp b/cpp/RAT/parallelContrasts.cpp similarity index 100% rename from RAT/parallelContrasts.cpp rename to cpp/RAT/parallelContrasts.cpp diff --git a/RAT/parallelContrasts.h b/cpp/RAT/parallelContrasts.h similarity index 100% rename from RAT/parallelContrasts.h rename to cpp/RAT/parallelContrasts.h diff --git a/RAT/parallelContrasts1.cpp b/cpp/RAT/parallelContrasts1.cpp similarity index 100% rename from RAT/parallelContrasts1.cpp rename to cpp/RAT/parallelContrasts1.cpp diff --git a/RAT/parallelContrasts1.h b/cpp/RAT/parallelContrasts1.h similarity index 100% rename from RAT/parallelContrasts1.h rename to cpp/RAT/parallelContrasts1.h diff --git a/RAT/parallelContrasts2.cpp b/cpp/RAT/parallelContrasts2.cpp similarity index 100% rename from RAT/parallelContrasts2.cpp rename to cpp/RAT/parallelContrasts2.cpp diff --git a/RAT/parallelContrasts2.h b/cpp/RAT/parallelContrasts2.h similarity index 100% rename from RAT/parallelContrasts2.h rename to cpp/RAT/parallelContrasts2.h diff --git a/RAT/parallelContrasts3.cpp b/cpp/RAT/parallelContrasts3.cpp similarity index 100% rename from RAT/parallelContrasts3.cpp rename to cpp/RAT/parallelContrasts3.cpp diff --git a/RAT/parallelContrasts3.h b/cpp/RAT/parallelContrasts3.h similarity index 100% rename from RAT/parallelContrasts3.h rename to cpp/RAT/parallelContrasts3.h diff --git a/RAT/parallelContrasts4.cpp b/cpp/RAT/parallelContrasts4.cpp similarity index 100% rename from RAT/parallelContrasts4.cpp rename to cpp/RAT/parallelContrasts4.cpp diff --git a/RAT/parallelContrasts4.h b/cpp/RAT/parallelContrasts4.h similarity index 100% rename from RAT/parallelContrasts4.h rename to cpp/RAT/parallelContrasts4.h diff --git a/RAT/parallelContrasts5.cpp b/cpp/RAT/parallelContrasts5.cpp similarity index 100% rename from RAT/parallelContrasts5.cpp rename to cpp/RAT/parallelContrasts5.cpp diff --git a/RAT/parallelContrasts5.h b/cpp/RAT/parallelContrasts5.h similarity index 100% rename from RAT/parallelContrasts5.h rename to cpp/RAT/parallelContrasts5.h diff --git a/RAT/parallelPoints.cpp b/cpp/RAT/parallelPoints.cpp similarity index 100% rename from RAT/parallelPoints.cpp rename to cpp/RAT/parallelPoints.cpp diff --git a/RAT/parallelPoints.h b/cpp/RAT/parallelPoints.h similarity index 100% rename from RAT/parallelPoints.h rename to cpp/RAT/parallelPoints.h diff --git a/RAT/parallelPoints1.cpp b/cpp/RAT/parallelPoints1.cpp similarity index 100% rename from RAT/parallelPoints1.cpp rename to cpp/RAT/parallelPoints1.cpp diff --git a/RAT/parallelPoints1.h b/cpp/RAT/parallelPoints1.h similarity index 100% rename from RAT/parallelPoints1.h rename to cpp/RAT/parallelPoints1.h diff --git a/RAT/parallelPoints2.cpp b/cpp/RAT/parallelPoints2.cpp similarity index 100% rename from RAT/parallelPoints2.cpp rename to cpp/RAT/parallelPoints2.cpp diff --git a/RAT/parallelPoints2.h b/cpp/RAT/parallelPoints2.h similarity index 100% rename from RAT/parallelPoints2.h rename to cpp/RAT/parallelPoints2.h diff --git a/RAT/parallelPoints3.cpp b/cpp/RAT/parallelPoints3.cpp similarity index 100% rename from RAT/parallelPoints3.cpp rename to cpp/RAT/parallelPoints3.cpp diff --git a/RAT/parallelPoints3.h b/cpp/RAT/parallelPoints3.h similarity index 100% rename from RAT/parallelPoints3.h rename to cpp/RAT/parallelPoints3.h diff --git a/RAT/parallelPoints4.cpp b/cpp/RAT/parallelPoints4.cpp similarity index 100% rename from RAT/parallelPoints4.cpp rename to cpp/RAT/parallelPoints4.cpp diff --git a/RAT/parallelPoints4.h b/cpp/RAT/parallelPoints4.h similarity index 100% rename from RAT/parallelPoints4.h rename to cpp/RAT/parallelPoints4.h diff --git a/RAT/parallelPoints5.cpp b/cpp/RAT/parallelPoints5.cpp similarity index 100% rename from RAT/parallelPoints5.cpp rename to cpp/RAT/parallelPoints5.cpp diff --git a/RAT/parallelPoints5.h b/cpp/RAT/parallelPoints5.h similarity index 100% rename from RAT/parallelPoints5.h rename to cpp/RAT/parallelPoints5.h diff --git a/RAT/parseResultToStruct.cpp b/cpp/RAT/parseResultToStruct.cpp similarity index 100% rename from RAT/parseResultToStruct.cpp rename to cpp/RAT/parseResultToStruct.cpp diff --git a/RAT/parseResultToStruct.h b/cpp/RAT/parseResultToStruct.h similarity index 100% rename from RAT/parseResultToStruct.h rename to cpp/RAT/parseResultToStruct.h diff --git a/RAT/pow2.cpp b/cpp/RAT/pow2.cpp similarity index 100% rename from RAT/pow2.cpp rename to cpp/RAT/pow2.cpp diff --git a/RAT/pow2.h b/cpp/RAT/pow2.h similarity index 100% rename from RAT/pow2.h rename to cpp/RAT/pow2.h diff --git a/RAT/prctile.cpp b/cpp/RAT/prctile.cpp similarity index 100% rename from RAT/prctile.cpp rename to cpp/RAT/prctile.cpp diff --git a/RAT/prctile.h b/cpp/RAT/prctile.h similarity index 100% rename from RAT/prctile.h rename to cpp/RAT/prctile.h diff --git a/RAT/prctileConfInts.cpp b/cpp/RAT/prctileConfInts.cpp similarity index 100% rename from RAT/prctileConfInts.cpp rename to cpp/RAT/prctileConfInts.cpp diff --git a/RAT/prctileConfInts.h b/cpp/RAT/prctileConfInts.h similarity index 100% rename from RAT/prctileConfInts.h rename to cpp/RAT/prctileConfInts.h diff --git a/RAT/processBayes.cpp b/cpp/RAT/processBayes.cpp similarity index 100% rename from RAT/processBayes.cpp rename to cpp/RAT/processBayes.cpp diff --git a/RAT/processBayes.h b/cpp/RAT/processBayes.h similarity index 100% rename from RAT/processBayes.h rename to cpp/RAT/processBayes.h diff --git a/RAT/processCustomFunction.cpp b/cpp/RAT/processCustomFunction.cpp similarity index 100% rename from RAT/processCustomFunction.cpp rename to cpp/RAT/processCustomFunction.cpp diff --git a/RAT/processCustomFunction.h b/cpp/RAT/processCustomFunction.h similarity index 100% rename from RAT/processCustomFunction.h rename to cpp/RAT/processCustomFunction.h diff --git a/RAT/processCustomFunction1.cpp b/cpp/RAT/processCustomFunction1.cpp similarity index 100% rename from RAT/processCustomFunction1.cpp rename to cpp/RAT/processCustomFunction1.cpp diff --git a/RAT/processCustomFunction1.h b/cpp/RAT/processCustomFunction1.h similarity index 100% rename from RAT/processCustomFunction1.h rename to cpp/RAT/processCustomFunction1.h diff --git a/RAT/processCustomFunction2.cpp b/cpp/RAT/processCustomFunction2.cpp similarity index 100% rename from RAT/processCustomFunction2.cpp rename to cpp/RAT/processCustomFunction2.cpp diff --git a/RAT/processCustomFunction2.h b/cpp/RAT/processCustomFunction2.h similarity index 100% rename from RAT/processCustomFunction2.h rename to cpp/RAT/processCustomFunction2.h diff --git a/RAT/processCustomFunction3.cpp b/cpp/RAT/processCustomFunction3.cpp similarity index 100% rename from RAT/processCustomFunction3.cpp rename to cpp/RAT/processCustomFunction3.cpp diff --git a/RAT/processCustomFunction3.h b/cpp/RAT/processCustomFunction3.h similarity index 100% rename from RAT/processCustomFunction3.h rename to cpp/RAT/processCustomFunction3.h diff --git a/RAT/qrsolve.cpp b/cpp/RAT/qrsolve.cpp similarity index 100% rename from RAT/qrsolve.cpp rename to cpp/RAT/qrsolve.cpp diff --git a/RAT/qrsolve.h b/cpp/RAT/qrsolve.h similarity index 100% rename from RAT/qrsolve.h rename to cpp/RAT/qrsolve.h diff --git a/RAT/rand.cpp b/cpp/RAT/rand.cpp similarity index 100% rename from RAT/rand.cpp rename to cpp/RAT/rand.cpp diff --git a/RAT/rand.h b/cpp/RAT/rand.h similarity index 100% rename from RAT/rand.h rename to cpp/RAT/rand.h diff --git a/RAT/randn.cpp b/cpp/RAT/randn.cpp similarity index 100% rename from RAT/randn.cpp rename to cpp/RAT/randn.cpp diff --git a/RAT/randn.h b/cpp/RAT/randn.h similarity index 100% rename from RAT/randn.h rename to cpp/RAT/randn.h diff --git a/RAT/randperm.cpp b/cpp/RAT/randperm.cpp similarity index 100% rename from RAT/randperm.cpp rename to cpp/RAT/randperm.cpp diff --git a/RAT/randperm.h b/cpp/RAT/randperm.h similarity index 100% rename from RAT/randperm.h rename to cpp/RAT/randperm.h diff --git a/RAT/randsample.cpp b/cpp/RAT/randsample.cpp similarity index 100% rename from RAT/randsample.cpp rename to cpp/RAT/randsample.cpp diff --git a/RAT/randsample.h b/cpp/RAT/randsample.h similarity index 100% rename from RAT/randsample.h rename to cpp/RAT/randsample.h diff --git a/RAT/ratDREAM.cpp b/cpp/RAT/ratDREAM.cpp similarity index 100% rename from RAT/ratDREAM.cpp rename to cpp/RAT/ratDREAM.cpp diff --git a/RAT/ratDREAM.h b/cpp/RAT/ratDREAM.h similarity index 100% rename from RAT/ratDREAM.h rename to cpp/RAT/ratDREAM.h diff --git a/RAT/rcond.cpp b/cpp/RAT/rcond.cpp similarity index 100% rename from RAT/rcond.cpp rename to cpp/RAT/rcond.cpp diff --git a/RAT/rcond.h b/cpp/RAT/rcond.h similarity index 100% rename from RAT/rcond.h rename to cpp/RAT/rcond.h diff --git a/RAT/rdivide_helper.cpp b/cpp/RAT/rdivide_helper.cpp similarity index 100% rename from RAT/rdivide_helper.cpp rename to cpp/RAT/rdivide_helper.cpp diff --git a/RAT/rdivide_helper.h b/cpp/RAT/rdivide_helper.h similarity index 100% rename from RAT/rdivide_helper.h rename to cpp/RAT/rdivide_helper.h diff --git a/RAT/refPrctileConfInts.cpp b/cpp/RAT/refPrctileConfInts.cpp similarity index 100% rename from RAT/refPrctileConfInts.cpp rename to cpp/RAT/refPrctileConfInts.cpp diff --git a/RAT/refPrctileConfInts.h b/cpp/RAT/refPrctileConfInts.h similarity index 100% rename from RAT/refPrctileConfInts.h rename to cpp/RAT/refPrctileConfInts.h diff --git a/RAT/reflectivityCalculation.cpp b/cpp/RAT/reflectivityCalculation.cpp similarity index 100% rename from RAT/reflectivityCalculation.cpp rename to cpp/RAT/reflectivityCalculation.cpp diff --git a/RAT/reflectivityCalculation.h b/cpp/RAT/reflectivityCalculation.h similarity index 100% rename from RAT/reflectivityCalculation.h rename to cpp/RAT/reflectivityCalculation.h diff --git a/RAT/reflectivityCalculation1.cpp b/cpp/RAT/reflectivityCalculation1.cpp similarity index 100% rename from RAT/reflectivityCalculation1.cpp rename to cpp/RAT/reflectivityCalculation1.cpp diff --git a/RAT/reflectivityCalculation1.h b/cpp/RAT/reflectivityCalculation1.h similarity index 100% rename from RAT/reflectivityCalculation1.h rename to cpp/RAT/reflectivityCalculation1.h diff --git a/RAT/reflectivityCalculation2.cpp b/cpp/RAT/reflectivityCalculation2.cpp similarity index 100% rename from RAT/reflectivityCalculation2.cpp rename to cpp/RAT/reflectivityCalculation2.cpp diff --git a/RAT/reflectivityCalculation2.h b/cpp/RAT/reflectivityCalculation2.h similarity index 100% rename from RAT/reflectivityCalculation2.h rename to cpp/RAT/reflectivityCalculation2.h diff --git a/RAT/relop.cpp b/cpp/RAT/relop.cpp similarity index 100% rename from RAT/relop.cpp rename to cpp/RAT/relop.cpp diff --git a/RAT/relop.h b/cpp/RAT/relop.h similarity index 100% rename from RAT/relop.h rename to cpp/RAT/relop.h diff --git a/RAT/removeOutlier.cpp b/cpp/RAT/removeOutlier.cpp similarity index 100% rename from RAT/removeOutlier.cpp rename to cpp/RAT/removeOutlier.cpp diff --git a/RAT/removeOutlier.h b/cpp/RAT/removeOutlier.h similarity index 100% rename from RAT/removeOutlier.h rename to cpp/RAT/removeOutlier.h diff --git a/RAT/repmat.cpp b/cpp/RAT/repmat.cpp similarity index 100% rename from RAT/repmat.cpp rename to cpp/RAT/repmat.cpp diff --git a/RAT/repmat.h b/cpp/RAT/repmat.h similarity index 100% rename from RAT/repmat.h rename to cpp/RAT/repmat.h diff --git a/RAT/resampleLayers.cpp b/cpp/RAT/resampleLayers.cpp similarity index 100% rename from RAT/resampleLayers.cpp rename to cpp/RAT/resampleLayers.cpp diff --git a/RAT/resampleLayers.h b/cpp/RAT/resampleLayers.h similarity index 100% rename from RAT/resampleLayers.h rename to cpp/RAT/resampleLayers.h diff --git a/RAT/resampleLayersReIm.cpp b/cpp/RAT/resampleLayersReIm.cpp similarity index 100% rename from RAT/resampleLayersReIm.cpp rename to cpp/RAT/resampleLayersReIm.cpp diff --git a/RAT/resampleLayersReIm.h b/cpp/RAT/resampleLayersReIm.h similarity index 100% rename from RAT/resampleLayersReIm.h rename to cpp/RAT/resampleLayersReIm.h diff --git a/RAT/rescale.cpp b/cpp/RAT/rescale.cpp similarity index 100% rename from RAT/rescale.cpp rename to cpp/RAT/rescale.cpp diff --git a/RAT/rescale.h b/cpp/RAT/rescale.h similarity index 100% rename from RAT/rescale.h rename to cpp/RAT/rescale.h diff --git a/RAT/rescaleKernel.cpp b/cpp/RAT/rescaleKernel.cpp similarity index 100% rename from RAT/rescaleKernel.cpp rename to cpp/RAT/rescaleKernel.cpp diff --git a/RAT/rescaleKernel.h b/cpp/RAT/rescaleKernel.h similarity index 100% rename from RAT/rescaleKernel.h rename to cpp/RAT/rescaleKernel.h diff --git a/RAT/rescaleParameters.cpp b/cpp/RAT/rescaleParameters.cpp similarity index 100% rename from RAT/rescaleParameters.cpp rename to cpp/RAT/rescaleParameters.cpp diff --git a/RAT/rescaleParameters.h b/cpp/RAT/rescaleParameters.h similarity index 100% rename from RAT/rescaleParameters.h rename to cpp/RAT/rescaleParameters.h diff --git a/RAT/reshapeSizeChecks.cpp b/cpp/RAT/reshapeSizeChecks.cpp similarity index 100% rename from RAT/reshapeSizeChecks.cpp rename to cpp/RAT/reshapeSizeChecks.cpp diff --git a/RAT/reshapeSizeChecks.h b/cpp/RAT/reshapeSizeChecks.h similarity index 100% rename from RAT/reshapeSizeChecks.h rename to cpp/RAT/reshapeSizeChecks.h diff --git a/RAT/resolutionPolly.cpp b/cpp/RAT/resolutionPolly.cpp similarity index 100% rename from RAT/resolutionPolly.cpp rename to cpp/RAT/resolutionPolly.cpp diff --git a/RAT/resolutionPolly.h b/cpp/RAT/resolutionPolly.h similarity index 100% rename from RAT/resolutionPolly.h rename to cpp/RAT/resolutionPolly.h diff --git a/RAT/rng.cpp b/cpp/RAT/rng.cpp similarity index 100% rename from RAT/rng.cpp rename to cpp/RAT/rng.cpp diff --git a/RAT/rng.h b/cpp/RAT/rng.h similarity index 100% rename from RAT/rng.h rename to cpp/RAT/rng.h diff --git a/RAT/rtGetInf.cpp b/cpp/RAT/rtGetInf.cpp similarity index 100% rename from RAT/rtGetInf.cpp rename to cpp/RAT/rtGetInf.cpp diff --git a/RAT/rtGetInf.h b/cpp/RAT/rtGetInf.h similarity index 100% rename from RAT/rtGetInf.h rename to cpp/RAT/rtGetInf.h diff --git a/RAT/rtGetNaN.cpp b/cpp/RAT/rtGetNaN.cpp similarity index 100% rename from RAT/rtGetNaN.cpp rename to cpp/RAT/rtGetNaN.cpp diff --git a/RAT/rtGetNaN.h b/cpp/RAT/rtGetNaN.h similarity index 100% rename from RAT/rtGetNaN.h rename to cpp/RAT/rtGetNaN.h diff --git a/RAT/rt_defines.h b/cpp/RAT/rt_defines.h similarity index 100% rename from RAT/rt_defines.h rename to cpp/RAT/rt_defines.h diff --git a/RAT/rt_nonfinite.cpp b/cpp/RAT/rt_nonfinite.cpp similarity index 100% rename from RAT/rt_nonfinite.cpp rename to cpp/RAT/rt_nonfinite.cpp diff --git a/RAT/rt_nonfinite.h b/cpp/RAT/rt_nonfinite.h similarity index 100% rename from RAT/rt_nonfinite.h rename to cpp/RAT/rt_nonfinite.h diff --git a/RAT/rtwtypes.h b/cpp/RAT/rtwtypes.h similarity index 100% rename from RAT/rtwtypes.h rename to cpp/RAT/rtwtypes.h diff --git a/RAT/runDE.cpp b/cpp/RAT/runDE.cpp similarity index 100% rename from RAT/runDE.cpp rename to cpp/RAT/runDE.cpp diff --git a/RAT/runDE.h b/cpp/RAT/runDE.h similarity index 100% rename from RAT/runDE.h rename to cpp/RAT/runDE.h diff --git a/RAT/runDREAM.cpp b/cpp/RAT/runDREAM.cpp similarity index 100% rename from RAT/runDREAM.cpp rename to cpp/RAT/runDREAM.cpp diff --git a/RAT/runDREAM.h b/cpp/RAT/runDREAM.h similarity index 100% rename from RAT/runDREAM.h rename to cpp/RAT/runDREAM.h diff --git a/RAT/runNestedSampler.cpp b/cpp/RAT/runNestedSampler.cpp similarity index 100% rename from RAT/runNestedSampler.cpp rename to cpp/RAT/runNestedSampler.cpp diff --git a/RAT/runNestedSampler.h b/cpp/RAT/runNestedSampler.h similarity index 100% rename from RAT/runNestedSampler.h rename to cpp/RAT/runNestedSampler.h diff --git a/RAT/runSimplex.cpp b/cpp/RAT/runSimplex.cpp similarity index 100% rename from RAT/runSimplex.cpp rename to cpp/RAT/runSimplex.cpp diff --git a/RAT/runSimplex.h b/cpp/RAT/runSimplex.h similarity index 100% rename from RAT/runSimplex.h rename to cpp/RAT/runSimplex.h diff --git a/RAT/scaleParameters.cpp b/cpp/RAT/scaleParameters.cpp similarity index 100% rename from RAT/scaleParameters.cpp rename to cpp/RAT/scaleParameters.cpp diff --git a/RAT/scaleParameters.h b/cpp/RAT/scaleParameters.h similarity index 100% rename from RAT/scaleParameters.h rename to cpp/RAT/scaleParameters.h diff --git a/RAT/scaledGaussPrior.cpp b/cpp/RAT/scaledGaussPrior.cpp similarity index 100% rename from RAT/scaledGaussPrior.cpp rename to cpp/RAT/scaledGaussPrior.cpp diff --git a/RAT/scaledGaussPrior.h b/cpp/RAT/scaledGaussPrior.h similarity index 100% rename from RAT/scaledGaussPrior.h rename to cpp/RAT/scaledGaussPrior.h diff --git a/RAT/schur.cpp b/cpp/RAT/schur.cpp similarity index 100% rename from RAT/schur.cpp rename to cpp/RAT/schur.cpp diff --git a/RAT/schur.h b/cpp/RAT/schur.h similarity index 100% rename from RAT/schur.h rename to cpp/RAT/schur.h diff --git a/RAT/setupDREAM.cpp b/cpp/RAT/setupDREAM.cpp similarity index 100% rename from RAT/setupDREAM.cpp rename to cpp/RAT/setupDREAM.cpp diff --git a/RAT/setupDREAM.h b/cpp/RAT/setupDREAM.h similarity index 100% rename from RAT/setupDREAM.h rename to cpp/RAT/setupDREAM.h diff --git a/RAT/shiftData.cpp b/cpp/RAT/shiftData.cpp similarity index 100% rename from RAT/shiftData.cpp rename to cpp/RAT/shiftData.cpp diff --git a/RAT/shiftData.h b/cpp/RAT/shiftData.h similarity index 100% rename from RAT/shiftData.h rename to cpp/RAT/shiftData.h diff --git a/RAT/simplexIntrafun.cpp b/cpp/RAT/simplexIntrafun.cpp similarity index 100% rename from RAT/simplexIntrafun.cpp rename to cpp/RAT/simplexIntrafun.cpp diff --git a/RAT/simplexIntrafun.h b/cpp/RAT/simplexIntrafun.h similarity index 100% rename from RAT/simplexIntrafun.h rename to cpp/RAT/simplexIntrafun.h diff --git a/RAT/simplexXTransform.cpp b/cpp/RAT/simplexXTransform.cpp similarity index 100% rename from RAT/simplexXTransform.cpp rename to cpp/RAT/simplexXTransform.cpp diff --git a/RAT/simplexXTransform.h b/cpp/RAT/simplexXTransform.h similarity index 100% rename from RAT/simplexXTransform.h rename to cpp/RAT/simplexXTransform.h diff --git a/RAT/single.cpp b/cpp/RAT/single.cpp similarity index 100% rename from RAT/single.cpp rename to cpp/RAT/single.cpp diff --git a/RAT/single.h b/cpp/RAT/single.h similarity index 100% rename from RAT/single.h rename to cpp/RAT/single.h diff --git a/RAT/single1.cpp b/cpp/RAT/single1.cpp similarity index 100% rename from RAT/single1.cpp rename to cpp/RAT/single1.cpp diff --git a/RAT/single1.h b/cpp/RAT/single1.h similarity index 100% rename from RAT/single1.h rename to cpp/RAT/single1.h diff --git a/RAT/single2.cpp b/cpp/RAT/single2.cpp similarity index 100% rename from RAT/single2.cpp rename to cpp/RAT/single2.cpp diff --git a/RAT/single2.h b/cpp/RAT/single2.h similarity index 100% rename from RAT/single2.h rename to cpp/RAT/single2.h diff --git a/RAT/single3.cpp b/cpp/RAT/single3.cpp similarity index 100% rename from RAT/single3.cpp rename to cpp/RAT/single3.cpp diff --git a/RAT/single3.h b/cpp/RAT/single3.h similarity index 100% rename from RAT/single3.h rename to cpp/RAT/single3.h diff --git a/RAT/single4.cpp b/cpp/RAT/single4.cpp similarity index 100% rename from RAT/single4.cpp rename to cpp/RAT/single4.cpp diff --git a/RAT/single4.h b/cpp/RAT/single4.h similarity index 100% rename from RAT/single4.h rename to cpp/RAT/single4.h diff --git a/RAT/single5.cpp b/cpp/RAT/single5.cpp similarity index 100% rename from RAT/single5.cpp rename to cpp/RAT/single5.cpp diff --git a/RAT/single5.h b/cpp/RAT/single5.h similarity index 100% rename from RAT/single5.h rename to cpp/RAT/single5.h diff --git a/RAT/sort.cpp b/cpp/RAT/sort.cpp similarity index 100% rename from RAT/sort.cpp rename to cpp/RAT/sort.cpp diff --git a/RAT/sort.h b/cpp/RAT/sort.h similarity index 100% rename from RAT/sort.h rename to cpp/RAT/sort.h diff --git a/RAT/sortAscendLE.cpp b/cpp/RAT/sortAscendLE.cpp similarity index 100% rename from RAT/sortAscendLE.cpp rename to cpp/RAT/sortAscendLE.cpp diff --git a/RAT/sortAscendLE.h b/cpp/RAT/sortAscendLE.h similarity index 100% rename from RAT/sortAscendLE.h rename to cpp/RAT/sortAscendLE.h diff --git a/RAT/sortIdx.cpp b/cpp/RAT/sortIdx.cpp similarity index 100% rename from RAT/sortIdx.cpp rename to cpp/RAT/sortIdx.cpp diff --git a/RAT/sortIdx.h b/cpp/RAT/sortIdx.h similarity index 100% rename from RAT/sortIdx.h rename to cpp/RAT/sortIdx.h diff --git a/RAT/sortLE.cpp b/cpp/RAT/sortLE.cpp similarity index 100% rename from RAT/sortLE.cpp rename to cpp/RAT/sortLE.cpp diff --git a/RAT/sortLE.h b/cpp/RAT/sortLE.h similarity index 100% rename from RAT/sortLE.h rename to cpp/RAT/sortLE.h diff --git a/RAT/sortrows.cpp b/cpp/RAT/sortrows.cpp similarity index 100% rename from RAT/sortrows.cpp rename to cpp/RAT/sortrows.cpp diff --git a/RAT/sortrows.h b/cpp/RAT/sortrows.h similarity index 100% rename from RAT/sortrows.h rename to cpp/RAT/sortrows.h diff --git a/RAT/splitEllipsoid.cpp b/cpp/RAT/splitEllipsoid.cpp similarity index 100% rename from RAT/splitEllipsoid.cpp rename to cpp/RAT/splitEllipsoid.cpp diff --git a/RAT/splitEllipsoid.h b/cpp/RAT/splitEllipsoid.h similarity index 100% rename from RAT/splitEllipsoid.h rename to cpp/RAT/splitEllipsoid.h diff --git a/RAT/sprintf.cpp b/cpp/RAT/sprintf.cpp similarity index 100% rename from RAT/sprintf.cpp rename to cpp/RAT/sprintf.cpp diff --git a/RAT/sprintf.h b/cpp/RAT/sprintf.h similarity index 100% rename from RAT/sprintf.h rename to cpp/RAT/sprintf.h diff --git a/RAT/sqrt.cpp b/cpp/RAT/sqrt.cpp similarity index 100% rename from RAT/sqrt.cpp rename to cpp/RAT/sqrt.cpp diff --git a/RAT/sqrt.h b/cpp/RAT/sqrt.h similarity index 100% rename from RAT/sqrt.h rename to cpp/RAT/sqrt.h diff --git a/RAT/sqrt1.cpp b/cpp/RAT/sqrt1.cpp similarity index 100% rename from RAT/sqrt1.cpp rename to cpp/RAT/sqrt1.cpp diff --git a/RAT/sqrt1.h b/cpp/RAT/sqrt1.h similarity index 100% rename from RAT/sqrt1.h rename to cpp/RAT/sqrt1.h diff --git a/RAT/std.cpp b/cpp/RAT/std.cpp similarity index 100% rename from RAT/std.cpp rename to cpp/RAT/std.cpp diff --git a/RAT/std.h b/cpp/RAT/std.h similarity index 100% rename from RAT/std.h rename to cpp/RAT/std.h diff --git a/RAT/str2double.cpp b/cpp/RAT/str2double.cpp similarity index 100% rename from RAT/str2double.cpp rename to cpp/RAT/str2double.cpp diff --git a/RAT/str2double.h b/cpp/RAT/str2double.h similarity index 100% rename from RAT/str2double.h rename to cpp/RAT/str2double.h diff --git a/RAT/str2double1.cpp b/cpp/RAT/str2double1.cpp similarity index 100% rename from RAT/str2double1.cpp rename to cpp/RAT/str2double1.cpp diff --git a/RAT/str2double1.h b/cpp/RAT/str2double1.h similarity index 100% rename from RAT/str2double1.h rename to cpp/RAT/str2double1.h diff --git a/RAT/strcmp.cpp b/cpp/RAT/strcmp.cpp similarity index 100% rename from RAT/strcmp.cpp rename to cpp/RAT/strcmp.cpp diff --git a/RAT/strcmp.h b/cpp/RAT/strcmp.h similarity index 100% rename from RAT/strcmp.h rename to cpp/RAT/strcmp.h diff --git a/RAT/structConstructorHelper.cpp b/cpp/RAT/structConstructorHelper.cpp similarity index 100% rename from RAT/structConstructorHelper.cpp rename to cpp/RAT/structConstructorHelper.cpp diff --git a/RAT/structConstructorHelper.h b/cpp/RAT/structConstructorHelper.h similarity index 100% rename from RAT/structConstructorHelper.h rename to cpp/RAT/structConstructorHelper.h diff --git a/RAT/sum.cpp b/cpp/RAT/sum.cpp similarity index 100% rename from RAT/sum.cpp rename to cpp/RAT/sum.cpp diff --git a/RAT/sum.h b/cpp/RAT/sum.h similarity index 100% rename from RAT/sum.h rename to cpp/RAT/sum.h diff --git a/RAT/textProgressBar.cpp b/cpp/RAT/textProgressBar.cpp similarity index 100% rename from RAT/textProgressBar.cpp rename to cpp/RAT/textProgressBar.cpp diff --git a/RAT/textProgressBar.h b/cpp/RAT/textProgressBar.h similarity index 100% rename from RAT/textProgressBar.h rename to cpp/RAT/textProgressBar.h diff --git a/RAT/tic.cpp b/cpp/RAT/tic.cpp similarity index 100% rename from RAT/tic.cpp rename to cpp/RAT/tic.cpp diff --git a/RAT/tic.h b/cpp/RAT/tic.h similarity index 100% rename from RAT/tic.h rename to cpp/RAT/tic.h diff --git a/RAT/timeKeeper.cpp b/cpp/RAT/timeKeeper.cpp similarity index 100% rename from RAT/timeKeeper.cpp rename to cpp/RAT/timeKeeper.cpp diff --git a/RAT/timeKeeper.h b/cpp/RAT/timeKeeper.h similarity index 100% rename from RAT/timeKeeper.h rename to cpp/RAT/timeKeeper.h diff --git a/RAT/tmwtypes.h b/cpp/RAT/tmwtypes.h similarity index 100% rename from RAT/tmwtypes.h rename to cpp/RAT/tmwtypes.h diff --git a/RAT/toc.cpp b/cpp/RAT/toc.cpp similarity index 100% rename from RAT/toc.cpp rename to cpp/RAT/toc.cpp diff --git a/RAT/toc.h b/cpp/RAT/toc.h similarity index 100% rename from RAT/toc.h rename to cpp/RAT/toc.h diff --git a/RAT/triggerEvent.cpp b/cpp/RAT/triggerEvent.cpp similarity index 100% rename from RAT/triggerEvent.cpp rename to cpp/RAT/triggerEvent.cpp diff --git a/RAT/triggerEvent.h b/cpp/RAT/triggerEvent.h similarity index 100% rename from RAT/triggerEvent.h rename to cpp/RAT/triggerEvent.h diff --git a/RAT/triu.cpp b/cpp/RAT/triu.cpp similarity index 100% rename from RAT/triu.cpp rename to cpp/RAT/triu.cpp diff --git a/RAT/triu.h b/cpp/RAT/triu.h similarity index 100% rename from RAT/triu.h rename to cpp/RAT/triu.h diff --git a/RAT/unpackParams.cpp b/cpp/RAT/unpackParams.cpp similarity index 100% rename from RAT/unpackParams.cpp rename to cpp/RAT/unpackParams.cpp diff --git a/RAT/unpackParams.h b/cpp/RAT/unpackParams.h similarity index 100% rename from RAT/unpackParams.h rename to cpp/RAT/unpackParams.h diff --git a/RAT/unsafeSxfun.cpp b/cpp/RAT/unsafeSxfun.cpp similarity index 100% rename from RAT/unsafeSxfun.cpp rename to cpp/RAT/unsafeSxfun.cpp diff --git a/RAT/unsafeSxfun.h b/cpp/RAT/unsafeSxfun.h similarity index 100% rename from RAT/unsafeSxfun.h rename to cpp/RAT/unsafeSxfun.h diff --git a/RAT/useConstantDim.cpp b/cpp/RAT/useConstantDim.cpp similarity index 100% rename from RAT/useConstantDim.cpp rename to cpp/RAT/useConstantDim.cpp diff --git a/RAT/useConstantDim.h b/cpp/RAT/useConstantDim.h similarity index 100% rename from RAT/useConstantDim.h rename to cpp/RAT/useConstantDim.h diff --git a/RAT/vAllOrAny.cpp b/cpp/RAT/vAllOrAny.cpp similarity index 100% rename from RAT/vAllOrAny.cpp rename to cpp/RAT/vAllOrAny.cpp diff --git a/RAT/vAllOrAny.h b/cpp/RAT/vAllOrAny.h similarity index 100% rename from RAT/vAllOrAny.h rename to cpp/RAT/vAllOrAny.h diff --git a/RAT/validate_print_arguments.cpp b/cpp/RAT/validate_print_arguments.cpp similarity index 100% rename from RAT/validate_print_arguments.cpp rename to cpp/RAT/validate_print_arguments.cpp diff --git a/RAT/validate_print_arguments.h b/cpp/RAT/validate_print_arguments.h similarity index 100% rename from RAT/validate_print_arguments.h rename to cpp/RAT/validate_print_arguments.h diff --git a/RAT/var.cpp b/cpp/RAT/var.cpp similarity index 100% rename from RAT/var.cpp rename to cpp/RAT/var.cpp diff --git a/RAT/var.h b/cpp/RAT/var.h similarity index 100% rename from RAT/var.h rename to cpp/RAT/var.h diff --git a/RAT/varstd.cpp b/cpp/RAT/varstd.cpp similarity index 100% rename from RAT/varstd.cpp rename to cpp/RAT/varstd.cpp diff --git a/RAT/varstd.h b/cpp/RAT/varstd.h similarity index 100% rename from RAT/varstd.h rename to cpp/RAT/varstd.h diff --git a/RAT/xdhseqr.cpp b/cpp/RAT/xdhseqr.cpp similarity index 100% rename from RAT/xdhseqr.cpp rename to cpp/RAT/xdhseqr.cpp diff --git a/RAT/xdhseqr.h b/cpp/RAT/xdhseqr.h similarity index 100% rename from RAT/xdhseqr.h rename to cpp/RAT/xdhseqr.h diff --git a/RAT/xdlanv2.cpp b/cpp/RAT/xdlanv2.cpp similarity index 100% rename from RAT/xdlanv2.cpp rename to cpp/RAT/xdlanv2.cpp diff --git a/RAT/xdlanv2.h b/cpp/RAT/xdlanv2.h similarity index 100% rename from RAT/xdlanv2.h rename to cpp/RAT/xdlanv2.h diff --git a/RAT/xgehrd.cpp b/cpp/RAT/xgehrd.cpp similarity index 100% rename from RAT/xgehrd.cpp rename to cpp/RAT/xgehrd.cpp diff --git a/RAT/xgehrd.h b/cpp/RAT/xgehrd.h similarity index 100% rename from RAT/xgehrd.h rename to cpp/RAT/xgehrd.h diff --git a/RAT/xgemm.cpp b/cpp/RAT/xgemm.cpp similarity index 100% rename from RAT/xgemm.cpp rename to cpp/RAT/xgemm.cpp diff --git a/RAT/xgemm.h b/cpp/RAT/xgemm.h similarity index 100% rename from RAT/xgemm.h rename to cpp/RAT/xgemm.h diff --git a/RAT/xgemv.cpp b/cpp/RAT/xgemv.cpp similarity index 100% rename from RAT/xgemv.cpp rename to cpp/RAT/xgemv.cpp diff --git a/RAT/xgemv.h b/cpp/RAT/xgemv.h similarity index 100% rename from RAT/xgemv.h rename to cpp/RAT/xgemv.h diff --git a/RAT/xgeqp3.cpp b/cpp/RAT/xgeqp3.cpp similarity index 100% rename from RAT/xgeqp3.cpp rename to cpp/RAT/xgeqp3.cpp diff --git a/RAT/xgeqp3.h b/cpp/RAT/xgeqp3.h similarity index 100% rename from RAT/xgeqp3.h rename to cpp/RAT/xgeqp3.h diff --git a/RAT/xgerc.cpp b/cpp/RAT/xgerc.cpp similarity index 100% rename from RAT/xgerc.cpp rename to cpp/RAT/xgerc.cpp diff --git a/RAT/xgerc.h b/cpp/RAT/xgerc.h similarity index 100% rename from RAT/xgerc.h rename to cpp/RAT/xgerc.h diff --git a/RAT/xgeru.cpp b/cpp/RAT/xgeru.cpp similarity index 100% rename from RAT/xgeru.cpp rename to cpp/RAT/xgeru.cpp diff --git a/RAT/xgeru.h b/cpp/RAT/xgeru.h similarity index 100% rename from RAT/xgeru.h rename to cpp/RAT/xgeru.h diff --git a/RAT/xgetrf.cpp b/cpp/RAT/xgetrf.cpp similarity index 100% rename from RAT/xgetrf.cpp rename to cpp/RAT/xgetrf.cpp diff --git a/RAT/xgetrf.h b/cpp/RAT/xgetrf.h similarity index 100% rename from RAT/xgetrf.h rename to cpp/RAT/xgetrf.h diff --git a/RAT/xnrm2.cpp b/cpp/RAT/xnrm2.cpp similarity index 100% rename from RAT/xnrm2.cpp rename to cpp/RAT/xnrm2.cpp diff --git a/RAT/xnrm2.h b/cpp/RAT/xnrm2.h similarity index 100% rename from RAT/xnrm2.h rename to cpp/RAT/xnrm2.h diff --git a/RAT/xrot.cpp b/cpp/RAT/xrot.cpp similarity index 100% rename from RAT/xrot.cpp rename to cpp/RAT/xrot.cpp diff --git a/RAT/xrot.h b/cpp/RAT/xrot.h similarity index 100% rename from RAT/xrot.h rename to cpp/RAT/xrot.h diff --git a/RAT/xswap.cpp b/cpp/RAT/xswap.cpp similarity index 100% rename from RAT/xswap.cpp rename to cpp/RAT/xswap.cpp diff --git a/RAT/xswap.h b/cpp/RAT/xswap.h similarity index 100% rename from RAT/xswap.h rename to cpp/RAT/xswap.h diff --git a/RAT/xtrsm.cpp b/cpp/RAT/xtrsm.cpp similarity index 100% rename from RAT/xtrsm.cpp rename to cpp/RAT/xtrsm.cpp diff --git a/RAT/xtrsm.h b/cpp/RAT/xtrsm.h similarity index 100% rename from RAT/xtrsm.h rename to cpp/RAT/xtrsm.h diff --git a/RAT/xtrsv.cpp b/cpp/RAT/xtrsv.cpp similarity index 100% rename from RAT/xtrsv.cpp rename to cpp/RAT/xtrsv.cpp diff --git a/RAT/xtrsv.h b/cpp/RAT/xtrsv.h similarity index 100% rename from RAT/xtrsv.h rename to cpp/RAT/xtrsv.h diff --git a/RAT/xungorghr.cpp b/cpp/RAT/xungorghr.cpp similarity index 100% rename from RAT/xungorghr.cpp rename to cpp/RAT/xungorghr.cpp diff --git a/RAT/xungorghr.h b/cpp/RAT/xungorghr.h similarity index 100% rename from RAT/xungorghr.h rename to cpp/RAT/xungorghr.h diff --git a/RAT/xunormqr.cpp b/cpp/RAT/xunormqr.cpp similarity index 100% rename from RAT/xunormqr.cpp rename to cpp/RAT/xunormqr.cpp diff --git a/RAT/xunormqr.h b/cpp/RAT/xunormqr.h similarity index 100% rename from RAT/xunormqr.h rename to cpp/RAT/xunormqr.h diff --git a/RAT/xzgeev.cpp b/cpp/RAT/xzgeev.cpp similarity index 100% rename from RAT/xzgeev.cpp rename to cpp/RAT/xzgeev.cpp diff --git a/RAT/xzgeev.h b/cpp/RAT/xzgeev.h similarity index 100% rename from RAT/xzgeev.h rename to cpp/RAT/xzgeev.h diff --git a/RAT/xzgeqp3.cpp b/cpp/RAT/xzgeqp3.cpp similarity index 100% rename from RAT/xzgeqp3.cpp rename to cpp/RAT/xzgeqp3.cpp diff --git a/RAT/xzgeqp3.h b/cpp/RAT/xzgeqp3.h similarity index 100% rename from RAT/xzgeqp3.h rename to cpp/RAT/xzgeqp3.h diff --git a/RAT/xzggbak.cpp b/cpp/RAT/xzggbak.cpp similarity index 100% rename from RAT/xzggbak.cpp rename to cpp/RAT/xzggbak.cpp diff --git a/RAT/xzggbak.h b/cpp/RAT/xzggbak.h similarity index 100% rename from RAT/xzggbak.h rename to cpp/RAT/xzggbak.h diff --git a/RAT/xzggbal.cpp b/cpp/RAT/xzggbal.cpp similarity index 100% rename from RAT/xzggbal.cpp rename to cpp/RAT/xzggbal.cpp diff --git a/RAT/xzggbal.h b/cpp/RAT/xzggbal.h similarity index 100% rename from RAT/xzggbal.h rename to cpp/RAT/xzggbal.h diff --git a/RAT/xzggev.cpp b/cpp/RAT/xzggev.cpp similarity index 100% rename from RAT/xzggev.cpp rename to cpp/RAT/xzggev.cpp diff --git a/RAT/xzggev.h b/cpp/RAT/xzggev.h similarity index 100% rename from RAT/xzggev.h rename to cpp/RAT/xzggev.h diff --git a/RAT/xzgghrd.cpp b/cpp/RAT/xzgghrd.cpp similarity index 100% rename from RAT/xzgghrd.cpp rename to cpp/RAT/xzgghrd.cpp diff --git a/RAT/xzgghrd.h b/cpp/RAT/xzgghrd.h similarity index 100% rename from RAT/xzgghrd.h rename to cpp/RAT/xzgghrd.h diff --git a/RAT/xzhgeqz.cpp b/cpp/RAT/xzhgeqz.cpp similarity index 100% rename from RAT/xzhgeqz.cpp rename to cpp/RAT/xzhgeqz.cpp diff --git a/RAT/xzhgeqz.h b/cpp/RAT/xzhgeqz.h similarity index 100% rename from RAT/xzhgeqz.h rename to cpp/RAT/xzhgeqz.h diff --git a/RAT/xzlangeM.cpp b/cpp/RAT/xzlangeM.cpp similarity index 100% rename from RAT/xzlangeM.cpp rename to cpp/RAT/xzlangeM.cpp diff --git a/RAT/xzlangeM.h b/cpp/RAT/xzlangeM.h similarity index 100% rename from RAT/xzlangeM.h rename to cpp/RAT/xzlangeM.h diff --git a/RAT/xzlanhs.cpp b/cpp/RAT/xzlanhs.cpp similarity index 100% rename from RAT/xzlanhs.cpp rename to cpp/RAT/xzlanhs.cpp diff --git a/RAT/xzlanhs.h b/cpp/RAT/xzlanhs.h similarity index 100% rename from RAT/xzlanhs.h rename to cpp/RAT/xzlanhs.h diff --git a/RAT/xzlarf.cpp b/cpp/RAT/xzlarf.cpp similarity index 100% rename from RAT/xzlarf.cpp rename to cpp/RAT/xzlarf.cpp diff --git a/RAT/xzlarf.h b/cpp/RAT/xzlarf.h similarity index 100% rename from RAT/xzlarf.h rename to cpp/RAT/xzlarf.h diff --git a/RAT/xzlarfg.cpp b/cpp/RAT/xzlarfg.cpp similarity index 100% rename from RAT/xzlarfg.cpp rename to cpp/RAT/xzlarfg.cpp diff --git a/RAT/xzlarfg.h b/cpp/RAT/xzlarfg.h similarity index 100% rename from RAT/xzlarfg.h rename to cpp/RAT/xzlarfg.h diff --git a/RAT/xzlartg.cpp b/cpp/RAT/xzlartg.cpp similarity index 100% rename from RAT/xzlartg.cpp rename to cpp/RAT/xzlartg.cpp diff --git a/RAT/xzlartg.h b/cpp/RAT/xzlartg.h similarity index 100% rename from RAT/xzlartg.h rename to cpp/RAT/xzlartg.h diff --git a/RAT/xzlascl.cpp b/cpp/RAT/xzlascl.cpp similarity index 100% rename from RAT/xzlascl.cpp rename to cpp/RAT/xzlascl.cpp diff --git a/RAT/xzlascl.h b/cpp/RAT/xzlascl.h similarity index 100% rename from RAT/xzlascl.h rename to cpp/RAT/xzlascl.h diff --git a/RAT/xztgevc.cpp b/cpp/RAT/xztgevc.cpp similarity index 100% rename from RAT/xztgevc.cpp rename to cpp/RAT/xztgevc.cpp diff --git a/RAT/xztgevc.h b/cpp/RAT/xztgevc.h similarity index 100% rename from RAT/xztgevc.h rename to cpp/RAT/xztgevc.h diff --git a/RAT/xzungqr.cpp b/cpp/RAT/xzungqr.cpp similarity index 100% rename from RAT/xzungqr.cpp rename to cpp/RAT/xzungqr.cpp diff --git a/RAT/xzungqr.h b/cpp/RAT/xzungqr.h similarity index 100% rename from RAT/xzungqr.h rename to cpp/RAT/xzungqr.h diff --git a/rat.cpp b/cpp/rat.cpp similarity index 99% rename from rat.cpp rename to cpp/rat.cpp index 022d8f11..57e3fe90 100644 --- a/rat.cpp +++ b/cpp/rat.cpp @@ -18,7 +18,7 @@ setup_pybind11(cfg) #include "RAT/RATMain_types.h" #include "RAT/classHandle.hpp" #include "RAT/dylib.hpp" -#include "events/eventManager.h" +#include "RAT/events/eventManager.h" namespace py = pybind11; @@ -151,7 +151,7 @@ class EventStuff EventStuff(py::function callback) { std::string filename = "eventManager" + std::string(dylib::extension); - this->library = std::unique_ptr(new dylib("", filename.c_str())); + this->library = std::unique_ptr(new dylib(std::getenv("RAT_PATH"), filename.c_str())); if (!library) { std::cerr << "event manager dynamic libray failed to load" << std::endl; @@ -1209,7 +1209,7 @@ class Module } }; -PYBIND11_MODULE(rat, m) { +PYBIND11_MODULE(rat_core, m) { static Module module; py::class_(m, "EventStuff") .def(py::init()) diff --git a/DSPC_bilayer_example.py b/examples/DSPC_bilayer_example.py similarity index 97% rename from DSPC_bilayer_example.py rename to examples/DSPC_bilayer_example.py index c20000db..9debc19c 100644 --- a/DSPC_bilayer_example.py +++ b/examples/DSPC_bilayer_example.py @@ -1,15 +1,13 @@ -import cppimport import numpy as np - -rat = cppimport.imp("rat") +from rat import rat_core if __name__ == '__main__': - control = rat.Control() - problem = rat.ProblemDefinition() - limits = rat.Limits() - cells = rat.Cells() - priors = rat.Priors() + control = rat_core.Control() + problem = rat_core.ProblemDefinition() + limits = rat_core.Limits() + cells = rat_core.Cells() + priors = rat_core.Priors() #------------------------------------------------------------------------------------ # Control @@ -189,7 +187,7 @@ [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf], [1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf],[1, 0, np.Inf]] - problem, contrast_params, result, bayes_results = rat.RATMain(problem, cells, limits, control, priors) + problem, contrast_params, result, bayes_results = rat_core.RATMain(problem, cells, limits, control, priors) print(contrast_params.ssubs) print(contrast_params.backgroundParams) diff --git a/DSPC_custom_layers_example.py b/examples/DSPC_custom_layers_example.py similarity index 93% rename from DSPC_custom_layers_example.py rename to examples/DSPC_custom_layers_example.py index c2e12a32..a448b46d 100644 --- a/DSPC_custom_layers_example.py +++ b/examples/DSPC_custom_layers_example.py @@ -1,22 +1,19 @@ import faulthandler -import cppimport import numpy as np from customBilayer import customBilayer -from misc import MatlabWrapper, DylibWrapper -import events +from rat import events, rat_core +from rat.misc import MatlabWrapper, DylibWrapper faulthandler.enable() -rat = cppimport.imp("rat") - if __name__ == '__main__': - control = rat.Control() - problem = rat.ProblemDefinition() - limits = rat.Limits() - cells = rat.Cells() - priors = rat.Priors() + control = rat_core.Control() + problem = rat_core.ProblemDefinition() + limits = rat_core.Limits() + cells = rat_core.Cells() + priors = rat_core.Priors() #------------------------------------------------------------------------------------ # Control @@ -131,10 +128,10 @@ cells.f12 = ['SLD D2O', 'SLD SMW', 'SLD H2O'] cells.f13 = ['Resolution par 1'] - dylib_wrapper = DylibWrapper('customBilayer.dll', 'customBilayer') + dylib_wrapper = DylibWrapper('examples/customBilayer.dll', 'customBilayer') cells.f14 = [dylib_wrapper.getHandle()] # C++ callback - # matlab_wrapper = MatlabWrapper('customBilayer.m') + # matlab_wrapper = MatlabWrapper('examples/customBilayer.m') # cells.f14 = [matlab_wrapper.getHandle()] # Matlab callback # cells.f14 = [customBilayer] # Python callback @@ -178,8 +175,8 @@ def fakePlot(event): import time start = time.perf_counter() - events.register(rat.EventTypes.Plot, fakePlot) - problem, contrast_params, result, bayes_results = rat.RATMain(problem, cells, limits, control, priors) + events.register(rat_core.EventTypes.Plot, fakePlot) + problem, contrast_params, result, bayes_results = rat_core.RATMain(problem, cells, limits, control, priors) events.clear() print(time.perf_counter() - start, 'sec') # print(contrast_params.ssubs) diff --git a/alloyDomains.cpp b/examples/alloyDomains.cpp similarity index 100% rename from alloyDomains.cpp rename to examples/alloyDomains.cpp diff --git a/alloyDomains.m b/examples/alloyDomains.m similarity index 100% rename from alloyDomains.m rename to examples/alloyDomains.m diff --git a/alloyDomains.py b/examples/alloyDomains.py similarity index 100% rename from alloyDomains.py rename to examples/alloyDomains.py diff --git a/customBilayer.m b/examples/customBilayer.m similarity index 100% rename from customBilayer.m rename to examples/customBilayer.m diff --git a/customBilayer.py b/examples/customBilayer.py similarity index 100% rename from customBilayer.py rename to examples/customBilayer.py diff --git a/domains_custom_layers_example.py b/examples/domains_custom_layers_example.py similarity index 93% rename from domains_custom_layers_example.py rename to examples/domains_custom_layers_example.py index c1ab7134..30da6933 100644 --- a/domains_custom_layers_example.py +++ b/examples/domains_custom_layers_example.py @@ -1,21 +1,19 @@ import faulthandler -import cppimport import numpy as np from alloyDomains import alloyDomains -from misc import MatlabWrapper, DylibWrapper +from rat import events, rat_core +from rat.misc import MatlabWrapper, DylibWrapper faulthandler.enable() -rat = cppimport.imp("rat") - if __name__ == '__main__': - control = rat.Control() - problem = rat.ProblemDefinition() - limits = rat.Limits() - cells = rat.Cells() - priors = rat.Priors() + control = rat_core.Control() + problem = rat_core.ProblemDefinition() + limits = rat_core.Limits() + cells = rat_core.Cells() + priors = rat_core.Priors() #------------------------------------------------------------------------------------ # Control @@ -126,10 +124,10 @@ cells.f12 = ['SLD D2O'] cells.f13 = ['Resolution par 1'] - dylib_wrapper = DylibWrapper('alloyDomains.dll', 'alloyDomains') + dylib_wrapper = DylibWrapper('examples/alloyDomains.dll', 'alloyDomains') cells.f14 = [dylib_wrapper.getHandle()] # C++ callback - # matlab_wrapper = MatlabWrapper('alloyDomains.m') + # matlab_wrapper = MatlabWrapper('examples/alloyDomains.m') # cells.f14 = [matlab_wrapper.getHandle()] # Matlab callback # cells.f14 = [alloyDomains] # Python callback @@ -170,7 +168,7 @@ import time start = time.perf_counter() - problem, contrast_params, result, bayes_results = rat.RATMain(problem, cells, limits, control, priors) + problem, contrast_params, result, bayes_results = rat_core.RATMain(problem, cells, limits, control, priors) print(time.perf_counter() - start, 'sec') # print(contrast_params.ssubs) # print(contrast_params.backgroundParams) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..91e42ebf --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel", + "pybind11>=2.4", + "numpy", +] + +build-backend = "setuptools.build_meta" diff --git a/rat/__init__.py b/rat/__init__.py new file mode 100644 index 00000000..bd3e549b --- /dev/null +++ b/rat/__init__.py @@ -0,0 +1,4 @@ +import os + +dir_path = os.path.dirname(os.path.realpath(__file__)) +os.environ["RAT_PATH"] = os.path.join(dir_path, '') diff --git a/events.py b/rat/events.py similarity index 53% rename from events.py rename to rat/events.py index f540022e..7f2f4577 100644 --- a/events.py +++ b/rat/events.py @@ -1,9 +1,4 @@ -import pathlib -import cppimport -import numpy as np -import matlab.engine - -rat = cppimport.imp("rat") +from rat import rat_core def nofiy(event_type, data): @@ -13,8 +8,8 @@ def nofiy(event_type, data): def register(event_type, callback): - if not isinstance(event_type, rat.EventTypes): - raise ValueError("event_type must be a rat.EventTypes enum") + if not isinstance(event_type, rat_core.EventTypes): + raise ValueError("event_type must be a rat_core.EventTypes enum") if len(__event_callbacks[event_type]) == 0: __event_impl.register(event_type) @@ -26,5 +21,5 @@ def clear(): __event_callbacks.clear() -__event_impl = rat.EventStuff(nofiy) -__event_callbacks = {rat.EventTypes.Message: set(), rat.EventTypes.Plot: set()} +__event_impl = rat_core.EventStuff(nofiy) +__event_callbacks = {rat_core.EventTypes.Message: set(), rat_core.EventTypes.Plot: set()} diff --git a/misc.py b/rat/misc.py similarity index 94% rename from misc.py rename to rat/misc.py index 1cbb3309..6e10ab3a 100644 --- a/misc.py +++ b/rat/misc.py @@ -1,9 +1,7 @@ import pathlib -import cppimport import numpy as np import matlab.engine - -rat = cppimport.imp("rat") +from rat import rat_core class MatlabWrapper: @@ -34,7 +32,7 @@ def handle(params, bulk_in, bulk_out, contrast, domain=-1): class DylibWrapper: def __init__(self, filename, function_name): - self.engine = rat.DylibEngine(filename, function_name) + self.engine = rat_core.DylibEngine(filename, function_name) def getHandle(self): def handle(params, bulk_in, bulk_out, contrast, domain=-1): diff --git a/requirements.txt b/requirements.txt index f8bd94e3..83550d52 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -cppimport numpy pybind11 -matlabengine \ No newline at end of file +matlabengine diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..3a8326c5 --- /dev/null +++ b/setup.py @@ -0,0 +1,150 @@ +from glob import glob +import platform +from setuptools import setup, Extension +from setuptools.command.build_ext import build_ext +from setuptools.command.build_clib import build_clib +import sys +import pybind11 + +__version__ = '0.0.0' + + +libevent = ('eventManager', {'sources': ['cpp/RAT/events/eventManager.cpp'], + 'include_dirs': ['cpp/RAT/events/']}) + + +ext_modules = [ + Extension( + 'rat.rat_core', + sources=['cpp/rat.cpp', *glob('cpp/RAT/*.c*')], + include_dirs=[ + # Path to pybind11 headers + pybind11.get_include(), + pybind11.get_include(True), + 'cpp/RAT/', + ], + language='c++' + ), +] + + +# check whether compiler supports a flag +def has_flag(compiler, flagname): + import tempfile + from distutils.errors import CompileError + with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f: + f.write('int main (int argc, char **argv) { return 0; }') + try: + compiler.compile([f.name], extra_postargs=[flagname]) + except CompileError: + return False + return True + + +def get_shared_object_name(lib_name): + if platform.system() == 'Windows': + return f'{lib_name}.dll' + elif platform.system() == 'Darwin': + return f'{lib_name}.dylib' + else: + return f'{lib_name}.so' + + +class BuildExt(build_ext): + """A custom build extension for adding compiler-specific options.""" + c_opts = { + 'msvc': ['/EHsc'], + 'unix': ['-fopenmp'], + } + l_opts = { + 'msvc': [], + 'unix': ['-fopenmp'], + } + + if sys.platform == 'darwin': + darwin_opts = ['-stdlib=libc++', '-mmacosx-version-min=10.7'] + c_opts['unix'] += darwin_opts + l_opts['unix'] += darwin_opts + + def build_extensions(self): + ct = self.compiler.compiler_type + opts = self.c_opts.get(ct, []) + link_opts = self.l_opts.get(ct, []) + if ct == 'unix': + if '-Wstrict-prototypes' in self.compiler.compiler_so: + self.compiler.compiler_so.remove('-Wstrict-prototypes') + + opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version()) + opts.append('-std=c++11') + if has_flag(self.compiler, '-fvisibility=hidden'): + opts.append('-fvisibility=hidden') + elif ct == 'msvc': + opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version()) + for ext in self.extensions: + ext.extra_compile_args = opts + ext.extra_link_args = link_opts + build_ext.build_extensions(self) + + +class BuildClib(build_clib): + def initialize_options(self): + super().initialize_options() + build_py = self.get_finalized_command('build_py') + self.build_clib = build_py.get_package_dir("rat") + + def build_libraries(self, libraries): + # bug in distutils: flag not valid for c++ + flag = '-Wstrict-prototypes' + if (hasattr(self.compiler, 'compiler_so') + and flag in self.compiler.compiler_so): + self.compiler.compiler_so.remove(flag) + + compiler_type = self.compiler.compiler_type + if compiler_type == 'msvc': + compile_args = ['/std:c++11', '/EHsc', '/LD'] + else: + compile_args = ['-std=c++11', '-fPIC'] + + for (lib_name, build_info) in libraries: + build_info['cflags'] = compile_args + macros = build_info.get('macros') + include_dirs = build_info.get('include_dirs') + cflags = build_info.get('cflags') + sources = list(build_info.get('sources')) + objects = self.compiler.compile( + sources, + output_dir=self.build_temp, + macros=macros, + include_dirs=include_dirs, + extra_postargs=cflags, + debug=self.debug + ) + language = self.compiler.detect_language(sources) + self.compiler.link_shared_object( + objects, + get_shared_object_name(lib_name), + output_dir=self.build_clib, + target_lang=language + ) + + super().build_libraries(libraries) + + +setup( + name='rat', + version=__version__, + author='demo', + author_email='demo@gmail.com', + url='https://github.com/RascalSoftware/python-RAT', + description='Python extension for the Reflectivity Analysis Toolbox (RAT)', + long_description='', + packages=['rat'], + package_data={'rat': [get_shared_object_name(libevent[0])]}, + libraries=[libevent], + ext_modules=ext_modules, + install_requires=['pybind11>=2.4', 'numpy'], + python_requires='>=3.9', + # setup_requires=['pybind11>=2.4'], + cmdclass={'build_ext': BuildExt, 'build_clib': BuildClib}, + zip_safe=False, +) From 03f3259de829355bdcc6f2d0a15a8d250a671f6b Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Tue, 20 Feb 2024 10:33:09 +0000 Subject: [PATCH 6/8] Updates setup.py to delete unneeded build artifact and adds github action to build --- .gitignore | 2 + MANIFEST.in | 1 + README.md | 5 +- _github/workflows/runTests.yml | 61 +++++ cpp/rat.cpp | 272 +++++++++++----------- examples/DSPC_custom_layers_example.py | 10 +- examples/domains_custom_layers_example.py | 10 +- pyproject.toml | 9 +- rat/misc.py | 50 ++-- setup.py | 48 ++-- 10 files changed, 283 insertions(+), 185 deletions(-) create mode 100644 MANIFEST.in create mode 100644 _github/workflows/runTests.yml diff --git a/.gitignore b/.gitignore index 495640e3..ed603d64 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ __pycache__/ *.a *.egg-info/ build/* +dist/* +*.whl diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..64ad321d --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include README.md LICENSE diff --git a/README.md b/README.md index aaac7eb1..35f2a9c8 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,12 @@ Build This has been tested using python 3.9, a c++ compiler is required to run the code. Install the requirement then run the example, if the compiler can be found, the python extension (*.pyd) will be built and the example will run - Install ======= To install in local directory: pip install -e . + +To build wheel: + pip install build + python -m build --wheel diff --git a/_github/workflows/runTests.yml b/_github/workflows/runTests.yml new file mode 100644 index 00000000..325ce20b --- /dev/null +++ b/_github/workflows/runTests.yml @@ -0,0 +1,61 @@ +name: Run Unit Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + test: + strategy: + fail-fast: false + matrix: + platform: [windows-latest, ubuntu-latest, macos-latest] + env: + CIBW_BUILD: 'cp39-*' + CIBW_ARCHS: 'auto64' + + runs-on: ${{ matrix.platform }} + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.9 + uses: actions/setup-python@v4 + with: + python-version: "3.9" + - name: Install (MacOS) + if: runner.os == 'macOS' + run: | + brew install llvm libomp + export CC=/usr/local/opt/llvm/bin/clang + export CFLAGS="$CFLAGS -I/usr/local/opt/libomp/include" + export CXXFLAGS="$CXXFLAGS -I/usr/local/opt/libomp/include" + export LDFLAGS="$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp" + python -m pip install cibuildwheel==2.16.5 + python -m cibuildwheel --output-dir wheelhouse + - name: Install (Linux) + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt install libomp-dev + python -m pip install cibuildwheel==2.16.5 + python -m cibuildwheel --output-dir wheelhouse + - name: Install (Windows) + if: runner.os == 'Windows' + run: | + python -m pip install cibuildwheel==2.16.5 + python -m cibuildwheel --output-dir wheelhouse + - uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} + path: ./wheelhouse/*.whl + - name: Run Example + run: | + python -m pip install --no-index --find-links wheelhouse/ rat + python examples/DSPC_custom_layers_example.py diff --git a/cpp/rat.cpp b/cpp/rat.cpp index 57e3fe90..d6be51f6 100644 --- a/cpp/rat.cpp +++ b/cpp/rat.cpp @@ -492,7 +492,7 @@ struct Control { }; -void string_to_rat_array(std::string value, char_T result_data[], int32_T result_size[2]) +void stringToRatArray(std::string value, char_T result_data[], int32_T result_size[2]) { result_size[0] = 1; result_size[1] = value.length(); @@ -502,7 +502,7 @@ void string_to_rat_array(std::string value, char_T result_data[], int32_T result } } -void string_to_rat_char_array(std::string value, coder::array& result) +void stringToRatCharArray(std::string value, coder::array& result) { result.set_size(1, value.length()); @@ -511,7 +511,7 @@ void string_to_rat_char_array(std::string value, coder::array& resul } } -coder::array py_array_to_rat_1d_array(py::array_t value) +coder::array pyArrayToRatArray1d(py::array_t value) { coder::array result; @@ -531,7 +531,7 @@ coder::array py_array_to_rat_1d_array(py::array_t value) return result; } -coder::bounded_array py_array_to_rat_bounded_array(py::array_t value) +coder::bounded_array pyArrayToRatBoundedArray(py::array_t value) { coder::bounded_array result {}; @@ -552,7 +552,7 @@ coder::bounded_array py_array_to_rat_bounded_array(py::array_t< return result; } -coder::array py_array_to_rat_2d_array(py::array_t value) +coder::array pyArrayToRatArray2d(py::array_t value) { coder::array result; @@ -587,8 +587,8 @@ coder::array py_array_to_unboundedx1_cell_0(py::list values) py::list value = py::cast(list); if (py::len(list) != 4) throw std::runtime_error("Number of dimensions for each row must be 4"); - string_to_rat_char_array(value[0].cast(), result[idx].f1); - string_to_rat_char_array(value[1].cast(), result[idx].f2); + stringToRatCharArray(value[0].cast(), result[idx].f1); + stringToRatCharArray(value[1].cast(), result[idx].f2); result[idx].f3 = value[2].cast(); result[idx].f4 = value[3].cast(); idx++; @@ -606,14 +606,14 @@ coder::array py_array_to_unboundedx1_cell_1(py::list value { std::string value = py::cast(list); //TODO: validate dimension - string_to_rat_char_array(value, result[idx].f1); + stringToRatCharArray(value, result[idx].f1); idx++; } return result; } -RAT::struct0_T create_struct0_T(const ProblemDefinition& problem) +RAT::struct0_T createStruct0_T(const ProblemDefinition& problem) { RAT::struct0_T problem_struct; @@ -623,51 +623,51 @@ RAT::struct0_T create_struct0_T(const ProblemDefinition& problem) problem_struct.numberOfDomainContrasts = problem.numberOfDomainContrasts; problem_struct.numberOfContrasts = problem.numberOfContrasts; - string_to_rat_array(problem.modelType, problem_struct.modelType.data, problem_struct.modelType.size); - string_to_rat_array(problem.geometry, problem_struct.geometry.data, problem_struct.geometry.size); - string_to_rat_array(problem.TF, problem_struct.TF.data, problem_struct.TF.size); + stringToRatArray(problem.modelType, problem_struct.modelType.data, problem_struct.modelType.size); + stringToRatArray(problem.geometry, problem_struct.geometry.data, problem_struct.geometry.size); + stringToRatArray(problem.TF, problem_struct.TF.data, problem_struct.TF.size); - problem_struct.contrastBackgrounds = py_array_to_rat_1d_array(problem.contrastBackgrounds); - problem_struct.contrastBackgroundsType = py_array_to_rat_1d_array(problem.contrastBackgroundsType); - problem_struct.resample = py_array_to_rat_1d_array(problem.resample); - problem_struct.dataPresent = py_array_to_rat_1d_array(problem.dataPresent); - problem_struct.oilChiDataPresent = py_array_to_rat_1d_array(problem.oilChiDataPresent); - problem_struct.contrastQzshifts = py_array_to_rat_1d_array(problem.contrastQzshifts); - problem_struct.contrastScalefactors = py_array_to_rat_1d_array(problem.contrastScalefactors); - problem_struct.contrastBulkIns = py_array_to_rat_1d_array(problem.contrastBulkIns); - problem_struct.contrastBulkOuts = py_array_to_rat_1d_array(problem.contrastBulkOuts); - problem_struct.contrastResolutions = py_array_to_rat_1d_array(problem.contrastResolutions); - problem_struct.backgroundParams = py_array_to_rat_1d_array(problem.backgroundParams); - problem_struct.qzshifts = py_array_to_rat_1d_array(problem.qzshifts); - problem_struct.scalefactors = py_array_to_rat_1d_array(problem.scalefactors); - problem_struct.bulkIn = py_array_to_rat_1d_array(problem.bulkIn); - problem_struct.bulkOut = py_array_to_rat_1d_array(problem.bulkOut); - problem_struct.resolutionParams = py_array_to_rat_1d_array(problem.resolutionParams); - problem_struct.params = py_array_to_rat_1d_array(problem.params); - - problem_struct.contrastCustomFiles = py_array_to_rat_1d_array(problem.contrastCustomFiles); - problem_struct.contrastDomainRatios = py_array_to_rat_1d_array(problem.contrastDomainRatios); - problem_struct.domainRatio = py_array_to_rat_1d_array(problem.domainRatio); - - problem_struct.fitParams = py_array_to_rat_1d_array(problem.fitParams); - problem_struct.otherParams = py_array_to_rat_1d_array(problem.otherParams); - problem_struct.fitLimits = py_array_to_rat_2d_array(problem.fitLimits); - problem_struct.otherLimits = py_array_to_rat_2d_array(problem.otherLimits); + problem_struct.contrastBackgrounds = pyArrayToRatArray1d(problem.contrastBackgrounds); + problem_struct.contrastBackgroundsType = pyArrayToRatArray1d(problem.contrastBackgroundsType); + problem_struct.resample = pyArrayToRatArray1d(problem.resample); + problem_struct.dataPresent = pyArrayToRatArray1d(problem.dataPresent); + problem_struct.oilChiDataPresent = pyArrayToRatArray1d(problem.oilChiDataPresent); + problem_struct.contrastQzshifts = pyArrayToRatArray1d(problem.contrastQzshifts); + problem_struct.contrastScalefactors = pyArrayToRatArray1d(problem.contrastScalefactors); + problem_struct.contrastBulkIns = pyArrayToRatArray1d(problem.contrastBulkIns); + problem_struct.contrastBulkOuts = pyArrayToRatArray1d(problem.contrastBulkOuts); + problem_struct.contrastResolutions = pyArrayToRatArray1d(problem.contrastResolutions); + problem_struct.backgroundParams = pyArrayToRatArray1d(problem.backgroundParams); + problem_struct.qzshifts = pyArrayToRatArray1d(problem.qzshifts); + problem_struct.scalefactors = pyArrayToRatArray1d(problem.scalefactors); + problem_struct.bulkIn = pyArrayToRatArray1d(problem.bulkIn); + problem_struct.bulkOut = pyArrayToRatArray1d(problem.bulkOut); + problem_struct.resolutionParams = pyArrayToRatArray1d(problem.resolutionParams); + problem_struct.params = pyArrayToRatArray1d(problem.params); + + problem_struct.contrastCustomFiles = pyArrayToRatArray1d(problem.contrastCustomFiles); + problem_struct.contrastDomainRatios = pyArrayToRatArray1d(problem.contrastDomainRatios); + problem_struct.domainRatio = pyArrayToRatArray1d(problem.domainRatio); + + problem_struct.fitParams = pyArrayToRatArray1d(problem.fitParams); + problem_struct.otherParams = pyArrayToRatArray1d(problem.otherParams); + problem_struct.fitLimits = pyArrayToRatArray2d(problem.fitLimits); + problem_struct.otherLimits = pyArrayToRatArray2d(problem.otherLimits); return problem_struct; } -RAT::struct1_T create_struct1_T(const Limits& limits) +RAT::struct1_T createStruct1T(const Limits& limits) { RAT::struct1_T limits_struct; - limits_struct.param = py_array_to_rat_2d_array(limits.param); - limits_struct.backgroundParam = py_array_to_rat_2d_array(limits.backgroundParam); - limits_struct.qzshift = py_array_to_rat_2d_array(limits.qzshift); - limits_struct.scalefactor = py_array_to_rat_2d_array(limits.scalefactor); - limits_struct.bulkIn = py_array_to_rat_2d_array(limits.bulkIn); - limits_struct.bulkOut = py_array_to_rat_2d_array(limits.bulkOut); - limits_struct.resolutionParam = py_array_to_rat_2d_array(limits.resolutionParam); - limits_struct.domainRatio = py_array_to_rat_2d_array(limits.domainRatio); + limits_struct.param = pyArrayToRatArray2d(limits.param); + limits_struct.backgroundParam = pyArrayToRatArray2d(limits.backgroundParam); + limits_struct.qzshift = pyArrayToRatArray2d(limits.qzshift); + limits_struct.scalefactor = pyArrayToRatArray2d(limits.scalefactor); + limits_struct.bulkIn = pyArrayToRatArray2d(limits.bulkIn); + limits_struct.bulkOut = pyArrayToRatArray2d(limits.bulkOut); + limits_struct.resolutionParam = pyArrayToRatArray2d(limits.resolutionParam); + limits_struct.domainRatio = pyArrayToRatArray2d(limits.domainRatio); return limits_struct; } @@ -675,19 +675,19 @@ RAT::struct1_T create_struct1_T(const Limits& limits) RAT::struct3_T create_struct3_T(const Checks& checks) { RAT::struct3_T checks_struct; - checks_struct.fitParam = py_array_to_rat_1d_array(checks.fitParam); - checks_struct.fitBackgroundParam = py_array_to_rat_1d_array(checks.fitBackgroundParam); - checks_struct.fitQzshift = py_array_to_rat_1d_array(checks.fitQzshift); - checks_struct.fitScalefactor = py_array_to_rat_1d_array(checks.fitScalefactor); - checks_struct.fitBulkIn = py_array_to_rat_1d_array(checks.fitBulkIn); - checks_struct.fitBulkOut = py_array_to_rat_1d_array(checks.fitBulkOut); - checks_struct.fitResolutionParam = py_array_to_rat_1d_array(checks.fitResolutionParam); - checks_struct.fitDomainRatio = py_array_to_rat_1d_array(checks.fitDomainRatio); + checks_struct.fitParam = pyArrayToRatArray1d(checks.fitParam); + checks_struct.fitBackgroundParam = pyArrayToRatArray1d(checks.fitBackgroundParam); + checks_struct.fitQzshift = pyArrayToRatArray1d(checks.fitQzshift); + checks_struct.fitScalefactor = pyArrayToRatArray1d(checks.fitScalefactor); + checks_struct.fitBulkIn = pyArrayToRatArray1d(checks.fitBulkIn); + checks_struct.fitBulkOut = pyArrayToRatArray1d(checks.fitBulkOut); + checks_struct.fitResolutionParam = pyArrayToRatArray1d(checks.fitResolutionParam); + checks_struct.fitDomainRatio = pyArrayToRatArray1d(checks.fitDomainRatio); return checks_struct; } -RAT::struct4_T create_struct4_T(const Priors& priors) +RAT::struct4_T createStruct4T(const Priors& priors) { RAT::struct4_T priors_struct; priors_struct.param = py_array_to_unboundedx1_cell_0(priors.param); @@ -699,7 +699,7 @@ RAT::struct4_T create_struct4_T(const Priors& priors) priors_struct.bulkOut = py_array_to_unboundedx1_cell_0(priors.bulkOut); priors_struct.domainRatio = py_array_to_unboundedx1_cell_0(priors.domainRatio); priors_struct.priorNames = py_array_to_unboundedx1_cell_1(priors.priorNames); - priors_struct.priorValues = py_array_to_rat_2d_array(priors.priorValues); + priors_struct.priorValues = pyArrayToRatArray2d(priors.priorValues); return priors_struct; } @@ -728,7 +728,7 @@ coder::array py_array_to_rat_cell_wrap_3(py::list values) for (py::handle array: values) { py::array_t casted_array = py::cast(array); - result[idx].f1 = py_array_to_rat_2d_array(casted_array); + result[idx].f1 = pyArrayToRatArray2d(casted_array); idx++; } @@ -743,7 +743,7 @@ coder::array py_array_to_rat_cell_wrap_4(py::list values) for (py::handle array: values) { py::array_t casted_array = py::cast(array); - result[idx].f1 = py_array_to_rat_1d_array(casted_array); + result[idx].f1 = pyArrayToRatArray1d(casted_array); idx++; } @@ -758,7 +758,7 @@ coder::array py_array_to_rat_cell_wrap_5(py::list values) for (py::handle array: values) { py::array_t casted_array = py::cast(array); - result[idx].f1 = py_array_to_rat_bounded_array(casted_array); + result[idx].f1 = pyArrayToRatBoundedArray(casted_array); idx++; } @@ -773,7 +773,7 @@ coder::array py_array_to_rat_cell_wrap_6(py::list values) for (py::handle array: values) { std::string name = py::cast(array); - string_to_rat_array(name, result[idx].f1.data, result[idx].f1.size); + stringToRatArray(name, result[idx].f1.data, result[idx].f1.size); idx++; } @@ -789,14 +789,14 @@ coder::array py_function_array_to_rat_cell_wrap_6(py::list { auto func = py::cast(array); std::string func_ptr = convertPtr2String(new Library(func)); - string_to_rat_array(func_ptr, result[idx].f1.data, result[idx].f1.size); + stringToRatArray(func_ptr, result[idx].f1.data, result[idx].f1.size); idx++; } return result; } -RAT::cell_7 create_cell_7(const Cells& cells) +RAT::cell_7 createCell7(const Cells& cells) { RAT::cell_7 cells_struct; cells_struct.f1 = py_array_to_rat_cell_wrap_2(cells.f1); @@ -823,7 +823,7 @@ RAT::cell_7 create_cell_7(const Cells& cells) return cells_struct; } -RAT::struct2_T create_struct2_T(const Control& control) +RAT::struct2_T createStruct2T(const Control& control) { RAT::struct2_T control_struct; control_struct.tolFun = control.tolFun; @@ -846,20 +846,20 @@ RAT::struct2_T create_struct2_T(const Control& control) control_struct.nChains = control.nChains; control_struct.jumpProbability = control.jumpProbability; control_struct.pUnitGamma = control.pUnitGamma; - string_to_rat_array(control.parallel, control_struct.parallel.data, control_struct.parallel.size); - string_to_rat_array(control.procedure, control_struct.procedure.data, control_struct.procedure.size); - string_to_rat_array(control.display, control_struct.display.data, control_struct.display.size); + stringToRatArray(control.parallel, control_struct.parallel.data, control_struct.parallel.size); + stringToRatArray(control.procedure, control_struct.procedure.data, control_struct.procedure.size); + stringToRatArray(control.display, control_struct.display.data, control_struct.display.size); control_struct.tolX = control.tolX; control_struct.resamPars[0] = control.resamPars.at(0); control_struct.resamPars[1] = control.resamPars.at(1); - string_to_rat_array(control.boundHandling, control_struct.boundHandling.data, control_struct.boundHandling.size); + stringToRatArray(control.boundHandling, control_struct.boundHandling.data, control_struct.boundHandling.size); control_struct.adaptPCR = control.adaptPCR; control_struct.checks = create_struct3_T(control.checks); return control_struct; } -py::array_t rat_array_1d_to_py_array(coder::array array) +py::array_t pyArrayFromRatArray1d(coder::array array) { auto size = (array.size(0) > 1) ? array.size(0) : array.size(1); auto result_array = py::array_t(size); @@ -868,7 +868,7 @@ py::array_t rat_array_1d_to_py_array(coder::array array) return result_array; } -py::array_t rat_array_2d_to_py_array(coder::array array) +py::array_t pyArrayFromRatArray2d(coder::array array) { auto result_array = py::array_t({array.size(0), array.size(1)}); std::memcpy(result_array.request().ptr, array.data(), result_array.nbytes()); @@ -876,7 +876,7 @@ py::array_t rat_array_2d_to_py_array(coder::array array) return result_array; } -py::list result_to_list(const RAT::cell_wrap_9 results[]) +py::list resultArrayToList(const RAT::cell_wrap_9 results[]) { py::list outer_list_1; for (int32_T idx0{0}; idx0 < results[0].f1.size(0); idx0++) { @@ -960,7 +960,7 @@ py::list result_to_list(const RAT::cell_wrap_9 results[]) return output_result; } -ContrastParams struct5_T_to_ContrastParams(const RAT::struct5_T problem) +ContrastParams contrastParamsFromStruct5T(const RAT::struct5_T problem) { // Copy problem to output ContrastParams output_problem; @@ -1008,7 +1008,7 @@ ContrastParams struct5_T_to_ContrastParams(const RAT::struct5_T problem) return output_problem; } -ProblemDefinition struct0_T_to_ProblemDefinition(const RAT::struct0_T problem) +ProblemDefinition problemDefinitionFromStruct0T(const RAT::struct0_T problem) { ProblemDefinition problem_def; @@ -1025,48 +1025,48 @@ ProblemDefinition struct0_T_to_ProblemDefinition(const RAT::struct0_T problem) problem_def.TF.resize(problem.TF.size[1]); memcpy(&problem_def.TF[0], problem.TF.data, problem.TF.size[1]); - problem_def.contrastBackgrounds = rat_array_1d_to_py_array(problem.contrastBackgrounds); - problem_def.contrastBackgroundsType = rat_array_1d_to_py_array(problem.contrastBackgroundsType); - problem_def.resample = rat_array_1d_to_py_array(problem.resample); - problem_def.dataPresent = rat_array_1d_to_py_array(problem.dataPresent); - problem_def.oilChiDataPresent = rat_array_1d_to_py_array(problem.oilChiDataPresent); - problem_def.contrastQzshifts = rat_array_1d_to_py_array(problem.contrastQzshifts); - problem_def.contrastScalefactors = rat_array_1d_to_py_array(problem.contrastScalefactors); - problem_def.contrastBulkIns = rat_array_1d_to_py_array(problem.contrastBulkIns); - problem_def.contrastBulkOuts = rat_array_1d_to_py_array(problem.contrastBulkOuts); - problem_def.contrastResolutions = rat_array_1d_to_py_array(problem.contrastResolutions); - problem_def.backgroundParams = rat_array_1d_to_py_array(problem.backgroundParams); - problem_def.qzshifts = rat_array_1d_to_py_array(problem.qzshifts); - problem_def.scalefactors = rat_array_1d_to_py_array(problem.scalefactors); - problem_def.bulkIn = rat_array_1d_to_py_array(problem.bulkIn); - problem_def.bulkOut = rat_array_1d_to_py_array(problem.bulkOut); - problem_def.resolutionParams = rat_array_1d_to_py_array(problem.resolutionParams); - problem_def.params = rat_array_1d_to_py_array(problem.params); - - problem_def.contrastCustomFiles = rat_array_1d_to_py_array(problem.contrastCustomFiles); - problem_def.contrastDomainRatios = rat_array_1d_to_py_array(problem.contrastDomainRatios); - problem_def.domainRatio = rat_array_1d_to_py_array(problem.domainRatio); - - problem_def.fitParams = rat_array_1d_to_py_array(problem.fitParams); - problem_def.otherParams = rat_array_1d_to_py_array(problem.otherParams); - problem_def.fitLimits = rat_array_2d_to_py_array(problem.fitLimits); - problem_def.otherLimits = rat_array_2d_to_py_array(problem.otherLimits); + problem_def.contrastBackgrounds = pyArrayFromRatArray1d(problem.contrastBackgrounds); + problem_def.contrastBackgroundsType = pyArrayFromRatArray1d(problem.contrastBackgroundsType); + problem_def.resample = pyArrayFromRatArray1d(problem.resample); + problem_def.dataPresent = pyArrayFromRatArray1d(problem.dataPresent); + problem_def.oilChiDataPresent = pyArrayFromRatArray1d(problem.oilChiDataPresent); + problem_def.contrastQzshifts = pyArrayFromRatArray1d(problem.contrastQzshifts); + problem_def.contrastScalefactors = pyArrayFromRatArray1d(problem.contrastScalefactors); + problem_def.contrastBulkIns = pyArrayFromRatArray1d(problem.contrastBulkIns); + problem_def.contrastBulkOuts = pyArrayFromRatArray1d(problem.contrastBulkOuts); + problem_def.contrastResolutions = pyArrayFromRatArray1d(problem.contrastResolutions); + problem_def.backgroundParams = pyArrayFromRatArray1d(problem.backgroundParams); + problem_def.qzshifts = pyArrayFromRatArray1d(problem.qzshifts); + problem_def.scalefactors = pyArrayFromRatArray1d(problem.scalefactors); + problem_def.bulkIn = pyArrayFromRatArray1d(problem.bulkIn); + problem_def.bulkOut = pyArrayFromRatArray1d(problem.bulkOut); + problem_def.resolutionParams = pyArrayFromRatArray1d(problem.resolutionParams); + problem_def.params = pyArrayFromRatArray1d(problem.params); + + problem_def.contrastCustomFiles = pyArrayFromRatArray1d(problem.contrastCustomFiles); + problem_def.contrastDomainRatios = pyArrayFromRatArray1d(problem.contrastDomainRatios); + problem_def.domainRatio = pyArrayFromRatArray1d(problem.domainRatio); + + problem_def.fitParams = pyArrayFromRatArray1d(problem.fitParams); + problem_def.otherParams = pyArrayFromRatArray1d(problem.otherParams); + problem_def.fitLimits = pyArrayFromRatArray2d(problem.fitLimits); + problem_def.otherLimits = pyArrayFromRatArray2d(problem.otherLimits); return problem_def; } -py::list rat_cell_wrap_8_to_py_list(const coder::array& values) +py::list pyList1DFromRatCellWrap8(const coder::array& values) { py::list result; for (int32_T idx0{0}; idx0 < values.size(0); idx0++) { - result.append(rat_array_2d_to_py_array(values[idx0].f1)); + result.append(pyArrayFromRatArray2d(values[idx0].f1)); } return result; } -py::list rat_cell_wrap_8_2d_to_py_list(const coder::array& values) +py::list pyList2dFromRatCellWrap8(const coder::array& values) { py::list result; int32_T idx {0}; @@ -1074,7 +1074,7 @@ py::list rat_cell_wrap_8_2d_to_py_list(const coder::array& py::list inner; for (int32_T idx1{0}; idx1 < values.size(1); idx1++) { idx = idx0 + values.size(0) * idx1; - inner.append(rat_array_2d_to_py_array(values[idx].f1)); + inner.append(pyArrayFromRatArray2d(values[idx].f1)); } result.append(inner); } @@ -1083,7 +1083,7 @@ py::list rat_cell_wrap_8_2d_to_py_list(const coder::array& } template -py::array_t bounded_array_1d_to_py_array(const T& array) +py::array_t pyArray1dFromBoundedArray(const T& array) { auto result_array = py::array_t({array.size[0]}); std::memcpy(result_array.request().ptr, array.data, result_array.nbytes()); @@ -1092,7 +1092,7 @@ py::array_t bounded_array_1d_to_py_array(const T& array) } template -py::array_t bounded_array_2d_to_py_array(const T& array) +py::array_t pyArray2dFromBoundedArray(const T& array) { auto result_array = py::array_t({array.size[0], array.size[1]}); std::memcpy(result_array.request().ptr, array.data, result_array.nbytes()); @@ -1100,7 +1100,7 @@ py::array_t bounded_array_2d_to_py_array(const T& array) return result_array; } -py::array_t rat_array_3d_to_py_array(coder::array array) +py::array_t pyArrayFromRatArray3d(coder::array array) { auto result_array = py::array_t({array.size(0), array.size(1), array.size(2)}); std::memcpy(result_array.request().ptr, array.data(), result_array.nbytes()); @@ -1108,42 +1108,42 @@ py::array_t rat_array_3d_to_py_array(coder::array array) return result_array; } -BayesResults struct7_T_to_BayesResults(const RAT::struct7_T results) +BayesResults bayesResultsFromStruct7T(const RAT::struct7_T results) { BayesResults bayesResults; - bayesResults.bestPars = rat_array_2d_to_py_array(results.bestPars); - bayesResults.chain = rat_array_2d_to_py_array(results.chain); + bayesResults.bestPars = pyArrayFromRatArray2d(results.bestPars); + bayesResults.chain = pyArrayFromRatArray2d(results.chain); - bayesResults.bestFitsMean.ref = rat_cell_wrap_8_to_py_list(results.bestFitsMean.ref); - bayesResults.bestFitsMean.sld = rat_cell_wrap_8_2d_to_py_list(results.bestFitsMean.sld); + bayesResults.bestFitsMean.ref = pyList1DFromRatCellWrap8(results.bestFitsMean.ref); + bayesResults.bestFitsMean.sld = pyList2dFromRatCellWrap8(results.bestFitsMean.sld); bayesResults.bestFitsMean.chi = results.bestFitsMean.chi; - bayesResults.bestFitsMean.data = rat_cell_wrap_8_to_py_list(results.bestFitsMean.data); + bayesResults.bestFitsMean.data = pyList1DFromRatCellWrap8(results.bestFitsMean.data); - bayesResults.predlims.refPredInts = rat_cell_wrap_8_to_py_list(results.predlims.refPredInts); - bayesResults.predlims.sldPredInts = rat_cell_wrap_8_2d_to_py_list(results.predlims.sldPredInts); - bayesResults.predlims.refXdata = rat_cell_wrap_8_to_py_list(results.predlims.refXdata); - bayesResults.predlims.sldXdata = rat_cell_wrap_8_2d_to_py_list(results.predlims.sldXdata); - bayesResults.predlims.sampleChi = bounded_array_1d_to_py_array>(results.predlims.sampleChi); + bayesResults.predlims.refPredInts = pyList1DFromRatCellWrap8(results.predlims.refPredInts); + bayesResults.predlims.sldPredInts = pyList2dFromRatCellWrap8(results.predlims.sldPredInts); + bayesResults.predlims.refXdata = pyList1DFromRatCellWrap8(results.predlims.refXdata); + bayesResults.predlims.sldXdata = pyList2dFromRatCellWrap8(results.predlims.sldXdata); + bayesResults.predlims.sampleChi = pyArray1dFromBoundedArray>(results.predlims.sampleChi); - bayesResults.parConfInts.par95 = rat_array_2d_to_py_array(results.parConfInts.par95); - bayesResults.parConfInts.par65 = rat_array_2d_to_py_array(results.parConfInts.par65); - bayesResults.parConfInts.mean = rat_array_2d_to_py_array(results.parConfInts.mean); + bayesResults.parConfInts.par95 = pyArrayFromRatArray2d(results.parConfInts.par95); + bayesResults.parConfInts.par65 = pyArrayFromRatArray2d(results.parConfInts.par65); + bayesResults.parConfInts.mean = pyArrayFromRatArray2d(results.parConfInts.mean); - bayesResults.bayesRes.allChains = rat_array_3d_to_py_array(results.bayesRes.allChains); + bayesResults.bayesRes.allChains = pyArrayFromRatArray3d(results.bayesRes.allChains); bayesResults.bayesRes.nestOutput.logZ = results.bayesRes.nestOutput.LogZ; - bayesResults.bayesRes.nestOutput.nestSamples = rat_array_2d_to_py_array(results.bayesRes.nestOutput.nestSamples); - bayesResults.bayesRes.nestOutput.postSamples = rat_array_2d_to_py_array(results.bayesRes.nestOutput.postSamples); + bayesResults.bayesRes.nestOutput.nestSamples = pyArrayFromRatArray2d(results.bayesRes.nestOutput.nestSamples); + bayesResults.bayesRes.nestOutput.postSamples = pyArrayFromRatArray2d(results.bayesRes.nestOutput.postSamples); bayesResults.bayesRes.dreamOutput.runtime = results.bayesRes.dreamOutput.RunTime; bayesResults.bayesRes.dreamOutput.iteration = results.bayesRes.dreamOutput.iteration; bayesResults.bayesRes.dreamOutput.iloc = results.bayesRes.dreamOutput.iloc; bayesResults.bayesRes.dreamOutput.fx = results.bayesRes.dreamOutput.fx; - bayesResults.bayesRes.dreamOutput.R_stat = rat_array_2d_to_py_array(results.bayesRes.dreamOutput.R_stat); - bayesResults.bayesRes.dreamOutput.CR = rat_array_2d_to_py_array(results.bayesRes.dreamOutput.CR); - bayesResults.bayesRes.dreamOutput.AR = bounded_array_2d_to_py_array>(results.bayesRes.dreamOutput.AR); - bayesResults.bayesRes.dreamOutput.outlier = bounded_array_2d_to_py_array>(results.bayesRes.dreamOutput.outlier); + bayesResults.bayesRes.dreamOutput.R_stat = pyArrayFromRatArray2d(results.bayesRes.dreamOutput.R_stat); + bayesResults.bayesRes.dreamOutput.CR = pyArrayFromRatArray2d(results.bayesRes.dreamOutput.CR); + bayesResults.bayesRes.dreamOutput.AR = pyArray2dFromBoundedArray>(results.bayesRes.dreamOutput.AR); + bayesResults.bayesRes.dreamOutput.outlier = pyArray2dFromBoundedArray>(results.bayesRes.dreamOutput.outlier); bayesResults.bayesRes.dreamOutput.Meas_info.Y = results.bayesRes.dreamOutput.Meas_info.Y; bayesResults.bayesRes.dreamOutput.Meas_info.N = results.bayesRes.dreamOutput.Meas_info.N; @@ -1168,7 +1168,7 @@ BayesResults struct7_T_to_BayesResults(const RAT::struct7_T results) bayesResults.bayesRes.dreamOutput.DREAMPar.modout = results.bayesRes.dreamOutput.DREAMPar.modout; bayesResults.bayesRes.dreamOutput.DREAMPar.restart = results.bayesRes.dreamOutput.DREAMPar.restart; bayesResults.bayesRes.dreamOutput.DREAMPar.save = results.bayesRes.dreamOutput.DREAMPar.save; - bayesResults.bayesRes.dreamOutput.DREAMPar.R = rat_array_2d_to_py_array(results.bayesRes.dreamOutput.DREAMPar.R); + bayesResults.bayesRes.dreamOutput.DREAMPar.R = pyArrayFromRatArray2d(results.bayesRes.dreamOutput.DREAMPar.R); return bayesResults; } @@ -1176,11 +1176,11 @@ BayesResults struct7_T_to_BayesResults(const RAT::struct7_T results) py::tuple RATMain(const ProblemDefinition& problem_def, const Cells& cells, const Limits& limits, const Control& control, const Priors& priors) { - RAT::struct0_T problem_def_struct = create_struct0_T(problem_def); - RAT::cell_7 cells_struct = create_cell_7(cells); - RAT::struct1_T limits_struct = create_struct1_T(limits); - RAT::struct2_T control_struct = create_struct2_T(control); - RAT::struct4_T priors_struct = create_struct4_T(priors); + RAT::struct0_T problem_def_struct = createStruct0T(problem_def); + RAT::cell_7 cells_struct = createCell7(cells); + RAT::struct1_T limits_struct = createStruct1T(limits); + RAT::struct2_T control_struct = createStruct2T(control); + RAT::struct4_T priors_struct = createStruct4T(priors); RAT::cell_wrap_9 results[6]; RAT::struct5_T problem; @@ -1191,9 +1191,9 @@ py::tuple RATMain(const ProblemDefinition& problem_def, const Cells& cells, cons &priors_struct, &problem, results, &bayesResults); // Copy result to output - return py::make_tuple(struct0_T_to_ProblemDefinition(problem_def_struct), - struct5_T_to_ContrastParams(problem), - result_to_list(results), struct7_T_to_BayesResults(bayesResults)); + return py::make_tuple(problemDefinitionFromStruct0T(problem_def_struct), + contrastParamsFromStruct5T(problem), + resultArrayToList(results), bayesResultsFromStruct7T(bayesResults)); } class Module diff --git a/examples/DSPC_custom_layers_example.py b/examples/DSPC_custom_layers_example.py index a448b46d..4d4fdfa0 100644 --- a/examples/DSPC_custom_layers_example.py +++ b/examples/DSPC_custom_layers_example.py @@ -2,7 +2,7 @@ import numpy as np from customBilayer import customBilayer from rat import events, rat_core -from rat.misc import MatlabWrapper, DylibWrapper +from rat.misc import DylibWrapper # MatlabWrapper faulthandler.enable() @@ -128,13 +128,13 @@ cells.f12 = ['SLD D2O', 'SLD SMW', 'SLD H2O'] cells.f13 = ['Resolution par 1'] - dylib_wrapper = DylibWrapper('examples/customBilayer.dll', 'customBilayer') - cells.f14 = [dylib_wrapper.getHandle()] # C++ callback + # dylib_wrapper = DylibWrapper('examples/customBilayer.dll', 'customBilayer') + # cells.f14 = [dylib_wrapper.getHandle()] # C++ callback # matlab_wrapper = MatlabWrapper('examples/customBilayer.m') # cells.f14 = [matlab_wrapper.getHandle()] # Matlab callback - # cells.f14 = [customBilayer] # Python callback + cells.f14 = [customBilayer] # Python callback cells.f15 = ['constant', 'constant', 'constant'] cells.f16 = ['constant'] @@ -191,4 +191,4 @@ def fakePlot(event): # print(contrast_params.allSubRough) # print(contrast_params.resample) #print(output) - \ No newline at end of file + diff --git a/examples/domains_custom_layers_example.py b/examples/domains_custom_layers_example.py index 30da6933..f901a898 100644 --- a/examples/domains_custom_layers_example.py +++ b/examples/domains_custom_layers_example.py @@ -2,7 +2,7 @@ import numpy as np from alloyDomains import alloyDomains from rat import events, rat_core -from rat.misc import MatlabWrapper, DylibWrapper +from rat.misc import DylibWrapper # MatlabWrapper faulthandler.enable() @@ -124,13 +124,13 @@ cells.f12 = ['SLD D2O'] cells.f13 = ['Resolution par 1'] - dylib_wrapper = DylibWrapper('examples/alloyDomains.dll', 'alloyDomains') - cells.f14 = [dylib_wrapper.getHandle()] # C++ callback + # dylib_wrapper = DylibWrapper('examples/alloyDomains.dll', 'alloyDomains') + # cells.f14 = [dylib_wrapper.getHandle()] # C++ callback # matlab_wrapper = MatlabWrapper('examples/alloyDomains.m') # cells.f14 = [matlab_wrapper.getHandle()] # Matlab callback - # cells.f14 = [alloyDomains] # Python callback + cells.f14 = [alloyDomains] # Python callback cells.f15 = ['constant'] cells.f16 = ['constant'] @@ -182,4 +182,4 @@ # print(contrast_params.allSubRough) # print(contrast_params.resample) #print(output) - \ No newline at end of file + diff --git a/pyproject.toml b/pyproject.toml index 91e42ebf..515031d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,14 @@ requires = [ "setuptools>=42", "wheel", "pybind11>=2.4", - "numpy", ] +[optional-dependencies] +Matlab-2023b = ["matlabengine==23.2.1"] +Matlab-2023a = ["matlabengine==9.14.3"] +Matlab-2022b = ["matlabengine==9.13.9"] +Matlab-2022a = ["matlabengine==9.12.19"] +Matlab-2021b = ["matlabengine==9.11.21"] +Matlab-2021a = ["matlabengine==9.10.3"] + build-backend = "setuptools.build_meta" diff --git a/rat/misc.py b/rat/misc.py index 6e10ab3a..e280ec3e 100644 --- a/rat/misc.py +++ b/rat/misc.py @@ -1,33 +1,35 @@ import pathlib import numpy as np -import matlab.engine from rat import rat_core +try: + import matlab.engine + class MatlabWrapper: + def __init__(self, filename): + self.engine = matlab.engine.start_matlab() + path = pathlib.Path(filename) + self.engine.cd(str(path.parent), nargout=0) + self.function_name = path.stem -class MatlabWrapper: - def __init__(self, filename): - self.engine = matlab.engine.start_matlab() - path = pathlib.Path(filename) - self.engine.cd(str(path.parent), nargout=0) - self.function_name = path.stem + def __del__(self): + self.engine.quit() - def __del__(self): - self.engine.quit() - - def getHandle(self): - def handle(params, bulk_in, bulk_out, contrast, domain=-1): - if domain == -1: - output, sub_rough = getattr(self.engine, self.function_name)(np.array(params, 'float'), - np.array(bulk_in, 'float'), - np.array(bulk_out, 'float'), - float(contrast + 1), nargout=2) - else: - output, sub_rough = getattr(self.engine, self.function_name)(np.array(params, 'float'), - np.array(bulk_in, 'float'), - np.array(bulk_out, 'float'), - float(contrast + 1), float(domain + 1), nargout=2) - return output, sub_rough - return handle + def getHandle(self): + def handle(params, bulk_in, bulk_out, contrast, domain=-1): + if domain == -1: + output, sub_rough = getattr(self.engine, self.function_name)(np.array(params, 'float'), + np.array(bulk_in, 'float'), + np.array(bulk_out, 'float'), + float(contrast + 1), nargout=2) + else: + output, sub_rough = getattr(self.engine, self.function_name)(np.array(params, 'float'), + np.array(bulk_in, 'float'), + np.array(bulk_out, 'float'), + float(contrast + 1), float(domain + 1), nargout=2) + return output, sub_rough + return handle +except ImportError: + pass # maybe should log matlab engine is not installed class DylibWrapper: diff --git a/setup.py b/setup.py index 3a8326c5..bbb921ae 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,12 @@ from glob import glob +from pathlib import Path import platform +import sys +import pybind11 from setuptools import setup, Extension from setuptools.command.build_ext import build_ext from setuptools.command.build_clib import build_clib -import sys -import pybind11 + __version__ = '0.0.0' @@ -31,7 +33,7 @@ # check whether compiler supports a flag def has_flag(compiler, flagname): import tempfile - from distutils.errors import CompileError + from setuptools.errors import CompileError with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f: f.write('int main (int argc, char **argv) { return 0; }') try: @@ -54,7 +56,7 @@ class BuildExt(build_ext): """A custom build extension for adding compiler-specific options.""" c_opts = { 'msvc': ['/EHsc'], - 'unix': ['-fopenmp'], + 'unix': ['-fopenmp', '-std=c++11'], } l_opts = { 'msvc': [], @@ -62,9 +64,9 @@ class BuildExt(build_ext): } if sys.platform == 'darwin': - darwin_opts = ['-stdlib=libc++', '-mmacosx-version-min=10.7'] - c_opts['unix'] += darwin_opts - l_opts['unix'] += darwin_opts + darwin_opts = ['-stdlib=libc++', '-mmacosx-version-min=10.9'] + c_opts['unix'] = [*darwin_opts, '-fopenmp'] + l_opts['unix'] = [*darwin_opts, '-lomp'] def build_extensions(self): ct = self.compiler.compiler_type @@ -75,7 +77,6 @@ def build_extensions(self): self.compiler.compiler_so.remove('-Wstrict-prototypes') opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version()) - opts.append('-std=c++11') if has_flag(self.compiler, '-fvisibility=hidden'): opts.append('-fvisibility=hidden') elif ct == 'msvc': @@ -84,13 +85,27 @@ def build_extensions(self): ext.extra_compile_args = opts ext.extra_link_args = link_opts build_ext.build_extensions(self) + + def run(self): + super().run() + build_py = self.get_finalized_command('build_py') + package_dir = f'{build_py.build_lib}/rat/' + for p in Path(package_dir).glob("**/*"): + if p.suffix in {".exp", ".a", ".lib"}: + p.unlink() + + if self.inplace: + obj_name = get_shared_object_name(libevent[0]) + src = f'{build_py.build_lib}/rat/{obj_name}' + dest = f'{build_py.get_package_dir("rat")}/{obj_name}' + build_py.copy_file(src, dest) class BuildClib(build_clib): def initialize_options(self): super().initialize_options() build_py = self.get_finalized_command('build_py') - self.build_clib = build_py.get_package_dir("rat") + self.build_clib = f'{build_py.build_lib}/rat' def build_libraries(self, libraries): # bug in distutils: flag not valid for c++ @@ -101,7 +116,7 @@ def build_libraries(self, libraries): compiler_type = self.compiler.compiler_type if compiler_type == 'msvc': - compile_args = ['/std:c++11', '/EHsc', '/LD'] + compile_args = ['/EHsc', '/LD'] else: compile_args = ['-std=c++11', '-fPIC'] @@ -139,12 +154,19 @@ def build_libraries(self, libraries): description='Python extension for the Reflectivity Analysis Toolbox (RAT)', long_description='', packages=['rat'], - package_data={'rat': [get_shared_object_name(libevent[0])]}, + include_package_data=True, + package_data={'': [get_shared_object_name(libevent[0])]}, libraries=[libevent], ext_modules=ext_modules, - install_requires=['pybind11>=2.4', 'numpy'], + install_requires=['numpy'], python_requires='>=3.9', # setup_requires=['pybind11>=2.4'], - cmdclass={'build_ext': BuildExt, 'build_clib': BuildClib}, + cmdclass={'build_clib': BuildClib, 'build_ext': BuildExt}, + extras_require={"Matlab_2023b": ["matlabengine==23.2.1"], + "Matlab_2023a": ["matlabengine==9.14.3"], + "Matlab-2022b": ["matlabengine==9.13.9"], + "Matlab_2022a": ["matlabengine==9.12.19"], + "Matlab_2021b": ["matlabengine==9.11.21"], + "Matlab_2021a": ["matlabengine==9.10.3"]}, zip_safe=False, ) From db451b509179cac35cd42600051baa01fd06c096 Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Tue, 20 Feb 2024 12:41:24 +0000 Subject: [PATCH 7/8] Renames variables --- cpp/rat.cpp | 128 ++++++++++++------------- examples/DSPC_custom_layers_example.py | 2 +- rat/events.py | 9 +- 3 files changed, 70 insertions(+), 69 deletions(-) diff --git a/cpp/rat.cpp b/cpp/rat.cpp index d6be51f6..86372ad5 100644 --- a/cpp/rat.cpp +++ b/cpp/rat.cpp @@ -37,38 +37,38 @@ class Library: public CallbackInterface void setOutput(py::tuple& result, std::vector& output, double *outputSize) { - int n_rows = 0, idx = 0; - for (py::handle row_handle : result[0]) + int nRows = 0, idx = 0; + for (py::handle rowHandle : result[0]) { - py::list rows = py::cast(row_handle); + py::list rows = py::cast(rowHandle); for (py::handle value : rows) { output.push_back(py::cast(value)); idx++; } - n_rows++; + nRows++; } - outputSize[0] = n_rows; - outputSize[1] = (n_rows == 0) ? 0 : idx / n_rows; + outputSize[0] = nRows; + outputSize[1] = (nRows == 0) ? 0 : idx / nRows; } // Domain overload - void invoke(std::vector& params, std::vector& bulk_in, std::vector& bulk_out, + void invoke(std::vector& params, std::vector& bulkIn, std::vector& bulkOut, int contrast, int domainNumber, std::vector& output, double *outputSize, double *roughness) { auto f = py::cast>(this->function); - auto result = f(py::cast(params), py::cast(bulk_in), py::cast(bulk_out), contrast, domainNumber); + auto result = f(py::cast(params), py::cast(bulkIn), py::cast(bulkOut), contrast, domainNumber); *roughness = py::cast(result[1]); setOutput(result, output, outputSize); }; // Non-Domain overload - void invoke(std::vector& params, std::vector& bulk_in, std::vector& bulk_out, + void invoke(std::vector& params, std::vector& bulkIn, std::vector& bulkOut, int contrast, std::vector& output, double *outputSize, double *roughness) { auto f = py::cast>(this->function); - auto result = f(py::cast(params), py::cast(bulk_in), py::cast(bulk_out), contrast); + auto result = f(py::cast(params), py::cast(bulkIn), py::cast(bulkOut), contrast); *roughness = py::cast(result[1]); setOutput(result, output, outputSize); }; @@ -93,7 +93,7 @@ class DylibEngine ~DylibEngine(){}; - py::tuple invoke(std::vector& params, std::vector& bulk_in, std::vector& bulk_out, int contrast, int domain=DEFAULT_DOMAIN) + py::tuple invoke(std::vector& params, std::vector& bulkIn, std::vector& bulkOut, int contrast, int domain=DEFAULT_DOMAIN) { try{ std::vector tempOutput; @@ -103,12 +103,12 @@ class DylibEngine if (domain != -1) { auto func = library->get_function&, std::vector&, std::vector&, int, int, std::vector&, double*, double*)>(functionName); - func(params, bulk_in, bulk_out, contrast, domain, tempOutput, outputSize, &roughness); + func(params, bulkIn, bulkOut, contrast, domain, tempOutput, outputSize, &roughness); } else { auto func = library->get_function&, std::vector&, std::vector&, int, std::vector&, double*, double*)>(functionName); - func(params, bulk_in, bulk_out, contrast, tempOutput, outputSize, &roughness); + func(params, bulkIn, bulkOut, contrast, tempOutput, outputSize, &roughness); } py::list output; @@ -142,13 +142,13 @@ struct PlotEventData std::string modelType; }; -class EventStuff +class EventBridge { public: std::unique_ptr library; py::function callback; - EventStuff(py::function callback) + EventBridge(py::function callback) { std::string filename = "eventManager" + std::string(dylib::extension); this->library = std::unique_ptr(new dylib(std::getenv("RAT_PATH"), filename.c_str())); @@ -233,7 +233,7 @@ class EventStuff void registerEvent(EventTypes eventType) { - std::function caller = std::bind(&EventStuff::eventCallback, this, std::placeholders::_1); + std::function caller = std::bind(&EventBridge::eventCallback, this, std::placeholders::_1); auto addListener = library->get_function)>("addListener"); addListener(eventType, caller); }; @@ -577,7 +577,7 @@ coder::array pyArrayToRatArray2d(py::array_t value) return result; } -coder::array py_array_to_unboundedx1_cell_0(py::list values) +coder::array pyListToUnboundedCell0(py::list values) { coder::array result; result.set_size(values.size()); @@ -597,7 +597,7 @@ coder::array py_array_to_unboundedx1_cell_0(py::list values) return result; } -coder::array py_array_to_unboundedx1_cell_1(py::list values) +coder::array pyListToUnboundedCell1(py::list values) { coder::array result; result.set_size(values.size()); @@ -613,7 +613,7 @@ coder::array py_array_to_unboundedx1_cell_1(py::list value return result; } -RAT::struct0_T createStruct0_T(const ProblemDefinition& problem) +RAT::struct0_T createStruct0(const ProblemDefinition& problem) { RAT::struct0_T problem_struct; @@ -657,7 +657,7 @@ RAT::struct0_T createStruct0_T(const ProblemDefinition& problem) return problem_struct; } -RAT::struct1_T createStruct1T(const Limits& limits) +RAT::struct1_T createStruct1(const Limits& limits) { RAT::struct1_T limits_struct; limits_struct.param = pyArrayToRatArray2d(limits.param); @@ -672,7 +672,7 @@ RAT::struct1_T createStruct1T(const Limits& limits) return limits_struct; } -RAT::struct3_T create_struct3_T(const Checks& checks) +RAT::struct3_T createStruct3(const Checks& checks) { RAT::struct3_T checks_struct; checks_struct.fitParam = pyArrayToRatArray1d(checks.fitParam); @@ -687,24 +687,24 @@ RAT::struct3_T create_struct3_T(const Checks& checks) return checks_struct; } -RAT::struct4_T createStruct4T(const Priors& priors) +RAT::struct4_T createStruct4(const Priors& priors) { RAT::struct4_T priors_struct; - priors_struct.param = py_array_to_unboundedx1_cell_0(priors.param); - priors_struct.backgroundParam = py_array_to_unboundedx1_cell_0(priors.backgroundParam); - priors_struct.resolutionParam = py_array_to_unboundedx1_cell_0(priors.resolutionParam); - priors_struct.qzshift = py_array_to_unboundedx1_cell_0(priors.qzshift); - priors_struct.scalefactor = py_array_to_unboundedx1_cell_0(priors.scalefactor); - priors_struct.bulkIn = py_array_to_unboundedx1_cell_0(priors.bulkIn); - priors_struct.bulkOut = py_array_to_unboundedx1_cell_0(priors.bulkOut); - priors_struct.domainRatio = py_array_to_unboundedx1_cell_0(priors.domainRatio); - priors_struct.priorNames = py_array_to_unboundedx1_cell_1(priors.priorNames); + priors_struct.param = pyListToUnboundedCell0(priors.param); + priors_struct.backgroundParam = pyListToUnboundedCell0(priors.backgroundParam); + priors_struct.resolutionParam = pyListToUnboundedCell0(priors.resolutionParam); + priors_struct.qzshift = pyListToUnboundedCell0(priors.qzshift); + priors_struct.scalefactor = pyListToUnboundedCell0(priors.scalefactor); + priors_struct.bulkIn = pyListToUnboundedCell0(priors.bulkIn); + priors_struct.bulkOut = pyListToUnboundedCell0(priors.bulkOut); + priors_struct.domainRatio = pyListToUnboundedCell0(priors.domainRatio); + priors_struct.priorNames = pyListToUnboundedCell1(priors.priorNames); priors_struct.priorValues = pyArrayToRatArray2d(priors.priorValues); return priors_struct; } -coder::array py_array_to_rat_cell_wrap_2(py::list values) +coder::array pyListToRatCellWrap2(py::list values) { coder::array result; result.set_size(1, values.size()); @@ -720,7 +720,7 @@ coder::array py_array_to_rat_cell_wrap_2(py::list values) return result; } -coder::array py_array_to_rat_cell_wrap_3(py::list values) +coder::array pyListToRatCellWrap3(py::list values) { coder::array result; result.set_size(1, values.size()); @@ -735,7 +735,7 @@ coder::array py_array_to_rat_cell_wrap_3(py::list values) return result; } -coder::array py_array_to_rat_cell_wrap_4(py::list values) +coder::array pyListToRatCellWrap4(py::list values) { coder::array result; result.set_size(1, values.size()); @@ -750,7 +750,7 @@ coder::array py_array_to_rat_cell_wrap_4(py::list values) return result; } -coder::array py_array_to_rat_cell_wrap_5(py::list values) +coder::array pyListToRatCellWrap5(py::list values) { coder::array result; result.set_size(values.size()); @@ -765,7 +765,7 @@ coder::array py_array_to_rat_cell_wrap_5(py::list values) return result; } -coder::array py_array_to_rat_cell_wrap_6(py::list values) +coder::array pyListToRatCellWrap6(py::list values) { coder::array result; result.set_size(1, values.size()); @@ -799,26 +799,26 @@ coder::array py_function_array_to_rat_cell_wrap_6(py::list RAT::cell_7 createCell7(const Cells& cells) { RAT::cell_7 cells_struct; - cells_struct.f1 = py_array_to_rat_cell_wrap_2(cells.f1); - cells_struct.f2 = py_array_to_rat_cell_wrap_3(cells.f2); - cells_struct.f3 = py_array_to_rat_cell_wrap_2(cells.f3); - cells_struct.f4 = py_array_to_rat_cell_wrap_2(cells.f4); - cells_struct.f5 = py_array_to_rat_cell_wrap_4(cells.f5); - cells_struct.f6 = py_array_to_rat_cell_wrap_5(cells.f6); - cells_struct.f7 = py_array_to_rat_cell_wrap_6(cells.f7); - cells_struct.f8 = py_array_to_rat_cell_wrap_6(cells.f8); - cells_struct.f9 = py_array_to_rat_cell_wrap_6(cells.f9); - cells_struct.f10 = py_array_to_rat_cell_wrap_6(cells.f10); - cells_struct.f11 = py_array_to_rat_cell_wrap_6(cells.f11); - cells_struct.f12 = py_array_to_rat_cell_wrap_6(cells.f12); - cells_struct.f13 = py_array_to_rat_cell_wrap_6(cells.f13); + cells_struct.f1 = pyListToRatCellWrap2(cells.f1); + cells_struct.f2 = pyListToRatCellWrap3(cells.f2); + cells_struct.f3 = pyListToRatCellWrap2(cells.f3); + cells_struct.f4 = pyListToRatCellWrap2(cells.f4); + cells_struct.f5 = pyListToRatCellWrap4(cells.f5); + cells_struct.f6 = pyListToRatCellWrap5(cells.f6); + cells_struct.f7 = pyListToRatCellWrap6(cells.f7); + cells_struct.f8 = pyListToRatCellWrap6(cells.f8); + cells_struct.f9 = pyListToRatCellWrap6(cells.f9); + cells_struct.f10 = pyListToRatCellWrap6(cells.f10); + cells_struct.f11 = pyListToRatCellWrap6(cells.f11); + cells_struct.f12 = pyListToRatCellWrap6(cells.f12); + cells_struct.f13 = pyListToRatCellWrap6(cells.f13); cells_struct.f14 = py_function_array_to_rat_cell_wrap_6(cells.f14); - cells_struct.f15 = py_array_to_rat_cell_wrap_6(cells.f15); - cells_struct.f16 = py_array_to_rat_cell_wrap_6(cells.f16); - cells_struct.f17 = py_array_to_rat_cell_wrap_3(cells.f17); - cells_struct.f18 = py_array_to_rat_cell_wrap_2(cells.f18); - cells_struct.f19 = py_array_to_rat_cell_wrap_4(cells.f19); - cells_struct.f20 = py_array_to_rat_cell_wrap_6(cells.f20); + cells_struct.f15 = pyListToRatCellWrap6(cells.f15); + cells_struct.f16 = pyListToRatCellWrap6(cells.f16); + cells_struct.f17 = pyListToRatCellWrap3(cells.f17); + cells_struct.f18 = pyListToRatCellWrap2(cells.f18); + cells_struct.f19 = pyListToRatCellWrap4(cells.f19); + cells_struct.f20 = pyListToRatCellWrap6(cells.f20); return cells_struct; } @@ -854,7 +854,7 @@ RAT::struct2_T createStruct2T(const Control& control) control_struct.resamPars[1] = control.resamPars.at(1); stringToRatArray(control.boundHandling, control_struct.boundHandling.data, control_struct.boundHandling.size); control_struct.adaptPCR = control.adaptPCR; - control_struct.checks = create_struct3_T(control.checks); + control_struct.checks = createStruct3(control.checks); return control_struct; } @@ -1176,11 +1176,11 @@ BayesResults bayesResultsFromStruct7T(const RAT::struct7_T results) py::tuple RATMain(const ProblemDefinition& problem_def, const Cells& cells, const Limits& limits, const Control& control, const Priors& priors) { - RAT::struct0_T problem_def_struct = createStruct0T(problem_def); + RAT::struct0_T problem_def_struct = createStruct0(problem_def); RAT::cell_7 cells_struct = createCell7(cells); - RAT::struct1_T limits_struct = createStruct1T(limits); + RAT::struct1_T limits_struct = createStruct1(limits); RAT::struct2_T control_struct = createStruct2T(control); - RAT::struct4_T priors_struct = createStruct4T(priors); + RAT::struct4_T priors_struct = createStruct4(priors); RAT::cell_wrap_9 results[6]; RAT::struct5_T problem; @@ -1211,10 +1211,10 @@ class Module PYBIND11_MODULE(rat_core, m) { static Module module; - py::class_(m, "EventStuff") + py::class_(m, "EventBridge") .def(py::init()) - .def("register", &EventStuff::registerEvent) - .def("clear", &EventStuff::clear); + .def("register", &EventBridge::registerEvent) + .def("clear", &EventBridge::clear); py::enum_(m, "EventTypes") .value("Message", EventTypes::Message) @@ -1222,8 +1222,8 @@ PYBIND11_MODULE(rat_core, m) { py::class_(m, "DylibEngine") .def(py::init()) - .def("invoke", &DylibEngine::invoke, py::arg("params"), py::arg("bulk_in"), - py::arg("bulk_out"), py::arg("contrast"), + .def("invoke", &DylibEngine::invoke, py::arg("params"), py::arg("bulkIn"), + py::arg("bulkOut"), py::arg("contrast"), py::arg("domain") = DEFAULT_DOMAIN); py::class_(m, "Predlims") diff --git a/examples/DSPC_custom_layers_example.py b/examples/DSPC_custom_layers_example.py index 4d4fdfa0..4ba2a96c 100644 --- a/examples/DSPC_custom_layers_example.py +++ b/examples/DSPC_custom_layers_example.py @@ -175,7 +175,7 @@ def fakePlot(event): import time start = time.perf_counter() - events.register(rat_core.EventTypes.Plot, fakePlot) + events.register(events.EventTypes.Plot, fakePlot) problem, contrast_params, result, bayes_results = rat_core.RATMain(problem, cells, limits, control, priors) events.clear() print(time.perf_counter() - start, 'sec') diff --git a/rat/events.py b/rat/events.py index 7f2f4577..f599db8e 100644 --- a/rat/events.py +++ b/rat/events.py @@ -1,4 +1,5 @@ from rat import rat_core +from rat.rat_core import EventTypes def nofiy(event_type, data): @@ -8,8 +9,8 @@ def nofiy(event_type, data): def register(event_type, callback): - if not isinstance(event_type, rat_core.EventTypes): - raise ValueError("event_type must be a rat_core.EventTypes enum") + if not isinstance(event_type, EventTypes): + raise ValueError("event_type must be a events.EventTypes enum") if len(__event_callbacks[event_type]) == 0: __event_impl.register(event_type) @@ -21,5 +22,5 @@ def clear(): __event_callbacks.clear() -__event_impl = rat_core.EventStuff(nofiy) -__event_callbacks = {rat_core.EventTypes.Message: set(), rat_core.EventTypes.Plot: set()} +__event_impl = rat_core.EventBridge(nofiy) +__event_callbacks = {EventTypes.Message: set(), EventTypes.Plot: set()} From eee9c8395c706e04085e72c8b15681fa3a1e3edd Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Thu, 22 Feb 2024 09:29:43 +0000 Subject: [PATCH 8/8] Adds docstring, type hints, and unit tests --- .gitignore | 3 + MANIFEST.in | 1 - README.md | 3 + cpp/rat.cpp | 16 ++-- examples/DSPC_custom_layers_example.py | 4 +- examples/domains_custom_layers_example.py | 2 +- rat/events.py | 49 ++++++++++-- rat/misc.py | 92 ++++++++++++++++------- setup.py | 6 +- tests/__init__.py | 0 tests/test_events.py | 48 ++++++++++++ tests/test_wrappers.py | 56 ++++++++++++++ 12 files changed, 232 insertions(+), 48 deletions(-) delete mode 100644 MANIFEST.in create mode 100644 tests/__init__.py create mode 100644 tests/test_events.py create mode 100644 tests/test_wrappers.py diff --git a/.gitignore b/.gitignore index ed603d64..ef5e8370 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ __pycache__/ build/* dist/* *.whl + +# test +.coverage diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 64ad321d..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include README.md LICENSE diff --git a/README.md b/README.md index 35f2a9c8..5dc4af5b 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,6 @@ To install in local directory: To build wheel: pip install build python -m build --wheel + +matlabengine is an optional dependency only required for Matlab custom functions. The version of matlabengine should match the version of Matlab installed on the machine. This can be installed as shown below: + pip install -e .[Matlab-2023a] diff --git a/cpp/rat.cpp b/cpp/rat.cpp index 86372ad5..20e60d24 100644 --- a/cpp/rat.cpp +++ b/cpp/rat.cpp @@ -1236,14 +1236,14 @@ PYBIND11_MODULE(rat_core, m) { py::class_(m, "PlotEventData") .def(py::init<>()) - .def_readonly("reflectivity", &PlotEventData::reflectivity) - .def_readonly("shiftedData", &PlotEventData::shiftedData) - .def_readonly("sldProfiles", &PlotEventData::sldProfiles) - .def_readonly("allLayers", &PlotEventData::allLayers) - .def_readonly("ssubs", &PlotEventData::ssubs) - .def_readonly("resample", &PlotEventData::resample) - .def_readonly("dataPresent", &PlotEventData::dataPresent) - .def_readonly("modelType", &PlotEventData::modelType); + .def_readwrite("reflectivity", &PlotEventData::reflectivity) + .def_readwrite("shiftedData", &PlotEventData::shiftedData) + .def_readwrite("sldProfiles", &PlotEventData::sldProfiles) + .def_readwrite("allLayers", &PlotEventData::allLayers) + .def_readwrite("ssubs", &PlotEventData::ssubs) + .def_readwrite("resample", &PlotEventData::resample) + .def_readwrite("dataPresent", &PlotEventData::dataPresent) + .def_readwrite("modelType", &PlotEventData::modelType); py::class_(m, "BestFitsMean") .def(py::init<>()) diff --git a/examples/DSPC_custom_layers_example.py b/examples/DSPC_custom_layers_example.py index 4ba2a96c..d8190b0d 100644 --- a/examples/DSPC_custom_layers_example.py +++ b/examples/DSPC_custom_layers_example.py @@ -2,7 +2,7 @@ import numpy as np from customBilayer import customBilayer from rat import events, rat_core -from rat.misc import DylibWrapper # MatlabWrapper +from rat.misc import DylibWrapper, MatlabWrapper faulthandler.enable() @@ -171,7 +171,7 @@ def fakePlot(event): - print("Hello plotting") + print('Hello plotting') import time start = time.perf_counter() diff --git a/examples/domains_custom_layers_example.py b/examples/domains_custom_layers_example.py index f901a898..2981ed8f 100644 --- a/examples/domains_custom_layers_example.py +++ b/examples/domains_custom_layers_example.py @@ -2,7 +2,7 @@ import numpy as np from alloyDomains import alloyDomains from rat import events, rat_core -from rat.misc import DylibWrapper # MatlabWrapper +from rat.misc import DylibWrapper, MatlabWrapper faulthandler.enable() diff --git a/rat/events.py b/rat/events.py index f599db8e..1dad21fe 100644 --- a/rat/events.py +++ b/rat/events.py @@ -1,14 +1,49 @@ +from typing import Callable, Union, List from rat import rat_core -from rat.rat_core import EventTypes +from rat.rat_core import EventTypes, PlotEventData -def nofiy(event_type, data): +def notify(event_type: EventTypes, data: Union[str, PlotEventData]) -> None: + """Calls registered callbacks with the data when event type has + been triggered. + + Parameters + ---------- + event_type : EventTypes + The event type that was triggered. + data : str or PlotEventData + The data sent by th event. The message event data is a string. + """ callbacks = __event_callbacks[event_type] for callback in callbacks: callback(data) +def get_event_callback(event_type: EventTypes) -> List[Callable[[Union[str, PlotEventData]], None]]: + """Returns all callbacks registered for the given event type. + + Parameters + ---------- + event_type : EventTypes + The event type. + + Retuns + ------ + callback : Callable[[Union[str, PlotEventData]], None] + The callback for the event type. + """ + return list(__event_callbacks[event_type]) + + +def register(event_type: EventTypes, callback: Callable[[Union[str, PlotEventData]], None]) -> None: + """Registers a new callback for the event type. -def register(event_type, callback): + Parameters + ---------- + event_type : EventTypes + The event type to register. + callback : Callable[[Union[str, PlotEventData]], None] + The callback for when the event is triggered. + """ if not isinstance(event_type, EventTypes): raise ValueError("event_type must be a events.EventTypes enum") @@ -17,10 +52,12 @@ def register(event_type, callback): __event_callbacks[event_type].add(callback) -def clear(): +def clear() -> None: + """Clears all event callbacks.""" __event_impl.clear() - __event_callbacks.clear() + for key in __event_callbacks.keys(): + __event_callbacks[key] = set() -__event_impl = rat_core.EventBridge(nofiy) +__event_impl = rat_core.EventBridge(notify) __event_callbacks = {EventTypes.Message: set(), EventTypes.Plot: set()} diff --git a/rat/misc.py b/rat/misc.py index e280ec3e..2c86cd1a 100644 --- a/rat/misc.py +++ b/rat/misc.py @@ -1,42 +1,80 @@ import pathlib +from typing import Callable, Tuple import numpy as np +from numpy.typing import ArrayLike from rat import rat_core -try: - import matlab.engine - class MatlabWrapper: - def __init__(self, filename): - self.engine = matlab.engine.start_matlab() - path = pathlib.Path(filename) - self.engine.cd(str(path.parent), nargout=0) - self.function_name = path.stem - def __del__(self): +class MatlabWrapper: + """Creates a python callback for a MATLAB function. + + Parameters + ---------- + filename : string + The path of the file containing MATLAB function + """ + def __init__(self, filename: str) -> None : + self.engine = None + try: + import matlab.engine + except ImportError: + raise ImportError('matlabengine is required to use MatlabWrapper') + self.engine = matlab.engine.start_matlab() + path = pathlib.Path(filename) + self.engine.cd(str(path.parent), nargout=0) + self.function_name = path.stem + + def __del__(self): + if self.engine is not None: self.engine.quit() - def getHandle(self): - def handle(params, bulk_in, bulk_out, contrast, domain=-1): - if domain == -1: - output, sub_rough = getattr(self.engine, self.function_name)(np.array(params, 'float'), - np.array(bulk_in, 'float'), - np.array(bulk_out, 'float'), - float(contrast + 1), nargout=2) - else: - output, sub_rough = getattr(self.engine, self.function_name)(np.array(params, 'float'), - np.array(bulk_in, 'float'), - np.array(bulk_out, 'float'), - float(contrast + 1), float(domain + 1), nargout=2) - return output, sub_rough - return handle -except ImportError: - pass # maybe should log matlab engine is not installed + def getHandle(self)\ + -> Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], Tuple[ArrayLike, float]]: + """Returns a wrapper for the custom MATLAB function + + Returns + ------- + wrapper : Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], Tuple[ArrayLike, float]] + The wrapper function for the MATLAB callback + """ + def handle(params, bulk_in, bulk_out, contrast, domain=-1): + if domain == -1: + output, sub_rough = getattr(self.engine, self.function_name)(np.array(params, 'float'), + np.array(bulk_in, 'float'), + np.array(bulk_out, 'float'), + float(contrast + 1), nargout=2) + else: + output, sub_rough = getattr(self.engine, self.function_name)(np.array(params, 'float'), + np.array(bulk_in, 'float'), + np.array(bulk_out, 'float'), + float(contrast + 1), float(domain + 1), nargout=2) + return output, sub_rough + return handle class DylibWrapper: - def __init__(self, filename, function_name): + """Creates a python callback for a function in dynamic library. + + Parameters + ---------- + filename : str + The path of the dyanamic library + function_name : str + The name of the function to call + """ + def __init__(self, filename, function_name) -> None: self.engine = rat_core.DylibEngine(filename, function_name) - def getHandle(self): + def getHandle(self)\ + -> Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], Tuple[ArrayLike, float]]: + + """Returns a wrapper for the custom dynamic library function + + Returns + ------- + wrapper : Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], Tuple[ArrayLike, float]] + The wrapper function for the dynamic library callback + """ def handle(params, bulk_in, bulk_out, contrast, domain=-1): if domain == -1: output, sub_rough = self.engine.invoke(params, bulk_in, bulk_out, contrast) diff --git a/setup.py b/setup.py index bbb921ae..8449e2fa 100644 --- a/setup.py +++ b/setup.py @@ -143,7 +143,7 @@ def build_libraries(self, libraries): ) super().build_libraries(libraries) - + setup( name='rat', @@ -160,9 +160,9 @@ def build_libraries(self, libraries): ext_modules=ext_modules, install_requires=['numpy'], python_requires='>=3.9', - # setup_requires=['pybind11>=2.4'], cmdclass={'build_clib': BuildClib, 'build_ext': BuildExt}, - extras_require={"Matlab_2023b": ["matlabengine==23.2.1"], + extras_require={"Matlab_latest": ["matlabengine"], + "Matlab_2023b": ["matlabengine==23.2.1"], "Matlab_2023a": ["matlabengine==9.14.3"], "Matlab-2022b": ["matlabengine==9.13.9"], "Matlab_2022a": ["matlabengine==9.12.19"], diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_events.py b/tests/test_events.py new file mode 100644 index 00000000..b345fe8f --- /dev/null +++ b/tests/test_events.py @@ -0,0 +1,48 @@ +import unittest.mock as mock +import pytest +import rat.events + + +def test_event_register(): + first_callback = mock.Mock() + second_callback = mock.Mock() + + with pytest.raises(ValueError): + rat.events.register("Message", first_callback) + + rat.events.register(rat.events.EventTypes.Message, first_callback) + result = rat.events.get_event_callback(rat.events.EventTypes.Message) + assert result == [first_callback] + + rat.events.register(rat.events.EventTypes.Plot, second_callback) + assert rat.events.get_event_callback(rat.events.EventTypes.Plot) == [second_callback] + + rat.events.register(rat.events.EventTypes.Message, second_callback) + # the list is not guaranteed to be in the same order as inputted hence the set + assert set(rat.events.get_event_callback(rat.events.EventTypes.Message)) == set([first_callback, second_callback]) + + rat.events.clear() + assert rat.events.get_event_callback(rat.events.EventTypes.Plot) == [] + assert rat.events.get_event_callback(rat.events.EventTypes.Message) == [] + +def test_event_notify(): + first_callback = mock.Mock() + second_callback = mock.Mock() + rat.events.register(rat.events.EventTypes.Message, first_callback) + rat.events.register(rat.events.EventTypes.Plot, second_callback) + + rat.events.notify(rat.events.EventTypes.Message, "Hello World") + first_callback.assert_called_once_with("Hello World") + second_callback.assert_not_called() + + data = rat.events.PlotEventData() + rat.events.notify(rat.events.EventTypes.Plot, data) + first_callback.assert_called_once() + second_callback.assert_called_once_with(data) + + rat.events.clear() + rat.events.notify(rat.events.EventTypes.Message, "Hello World") + rat.events.notify(rat.events.EventTypes.Plot, data) + assert first_callback.call_count == 1 + assert second_callback.call_count == 1 + \ No newline at end of file diff --git a/tests/test_wrappers.py b/tests/test_wrappers.py new file mode 100644 index 00000000..05ae995a --- /dev/null +++ b/tests/test_wrappers.py @@ -0,0 +1,56 @@ +import pathlib +import sys +import unittest.mock as mock +import pytest +import rat.misc + + +def test_matlab_wrapper(): + with pytest.raises(ImportError): + rat.misc.MatlabWrapper('demo.m') + mocked_matlab_module = mock.MagicMock() + mocked_engine = mock.MagicMock() + mocked_matlab_module.engine.start_matlab.return_value = mocked_engine + + # mocked_matlab_module.engine = mock.MagicMock() + + with mock.patch.dict('sys.modules', {'matlab': mocked_matlab_module, + 'matlab.engine': mocked_matlab_module.engine}): + wrapper = rat.misc.MatlabWrapper('demo.m') + assert wrapper.function_name == 'demo' + mocked_engine.cd.assert_called_once() + assert pathlib.Path(mocked_engine.cd.call_args[0][0]).samefile('.') + + handle = wrapper.getHandle() + + mocked_engine.demo.return_value = ([2], 5) + result = handle([1], [2], [3], 0) + assert result == ([2], 5) + assert wrapper.engine.demo.call_args[0] == ([1], [2], [3], 1) + mocked_engine.demo.assert_called_once() + + mocked_engine.demo.return_value = ([3, 1], 7) + result = handle([4], [5], [6], 1, 1) + assert result == ([3, 1], 7) + assert wrapper.engine.demo.call_args[0] == ([4], [5], [6], 2, 2) + assert mocked_engine.demo.call_count == 2 + + +def test_dylib_wrapper(): + mocked_engine = mock.MagicMock() + with mock.patch('rat.misc.rat_core.DylibEngine', mocked_engine): + wrapper = rat.misc.DylibWrapper('demo.dylib', 'demo') + mocked_engine.assert_called_once_with('demo.dylib', 'demo') + + wrapper.engine.invoke.return_value = ([2], 5) + handle = wrapper.getHandle() + result = handle([1], [2], [3], 0) + assert result == ([2], 5) + assert wrapper.engine.invoke.call_args[0] == ([1], [2], [3], 0) + wrapper.engine.invoke.assert_called_once() + + wrapper.engine.invoke.return_value = ([3, 1], 7) + result = handle([4], [5], [6], 1, 1) + assert result == ([3, 1], 7) + assert wrapper.engine.invoke.call_args[0] == ([4], [5], [6], 1, 1) + assert wrapper.engine.invoke.call_count == 2