def data(self): self.assertEqual(m.Data(0x80000000).__class__, m.Int64) self.assertEqual(m.Data(0x7fffffff).__class__, m.Int32) if m.version.ispy2: self.assertEqual(m.Data(long(1)).__class__, m.Int64) a = m.ADD(m.Int32(1), m.Int32(2)) self.assertEqual(m.MULTIPLY(a, a).decompile(), "(1 + 2) * (1 + 2)") self.assertEqual(m.Data(2).compare(2), True) self.assertEqual(m.Data(2).compare(1), False) self.assertEqual( m.Dictionary([1, 'a', 2, 'b']).data().tolist(), { 1: 'a', 2: 'b' }) self.assertEqual( m.List([1, 'a', 2, 'b']).data().tolist(), [1, 'a', 2, 'b']) a = m.Apd() e = m.Data(1) e.tree = 'dummy_e' f = m.Data(2) f.tree = 'dummy_f' self.assertEqual(a.tree, None) a.append(e) # a should use tree of e self.assertEqual(a.tree, e.tree) self.assertEqual(a[0].tree, e.tree) a.append(f) # a should keep tree of e self.assertEqual(a.tree, e.tree) self.assertEqual(a[1].tree, f.tree) self._doUnaryArray(m.Int32(range(10)), m.Int32Array(range(10)), 'Int32(range(10))')
def getShotDB(expt, path=None, lower=None, upper=None): try: """ getShotDB("mytree") getShotDB("mytree",0) getShotDB("mytree","/my/local/tree/path") getShotDB("mytree","myserver::") getShotDB("mytree","myserver::/my/remote/tree/path") getShotDB("mytree",*,_from) getShotDB("mytree",*,*,_upto) getShotDB("mytree",*,_from,_upto) """ return MDSplus.Int32Array( MDSplus.Tree.getShotDB(expt, path, lower, upper)) except Exception: import traceback traceback.print_exc()
def tdiFunctions(self): m.dTRUE = m.__dict__['$TRUE'] m.dFALSE = m.__dict__['$FALSE'] from MDSplus import mdsExceptions as Exc """Test Exceptions""" self._doExceptionTest('abort()', Exc.TdiABORT) self._doExceptionTest('{,}', Exc.TdiSYNTAX) self._doExceptionTest('\033[[A', Exc.TdiBOMB) self._doExceptionTest('abs()', Exc.TdiMISS_ARG) self._doExceptionTest('abs("")', Exc.TdiINVDTYDSC) self._doExceptionTest('abs(1,2)', Exc.TdiEXTRA_ARG) self._doExceptionTest('"', Exc.TdiUNBALANCE) """Test $Missing/NoData/None""" self._doTdiTest('', None) """Test abs""" self._doThreeTest('abs(cmplx(3.0,4.0))', m.ABS(m.Complex64(3. + 4.j)), m.Float32(5.)) """Test abs1""" self._doThreeTest('abs1(cmplx(3.0,4.0))', m.ABS1(m.Complex64(3. + 4.j)), m.Float32(7.)) """Test abssq""" self._doThreeTest('abssq(cmplx(3.0,4.0))', m.ABSSQ(m.Complex64(3. + 4.j)), m.Float32(25.)) """Test accumulate""" self._doThreeTestArray('accumulate([1,2,3])', m.ACCUMULATE(m.makeArray([1, 2, 3])), m.Int32Array([1, 3, 6])) self._doThreeTestArray( 'accumulate([[1,3,5],[2,4,6]])', m.ACCUMULATE(m.makeArray([[1, 3, 5], [2, 4, 6]])), m.Int32Array([[1, 4, 9], [11, 15, 21]])) self._doThreeTestArray( 'accumulate([[1,3,5],[2,4,6]],0)', m.ACCUMULATE(m.makeArray([[1, 3, 5], [2, 4, 6]]), 0), m.Int32Array([[1, 4, 9], [2, 6, 12]])) #self._doThreeTestArray('accumulate([[1,3,5],[2,4,6]],1)',m.ACCUMULATE([[1,3,5],[2,4,6]],1),m.Int32Array([[1,3,5],[3,7,11]])) # tdi issue self._doUnaryArray( m.Data.execute('accumulate([[1,3,5],[2,4,6]],1)'), m.ACCUMULATE(m.makeArray([[1, 3, 5], [2, 4, 6]]), 1).getData()) """Test achar""" self._doThreeTest('achar(88)', m.ACHAR(88), m.String('X')) """Test ADJUSTL""" self._doThreeTest('adjustl(" WORD")', m.ADJUSTL(" WORD"), m.String("WORD ")) """Test ADJUSTR""" self._doThreeTest('adjustr("WORD ")', m.ADJUSTR("WORD "), m.String(" WORD")) """Test AIMAG""" self._doThreeTest('AIMAG(CMPLX(2.0,3.0))', m.AIMAG(m.CMPLX(2., 3.)), m.Float32(3.0)) """Test AINT""" self._doThreeTest('aint(2.783)', m.AINT(2.783), m.Float32(2.0)) self._doThreeTest('aint(-2.783)', m.AINT(-2.783), m.Float32(-2.0)) """Test NE (operates on flattened array, i.e. first 3 values are compared)""" A, B = m.makeArray([1, 3, 5]), m.makeArray([[0, 3, 5], [0, 0, 0], [0, 4, 8]]) self._doThreeTestArray( '_A=[1,3,5],_B=[[0,3,5],[0,0,0],[0,4,8]],_A ne _B', m.NE(A, B), m.Uint8Array([1, 0, 0])) """Test NE (operates on flattened array, i.e. first 3 values are compared)""" self._doThreeTestArray('_A eq _B', m.EQ(A, B), m.Uint8Array([0, 1, 1])) """Test ALL and ANY""" self._doThreeTest('all([$TRUE,$FALSE,$TRUE])', m.ALL(m.makeArray([1, 0, 1])), m.Uint8(0)) self._doThreeTest('any([$TRUE,$FALSE,$TRUE])', m.ANY(m.makeArray([1, 0, 1])), m.Uint8(1)) A = 0 self._doThreeTest('_A=0,all(_A eq _B)', m.ALL(m.EQ(A, B)), False) self._doThreeTest('any(_A ne _B)', m.ANY(m.NE(A, B)), True) self._doThreeTestArray('all(_A ne _B,0)', m.ALL(m.NE(A, B), 0), m.Uint8Array([0, 0, 0])) self._doThreeTestArray('any(_A ne _B,0)', m.ANY(m.NE(A, B), 0), m.Uint8Array([1, 0, 1])) self._doThreeTestArray('all(_A eq _B,1)', m.ALL(m.EQ(A, B), 1), m.Uint8Array([1, 0, 0])) self._doThreeTestArray('any(_A ne _B,1)', m.ANY(m.NE(A, B), 1), m.Uint8Array([0, 1, 1])) """Test allocated""" self.assertEqual(m.DEALLOCATE('*') >= 2, True) # deallocates _A and _B and more? self.assertEqual(m.ALLOCATED('_xyz'), m.Uint8(0)) self._doTdiTest('_xyz=0,allocated("_xyz")', m.Uint8(1)) self.assertEqual(m.ALLOCATED('_xyz'), m.Uint8(1)) self.assertEqual(m.DEALLOCATE('*'), m.Uint8(1)) self.assertEqual(m.ALLOCATED('_xyz'), m.Uint8(0)) """Test AND""" A, B = m.makeArray([0, 0, 1, 1]), m.makeArray([0, 1, 0, 1]) self._doThreeTestArray('_A=[0,0,1,1],_B=[0,1,0,1],_A && _B', m.AND(A, B), m.Uint8Array([0, 0, 0, 1])) """Test AND_NOT""" self._doThreeTestArray('_A AND_NOT _B', m.AND_NOT(A, B), m.Uint8Array([0, 0, 1, 0])) """Test ANINT""" self._doThreeTest('ANINT(2.783)', m.ANINT(2.783), m.Float32(3.0)) """Test ARG""" self._doTdiTest( 'execute("abs(arg(cmplx(3.0,4.0)) - .9272952) < .000001")', m.Uint8(1)) """Test ARGD""" self._doTdiTest( 'execute("abs(argd(cmplx(3.0,4.0)) - 53.1301) < .000001")', m.Uint8(1)) """Test arg_of""" self._doThreeTest('arg_of(pub->foo(42,43))', m.ARG_OF(m.Call('pub', 'foo', 42, 43)), m.Int32(42)) self._doThreeTest('arg_of(pub->foo(42,43),1)', m.ARG_OF(m.Call('pub', 'foo', 42, 43), 1), m.Int32(43)) self._doThreeTest('arg_of(1+3,1)', m.ARG_OF(m.ADD(1, 3), 1), m.Int32(3)) """Test Array""" self._doThreeTestArray('array(10)', m.ARRAY(10), m.Float32Array([0] * 10)) self._doThreeTestArray('array(10,0)', m.ARRAY(10, 0), m.Int32Array([0] * 10)) self._doThreeTestArray('array(10,0BU)', m.ARRAY(10, m.Uint8(0)), m.Uint8Array([0] * 10)) self._doThreeTestArray('zero(100)', m.ZERO(100), m.Float32Array([0] * 100))
def GetModelParameterData(ParameterStruct, numOfParameters): paramList = [] for paramIdx in range(numOfParameters): # name is retrieved retrievedName = WrapperLib.WCAPI_GetModelParameterName( ParameterStruct, paramIdx) retrievedName = retrievedName.decode("utf-8") # type is retrieved retrievedTypeIdx = WrapperLib.WCAPI_GetModelParameterDataTypeIdx( ParameterStruct, paramIdx) retrievedSLIdType = WrapperLib.WCAPI_GetDataTypeSLId( DataTypeMap, retrievedTypeIdx) retrievedCTypename = WrapperLib.WCAPI_GetDataTypeCName( DataTypeMap, retrievedTypeIdx) retrievedCTypename = retrievedCTypename.decode("utf-8") if retrievedSLIdType == 0: MARTe2Typename = 'float64' pythonTypename = ctypes.c_double elif retrievedSLIdType == 1: MARTe2Typename = 'float32' pythonTypename = ctypes.c_float elif retrievedSLIdType == 2: MARTe2Typename = 'int8' pythonTypename = ctypes.c_int8 elif retrievedSLIdType == 3: MARTe2Typename = 'uint8' pythonTypename = ctypes.c_uint8 elif retrievedSLIdType == 4: MARTe2Typename = 'int16' pythonTypename = ctypes.c_int16 elif retrievedSLIdType == 5: MARTe2Typename = 'uint16' pythonTypename = ctypes.c_uint16 elif retrievedSLIdType == 6: MARTe2Typename = 'int32' pythonTypename = ctypes.c_int32 elif retrievedSLIdType == 7: MARTe2Typename = 'uint32' pythonTypename = ctypes.c_uint32 elif retrievedSLIdType == 8: MARTe2Typename = 'bool' pythonTypename = ctypes.c_bool else: raise Exception('Unsupported parameter datatype.') # actual parameter value is retrieved paramAddrIdx = WrapperLib.WCAPI_GetModelParameterAddrIdx( ParameterStruct, paramIdx) paramDataAddr = WrapperLib.WCAPI_GetDataAddress( DataAddrMap, paramAddrIdx) paramPointer = ctypes.cast(paramDataAddr, ctypes.POINTER(pythonTypename)) # dimensions are retrieved dimIdx = WrapperLib.WCAPI_GetModelParameterDimensionIdx( ParameterStruct, paramIdx) dimArrayIdx = WrapperLib.WCAPI_GetDimArrayIndex( DimensionMap, dimIdx) # Starting position in the dimensionArray dimNum = WrapperLib.WCAPI_GetNumDims( DimensionMap, dimIdx ) # Number of elements in the dimensionArray referring to this signal currDimension = [] for currIdx in range(dimNum): currDimension.append(DimensionArray[dimArrayIdx + currIdx]) if currDimension[0] == 1 and currDimension[1] == 1: # scalar dimension = 0 mdsplusValue = paramPointer[0] elif currDimension[0] == 1: # vector dimension = currDimension[0] * currDimension[1] valueList = [] for idx in range(dimension): valueList.append(paramPointer[idx]) else: # matrix or column vector (MARTe2 sees column vectors as matrices) dimension = currDimension idx = 0 valueList = [] valueRow = [] for nRow in range(currDimension[0]): for nCol in range(currDimension[1]): valueRow.append(paramPointer[idx]) idx = idx + 1 valueList.append(valueRow) valueRow = [] if currDimension[0] != 1 or currDimension[1] != 1: if retrievedSLIdType == 0: mdsplusValue = MDSplus.Float32Array(valueList) elif retrievedSLIdType == 1: mdsplusValue = MDSplus.Float64Array(valueList) elif retrievedSLIdType == 2: mdsplusValue = MDSplus.Int8Array(valueList) elif retrievedSLIdType == 3: mdsplusValue = MDSplus.Uint8Array(valueList) elif retrievedSLIdType == 4: mdsplusValue = MDSplus.Int16Array(valueList) elif retrievedSLIdType == 5: mdsplusValue = MDSplus.Uint16Array(valueList) elif retrievedSLIdType == 6: mdsplusValue = MDSplus.Int32Array(valueList) elif retrievedSLIdType == 7: mdsplusValue = MDSplus.Uint32Array(valueList) else: raise Exception('Unsupported parameter datatype.') # retrieved data is saved to a dictionary paramDict = dict(name='Parameters.' + retrievedName, type=MARTe2Typename, dimensions=dimension, value=mdsplusValue) # dictionary is appended to the MDSplus-style list paramList.append(paramDict) return paramList
def getConfigurationFromSimulink(self): try: modelName = self.getNode('parameters.par_3:value').data() libraryName = modelName + '.so' ModelLib = ctypes.cdll.LoadLibrary(libraryName) except: raise Exception( 'Cannot retrieve shared library for the Simulink model ') initializeFuncName = modelName + '_initialize' # By default functions are assumed to return the C int type. # Other return types can be specified by setting the restype attribute. InstFunc = getattr(ModelLib, modelName) InstFunc.argtypes = [] InstFunc.restype = ctypes.POINTER(None) states = InstFunc() GetMmiPtr = getattr(ModelLib, modelName + '_GetCAPImmi') GetMmiPtr.argtypes = [ctypes.POINTER(None)] GetMmiPtr.restype = ctypes.POINTER(None) mmi = GetMmiPtr(states) # Initialization function is called with a dynamically-specified name InitializeFunc = getattr(ModelLib, initializeFuncName) InitializeFunc.argtypes = [ctypes.POINTER(None)] InitializeFunc(states) try: WrapperLib = ctypes.cdll.LoadLibrary("rtw_capi_wrapper.so") except: raise Exception( 'Cannot link to rtw_capi_wrapper.so, required to get information from ' + libraryName) # ** GENERAL MODEL DATA ** # Number of inputs WrapperLib.WCAPI_GetNumRootInputs.argtypes = [ctypes.POINTER(None)] WrapperLib.WCAPI_GetNumRootInputs.restype = ctypes.c_int numInputs = WrapperLib.WCAPI_GetNumRootInputs(mmi) if (numInputs > 8): raise Exception('Number ' + str(numInputs) + ' of inputs cannot be greater than 8') # Number of outputs WrapperLib.WCAPI_GetNumRootOutputs.argtypes = [ctypes.POINTER(None)] WrapperLib.WCAPI_GetNumRootOutputs.restype = ctypes.c_int numOutputs = WrapperLib.WCAPI_GetNumRootOutputs(mmi) if (numOutputs > 8): raise Exception('Number ' + str(numOutputs) + ' of outputs cannot be greater than 8') # Number of parameters WrapperLib.WCAPI_GetNumModelParameters.argtypes = [ ctypes.POINTER(None) ] WrapperLib.WCAPI_GetNumModelParameters.restype = ctypes.c_int numParameters = WrapperLib.WCAPI_GetNumModelParameters(mmi) if (numParameters > 8): raise Exception('Number ' + str(numParameters) + ' of parameters cannot be greater than 8') # Input structure WrapperLib.WCAPI_GetRootInputs.argtypes = [ctypes.POINTER(None)] WrapperLib.WCAPI_GetRootInputs.restype = ctypes.POINTER(None) RootInputStruct = WrapperLib.WCAPI_GetRootInputs(mmi) # Output structure WrapperLib.WCAPI_GetRootOutputs.argtypes = [ctypes.POINTER(None)] WrapperLib.WCAPI_GetRootOutputs.restype = ctypes.POINTER(None) RootOutputStruct = WrapperLib.WCAPI_GetRootOutputs(mmi) # Parameter structure WrapperLib.WCAPI_GetModelParameters.argtypes = [ctypes.POINTER(None)] WrapperLib.WCAPI_GetModelParameters.restype = ctypes.POINTER(None) ParameterStruct = WrapperLib.WCAPI_GetModelParameters(mmi) # DataType structure WrapperLib.WCAPI_GetDataTypeMap.argtypes = [ctypes.POINTER(None)] WrapperLib.WCAPI_GetDataTypeMap.restype = ctypes.POINTER(None) DataTypeMap = WrapperLib.WCAPI_GetDataTypeMap(mmi) # Dimension structure WrapperLib.WCAPI_GetDimensionMap.argtypes = [ctypes.POINTER(None)] WrapperLib.WCAPI_GetDimensionMap.restype = ctypes.POINTER(None) DimensionMap = WrapperLib.WCAPI_GetDimensionMap(mmi) # Dimension structure WrapperLib.WCAPI_GetDataAddressMap.argtypes = [ctypes.POINTER(None)] WrapperLib.WCAPI_GetDataAddressMap.restype = ctypes.POINTER( ctypes.POINTER(None)) DataAddrMap = WrapperLib.WCAPI_GetDataAddressMap(mmi) # Dimension array WrapperLib.WCAPI_GetDimensionArray.argtypes = [ctypes.POINTER(None)] WrapperLib.WCAPI_GetDimensionArray.restype = ctypes.POINTER( ctypes.c_uint) DimensionArray = WrapperLib.WCAPI_GetDimensionArray(mmi) # ** SIGNAL DATA ** # Functions are imported from the library: # 1. Name WrapperLib.WCAPI_GetSignalName.argtypes = [ ctypes.POINTER(None), ctypes.c_int ] WrapperLib.WCAPI_GetSignalName.restype = ctypes.c_char_p # 2. Type WrapperLib.WCAPI_GetSignalDataTypeIdx.argtypes = [ ctypes.POINTER(None), ctypes.c_int ] WrapperLib.WCAPI_GetSignalDataTypeIdx.restype = ctypes.c_uint WrapperLib.WCAPI_GetDataTypeSLId.argtypes = [ ctypes.POINTER(None), ctypes.c_int ] WrapperLib.WCAPI_GetDataTypeSLId.restype = ctypes.c_uint WrapperLib.WCAPI_GetDataTypeCName.argtypes = [ ctypes.POINTER(None), ctypes.c_int ] WrapperLib.WCAPI_GetDataTypeCName.restype = ctypes.c_char_p # 3. Dimensions WrapperLib.WCAPI_GetDimArrayIndex.argtypes = [ ctypes.POINTER(None), ctypes.c_int ] WrapperLib.WCAPI_GetDimArrayIndex.restype = ctypes.c_uint WrapperLib.WCAPI_GetNumDims.argtypes = [ ctypes.POINTER(None), ctypes.c_int ] WrapperLib.WCAPI_GetNumDims.restype = ctypes.c_uint WrapperLib.WCAPI_GetSignalDimensionIdx.argtypes = [ ctypes.POINTER(None), ctypes.c_int ] WrapperLib.WCAPI_GetSignalDimensionIdx.restype = ctypes.c_uint16 def removeAngular(strIn): if strIn[0] == '<': return strIn[1:-1] return strIn # Function to retrieve data on inputs and outputs def GetSignalData(SignalStruct, numOfSignals): signalList = [] for signalIdx in range(numOfSignals): # name is retrieved retrievedName = WrapperLib.WCAPI_GetSignalName( SignalStruct, signalIdx) retrievedName = retrievedName.decode("utf-8") retrievedName = removeAngular(retrievedName) # type is retrieved retrievedTypeIdx = WrapperLib.WCAPI_GetSignalDataTypeIdx( SignalStruct, signalIdx) retrievedSLIdType = WrapperLib.WCAPI_GetDataTypeSLId( DataTypeMap, retrievedTypeIdx) retrievedCTypename = WrapperLib.WCAPI_GetDataTypeCName( DataTypeMap, retrievedTypeIdx) retrievedCTypename = retrievedCTypename.decode("utf-8") if retrievedSLIdType == 0: MARTe2Typename = 'float64' elif retrievedSLIdType == 1: MARTe2Typename = 'float32' elif retrievedSLIdType == 2: MARTe2Typename = 'int8' elif retrievedSLIdType == 3: MARTe2Typename = 'uint8' elif retrievedSLIdType == 4: MARTe2Typename = 'int16' elif retrievedSLIdType == 5: MARTe2Typename = 'uint16' elif retrievedSLIdType == 6: MARTe2Typename = 'int32' elif retrievedSLIdType == 7: MARTe2Typename = 'uint32' elif retrievedSLIdType == 8: MARTe2Typename = 'bool' else: raise Exception('Unsupported datatype.') # dimensions are retrieved dimIdx = WrapperLib.WCAPI_GetSignalDimensionIdx( SignalStruct, signalIdx) dimArrayIdx = WrapperLib.WCAPI_GetDimArrayIndex( DimensionMap, dimIdx) # Starting position in the dimensionArray # Number of elements in the dimensionArray referring to this signal dimNum = WrapperLib.WCAPI_GetNumDims(DimensionMap, dimIdx) currDimension = [] for currIdx in range(dimNum): currDimension.append(DimensionArray[dimArrayIdx + currIdx]) if currDimension[0] == 1 and currDimension[1] == 1: dimension = 0 elif currDimension[0] == 1 or currDimension[1] == 1: dimension = [currDimension[0] * currDimension[1]] else: dimension = currDimension # retrieved data is saved to a dictionary signalDict = dict(name=retrievedName, type=MARTe2Typename, dimensions=dimension, parameters={}) # dictionary is appended to the MDSplus-style list signalList.append(signalDict) return signalList # ** PARAMETER DATA ** # Name WrapperLib.WCAPI_GetModelParameterName.argtypes = [ ctypes.POINTER(None), ctypes.c_int ] WrapperLib.WCAPI_GetModelParameterName.restype = ctypes.c_char_p # Type # same as the ones used for signals # Dimension WrapperLib.WCAPI_GetModelParameterDimensionIdx.argtypes = [ ctypes.POINTER(None), ctypes.c_int ] WrapperLib.WCAPI_GetModelParameterDimensionIdx.restype = ctypes.c_uint WrapperLib.WCAPI_GetModelParameterDataTypeIdx.argtypes = [ ctypes.POINTER(None), ctypes.c_int ] WrapperLib.WCAPI_GetModelParameterDataTypeIdx.restype = ctypes.c_uint # Value WrapperLib.WCAPI_GetModelParameterAddrIdx.argtypes = [ ctypes.POINTER(None), ctypes.c_int ] WrapperLib.WCAPI_GetModelParameterAddrIdx.restype = ctypes.c_uint WrapperLib.WCAPI_GetDataAddress.argtypes = [ ctypes.POINTER(ctypes.POINTER(None)), ctypes.c_int ] WrapperLib.WCAPI_GetDataAddress.restype = ctypes.c_void_p # Function to retrieve data on parameters def GetModelParameterData(ParameterStruct, numOfParameters): paramList = [] for paramIdx in range(numOfParameters): # name is retrieved retrievedName = WrapperLib.WCAPI_GetModelParameterName( ParameterStruct, paramIdx) retrievedName = retrievedName.decode("utf-8") # type is retrieved retrievedTypeIdx = WrapperLib.WCAPI_GetModelParameterDataTypeIdx( ParameterStruct, paramIdx) retrievedSLIdType = WrapperLib.WCAPI_GetDataTypeSLId( DataTypeMap, retrievedTypeIdx) retrievedCTypename = WrapperLib.WCAPI_GetDataTypeCName( DataTypeMap, retrievedTypeIdx) retrievedCTypename = retrievedCTypename.decode("utf-8") if retrievedSLIdType == 0: MARTe2Typename = 'float64' pythonTypename = ctypes.c_double elif retrievedSLIdType == 1: MARTe2Typename = 'float32' pythonTypename = ctypes.c_float elif retrievedSLIdType == 2: MARTe2Typename = 'int8' pythonTypename = ctypes.c_int8 elif retrievedSLIdType == 3: MARTe2Typename = 'uint8' pythonTypename = ctypes.c_uint8 elif retrievedSLIdType == 4: MARTe2Typename = 'int16' pythonTypename = ctypes.c_int16 elif retrievedSLIdType == 5: MARTe2Typename = 'uint16' pythonTypename = ctypes.c_uint16 elif retrievedSLIdType == 6: MARTe2Typename = 'int32' pythonTypename = ctypes.c_int32 elif retrievedSLIdType == 7: MARTe2Typename = 'uint32' pythonTypename = ctypes.c_uint32 elif retrievedSLIdType == 8: MARTe2Typename = 'bool' pythonTypename = ctypes.c_bool else: raise Exception('Unsupported parameter datatype.') # actual parameter value is retrieved paramAddrIdx = WrapperLib.WCAPI_GetModelParameterAddrIdx( ParameterStruct, paramIdx) paramDataAddr = WrapperLib.WCAPI_GetDataAddress( DataAddrMap, paramAddrIdx) paramPointer = ctypes.cast(paramDataAddr, ctypes.POINTER(pythonTypename)) # dimensions are retrieved dimIdx = WrapperLib.WCAPI_GetModelParameterDimensionIdx( ParameterStruct, paramIdx) dimArrayIdx = WrapperLib.WCAPI_GetDimArrayIndex( DimensionMap, dimIdx) # Starting position in the dimensionArray # Number of elements in the dimensionArray referring to this signal dimNum = WrapperLib.WCAPI_GetNumDims(DimensionMap, dimIdx) currDimension = [] for currIdx in range(dimNum): currDimension.append(DimensionArray[dimArrayIdx + currIdx]) if currDimension[0] == 1 and currDimension[1] == 1: # scalar dimension = 0 mdsplusValue = paramPointer[0] elif currDimension[0] == 1: # vector dimension = currDimension[0] * currDimension[1] valueList = [] for idx in range(dimension): valueList.append(paramPointer[idx]) else: # matrix or column vector (MARTe2 sees column vectors as matrices) dimension = currDimension idx = 0 valueList = [] valueRow = [] for nRow in range(currDimension[0]): if currDimension[1] == 1: valueList.append(paramPointer[idx]) idx = idx + 1 else: for nCol in range(currDimension[1]): valueRow.append(paramPointer[idx]) idx = idx + 1 valueList.append(valueRow) valueRow = [] # Transpose matrix if currDimension[0] > 1 and currDimension[1] > 1: transList = [] transRow = [] for nRow in range(currDimension[1]): for nCol in range(currDimension[0]): transRow.append( paramPointer[nCol * currDimension[1] + nRow]) transList.append(transRow) transRow = [] valueList = transList if currDimension[0] != 1 or currDimension[1] != 1: if retrievedSLIdType == 0: mdsplusValue = MDSplus.Float64Array(valueList) elif retrievedSLIdType == 1: mdsplusValue = MDSplus.Float32Array(valueList) elif retrievedSLIdType == 2: mdsplusValue = MDSplus.Int8Array(valueList) elif retrievedSLIdType == 3: mdsplusValue = MDSplus.Uint8Array(valueList) elif retrievedSLIdType == 4: mdsplusValue = MDSplus.Int16Array(valueList) elif retrievedSLIdType == 5: mdsplusValue = MDSplus.Uint16Array(valueList) elif retrievedSLIdType == 6: mdsplusValue = MDSplus.Int32Array(valueList) elif retrievedSLIdType == 7: mdsplusValue = MDSplus.Uint32Array(valueList) else: raise Exception('Unsupported parameter datatype.') # retrieved data is saved to a dictionary paramDict = dict(name='Parameters.' + retrievedName, type=MARTe2Typename, dimensions=dimension, value=mdsplusValue) # dictionary is appended to the MDSplus-style list paramList.append(paramDict) return paramList # Fill Parameters for i in range(8): self.getNode('parameters.par_' + str(i + 4) + ':name').deleteData() self.getNode('parameters.par_' + str(i + 4) + ':value').deleteData() self.getNode('inputs.in' + str(i + 1) + ':dimensions').deleteData() self.getNode('inputs.in' + str(i + 1) + ':name').deleteData() self.getNode('inputs.in' + str(i + 1) + ':type').putData('int32') self.getNode('outputs.out' + str(i + 1) + ':dimensions').putData(-1) self.getNode('outputs.out' + str(i + 1) + ':name').deleteData() self.getNode('outputs.out' + str(i + 1) + ':type').putData('int32') paramDicts = GetModelParameterData(ParameterStruct, numParameters) parIdx = 4 for paramDict in paramDicts: self.getNode('parameters.par_' + str(parIdx) + ':name').putData( paramDict['name']) self.getNode('parameters.par_' + str(parIdx) + ':value').putData( paramDict['value']) parIdx += 1 inputIdx = 1 inputDicts = GetSignalData(RootInputStruct, numInputs) for inputDict in inputDicts: self.getNode('inputs.in' + str(inputIdx) + ':name').putData( inputDict['name']) self.getNode('inputs.in' + str(inputIdx) + ':type').putData( inputDict['type']) inDim = inputDict['dimensions'] if inDim != 0: inDim = MDSplus.Int32Array(inDim) self.getNode('inputs.in' + str(inputIdx) + ':dimensions').putData(inDim) inputIdx += 1 outputIdx = 1 outputDicts = GetSignalData(RootOutputStruct, numOutputs) for outputDict in outputDicts: self.getNode('outputs.out' + str(outputIdx) + ':name').putData( outputDict['name']) self.getNode('outputs.out' + str(outputIdx) + ':type').putData( outputDict['type']) outDim = outputDict['dimensions'] if outDim != 0: outDim = MDSplus.Int32Array(outDim) self.getNode('outputs.out' + str(outputIdx) + ':dimensions').putData(outDim) outputIdx += 1
def GetModelParameterFields(structTypeIdx, ParameterStruct, paramIdx, baseParName, paramList, recLev ): if recLev == 10: raise Exception numFields = WrapperLib.WCAPI_GetDataTypeNumElements( DataTypeMap, structTypeIdx) elementMapIndex = WrapperLib.WCAPI_GetDataTypeElemMapIndex( DataTypeMap, structTypeIdx) # actual parameter value is retrieved paramAddrIdx = WrapperLib.WCAPI_GetModelParameterAddrIdx( ParameterStruct, paramIdx) paramDataAddr = WrapperLib.WCAPI_GetDataAddress( DataAddrMap, paramAddrIdx) #print('NUM FIELDS: '+str(numFields)) for fieldIdx in range(numFields): fieldName = WrapperLib.WCAPI_GetElementName( ElementMap, elementMapIndex + fieldIdx) fieldName = fieldName.decode("utf-8") #print('FIELD: '+baseParName+'-'+fieldName) fieldOffset = WrapperLib.WCAPI_GetElementOffset( ElementMap, elementMapIndex + fieldIdx) fieldTypeIdx = WrapperLib.WCAPI_GetElementDataTypeIdx( ElementMap, elementMapIndex + fieldIdx) #print('fieldTypeIdx: '+str(fieldTypeIdx)) fieldSLIdType = WrapperLib.WCAPI_GetDataTypeSLId( DataTypeMap, fieldTypeIdx) #print('fieldSLIdType: '+str(fieldSLIdType)) if fieldSLIdType == 0: fieldMARTe2Typename = 'float64' fieldPythonTypename = ctypes.c_double elif fieldSLIdType == 1: fieldMARTe2Typename = 'float32' fieldPythonTypename = ctypes.c_float elif fieldSLIdType == 2: fieldMARTe2Typename = 'int8' fieldPythonTypename = ctypes.c_int8 elif fieldSLIdType == 3: fieldMARTe2Typename = 'uint8' fieldPythonTypename = ctypes.c_uint8 elif fieldSLIdType == 4: fieldMARTe2Typename = 'int16' fieldPythonTypename = ctypes.c_int16 elif fieldSLIdType == 5: fieldMARTe2Typename = 'uint16' fieldPythonTypename = ctypes.c_uint16 elif fieldSLIdType == 6: fieldMARTe2Typename = 'int32' fieldPythonTypename = ctypes.c_int32 elif fieldSLIdType == 7: fieldMARTe2Typename = 'uint32' fieldPythonTypename = ctypes.c_uint32 elif fieldSLIdType == 8: fieldMARTe2Typename = 'uint8' fieldPythonTypename = ctypes.c_int8 elif fieldSLIdType == 254: fieldEnumType = WrapperLib.WCAPI_GetDataEnumStorageType(DataTypeMap, fieldTypeIdx) if fieldEnumType == 0: fieldMARTe2Typename = 'float64' fieldPythonTypename = ctypes.c_double elif fieldEnumType == 1: fieldMARTe2Typename = 'float32' fieldPythonTypename = ctypes.c_float elif fieldEnumType == 2: fieldMARTe2Typename = 'int8' fieldPythonTypename = ctypes.c_int8 elif fieldEnumType == 3: fieldMARTe2Typename = 'uint8' fieldPythonTypename = ctypes.c_uint8 elif fieldEnumType == 4: fieldMARTe2Typename = 'int16' fieldPythonTypename = ctypes.c_int16 elif fieldEnumType == 5: fieldMARTe2Typename = 'uint16' fieldPythonTypename = ctypes.c_uint16 elif fieldEnumType == 6: fieldMARTe2Typename = 'int32' fieldPythonTypename = ctypes.c_int32 elif fieldEnumType == 7: fieldMARTe2Typename = 'uint32' fieldPythonTypename = ctypes.c_uint32 else: print('type '+str(fieldEnumType)) raise Exception('Unsupported Enum datatype.') else: #NESTED STRUCTURES!!!!!!!!!!!!!!!! #print('TYPE '+str(fieldSLIdType) + ' '+str(fieldTypeIdx)) GetModelParameterFields(fieldTypeIdx, ParameterStruct, paramIdx, baseParName + '-'+fieldName, paramList, recLev+1) continue #no direct data associated # field dimensions # dimensions are retrieved fieldDimIdx = WrapperLib.WCAPI_GetElementDimensionIdx( ElementMap, elementMapIndex + fieldIdx) fieldDimArrayIdx = WrapperLib.WCAPI_GetDimArrayIndex( DimensionMap, fieldDimIdx) # Starting position in the dimensionArray # Number of elements in the dimensionArray referring to this signal fieldDimNum = WrapperLib.WCAPI_GetNumDims( DimensionMap, fieldDimIdx) #print('fieldDimNum: '+ str(fieldDimNum)) currDimension = [] for currIdx in range(fieldDimNum): currDimension.append( DimensionArray[fieldDimArrayIdx + currIdx]) if currDimension[0] == 1 and currDimension[1] == 1: fieldDimension = 0 elif currDimension[0] == 1 or currDimension[1] == 1: fieldDimension = [ currDimension[0]*currDimension[1]] else: fieldDimension = currDimension currParAddress = paramDataAddr + fieldOffset paramPointer = ctypes.cast( currParAddress, ctypes.POINTER(fieldPythonTypename)) if currDimension[0] == 1 and currDimension[1] == 1: # scalar dimension = 0 mdsplusValue = paramPointer[0] elif currDimension[0] == 1: # vector dimension = currDimension[0]*currDimension[1] valueList = [] for idx in range(dimension): valueList.append(paramPointer[idx]) else: # matrix or column vector (MARTe2 sees column vectors as matrices) dimension = currDimension idx = 0 valueList = [] valueRow = [] for nRow in range(currDimension[0]): for nCol in range(currDimension[1]): valueRow.append(paramPointer[idx]) idx = idx + 1 valueList.append(valueRow) valueRow = [] if currDimension[0] != 1 or currDimension[1] != 1: if fieldSLIdType == 0: mdsplusValue = MDSplus.Float32Array(valueList) elif fieldSLIdType == 1: mdsplusValue = MDSplus.Float64Array(valueList) elif fieldSLIdType == 2: mdsplusValue = MDSplus.Int8Array(valueList) elif fieldSLIdType == 3: mdsplusValue = MDSplus.Uint8Array(valueList) elif fieldSLIdType == 4: mdsplusValue = MDSplus.Int16Array(valueList) elif fieldSLIdType == 5: mdsplusValue = MDSplus.Uint16Array(valueList) elif fieldSLIdType == 6: mdsplusValue = MDSplus.Int32Array(valueList) elif fieldSLIdType == 7: mdsplusValue = MDSplus.Uint32Array(valueList) elif fieldSLIdType == 8: mdsplusValue = MDSplus.Uint8Array(valueList) else: raise Exception('Unsupported parameter datatype.') paramDict = dict(name=baseParName+'-'+fieldName, type=fieldMARTe2Typename, dimensions=fieldDimension, value=mdsplusValue) # dictionary is appended to the MDSplus-style list paramList.append(paramDict)
def GetModelParameterData(ParameterStruct, numOfParameters): paramList = [] for paramIdx in range(numOfParameters): # name is retrieved retrievedName = WrapperLib.WCAPI_GetModelParameterName( ParameterStruct, paramIdx) retrievedName = retrievedName.decode("utf-8") #print('retrievedname: ', retrievedName) # type is retrieved retrievedTypeIdx = WrapperLib.WCAPI_GetModelParameterDataTypeIdx( ParameterStruct, paramIdx) #print('retrievedTypeIdx: ', str(retrievedTypeIdx)) retrievedSLIdType = WrapperLib.WCAPI_GetDataTypeSLId( DataTypeMap, retrievedTypeIdx) #print('retrievedSLIdType: ', str(retrievedSLIdType)) #retrievedCTypename = WrapperLib.WCAPI_GetDataTypeCName( # DataTypeMap, retrievedTypeIdx) #retrievedCTypename = retrievedCTypename.decode("utf-8") #print('retrievedCTypename: '+retrievedCTypename) if retrievedSLIdType == 0: MARTe2Typename = 'float64' pythonTypename = ctypes.c_double elif retrievedSLIdType == 1: MARTe2Typename = 'float32' pythonTypename = ctypes.c_float elif retrievedSLIdType == 2: MARTe2Typename = 'int8' pythonTypename = ctypes.c_int8 elif retrievedSLIdType == 3: MARTe2Typename = 'uint8' pythonTypename = ctypes.c_uint8 elif retrievedSLIdType == 4: MARTe2Typename = 'int16' pythonTypename = ctypes.c_int16 elif retrievedSLIdType == 5: MARTe2Typename = 'uint16' pythonTypename = ctypes.c_uint16 elif retrievedSLIdType == 6: MARTe2Typename = 'int32' pythonTypename = ctypes.c_int32 elif retrievedSLIdType == 7: MARTe2Typename = 'uint32' pythonTypename = ctypes.c_uint32 elif retrievedSLIdType == 8: MARTe2Typename = 'uint8' pythonTypename = ctypes.c_bool elif retrievedSLIdType == 254: fieldEnumType = WrapperLib.WCAPI_GetDataEnumStorageType(DataTypeMap, retrievedTypeIdx) if fieldEnumType == 0: MARTe2Typename = 'float64' pythonTypename = ctypes.c_double elif fieldEnumType == 1: MARTe2Typename = 'float32' pythonTypename = ctypes.c_float elif fieldEnumType == 2: MARTe2Typename = 'int8' pythonTypename = ctypes.c_int8 elif fieldEnumType == 3: pythonTypename = ctypes.c_uint8 MARTe2Typename = 'uint8' elif fieldEnumType == 4: MARTe2Typename = 'int16' pythonTypename = ctypes.c_int16 elif fieldEnumType == 5: pythonTypename = ctypes.c_uint16 MARTe2Typename = 'uint16' elif fieldEnumType == 6: pythonTypename = ctypes.c_int32 MARTe2Typename = 'int32' elif fieldEnumType == 7: pythonTypename = ctypes.c_uint32 MARTe2Typename = 'uint32' else: print('type '+str(fieldEnumType)) raise Exception('Unsupported Enum datatype.') elif retrievedSLIdType == 255: pass else: raise Exception('Unsupported parameter datatype.') if retrievedSLIdType != 255: # actual parameter value is retrieved paramAddrIdx = WrapperLib.WCAPI_GetModelParameterAddrIdx( ParameterStruct, paramIdx) paramDataAddr = WrapperLib.WCAPI_GetDataAddress( DataAddrMap, paramAddrIdx) paramPointer = ctypes.cast( paramDataAddr, ctypes.POINTER(pythonTypename)) # dimensions are retrieved dimIdx = WrapperLib.WCAPI_GetModelParameterDimensionIdx( ParameterStruct, paramIdx) dimArrayIdx = WrapperLib.WCAPI_GetDimArrayIndex( DimensionMap, dimIdx) # Starting position in the dimensionArray # Number of elements in the dimensionArray referring to this signal dimNum = WrapperLib.WCAPI_GetNumDims( DimensionMap, dimIdx) currDimension = [] for currIdx in range(dimNum): currDimension.append(DimensionArray[dimArrayIdx + currIdx]) if currDimension[0] == 1 and currDimension[1] == 1: # scalar dimension = 0 mdsplusValue = paramPointer[0] elif currDimension[0] == 1: # vector dimension = currDimension[0]*currDimension[1] valueList = [] for idx in range(dimension): valueList.append(paramPointer[idx]) else: # matrix or column vector (MARTe2 sees column vectors as matrices) dimension = currDimension idx = 0 valueList = [] valueRow = [] for nRow in range(currDimension[0]): for nCol in range(currDimension[1]): valueRow.append(paramPointer[idx]) idx = idx + 1 valueList.append(valueRow) valueRow = [] if currDimension[0] != 1 or currDimension[1] != 1: if retrievedSLIdType == 0: mdsplusValue = MDSplus.Float32Array(valueList) elif retrievedSLIdType == 1: mdsplusValue = MDSplus.Float64Array(valueList) elif retrievedSLIdType == 2: mdsplusValue = MDSplus.Int8Array(valueList) elif retrievedSLIdType == 3: mdsplusValue = MDSplus.Uint8Array(valueList) elif retrievedSLIdType == 4: mdsplusValue = MDSplus.Int16Array(valueList) elif retrievedSLIdType == 5: mdsplusValue = MDSplus.Uint16Array(valueList) elif retrievedSLIdType == 6: mdsplusValue = MDSplus.Int32Array(valueList) elif retrievedSLIdType == 7: mdsplusValue = MDSplus.Uint32Array(valueList) else: raise Exception('Unsupported parameter datatype.') # retrieved data is saved to a dictionary paramDict = dict(name='Parameters.'+retrievedName, type=MARTe2Typename, dimensions=dimension, value=mdsplusValue) # dictionary is appended to the MDSplus-style list paramList.append(paramDict) else: #retrievedSLIdType == 255 SRUCTURED PARAMETERS GetModelParameterFields(retrievedTypeIdx, ParameterStruct, paramIdx, 'Parameters.'+retrievedName, paramList, 1) #numFields = WrapperLib.WCAPI_GetDataTypeNumElements( #DataTypeMap, retrievedTypeIdx) #elementMapIndex = WrapperLib.WCAPI_GetDataTypeElemMapIndex( #DataTypeMap, retrievedTypeIdx) ## actual parameter value is retrieved #paramAddrIdx = WrapperLib.WCAPI_GetModelParameterAddrIdx( #ParameterStruct, paramIdx) #paramDataAddr = WrapperLib.WCAPI_GetDataAddress( #DataAddrMap, paramAddrIdx) #print('NUM FIELDS: '+str(numFields)) #for fieldIdx in range(numFields): #fieldName = WrapperLib.WCAPI_GetElementName( #ElementMap, elementMapIndex + fieldIdx) #fieldName = fieldName.decode("utf-8") #print('FIELD: '+fieldName) #fieldOffset = WrapperLib.WCAPI_GetElementOffset( #ElementMap, elementMapIndex + fieldIdx) #fieldTypeIdx = WrapperLib.WCAPI_GetElementDataTypeIdx( #ElementMap, elementMapIndex + fieldIdx) #fieldSLIdType = WrapperLib.WCAPI_GetDataTypeSLId( #DataTypeMap, fieldTypeIdx) #if fieldSLIdType == 0: #fieldMARTe2Typename = 'float64' #fieldPythonTypename = ctypes.c_double #elif fieldSLIdType == 1: #fieldMARTe2Typename = 'float32' #fieldPythonTypename = ctypes.c_float #elif fieldSLIdType == 2: #fieldMARTe2Typename = 'int8' #fieldPythonTypename = ctypes.c_int8 #elif fieldSLIdType == 3: #fieldMARTe2Typename = 'uint8' #fieldPythonTypename = ctypes.c_uint8 #elif fieldSLIdType == 4: #fieldMARTe2Typename = 'int16' #fieldPythonTypename = ctypes.c_int16 #elif fieldSLIdType == 5: #fieldMARTe2Typename = 'uint16' #fieldPythonTypename = ctypes.c_uint16 #elif fieldSLIdType == 6: #fieldMARTe2Typename = 'int32' #fieldPythonTypename = ctypes.c_int32 #elif fieldSLIdType == 7: #fieldMARTe2Typename = 'uint32' #fieldPythonTypename = ctypes.c_uint32 #elif fieldSLIdType == 8: #fieldMARTe2Typename = 'bool' #fieldPythonTypename = ctypes.c_int8 #elif fieldSLIdType == 254: #fieldEnumType = WrapperLib.WCAPI_GetDataEnumStorageType(DataTypeMap, fieldTypeIdx) #if fieldEnumType == 0: #fieldMARTe2Typename = 'float64' #fieldPythonTypename = ctypes.c_double #elif fieldEnumType == 1: #fieldMARTe2Typename = 'float32' #fieldPythonTypename = ctypes.c_float #elif fieldEnumType == 2: #fieldMARTe2Typename = 'int8' #fieldPythonTypename = ctypes.c_int8 #elif fieldEnumType == 3: #fieldMARTe2Typename = 'uint8' #fieldPythonTypename = ctypes.c_uint8 #elif fieldEnumType == 4: #fieldMARTe2Typename = 'int16' #fieldPythonTypename = ctypes.c_int16 #elif fieldEnumType == 5: #fieldMARTe2Typename = 'uint16' #fieldPythonTypename = ctypes.c_uint16 #elif fieldEnumType == 6: #fieldMARTe2Typename = 'int32' #fieldPythonTypename = ctypes.c_int32 #elif fieldEnumType == 7: #fieldMARTe2Typename = 'uint32' #fieldPythonTypename = ctypes.c_uint32 #else: #print('type '+str(fieldEnumType)) #raise Exception('Unsupported Enum datatype.') #else: #print('type '+str(fieldSLIdType)) #raise Exception('Unsupported nested structures.') ## field dimensions ## dimensions are retrieved #fieldDimIdx = WrapperLib.WCAPI_GetElementDimensionIdx( #ElementMap, elementMapIndex + fieldIdx) #fieldDimArrayIdx = WrapperLib.WCAPI_GetDimArrayIndex( #DimensionMap, fieldDimIdx) # Starting position in the dimensionArray ## Number of elements in the dimensionArray referring to this signal #fieldDimNum = WrapperLib.WCAPI_GetNumDims( #DimensionMap, fieldDimIdx) #currDimension = [] #for currIdx in range(fieldDimNum): #currDimension.append( #DimensionArray[fieldDimArrayIdx + currIdx]) #if currDimension[0] == 1 and currDimension[1] == 1: #fieldDimension = 0 #elif currDimension[0] == 1 or currDimension[1] == 1: #fieldDimension = [ #currDimension[0]*currDimension[1]] #else: #fieldDimension = currDimension #currParAddress = paramDataAddr + fieldOffset #paramPointer = ctypes.cast( #currParAddress, ctypes.POINTER(fieldPythonTypename)) #if currDimension[0] == 1 and currDimension[1] == 1: # scalar #dimension = 0 #mdsplusValue = paramPointer[0] #elif currDimension[0] == 1: # vector #dimension = currDimension[0]*currDimension[1] #valueList = [] #for idx in range(dimension): #valueList.append(paramPointer[idx]) #else: ## matrix or column vector (MARTe2 sees column vectors as matrices) #dimension = currDimension #idx = 0 #valueList = [] #valueRow = [] #for nRow in range(currDimension[0]): #for nCol in range(currDimension[1]): #valueRow.append(paramPointer[idx]) #idx = idx + 1 #valueList.append(valueRow) #valueRow = [] #if currDimension[0] != 1 or currDimension[1] != 1: #if fieldSLIdType == 0: #mdsplusValue = MDSplus.Float32Array(valueList) #elif fieldSLIdType == 1: #mdsplusValue = MDSplus.Float64Array(valueList) #elif fieldSLIdType == 2: #mdsplusValue = MDSplus.Int8Array(valueList) #elif fieldSLIdType == 3: #mdsplusValue = MDSplus.Uint8Array(valueList) #elif fieldSLIdType == 4: #mdsplusValue = MDSplus.Int16Array(valueList) #elif fieldSLIdType == 5: #mdsplusValue = MDSplus.Uint16Array(valueList) #elif fieldSLIdType == 6: #mdsplusValue = MDSplus.Int32Array(valueList) #elif fieldSLIdType == 7: #mdsplusValue = MDSplus.Uint32Array(valueList) #else: #raise Exception('Unsupported parameter datatype.') #paramDict = dict(name='Parameters.'+retrievedName+'-'+fieldName, #type=fieldMARTe2Typename, dimensions=fieldDimension, value=mdsplusValue) ## dictionary is appended to the MDSplus-style list #paramList.append(paramDict) #endif STRUCTURED PARAMETER #endfor parameters #print('PARAMETRI FATTI') return paramList
def getShotDB(expt,path=None,lower=None,upper=None): """ getShotDB("mytree") getShotDB("mytree",0) getShotDB("mytree","/my/local/tree/path") getShotDB("mytree","myserver::") getShotDB("mytree","myserver::/my/remote/tree/path") getShotDB("mytree",*,_from) getShotDB("mytree",*,*,_upto) getShotDB("mytree",*,_from,_upto) """ isTdi = isinstance(expt, MDSplus.mdsdata.Data) expt = str(expt).lower() def getTreePath(): # split path variable into single paths and replaces the ~t treename expt_paths = os.getenv(expt+'_path') if expt_paths is None: raise MDSplus.mdsExceptions.TreeNOPATH return expt_paths.replace('~t',expt).split(';') def getshots(expt_path,lower,upper): if expt_path.find('::')>=0: # path is referring to remote tree server,path = expt_path.split('::',2) # check if thick or distributed path = "*" if len(path)==0 else '"'+path+'"' # handle None for upper and lower if lower is None: lower = "*" if upper is None: upper = "*" # fetch data from server return MDSplus.Connection(server).get('getShotDb("%s",%s,%s,%s)'%(expt,path,str(lower),str(upper)),).data().tolist() start = expt+'_' files = [f[len(expt):-5].split('_') for f in os.listdir(expt_path) if f.endswith('.tree') and f.startswith(start)] return [int(f[1]) for f in files if len(f)==2 and f[1]!='model'] """The path argument is interpreted""" # try to convert to native datatype try: path = path.data().tolist() except: pass if isinstance(path, (int,)): # path is int and refering to the index of the path list path = getTreePath()[path] if isinstance(path, MDSplus.version.basestring): # path is str and used as path shots = getshots(path,lower,upper) else: # path is undefined and the total list will be collected shots = [] for expt_path in getTreePath(): try: shots += getshots(expt_path,lower,upper) except: import traceback traceback.print_exc() """filter result by upper and lower limits""" if lower is not None or upper is not None: if lower is None: shots = numpy.array(filter(lambda x: x <= int(upper), shots)) elif upper is None: shots = numpy.array(filter(lambda x: x >= int(lower), shots)) else: shots = numpy.array(filter(lambda x: x >= int(lower) and x <= int(upper), shots)) shots.sort() # return as MDSplus type if input was MDSplus type return MDSplus.Int32Array(shots) if isTdi else shots