SPLINE_READ
ModelingUsed to read x, y, and optionally z, data from a file for use with a Reference_Spline element.
Use
User-defined request calling a SPLINE_READ to obtain the x, y, and optionally
z, vector to define a Reference_Spline
element.
<Reference_Spline
id = "301001"
usrsub_dll_name = "c:\work\test.dll"
file_name = "c:\data\spring1.dat"
block_name = "spring_force">
</ Reference_Spline>
Format
- Fortran Calling Syntax
-
SUBROUTINE SPLINE_READ (ID, FILE_NAME, BLOCK_NAME, ERRFLG)
- C/C++ Calling Syntax
-
void STDCALL SPLINE_READ (int *id, char *file_name, int file_name_len, char *block_name, int block_name_len, int *errflg)
- Python Calling Syntax
-
def SPLINE_READ(id, file_name, block_name): return errflag
- MATLAB Calling Syntax
-
function errflg = SPLINE_READ(id, file_name, block_name)
Attributes
- ID
- [integer]
- FILE_NAME
- [CHARACTER*(*)]
- BLOCK_NAME
- [CHARACTER*(*)]
Output
- ERRFLG
- [logical]
Example
- The following example demonstrates the SPLINE_READ user subroutine using the
Python scripting language:
def SPLINE_READ(id, file_name, block_name): x =6*[0.0] y =6*[0.0] x[0] =0.0 x[1] =0.3 x[2] =0.5 x[3] =1.0 x[4] =1.5 x[5] =2.0 y[0] =0.0 y[1] =0.0 y[2] =0.0 y[3] = -0.05 y[4] = -0.15 y[5] = -0.3 z =0.0 errflg = py_put_spline(id, x, y, z) return errflg
- In the example below, the SPLINE_READ subroutine is used to populate a
Reference_Spline model element with values that are read
from an external file data.txt.
- The model
element:
<Reference_Spline id = "301001" label = "Excite" interpreter = "Python" script_name = "read_curve.py" usrsub_fnc_name = "SPLINE_READ" file_name = "data.txt" block_name = "dummy" linear_extrap = "TRUE" />
- The external file data.txt contains a comma
separated list of x, y values as shown
below:
0, 0 0.1, 4.045084972 0.2, 4.755282581 0.3, 1.545084972 0.4, -2.938926261 0.5, -5 0.6, -2.938926261 0.7, 1.545084972 0.8, 4.755282581 0.9, 4.045084972 1, 1.07195E-14 1.1, -4.045084972 1.2, -4.755282581 1.3, -1.545084972 1.4, 2.938926261 …
- The user subroutine SPLINE_READ is written in the
Python scripting language and is shown
below:
# # This is an example for a spline read # def SPLINE_READ(id, file_name,block_name): x_ = [] y_ = [] # Open the external file for reading f = open(file_name, 'r') # Loop throught the file contents to get x,y values while 1: line = f.readline() if not line: break cols = line.split(',') x_.append(float(cols[0])) temp = cols[1].split('\n') y_.append(float(temp[0])) z_ = 0.0 # Use py_put_spline to put the x, y, z values into reference_spline errflg = py_put_spline(id, x_, y_, z_) return errflg
- The model
element: