Developer's Reference |
|
This chapter describes how to import data from simple files using modules in the File Access library.
The File Access library is located in the Accessories page of the Network Editor under Utility Modules. It contains a number of objects that allow you to import data from simple data files:
You can use these objects to construct a mapping between an AVS/Express object and the data in a file. As the values in the AVS/Express object are accessed, AVS/Express automatically goes to the file to get the values. From the Network Editor, you can use the Add File Import Module tool to create these objects.
The file objects can also be accessed through V, by prepending the module name with "FILE". For example, to create an instance of the file_scalar_ascii module, type:
The rest of this chapter provides reference information on each of the file access objects.
You use the file object to specify a filename. For example, you can create a filename object for each file that you need to read or search and connect each one to the appropriate reading and searching object as needed.
When you instance a file object, you set the name subobject to the pathname of the file containing the data. Once you set the name subobject, the file object's update method assigns values to the fptr, status, and cur_offset subobjects.
The file_obj object reads an ASCII or a binary array from the file object (refer to page 7-4 in the Developer's Reference). It starts reading data at the offset position which is specified in bytes, and it reads the number of values corresponding to the dimensionality of the referencing object. If the dimensionality is not specified, it reads until the end of file. If the dimensionality is specified and the end of file is reached before the target object is filled, an error is reported.
file is an object that identifies the file that will be accessed. Refer to page 7-4 in the Developer's Reference for more information.
offset specifies, in bytes, an offset from the beginning of the file.
type is an integer that specifies the type of data:
columns is an array of 1s and 0s that represents words in the lines of an ASCII file. It indicates whether or not to read the words. This parameter is not used for binary files.
ascii_binary is 0 for ASCII files, 1 for binary files and 2 for portable binary (XDR) files. Alternatively you can specify this parameter using one of the strings: "ascii", "binary" or "xdr".
stride is an optional integer value that specifies how many "strides" must be taken to get to the next data value. It is relevant only for binary files, if is omitted, 1 is assumed.
file_obj_bin reads a binary array or binary scalar from the file object (refer to page 7-4 in the Developer's Reference). It starts reading data at the offset position which is specified in bytes. file_obj_bin reads a number of bytes corresponding to the type value and dimensionality of the referencing object. It reports an error if it reaches the end of file before the target object is filled.
file is an object that identifies the file that will be accessed. Refer to page 7-4 in the Developer's Reference for more information.
offset specifies, in bytes, an offset from the beginning of the file.
type is an integer that specifies the type of data:
stride is an optional integer value that specifies how many "strides" must be taken to get to the next data value. It is relevant only for binary files, if is omitted, 1 assumed.
A binary file, myData, has an array of integers. To read the third integer:
Note that the offset is calculated in bytes. A value of 8 indicates that the first two integers in the file are ignored.
The inary file, myData, contains an array of integers. To read 100 integers, starting from position 200 in the file. To read 100 integers:
The file_scalar_ascii object reads ASCII scalar data from file starting at the position specified by an offset in bytes. The integer type specifies the type of data:
ASCII file, data, contains an integer and a float:
To get the integer and float values:
The file_array_ascii object reads an ASCII array from file starting at the position specified by an offset in bytes. The integer type specifies type of data:
columns is an array of 1s and 0s that represents words in the lines of an ASCII file. It indicates whether or not to read the words.
file_array_ascii reads the number of words corresponding to the dimensionality of the referencing object. It reports an error if it finds the end of file before the target object is filled. The words must be separated by spaces.
ASCII file, data, contains three columns of float numbers starting from line 100. There are 200 lines containing the array.
You want to extract the second and third components of the array:
The file_find_expr object searches for a pattern that matches a user-specified UNIX regular expression string. This capability only works on UNIX systems. It returns the offset in bytes of the next byte after the expression.
In ASCII file, data, find the integer "ndim" that follows an expression:
The file_skip_lines object returns the offset in bytes of a location in file after skipping nlines in an ASCII file.
The file_skip_words object returns the offset in bytes of a location after skipping nwords in an ASCII file. The words must be separated by spaces.
To read the third integer on line 10 in the ASCII file, data:
This example uses the file objects and V functions to import a file in AVS field format. It reads the hydrogen.fld file.
In the following example the "cache" function is used to prevent multiple accesses to the file from different modules.
This example uses the file objects and V functions to import a file in AVS ASCII UCD format. It reads the bluntfin.inp file.
To represent the general UCD file format using file objects is a rather challenging task. This example uses the fact that bluntfin.inp has just one hexahedral cell type. In general it is possible to use file objects with a UCD format only if there is just one cell type or a list of cells that is sorted by cell types. In this case it is possible to map UCD cells onto the Cell_Sets used in AVS/Express to represent different cell types.
In the following example the "cache" function is used to prevent multiple access to the file from different modules.
These objects act like arrays in that you can connect them to field mapper modules; they import generic data, not field data.
Online examples are also available in:
![]() |
![]() |
![]() |
![]() |