Skip to content

Commit

Permalink
Merge pull request #2175 from AllenInstitute/bugfix/2175-ignore-case-…
Browse files Browse the repository at this point in the history
…for-analysis-function-parameter-names

Ignore case for analysis function parameter names
  • Loading branch information
t-b authored Jul 16, 2024
2 parents 2c474e9 + 4ad95bb commit aa4eb66
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
31 changes: 22 additions & 9 deletions Packages/MIES/MIES_AnalysisFunctionHelpers.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,19 @@ Function/S AFH_GetListOfAnalysisParamNames(params)
return list
End

/// @brief Check if the given analysis parameter is present
///
/// @param name parameter name
/// @param params serialized parameters, usually just #AnalysisFunction_V3.params
///
/// @ingroup AnalysisFunctionParameterHelpers
///
/// @return one if present, zero otherwise
Function AFH_IsParameterPresent(string name, string params)

return WhichListItem(name, AFH_GetListOfAnalysisParamNames(params), ";", 0, 0) >= 0
End

/// @brief Return the type of the user parameter
///
/// @param name parameter name
Expand Down Expand Up @@ -638,7 +651,7 @@ Function AFH_GetAnalysisParamNumerical(name, params, [defValue])

ASSERT(AFH_IsValidAnalysisParameter(name), "Name is not a legal non-liberal igor object name")

if(WhichListItem(name, AFH_GetListOfAnalysisParamNames(params)) == -1)
if(!AFH_IsParameterPresent(name, params))
if(ParamIsDefault(defValue))
return NaN
endif
Expand Down Expand Up @@ -674,7 +687,7 @@ Function/S AFH_GetAnalysisParamTextual(name, params, [defValue, percentDecoded])
percentDecoded = !!percentDecoded
endif

if(WhichListItem(name, AFH_GetListOfAnalysisParamNames(params)) == -1)
if(!AFH_IsParameterPresent(name, params))
if(ParamIsDefault(defValue))
return ""
endif
Expand Down Expand Up @@ -709,7 +722,7 @@ Function/WAVE AFH_GetAnalysisParamWave(name, params, [defValue])

ASSERT(AFH_IsValidAnalysisParameter(name), "Name is not a legal non-liberal igor object name")

