SingleGroup and MultiGroup Structures



next up previous
Next: Example Programs Up: A Descritpion of the Previous: Append versus Overwrite

SingleGroup and MultiGroup Structures

The SingleGroup and MultiGroup structures have been changed. They are now:

    219:    typedef struct {
    220:            char *filename;
    221:            int group_num;
    222:            Hdr *globalhdr;
    223:            SciHdrData sci;
    224:            ErrHdrData err;
    225:            DQHdrData dq;
    226:    } SingleGroup;
    227:    
    228:    typedef struct {
    229:            char *filename;
    230:            int group_num;
    231:            Hdr *globalhdr;
    232:            SciHdrData sci;
    233:            ErrHdrData err;
    234:            DQHdrData dq;
    235:            SmplHdrData smpl;
    236:            IntgHdrData intg;
    237:    } SingleNicmosGroup;

This is much more convenient than the previous definition because it makes a multi-group merely an array of single groups. However, this complicates the handling of the global header. Fortunately, this complication is completely buried in the I/O routines, at least if you use the normal init-alloc-free routines. Here's what those routines do. The SingleGroup case is fairly easy to handle. InitSingleGroup merely sets the pointer globalhdr to NULL, allocSingleGroup allocates it, and freeSingleGroup frees it. For a multigroup, group[0] contains the space for the actually allocated filename and the global header. The other groups in the multi-group merely point to the same allocated space. This means that there is only one global header and one filename, so it doesn't matter which group you use to change things in the global header. The freeMultiGroup routine is smart enough to free only group[0]. Neither input nor output have to be changed; everything should work just as before.

In the test examples, output has been copied from input. Handling output from scratch, i. e. generating it from completely new data, might take some explanation. Here's a code fragment as an example. Notice that the individual groups within a MultiGroup do not have to have the same dimensionality.

        SingleGroup sg;
        MultiGroup mg;

        initSingleGroup(&sg);
        initMultiGroup(&mg);

        allocSingleGroup(&sg,128,128);
        ... fill the global header ...
        ... fill the data arrays ...
        putSingleGroup("filename",1,&sg,0);
        freeSingleGroup(&sg);

        allocMultiGroup(&mg,3);
        allocSingleGroup(&mg.group[0],128,128);
        allocSingleGroup(&mg.group[1],256,256);
        allocSingleGroup(&mg.group[2],512,512);

        ... fill the global header ...
        ... fill data group[0] ...
        ... fill data group[1] ...
        ... fill data group[2] ...

        for (k = 0; k < 3; ++k)
            putMultiGroup("filename",(k + 1),&mg,k,0);
        freeMultiGroup(&mg);



Sdas Group
Wed Aug 21 10:27:26 EDT 1996