A Course in BTRON MicroScript for Beginners

Real Object Operations


18.11 Real Object Operations

These carry out reading and writing in regard to the contents of specified real objects.

The functions of real object operations make as their targets not just the real objects created with applications such as the Basic Text Editor, but real objects with a relative simple original structure that are employed for data exchange use with fellow microscripts and other systems. The contents of real objects created with applications such as the Basic Text Editor are made up into TAD data structures. It is necessary for the user to carry out the interpretation of these TAD data structures, and this becomes fairly difficult work.

In real objects (files), broad information classifications are first done on the basis of records (data strings of arbitrary length). You can include multiple records in one real object. Record types (with the numbers 0-31) are attached to each record, thus showing the role of the record.

Main record types

0 :

Link record

1 :

TAD main record

6 :

Specification fusen record

7 :

Function fusen record

8 :

Execution function fusen record

9 :

Execution program record

10 :

Data box record

16-31 :

Application dependent records

Next, a detailed information classification is done based on the segments inside the TAD main record (record type 1). TAD is described as a list of these segments. There are many types to these segments; such things as text and forms, and figures can be described.

  • The real object operation functions that MicroScript provides simply carry out the reading and writing of data inside records, without any relation to the type, record types, and data contents of the real object that will become the target. For that reason, it is necessary use them with caution, after having sufficiently understood the data structures of real objects.

FOPEN <real object specification>, <mode specification>

This makes it so that we can open a specified real object in a specified mode and use it.

This cannot create a real object anew.

<Real Object Specification>

This specifies the real object that will become the target. In a case where a virtual object segment has been specified, this opens the real object that the virtual object references. In a case where a character string has been specified with a character string constant or character string variable, this opens the corresponding real object with that as a path name (p. 323).

<Mode Specification>

This specifies with a character string constant or character string variable the mode in which to do the opening.

"R" Read-in mode
"W" Write-in mode
"U" Update mode
"RX" Read-in mode (exclusion)
"WX" Write-in mode (exclusion)
"UX" Update mode (exclusion)
"Rx" Read-in mode (exclusive write-in)
"Wx" Write-in mode (exclusive write-in)
"Ux" Update mode (exclusive write-in)

With a real object opened in read-in mode, read-in based on the FREAD statement is possible. With a real object opened in write-in mode, write-in based on the FWRITE statement is possible. With a real object opened in update mode, read-in based on the FREAD statement and write-in based on the FWRITE statement are possible. Exclusion mode prohibits another application from simultaneously opening the target real object. In a case where the real object has already been opened from another application, it cannot be opened in exclusion mode. Exclusive write-in mode prohibits another application from simultaneously opening the target real object in write-in or update mode. In a case where the real object has already been opened from another application in write-in or update mode, it cannot be opened in exclusive write-in mode.

The number of files that MicroScript can simultaneously open is a maximum of 16.

Example:
VARIABLE path:C[30]
SET path[:]="/SYS/XX/TMP"
FOPEN path, "UX"

FCLOSE <real object specification>

This closes a specified real object.

The <real object specification> specifies the real object that will become the target. In a case where a virtual object has been specified, this closes the real object that the virtual object references. In a case where a character string has been specified with a character string constant or character string variable, this opens the corresponding real object with that as a path name (p. 323).

Example:
FCLOSE path

  • When MicroScript terminates, windows that have been opened will be closed, but we strongly recommend that you close them at the point in time that the use of the real object ends.

FREAD <real object specification>, <record number expression>, <offset expression>, <size expression>, <array variable> [, <record size variable>]

This reads in the data of a specified real object. In a case where the real object has not been opened, it will automatically open in update mode (U). In this case, it will automatically be closed at an appropriate point in time.

<Real Object Specification>

This specifies the real object we will make the target. In a case where a virtual object has been specified, it will read in from the real object that the virtual object references. In a case where a character string has been specified with a character string constant or character string variable, this reads in from the corresponding real object with that as a path name (p. 323).

<Record Number Expression>

This is an expression that expresses the record number (0- ) that we will make the target. When we specify a record number that does not exist, it will become an error.

<Offset Expression>

This is an expression that expresses the offset byte number (0- ) at which we will begin read-in. It must be below the record size of the record we will make the target.

<Size Expression>

This is an expression that expresses byte number (0- ) on which we will carry out read-in. The byte number on which we will actually carry out read-in becomes the smallest value among the following.