if(WhichListItem(name, AFH_GetListOfAnalysisParamNames(params)) == -1)
if(!AFH_IsParameterPresent(name, params))
if(ParamIsDefault(defValue))
return $""
endif
Expand Down Expand Up @@ -748,7 +761,7 @@ Function/WAVE AFH_GetAnalysisParamTextWave(name, params, [defValue, percentDecod
percentDecoded = !!percentDecoded
endif

if(WhichListItem(name, AFH_GetListOfAnalysisParamNames(params)) == -1)
if(!AFH_IsParameterPresent(name, params))
if(ParamIsDefault(defValue))
return $""
endif
Expand All @@ -761,7 +774,7 @@ Function/WAVE AFH_GetAnalysisParamTextWave(name, params, [defValue, percentDecod
WAVE/T wv = ListToTextWave(contents, "|")

if(percentDecoded)
wv = URLDecode(wv)
wv[] = URLDecode(wv[p])
return wv
endif

Expand All @@ -783,7 +796,7 @@ End
Function AFH_IsValidAnalysisParamType(type)
string type

return !IsEmpty(type) && WhichListItem(type, ANALYSIS_FUNCTION_PARAMS_TYPES) != -1
return !IsEmpty(type) && WhichListItem(type, ANALYSIS_FUNCTION_PARAMS_TYPES, ";", 0, 0) != -1
End

/// @brief Return an user parameter's value as string
Expand Down Expand Up @@ -863,14 +876,14 @@ Function/S AFH_CheckAnalysisParameter(string genericFunc, STRUCT CheckParameters
for(i = 0; i < numParams; i += 1)
name = StringFromList(i, allNames)

if(WhichListItem(name, presentNames) == -1)
if(WhichListItem(name, optNames) != -1)
if(WhichListItem(name, presentNames, ";", 0, 0) == -1)
if(WhichListItem(name, optNames, ";", 0, 0) != -1)
// non present optional parameters should not be checked
continue
endif

// non present required parameters are an error
if(WhichListItem(name, reqNames) != -1)
if(WhichListItem(name, reqNames, ";", 0, 0) != -1)
errorMessages[index++] = name + ": is required but missing"
continue
endif
Expand Down
15 changes: 8 additions & 7 deletions Packages/MIES/MIES_AnalysisFunctions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@
/// the `WPT` wave, see GetWaveBuilderWaveTextParam() for the exact format. See
/// TestAnalysisFunction_V3() for an example implementation.
///
/// If you want to propose a list of parameters which should/must be present, define
/// an additional function named like your analysis function but suffixed with
/// `_GetParams` and return a comma separated list of names. Adding the
/// type is also possible via `$name:$type` syntax. The list of parameter names and types
/// is then checked before DAQ. The supplied names are taken to be required by
/// default, optional parameters, and their types, must be enclosed with `[]`.
/// The list at #ANALYSIS_FUNCTION_PARAMS_TYPES holds all valid types.
/// If you want to propose a list of parameters which should/must be present,
/// define an additional function named like your analysis function but
/// suffixed with `_GetParams` and return a comma separated list of names.
/// Adding the type is also possible via `$name:$type` syntax. The list of
/// parameter names and types is then checked before DAQ. The supplied names
/// are taken to be required by default, optional parameters, and their types,
/// must be enclosed with `[]`. The list at #ANALYSIS_FUNCTION_PARAMS_TYPES
/// holds all valid types. Case does not matter for the parameter names.
///
/// The optional function `_CheckParam` allows you to validate passed
/// parameters. In case of a valid parameter it must return an emtpy string and
Expand Down
4 changes: 2 additions & 2 deletions Packages/MIES/MIES_DAEphys.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2853,7 +2853,7 @@ static Function DAP_CheckAnalysisFunctionAndParameter(device, setName)
reqNames = AFH_GetListOfAnalysisParamNames(reqNamesAndTypesFromFunc)
suppParams = WB_ExtractAnalysisFunctionParams(stimSet)
suppNames = AFH_GetListOfAnalysisParamNames(suppParams)
diff = GetListDifference(reqNames, suppNames)
diff = GetListDifference(reqNames, suppNames, caseSensitive = 0)
if(!IsEmpty(diff))
printf "(%s) The required analysis parameters requested by %s for stim set %s were not all supplied (missing are: %s)\r", device, func, setName, diff
ControlWindowToFront()
Expand All @@ -2877,7 +2877,7 @@ static Function DAP_CheckAnalysisFunctionAndParameter(device, setName)
endif

// invalid types are not allowed
if(WhichListItem(reqType, ANALYSIS_FUNCTION_PARAMS_TYPES) == -1)
if(WhichListItem(reqType, ANALYSIS_FUNCTION_PARAMS_TYPES, ";", 0, 0) == -1)
printf "(%s) The required analysis parameter %s for %s in stim set %s has type %s which is unknown.\r", device, reqName, func, setName, reqType
ControlWindowToFront()
return 1
Expand Down
10 changes: 10 additions & 0 deletions Packages/tests/Basic/UTF_AnalysisFunctionHelpers.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,16 @@ Function AGLAP_WorksWithType()
CHECK_EQUAL_STR(expected, actual)
End

Function AIPP_Works()

string params = "param1,param2:string"

CHECK(AFH_IsParameterPresent("param1", params))
CHECK(AFH_IsParameterPresent("param2", params))
CHECK(AFH_IsParameterPresent("Param2", params))
CHECK(!AFH_IsParameterPresent("param3", params))
End

/// END AFH_GetListOfAnalysisParams
/// @}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,8 @@ static Function AFT14_PreInit(device)
string device

string stimSet = "AnaFuncParams1_DA_0"
AFH_AddAnalysisParameter(stimSet, "MyVar", str = "abcd")
// use all lower case name for MyVar
AFH_AddAnalysisParameter(stimSet, "myvar", str = "abcd")
AFH_AddAnalysisParameter(stimSet, "MyStr", str = "abcd")
AFH_AddAnalysisParameter(stimSet, "MyWave", wv = {1, 2, 3})
Make/FREE/T textData = {"a", "b", "c"}
Expand Down

0 comments on commit aa4eb66

Please sign in to comment.