![](https://www.opentextbooks.org.hk/sites/opentextbooks/files/book_profile/cc_icon/by-sa.png)
Consider the function in Figure Figure 11.1 where a set of numbers in a one-dimensional array represents the resulting noisy signal is to be written to a file. This section will outline the steps required to create files.
![media/image1.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image1.png)
Create a new G program, right click in the G programming window and select File Dialog from the Functions »Programming »File I/O »Advanced Functions menu. Drag and drop the File Dialog function onto the G programming window.
![media/image2.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image2.png)
The Configure File Dialog dialog box automatically appears to configure the function. Accept the default configuration shown in Figure Figure 11.3 to create a single file by clicking the OK button.
![media/image3.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image3.png)
The resulting diagram after closing the configuration dialog box is shown in . Optionally, right click on File Dialog and select View As Icon from the pop-up menu. This will save some real estate in the G programming window.
![media/image4.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image4.png)
![media/image5.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image5.png)
From the Functions »Programming »File I/O menu select Open/Create File, Write Binary File and Close File functions.
![media/image6.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image6.png)
Arrange the File I/O operations as shown in Figure Figure 11.7.
![media/image7.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image7.png)
Right click on the operation (0:open) terminal of the Open/Create File function (highlighted in Figure File Create Operation).
![media/image8.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image8.png)
Select Create » Constant from the pop-up menu.
![media/image9.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image9.png)
Arrange the diagram to look as in Figure Figure 11.10.
![media/image10.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image10.png)
Click on the down arrow in the operation constant just created and select open or create from the pop-up menu.
![media/image11.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image11.png)
The resulting updated operation constant value is shown in Figure Figure 11.12.
![media/image12.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image12.png)
Repeat the process to create a constant for theaccess (0:read/write) terminal (highlighted in Figure Figure 11.13).
![media/image13.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image13.png)
Set the constant to write-only. Re-arrange the block diagram to look like the diagram shown in Figure Figure 11.14. At this point, the file is set to create a new file for writing.
![media/image14.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image14.png)
Get the Noisy Signal function and wire its output data to the Data terminal of the Write to Binary File function.
![media/image15.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image15.png)
Complete the diagram by connecting the Open, Write and Close file operations as shown in Figure Figure 11.16.
![media/image16.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image16.png)
When this G program is executed, the standard file dialog box appears. Name the file to be written signal.dat.
![media/image17.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image17.png)
Once the program completes executing, the signal.dat file is created and located in the location indicated by the path selected.
![media/image18.png](http://www.opentextbooks.org.hk/system/files/resource/8/8091/8160/media/image18.png)
- 1634 reads