Writing to a File


Contents:



How to Write a GR image

Typical functions that you would use to create and write general raster images are as follows:

Sample Program

The gr_wt program is a sample program for writing out a GR image. You can either download the C or FORTRAN program at the end, or just take a look at the HTML version, with the HDF calls highlighted: If you have downloaded this program, then you can compile and run it. It creates an HDF file called gr1.hdf. You can view the contents of the HDF file that gets created by this program, in the next section, "Contents of HDF File Created".

Following is a detailed review of what this program does:

ADDITIONAL EXERCISES:
Change the stride to 2 (and edge accordingly). What happens?
Change the edge to only read one line at a time.

Contents of HDF File Created

You can view the contents of gr1.hdf, using the hdp command. Following is the output you would get by examining the file with hdp dumpgr gr1.hdf:

File name: gr1.hdf 

	 Image  Name = Image_1
	 Index = 0
	 Type= 16-bit signed integer
	 width=15; height=10
	 Ref. = 2
	 ncomps = 2
	 Number of attributes = 0
	 Interlace= 0
	 Data : 
                1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 
                12 13 13 14 14 15 15 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 
                9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 3 3 4 
                4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 
                15 15 16 16 17 17 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 
                11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 5 5 6 
                6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 
                16 16 17 17 18 18 19 19 6 6 7 7 8 8 9 9 10 10 11 11 
                12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 
                20 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 
                16 16 17 17 18 18 19 19 20 20 21 21 8 8 9 9 10 10 
                11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 
                19 20 20 21 21 22 22 9 9 10 10 11 11 12 12 13 13 14 
                14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 
                23 23 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 
                17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 


Download Sample Program (optional)

Programs used in this tutorial: [Compiling a program]