When 0, read-in is not carried out, but we can obtain the record size.

<Array Variable>

This is an array variable in which we store read-in data. The array variable type is arbitrary. In a case where the <size expression> is greater than the size of the array variable, data will be stored only to the extent of the array variable size.

You can also specify an array section instead of an array variable. In that case, only the <element number> from the specified <beginning element> will become the target of the read-in.

Array section: <array variable> [<beginning element> : <element number>]

<Record Size Variable>

This is a variable for the purpose of storing the record size (byte number of the entire record), and it can also be omitted. The size of the entire record always returns, without regard to the specified <offset> and <size>.

  • The read-in location of the record will not be saved. Each time you execute the FREAD statement, it is necessary to specify the target record and offset.
  • In a case where the record that will become the target is a link record, there are cases in which it will become an error. A method to investigate the the record type of the record that will become the target has not been provided.

FWRITE <real object specification>, <record number expression>, <offset expression>, <size expression>, <array variable> [, <record size variable>]

This writes in the record data of a specified real object. In a case where the real object has not been opened, it will automatically open in update mode (U). In this case, it will automatically be closed at an appropriate point in time.

<Real Object Specification>

This specifies the real object we will make the target. In a case where a virtual object has been specified, it will read in from the real object that the virtual object references. In a case where a character string has been specified with a character string constant or character string variable, this reads in from the corresponding real object with that as a path name (p. 323).

<Record Number Expression>

This is an expression that expresses the record number (0- ) that we will make the target. When we specify a record number that does not exist, it will become an error. However, when we have specified the record number of "last record number + 1," we can write in by newly adding in a record. In this case, the <offset expression> must be 0.

The record type of a newly added record will be fixed at 31 (an application dependent record). You cannot specify the record type. There will be no instances in which the contents of records outside of the specified record will change.

<Offset Expression>

This is an expression that expresses the offset byte number (0- ) at which we will begin write-in. It must be below the record size of the record we will make the target. In a case where we newly add a record, it must be 0. When the offset expression = -1, we specially reduce the record size to the byte number specified in the <size expression>.

When the record size is below the specified byte size, it won't do anything. Even if you make the size 0, you cannot delete the record.

<Size Expression>

This is an expression that expresses byte number (0- ) on which we will carry out write-in. The byte number on which we will actually carry out write-in becomes the smallest value among the following.

When 0, write-in is not carried out, but we can obtain the record size.

<Array Variable>

This specifies an array variable in which we store write-in data. The array variable type is arbitrary. In a case where the <size expression> is greater than the size of the array variable, data will be read in only to the extent of the array variable size. You can also specify an array section instead of an array variable; in that case, only the <element number> from the specified <beginning element> will become the target of the write-in.

Array section: <array variable> [<beginning element> : <element number>]

<Record Size Variable>

This is a variable for the purpose of storing the record size (byte number of the entire record), and it can also be omitted. The size of the entire record after write-in always returns, without regard to the specified <offset> and <size>.

  • Depending on the write-in of the data, the contents of the record will be overwritten. In a case where you have carried out write-in by exceeding the record size, the record size will automatically be extended.
  • In a case where the record that will become the target is a link record, there are cases in which it will become an error.
  • After you have carried out write-in for the real object, we strongly recommend that you close by means of the FCLOSE statement.

Data Correspondences

We will next show the relationship between the specified <array variable> type and the record data (byte strings). When the <array variable> type is different or the <offset> and <size> specifications straddle the boundaries of the variable byte number, there is the possibility that the expected results will not be attained.

Example of Use

For the real object that will become the target, either duplicate an appropriate real object, or create one using another program. In a case where you have duplicated an appropriate real object, generally several records will already exist, but first it will be overwritten by carrying out write-in with the FWRITE statement.

VERSION 2
VARIABLE B1:B[100]
VARIABLE B2:B[101]
VARIABLE SZ:I
# Set the values of 0-99 in B1[0-99]
REPEAT 100
  SET B1[$CNT]=$CNT
ENDREPEAT 
# Write in B1[0-99] from offset 0 of F1
FWRITE F1, 0, 0, 100, B1, SZ
# Read in to B2[1-100] from offset 0 of F1
FREAD F1, 0, 0, 100, B2[1:100], SZ


Copyright © 1999 Personal Media Corporation

Copyright © 2011 Sakamura Laboratory, University Museum, University of Tokyo