#include "hdf.h"
#define WIDTH 5
#define HEIGHT 6
main( )
{
/* Initialize the image array */
static uint8 raster_data[HEIGHT][WIDTH] =
{ 1, 2, 3, 4, 5,
6, 7, 8, 9, 10,
11, 12, 13, 14, 15,
16, 17, 18, 19, 20,
21, 22, 23, 24, 25,
26, 27, 28, 29, 30 };
intn status;
/* Write the 8-bit raster image to file */
status = DFR8addimage("Example1.hdf", raster_data,
WIDTH, HEIGHT, 0);
}
PROGRAM RASTER8
character*1 raster_data(5,6)
integer retn, d8aimg
integer*4 WIDTH, HEIGHT
parameter(WIDTH = 5, HEIGHT = 6)
C Initialize the image array
data raster_data / 1, 2, 3, 4, 5,
$ 6, 7, 8, 9, 10,
$ 11, 12, 13, 14, 15,
$ 16, 17, 18, 19, 20,
$ 21, 22, 23, 24, 25,
$ 26, 27, 28, 29, 30 /
C Write the 8-bit raster image to the file
retn = d8aimg(`Example1.hdf', raster_data, WIDTH, HEIGHT, 0)
end
#include "hdf.h"
#define WIDTH 20
#define HEIGHT 20
main( )
{
uint8 colors[256*3], picture[HEIGHT][WIDTH];
uint8 i, j;
int16 status;
/* Initialize image arrays. */
for (j = 0; j < WIDTH; j++) {
for (i = 0; i < HEIGHT; i++)
picture[j][i] = 1;
}
/* Set the current palette. */
status = DFR8setpalette(colors);
/* Write the image data to the file. */
status = DFR8putimage("Example2.hdf", picture, WIDTH,
HEIGHT, COMP_NONE);
}
PROGRAM WRITE UNCOMPRESSED RIS8
integer d8spal, d8pimg, status, i, j
integer colors(768)
integer*4 WIDTH, HEIGHT, COMP_NONE
parameter (COMP_NONE = 0,
+ WIDTH = 20,
+ HEIGHT = 20)
integer picture(WIDTH, HEIGHT)
C Initialize the image data.
do 20 j = 1, WIDTH
do 10 i = 1, HEIGHT
picture(j, i) = 1
10 continue
20 continue
C Set the current palette.
status = d8spal(colors)
C Write the image data to the file.
status = d8pimg(`Example2.hdf', picture, WIDTH, HEIGHT,
+ COMP_NONE)
end
#include "hdf.h"
#define WIDTH 20
#define HEIGHT 20
main ( )
{
uint8 paletteA[256*3], paletteB[256*3];
uint8 picture1[HEIGHT][WIDTH], picture2[HEIGHT][WIDTH];
uint8 picture3[HEIGHT][WIDTH], picture4[HEIGHT][WIDTH];
uint8 i, j;
int16 status;
/* Initialize image arrays. */
for (j = 0; j < WIDTH; j++) {
for (i = 0; i < HEIGHT; i++) {
picture1[j][i] = 1;
picture2[j][i] = 1;
picture3[j][i] = 1;
picture4[j][i] = 1;
}
}
/* Set the first palette. */
status = DFR8setpalette(paletteA);
/* Write the compressed image data to the HDF file. */
status = DFR8putimage("Example3.hdf", (VOIDP)picture1, WIDTH, HEIGHT, \
COMP_RLE);
status = DFR8addimage("Example3.hdf", (VOIDP)picture2, WIDTH, HEIGHT, \
COMP_RLE);
/* Set the second palette. */
status = DFR8setpalette(paletteB);
/* Write the uncompressed image data to the HDF file. */
status = DFR8addimage("Example3.hdf", (VOIDP)picture3, WIDTH, HEIGHT, \
COMP_NONE);
status = DFR8addimage("Example3.hdf", (VOIDP)picture4, WIDTH, HEIGHT, \
COMP_NONE);
}
PROGRAM WRITE IMAGE SETS
integer d8spal, d8pimg, d8aimg, status
integer*4 COMP_RLE, COMP_NONE, WIDTH, HEIGHT
parameter (COMP_RLE = 11,
+ COMP_NONE = 0,
+ WIDTH = 20,
+ HEIGHT = 20)
integer paletteA(768), paletteB(768)
integer picture1(WIDTH, HEIGHT), picture2(WIDTH, HEIGHT)
integer picture3(WIDTH, HEIGHT), picture4(WIDTH, HEIGHT)
C Initialize the image data.
do 20 j = 1, WIDTH
do 10 i = 1, HEIGHT
picture1(j, i) = 1
picture2(j, i) = 1
picture3(j, i) = 1
picture4(j, i) = 1
10 continue
20 continue
C Set the first palette.
status = d8spal(paletteA)
C Write the compressed image data to the HDF file.
status = d8pimg(`Example3.hdf', picture1, WIDTH, HEIGHT,
+ COMP_RLE)
status = d8aimg(`Example3.hdf', picture2, WIDTH, HEIGHT,
+ COMP_RLE)
C Set the second palette.
status = d8spal(paletteB)
C Write the uncompressed image data to the HDF file.
status = d8aimg(`Example3.hdf', picture3, WIDTH, HEIGHT,
+ COMP_NONE)
status = d8aimg(`Example3.hdf', picture4, WIDTH, HEIGHT,
+ COMP_NONE)
end
#include "hdf.h"
#include "hcomp.h"
#define WIDTH 3
#define HEIGHT 5
#define PIXEL_DEPTH 3
main( )
{
/* Initialize the image array. */
static uint8 raster_data[HEIGHT][WIDTH][PIXEL_DEPTH] =
{ 1, 2, 3, 4, 5, 6, 7, 8, 9,
10,11,12, 13,14,15, 16,17,18,
19,20,21, 22,23,24, 25,26,27,
28,29,30, 31,32,33, 34,35,36,
37,38,39, 40,41,42, 43,44,45 };
static comp_info compress_info;
intn status;
/* Initialize JPEG compression structure. */
compress_info.jpeg.quality = 60;
compress_info.jpeg.force_baseline = 1;
/* Set JPEG compression for storing the image. */
status = DFR8setcompress(COMP_JPEG, &compress_info);
/* Write the 8-bit image data to file. */
status = DFR8addimage("Example2.hdf", (VOIDP)raster_data, WIDTH,
HEIGHT, COMP_JPEG);
}
PROGRAM COMPRESS RIS8
integer d8aimg, d8scomp, d8sjpeg, status
integer*4 WIDTH, HEIGHT, PIXEL_DEPTH, COMP_JPEG
C COMP_JPEG is defined in hcomp.h.
parameter(WIDTH = 3,
+ HEIGHT = 5,
+ COMP_JPEG = 1,
+ PIXEL_DEPTH = 3)
character raster_data(PIXEL_DEPTH, WIDTH, HEIGHT)
C Initialize the image array.
data raster_data
+ / 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10,11,12, 13,14,15, 16,17,18,
+ 19,20,21, 22,23,24, 25,26,27,
+ 28,29,30, 31,32,33, 34,35,36,
+ 37,38,39, 40,41,42, 43,44,45 /
C Set compression.
status = d8scomp(COMP_JPEG)
C Set JPEG parameters to quality = 60, and turn compatibility on.
status = d8sjpeg(60, 1)
C Write the 8-bit image data to the HDF file.
status = d8aimg(`Example2.hdf', raster_data, WIDTH, HEIGHT,
+ COMP_JPEG)
end
#include "hdf.h"
#define WIDTH 5
#define HEIGHT 6
main( )
{
uint8 raster_data[HEIGHT][WIDTH];
int32 width, height;
intn haspal, status;
/* Get the dimensions of the image */
status = DFR8getdims("Example1.hdf", &width, &height, &haspal);
/* Read the raster data if the dimensions are correct */
if (width <= WIDTH && height <= HEIGHT)
status = DFR8getimage("Example1.hdf", (VOIDP)raster_data, width,
height, NULL);
}
PROGRAM RASTER8
character*1 image(5, 6)
integer status, height, width, d8gimg, d8gdims, haspal
integer*4 width, height
C Get the dimensions of the image.
status = d8gdims(`Example1.hdf', width, height, haspal)
C Read the raster data if the dimensions are correct.
if (width .le. 5 .and. height .le. 6) then
status = d8gimg(`Example1.hdf', image, width, height, 0)
endif
end
PROGRAM GET LABEL LIST
integer dallist
integer*4 DFTAG_NDG, LISTSIZE, DFS_MAXLEN
parameter (DFTAG_NDG = 720,
+ LISTSIZE = 20,
+ DFS_MAXLEN = 255)
character*60 label_list(DFS_MAXLEN*LISTSIZE)
integer i, num_of_labels, start_position, ref_list(DFS_MAXLEN)
start_position = 1
num_of_labels = dallist(`Example1.hdf', DFTAG_NDG, ref_list,
+ label_list, 10, DFS_MAXLEN,
+ start_position)
do 10 i = 1, num_of_labels
print *,' Ref number: `,ref_list(i),
+ ` Label: `,label_list(i)
10 continue
end