Now we know nearly enough to rewrite our
-fitting program
so that it reads data from and HDF file into dynamically sized
arrays. But before we do that, still a few comments about file and
data sets attributes, i.e., annotations.
Consider the following short program:2.8
program annotate_SDS
use hdf
use dffunc
implicit none
integer :: sd_file_id, sd_file_status, sd_file_attr_status
sd_file_id = sfstart("SDS.hdf", DFACC_WRITE)
sd_file_attr_status = sfscatt(sd_file_id, "File Contents", DFNT_CHAR8, &
30, "Data for the chi^2-fit Program")
sd_file_status = sfend(sd_file_id)
end program annotate_SDS
Observe first that for the sake of conciseness we have dropped definitions
of numerous parameters and, instead, we're passing file names and other
strings directly to the functions (rather than wrapping them into
parameters first). This is a matter of cosmetics. It's good
do have information clearly visible and unwrapped where it is used.
On the other hand, in a long program
this will make it harder to maintain and
modify if you need to change values of some of those parameters
in future.
Anyhow, the only new element in this program is the call:
sd_file_attr_status = sfscatt(sd_file_id, "File Contents", DFNT_CHAR8, &
30, "Data for the chi^2-fit Program")
which creates a file attribute. The name of the attribute is
"File Contents" and the attribute itself is a string of
30 characters: "Data for the chi^2-fit Program".
The program runs quietly, and when it exits, the file SFS.hdf is left modified. Let us inspect it with hdfed:
gustav@blanc:../src 11:29:51 !523 $ hdfed SDS.hdf hdfed> info -all (1) Version Descriptor : (Tag 30) Ref 1 (2) Vdata Storage : (Tag 1963) Ref 14 (3) Vdata : (Tag 1962) Ref 14 (4) Vgroup : (Tag 1965) Ref 15 (5) Number type : (Tag 106) Ref 16 (6) SciData dimension record : (Tag 701) Ref 16 *(7) Numeric Data Group : (Tag 720) Ref 2 (8) Vgroup : (Tag 1965) Ref 17 (9) Vdata Storage : (Tag 1963) Ref 18 (10) Scientific Data : (Tag 702) Ref 8 (11) Vdata : (Tag 1962) Ref 18 (12) Vgroup : (Tag 1965) Ref 19 hdfed>First observe that compared to the last time we looked at it there are two new records in it: items (9) and (11). Let us have a look at record number 9:
hdfed> next tag=1963
hdfed> dump -asci
0: Data for the chi^2-fit Program
hdfed>
So here we have our file annotation.
Now let us try to annotate the scientific data set itself. The following program does it:
program annotate_set_SDS
use hdf
use dffunc
implicit none
integer :: sd_file_id, sd_set_id, sd_set_status, sd_file_status, &
sd_set_attrib_status
sd_file_id = sfstart("SDS.hdf", DFACC_WRITE)
sd_set_id = sfselect(sd_file_id, 0)
sd_set_attrib_status = sfscatt(sd_set_id, "First Set Annotation", &
DFNT_CHAR8, 25, "redshift velocity in km/h")
sd_set_status = sfendacc(sd_set_id)
sd_file_status = sfend(sd_file_id)
end program annotate_set_SDS
As you see we do it exactly the same way as writing annotations on
the file itself. The only difference is that this time we point
function sfscatt to a data set object (sd_set_id)
instead of a file object (sd_file_id).
Inspection of SDS.hdf shows two new records again:
hdfed> info -all (1) Version Descriptor : (Tag 30) Ref 1 (2) Vdata Storage : (Tag 1963) Ref 20 (3) Vdata : (Tag 1962) Ref 20 (4) Vgroup : (Tag 1965) Ref 21 (5) Vdata Storage : (Tag 1963) Ref 22 (6) Vdata : (Tag 1962) Ref 22 (7) Number type : (Tag 106) Ref 23 (8) SciData dimension record : (Tag 701) Ref 23 *(9) Numeric Data Group : (Tag 720) Ref 2 (10) Scientific Data : (Tag 702) Ref 8 (11) Vgroup : (Tag 1965) Ref 24 (12) Vdata Storage : (Tag 1963) Ref 25 (13) Vdata : (Tag 1962) Ref 25 (14) Vgroup : (Tag 1965) Ref 26 hdfed>Let us inspect record number 5:
hdfed> prev tag=1963 ref=22
hdfed> dump -asci
0: redshift velocity in km/h
hdfed>
Here it is! Nothing has been lost.