Example #1
0
JNIEXPORT jlong JNICALL
Java_hdf_hdflib_HDFLibrary_Vgetid
(JNIEnv *env, jclass clss, jlong fid, jint vgroup_ref)
{
    int32 rval;

    rval = Vgetid((int32)fid, (int32)vgroup_ref);
    if (rval == FAIL)
        CALL_ERROR_CHECK();

    return (jlong)rval;
}
Example #2
0
static void
test_vgisinternal()
{
    int32   fid, vgroup_id;
    intn    is_internal = FALSE;
    int32   vref = -1;
    intn    ii, status;
    char testfile[H4_MAX_NC_NAME] = "";
    char    internal_array2[2] = {TRUE, TRUE};
    intn    num_errs = 0;     /* number of errors so far */

    /* Use a GR file to test Vgisinternal on internal vgroups */

    /* The file GR_FILE is an existing file in the test_files directory,
       make_datafilename builds the file name with correct path */
    if (make_datafilename(GR_FILE, testfile, H4_MAX_NC_NAME) != FAIL)
    {
	/* Open the old GR file and initialize the V interface */
	fid = Hopen(testfile, DFACC_READ, 0);
	CHECK_VOID(fid, FAIL, "Hopen: grtdfui83.hdf");
	status = Vstart(fid);
	CHECK_VOID(status, FAIL, "Vstart");

	ii = 0;
	while ((vref = Vgetid(fid, vref)) != FAIL)
	{     /* until no more vgroups */
	    vgroup_id = Vattach(fid, vref, "r"); /* attach to vgroup */

	    /* Test that the current vgroup is or is not internal as specified
	       in the array internal_array2 */
	    is_internal = Vgisinternal(vgroup_id);
	    CHECK_VOID(is_internal, FAIL, "Vgisinternal");
  	    VERIFY_VOID(is_internal, internal_array2[ii], "Vgisinternal");

	    status = Vdetach(vgroup_id);
	    CHECK_VOID(status, FAIL, "Vdetach");

	    ii++; /* increment vgroup index */
	}

	/* Terminate access to the V interface and close the file */
	status = Vend(fid);
	CHECK_VOID(status, FAIL, "Vend");
	status = Hclose(fid);
	CHECK_VOID(status, FAIL, "Hclose");
    }
    else
    {
	fprintf(stderr, "ERROR>>> Unable to make filename for %s\n", GR_FILE);
	H4_FAILED()
    }
}   /* test_vgisinternal */
Example #3
0
static int init_Vgroups(coda_hdf4_product *product)
{
    int32 vgroup_ref;
    int result;
    int i;

    vgroup_ref = Vgetid(product->file_id, -1);
    while (vgroup_ref != -1)
    {
        if (product->num_vgroup % BLOCK_SIZE == 0)
        {
            coda_hdf4_Vgroup **vgroup;
            int i;

            vgroup = realloc(product->vgroup, (product->num_vgroup + BLOCK_SIZE) * sizeof(coda_hdf4_Vgroup *));
            if (vgroup == NULL)
            {
                coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
                               (long)(product->num_vgroup + BLOCK_SIZE) * sizeof(coda_hdf4_Vgroup *), __FILE__,
                               __LINE__);
                return -1;
            }
            product->vgroup = vgroup;
            for (i = product->num_vgroup; i < product->num_vgroup + BLOCK_SIZE; i++)
            {
                product->vgroup[i] = NULL;
            }
        }
        product->num_vgroup++;
        /* This will not yet create the links to the entries of the Vgroup */
        product->vgroup[product->num_vgroup - 1] = coda_hdf4_Vgroup_new(product, vgroup_ref);
        if (product->vgroup[product->num_vgroup - 1] == NULL)
        {
            return -1;
        }
        vgroup_ref = Vgetid(product->file_id, vgroup_ref);
    }

    /* Now for each Vgroup create the links to its entries */
    for (i = 0; i < product->num_vgroup; i++)
    {
        coda_hdf4_Vgroup *type;
        int32 num_entries;

        type = product->vgroup[i];
        num_entries = Vntagrefs(type->vgroup_id);
        if (num_entries < 0)
        {
            coda_set_error(CODA_ERROR_HDF4, NULL);
            return -1;
        }

        if (num_entries > 0 && !type->hide)
        {
            int32 *tags;
            int32 *refs;
            int j;

            type->entry = malloc(num_entries * sizeof(coda_hdf4_type *));
            if (type->entry == NULL)
            {
                coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
                               (long)num_entries * sizeof(coda_hdf4_type *), __FILE__, __LINE__);
                return -1;
            }
            tags = malloc(num_entries * sizeof(int32));
            if (tags == NULL)
            {
                coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
                               (long)num_entries * sizeof(int32), __FILE__, __LINE__);
                return -1;
            }
            refs = malloc(num_entries * sizeof(int32));
            if (refs == NULL)
            {
                coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
                               (long)num_entries * sizeof(int32), __FILE__, __LINE__);
                free(tags);
                return -1;
            }

            result = Vgettagrefs(type->vgroup_id, tags, refs, num_entries);
            if (result != num_entries)
            {
                coda_set_error(CODA_ERROR_HDF4, NULL);
                free(refs);
                free(tags);
                return -1;
            }

            for (j = 0; j < num_entries; j++)
            {
                int32 index;
                int k;

                switch (tags[j])
                {
                case DFTAG_RIG:
                case DFTAG_RI:
                case DFTAG_RI8:
                    index = GRreftoindex(product->gr_id, (uint16)refs[j]);
                    if (index != -1)
                    {
                        for (k = 0; k < product->num_images; k++)
                        {
                            if (product->gri[k]->index == index)
                            {
                                product->gri[k]->group_count++;
                                if (coda_type_record_create_field(type->definition, product->gri[k]->gri_name,
                                                                  (coda_type *)product->gri[k]->definition) != 0)
                                {
                                    free(refs);
                                    free(tags);
                                    return -1;
                                }
                                type->entry[type->definition->num_fields - 1] = (coda_hdf4_type *)product->gri[k];
                                break;
                            }
                        }
                        /* if k == product->num_images then the Vgroup links to a non-existent GRImage and
                         * we ignore the entry */
                    }
                    /* if index == -1 then the Vgroup links to a non-existent GRImage and we ignore the entry */
                    break;
                case DFTAG_SD:
                case DFTAG_SDG:
                case DFTAG_NDG:
                    index = SDreftoindex(product->sd_id, refs[j]);
                    if (index != -1)
                    {
                        for (k = 0; k < product->num_sds; k++)
                        {
                            if (product->sds[k]->index == index)
                            {
                                product->sds[k]->group_count++;
                                if (coda_type_record_create_field(type->definition, product->sds[k]->sds_name,
                                                                  (coda_type *)product->sds[k]->definition) != 0)
                                {
                                    free(refs);
                                    free(tags);
                                    return -1;
                                }
                                type->entry[type->definition->num_fields - 1] = (coda_hdf4_type *)product->sds[k];
                                break;
                            }
                        }
                        /* if k == product->num_sds then the Vgroup links to a non-existent SDS and
                         * we ignore the entry */
                    }
                    /* if index == -1 then the Vgroup links to a non-existent SDS and we ignore the entry */
                    break;
                case DFTAG_VH:
                case DFTAG_VS:
                    for (k = 0; k < product->num_vdata; k++)
                    {
                        if (product->vdata[k]->ref == refs[j])
                        {
                            if (!product->vdata[k]->hide)
                            {
                                product->vdata[k]->group_count++;
                                if (coda_type_record_create_field(type->definition, product->vdata[k]->vdata_name,
                                                                  (coda_type *)product->vdata[k]->definition) != 0)
                                {
                                    free(refs);
                                    free(tags);
                                    return -1;
                                }
                                type->entry[type->definition->num_fields - 1] = (coda_hdf4_type *)product->vdata[k];
                            }
                            break;
                        }
                    }
                    /* if k == product->num_vdata then the Vgroup links to a non-existent Vdata and
                     * we ignore the entry */
                    break;
                case DFTAG_VG:
                    for (k = 0; k < product->num_vgroup; k++)
                    {
                        if (product->vgroup[k]->ref == refs[j])
                        {
                            if (!product->vgroup[k]->hide)
                            {
                                product->vgroup[k]->group_count++;
                                if (coda_type_record_create_field(type->definition, product->vgroup[k]->vgroup_name,
                                                                  (coda_type *)product->vgroup[k]->definition) != 0)
                                {
                                    free(refs);
                                    free(tags);
                                    return -1;
                                }
                                type->entry[type->definition->num_fields - 1] =
                                    (coda_hdf4_type *)product->vgroup[k];
                            }
                            break;
                        }
                    }
                    /* if k == product->num_vgroup then the Vgroup links to a non-existent Vgroup and
                     * we ignore the entry */
                    break;
                default:
                    /* The Vgroup contains an unsupported item and we ignore the entry */
                    break;
                }
            }
            free(refs);
            free(tags);
        }
    }

    return 0;
}
int main( )
{
   /************************* Variable declaration **************************/

   intn   status_n;     /* returned status for functions returning an intn  */
   int32  status_32,    /* returned status for functions returning an int32 */
          file_id, vgroup_id, vgroup_ref, vdata_id, vdata_ref,
	  num_of_records, num_of_vals_per_rec, record_pos,
          obj_index,    /* index of an object within a vgroup */
          num_of_pairs, /* number of tag/ref number pairs, i.e., objects */
          obj_tag, obj_ref,     /* tag/ref number of an HDF object */
          vgroup_pos = 0;       /* position of a vgroup in the file */
   float32 databuf[N_RECORDS][N_VALS_PER_REC];
   int16 rec_num;

   /********************** End of variable declaration ***********************/

   char FIELDNAME_LIST[MAX_FIELDNAME_LIST_LENGTH];
   memset(FIELDNAME_LIST, 0x00, MAX_FIELDNAME_LIST_LENGTH);
   int i;
   for (i = 0; i < N_VALS_PER_REC; i++) {
	   char buffer[256];
	   if (i == 0) {
		   sprintf(buffer, "%d", i);
	   } else {
		   sprintf(buffer, " %d", i);
	   }
	   strcat(FIELDNAME_LIST, buffer);
   }
   file_id = Hopen (FILE_NAME, DFACC_READ, 0);

   status_n = Vstart (file_id);

   vgroup_ref = -1;

   vgroup_ref = Vgetid (file_id, vgroup_ref);
   if (vgroup_ref == -1) exit(1);
   vgroup_ref = Vgetid (file_id, vgroup_ref);
   if (vgroup_ref == -1) exit(1);

   vgroup_id = Vattach (file_id, vgroup_ref, "r"); 

   num_of_pairs = Vntagrefs (vgroup_id);

   if (num_of_pairs > 0)
   {
	   printf ("\nVgroup #%d contains:\n", vgroup_pos);
	   for (obj_index = 0; obj_index < num_of_pairs; obj_index++)
	   {
		   status_n = Vgettagref (vgroup_id, obj_index, &obj_tag, &obj_ref);
		   printf ("tag = %d, ref = %d", obj_tag, obj_ref);


		   if (Visvg (vgroup_id, obj_ref))
			   printf ("  <-- is a vgroup\n");
		   else if (Visvs (vgroup_id, obj_ref)) {
			   printf ("  <-- is a vdata\n");
			   vdata_ref = VSfind (file_id, VDATA_NAME);
			   vdata_id = VSattach (file_id, vdata_ref, "r");
			   status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
			   record_pos = VSseek (vdata_id, RECORD_INDEX);
			   num_of_records =
				   VSread (vdata_id, (uint8 *)databuf, N_RECORDS, FULL_INTERLACE);
			   for (rec_num = 0; rec_num < num_of_records; rec_num++)
			   {
				   for (num_of_vals_per_rec = 0; num_of_vals_per_rec < N_VALS_PER_REC; num_of_vals_per_rec++) {
					   printf ("%6.2f\n", databuf[rec_num][num_of_vals_per_rec]);

				   }
			   }
		   }
		   else {
			   printf ("  <-- neither vdata nor vgroup\n");
		   }
	   } /* for */
   } /* if */

   else
	   printf ("Vgroup #%d contains no HDF objects\n", vgroup_pos);

   /*
    * Terminate access to the current vgroup.
    */
   status_32 = Vdetach (vgroup_id);

   /*
    * Move to the next vgroup position.
    */
   vgroup_pos++;

   /*
   * Terminate access to the V interface and close the file.
   */
   status_n = Vend (file_id);
   status_n = Hclose (file_id);
   return 0;
}