diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..e1f53046 --- /dev/null +++ b/.clang-format @@ -0,0 +1,136 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: false +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Latest +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +... diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..255c1ed0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,32 @@ +exclude: "^.github/" +repos: +- repo: https://github.com/pre-commit/mirrors-yapf.git + rev: v0.32.0 + hooks: + - id: yapf + additional_dependencies: [toml] +- repo: https://github.com/pre-commit/mirrors-clang-format.git + rev: v13.0.0 + hooks: + - id: clang-format +- repo: https://github.com/pre-commit/pre-commit-hooks.git + rev: v4.1.0 + hooks: + - id: trailing-whitespace + exclude: \.fits + - id: end-of-file-fixer + exclude: \.fits + - id: check-yaml + - id: debug-statements + - id: requirements-txt-fixer + - id: check-added-large-files + - id: check-ast + - id: check-merge-conflict +#- repo: git://github.com/detailyang/pre-commit-shell +# rev: v1.0.6 +# hooks: +# - id: shell-lint +#- repo: https://github.com/lovesegfault/beautysh.git +# rev: v6.2.1 +# hooks: +# - id: beautysh diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 00000000..32fce91e --- /dev/null +++ b/.style.yapf @@ -0,0 +1,182 @@ +[style] +# Custom stylesheet for COMPASS python code +# Relatively relax policy, trying to make nice, compact, complete lines + +# Align closing bracket with visual indentation. +align_closing_bracket_with_visual_indent = True + +# Allow dictionary keys to exist on multiple lines. For example: +# +# x = { +# ('this is the first element of a tuple', +# 'this is the second element of a tuple'): +# value, +# } +allow_multiline_dictionary_keys = True + +# Allow lambdas to be formatted on more than one line. +allow_multiline_lambdas = True + +# Insert a blank line before a class-level docstring. +blank_line_before_class_docstring = False + +# Insert a blank line before a 'def' or 'class' immediately nested +# within another 'def' or 'class'. For example: +# +# class Foo: +# # <------ this blank line +# def method(): +# ... +blank_line_before_nested_class_or_def = True + +# Do not split consecutive brackets. Only relevant when +# dedent_closing_brackets is set. For example: +# +# call_func_that_takes_a_dict( +# { +# 'key1': 'value1', +# 'key2': 'value2', +# } +# ) +# +# would reformat to: +# +# call_func_that_takes_a_dict({ +# 'key1': 'value1', +# 'key2': 'value2', +# }) +coalesce_brackets = True + +# The column limit. +column_limit = 79 + +# Indent width used for line continuations. +continuation_indent_width = 8 + +# Put closing brackets on a separate line, dedented, if the bracketed +# expression can't fit in a single line. Applies to all kinds of brackets, +# including function definitions and calls. For example: +# +# config = { +# 'key1': 'value1', +# 'key2': 'value2', +# } # <--- this bracket is dedented and on a separate line +# +# time_series = self.remote_client.query_entity_counters( +# entity='dev3246.region1', +# key='dns.query_latency_tcp', +# transform=Transformation.AVERAGE(window=timedelta(seconds=60)), +# start_ts=now()-timedelta(days=3), +# end_ts=now(), +# ) # <--- this bracket is dedented and on a separate line +dedent_closing_brackets = False + +# Place each dictionary entry onto its own line. +each_dict_entry_on_separate_line = True + +# The regex for an i18n comment. The presence of this comment stops +# reformatting of that line, because the comments are required to be +# next to the string they translate. +i18n_comment= + +# The i18n function call names. The presence of this function stops +# reformattting on that line, because the string it has cannot be moved +# away from the i18n comment. +i18n_function_call= + +# Indent the dictionary value if it cannot fit on the same line as the +# dictionary key. For example: +# +# config = { +# 'key1': +# 'value1', +# 'key2': value1 + +# value2, +# } +indent_dictionary_value = True + +# The number of columns to use for indentation. +indent_width=4 + +# Join short lines into one line. E.g., single line 'if' statements. +join_multiple_lines = True + +# Use spaces around default or named assigns. +spaces_around_default_or_named_assign = False + +# Use spaces around the power operator. +spaces_around_power_operator = False + +# The number of spaces required before a trailing comment. +spaces_before_comment = 2 + +# Insert a space between the ending comma and closing bracket of a list, +# etc. +space_between_ending_comma_and_closing_bracket = True + +# Split before arguments if the argument list is terminated by a +# comma. +split_arguments_when_comma_terminated = False + +# Set to True to prefer splitting before '&', '|' or '^' rather than +# after. +split_before_bitwise_operator = False + +# Split before a dictionary or set generator (comp_for). For example, note +# the split before the 'for': +# +# foo = { +# variable: 'Hello world, have a nice day!' +# for variable in bar if variable != 42 +# } +split_before_dict_set_generator = True + +# If an argument / parameter list is going to be split, then split before +# the first argument. +split_before_first_argument = False + +# Set to True to prefer splitting before 'and' or 'or' rather than +# after. +split_before_logical_operator = False + +# Split named assignments onto individual lines. +split_before_named_assigns = False + +# The penalty for splitting right after the opening bracket. +split_penalty_after_opening_bracket = 2600 + +# The penalty for splitting the line after a unary operator. +split_penalty_after_unary_operator = 10000 + +# The penalty for splitting right before an if expression. +split_penalty_before_if_expr = 0 + +# The penalty of splitting the line around the '&', '|', and '^' +# operators. +split_penalty_bitwise_operator = 300 + +# The penalty for characters over the column limit. +split_penalty_excess_character = 4000 + +# The penalty incurred by adding a line split to the unwrapped line. The +# more line splits added the higher the penalty. +split_penalty_for_added_line_split = 150 + +# The penalty of splitting a list of "import as" names. For example: +# +# from a_very_long_or_indented_module_name_yada_yad import (long_argument_1, +# long_argument_2, +# long_argument_3) +# +# would reformat to something like: +# +# from a_very_long_or_indented_module_name_yada_yad import ( +# long_argument_1, long_argument_2, long_argument_3) +split_penalty_import_names = 0 + +# The penalty of splitting the line around the 'and' and 'or' +# operators. +split_penalty_logical_operator = 300 + +# Use the Tab character for indentation. +use_tabs = False diff --git a/.travis.yml b/.travis.yml index c5251046..8a898062 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,4 +26,3 @@ script: - export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${MILK_INSTALLDIR}/lib/pkgconfig - ls -l /usr/local/milk/bin/ - ctest -D Experimental - diff --git a/CTestConfig.cmake b/CTestConfig.cmake index 621e0332..d095c1d4 100644 --- a/CTestConfig.cmake +++ b/CTestConfig.cmake @@ -13,4 +13,3 @@ set(CTEST_DROP_METHOD "http") set(CTEST_DROP_SITE "my.cdash.org") set(CTEST_DROP_LOCATION "/submit.php?project=milk-core") set(CTEST_DROP_SITE_CDASH TRUE) - diff --git a/README.md b/README.md index 6172605c..bc978d4f 100644 --- a/README.md +++ b/README.md @@ -63,5 +63,3 @@ Compile with coffee plugins: ./fetch_coffee_dev.sh ./compile.sh $PWD/local - - diff --git a/compile.sh b/compile.sh index 2eb2296f..98d081f9 100755 --- a/compile.sh +++ b/compile.sh @@ -3,7 +3,7 @@ usage() { - echo -n "############################################################ + echo -n "############################################################ # Compile script for milk_package # Customize / add you own options # Use as-is, or make a local custom copy (private, do not commit) @@ -40,12 +40,12 @@ Check you bashrc for export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${MILK_INSTALLDIR}/lib/pkgconfig -" + " } if [ "$1" == "-h" ]; then -usage -exit 1 + usage + exit 1 fi @@ -68,18 +68,18 @@ BUILDTYPE=${MILK_BUILD_TYPE:-"Release"} if [ "${MILK_PYTHON}" == "OFF" ]; then -echo "Compiling without Python wrapper" -cmake .. $MILK_CMAKE_OPT -DCMAKE_INSTALL_PREFIX=$MILK_INSTALL_ROOT -DCMAKE_BUILD_TYPE=${BUILDTYPE} + echo "Compiling without Python wrapper" + cmake .. $MILK_CMAKE_OPT -DCMAKE_INSTALL_PREFIX=$MILK_INSTALL_ROOT -DCMAKE_BUILD_TYPE=${BUILDTYPE} else -# find python executable -pythonexec=$(which python) -if command -v python3 &> /dev/null -then - pythonexec=$(which python3) -fi -echo "using python at ${pythonexec}" -cmake .. $MILK_CMAKE_OPT -Dbuild_python_module=ON -DPYTHON_EXECUTABLE=${pythonexec} -DCMAKE_INSTALL_PREFIX=$MILK_INSTALL_ROOT -DCMAKE_BUILD_TYPE=${BUILDTYPE} + # find python executable + pythonexec=$(which python) + if command -v python3 &> /dev/null + then + pythonexec=$(which python3) + fi + echo "using python at ${pythonexec}" + cmake .. $MILK_CMAKE_OPT -Dbuild_python_module=ON -DPYTHON_EXECUTABLE=${pythonexec} -DCMAKE_INSTALL_PREFIX=$MILK_INSTALL_ROOT -DCMAKE_BUILD_TYPE=${BUILDTYPE} fi @@ -87,6 +87,3 @@ fi NCPUS=`fgrep processor /proc/cpuinfo | wc -l` cmake --build . -- -j $NCPUS - - - diff --git a/deploy_pre_commit.sh b/deploy_pre_commit.sh new file mode 100755 index 00000000..0de61d0a --- /dev/null +++ b/deploy_pre_commit.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +if [[ ! -z "${MILK_ROOT}" ]]; then + echo "Changing dir to ${MILK_ROOT}" + cd ${MILK_ROOT} +fi + +pip install pre-commit + +sudo apt install shellcheck + +pre-commit install + + +for FOLD in $(ls -d ${MILK_ROOT}/plugins/milk-extra-src/*/); do + echo "Installing pre-commit in ${FOLD}" + cp ${MILK_ROOT}/.style.yapf ${FOLD}/ + cp ${MILK_ROOT}/.pre-commit-config.yaml ${FOLD}/ + cp ${MILK_ROOT}/.clang-format ${FOLD}/ + cd ${FOLD} + pre-commit install + cd ${MILK_ROOT} +done + +FOLD=${MILK_ROOT}/plugins/cacao-src/ +echo "Installing pre-commit in ${FOLD}" +cp ${MILK_ROOT}/.style.yapf ${FOLD}/ +cp ${MILK_ROOT}/.pre-commit-config.yaml ${FOLD}/ +cp ${MILK_ROOT}/.clang-format ${FOLD}/ +cd ${FOLD} +pre-commit install +cd ${MILK_ROOT} + +FOLD=${MILK_ROOT}/plugins/coffee-src/ +echo "Installing pre-commit in ${FOLD}" +cp ${MILK_ROOT}/.style.yapf ${FOLD}/ +cp ${MILK_ROOT}/.pre-commit-config.yaml ${FOLD}/ +cp ${MILK_ROOT}/.clang-format ${FOLD}/ +cd ${FOLD} +pre-commit install +cd ${MILK_ROOT} + +echo "Now you may run \"pre-commit run --all-files\" here and in plugin repos" diff --git a/deployconfig b/deployconfig deleted file mode 100755 index a81df0b5..00000000 --- a/deployconfig +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -cp devscripts/pre-commit .git/hooks/ diff --git a/devscripts/apply-format b/devscripts/apply-format new file mode 100755 index 00000000..653f06d0 --- /dev/null +++ b/devscripts/apply-format @@ -0,0 +1,342 @@ +#! /bin/bash +# +# Copyright 2018 Undo Ltd. +# +# https://github.com/barisione/clang-format-hooks + +# Force variable declaration before access. +set -u +# Make any failure in piped commands be reflected in the exit code. +set -o pipefail + +readonly bash_source="${BASH_SOURCE[0]:-$0}" + +################## +# Misc functions # +################## + +function error_exit() { + for str in "$@"; do + echo -n "$str" >&2 + done + echo >&2 + + exit 1 +} + + +######################## +# Command line parsing # +######################## + +function show_help() { + if [ -t 1 ] && hash tput 2> /dev/null; then + local -r b=$(tput bold) + local -r i=$(tput sitm) + local -r n=$(tput sgr0) + else + local -r b= + local -r i= + local -r n= + fi + + cat << EOF +${b}SYNOPSIS${n} + + To reformat git diffs: + + ${i}$bash_source [OPTIONS] [FILES-OR-GIT-DIFF-OPTIONS]${n} + + To reformat whole files, including unchanged parts: + + ${i}$bash_source [-f | --whole-file] FILES${n} + +${b}DESCRIPTION${n} + + Reformat C or C++ code to match a specified formatting style. + + This command can either work on diffs, to reformat only changed parts of + the code, or on whole files (if -f or --whole-file is used). + + ${b}FILES-OR-GIT-DIFF-OPTIONS${n} + List of files to consider when applying clang-format to a diff. This is + passed to "git diff" as is, so it can also include extra git options or + revisions. + For example, to apply clang-format on the changes made in the last few + revisions you could use: + ${i}\$ $bash_source HEAD~3${n} + + ${b}FILES${n} + List of files to completely reformat. + + ${b}-f, --whole-file${n} + Reformat the specified files completely (including parts you didn't + change). + The fix is printed on stdout by default. Use -i if you want to modify + the files on disk. + + ${b}--staged, --cached${n} + Reformat only code which is staged for commit. + The fix is printed on stdout by default. Use -i if you want to modify + the files on disk. + + ${b}-i${n} + Reformat the code and apply the changes to the files on disk (instead + of just printing the fix on stdout). + + ${b}--apply-to-staged${n} + This is like specifying both --staged and -i, but the formatting + changes are also staged for commit (so you can just use "git commit" + to commit what you planned to, but formatted correctly). + + ${b}--style STYLE${n} + The style to use for reformatting code. + If no style is specified, then it's assumed there's a .clang-format + file in the current directory or one of its parents. + + ${b}--help, -h, -?${n} + Show this help. +EOF +} + +# getopts doesn't support long options. +# getopt mangles stuff. +# So we parse manually... +declare positionals=() +declare has_positionals=false +declare whole_file=false +declare apply_to_staged=false +declare staged=false +declare in_place=false +declare style=file +declare ignored=() +while [ $# -gt 0 ]; do + declare arg="$1" + shift # Past option. + case "$arg" in + -h | -\? | --help ) + show_help + exit 0 + ;; + -f | --whole-file ) + whole_file=true + ;; + --apply-to-staged ) + apply_to_staged=true + ;; + --cached | --staged ) + staged=true + ;; + -i ) + in_place=true + ;; + --style=* ) + style="${arg//--style=/}" + ;; + --style ) + [ $# -gt 0 ] || \ + error_exit "No argument for --style option." + style="$1" + shift + ;; + --internal-opt-ignore-regex=* ) + ignored+=("${arg//--internal-opt-ignore-regex=/}") + ;; + --internal-opt-ignore-regex ) + ignored+=("${arg//--internal-opt-ignore-regex=/}") + [ $# -gt 0 ] || \ + error_exit "No argument for --internal-opt-ignore-regex option." + ignored+=("$1") + shift + ;; + -- ) + # Stop processing further arguments. + if [ $# -gt 0 ]; then + positionals+=("$@") + has_positionals=true + fi + break + ;; + -* ) + error_exit "Unknown argument: $arg" + ;; + *) + positionals+=("$arg") + ;; + esac +done + +# Restore positional arguments, access them from "$@". +if [ ${#positionals[@]} -gt 0 ]; then + set -- "${positionals[@]}" + has_positionals=true +fi + +[ -n "$style" ] || \ + error_exit "If you use --style you need to specify a valid style." + +####################################### +# Detection of clang-format & friends # +####################################### + +# clang-format. +declare format="${CLANG_FORMAT:-}" +if [ -z "$format" ]; then + format=$(type -p clang-format) +fi + +if [ -z "$format" ]; then + error_exit \ + $'You need to install clang-format.\n' \ + $'\n' \ + $'On Ubuntu/Debian this is available in the clang-format package or, in\n' \ + $'older distro versions, clang-format-VERSION.\n' \ + $'On Fedora it\'s available in the clang package.\n' \ + $'You can also specify your own path for clang-format by setting the\n' \ + $'$CLANG_FORMAT environment variable.' +fi + +# clang-format-diff. +if [ "$whole_file" = false ]; then + invalid="/dev/null/invalid/path" + if [ "${OSTYPE:-}" = "linux-gnu" ]; then + readonly sort_version=-V + else + # On macOS, sort doesn't have -V. + readonly sort_version=-n + fi + declare paths_to_try=() + # .deb packages directly from upstream. + # We try these first as they are probably newer than the system ones. + while read -r f; do + paths_to_try+=("$f") + done < <(compgen -G "/usr/share/clang/clang-format-*/clang-format-diff.py" | sort "$sort_version" -r) + # LLVM official releases (just untarred in /usr/local). + while read -r f; do + paths_to_try+=("$f") + done < <(compgen -G "/usr/local/clang+llvm*/share/clang/clang-format-diff.py" | sort "$sort_version" -r) + # Maybe it's in the $PATH already? This is true for Ubuntu and Debian. + paths_to_try+=( \ + "$(type -p clang-format-diff 2> /dev/null || echo "$invalid")" \ + "$(type -p clang-format-diff.py 2> /dev/null || echo "$invalid")" \ + ) + # Fedora. + paths_to_try+=( \ + /usr/share/clang/clang-format-diff.py \ + ) + # Gentoo. + while read -r f; do + paths_to_try+=("$f") + done < <(compgen -G "/usr/lib/llvm/*/share/clang/clang-format-diff.py" | sort -n -r) + # Homebrew. + while read -r f; do + paths_to_try+=("$f") + done < <(compgen -G "/usr/local/Cellar/clang-format/*/share/clang/clang-format-diff.py" | sort -n -r) + + declare format_diff= + + # Did the user specify a path? + if [ -n "${CLANG_FORMAT_DIFF:-}" ]; then + format_diff="$CLANG_FORMAT_DIFF" + else + for path in "${paths_to_try[@]}"; do + if [ -e "$path" ]; then + # Found! + format_diff="$path" + if [ ! -x "$format_diff" ]; then + format_diff="python $format_diff" + fi + break + fi + done + fi + + if [ -z "$format_diff" ]; then + error_exit \ + $'Cannot find clang-format-diff which should be shipped as part of the same\n' \ + $'package where clang-format is.\n' \ + $'\n' \ + $'Please find out where clang-format-diff is in your distro and report an issue\n' \ + $'at https://github.com/barisione/clang-format-hooks/issues with details about\n' \ + $'your operating system and setup.\n' \ + $'\n' \ + $'You can also specify your own path for clang-format-diff by setting the\n' \ + $'$CLANG_FORMAT_DIFF environment variable, for instance:\n' \ + $'\n' \ + $' CLANG_FORMAT_DIFF="python /.../clang-format-diff.py" \\\n' \ + $' ' "$bash_source" + fi + + readonly format_diff +fi + + +############################ +# Actually run the command # +############################ + +if [ "$whole_file" = true ]; then + + [ "$has_positionals" = true ] || \ + error_exit "No files to reformat specified." + [ "$staged" = false ] || \ + error_exit "--staged/--cached only make sense when applying to a diff." + + read -r -a format_args <<< "$format" + format_args+=("-style=file") + [ "$in_place" = true ] && format_args+=("-i") + + "${format_args[@]}" "$@" + +else # Diff-only. + + if [ "$apply_to_staged" = true ]; then + [ "$staged" = false ] || \ + error_exit "You don't need --staged/--cached with --apply-to-staged." + [ "$in_place" = false ] || \ + error_exit "You don't need -i with --apply-to-staged." + staged=true + readonly patch_dest=$(mktemp) + trap '{ rm -f "$patch_dest"; }' EXIT + else + readonly patch_dest=/dev/stdout + fi + + declare git_args=(git diff -U0 --no-color) + [ "$staged" = true ] && git_args+=("--staged") + + # $format_diff may contain a command ("python") and the script to excute, so we + # need to split it. + read -r -a format_diff_args <<< "$format_diff" + [ "$in_place" = true ] && format_diff_args+=("-i") + + # Build the regex for paths to consider or ignore. + # We use negative lookahead assertions which preceed the list of allowed patterns + # (that is, the extensions we want). + exclusions_regex= + if [ "${#ignored[@]}" -gt 0 ]; then + for pattern in "${ignored[@]}"; do + exclusions_regex="$exclusions_regex(?!$pattern)" + done + fi + + "${git_args[@]}" "$@" \ + | "${format_diff_args[@]}" \ + -p1 \ + -style="$style" \ + -iregex="$exclusions_regex"'.*\.(c|cpp|cxx|cc|h|hpp|m|mm|js|java)' \ + > "$patch_dest" \ + || exit 1 + + if [ "$apply_to_staged" = true ]; then + if [ ! -s "$patch_dest" ]; then + echo "No formatting changes to apply." + exit 0 + fi + patch -p0 < "$patch_dest" || \ + error_exit "Cannot apply fix to local files." + git apply -p0 --cached < "$patch_dest" || \ + error_exit "Cannot apply fix to git staged changes." + fi + +fi diff --git a/devscripts/pre-commit b/devscripts/pre-commit index c30fd953..83e85bf4 100755 --- a/devscripts/pre-commit +++ b/devscripts/pre-commit @@ -1,4 +1,3 @@ #!/bin/sh ./devscripts/precommit-code-format - diff --git a/devscripts/precommit-code-format b/devscripts/precommit-code-format index 6d85f4b5..d8069fda 100755 --- a/devscripts/precommit-code-format +++ b/devscripts/precommit-code-format @@ -6,14 +6,13 @@ RETURN=0 ASTYLECMD=$(which astyle) if [ $? -ne 0 ]; then - echo "[!] astyle not installed. Unable to check source file format policy." >&2 - exit 1 + echo "[!] astyle not installed. Unable to check source file format policy." >&2 + exit 1 fi FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep -E "\.(c|cpp|h)$") for FILE in $FILES; do - $ASTYLECMD $ASTYLEOPTIONS $FILE -n + $ASTYLECMD $ASTYLEOPTIONS $FILE -n done exit $RETURN - diff --git a/doc/CLI_Overview.md b/doc/CLI_Overview.md index 24136480..f65cc2dd 100644 --- a/doc/CLI_Overview.md +++ b/doc/CLI_Overview.md @@ -7,4 +7,3 @@ The entire C code is compiled into a single executable : Running the executable starts a command line interface (CLI) prompt from which all functions can be launched. The source code is organized in modules. A module included C code and documentation. It may also include data files and extended documentation. Run `m?` in the CLI prompt to list modules. - diff --git a/doc/CLIcore.md b/doc/CLIcore.md index 44e804c9..267419c3 100644 --- a/doc/CLIcore.md +++ b/doc/CLIcore.md @@ -1,22 +1,22 @@ -# Command Line Interface Syntax {#page_command_line_interface} +# Command Line Interface Syntax {#page_command_line_interface} Files CLIcore.c and CLIcore.h contain the source code for the command line interpreter (CLI) ## COMMAND LINE OPTIONS \verbatim - -h, --help + -h, --help print this message and exit -i, --info Print version, settings, info and exit -j, --journal - keeps journal of commands - TO BE IMPLEMENTED + keeps journal of commands - TO BE IMPLEMENTED Write all commands to file "cfits_cmdlog.txt" as they are entered --verbose be verbose -d, --debug=DEBUGLEVEL Set debug level at startup - -o, --overwrite + -o, --overwrite Automatically overwrite files if necessary (USE WITH CAUTION - WILL OVERWRITE EXISTING FITS FILES) -l Keeps a list of images in file imlist.txt @@ -61,7 +61,7 @@ Tab completion is provided and behaves as follows: GNU readline used to read input. See GNU readline documentation on http://tiswww.case.edu/php/chet/readline/rltop.html. For a quick help on readline input, type: \verbatim -> helprl +> helprl \endverbatim The command line interpreter (CLI) will take input from file cmdfile.txt if it exists. If file cmdfile.txt exists commands will be read one by one from top to bottom, and will be removed from the file as they are read, until the file is empty @@ -71,21 +71,21 @@ The command line interpreter (CLI) will take input from file cmdfile.txt if it e \verbatim > ? -> help +> help # print this help file -> helprl +> helprl # print readline quick help -> lm? +> lm? # list all modules loaded -> m? +> m? # list all commands for a module -> m? +> m? # perform m? on all modules loaded -> cmd? +> cmd? # command description for -> cmd? +> cmd? # command description for all commands -> h? str +> h? str # search for string in all commands and their descriptions \endverbatim @@ -95,20 +95,20 @@ The command line interpreter (CLI) will take input from file cmdfile.txt if it e \verbatim > ci # compilation time and memory usage -> listim +> listim # list all images in memory -> listimf +> listimf # list all images in memory and write output to file -> ! +> ! # execute system command -> showhist +> showhist # prints history of all commands -> quit +> quit # exit Cfits (exit also works) -> setdp +> setdp # set default precision to float ( = 0) or double ( = 1) -> creaim +> creaim # creates a 2D image named , size = x pixels \endverbatim @@ -119,30 +119,30 @@ FITSIO is used for FITS files I/O, see FITSIO documentation for more detailed in ## LOADING FILES \verbatim -> loadfits +> loadfits # load FITS file into image -> loadfits im1.fits imf1 +> loadfits im1.fits imf1 # load file im1.fits in memory with name imf1 -> loadfits im1.fits +> loadfits im1.fits # load file im1.fits in memory with name im1 (default name is composed of all chars before first ".") -> loadfits im1.fits.gz im1 +> loadfits im1.fits.gz im1 # load compressed file \endverbatim ## SAVING FILES \verbatim -> save_fl +> save_fl # save image into FITS file (float) -> save_fl im1 imf1.fits +> save_fl im1 imf1.fits # write image im1 to disk file imf1.fits > save_fl im1 # write image im1 to disk file im1.fits (default file name = image name + ".fits") -> save_fl im1 "!im1.fits" +> save_fl im1 "!im1.fits" # overwrite file im1.fits if it exists > save_fl im1 "../dir2/im1.fits" # specify full path -> save_fl im1 im1.fits.gz +> save_fl im1 im1.fits.gz # save compressed image \endverbatim @@ -172,15 +172,6 @@ If you start Cfits with the "-l" option, the file "imlist.txt" contains the lis # ARITHMETIC OPERATIONS \verbatim -> im1=sqrt(im+2.0) +> im1=sqrt(im+2.0) # will perform an arithmetic operation on image im and store the result in image im1 \endverbatim - - - - - - - - - diff --git a/doc/TemplateSourceCode.md b/doc/TemplateSourceCode.md index 46dba62e..8c08a001 100644 --- a/doc/TemplateSourceCode.md +++ b/doc/TemplateSourceCode.md @@ -5,15 +5,13 @@ Documentation should appear before each function in the .c and .h files, followi ## .h file -Download templatemodule.h +Download templatemodule.h See corresponding doxygen documentation : templatemodule/templatemodule.h ## .c file -Download templatemodule.c +Download templatemodule.c See corresponding doxygen documentation : templatemodule/templatemodule.c - - diff --git a/doc/coding_standards.md b/doc/coding_standards.md index feebc9af..c9eaa037 100644 --- a/doc/coding_standards.md +++ b/doc/coding_standards.md @@ -12,4 +12,3 @@ - @subpage page_ProcessInfoStructure - @subpage page_FunctionParameterStructure - @subpage page_exampleBASHscript - diff --git a/doc/help.txt b/doc/help.txt index d7bdf533..f73489de 100644 --- a/doc/help.txt +++ b/doc/help.txt @@ -3,7 +3,7 @@ ----------------------------------------------------------------------------------- COMMAND LINE OPTIONS - -h, --help + -h, --help print this message and exit -i, --info Print version, settings, info and exit @@ -11,12 +11,12 @@ COMMAND LINE OPTIONS be verbose -d, --debug=DEBUGLEVEL Set debug level at startup - -o, --overwrite + -o, --overwrite Automatically overwrite files if necessary (USE WITH CAUTION - WILL OVERWRITE EXISTING FITS FILES) -e, --idle Only run process when X is idle (WARNING: PREVENTS INTERACTIVE USER INPUT) Requires script runidle - --listimfile + --listimfile Keeps a list of images in file imlist.txt -m, --mmon=TTYDEVICE open memory monitor on tty device @@ -58,7 +58,7 @@ Tab completion is provided and behaves as follows: INPUT GNU readline used to read input. See GNU readline documentation on http://tiswww.case.edu/php/chet/readline/rltop.html. For a quick help on readline input, type: -> helprl +> helprl The command line interpreter (CLI) will take input from file cmdfile.txt if it exists. If file cmdfile.txt exists commands will be read one by one from top to bottom, and will be removed from the file as they are read, until the file is empty @@ -66,21 +66,21 @@ The command line interpreter (CLI) will take input from file cmdfile.txt if it e HELP COMMANDS > ? -> help +> help # print this help file -> helprl +> helprl # print readline quick help -> lm? +> lm? # list all modules loaded -> m? +> m? # list all commands for a module -> m? +> m? # perform m? on all modules loaded -> cmd? +> cmd? # command description for -> cmd? +> cmd? # command description for all commands -> h? str +> h? str # search for string in all commands and their descriptions ----------------------------------------------------------------------------------- @@ -88,17 +88,17 @@ IMPORTANT COMMANDS > ci # compilation time and memory usage -> listim +> listim # list all images in memory -> listimf +> listimf # list all images in memory and write output to file -> ! +> ! # execute system command -> showhist +> showhist # prints history of all commands -> quit +> quit # exit Cfits (exit also works) -> creaim +> creaim # creates a 2D image named , size = x pixels ----------------------------------------------------------------------------------- @@ -108,28 +108,28 @@ FITSIO is used for FITS files I/O, see FITSIO documentation for more detailed in LOADING FILES -> loadfits +> loadfits # load FITS file into image -> loadfits im1.fits imf1 +> loadfits im1.fits imf1 # load file im1.fits in memory with name imf1 -> loadfits im1.fits +> loadfits im1.fits # load file im1.fits in memory with name im1 (default name is composed of all chars before first ".") -> loadfits im1.fits.gz im1 +> loadfits im1.fits.gz im1 # load compressed file SAVING FILES -> savefits - # save image into FITS file -> savefits im1 imf1.fits +> savefits + # save image into FITS file +> savefits im1 imf1.fits # write image im1 to disk file imf1.fits > savefits im1 # write image im1 to disk file im1.fits (default file name = image name + ".fits") -> savefits im1 "!im1.fits" +> savefits im1 "!im1.fits" # overwrite file im1.fits if it exists > savefits im1 "../dir2/im1.fits" # specify full path -> savefits im1 im1.fits.gz +> savefits im1 im1.fits.gz # save compressed image ----------------------------------------------------------------------------------- @@ -141,11 +141,11 @@ You can control the executable through a named pipe (fifo), which is created by By default, the fifo is created in the local directory, with the name "clififo", to pipe commands into the command line interface. You can opt out of the fifo feature by adding the option --nofifo to the command line executable, or rename the fifo with the -f option : -f "/tmp/fifo145.txt" -This will create a fifo named /tmp/fifo145.txt. +This will create a fifo named /tmp/fifo145.txt. Other programs can write to the fifo to issue commands to the executable, such as: cat myscript.txt > clififo -More complex commands can be issued within the executable using the fifo. +More complex commands can be issued within the executable using the fifo. For example, to load all im*.fits files in memory, you can type within the executable: > !ls im*.fits | xargs -I {} echo loadfits {} >> clififo @@ -162,8 +162,7 @@ Note that if you launch several instances of the executable in the same director ----------------------------------------------------------------------------------- ARITHMETIC OPERATIONS -> im1=sqrt(im+2.0) +> im1=sqrt(im+2.0) # will perform an arithmetic operation on image im and store the result in image im1 ----------------------------------------------------------------------------------- - diff --git a/doc/helpreadline.md b/doc/helpreadline.md index 67643a02..34ad379f 100644 --- a/doc/helpreadline.md +++ b/doc/helpreadline.md @@ -2,11 +2,11 @@ The command line interface (CLI) uses readline to take input command for keyboard. Readline offers convenient bindings, listed in this page. - + For more information, consult the readline library documentation. -
 
+
 
 READLINE QUICK HELP
 
@@ -15,34 +15,32 @@ Notations:
 C- is control key
 M- is meta key (if already bound to action, use ESC and then type the folling character)
 
-C-_ or C-x C-u    Undo the last editing command. You can undo all the way back to an empty line. 
+C-_ or C-x C-u    Undo the last editing command. You can undo all the way back to an empty line.
 C-a	    Move to the start of the line
 C-e         Move to the end of the line
-M-f         Move forward a word, where a word is composed of letters and digits. 
-M-b         Move backward a word. 
-C-l         Clear the screen, reprinting the current line at the top. 
+M-f         Move forward a word, where a word is composed of letters and digits.
+M-b         Move backward a word.
+C-l         Clear the screen, reprinting the current line at the top.
 
 C-k         Kill the text from the current cursor position to the end of the line.
-M-d         Kill from the cursor to the end of the current word, or, if between words, to the end of the next word. 
-M-DEL       Kill from the cursor the start of the current word, or, if between words, to the start of the previous 
+M-d         Kill from the cursor to the end of the current word, or, if between words, to the end of the next word.
+M-DEL       Kill from the cursor the start of the current word, or, if between words, to the start of the previous
 C-w         Kill from the cursor to the previous whitespace. This is different than M-DEL because the word boundaries differ.
 
 C-y         Yank the most recently killed text back into the buffer at the cursor.
-M-y         Rotate the kill-ring, and yank the new top. You can only do this if the prior command is C-y or ESC y. 
+M-y         Rotate the kill-ring, and yank the new top. You can only do this if the prior command is C-y or ESC y.
 
 M-<         Move to the first line in the history.
-M->         Move to the end of the input history, i.e., the line currently being entered. 
+M->         Move to the end of the input history, i.e., the line currently being entered.
 
 C-t	    Drag the character before the cursor forward over the character at the cursor, moving the cursor forward as well. If the insertion point is at the end of the line, then this transposes the last two characters of the line. Negative arguments have no effect.
 M-t	    Drag the word before point past the word after point, moving point past that word as well. If the insertion point is at the end of the line, this transposes the last two words on the line.
 M-u	    Uppercase the current (or following) word. With a negative argument, uppercase the previous word, but do not move the cursor.
 M-l	    Lowercase the current (or following) word. With a negative argument, lowercase the previous word, but do not move the cursor.
-M-c	    Capitalize the current (or following) word. With a negative argument, capitalize the previous word, but do not move the cursor. 
+M-c	    Capitalize the current (or following) word. With a negative argument, capitalize the previous word, but do not move the cursor.
 
 TAB         Attempt to perform completion on the text before point. The actual completion performed is application-specific. The default is filename completion.
 M-?         List the possible completions of the text before point.
-M-*         Insert all completions of the text before point that would have been generated by possible-completions. 
+M-*         Insert all completions of the text before point that would have been generated by possible-completions.
 
 
- - diff --git a/doc/templatemodule/templatemodule.c b/doc/templatemodule/templatemodule.c index 23fb9cca..e2102e2b 100644 --- a/doc/templatemodule/templatemodule.c +++ b/doc/templatemodule/templatemodule.c @@ -5,12 +5,12 @@ * Follow this template to write your C code * The template includes examples of frequently used coding practices * and doxygen-based documentation - * + * * Source code includes notes (comments): * - CODING STANDARD NOTE : note about coding practices and standards * - DOCUMENTATION NOTE : how to document code - * - * + * + * * ## Other files of interest * Each module should include : * - souce code (.c file) @@ -19,21 +19,15 @@ * ## Change log * - 20180120 Guyon Added mode documentation * - 20170813 Guyon Added some documentation - * + * * @author O. Guyon * * @bug No known bugs. * */ - /** @defgroup RTfunctions Functions with high priority scheduler */ - - - - - /// CODING STANDARD NOTE: code indented by : bash -c "astyle --indent-classes -Y" /* =============================================================================================== */ @@ -48,25 +42,20 @@ /// CODING STANDARD NOTE: document any unusual head file include -#include // module strangefile does strange things, which we need in this module - +#include // module strangefile does strange things, which we need in this module // frequently included -#include -#include "CLIcore.h" #include "00CORE/00CORE.h" -#include "COREMOD_memory/COREMOD_memory.h" +#include "CLIcore.h" +#include "COREMOD_arith/COREMOD_arith.h" #include "COREMOD_iofits/COREMOD_iofits.h" +#include "COREMOD_memory/COREMOD_memory.h" #include "COREMOD_tools/COREMOD_tools.h" -#include "COREMOD_arith/COREMOD_arith.h" - - +#include // CODING STANDARD NOTE: include function prototypes for this module #include "templatemodule/templatemodule.h" - - /* =============================================================================================== */ /* =============================================================================================== */ /* DEFINES, MACROS */ @@ -76,31 +65,26 @@ // CODING STANDARD NOTE: start with defines // CODING STANDARD NOTE: #define constants should be in all CAPS // CODING STANDARD NOTE: do not use names starting or ending with "_" (reserved for system) -#define TWOPLUSTWO 4 +#define TWOPLUSTWO 4 #define NAME_STRING_MAXSIZE 100 #define FNAME_STRING_MAXSIZE 200 #define COMMAND_STRING_MAXSIZE 200 - // CODING STANDARD NOTE: list function macros after defines // CODING STANDARD NOTE: function macro start with module name when specific to current module -#define ABS(x) (((x) < 0) ? -(x) : (x)) -#define EXAMPLEMODULE_MAX(a,b) ((a < b) ? (b) : (a)) +#define ABS(x) (((x) < 0) ? -(x) : (x)) +#define EXAMPLEMODULE_MAX(a, b) ((a < b) ? (b) : (a)) // CODING STANDARD NOTE: list typedefs after function macros // CODING STANDARD NOTE: list enums after typedefs - - - /* =============================================================================================== */ /* =============================================================================================== */ /* GLOBAL DATA DECLARATION */ /* =============================================================================================== */ /* =============================================================================================== */ - // CODING STANDARD NOTE: Function, typedef, and variable names, as well as struct, union, and enum tag names should be in lower case // CODING STANDARD NOTE: @@ -110,10 +94,6 @@ // static globals - - - - /* =============================================================================================== */ /* =============================================================================================== */ /* FUNCTIONS TIED TO COMMAND LINE INTERFACE (CLI) */ @@ -131,30 +111,32 @@ // 2: long // 3: string, not existing image // 4: existing image -// 5: string +// 5: string // - // CODING STANDARD NOTE: CLI function name should be function name + "_cli", with no argument -int_fast8_t templatemodule_examplefunction00_cli() { - if(CLI_checkarg(1,2)==0) { +int_fast8_t templatemodule_examplefunction00_cli() +{ + if (CLI_checkarg(1, 2) == 0) + { templatemodule_examplefunction00(data.cmdargtoken[1].val.numl); return 0; } - else return 1; + else + return 1; } -int_fast8_t templatemodule_examplefunction01_cli() { - if(CLI_checkarg(1,1)+CLI_checkarg(2,2)==0) { +int_fast8_t templatemodule_examplefunction01_cli() +{ + if (CLI_checkarg(1, 1) + CLI_checkarg(2, 2) == 0) + { templatemodule_examplefunction01(data.cmdargtoken[1].val.numl, data.cmdargtoken[2].val.numf, NULL); return 0; } - else return 1; + else + return 1; } - - - /* =============================================================================================== */ /* =============================================================================================== */ /* MODULE INITIALIZATION */ @@ -170,40 +152,24 @@ int_fast8_t init_templatemodule() strcpy(data.module[data.NBmodule].info, "AO loop control"); data.NBmodule++; + // CODING STANDARD NOTE: follow this template to link function calls to the command line interface + // CODING STANDARD NOTE: arg1 : function name in command line + // CODING STANDARD NOTE: arg2 : module name (= __FILE__) + // CODING STANDARD NOTE: arg3 : C call + // CODING STANDARD NOTE: arg4 : one-line description + // CODING STANDARD NOTE: arg5 : arguments. ... + // CODING STANDARD NOTE: arg6 : example call from CLI + // CODING STANDARD NOTE: arg7 : C call syntax - // CODING STANDARD NOTE: follow this template to link function calls to the command line interface - // CODING STANDARD NOTE: arg1 : function name in command line - // CODING STANDARD NOTE: arg2 : module name (= __FILE__) - // CODING STANDARD NOTE: arg3 : C call - // CODING STANDARD NOTE: arg4 : one-line description - // CODING STANDARD NOTE: arg5 : arguments. ... - // CODING STANDARD NOTE: arg6 : example call from CLI - // CODING STANDARD NOTE: arg7 : C call syntax - - RegisterCLIcommand("clicmdname", - __FILE__, - templatemodule_examplefunction_cli, - "function purpose", - "", - "clicmdname 3", - "int templatemodule_examplefunc(int mode)"); + RegisterCLIcommand("clicmdname", __FILE__, templatemodule_examplefunction_cli, "function purpose", "", + "clicmdname 3", "int templatemodule_examplefunc(int mode)"); - // CODING STANDARD NOTE: Link as many functions as desired + // CODING STANDARD NOTE: Link as many functions as desired // CODING STANDARD NOTE: Add atexit function(s) here (OPTIONAL) // atexit((void*) templatemodule_clearmem()); } - - - - - - - - - - /* =============================================================================================== */ /* =============================================================================================== */ /* FUNCTION(S) SOURCE CODE */ @@ -211,47 +177,35 @@ int_fast8_t init_templatemodule() /* =============================================================================================== */ /** @name TEMPLATEMODULE functions */ - - - - - - - - /* =============================================================================================== */ /* =============================================================================================== */ /** @name TEMPLATEMODULE - 1. FIRST GROUP OF FUNCTIONS */ /* =============================================================================================== */ /* =============================================================================================== */ - - - - // CODING STANDARD NOTE: minimal required documentation for doxygen /** * ## Purpose - * + * * This function does absolutely nothing useful - * - * + * + * * ## Arguments - * + * * @param[in] mode * mode sets up what function does * - does nothing * - also does nothing - * + * */ // CODING STANDARD NOTE: function name start with module name -int templatemodule_examplefunc00(int mode) +int templatemodule_examplefunc00(int mode) { // CODING STANDARD NOTE: pointer qualifier '*' with variable rather than with the type float *farray; - - int return_value; - + + int return_value; + // CODING STANDARD NOTE: choose human-readable variable names // CODING STANDARD NOTE: unrelated declarations should be on separate lines long iipix, jjpix; // pixel coordinates @@ -259,28 +213,26 @@ int templatemodule_examplefunc00(int mode) long NBiteration; long n2; - FILE *fp_test; - + FILE *fp_test; + + farray = (float *)malloc(sizeof(float) * 10); + if (farray == NULL) + printERROR(__FILE__, __func__, __LINE__, "malloc returns zero value"); - farray = (float*) malloc(sizeof(float)*10); - if(farray == NULL) - printERROR(__FILE__, __func__, __LINE__, "malloc returns zero value"); - - // CODING STANDARD NOTE: how to write an infinite loop // CODING STANDARD NOTE: Do not write infinite loop with while statement - for(;;) + for (;;) { // infinite loop } - free(farray); + free(farray); - fp_test = fopen("testfile.log", "w"); - if(fp_test == NULL) - printERROR(__FILE__, __func__, __LINE__, "Cannot open file testfile.log"); - fclose(fp_test); + fp_test = fopen("testfile.log", "w"); + if (fp_test == NULL) + printERROR(__FILE__, __func__, __LINE__, "Cannot open file testfile.log"); + fclose(fp_test); - if(mode == 2) + if (mode == 2) { // CODING STANDARD NOTE: reduce variable scope as much as possible // CODING STANDARD NOTE: variables used inside code block declared at beginning of code block @@ -292,33 +244,30 @@ int templatemodule_examplefunc00(int mode) // CODING STANDARD NOTE: printERROR(const char *file, const char *func, int line, char *errmessage) // CODING STANDARD NOTE: printWARNING(const char *file, const char *func, int line, char *warnmessage) // CODING STANDARD NOTE: printERROR will exit code, printWARNING will issue warning and continue - if(sprintf(name, "image1", loop)<1) + if (sprintf(name, "image1", loop) < 1) printERROR(__FILE__, __func__, __LINE__, "sprintf wrote <1 char"); - if(sprintf(command, "ls %s.fits", name) < 1) + if (sprintf(command, "ls %s.fits", name) < 1) printERROR(__FILE__, __func__, __LINE__, "sprintf wrote <1 char"); - if(system(command) != 0) - printERROR(__FILE__,__func__,__LINE__, "system() returns non-zero value"); + if (system(command) != 0) + printERROR(__FILE__, __func__, __LINE__, "system() returns non-zero value"); } - fp_test = fopen("testfile.log", "r"); - if(fp_test == NULL) - printERROR(__FILE__, __func__, __LINE__, "Cannot Read file testfile.log"); + fp_test = fopen("testfile.log", "r"); + if (fp_test == NULL) + printERROR(__FILE__, __func__, __LINE__, "Cannot Read file testfile.log"); - // CODING STANDARD NOTE: include field width limits in fscanf and sscanf calls - if(fscanf(fp_test, "%8ld", &n2) != 1) - printERROR(__FILE__,__func__,__LINE__, "fscanf returns value != 1"); - fclose(fp_test); - - // CODING STANDARD NOTE: Other test prototypes: - // CODING STANDARD NOTE: if(fread(...) < 1) printERROR(__FILE__,__func__,__LINE__, "fread() returns <1 value"); + // CODING STANDARD NOTE: include field width limits in fscanf and sscanf calls + if (fscanf(fp_test, "%8ld", &n2) != 1) + printERROR(__FILE__, __func__, __LINE__, "fscanf returns value != 1"); + fclose(fp_test); + // CODING STANDARD NOTE: Other test prototypes: + // CODING STANDARD NOTE: if(fread(...) < 1) printERROR(__FILE__,__func__,__LINE__, "fread() returns <1 value"); free(farray); - - return(0); -} - + return (0); +} /* =============================================================================================== */ /* =============================================================================================== */ @@ -326,99 +275,83 @@ int templatemodule_examplefunc00(int mode) /* =============================================================================================== */ /* =============================================================================================== */ - - - - /* =============================================================================================== */ /** @name TEMPLATEMODULE - 2.1. SECOND GROUP OF FUNCTIONS - SUBGROUP1 */ /* =============================================================================================== */ - - // DOCUMENTATION NOTE: put @brief statement in .h // DOCUMENTATION NOTE: put short argument description in .h // DOCUMENTATION NOTE: put detailed function documentation in .c - /** * ## Purpose - * + * * This function demonstrates use of seteuid, sched_setscheduler \n * Note that fields "Use", "return", "not" and "warning" are optional - * + * * ## Arguments - * + * * Brief description of arguments is in .h file \n * A more detailed description of arguments in provided here \n - * - * - * + * + * + * * ## Use - * + * * Use section is optional * to use this function, call it as * @code * templatemodule_examplefunc01(v1, n1, farray) * @endcode - * + * * --- - * - * + * + * * @return number of iteration [int] * @note sched_setscheduler and seteuid not supported under OS-X - * @warning This function does nothing useful - * + * @warning This function does nothing useful + * * \ingroup RTfunctions - * - * + * + * * ## Details - * + * */ -int templatemodule_examplefunc01( - const char* namein, - float val1, - int n1, - float* restrict farray - ) +int templatemodule_examplefunc01(const char *namein, float val1, int n1, float *restrict farray) { - /// --- - /// # Code Description - /// - int Niteration; - - int RT_priority = 95; // any number from 0-99. Higher number = higher priority - struct sched_param schedpar; - - int retval; - - schedpar.sched_priority = RT_priority; - - /// ## Set up priviledges - - #ifndef __MACH__ // Do not run code below if OS-X + /// --- + /// # Code Description + /// + int Niteration; + + int RT_priority = 95; // any number from 0-99. Higher number = higher priority + struct sched_param schedpar; + + int retval; + + schedpar.sched_priority = RT_priority; + + /// ## Set up priviledges + +#ifndef __MACH__ // Do not run code below if OS-X iretval = seteuid(euid_called); //This goes up to maximum privileges - if(retval != 0) - printERROR(__FILE__, __func__, __LINE__, "seteuid() returns non-zero value"); - - sched_setscheduler(0, SCHED_FIFO, &schedpar); //other option is SCHED_RR, might be faster + if (retval != 0) + printERROR(__FILE__, __func__, __LINE__, "seteuid() returns non-zero value"); - retval = seteuid(euid_real); //Go back to normal privileges - if(retval != 0) - printERROR(__FILE__, __func__, __LINE__, "seteuid() returns non-zero value"); - #endif - - /// ## Execute loop - - // code here - for(;;) // preferred way to write infinite loop - { - } - - /// --- - return(Niteration); -} + sched_setscheduler(0, SCHED_FIFO, &schedpar); //other option is SCHED_RR, might be faster + retval = seteuid(euid_real); //Go back to normal privileges + if (retval != 0) + printERROR(__FILE__, __func__, __LINE__, "seteuid() returns non-zero value"); +#endif + /// ## Execute loop + // code here + for (;;) // preferred way to write infinite loop + { + } + /// --- + return (Niteration); +} diff --git a/doc/templatemodule/templatemodule.h b/doc/templatemodule/templatemodule.h index e4c65ded..ba24847b 100644 --- a/doc/templatemodule/templatemodule.h +++ b/doc/templatemodule/templatemodule.h @@ -1,31 +1,23 @@ /** * @file templatemodule.h * @brief Function prototypes for templatemodule - * - * + * + * * @author O. Guyon * @date Aug 2 2017 * - * + * * @bug No known bugs. - * + * */ - // CODING STANDARD NOTE: Ensure this code is only read once #ifndef _TEMPLATEMODULE_H #define _TEMPLATEMODULE_H - - - - /** @name INITIALIZATION * Module initialization functions */ - - - /** @brief Initialize module */ int_fast8_t init_templatemodule(); @@ -36,31 +28,24 @@ int_fast8_t init_templatemodule(); /* =============================================================================================== */ /* =============================================================================================== */ -/** @brief one-line description of function +/** @brief one-line description of function * More can be included here if needed */ int templatemodule_examplefunc00(int mode); - /* =============================================================================================== */ /* =============================================================================================== */ /** @name TEMPLATEMODULE - 2. SECOND GROUP OF FUNCTIONS */ /* =============================================================================================== */ /* =============================================================================================== */ - /* =============================================================================================== */ /** @name TEMPLATEMODULE - 2.1. SECOND GROUP OF FUNCTIONS - SUBGROUP1 */ /* =============================================================================================== */ /** @brief one-line description of function */ -int templatemodule_examplefunc01( - float val1, ///< [in] This parameter does this and that - int n1, ///< [in] Number of that - float *farray ///< [out] Output array - ); - - - +int templatemodule_examplefunc01(float val1, ///< [in] This parameter does this and that + int n1, ///< [in] Number of that + float *farray ///< [out] Output array +); #endif - diff --git a/docs/_config.yml b/docs/_config.yml index 2f7efbea..fff4ab92 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-minimal \ No newline at end of file +theme: jekyll-theme-minimal diff --git a/docs/fps.md b/docs/fps.md index df06470a..a3b7b2aa 100644 --- a/docs/fps.md +++ b/docs/fps.md @@ -1,3 +1,3 @@ # Function Parameter Structure (FPS) -FPS is +FPS is diff --git a/docs/install/p1.md b/docs/install/p1.md index 44e63b45..76ee417d 100644 --- a/docs/install/p1.md +++ b/docs/install/p1.md @@ -1,2 +1 @@ this is page 1 - diff --git a/docs/install/p2.md b/docs/install/p2.md index 8f9df864..91e02fc8 100644 --- a/docs/install/p2.md +++ b/docs/install/p2.md @@ -1,2 +1 @@ page 2 content - diff --git a/docs/procinfo.md b/docs/procinfo.md index 15a2edee..76374c02 100644 --- a/docs/procinfo.md +++ b/docs/procinfo.md @@ -1,3 +1,3 @@ # Process Information (procinfo) -procinfo is +procinfo is diff --git a/docs/streams.md b/docs/streams.md index 100cc373..def5082a 100644 --- a/docs/streams.md +++ b/docs/streams.md @@ -1,4 +1,3 @@ # Image Streams blabla... - diff --git a/fetch_atmosphere_dev.sh b/fetch_atmosphere_dev.sh index 0e83c2eb..d9669ccd 100755 --- a/fetch_atmosphere_dev.sh +++ b/fetch_atmosphere_dev.sh @@ -6,13 +6,13 @@ CWD=$PWD cd plugins/milk-extra-src for mod in WFpropagate OpticsMaterials AtmosphereModel AtmosphericTurbulence do -echo "Module ${mod}" -if [ -d "${mod}" ]; then - echo " Already installed -> pulling" - (cd ${mod}; git pull) -else - git clone -b dev https://github.com/milk-org/${mod} - echo "" -fi + echo "Module ${mod}" + if [ -d "${mod}" ]; then + echo " Already installed -> pulling" + (cd ${mod}; git pull) + else + git clone -b dev https://github.com/milk-org/${mod} + echo "" + fi done cd $CWD diff --git a/fetch_cacao_dev.sh b/fetch_cacao_dev.sh index 16d9bbab..af9c3e0a 100755 --- a/fetch_cacao_dev.sh +++ b/fetch_cacao_dev.sh @@ -4,9 +4,9 @@ echo "Module CACAO" if [ -d "plugins/cacao-src" ]; then - echo " Already installed -> pulling" - (cd plugins/cacao-src; git pull) + echo " Already installed -> pulling" + (cd plugins/cacao-src; git pull) else - git clone -b dev https://github.com/cacao-org/cacao plugins/cacao-src - echo "" + git clone -b dev https://github.com/cacao-org/cacao plugins/cacao-src + echo "" fi diff --git a/fetch_coffee_dev.sh b/fetch_coffee_dev.sh index ef3465a5..44ed87be 100755 --- a/fetch_coffee_dev.sh +++ b/fetch_coffee_dev.sh @@ -6,23 +6,23 @@ CWD=$PWD cd plugins/milk-extra-src for mod in WFpropagate OpticsMaterials do -echo "Module ${mod}" -if [ -d "${mod}" ]; then - echo " Already installed -> pulling" - (cd ${mod}; git pull) -else - git clone -b dev https://github.com/milk-org/${mod} - echo "" -fi + echo "Module ${mod}" + if [ -d "${mod}" ]; then + echo " Already installed -> pulling" + (cd ${mod}; git pull) + else + git clone -b dev https://github.com/milk-org/${mod} + echo "" + fi done cd $CWD echo "COFFEE modules" if [ -d "plugins/coffee-src" ]; then - echo " Already installed -> pulling" - (cd plugins/coffee-src; git pull) + echo " Already installed -> pulling" + (cd plugins/coffee-src; git pull) else - git clone -b dev https://github.com/coffee-org/coffee plugins/coffee-src - echo "" + git clone -b dev https://github.com/coffee-org/coffee plugins/coffee-src + echo "" fi diff --git a/fetch_milk_dev.sh b/fetch_milk_dev.sh index bfd1bcdf..b4f3b54f 100755 --- a/fetch_milk_dev.sh +++ b/fetch_milk_dev.sh @@ -5,12 +5,12 @@ cd plugins/milk-extra-src for mod in clustering fft ZernikePolyn cudacomp image_basic image_filter image_format image_gen img_reduce info kdtree linARfilterPred linopt_imtools psf statistic do -echo "Module ${mod}" -if [ -d "${mod}" ]; then - echo " Already installed -> pulling" - (cd ${mod}; git pull) -else - git clone -b dev https://github.com/milk-org/${mod} - echo "" -fi + echo "Module ${mod}" + if [ -d "${mod}" ]; then + echo " Already installed -> pulling" + (cd ${mod}; git pull) + else + git clone -b dev https://github.com/milk-org/${mod} + echo "" + fi done diff --git a/python_module/CacaoProcessTools.cpp b/python_module/CacaoProcessTools.cpp index 9db0a808..15435cb1 100644 --- a/python_module/CacaoProcessTools.cpp +++ b/python_module/CacaoProcessTools.cpp @@ -8,127 +8,126 @@ namespace py = pybind11; using namespace pybind11::literals; -extern "C" { -DATA __attribute__((used)) data; +extern "C" +{ + DATA __attribute__((used)) data; } -int fps_value_to_key(pyFps &cls, const std::string &key, - const FPS_type fps_type, py::object value) { - switch (fps_type) { +int fps_value_to_key(pyFps &cls, const std::string &key, const FPS_type fps_type, py::object value) +{ + switch (fps_type) + { case FPS_type::INT32: case FPS_type::UINT32: case FPS_type::INT64: case FPS_type::UINT64: - return functionparameter_SetParamValue_INT64(cls, key.c_str(), - py::int_(value)); + return functionparameter_SetParamValue_INT64(cls, key.c_str(), py::int_(value)); case FPS_type::FLOAT32: - return functionparameter_SetParamValue_FLOAT32(cls, key.c_str(), - py::float_(value)); + return functionparameter_SetParamValue_FLOAT32(cls, key.c_str(), py::float_(value)); case FPS_type::FLOAT64: - return functionparameter_SetParamValue_FLOAT64(cls, key.c_str(), - py::float_(value)); + return functionparameter_SetParamValue_FLOAT64(cls, key.c_str(), py::float_(value)); case FPS_type::STRING: - return functionparameter_SetParamValue_STRING(cls, key.c_str(), - std::string(py::str(value)).c_str()); + return functionparameter_SetParamValue_STRING(cls, key.c_str(), std::string(py::str(value)).c_str()); default: - return EXIT_FAILURE; - } + return EXIT_FAILURE; + } } -py::object fps_value_from_key(pyFps &cls, const std::string &key, - const FPS_type fps_type) { - switch (fps_type) { +py::object fps_value_from_key(pyFps &cls, const std::string &key, const FPS_type fps_type) +{ + switch (fps_type) + { case FPS_type::INT32: case FPS_type::UINT32: case FPS_type::INT64: case FPS_type::UINT64: - return py::int_(functionparameter_GetParamValue_INT64(cls, key.c_str())); + return py::int_(functionparameter_GetParamValue_INT64(cls, key.c_str())); case FPS_type::FLOAT32: - return py::float_( - functionparameter_GetParamValue_FLOAT32(cls, key.c_str())); + return py::float_(functionparameter_GetParamValue_FLOAT32(cls, key.c_str())); case FPS_type::FLOAT64: - return py::float_( - functionparameter_GetParamValue_FLOAT64(cls, key.c_str())); + return py::float_(functionparameter_GetParamValue_FLOAT64(cls, key.c_str())); case FPS_type::STRING: - return py::str(functionparameter_GetParamPtr_STRING(cls, key.c_str())); + return py::str(functionparameter_GetParamPtr_STRING(cls, key.c_str())); default: - return py::none(); - } + return py::none(); + } } -py::dict fps_to_dict(pyFps &cls) { - py::dict fps_dict; - for (auto &key : cls.keys()) { - fps_dict[py::str(key.first)] = - fps_value_from_key(cls, key.first, key.second); - } - return fps_dict; +py::dict fps_to_dict(pyFps &cls) +{ + py::dict fps_dict; + for (auto &key : cls.keys()) + { + fps_dict[py::str(key.first)] = fps_value_from_key(cls, key.first, key.second); + } + return fps_dict; } -PYBIND11_MODULE(CacaoProcessTools, m) { - m.doc() = "CacaoProcessTools library module"; +PYBIND11_MODULE(CacaoProcessTools, m) +{ + m.doc() = "CacaoProcessTools library module"; - CLI_data_init(); - // m.attr("data") = &data; + CLI_data_init(); + // m.attr("data") = &data; - m.def("processCTRL", &processinfo_CTRLscreen, - R"pbdoc(Open the process control monitor + m.def("processCTRL", &processinfo_CTRLscreen, + R"pbdoc(Open the process control monitor )pbdoc"); - m.def("streamCTRL", &streamCTRL_CTRLscreen, - R"pbdoc(Open the stream control monitor + m.def("streamCTRL", &streamCTRL_CTRLscreen, + R"pbdoc(Open the stream control monitor )pbdoc"); - m.def("fparamCTRL", &functionparameter_CTRLscreen, - R"pbdoc(Open the function parameter monitor + m.def("fparamCTRL", &functionparameter_CTRLscreen, + R"pbdoc(Open the function parameter monitor )pbdoc"); - py::enum_(m, "FPS_status") - .value("CONF", FPS_status::CONF) - .value("RUN", FPS_status::RUN) - .value("CMDCONF", FPS_status::CMDCONF) - .value("CMDRUN", FPS_status::CMDRUN) - .value("RUNLOOP", FPS_status::RUNLOOP) - .value("CHECKOK", FPS_status::CHECKOK) - .value("TMUXCONF", FPS_status::TMUXCONF) - .value("TMUXRUN", FPS_status::TMUXRUN) - .value("TMUXCTRL", FPS_status::TMUXCTRL) - .export_values(); - - py::enum_(m, "FPS_type") - .value("AUTO", FPS_type::AUTO) - .value("UNDEF", FPS_type::UNDEF) - .value("INT32", FPS_type::INT32) - .value("UINT32", FPS_type::UINT32) - .value("INT64", FPS_type::INT64) - .value("UINT64", FPS_type::UINT64) - .value("FLOAT32", FPS_type::FLOAT32) - .value("FLOAT64", FPS_type::FLOAT64) - .value("PID", FPS_type::PID) - .value("TIMESPEC", FPS_type::TIMESPEC) - .value("FILENAME", FPS_type::FILENAME) - .value("FITSFILENAME", FPS_type::FITSFILENAME) - .value("EXECFILENAME", FPS_type::EXECFILENAME) - .value("DIRNAME", FPS_type::DIRNAME) - .value("STREAMNAME", FPS_type::STREAMNAME) - .value("STRING", FPS_type::STRING) - .value("ONOFF", FPS_type::ONOFF) - .value("PROCESS", FPS_type::PROCESS) - .value("FPSNAME", FPS_type::FPSNAME) - .export_values(); - - py::class_(m, "timespec") - .def(py::init()) - .def_readwrite("tv_sec", ×pec::tv_sec) - .def_readwrite("tv_nsec", ×pec::tv_nsec); - - py::class_(m, "processinfo") - .def(py::init<>(), - R"pbdoc(Construct a empty Process Info object + py::enum_(m, "FPS_status") + .value("CONF", FPS_status::CONF) + .value("RUN", FPS_status::RUN) + .value("CMDCONF", FPS_status::CMDCONF) + .value("CMDRUN", FPS_status::CMDRUN) + .value("RUNLOOP", FPS_status::RUNLOOP) + .value("CHECKOK", FPS_status::CHECKOK) + .value("TMUXCONF", FPS_status::TMUXCONF) + .value("TMUXRUN", FPS_status::TMUXRUN) + .value("TMUXCTRL", FPS_status::TMUXCTRL) + .export_values(); + + py::enum_(m, "FPS_type") + .value("AUTO", FPS_type::AUTO) + .value("UNDEF", FPS_type::UNDEF) + .value("INT32", FPS_type::INT32) + .value("UINT32", FPS_type::UINT32) + .value("INT64", FPS_type::INT64) + .value("UINT64", FPS_type::UINT64) + .value("FLOAT32", FPS_type::FLOAT32) + .value("FLOAT64", FPS_type::FLOAT64) + .value("PID", FPS_type::PID) + .value("TIMESPEC", FPS_type::TIMESPEC) + .value("FILENAME", FPS_type::FILENAME) + .value("FITSFILENAME", FPS_type::FITSFILENAME) + .value("EXECFILENAME", FPS_type::EXECFILENAME) + .value("DIRNAME", FPS_type::DIRNAME) + .value("STREAMNAME", FPS_type::STREAMNAME) + .value("STRING", FPS_type::STRING) + .value("ONOFF", FPS_type::ONOFF) + .value("PROCESS", FPS_type::PROCESS) + .value("FPSNAME", FPS_type::FPSNAME) + .export_values(); + + py::class_(m, "timespec") + .def(py::init()) + .def_readwrite("tv_sec", ×pec::tv_sec) + .def_readwrite("tv_nsec", ×pec::tv_nsec); + + py::class_(m, "processinfo") + .def(py::init<>(), + R"pbdoc(Construct a empty Process Info object )pbdoc") - .def(py::init(), - R"pbdoc(Construct a new Process Info object + .def(py::init(), + R"pbdoc(Construct a new Process Info object Parameters: pname : name of the Process Info object (human-readable) @@ -138,10 +137,10 @@ PYBIND11_MODULE(CacaoProcessTools, m) { - 2: increment single step (will go back to 1) - 3: exit loop )pbdoc", - py::arg("name"), py::arg("CTRLval")) + py::arg("name"), py::arg("CTRLval")) - .def("create", &pyProcessInfo::create, - R"pbdoc(Create Process Info object in shared memory + .def("create", &pyProcessInfo::create, + R"pbdoc(Create Process Info object in shared memory Parameters: pname : name of the Process Info object (human-readable) @@ -153,163 +152,139 @@ PYBIND11_MODULE(CacaoProcessTools, m) { Return: ret : error code )pbdoc", - py::arg("name"), py::arg("CTRLval")) + py::arg("name"), py::arg("CTRLval")) - .def("link", &pyProcessInfo::link, - R"pbdoc(Link an existing Process Info object in shared memory + .def("link", &pyProcessInfo::link, + R"pbdoc(Link an existing Process Info object in shared memory Parameters: pname : name of the Process Info object (human-readable) Return: ret : error code )pbdoc", - py::arg("name")) + py::arg("name")) - .def("close", &pyProcessInfo::close, - R"pbdoc(Close an existing Process Info object in shared memory + .def("close", &pyProcessInfo::close, + R"pbdoc(Close an existing Process Info object in shared memory Parameters: pname : name of the Process Info object (human-readable) Return: ret : error code )pbdoc", - py::arg("name")) + py::arg("name")) - .def("sigexit", &pyProcessInfo::sigexit, - R"pbdoc(Send a signal to a Process Info object + .def("sigexit", &pyProcessInfo::sigexit, + R"pbdoc(Send a signal to a Process Info object Parameters: sig : signal to send )pbdoc", - py::arg("sig")) + py::arg("sig")) - .def("writeMessage", &pyProcessInfo::writeMessage, - R"pbdoc(Write a message into a Process Info object + .def("writeMessage", &pyProcessInfo::writeMessage, + R"pbdoc(Write a message into a Process Info object Parameters: message : message to write Return: ret : error code )pbdoc", - py::arg("message")) + py::arg("message")) - .def("exec_start", &pyProcessInfo::exec_start, - R"pbdoc(Define the start of the process (timing purpose) + .def("exec_start", &pyProcessInfo::exec_start, + R"pbdoc(Define the start of the process (timing purpose) Return: ret : error code )pbdoc") - .def("exec_end", &pyProcessInfo::exec_end, - R"pbdoc(Define the end of the process (timing purpose) + .def("exec_end", &pyProcessInfo::exec_end, + R"pbdoc(Define the end of the process (timing purpose) Return: ret : error code )pbdoc") - .def_property( - "name", [](pyProcessInfo &p) { return std::string(p->name); }, - [](pyProcessInfo &p, std::string name) { - strncpy(p->name, name.c_str(), sizeof(p->name)); - }, - "Name of the Process Info object") - - .def_property( - "source_FUNCTION", - [](pyProcessInfo &p) { return std::string(p->source_FUNCTION); }, - [](pyProcessInfo &p, std::string source_FUNCTION) { - strncpy(p->source_FUNCTION, source_FUNCTION.c_str(), - sizeof(p->source_FUNCTION)); - }) - - .def_property( - "source_FILE", - [](pyProcessInfo &p) { return std::string(p->source_FILE); }, - [](pyProcessInfo &p, std::string source_FILE) { - strncpy(p->source_FILE, source_FILE.c_str(), - sizeof(p->source_FILE)); - }) - .def_property( - "source_LINE", [](pyProcessInfo &p) { return p->source_LINE; }, - [](pyProcessInfo &p, int source_LINE) { - p->source_LINE = source_LINE; - }) - .def_property( - "PID", [](pyProcessInfo &p) { return p->PID; }, - [](pyProcessInfo &p, int PID) { p->PID = PID; }) - - .def_property( - "createtime", [](pyProcessInfo &p) { return p->createtime; }, - [](pyProcessInfo &p, timespec createtime) { - p->createtime = createtime; - }) - .def_property( - "loopcnt", [](pyProcessInfo &p) { return p->loopcnt; }, - [](pyProcessInfo &p, int loopcnt) { p->loopcnt = loopcnt; }) - .def_property( - "CTRLval", [](pyProcessInfo &p) { return p->CTRLval; }, - [](pyProcessInfo &p, int CTRLval) { p->CTRLval = CTRLval; }) - .def_property( - "tmuxname", [](pyProcessInfo &p) { return std::string(p->tmuxname); }, - [](pyProcessInfo &p, std::string name) { - strncpy(p->tmuxname, name.c_str(), sizeof(p->tmuxname)); - }) - .def_property( - "loopstat", [](pyProcessInfo &p) { return p->loopstat; }, - [](pyProcessInfo &p, int loopstat) { p->loopstat = loopstat; }) - .def_property( - "statusmsg", - [](pyProcessInfo &p) { return std::string(p->statusmsg); }, - [](pyProcessInfo &p, std::string name) { - strncpy(p->statusmsg, name.c_str(), sizeof(p->statusmsg)); - }) - .def_property( - "statuscode", [](pyProcessInfo &p) { return p->statuscode; }, - [](pyProcessInfo &p, int statuscode) { p->statuscode = statuscode; }) - // .def_readwrite("logFile", &pyProcessInfo::m_pinfo::logFile) - .def_property( - "description", - [](pyProcessInfo &p) { return std::string(p->description); }, - [](pyProcessInfo &p, std::string name) { - strncpy(p->description, name.c_str(), sizeof(p->description)); - }); - - py::class_(m, "fps") - // read-only constructor - .def(py::init(), - R"pbdoc(Read / connect to existing shared memory FPS + .def_property( + "name", [](pyProcessInfo &p) { return std::string(p->name); }, + [](pyProcessInfo &p, std::string name) { strncpy(p->name, name.c_str(), sizeof(p->name)); }, + "Name of the Process Info object") + + .def_property( + "source_FUNCTION", [](pyProcessInfo &p) { return std::string(p->source_FUNCTION); }, + [](pyProcessInfo &p, std::string source_FUNCTION) { + strncpy(p->source_FUNCTION, source_FUNCTION.c_str(), sizeof(p->source_FUNCTION)); + }) + + .def_property( + "source_FILE", [](pyProcessInfo &p) { return std::string(p->source_FILE); }, + [](pyProcessInfo &p, std::string source_FILE) { + strncpy(p->source_FILE, source_FILE.c_str(), sizeof(p->source_FILE)); + }) + .def_property( + "source_LINE", [](pyProcessInfo &p) { return p->source_LINE; }, + [](pyProcessInfo &p, int source_LINE) { p->source_LINE = source_LINE; }) + .def_property( + "PID", [](pyProcessInfo &p) { return p->PID; }, [](pyProcessInfo &p, int PID) { p->PID = PID; }) + + .def_property( + "createtime", [](pyProcessInfo &p) { return p->createtime; }, + [](pyProcessInfo &p, timespec createtime) { p->createtime = createtime; }) + .def_property( + "loopcnt", [](pyProcessInfo &p) { return p->loopcnt; }, + [](pyProcessInfo &p, int loopcnt) { p->loopcnt = loopcnt; }) + .def_property( + "CTRLval", [](pyProcessInfo &p) { return p->CTRLval; }, + [](pyProcessInfo &p, int CTRLval) { p->CTRLval = CTRLval; }) + .def_property( + "tmuxname", [](pyProcessInfo &p) { return std::string(p->tmuxname); }, + [](pyProcessInfo &p, std::string name) { strncpy(p->tmuxname, name.c_str(), sizeof(p->tmuxname)); }) + .def_property( + "loopstat", [](pyProcessInfo &p) { return p->loopstat; }, + [](pyProcessInfo &p, int loopstat) { p->loopstat = loopstat; }) + .def_property( + "statusmsg", [](pyProcessInfo &p) { return std::string(p->statusmsg); }, + [](pyProcessInfo &p, std::string name) { strncpy(p->statusmsg, name.c_str(), sizeof(p->statusmsg)); }) + .def_property( + "statuscode", [](pyProcessInfo &p) { return p->statuscode; }, + [](pyProcessInfo &p, int statuscode) { p->statuscode = statuscode; }) + // .def_readwrite("logFile", &pyProcessInfo::m_pinfo::logFile) + .def_property( + "description", [](pyProcessInfo &p) { return std::string(p->description); }, + [](pyProcessInfo &p, std::string name) { strncpy(p->description, name.c_str(), sizeof(p->description)); }); + + py::class_(m, "fps") + // read-only constructor + .def(py::init(), + R"pbdoc(Read / connect to existing shared memory FPS Parameters: name [in]: the name of the shared memory file to connect )pbdoc", - py::arg("name")) + py::arg("name")) - // read/write constructor - .def(py::init(), - R"pbdoc(Read / connect to existing shared memory FPS + // read/write constructor + .def(py::init(), + R"pbdoc(Read / connect to existing shared memory FPS Parameters: name [in]: the name of the shared memory file to connect create [in]: flag for creating of shared memory identifier NBparamMAX [in]: Max number of parameters )pbdoc", - py::arg("name"), py::arg("create"), - py::arg("NBparamMAX") = FUNCTION_PARAMETER_NBPARAM_DEFAULT) + py::arg("name"), py::arg("create"), py::arg("NBparamMAX") = FUNCTION_PARAMETER_NBPARAM_DEFAULT) - .def("asdict", &fps_to_dict) + .def("asdict", &fps_to_dict) - .def("__getitem__", - [](pyFps &cls, const std::string &key) { - return fps_value_from_key(cls, key, cls.keys(key)); - }) + .def("__getitem__", + [](pyFps &cls, const std::string &key) { return fps_value_from_key(cls, key, cls.keys(key)); }) - .def("__setitem__", - [](pyFps &cls, const std::string &key, py::object value) { - return fps_value_to_key(cls, key, cls.keys(key), value); - }) + .def("__setitem__", [](pyFps &cls, const std::string &key, + py::object value) { return fps_value_to_key(cls, key, cls.keys(key), value); }) - .def("md", &pyFps::md, py::return_value_policy::reference) + .def("md", &pyFps::md, py::return_value_policy::reference) - .def("add_entry", &pyFps::add_entry, - R"pbdoc(Add parameter to database with default settings + .def("add_entry", &pyFps::add_entry, + R"pbdoc(Add parameter to database with default settings If entry already exists, do not modify it @@ -318,75 +293,67 @@ If entry already exists, do not modify it create [in]: flag for creating of shared memory identifier NBparamMAX [in]: Max number of parameters )pbdoc", - py::arg("entry_name"), py::arg("entry_desc"), py::arg("fptype")) + py::arg("entry_name"), py::arg("entry_desc"), py::arg("fptype")) - .def("get_status", &pyFps::get_status) - .def("set_status", &pyFps::set_status) + .def("get_status", &pyFps::get_status) + .def("set_status", &pyFps::set_status) - .def("get_levelKeys", &pyFps::get_levelKeys) + .def("get_levelKeys", &pyFps::get_levelKeys) - .def( - "get_param_value_int", - [](pyFps &cls, std::string key) { - return functionparameter_GetParamValue_INT64(cls, key.c_str()); - }, - R"pbdoc(Get the int64 value of the FPS key + .def( + "get_param_value_int", + [](pyFps &cls, std::string key) { return functionparameter_GetParamValue_INT64(cls, key.c_str()); }, + R"pbdoc(Get the int64 value of the FPS key Parameters: key [in]: Parameter name Return: ret [out]: parameter value )pbdoc", - py::arg("key")) + py::arg("key")) - .def( - "get_param_value_float", - [](pyFps &cls, std::string key) { - return functionparameter_GetParamValue_FLOAT32(cls, key.c_str()); - }, - R"pbdoc(Get the float32 value of the FPS key + .def( + "get_param_value_float", + [](pyFps &cls, std::string key) { return functionparameter_GetParamValue_FLOAT32(cls, key.c_str()); }, + R"pbdoc(Get the float32 value of the FPS key Parameters: key [in]: Parameter name Return: ret [out]: parameter value )pbdoc", - py::arg("key")) - .def( - "get_param_value_double", - [](pyFps &cls, std::string key) { - return functionparameter_GetParamValue_FLOAT64(cls, key.c_str()); - }, - R"pbdoc(Get the float64 value of the FPS key + py::arg("key")) + .def( + "get_param_value_double", + [](pyFps &cls, std::string key) { return functionparameter_GetParamValue_FLOAT64(cls, key.c_str()); }, + R"pbdoc(Get the float64 value of the FPS key Parameters: key [in]: Parameter name Return: ret [out]: parameter value )pbdoc", - py::arg("key")) - .def( - "get_param_value_string", - [](pyFps &cls, std::string key) { - return std::string( - functionparameter_GetParamPtr_STRING(cls, key.c_str())); - }, - R"pbdoc(Get the string value of the FPS key + py::arg("key")) + .def( + "get_param_value_string", + [](pyFps &cls, std::string key) { + return std::string(functionparameter_GetParamPtr_STRING(cls, key.c_str())); + }, + R"pbdoc(Get the string value of the FPS key Parameters: key [in]: Parameter name Return: ret [out]: parameter value )pbdoc", - py::arg("key")) + py::arg("key")) - .def( - "set_param_value_int", - [](pyFps &cls, std::string key, std::string value) { - return functionparameter_SetParamValue_INT64(cls, key.c_str(), - std::stol(value)); - }, - R"pbdoc(Set the int64 value of the FPS key + .def( + "set_param_value_int", + [](pyFps &cls, std::string key, std::string value) { + return functionparameter_SetParamValue_INT64(cls, key.c_str(), std::stol(value)); + }, + R"pbdoc(Set the int64 value of the FPS key Parameters: key [in]: Parameter name @@ -394,14 +361,13 @@ If entry already exists, do not modify it Return: ret [out]: error code )pbdoc", - py::arg("key"), py::arg("value")) - .def( - "set_param_value_float", - [](pyFps &cls, std::string key, std::string value) { - return functionparameter_SetParamValue_FLOAT32(cls, key.c_str(), - std::stol(value)); - }, - R"pbdoc(Set the float32 value of the FPS key + py::arg("key"), py::arg("value")) + .def( + "set_param_value_float", + [](pyFps &cls, std::string key, std::string value) { + return functionparameter_SetParamValue_FLOAT32(cls, key.c_str(), std::stol(value)); + }, + R"pbdoc(Set the float32 value of the FPS key Parameters: key [in]: Parameter name @@ -409,14 +375,13 @@ If entry already exists, do not modify it Return: ret [out]: error code )pbdoc", - py::arg("key"), py::arg("value")) - .def( - "set_param_value_double", - [](pyFps &cls, std::string key, std::string value) { - return functionparameter_SetParamValue_FLOAT64(cls, key.c_str(), - std::stol(value)); - }, - R"pbdoc(Set the float64 value of the FPS key + py::arg("key"), py::arg("value")) + .def( + "set_param_value_double", + [](pyFps &cls, std::string key, std::string value) { + return functionparameter_SetParamValue_FLOAT64(cls, key.c_str(), std::stol(value)); + }, + R"pbdoc(Set the float64 value of the FPS key Parameters: key [in]: Parameter name @@ -424,14 +389,13 @@ If entry already exists, do not modify it Return: ret [out]: error code )pbdoc", - py::arg("key"), py::arg("value")) - .def( - "set_param_value_string", - [](pyFps &cls, std::string key, std::string value) { - return functionparameter_SetParamValue_STRING(cls, key.c_str(), - value.c_str()); - }, - R"pbdoc(Set the string value of the FPS key + py::arg("key"), py::arg("value")) + .def( + "set_param_value_string", + [](pyFps &cls, std::string key, std::string value) { + return functionparameter_SetParamValue_STRING(cls, key.c_str(), value.c_str()); + }, + R"pbdoc(Set the string value of the FPS key Parameters: key [in]: Parameter name @@ -439,12 +403,12 @@ If entry already exists, do not modify it Return: ret [out]: error code )pbdoc", - py::arg("key"), py::arg("value")) + py::arg("key"), py::arg("value")) - .def_property_readonly("keys", [](pyFps &cls) { return cls.keys(); }) + .def_property_readonly("keys", [](pyFps &cls) { return cls.keys(); }) - .def("CONFstart", &pyFps::CONFstart, - R"pbdoc(FPS start CONF process + .def("CONFstart", &pyFps::CONFstart, + R"pbdoc(FPS start CONF process Requires setup performed by milk-fpsinit, which performs the following setup - creates the FPS shared memory @@ -455,36 +419,36 @@ Requires setup performed by milk-fpsinit, which performs the following setup ret [out]: error code )pbdoc") - .def("CONFstop", &pyFps::CONFstop, - R"pbdoc(FPS stop CONF process + .def("CONFstop", &pyFps::CONFstop, + R"pbdoc(FPS stop CONF process Return: ret [out]: error code )pbdoc") - .def("FPCONFexit", &pyFps::FPCONFexit, - R"pbdoc(FPS exit FPCONF process + .def("FPCONFexit", &pyFps::FPCONFexit, + R"pbdoc(FPS exit FPCONF process Return: ret [out]: error code )pbdoc") - // .def("FPCONFsetup", &pyFps::FPCONFsetup, - // R"pbdoc(FPS setup FPCONF process + // .def("FPCONFsetup", &pyFps::FPCONFsetup, + // R"pbdoc(FPS setup FPCONF process - // Return: - // ret [out]: error code - // )pbdoc") + // Return: + // ret [out]: error code + // )pbdoc") - .def("FPCONFloopstep", &pyFps::FPCONFloopstep, - R"pbdoc(FPS loop step FPCONF process + .def("FPCONFloopstep", &pyFps::FPCONFloopstep, + R"pbdoc(FPS loop step FPCONF process Return: ret [out]: error code )pbdoc") - .def("RUNstart", &pyFps::RUNstart, - R"pbdoc(FPS start RUN process + .def("RUNstart", &pyFps::RUNstart, + R"pbdoc(FPS start RUN process Requires setup performed by milk-fpsinit, which performs the following setup - creates the FPS shared memory @@ -495,8 +459,8 @@ Requires setup performed by milk-fpsinit, which performs the following setup ret [out]: error code )pbdoc") - .def("RUNstop", &pyFps::RUNstop, - R"pbdoc(FPS stop RUN process + .def("RUNstop", &pyFps::RUNstop, + R"pbdoc(FPS stop RUN process Run pre-set function fpsrunstop in tmux ctrl window @@ -504,89 +468,97 @@ Requires setup performed by milk-fpsinit, which performs the following setup ret [out]: error code )pbdoc") - .def("RUNexit", &pyFps::RUNexit, - R"pbdoc(FPS exit RUN process + .def("RUNexit", &pyFps::RUNexit, + R"pbdoc(FPS exit RUN process Return: ret [out]: error code )pbdoc") - // Test if CONF process is running - - .def_property_readonly( - "CONFrunning", - [](pyFps &cls) { - pid_t pid = cls->md->confpid; - if ((getpgid(pid) >= 0) && (pid > 0)) { - return 1; - } else // PID not active - { - if (cls->md->status & FUNCTION_PARAMETER_STRUCT_STATUS_CMDCONF) { - // not clean exit - return -1; - } else { - return 0; - } - } - }, - R"pbdoc(Test if CONF process is running + // Test if CONF process is running + + .def_property_readonly( + "CONFrunning", + [](pyFps &cls) { + pid_t pid = cls->md->confpid; + if ((getpgid(pid) >= 0) && (pid > 0)) + { + return 1; + } + else // PID not active + { + if (cls->md->status & FUNCTION_PARAMETER_STRUCT_STATUS_CMDCONF) + { + // not clean exit + return -1; + } + else + { + return 0; + } + } + }, + R"pbdoc(Test if CONF process is running Return: ret [out]: CONF process is running or not )pbdoc") - .def_property_readonly( - "RUNrunning", - [](pyFps &cls) { - pid_t pid = cls->md->runpid; - if ((getpgid(pid) >= 0) && (pid > 0)) { - return 1; - } else // PID not active - { - if (cls->md->status & FUNCTION_PARAMETER_STRUCT_STATUS_CMDRUN) { - // not clean exit - return -1; - } else { - return 0; - } - } - }, - R"pbdoc(Test if RUN process is running + .def_property_readonly( + "RUNrunning", + [](pyFps &cls) { + pid_t pid = cls->md->runpid; + if ((getpgid(pid) >= 0) && (pid > 0)) + { + return 1; + } + else // PID not active + { + if (cls->md->status & FUNCTION_PARAMETER_STRUCT_STATUS_CMDRUN) + { + // not clean exit + return -1; + } + else + { + return 0; + } + } + }, + R"pbdoc(Test if RUN process is running Return: ret [out]: RUN process is running or not )pbdoc") - ; - py::class_(m, "FPS_md") - // .def(py::init([]() { - // return std::unique_ptr(new - // FUNCTION_PARAMETER_STRUCT_MD()); - // })) - .def_readonly("name", &FUNCTION_PARAMETER_STRUCT_MD::name) - .def_readonly("description", &FUNCTION_PARAMETER_STRUCT_MD::description) - .def_readonly("workdir", &FUNCTION_PARAMETER_STRUCT_MD::workdir) - .def_readonly("datadir", &FUNCTION_PARAMETER_STRUCT_MD::datadir) - .def_readonly("confdir", &FUNCTION_PARAMETER_STRUCT_MD::confdir) - .def_readonly("sourcefname", &FUNCTION_PARAMETER_STRUCT_MD::sourcefname) - .def_readonly("sourceline", &FUNCTION_PARAMETER_STRUCT_MD::sourceline) - .def_readonly("pname", &FUNCTION_PARAMETER_STRUCT_MD::pname) - .def_readonly("callprogname", &FUNCTION_PARAMETER_STRUCT_MD::callprogname) - // .def_readonly("nameindexW", - // &FUNCTION_PARAMETER_STRUCT_MD::nameindexW) - .def_readonly("NBnameindex", &FUNCTION_PARAMETER_STRUCT_MD::NBnameindex) - .def_readonly("confpid", &FUNCTION_PARAMETER_STRUCT_MD::confpid) - .def_readonly("confpidstarttime", - &FUNCTION_PARAMETER_STRUCT_MD::confpidstarttime) - .def_readonly("runpid", &FUNCTION_PARAMETER_STRUCT_MD::runpid) - .def_readonly("runpidstarttime", - &FUNCTION_PARAMETER_STRUCT_MD::runpidstarttime) - .def_readonly("signal", &FUNCTION_PARAMETER_STRUCT_MD::signal) - .def_readonly("confwaitus", &FUNCTION_PARAMETER_STRUCT_MD::confwaitus) - .def_readonly("status", &FUNCTION_PARAMETER_STRUCT_MD::status) - .def_readonly("NBparamMAX", &FUNCTION_PARAMETER_STRUCT_MD::NBparamMAX) - // .def_readonly("message", &FUNCTION_PARAMETER_STRUCT_MD::message) - .def_readonly("msgpindex", &FUNCTION_PARAMETER_STRUCT_MD::msgpindex) - .def_readonly("msgcode", &FUNCTION_PARAMETER_STRUCT_MD::msgcode) - .def_readonly("msgcnt", &FUNCTION_PARAMETER_STRUCT_MD::msgcnt) - .def_readonly("conferrcnt", &FUNCTION_PARAMETER_STRUCT_MD::conferrcnt); + ; + py::class_(m, "FPS_md") + // .def(py::init([]() { + // return std::unique_ptr(new + // FUNCTION_PARAMETER_STRUCT_MD()); + // })) + .def_readonly("name", &FUNCTION_PARAMETER_STRUCT_MD::name) + .def_readonly("description", &FUNCTION_PARAMETER_STRUCT_MD::description) + .def_readonly("workdir", &FUNCTION_PARAMETER_STRUCT_MD::workdir) + .def_readonly("datadir", &FUNCTION_PARAMETER_STRUCT_MD::datadir) + .def_readonly("confdir", &FUNCTION_PARAMETER_STRUCT_MD::confdir) + .def_readonly("sourcefname", &FUNCTION_PARAMETER_STRUCT_MD::sourcefname) + .def_readonly("sourceline", &FUNCTION_PARAMETER_STRUCT_MD::sourceline) + .def_readonly("pname", &FUNCTION_PARAMETER_STRUCT_MD::pname) + .def_readonly("callprogname", &FUNCTION_PARAMETER_STRUCT_MD::callprogname) + // .def_readonly("nameindexW", + // &FUNCTION_PARAMETER_STRUCT_MD::nameindexW) + .def_readonly("NBnameindex", &FUNCTION_PARAMETER_STRUCT_MD::NBnameindex) + .def_readonly("confpid", &FUNCTION_PARAMETER_STRUCT_MD::confpid) + .def_readonly("confpidstarttime", &FUNCTION_PARAMETER_STRUCT_MD::confpidstarttime) + .def_readonly("runpid", &FUNCTION_PARAMETER_STRUCT_MD::runpid) + .def_readonly("runpidstarttime", &FUNCTION_PARAMETER_STRUCT_MD::runpidstarttime) + .def_readonly("signal", &FUNCTION_PARAMETER_STRUCT_MD::signal) + .def_readonly("confwaitus", &FUNCTION_PARAMETER_STRUCT_MD::confwaitus) + .def_readonly("status", &FUNCTION_PARAMETER_STRUCT_MD::status) + .def_readonly("NBparamMAX", &FUNCTION_PARAMETER_STRUCT_MD::NBparamMAX) + // .def_readonly("message", &FUNCTION_PARAMETER_STRUCT_MD::message) + .def_readonly("msgpindex", &FUNCTION_PARAMETER_STRUCT_MD::msgpindex) + .def_readonly("msgcode", &FUNCTION_PARAMETER_STRUCT_MD::msgcode) + .def_readonly("msgcnt", &FUNCTION_PARAMETER_STRUCT_MD::msgcnt) + .def_readonly("conferrcnt", &FUNCTION_PARAMETER_STRUCT_MD::conferrcnt); } diff --git a/python_module/pyFps.hpp b/python_module/pyFps.hpp index 0792460d..291745d1 100644 --- a/python_module/pyFps.hpp +++ b/python_module/pyFps.hpp @@ -1,7 +1,8 @@ #ifndef PYFPS_H #define PYFPS_H -extern "C" { +extern "C" +{ #include "CLIcore.h" #include "CLIcore_datainit.h" #include "fps_CONFstart.h" @@ -18,139 +19,148 @@ extern "C" { * */ -enum FPS_status : uint32_t { - CONF = FUNCTION_PARAMETER_STRUCT_STATUS_CONF, - RUN = FUNCTION_PARAMETER_STRUCT_STATUS_RUN, - CMDCONF = FUNCTION_PARAMETER_STRUCT_STATUS_CMDCONF, - CMDRUN = FUNCTION_PARAMETER_STRUCT_STATUS_CMDRUN, - RUNLOOP = FUNCTION_PARAMETER_STRUCT_STATUS_RUNLOOP, - CHECKOK = FUNCTION_PARAMETER_STRUCT_STATUS_CHECKOK, - TMUXCONF = FUNCTION_PARAMETER_STRUCT_STATUS_TMUXCONF, - TMUXRUN = FUNCTION_PARAMETER_STRUCT_STATUS_TMUXRUN, - TMUXCTRL = FUNCTION_PARAMETER_STRUCT_STATUS_TMUXCTRL +enum FPS_status : uint32_t +{ + CONF = FUNCTION_PARAMETER_STRUCT_STATUS_CONF, + RUN = FUNCTION_PARAMETER_STRUCT_STATUS_RUN, + CMDCONF = FUNCTION_PARAMETER_STRUCT_STATUS_CMDCONF, + CMDRUN = FUNCTION_PARAMETER_STRUCT_STATUS_CMDRUN, + RUNLOOP = FUNCTION_PARAMETER_STRUCT_STATUS_RUNLOOP, + CHECKOK = FUNCTION_PARAMETER_STRUCT_STATUS_CHECKOK, + TMUXCONF = FUNCTION_PARAMETER_STRUCT_STATUS_TMUXCONF, + TMUXRUN = FUNCTION_PARAMETER_STRUCT_STATUS_TMUXRUN, + TMUXCTRL = FUNCTION_PARAMETER_STRUCT_STATUS_TMUXCTRL }; -enum FPS_type : uint32_t { - AUTO = FPTYPE_AUTO, - UNDEF = FPTYPE_UNDEF, - INT32 = FPTYPE_INT32, - UINT32 = FPTYPE_UINT32, - INT64 = FPTYPE_INT64, - UINT64 = FPTYPE_UINT64, - FLOAT32 = FPTYPE_FLOAT32, - FLOAT64 = FPTYPE_FLOAT64, - PID = FPTYPE_PID, - TIMESPEC = FPTYPE_TIMESPEC, - FILENAME = FPTYPE_FILENAME, - FITSFILENAME = FPTYPE_FITSFILENAME, - EXECFILENAME = FPTYPE_EXECFILENAME, - DIRNAME = FPTYPE_DIRNAME, - STREAMNAME = FPTYPE_STREAMNAME, - STRING = FPTYPE_STRING, - ONOFF = FPTYPE_ONOFF, - PROCESS = FPTYPE_PROCESS, - FPSNAME = FPTYPE_FPSNAME, +enum FPS_type : uint32_t +{ + AUTO = FPTYPE_AUTO, + UNDEF = FPTYPE_UNDEF, + INT32 = FPTYPE_INT32, + UINT32 = FPTYPE_UINT32, + INT64 = FPTYPE_INT64, + UINT64 = FPTYPE_UINT64, + FLOAT32 = FPTYPE_FLOAT32, + FLOAT64 = FPTYPE_FLOAT64, + PID = FPTYPE_PID, + TIMESPEC = FPTYPE_TIMESPEC, + FILENAME = FPTYPE_FILENAME, + FITSFILENAME = FPTYPE_FITSFILENAME, + EXECFILENAME = FPTYPE_EXECFILENAME, + DIRNAME = FPTYPE_DIRNAME, + STREAMNAME = FPTYPE_STREAMNAME, + STRING = FPTYPE_STRING, + ONOFF = FPTYPE_ONOFF, + PROCESS = FPTYPE_PROCESS, + FPSNAME = FPTYPE_FPSNAME, }; -class pyFps { - std::string name_; - FUNCTION_PARAMETER_STRUCT fps_; - std::map keys_; - - int read_keys() { - int k = 0; - while ((k < fps_.md->NBparamMAX) && - (fps_.parray[k].keywordfull[0] != '\0')) { - int offset = strlen(fps_.parray[k].keyword[0]) + 1; - char *key = fps_.parray[k].keywordfull + offset; - keys_[key] = static_cast(fps_.parray[k].type); - k++; - } - - return EXIT_SUCCESS; - }; - - public: - /** +class pyFps +{ + std::string name_; + FUNCTION_PARAMETER_STRUCT fps_; + std::map keys_; + + int read_keys() + { + int k = 0; + while ((k < fps_.md->NBparamMAX) && (fps_.parray[k].keywordfull[0] != '\0')) + { + int offset = strlen(fps_.parray[k].keyword[0]) + 1; + char *key = fps_.parray[k].keywordfull + offset; + keys_[key] = static_cast(fps_.parray[k].type); + k++; + } + + return EXIT_SUCCESS; + }; + + public: + /** * @brief Read / connect to existing shared memory FPS * @param name : the name of the shared memory file to connect */ - pyFps(std::string name) - : pyFps(name, false, FUNCTION_PARAMETER_NBPARAM_DEFAULT){}; + pyFps(std::string name) : pyFps(name, false, FUNCTION_PARAMETER_NBPARAM_DEFAULT){}; - /** + /** * @brief Read or create an shared FPS * * @param fps_name : the name of the shared memory file to connect * @param create : flag for creating of shared memory identifier * @param NBparamMAX : Max number of parameters */ - pyFps(std::string fps_name, bool create, int NBparamMAX) : name_(fps_name) { - fps_.md = nullptr; - fps_.parray = nullptr; // array of function parameters - - // these variables are local to each process - fps_.localstatus = 0; // 1 if conf loop should be active - fps_.SMfd = -1; - fps_.CMDmode = 0; - - fps_.NBparam = 0; // number of parameters in array - fps_.NBparamActive = 0; // number of active parameters - - if (create) { - create_and_connect(NBparamMAX); - } else { - if (connect() == -1) { - throw std::runtime_error("FPS does not exist"); - } - read_keys(); + pyFps(std::string fps_name, bool create, int NBparamMAX) : name_(fps_name) + { + fps_.md = nullptr; + fps_.parray = nullptr; // array of function parameters + + // these variables are local to each process + fps_.localstatus = 0; // 1 if conf loop should be active + fps_.SMfd = -1; + fps_.CMDmode = 0; + + fps_.NBparam = 0; // number of parameters in array + fps_.NBparamActive = 0; // number of active parameters + + if (create) + { + create_and_connect(NBparamMAX); + } + else + { + if (connect() == -1) + { + throw std::runtime_error("FPS does not exist"); + } + read_keys(); + } + std::cout << "FPS connected" << std::endl; } - std::cout << "FPS connected" << std::endl; - } - /** + /** * @brief Destroy the py Fps object * */ - ~pyFps() = default; + ~pyFps() = default; - FUNCTION_PARAMETER_STRUCT *operator->() { return &fps_; } - operator FUNCTION_PARAMETER_STRUCT *() { return &fps_; } - const FUNCTION_PARAMETER_STRUCT_MD *md() const { return fps_.md; } - const std::map &keys() { return keys_; } - const FPS_type keys(const std::string &key) { return keys_[key]; } + FUNCTION_PARAMETER_STRUCT *operator->() { return &fps_; } + operator FUNCTION_PARAMETER_STRUCT *() { return &fps_; } + const FUNCTION_PARAMETER_STRUCT_MD *md() const { return fps_.md; } + const std::map &keys() { return keys_; } + const FPS_type keys(const std::string &key) { return keys_[key]; } - /** + /** * @brief Create a and connect object * * @param NBparamMAX * @return int */ - int create_and_connect(int NBparamMAX) { - if (connect() == -1) { - std::cout << "Creating FPS..."; - function_parameter_struct_create(NBparamMAX, name_.c_str()); - std::cout << "Done" << std::endl; - connect(); - } else { - connect(); - read_keys(); + int create_and_connect(int NBparamMAX) + { + if (connect() == -1) + { + std::cout << "Creating FPS..."; + function_parameter_struct_create(NBparamMAX, name_.c_str()); + std::cout << "Done" << std::endl; + connect(); + } + else + { + connect(); + read_keys(); + } + return EXIT_SUCCESS; } - return EXIT_SUCCESS; - } - /** + /** * @brief Connect to existing shared memory FPS * @param name : the name of the shared memory file to connect */ - int connect() { - return function_parameter_struct_connect(name_.c_str(), &fps_, - FPSCONNECT_SIMPLE); - }; + int connect() { return function_parameter_struct_connect(name_.c_str(), &fps_, FPSCONNECT_SIMPLE); }; - /** + /** * @brief Add parameter to database with default settings * * If entry already exists, do not modify it @@ -160,70 +170,73 @@ class pyFps { * @param fptype : entry type ("int","double","float","string") * @return int */ - int add_entry(std::string entry_name, std::string entry_desc, - uint32_t fptype) { - keys_[entry_name] = static_cast(fptype); - return function_parameter_add_entry(&fps_, entry_name.c_str(), - entry_desc.c_str(), fptype, - FPFLAG_DEFAULT_INPUT, nullptr); - } - - /** + int add_entry(std::string entry_name, std::string entry_desc, uint32_t fptype) + { + keys_[entry_name] = static_cast(fptype); + return function_parameter_add_entry(&fps_, entry_name.c_str(), entry_desc.c_str(), fptype, FPFLAG_DEFAULT_INPUT, + nullptr); + } + + /** * @brief Get the status object * * @return int */ - int get_status() { return fps_.md->status; } + int get_status() { return fps_.md->status; } - /** + /** * @brief Set the status object * * @param status * @return int */ - int set_status(int status) { - fps_.md->status = status; - return EXIT_SUCCESS; - } + int set_status(int status) + { + fps_.md->status = status; + return EXIT_SUCCESS; + } - /** + /** * @brief Get the levelKeys object * * @param level * @return std::vector */ - std::vector get_levelKeys(int level) { - std::vector levelKeys = std::vector(); - int k = 0; - while (fps_.parray[k].keywordfull[0] != '\0' && k < fps_.md->NBparamMAX) { - std::string tmp = fps_.parray[k].keyword[level]; - auto exist = std::find(levelKeys.begin(), levelKeys.end(), tmp); - if (exist == levelKeys.end()) { - levelKeys.push_back(tmp); - } - k++; + std::vector get_levelKeys(int level) + { + std::vector levelKeys = std::vector(); + int k = 0; + while (fps_.parray[k].keywordfull[0] != '\0' && k < fps_.md->NBparamMAX) + { + std::string tmp = fps_.parray[k].keyword[level]; + auto exist = std::find(levelKeys.begin(), levelKeys.end(), tmp); + if (exist == levelKeys.end()) + { + levelKeys.push_back(tmp); + } + k++; + } + + return levelKeys; } - return levelKeys; - } - - errno_t CONFstart() { return functionparameter_CONFstart(&fps_); } + errno_t CONFstart() { return functionparameter_CONFstart(&fps_); } - errno_t CONFstop() { return functionparameter_CONFstop(&fps_); } + errno_t CONFstop() { return functionparameter_CONFstop(&fps_); } - errno_t FPCONFexit() { return function_parameter_FPCONFexit(&fps_); } + errno_t FPCONFexit() { return function_parameter_FPCONFexit(&fps_); } - // errno_t FPCONFsetup(){ - // return function_parameter_FPCONFsetup(&fps_); - // } + // errno_t FPCONFsetup(){ + // return function_parameter_FPCONFsetup(&fps_); + // } - errno_t FPCONFloopstep() { return function_parameter_FPCONFloopstep(&fps_); } + errno_t FPCONFloopstep() { return function_parameter_FPCONFloopstep(&fps_); } - errno_t RUNstart() { return functionparameter_RUNstart(&fps_); } + errno_t RUNstart() { return functionparameter_RUNstart(&fps_); } - errno_t RUNstop() { return functionparameter_RUNstop(&fps_); } + errno_t RUNstop() { return functionparameter_RUNstop(&fps_); } - errno_t RUNexit() { return function_parameter_RUNexit(&fps_); } + errno_t RUNexit() { return function_parameter_RUNexit(&fps_); } }; #endif diff --git a/python_module/pyProcessInfo.hpp b/python_module/pyProcessInfo.hpp index c63a61ef..6cdfeb43 100644 --- a/python_module/pyProcessInfo.hpp +++ b/python_module/pyProcessInfo.hpp @@ -2,25 +2,27 @@ #ifndef PYPROCESSINFO_H #define PYPROCESSINFO_H -extern "C" { +extern "C" +{ #include "CLIcore.h" #include "CLIcore_datainit.h" #include "processinfo.h" #include "processtools.h" } -class pyProcessInfo { - PROCESSINFO *m_pinfo; - int m_fd; +class pyProcessInfo +{ + PROCESSINFO *m_pinfo; + int m_fd; - public: - /** + public: + /** * @brief Construct a empty Process Info object * */ - pyProcessInfo() : m_pinfo(nullptr) {} + pyProcessInfo() : m_pinfo(nullptr) {} - /** + /** * @brief Construct a new Process Info object * * @param pname : name of the Process Info object (human-readable) @@ -30,22 +32,24 @@ class pyProcessInfo { * - 2: increment single step (will go back to 1) * - 3: exit loop */ - pyProcessInfo(char *pname, int CTRLval) { create(pname, CTRLval); } + pyProcessInfo(char *pname, int CTRLval) { create(pname, CTRLval); } - /** + /** * @brief Destroy the Process Info object * */ - ~pyProcessInfo() { - if (m_pinfo != nullptr) { - processinfo_cleanExit(m_pinfo); - m_pinfo = nullptr; + ~pyProcessInfo() + { + if (m_pinfo != nullptr) + { + processinfo_cleanExit(m_pinfo); + m_pinfo = nullptr; + } } - } - PROCESSINFO *operator->() { return m_pinfo; } + PROCESSINFO *operator->() { return m_pinfo; } - /** + /** * @brief Create Process Info object in shared memory * * The structure holds real-time information about a process, so its status can be monitored and controlled @@ -59,21 +63,22 @@ class pyProcessInfo { * - 3: exit loop * @return int : error code */ - int create(char *pname, int CTRLval) { - // if (m_pinfo != nullptr) { - // processinfo_cleanExit(m_pinfo); - // } - m_pinfo = processinfo_shm_create(pname, CTRLval); - m_pinfo->loopstat = 0; // loop initialization - strcpy(m_pinfo->source_FUNCTION, "\0"); - strcpy(m_pinfo->source_FILE, "\0"); - m_pinfo->source_LINE = 0; - strcpy(m_pinfo->description, "\0"); - writeMessage("initialization done"); - return EXIT_SUCCESS; - } + int create(char *pname, int CTRLval) + { + // if (m_pinfo != nullptr) { + // processinfo_cleanExit(m_pinfo); + // } + m_pinfo = processinfo_shm_create(pname, CTRLval); + m_pinfo->loopstat = 0; // loop initialization + strcpy(m_pinfo->source_FUNCTION, "\0"); + strcpy(m_pinfo->source_FILE, "\0"); + m_pinfo->source_LINE = 0; + strcpy(m_pinfo->description, "\0"); + writeMessage("initialization done"); + return EXIT_SUCCESS; + } - /** + /** * @brief Link an existing Process Info object in shared memory * * The structure holds real-time information about a process, so its status can be monitored and controlled @@ -82,73 +87,83 @@ class pyProcessInfo { * @param pname : name of the Process Info object (human-readable) * @return int : error code */ - int link(char *pname){ - m_pinfo = processinfo_shm_link(pname, &m_fd); - return EXIT_SUCCESS; - } + int link(char *pname) + { + m_pinfo = processinfo_shm_link(pname, &m_fd); + return EXIT_SUCCESS; + } - /** + /** * @brief Close an existing Process Info object in shared memory * * @param pname : name of the Process Info object (human-readable) * @return int : error code */ - int close(char *pname){ - processinfo_shm_close(m_pinfo, m_fd); - return EXIT_SUCCESS; - } + int close(char *pname) + { + processinfo_shm_close(m_pinfo, m_fd); + return EXIT_SUCCESS; + } - /** + /** * @brief Send a signal to a Process Info object * * @param sig : signal to send * @return int : error code */ - int sigexit(int sig) { - if (m_pinfo != nullptr) { - int ret = processinfo_SIGexit(m_pinfo, sig); - m_pinfo = nullptr; - return ret; + int sigexit(int sig) + { + if (m_pinfo != nullptr) + { + int ret = processinfo_SIGexit(m_pinfo, sig); + m_pinfo = nullptr; + return ret; + } + return EXIT_FAILURE; } - return EXIT_FAILURE; - } - /** + /** * @brief Write a message into a Process Info object * * @param message : message to write * @return int : error code */ - int writeMessage(const char *message) { - if (m_pinfo != nullptr) { - return processinfo_WriteMessage(m_pinfo, message); - } - return EXIT_FAILURE; - }; + int writeMessage(const char *message) + { + if (m_pinfo != nullptr) + { + return processinfo_WriteMessage(m_pinfo, message); + } + return EXIT_FAILURE; + }; - /** + /** * @brief Define the start of the process (timing purpose) * * @return int : error code */ - int exec_start() { - if ( (m_pinfo != nullptr) && (m_pinfo->MeasureTiming==1) ) { - return processinfo_exec_start(m_pinfo); - } - return EXIT_FAILURE; - }; + int exec_start() + { + if ((m_pinfo != nullptr) && (m_pinfo->MeasureTiming == 1)) + { + return processinfo_exec_start(m_pinfo); + } + return EXIT_FAILURE; + }; - /** + /** * @brief Define the end of the process (timing purpose) * * @return int : error code */ - int exec_end() { - if ( (m_pinfo != nullptr) && (m_pinfo->MeasureTiming==1) ) { - return processinfo_exec_end(m_pinfo); - } - return EXIT_FAILURE; - }; + int exec_end() + { + if ((m_pinfo != nullptr) && (m_pinfo->MeasureTiming == 1)) + { + return processinfo_exec_end(m_pinfo); + } + return EXIT_FAILURE; + }; }; -#endif \ No newline at end of file +#endif diff --git a/scripts/merge3DfitsTelemetry b/scripts/merge3DfitsTelemetry index 34c2730f..c6e53128 100755 --- a/scripts/merge3DfitsTelemetry +++ b/scripts/merge3DfitsTelemetry @@ -3,12 +3,12 @@ EXPECTED_ARGS=3 if [ $# -ne $EXPECTED_ARGS ] then - echo - echo " ---------- merge 3D telemetry FITS cubes ----------- " - echo - echo " Usage: $0 " - echo - echo "looks for files ., xxx from 000 to number of files" + echo + echo " ---------- merge 3D telemetry FITS cubes ----------- " + echo + echo " Usage: $0 " + echo + echo "looks for files ., xxx from 000 to number of files" fi pname=$0 diff --git a/scripts/milk-FITS2shm b/scripts/milk-FITS2shm index 8998b905..f136ba33 100755 --- a/scripts/milk-FITS2shm +++ b/scripts/milk-FITS2shm @@ -8,47 +8,47 @@ VERBOSE="0" function printHELP { -echo "------------------------------------------------------------------------" -echo "$(tput bold) $pname : Copy FITS files to shared memory $(tput sgr0)" -echo "------------------------------------------------------------------------" -echo " Copy FITS file to shared memory" -echo " Writes into ./loadedSM/ what has been loaded" -echo " unless -f option, will not re-load unchanged files" -echo " " -echo " $(tput bold)USAGE (conf name output):$(tput sgr0)" -echo " $0 [-hfpr] " -echo " $(tput bold)USAGE (conf name input):$(tput sgr0)" -echo " $0 -c [-hfpr] " -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -echo " $(tput bold)-h$(tput sgr0) help" -echo " $(tput bold)-f$(tput sgr0) force load (even if unchanged file)" -echo " $(tput bold)-c$(tput sgr0) read FITS file name from ./conf/shmim..name.txt directory" -echo " $(tput bold)-p$(tput sgr0) stream prefix" -echo " $(tput bold)-r$(tput sgr0) remove / clear previous stream and associated files" -echo "" -echo " $(tput bold)INPUT:$(tput sgr0)" -echo " filesystem FITS file" -echo " shared memory stream name" -echo "" -echo " $(tput bold)EXAMPLES:$(tput sgr0)" -echo " $0 -f image32.fits ims10" -echo " Load image32.fits to stream ims10" -echo " -f option : force load even if image and stream have not changed" -echo " write \"image32.fits\" into file \"conf/shmim.ims10.name.txt" -echo " echo \"image102.fits\" > conf/shmim.ims10.name.txt" -echo " $0 -c ims10" -echo " Load image102.fits to stream ims10" -echo " $0 -c -p aol3_ ims10" -echo " Load image102.fits to stream aol3_ims10" -echo "" -echo "------------------------------------------------------------------------" + echo "------------------------------------------------------------------------" + echo "$(tput bold) $pname : Copy FITS files to shared memory $(tput sgr0)" + echo "------------------------------------------------------------------------" + echo " Copy FITS file to shared memory" + echo " Writes into ./loadedSM/ what has been loaded" + echo " unless -f option, will not re-load unchanged files" + echo " " + echo " $(tput bold)USAGE (conf name output):$(tput sgr0)" + echo " $0 [-hfpr] " + echo " $(tput bold)USAGE (conf name input):$(tput sgr0)" + echo " $0 -c [-hfpr] " + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + echo " $(tput bold)-h$(tput sgr0) help" + echo " $(tput bold)-f$(tput sgr0) force load (even if unchanged file)" + echo " $(tput bold)-c$(tput sgr0) read FITS file name from ./conf/shmim..name.txt directory" + echo " $(tput bold)-p$(tput sgr0) stream prefix" + echo " $(tput bold)-r$(tput sgr0) remove / clear previous stream and associated files" + echo "" + echo " $(tput bold)INPUT:$(tput sgr0)" + echo " filesystem FITS file" + echo " shared memory stream name" + echo "" + echo " $(tput bold)EXAMPLES:$(tput sgr0)" + echo " $0 -f image32.fits ims10" + echo " Load image32.fits to stream ims10" + echo " -f option : force load even if image and stream have not changed" + echo " write \"image32.fits\" into file \"conf/shmim.ims10.name.txt" + echo " echo \"image102.fits\" > conf/shmim.ims10.name.txt" + echo " $0 -c ims10" + echo " Load image102.fits to stream ims10" + echo " $0 -c -p aol3_ ims10" + echo " Load image102.fits to stream aol3_ims10" + echo "" + echo "------------------------------------------------------------------------" } printHELP1 () { - printf "%25s Copy FITS files to shared memory\n" "$0" + printf "%25s Copy FITS files to shared memory\n" "$0" } @@ -58,23 +58,23 @@ printHELP1 () EXITSTATUS=0 function checkFile { -if [ -f $1 ] - then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" - else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" - EXITSTATUS=1 -fi + if [ -f $1 ] + then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" + EXITSTATUS=1 + fi } function checkDir { -if [ -d $1 ] - then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) found" - else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) not found" - EXITSTATUS=1 -fi + if [ -d $1 ] + then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) not found" + EXITSTATUS=1 + fi } @@ -86,15 +86,15 @@ fi # Transform long options to short ones singlelinehelp=0 for arg in "$@"; do - shift - case "$arg" in - "--help") set -- "$@" "-h" ;; - "--help1") -set -- "$@" "-h" -singlelinehelp=1; -;; - *) set -- "$@" "$arg" - esac + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--help1") + set -- "$@" "-h" + singlelinehelp=1; + ;; + *) set -- "$@" "$arg" + esac done @@ -104,36 +104,36 @@ SMPREFIX="" CLEARSTREAM="0" while getopts :hfcp:r FLAG; do - case $FLAG in - h) #show help - if [ "$singlelinehelp" -eq "0" ]; then - printHELP - else - printHELP1 - fi - exit - ;; - c) # read from conf - READFROMCONF=1 - NBARGS=1 - ;; - f) - FORCE="1" - ;; - p) - SMPREFIX="$OPTARG" - ;; - r) - CLEARSTREAM="1" - ;; - \?) #unrecognized option - show help - echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." - printHELP - ;; - esac + case $FLAG in + h) #show help + if [ "$singlelinehelp" -eq "0" ]; then + printHELP + else + printHELP1 + fi + exit + ;; + c) # read from conf + READFROMCONF=1 + NBARGS=1 + ;; + f) + FORCE="1" + ;; + p) + SMPREFIX="$OPTARG" + ;; + r) + CLEARSTREAM="1" + ;; + \?) #unrecognized option - show help + echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." + printHELP + ;; + esac done -shift $((OPTIND-1)) +shift $((OPTIND-1)) @@ -142,32 +142,32 @@ shift $((OPTIND-1)) if [ "$1" = "help" ] || [ "$#" -ne $NBARGS ]; then -if [ "$#" -ne $NBARGS ]; then - echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" -fi -printHELP - exit + if [ "$#" -ne $NBARGS ]; then + echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" + fi + printHELP + exit fi # ======================= CHECK REQUIRED FILES ================================= if [ "$READFROMCONF" = "0" ]; then -checkFile $1 + checkFile $1 else -checkFile conf/shmim.$1.name.txt + checkFile conf/shmim.$1.name.txt fi if [ $EXITSTATUS -eq 1 ]; then -echo "" -echo "$(tput setaf 1)$(tput bold) REQUIRED FILES, COMMANDS NOT FOUND: EXITING $(tput sgr0)" -echo "" -exit + echo "" + echo "$(tput setaf 1)$(tput bold) REQUIRED FILES, COMMANDS NOT FOUND: EXITING $(tput sgr0)" + echo "" + exit else -echo "" + echo "" fi @@ -179,13 +179,13 @@ fi if [ "$READFROMCONF" = "0" ]; then -FITSfname="$1" -STREAMname="$2" -STREAMname0="$2" + FITSfname="$1" + STREAMname="$2" + STREAMname0="$2" else -STREAMname0="$1" -STREAMname="${SMPREFIX}$1" -FITSfname=$( cat ./conf/shmim.$1.name.txt ) + STREAMname0="$1" + STREAMname="${SMPREFIX}$1" + FITSfname=$( cat ./conf/shmim.$1.name.txt ) fi @@ -194,9 +194,9 @@ fi # if it is, resolve link # if [ -L "$FITSfname" ]; then -flink=$( readlink -f $FITSfname ) -rm $FITSfname -rsync -auL $flink $FITSfname + flink=$( readlink -f $FITSfname ) + rm $FITSfname + rsync -auL $flink $FITSfname fi @@ -212,11 +212,11 @@ mkdir -p loadedSM if [ "$CLEARSTREAM" = "1" ]; then # clear stream and associated files -rm ./loadedSM/${STREAMname0}.* -rm $MILK_SHM_DIR/${STREAMname}.im.shm -rm /dev/shm/sem.${STREAMname}.* -rm ./conf/shmim.${STREAMname0}.imsize.txt -rm ./conf/shmim.${STREAMname0}.fits + rm ./loadedSM/${STREAMname0}.* + rm $MILK_SHM_DIR/${STREAMname}.im.shm + rm /dev/shm/sem.${STREAMname}.* + rm ./conf/shmim.${STREAMname0}.imsize.txt + rm ./conf/shmim.${STREAMname0}.fits fi @@ -233,22 +233,22 @@ stat -L --format "%n %s %y" ${FITSfname} > ./loadedSM/${STREAMname0}.FITSinfo str1=$(cat ./loadedSM/${STREAMname0}.FITSinfo.old) str2=$(cat ./loadedSM/${STREAMname0}.FITSinfo) if [ "$str1" = "$str2" ]; then -if [ "$VERBOSE" = "1" ]; then -echo "======= FITS file unchanged ========" -echo "======= LOADfile = $LOADfile ========" -fi -touch ./loadedSM/${STREAMname0}.FITSsame -rm ./loadedSM/${STREAMname0}.FITSchanged &> /dev/null -NEW="0" + if [ "$VERBOSE" = "1" ]; then + echo "======= FITS file unchanged ========" + echo "======= LOADfile = $LOADfile ========" + fi + touch ./loadedSM/${STREAMname0}.FITSsame + rm ./loadedSM/${STREAMname0}.FITSchanged &> /dev/null + NEW="0" else -if [ "$VERBOSE" = "1" ]; then -echo "======= FITS file changed ==========" -echo "======= LOADfile = $LOADfile ========" -fi -rm ./loadedSM/${STREAMname0}.FITSsame &> /dev/null -touch ./loadedSM/${STREAMname0}.FITSchanged -NEW="1" -LOADfile="1" + if [ "$VERBOSE" = "1" ]; then + echo "======= FITS file changed ==========" + echo "======= LOADfile = $LOADfile ========" + fi + rm ./loadedSM/${STREAMname0}.FITSsame &> /dev/null + touch ./loadedSM/${STREAMname0}.FITSchanged + NEW="1" + LOADfile="1" fi rm ./loadedSM/${STREAMname0}.SMloaded.old &> /dev/null @@ -261,22 +261,22 @@ str1=$(cat ./loadedSM/${STREAMname0}.SMinfo.old) str2=$(cat ./loadedSM/${STREAMname0}.SMinfo) if [ "$str1" = "$str2" ]; then -if [ "$VERBOSE" = "1" ]; then -echo "======= SM file unchanged ========" -echo "======= LOADfile = $LOADfile ========" -fi -touch ./loadedSM/${STREAMname0}.SMsame -rm ./loadedSM/${STREAMname0}.SMchanged &> /dev/null -NEW_SM="0" + if [ "$VERBOSE" = "1" ]; then + echo "======= SM file unchanged ========" + echo "======= LOADfile = $LOADfile ========" + fi + touch ./loadedSM/${STREAMname0}.SMsame + rm ./loadedSM/${STREAMname0}.SMchanged &> /dev/null + NEW_SM="0" else -if [ "$VERBOSE" = "1" ]; then -echo "======= SM file changed ==========" -echo "======= LOADfile = $LOADfile ========" -fi -rm ./loadedSM/${STREAMname0}.SMsame &> /dev/null -touch ./loadedSM/${STREAMname0}.SMchanged -NEW_SM="1" -LOADfile="1" + if [ "$VERBOSE" = "1" ]; then + echo "======= SM file changed ==========" + echo "======= LOADfile = $LOADfile ========" + fi + rm ./loadedSM/${STREAMname0}.SMsame &> /dev/null + touch ./loadedSM/${STREAMname0}.SMchanged + NEW_SM="1" + LOADfile="1" fi rm ./loadedSM/${STREAMname0}.SMinfo.old &> /dev/null @@ -285,28 +285,28 @@ rm ./loadedSM/${STREAMname0}.SMinfo.old &> /dev/null if [ ! -f "$MILK_SHM_DIR/${STREAMname}.im.shm" ]; then -if [ "$VERBOSE" = "1" ]; then -echo "======= SM file missing ==========" -echo "======= LOADfile = $LOADfile ========" -fi -touch ./loadedSM/${STREAMname0}.missing -LOADfile="1" + if [ "$VERBOSE" = "1" ]; then + echo "======= SM file missing ==========" + echo "======= LOADfile = $LOADfile ========" + fi + touch ./loadedSM/${STREAMname0}.missing + LOADfile="1" else -rm ./loadedSM/${STREAMname0}.missing &> /dev/null + rm ./loadedSM/${STREAMname0}.missing &> /dev/null fi if [ "$FORCE" = "1" ]; then -if [ "$VERBOSE" = "1" ]; then -echo "======= FORCE MODE ==========" -echo "======= LOADfile = $LOADfile ========" -fi -LOADfile="1" + if [ "$VERBOSE" = "1" ]; then + echo "======= FORCE MODE ==========" + echo "======= LOADfile = $LOADfile ========" + fi + LOADfile="1" fi if [ "$VERBOSE" = "1" ]; then -echo "======= LOADfile = $LOADfile ========" + echo "======= LOADfile = $LOADfile ========" fi @@ -315,7 +315,7 @@ fi if [ "$LOADfile" = "1" ]; then -milk -n $pname << EOF + milk -n $pname << EOF loadfits "${FITSfname}" im readshmim "${STREAMname}" cpsh im "${STREAMname}" @@ -323,23 +323,21 @@ readshmimsize ${STREAMname} "./loadedSM/${STREAMname0}.imsize" exitCLI EOF -# copy imsize to conf -cp ./loadedSM/${STREAMname0}.imsize ./conf/shmim.${STREAMname0}.imsize.txt -# add link to conf -rm ./conf/shmim.${STREAMname0}.fits -ln -s ${PWD}/${FITSfname} ./conf/shmim.${STREAMname0}.fits + # copy imsize to conf + cp ./loadedSM/${STREAMname0}.imsize ./conf/shmim.${STREAMname0}.imsize.txt + # add link to conf + rm ./conf/shmim.${STREAMname0}.fits + ln -s ${PWD}/${FITSfname} ./conf/shmim.${STREAMname0}.fits -# write SM stat AFTER it has been updated -stat -L --format "%n %s %y" $MILK_SHM_DIR/${STREAMname}.im.shm > ./loadedSM/${STREAMname0}.SMinfo -rm ./loadedSM/${STREAMname0}.kept &> /dev/null -touch ./loadedSM/${STREAMname0}.changed + # write SM stat AFTER it has been updated + stat -L --format "%n %s %y" $MILK_SHM_DIR/${STREAMname}.im.shm > ./loadedSM/${STREAMname0}.SMinfo + rm ./loadedSM/${STREAMname0}.kept &> /dev/null + touch ./loadedSM/${STREAMname0}.changed else -touch ./loadedSM/${STREAMname0}.kept -rm ./loadedSM/${STREAMname0}.changed &> /dev/null + touch ./loadedSM/${STREAMname0}.kept + rm ./loadedSM/${STREAMname0}.changed &> /dev/null fi - - diff --git a/scripts/milk-argparse b/scripts/milk-argparse index be56f487..43236bc7 100755 --- a/scripts/milk-argparse +++ b/scripts/milk-argparse @@ -75,44 +75,44 @@ QUIET=0 function checkFile { - if [ -f $1 ]; then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" - else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" - EXITSTATUS=1 - fi + if [ -f $1 ]; then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" + EXITSTATUS=1 + fi } function checkDir { - if [ -d $1 ]; then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) found" - else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) not found" - EXITSTATUS=1 - fi + if [ -d $1 ]; then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) not found" + EXITSTATUS=1 + fi } function cmdexists() { - command -v "$1" >/dev/null 2>&1 + command -v "$1" >/dev/null 2>&1 } function checkCommand { -if cmdexists $1; then - if [ ${QUIET} = 0 ]; then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) found" - fi - COMMAND_FOUND=1 -else - if [ ${QUIET} = 0 ]; then - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) not installed. Aborting." + if cmdexists $1; then + if [ ${QUIET} = 0 ]; then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) found" + fi + COMMAND_FOUND=1 + else + if [ ${QUIET} = 0 ]; then + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) not installed. Aborting." + fi + COMMAND_FOUND=0 + EXITSTATUS=1; fi - COMMAND_FOUND=0 - EXITSTATUS=1; -fi } @@ -122,61 +122,61 @@ fi function printHELP { -optlistshort="" -optindex=0 -while [ $optindex -lt ${NBopt} ]; do - optlistshort="${optlistshort}[${fgRed}-${inputMSoptshortARRAY[$optindex]}${txReset}]" - let optindex+=1 -done - -argliststring="" -argindex=0 -while [ $argindex -lt ${NBarg} ]; do - argliststring="${argliststring} ${inputMSargnameARRAY[$argindex]}" - let argindex+=1 -done - - -echo "------------------------------------------------------------------------" -echo "${txBold} ${pname} : ${MSdescr} ${txReset}" -echo " $0" -echo "------------------------------------------------------------------------" -echo "" -set +o nounset -if [ ! -z "${MSextdescr}" ]; then -printf "${MSextdescr}" -echo "" -echo "" -fi -set -o nounset -echo " $(tput bold)USAGE:$(tput sgr0)" -echo " ${pname} [OPTION(S)] ${fgYellow}${argliststring}${txReset}" -echo " option(s): ${optlistshort}" -echo "" -echo " $(tput bold)ARGUMENTS:$(tput sgr0)" -argindex=0 -while [ $argindex -lt ${NBarg} ]; do - printf " %12s [%s]\n %s\n" "${fgYellow}${inputMSargnameARRAY[$argindex]}${txReset}" "${fgGreen}${inputMSargtypeARRAY[$argindex]}${txReset}" "${inputMSargdescrARRAY[$argindex]}" - let argindex+=1 -done -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -optindex=0 -while [ $optindex -lt ${NBopt} ]; do - echo -e " ${fgRed}-${inputMSoptshortARRAY[$optindex]}${txReset}, ${fgRed}--${inputMSoptlongARRAY[$optindex]}${txReset} ${fgBGreen}${inputMSoptargARRAY[$optindex]}${txReset}" - echo " ${inputMSoptdescrARRAY[$optindex]}" - let optindex+=1 -done -echo "" -exit + optlistshort="" + optindex=0 + while [ $optindex -lt ${NBopt} ]; do + optlistshort="${optlistshort}[${fgRed}-${inputMSoptshortARRAY[$optindex]}${txReset}]" + let optindex+=1 + done + + argliststring="" + argindex=0 + while [ $argindex -lt ${NBarg} ]; do + argliststring="${argliststring} ${inputMSargnameARRAY[$argindex]}" + let argindex+=1 + done + + + echo "------------------------------------------------------------------------" + echo "${txBold} ${pname} : ${MSdescr} ${txReset}" + echo " $0" + echo "------------------------------------------------------------------------" + echo "" + set +o nounset + if [ ! -z "${MSextdescr}" ]; then + printf "${MSextdescr}" + echo "" + echo "" + fi + set -o nounset + echo " $(tput bold)USAGE:$(tput sgr0)" + echo " ${pname} [OPTION(S)] ${fgYellow}${argliststring}${txReset}" + echo " option(s): ${optlistshort}" + echo "" + echo " $(tput bold)ARGUMENTS:$(tput sgr0)" + argindex=0 + while [ $argindex -lt ${NBarg} ]; do + printf " %12s [%s]\n %s\n" "${fgYellow}${inputMSargnameARRAY[$argindex]}${txReset}" "${fgGreen}${inputMSargtypeARRAY[$argindex]}${txReset}" "${inputMSargdescrARRAY[$argindex]}" + let argindex+=1 + done + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + optindex=0 + while [ $optindex -lt ${NBopt} ]; do + echo -e " ${fgRed}-${inputMSoptshortARRAY[$optindex]}${txReset}, ${fgRed}--${inputMSoptlongARRAY[$optindex]}${txReset} ${fgBGreen}${inputMSoptargARRAY[$optindex]}${txReset}" + echo " ${inputMSoptdescrARRAY[$optindex]}" + let optindex+=1 + done + echo "" + exit } printHELPshort () { - printf "%20s ${MSdescr}\n" "$0" - exit + printf "%20s ${MSdescr}\n" "$0" + exit } @@ -193,25 +193,25 @@ printHELPshort () # ================================================= function checkallprerequisites() { -set +o nounset -for cmd in ${RequiredCommands[@]}; do - checkCommand $cmd -done - -for fname in ${RequiredFiles[@]}; do - checkFile $fname -done - -for dname in ${RequiredDirs[@]}; do - checkDir $dname -done -set -o nounset + set +o nounset + for cmd in ${RequiredCommands[@]}; do + checkCommand $cmd + done + + for fname in ${RequiredFiles[@]}; do + checkFile $fname + done + + for dname in ${RequiredDirs[@]}; do + checkDir $dname + done + set -o nounset } function checkallprerequisitesExit() { - checkallprerequisites - exit + checkallprerequisites + exit } @@ -232,13 +232,13 @@ inputMSargdescrARRAY=( ) NBarg=0 for argdat in "${MSarg[@]}";do - #echo "Argument ${NBarg}: $argdat" - IFS=':' read -r -a argarray <<< "$argdat" - inputMSargnameARRAY+=( ${argarray[0]} ) - inputMSargtypeARRAY+=( ${argarray[1]} ) - inputMSargdescrARRAY+=( "${argarray[2]}" ) - #echo " ${inputMSargnameARRAY[$NBarg]}" - let NBarg+=1 + #echo "Argument ${NBarg}: $argdat" + IFS=':' read -r -a argarray <<< "$argdat" + inputMSargnameARRAY+=( ${argarray[0]} ) + inputMSargtypeARRAY+=( ${argarray[1]} ) + inputMSargdescrARRAY+=( "${argarray[2]}" ) + #echo " ${inputMSargnameARRAY[$NBarg]}" + let NBarg+=1 done #echo "NBarg = ${NBarg}" @@ -268,18 +268,18 @@ optactlist=( ) NBopt=0 for optdat in "${MSopt[@]}";do - #echo "Option ${NBopt}: $optdat" - IFS=':' read -r -a optarray <<< "$optdat" - let NBopt+=1 - inputMSoptshortARRAY+=( ${optarray[0]} ) - inputMSoptlongARRAY+=( ${optarray[1]} ) - inputMSoptfuncARRAY+=( ${optarray[2]} ) - inputMSoptargARRAY+=( "${optarray[3]}" ) - inputMSoptdescrARRAY+=( "${optarray[4]}" ) - OPTlong[${optarray[0]}]="${optarray[1]}" - OPTfunc[${optarray[0]}]="${optarray[2]}" - OPTarg[${optarray[0]}]="${optarray[3]}" - OPTlong2short[${OPTlong[${optarray[0]}]}]=${optarray[0]} + #echo "Option ${NBopt}: $optdat" + IFS=':' read -r -a optarray <<< "$optdat" + let NBopt+=1 + inputMSoptshortARRAY+=( ${optarray[0]} ) + inputMSoptlongARRAY+=( ${optarray[1]} ) + inputMSoptfuncARRAY+=( ${optarray[2]} ) + inputMSoptargARRAY+=( "${optarray[3]}" ) + inputMSoptdescrARRAY+=( "${optarray[4]}" ) + OPTlong[${optarray[0]}]="${optarray[1]}" + OPTfunc[${optarray[0]}]="${optarray[2]}" + OPTarg[${optarray[0]}]="${optarray[3]}" + OPTlong2short[${OPTlong[${optarray[0]}]}]=${optarray[0]} done @@ -294,53 +294,53 @@ optargstring="" inputParamString=( ) function getoptargs { - optargstring="" - shiftcnt=0 - nboptarg=$( wc -w <<< "${OPTarg[${shortopt}]}" ) - #echo "nboptarg = ${nboptarg} from $@" - optargindex=0 + optargstring="" + shiftcnt=0 + nboptarg=$( wc -w <<< "${OPTarg[${shortopt}]}" ) + #echo "nboptarg = ${nboptarg} from $@" + optargindex=0 while [ $optargindex -lt ${nboptarg} ]; do - let shiftcnt+=1 - let optargindex+=1 - optargstring="${optargstring} $1" - shift - done + let shiftcnt+=1 + let optargindex+=1 + optargstring="${optargstring} $1" + shift + done } while (( "$#" )); do - case "$1" in - --*) # long option - #echo "long option: $1" - inputMSoptlongARRAY+=( $1 ) - longopt=$1 - longopt="${longopt:2}" - shortopt=${OPTlong2short[$longopt]} - #echo "func $1 $shortopt : ${OPTfunc[${shortopt}]}" - optactlist+=( $shortopt ) - shift - getoptargs $@ - OPTargstring[${shortopt}]=${optargstring} - shift ${shiftcnt} - ;; - -*) # short option - inputMSoptshortARRAY+=( $1 ) - shortopt=$1 - shortopt="${shortopt:1}" - #echo "func $1 $shortopt : ${OPTfunc[${shortopt}]}" - optactlist+=( $shortopt ) - shift - getoptargs $@ - OPTargstring[${shortopt}]=${optargstring} - shift ${shiftcnt} - ;; - *) - #echo "param: $1" - inputMSargARRAY+=( "$1" ) - inputParamString+=( "$1" ) - shift - ;; - esac + case "$1" in + --*) # long option + #echo "long option: $1" + inputMSoptlongARRAY+=( $1 ) + longopt=$1 + longopt="${longopt:2}" + shortopt=${OPTlong2short[$longopt]} + #echo "func $1 $shortopt : ${OPTfunc[${shortopt}]}" + optactlist+=( $shortopt ) + shift + getoptargs $@ + OPTargstring[${shortopt}]=${optargstring} + shift ${shiftcnt} + ;; + -*) # short option + inputMSoptshortARRAY+=( $1 ) + shortopt=$1 + shortopt="${shortopt:1}" + #echo "func $1 $shortopt : ${OPTfunc[${shortopt}]}" + optactlist+=( $shortopt ) + shift + getoptargs $@ + OPTargstring[${shortopt}]=${optargstring} + shift ${shiftcnt} + ;; + *) + #echo "param: $1" + inputMSargARRAY+=( "$1" ) + inputParamString+=( "$1" ) + shift + ;; + esac done @@ -348,9 +348,9 @@ done set +o nounset NBoptact=0 for MSopt in "${optactlist[@]}";do - #echo " input option ${NBoptact} : $MSopt -> ${OPTfunc[$MSopt]} ${OPTargstring[$MSopt]}" - ${OPTfunc[$MSopt]} ${OPTargstring[$MSopt]} - let NBoptact+=1 + #echo " input option ${NBoptact} : $MSopt -> ${OPTfunc[$MSopt]} ${OPTargstring[$MSopt]}" + ${OPTfunc[$MSopt]} ${OPTargstring[$MSopt]} + let NBoptact+=1 done set -o nounset @@ -367,13 +367,13 @@ checkallprerequisites NBargin=0 #for MSarg in "${inputMSargARRAY[@]}";do for MSarg in "${inputParamString[@]}";do -# echo " input argument ${NBargin} : $MSarg" - let NBargin+=1 + # echo " input argument ${NBargin} : $MSarg" + let NBargin+=1 done if [[ ${NBargin} -ne ${NBarg} ]]; then - echo "${fgRed} ERROR: ${NBarg} arguments expected, ${NBargin} entered ${txReset}" - exit + echo "${fgRed} ERROR: ${NBarg} arguments expected, ${NBargin} entered ${txReset}" + exit fi @@ -382,16 +382,16 @@ fi function cleanup() { - echo "" - # optional custom cleanup provided by application - customcleanup - echo "Exiting script ${pname}" - echo "" + echo "" + # optional custom cleanup provided by application + customcleanup + echo "Exiting script ${pname}" + echo "" } function settrap() { - trap cleanup EXIT + trap cleanup EXIT } # call settrap function diff --git a/scripts/milk-debug b/scripts/milk-debug index eafdf566..bb486ca1 100755 --- a/scripts/milk-debug +++ b/scripts/milk-debug @@ -16,4 +16,3 @@ OPTION="$OPTION --max-stackframe=4442392" valgrind ${OPTION} ./milkdebugtest rm ./milkdebugtest - diff --git a/scripts/milk-exec b/scripts/milk-exec index bac5ed68..ba4955cc 100755 --- a/scripts/milk-exec +++ b/scripts/milk-exec @@ -18,12 +18,12 @@ MSarg+=( "commandstring:string:command string" ) MSopt+=( "n:name:set_pname:pname[string]:(n)ame process" ) function set_pname() { - pname="$1" + pname="$1" } MSopt+=( "T:testmode:set_testmode::(T)est mode" ) function set_testmode() { - echo "CTEST_FULL_OUTPUT" + echo "CTEST_FULL_OUTPUT" } @@ -54,5 +54,3 @@ echo "exitCLI" >> $SF milk -n ${pname} -f -s ${SF} rm ${SF} - - diff --git a/scripts/milk-fpsCTRL b/scripts/milk-fpsCTRL index 71daae5a..b9b1806b 100755 --- a/scripts/milk-fpsCTRL +++ b/scripts/milk-fpsCTRL @@ -11,35 +11,35 @@ echo "pname = ${pname}" function printHELP { -echo "------------------------------------------------------------------------" -echo "$(tput bold) $pname : function parameters control $(tput sgr0)" -echo "------------------------------------------------------------------------" -echo " Monitors and controls function parameters" -echo " Connects to .fps.shm shared memory structures" -echo " Argument is string match filter to select fps structures" -echo " " -echo " $(tput bold)USAGE:$(tput sgr0)" -echo " $0 [-hlmD] " -echo "" -echo " $(tput bold)ARGUMENTS:$(tput sgr0)" -echo " string filter (optional)" -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -echo " $(tput bold)-h$(tput sgr0) help" -echo " $(tput bold)-f$(tput sgr0) input (f)ifo name" -echo " $(tput bold)-l$(tput sgr0) (l)ist fps structures" -echo " $(tput bold)-m$(tput sgr0) must (m)atch fpscmd/fpslist.txt" -echo " $(tput bold)-s$(tput sgr0) use (s)tdio instead of ncurses" -echo " $(tput bold)-q$(tput sgr0) (q)uiet mode, do not print" -echo " $(tput bold)-D$(tput sgr0) (D)ebug mode, uses valgrind" -echo "" -echo "------------------------------------------------------------------------" + echo "------------------------------------------------------------------------" + echo "$(tput bold) $pname : function parameters control $(tput sgr0)" + echo "------------------------------------------------------------------------" + echo " Monitors and controls function parameters" + echo " Connects to .fps.shm shared memory structures" + echo " Argument is string match filter to select fps structures" + echo " " + echo " $(tput bold)USAGE:$(tput sgr0)" + echo " $0 [-hlmD] " + echo "" + echo " $(tput bold)ARGUMENTS:$(tput sgr0)" + echo " string filter (optional)" + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + echo " $(tput bold)-h$(tput sgr0) help" + echo " $(tput bold)-f$(tput sgr0) input (f)ifo name" + echo " $(tput bold)-l$(tput sgr0) (l)ist fps structures" + echo " $(tput bold)-m$(tput sgr0) must (m)atch fpscmd/fpslist.txt" + echo " $(tput bold)-s$(tput sgr0) use (s)tdio instead of ncurses" + echo " $(tput bold)-q$(tput sgr0) (q)uiet mode, do not print" + echo " $(tput bold)-D$(tput sgr0) (D)ebug mode, uses valgrind" + echo "" + echo "------------------------------------------------------------------------" } printHELP1 () { - printf "%20s Monitor and control function parameters\n" "$0" + printf "%20s Monitor and control function parameters\n" "$0" } @@ -53,15 +53,15 @@ echo -n "sh-${shortpname}" > /proc/self/comm # Transform long options to short ones singlelinehelp=0 for arg in "$@"; do - shift - case "$arg" in - "--help") set -- "$@" "-h" ;; - "--help1") -set -- "$@" "-h" -singlelinehelp=1; -;; - *) set -- "$@" "$arg" - esac + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--help1") + set -- "$@" "-h" + singlelinehelp=1; + ;; + *) set -- "$@" "$arg" + esac done @@ -78,45 +78,45 @@ fifoname="$MILK_SHM_DIR/milkCLIfifo.${pname}.${ttystring}" outlogname="$MILK_SHM_DIR/milkCLIlog.${pname}.${ttystring}" while getopts :hlmDf:o:sq FLAG; do - case $FLAG in - h) #show help - if [ "$singlelinehelp" -eq "0" ]; then - printHELP - else - printHELP1 - fi - exit - ;; - l) # list fps structures - echo "" - ls -l $MILK_SHM_DIR/*.fps.shm - echo "" - exit - ;; - f) # fifo name - fifoname=${OPTARG} - echo "using fifo name : ${fifoname}" - ;; - m) - MODE="1" - ;; - s) # use stdio instead of ncurses - export MILK_TUIPRINT_STDIO=1 - ;; - q) # quiet mode - don't print status - export MILK_TUIPRINT_NONE=1 - ;; - D) - DEBUG="1" - ;; - \?) - echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." - printHELP - ;; - esac + case $FLAG in + h) #show help + if [ "$singlelinehelp" -eq "0" ]; then + printHELP + else + printHELP1 + fi + exit + ;; + l) # list fps structures + echo "" + ls -l $MILK_SHM_DIR/*.fps.shm + echo "" + exit + ;; + f) # fifo name + fifoname=${OPTARG} + echo "using fifo name : ${fifoname}" + ;; + m) + MODE="1" + ;; + s) # use stdio instead of ncurses + export MILK_TUIPRINT_STDIO=1 + ;; + q) # quiet mode - don't print status + export MILK_TUIPRINT_NONE=1 + ;; + D) + DEBUG="1" + ;; + \?) + echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." + printHELP + ;; + esac done -shift $((OPTIND-1)) +shift $((OPTIND-1)) ### End getopts code ### @@ -125,18 +125,18 @@ NBargInput="$#" arg1="$1" if [ "$#" -eq 0 ]; then -arg1="_ALL" -NBargInput="1" + arg1="_ALL" + NBargInput="1" fi if [ "$arg1" = "help" ] || [ "$NBargInput" -ne $NBARGS ]; then -if [ "$#" -ne $NBARGS ]; then - echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" -fi -printHELP - exit + if [ "$#" -ne $NBARGS ]; then + echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" + fi + printHELP + exit fi @@ -154,24 +154,24 @@ echo "SF = ${SF}" if [ "$DEBUG" = "1" ]; then -cp $(which milk) milkdebugtest -OPTION="--leak-check=full --show-leak-kinds=all" -OPTION="$OPTION --track-origins=yes" -OPTION="$OPTION --num-callers=200" -OPTION="$OPTION --show-reachable=yes" -#OPTION="$OPTION --gen-suppressions=all" -OPTION="$OPTION --log-file=milk.memcheck.log" -OPTION="$OPTION --suppressions=$MILK_ROOT/milk.memcheck.supp" -OPTION="$OPTION --max-stackframe=4442392" + cp $(which milk) milkdebugtest + OPTION="--leak-check=full --show-leak-kinds=all" + OPTION="$OPTION --track-origins=yes" + OPTION="$OPTION --num-callers=200" + OPTION="$OPTION --show-reachable=yes" + #OPTION="$OPTION --gen-suppressions=all" + OPTION="$OPTION --log-file=milk.memcheck.log" + OPTION="$OPTION --suppressions=$MILK_ROOT/milk.memcheck.supp" + OPTION="$OPTION --max-stackframe=4442392" -valgrind ${OPTION} ./milkdebugtest -n ${pname} -f ${CLIfifoname} -s ${SF} -rm ./milkdebugtest + valgrind ${OPTION} ./milkdebugtest -n ${pname} -f ${CLIfifoname} -s ${SF} + rm ./milkdebugtest else -echo "Running: milk -n ${shortpname} -f ${CLIfifoname} -s ${SF}" -export MILK_QUIET=1 -milk -n ${shortpname} -f ${CLIfifoname} -s ${SF} -#2> testout.txt + echo "Running: milk -n ${shortpname} -f ${CLIfifoname} -s ${SF}" + export MILK_QUIET=1 + milk -n ${shortpname} -f ${CLIfifoname} -s ${SF} + #2> testout.txt fi @@ -185,8 +185,7 @@ rm ${fifoname} exitscriptname="${pname}-exitscript" if [ -f ${exitscriptname} ]; then - echo "running script ${exitscriptname}" - source ${exitscriptname} - rm ${exitscriptname} + echo "running script ${exitscriptname}" + source ${exitscriptname} + rm ${exitscriptname} fi - diff --git a/scripts/milk-fpsinit b/scripts/milk-fpsinit index 78f3a980..70124041 100755 --- a/scripts/milk-fpsinit +++ b/scripts/milk-fpsinit @@ -6,33 +6,33 @@ MSdescr="initialize Function Parameter Structures (FPS)" scriptname=$(basename $0) MSextdescr="Reads file fpslist.txt - For each entry, initialize the FPS : - - Create and initialize FPS - - Create tmux session and functions in tmux sessions - Run without argument to print FPSs status +For each entry, initialize the FPS : +- Create and initialize FPS +- Create tmux session and functions in tmux sessions +Run without argument to print FPSs status $(tput bold)fpslist.txt file format$(tput sgr0) - One line per entry: - Add modules with \"+module1;module2\" line directly before entry - Optional arguments may be parsed by code, or simply used for FPS naming +One line per entry: +Add modules with \"+module1;module2\" line directly before entry +Optional arguments may be parsed by code, or simply used for FPS naming $(tput bold)Example use$(tput sgr0) - [1] Create fpslist.txt file: - +mycustommodule;othercustommodule - myfpsname custommod.customcommand im1 304 +[1] Create fpslist.txt file: ++mycustommodule;othercustommodule +myfpsname custommod.customcommand im1 304 - [2] Run ${scriptname} : - > ${scriptname} -c 0 - Will create FPS named \"myfpsname-im1-304\" +[2] Run ${scriptname} : +> ${scriptname} -c 0 +Will create FPS named \"myfpsname-im1-304\" - [3] Launch milk-fpsCTRL to manage and control +[3] Launch milk-fpsCTRL to manage and control $(tput bold)Related scripts:$(tput sgr0) - milk-fpsCTRL - milk-procCTRL - " +milk-fpsCTRL +milk-procCTRL +" source milk-script-std-config @@ -346,9 +346,3 @@ for i in "${!FPSNAMEARRAY[@]}"; do fi done - - - - - - diff --git a/scripts/milk-fpsmkcmd b/scripts/milk-fpsmkcmd index ee5ac818..5341a018 100755 --- a/scripts/milk-fpsmkcmd +++ b/scripts/milk-fpsmkcmd @@ -35,147 +35,147 @@ chmod +x ${FPScmddir}/fpsrunstopscript cat "$FPSlistfilename" | while read LINE; do nw=$( echo "$LINE" | wc -w ) if [ "$nw" -gt 1 ]; then - if [[ $LINE != \#* ]]; then - - declare -a OPTARG - - stringarr=($LINE) - nbarg=$(( $nw - 2 )) - - FPSrootname=${stringarr[0]} - #$( echo "$LINE" | awk '{print $1}' ) - CLIname=${stringarr[1]} - #$( echo "$LINE" | awk '{print $2}' ) - - FPSname="${FPSrootname}" - echo " FPS root name = ${FPSname}" - echo " CLI cmd = ${CLIname}" - - for arg in `seq 1 $nbarg`; - do - i=$(( $arg + 1 )) - OPTARG[$arg]=${stringarr[$i]} + if [[ $LINE != \#* ]]; then + + declare -a OPTARG + + stringarr=($LINE) + nbarg=$(( $nw - 2 )) + + FPSrootname=${stringarr[0]} + #$( echo "$LINE" | awk '{print $1}' ) + CLIname=${stringarr[1]} + #$( echo "$LINE" | awk '{print $2}' ) + + FPSname="${FPSrootname}" + echo " FPS root name = ${FPSname}" + echo " CLI cmd = ${CLIname}" + + for arg in `seq 1 $nbarg`; + do + i=$(( $arg + 1 )) + OPTARG[$arg]=${stringarr[$i]} echo " Argument $arg =" ${OPTARG[$arg]} FPSname+="-"${OPTARG[$arg]} - done - - echo " FPS name = ${FPSname}" - - - # write to list of FPS names - echo "${FPSname}" >> ./${FPScmddir}/fpslist.txt - - # write scripts - for CMDCODE in "FPSINIT" "CONFSTART" "CONFSTOP" "RUNSTART" "RUNSTOP"; do - - pnamestr="$(echo "$CMDCODE" | awk '{print tolower($0)}')" - - fname="./${FPScmddir}/${FPSrootname}-${pnamestr}" - - if [ "$CMDCODE" != "CONFSTOP" ]; # CONFSTOP does not run a program. Instead, C-c char sent to tmux session - then - - if [ -f ${fname} ]; then - echo "File $fname exists - no write" - else - echo "Writing $fname" - - echo "#!/bin/bash" > $fname - echo "# This script was automatically written by $0" >> $fname - echo "" >> $fname - for arg in `seq 1 $nbarg`; - do - echo "arg${arg}=\"\$${arg}\"" >> $fname - done - - pname="${FPSrootname}" - CLIcmdstring="${CLIname} _${CMDCODE}_" - for arg in `seq 1 $nbarg`; do - pname+="-\${arg$arg}" - CLIcmdstring+=" \${arg$arg}" - done - echo "" >> $fname - echo "pname=\"${pname}.${pnamestr}\"" >> $fname - echo "" >> $fname - - redirect="" - if [ "$CMDCODE" = "RUNSTOP" ]; then - redirect="&>> ./${FPScmdlogdir}/${pname}.runstop.log" - fi - - # create fifo - #if [ "$CMDCODE" = "CONFSTART" ]; then - #echo "mkfifo ${MILK_SHM_DIR}/${pname}.fpsconf.fifo" >> $fname - #echo "" >> $fname - #fi - - echo "cacao -n \${pname} ${redirect} << EOF" >> $fname - - echo "$CLIcmdstring" >> $fname - echo "exitCLI" >> $fname - echo "EOF" >> $fname - - chmod +x $fname - fi - - fi - - - - - if [ "$CMDCODE" = "FPSINIT" ]; then - echo "" >> ${FPScmddir}/fpsinitscript - cmdstring="$fname" - for arg in `seq 1 $nbarg`; do - cmdstring+=" "${OPTARG[$arg]} - done - echo "${cmdstring}" >> ${FPScmddir}/fpsinitscript - fi - - if [ "$CMDCODE" = "CONFSTART" ]; then - echo "" >> ${FPScmddir}/fpsconfstartscript - cmdstring="$fname" - tmuxname="${FPSname}-conf" - echo "tmux new-session -d -s ${tmuxname}" >> ${FPScmddir}/fpsconfstartscript - for arg in `seq 1 $nbarg`; do - cmdstring+=" "${OPTARG[$arg]} - done - echo "tmux send-keys -t ${tmuxname} \"${cmdstring}\" C-m" >> ${FPScmddir}/fpsconfstartscript - fi - - if [ "$CMDCODE" = "CONFSTOP" ]; then - echo "" >> ${FPScmddir}/fpsconfstopscript - tmuxname="${FPSname}-conf" - echo "tmux send-keys -t ${tmuxname} C-c" >> ${FPScmddir}/fpsconfstopscript - fi - - - if [ "$CMDCODE" = "RUNSTART" ]; then - echo "" >> ${FPScmddir}/fpsrunstartscript - cmdstring="$fname" - tmuxname="${FPSname}-run" - echo "tmux new-session -d -s ${tmuxname}" >> ${FPScmddir}/fpsrunstartscript - for arg in `seq 1 $nbarg`; do - cmdstring+=" "${OPTARG[$arg]} - done - echo "tmux send-keys -t ${tmuxname} \"${cmdstring}\" C-m" >> ${FPScmddir}/fpsrunstartscript - fi - - if [ "$CMDCODE" = "RUNSTOP" ]; then - echo "" >> ${FPScmddir}/fpsrunstopscript - cmdstring="$fname" - for arg in `seq 1 $nbarg`; do - cmdstring+=" "${OPTARG[$arg]} - done - echo "${cmdstring}" >> ${FPScmddir}/fpsrunstopscript - fi - - - done - - - - echo "" - fi + done + + echo " FPS name = ${FPSname}" + + + # write to list of FPS names + echo "${FPSname}" >> ./${FPScmddir}/fpslist.txt + + # write scripts + for CMDCODE in "FPSINIT" "CONFSTART" "CONFSTOP" "RUNSTART" "RUNSTOP"; do + + pnamestr="$(echo "$CMDCODE" | awk '{print tolower($0)}')" + + fname="./${FPScmddir}/${FPSrootname}-${pnamestr}" + + if [ "$CMDCODE" != "CONFSTOP" ]; # CONFSTOP does not run a program. Instead, C-c char sent to tmux session + then + + if [ -f ${fname} ]; then + echo "File $fname exists - no write" + else + echo "Writing $fname" + + echo "#!/bin/bash" > $fname + echo "# This script was automatically written by $0" >> $fname + echo "" >> $fname + for arg in `seq 1 $nbarg`; + do + echo "arg${arg}=\"\$${arg}\"" >> $fname + done + + pname="${FPSrootname}" + CLIcmdstring="${CLIname} _${CMDCODE}_" + for arg in `seq 1 $nbarg`; do + pname+="-\${arg$arg}" + CLIcmdstring+=" \${arg$arg}" + done + echo "" >> $fname + echo "pname=\"${pname}.${pnamestr}\"" >> $fname + echo "" >> $fname + + redirect="" + if [ "$CMDCODE" = "RUNSTOP" ]; then + redirect="&>> ./${FPScmdlogdir}/${pname}.runstop.log" + fi + + # create fifo + #if [ "$CMDCODE" = "CONFSTART" ]; then + #echo "mkfifo ${MILK_SHM_DIR}/${pname}.fpsconf.fifo" >> $fname + #echo "" >> $fname + #fi + + echo "cacao -n \${pname} ${redirect} << EOF" >> $fname + + echo "$CLIcmdstring" >> $fname + echo "exitCLI" >> $fname + echo "EOF" >> $fname + + chmod +x $fname + fi + + fi + + + + + if [ "$CMDCODE" = "FPSINIT" ]; then + echo "" >> ${FPScmddir}/fpsinitscript + cmdstring="$fname" + for arg in `seq 1 $nbarg`; do + cmdstring+=" "${OPTARG[$arg]} + done + echo "${cmdstring}" >> ${FPScmddir}/fpsinitscript + fi + + if [ "$CMDCODE" = "CONFSTART" ]; then + echo "" >> ${FPScmddir}/fpsconfstartscript + cmdstring="$fname" + tmuxname="${FPSname}-conf" + echo "tmux new-session -d -s ${tmuxname}" >> ${FPScmddir}/fpsconfstartscript + for arg in `seq 1 $nbarg`; do + cmdstring+=" "${OPTARG[$arg]} + done + echo "tmux send-keys -t ${tmuxname} \"${cmdstring}\" C-m" >> ${FPScmddir}/fpsconfstartscript + fi + + if [ "$CMDCODE" = "CONFSTOP" ]; then + echo "" >> ${FPScmddir}/fpsconfstopscript + tmuxname="${FPSname}-conf" + echo "tmux send-keys -t ${tmuxname} C-c" >> ${FPScmddir}/fpsconfstopscript + fi + + + if [ "$CMDCODE" = "RUNSTART" ]; then + echo "" >> ${FPScmddir}/fpsrunstartscript + cmdstring="$fname" + tmuxname="${FPSname}-run" + echo "tmux new-session -d -s ${tmuxname}" >> ${FPScmddir}/fpsrunstartscript + for arg in `seq 1 $nbarg`; do + cmdstring+=" "${OPTARG[$arg]} + done + echo "tmux send-keys -t ${tmuxname} \"${cmdstring}\" C-m" >> ${FPScmddir}/fpsrunstartscript + fi + + if [ "$CMDCODE" = "RUNSTOP" ]; then + echo "" >> ${FPScmddir}/fpsrunstopscript + cmdstring="$fname" + for arg in `seq 1 $nbarg`; do + cmdstring+=" "${OPTARG[$arg]} + done + echo "${cmdstring}" >> ${FPScmddir}/fpsrunstopscript + fi + + + done + + + + echo "" + fi fi done diff --git a/scripts/milk-logshim b/scripts/milk-logshim index 531e1c22..1334cfbb 100755 --- a/scripts/milk-logshim +++ b/scripts/milk-logshim @@ -12,33 +12,33 @@ pname="logshim-$1" function printHELP { -echo "------------------------------------------------------------------------" -echo "$(tput bold) $pname : Log image stream $(tput sgr0)" -echo "------------------------------------------------------------------------" -echo " Start process to log image stream to disk" -echo " " -echo " $(tput bold)USAGE:$(tput sgr0)" -echo " $0 [-h c ] " -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -echo " $(tput bold)-h$(tput sgr0) help" -echo " $(tput bold)-c$(tput sgr0) move process to CPUset" -echo "" -echo " $(tput bold)INPUT:$(tput sgr0)" -echo " Shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" -echo " Number of slices in each data cube saved" -echo " Destination directory" -echo "" -echo " $(tput bold)EXAMPLE:$(tput sgr0)" -echo " logshim ircam2 10000 /media/data/20150222/ircamlog/" -echo "" -echo "------------------------------------------------------------------------" + echo "------------------------------------------------------------------------" + echo "$(tput bold) $pname : Log image stream $(tput sgr0)" + echo "------------------------------------------------------------------------" + echo " Start process to log image stream to disk" + echo " " + echo " $(tput bold)USAGE:$(tput sgr0)" + echo " $0 [-h c ] " + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + echo " $(tput bold)-h$(tput sgr0) help" + echo " $(tput bold)-c$(tput sgr0) move process to CPUset" + echo "" + echo " $(tput bold)INPUT:$(tput sgr0)" + echo " Shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" + echo " Number of slices in each data cube saved" + echo " Destination directory" + echo "" + echo " $(tput bold)EXAMPLE:$(tput sgr0)" + echo " logshim ircam2 10000 /media/data/20150222/ircamlog/" + echo "" + echo "------------------------------------------------------------------------" } printHELP1 () { - printf "%20s Start process to log image stream to disk\n" "$0" + printf "%20s Start process to log image stream to disk\n" "$0" } @@ -50,38 +50,38 @@ EXITSTATUS=0 function checkFile { -if [ -f $1 ] - then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" - else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" - EXITSTATUS=1 -fi + if [ -f $1 ] + then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" + EXITSTATUS=1 + fi } function checkDir { -if [ -d $1 ] - then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) found" - else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) not found" - EXITSTATUS=1 -fi + if [ -d $1 ] + then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) not found" + EXITSTATUS=1 + fi } function cmdexists() { - command -v "$1" >/dev/null 2>&1 + command -v "$1" >/dev/null 2>&1 } function checkCommand { -if cmdexists $1; then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) found" -else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) not installed. Aborting."; EXITSTATUS=1; -fi + if cmdexists $1; then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) not installed. Aborting."; EXITSTATUS=1; + fi } @@ -96,15 +96,15 @@ fi # Transform long options to short ones singlelinehelp=0 for arg in "$@"; do - shift - case "$arg" in - "--help") set -- "$@" "-h" ;; - "--help1") -set -- "$@" "-h" -singlelinehelp=1; -;; - *) set -- "$@" "$arg" - esac + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--help1") + set -- "$@" "-h" + singlelinehelp=1; + ;; + *) set -- "$@" "$arg" + esac done @@ -113,23 +113,23 @@ done CPUset="NULL" while getopts :hc: FLAG; do - case $FLAG in - h) #show help - if [ "$singlelinehelp" -eq "0" ]; then - printHELP - else - printHELP1 - fi - exit - ;; - c) # CPU set - CPUset="$OPTARG" - ;; - \?) #unrecognized option - show help - echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." - printHELP - ;; - esac + case $FLAG in + h) #show help + if [ "$singlelinehelp" -eq "0" ]; then + printHELP + else + printHELP1 + fi + exit + ;; + c) # CPU set + CPUset="$OPTARG" + ;; + \?) #unrecognized option - show help + echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." + printHELP + ;; + esac done shift $((OPTIND-1)) @@ -142,11 +142,11 @@ shift $((OPTIND-1)) if [ "$1" = "help" ] || [ "$#" -ne $NBARGS ]; then -if [ "$#" -ne $NBARGS ]; then - echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" -fi -printHELP - exit + if [ "$#" -ne $NBARGS ]; then + echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" + fi + printHELP + exit fi @@ -164,12 +164,12 @@ checkCommand milk if [ $EXITSTATUS -eq 1 ]; then -echo "" -echo "$(tput setaf 1)$(tput bold) REQUIRED FILES, COMMANDS NOT FOUND: EXITING $(tput sgr0)" -echo "" -exit + echo "" + echo "$(tput setaf 1)$(tput bold) REQUIRED FILES, COMMANDS NOT FOUND: EXITING $(tput sgr0)" + echo "" + exit else -echo "" + echo "" fi diff --git a/scripts/milk-logshimkill b/scripts/milk-logshimkill index 21e47dc4..2c2d4d2c 100755 --- a/scripts/milk-logshimkill +++ b/scripts/milk-logshimkill @@ -4,16 +4,16 @@ EXPECTED_ARGS=1 if [ $# -ne $EXPECTED_ARGS ] then - echo - echo "-------- KILL LOG SHARED MEMORY DATA STREAM ---------" - echo " " - echo "Usage: $0 " - echo " " - echo " INPUT : shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" - echo " " - echo "EXAMPLE : $0 ircam2" - echo " " - exit + echo + echo "-------- KILL LOG SHARED MEMORY DATA STREAM ---------" + echo " " + echo "Usage: $0 " + echo " " + echo " INPUT : shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" + echo " " + echo "EXAMPLE : $0 ircam2" + echo " " + exit fi pname="$0-$1" diff --git a/scripts/milk-logshimoff b/scripts/milk-logshimoff index ee624d2c..edd07c51 100755 --- a/scripts/milk-logshimoff +++ b/scripts/milk-logshimoff @@ -4,16 +4,16 @@ EXPECTED_ARGS=1 if [ $# -ne $EXPECTED_ARGS ] then - echo - echo "-------- STOP LOG SHARED MEMORY DATA STREAM ---------" - echo " " - echo "Usage: $0 " - echo " " - echo " INPUT : shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" - echo " " - echo "EXAMPLE : $0 ircam2" - echo " " - exit + echo + echo "-------- STOP LOG SHARED MEMORY DATA STREAM ---------" + echo " " + echo "Usage: $0 " + echo " " + echo " INPUT : shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" + echo " " + echo "EXAMPLE : $0 ircam2" + echo " " + exit fi pname="$0-$1" diff --git a/scripts/milk-logshimon b/scripts/milk-logshimon index d5aecc0e..5fc05ace 100755 --- a/scripts/milk-logshimon +++ b/scripts/milk-logshimon @@ -4,16 +4,16 @@ EXPECTED_ARGS=1 if [ $# -ne $EXPECTED_ARGS ] then - echo - echo "-------- RESUME LOG SHARED MEMORY DATA STREAM ---------" - echo " " - echo "Usage: $0 " - echo " " - echo " INPUT : shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" - echo " " - echo "EXAMPLE : $0 ircam2" - echo " " - exit + echo + echo "-------- RESUME LOG SHARED MEMORY DATA STREAM ---------" + echo " " + echo "Usage: $0 " + echo " " + echo " INPUT : shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" + echo " " + echo "EXAMPLE : $0 ircam2" + echo " " + exit fi pname="$0-$1" diff --git a/scripts/milk-logshimstat b/scripts/milk-logshimstat index 51b13957..82573eb9 100755 --- a/scripts/milk-logshimstat +++ b/scripts/milk-logshimstat @@ -4,16 +4,16 @@ EXPECTED_ARGS=1 if [ $# -ne $EXPECTED_ARGS ] then - echo - echo "-------- LOG SHARED MEMORY DATA STREAM STATUS ---------" - echo " " - echo "Usage: $0 " - echo " " - echo " INPUT : shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" - echo " " - echo "EXAMPLE : $0 ircam2" - echo " " - exit + echo + echo "-------- LOG SHARED MEMORY DATA STREAM STATUS ---------" + echo " " + echo "Usage: $0 " + echo " " + echo " INPUT : shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" + echo " " + echo "EXAMPLE : $0 ircam2" + echo " " + exit fi pname="logshimstat-$1" diff --git a/scripts/milk-makecsetandrt b/scripts/milk-makecsetandrt index e23f15ae..ddbf2327 100755 --- a/scripts/milk-makecsetandrt +++ b/scripts/milk-makecsetandrt @@ -4,18 +4,18 @@ EXPECTED_ARGS=3 if [ $# -ne $EXPECTED_ARGS ] then - echo - echo "-------- MOVE PID TO CSET AND ASSIGN RT PRIORITY ---------" - echo " " - echo "Usage: $0 " - echo " " - echo " INPUT : PID to move/elevate" - echo " INPUT : Name of CPU set" - echo " INPUT : RT priority to give to PID - 0 to ignore" - echo " " - echo "EXAMPLE : $0 33654 ircam0_edt 80" - echo " " - exit + echo + echo "-------- MOVE PID TO CSET AND ASSIGN RT PRIORITY ---------" + echo " " + echo "Usage: $0 " + echo " " + echo " INPUT : PID to move/elevate" + echo " INPUT : Name of CPU set" + echo " INPUT : RT priority to give to PID - 0 to ignore" + echo " " + echo "EXAMPLE : $0 33654 ircam0_edt 80" + echo " " + exit fi pname="$0-$1-$2" diff --git a/scripts/milk-procCTRL b/scripts/milk-procCTRL index a8ac1264..034a076c 100755 --- a/scripts/milk-procCTRL +++ b/scripts/milk-procCTRL @@ -10,26 +10,26 @@ echo "pname = $pname" function printHELP { -echo "------------------------------------------------------------------------" -echo "$(tput bold) $pname : loop processes control $(tput sgr0)" -echo "------------------------------------------------------------------------" -echo " Monitors and controls loop processes" -echo " " -echo " $(tput bold)USAGE:$(tput sgr0)" -echo " $0 [-hD]" -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -echo " $(tput bold)-D$(tput sgr0) (D)ebug mode, uses valgrind" -echo " $(tput bold)-s$(tput sgr0) use (s)tdio instead of ncurses" -echo " $(tput bold)-q$(tput sgr0) (q)uiet mode, do not print" -echo "" -echo "------------------------------------------------------------------------" + echo "------------------------------------------------------------------------" + echo "$(tput bold) $pname : loop processes control $(tput sgr0)" + echo "------------------------------------------------------------------------" + echo " Monitors and controls loop processes" + echo " " + echo " $(tput bold)USAGE:$(tput sgr0)" + echo " $0 [-hD]" + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + echo " $(tput bold)-D$(tput sgr0) (D)ebug mode, uses valgrind" + echo " $(tput bold)-s$(tput sgr0) use (s)tdio instead of ncurses" + echo " $(tput bold)-q$(tput sgr0) (q)uiet mode, do not print" + echo "" + echo "------------------------------------------------------------------------" } printHELP1 () { - printf "%20s Monitor and control loop processes\n" "$0" + printf "%20s Monitor and control loop processes\n" "$0" } @@ -40,15 +40,15 @@ printHELP1 () # Transform long options to short ones singlelinehelp=0 for arg in "$@"; do - shift - case "$arg" in - "--help") set -- "$@" "-h" ;; - "--help1") -set -- "$@" "-h" -singlelinehelp=1; -;; - *) set -- "$@" "$arg" - esac + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--help1") + set -- "$@" "-h" + singlelinehelp=1; + ;; + *) set -- "$@" "$arg" + esac done @@ -56,32 +56,32 @@ done DEBUG="0" while getopts :hDsq FLAG; do - case $FLAG in - h) #show help - if [ "$singlelinehelp" -eq "0" ]; then - printHELP - else - printHELP1 - fi - exit - ;; - s) # use stdio instead of ncurses - export MILK_TUIPRINT_STDIO=1 - ;; - q) # quiet mode - don't print status - export MILK_TUIPRINT_NONE=1 - ;; - D) - DEBUG="1" - ;; - \?) - echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." - printHELP - ;; - esac + case $FLAG in + h) #show help + if [ "$singlelinehelp" -eq "0" ]; then + printHELP + else + printHELP1 + fi + exit + ;; + s) # use stdio instead of ncurses + export MILK_TUIPRINT_STDIO=1 + ;; + q) # quiet mode - don't print status + export MILK_TUIPRINT_NONE=1 + ;; + D) + DEBUG="1" + ;; + \?) + echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." + printHELP + ;; + esac done -shift $((OPTIND-1)) +shift $((OPTIND-1)) ### End getopts code ### @@ -91,11 +91,11 @@ shift $((OPTIND-1)) if [ "$1" = "help" ] || [ "$#" -ne $NBARGS ]; then -if [ "$#" -ne $NBARGS ]; then - echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" -fi -printHELP - exit + if [ "$#" -ne $NBARGS ]; then + echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" + fi + printHELP + exit fi @@ -108,25 +108,23 @@ echo "exitCLI" >> $SF if [ "$DEBUG" = "1" ]; then -cp $(which milk) milkdebugtest -OPTION="--leak-check=full --show-leak-kinds=all" -OPTION="$OPTION --track-origins=yes" -OPTION="$OPTION --num-callers=200" -OPTION="$OPTION --show-reachable=yes" -#OPTION="$OPTION --gen-suppressions=all" -OPTION="$OPTION --log-file=milk.memcheck.log" -OPTION="$OPTION --suppressions=$MILK_ROOT/milk.memcheck.supp" -OPTION="$OPTION --max-stackframe=4442392" + cp $(which milk) milkdebugtest + OPTION="--leak-check=full --show-leak-kinds=all" + OPTION="$OPTION --track-origins=yes" + OPTION="$OPTION --num-callers=200" + OPTION="$OPTION --show-reachable=yes" + #OPTION="$OPTION --gen-suppressions=all" + OPTION="$OPTION --log-file=milk.memcheck.log" + OPTION="$OPTION --suppressions=$MILK_ROOT/milk.memcheck.supp" + OPTION="$OPTION --max-stackframe=4442392" -valgrind ${OPTION} ./milkdebugtest -n ${pname} -f ${fifoname} -s ${SF} -rm ./milkdebugtest + valgrind ${OPTION} ./milkdebugtest -n ${pname} -f ${fifoname} -s ${SF} + rm ./milkdebugtest else -milk -n ${pname} -f ${fifoname} -s ${SF} + milk -n ${pname} -f ${fifoname} -s ${SF} fi rm ${SF} - - diff --git a/scripts/milk-script-std-config b/scripts/milk-script-std-config index 5f9c1578..576e1dde 100755 --- a/scripts/milk-script-std-config +++ b/scripts/milk-script-std-config @@ -12,7 +12,7 @@ set -o pipefail function customcleanup() { - echo "default cleanup" + echo "default cleanup" } @@ -69,55 +69,55 @@ MSopt+=( "chkp:check-prerequ:checkallprerequisitesExit::check all prerequisites spin() { - local CPU=0 - local cpuprobecntlim=10 - local cpuprobecnt=0 - local delay=0.1 - local spincnt=0 - spinstr="▏▎▍▌▋▊▉▊▋▌▍▎" - #spinstr="▁▃▄▅▆▇▆▅▄▃▁ " - #spinstr="/|\\-/|\\-" - - let cpuprobecnt=cpuprobecntlim+1 - echo -n "STARTED $(date -u) " - while : - do - if [[ "${cpuprobecnt}" -gt "${cpuprobecntlim}" ]]; then - CPU=$( pstree -p $THIS_PID | grep -o '([0-9]\+)' | grep -o '[0-9]\+' |\ - xargs ps -o %cpu,cmd -p | awk '{cpu+=$1} END {print cpu}' ) - cpuprobecnt=0 - fi - let cpuprobecnt+=1 - - t1=$( echo "scale=2;${spincnt}*${delay}" | bc ) - local temp=${spinstr#?} - local temp1=${temp:0:4} - - printf " [%s CPU %3.0f%%] %5.1f s" "$temp1" "${CPU}" "${t1}" - local spinstr=$temp${spinstr%"$temp"} - sleep $delay - printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" - let spincnt+=1 + local CPU=0 + local cpuprobecntlim=10 + local cpuprobecnt=0 + local delay=0.1 + local spincnt=0 + spinstr="▏▎▍▌▋▊▉▊▋▌▍▎" + #spinstr="▁▃▄▅▆▇▆▅▄▃▁ " + #spinstr="/|\\-/|\\-" + + let cpuprobecnt=cpuprobecntlim+1 + echo -n "STARTED $(date -u) " + while : + do + if [[ "${cpuprobecnt}" -gt "${cpuprobecntlim}" ]]; then + CPU=$( pstree -p $THIS_PID | grep -o '([0-9]\+)' | grep -o '[0-9]\+' |\ + xargs ps -o %cpu,cmd -p | awk '{cpu+=$1} END {print cpu}' ) + cpuprobecnt=0 + fi + let cpuprobecnt+=1 + + t1=$( echo "scale=2;${spincnt}*${delay}" | bc ) + local temp=${spinstr#?} + local temp1=${temp:0:4} + + printf " [%s CPU %3.0f%%] %5.1f s" "$temp1" "${CPU}" "${t1}" + local spinstr=$temp${spinstr%"$temp"} + sleep $delay + printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" + let spincnt+=1 done } startspin() { - tput civis - # Start the Spinner: - THIS_PID=$$ - spin & - SPIN_PID=$! - #echo "SPIN_PID ${SPIN_PID}" - #echo "THIS_PID ${THIS_PID}" - # Kill the spinner on any signal, including our own exit. - trap "kill -9 $SPIN_PID &> /dev/null" `seq 0 15` + tput civis + # Start the Spinner: + THIS_PID=$$ + spin & + SPIN_PID=$! + #echo "SPIN_PID ${SPIN_PID}" + #echo "THIS_PID ${THIS_PID}" + # Kill the spinner on any signal, including our own exit. + trap "kill -9 $SPIN_PID &> /dev/null" `seq 0 15` } stopspin() { - kill -9 $SPIN_PID &> /dev/null - echo "" - tput cnorm - #settrap + kill -9 $SPIN_PID &> /dev/null + echo "" + tput cnorm + #settrap } diff --git a/scripts/milk-scriptexample b/scripts/milk-scriptexample index 6ae0e163..bbadfa28 100755 --- a/scripts/milk-scriptexample +++ b/scripts/milk-scriptexample @@ -8,7 +8,7 @@ Can span muliple lines " # standard configuration -# +# source milk-script-std-config @@ -97,7 +97,7 @@ exit function redraw() { local str width height length - + width=$(tput cols) height=$(tput lines) str="Width = $width Height = $height" @@ -113,5 +113,3 @@ redraw while true; do : done - - diff --git a/scripts/milk-shm2FITS b/scripts/milk-shm2FITS index 814b6a79..cce2f3d7 100755 --- a/scripts/milk-shm2FITS +++ b/scripts/milk-shm2FITS @@ -3,11 +3,11 @@ EXPECTED_ARGS=2 if [ $# -ne $EXPECTED_ARGS ] then - echo - echo " ---------- write shared memory to FITS file ----------- " - echo - echo " Usage: $0 " - echo + echo + echo " ---------- write shared memory to FITS file ----------- " + echo + echo " Usage: $0 " + echo fi pname=$0 diff --git a/scripts/milk-shm2FITSloop b/scripts/milk-shm2FITSloop index 45d23409..09156538 100755 --- a/scripts/milk-shm2FITSloop +++ b/scripts/milk-shm2FITSloop @@ -6,12 +6,12 @@ trap cleanup EXIT EXPECTED_ARGS=2 if [ $# -ne $EXPECTED_ARGS ] then - echo - echo " ---------- write shared memory to FITS file ----------- " - echo "runs as a simple loop" - echo "" - echo " Usage: $0 " - echo + echo + echo " ---------- write shared memory to FITS file ----------- " + echo "runs as a simple loop" + echo "" + echo " Usage: $0 " + echo fi progname=`basename "$0"` @@ -20,8 +20,8 @@ pname=${tmuxname} function cleanup { - echo "clean exit" - tmux send-keys -t ${tmuxname} "exitCLI" C-m + echo "clean exit" + tmux send-keys -t ${tmuxname} "exitCLI" C-m } @@ -39,10 +39,8 @@ IMCNT=0 while : do - echo "saving count ${IMCNT}" - tmux send-keys -t ${tmuxname} "savefits $1 \"!$1.fits\"" C-m - let IMCNT=IMCNT+1 - sleep $2 + echo "saving count ${IMCNT}" + tmux send-keys -t ${tmuxname} "savefits $1 \"!$1.fits\"" C-m + let IMCNT=IMCNT+1 + sleep $2 done - - diff --git a/scripts/milk-shmimmon b/scripts/milk-shmimmon index 1efcc989..7844ff69 100755 --- a/scripts/milk-shmimmon +++ b/scripts/milk-shmimmon @@ -6,38 +6,38 @@ NBARGS=1 function printHELP { -echo "------------------------------------------------------------------------" -echo "$(tput bold) $0 : EXAMPLE SCRIPT $(tput sgr0)" -echo "------------------------------------------------------------------------" -echo " Monitor image stream" -echo " " -echo " $(tput bold)USAGE:$(tput sgr0)" -echo " $0 [-h] " -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -echo " $(tput bold)-h$(tput sgr0) help" -echo "" -echo " $(tput bold)INPUT:$(tput sgr0)" -echo " data stream" -echo "" -echo "------------------------------------------------------------------------" + echo "------------------------------------------------------------------------" + echo "$(tput bold) $0 : EXAMPLE SCRIPT $(tput sgr0)" + echo "------------------------------------------------------------------------" + echo " Monitor image stream" + echo " " + echo " $(tput bold)USAGE:$(tput sgr0)" + echo " $0 [-h] " + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + echo " $(tput bold)-h$(tput sgr0) help" + echo "" + echo " $(tput bold)INPUT:$(tput sgr0)" + echo " data stream" + echo "" + echo "------------------------------------------------------------------------" } printHELP1 () { - printf "%20s Monitor stream\n" "$0" + printf "%20s Monitor stream\n" "$0" } function checkFile { -if [ -f $1 ] - then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" - else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" - EXITSTATUS=1 -fi + if [ -f $1 ] + then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" + EXITSTATUS=1 + fi } @@ -50,34 +50,34 @@ fi # Transform long options to short ones singlelinehelp=0 for arg in "$@"; do - shift - case "$arg" in - "--help") set -- "$@" "-h" ;; - "--help1") -set -- "$@" "-h" -singlelinehelp=1; -;; - *) set -- "$@" "$arg" - esac + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--help1") + set -- "$@" "-h" + singlelinehelp=1; + ;; + *) set -- "$@" "$arg" + esac done while getopts :h FLAG; do - case $FLAG in - h) #show help - if [ "$singlelinehelp" -eq "0" ]; then - printHELP - else - printHELP1 - fi - exit - ;; - \?) #unrecognized option - show help - echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." - printHELP - ;; - esac + case $FLAG in + h) #show help + if [ "$singlelinehelp" -eq "0" ]; then + printHELP + else + printHELP1 + fi + exit + ;; + \?) #unrecognized option - show help + echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." + printHELP + ;; + esac done shift $((OPTIND-1)) #This tells getopts to move on to the next argument. @@ -88,11 +88,11 @@ shift $((OPTIND-1)) #This tells getopts to move on to the next argument. if [ "$1" = "help" ] || [ "$#" -ne $NBARGS ]; then -if [ "$#" -ne $NBARGS ]; then - echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" -fi -printHELP - exit + if [ "$#" -ne $NBARGS ]; then + echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" + fi + printHELP + exit fi @@ -103,12 +103,12 @@ checkFile ${MILK_SHM_DIR}/$1.im.shm if [ $EXITSTATUS -eq 1 ]; then -echo "" -echo "$(tput setaf 1)$(tput bold) REQUIRED FILE NOT FOUND: EXITING $(tput sgr0)" -echo "" -exit + echo "" + echo "$(tput setaf 1)$(tput bold) REQUIRED FILE NOT FOUND: EXITING $(tput sgr0)" + echo "" + exit else -echo "" + echo "" fi diff --git a/scripts/milk-streamCTRL b/scripts/milk-streamCTRL index 7b5f71f3..cc0bfe30 100755 --- a/scripts/milk-streamCTRL +++ b/scripts/milk-streamCTRL @@ -10,26 +10,26 @@ pname=`echo "$0" | sed "s/\.\///g"` function printHELP { -echo "------------------------------------------------------------------------" -echo "$(tput bold) $pname : data streams control $(tput sgr0)" -echo "------------------------------------------------------------------------" -echo " Monitors and controls shared memory data streams" -echo " " -echo " $(tput bold)USAGE:$(tput sgr0)" -echo " $0 [-hD]" -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -echo " $(tput bold)-D$(tput sgr0) (D)ebug mode, uses valgrind" -echo " $(tput bold)-s$(tput sgr0) use (s)tdio instead of ncurses" -echo " $(tput bold)-q$(tput sgr0) (q)uiet mode, do not print" -echo "" -echo "------------------------------------------------------------------------" + echo "------------------------------------------------------------------------" + echo "$(tput bold) $pname : data streams control $(tput sgr0)" + echo "------------------------------------------------------------------------" + echo " Monitors and controls shared memory data streams" + echo " " + echo " $(tput bold)USAGE:$(tput sgr0)" + echo " $0 [-hD]" + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + echo " $(tput bold)-D$(tput sgr0) (D)ebug mode, uses valgrind" + echo " $(tput bold)-s$(tput sgr0) use (s)tdio instead of ncurses" + echo " $(tput bold)-q$(tput sgr0) (q)uiet mode, do not print" + echo "" + echo "------------------------------------------------------------------------" } printHELP1 () { - printf "%20s Monitor and control loop processes\n" "$0" + printf "%20s Monitor and control loop processes\n" "$0" } @@ -40,15 +40,15 @@ printHELP1 () # Transform long options to short ones singlelinehelp=0 for arg in "$@"; do - shift - case "$arg" in - "--help") set -- "$@" "-h" ;; - "--help1") -set -- "$@" "-h" -singlelinehelp=1; -;; - *) set -- "$@" "$arg" - esac + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--help1") + set -- "$@" "-h" + singlelinehelp=1; + ;; + *) set -- "$@" "$arg" + esac done @@ -56,32 +56,32 @@ done DEBUG="0" while getopts :hDsq FLAG; do - case $FLAG in - h) #show help - if [ "$singlelinehelp" -eq "0" ]; then - printHELP - else - printHELP1 - fi - exit - ;; - s) # use stdio instead of ncurses - export MILK_TUIPRINT_STDIO=1 - ;; - q) # quiet mode - don't print status - export MILK_TUIPRINT_NONE=1 - ;; - D) - DEBUG="1" - ;; - \?) - echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." - printHELP - ;; - esac + case $FLAG in + h) #show help + if [ "$singlelinehelp" -eq "0" ]; then + printHELP + else + printHELP1 + fi + exit + ;; + s) # use stdio instead of ncurses + export MILK_TUIPRINT_STDIO=1 + ;; + q) # quiet mode - don't print status + export MILK_TUIPRINT_NONE=1 + ;; + D) + DEBUG="1" + ;; + \?) + echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." + printHELP + ;; + esac done -shift $((OPTIND-1)) +shift $((OPTIND-1)) ### End getopts code ### @@ -91,11 +91,11 @@ shift $((OPTIND-1)) if [ "$1" = "help" ] || [ "$#" -ne $NBARGS ]; then -if [ "$#" -ne $NBARGS ]; then - echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" -fi -printHELP - exit + if [ "$#" -ne $NBARGS ]; then + echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" + fi + printHELP + exit fi @@ -111,22 +111,22 @@ echo "exitCLI" >> $SF if [ "$DEBUG" = "1" ]; then -cp $(which milk) milkdebugtest -OPTION="--leak-check=full --show-leak-kinds=all" -OPTION="$OPTION --track-origins=yes" -OPTION="$OPTION --num-callers=200" -OPTION="$OPTION --show-reachable=yes" -#OPTION="$OPTION --gen-suppressions=all" -OPTION="$OPTION --log-file=milk.memcheck.log" -OPTION="$OPTION --suppressions=$MILK_ROOT/milk.memcheck.supp" -OPTION="$OPTION --max-stackframe=4442392" + cp $(which milk) milkdebugtest + OPTION="--leak-check=full --show-leak-kinds=all" + OPTION="$OPTION --track-origins=yes" + OPTION="$OPTION --num-callers=200" + OPTION="$OPTION --show-reachable=yes" + #OPTION="$OPTION --gen-suppressions=all" + OPTION="$OPTION --log-file=milk.memcheck.log" + OPTION="$OPTION --suppressions=$MILK_ROOT/milk.memcheck.supp" + OPTION="$OPTION --max-stackframe=4442392" -valgrind ${OPTION} ./milkdebugtest -n ${pname} -f ${fifoname} -s ${SF} -rm ./milkdebugtest + valgrind ${OPTION} ./milkdebugtest -n ${pname} -f ${fifoname} -s ${SF} + rm ./milkdebugtest else -MILK_QUIET=1 milk -n ${pname} -f ${fifoname} -s $SF + MILK_QUIET=1 milk -n ${pname} -f ${fifoname} -s $SF fi diff --git a/scripts/milk-streamlink b/scripts/milk-streamlink index 9720fff2..4b2bc8c3 100755 --- a/scripts/milk-streamlink +++ b/scripts/milk-streamlink @@ -8,35 +8,35 @@ NBARGS=1 pname=`basename "$0"` function printHELP { -echo "------------------------------------------------------------------------" -echo "$(tput bold) $pname : CONNECT TO STREAM $(tput sgr0)" -echo " Full path name : $0" -echo "------------------------------------------------------------------------" -echo " Establishes a stream sym link from TARGET= to LINKNAME=." -echo " Reads conf/streamlink..name.txt to identify source stream." -echo " - Create $MILK_SHM_DIR/.im.shm that points to $MI_SHM_DIR/.im.shm" -echo " - Runs milk, connects to and writes its size to ./conf/streamlink..imsize.txt" -echo " " -echo " $(tput bold)USAGE:$(tput sgr0)" -echo " $0 [-h] " -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -echo " $(tput bold)-h$(tput sgr0) help" -echo " $(tput bold)-p$(tput sgr0) stream prefix" -echo "" -echo " $(tput bold)INPUT:$(tput sgr0)" -echo " stream name (full name: )" -echo "" -echo " $(tput bold)OUTPUT:$(tput sgr0)" -echo " ./conf/streamlink..imsize.txt : stream aimage size" -echo "" -echo "------------------------------------------------------------------------" + echo "------------------------------------------------------------------------" + echo "$(tput bold) $pname : CONNECT TO STREAM $(tput sgr0)" + echo " Full path name : $0" + echo "------------------------------------------------------------------------" + echo " Establishes a stream sym link from TARGET= to LINKNAME=." + echo " Reads conf/streamlink..name.txt to identify source stream." + echo " - Create $MILK_SHM_DIR/.im.shm that points to $MI_SHM_DIR/.im.shm" + echo " - Runs milk, connects to and writes its size to ./conf/streamlink..imsize.txt" + echo " " + echo " $(tput bold)USAGE:$(tput sgr0)" + echo " $0 [-h] " + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + echo " $(tput bold)-h$(tput sgr0) help" + echo " $(tput bold)-p$(tput sgr0) stream prefix" + echo "" + echo " $(tput bold)INPUT:$(tput sgr0)" + echo " stream name (full name: )" + echo "" + echo " $(tput bold)OUTPUT:$(tput sgr0)" + echo " ./conf/streamlink..imsize.txt : stream aimage size" + echo "" + echo "------------------------------------------------------------------------" } printHELP1 () { - printf " $(tput bold)%-25s$(tput sgr0) Connect to shared memory stream\n" "$0" + printf " $(tput bold)%-25s$(tput sgr0) Connect to shared memory stream\n" "$0" } @@ -46,41 +46,41 @@ printHELP1 () # Transform long options to short ones singlelinehelp=0 for arg in "$@"; do - shift - case "$arg" in - "--help") set -- "$@" "-h" ;; - "--help1") -set -- "$@" "-h" -singlelinehelp=1; -;; - *) set -- "$@" "$arg" - esac + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--help1") + set -- "$@" "-h" + singlelinehelp=1; + ;; + *) set -- "$@" "$arg" + esac done SMPREFIX="" while getopts :hp: FLAG; do - case $FLAG in - h) #show help - if [ "$singlelinehelp" -eq "0" ]; then - printHELP - else - printHELP1 - fi - exit - ;; - p) - SMPREFIX="$OPTARG" - ;; - \?) #unrecognized option - show help - echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." - printHELP - ;; - esac + case $FLAG in + h) #show help + if [ "$singlelinehelp" -eq "0" ]; then + printHELP + else + printHELP1 + fi + exit + ;; + p) + SMPREFIX="$OPTARG" + ;; + \?) #unrecognized option - show help + echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." + printHELP + ;; + esac done -shift $((OPTIND-1)) +shift $((OPTIND-1)) fullname="${SMPREFIX}$1" @@ -92,10 +92,10 @@ fullname="${SMPREFIX}$1" if [[ -z "${MILK_SHM_DIR}" ]]; then - echo "ERROR: MILK_SHM_DIR environment variable does not exist: cannot find/access shared memory" - exit + echo "ERROR: MILK_SHM_DIR environment variable does not exist: cannot find/access shared memory" + exit else - SHMDIR="${MILK_SHM_DIR}" + SHMDIR="${MILK_SHM_DIR}" fi echo "SHMDIR = $SHMDIR" @@ -107,16 +107,15 @@ echo "SHMDIR = $SHMDIR" file="./conf/streamlink.$1.name.txt" if [ -a $file ]; then -streamname=$( head -1 $file ) # source -rm $SHMDIR/${fullname}.im.shm # remove dest -ln -s $SHMDIR/${streamname}.im.shm $SHMDIR/${fullname}.im.shm # establish link + streamname=$( head -1 $file ) # source + rm $SHMDIR/${fullname}.im.shm # remove dest + ln -s $SHMDIR/${streamname}.im.shm $SHMDIR/${fullname}.im.shm # establish link -milk << EOF + milk << EOF readshmim ${fullname} readshmimsize ${fullname} "./conf/streamlink.$1.imsize.txt" exitCLI EOF fi - diff --git a/scripts/milkFits2shm b/scripts/milkFits2shm index 560ef1b3..018b8e4b 100755 --- a/scripts/milkFits2shm +++ b/scripts/milkFits2shm @@ -9,48 +9,48 @@ VERBOSE="0" function printHELP { -echo "------------------------------------------------------------------------" -echo "$(tput bold) $pname : Load FITS files to shared memory $(tput sgr0)" -echo " Full path name : $0" -echo "------------------------------------------------------------------------" -echo " Load FITS file to shared memory" -echo " Writes into ./loadedSM/ what has been loaded" -echo " unless -f option, will not re-load unchanged files" -echo " " -echo " $(tput bold)USAGE (conf name output):$(tput sgr0)" -echo " $pname [-hfpr] " -echo " $(tput bold)USAGE (conf name input):$(tput sgr0)" -echo " $pname -c [-hfpr] " -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -echo " $(tput bold)-h$(tput sgr0) help" -echo " $(tput bold)-f$(tput sgr0) force load (even if unchanged file)" -echo " $(tput bold)-c$(tput sgr0) read FITS file name from ./conf/shmim..name.txt directory" -echo " $(tput bold)-p$(tput sgr0) stream prefix" -echo " $(tput bold)-r$(tput sgr0) remove / clear previous stream and associated files" -echo "" -echo " $(tput bold)INPUT:$(tput sgr0)" -echo " filesystem FITS file" -echo " shared memory stream name" -echo "" -echo " $(tput bold)EXAMPLES:$(tput sgr0)" -echo " $pname -f image32.fits ims10" -echo " Load image32.fits to stream ims10" -echo " -f option : force load even if image and stream have not changed" -echo " write \"image32.fits\" into file \"conf/shmim.ims10.name.txt" -echo " echo \"image102.fits\" > conf/shmim.ims10.name.txt" -echo " $pname -c ims10" -echo " Load image102.fits to stream ims10" -echo " $pname -c -p aol3_ ims10" -echo " Load image102.fits to stream aol3_ims10" -echo "" -echo "------------------------------------------------------------------------" + echo "------------------------------------------------------------------------" + echo "$(tput bold) $pname : Load FITS files to shared memory $(tput sgr0)" + echo " Full path name : $0" + echo "------------------------------------------------------------------------" + echo " Load FITS file to shared memory" + echo " Writes into ./loadedSM/ what has been loaded" + echo " unless -f option, will not re-load unchanged files" + echo " " + echo " $(tput bold)USAGE (conf name output):$(tput sgr0)" + echo " $pname [-hfpr] " + echo " $(tput bold)USAGE (conf name input):$(tput sgr0)" + echo " $pname -c [-hfpr] " + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + echo " $(tput bold)-h$(tput sgr0) help" + echo " $(tput bold)-f$(tput sgr0) force load (even if unchanged file)" + echo " $(tput bold)-c$(tput sgr0) read FITS file name from ./conf/shmim..name.txt directory" + echo " $(tput bold)-p$(tput sgr0) stream prefix" + echo " $(tput bold)-r$(tput sgr0) remove / clear previous stream and associated files" + echo "" + echo " $(tput bold)INPUT:$(tput sgr0)" + echo " filesystem FITS file" + echo " shared memory stream name" + echo "" + echo " $(tput bold)EXAMPLES:$(tput sgr0)" + echo " $pname -f image32.fits ims10" + echo " Load image32.fits to stream ims10" + echo " -f option : force load even if image and stream have not changed" + echo " write \"image32.fits\" into file \"conf/shmim.ims10.name.txt" + echo " echo \"image102.fits\" > conf/shmim.ims10.name.txt" + echo " $pname -c ims10" + echo " Load image102.fits to stream ims10" + echo " $pname -c -p aol3_ ims10" + echo " Load image102.fits to stream aol3_ims10" + echo "" + echo "------------------------------------------------------------------------" } printHELP1 () { - printf "%25s Copy FITS files to shared memory\n" "$0" + printf "%25s Copy FITS files to shared memory\n" "$0" } @@ -60,23 +60,23 @@ printHELP1 () EXITSTATUS=0 function checkFile { -if [ -f $1 ] - then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" - else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" - EXITSTATUS=1 -fi + if [ -f $1 ] + then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" + EXITSTATUS=1 + fi } function checkDir { -if [ -d $1 ] - then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) found" - else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) not found" - EXITSTATUS=1 -fi + if [ -d $1 ] + then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) not found" + EXITSTATUS=1 + fi } @@ -88,15 +88,15 @@ fi # Transform long options to short ones singlelinehelp=0 for arg in "$@"; do - shift - case "$arg" in - "--help") set -- "$@" "-h" ;; - "--help1") -set -- "$@" "-h" -singlelinehelp=1; -;; - *) set -- "$@" "$arg" - esac + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--help1") + set -- "$@" "-h" + singlelinehelp=1; + ;; + *) set -- "$@" "$arg" + esac done @@ -106,36 +106,36 @@ SMPREFIX="" CLEARSTREAM="0" while getopts :hfcp:r FLAG; do - case $FLAG in - h) #show help - if [ "$singlelinehelp" -eq "0" ]; then - printHELP - else - printHELP1 - fi - exit - ;; - c) # read from conf - READFROMCONF=1 - NBARGS=1 - ;; - f) - FORCE="1" - ;; - p) - SMPREFIX="$OPTARG" - ;; - r) - CLEARSTREAM="1" - ;; - \?) #unrecognized option - show help - echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." - printHELP - ;; - esac + case $FLAG in + h) #show help + if [ "$singlelinehelp" -eq "0" ]; then + printHELP + else + printHELP1 + fi + exit + ;; + c) # read from conf + READFROMCONF=1 + NBARGS=1 + ;; + f) + FORCE="1" + ;; + p) + SMPREFIX="$OPTARG" + ;; + r) + CLEARSTREAM="1" + ;; + \?) #unrecognized option - show help + echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." + printHELP + ;; + esac done -shift $((OPTIND-1)) +shift $((OPTIND-1)) @@ -144,42 +144,42 @@ shift $((OPTIND-1)) if [ "$1" = "help" ] || [ "$#" -ne $NBARGS ]; then -if [ "$#" -ne $NBARGS ]; then - echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" -fi -printHELP - exit + if [ "$#" -ne $NBARGS ]; then + echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" + fi + printHELP + exit fi # ======================= CHECK REQUIRED FILES ================================= if [ "$READFROMCONF" = "0" ]; then -checkFile $1 + checkFile $1 else -checkFile conf/shmim.$1.name.txt + checkFile conf/shmim.$1.name.txt fi if [ $EXITSTATUS -eq 1 ]; then -echo "" -echo "$(tput setaf 1)$(tput bold) REQUIRED FILES, COMMANDS NOT FOUND: EXITING $(tput sgr0)" -echo "" -exit + echo "" + echo "$(tput setaf 1)$(tput bold) REQUIRED FILES, COMMANDS NOT FOUND: EXITING $(tput sgr0)" + echo "" + exit else -echo "" + echo "" fi if [[ -z "${MILK_SHM_DIR}" ]]; then - echo "ERROR: MILK_SHM_DIR environment variable does not exist: cannot find/access shared memory" - exit + echo "ERROR: MILK_SHM_DIR environment variable does not exist: cannot find/access shared memory" + exit else - SHMDIR="${MILK_SHM_DIR}" + SHMDIR="${MILK_SHM_DIR}" fi echo "SHMDIR = $SHMDIR" @@ -191,13 +191,13 @@ echo "SHMDIR = $SHMDIR" if [ "$READFROMCONF" = "0" ]; then -FITSfname="$1" -STREAMname="$2" -STREAMname0="$2" + FITSfname="$1" + STREAMname="$2" + STREAMname0="$2" else -STREAMname0="$1" -STREAMname="${SMPREFIX}$1" -FITSfname=$( cat ./conf/shmim.$1.name.txt ) + STREAMname0="$1" + STREAMname="${SMPREFIX}$1" + FITSfname=$( cat ./conf/shmim.$1.name.txt ) fi @@ -206,9 +206,9 @@ fi # if it is, resolve link # if [ -L "$FITSfname" ]; then -flink=$( readlink -f $FITSfname ) -rm $FITSfname -rsync -auL $flink $FITSfname + flink=$( readlink -f $FITSfname ) + rm $FITSfname + rsync -auL $flink $FITSfname fi @@ -224,11 +224,11 @@ mkdir -p loadedSM if [ "$CLEARSTREAM" = "1" ]; then # clear stream and associated files -rm ./loadedSM/${STREAMname0}.* -rm $MILK_SHM_DIR/${STREAMname}.im.shm -rm /dev/shm/sem.${STREAMname}.* -rm ./conf/shmim.${STREAMname0}.imsize.txt -rm ./conf/shmim.${STREAMname0}.fits + rm ./loadedSM/${STREAMname0}.* + rm $MILK_SHM_DIR/${STREAMname}.im.shm + rm /dev/shm/sem.${STREAMname}.* + rm ./conf/shmim.${STREAMname0}.imsize.txt + rm ./conf/shmim.${STREAMname0}.fits fi @@ -245,22 +245,22 @@ stat -L --format "%n %s %y" ${FITSfname} > ./loadedSM/${STREAMname0}.FITSinfo str1=$(cat ./loadedSM/${STREAMname0}.FITSinfo.old) str2=$(cat ./loadedSM/${STREAMname0}.FITSinfo) if [ "$str1" = "$str2" ]; then -if [ "$VERBOSE" = "1" ]; then -echo "======= FITS file unchanged ========" -echo "======= LOADfile = $LOADfile ========" -fi -touch ./loadedSM/${STREAMname0}.FITSsame -rm ./loadedSM/${STREAMname0}.FITSchanged &> /dev/null -NEW="0" + if [ "$VERBOSE" = "1" ]; then + echo "======= FITS file unchanged ========" + echo "======= LOADfile = $LOADfile ========" + fi + touch ./loadedSM/${STREAMname0}.FITSsame + rm ./loadedSM/${STREAMname0}.FITSchanged &> /dev/null + NEW="0" else -if [ "$VERBOSE" = "1" ]; then -echo "======= FITS file changed ==========" -echo "======= LOADfile = $LOADfile ========" -fi -rm ./loadedSM/${STREAMname0}.FITSsame &> /dev/null -touch ./loadedSM/${STREAMname0}.FITSchanged -NEW="1" -LOADfile="1" + if [ "$VERBOSE" = "1" ]; then + echo "======= FITS file changed ==========" + echo "======= LOADfile = $LOADfile ========" + fi + rm ./loadedSM/${STREAMname0}.FITSsame &> /dev/null + touch ./loadedSM/${STREAMname0}.FITSchanged + NEW="1" + LOADfile="1" fi rm ./loadedSM/${STREAMname0}.SMloaded.old &> /dev/null @@ -273,22 +273,22 @@ str1=$(cat ./loadedSM/${STREAMname0}.SMinfo.old) str2=$(cat ./loadedSM/${STREAMname0}.SMinfo) if [ "$str1" = "$str2" ]; then -if [ "$VERBOSE" = "1" ]; then -echo "======= SM file unchanged ========" -echo "======= LOADfile = $LOADfile ========" -fi -touch ./loadedSM/${STREAMname0}.SMsame -rm ./loadedSM/${STREAMname0}.SMchanged &> /dev/null -NEW_SM="0" + if [ "$VERBOSE" = "1" ]; then + echo "======= SM file unchanged ========" + echo "======= LOADfile = $LOADfile ========" + fi + touch ./loadedSM/${STREAMname0}.SMsame + rm ./loadedSM/${STREAMname0}.SMchanged &> /dev/null + NEW_SM="0" else -if [ "$VERBOSE" = "1" ]; then -echo "======= SM file changed ==========" -echo "======= LOADfile = $LOADfile ========" -fi -rm ./loadedSM/${STREAMname0}.SMsame &> /dev/null -touch ./loadedSM/${STREAMname0}.SMchanged -NEW_SM="1" -LOADfile="1" + if [ "$VERBOSE" = "1" ]; then + echo "======= SM file changed ==========" + echo "======= LOADfile = $LOADfile ========" + fi + rm ./loadedSM/${STREAMname0}.SMsame &> /dev/null + touch ./loadedSM/${STREAMname0}.SMchanged + NEW_SM="1" + LOADfile="1" fi rm ./loadedSM/${STREAMname0}.SMinfo.old &> /dev/null @@ -297,28 +297,28 @@ rm ./loadedSM/${STREAMname0}.SMinfo.old &> /dev/null if [ ! -f "$MILK_SHM_DIR/${STREAMname}.im.shm" ]; then -if [ "$VERBOSE" = "1" ]; then -echo "======= SM file missing ==========" -echo "======= LOADfile = $LOADfile ========" -fi -touch ./loadedSM/${STREAMname0}.missing -LOADfile="1" + if [ "$VERBOSE" = "1" ]; then + echo "======= SM file missing ==========" + echo "======= LOADfile = $LOADfile ========" + fi + touch ./loadedSM/${STREAMname0}.missing + LOADfile="1" else -rm ./loadedSM/${STREAMname0}.missing &> /dev/null + rm ./loadedSM/${STREAMname0}.missing &> /dev/null fi if [ "$FORCE" = "1" ]; then -if [ "$VERBOSE" = "1" ]; then -echo "======= FORCE MODE ==========" -echo "======= LOADfile = $LOADfile ========" -fi -LOADfile="1" + if [ "$VERBOSE" = "1" ]; then + echo "======= FORCE MODE ==========" + echo "======= LOADfile = $LOADfile ========" + fi + LOADfile="1" fi if [ "$VERBOSE" = "1" ]; then -echo "======= LOADfile = $LOADfile ========" + echo "======= LOADfile = $LOADfile ========" fi @@ -327,7 +327,7 @@ fi if [ "$LOADfile" = "1" ]; then -./AOloopControl -n $pname << EOF + ./AOloopControl -n $pname << EOF loadfits "${FITSfname}" im readshmim "${STREAMname}" cpsh im "${STREAMname}" @@ -335,23 +335,21 @@ readshmimsize ${STREAMname} "./loadedSM/${STREAMname0}.imsize" exitCLI EOF -# copy imsize to conf -cp ./loadedSM/${STREAMname0}.imsize ./conf/shmim.${STREAMname0}.imsize.txt -# add link to conf -rm ./conf/shmim.${STREAMname0}.fits -ln -s ${PWD}/${FITSfname} ./conf/shmim.${STREAMname0}.fits + # copy imsize to conf + cp ./loadedSM/${STREAMname0}.imsize ./conf/shmim.${STREAMname0}.imsize.txt + # add link to conf + rm ./conf/shmim.${STREAMname0}.fits + ln -s ${PWD}/${FITSfname} ./conf/shmim.${STREAMname0}.fits -# write SM stat AFTER it has been updated -stat -L --format "%n %s %y" $MILK_SHM_DIR/${STREAMname}.im.shm > ./loadedSM/${STREAMname0}.SMinfo -rm ./loadedSM/${STREAMname0}.kept &> /dev/null -touch ./loadedSM/${STREAMname0}.changed + # write SM stat AFTER it has been updated + stat -L --format "%n %s %y" $MILK_SHM_DIR/${STREAMname}.im.shm > ./loadedSM/${STREAMname0}.SMinfo + rm ./loadedSM/${STREAMname0}.kept &> /dev/null + touch ./loadedSM/${STREAMname0}.changed else -touch ./loadedSM/${STREAMname0}.kept -rm ./loadedSM/${STREAMname0}.changed &> /dev/null + touch ./loadedSM/${STREAMname0}.kept + rm ./loadedSM/${STREAMname0}.changed &> /dev/null fi - - diff --git a/scripts/pyshmimview b/scripts/pyshmimview index 0ce3c23d..246a1aa7 100755 --- a/scripts/pyshmimview +++ b/scripts/pyshmimview @@ -9,12 +9,10 @@ import time from PIL import Image home = os.getenv('HOME') -sys.path.append(home+'/src/lib/python/') +sys.path.append(home + '/src/lib/python/') import matplotlib.colors as cmaps #import colormaps as cmaps -from scexao_shm import shm - - +from scexao_shm import shm hmsg = """ @@ -48,9 +46,9 @@ ESC : quit shmview """ args = sys.argv[1:] -if args == []: +if args == []: print(hmsg) - cam = shm("$MILK_SHM_DIR/ircam%d.im.shm" % (2,)) + cam = shm("$MILK_SHM_DIR/ircam%d.im.shm" % (2, )) else: cam = shm(args[0]) @@ -73,7 +71,7 @@ else: # ----------------------- pygame.init() -FPS = 20 # frames per second setting +FPS = 20 # frames per second setting fpsClock = pygame.time.Clock() # start the pygame clock! XW, YW = 650, 712 XW, YW = zoom * xsize, zoom * ysize @@ -81,6 +79,7 @@ XW, YW = zoom * xsize, zoom * ysize screen = pygame.display.set_mode((XW, YW), 0, 32) pygame.display.set_caption('shared memory live viewer') + # ------------------------------------------------------------------ # short hands for shared memory data access # ------------------------------------------------------------------ @@ -91,41 +90,43 @@ def get_img_data(check=False): Reads from the already-opened shared memory data structure. ---------------------------------------- ''' - return(cam.get_data(check, True).astype(float)) + return (cam.get_data(check, True).astype(float)) + # ------------------------------------------------------------------ # another short hand to convert numpy array into image for display # ------------------------------------------------------------------ def arr2im(arr, vmin=0., vmax=10000.0, pwr=1.0): - + arr2 = arr.astype('float')**pwr - mmin,mmax = arr2.min(), arr2.max() + mmin, mmax = arr2.min(), arr2.max() #mmax = np.percentile(arr2, 99) arr2 -= mmin - arr2 /= (mmax-mmin) + arr2 /= (mmax - mmin) if zoom != 1: img = Image.fromarray(arr2) - rimg = img.resize((zoom*ysize, zoom*xsize)) + rimg = img.resize((zoom * ysize, zoom * xsize)) rarr = np.asarray(rimg) test = mycmap(rarr) else: test = mycmap(arr2) - return((255*test[:,:,:3]).astype('int')) + return ((255 * test[:, :, :3]).astype('int')) + # ------------------------------------------------------------------ # !!! now we are in business !!!! # ------------------------------------------------------------------ WHITE = (255, 255, 255) -GREEN = ( 0, 255, 0) -BLUE = ( 0, 0, 255) -RED = (255, 0, 0) -BLK = ( 0, 0, 0) +GREEN = (0, 255, 0) +BLUE = (0, 0, 255) +RED = (255, 0, 0) +BLK = (0, 0, 0) FGCOL = WHITE # foreground color (text) -BGCOL = BLK # background color -BTCOL = BLUE # *button* color +BGCOL = BLK # background color +BTCOL = BLUE # *button* color background = pygame.Surface(screen.get_size()) background = background.convert() @@ -134,34 +135,32 @@ background.fill(BLK) # ---------------------------- # labels # ---------------------------- -font1 = pygame.font.SysFont("default", 48) -font2 = pygame.font.SysFont("default", 30) +font1 = pygame.font.SysFont("default", 48) +font2 = pygame.font.SysFont("default", 30) font3 = pygame.font.SysFont("monospace", 16) -xws = xsize*zoom -yws = ysize*zoom +xws = xsize * zoom +yws = ysize * zoom imin, imax = 0, 0 -surf_live = pygame.surface.Surface((zoom*xsize, zoom*ysize)) +surf_live = pygame.surface.Surface((zoom * xsize, zoom * ysize)) #screen.blit(surf_live, (5,5)) rect1 = surf_live.get_rect() -rect1.center = (xws/2, yws/2) - -temp = get_img_data() +rect1.center = (xws / 2, yws / 2) +temp = get_img_data() plot_cross = True # flag for display of the crosses -subt_bias = False # flag for bias subtraction -cont_acq = False -lin_scale = True # flag for linear range -clr_scale = False # flag for the display color scale +subt_bias = False # flag for bias subtraction +cont_acq = False +lin_scale = True # flag for linear range +clr_scale = False # flag for the display color scale bias = np.zeros_like(temp) - # ======================================================= # ======================================================= -while True: # the main game loop +while True: # the main game loop clicked = False pwr0 = 1.0 @@ -173,20 +172,19 @@ while True: # the main game loop mycmap = cmaps.inferno # read image - temp = get_img_data() + temp = get_img_data() imin, imax = temp.min(), temp.max() temp -= imin - myim = arr2im(temp.transpose(), pwr=pwr0) + myim = arr2im(temp.transpose(), pwr=pwr0) imax = np.percentile(temp, 99.95) - msg = ""#"(min,max) = (%5d,%5d)" % (imin, imax) + msg = "" #"(min,max) = (%5d,%5d)" % (imin, imax) # display information pygame.surfarray.blit_array(surf_live, myim) screen.blit(surf_live, rect1) - # ===================================== for event in pygame.event.get(): @@ -195,7 +193,7 @@ while True: # the main game loop # close shared memory access # -------------------------- - cam.close() # global disp map + cam.close() # global disp map print("shmview has ended normally.") sys.exit() elif event.type == KEYDOWN: @@ -204,7 +202,7 @@ while True: # the main game loop pygame.quit() # close shared memory access # -------------------------- - cam.close() # global disp map + cam.close() # global disp map print("shmview has ended normally.") sys.exit() if event.key == K_m: diff --git a/scripts/runidle b/scripts/runidle index e2176866..dcb09ec1 100755 --- a/scripts/runidle +++ b/scripts/runidle @@ -13,22 +13,22 @@ tidle=2000 # 2 sec while [ 1 ]; do -if ps -p $PID > /dev/null -then -# echo "$PID is running" - if [ `xprintidle` -gt "$tidle" ]; - then - echo "idle for more than $tidle ms -> continue process $PID" - kill -CONT $PID - else - echo "stopping process $PID" - kill -STOP $PID - fi -else - echo "$PID is not running -> exit runidle" - exit -fi + if ps -p $PID > /dev/null + then + # echo "$PID is running" + if [ `xprintidle` -gt "$tidle" ]; + then + echo "idle for more than $tidle ms -> continue process $PID" + kill -CONT $PID + else + echo "stopping process $PID" + kill -STOP $PID + fi + else + echo "$PID is not running -> exit runidle" + exit + fi -sleep 1 + sleep 1 done diff --git a/scripts/shmimview2 b/scripts/shmimview2 index 2c9fde47..87ca0d8d 100755 --- a/scripts/shmimview2 +++ b/scripts/shmimview2 @@ -6,135 +6,124 @@ import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm #import pyfits as pf -import pdb import threading import mmap -import struct +import struct import os #import Image import time from PIL import Image - - - - class shm: ''' ------------------------------------------------------------- - Shared memory data structure for images + Shared memory data structure for images ------------------------------------------------------------- ''' def __init__(self, fname=None, verbose=True): if fname == None: print("No shared memory file name provided") - return(None) + return (None) try: self.fd = os.open(fname, os.O_RDWR) except: - print("File %s is not a shared memory file" % (fname,)) - return(None) + print("File %s is not a shared memory file" % (fname, )) + return (None) fsz = os.path.getsize(fname) #print ("file %s size = %d bytes" % (fname, fsz)) self.buf = mmap.mmap(self.fd, 0, mmap.MAP_SHARED) self.read_meta_data(verbose=verbose) - - def close(self,): + def close(self, ): self.buf.close() os.close(self.fd) - def read_meta_data(self, verbose=True): buf = self.buf - self.imname = str(buf[0:80]).strip('\x00') # image name - self.naxis, = struct.unpack('l', buf[80:88]) # array dimension - self.size = struct.unpack('lll', buf[88:112]) # array size - self.nel, = struct.unpack('l', buf[112:120]) # nb. elements - self.idtype, = struct.unpack('l', buf[120:128]) # image dtype - self.crtime, = struct.unpack('d', buf[128:136]) # creation time - self.latime, = struct.unpack('d', buf[136:144]) # last access time - - self.shared, = struct.unpack('i', buf[164:168]) # flag - self.write, = struct.unpack('i', buf[168:172]) # flag - - self.status, = struct.unpack('i', buf[172:176]) - self.cnt0, = struct.unpack('l', buf[176:184]) # counter - self.cnt1, = struct.unpack('l', buf[184:192]) # counter - self.nbkw = struct.unpack('l', buf[192:200]) # nb of keywords + self.imname = str(buf[0:80]).strip('\x00') # image name + self.naxis, = struct.unpack('l', buf[80:88]) # array dimension + self.size = struct.unpack('lll', buf[88:112]) # array size + self.nel, = struct.unpack('l', buf[112:120]) # nb. elements + self.idtype, = struct.unpack('l', buf[120:128]) # image dtype + self.crtime, = struct.unpack('d', buf[128:136]) # creation time + self.latime, = struct.unpack('d', buf[136:144]) # last access time + + self.shared, = struct.unpack('i', buf[164:168]) # flag + self.write, = struct.unpack('i', buf[168:172]) # flag + + self.status, = struct.unpack('i', buf[172:176]) + self.cnt0, = struct.unpack('l', buf[176:184]) # counter + self.cnt1, = struct.unpack('l', buf[184:192]) # counter + self.nbkw = struct.unpack('l', buf[192:200]) # nb of keywords self.naxis = 2 self.size = (self.size[0], self.size[1], 0) - self.nel = self.size[0]*self.size[1] + self.nel = self.size[0] * self.size[1] self.elt_sz = 2 self.ddtype = np.int32 - if self.idtype == 1: # C-char + if self.idtype == 1: # C-char self.elt_sz = 1 self.ddtype = np.str - if self.idtype == 2: # C-long + if self.idtype == 2: # C-long self.elt_sz = 4 self.ddtype = np.int32 - - if self.idtype == 3: # C-float - self.elt_sz = 4 + + if self.idtype == 3: # C-float + self.elt_sz = 4 self.ddtype = np.float32 - if self.idtype == 4: # C-double - self.elt_sz= 8 + if self.idtype == 4: # C-double + self.elt_sz = 8 self.ddtype = np.float64 - if self.idtype == 7: # C-ushort - self.elt_sz= 2 + if self.idtype == 7: # C-ushort + self.elt_sz = 2 self.ddtype = np.ushort if verbose: - print("imname = %s" % (self.imname,)) - print("naxis = %d" % (self.naxis,)) - print("xs, ys, zs = %d, %d, %d" % self.size) - print("image data type %d" % (self.idtype,)) - print("image counter = %d" % (self.cnt0,)) - print("SHARED %d" % (self.shared,)) + print("imname = %s" % (self.imname, )) + print("naxis = %d" % (self.naxis, )) + print("xs, ys, zs = %d, %d, %d" % self.size) + print("image data type %d" % (self.idtype, )) + print("image counter = %d" % (self.cnt0, )) + print("SHARED %d" % (self.shared, )) # ------ - def get_data(self,check=False,reform=True): + def get_data(self, check=False, reform=True): if check: - cnt, = struct.unpack('l', self.buf[176:184]) # current counter val + cnt, = struct.unpack('l', self.buf[176:184]) # current counter val while (cnt <= self.cnt0): time.sleep(0.001) - cnt, = struct.unpack('l', self.buf[168:176]) + cnt, = struct.unpack('l', self.buf[168:176]) self.cnt0 = cnt - - data = np.fromstring( - self.buf[200:200+self.nel*self.elt_sz], dtype=self.ddtype) + + data = np.fromstring(self.buf[200:200 + self.nel * self.elt_sz], + dtype=self.ddtype) if reform: data = data.reshape(self.size[:self.naxis][::-1]) - return(data) + return (data) # ------ def get_counter(self): - self.cnt0, = struct.unpack('l', self.buf[176:184]) # counter + self.cnt0, = struct.unpack('l', self.buf[176:184]) # counter return self.cnt0 # ------ def set_data(self, data): aa = array.array('f', (np.hstack(data.astype('f'))).tolist()) try: - self.buf[200:200+self.nel*self.elt_sz] = aa.tostring() - counter, = struct.unpack('l', self.buf[176:184]) + self.buf[200:200 + self.nel * self.elt_sz] = aa.tostring() + counter, = struct.unpack('l', self.buf[176:184]) counter += 1 self.buf[176:184] = struct.pack('l', counter) except: print("Failed to write buffer to shared mem structure") - return(True) - - - - + return (True) hmsg = """ @@ -172,9 +161,9 @@ ESC : quit shmview """ args = sys.argv[1:] -if args == []: +if args == []: print(hmsg) - cam = shm("$MILK_SHM_DIR/ircam%d.im.shm" % (2,)) + cam = shm("$MILK_SHM_DIR/ircam%d.im.shm" % (2, )) else: cam = shm(args[0]) @@ -209,7 +198,7 @@ else: # ----------------------- pygame.init() -FPS = 20 # frames per second setting +FPS = 20 # frames per second setting fpsClock = pygame.time.Clock() # start the pygame clock! XW, YW = 650, 712 XW, YW = zoom * xsize, zoom * ysize @@ -218,6 +207,7 @@ screen = pygame.display.set_mode((XW, YW), 0, 32) #pygame.display.set_caption('shared memory live viewer') pygame.display.set_caption(args[0]) + # ------------------------------------------------------------------ # short hands for shared memory data access # ------------------------------------------------------------------ @@ -228,42 +218,44 @@ def get_img_data(check=False): Reads from the already-opened shared memory data structure. ---------------------------------------- ''' - return(cam.get_data(check, True).astype(float)) + return (cam.get_data(check, True).astype(float)) + # ------------------------------------------------------------------ # another short hand to convert numpy array into image for display # ------------------------------------------------------------------ def arr2im(arr, vmin=0., vmax=10000.0, pwr=1.0, mmin=None, mmax=None): - - arr2 = arr.astype('float') - if mmin is None or mmax is None: mmin,mmax = arr2.min(), arr2.max() + + arr2 = arr.astype('float') + if mmin is None or mmax is None: mmin, mmax = arr2.min(), arr2.max() #mmax = np.percentile(arr2, 99) arr2 -= mmin - arr2 /= (mmax-mmin) + arr2 /= (mmax - mmin) if not lin_scale: arr2 = arr2**pwr - + if zoom != 1: img = Image.fromarray(arr2) - rimg = img.resize((zoom*ysize, zoom*xsize)) + rimg = img.resize((zoom * ysize, zoom * xsize)) rarr = np.asarray(rimg) test = mycmap(rarr) else: test = mycmap(arr2) - return((255*test[:,:,:3]).astype('int')) + return ((255 * test[:, :, :3]).astype('int')) + # ------------------------------------------------------------------ # !!! now we are in business !!!! # ------------------------------------------------------------------ WHITE = (255, 255, 255) -GREEN = ( 0, 255, 0) -BLUE = ( 0, 0, 255) -RED = (255, 0, 0) -BLK = ( 0, 0, 0) +GREEN = (0, 255, 0) +BLUE = (0, 0, 255) +RED = (255, 0, 0) +BLK = (0, 0, 0) FGCOL = WHITE # foreground color (text) -BGCOL = BLK # background color -BTCOL = BLUE # *button* color +BGCOL = BLK # background color +BTCOL = BLUE # *button* color background = pygame.Surface(screen.get_size()) background = background.convert() @@ -272,34 +264,32 @@ background.fill(BLK) # ---------------------------- # labels # ---------------------------- -font1 = pygame.font.SysFont("default", 48) -font2 = pygame.font.SysFont("default", 30) +font1 = pygame.font.SysFont("default", 48) +font2 = pygame.font.SysFont("default", 30) font3 = pygame.font.SysFont("monospace", 16) -xws = xsize*zoom -yws = ysize*zoom +xws = xsize * zoom +yws = ysize * zoom imin, imax = 0, 0 -surf_live = pygame.surface.Surface((zoom*xsize, zoom*ysize)) +surf_live = pygame.surface.Surface((zoom * xsize, zoom * ysize)) #screen.blit(surf_live, (5,5)) rect1 = surf_live.get_rect() -rect1.center = (xws/2, yws/2) - -temp = get_img_data() +rect1.center = (xws / 2, yws / 2) +temp = get_img_data() #plot_cross = True # flag for display of the crosses #subt_bias = False # flag for bias subtraction -#cont_acq = False -lin_scale = True # flag for linear range -clr_scale = False # flag for the display color scale +#cont_acq = False +lin_scale = True # flag for linear range +clr_scale = False # flag for the display color scale #bias = np.zeros_like(temp) - # ======================================================= # ======================================================= -while True: # the main game loop +while True: # the main game loop clicked = False pwr0 = 1.0 @@ -311,11 +301,11 @@ while True: # the main game loop mycmap = cm.jet # read image - temp = get_img_data() + temp = get_img_data() imin, imax = temp.min(), temp.max() temp -= imin - myim = arr2im(temp.transpose(), pwr=pwr0, mmin=mindisp, mmax=maxdisp) + myim = arr2im(temp.transpose(), pwr=pwr0, mmin=mindisp, mmax=maxdisp) #imax = np.percentile(temp, 99.95) #msg = "(min,max) = (%5d,%5d)" % (imin, imax) @@ -324,7 +314,6 @@ while True: # the main game loop pygame.surfarray.blit_array(surf_live, myim) screen.blit(surf_live, rect1) - # ===================================== for event in pygame.event.get(): @@ -333,7 +322,7 @@ while True: # the main game loop # close shared memory access # -------------------------- - cam.close() # global disp map + cam.close() # global disp map print("shmview has ended normally.") sys.exit() elif event.type == KEYDOWN: @@ -342,7 +331,7 @@ while True: # the main game loop pygame.quit() # close shared memory access # -------------------------- - cam.close() # global disp map + cam.close() # global disp map print("shmview has ended normally.") sys.exit() if event.key == K_m: diff --git a/setup.py b/setup.py index 0b7e36ba..ab65fba1 100644 --- a/setup.py +++ b/setup.py @@ -10,24 +10,26 @@ class CMakeExtension(Extension): + def __init__(self, name, sourcedir=''): Extension.__init__(self, name, sources=[]) self.sourcedir = os.path.abspath(sourcedir) class CMakeBuildExt(build_ext): + def run(self): try: import pybind11 out = subprocess.check_output(['cmake', '--version']) except: raise RuntimeError( - "CMake and pybind11 must be installed to build the following extensions: " + - ", ".join(e.name for e in self.extensions)) + "CMake and pybind11 must be installed to build the following extensions: " + + ", ".join(e.name for e in self.extensions)) if platform.system() == "Windows": cmake_version = LooseVersion( - re.search(r'version\s*([\d.]+)', out.decode()).group(1)) + re.search(r'version\s*([\d.]+)', out.decode()).group(1)) if cmake_version < '3.1.0': raise RuntimeError("CMake >= 3.1.0 is required on Windows") @@ -40,11 +42,11 @@ def build_extension(self, ext): self.announce("Preparing the build environment", level=3) extdir = os.path.abspath( - os.path.dirname(self.get_ext_fullpath(ext.name))) + os.path.dirname(self.get_ext_fullpath(ext.name))) cmake_args = [ - '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, - '-DPYTHON_EXECUTABLE=' + sys.executable, + '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, + '-DPYTHON_EXECUTABLE=' + sys.executable, ] cfg = 'Debug' if self.debug else 'Release' @@ -52,8 +54,8 @@ def build_extension(self, ext): if platform.system() == "Windows": cmake_args += [ - '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format( - cfg.upper(), extdir) + '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format( + cfg.upper(), extdir) ] if sys.maxsize > 2**32: cmake_args += ['-A', 'x64'] @@ -82,23 +84,23 @@ def build_extension(self, ext): os.makedirs(self.build_temp, exist_ok=True) self.announce("Configuring cmake project", level=3) - subprocess.check_call( - ['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp) - subprocess.check_call( - ['cmake', '--build', '.'] + build_args, cwd=self.build_temp) + subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, + cwd=self.build_temp) + subprocess.check_call(['cmake', '--build', '.'] + build_args, + cwd=self.build_temp) setup( - name='CacaoProcessTools', - version='1.0.0', - author=['Arnaud Sevin'], - author_email=['Arnaud.Sevin@obspm.fr'], - description='A wrap project to use milk with python', - long_description='A wrap project to use milk with python', - ext_modules=[CMakeExtension('CacaoProcessTools')], - install_requires=['pybind11>=2.4', 'wheel', 'cmake'], - setup_requires=['pybind11>=2.4', 'wheel', 'cmake'], - python_requires='>=3', - cmdclass={'build_ext': CMakeBuildExt}, - zip_safe=False, + name='CacaoProcessTools', + version='1.0.0', + author=['Arnaud Sevin'], + author_email=['Arnaud.Sevin@obspm.fr'], + description='A wrap project to use milk with python', + long_description='A wrap project to use milk with python', + ext_modules=[CMakeExtension('CacaoProcessTools')], + install_requires=['pybind11>=2.4', 'wheel', 'cmake'], + setup_requires=['pybind11>=2.4', 'wheel', 'cmake'], + python_requires='>=3', + cmdclass={'build_ext': CMakeBuildExt}, + zip_safe=False, ) diff --git a/src/CLImain.c b/src/CLImain.c index 19929c55..a7a59318 100644 --- a/src/CLImain.c +++ b/src/CLImain.c @@ -1,44 +1,37 @@ #include "milk_config.h" +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include -#include #include "CLIcore_UI.h" +#include - -#define STYLE_BOLD "\033[1m" +#define STYLE_BOLD "\033[1m" #define STYLE_NO_BOLD "\033[22m" - #define STRINGMAXLEN_VERSIONSTRING 80 #define STRINGMAXLEN_APPNAME 40 -int main( - int argc, - char *argv[] -) +int main(int argc, char *argv[]) { char AppName[STRINGMAXLEN_APPNAME]; char *CLI_APPNAME = getenv("MILKCLI_APPNAME"); - if(CLI_APPNAME != NULL) + if (CLI_APPNAME != NULL) { - strncpy(AppName, CLI_APPNAME, STRINGMAXLEN_APPNAME-1); + strncpy(AppName, CLI_APPNAME, STRINGMAXLEN_APPNAME - 1); } else { - strncpy(AppName, "milk", STRINGMAXLEN_APPNAME-1); + strncpy(AppName, "milk", STRINGMAXLEN_APPNAME - 1); } - - if(getenv("MILK_QUIET")) + if (getenv("MILK_QUIET")) { data.quiet = 1; } @@ -47,7 +40,7 @@ int main( data.quiet = 0; } - if(getenv("MILK_ERROREXIT")) + if (getenv("MILK_ERROREXIT")) { data.errorexit = 1; } @@ -56,28 +49,24 @@ int main( data.errorexit = 0; } - // Allocate data.testpointarray #ifndef NDEBUG printf(" [ENABLED] Code test point tracing\n"); -// allocate circular buffer memory - data.testpointarray = (CODETESTPOINT *) malloc(sizeof(CODETESTPOINT) * CODETESTPOINTARRAY_NBCNT); + // allocate circular buffer memory + data.testpointarray = (CODETESTPOINT *)malloc(sizeof(CODETESTPOINT) * CODETESTPOINTARRAY_NBCNT); data.testpointarrayinit = 1; -// initialize loop counter -// loop counter increments when reaching end of circular buffer + // initialize loop counter + // loop counter increments when reaching end of circular buffer data.testpointloopcnt = 0; -// set current entry index to zero + // set current entry index to zero data.testpointcnt = 0; #endif - - - char versionstring[STRINGMAXLEN_VERSIONSTRING]; - snprintf(versionstring, STRINGMAXLEN_VERSIONSTRING, "%d.%02d.%02d%s", - VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_OPTION); + snprintf(versionstring, STRINGMAXLEN_VERSIONSTRING, "%d.%02d.%02d%s", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, + VERSION_OPTION); - if(data.quiet == 0) + if (data.quiet == 0) { printf(STYLE_BOLD); printf("\n milk v %s\n", versionstring); @@ -85,7 +74,7 @@ int main( printf(" === DEBUG MODE : assert() & DEBUG_TRACEPOINT enabled ===\n"); #endif printf(STYLE_NO_BOLD); - if(data.errorexit == 1) + if (data.errorexit == 1) { printf(" EXIT-ON-ERROR mode\n"); } @@ -93,7 +82,6 @@ int main( strcpy(data.package_name, PACKAGE_NAME); - data.package_version_major = VERSION_MAJOR; data.package_version_minor = VERSION_MINOR; data.package_version_patch = VERSION_PATCH; @@ -104,8 +92,7 @@ int main( strcpy(data.configdir, CONFIGDIR); strcpy(data.installdir, INSTALLDIR); - - if(data.quiet == 0) + if (data.quiet == 0) { //printf(" %s version %s\n", data.package_name, data.package_version); #ifdef IMAGESTRUCT_VERSION @@ -122,10 +109,10 @@ int main( runCLI(argc, argv, AppName); - //errno_t CLIretval = RETURN_SUCCESS; - if(data.quiet == 0) { + if (data.quiet == 0) + { printf("EXIT CODE %d\n", data.exitcode); } else @@ -133,13 +120,12 @@ int main( printf("\n"); } - // clean-up calling thread //pthread_exit(NULL); #ifndef NDEBUG - if(getenv("MILK_WRITECODETRACE")) + if (getenv("MILK_WRITECODETRACE")) { write_tracedebugfile(); } diff --git a/src/COREMOD_arith/COREMOD_arith.c b/src/COREMOD_arith/COREMOD_arith.c index c6ddd268..0b6d2e05 100644 --- a/src/COREMOD_arith/COREMOD_arith.c +++ b/src/COREMOD_arith/COREMOD_arith.c @@ -7,7 +7,6 @@ * */ - /* ================================================================== */ /* ================================================================== */ /* MODULE INFO */ @@ -20,13 +19,7 @@ #define MODULE_SHORTNAME_DEFAULT "" // Module short description -#define MODULE_DESCRIPTION "Image arithmetic operations" - - - - - - +#define MODULE_DESCRIPTION "Image arithmetic operations" /* ================================================================== */ /* ================================================================== */ @@ -34,69 +27,53 @@ /* ================================================================== */ /* ================================================================== */ - - - -#include -#include -#include #include +#include #include +#include +#include #include -#include +#include #include - #ifdef _OPENMP #include #define OMP_NELEMENT_LIMIT 1000000 #endif - -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" #include "COREMOD_tools/COREMOD_tools.h" - +#include "CommandLineInterface/CLIcore.h" //#include "COREMOD_arith/COREMOD_arith.h" - -#include "set_pixel.h" #include "image_crop.h" +#include "image_dxdy.h" #include "image_merge3D.h" -#include "image_total.h" #include "image_stats.h" -#include "image_dxdy.h" +#include "image_total.h" #include "imfunctions.h" +#include "set_pixel.h" -#include "mathfuncs.h" #include "image_arith__im__im.h" -#include "image_arith__im_im__im.h" #include "image_arith__im_f__im.h" #include "image_arith__im_f_f__im.h" +#include "image_arith__im_im__im.h" +#include "mathfuncs.h" #include "execute_arith.h" - - /* ================================================================== */ /* ================================================================== */ /* MACROS, DEFINES */ /* ================================================================== */ /* ================================================================== */ - #ifndef M_PI #define M_PI 3.14159265358979323846 #endif - - - - - - /* ================================================================== */ /* ================================================================== */ /* INITIALIZE LIBRARY */ @@ -108,64 +85,31 @@ // INIT_MODULE_LIB(COREMOD_arith) - - - - /* ================================================================== */ /* ================================================================== */ /* COMMAND LINE INTERFACE (CLI) FUNCTIONS */ /* ================================================================== */ /* ================================================================== */ - - - - - - static errno_t init_module_CLI() { - image_crop_addCLIcmd(); + image_crop_addCLIcmd(); - set_pixel_addCLIcmd(); + set_pixel_addCLIcmd(); - image_arith__im_f_f__im_addCLIcmd(); - - image_merge3D_addCLIcmd(); + image_arith__im_f_f__im_addCLIcmd(); + image_merge3D_addCLIcmd(); // add atexit functions here return RETURN_SUCCESS; } - - - - - errno_t init_COREMOD_arith() { init_module_CLI(); return RETURN_SUCCESS; } - - - - - - - - - - - - - - - - - diff --git a/src/COREMOD_arith/COREMOD_arith.h b/src/COREMOD_arith/COREMOD_arith.h index 7932cb51..203820fa 100644 --- a/src/COREMOD_arith/COREMOD_arith.h +++ b/src/COREMOD_arith/COREMOD_arith.h @@ -1,26 +1,24 @@ #ifndef _ARITH_H #define _ARITH_H - //void __attribute__ ((constructor)) libinit_COREMOD_arith(); //int init_COREMOD_arith(); -#include "COREMOD_arith/set_pixel.h" +#include "COREMOD_arith/execute_arith.h" +#include "COREMOD_arith/image_arith__Cim_Cim__Cim.h" +#include "COREMOD_arith/image_arith__im__im.h" +#include "COREMOD_arith/image_arith__im_f__im.h" +#include "COREMOD_arith/image_arith__im_f_f__im.h" +#include "COREMOD_arith/image_arith__im_im__im.h" #include "COREMOD_arith/image_crop.h" +#include "COREMOD_arith/image_dxdy.h" #include "COREMOD_arith/image_merge3D.h" -#include "COREMOD_arith/image_total.h" #include "COREMOD_arith/image_stats.h" -#include "COREMOD_arith/image_dxdy.h" +#include "COREMOD_arith/image_total.h" #include "COREMOD_arith/imfunctions.h" -#include "COREMOD_arith/image_arith__im__im.h" -#include "COREMOD_arith/image_arith__im_im__im.h" -#include "COREMOD_arith/image_arith__Cim_Cim__Cim.h" -#include "COREMOD_arith/image_arith__im_f__im.h" -#include "COREMOD_arith/image_arith__im_f_f__im.h" -#include "COREMOD_arith/execute_arith.h" +#include "COREMOD_arith/set_pixel.h" //imageID arith_make_slopexy(const char *ID_name, long l1,long l2, double sx, double sy); - #endif diff --git a/src/COREMOD_arith/execute_arith.c b/src/COREMOD_arith/execute_arith.c index 80886c85..b4e8ffa4 100644 --- a/src/COREMOD_arith/execute_arith.c +++ b/src/COREMOD_arith/execute_arith.c @@ -5,173 +5,167 @@ * */ -#include #include +#include -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" +#include "CommandLineInterface/CLIcore.h" -#include "set_pixel.h" +#include "image_arith__Cim_Cim__Cim.h" +#include "image_arith__im__im.h" +#include "image_arith__im_f__im.h" +#include "image_arith__im_f_f__im.h" +#include "image_arith__im_im__im.h" #include "image_crop.h" +#include "image_dxdy.h" #include "image_merge3D.h" -#include "image_total.h" #include "image_stats.h" -#include "image_dxdy.h" +#include "image_total.h" #include "imfunctions.h" -#include "image_arith__im__im.h" -#include "image_arith__im_im__im.h" -#include "image_arith__Cim_Cim__Cim.h" -#include "image_arith__im_f__im.h" -#include "image_arith__im_f_f__im.h" - - - -#define ARITHTOKENTYPE_UNKNOWN 0 -#define ARITHTOKENTYPE_NOTEXIST 1 // non-existing variable or image -#define ARITHTOKENTYPE_VARIABLE 2 -#define ARITHTOKENTYPE_NUMBER 3 -#define ARITHTOKENTYPE_OPERAND 4 -#define ARITHTOKENTYPE_OPENPAR 5 -#define ARITHTOKENTYPE_CLOSEPAR 6 -#define ARITHTOKENTYPE_COMA 7 -#define ARITHTOKENTYPE_FUNCTION 8 -#define ARITHTOKENTYPE_EQUAL 9 -#define ARITHTOKENTYPE_IMAGE 10 -#define ARITHTOKENTYPE_MULTFUNC 11 // function of several variables/images, returning one variable/image - +#include "set_pixel.h" +#define ARITHTOKENTYPE_UNKNOWN 0 +#define ARITHTOKENTYPE_NOTEXIST 1 // non-existing variable or image +#define ARITHTOKENTYPE_VARIABLE 2 +#define ARITHTOKENTYPE_NUMBER 3 +#define ARITHTOKENTYPE_OPERAND 4 +#define ARITHTOKENTYPE_OPENPAR 5 +#define ARITHTOKENTYPE_CLOSEPAR 6 +#define ARITHTOKENTYPE_COMA 7 +#define ARITHTOKENTYPE_FUNCTION 8 +#define ARITHTOKENTYPE_EQUAL 9 +#define ARITHTOKENTYPE_IMAGE 10 +#define ARITHTOKENTYPE_MULTFUNC 11 // function of several variables/images, returning one variable/image int isoperand(const char *word) { int value = 0; - if(strcmp(word, "+") == 0) + if (strcmp(word, "+") == 0) { value = 1; } - if(strcmp(word, "-") == 0) + if (strcmp(word, "-") == 0) { value = 1; } - if(strcmp(word, "/") == 0) + if (strcmp(word, "/") == 0) { value = 1; } - if(strcmp(word, "*") == 0) + if (strcmp(word, "*") == 0) { value = 1; } - if(strcmp(word, "^") == 0) + if (strcmp(word, "^") == 0) { value = 1; } - return(value); + return (value); } - int isfunction(const char *word) { int value = 0; - if(strcmp(word, "acos") == 0) + if (strcmp(word, "acos") == 0) { value = 1; } - if(strcmp(word, "asin") == 0) + if (strcmp(word, "asin") == 0) { value = 1; } - if(strcmp(word, "atan") == 0) + if (strcmp(word, "atan") == 0) { value = 1; } - if(strcmp(word, "ceil") == 0) + if (strcmp(word, "ceil") == 0) { value = 1; } - if(strcmp(word, "cos") == 0) + if (strcmp(word, "cos") == 0) { value = 1; } - if(strcmp(word, "cosh") == 0) + if (strcmp(word, "cosh") == 0) { value = 1; } - if(strcmp(word, "exp") == 0) + if (strcmp(word, "exp") == 0) { value = 1; } - if(strcmp(word, "fabs") == 0) + if (strcmp(word, "fabs") == 0) { value = 1; } - if(strcmp(word, "floor") == 0) + if (strcmp(word, "floor") == 0) { value = 1; } - if(strcmp(word, "imedian") == 0) + if (strcmp(word, "imedian") == 0) { value = 1; } - if(strcmp(word, "itot") == 0) + if (strcmp(word, "itot") == 0) { value = 1; } - if(strcmp(word, "imean") == 0) + if (strcmp(word, "imean") == 0) { value = 1; } - if(strcmp(word, "imin") == 0) + if (strcmp(word, "imin") == 0) { value = 1; } - if(strcmp(word, "imax") == 0) + if (strcmp(word, "imax") == 0) { value = 1; } - if(strcmp(word, "ln") == 0) + if (strcmp(word, "ln") == 0) { value = 1; } - if(strcmp(word, "log") == 0) + if (strcmp(word, "log") == 0) { value = 1; } - if(strcmp(word, "sqrt") == 0) + if (strcmp(word, "sqrt") == 0) { value = 1; } - if(strcmp(word, "sin") == 0) + if (strcmp(word, "sin") == 0) { value = 1; } - if(strcmp(word, "sinh") == 0) + if (strcmp(word, "sinh") == 0) { value = 1; } - if(strcmp(word, "tan") == 0) + if (strcmp(word, "tan") == 0) { value = 1; } - if(strcmp(word, "tanh") == 0) + if (strcmp(word, "tanh") == 0) { value = 1; } - if(strcmp(word, "posi") == 0) + if (strcmp(word, "posi") == 0) { value = 1; } - if(strcmp(word, "imdx") == 0) + if (strcmp(word, "imdx") == 0) { value = 1; } - if(strcmp(word, "imdy") == 0) + if (strcmp(word, "imdy") == 0) { value = 1; } - /* if (!strcmp(word,"pow")) value = 1; if (!strcmp(word,"max")) @@ -181,49 +175,45 @@ int isfunction(const char *word) if (!strcmp(word,"median")) value = 1; */ - return(value); + return (value); } - - int isfunction_sev_var(const char *word) { int value = 0; /* number of input variables */ - if(strcmp(word, "fmod") == 0) + if (strcmp(word, "fmod") == 0) { value = 2; } - if(strcmp(word, "trunc") == 0) + if (strcmp(word, "trunc") == 0) { value = 3; } - if(strcmp(word, "perc") == 0) + if (strcmp(word, "perc") == 0) { value = 2; } - if(strcmp(word, "min") == 0) + if (strcmp(word, "min") == 0) { value = 2; } - if(strcmp(word, "max") == 0) + if (strcmp(word, "max") == 0) { value = 2; } - if(strcmp(word, "testlt") == 0) + if (strcmp(word, "testlt") == 0) { value = 2; } - if(strcmp(word, "testmt") == 0) + if (strcmp(word, "testmt") == 0) { value = 2; } - - return(value); + return (value); } - int isanumber(const char *word) { DEBUG_TRACE_FSTART(); @@ -233,7 +223,7 @@ int isanumber(const char *word) __attribute__((unused)) double v1; v1 = strtod(word, &endptr); - if((long)(endptr - word) == (long) strlen(word)) + if ((long)(endptr - word) == (long)strlen(word)) { value = 1; } @@ -243,19 +233,10 @@ int isanumber(const char *word) } DEBUG_TRACE_FEXIT(); - return(value); + return (value); } - - - -imageID arith_make_slopexy( - const char *ID_name, - long l1, - long l2, - double sx, - double sy -) +imageID arith_make_slopexy(const char *ID_name, long l1, long l2, double sx, double sy) { DEBUG_TRACE_FSTART(); @@ -263,15 +244,14 @@ imageID arith_make_slopexy( uint32_t naxes[2]; double coeff; - create_2Dimage_ID(ID_name, l1, l2, &ID); naxes[0] = data.image[ID].md[0].size[0]; naxes[1] = data.image[ID].md[0].size[1]; coeff = sx * (naxes[0] / 2) + sy * (naxes[1] / 2); - for(uint32_t jj = 0; jj < naxes[1]; jj++) - for(uint32_t ii = 0; ii < naxes[0]; ii++) + for (uint32_t jj = 0; jj < naxes[1]; jj++) + for (uint32_t ii = 0; ii < naxes[0]; ii++) { data.image[ID].array.F[jj * naxes[0] + ii] = sx * ii + sy * jj - coeff; } @@ -280,12 +260,6 @@ imageID arith_make_slopexy( return ID; } - - - - - - /*^----------------------------------------------------------------------------- | int | execute_arith : @@ -317,7 +291,6 @@ int execute_arith(const char *cmd1) int parlevel; int intr_priority[100]; /* 0 (+,-) 1 (*,/) 2 (functions) */ - int found_word_type; int highest_parlevel; int highest_intr_priority; @@ -339,16 +312,13 @@ int execute_arith(const char *cmd1) // if( Debug > 0 ) fprintf(stdout, "[execute_arith]\n"); // if( Debug > 0 ) fprintf(stdout, "[execute_arith] str: [%s]\n", cmd1); - for(int i = 0; i < 100; i++) + for (int i = 0; i < 100; i++) { word_type[i] = 0; par_level[i] = 0; intr_priority[i] = 0; } - - - /* Pre-process string: - remove any spaces in cmd1 @@ -356,22 +326,22 @@ int execute_arith(const char *cmd1) copy result into cmd */ j = 0; - for(int i = 0; i < (int)(strlen(cmd1)); i++) + for (int i = 0; i < (int)(strlen(cmd1)); i++) { - if((cmd1[i] == '=') && (cmd1[i + 1] == '-')) + if ((cmd1[i] == '=') && (cmd1[i + 1] == '-')) { cmd[j] = '='; j++; cmd[j] = '0'; j++; } - else if((cmd1[i] == '=') && (cmd1[i + 1] == '+')) + else if ((cmd1[i] == '=') && (cmd1[i + 1] == '+')) { cmd[j] = '='; j++; i++; } - else if(cmd1[i] != ' ') + else if (cmd1[i] != ' ') { cmd[j] = cmd1[i]; j++; @@ -380,8 +350,6 @@ int execute_arith(const char *cmd1) cmd[j] = '\0'; // if( Debug > 0 ) fprintf(stdout, "[execute_arith] preprocessed str %s -> %s\n", cmd1, cmd); - - /* * cmd is first broken into words. * The spacing between words is operands (+,-,/,*), equal (=), @@ -389,15 +357,14 @@ int execute_arith(const char *cmd1) */ w = 0; l = 0; - for(int i = 0; i < (signed) strlen(cmd); i++) + for (int i = 0; i < (signed)strlen(cmd); i++) { - switch(cmd[i]) + switch (cmd[i]) { case '+': case '-': - if(((cmd[i - 1] == 'e') || (cmd[i - 1] == 'E')) && (isdigit(cmd[i - 2])) - && (isdigit(cmd[i + 1]))) + if (((cmd[i - 1] == 'e') || (cmd[i - 1] == 'E')) && (isdigit(cmd[i - 2])) && (isdigit(cmd[i + 1]))) { // + or - is part of exponent word[w][l] = cmd[i]; @@ -405,7 +372,7 @@ int execute_arith(const char *cmd1) } else { - if(l > 0) + if (l > 0) { word[w][l] = '\0'; w++; @@ -413,7 +380,7 @@ int execute_arith(const char *cmd1) l = 0; word[w][l] = cmd[i]; word[w][1] = '\0'; - if(i < (signed)(strlen(cmd) - 1)) + if (i < (signed)(strlen(cmd) - 1)) { w++; } @@ -428,7 +395,7 @@ int execute_arith(const char *cmd1) case ')': case '=': case ',': - if(l > 0) + if (l > 0) { word[w][l] = '\0'; w++; @@ -436,7 +403,7 @@ int execute_arith(const char *cmd1) l = 0; word[w][l] = cmd[i]; word[w][1] = '\0'; - if(i < (signed)(strlen(cmd) - 1)) + if (i < (signed)(strlen(cmd) - 1)) { w++; } @@ -460,155 +427,140 @@ int execute_arith(const char *cmd1) } } - - if(l > 0) + if (l > 0) { word[w][l] = '\0'; } nbword = w + 1; - // printf("number of words is %d\n",nbword); - for(int i = 0; i < nbword; i++) + for (int i = 0; i < nbword; i++) { - if(Debug > 0) + if (Debug > 0) { printf("TESTING WORD %d = %s\n", i, word[i]); } word_type[i] = ARITHTOKENTYPE_UNKNOWN; found_word_type = 0; - if((isanumber(word[i]) == 1) && (found_word_type == 0)) + if ((isanumber(word[i]) == 1) && (found_word_type == 0)) { word_type[i] = ARITHTOKENTYPE_NUMBER; found_word_type = 1; } - if((isfunction(word[i]) == 1) && (found_word_type == 0)) + if ((isfunction(word[i]) == 1) && (found_word_type == 0)) { word_type[i] = ARITHTOKENTYPE_FUNCTION; found_word_type = 1; } - if((isfunction_sev_var(word[i]) != 0) && (found_word_type == 0)) + if ((isfunction_sev_var(word[i]) != 0) && (found_word_type == 0)) { word_type[i] = ARITHTOKENTYPE_MULTFUNC; found_word_type = 1; } - if((isoperand(word[i]) == 1) && (found_word_type == 0)) + if ((isoperand(word[i]) == 1) && (found_word_type == 0)) { word_type[i] = ARITHTOKENTYPE_OPERAND; found_word_type = 1; } - if((strcmp(word[i], "=") == 0) && (found_word_type == 0)) + if ((strcmp(word[i], "=") == 0) && (found_word_type == 0)) { word_type[i] = ARITHTOKENTYPE_EQUAL; found_word_type = 1; } - if((strcmp(word[i], ",") == 0) && (found_word_type == 0)) + if ((strcmp(word[i], ",") == 0) && (found_word_type == 0)) { word_type[i] = ARITHTOKENTYPE_COMA; found_word_type = 1; } - if((i < nbword - 1) && (found_word_type == 0)) + if ((i < nbword - 1) && (found_word_type == 0)) { - if((strcmp(word[i + 1], "(") == 0) && (isfunction(word[i]) == 1)) + if ((strcmp(word[i + 1], "(") == 0) && (isfunction(word[i]) == 1)) { word_type[i] = ARITHTOKENTYPE_FUNCTION; found_word_type = 1; } } - if((strcmp(word[i], "(") == 0) && (found_word_type == 0)) + if ((strcmp(word[i], "(") == 0) && (found_word_type == 0)) { word_type[i] = ARITHTOKENTYPE_OPENPAR; found_word_type = 1; } - if((strcmp(word[i], ")") == 0) && (found_word_type == 0)) + if ((strcmp(word[i], ")") == 0) && (found_word_type == 0)) { word_type[i] = ARITHTOKENTYPE_CLOSEPAR; found_word_type = 1; } - if((variable_ID(word[i]) != -1) && (found_word_type == 0)) + if ((variable_ID(word[i]) != -1) && (found_word_type == 0)) { word_type[i] = ARITHTOKENTYPE_VARIABLE; found_word_type = 1; } - if((image_ID(word[i]) != -1) && (found_word_type == 0)) + if ((image_ID(word[i]) != -1) && (found_word_type == 0)) { word_type[i] = ARITHTOKENTYPE_IMAGE; found_word_type = 1; } - if(found_word_type == 0) + if (found_word_type == 0) { word_type[i] = ARITHTOKENTYPE_NOTEXIST; } - if(Debug > 0) + if (Debug > 0) { printf("word %d is \"%s\" word type is %d\n", i, word[i], word_type[i]); } } - - - - - - - - /* checks for obvious errors */ passedequ = 0; - for(int i = (nbword - 1); i > -1; i--) + for (int i = (nbword - 1); i > -1; i--) { - if(passedequ == 1) + if (passedequ == 1) { - if(word_type[i] == ARITHTOKENTYPE_EQUAL) + if (word_type[i] == ARITHTOKENTYPE_EQUAL) { PRINT_WARNING("line has multiple \"=\""); OKea = 0; } - if(word_type[i] == ARITHTOKENTYPE_OPERAND) + if (word_type[i] == ARITHTOKENTYPE_OPERAND) { PRINT_WARNING("operand on left side of \"=\""); OKea = 0; } - if(word_type[i] == ARITHTOKENTYPE_OPENPAR) + if (word_type[i] == ARITHTOKENTYPE_OPENPAR) { PRINT_WARNING("\"(\" on left side of \"=\""); OKea = 0; } - if(word_type[i] == ARITHTOKENTYPE_CLOSEPAR) + if (word_type[i] == ARITHTOKENTYPE_CLOSEPAR) { PRINT_WARNING("\")\" on left side of \"=\""); OKea = 0; } } - if(word_type[i] == ARITHTOKENTYPE_EQUAL) + if (word_type[i] == ARITHTOKENTYPE_EQUAL) { passedequ = 1; } - if((passedequ == 0) - && (word_type[i] == - ARITHTOKENTYPE_NOTEXIST)) /* non-existing variable or image as input */ + if ((passedequ == 0) && (word_type[i] == ARITHTOKENTYPE_NOTEXIST)) /* non-existing variable or image as input */ { PRINT_WARNING("%s is a non-existing variable or image", word[i]); OKea = 0; } } - for(int i = 0; i < nbword - 1; i++) + for (int i = 0; i < nbword - 1; i++) { - if((word_type[i] == ARITHTOKENTYPE_OPERAND) - && (word_type[i + 1] == ARITHTOKENTYPE_OPERAND)) + if ((word_type[i] == ARITHTOKENTYPE_OPERAND) && (word_type[i + 1] == ARITHTOKENTYPE_OPERAND)) { PRINT_WARNING("consecutive operands"); OKea = 0; } - if((word_type[i + 1] == ARITHTOKENTYPE_OPENPAR) - && (!((word_type[i] == ARITHTOKENTYPE_OPENPAR) - || (word_type[i] == ARITHTOKENTYPE_FUNCTION) - || (word_type[i] == ARITHTOKENTYPE_MULTFUNC) - || (word_type[i] == ARITHTOKENTYPE_EQUAL) - || (word_type[i] == ARITHTOKENTYPE_OPERAND)))) + if ((word_type[i + 1] == ARITHTOKENTYPE_OPENPAR) && + (!((word_type[i] == ARITHTOKENTYPE_OPENPAR) || (word_type[i] == ARITHTOKENTYPE_FUNCTION) || + (word_type[i] == ARITHTOKENTYPE_MULTFUNC) || (word_type[i] == ARITHTOKENTYPE_EQUAL) || + (word_type[i] == ARITHTOKENTYPE_OPERAND)))) { PRINT_WARNING("\"(\" should be preceeded by \"=\", \"(\", operand or function"); OKea = 0; @@ -616,39 +568,37 @@ int execute_arith(const char *cmd1) } cntP = 0; - for(int i = 0; i < nbword; i++) + for (int i = 0; i < nbword; i++) { - if(word_type[i] == ARITHTOKENTYPE_OPENPAR) + if (word_type[i] == ARITHTOKENTYPE_OPENPAR) { - cntP ++; + cntP++; } - if(word_type[i] == ARITHTOKENTYPE_CLOSEPAR) + if (word_type[i] == ARITHTOKENTYPE_CLOSEPAR) { - cntP --; + cntP--; } - if(cntP < 0) + if (cntP < 0) { PRINT_WARNING("parentheses error"); OKea = 0; } } - if(cntP != 0) + if (cntP != 0) { PRINT_WARNING("parentheses error"); OKea = 0; } - - - if(OKea == 1) + if (OKea == 1) { /* numbers are saved into variables */ tmp_name_index = 0; - for(int i = 0; i < nbword; i++) + for (int i = 0; i < nbword; i++) { - if(word_type[i] == ARITHTOKENTYPE_NUMBER) + if (word_type[i] == ARITHTOKENTYPE_NUMBER) { - CREATE_IMAGENAME(name, "_tmp%d_%d", tmp_name_index, (int) getpid()); + CREATE_IMAGENAME(name, "_tmp%d_%d", tmp_name_index, (int)getpid()); create_variable_ID(name, 1.0 * strtod(word[i], NULL)); strcpy(word[i], name); @@ -660,30 +610,29 @@ int execute_arith(const char *cmd1) /* computing the number of to-be-processed words */ passedequ = 0; nb_tbp_word = 0; - for(int i = (nbword - 1); i > -1; i--) + for (int i = (nbword - 1); i > -1; i--) { - if(word_type[i] == ARITHTOKENTYPE_EQUAL) + if (word_type[i] == ARITHTOKENTYPE_EQUAL) { passedequ = 1; } - if(passedequ == 0) + if (passedequ == 0) { nb_tbp_word++; } } /* main loop starts here */ - while(nb_tbp_word > 1) + while (nb_tbp_word > 1) { /* non necessary braces are removed */ - for(int i = 0; i < nbword - 2; i++) - if((word_type[i] == ARITHTOKENTYPE_OPENPAR) - && (word_type[i + 2] == ARITHTOKENTYPE_CLOSEPAR)) + for (int i = 0; i < nbword - 2; i++) + if ((word_type[i] == ARITHTOKENTYPE_OPENPAR) && (word_type[i + 2] == ARITHTOKENTYPE_CLOSEPAR)) { strcpy(word[i], word[i + 1]); word_type[i] = word_type[i + 1]; - for(j = i + 1; j < nbword - 2; j++) + for (j = i + 1; j < nbword - 2; j++) { strcpy(word[j], word[j + 2]); word_type[j] = word_type[j + 2]; @@ -691,16 +640,14 @@ int execute_arith(const char *cmd1) nbword = nbword - 2; } - for(int i = 0; i < nbword - 3; i++) - if((word_type[i] == ARITHTOKENTYPE_OPENPAR) - && (word_type[i + 3] == ARITHTOKENTYPE_CLOSEPAR) - && (strcmp(word[i + 1], "-") == 0)) + for (int i = 0; i < nbword - 3; i++) + if ((word_type[i] == ARITHTOKENTYPE_OPENPAR) && (word_type[i + 3] == ARITHTOKENTYPE_CLOSEPAR) && + (strcmp(word[i + 1], "-") == 0)) { - data.variable[variable_ID(word[i + 2])].value.f = -data.variable[variable_ID( - word[i + 2])].value.f; + data.variable[variable_ID(word[i + 2])].value.f = -data.variable[variable_ID(word[i + 2])].value.f; strcpy(word[i], word[i + 2]); word_type[i] = word_type[i + 2]; - for(j = i + 2; j < nbword - 3; j++) + for (j = i + 2; j < nbword - 3; j++) { strcpy(word[j], word[j + 3]); word_type[j] = word_type[j + 3]; @@ -711,34 +658,34 @@ int execute_arith(const char *cmd1) /* now the priorities are given */ parlevel = 0; - for(int i = 0; i < nbword; i++) + for (int i = 0; i < nbword; i++) { - if(word_type[i] == ARITHTOKENTYPE_OPENPAR) + if (word_type[i] == ARITHTOKENTYPE_OPENPAR) { parlevel++; } - if(word_type[i] == ARITHTOKENTYPE_CLOSEPAR) + if (word_type[i] == ARITHTOKENTYPE_CLOSEPAR) { parlevel--; } - if((word_type[i] == 4) || (word_type[i] == 8) || (word_type[i] == 11)) + if ((word_type[i] == 4) || (word_type[i] == 8) || (word_type[i] == 11)) { par_level[i] = parlevel; - if(word_type[i] == ARITHTOKENTYPE_FUNCTION) + if (word_type[i] == ARITHTOKENTYPE_FUNCTION) { intr_priority[i] = 2; } - if(word_type[i] == ARITHTOKENTYPE_MULTFUNC) + if (word_type[i] == ARITHTOKENTYPE_MULTFUNC) { intr_priority[i] = 2; } - if(word_type[i] == ARITHTOKENTYPE_OPERAND) + if (word_type[i] == ARITHTOKENTYPE_OPERAND) { - if((strcmp(word[i], "+") == 0) || (strcmp(word[i], "-") == 0)) + if ((strcmp(word[i], "+") == 0) || (strcmp(word[i], "-") == 0)) { intr_priority[i] = 0; } - if((strcmp(word[i], "*") == 0) || (strcmp(word[i], "/") == 0)) + if ((strcmp(word[i], "*") == 0) || (strcmp(word[i], "/") == 0)) { intr_priority[i] = 1; } @@ -751,14 +698,13 @@ int execute_arith(const char *cmd1) highest_intr_priority = -1; highest_priority_index = -1; - for(int i = 0; i < nbword; i++) + for (int i = 0; i < nbword; i++) { - if((word_type[i] == ARITHTOKENTYPE_OPERAND) - || (word_type[i] == ARITHTOKENTYPE_FUNCTION) - || (word_type[i] == ARITHTOKENTYPE_MULTFUNC)) + if ((word_type[i] == ARITHTOKENTYPE_OPERAND) || (word_type[i] == ARITHTOKENTYPE_FUNCTION) || + (word_type[i] == ARITHTOKENTYPE_MULTFUNC)) { /*printf("operation \"%s\" (%d,%d)\n",word[i],par_level[i],intr_priority[i]);*/ - if(par_level[i] > highest_parlevel) + if (par_level[i] > highest_parlevel) { highest_priority_index = i; highest_parlevel = par_level[i]; @@ -766,8 +712,7 @@ int execute_arith(const char *cmd1) } else { - if((par_level[i] == highest_parlevel) - && (intr_priority[i] > highest_intr_priority)) + if ((par_level[i] == highest_parlevel) && (intr_priority[i] > highest_intr_priority)) { highest_priority_index = i; highest_intr_priority = intr_priority[i]; @@ -778,8 +723,6 @@ int execute_arith(const char *cmd1) /* printf("executing operation %s\n",word[highest_priority_index]);*/ - - /* printf("before : "); for (j=0;j - data.variable[variable_ID( - word[highest_priority_index + 4])].value.f) + if (data.variable[variable_ID(word[highest_priority_index + 2])].value.f > + data.variable[variable_ID(word[highest_priority_index + 4])].value.f) { tmp_prec = data.variable[variable_ID(word[highest_priority_index + 2])].value.f; } @@ -1544,42 +1442,40 @@ int execute_arith(const char *cmd1) tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } - else if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) + else if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) { - arith_image_cstmaxv(word[highest_priority_index + 4], - (double) data.variable[variable_ID(word[highest_priority_index + 2])].value.f, - name); + arith_image_cstmaxv( + word[highest_priority_index + 4], + (double)data.variable[variable_ID(word[highest_priority_index + 2])].value.f, name); tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } - else if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == 2)) + else if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == 2)) { - arith_image_cstmaxv(word[highest_priority_index + 2], - (double) data.variable[variable_ID(word[highest_priority_index + 4])].value.f, - name); + arith_image_cstmaxv( + word[highest_priority_index + 2], + (double)data.variable[variable_ID(word[highest_priority_index + 4])].value.f, name); tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } - else if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) + else if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) { - arith_image_maxv(word[highest_priority_index + 2], - word[highest_priority_index + 4], name); + arith_image_maxv(word[highest_priority_index + 2], word[highest_priority_index + 4], name); tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } } - if(strcmp(word[highest_priority_index], "testlt") == 0) + if (strcmp(word[highest_priority_index], "testlt") == 0) { - if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) + if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) { - if(data.variable[variable_ID(word[highest_priority_index + 2])].value.f > - data.variable[variable_ID( - word[highest_priority_index + 4])].value.f) + if (data.variable[variable_ID(word[highest_priority_index + 2])].value.f > + data.variable[variable_ID(word[highest_priority_index + 4])].value.f) { tmp_prec = 0.0; } @@ -1591,29 +1487,28 @@ int execute_arith(const char *cmd1) tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } - else if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) + else if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) { - arith_image_csttestmt(word[highest_priority_index + 4], - (double) data.variable[variable_ID(word[highest_priority_index + 2])].value.f, - name); + arith_image_csttestmt( + word[highest_priority_index + 4], + (double)data.variable[variable_ID(word[highest_priority_index + 2])].value.f, name); tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } - else if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) + else if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) { - arith_image_csttestlt(word[highest_priority_index + 2], - (double) data.variable[variable_ID(word[highest_priority_index + 4])].value.f, - name); + arith_image_csttestlt( + word[highest_priority_index + 2], + (double)data.variable[variable_ID(word[highest_priority_index + 4])].value.f, name); tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } - else if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) + else if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) { - arith_image_testlt(word[highest_priority_index + 2], - word[highest_priority_index + 4], name); + arith_image_testlt(word[highest_priority_index + 2], word[highest_priority_index + 4], name); tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } @@ -1623,14 +1518,13 @@ int execute_arith(const char *cmd1) } } - if(strcmp(word[highest_priority_index], "testmt") == 0) + if (strcmp(word[highest_priority_index], "testmt") == 0) { - if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) + if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) { - if(data.variable[variable_ID(word[highest_priority_index + 2])].value.f > - data.variable[variable_ID( - word[highest_priority_index + 4])].value.f) + if (data.variable[variable_ID(word[highest_priority_index + 2])].value.f > + data.variable[variable_ID(word[highest_priority_index + 4])].value.f) { tmp_prec = 1.0; } @@ -1642,29 +1536,28 @@ int execute_arith(const char *cmd1) tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } - else if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) + else if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) { - arith_image_csttestlt(word[highest_priority_index + 4], - (double) data.variable[variable_ID(word[highest_priority_index + 2])].value.f, - name); + arith_image_csttestlt( + word[highest_priority_index + 4], + (double)data.variable[variable_ID(word[highest_priority_index + 2])].value.f, name); tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } - else if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) + else if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) { - arith_image_csttestmt(word[highest_priority_index + 2], - (double) data.variable[variable_ID(word[highest_priority_index + 4])].value.f, - name); + arith_image_csttestmt( + word[highest_priority_index + 2], + (double)data.variable[variable_ID(word[highest_priority_index + 4])].value.f, name); tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } - else if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) + else if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == ARITHTOKENTYPE_IMAGE)) { - arith_image_testmt(word[highest_priority_index + 2], - word[highest_priority_index + 4], name); + arith_image_testmt(word[highest_priority_index + 2], word[highest_priority_index + 4], name); tmp_name_index++; type = ARITHTOKENTYPE_IMAGE; } @@ -1674,36 +1567,35 @@ int execute_arith(const char *cmd1) } } - - if(strcmp(word[highest_priority_index], "perc") == 0) + if (strcmp(word[highest_priority_index], "perc") == 0) { // printf("%d %d\n",word_type[i+2],word_type[i+4]); - if((word_type[highest_priority_index + 2] != ARITHTOKENTYPE_IMAGE) - || (word_type[highest_priority_index + 4] != 2)) + if ((word_type[highest_priority_index + 2] != ARITHTOKENTYPE_IMAGE) || + (word_type[highest_priority_index + 4] != 2)) { PRINT_ERROR("Wrong input to function perc\n"); } else { // printf("Running percentile args = %s %f\n",word[i+2],data.variable[variable_ID(word[i+4])].value.f); - tmp_prec = arith_image_percentile(word[highest_priority_index + 2], - (double) data.variable[variable_ID(word[highest_priority_index + 4])].value.f); + tmp_prec = arith_image_percentile( + word[highest_priority_index + 2], + (double)data.variable[variable_ID(word[highest_priority_index + 4])].value.f); create_variable_ID(name, tmp_prec); tmp_name_index++; type = 2; } } - if(strcmp(word[highest_priority_index], "trunc") == 0) + if (strcmp(word[highest_priority_index], "trunc") == 0) { - if((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) - && (word_type[highest_priority_index + 4] == 2) - && (word_type[highest_priority_index + 6] == 2)) + if ((word_type[highest_priority_index + 2] == ARITHTOKENTYPE_IMAGE) && + (word_type[highest_priority_index + 4] == 2) && (word_type[highest_priority_index + 6] == 2)) { tmp_name_index++; arith_image_trunc(word[highest_priority_index + 2], - (double) data.variable[variable_ID(word[highest_priority_index + 4])].value.f, - (double) data.variable[variable_ID(word[highest_priority_index + 6])].value.f, + (double)data.variable[variable_ID(word[highest_priority_index + 4])].value.f, + (double)data.variable[variable_ID(word[highest_priority_index + 6])].value.f, name); type = ARITHTOKENTYPE_IMAGE; } @@ -1715,7 +1607,7 @@ int execute_arith(const char *cmd1) strcpy(word[highest_priority_index], name); word_type[highest_priority_index] = type; - for(j = highest_priority_index + 1; j < nbword - (nbvarinput * 2 + 1); j++) + for (j = highest_priority_index + 1; j < nbword - (nbvarinput * 2 + 1); j++) { strcpy(word[j], word[j + (nbvarinput * 2 + 1)]); word_type[j] = word_type[j + (nbvarinput * 2 + 1)]; @@ -1723,9 +1615,6 @@ int execute_arith(const char *cmd1) nbword = nbword - nbvarinput * 2 - 1; } - - - /* printf("after : "); for (i=0;i -1; i--) + for (int i = (nbword - 1); i > -1; i--) { - if(word_type[i] == ARITHTOKENTYPE_EQUAL) + if (word_type[i] == ARITHTOKENTYPE_EQUAL) { passedequ = 1; } - if(passedequ == 0) + if (passedequ == 0) { nb_tbp_word++; } } - } - if(nbword > 2) + if (nbword > 2) { - if(word_type[1] == ARITHTOKENTYPE_EQUAL) + if (word_type[1] == ARITHTOKENTYPE_EQUAL) { - if(variable_ID(word[0]) != -1) + if (variable_ID(word[0]) != -1) { delete_variable_ID(word[0]); } - if(image_ID(word[0]) != -1) + if (image_ID(word[0]) != -1) { delete_image_ID(word[0], DELETE_IMAGE_ERRMODE_WARNING); } - if(word_type[2] == 2) + if (word_type[2] == 2) { create_variable_ID(word[0], data.variable[variable_ID(word[2])].value.f); printf("%.20g\n", data.variable[variable_ID(word[2])].value.f); } - if(word_type[2] == 10) + if (word_type[2] == 10) { chname_image_ID(word[2], word[0]); } @@ -1782,19 +1670,19 @@ int execute_arith(const char *cmd1) printf("%.20g\n", data.variable[variable_ID(word[0])].value.f); } - for(int i = 0; i < tmp_name_index; i++) + for (int i = 0; i < tmp_name_index; i++) { - CREATE_IMAGENAME(name, "_tmp%d_%d", i, (int) getpid()); - if(variable_ID(name) != -1) + CREATE_IMAGENAME(name, "_tmp%d_%d", i, (int)getpid()); + if (variable_ID(name) != -1) { delete_variable_ID(name); } - if(image_ID(name) != -1) + if (image_ID(name) != -1) { delete_image_ID(name, DELETE_IMAGE_ERRMODE_WARNING); } } } - return(0); + return (0); } diff --git a/src/COREMOD_arith/execute_arith.h b/src/COREMOD_arith/execute_arith.h index 5adcadb1..307c209d 100644 --- a/src/COREMOD_arith/execute_arith.h +++ b/src/COREMOD_arith/execute_arith.h @@ -3,14 +3,6 @@ * */ - -imageID arith_make_slopexy( - const char *ID_name, - long l1, - long l2, - double sx, - double sy -); - +imageID arith_make_slopexy(const char *ID_name, long l1, long l2, double sx, double sy); int execute_arith(const char *cmd1); diff --git a/src/COREMOD_arith/image_arith__Cim_Cim__Cim.c b/src/COREMOD_arith/image_arith__Cim_Cim__Cim.c index fefe8771..56df5f69 100644 --- a/src/COREMOD_arith/image_arith__Cim_Cim__Cim.c +++ b/src/COREMOD_arith/image_arith__Cim_Cim__Cim.c @@ -1,30 +1,21 @@ /** * @file image_arith__Cim_Cim__Cim.c * @brief arith functions - * + * * input : complex image, complex image * output: complex image * */ - #include - -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" +#include "CommandLineInterface/CLIcore.h" #include "imfunctions.h" #include "mathfuncs.h" - - - -errno_t arith_image_Cadd( - const char *ID1_name, - const char *ID2_name, - const char *ID_out -) +errno_t arith_image_Cadd(const char *ID1_name, const char *ID2_name, const char *ID_out) { uint8_t atype1, atype2; imageID ID1; @@ -35,30 +26,23 @@ errno_t arith_image_Cadd( atype1 = data.image[ID1].md[0].datatype; atype2 = data.image[ID2].md[0].datatype; - if((atype1 == _DATATYPE_COMPLEX_FLOAT) && (atype2 == _DATATYPE_COMPLEX_FLOAT)) + if ((atype1 == _DATATYPE_COMPLEX_FLOAT) && (atype2 == _DATATYPE_COMPLEX_FLOAT)) { arith_image_function_CF_CF__CF(ID1_name, ID2_name, ID_out, &CPadd_CF_CF); return RETURN_SUCCESS; } - if((atype1 == _DATATYPE_COMPLEX_DOUBLE) - && (atype2 == _DATATYPE_COMPLEX_DOUBLE)) + if ((atype1 == _DATATYPE_COMPLEX_DOUBLE) && (atype2 == _DATATYPE_COMPLEX_DOUBLE)) { arith_image_function_CD_CD__CD(ID1_name, ID2_name, ID_out, &CPadd_CD_CD); return RETURN_SUCCESS; } - PRINT_ERROR( "data types do not match"); + PRINT_ERROR("data types do not match"); return RETURN_FAILURE; } - - -errno_t arith_image_Csub( - const char *ID1_name, - const char *ID2_name, - const char *ID_out -) +errno_t arith_image_Csub(const char *ID1_name, const char *ID2_name, const char *ID_out) { uint8_t datatype1, datatype2; imageID ID1; @@ -69,15 +53,13 @@ errno_t arith_image_Csub( datatype1 = data.image[ID1].md[0].datatype; datatype2 = data.image[ID2].md[0].datatype; - if((datatype1 == _DATATYPE_COMPLEX_FLOAT) - && (datatype2 == _DATATYPE_COMPLEX_FLOAT)) + if ((datatype1 == _DATATYPE_COMPLEX_FLOAT) && (datatype2 == _DATATYPE_COMPLEX_FLOAT)) { arith_image_function_CF_CF__CF(ID1_name, ID2_name, ID_out, &CPsub_CF_CF); return RETURN_SUCCESS; } - if((datatype1 == _DATATYPE_COMPLEX_DOUBLE) - && (datatype2 == _DATATYPE_COMPLEX_DOUBLE)) + if ((datatype1 == _DATATYPE_COMPLEX_DOUBLE) && (datatype2 == _DATATYPE_COMPLEX_DOUBLE)) { arith_image_function_CD_CD__CD(ID1_name, ID2_name, ID_out, &CPsub_CD_CD); return RETURN_SUCCESS; @@ -87,13 +69,7 @@ errno_t arith_image_Csub( return RETURN_FAILURE; } - - -errno_t arith_image_Cmult( - const char *ID1_name, - const char *ID2_name, - const char *ID_out -) +errno_t arith_image_Cmult(const char *ID1_name, const char *ID2_name, const char *ID_out) { uint8_t datatype1, datatype2; imageID ID1; @@ -104,15 +80,13 @@ errno_t arith_image_Cmult( datatype1 = data.image[ID1].md[0].datatype; datatype2 = data.image[ID2].md[0].datatype; - if((datatype1 == _DATATYPE_COMPLEX_FLOAT) - && (datatype2 == _DATATYPE_COMPLEX_FLOAT)) + if ((datatype1 == _DATATYPE_COMPLEX_FLOAT) && (datatype2 == _DATATYPE_COMPLEX_FLOAT)) { arith_image_function_CF_CF__CF(ID1_name, ID2_name, ID_out, &CPmult_CF_CF); return RETURN_SUCCESS; } - if((datatype1 == _DATATYPE_COMPLEX_DOUBLE) - && (datatype2 == _DATATYPE_COMPLEX_DOUBLE)) + if ((datatype1 == _DATATYPE_COMPLEX_DOUBLE) && (datatype2 == _DATATYPE_COMPLEX_DOUBLE)) { arith_image_function_CD_CD__CD(ID1_name, ID2_name, ID_out, &CPmult_CD_CD); return RETURN_SUCCESS; @@ -122,13 +96,7 @@ errno_t arith_image_Cmult( return RETURN_FAILURE; } - - -int arith_image_Cdiv( - const char *ID1_name, - const char *ID2_name, - const char *ID_out -) +int arith_image_Cdiv(const char *ID1_name, const char *ID2_name, const char *ID_out) { uint8_t datatype1, datatype2; imageID ID1; @@ -139,15 +107,13 @@ int arith_image_Cdiv( datatype1 = data.image[ID1].md[0].datatype; datatype2 = data.image[ID2].md[0].datatype; - if((datatype1 == _DATATYPE_COMPLEX_FLOAT) - && (datatype2 == _DATATYPE_COMPLEX_FLOAT)) + if ((datatype1 == _DATATYPE_COMPLEX_FLOAT) && (datatype2 == _DATATYPE_COMPLEX_FLOAT)) { arith_image_function_CF_CF__CF(ID1_name, ID2_name, ID_out, &CPdiv_CF_CF); return RETURN_SUCCESS; } - if((datatype1 == _DATATYPE_COMPLEX_DOUBLE) - && (datatype2 == _DATATYPE_COMPLEX_DOUBLE)) + if ((datatype1 == _DATATYPE_COMPLEX_DOUBLE) && (datatype2 == _DATATYPE_COMPLEX_DOUBLE)) { arith_image_function_CD_CD__CD(ID1_name, ID2_name, ID_out, &CPdiv_CD_CD); return RETURN_SUCCESS; @@ -156,4 +122,3 @@ int arith_image_Cdiv( return RETURN_FAILURE; } - diff --git a/src/COREMOD_arith/image_arith__im__im.c b/src/COREMOD_arith/image_arith__im__im.c index e21589ae..43db4a5f 100644 --- a/src/COREMOD_arith/image_arith__im__im.c +++ b/src/COREMOD_arith/image_arith__im__im.c @@ -1,428 +1,392 @@ /** * @file image_arith__im__im.c * @brief arith functions - * + * * input : image * output: image * */ - #include - -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" +#include "CommandLineInterface/CLIcore.h" #include "imfunctions.h" #include "mathfuncs.h" - - - - - int arith_image_acos_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Pacos); - return(0); + return (0); } - int arith_image_asin_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Pasin); - return(0); + return (0); } - int arith_image_atan_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Patan); - return(0); + return (0); } - int arith_image_ceil_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Pceil); - return(0); + return (0); } - int arith_image_cos_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Pcos); - return(0); + return (0); } - int arith_image_cosh_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Pcosh); - return(0); + return (0); } - int arith_image_exp_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Pexp); - return(0); + return (0); } - int arith_image_fabs_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Pfabs); - return(0); + return (0); } - int arith_image_floor_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Pfloor); - return(0); + return (0); } - int arith_image_ln_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Pln); - return(0); + return (0); } - int arith_image_log_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Plog); - return(0); + return (0); } - int arith_image_sqrt_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Psqrt); - return(0); + return (0); } - int arith_image_sin_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Psin); - return(0); + return (0); } - int arith_image_sinh_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Psinh); - return(0); + return (0); } int arith_image_tan_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Ptan); - return(0); + return (0); } int arith_image_tanh_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Ptanh); - return(0); + return (0); } int arith_image_positive_byID(long ID, long IDout) { arith_image_function_1_1_byID(ID, IDout, &Ppositive); - return(0); + return (0); } - - - int arith_image_acos(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Pacos); - return(0); + return (0); } int arith_image_asin(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Pasin); - return(0); + return (0); } int arith_image_atan(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Patan); - return(0); + return (0); } int arith_image_ceil(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Pceil); - return(0); + return (0); } int arith_image_cos(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Pcos); - return(0); + return (0); } int arith_image_cosh(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Pcosh); - return(0); + return (0); } int arith_image_exp(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Pexp); - return(0); + return (0); } int arith_image_fabs(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Pfabs); - return(0); + return (0); } int arith_image_floor(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Pfloor); - return(0); + return (0); } int arith_image_ln(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Pln); - return(0); + return (0); } int arith_image_log(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Plog); - return(0); + return (0); } int arith_image_sqrt(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Psqrt); - return(0); + return (0); } int arith_image_sin(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Psin); - return(0); + return (0); } int arith_image_sinh(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Psinh); - return(0); + return (0); } int arith_image_tan(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Ptan); - return(0); + return (0); } int arith_image_tanh(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Ptanh); - return(0); + return (0); } int arith_image_positive(const char *ID_name, const char *ID_out) { arith_image_function_1_1(ID_name, ID_out, &Ppositive); - return(0); + return (0); } - - - - - - - int arith_image_acos_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Pacos); - return(0); + return (0); } int arith_image_asin_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Pasin); - return(0); + return (0); } int arith_image_atan_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Patan); - return(0); + return (0); } int arith_image_ceil_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Pceil); - return(0); + return (0); } int arith_image_cos_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Pcos); - return(0); + return (0); } int arith_image_cosh_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Pcosh); - return(0); + return (0); } int arith_image_exp_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Pexp); - return(0); + return (0); } int arith_image_fabs_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Pfabs); - return(0); + return (0); } int arith_image_floor_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Pfloor); - return(0); + return (0); } int arith_image_ln_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Pln); - return(0); + return (0); } int arith_image_log_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Plog); - return(0); + return (0); } int arith_image_sqrt_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Psqrt); - return(0); + return (0); } int arith_image_sin_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Psin); - return(0); + return (0); } int arith_image_sinh_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Psinh); - return(0); + return (0); } int arith_image_tan_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Ptan); - return(0); + return (0); } int arith_image_tanh_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Ptanh); - return(0); + return (0); } int arith_image_positive_inplace_byID(long ID) { arith_image_function_1_1_inplace_byID(ID, &Ppositive); - return(0); + return (0); } - - int arith_image_acos_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Pacos); - return(0); + return (0); } int arith_image_asin_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Pasin); - return(0); + return (0); } int arith_image_atan_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Patan); - return(0); + return (0); } int arith_image_ceil_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Pceil); - return(0); + return (0); } int arith_image_cos_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Pcos); - return(0); + return (0); } int arith_image_cosh_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Pcosh); - return(0); + return (0); } int arith_image_exp_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Pexp); - return(0); + return (0); } int arith_image_fabs_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Pfabs); - return(0); + return (0); } int arith_image_floor_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Pfloor); - return(0); + return (0); } int arith_image_ln_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Pln); - return(0); + return (0); } int arith_image_log_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Plog); - return(0); + return (0); } int arith_image_sqrt_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Psqrt); - return(0); + return (0); } int arith_image_sin_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Psin); - return(0); + return (0); } int arith_image_sinh_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Psinh); - return(0); + return (0); } int arith_image_tan_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Ptan); - return(0); + return (0); } int arith_image_tanh_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Ptanh); - return(0); + return (0); } int arith_image_positive_inplace(const char *ID_name) { arith_image_function_1_1_inplace(ID_name, &Ppositive); - return(0); + return (0); } - - - - diff --git a/src/COREMOD_arith/image_arith__im__im.h b/src/COREMOD_arith/image_arith__im__im.h index 8ef396cb..d78d5952 100644 --- a/src/COREMOD_arith/image_arith__im__im.h +++ b/src/COREMOD_arith/image_arith__im__im.h @@ -3,18 +3,12 @@ * */ - - double Ppositive(double a); - - /* ------------------------------------------------------------------------- */ /* image -> image */ /* ------------------------------------------------------------------------- */ - - int arith_image_acos_byID(long ID, long IDout); int arith_image_asin_byID(long ID, long IDout); int arith_image_atan_byID(long ID, long IDout); @@ -50,10 +44,6 @@ int arith_image_tan(const char *ID_name, const char *ID_out); int arith_image_tanh(const char *ID_name, const char *ID_out); int arith_image_positive(const char *ID_name, const char *ID_out); - - - - int arith_image_acos_inplace_byID(long ID); int arith_image_asin_inplace_byID(long ID); int arith_image_atan_inplace_byID(long ID); @@ -87,4 +77,3 @@ int arith_image_sin_inplace(const char *ID_name); int arith_image_sinh_inplace(const char *ID_name); int arith_image_tan_inplace(const char *ID_name); int arith_image_tanh_inplace(const char *ID_name); - diff --git a/src/COREMOD_arith/image_arith__im_f__im.c b/src/COREMOD_arith/image_arith__im_f__im.c index 6c9741be..e7ec206d 100644 --- a/src/COREMOD_arith/image_arith__im_f__im.c +++ b/src/COREMOD_arith/image_arith__im_f__im.c @@ -1,266 +1,220 @@ /** * @file image_arith__im_f__im.c * @brief arith functions - * + * * input : image, float * output: image * */ - #include - -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" +#include "CommandLineInterface/CLIcore.h" #include "imfunctions.h" #include "mathfuncs.h" - - - - - int arith_image_cstfmod(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Pfmod); - return(0); + return (0); } - int arith_image_cstadd(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Padd); - return(0); + return (0); } - int arith_image_cstsub(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Psub); - return(0); + return (0); } - int arith_image_cstsubm(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Psubm); - return(0); + return (0); } - int arith_image_cstmult(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Pmult); - return(0); + return (0); } - int arith_image_cstdiv(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Pdiv); - return(0); + return (0); } - int arith_image_cstdiv1(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Pdiv1); - return(0); + return (0); } - int arith_image_cstpow(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Ppow); - return(0); + return (0); } - int arith_image_cstmaxv(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Pmaxv); - return(0); + return (0); } - int arith_image_cstminv(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Pminv); - return(0); + return (0); } - int arith_image_csttestlt(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Ptestlt); - return(0); + return (0); } - int arith_image_csttestmt(const char *ID_name, double f1, const char *ID_out) { arith_image_function_1f_1(ID_name, f1, ID_out, &Ptestmt); - return(0); + return (0); } - - - int arith_image_cstfmod_inplace(const char *ID_name, double f1) { arith_image_function_1f_1_inplace(ID_name, f1, &Pfmod); - return(0); + return (0); } - int arith_image_cstadd_inplace(const char *ID_name, double f1) { arith_image_function_1f_1_inplace(ID_name, f1, &Padd); - return(0); + return (0); } - int arith_image_cstsub_inplace(const char *ID_name, double f1) { arith_image_function_1f_1_inplace(ID_name, f1, &Psub); - return(0); + return (0); } - int arith_image_cstmult_inplace(const char *ID_name, double f1) { arith_image_function_1f_1_inplace(ID_name, f1, &Pmult); - return(0); + return (0); } - int arith_image_cstdiv_inplace(const char *ID_name, double f1) { arith_image_function_1f_1_inplace(ID_name, f1, &Pdiv); - return(0); + return (0); } - int arith_image_cstdiv1_inplace(const char *ID_name, double f1) { arith_image_function_1f_1_inplace(ID_name, f1, &Pdiv1); - return(0); + return (0); } - int arith_image_cstpow_inplace(const char *ID_name, double f1) { arith_image_function_1f_1_inplace(ID_name, f1, &Ppow); - return(0); + return (0); } - int arith_image_cstmaxv_inplace(const char *ID_name, double f1) { arith_image_function_1f_1_inplace(ID_name, f1, &Pmaxv); - return(0); + return (0); } - int arith_image_cstminv_inplace(const char *ID_name, double f1) { arith_image_function_1f_1_inplace(ID_name, f1, &Pminv); - return(0); + return (0); } - int arith_image_csttestlt_inplace(const char *ID_name, double f1) { arith_image_function_1f_1_inplace(ID_name, f1, &Ptestlt); - return(0); + return (0); } - int arith_image_csttestmt_inplace(const char *ID_name, double f1) { arith_image_function_1f_1_inplace(ID_name, f1, &Ptestmt); - return(0); + return (0); } - - - int arith_image_cstfmod_inplace_byID(long ID, double f1) { arith_image_function_1f_1_inplace_byID(ID, f1, &Pfmod); - return(0); + return (0); } - int arith_image_cstadd_inplace_byID(long ID, double f1) { arith_image_function_1f_1_inplace_byID(ID, f1, &Padd); - return(0); + return (0); } - int arith_image_cstsub_inplace_byID(long ID, double f1) { arith_image_function_1f_1_inplace_byID(ID, f1, &Psub); - return(0); + return (0); } - int arith_image_cstmult_inplace_byID(long ID, double f1) { arith_image_function_1f_1_inplace_byID(ID, f1, &Pmult); - return(0); + return (0); } - int arith_image_cstdiv_inplace_byID(long ID, double f1) { arith_image_function_1f_1_inplace_byID(ID, f1, &Pdiv); - return(0); + return (0); } - int arith_image_cstdiv1_inplace_byID(long ID, double f1) { arith_image_function_1f_1_inplace_byID(ID, f1, &Pdiv1); - return(0); + return (0); } - int arith_image_cstpow_inplace_byID(long ID, double f1) { arith_image_function_1f_1_inplace_byID(ID, f1, &Ppow); - return(0); + return (0); } - int arith_image_cstmaxv_inplace_byID(long ID, double f1) { arith_image_function_1f_1_inplace_byID(ID, f1, &Pmaxv); - return(0); + return (0); } - int arith_image_cstminv_inplace_byID(long ID, double f1) { arith_image_function_1f_1_inplace_byID(ID, f1, &Pminv); - return(0); + return (0); } - int arith_image_csttestlt_inplace_byID(long ID, double f1) { arith_image_function_1f_1_inplace_byID(ID, f1, &Ptestlt); - return(0); + return (0); } - int arith_image_csttestmt_inplace_byID(long ID, double f1) { arith_image_function_1f_1_inplace_byID(ID, f1, &Ptestmt); - return(0); + return (0); } - - diff --git a/src/COREMOD_arith/image_arith__im_f__im.h b/src/COREMOD_arith/image_arith__im_f__im.h index e439ecd5..95cb82c7 100644 --- a/src/COREMOD_arith/image_arith__im_f__im.h +++ b/src/COREMOD_arith/image_arith__im_f__im.h @@ -3,7 +3,6 @@ * */ - int arith_image_cstfmod(const char *ID_name, double f1, const char *ID_out); int arith_image_cstadd(const char *ID_name, double f1, const char *ID_out); @@ -71,4 +70,3 @@ int arith_image_cstminv_inplace_byID(long ID, double f1); int arith_image_csttestlt_inplace_byID(long ID, double f1); int arith_image_csttestmt_inplace_byID(long ID, double f1); - diff --git a/src/COREMOD_arith/image_arith__im_f_f__im.c b/src/COREMOD_arith/image_arith__im_f_f__im.c index e96daa68..81f32008 100644 --- a/src/COREMOD_arith/image_arith__im_f_f__im.c +++ b/src/COREMOD_arith/image_arith__im_f_f__im.c @@ -1,56 +1,38 @@ /** * @file image_arith__im_f_f__im.c * @brief arith functions - * + * * input : image, float, float * output: image * */ - #include - -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" +#include "CommandLineInterface/CLIcore.h" #include "imfunctions.h" #include "mathfuncs.h" - - - - - // ========================================== // Forward declaration(s) // ========================================== -int arith_image_trunc(const char *ID_name, double f1, double f2, - const char *ID_out); - - +int arith_image_trunc(const char *ID_name, double f1, double f2, const char *ID_out); // ========================================== // Command line interface wrapper function(s) // ========================================== - - static errno_t arith_image_trunc_cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_FLOAT) - + CLI_checkarg(3, CLIARG_FLOAT) - + CLI_checkarg(4, CLIARG_STR_NOT_IMG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_FLOAT) + CLI_checkarg(3, CLIARG_FLOAT) + + CLI_checkarg(4, CLIARG_STR_NOT_IMG) == + 0) { - arith_image_trunc( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numf, - data.cmdargtoken[3].val.numf, - data.cmdargtoken[4].val.string); + arith_image_trunc(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numf, data.cmdargtoken[3].val.numf, + data.cmdargtoken[4].val.string); return CLICMD_SUCCESS; } @@ -60,12 +42,6 @@ static errno_t arith_image_trunc_cli() } } - - - - - - // ========================================== // Register CLI command(s) // ========================================== @@ -73,46 +49,26 @@ static errno_t arith_image_trunc_cli() errno_t image_arith__im_f_f__im_addCLIcmd() { - RegisterCLIcommand( - "imtrunc", - __FILE__, - arith_image_trunc_cli, - "trucate pixel values", - " ", - "imtrunc im 0.0 1.0 out", - "arith_image_trunc(const char *ID_name, double f1, double f2, const char *ID_out)"); - + RegisterCLIcommand("imtrunc", __FILE__, arith_image_trunc_cli, "trucate pixel values", + " ", "imtrunc im 0.0 1.0 out", + "arith_image_trunc(const char *ID_name, double f1, double f2, const char *ID_out)"); return RETURN_SUCCESS; } - - - - - - - - - - -int arith_image_trunc(const char *ID_name, double f1, double f2, - const char *ID_out) +int arith_image_trunc(const char *ID_name, double f1, double f2, const char *ID_out) { arith_image_function_1ff_1(ID_name, f1, f2, ID_out, &Ptrunc); - return(0); + return (0); } int arith_image_trunc_inplace(const char *ID_name, double f1, double f2) { arith_image_function_1ff_1_inplace(ID_name, f1, f2, &Ptrunc); - return(0); + return (0); } int arith_image_trunc_inplace_byID(long ID, double f1, double f2) { arith_image_function_1ff_1_inplace_byID(ID, f1, f2, &Ptrunc); - return(0); + return (0); } - - - diff --git a/src/COREMOD_arith/image_arith__im_f_f__im.h b/src/COREMOD_arith/image_arith__im_f_f__im.h index b78403e8..fe9c5603 100644 --- a/src/COREMOD_arith/image_arith__im_f_f__im.h +++ b/src/COREMOD_arith/image_arith__im_f_f__im.h @@ -2,15 +2,12 @@ * @file image_arith__im_f_f__im.h */ - errno_t image_arith__im_f_f__im_addCLIcmd(); - int arith_image_trunc_byID(long ID, double f1, double f2, long IDout); int arith_image_trunc_inplace_byID(long IDname, double f1, double f2); - int arith_image_trunc(const char *ID_name, double f1, double f2, const char *ID_out); int arith_image_trunc_inplace(const char *ID_name, double f1, double f2); diff --git a/src/COREMOD_arith/image_arith__im_im__im.c b/src/COREMOD_arith/image_arith__im_im__im.c index 373dc1c1..533f9331 100644 --- a/src/COREMOD_arith/image_arith__im_im__im.c +++ b/src/COREMOD_arith/image_arith__im_im__im.c @@ -1,243 +1,195 @@ /** * @file image_arith__im_im__im.c * @brief arith functions - * + * * input : image, image * output: image * */ - #include - -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" +#include "CommandLineInterface/CLIcore.h" #include "imfunctions.h" #include "mathfuncs.h" - - - -int arith_image_fmod(const char *ID1_name, const char *ID2_name, - const char *ID_out) +int arith_image_fmod(const char *ID1_name, const char *ID2_name, const char *ID_out) { arith_image_function_2_1(ID1_name, ID2_name, ID_out, &Pfmod); - return(0); + return (0); } - -int arith_image_pow(const char *ID1_name, const char *ID2_name, - const char *ID_out) +int arith_image_pow(const char *ID1_name, const char *ID2_name, const char *ID_out) { arith_image_function_2_1(ID1_name, ID2_name, ID_out, &Ppow); - return(0); + return (0); } - -int arith_image_add(const char *ID1_name, const char *ID2_name, - const char *ID_out) +int arith_image_add(const char *ID1_name, const char *ID2_name, const char *ID_out) { arith_image_function_2_1(ID1_name, ID2_name, ID_out, &Padd); - return(0); + return (0); } - -int arith_image_sub(const char *ID1_name, const char *ID2_name, - const char *ID_out) +int arith_image_sub(const char *ID1_name, const char *ID2_name, const char *ID_out) { arith_image_function_2_1(ID1_name, ID2_name, ID_out, &Psub); - return(0); + return (0); } - -int arith_image_mult(const char *ID1_name, const char *ID2_name, - const char *ID_out) +int arith_image_mult(const char *ID1_name, const char *ID2_name, const char *ID_out) { arith_image_function_2_1(ID1_name, ID2_name, ID_out, &Pmult); - return(0); + return (0); } - -int arith_image_div(const char *ID1_name, const char *ID2_name, - const char *ID_out) +int arith_image_div(const char *ID1_name, const char *ID2_name, const char *ID_out) { arith_image_function_2_1(ID1_name, ID2_name, ID_out, &Pdiv); - return(0); + return (0); } - -int arith_image_minv(const char *ID1_name, const char *ID2_name, - const char *ID_out) +int arith_image_minv(const char *ID1_name, const char *ID2_name, const char *ID_out) { arith_image_function_2_1(ID1_name, ID2_name, ID_out, &Pminv); - return(0); + return (0); } - -int arith_image_maxv(const char *ID1_name, const char *ID2_name, - const char *ID_out) +int arith_image_maxv(const char *ID1_name, const char *ID2_name, const char *ID_out) { arith_image_function_2_1(ID1_name, ID2_name, ID_out, &Pmaxv); - return(0); + return (0); } - -int arith_image_testlt(const char *ID1_name, const char *ID2_name, - const char *ID_out) +int arith_image_testlt(const char *ID1_name, const char *ID2_name, const char *ID_out) { arith_image_function_2_1(ID1_name, ID2_name, ID_out, &Ptestlt); - return(0); + return (0); } - -int arith_image_testmt(const char *ID1_name, const char *ID2_name, - const char *ID_out) +int arith_image_testmt(const char *ID1_name, const char *ID2_name, const char *ID_out) { arith_image_function_2_1(ID1_name, ID2_name, ID_out, &Ptestmt); - return(0); + return (0); } - int arith_image_fmod_inplace(const char *ID1_name, const char *ID2_name) { arith_image_function_2_1_inplace(ID1_name, ID2_name, &Pfmod); - return(0); + return (0); } - int arith_image_pow_inplace(const char *ID1_name, const char *ID2_name) { arith_image_function_2_1_inplace(ID1_name, ID2_name, &Ppow); - return(0); + return (0); } - int arith_image_add_inplace(const char *ID1_name, const char *ID2_name) { arith_image_function_2_1_inplace(ID1_name, ID2_name, &Padd); - return(0); + return (0); } - int arith_image_sub_inplace(const char *ID1_name, const char *ID2_name) { arith_image_function_2_1_inplace(ID1_name, ID2_name, &Psub); - return(0); + return (0); } - int arith_image_mult_inplace(const char *ID1_name, const char *ID2_name) { arith_image_function_2_1_inplace(ID1_name, ID2_name, &Pmult); - return(0); + return (0); } - int arith_image_div_inplace(const char *ID1_name, const char *ID2_name) { arith_image_function_2_1_inplace(ID1_name, ID2_name, &Pdiv); - return(0); + return (0); } - int arith_image_minv_inplace(const char *ID1_name, const char *ID2_name) { arith_image_function_2_1_inplace(ID1_name, ID2_name, &Pminv); - return(0); + return (0); } - int arith_image_maxv_inplace(const char *ID1_name, const char *ID2_name) { arith_image_function_2_1_inplace(ID1_name, ID2_name, &Pmaxv); - return(0); + return (0); } - int arith_image_testlt_inplace(const char *ID1_name, const char *ID2_name) { arith_image_function_2_1_inplace(ID1_name, ID2_name, &Ptestlt); - return(0); + return (0); } - int arith_image_testmt_inplace(const char *ID1_name, const char *ID2_name) { arith_image_function_2_1_inplace(ID1_name, ID2_name, &Ptestmt); - return(0); + return (0); } - int arith_image_fmod_inplace_byID(long ID1, long ID2) { arith_image_function_2_1_inplace_byID(ID1, ID2, &Pfmod); - return(0); + return (0); } - int arith_image_pow_inplace_byID(long ID1, long ID2) { arith_image_function_2_1_inplace_byID(ID1, ID2, &Ppow); - return(0); + return (0); } - int arith_image_add_inplace_byID(long ID1, long ID2) { arith_image_function_2_1_inplace_byID(ID1, ID2, &Padd); - return(0); + return (0); } - int arith_image_sub_inplace_byID(long ID1, long ID2) { arith_image_function_2_1_inplace_byID(ID1, ID2, &Psub); - return(0); + return (0); } - int arith_image_mult_inplace_byID(long ID1, long ID2) { arith_image_function_2_1_inplace_byID(ID1, ID2, &Pmult); - return(0); + return (0); } int arith_image_div_inplace_byID(long ID1, long ID2) { arith_image_function_2_1_inplace_byID(ID1, ID2, &Pdiv); - return(0); + return (0); } - int arith_image_minv_inplace_byID(long ID1, long ID2) { arith_image_function_2_1_inplace_byID(ID1, ID2, &Pminv); - return(0); + return (0); } - int arith_image_maxv_inplace_byID(long ID1, long ID2) { arith_image_function_2_1_inplace_byID(ID1, ID2, &Pmaxv); - return(0); + return (0); } - int arith_image_testlt_inplace_byID(long ID1, long ID2) { arith_image_function_2_1_inplace_byID(ID1, ID2, &Ptestlt); - return(0); + return (0); } - int arith_image_testmt_inplace_byID(long ID1, long ID2) { arith_image_function_2_1_inplace_byID(ID1, ID2, &Ptestmt); - return(0); + return (0); } - - - - - diff --git a/src/COREMOD_arith/image_arith__im_im__im.h b/src/COREMOD_arith/image_arith__im_im__im.h index ad1b23e6..70da1493 100644 --- a/src/COREMOD_arith/image_arith__im_im__im.h +++ b/src/COREMOD_arith/image_arith__im_im__im.h @@ -3,16 +3,12 @@ * */ - double Ptrunc(double a, double b, double c); - - /* ------------------------------------------------------------------------- */ /* predefined functions image, image -> image */ /* ------------------------------------------------------------------------- */ - int arith_image_fmod_byID(long ID1, long ID2, long IDout); int arith_image_pow_byID(long ID1, long ID2, const char *IDout); int arith_image_add_byID(long ID1, long ID2, long IDout); @@ -30,24 +26,19 @@ int arith_image_mult(const char *ID1_name, const char *ID2_name, const char *ID_ int arith_image_div(const char *ID1_name, const char *ID2_name, const char *ID_out); int arith_image_minv(const char *ID1_name, const char *ID2_name, const char *ID_out); int arith_image_maxv(const char *ID1_name, const char *ID2_name, const char *ID_out); -int arith_image_testlt(const char *ID1_name, const char *ID2_name, - const char *ID_out); -int arith_image_testmt(const char *ID1_name, const char *ID2_name, - const char *ID_out); - - - +int arith_image_testlt(const char *ID1_name, const char *ID2_name, const char *ID_out); +int arith_image_testmt(const char *ID1_name, const char *ID2_name, const char *ID_out); int arith_image_fmod_inplace_byID(long ID1, long ID2); int arith_image_pow_inplace_byID(long ID1, long ID2); int arith_image_add_inplace_byID(long ID1, long ID2); int arith_image_sub_inplace_byID(long ID1, long ID2); int arith_image_mult_inplace_byID(long ID1, long ID2); -int arith_image_div_inplace_byID(long ID1, long ID2); +int arith_image_div_inplace_byID(long ID1, long ID2); int arith_image_minv_inplace_byID(long ID1, long ID2); int arith_image_maxv_inplace_byID(long ID1, long ID2); -int arith_image_fmod_inplace(const char *ID1_name, const char *ID2_name); // ID1 is output +int arith_image_fmod_inplace(const char *ID1_name, const char *ID2_name); // ID1 is output int arith_image_pow_inplace(const char *ID1_name, const char *ID2_name); int arith_image_add_inplace(const char *ID1_name, const char *ID2_name); int arith_image_sub_inplace(const char *ID1_name, const char *ID2_name); diff --git a/src/COREMOD_arith/image_crop.c b/src/COREMOD_arith/image_crop.c index 7d5f20b5..97f57182 100644 --- a/src/COREMOD_arith/image_crop.c +++ b/src/COREMOD_arith/image_crop.c @@ -5,51 +5,20 @@ * */ - -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" - - - - +#include "CommandLineInterface/CLIcore.h" // ========================================== // Forward declaration(s) // ========================================== -imageID arith_image_crop( - const char *ID_name, - const char *ID_out, - long *start, - long *end, - long cropdim -); - - -imageID arith_image_extract2D( - const char *in_name, - const char *out_name, - long size_x, - long size_y, - long xstart, - long ystart -); - - - -imageID arith_image_extract3D( - const char *in_name, - const char *out_name, - long size_x, - long size_y, - long size_z, - long xstart, - long ystart, - long zstart -); - +imageID arith_image_crop(const char *ID_name, const char *ID_out, long *start, long *end, long cropdim); +imageID arith_image_extract2D(const char *in_name, const char *out_name, long size_x, long size_y, long xstart, + long ystart); +imageID arith_image_extract3D(const char *in_name, const char *out_name, long size_x, long size_y, long size_z, + long xstart, long ystart, long zstart); // ========================================== // Command line interface wrapper function(s) @@ -57,22 +26,13 @@ imageID arith_image_extract3D( static errno_t arith_image_extract2D__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_STR_NOT_IMG) - + CLI_checkarg(3, CLIARG_LONG) - + CLI_checkarg(4, CLIARG_LONG) - + CLI_checkarg(5, CLIARG_LONG) - + CLI_checkarg(6, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_STR_NOT_IMG) + CLI_checkarg(3, CLIARG_LONG) + + CLI_checkarg(4, CLIARG_LONG) + CLI_checkarg(5, CLIARG_LONG) + CLI_checkarg(6, CLIARG_LONG) == + 0) { - arith_image_extract2D( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.string, - data.cmdargtoken[3].val.numl, - data.cmdargtoken[4].val.numl, - data.cmdargtoken[5].val.numl, - data.cmdargtoken[6].val.numl); + arith_image_extract2D(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, + data.cmdargtoken[3].val.numl, data.cmdargtoken[4].val.numl, data.cmdargtoken[5].val.numl, + data.cmdargtoken[6].val.numl); return CLICMD_SUCCESS; } @@ -82,29 +42,16 @@ static errno_t arith_image_extract2D__cli() } } - static errno_t arith_image_extract3D__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_STR_NOT_IMG) - + CLI_checkarg(3, CLIARG_LONG) - + CLI_checkarg(4, CLIARG_LONG) - + CLI_checkarg(5, CLIARG_LONG) - + CLI_checkarg(6, CLIARG_LONG) - + CLI_checkarg(7, CLIARG_LONG) - + CLI_checkarg(8, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_STR_NOT_IMG) + CLI_checkarg(3, CLIARG_LONG) + + CLI_checkarg(4, CLIARG_LONG) + CLI_checkarg(5, CLIARG_LONG) + CLI_checkarg(6, CLIARG_LONG) + + CLI_checkarg(7, CLIARG_LONG) + CLI_checkarg(8, CLIARG_LONG) == + 0) { - arith_image_extract3D( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.string, - data.cmdargtoken[3].val.numl, - data.cmdargtoken[4].val.numl, - data.cmdargtoken[5].val.numl, - data.cmdargtoken[6].val.numl, - data.cmdargtoken[7].val.numl, - data.cmdargtoken[8].val.numl); + arith_image_extract3D(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, + data.cmdargtoken[3].val.numl, data.cmdargtoken[4].val.numl, data.cmdargtoken[5].val.numl, + data.cmdargtoken[6].val.numl, data.cmdargtoken[7].val.numl, data.cmdargtoken[8].val.numl); return CLICMD_SUCCESS; } @@ -114,9 +61,6 @@ static errno_t arith_image_extract3D__cli() } } - - - // ========================================== // Register CLI command(s) // ========================================== @@ -124,49 +68,22 @@ static errno_t arith_image_extract3D__cli() errno_t image_crop_addCLIcmd() { - RegisterCLIcommand( - "extractim", - __FILE__, - arith_image_extract2D__cli, - "crop 2D image", - " ", - "extractim im ime 256 256 100 100", - "int arith_image_extract2D(const char *in_name, const char *out_name, long size_x, long size_y, long xstart, long ystart)"); - - - - RegisterCLIcommand( - "extract3Dim", - __FILE__, - arith_image_extract3D__cli, - "crop 3D image", - " ", - "extractim im ime 256 256 5 100 100 0", - "int arith_image_extract3D(const char *in_name, const char *out_name, long size_x, long size_y, long size_z, long xstart, long ystart, long zstart)"); + RegisterCLIcommand("extractim", __FILE__, arith_image_extract2D__cli, "crop 2D image", + " ", + "extractim im ime 256 256 100 100", + "int arith_image_extract2D(const char *in_name, const char *out_name, long size_x, long size_y, " + "long xstart, long ystart)"); + RegisterCLIcommand("extract3Dim", __FILE__, arith_image_extract3D__cli, "crop 3D image", + " ", + "extractim im ime 256 256 5 100 100 0", + "int arith_image_extract3D(const char *in_name, const char *out_name, long size_x, long size_y, " + "long size_z, long xstart, long ystart, long zstart)"); return RETURN_SUCCESS; } - - - - - - - - - - - - -imageID arith_image_crop( - const char *ID_name, - const char *ID_out, - long *start, - long *end, - long cropdim -) +imageID arith_image_crop(const char *ID_name, const char *ID_out, long *start, long *end, long cropdim) { long naxis; imageID IDin; @@ -179,14 +96,14 @@ imageID arith_image_crop( long start_c[3]; long end_c[3]; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { start_c[i] = 0; end_c[i] = 0; } IDin = image_ID(ID_name); - if(IDin == -1) + if (IDin == -1) { PRINT_ERROR("Missing input image = %s", ID_name); list_image_ID(); @@ -194,20 +111,20 @@ imageID arith_image_crop( } naxis = data.image[IDin].md[0].naxis; - if(naxis < 1) + if (naxis < 1) { PRINT_ERROR("naxis < 1"); exit(0); } - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc() error, naxis = %ld", naxis); exit(0); } - naxesout = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxesout == NULL) + naxesout = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxesout == NULL) { PRINT_ERROR("malloc() error"); exit(0); @@ -217,150 +134,145 @@ imageID arith_image_crop( naxes[0] = 0; naxesout[0] = 0; - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[IDin].md[0].size[i]; naxesout[i] = end[i] - start[i]; } - create_image_ID(ID_out, naxis, naxesout, datatype, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); + create_image_ID(ID_out, naxis, naxesout, datatype, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); start_c[0] = start[0]; - if(start_c[0] < 0) + if (start_c[0] < 0) { start_c[0] = 0; } end_c[0] = end[0]; - if(end_c[0] > naxes[0]) + if (end_c[0] > naxes[0]) { end_c[0] = naxes[0]; } - if(naxis > 1) + if (naxis > 1) { start_c[1] = start[1]; - if(start_c[1] < 0) + if (start_c[1] < 0) { start_c[1] = 0; } end_c[1] = end[1]; - if(end_c[1] > naxes[1]) + if (end_c[1] > naxes[1]) { end_c[1] = naxes[1]; } } - if(naxis > 2) + if (naxis > 2) { start_c[2] = start[2]; - if(start_c[2] < 0) + if (start_c[2] < 0) { start_c[2] = 0; } end_c[2] = end[2]; - if(end_c[2] > naxes[2]) + if (end_c[2] > naxes[2]) { end_c[2] = naxes[2]; } } - printf("CROP: \n"); - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { printf("axis %ld: %ld -> %ld\n", i, start_c[i], end_c[i]); } - - if(cropdim != naxis) + if (cropdim != naxis) { - printf("Error (arith_image_crop): cropdim [%ld] and naxis [%ld] are different\n", - cropdim, naxis); + printf("Error (arith_image_crop): cropdim [%ld] and naxis [%ld] are different\n", cropdim, naxis); } - - if(naxis == 1) + if (naxis == 1) { - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.F[ii - start[0]] = data.image[IDin].array.F[ii]; } } - else if(datatype == _DATATYPE_DOUBLE) + else if (datatype == _DATATYPE_DOUBLE) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.D[ii - start[0]] = data.image[IDin].array.D[ii]; } } - else if(datatype == _DATATYPE_COMPLEX_FLOAT) + else if (datatype == _DATATYPE_COMPLEX_FLOAT) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.CF[ii - start[0]].re = data.image[IDin].array.CF[ii].re; data.image[IDout].array.CF[ii - start[0]].im = data.image[IDin].array.CF[ii].im; } } - else if(datatype == _DATATYPE_COMPLEX_DOUBLE) + else if (datatype == _DATATYPE_COMPLEX_DOUBLE) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.CD[ii - start[0]].re = data.image[IDin].array.CD[ii].re; data.image[IDout].array.CD[ii - start[0]].im = data.image[IDin].array.CD[ii].im; } } - else if(datatype == _DATATYPE_UINT8) + else if (datatype == _DATATYPE_UINT8) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.UI8[ii - start[0]] = data.image[IDin].array.UI8[ii]; } } - else if(datatype == _DATATYPE_UINT16) + else if (datatype == _DATATYPE_UINT16) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.UI16[ii - start[0]] = data.image[IDin].array.UI16[ii]; } } - else if(datatype == _DATATYPE_UINT32) + else if (datatype == _DATATYPE_UINT32) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.UI32[ii - start[0]] = data.image[IDin].array.UI32[ii]; } } - else if(datatype == _DATATYPE_UINT64) + else if (datatype == _DATATYPE_UINT64) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.UI64[ii - start[0]] = data.image[IDin].array.UI64[ii]; } } - else if(datatype == _DATATYPE_INT8) + else if (datatype == _DATATYPE_INT8) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.SI8[ii - start[0]] = data.image[IDin].array.SI8[ii]; } } - else if(datatype == _DATATYPE_INT16) + else if (datatype == _DATATYPE_INT16) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.SI16[ii - start[0]] = data.image[IDin].array.SI16[ii]; } } - else if(datatype == _DATATYPE_INT32) + else if (datatype == _DATATYPE_INT32) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.SI32[ii - start[0]] = data.image[IDin].array.SI32[ii]; } } - else if(datatype == _DATATYPE_INT64) + else if (datatype == _DATATYPE_INT64) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) { data.image[IDout].array.SI64[ii - start[0]] = data.image[IDin].array.SI64[ii]; } @@ -371,99 +283,99 @@ imageID arith_image_crop( exit(0); } } - if(naxis == 2) + if (naxis == 2) { - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - data.image[IDout].array.F[(jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.F[jj * naxes[0] + ii]; + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + data.image[IDout].array.F[(jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.F[jj * naxes[0] + ii]; } - else if(datatype == _DATATYPE_DOUBLE) + else if (datatype == _DATATYPE_DOUBLE) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - data.image[IDout].array.D[(jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.D[jj * naxes[0] + ii]; + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + data.image[IDout].array.D[(jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.D[jj * naxes[0] + ii]; } - else if(datatype == _DATATYPE_COMPLEX_FLOAT) + else if (datatype == _DATATYPE_COMPLEX_FLOAT) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) { - data.image[IDout].array.CF[(jj - start[1])*naxesout[0] + (ii - start[0])].re - = data.image[IDin].array.CF[jj * naxes[0] + ii].re; - data.image[IDout].array.CF[(jj - start[1])*naxesout[0] + (ii - start[0])].im - = data.image[IDin].array.CF[jj * naxes[0] + ii].im; + data.image[IDout].array.CF[(jj - start[1]) * naxesout[0] + (ii - start[0])].re = + data.image[IDin].array.CF[jj * naxes[0] + ii].re; + data.image[IDout].array.CF[(jj - start[1]) * naxesout[0] + (ii - start[0])].im = + data.image[IDin].array.CF[jj * naxes[0] + ii].im; } } - else if(datatype == _DATATYPE_COMPLEX_DOUBLE) + else if (datatype == _DATATYPE_COMPLEX_DOUBLE) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) { - data.image[IDout].array.CD[(jj - start[1])*naxesout[0] + (ii - start[0])].re - = data.image[IDin].array.CD[jj * naxes[0] + ii].re; - data.image[IDout].array.CD[(jj - start[1])*naxesout[0] + (ii - start[0])].im - = data.image[IDin].array.CD[jj * naxes[0] + ii].im; + data.image[IDout].array.CD[(jj - start[1]) * naxesout[0] + (ii - start[0])].re = + data.image[IDin].array.CD[jj * naxes[0] + ii].re; + data.image[IDout].array.CD[(jj - start[1]) * naxesout[0] + (ii - start[0])].im = + data.image[IDin].array.CD[jj * naxes[0] + ii].im; } } - else if(datatype == _DATATYPE_UINT8) + else if (datatype == _DATATYPE_UINT8) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - data.image[IDout].array.UI8[(jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.UI8[jj * naxes[0] + ii]; + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + data.image[IDout].array.UI8[(jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.UI8[jj * naxes[0] + ii]; } - else if(datatype == _DATATYPE_UINT16) + else if (datatype == _DATATYPE_UINT16) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - data.image[IDout].array.UI16[(jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.UI16[jj * naxes[0] + ii]; + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + data.image[IDout].array.UI16[(jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.UI16[jj * naxes[0] + ii]; } - else if(datatype == _DATATYPE_UINT32) + else if (datatype == _DATATYPE_UINT32) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - data.image[IDout].array.UI32[(jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.UI32[jj * naxes[0] + ii]; + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + data.image[IDout].array.UI32[(jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.UI32[jj * naxes[0] + ii]; } - else if(datatype == _DATATYPE_UINT64) + else if (datatype == _DATATYPE_UINT64) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - data.image[IDout].array.UI64[(jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.UI64[jj * naxes[0] + ii]; + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + data.image[IDout].array.UI64[(jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.UI64[jj * naxes[0] + ii]; } - else if(datatype == _DATATYPE_INT8) + else if (datatype == _DATATYPE_INT8) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - data.image[IDout].array.SI8[(jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.SI8[jj * naxes[0] + ii]; + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + data.image[IDout].array.SI8[(jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.SI8[jj * naxes[0] + ii]; } - else if(datatype == _DATATYPE_INT16) + else if (datatype == _DATATYPE_INT16) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - data.image[IDout].array.SI16[(jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.SI16[jj * naxes[0] + ii]; + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + data.image[IDout].array.SI16[(jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.SI16[jj * naxes[0] + ii]; } - else if(datatype == _DATATYPE_INT32) + else if (datatype == _DATATYPE_INT32) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - data.image[IDout].array.SI32[(jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.SI32[jj * naxes[0] + ii]; + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + data.image[IDout].array.SI32[(jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.SI32[jj * naxes[0] + ii]; } - else if(datatype == _DATATYPE_INT64) + else if (datatype == _DATATYPE_INT64) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - data.image[IDout].array.SI64[(jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.SI64[jj * naxes[0] + ii]; + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + data.image[IDout].array.SI64[(jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.SI64[jj * naxes[0] + ii]; } else { @@ -471,145 +383,153 @@ imageID arith_image_crop( exit(0); } } - if(naxis == 3) + if (naxis == 3) { // printf("naxis = 3\n"); - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.F[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.F[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; + data.image[IDout].array.F[(kk - start[2]) * naxesout[0] * naxesout[1] + + (jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.F[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; } } - else if(datatype == _DATATYPE_DOUBLE) + else if (datatype == _DATATYPE_DOUBLE) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.D[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.D[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; + data.image[IDout].array.D[(kk - start[2]) * naxesout[0] * naxesout[1] + + (jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.D[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; } } - else if(datatype == _DATATYPE_COMPLEX_FLOAT) + else if (datatype == _DATATYPE_COMPLEX_FLOAT) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.CF[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])].re - = data.image[IDin].array.CF[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii].re; - data.image[IDout].array.CF[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])].im - = data.image[IDin].array.CF[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii].im; + data.image[IDout] + .array + .CF[(kk - start[2]) * naxesout[0] * naxesout[1] + (jj - start[1]) * naxesout[0] + + (ii - start[0])] + .re = data.image[IDin].array.CF[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii].re; + data.image[IDout] + .array + .CF[(kk - start[2]) * naxesout[0] * naxesout[1] + (jj - start[1]) * naxesout[0] + + (ii - start[0])] + .im = data.image[IDin].array.CF[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii].im; } } - else if(datatype == _DATATYPE_COMPLEX_DOUBLE) + else if (datatype == _DATATYPE_COMPLEX_DOUBLE) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.CD[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])].re - = data.image[IDin].array.CD[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii].re; - data.image[IDout].array.CD[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])].im - = data.image[IDin].array.CD[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii].im; + data.image[IDout] + .array + .CD[(kk - start[2]) * naxesout[0] * naxesout[1] + (jj - start[1]) * naxesout[0] + + (ii - start[0])] + .re = data.image[IDin].array.CD[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii].re; + data.image[IDout] + .array + .CD[(kk - start[2]) * naxesout[0] * naxesout[1] + (jj - start[1]) * naxesout[0] + + (ii - start[0])] + .im = data.image[IDin].array.CD[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii].im; } } - else if(datatype == _DATATYPE_UINT8) + else if (datatype == _DATATYPE_UINT8) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.UI8[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.UI8[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; + data.image[IDout].array.UI8[(kk - start[2]) * naxesout[0] * naxesout[1] + + (jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.UI8[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; } } - else if(datatype == _DATATYPE_UINT16) + else if (datatype == _DATATYPE_UINT16) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.UI16[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.UI16[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; + data.image[IDout].array.UI16[(kk - start[2]) * naxesout[0] * naxesout[1] + + (jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.UI16[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; } } - else if(datatype == _DATATYPE_UINT32) + else if (datatype == _DATATYPE_UINT32) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.UI32[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.UI32[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; + data.image[IDout].array.UI32[(kk - start[2]) * naxesout[0] * naxesout[1] + + (jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.UI32[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; } } - else if(datatype == _DATATYPE_UINT64) + else if (datatype == _DATATYPE_UINT64) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.UI64[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.UI64[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; + data.image[IDout].array.UI64[(kk - start[2]) * naxesout[0] * naxesout[1] + + (jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.UI64[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; } } - else if(datatype == _DATATYPE_INT8) + else if (datatype == _DATATYPE_INT8) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.SI8[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.SI8[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; + data.image[IDout].array.SI8[(kk - start[2]) * naxesout[0] * naxesout[1] + + (jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.SI8[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; } } - else if(datatype == _DATATYPE_INT16) + else if (datatype == _DATATYPE_INT16) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.SI16[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.SI16[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; + data.image[IDout].array.SI16[(kk - start[2]) * naxesout[0] * naxesout[1] + + (jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.SI16[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; } } - else if(datatype == _DATATYPE_INT32) + else if (datatype == _DATATYPE_INT32) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.SI32[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.SI32[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; + data.image[IDout].array.SI32[(kk - start[2]) * naxesout[0] * naxesout[1] + + (jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.SI32[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; } } - else if(datatype == _DATATYPE_INT64) + else if (datatype == _DATATYPE_INT64) { - for(uint32_t ii = start_c[0]; ii < end_c[0]; ii++) - for(uint32_t jj = start_c[1]; jj < end_c[1]; jj++) - for(uint32_t kk = start_c[2]; kk < end_c[2]; kk++) + for (uint32_t ii = start_c[0]; ii < end_c[0]; ii++) + for (uint32_t jj = start_c[1]; jj < end_c[1]; jj++) + for (uint32_t kk = start_c[2]; kk < end_c[2]; kk++) { - data.image[IDout].array.SI64[(kk - start[2])*naxesout[0]*naxesout[1] + - (jj - start[1])*naxesout[0] + (ii - start[0])] - = data.image[IDin].array.SI64[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; + data.image[IDout].array.SI64[(kk - start[2]) * naxesout[0] * naxesout[1] + + (jj - start[1]) * naxesout[0] + (ii - start[0])] = + data.image[IDin].array.SI64[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; } } else @@ -625,45 +545,34 @@ imageID arith_image_crop( return IDout; } - - - - -imageID arith_image_extract2D( - const char *in_name, - const char *out_name, - long size_x, - long size_y, - long xstart, - long ystart -) +imageID arith_image_extract2D(const char *in_name, const char *out_name, long size_x, long size_y, long xstart, + long ystart) { - long *start = NULL; - long *end = NULL; - int naxis; - imageID ID; - imageID IDout; + long *start = NULL; + long *end = NULL; + int naxis; + imageID ID; + imageID IDout; uint_fast8_t k; ID = image_ID(in_name); naxis = data.image[ID].md[0].naxis; - - start = (long *) malloc(sizeof(long) * naxis); - if(start == NULL) + start = (long *)malloc(sizeof(long) * naxis); + if (start == NULL) { PRINT_ERROR("malloc() error"); exit(0); } - end = (long *) malloc(sizeof(long) * naxis); - if(end == NULL) + end = (long *)malloc(sizeof(long) * naxis); + if (end == NULL) { PRINT_ERROR("malloc() error"); exit(0); } - for(k = 0; k < naxis; k++) + for (k = 0; k < naxis; k++) { start[k] = 0; end[k] = data.image[ID].md[0].size[k]; @@ -681,41 +590,28 @@ imageID arith_image_extract2D( return IDout; } - - - - - -imageID arith_image_extract3D( - const char *in_name, - const char *out_name, - long size_x, - long size_y, - long size_z, - long xstart, - long ystart, - long zstart -) +imageID arith_image_extract3D(const char *in_name, const char *out_name, long size_x, long size_y, long size_z, + long xstart, long ystart, long zstart) { - imageID IDout; - long *start = NULL; - long *end = NULL; + imageID IDout; + long *start = NULL; + long *end = NULL; - start = (long *) malloc(sizeof(long) * 3); - if(start == NULL) + start = (long *)malloc(sizeof(long) * 3); + if (start == NULL) { PRINT_ERROR("malloc() error"); - printf("params: %s %s %ld %ld %ld %ld %ld %ld \n", in_name, out_name, size_x, - size_y, size_z, xstart, ystart, zstart); + printf("params: %s %s %ld %ld %ld %ld %ld %ld \n", in_name, out_name, size_x, size_y, size_z, xstart, ystart, + zstart); exit(0); } - end = (long *) malloc(sizeof(long) * 3); - if(end == NULL) + end = (long *)malloc(sizeof(long) * 3); + if (end == NULL) { PRINT_ERROR("malloc() error"); - printf("params: %s %s %ld %ld %ld %ld %ld %ld \n", in_name, out_name, size_x, - size_y, size_z, xstart, ystart, zstart); + printf("params: %s %s %ld %ld %ld %ld %ld %ld \n", in_name, out_name, size_x, size_y, size_z, xstart, ystart, + zstart); exit(0); } diff --git a/src/COREMOD_arith/image_crop.h b/src/COREMOD_arith/image_crop.h index 907eca79..f85488f6 100644 --- a/src/COREMOD_arith/image_crop.h +++ b/src/COREMOD_arith/image_crop.h @@ -3,41 +3,12 @@ * */ - - errno_t image_crop_addCLIcmd(); +imageID arith_image_crop(const char *ID_name, const char *ID_out, long *start, long *end, long cropdim); +imageID arith_image_extract2D(const char *in_name, const char *out_name, long size_x, long size_y, long xstart, + long ystart); -imageID arith_image_crop( - const char *ID_name, - const char *ID_out, - long *start, - long *end, - long cropdim -); - - -imageID arith_image_extract2D( - const char *in_name, - const char *out_name, - long size_x, - long size_y, - long xstart, - long ystart -); - - - -imageID arith_image_extract3D( - const char *in_name, - const char *out_name, - long size_x, - long size_y, - long size_z, - long xstart, - long ystart, - long zstart -); - - +imageID arith_image_extract3D(const char *in_name, const char *out_name, long size_x, long size_y, long size_z, + long xstart, long ystart, long zstart); diff --git a/src/COREMOD_arith/image_dxdy.c b/src/COREMOD_arith/image_dxdy.c index 356433c0..089c6c86 100644 --- a/src/COREMOD_arith/image_dxdy.c +++ b/src/COREMOD_arith/image_dxdy.c @@ -6,15 +6,10 @@ */ #include -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" +#include "CommandLineInterface/CLIcore.h" - - -imageID arith_image_dx( - const char *ID_name, - const char *IDout_name -) +imageID arith_image_dx(const char *ID_name, const char *IDout_name) { imageID ID; imageID IDout; @@ -25,37 +20,33 @@ imageID arith_image_dx( ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; naxis = data.image[ID].md[0].naxis; - if(naxis != 2) + if (naxis != 2) { PRINT_ERROR("Function only supports 2-D images\n"); abort(); } assert(naxis != 0); - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { - PRINT_ERROR("malloc error. size %d", (int) naxis); + PRINT_ERROR("malloc error. size %d", (int)naxis); abort(); } naxes[0] = data.image[ID].md[0].size[0]; naxes[1] = data.image[ID].md[0].size[1]; - create_image_ID(IDout_name, naxis, naxes, datatype, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); - for(uint32_t jj = 0; jj < naxes[1]; jj++) + create_image_ID(IDout_name, naxis, naxes, datatype, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); + for (uint32_t jj = 0; jj < naxes[1]; jj++) { - for(uint32_t ii = 1; ii < naxes[0] - 1; ii++) + for (uint32_t ii = 1; ii < naxes[0] - 1; ii++) data.image[IDout].array.F[jj * naxes[0] + ii] = - (data.image[ID].array.F[jj * naxes[0] + ii + 1] - data.image[ID].array.F[jj * - naxes[0] + ii - 1]) / 2.0; + (data.image[ID].array.F[jj * naxes[0] + ii + 1] - data.image[ID].array.F[jj * naxes[0] + ii - 1]) / 2.0; data.image[IDout].array.F[jj * naxes[0]] = - data.image[ID].array.F[jj * naxes[0] + 1] - data.image[ID].array.F[jj * - naxes[0]]; + data.image[ID].array.F[jj * naxes[0] + 1] - data.image[ID].array.F[jj * naxes[0]]; data.image[IDout].array.F[jj * naxes[0] + naxes[0] - 1] = - data.image[ID].array.F[jj * naxes[0] + naxes[0] - 1] - data.image[ID].array.F[jj - * naxes[0] + naxes[0] - 2]; + data.image[ID].array.F[jj * naxes[0] + naxes[0] - 1] - data.image[ID].array.F[jj * naxes[0] + naxes[0] - 2]; } free(naxes); @@ -63,13 +54,7 @@ imageID arith_image_dx( return IDout; } - - - -imageID arith_image_dy( - const char *ID_name, - const char *IDout_name -) +imageID arith_image_dy(const char *ID_name, const char *IDout_name) { imageID ID; imageID IDout; @@ -80,40 +65,38 @@ imageID arith_image_dy( ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; naxis = data.image[ID].md[0].naxis; - if(naxis != 2) + if (naxis != 2) { PRINT_ERROR("Function only supports 2-D images\n"); abort(); } assert(naxis != 0); - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { - PRINT_ERROR("malloc error. size %d", (int) naxis); + PRINT_ERROR("malloc error. size %d", (int)naxis); abort(); } naxes[0] = data.image[ID].md[0].size[0]; naxes[1] = data.image[ID].md[0].size[1]; - create_image_ID(IDout_name, naxis, naxes, datatype, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); - for(uint32_t ii = 0; ii < naxes[0]; ii++) + create_image_ID(IDout_name, naxis, naxes, datatype, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); + for (uint32_t ii = 0; ii < naxes[0]; ii++) { - for(uint32_t jj = 1; jj < naxes[1] - 1; jj++) + for (uint32_t jj = 1; jj < naxes[1] - 1; jj++) { - data.image[IDout].array.F[jj * naxes[0] + ii] = (data.image[ID].array.F[(jj + 1) - * naxes[0] + ii] - data.image[ID].array.F[(jj - 1) * naxes[0] + ii]) / 2.0; + data.image[IDout].array.F[jj * naxes[0] + ii] = + (data.image[ID].array.F[(jj + 1) * naxes[0] + ii] - data.image[ID].array.F[(jj - 1) * naxes[0] + ii]) / + 2.0; } - data.image[IDout].array.F[ii] = data.image[ID].array.F[1 * naxes[0] + ii] - - data.image[ID].array.F[ii]; + data.image[IDout].array.F[ii] = data.image[ID].array.F[1 * naxes[0] + ii] - data.image[ID].array.F[ii]; - data.image[IDout].array.F[(naxes[1] - 1)*naxes[0] + ii] = + data.image[IDout].array.F[(naxes[1] - 1) * naxes[0] + ii] = data.image[ID].array.F[(naxes[1] - 1) * naxes[0] + ii] - data.image[ID].array.F[(naxes[1] - 2) * naxes[0] + ii]; - } free(naxes); diff --git a/src/COREMOD_arith/image_dxdy.h b/src/COREMOD_arith/image_dxdy.h index f4571ee4..30db232c 100644 --- a/src/COREMOD_arith/image_dxdy.h +++ b/src/COREMOD_arith/image_dxdy.h @@ -2,7 +2,6 @@ * @file image_dxdy.c */ - imageID arith_image_dx(const char *ID_name, const char *IDout_name); imageID arith_image_dy(const char *ID_name, const char *IDout_name); diff --git a/src/COREMOD_arith/image_merge3D.c b/src/COREMOD_arith/image_merge3D.c index 9c7b9840..29395929 100644 --- a/src/COREMOD_arith/image_merge3D.c +++ b/src/COREMOD_arith/image_merge3D.c @@ -5,43 +5,25 @@ * */ - -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" - - - - +#include "CommandLineInterface/CLIcore.h" // ========================================== // Forward declaration(s) // ========================================== -imageID arith_image_merge3D( - const char *ID_name1, - const char *ID_name2, - const char *IDout_name -); - - +imageID arith_image_merge3D(const char *ID_name1, const char *ID_name2, const char *IDout_name); // ========================================== // Command line interface wrapper function(s) // ========================================== - static errno_t arith_image_merge3D_cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_IMG) - + CLI_checkarg(3, CLIARG_STR_NOT_IMG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_IMG) + CLI_checkarg(3, CLIARG_STR_NOT_IMG) == 0) { - arith_image_merge3D( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.string, - data.cmdargtoken[3].val.string); + arith_image_merge3D(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, + data.cmdargtoken[3].val.string); return CLICMD_SUCCESS; } @@ -51,9 +33,6 @@ static errno_t arith_image_merge3D_cli() } } - - - // ========================================== // Register CLI command(s) // ========================================== @@ -61,39 +40,15 @@ static errno_t arith_image_merge3D_cli() errno_t image_merge3D_addCLIcmd() { - RegisterCLIcommand( - "merge3d", - __FILE__, - arith_image_merge3D_cli, - "merge two 3D cubes into one", - " ", - "merge3d imc1 imc2 imcout", - "long arith_image_merge3D(const char *ID_name1, const char *ID_name2, const char *IDout_name)"); - + RegisterCLIcommand("merge3d", __FILE__, arith_image_merge3D_cli, "merge two 3D cubes into one", + " ", "merge3d imc1 imc2 imcout", + "long arith_image_merge3D(const char *ID_name1, const char *ID_name2, const char *IDout_name)"); return RETURN_SUCCESS; } - - - - - - - - - - - - - - // join two cubes -imageID arith_image_merge3D( - const char *ID_name1, - const char *ID_name2, - const char *IDout_name -) +imageID arith_image_merge3D(const char *ID_name1, const char *ID_name2, const char *IDout_name) { DEBUG_TRACE_FSTART(); @@ -109,7 +64,7 @@ imageID arith_image_merge3D( xsize = data.image[ID1].md[0].size[0]; ysize = data.image[ID1].md[0].size[1]; - if(data.image[ID1].md[0].naxis == 2) + if (data.image[ID1].md[0].naxis == 2) { zsize1 = 1; } @@ -118,7 +73,7 @@ imageID arith_image_merge3D( zsize1 = data.image[ID1].md[0].size[2]; } - if(data.image[ID2].md[0].naxis == 2) + if (data.image[ID2].md[0].naxis == 2) { zsize2 = 1; } @@ -127,70 +82,57 @@ imageID arith_image_merge3D( zsize2 = data.image[ID2].md[0].size[2]; } - - - if((xsize != data.image[ID2].md[0].size[0]) - || (ysize != data.image[ID2].md[0].size[1])) + if ((xsize != data.image[ID2].md[0].size[0]) || (ysize != data.image[ID2].md[0].size[1])) { printf("ERROR: input images must have same x y sizes\n"); printf("%s : %u %u\n", ID_name1, xsize, ysize); - printf("%s : %ld %ld\n", ID_name2, (long) data.image[ID2].md[0].size[0], - (long) data.image[ID2].md[0].size[1]); + printf("%s : %ld %ld\n", ID_name2, (long)data.image[ID2].md[0].size[0], (long)data.image[ID2].md[0].size[1]); exit(0); } - uint32_t * sizearray = (uint32_t *) malloc(sizeof(uint32_t)*3); + uint32_t *sizearray = (uint32_t *)malloc(sizeof(uint32_t) * 3); sizearray[0] = xsize; sizearray[1] = xsize; - sizearray[2] = zsize1+zsize2; + sizearray[2] = zsize1 + zsize2; uint8_t datatype = data.image[ID1].md[0].datatype; - FUNC_CHECK_RETURN( - create_image_ID(IDout_name, 3, sizearray, datatype, 0, 0, 0, &IDout) - ); - + FUNC_CHECK_RETURN(create_image_ID(IDout_name, 3, sizearray, datatype, 0, 0, 0, &IDout)); switch (datatype) { - case _DATATYPE_FLOAT : - mapv = (void *) data.image[IDout].array.F; - memcpy(mapv, (void *) data.image[ID1].array.F, - sizeof(float)*xsize * ysize * zsize1); + case _DATATYPE_FLOAT: + mapv = (void *)data.image[IDout].array.F; + memcpy(mapv, (void *)data.image[ID1].array.F, sizeof(float) * xsize * ysize * zsize1); mapv += sizeof(float) * xsize * ysize * zsize1; - memcpy(mapv, data.image[ID2].array.F, sizeof(float)*xsize * ysize * zsize2); + memcpy(mapv, data.image[ID2].array.F, sizeof(float) * xsize * ysize * zsize2); break; - case _DATATYPE_DOUBLE : - mapv = (void *) data.image[IDout].array.D; - memcpy(mapv, (void *) data.image[ID1].array.D, - sizeof(double)*xsize * ysize * zsize1); + case _DATATYPE_DOUBLE: + mapv = (void *)data.image[IDout].array.D; + memcpy(mapv, (void *)data.image[ID1].array.D, sizeof(double) * xsize * ysize * zsize1); mapv += sizeof(double) * xsize * ysize * zsize1; - memcpy(mapv, data.image[ID2].array.D, sizeof(double)*xsize * ysize * zsize2); + memcpy(mapv, data.image[ID2].array.D, sizeof(double) * xsize * ysize * zsize2); break; - case _DATATYPE_INT16 : - mapv = (void *) data.image[IDout].array.SI16; - memcpy(mapv, (void *) data.image[ID1].array.SI16, - sizeof(int16_t)*xsize * ysize * zsize1); + case _DATATYPE_INT16: + mapv = (void *)data.image[IDout].array.SI16; + memcpy(mapv, (void *)data.image[ID1].array.SI16, sizeof(int16_t) * xsize * ysize * zsize1); mapv += sizeof(int16_t) * xsize * ysize * zsize1; - memcpy(mapv, data.image[ID2].array.SI16, sizeof(int16_t)*xsize * ysize * zsize2); + memcpy(mapv, data.image[ID2].array.SI16, sizeof(int16_t) * xsize * ysize * zsize2); break; - case _DATATYPE_UINT16 : - mapv = (void *) data.image[IDout].array.UI16; - memcpy(mapv, (void *) data.image[ID1].array.UI16, - sizeof(uint16_t)*xsize * ysize * zsize1); + case _DATATYPE_UINT16: + mapv = (void *)data.image[IDout].array.UI16; + memcpy(mapv, (void *)data.image[ID1].array.UI16, sizeof(uint16_t) * xsize * ysize * zsize1); mapv += sizeof(uint16_t) * xsize * ysize * zsize1; - memcpy(mapv, data.image[ID2].array.UI16, sizeof(uint16_t)*xsize * ysize * zsize2); + memcpy(mapv, data.image[ID2].array.UI16, sizeof(uint16_t) * xsize * ysize * zsize2); break; default: printf("dataypte not supported\n"); } - - DEBUG_TRACE_FEXIT(); return IDout; } diff --git a/src/COREMOD_arith/image_merge3D.h b/src/COREMOD_arith/image_merge3D.h index 19c9e3f7..f8d71e7f 100644 --- a/src/COREMOD_arith/image_merge3D.h +++ b/src/COREMOD_arith/image_merge3D.h @@ -3,12 +3,6 @@ * */ - errno_t image_merge3D_addCLIcmd(); - -imageID arith_image_merge3D( - const char *ID_name1, - const char *ID_name2, - const char *IDout_name -); +imageID arith_image_merge3D(const char *ID_name1, const char *ID_name2, const char *IDout_name); diff --git a/src/COREMOD_arith/image_stats.c b/src/COREMOD_arith/image_stats.c index 47fa44b4..ede383c1 100644 --- a/src/COREMOD_arith/image_stats.c +++ b/src/COREMOD_arith/image_stats.c @@ -5,19 +5,14 @@ * */ - -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" +#include "CommandLineInterface/CLIcore.h" #include "COREMOD_tools/COREMOD_tools.h" #include "image_total.h" - - -double arith_image_mean( - const char *ID_name -) +double arith_image_mean(const char *ID_name) { double value; imageID ID; @@ -26,15 +21,10 @@ double arith_image_mean( value = (double)(arith_image_total(ID_name) / data.image[ID].md[0].nelement); - return(value); + return (value); } - - - -double arith_image_min( - const char *ID_name -) +double arith_image_min(const char *ID_name) { imageID ID; uint64_t nelement; @@ -46,33 +36,32 @@ double arith_image_min( nelement = data.image[ID].md[0].nelement; - - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { float value; value = data.image[ID].array.F[0]; - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { float value1 = data.image[ID].array.F[ii]; - if(value1 < value) + if (value1 < value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { double value; value = data.image[ID].array.D[0]; - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { double value1 = data.image[ID].array.D[ii]; - if(value1 < value) + if (value1 < value) { value = value1; } @@ -81,195 +70,189 @@ double arith_image_min( return (value); } - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { uint8_t value; value = data.image[ID].array.UI8[0]; - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { uint8_t value1 = data.image[ID].array.UI8[ii]; - if(value1 < value) + if (value1 < value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { uint16_t value; value = data.image[ID].array.UI16[0]; - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { uint16_t value1 = data.image[ID].array.UI16[ii]; - if(value1 < value) + if (value1 < value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { uint32_t value; value = data.image[ID].array.UI32[0]; - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { uint32_t value1 = data.image[ID].array.UI32[ii]; - if(value1 < value) + if (value1 < value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { uint64_t value; value = data.image[ID].array.UI64[0]; - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { uint64_t value1 = data.image[ID].array.UI64[ii]; - if(value1 < value) + if (value1 < value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { int8_t value; value = data.image[ID].array.SI8[0]; - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { int8_t value1 = data.image[ID].array.SI8[ii]; - if(value1 < value) + if (value1 < value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { int16_t value; - value = (double) data.image[ID].array.SI16[0]; - for(uint64_t ii = 0; ii < nelement; ii++) + value = (double)data.image[ID].array.SI16[0]; + for (uint64_t ii = 0; ii < nelement; ii++) { int16_t value1 = data.image[ID].array.SI16[ii]; - if(value1 < value) + if (value1 < value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { int32_t value; value = data.image[ID].array.SI32[0]; - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { int32_t value1 = data.image[ID].array.SI32[ii]; - if(value1 < value) + if (value1 < value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { int64_t value; value = data.image[ID].array.SI64[0]; - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { int64_t value1 = data.image[ID].array.SI64[ii]; - if(value1 < value) + if (value1 < value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(OK == 0) + if (OK == 0) { printf("Error : Invalid data format for arith_image_min\n"); } - return(0); + return (0); } - - - - -double arith_image_max( - const char *ID_name -) +double arith_image_max(const char *ID_name) { imageID ID; - long ii; - long nelement; + long ii; + long nelement; uint8_t datatype; - int OK = 0; + int OK = 0; ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; nelement = data.image[ID].md[0].nelement; - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { float value, value1; value = data.image[ID].array.F[0]; - for(ii = 0; ii < nelement; ii++) + for (ii = 0; ii < nelement; ii++) { value1 = data.image[ID].array.F[ii]; - if(value1 > value) + if (value1 > value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { double value, value1; value = data.image[ID].array.D[0]; - for(ii = 0; ii < nelement; ii++) + for (ii = 0; ii < nelement; ii++) { value1 = data.image[ID].array.D[ii]; - if(value1 > value) + if (value1 > value) { value = value1; } @@ -278,357 +261,343 @@ double arith_image_max( return (value); } - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { uint8_t value, value1; value = data.image[ID].array.UI8[0]; - for(ii = 0; ii < nelement; ii++) + for (ii = 0; ii < nelement; ii++) { value1 = data.image[ID].array.UI8[ii]; - if(value1 > value) + if (value1 > value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { uint16_t value, value1; value = data.image[ID].array.UI16[0]; - for(ii = 0; ii < nelement; ii++) + for (ii = 0; ii < nelement; ii++) { value1 = data.image[ID].array.UI16[ii]; - if(value1 > value) + if (value1 > value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { uint32_t value, value1; value = data.image[ID].array.UI32[0]; - for(ii = 0; ii < nelement; ii++) + for (ii = 0; ii < nelement; ii++) { value1 = data.image[ID].array.UI32[ii]; - if(value1 > value) + if (value1 > value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { uint64_t value, value1; value = data.image[ID].array.UI64[0]; - for(ii = 0; ii < nelement; ii++) + for (ii = 0; ii < nelement; ii++) { value1 = data.image[ID].array.UI64[ii]; - if(value1 > value) + if (value1 > value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { int8_t value, value1; value = data.image[ID].array.SI8[0]; - for(ii = 0; ii < nelement; ii++) + for (ii = 0; ii < nelement; ii++) { value1 = data.image[ID].array.SI8[ii]; - if(value1 > value) + if (value1 > value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { int16_t value, value1; - value = (double) data.image[ID].array.SI16[0]; - for(ii = 0; ii < nelement; ii++) + value = (double)data.image[ID].array.SI16[0]; + for (ii = 0; ii < nelement; ii++) { value1 = data.image[ID].array.SI16[ii]; - if(value1 > value) + if (value1 > value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { int32_t value, value1; value = data.image[ID].array.SI32[0]; - for(ii = 0; ii < nelement; ii++) + for (ii = 0; ii < nelement; ii++) { value1 = data.image[ID].array.SI32[ii]; - if(value1 > value) + if (value1 > value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { int64_t value, value1; value = data.image[ID].array.SI64[0]; - for(ii = 0; ii < nelement; ii++) + for (ii = 0; ii < nelement; ii++) { value1 = data.image[ID].array.SI64[ii]; - if(value1 > value) + if (value1 > value) { value = value1; } } OK = 1; - return ((double) value); + return ((double)value); } - if(OK == 0) + if (OK == 0) { printf("Error : Invalid data format for arith_image_max\n"); } - return(0); + return (0); } - - - - -double arith_image_percentile( - const char *ID_name, - double fraction -) +double arith_image_percentile(const char *ID_name, double fraction) { - imageID ID; - long ii; - double value = 0; - long *arrayL = NULL; - float *arrayF = NULL; - double *arrayD = NULL; + imageID ID; + long ii; + double value = 0; + long *arrayL = NULL; + float *arrayF = NULL; + double *arrayD = NULL; unsigned short *arrayU = NULL; - long nelement; - uint8_t datatype; - int atypeOK = 1; + long nelement; + uint8_t datatype; + int atypeOK = 1; ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; nelement = data.image[ID].md[0].nelement; - - switch(datatype) + switch (datatype) { - case _DATATYPE_FLOAT : - arrayF = (float *) malloc(sizeof(float) * nelement); - if(arrayF == NULL) - { - PRINT_ERROR("malloc() error"); - exit(EXIT_FAILURE); - } - memcpy(arrayF, data.image[ID].array.F, sizeof(float)*nelement); - quick_sort_float(arrayF, nelement); - value = (double) arrayF[(long)(fraction * nelement)]; - free(arrayF); - break; - - case _DATATYPE_DOUBLE : - arrayD = (double *) malloc(sizeof(double) * nelement); - if(arrayD == NULL) - { - PRINT_ERROR("malloc() error"); - exit(EXIT_FAILURE); - } - memcpy(arrayD, data.image[ID].array.D, sizeof(double)*nelement); - quick_sort_double(arrayD, nelement); - value = arrayD[(long)(fraction * nelement)]; - free(arrayD); - break; - - - - case _DATATYPE_UINT8 : - arrayU = (unsigned short *) malloc(sizeof(unsigned short) * nelement); - if(arrayU == NULL) - { - PRINT_ERROR("malloc() error"); - exit(EXIT_FAILURE); - } - for(ii = 0; ii < nelement; ii++) - { - arrayU[ii] = data.image[ID].array.UI8[ii]; - } - quick_sort_ushort(arrayU, nelement); - value = arrayU[(long)(fraction * nelement)]; - free(arrayU); - break; - - case _DATATYPE_UINT16 : - arrayU = (unsigned short *) malloc(sizeof(unsigned short) * nelement); - if(arrayU == NULL) - { - PRINT_ERROR("malloc() error"); - exit(EXIT_FAILURE); - } - for(ii = 0; ii < nelement; ii++) - { - arrayU[ii] = data.image[ID].array.UI16[ii]; - } - quick_sort_ushort(arrayU, nelement); - value = arrayU[(long)(fraction * nelement)]; - free(arrayU); - break; - - case _DATATYPE_UINT32 : - arrayL = (long *) malloc(sizeof(long) * nelement); - if(arrayU == NULL) - { - PRINT_ERROR("malloc() error"); - exit(EXIT_FAILURE); - } - for(ii = 0; ii < nelement; ii++) - { - arrayL[ii] = data.image[ID].array.UI32[ii]; - } - quick_sort_long(arrayL, nelement); - value = arrayL[(long)(fraction * nelement)]; - free(arrayL); - break; - - case _DATATYPE_UINT64 : - arrayL = (long *) malloc(sizeof(long) * nelement); - if(arrayU == NULL) - { - PRINT_ERROR("malloc() error"); - exit(EXIT_FAILURE); - } - for(ii = 0; ii < nelement; ii++) - { - arrayL[ii] = data.image[ID].array.UI64[ii]; - } - quick_sort_long(arrayL, nelement); - value = arrayL[(long)(fraction * nelement)]; - free(arrayL); - break; - - - case _DATATYPE_INT8 : - arrayL = (long *) malloc(sizeof(long) * nelement); - if(arrayL == NULL) - { - PRINT_ERROR("malloc() error"); - exit(EXIT_FAILURE); - } - for(ii = 0; ii < nelement; ii++) - { - arrayL[ii] = (long) data.image[ID].array.SI8[ii]; - } - quick_sort_long(arrayL, nelement); - value = (double) arrayL[(long)(fraction * nelement)]; - free(arrayL); - break; - - case _DATATYPE_INT16 : - arrayL = (long *) malloc(sizeof(long) * nelement); - if(arrayL == NULL) - { - PRINT_ERROR("malloc() error"); - exit(EXIT_FAILURE); - } - for(ii = 0; ii < nelement; ii++) - { - arrayL[ii] = (long) data.image[ID].array.SI16[ii]; - } - quick_sort_long(arrayL, nelement); - value = (double) arrayL[(long)(fraction * nelement)]; - free(arrayL); - break; - - case _DATATYPE_INT32 : - arrayL = (long *) malloc(sizeof(long) * nelement); - if(arrayL == NULL) - { - PRINT_ERROR("malloc() error"); - exit(EXIT_FAILURE); - } - for(ii = 0; ii < nelement; ii++) - { - arrayL[ii] = (long) data.image[ID].array.SI32[ii]; - } - quick_sort_long(arrayL, nelement); - value = (double) arrayL[(long)(fraction * nelement)]; - free(arrayL); - break; - - case _DATATYPE_INT64 : - arrayL = (long *) malloc(sizeof(long) * nelement); - if(arrayL == NULL) - { - PRINT_ERROR("malloc() error"); - exit(EXIT_FAILURE); - } - for(ii = 0; ii < nelement; ii++) - { - arrayL[ii] = (long) data.image[ID].array.SI64[ii]; - } - quick_sort_long(arrayL, nelement); - value = (double) arrayL[(long)(fraction * nelement)]; - free(arrayL); - break; - - default: - PRINT_ERROR("Image type not supported"); - atypeOK = 0; - break; + case _DATATYPE_FLOAT: + arrayF = (float *)malloc(sizeof(float) * nelement); + if (arrayF == NULL) + { + PRINT_ERROR("malloc() error"); + exit(EXIT_FAILURE); + } + memcpy(arrayF, data.image[ID].array.F, sizeof(float) * nelement); + quick_sort_float(arrayF, nelement); + value = (double)arrayF[(long)(fraction * nelement)]; + free(arrayF); + break; + + case _DATATYPE_DOUBLE: + arrayD = (double *)malloc(sizeof(double) * nelement); + if (arrayD == NULL) + { + PRINT_ERROR("malloc() error"); + exit(EXIT_FAILURE); + } + memcpy(arrayD, data.image[ID].array.D, sizeof(double) * nelement); + quick_sort_double(arrayD, nelement); + value = arrayD[(long)(fraction * nelement)]; + free(arrayD); + break; + + case _DATATYPE_UINT8: + arrayU = (unsigned short *)malloc(sizeof(unsigned short) * nelement); + if (arrayU == NULL) + { + PRINT_ERROR("malloc() error"); + exit(EXIT_FAILURE); + } + for (ii = 0; ii < nelement; ii++) + { + arrayU[ii] = data.image[ID].array.UI8[ii]; + } + quick_sort_ushort(arrayU, nelement); + value = arrayU[(long)(fraction * nelement)]; + free(arrayU); + break; + + case _DATATYPE_UINT16: + arrayU = (unsigned short *)malloc(sizeof(unsigned short) * nelement); + if (arrayU == NULL) + { + PRINT_ERROR("malloc() error"); + exit(EXIT_FAILURE); + } + for (ii = 0; ii < nelement; ii++) + { + arrayU[ii] = data.image[ID].array.UI16[ii]; + } + quick_sort_ushort(arrayU, nelement); + value = arrayU[(long)(fraction * nelement)]; + free(arrayU); + break; + + case _DATATYPE_UINT32: + arrayL = (long *)malloc(sizeof(long) * nelement); + if (arrayU == NULL) + { + PRINT_ERROR("malloc() error"); + exit(EXIT_FAILURE); + } + for (ii = 0; ii < nelement; ii++) + { + arrayL[ii] = data.image[ID].array.UI32[ii]; + } + quick_sort_long(arrayL, nelement); + value = arrayL[(long)(fraction * nelement)]; + free(arrayL); + break; + + case _DATATYPE_UINT64: + arrayL = (long *)malloc(sizeof(long) * nelement); + if (arrayU == NULL) + { + PRINT_ERROR("malloc() error"); + exit(EXIT_FAILURE); + } + for (ii = 0; ii < nelement; ii++) + { + arrayL[ii] = data.image[ID].array.UI64[ii]; + } + quick_sort_long(arrayL, nelement); + value = arrayL[(long)(fraction * nelement)]; + free(arrayL); + break; + + case _DATATYPE_INT8: + arrayL = (long *)malloc(sizeof(long) * nelement); + if (arrayL == NULL) + { + PRINT_ERROR("malloc() error"); + exit(EXIT_FAILURE); + } + for (ii = 0; ii < nelement; ii++) + { + arrayL[ii] = (long)data.image[ID].array.SI8[ii]; + } + quick_sort_long(arrayL, nelement); + value = (double)arrayL[(long)(fraction * nelement)]; + free(arrayL); + break; + + case _DATATYPE_INT16: + arrayL = (long *)malloc(sizeof(long) * nelement); + if (arrayL == NULL) + { + PRINT_ERROR("malloc() error"); + exit(EXIT_FAILURE); + } + for (ii = 0; ii < nelement; ii++) + { + arrayL[ii] = (long)data.image[ID].array.SI16[ii]; + } + quick_sort_long(arrayL, nelement); + value = (double)arrayL[(long)(fraction * nelement)]; + free(arrayL); + break; + + case _DATATYPE_INT32: + arrayL = (long *)malloc(sizeof(long) * nelement); + if (arrayL == NULL) + { + PRINT_ERROR("malloc() error"); + exit(EXIT_FAILURE); + } + for (ii = 0; ii < nelement; ii++) + { + arrayL[ii] = (long)data.image[ID].array.SI32[ii]; + } + quick_sort_long(arrayL, nelement); + value = (double)arrayL[(long)(fraction * nelement)]; + free(arrayL); + break; + + case _DATATYPE_INT64: + arrayL = (long *)malloc(sizeof(long) * nelement); + if (arrayL == NULL) + { + PRINT_ERROR("malloc() error"); + exit(EXIT_FAILURE); + } + for (ii = 0; ii < nelement; ii++) + { + arrayL[ii] = (long)data.image[ID].array.SI64[ii]; + } + quick_sort_long(arrayL, nelement); + value = (double)arrayL[(long)(fraction * nelement)]; + free(arrayL); + break; + + default: + PRINT_ERROR("Image type not supported"); + atypeOK = 0; + break; } - if(atypeOK == 0) + if (atypeOK == 0) { exit(EXIT_FAILURE); } - return(value); + return (value); } - -double arith_image_median( - const char *ID_name -) +double arith_image_median(const char *ID_name) { double value = 0.0; value = arith_image_percentile(ID_name, 0.5); - return(value); + return (value); } diff --git a/src/COREMOD_arith/image_stats.h b/src/COREMOD_arith/image_stats.h index 6da8dd62..6e3b7b7a 100644 --- a/src/COREMOD_arith/image_stats.h +++ b/src/COREMOD_arith/image_stats.h @@ -4,8 +4,6 @@ * */ - - double arith_image_mean(const char *ID_name); double arith_image_min(const char *ID_name); diff --git a/src/COREMOD_arith/image_total.c b/src/COREMOD_arith/image_total.c index 09d1db0a..bcea6ff3 100644 --- a/src/COREMOD_arith/image_total.c +++ b/src/COREMOD_arith/image_total.c @@ -5,18 +5,13 @@ * */ - -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" +#include "CommandLineInterface/CLIcore.h" - - -double arith_image_total( - const char *ID_name -) +double arith_image_total(const char *ID_name) { long double lvalue; // uses long double internally - imageID ID; + imageID ID; uint64_t nelement; uint8_t datatype; @@ -27,74 +22,74 @@ double arith_image_total( lvalue = 0.0; - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) data.image[ID].array.F[ii]; + lvalue += (long double)data.image[ID].array.F[ii]; } } - else if(datatype == _DATATYPE_DOUBLE) + else if (datatype == _DATATYPE_DOUBLE) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) data.image[ID].array.D[ii]; + lvalue += (long double)data.image[ID].array.D[ii]; } } - else if(datatype == _DATATYPE_UINT8) + else if (datatype == _DATATYPE_UINT8) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) data.image[ID].array.UI8[ii]; + lvalue += (long double)data.image[ID].array.UI8[ii]; } } - else if(datatype == _DATATYPE_UINT16) + else if (datatype == _DATATYPE_UINT16) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) data.image[ID].array.UI16[ii]; + lvalue += (long double)data.image[ID].array.UI16[ii]; } } - else if(datatype == _DATATYPE_UINT32) + else if (datatype == _DATATYPE_UINT32) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) data.image[ID].array.UI32[ii]; + lvalue += (long double)data.image[ID].array.UI32[ii]; } } - else if(datatype == _DATATYPE_UINT64) + else if (datatype == _DATATYPE_UINT64) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) data.image[ID].array.UI64[ii]; + lvalue += (long double)data.image[ID].array.UI64[ii]; } } - else if(datatype == _DATATYPE_INT8) + else if (datatype == _DATATYPE_INT8) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) data.image[ID].array.SI8[ii]; + lvalue += (long double)data.image[ID].array.SI8[ii]; } } - else if(datatype == _DATATYPE_INT16) + else if (datatype == _DATATYPE_INT16) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) data.image[ID].array.SI16[ii]; + lvalue += (long double)data.image[ID].array.SI16[ii]; } } - else if(datatype == _DATATYPE_INT32) + else if (datatype == _DATATYPE_INT32) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) data.image[ID].array.SI32[ii]; + lvalue += (long double)data.image[ID].array.SI32[ii]; } } - else if(datatype == _DATATYPE_INT64) + else if (datatype == _DATATYPE_INT64) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) data.image[ID].array.SI64[ii]; + lvalue += (long double)data.image[ID].array.SI64[ii]; } } else @@ -104,17 +99,12 @@ double arith_image_total( } double value; - value = (double) lvalue; + value = (double)lvalue; - return(value); + return (value); } - - - -double arith_image_sumsquare( - const char *ID_name -) +double arith_image_sumsquare(const char *ID_name) { long double lvalue; // uses long double internally imageID ID; @@ -128,74 +118,74 @@ double arith_image_sumsquare( lvalue = 0.0; - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) (data.image[ID].array.F[ii]*data.image[ID].array.F[ii]); + lvalue += (long double)(data.image[ID].array.F[ii] * data.image[ID].array.F[ii]); } } - else if(datatype == _DATATYPE_DOUBLE) + else if (datatype == _DATATYPE_DOUBLE) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) (data.image[ID].array.D[ii]*data.image[ID].array.D[ii]); + lvalue += (long double)(data.image[ID].array.D[ii] * data.image[ID].array.D[ii]); } } - else if(datatype == _DATATYPE_UINT8) + else if (datatype == _DATATYPE_UINT8) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) (data.image[ID].array.UI8[ii]*data.image[ID].array.UI8[ii]); + lvalue += (long double)(data.image[ID].array.UI8[ii] * data.image[ID].array.UI8[ii]); } } - else if(datatype == _DATATYPE_UINT16) + else if (datatype == _DATATYPE_UINT16) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) (data.image[ID].array.UI16[ii]*data.image[ID].array.UI16[ii]); + lvalue += (long double)(data.image[ID].array.UI16[ii] * data.image[ID].array.UI16[ii]); } } - else if(datatype == _DATATYPE_UINT32) + else if (datatype == _DATATYPE_UINT32) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) (data.image[ID].array.UI32[ii]*data.image[ID].array.UI32[ii]); + lvalue += (long double)(data.image[ID].array.UI32[ii] * data.image[ID].array.UI32[ii]); } } - else if(datatype == _DATATYPE_UINT64) + else if (datatype == _DATATYPE_UINT64) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) (data.image[ID].array.UI64[ii]*data.image[ID].array.UI64[ii]); + lvalue += (long double)(data.image[ID].array.UI64[ii] * data.image[ID].array.UI64[ii]); } } - else if(datatype == _DATATYPE_INT8) + else if (datatype == _DATATYPE_INT8) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) (data.image[ID].array.SI8[ii]*data.image[ID].array.SI8[ii]); + lvalue += (long double)(data.image[ID].array.SI8[ii] * data.image[ID].array.SI8[ii]); } } - else if(datatype == _DATATYPE_INT16) + else if (datatype == _DATATYPE_INT16) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) (data.image[ID].array.SI16[ii]*data.image[ID].array.SI16[ii]); + lvalue += (long double)(data.image[ID].array.SI16[ii] * data.image[ID].array.SI16[ii]); } } - else if(datatype == _DATATYPE_INT32) + else if (datatype == _DATATYPE_INT32) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) (data.image[ID].array.SI32[ii]*data.image[ID].array.SI32[ii]); + lvalue += (long double)(data.image[ID].array.SI32[ii] * data.image[ID].array.SI32[ii]); } } - else if(datatype == _DATATYPE_INT64) + else if (datatype == _DATATYPE_INT64) { - for(uint64_t ii = 0; ii < nelement; ii++) + for (uint64_t ii = 0; ii < nelement; ii++) { - lvalue += (long double) (data.image[ID].array.SI64[ii]*data.image[ID].array.SI64[ii]); + lvalue += (long double)(data.image[ID].array.SI64[ii] * data.image[ID].array.SI64[ii]); } } else @@ -205,10 +195,7 @@ double arith_image_sumsquare( } double value; - value = (double) lvalue; + value = (double)lvalue; - return(value); + return (value); } - - - diff --git a/src/COREMOD_arith/image_total.h b/src/COREMOD_arith/image_total.h index 6a937f35..0aeefc6a 100644 --- a/src/COREMOD_arith/image_total.h +++ b/src/COREMOD_arith/image_total.h @@ -1,14 +1,8 @@ /** * @file image_total.h - * + * */ +double arith_image_total(const char *ID_name); - -double arith_image_total( - const char *ID_name -); - -double arith_image_sumsquare( - const char *ID_name -); +double arith_image_sumsquare(const char *ID_name); diff --git a/src/COREMOD_arith/imfunctions.c b/src/COREMOD_arith/imfunctions.c index 9c4a3880..4d936705 100644 --- a/src/COREMOD_arith/imfunctions.c +++ b/src/COREMOD_arith/imfunctions.c @@ -7,19 +7,14 @@ #include -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" - - - +#include "CommandLineInterface/CLIcore.h" #ifdef _OPENMP #include #define OMP_NELEMENT_LIMIT 1000000 #endif - - /* ------------------------------------------------------------------------- */ /* Functions for bison / flex */ /* im : image @@ -32,12 +27,7 @@ ------------------------------------------------------------------------- */ - -errno_t arith_image_function_im_im__d_d( - const char *ID_name, - const char *ID_out, - double (*pt2function)(double) -) +errno_t arith_image_function_im_im__d_d(const char *ID_name, const char *ID_out, double (*pt2function)(double)) { imageID ID; imageID IDout; @@ -48,8 +38,7 @@ errno_t arith_image_function_im_im__d_d( uint8_t datatype, datatypeout; long i; - - if(data.Debug > 0) + if (data.Debug > 0) { printf("arith_image_function_d_d %s %s\n", ID_name, ID_out); fflush(stdout); @@ -58,175 +47,151 @@ errno_t arith_image_function_im_im__d_d( ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; naxis = data.image[ID].md[0].naxis; - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc() error"); exit(0); } - - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[ID].md[0].size[i]; } - datatypeout = _DATATYPE_FLOAT; - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { datatypeout = _DATATYPE_DOUBLE; } - create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); + create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); free(naxes); nelement = data.image[ID].md[0].nelement; - -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { -# endif - +#endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI8[ii])); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI8[ii])); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI16[ii])); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI16[ii])); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI32[ii])); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI32[ii])); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI64[ii])); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI64[ii])); } } - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI8[ii])); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI8[ii])); } } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI16[ii])); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI16[ii])); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI32[ii])); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI32[ii])); } } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI64[ii])); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI64[ii])); } } - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.F[ii])); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.F[ii])); } } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { data.image[IDout].array.D[ii] = pt2function(data.image[ID].array.D[ii]); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif - +#endif - if(data.Debug > 0) + if (data.Debug > 0) { printf("arith_image_function_d_d DONE\n"); fflush(stdout); } - return RETURN_SUCCESS; } - - - - -errno_t arith_image_function_imd_im__dd_d( - const char *ID_name, - double v0, - const char *ID_out, - double (*pt2function)(double, double) -) +errno_t arith_image_function_imd_im__dd_d(const char *ID_name, double v0, const char *ID_out, + double (*pt2function)(double, double)) { imageID ID; imageID IDout; @@ -237,183 +202,154 @@ errno_t arith_image_function_imd_im__dd_d( uint8_t datatype, datatypeout; long i; - - ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; naxis = data.image[ID].md[0].naxis; - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc() error"); exit(0); } - - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[ID].md[0].size[i]; } - datatypeout = _DATATYPE_FLOAT; - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { datatypeout = _DATATYPE_DOUBLE; } - create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); + create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); free(naxes); nelement = data.image[ID].md[0].nelement; - -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { -# endif - +#endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI8[ii]), v0); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI8[ii]), v0); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI16[ii]), v0); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI16[ii]), v0); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI32[ii]), v0); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI32[ii]), v0); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI64[ii]), v0); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI64[ii]), v0); } } - - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI8[ii]), v0); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI8[ii]), v0); } } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI16[ii]), v0); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI16[ii]), v0); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI32[ii]), v0); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI32[ii]), v0); } } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI64[ii]), v0); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI64[ii]), v0); } } - - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.F[ii]), v0); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.F[ii]), v0); } } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { data.image[IDout].array.D[ii] = pt2function(data.image[ID].array.D[ii], v0); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif - +#endif - if(data.Debug > 0) + if (data.Debug > 0) { printf("arith_image_function_d_d DONE\n"); fflush(stdout); } - return RETURN_SUCCESS; } - - - - -errno_t arith_image_function_imdd_im__ddd_d( - const char *ID_name, - double v0, - double v1, - const char *ID_out, - double (*pt2function)(double, double, double) -) +errno_t arith_image_function_imdd_im__ddd_d(const char *ID_name, double v0, double v1, const char *ID_out, + double (*pt2function)(double, double, double)) { imageID ID; imageID IDout; @@ -424,189 +360,157 @@ errno_t arith_image_function_imdd_im__ddd_d( uint8_t datatype, datatypeout; long i; - - ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; naxis = data.image[ID].md[0].naxis; - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc() error"); exit(0); } - - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[ID].md[0].size[i]; } - datatypeout = _DATATYPE_FLOAT; - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { datatypeout = _DATATYPE_DOUBLE; } - create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); + create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); free(naxes); nelement = data.image[ID].md[0].nelement; - -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { -# endif - +#endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI8[ii]), v0, v1); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI8[ii]), v0, v1); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI16[ii]), v0, v1); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI16[ii]), v0, v1); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI32[ii]), v0, v1); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI32[ii]), v0, v1); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.UI64[ii]), v0, v1); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.UI64[ii]), v0, v1); } } - - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI8[ii]), v0, v1); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI8[ii]), v0, v1); } } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI16[ii]), v0, v1); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI16[ii]), v0, v1); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI32[ii]), v0, v1); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI32[ii]), v0, v1); } } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.SI64[ii]), v0, v1); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.SI64[ii]), v0, v1); } } - - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = (float) pt2function((double)( - data.image[ID].array.F[ii]), v0, v1); + data.image[IDout].array.F[ii] = (float)pt2function((double)(data.image[ID].array.F[ii]), v0, v1); } } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function(data.image[ID].array.D[ii], v0, - v1); + data.image[IDout].array.D[ii] = pt2function(data.image[ID].array.D[ii], v0, v1); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif - +#endif - if(data.Debug > 0) + if (data.Debug > 0) { printf("arith_image_function_d_d DONE\n"); fflush(stdout); } - return RETURN_SUCCESS; } - - - - /* ------------------------------------------------------------------------- */ /* image -> image */ /* ------------------------------------------------------------------------- */ - - - -errno_t arith_image_function_1_1_byID( - imageID ID, - imageID IDout, - double (*pt2function)(double) -) +errno_t arith_image_function_1_1_byID(imageID ID, imageID IDout, double (*pt2function)(double)) { uint32_t *naxes = NULL; long naxis; @@ -620,170 +524,144 @@ errno_t arith_image_function_1_1_byID( datatype = data.image[ID].md[0].datatype; naxis = data.image[ID].md[0].naxis; - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc() error"); exit(0); } - - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[ID].md[0].size[i]; } - -// datatypeout = _DATATYPE_FLOAT; -// if(datatype == _DATATYPE_DOUBLE) -// datatypeout = _DATATYPE_DOUBLE; + // datatypeout = _DATATYPE_FLOAT; + // if(datatype == _DATATYPE_DOUBLE) + // datatypeout = _DATATYPE_DOUBLE; free(naxes); nelement = data.image[ID].md[0].nelement; - -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { -# endif - +#endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI8[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI8[ii])); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI16[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI16[ii])); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI32[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI32[ii])); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI64[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI64[ii])); } } - - - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI8[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI8[ii])); } } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI16[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI16[ii])); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI32[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI32[ii])); } } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI64[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI64[ii])); } } - - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.F[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii])); } } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = (double) pt2function((double)( - data.image[ID].array.D[ii])); + data.image[IDout].array.D[ii] = (double)pt2function((double)(data.image[ID].array.D[ii])); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif return RETURN_SUCCESS; } - - - - - -errno_t arith_image_function_1_1( - const char *ID_name, - const char *ID_out, - double (*pt2function)(double) -) +errno_t arith_image_function_1_1(const char *ID_name, const char *ID_out, double (*pt2function)(double)) { imageID ID; imageID IDout; @@ -799,170 +677,146 @@ errno_t arith_image_function_1_1( ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; naxis = data.image[ID].md[0].naxis; - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc() error"); exit(0); } - - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[ID].md[0].size[i]; } - datatypeout = _DATATYPE_FLOAT; - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { datatypeout = _DATATYPE_DOUBLE; } - create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); + create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); free(naxes); nelement = data.image[ID].md[0].nelement; - -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { -# endif - +#endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI8[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI8[ii])); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI16[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI16[ii])); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI32[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI32[ii])); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI64[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI64[ii])); } } - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI8[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI8[ii])); } } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI16[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI16[ii])); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI32[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI32[ii])); } } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI64[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI64[ii])); } } - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.F[ii])); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii])); } } - - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = (double) pt2function((double)( - data.image[ID].array.D[ii])); + data.image[IDout].array.D[ii] = (double)pt2function((double)(data.image[ID].array.D[ii])); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif return RETURN_SUCCESS; } - - - - - // imagein -> imagein (in place) -errno_t arith_image_function_1_1_inplace_byID( - imageID ID, - double (*pt2function)(double) -) +errno_t arith_image_function_1_1_inplace_byID(imageID ID, double (*pt2function)(double)) { long ii; long nelement; @@ -980,129 +834,118 @@ errno_t arith_image_function_1_1_inplace_byID( nelement = data.image[ID].md[0].nelement; data.image[ID].md[0].write = 0; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { #endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.UI8[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI8[ii])); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.UI16[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI16[ii])); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.UI32[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI32[ii])); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.UI64[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI64[ii])); } } - - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.SI8[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI8[ii])); } } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.SI16[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI16[ii])); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.SI32[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI32[ii])); } } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.SI64[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI64[ii])); } } - - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii])); } } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.D[ii] = (double) pt2function((double)( - data.image[ID].array.D[ii])); + data.image[ID].array.D[ii] = (double)pt2function((double)(data.image[ID].array.D[ii])); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif data.image[ID].md[0].write = 0; data.image[ID].md[0].cnt0++; @@ -1110,16 +953,8 @@ errno_t arith_image_function_1_1_inplace_byID( return RETURN_SUCCESS; } - - - - - // imagein -> imagein (in place) -errno_t arith_image_function_1_1_inplace( - const char *ID_name, - double (*pt2function)(double) -) +errno_t arith_image_function_1_1_inplace(const char *ID_name, double (*pt2function)(double)) { imageID ID; long ii; @@ -1132,135 +967,124 @@ errno_t arith_image_function_1_1_inplace( ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; -// datatypeout = _DATATYPE_FLOAT; -// if(datatype == _DATATYPE_DOUBLE) -// datatypeout = _DATATYPE_DOUBLE; + // datatypeout = _DATATYPE_FLOAT; + // if(datatype == _DATATYPE_DOUBLE) + // datatypeout = _DATATYPE_DOUBLE; nelement = data.image[ID].md[0].nelement; data.image[ID].md[0].write = 0; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { #endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.UI8[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI8[ii])); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.UI16[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI16[ii])); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.UI32[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI32[ii])); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.UI64[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI64[ii])); } } - - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.SI8[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI8[ii])); } } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.SI16[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI16[ii])); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.SI32[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI32[ii])); } } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.SI64[ii])); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI64[ii])); } } - - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii])); } } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.D[ii] = (double) pt2function((double)( - data.image[ID].array.D[ii])); + data.image[ID].array.D[ii] = (double)pt2function((double)(data.image[ID].array.D[ii])); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif data.image[ID].md[0].write = 0; data.image[ID].md[0].cnt0++; @@ -1268,24 +1092,12 @@ errno_t arith_image_function_1_1_inplace( return RETURN_SUCCESS; } - - - - - - - /* ------------------------------------------------------------------------- */ /* image, image -> image */ /* ------------------------------------------------------------------------- */ - -errno_t arith_image_function_2_1( - const char *ID_name1, - const char *ID_name2, - const char *ID_out, - double (*pt2function)(double, double) -) +errno_t arith_image_function_2_1(const char *ID_name1, const char *ID_name2, const char *ID_out, + double (*pt2function)(double, double)) { imageID ID1; imageID ID2; @@ -1300,21 +1112,19 @@ errno_t arith_image_function_2_1( int op3D2Dto3D = 0; // 3D image, 2D image -> 3D image long xysize; - - ID1 = image_ID(ID_name1); ID2 = image_ID(ID_name2); //list_image_ID(); //TEST printf("%s IDs : %ld %ld\n", __FUNCTION__, ID1, ID2); - if(ID1 == -1) + if (ID1 == -1) { PRINT_WARNING("Image %s does not exist: cannot proceed\n", ID_name1); return 1; } - if(ID2 == -1) + if (ID2 == -1) { PRINT_WARNING("Image %s does not exist: cannot proceed\n", ID_name2); return 1; @@ -1325,68 +1135,59 @@ errno_t arith_image_function_2_1( naxis = data.image[ID1].md[0].naxis; naxis2 = data.image[ID2].md[0].naxis; - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc() error"); abort(); } - naxes2 = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes2 == NULL) + naxes2 = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes2 == NULL) { PRINT_ERROR("malloc() error"); abort(); } - - for(uint8_t i = 0; i < naxis; i++) + for (uint8_t i = 0; i < naxis; i++) { naxes[i] = data.image[ID1].md[0].size[i]; } - for(uint8_t i = 0; i < naxis2; i++) + for (uint8_t i = 0; i < naxis2; i++) { naxes2[i] = data.image[ID2].md[0].size[i]; } - datatypeout = _DATATYPE_FLOAT; // default // other cases // DOUBLE * -> DOUBLE - if(datatype1 == _DATATYPE_DOUBLE) + if (datatype1 == _DATATYPE_DOUBLE) { datatypeout = _DATATYPE_DOUBLE; } // * DOUBLE -> DOUBLE - if(datatype2 == _DATATYPE_DOUBLE) + if (datatype2 == _DATATYPE_DOUBLE) { datatypeout = _DATATYPE_DOUBLE; } - - - create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); - - + create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); nelement1 = data.image[ID1].md[0].nelement; nelement2 = data.image[ID2].md[0].nelement; - // test if 3D 2D -> 3D operation op3D2Dto3D = 0; xysize = 0; - if((naxis == 3) && (naxis2 == 2)) + if ((naxis == 3) && (naxis2 == 2)) { - printf("naxes: %ld %ld %ld %ld\n", (long) naxes[0], (long) naxes2[0], - (long) naxes[1], (long) naxes2[1]); + printf("naxes: %ld %ld %ld %ld\n", (long)naxes[0], (long)naxes2[0], (long)naxes[1], (long)naxes2[1]); fflush(stdout); - if((naxes[0] == naxes2[0]) && (naxes[1] == naxes2[1])) + if ((naxes[0] == naxes2[0]) && (naxes[1] == naxes2[1])) { op3D2Dto3D = 1; xysize = naxes[0] * naxes[1]; @@ -1396,2589 +1197,2551 @@ errno_t arith_image_function_2_1( } } - nelement = nelement1; - if(op3D2Dto3D == 0) - if(nelement1 != nelement2) + if (op3D2Dto3D == 0) + if (nelement1 != nelement2) { - PRINT_ERROR( - "images %s and %s have different number of elements ( %ld %ld )\n", ID_name1, - ID_name2, nelement1, nelement2); + PRINT_ERROR("images %s and %s have different number of elements ( %ld %ld )\n", ID_name1, ID_name2, + nelement1, nelement2); exit(0); } + //# ifdef _OPENMP + // #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) + // { + //# endif - - -//# ifdef _OPENMP -// #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) -// { -//# endif - - -// ID1 datatype UINT8 - if(datatype1 == _DATATYPE_UINT8) + // ID1 datatype UINT8 + if (datatype1 == _DATATYPE_UINT8) { - if(datatype2 == _DATATYPE_UINT8) // UINT8 UINT8 -> FLOAT + if (datatype2 == _DATATYPE_UINT8) // UINT8 UINT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.UI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI8[kk * xysize + ii]), - (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI8[kk * xysize + ii]), + (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // UINT8 UINT16 -> FLOAT + if (datatype2 == _DATATYPE_UINT16) // UINT8 UINT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.UI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI8[kk * xysize + ii]), - (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI8[kk * xysize + ii]), + (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // UINT8 UINT32 -> FLOAT + if (datatype2 == _DATATYPE_UINT32) // UINT8 UINT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.UI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI8[kk * xysize + ii]), - (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI8[kk * xysize + ii]), + (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // UINT8 UINT64 -> FLOAT + if (datatype2 == _DATATYPE_UINT64) // UINT8 UINT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.UI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI8[kk * xysize + ii]), - (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI8[kk * xysize + ii]), + (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // UINT8 INT8 -> FLOAT + if (datatype2 == _DATATYPE_INT8) // UINT8 INT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.SI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI8[kk * xysize + ii]), - (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI8[kk * xysize + ii]), + (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // UINT8 INT16 -> FLOAT + if (datatype2 == _DATATYPE_INT16) // UINT8 INT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.SI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI8[kk * xysize + ii]), - (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI8[kk * xysize + ii]), + (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // UINT8 INT32 -> FLOAT + if (datatype2 == _DATATYPE_INT32) // UINT8 INT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.SI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI8[kk * xysize + ii]), - (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI8[kk * xysize + ii]), + (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // UINT8 INT64 -> FLOAT + if (datatype2 == _DATATYPE_INT64) // UINT8 INT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.SI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI8[kk * xysize + ii]), - (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI8[kk * xysize + ii]), + (double)(data.image[ID2].array.SI64[ii])); } } - if(datatype2 == _DATATYPE_FLOAT) // UINT8 FLOAT -> FLOAT + if (datatype2 == _DATATYPE_FLOAT) // UINT8 FLOAT -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI8[ii]), (double)(data.image[ID2].array.F[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI8[kk * xysize + ii]), - (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI8[kk * xysize + ii]), + (double)(data.image[ID2].array.F[ii])); } } - if(datatype2 == _DATATYPE_DOUBLE) // UINT8 DOUBLE -> DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // UINT8 DOUBLE -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function((double)( - data.image[ID1].array.UI8[ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[ii] = + pt2function((double)(data.image[ID1].array.UI8[ii]), data.image[ID2].array.D[ii]); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.D[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI8[kk * xysize + ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[kk * xysize + ii] = pt2function( + (double)(data.image[ID1].array.UI8[kk * xysize + ii]), data.image[ID2].array.D[ii]); } } } + // ID1 datatype UINT16 - -// ID1 datatype UINT16 - - if(datatype1 == _DATATYPE_UINT16) + if (datatype1 == _DATATYPE_UINT16) { - if(datatype2 == _DATATYPE_UINT8) // UINT16 UINT8 -> FLOAT + if (datatype2 == _DATATYPE_UINT8) // UINT16 UINT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.UI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI16[kk * xysize + ii]), - (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI16[kk * xysize + ii]), + (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // UINT16 UINT16 -> FLOAT + if (datatype2 == _DATATYPE_UINT16) // UINT16 UINT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.UI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI16[kk * xysize + ii]), - (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI16[kk * xysize + ii]), + (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // UINT16 UINT32 -> FLOAT + if (datatype2 == _DATATYPE_UINT32) // UINT16 UINT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.UI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI16[kk * xysize + ii]), - (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI16[kk * xysize + ii]), + (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // UINT16 UINT64 -> FLOAT + if (datatype2 == _DATATYPE_UINT64) // UINT16 UINT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.UI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI16[kk * xysize + ii]), - (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI16[kk * xysize + ii]), + (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // UINT16 INT8 -> FLOAT + if (datatype2 == _DATATYPE_INT8) // UINT16 INT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.SI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI16[kk * xysize + ii]), - (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI16[kk * xysize + ii]), + (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // UINT16 INT16 -> FLOAT + if (datatype2 == _DATATYPE_INT16) // UINT16 INT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.SI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI16[kk * xysize + ii]), - (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI16[kk * xysize + ii]), + (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // UINT16 INT32 -> FLOAT + if (datatype2 == _DATATYPE_INT32) // UINT16 INT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.SI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI16[kk * xysize + ii]), - (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI16[kk * xysize + ii]), + (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // UINT16 INT64 -> FLOAT + if (datatype2 == _DATATYPE_INT64) // UINT16 INT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.SI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI16[kk * xysize + ii]), - (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI16[kk * xysize + ii]), + (double)(data.image[ID2].array.SI64[ii])); } } - if(datatype2 == _DATATYPE_FLOAT) // UINT16 FLOAT -> FLOAT + if (datatype2 == _DATATYPE_FLOAT) // UINT16 FLOAT -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI16[ii]), (double)(data.image[ID2].array.F[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI16[kk * xysize + ii]), - (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI16[kk * xysize + ii]), + (double)(data.image[ID2].array.F[ii])); } } - if(datatype2 == _DATATYPE_DOUBLE) // UINT16 DOUBLE -> DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // UINT16 DOUBLE -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function((double)( - data.image[ID1].array.UI16[ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[ii] = + pt2function((double)(data.image[ID1].array.UI16[ii]), data.image[ID2].array.D[ii]); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.D[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI16[kk * xysize + ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[kk * xysize + ii] = pt2function( + (double)(data.image[ID1].array.UI16[kk * xysize + ii]), data.image[ID2].array.D[ii]); } } } - -// ID1 datatype UINT32 - if(datatype1 == _DATATYPE_UINT32) + // ID1 datatype UINT32 + if (datatype1 == _DATATYPE_UINT32) { - if(datatype2 == _DATATYPE_UINT8) // UINT32 UINT8 -> FLOAT + if (datatype2 == _DATATYPE_UINT8) // UINT32 UINT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.UI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI32[kk * xysize + ii]), - (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI32[kk * xysize + ii]), + (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // UINT32 UINT16 -> FLOAT + if (datatype2 == _DATATYPE_UINT16) // UINT32 UINT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.UI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI32[kk * xysize + ii]), - (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI32[kk * xysize + ii]), + (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // UINT32 UINT32 -> FLOAT + if (datatype2 == _DATATYPE_UINT32) // UINT32 UINT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.UI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI32[kk * xysize + ii]), - (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI32[kk * xysize + ii]), + (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // UINT32 UINT64 -> FLOAT + if (datatype2 == _DATATYPE_UINT64) // UINT32 UINT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.UI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI32[kk * xysize + ii]), - (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI32[kk * xysize + ii]), + (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // UINT32 INT8 -> FLOAT + if (datatype2 == _DATATYPE_INT8) // UINT32 INT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.SI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI32[kk * xysize + ii]), - (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI32[kk * xysize + ii]), + (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // UINT32 INT16 -> FLOAT + if (datatype2 == _DATATYPE_INT16) // UINT32 INT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.SI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI32[kk * xysize + ii]), - (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI32[kk * xysize + ii]), + (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // UINT32 INT32 -> FLOAT + if (datatype2 == _DATATYPE_INT32) // UINT32 INT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.SI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI32[kk * xysize + ii]), - (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI32[kk * xysize + ii]), + (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // UINT32 INT64 -> FLOAT + if (datatype2 == _DATATYPE_INT64) // UINT32 INT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.SI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI32[kk * xysize + ii]), - (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI32[kk * xysize + ii]), + (double)(data.image[ID2].array.SI64[ii])); } } - if(datatype2 == _DATATYPE_FLOAT) // UINT32 FLOAT -> FLOAT + if (datatype2 == _DATATYPE_FLOAT) // UINT32 FLOAT -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI32[ii]), (double)(data.image[ID2].array.F[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI32[kk * xysize + ii]), - (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI32[kk * xysize + ii]), + (double)(data.image[ID2].array.F[ii])); } } - if(datatype2 == _DATATYPE_DOUBLE) // UINT32 DOUBLE -> DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // UINT32 DOUBLE -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function((double)( - data.image[ID1].array.UI32[ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[ii] = + pt2function((double)(data.image[ID1].array.UI32[ii]), data.image[ID2].array.D[ii]); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.D[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI32[kk * xysize + ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[kk * xysize + ii] = pt2function( + (double)(data.image[ID1].array.UI32[kk * xysize + ii]), data.image[ID2].array.D[ii]); } } } - - -// ID1 datatype UINT64 - if(datatype1 == _DATATYPE_UINT64) + // ID1 datatype UINT64 + if (datatype1 == _DATATYPE_UINT64) { - if(datatype2 == _DATATYPE_UINT8) // UINT64 UINT8 -> FLOAT + if (datatype2 == _DATATYPE_UINT8) // UINT64 UINT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.UI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI64[kk * xysize + ii]), - (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI64[kk * xysize + ii]), + (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // UINT64 UINT16 -> FLOAT + if (datatype2 == _DATATYPE_UINT16) // UINT64 UINT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.UI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI64[kk * xysize + ii]), - (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI64[kk * xysize + ii]), + (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // UINT64 UINT32 -> FLOAT + if (datatype2 == _DATATYPE_UINT32) // UINT64 UINT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.UI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI64[kk * xysize + ii]), - (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI64[kk * xysize + ii]), + (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // UINT64 UINT64 -> FLOAT + if (datatype2 == _DATATYPE_UINT64) // UINT64 UINT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.UI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI64[kk * xysize + ii]), - (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI64[kk * xysize + ii]), + (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // UINT64 INT8 -> FLOAT + if (datatype2 == _DATATYPE_INT8) // UINT64 INT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.SI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI64[kk * xysize + ii]), - (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI64[kk * xysize + ii]), + (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // UINT64 INT16 -> FLOAT + if (datatype2 == _DATATYPE_INT16) // UINT64 INT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.SI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI64[kk * xysize + ii]), - (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI64[kk * xysize + ii]), + (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // UINT64 INT32 -> FLOAT + if (datatype2 == _DATATYPE_INT32) // UINT64 INT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.SI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI64[kk * xysize + ii]), - (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI64[kk * xysize + ii]), + (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // UINT64 INT64 -> FLOAT + if (datatype2 == _DATATYPE_INT64) // UINT64 INT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.SI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI64[kk * xysize + ii]), - (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI64[kk * xysize + ii]), + (double)(data.image[ID2].array.SI64[ii])); } } - if(datatype2 == _DATATYPE_FLOAT) // UINT64 FLOAT -> FLOAT + if (datatype2 == _DATATYPE_FLOAT) // UINT64 FLOAT -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.UI64[ii]), (double)(data.image[ID2].array.F[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI64[kk * xysize + ii]), - (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.UI64[kk * xysize + ii]), + (double)(data.image[ID2].array.F[ii])); } } - if(datatype2 == _DATATYPE_DOUBLE) // UINT64 DOUBLE -> DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // UINT64 DOUBLE -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function((double)( - data.image[ID1].array.UI64[ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[ii] = + pt2function((double)(data.image[ID1].array.UI64[ii]), data.image[ID2].array.D[ii]); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.D[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.UI64[kk * xysize + ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[kk * xysize + ii] = pt2function( + (double)(data.image[ID1].array.UI64[kk * xysize + ii]), data.image[ID2].array.D[ii]); } } } + // ID1 datatype INT8 - -// ID1 datatype INT8 - - if(datatype1 == _DATATYPE_INT8) + if (datatype1 == _DATATYPE_INT8) { - if(datatype2 == _DATATYPE_UINT8) // INT8 UINT8 -> FLOAT + if (datatype2 == _DATATYPE_UINT8) // INT8 UINT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.UI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI8[kk * xysize + ii]), - (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI8[kk * xysize + ii]), + (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // INT8 UINT16 -> FLOAT + if (datatype2 == _DATATYPE_UINT16) // INT8 UINT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.UI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI8[kk * xysize + ii]), - (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI8[kk * xysize + ii]), + (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // INT8 UINT32 -> FLOAT + if (datatype2 == _DATATYPE_UINT32) // INT8 UINT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.UI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI8[kk * xysize + ii]), - (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI8[kk * xysize + ii]), + (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // INT8 UINT64 -> FLOAT + if (datatype2 == _DATATYPE_UINT64) // INT8 UINT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.UI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI8[kk * xysize + ii]), - (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI8[kk * xysize + ii]), + (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // INT8 INT8 -> FLOAT + if (datatype2 == _DATATYPE_INT8) // INT8 INT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.SI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI8[kk * xysize + ii]), - (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI8[kk * xysize + ii]), + (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // INT8 INT16 -> FLOAT + if (datatype2 == _DATATYPE_INT16) // INT8 INT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.SI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI8[kk * xysize + ii]), - (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI8[kk * xysize + ii]), + (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // INT8 INT32 -> FLOAT + if (datatype2 == _DATATYPE_INT32) // INT8 INT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.SI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI8[kk * xysize + ii]), - (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI8[kk * xysize + ii]), + (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // INT8 INT64 -> FLOAT + if (datatype2 == _DATATYPE_INT64) // INT8 INT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.SI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI8[kk * xysize + ii]), - (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI8[kk * xysize + ii]), + (double)(data.image[ID2].array.SI64[ii])); } } - if(datatype2 == _DATATYPE_FLOAT) // INT8 FLOAT -> FLOAT + if (datatype2 == _DATATYPE_FLOAT) // INT8 FLOAT -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI8[ii]), (double)(data.image[ID2].array.F[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI8[kk * xysize + ii]), - (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI8[kk * xysize + ii]), + (double)(data.image[ID2].array.F[ii])); } } - if(datatype2 == _DATATYPE_DOUBLE) // INT8 DOUBLE -> DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // INT8 DOUBLE -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function((double)( - data.image[ID1].array.SI8[ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[ii] = + pt2function((double)(data.image[ID1].array.SI8[ii]), data.image[ID2].array.D[ii]); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.D[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI8[kk * xysize + ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[kk * xysize + ii] = pt2function( + (double)(data.image[ID1].array.SI8[kk * xysize + ii]), data.image[ID2].array.D[ii]); } } } + // ID1 datatype INT16 - -// ID1 datatype INT16 - - if(datatype1 == _DATATYPE_INT16) + if (datatype1 == _DATATYPE_INT16) { - if(datatype2 == _DATATYPE_UINT8) // INT16 UINT8 -> FLOAT + if (datatype2 == _DATATYPE_UINT8) // INT16 UINT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.UI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI16[kk * xysize + ii]), - (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI16[kk * xysize + ii]), + (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // INT16 UINT16 -> FLOAT + if (datatype2 == _DATATYPE_UINT16) // INT16 UINT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.UI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI16[kk * xysize + ii]), - (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI16[kk * xysize + ii]), + (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // INT16 UINT32 -> FLOAT + if (datatype2 == _DATATYPE_UINT32) // INT16 UINT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.UI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI16[kk * xysize + ii]), - (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI16[kk * xysize + ii]), + (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // INT16 UINT64 -> FLOAT + if (datatype2 == _DATATYPE_UINT64) // INT16 UINT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.UI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI16[kk * xysize + ii]), - (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI16[kk * xysize + ii]), + (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // INT16 INT8 -> FLOAT + if (datatype2 == _DATATYPE_INT8) // INT16 INT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.SI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI16[kk * xysize + ii]), - (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI16[kk * xysize + ii]), + (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // INT16 INT16 -> FLOAT + if (datatype2 == _DATATYPE_INT16) // INT16 INT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.SI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI16[kk * xysize + ii]), - (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI16[kk * xysize + ii]), + (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // INT16 INT32 -> FLOAT + if (datatype2 == _DATATYPE_INT32) // INT16 INT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.SI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI16[kk * xysize + ii]), - (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI16[kk * xysize + ii]), + (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // INT16 INT64 -> FLOAT + if (datatype2 == _DATATYPE_INT64) // INT16 INT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.SI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI16[kk * xysize + ii]), - (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI16[kk * xysize + ii]), + (double)(data.image[ID2].array.SI64[ii])); } } - if(datatype2 == _DATATYPE_FLOAT) // INT16 FLOAT -> FLOAT + if (datatype2 == _DATATYPE_FLOAT) // INT16 FLOAT -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI16[ii]), (double)(data.image[ID2].array.F[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI16[kk * xysize + ii]), - (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI16[kk * xysize + ii]), + (double)(data.image[ID2].array.F[ii])); } } - if(datatype2 == _DATATYPE_DOUBLE) // INT16 DOUBLE -> DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // INT16 DOUBLE -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function((double)( - data.image[ID1].array.SI16[ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[ii] = + pt2function((double)(data.image[ID1].array.SI16[ii]), data.image[ID2].array.D[ii]); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.D[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI16[kk * xysize + ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[kk * xysize + ii] = pt2function( + (double)(data.image[ID1].array.SI16[kk * xysize + ii]), data.image[ID2].array.D[ii]); } } } + // ID1 datatype INT32 - -// ID1 datatype INT32 - - if(datatype1 == _DATATYPE_INT32) + if (datatype1 == _DATATYPE_INT32) { - if(datatype2 == _DATATYPE_UINT8) // INT32 UINT8 -> FLOAT + if (datatype2 == _DATATYPE_UINT8) // INT32 UINT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.UI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI32[kk * xysize + ii]), - (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI32[kk * xysize + ii]), + (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // INT32 UINT16 -> FLOAT + if (datatype2 == _DATATYPE_UINT16) // INT32 UINT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.UI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI32[kk * xysize + ii]), - (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI32[kk * xysize + ii]), + (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // INT32 UINT32 -> FLOAT + if (datatype2 == _DATATYPE_UINT32) // INT32 UINT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.UI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI32[kk * xysize + ii]), - (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI32[kk * xysize + ii]), + (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // INT32 UINT64 -> FLOAT + if (datatype2 == _DATATYPE_UINT64) // INT32 UINT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.UI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI32[kk * xysize + ii]), - (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI32[kk * xysize + ii]), + (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // INT32 INT8 -> FLOAT + if (datatype2 == _DATATYPE_INT8) // INT32 INT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.SI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI32[kk * xysize + ii]), - (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI32[kk * xysize + ii]), + (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // INT32 INT16 -> FLOAT + if (datatype2 == _DATATYPE_INT16) // INT32 INT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.SI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI32[kk * xysize + ii]), - (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI32[kk * xysize + ii]), + (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // INT32 INT32 -> FLOAT + if (datatype2 == _DATATYPE_INT32) // INT32 INT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.SI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI32[kk * xysize + ii]), - (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI32[kk * xysize + ii]), + (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // INT32 INT64 -> FLOAT + if (datatype2 == _DATATYPE_INT64) // INT32 INT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.SI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI32[kk * xysize + ii]), - (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI32[kk * xysize + ii]), + (double)(data.image[ID2].array.SI64[ii])); } } - if(datatype2 == _DATATYPE_FLOAT) // INT32 FLOAT -> FLOAT + if (datatype2 == _DATATYPE_FLOAT) // INT32 FLOAT -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI32[ii]), (double)(data.image[ID2].array.F[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI32[kk * xysize + ii]), - (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI32[kk * xysize + ii]), + (double)(data.image[ID2].array.F[ii])); } } - if(datatype2 == _DATATYPE_DOUBLE) // INT32 DOUBLE -> DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // INT32 DOUBLE -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function((double)( - data.image[ID1].array.SI32[ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[ii] = + pt2function((double)(data.image[ID1].array.SI32[ii]), data.image[ID2].array.D[ii]); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.D[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI32[kk * xysize + ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[kk * xysize + ii] = pt2function( + (double)(data.image[ID1].array.SI32[kk * xysize + ii]), data.image[ID2].array.D[ii]); } } } - - -// ID1 datatype INT64 - if(datatype1 == _DATATYPE_INT64) + // ID1 datatype INT64 + if (datatype1 == _DATATYPE_INT64) { - if(datatype2 == _DATATYPE_UINT8) // INT64 UINT8 -> FLOAT + if (datatype2 == _DATATYPE_UINT8) // INT64 UINT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.UI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI64[kk * xysize + ii]), - (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI64[kk * xysize + ii]), + (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // INT64 UINT16 -> FLOAT + if (datatype2 == _DATATYPE_UINT16) // INT64 UINT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.UI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI64[kk * xysize + ii]), - (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI64[kk * xysize + ii]), + (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // INT64 UINT32 -> FLOAT + if (datatype2 == _DATATYPE_UINT32) // INT64 UINT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.UI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI64[kk * xysize + ii]), - (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI64[kk * xysize + ii]), + (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // INT64 UINT64 -> FLOAT + if (datatype2 == _DATATYPE_UINT64) // INT64 UINT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.UI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI64[kk * xysize + ii]), - (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI64[kk * xysize + ii]), + (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // INT64 INT8 -> FLOAT + if (datatype2 == _DATATYPE_INT8) // INT64 INT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.SI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI64[kk * xysize + ii]), - (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI64[kk * xysize + ii]), + (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // INT64 INT16 -> FLOAT + if (datatype2 == _DATATYPE_INT16) // INT64 INT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.SI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI64[kk * xysize + ii]), - (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI64[kk * xysize + ii]), + (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // INT64 INT32 -> FLOAT + if (datatype2 == _DATATYPE_INT32) // INT64 INT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.SI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI64[kk * xysize + ii]), - (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI64[kk * xysize + ii]), + (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // INT64 INT64 -> FLOAT + if (datatype2 == _DATATYPE_INT64) // INT64 INT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.SI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI64[kk * xysize + ii]), - (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI64[kk * xysize + ii]), + (double)(data.image[ID2].array.SI64[ii])); } } - if(datatype2 == _DATATYPE_FLOAT) // INT64 FLOAT -> FLOAT + if (datatype2 == _DATATYPE_FLOAT) // INT64 FLOAT -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.SI64[ii]), (double)(data.image[ID2].array.F[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI64[kk * xysize + ii]), - (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.SI64[kk * xysize + ii]), + (double)(data.image[ID2].array.F[ii])); } } - if(datatype2 == _DATATYPE_DOUBLE) // INT64 DOUBLE -> DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // INT64 DOUBLE -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function((double)( - data.image[ID1].array.SI64[ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[ii] = + pt2function((double)(data.image[ID1].array.SI64[ii]), data.image[ID2].array.D[ii]); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.D[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.SI64[kk * xysize + ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[kk * xysize + ii] = pt2function( + (double)(data.image[ID1].array.SI64[kk * xysize + ii]), data.image[ID2].array.D[ii]); } } } - - -// ID1 datatype FLOAT - if(datatype1 == _DATATYPE_FLOAT) + // ID1 datatype FLOAT + if (datatype1 == _DATATYPE_FLOAT) { - if(datatype2 == _DATATYPE_UINT8) // FLOAT UINT8 -> FLOAT + if (datatype2 == _DATATYPE_UINT8) // FLOAT UINT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.F[kk * xysize + ii]), - (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.F[kk * xysize + ii]), + (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // FLOAT UINT16 -> FLOAT + if (datatype2 == _DATATYPE_UINT16) // FLOAT UINT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.F[kk * xysize + ii]), - (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.F[kk * xysize + ii]), + (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // FLOAT UINT32 -> FLOAT + if (datatype2 == _DATATYPE_UINT32) // FLOAT UINT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.F[kk * xysize + ii]), - (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.F[kk * xysize + ii]), + (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // FLOAT UINT64 -> FLOAT + if (datatype2 == _DATATYPE_UINT64) // FLOAT UINT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.F[kk * xysize + ii]), - (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.F[kk * xysize + ii]), + (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // FLOAT INT8 -> FLOAT + if (datatype2 == _DATATYPE_INT8) // FLOAT INT8 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.F[kk * xysize + ii]), - (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.F[kk * xysize + ii]), + (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // FLOAT INT16 -> FLOAT + if (datatype2 == _DATATYPE_INT16) // FLOAT INT16 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.F[kk * xysize + ii]), - (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.F[kk * xysize + ii]), + (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // FLOAT INT32 -> FLOAT + if (datatype2 == _DATATYPE_INT32) // FLOAT INT32 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.F[kk * xysize + ii]), - (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.F[kk * xysize + ii]), + (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // FLOAT INT64 -> FLOAT + if (datatype2 == _DATATYPE_INT64) // FLOAT INT64 -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.F[kk * xysize + ii]), - (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[kk * xysize + ii] = + pt2function((double)(data.image[ID1].array.F[kk * xysize + ii]), + (double)(data.image[ID2].array.SI64[ii])); } } - if(datatype2 == _DATATYPE_FLOAT) // FLOAT FLOAT -> FLOAT + if (datatype2 == _DATATYPE_FLOAT) // FLOAT FLOAT -> FLOAT { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.F[ii])); } - if(op3D2Dto3D == 1) + if (op3D2Dto3D == 1) { -//# ifdef _OPENMP -// #pragma omp for -//# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + //# ifdef _OPENMP + // #pragma omp for + //# endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.F[kk * xysize + ii]), - (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[kk * xysize + ii] = pt2function( + (double)(data.image[ID1].array.F[kk * xysize + ii]), (double)(data.image[ID2].array.F[ii])); } } } - if(datatype2 == _DATATYPE_DOUBLE) // FLOAT DOUBLE -> DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // FLOAT DOUBLE -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function((double)( - data.image[ID1].array.F[ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), data.image[ID2].array.D[ii]); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.D[kk * xysize + ii] = pt2function((double)( - data.image[ID1].array.F[kk * xysize + ii]), data.image[ID2].array.D[ii]); + data.image[IDout].array.D[kk * xysize + ii] = pt2function( + (double)(data.image[ID1].array.F[kk * xysize + ii]), data.image[ID2].array.D[ii]); } } } + // ID1 datatype DOUBLE - - -// ID1 datatype DOUBLE - - if(datatype1 == _DATATYPE_DOUBLE) + if (datatype1 == _DATATYPE_DOUBLE) { - if(datatype2 == _DATATYPE_UINT8) // DOUBLE UINT8 -> DOUBLE + if (datatype2 == _DATATYPE_UINT8) // DOUBLE UINT8 -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.UI8[ii])); + data.image[IDout].array.F[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.UI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[kk * xysize + ii] = pt2function( - data.image[ID1].array.D[kk * xysize + ii], - (double)(data.image[ID2].array.UI8[ii])); + data.image[ID1].array.D[kk * xysize + ii], (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // DOUBLE UINT16 -> DOUBLE + if (datatype2 == _DATATYPE_UINT16) // DOUBLE UINT16 -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.UI16[ii])); + data.image[IDout].array.F[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.UI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[kk * xysize + ii] = pt2function( - data.image[ID1].array.D[kk * xysize + ii], - (double)(data.image[ID2].array.UI16[ii])); + data.image[ID1].array.D[kk * xysize + ii], (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // DOUBLE UINT32 -> DOUBLE + if (datatype2 == _DATATYPE_UINT32) // DOUBLE UINT32 -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.UI32[ii])); + data.image[IDout].array.F[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.UI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[kk * xysize + ii] = pt2function( - data.image[ID1].array.D[kk * xysize + ii], - (double)(data.image[ID2].array.UI32[ii])); + data.image[ID1].array.D[kk * xysize + ii], (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // DOUBLE UINT64 -> DOUBLE + if (datatype2 == _DATATYPE_UINT64) // DOUBLE UINT64 -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.UI64[ii])); + data.image[IDout].array.F[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.UI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[kk * xysize + ii] = pt2function( - data.image[ID1].array.D[kk * xysize + ii], - (double)(data.image[ID2].array.UI64[ii])); + data.image[ID1].array.D[kk * xysize + ii], (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // DOUBLE INT8 -> DOUBLE + if (datatype2 == _DATATYPE_INT8) // DOUBLE INT8 -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.SI8[ii])); + data.image[IDout].array.F[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.SI8[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[kk * xysize + ii] = pt2function( - data.image[ID1].array.D[kk * xysize + ii], - (double)(data.image[ID2].array.SI8[ii])); + data.image[ID1].array.D[kk * xysize + ii], (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // DOUBLE INT16 -> DOUBLE + if (datatype2 == _DATATYPE_INT16) // DOUBLE INT16 -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.SI16[ii])); + data.image[IDout].array.F[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.SI16[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[kk * xysize + ii] = pt2function( - data.image[ID1].array.D[kk * xysize + ii], - (double)(data.image[ID2].array.SI16[ii])); + data.image[ID1].array.D[kk * xysize + ii], (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // DOUBLE INT32 -> DOUBLE + if (datatype2 == _DATATYPE_INT32) // DOUBLE INT32 -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.SI32[ii])); + data.image[IDout].array.F[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.SI32[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[kk * xysize + ii] = pt2function( - data.image[ID1].array.D[kk * xysize + ii], - (double)(data.image[ID2].array.SI32[ii])); + data.image[ID1].array.D[kk * xysize + ii], (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // DOUBLE INT64 -> DOUBLE + if (datatype2 == _DATATYPE_INT64) // DOUBLE INT64 -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.SI64[ii])); + data.image[IDout].array.F[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.SI64[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[kk * xysize + ii] = pt2function( - data.image[ID1].array.D[kk * xysize + ii], - (double)(data.image[ID2].array.SI64[ii])); + data.image[ID1].array.D[kk * xysize + ii], (double)(data.image[ID2].array.SI64[ii])); } } - if(datatype2 == _DATATYPE_FLOAT) // DOUBLE FLOAT -> DOUBLE + if (datatype2 == _DATATYPE_FLOAT) // DOUBLE FLOAT -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.F[ii])); + data.image[IDout].array.F[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.F[ii])); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[kk * xysize + ii] = pt2function( - data.image[ID1].array.D[kk * xysize + ii], - (double)(data.image[ID2].array.F[ii])); + data.image[ID1].array.D[kk * xysize + ii], (double)(data.image[ID2].array.F[ii])); } } - if(datatype2 == _DATATYPE_DOUBLE) // DOUBLE DOUBLE -> DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // DOUBLE DOUBLE -> DOUBLE { - if(op3D2Dto3D == 0) -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) + if (op3D2Dto3D == 0) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function(data.image[ID1].array.D[ii], - data.image[ID2].array.D[ii]); + data.image[IDout].array.D[ii] = + pt2function(data.image[ID1].array.D[ii], data.image[ID2].array.D[ii]); } - if(op3D2Dto3D == 1) -# ifdef _OPENMP - #pragma omp for -# endif - for(kk = 0; kk < naxes[2]; kk++) - for(ii = 0; ii < xysize; ii++) + if (op3D2Dto3D == 1) +#ifdef _OPENMP +#pragma omp for +#endif + for (kk = 0; kk < naxes[2]; kk++) + for (ii = 0; ii < xysize; ii++) { - data.image[IDout].array.D[kk * xysize + ii] = pt2function( - data.image[ID1].array.D[kk * xysize + ii], data.image[ID2].array.D[ii]); + data.image[IDout].array.D[kk * xysize + ii] = + pt2function(data.image[ID1].array.D[kk * xysize + ii], data.image[ID2].array.D[ii]); } } } - - - - -//# ifdef _OPENMP -// } -//# endif + //# ifdef _OPENMP + // } + //# endif free(naxes); free(naxes2); @@ -3986,16 +3749,7 @@ errno_t arith_image_function_2_1( return RETURN_SUCCESS; } - - - - - -errno_t arith_image_function_2_1_inplace_byID( - imageID ID1, - imageID ID2, - double (*pt2function)(double, double) -) +errno_t arith_image_function_2_1_inplace_byID(imageID ID1, imageID ID2, double (*pt2function)(double, double)) { long ii; long nelement1, nelement2, nelement; @@ -4007,313 +3761,297 @@ errno_t arith_image_function_2_1_inplace_byID( nelement2 = data.image[ID2].md[0].nelement; nelement = nelement1; - if(nelement1 != nelement2) + if (nelement1 != nelement2) { - PRINT_ERROR( - "images %ld and %ld have different number of elements\n", ID1, ID2); + PRINT_ERROR("images %ld and %ld have different number of elements\n", ID1, ID2); exit(0); } data.image[ID1].md[0].write = 1; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { -# endif +#endif // FLOAT - if(datatype1 == _DATATYPE_FLOAT) + if (datatype1 == _DATATYPE_FLOAT) { - if(datatype2 == _DATATYPE_UINT8) // FLOAT <- UINT8 + if (datatype2 == _DATATYPE_UINT8) // FLOAT <- UINT8 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.F[ii] = pt2function((double)(data.image[ID1].array.F[ii]), - (double)(data.image[ID2].array.UI8[ii])); + data.image[ID1].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // FLOAT <- UINT16 + if (datatype2 == _DATATYPE_UINT16) // FLOAT <- UINT16 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.F[ii] = pt2function((double)(data.image[ID1].array.F[ii]), - (double)(data.image[ID2].array.UI16[ii])); + data.image[ID1].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // FLOAT <- UINT32 + if (datatype2 == _DATATYPE_UINT32) // FLOAT <- UINT32 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.F[ii] = pt2function((double)(data.image[ID1].array.F[ii]), - (double)(data.image[ID2].array.UI32[ii])); + data.image[ID1].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // FLOAT <- UINT64 + if (datatype2 == _DATATYPE_UINT64) // FLOAT <- UINT64 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.F[ii] = pt2function((double)(data.image[ID1].array.F[ii]), - (double)(data.image[ID2].array.UI64[ii])); + data.image[ID1].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // FLOAT <- INT8 + if (datatype2 == _DATATYPE_INT8) // FLOAT <- INT8 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.F[ii] = pt2function((double)(data.image[ID1].array.F[ii]), - (double)(data.image[ID2].array.SI8[ii])); + data.image[ID1].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // FLOAT <- INT16 + if (datatype2 == _DATATYPE_INT16) // FLOAT <- INT16 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.F[ii] = pt2function((double)(data.image[ID1].array.F[ii]), - (double)(data.image[ID2].array.SI16[ii])); + data.image[ID1].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // FLOAT <- INT32 + if (datatype2 == _DATATYPE_INT32) // FLOAT <- INT32 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.F[ii] = pt2function((double)(data.image[ID1].array.F[ii]), - (double)(data.image[ID2].array.SI32[ii])); + data.image[ID1].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // FLOAT <- INT64 + if (datatype2 == _DATATYPE_INT64) // FLOAT <- INT64 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.F[ii] = pt2function((double)(data.image[ID1].array.F[ii]), - (double)(data.image[ID2].array.SI64[ii])); + data.image[ID1].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.SI64[ii])); } } - - if(datatype2 == _DATATYPE_FLOAT) // FLOAT <- FLOAT + if (datatype2 == _DATATYPE_FLOAT) // FLOAT <- FLOAT { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.F[ii] = pt2function((double)(data.image[ID1].array.F[ii]), - (double)(data.image[ID2].array.F[ii])); + data.image[ID1].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), (double)(data.image[ID2].array.F[ii])); } } - if(datatype2 == _DATATYPE_DOUBLE) // FLOAT <- DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // FLOAT <- DOUBLE { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.F[ii] = pt2function((double)(data.image[ID1].array.F[ii]), - data.image[ID2].array.D[ii]); + data.image[ID1].array.F[ii] = + pt2function((double)(data.image[ID1].array.F[ii]), data.image[ID2].array.D[ii]); } } - } - - // DOUBLE - if(datatype1 == _DATATYPE_DOUBLE) + if (datatype1 == _DATATYPE_DOUBLE) { - if(datatype2 == _DATATYPE_UINT8) // DOUBLE <- UINT8 + if (datatype2 == _DATATYPE_UINT8) // DOUBLE <- UINT8 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.D[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.UI8[ii])); + data.image[ID1].array.D[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.UI8[ii])); } } - if(datatype2 == _DATATYPE_UINT16) // DOUBLE <- UINT16 + if (datatype2 == _DATATYPE_UINT16) // DOUBLE <- UINT16 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.D[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.UI16[ii])); + data.image[ID1].array.D[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.UI16[ii])); } } - if(datatype2 == _DATATYPE_UINT32) // DOUBLE <- UINT32 + if (datatype2 == _DATATYPE_UINT32) // DOUBLE <- UINT32 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.D[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.UI32[ii])); + data.image[ID1].array.D[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.UI32[ii])); } } - if(datatype2 == _DATATYPE_UINT64) // DOUBLE <- UINT64 + if (datatype2 == _DATATYPE_UINT64) // DOUBLE <- UINT64 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.D[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.UI64[ii])); + data.image[ID1].array.D[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.UI64[ii])); } } - if(datatype2 == _DATATYPE_INT8) // DOUBLE <- INT8 + if (datatype2 == _DATATYPE_INT8) // DOUBLE <- INT8 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.D[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.SI8[ii])); + data.image[ID1].array.D[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.SI8[ii])); } } - if(datatype2 == _DATATYPE_INT16) // DOUBLE <- INT16 + if (datatype2 == _DATATYPE_INT16) // DOUBLE <- INT16 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.D[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.SI16[ii])); + data.image[ID1].array.D[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.SI16[ii])); } } - if(datatype2 == _DATATYPE_INT32) // DOUBLE <- INT32 + if (datatype2 == _DATATYPE_INT32) // DOUBLE <- INT32 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.D[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.SI32[ii])); + data.image[ID1].array.D[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.SI32[ii])); } } - if(datatype2 == _DATATYPE_INT64) // DOUBLE <- INT64 + if (datatype2 == _DATATYPE_INT64) // DOUBLE <- INT64 { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.D[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.SI64[ii])); + data.image[ID1].array.D[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.SI64[ii])); } } - - if(datatype2 == _DATATYPE_FLOAT) // DOUBLE <- FLOAT + if (datatype2 == _DATATYPE_FLOAT) // DOUBLE <- FLOAT { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.D[ii] = pt2function(data.image[ID1].array.D[ii], - (double)(data.image[ID2].array.F[ii])); + data.image[ID1].array.D[ii] = + pt2function(data.image[ID1].array.D[ii], (double)(data.image[ID2].array.F[ii])); } } - - if(datatype2 == _DATATYPE_DOUBLE) // DOUBLE <- DOUBLE + if (datatype2 == _DATATYPE_DOUBLE) // DOUBLE <- DOUBLE { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.D[ii] = pt2function(data.image[ID1].array.D[ii], - data.image[ID2].array.D[ii]); + data.image[ID1].array.D[ii] = pt2function(data.image[ID1].array.D[ii], data.image[ID2].array.D[ii]); } } } - - - - - - - if((datatype1 == _DATATYPE_COMPLEX_FLOAT) - && (datatype2 == _DATATYPE_COMPLEX_FLOAT)) + if ((datatype1 == _DATATYPE_COMPLEX_FLOAT) && (datatype2 == _DATATYPE_COMPLEX_FLOAT)) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.CF[ii].re = pt2function((double)( - data.image[ID1].array.CF[ii].re), (double)(data.image[ID2].array.CF[ii].re)); - data.image[ID1].array.CF[ii].im = pt2function((double)( - data.image[ID1].array.CF[ii].im), (double)(data.image[ID2].array.CF[ii].im)); + data.image[ID1].array.CF[ii].re = + pt2function((double)(data.image[ID1].array.CF[ii].re), (double)(data.image[ID2].array.CF[ii].re)); + data.image[ID1].array.CF[ii].im = + pt2function((double)(data.image[ID1].array.CF[ii].im), (double)(data.image[ID2].array.CF[ii].im)); } } - if((datatype1 == _DATATYPE_COMPLEX_DOUBLE) - && (datatype2 == _DATATYPE_COMPLEX_DOUBLE)) + if ((datatype1 == _DATATYPE_COMPLEX_DOUBLE) && (datatype2 == _DATATYPE_COMPLEX_DOUBLE)) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID1].array.CD[ii].re = pt2function((double)( - data.image[ID1].array.CD[ii].re), (double)(data.image[ID2].array.CD[ii].re)); - data.image[ID1].array.CD[ii].im = pt2function((double)( - data.image[ID1].array.CD[ii].im), (double)(data.image[ID2].array.CD[ii].im)); + data.image[ID1].array.CD[ii].re = + pt2function((double)(data.image[ID1].array.CD[ii].re), (double)(data.image[ID2].array.CD[ii].re)); + data.image[ID1].array.CD[ii].im = + pt2function((double)(data.image[ID1].array.CD[ii].im), (double)(data.image[ID2].array.CD[ii].im)); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif data.image[ID1].md[0].write = 0; data.image[ID1].md[0].cnt0++; @@ -4321,16 +4059,8 @@ errno_t arith_image_function_2_1_inplace_byID( return EXIT_SUCCESS; } - - - - - -errno_t arith_image_function_2_1_inplace( - const char *ID_name1, - const char *ID_name2, - double (*pt2function)(double, double) -) +errno_t arith_image_function_2_1_inplace(const char *ID_name1, const char *ID_name2, + double (*pt2function)(double, double)) { imageID ID1; imageID ID2; @@ -4343,26 +4073,12 @@ errno_t arith_image_function_2_1_inplace( return EXIT_SUCCESS; } - - - - - - - - - - /* ------------------------------------------------------------------------- */ /* complex image, complex image -> complex image */ /* ------------------------------------------------------------------------- */ // complex float (CF), complex float (CF) -> complex float (CF) -errno_t arith_image_function_CF_CF__CF( - const char *ID_name1, - const char *ID_name2, - const char *ID_out, - complex_float(*pt2function)(complex_float, complex_float) -) +errno_t arith_image_function_CF_CF__CF(const char *ID_name1, const char *ID_name2, const char *ID_out, + complex_float (*pt2function)(complex_float, complex_float)) { imageID ID1; imageID ID2; @@ -4379,50 +4095,41 @@ errno_t arith_image_function_CF_CF__CF( datatype1 = data.image[ID1].md[0].datatype; //datatype2 = data.image[ID2].md[0].datatype; naxis = data.image[ID1].md[0].naxis; - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc() error"); exit(0); } - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[ID1].md[0].size[i]; } - create_image_ID(ID_out, naxis, naxes, datatype1, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); + create_image_ID(ID_out, naxis, naxes, datatype1, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); free(naxes); nelement = data.image[ID1].md[0].nelement; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.CF[ii] = pt2function(data.image[ID1].array.CF[ii], - data.image[ID2].array.CF[ii]); + data.image[IDout].array.CF[ii] = pt2function(data.image[ID1].array.CF[ii], data.image[ID2].array.CF[ii]); } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif return RETURN_SUCCESS; } - - - // complex double (CD), complex double (CD) -> complex double (CD) -errno_t arith_image_function_CD_CD__CD( - const char *ID_name1, - const char *ID_name2, - const char *ID_out, - complex_double(*pt2function)(complex_double, complex_double) -) +errno_t arith_image_function_CD_CD__CD(const char *ID_name1, const char *ID_name2, const char *ID_out, + complex_double (*pt2function)(complex_double, complex_double)) { imageID ID1; imageID ID2; @@ -4439,51 +4146,43 @@ errno_t arith_image_function_CD_CD__CD( datatype1 = data.image[ID1].md[0].datatype; //datatype2 = data.image[ID2].md[0].datatype; naxis = data.image[ID1].md[0].naxis; - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc() error"); exit(0); } - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[ID1].md[0].size[i]; } - create_image_ID(ID_out, naxis, naxes, datatype1, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); + create_image_ID(ID_out, naxis, naxes, datatype1, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); free(naxes); nelement = data.image[ID1].md[0].nelement; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.CD[ii] = pt2function(data.image[ID1].array.CD[ii], - data.image[ID2].array.CD[ii]); + data.image[IDout].array.CD[ii] = pt2function(data.image[ID1].array.CD[ii], data.image[ID2].array.CD[ii]); } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif return RETURN_SUCCESS; } - - - - /* ------------------------------------------------------------------------- */ /* image, double -> image */ /* ------------------------------------------------------------------------- */ - -int arith_image_function_1f_1(const char *ID_name, double f1, - const char *ID_out, double (*pt2function)(double, double)) +int arith_image_function_1f_1(const char *ID_name, double f1, const char *ID_out, double (*pt2function)(double, double)) { long ID; long IDout; @@ -4497,165 +4196,144 @@ int arith_image_function_1f_1(const char *ID_name, double f1, ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; naxis = data.image[ID].md[0].naxis; - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc() error"); exit(0); } - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[ID].md[0].size[i]; } datatypeout = _DATATYPE_FLOAT; - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { datatypeout = _DATATYPE_DOUBLE; } - create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); + create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); free(naxes); nelement = data.image[ID].md[0].nelement; - - -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { -# endif - +#endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI8[ii]), f1); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI8[ii]), f1); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI16[ii]), f1); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI16[ii]), f1); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI32[ii]), f1); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI32[ii]), f1); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI64[ii]), f1); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI64[ii]), f1); } } - - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI8[ii]), f1); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI8[ii]), f1); } } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI16[ii]), f1); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI16[ii]), f1); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI32[ii]), f1); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI32[ii]), f1); } } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI64[ii]), f1); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI64[ii]), f1); } } - - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.F[ii]), f1); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii]), f1); } } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = (double) pt2function((double)( - data.image[ID].array.D[ii]), f1); + data.image[IDout].array.D[ii] = (double)pt2function((double)(data.image[ID].array.D[ii]), f1); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif - - +#endif return EXIT_SUCCESS; } - - -int arith_image_function_1f_1_inplace_byID(long ID, double f1, - double (*pt2function)(double, double)) +int arith_image_function_1f_1_inplace_byID(long ID, double f1, double (*pt2function)(double, double)) { long ii; long nelement; @@ -4664,138 +4342,121 @@ int arith_image_function_1f_1_inplace_byID(long ID, double f1, datatype = data.image[ID].md[0].datatype; nelement = data.image[ID].md[0].nelement; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { -# endif - +#endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI8[ii]), - f1); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI8[ii]), f1); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.UI16[ii]), f1); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI16[ii]), f1); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.UI32[ii]), f1); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI32[ii]), f1); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.UI64[ii]), f1); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.UI64[ii]), f1); } } - - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI8[ii]), - f1); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI8[ii]), f1); } } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.SI16[ii]), f1); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI16[ii]), f1); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.SI32[ii]), f1); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI32[ii]), f1); } } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)( - data.image[ID].array.SI64[ii]), f1); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.SI64[ii]), f1); } } - - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii]), - f1); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii]), f1); } } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.D[ii] = (double) pt2function((double)( - data.image[ID].array.D[ii]), f1); + data.image[ID].array.D[ii] = (double)pt2function((double)(data.image[ID].array.D[ii]), f1); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif return EXIT_SUCCESS; } - - - -int arith_image_function_1f_1_inplace(const char *ID_name, double f1, - double (*pt2function)(double, double)) +int arith_image_function_1f_1_inplace(const char *ID_name, double f1, double (*pt2function)(double, double)) { long ID; ID = image_ID(ID_name); @@ -4803,18 +4464,12 @@ int arith_image_function_1f_1_inplace(const char *ID_name, double f1, return (arith_image_function_1f_1_inplace_byID(ID, f1, pt2function)); } - - - - - /* ------------------------------------------------------------------------- */ /* image, double, double -> image */ /* ------------------------------------------------------------------------- */ - -int arith_image_function_1ff_1(const char *ID_name, double f1, double f2, - const char *ID_out, double (*pt2function)(double, double, double)) +int arith_image_function_1ff_1(const char *ID_name, double f1, double f2, const char *ID_out, + double (*pt2function)(double, double, double)) { long ID; long IDout; @@ -4829,160 +4484,143 @@ int arith_image_function_1ff_1(const char *ID_name, double f1, double f2, ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; naxis = data.image[ID].md[0].naxis; - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc() error"); exit(0); } - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[ID].md[0].size[i]; } datatypeout = _DATATYPE_FLOAT; - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { datatypeout = _DATATYPE_DOUBLE; } - create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &IDout); + create_image_ID(ID_out, naxis, naxes, datatypeout, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &IDout); free(naxes); nelement = data.image[ID].md[0].nelement; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { -# endif +#endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI8[ii]), f1, f2); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI8[ii]), f1, f2); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI16[ii]), f1, f2); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI16[ii]), f1, f2); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI32[ii]), f1, f2); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI32[ii]), f1, f2); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.UI64[ii]), f1, f2); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.UI64[ii]), f1, f2); } } - - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI8[ii]), f1, f2); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI8[ii]), f1, f2); } } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI16[ii]), f1, f2); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI16[ii]), f1, f2); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI32[ii]), f1, f2); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI32[ii]), f1, f2); } } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.SI64[ii]), f1, f2); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.SI64[ii]), f1, f2); } } - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.F[ii] = pt2function((double)( - data.image[ID].array.F[ii]), f1, f2); + data.image[IDout].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii]), f1, f2); } } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[IDout].array.D[ii] = pt2function((double)( - data.image[ID].array.D[ii]), f1, f2); + data.image[IDout].array.D[ii] = pt2function((double)(data.image[ID].array.D[ii]), f1, f2); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif - return(0); + return (0); } - - - - - -int arith_image_function_1ff_1_inplace(const char *ID_name, double f1, - double f2, double (*pt2function)(double, double, double)) +int arith_image_function_1ff_1_inplace(const char *ID_name, double f1, double f2, + double (*pt2function)(double, double, double)) { long ID; long ii; @@ -4993,141 +4631,122 @@ int arith_image_function_1ff_1_inplace(const char *ID_name, double f1, datatype = data.image[ID].md[0].datatype; nelement = data.image[ID].md[0].nelement; - -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { -# endif - +#endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.UI8[ii] = (uint8_t) pt2function((double)( - data.image[ID].array.UI8[ii]), f1, f2); + data.image[ID].array.UI8[ii] = (uint8_t)pt2function((double)(data.image[ID].array.UI8[ii]), f1, f2); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.UI16[ii] = (uint16_t) pt2function((double)( - data.image[ID].array.UI16[ii]), f1, f2); + data.image[ID].array.UI16[ii] = (uint16_t)pt2function((double)(data.image[ID].array.UI16[ii]), f1, f2); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.UI32[ii] = (uint32_t) pt2function((double)( - data.image[ID].array.UI32[ii]), f1, f2); + data.image[ID].array.UI32[ii] = (uint32_t)pt2function((double)(data.image[ID].array.UI32[ii]), f1, f2); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.UI64[ii] = (uint64_t) pt2function((double)( - data.image[ID].array.UI64[ii]), f1, f2); + data.image[ID].array.UI64[ii] = (uint64_t)pt2function((double)(data.image[ID].array.UI64[ii]), f1, f2); } } - - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.SI8[ii] = (int8_t) pt2function((double)( - data.image[ID].array.SI8[ii]), f1, f2); + data.image[ID].array.SI8[ii] = (int8_t)pt2function((double)(data.image[ID].array.SI8[ii]), f1, f2); } } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.SI16[ii] = (int16_t) pt2function((double)( - data.image[ID].array.SI16[ii]), f1, f2); + data.image[ID].array.SI16[ii] = (int16_t)pt2function((double)(data.image[ID].array.SI16[ii]), f1, f2); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.SI32[ii] = (int32_t) pt2function((double)( - data.image[ID].array.SI32[ii]), f1, f2); + data.image[ID].array.SI32[ii] = (int32_t)pt2function((double)(data.image[ID].array.SI32[ii]), f1, f2); } } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.SI64[ii] = (int64_t) pt2function((double)( - data.image[ID].array.SI64[ii]), f1, f2); + data.image[ID].array.SI64[ii] = (int64_t)pt2function((double)(data.image[ID].array.SI64[ii]), f1, f2); } } - - - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii]), - f1, f2); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii]), f1, f2); } } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.D[ii] = pt2function((double)(data.image[ID].array.D[ii]), - f1, f2); + data.image[ID].array.D[ii] = pt2function((double)(data.image[ID].array.D[ii]), f1, f2); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif - return(0); + return (0); } - - - - int arith_image_function_1ff_1_inplace_byID(long ID, double f1, double f2, - double (*pt2function)(double, double, double)) + double (*pt2function)(double, double, double)) { long ii; long nelement; @@ -5136,137 +4755,117 @@ int arith_image_function_1ff_1_inplace_byID(long ID, double f1, double f2, datatype = data.image[ID].md[0].datatype; nelement = data.image[ID].md[0].nelement; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { -# endif - +#endif - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.UI8[ii] = (uint8_t) pt2function((double)( - data.image[ID].array.UI8[ii]), f1, f2); + data.image[ID].array.UI8[ii] = (uint8_t)pt2function((double)(data.image[ID].array.UI8[ii]), f1, f2); } } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.UI16[ii] = (uint16_t) pt2function((double)( - data.image[ID].array.UI16[ii]), f1, f2); + data.image[ID].array.UI16[ii] = (uint16_t)pt2function((double)(data.image[ID].array.UI16[ii]), f1, f2); } } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.UI32[ii] = (uint32_t) pt2function((double)( - data.image[ID].array.UI32[ii]), f1, f2); + data.image[ID].array.UI32[ii] = (uint32_t)pt2function((double)(data.image[ID].array.UI32[ii]), f1, f2); } } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.UI64[ii] = (uint64_t) pt2function((double)( - data.image[ID].array.UI64[ii]), f1, f2); + data.image[ID].array.UI64[ii] = (uint64_t)pt2function((double)(data.image[ID].array.UI64[ii]), f1, f2); } } - - - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.SI8[ii] = (int8_t) pt2function((double)( - data.image[ID].array.SI8[ii]), f1, f2); + data.image[ID].array.SI8[ii] = (int8_t)pt2function((double)(data.image[ID].array.SI8[ii]), f1, f2); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.SI16[ii] = (int16_t) pt2function((double)( - data.image[ID].array.SI16[ii]), f1, f2); + data.image[ID].array.SI16[ii] = (int16_t)pt2function((double)(data.image[ID].array.SI16[ii]), f1, f2); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.SI32[ii] = (int32_t) pt2function((double)( - data.image[ID].array.SI32[ii]), f1, f2); + data.image[ID].array.SI32[ii] = (int32_t)pt2function((double)(data.image[ID].array.SI32[ii]), f1, f2); } } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.SI64[ii] = (int64_t) pt2function((double)( - data.image[ID].array.SI64[ii]), f1, f2); + data.image[ID].array.SI64[ii] = (int64_t)pt2function((double)(data.image[ID].array.SI64[ii]), f1, f2); } } - - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii]), - f1, f2); + data.image[ID].array.F[ii] = pt2function((double)(data.image[ID].array.F[ii]), f1, f2); } } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { -# ifdef _OPENMP - #pragma omp for -# endif - for(ii = 0; ii < nelement; ii++) +#ifdef _OPENMP +#pragma omp for +#endif + for (ii = 0; ii < nelement; ii++) { - data.image[ID].array.D[ii] = pt2function((double)(data.image[ID].array.D[ii]), - f1, f2); + data.image[ID].array.D[ii] = pt2function((double)(data.image[ID].array.D[ii]), f1, f2); } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif - return(0); + return (0); } - - - - - - diff --git a/src/COREMOD_arith/imfunctions.h b/src/COREMOD_arith/imfunctions.h index f1585641..5ae666da 100644 --- a/src/COREMOD_arith/imfunctions.h +++ b/src/COREMOD_arith/imfunctions.h @@ -4,122 +4,52 @@ * */ +/* Functions for bison / flex */ +errno_t arith_image_function_im_im__d_d(const char *ID_name, const char *ID_out, double (*pt2function)(double)); -/* Functions for bison / flex */ +errno_t arith_image_function_imd_im__dd_d(const char *ID_name, double v0, const char *ID_out, + double (*pt2function)(double, double)); -errno_t arith_image_function_im_im__d_d( - const char *ID_name, - const char *ID_out, - double (*pt2function)(double) -); - - -errno_t arith_image_function_imd_im__dd_d( - const char *ID_name, - double v0, - const char *ID_out, - double (*pt2function)(double, double) -); - - -errno_t arith_image_function_imdd_im__ddd_d( - const char *ID_name, - double v0, - double v1, - const char *ID_out, - double (*pt2function)(double, double, double) -); - - - - - - -errno_t arith_image_function_1_1_byID( - imageID ID, - imageID IDout, - double (*pt2function)(double) -); - - -errno_t arith_image_function_1_1( - const char *ID_name, - const char *ID_out, - double (*pt2function)(double) -); +errno_t arith_image_function_imdd_im__ddd_d(const char *ID_name, double v0, double v1, const char *ID_out, + double (*pt2function)(double, double, double)); +errno_t arith_image_function_1_1_byID(imageID ID, imageID IDout, double (*pt2function)(double)); +errno_t arith_image_function_1_1(const char *ID_name, const char *ID_out, double (*pt2function)(double)); // imagein -> imagein (in place) -errno_t arith_image_function_1_1_inplace_byID( - imageID ID, - double (*pt2function)(double) -); - +errno_t arith_image_function_1_1_inplace_byID(imageID ID, double (*pt2function)(double)); // imagein -> imagein (in place) -errno_t arith_image_function_1_1_inplace( - const char *ID_name, - double (*pt2function)(double) -); - - - -errno_t arith_image_function_2_1( - const char *ID_name1, - const char *ID_name2, - const char *ID_out, - double (*pt2function)(double, double) -); - -errno_t arith_image_function_2_1_inplace_byID( - imageID ID1, - imageID ID2, - double (*pt2function)(double, double) -); - -errno_t arith_image_function_2_1_inplace( - const char *ID_name1, - const char *ID_name2, - double (*pt2function)(double, double) -); - - -errno_t arith_image_function_CF_CF__CF( - const char *ID_name1, - const char *ID_name2, - const char *ID_out, - complex_float(*pt2function)(complex_float, complex_float) -); - - -errno_t arith_image_function_CD_CD__CD( - const char *ID_name1, - const char *ID_name2, - const char *ID_out, - complex_double(*pt2function)(complex_double, complex_double) -); +errno_t arith_image_function_1_1_inplace(const char *ID_name, double (*pt2function)(double)); +errno_t arith_image_function_2_1(const char *ID_name1, const char *ID_name2, const char *ID_out, + double (*pt2function)(double, double)); +errno_t arith_image_function_2_1_inplace_byID(imageID ID1, imageID ID2, double (*pt2function)(double, double)); +errno_t arith_image_function_2_1_inplace(const char *ID_name1, const char *ID_name2, + double (*pt2function)(double, double)); -int arith_image_function_1f_1(const char *ID_name, double f1, - const char *ID_out, double (*pt2function)(double, double)); +errno_t arith_image_function_CF_CF__CF(const char *ID_name1, const char *ID_name2, const char *ID_out, + complex_float (*pt2function)(complex_float, complex_float)); -int arith_image_function_1f_1_inplace_byID(long ID, double f1, - double (*pt2function)(double, double)); +errno_t arith_image_function_CD_CD__CD(const char *ID_name1, const char *ID_name2, const char *ID_out, + complex_double (*pt2function)(complex_double, complex_double)); -int arith_image_function_1f_1_inplace(const char *ID_name, double f1, - double (*pt2function)(double, double)); +int arith_image_function_1f_1(const char *ID_name, double f1, const char *ID_out, + double (*pt2function)(double, double)); +int arith_image_function_1f_1_inplace_byID(long ID, double f1, double (*pt2function)(double, double)); +int arith_image_function_1f_1_inplace(const char *ID_name, double f1, double (*pt2function)(double, double)); -int arith_image_function_1ff_1(const char *ID_name, double f1, double f2, - const char *ID_out, double (*pt2function)(double, double, double)); +int arith_image_function_1ff_1(const char *ID_name, double f1, double f2, const char *ID_out, + double (*pt2function)(double, double, double)); -int arith_image_function_1ff_1_inplace(const char *ID_name, double f1, - double f2, double (*pt2function)(double, double, double)); +int arith_image_function_1ff_1_inplace(const char *ID_name, double f1, double f2, + double (*pt2function)(double, double, double)); int arith_image_function_1ff_1_inplace_byID(long ID, double f1, double f2, - double (*pt2function)(double, double, double)); + double (*pt2function)(double, double, double)); diff --git a/src/COREMOD_arith/mathfuncs.c b/src/COREMOD_arith/mathfuncs.c index cb93bd89..3bd8a331 100644 --- a/src/COREMOD_arith/mathfuncs.c +++ b/src/COREMOD_arith/mathfuncs.c @@ -5,231 +5,131 @@ * */ - +#include "CommandLineInterface/CLIcore.h" // complex types #include -#include "CommandLineInterface/CLIcore.h" // complex types -double Pacos(double a) -{ - return((double) acos(a)); -} -double Pasin(double a) -{ - return((double) asin(a)); -} -double Patan(double a) -{ - return((double) atan(a)); -} -double Pceil(double a) -{ - return((double) ceil(a)); -} -double Pcos(double a) -{ - return((double) cos(a)); -} -double Pcosh(double a) -{ - return((double) cosh(a)); -} -double Pexp(double a) -{ - return((double) exp(a)); -} -double Pfabs(double a) -{ - return((double) fabs(a)); -} -double Pfloor(double a) -{ - return((double) floor(a)); -} -double Pln(double a) -{ - return((double) log(a)); -} -double Plog(double a) -{ - return((double) log10(a)); -} -double Psqrt(double a) -{ - return((double) sqrt(a)); -} -double Psin(double a) -{ - return((double) sin(a)); -} -double Psinh(double a) -{ - return((double) sinh(a)); -} -double Ptan(double a) -{ - return((double) tan(a)); -} -double Ptanh(double a) -{ - return((double) tanh(a)); -} +double Pacos(double a) { return ((double)acos(a)); } +double Pasin(double a) { return ((double)asin(a)); } +double Patan(double a) { return ((double)atan(a)); } +double Pceil(double a) { return ((double)ceil(a)); } +double Pcos(double a) { return ((double)cos(a)); } +double Pcosh(double a) { return ((double)cosh(a)); } +double Pexp(double a) { return ((double)exp(a)); } +double Pfabs(double a) { return ((double)fabs(a)); } +double Pfloor(double a) { return ((double)floor(a)); } +double Pln(double a) { return ((double)log(a)); } +double Plog(double a) { return ((double)log10(a)); } +double Psqrt(double a) { return ((double)sqrt(a)); } +double Psin(double a) { return ((double)sin(a)); } +double Psinh(double a) { return ((double)sinh(a)); } +double Ptan(double a) { return ((double)tan(a)); } +double Ptanh(double a) { return ((double)tanh(a)); } double Ppositive(double a) { double value = 0.0; - if(a > 0.0) + if (a > 0.0) { - value = (double) 1.0; + value = (double)1.0; } - return(value); -} - - - - - - - - - - -double Pfmod(double a, double b) -{ - return((double) fmod(a, b)); + return (value); } +double Pfmod(double a, double b) { return ((double)fmod(a, b)); } double Ppow(double a, double b) { - if(b > 0) + if (b > 0) { - return((double) pow(a, b)); + return ((double)pow(a, b)); } else { - return((double) pow(a, -b)); + return ((double)pow(a, -b)); } } +double Padd(double a, double b) { return ((double)a + b); } -double Padd(double a, double b) -{ - return((double) a + b); -} - - -double Psubm(double a, double b) -{ - return((double) b - a); -} - - -double Psub(double a, double b) -{ - return((double) a - b); -} - - -double Pmult(double a, double b) -{ - return((double) a * b); -} +double Psubm(double a, double b) { return ((double)b - a); } +double Psub(double a, double b) { return ((double)a - b); } -double Pdiv(double a, double b) -{ - return((double) a / b); -} - +double Pmult(double a, double b) { return ((double)a * b); } -double Pdiv1(double a, double b) -{ - return((double) b / a); -} +double Pdiv(double a, double b) { return ((double)a / b); } +double Pdiv1(double a, double b) { return ((double)b / a); } double Pminv(double a, double b) { - if(a < b) + if (a < b) { - return(a); + return (a); } else { - return(b); + return (b); } } - double Pmaxv(double a, double b) { - if(a > b) + if (a > b) { - return(a); + return (a); } else { - return(b); + return (b); } } - double Ptestlt(double a, double b) { - if(a < b) + if (a < b) { - return((double) 1.0); + return ((double)1.0); } else { - return((double) 0.0); + return ((double)0.0); } } - double Ptestmt(double a, double b) { - if(a < b) + if (a < b) { - return((double) 0.0); + return ((double)0.0); } else { - return((double) 1.0); + return ((double)1.0); } } - - - - - - double Ptrunc(double a, double b, double c) { double value; value = a; - if(a < b) + if (a < b) { value = b; }; - if(a > c) + if (a > c) { value = c; }; - return(value); + return (value); } - - - - complex_double CPadd_CD_CD(complex_double a, complex_double b) { complex_double v; v.re = a.re + b.re; v.im = a.im + b.im; - return(v); + return (v); } complex_double CPsub_CD_CD(complex_double a, complex_double b) @@ -237,7 +137,7 @@ complex_double CPsub_CD_CD(complex_double a, complex_double b) complex_double v; v.re = a.re - b.re; v.im = a.im - b.im; - return(v); + return (v); } complex_double CPmult_CD_CD(complex_double a, complex_double b) @@ -245,10 +145,9 @@ complex_double CPmult_CD_CD(complex_double a, complex_double b) complex_double v; v.re = a.re * b.re - a.im * b.im; v.im = a.re * b.im + a.im * b.re; - return(v); + return (v); } - complex_double CPdiv_CD_CD(complex_double a, complex_double b) { complex_double v; @@ -268,7 +167,7 @@ complex_double CPdiv_CD_CD(complex_double a, complex_double b) v.re = (double)(amp * cos(pha)); v.im = (double)(amp * sin(pha)); - return(v); + return (v); } complex_float CPadd_CF_CF(complex_float a, complex_float b) @@ -276,7 +175,7 @@ complex_float CPadd_CF_CF(complex_float a, complex_float b) complex_float v; v.re = a.re + b.re; v.im = a.im + b.im; - return(v); + return (v); } complex_float CPsub_CF_CF(complex_float a, complex_float b) @@ -284,7 +183,7 @@ complex_float CPsub_CF_CF(complex_float a, complex_float b) complex_float v; v.re = a.re - b.re; v.im = a.im - b.im; - return(v); + return (v); } complex_float CPmult_CF_CF(complex_float a, complex_float b) @@ -292,7 +191,7 @@ complex_float CPmult_CF_CF(complex_float a, complex_float b) complex_float v; v.re = a.re * b.re - a.im * b.im; v.im = a.re * b.im + a.im * b.re; - return(v); + return (v); } complex_float CPdiv_CF_CF(complex_float a, complex_float b) @@ -314,8 +213,5 @@ complex_float CPdiv_CF_CF(complex_float a, complex_float b) v.re = (float)(amp * cos(pha)); v.im = (float)(amp * sin(pha)); - return(v); + return (v); } - - - diff --git a/src/COREMOD_arith/mathfuncs.h b/src/COREMOD_arith/mathfuncs.h index e3503fed..c025168c 100644 --- a/src/COREMOD_arith/mathfuncs.h +++ b/src/COREMOD_arith/mathfuncs.h @@ -1,11 +1,8 @@ /** * @file mathfuncs.h - * + * */ - - - double Pacos(double a); double Pasin(double a); @@ -40,10 +37,6 @@ double Ptanh(double a); double Ppositive(double a); - - - - double Pfmod(double a, double b); double Ppow(double a, double b); @@ -68,14 +61,8 @@ double Ptestlt(double a, double b); double Ptestmt(double a, double b); - - - double Ptrunc(double a, double b, double c); - - - complex_double CPadd_CD_CD(complex_double a, complex_double b); complex_double CPsub_CD_CD(complex_double a, complex_double b); @@ -91,5 +78,3 @@ complex_float CPsub_CF_CF(complex_float a, complex_float b); complex_float CPmult_CF_CF(complex_float a, complex_float b); complex_float CPdiv_CF_CF(complex_float a, complex_float b); - - diff --git a/src/COREMOD_arith/set_pixel.c b/src/COREMOD_arith/set_pixel.c index e5f04037..b2d373e7 100644 --- a/src/COREMOD_arith/set_pixel.c +++ b/src/COREMOD_arith/set_pixel.c @@ -5,78 +5,35 @@ * */ - -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" - - - +#include "CommandLineInterface/CLIcore.h" // ========================================== // Forward declaration(s) // ========================================== -imageID arith_set_pixel( - const char *ID_name, - double value, - long x, - long y -); - - - -imageID arith_set_pixel_1Drange( - const char *ID_name, - double value, - long x, - long y -); - +imageID arith_set_pixel(const char *ID_name, double value, long x, long y); +imageID arith_set_pixel_1Drange(const char *ID_name, double value, long x, long y); -imageID arith_set_row( - const char *ID_name, - double value, - long y -); - - - -imageID arith_set_col( - const char *ID_name, - double value, - long x -); - - -imageID arith_image_zero( - const char *ID_name -); - +imageID arith_set_row(const char *ID_name, double value, long y); +imageID arith_set_col(const char *ID_name, double value, long x); +imageID arith_image_zero(const char *ID_name); // ========================================== // Command line interface wrapper function(s) // ========================================== - - - static errno_t arith_set_pixel_cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_FLOAT) - + CLI_checkarg(3, CLIARG_LONG) - + CLI_checkarg(4, CLIARG_LONG) - == 0) - { - arith_set_pixel( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numf, - data.cmdargtoken[3].val.numl, - data.cmdargtoken[4].val.numl); + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_FLOAT) + CLI_checkarg(3, CLIARG_LONG) + + CLI_checkarg(4, CLIARG_LONG) == + 0) + { + arith_set_pixel(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numf, data.cmdargtoken[3].val.numl, + data.cmdargtoken[4].val.numl); return CLICMD_SUCCESS; } @@ -86,21 +43,14 @@ static errno_t arith_set_pixel_cli() } } - static errno_t arith_set_pixel_1Drange_cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_FLOAT) - + CLI_checkarg(3, CLIARG_LONG) - + CLI_checkarg(4, CLIARG_LONG) - == 0) - { - arith_set_pixel_1Drange( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numf, - data.cmdargtoken[3].val.numl, - data.cmdargtoken[4].val.numl); + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_FLOAT) + CLI_checkarg(3, CLIARG_LONG) + + CLI_checkarg(4, CLIARG_LONG) == + 0) + { + arith_set_pixel_1Drange(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numf, + data.cmdargtoken[3].val.numl, data.cmdargtoken[4].val.numl); return CLICMD_SUCCESS; } @@ -110,19 +60,11 @@ static errno_t arith_set_pixel_1Drange_cli() } } - static errno_t arith_set_row_cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_FLOAT) - + CLI_checkarg(3, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_FLOAT) + CLI_checkarg(3, CLIARG_LONG) == 0) { - arith_set_row( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numf, - data.cmdargtoken[3].val.numl); + arith_set_row(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numf, data.cmdargtoken[3].val.numl); return CLICMD_SUCCESS; } @@ -132,19 +74,11 @@ static errno_t arith_set_row_cli() } } - static errno_t arith_set_col_cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_FLOAT) - + CLI_checkarg(3, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_FLOAT) + CLI_checkarg(3, CLIARG_LONG) == 0) { - arith_set_col( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numf, - data.cmdargtoken[3].val.numl); + arith_set_col(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numf, data.cmdargtoken[3].val.numl); return CLICMD_SUCCESS; } @@ -154,12 +88,9 @@ static errno_t arith_set_col_cli() } } - static errno_t arith_image_zero_cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) == 0) { arith_image_zero(data.cmdargtoken[1].val.string); @@ -171,9 +102,6 @@ static errno_t arith_image_zero_cli() } } - - - // ========================================== // Register CLI command(s) // ========================================== @@ -181,98 +109,31 @@ static errno_t arith_image_zero_cli() errno_t set_pixel_addCLIcmd() { - RegisterCLIcommand( - "setpix", - __FILE__, - arith_set_pixel_cli, - "set pixel value", - " ", - "setpix im 1.24 100 100", - "int arith_set_pixel(const char *ID_name, double value, long x, long y)"); - - - RegisterCLIcommand( - "setpix1Drange", - __FILE__, - arith_set_pixel_1Drange_cli, - "set pixel value for 1D area", - " ", - "setpix im 1.24 10 200", - "int arith_set_pixel_1Drange(const char *ID_name, double value, long x, long y)"); - - - RegisterCLIcommand( - "setrow", - __FILE__, - arith_set_row_cli, - "set pixel row value", - " ", - "setrow im 1.24 100", - "int arith_set_row(const char *ID_name, double value, long y)"); - - - RegisterCLIcommand( - "setcol", - __FILE__, - arith_set_col_cli, - "set pixel column value", - " ", - "setcol im 1.24 100", - "int arith_set_col(const char *ID_name, double value, long x)"); - - - RegisterCLIcommand( - "imzero", - __FILE__, - arith_image_zero_cli, - "set pixels to zero", - "", - "imzero im", - "int arith_image_zero(const char *ID_name)"); - - - return RETURN_SUCCESS; -} - - - - - - - - - - - - - - - - - - - - - - - - + RegisterCLIcommand("setpix", __FILE__, arith_set_pixel_cli, "set pixel value", " ", + "setpix im 1.24 100 100", + "int arith_set_pixel(const char *ID_name, double value, long x, long y)"); + RegisterCLIcommand("setpix1Drange", __FILE__, arith_set_pixel_1Drange_cli, "set pixel value for 1D area", + " ", "setpix im 1.24 10 200", + "int arith_set_pixel_1Drange(const char *ID_name, double value, long x, long y)"); + RegisterCLIcommand("setrow", __FILE__, arith_set_row_cli, "set pixel row value", " ", + "setrow im 1.24 100", "int arith_set_row(const char *ID_name, double value, long y)"); + RegisterCLIcommand("setcol", __FILE__, arith_set_col_cli, "set pixel column value", " ", + "setcol im 1.24 100", "int arith_set_col(const char *ID_name, double value, long x)"); + RegisterCLIcommand("imzero", __FILE__, arith_image_zero_cli, "set pixels to zero", "", "imzero im", + "int arith_image_zero(const char *ID_name)"); + return RETURN_SUCCESS; +} -imageID arith_set_pixel( - const char *ID_name, - double value, - long x, - long y -) +imageID arith_set_pixel(const char *ID_name, double value, long x, long y) { - imageID ID; + imageID ID; uint32_t naxes[2]; - uint8_t datatype; + uint8_t datatype; ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; @@ -282,46 +143,46 @@ imageID arith_set_pixel( // printf("Setting pixel %ld %ld of image %s [%ld] to %f\n", x, y, ID_name, ID, (float) value); data.image[ID].md[0].write = 1; - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { - data.image[ID].array.F[y * naxes[0] + x] = (float) value; + data.image[ID].array.F[y * naxes[0] + x] = (float)value; // printf("float -> %f\n", data.image[ID].array.F[y*naxes[0]+x]); } - else if(datatype == _DATATYPE_DOUBLE) + else if (datatype == _DATATYPE_DOUBLE) { data.image[ID].array.D[y * naxes[0] + x] = value; } - else if(datatype == _DATATYPE_UINT8) + else if (datatype == _DATATYPE_UINT8) { - data.image[ID].array.UI8[y * naxes[0] + x] = (uint8_t) value; + data.image[ID].array.UI8[y * naxes[0] + x] = (uint8_t)value; } - else if(datatype == _DATATYPE_UINT16) + else if (datatype == _DATATYPE_UINT16) { - data.image[ID].array.UI16[y * naxes[0] + x] = (uint16_t) value; + data.image[ID].array.UI16[y * naxes[0] + x] = (uint16_t)value; } - else if(datatype == _DATATYPE_UINT32) + else if (datatype == _DATATYPE_UINT32) { - data.image[ID].array.UI32[y * naxes[0] + x] = (uint32_t) value; + data.image[ID].array.UI32[y * naxes[0] + x] = (uint32_t)value; } - else if(datatype == _DATATYPE_UINT64) + else if (datatype == _DATATYPE_UINT64) { - data.image[ID].array.UI64[y * naxes[0] + x] = (uint64_t) value; + data.image[ID].array.UI64[y * naxes[0] + x] = (uint64_t)value; } - else if(datatype == _DATATYPE_INT8) + else if (datatype == _DATATYPE_INT8) { - data.image[ID].array.SI8[y * naxes[0] + x] = (int8_t) value; + data.image[ID].array.SI8[y * naxes[0] + x] = (int8_t)value; } - else if(datatype == _DATATYPE_INT16) + else if (datatype == _DATATYPE_INT16) { - data.image[ID].array.SI16[y * naxes[0] + x] = (int16_t) value; + data.image[ID].array.SI16[y * naxes[0] + x] = (int16_t)value; } - else if(datatype == _DATATYPE_INT32) + else if (datatype == _DATATYPE_INT32) { - data.image[ID].array.SI32[y * naxes[0] + x] = (int32_t) value; + data.image[ID].array.SI32[y * naxes[0] + x] = (int32_t)value; } - else if(datatype == _DATATYPE_INT64) + else if (datatype == _DATATYPE_INT64) { - data.image[ID].array.SI64[y * naxes[0] + x] = (int64_t) value; + data.image[ID].array.SI64[y * naxes[0] + x] = (int64_t)value; } else { @@ -335,21 +196,13 @@ imageID arith_set_pixel( return ID; } - - -imageID arith_set_pixel_1Drange( - const char *ID_name, - double value, - long x, - long y -) +imageID arith_set_pixel_1Drange(const char *ID_name, double value, long x, long y) { imageID ID; uint32_t naxes[2]; uint8_t datatype; long ii, iistart, iiend; - ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; naxes[0] = data.image[ID].md[0].size[0]; @@ -357,20 +210,20 @@ imageID arith_set_pixel_1Drange( iistart = x; iiend = y + 1; - if(iistart < 0) + if (iistart < 0) { iistart = 0; } - if(iistart >= naxes[0]*naxes[1]) + if (iistart >= naxes[0] * naxes[1]) { iistart = naxes[0] * naxes[1]; } - if(iiend < 0) + if (iiend < 0) { iiend = 0; } - if(iiend >= naxes[0]*naxes[1]) + if (iiend >= naxes[0] * naxes[1]) { iiend = naxes[0] * naxes[1]; } @@ -380,16 +233,16 @@ imageID arith_set_pixel_1Drange( fflush(stdout); data.image[ID].md[0].write = 1; - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { - for(ii = iistart; ii < iiend; ii++) + for (ii = iistart; ii < iiend; ii++) { - data.image[ID].array.F[ii] = (float) value; + data.image[ID].array.F[ii] = (float)value; } } - else if(datatype == _DATATYPE_DOUBLE) + else if (datatype == _DATATYPE_DOUBLE) { - for(ii = iistart; ii < iiend; ii++) + for (ii = iistart; ii < iiend; ii++) { data.image[ID].array.D[ii] = value; } @@ -406,19 +259,12 @@ imageID arith_set_pixel_1Drange( return ID; } - - - -imageID arith_set_row( - const char *ID_name, - double value, - long y -) +imageID arith_set_row(const char *ID_name, double value, long y) { - imageID ID; - uint32_t naxes[2]; - long ii; - uint8_t datatype; + imageID ID; + uint32_t naxes[2]; + long ii; + uint8_t datatype; ID = image_ID(ID_name); datatype = data.image[ID].md[0].datatype; @@ -426,16 +272,16 @@ imageID arith_set_row( naxes[1] = data.image[ID].md[0].size[1]; data.image[ID].md[0].write = 1; - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { - for(ii = 0; ii < naxes[0]; ii++) + for (ii = 0; ii < naxes[0]; ii++) { data.image[ID].array.F[y * naxes[0] + ii] = value; } } - else if(datatype == _DATATYPE_DOUBLE) + else if (datatype == _DATATYPE_DOUBLE) { - for(ii = 0; ii < naxes[0]; ii++) + for (ii = 0; ii < naxes[0]; ii++) { data.image[ID].array.D[y * naxes[0] + ii] = value; } @@ -453,37 +299,29 @@ imageID arith_set_row( return ID; } - - - -imageID arith_set_col( - const char *ID_name, - double value, - long x -) +imageID arith_set_col(const char *ID_name, double value, long x) { - imageID ID; + imageID ID; uint32_t naxes[2]; - long y; - uint8_t datatype; + long y; + uint8_t datatype; ID = image_ID(ID_name); naxes[0] = data.image[ID].md[0].size[0]; naxes[1] = data.image[ID].md[0].size[1]; datatype = data.image[ID].md[0].datatype; - data.image[ID].md[0].write = 1; - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { - for(y = 0; y < naxes[1]; y++) + for (y = 0; y < naxes[1]; y++) { data.image[ID].array.F[y * naxes[0] + x] = value; } } - else if(datatype == _DATATYPE_DOUBLE) + else if (datatype == _DATATYPE_DOUBLE) { - for(y = 0; y < naxes[1]; y++) + for (y = 0; y < naxes[1]; y++) { data.image[ID].array.D[y * naxes[0] + x] = value; } @@ -498,80 +336,73 @@ imageID arith_set_col( data.image[ID].md[0].cnt0++; COREMOD_MEMORY_image_set_sempost(ID_name, -1); - return ID; } - - - -imageID arith_image_zero( - const char *ID_name -) +imageID arith_image_zero(const char *ID_name) { imageID ID; long nelem; ID = image_ID(ID_name); - if(ID != -1) + if (ID != -1) { nelem = data.image[ID].md[0].nelement; data.image[ID].md[0].write = 0; - if(data.image[ID].md[0].datatype == _DATATYPE_FLOAT) + if (data.image[ID].md[0].datatype == _DATATYPE_FLOAT) { memset(data.image[ID].array.F, 0, SIZEOF_DATATYPE_FLOAT * nelem); } - else if(data.image[ID].md[0].datatype == _DATATYPE_DOUBLE) + else if (data.image[ID].md[0].datatype == _DATATYPE_DOUBLE) { memset(data.image[ID].array.D, 0, SIZEOF_DATATYPE_DOUBLE * nelem); } - else if(data.image[ID].md[0].datatype == _DATATYPE_INT8) + else if (data.image[ID].md[0].datatype == _DATATYPE_INT8) { memset(data.image[ID].array.SI8, 0, SIZEOF_DATATYPE_INT8 * nelem); } - else if(data.image[ID].md[0].datatype == _DATATYPE_INT16) + else if (data.image[ID].md[0].datatype == _DATATYPE_INT16) { memset(data.image[ID].array.SI16, 0, SIZEOF_DATATYPE_INT16 * nelem); } - else if(data.image[ID].md[0].datatype == _DATATYPE_INT32) + else if (data.image[ID].md[0].datatype == _DATATYPE_INT32) { memset(data.image[ID].array.SI32, 0, SIZEOF_DATATYPE_INT32 * nelem); } - else if(data.image[ID].md[0].datatype == _DATATYPE_INT64) + else if (data.image[ID].md[0].datatype == _DATATYPE_INT64) { memset(data.image[ID].array.SI64, 0, SIZEOF_DATATYPE_INT64 * nelem); } - else if(data.image[ID].md[0].datatype == _DATATYPE_UINT8) + else if (data.image[ID].md[0].datatype == _DATATYPE_UINT8) { memset(data.image[ID].array.UI8, 0, SIZEOF_DATATYPE_UINT8 * nelem); } - else if(data.image[ID].md[0].datatype == _DATATYPE_UINT16) + else if (data.image[ID].md[0].datatype == _DATATYPE_UINT16) { memset(data.image[ID].array.UI16, 0, SIZEOF_DATATYPE_UINT16 * nelem); } - else if(data.image[ID].md[0].datatype == _DATATYPE_UINT32) + else if (data.image[ID].md[0].datatype == _DATATYPE_UINT32) { memset(data.image[ID].array.UI32, 0, SIZEOF_DATATYPE_UINT32 * nelem); } - else if(data.image[ID].md[0].datatype == _DATATYPE_UINT64) + else if (data.image[ID].md[0].datatype == _DATATYPE_UINT64) { memset(data.image[ID].array.UI64, 0, SIZEOF_DATATYPE_UINT64 * nelem); } - else if(data.image[ID].md[0].datatype == _DATATYPE_COMPLEX_FLOAT) + else if (data.image[ID].md[0].datatype == _DATATYPE_COMPLEX_FLOAT) { memset(data.image[ID].array.CF, 0, SIZEOF_DATATYPE_COMPLEX_FLOAT * nelem); } - else if(data.image[ID].md[0].datatype == _DATATYPE_COMPLEX_DOUBLE) + else if (data.image[ID].md[0].datatype == _DATATYPE_COMPLEX_DOUBLE) { memset(data.image[ID].array.CD, 0, SIZEOF_DATATYPE_COMPLEX_DOUBLE * nelem); } else { - PRINT_ERROR("cannot detect image type for image %s", - ID_name); + PRINT_ERROR("cannot detect image type for image %s", ID_name); exit(0); } data.image[ID].md[0].write = 0; @@ -579,6 +410,5 @@ imageID arith_image_zero( COREMOD_MEMORY_image_set_sempost(ID_name, -1); } - return(ID); + return (ID); } - diff --git a/src/COREMOD_arith/set_pixel.h b/src/COREMOD_arith/set_pixel.h index 8b3a55fd..c8e766db 100644 --- a/src/COREMOD_arith/set_pixel.h +++ b/src/COREMOD_arith/set_pixel.h @@ -3,45 +3,14 @@ * */ - - errno_t set_pixel_addCLIcmd(); +imageID arith_set_pixel(const char *ID_name, double value, long x, long y); -imageID arith_set_pixel( - const char *ID_name, - double value, - long x, - long y -); - - - -imageID arith_set_pixel_1Drange( - const char *ID_name, - double value, - long x, - long y -); - - - -imageID arith_set_row( - const char *ID_name, - double value, - long y -); - - - -imageID arith_set_col( - const char *ID_name, - double value, - long x -); +imageID arith_set_pixel_1Drange(const char *ID_name, double value, long x, long y); +imageID arith_set_row(const char *ID_name, double value, long y); +imageID arith_set_col(const char *ID_name, double value, long x); -imageID arith_image_zero( - const char *ID_name -); +imageID arith_image_zero(const char *ID_name); diff --git a/src/COREMOD_iofits/COREMOD_iofits.c b/src/COREMOD_iofits/COREMOD_iofits.c index 4709b6da..4ae48f66 100644 --- a/src/COREMOD_iofits/COREMOD_iofits.c +++ b/src/COREMOD_iofits/COREMOD_iofits.c @@ -6,10 +6,10 @@ */ #define MODULE_SHORTNAME_DEFAULT "" -#define MODULE_DESCRIPTION "Read/Write FITS files" +#define MODULE_DESCRIPTION "Read/Write FITS files" -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_iofits_common.h" +#include "CommandLineInterface/CLIcore.h" #include "breakcube.h" #include "images2cube.h" @@ -19,20 +19,17 @@ COREMOD_IOFITS_DATA COREMOD_iofits_data; - INIT_MODULE_LIB(COREMOD_iofits) - static errno_t init_module_CLI() { - COREMOD_iofits_data.FITSIO_status = 0; - - CLIADDCMD_COREMOD_iofits__loadfits(); - CLIADDCMD_COREMOD_iofits__saveFITS(); + COREMOD_iofits_data.FITSIO_status = 0; - breakcube_addCLIcmd(); - images2cube_addCLIcmd(); + CLIADDCMD_COREMOD_iofits__loadfits(); + CLIADDCMD_COREMOD_iofits__saveFITS(); + breakcube_addCLIcmd(); + images2cube_addCLIcmd(); // add atexit functions here diff --git a/src/COREMOD_iofits/COREMOD_iofits.h b/src/COREMOD_iofits/COREMOD_iofits.h index 2d7f30cb..749f0eb7 100644 --- a/src/COREMOD_iofits/COREMOD_iofits.h +++ b/src/COREMOD_iofits/COREMOD_iofits.h @@ -3,9 +3,9 @@ #include "COREMOD_iofits/COREMOD_iofits_common.h" +#include "COREMOD_iofits/breakcube.h" #include "COREMOD_iofits/check_fitsio_status.h" #include "COREMOD_iofits/data_type_code.h" -#include "COREMOD_iofits/breakcube.h" #include "COREMOD_iofits/file_exists.h" #include "COREMOD_iofits/images2cube.h" #include "COREMOD_iofits/is_fits_file.h" diff --git a/src/COREMOD_iofits/COREMOD_iofits_common.h b/src/COREMOD_iofits/COREMOD_iofits_common.h index b65d968c..e8d6374c 100644 --- a/src/COREMOD_iofits/COREMOD_iofits_common.h +++ b/src/COREMOD_iofits/COREMOD_iofits_common.h @@ -1,7 +1,6 @@ #ifndef _IOFITS_COMMON_H #define _IOFITS_COMMON_H - #include typedef struct @@ -9,12 +8,11 @@ typedef struct int FITSIO_status; } COREMOD_IOFITS_DATA; +#define STRINGMAXLEN_FITSKEYWORDNAME 8 +#define STRINGMAXLEN_FITSKEYWORDVALUE 68 +#define STRINGMAXLEN_FITSKEYWCOMMENT FLEN_COMMENT -#define STRINGMAXLEN_FITSKEYWORDNAME 8 -#define STRINGMAXLEN_FITSKEYWORDVALUE 68 -#define STRINGMAXLEN_FITSKEYWCOMMENT FLEN_COMMENT - -#define STRINGMAXLEN_FITSIOCHECK_ERRSTRING 100 +#define STRINGMAXLEN_FITSIOCHECK_ERRSTRING 100 /** * @ingroup errcheckmacro @@ -32,37 +30,38 @@ typedef struct * * */ -#define WRITE_FITSKEYWNAME(keywname, ...) do { \ -int slen = snprintf(keywname, STRINGMAXLEN_FITSKEYWORDNAME, __VA_ARGS__); \ -if(slen<1) { \ - PRINT_ERROR("snprintf wrote <1 char"); \ - abort(); \ -} \ -if(slen >= STRINGMAXLEN_FITSKEYWORDNAME) { \ - PRINT_ERROR("snprintf string truncation"); \ - abort(); \ -} \ -} while(0) - - - -#define FITSIO_CHECK_ERROR(status, errmode, ...) do { \ -if ((status != 0) && (errmode !=0)) { \ - char errstr[STRINGMAXLEN_FITSIOCHECK_ERRSTRING]; \ - fits_get_errstatus(status, errstr); \ - fprintf(stderr, \ - "%c[%d;%dmFITSIO error %d [%s, %s, %d]: %s%c[%d;m\n\a", \ - (char) 27, 1, 31, status, __FILE__, __func__, __LINE__, errstr, (char) 27, 0); \ - PRINT_ERROR(__VA_ARGS__); \ - if(errmode > 2) { \ - abort(); \ - } \ - } \ - status =0; \ -} while(0) - +#define WRITE_FITSKEYWNAME(keywname, ...) \ + do \ + { \ + int slen = snprintf(keywname, STRINGMAXLEN_FITSKEYWORDNAME, __VA_ARGS__); \ + if (slen < 1) \ + { \ + PRINT_ERROR("snprintf wrote <1 char"); \ + abort(); \ + } \ + if (slen >= STRINGMAXLEN_FITSKEYWORDNAME) \ + { \ + PRINT_ERROR("snprintf string truncation"); \ + abort(); \ + } \ + } while (0) +#define FITSIO_CHECK_ERROR(status, errmode, ...) \ + do \ + { \ + if ((status != 0) && (errmode != 0)) \ + { \ + char errstr[STRINGMAXLEN_FITSIOCHECK_ERRSTRING]; \ + fits_get_errstatus(status, errstr); \ + fprintf(stderr, "%c[%d;%dmFITSIO error %d [%s, %s, %d]: %s%c[%d;m\n\a", (char)27, 1, 31, status, __FILE__, \ + __func__, __LINE__, errstr, (char)27, 0); \ + PRINT_ERROR(__VA_ARGS__); \ + if (errmode > 2) \ + { \ + abort(); \ + } \ + } \ + status = 0; \ + } while (0) #endif - - diff --git a/src/COREMOD_iofits/README.md b/src/COREMOD_iofits/README.md index a27a5249..c16c8998 100644 --- a/src/COREMOD_iofits/README.md +++ b/src/COREMOD_iofits/README.md @@ -4,4 +4,3 @@ # Module COREMOD_iofits {#page_module_COREMOD_iofits} I/O routines for FITS format - diff --git a/src/COREMOD_iofits/breakcube.c b/src/COREMOD_iofits/breakcube.c index 6e138756..b262cbb1 100644 --- a/src/COREMOD_iofits/breakcube.c +++ b/src/COREMOD_iofits/breakcube.c @@ -2,30 +2,22 @@ * @file breakcube.c */ -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" - - +#include "CommandLineInterface/CLIcore.h" // ========================================== // Forward declaration(s) // ========================================== -imageID break_cube( - const char *restrict ID_name -); +imageID break_cube(const char *restrict ID_name); // ========================================== // Command line interface wrapper function(s) // ========================================== - - errno_t break_cube_cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) == 0) { break_cube(data.cmdargtoken[1].val.string); @@ -43,8 +35,6 @@ errno_t break_cube_cli() return CLICMD_SUCCESS; } - - // ========================================== // Register CLI command(s) // ========================================== @@ -52,29 +42,13 @@ errno_t break_cube_cli() errno_t breakcube_addCLIcmd() { - RegisterCLIcommand( - "breakcube", - __FILE__, - break_cube_cli, - "break cube into individual images (slices)", - "", - "breakcube imc", - "int break_cube(char *ID_name)" - ); + RegisterCLIcommand("breakcube", __FILE__, break_cube_cli, "break cube into individual images (slices)", + "", "breakcube imc", "int break_cube(char *ID_name)"); return RETURN_SUCCESS; } - - - - - - - -imageID break_cube( - const char *restrict ID_name -) +imageID break_cube(const char *restrict ID_name) { imageID ID; uint32_t naxes[3]; @@ -85,29 +59,27 @@ imageID break_cube( naxes[1] = data.image[ID].md[0].size[1]; naxes[2] = data.image[ID].md[0].size[2]; - for(uint32_t kk = 0; kk < naxes[2]; kk++) + for (uint32_t kk = 0; kk < naxes[2]; kk++) { long ID1; - CREATE_IMAGENAME(framename, "%s_%5u", ID_name, kk); + CREATE_IMAGENAME(framename, "%s_%5u", ID_name, kk); - for(i = 0; i < (long) strlen(framename); i++) + for (i = 0; i < (long)strlen(framename); i++) { - if(framename[i] == ' ') + if (framename[i] == ' ') { framename[i] = '0'; } } create_2Dimage_ID(framename, naxes[0], naxes[1], &ID1); - for(uint32_t ii = 0; ii < naxes[0]; ii++) - for(uint32_t jj = 0; jj < naxes[1]; jj++) + for (uint32_t ii = 0; ii < naxes[0]; ii++) + for (uint32_t jj = 0; jj < naxes[1]; jj++) { - data.image[ID1].array.F[jj * naxes[0] + ii] = data.image[ID].array.F[kk * - naxes[0] * naxes[1] + jj * naxes[0] + ii]; + data.image[ID1].array.F[jj * naxes[0] + ii] = + data.image[ID].array.F[kk * naxes[0] * naxes[1] + jj * naxes[0] + ii]; } } return ID; } - - diff --git a/src/COREMOD_iofits/breakcube.h b/src/COREMOD_iofits/breakcube.h index 8825acac..53e3d58c 100644 --- a/src/COREMOD_iofits/breakcube.h +++ b/src/COREMOD_iofits/breakcube.h @@ -4,7 +4,4 @@ errno_t breakcube_addCLIcmd(); - -imageID break_cube( - const char *restrict ID_name -); +imageID break_cube(const char *restrict ID_name); diff --git a/src/COREMOD_iofits/check_fitsio_status.c b/src/COREMOD_iofits/check_fitsio_status.c index 0af20576..9bb59eb1 100644 --- a/src/COREMOD_iofits/check_fitsio_status.c +++ b/src/COREMOD_iofits/check_fitsio_status.c @@ -2,35 +2,28 @@ * @file ckeck_fitsio_status.c */ - #include "COREMOD_iofits_common.h" extern COREMOD_IOFITS_DATA COREMOD_iofits_data; - // set print to 0 if error message should not be printed to stderr // set print to 1 if error message should be printed to stderr -int check_FITSIO_status( - const char *restrict cfile, - const char *restrict cfunc, - long cline, - int print) +int check_FITSIO_status(const char *restrict cfile, const char *restrict cfunc, long cline, int print) { int Ferr = 0; - if(COREMOD_iofits_data.FITSIO_status != 0) + if (COREMOD_iofits_data.FITSIO_status != 0) { - if(print == 1) + if (print == 1) { char errstr[STRINGMAXLEN_FITSIOCHECK_ERRSTRING]; fits_get_errstatus(COREMOD_iofits_data.FITSIO_status, errstr); - fprintf(stderr, - "%c[%d;%dmFITSIO error %d [%s, %s, %ld]: %s%c[%d;m\n\a", - (char) 27, 1, 31, COREMOD_iofits_data.FITSIO_status, cfile, cfunc, cline, errstr, (char) 27, 0); + fprintf(stderr, "%c[%d;%dmFITSIO error %d [%s, %s, %ld]: %s%c[%d;m\n\a", (char)27, 1, 31, + COREMOD_iofits_data.FITSIO_status, cfile, cfunc, cline, errstr, (char)27, 0); } Ferr = COREMOD_iofits_data.FITSIO_status; } COREMOD_iofits_data.FITSIO_status = 0; - return(Ferr); + return (Ferr); } diff --git a/src/COREMOD_iofits/check_fitsio_status.h b/src/COREMOD_iofits/check_fitsio_status.h index af9194f2..ed26646b 100644 --- a/src/COREMOD_iofits/check_fitsio_status.h +++ b/src/COREMOD_iofits/check_fitsio_status.h @@ -2,9 +2,4 @@ * @file ckeck_fitsio_status.h */ - -int check_FITSIO_status( - const char *restrict cfile, - const char *restrict cfunc, - long cline, - int print); +int check_FITSIO_status(const char *restrict cfile, const char *restrict cfunc, long cline, int print); diff --git a/src/COREMOD_iofits/data_type_code.c b/src/COREMOD_iofits/data_type_code.c index 99500b79..ac607d86 100644 --- a/src/COREMOD_iofits/data_type_code.c +++ b/src/COREMOD_iofits/data_type_code.c @@ -2,12 +2,7 @@ * @file data_type_code.c */ - - - -int data_type_code( - int bitpix -) +int data_type_code(int bitpix) { int code; /* @@ -25,34 +20,33 @@ int data_type_code( double complex, M 163 TDBLCOMPLEX */ code = 0; - if(bitpix == 1) + if (bitpix == 1) { code = 1; } - if(bitpix == 8) + if (bitpix == 8) { code = 11; } - if(bitpix == 16) + if (bitpix == 16) { code = 21; } - if(bitpix == 32) + if (bitpix == 32) { code = 41; } - if(bitpix == 64) + if (bitpix == 64) { code = 81; } - if(bitpix == -32) + if (bitpix == -32) { code = 42; } - if(bitpix == -64) + if (bitpix == -64) { code = 82; } - return(code); + return (code); } - diff --git a/src/COREMOD_iofits/data_type_code.h b/src/COREMOD_iofits/data_type_code.h index 79ae9159..0db14889 100644 --- a/src/COREMOD_iofits/data_type_code.h +++ b/src/COREMOD_iofits/data_type_code.h @@ -2,8 +2,4 @@ * @file data_type_code.h */ - -int data_type_code( - int bitpix -); - +int data_type_code(int bitpix); diff --git a/src/COREMOD_iofits/file_exists.c b/src/COREMOD_iofits/file_exists.c index 755b426f..59506b0d 100644 --- a/src/COREMOD_iofits/file_exists.c +++ b/src/COREMOD_iofits/file_exists.c @@ -4,15 +4,12 @@ #include - -int file_exists( - const char *restrict file_name -) +int file_exists(const char *restrict file_name) { FILE *fp; int exists = 1; - if((fp = fopen(file_name, "r")) == NULL) + if ((fp = fopen(file_name, "r")) == NULL) { exists = 0; /* printf("file %s does not exist\n",file_name);*/ @@ -22,5 +19,5 @@ int file_exists( fclose(fp); } - return(exists); + return (exists); } diff --git a/src/COREMOD_iofits/file_exists.h b/src/COREMOD_iofits/file_exists.h index ad61c9ab..37925820 100644 --- a/src/COREMOD_iofits/file_exists.h +++ b/src/COREMOD_iofits/file_exists.h @@ -2,6 +2,4 @@ * @file file_exists.h */ -int file_exists( - const char *restrict file_name -); +int file_exists(const char *restrict file_name); diff --git a/src/COREMOD_iofits/images2cube.c b/src/COREMOD_iofits/images2cube.c index 2796f446..f472b33a 100644 --- a/src/COREMOD_iofits/images2cube.c +++ b/src/COREMOD_iofits/images2cube.c @@ -2,26 +2,19 @@ * @file images2cube.c */ -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" +#include "CommandLineInterface/CLIcore.h" // ========================================== // Forward declaration(s) // ========================================== -errno_t images_to_cube( - const char *restrict img_name, - long nbframes, - const char *restrict cube_name -); - +errno_t images_to_cube(const char *restrict img_name, long nbframes, const char *restrict cube_name); // ========================================== // Command line interface wrapper function(s) // ========================================== - - errno_t images_to_cube_cli() { /* if(data.cmdargtoken[1].type != 4) @@ -30,21 +23,17 @@ errno_t images_to_cube_cli() return -1; }*/ - if(data.cmdargtoken[2].type != 2) + if (data.cmdargtoken[2].type != 2) { printf("second argument has to be integer\n"); return -1; } - images_to_cube(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl, - data.cmdargtoken[3].val.string); + images_to_cube(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl, data.cmdargtoken[3].val.string); return CLICMD_SUCCESS; } - - - // ========================================== // Register CLI command(s) // ========================================== @@ -52,29 +41,15 @@ errno_t images_to_cube_cli() errno_t images2cube_addCLIcmd() { - RegisterCLIcommand( - "imgs2cube", - __FILE__, - images_to_cube_cli, - "combine individual images into cube, image name is prefix followed by 5 digits", - " ", "imgs2cube im_ 100 imc", - "int images_to_cube(char *img_name, long nbframes, char *cube_name)" - ); + RegisterCLIcommand("imgs2cube", __FILE__, images_to_cube_cli, + "combine individual images into cube, image name is prefix followed by 5 digits", + " ", "imgs2cube im_ 100 imc", + "int images_to_cube(char *img_name, long nbframes, char *cube_name)"); return RETURN_SUCCESS; } - - - - - - -errno_t images_to_cube( - const char *restrict img_name, - long nbframes, - const char *restrict cube_name -) +errno_t images_to_cube(const char *restrict img_name, long nbframes, const char *restrict cube_name) { DEBUG_TRACE_FSTART(); imageID ID; @@ -88,7 +63,7 @@ errno_t images_to_cube( CREATE_IMAGENAME(imname, "%s%05ld", img_name, frame); ID1 = image_ID(imname); - if(ID1 == -1) + if (ID1 == -1) { PRINT_ERROR("Image \"%s\" does not exist", imname); exit(0); @@ -98,28 +73,26 @@ errno_t images_to_cube( xsize = naxes[0]; ysize = naxes[1]; - printf("SIZE = %ld %ld %ld\n", (long) naxes[0], (long) naxes[1], - (long) nbframes); + printf("SIZE = %ld %ld %ld\n", (long)naxes[0], (long)naxes[1], (long)nbframes); fflush(stdout); - FUNC_CHECK_RETURN( - create_3Dimage_ID(cube_name, naxes[0], naxes[1], nbframes, &ID)); + FUNC_CHECK_RETURN(create_3Dimage_ID(cube_name, naxes[0], naxes[1], nbframes, &ID)); - for(uint32_t ii = 0; ii < naxes[0]; ii++) - for(uint32_t jj = 0; jj < naxes[1]; jj++) + for (uint32_t ii = 0; ii < naxes[0]; ii++) + for (uint32_t jj = 0; jj < naxes[1]; jj++) { - data.image[ID].array.F[frame * naxes[0]*naxes[1] + (jj * naxes[0] + ii)] = + data.image[ID].array.F[frame * naxes[0] * naxes[1] + (jj * naxes[0] + ii)] = data.image[ID1].array.F[jj * naxes[0] + ii]; } - for(frame = 1; frame < nbframes; frame++) + for (frame = 1; frame < nbframes; frame++) { WRITE_IMAGENAME(imname, "%s%05ld", img_name, frame); printf("Adding image %s -> %ld/%ld ... ", img_name, frame, nbframes); fflush(stdout); ID1 = image_ID(imname); - if(ID1 == -1) + if (ID1 == -1) { PRINT_ERROR("Image \"%s\" does not exist - skipping", imname); } @@ -127,15 +100,15 @@ errno_t images_to_cube( { naxes[0] = data.image[ID1].md[0].size[0]; naxes[1] = data.image[ID1].md[0].size[1]; - if((xsize != naxes[0]) || (ysize != naxes[1])) + if ((xsize != naxes[0]) || (ysize != naxes[1])) { PRINT_ERROR("Image has wrong size"); exit(0); } - for(uint32_t ii = 0; ii < naxes[0]; ii++) - for(uint32_t jj = 0; jj < naxes[1]; jj++) + for (uint32_t ii = 0; ii < naxes[0]; ii++) + for (uint32_t jj = 0; jj < naxes[1]; jj++) { - data.image[ID].array.F[frame * naxes[0]*naxes[1] + (jj * naxes[0] + ii)] = + data.image[ID].array.F[frame * naxes[0] * naxes[1] + (jj * naxes[0] + ii)] = data.image[ID1].array.F[jj * naxes[0] + ii]; } } @@ -146,5 +119,3 @@ errno_t images_to_cube( DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - - diff --git a/src/COREMOD_iofits/images2cube.h b/src/COREMOD_iofits/images2cube.h index 702d6433..f83a635a 100644 --- a/src/COREMOD_iofits/images2cube.h +++ b/src/COREMOD_iofits/images2cube.h @@ -2,12 +2,6 @@ * @file images2cube.h */ - errno_t images2cube_addCLIcmd(); - -errno_t images_to_cube( - const char *restrict img_name, - long nbframes, - const char *restrict cube_name -); +errno_t images_to_cube(const char *restrict img_name, long nbframes, const char *restrict cube_name); diff --git a/src/COREMOD_iofits/is_fits_file.c b/src/COREMOD_iofits/is_fits_file.c index 0bf2a6b7..2d4105ca 100644 --- a/src/COREMOD_iofits/is_fits_file.c +++ b/src/COREMOD_iofits/is_fits_file.c @@ -2,30 +2,26 @@ * @file is_fits_file.c */ -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_iofits_common.h" +#include "CommandLineInterface/CLIcore.h" #include "check_fitsio_status.h" extern COREMOD_IOFITS_DATA COREMOD_iofits_data; - -int is_fits_file( - const char *restrict file_name -) +int is_fits_file(const char *restrict file_name) { int value = 0; fitsfile *fptr; - - if(!fits_open_file(&fptr, file_name, READONLY, &COREMOD_iofits_data.FITSIO_status)) + if (!fits_open_file(&fptr, file_name, READONLY, &COREMOD_iofits_data.FITSIO_status)) { fits_close_file(fptr, &COREMOD_iofits_data.FITSIO_status); value = 1; } - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 1) == 1) + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 1) == 1) { PRINT_ERROR("Error in function is_fits_file(%s)", file_name); } - return(value); + return (value); } diff --git a/src/COREMOD_iofits/is_fits_file.h b/src/COREMOD_iofits/is_fits_file.h index 4170f91d..9b4ed235 100644 --- a/src/COREMOD_iofits/is_fits_file.h +++ b/src/COREMOD_iofits/is_fits_file.h @@ -2,7 +2,4 @@ * @file is_fits_file.h */ - -int is_fits_file( - const char *restrict file_name -); +int is_fits_file(const char *restrict file_name); diff --git a/src/COREMOD_iofits/loadfits.c b/src/COREMOD_iofits/loadfits.c index 4992d15d..e49fe397 100644 --- a/src/COREMOD_iofits/loadfits.c +++ b/src/COREMOD_iofits/loadfits.c @@ -3,64 +3,37 @@ * @brief load FITS format files */ - #include #include "CommandLineInterface/CLIcore.h" - -#include "COREMOD_memory/COREMOD_memory.h" #include "COREMOD_iofits_common.h" +#include "COREMOD_memory/COREMOD_memory.h" -#include "data_type_code.h" #include "check_fitsio_status.h" +#include "data_type_code.h" -#include "COREMOD_memory/image_keyword_addL.h" #include "COREMOD_memory/image_keyword_addD.h" +#include "COREMOD_memory/image_keyword_addL.h" #include "COREMOD_memory/image_keyword_addS.h" - extern COREMOD_IOFITS_DATA COREMOD_iofits_data; - - // CLI function arguments and parameters static char *infilename; static char *outimname; static long *FITSIOerrmode; - // CLI function arguments and parameters -static CLICMDARGDEF farg[] = -{ - { - CLIARG_STR, ".infname", "input file", "imfname", - CLIARG_VISIBLE_DEFAULT, - (void **) &infilename, NULL - }, - { - CLIARG_STR_NOT_IMG, ".outimname", "output image name", "outimname", - CLIARG_VISIBLE_DEFAULT, - (void **) &outimname, NULL - }, - { - CLIARG_LONG, ".errmode", "FITSIO errors mode \n(0:ignore) (1:warning) (2:error) (3:exit)", "1", - CLIARG_HIDDEN_DEFAULT, - (void **) &FITSIOerrmode, NULL - } -}; - - +static CLICMDARGDEF farg[] = { + {CLIARG_STR, ".infname", "input file", "imfname", CLIARG_VISIBLE_DEFAULT, (void **)&infilename, NULL}, + {CLIARG_STR_NOT_IMG, ".outimname", "output image name", "outimname", CLIARG_VISIBLE_DEFAULT, (void **)&outimname, + NULL}, + {CLIARG_LONG, ".errmode", "FITSIO errors mode \n(0:ignore) (1:warning) (2:error) (3:exit)", "1", + CLIARG_HIDDEN_DEFAULT, (void **)&FITSIOerrmode, NULL}}; // CLI function initialization data -static CLICMDDATA CLIcmddata = -{ - "loadfits", - "load FITS format file", - CLICMD_FIELDS_DEFAULTS -}; - - +static CLICMDDATA CLIcmddata = {"loadfits", "load FITS format file", CLICMD_FIELDS_DEFAULTS}; // detailed help static errno_t help_function() @@ -70,41 +43,31 @@ static errno_t help_function() "Uses fitsio library, supports extended fitsio file syntax\n" "File name should be in double quotes unless free of special chars\n" "Examples:\n" - " loadfits \"im1.fits\" im\n" - ); + " loadfits \"im1.fits\" im\n"); return RETURN_SUCCESS; } - - - - /// errmode values : /// LOADFITS_ERRMODE_IGNORE (0) print warning, do not show error messages, continue /// LOADFITS_ERRMODE_WARNING (1) print error, continue /// LOADFITS_ERRMODE_ERROR (2) return error /// LOADFITS_ERRMODE_EXIT (3) exit program at error -errno_t load_fits( - const char *restrict file_name, - const char *restrict ID_name, - int errmode, - imageID *IDout -) +errno_t load_fits(const char *restrict file_name, const char *restrict ID_name, int errmode, imageID *IDout) { DEBUG_TRACE_FSTART(); - fitsfile *fptr = NULL; /* pointer to the FITS file; defined in fitsio.h */ - int nulval, anynul; - long bitpixl = 0; + fitsfile *fptr = NULL; /* pointer to the FITS file; defined in fitsio.h */ + int nulval, anynul; + long bitpixl = 0; - uint32_t naxes[3]; + uint32_t naxes[3]; - double bscale; - double bzero; + double bscale; + double bzero; unsigned char *barray = NULL; - long *larray = NULL; + long *larray = NULL; // unsigned short *sarray = NULL; // long NDR = 1; /* non-destructive reads */ @@ -119,8 +82,6 @@ errno_t load_fits( naxes[1] = 0; naxes[2] = 0; - - DEBUG_TRACEPOINT("FARG \"%s\" %s %d", file_name, ID_name, errmode); { @@ -128,33 +89,32 @@ errno_t load_fits( // tyr 3 consecutive times and then give up if not successful int fileOK = 0; int NBtry = 3; - for(int tr = 0; tr < NBtry; tr++) + for (int tr = 0; tr < NBtry; tr++) { - if(fileOK == 0) + if (fileOK == 0) { int status = 0; fits_open_file(&fptr, file_name, READONLY, &status); - if(status != 0) + if (status != 0) { - if(errmode > 0) + if (errmode > 0) { printf("attempt # %d failed\n", tr); } //void fits_get_errstatus(int status, char *err_text) - if(status != 0) + if (status != 0) { - if(errmode > 1) + if (errmode > 1) { - if(tr == NBtry - 1) + if (tr == NBtry - 1) { - FITSIO_CHECK_ERROR(status, errmode, "can't load %s (tried %d times)", file_name, - NBtry); + FITSIO_CHECK_ERROR(status, errmode, "can't load %s (tried %d times)", file_name, NBtry); } } - if(tr != NBtry - 1) // don't wait on last try + if (tr != NBtry - 1) // don't wait on last try { usleep(10000); } @@ -170,36 +130,33 @@ errno_t load_fits( } printf("fileOK = %d\n", fileOK); - if(fileOK == 0) + if (fileOK == 0) { // if image not loaded, set output identifier to -1 - if(IDout != NULL) + if (IDout != NULL) { *IDout = -1; } - if(errmode == 0) + if (errmode == 0) { DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - if(errmode == 1) + if (errmode == 1) { - PRINT_WARNING("Image \"%s\" could not be loaded from file \"%s\"", - ID_name, - file_name); + PRINT_WARNING("Image \"%s\" could not be loaded from file \"%s\"", ID_name, file_name); DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - if(errmode == 2) + if (errmode == 2) { - FUNC_RETURN_FAILURE("Image \"%s\" could not be loaded from file \"%s\"", - ID_name, file_name); + FUNC_RETURN_FAILURE("Image \"%s\" could not be loaded from file \"%s\"", ID_name, file_name); } - if(errmode == 3) + if (errmode == 3) { abort(); } @@ -210,13 +167,11 @@ errno_t load_fits( DEBUG_TRACEPOINT("File %s open", file_name); - - char keyword[STRINGMAXLEN_FITSKEYWORDNAME]; - long fpixel = 1; - char comment[STRINGMAXLEN_FITSKEYWCOMMENT]; - long nelements; - long naxis = 0; - + char keyword[STRINGMAXLEN_FITSKEYWORDNAME]; + long fpixel = 1; + char comment[STRINGMAXLEN_FITSKEYWCOMMENT]; + long nelements; + long naxis = 0; // Keywords int nbFITSkeys = 0; @@ -224,22 +179,18 @@ errno_t load_fits( { int status = 0; fits_get_hdrspace(fptr, &nbFITSkeys, NULL, &status); - FITSIO_CHECK_ERROR(status, errmode, "fits_get_hdrspace error on %s", - file_name); + FITSIO_CHECK_ERROR(status, errmode, "fits_get_hdrspace error on %s", file_name); } - { int status = 0; - fits_read_key(fptr, TLONG, "NAXIS", &naxis, comment, - &status); + fits_read_key(fptr, TLONG, "NAXIS", &naxis, comment, &status); FITSIO_CHECK_ERROR(status, errmode, "File %s has no NAXIS", file_name); } printf("naxis = %ld\n", naxis); DEBUG_TRACEPOINT("naxis = %ld", naxis); - - for(long i = 0; i < naxis; i++) + for (long i = 0; i < naxis; i++) { WRITE_FITSKEYWNAME(keyword, "NAXIS%ld", i + 1); @@ -256,12 +207,11 @@ errno_t load_fits( FITSIO_CHECK_ERROR(status, errmode, "File %s has no BITPIX", file_name); } - - int bitpix = (int) bitpixl; + int bitpix = (int)bitpixl; { int status = 0; fits_read_key(fptr, TDOUBLE, "BSCALE", &bscale, comment, &status); - if(status != 0) + if (status != 0) { bscale = 1.0; } @@ -270,119 +220,93 @@ errno_t load_fits( { int status = 0; fits_read_key(fptr, TDOUBLE, "BZERO", &bzero, comment, &status); - if(status != 0) + if (status != 0) { bzero = 0.0; } } - - { int status = 0; fits_set_bscale(fptr, bscale, bzero, &status); FITSIO_CHECK_ERROR(status, errmode, "bscake set errror"); } - - if(1) + if (1) { - printf("[%ld", (long) naxes[0]); - for(long i = 1; i < naxis; i++) + printf("[%ld", (long)naxes[0]); + for (long i = 1; i < naxis; i++) { - printf(",%ld", (long) naxes[i]); + printf(",%ld", (long)naxes[i]); } printf("] %d %f %f\n", bitpix, bscale, bzero); fflush(stdout); } nelements = 1; - for(long i = 0; i < naxis; i++) + for (long i = 0; i < naxis; i++) { nelements *= naxes[i]; } - /* bitpix = -32 TFLOAT */ - if(bitpix == -32) + if (bitpix == -32) { - create_image_ID( - ID_name, - naxis, - naxes, - _DATATYPE_FLOAT, - data.SHARED_DFT, - data.NBKEYWORD_DFT, - 0, - &ID); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID); { int status = 0; - fits_read_img(fptr, data_type_code(bitpix), fpixel, nelements, &nulval, - data.image[ID].array.F, &anynul, &status); + fits_read_img(fptr, data_type_code(bitpix), fpixel, nelements, &nulval, data.image[ID].array.F, &anynul, + &status); FITSIO_CHECK_ERROR(status, errmode, "fits_read_img bitpix=%d", bitpix); } } /* bitpix = -64 TDOUBLE */ - if(bitpix == -64) + if (bitpix == -64) { - create_image_ID( - ID_name, - naxis, - naxes, - _DATATYPE_DOUBLE, - data.SHARED_DFT, - data.NBKEYWORD_DFT, - 0, - &ID); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_DOUBLE, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID); { int status = 0; - fits_read_img(fptr, data_type_code(bitpix), fpixel, nelements, &nulval, - data.image[ID].array.D, &anynul, &status); + fits_read_img(fptr, data_type_code(bitpix), fpixel, nelements, &nulval, data.image[ID].array.D, &anynul, + &status); FITSIO_CHECK_ERROR(status, errmode, "fits_read_img bitpix=%d", bitpix); } } - /* bitpix = 16 TSHORT */ - if(bitpix == 16) + if (bitpix == 16) { // ID = create_image_ID(ID_name, naxis, naxes, Dtype, data.SHARED_DFT, data.NBKEWORD_DFT); - create_image_ID(ID_name, naxis, naxes, _DATATYPE_UINT16, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_UINT16, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID); // fits_read_img(fptr, 20, fpixel, nelements, &nulval, sarray, &anynul, &FITSIO_status); { int status = 0; - fits_read_img(fptr, 20, fpixel, nelements, &nulval, data.image[ID].array.UI16, - &anynul, &status); + fits_read_img(fptr, 20, fpixel, nelements, &nulval, data.image[ID].array.UI16, &anynul, &status); FITSIO_CHECK_ERROR(status, errmode, "fits_read_img bitpix=%d", bitpix); } } - /* bitpix = 32 TLONG */ - if(bitpix == 32) + if (bitpix == 32) { - create_image_ID(ID_name, naxis, naxes, _DATATYPE_INT32, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID); - larray = (long *) malloc(sizeof(long) * nelements); - if(larray == NULL) + create_image_ID(ID_name, naxis, naxes, _DATATYPE_INT32, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID); + larray = (long *)malloc(sizeof(long) * nelements); + if (larray == NULL) { PRINT_ERROR("malloc error"); exit(0); } { int status = 0; - fits_read_img(fptr, data_type_code(bitpix), fpixel, nelements, &nulval, larray, - &anynul, &status); + fits_read_img(fptr, data_type_code(bitpix), fpixel, nelements, &nulval, larray, &anynul, &status); FITSIO_CHECK_ERROR(status, errmode, "fits_read_img bitpix=%d", bitpix); } bzero = 0.0; - for(uint_fast64_t ii = 0; ii < (uint_fast64_t) nelements; ii++) + for (uint_fast64_t ii = 0; ii < (uint_fast64_t)nelements; ii++) { data.image[ID].array.SI32[ii] = larray[ii] * bscale + bzero; } @@ -390,14 +314,12 @@ errno_t load_fits( larray = NULL; } - /* bitpix = 64 TLONG */ - if(bitpix == 64) + if (bitpix == 64) { - create_image_ID(ID_name, naxis, naxes, _DATATYPE_INT64, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID); - larray = (long *) malloc(sizeof(long) * nelements); - if(larray == NULL) + create_image_ID(ID_name, naxis, naxes, _DATATYPE_INT64, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID); + larray = (long *)malloc(sizeof(long) * nelements); + if (larray == NULL) { PRINT_ERROR("malloc error"); abort(); @@ -405,13 +327,12 @@ errno_t load_fits( { int status = 0; - fits_read_img(fptr, data_type_code(bitpix), fpixel, nelements, &nulval, larray, - &anynul, &status); + fits_read_img(fptr, data_type_code(bitpix), fpixel, nelements, &nulval, larray, &anynul, &status); FITSIO_CHECK_ERROR(status, errmode, "fits_read_img bitpix=%d", bitpix); } bzero = 0.0; - for(uint_fast64_t ii = 0; ii < (uint_fast64_t) nelements; ii++) + for (uint_fast64_t ii = 0; ii < (uint_fast64_t)nelements; ii++) { data.image[ID].array.SI64[ii] = larray[ii] * bscale + bzero; } @@ -419,16 +340,12 @@ errno_t load_fits( larray = NULL; } - - - /* bitpix = 8 TBYTE */ - if(bitpix == 8) + if (bitpix == 8) { - create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID); - barray = (unsigned char *) malloc(sizeof(unsigned char) * naxes[1] * naxes[0]); - if(barray == NULL) + create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID); + barray = (unsigned char *)malloc(sizeof(unsigned char) * naxes[1] * naxes[0]); + if (barray == NULL) { PRINT_ERROR("malloc error"); exit(0); @@ -436,12 +353,11 @@ errno_t load_fits( { int status = 0; - fits_read_img(fptr, data_type_code(bitpix), fpixel, nelements, &nulval, barray, - &anynul, &status); + fits_read_img(fptr, data_type_code(bitpix), fpixel, nelements, &nulval, barray, &anynul, &status); FITSIO_CHECK_ERROR(status, errmode, "fits_read_img bitpix=%d", bitpix); } - for(uint_fast64_t ii = 0; ii < (uint_fast64_t) nelements; ii++) + for (uint_fast64_t ii = 0; ii < (uint_fast64_t)nelements; ii++) { data.image[ID].array.F[ii] = (1.0 * barray[ii] * bscale + bzero); } @@ -449,13 +365,13 @@ errno_t load_fits( barray = NULL; } - IMGID img = makesetIMGID(ID_name, ID); // keywords to ignore - char *keywordignore[] = {"BITPIX", "NAXIS", "SIMPLE", "EXTEND", "COMMENT", "DATE", "NAXIS1", "NAXIS2", "NAXIS3", "NAXIS4", "BSCALE", "BZERO", 0}; + char *keywordignore[] = {"BITPIX", "NAXIS", "SIMPLE", "EXTEND", "COMMENT", "DATE", "NAXIS1", + "NAXIS2", "NAXIS3", "NAXIS4", "BSCALE", "BZERO", 0}; printf("%d FITS keywords detected\n", nbFITSkeys); - for(int kwnum = 0; kwnum < nbFITSkeys; kwnum ++) + for (int kwnum = 0; kwnum < nbFITSkeys; kwnum++) { char keyname[9]; char kwvaluestr[21]; @@ -467,12 +383,11 @@ errno_t load_fits( //printf("FITS KEYW %3d %8s %20s / %s\n", kwnum, keyname, kwvaluestr, kwcomment); - int kwignore = 0; int ki = 0; - while(keywordignore[ki]) + while (keywordignore[ki]) { - if(strcmp(keywordignore[ki], keyname) == 0) + if (strcmp(keywordignore[ki], keyname) == 0) { //printf("%3d IGNORING %s\n", kwnum, keyname); kwignore = 1; @@ -481,62 +396,54 @@ errno_t load_fits( ki++; } - if((kwignore == 0) && (strlen(kwvaluestr) > 0)) + if ((kwignore == 0) && (strlen(kwvaluestr) > 0)) { int kwtypeOK = 0; // is this a long ? char *tailstr; long kwlongval = strtol(kwvaluestr, &tailstr, 10); - if(strlen(tailstr) == 0) + if (strlen(tailstr) == 0) { kwtypeOK = 1; - printf("%3d FITS KEYW [L] %-8s= %20ld / %s\n", kwnum, keyname, kwlongval, - kwcomment); + printf("%3d FITS KEYW [L] %-8s= %20ld / %s\n", kwnum, keyname, kwlongval, kwcomment); image_keyword_addL(img, keyname, kwlongval, kwcomment); } - if(kwtypeOK == 0) + if (kwtypeOK == 0) { // is this a float ? double kwdoubleval = strtold(kwvaluestr, &tailstr); - if(strlen(tailstr) == 0) + if (strlen(tailstr) == 0) { kwtypeOK = 1; - printf("%3d FITS KEYW [D] %-8s= %20g / %s\n", kwnum, keyname, kwdoubleval, - kwcomment); + printf("%3d FITS KEYW [D] %-8s= %20g / %s\n", kwnum, keyname, kwdoubleval, kwcomment); image_keyword_addD(img, keyname, kwdoubleval, kwcomment); } - if(kwtypeOK == 0) + if (kwtypeOK == 0) { // default to string - printf("%3d FITS KEYW [S] %-8s= %-20s / %s\n", kwnum, keyname, kwvaluestr, - kwcomment); + printf("%3d FITS KEYW [S] %-8s= %-20s / %s\n", kwnum, keyname, kwvaluestr, kwcomment); // remove leading and trailing ' kwvaluestr[strlen(kwvaluestr) - 1] = '\0'; char *kwvaluestr1; kwvaluestr1 = kwvaluestr + 1; image_keyword_addS(img, keyname, kwvaluestr1, kwcomment); } - } } } - - { int status = 0; fits_close_file(fptr, &status); - FITSIO_CHECK_ERROR(status, errmode, "fits_close_file error in image %s", - file_name); + FITSIO_CHECK_ERROR(status, errmode, "fits_close_file error in image %s", file_name); } list_image_ID(); - - if(IDout != NULL) + if (IDout != NULL) { *IDout = ID; } @@ -547,22 +454,13 @@ errno_t load_fits( return RETURN_SUCCESS; } - - - static errno_t compute_function() { DEBUG_TRACE_FSTART(); INSERT_STD_PROCINFO_COMPUTEFUNC_START - FUNC_CHECK_RETURN(load_fits( - infilename, - outimname, - *FITSIOerrmode, - NULL - ) - ); + FUNC_CHECK_RETURN(load_fits(infilename, outimname, *FITSIOerrmode, NULL)); INSERT_STD_PROCINFO_COMPUTEFUNC_END @@ -570,14 +468,11 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - - INSERT_STD_FPSCLIfunctions - -// Register function in CLI -errno_t CLIADDCMD_COREMOD_iofits__loadfits() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_iofits__loadfits() { //INSERT_STD_FPSCLIREGISTERFUNC @@ -586,5 +481,3 @@ errno_t CLIADDCMD_COREMOD_iofits__loadfits() return RETURN_SUCCESS; } - - diff --git a/src/COREMOD_iofits/loadfits.h b/src/COREMOD_iofits/loadfits.h index 3d0c524f..155bd891 100644 --- a/src/COREMOD_iofits/loadfits.h +++ b/src/COREMOD_iofits/loadfits.h @@ -2,22 +2,16 @@ * @file loadfits.h */ - #ifndef MILK_COREMOD_IOFIT_LOADFITS_H #define MILK_COREMOD_IOFIT_LOADFITS_H -#define LOADFITS_ERRMODE_IGNORE 0 +#define LOADFITS_ERRMODE_IGNORE 0 #define LOADFITS_ERRMODE_WARNING 1 -#define LOADFITS_ERRMODE_ERROR 2 -#define LOADFITS_ERRMODE_EXIT 3 +#define LOADFITS_ERRMODE_ERROR 2 +#define LOADFITS_ERRMODE_EXIT 3 errno_t CLIADDCMD_COREMOD_iofits__loadfits(); -errno_t load_fits( - const char *restrict file_name, - const char *restrict ID_name, - int errmode, - imageID *ID -); +errno_t load_fits(const char *restrict file_name, const char *restrict ID_name, int errmode, imageID *ID); #endif diff --git a/src/COREMOD_iofits/loadmemstream.c b/src/COREMOD_iofits/loadmemstream.c index 4c7d560b..737886f9 100644 --- a/src/COREMOD_iofits/loadmemstream.c +++ b/src/COREMOD_iofits/loadmemstream.c @@ -5,8 +5,8 @@ * Scan for source location, load stream of FITS file */ -#include "CommandLineInterface/CLIcore.h" #include "COREMOD_memory/COREMOD_memory.h" +#include "CommandLineInterface/CLIcore.h" #include "COREMOD_iofits_common.h" #include "loadfits.h" @@ -14,87 +14,67 @@ extern COREMOD_IOFITS_DATA COREMOD_iofits_data; - - // High-level load to stream - -imageID COREMOD_IOFITS_LoadMemStream( - const char *sname, - uint64_t *streamflag, - uint32_t *imLOC -) +imageID COREMOD_IOFITS_LoadMemStream(const char *sname, uint64_t *streamflag, uint32_t *imLOC) { imageID ID = -1; - // toggles to 1 if updating shared mem __attribute__((unused)) int updateSHAREMEM = 0; - int updateCONFFITS = 0; // toggles to 1 if updating CONF FITS - int MEMLOADREPORT = 0; - if(FPFLAG_STREAM_MEMLOADREPORT & *streamflag) // write report to disk + if (FPFLAG_STREAM_MEMLOADREPORT & *streamflag) // write report to disk { MEMLOADREPORT = 1; } - MEMLOADREPORT = 1;// TMP - + MEMLOADREPORT = 1; // TMP *imLOC = STREAM_LOAD_SOURCE_NOTFOUND; - - - - if(strcmp(sname, "NULL") == 0) // don't bother looking for it + if (strcmp(sname, "NULL") == 0) // don't bother looking for it { *imLOC = STREAM_LOAD_SOURCE_NULL; ID = -1; } - - int imLOCALMEM; - if(*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching + if (*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching { // Does image exist in memory ? ID = image_ID(sname); - if(ID == -1) + if (ID == -1) { imLOCALMEM = 0; - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s stream not in local memory", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s stream not in local memory", sname); functionparameter_outlog("LOADMEMSTREAM", msg); } } else { imLOCALMEM = 1; - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s stream in local memory", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s stream in local memory", sname); functionparameter_outlog("LOADMEMSTREAM", msg); } } - // printf("imLOC = %d\n", *imLOC); - // FORCE_LOCALMEM - if(FPFLAG_STREAM_LOAD_FORCE_LOCALMEM & *streamflag) + if (FPFLAG_STREAM_LOAD_FORCE_LOCALMEM & *streamflag) { - if(imLOCALMEM == 0) + if (imLOCALMEM == 0) { *imLOC = STREAM_LOAD_SOURCE_EXITFAILURE; // fail - if(MEMLOADREPORT) + if (MEMLOADREPORT) { char msg[STRINGMAXLEN_FPS_LOGMSG]; SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, @@ -106,11 +86,10 @@ imageID COREMOD_IOFITS_LoadMemStream( else { *imLOC = STREAM_LOAD_SOURCE_LOCALMEM; - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s SUCCESS STREAM_LOAD_FORCE_LOCALMEM", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s SUCCESS STREAM_LOAD_FORCE_LOCALMEM", sname); functionparameter_outlog("LOADMEMSTREAM", msg); sprintf(msg, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); @@ -119,19 +98,17 @@ imageID COREMOD_IOFITS_LoadMemStream( } } - - // FORCE_SHAREMEM - if(*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching + if (*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching { - if(FPFLAG_STREAM_LOAD_FORCE_SHAREMEM & *streamflag) + if (FPFLAG_STREAM_LOAD_FORCE_SHAREMEM & *streamflag) { // search SHAREMEM ID = read_sharedmem_image(sname); - if(ID == -1) + if (ID == -1) { *imLOC = STREAM_LOAD_SOURCE_EXITFAILURE; // fail - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, @@ -143,64 +120,57 @@ imageID COREMOD_IOFITS_LoadMemStream( else { *imLOC = STREAM_LOAD_SOURCE_SHAREMEM; - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s SUCCESS STREAM_LOAD_FORCE_SHAREDMEM", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s SUCCESS STREAM_LOAD_FORCE_SHAREDMEM", sname); functionparameter_outlog("LOADMEMSTREAM", msg); - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s imLOC %u", sname, *imLOC); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); } } } } - // FORCE_CONFFITS - if(*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching + if (*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching { - if(FPFLAG_STREAM_LOAD_FORCE_CONFFITS & *streamflag) + if (FPFLAG_STREAM_LOAD_FORCE_CONFFITS & *streamflag) { // search CONFFITS char fname[STRINGMAXLEN_FULLFILENAME]; WRITE_FULLFILENAME(fname, "./conf/shmim.%s.fits", sname); load_fits(fname, sname, 0, &ID); - if(ID == -1) + if (ID == -1) { *imLOC = STREAM_LOAD_SOURCE_EXITFAILURE; // fail - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s EXITFAIL STREAM_LOAD_FORCE_CONFFITS: Image does not exist as conf FITS", - sname); + "%s EXITFAIL STREAM_LOAD_FORCE_CONFFITS: Image does not exist as conf FITS", sname); functionparameter_outlog("LOADMEMSTREAM", msg); } } else { *imLOC = STREAM_LOAD_SOURCE_CONFFITS; - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s SUCCESS STREAM_LOAD_FORCE_CONFFITS", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s SUCCESS STREAM_LOAD_FORCE_CONFFITS", sname); functionparameter_outlog("LOADMEMSTREAM", msg); - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s imLOC %u", sname, *imLOC); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); } } } } - // FORCE_CONFNAME - if(*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching + if (*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching { - if(FPFLAG_STREAM_LOAD_FORCE_CONFNAME & *streamflag) + if (FPFLAG_STREAM_LOAD_FORCE_CONFNAME & *streamflag) { // search CONFNAME FILE *fp; @@ -211,31 +181,30 @@ imageID COREMOD_IOFITS_LoadMemStream( WRITE_FULLFILENAME(fname, "./conf/shmim.%s.fname.txt", sname); fp = fopen(fname, "r"); - if(fp == NULL) + if (fp == NULL) { printf("ERROR: stream %s could not be loaded from CONF\n", sname); *imLOC = STREAM_LOAD_SOURCE_EXITFAILURE; // fail - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s EXITFAIL STREAM_LOAD_FORCE_CONFNAME: File %s does not exist", sname, fname); functionparameter_outlog("LOADMEMSTREAM", msg); - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s imLOC %u", sname, *imLOC); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); } } else { fscanfcnt = fscanf(fp, "%s", streamfname); - if(fscanfcnt == EOF) + if (fscanfcnt == EOF) { - if(ferror(fp)) + if (ferror(fp)) { perror("fscanf"); *imLOC = STREAM_LOAD_SOURCE_EXITFAILURE; // fail - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, @@ -249,15 +218,15 @@ imageID COREMOD_IOFITS_LoadMemStream( fprintf(stderr, "Error: fscanf reached end of file, no matching characters, no matching failure\n"); *imLOC = STREAM_LOAD_SOURCE_EXITFAILURE; // fail - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s EXITFAIL STREAM_LOAD_FORCE_CONFNAME: fscanf reached end of file, no matching characters", + "%s EXITFAIL STREAM_LOAD_FORCE_CONFNAME: fscanf reached end of file, no " + "matching characters", sname); functionparameter_outlog("LOADMEMSTREAM", msg); - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s imLOC %u", sname, *imLOC); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); } } @@ -265,38 +234,36 @@ imageID COREMOD_IOFITS_LoadMemStream( fclose(fp); } - - if(*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) + if (*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) { - if(fscanfcnt > 0) + if (fscanfcnt > 0) { { load_fits(streamfname, sname, 0, &ID); - if(ID == -1) + if (ID == -1) { *imLOC = STREAM_LOAD_SOURCE_EXITFAILURE; // fail - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s EXITFAIL STREAM_LOAD_FORCE_CONFNAME: cannot load stream fname", sname); + "%s EXITFAIL STREAM_LOAD_FORCE_CONFNAME: cannot load stream fname", + sname); functionparameter_outlog("LOADMEMSTREAM", msg); - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s imLOC %u", sname, *imLOC); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); } } else { *imLOC = STREAM_LOAD_SOURCE_CONFNAME; - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s SUCCESS STREAM_LOAD_FORCE_CONFFITS", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s SUCCESS STREAM_LOAD_FORCE_CONFFITS", + sname); functionparameter_outlog("LOADMEMSTREAM", msg); - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s imLOC %u", sname, *imLOC); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); } } @@ -306,29 +273,25 @@ imageID COREMOD_IOFITS_LoadMemStream( } } - - // SEARCH LOCALMEM - if(*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching + if (*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching { //printf("imLOC = %d\n", *imLOC); - if(!(FPFLAG_STREAM_LOAD_SKIPSEARCH_LOCALMEM & *streamflag)) + if (!(FPFLAG_STREAM_LOAD_SKIPSEARCH_LOCALMEM & *streamflag)) { - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s Search LOCALMEM", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s Search LOCALMEM", sname); functionparameter_outlog("LOADMEMSTREAM", msg); } - if(imLOCALMEM == 1) + if (imLOCALMEM == 1) { *imLOC = STREAM_LOAD_SOURCE_LOCALMEM; - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s SUCCESS found image in LOCALMEM", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s SUCCESS found image in LOCALMEM", sname); functionparameter_outlog("LOADMEMSTREAM", msg); SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); @@ -337,109 +300,93 @@ imageID COREMOD_IOFITS_LoadMemStream( else { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s localmem stream not found", - sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s localmem stream not found", sname); functionparameter_outlog("LOADMEMSTREAM", msg); } } //printf("imLOC = %d\n", *imLOC); } - - // SEARCH SHAREMEM - if(*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching + if (*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching { - if(!(FPFLAG_STREAM_LOAD_SKIPSEARCH_SHAREMEM & *streamflag)) + if (!(FPFLAG_STREAM_LOAD_SKIPSEARCH_SHAREMEM & *streamflag)) { - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s Search SHAREMEM", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s Search SHAREMEM", sname); functionparameter_outlog("LOADMEMSTREAM", msg); } ID = read_sharedmem_image(sname); - if(ID != -1) + if (ID != -1) { *imLOC = STREAM_LOAD_SOURCE_SHAREMEM; - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s SUCCESS found image in SHAREMEM", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s SUCCESS found image in SHAREMEM", sname); functionparameter_outlog("LOADMEMSTREAM", msg); - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s imLOC %u", sname, *imLOC); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); } } else { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s sharedmem stream not found", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s sharedmem stream not found", sname); functionparameter_outlog("LOADMEMSTREAM", msg); } } //printf("imLOC = %d\n", *imLOC); } - - // SEARCH CONFFITS - if(*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching + if (*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching { - if(!(FPFLAG_STREAM_LOAD_SKIPSEARCH_CONFFITS & *streamflag)) + if (!(FPFLAG_STREAM_LOAD_SKIPSEARCH_CONFFITS & *streamflag)) { - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s Search CONFFITS", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s Search CONFFITS", sname); functionparameter_outlog("LOADMEMSTREAM", msg); } //printf("imLOC = %d\n", *imLOC); char fname[STRINGMAXLEN_FULLFILENAME]; WRITE_FULLFILENAME(fname, "./conf/shmim.%s.fits", sname); load_fits(fname, sname, 0, &ID); - if(ID != -1) + if (ID != -1) { *imLOC = STREAM_LOAD_SOURCE_CONFFITS; - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s SUCCESS found image in CONFFITS", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s SUCCESS found image in CONFFITS", sname); functionparameter_outlog("LOADMEMSTREAM", msg); - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s imLOC %u", sname, *imLOC); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); } } else { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s File %s not found", sname, fname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s File %s not found", sname, fname); functionparameter_outlog("LOADMEMSTREAM", msg); } // printf("imLOC = %d\n", *imLOC); } } - - // SEARCH CONFNAME - if(*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching + if (*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) // still searching { - if(!(FPFLAG_STREAM_LOAD_SKIPSEARCH_CONFNAME & *streamflag)) + if (!(FPFLAG_STREAM_LOAD_SKIPSEARCH_CONFNAME & *streamflag)) { - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s Search CONFNAME", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s Search CONFNAME", sname); functionparameter_outlog("LOADMEMSTREAM", msg); } @@ -452,14 +399,13 @@ imageID COREMOD_IOFITS_LoadMemStream( sprintf(fname, "./conf/shmim.%s.fname.txt", sname); fp = fopen(fname, "r"); - if(fp == NULL) + if (fp == NULL) { printf("ERROR: stream %s could not be loaded from CONF\n", sname); - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s Cannot find CONFNAME file %s", sname, fname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s Cannot find CONFNAME file %s", sname, fname); functionparameter_outlog("LOADMEMSTREAM", msg); // don't fail... keep going } @@ -467,20 +413,19 @@ imageID COREMOD_IOFITS_LoadMemStream( else { fscanfcnt = fscanf(fp, "%s", streamfname); - if(fscanfcnt == EOF) + if (fscanfcnt == EOF) { - if(ferror(fp)) + if (ferror(fp)) { perror("fscanf"); *imLOC = STREAM_LOAD_SOURCE_EXITFAILURE; // fail - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s EXITFAILURE fscanf error reading %s", sname, fname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s EXITFAILURE fscanf error reading %s", + sname, fname); functionparameter_outlog("LOADMEMSTREAM", msg); - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s imLOC %u", sname, *imLOC); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); } } @@ -489,15 +434,15 @@ imageID COREMOD_IOFITS_LoadMemStream( fprintf(stderr, "Error: fscanf reached end of file, no matching characters, no matching failure\n"); *imLOC = STREAM_LOAD_SOURCE_EXITFAILURE; // fail - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s EXITFAILURE fscanf error reading %s. fscanf reached end of file, no matching characters", + "%s EXITFAILURE fscanf error reading %s. fscanf reached end of file, no " + "matching characters", sname, fname); functionparameter_outlog("LOADMEMSTREAM", msg); - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s imLOC %u", sname, *imLOC); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); } } @@ -505,27 +450,24 @@ imageID COREMOD_IOFITS_LoadMemStream( fclose(fp); } - if(*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) + if (*imLOC == STREAM_LOAD_SOURCE_NOTFOUND) { - if(fscanfcnt > 0) + if (fscanfcnt > 0) { { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s LOADING %s", sname, streamfname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s LOADING %s", sname, streamfname); functionparameter_outlog("LOADMEMSTREAM", msg); load_fits(streamfname, sname, 0, &ID); - if(ID != -1) + if (ID != -1) { *imLOC = STREAM_LOAD_SOURCE_CONFNAME; updateCONFFITS = 1; - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s SUCCESS CONFNAME", sname); - functionparameter_outlog("LOADMEMSTREAM", msg) - ; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s imLOC %u", sname, *imLOC); + functionparameter_outlog("LOADMEMSTREAM", msg); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s imLOC %u", sname, *imLOC); functionparameter_outlog("LOADMEMSTREAM", msg); } } @@ -536,102 +478,88 @@ imageID COREMOD_IOFITS_LoadMemStream( } } - // copy to shared memory - if(*imLOC == STREAM_LOAD_SOURCE_LOCALMEM) - if(FPFLAG_STREAM_LOAD_UPDATE_SHAREMEM & *streamflag) + if (*imLOC == STREAM_LOAD_SOURCE_LOCALMEM) + if (FPFLAG_STREAM_LOAD_UPDATE_SHAREMEM & *streamflag) { - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s copy to SHAREMEM", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s copy to SHAREMEM", sname); functionparameter_outlog("LOADMEMSTREAM", msg); } copy_image_ID(sname, sname, 1); } - - // copy to conf FITS - if((*imLOC != STREAM_LOAD_SOURCE_NOTFOUND) - && (*imLOC != STREAM_LOAD_SOURCE_CONFFITS)) - if(FPFLAG_STREAM_LOAD_UPDATE_CONFFITS & *streamflag) + if ((*imLOC != STREAM_LOAD_SOURCE_NOTFOUND) && (*imLOC != STREAM_LOAD_SOURCE_CONFFITS)) + if (FPFLAG_STREAM_LOAD_UPDATE_CONFFITS & *streamflag) { updateCONFFITS = 1; } - if(updateCONFFITS == 1) + if (updateCONFFITS == 1) { char fname[STRINGMAXLEN_FULLFILENAME]; - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, - "%s copy to CONFFITS", sname); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s copy to CONFFITS", sname); functionparameter_outlog("LOADMEMSTREAM", msg); } WRITE_FULLFILENAME(fname, "./conf/shmim.%s.fits", sname); save_fits(sname, fname); } - - - if((int) *imLOC == STREAM_LOAD_SOURCE_EXITFAILURE) + if ((int)*imLOC == STREAM_LOAD_SOURCE_EXITFAILURE) { *imLOC = STREAM_LOAD_SOURCE_NOTFOUND; } - - if(MEMLOADREPORT == 1) + if (MEMLOADREPORT == 1) { char msg[STRINGMAXLEN_FPS_LOGMSG]; char locstring[100]; - switch(*imLOC) + switch (*imLOC) { - case STREAM_LOAD_SOURCE_NOTFOUND : - strcpy(locstring, STREAM_LOAD_SOURCE_NOTFOUND_STRING); - break; + case STREAM_LOAD_SOURCE_NOTFOUND: + strcpy(locstring, STREAM_LOAD_SOURCE_NOTFOUND_STRING); + break; - case STREAM_LOAD_SOURCE_LOCALMEM : - strcpy(locstring, STREAM_LOAD_SOURCE_LOCALMEM_STRING); - break; + case STREAM_LOAD_SOURCE_LOCALMEM: + strcpy(locstring, STREAM_LOAD_SOURCE_LOCALMEM_STRING); + break; - case STREAM_LOAD_SOURCE_SHAREMEM : - strcpy(locstring, STREAM_LOAD_SOURCE_SHAREMEM_STRING); - break; + case STREAM_LOAD_SOURCE_SHAREMEM: + strcpy(locstring, STREAM_LOAD_SOURCE_SHAREMEM_STRING); + break; - case STREAM_LOAD_SOURCE_CONFFITS : - strcpy(locstring, STREAM_LOAD_SOURCE_CONFFITS_STRING); - break; + case STREAM_LOAD_SOURCE_CONFFITS: + strcpy(locstring, STREAM_LOAD_SOURCE_CONFFITS_STRING); + break; - case STREAM_LOAD_SOURCE_CONFNAME : - strcpy(locstring, STREAM_LOAD_SOURCE_CONFNAME_STRING); - break; + case STREAM_LOAD_SOURCE_CONFNAME: + strcpy(locstring, STREAM_LOAD_SOURCE_CONFNAME_STRING); + break; - case STREAM_LOAD_SOURCE_NULL : - strcpy(locstring, STREAM_LOAD_SOURCE_NULL_STRING); - break; + case STREAM_LOAD_SOURCE_NULL: + strcpy(locstring, STREAM_LOAD_SOURCE_NULL_STRING); + break; - case STREAM_LOAD_SOURCE_EXITFAILURE : - strcpy(locstring, STREAM_LOAD_SOURCE_EXITFAILURE_STRING); - break; + case STREAM_LOAD_SOURCE_EXITFAILURE: + strcpy(locstring, STREAM_LOAD_SOURCE_EXITFAILURE_STRING); + break; - default : - strcpy(locstring, "unknown"); - break; + default: + strcpy(locstring, "unknown"); + break; } - - SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s FINAL imLOC %u %s", sname, - *imLOC, locstring); + SNPRINTF_CHECK(msg, STRINGMAXLEN_FPS_LOGMSG, "%s FINAL imLOC %u %s", sname, *imLOC, locstring); functionparameter_outlog("LOADMEMSTREAM", msg); } return ID; } - - - diff --git a/src/COREMOD_iofits/loadmemstream.h b/src/COREMOD_iofits/loadmemstream.h index 5a019723..19999f03 100644 --- a/src/COREMOD_iofits/loadmemstream.h +++ b/src/COREMOD_iofits/loadmemstream.h @@ -2,9 +2,4 @@ * @file loadmemstream.h */ - -imageID COREMOD_IOFITS_LoadMemStream( - const char *sname, - uint64_t *streamflag, - uint32_t *imLOC -); +imageID COREMOD_IOFITS_LoadMemStream(const char *sname, uint64_t *streamflag, uint32_t *imLOC); diff --git a/src/COREMOD_iofits/read_keyword.c b/src/COREMOD_iofits/read_keyword.c index d60f4eef..3d6977d8 100644 --- a/src/COREMOD_iofits/read_keyword.c +++ b/src/COREMOD_iofits/read_keyword.c @@ -2,33 +2,25 @@ * @file read_keyword.c */ - #include "CommandLineInterface/CLIcore.h" #include "COREMOD_iofits_common.h" #include "check_fitsio_status.h" - extern COREMOD_IOFITS_DATA COREMOD_iofits_data; - - -int read_keyword( - const char *restrict file_name, - const char *restrict KEYWORD, - char *restrict content -) +int read_keyword(const char *restrict file_name, const char *restrict KEYWORD, char *restrict content) { - fitsfile *fptr; /* FITS file pointer, defined in fitsio.h */ + fitsfile *fptr; /* FITS file pointer, defined in fitsio.h */ int exists = 0; int n; - if(!fits_open_file(&fptr, file_name, READONLY, &COREMOD_iofits_data.FITSIO_status)) + if (!fits_open_file(&fptr, file_name, READONLY, &COREMOD_iofits_data.FITSIO_status)) { char comment[STRINGMAXLEN_FITSKEYWCOMMENT]; char str1[STRINGMAXLEN_FITSKEYWORDVALUE]; - if(fits_read_keyword(fptr, KEYWORD, str1, comment, &COREMOD_iofits_data.FITSIO_status)) + if (fits_read_keyword(fptr, KEYWORD, str1, comment, &COREMOD_iofits_data.FITSIO_status)) { PRINT_ERROR("Keyword \"%s\" does not exist in file \"%s\"", KEYWORD, file_name); exists = 1; @@ -36,32 +28,26 @@ int read_keyword( else { n = snprintf(content, STRINGMAXLEN_FITSKEYWORDVALUE, "%s\n", str1); - if(n >= STRINGMAXLEN_FITSKEYWORDVALUE) + if (n >= STRINGMAXLEN_FITSKEYWORDVALUE) { PRINT_ERROR("Attempted to write string buffer with too many characters"); } } fits_close_file(fptr, &COREMOD_iofits_data.FITSIO_status); } - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 0) == 1) + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 0) == 1) { - PRINT_ERROR("Error reading keyword \"%s\" in file \"%s\"", KEYWORD, file_name); + PRINT_ERROR("Error reading keyword \"%s\" in file \"%s\"", KEYWORD, file_name); } - return(exists); + return (exists); } - - - -errno_t read_keyword_alone( - const char *restrict file_name, - const char *restrict KEYWORD -) +errno_t read_keyword_alone(const char *restrict file_name, const char *restrict KEYWORD) { - char *content = (char *) malloc(sizeof(char) * STRINGMAXLEN_FITSKEYWORDVALUE); + char *content = (char *)malloc(sizeof(char) * STRINGMAXLEN_FITSKEYWORDVALUE); - if(content == NULL) + if (content == NULL) { PRINT_ERROR("malloc error"); exit(0); @@ -75,4 +61,3 @@ errno_t read_keyword_alone( return RETURN_SUCCESS; } - diff --git a/src/COREMOD_iofits/read_keyword.h b/src/COREMOD_iofits/read_keyword.h index 6bea1cce..0a3c8d50 100644 --- a/src/COREMOD_iofits/read_keyword.h +++ b/src/COREMOD_iofits/read_keyword.h @@ -2,15 +2,6 @@ * @file read_keyword.h */ +int read_keyword(const char *restrict file_name, const char *restrict KEYWORD, char *restrict content); - -int read_keyword( - const char *restrict file_name, - const char *restrict KEYWORD, - char *restrict content -); - -errno_t read_keyword_alone( - const char *restrict file_name, - const char *restrict KEYWORD -); +errno_t read_keyword_alone(const char *restrict file_name, const char *restrict KEYWORD); diff --git a/src/COREMOD_iofits/savefits.c b/src/COREMOD_iofits/savefits.c index f1750fc7..6a0de606 100644 --- a/src/COREMOD_iofits/savefits.c +++ b/src/COREMOD_iofits/savefits.c @@ -3,10 +3,8 @@ * @brief save FITS format files */ - #include "CommandLineInterface/CLIcore.h" - #include // Handle old fitsios @@ -14,18 +12,14 @@ #define ULONGLONG_IMG (80) #endif -#include "COREMOD_memory/COREMOD_memory.h" #include "COREMOD_iofits_common.h" +#include "COREMOD_memory/COREMOD_memory.h" #include "check_fitsio_status.h" #include "file_exists.h" #include "is_fits_file.h" extern COREMOD_IOFITS_DATA COREMOD_iofits_data; - - - - // variables local to this translation unit static char *inimname; static char *outfname; @@ -33,58 +27,24 @@ static int *outbitpix; static char *inheader; // import header from this file // CLI function arguments and parameters -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".in_name", "input image", "im1", - CLIARG_VISIBLE_DEFAULT, - (void **) &inimname, NULL - }, - { - CLIARG_STR, ".out_fname", "output FITS file name", "out.fits", - CLIARG_VISIBLE_DEFAULT, - (void **) &outfname, NULL - }, - { - // non-CLI parameter - CLIARG_LONG, ".bitpix", - "0: auto\n" - "8 /(10) : (un)sig 8-b int\n" - "16/(20) 32/(40) 64/(80) : (un)sig int\n" - "-32/-64 : 32/64-b flt\n" - , "0", - CLIARG_HIDDEN_DEFAULT, - (void **) &outbitpix, NULL - }, - { - CLIARG_STR, ".in_header", "header import from this FITS file", "", - CLIARG_HIDDEN_DEFAULT, - (void **) &inheader, NULL - } -}; - +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".in_name", "input image", "im1", CLIARG_VISIBLE_DEFAULT, (void **)&inimname, NULL}, + {CLIARG_STR, ".out_fname", "output FITS file name", "out.fits", CLIARG_VISIBLE_DEFAULT, (void **)&outfname, NULL}, + {// non-CLI parameter + CLIARG_LONG, ".bitpix", + "0: auto\n" + "8 /(10) : (un)sig 8-b int\n" + "16/(20) 32/(40) 64/(80) : (un)sig int\n" + "-32/-64 : 32/64-b flt\n", + "0", CLIARG_HIDDEN_DEFAULT, (void **)&outbitpix, NULL}, + {CLIARG_STR, ".in_header", "header import from this FITS file", "", CLIARG_HIDDEN_DEFAULT, (void **)&inheader, + NULL}}; // CLI function initialization data -static CLICMDDATA CLIcmddata = -{ - "saveFITS", - "save image as FITS", - CLICMD_FIELDS_DEFAULTS -}; - - +static CLICMDDATA CLIcmddata = {"saveFITS", "save image as FITS", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - - - - - - +static errno_t help_function() { return RETURN_SUCCESS; } /** * @brief Write FITS file @@ -97,21 +57,11 @@ static errno_t help_function() * @param kwarraysize number of keywords in optional keyword array. Set to 0 if unused. * @return errno_t */ -errno_t saveFITS( - const char *__restrict inputimname, - const char *__restrict outputFITSname, - int outputbitpix, - const char *__restrict importheaderfile, - IMAGE_KEYWORD *kwarray, - int kwarraysize -) +errno_t saveFITS(const char *__restrict inputimname, const char *__restrict outputFITSname, int outputbitpix, + const char *__restrict importheaderfile, IMAGE_KEYWORD *kwarray, int kwarraysize) { DEBUG_TRACE_FSTART(); - DEBUG_TRACEPOINT("Saving image %s to file %s, bitpix = %d", - inputimname, - outputFITSname, - outputbitpix); - + DEBUG_TRACEPOINT("Saving image %s to file %s, bitpix = %d", inputimname, outputFITSname, outputbitpix); COREMOD_iofits_data.FITSIO_status = 0; @@ -128,25 +78,18 @@ errno_t saveFITS( (int) getpid(), (long) self_id); */ - WRITE_FILENAME(fnametmp, - "%s.%d.%ld.tmp", - outputFITSname, - (int) getpid(), - (long) self_id); + WRITE_FILENAME(fnametmp, "%s.%d.%ld.tmp", outputFITSname, (int)getpid(), (long)self_id); printf("temp name : %s\n", fnametmp); - IMGID imgin = makeIMGID(inputimname); resolveIMGID(&imgin, ERRMODE_WARN); - if(imgin.ID == -1) + if (imgin.ID == -1) { - PRINT_WARNING("Image %s does not exist in memory - cannot save to FITS", - inputimname); + PRINT_WARNING("Image %s does not exist in memory - cannot save to FITS", inputimname); DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - // data types uint8_t datatype = imgin.md->datatype; int FITSIOdatatype = TFLOAT; @@ -154,166 +97,155 @@ errno_t saveFITS( char *datainptr; - DEBUG_TRACEPOINT("datatype = %d", (int) datatype); - switch(datatype) + DEBUG_TRACEPOINT("datatype = %d", (int)datatype); + switch (datatype) { - case _DATATYPE_UINT8: - FITSIOdatatype = TBYTE; - bitpix = BYTE_IMG; - datainptr = (char *) imgin.im->array.UI8; - break; - - case _DATATYPE_INT8: - FITSIOdatatype = TSBYTE; - bitpix = SBYTE_IMG; - datainptr = (char *) imgin.im->array.SI8; - break; - - - case _DATATYPE_UINT16: - FITSIOdatatype = TUSHORT; - bitpix = SHORT_IMG; - datainptr = (char *) imgin.im->array.UI16; - break; - - case _DATATYPE_INT16: - FITSIOdatatype = TUSHORT; - bitpix = SHORT_IMG; - datainptr = (char *) imgin.im->array.SI16; - break; - - - case _DATATYPE_UINT32: - FITSIOdatatype = TUINT; - bitpix = ULONG_IMG; - datainptr = (char *) imgin.im->array.UI32; - break; - - case _DATATYPE_INT32: - FITSIOdatatype = TINT; - bitpix = LONG_IMG; - datainptr = (char *) imgin.im->array.SI32; - break; - - - case _DATATYPE_UINT64: - FITSIOdatatype = TULONG; - bitpix = ULONGLONG_IMG; - datainptr = (char *) imgin.im->array.UI64; - break; - - case _DATATYPE_INT64: - FITSIOdatatype = TLONG; - bitpix = LONGLONG_IMG; - datainptr = (char *) imgin.im->array.SI64; - break; - - - case _DATATYPE_FLOAT: - FITSIOdatatype = TFLOAT; - bitpix = FLOAT_IMG; - datainptr = (char *) imgin.im->array.F; - break; - - case _DATATYPE_DOUBLE: - FITSIOdatatype = TDOUBLE; - bitpix = DOUBLE_IMG; - datainptr = (char *) imgin.im->array.D; - break; + case _DATATYPE_UINT8: + FITSIOdatatype = TBYTE; + bitpix = BYTE_IMG; + datainptr = (char *)imgin.im->array.UI8; + break; + + case _DATATYPE_INT8: + FITSIOdatatype = TSBYTE; + bitpix = SBYTE_IMG; + datainptr = (char *)imgin.im->array.SI8; + break; + + case _DATATYPE_UINT16: + FITSIOdatatype = TUSHORT; + bitpix = SHORT_IMG; + datainptr = (char *)imgin.im->array.UI16; + break; + + case _DATATYPE_INT16: + FITSIOdatatype = TUSHORT; + bitpix = SHORT_IMG; + datainptr = (char *)imgin.im->array.SI16; + break; + + case _DATATYPE_UINT32: + FITSIOdatatype = TUINT; + bitpix = ULONG_IMG; + datainptr = (char *)imgin.im->array.UI32; + break; + + case _DATATYPE_INT32: + FITSIOdatatype = TINT; + bitpix = LONG_IMG; + datainptr = (char *)imgin.im->array.SI32; + break; + + case _DATATYPE_UINT64: + FITSIOdatatype = TULONG; + bitpix = ULONGLONG_IMG; + datainptr = (char *)imgin.im->array.UI64; + break; + + case _DATATYPE_INT64: + FITSIOdatatype = TLONG; + bitpix = LONGLONG_IMG; + datainptr = (char *)imgin.im->array.SI64; + break; + + case _DATATYPE_FLOAT: + FITSIOdatatype = TFLOAT; + bitpix = FLOAT_IMG; + datainptr = (char *)imgin.im->array.F; + break; + + case _DATATYPE_DOUBLE: + FITSIOdatatype = TDOUBLE; + bitpix = DOUBLE_IMG; + datainptr = (char *)imgin.im->array.D; + break; } DEBUG_TRACEPOINT("bitpix = %d", bitpix); - switch(outputbitpix) + switch (outputbitpix) { - case 8: - bitpix = BYTE_IMG; - printf(" output data type: BYTE_IMG\n"); - break; - case 10: - bitpix = SBYTE_IMG; - printf(" output data type: SBYTE_IMG\n"); - break; - - case 16: - bitpix = SHORT_IMG; - printf(" output data type: SHORT_IMG\n"); - break; - case 20: - bitpix = USHORT_IMG; - printf(" output data type: USHORT_IMG\n"); - break; - - case 32: - bitpix = LONG_IMG; - printf(" output data type: LONG_IMG\n"); - break; - case 40: - bitpix = ULONG_IMG; - printf(" output data type: ULONG_IMG\n"); - break; - - case 64: - bitpix = LONGLONG_IMG; - printf(" output data type: LONGLONG_IMG\n"); - break; - case 80: - bitpix = ULONGLONG_IMG; - printf(" output data type: ULONGLONG_IMG\n"); - break; - - case -32: - bitpix = FLOAT_IMG; - printf(" output data type: FLOAT_IMG\n"); - break; - case -64: - bitpix = DOUBLE_IMG; - printf(" output data type: DOUBLE_IMG\n"); - break; + case 8: + bitpix = BYTE_IMG; + printf(" output data type: BYTE_IMG\n"); + break; + case 10: + bitpix = SBYTE_IMG; + printf(" output data type: SBYTE_IMG\n"); + break; + + case 16: + bitpix = SHORT_IMG; + printf(" output data type: SHORT_IMG\n"); + break; + case 20: + bitpix = USHORT_IMG; + printf(" output data type: USHORT_IMG\n"); + break; + + case 32: + bitpix = LONG_IMG; + printf(" output data type: LONG_IMG\n"); + break; + case 40: + bitpix = ULONG_IMG; + printf(" output data type: ULONG_IMG\n"); + break; + + case 64: + bitpix = LONGLONG_IMG; + printf(" output data type: LONGLONG_IMG\n"); + break; + case 80: + bitpix = ULONGLONG_IMG; + printf(" output data type: ULONGLONG_IMG\n"); + break; + + case -32: + bitpix = FLOAT_IMG; + printf(" output data type: FLOAT_IMG\n"); + break; + case -64: + bitpix = DOUBLE_IMG; + printf(" output data type: DOUBLE_IMG\n"); + break; } DEBUG_TRACEPOINT("bitpix = %d", bitpix); - fitsfile *fptr; COREMOD_iofits_data.FITSIO_status = 0; DEBUG_TRACEPOINT("creating FITS file %s", fnametmp); fits_create_file(&fptr, fnametmp, &COREMOD_iofits_data.FITSIO_status); DEBUG_TRACEPOINT(" "); - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) { char errstring[200]; - if(access(fnametmp, F_OK) == 0) + if (access(fnametmp, F_OK) == 0) { sprintf(errstring, "File already exists"); } - PRINT_ERROR("fits_create_file error %d on file %s %s", - COREMOD_iofits_data.FITSIO_status, fnametmp, errstring); + PRINT_ERROR("fits_create_file error %d on file %s %s", COREMOD_iofits_data.FITSIO_status, fnametmp, errstring); abort(); } - - - - int naxis = imgin.md->naxis; long naxesl[3]; - for(int i = 0; i < naxis; i++) + for (int i = 0; i < naxis; i++) { - naxesl[i] = (long) imgin.md->size[i]; + naxesl[i] = (long)imgin.md->size[i]; } long nelements = 1; - for(int i = 0; i < naxis; i++) + for (int i = 0; i < naxis; i++) { nelements *= naxesl[i]; } COREMOD_iofits_data.FITSIO_status = 0; - fits_create_img(fptr, bitpix, naxis, naxesl, - &COREMOD_iofits_data.FITSIO_status); - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) + fits_create_img(fptr, bitpix, naxis, naxesl, &COREMOD_iofits_data.FITSIO_status); + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) { PRINT_ERROR("fits_create_img error on file %s", fnametmp); EXECUTE_SYSTEM_COMMAND("rm %s", fnametmp); @@ -322,16 +254,13 @@ errno_t saveFITS( DEBUG_TRACEPOINT(" "); - - DEBUG_TRACEPOINT("Adding optional header"); // HEADER - // Add FITS keywords from importheaderfile (optional) - if(strlen(importheaderfile) > 0) + if (strlen(importheaderfile) > 0) { - if(is_fits_file(importheaderfile) == 1) + if (is_fits_file(importheaderfile) == 1) { printf("Importing FITS header entries from : %s\n", importheaderfile); @@ -341,19 +270,16 @@ errno_t saveFITS( char *header; COREMOD_iofits_data.FITSIO_status = 0; - fits_open_file(&fptr_header, importheaderfile, READONLY, - &COREMOD_iofits_data.FITSIO_status); - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) + fits_open_file(&fptr_header, importheaderfile, READONLY, &COREMOD_iofits_data.FITSIO_status); + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) { PRINT_ERROR("fits_open_file error on file %s", importheaderfile); abort(); } - COREMOD_iofits_data.FITSIO_status = 0; - fits_hdr2str(fptr_header, 1, NULL, 0, &header, &nkeys, - &COREMOD_iofits_data.FITSIO_status); - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) + fits_hdr2str(fptr_header, 1, NULL, 0, &header, &nkeys, &COREMOD_iofits_data.FITSIO_status); + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) { PRINT_ERROR("fits_hdr2str erroron file %s", importheaderfile); abort(); @@ -362,7 +288,7 @@ errno_t saveFITS( char *hptr; // pointer to header hptr = header; - while(*hptr) + while (*hptr) { char fitscard[81]; sprintf(fitscard, "%.80s", hptr); @@ -371,9 +297,9 @@ errno_t saveFITS( int writecard = 1; char *keyexcl[] = {"BITPIX", "NAXIS", "SIMPLE", "EXTEND", 0}; int ki = 0; - while(keyexcl[ki]) + while (keyexcl[ki]) { - if(strncmp(keyexcl[ki], fitscard, strlen(keyexcl[ki])) == 0) + if (strncmp(keyexcl[ki], fitscard, strlen(keyexcl[ki])) == 0) { printf("EXCLUDING %s\n", fitscard); writecard = 0; @@ -382,11 +308,11 @@ errno_t saveFITS( ki++; } - if(writecard == 1) + if (writecard == 1) { COREMOD_iofits_data.FITSIO_status = 0; fits_write_record(fptr, fitscard, &COREMOD_iofits_data.FITSIO_status); - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) { PRINT_ERROR("fits_write_record error on file %s", importheaderfile); abort(); @@ -397,7 +323,7 @@ errno_t saveFITS( COREMOD_iofits_data.FITSIO_status = 0; fits_free_memory(header, &COREMOD_iofits_data.FITSIO_status); - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) { PRINT_ERROR("fits_free_memory error on file %s", importheaderfile); abort(); @@ -405,7 +331,7 @@ errno_t saveFITS( COREMOD_iofits_data.FITSIO_status = 0; fits_close_file(fptr_header, &COREMOD_iofits_data.FITSIO_status); - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) { PRINT_ERROR("fits_close_file error on file %s", importheaderfile); abort(); @@ -413,55 +339,50 @@ errno_t saveFITS( } } - - // Add FITS keywords from image keywords { int NBkw = imgin.md->NBkw; int kwcnt = 0; printf("----------- NUMBER KW = %d ---------------\n", NBkw); - for(int kw = 0; kw < NBkw; kw++) + for (int kw = 0; kw < NBkw; kw++) { char tmpkwvalstr[81]; - switch(imgin.im->kw[kw].type) + switch (imgin.im->kw[kw].type) { - case 'L': - printf("writing keyword [L] %-8s= %20ld / %s\n", imgin.im->kw[kw].name, - imgin.im->kw[kw].value.numl, imgin.im->kw[kw].comment); - COREMOD_iofits_data.FITSIO_status = 0; - fits_update_key(fptr, TLONG, imgin.im->kw[kw].name, - &imgin.im->kw[kw].value.numl, imgin.im->kw[kw].comment, - &COREMOD_iofits_data.FITSIO_status); - kwcnt++; - break; - - case 'D': - printf("writing keyword [D] %-8s= %20g / %s\n", imgin.im->kw[kw].name, - imgin.im->kw[kw].value.numf, imgin.im->kw[kw].comment); - COREMOD_iofits_data.FITSIO_status = 0; - fits_update_key(fptr, TDOUBLE, imgin.im->kw[kw].name, - &imgin.im->kw[kw].value.numf, imgin.im->kw[kw].comment, - &COREMOD_iofits_data.FITSIO_status); - kwcnt++; - break; - - case 'S': - sprintf(tmpkwvalstr, "'%s'", imgin.im->kw[kw].value.valstr); - printf("writing keyword [S] %-8s= %20s / %s\n", imgin.im->kw[kw].name, - tmpkwvalstr, imgin.im->kw[kw].comment); - COREMOD_iofits_data.FITSIO_status = 0; - fits_update_key(fptr, TSTRING, imgin.im->kw[kw].name, - imgin.im->kw[kw].value.valstr, imgin.im->kw[kw].comment, - &COREMOD_iofits_data.FITSIO_status); - kwcnt++; - break; - - default: - break; + case 'L': + printf("writing keyword [L] %-8s= %20ld / %s\n", imgin.im->kw[kw].name, imgin.im->kw[kw].value.numl, + imgin.im->kw[kw].comment); + COREMOD_iofits_data.FITSIO_status = 0; + fits_update_key(fptr, TLONG, imgin.im->kw[kw].name, &imgin.im->kw[kw].value.numl, + imgin.im->kw[kw].comment, &COREMOD_iofits_data.FITSIO_status); + kwcnt++; + break; + + case 'D': + printf("writing keyword [D] %-8s= %20g / %s\n", imgin.im->kw[kw].name, imgin.im->kw[kw].value.numf, + imgin.im->kw[kw].comment); + COREMOD_iofits_data.FITSIO_status = 0; + fits_update_key(fptr, TDOUBLE, imgin.im->kw[kw].name, &imgin.im->kw[kw].value.numf, + imgin.im->kw[kw].comment, &COREMOD_iofits_data.FITSIO_status); + kwcnt++; + break; + + case 'S': + sprintf(tmpkwvalstr, "'%s'", imgin.im->kw[kw].value.valstr); + printf("writing keyword [S] %-8s= %20s / %s\n", imgin.im->kw[kw].name, tmpkwvalstr, + imgin.im->kw[kw].comment); + COREMOD_iofits_data.FITSIO_status = 0; + fits_update_key(fptr, TSTRING, imgin.im->kw[kw].name, imgin.im->kw[kw].value.valstr, + imgin.im->kw[kw].comment, &COREMOD_iofits_data.FITSIO_status); + kwcnt++; + break; + + default: + break; } - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) { PRINT_ERROR("fits_write_record error on keyword %s", imgin.im->kw[kw].name); abort(); @@ -469,48 +390,43 @@ errno_t saveFITS( } } - // add custom keywords - if((kwarraysize > 0) && (kwarray != NULL)) + if ((kwarraysize > 0) && (kwarray != NULL)) { printf("----------- NUMBER CUSTOM KW = %d ---------------\n", kwarraysize); - for(int kwi = 0; kwi < kwarraysize; kwi++) + for (int kwi = 0; kwi < kwarraysize; kwi++) { char tmpkwvalstr[81]; - switch(kwarray[kwi].type) + switch (kwarray[kwi].type) { - case 'L': - COREMOD_iofits_data.FITSIO_status = 0; - fits_update_key(fptr, TLONG, kwarray[kwi].name, - &kwarray[kwi].value.numl, kwarray[kwi].comment, - &COREMOD_iofits_data.FITSIO_status); - break; - - case 'D': - COREMOD_iofits_data.FITSIO_status = 0; - printf("writing keyword [D] %-8s= %20g / %s\n", kwarray[kwi].name, - kwarray[kwi].value.numf, kwarray[kwi].comment); - fits_update_key(fptr, TDOUBLE, kwarray[kwi].name, - &kwarray[kwi].value.numf, kwarray[kwi].comment, - &COREMOD_iofits_data.FITSIO_status); - break; - - case 'S': - sprintf(tmpkwvalstr, "'%s'", kwarray[kwi].value.valstr); - printf("writing keyword [S] %-8s= %20s / %s\n", kwarray[kwi].name, - tmpkwvalstr, kwarray[kwi].comment); - COREMOD_iofits_data.FITSIO_status = 0; - fits_update_key(fptr, TSTRING, kwarray[kwi].name, - kwarray[kwi].value.valstr, kwarray[kwi].comment, - &COREMOD_iofits_data.FITSIO_status); - break; - - default: - break; + case 'L': + COREMOD_iofits_data.FITSIO_status = 0; + fits_update_key(fptr, TLONG, kwarray[kwi].name, &kwarray[kwi].value.numl, kwarray[kwi].comment, + &COREMOD_iofits_data.FITSIO_status); + break; + + case 'D': + COREMOD_iofits_data.FITSIO_status = 0; + printf("writing keyword [D] %-8s= %20g / %s\n", kwarray[kwi].name, kwarray[kwi].value.numf, + kwarray[kwi].comment); + fits_update_key(fptr, TDOUBLE, kwarray[kwi].name, &kwarray[kwi].value.numf, kwarray[kwi].comment, + &COREMOD_iofits_data.FITSIO_status); + break; + + case 'S': + sprintf(tmpkwvalstr, "'%s'", kwarray[kwi].value.valstr); + printf("writing keyword [S] %-8s= %20s / %s\n", kwarray[kwi].name, tmpkwvalstr, kwarray[kwi].comment); + COREMOD_iofits_data.FITSIO_status = 0; + fits_update_key(fptr, TSTRING, kwarray[kwi].name, kwarray[kwi].value.valstr, kwarray[kwi].comment, + &COREMOD_iofits_data.FITSIO_status); + break; + + default: + break; } - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) { PRINT_ERROR("fits_write_record error on keyword %s", kwarray[kwi].name); abort(); @@ -518,16 +434,13 @@ errno_t saveFITS( } } - - long fpixel = 1; COREMOD_iofits_data.FITSIO_status = 0; - fits_write_img(fptr, FITSIOdatatype, fpixel, nelements, datainptr, - &COREMOD_iofits_data.FITSIO_status); + fits_write_img(fptr, FITSIOdatatype, fpixel, nelements, datainptr, &COREMOD_iofits_data.FITSIO_status); int errcode = check_FITSIO_status(__FILE__, __func__, __LINE__, 1); - if(errcode != 0) + if (errcode != 0) { - if(errcode == 412) + if (errcode == 412) { PRINT_WARNING("data trucated"); } @@ -542,36 +455,30 @@ errno_t saveFITS( COREMOD_iofits_data.FITSIO_status = 0; fits_write_date(fptr, &COREMOD_iofits_data.FITSIO_status); - COREMOD_iofits_data.FITSIO_status = 0; fits_close_file(fptr, &COREMOD_iofits_data.FITSIO_status); - if(check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) + if (check_FITSIO_status(__FILE__, __func__, __LINE__, 1) != 0) { PRINT_ERROR("fits_close_file error on file %s", fnametmp); EXECUTE_SYSTEM_COMMAND("rm %s", fnametmp); FUNC_RETURN_FAILURE(" "); } - EXECUTE_SYSTEM_COMMAND_ERRCHECK("mv %s %s", fnametmp, outputFITSname); DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - - -errno_t saveall_fits( - const char *__restrict savedirname -) +errno_t saveall_fits(const char *__restrict savedirname) { DEBUG_TRACE_FSTART(); char fname[STRINGMAXLEN_FULLFILENAME]; EXECUTE_SYSTEM_COMMAND("mkdir -p %s", savedirname); - for(long i = 0; i < data.NB_MAX_IMAGE; i++) - if(data.image[i].used == 1) + for (long i = 0; i < data.NB_MAX_IMAGE; i++) + if (data.image[i].used == 1) { WRITE_FULLFILENAME(fname, "./%s/%s.fits", savedirname, data.image[i].name); @@ -582,73 +489,43 @@ errno_t saveall_fits( return RETURN_SUCCESS; } - - - -errno_t save_fits( - const char *__restrict savedirname, - const char *__restrict outputFITSname -) +errno_t save_fits(const char *__restrict savedirname, const char *__restrict outputFITSname) { DEBUG_TRACE_FSTART(); - FUNC_CHECK_RETURN( - saveFITS(savedirname, outputFITSname, 0, "", NULL, 0) - ); + FUNC_CHECK_RETURN(saveFITS(savedirname, outputFITSname, 0, "", NULL, 0)); DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - -errno_t save_fl_fits( - const char *__restrict savedirname, - const char *__restrict outputFITSname -) +errno_t save_fl_fits(const char *__restrict savedirname, const char *__restrict outputFITSname) { DEBUG_TRACE_FSTART(); - FUNC_CHECK_RETURN( - saveFITS(savedirname, outputFITSname, -32, "", NULL, 0)); + FUNC_CHECK_RETURN(saveFITS(savedirname, outputFITSname, -32, "", NULL, 0)); DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - -errno_t save_db_fits( - const char *__restrict savedirname, - const char *__restrict outputFITSname -) +errno_t save_db_fits(const char *__restrict savedirname, const char *__restrict outputFITSname) { DEBUG_TRACE_FSTART(); - FUNC_CHECK_RETURN( - saveFITS(savedirname, outputFITSname, -64, "", NULL, 0)); + FUNC_CHECK_RETURN(saveFITS(savedirname, outputFITSname, -64, "", NULL, 0)); DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - - - - - static errno_t compute_function() { DEBUG_TRACE_FSTART(); INSERT_STD_PROCINFO_COMPUTEFUNC_START - saveFITS( - inimname, - outfname, - *outbitpix, - inheader, - NULL, - 0 - ); + saveFITS(inimname, outfname, *outbitpix, inheader, NULL, 0); INSERT_STD_PROCINFO_COMPUTEFUNC_END @@ -656,12 +533,11 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - INSERT_STD_FPSCLIfunctions -// Register function in CLI -errno_t CLIADDCMD_COREMOD_iofits__saveFITS() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_iofits__saveFITS() { INSERT_STD_CLIREGISTERFUNC diff --git a/src/COREMOD_iofits/savefits.h b/src/COREMOD_iofits/savefits.h index 8ccc8f47..34552608 100644 --- a/src/COREMOD_iofits/savefits.h +++ b/src/COREMOD_iofits/savefits.h @@ -2,7 +2,6 @@ * @file savefits.h */ - #ifndef MILK_COREMOD_IOFITS_SAVEFITS_H #define MILK_COREMOD_IOFITS_SAVEFITS_H @@ -10,29 +9,13 @@ errno_t CLIADDCMD_COREMOD_iofits__saveFITS(); +errno_t saveFITS(const char *__restrict inputimname, const char *__restrict outputFITSname, int outputbitpix, + const char *__restrict importheaderfile, IMAGE_KEYWORD *kwarray, int kwarraysize); + +errno_t save_fits(const char *__restrict inputimname, const char *__restrict outputFITSname); + +errno_t save_fl_fits(const char *__restrict inputimname, const char *__restrict outputFITSname); -errno_t saveFITS( - const char *__restrict inputimname, - const char *__restrict outputFITSname, - int outputbitpix, - const char *__restrict importheaderfile, - IMAGE_KEYWORD *kwarray, - int kwarraysize -); - -errno_t save_fits( - const char *__restrict inputimname, - const char *__restrict outputFITSname -); - -errno_t save_fl_fits( - const char *__restrict inputimname, - const char *__restrict outputFITSname -); - -errno_t save_db_fits( - const char *__restrict inputimname, - const char *__restrict outputFITSname -); +errno_t save_db_fits(const char *__restrict inputimname, const char *__restrict outputFITSname); #endif diff --git a/src/COREMOD_memory/COREMOD_memory.c b/src/COREMOD_memory/COREMOD_memory.c index bdf7d91d..81604b90 100644 --- a/src/COREMOD_memory/COREMOD_memory.c +++ b/src/COREMOD_memory/COREMOD_memory.c @@ -6,7 +6,6 @@ * */ - /* ================================================================== */ /* ================================================================== */ /* MODULE INFO */ @@ -19,10 +18,7 @@ #define MODULE_SHORTNAME_DEFAULT "" // Module short description -#define MODULE_DESCRIPTION "Memory management for images and variables" - - - +#define MODULE_DESCRIPTION "Memory management for images and variables" /* =============================================================================================== */ /* =============================================================================================== */ @@ -34,7 +30,6 @@ #include "CommandLineInterface/timeutils.h" - #include "clearall.h" #include "create_image.h" #include "create_variable.h" @@ -51,19 +46,18 @@ #include "image_copy.h" #include "image_copy_shm.h" #include "image_keyword.h" -#include "image_keyword_list.h" #include "image_keyword_addD.h" #include "image_keyword_addL.h" #include "image_keyword_addS.h" +#include "image_keyword_list.h" #include "image_make2D.h" #include "image_make3D.h" +#include "image_mk_amph_from_complex.h" #include "image_mk_complex_from_amph.h" #include "image_mk_complex_from_reim.h" -#include "image_mk_amph_from_complex.h" #include "image_mk_reim_from_complex.h" #include "image_set_counters.h" - #include "list_image.h" #include "list_variable.h" #include "logshmim.h" @@ -78,6 +72,7 @@ #include "saveall.h" #include "shmim_purge.h" #include "shmim_setowner.h" +#include "stream_TCP.h" #include "stream_ave.h" #include "stream_delay.h" #include "stream_diff.h" @@ -87,19 +82,10 @@ #include "stream_pixmapdecode.h" #include "stream_poke.h" #include "stream_sem.h" -#include "stream_TCP.h" #include "stream_updateloop.h" - #include "variable_ID.h" - - - - - - - /* ================================================================== */ /* ================================================================== */ /* INITIALIZE LIBRARY */ @@ -111,17 +97,11 @@ // INIT_MODULE_LIB(COREMOD_memory) - - - - - static errno_t init_module_CLI() { data.MEM_MONITOR = 0; // 1 if memory monitor is on - clearall_addCLIcmd(); list_image_addCLIcmd(); @@ -150,15 +130,12 @@ static errno_t init_module_CLI() CLIADDCMD_COREMOD_memory__delete_image(); CLIADDCMD_COREMOD_memory__delete_sharedmem_image(); - list_variable_addCLIcmd(); // FPS fps_list_addCLIcmd(); fps_create_addCLIcmd(); - - // TYPE CONVERSIONS TO AND FROM COMPLEX CLIADDCMD_COREMOD__mk_complex_from_reim(); CLIADDCMD_COREMOD__mk_complex_from_amph(); @@ -195,9 +172,7 @@ static errno_t init_module_CLI() CLIADDCMD_COREMOD_memory__shmimlog(); CLIADDCMD_COREMOD_memory__shmimlogcmd(); - // add atexit functions here return RETURN_SUCCESS; } - diff --git a/src/COREMOD_memory/COREMOD_memory.h b/src/COREMOD_memory/COREMOD_memory.h index 9ca59774..e8cbd5de 100644 --- a/src/COREMOD_memory/COREMOD_memory.h +++ b/src/COREMOD_memory/COREMOD_memory.h @@ -7,7 +7,6 @@ * */ - #ifndef _COREMODMEMORY_H #define _COREMODMEMORY_H @@ -20,7 +19,6 @@ // it is increased by NB_IMAGES_BUFFER #define NB_IMAGES_BUFFER_REALLOC 600 - // The number of variables in the data structure is kept NB_VARIABLES_BUFFER // above the number of used variables prior to the execution of any function. // It means that no function should create more than 100 variables. @@ -30,8 +28,6 @@ // it is increased by NB_VARIABLES_BUFFER #define NB_VARIABLES_BUFFER_REALLOC 150 - - #include "COREMOD_memory/shmimlog_types.h" #include "COREMOD_memory/clearall.h" @@ -43,25 +39,26 @@ #include "COREMOD_memory/delete_image.h" #include "COREMOD_memory/delete_variable.h" -#include "COREMOD_memory/fps_create.h" #include "COREMOD_memory/fps_ID.h" +#include "COREMOD_memory/fps_create.h" #include "COREMOD_memory/fps_list.h" +#include "COREMOD_memory/image_ID.h" #include "COREMOD_memory/image_checksize.h" #include "COREMOD_memory/image_complex.h" #include "COREMOD_memory/image_copy.h" -#include "COREMOD_memory/image_ID.h" #include "COREMOD_memory/image_keyword.h" #include "COREMOD_memory/image_mk_amph_from_complex.h" -#include "COREMOD_memory/image_mk_reim_from_complex.h" #include "COREMOD_memory/image_mk_complex_from_amph.h" #include "COREMOD_memory/image_mk_complex_from_reim.h" +#include "COREMOD_memory/image_mk_reim_from_complex.h" #include "COREMOD_memory/image_set_counters.h" #include "COREMOD_memory/list_image.h" #include "COREMOD_memory/list_variable.h" #include "COREMOD_memory/logshmim.h" #include "COREMOD_memory/read_shmim.h" #include "COREMOD_memory/saveall.h" +#include "COREMOD_memory/stream_TCP.h" #include "COREMOD_memory/stream_ave.h" #include "COREMOD_memory/stream_delay.h" #include "COREMOD_memory/stream_diff.h" @@ -70,15 +67,10 @@ #include "COREMOD_memory/stream_pixmapdecode.h" #include "COREMOD_memory/stream_poke.h" #include "COREMOD_memory/stream_sem.h" -#include "COREMOD_memory/stream_TCP.h" #include "COREMOD_memory/stream_updateloop.h" #include "COREMOD_memory/variable_ID.h" - - - //errno_t rotate_cube(const char *ID_name, const char *ID_out_name, // int orientation); - #endif diff --git a/src/COREMOD_memory/OBSOLETE_stream_delay.c b/src/COREMOD_memory/OBSOLETE_stream_delay.c index fca71fc2..559b6695 100644 --- a/src/COREMOD_memory/OBSOLETE_stream_delay.c +++ b/src/COREMOD_memory/OBSOLETE_stream_delay.c @@ -4,44 +4,28 @@ #include #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" -#include "stream_sem.h" #include "create_image.h" #include "delete_image.h" +#include "image_ID.h" +#include "stream_sem.h" #include "COREMOD_tools/COREMOD_tools.h" #include "CommandLineInterface/timeutils.h" - - - - - // ========================================== // Forward declaration(s) // ========================================== - - errno_t COREMOD_MEMORY_streamDelay_FPCONF(); errno_t COREMOD_MEMORY_streamDelay_RUN(); - -errno_t COREMOD_MEMORY_streamDelay( - const char *IDin_name, - const char *IDout_name, - long delayus, - long dtus -); - - +errno_t COREMOD_MEMORY_streamDelay(const char *IDin_name, const char *IDout_name, long delayus, long dtus); // ========================================== // Command line interface wrapper function(s) // ========================================== - static errno_t COREMOD_MEMORY_streamDelay__cli() { // Try FPS implementation @@ -52,41 +36,30 @@ static errno_t COREMOD_MEMORY_streamDelay__cli() function_parameter_getFPSargs_from_CLIfunc("streamDelay"); - if(data.FPS_CMDCODE != 0) // use FPS implementation + if (data.FPS_CMDCODE != 0) // use FPS implementation { // set pointers to CONF and RUN functions data.FPS_CONFfunc = COREMOD_MEMORY_streamDelay_FPCONF; - data.FPS_RUNfunc = COREMOD_MEMORY_streamDelay_RUN; + data.FPS_RUNfunc = COREMOD_MEMORY_streamDelay_RUN; function_parameter_execFPScmd(); return RETURN_SUCCESS; } - // non FPS implementation - all parameters specified at function launch - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, 5) - + CLI_checkarg(3, CLIARG_LONG) - + CLI_checkarg(4, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, 5) + CLI_checkarg(3, CLIARG_LONG) + + CLI_checkarg(4, CLIARG_LONG) == + 0) { - COREMOD_MEMORY_streamDelay( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.string, - data.cmdargtoken[3].val.numl, - data.cmdargtoken[4].val.numl - ); + COREMOD_MEMORY_streamDelay(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, + data.cmdargtoken[3].val.numl, data.cmdargtoken[4].val.numl); return CLICMD_SUCCESS; } else { return CLICMD_INVALID_ARG; } - } - - // ========================================== // Register CLI command(s) // ========================================== @@ -95,26 +68,13 @@ errno_t stream_delay_addCLIcmd() { RegisterCLIcommand( - "streamdelay", - __FILE__, - COREMOD_MEMORY_streamDelay__cli, - "delay 2D image stream", - " ", - "streamdelay instream outstream 1000 10", + "streamdelay", __FILE__, COREMOD_MEMORY_streamDelay__cli, "delay 2D image stream", + " ", "streamdelay instream outstream 1000 10", "long COREMOD_MEMORY_streamDelay(const char *IDin_name, const char *IDout_name, long delayus, long dtus)"); return RETURN_SUCCESS; } - - - - - - - - - /** * @brief Manages configuration parameters for streamDelay * @@ -145,50 +105,36 @@ errno_t COREMOD_MEMORY_streamDelay_FPCONF() FPFLAG = FPFLAG_DEFAULT_INPUT | FPFLAG_MINLIMIT; FPFLAG &= ~FPFLAG_WRITERUN; - long delayus_default[4] = { 1000, 1, 10000, 1000 }; + long delayus_default[4] = {1000, 1, 10000, 1000}; long fp_delayus = 0; - function_parameter_add_entry(&fps, ".delayus", "Delay [us]", - FPTYPE_INT64, FPFLAG, &delayus_default, &fp_delayus); - (void) fp_delayus; // suppresses unused parameter compiler warning - - long dtus_default[4] = { 50, 1, 200, 50 }; - long fp_dtus = 0; - function_parameter_add_entry(&fps, ".dtus", - "Loop period [us]", FPTYPE_INT64, FPFLAG, &dtus_default, &fp_dtus); - (void) fp_dtus; // suppresses unused parameter compiler warning + function_parameter_add_entry(&fps, ".delayus", "Delay [us]", FPTYPE_INT64, FPFLAG, &delayus_default, &fp_delayus); + (void)fp_delayus; // suppresses unused parameter compiler warning + long dtus_default[4] = {50, 1, 200, 50}; + long fp_dtus = 0; + function_parameter_add_entry(&fps, ".dtus", "Loop period [us]", FPTYPE_INT64, FPFLAG, &dtus_default, &fp_dtus); + (void)fp_dtus; // suppresses unused parameter compiler warning - FPS_ADDPARAM_STREAM_IN(stream_inname, ".in_name", "input stream", NULL); + FPS_ADDPARAM_STREAM_IN(stream_inname, ".in_name", "input stream", NULL); FPS_ADDPARAM_STREAM_OUT(stream_outname, ".out_name", "output stream"); - long timeavemode_default[4] = { 0, 0, 3, 0 }; - FPS_ADDPARAM_INT64_IN( - option_timeavemode, - ".option.timeavemode", - "Enable time window averaging (>0)", - &timeavemode_default); + long timeavemode_default[4] = {0, 0, 3, 0}; + FPS_ADDPARAM_INT64_IN(option_timeavemode, ".option.timeavemode", "Enable time window averaging (>0)", + &timeavemode_default); - double avedt_default[4] = { 0.001, 0.0001, 1.0, 0.001}; - FPS_ADDPARAM_FLT64_IN( - option_avedt, - ".option.avedt", - "Averaging time window width", - &avedt_default); + double avedt_default[4] = {0.001, 0.0001, 1.0, 0.001}; + FPS_ADDPARAM_FLT64_IN(option_avedt, ".option.avedt", "Averaging time window width", &avedt_default); // status - FPS_ADDPARAM_INT64_OUT(zsize, ".status.zsize", "cube size"); + FPS_ADDPARAM_INT64_OUT(zsize, ".status.zsize", "cube size"); FPS_ADDPARAM_INT64_OUT(framelog, ".status.framelag", "lag in frame unit"); FPS_ADDPARAM_INT64_OUT(kkin, ".status.kkin", "input cube slice index"); FPS_ADDPARAM_INT64_OUT(kkout, ".status.kkout", "output cube slice index"); - - - // start function parameter conf loop, defined in function_parameter.h FPS_CONFLOOP_START - - if(fps.parray[fp_option_timeavemode].val.i64[0] != 0) + if (fps.parray[fp_option_timeavemode].val.i64[0] != 0) { // time averaging enabled fps.parray[fp_option_avedt].fpflag |= FPFLAG_WRITERUN; @@ -202,27 +148,12 @@ errno_t COREMOD_MEMORY_streamDelay_FPCONF() fps.parray[fp_option_avedt].fpflag &= ~FPFLAG_VISIBLE; } - // stop function parameter conf loop, defined in function_parameter.h FPS_CONFLOOP_END - return RETURN_SUCCESS; } - - - - - - - - - - - - - /** * @brief Delay image stream by time offset * @@ -232,26 +163,24 @@ errno_t COREMOD_MEMORY_streamDelay_FPCONF() errno_t COREMOD_MEMORY_streamDelay_RUN() { - imageID IDimc; - imageID IDin, IDout; - uint32_t xsize, ysize, xysize; + imageID IDimc; + imageID IDin, IDout; + uint32_t xsize, ysize, xysize; // long cnt0old; - long ii; - struct timespec *t0array; - struct timespec tnow; - double tdiffv; - struct timespec tdiff; - uint32_t *arraytmp; - long cntskip = 0; - long kk; - + long ii; + struct timespec *t0array; + struct timespec tnow; + double tdiffv; + struct timespec tdiff; + uint32_t *arraytmp; + long cntskip = 0; + long kk; // =========================== /// ### CONNECT TO FPS // =========================== FPS_CONNECT(data.FPS_name, FPSCONNECT_RUN); - // =============================== /// ### GET FUNCTION PARAMETER VALUES // =============================== @@ -259,25 +188,22 @@ errno_t COREMOD_MEMORY_streamDelay_RUN() // These parameters are read once, before running the loop // char IDin_name[FUNCTION_PARAMETER_STRMAXLEN]; - strncpy(IDin_name, functionparameter_GetParamPtr_STRING(&fps, ".in_name"), - FUNCTION_PARAMETER_STRMAXLEN - 1); + strncpy(IDin_name, functionparameter_GetParamPtr_STRING(&fps, ".in_name"), FUNCTION_PARAMETER_STRMAXLEN - 1); char IDout_name[FUNCTION_PARAMETER_STRMAXLEN]; - strncpy(IDout_name, functionparameter_GetParamPtr_STRING(&fps, ".out_name"), - FUNCTION_PARAMETER_STRMAXLEN - 1); + strncpy(IDout_name, functionparameter_GetParamPtr_STRING(&fps, ".out_name"), FUNCTION_PARAMETER_STRMAXLEN - 1); long delayus = functionparameter_GetParamValue_INT64(&fps, ".delayus"); - long dtus = functionparameter_GetParamValue_INT64(&fps, ".dtus"); + long dtus = functionparameter_GetParamValue_INT64(&fps, ".dtus"); - int timeavemode = functionparameter_GetParamValue_INT64(&fps, - ".option.timeavemode"); - double *avedt = functionparameter_GetParamPtr_FLOAT64(&fps, ".option.avedt"); + int timeavemode = functionparameter_GetParamValue_INT64(&fps, ".option.timeavemode"); + double *avedt = functionparameter_GetParamPtr_FLOAT64(&fps, ".option.avedt"); - long *zsize = functionparameter_GetParamPtr_INT64(&fps, ".status.zsize"); + long *zsize = functionparameter_GetParamPtr_INT64(&fps, ".status.zsize"); long *framelag = functionparameter_GetParamPtr_INT64(&fps, ".status.framelag"); - long *kkin = functionparameter_GetParamPtr_INT64(&fps, ".status.kkin"); - long *kkout = functionparameter_GetParamPtr_INT64(&fps, ".status.kkout"); + long *kkin = functionparameter_GetParamPtr_INT64(&fps, ".status.kkin"); + long *kkout = functionparameter_GetParamPtr_INT64(&fps, ".status.kkout"); DEBUG_TRACEPOINT(" "); @@ -288,12 +214,10 @@ errno_t COREMOD_MEMORY_streamDelay_RUN() char pinfodescr[200]; sprintf(pinfodescr, "streamdelay %.10s %.10s", IDin_name, IDout_name); - processinfo = processinfo_setup( - data.FPS_name, // re-use fpsname as processinfo name - pinfodescr, // description - "startup", // message on startup - __FUNCTION__, __FILE__, __LINE__ - ); + processinfo = processinfo_setup(data.FPS_name, // re-use fpsname as processinfo name + pinfodescr, // description + "startup", // message on startup + __FUNCTION__, __FILE__, __LINE__); // OPTIONAL SETTINGS // Measure timing @@ -301,24 +225,18 @@ errno_t COREMOD_MEMORY_streamDelay_RUN() // RT_priority, 0-99. Larger number = higher priority. If <0, ignore processinfo->RT_priority = 20; - fps_to_processinfo(&fps, processinfo); - - // ============================================= /// ### OPTIONAL: TESTING CONDITION FOR LOOP ENTRY // ============================================= // Pre-loop testing, anything that would prevent loop from starting should issue message int loopOK = 1; - IDin = image_ID(IDin_name); - - // ERROR HANDLING - if(IDin == -1) + if (IDin == -1) { struct timespec errtime; struct tm *errtm; @@ -326,15 +244,8 @@ errno_t COREMOD_MEMORY_streamDelay_RUN() clock_gettime(CLOCK_REALTIME, &errtime); errtm = gmtime(&errtime.tv_sec); - fprintf(stderr, - "%02d:%02d:%02d.%09ld ERROR [%s %s %d] Input stream %s does not exist, cannot proceed\n", - errtm->tm_hour, - errtm->tm_min, - errtm->tm_sec, - errtime.tv_nsec, - __FILE__, - __FUNCTION__, - __LINE__, + fprintf(stderr, "%02d:%02d:%02d.%09ld ERROR [%s %s %d] Input stream %s does not exist, cannot proceed\n", + errtm->tm_hour, errtm->tm_min, errtm->tm_sec, errtime.tv_nsec, __FILE__, __FUNCTION__, __LINE__, IDin_name); char msgstring[200]; @@ -343,26 +254,23 @@ errno_t COREMOD_MEMORY_streamDelay_RUN() loopOK = 0; } - xsize = data.image[IDin].md[0].size[0]; ysize = data.image[IDin].md[0].size[1]; *zsize = (long)(2 * delayus / dtus); - if(*zsize < 1) + if (*zsize < 1) { *zsize = 1; } xysize = xsize * ysize; - t0array = (struct timespec *) malloc(sizeof(struct timespec) * *zsize); + t0array = (struct timespec *)malloc(sizeof(struct timespec) * *zsize); create_3Dimage_ID("_tmpc", xsize, ysize, *zsize, &IDimc); - - IDout = image_ID(IDout_name); - if(IDout == -1) // CREATE IT + if (IDout == -1) // CREATE IT { - arraytmp = (uint32_t *) malloc(sizeof(uint32_t) * 2); + arraytmp = (uint32_t *)malloc(sizeof(uint32_t) * 2); arraytmp[0] = xsize; arraytmp[1] = ysize; create_image_ID(IDout_name, 2, arraytmp, _DATATYPE_FLOAT, 1, 0, 0, &IDout); @@ -370,47 +278,41 @@ errno_t COREMOD_MEMORY_streamDelay_RUN() free(arraytmp); } - *kkin = 0; *kkout = 0; -// cnt0old = data.image[IDin].md[0].cnt0; + // cnt0old = data.image[IDin].md[0].cnt0; float *arraytmpf; - arraytmpf = (float *) malloc(sizeof(float) * xsize * ysize); + arraytmpf = (float *)malloc(sizeof(float) * xsize * ysize); clock_gettime(CLOCK_REALTIME, &tnow); - for(kk = 0; kk < *zsize; kk++) + for (kk = 0; kk < *zsize; kk++) { t0array[kk] = tnow; } - DEBUG_TRACEPOINT(" "); - // Specify input stream trigger - processinfo_waitoninputstream_init(processinfo, IDin, - PROCESSINFO_TRIGGERMODE_DELAY, -1); + processinfo_waitoninputstream_init(processinfo, IDin, PROCESSINFO_TRIGGERMODE_DELAY, -1); processinfo->triggerdelay.tv_sec = 0; processinfo->triggerdelay.tv_nsec = (long)(dtus * 1000); - while(processinfo->triggerdelay.tv_nsec > 1000000000) + while (processinfo->triggerdelay.tv_nsec > 1000000000) { processinfo->triggerdelay.tv_nsec -= 1000000000; processinfo->triggerdelay.tv_sec += 1; } - // =========================== /// ### START LOOP // =========================== - processinfo_loopstart( - processinfo); // Notify processinfo that we are entering loop + processinfo_loopstart(processinfo); // Notify processinfo that we are entering loop DEBUG_TRACEPOINT(" "); - while(loopOK == 1) + while (loopOK == 1) { int kkinscan; float normframes = 0.0; @@ -418,53 +320,48 @@ errno_t COREMOD_MEMORY_streamDelay_RUN() DEBUG_TRACEPOINT(" "); loopOK = processinfo_loopstep(processinfo); - processinfo_waitoninputstream(processinfo); //usleep(dtus); // main loop wait processinfo_exec_start(processinfo); - if(processinfo_compute_status(processinfo) == 1) + if (processinfo_compute_status(processinfo) == 1) { DEBUG_TRACEPOINT(" "); // has new frame arrived ? -// cnt0 = data.image[IDin].md[0].cnt0; + // cnt0 = data.image[IDin].md[0].cnt0; -// if(cnt0 != cnt0old) { // new frame - clock_gettime(CLOCK_REALTIME, &t0array[*kkin]); // record time of input frame + // if(cnt0 != cnt0old) { // new frame + clock_gettime(CLOCK_REALTIME, &t0array[*kkin]); // record time of input frame DEBUG_TRACEPOINT(" "); - for(ii = 0; ii < xysize; ii++) + for (ii = 0; ii < xysize; ii++) { data.image[IDimc].array.F[(*kkin) * xysize + ii] = data.image[IDin].array.F[ii]; } - (*kkin) ++; + (*kkin)++; DEBUG_TRACEPOINT(" "); - if((*kkin) == (*zsize)) + if ((*kkin) == (*zsize)) { (*kkin) = 0; } - - clock_gettime(CLOCK_REALTIME, &tnow); DEBUG_TRACEPOINT(" "); - cntskip = 0; tdiff = timespec_diff(t0array[*kkout], tnow); tdiffv = 1.0 * tdiff.tv_sec + 1.0e-9 * tdiff.tv_nsec; DEBUG_TRACEPOINT(" "); - - while((tdiffv > 1.0e-6 * delayus) && (cntskip < *zsize)) + while ((tdiffv > 1.0e-6 * delayus) && (cntskip < *zsize)) { - cntskip++; // advance index until time condition is satisfied - (*kkout) ++; - if(*kkout == *zsize) + cntskip++; // advance index until time condition is satisfied + (*kkout)++; + if (*kkout == *zsize) { *kkout = 0; } @@ -475,85 +372,80 @@ errno_t COREMOD_MEMORY_streamDelay_RUN() DEBUG_TRACEPOINT(" "); *framelag = *kkin - *kkout; - if(*framelag < 0) + if (*framelag < 0) { *framelag += *zsize; } - DEBUG_TRACEPOINT(" "); - - switch(timeavemode) + switch (timeavemode) { - case 0: // no time averaging - pick more recent frame that matches requirement - DEBUG_TRACEPOINT(" "); - if(cntskip > 0) - { - char *ptr; // pointer address + case 0: // no time averaging - pick more recent frame that matches requirement + DEBUG_TRACEPOINT(" "); + if (cntskip > 0) + { + char *ptr; // pointer address - data.image[IDout].md[0].write = 1; + data.image[IDout].md[0].write = 1; - ptr = (char *) data.image[IDimc].array.F; - ptr += SIZEOF_DATATYPE_FLOAT * xysize * *kkout; + ptr = (char *)data.image[IDimc].array.F; + ptr += SIZEOF_DATATYPE_FLOAT * xysize * *kkout; - memcpy(data.image[IDout].array.F, ptr, - SIZEOF_DATATYPE_FLOAT * xysize); // copy time-delayed input to output + memcpy(data.image[IDout].array.F, ptr, + SIZEOF_DATATYPE_FLOAT * xysize); // copy time-delayed input to output - COREMOD_MEMORY_image_set_sempost_byID(IDout, -1); - data.image[IDout].md[0].cnt0++; - data.image[IDout].md[0].write = 0; - } - break; + COREMOD_MEMORY_image_set_sempost_byID(IDout, -1); + data.image[IDout].md[0].cnt0++; + data.image[IDout].md[0].write = 0; + } + break; - default : // strict time window (note: other modes will be coded in the future) - normframes = 0.0; - DEBUG_TRACEPOINT(" "); + default: // strict time window (note: other modes will be coded in the future) + normframes = 0.0; + DEBUG_TRACEPOINT(" "); - for(ii = 0; ii < xysize; ii++) - { - arraytmpf[ii] = 0.0; - } + for (ii = 0; ii < xysize; ii++) + { + arraytmpf[ii] = 0.0; + } - for(kkinscan = 0; kkinscan < *zsize; kkinscan++) - { - tdiff = timespec_diff(t0array[kkinscan], tnow); - tdiffv = 1.0 * tdiff.tv_sec + 1.0e-9 * tdiff.tv_nsec; + for (kkinscan = 0; kkinscan < *zsize; kkinscan++) + { + tdiff = timespec_diff(t0array[kkinscan], tnow); + tdiffv = 1.0 * tdiff.tv_sec + 1.0e-9 * tdiff.tv_nsec; - if((tdiffv > 0) && (fabs(tdiffv - 1.0e-6 * delayus) < *avedt)) + if ((tdiffv > 0) && (fabs(tdiffv - 1.0e-6 * delayus) < *avedt)) + { + float coeff = 1.0; + for (ii = 0; ii < xysize; ii++) { - float coeff = 1.0; - for(ii = 0; ii < xysize; ii++) - { - arraytmpf[ii] += coeff * data.image[IDimc].array.F[kkinscan * xysize + ii]; - } - normframes += coeff; + arraytmpf[ii] += coeff * data.image[IDimc].array.F[kkinscan * xysize + ii]; } + normframes += coeff; } - if(normframes < 0.0001) - { - normframes = 0.0001; // avoid division by zero - } + } + if (normframes < 0.0001) + { + normframes = 0.0001; // avoid division by zero + } - data.image[IDout].md[0].write = 1; - for(ii = 0; ii < xysize; ii++) - { - data.image[IDout].array.F[ii] = arraytmpf[ii] / normframes; - } + data.image[IDout].md[0].write = 1; + for (ii = 0; ii < xysize; ii++) + { + data.image[IDout].array.F[ii] = arraytmpf[ii] / normframes; + } - processinfo_update_output_stream(processinfo, IDout); - /* + processinfo_update_output_stream(processinfo, IDout); + /* COREMOD_MEMORY_image_set_sempost_byID(IDout, -1); data.image[IDout].md[0].cnt0++; data.image[IDout].md[0].write = 0; */ - break; + break; } DEBUG_TRACEPOINT(" "); - - - } // process signals, increment loop counter processinfo_exec_end(processinfo); @@ -579,23 +471,7 @@ errno_t COREMOD_MEMORY_streamDelay_RUN() return IDout; } - - - - - - - - - - - -errno_t COREMOD_MEMORY_streamDelay( - const char *IDin_name, - const char *IDout_name, - long delayus, - long dtus -) +errno_t COREMOD_MEMORY_streamDelay(const char *IDin_name, const char *IDout_name, long delayus, long dtus) { char fpsname[200]; unsigned int pindex = 0; @@ -621,9 +497,3 @@ errno_t COREMOD_MEMORY_streamDelay( return RETURN_SUCCESS; } - - - - - - diff --git a/src/COREMOD_memory/OBSOLETE_stream_delay.h b/src/COREMOD_memory/OBSOLETE_stream_delay.h index 245fd031..d04d806e 100644 --- a/src/COREMOD_memory/OBSOLETE_stream_delay.h +++ b/src/COREMOD_memory/OBSOLETE_stream_delay.h @@ -1,17 +1,6 @@ /** @file stream_delay,h */ - - - errno_t stream_delay_addCLIcmd(); - - - -errno_t COREMOD_MEMORY_streamDelay( - const char *IDin_name, - const char *IDout_name, - long delayus, - long dtus -); +errno_t COREMOD_MEMORY_streamDelay(const char *IDin_name, const char *IDout_name, long delayus, long dtus); diff --git a/src/COREMOD_memory/README.md b/src/COREMOD_memory/README.md index c2aa0ba4..ac89fd3b 100644 --- a/src/COREMOD_memory/README.md +++ b/src/COREMOD_memory/README.md @@ -3,4 +3,3 @@ # Module COREMOD_memory {#page_module_COREMOD_memory} Memory management for images - diff --git a/src/COREMOD_memory/clearall.c b/src/COREMOD_memory/clearall.c index aedce040..9dd9c158 100644 --- a/src/COREMOD_memory/clearall.c +++ b/src/COREMOD_memory/clearall.c @@ -1,12 +1,10 @@ /** @file clearall.c */ - #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" #include "delete_image.h" #include "delete_variable.h" - +#include "image_ID.h" // ========================================== // Forward declaration(s) @@ -14,15 +12,10 @@ errno_t clearall(); - // ========================================== // Command line interface wrapper function(s) // ========================================== - - - - // ========================================== // Register CLI command(s) // ========================================== @@ -30,41 +23,28 @@ errno_t clearall(); errno_t clearall_addCLIcmd() { - RegisterCLIcommand( - "rmall", - __FILE__, - clearall, - "remove all images", - "no argument", - "rmall", - "int clearall()"); - + RegisterCLIcommand("rmall", __FILE__, clearall, "remove all images", "no argument", "rmall", "int clearall()"); return RETURN_SUCCESS; } - - - - - errno_t clearall() { imageID ID; // clear images - for(ID = 0; ID < data.NB_MAX_IMAGE; ID++) + for (ID = 0; ID < data.NB_MAX_IMAGE; ID++) { - if(data.image[ID].used == 1) + if (data.image[ID].used == 1) { delete_image_ID(data.image[ID].name, DELETE_IMAGE_ERRMODE_WARNING); } } // clear variables - for(ID = 0; ID < data.NB_MAX_VARIABLE; ID++) + for (ID = 0; ID < data.NB_MAX_VARIABLE; ID++) { - if(data.variable[ID].used == 1) + if (data.variable[ID].used == 1) { delete_variable_ID(data.variable[ID].name); } @@ -72,23 +52,19 @@ errno_t clearall() // clear FPS - for(int fpsindex = 0; fpsindex < data.NB_MAX_FPS; fpsindex++) + for (int fpsindex = 0; fpsindex < data.NB_MAX_FPS; fpsindex++) { DEBUG_TRACEPOINT("clear FPS %d", fpsindex); data.fpsarray[fpsindex].SMfd = -1; - if(data.fpsarray[fpsindex].parray != NULL) + if (data.fpsarray[fpsindex].parray != NULL) { data.fpsarray[fpsindex].parray = NULL; } - if(data.fpsarray[fpsindex].md != NULL) + if (data.fpsarray[fpsindex].md != NULL) { data.fpsarray[fpsindex].md = NULL; } } - return RETURN_SUCCESS; } - - - diff --git a/src/COREMOD_memory/clearall.h b/src/COREMOD_memory/clearall.h index f393d6f8..61652b80 100644 --- a/src/COREMOD_memory/clearall.h +++ b/src/COREMOD_memory/clearall.h @@ -1,8 +1,6 @@ /** @file clearall.h */ - errno_t clearall_addCLIcmd(); - -errno_t clearall(); +errno_t clearall(); diff --git a/src/COREMOD_memory/compute_image_memory.c b/src/COREMOD_memory/compute_image_memory.c index a9a33595..b6f6190d 100644 --- a/src/COREMOD_memory/compute_image_memory.c +++ b/src/COREMOD_memory/compute_image_memory.c @@ -2,25 +2,20 @@ * @file compute_image_memory.c */ - - #include "CommandLineInterface/CLIcore.h" - - uint64_t compute_image_memory() { uint64_t totalmem = 0; - for(imageID i = 0; i < data.NB_MAX_IMAGE; i++) + for (imageID i = 0; i < data.NB_MAX_IMAGE; i++) { //printf("%5ld / %5ld %d\n", i, data.NB_MAX_IMAGE, data.image[i].used); // fflush(stdout); - if(data.image[i].used == 1) + if (data.image[i].used == 1) { - totalmem += data.image[i].md[0].nelement * - ImageStreamIO_typesize(data.image[i].md[0].datatype); + totalmem += data.image[i].md[0].nelement * ImageStreamIO_typesize(data.image[i].md[0].datatype); } } diff --git a/src/COREMOD_memory/compute_image_memory.h b/src/COREMOD_memory/compute_image_memory.h index a04ff71d..322c2aef 100644 --- a/src/COREMOD_memory/compute_image_memory.h +++ b/src/COREMOD_memory/compute_image_memory.h @@ -2,5 +2,4 @@ * @file compute_image_memory.h */ - uint64_t compute_image_memory(); diff --git a/src/COREMOD_memory/compute_nb_image.c b/src/COREMOD_memory/compute_nb_image.c index 8ba04197..7c5fc119 100644 --- a/src/COREMOD_memory/compute_nb_image.c +++ b/src/COREMOD_memory/compute_nb_image.c @@ -2,20 +2,18 @@ * @file compute_nb_image.c */ - #include "CommandLineInterface/CLIcore.h" - long compute_nb_image() { long NBimage = 0; - //printf("NB_MAX_IMAGE = %d\n", data.NB_MAX_IMAGE); - //fflush(stdout); + //printf("NB_MAX_IMAGE = %d\n", data.NB_MAX_IMAGE); + //fflush(stdout); - for(imageID i = 0; i < data.NB_MAX_IMAGE; i++) + for (imageID i = 0; i < data.NB_MAX_IMAGE; i++) { - if(data.image[i].used == 1) + if (data.image[i].used == 1) { NBimage += 1; } diff --git a/src/COREMOD_memory/compute_nb_image.h b/src/COREMOD_memory/compute_nb_image.h index df051f89..d6b15bc8 100644 --- a/src/COREMOD_memory/compute_nb_image.h +++ b/src/COREMOD_memory/compute_nb_image.h @@ -2,4 +2,4 @@ * @file compute_nb_image.h */ -long compute_nb_image(); +long compute_nb_image(); diff --git a/src/COREMOD_memory/compute_nb_variable.c b/src/COREMOD_memory/compute_nb_variable.c index 54c4a8a1..96aab9b7 100644 --- a/src/COREMOD_memory/compute_nb_variable.c +++ b/src/COREMOD_memory/compute_nb_variable.c @@ -2,18 +2,15 @@ * @file compute_nb_variable.c */ - #include "CommandLineInterface/CLIcore.h" - - long compute_nb_variable() { long NBvar = 0; - for(variableID i = 0; i < data.NB_MAX_VARIABLE; i++) + for (variableID i = 0; i < data.NB_MAX_VARIABLE; i++) { - if(data.variable[i].used == 1) + if (data.variable[i].used == 1) { NBvar += 1; } diff --git a/src/COREMOD_memory/compute_nb_variable.h b/src/COREMOD_memory/compute_nb_variable.h index cdd1df06..f0289d6f 100644 --- a/src/COREMOD_memory/compute_nb_variable.h +++ b/src/COREMOD_memory/compute_nb_variable.h @@ -2,4 +2,4 @@ * @file compute_nb_variable.h */ -long compute_nb_variable(); +long compute_nb_variable(); diff --git a/src/COREMOD_memory/create_image.c b/src/COREMOD_memory/create_image.c index b39fb63d..91d011fe 100644 --- a/src/COREMOD_memory/create_image.c +++ b/src/COREMOD_memory/create_image.c @@ -3,36 +3,22 @@ * @brief create images and streams */ - #include "CommandLineInterface/CLIcore.h" #include "image_ID.h" #include "list_image.h" #include "stream_sem.h" - - // ========================================== // forward declarations // ========================================== -errno_t create_image_ID( - const char *name, - long naxis, - uint32_t *size, - uint8_t datatype, - int shared, - int nbkw, - int CBsize, - imageID *outID -); - - +errno_t create_image_ID(const char *name, long naxis, uint32_t *size, uint8_t datatype, int shared, int nbkw, + int CBsize, imageID *outID); // ========================================== // command line interface wrapper functions // ========================================== - static errno_t create_image__cli() { uint32_t *imsize; @@ -40,93 +26,86 @@ static errno_t create_image__cli() long i; uint8_t datatype; - - - if(0 - + CLI_checkarg(1, CLIARG_STR_NOT_IMG) - + CLI_checkarg_noerrmsg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_STR_NOT_IMG) + CLI_checkarg_noerrmsg(2, CLIARG_LONG) == 0) { naxis = 0; - imsize = (uint32_t *) malloc(sizeof(uint32_t) * 5); + imsize = (uint32_t *)malloc(sizeof(uint32_t) * 5); i = 2; - while(data.cmdargtoken[i].type == 2) + while (data.cmdargtoken[i].type == 2) { imsize[naxis] = data.cmdargtoken[i].val.numl; naxis++; i++; } - switch(data.precision) + switch (data.precision) { case 0: - create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_FLOAT, - data.SHARED_DFT, data.NBKEYWORD_DFT, 0, NULL); + create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_FLOAT, data.SHARED_DFT, + data.NBKEYWORD_DFT, 0, NULL); break; case 1: - create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_DOUBLE, - data.SHARED_DFT, data.NBKEYWORD_DFT, 0, NULL); + create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_DOUBLE, data.SHARED_DFT, + data.NBKEYWORD_DFT, 0, NULL); break; } free(imsize); return CLICMD_SUCCESS; } - else if(0 - + CLI_checkarg(1, CLIARG_STR_NOT_IMG) - + CLI_checkarg(2, CLIARG_STR_NOT_IMG) - + CLI_checkarg(3, CLIARG_LONG) - == 0) // type option exists + else if (0 + CLI_checkarg(1, CLIARG_STR_NOT_IMG) + CLI_checkarg(2, CLIARG_STR_NOT_IMG) + + CLI_checkarg(3, CLIARG_LONG) == + 0) // type option exists { datatype = 0; - if(strcmp(data.cmdargtoken[2].val.string, "c") == 0) + if (strcmp(data.cmdargtoken[2].val.string, "c") == 0) { printf("type = CHAR\n"); datatype = _DATATYPE_UINT8; } - if(strcmp(data.cmdargtoken[2].val.string, "i") == 0) + if (strcmp(data.cmdargtoken[2].val.string, "i") == 0) { printf("type = INT\n"); datatype = _DATATYPE_INT32; } - if(strcmp(data.cmdargtoken[2].val.string, "f") == 0) + if (strcmp(data.cmdargtoken[2].val.string, "f") == 0) { printf("type = FLOAT\n"); datatype = _DATATYPE_FLOAT; } - if(strcmp(data.cmdargtoken[2].val.string, "d") == 0) + if (strcmp(data.cmdargtoken[2].val.string, "d") == 0) { printf("type = DOUBLE\n"); datatype = _DATATYPE_DOUBLE; } - if(strcmp(data.cmdargtoken[2].val.string, "cf") == 0) + if (strcmp(data.cmdargtoken[2].val.string, "cf") == 0) { printf("type = COMPLEX_FLOAT\n"); datatype = _DATATYPE_COMPLEX_FLOAT; } - if(strcmp(data.cmdargtoken[2].val.string, "cd") == 0) + if (strcmp(data.cmdargtoken[2].val.string, "cd") == 0) { printf("type = COMPLEX_DOUBLE\n"); datatype = _DATATYPE_COMPLEX_DOUBLE; } - if(strcmp(data.cmdargtoken[2].val.string, "u") == 0) + if (strcmp(data.cmdargtoken[2].val.string, "u") == 0) { printf("type = USHORT\n"); datatype = _DATATYPE_UINT16; } - if(strcmp(data.cmdargtoken[2].val.string, "l") == 0) + if (strcmp(data.cmdargtoken[2].val.string, "l") == 0) { printf("type = LONG\n"); datatype = _DATATYPE_INT64; } - if(datatype == 0) + if (datatype == 0) { printf("Data type \"%s\" not recognized\n", data.cmdargtoken[2].val.string); printf("must be : \n"); @@ -141,17 +120,17 @@ static errno_t create_image__cli() return CLICMD_INVALID_ARG; } naxis = 0; - imsize = (uint32_t *) malloc(sizeof(uint32_t) * 5); + imsize = (uint32_t *)malloc(sizeof(uint32_t) * 5); i = 3; - while(data.cmdargtoken[i].type == 2) + while (data.cmdargtoken[i].type == 2) { imsize[naxis] = data.cmdargtoken[i].val.numl; naxis++; i++; } - create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, datatype, - data.SHARED_DFT, data.NBKEYWORD_DFT, 0, NULL); + create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, datatype, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, + NULL); free(imsize); return CLICMD_SUCCESS; @@ -162,45 +141,37 @@ static errno_t create_image__cli() } } - - - static errno_t create_image_shared__cli() // default precision { uint32_t *imsize; long naxis = 0; long i; - - if(0 - + CLI_checkarg(1, CLIARG_STR_NOT_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_STR_NOT_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { naxis = 0; - imsize = (uint32_t *) malloc(sizeof(uint32_t) * 5); + imsize = (uint32_t *)malloc(sizeof(uint32_t) * 5); i = 2; - while(data.cmdargtoken[i].type == 2) + while (data.cmdargtoken[i].type == 2) { imsize[naxis] = data.cmdargtoken[i].val.numl; naxis++; i++; } - switch(data.precision) + switch (data.precision) { case 0: - create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_FLOAT, - 1, data.NBKEYWORD_DFT, 0, NULL); + create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_FLOAT, 1, data.NBKEYWORD_DFT, 0, + NULL); break; case 1: - create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_DOUBLE, - 1, data.NBKEYWORD_DFT, 0, NULL); + create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_DOUBLE, 1, data.NBKEYWORD_DFT, 0, + NULL); break; } free(imsize); printf("Creating 10 semaphores\n"); - COREMOD_MEMORY_image_set_createsem(data.cmdargtoken[1].val.string, - IMAGE_NB_SEMAPHORE); + COREMOD_MEMORY_image_set_createsem(data.cmdargtoken[1].val.string, IMAGE_NB_SEMAPHORE); return CLICMD_SUCCESS; } else @@ -209,32 +180,25 @@ static errno_t create_image_shared__cli() // default precision } } - - - static errno_t create_ushort_image_shared__cli() // default precision { uint32_t *imsize; long naxis = 0; long i; - - if(0 - + CLI_checkarg(1, CLIARG_STR_NOT_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_STR_NOT_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { naxis = 0; - imsize = (uint32_t *) malloc(sizeof(uint32_t) * 5); + imsize = (uint32_t *)malloc(sizeof(uint32_t) * 5); i = 2; - while(data.cmdargtoken[i].type == 2) + while (data.cmdargtoken[i].type == 2) { imsize[naxis] = data.cmdargtoken[i].val.numl; naxis++; i++; } - create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_UINT16, - 1, data.NBKEYWORD_DFT, 0, NULL); + create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_UINT16, 1, data.NBKEYWORD_DFT, 0, + NULL); free(imsize); return CLICMD_SUCCESS; @@ -251,23 +215,18 @@ static errno_t create_sshort_image_shared__cli() // default precision long naxis = 0; long i; - - if(0 - + CLI_checkarg(1, CLIARG_STR_NOT_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_STR_NOT_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { naxis = 0; - imsize = (uint32_t *) malloc(sizeof(uint32_t) * 5); + imsize = (uint32_t *)malloc(sizeof(uint32_t) * 5); i = 2; - while(data.cmdargtoken[i].type == 2) + while (data.cmdargtoken[i].type == 2) { imsize[naxis] = data.cmdargtoken[i].val.numl; naxis++; i++; } - create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_INT16, - 1, data.NBKEYWORD_DFT, 0, NULL); + create_image_ID(data.cmdargtoken[1].val.string, naxis, imsize, _DATATYPE_INT16, 1, data.NBKEYWORD_DFT, 0, NULL); free(imsize); return CLICMD_SUCCESS; @@ -278,9 +237,6 @@ static errno_t create_sshort_image_shared__cli() // default precision } } - - - static errno_t create_3Dimage_float() { DEBUG_TRACE_FSTART(); @@ -289,14 +245,14 @@ static errno_t create_3Dimage_float() // CHECK ARGS // printf("CREATING 3D IMAGE\n"); - imsize = (uint32_t *) malloc(sizeof(uint32_t) * 3); + imsize = (uint32_t *)malloc(sizeof(uint32_t) * 3); imsize[0] = data.cmdargtoken[2].val.numl; imsize[1] = data.cmdargtoken[3].val.numl; imsize[2] = data.cmdargtoken[4].val.numl; - create_image_ID(data.cmdargtoken[1].val.string, 3, imsize, _DATATYPE_FLOAT, - data.SHARED_DFT, data.NBKEYWORD_DFT, 0, NULL); + create_image_ID(data.cmdargtoken[1].val.string, 3, imsize, _DATATYPE_FLOAT, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, + NULL); free(imsize); @@ -304,14 +260,6 @@ static errno_t create_3Dimage_float() return RETURN_SUCCESS; } - - - - - - - - // ========================================== // Register CLI commands // ========================================== @@ -320,133 +268,77 @@ errno_t create_image_addCLIcmd() { RegisterCLIcommand( - "creaim", - __FILE__, - create_image__cli, - "create image, default precision", - " ", + "creaim", __FILE__, create_image__cli, "create image, default precision", " ", "creaim imname 512 512", "long create_image_ID(const char *name, long naxis, uint32_t *size, uint8_t datatype, 0, 10, NULL)"); RegisterCLIcommand( - "creaimshm", - __FILE__, create_image_shared__cli, - "create image in shared mem, default precision", - " ", - "creaimshm imname 512 512", + "creaimshm", __FILE__, create_image_shared__cli, "create image in shared mem, default precision", + " ", "creaimshm imname 512 512", "long create_image_ID(const char *name, long naxis, uint32_t *size, uint8_t datatype, 0, 10, NULL)"); - RegisterCLIcommand( - "creaushortimshm", - __FILE__, - create_ushort_image_shared__cli, - "create unsigned short image in shared mem", - " ", - "creaushortimshm imname 512 512", - "long create_image_ID(const char *name, long naxis, long *size, _DATATYPE_UINT16, 0, 10, NULL)"); - - RegisterCLIcommand( - "creasshortimshm", - __FILE__, - create_sshort_image_shared__cli, - "create signed short image in shared mem", - " ", - "creasshortimshm imname 512 512", - "long create_image_ID(const char *name, long naxis, long *size, _DATATYPE_INT16, 0, 10, NULL)"); - - RegisterCLIcommand( - "crea3dim", - __FILE__, - create_3Dimage_float, - "creates 3D image, single precision", - " ", - "crea3dim imname 512 512 100", - "long create_image_ID(const char *name, long naxis, long *size, _DATATYPE_FLOAT, 0, 10, NULL)"); + RegisterCLIcommand("creaushortimshm", __FILE__, create_ushort_image_shared__cli, + "create unsigned short image in shared mem", " ", + "creaushortimshm imname 512 512", + "long create_image_ID(const char *name, long naxis, long *size, _DATATYPE_UINT16, 0, 10, NULL)"); + RegisterCLIcommand("creasshortimshm", __FILE__, create_sshort_image_shared__cli, + "create signed short image in shared mem", " ", + "creasshortimshm imname 512 512", + "long create_image_ID(const char *name, long naxis, long *size, _DATATYPE_INT16, 0, 10, NULL)"); + RegisterCLIcommand("crea3dim", __FILE__, create_3Dimage_float, "creates 3D image, single precision", + " ", "crea3dim imname 512 512 100", + "long create_image_ID(const char *name, long naxis, long *size, _DATATYPE_FLOAT, 0, 10, NULL)"); return RETURN_SUCCESS; } - - - - - - - /* creates an image ID */ /* all images should be created by this function */ -errno_t create_image_ID( - const char *name, - long naxis, - uint32_t *size, - uint8_t datatype, - int shared, - int NBkw, - int CBsize, - imageID *outID -) +errno_t create_image_ID(const char *name, long naxis, uint32_t *size, uint8_t datatype, int shared, int NBkw, + int CBsize, imageID *outID) { DEBUG_TRACE_FSTART(); - DEBUG_TRACEPOINT( - "FARG %s %ld %d %d %d %d", - name, - naxis, - (int) datatype, - shared, - NBkw, - CBsize - ); + DEBUG_TRACEPOINT("FARG %s %ld %d %d %d %d", name, naxis, (int)datatype, shared, NBkw, CBsize); imageID ID; - ID = -1; - if(image_ID(name) == -1) + if (image_ID(name) == -1) { ID = next_avail_image_ID(); - ImageStreamIO_createIm( - &data.image[ID], - name, - naxis, - size, - datatype, - shared, - NBkw, - CBsize - ); + ImageStreamIO_createIm(&data.image[ID], name, naxis, size, datatype, shared, NBkw, CBsize); } else { // Cannot create image : name already in use ID = image_ID(name); - if(data.image[ID].md[0].datatype != datatype) + if (data.image[ID].md[0].datatype != datatype) { FUNC_RETURN_FAILURE("Pre-existing image \"%s\" has wrong type", name); } - if(data.image[ID].md[0].naxis != naxis) + if (data.image[ID].md[0].naxis != naxis) { FUNC_RETURN_FAILURE("Pre-existing image \"%s\" has wrong naxis", name); } - for(int i = 0; i < naxis; i++) - if(data.image[ID].md[0].size[i] != size[i]) + for (int i = 0; i < naxis; i++) + if (data.image[ID].md[0].size[i] != size[i]) { - FUNC_RETURN_FAILURE( - "Pre-existing image \"%s\" has wrong size: axis %d : %ld %ld", - name, i, (long) data.image[ID].md[0].size[i], (long) size[i]); + FUNC_RETURN_FAILURE("Pre-existing image \"%s\" has wrong size: axis %d : %ld %ld", name, i, + (long)data.image[ID].md[0].size[i], (long)size[i]); } } - if(data.MEM_MONITOR == 1) + if (data.MEM_MONITOR == 1) { list_image_ID_ncurses(); } - if(outID != NULL) + if (outID != NULL) { *outID = ID; } @@ -455,14 +347,7 @@ errno_t create_image_ID( return RETURN_SUCCESS; } - - - -errno_t create_1Dimage_ID( - const char *ID_name, - uint32_t xsize, - imageID *outID -) +errno_t create_1Dimage_ID(const char *ID_name, uint32_t xsize, imageID *outID) { DEBUG_TRACE_FSTART(); @@ -472,21 +357,18 @@ errno_t create_1Dimage_ID( naxes[0] = xsize; - if(data.precision == 0) - { // single precision + if (data.precision == 0) + { // single precision FUNC_CHECK_RETURN( - create_image_ID( - ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID)); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); } - if(data.precision == 1) - { // double precision + if (data.precision == 1) + { // double precision FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_DOUBLE, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID)); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_DOUBLE, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); } - if(outID != NULL) + if (outID != NULL) { *outID = ID; } @@ -495,13 +377,7 @@ errno_t create_1Dimage_ID( return RETURN_SUCCESS; } - - -errno_t create_1DCimage_ID( - const char *ID_name, - uint32_t xsize, - imageID *outID -) +errno_t create_1DCimage_ID(const char *ID_name, uint32_t xsize, imageID *outID) { DEBUG_TRACE_FSTART(); @@ -511,20 +387,18 @@ errno_t create_1DCimage_ID( naxes[0] = xsize; - if(data.precision == 0) - { // single precision - FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_FLOAT, - data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); + if (data.precision == 0) + { // single precision + FUNC_CHECK_RETURN(create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_FLOAT, data.SHARED_DFT, + data.NBKEYWORD_DFT, 0, &ID)); } - if(data.precision == 1) - { // double precision - FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_DOUBLE, - data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); + if (data.precision == 1) + { // double precision + FUNC_CHECK_RETURN(create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_DOUBLE, data.SHARED_DFT, + data.NBKEYWORD_DFT, 0, &ID)); } - if(outID != NULL) + if (outID != NULL) { *outID = ID; } @@ -533,14 +407,7 @@ errno_t create_1DCimage_ID( return RETURN_SUCCESS; } - - -errno_t create_2Dimage_ID( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - imageID *outID -) +errno_t create_2Dimage_ID(const char *ID_name, uint32_t xsize, uint32_t ysize, imageID *outID) { DEBUG_TRACE_FSTART(); @@ -551,28 +418,24 @@ errno_t create_2Dimage_ID( naxes[0] = xsize; naxes[1] = ysize; - if(data.precision == 0) - { // single precision + if (data.precision == 0) + { // single precision FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID)); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); } - else if(data.precision == 1) - { // double precision + else if (data.precision == 1) + { // double precision FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_DOUBLE, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID)); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_DOUBLE, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); } else - { // single precision - printf("Default precision (%d) invalid value: assuming single precision\n", - data.precision); + { // single precision + printf("Default precision (%d) invalid value: assuming single precision\n", data.precision); FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID)); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); } - if(outID != NULL) + if (outID != NULL) { *outID = ID; } @@ -581,15 +444,7 @@ errno_t create_2Dimage_ID( return RETURN_SUCCESS; } - - - -errno_t create_2Dimage_ID_double( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - imageID *outID -) +errno_t create_2Dimage_ID_double(const char *ID_name, uint32_t xsize, uint32_t ysize, imageID *outID) { DEBUG_TRACE_FSTART(); @@ -601,10 +456,9 @@ errno_t create_2Dimage_ID_double( naxes[1] = ysize; FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_DOUBLE, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID)); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_DOUBLE, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); - if(outID != NULL) + if (outID != NULL) { *outID = ID; } @@ -613,14 +467,8 @@ errno_t create_2Dimage_ID_double( return RETURN_SUCCESS; } - /* 2D complex image */ -errno_t create_2DCimage_ID( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - imageID *outID -) +errno_t create_2DCimage_ID(const char *ID_name, uint32_t xsize, uint32_t ysize, imageID *outID) { DEBUG_TRACE_FSTART(); @@ -631,20 +479,18 @@ errno_t create_2DCimage_ID( naxes[0] = xsize; naxes[1] = ysize; - if(data.precision == 0) - { // single precision - FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_FLOAT, - data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); + if (data.precision == 0) + { // single precision + FUNC_CHECK_RETURN(create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_FLOAT, data.SHARED_DFT, + data.NBKEYWORD_DFT, 0, &ID)); } - if(data.precision == 1) - { // double precision - FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_DOUBLE, - data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); + if (data.precision == 1) + { // double precision + FUNC_CHECK_RETURN(create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_DOUBLE, data.SHARED_DFT, + data.NBKEYWORD_DFT, 0, &ID)); } - if(outID != NULL) + if (outID != NULL) { *outID = ID; } @@ -653,15 +499,8 @@ errno_t create_2DCimage_ID( return RETURN_SUCCESS; } - - /* 2D complex image */ -errno_t create_2DCimage_ID_double( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - imageID *outID -) +errno_t create_2DCimage_ID_double(const char *ID_name, uint32_t xsize, uint32_t ysize, imageID *outID) { DEBUG_TRACE_FSTART(); @@ -673,10 +512,9 @@ errno_t create_2DCimage_ID_double( naxes[1] = ysize; FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_DOUBLE, - data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_DOUBLE, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); - if(outID != NULL) + if (outID != NULL) { *outID = ID; } @@ -685,16 +523,8 @@ errno_t create_2DCimage_ID_double( return RETURN_SUCCESS; } - - /* 3D image, single precision */ -errno_t create_3Dimage_ID_float( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize, - imageID *outID -) +errno_t create_3Dimage_ID_float(const char *ID_name, uint32_t xsize, uint32_t ysize, uint32_t zsize, imageID *outID) { DEBUG_TRACE_FSTART(); @@ -710,13 +540,12 @@ errno_t create_3Dimage_ID_float( // fflush(stdout); FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID)); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); // printf("IMAGE CREATED WITH ID = %ld\n",ID); // fflush(stdout); - if(outID != NULL) + if (outID != NULL) { *outID = ID; } @@ -725,15 +554,8 @@ errno_t create_3Dimage_ID_float( return RETURN_SUCCESS; } - /* 3D image, double precision */ -errno_t create_3Dimage_ID_double( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize, - imageID *outID -) +errno_t create_3Dimage_ID_double(const char *ID_name, uint32_t xsize, uint32_t ysize, uint32_t zsize, imageID *outID) { DEBUG_TRACE_FSTART(); @@ -746,10 +568,9 @@ errno_t create_3Dimage_ID_double( naxes[2] = zsize; FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_DOUBLE, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID)); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_DOUBLE, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); - if(outID != NULL) + if (outID != NULL) { *outID = ID; } @@ -758,16 +579,8 @@ errno_t create_3Dimage_ID_double( return RETURN_SUCCESS; } - - /* 3D image, default precision */ -errno_t create_3Dimage_ID( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize, - imageID *outID -) +errno_t create_3Dimage_ID(const char *ID_name, uint32_t xsize, uint32_t ysize, uint32_t zsize, imageID *outID) { DEBUG_TRACE_FSTART(); @@ -775,29 +588,26 @@ errno_t create_3Dimage_ID( long naxis = 3; uint32_t *naxes; - - naxes = (uint32_t *) malloc(sizeof(uint32_t) * 3); + naxes = (uint32_t *)malloc(sizeof(uint32_t) * 3); naxes[0] = xsize; naxes[1] = ysize; naxes[2] = zsize; - if(data.precision == 0) - { // single precision + if (data.precision == 0) + { // single precision FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID)); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_FLOAT, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); } - if(data.precision == 1) - { // double precision + if (data.precision == 1) + { // double precision FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_DOUBLE, data.SHARED_DFT, - data.NBKEYWORD_DFT, 0, &ID)); + create_image_ID(ID_name, naxis, naxes, _DATATYPE_DOUBLE, data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); } free(naxes); - if(outID != NULL) + if (outID != NULL) { *outID = ID; } @@ -806,15 +616,8 @@ errno_t create_3Dimage_ID( return RETURN_SUCCESS; } - /* 3D complex image */ -errno_t create_3DCimage_ID( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize, - imageID *outID -) +errno_t create_3DCimage_ID(const char *ID_name, uint32_t xsize, uint32_t ysize, uint32_t zsize, imageID *outID) { DEBUG_TRACE_FSTART(); @@ -822,28 +625,26 @@ errno_t create_3DCimage_ID( long naxis = 3; uint32_t *naxes; - - naxes = (uint32_t *) malloc(sizeof(uint32_t) * 3); + naxes = (uint32_t *)malloc(sizeof(uint32_t) * 3); naxes[0] = xsize; naxes[1] = ysize; naxes[2] = zsize; - if(data.precision == 0) - { // single precision - FUNC_CHECK_RETURN( - create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_FLOAT, - data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); + if (data.precision == 0) + { // single precision + FUNC_CHECK_RETURN(create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_FLOAT, data.SHARED_DFT, + data.NBKEYWORD_DFT, 0, &ID)); } - if(data.precision == 1) - { // double precision - FUNC_CHECK_RETURN(create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_DOUBLE, - data.SHARED_DFT, data.NBKEYWORD_DFT, 0, &ID)); + if (data.precision == 1) + { // double precision + FUNC_CHECK_RETURN(create_image_ID(ID_name, naxis, naxes, _DATATYPE_COMPLEX_DOUBLE, data.SHARED_DFT, + data.NBKEYWORD_DFT, 0, &ID)); } free(naxes); - if(outID != NULL) + if (outID != NULL) { *outID = ID; } @@ -851,9 +652,3 @@ errno_t create_3DCimage_ID( DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - - - - - - diff --git a/src/COREMOD_memory/create_image.h b/src/COREMOD_memory/create_image.h index c935791f..7891e369 100644 --- a/src/COREMOD_memory/create_image.h +++ b/src/COREMOD_memory/create_image.h @@ -2,99 +2,27 @@ * @file create_image.h */ - - - - - - errno_t create_image_addCLIcmd(); +errno_t create_image_ID(const char *name, long naxis, uint32_t *size, uint8_t datatype, int shared, int nbkw, + int CBsize, imageID *outID); +errno_t create_1Dimage_ID(const char *ID_name, uint32_t xsize, imageID *outID); +errno_t create_1DCimage_ID(const char *ID_name, uint32_t xsize, imageID *outID); +errno_t create_2Dimage_ID(const char *ID_name, uint32_t xsize, uint32_t ysize, imageID *outID); -errno_t create_image_ID( - const char *name, - long naxis, - uint32_t *size, - uint8_t datatype, - int shared, - int nbkw, - int CBsize, - imageID *outID -); - - - -errno_t create_1Dimage_ID( - const char *ID_name, - uint32_t xsize, - imageID *outID -); - -errno_t create_1DCimage_ID( - const char *ID_name, - uint32_t xsize, - imageID *outID -); - -errno_t create_2Dimage_ID( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - imageID *outID -); - -errno_t create_2Dimage_ID_double( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - imageID *outID -); +errno_t create_2Dimage_ID_double(const char *ID_name, uint32_t xsize, uint32_t ysize, imageID *outID); -errno_t create_2DCimage_ID( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - imageID *outID -); +errno_t create_2DCimage_ID(const char *ID_name, uint32_t xsize, uint32_t ysize, imageID *outID); -errno_t create_2DCimage_ID_double( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - imageID *outID -); +errno_t create_2DCimage_ID_double(const char *ID_name, uint32_t xsize, uint32_t ysize, imageID *outID); -errno_t create_3Dimage_ID( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize, - imageID *outID -); +errno_t create_3Dimage_ID(const char *ID_name, uint32_t xsize, uint32_t ysize, uint32_t zsize, imageID *outID); -errno_t create_3Dimage_ID_float( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize, - imageID *outID -); +errno_t create_3Dimage_ID_float(const char *ID_name, uint32_t xsize, uint32_t ysize, uint32_t zsize, imageID *outID); -errno_t create_3Dimage_ID_double( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize, - imageID *outID -); +errno_t create_3Dimage_ID_double(const char *ID_name, uint32_t xsize, uint32_t ysize, uint32_t zsize, imageID *outID); -errno_t create_3DCimage_ID( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize, - imageID *outID -); +errno_t create_3DCimage_ID(const char *ID_name, uint32_t xsize, uint32_t ysize, uint32_t zsize, imageID *outID); diff --git a/src/COREMOD_memory/create_variable.c b/src/COREMOD_memory/create_variable.c index 4519d446..fcbf728f 100644 --- a/src/COREMOD_memory/create_variable.c +++ b/src/COREMOD_memory/create_variable.c @@ -1,22 +1,14 @@ /** * @file create_variable.c - * @brief create variables + * @brief create variables */ - #include "CommandLineInterface/CLIcore.h" -#include "variable_ID.h" #include "image_ID.h" - - - - +#include "variable_ID.h" /* creates floating point variable */ -variableID create_variable_ID( - const char *name, - double value -) +variableID create_variable_ID(const char *name, double value) { variableID ID; long i1, i2; @@ -29,18 +21,16 @@ variableID create_variable_ID( i1 = image_ID(name); //printf("TEST %s %ld %ld %ld ================== \n", __FILE__, __LINE__, data.NB_MAX_IMAGE, data.NB_MAX_VARIABLE); - i2 = variable_ID(name); // printf("TEST %s %ld %ld %ld ================== \n", __FILE__, __LINE__, data.NB_MAX_IMAGE, data.NB_MAX_VARIABLE); - if(i1 != -1) + if (i1 != -1) { - printf("ERROR: cannot create variable \"%s\": name already used as an image\n", - name); + printf("ERROR: cannot create variable \"%s\": name already used as an image\n", name); } else { - if(i2 != -1) + if (i2 != -1) { // printf("Warning : variable name \"%s\" is already in use\n",name); ID = i2; @@ -54,19 +44,13 @@ variableID create_variable_ID( data.variable[ID].type = 0; /** floating point double */ strcpy(data.variable[ID].name, name); data.variable[ID].value.f = value; - } // printf("TEST %s %ld %ld %ld ================== \n", __FILE__, __LINE__, data.NB_MAX_IMAGE, data.NB_MAX_VARIABLE); return ID; } - - /* creates long variable */ -variableID create_variable_long_ID( - const char *name, - long value -) +variableID create_variable_long_ID(const char *name, long value) { variableID ID; long i1, i2; @@ -75,14 +59,13 @@ variableID create_variable_long_ID( i1 = image_ID(name); i2 = variable_ID(name); - if(i1 != -1) + if (i1 != -1) { - printf("ERROR: cannot create variable \"%s\": name already used as an image\n", - name); + printf("ERROR: cannot create variable \"%s\": name already used as an image\n", name); } else { - if(i2 != -1) + if (i2 != -1) { // printf("Warning : variable name \"%s\" is already in use\n",name); ID = i2; @@ -96,19 +79,13 @@ variableID create_variable_long_ID( data.variable[ID].type = 1; /** long */ strcpy(data.variable[ID].name, name); data.variable[ID].value.l = value; - } return ID; } - - /* creates long variable */ -variableID create_variable_string_ID( - const char *name, - const char *value -) +variableID create_variable_string_ID(const char *name, const char *value) { variableID ID; long i1, i2; @@ -117,14 +94,13 @@ variableID create_variable_string_ID( i1 = image_ID(name); i2 = variable_ID(name); - if(i1 != -1) + if (i1 != -1) { - printf("ERROR: cannot create variable \"%s\": name already used as an image\n", - name); + printf("ERROR: cannot create variable \"%s\": name already used as an image\n", name); } else { - if(i2 != -1) + if (i2 != -1) { // printf("Warning : variable name \"%s\" is already in use\n",name); ID = i2; @@ -142,14 +118,3 @@ variableID create_variable_string_ID( return ID; } - - - - - - - - - - - diff --git a/src/COREMOD_memory/create_variable.h b/src/COREMOD_memory/create_variable.h index aace42cf..8e43a026 100644 --- a/src/COREMOD_memory/create_variable.h +++ b/src/COREMOD_memory/create_variable.h @@ -2,23 +2,8 @@ * @file create_variable.h */ +variableID create_variable_ID(const char *name, double value); +variableID create_variable_long_ID(const char *name, long value); - - -variableID create_variable_ID( - const char *name, - double value -); - -variableID create_variable_long_ID( - const char *name, - long value -); - -variableID create_variable_string_ID( - const char *name, - const char *value -); - - +variableID create_variable_string_ID(const char *name, const char *value); diff --git a/src/COREMOD_memory/delete_image.c b/src/COREMOD_memory/delete_image.c index ccb670bf..f94bf46b 100644 --- a/src/COREMOD_memory/delete_image.c +++ b/src/COREMOD_memory/delete_image.c @@ -6,71 +6,28 @@ #include #include - #include "CommandLineInterface/CLIcore.h" #include "image_ID.h" #include "list_image.h" - - // Forward declaration(s) -errno_t delete_image_ID( - const char *__restrict imname, - int errmode -); - - - - - +errno_t delete_image_ID(const char *__restrict imname, int errmode); // CLI function arguments and parameters static char *imname; static long *errmode; - - - // CLI function arguments and parameters -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".imname", "image name", "im", - CLIARG_VISIBLE_DEFAULT, - (void **) &imname, NULL - }, - { - CLIARG_LONG, ".errmode", "errors mode \n(0:ignore) (1:warning) (2:error) (3:exit)", "1", - CLIARG_HIDDEN_DEFAULT, - (void **) &errmode, NULL - } -}; - - +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".imname", "image name", "im", CLIARG_VISIBLE_DEFAULT, (void **)&imname, NULL}, + {CLIARG_LONG, ".errmode", "errors mode \n(0:ignore) (1:warning) (2:error) (3:exit)", "1", CLIARG_HIDDEN_DEFAULT, + (void **)&errmode, NULL}}; // CLI function initialization data -static CLICMDDATA CLIcmddata = -{ - "rm", - "remove image", - CLICMD_FIELDS_DEFAULTS -}; - - +static CLICMDDATA CLIcmddata = {"rm", "remove image", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - - - - - - - - +static errno_t help_function() { return RETURN_SUCCESS; } static errno_t compute_function() { @@ -78,12 +35,7 @@ static errno_t compute_function() INSERT_STD_PROCINFO_COMPUTEFUNC_START - FUNC_CHECK_RETURN( - delete_image_ID( - imname, - (int) *errmode - ) - ); + FUNC_CHECK_RETURN(delete_image_ID(imname, (int)*errmode)); INSERT_STD_PROCINFO_COMPUTEFUNC_END @@ -91,15 +43,11 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - - - INSERT_STD_FPSCLIfunctions - -// Register function in CLI -errno_t CLIADDCMD_COREMOD_memory__delete_image() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_memory__delete_image() { //INSERT_STD_FPSCLIREGISTERFUNC @@ -109,15 +57,6 @@ errno_t CLIADDCMD_COREMOD_memory__delete_image() return RETURN_SUCCESS; } - - - - - - - - - /** @brief deletes an ID * * errmode values: @@ -127,43 +66,38 @@ errno_t CLIADDCMD_COREMOD_memory__delete_image() * DELETE_IMAGE_ERRMODE_EXIT * */ -errno_t delete_image_ID( - const char *__restrict imname, - int errmode -) +errno_t delete_image_ID(const char *__restrict imname, int errmode) { DEBUG_TRACE_FSTART(); imageID ID; - long s; - char fname[STRINGMAXLEN_FULLFILENAME]; + long s; + char fname[STRINGMAXLEN_FULLFILENAME]; ID = image_ID(imname); - if(ID == -1) + if (ID == -1) { - if(errmode == DELETE_IMAGE_ERRMODE_IGNORE) + if (errmode == DELETE_IMAGE_ERRMODE_IGNORE) { DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - if(errmode == DELETE_IMAGE_ERRMODE_WARNING) + if (errmode == DELETE_IMAGE_ERRMODE_WARNING) { - PRINT_WARNING("Image \"%s\" does not exist", - imname); + PRINT_WARNING("Image \"%s\" does not exist", imname); DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - if(errmode == DELETE_IMAGE_ERRMODE_ERROR) + if (errmode == DELETE_IMAGE_ERRMODE_ERROR) { - PRINT_WARNING("Image \"%s\" does not exist", - imname); + PRINT_WARNING("Image \"%s\" does not exist", imname); FUNC_RETURN_FAILURE("Image \"%s\" does not exist", imname); } - if(errmode == DELETE_IMAGE_ERRMODE_EXIT) + if (errmode == DELETE_IMAGE_ERRMODE_EXIT) { abort(); } @@ -173,9 +107,9 @@ errno_t delete_image_ID( { data.image[ID].used = 0; - if(data.image[ID].md[0].shared == 1) + if (data.image[ID].md[0].shared == 1) { - for(s = 0; s < data.image[ID].md[0].sem; s++) + for (s = 0; s < data.image[ID].md[0].sem; s++) { sem_close(data.image[ID].semptr[s]); } @@ -183,17 +117,15 @@ errno_t delete_image_ID( free(data.image[ID].semptr); data.image[ID].semptr = NULL; - - if(data.image[ID].semlog != NULL) + if (data.image[ID].semlog != NULL) { sem_close(data.image[ID].semlog); data.image[ID].semlog = NULL; } - if(munmap(data.image[ID].md, data.image[ID].memsize) == -1) + if (munmap(data.image[ID].md, data.image[ID].memsize) == -1) { - printf("unmapping ID %ld : %p %ld\n", ID, data.image[ID].md, - data.image[ID].memsize); + printf("unmapping ID %ld : %p %ld\n", ID, data.image[ID].md, data.image[ID].memsize); perror("Error un-mmapping the file"); } @@ -205,68 +137,65 @@ errno_t delete_image_ID( data.image[ID].memsize = 0; - if(data.rmSHMfile == 1) // remove files from disk + if (data.rmSHMfile == 1) // remove files from disk { - EXECUTE_SYSTEM_COMMAND("rm /dev/shm/sem.%s.%s_sem*", - data.shmsemdirname, imname); - WRITE_FULLFILENAME(fname, "/dev/shm/sem.%s.%s_semlog", data.shmsemdirname, - imname); + EXECUTE_SYSTEM_COMMAND("rm /dev/shm/sem.%s.%s_sem*", data.shmsemdirname, imname); + WRITE_FULLFILENAME(fname, "/dev/shm/sem.%s.%s_semlog", data.shmsemdirname, imname); remove(fname); EXECUTE_SYSTEM_COMMAND("rm %s/%s.im.shm", data.shmdir, imname); } - } else { - if(data.image[ID].md[0].datatype == _DATATYPE_UINT8) + if (data.image[ID].md[0].datatype == _DATATYPE_UINT8) { - if(data.image[ID].array.UI8 == NULL) + if (data.image[ID].array.UI8 == NULL) { FUNC_RETURN_FAILURE("data array pointer is null"); } free(data.image[ID].array.UI8); data.image[ID].array.UI8 = NULL; } - if(data.image[ID].md[0].datatype == _DATATYPE_INT32) + if (data.image[ID].md[0].datatype == _DATATYPE_INT32) { - if(data.image[ID].array.SI32 == NULL) + if (data.image[ID].array.SI32 == NULL) { FUNC_RETURN_FAILURE("data array pointer is null"); } free(data.image[ID].array.SI32); data.image[ID].array.SI32 = NULL; } - if(data.image[ID].md[0].datatype == _DATATYPE_FLOAT) + if (data.image[ID].md[0].datatype == _DATATYPE_FLOAT) { - if(data.image[ID].array.F == NULL) + if (data.image[ID].array.F == NULL) { FUNC_RETURN_FAILURE("data array pointer is null"); } free(data.image[ID].array.F); data.image[ID].array.F = NULL; } - if(data.image[ID].md[0].datatype == _DATATYPE_DOUBLE) + if (data.image[ID].md[0].datatype == _DATATYPE_DOUBLE) { - if(data.image[ID].array.D == NULL) + if (data.image[ID].array.D == NULL) { FUNC_RETURN_FAILURE("data array pointer is null"); } free(data.image[ID].array.D); data.image[ID].array.D = NULL; } - if(data.image[ID].md[0].datatype == _DATATYPE_COMPLEX_FLOAT) + if (data.image[ID].md[0].datatype == _DATATYPE_COMPLEX_FLOAT) { - if(data.image[ID].array.CF == NULL) + if (data.image[ID].array.CF == NULL) { FUNC_RETURN_FAILURE("data array pointer is null"); } free(data.image[ID].array.CF); data.image[ID].array.CF = NULL; } - if(data.image[ID].md[0].datatype == _DATATYPE_COMPLEX_DOUBLE) + if (data.image[ID].md[0].datatype == _DATATYPE_COMPLEX_DOUBLE) { - if(data.image[ID].array.CD == NULL) + if (data.image[ID].array.CD == NULL) { FUNC_RETURN_FAILURE("data array pointer is null"); } @@ -274,28 +203,25 @@ errno_t delete_image_ID( data.image[ID].array.CD = NULL; } - if(data.image[ID].md == NULL) + if (data.image[ID].md == NULL) { FUNC_RETURN_FAILURE("data array pointer is null"); } free(data.image[ID].md); data.image[ID].md = NULL; - - if(data.image[ID].kw != NULL) + if (data.image[ID].kw != NULL) { free(data.image[ID].kw); data.image[ID].kw = NULL; } - } //free(data.image[ID].logstatus); /* free(data.image[ID].size);*/ // data.image[ID].md[0].last_access = 0; } - - if(data.MEM_MONITOR == 1) + if (data.MEM_MONITOR == 1) { list_image_ID_ncurses(); } @@ -304,19 +230,15 @@ errno_t delete_image_ID( return RETURN_SUCCESS; } - - // delete all images with a prefix -errno_t delete_image_ID_prefix( - const char *prefix -) +errno_t delete_image_ID_prefix(const char *prefix) { imageID i; - for(i = 0; i < data.NB_MAX_IMAGE; i++) + for (i = 0; i < data.NB_MAX_IMAGE; i++) { - if(data.image[i].used == 1) - if((strncmp(prefix, data.image[i].name, strlen(prefix))) == 0) + if (data.image[i].used == 1) + if ((strncmp(prefix, data.image[i].name, strlen(prefix))) == 0) { printf("deleting image %s\n", data.image[i].name); delete_image_ID(data.image[i].name, DELETE_IMAGE_ERRMODE_IGNORE); @@ -324,6 +246,3 @@ errno_t delete_image_ID_prefix( } return RETURN_SUCCESS; } - - - diff --git a/src/COREMOD_memory/delete_image.h b/src/COREMOD_memory/delete_image.h index 681b6646..37986343 100644 --- a/src/COREMOD_memory/delete_image.h +++ b/src/COREMOD_memory/delete_image.h @@ -1,21 +1,15 @@ #ifndef MILK_COREMOD_MEMORY_DELETE_IMAGE_H #define MILK_COREMOD_MEMORY_DELETE_IMAGE_H - -#define DELETE_IMAGE_ERRMODE_IGNORE 0 +#define DELETE_IMAGE_ERRMODE_IGNORE 0 #define DELETE_IMAGE_ERRMODE_WARNING 1 -#define DELETE_IMAGE_ERRMODE_ERROR 2 -#define DELETE_IMAGE_ERRMODE_EXIT 3 +#define DELETE_IMAGE_ERRMODE_ERROR 2 +#define DELETE_IMAGE_ERRMODE_EXIT 3 errno_t CLIADDCMD_COREMOD_memory__delete_image(); -errno_t delete_image_ID( - const char *imname, - int errmode -); +errno_t delete_image_ID(const char *imname, int errmode); -errno_t delete_image_ID_prefix( - const char *prefix -); +errno_t delete_image_ID_prefix(const char *prefix); #endif diff --git a/src/COREMOD_memory/delete_sharedmem_image.c b/src/COREMOD_memory/delete_sharedmem_image.c index 1d7ed525..c9df065d 100644 --- a/src/COREMOD_memory/delete_sharedmem_image.c +++ b/src/COREMOD_memory/delete_sharedmem_image.c @@ -6,88 +6,49 @@ #include #include - #include "CommandLineInterface/CLIcore.h" #include "image_ID.h" #include "list_image.h" - - // CLI function arguments and parameters static char *imname; - - - // CLI function arguments and parameters -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".imname", "image name", "im", - CLIARG_VISIBLE_DEFAULT, - (void **) &imname, NULL - } -}; - - +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".imname", "image name", "im", CLIARG_VISIBLE_DEFAULT, (void **)&imname, NULL}}; // CLI function initialization data -static CLICMDDATA CLIcmddata = -{ - "rmshmim", - "remove shared image and files", - CLICMD_FIELDS_DEFAULTS -}; - - +static CLICMDDATA CLIcmddata = {"rmshmim", "remove shared image and files", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - - +static errno_t help_function() { return RETURN_SUCCESS; } - -errno_t destroy_shared_image_ID( - const char *__restrict imname -) +errno_t destroy_shared_image_ID(const char *__restrict imname) { imageID ID; ID = image_ID(imname); - if((ID != -1) && (data.image[ID].md[0].shared == 1)) + if ((ID != -1) && (data.image[ID].md[0].shared == 1)) { ImageStreamIO_destroyIm(&data.image[ID]); } else { - fprintf(stderr, - "%c[%d;%dm WARNING: shared image %s does not exist [ %s %s %d ] %c[%d;m\n", - (char) 27, 1, 31, imname, __FILE__, __func__, __LINE__, (char) 27, 0); + fprintf(stderr, "%c[%d;%dm WARNING: shared image %s does not exist [ %s %s %d ] %c[%d;m\n", (char)27, 1, 31, + imname, __FILE__, __func__, __LINE__, (char)27, 0); } return RETURN_SUCCESS; } - - - - - static errno_t compute_function() { DEBUG_TRACE_FSTART(); INSERT_STD_PROCINFO_COMPUTEFUNC_START - FUNC_CHECK_RETURN( - destroy_shared_image_ID( - imname - ) - ); + FUNC_CHECK_RETURN(destroy_shared_image_ID(imname)); INSERT_STD_PROCINFO_COMPUTEFUNC_END @@ -95,15 +56,11 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - - - INSERT_STD_FPSCLIfunctions - -// Register function in CLI -errno_t CLIADDCMD_COREMOD_memory__delete_sharedmem_image() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_memory__delete_sharedmem_image() { //INSERT_STD_FPSCLIREGISTERFUNC diff --git a/src/COREMOD_memory/delete_sharedmem_image.h b/src/COREMOD_memory/delete_sharedmem_image.h index 5ce79c25..a0397f65 100644 --- a/src/COREMOD_memory/delete_sharedmem_image.h +++ b/src/COREMOD_memory/delete_sharedmem_image.h @@ -1,11 +1,8 @@ #ifndef MILK_COREMOD_MEMORY_DELETE_SHAREDMEM_IMAGE_H #define MILK_COREMOD_MEMORY_DELETE_SHAREDMEM_IMAGE_H - errno_t CLIADDCMD_COREMOD_memory__delete_sharedmem_image(); -errno_t destroy_shared_image_ID( - const char *__restrict imname -); +errno_t destroy_shared_image_ID(const char *__restrict imname); #endif diff --git a/src/COREMOD_memory/delete_variable.c b/src/COREMOD_memory/delete_variable.c index 65d1f0a7..98cb0a13 100644 --- a/src/COREMOD_memory/delete_variable.c +++ b/src/COREMOD_memory/delete_variable.c @@ -1,29 +1,23 @@ /** @file delete_variable.c */ - #include "CommandLineInterface/CLIcore.h" #include "variable_ID.h" /* deletes a variable ID */ -errno_t delete_variable_ID( - const char *varname -) +errno_t delete_variable_ID(const char *varname) { imageID ID; ID = variable_ID(varname); - if(ID != -1) + if (ID != -1) { data.variable[ID].used = 0; /* free(data.variable[ID].name);*/ } else - fprintf(stderr, - "%c[%d;%dm WARNING: variable %s does not exist [ %s %s %d ] %c[%d;m\n", - (char) 27, 1, 31, varname, __FILE__, __func__, __LINE__, (char) 27, 0); + fprintf(stderr, "%c[%d;%dm WARNING: variable %s does not exist [ %s %s %d ] %c[%d;m\n", (char)27, 1, 31, + varname, __FILE__, __func__, __LINE__, (char)27, 0); return RETURN_SUCCESS; } - - diff --git a/src/COREMOD_memory/delete_variable.h b/src/COREMOD_memory/delete_variable.h index b7f19911..0d4180e5 100644 --- a/src/COREMOD_memory/delete_variable.h +++ b/src/COREMOD_memory/delete_variable.h @@ -1,7 +1,4 @@ /** @file delete_variable.h */ -errno_t delete_variable_ID( - const char *varname -); - +errno_t delete_variable_ID(const char *varname); diff --git a/src/COREMOD_memory/fps_ID.c b/src/COREMOD_memory/fps_ID.c index 4c536f7d..a7d815e2 100644 --- a/src/COREMOD_memory/fps_ID.c +++ b/src/COREMOD_memory/fps_ID.c @@ -3,31 +3,26 @@ * @brief find fps ID(s) from name */ - #include "CommandLineInterface/CLIcore.h" - - /* ID number corresponding to a name */ -long fps_ID( - const char *name -) +long fps_ID(const char *name) { - long i; - int loopOK; - long tmpID = 0; + long i; + int loopOK; + long tmpID = 0; i = 0; loopOK = 1; - while(loopOK == 1) + while (loopOK == 1) { - if(data.fpsarray[i].SMfd >= 0) + if (data.fpsarray[i].SMfd >= 0) { // fps in use - if((strncmp(name, data.fpsarray[i].md->name, strlen(name)) == 0) - && (data.fpsarray[i].md->name[strlen(name)] == '\0')) + if ((strncmp(name, data.fpsarray[i].md->name, strlen(name)) == 0) && + (data.fpsarray[i].md->name[strlen(name)] == '\0')) { loopOK = 0; tmpID = i; @@ -36,7 +31,7 @@ long fps_ID( i++; - if(i == data.NB_MAX_FPS) + if (i == data.NB_MAX_FPS) { loopOK = 0; tmpID = -1; @@ -46,37 +41,33 @@ long fps_ID( return tmpID; } - - - /* next available ID number */ long next_avail_fps_ID() { long i; long ID = -1; -# ifdef _OPENMP - #pragma omp critical +#ifdef _OPENMP +#pragma omp critical { #endif - for(i = 0; i < data.NB_MAX_FPS; i++) + for (i = 0; i < data.NB_MAX_FPS; i++) { - if(data.fpsarray[i].SMfd < 0) + if (data.fpsarray[i].SMfd < 0) { // fps is unused, lets grab it ID = i; break; } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif - if(ID == -1) + if (ID == -1) { printf("ERROR: ran out of FPS IDs - cannot allocate new ID\n"); - printf("NB_MAX_FPS should be increased above current value (%ld)\n", - data.NB_MAX_FPS); + printf("NB_MAX_FPS should be increased above current value (%ld)\n", data.NB_MAX_FPS); exit(0); } diff --git a/src/COREMOD_memory/fps_ID.h b/src/COREMOD_memory/fps_ID.h index 58082f60..ab1e709f 100644 --- a/src/COREMOD_memory/fps_ID.h +++ b/src/COREMOD_memory/fps_ID.h @@ -2,9 +2,6 @@ * @file fps_ID.h */ -long fps_ID( - const char *name -); +long fps_ID(const char *name); - -long next_avail_fps_ID(); +long next_avail_fps_ID(); diff --git a/src/COREMOD_memory/fps_create.c b/src/COREMOD_memory/fps_create.c index b5d965a4..a927f7da 100644 --- a/src/COREMOD_memory/fps_create.c +++ b/src/COREMOD_memory/fps_create.c @@ -3,27 +3,18 @@ * @brief create function parameter structure */ -#include #include // for open -#include // for close #include - +#include +#include // for close #include "CommandLineInterface/CLIcore.h" - - - - // ========================================== // Forward declaration(s) // ========================================== -errno_t function_parameter_struct_create( - int NBparamMAX, - const char *name -); - +errno_t function_parameter_struct_create(int NBparamMAX, const char *name); // ========================================== // Command line interface wrapper function(s) @@ -31,26 +22,17 @@ errno_t function_parameter_struct_create( static errno_t fps_create__cli() { - if(0 - + CLI_checkarg(1, CLIARG_LONG) - + CLI_checkarg_noerrmsg(2, CLIARG_STR) - == 0) + if (0 + CLI_checkarg(1, CLIARG_LONG) + CLI_checkarg_noerrmsg(2, CLIARG_STR) == 0) { - function_parameter_struct_create( - data.cmdargtoken[1].val.numl, - data.cmdargtoken[2].val.string - ); + function_parameter_struct_create(data.cmdargtoken[1].val.numl, data.cmdargtoken[2].val.string); return CLICMD_SUCCESS; } else { return CLICMD_INVALID_ARG; } - } - - // ========================================== // Register CLI command(s) // ========================================== @@ -58,27 +40,14 @@ static errno_t fps_create__cli() errno_t fps_create_addCLIcmd() { - RegisterCLIcommand( - "fpscreate", - __FILE__, - fps_create__cli, - "create function parameter structure (FPS)", - " ", - "fpscreate 100 newfps", - "errno_t function_parameter_struct_create(int NBparamMAX, const char *name"); + RegisterCLIcommand("fpscreate", __FILE__, fps_create__cli, "create function parameter structure (FPS)", + " ", "fpscreate 100 newfps", + "errno_t function_parameter_struct_create(int NBparamMAX, const char *name"); return RETURN_SUCCESS; } - - - - - -errno_t function_parameter_struct_create( - int NBparamMAX, - const char *name -) +errno_t function_parameter_struct_create(int NBparamMAX, const char *name) { int index; char *mapv; @@ -89,12 +58,12 @@ errno_t function_parameter_struct_create( char SM_fname[200]; size_t sharedsize = 0; // shared memory size in bytes - int SM_fd; // shared memory file descriptor + int SM_fd; // shared memory file descriptor char shmdname[200]; function_parameter_struct_shmdirname(shmdname); - if(snprintf(SM_fname, sizeof(SM_fname), "%s/%s.fps.shm", shmdname, name) < 0) + if (snprintf(SM_fname, sizeof(SM_fname), "%s/%s.fps.shm", shmdname, name) < 0) { PRINT_ERROR("snprintf error"); } @@ -107,7 +76,7 @@ errno_t function_parameter_struct_create( sharedsize += sizeof(FUNCTION_PARAMETER) * NBparamMAX; SM_fd = open(SM_fname, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); - if(SM_fd == -1) + if (SM_fd == -1) { perror("Error opening file for writing"); printf("STEP %s %d\n", __FILE__, __LINE__); @@ -119,18 +88,17 @@ errno_t function_parameter_struct_create( int result; result = lseek(SM_fd, sharedsize - 1, SEEK_SET); - if(result == -1) + if (result == -1) { close(SM_fd); - printf("ERROR [%s %s %d]: Error calling lseek() to 'stretch' the file\n", - __FILE__, __func__, __LINE__); + printf("ERROR [%s %s %d]: Error calling lseek() to 'stretch' the file\n", __FILE__, __func__, __LINE__); printf("STEP %s %d\n", __FILE__, __LINE__); fflush(stdout); exit(0); } result = write(SM_fd, "", 1); - if(result != 1) + if (result != 1) { close(SM_fd); perror("Error writing last byte of the file"); @@ -139,9 +107,8 @@ errno_t function_parameter_struct_create( exit(0); } - fps.md = (FUNCTION_PARAMETER_STRUCT_MD *) mmap(0, sharedsize, - PROT_READ | PROT_WRITE, MAP_SHARED, SM_fd, 0); - if(fps.md == MAP_FAILED) + fps.md = (FUNCTION_PARAMETER_STRUCT_MD *)mmap(0, sharedsize, PROT_READ | PROT_WRITE, MAP_SHARED, SM_fd, 0); + if (fps.md == MAP_FAILED) { close(SM_fd); perror("Error mmapping the file"); @@ -151,33 +118,28 @@ errno_t function_parameter_struct_create( } //funcparamstruct->md = funcparammd; - mapv = (char *) fps.md; + mapv = (char *)fps.md; mapv += sizeof(FUNCTION_PARAMETER_STRUCT_MD); - fps.parray = (FUNCTION_PARAMETER *) mapv; - - + fps.parray = (FUNCTION_PARAMETER *)mapv; //printf("shared memory space = %ld bytes\n", sharedsize); //TEST - fps.md->NBparamMAX = NBparamMAX; - for(index = 0; index < NBparamMAX; index++) + for (index = 0; index < NBparamMAX; index++) { fps.parray[index].fpflag = 0; // not active fps.parray[index].cnt0 = 0; // update counter } - - strncpy(fps.md->name, name, STRINGMAXLEN_FPS_NAME-1); - strncpy(fps.md->callprogname, data.package_name, FPS_CALLPROGNAME_STRMAXLEN-1); - strncpy(fps.md->callfuncname, data.cmdargtoken[0].val.string, - FPS_CALLFUNCNAME_STRMAXLEN-1); + strncpy(fps.md->name, name, STRINGMAXLEN_FPS_NAME - 1); + strncpy(fps.md->callprogname, data.package_name, FPS_CALLPROGNAME_STRMAXLEN - 1); + strncpy(fps.md->callfuncname, data.cmdargtoken[0].val.string, FPS_CALLFUNCNAME_STRMAXLEN - 1); char cwd[FPS_CWD_STRLENMAX]; - if(getcwd(cwd, sizeof(cwd)) != NULL) + if (getcwd(cwd, sizeof(cwd)) != NULL) { - strncpy(fps.md->workdir, cwd, FPS_CWD_STRLENMAX-1); + strncpy(fps.md->workdir, cwd, FPS_CWD_STRLENMAX - 1); } else { @@ -185,7 +147,7 @@ errno_t function_parameter_struct_create( return 1; } - strncpy(fps.md->sourcefname, "NULL", FPS_SRCDIR_STRLENMAX-1); + strncpy(fps.md->sourcefname, "NULL", FPS_SRCDIR_STRLENMAX - 1); fps.md->sourceline = 0; // set default fpsdatadir @@ -193,36 +155,27 @@ errno_t function_parameter_struct_create( // and create the directory mkdir(fps.md->datadir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - // set default fpsconfdir sprintf(fps.md->confdir, "fps.%s.confdir", fps.md->name); // and create the directory mkdir(fps.md->confdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - // write currently loaded modules to fps fps.md->NBmodule = 0; - for(int m = 0; m < data.NBmodule; m++) + for (int m = 0; m < data.NBmodule; m++) { - if(data.module[m].type == MODULE_TYPE_CUSTOMLOAD) // custom loaded module + if (data.module[m].type == MODULE_TYPE_CUSTOMLOAD) // custom loaded module { - strncpy(fps.md->modulename[fps.md->NBmodule], data.module[m].loadname, - FPS_MODULE_STRMAXLEN-1); + strncpy(fps.md->modulename[fps.md->NBmodule], data.module[m].loadname, FPS_MODULE_STRMAXLEN - 1); fps.md->NBmodule++; } } - - fps.md->signal = (uint64_t) FUNCTION_PARAMETER_STRUCT_SIGNAL_CONFRUN; - fps.md->confwaitus = (uint64_t) 1000; // 1 kHz default + fps.md->signal = (uint64_t)FUNCTION_PARAMETER_STRUCT_SIGNAL_CONFRUN; + fps.md->confwaitus = (uint64_t)1000; // 1 kHz default fps.md->msgcnt = 0; munmap(fps.md, sharedsize); - return EXIT_SUCCESS; } - - - - diff --git a/src/COREMOD_memory/fps_create.h b/src/COREMOD_memory/fps_create.h index ebedf24d..a90656ae 100644 --- a/src/COREMOD_memory/fps_create.h +++ b/src/COREMOD_memory/fps_create.h @@ -5,12 +5,8 @@ #ifndef _FPS_CREATE_H #define FPS_CREATE_H - errno_t fps_create_addCLIcmd(); -errno_t function_parameter_struct_create( - int NBparamMAX, - const char *name -); +errno_t function_parameter_struct_create(int NBparamMAX, const char *name); #endif diff --git a/src/COREMOD_memory/fps_list.c b/src/COREMOD_memory/fps_list.c index 31f50daf..f5d2a6b1 100644 --- a/src/COREMOD_memory/fps_list.c +++ b/src/COREMOD_memory/fps_list.c @@ -3,32 +3,20 @@ * @brief list function parameter structure */ - - #include #include "CommandLineInterface/CLIcore.h" - - - - // ========================================== // Forward declaration(s) // ========================================== errno_t fps_list(); - - // ========================================== // Command line interface wrapper function(s) // ========================================== - - - - // ========================================== // Register CLI command(s) // ========================================== @@ -36,23 +24,12 @@ errno_t fps_list(); errno_t fps_list_addCLIcmd() { - RegisterCLIcommand( - "fpslist", - __FILE__, - fps_list, - "list function parameter structures (FPSs)", - "no argument", - "fpslist", - "errno_t fps_list()"); + RegisterCLIcommand("fpslist", __FILE__, fps_list, "list function parameter structures (FPSs)", "no argument", + "fpslist", "errno_t fps_list()"); return RETURN_SUCCESS; } - - - - - errno_t fps_list() { long fpsID; @@ -62,27 +39,24 @@ errno_t fps_list() int NBchar_fpsname = 12; int NBchar_NBparam = 4; - for(fpsID = 0; fpsID < data.NB_MAX_FPS; fpsID++) + for (fpsID = 0; fpsID < data.NB_MAX_FPS; fpsID++) { - if(data.fpsarray[fpsID].SMfd > -1) + if (data.fpsarray[fpsID].SMfd > -1) { - if(fpscnt == 0) + if (fpscnt == 0) { printf("FPSs currently connected :\n"); } // connected - printf("%*ld %*s %*ld/%*ld entries\n", - NBchar_fpsID, fpsID, - NBchar_fpsname, data.fpsarray[fpsID].md[0].name, - NBchar_NBparam, data.fpsarray[fpsID].NBparamActive, - NBchar_NBparam, data.fpsarray[fpsID].NBparam - ); + printf("%*ld %*s %*ld/%*ld entries\n", NBchar_fpsID, fpsID, NBchar_fpsname, + data.fpsarray[fpsID].md[0].name, NBchar_NBparam, data.fpsarray[fpsID].NBparamActive, NBchar_NBparam, + data.fpsarray[fpsID].NBparam); fpscnt++; } } - if(fpscnt == 0) + if (fpscnt == 0) { printf("No FPS currently connected\n"); } @@ -94,16 +68,16 @@ errno_t fps_list() struct dirent *de; DIR *dr = opendir(data.shmdir); - if(dr == NULL) + if (dr == NULL) { printf("Could not open current directory"); return RETURN_FAILURE; } fpscnt = 0; - while((de = readdir(dr)) != NULL) + while ((de = readdir(dr)) != NULL) { - if(strstr(de->d_name, ".fps.shm") != NULL) + if (strstr(de->d_name, ".fps.shm") != NULL) { char fpsname[100]; int slen = strlen(de->d_name); @@ -111,17 +85,11 @@ errno_t fps_list() strncpy(fpsname, de->d_name, slen1); fpsname[slen1] = '\0'; - printf("%*ld %*s\n", - NBchar_fpsID, fpscnt, - NBchar_fpsname, fpsname); - fpscnt ++; + printf("%*ld %*s\n", NBchar_fpsID, fpscnt, NBchar_fpsname, fpsname); + fpscnt++; } } closedir(dr); return RETURN_SUCCESS; } - - - - diff --git a/src/COREMOD_memory/fps_list.h b/src/COREMOD_memory/fps_list.h index 27c756b1..a87ea142 100644 --- a/src/COREMOD_memory/fps_list.h +++ b/src/COREMOD_memory/fps_list.h @@ -2,9 +2,6 @@ * @file fps_list.h */ - - errno_t fps_list_addCLIcmd(); - errno_t fps_list(); diff --git a/src/COREMOD_memory/image_ID.c b/src/COREMOD_memory/image_ID.c index f47f40da..7217d343 100644 --- a/src/COREMOD_memory/image_ID.c +++ b/src/COREMOD_memory/image_ID.c @@ -3,30 +3,24 @@ * @brief find image ID(s) from name */ - #include "CommandLineInterface/CLIcore.h" - - /* ID number corresponding to a name */ -imageID image_ID( - const char *name -) +imageID image_ID(const char *name) { DEBUG_TRACE_FSTART(); - imageID i; - int loopOK; - imageID tmpID = 0; + imageID i; + int loopOK; + imageID tmpID = 0; i = 0; loopOK = 1; - while(loopOK == 1) + while (loopOK == 1) { - if(data.image[i].used == 1) + if (data.image[i].used == 1) { - if((strncmp(name, data.image[i].name, strlen(name)) == 0) - && (data.image[i].name[strlen(name)] == '\0')) + if ((strncmp(name, data.image[i].name, strlen(name)) == 0) && (data.image[i].name[strlen(name)] == '\0')) { loopOK = 0; tmpID = i; @@ -35,7 +29,7 @@ imageID image_ID( } i++; - if(i == data.NB_MAX_IMAGE) + if (i == data.NB_MAX_IMAGE) { loopOK = 0; tmpID = -1; @@ -47,26 +41,22 @@ imageID image_ID( return tmpID; } - /* ID number corresponding to a name */ -imageID image_ID_noaccessupdate( - const char *name -) +imageID image_ID_noaccessupdate(const char *name) { DEBUG_TRACE_FSTART(); - imageID i; - imageID tmpID = 0; - int loopOK; + imageID i; + imageID tmpID = 0; + int loopOK; i = 0; loopOK = 1; - while(loopOK == 1) + while (loopOK == 1) { - if(data.image[i].used == 1) + if (data.image[i].used == 1) { - if((strncmp(name, data.image[i].name, strlen(name)) == 0) - && (data.image[i].name[strlen(name)] == '\0')) + if ((strncmp(name, data.image[i].name, strlen(name)) == 0) && (data.image[i].name[strlen(name)] == '\0')) { loopOK = 0; tmpID = i; @@ -74,7 +64,7 @@ imageID image_ID_noaccessupdate( } i++; - if(i == data.NB_MAX_IMAGE) + if (i == data.NB_MAX_IMAGE) { loopOK = 0; tmpID = -1; @@ -85,9 +75,6 @@ imageID image_ID_noaccessupdate( return tmpID; } - - - /* next available ID number */ imageID next_avail_image_ID() { @@ -96,28 +83,27 @@ imageID next_avail_image_ID() imageID i; imageID ID = -1; -# ifdef _OPENMP - #pragma omp critical +#ifdef _OPENMP +#pragma omp critical { #endif - for(i = 0; i < data.NB_MAX_IMAGE; i++) + for (i = 0; i < data.NB_MAX_IMAGE; i++) { - if(data.image[i].used == 0) + if (data.image[i].used == 0) { ID = i; data.image[ID].used = 1; break; } } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif - if(ID == -1) + if (ID == -1) { printf("ERROR: ran out of image IDs - cannot allocate new ID\n"); - printf("NB_MAX_IMAGE should be increased above current value (%ld)\n", - data.NB_MAX_IMAGE); + printf("NB_MAX_IMAGE should be increased above current value (%ld)\n", data.NB_MAX_IMAGE); exit(0); } diff --git a/src/COREMOD_memory/image_ID.h b/src/COREMOD_memory/image_ID.h index 8a0f4042..deec247f 100644 --- a/src/COREMOD_memory/image_ID.h +++ b/src/COREMOD_memory/image_ID.h @@ -2,13 +2,8 @@ * @file image_ID.h */ -imageID image_ID( - const char *name -); +imageID image_ID(const char *name); -imageID image_ID_noaccessupdate( - const char *name -); +imageID image_ID_noaccessupdate(const char *name); - -imageID next_avail_image_ID(); +imageID next_avail_image_ID(); diff --git a/src/COREMOD_memory/image_checksize.c b/src/COREMOD_memory/image_checksize.c index 2af9060d..5c0a5a11 100644 --- a/src/COREMOD_memory/image_checksize.c +++ b/src/COREMOD_memory/image_checksize.c @@ -3,38 +3,28 @@ * @brief check image size */ - #include "CommandLineInterface/CLIcore.h" #include "image_ID.h" - - - - - // check only is size > 0 -int check_2Dsize( - const char *ID_name, - uint32_t xsize, - uint32_t ysize -) +int check_2Dsize(const char *ID_name, uint32_t xsize, uint32_t ysize) { - int retval; - imageID ID; + int retval; + imageID ID; retval = 1; ID = image_ID(ID_name); - if(data.image[ID].md[0].naxis != 2) + if (data.image[ID].md[0].naxis != 2) { retval = 0; } - if(retval == 1) + if (retval == 1) { - if((xsize > 0) && (data.image[ID].md[0].size[0] != xsize)) + if ((xsize > 0) && (data.image[ID].md[0].size[0] != xsize)) { retval = 0; } - if((ysize > 0) && (data.image[ID].md[0].size[1] != ysize)) + if ((ysize > 0) && (data.image[ID].md[0].size[1] != ysize)) { retval = 0; } @@ -43,38 +33,31 @@ int check_2Dsize( return retval; } - - -int check_3Dsize( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize -) +int check_3Dsize(const char *ID_name, uint32_t xsize, uint32_t ysize, uint32_t zsize) { - int retval; + int retval; imageID ID; retval = 1; ID = image_ID(ID_name); - if(data.image[ID].md[0].naxis != 3) + if (data.image[ID].md[0].naxis != 3) { /* printf("Wrong naxis : %ld - should be 3\n",data.image[ID].md[0].naxis);*/ retval = 0; } - if(retval == 1) + if (retval == 1) { - if((xsize > 0) && (data.image[ID].md[0].size[0] != xsize)) + if ((xsize > 0) && (data.image[ID].md[0].size[0] != xsize)) { /* printf("Wrong xsize : %ld - should be %ld\n",data.image[ID].md[0].size[0],xsize);*/ retval = 0; } - if((ysize > 0) && (data.image[ID].md[0].size[1] != ysize)) + if ((ysize > 0) && (data.image[ID].md[0].size[1] != ysize)) { /* printf("Wrong ysize : %ld - should be %ld\n",data.image[ID].md[0].size[1],ysize);*/ retval = 0; } - if((zsize > 0) && (data.image[ID].md[0].size[2] != zsize)) + if ((zsize > 0) && (data.image[ID].md[0].size[2] != zsize)) { /* printf("Wrong zsize : %ld - should be %ld\n",data.image[ID].md[0].size[2],zsize);*/ retval = 0; @@ -85,84 +68,64 @@ int check_3Dsize( return retval; } - - - - - - -int COREMOD_MEMORY_check_2Dsize( - const char *IDname, - uint32_t xsize, - uint32_t ysize -) +int COREMOD_MEMORY_check_2Dsize(const char *IDname, uint32_t xsize, uint32_t ysize) { - int sizeOK = 1; // 1 if size matches + int sizeOK = 1; // 1 if size matches imageID ID; - ID = image_ID(IDname); - if(data.image[ID].md[0].naxis != 2) + if (data.image[ID].md[0].naxis != 2) { - printf("WARNING : image %s naxis = %d does not match expected value 2\n", - IDname, (int) data.image[ID].md[0].naxis); + printf("WARNING : image %s naxis = %d does not match expected value 2\n", IDname, + (int)data.image[ID].md[0].naxis); sizeOK = 0; } - if((xsize > 0) && (data.image[ID].md[0].size[0] != xsize)) + if ((xsize > 0) && (data.image[ID].md[0].size[0] != xsize)) { - printf("WARNING : image %s xsize = %d does not match expected value %d\n", - IDname, (int) data.image[ID].md[0].size[0], (int) xsize); + printf("WARNING : image %s xsize = %d does not match expected value %d\n", IDname, + (int)data.image[ID].md[0].size[0], (int)xsize); sizeOK = 0; } - if((ysize > 0) && (data.image[ID].md[0].size[1] != ysize)) + if ((ysize > 0) && (data.image[ID].md[0].size[1] != ysize)) { - printf("WARNING : image %s ysize = %d does not match expected value %d\n", - IDname, (int) data.image[ID].md[0].size[1], (int) ysize); + printf("WARNING : image %s ysize = %d does not match expected value %d\n", IDname, + (int)data.image[ID].md[0].size[1], (int)ysize); sizeOK = 0; } return sizeOK; } - - -int COREMOD_MEMORY_check_3Dsize( - const char *IDname, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize -) +int COREMOD_MEMORY_check_3Dsize(const char *IDname, uint32_t xsize, uint32_t ysize, uint32_t zsize) { - int sizeOK = 1; // 1 if size matches + int sizeOK = 1; // 1 if size matches imageID ID; ID = image_ID(IDname); - if(data.image[ID].md[0].naxis != 3) + if (data.image[ID].md[0].naxis != 3) { - printf("WARNING : image %s naxis = %d does not match expected value 3\n", - IDname, (int) data.image[ID].md[0].naxis); + printf("WARNING : image %s naxis = %d does not match expected value 3\n", IDname, + (int)data.image[ID].md[0].naxis); sizeOK = 0; } - if((xsize > 0) && (data.image[ID].md[0].size[0] != xsize)) + if ((xsize > 0) && (data.image[ID].md[0].size[0] != xsize)) { - printf("WARNING : image %s xsize = %d does not match expected value %d\n", - IDname, (int) data.image[ID].md[0].size[0], (int) xsize); + printf("WARNING : image %s xsize = %d does not match expected value %d\n", IDname, + (int)data.image[ID].md[0].size[0], (int)xsize); sizeOK = 0; } - if((ysize > 0) && (data.image[ID].md[0].size[1] != ysize)) + if ((ysize > 0) && (data.image[ID].md[0].size[1] != ysize)) { - printf("WARNING : image %s ysize = %d does not match expected value %d\n", - IDname, (int) data.image[ID].md[0].size[1], (int) ysize); + printf("WARNING : image %s ysize = %d does not match expected value %d\n", IDname, + (int)data.image[ID].md[0].size[1], (int)ysize); sizeOK = 0; } - if((zsize > 0) && (data.image[ID].md[0].size[2] != zsize)) + if ((zsize > 0) && (data.image[ID].md[0].size[2] != zsize)) { - printf("WARNING : image %s zsize = %d does not match expected value %d\n", - IDname, (int) data.image[ID].md[0].size[2], (int) zsize); + printf("WARNING : image %s zsize = %d does not match expected value %d\n", IDname, + (int)data.image[ID].md[0].size[2], (int)zsize); sizeOK = 0; } return sizeOK; } - - diff --git a/src/COREMOD_memory/image_checksize.h b/src/COREMOD_memory/image_checksize.h index c6ba462e..ab147985 100644 --- a/src/COREMOD_memory/image_checksize.h +++ b/src/COREMOD_memory/image_checksize.h @@ -2,31 +2,10 @@ * @file image_checksize.h */ +int check_2Dsize(const char *ID_name, uint32_t xsize, uint32_t ysize); +int check_3Dsize(const char *ID_name, uint32_t xsize, uint32_t ysize, uint32_t zsize); +int COREMOD_MEMORY_check_2Dsize(const char *IDname, uint32_t xsize, uint32_t ysize); -int check_2Dsize( - const char *ID_name, - uint32_t xsize, - uint32_t ysize -); - -int check_3Dsize( - const char *ID_name, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize -); - -int COREMOD_MEMORY_check_2Dsize( - const char *IDname, - uint32_t xsize, - uint32_t ysize -); - -int COREMOD_MEMORY_check_3Dsize( - const char *IDname, - uint32_t xsize, - uint32_t ysize, - uint32_t zsize -); +int COREMOD_MEMORY_check_3Dsize(const char *IDname, uint32_t xsize, uint32_t ysize, uint32_t zsize); diff --git a/src/COREMOD_memory/image_complex.c b/src/COREMOD_memory/image_complex.c index f9c6f62e..99ebb485 100644 --- a/src/COREMOD_memory/image_complex.c +++ b/src/COREMOD_memory/image_complex.c @@ -3,74 +3,40 @@ * @brief complex number conversion */ - #include #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" #include "create_image.h" -#include "stream_sem.h" #include "delete_image.h" +#include "image_ID.h" +#include "stream_sem.h" - - - - - -errno_t mk_reim_from_amph( - const char *am_name, - const char *ph_name, - const char *re_out_name, - const char *im_out_name, - int sharedmem -) +errno_t mk_reim_from_amph(const char *am_name, const char *ph_name, const char *re_out_name, const char *im_out_name, + int sharedmem) { DEBUG_TRACE_FSTART(); - FUNC_CHECK_RETURN( - mk_complex_from_amph(am_name, ph_name, "Ctmp", 0) - ); + FUNC_CHECK_RETURN(mk_complex_from_amph(am_name, ph_name, "Ctmp", 0)); - FUNC_CHECK_RETURN( - mk_reim_from_complex("Ctmp", re_out_name, im_out_name, sharedmem) - ); + FUNC_CHECK_RETURN(mk_reim_from_complex("Ctmp", re_out_name, im_out_name, sharedmem)); - FUNC_CHECK_RETURN( - delete_image_ID("Ctmp", DELETE_IMAGE_ERRMODE_WARNING) - ); + FUNC_CHECK_RETURN(delete_image_ID("Ctmp", DELETE_IMAGE_ERRMODE_WARNING)); DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - - -errno_t mk_amph_from_reim( - const char *re_name, - const char *im_name, - const char *am_out_name, - const char *ph_out_name, - int sharedmem -) +errno_t mk_amph_from_reim(const char *re_name, const char *im_name, const char *am_out_name, const char *ph_out_name, + int sharedmem) { DEBUG_TRACE_FSTART(); - FUNC_CHECK_RETURN( - mk_complex_from_reim(re_name, im_name, "Ctmp", 0) - ); + FUNC_CHECK_RETURN(mk_complex_from_reim(re_name, im_name, "Ctmp", 0)); - FUNC_CHECK_RETURN( - mk_amph_from_complex("Ctmp", am_out_name, ph_out_name, sharedmem) - ); + FUNC_CHECK_RETURN(mk_amph_from_complex("Ctmp", am_out_name, ph_out_name, sharedmem)); - FUNC_CHECK_RETURN( - delete_image_ID("Ctmp", DELETE_IMAGE_ERRMODE_WARNING) - ); + FUNC_CHECK_RETURN(delete_image_ID("Ctmp", DELETE_IMAGE_ERRMODE_WARNING)); DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - - - - diff --git a/src/COREMOD_memory/image_complex.h b/src/COREMOD_memory/image_complex.h index 74a56b40..62ef5a2e 100644 --- a/src/COREMOD_memory/image_complex.h +++ b/src/COREMOD_memory/image_complex.h @@ -1,20 +1,10 @@ #ifndef COREMOD_MEMORY_IMAGE_COMPLEX_H #define COREMOD_MEMORY_IMAGE_COMPLEX_H -errno_t mk_reim_from_amph( - const char *am_name, - const char *ph_name, - const char *re_out_name, - const char *im_out_name, - int sharedmem -); +errno_t mk_reim_from_amph(const char *am_name, const char *ph_name, const char *re_out_name, const char *im_out_name, + int sharedmem); -errno_t mk_amph_from_reim( - const char *re_name, - const char *im_name, - const char *am_out_name, - const char *ph_out_name, - int sharedmem -); +errno_t mk_amph_from_reim(const char *re_name, const char *im_name, const char *am_out_name, const char *ph_out_name, + int sharedmem); #endif diff --git a/src/COREMOD_memory/image_copy.c b/src/COREMOD_memory/image_copy.c index 69516e3b..6b71df0f 100644 --- a/src/COREMOD_memory/image_copy.c +++ b/src/COREMOD_memory/image_copy.c @@ -4,79 +4,57 @@ #include "CommandLineInterface/CLIcore.h" -#include "variable_ID.h" -#include "image_ID.h" -#include "delete_image.h" #include "create_image.h" +#include "delete_image.h" +#include "image_ID.h" #include "list_image.h" -#include "stream_sem.h" #include "read_shmim.h" - - +#include "stream_sem.h" +#include "variable_ID.h" // ========================================== // Forward declaration(s) // ========================================== -imageID copy_image_ID( - const char *name, - const char *newname, - int shared -); - -imageID chname_image_ID( - const char *ID_name, - const char *new_name -); - -errno_t COREMOD_MEMORY_cp2shm( - const char *IDname, - const char *IDshmname -); - +imageID copy_image_ID(const char *name, const char *newname, int shared); +imageID chname_image_ID(const char *ID_name, const char *new_name); +errno_t COREMOD_MEMORY_cp2shm(const char *IDname, const char *IDshmname); // ========================================== // Command line interface wrapper function(s) // ========================================== - static errno_t copy_image_ID__cli() { - if(data.cmdargtoken[1].type != CLIARG_IMG) + if (data.cmdargtoken[1].type != CLIARG_IMG) { printf("Image %s does not exist\n", data.cmdargtoken[1].val.string); return CLICMD_INVALID_ARG; } - copy_image_ID(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, - 0); + copy_image_ID(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, 0); return CLICMD_SUCCESS; } - - - static errno_t copy_image_ID_sharedmem__cli() { - if(data.cmdargtoken[1].type != CLIARG_IMG) + if (data.cmdargtoken[1].type != CLIARG_IMG) { printf("Image %s does not exist\n", data.cmdargtoken[1].val.string); return CLICMD_INVALID_ARG; } - copy_image_ID(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, - 1); + copy_image_ID(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, 1); return CLICMD_SUCCESS; } - static errno_t chname_image_ID__cli() { - if(data.cmdargtoken[1].type != CLIARG_IMG) + if (data.cmdargtoken[1].type != CLIARG_IMG) { printf("Image %s does not exist\n", data.cmdargtoken[1].val.string); return CLICMD_INVALID_ARG; @@ -87,16 +65,11 @@ static errno_t chname_image_ID__cli() return CLICMD_SUCCESS; } - - static errno_t COREMOD_MEMORY_cp2shm__cli() { - if(CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_STR_NOT_IMG) - == 0) + if (CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_STR_NOT_IMG) == 0) { - COREMOD_MEMORY_cp2shm(data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.string); + COREMOD_MEMORY_cp2shm(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string); return CLICMD_SUCCESS; } else @@ -105,133 +78,93 @@ static errno_t COREMOD_MEMORY_cp2shm__cli() } } - - - - // ========================================== // Register CLI command(s) // ========================================== errno_t image_copy_addCLIcmd() { - RegisterCLIcommand( - "cp", - __FILE__, copy_image_ID__cli, - "copy image", - "source, dest", - "cp im1 im4", - "long copy_image_ID(const char *name, const char *newname, 0)"); - - RegisterCLIcommand( - "cpsh", - __FILE__, copy_image_ID_sharedmem__cli, - "copy image - create in shared mem if does not exist", - "source, dest", - "cp im1 im4", - "long copy_image_ID(const char *name, const char *newname, 1)"); - - RegisterCLIcommand( - "mv", - __FILE__, - chname_image_ID__cli, - "change image name", - "source, dest", - "mv im1 im4", - "long chname_image_ID(const char *name, const char *newname)"); - - RegisterCLIcommand( - "imcp2shm", - __FILE__, - COREMOD_MEMORY_cp2shm__cli, - "copy image ot shared memory", - " ", - "imcp2shm im1 ims1", - "long COREMOD_MEMORY_cp2shm(const char *IDname, const char *IDshmname)"); - - return RETURN_SUCCESS; -} - - - - - - + RegisterCLIcommand("cp", __FILE__, copy_image_ID__cli, "copy image", "source, dest", "cp im1 im4", + "long copy_image_ID(const char *name, const char *newname, 0)"); + RegisterCLIcommand("cpsh", __FILE__, copy_image_ID_sharedmem__cli, + "copy image - create in shared mem if does not exist", "source, dest", "cp im1 im4", + "long copy_image_ID(const char *name, const char *newname, 1)"); + RegisterCLIcommand("mv", __FILE__, chname_image_ID__cli, "change image name", "source, dest", "mv im1 im4", + "long chname_image_ID(const char *name, const char *newname)"); + RegisterCLIcommand("imcp2shm", __FILE__, COREMOD_MEMORY_cp2shm__cli, "copy image ot shared memory", + " ", "imcp2shm im1 ims1", + "long COREMOD_MEMORY_cp2shm(const char *IDname, const char *IDshmname)"); + return RETURN_SUCCESS; +} -imageID copy_image_ID( - const char *name, - const char *newname, - int shared -) +imageID copy_image_ID(const char *name, const char *newname, int shared) { - imageID ID; - imageID IDout; - long naxis; - uint32_t *size = NULL; - uint8_t datatype; - long nelement; - long i; - int newim = 0; - + imageID ID; + imageID IDout; + long naxis; + uint32_t *size = NULL; + uint8_t datatype; + long nelement; + long i; + int newim = 0; ID = image_ID(name); - if(ID == -1) + if (ID == -1) { PRINT_ERROR("image \"%s\" does not exist", name); exit(0); } naxis = data.image[ID].md[0].naxis; - size = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(size == NULL) + size = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (size == NULL) { PRINT_ERROR("malloc error"); exit(0); } - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { size[i] = data.image[ID].md[0].size[i]; } - datatype = data.image[ID].md[0].datatype; + datatype = data.image[ID].md[0].datatype; nelement = data.image[ID].md[0].nelement; IDout = image_ID(newname); - if(IDout != -1) + if (IDout != -1) { // verify newname has the right size and type - if(data.image[ID].md[0].nelement != data.image[IDout].md[0].nelement) + if (data.image[ID].md[0].nelement != data.image[IDout].md[0].nelement) { - fprintf(stderr, - "ERROR [copy_image_ID]: images %s and %s do not have the same size -> deleting and re-creating image\n", - name, newname); + fprintf( + stderr, + "ERROR [copy_image_ID]: images %s and %s do not have the same size -> deleting and re-creating image\n", + name, newname); newim = 1; } - if(data.image[ID].md[0].datatype != data.image[IDout].md[0].datatype) + if (data.image[ID].md[0].datatype != data.image[IDout].md[0].datatype) { - fprintf(stderr, - "ERROR [copy_image_ID]: images %s and %s do not have the same type -> deleting and re-creating image\n", - name, newname); + fprintf( + stderr, + "ERROR [copy_image_ID]: images %s and %s do not have the same type -> deleting and re-creating image\n", + name, newname); newim = 1; } - if(newim == 1) + if (newim == 1) { delete_image_ID(newname, DELETE_IMAGE_ERRMODE_WARNING); IDout = -1; } } - - - - if(IDout == -1) + if (IDout == -1) { create_image_ID(newname, naxis, size, datatype, shared, data.NBKEYWORD_DFT, 0, NULL); IDout = image_ID(newname); @@ -239,95 +172,77 @@ imageID copy_image_ID( else { // verify newname has the right size and type - if(data.image[ID].md[0].nelement != data.image[IDout].md[0].nelement) + if (data.image[ID].md[0].nelement != data.image[IDout].md[0].nelement) { - fprintf(stderr, - "ERROR [copy_image_ID]: images %s and %s do not have the same size\n", name, - newname); + fprintf(stderr, "ERROR [copy_image_ID]: images %s and %s do not have the same size\n", name, newname); exit(0); } - if(data.image[ID].md[0].datatype != data.image[IDout].md[0].datatype) + if (data.image[ID].md[0].datatype != data.image[IDout].md[0].datatype) { - fprintf(stderr, - "ERROR [copy_image_ID]: images %s and %s do not have the same type\n", name, - newname); + fprintf(stderr, "ERROR [copy_image_ID]: images %s and %s do not have the same type\n", name, newname); exit(0); } } data.image[IDout].md[0].write = 1; - - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { - memcpy(data.image[IDout].array.UI8, data.image[ID].array.UI8, - SIZEOF_DATATYPE_UINT8 * nelement); + memcpy(data.image[IDout].array.UI8, data.image[ID].array.UI8, SIZEOF_DATATYPE_UINT8 * nelement); } - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { - memcpy(data.image[IDout].array.SI8, data.image[ID].array.SI8, - SIZEOF_DATATYPE_INT8 * nelement); + memcpy(data.image[IDout].array.SI8, data.image[ID].array.SI8, SIZEOF_DATATYPE_INT8 * nelement); } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { - memcpy(data.image[IDout].array.UI16, data.image[ID].array.UI16, - SIZEOF_DATATYPE_UINT16 * nelement); + memcpy(data.image[IDout].array.UI16, data.image[ID].array.UI16, SIZEOF_DATATYPE_UINT16 * nelement); } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { - memcpy(data.image[IDout].array.SI16, data.image[ID].array.SI16, - SIZEOF_DATATYPE_INT8 * nelement); + memcpy(data.image[IDout].array.SI16, data.image[ID].array.SI16, SIZEOF_DATATYPE_INT8 * nelement); } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { - memcpy(data.image[IDout].array.UI32, data.image[ID].array.UI32, - SIZEOF_DATATYPE_UINT32 * nelement); + memcpy(data.image[IDout].array.UI32, data.image[ID].array.UI32, SIZEOF_DATATYPE_UINT32 * nelement); } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { - memcpy(data.image[IDout].array.SI32, data.image[ID].array.SI32, - SIZEOF_DATATYPE_INT32 * nelement); + memcpy(data.image[IDout].array.SI32, data.image[ID].array.SI32, SIZEOF_DATATYPE_INT32 * nelement); } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { - memcpy(data.image[IDout].array.UI64, data.image[ID].array.UI64, - SIZEOF_DATATYPE_UINT64 * nelement); + memcpy(data.image[IDout].array.UI64, data.image[ID].array.UI64, SIZEOF_DATATYPE_UINT64 * nelement); } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { - memcpy(data.image[IDout].array.SI64, data.image[ID].array.SI64, - SIZEOF_DATATYPE_INT64 * nelement); + memcpy(data.image[IDout].array.SI64, data.image[ID].array.SI64, SIZEOF_DATATYPE_INT64 * nelement); } - - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { - memcpy(data.image[IDout].array.F, data.image[ID].array.F, - SIZEOF_DATATYPE_FLOAT * nelement); + memcpy(data.image[IDout].array.F, data.image[ID].array.F, SIZEOF_DATATYPE_FLOAT * nelement); } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { - memcpy(data.image[IDout].array.D, data.image[ID].array.D, - SIZEOF_DATATYPE_DOUBLE * nelement); + memcpy(data.image[IDout].array.D, data.image[ID].array.D, SIZEOF_DATATYPE_DOUBLE * nelement); } - if(datatype == _DATATYPE_COMPLEX_FLOAT) + if (datatype == _DATATYPE_COMPLEX_FLOAT) { - memcpy(data.image[IDout].array.CF, data.image[ID].array.CF, - SIZEOF_DATATYPE_COMPLEX_FLOAT * nelement); + memcpy(data.image[IDout].array.CF, data.image[ID].array.CF, SIZEOF_DATATYPE_COMPLEX_FLOAT * nelement); } - if(datatype == _DATATYPE_COMPLEX_DOUBLE) + if (datatype == _DATATYPE_COMPLEX_DOUBLE) { - memcpy(data.image[IDout].array.CD, data.image[ID].array.CD, - SIZEOF_DATATYPE_COMPLEX_DOUBLE * nelement); + memcpy(data.image[IDout].array.CD, data.image[ID].array.CD, SIZEOF_DATATYPE_COMPLEX_DOUBLE * nelement); } COREMOD_MEMORY_image_set_sempost_byID(IDout, -1); @@ -337,22 +252,15 @@ imageID copy_image_ID( free(size); - return IDout; } - - - -imageID chname_image_ID( - const char *ID_name, - const char *new_name -) +imageID chname_image_ID(const char *ID_name, const char *new_name) { imageID ID; ID = -1; - if((image_ID(new_name) == -1) && (variable_ID(new_name) == -1)) + if ((image_ID(new_name) == -1) && (variable_ID(new_name) == -1)) { ID = image_ID(ID_name); strcpy(data.image[ID].name, new_name); @@ -360,11 +268,10 @@ imageID chname_image_ID( } else { - printf("Cannot change name %s -> %s : new name already in use\n", ID_name, - new_name); + printf("Cannot change name %s -> %s : new name already in use\n", ID_name, new_name); } - if(data.MEM_MONITOR == 1) + if (data.MEM_MONITOR == 1) { list_image_ID_ncurses(); } @@ -372,73 +279,63 @@ imageID chname_image_ID( return ID; } - - - - - /** copy an image to shared memory * * */ -errno_t COREMOD_MEMORY_cp2shm( - const char *IDname, - const char *IDshmname -) +errno_t COREMOD_MEMORY_cp2shm(const char *IDname, const char *IDshmname) { - imageID ID; - imageID IDshm; - uint8_t datatype; - long naxis; - uint32_t *sizearray; - char *ptr1; - char *ptr2; - long k; - int axis; - int shmOK; - + imageID ID; + imageID IDshm; + uint8_t datatype; + long naxis; + uint32_t *sizearray; + char *ptr1; + char *ptr2; + long k; + int axis; + int shmOK; ID = image_ID(IDname); naxis = data.image[ID].md[0].naxis; - - sizearray = (uint32_t *) malloc(sizeof(uint32_t) * naxis); + sizearray = (uint32_t *)malloc(sizeof(uint32_t) * naxis); datatype = data.image[ID].md[0].datatype; - for(k = 0; k < naxis; k++) + for (k = 0; k < naxis; k++) { sizearray[k] = data.image[ID].md[0].size[k]; } shmOK = 1; IDshm = read_sharedmem_image(IDshmname); - if(IDshm != -1) + if (IDshm != -1) { // verify type and size - if(data.image[ID].md[0].naxis != data.image[IDshm].md[0].naxis) + if (data.image[ID].md[0].naxis != data.image[IDshm].md[0].naxis) { shmOK = 0; } - if(shmOK == 1) + if (shmOK == 1) { - for(axis = 0; axis < data.image[IDshm].md[0].naxis; axis++) - if(data.image[ID].md[0].size[axis] != data.image[IDshm].md[0].size[axis]) + for (axis = 0; axis < data.image[IDshm].md[0].naxis; axis++) + if (data.image[ID].md[0].size[axis] != data.image[IDshm].md[0].size[axis]) { shmOK = 0; } } - if(data.image[ID].md[0].datatype != data.image[IDshm].md[0].datatype) + if (data.image[ID].md[0].datatype != data.image[IDshm].md[0].datatype) { shmOK = 0; } - if(shmOK == 0) + if (shmOK == 0) { delete_image_ID(IDshmname, DELETE_IMAGE_ERRMODE_WARNING); IDshm = -1; } } - if(IDshm == -1) + if (IDshm == -1) { create_image_ID(IDshmname, naxis, sizearray, datatype, 1, 0, 0, &IDshm); } @@ -449,84 +346,72 @@ errno_t COREMOD_MEMORY_cp2shm( data.image[IDshm].md[0].write = 1; - switch(datatype) + switch (datatype) { - case _DATATYPE_FLOAT : - ptr1 = (char *) data.image[ID].array.F; - ptr2 = (char *) data.image[IDshm].array.F; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_FLOAT * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_DOUBLE : - ptr1 = (char *) data.image[ID].array.D; - ptr2 = (char *) data.image[IDshm].array.D; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_DOUBLE * data.image[ID].md[0].nelement); - break; - - - case _DATATYPE_INT8 : - ptr1 = (char *) data.image[ID].array.SI8; - ptr2 = (char *) data.image[IDshm].array.SI8; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_INT8 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_UINT8 : - ptr1 = (char *) data.image[ID].array.UI8; - ptr2 = (char *) data.image[IDshm].array.UI8; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_UINT8 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_INT16 : - ptr1 = (char *) data.image[ID].array.SI16; - ptr2 = (char *) data.image[IDshm].array.SI16; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_INT16 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_UINT16 : - ptr1 = (char *) data.image[ID].array.UI16; - ptr2 = (char *) data.image[IDshm].array.UI16; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_UINT16 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_INT32 : - ptr1 = (char *) data.image[ID].array.SI32; - ptr2 = (char *) data.image[IDshm].array.SI32; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_INT32 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_UINT32 : - ptr1 = (char *) data.image[ID].array.UI32; - ptr2 = (char *) data.image[IDshm].array.UI32; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_UINT32 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_INT64 : - ptr1 = (char *) data.image[ID].array.SI64; - ptr2 = (char *) data.image[IDshm].array.SI64; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_INT64 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_UINT64 : - ptr1 = (char *) data.image[ID].array.UI64; - ptr2 = (char *) data.image[IDshm].array.UI64; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_UINT64 * data.image[ID].md[0].nelement); - break; - - - default : - printf("data type not supported\n"); - break; + case _DATATYPE_FLOAT: + ptr1 = (char *)data.image[ID].array.F; + ptr2 = (char *)data.image[IDshm].array.F; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_FLOAT * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_DOUBLE: + ptr1 = (char *)data.image[ID].array.D; + ptr2 = (char *)data.image[IDshm].array.D; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_DOUBLE * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_INT8: + ptr1 = (char *)data.image[ID].array.SI8; + ptr2 = (char *)data.image[IDshm].array.SI8; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_INT8 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_UINT8: + ptr1 = (char *)data.image[ID].array.UI8; + ptr2 = (char *)data.image[IDshm].array.UI8; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_UINT8 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_INT16: + ptr1 = (char *)data.image[ID].array.SI16; + ptr2 = (char *)data.image[IDshm].array.SI16; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_INT16 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_UINT16: + ptr1 = (char *)data.image[ID].array.UI16; + ptr2 = (char *)data.image[IDshm].array.UI16; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_UINT16 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_INT32: + ptr1 = (char *)data.image[ID].array.SI32; + ptr2 = (char *)data.image[IDshm].array.SI32; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_INT32 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_UINT32: + ptr1 = (char *)data.image[ID].array.UI32; + ptr2 = (char *)data.image[IDshm].array.UI32; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_UINT32 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_INT64: + ptr1 = (char *)data.image[ID].array.SI64; + ptr2 = (char *)data.image[IDshm].array.SI64; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_INT64 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_UINT64: + ptr1 = (char *)data.image[ID].array.UI64; + ptr2 = (char *)data.image[IDshm].array.UI64; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_UINT64 * data.image[ID].md[0].nelement); + break; + + default: + printf("data type not supported\n"); + break; } COREMOD_MEMORY_image_set_sempost_byID(IDshm, -1); data.image[IDshm].md[0].cnt0++; @@ -534,11 +419,3 @@ errno_t COREMOD_MEMORY_cp2shm( return RETURN_SUCCESS; } - - - - - - - - diff --git a/src/COREMOD_memory/image_copy.h b/src/COREMOD_memory/image_copy.h index 31c09f2f..f30008a4 100644 --- a/src/COREMOD_memory/image_copy.h +++ b/src/COREMOD_memory/image_copy.h @@ -2,24 +2,10 @@ * @file image_copy.h */ - - - errno_t image_copy_addCLIcmd(); +imageID copy_image_ID(const char *name, const char *newname, int shared); -imageID copy_image_ID( - const char *name, - const char *newname, - int shared -); - -imageID chname_image_ID( - const char *ID_name, - const char *new_name -); +imageID chname_image_ID(const char *ID_name, const char *new_name); -errno_t COREMOD_MEMORY_cp2shm( - const char *IDname, - const char *IDshmname -); +errno_t COREMOD_MEMORY_cp2shm(const char *IDname, const char *IDshmname); diff --git a/src/COREMOD_memory/image_copy_shm.c b/src/COREMOD_memory/image_copy_shm.c index 1061406c..83592889 100644 --- a/src/COREMOD_memory/image_copy_shm.c +++ b/src/COREMOD_memory/image_copy_shm.c @@ -3,61 +3,30 @@ #include "create_image.h" #include "read_shmim.h" - // Local variables pointers static char *inimname; static char *outimname; - - -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".in_name", "input image", "im1", - CLIARG_VISIBLE_DEFAULT, - (void **) &inimname, NULL - }, - { - CLIARG_STR, ".out_name", "output stream", "out1", - CLIARG_VISIBLE_DEFAULT, - (void **) &outimname, NULL - } -}; - +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".in_name", "input image", "im1", CLIARG_VISIBLE_DEFAULT, (void **)&inimname, NULL}, + {CLIARG_STR, ".out_name", "output stream", "out1", CLIARG_VISIBLE_DEFAULT, (void **)&outimname, NULL}}; // flag CLICMDFLAG_FPS enabled FPS capability -static CLICMDDATA CLIcmddata = -{ - "imcpshm", - "copy image to shm", - CLICMD_FIELDS_DEFAULTS -}; - - +static CLICMDDATA CLIcmddata = {"imcpshm", "copy image to shm", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - - - - +static errno_t help_function() { return RETURN_SUCCESS; } // Computation code -static errno_t image_copy_shm( - IMGID img, - char *outshmname -) +static errno_t image_copy_shm(IMGID img, char *outshmname) { resolveIMGID(&img, ERRMODE_ABORT); imageID ID = img.ID; uint8_t naxis = data.image[ID].md[0].naxis; - uint32_t *sizearray = (uint32_t *) malloc(sizeof(uint32_t) * naxis); + uint32_t *sizearray = (uint32_t *)malloc(sizeof(uint32_t) * naxis); uint8_t datatype = data.image[ID].md[0].datatype; - for(uint8_t k = 0; k < naxis; k++) + for (uint8_t k = 0; k < naxis; k++) { sizearray[k] = data.image[ID].md[0].size[k]; } @@ -69,35 +38,34 @@ static errno_t image_copy_shm( imageID IDshm = read_sharedmem_image(outshmname); DEBUG_TRACEPOINT("IDshm = %ld", IDshm); - if(IDshm != -1) + if (IDshm != -1) { // verify type and size - if(data.image[ID].md[0].naxis != data.image[IDshm].md[0].naxis) + if (data.image[ID].md[0].naxis != data.image[IDshm].md[0].naxis) { shmOK = 0; } - if(shmOK == 1) + if (shmOK == 1) { - for(uint8_t axis = 0; axis < data.image[IDshm].md[0].naxis; axis++) - if(data.image[ID].md[0].size[axis] != data.image[IDshm].md[0].size[axis]) + for (uint8_t axis = 0; axis < data.image[IDshm].md[0].naxis; axis++) + if (data.image[ID].md[0].size[axis] != data.image[IDshm].md[0].size[axis]) { shmOK = 0; } } - if(data.image[ID].md[0].datatype != data.image[IDshm].md[0].datatype) + if (data.image[ID].md[0].datatype != data.image[IDshm].md[0].datatype) { shmOK = 0; } - if(shmOK == 0) + if (shmOK == 0) { delete_image_ID(outshmname, DELETE_IMAGE_ERRMODE_WARNING); IDshm = -1; } } - - if(IDshm == -1) + if (IDshm == -1) { DEBUG_TRACEPOINT("Creating image"); create_image_ID(outshmname, naxis, sizearray, datatype, 1, NBkw, 0, &IDshm); @@ -111,103 +79,88 @@ static errno_t image_copy_shm( data.image[IDshm].md[0].write = 1; - char *ptr1; - char *ptr2; + char *ptr1; + char *ptr2; - switch(datatype) + switch (datatype) { - case _DATATYPE_FLOAT : - ptr1 = (char *) data.image[ID].array.F; - ptr2 = (char *) data.image[IDshm].array.F; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_FLOAT * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_DOUBLE : - ptr1 = (char *) data.image[ID].array.D; - ptr2 = (char *) data.image[IDshm].array.D; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_DOUBLE * data.image[ID].md[0].nelement); - break; - - - case _DATATYPE_INT8 : - ptr1 = (char *) data.image[ID].array.SI8; - ptr2 = (char *) data.image[IDshm].array.SI8; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_INT8 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_UINT8 : - ptr1 = (char *) data.image[ID].array.UI8; - ptr2 = (char *) data.image[IDshm].array.UI8; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_UINT8 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_INT16 : - ptr1 = (char *) data.image[ID].array.SI16; - ptr2 = (char *) data.image[IDshm].array.SI16; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_INT16 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_UINT16 : - ptr1 = (char *) data.image[ID].array.UI16; - ptr2 = (char *) data.image[IDshm].array.UI16; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_UINT16 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_INT32 : - ptr1 = (char *) data.image[ID].array.SI32; - ptr2 = (char *) data.image[IDshm].array.SI32; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_INT32 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_UINT32 : - ptr1 = (char *) data.image[ID].array.UI32; - ptr2 = (char *) data.image[IDshm].array.UI32; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_UINT32 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_INT64 : - ptr1 = (char *) data.image[ID].array.SI64; - ptr2 = (char *) data.image[IDshm].array.SI64; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_INT64 * data.image[ID].md[0].nelement); - break; - - case _DATATYPE_UINT64 : - ptr1 = (char *) data.image[ID].array.UI64; - ptr2 = (char *) data.image[IDshm].array.UI64; - memcpy((void *) ptr2, (void *) ptr1, - SIZEOF_DATATYPE_UINT64 * data.image[ID].md[0].nelement); - break; - - default : - printf("data type not supported\n"); - break; + case _DATATYPE_FLOAT: + ptr1 = (char *)data.image[ID].array.F; + ptr2 = (char *)data.image[IDshm].array.F; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_FLOAT * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_DOUBLE: + ptr1 = (char *)data.image[ID].array.D; + ptr2 = (char *)data.image[IDshm].array.D; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_DOUBLE * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_INT8: + ptr1 = (char *)data.image[ID].array.SI8; + ptr2 = (char *)data.image[IDshm].array.SI8; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_INT8 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_UINT8: + ptr1 = (char *)data.image[ID].array.UI8; + ptr2 = (char *)data.image[IDshm].array.UI8; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_UINT8 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_INT16: + ptr1 = (char *)data.image[ID].array.SI16; + ptr2 = (char *)data.image[IDshm].array.SI16; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_INT16 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_UINT16: + ptr1 = (char *)data.image[ID].array.UI16; + ptr2 = (char *)data.image[IDshm].array.UI16; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_UINT16 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_INT32: + ptr1 = (char *)data.image[ID].array.SI32; + ptr2 = (char *)data.image[IDshm].array.SI32; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_INT32 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_UINT32: + ptr1 = (char *)data.image[ID].array.UI32; + ptr2 = (char *)data.image[IDshm].array.UI32; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_UINT32 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_INT64: + ptr1 = (char *)data.image[ID].array.SI64; + ptr2 = (char *)data.image[IDshm].array.SI64; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_INT64 * data.image[ID].md[0].nelement); + break; + + case _DATATYPE_UINT64: + ptr1 = (char *)data.image[ID].array.UI64; + ptr2 = (char *)data.image[IDshm].array.UI64; + memcpy((void *)ptr2, (void *)ptr1, SIZEOF_DATATYPE_UINT64 * data.image[ID].md[0].nelement); + break; + + default: + printf("data type not supported\n"); + break; } // copy keywords - ptr1 = (char *) data.image[ID].kw; - ptr2 = (char *) data.image[IDshm].kw; - memcpy((void *) ptr2, (void *) ptr1, - sizeof(IMAGE_KEYWORD) * NBkw); + ptr1 = (char *)data.image[ID].kw; + ptr2 = (char *)data.image[IDshm].kw; + memcpy((void *)ptr2, (void *)ptr1, sizeof(IMAGE_KEYWORD) * NBkw); COREMOD_MEMORY_image_set_sempost_byID(IDshm, -1); data.image[IDshm].md[0].cnt0++; data.image[IDshm].md[0].write = 0; - - return RETURN_SUCCESS; } - // adding INSERT_STD_PROCINFO statements enables processinfo support static errno_t compute_function() { @@ -215,10 +168,7 @@ static errno_t compute_function() INSERT_STD_PROCINFO_COMPUTEFUNC_START - image_copy_shm( - makeIMGID(inimname), - outimname - ); + image_copy_shm(makeIMGID(inimname), outimname); INSERT_STD_PROCINFO_COMPUTEFUNC_END @@ -226,10 +176,10 @@ static errno_t compute_function() return RETURN_SUCCESS; } - INSERT_STD_FPSCLIfunctions -errno_t CLIADDCMD_COREMOD_memory__image_copy_shm() + errno_t + CLIADDCMD_COREMOD_memory__image_copy_shm() { INSERT_STD_CLIREGISTERFUNC return RETURN_SUCCESS; diff --git a/src/COREMOD_memory/image_keyword.c b/src/COREMOD_memory/image_keyword.c index e703a7b3..8dd07e11 100644 --- a/src/COREMOD_memory/image_keyword.c +++ b/src/COREMOD_memory/image_keyword.c @@ -2,43 +2,16 @@ * @file image_keyword.c */ - - #include "CommandLineInterface/CLIcore.h" #include "image_ID.h" - - - - - - - - - - - - - - - - // ========================================== // forward declarations // ========================================== -long image_write_keyword_L( - const char *IDname, - const char *kname, - long value, const - char *comment -); - -long image_list_keywords( - const char *IDname -); - +long image_write_keyword_L(const char *IDname, const char *kname, long value, const char *comment); +long image_list_keywords(const char *IDname); // ========================================== // command line interface wrapper functions @@ -46,19 +19,12 @@ long image_list_keywords( errno_t image_write_keyword_L__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_STR_NOT_IMG) - + CLI_checkarg(3, CLIARG_LONG) - + CLI_checkarg(4, CLIARG_STR_NOT_IMG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_STR_NOT_IMG) + CLI_checkarg(3, CLIARG_LONG) + + CLI_checkarg(4, CLIARG_STR_NOT_IMG) == + 0) { - image_write_keyword_L( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.string, - data.cmdargtoken[3].val.numl, - data.cmdargtoken[4].val.string - ); + image_write_keyword_L(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, + data.cmdargtoken[3].val.numl, data.cmdargtoken[4].val.string); return CLICMD_SUCCESS; } else @@ -67,14 +33,9 @@ errno_t image_write_keyword_L__cli() } } - - - errno_t image_list_keywords__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) == 0) { image_list_keywords(data.cmdargtoken[1].val.string); return CLICMD_SUCCESS; @@ -85,10 +46,6 @@ errno_t image_list_keywords__cli() } } - - - - // ========================================== // Register CLI commands // ========================================== @@ -96,57 +53,32 @@ errno_t image_list_keywords__cli() errno_t image_keyword_addCLIcmd() { RegisterCLIcommand( - "imwritekwL", - __FILE__, - image_write_keyword_L__cli, - "write long type keyword", - " ", - "imwritekwL im1 kw2 34 my_keyword_comment", + "imwritekwL", __FILE__, image_write_keyword_L__cli, "write long type keyword", + " ", "imwritekwL im1 kw2 34 my_keyword_comment", "long image_write_keyword_L(const char *IDname, const char *kname, long value, const char *comment)"); - RegisterCLIcommand( - "imlistkw", - __FILE__, - image_list_keywords__cli, - "list image keywords", - "", - "imlistkw im1", - "long image_list_keywords(const char *IDname)"); + RegisterCLIcommand("imlistkw", __FILE__, image_list_keywords__cli, "list image keywords", "", + "imlistkw im1", "long image_list_keywords(const char *IDname)"); return RETURN_SUCCESS; } - - - - - - - - - - -long image_write_keyword_L( - const char *IDname, - const char *kname, - long value, - const char *comment -) +long image_write_keyword_L(const char *IDname, const char *kname, long value, const char *comment) { - imageID ID; - long kw, NBkw, kw0; + imageID ID; + long kw, NBkw, kw0; ID = image_ID(IDname); NBkw = data.image[ID].md[0].NBkw; kw = 0; - while((data.image[ID].kw[kw].type != 'N') && (kw < NBkw)) + while ((data.image[ID].kw[kw].type != 'N') && (kw < NBkw)) { kw++; } kw0 = kw; - if(kw0 == NBkw) + if (kw0 == NBkw) { printf("ERROR: no available keyword entry\n"); exit(0); @@ -162,31 +94,24 @@ long image_write_keyword_L( return kw0; } - - -long image_write_keyword_D( - const char *IDname, - const char *kname, - double value, - const char *comment -) +long image_write_keyword_D(const char *IDname, const char *kname, double value, const char *comment) { - imageID ID; - long kw; - long NBkw; - long kw0; + imageID ID; + long kw; + long NBkw; + long kw0; ID = image_ID(IDname); NBkw = data.image[ID].md[0].NBkw; kw = 0; - while((data.image[ID].kw[kw].type != 'N') && (kw < NBkw)) + while ((data.image[ID].kw[kw].type != 'N') && (kw < NBkw)) { kw++; } kw0 = kw; - if(kw0 == NBkw) + if (kw0 == NBkw) { printf("ERROR: no available keyword entry\n"); exit(0); @@ -202,31 +127,24 @@ long image_write_keyword_D( return kw0; } - - -long image_write_keyword_S( - const char *IDname, - const char *kname, - const char *value, - const char *comment -) +long image_write_keyword_S(const char *IDname, const char *kname, const char *value, const char *comment) { imageID ID; - long kw; - long NBkw; - long kw0; + long kw; + long NBkw; + long kw0; ID = image_ID(IDname); NBkw = data.image[ID].md[0].NBkw; kw = 0; - while((data.image[ID].kw[kw].type != 'N') && (kw < NBkw)) + while ((data.image[ID].kw[kw].type != 'N') && (kw < NBkw)) { kw++; } kw0 = kw; - if(kw0 == NBkw) + if (kw0 == NBkw) { printf("ERROR: no available keyword entry\n"); exit(0); @@ -242,34 +160,29 @@ long image_write_keyword_S( return kw0; } - - - -imageID image_list_keywords( - const char *IDname -) +imageID image_list_keywords(const char *IDname) { imageID ID; - long kw; + long kw; ID = image_ID(IDname); - for(kw = 0; kw < data.image[ID].md[0].NBkw; kw++) + for (kw = 0; kw < data.image[ID].md[0].NBkw; kw++) { - if(data.image[ID].kw[kw].type == 'L') + if (data.image[ID].kw[kw].type == 'L') { - printf("%18s %20ld %s\n", data.image[ID].kw[kw].name, - data.image[ID].kw[kw].value.numl, data.image[ID].kw[kw].comment); + printf("%18s %20ld %s\n", data.image[ID].kw[kw].name, data.image[ID].kw[kw].value.numl, + data.image[ID].kw[kw].comment); } - if(data.image[ID].kw[kw].type == 'D') + if (data.image[ID].kw[kw].type == 'D') { - printf("%18s %20lf %s\n", data.image[ID].kw[kw].name, - data.image[ID].kw[kw].value.numf, data.image[ID].kw[kw].comment); + printf("%18s %20lf %s\n", data.image[ID].kw[kw].name, data.image[ID].kw[kw].value.numf, + data.image[ID].kw[kw].comment); } - if(data.image[ID].kw[kw].type == 'S') + if (data.image[ID].kw[kw].type == 'S') { - printf("%18s %20s %s\n", data.image[ID].kw[kw].name, - data.image[ID].kw[kw].value.valstr, data.image[ID].kw[kw].comment); + printf("%18s %20s %s\n", data.image[ID].kw[kw].name, data.image[ID].kw[kw].value.valstr, + data.image[ID].kw[kw].comment); } // if(data.image[ID].kw[kw].type=='N') // printf("-------------\n"); @@ -278,25 +191,17 @@ imageID image_list_keywords( return ID; } - - - -long image_read_keyword_D( - const char *IDname, - const char *kname, - double *val -) +long image_read_keyword_D(const char *IDname, const char *kname, double *val) { - variableID ID; - long kw; - long kw0; + variableID ID; + long kw; + long kw0; ID = image_ID(IDname); kw0 = -1; - for(kw = 0; kw < data.image[ID].md[0].NBkw; kw++) + for (kw = 0; kw < data.image[ID].md[0].NBkw; kw++) { - if((data.image[ID].kw[kw].type == 'D') - && (strncmp(kname, data.image[ID].kw[kw].name, strlen(kname)) == 0)) + if ((data.image[ID].kw[kw].type == 'D') && (strncmp(kname, data.image[ID].kw[kw].name, strlen(kname)) == 0)) { kw0 = kw; *val = data.image[ID].kw[kw].value.numf; @@ -306,24 +211,17 @@ long image_read_keyword_D( return kw0; } - - -long image_read_keyword_L( - const char *IDname, - const char *kname, - long *val -) +long image_read_keyword_L(const char *IDname, const char *kname, long *val) { variableID ID; - long kw; - long kw0; + long kw; + long kw0; ID = image_ID(IDname); kw0 = -1; - for(kw = 0; kw < data.image[ID].md[0].NBkw; kw++) + for (kw = 0; kw < data.image[ID].md[0].NBkw; kw++) { - if((data.image[ID].kw[kw].type == 'L') - && (strncmp(kname, data.image[ID].kw[kw].name, strlen(kname)) == 0)) + if ((data.image[ID].kw[kw].type == 'L') && (strncmp(kname, data.image[ID].kw[kw].name, strlen(kname)) == 0)) { kw0 = kw; *val = data.image[ID].kw[kw].value.numl; @@ -332,4 +230,3 @@ long image_read_keyword_L( return kw0; } - diff --git a/src/COREMOD_memory/image_keyword.h b/src/COREMOD_memory/image_keyword.h index c8e1c33d..b66dea63 100644 --- a/src/COREMOD_memory/image_keyword.h +++ b/src/COREMOD_memory/image_keyword.h @@ -2,46 +2,16 @@ * @file image_keyword.h */ - - - errno_t image_keyword_addCLIcmd(); +long image_write_keyword_L(const char *IDname, const char *kname, long value, const char *comment); +long image_write_keyword_D(const char *IDname, const char *kname, double value, const char *comment); -long image_write_keyword_L( - const char *IDname, - const char *kname, - long value, const - char *comment -); - -long image_write_keyword_D( - const char *IDname, - const char *kname, - double value, - const char *comment -); - -long image_write_keyword_S( - const char *IDname, - const char *kname, - const char *value, - const char *comment -); +long image_write_keyword_S(const char *IDname, const char *kname, const char *value, const char *comment); -long image_list_keywords( - const char *IDname -); +long image_list_keywords(const char *IDname); -long image_read_keyword_D( - const char *IDname, - const char *kname, - double *val -); +long image_read_keyword_D(const char *IDname, const char *kname, double *val); -long image_read_keyword_L( - const char *IDname, - const char *kname, - long *val -); +long image_read_keyword_L(const char *IDname, const char *kname, long *val); diff --git a/src/COREMOD_memory/image_keyword_addD.c b/src/COREMOD_memory/image_keyword_addD.c index 78e0fba1..92f83358 100644 --- a/src/COREMOD_memory/image_keyword_addD.c +++ b/src/COREMOD_memory/image_keyword_addD.c @@ -5,58 +5,28 @@ static char *kwname; static double *kwval; static char *comment; -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".in_name", "input image", "im1", - CLIARG_VISIBLE_DEFAULT, - (void **) &inimname, NULL - }, - { - CLIARG_STR, ".kwname", "keyword name", "KW1", - CLIARG_VISIBLE_DEFAULT, - (void **) &kwname, NULL - }, - { - CLIARG_FLOAT, ".kwval", "keyword value", "1.234", - CLIARG_VISIBLE_DEFAULT, - (void **) &kwval, NULL - }, - { - CLIARG_STR, ".comment", "comment", "keyword comment", - CLIARG_VISIBLE_DEFAULT, - (void **) &comment, NULL - } -}; - - -static CLICMDDATA CLIcmddata = -{ - "imkwaddD", - "add float type image keyword", - CLICMD_FIELDS_NOFPS -}; +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".in_name", "input image", "im1", CLIARG_VISIBLE_DEFAULT, (void **)&inimname, NULL}, + {CLIARG_STR, ".kwname", "keyword name", "KW1", CLIARG_VISIBLE_DEFAULT, (void **)&kwname, NULL}, + {CLIARG_FLOAT, ".kwval", "keyword value", "1.234", CLIARG_VISIBLE_DEFAULT, (void **)&kwval, NULL}, + {CLIARG_STR, ".comment", "comment", "keyword comment", CLIARG_VISIBLE_DEFAULT, (void **)&comment, NULL}}; +static CLICMDDATA CLIcmddata = {"imkwaddD", "add float type image keyword", CLICMD_FIELDS_NOFPS}; -errno_t image_keyword_addD( - IMGID img, - char *kwname, - double kwval, - char *comment -) +errno_t image_keyword_addD(IMGID img, char *kwname, double kwval, char *comment) { resolveIMGID(&img, ERRMODE_ABORT); int NBkw = img.md->NBkw; // max nb kw int kw = 0; - while((img.im->kw[kw].type != 'N') && (kw < NBkw)) + while ((img.im->kw[kw].type != 'N') && (kw < NBkw)) { kw++; } int kw0 = kw; - if(kw0 == NBkw) + if (kw0 == NBkw) { printf("ERROR: no available keyword entry\n"); abort(); @@ -72,28 +42,16 @@ errno_t image_keyword_addD( return RETURN_SUCCESS; } - - - - static errno_t compute_function() { - image_keyword_addD( - makeIMGID(inimname), - kwname, - *kwval, - comment - ); + image_keyword_addD(makeIMGID(inimname), kwname, *kwval, comment); return RETURN_SUCCESS; } - - INSERT_STD_CLIfunction - - -errno_t CLIADDCMD_COREMOD_memory__image_keyword_addD() + errno_t + CLIADDCMD_COREMOD_memory__image_keyword_addD() { INSERT_STD_CLIREGISTERFUNC diff --git a/src/COREMOD_memory/image_keyword_addD.h b/src/COREMOD_memory/image_keyword_addD.h index 9240f2b0..9fb2316e 100644 --- a/src/COREMOD_memory/image_keyword_addD.h +++ b/src/COREMOD_memory/image_keyword_addD.h @@ -1,12 +1,7 @@ #ifndef COREMOD_MEMORY_IMAGE_KEYWORD_ADDD_H #define COREMOD_MEMORY_IMAGE_KEYWORD_ADDD_H -errno_t image_keyword_addD( - IMGID img, - char *kwname, - double kwval, - char *comment -); +errno_t image_keyword_addD(IMGID img, char *kwname, double kwval, char *comment); errno_t CLIADDCMD_COREMOD_memory__image_keyword_addD(); diff --git a/src/COREMOD_memory/image_keyword_addL.c b/src/COREMOD_memory/image_keyword_addL.c index 008ac2a2..b6c34dd0 100644 --- a/src/COREMOD_memory/image_keyword_addL.c +++ b/src/COREMOD_memory/image_keyword_addL.c @@ -5,58 +5,28 @@ static char *kwname; static long *kwval; static char *comment; -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".in_name", "input image", "im1", - CLIARG_VISIBLE_DEFAULT, - (void **) &inimname, NULL - }, - { - CLIARG_STR, ".kwname", "keyword name", "KW1", - CLIARG_VISIBLE_DEFAULT, - (void **) &kwname, NULL - }, - { - CLIARG_LONG, ".kwval", "keyword value", "1", - CLIARG_VISIBLE_DEFAULT, - (void **) &kwval, NULL - }, - { - CLIARG_STR, ".comment", "comment", "keyword comment", - CLIARG_VISIBLE_DEFAULT, - (void **) &comment, NULL - } -}; - - -static CLICMDDATA CLIcmddata = -{ - "imkwaddL", - "add integer type image keyword", - CLICMD_FIELDS_NOFPS -}; +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".in_name", "input image", "im1", CLIARG_VISIBLE_DEFAULT, (void **)&inimname, NULL}, + {CLIARG_STR, ".kwname", "keyword name", "KW1", CLIARG_VISIBLE_DEFAULT, (void **)&kwname, NULL}, + {CLIARG_LONG, ".kwval", "keyword value", "1", CLIARG_VISIBLE_DEFAULT, (void **)&kwval, NULL}, + {CLIARG_STR, ".comment", "comment", "keyword comment", CLIARG_VISIBLE_DEFAULT, (void **)&comment, NULL}}; +static CLICMDDATA CLIcmddata = {"imkwaddL", "add integer type image keyword", CLICMD_FIELDS_NOFPS}; -errno_t image_keyword_addL( - IMGID img, - char *kwname, - long kwval, - char *comment -) +errno_t image_keyword_addL(IMGID img, char *kwname, long kwval, char *comment) { resolveIMGID(&img, ERRMODE_ABORT); int NBkw = img.md->NBkw; // max nb kw int kw = 0; - while((img.im->kw[kw].type != 'N') && (kw < NBkw)) + while ((img.im->kw[kw].type != 'N') && (kw < NBkw)) { kw++; } int kw0 = kw; - if(kw0 == NBkw) + if (kw0 == NBkw) { printf("ERROR: no available keyword entry\n"); abort(); @@ -72,28 +42,16 @@ errno_t image_keyword_addL( return RETURN_SUCCESS; } - - - - static errno_t compute_function() { - image_keyword_addL( - makeIMGID(inimname), - kwname, - *kwval, - comment - ); + image_keyword_addL(makeIMGID(inimname), kwname, *kwval, comment); return RETURN_SUCCESS; } - - INSERT_STD_CLIfunction - - -errno_t CLIADDCMD_COREMOD_memory__image_keyword_addL() + errno_t + CLIADDCMD_COREMOD_memory__image_keyword_addL() { INSERT_STD_CLIREGISTERFUNC diff --git a/src/COREMOD_memory/image_keyword_addL.h b/src/COREMOD_memory/image_keyword_addL.h index e304c27d..98b29543 100644 --- a/src/COREMOD_memory/image_keyword_addL.h +++ b/src/COREMOD_memory/image_keyword_addL.h @@ -1,12 +1,7 @@ #ifndef COREMOD_MEMORY_IMAGE_KEYWORD_ADDL_H #define COREMOD_MEMORY_IMAGE_KEYWORD_ADDL_H -errno_t image_keyword_addL( - IMGID img, - char *kwname, - long kwval, - char *comment -); +errno_t image_keyword_addL(IMGID img, char *kwname, long kwval, char *comment); errno_t CLIADDCMD_COREMOD_memory__image_keyword_addL(); diff --git a/src/COREMOD_memory/image_keyword_addS.c b/src/COREMOD_memory/image_keyword_addS.c index 20876dd8..2fb799db 100644 --- a/src/COREMOD_memory/image_keyword_addS.c +++ b/src/COREMOD_memory/image_keyword_addS.c @@ -5,58 +5,28 @@ static char *kwname; static char *kwval; static char *comment; -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".in_name", "input image", "im1", - CLIARG_VISIBLE_DEFAULT, - (void **) &inimname, NULL - }, - { - CLIARG_STR, ".kwname", "keyword name", "KW1", - CLIARG_VISIBLE_DEFAULT, - (void **) &kwname, NULL - }, - { - CLIARG_STR, ".kwval", "keyword value", "blue", - CLIARG_VISIBLE_DEFAULT, - (void **) &kwval, NULL - }, - { - CLIARG_STR, ".comment", "comment", "keyword comment", - CLIARG_VISIBLE_DEFAULT, - (void **) &comment, NULL - } -}; - - -static CLICMDDATA CLIcmddata = -{ - "imkwaddS", - "add string type image keyword", - CLICMD_FIELDS_NOFPS -}; +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".in_name", "input image", "im1", CLIARG_VISIBLE_DEFAULT, (void **)&inimname, NULL}, + {CLIARG_STR, ".kwname", "keyword name", "KW1", CLIARG_VISIBLE_DEFAULT, (void **)&kwname, NULL}, + {CLIARG_STR, ".kwval", "keyword value", "blue", CLIARG_VISIBLE_DEFAULT, (void **)&kwval, NULL}, + {CLIARG_STR, ".comment", "comment", "keyword comment", CLIARG_VISIBLE_DEFAULT, (void **)&comment, NULL}}; +static CLICMDDATA CLIcmddata = {"imkwaddS", "add string type image keyword", CLICMD_FIELDS_NOFPS}; -errno_t image_keyword_addS( - IMGID img, - char *kwname, - char *kwval, - char *comment -) +errno_t image_keyword_addS(IMGID img, char *kwname, char *kwval, char *comment) { resolveIMGID(&img, ERRMODE_ABORT); int NBkw = img.md->NBkw; // max nb kw int kw = 0; - while((img.im->kw[kw].type != 'N') && (kw < NBkw)) + while ((img.im->kw[kw].type != 'N') && (kw < NBkw)) { kw++; } int kw0 = kw; - if(kw0 == NBkw) + if (kw0 == NBkw) { printf("ERROR: no available keyword entry\n"); abort(); @@ -72,28 +42,16 @@ errno_t image_keyword_addS( return RETURN_SUCCESS; } - - - - static errno_t compute_function() { - image_keyword_addS( - makeIMGID(inimname), - kwname, - kwval, - comment - ); + image_keyword_addS(makeIMGID(inimname), kwname, kwval, comment); return RETURN_SUCCESS; } - - INSERT_STD_CLIfunction - - -errno_t CLIADDCMD_COREMOD_memory__image_keyword_addS() + errno_t + CLIADDCMD_COREMOD_memory__image_keyword_addS() { INSERT_STD_CLIREGISTERFUNC diff --git a/src/COREMOD_memory/image_keyword_addS.h b/src/COREMOD_memory/image_keyword_addS.h index 9b5465fc..b6c62554 100644 --- a/src/COREMOD_memory/image_keyword_addS.h +++ b/src/COREMOD_memory/image_keyword_addS.h @@ -1,12 +1,7 @@ #ifndef COREMOD_MEMORY_IMAGE_KEYWORD_ADDS_H #define COREMOD_MEMORY_IMAGE_KEYWORD_ADDS_H -errno_t image_keyword_addS( - IMGID img, - char *kwname, - char *kwval, - char *comment -); +errno_t image_keyword_addS(IMGID img, char *kwname, char *kwval, char *comment); errno_t CLIADDCMD_COREMOD_memory__image_keyword_addS(); diff --git a/src/COREMOD_memory/image_keyword_list.c b/src/COREMOD_memory/image_keyword_list.c index 8a22860b..de0efd2e 100644 --- a/src/COREMOD_memory/image_keyword_list.c +++ b/src/COREMOD_memory/image_keyword_list.c @@ -2,58 +2,40 @@ static char *inimname; -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".in_name", "input image", "im1", - CLIARG_VISIBLE_DEFAULT, - (void **) &inimname, NULL - } -}; +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".in_name", "input image", "im1", CLIARG_VISIBLE_DEFAULT, (void **)&inimname, NULL}}; +static CLICMDDATA CLIcmddata = {"imkwlist", "list image keywords", CLICMD_FIELDS_NOFPS}; -static CLICMDDATA CLIcmddata = -{ - "imkwlist", - "list image keywords", - CLICMD_FIELDS_NOFPS -}; - - -errno_t image_keywords_list( - IMGID img -) +errno_t image_keywords_list(IMGID img) { resolveIMGID(&img, ERRMODE_ABORT); int NBkw = img.md->NBkw; int kwcnt = 0; - for(int kw = 0; kw < NBkw; kw++) + for (int kw = 0; kw < NBkw; kw++) { char tmpkwvalstr[81]; - switch(img.im->kw[kw].type) + switch (img.im->kw[kw].type) { - case 'L': - printf("[L] %-8s= %20ld / %s\n", img.im->kw[kw].name, - img.im->kw[kw].value.numl, img.im->kw[kw].comment); - kwcnt++; - break; - - case 'D': - printf("[D] %-8s= %20g / %s\n", img.im->kw[kw].name, - img.im->kw[kw].value.numf, img.im->kw[kw].comment); - kwcnt++; - break; - - case 'S': - sprintf(tmpkwvalstr, "'%s'", img.im->kw[kw].value.valstr); - printf("[S] %-8s= %-20s / %s\n", img.im->kw[kw].name, - tmpkwvalstr, img.im->kw[kw].comment); - kwcnt++; - break; - - default: - break; + case 'L': + printf("[L] %-8s= %20ld / %s\n", img.im->kw[kw].name, img.im->kw[kw].value.numl, img.im->kw[kw].comment); + kwcnt++; + break; + + case 'D': + printf("[D] %-8s= %20g / %s\n", img.im->kw[kw].name, img.im->kw[kw].value.numf, img.im->kw[kw].comment); + kwcnt++; + break; + + case 'S': + sprintf(tmpkwvalstr, "'%s'", img.im->kw[kw].value.valstr); + printf("[S] %-8s= %-20s / %s\n", img.im->kw[kw].name, tmpkwvalstr, img.im->kw[kw].comment); + kwcnt++; + break; + + default: + break; } } @@ -62,22 +44,16 @@ errno_t image_keywords_list( return RETURN_SUCCESS; } - static errno_t compute_function() { - image_keywords_list( - makeIMGID(inimname) - ); + image_keywords_list(makeIMGID(inimname)); return RETURN_SUCCESS; } - - INSERT_STD_CLIfunction - - -errno_t CLIADDCMD_COREMOD_memory__image_keyword_list() + errno_t + CLIADDCMD_COREMOD_memory__image_keyword_list() { INSERT_STD_CLIREGISTERFUNC diff --git a/src/COREMOD_memory/image_keyword_list.h b/src/COREMOD_memory/image_keyword_list.h index c128c408..c3452c0f 100644 --- a/src/COREMOD_memory/image_keyword_list.h +++ b/src/COREMOD_memory/image_keyword_list.h @@ -1,9 +1,7 @@ #ifndef COREMOD_MEMORY_IMAGE_KEYWORD_LIST_H #define COREMOD_MEMORY_IMAGE_KEYWORD_LIST_H -errno_t image_keywords_list( - IMGID img -); +errno_t image_keywords_list(IMGID img); errno_t CLIADDCMD_COREMOD_memory__image_keyword_list(); diff --git a/src/COREMOD_memory/image_make2D.c b/src/COREMOD_memory/image_make2D.c index 8b39feee..017c6769 100644 --- a/src/COREMOD_memory/image_make2D.c +++ b/src/COREMOD_memory/image_make2D.c @@ -1,81 +1,48 @@ #include "CommandLineInterface/CLIcore.h" - - // Local variables pointers static char *outimname; static uint32_t *imxsize; static uint32_t *imysize; +static CLICMDARGDEF farg[] = { + {CLIARG_STR, ".out_name", "output image", "out1", CLIARG_VISIBLE_DEFAULT, (void **)&outimname, NULL}, + {CLIARG_LONG, ".xsize", "x size", "512", CLIARG_VISIBLE_DEFAULT, (void **)&imxsize, NULL}, + {CLIARG_LONG, ".ysize", "y size", "512", CLIARG_VISIBLE_DEFAULT, (void **)&imysize, NULL}}; - -static CLICMDARGDEF farg[] = -{ - { - CLIARG_STR, ".out_name", "output image", "out1", - CLIARG_VISIBLE_DEFAULT, - (void **) &outimname, NULL - }, - { - CLIARG_LONG, ".xsize", "x size", "512", - CLIARG_VISIBLE_DEFAULT, - (void **) &imxsize, NULL - }, - { - CLIARG_LONG, ".ysize", "y size", "512", - CLIARG_VISIBLE_DEFAULT, - (void **) &imysize, NULL - } -}; - -static CLICMDDATA CLIcmddata = -{ - "mk2Dim", - "make 2D image", - CLICMD_FIELDS_DEFAULTS -}; - - +static CLICMDDATA CLIcmddata = {"mk2Dim", "make 2D image", CLICMD_FIELDS_DEFAULTS}; // detailed help static errno_t help_function() { - printf( - "Create 2D image\n" - "File name can be appended with attribute:\n" - "For example: \"s>im1\", indicates a shared memory image (attribute \"s\")\n" - "Attributes list:\n" - " s> shared memory\n" - " k20> number of keyword=20\n" - " c5> 5-deep circular buffer for logging\n" - " tui8> type unsigned int 8-bit\n" - " tsi8> type signed int 8-bit\n" - " tui16> type unsigned int 16-bit\n" - " tsi16> type signed int 16-bit\n" - " tui32> type unsigned int 32-bit\n" - " tsi32> type signed int 32-bit\n" - " tui64> type unsigned int 64-bit\n" - " tf32> type float 32-bit\n" - " tf64> type float 64-bit\n" - ); + printf("Create 2D image\n" + "File name can be appended with attribute:\n" + "For example: \"s>im1\", indicates a shared memory image (attribute \"s\")\n" + "Attributes list:\n" + " s> shared memory\n" + " k20> number of keyword=20\n" + " c5> 5-deep circular buffer for logging\n" + " tui8> type unsigned int 8-bit\n" + " tsi8> type signed int 8-bit\n" + " tui16> type unsigned int 16-bit\n" + " tsi16> type signed int 16-bit\n" + " tui32> type unsigned int 32-bit\n" + " tsi32> type signed int 32-bit\n" + " tui64> type unsigned int 64-bit\n" + " tf32> type float 32-bit\n" + " tf64> type float 64-bit\n"); return RETURN_SUCCESS; } - - -static imageID make_2Dimage( - IMGID *img -) +static imageID make_2Dimage(IMGID *img) { // Create image if needed imcreateIMGID(img); - return(img->ID); + return (img->ID); } - - static errno_t compute_function() { DEBUG_TRACE_FSTART(); @@ -84,27 +51,21 @@ static errno_t compute_function() INSERT_STD_PROCINFO_COMPUTEFUNC_START - make_2Dimage( - &img - ); + make_2Dimage(&img); processinfo_update_output_stream(processinfo, img.ID); INSERT_STD_PROCINFO_COMPUTEFUNC_END - DEBUG_TRACE_FEXIT(); return RETURN_SUCCESS; } - - - INSERT_STD_FPSCLIfunctions -// Register function in CLI -errno_t CLIADDCMD_COREMOD_memory__mk2Dim() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_memory__mk2Dim() { INSERT_STD_CLIREGISTERFUNC return RETURN_SUCCESS; } - diff --git a/src/COREMOD_memory/image_make2D.h b/src/COREMOD_memory/image_make2D.h index dae4da6a..822052a7 100644 --- a/src/COREMOD_memory/image_make2D.h +++ b/src/COREMOD_memory/image_make2D.h @@ -3,4 +3,4 @@ errno_t CLIADDCMD_COREMOD_memory__mk2Dim(); -#endif \ No newline at end of file +#endif diff --git a/src/COREMOD_memory/image_make3D.c b/src/COREMOD_memory/image_make3D.c index ebbbdbf1..454f6f24 100644 --- a/src/COREMOD_memory/image_make3D.c +++ b/src/COREMOD_memory/image_make3D.c @@ -1,71 +1,34 @@ #include "CommandLineInterface/CLIcore.h" - - // Local variables pointers static char *outimname; static uint32_t *imxsize; static uint32_t *imysize; static uint32_t *imzsize; +static CLICMDARGDEF farg[] = { + {CLIARG_STR, ".out_name", "output image", "out1", CLIARG_VISIBLE_DEFAULT, (void **)&outimname, NULL}, + {CLIARG_LONG, ".xsize", "x size", "512", CLIARG_VISIBLE_DEFAULT, (void **)&imxsize, NULL}, + {CLIARG_LONG, ".ysize", "y size", "512", CLIARG_VISIBLE_DEFAULT, (void **)&imysize, NULL}, + {CLIARG_LONG, ".zsize", "z size", "512", CLIARG_VISIBLE_DEFAULT, (void **)&imzsize, NULL}}; -static CLICMDARGDEF farg[] = -{ - { - CLIARG_STR, ".out_name", "output image", "out1", - CLIARG_VISIBLE_DEFAULT, - (void **) &outimname, NULL - }, - { - CLIARG_LONG, ".xsize", "x size", "512", - CLIARG_VISIBLE_DEFAULT, - (void **) &imxsize, NULL - }, - { - CLIARG_LONG, ".ysize", "y size", "512", - CLIARG_VISIBLE_DEFAULT, - (void **) &imysize, NULL - }, - { - CLIARG_LONG, ".zsize", "z size", "512", - CLIARG_VISIBLE_DEFAULT, - (void **) &imzsize, NULL - } -}; - -static CLICMDDATA CLIcmddata = -{ - "mk3Dim", - "make 3D image\n" - "attributes: s> : shared\n" - " k20> : 20 keywords\n", - CLICMD_FIELDS_DEFAULTS -}; - - - +static CLICMDDATA CLIcmddata = {"mk3Dim", + "make 3D image\n" + "attributes: s> : shared\n" + " k20> : 20 keywords\n", + CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - - +static errno_t help_function() { return RETURN_SUCCESS; } - -static imageID make_3Dimage( - IMGID *img -) +static imageID make_3Dimage(IMGID *img) { // Create image if needed imcreateIMGID(img); - return(img->ID); + return (img->ID); } - - static errno_t compute_function() { DEBUG_TRACE_FSTART(); @@ -74,9 +37,7 @@ static errno_t compute_function() INSERT_STD_PROCINFO_COMPUTEFUNC_START - make_3Dimage( - &img - ); + make_3Dimage(&img); processinfo_update_output_stream(processinfo, img.ID); INSERT_STD_PROCINFO_COMPUTEFUNC_END @@ -85,15 +46,12 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - - INSERT_STD_FPSCLIfunctions -// Register function in CLI -errno_t CLIADDCMD_COREMOD_memory__mk3Dim() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_memory__mk3Dim() { INSERT_STD_CLIREGISTERFUNC return RETURN_SUCCESS; } - diff --git a/src/COREMOD_memory/image_make3D.h b/src/COREMOD_memory/image_make3D.h index 77ba21c6..9944ec9e 100644 --- a/src/COREMOD_memory/image_make3D.h +++ b/src/COREMOD_memory/image_make3D.h @@ -3,4 +3,4 @@ errno_t CLIADDCMD_COREMOD_memory__mk3Dim(); -#endif \ No newline at end of file +#endif diff --git a/src/COREMOD_memory/image_mk_amph_from_complex.c b/src/COREMOD_memory/image_mk_amph_from_complex.c index 0dc0b1d1..30ffe86e 100644 --- a/src/COREMOD_memory/image_mk_amph_from_complex.c +++ b/src/COREMOD_memory/image_mk_amph_from_complex.c @@ -2,159 +2,106 @@ #include "CommandLineInterface/CLIcore.h" - // Local variables pointers static char *inimname; static char *outampimname; static char *outphaimname; +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".imre_name", "input imaginary image", "imC", CLIARG_VISIBLE_DEFAULT, (void **)&inimname, NULL}, + {CLIARG_STR, ".imim_name", "output amplitude image", "outamp", CLIARG_VISIBLE_DEFAULT, (void **)&outampimname, + NULL}, + {CLIARG_STR, ".out_name", "output phase image", "outpha", CLIARG_VISIBLE_DEFAULT, (void **)&outphaimname, NULL}}; - - - -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".imre_name", "input imaginary image", "imC", - CLIARG_VISIBLE_DEFAULT, - (void **) &inimname, NULL - }, - { - CLIARG_STR, ".imim_name", "output amplitude image", "outamp", - CLIARG_VISIBLE_DEFAULT, - (void **) &outampimname, NULL - }, - { - CLIARG_STR, ".out_name", "output phase image", "outpha", - CLIARG_VISIBLE_DEFAULT, - (void **) &outphaimname, NULL - } -}; - -static CLICMDDATA CLIcmddata = -{ - "c2ap", - "complex -> ampl, pha", - CLICMD_FIELDS_DEFAULTS -}; - +static CLICMDDATA CLIcmddata = {"c2ap", "complex -> ampl, pha", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - +static errno_t help_function() { return RETURN_SUCCESS; } - - - - -errno_t mk_amph_from_complex( - const char *in_name, - const char *am_name, - const char *ph_name, - int sharedmem -) +errno_t mk_amph_from_complex(const char *in_name, const char *am_name, const char *ph_name, int sharedmem) { DEBUG_TRACE_FSTART(); - imageID IDam; - imageID IDph; - imageID IDin; - uint32_t naxes[3]; - uint8_t datatype; + imageID IDam; + imageID IDph; + imageID IDin; + uint32_t naxes[3]; + uint8_t datatype; IDin = image_ID(in_name); datatype = data.image[IDin].md[0].datatype; uint8_t naxis = data.image[IDin].md[0].naxis; - for(uint8_t i = 0; i < naxis; i++) + for (uint8_t i = 0; i < naxis; i++) { naxes[i] = data.image[IDin].md[0].size[i]; } uint64_t nelement = data.image[IDin].md[0].nelement; - if(datatype == _DATATYPE_COMPLEX_FLOAT) // single precision + if (datatype == _DATATYPE_COMPLEX_FLOAT) // single precision { FUNC_CHECK_RETURN( - create_image_ID(am_name, naxis, naxes, _DATATYPE_FLOAT, sharedmem, - data.NBKEYWORD_DFT, 0, &IDam) - ); + create_image_ID(am_name, naxis, naxes, _DATATYPE_FLOAT, sharedmem, data.NBKEYWORD_DFT, 0, &IDam)); FUNC_CHECK_RETURN( - create_image_ID(ph_name, naxis, naxes, _DATATYPE_FLOAT, sharedmem, - data.NBKEYWORD_DFT, 0, &IDph) - ); + create_image_ID(ph_name, naxis, naxes, _DATATYPE_FLOAT, sharedmem, data.NBKEYWORD_DFT, 0, &IDph)); data.image[IDam].md[0].write = 1; data.image[IDph].md[0].write = 1; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) private(ii,amp_f,pha_f) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) private(ii, amp_f, pha_f) { - #pragma omp for -# endif - for(uint64_t ii = 0; ii < nelement; ii++) +#pragma omp for +#endif + for (uint64_t ii = 0; ii < nelement; ii++) { - float amp_f = (float) sqrt(data.image[IDin].array.CF[ii].re * - data.image[IDin].array.CF[ii].re + data.image[IDin].array.CF[ii].im * - data.image[IDin].array.CF[ii].im); - float pha_f = (float) atan2(data.image[IDin].array.CF[ii].im, - data.image[IDin].array.CF[ii].re); + float amp_f = (float)sqrt(data.image[IDin].array.CF[ii].re * data.image[IDin].array.CF[ii].re + + data.image[IDin].array.CF[ii].im * data.image[IDin].array.CF[ii].im); + float pha_f = (float)atan2(data.image[IDin].array.CF[ii].im, data.image[IDin].array.CF[ii].re); data.image[IDam].array.F[ii] = amp_f; data.image[IDph].array.F[ii] = pha_f; } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif - if(sharedmem == 1) +#endif + if (sharedmem == 1) { - FUNC_CHECK_RETURN( - COREMOD_MEMORY_image_set_sempost_byID(IDam, -1) - ); + FUNC_CHECK_RETURN(COREMOD_MEMORY_image_set_sempost_byID(IDam, -1)); - FUNC_CHECK_RETURN( - COREMOD_MEMORY_image_set_sempost_byID(IDph, -1) - ); + FUNC_CHECK_RETURN(COREMOD_MEMORY_image_set_sempost_byID(IDph, -1)); } data.image[IDam].md[0].cnt0++; data.image[IDph].md[0].cnt0++; data.image[IDam].md[0].write = 0; data.image[IDph].md[0].write = 0; } - else if(datatype == _DATATYPE_COMPLEX_DOUBLE) // double precision + else if (datatype == _DATATYPE_COMPLEX_DOUBLE) // double precision { FUNC_CHECK_RETURN( - create_image_ID(am_name, naxis, naxes, _DATATYPE_DOUBLE, sharedmem, - data.NBKEYWORD_DFT, 0, &IDam) - ); + create_image_ID(am_name, naxis, naxes, _DATATYPE_DOUBLE, sharedmem, data.NBKEYWORD_DFT, 0, &IDam)); FUNC_CHECK_RETURN( - create_image_ID(ph_name, naxis, naxes, _DATATYPE_DOUBLE, sharedmem, - data.NBKEYWORD_DFT, 0, &IDph) - ); + create_image_ID(ph_name, naxis, naxes, _DATATYPE_DOUBLE, sharedmem, data.NBKEYWORD_DFT, 0, &IDph)); data.image[IDam].md[0].write = 1; data.image[IDph].md[0].write = 1; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) private(ii,amp_d,pha_d) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) private(ii, amp_d, pha_d) { - #pragma omp for -# endif - for(uint64_t ii = 0; ii < nelement; ii++) +#pragma omp for +#endif + for (uint64_t ii = 0; ii < nelement; ii++) { - double amp_d = sqrt(data.image[IDin].array.CD[ii].re * - data.image[IDin].array.CD[ii].re - + data.image[IDin].array.CD[ii].im * data.image[IDin].array.CD[ii].im); - double pha_d = atan2(data.image[IDin].array.CD[ii].im, - data.image[IDin].array.CD[ii].re); + double amp_d = sqrt(data.image[IDin].array.CD[ii].re * data.image[IDin].array.CD[ii].re + + data.image[IDin].array.CD[ii].im * data.image[IDin].array.CD[ii].im); + double pha_d = atan2(data.image[IDin].array.CD[ii].im, data.image[IDin].array.CD[ii].re); data.image[IDam].array.D[ii] = amp_d; data.image[IDph].array.D[ii] = pha_d; } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif - if(sharedmem == 1) +#endif + if (sharedmem == 1) { COREMOD_MEMORY_image_set_sempost_byID(IDam, -1); COREMOD_MEMORY_image_set_sempost_byID(IDph, -1); @@ -174,25 +121,13 @@ errno_t mk_amph_from_complex( return RETURN_SUCCESS; } - - - - - - static errno_t compute_function() { DEBUG_TRACE_FSTART(); - INSERT_STD_PROCINFO_COMPUTEFUNC_START - mk_amph_from_complex( - inimname, - outampimname, - outphaimname, - 0 - ); + mk_amph_from_complex(inimname, outampimname, outphaimname, 0); INSERT_STD_PROCINFO_COMPUTEFUNC_END @@ -200,15 +135,12 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - - INSERT_STD_FPSCLIfunctions -// Register function in CLI -errno_t CLIADDCMD_COREMOD__mk_amph_from_complex() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD__mk_amph_from_complex() { INSERT_STD_CLIREGISTERFUNC return RETURN_SUCCESS; } - diff --git a/src/COREMOD_memory/image_mk_amph_from_complex.h b/src/COREMOD_memory/image_mk_amph_from_complex.h index 6ffd1fd7..6080d8f7 100644 --- a/src/COREMOD_memory/image_mk_amph_from_complex.h +++ b/src/COREMOD_memory/image_mk_amph_from_complex.h @@ -1,12 +1,7 @@ #ifndef COREMOD_MEMORY_IMAGE_MK_AMPH_FROM_COMPLEX_H #define COREMOD_MEMORY_IMAGE_MK_AMPH_FROM_COMPLEX_H -errno_t mk_amph_from_complex( - const char *in_name, - const char *am_name, - const char *ph_name, - int sharedmem -); +errno_t mk_amph_from_complex(const char *in_name, const char *am_name, const char *ph_name, int sharedmem); errno_t CLIADDCMD_COREMOD__mk_amph_from_complex(); diff --git a/src/COREMOD_memory/image_mk_complex_from_amph.c b/src/COREMOD_memory/image_mk_complex_from_amph.c index e3a29c0e..b01746f9 100644 --- a/src/COREMOD_memory/image_mk_complex_from_amph.c +++ b/src/COREMOD_memory/image_mk_complex_from_amph.c @@ -2,74 +2,35 @@ #include "CommandLineInterface/CLIcore.h" - // Local variables pointers static char *inampimname; static char *inphaimname; static char *outimname; +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".imamp_name", "amplitude image", "imamp", CLIARG_VISIBLE_DEFAULT, (void **)&inampimname, NULL}, + {CLIARG_IMG, ".impha_name", "phase image", "impha", CLIARG_VISIBLE_DEFAULT, (void **)&inphaimname, NULL}, + {CLIARG_STR, ".out_name", "output complex image", "outim", CLIARG_VISIBLE_DEFAULT, (void **)&outimname, NULL}}; - - - -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".imamp_name", "amplitude image", "imamp", - CLIARG_VISIBLE_DEFAULT, - (void **) &inampimname, NULL - }, - { - CLIARG_IMG, ".impha_name", "phase image", "impha", - CLIARG_VISIBLE_DEFAULT, - (void **) &inphaimname, NULL - }, - { - CLIARG_STR, ".out_name", "output complex image", "outim", - CLIARG_VISIBLE_DEFAULT, - (void **) &outimname, NULL - } -}; - -static CLICMDDATA CLIcmddata = -{ - "ap2c", - "amplitude, phase -> complex", - CLICMD_FIELDS_DEFAULTS -}; - +static CLICMDDATA CLIcmddata = {"ap2c", "amplitude, phase -> complex", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} +static errno_t help_function() { return RETURN_SUCCESS; } - - - - - - -errno_t mk_complex_from_amph( - const char *am_name, - const char *ph_name, - const char *out_name, - int sharedmem -) +errno_t mk_complex_from_amph(const char *am_name, const char *ph_name, const char *out_name, int sharedmem) { DEBUG_TRACE_FSTART(); - imageID IDam; - imageID IDph; - imageID IDout; - uint32_t naxes[3]; - long naxis; - uint64_t nelement; - long i; - uint8_t datatype_am; - uint8_t datatype_ph; - uint8_t datatype_out; + imageID IDam; + imageID IDph; + imageID IDout; + uint32_t naxes[3]; + long naxis; + uint64_t nelement; + long i; + uint8_t datatype_am; + uint8_t datatype_ph; + uint8_t datatype_out; IDam = image_ID(am_name); IDph = image_ID(ph_name); @@ -77,116 +38,100 @@ errno_t mk_complex_from_amph( datatype_ph = data.image[IDph].md[0].datatype; naxis = data.image[IDam].md[0].naxis; - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[IDam].md[0].size[i]; } nelement = data.image[IDam].md[0].nelement; - if((datatype_am == _DATATYPE_FLOAT) && (datatype_ph == _DATATYPE_FLOAT)) + if ((datatype_am == _DATATYPE_FLOAT) && (datatype_ph == _DATATYPE_FLOAT)) { datatype_out = _DATATYPE_COMPLEX_FLOAT; FUNC_CHECK_RETURN( - create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, - data.NBKEYWORD_DFT, 0, &IDout) - ); + create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, data.NBKEYWORD_DFT, 0, &IDout)); data.image[IDout].md[0].write = 1; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { - #pragma omp for -# endif - for(uint64_t ii = 0; ii < nelement; ii++) +#pragma omp for +#endif + for (uint64_t ii = 0; ii < nelement; ii++) { - data.image[IDout].array.CF[ii].re = data.image[IDam].array.F[ii] * ((float) cos( - data.image[IDph].array.F[ii])); - data.image[IDout].array.CF[ii].im = data.image[IDam].array.F[ii] * ((float) sin( - data.image[IDph].array.F[ii])); + data.image[IDout].array.CF[ii].re = + data.image[IDam].array.F[ii] * ((float)cos(data.image[IDph].array.F[ii])); + data.image[IDout].array.CF[ii].im = + data.image[IDam].array.F[ii] * ((float)sin(data.image[IDph].array.F[ii])); } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif data.image[IDout].md[0].cnt0++; data.image[IDout].md[0].write = 0; - } - else if((datatype_am == _DATATYPE_FLOAT) && (datatype_ph == _DATATYPE_DOUBLE)) + else if ((datatype_am == _DATATYPE_FLOAT) && (datatype_ph == _DATATYPE_DOUBLE)) { datatype_out = _DATATYPE_COMPLEX_DOUBLE; FUNC_CHECK_RETURN( - create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, - data.NBKEYWORD_DFT, 0, &IDout) - ); + create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, data.NBKEYWORD_DFT, 0, &IDout)); data.image[IDout].md[0].write = 1; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { - #pragma omp for -# endif - for(uint64_t ii = 0; ii < nelement; ii++) +#pragma omp for +#endif + for (uint64_t ii = 0; ii < nelement; ii++) { - data.image[IDout].array.CD[ii].re = data.image[IDam].array.F[ii] * cos( - data.image[IDph].array.D[ii]); - data.image[IDout].array.CD[ii].im = data.image[IDam].array.F[ii] * sin( - data.image[IDph].array.D[ii]); + data.image[IDout].array.CD[ii].re = data.image[IDam].array.F[ii] * cos(data.image[IDph].array.D[ii]); + data.image[IDout].array.CD[ii].im = data.image[IDam].array.F[ii] * sin(data.image[IDph].array.D[ii]); } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif data.image[IDout].md[0].cnt0++; data.image[IDout].md[0].write = 0; } - else if((datatype_am == _DATATYPE_DOUBLE) && (datatype_ph == _DATATYPE_FLOAT)) + else if ((datatype_am == _DATATYPE_DOUBLE) && (datatype_ph == _DATATYPE_FLOAT)) { datatype_out = _DATATYPE_COMPLEX_DOUBLE; FUNC_CHECK_RETURN( - create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, - data.NBKEYWORD_DFT, 0, &IDout) - ); + create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, data.NBKEYWORD_DFT, 0, &IDout)); data.image[IDout].md[0].write = 1; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { - #pragma omp for -# endif - for(uint64_t ii = 0; ii < nelement; ii++) +#pragma omp for +#endif + for (uint64_t ii = 0; ii < nelement; ii++) { - data.image[IDout].array.CD[ii].re = data.image[IDam].array.D[ii] * cos( - data.image[IDph].array.F[ii]); - data.image[IDout].array.CD[ii].im = data.image[IDam].array.D[ii] * sin( - data.image[IDph].array.F[ii]); + data.image[IDout].array.CD[ii].re = data.image[IDam].array.D[ii] * cos(data.image[IDph].array.F[ii]); + data.image[IDout].array.CD[ii].im = data.image[IDam].array.D[ii] * sin(data.image[IDph].array.F[ii]); } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif data.image[IDout].md[0].cnt0++; data.image[IDout].md[0].write = 0; - } - else if((datatype_am == _DATATYPE_DOUBLE) && (datatype_ph == _DATATYPE_DOUBLE)) + else if ((datatype_am == _DATATYPE_DOUBLE) && (datatype_ph == _DATATYPE_DOUBLE)) { datatype_out = _DATATYPE_COMPLEX_DOUBLE; FUNC_CHECK_RETURN( - create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, - data.NBKEYWORD_DFT, 0, &IDout) - ); + create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, data.NBKEYWORD_DFT, 0, &IDout)); data.image[IDout].md[0].write = 1; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { - #pragma omp for -# endif - for(uint64_t ii = 0; ii < nelement; ii++) +#pragma omp for +#endif + for (uint64_t ii = 0; ii < nelement; ii++) { - data.image[IDout].array.CD[ii].re = data.image[IDam].array.D[ii] * cos( - data.image[IDph].array.D[ii]); - data.image[IDout].array.CD[ii].im = data.image[IDam].array.D[ii] * sin( - data.image[IDph].array.D[ii]); + data.image[IDout].array.CD[ii].re = data.image[IDam].array.D[ii] * cos(data.image[IDph].array.D[ii]); + data.image[IDout].array.CD[ii].im = data.image[IDam].array.D[ii] * sin(data.image[IDph].array.D[ii]); } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif +#endif data.image[IDout].md[0].cnt0++; data.image[IDout].md[0].write = 0; } @@ -200,21 +145,13 @@ errno_t mk_complex_from_amph( return RETURN_SUCCESS; } - - static errno_t compute_function() { DEBUG_TRACE_FSTART(); - INSERT_STD_PROCINFO_COMPUTEFUNC_START - mk_complex_from_amph( - inampimname, - inphaimname, - outimname, - 0 - ); + mk_complex_from_amph(inampimname, inphaimname, outimname, 0); INSERT_STD_PROCINFO_COMPUTEFUNC_END @@ -222,15 +159,12 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - - INSERT_STD_FPSCLIfunctions -// Register function in CLI -errno_t CLIADDCMD_COREMOD__mk_complex_from_amph() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD__mk_complex_from_amph() { INSERT_STD_CLIREGISTERFUNC return RETURN_SUCCESS; } - diff --git a/src/COREMOD_memory/image_mk_complex_from_amph.h b/src/COREMOD_memory/image_mk_complex_from_amph.h index a5e425f5..5849e268 100644 --- a/src/COREMOD_memory/image_mk_complex_from_amph.h +++ b/src/COREMOD_memory/image_mk_complex_from_amph.h @@ -1,12 +1,7 @@ #ifndef COREMOD_MEMORY_IMAGE_MK_COMPLEX_FROM_AMPH_H #define COREMOD_MEMORY_IMAGE_MK_COMPLEX_FROM_AMPH_H -errno_t mk_complex_from_amph( - const char *amp_name, - const char *pha_name, - const char *out_name, - int sharedmem -); +errno_t mk_complex_from_amph(const char *amp_name, const char *pha_name, const char *out_name, int sharedmem); errno_t CLIADDCMD_COREMOD__mk_complex_from_amph(); diff --git a/src/COREMOD_memory/image_mk_complex_from_reim.c b/src/COREMOD_memory/image_mk_complex_from_reim.c index 3005186e..47ad8423 100644 --- a/src/COREMOD_memory/image_mk_complex_from_reim.c +++ b/src/COREMOD_memory/image_mk_complex_from_reim.c @@ -2,71 +2,33 @@ #include "CommandLineInterface/CLIcore.h" - // Local variables pointers static char *inreimname; static char *inimimname; static char *outimname; +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".imre_name", "real image", "imre", CLIARG_VISIBLE_DEFAULT, (void **)&inreimname, NULL}, + {CLIARG_IMG, ".imim_name", "imaginary image", "imim", CLIARG_VISIBLE_DEFAULT, (void **)&inimimname, NULL}, + {CLIARG_STR, ".out_name", "output complex image", "outim", CLIARG_VISIBLE_DEFAULT, (void **)&outimname, NULL}}; - - - -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".imre_name", "real image", "imre", - CLIARG_VISIBLE_DEFAULT, - (void **) &inreimname, NULL - }, - { - CLIARG_IMG, ".imim_name", "imaginary image", "imim", - CLIARG_VISIBLE_DEFAULT, - (void **) &inimimname, NULL - }, - { - CLIARG_STR, ".out_name", "output complex image", "outim", - CLIARG_VISIBLE_DEFAULT, - (void **) &outimname, NULL - } -}; - -static CLICMDDATA CLIcmddata = -{ - "ri2c", - "real, imaginary -> complex", - CLICMD_FIELDS_DEFAULTS -}; - +static CLICMDDATA CLIcmddata = {"ri2c", "real, imaginary -> complex", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - - - +static errno_t help_function() { return RETURN_SUCCESS; } - - -errno_t mk_complex_from_reim( - const char *re_name, - const char *im_name, - const char *out_name, - int sharedmem -) +errno_t mk_complex_from_reim(const char *re_name, const char *im_name, const char *out_name, int sharedmem) { DEBUG_TRACE_FSTART(); - imageID IDre; - imageID IDim; - imageID IDout; - uint32_t *naxes = NULL; - int8_t naxis; - uint8_t datatype_re; - uint8_t datatype_im; - uint8_t datatype_out; + imageID IDre; + imageID IDim; + imageID IDout; + uint32_t *naxes = NULL; + int8_t naxis; + uint8_t datatype_re; + uint8_t datatype_im; + uint8_t datatype_out; IDre = image_ID(re_name); IDim = image_ID(im_name); @@ -75,67 +37,58 @@ errno_t mk_complex_from_reim( datatype_im = data.image[IDim].md[0].datatype; naxis = data.image[IDre].md[0].naxis; - naxes = (uint32_t *) malloc(sizeof(uint32_t) * naxis); - if(naxes == NULL) + naxes = (uint32_t *)malloc(sizeof(uint32_t) * naxis); + if (naxes == NULL) { PRINT_ERROR("malloc error"); abort(); } - for(int8_t i = 0; i < naxis; i++) + for (int8_t i = 0; i < naxis; i++) { naxes[i] = data.image[IDre].md[0].size[i]; } uint64_t nelement = data.image[IDre].md[0].nelement; - - if((datatype_re == _DATATYPE_FLOAT) && (datatype_im == _DATATYPE_FLOAT)) + if ((datatype_re == _DATATYPE_FLOAT) && (datatype_im == _DATATYPE_FLOAT)) { datatype_out = _DATATYPE_COMPLEX_FLOAT; FUNC_CHECK_RETURN( - create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, - data.NBKEYWORD_DFT, 0, &IDout) - ); - for(uint64_t ii = 0; ii < nelement; ii++) + create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, data.NBKEYWORD_DFT, 0, &IDout)); + for (uint64_t ii = 0; ii < nelement; ii++) { data.image[IDout].array.CF[ii].re = data.image[IDre].array.F[ii]; data.image[IDout].array.CF[ii].im = data.image[IDim].array.F[ii]; } } - else if((datatype_re == _DATATYPE_FLOAT) && (datatype_im == _DATATYPE_DOUBLE)) + else if ((datatype_re == _DATATYPE_FLOAT) && (datatype_im == _DATATYPE_DOUBLE)) { datatype_out = _DATATYPE_COMPLEX_DOUBLE; FUNC_CHECK_RETURN( - create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, - data.NBKEYWORD_DFT, 0, &IDout) - ); - for(uint64_t ii = 0; ii < nelement; ii++) + create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, data.NBKEYWORD_DFT, 0, &IDout)); + for (uint64_t ii = 0; ii < nelement; ii++) { data.image[IDout].array.CD[ii].re = data.image[IDre].array.F[ii]; data.image[IDout].array.CD[ii].im = data.image[IDim].array.D[ii]; } } - else if((datatype_re == _DATATYPE_DOUBLE) && (datatype_im == _DATATYPE_FLOAT)) + else if ((datatype_re == _DATATYPE_DOUBLE) && (datatype_im == _DATATYPE_FLOAT)) { datatype_out = _DATATYPE_COMPLEX_DOUBLE; FUNC_CHECK_RETURN( - create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, - data.NBKEYWORD_DFT, 0, &IDout) - ); - for(uint64_t ii = 0; ii < nelement; ii++) + create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, data.NBKEYWORD_DFT, 0, &IDout)); + for (uint64_t ii = 0; ii < nelement; ii++) { data.image[IDout].array.CD[ii].re = data.image[IDre].array.D[ii]; data.image[IDout].array.CD[ii].im = data.image[IDim].array.F[ii]; } } - else if((datatype_re == _DATATYPE_DOUBLE) && (datatype_im == _DATATYPE_DOUBLE)) + else if ((datatype_re == _DATATYPE_DOUBLE) && (datatype_im == _DATATYPE_DOUBLE)) { datatype_out = _DATATYPE_COMPLEX_DOUBLE; FUNC_CHECK_RETURN( - create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, - data.NBKEYWORD_DFT, 0, &IDout) - ); - for(uint64_t ii = 0; ii < nelement; ii++) + create_image_ID(out_name, naxis, naxes, datatype_out, sharedmem, data.NBKEYWORD_DFT, 0, &IDout)); + for (uint64_t ii = 0; ii < nelement; ii++) { data.image[IDout].array.CD[ii].re = data.image[IDre].array.D[ii]; data.image[IDout].array.CD[ii].im = data.image[IDim].array.D[ii]; @@ -154,21 +107,13 @@ errno_t mk_complex_from_reim( return RETURN_SUCCESS; } - - static errno_t compute_function() { DEBUG_TRACE_FSTART(); - INSERT_STD_PROCINFO_COMPUTEFUNC_START - mk_complex_from_reim( - inreimname, - inimimname, - outimname, - 0 - ); + mk_complex_from_reim(inreimname, inimimname, outimname, 0); INSERT_STD_PROCINFO_COMPUTEFUNC_END @@ -176,15 +121,12 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - - INSERT_STD_FPSCLIfunctions -// Register function in CLI -errno_t CLIADDCMD_COREMOD__mk_complex_from_reim() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD__mk_complex_from_reim() { INSERT_STD_CLIREGISTERFUNC return RETURN_SUCCESS; } - diff --git a/src/COREMOD_memory/image_mk_complex_from_reim.h b/src/COREMOD_memory/image_mk_complex_from_reim.h index 61c1e184..8cc59985 100644 --- a/src/COREMOD_memory/image_mk_complex_from_reim.h +++ b/src/COREMOD_memory/image_mk_complex_from_reim.h @@ -1,12 +1,7 @@ #ifndef COREMOD_MEMORY_IMAGE_MK_COMPLEX_FROM_REIM_H #define COREMOD_MEMORY_IMAGE_MK_COMPLEX_FROM_REIM_H -errno_t mk_complex_from_reim( - const char *re_name, - const char *im_name, - const char *out_name, - int sharedmem -); +errno_t mk_complex_from_reim(const char *re_name, const char *im_name, const char *out_name, int sharedmem); errno_t CLIADDCMD_COREMOD__mk_complex_from_reim(); diff --git a/src/COREMOD_memory/image_mk_reim_from_complex.c b/src/COREMOD_memory/image_mk_reim_from_complex.c index 4b899be8..d84abe58 100644 --- a/src/COREMOD_memory/image_mk_reim_from_complex.c +++ b/src/COREMOD_memory/image_mk_reim_from_complex.c @@ -2,109 +2,67 @@ #include "CommandLineInterface/CLIcore.h" - // Local variables pointers static char *inimname; static char *outreimname; static char *outimimname; +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".imre_name", "input imaginary image", "imC", CLIARG_VISIBLE_DEFAULT, (void **)&inimname, NULL}, + {CLIARG_STR, ".imim_name", "output real image", "outre", CLIARG_VISIBLE_DEFAULT, (void **)&outreimname, NULL}, + {CLIARG_STR, ".out_name", "output imaginary image", "outim", CLIARG_VISIBLE_DEFAULT, (void **)&outimimname, NULL}}; - - - -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".imre_name", "input imaginary image", "imC", - CLIARG_VISIBLE_DEFAULT, - (void **) &inimname, NULL - }, - { - CLIARG_STR, ".imim_name", "output real image", "outre", - CLIARG_VISIBLE_DEFAULT, - (void **) &outreimname, NULL - }, - { - CLIARG_STR, ".out_name", "output imaginary image", "outim", - CLIARG_VISIBLE_DEFAULT, - (void **) &outimimname, NULL - } -}; - -static CLICMDDATA CLIcmddata = -{ - "c2ap", - "complex -> re, im", - CLICMD_FIELDS_DEFAULTS -}; - +static CLICMDDATA CLIcmddata = {"c2ap", "complex -> re, im", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - +static errno_t help_function() { return RETURN_SUCCESS; } - - - - -errno_t mk_reim_from_complex( - const char *in_name, - const char *re_name, - const char *im_name, - int sharedmem -) +errno_t mk_reim_from_complex(const char *in_name, const char *re_name, const char *im_name, int sharedmem) { DEBUG_TRACE_FSTART(); - imageID IDre; - imageID IDim; - imageID IDin; - uint32_t naxes[3]; - long naxis; - uint64_t nelement; - long i; - uint8_t datatype; + imageID IDre; + imageID IDim; + imageID IDin; + uint32_t naxes[3]; + long naxis; + uint64_t nelement; + long i; + uint8_t datatype; IDin = image_ID(in_name); datatype = data.image[IDin].md[0].datatype; naxis = data.image[IDin].md[0].naxis; - for(i = 0; i < naxis; i++) + for (i = 0; i < naxis; i++) { naxes[i] = data.image[IDin].md[0].size[i]; } nelement = data.image[IDin].md[0].nelement; - if(datatype == _DATATYPE_COMPLEX_FLOAT) // single precision + if (datatype == _DATATYPE_COMPLEX_FLOAT) // single precision { FUNC_CHECK_RETURN( - create_image_ID(re_name, naxis, naxes, _DATATYPE_FLOAT, sharedmem, - data.NBKEYWORD_DFT, 0, &IDre) - ); + create_image_ID(re_name, naxis, naxes, _DATATYPE_FLOAT, sharedmem, data.NBKEYWORD_DFT, 0, &IDre)); FUNC_CHECK_RETURN( - create_image_ID(im_name, naxis, naxes, _DATATYPE_FLOAT, sharedmem, - data.NBKEYWORD_DFT, 0, &IDim) - ); + create_image_ID(im_name, naxis, naxes, _DATATYPE_FLOAT, sharedmem, data.NBKEYWORD_DFT, 0, &IDim)); data.image[IDre].md[0].write = 1; data.image[IDim].md[0].write = 1; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { - #pragma omp for -# endif - for(uint64_t ii = 0; ii < nelement; ii++) +#pragma omp for +#endif + for (uint64_t ii = 0; ii < nelement; ii++) { data.image[IDre].array.F[ii] = data.image[IDin].array.CF[ii].re; data.image[IDim].array.F[ii] = data.image[IDin].array.CF[ii].im; } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif - if(sharedmem == 1) +#endif + if (sharedmem == 1) { COREMOD_MEMORY_image_set_sempost_byID(IDre, -1); COREMOD_MEMORY_image_set_sempost_byID(IDim, -1); @@ -114,33 +72,29 @@ errno_t mk_reim_from_complex( data.image[IDre].md[0].write = 0; data.image[IDim].md[0].write = 0; } - else if(datatype == _DATATYPE_COMPLEX_DOUBLE) // double precision + else if (datatype == _DATATYPE_COMPLEX_DOUBLE) // double precision { FUNC_CHECK_RETURN( - create_image_ID(re_name, naxis, naxes, _DATATYPE_DOUBLE, sharedmem, - data.NBKEYWORD_DFT, 0, &IDre) - ); + create_image_ID(re_name, naxis, naxes, _DATATYPE_DOUBLE, sharedmem, data.NBKEYWORD_DFT, 0, &IDre)); FUNC_CHECK_RETURN( - create_image_ID(im_name, naxis, naxes, _DATATYPE_DOUBLE, sharedmem, - data.NBKEYWORD_DFT, 0, &IDim) - ); + create_image_ID(im_name, naxis, naxes, _DATATYPE_DOUBLE, sharedmem, data.NBKEYWORD_DFT, 0, &IDim)); data.image[IDre].md[0].write = 1; data.image[IDim].md[0].write = 1; -# ifdef _OPENMP - #pragma omp parallel if (nelement>OMP_NELEMENT_LIMIT) +#ifdef _OPENMP +#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT) { - #pragma omp for -# endif - for(uint64_t ii = 0; ii < nelement; ii++) +#pragma omp for +#endif + for (uint64_t ii = 0; ii < nelement; ii++) { data.image[IDre].array.D[ii] = data.image[IDin].array.CD[ii].re; data.image[IDim].array.D[ii] = data.image[IDin].array.CD[ii].im; } -# ifdef _OPENMP +#ifdef _OPENMP } -# endif - if(sharedmem == 1) +#endif + if (sharedmem == 1) { COREMOD_MEMORY_image_set_sempost_byID(IDre, -1); COREMOD_MEMORY_image_set_sempost_byID(IDim, -1); @@ -149,7 +103,6 @@ errno_t mk_reim_from_complex( data.image[IDim].md[0].cnt0++; data.image[IDre].md[0].write = 0; data.image[IDim].md[0].write = 0; - } else { @@ -161,25 +114,13 @@ errno_t mk_reim_from_complex( return RETURN_SUCCESS; } - - - - - - static errno_t compute_function() { DEBUG_TRACE_FSTART(); - INSERT_STD_PROCINFO_COMPUTEFUNC_START - mk_reim_from_complex( - inimname, - outreimname, - outimimname, - 0 - ); + mk_reim_from_complex(inimname, outreimname, outimimname, 0); INSERT_STD_PROCINFO_COMPUTEFUNC_END @@ -187,15 +128,12 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - - INSERT_STD_FPSCLIfunctions -// Register function in CLI -errno_t CLIADDCMD_COREMOD__mk_reim_from_complex() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD__mk_reim_from_complex() { INSERT_STD_CLIREGISTERFUNC return RETURN_SUCCESS; } - diff --git a/src/COREMOD_memory/image_mk_reim_from_complex.h b/src/COREMOD_memory/image_mk_reim_from_complex.h index 6564ac8c..fa0f1109 100644 --- a/src/COREMOD_memory/image_mk_reim_from_complex.h +++ b/src/COREMOD_memory/image_mk_reim_from_complex.h @@ -1,12 +1,7 @@ #ifndef COREMOD_MEMORY_IMAGE_MK_REIM_FROM_COMPLEX_H #define COREMOD_MEMORY_IMAGE_MK_REIM_FROM_COMPLEX_H -errno_t mk_reim_from_complex( - const char *in_name, - const char *re_name, - const char *im_name, - int sharedmem -); +errno_t mk_reim_from_complex(const char *in_name, const char *re_name, const char *im_name, int sharedmem); errno_t CLIADDCMD_COREMOD__mk_reim_from_complex(); diff --git a/src/COREMOD_memory/image_set_counters.c b/src/COREMOD_memory/image_set_counters.c index 64801c69..0a0f3793 100644 --- a/src/COREMOD_memory/image_set_counters.c +++ b/src/COREMOD_memory/image_set_counters.c @@ -1,53 +1,30 @@ /** * @file image_set_couters.c - * @brief SET IMAGE FLAGS / COUNTERS + * @brief SET IMAGE FLAGS / COUNTERS */ #include "CommandLineInterface/CLIcore.h" #include "image_ID.h" - - - - // ========================================== // Forward declaration(s) // ========================================== +errno_t COREMOD_MEMORY_image_set_status(const char *IDname, int status); -errno_t COREMOD_MEMORY_image_set_status( - const char *IDname, - int status -); - -errno_t COREMOD_MEMORY_image_set_cnt0( - const char *IDname, - int cnt0 -); - -errno_t COREMOD_MEMORY_image_set_cnt1( - const char *IDname, - int cnt1 -); - +errno_t COREMOD_MEMORY_image_set_cnt0(const char *IDname, int cnt0); +errno_t COREMOD_MEMORY_image_set_cnt1(const char *IDname, int cnt1); // ========================================== // Command line interface wrapper function(s) // ========================================== - static errno_t COREMOD_MEMORY_image_set_status__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { - COREMOD_MEMORY_image_set_status( - data.cmdargtoken[1].val.string, - (int) data.cmdargtoken[2].val.numl - ); + COREMOD_MEMORY_image_set_status(data.cmdargtoken[1].val.string, (int)data.cmdargtoken[2].val.numl); return CLICMD_SUCCESS; } else @@ -56,18 +33,11 @@ static errno_t COREMOD_MEMORY_image_set_status__cli() } } - static errno_t COREMOD_MEMORY_image_set_cnt0__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { - COREMOD_MEMORY_image_set_cnt0( - data.cmdargtoken[1].val.string, - (int) data.cmdargtoken[2].val.numl - ); + COREMOD_MEMORY_image_set_cnt0(data.cmdargtoken[1].val.string, (int)data.cmdargtoken[2].val.numl); return CLICMD_SUCCESS; } else @@ -76,18 +46,11 @@ static errno_t COREMOD_MEMORY_image_set_cnt0__cli() } } - static errno_t COREMOD_MEMORY_image_set_cnt1__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { - COREMOD_MEMORY_image_set_cnt1( - data.cmdargtoken[1].val.string, - (int) data.cmdargtoken[2].val.numl - ); + COREMOD_MEMORY_image_set_cnt1(data.cmdargtoken[1].val.string, (int)data.cmdargtoken[2].val.numl); return CLICMD_SUCCESS; } else @@ -96,51 +59,28 @@ static errno_t COREMOD_MEMORY_image_set_cnt1__cli() } } - - - // ========================================== // Register CLI command(s) // ========================================== errno_t image_set_counters_addCLIcmd() { - RegisterCLIcommand( - "imsetstatus", - __FILE__, - COREMOD_MEMORY_image_set_status__cli, - "set image status variable", " ", - "imsetstatus im1 2", - "long COREMOD_MEMORY_image_set_status(const char *IDname, int status)"); - - RegisterCLIcommand( - "imsetcnt0", - __FILE__, - COREMOD_MEMORY_image_set_cnt0__cli, - "set image cnt0 variable", " ", - "imsetcnt0 im1 2", - "long COREMOD_MEMORY_image_set_cnt0(const char *IDname, int status)"); - - RegisterCLIcommand( - "imsetcnt1", - __FILE__, - COREMOD_MEMORY_image_set_cnt1__cli, - "set image cnt1 variable", " ", - "imsetcnt1 im1 2", - "long COREMOD_MEMORY_image_set_cnt1(const char *IDname, int status)"); - - return RETURN_SUCCESS; -} - - + RegisterCLIcommand("imsetstatus", __FILE__, COREMOD_MEMORY_image_set_status__cli, "set image status variable", + " ", "imsetstatus im1 2", + "long COREMOD_MEMORY_image_set_status(const char *IDname, int status)"); + RegisterCLIcommand("imsetcnt0", __FILE__, COREMOD_MEMORY_image_set_cnt0__cli, "set image cnt0 variable", + " ", "imsetcnt0 im1 2", + "long COREMOD_MEMORY_image_set_cnt0(const char *IDname, int status)"); + RegisterCLIcommand("imsetcnt1", __FILE__, COREMOD_MEMORY_image_set_cnt1__cli, "set image cnt1 variable", + " ", "imsetcnt1 im1 2", + "long COREMOD_MEMORY_image_set_cnt1(const char *IDname, int status)"); + return RETURN_SUCCESS; +} -errno_t COREMOD_MEMORY_image_set_status( - const char *IDname, - int status -) +errno_t COREMOD_MEMORY_image_set_status(const char *IDname, int status) { imageID ID; @@ -150,11 +90,7 @@ errno_t COREMOD_MEMORY_image_set_status( return RETURN_SUCCESS; } - -errno_t COREMOD_MEMORY_image_set_cnt0( - const char *IDname, - int cnt0 -) +errno_t COREMOD_MEMORY_image_set_cnt0(const char *IDname, int cnt0) { imageID ID; @@ -164,11 +100,7 @@ errno_t COREMOD_MEMORY_image_set_cnt0( return RETURN_SUCCESS; } - -errno_t COREMOD_MEMORY_image_set_cnt1( - const char *IDname, - int cnt1 -) +errno_t COREMOD_MEMORY_image_set_cnt1(const char *IDname, int cnt1) { imageID ID; @@ -177,6 +109,3 @@ errno_t COREMOD_MEMORY_image_set_cnt1( return RETURN_SUCCESS; } - - - diff --git a/src/COREMOD_memory/image_set_counters.h b/src/COREMOD_memory/image_set_counters.h index 02f4c5ba..6ea6b92f 100644 --- a/src/COREMOD_memory/image_set_counters.h +++ b/src/COREMOD_memory/image_set_counters.h @@ -2,24 +2,10 @@ * @file image_set_couters.h */ - - errno_t image_set_counters_addCLIcmd(); +errno_t COREMOD_MEMORY_image_set_status(const char *IDname, int status); +errno_t COREMOD_MEMORY_image_set_cnt0(const char *IDname, int cnt0); - -errno_t COREMOD_MEMORY_image_set_status( - const char *IDname, - int status -); - -errno_t COREMOD_MEMORY_image_set_cnt0( - const char *IDname, - int cnt0 -); - -errno_t COREMOD_MEMORY_image_set_cnt1( - const char *IDname, - int cnt1 -); +errno_t COREMOD_MEMORY_image_set_cnt1(const char *IDname, int cnt1); diff --git a/src/COREMOD_memory/list_image.c b/src/COREMOD_memory/list_image.c index f68efddc..27d9bb15 100644 --- a/src/COREMOD_memory/list_image.c +++ b/src/COREMOD_memory/list_image.c @@ -3,18 +3,15 @@ * @brief list images */ - #include #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" -#include "compute_nb_image.h" #include "compute_image_memory.h" - +#include "compute_nb_image.h" +#include "image_ID.h" #define STYPESIZE 10 - // MEMORY MONITOR static FILE *listim_scr_fpo; static FILE *listim_scr_fpi; @@ -23,101 +20,58 @@ static SCREEN *listim_scr; // for memory monitoring static int listim_scr_wrow; static int listim_scr_wcol; - - - - // ========================================== // Forward declaration(s) // ========================================== -errno_t memory_monitor( - const char *termttyname -); - +errno_t memory_monitor(const char *termttyname); -errno_t init_list_image_ID_ncurses( - const char *termttyname -); +errno_t init_list_image_ID_ncurses(const char *termttyname); void close_list_image_ID_ncurses(); errno_t list_image_ID_ncurses(); -errno_t list_image_ID_ofp( - FILE *fo -); +errno_t list_image_ID_ofp(FILE *fo); -errno_t list_image_ID_ofp_simple( - FILE *fo -); +errno_t list_image_ID_ofp_simple(FILE *fo); errno_t list_image_ID(); -errno_t list_image_ID_file( - const char *fname -); +errno_t list_image_ID_file(const char *fname); errno_t list_variable_ID(); -errno_t list_variable_ID_file( - const char *fname -); - - +errno_t list_variable_ID_file(const char *fname); // ========================================== // Command line interface wrapper function(s) // ========================================== - static errno_t memory_monitor__cli() { memory_monitor(data.cmdargtoken[1].val.string); return CLICMD_SUCCESS; } - - - // ========================================== // Register CLI command(s) // ========================================== errno_t list_image_addCLIcmd() { - RegisterCLIcommand( - "mmon", - __FILE__, - memory_monitor__cli, - "Monitor memory content", - "terminal tty name", - "mmon /dev/pts/4", - "int memory_monitor(const char *ttyname)"); - - RegisterCLIcommand( - "listim", - __FILE__, - list_image_ID, - "list images in memory", - "no argument", - "listim", "errno_t list_image_ID()"); + RegisterCLIcommand("mmon", __FILE__, memory_monitor__cli, "Monitor memory content", "terminal tty name", + "mmon /dev/pts/4", "int memory_monitor(const char *ttyname)"); + + RegisterCLIcommand("listim", __FILE__, list_image_ID, "list images in memory", "no argument", "listim", + "errno_t list_image_ID()"); return RETURN_SUCCESS; } - - - - - - - -errno_t init_list_image_ID_ncurses( - const char *termttyname -) +errno_t init_list_image_ID_ncurses(const char *termttyname) { -// int wrow, wcol; + // int wrow, wcol; listim_scr_fpi = fopen(termttyname, "r"); listim_scr_fpo = fopen(termttyname, "w"); @@ -138,26 +92,20 @@ errno_t init_list_image_ID_ncurses( return RETURN_SUCCESS; } - - - - - - errno_t list_image_ID_ncurses() { - char str[300]; - char str1[500]; - char str2[512]; - long i, j; + char str[300]; + char str1[500]; + char str2[512]; + long i, j; long long tmp_long; - char type[STYPESIZE]; - uint8_t datatype; - int n; - uint64_t sizeb, sizeKb, sizeMb, sizeGb; + char type[STYPESIZE]; + uint8_t datatype; + int n; + uint64_t sizeb, sizeKb, sizeMb, sizeGb; - struct timespec timenow; - double timediff; + struct timespec timenow; + double timediff; clock_gettime(CLOCK_REALTIME, &timenow); @@ -165,21 +113,19 @@ errno_t list_image_ID_ncurses() clear(); - sizeb = compute_image_memory(); - printw("INDEX NAME SIZE TYPE SIZE [percent] LAST ACCESS\n"); printw("\n"); - for(i = 0; i < data.NB_MAX_IMAGE; i++) + for (i = 0; i < data.NB_MAX_IMAGE; i++) { - if(data.image[i].used == 1) + if (data.image[i].used == 1) { datatype = data.image[i].md[0].datatype; tmp_long = ((long long)(data.image[i].md[0].nelement)) * ImageStreamIO_typesize(datatype); - if(data.image[i].md[0].shared == 1) + if (data.image[i].md[0].shared == 1) { printw("%4ldS", i); } @@ -188,7 +134,7 @@ errno_t list_image_ID_ncurses() printw("%4ld ", i); } - if(data.image[i].md[0].shared == 1) + if (data.image[i].md[0].shared == 1) { attron(A_BOLD | COLOR_PAIR(9)); } @@ -199,7 +145,7 @@ errno_t list_image_ID_ncurses() sprintf(str, "%10s ", data.image[i].name); printw(str); - if(data.image[i].md[0].shared == 1) + if (data.image[i].md[0].shared == 1) { attroff(A_BOLD | COLOR_PAIR(9)); } @@ -208,11 +154,11 @@ errno_t list_image_ID_ncurses() attroff(A_BOLD | COLOR_PAIR(6)); } - sprintf(str, "[ %6ld", (long) data.image[i].md[0].size[0]); + sprintf(str, "[ %6ld", (long)data.image[i].md[0].size[0]); - for(j = 1; j < data.image[i].md[0].naxis; j++) + for (j = 1; j < data.image[i].md[0].naxis; j++) { - sprintf(str1, "%s x %6ld", str, (long) data.image[i].md[0].size[j]); + sprintf(str1, "%s x %6ld", str, (long)data.image[i].md[0].size[j]); } sprintf(str2, "%s]", str1); @@ -221,51 +167,51 @@ errno_t list_image_ID_ncurses() attron(COLOR_PAIR(3)); n = 0; - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { n = snprintf(type, STYPESIZE, "UINT8 "); } - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { n = snprintf(type, STYPESIZE, "INT8 "); } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { n = snprintf(type, STYPESIZE, "UINT16 "); } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { n = snprintf(type, STYPESIZE, "INT16 "); } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { n = snprintf(type, STYPESIZE, "UINT32 "); } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { n = snprintf(type, STYPESIZE, "INT32 "); } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { n = snprintf(type, STYPESIZE, "UINT64 "); } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { n = snprintf(type, STYPESIZE, "INT64 "); } - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { n = snprintf(type, STYPESIZE, "FLOAT "); } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { n = snprintf(type, STYPESIZE, "DOUBLE "); } - if(datatype == _DATATYPE_COMPLEX_FLOAT) + if (datatype == _DATATYPE_COMPLEX_FLOAT) { n = snprintf(type, STYPESIZE, "CFLOAT "); } - if(datatype == _DATATYPE_COMPLEX_DOUBLE) + if (datatype == _DATATYPE_COMPLEX_DOUBLE) { n = snprintf(type, STYPESIZE, "CDOUBLE"); } @@ -274,18 +220,18 @@ errno_t list_image_ID_ncurses() attroff(COLOR_PAIR(3)); - if(n >= STYPESIZE) { + if (n >= STYPESIZE) + { PRINT_ERROR("Attempted to write string buffer with too many characters"); - } + } - printw("%10ld Kb %6.2f ", (long)(tmp_long / 1024), - (float)(100.0 * tmp_long / sizeb)); + printw("%10ld Kb %6.2f ", (long)(tmp_long / 1024), (float)(100.0 * tmp_long / sizeb)); timediff = (1.0 * timenow.tv_sec + 0.000000001 * timenow.tv_nsec) - - (1.0 * data.image[i].md[0].lastaccesstime.tv_sec + 0.000000001 * - data.image[i].md[0].lastaccesstime.tv_nsec); + (1.0 * data.image[i].md[0].lastaccesstime.tv_sec + + 0.000000001 * data.image[i].md[0].lastaccesstime.tv_nsec); - if(timediff < 0.01) + if (timediff < 0.01) { attron(COLOR_PAIR(4)); printw("%15.9f\n", timediff); @@ -307,17 +253,17 @@ errno_t list_image_ID_ncurses() sizeKb = 0; sizeb = compute_image_memory(); - if(sizeb > 1024 - 1) + if (sizeb > 1024 - 1) { sizeKb = sizeb / 1024; sizeb = sizeb - 1024 * sizeKb; } - if(sizeKb > 1024 - 1) + if (sizeKb > 1024 - 1) { sizeMb = sizeKb / 1024; sizeKb = sizeKb - 1024 * sizeMb; } - if(sizeMb > 1024 - 1) + if (sizeMb > 1024 - 1) { sizeGb = sizeMb / 1024; sizeMb = sizeMb - 1024 * sizeGb; @@ -326,25 +272,25 @@ errno_t list_image_ID_ncurses() //attron(A_BOLD); sprintf(str, "%ld image(s) ", compute_nb_image()); - if(sizeGb > 0) + if (sizeGb > 0) { sprintf(str1, "%s %ld GB", str, (long)(sizeGb)); strcpy(str, str1); } - if(sizeMb > 0) + if (sizeMb > 0) { sprintf(str1, "%s %ld MB", str, (long)(sizeMb)); strcpy(str, str1); } - if(sizeKb > 0) + if (sizeKb > 0) { sprintf(str1, "%s %ld KB", str, (long)(sizeKb)); strcpy(str, str1); } - if(sizeb > 0) + if (sizeb > 0) { sprintf(str1, "%s %ld B", str, (long)(sizeb)); strcpy(str, str1); @@ -355,13 +301,9 @@ errno_t list_image_ID_ncurses() refresh(); - return RETURN_SUCCESS; } - - - void close_list_image_ID_ncurses(void) { printf("Closing monitor cleanly\n"); @@ -372,27 +314,19 @@ void close_list_image_ID_ncurses(void) data.MEM_MONITOR = 0; } - - - - - - -errno_t list_image_ID_ofp( - FILE *fo -) +errno_t list_image_ID_ofp(FILE *fo) { - long i; - long j; - long long tmp_long; - char type[STYPESIZE]; - uint8_t datatype; - int n; + long i; + long j; + long long tmp_long; + char type[STYPESIZE]; + uint8_t datatype; + int n; unsigned long long sizeb, sizeKb, sizeMb, sizeGb; - char str[500]; - char str1[512]; - struct timespec timenow; - double timediff; + char str[500]; + char str1[512]; + struct timespec timenow; + double timediff; //struct mallinfo minfo; sizeb = compute_image_memory(); @@ -401,36 +335,31 @@ errno_t list_image_ID_ofp( clock_gettime(CLOCK_REALTIME, &timenow); //fprintf(fo, "time: %ld.%09ld\n", timenow.tv_sec % 60, timenow.tv_nsec); - - fprintf(fo, "\n"); - fprintf(fo, - "INDEX NAME SIZE TYPE SIZE [percent] LAST ACCESS\n"); + fprintf(fo, "INDEX NAME SIZE TYPE SIZE [percent] LAST ACCESS\n"); fprintf(fo, "\n"); - for(i = 0; i < data.NB_MAX_IMAGE; i++) - if(data.image[i].used == 1) + for (i = 0; i < data.NB_MAX_IMAGE; i++) + if (data.image[i].used == 1) { datatype = data.image[i].md[0].datatype; tmp_long = ((long long)(data.image[i].md[0].nelement)) * ImageStreamIO_typesize(datatype); - if(data.image[i].md[0].shared == 1) + if (data.image[i].md[0].shared == 1) { - fprintf(fo, "%4ld %c[%d;%dm%14s%c[%d;m ", i, (char) 27, 1, 34, - data.image[i].name, (char) 27, 0); + fprintf(fo, "%4ld %c[%d;%dm%14s%c[%d;m ", i, (char)27, 1, 34, data.image[i].name, (char)27, 0); } else { - fprintf(fo, "%4ld %c[%d;%dm%14s%c[%d;m ", i, (char) 27, 1, 33, - data.image[i].name, (char) 27, 0); + fprintf(fo, "%4ld %c[%d;%dm%14s%c[%d;m ", i, (char)27, 1, 33, data.image[i].name, (char)27, 0); } //fprintf(fo, "%s", str); - sprintf(str, "[ %6ld", (long) data.image[i].md[0].size[0]); + sprintf(str, "[ %6ld", (long)data.image[i].md[0].size[0]); - for(j = 1; j < data.image[i].md[0].naxis; j++) + for (j = 1; j < data.image[i].md[0].naxis; j++) { - sprintf(str1, "%s x %6ld", str, (long) data.image[i].md[0].size[j]); + sprintf(str1, "%s x %6ld", str, (long)data.image[i].md[0].size[j]); strcpy(str, str1); } sprintf(str1, "%s]", str); @@ -438,112 +367,108 @@ errno_t list_image_ID_ofp( fprintf(fo, "%-32s", str); - n = 0; - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { n = snprintf(type, STYPESIZE, "UINT8 "); } - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { n = snprintf(type, STYPESIZE, "INT8 "); } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { n = snprintf(type, STYPESIZE, "UINT16 "); } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { n = snprintf(type, STYPESIZE, "INT16 "); } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { n = snprintf(type, STYPESIZE, "UINT32 "); } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { n = snprintf(type, STYPESIZE, "INT32 "); } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { n = snprintf(type, STYPESIZE, "UINT64 "); } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { n = snprintf(type, STYPESIZE, "INT64 "); } - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { n = snprintf(type, STYPESIZE, "FLOAT "); } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { n = snprintf(type, STYPESIZE, "DOUBLE "); } - if(datatype == _DATATYPE_COMPLEX_FLOAT) + if (datatype == _DATATYPE_COMPLEX_FLOAT) { n = snprintf(type, STYPESIZE, "CFLOAT "); } - if(datatype == _DATATYPE_COMPLEX_DOUBLE) + if (datatype == _DATATYPE_COMPLEX_DOUBLE) { n = snprintf(type, STYPESIZE, "CDOUBLE"); } fprintf(fo, "%7s ", type); - - if(n >= STYPESIZE) + if (n >= STYPESIZE) { PRINT_ERROR("Attempted to write string buffer with too many characters"); } - fprintf(fo, "%10ld Kb %6.2f ", (long)(tmp_long / 1024), - (float)(100.0 * tmp_long / sizeb)); + fprintf(fo, "%10ld Kb %6.2f ", (long)(tmp_long / 1024), (float)(100.0 * tmp_long / sizeb)); timediff = (1.0 * timenow.tv_sec + 0.000000001 * timenow.tv_nsec) - - (1.0 * data.image[i].md[0].lastaccesstime.tv_sec + 0.000000001 * - data.image[i].md[0].lastaccesstime.tv_nsec); + (1.0 * data.image[i].md[0].lastaccesstime.tv_sec + + 0.000000001 * data.image[i].md[0].lastaccesstime.tv_nsec); fprintf(fo, "%15.9f\n", timediff); } fprintf(fo, "\n"); - sizeGb = 0; sizeMb = 0; sizeKb = 0; sizeb = compute_image_memory(); - if(sizeb > 1024 - 1) + if (sizeb > 1024 - 1) { sizeKb = sizeb / 1024; sizeb = sizeb - 1024 * sizeKb; } - if(sizeKb > 1024 - 1) + if (sizeKb > 1024 - 1) { sizeMb = sizeKb / 1024; sizeKb = sizeKb - 1024 * sizeMb; } - if(sizeMb > 1024 - 1) + if (sizeMb > 1024 - 1) { sizeGb = sizeMb / 1024; sizeMb = sizeMb - 1024 * sizeGb; } fprintf(fo, "%ld image(s) ", compute_nb_image()); - if(sizeGb > 0) + if (sizeGb > 0) { fprintf(fo, " %ld Gb", (long)(sizeGb)); } - if(sizeMb > 0) + if (sizeMb > 0) { fprintf(fo, " %ld Mb", (long)(sizeMb)); } - if(sizeKb > 0) + if (sizeKb > 0) { fprintf(fo, " %ld Kb", (long)(sizeKb)); } - if(sizeb > 0) + if (sizeb > 0) { fprintf(fo, " %ld", (long)(sizeb)); } @@ -551,34 +476,27 @@ errno_t list_image_ID_ofp( fflush(fo); - return RETURN_SUCCESS; } - - - -errno_t list_image_ID_ofp_simple( - FILE *fo -) +errno_t list_image_ID_ofp_simple(FILE *fo) { - long i, j; + long i, j; //long long tmp_long; - uint8_t datatype; + uint8_t datatype; - for(i = 0; i < data.NB_MAX_IMAGE; i++) - if(data.image[i].used == 1) + for (i = 0; i < data.NB_MAX_IMAGE; i++) + if (data.image[i].used == 1) { datatype = data.image[i].md[0].datatype; //tmp_long = ((long long) (data.image[i].md[0].nelement)) * ImageStreamIO_typesize(datatype); - fprintf(fo, "%20s %d %ld %d %4ld", data.image[i].name, datatype, - (long) data.image[i].md[0].naxis, data.image[i].md[0].shared, - (long) data.image[i].md[0].size[0]); + fprintf(fo, "%20s %d %ld %d %4ld", data.image[i].name, datatype, (long)data.image[i].md[0].naxis, + data.image[i].md[0].shared, (long)data.image[i].md[0].size[0]); - for(j = 1; j < data.image[i].md[0].naxis; j++) + for (j = 1; j < data.image[i].md[0].naxis; j++) { - fprintf(fo, " %4ld", (long) data.image[i].md[0].size[j]); + fprintf(fo, " %4ld", (long)data.image[i].md[0].size[j]); } fprintf(fo, "\n"); } @@ -587,9 +505,6 @@ errno_t list_image_ID_ofp_simple( return RETURN_SUCCESS; } - - - errno_t list_image_ID() { list_image_ID_ofp(stdout); @@ -597,8 +512,6 @@ errno_t list_image_ID() return RETURN_SUCCESS; } - - /* list all images in memory output is written in ASCII file only basic info is listed @@ -608,9 +521,7 @@ errno_t list_image_ID() type */ -errno_t list_image_ID_file( - const char *fname -) +errno_t list_image_ID_file(const char *fname) { FILE *fp; long i, j; @@ -619,76 +530,75 @@ errno_t list_image_ID_file( int n; fp = fopen(fname, "w"); - if(fp == NULL) + if (fp == NULL) { PRINT_ERROR("Cannot create file %s", fname); abort(); } - for(i = 0; i < data.NB_MAX_IMAGE; i++) - if(data.image[i].used == 1) + for (i = 0; i < data.NB_MAX_IMAGE; i++) + if (data.image[i].used == 1) { datatype = data.image[i].md[0].datatype; fprintf(fp, "%ld %s", i, data.image[i].name); - fprintf(fp, " %ld", (long) data.image[i].md[0].naxis); - for(j = 0; j < data.image[i].md[0].naxis; j++) + fprintf(fp, " %ld", (long)data.image[i].md[0].naxis); + for (j = 0; j < data.image[i].md[0].naxis; j++) { - fprintf(fp, " %ld", (long) data.image[i].md[0].size[j]); + fprintf(fp, " %ld", (long)data.image[i].md[0].size[j]); } n = 0; - if(datatype == _DATATYPE_UINT8) + if (datatype == _DATATYPE_UINT8) { n = snprintf(type, STYPESIZE, "UINT8 "); } - if(datatype == _DATATYPE_INT8) + if (datatype == _DATATYPE_INT8) { n = snprintf(type, STYPESIZE, "INT8 "); } - if(datatype == _DATATYPE_UINT16) + if (datatype == _DATATYPE_UINT16) { n = snprintf(type, STYPESIZE, "UINT16 "); } - if(datatype == _DATATYPE_INT16) + if (datatype == _DATATYPE_INT16) { n = snprintf(type, STYPESIZE, "INT16 "); } - if(datatype == _DATATYPE_UINT32) + if (datatype == _DATATYPE_UINT32) { n = snprintf(type, STYPESIZE, "UINT32 "); } - if(datatype == _DATATYPE_INT32) + if (datatype == _DATATYPE_INT32) { n = snprintf(type, STYPESIZE, "INT32 "); } - if(datatype == _DATATYPE_UINT64) + if (datatype == _DATATYPE_UINT64) { n = snprintf(type, STYPESIZE, "UINT64 "); } - if(datatype == _DATATYPE_INT64) + if (datatype == _DATATYPE_INT64) { n = snprintf(type, STYPESIZE, "INT64 "); } - if(datatype == _DATATYPE_FLOAT) + if (datatype == _DATATYPE_FLOAT) { n = snprintf(type, STYPESIZE, "FLOAT "); } - if(datatype == _DATATYPE_DOUBLE) + if (datatype == _DATATYPE_DOUBLE) { n = snprintf(type, STYPESIZE, "DOUBLE "); } - if(datatype == _DATATYPE_COMPLEX_FLOAT) + if (datatype == _DATATYPE_COMPLEX_FLOAT) { n = snprintf(type, STYPESIZE, "CFLOAT "); } - if(datatype == _DATATYPE_COMPLEX_DOUBLE) + if (datatype == _DATATYPE_COMPLEX_DOUBLE) { n = snprintf(type, STYPESIZE, "CDOUBLE"); } - - if(n >= STYPESIZE) + if (n >= STYPESIZE) { PRINT_ERROR("Attempted to write string buffer with too many characters"); } @@ -700,15 +610,9 @@ errno_t list_image_ID_file( return RETURN_SUCCESS; } - - - - -errno_t memory_monitor( - const char *termttyname -) +errno_t memory_monitor(const char *termttyname) { - if(data.Debug > 0) + if (data.Debug > 0) { printf("starting memory_monitor on \"%s\"\n", termttyname); } @@ -720,6 +624,3 @@ errno_t memory_monitor( return RETURN_SUCCESS; } - - - diff --git a/src/COREMOD_memory/list_image.h b/src/COREMOD_memory/list_image.h index 50b82f09..4e580578 100644 --- a/src/COREMOD_memory/list_image.h +++ b/src/COREMOD_memory/list_image.h @@ -2,37 +2,20 @@ * @file list_image.h */ - - errno_t list_image_addCLIcmd(); +errno_t memory_monitor(const char *termttyname); - -errno_t memory_monitor( - const char *termttyname -); - - - -errno_t init_list_image_ID_ncurses( - const char *termttyname -); +errno_t init_list_image_ID_ncurses(const char *termttyname); void close_list_image_ID_ncurses(); errno_t list_image_ID_ncurses(); -errno_t list_image_ID_ofp( - FILE *fo -); +errno_t list_image_ID_ofp(FILE *fo); -errno_t list_image_ID_ofp_simple( - FILE *fo -); +errno_t list_image_ID_ofp_simple(FILE *fo); errno_t list_image_ID(); -errno_t list_image_ID_file( - const char *fname -); - +errno_t list_image_ID_file(const char *fname); diff --git a/src/COREMOD_memory/list_variable.c b/src/COREMOD_memory/list_variable.c index eed2f842..e0fa28fe 100644 --- a/src/COREMOD_memory/list_variable.c +++ b/src/COREMOD_memory/list_variable.c @@ -3,33 +3,23 @@ * @brief list variables */ - #include "CommandLineInterface/CLIcore.h" - - - - // ========================================== // Forward declaration(s) // ========================================== errno_t list_variable_ID(); -errno_t list_variable_ID_file( - const char *fname -); - - +errno_t list_variable_ID_file(const char *fname); // ========================================== // Command line interface wrapper function(s) // ========================================== - static errno_t list_variable_ID_file__cli() { - if(CLI_checkarg(1, CLIARG_STR_NOT_IMG) == 0) + if (CLI_checkarg(1, CLIARG_STR_NOT_IMG) == 0) { list_variable_ID_file(data.cmdargtoken[1].val.string); return CLICMD_SUCCESS; @@ -40,9 +30,6 @@ static errno_t list_variable_ID_file__cli() } } - - - // ========================================== // Register CLI command(s) // ========================================== @@ -50,56 +37,36 @@ static errno_t list_variable_ID_file__cli() errno_t list_variable_addCLIcmd() { - RegisterCLIcommand( - "listvar", - __FILE__, - list_variable_ID, - "list variables in memory", - "no argument", - "listvar", - "int list_variable_ID()"); - - RegisterCLIcommand( - "listvarf", - __FILE__, - list_variable_ID_file__cli, - "list variables in memory, write to file", - "", - "listvarf var.txt", - "int list_variable_ID_file()"); + RegisterCLIcommand("listvar", __FILE__, list_variable_ID, "list variables in memory", "no argument", "listvar", + "int list_variable_ID()"); + RegisterCLIcommand("listvarf", __FILE__, list_variable_ID_file__cli, "list variables in memory, write to file", + "", "listvarf var.txt", "int list_variable_ID_file()"); return RETURN_SUCCESS; } - - - - - errno_t list_variable_ID() { variableID i; - for(i = 0; i < data.NB_MAX_VARIABLE; i++) - if(data.variable[i].used == 1) + for (i = 0; i < data.NB_MAX_VARIABLE; i++) + if (data.variable[i].used == 1) { - printf("%4ld %16s %25.18g\n", i, data.variable[i].name, - data.variable[i].value.f); + printf("%4ld %16s %25.18g\n", i, data.variable[i].name, data.variable[i].value.f); } return RETURN_SUCCESS; } - errno_t list_variable_ID_file(const char *fname) { imageID i; FILE *fp; fp = fopen(fname, "w"); - for(i = 0; i < data.NB_MAX_VARIABLE; i++) - if(data.variable[i].used == 1) + for (i = 0; i < data.NB_MAX_VARIABLE; i++) + if (data.variable[i].used == 1) { fprintf(fp, "%s=%.18g\n", data.variable[i].name, data.variable[i].value.f); } @@ -108,6 +75,3 @@ errno_t list_variable_ID_file(const char *fname) return RETURN_SUCCESS; } - - - diff --git a/src/COREMOD_memory/list_variable.h b/src/COREMOD_memory/list_variable.h index 61abd172..b3630dcf 100644 --- a/src/COREMOD_memory/list_variable.h +++ b/src/COREMOD_memory/list_variable.h @@ -2,13 +2,8 @@ * @file list_variable.h */ - - errno_t list_variable_addCLIcmd(); - errno_t list_variable_ID(); -errno_t list_variable_ID_file( - const char *fname -); +errno_t list_variable_ID_file(const char *fname); diff --git a/src/COREMOD_memory/logshmim.c b/src/COREMOD_memory/logshmim.c index f96dcd4d..d682a134 100644 --- a/src/COREMOD_memory/logshmim.c +++ b/src/COREMOD_memory/logshmim.c @@ -3,96 +3,61 @@ * @brief Save telemetry stream data */ - #define _GNU_SOURCE -#include -#include #include +#include +#include +#include #include -#include #include +#include #include -#include -#include - #include "CommandLineInterface/CLIcore.h" #include "CommandLineInterface/timeutils.h" - #include "COREMOD_iofits/COREMOD_iofits.h" -#include "COREMOD_memory/image_keyword_addS.h" #include "COREMOD_memory/image_keyword_addD.h" +#include "COREMOD_memory/image_keyword_addS.h" -#include "image_ID.h" -#include "list_image.h" #include "create_image.h" #include "delete_image.h" +#include "image_ID.h" +#include "list_image.h" #include "read_shmim.h" #include "stream_sem.h" #include "shmimlog_types.h" - - - -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) - +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) static long tret; // thread return value - - - - - - - - // ========================================== // Forward declaration(s) // ========================================== -errno_t COREMOD_MEMORY_logshim_printstatus( - const char *IDname -); +errno_t COREMOD_MEMORY_logshim_printstatus(const char *IDname); -errno_t COREMOD_MEMORY_logshim_set_on( - const char *IDname, - int setv -); - -errno_t COREMOD_MEMORY_logshim_set_logexit( - const char *IDname, - int setv -); - -errno_t COREMOD_MEMORY_sharedMem_2Dim_log( - const char *IDname, - uint32_t zsize, - const char *logdir, - const char *IDlogdata_name -); +errno_t COREMOD_MEMORY_logshim_set_on(const char *IDname, int setv); +errno_t COREMOD_MEMORY_logshim_set_logexit(const char *IDname, int setv); +errno_t COREMOD_MEMORY_sharedMem_2Dim_log(const char *IDname, uint32_t zsize, const char *logdir, + const char *IDlogdata_name); // ========================================== // Command line interface wrapper function(s) // ========================================== - static errno_t COREMOD_MEMORY_logshim_printstatus__cli() { - if(0 - + CLI_checkarg(1, CLIARG_STR_NOT_IMG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_STR_NOT_IMG) == 0) { - COREMOD_MEMORY_logshim_printstatus( - data.cmdargtoken[1].val.string - ); + COREMOD_MEMORY_logshim_printstatus(data.cmdargtoken[1].val.string); return CLICMD_SUCCESS; } else @@ -101,19 +66,12 @@ static errno_t COREMOD_MEMORY_logshim_printstatus__cli() } } - static errno_t COREMOD_MEMORY_logshim_set_on__cli() { - if(0 - + CLI_checkarg(1, CLIARG_STR_NOT_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_STR_NOT_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { printf("logshim_set_on ----------------------\n"); - COREMOD_MEMORY_logshim_set_on( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numl - ); + COREMOD_MEMORY_logshim_set_on(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl); return CLICMD_SUCCESS; } else @@ -122,18 +80,11 @@ static errno_t COREMOD_MEMORY_logshim_set_on__cli() } } - static errno_t COREMOD_MEMORY_logshim_set_logexit__cli() { - if(0 - + CLI_checkarg(1, CLIARG_STR_NOT_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_STR_NOT_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { - COREMOD_MEMORY_logshim_set_logexit( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numl - ); + COREMOD_MEMORY_logshim_set_logexit(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl); return CLICMD_SUCCESS; } else @@ -142,27 +93,18 @@ static errno_t COREMOD_MEMORY_logshim_set_logexit__cli() } } - static errno_t COREMOD_MEMORY_sharedMem_2Dim_log__cli() { - if(CLI_checkarg_noerrmsg(4, CLIARG_STR_NOT_IMG) != 0) + if (CLI_checkarg_noerrmsg(4, CLIARG_STR_NOT_IMG) != 0) { sprintf(data.cmdargtoken[4].val.string, "null"); } - if(0 - + CLI_checkarg(1, 3) - + CLI_checkarg(2, CLIARG_LONG) - + CLI_checkarg(3, 3) - == 0) + if (0 + CLI_checkarg(1, 3) + CLI_checkarg(2, CLIARG_LONG) + CLI_checkarg(3, 3) == 0) { - COREMOD_MEMORY_sharedMem_2Dim_log( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numl, - data.cmdargtoken[3].val.string, - data.cmdargtoken[4].val.string - ); + COREMOD_MEMORY_sharedMem_2Dim_log(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl, + data.cmdargtoken[3].val.string, data.cmdargtoken[4].val.string); return CLICMD_SUCCESS; } else @@ -171,11 +113,6 @@ static errno_t COREMOD_MEMORY_sharedMem_2Dim_log__cli() } } - - - - - // ========================================== // Register CLI command(s) // ========================================== @@ -183,60 +120,27 @@ static errno_t COREMOD_MEMORY_sharedMem_2Dim_log__cli() errno_t logshmim_addCLIcmd() { - RegisterCLIcommand( - "shmimstreamlog", - __FILE__, - COREMOD_MEMORY_sharedMem_2Dim_log__cli, - "logs shared memory stream (run in current directory)", - " ", - "shmimstreamlog wfscamim 10000 /media/data \"\"", - "long COREMOD_MEMORY_sharedMem_2Dim_log(const char *IDname, uint32_t zsize, const char *logdir, const char *IDlogdata_name"); - - RegisterCLIcommand( - "shmimslogstat", - __FILE__, - COREMOD_MEMORY_logshim_printstatus__cli, - "print log shared memory stream status", - "", "shmimslogstat wfscamim", - "int COREMOD_MEMORY_logshim_printstatus(const char *IDname)"); - - RegisterCLIcommand( - "shmimslogonset", __FILE__, - COREMOD_MEMORY_logshim_set_on__cli, - "set on variable in log shared memory stream", - " ", - "shmimslogonset imwfs 1", - "int COREMOD_MEMORY_logshim_set_on(const char *IDname, int setv)"); - - RegisterCLIcommand( - "shmimslogexitset", - __FILE__, - COREMOD_MEMORY_logshim_set_logexit__cli, - "set exit variable in log shared memory stream", - " ", - "shmimslogexitset imwfs 1", - "int COREMOD_MEMORY_logshim_set_logexit(const char *IDname, int setv)"); - - - return RETURN_SUCCESS; -} - - - - - - - - - - - - - + RegisterCLIcommand("shmimstreamlog", __FILE__, COREMOD_MEMORY_sharedMem_2Dim_log__cli, + "logs shared memory stream (run in current directory)", " ", + "shmimstreamlog wfscamim 10000 /media/data \"\"", + "long COREMOD_MEMORY_sharedMem_2Dim_log(const char *IDname, uint32_t zsize, const char *logdir, " + "const char *IDlogdata_name"); + RegisterCLIcommand("shmimslogstat", __FILE__, COREMOD_MEMORY_logshim_printstatus__cli, + "print log shared memory stream status", "", "shmimslogstat wfscamim", + "int COREMOD_MEMORY_logshim_printstatus(const char *IDname)"); + RegisterCLIcommand("shmimslogonset", __FILE__, COREMOD_MEMORY_logshim_set_on__cli, + "set on variable in log shared memory stream", " ", + "shmimslogonset imwfs 1", "int COREMOD_MEMORY_logshim_set_on(const char *IDname, int setv)"); + RegisterCLIcommand("shmimslogexitset", __FILE__, COREMOD_MEMORY_logshim_set_logexit__cli, + "set exit variable in log shared memory stream", " ", + "shmimslogexitset imwfs 1", + "int COREMOD_MEMORY_logshim_set_logexit(const char *IDname, int setv)"); + return RETURN_SUCCESS; +} /** * ## Purpose @@ -244,28 +148,23 @@ errno_t logshmim_addCLIcmd() * Save telemetry stream data * */ -void *save_fits_function( - void *ptr -) +void *save_fits_function(void *ptr) { - imageID ID; - + imageID ID; //struct savethreadmsg *tmsg; // = malloc(sizeof(struct savethreadmsg)); STREAMSAVE_THREAD_MESSAGE *tmsg; - uint32_t *imsizearray; - uint32_t xsize, ysize; - uint8_t datatype; - - - imageID IDc; - long framesize; // in bytes - char *ptr0; // source pointer - char *ptr1; // destination pointer - long k; - FILE *fp; + uint32_t *imsizearray; + uint32_t xsize, ysize; + uint8_t datatype; + imageID IDc; + long framesize; // in bytes + char *ptr0; // source pointer + char *ptr1; // destination pointer + long k; + FILE *fp; // Set save function to RT priority 0 // This is meant to be lower priority than the data collection into buffers @@ -274,72 +173,58 @@ void *save_fits_function( struct sched_param schedpar; schedpar.sched_priority = RT_priority; - if(seteuid(data.euid) != 0) //This goes up to maximum privileges + if (seteuid(data.euid) != 0) //This goes up to maximum privileges { PRINT_ERROR("seteuid error"); } sched_setscheduler(0, SCHED_FIFO, &schedpar); //other option is SCHED_RR, might be faster - if(seteuid(data.ruid) != 0) //Go back to normal privileges + if (seteuid(data.ruid) != 0) //Go back to normal privileges { PRINT_ERROR("seteuid error"); } - printf("===================== START SAVE THREAD =====================\n"); fflush(stdout); - - - imsizearray = (uint32_t *) malloc(sizeof(uint32_t) * 3); - if(imsizearray == NULL) + imsizearray = (uint32_t *)malloc(sizeof(uint32_t) * 3); + if (imsizearray == NULL) { PRINT_ERROR("malloc error"); abort(); } // tmsg = (struct savethreadmsg*) ptr; - tmsg = (STREAMSAVE_THREAD_MESSAGE *) ptr; - + tmsg = (STREAMSAVE_THREAD_MESSAGE *)ptr; // Add custom keywords int NBcustomKW = 9; - IMAGE_KEYWORD *imkwarray = (IMAGE_KEYWORD *) malloc(sizeof( - IMAGE_KEYWORD) * NBcustomKW); - - - - + IMAGE_KEYWORD *imkwarray = (IMAGE_KEYWORD *)malloc(sizeof(IMAGE_KEYWORD) * NBcustomKW); // UT time strcpy(imkwarray[0].name, "UT"); imkwarray[0].type = 'S'; strcpy(imkwarray[0].value.valstr, - timedouble_to_UTC_timeofdaystring(0.5 * tmsg->arraytime[0] + 0.5 * - tmsg->arraytime[tmsg->cubesize - 1])); + timedouble_to_UTC_timeofdaystring(0.5 * tmsg->arraytime[0] + 0.5 * tmsg->arraytime[tmsg->cubesize - 1])); strcpy(imkwarray[0].comment, "HH:MM:SS.SS typical UTC at exposure"); strcpy(imkwarray[1].name, "UT-STR"); imkwarray[1].type = 'S'; - strcpy(imkwarray[1].value.valstr, - timedouble_to_UTC_timeofdaystring(tmsg->arraytime[0])); + strcpy(imkwarray[1].value.valstr, timedouble_to_UTC_timeofdaystring(tmsg->arraytime[0])); strcpy(imkwarray[1].comment, "HH:MM:SS.SS UTC at exposure start"); strcpy(imkwarray[2].name, "UT-END"); imkwarray[2].type = 'S'; - strcpy(imkwarray[2].value.valstr, - timedouble_to_UTC_timeofdaystring(tmsg->arraytime[tmsg->cubesize - 1])); + strcpy(imkwarray[2].value.valstr, timedouble_to_UTC_timeofdaystring(tmsg->arraytime[tmsg->cubesize - 1])); strcpy(imkwarray[2].comment, "HH:MM:SS.SS UTC at exposure start"); - - // Modified Julian Date (MJD) strcpy(imkwarray[3].name, "MJD"); imkwarray[3].type = 'D'; - imkwarray[3].value.numf = (0.5 * tmsg->arraytime[0] + 0.5 * - tmsg->arraytime[tmsg->cubesize - 1]) / 86400.0 + 40587.0; + imkwarray[3].value.numf = + (0.5 * tmsg->arraytime[0] + 0.5 * tmsg->arraytime[tmsg->cubesize - 1]) / 86400.0 + 40587.0; strcpy(imkwarray[3].comment, "Modified Julian Day at exposure"); strcpy(imkwarray[4].name, "MJD-STR"); @@ -349,11 +234,9 @@ void *save_fits_function( strcpy(imkwarray[5].name, "MJD-END"); imkwarray[5].type = 'D'; - imkwarray[5].value.numf = (tmsg->arraytime[tmsg->cubesize - 1] / 86400.0) + - 40587.0; + imkwarray[5].value.numf = (tmsg->arraytime[tmsg->cubesize - 1] / 86400.0) + 40587.0; strcpy(imkwarray[5].comment, "Modified Julian Day at exposure start"); - // Local time // get time zone @@ -366,44 +249,26 @@ void *save_fits_function( sprintf(imkwarray[6].name, "%s", lt.tm_zone); imkwarray[6].type = 'S'; strcpy(imkwarray[6].value.valstr, - timedouble_to_UTC_timeofdaystring( - (0.5 * tmsg->arraytime[0] + 0.5 * tmsg->arraytime[tmsg->cubesize - 1]) + - lt.tm_gmtoff - )); + timedouble_to_UTC_timeofdaystring((0.5 * tmsg->arraytime[0] + 0.5 * tmsg->arraytime[tmsg->cubesize - 1]) + + lt.tm_gmtoff)); sprintf(imkwarray[6].comment, "HH:MM:SS.SS typical %s at exposure", lt.tm_zone); sprintf(imkwarray[7].name, "%s-STR", lt.tm_zone); imkwarray[7].type = 'S'; - strcpy(imkwarray[7].value.valstr, - timedouble_to_UTC_timeofdaystring( - tmsg->arraytime[0] + lt.tm_gmtoff - )); + strcpy(imkwarray[7].value.valstr, timedouble_to_UTC_timeofdaystring(tmsg->arraytime[0] + lt.tm_gmtoff)); sprintf(imkwarray[7].comment, "HH:MM:SS.SS typical %s at exposure", lt.tm_zone); sprintf(imkwarray[8].name, "%s-END", lt.tm_zone); imkwarray[8].type = 'S'; strcpy(imkwarray[8].value.valstr, - timedouble_to_UTC_timeofdaystring( - tmsg->arraytime[tmsg->cubesize - 1] + lt.tm_gmtoff - )); + timedouble_to_UTC_timeofdaystring(tmsg->arraytime[tmsg->cubesize - 1] + lt.tm_gmtoff)); sprintf(imkwarray[8].comment, "HH:MM:SS.SS typical %s at exposure", lt.tm_zone); - - - - - if(tmsg->partial == 0) // full image + if (tmsg->partial == 0) // full image { printf("auxFITSheader = \"%s\"\n", tmsg->fname_auxFITSheader); - saveFITS( - tmsg->iname, - tmsg->fname, - 0, - tmsg->fname_auxFITSheader, - imkwarray, - NBcustomKW - ); + saveFITS(tmsg->iname, tmsg->fname, 0, tmsg->fname_auxFITSheader, imkwarray, NBcustomKW); } else { @@ -412,105 +277,98 @@ void *save_fits_function( xsize = data.image[ID].md[0].size[0]; ysize = data.image[ID].md[0].size[1]; - imsizearray[0] = xsize; imsizearray[1] = ysize; imsizearray[2] = tmsg->cubesize; - create_image_ID("tmpsavecube", 3, imsizearray, datatype, 0, 10, 0, &IDc); - - switch(datatype) + switch (datatype) { - case _DATATYPE_UINT8: - framesize = SIZEOF_DATATYPE_UINT8 * xsize * ysize; - ptr0 = (char *) data.image[ID].array.UI8; // source - ptr1 = (char *) data.image[IDc].array.UI8; // destination - break; - case _DATATYPE_INT8: - framesize = SIZEOF_DATATYPE_INT8 * xsize * ysize; - ptr0 = (char *) data.image[ID].array.SI8; // source - ptr1 = (char *) data.image[IDc].array.SI8; // destination - break; + case _DATATYPE_UINT8: + framesize = SIZEOF_DATATYPE_UINT8 * xsize * ysize; + ptr0 = (char *)data.image[ID].array.UI8; // source + ptr1 = (char *)data.image[IDc].array.UI8; // destination + break; + case _DATATYPE_INT8: + framesize = SIZEOF_DATATYPE_INT8 * xsize * ysize; + ptr0 = (char *)data.image[ID].array.SI8; // source + ptr1 = (char *)data.image[IDc].array.SI8; // destination + break; - case _DATATYPE_UINT16: - framesize = SIZEOF_DATATYPE_UINT16 * xsize * ysize; - ptr0 = (char *) data.image[ID].array.UI16; // source - ptr1 = (char *) data.image[IDc].array.UI16; // destination - break; - case _DATATYPE_INT16: - framesize = SIZEOF_DATATYPE_INT16 * xsize * ysize; - ptr0 = (char *) data.image[ID].array.SI16; // source - ptr1 = (char *) data.image[IDc].array.SI16; // destination - break; + case _DATATYPE_UINT16: + framesize = SIZEOF_DATATYPE_UINT16 * xsize * ysize; + ptr0 = (char *)data.image[ID].array.UI16; // source + ptr1 = (char *)data.image[IDc].array.UI16; // destination + break; + case _DATATYPE_INT16: + framesize = SIZEOF_DATATYPE_INT16 * xsize * ysize; + ptr0 = (char *)data.image[ID].array.SI16; // source + ptr1 = (char *)data.image[IDc].array.SI16; // destination + break; - case _DATATYPE_UINT32: - framesize = SIZEOF_DATATYPE_UINT32 * xsize * ysize; - ptr0 = (char *) data.image[ID].array.UI32; // source - ptr1 = (char *) data.image[IDc].array.UI32; // destination - break; - case _DATATYPE_INT32: - framesize = SIZEOF_DATATYPE_INT32 * xsize * ysize; - ptr0 = (char *) data.image[ID].array.SI32; // source - ptr1 = (char *) data.image[IDc].array.SI32; // destination - break; + case _DATATYPE_UINT32: + framesize = SIZEOF_DATATYPE_UINT32 * xsize * ysize; + ptr0 = (char *)data.image[ID].array.UI32; // source + ptr1 = (char *)data.image[IDc].array.UI32; // destination + break; + case _DATATYPE_INT32: + framesize = SIZEOF_DATATYPE_INT32 * xsize * ysize; + ptr0 = (char *)data.image[ID].array.SI32; // source + ptr1 = (char *)data.image[IDc].array.SI32; // destination + break; - case _DATATYPE_UINT64: - framesize = SIZEOF_DATATYPE_UINT64 * xsize * ysize; - ptr0 = (char *) data.image[ID].array.UI64; // source - ptr1 = (char *) data.image[IDc].array.UI64; // destination - break; - case _DATATYPE_INT64: - framesize = SIZEOF_DATATYPE_INT64 * xsize * ysize; - ptr0 = (char *) data.image[ID].array.SI64; // source - ptr1 = (char *) data.image[IDc].array.SI64; // destination - break; + case _DATATYPE_UINT64: + framesize = SIZEOF_DATATYPE_UINT64 * xsize * ysize; + ptr0 = (char *)data.image[ID].array.UI64; // source + ptr1 = (char *)data.image[IDc].array.UI64; // destination + break; + case _DATATYPE_INT64: + framesize = SIZEOF_DATATYPE_INT64 * xsize * ysize; + ptr0 = (char *)data.image[ID].array.SI64; // source + ptr1 = (char *)data.image[IDc].array.SI64; // destination + break; - case _DATATYPE_FLOAT: - framesize = SIZEOF_DATATYPE_FLOAT * xsize * ysize; - ptr0 = (char *) data.image[ID].array.F; // source - ptr1 = (char *) data.image[IDc].array.F; // destination - break; - case _DATATYPE_DOUBLE: - framesize = SIZEOF_DATATYPE_DOUBLE * xsize * ysize; - ptr0 = (char *) data.image[ID].array.D; // source - ptr1 = (char *) data.image[IDc].array.D; // destination - break; + case _DATATYPE_FLOAT: + framesize = SIZEOF_DATATYPE_FLOAT * xsize * ysize; + ptr0 = (char *)data.image[ID].array.F; // source + ptr1 = (char *)data.image[IDc].array.F; // destination + break; + case _DATATYPE_DOUBLE: + framesize = SIZEOF_DATATYPE_DOUBLE * xsize * ysize; + ptr0 = (char *)data.image[ID].array.D; // source + ptr1 = (char *)data.image[IDc].array.D; // destination + break; - default: - printf("ERROR: WRONG DATA TYPE\n"); - free(imsizearray); - free(tmsg); - exit(0); - break; + default: + printf("ERROR: WRONG DATA TYPE\n"); + free(imsizearray); + free(tmsg); + exit(0); + break; } - - memcpy((void *) ptr1, (void *) ptr0, framesize * tmsg->cubesize); + memcpy((void *)ptr1, (void *)ptr0, framesize * tmsg->cubesize); printf("auxFITSheader = \"%s\"\n", tmsg->fname_auxFITSheader); - saveFITS("tmpsavecube", tmsg->fname, 0, tmsg->fname_auxFITSheader, imkwarray, - NBcustomKW); - + saveFITS("tmpsavecube", tmsg->fname, 0, tmsg->fname_auxFITSheader, imkwarray, NBcustomKW); delete_image_ID("tmpsavecube", DELETE_IMAGE_ERRMODE_WARNING); } free(imkwarray); - if(tmsg->saveascii == 1) + if (tmsg->saveascii == 1) { - if((fp = fopen(tmsg->fnameascii, "w")) == NULL) + if ((fp = fopen(tmsg->fnameascii, "w")) == NULL) { printf("ERROR: cannot create file \"%s\"\n", tmsg->fnameascii); exit(0); } fprintf(fp, "# Telemetry stream timing data \n"); - fprintf(fp, "# File written by function %s in file %s\n", __FUNCTION__, - __FILE__); + fprintf(fp, "# File written by function %s in file %s\n", __FUNCTION__, __FILE__); fprintf(fp, "# \n"); fprintf(fp, "# col1 : datacube frame index\n"); fprintf(fp, "# col2 : Main index\n"); @@ -522,7 +380,7 @@ void *save_fits_function( double t0; // time reference t0 = tmsg->arraytime[0]; - for(k = 0; k < tmsg->cubesize; k++) + for (k = 0; k < tmsg->cubesize; k++) { //fprintf(fp, "%6ld %10lu %10lu %15.9lf\n", k, tmsg->arraycnt0[k], tmsg->arraycnt1[k], tmsg->arraytime[k]); @@ -534,14 +392,12 @@ void *save_fits_function( // - cnt0 // - cnt1 - fprintf(fp, "%10ld %10lu %15.9lf %20.9lf %10ld %10ld\n", k, - tmsg->arrayindex[k], tmsg->arraytime[k] - t0, tmsg->arraytime[k], - tmsg->arraycnt0[k], tmsg->arraycnt1[k]); + fprintf(fp, "%10ld %10lu %15.9lf %20.9lf %10ld %10ld\n", k, tmsg->arrayindex[k], + tmsg->arraytime[k] - t0, tmsg->arraytime[k], tmsg->arraycnt0[k], tmsg->arraycnt1[k]); } fclose(fp); } - ID = image_ID(tmsg->iname); tret = ID; free(imsizearray); @@ -549,31 +405,26 @@ void *save_fits_function( printf("===================== END SAVE THREAD =====================\n"); fflush(stdout); - pthread_exit(&tret); } - - /** @brief creates logshimconf shared memory and loads it * */ -LOGSHIM_CONF *COREMOD_MEMORY_logshim_create_SHMconf( - const char *logshimname -) +LOGSHIM_CONF *COREMOD_MEMORY_logshim_create_SHMconf(const char *logshimname) { - int SM_fd; - size_t sharedsize = 0; // shared memory size in bytes - char SM_fname[STRINGMAXLEN_FULLFILENAME]; - int result; - LOGSHIM_CONF *map; + int SM_fd; + size_t sharedsize = 0; // shared memory size in bytes + char SM_fname[STRINGMAXLEN_FULLFILENAME]; + int result; + LOGSHIM_CONF *map; sharedsize = sizeof(LOGSHIM_CONF); WRITE_FULLFILENAME(SM_fname, "%s/%s.logshimconf.shm", data.shmdir, logshimname); SM_fd = open(SM_fname, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); - if(SM_fd == -1) + if (SM_fd == -1) { printf("File \"%s\"\n", SM_fname); fflush(stdout); @@ -582,7 +433,7 @@ LOGSHIM_CONF *COREMOD_MEMORY_logshim_create_SHMconf( } result = lseek(SM_fd, sharedsize - 1, SEEK_SET); - if(result == -1) + if (result == -1) { close(SM_fd); PRINT_ERROR("Error calling lseek() to 'stretch' the file"); @@ -590,16 +441,15 @@ LOGSHIM_CONF *COREMOD_MEMORY_logshim_create_SHMconf( } result = write(SM_fd, "", 1); - if(result != 1) + if (result != 1) { close(SM_fd); perror("Error writing last byte of the file"); exit(0); } - map = (LOGSHIM_CONF *) mmap(0, sharedsize, PROT_READ | PROT_WRITE, MAP_SHARED, - SM_fd, 0); - if(map == MAP_FAILED) + map = (LOGSHIM_CONF *)mmap(0, sharedsize, PROT_READ | PROT_WRITE, MAP_SHARED, SM_fd, 0); + if (map == MAP_FAILED) { close(SM_fd); perror("Error mmapping the file"); @@ -616,27 +466,20 @@ LOGSHIM_CONF *COREMOD_MEMORY_logshim_create_SHMconf( return map; } - - - - - // IDname is name of image logged -errno_t COREMOD_MEMORY_logshim_printstatus( - const char *IDname -) +errno_t COREMOD_MEMORY_logshim_printstatus(const char *IDname) { LOGSHIM_CONF *map; - char SM_fname[STRINGMAXLEN_FULLFILENAME]; - int SM_fd; - struct stat file_stat; + char SM_fname[STRINGMAXLEN_FULLFILENAME]; + int SM_fd; + struct stat file_stat; // read shared mem WRITE_FULLFILENAME(SM_fname, "%s/%s.logshimconf.shm", data.shmdir, IDname); printf("Importing mmap file \"%s\"\n", SM_fname); SM_fd = open(SM_fname, O_RDWR); - if(SM_fd == -1) + if (SM_fd == -1) { printf("Cannot import file - continuing\n"); exit(0); @@ -646,9 +489,8 @@ errno_t COREMOD_MEMORY_logshim_printstatus( fstat(SM_fd, &file_stat); printf("File %s size: %zd\n", SM_fname, file_stat.st_size); - map = (LOGSHIM_CONF *) mmap(0, file_stat.st_size, PROT_READ | PROT_WRITE, - MAP_SHARED, SM_fd, 0); - if(map == MAP_FAILED) + map = (LOGSHIM_CONF *)mmap(0, file_stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, SM_fd, 0); + if (map == MAP_FAILED) { close(SM_fd); perror("Error mmapping the file"); @@ -661,7 +503,7 @@ errno_t COREMOD_MEMORY_logshim_printstatus( printf("interval = %ld\n", map[0].interval); printf("logexit = %d\n", map[0].logexit); - if(munmap(map, sizeof(LOGSHIM_CONF)) == -1) + if (munmap(map, sizeof(LOGSHIM_CONF)) == -1) { printf("unmapping %s\n", SM_fname); perror("Error un-mmapping the file"); @@ -671,29 +513,21 @@ errno_t COREMOD_MEMORY_logshim_printstatus( return RETURN_SUCCESS; } - - - - - // set the on field in logshim // IDname is name of image logged -errno_t COREMOD_MEMORY_logshim_set_on( - const char *IDname, - int setv -) +errno_t COREMOD_MEMORY_logshim_set_on(const char *IDname, int setv) { - LOGSHIM_CONF *map; - char SM_fname[STRINGMAXLEN_FULLFILENAME]; - int SM_fd; - struct stat file_stat; + LOGSHIM_CONF *map; + char SM_fname[STRINGMAXLEN_FULLFILENAME]; + int SM_fd; + struct stat file_stat; // read shared mem WRITE_FULLFILENAME(SM_fname, "%s/%s.logshimconf.shm", data.shmdir, IDname); printf("Importing mmap file \"%s\"\n", SM_fname); SM_fd = open(SM_fname, O_RDWR); - if(SM_fd == -1) + if (SM_fd == -1) { printf("Cannot import file - continuing\n"); exit(0); @@ -703,9 +537,8 @@ errno_t COREMOD_MEMORY_logshim_set_on( fstat(SM_fd, &file_stat); printf("File %s size: %zd\n", SM_fname, file_stat.st_size); - map = (LOGSHIM_CONF *) mmap(0, file_stat.st_size, PROT_READ | PROT_WRITE, - MAP_SHARED, SM_fd, 0); - if(map == MAP_FAILED) + map = (LOGSHIM_CONF *)mmap(0, file_stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, SM_fd, 0); + if (map == MAP_FAILED) { close(SM_fd); perror("Error mmapping the file"); @@ -714,7 +547,7 @@ errno_t COREMOD_MEMORY_logshim_set_on( map[0].on = setv; - if(munmap(map, sizeof(LOGSHIM_CONF)) == -1) + if (munmap(map, sizeof(LOGSHIM_CONF)) == -1) { printf("unmapping %s\n", SM_fname); perror("Error un-mmapping the file"); @@ -724,28 +557,21 @@ errno_t COREMOD_MEMORY_logshim_set_on( return RETURN_SUCCESS; } - - - - // set the on field in logshim // IDname is name of image logged -errno_t COREMOD_MEMORY_logshim_set_logexit( - const char *IDname, - int setv -) +errno_t COREMOD_MEMORY_logshim_set_logexit(const char *IDname, int setv) { - LOGSHIM_CONF *map; - char SM_fname[STRINGMAXLEN_FULLFILENAME]; - int SM_fd; - struct stat file_stat; + LOGSHIM_CONF *map; + char SM_fname[STRINGMAXLEN_FULLFILENAME]; + int SM_fd; + struct stat file_stat; // read shared mem WRITE_FULLFILENAME(SM_fname, "%s/%s.logshimconf.shm", data.shmdir, IDname); printf("Importing mmap file \"%s\"\n", SM_fname); SM_fd = open(SM_fname, O_RDWR); - if(SM_fd == -1) + if (SM_fd == -1) { printf("Cannot import file - continuing\n"); exit(0); @@ -755,9 +581,8 @@ errno_t COREMOD_MEMORY_logshim_set_logexit( fstat(SM_fd, &file_stat); printf("File %s size: %zd\n", SM_fname, file_stat.st_size); - map = (LOGSHIM_CONF *) mmap(0, file_stat.st_size, PROT_READ | PROT_WRITE, - MAP_SHARED, SM_fd, 0); - if(map == MAP_FAILED) + map = (LOGSHIM_CONF *)mmap(0, file_stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, SM_fd, 0); + if (map == MAP_FAILED) { close(SM_fd); perror("Error mmapping the file"); @@ -766,7 +591,7 @@ errno_t COREMOD_MEMORY_logshim_set_logexit( map[0].logexit = setv; - if(munmap(map, sizeof(LOGSHIM_CONF)) == -1) + if (munmap(map, sizeof(LOGSHIM_CONF)) == -1) { printf("unmapping %s\n", SM_fname); perror("Error un-mmapping the file"); @@ -776,11 +601,6 @@ errno_t COREMOD_MEMORY_logshim_set_logexit( return RETURN_SUCCESS; } - - - - - /** @brief Logs a shared memory stream onto disk * * uses semlog semaphore @@ -789,62 +609,56 @@ errno_t COREMOD_MEMORY_logshim_set_logexit( * if an image name logdata exists (should ideally be in shared mem), * then this will be included in the timing txt file */ -errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( - const char *IDname, - uint32_t zsize, - const char *logdir, - const char *IDlogdata_name -) +errno_t __attribute__((hot)) +COREMOD_MEMORY_sharedMem_2Dim_log(const char *IDname, uint32_t zsize, const char *logdir, const char *IDlogdata_name) { // WAIT time. If no new frame during this time, save existing cube - int WaitSec = 5; - - imageID ID; - uint32_t xsize; - uint32_t ysize; - imageID IDb; - imageID IDb0; - imageID IDb1; - long index = 0; - unsigned long long cnt = 0; - int buffer; - uint8_t datatype; - uint32_t *imsizearray; - char fname[STRINGMAXLEN_FILENAME]; - char iname[STRINGMAXLEN_IMGNAME]; - - time_t t; - struct tm *uttimeStart; + int WaitSec = 5; + + imageID ID; + uint32_t xsize; + uint32_t ysize; + imageID IDb; + imageID IDb0; + imageID IDb1; + long index = 0; + unsigned long long cnt = 0; + int buffer; + uint8_t datatype; + uint32_t *imsizearray; + char fname[STRINGMAXLEN_FILENAME]; + char iname[STRINGMAXLEN_IMGNAME]; + + time_t t; + struct tm *uttimeStart; struct timespec ts; struct timespec timenow; struct timespec timenowStart; - int ret; - imageID IDlogdata; + int ret; + imageID IDlogdata; char *ptr0_0; // source image data char *ptr1_0; // destination image data - char *ptr0; // source image data, after offset - char *ptr1; // destination image data, after offset + char *ptr0; // source image data, after offset + char *ptr1; // destination image data, after offset long framesize; // in bytes char fnameascii[200]; - pthread_t thread_savefits; - int tOK = 0; - int iret_savefits; + pthread_t thread_savefits; + int tOK = 0; + int iret_savefits; STREAMSAVE_THREAD_MESSAGE *tmsg = malloc(sizeof(STREAMSAVE_THREAD_MESSAGE)); - long NBfiles = -1; // run forever long long cntwait; - long waitdelayus = 50; // max speed = 20 kHz + long waitdelayus = 50; // max speed = 20 kHz long long cntwaitlim = 10000; // 5 sec int wOK; int noframe; - char logb0name[500]; char logb1name[500]; @@ -868,7 +682,6 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( int use_semlog; int semval; - int VERBOSE = 0; // 0: don't print // 1: print statements outside fast loop @@ -877,48 +690,38 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( // convert wait time into number of couunter steps (counter mode only) cntwaitlim = (long)(WaitSec * 1000000 / waitdelayus); - - schedpar.sched_priority = RT_priority; - if(seteuid(data.euid) != 0) //This goes up to maximum privileges + if (seteuid(data.euid) != 0) //This goes up to maximum privileges { PRINT_ERROR("seteuid error"); } sched_setscheduler(0, SCHED_FIFO, &schedpar); //other option is SCHED_RR, might be faster - if(seteuid(data.ruid) != 0) //Go back to normal privileges + if (seteuid(data.ruid) != 0) //Go back to normal privileges { PRINT_ERROR("seteuid error"); } - - IDlogdata = image_ID(IDlogdata_name); - if(IDlogdata != -1) + if (IDlogdata != -1) { - if(data.image[IDlogdata].md[0].datatype != _DATATYPE_FLOAT) + if (data.image[IDlogdata].md[0].datatype != _DATATYPE_FLOAT) { IDlogdata = -1; } } printf("log data name = %s\n", IDlogdata_name); - logshimconf = COREMOD_MEMORY_logshim_create_SHMconf(IDname); - logshimconf[0].on = 1; logshimconf[0].cnt = 0; logshimconf[0].filecnt = 0; logshimconf[0].logexit = 0; logshimconf[0].interval = 1; - - - imsizearray = (uint32_t *) malloc(sizeof(uint32_t) * 3); - - + imsizearray = (uint32_t *)malloc(sizeof(uint32_t) * 3); read_sharedmem_image(IDname); ID = image_ID(IDname); @@ -926,7 +729,7 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( xsize = data.image[ID].md[0].size[0]; ysize = data.image[ID].md[0].size[1]; - if(data.image[ID].md[0].naxis == 3) + if (data.image[ID].md[0].naxis == 3) { is3Dcube = 1; } @@ -940,146 +743,131 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( sprintf(logb0name, "%s_logbuff0", IDname); sprintf(logb1name, "%s_logbuff1", IDname); - - create_image_ID(logb0name, 3, imsizearray, datatype, 1, - data.image[ID].md[0].NBkw, 0, &IDb0); - create_image_ID(logb1name, 3, imsizearray, datatype, 1, - data.image[ID].md[0].NBkw, 0, &IDb1); + create_image_ID(logb0name, 3, imsizearray, datatype, 1, data.image[ID].md[0].NBkw, 0, &IDb0); + create_image_ID(logb1name, 3, imsizearray, datatype, 1, data.image[ID].md[0].NBkw, 0, &IDb1); // copy keywords { - memcpy(data.image[IDb0].kw, data.image[ID].kw, - sizeof(IMAGE_KEYWORD)*data.image[ID].md[0].NBkw); - memcpy(data.image[IDb1].kw, data.image[ID].kw, - sizeof(IMAGE_KEYWORD)*data.image[ID].md[0].NBkw); + memcpy(data.image[IDb0].kw, data.image[ID].kw, sizeof(IMAGE_KEYWORD) * data.image[ID].md[0].NBkw); + memcpy(data.image[IDb1].kw, data.image[ID].kw, sizeof(IMAGE_KEYWORD) * data.image[ID].md[0].NBkw); } - COREMOD_MEMORY_image_set_semflush(logb0name, -1); COREMOD_MEMORY_image_set_semflush(logb1name, -1); + array_time = (double *)malloc(sizeof(double) * zsize); + array_cnt0 = (uint64_t *)malloc(sizeof(uint64_t) * zsize); + array_cnt1 = (uint64_t *)malloc(sizeof(uint64_t) * zsize); - array_time = (double *) malloc(sizeof(double) * zsize); - array_cnt0 = (uint64_t *) malloc(sizeof(uint64_t) * zsize); - array_cnt1 = (uint64_t *) malloc(sizeof(uint64_t) * zsize); - - array_time_cp = (double *) malloc(sizeof(double) * zsize); - array_cnt0_cp = (uint64_t *) malloc(sizeof(uint64_t) * zsize); - array_cnt1_cp = (uint64_t *) malloc(sizeof(uint64_t) * zsize); - + array_time_cp = (double *)malloc(sizeof(double) * zsize); + array_cnt0_cp = (uint64_t *)malloc(sizeof(uint64_t) * zsize); + array_cnt1_cp = (uint64_t *)malloc(sizeof(uint64_t) * zsize); IDb = IDb0; - switch(datatype) + switch (datatype) { - case _DATATYPE_FLOAT: - framesize = SIZEOF_DATATYPE_FLOAT * xsize * ysize; - ptr0_0 = (char *) data.image[ID].array.F; - break; - - case _DATATYPE_INT8: - framesize = SIZEOF_DATATYPE_INT8 * xsize * ysize; - ptr0_0 = (char *) data.image[ID].array.SI8; - break; - - case _DATATYPE_UINT8: - framesize = SIZEOF_DATATYPE_UINT8 * xsize * ysize; - ptr0_0 = (char *) data.image[ID].array.UI8; - break; - - case _DATATYPE_INT16: - framesize = SIZEOF_DATATYPE_INT16 * xsize * ysize; - ptr0_0 = (char *) data.image[ID].array.SI16; - break; - - case _DATATYPE_UINT16: - framesize = SIZEOF_DATATYPE_UINT16 * xsize * ysize; - ptr0_0 = (char *) data.image[ID].array.UI16; - break; - - case _DATATYPE_INT32: - framesize = SIZEOF_DATATYPE_INT32 * xsize * ysize; - ptr0_0 = (char *) data.image[ID].array.SI32; - break; - - case _DATATYPE_UINT32: - framesize = SIZEOF_DATATYPE_UINT32 * xsize * ysize; - ptr0_0 = (char *) data.image[ID].array.UI32; - break; - - case _DATATYPE_INT64: - framesize = SIZEOF_DATATYPE_INT64 * xsize * ysize; - ptr0_0 = (char *) data.image[ID].array.SI64; - break; - - case _DATATYPE_UINT64: - framesize = SIZEOF_DATATYPE_UINT64 * xsize * ysize; - ptr0_0 = (char *) data.image[ID].array.UI64; - break; - - - case _DATATYPE_DOUBLE: - framesize = SIZEOF_DATATYPE_DOUBLE * xsize * ysize; - ptr0_0 = (char *) data.image[ID].array.D; - break; - - default: - printf("ERROR: WRONG DATA TYPE\n"); - exit(0); - break; + case _DATATYPE_FLOAT: + framesize = SIZEOF_DATATYPE_FLOAT * xsize * ysize; + ptr0_0 = (char *)data.image[ID].array.F; + break; + + case _DATATYPE_INT8: + framesize = SIZEOF_DATATYPE_INT8 * xsize * ysize; + ptr0_0 = (char *)data.image[ID].array.SI8; + break; + + case _DATATYPE_UINT8: + framesize = SIZEOF_DATATYPE_UINT8 * xsize * ysize; + ptr0_0 = (char *)data.image[ID].array.UI8; + break; + + case _DATATYPE_INT16: + framesize = SIZEOF_DATATYPE_INT16 * xsize * ysize; + ptr0_0 = (char *)data.image[ID].array.SI16; + break; + + case _DATATYPE_UINT16: + framesize = SIZEOF_DATATYPE_UINT16 * xsize * ysize; + ptr0_0 = (char *)data.image[ID].array.UI16; + break; + + case _DATATYPE_INT32: + framesize = SIZEOF_DATATYPE_INT32 * xsize * ysize; + ptr0_0 = (char *)data.image[ID].array.SI32; + break; + + case _DATATYPE_UINT32: + framesize = SIZEOF_DATATYPE_UINT32 * xsize * ysize; + ptr0_0 = (char *)data.image[ID].array.UI32; + break; + + case _DATATYPE_INT64: + framesize = SIZEOF_DATATYPE_INT64 * xsize * ysize; + ptr0_0 = (char *)data.image[ID].array.SI64; + break; + + case _DATATYPE_UINT64: + framesize = SIZEOF_DATATYPE_UINT64 * xsize * ysize; + ptr0_0 = (char *)data.image[ID].array.UI64; + break; + + case _DATATYPE_DOUBLE: + framesize = SIZEOF_DATATYPE_DOUBLE * xsize * ysize; + ptr0_0 = (char *)data.image[ID].array.D; + break; + + default: + printf("ERROR: WRONG DATA TYPE\n"); + exit(0); + break; } - - - switch(datatype) + switch (datatype) { - case _DATATYPE_FLOAT: - ptr1_0 = (char *) data.image[IDb].array.F; - break; - - case _DATATYPE_INT8: - ptr1_0 = (char *) data.image[IDb].array.SI8; - break; + case _DATATYPE_FLOAT: + ptr1_0 = (char *)data.image[IDb].array.F; + break; - case _DATATYPE_UINT8: - ptr1_0 = (char *) data.image[IDb].array.UI8; - break; + case _DATATYPE_INT8: + ptr1_0 = (char *)data.image[IDb].array.SI8; + break; - case _DATATYPE_INT16: - ptr1_0 = (char *) data.image[IDb].array.SI16; - break; + case _DATATYPE_UINT8: + ptr1_0 = (char *)data.image[IDb].array.UI8; + break; - case _DATATYPE_UINT16: - ptr1_0 = (char *) data.image[IDb].array.UI16; - break; + case _DATATYPE_INT16: + ptr1_0 = (char *)data.image[IDb].array.SI16; + break; - case _DATATYPE_INT32: - ptr1_0 = (char *) data.image[IDb].array.SI32; - break; + case _DATATYPE_UINT16: + ptr1_0 = (char *)data.image[IDb].array.UI16; + break; - case _DATATYPE_UINT32: - ptr1_0 = (char *) data.image[IDb].array.UI32; - break; + case _DATATYPE_INT32: + ptr1_0 = (char *)data.image[IDb].array.SI32; + break; - case _DATATYPE_INT64: - ptr1_0 = (char *) data.image[IDb].array.SI64; - break; + case _DATATYPE_UINT32: + ptr1_0 = (char *)data.image[IDb].array.UI32; + break; - case _DATATYPE_UINT64: - ptr1_0 = (char *) data.image[IDb].array.UI64; - break; + case _DATATYPE_INT64: + ptr1_0 = (char *)data.image[IDb].array.SI64; + break; - case _DATATYPE_DOUBLE: - ptr1_0 = (char *) data.image[IDb].array.D; - break; + case _DATATYPE_UINT64: + ptr1_0 = (char *)data.image[IDb].array.UI64; + break; + case _DATATYPE_DOUBLE: + ptr1_0 = (char *)data.image[IDb].array.D; + break; } - - - cnt = data.image[ID].md[0].cnt0 - 1; buffer = 0; @@ -1088,30 +876,26 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( printf("logdata ID = %ld\n", IDlogdata); list_image_ID(); - - // using semlog ? use_semlog = 0; - if(data.image[ID].semlog != NULL) + if (data.image[ID].semlog != NULL) { use_semlog = 1; sem_getvalue(data.image[ID].semlog, &semval); // bring semaphore value to 1 to only save 1 frame - while(semval > 1) + while (semval > 1) { sem_wait(data.image[ID].semlog); sem_getvalue(data.image[ID].semlog, &semval); } - if(semval == 0) + if (semval == 0) { sem_post(data.image[ID].semlog); } } - - - while((logshimconf[0].filecnt != NBfiles) && (logshimconf[0].logexit == 0)) + while ((logshimconf[0].filecnt != NBfiles) && (logshimconf[0].logexit == 0)) { int timeout; // 1 if timeout has occurred @@ -1119,20 +903,20 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( noframe = 0; wOK = 1; - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d Entering wait loop index = %ld %d\n", __LINE__, index, noframe); } timeout = 0; - if(likely(use_semlog == 1)) + if (likely(use_semlog == 1)) { - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d Waiting for semaphore\n", __LINE__); } - if(clock_gettime(CLOCK_REALTIME, &ts) == -1) + if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { perror("clock_gettime"); exit(EXIT_FAILURE); @@ -1140,16 +924,14 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( ts.tv_sec += WaitSec; ret = sem_timedwait(data.image[ID].semlog, &ts); - if(ret == -1) + if (ret == -1) { - if(errno == ETIMEDOUT) + if (errno == ETIMEDOUT) { - printf("%5d sem_timedwait() timed out (%d sec) -[index %ld]\n", __LINE__, - WaitSec, index); - if(VERBOSE > 0) + printf("%5d sem_timedwait() timed out (%d sec) -[index %ld]\n", __LINE__, WaitSec, index); + if (VERBOSE > 0) { - printf("%5d sem time elapsed -> Save current cube [index %ld]\n", __LINE__, - index); + printf("%5d sem time elapsed -> Save current cube [index %ld]\n", __LINE__, index); } strcpy(tmsg->iname, iname); @@ -1157,9 +939,9 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( tmsg->partial = 1; // partial cube tmsg->cubesize = index; - memcpy(array_time_cp, array_time, sizeof(double)*index); - memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t)*index); - memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t)*index); + memcpy(array_time_cp, array_time, sizeof(double) * index); + memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t) * index); + memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t) * index); tmsg->arrayindex = array_cnt0_cp; tmsg->arraycnt0 = array_cnt0_cp; @@ -1168,28 +950,28 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( timeout = 1; } - if(errno == EINTR) + if (errno == EINTR) { - printf("%5d sem_timedwait [index %ld]: The call was interrupted by a signal handler\n", - __LINE__, index); + printf("%5d sem_timedwait [index %ld]: The call was interrupted by a signal handler\n", __LINE__, + index); } - if(errno == EINVAL) + if (errno == EINVAL) { - printf("%5d sem_timedwait [index %ld]: Not a valid semaphore\n", __LINE__, - index); - printf(" The value of abs_timeout.tv_nsecs is less than 0, or greater than or equal to 1000 million\n"); + printf("%5d sem_timedwait [index %ld]: Not a valid semaphore\n", __LINE__, index); + printf(" The value of abs_timeout.tv_nsecs is less than 0, or greater than or equal " + "to 1000 million\n"); } - if(errno == EAGAIN) + if (errno == EAGAIN) { - printf("%5d sem_timedwait [index %ld]: The operation could not be performed without blocking (i.e., the semaphore currently has the value zero)\n", + printf("%5d sem_timedwait [index %ld]: The operation could not be performed without blocking " + "(i.e., the semaphore currently has the value zero)\n", __LINE__, index); } - wOK = 0; - if(index == 0) + if (index == 0) { noframe = 1; } @@ -1198,19 +980,17 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( noframe = 0; } } - } else { - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d Not using semaphore, watching counter\n", __LINE__); } - while(((cnt == data.image[ID].md[0].cnt0) || (logshimconf[0].on == 0)) - && (wOK == 1)) + while (((cnt == data.image[ID].md[0].cnt0) || (logshimconf[0].on == 0)) && (wOK == 1)) { - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d waiting time step\n", __LINE__); } @@ -1218,28 +998,27 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( usleep(waitdelayus); cntwait++; - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d cntwait = %lld\n", __LINE__, cntwait); fflush(stdout); } - if(cntwait > cntwaitlim) // save current cube + if (cntwait > cntwaitlim) // save current cube { - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d cnt time elapsed -> Save current cube\n", __LINE__); } - strcpy(tmsg->iname, iname); strcpy(tmsg->fname, fname); tmsg->partial = 1; // partial cube tmsg->cubesize = index; - memcpy(array_time_cp, array_time, sizeof(double)*index); - memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t)*index); - memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t)*index); + memcpy(array_time_cp, array_time, sizeof(double) * index); + memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t) * index); + memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t) * index); tmsg->arrayindex = array_cnt0_cp; tmsg->arraycnt0 = array_cnt0_cp; @@ -1247,7 +1026,7 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( tmsg->arraytime = array_time_cp; wOK = 0; - if(index == 0) + if (index == 0) { noframe = 1; } @@ -1259,11 +1038,9 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( } } - - - if(index == 0) + if (index == 0) { - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d Setting cube start time [index %ld]\n", __LINE__, index); } @@ -1277,18 +1054,16 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( // sprintf(fnameascii,"%s/%s_%02d:%02d:%02ld.%09ld.txt", logdir, IDname, uttime->tm_hour, uttime->tm_min, timenow.tv_sec % 60, timenow.tv_nsec); } - - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d logshimconf[0].on = %d\n", __LINE__, logshimconf[0].on); } - - if(likely(logshimconf[0].on == 1)) + if (likely(logshimconf[0].on == 1)) { - if(likely(wOK == 1)) // normal step: a frame has arrived + if (likely(wOK == 1)) // normal step: a frame has arrived { - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d Frame has arrived [index %ld]\n", __LINE__, index); } @@ -1299,8 +1074,7 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( clock_gettime(CLOCK_REALTIME, &timenow); - - if(is3Dcube == 1) + if (is3Dcube == 1) { ptr0 = ptr0_0 + framesize * data.image[ID].md[0].cnt1; } @@ -1311,14 +1085,14 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( ptr1 = ptr1_0 + framesize * index; - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d memcpy framesize = %ld\n", __LINE__, framesize); } - memcpy((void *) ptr1, (void *) ptr0, framesize); + memcpy((void *)ptr1, (void *)ptr0, framesize); - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d memcpy done\n", __LINE__); } @@ -1336,33 +1110,30 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( // save partial if possible //if(index>0) wOK = 0; - } - - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d index = %ld wOK = %d\n", __LINE__, index, wOK); } - // SAVE CUBE TO DISK /// cases: /// index>zsize-1 buffer full /// timeout==1 && index>0 : partial - if((index > zsize - 1) || ((timeout == 1) && (index > 0))) + if ((index > zsize - 1) || ((timeout == 1) && (index > 0))) { long NBframemissing; /// save image - if(VERBOSE > 0) + if (VERBOSE > 0) { - printf("%5d Save image [index %ld] [timeout %d] [zsize %ld]\n", __LINE__, - index, timeout, (long) zsize); + printf("%5d Save image [index %ld] [timeout %d] [zsize %ld]\n", __LINE__, index, timeout, + (long)zsize); } sprintf(iname, "%s_logbuff%d", IDname, buffer); - if(buffer == 0) + if (buffer == 0) { IDb = IDb0; } @@ -1372,52 +1143,43 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( } // update buffer content - memcpy(data.image[IDb].kw, data.image[ID].kw, - sizeof(IMAGE_KEYWORD)*data.image[ID].md[0].NBkw); - + memcpy(data.image[IDb].kw, data.image[ID].kw, sizeof(IMAGE_KEYWORD) * data.image[ID].md[0].NBkw); - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d Building file name: ascii\n", __LINE__); fflush(stdout); } - sprintf(fnameascii, "%s/%s_%02d:%02d:%02ld.%09ld.txt", logdir, IDname, - uttimeStart->tm_hour, uttimeStart->tm_min, timenowStart.tv_sec % 60, - timenowStart.tv_nsec); + sprintf(fnameascii, "%s/%s_%02d:%02d:%02ld.%09ld.txt", logdir, IDname, uttimeStart->tm_hour, + uttimeStart->tm_min, timenowStart.tv_sec % 60, timenowStart.tv_nsec); - - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d Building file name: fits\n", __LINE__); fflush(stdout); } - sprintf(fname, "%s/%s_%02d:%02d:%02ld.%09ld.fits", logdir, IDname, - uttimeStart->tm_hour, uttimeStart->tm_min, timenowStart.tv_sec % 60, - timenowStart.tv_nsec); - - + sprintf(fname, "%s/%s_%02d:%02d:%02ld.%09ld.fits", logdir, IDname, uttimeStart->tm_hour, + uttimeStart->tm_min, timenowStart.tv_sec % 60, timenowStart.tv_nsec); strcpy(tmsg->iname, iname); strcpy(tmsg->fname, fname); strcpy(tmsg->fnameascii, fnameascii); tmsg->saveascii = 1; - - if(wOK == 1) // full cube + if (wOK == 1) // full cube { tmsg->partial = 0; // full cube - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d SAVING FULL CUBE\n", __LINE__); fflush(stdout); } - } else // partial cube { tmsg->partial = 1; // partial cube - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d SAVING PARTIAL CUBE\n", __LINE__); fflush(stdout); @@ -1428,99 +1190,82 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( long cnt0start = data.image[ID].md[0].cnt0; // Wait for save thread to complete to launch next one - if(tOK == 1) + if (tOK == 1) { - if(pthread_tryjoin_np(thread_savefits, NULL) == EBUSY) + if (pthread_tryjoin_np(thread_savefits, NULL) == EBUSY) { - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d PREVIOUS SAVE THREAD NOT TERMINATED -> waiting\n", __LINE__); } pthread_join(thread_savefits, NULL); - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d PREVIOUS SAVE THREAD NOW COMPLETED -> continuing\n", __LINE__); } } else { - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d PREVIOUS SAVE THREAD ALREADY COMPLETED -> OK\n", __LINE__); } } } - printf("\n ************** MISSED = %ld\n", - data.image[ID].md[0].cnt0 - cnt0start); + printf("\n ************** MISSED = %ld\n", data.image[ID].md[0].cnt0 - cnt0start); } - COREMOD_MEMORY_image_set_sempost_byID(IDb, -1); data.image[IDb].md[0].cnt0++; data.image[IDb].md[0].write = 0; - - tmsg->cubesize = index; strcpy(tmsg->iname, iname); + memcpy(array_time_cp, array_time, sizeof(double) * index); - memcpy(array_time_cp, array_time, sizeof(double)*index); - - - memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t)*index); + memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t) * index); - - memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t)*index); + memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t) * index); NBframemissing = (array_cnt0[index - 1] - array_cnt0[0]) - (index - 1); - printf("=>=>=>=>= CUBE %8lld Number of missed frames = %8ld / %ld / %8ld ====\n", - logshimconf[0].filecnt, NBframemissing, index, (long) zsize); + logshimconf[0].filecnt, NBframemissing, index, (long)zsize); - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d Starting image save thread\n", __LINE__); fflush(stdout); } - - tmsg->arrayindex = array_cnt0_cp; tmsg->arraycnt0 = array_cnt0_cp; tmsg->arraycnt1 = array_cnt1_cp; tmsg->arraytime = array_time_cp; - WRITE_FILENAME(tmsg->fname_auxFITSheader, - "%s/%s.auxFITSheader.shm", - data.shmdir, - IDname); - + WRITE_FILENAME(tmsg->fname_auxFITSheader, "%s/%s.auxFITSheader.shm", data.shmdir, IDname); - iret_savefits = pthread_create(&thread_savefits, NULL, save_fits_function, - tmsg); + iret_savefits = pthread_create(&thread_savefits, NULL, save_fits_function, tmsg); - - logshimconf[0].cnt ++; + logshimconf[0].cnt++; tOK = 1; - if(iret_savefits) + if (iret_savefits) { fprintf(stderr, "Error - pthread_create() return code: %d\n", iret_savefits); exit(EXIT_FAILURE); } - index = 0; buffer++; - if(buffer == 2) + if (buffer == 2) { buffer = 0; } // printf("[%ld -> %d]", cnt, buffer); // fflush(stdout); - if(buffer == 0) + if (buffer == 0) { IDb = IDb0; } @@ -1529,56 +1274,54 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( IDb = IDb1; } - switch(datatype) + switch (datatype) { - case _DATATYPE_FLOAT: - ptr1_0 = (char *) data.image[IDb].array.F; - break; - - case _DATATYPE_INT8: - ptr1_0 = (char *) data.image[IDb].array.SI8; - break; + case _DATATYPE_FLOAT: + ptr1_0 = (char *)data.image[IDb].array.F; + break; - case _DATATYPE_UINT8: - ptr1_0 = (char *) data.image[IDb].array.UI8; - break; + case _DATATYPE_INT8: + ptr1_0 = (char *)data.image[IDb].array.SI8; + break; - case _DATATYPE_INT16: - ptr1_0 = (char *) data.image[IDb].array.SI16; - break; + case _DATATYPE_UINT8: + ptr1_0 = (char *)data.image[IDb].array.UI8; + break; - case _DATATYPE_UINT16: - ptr1_0 = (char *) data.image[IDb].array.UI16; - break; + case _DATATYPE_INT16: + ptr1_0 = (char *)data.image[IDb].array.SI16; + break; - case _DATATYPE_INT32: - ptr1_0 = (char *) data.image[IDb].array.SI32; - break; + case _DATATYPE_UINT16: + ptr1_0 = (char *)data.image[IDb].array.UI16; + break; - case _DATATYPE_UINT32: - ptr1_0 = (char *) data.image[IDb].array.UI32; - break; + case _DATATYPE_INT32: + ptr1_0 = (char *)data.image[IDb].array.SI32; + break; - case _DATATYPE_INT64: - ptr1_0 = (char *) data.image[IDb].array.SI64; - break; + case _DATATYPE_UINT32: + ptr1_0 = (char *)data.image[IDb].array.UI32; + break; - case _DATATYPE_UINT64: - ptr1_0 = (char *) data.image[IDb].array.UI64; - break; + case _DATATYPE_INT64: + ptr1_0 = (char *)data.image[IDb].array.SI64; + break; - case _DATATYPE_DOUBLE: - ptr1_0 = (char *) data.image[IDb].array.D; - break; + case _DATATYPE_UINT64: + ptr1_0 = (char *)data.image[IDb].array.UI64; + break; + case _DATATYPE_DOUBLE: + ptr1_0 = (char *)data.image[IDb].array.D; + break; } data.image[IDb].md[0].write = 1; - logshimconf[0].filecnt ++; + logshimconf[0].filecnt++; } - cnt = data.image[ID].md[0].cnt0; } @@ -1595,11 +1338,3 @@ errno_t __attribute__((hot)) COREMOD_MEMORY_sharedMem_2Dim_log( return RETURN_SUCCESS; } - - - - - - - - diff --git a/src/COREMOD_memory/logshmim.h b/src/COREMOD_memory/logshmim.h index be1e647c..f64e7a7c 100644 --- a/src/COREMOD_memory/logshmim.h +++ b/src/COREMOD_memory/logshmim.h @@ -2,41 +2,20 @@ * @file logshmim.h */ - - #ifndef CLICORE_MEMORY_LOGSHMIM_H #define CLICORE_MEMORY_LOGSHMIM_H - - errno_t logshmim_addCLIcmd(); +void *save_fits_function(void *ptr); -void *save_fits_function( - void *ptr -); - - - -errno_t COREMOD_MEMORY_logshim_printstatus( - const char *IDname -); +errno_t COREMOD_MEMORY_logshim_printstatus(const char *IDname); -errno_t COREMOD_MEMORY_logshim_set_on( - const char *IDname, - int setv -); +errno_t COREMOD_MEMORY_logshim_set_on(const char *IDname, int setv); -errno_t COREMOD_MEMORY_logshim_set_logexit( - const char *IDname, - int setv -); +errno_t COREMOD_MEMORY_logshim_set_logexit(const char *IDname, int setv); -errno_t COREMOD_MEMORY_sharedMem_2Dim_log( - const char *IDname, - uint32_t zsize, - const char *logdir, - const char *IDlogdata_name -); +errno_t COREMOD_MEMORY_sharedMem_2Dim_log(const char *IDname, uint32_t zsize, const char *logdir, + const char *IDlogdata_name); #endif diff --git a/src/COREMOD_memory/read_shmim.c b/src/COREMOD_memory/read_shmim.c index 0efb4aea..7beef0f1 100644 --- a/src/COREMOD_memory/read_shmim.c +++ b/src/COREMOD_memory/read_shmim.c @@ -3,63 +3,36 @@ * @brief read shared memory stream */ +#include // open +#include // mmap #include -#include // open #include // close -#include // mmap #include "CommandLineInterface/CLIcore.h" #include "image_ID.h" -#include "list_image.h" #include "image_keyword_list.h" - - +#include "list_image.h" // Local variables pointers static char *insname; - // List of arguments to function -static CLICMDARGDEF farg[] = -{ - { - CLIARG_STR_NOT_IMG, ".in_sname", "input stream", "ims1", - CLIARG_VISIBLE_DEFAULT, - (void **) &insname, NULL - } -}; - - - +static CLICMDARGDEF farg[] = { + {CLIARG_STR_NOT_IMG, ".in_sname", "input stream", "ims1", CLIARG_VISIBLE_DEFAULT, (void **)&insname, NULL}}; // flag CLICMDFLAG_FPS enabled FPS capability -static CLICMDDATA CLIcmddata = -{ - "readshmim", - "read shared memory image", - CLICMD_FIELDS_DEFAULTS -}; - - - +static CLICMDDATA CLIcmddata = {"readshmim", "read shared memory image", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} +static errno_t help_function() { return RETURN_SUCCESS; } - - -imageID read_sharedmem_image( - const char *sname -) +imageID read_sharedmem_image(const char *sname) { imageID ID = -1; imageID IDmem = 0; IMAGE *image; - if(strlen(sname) != 0) + if (strlen(sname) != 0) { DEBUG_TRACEPOINT("looking for next ID"); IDmem = next_avail_image_ID(); @@ -67,8 +40,7 @@ imageID read_sharedmem_image( image = &data.image[IDmem]; - if(ImageStreamIO_read_sharedmem_image_toIMAGE(sname, - image) != IMAGESTREAMIO_SUCCESS) + if (ImageStreamIO_read_sharedmem_image_toIMAGE(sname, image) != IMAGESTREAMIO_SUCCESS) { printf("read shared mem image failed -> ID = -1\n"); fflush(stdout); @@ -89,7 +61,7 @@ imageID read_sharedmem_image( image_keywords_list(img); } - if(data.MEM_MONITOR == 1) + if (data.MEM_MONITOR == 1) { list_image_ID_ncurses(); } @@ -101,8 +73,6 @@ imageID read_sharedmem_image( } } - - // adding INSERT_STD_PROCINFO statements enables processinfo support static errno_t compute_function() { @@ -118,17 +88,11 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - - - INSERT_STD_FPSCLIfunctions -errno_t CLIADDCMD_COREMOD_memory__read_sharedmem_image() + errno_t + CLIADDCMD_COREMOD_memory__read_sharedmem_image() { INSERT_STD_CLIREGISTERFUNC return RETURN_SUCCESS; } - - - diff --git a/src/COREMOD_memory/read_shmim.h b/src/COREMOD_memory/read_shmim.h index fc75ca97..91781d96 100644 --- a/src/COREMOD_memory/read_shmim.h +++ b/src/COREMOD_memory/read_shmim.h @@ -2,14 +2,11 @@ * @file read_shmim.h */ - #ifndef COREMOD_MEMORY_READ_SHMIM_H #define COREMOD_MEMORY_READ_SHMIM_H errno_t CLIADDCMD_COREMOD_memory__read_sharedmem_image(); -imageID read_sharedmem_image( - const char *name -); +imageID read_sharedmem_image(const char *name); #endif diff --git a/src/COREMOD_memory/read_shmim_size.c b/src/COREMOD_memory/read_shmim_size.c index 9c780de2..23e504fc 100644 --- a/src/COREMOD_memory/read_shmim_size.c +++ b/src/COREMOD_memory/read_shmim_size.c @@ -3,59 +3,30 @@ * @brief read shared memory stream */ +#include // open +#include // mmap #include -#include // open #include // close -#include // mmap #include "CommandLineInterface/CLIcore.h" #include "image_ID.h" #include "list_image.h" - - - // Local variables pointers static char *insname; static char *outfname; - // List of arguments to function -static CLICMDARGDEF farg[] = -{ - { - CLIARG_STR, ".in_sname", "input stream", "ims1", - CLIARG_VISIBLE_DEFAULT, - (void **) &insname, NULL - }, - { - CLIARG_STR_NOT_IMG, ".outfname", "output file name", "outsize.dat", - CLIARG_VISIBLE_DEFAULT, - (void **) &outfname, NULL - } -}; - - - +static CLICMDARGDEF farg[] = { + {CLIARG_STR, ".in_sname", "input stream", "ims1", CLIARG_VISIBLE_DEFAULT, (void **)&insname, NULL}, + {CLIARG_STR_NOT_IMG, ".outfname", "output file name", "outsize.dat", CLIARG_VISIBLE_DEFAULT, (void **)&outfname, + NULL}}; // flag CLICMDFLAG_FPS enabled FPS capability -static CLICMDDATA CLIcmddata = -{ - "readshmimsize", - "read shared memory image size", - CLICMD_FIELDS_DEFAULTS -}; - - +static CLICMDDATA CLIcmddata = {"readshmimsize", "read shared memory image size", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - - - +static errno_t help_function() { return RETURN_SUCCESS; } /** * ## Purpose @@ -74,26 +45,22 @@ static errno_t help_function() * file name to write image name * */ -imageID read_sharedmem_image_size( - const char *name, - const char *fname -) +imageID read_sharedmem_image_size(const char *name, const char *fname) { - int SM_fd; - struct stat file_stat; - char SM_fname[STRINGMAXLEN_FULLFILENAME]; + int SM_fd; + struct stat file_stat; + char SM_fname[STRINGMAXLEN_FULLFILENAME]; IMAGE_METADATA *map; - int i; - FILE *fp; - imageID ID = -1; + int i; + FILE *fp; + imageID ID = -1; - - if((ID = image_ID(name)) == -1) + if ((ID = image_ID(name)) == -1) { WRITE_FULLFILENAME(SM_fname, "%s/%s.im.shm", data.shmdir, name); SM_fd = open(SM_fname, O_RDWR); - if(SM_fd == -1) + if (SM_fd == -1) { printf("Cannot import file - continuing\n"); } @@ -102,9 +69,8 @@ imageID read_sharedmem_image_size( fstat(SM_fd, &file_stat); // printf("File %s size: %zd\n", SM_fname, file_stat.st_size); - map = (IMAGE_METADATA *) mmap(0, sizeof(IMAGE_METADATA), PROT_READ | PROT_WRITE, - MAP_SHARED, SM_fd, 0); - if(map == MAP_FAILED) + map = (IMAGE_METADATA *)mmap(0, sizeof(IMAGE_METADATA), PROT_READ | PROT_WRITE, MAP_SHARED, SM_fd, 0); + if (map == MAP_FAILED) { close(SM_fd); perror("Error mmapping the file"); @@ -112,15 +78,14 @@ imageID read_sharedmem_image_size( } fp = fopen(fname, "w"); - for(i = 0; i < map[0].naxis; i++) + for (i = 0; i < map[0].naxis; i++) { - fprintf(fp, "%ld ", (long) map[0].size[i]); + fprintf(fp, "%ld ", (long)map[0].size[i]); } fprintf(fp, "\n"); fclose(fp); - - if(munmap(map, sizeof(IMAGE_METADATA)) == -1) + if (munmap(map, sizeof(IMAGE_METADATA)) == -1) { printf("unmapping %s\n", SM_fname); perror("Error un-mmapping the file"); @@ -131,9 +96,9 @@ imageID read_sharedmem_image_size( else { fp = fopen(fname, "w"); - for(i = 0; i < data.image[ID].md[0].naxis; i++) + for (i = 0; i < data.image[ID].md[0].naxis; i++) { - fprintf(fp, "%ld ", (long) data.image[ID].md[0].size[i]); + fprintf(fp, "%ld ", (long)data.image[ID].md[0].size[i]); } fprintf(fp, "\n"); fclose(fp); @@ -142,24 +107,13 @@ imageID read_sharedmem_image_size( return ID; } - - - - - - - - // adding INSERT_STD_PROCINFO statements enables processinfo support static errno_t compute_function() { DEBUG_TRACE_FSTART(); INSERT_STD_PROCINFO_COMPUTEFUNC_START - read_sharedmem_image_size( - insname, - outfname - ); + read_sharedmem_image_size(insname, outfname); INSERT_STD_PROCINFO_COMPUTEFUNC_END @@ -167,12 +121,11 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - INSERT_STD_FPSCLIfunctions -// Register function in CLI -errno_t CLIADDCMD_COREMOD_memory__read_sharedmem_image_size() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_memory__read_sharedmem_image_size() { INSERT_STD_CLIREGISTERFUNC diff --git a/src/COREMOD_memory/read_shmim_size.h b/src/COREMOD_memory/read_shmim_size.h index 7f4963d8..4d1a2dfa 100644 --- a/src/COREMOD_memory/read_shmim_size.h +++ b/src/COREMOD_memory/read_shmim_size.h @@ -3,9 +3,6 @@ errno_t CLIADDCMD_COREMOD_memory__read_sharedmem_image_size(); -imageID read_sharedmem_image_size( - const char *name, - const char *fname -); +imageID read_sharedmem_image_size(const char *name, const char *fname); #endif diff --git a/src/COREMOD_memory/read_shmimall.c b/src/COREMOD_memory/read_shmimall.c index d33f8f79..4c5c639d 100644 --- a/src/COREMOD_memory/read_shmimall.c +++ b/src/COREMOD_memory/read_shmimall.c @@ -3,42 +3,32 @@ * @brief read all shared memory stream */ +#include // open +#include // mmap #include -#include // open #include // close -#include // mmap #include "CommandLineInterface/CLIcore.h" #include "image_ID.h" #include "list_image.h" #include "read_shmim.h" - - - // ========================================== // forward declaration // ========================================== -errno_t read_sharedmem_image_all( - const char *name -); - +errno_t read_sharedmem_image_all(const char *name); // ========================================== // command line interface wrapper functions // ========================================== - static errno_t read_sharedmem_image_all__cli() { - if(0 - + CLI_checkarg(1, CLIARG_STR) - == 0) + if (0 + CLI_checkarg(1, CLIARG_STR) == 0) { - read_sharedmem_image_all( - data.cmdargtoken[1].val.string); + read_sharedmem_image_all(data.cmdargtoken[1].val.string); return CLICMD_SUCCESS; } @@ -48,13 +38,6 @@ static errno_t read_sharedmem_image_all__cli() } } - - - - - - - // ========================================== // Register CLI command(s) // ========================================== @@ -62,44 +45,29 @@ static errno_t read_sharedmem_image_all__cli() errno_t read_shmimall_addCLIcmd() { - RegisterCLIcommand( - "readshmimall", - __FILE__, - read_sharedmem_image_all__cli, - "read all shared memory images", - "", - "readshmimall aol_", - "read_sharedmem_image_all(const char *name)"); + RegisterCLIcommand("readshmimall", __FILE__, read_sharedmem_image_all__cli, "read all shared memory images", + "", "readshmimall aol_", "read_sharedmem_image_all(const char *name)"); return RETURN_SUCCESS; } - - - - - - - -errno_t read_sharedmem_image_all( - const char *strfilter -) +errno_t read_sharedmem_image_all(const char *strfilter) { //printf("LOADING ALL STREAMS matching %s\n", strfilter); int NBstreamMAX = 10000; STREAMINFO *streaminfo; - streaminfo = (STREAMINFO *) malloc(sizeof(STREAMINFO) * NBstreamMAX); + streaminfo = (STREAMINFO *)malloc(sizeof(STREAMINFO) * NBstreamMAX); int NBstream = find_streams(streaminfo, 1, strfilter); //printf("%d streams found :\n", NBstream); - for(int sindex = 0; sindex < NBstream; sindex++) + for (int sindex = 0; sindex < NBstream; sindex++) { //printf(" %3d %s\n", sindex, streaminfo[sindex].sname); imageID ID = image_ID(streaminfo[sindex].sname); - if(ID == -1) + if (ID == -1) { read_sharedmem_image(streaminfo[sindex].sname); } @@ -109,5 +77,3 @@ errno_t read_sharedmem_image_all( return RETURN_SUCCESS; } - - diff --git a/src/COREMOD_memory/read_shmimall.h b/src/COREMOD_memory/read_shmimall.h index e50686e2..84cc4cec 100644 --- a/src/COREMOD_memory/read_shmimall.h +++ b/src/COREMOD_memory/read_shmimall.h @@ -2,16 +2,11 @@ * @file read_shmimall.h */ - #ifndef _READ_SHMIMALL_H #define _READ_SHMIMALL_H - errno_t read_shmimall_addCLIcmd(); - -imageID read_sharedmem_image_all( - const char *strfilter -); +imageID read_sharedmem_image_all(const char *strfilter); #endif diff --git a/src/COREMOD_memory/saveall.c b/src/COREMOD_memory/saveall.c index 95405a45..3f6de44d 100644 --- a/src/COREMOD_memory/saveall.c +++ b/src/COREMOD_memory/saveall.c @@ -1,47 +1,30 @@ /** @file saveall.c */ - #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" -#include "list_image.h" #include "create_image.h" #include "delete_image.h" +#include "image_ID.h" #include "image_copy.h" +#include "list_image.h" #include "COREMOD_iofits/COREMOD_iofits.h" - - - - // ========================================== // Forward declaration(s) // ========================================== -errno_t COREMOD_MEMORY_SaveAll_snapshot( - const char *dirname -); - - -errno_t COREMOD_MEMORY_SaveAll_sequ( - const char *dirname, - const char *IDtrig_name, - long semtrig, - long NBframes -); - +errno_t COREMOD_MEMORY_SaveAll_snapshot(const char *dirname); +errno_t COREMOD_MEMORY_SaveAll_sequ(const char *dirname, const char *IDtrig_name, long semtrig, long NBframes); // ========================================== // Command line interface wrapper function(s) // ========================================== - static errno_t COREMOD_MEMORY_SaveAll_snapshot__cli() { - if(0 - + CLI_checkarg(1, 5) == 0) + if (0 + CLI_checkarg(1, 5) == 0) { COREMOD_MEMORY_SaveAll_snapshot(data.cmdargtoken[1].val.string); return CLICMD_SUCCESS; @@ -52,22 +35,14 @@ static errno_t COREMOD_MEMORY_SaveAll_snapshot__cli() } } - static errno_t COREMOD_MEMORY_SaveAll_sequ__cli() { - if(0 - + CLI_checkarg(1, 5) - + CLI_checkarg(2, CLIARG_IMG) - + CLI_checkarg(3, CLIARG_LONG) - + CLI_checkarg(4, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, 5) + CLI_checkarg(2, CLIARG_IMG) + CLI_checkarg(3, CLIARG_LONG) + + CLI_checkarg(4, CLIARG_LONG) == + 0) { - COREMOD_MEMORY_SaveAll_sequ( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.string, - data.cmdargtoken[3].val.numl, - data.cmdargtoken[4].val.numl - ); + COREMOD_MEMORY_SaveAll_sequ(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, + data.cmdargtoken[3].val.numl, data.cmdargtoken[4].val.numl); return CLICMD_SUCCESS; } else @@ -76,10 +51,6 @@ static errno_t COREMOD_MEMORY_SaveAll_sequ__cli() } } - - - - // ========================================== // Register CLI command(s) // ========================================== @@ -87,39 +58,22 @@ static errno_t COREMOD_MEMORY_SaveAll_sequ__cli() errno_t saveall_addCLIcmd() { - RegisterCLIcommand( - "imsaveallsnap", - __FILE__, - COREMOD_MEMORY_SaveAll_snapshot__cli, "save all images in directory", - "", "imsaveallsnap dir1", - "long COREMOD_MEMORY_SaveAll_snapshot(const char *dirname)"); + RegisterCLIcommand("imsaveallsnap", __FILE__, COREMOD_MEMORY_SaveAll_snapshot__cli, "save all images in directory", + "", "imsaveallsnap dir1", + "long COREMOD_MEMORY_SaveAll_snapshot(const char *dirname)"); RegisterCLIcommand( - "imsaveallseq", - __FILE__, - COREMOD_MEMORY_SaveAll_sequ__cli, - "save all images in directory - sequence", - " ", - "imsaveallsequ dir1 im1 3 20", + "imsaveallseq", __FILE__, COREMOD_MEMORY_SaveAll_sequ__cli, "save all images in directory - sequence", + " ", "imsaveallsequ dir1 im1 3 20", "long COREMOD_MEMORY_SaveAll_sequ(const char *dirname, const char *IDtrig_name, long semtrig, long NBframes)"); return RETURN_SUCCESS; } - - - - - - - - // // save all current images/stream onto file // -errno_t COREMOD_MEMORY_SaveAll_snapshot( - const char *dirname -) +errno_t COREMOD_MEMORY_SaveAll_snapshot(const char *dirname) { long *IDarray; long *IDarraycp; @@ -129,20 +83,19 @@ errno_t COREMOD_MEMORY_SaveAll_snapshot( char fnamecp[STRINGMAXLEN_FULLFILENAME]; long ID; - - for(i = 0; i < data.NB_MAX_IMAGE; i++) - if(data.image[i].used == 1) + for (i = 0; i < data.NB_MAX_IMAGE; i++) + if (data.image[i].used == 1) { imcnt++; } - IDarray = (long *) malloc(sizeof(long) * imcnt); - IDarraycp = (long *) malloc(sizeof(long) * imcnt); + IDarray = (long *)malloc(sizeof(long) * imcnt); + IDarraycp = (long *)malloc(sizeof(long) * imcnt); imcnt = 0; - for(i = 0; i < data.NB_MAX_IMAGE; i++) + for (i = 0; i < data.NB_MAX_IMAGE; i++) { - if(data.image[i].used == 1) + if (data.image[i].used == 1) { IDarray[imcnt] = i; imcnt++; @@ -152,7 +105,7 @@ errno_t COREMOD_MEMORY_SaveAll_snapshot( EXECUTE_SYSTEM_COMMAND("mkdir -p %s", dirname); // create array for each image - for(i = 0; i < imcnt; i++) + for (i = 0; i < imcnt; i++) { ID = IDarray[i]; WRITE_IMAGENAME(imnamecp, "%s_cp", data.image[ID].name); @@ -162,7 +115,7 @@ errno_t COREMOD_MEMORY_SaveAll_snapshot( list_image_ID(); - for(i = 0; i < imcnt; i++) + for (i = 0; i < imcnt; i++) { ID = IDarray[i]; WRITE_IMAGENAME(imnamecp, "%s_cp", data.image[ID].name); @@ -173,22 +126,14 @@ errno_t COREMOD_MEMORY_SaveAll_snapshot( free(IDarray); free(IDarraycp); - return RETURN_SUCCESS; } - - // // save all current images/stream onto file // only saves 2D float streams into 3D cubes // -errno_t COREMOD_MEMORY_SaveAll_sequ( - const char *dirname, - const char *IDtrig_name, - long semtrig, - long NBframes -) +errno_t COREMOD_MEMORY_SaveAll_sequ(const char *dirname, const char *IDtrig_name, long semtrig, long NBframes) { long *IDarray; long *IDarrayout; @@ -204,52 +149,41 @@ errno_t COREMOD_MEMORY_SaveAll_sequ( char *ptr1; uint32_t *imsizearray; - - - - for(i = 0; i < data.NB_MAX_IMAGE; i++) - if(data.image[i].used == 1) + for (i = 0; i < data.NB_MAX_IMAGE; i++) + if (data.image[i].used == 1) { imcnt++; } - IDarray = (imageID *) malloc(sizeof(imageID) * imcnt); - IDarrayout = (imageID *) malloc(sizeof(imageID) * imcnt); + IDarray = (imageID *)malloc(sizeof(imageID) * imcnt); + IDarrayout = (imageID *)malloc(sizeof(imageID) * imcnt); imcnt = 0; - for(i = 0; i < data.NB_MAX_IMAGE; i++) - if(data.image[i].used == 1) + for (i = 0; i < data.NB_MAX_IMAGE; i++) + if (data.image[i].used == 1) { IDarray[imcnt] = i; imcnt++; } - imsizearray = (uint32_t *) malloc(sizeof(uint32_t) * imcnt); - - + imsizearray = (uint32_t *)malloc(sizeof(uint32_t) * imcnt); EXECUTE_SYSTEM_COMMAND("mkdir -p %s", dirname); IDtrig = image_ID(IDtrig_name); - printf("Creating arrays\n"); fflush(stdout); // create 3D arrays - for(i = 0; i < imcnt; i++) + for (i = 0; i < imcnt; i++) { sprintf(imnameout, "%s_out", data.image[IDarray[i]].name); - imsizearray[i] = sizeof(float) * data.image[IDarray[i]].md[0].size[0] * - data.image[IDarray[i]].md[0].size[1]; - printf("Creating image %s size %d x %d x %ld\n", imnameout, - data.image[IDarray[i]].md[0].size[0], data.image[IDarray[i]].md[0].size[1], - NBframes); + imsizearray[i] = sizeof(float) * data.image[IDarray[i]].md[0].size[0] * data.image[IDarray[i]].md[0].size[1]; + printf("Creating image %s size %d x %d x %ld\n", imnameout, data.image[IDarray[i]].md[0].size[0], + data.image[IDarray[i]].md[0].size[1], NBframes); fflush(stdout); - create_3Dimage_ID(imnameout, - data.image[IDarray[i]].md[0].size[0], - data.image[IDarray[i]].md[0].size[1], - NBframes, - &(IDarrayout[i])); + create_3Dimage_ID(imnameout, data.image[IDarray[i]].md[0].size[0], data.image[IDarray[i]].md[0].size[1], + NBframes, &(IDarrayout[i])); } list_image_ID(); @@ -257,30 +191,30 @@ errno_t COREMOD_MEMORY_SaveAll_sequ( fflush(stdout); // drive semaphore to zero - while(sem_trywait(data.image[IDtrig].semptr[semtrig]) == 0) {} + while (sem_trywait(data.image[IDtrig].semptr[semtrig]) == 0) + { + } frame = 0; - while(frame < NBframes) + while (frame < NBframes) { sem_wait(data.image[IDtrig].semptr[semtrig]); - for(i = 0; i < imcnt; i++) + for (i = 0; i < imcnt; i++) { ID = IDarray[i]; - ptr0 = (char *) data.image[IDarrayout[i]].array.F; + ptr0 = (char *)data.image[IDarrayout[i]].array.F; ptr1 = ptr0 + imsizearray[i] * frame; memcpy(ptr1, data.image[ID].array.F, imsizearray[i]); } frame++; } - printf("Saving images\n"); fflush(stdout); list_image_ID(); - - for(i = 0; i < imcnt; i++) + for (i = 0; i < imcnt; i++) { ID = IDarray[i]; sprintf(imnameout, "%s_out", data.image[ID].name); @@ -294,8 +228,3 @@ errno_t COREMOD_MEMORY_SaveAll_sequ( return RETURN_SUCCESS; } - - - - - diff --git a/src/COREMOD_memory/saveall.h b/src/COREMOD_memory/saveall.h index f2f55286..69e64454 100644 --- a/src/COREMOD_memory/saveall.h +++ b/src/COREMOD_memory/saveall.h @@ -1,23 +1,8 @@ /** @file saveall.h */ - - - errno_t saveall_addCLIcmd(); +errno_t COREMOD_MEMORY_SaveAll_snapshot(const char *dirname); - -errno_t COREMOD_MEMORY_SaveAll_snapshot( - const char *dirname -); - - -errno_t COREMOD_MEMORY_SaveAll_sequ( - const char *dirname, - const char *IDtrig_name, - long semtrig, - long NBframes -); - - +errno_t COREMOD_MEMORY_SaveAll_sequ(const char *dirname, const char *IDtrig_name, long semtrig, long NBframes); diff --git a/src/COREMOD_memory/scripts/milk-rmshmim b/src/COREMOD_memory/scripts/milk-rmshmim index e2d99683..b30677b9 100755 --- a/src/COREMOD_memory/scripts/milk-rmshmim +++ b/src/COREMOD_memory/scripts/milk-rmshmim @@ -10,25 +10,25 @@ echo "pname = $pname" function printHELP { -echo "------------------------------------------------------------------------" -echo "$(tput bold) $pname : remove shmim and files $(tput sgr0)" -echo "------------------------------------------------------------------------" -echo " Remove shared memory image (stream) and associated files" -echo " Multiple streams can be entered, separated by comma, no space" -echo " " -echo " $(tput bold)USAGE:$(tput sgr0)" -echo " $0 [-h] " -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -echo " $(tput bold)-h$(tput sgr0) (h)elp" -echo "" -echo "------------------------------------------------------------------------" + echo "------------------------------------------------------------------------" + echo "$(tput bold) $pname : remove shmim and files $(tput sgr0)" + echo "------------------------------------------------------------------------" + echo " Remove shared memory image (stream) and associated files" + echo " Multiple streams can be entered, separated by comma, no space" + echo " " + echo " $(tput bold)USAGE:$(tput sgr0)" + echo " $0 [-h] " + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + echo " $(tput bold)-h$(tput sgr0) (h)elp" + echo "" + echo "------------------------------------------------------------------------" } printHELP1 () { - printf "%20s Remove shared memory image (stream)\n" "$0" + printf "%20s Remove shared memory image (stream)\n" "$0" } @@ -39,38 +39,38 @@ printHELP1 () # Transform long options to short ones singlelinehelp=0 for arg in "$@"; do - shift - case "$arg" in - "--help") set -- "$@" "-h" ;; - "--help1") -set -- "$@" "-h" -singlelinehelp=1; -;; - *) set -- "$@" "$arg" - esac + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--help1") + set -- "$@" "-h" + singlelinehelp=1; + ;; + *) set -- "$@" "$arg" + esac done while getopts :h FLAG; do - case $FLAG in - h) #show help - if [ "$singlelinehelp" -eq "0" ]; then - printHELP - else - printHELP1 - fi - exit - ;; - \?) - echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." - printHELP - ;; - esac + case $FLAG in + h) #show help + if [ "$singlelinehelp" -eq "0" ]; then + printHELP + else + printHELP1 + fi + exit + ;; + \?) + echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." + printHELP + ;; + esac done -shift $((OPTIND-1)) +shift $((OPTIND-1)) ### End getopts code ### @@ -80,11 +80,11 @@ shift $((OPTIND-1)) if [ "$1" = "help" ] || [ "$#" -ne $NBARGS ]; then -if [ "$#" -ne $NBARGS ]; then - echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" -fi -printHELP - exit + if [ "$#" -ne $NBARGS ]; then + echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" + fi + printHELP + exit fi @@ -99,7 +99,7 @@ SF="milkCLIstartup.${pname}" echo "" > $SF for streamname in "${array[@]}" do - echo "readshmim ${streamname}" >> $SF + echo "readshmim ${streamname}" >> $SF echo "rmshmim ${streamname}" >> $SF done echo "exitCLI" >> $SF @@ -107,5 +107,3 @@ echo "exitCLI" >> $SF milk -n ${pname} -f ${fifoname} -s ${SF} rm ${SF} - - diff --git a/src/COREMOD_memory/scripts/milk-shmimlog b/src/COREMOD_memory/scripts/milk-shmimlog index 82530d17..ae5df68a 100755 --- a/src/COREMOD_memory/scripts/milk-shmimlog +++ b/src/COREMOD_memory/scripts/milk-shmimlog @@ -12,33 +12,33 @@ pname="logshim-$1" function printHELP { -echo "------------------------------------------------------------------------" -echo "$(tput bold) $pname : Log image stream $(tput sgr0)" -echo "------------------------------------------------------------------------" -echo " Start process to log image stream to disk" -echo " " -echo " $(tput bold)USAGE:$(tput sgr0)" -echo " $0 [-h c ] " -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -echo " $(tput bold)-h$(tput sgr0) help" -echo " $(tput bold)-c$(tput sgr0) move process to CPUset" -echo "" -echo " $(tput bold)INPUT:$(tput sgr0)" -echo " Shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" -echo " Number of slices in each data cube saved" -echo " Destination directory" -echo "" -echo " $(tput bold)EXAMPLE:$(tput sgr0)" -echo " logshim ircam2 10000 /media/data/20150222/ircamlog/" -echo "" -echo "------------------------------------------------------------------------" + echo "------------------------------------------------------------------------" + echo "$(tput bold) $pname : Log image stream $(tput sgr0)" + echo "------------------------------------------------------------------------" + echo " Start process to log image stream to disk" + echo " " + echo " $(tput bold)USAGE:$(tput sgr0)" + echo " $0 [-h c ] " + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + echo " $(tput bold)-h$(tput sgr0) help" + echo " $(tput bold)-c$(tput sgr0) move process to CPUset" + echo "" + echo " $(tput bold)INPUT:$(tput sgr0)" + echo " Shared memory stream name. Actual file is $MILK_SHM_DIR/.im.shm" + echo " Number of slices in each data cube saved" + echo " Destination directory" + echo "" + echo " $(tput bold)EXAMPLE:$(tput sgr0)" + echo " logshim ircam2 10000 /media/data/20150222/ircamlog/" + echo "" + echo "------------------------------------------------------------------------" } printHELP1 () { - printf "%20s Start process to log image stream to disk\n" "$0" + printf "%20s Start process to log image stream to disk\n" "$0" } @@ -50,38 +50,38 @@ EXITSTATUS=0 function checkFile { -if [ -f $1 ] - then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" - else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" - EXITSTATUS=1 -fi + if [ -f $1 ] + then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] File $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] File $(tput bold)$1$(tput sgr0) not found" + EXITSTATUS=1 + fi } function checkDir { -if [ -d $1 ] - then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) found" - else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) not found" - EXITSTATUS=1 -fi + if [ -d $1 ] + then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Directory $(tput bold)$1$(tput sgr0) not found" + EXITSTATUS=1 + fi } function cmdexists() { - command -v "$1" >/dev/null 2>&1 + command -v "$1" >/dev/null 2>&1 } function checkCommand { -if cmdexists $1; then - echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) found" -else - echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) not installed. Aborting."; EXITSTATUS=1; -fi + if cmdexists $1; then + echo "[$(tput setaf 2)$(tput bold) OK $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) found" + else + echo "[$(tput setaf 1)$(tput bold) FAILED $(tput sgr0)] Command $(tput bold)$1$(tput sgr0) not installed. Aborting."; EXITSTATUS=1; + fi } @@ -96,15 +96,15 @@ fi # Transform long options to short ones singlelinehelp=0 for arg in "$@"; do - shift - case "$arg" in - "--help") set -- "$@" "-h" ;; - "--help1") -set -- "$@" "-h" -singlelinehelp=1; -;; - *) set -- "$@" "$arg" - esac + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--help1") + set -- "$@" "-h" + singlelinehelp=1; + ;; + *) set -- "$@" "$arg" + esac done @@ -113,23 +113,23 @@ done CPUset="NULL" while getopts :hc: FLAG; do - case $FLAG in - h) #show help - if [ "$singlelinehelp" -eq "0" ]; then - printHELP - else - printHELP1 - fi - exit - ;; - c) # CPU set - CPUset="$OPTARG" - ;; - \?) #unrecognized option - show help - echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." - printHELP - ;; - esac + case $FLAG in + h) #show help + if [ "$singlelinehelp" -eq "0" ]; then + printHELP + else + printHELP1 + fi + exit + ;; + c) # CPU set + CPUset="$OPTARG" + ;; + \?) #unrecognized option - show help + echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." + printHELP + ;; + esac done shift $((OPTIND-1)) @@ -142,11 +142,11 @@ shift $((OPTIND-1)) if [ "$1" = "help" ] || [ "$#" -ne $NBARGS ]; then -if [ "$#" -ne $NBARGS ]; then - echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" -fi -printHELP - exit + if [ "$#" -ne $NBARGS ]; then + echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" + fi + printHELP + exit fi @@ -164,12 +164,12 @@ checkCommand milk if [ $EXITSTATUS -eq 1 ]; then -echo "" -echo "$(tput setaf 1)$(tput bold) REQUIRED FILES, COMMANDS NOT FOUND: EXITING $(tput sgr0)" -echo "" -exit + echo "" + echo "$(tput setaf 1)$(tput bold) REQUIRED FILES, COMMANDS NOT FOUND: EXITING $(tput sgr0)" + echo "" + exit else -echo "" + echo "" fi diff --git a/src/COREMOD_memory/scripts/milk-shmimpoke b/src/COREMOD_memory/scripts/milk-shmimpoke index a0ee8cea..63b30a5b 100755 --- a/src/COREMOD_memory/scripts/milk-shmimpoke +++ b/src/COREMOD_memory/scripts/milk-shmimpoke @@ -71,4 +71,3 @@ shmimpoke ${streamname} listim exitCLI EOF - diff --git a/src/COREMOD_memory/scripts/milk-shmimpurge b/src/COREMOD_memory/scripts/milk-shmimpurge index 4e7cb333..1c3fd3af 100755 --- a/src/COREMOD_memory/scripts/milk-shmimpurge +++ b/src/COREMOD_memory/scripts/milk-shmimpurge @@ -10,26 +10,26 @@ echo "pname = $pname" function printHELP { -echo "------------------------------------------------------------------------" -echo "$(tput bold) $pname : purge orphan streams $(tput sgr0)" -echo "------------------------------------------------------------------------" -echo " Remove orphan shared memory image (stream) and associated files" -echo " Optional filter string to be matched can be specified" -echo " " -echo " $(tput bold)USAGE:$(tput sgr0)" -echo " $0 [-hf:]" -echo "" -echo " $(tput bold)OPTIONS:$(tput sgr0)" -echo " $(tput bold)-h$(tput sgr0) (h)elp" -echo " $(tput bold)-f$(tput sgr0) only purge streams matching (f)ilter" -echo "" -echo "------------------------------------------------------------------------" + echo "------------------------------------------------------------------------" + echo "$(tput bold) $pname : purge orphan streams $(tput sgr0)" + echo "------------------------------------------------------------------------" + echo " Remove orphan shared memory image (stream) and associated files" + echo " Optional filter string to be matched can be specified" + echo " " + echo " $(tput bold)USAGE:$(tput sgr0)" + echo " $0 [-hf:]" + echo "" + echo " $(tput bold)OPTIONS:$(tput sgr0)" + echo " $(tput bold)-h$(tput sgr0) (h)elp" + echo " $(tput bold)-f$(tput sgr0) only purge streams matching (f)ilter" + echo "" + echo "------------------------------------------------------------------------" } printHELP1 () { - printf "%20s Purge orphan streams\n" "$0" + printf "%20s Purge orphan streams\n" "$0" } @@ -40,15 +40,15 @@ printHELP1 () # Transform long options to short ones singlelinehelp=0 for arg in "$@"; do - shift - case "$arg" in - "--help") set -- "$@" "-h" ;; - "--help1") -set -- "$@" "-h" -singlelinehelp=1; -;; - *) set -- "$@" "$arg" - esac + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--help1") + set -- "$@" "-h" + singlelinehelp=1; + ;; + *) set -- "$@" "$arg" + esac done @@ -56,27 +56,27 @@ done FILTERSTRING="" while getopts :hf: FLAG; do - case $FLAG in - h) #show help - if [ "$singlelinehelp" -eq "0" ]; then - printHELP - else - printHELP1 - fi - exit - ;; - f) - FILTERSTRING="${OPTARG}" - echo "using filter ${FILTERSTRING}" - ;; - \?) - echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." - printHELP - ;; - esac + case $FLAG in + h) #show help + if [ "$singlelinehelp" -eq "0" ]; then + printHELP + else + printHELP1 + fi + exit + ;; + f) + FILTERSTRING="${OPTARG}" + echo "using filter ${FILTERSTRING}" + ;; + \?) + echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." + printHELP + ;; + esac done -shift $((OPTIND-1)) +shift $((OPTIND-1)) ### End getopts code ### @@ -86,11 +86,11 @@ shift $((OPTIND-1)) if [ "$1" = "help" ] || [ "$#" -ne $NBARGS ]; then -if [ "$#" -ne $NBARGS ]; then - echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" -fi -printHELP - exit + if [ "$#" -ne $NBARGS ]; then + echo "$(tput setaf 1)$(tput bold) Illegal number of parameters ($NBARGS params required, $# entered) $(tput sgr0)" + fi + printHELP + exit fi @@ -99,6 +99,3 @@ milk -n ${pname} << EOF shmimpurge "${FILTERSTRING}" exitCLI EOF - - - diff --git a/src/COREMOD_memory/shmim_purge.c b/src/COREMOD_memory/shmim_purge.c index c663ee3d..a3f48d58 100644 --- a/src/COREMOD_memory/shmim_purge.c +++ b/src/COREMOD_memory/shmim_purge.c @@ -3,56 +3,31 @@ * @brief purge shared memory stream */ +#include // open +#include // mmap #include -#include // open #include // close -#include // mmap #include "CommandLineInterface/CLIcore.h" #include "image_ID.h" #include "read_shmim.h" - // Local variables pointers static char *stringfilter; +static CLICMDARGDEF farg[] = { + {CLIARG_STR, ".strfilter", "string filter", "im", CLIARG_VISIBLE_DEFAULT, (void **)&stringfilter, NULL}}; -static CLICMDARGDEF farg[] = -{ - { - CLIARG_STR, ".strfilter", "string filter", "im", - CLIARG_VISIBLE_DEFAULT, - (void **) &stringfilter, NULL - } -}; - - -static CLICMDDATA CLIcmddata = -{ - "shmimpurge", - "purge orphan streams", - CLICMD_FIELDS_DEFAULTS -}; - - +static CLICMDDATA CLIcmddata = {"shmimpurge", "purge orphan streams", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - - - - +static errno_t help_function() { return RETURN_SUCCESS; } /** @brief purge orphan share memory streams * * */ -errno_t shmim_purge( - const char *strfilter -) +errno_t shmim_purge(const char *strfilter) { //printf("PURGING ORPHAN STREAMS (matching %s)\n", strfilter); @@ -60,30 +35,29 @@ errno_t shmim_purge( STREAMINFO *streaminfo; DEBUG_TRACEPOINT("Searching for streams"); - streaminfo = (STREAMINFO *) malloc(sizeof(STREAMINFO) * NBstreamMAX); + streaminfo = (STREAMINFO *)malloc(sizeof(STREAMINFO) * NBstreamMAX); int NBstream = find_streams(streaminfo, 1, strfilter); printf("%d stream(s) found\n", NBstream); DEBUG_TRACEPOINT("scanning %d streams for purging", NBstream); - for(int sindex = 0; sindex < NBstream; sindex++) + for (int sindex = 0; sindex < NBstream; sindex++) { printf(" STREAM %3d %s\n", sindex, streaminfo[sindex].sname); imageID ID = image_ID(streaminfo[sindex].sname); - if(ID == -1) + if (ID == -1) { ID = read_sharedmem_image(streaminfo[sindex].sname); } - DEBUG_TRACEPOINT("stream %s loaded ID %ld", streaminfo[sindex].sname, - (long) ID); + DEBUG_TRACEPOINT("stream %s loaded ID %ld", streaminfo[sindex].sname, (long)ID); pid_t opid; // owner PID opid = data.image[ID].md[0].ownerPID; - DEBUG_TRACEPOINT("owner PID : %ld", (long) opid); - printf("owner PID : %ld\n", (long) opid); + DEBUG_TRACEPOINT("owner PID : %ld", (long)opid); + printf("owner PID : %ld\n", (long)opid); - if(opid != 0) + if (opid != 0) { - if(getpgid(opid) >= 0) + if (getpgid(opid) >= 0) { printf("Keeping stream %s\n", streaminfo[sindex].sname); } @@ -106,8 +80,6 @@ errno_t shmim_purge( return RETURN_SUCCESS; } - - // adding INSERT_STD_PROCINFO statements enables processinfo support static errno_t compute_function() { @@ -121,12 +93,11 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - INSERT_STD_FPSCLIfunctions -// Register function in CLI -errno_t CLIADDCMD_COREMOD_memory__shmim_purge() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_memory__shmim_purge() { INSERT_STD_CLIREGISTERFUNC diff --git a/src/COREMOD_memory/shmim_purge.h b/src/COREMOD_memory/shmim_purge.h index bb1ad647..27985c93 100644 --- a/src/COREMOD_memory/shmim_purge.h +++ b/src/COREMOD_memory/shmim_purge.h @@ -1,12 +1,8 @@ #ifndef COREMOD_MEMORY_SHMIM_PURGE_H #define COREMOD_MEMORY_SHMIM_PURGE_H - errno_t CLIADDCMD_COREMOD_memory__shmim_purge(); - -errno_t shmim_purge( - const char *strfilter -); +errno_t shmim_purge(const char *strfilter); #endif diff --git a/src/COREMOD_memory/shmim_setowner.c b/src/COREMOD_memory/shmim_setowner.c index 171e2945..0e9822df 100644 --- a/src/COREMOD_memory/shmim_setowner.c +++ b/src/COREMOD_memory/shmim_setowner.c @@ -3,47 +3,29 @@ * @brief set stream owner PID */ - #include "CommandLineInterface/CLIcore.h" #include "image_ID.h" - - - - - // ========================================== // forward declaration // ========================================== -imageID shmim_setowner_creator( - const char *name -); +imageID shmim_setowner_creator(const char *name); +imageID shmim_setowner_current(const char *name); -imageID shmim_setowner_current( - const char *name -); - -imageID shmim_setowner_init( - const char *name -); - +imageID shmim_setowner_init(const char *name); // ========================================== // command line interface wrapper functions // ========================================== - static errno_t shmim_setowner_creator__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) == 0) { - shmim_setowner_creator( - data.cmdargtoken[1].val.string); + shmim_setowner_creator(data.cmdargtoken[1].val.string); return CLICMD_SUCCESS; } @@ -55,13 +37,10 @@ static errno_t shmim_setowner_creator__cli() static errno_t shmim_setowner_current__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) == 0) { - shmim_setowner_current( - data.cmdargtoken[1].val.string); + shmim_setowner_current(data.cmdargtoken[1].val.string); return CLICMD_SUCCESS; } @@ -71,16 +50,12 @@ static errno_t shmim_setowner_current__cli() } } - static errno_t shmim_setowner_init__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) == 0) { - shmim_setowner_init( - data.cmdargtoken[1].val.string); + shmim_setowner_init(data.cmdargtoken[1].val.string); return CLICMD_SUCCESS; } @@ -90,14 +65,6 @@ static errno_t shmim_setowner_init__cli() } } - - - - - - - - // ========================================== // Register CLI command(s) // ========================================== @@ -105,97 +72,59 @@ static errno_t shmim_setowner_init__cli() errno_t shmim_setowner_addCLIcmd() { - RegisterCLIcommand( - "shmimsetowncreator", - __FILE__, - shmim_setowner_creator__cli, - "set owner to creator PID", - "", - "shmimsetowncreator im3", - "imageID shmim_setowner_creator(const char *name)" - ); - - RegisterCLIcommand( - "shmimsetowncurrent", - __FILE__, - shmim_setowner_current__cli, - "set owner to current PID", - "", - "shmimsetowncurrent im3", - "imageID shmim_setowner_current(const char *name)" - ); - - RegisterCLIcommand( - "shmimsetowninit", - __FILE__, - shmim_setowner_init__cli, - "set owner to init PID", - "", - "shmimsetowninit im3", - "imageID shmim_setowner_init(const char *name)" - ); + RegisterCLIcommand("shmimsetowncreator", __FILE__, shmim_setowner_creator__cli, "set owner to creator PID", + "", "shmimsetowncreator im3", "imageID shmim_setowner_creator(const char *name)"); + + RegisterCLIcommand("shmimsetowncurrent", __FILE__, shmim_setowner_current__cli, "set owner to current PID", + "", "shmimsetowncurrent im3", "imageID shmim_setowner_current(const char *name)"); + RegisterCLIcommand("shmimsetowninit", __FILE__, shmim_setowner_init__cli, "set owner to init PID", "", + "shmimsetowninit im3", "imageID shmim_setowner_init(const char *name)"); return RETURN_SUCCESS; } - - - - - - /** @brief set owner to creator */ -imageID shmim_setowner_creator( - const char *name -) +imageID shmim_setowner_creator(const char *name) { - imageID ID; - - ID = image_ID(name); - if(ID != -1) - { + imageID ID; + + ID = image_ID(name); + if (ID != -1) + { data.image[ID].md[0].ownerPID = data.image[ID].md[0].creatorPID; - } - + } + return ID; } - - /** @brief set owner to current PID */ -imageID shmim_setowner_current( - const char *name -) +imageID shmim_setowner_current(const char *name) { - imageID ID; - - ID = image_ID(name); - if(ID != -1) - { + imageID ID; + + ID = image_ID(name); + if (ID != -1) + { data.image[ID].md[0].ownerPID = getpid(); - } - + } + return ID; } - - -/** @brief set owner to init process - * +/** @brief set owner to init process + * * This makes the stream immune to orphan purging */ -imageID shmim_setowner_init( - const char *name -) +imageID shmim_setowner_init(const char *name) { - imageID ID; - - ID = image_ID(name); - if(ID != -1) - { + imageID ID; + + ID = image_ID(name); + if (ID != -1) + { data.image[ID].md[0].ownerPID = 1; - } - + } + return ID; } diff --git a/src/COREMOD_memory/shmim_setowner.h b/src/COREMOD_memory/shmim_setowner.h index 679f9ba4..add5703f 100644 --- a/src/COREMOD_memory/shmim_setowner.h +++ b/src/COREMOD_memory/shmim_setowner.h @@ -2,18 +2,10 @@ * @file shmim_setowner.h */ -imageID shmim_setowner_creator( - const char *name -); +imageID shmim_setowner_creator(const char *name); +imageID shmim_setowner_current(const char *name); -imageID shmim_setowner_current( - const char *name -); - -imageID shmim_setowner_init( - const char *name -); - +imageID shmim_setowner_init(const char *name); errno_t shmim_setowner_addCLIcmd(); diff --git a/src/COREMOD_memory/shmimlog.c b/src/COREMOD_memory/shmimlog.c index b7a7d2cf..7011da66 100644 --- a/src/COREMOD_memory/shmimlog.c +++ b/src/COREMOD_memory/shmimlog.c @@ -1,73 +1,36 @@ #define _GNU_SOURCE #include -#include #include -#include +#include #include +#include #include "CommandLineInterface/CLIcore.h" -#include "shmimlog_types.h" #include "CommandLineInterface/timeutils.h" +#include "shmimlog_types.h" - - -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) - - +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) // Local variables pointers static char *instreamname; static char *logdir; static long *logcubesize; - - - - // List of arguments to function -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".in_sname", "input stream name", "im1", - CLIARG_VISIBLE_DEFAULT, - (void **) &instreamname, NULL - }, - { - CLIARG_LONG, ".cubesize", "cube size", "10000", - CLIARG_VISIBLE_DEFAULT, - (void **) &logcubesize, NULL - }, - { - CLIARG_STR, ".logdir", "log directory", "/media/data", - CLIARG_VISIBLE_DEFAULT, - (void **) &logdir, NULL - } -}; - +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".in_sname", "input stream name", "im1", CLIARG_VISIBLE_DEFAULT, (void **)&instreamname, NULL}, + {CLIARG_LONG, ".cubesize", "cube size", "10000", CLIARG_VISIBLE_DEFAULT, (void **)&logcubesize, NULL}, + {CLIARG_STR, ".logdir", "log directory", "/media/data", CLIARG_VISIBLE_DEFAULT, (void **)&logdir, NULL}}; // flag CLICMDFLAG_FPS enabled FPS capability -static CLICMDDATA CLIcmddata = -{ - "shmimlog", - "log shared memory stream", - CLICMD_FIELDS_DEFAULTS -}; - - - - +static CLICMDDATA CLIcmddata = {"shmimlog", "log shared memory stream", CLICMD_FIELDS_DEFAULTS}; // Forward declarations -static errno_t __attribute__((hot)) shmimlog2D( - const char *IDname, - uint32_t zsize, - const char *logdir, - const char *IDlogdata_name -); - +static errno_t __attribute__((hot)) +shmimlog2D(const char *IDname, uint32_t zsize, const char *logdir, const char *IDlogdata_name); // adding INSERT_STD_PROCINFO statements enable processinfo support static errno_t compute_function() @@ -79,37 +42,27 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - INSERT_STD_CLIfunction -// Register function in CLI -errno_t CLIADDCMD_COREMOD_memory__shmimlog() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_memory__shmimlog() { INSERT_STD_CLIREGISTERFUNC return RETURN_SUCCESS; } - - - - - - - /** @brief creates logshimconf shared memory and loads it * */ -static LOGSHIM_CONF *shmimlog_create_SHMconf( - const char *logshimname -) +static LOGSHIM_CONF *shmimlog_create_SHMconf(const char *logshimname) { - int SM_fd; - size_t sharedsize = 0; // shared memory size in bytes - char SM_fname[STRINGMAXLEN_FILENAME]; - int result; - LOGSHIM_CONF *map; + int SM_fd; + size_t sharedsize = 0; // shared memory size in bytes + char SM_fname[STRINGMAXLEN_FILENAME]; + int result; + LOGSHIM_CONF *map; sharedsize = sizeof(LOGSHIM_CONF); @@ -117,7 +70,7 @@ static LOGSHIM_CONF *shmimlog_create_SHMconf( umask(0); SM_fd = open(SM_fname, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0666); - if(SM_fd == -1) + if (SM_fd == -1) { printf("File \"%s\"\n", SM_fname); fflush(stdout); @@ -126,7 +79,7 @@ static LOGSHIM_CONF *shmimlog_create_SHMconf( } result = lseek(SM_fd, sharedsize - 1, SEEK_SET); - if(result == -1) + if (result == -1) { close(SM_fd); PRINT_ERROR("Error calling lseek() to 'stretch' the file"); @@ -134,16 +87,15 @@ static LOGSHIM_CONF *shmimlog_create_SHMconf( } result = write(SM_fd, "", 1); - if(result != 1) + if (result != 1) { close(SM_fd); perror("Error writing last byte of the file"); exit(0); } - map = (LOGSHIM_CONF *) mmap(0, sharedsize, PROT_READ | PROT_WRITE, MAP_SHARED, - SM_fd, 0); - if(map == MAP_FAILED) + map = (LOGSHIM_CONF *)mmap(0, sharedsize, PROT_READ | PROT_WRITE, MAP_SHARED, SM_fd, 0); + if (map == MAP_FAILED) { close(SM_fd); perror("Error mmapping the file"); @@ -160,10 +112,6 @@ static LOGSHIM_CONF *shmimlog_create_SHMconf( return map; } - - - - /** @brief Logs a shared memory stream onto disk * * uses semlog semaphore @@ -171,71 +119,64 @@ static LOGSHIM_CONF *shmimlog_create_SHMconf( * uses data cube buffer to store frames * if an image name logdata exists (should ideally be in shared mem), then this will be included in the timing txt file */ -static errno_t __attribute__((hot)) shmimlog2D( - const char *IDname, - uint32_t zsize, - const char *logdir, - const char *IDlogdata_name -) +static errno_t __attribute__((hot)) +shmimlog2D(const char *IDname, uint32_t zsize, const char *logdir, const char *IDlogdata_name) { // WAIT time. If no new frame during this time, save existing cube - int WaitSec = 5; - - imageID ID; - uint32_t xsize; - uint32_t ysize; - imageID IDb; - imageID IDb0; - imageID IDb1; - long index = 0; - unsigned long long cnt = 0; - int buffer; - uint8_t datatype; - uint32_t *imsizearray; - char fname[200]; - char iname[200]; - - time_t t; -// struct tm *uttime; - struct tm *uttimeStart; + int WaitSec = 5; + + imageID ID; + uint32_t xsize; + uint32_t ysize; + imageID IDb; + imageID IDb0; + imageID IDb1; + long index = 0; + unsigned long long cnt = 0; + int buffer; + uint8_t datatype; + uint32_t *imsizearray; + char fname[200]; + char iname[200]; + + time_t t; + // struct tm *uttime; + struct tm *uttimeStart; struct timespec ts; struct timespec timenow; struct timespec timenowStart; -// long kw; - int ret; - imageID IDlogdata; + // long kw; + int ret; + imageID IDlogdata; char *ptr0_0; // source image data char *ptr1_0; // destination image data - char *ptr0; // source image data, after offset - char *ptr1; // destination image data, after offset + char *ptr0; // source image data, after offset + char *ptr1; // destination image data, after offset long framesize; // in bytes - -// FILE *fp; + // FILE *fp; char fnameascii[200]; - pthread_t thread_savefits; - int tOK = 0; - int iret_savefits; + pthread_t thread_savefits; + int tOK = 0; + int iret_savefits; STREAMSAVE_THREAD_MESSAGE *tmsg = malloc(sizeof(STREAMSAVE_THREAD_MESSAGE)); - long NBfiles = -1; // run forever long long cntwait; - long waitdelayus = 50; // max speed = 20 kHz + long waitdelayus = 50; // max speed = 20 kHz long long cntwaitlim = 10000; // 5 sec int wOK; int noframe; - char logb0name[STRINGMAXLEN_STREAMNAME]; char logb1name[STRINGMAXLEN_STREAMNAME]; int is3Dcube = 0; // this is a rolling buffer -// int exitflag = 0; // toggles to 1 when loop must exit + // int exitflag = 0; // toggles to 1 when loop must exit LOGSHIM_CONF *logshimconf; @@ -255,7 +196,6 @@ static errno_t __attribute__((hot)) shmimlog2D( int use_semlog; int semval; - int VERBOSE = 0; // 0: don't print // 1: print statements outside fast loop @@ -264,34 +204,28 @@ static errno_t __attribute__((hot)) shmimlog2D( // convert wait time into number of couunter steps (counter mode only) cntwaitlim = (long)(WaitSec * 1000000 / waitdelayus); - - schedpar.sched_priority = RT_priority; - if(seteuid(data.euid) != 0) //This goes up to maximum privileges + if (seteuid(data.euid) != 0) //This goes up to maximum privileges { PRINT_ERROR("seteuid error"); } sched_setscheduler(0, SCHED_FIFO, &schedpar); //other option is SCHED_RR, might be faster - if(seteuid(data.ruid) != 0) //Go back to normal privileges + if (seteuid(data.ruid) != 0) //Go back to normal privileges { PRINT_ERROR("seteuid error"); } - - - IDlogdata = image_ID(IDlogdata_name); - if(IDlogdata != -1) + if (IDlogdata != -1) { - if(data.image[IDlogdata].md[0].datatype != _DATATYPE_FLOAT) + if (data.image[IDlogdata].md[0].datatype != _DATATYPE_FLOAT) { IDlogdata = -1; } } printf("log data name = %s\n", IDlogdata_name); - logshimconf = shmimlog_create_SHMconf(IDname); logshimconf[0].on = 1; logshimconf[0].cnt = 0; @@ -299,11 +233,7 @@ static errno_t __attribute__((hot)) shmimlog2D( logshimconf[0].logexit = 0; logshimconf[0].interval = 1; - - - imsizearray = (uint32_t *) malloc(sizeof(uint32_t) * 3); - - + imsizearray = (uint32_t *)malloc(sizeof(uint32_t) * 3); read_sharedmem_image(IDname); ID = image_ID(IDname); @@ -311,12 +241,11 @@ static errno_t __attribute__((hot)) shmimlog2D( xsize = data.image[ID].md[0].size[0]; ysize = data.image[ID].md[0].size[1]; - if(data.image[ID].md[0].naxis == 3) + if (data.image[ID].md[0].naxis == 3) { is3Dcube = 1; } - /** create the 2 buffers */ imsizearray[0] = xsize; @@ -331,72 +260,66 @@ static errno_t __attribute__((hot)) shmimlog2D( COREMOD_MEMORY_image_set_semflush(logb0name, -1); COREMOD_MEMORY_image_set_semflush(logb1name, -1); + array_time = (double *)malloc(sizeof(double) * zsize); + array_cnt0 = (uint64_t *)malloc(sizeof(uint64_t) * zsize); + array_cnt1 = (uint64_t *)malloc(sizeof(uint64_t) * zsize); - array_time = (double *) malloc(sizeof(double) * zsize); - array_cnt0 = (uint64_t *) malloc(sizeof(uint64_t) * zsize); - array_cnt1 = (uint64_t *) malloc(sizeof(uint64_t) * zsize); - - array_time_cp = (double *) malloc(sizeof(double) * zsize); - array_cnt0_cp = (uint64_t *) malloc(sizeof(uint64_t) * zsize); - array_cnt1_cp = (uint64_t *) malloc(sizeof(uint64_t) * zsize); - + array_time_cp = (double *)malloc(sizeof(double) * zsize); + array_cnt0_cp = (uint64_t *)malloc(sizeof(uint64_t) * zsize); + array_cnt1_cp = (uint64_t *)malloc(sizeof(uint64_t) * zsize); IDb = IDb0; - switch(datatype) + switch (datatype) { - case _DATATYPE_FLOAT: - framesize = SIZEOF_DATATYPE_FLOAT * xsize * ysize; - break; + case _DATATYPE_FLOAT: + framesize = SIZEOF_DATATYPE_FLOAT * xsize * ysize; + break; - case _DATATYPE_INT8: - framesize = SIZEOF_DATATYPE_INT8 * xsize * ysize; - break; + case _DATATYPE_INT8: + framesize = SIZEOF_DATATYPE_INT8 * xsize * ysize; + break; - case _DATATYPE_UINT8: - framesize = SIZEOF_DATATYPE_UINT8 * xsize * ysize; - break; + case _DATATYPE_UINT8: + framesize = SIZEOF_DATATYPE_UINT8 * xsize * ysize; + break; - case _DATATYPE_INT16: - framesize = SIZEOF_DATATYPE_INT16 * xsize * ysize; - break; + case _DATATYPE_INT16: + framesize = SIZEOF_DATATYPE_INT16 * xsize * ysize; + break; - case _DATATYPE_UINT16: - framesize = SIZEOF_DATATYPE_UINT16 * xsize * ysize; - break; + case _DATATYPE_UINT16: + framesize = SIZEOF_DATATYPE_UINT16 * xsize * ysize; + break; - case _DATATYPE_INT32: - framesize = SIZEOF_DATATYPE_INT32 * xsize * ysize; - break; + case _DATATYPE_INT32: + framesize = SIZEOF_DATATYPE_INT32 * xsize * ysize; + break; - case _DATATYPE_UINT32: - framesize = SIZEOF_DATATYPE_UINT32 * xsize * ysize; - break; + case _DATATYPE_UINT32: + framesize = SIZEOF_DATATYPE_UINT32 * xsize * ysize; + break; - case _DATATYPE_INT64: - framesize = SIZEOF_DATATYPE_INT64 * xsize * ysize; - break; + case _DATATYPE_INT64: + framesize = SIZEOF_DATATYPE_INT64 * xsize * ysize; + break; - case _DATATYPE_UINT64: - framesize = SIZEOF_DATATYPE_UINT64 * xsize * ysize; - break; + case _DATATYPE_UINT64: + framesize = SIZEOF_DATATYPE_UINT64 * xsize * ysize; + break; + case _DATATYPE_DOUBLE: + framesize = SIZEOF_DATATYPE_DOUBLE * xsize * ysize; + break; - case _DATATYPE_DOUBLE: - framesize = SIZEOF_DATATYPE_DOUBLE * xsize * ysize; - break; - - default: - printf("ERROR: WRONG DATA TYPE\n"); - exit(0); - break; + default: + printf("ERROR: WRONG DATA TYPE\n"); + exit(0); + break; } - ptr0_0 = (char *) data.image[ID].array.raw; - ptr1_0 = (char *) data.image[IDb].array.raw; - - - + ptr0_0 = (char *)data.image[ID].array.raw; + ptr1_0 = (char *)data.image[IDb].array.raw; cnt = data.image[ID].md[0].cnt0 - 1; @@ -408,43 +331,38 @@ static errno_t __attribute__((hot)) shmimlog2D( // exitflag = 0; - // initialize circuler buffer vars logshimconf->CBsize = data.image[ID].md->CBsize; logshimconf->CBindex = data.image[ID].md->CBindex; logshimconf->CBcycle = data.image[ID].md->CBcycle; - // using semlog ? use_semlog = 0; - if(data.image[ID].semlog != NULL) + if (data.image[ID].semlog != NULL) { use_semlog = 1; sem_getvalue(data.image[ID].semlog, &semval); // bring semaphore value to 1 to only save 1 frame - while(semval > 1) + while (semval > 1) { sem_wait(data.image[ID].semlog); sem_getvalue(data.image[ID].semlog, &semval); } - if(semval == 0) + if (semval == 0) { sem_post(data.image[ID].semlog); } } - DEBUG_TRACEPOINT(" "); - - int SkipWait = 0; // wait for update - while((logshimconf[0].filecnt != NBfiles) && (logshimconf[0].logexit == 0)) + while ((logshimconf[0].filecnt != NBfiles) && (logshimconf[0].logexit == 0)) { int timeout; // 1 if timeout has occurred - if(logshimconf[0].filecnt == 3) + if (logshimconf[0].filecnt == 3) { //test logshimconf[0].on = 0; @@ -454,16 +372,15 @@ static errno_t __attribute__((hot)) shmimlog2D( noframe = 0; wOK = 1; - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d Entering wait loop index = %ld %d\n", __LINE__, index, noframe); } timeout = 0; - // Keep CPU load light when not logging - if(logshimconf[0].on == 0) + if (logshimconf[0].on == 0) { float tdelay_us = 100.0; // 10 kHz struct timespec tdel; @@ -473,13 +390,11 @@ static errno_t __attribute__((hot)) shmimlog2D( nanosleep(&tdel, NULL); } - - - if(SkipWait == 1) + if (SkipWait == 1) { - if(VERBOSE > 0) + if (VERBOSE > 0) { - if(logshimconf[0].on == 1) + if (logshimconf[0].on == 1) { printf(">>>>>>> SKIPPING WAIT >>>>>>>>\n"); } @@ -487,14 +402,14 @@ static errno_t __attribute__((hot)) shmimlog2D( } else { - if(likely(use_semlog == 1)) + if (likely(use_semlog == 1)) { - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d Waiting for semaphore\n", __LINE__); } - if(clock_gettime(CLOCK_REALTIME, &ts) == -1) + if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { perror("clock_gettime"); exit(EXIT_FAILURE); @@ -502,16 +417,14 @@ static errno_t __attribute__((hot)) shmimlog2D( ts.tv_sec += WaitSec; ret = sem_timedwait(data.image[ID].semlog, &ts); - if(ret == -1) + if (ret == -1) { - if(errno == ETIMEDOUT) + if (errno == ETIMEDOUT) { - printf("%5d sem_timedwait() timed out (%d sec) -[index %ld]\n", __LINE__, - WaitSec, index); - if(VERBOSE > 0) + printf("%5d sem_timedwait() timed out (%d sec) -[index %ld]\n", __LINE__, WaitSec, index); + if (VERBOSE > 0) { - printf("%5d sem time elapsed -> Save current cube [index %ld]\n", __LINE__, - index); + printf("%5d sem time elapsed -> Save current cube [index %ld]\n", __LINE__, index); } strcpy(tmsg->iname, iname); @@ -519,9 +432,9 @@ static errno_t __attribute__((hot)) shmimlog2D( tmsg->partial = 1; // partial cube tmsg->cubesize = index; - memcpy(array_time_cp, array_time, sizeof(double)*index); - memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t)*index); - memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t)*index); + memcpy(array_time_cp, array_time, sizeof(double) * index); + memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t) * index); + memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t) * index); tmsg->arrayindex = array_cnt0_cp; tmsg->arraycnt0 = array_cnt0_cp; @@ -530,28 +443,28 @@ static errno_t __attribute__((hot)) shmimlog2D( timeout = 1; } - if(errno == EINTR) + if (errno == EINTR) { printf("%5d sem_timedwait [index %ld]: The call was interrupted by a signal handler\n", __LINE__, index); } - if(errno == EINVAL) + if (errno == EINVAL) { - printf("%5d sem_timedwait [index %ld]: Not a valid semaphore\n", __LINE__, - index); - printf(" The value of abs_timeout.tv_nsecs is less than 0, or greater than or equal to 1000 million\n"); + printf("%5d sem_timedwait [index %ld]: Not a valid semaphore\n", __LINE__, index); + printf(" The value of abs_timeout.tv_nsecs is less than 0, or greater than or " + "equal to 1000 million\n"); } - if(errno == EAGAIN) + if (errno == EAGAIN) { - printf("%5d sem_timedwait [index %ld]: The operation could not be performed without blocking (i.e., the semaphore currently has the value zero)\n", + printf("%5d sem_timedwait [index %ld]: The operation could not be performed without blocking " + "(i.e., the semaphore currently has the value zero)\n", __LINE__, index); } - wOK = 0; - if(index == 0) + if (index == 0) { noframe = 1; } @@ -560,19 +473,17 @@ static errno_t __attribute__((hot)) shmimlog2D( noframe = 0; } } - } else { - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d Not using semaphore, watching counter\n", __LINE__); } - while(((cnt == data.image[ID].md[0].cnt0) || (logshimconf[0].on == 0)) - && (wOK == 1)) + while (((cnt == data.image[ID].md[0].cnt0) || (logshimconf[0].on == 0)) && (wOK == 1)) { - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d waiting time step\n", __LINE__); } @@ -580,28 +491,27 @@ static errno_t __attribute__((hot)) shmimlog2D( usleep(waitdelayus); cntwait++; - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d cntwait = %lld\n", __LINE__, cntwait); fflush(stdout); } - if(cntwait > cntwaitlim) // save current cube + if (cntwait > cntwaitlim) // save current cube { - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d cnt time elapsed -> Save current cube\n", __LINE__); } - strcpy(tmsg->iname, iname); strcpy(tmsg->fname, fname); tmsg->partial = 1; // partial cube tmsg->cubesize = index; - memcpy(array_time_cp, array_time, sizeof(double)*index); - memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t)*index); - memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t)*index); + memcpy(array_time_cp, array_time, sizeof(double) * index); + memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t) * index); + memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t) * index); tmsg->arrayindex = array_cnt0_cp; tmsg->arraycnt0 = array_cnt0_cp; @@ -609,7 +519,7 @@ static errno_t __attribute__((hot)) shmimlog2D( tmsg->arraytime = array_time_cp; wOK = 0; - if(index == 0) + if (index == 0) { noframe = 1; } @@ -624,10 +534,9 @@ static errno_t __attribute__((hot)) shmimlog2D( DEBUG_TRACEPOINT(" "); - - if(index == 0) + if (index == 0) { - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d Setting cube start time [index %ld]\n", __LINE__, index); } @@ -641,19 +550,18 @@ static errno_t __attribute__((hot)) shmimlog2D( // sprintf(fnameascii,"%s/%s_%02d:%02d:%02ld.%09ld.txt", logdir, IDname, uttime->tm_hour, uttime->tm_min, timenow.tv_sec % 60, timenow.tv_nsec); } - - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d logshimconf[0].on = %d\n", __LINE__, logshimconf[0].on); } DEBUG_TRACEPOINT(" "); - if(likely(logshimconf[0].on == 1)) + if (likely(logshimconf[0].on == 1)) { - if(likely(wOK == 1)) // normal step: a frame has arrived + if (likely(wOK == 1)) // normal step: a frame has arrived { - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d Frame has arrived [index %ld]\n", __LINE__, index); } @@ -672,67 +580,54 @@ static errno_t __attribute__((hot)) shmimlog2D( long grabStart1 = 0; long grabEnd1 = 0; - if(data.image[ID].md->CBsize > 0) + if (data.image[ID].md->CBsize > 0) { - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("\n"); - printf(" LAST SAVED [%8ld %3ld]\n", - logshimconf->CBcycle, - (long) logshimconf->CBindex - ); + printf(" LAST SAVED [%8ld %3ld]\n", logshimconf->CBcycle, + (long)logshimconf->CBindex); } long currentCBcycle = data.image[ID].md->CBcycle; long currentCBindex = data.image[ID].md->CBindex; - if(VERBOSE > 0) + if (VERBOSE > 0) { - printf(" LAST WRITTEN IN CB [%8ld %3ld]\n", - (long) currentCBcycle, - (long) currentCBindex - ); + printf(" LAST WRITTEN IN CB [%8ld %3ld]\n", (long)currentCBcycle, (long)currentCBindex); } - long CBcyclediff = (long) currentCBcycle - - (long) logshimconf->CBcycle; - - long CBindexdiff = (long) currentCBindex - - (long) logshimconf->CBindex; + long CBcyclediff = (long)currentCBcycle - (long)logshimconf->CBcycle; + long CBindexdiff = (long)currentCBindex - (long)logshimconf->CBindex; // number of frames behind - long NBframesbehind = - (long)(CBcyclediff * (long) data.image[ID].md->CBsize - + CBindexdiff); + long NBframesbehind = (long)(CBcyclediff * (long)data.image[ID].md->CBsize + CBindexdiff); - if(VERBOSE > 0) + if (VERBOSE > 0) { - printf(" DIFF [%8ld %3ld] %8ld frames\n", - CBcyclediff, - CBindexdiff, - NBframesbehind - ); + printf(" DIFF [%8ld %3ld] %8ld frames\n", CBcyclediff, CBindexdiff, + NBframesbehind); } long NBgrabmax = 20; NBgrab = NBframesbehind; - if(NBgrab > NBgrabmax) + if (NBgrab > NBgrabmax) { NBgrab = NBgrabmax; } // avoid crossing big cube boundary - long grabmax_logbuff = zsize - index; + long grabmax_logbuff = zsize - index; - if(VERBOSE > 0) + if (VERBOSE > 0) { printf(" -> GRABBING %4ld frames (max %6ld) -> ", NBgrab, grabmax_logbuff); } - if(NBgrab > grabmax_logbuff) + if (NBgrab > grabmax_logbuff) { NBgrab = grabmax_logbuff; } - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%6ld\n", NBgrab); } @@ -742,56 +637,49 @@ static errno_t __attribute__((hot)) shmimlog2D( long grabEnd = currentCBindex; grabStart0 = 0; - grabEnd0 = 0; - grabSpan0 = 0; + grabEnd0 = 0; + grabSpan0 = 0; grabStart1 = 0; - grabEnd1 = 0; - grabSpan1 = 0; - + grabEnd1 = 0; + grabSpan1 = 0; - if(grabStart < 0) + if (grabStart < 0) { grabStart0 = grabStart + data.image[ID].md->CBsize; - grabEnd0 = data.image[ID].md->CBsize - 1; - grabSpan0 = grabEnd0 - grabStart0 + 1; + grabEnd0 = data.image[ID].md->CBsize - 1; + grabSpan0 = grabEnd0 - grabStart0 + 1; grabStart1 = 0; - grabEnd1 = grabEnd; - grabSpan1 = grabEnd1 - grabStart1 + 1; + grabEnd1 = grabEnd; + grabSpan1 = grabEnd1 - grabStart1 + 1; } else { grabStart0 = grabStart; - grabEnd0 = grabEnd; - grabSpan0 = grabEnd0 - grabStart0 + 1; + grabEnd0 = grabEnd; + grabSpan0 = grabEnd0 - grabStart0 + 1; grabStart1 = 0; - grabEnd1 = 0; - grabSpan1 = 0; + grabEnd1 = 0; + grabSpan1 = 0; } - index0start = index; index0end = index0start + (grabSpan0 - 1); index1start = index0end + 1; index1end = index1start + (grabSpan1 - 1); - if(VERBOSE > 0) + if (VERBOSE > 0) { printf(" CB BUFFER RANGE %3ld -> %3ld\n", grabStart, grabEnd); - printf(" GRAB RANGE %3ld %3ld (%3ld) -> %6ld %6ld\n", - grabStart0, grabEnd0, - grabSpan0, + printf(" GRAB RANGE %3ld %3ld (%3ld) -> %6ld %6ld\n", grabStart0, grabEnd0, grabSpan0, index0start, index0end); - printf(" GRAB RANGE %3ld %3ld (%3ld) -> %6ld %6ld\n", - grabStart1, grabEnd1, - grabSpan1, + printf(" GRAB RANGE %3ld %3ld (%3ld) -> %6ld %6ld\n", grabStart1, grabEnd1, grabSpan1, index1start, index1end); } - // update last saved logshimconf->CBcycle = currentCBcycle; logshimconf->CBindex = currentCBindex; @@ -799,9 +687,7 @@ static errno_t __attribute__((hot)) shmimlog2D( // total number of frames grabbed NBgrab = grabSpan0 + grabSpan1; - - - if(NBframesbehind > 1) + if (NBframesbehind > 1) { SkipWait = 1; // don't wait, proceed to grab next frame } @@ -817,46 +703,41 @@ static errno_t __attribute__((hot)) shmimlog2D( NBgrab = 1; } - /// measure time // t = time(NULL); // uttime = gmtime(&t); clock_gettime(CLOCK_REALTIME, &timenow); - DEBUG_TRACEPOINT(" "); - - // memcpy // - if(data.image[ID].md->CBsize > 0) // circ buffer mode + if (data.image[ID].md->CBsize > 0) // circ buffer mode { - - if(grabSpan0 > 0) + if (grabSpan0 > 0) { // source - ptr0 = (char *) data.image[ID].CBimdata; + ptr0 = (char *)data.image[ID].CBimdata; ptr0 += data.image[ID].md->imdatamemsize * grabStart0; // destination ptr1 = ptr1_0 + framesize * index0start; - memcpy((void *) ptr1, (void *) ptr0, framesize * grabSpan0); + memcpy((void *)ptr1, (void *)ptr0, framesize * grabSpan0); } - if(grabSpan1 > 0) + if (grabSpan1 > 0) { // source - ptr0 = (char *) data.image[ID].CBimdata; + ptr0 = (char *)data.image[ID].CBimdata; ptr0 += data.image[ID].md->imdatamemsize * grabStart1; // destination ptr1 = ptr1_0 + framesize * index1start; - memcpy((void *) ptr1, (void *) ptr0, framesize * grabSpan1); + memcpy((void *)ptr1, (void *)ptr0, framesize * grabSpan1); } index += NBgrab; } @@ -865,7 +746,7 @@ static errno_t __attribute__((hot)) shmimlog2D( // no circular buffer // source - if(is3Dcube == 1) + if (is3Dcube == 1) { ptr0 = ptr0_0 + framesize * data.image[ID].md[0].cnt1; } @@ -877,9 +758,9 @@ static errno_t __attribute__((hot)) shmimlog2D( // destination ptr1 = ptr1_0 + framesize * index; - if(NBgrab > 0) + if (NBgrab > 0) { - memcpy((void *) ptr1, (void *) ptr0, framesize * NBgrab); + memcpy((void *)ptr1, (void *)ptr0, framesize * NBgrab); array_cnt0[index] = data.image[ID].md[0].cnt0; array_cnt1[index] = data.image[ID].md[0].cnt1; array_time[index] = timenow.tv_sec + 1.0e-9 * timenow.tv_nsec; @@ -887,10 +768,7 @@ static errno_t __attribute__((hot)) shmimlog2D( index += NBgrab; } - DEBUG_TRACEPOINT(" "); - - } } else @@ -898,39 +776,30 @@ static errno_t __attribute__((hot)) shmimlog2D( // save partial if possible //if(index>0) wOK = 0; - } - - if(VERBOSE > 1) + if (VERBOSE > 1) { printf("%5d index = %ld wOK = %d\n", __LINE__, index, wOK); } - - - - - - - // SAVE CUBE TO DISK /// cases: /// index>zsize-1 buffer full /// timeout==1 && index>0 : partial - if((index > zsize - 1) || ((timeout == 1) && (index > 0))) + if ((index > zsize - 1) || ((timeout == 1) && (index > 0))) { long NBframemissing; /// save image - if(VERBOSE > 0) + if (VERBOSE > 0) { - printf("%5d Save image [index %ld] [timeout %d] [zsize %ld]\n", __LINE__, - index, timeout, (long) zsize); + printf("%5d Save image [index %ld] [timeout %d] [zsize %ld]\n", __LINE__, index, timeout, + (long)zsize); } sprintf(iname, "%s_logbuff%d", IDname, buffer); - if(buffer == 0) + if (buffer == 0) { IDb = IDb0; } @@ -939,69 +808,58 @@ static errno_t __attribute__((hot)) shmimlog2D( IDb = IDb1; } - - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d Building file name: ascii\n", __LINE__); fflush(stdout); } - sprintf(fnameascii, "%s/%s.%04d%02d%02dT%02d%02d%02ld.%09ldZ.txt", logdir, - IDname, - 1900 + uttimeStart->tm_year, 1 + uttimeStart->tm_mon, uttimeStart->tm_mday, - uttimeStart->tm_hour, uttimeStart->tm_min, timenowStart.tv_sec % 60, - timenowStart.tv_nsec); - + sprintf(fnameascii, "%s/%s.%04d%02d%02dT%02d%02d%02ld.%09ldZ.txt", logdir, IDname, + 1900 + uttimeStart->tm_year, 1 + uttimeStart->tm_mon, uttimeStart->tm_mday, uttimeStart->tm_hour, + uttimeStart->tm_min, timenowStart.tv_sec % 60, timenowStart.tv_nsec); - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d Building file name: fits\n", __LINE__); fflush(stdout); } - sprintf(fname, "%s/%s.%04d%02d%02dT%02d%02d%02ld.%09ldZ.fits", logdir, IDname, - 1900 + uttimeStart->tm_year, 1 + uttimeStart->tm_mon, uttimeStart->tm_mday, - uttimeStart->tm_hour, uttimeStart->tm_min, timenowStart.tv_sec % 60, - timenowStart.tv_nsec); - - + sprintf(fname, "%s/%s.%04d%02d%02dT%02d%02d%02ld.%09ldZ.fits", logdir, IDname, 1900 + uttimeStart->tm_year, + 1 + uttimeStart->tm_mon, uttimeStart->tm_mday, uttimeStart->tm_hour, uttimeStart->tm_min, + timenowStart.tv_sec % 60, timenowStart.tv_nsec); strcpy(tmsg->iname, iname); strcpy(tmsg->fname, fname); strcpy(tmsg->fnameascii, fnameascii); tmsg->saveascii = 1; - - - if(wOK == 1) // full cube + if (wOK == 1) // full cube { tmsg->partial = 0; // full cube - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d SAVING FULL CUBE\n", __LINE__); fflush(stdout); } - } else // partial cube { tmsg->partial = 1; // partial cube - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d SAVING PARTIAL CUBE\n", __LINE__); fflush(stdout); } } - // fclose(fp); // Wait for save thread to complete to launch next one - if(tOK == 1) + if (tOK == 1) { - if(pthread_tryjoin_np(thread_savefits, NULL) == EBUSY) + if (pthread_tryjoin_np(thread_savefits, NULL) == EBUSY) { VERBOSE = 1; - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d PREVIOUS SAVE THREAD NOT TERMINATED -> waiting\n", __LINE__); } @@ -1015,38 +873,36 @@ static errno_t __attribute__((hot)) shmimlog2D( tdiff = timespec_diff(t0, t1); printf("WAITED %ld.%09ld sec\n", tdiff.tv_sec, tdiff.tv_nsec); - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d PREVIOUS SAVE THREAD NOW COMPLETED -> continuing\n", __LINE__); } } - else if(VERBOSE > 0) + else if (VERBOSE > 0) { printf("%5d PREVIOUS SAVE THREAD ALREADY COMPLETED -> OK\n", __LINE__); } VERBOSE = 0; } - COREMOD_MEMORY_image_set_sempost_byID(IDb, -1); data.image[IDb].md[0].cnt0++; data.image[IDb].md[0].write = 0; - tmsg->cubesize = index; strcpy(tmsg->iname, iname); - memcpy(array_time_cp, array_time, sizeof(double)*index); - memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t)*index); - memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t)*index); + memcpy(array_time_cp, array_time, sizeof(double) * index); + memcpy(array_cnt0_cp, array_cnt0, sizeof(uint64_t) * index); + memcpy(array_cnt1_cp, array_cnt1, sizeof(uint64_t) * index); NBframemissing = (array_cnt0[index - 1] - array_cnt0[0]) - (index - 1); - printf("=== %6ld %6ld %6ld %6ld ====\n", array_cnt0[0], - array_cnt0[index - 1], index, array_cnt0[index - 1] - array_cnt0[0]); - printf("===== CUBE %8lld Number of missed frames = %8ld / %ld / %8ld ====\n", - logshimconf[0].filecnt, NBframemissing, index, (long) zsize); + printf("=== %6ld %6ld %6ld %6ld ====\n", array_cnt0[0], array_cnt0[index - 1], index, + array_cnt0[index - 1] - array_cnt0[0]); + printf("===== CUBE %8lld Number of missed frames = %8ld / %ld / %8ld ====\n", logshimconf[0].filecnt, + NBframemissing, index, (long)zsize); - if(VERBOSE > 0) + if (VERBOSE > 0) { printf("%5d Starting image save thread\n", __LINE__); fflush(stdout); @@ -1056,17 +912,13 @@ static errno_t __attribute__((hot)) shmimlog2D( tmsg->arraycnt0 = array_cnt0_cp; tmsg->arraycnt1 = array_cnt1_cp; tmsg->arraytime = array_time_cp; - WRITE_FULLFILENAME(tmsg->fname_auxFITSheader, - "%s/%s.auxFITSheader.shm", - data.shmdir, - IDname); - iret_savefits = pthread_create(&thread_savefits, NULL, save_fits_function, - tmsg); + WRITE_FULLFILENAME(tmsg->fname_auxFITSheader, "%s/%s.auxFITSheader.shm", data.shmdir, IDname); + iret_savefits = pthread_create(&thread_savefits, NULL, save_fits_function, tmsg); - logshimconf[0].cnt ++; + logshimconf[0].cnt++; tOK = 1; - if(iret_savefits) + if (iret_savefits) { fprintf(stderr, "Error - pthread_create() return code: %d\n", iret_savefits); exit(EXIT_FAILURE); @@ -1074,13 +926,13 @@ static errno_t __attribute__((hot)) shmimlog2D( index = 0; buffer++; - if(buffer == 2) + if (buffer == 2) { buffer = 0; } // printf("[%ld -> %d]", cnt, buffer); // fflush(stdout); - if(buffer == 0) + if (buffer == 0) { IDb = IDb0; } @@ -1089,51 +941,51 @@ static errno_t __attribute__((hot)) shmimlog2D( IDb = IDb1; } - switch(datatype) + switch (datatype) { - case _DATATYPE_FLOAT: - ptr1_0 = (char *) data.image[IDb].array.F; - break; + case _DATATYPE_FLOAT: + ptr1_0 = (char *)data.image[IDb].array.F; + break; - case _DATATYPE_INT8: - ptr1_0 = (char *) data.image[IDb].array.SI8; - break; + case _DATATYPE_INT8: + ptr1_0 = (char *)data.image[IDb].array.SI8; + break; - case _DATATYPE_UINT8: - ptr1_0 = (char *) data.image[IDb].array.UI8; - break; + case _DATATYPE_UINT8: + ptr1_0 = (char *)data.image[IDb].array.UI8; + break; - case _DATATYPE_INT16: - ptr1_0 = (char *) data.image[IDb].array.SI16; - break; + case _DATATYPE_INT16: + ptr1_0 = (char *)data.image[IDb].array.SI16; + break; - case _DATATYPE_UINT16: - ptr1_0 = (char *) data.image[IDb].array.UI16; - break; + case _DATATYPE_UINT16: + ptr1_0 = (char *)data.image[IDb].array.UI16; + break; - case _DATATYPE_INT32: - ptr1_0 = (char *) data.image[IDb].array.SI32; - break; + case _DATATYPE_INT32: + ptr1_0 = (char *)data.image[IDb].array.SI32; + break; - case _DATATYPE_UINT32: - ptr1_0 = (char *) data.image[IDb].array.UI32; - break; + case _DATATYPE_UINT32: + ptr1_0 = (char *)data.image[IDb].array.UI32; + break; - case _DATATYPE_INT64: - ptr1_0 = (char *) data.image[IDb].array.SI64; - break; + case _DATATYPE_INT64: + ptr1_0 = (char *)data.image[IDb].array.SI64; + break; - case _DATATYPE_UINT64: - ptr1_0 = (char *) data.image[IDb].array.UI64; - break; + case _DATATYPE_UINT64: + ptr1_0 = (char *)data.image[IDb].array.UI64; + break; - case _DATATYPE_DOUBLE: - ptr1_0 = (char *) data.image[IDb].array.D; - break; + case _DATATYPE_DOUBLE: + ptr1_0 = (char *)data.image[IDb].array.D; + break; } data.image[IDb].md[0].write = 1; - logshimconf[0].filecnt ++; + logshimconf[0].filecnt++; } cnt = data.image[ID].md[0].cnt0; } @@ -1151,17 +1003,3 @@ static errno_t __attribute__((hot)) shmimlog2D( return RETURN_SUCCESS; } - - - - - - - - - - - - - - diff --git a/src/COREMOD_memory/shmimlog_types.h b/src/COREMOD_memory/shmimlog_types.h index 13492580..02cc226e 100644 --- a/src/COREMOD_memory/shmimlog_types.h +++ b/src/COREMOD_memory/shmimlog_types.h @@ -7,12 +7,11 @@ #ifndef CLICORE_MEMORY_LOGSHMIM_TYPES_H #define CLICORE_MEMORY_LOGSHMIM_TYPES_H - typedef struct { char iname[100]; char fname[200]; - int partial; // 1 if partial cube + int partial; // 1 if partial cube long cubesize; // size of the cube int saveascii; @@ -20,34 +19,30 @@ typedef struct // 1 : Saving ascii: arraycnt0, arraycnt1, arraytime // 2 : ??? - char fname_auxFITSheader[STRINGMAXLEN_FILENAME]; + char fname_auxFITSheader[STRINGMAXLEN_FILENAME]; - char fnameascii[STRINGMAXLEN_FILENAME]; // name of frame to be saved + char fnameascii[STRINGMAXLEN_FILENAME]; // name of frame to be saved uint64_t *arrayindex; uint64_t *arraycnt0; uint64_t *arraycnt1; - double *arraytime; + double *arraytime; } STREAMSAVE_THREAD_MESSAGE; - - - - typedef struct { - int on; /**< 1 if logging, 0 otherwise */ + int on; /**< 1 if logging, 0 otherwise */ long long cnt; long long filecnt; - long interval; /**< log every x frames (default = 1) */ - int logexit; /**< toggle to 1 when exiting */ - char fname[200]; + long interval; /**< log every x frames (default = 1) */ + int logexit; /**< toggle to 1 when exiting */ + char fname[200]; // circular buffer - uint32_t CBsize; + uint32_t CBsize; - uint32_t CBindex; // last frame grabbed - uint64_t CBcycle; // last frame grabbed + uint32_t CBindex; // last frame grabbed + uint64_t CBcycle; // last frame grabbed } LOGSHIM_CONF; #endif diff --git a/src/COREMOD_memory/shmimlogcmd.c b/src/COREMOD_memory/shmimlogcmd.c index c98781ee..8fc480ce 100644 --- a/src/COREMOD_memory/shmimlogcmd.c +++ b/src/COREMOD_memory/shmimlogcmd.c @@ -5,66 +5,37 @@ #include "CommandLineInterface/CLIcore.h" #include "shmimlog_types.h" - - // Local variables pointers static char *logstreamname; static char *logcmd; - - // List of arguments to function -static CLICMDARGDEF farg[] = -{ - { - CLIARG_STR, ".in_sname", "input stream name", "im1", - CLIARG_VISIBLE_DEFAULT, - (void **) &logstreamname, NULL - }, - { - CLIARG_STR, ".logcmd", "log command", "logon", - CLIARG_VISIBLE_DEFAULT, - (void **) &logcmd, NULL - } -}; - +static CLICMDARGDEF farg[] = { + {CLIARG_STR, ".in_sname", "input stream name", "im1", CLIARG_VISIBLE_DEFAULT, (void **)&logstreamname, NULL}, + {CLIARG_STR, ".logcmd", "log command", "logon", CLIARG_VISIBLE_DEFAULT, (void **)&logcmd, NULL}}; // flag CLICMDFLAG_FPS enabled FPS capability -static CLICMDDATA CLIcmddata = -{ - "shmimlogcmd", - "log shared memory stream command\n" - "logon, logoff", - CLICMD_FIELDS_NOFPS -}; - - - - - - - +static CLICMDDATA CLIcmddata = {"shmimlogcmd", + "log shared memory stream command\n" + "logon, logoff", + CLICMD_FIELDS_NOFPS}; // set the on field in logshim // IDname is name of image logged -static errno_t logshim_cmd( - const char *logshimname, - const char *cmd -) +static errno_t logshim_cmd(const char *logshimname, const char *cmd) { - LOGSHIM_CONF *map; - char SM_fname[STRINGMAXLEN_FILENAME]; - int SM_fd; - struct stat file_stat; + LOGSHIM_CONF *map; + char SM_fname[STRINGMAXLEN_FILENAME]; + int SM_fd; + struct stat file_stat; // read shared mem WRITE_FILENAME(SM_fname, "%s/%s.logshimconf.shm", data.shmdir, logshimname); - printf("Importing mmap file \"%s\"\n", SM_fname); SM_fd = open(SM_fname, O_RDWR); - if(SM_fd == -1) + if (SM_fd == -1) { printf("Cannot import file - continuing\n"); exit(0); @@ -74,31 +45,30 @@ static errno_t logshim_cmd( fstat(SM_fd, &file_stat); printf("File %s size: %zd\n", SM_fname, file_stat.st_size); - map = (LOGSHIM_CONF *) mmap(0, file_stat.st_size, PROT_READ | PROT_WRITE, - MAP_SHARED, SM_fd, 0); - if(map == MAP_FAILED) + map = (LOGSHIM_CONF *)mmap(0, file_stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, SM_fd, 0); + if (map == MAP_FAILED) { close(SM_fd); perror("Error mmapping the file"); exit(0); } - if(strcmp(cmd, "logon") == 0) + if (strcmp(cmd, "logon") == 0) { printf("Setting logging to ON\n"); map[0].on = 1; } - else if(strcmp(cmd, "logoff") == 0) + else if (strcmp(cmd, "logoff") == 0) { printf("Setting logging to OFF\n"); map[0].on = 0; } - else if(strcmp(cmd, "logexit") == 0) + else if (strcmp(cmd, "logexit") == 0) { printf("log exit\n"); map[0].logexit = 1; } - else if(strcmp(cmd, "stat") == 0) + else if (strcmp(cmd, "stat") == 0) { printf("LOG on = %d\n", map[0].on); printf(" cnt = %lld\n", map[0].cnt); @@ -107,9 +77,7 @@ static errno_t logshim_cmd( printf("logexit = %d\n", map[0].logexit); } - - - if(munmap(map, sizeof(LOGSHIM_CONF)) == -1) + if (munmap(map, sizeof(LOGSHIM_CONF)) == -1) { printf("unmapping %s\n", SM_fname); perror("Error un-mmapping the file"); @@ -119,8 +87,6 @@ static errno_t logshim_cmd( return RETURN_SUCCESS; } - - // adding INSERT_STD_PROCINFO statements enable processinfo support static errno_t compute_function() { @@ -130,19 +96,13 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - INSERT_STD_CLIfunction -// Register function in CLI -errno_t CLIADDCMD_COREMOD_memory__shmimlogcmd() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_memory__shmimlogcmd() { INSERT_STD_CLIREGISTERFUNC return RETURN_SUCCESS; } - - - - - diff --git a/src/COREMOD_memory/stream_TCP.c b/src/COREMOD_memory/stream_TCP.c index 438c93cd..f1d64718 100644 --- a/src/COREMOD_memory/stream_TCP.c +++ b/src/COREMOD_memory/stream_TCP.c @@ -3,84 +3,49 @@ * @brief TCP stream transfer */ - #include #include #include #include - #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" -#include "list_image.h" #include "create_image.h" #include "delete_image.h" +#include "image_ID.h" +#include "list_image.h" #include "read_shmim.h" #include "stream_sem.h" - // set to 1 if transfering keywords static int TCPTRANSFERKW = 1; - typedef struct { long cnt0; long cnt1; } TCP_BUFFER_METADATA; - - - - - // ========================================== // Forward declaration(s) // ========================================== +errno_t COREMOD_MEMORY_testfunction_semaphore(const char *IDname, int semtrig, int testmode); -errno_t COREMOD_MEMORY_testfunction_semaphore( - const char *IDname, - int semtrig, - int testmode -); - - -imageID COREMOD_MEMORY_image_NETWORKtransmit( - const char *IDname, - const char *IPaddr, - int port, - int mode, - int RT_priority -); - -imageID COREMOD_MEMORY_image_NETWORKreceive( - int port, - int mode, - int RT_priority -); - - +imageID COREMOD_MEMORY_image_NETWORKtransmit(const char *IDname, const char *IPaddr, int port, int mode, + int RT_priority); +imageID COREMOD_MEMORY_image_NETWORKreceive(int port, int mode, int RT_priority); // ========================================== // Command line interface wrapper function(s) // ========================================== - static errno_t COREMOD_MEMORY_testfunction_semaphore__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_LONG) - + CLI_checkarg(3, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_LONG) + CLI_checkarg(3, CLIARG_LONG) == 0) { - COREMOD_MEMORY_testfunction_semaphore( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numl, - data.cmdargtoken[3].val.numl - ); + COREMOD_MEMORY_testfunction_semaphore(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl, + data.cmdargtoken[3].val.numl); return CLICMD_SUCCESS; } else @@ -89,25 +54,15 @@ static errno_t COREMOD_MEMORY_testfunction_semaphore__cli() } } - - static errno_t COREMOD_MEMORY_image_NETWORKtransmit__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_STR_NOT_IMG) - + CLI_checkarg(3, CLIARG_LONG) - + CLI_checkarg(4, CLIARG_LONG) - + CLI_checkarg(5, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_STR_NOT_IMG) + CLI_checkarg(3, CLIARG_LONG) + + CLI_checkarg(4, CLIARG_LONG) + CLI_checkarg(5, CLIARG_LONG) == + 0) { - COREMOD_MEMORY_image_NETWORKtransmit( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.string, - data.cmdargtoken[3].val.numl, - data.cmdargtoken[4].val.numl, - data.cmdargtoken[5].val.numl - ); + COREMOD_MEMORY_image_NETWORKtransmit(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, + data.cmdargtoken[3].val.numl, data.cmdargtoken[4].val.numl, + data.cmdargtoken[5].val.numl); return CLICMD_SUCCESS; } else @@ -116,20 +71,12 @@ static errno_t COREMOD_MEMORY_image_NETWORKtransmit__cli() } } - static errno_t COREMOD_MEMORY_image_NETWORKreceive__cli() { - if(0 - + CLI_checkarg(1, CLIARG_LONG) - + CLI_checkarg(2, CLIARG_LONG) - + CLI_checkarg(3, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_LONG) + CLI_checkarg(2, CLIARG_LONG) + CLI_checkarg(3, CLIARG_LONG) == 0) { - COREMOD_MEMORY_image_NETWORKreceive( - data.cmdargtoken[1].val.numl, - data.cmdargtoken[2].val.numl, - data.cmdargtoken[3].val.numl - ); + COREMOD_MEMORY_image_NETWORKreceive(data.cmdargtoken[1].val.numl, data.cmdargtoken[2].val.numl, + data.cmdargtoken[3].val.numl); return CLICMD_SUCCESS; } else @@ -138,129 +85,91 @@ static errno_t COREMOD_MEMORY_image_NETWORKreceive__cli() } } - - - // ========================================== // Register CLI command(s) // ========================================== errno_t stream__TCP_addCLIcmd() { - RegisterCLIcommand( - "testfuncsem", - __FILE__, - COREMOD_MEMORY_testfunction_semaphore__cli, - "test semaphore loop", - " ", - "testfuncsem im1 1 0", - "int COREMOD_MEMORY_testfunction_semaphore(const char *IDname, int semtrig, int testmode)"); + RegisterCLIcommand("testfuncsem", __FILE__, COREMOD_MEMORY_testfunction_semaphore__cli, "test semaphore loop", + " ", "testfuncsem im1 1 0", + "int COREMOD_MEMORY_testfunction_semaphore(const char *IDname, int semtrig, int testmode)"); RegisterCLIcommand( - "imnetwtransmit", - __FILE__, - COREMOD_MEMORY_image_NETWORKtransmit__cli, - "transmit image over network", - " ", - "imnetwtransmit im1 127.0.0.1 0 8888 0", + "imnetwtransmit", __FILE__, COREMOD_MEMORY_image_NETWORKtransmit__cli, "transmit image over network", + " ", "imnetwtransmit im1 127.0.0.1 0 8888 0", "long COREMOD_MEMORY_image_NETWORKtransmit(const char *IDname, const char *IPaddr, int port, int mode)"); - RegisterCLIcommand( - "imnetwreceive", - __FILE__, - COREMOD_MEMORY_image_NETWORKreceive__cli, - "receive image(s) over network. mode=1 uses counter instead of semaphore", - " ", - "imnetwreceive 8887 0 80", - "long COREMOD_MEMORY_image_NETWORKreceive(int port, int mode, int RT_priority)"); - + RegisterCLIcommand("imnetwreceive", __FILE__, COREMOD_MEMORY_image_NETWORKreceive__cli, + "receive image(s) over network. mode=1 uses counter instead of semaphore", + " ", "imnetwreceive 8887 0 80", + "long COREMOD_MEMORY_image_NETWORKreceive(int port, int mode, int RT_priority)"); return RETURN_SUCCESS; } - - - - - - - - - - - - - - - - -errno_t COREMOD_MEMORY_testfunction_semaphore( - const char *IDname, - int semtrig, - int testmode -) +errno_t COREMOD_MEMORY_testfunction_semaphore(const char *IDname, int semtrig, int testmode) { imageID ID; - int semval; - int rv; - long loopcnt = 0; + int semval; + int rv; + long loopcnt = 0; ID = image_ID(IDname); char pinfomsg[200]; - // =========================== // Start loop // =========================== int loopOK = 1; - while(loopOK == 1) + while (loopOK == 1) { printf("\n"); usleep(500); sem_getvalue(data.image[ID].semptr[semtrig], &semval); - sprintf(pinfomsg, "%ld TEST 0 semtrig %d ID %ld %d", loopcnt, semtrig, ID, - semval); + sprintf(pinfomsg, "%ld TEST 0 semtrig %d ID %ld %d", loopcnt, semtrig, ID, semval); printf("MSG: %s\n", pinfomsg); fflush(stdout); - if(testmode == 0) + if (testmode == 0) { rv = sem_wait(data.image[ID].semptr[semtrig]); } - if(testmode == 1) + if (testmode == 1) { rv = sem_trywait(data.image[ID].semptr[semtrig]); } - if(testmode == 2) + if (testmode == 2) { sem_post(data.image[ID].semptr[semtrig]); rv = sem_wait(data.image[ID].semptr[semtrig]); } - if(rv == -1) + if (rv == -1) { - switch(errno) + switch (errno) { - case EINTR: - printf(" sem_wait call was interrupted by a signal handler\n"); - break; + case EINTR: + printf(" sem_wait call was interrupted by a signal handler\n"); + break; - case EINVAL: - printf(" not a valid semaphore\n"); - break; + case EINVAL: + printf(" not a valid semaphore\n"); + break; - case EAGAIN: - printf(" The operation could not be performed without blocking (i.e., the semaphore currently has the value zero)\n"); - break; + case EAGAIN: + printf(" The operation could not be performed without blocking (i.e., the semaphore currently has " + "the value zero)\n"); + break; - default: - printf(" ERROR: unknown code %d\n", rv); - break; + default: + printf(" ERROR: unknown code %d\n", rv); + break; } } else @@ -269,78 +178,59 @@ errno_t COREMOD_MEMORY_testfunction_semaphore( } sem_getvalue(data.image[ID].semptr[semtrig], &semval); - sprintf(pinfomsg, "%ld TEST 1 semtrig %d ID %ld %d", loopcnt, semtrig, ID, - semval); + sprintf(pinfomsg, "%ld TEST 1 semtrig %d ID %ld %d", loopcnt, semtrig, ID, semval); printf("MSG: %s\n", pinfomsg); fflush(stdout); - - loopcnt ++; + loopcnt++; } - return RETURN_SUCCESS; } - - - - - /** continuously transmits 2D image through TCP link * mode = 1, force counter to be used for synchronization, ignore semaphores if they exist */ - -imageID COREMOD_MEMORY_image_NETWORKtransmit( - const char *IDname, - const char *IPaddr, - int port, - int mode, - int RT_priority -) +imageID COREMOD_MEMORY_image_NETWORKtransmit(const char *IDname, const char *IPaddr, int port, int mode, + int RT_priority) { - imageID ID; - struct sockaddr_in sock_server; - int fds_client; - int flag = 1; - int result; - unsigned long long cnt = 0; - long long iter = 0; - long framesize; // pixel data only - uint32_t xsize, ysize; - char *ptr0; // source - char *ptr1; // source - offset by slice - int rs; - - - struct timespec ts; - long scnt; - int semval; - int semr; - int slice, oldslice; - int NBslices; + imageID ID; + struct sockaddr_in sock_server; + int fds_client; + int flag = 1; + int result; + unsigned long long cnt = 0; + long long iter = 0; + long framesize; // pixel data only + uint32_t xsize, ysize; + char *ptr0; // source + char *ptr1; // source - offset by slice + int rs; + + struct timespec ts; + long scnt; + int semval; + int semr; + int slice, oldslice; + int NBslices; TCP_BUFFER_METADATA *frame_md; - long framesize1; // pixel data + metadata - long framesizeall; // total frame size : pixel data + metadata + kw - char *buff; // transmit buffer - + long framesize1; // pixel data + metadata + long framesizeall; // total frame size : pixel data + metadata + kw + char *buff; // transmit buffer - int semtrig = 6; // TODO - scan for available sem + int semtrig = 6; // TODO - scan for available sem // IMPORTANT: do not use semtrig 0 - int UseSem = 1; - - char errmsg[200]; - + int UseSem = 1; + char errmsg[200]; printf("Transmit stream %s over IP %s port %d\n", IDname, IPaddr, port); fflush(stdout); DEBUG_TRACEPOINT(" "); - // =========================== // processinfo support // =========================== @@ -355,61 +245,49 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit( char pinfomsg[200]; sprintf(pinfomsg, "setup"); - printf("Setup processinfo ..."); fflush(stdout); - processinfo = processinfo_setup( - pinfoname, - descr, // description - pinfomsg, // message on startup - __FUNCTION__, __FILE__, __LINE__ - ); + processinfo = processinfo_setup(pinfoname, + descr, // description + pinfomsg, // message on startup + __FUNCTION__, __FILE__, __LINE__); printf(" done\n"); fflush(stdout); - - // OPTIONAL SETTINGS - processinfo->MeasureTiming = 1; // Measure timing - processinfo->RT_priority = - RT_priority; // RT_priority, 0-99. Larger number = higher priority. If <0, ignore + processinfo->MeasureTiming = 1; // Measure timing + processinfo->RT_priority = RT_priority; // RT_priority, 0-99. Larger number = higher priority. If <0, ignore int loopOK = 1; ID = image_ID(IDname); - - - - - if((fds_client = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) + if ((fds_client = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { printf("ERROR creating socket\n"); exit(0); } - result = setsockopt(fds_client, /* socket affected */ - IPPROTO_TCP, /* set option at TCP level */ - TCP_NODELAY, /* name of option */ - (char *) &flag, /* the cast is historical cruft */ - sizeof(int)); /* length of option value */ + result = setsockopt(fds_client, /* socket affected */ + IPPROTO_TCP, /* set option at TCP level */ + TCP_NODELAY, /* name of option */ + (char *)&flag, /* the cast is historical cruft */ + sizeof(int)); /* length of option value */ - - if(result < 0) + if (result < 0) { processinfo_error(processinfo, "ERROR: setsockopt() failed\n"); loopOK = 0; } - if(loopOK == 1) + if (loopOK == 1) { - memset((char *) &sock_server, 0, sizeof(sock_server)); + memset((char *)&sock_server, 0, sizeof(sock_server)); sock_server.sin_family = AF_INET; sock_server.sin_port = htons(port); sock_server.sin_addr.s_addr = inet_addr(IPaddr); - if(connect(fds_client, (struct sockaddr *) &sock_server, - sizeof(sock_server)) < 0) + if (connect(fds_client, (struct sockaddr *)&sock_server, sizeof(sock_server)) < 0) { perror("Error connect() failed "); printf("port = %d\n", port); @@ -418,142 +296,132 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit( } } - if(loopOK == 1) + if (loopOK == 1) { - if(send(fds_client, (void *) data.image[ID].md, sizeof(IMAGE_METADATA), - 0) != sizeof(IMAGE_METADATA)) + if (send(fds_client, (void *)data.image[ID].md, sizeof(IMAGE_METADATA), 0) != sizeof(IMAGE_METADATA)) { - printf("send() sent a different number of bytes than expected %ld\n", - sizeof(IMAGE_METADATA)); + printf("send() sent a different number of bytes than expected %ld\n", sizeof(IMAGE_METADATA)); fflush(stdout); - processinfo_error(processinfo, - "send() sent a different number of bytes than expected"); + processinfo_error(processinfo, "send() sent a different number of bytes than expected"); loopOK = 0; } } - - if(loopOK == 1) + if (loopOK == 1) { xsize = data.image[ID].md[0].size[0]; ysize = data.image[ID].md[0].size[1]; NBslices = 1; - if(data.image[ID].md[0].naxis > 2) - if(data.image[ID].md[0].size[2] > 1) + if (data.image[ID].md[0].naxis > 2) + if (data.image[ID].md[0].size[2] > 1) { NBslices = data.image[ID].md[0].size[2]; } } - if(loopOK == 1) + if (loopOK == 1) { - switch(data.image[ID].md[0].datatype) + switch (data.image[ID].md[0].datatype) { - case _DATATYPE_INT8: - framesize = SIZEOF_DATATYPE_INT8 * xsize * ysize; - break; - case _DATATYPE_UINT8: - framesize = SIZEOF_DATATYPE_UINT8 * xsize * ysize; - break; - - case _DATATYPE_INT16: - framesize = SIZEOF_DATATYPE_INT16 * xsize * ysize; - break; - case _DATATYPE_UINT16: - framesize = SIZEOF_DATATYPE_UINT16 * xsize * ysize; - break; + case _DATATYPE_INT8: + framesize = SIZEOF_DATATYPE_INT8 * xsize * ysize; + break; + case _DATATYPE_UINT8: + framesize = SIZEOF_DATATYPE_UINT8 * xsize * ysize; + break; - case _DATATYPE_INT32: - framesize = SIZEOF_DATATYPE_INT32 * xsize * ysize; - break; - case _DATATYPE_UINT32: - framesize = SIZEOF_DATATYPE_UINT32 * xsize * ysize; - break; + case _DATATYPE_INT16: + framesize = SIZEOF_DATATYPE_INT16 * xsize * ysize; + break; + case _DATATYPE_UINT16: + framesize = SIZEOF_DATATYPE_UINT16 * xsize * ysize; + break; - case _DATATYPE_INT64: - framesize = SIZEOF_DATATYPE_INT64 * xsize * ysize; - break; - case _DATATYPE_UINT64: - framesize = SIZEOF_DATATYPE_UINT64 * xsize * ysize; - break; + case _DATATYPE_INT32: + framesize = SIZEOF_DATATYPE_INT32 * xsize * ysize; + break; + case _DATATYPE_UINT32: + framesize = SIZEOF_DATATYPE_UINT32 * xsize * ysize; + break; - case _DATATYPE_FLOAT: - framesize = SIZEOF_DATATYPE_FLOAT * xsize * ysize; - break; - case _DATATYPE_DOUBLE: - framesize = SIZEOF_DATATYPE_DOUBLE * xsize * ysize; - break; + case _DATATYPE_INT64: + framesize = SIZEOF_DATATYPE_INT64 * xsize * ysize; + break; + case _DATATYPE_UINT64: + framesize = SIZEOF_DATATYPE_UINT64 * xsize * ysize; + break; + case _DATATYPE_FLOAT: + framesize = SIZEOF_DATATYPE_FLOAT * xsize * ysize; + break; + case _DATATYPE_DOUBLE: + framesize = SIZEOF_DATATYPE_DOUBLE * xsize * ysize; + break; - default: - printf("ERROR: WRONG DATA TYPE\n"); - sprintf(errmsg, "WRONG DATA TYPE data type = %d\n", - data.image[ID].md[0].datatype); - printf("data type = %d\n", data.image[ID].md[0].datatype); - processinfo_error(processinfo, errmsg); - loopOK = 0; - break; + default: + printf("ERROR: WRONG DATA TYPE\n"); + sprintf(errmsg, "WRONG DATA TYPE data type = %d\n", data.image[ID].md[0].datatype); + printf("data type = %d\n", data.image[ID].md[0].datatype); + processinfo_error(processinfo, errmsg); + loopOK = 0; + break; } - printf("IMAGE FRAME SIZE = %ld\n", framesize); fflush(stdout); } - if(loopOK == 1) + if (loopOK == 1) { - switch(data.image[ID].md[0].datatype) + switch (data.image[ID].md[0].datatype) { - case _DATATYPE_INT8: - ptr0 = (char *) data.image[ID].array.SI8; - break; - case _DATATYPE_UINT8: - ptr0 = (char *) data.image[ID].array.UI8; - break; + case _DATATYPE_INT8: + ptr0 = (char *)data.image[ID].array.SI8; + break; + case _DATATYPE_UINT8: + ptr0 = (char *)data.image[ID].array.UI8; + break; - case _DATATYPE_INT16: - ptr0 = (char *) data.image[ID].array.SI16; - break; - case _DATATYPE_UINT16: - ptr0 = (char *) data.image[ID].array.UI16; - break; + case _DATATYPE_INT16: + ptr0 = (char *)data.image[ID].array.SI16; + break; + case _DATATYPE_UINT16: + ptr0 = (char *)data.image[ID].array.UI16; + break; - case _DATATYPE_INT32: - ptr0 = (char *) data.image[ID].array.SI32; - break; - case _DATATYPE_UINT32: - ptr0 = (char *) data.image[ID].array.UI32; - break; + case _DATATYPE_INT32: + ptr0 = (char *)data.image[ID].array.SI32; + break; + case _DATATYPE_UINT32: + ptr0 = (char *)data.image[ID].array.UI32; + break; - case _DATATYPE_INT64: - ptr0 = (char *) data.image[ID].array.SI64; - break; - case _DATATYPE_UINT64: - ptr0 = (char *) data.image[ID].array.UI64; - break; + case _DATATYPE_INT64: + ptr0 = (char *)data.image[ID].array.SI64; + break; + case _DATATYPE_UINT64: + ptr0 = (char *)data.image[ID].array.UI64; + break; - case _DATATYPE_FLOAT: - ptr0 = (char *) data.image[ID].array.F; - break; - case _DATATYPE_DOUBLE: - ptr0 = (char *) data.image[ID].array.D; - break; + case _DATATYPE_FLOAT: + ptr0 = (char *)data.image[ID].array.F; + break; + case _DATATYPE_DOUBLE: + ptr0 = (char *)data.image[ID].array.D; + break; - default: - printf("ERROR: WRONG DATA TYPE\n"); - exit(0); - break; + default: + printf("ERROR: WRONG DATA TYPE\n"); + exit(0); + break; } - - - - frame_md = (TCP_BUFFER_METADATA *) malloc(sizeof(TCP_BUFFER_METADATA)); + frame_md = (TCP_BUFFER_METADATA *)malloc(sizeof(TCP_BUFFER_METADATA)); framesize1 = framesize + sizeof(TCP_BUFFER_METADATA); - if(TCPTRANSFERKW == 0) + if (TCPTRANSFERKW == 0) { framesizeall = framesize1; } @@ -562,7 +430,7 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit( framesizeall = framesize1 + data.image[ID].md[0].NBkw * sizeof(IMAGE_KEYWORD); } - buff = (char *) malloc(sizeof(char) * framesizeall); + buff = (char *)malloc(sizeof(char) * framesizeall); printf("transfer buffer size = %ld\n", framesizeall); fflush(stdout); @@ -573,7 +441,7 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit( fflush(stdout); } - if((data.image[ID].md[0].sem == 0) || (mode == 1)) + if ((data.image[ID].md[0].sem == 0) || (mode == 1)) { processinfo_WriteMessage(processinfo, "sync using counter"); UseSem = 0; @@ -585,23 +453,18 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit( processinfo_WriteMessage(processinfo, msgstring); } - // =========================== // Start loop // =========================== - processinfo_loopstart( - processinfo); // Notify processinfo that we are entering loop - + processinfo_loopstart(processinfo); // Notify processinfo that we are entering loop - - while(loopOK == 1) + while (loopOK == 1) { loopOK = processinfo_loopstep(processinfo); - - if(UseSem == 0) // use counter + if (UseSem == 0) // use counter { - while(data.image[ID].md[0].cnt0 == cnt) // test if new frame exists + while (data.image[ID].md[0].cnt0 == cnt) // test if new frame exists { usleep(5); } @@ -610,7 +473,7 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit( } else { - if(clock_gettime(CLOCK_REALTIME, &ts) == -1) + if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { perror("clock_gettime"); exit(EXIT_FAILURE); @@ -619,14 +482,14 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit( semr = sem_timedwait(data.image[ID].semptr[semtrig], &ts); - if(iter == 0) + if (iter == 0) { processinfo_WriteMessage(processinfo, "Driving sem to 0"); printf("Driving semaphore to zero ... "); fflush(stdout); sem_getvalue(data.image[ID].semptr[semtrig], &semval); int semvalcnt = semval; - for(scnt = 0; scnt < semvalcnt; scnt++) + for (scnt = 0; scnt < semvalcnt; scnt++) { sem_getvalue(data.image[ID].semptr[semtrig], &semval); printf("sem = %d\n", semval); @@ -644,61 +507,49 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit( } } - - - - - - - processinfo_exec_start(processinfo); - if(processinfo_compute_status(processinfo) == 1) + if (processinfo_compute_status(processinfo) == 1) { - if(semr == 0) + if (semr == 0) { frame_md[0].cnt0 = data.image[ID].md[0].cnt0; frame_md[0].cnt1 = data.image[ID].md[0].cnt1; slice = data.image[ID].md[0].cnt1; - if(slice > oldslice + 1) + if (slice > oldslice + 1) { slice = oldslice + 1; } - if(NBslices > 1) - if(oldslice == NBslices - 1) + if (NBslices > 1) + if (oldslice == NBslices - 1) { slice = 0; } - if(slice > NBslices - 1) + if (slice > NBslices - 1) { slice = 0; } frame_md[0].cnt1 = slice; - ptr1 = ptr0 + framesize * - slice; //data.image[ID].md[0].cnt1; // frame that was just written + ptr1 = ptr0 + framesize * slice; //data.image[ID].md[0].cnt1; // frame that was just written memcpy(buff, ptr1, framesize); memcpy(buff + framesize, frame_md, sizeof(TCP_BUFFER_METADATA)); - if(TCPTRANSFERKW == 1) + if (TCPTRANSFERKW == 1) { - memcpy( - buff + framesize1, - (char *) data.image[ID].kw, - data.image[ID].md[0].NBkw * sizeof(IMAGE_KEYWORD)); + memcpy(buff + framesize1, (char *)data.image[ID].kw, + data.image[ID].md[0].NBkw * sizeof(IMAGE_KEYWORD)); } - rs = send(fds_client, buff, framesizeall, 0); - if(rs != framesizeall) + if (rs != framesizeall) { perror("socket send error "); - sprintf(errmsg, - "ERROR: send() sent a different number of bytes (%d) than expected %ld %ld %ld", - rs, (long) framesize, (long) framesizeall, (long) sizeof(TCP_BUFFER_METADATA)); + sprintf(errmsg, "ERROR: send() sent a different number of bytes (%d) than expected %ld %ld %ld", + rs, (long)framesize, (long)framesizeall, (long)sizeof(TCP_BUFFER_METADATA)); printf("%s\n", errmsg); fflush(stdout); processinfo_WriteMessage(processinfo, errmsg); @@ -706,19 +557,12 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit( } oldslice = slice; } - - } // process signals, increment loop counter processinfo_exec_end(processinfo); - if((data.signal_INT == 1) || \ - (data.signal_TERM == 1) || \ - (data.signal_ABRT == 1) || \ - (data.signal_BUS == 1) || \ - (data.signal_SEGV == 1) || \ - (data.signal_HUP == 1) || \ - (data.signal_PIPE == 1)) + if ((data.signal_INT == 1) || (data.signal_TERM == 1) || (data.signal_ABRT == 1) || (data.signal_BUS == 1) || + (data.signal_SEGV == 1) || (data.signal_HUP == 1) || (data.signal_PIPE == 1)) { loopOK = 0; } @@ -728,7 +572,6 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit( // ================================== processinfo_cleanExit(processinfo); - free(buff); close(fds_client); @@ -737,69 +580,51 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit( free(frame_md); - return ID; } - - - - - /** continuously receives 2D image through TCP link * mode = 1, force counter to be used for synchronization, ignore semaphores if they exist */ - -imageID COREMOD_MEMORY_image_NETWORKreceive( - int port, - __attribute__((unused)) int mode, - int RT_priority -) +imageID COREMOD_MEMORY_image_NETWORKreceive(int port, __attribute__((unused)) int mode, int RT_priority) { - struct sockaddr_in sock_server; - struct sockaddr_in sock_client; - int fds_server; - int fds_client; - socklen_t slen_client; - - int flag = 1; - long recvsize; - int result; - long totsize = 0; - int MAXPENDING = 5; - + struct sockaddr_in sock_server; + struct sockaddr_in sock_client; + int fds_server; + int fds_client; + socklen_t slen_client; + + int flag = 1; + long recvsize; + int result; + long totsize = 0; + int MAXPENDING = 5; IMAGE_METADATA *imgmd; - imageID ID; - long framesize; - uint32_t xsize; - uint32_t ysize; - char *ptr0; // source - long NBslices; - int socketOpen = 1; // 0 if socket is closed - int semval; - int semnb; - int OKim; - int axis; - - - imgmd = (IMAGE_METADATA *) malloc(sizeof(IMAGE_METADATA)); + imageID ID; + long framesize; + uint32_t xsize; + uint32_t ysize; + char *ptr0; // source + long NBslices; + int socketOpen = 1; // 0 if socket is closed + int semval; + int semnb; + int OKim; + int axis; + + imgmd = (IMAGE_METADATA *)malloc(sizeof(IMAGE_METADATA)); TCP_BUFFER_METADATA *frame_md; - long framesize1; // pixel data + metadata - long framesizefull; // pixel data + metadata + kw - char *buff; // buffer - - + long framesize1; // pixel data + metadata + long framesizefull; // pixel data + metadata + kw + char *buff; // buffer struct sched_param schedpar; - - - PROCESSINFO *processinfo; - if(data.processinfo == 1) + if (data.processinfo == 1) { // CREATE PROCESSINFO ENTRY // see processtools.c in module CommandLineInterface for details @@ -810,7 +635,7 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( processinfo->loopstat = 0; // loop initialization strcpy(processinfo->source_FUNCTION, __FUNCTION__); - strcpy(processinfo->source_FILE, __FILE__); + strcpy(processinfo->source_FILE, __FILE__); processinfo->source_LINE = __LINE__; char msgstring[200]; @@ -820,63 +645,58 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( // CATCH SIGNALS - if(sigaction(SIGTERM, &data.sigact, NULL) == -1) + if (sigaction(SIGTERM, &data.sigact, NULL) == -1) { printf("\ncan't catch SIGTERM\n"); } - if(sigaction(SIGINT, &data.sigact, NULL) == -1) + if (sigaction(SIGINT, &data.sigact, NULL) == -1) { printf("\ncan't catch SIGINT\n"); } - if(sigaction(SIGABRT, &data.sigact, NULL) == -1) + if (sigaction(SIGABRT, &data.sigact, NULL) == -1) { printf("\ncan't catch SIGABRT\n"); } - if(sigaction(SIGBUS, &data.sigact, NULL) == -1) + if (sigaction(SIGBUS, &data.sigact, NULL) == -1) { printf("\ncan't catch SIGBUS\n"); } - if(sigaction(SIGSEGV, &data.sigact, NULL) == -1) + if (sigaction(SIGSEGV, &data.sigact, NULL) == -1) { printf("\ncan't catch SIGSEGV\n"); } - if(sigaction(SIGHUP, &data.sigact, NULL) == -1) + if (sigaction(SIGHUP, &data.sigact, NULL) == -1) { printf("\ncan't catch SIGHUP\n"); } - if(sigaction(SIGPIPE, &data.sigact, NULL) == -1) + if (sigaction(SIGPIPE, &data.sigact, NULL) == -1) { printf("\ncan't catch SIGPIPE\n"); } - - - - - schedpar.sched_priority = RT_priority; - if(seteuid(data.euid) != 0) //This goes up to maximum privileges + if (seteuid(data.euid) != 0) //This goes up to maximum privileges { PRINT_ERROR("seteuid error"); } sched_setscheduler(0, SCHED_FIFO, &schedpar); //other option is SCHED_RR, might be faster - if(seteuid(data.ruid) != 0) //Go back to normal privileges + if (seteuid(data.ruid) != 0) //Go back to normal privileges { PRINT_ERROR("seteuid error"); } // create TCP socket - if((fds_server = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) + if ((fds_server = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { printf("ERROR creating socket\n"); - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo->loopstat = 4; processinfo_WriteMessage(processinfo, "ERROR creating socket"); @@ -884,21 +704,17 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( exit(0); } + memset((char *)&sock_server, 0, sizeof(sock_server)); - - - - memset((char *) &sock_server, 0, sizeof(sock_server)); - - result = setsockopt(fds_server, /* socket affected */ - IPPROTO_TCP, /* set option at TCP level */ - TCP_NODELAY, /* name of option */ - (char *) &flag, /* the cast is historical cruft */ - sizeof(int)); /* length of option value */ - if(result < 0) + result = setsockopt(fds_server, /* socket affected */ + IPPROTO_TCP, /* set option at TCP level */ + TCP_NODELAY, /* name of option */ + (char *)&flag, /* the cast is historical cruft */ + sizeof(int)); /* length of option value */ + if (result < 0) { printf("ERROR setsockopt\n"); - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo->loopstat = 4; processinfo_WriteMessage(processinfo, "ERROR socketopt"); @@ -906,21 +722,19 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( exit(0); } - sock_server.sin_family = AF_INET; sock_server.sin_port = htons(port); sock_server.sin_addr.s_addr = htonl(INADDR_ANY); //bind socket to port - if(bind(fds_server, (struct sockaddr *)&sock_server, - sizeof(sock_server)) == -1) + if (bind(fds_server, (struct sockaddr *)&sock_server, sizeof(sock_server)) == -1) { char msgstring[200]; sprintf(msgstring, "ERROR binding socket, port %d", port); printf("%s\n", msgstring); - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo->loopstat = 4; processinfo_WriteMessage(processinfo, msgstring); @@ -928,15 +742,14 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( exit(0); } - - if(listen(fds_server, MAXPENDING) < 0) + if (listen(fds_server, MAXPENDING) < 0) { char msgstring[200]; sprintf(msgstring, "ERROR listen socket"); printf("%s\n", msgstring); - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo->loopstat = 4; processinfo_WriteMessage(processinfo, msgstring); @@ -945,21 +758,20 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( exit(0); } -// cnt = 0; + // cnt = 0; /* Set the size of the in-out parameter */ slen_client = sizeof(sock_client); /* Wait for a client to connect */ - if((fds_client = accept(fds_server, (struct sockaddr *) &sock_client, - &slen_client)) == -1) + if ((fds_client = accept(fds_server, (struct sockaddr *)&sock_client, &slen_client)) == -1) { char msgstring[200]; sprintf(msgstring, "ERROR accept socket"); printf("%s\n", msgstring); - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo->loopstat = 4; processinfo_WriteMessage(processinfo, msgstring); @@ -972,15 +784,14 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( fflush(stdout); // listen for image metadata - if((recvsize = recv(fds_client, imgmd, sizeof(IMAGE_METADATA), - MSG_WAITALL)) < 0) + if ((recvsize = recv(fds_client, imgmd, sizeof(IMAGE_METADATA), MSG_WAITALL)) < 0) { char msgstring[200]; sprintf(msgstring, "ERROR receiving image metadata"); printf("%s\n", msgstring); - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo->loopstat = 4; processinfo_WriteMessage(processinfo, msgstring); @@ -989,37 +800,31 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( exit(0); } - - - if(data.processinfo == 1) + if (data.processinfo == 1) { char msgstring[200]; sprintf(msgstring, "Receiving stream %s", imgmd[0].name); processinfo_WriteMessage(processinfo, msgstring); } - { // flush socket for 1MB size_t flushsize = 1048576; char *flushbuff; - flushbuff = (char *) malloc(flushsize); + flushbuff = (char *)malloc(flushsize); recv(fds_client, flushbuff, flushsize, MSG_DONTWAIT); free(flushbuff); } - - - // is image already in memory ? OKim = 0; ID = image_ID(imgmd[0].name); - if(ID == -1) + if (ID == -1) { // is it in shared memory ? ID = read_sharedmem_image(imgmd[0].name); @@ -1027,55 +832,52 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( list_image_ID(); - if(ID == -1) + if (ID == -1) { OKim = 0; } else { OKim = 1; - if(imgmd[0].naxis != data.image[ID].md[0].naxis) + if (imgmd[0].naxis != data.image[ID].md[0].naxis) { OKim = 0; } - if(OKim == 1) + if (OKim == 1) { - for(axis = 0; axis < imgmd[0].naxis; axis++) - if(imgmd[0].size[axis] != data.image[ID].md[0].size[axis]) + for (axis = 0; axis < imgmd[0].naxis; axis++) + if (imgmd[0].size[axis] != data.image[ID].md[0].size[axis]) { OKim = 0; } } - if(imgmd[0].datatype != data.image[ID].md[0].datatype) + if (imgmd[0].datatype != data.image[ID].md[0].datatype) { OKim = 0; } - if(OKim == 0) + if (OKim == 0) { delete_image_ID(imgmd[0].name, DELETE_IMAGE_ERRMODE_WARNING); ID = -1; } } - int nbkw = 0; - if(TCPTRANSFERKW == 1) + if (TCPTRANSFERKW == 1) { nbkw = imgmd[0].NBkw; - if(imgmd[0].NBkw != data.image[ID].md[0].NBkw) + if (imgmd[0].NBkw != data.image[ID].md[0].NBkw) { OKim = 0; } } - if(OKim == 0) + if (OKim == 0) { printf("IMAGE %s HAS TO BE CREATED\n", imgmd[0].name); - create_image_ID(imgmd[0].name, imgmd[0].naxis, imgmd[0].size, - imgmd[0].datatype, imgmd[0].shared, nbkw, 0, &ID); - printf("Created image stream %s - shared = %d\n", imgmd[0].name, - imgmd[0].shared); + create_image_ID(imgmd[0].name, imgmd[0].naxis, imgmd[0].size, imgmd[0].datatype, imgmd[0].shared, nbkw, 0, &ID); + printf("Created image stream %s - shared = %d\n", imgmd[0].name, imgmd[0].shared); printf("Size = %d,%d\n", imgmd[0].size[0], imgmd[0].size[1]); } else @@ -1083,149 +885,139 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( printf("REUSING EXISTING IMAGE %s\n", imgmd[0].name); } - - - - COREMOD_MEMORY_image_set_createsem(imgmd[0].name, IMAGE_NB_SEMAPHORE); xsize = data.image[ID].md[0].size[0]; ysize = data.image[ID].md[0].size[1]; NBslices = 1; - if(data.image[ID].md[0].naxis > 2) - if(data.image[ID].md[0].size[2] > 1) + if (data.image[ID].md[0].naxis > 2) + if (data.image[ID].md[0].size[2] > 1) { NBslices = data.image[ID].md[0].size[2]; } - char typestring[8]; - switch(data.image[ID].md[0].datatype) + switch (data.image[ID].md[0].datatype) { - case _DATATYPE_INT8: - framesize = SIZEOF_DATATYPE_INT8 * xsize * ysize; - sprintf(typestring, "INT8"); - break; - - case _DATATYPE_UINT8: - framesize = SIZEOF_DATATYPE_UINT8 * xsize * ysize; - sprintf(typestring, "UINT8"); - break; - - case _DATATYPE_INT16: - framesize = SIZEOF_DATATYPE_INT16 * xsize * ysize; - sprintf(typestring, "INT16"); - break; - - case _DATATYPE_UINT16: - framesize = SIZEOF_DATATYPE_UINT16 * xsize * ysize; - sprintf(typestring, "UINT16"); - break; - - case _DATATYPE_INT32: - framesize = SIZEOF_DATATYPE_INT32 * xsize * ysize; - sprintf(typestring, "INT32"); - break; - - case _DATATYPE_UINT32: - framesize = SIZEOF_DATATYPE_UINT32 * xsize * ysize; - sprintf(typestring, "UINT32"); - break; - - case _DATATYPE_INT64: - framesize = SIZEOF_DATATYPE_INT64 * xsize * ysize; - sprintf(typestring, "INT64"); - break; - - case _DATATYPE_UINT64: - framesize = SIZEOF_DATATYPE_UINT64 * xsize * ysize; - sprintf(typestring, "UINT64"); - break; - - case _DATATYPE_FLOAT: - framesize = SIZEOF_DATATYPE_FLOAT * xsize * ysize; - sprintf(typestring, "FLOAT"); - break; - - case _DATATYPE_DOUBLE: - framesize = SIZEOF_DATATYPE_DOUBLE * xsize * ysize; - sprintf(typestring, "DOUBLE"); - break; - - default: - printf("ERROR: WRONG DATA TYPE\n"); - sprintf(typestring, "ERR"); - exit(0); - break; + case _DATATYPE_INT8: + framesize = SIZEOF_DATATYPE_INT8 * xsize * ysize; + sprintf(typestring, "INT8"); + break; + + case _DATATYPE_UINT8: + framesize = SIZEOF_DATATYPE_UINT8 * xsize * ysize; + sprintf(typestring, "UINT8"); + break; + + case _DATATYPE_INT16: + framesize = SIZEOF_DATATYPE_INT16 * xsize * ysize; + sprintf(typestring, "INT16"); + break; + + case _DATATYPE_UINT16: + framesize = SIZEOF_DATATYPE_UINT16 * xsize * ysize; + sprintf(typestring, "UINT16"); + break; + + case _DATATYPE_INT32: + framesize = SIZEOF_DATATYPE_INT32 * xsize * ysize; + sprintf(typestring, "INT32"); + break; + + case _DATATYPE_UINT32: + framesize = SIZEOF_DATATYPE_UINT32 * xsize * ysize; + sprintf(typestring, "UINT32"); + break; + + case _DATATYPE_INT64: + framesize = SIZEOF_DATATYPE_INT64 * xsize * ysize; + sprintf(typestring, "INT64"); + break; + + case _DATATYPE_UINT64: + framesize = SIZEOF_DATATYPE_UINT64 * xsize * ysize; + sprintf(typestring, "UINT64"); + break; + + case _DATATYPE_FLOAT: + framesize = SIZEOF_DATATYPE_FLOAT * xsize * ysize; + sprintf(typestring, "FLOAT"); + break; + + case _DATATYPE_DOUBLE: + framesize = SIZEOF_DATATYPE_DOUBLE * xsize * ysize; + sprintf(typestring, "DOUBLE"); + break; + + default: + printf("ERROR: WRONG DATA TYPE\n"); + sprintf(typestring, "ERR"); + exit(0); + break; } printf("image frame size = %ld\n", framesize); - switch(data.image[ID].md[0].datatype) + switch (data.image[ID].md[0].datatype) { - case _DATATYPE_INT8: - ptr0 = (char *) data.image[ID].array.SI8; - break; - case _DATATYPE_UINT8: - ptr0 = (char *) data.image[ID].array.UI8; - break; - - case _DATATYPE_INT16: - ptr0 = (char *) data.image[ID].array.SI16; - break; - case _DATATYPE_UINT16: - ptr0 = (char *) data.image[ID].array.UI16; - break; - - case _DATATYPE_INT32: - ptr0 = (char *) data.image[ID].array.SI32; - break; - case _DATATYPE_UINT32: - ptr0 = (char *) data.image[ID].array.UI32; - break; - - case _DATATYPE_INT64: - ptr0 = (char *) data.image[ID].array.SI64; - break; - case _DATATYPE_UINT64: - ptr0 = (char *) data.image[ID].array.UI64; - break; - - case _DATATYPE_FLOAT: - ptr0 = (char *) data.image[ID].array.F; - break; - case _DATATYPE_DOUBLE: - ptr0 = (char *) data.image[ID].array.D; - break; - - default: - printf("ERROR: WRONG DATA TYPE\n"); - exit(0); - break; + case _DATATYPE_INT8: + ptr0 = (char *)data.image[ID].array.SI8; + break; + case _DATATYPE_UINT8: + ptr0 = (char *)data.image[ID].array.UI8; + break; + + case _DATATYPE_INT16: + ptr0 = (char *)data.image[ID].array.SI16; + break; + case _DATATYPE_UINT16: + ptr0 = (char *)data.image[ID].array.UI16; + break; + + case _DATATYPE_INT32: + ptr0 = (char *)data.image[ID].array.SI32; + break; + case _DATATYPE_UINT32: + ptr0 = (char *)data.image[ID].array.UI32; + break; + + case _DATATYPE_INT64: + ptr0 = (char *)data.image[ID].array.SI64; + break; + case _DATATYPE_UINT64: + ptr0 = (char *)data.image[ID].array.UI64; + break; + + case _DATATYPE_FLOAT: + ptr0 = (char *)data.image[ID].array.F; + break; + case _DATATYPE_DOUBLE: + ptr0 = (char *)data.image[ID].array.D; + break; + + default: + printf("ERROR: WRONG DATA TYPE\n"); + exit(0); + break; } - - - if(data.processinfo == 1) + if (data.processinfo == 1) { char msgstring[200]; - sprintf(msgstring, "<- %s [%d x %d x %ld] %s", imgmd[0].name, (int) xsize, - (int) ysize, NBslices, typestring); - sprintf(processinfo->description, "%s %dx%dx%ld %s", imgmd[0].name, (int) xsize, - (int) ysize, NBslices, typestring); + sprintf(msgstring, "<- %s [%d x %d x %ld] %s", imgmd[0].name, (int)xsize, (int)ysize, NBslices, typestring); + sprintf(processinfo->description, "%s %dx%dx%ld %s", imgmd[0].name, (int)xsize, (int)ysize, NBslices, + typestring); processinfo_WriteMessage(processinfo, msgstring); } - - // this line is not needed, as frame_md is declared below // frame_md = (TCP_BUFFER_METADATA*) malloc(sizeof(TCP_BUFFER_METADATA)); framesize1 = framesize + sizeof(TCP_BUFFER_METADATA); - if(TCPTRANSFERKW == 0) + if (TCPTRANSFERKW == 0) { framesizefull = framesize1; } @@ -1234,15 +1026,13 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( framesizefull = framesize1 + nbkw * sizeof(IMAGE_KEYWORD); } - buff = (char *) malloc(sizeof(char) * framesizefull); + buff = (char *)malloc(sizeof(char) * framesizefull); frame_md = (TCP_BUFFER_METADATA *)(buff + framesize); - - - if(data.processinfo == 1) + if (data.processinfo == 1) { - processinfo->loopstat = 1; //notify processinfo that we are entering loop + processinfo->loopstat = 1; //notify processinfo that we are entering loop } socketOpen = 1; @@ -1258,40 +1048,38 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( long monitorloopindex = 0; long cnt0previous = 0; - while(loopOK == 1) + while (loopOK == 1) { - if(data.processinfo == 1) + if (data.processinfo == 1) { - while(processinfo->CTRLval == 1) // pause + while (processinfo->CTRLval == 1) // pause { usleep(50); } - if(processinfo->CTRLval == 2) // single iteration + if (processinfo->CTRLval == 2) // single iteration { processinfo->CTRLval = 1; } - if(processinfo->CTRLval == 3) // exit loop + if (processinfo->CTRLval == 3) // exit loop { loopOK = 0; } } - - if((recvsize = recv(fds_client, buff, framesizefull, MSG_WAITALL)) < 0) + if ((recvsize = recv(fds_client, buff, framesizefull, MSG_WAITALL)) < 0) { printf("ERROR recv()\n"); socketOpen = 0; } - - if((data.processinfo == 1) && (processinfo->MeasureTiming == 1)) + if ((data.processinfo == 1) && (processinfo->MeasureTiming == 1)) { processinfo_exec_start(processinfo); } - if(recvsize != 0) + if (recvsize != 0) { totsize += recvsize; } @@ -1300,16 +1088,14 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( socketOpen = 0; } - if(socketOpen == 1) + if (socketOpen == 1) { frame_md = (TCP_BUFFER_METADATA *)(buff + framesize); - data.image[ID].md[0].cnt1 = frame_md[0].cnt1; - // copy pixel data - if(NBslices > 1) + if (NBslices > 1) { memcpy(ptr0 + framesize * frame_md[0].cnt1, buff, framesize); } @@ -1318,32 +1104,25 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( memcpy(ptr0, buff, framesize); } - if(TCPTRANSFERKW == 1) + if (TCPTRANSFERKW == 1) { // copy kw - memcpy( - data.image[ID].kw, - (IMAGE_KEYWORD *)(buff + framesize1), - nbkw * sizeof(IMAGE_KEYWORD) - ); + memcpy(data.image[ID].kw, (IMAGE_KEYWORD *)(buff + framesize1), nbkw * sizeof(IMAGE_KEYWORD)); } frameincr = (long)frame_md[0].cnt0 - cnt0previous; - if(frameincr > 1) + if (frameincr > 1) { - printf("Skipped %ld frame(s) at index %ld %ld\n", frameincr - 1, - (long)(frame_md[0].cnt0), (long)(frame_md[0].cnt1)); + printf("Skipped %ld frame(s) at index %ld %ld\n", frameincr - 1, (long)(frame_md[0].cnt0), + (long)(frame_md[0].cnt1)); } cnt0previous = frame_md[0].cnt0; - if(monitorindex == monitorinterval) + if (monitorindex == monitorinterval) { - printf("[%5ld] input %20ld (+ %8ld) output %20ld (+ %8ld)\n", - monitorloopindex, - frame_md[0].cnt0, frame_md[0].cnt0 - minputcnt, - data.image[ID].md[0].cnt0, data.image[ID].md[0].cnt0 - moutputcnt); - + printf("[%5ld] input %20ld (+ %8ld) output %20ld (+ %8ld)\n", monitorloopindex, frame_md[0].cnt0, + frame_md[0].cnt0 - minputcnt, data.image[ID].md[0].cnt0, data.image[ID].md[0].cnt0 - moutputcnt); minputcnt = frame_md[0].cnt0; moutputcnt = data.image[ID].md[0].cnt0; @@ -1354,114 +1133,110 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( monitorindex++; - data.image[ID].md[0].cnt0++; - for(semnb = 0; semnb < data.image[ID].md[0].sem ; semnb++) + for (semnb = 0; semnb < data.image[ID].md[0].sem; semnb++) { sem_getvalue(data.image[ID].semptr[semnb], &semval); - if(semval < SEMAPHORE_MAXVAL) + if (semval < SEMAPHORE_MAXVAL) { sem_post(data.image[ID].semptr[semnb]); } } sem_getvalue(data.image[ID].semlog, &semval); - if(semval < 2) + if (semval < 2) { sem_post(data.image[ID].semlog); } - } - if(socketOpen == 0) + if (socketOpen == 0) { loopOK = 0; } - if((data.processinfo == 1) && (processinfo->MeasureTiming == 1)) + if ((data.processinfo == 1) && (processinfo->MeasureTiming == 1)) { processinfo_exec_end(processinfo); } - // process signals - if(data.signal_TERM == 1) + if (data.signal_TERM == 1) { loopOK = 0; - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo_SIGexit(processinfo, SIGTERM); } } - if(data.signal_INT == 1) + if (data.signal_INT == 1) { loopOK = 0; - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo_SIGexit(processinfo, SIGINT); } } - if(data.signal_ABRT == 1) + if (data.signal_ABRT == 1) { loopOK = 0; - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo_SIGexit(processinfo, SIGABRT); } } - if(data.signal_BUS == 1) + if (data.signal_BUS == 1) { loopOK = 0; - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo_SIGexit(processinfo, SIGBUS); } } - if(data.signal_SEGV == 1) + if (data.signal_SEGV == 1) { loopOK = 0; - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo_SIGexit(processinfo, SIGSEGV); } } - if(data.signal_HUP == 1) + if (data.signal_HUP == 1) { loopOK = 0; - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo_SIGexit(processinfo, SIGHUP); } } - if(data.signal_PIPE == 1) + if (data.signal_PIPE == 1) { loopOK = 0; - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo_SIGexit(processinfo, SIGPIPE); } } loopcnt++; - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo->loopcnt = loopcnt; } } - if(data.processinfo == 1) + if (data.processinfo == 1) { processinfo_cleanExit(processinfo); } - free(buff); close(fds_client); @@ -1471,10 +1246,5 @@ imageID COREMOD_MEMORY_image_NETWORKreceive( free(imgmd); - return ID; } - - - - diff --git a/src/COREMOD_memory/stream_TCP.h b/src/COREMOD_memory/stream_TCP.h index fc2224b0..ce860e67 100644 --- a/src/COREMOD_memory/stream_TCP.h +++ b/src/COREMOD_memory/stream_TCP.h @@ -5,29 +5,13 @@ #ifndef _STREAM_TCP_H #define _STREAM_TCP_H - errno_t stream__TCP_addCLIcmd(); +errno_t COREMOD_MEMORY_testfunction_semaphore(const char *IDname, int semtrig, int testmode); -errno_t COREMOD_MEMORY_testfunction_semaphore( - const char *IDname, - int semtrig, - int testmode -); - - -imageID COREMOD_MEMORY_image_NETWORKtransmit( - const char *IDname, - const char *IPaddr, - int port, - int mode, - int RT_priority -); +imageID COREMOD_MEMORY_image_NETWORKtransmit(const char *IDname, const char *IPaddr, int port, int mode, + int RT_priority); -imageID COREMOD_MEMORY_image_NETWORKreceive( - int port, - int mode, - int RT_priority -); +imageID COREMOD_MEMORY_image_NETWORKreceive(int port, int mode, int RT_priority); #endif diff --git a/src/COREMOD_memory/stream_ave.c b/src/COREMOD_memory/stream_ave.c index d1a382ae..40287a36 100644 --- a/src/COREMOD_memory/stream_ave.c +++ b/src/COREMOD_memory/stream_ave.c @@ -1,31 +1,17 @@ /** @file stream_ave.c */ - - - #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" -#include "stream_sem.h" #include "create_image.h" #include "delete_image.h" - - - - +#include "image_ID.h" +#include "stream_sem.h" // ========================================== // Forward declaration(s) // ========================================== -imageID COREMOD_MEMORY_streamAve( - const char *IDstream_name, - int NBave, - int mode, - const char *IDout_name -); - - +imageID COREMOD_MEMORY_streamAve(const char *IDstream_name, int NBave, int mode, const char *IDout_name); // ========================================== // Command line interface wrapper function(s) @@ -33,19 +19,12 @@ imageID COREMOD_MEMORY_streamAve( static errno_t COREMOD_MEMORY_streamAve__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_LONG) - + CLI_checkarg(3, CLIARG_LONG) - + CLI_checkarg(4, 5) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_LONG) + CLI_checkarg(3, CLIARG_LONG) + + CLI_checkarg(4, 5) == + 0) { - COREMOD_MEMORY_streamAve( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numl, - data.cmdargtoken[3].val.numl, - data.cmdargtoken[4].val.string - ); + COREMOD_MEMORY_streamAve(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl, + data.cmdargtoken[3].val.numl, data.cmdargtoken[4].val.string); return CLICMD_SUCCESS; } else @@ -54,9 +33,6 @@ static errno_t COREMOD_MEMORY_streamAve__cli() } } - - - // ========================================== // Register CLI command(s) // ========================================== @@ -64,10 +40,7 @@ static errno_t COREMOD_MEMORY_streamAve__cli() errno_t stream_ave_addCLIcmd() { RegisterCLIcommand( - "streamave", - __FILE__, - COREMOD_MEMORY_streamAve__cli, - "averages stream", + "streamave", __FILE__, COREMOD_MEMORY_streamAve__cli, "averages stream", " ", "streamave instream 100 0 outstream", "long COREMODE_MEMORY_streamAve(const char *IDstream_name, int NBave, int mode, const char *IDout_name)"); @@ -75,22 +48,6 @@ errno_t stream_ave_addCLIcmd() return RETURN_SUCCESS; } - - - - - - - - - - - - - - - - /** @brief Averages frames in stream * * @param[in] IDstream_name Input stream @@ -101,30 +58,24 @@ errno_t stream_ave_addCLIcmd() * */ - -imageID COREMOD_MEMORY_streamAve( - const char *IDstream_name, - int NBave, - int mode, - const char *IDout_name -) +imageID COREMOD_MEMORY_streamAve(const char *IDstream_name, int NBave, int mode, const char *IDout_name) { DEBUG_TRACE_FSTART(); - imageID IDout; - imageID IDout0; - imageID IDin; - uint8_t datatype; - uint32_t xsize; - uint32_t ysize; - uint32_t xysize; - uint32_t *imsize; - int_fast8_t OKloop; - int cntin = 0; - long dtus = 20; - long ii; - long cnt0; - long cnt0old; + imageID IDout; + imageID IDout0; + imageID IDin; + uint8_t datatype; + uint32_t xsize; + uint32_t ysize; + uint32_t xysize; + uint32_t *imsize; + int_fast8_t OKloop; + int cntin = 0; + long dtus = 20; + long ii; + long cnt0; + long cnt0old; IDin = image_ID(IDstream_name); datatype = data.image[IDin].md[0].datatype; @@ -132,21 +83,18 @@ imageID COREMOD_MEMORY_streamAve( ysize = data.image[IDin].md[0].size[1]; xysize = xsize * ysize; + FUNC_CHECK_RETURN(create_2Dimage_ID("_streamAve_tmp", xsize, ysize, &IDout0)); - FUNC_CHECK_RETURN( - create_2Dimage_ID("_streamAve_tmp", xsize, ysize, &IDout0)); - - if(mode == 1) // local image + if (mode == 1) // local image { - FUNC_CHECK_RETURN( - create_2Dimage_ID(IDout_name, xsize, ysize, &IDout)); + FUNC_CHECK_RETURN(create_2Dimage_ID(IDout_name, xsize, ysize, &IDout)); } else // shared memory { IDout = image_ID(IDout_name); - if(IDout == -1) // CREATE IT + if (IDout == -1) // CREATE IT { - imsize = (uint32_t *) malloc(sizeof(uint32_t) * 2); + imsize = (uint32_t *)malloc(sizeof(uint32_t) * 2); imsize[0] = xsize; imsize[1] = ysize; create_image_ID(IDout_name, 2, imsize, _DATATYPE_FLOAT, 1, 0, 0, &IDout); @@ -155,89 +103,88 @@ imageID COREMOD_MEMORY_streamAve( } } - cntin = 0; cnt0old = data.image[IDin].md[0].cnt0; - for(ii = 0; ii < xysize; ii++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[ii] = 0.0; } OKloop = 1; - while(OKloop == 1) + while (OKloop == 1) { // has new frame arrived ? cnt0 = data.image[IDin].md[0].cnt0; - if(cnt0 != cnt0old) + if (cnt0 != cnt0old) { - switch(datatype) + switch (datatype) { - case _DATATYPE_UINT8 : - for(ii = 0; ii < xysize; ii++) + case _DATATYPE_UINT8: + for (ii = 0; ii < xysize; ii++) { data.image[IDout0].array.F[ii] += data.image[IDin].array.UI8[ii]; } break; - case _DATATYPE_INT8 : - for(ii = 0; ii < xysize; ii++) + case _DATATYPE_INT8: + for (ii = 0; ii < xysize; ii++) { data.image[IDout0].array.F[ii] += data.image[IDin].array.SI8[ii]; } break; - case _DATATYPE_UINT16 : - for(ii = 0; ii < xysize; ii++) + case _DATATYPE_UINT16: + for (ii = 0; ii < xysize; ii++) { data.image[IDout0].array.F[ii] += data.image[IDin].array.UI16[ii]; } break; - case _DATATYPE_INT16 : - for(ii = 0; ii < xysize; ii++) + case _DATATYPE_INT16: + for (ii = 0; ii < xysize; ii++) { data.image[IDout0].array.F[ii] += data.image[IDin].array.SI16[ii]; } break; - case _DATATYPE_UINT32 : - for(ii = 0; ii < xysize; ii++) + case _DATATYPE_UINT32: + for (ii = 0; ii < xysize; ii++) { data.image[IDout0].array.F[ii] += data.image[IDin].array.UI32[ii]; } break; - case _DATATYPE_INT32 : - for(ii = 0; ii < xysize; ii++) + case _DATATYPE_INT32: + for (ii = 0; ii < xysize; ii++) { data.image[IDout0].array.F[ii] += data.image[IDin].array.SI32[ii]; } break; - case _DATATYPE_UINT64 : - for(ii = 0; ii < xysize; ii++) + case _DATATYPE_UINT64: + for (ii = 0; ii < xysize; ii++) { data.image[IDout0].array.F[ii] += data.image[IDin].array.UI64[ii]; } break; - case _DATATYPE_INT64 : - for(ii = 0; ii < xysize; ii++) + case _DATATYPE_INT64: + for (ii = 0; ii < xysize; ii++) { data.image[IDout0].array.F[ii] += data.image[IDin].array.SI64[ii]; } break; - case _DATATYPE_FLOAT : - for(ii = 0; ii < xysize; ii++) + case _DATATYPE_FLOAT: + for (ii = 0; ii < xysize; ii++) { data.image[IDout0].array.F[ii] += data.image[IDin].array.F[ii]; } break; - case _DATATYPE_DOUBLE : - for(ii = 0; ii < xysize; ii++) + case _DATATYPE_DOUBLE: + for (ii = 0; ii < xysize; ii++) { data.image[IDout0].array.F[ii] += data.image[IDin].array.D[ii]; } @@ -245,11 +192,11 @@ imageID COREMOD_MEMORY_streamAve( } cntin++; - if(cntin == NBave) + if (cntin == NBave) { cntin = 0; data.image[IDout].md[0].write = 1; - for(ii = 0; ii < xysize; ii++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[ii] = data.image[IDout0].array.F[ii] / NBave; } @@ -257,9 +204,9 @@ imageID COREMOD_MEMORY_streamAve( data.image[IDout].md[0].write = 0; COREMOD_MEMORY_image_set_sempost_byID(IDout, -1); - if(mode != 1) + if (mode != 1) { - for(ii = 0; ii < xysize; ii++) + for (ii = 0; ii < xysize; ii++) { data.image[IDout].array.F[ii] = 0.0; } @@ -279,4 +226,3 @@ imageID COREMOD_MEMORY_streamAve( DEBUG_TRACE_FEXIT(); return IDout; } - diff --git a/src/COREMOD_memory/stream_ave.h b/src/COREMOD_memory/stream_ave.h index 021275b5..bc03029a 100644 --- a/src/COREMOD_memory/stream_ave.h +++ b/src/COREMOD_memory/stream_ave.h @@ -1,14 +1,6 @@ /** @file stream_ave.h */ - errno_t stream_ave_addCLIcmd(); - -imageID COREMOD_MEMORY_streamAve( - const char *IDstream_name, - int NBave, - int mode, - const char *IDout_name -); - +imageID COREMOD_MEMORY_streamAve(const char *IDstream_name, int NBave, int mode, const char *IDout_name); diff --git a/src/COREMOD_memory/stream_delay.c b/src/COREMOD_memory/stream_delay.c index 3f0521e3..f226d51f 100644 --- a/src/COREMOD_memory/stream_delay.c +++ b/src/COREMOD_memory/stream_delay.c @@ -4,98 +4,52 @@ #include #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" -#include "stream_sem.h" #include "create_image.h" #include "delete_image.h" +#include "image_ID.h" +#include "stream_sem.h" #include "COREMOD_tools/COREMOD_tools.h" #include "CommandLineInterface/timeutils.h" - - - - // Local variables pointers -static char *inimname; -static char *outimname; -static float *delaysec; +static char *inimname; +static char *outimname; +static float *delaysec; static uint64_t *timebuffsize; -static int32_t *avemode; +static int32_t *avemode; static long fpi_avemode; static uint64_t *avedtns; static long fpi_timeavedtns; -static uint64_t *statusframelag; -static uint64_t *statuskkin; -static uint64_t *statuskkout; - - -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".in_name", "input image", "im1", - CLIARG_VISIBLE_DEFAULT, - (void **) &inimname, NULL - }, - { - CLIARG_STR, ".out_name", "output image", "out1", - CLIARG_VISIBLE_DEFAULT, - (void **) &outimname, NULL - }, - { - CLIARG_FLOAT32, ".delaysec", "delay [s]", "0.001", - CLIARG_VISIBLE_DEFAULT, - (void **) &delaysec, NULL - }, - { - CLIARG_UINT64, ".timebuffsize", "time buffer size", "10000", - CLIARG_HIDDEN_DEFAULT, - (void **) &timebuffsize, NULL - }, - { - CLIARG_INT32, ".option.timeavemode", "Enable time window averaging (>0)", "0", - CLIARG_HIDDEN_DEFAULT, - (void **) &avemode, &fpi_avemode - }, - { - CLIARG_UINT64, ".option.timeavedtns", "Averaging time window width [ns]", "10000", - CLIARG_HIDDEN_DEFAULT, - (void **) &avedtns, &fpi_timeavedtns - }, - { - CLIARG_UINT64, ".status.framelag", "current time lag frame index", "100", - CLIARG_OUTPUT_DEFAULT, - (void **) &statusframelag, NULL - }, - { - CLIARG_UINT64, ".status.kkin", "input cube slice index", "100", - CLIARG_OUTPUT_DEFAULT, - (void **) &statuskkin, NULL - }, - { - CLIARG_UINT64, ".status.kkout", "output cube slice index", "100", - CLIARG_OUTPUT_DEFAULT, - (void **) &statuskkout, NULL - } -}; - - - -static errno_t customCONFsetup() -{ - - return RETURN_SUCCESS; -} - +static uint64_t *statusframelag; +static uint64_t *statuskkin; +static uint64_t *statuskkout; + +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".in_name", "input image", "im1", CLIARG_VISIBLE_DEFAULT, (void **)&inimname, NULL}, + {CLIARG_STR, ".out_name", "output image", "out1", CLIARG_VISIBLE_DEFAULT, (void **)&outimname, NULL}, + {CLIARG_FLOAT32, ".delaysec", "delay [s]", "0.001", CLIARG_VISIBLE_DEFAULT, (void **)&delaysec, NULL}, + {CLIARG_UINT64, ".timebuffsize", "time buffer size", "10000", CLIARG_HIDDEN_DEFAULT, (void **)&timebuffsize, NULL}, + {CLIARG_INT32, ".option.timeavemode", "Enable time window averaging (>0)", "0", CLIARG_HIDDEN_DEFAULT, + (void **)&avemode, &fpi_avemode}, + {CLIARG_UINT64, ".option.timeavedtns", "Averaging time window width [ns]", "10000", CLIARG_HIDDEN_DEFAULT, + (void **)&avedtns, &fpi_timeavedtns}, + {CLIARG_UINT64, ".status.framelag", "current time lag frame index", "100", CLIARG_OUTPUT_DEFAULT, + (void **)&statusframelag, NULL}, + {CLIARG_UINT64, ".status.kkin", "input cube slice index", "100", CLIARG_OUTPUT_DEFAULT, (void **)&statuskkin, NULL}, + {CLIARG_UINT64, ".status.kkout", "output cube slice index", "100", CLIARG_OUTPUT_DEFAULT, (void **)&statuskkout, + NULL}}; + +static errno_t customCONFsetup() { return RETURN_SUCCESS; } static errno_t customCONFcheck() { - if(data.fpsptr != NULL) + if (data.fpsptr != NULL) { - if(data.fpsptr->parray[fpi_avemode].val.i32[0] == 0) // no ave mode + if (data.fpsptr->parray[fpi_avemode].val.i32[0] == 0) // no ave mode { data.fpsptr->parray[fpi_timeavedtns].fpflag &= ~FPFLAG_USED; data.fpsptr->parray[fpi_timeavedtns].fpflag &= ~FPFLAG_VISIBLE; @@ -110,47 +64,24 @@ static errno_t customCONFcheck() return RETURN_SUCCESS; } - - -static CLICMDDATA CLIcmddata = -{ - "streamdelay", - "delay input stream to output stream", - CLICMD_FIELDS_DEFAULTS -}; - +static CLICMDDATA CLIcmddata = {"streamdelay", "delay input stream to output stream", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - - - - +static errno_t help_function() { return RETURN_SUCCESS; } - -static errno_t streamdelay( - IMGID inimg, - IMGID outimg, - IMGID bufferimg, - struct timespec *tarray, - int *warray, - int *status -) +static errno_t streamdelay(IMGID inimg, IMGID outimg, IMGID bufferimg, struct timespec *tarray, int *warray, + int *status) { static uint64_t cnt0prev = 0; static uint64_t bufferindex_input = 0; static uint64_t bufferindex_output = 0; - // get current time struct timespec tnow; clock_gettime(CLOCK_REALTIME, &tnow); // update circular buffer if new frame has arrived - if(cnt0prev != inimg.md->cnt0) + if (cnt0prev != inimg.md->cnt0) { //printf("cnt %8ld %8ld CIRC BUFFER UPDATE -> index %8ld / %8ld\n", // cnt0prev, inimg.md->cnt0, bufferindex_input, *timebuffsize); @@ -159,32 +90,26 @@ static errno_t streamdelay( // update counter for next detection loop cnt0prev = inimg.md->cnt0; - // write current time to array - tarray[bufferindex_input].tv_sec = tnow.tv_sec; + tarray[bufferindex_input].tv_sec = tnow.tv_sec; tarray[bufferindex_input].tv_nsec = tnow.tv_nsec; // copy image data to circular buffer char *destptr; - destptr = (char *) bufferimg.im->array.raw; + destptr = (char *)bufferimg.im->array.raw; destptr += inimg.md->imdatamemsize * bufferindex_input; - memcpy( - destptr, - inimg.im->array.raw, - inimg.md->imdatamemsize - ); + memcpy(destptr, inimg.im->array.raw, inimg.md->imdatamemsize); warray[bufferindex_input] = 0; - bufferindex_input ++; - if(bufferindex_input == (*timebuffsize)) + bufferindex_input++; + if (bufferindex_input == (*timebuffsize)) { // end of circular buffer reached bufferindex_input = 0; } } - // check if current time is past time array at output index + delay struct timespec tdiff = timespec_diff(tarray[bufferindex_output], tnow); double tdiffv = 1.0 * tdiff.tv_sec + 1.0e-9 * tdiff.tv_nsec; @@ -195,15 +120,15 @@ static errno_t streamdelay( int updateflag = 0; long bufferindex_output_last = 0; - while((warray[bufferindex_output] == 0) && (tdiffv > (*delaysec))) + while ((warray[bufferindex_output] == 0) && (tdiffv > (*delaysec))) { // update output frame updateflag = 1; warray[bufferindex_output] = 1; bufferindex_output_last = bufferindex_output; - bufferindex_output ++; - if(bufferindex_output == (*timebuffsize)) + bufferindex_output++; + if (bufferindex_output == (*timebuffsize)) { // end of circular buffer reached bufferindex_output = 0; @@ -214,20 +139,15 @@ static errno_t streamdelay( tdiffv = 1.0 * tdiff.tv_sec + 1.0e-9 * tdiff.tv_nsec; } - if(updateflag == 1) + if (updateflag == 1) { - printf(" WRITE %8ld %8ld : %ld bytes\n", - bufferindex_input, bufferindex_output_last, - (long) inimg.md->imdatamemsize); + printf(" WRITE %8ld %8ld : %ld bytes\n", bufferindex_input, bufferindex_output_last, + (long)inimg.md->imdatamemsize); // copy circular buffer frame to output char *srcptr; - srcptr = (char *) bufferimg.im->array.raw; + srcptr = (char *)bufferimg.im->array.raw; srcptr += inimg.md->imdatamemsize * bufferindex_output_last; - memcpy( - outimg.im->array.raw, - srcptr, - inimg.md->imdatamemsize - ); + memcpy(outimg.im->array.raw, srcptr, inimg.md->imdatamemsize); // frame has been processed *status = 1; @@ -240,11 +160,6 @@ static errno_t streamdelay( return RETURN_SUCCESS; } - - - - - static errno_t compute_function() { DEBUG_TRACE_FSTART(); @@ -255,29 +170,26 @@ static errno_t compute_function() IMGID outimg = makeIMGID(outimname); imcreatelikewiseIMGID(&outimg, &inimg); - IMGID bufferimg = makeIMGID_3D("streamdelaybuff", inimg.size[0], inimg.size[1], - *timebuffsize); + IMGID bufferimg = makeIMGID_3D("streamdelaybuff", inimg.size[0], inimg.size[1], *timebuffsize); bufferimg.datatype = inimg.datatype; imcreateIMGID(&bufferimg); - - struct timespec *timeinarray; - timeinarray = (struct timespec *) malloc(sizeof(struct timespec) * - (*timebuffsize)); + struct timespec *timeinarray; + timeinarray = (struct timespec *)malloc(sizeof(struct timespec) * (*timebuffsize)); // get current time struct timespec tnow; clock_gettime(CLOCK_REALTIME, &tnow); - for(uint64_t i = 0; i < *timebuffsize; i++) + for (uint64_t i = 0; i < *timebuffsize; i++) { - timeinarray[i].tv_sec = tnow.tv_sec; + timeinarray[i].tv_sec = tnow.tv_sec; timeinarray[i].tv_nsec = tnow.tv_nsec; } // write array // 0 if new, 1 if already sent to output int *warray; - warray = (int *) malloc(sizeof(int) * (*timebuffsize)); - for(uint64_t i = 0; i < *timebuffsize; i++) + warray = (int *)malloc(sizeof(int) * (*timebuffsize)); + for (uint64_t i = 0; i < *timebuffsize; i++) { warray[i] = 1; } @@ -288,15 +200,9 @@ static errno_t compute_function() INSERT_STD_PROCINFO_COMPUTEFUNC_INIT INSERT_STD_PROCINFO_COMPUTEFUNC_LOOPSTART - streamdelay( - inimg, - outimg, - bufferimg, - timeinarray, - warray, - &status); + streamdelay(inimg, outimg, bufferimg, timeinarray, warray, &status); // status is 0 if no update to output, 1 otherwise - if(status != 0) + if (status != 0) { processinfo_update_output_stream(processinfo, outimg.ID); } @@ -310,13 +216,11 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - - INSERT_STD_FPSCLIfunctions -// Register function in CLI -errno_t CLIADDCMD_COREMOD_memory__streamdelay() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_memory__streamdelay() { CLIcmddata.FPS_customCONFsetup = customCONFsetup; CLIcmddata.FPS_customCONFcheck = customCONFcheck; @@ -325,13 +229,6 @@ errno_t CLIADDCMD_COREMOD_memory__streamdelay() return RETURN_SUCCESS; } - - - - - - - /* imageID IDimc; imageID IDin, IDout; @@ -549,12 +446,3 @@ errno_t CLIADDCMD_COREMOD_memory__streamdelay() processinfo_update_output_stream(processinfo, IDout); */ - - - - - - - - - diff --git a/src/COREMOD_memory/stream_delay.h b/src/COREMOD_memory/stream_delay.h index 1572efae..2a4dfc89 100644 --- a/src/COREMOD_memory/stream_delay.h +++ b/src/COREMOD_memory/stream_delay.h @@ -1,10 +1,8 @@ /** @file stream_delay,h */ - errno_t CLIADDCMD_COREMOD_memory__streamdelay(); - /* errno_t COREMOD_MEMORY_streamDelay( const char *IDin_name, diff --git a/src/COREMOD_memory/stream_diff.c b/src/COREMOD_memory/stream_diff.c index 9c6ac27c..37f00177 100644 --- a/src/COREMOD_memory/stream_diff.c +++ b/src/COREMOD_memory/stream_diff.c @@ -2,51 +2,31 @@ * @file stream_diff.c */ - #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" #include "create_image.h" +#include "image_ID.h" #include "stream_sem.h" - - - // ========================================== // forward declarations // ========================================== -imageID COREMOD_MEMORY_streamDiff( - const char *IDstream0_name, - const char *IDstream1_name, - const char *IDstreammask_name, - const char *IDstreamout_name, - long semtrig -); - +imageID COREMOD_MEMORY_streamDiff(const char *IDstream0_name, const char *IDstream1_name, const char *IDstreammask_name, + const char *IDstreamout_name, long semtrig); // ========================================== // command line interface wrapper functions // ========================================== - - static errno_t COREMOD_MEMORY_streamDiff__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_IMG) - + CLI_checkarg(3, 5) - + CLI_checkarg(4, CLIARG_STR_NOT_IMG) - + CLI_checkarg(5, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_IMG) + CLI_checkarg(3, 5) + + CLI_checkarg(4, CLIARG_STR_NOT_IMG) + CLI_checkarg(5, CLIARG_LONG) == + 0) { - COREMOD_MEMORY_streamDiff( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.string, - data.cmdargtoken[3].val.string, - data.cmdargtoken[4].val.string, - data.cmdargtoken[5].val.numl - ); + COREMOD_MEMORY_streamDiff(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, + data.cmdargtoken[3].val.string, data.cmdargtoken[4].val.string, + data.cmdargtoken[5].val.numl); return CLICMD_SUCCESS; } else @@ -55,38 +35,22 @@ static errno_t COREMOD_MEMORY_streamDiff__cli() } } - - // ========================================== // Register CLI command(s) // ========================================== errno_t stream_diff_addCLIcmd() { - RegisterCLIcommand( - "streamdiff", - __FILE__, - COREMOD_MEMORY_streamDiff__cli, - "compute difference between two image streams", - " ", - "streamdiff stream0 stream1 null outstream 3", - "long COREMOD_MEMORY_streamDiff(const char *IDstream0_name, const char *IDstream1_name, const char *IDstreamout_name, long semtrig)"); + RegisterCLIcommand("streamdiff", __FILE__, COREMOD_MEMORY_streamDiff__cli, + "compute difference between two image streams", + " ", + "streamdiff stream0 stream1 null outstream 3", + "long COREMOD_MEMORY_streamDiff(const char *IDstream0_name, const char *IDstream1_name, const " + "char *IDstreamout_name, long semtrig)"); return RETURN_SUCCESS; } - - - - - - - - - - - - /** * ## Purpose * @@ -94,23 +58,18 @@ errno_t stream_diff_addCLIcmd() * Triggers on stream0\n * */ -imageID COREMOD_MEMORY_streamDiff( - const char *IDstream0_name, - const char *IDstream1_name, - const char *IDstreammask_name, - const char *IDstreamout_name, - long semtrig -) +imageID COREMOD_MEMORY_streamDiff(const char *IDstream0_name, const char *IDstream1_name, const char *IDstreammask_name, + const char *IDstreamout_name, long semtrig) { - imageID ID0; - imageID ID1; - imageID IDout; - uint32_t xsize; - uint32_t ysize; - uint64_t xysize; - uint32_t *arraysize; - unsigned long long cnt; - imageID IDmask; // optional + imageID ID0; + imageID ID1; + imageID IDout; + uint32_t xsize; + uint32_t ysize; + uint64_t xysize; + uint32_t *arraysize; + unsigned long long cnt; + imageID IDmask; // optional ID0 = image_ID(IDstream0_name); ID1 = image_ID(IDstream1_name); @@ -120,17 +79,17 @@ imageID COREMOD_MEMORY_streamDiff( ysize = data.image[ID0].md[0].size[1]; xysize = xsize * ysize; - arraysize = (uint32_t *) malloc(sizeof(uint32_t) * 2); - if(arraysize == NULL) + arraysize = (uint32_t *)malloc(sizeof(uint32_t) * 2); + if (arraysize == NULL) { - PRINT_ERROR("malloc error"); - abort(); - } + PRINT_ERROR("malloc error"); + abort(); + } arraysize[0] = xsize; arraysize[1] = ysize; IDout = image_ID(IDstreamout_name); - if(IDout == -1) + if (IDout == -1) { create_image_ID(IDstreamout_name, 2, arraysize, _DATATYPE_FLOAT, 1, 0, 0, &IDout); COREMOD_MEMORY_image_set_createsem(IDstreamout_name, IMAGE_NB_SEMAPHORE); @@ -138,13 +97,12 @@ imageID COREMOD_MEMORY_streamDiff( free(arraysize); - - while(1) + while (1) { // has new frame arrived ? - if(data.image[ID0].md[0].sem == 0) + if (data.image[ID0].md[0].sem == 0) { - while(cnt == data.image[ID0].md[0].cnt0) // test if new frame exists + while (cnt == data.image[ID0].md[0].cnt0) // test if new frame exists { usleep(5); } @@ -155,33 +113,27 @@ imageID COREMOD_MEMORY_streamDiff( sem_wait(data.image[ID0].semptr[semtrig]); } - - - data.image[IDout].md[0].write = 1; - if(IDmask == -1) + if (IDmask == -1) { - for(uint64_t ii = 0; ii < xysize; ii++) + for (uint64_t ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[ii] = data.image[ID0].array.F[ii] - - data.image[ID1].array.F[ii]; + data.image[IDout].array.F[ii] = data.image[ID0].array.F[ii] - data.image[ID1].array.F[ii]; } } else { - for(uint64_t ii = 0; ii < xysize; ii++) + for (uint64_t ii = 0; ii < xysize; ii++) { - data.image[IDout].array.F[ii] = (data.image[ID0].array.F[ii] - - data.image[ID1].array.F[ii]) * data.image[IDmask].array.F[ii]; + data.image[IDout].array.F[ii] = + (data.image[ID0].array.F[ii] - data.image[ID1].array.F[ii]) * data.image[IDmask].array.F[ii]; } } - COREMOD_MEMORY_image_set_sempost_byID(IDout, -1);; + COREMOD_MEMORY_image_set_sempost_byID(IDout, -1); + ; data.image[IDout].md[0].cnt0++; data.image[IDout].md[0].write = 0; } - return IDout; } - - diff --git a/src/COREMOD_memory/stream_diff.h b/src/COREMOD_memory/stream_diff.h index 3c5ea535..190dcd06 100644 --- a/src/COREMOD_memory/stream_diff.h +++ b/src/COREMOD_memory/stream_diff.h @@ -2,14 +2,7 @@ * @file stream_diff.h */ - errno_t stream_diff_addCLIcmd(); - -imageID COREMOD_MEMORY_streamDiff( - const char *IDstream0_name, - const char *IDstream1_name, - const char *IDstreammask_name, - const char *IDstreamout_name, - long semtrig -); +imageID COREMOD_MEMORY_streamDiff(const char *IDstream0_name, const char *IDstream1_name, const char *IDstreammask_name, + const char *IDstreamout_name, long semtrig); diff --git a/src/COREMOD_memory/stream_halfimdiff.c b/src/COREMOD_memory/stream_halfimdiff.c index 21c85eff..4c50a4b8 100644 --- a/src/COREMOD_memory/stream_halfimdiff.c +++ b/src/COREMOD_memory/stream_halfimdiff.c @@ -1,29 +1,18 @@ -/** +/** * @file stream_hlfimdiff.c * @brief difference between two halves of stream image */ - #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" #include "create_image.h" +#include "image_ID.h" #include "stream_sem.h" - - - - - // ========================================== // Forward declaration(s) // ========================================== -imageID COREMOD_MEMORY_stream_halfimDiff( - const char *IDstream_name, - const char *IDstreamout_name, - long semtrig -); - +imageID COREMOD_MEMORY_stream_halfimDiff(const char *IDstream_name, const char *IDstreamout_name, long semtrig); // ========================================== // Command line interface wrapper function(s) @@ -31,17 +20,10 @@ imageID COREMOD_MEMORY_stream_halfimDiff( static errno_t COREMOD_MEMORY_stream_halfimDiff__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_IMG) - + CLI_checkarg(3, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_IMG) + CLI_checkarg(3, CLIARG_LONG) == 0) { - COREMOD_MEMORY_stream_halfimDiff( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.string, - data.cmdargtoken[3].val.numl - ); + COREMOD_MEMORY_stream_halfimDiff(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, + data.cmdargtoken[3].val.numl); return CLICMD_SUCCESS; } else @@ -50,9 +32,6 @@ static errno_t COREMOD_MEMORY_stream_halfimDiff__cli() } } - - - // ========================================== // Register CLI command(s) // ========================================== @@ -60,112 +39,95 @@ static errno_t COREMOD_MEMORY_stream_halfimDiff__cli() errno_t stream_halfimdiff_addCLIcmd() { RegisterCLIcommand( - "streamhalfdiff", - __FILE__, - COREMOD_MEMORY_stream_halfimDiff__cli, - "compute difference between two halves of an image stream", - " ", + "streamhalfdiff", __FILE__, COREMOD_MEMORY_stream_halfimDiff__cli, + "compute difference between two halves of an image stream", " ", "streamhalfdiff stream outstream 3", "long COREMOD_MEMORY_stream_halfimDiff(const char *IDstream_name, const char *IDstreamout_name, long semtrig)"); - + return RETURN_SUCCESS; } - - - - - - - // // compute difference between two halves of an image stream // triggers on instream // -imageID COREMOD_MEMORY_stream_halfimDiff( - const char *IDstream_name, - const char *IDstreamout_name, - long semtrig -) +imageID COREMOD_MEMORY_stream_halfimDiff(const char *IDstream_name, const char *IDstreamout_name, long semtrig) { - imageID ID0; - imageID IDout; - uint32_t xsizein; - uint32_t ysizein; - uint32_t xsize; - uint32_t ysize; - uint64_t xysize; - uint32_t *arraysize; - unsigned long long cnt; - uint8_t datatype; - uint8_t datatypeout; - + imageID ID0; + imageID IDout; + uint32_t xsizein; + uint32_t ysizein; + uint32_t xsize; + uint32_t ysize; + uint64_t xysize; + uint32_t *arraysize; + unsigned long long cnt; + uint8_t datatype; + uint8_t datatypeout; ID0 = image_ID(IDstream_name); xsizein = data.image[ID0].md[0].size[0]; ysizein = data.image[ID0].md[0].size[1]; -// xysizein = xsizein*ysizein; + // xysizein = xsizein*ysizein; xsize = xsizein; ysize = ysizein / 2; xysize = xsize * ysize; - - arraysize = (uint32_t *) malloc(sizeof(uint32_t) * 2); - if(arraysize == NULL) + arraysize = (uint32_t *)malloc(sizeof(uint32_t) * 2); + if (arraysize == NULL) { - PRINT_ERROR("malloc error"); - abort(); - } + PRINT_ERROR("malloc error"); + abort(); + } arraysize[0] = xsize; arraysize[1] = ysize; datatype = data.image[ID0].md[0].datatype; datatypeout = _DATATYPE_FLOAT; - switch(datatype) + switch (datatype) { - case _DATATYPE_UINT8: - datatypeout = _DATATYPE_INT16; - break; + case _DATATYPE_UINT8: + datatypeout = _DATATYPE_INT16; + break; - case _DATATYPE_UINT16: - datatypeout = _DATATYPE_INT32; - break; + case _DATATYPE_UINT16: + datatypeout = _DATATYPE_INT32; + break; - case _DATATYPE_UINT32: - datatypeout = _DATATYPE_INT64; - break; + case _DATATYPE_UINT32: + datatypeout = _DATATYPE_INT64; + break; - case _DATATYPE_UINT64: - datatypeout = _DATATYPE_INT64; - break; + case _DATATYPE_UINT64: + datatypeout = _DATATYPE_INT64; + break; + case _DATATYPE_INT8: + datatypeout = _DATATYPE_INT16; + break; - case _DATATYPE_INT8: - datatypeout = _DATATYPE_INT16; - break; + case _DATATYPE_INT16: + datatypeout = _DATATYPE_INT32; + break; - case _DATATYPE_INT16: - datatypeout = _DATATYPE_INT32; - break; + case _DATATYPE_INT32: + datatypeout = _DATATYPE_INT64; + break; - case _DATATYPE_INT32: - datatypeout = _DATATYPE_INT64; - break; - - case _DATATYPE_INT64: - datatypeout = _DATATYPE_INT64; - break; + case _DATATYPE_INT64: + datatypeout = _DATATYPE_INT64; + break; - case _DATATYPE_DOUBLE: - datatypeout = _DATATYPE_DOUBLE; - break; + case _DATATYPE_DOUBLE: + datatypeout = _DATATYPE_DOUBLE; + break; } IDout = image_ID(IDstreamout_name); - if(IDout == -1) + if (IDout == -1) { create_image_ID(IDstreamout_name, 2, arraysize, datatypeout, 1, 0, 0, &IDout); COREMOD_MEMORY_image_set_createsem(IDstreamout_name, IMAGE_NB_SEMAPHORE); @@ -173,14 +135,12 @@ imageID COREMOD_MEMORY_stream_halfimDiff( free(arraysize); - - - while(1) + while (1) { // has new frame arrived ? - if(data.image[ID0].md[0].sem == 0) + if (data.image[ID0].md[0].sem == 0) { - while(cnt == data.image[ID0].md[0].cnt0) // test if new frame exists + while (cnt == data.image[ID0].md[0].cnt0) // test if new frame exists { usleep(5); } @@ -193,93 +153,86 @@ imageID COREMOD_MEMORY_stream_halfimDiff( data.image[IDout].md[0].write = 1; - switch(datatype) + switch (datatype) { - case _DATATYPE_UINT8: - for(uint64_t ii = 0; ii < xysize; ii++) - { - data.image[IDout].array.SI16[ii] = data.image[ID0].array.UI8[ii] - - data.image[ID0].array.UI8[xysize + ii]; - } - break; - - case _DATATYPE_UINT16: - for(uint64_t ii = 0; ii < xysize; ii++) - { - data.image[IDout].array.SI32[ii] = data.image[ID0].array.UI16[ii] - - data.image[ID0].array.UI16[xysize + ii]; - } - break; - - case _DATATYPE_UINT32: - for(uint64_t ii = 0; ii < xysize; ii++) - { - data.image[IDout].array.SI64[ii] = data.image[ID0].array.UI32[ii] - - data.image[ID0].array.UI32[xysize + ii]; - } - break; - - case _DATATYPE_UINT64: - for(uint64_t ii = 0; ii < xysize; ii++) - { - data.image[IDout].array.SI64[ii] = data.image[ID0].array.UI64[ii] - - data.image[ID0].array.UI64[xysize + ii]; - } - break; - - - - case _DATATYPE_INT8: - for(uint64_t ii = 0; ii < xysize; ii++) - { - data.image[IDout].array.SI16[ii] = data.image[ID0].array.SI8[ii] - - data.image[ID0].array.SI8[xysize + ii]; - } - break; - - case _DATATYPE_INT16: - for(uint64_t ii = 0; ii < xysize; ii++) - { - data.image[IDout].array.SI32[ii] = data.image[ID0].array.SI16[ii] - - data.image[ID0].array.SI16[xysize + ii]; - } - break; - - case _DATATYPE_INT32: - for(uint64_t ii = 0; ii < xysize; ii++) - { - data.image[IDout].array.SI64[ii] = data.image[ID0].array.SI32[ii] - - data.image[ID0].array.SI32[xysize + ii]; - } - break; - - case _DATATYPE_INT64: - for(uint64_t ii = 0; ii < xysize; ii++) - { - data.image[IDout].array.SI64[ii] = data.image[ID0].array.SI64[ii] - - data.image[ID0].array.SI64[xysize + ii]; - } - break; - - - - case _DATATYPE_FLOAT: - for(uint64_t ii = 0; ii < xysize; ii++) - { - data.image[IDout].array.F[ii] = data.image[ID0].array.F[ii] - - data.image[ID0].array.F[xysize + ii]; - } - break; - - case _DATATYPE_DOUBLE: - for(uint64_t ii = 0; ii < xysize; ii++) - { - data.image[IDout].array.D[ii] = data.image[ID0].array.D[ii] - - data.image[ID0].array.D[xysize + ii]; - } - break; + case _DATATYPE_UINT8: + for (uint64_t ii = 0; ii < xysize; ii++) + { + data.image[IDout].array.SI16[ii] = + data.image[ID0].array.UI8[ii] - data.image[ID0].array.UI8[xysize + ii]; + } + break; + + case _DATATYPE_UINT16: + for (uint64_t ii = 0; ii < xysize; ii++) + { + data.image[IDout].array.SI32[ii] = + data.image[ID0].array.UI16[ii] - data.image[ID0].array.UI16[xysize + ii]; + } + break; + + case _DATATYPE_UINT32: + for (uint64_t ii = 0; ii < xysize; ii++) + { + data.image[IDout].array.SI64[ii] = + data.image[ID0].array.UI32[ii] - data.image[ID0].array.UI32[xysize + ii]; + } + break; + + case _DATATYPE_UINT64: + for (uint64_t ii = 0; ii < xysize; ii++) + { + data.image[IDout].array.SI64[ii] = + data.image[ID0].array.UI64[ii] - data.image[ID0].array.UI64[xysize + ii]; + } + break; + + case _DATATYPE_INT8: + for (uint64_t ii = 0; ii < xysize; ii++) + { + data.image[IDout].array.SI16[ii] = + data.image[ID0].array.SI8[ii] - data.image[ID0].array.SI8[xysize + ii]; + } + break; + + case _DATATYPE_INT16: + for (uint64_t ii = 0; ii < xysize; ii++) + { + data.image[IDout].array.SI32[ii] = + data.image[ID0].array.SI16[ii] - data.image[ID0].array.SI16[xysize + ii]; + } + break; + + case _DATATYPE_INT32: + for (uint64_t ii = 0; ii < xysize; ii++) + { + data.image[IDout].array.SI64[ii] = + data.image[ID0].array.SI32[ii] - data.image[ID0].array.SI32[xysize + ii]; + } + break; + case _DATATYPE_INT64: + for (uint64_t ii = 0; ii < xysize; ii++) + { + data.image[IDout].array.SI64[ii] = + data.image[ID0].array.SI64[ii] - data.image[ID0].array.SI64[xysize + ii]; + } + break; + + case _DATATYPE_FLOAT: + for (uint64_t ii = 0; ii < xysize; ii++) + { + data.image[IDout].array.F[ii] = data.image[ID0].array.F[ii] - data.image[ID0].array.F[xysize + ii]; + } + break; + + case _DATATYPE_DOUBLE: + for (uint64_t ii = 0; ii < xysize; ii++) + { + data.image[IDout].array.D[ii] = data.image[ID0].array.D[ii] - data.image[ID0].array.D[xysize + ii]; + } + break; } COREMOD_MEMORY_image_set_sempost_byID(IDout, -1); @@ -287,7 +240,5 @@ imageID COREMOD_MEMORY_stream_halfimDiff( data.image[IDout].md[0].write = 0; } - return IDout; } - diff --git a/src/COREMOD_memory/stream_halfimdiff.h b/src/COREMOD_memory/stream_halfimdiff.h index a999cd8a..c0628d15 100644 --- a/src/COREMOD_memory/stream_halfimdiff.h +++ b/src/COREMOD_memory/stream_halfimdiff.h @@ -1,13 +1,7 @@ -/** +/** * @file stream_hlfimdiff.h */ - errno_t stream_halfimdiff_addCLIcmd(); - -imageID COREMOD_MEMORY_stream_halfimDiff( - const char *IDstream_name, - const char *IDstreamout_name, - long semtrig -); +imageID COREMOD_MEMORY_stream_halfimDiff(const char *IDstream_name, const char *IDstreamout_name, long semtrig); diff --git a/src/COREMOD_memory/stream_monitorlimits.c b/src/COREMOD_memory/stream_monitorlimits.c index 47c588eb..3503a671 100644 --- a/src/COREMOD_memory/stream_monitorlimits.c +++ b/src/COREMOD_memory/stream_monitorlimits.c @@ -8,36 +8,22 @@ #include #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" -#include "stream_sem.h" #include "create_image.h" #include "delete_image.h" +#include "image_ID.h" +#include "stream_sem.h" #include "COREMOD_tools/COREMOD_tools.h" - - - - - - // ========================================== // Forward declaration(s) // ========================================== - - errno_t stream_monitorlimits_FPCONF(); errno_t stream_monitorlimits_RUN(); - -errno_t stream_monitorlimits( - const char *instreamname -); - - - +errno_t stream_monitorlimits(const char *instreamname); // ========================================== // Command line interface wrapper function(s) @@ -52,31 +38,28 @@ static errno_t COREMOD_MEMORY_stream_monitorlimits__cli() // See code in function_parameter.c for detailed rules. function_parameter_getFPSargs_from_CLIfunc("streammlim"); - if(data.FPS_CMDCODE != 0) { // use FPS implementation + if (data.FPS_CMDCODE != 0) + { // use FPS implementation // set pointers to CONF and RUN functions data.FPS_CONFfunc = stream_monitorlimits_FPCONF; - data.FPS_RUNfunc = stream_monitorlimits_RUN; + data.FPS_RUNfunc = stream_monitorlimits_RUN; function_parameter_execFPScmd(); return RETURN_SUCCESS; } - // call non FPS implementation - all parameters specified at function launch - if( - CLI_checkarg(1, CLIARG_IMG) - == 0) { - stream_monitorlimits( - data.cmdargtoken[1].val.string - ); + if (CLI_checkarg(1, CLIARG_IMG) == 0) + { + stream_monitorlimits(data.cmdargtoken[1].val.string); return RETURN_SUCCESS; - } else { + } + else + { return CLICMD_INVALID_ARG; } } - - // ========================================== // Register CLI command(s) // ========================================== @@ -84,25 +67,13 @@ static errno_t COREMOD_MEMORY_stream_monitorlimits__cli() errno_t stream_monitorlimits_addCLIcmd() { - RegisterCLIcommand( - "streammlim", - __FILE__, - COREMOD_MEMORY_stream_monitorlimits__cli, - "monitor stream values for safety", - "FPS function", - "streammlim", - "COREMOD_MEMORY_stream_monitorlimits_RUN"); + RegisterCLIcommand("streammlim", __FILE__, COREMOD_MEMORY_stream_monitorlimits__cli, + "monitor stream values for safety", "FPS function", "streammlim", + "COREMOD_MEMORY_stream_monitorlimits_RUN"); return RETURN_SUCCESS; } - - - - - - - /** * @brief Manages configuration parameters for stream_monitorlimits * @@ -130,15 +101,12 @@ errno_t stream_monitorlimits_FPCONF() FPFLAG = FPFLAG_DEFAULT_INPUT; FPFLAG &= ~FPFLAG_WRITERUN; - FPS_ADDPARAM_STREAM_IN(streaminname, ".in_sname", "input stream", NULL); - - long dtus_default[4] = { 50, 1, 1000000000, 50 }; - long fp_dtus = 0; - function_parameter_add_entry(&fps, ".dtus", - "Loop period [us]", FPTYPE_INT64, FPFLAG, &dtus_default, &fp_dtus); - (void) fp_dtus; // suppresses unused parameter compiler warning - + FPS_ADDPARAM_STREAM_IN(streaminname, ".in_sname", "input stream", NULL); + long dtus_default[4] = {50, 1, 1000000000, 50}; + long fp_dtus = 0; + function_parameter_add_entry(&fps, ".dtus", "Loop period [us]", FPTYPE_INT64, FPFLAG, &dtus_default, &fp_dtus); + (void)fp_dtus; // suppresses unused parameter compiler warning // Limits @@ -146,57 +114,32 @@ errno_t stream_monitorlimits_FPCONF() FPFLAG |= FPFLAG_WRITERUN; long fpi_minON = 0; - function_parameter_add_entry(&fps, ".minON", "min toggle", - FPTYPE_ONOFF, FPFLAG, NULL, &fpi_minON); - (void) fpi_minON; + function_parameter_add_entry(&fps, ".minON", "min toggle", FPTYPE_ONOFF, FPFLAG, NULL, &fpi_minON); + (void)fpi_minON; long fpi_minVal = 0; - function_parameter_add_entry(&fps, ".minVal", "min value", - FPTYPE_FLOAT32, FPFLAG, NULL, &fpi_minVal); - (void) fpi_minVal; - - - + function_parameter_add_entry(&fps, ".minVal", "min value", FPTYPE_FLOAT32, FPFLAG, NULL, &fpi_minVal); + (void)fpi_minVal; long fpi_maxON = 0; - function_parameter_add_entry(&fps, ".maxON", "max toggle", - FPTYPE_ONOFF, FPFLAG_DEFAULT_INPUT, NULL, &fpi_maxON); - (void) fpi_maxON; + function_parameter_add_entry(&fps, ".maxON", "max toggle", FPTYPE_ONOFF, FPFLAG_DEFAULT_INPUT, NULL, &fpi_maxON); + (void)fpi_maxON; long fpi_maxVal = 0; - function_parameter_add_entry(&fps, ".minVal", "min value", - FPTYPE_FLOAT32, FPFLAG, NULL, &fpi_maxVal); - (void) fpi_maxVal; - - - + function_parameter_add_entry(&fps, ".minVal", "min value", FPTYPE_FLOAT32, FPFLAG, NULL, &fpi_maxVal); + (void)fpi_maxVal; // start function parameter conf loop, defined in function_parameter.h FPS_CONFLOOP_START - // stop function parameter conf loop, defined in function_parameter.h FPS_CONFLOOP_END printf("CONF EXIT CONDITION MET\n"); - return RETURN_SUCCESS; } - - - - - - - - - - - - - /** * @brief Delay image stream by time offset * @@ -210,7 +153,7 @@ errno_t stream_monitorlimits_RUN() // =========================== /// ### CONNECT TO FPS // =========================== - FPS_CONNECT( data.FPS_name, FPSCONNECT_RUN ); + FPS_CONNECT(data.FPS_name, FPSCONNECT_RUN); // =============================== /// ### GET FUNCTION PARAMETER VALUES @@ -219,26 +162,19 @@ errno_t stream_monitorlimits_RUN() // These parameters are read once, before running the loop // char IDin_name[FUNCTION_PARAMETER_STRMAXLEN]; - strncpy(IDin_name, functionparameter_GetParamPtr_STRING(&fps, ".in_sname"), - FUNCTION_PARAMETER_STRMAXLEN-1); - - long dtus = functionparameter_GetParamValue_INT64(&fps, ".dtus"); - - + strncpy(IDin_name, functionparameter_GetParamPtr_STRING(&fps, ".in_sname"), FUNCTION_PARAMETER_STRMAXLEN - 1); + long dtus = functionparameter_GetParamValue_INT64(&fps, ".dtus"); // =========================== /// ### processinfo support // =========================== PROCESSINFO *processinfo; - processinfo = processinfo_setup( - data.FPS_name, // re-use fpsname as processinfo name - "monitor stream limits", // description - "starting monitor", // message on startup - __FUNCTION__, __FILE__, __LINE__ - ); - + processinfo = processinfo_setup(data.FPS_name, // re-use fpsname as processinfo name + "monitor stream limits", // description + "starting monitor", // message on startup + __FUNCTION__, __FILE__, __LINE__); // ============================================= /// ### OPTIONAL: TESTING CONDITION FOR LOOP ENTRY @@ -246,22 +182,18 @@ errno_t stream_monitorlimits_RUN() // Pre-loop testing, anything that would prevent loop from starting should issue message int loopOK = 1; - - // Specify input stream trigger imageID IDin = image_ID(IDin_name); - processinfo_waitoninputstream_init(processinfo, IDin, - PROCESSINFO_TRIGGERMODE_DELAY, -1); + processinfo_waitoninputstream_init(processinfo, IDin, PROCESSINFO_TRIGGERMODE_DELAY, -1); processinfo->triggerdelay.tv_sec = 0; - processinfo->triggerdelay.tv_nsec = (long) (dtus*1000); - while(processinfo->triggerdelay.tv_nsec > 1000000000) + processinfo->triggerdelay.tv_nsec = (long)(dtus * 1000); + while (processinfo->triggerdelay.tv_nsec > 1000000000) { processinfo->triggerdelay.tv_nsec -= 1000000000; processinfo->triggerdelay.tv_sec += 1; } - // =========================== /// ### START LOOP // =========================== @@ -269,19 +201,16 @@ errno_t stream_monitorlimits_RUN() // Notify processinfo that we are entering loop processinfo_loopstart(processinfo); - - while(loopOK == 1) + while (loopOK == 1) { loopOK = processinfo_loopstep(processinfo); processinfo_waitoninputstream(processinfo); - processinfo_exec_start(processinfo); - if(processinfo_compute_status(processinfo) == 1) + if (processinfo_compute_status(processinfo) == 1) { - } // process signals, increment loop counter @@ -294,21 +223,10 @@ errno_t stream_monitorlimits_RUN() processinfo_cleanExit(processinfo); function_parameter_RUNexit(&fps); - return RETURN_SUCCESS; } - - - - - - - - -errno_t stream_monitorlimits( - const char *instreamname -) +errno_t stream_monitorlimits(const char *instreamname) { FUNCTION_PARAMETER_STRUCT fps; @@ -328,9 +246,3 @@ errno_t stream_monitorlimits( return RETURN_SUCCESS; } - - - - - - diff --git a/src/COREMOD_memory/stream_monitorlimits.h b/src/COREMOD_memory/stream_monitorlimits.h index 52ff95d5..9e93ca7d 100644 --- a/src/COREMOD_memory/stream_monitorlimits.h +++ b/src/COREMOD_memory/stream_monitorlimits.h @@ -1,19 +1,10 @@ /** @file stream_delay,h */ - - - errno_t stream_monitorlimits_addCLIcmd(); - - - errno_t stream_monitorlimits_FPCONF(); errno_t stream_monitorlimits_RUN(); - -errno_t stream_monitorlimits( - const char *instreamname -); +errno_t stream_monitorlimits(const char *instreamname); diff --git a/src/COREMOD_memory/stream_paste.c b/src/COREMOD_memory/stream_paste.c index 31c7b473..87f6f3c4 100644 --- a/src/COREMOD_memory/stream_paste.c +++ b/src/COREMOD_memory/stream_paste.c @@ -3,54 +3,31 @@ * @brief Paste two equal size 2D streams into an output 2D stream */ - - #include "CommandLineInterface/CLIcore.h" +#include "create_image.h" #include "image_ID.h" #include "stream_sem.h" -#include "create_image.h" - - - // ========================================== // Forward declarations // ========================================== -imageID COREMOD_MEMORY_streamPaste( - const char *IDstream0_name, - const char *IDstream1_name, - const char *IDstreamout_name, - long semtrig0, - long semtrig1, - int master -); - +imageID COREMOD_MEMORY_streamPaste(const char *IDstream0_name, const char *IDstream1_name, const char *IDstreamout_name, + long semtrig0, long semtrig1, int master); // ========================================== // Command line interface wrapper functions // ========================================== - static errno_t COREMOD_MEMORY_streamPaste__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_IMG) - + CLI_checkarg(3, 5) - + CLI_checkarg(4, CLIARG_LONG) - + CLI_checkarg(5, CLIARG_LONG) - + CLI_checkarg(6, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_IMG) + CLI_checkarg(3, 5) + + CLI_checkarg(4, CLIARG_LONG) + CLI_checkarg(5, CLIARG_LONG) + CLI_checkarg(6, CLIARG_LONG) == + 0) { - COREMOD_MEMORY_streamPaste( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.string, - data.cmdargtoken[3].val.string, - data.cmdargtoken[4].val.numl, - data.cmdargtoken[5].val.numl, - data.cmdargtoken[6].val.numl - ); + COREMOD_MEMORY_streamPaste(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, + data.cmdargtoken[3].val.string, data.cmdargtoken[4].val.numl, + data.cmdargtoken[5].val.numl, data.cmdargtoken[6].val.numl); return CLICMD_SUCCESS; } else @@ -59,8 +36,6 @@ static errno_t COREMOD_MEMORY_streamPaste__cli() } } - - // ========================================== // Register CLI command(s) // ========================================== @@ -68,50 +43,34 @@ static errno_t COREMOD_MEMORY_streamPaste__cli() errno_t stream_paste_addCLIcmd() { - RegisterCLIcommand( - "streampaste", - __FILE__, - COREMOD_MEMORY_streamPaste__cli, - "paste two 2D image streams of same size", - " ", - "streampaste stream0 stream1 outstream 3 3 0", - "long COREMOD_MEMORY_streamPaste(const char *IDstream0_name, const char *IDstream1_name, const char *IDstreamout_name, long semtrig0, long semtrig1, int master)"); - + RegisterCLIcommand("streampaste", __FILE__, COREMOD_MEMORY_streamPaste__cli, + "paste two 2D image streams of same size", + " ", + "streampaste stream0 stream1 outstream 3 3 0", + "long COREMOD_MEMORY_streamPaste(const char *IDstream0_name, const char *IDstream1_name, const " + "char *IDstreamout_name, long semtrig0, long semtrig1, int master)"); return RETURN_SUCCESS; } - - - - - - - // // compute difference between two 2D streams // triggers alternatively on stream0 and stream1 // -imageID COREMOD_MEMORY_streamPaste( - const char *IDstream0_name, - const char *IDstream1_name, - const char *IDstreamout_name, - long semtrig0, - long semtrig1, - int master -) +imageID COREMOD_MEMORY_streamPaste(const char *IDstream0_name, const char *IDstream1_name, const char *IDstreamout_name, + long semtrig0, long semtrig1, int master) { - imageID ID0; - imageID ID1; - imageID IDout; - imageID IDin; - long Xoffset; - uint32_t xsize; - uint32_t ysize; - uint32_t *arraysize; - unsigned long long cnt; - uint8_t datatype; - int FrameIndex; + imageID ID0; + imageID ID1; + imageID IDout; + imageID IDin; + long Xoffset; + uint32_t xsize; + uint32_t ysize; + uint32_t *arraysize; + unsigned long long cnt; + uint8_t datatype; + int FrameIndex; ID0 = image_ID(IDstream0_name); ID1 = image_ID(IDstream1_name); @@ -120,8 +79,8 @@ imageID COREMOD_MEMORY_streamPaste( ysize = data.image[ID0].md[0].size[1]; datatype = data.image[ID0].md[0].datatype; - arraysize = (uint32_t *) malloc(sizeof(uint32_t) * 2); - if(arraysize == NULL) + arraysize = (uint32_t *)malloc(sizeof(uint32_t) * 2); + if (arraysize == NULL) { PRINT_ERROR("malloc error"); abort(); @@ -130,24 +89,23 @@ imageID COREMOD_MEMORY_streamPaste( arraysize[1] = ysize; IDout = image_ID(IDstreamout_name); - if(IDout == -1) + if (IDout == -1) { create_image_ID(IDstreamout_name, 2, arraysize, datatype, 1, 0, 0, &IDout); COREMOD_MEMORY_image_set_createsem(IDstreamout_name, IMAGE_NB_SEMAPHORE); } free(arraysize); - FrameIndex = 0; - while(1) + while (1) { - if(FrameIndex == 0) + if (FrameIndex == 0) { // has new frame 0 arrived ? - if(data.image[ID0].md[0].sem == 0) + if (data.image[ID0].md[0].sem == 0) { - while(cnt == data.image[ID0].md[0].cnt0) // test if new frame exists + while (cnt == data.image[ID0].md[0].cnt0) // test if new frame exists { usleep(5); } @@ -163,9 +121,9 @@ imageID COREMOD_MEMORY_streamPaste( else { // has new frame 1 arrived ? - if(data.image[ID1].md[0].sem == 0) + if (data.image[ID1].md[0].sem == 0) { - while(cnt == data.image[ID1].md[0].cnt0) // test if new frame exists + while (cnt == data.image[ID1].md[0].cnt0) // test if new frame exists { usleep(5); } @@ -179,133 +137,133 @@ imageID COREMOD_MEMORY_streamPaste( IDin = 1; } - data.image[IDout].md[0].write = 1; - switch(datatype) + switch (datatype) { - case _DATATYPE_UINT8 : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.UI8[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.UI8[jj * xsize + ii]; - } - break; - - case _DATATYPE_UINT16 : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.UI16[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.UI16[jj * xsize + ii]; - } - break; - - case _DATATYPE_UINT32 : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.UI32[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.UI32[jj * xsize + ii]; - } - break; - - case _DATATYPE_UINT64 : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.UI64[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.UI64[jj * xsize + ii]; - } - break; - - case _DATATYPE_INT8 : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.SI8[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.SI8[jj * xsize + ii]; - } - break; - - case _DATATYPE_INT16 : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.SI16[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.SI16[jj * xsize + ii]; - } - break; - - case _DATATYPE_INT32 : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.SI32[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.SI32[jj * xsize + ii]; - } - break; - - case _DATATYPE_INT64 : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.SI64[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.SI64[jj * xsize + ii]; - } - break; - - case _DATATYPE_FLOAT : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.F[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.F[jj * xsize + ii]; - } - break; - - case _DATATYPE_DOUBLE : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.D[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.D[jj * xsize + ii]; - } - break; - - case _DATATYPE_COMPLEX_FLOAT : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.CF[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.CF[jj * xsize + ii]; - } - break; - - case _DATATYPE_COMPLEX_DOUBLE : - for(uint32_t ii = 0; ii < xsize; ii++) - for(uint32_t jj = 0; jj < ysize; jj++) - { - data.image[IDout].array.CD[jj * 2 * xsize + ii + Xoffset] = - data.image[IDin].array.CD[jj * xsize + ii]; - } - break; - - default : - printf("Unknown data type\n"); - exit(0); - break; + case _DATATYPE_UINT8: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.UI8[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.UI8[jj * xsize + ii]; + } + break; + + case _DATATYPE_UINT16: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.UI16[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.UI16[jj * xsize + ii]; + } + break; + + case _DATATYPE_UINT32: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.UI32[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.UI32[jj * xsize + ii]; + } + break; + + case _DATATYPE_UINT64: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.UI64[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.UI64[jj * xsize + ii]; + } + break; + + case _DATATYPE_INT8: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.SI8[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.SI8[jj * xsize + ii]; + } + break; + + case _DATATYPE_INT16: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.SI16[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.SI16[jj * xsize + ii]; + } + break; + + case _DATATYPE_INT32: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.SI32[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.SI32[jj * xsize + ii]; + } + break; + + case _DATATYPE_INT64: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.SI64[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.SI64[jj * xsize + ii]; + } + break; + + case _DATATYPE_FLOAT: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.F[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.F[jj * xsize + ii]; + } + break; + + case _DATATYPE_DOUBLE: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.D[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.D[jj * xsize + ii]; + } + break; + + case _DATATYPE_COMPLEX_FLOAT: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.CF[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.CF[jj * xsize + ii]; + } + break; + + case _DATATYPE_COMPLEX_DOUBLE: + for (uint32_t ii = 0; ii < xsize; ii++) + for (uint32_t jj = 0; jj < ysize; jj++) + { + data.image[IDout].array.CD[jj * 2 * xsize + ii + Xoffset] = + data.image[IDin].array.CD[jj * xsize + ii]; + } + break; + + default: + printf("Unknown data type\n"); + exit(0); + break; } - if(FrameIndex == master) + if (FrameIndex == master) { - COREMOD_MEMORY_image_set_sempost_byID(IDout, -1);; + COREMOD_MEMORY_image_set_sempost_byID(IDout, -1); + ; data.image[IDout].md[0].cnt0++; } data.image[IDout].md[0].cnt1 = FrameIndex; data.image[IDout].md[0].write = 0; - if(FrameIndex == 0) + if (FrameIndex == 0) { FrameIndex = 1; } @@ -317,7 +275,3 @@ imageID COREMOD_MEMORY_streamPaste( return IDout; } - - - - diff --git a/src/COREMOD_memory/stream_paste.h b/src/COREMOD_memory/stream_paste.h index d6ec7ac1..2b3eb63a 100644 --- a/src/COREMOD_memory/stream_paste.h +++ b/src/COREMOD_memory/stream_paste.h @@ -1,16 +1,8 @@ -/** +/** * @file stream_paste.h */ - errno_t stream_paste_addCLIcmd(); - -imageID COREMOD_MEMORY_streamPaste( - const char *IDstream0_name, - const char *IDstream1_name, - const char *IDstreamout_name, - long semtrig0, - long semtrig1, - int master -); +imageID COREMOD_MEMORY_streamPaste(const char *IDstream0_name, const char *IDstream1_name, const char *IDstreamout_name, + long semtrig0, long semtrig1, int master); diff --git a/src/COREMOD_memory/stream_pixmapdecode.c b/src/COREMOD_memory/stream_pixmapdecode.c index aae85138..14d6db8d 100644 --- a/src/COREMOD_memory/stream_pixmapdecode.c +++ b/src/COREMOD_memory/stream_pixmapdecode.c @@ -1,67 +1,37 @@ /** @file stream_pixmapdecode.c */ - #include "CommandLineInterface/CLIcore.h" -#include "image_ID.h" -#include "stream_sem.h" #include "create_image.h" #include "delete_image.h" - +#include "image_ID.h" +#include "stream_sem.h" #include "COREMOD_iofits/COREMOD_iofits.h" - - - - - - // ========================================== // Forward declaration(s) // ========================================== -imageID COREMOD_MEMORY_PixMapDecode_U( - const char *inputstream_name, - uint32_t xsizeim, - uint32_t ysizeim, - const char *NBpix_fname, - const char *IDmap_name, - const char *IDout_name, - const char *IDout_pixslice_fname, - uint32_t reverse -); - - +imageID COREMOD_MEMORY_PixMapDecode_U(const char *inputstream_name, uint32_t xsizeim, uint32_t ysizeim, + const char *NBpix_fname, const char *IDmap_name, const char *IDout_name, + const char *IDout_pixslice_fname, uint32_t reverse); // ========================================== // Command line interface wrapper function(s) // ========================================== - static errno_t COREMOD_MEMORY_PixMapDecode_U__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_LONG) - + CLI_checkarg(3, CLIARG_LONG) - + CLI_checkarg(4, CLIARG_STR_NOT_IMG) - + CLI_checkarg(5, CLIARG_IMG) - + CLI_checkarg(6, CLIARG_STR_NOT_IMG) - + CLI_checkarg(7, CLIARG_STR_NOT_IMG) - + CLI_checkarg(8, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_LONG) + CLI_checkarg(3, CLIARG_LONG) + + CLI_checkarg(4, CLIARG_STR_NOT_IMG) + CLI_checkarg(5, CLIARG_IMG) + CLI_checkarg(6, CLIARG_STR_NOT_IMG) + + CLI_checkarg(7, CLIARG_STR_NOT_IMG) + CLI_checkarg(8, CLIARG_LONG) == + 0) { - COREMOD_MEMORY_PixMapDecode_U( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numl, - data.cmdargtoken[3].val.numl, - data.cmdargtoken[4].val.string, - data.cmdargtoken[5].val.string, - data.cmdargtoken[6].val.string, - data.cmdargtoken[7].val.string, - data.cmdargtoken[8].val.numl - ); + COREMOD_MEMORY_PixMapDecode_U(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl, + data.cmdargtoken[3].val.numl, data.cmdargtoken[4].val.string, + data.cmdargtoken[5].val.string, data.cmdargtoken[6].val.string, + data.cmdargtoken[7].val.string, data.cmdargtoken[8].val.numl); return CLICMD_SUCCESS; } else @@ -70,71 +40,48 @@ static errno_t COREMOD_MEMORY_PixMapDecode_U__cli() } } - - - - // ========================================== // Register CLI command(s) // ========================================== errno_t stream_pixmapdecode_addCLIcmd() { - RegisterCLIcommand( - "impixdecodeU", - __FILE__, - COREMOD_MEMORY_PixMapDecode_U__cli, - "decode image stream", - " ", - "impixdecodeU streamin 120 120 pixsclienb.txt decmap outim outsliceindex.fits 0", - "COREMOD_MEMORY_PixMapDecode_U(const char *inputstream_name, uint32_t xsizeim, uint32_t ysizeim, const char* NBpix_fname, const char* IDmap_name, const char *IDout_name, const char *IDout_pixslice_fname, uint32_t reverse)"); - + RegisterCLIcommand("impixdecodeU", __FILE__, COREMOD_MEMORY_PixMapDecode_U__cli, "decode image stream", + " ", + "impixdecodeU streamin 120 120 pixsclienb.txt decmap outim outsliceindex.fits 0", + "COREMOD_MEMORY_PixMapDecode_U(const char *inputstream_name, uint32_t xsizeim, uint32_t " + "ysizeim, const char* NBpix_fname, const char* IDmap_name, const char *IDout_name, const char " + "*IDout_pixslice_fname, uint32_t reverse)"); return RETURN_SUCCESS; } - - - - - - - - - - // // pixel decode for unsigned short // sem0, cnt0 gets updated at each full frame // sem1 gets updated for each slice // cnt1 contains the slice index that was just written // -imageID COREMOD_MEMORY_PixMapDecode_U( - const char *inputstream_name, - uint32_t xsizeim, - uint32_t ysizeim, - const char *NBpix_fname, - const char *IDmap_name, - const char *IDout_name, - const char *IDout_pixslice_fname, - uint32_t reverse -) +imageID COREMOD_MEMORY_PixMapDecode_U(const char *inputstream_name, uint32_t xsizeim, uint32_t ysizeim, + const char *NBpix_fname, const char *IDmap_name, const char *IDout_name, + const char *IDout_pixslice_fname, uint32_t reverse) { - imageID IDout = -1; - imageID IDin; - imageID IDmap; - long slice, sliceii; - long oldslice = 0; - long NBslice; - long *nbpixslice; - uint32_t xsizein; - uint32_t ysizein; - uint32_t nbpixout = xsizeim * ysizeim; - FILE *fp; + imageID IDout = -1; + imageID IDin; + imageID IDmap; + long slice, sliceii; + long oldslice = 0; + long NBslice; + long *nbpixslice; + uint32_t xsizein; + uint32_t ysizein; + uint32_t nbpixout = xsizeim * ysizeim; + FILE *fp; uint32_t *sizearray; - imageID IDout_pixslice; - long ii; - unsigned long long cnt = 0; + imageID IDout_pixslice; + long ii; + unsigned long long cnt = 0; // int RT_priority = 80; //any number from 0-99 // struct sched_param schedpar; @@ -148,8 +95,7 @@ imageID COREMOD_MEMORY_PixMapDecode_U( double *dtarray; struct timespec *tarray; -// long slice1; - + // long slice1; PROCESSINFO *processinfo; @@ -162,7 +108,7 @@ imageID COREMOD_MEMORY_PixMapDecode_U( xsizein = data.image[IDin].md[0].size[0]; ysizein = data.image[IDin].md[0].size[1]; - if(data.image[IDin].md[0].naxis > 2) + if (data.image[IDin].md[0].naxis > 2) { NBslice = data.image[IDin].md[0].size[2]; } @@ -171,32 +117,28 @@ imageID COREMOD_MEMORY_PixMapDecode_U( NBslice = 1; } - char pinfoname[200]; // short name for the processinfo instance + char pinfoname[200]; // short name for the processinfo instance sprintf(pinfoname, "decode-%s-to-%s", inputstream_name, IDout_name); char pinfodescr[200]; - sprintf(pinfodescr, "%ldx%ldx%ld->%ldx%ld", (long) xsizein, (long) ysizein, - NBslice, (long) xsizeim, (long) ysizeim); + sprintf(pinfodescr, "%ldx%ldx%ld->%ldx%ld", (long)xsizein, (long)ysizein, NBslice, (long)xsizeim, (long)ysizeim); char msgstring[200]; sprintf(msgstring, "%s->%s", inputstream_name, IDout_name); processinfo = processinfo_setup( - pinfoname, // short name for the processinfo instance, no spaces, no dot, name should be human-readable - pinfodescr, // description - msgstring, // message on startup - __FUNCTION__, __FILE__, __LINE__ - ); + pinfoname, // short name for the processinfo instance, no spaces, no dot, name should be human-readable + pinfodescr, // description + msgstring, // message on startup + __FUNCTION__, __FILE__, __LINE__); // OPTIONAL SETTINGS processinfo->MeasureTiming = 1; // Measure timing - processinfo->RT_priority = - 20; // RT_priority, 0-99. Larger number = higher priority. If <0, ignore - + processinfo->RT_priority = 20; // RT_priority, 0-99. Larger number = higher priority. If <0, ignore int loopOK = 1; processinfo_WriteMessage(processinfo, "Allocating memory"); - sizearray = (uint32_t *) malloc(sizeof(uint32_t) * 3); - if(sizearray == NULL) + sizearray = (uint32_t *)malloc(sizeof(uint32_t) * 3); + if (sizearray == NULL) { PRINT_ERROR("malloc error"); abort(); @@ -204,35 +146,30 @@ imageID COREMOD_MEMORY_PixMapDecode_U( int in_semwaitindex = ImageStreamIO_getsemwaitindex(&data.image[IDin], 0); - if(reverse == 0 && (xsizein != data.image[IDmap].md[0].size[0] - || ysizein != data.image[IDmap].md[0].size[1])) + if (reverse == 0 && (xsizein != data.image[IDmap].md[0].size[0] || ysizein != data.image[IDmap].md[0].size[1])) { - printf("ERROR: xsize, ysize for %s (%d, %d) does not match %s (%d, %d)\n", - inputstream_name, xsizein, ysizein, IDmap_name, data.image[IDmap].md[0].size[0], - data.image[IDmap].md[0].size[0]); + printf("ERROR: xsize, ysize for %s (%d, %d) does not match %s (%d, %d)\n", inputstream_name, xsizein, ysizein, + IDmap_name, data.image[IDmap].md[0].size[0], data.image[IDmap].md[0].size[0]); exit(0); } - if(reverse == 1 && (xsizeim != data.image[IDmap].md[0].size[0] - || ysizeim != data.image[IDmap].md[0].size[1])) + if (reverse == 1 && (xsizeim != data.image[IDmap].md[0].size[0] || ysizeim != data.image[IDmap].md[0].size[1])) { - printf("ERROR: xsize, ysize for %s (%d, %d) does not match %s (%d, %d)\n", - IDout_name, xsizein, ysizein, IDmap_name, data.image[IDmap].md[0].size[0], - data.image[IDmap].md[0].size[0]); + printf("ERROR: xsize, ysize for %s (%d, %d) does not match %s (%d, %d)\n", IDout_name, xsizein, ysizein, + IDmap_name, data.image[IDmap].md[0].size[0], data.image[IDmap].md[0].size[0]); exit(0); } - if(NBslice > 1 && reverse == 1) + if (NBslice > 1 && reverse == 1) { printf("ERROR: Cannot use reverse lookup decode with multiple slices\n"); } sizearray[0] = xsizeim; sizearray[1] = ysizeim; - create_image_ID(IDout_name, 2, sizearray, - data.image[IDin].md[0].datatype, 1, 25, 0, &IDout); + create_image_ID(IDout_name, 2, sizearray, data.image[IDin].md[0].datatype, 1, 25, 0, &IDout); // Copy the keywords over from IDin to IDout int NBkw = data.image[IDin].md[0].NBkw; - for(int kw = 0; kw < NBkw; ++kw) + for (int kw = 0; kw < NBkw; ++kw) { strcpy(data.image[IDout].kw[kw].name, data.image[IDin].kw[kw].name); data.image[IDout].kw[kw].type = data.image[IDin].kw[kw].type; @@ -240,85 +177,75 @@ imageID COREMOD_MEMORY_PixMapDecode_U( strcpy(data.image[IDout].kw[kw].comment, data.image[IDin].kw[kw].comment); } - - COREMOD_MEMORY_image_set_createsem(IDout_name, IMAGE_NB_SEMAPHORE); - dtarray = (double *) malloc(sizeof(double) * NBslice); - if(dtarray == NULL) + dtarray = (double *)malloc(sizeof(double) * NBslice); + if (dtarray == NULL) { PRINT_ERROR("malloc error"); abort(); } - tarray = (struct timespec *) malloc(sizeof(struct timespec) * NBslice); - if(tarray == NULL) + tarray = (struct timespec *)malloc(sizeof(struct timespec) * NBslice); + if (tarray == NULL) { PRINT_ERROR("malloc error"); abort(); } - - nbpixslice = (long *) malloc(sizeof(long) * NBslice); - if(nbpixslice == NULL) + nbpixslice = (long *)malloc(sizeof(long) * NBslice); + if (nbpixslice == NULL) { PRINT_ERROR("malloc error"); abort(); } - if((fp = fopen(NBpix_fname, "r")) == NULL) + if ((fp = fopen(NBpix_fname, "r")) == NULL) { printf("ERROR : cannot open file \"%s\"\n", NBpix_fname); exit(0); } - for(slice = 0; slice < NBslice; slice++) + for (slice = 0; slice < NBslice; slice++) { int fscanfcnt = fscanf(fp, "%ld %ld %ld\n", &tmpl0, &nbpixslice[slice], &tmpl1); - if(fscanfcnt == EOF) + if (fscanfcnt == EOF) { - if(ferror(fp)) + if (ferror(fp)) { perror("fscanf"); } else { - fprintf(stderr, - "Error: fscanf reached end of file, no matching characters, no matching failure\n"); + fprintf(stderr, "Error: fscanf reached end of file, no matching characters, no matching failure\n"); } return RETURN_FAILURE; } - else if(fscanfcnt != 3) + else if (fscanfcnt != 3) { - fprintf(stderr, - "Error: fscanf successfully matched and assigned %i input items, 2 expected\n", - fscanfcnt); + fprintf(stderr, "Error: fscanf successfully matched and assigned %i input items, 2 expected\n", fscanfcnt); return RETURN_FAILURE; } - - } fclose(fp); - for(slice = 0; slice < NBslice; slice++) + for (slice = 0; slice < NBslice; slice++) { printf("Slice %5ld : %5ld pix\n", slice, nbpixslice[slice]); } - if(reverse == 0) // Only for legacy mode + if (reverse == 0) // Only for legacy mode { - create_image_ID("outpixsl", 2, sizearray, _DATATYPE_UINT16, 0, - 0, 0, &IDout_pixslice); + create_image_ID("outpixsl", 2, sizearray, _DATATYPE_UINT16, 0, 0, 0, &IDout_pixslice); - for(slice = 0; slice < NBslice; slice++) + for (slice = 0; slice < NBslice; slice++) { - sliceii = slice * data.image[IDmap].md[0].size[0] * - data.image[IDmap].md[0].size[1]; - for(ii = 0; ii < nbpixslice[slice]; ii++) + sliceii = slice * data.image[IDmap].md[0].size[0] * data.image[IDmap].md[0].size[1]; + for (ii = 0; ii < nbpixslice[slice]; ii++) { // ocam2kpixi files MUST now be in int32 - otherwise we'll overflow in 240x240 - data.image[IDout_pixslice].array.UI16[ data.image[IDmap].array.UI32[sliceii + - ii] ] = (unsigned short)(1 + slice); + data.image[IDout_pixslice].array.UI16[data.image[IDmap].array.UI32[sliceii + ii]] = + (unsigned short)(1 + slice); } } @@ -326,27 +253,21 @@ imageID COREMOD_MEMORY_PixMapDecode_U( delete_image_ID("outpixsl", DELETE_IMAGE_ERRMODE_WARNING); } - - - - processinfo_WriteMessage(processinfo, "Starting loop"); // ================================== // STARTING LOOP // ================================== - processinfo_loopstart( - processinfo); // Notify processinfo that we are entering loop - + processinfo_loopstart(processinfo); // Notify processinfo that we are entering loop // long loopcnt = 0; - while(loopOK == 1) + while (loopOK == 1) { loopOK = processinfo_loopstep(processinfo); - if(data.image[IDin].md[0].sem == 0) + if (data.image[IDin].md[0].sem == 0) { - while(data.image[IDin].md[0].cnt0 == cnt) // test if new frame exists + while (data.image[IDin].md[0].cnt0 == cnt) // test if new frame exists { usleep(5); } @@ -354,7 +275,7 @@ imageID COREMOD_MEMORY_PixMapDecode_U( } else { - if(clock_gettime(CLOCK_REALTIME, &ts) == -1) + if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { perror("clock_gettime"); exit(EXIT_FAILURE); @@ -363,10 +284,10 @@ imageID COREMOD_MEMORY_PixMapDecode_U( semr = ImageStreamIO_semtimedwait(&data.image[IDin], in_semwaitindex, &ts); - if(processinfo->loopcnt == 0) + if (processinfo->loopcnt == 0) { sem_getvalue(data.image[IDin].semptr[in_semwaitindex], &semval); - for(scnt = 0; scnt < semval; scnt++) + for (scnt = 0; scnt < semval; scnt++) { sem_trywait(data.image[IDin].semptr[in_semwaitindex]); } @@ -375,17 +296,17 @@ imageID COREMOD_MEMORY_PixMapDecode_U( processinfo_exec_start(processinfo); - if(processinfo_compute_status(processinfo) == 1) + if (processinfo_compute_status(processinfo) == 1) { - if(semr == 0) + if (semr == 0) { slice = data.image[IDin].md[0].cnt1; - if(slice > oldslice + 1) + if (slice > oldslice + 1) { slice = oldslice + 1; } - if(oldslice == NBslice - 1) + if (oldslice == NBslice - 1) { slice = 0; } @@ -394,22 +315,21 @@ imageID COREMOD_MEMORY_PixMapDecode_U( // dtarray[slice] = 1.0*tarray[slice].tv_sec + 1.0e-9*tarray[slice].tv_nsec; data.image[IDout].md[0].write = 1; - if(reverse == 0) // legacy forward lookup mode + if (reverse == 0) // legacy forward lookup mode { - if(slice < NBslice) + if (slice < NBslice) { - sliceii = slice * data.image[IDmap].md[0].size[0] * - data.image[IDmap].md[0].size[1]; - for(ii = 0; ii < nbpixslice[slice]; ii++) + sliceii = slice * data.image[IDmap].md[0].size[0] * data.image[IDmap].md[0].size[1]; + for (ii = 0; ii < nbpixslice[slice]; ii++) { - data.image[IDout].array.UI16[data.image[IDmap].array.UI32[sliceii + ii] ] = + data.image[IDout].array.UI16[data.image[IDmap].array.UI32[sliceii + ii]] = data.image[IDin].array.UI16[sliceii + ii]; } } } - else // reverse == 1, full image assumed (at least given how ocam is scrambled) + else // reverse == 1, full image assumed (at least given how ocam is scrambled) { - for(ii = 0; ii < nbpixout; ++ii) + for (ii = 0; ii < nbpixout; ++ii) { data.image[IDout].array.UI16[ii] = data.image[IDin].array.UI16[data.image[IDmap].array.UI32[ii]]; @@ -417,27 +337,27 @@ imageID COREMOD_MEMORY_PixMapDecode_U( } // Copy the value of the keywords - for(int kw = 0; kw < NBkw; ++kw) + for (int kw = 0; kw < NBkw; ++kw) { data.image[IDout].kw[kw].value = data.image[IDin].kw[kw].value; } - if(slice == NBslice - 1) + if (slice == NBslice - 1) { COREMOD_MEMORY_image_set_sempost_byID(IDout, -1); - data.image[IDout].md[0].cnt0 ++; + data.image[IDout].md[0].cnt0++; } data.image[IDout].md[0].cnt1 = slice; sem_getvalue(data.image[IDout].semptr[2], &semval); - if(semval < SEMAPHORE_MAXVAL) + if (semval < SEMAPHORE_MAXVAL) { sem_post(data.image[IDout].semptr[2]); } sem_getvalue(data.image[IDout].semptr[3], &semval); - if(semval < SEMAPHORE_MAXVAL) + if (semval < SEMAPHORE_MAXVAL) { sem_post(data.image[IDout].semptr[3]); } @@ -448,7 +368,6 @@ imageID COREMOD_MEMORY_PixMapDecode_U( } } - processinfo_exec_end(processinfo); } @@ -468,8 +387,3 @@ imageID COREMOD_MEMORY_PixMapDecode_U( return IDout; } - - - - - diff --git a/src/COREMOD_memory/stream_pixmapdecode.h b/src/COREMOD_memory/stream_pixmapdecode.h index dde1549b..ca957502 100644 --- a/src/COREMOD_memory/stream_pixmapdecode.h +++ b/src/COREMOD_memory/stream_pixmapdecode.h @@ -1,17 +1,8 @@ /** @file stream_pixmapdecode.h */ - errno_t stream_pixmapdecode_addCLIcmd(); - -imageID COREMOD_MEMORY_PixMapDecode_U( - const char *inputstream_name, - uint32_t xsizeim, - uint32_t ysizeim, - const char *NBpix_fname, - const char *IDmap_name, - const char *IDout_name, - const char *IDout_pixslice_fname, - uint32_t reverse -); +imageID COREMOD_MEMORY_PixMapDecode_U(const char *inputstream_name, uint32_t xsizeim, uint32_t ysizeim, + const char *NBpix_fname, const char *IDmap_name, const char *IDout_name, + const char *IDout_pixslice_fname, uint32_t reverse); diff --git a/src/COREMOD_memory/stream_poke.c b/src/COREMOD_memory/stream_poke.c index 20c2b594..917069e3 100644 --- a/src/COREMOD_memory/stream_poke.c +++ b/src/COREMOD_memory/stream_poke.c @@ -3,8 +3,6 @@ * @brief poke image stream */ - - #include "CommandLineInterface/CLIcore.h" #include "CommandLineInterface/timeutils.h" @@ -13,41 +11,16 @@ #include "COREMOD_tools/COREMOD_tools.h" - - - - // variables local to this translation unit static char *inimname; +static CLICMDARGDEF farg[] = { + {CLIARG_IMG, ".in_sname", "input stream", "ims1", CLIARG_VISIBLE_DEFAULT, (void **)&inimname, NULL}}; - - -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, ".in_sname", "input stream", "ims1", - CLIARG_VISIBLE_DEFAULT, - (void **) &inimname, NULL - } -}; - -static CLICMDDATA CLIcmddata = -{ - "shmimpoke", - "update stream without changing content", - CLICMD_FIELDS_DEFAULTS -}; - +static CLICMDDATA CLIcmddata = {"shmimpoke", "update stream without changing content", CLICMD_FIELDS_DEFAULTS}; // detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - - - +static errno_t help_function() { return RETURN_SUCCESS; } // Wrapper function, used by all CLI calls static errno_t compute_function() @@ -65,13 +38,11 @@ static errno_t compute_function() return RETURN_SUCCESS; } - - - INSERT_STD_FPSCLIfunctions -// Register function in CLI -errno_t CLIADDCMD_COREMOD_memory__stream_poke() + // Register function in CLI + errno_t + CLIADDCMD_COREMOD_memory__stream_poke() { INSERT_STD_CLIREGISTERFUNC diff --git a/src/COREMOD_memory/stream_poke.h b/src/COREMOD_memory/stream_poke.h index 8c28bfac..036630df 100644 --- a/src/COREMOD_memory/stream_poke.h +++ b/src/COREMOD_memory/stream_poke.h @@ -17,4 +17,4 @@ imageID COREMOD_MEMORY_streamPoke( errno_t CLIADDCMD_COREMOD_memory__stream_poke(); -#endif \ No newline at end of file +#endif diff --git a/src/COREMOD_memory/stream_sem.c b/src/COREMOD_memory/stream_sem.c index 558c39b6..55c98ab1 100644 --- a/src/COREMOD_memory/stream_sem.c +++ b/src/COREMOD_memory/stream_sem.c @@ -3,7 +3,6 @@ * @brief stream semaphores */ - #include #include "CommandLineInterface/CLIcore.h" @@ -11,93 +10,44 @@ #include "list_image.h" #include "read_shmim.h" - - - static pthread_t *thrarray_semwait; static long NB_thrarray_semwait; - - - // ========================================== // Forward declaration(s) // ========================================== +imageID COREMOD_MEMORY_image_set_createsem(const char *IDname, long NBsem); -imageID COREMOD_MEMORY_image_set_createsem( - const char *IDname, - long NBsem -); - - -imageID COREMOD_MEMORY_image_seminfo( - const char *IDname -); +imageID COREMOD_MEMORY_image_seminfo(const char *IDname); -imageID COREMOD_MEMORY_image_set_sempost( - const char *IDname, - long index -); +imageID COREMOD_MEMORY_image_set_sempost(const char *IDname, long index); -imageID COREMOD_MEMORY_image_set_sempost_byID( - imageID ID, - long index -); +imageID COREMOD_MEMORY_image_set_sempost_byID(imageID ID, long index); -imageID COREMOD_MEMORY_image_set_sempost_excl_byID( - imageID ID, - long index -); +imageID COREMOD_MEMORY_image_set_sempost_excl_byID(imageID ID, long index); -imageID COREMOD_MEMORY_image_set_sempost_loop( - const char *IDname, - long index, - long dtus -); +imageID COREMOD_MEMORY_image_set_sempost_loop(const char *IDname, long index, long dtus); -imageID COREMOD_MEMORY_image_set_semwait( - const char *IDname, - long index -); +imageID COREMOD_MEMORY_image_set_semwait(const char *IDname, long index); -void *waitforsemID( - void *ID -); +void *waitforsemID(void *ID); -errno_t COREMOD_MEMORY_image_set_semwait_OR_IDarray( - imageID *IDarray, - long NB_ID -); - -errno_t COREMOD_MEMORY_image_set_semflush_IDarray( - imageID *IDarray, - long NB_ID -); - -imageID COREMOD_MEMORY_image_set_semflush( - const char *IDname, - long index -); +errno_t COREMOD_MEMORY_image_set_semwait_OR_IDarray(imageID *IDarray, long NB_ID); +errno_t COREMOD_MEMORY_image_set_semflush_IDarray(imageID *IDarray, long NB_ID); +imageID COREMOD_MEMORY_image_set_semflush(const char *IDname, long index); // ========================================== // Command line interface wrapper function(s) // ========================================== - static errno_t COREMOD_MEMORY_image_set_createsem__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { - COREMOD_MEMORY_image_set_createsem( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numl - ); + COREMOD_MEMORY_image_set_createsem(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl); return CLICMD_SUCCESS; } else @@ -106,11 +56,9 @@ static errno_t COREMOD_MEMORY_image_set_createsem__cli() } } - static errno_t COREMOD_MEMORY_image_seminfo__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) == 0) { COREMOD_MEMORY_image_seminfo(data.cmdargtoken[1].val.string); return CLICMD_SUCCESS; @@ -121,18 +69,11 @@ static errno_t COREMOD_MEMORY_image_seminfo__cli() } } - static errno_t COREMOD_MEMORY_image_set_sempost__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { - COREMOD_MEMORY_image_set_sempost( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numl - ); + COREMOD_MEMORY_image_set_sempost(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl); return CLICMD_SUCCESS; } else @@ -141,20 +82,12 @@ static errno_t COREMOD_MEMORY_image_set_sempost__cli() } } - static errno_t COREMOD_MEMORY_image_set_sempost_loop__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_LONG) - + CLI_checkarg(3, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_LONG) + CLI_checkarg(3, CLIARG_LONG) == 0) { - COREMOD_MEMORY_image_set_sempost_loop( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numl, - data.cmdargtoken[3].val.numl - ); + COREMOD_MEMORY_image_set_sempost_loop(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl, + data.cmdargtoken[3].val.numl); return CLICMD_SUCCESS; } else @@ -163,18 +96,11 @@ static errno_t COREMOD_MEMORY_image_set_sempost_loop__cli() } } - - static errno_t COREMOD_MEMORY_image_set_semwait__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { - COREMOD_MEMORY_image_set_semwait( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numl); + COREMOD_MEMORY_image_set_semwait(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl); return CLICMD_SUCCESS; } else @@ -183,18 +109,11 @@ static errno_t COREMOD_MEMORY_image_set_semwait__cli() } } - static errno_t COREMOD_MEMORY_image_set_semflush__cli() { - if(0 - + CLI_checkarg(1, CLIARG_IMG) - + CLI_checkarg(2, CLIARG_LONG) - == 0) + if (0 + CLI_checkarg(1, CLIARG_IMG) + CLI_checkarg(2, CLIARG_LONG) == 0) { - COREMOD_MEMORY_image_set_semflush( - data.cmdargtoken[1].val.string, - data.cmdargtoken[2].val.numl - ); + COREMOD_MEMORY_image_set_semflush(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl); return CLICMD_SUCCESS; } else @@ -203,97 +122,49 @@ static errno_t COREMOD_MEMORY_image_set_semflush__cli() } } - - - // ========================================== // Register CLI command(s) // ========================================== errno_t stream_sem_addCLIcmd() { - RegisterCLIcommand( - "imsetcreatesem", - __FILE__, - COREMOD_MEMORY_image_set_createsem__cli, - "create image semaphore", - " ", - "imsetcreatesem im1 5", - "long COREMOD_MEMORY_image_set_createsem(const char *IDname, long NBsem)"); - - RegisterCLIcommand( - "imseminfo", - __FILE__, - COREMOD_MEMORY_image_seminfo__cli, - "display semaphore info", - "", - "imseminfo im1", - "long COREMOD_MEMORY_image_seminfo(const char *IDname)"); - - RegisterCLIcommand( - "imsetsempost", - __FILE__, - COREMOD_MEMORY_image_set_sempost__cli, - "post image semaphore. If sem index = -1, post all semaphores", - " ", - "imsetsempost im1 2", - "long COREMOD_MEMORY_image_set_sempost(const char *IDname, long index)"); - - RegisterCLIcommand( - "imsetsempostl", - __FILE__, - COREMOD_MEMORY_image_set_sempost_loop__cli, - "post image semaphore loop. If sem index = -1, post all semaphores", - "