Esempio n. 1
0
JNIEXPORT jint JNICALL
Java_hdf_hdflib_HDFLibrary_Vlone
(JNIEnv *env, jclass clss, jlong fid, jintArray ref_array, jint arraysize)
{
    int retVal = -1;
    jint * arr;
    jboolean bb;

    if (ref_array == NULL) {
        h4nullArgument(env, "Vlone: ref_array is NULL");
    } /* end if */
    else if (ENVPTR->GetArrayLength(ENVPAR ref_array) < arraysize) {
        h4badArgument(env, "Vlone: output array ref_array < order 'arraysize'");
    } /* end else if */
    else {
        arr = ENVPTR->GetIntArrayElements(ENVPAR ref_array,&bb);

        if (arr == NULL) {
            h4JNIFatalError(env, "Vlone: ref_array not pinned");
        } /* end if */
        else {
            /* get the lone group reference number in the vgroup */
            retVal = Vlone((int32)fid, (int32 *)arr, arraysize);

            if (retVal == FAIL)
                CALL_ERROR_CHECK();

            ENVPTR->ReleaseIntArrayElements(ENVPAR ref_array,arr, 0);
        } /* end else */
    } /* end else */

    return retVal;
}
Esempio n. 2
0
int list_vg(int32 infile_id,
            int32 outfile_id,
            int32 sd_id,
            int32 sd_out,
            int32 gr_id,
            int32 gr_out,
            list_table_t *list_tbl,
            dim_table_t *td1,
            dim_table_t *td2,
            options_t *options)
{
   

    int32  vg_id;          /* vgroup identifier */
    int32  nlones = 0;     /* number of lone vgroups */
    int32  ntagrefs;       /* number of tag/ref pairs in a vgroup */
    int32  *ref_array=NULL;/* buffer to hold the ref numbers of lone vgroups   */
    int32  *tags=NULL;     /* buffer to hold the tag numbers of vgroups   */
    int32  *refs=NULL;     /* buffer to hold the ref numbers of vgroups   */
    int32  vgroup_id_out=0;/* vgroup identifier */
    int32  tag_vg;
    int32  ref_vg;
    char   *vg_name;
    char   *vg_class;
    uint16 name_len;
    int32  i;
    
   /*-------------------------------------------------------------------------
    * initialize the V interface
    *-------------------------------------------------------------------------
    */
    
    if (Vstart(infile_id) == FAIL)  
    {
        return FAIL;
    } 
    
    if (options->trip==1)
    {
        if (Vstart(outfile_id) == FAIL)  
        {
            return FAIL;
        }
    }
    
   /*-------------------------------------------------------------------------
    * get and print the names and class names of all the lone vgroups.
    * first, call Vlone with nlones set to 0 to get the number of
    * lone vgroups in the file, but not to get their reference numbers.
    *-------------------------------------------------------------------------
    */
    nlones = Vlone (infile_id, NULL, nlones );
    
    if (nlones > 0)
    {
       /*
        * use the nlones returned to allocate sufficient space for the
        * buffer ref_array to hold the reference numbers of all lone vgroups,
        */
        ref_array = (int32 *) malloc(sizeof(int32) * nlones);
        
       /*
        * and call Vlone again to retrieve the reference numbers into 
        * the buffer ref_array.
        */
        nlones = Vlone (infile_id, ref_array, nlones);
        
       /*
        * iterate tru each lone vgroup.
        */
        for (i = 0; i < nlones; i++)
        {

            int32 ref = ref_array[i];
	    uint16 name_len;

           /*
            * attach to the current vgroup then get its
            * name and class. note: the current vgroup must be detached before
            * moving to the next.
            */
            if ((vg_id = Vattach (infile_id, ref, "r"))==FAIL)
            {
                printf("Error: Could not attach group with ref <%d>\n", ref);
                goto out;
            }

	    /* Get vgroup's name */
            if (Vgetnamelen(vg_id, &name_len)==FAIL)
            {
                printf("Error: Could not get name length for group with ref <%d>\n", ref);
                goto out;
            }
            vg_name = (char *) HDmalloc(sizeof(char) * (name_len+1));

            if (Vgetname (vg_id, vg_name)==FAIL)
            {
                printf( "Could not get name for group\n");
                goto out;
                
            }

	    /* Get vgroup's class name */
            if (Vgetclassnamelen(vg_id, &name_len)==FAIL)
            {
                printf("Error: Could not get name length for group with ref <%d>\n", ref);
                goto out;
            }


            vg_class = (char *) HDmalloc(sizeof(char) * (name_len+1));

            if (Vgetclass (vg_id, vg_class)==FAIL)
            {
                printf( "Could not get class for group\n");
                goto out;
            }
            
            /* ignore reserved HDF groups/vdatas */
            if( is_reserved(vg_class))
            {
                if (Vdetach (vg_id)==FAIL)
                {
                    printf( "Could not detach group\n");
                    goto out;
                }
                continue;
            }
            if(strcmp(vg_name,GR_NAME)==0) 
            {
                if (Vdetach (vg_id)==FAIL)
                {
                    printf( "Could not detach group\n");
                    goto out;
                }
                continue;
            }
            
            /* get ref, tag */
            if ((ref_vg = VQueryref(vg_id))==FAIL)
            {
                printf( "Failed to get ref for <%s>\n", vg_name);
                goto out;
            }
            if ((tag_vg = VQuerytag(vg_id))==FAIL)
            {
                printf( "Failed to get tag for <%s>\n", vg_name);
                goto out;
            }
            
           /*-------------------------------------------------------------------------
            * add object to table
            *-------------------------------------------------------------------------
            */
            list_table_add(list_tbl,tag_vg,ref_vg,vg_name);
            
            if (options->verbose)
                printf(PFORMAT,"","","",vg_name);  
            
            if (options->trip==1)
            {
                
               /* 
                * create the group in the output file.  the vgroup reference number is set
                * to -1 for creating and the access mode is "w" for writing 
                */
                vgroup_id_out = Vattach (outfile_id, -1, "w");
                if (Vsetname (vgroup_id_out, vg_name)==FAIL)
                {
                    printf("Error: Could not create group <%s>\n", vg_name);
                    goto out;
                }
                if (Vsetclass (vgroup_id_out, vg_class)==FAIL)
                {
                    printf("Error: Could not create group <%s>\n", vg_name);
                    goto out;
                }
                
                if (copy_vgroup_attrs(vg_id,vgroup_id_out,vg_name,options)<0)
                    goto out;
                if (copy_vg_an(infile_id,outfile_id,vg_id,vgroup_id_out,vg_name,options)<0)
                    goto out;
            }
            
            
            
            /* insert objects for this group */
            ntagrefs = Vntagrefs(vg_id);
            if ( ntagrefs > 0 )
            {
                tags = (int32 *) malloc(sizeof(int32) * ntagrefs);
                refs = (int32 *) malloc(sizeof(int32) * ntagrefs);
                if (Vgettagrefs(vg_id, tags, refs, ntagrefs)<0)
                    goto out;
                
                if (vgroup_insert(infile_id,
                    outfile_id,
                    sd_id,
                    sd_out,
                    gr_id,
                    gr_out,
                    vgroup_id_out,
                    vg_name,
                    tags,
                    refs,
                    ntagrefs,
                    list_tbl,
                    td1,
                    td2,
                    options)<0) {
                    goto out;
                }
                
                free (tags);
                tags=NULL;
                free (refs);
                refs=NULL;
            }
            
            if(Vdetach (vg_id)==FAIL)
            {
                printf("Error: Could not detach group <%s>\n", vg_name);
                goto out;
            }
            if (options->trip==1)
            {
                if (Vdetach (vgroup_id_out)==FAIL)
                {
                    printf("Error: Could not detach group <%s>\n", vg_name);
                    goto out;
                }
            }

            free (vg_name);
            
  } /* for nlones */
  
  
  /* free the space allocated */
  if (ref_array!=NULL) 
      free (ref_array);

 } /* if  nlones */
 

/*-------------------------------------------------------------------------
 * terminate access to the V interface
 *-------------------------------------------------------------------------
 */
 
 if (Vend (infile_id)==FAIL)
 {
     printf("Error: Could not end group interface in <%s>\n", vg_name);
     return FAIL;
 }
 if (options->trip==1)
 {
     if (Vend (outfile_id)==FAIL){
         printf("Error: Could not end group interface in <%s>\n", vg_name);
         return FAIL;
     }
 }
 
 return SUCCEED;
 
 
out:
 
 Vend (infile_id);
 if (options->trip==1)
     Vend (outfile_id);
 
 /* free the space allocated */
 if (ref_array!=NULL) 
     free (ref_array);
 if (tags!=NULL) 
     free (tags);
 if (refs!=NULL) 
     free (refs);
 
 return FAIL;
 
}