MOAB: Mesh Oriented datABase  (version 5.4.0)
file-desc.c
Go to the documentation of this file.
00001 #include "mhdf.h"
00002 #include "util.h"
00003 #include "status.h"
00004 #include <assert.h>
00005 #include <stdlib.h>
00006 #include <string.h>
00007 #include <H5Tpublic.h>
00008 #include <H5Dpublic.h>
00009 #include <H5Ppublic.h>
00010 
00011 static struct mhdf_FileDesc* alloc_file_desc( mhdf_Status* status );
00012 static void* realloc_data( struct mhdf_FileDesc** data, size_t append_bytes, mhdf_Status* status );
00013 static char buffer[512];
00014 
00015 static struct mhdf_FileDesc* alloc_file_desc( mhdf_Status* status )
00016 {
00017     struct mhdf_FileDesc* result;
00018     /* allocate a little short of a page */
00019     result = (struct mhdf_FileDesc*)mhdf_malloc( 4000, status );
00020     if( mhdf_isError( status ) ) return 0;
00021 
00022     memset( result, 0, sizeof( struct mhdf_FileDesc ) );
00023     result->total_size = 4000;
00024     result->offset     = ( (unsigned char*)result ) + sizeof( struct mhdf_FileDesc );
00025     return result;
00026 }
00027 
00028 static void* realloc_data( struct mhdf_FileDesc** data, size_t append_bytes, mhdf_Status* status )
00029 {
00030     void* result_ptr;
00031     struct mhdf_FileDesc* const input_ptr = *data;
00032     unsigned char* mem_ptr                = (unsigned char*)input_ptr;
00033     size_t new_size, occupied_size = input_ptr->offset - mem_ptr;
00034 
00035     /* input_ptr->offset - input_ptr == currently occupied size
00036        input_ptr->total_size         == currently allocated size
00037      */
00038 
00039     /* if the end of the allocated space is before the end of the required space */
00040     if( mem_ptr + input_ptr->total_size < input_ptr->offset + append_bytes )
00041     {
00042         if( append_bytes < input_ptr->total_size )
00043             new_size = 2 * input_ptr->total_size;
00044         else
00045             new_size = input_ptr->total_size + append_bytes;
00046         *data = (struct mhdf_FileDesc*)mhdf_realloc( *data, new_size, status );
00047         if( mhdf_isError( status ) ) return 0;
00048 
00049         /* if realloc moved us to a different location in memory,
00050          * we need to update all of the internal pointers to
00051          * new locations relative to the start of the struct */
00052         if( *data != input_ptr )
00053         {
00054             mhdf_fixFileDesc( *data, input_ptr );
00055             mem_ptr           = (unsigned char*)( *data );
00056             ( *data )->offset = mem_ptr + occupied_size;
00057         }
00058         ( *data )->total_size = new_size;
00059     }
00060 
00061     result_ptr = ( *data )->offset;
00062     ( *data )->offset += append_bytes;
00063     return result_ptr;
00064 }
00065 
00066 #define FIX_OFFSET( TYPE, FIELD ) \
00067     if( copy_ptr->FIELD != NULL ) \
00068     copy_ptr->FIELD = (TYPE)( ( (char*)( copy_ptr->FIELD ) - (char*)orig_addr ) + (char*)copy_ptr )
00069 
00070 void mhdf_fixFileDesc( struct mhdf_FileDesc* copy_ptr, const struct mhdf_FileDesc* orig_addr )
00071 {
00072     int i;
00073 
00074     API_BEGIN;
00075     FIX_OFFSET( int*, nodes.dense_tag_indices );
00076     FIX_OFFSET( int*, sets.dense_tag_indices );
00077     FIX_OFFSET( struct mhdf_ElemDesc*, elems );
00078     FIX_OFFSET( struct mhdf_TagDesc*, tags );
00079 
00080     FIX_OFFSET( int*, numEntSets );
00081     FIX_OFFSET( int**, defTagsEntSets );
00082     FIX_OFFSET( int**, defTagsVals );
00083 
00084     for( i = 0; i < 5; i++ )
00085     {
00086         if( copy_ptr->defTagsEntSets ) FIX_OFFSET( int*, defTagsEntSets[i] );
00087         if( copy_ptr->defTagsVals ) FIX_OFFSET( int*, defTagsVals[i] );
00088     }
00089 
00090     if( copy_ptr->elems != NULL )
00091     {
00092         for( i = 0; i < copy_ptr->num_elem_desc; ++i )
00093         {
00094             FIX_OFFSET( const char*, elems[i].handle );
00095             FIX_OFFSET( const char*, elems[i].type );
00096             FIX_OFFSET( int*, elems[i].desc.dense_tag_indices );
00097         }
00098     }
00099 
00100     if( copy_ptr->tags != NULL )
00101     {
00102         for( i = 0; i < copy_ptr->num_tag_desc; ++i )
00103         {
00104             FIX_OFFSET( const char*, tags[i].name );
00105             FIX_OFFSET( void*, tags[i].default_value );
00106             FIX_OFFSET( void*, tags[i].global_value );
00107             FIX_OFFSET( int*, tags[i].dense_elem_indices );
00108         }
00109     }
00110     API_END;
00111 }
00112 
00113 static struct mhdf_FileDesc* get_elem_desc( mhdf_FileHandle file_handle,
00114                                             struct mhdf_FileDesc* result,
00115                                             const char* elem_handle,
00116                                             int idx,
00117                                             mhdf_Status* status )
00118 {
00119     hid_t id_pair[2];
00120     int poly;
00121     void* ptr;
00122     long junk;
00123 
00124     ptr = realloc_data( &result, strlen( elem_handle ) + 1, status );
00125     if( !ptr ) return NULL;
00126     strcpy( ptr, elem_handle );
00127     result->elems[idx].handle = ptr;
00128 
00129     mhdf_getElemTypeName( file_handle, elem_handle, buffer, sizeof( buffer ), status );
00130     if( mhdf_isError( status ) )
00131     {
00132         free( result );
00133         return NULL;
00134     }
00135 
00136     ptr = realloc_data( &result, strlen( buffer ) + 1, status );
00137     if( !ptr ) return NULL;
00138     strcpy( ptr, buffer );
00139     result->elems[idx].type = ptr;
00140 
00141     poly = mhdf_isPolyElement( file_handle, elem_handle, status );
00142     if( mhdf_isError( status ) )
00143     {
00144         free( result );
00145         return NULL;
00146     }
00147 
00148     if( !poly )
00149     {
00150         id_pair[0] = mhdf_openConnectivity( file_handle, elem_handle, &result->elems[idx].desc.vals_per_ent,
00151                                             &result->elems[idx].desc.count, &result->elems[idx].desc.start_id, status );
00152         if( id_pair[0] < 0 )
00153         {
00154             free( result );
00155             return NULL;
00156         }
00157         mhdf_closeData( file_handle, id_pair[0], status );
00158     }
00159     else
00160     {
00161         result->elems[idx].desc.vals_per_ent = -1;
00162         mhdf_openPolyConnectivity( file_handle, elem_handle, &result->elems[idx].desc.count, &junk,
00163                                    &result->elems[idx].desc.start_id, id_pair, status );
00164         if( id_pair[0] < 0 )
00165         {
00166             free( result );
00167             return NULL;
00168         }
00169         mhdf_closeData( file_handle, id_pair[0], status );
00170         mhdf_closeData( file_handle, id_pair[1], status );
00171     }
00172 
00173     result->elems[idx].desc.dense_tag_indices = NULL;
00174     result->elems[idx].desc.num_dense_tags    = 0;
00175     result->elems[idx].have_adj               = mhdf_haveAdjacency( file_handle, result->elems[idx].handle, status );
00176     if( mhdf_isError( status ) )
00177     {
00178         free( result );
00179         return 0;
00180     }
00181 
00182     return result;
00183 }
00184 
00185 static unsigned get_file_id_size( hid_t file_id_type, mhdf_Status* status )
00186 {
00187     if( H5Tget_class( file_id_type ) != H5T_INTEGER )
00188     {
00189         mhdf_setFail( status, "Invalid handle or type class for file ID type." );
00190         return 0;
00191     }
00192 
00193     return H5Tget_size( file_id_type );
00194 }
00195 
00196 static struct mhdf_FileDesc* get_tag_desc( mhdf_FileHandle file_handle,
00197                                            struct mhdf_FileDesc* result,
00198                                            const char* name,
00199                                            int idx,
00200                                            hid_t type,
00201                                            mhdf_Status* status )
00202 {
00203     void* ptr;
00204     int have_default, have_global;
00205     int valsize, size, close_type = 0;
00206     hsize_t array_len;
00207 
00208     ptr = realloc_data( &result, strlen( name ) + 1, status );
00209     if( NULL == ptr ) return NULL;
00210     strcpy( ptr, name );
00211     result->tags[idx].name = ptr;
00212 
00213     mhdf_getTagInfo( file_handle, name, &result->tags[idx].type, &result->tags[idx].size, &result->tags[idx].storage,
00214                      &have_default, &have_global, &result->tags[idx].have_sparse, status );
00215     if( mhdf_isError( status ) )
00216     {
00217         free( result );
00218         return NULL;
00219     }
00220 
00221     /* For variable length tags, have_default and have_global will
00222        contain the size of the respective values.  For fixed-length
00223        tags, they are either zero or one.  Simplify later code by
00224        making them contain the size for both cases. */
00225     valsize = result->tags[idx].size;
00226     if( result->tags[idx].size >= 0 )
00227     {
00228         if( have_default ) have_default = valsize;
00229         if( have_global ) have_global = valsize;
00230     }
00231 
00232     result->tags[idx].default_value      = NULL;
00233     result->tags[idx].default_value_size = have_default;
00234     result->tags[idx].global_value       = NULL;
00235     result->tags[idx].global_value_size  = have_global;
00236 
00237     switch( result->tags[idx].type )
00238     {
00239         case mhdf_OPAQUE:
00240             type = 0;
00241             break;
00242         case mhdf_BOOLEAN:
00243             type = H5T_NATIVE_UCHAR;
00244             break;
00245         case mhdf_INTEGER:
00246             type = H5T_NATIVE_INT;
00247             have_default *= sizeof( int );
00248             have_global *= sizeof( int );
00249             valsize *= sizeof( int );
00250             break;
00251         case mhdf_FLOAT:
00252             type = H5T_NATIVE_DOUBLE;
00253             have_default *= sizeof( double );
00254             have_global *= sizeof( double );
00255             valsize *= sizeof( double );
00256             break;
00257         case mhdf_BITFIELD:
00258             have_default = ( have_default + 7 ) / 8;
00259             have_global  = ( have_global + 7 ) / 8;
00260             valsize      = ( valsize + 7 ) / 8;
00261             switch( valsize )
00262             {
00263                 case 1:
00264                     type = H5Tcopy( H5T_NATIVE_B8 );
00265                     break;
00266                 case 2:
00267                     type = H5Tcopy( H5T_NATIVE_B16 );
00268                     break;
00269                 case 3:
00270                 case 4:
00271                     valsize += 4 - valsize;  // to avoid fallthrough warning
00272                     type = H5Tcopy( H5T_NATIVE_B32 );
00273                     break;
00274                 case 5:
00275                 case 6:
00276                 case 7:
00277                 case 8:
00278                     valsize += 8 - valsize;  // to avoid fallthrough warning
00279                     type = H5Tcopy( H5T_NATIVE_B64 );
00280                     break;
00281                 default:
00282                     free( result );
00283                     mhdf_setFail( status, "Cannot create a bit tag larger than 64-bits.  %d bits requested.\n",
00284                                   (int)valsize );
00285                     return NULL;
00286             }
00287             close_type = 1;
00288             break;
00289         case mhdf_ENTITY_ID:
00290             if( 0 == type ) type = H5T_NATIVE_ULONG;
00291             size = get_file_id_size( type, status );
00292             if( !size )
00293             {
00294                 free( result );
00295                 return NULL;
00296             }
00297             have_default *= size;
00298             have_global *= size;
00299             valsize *= size;
00300             break;
00301         default:
00302             mhdf_setFail( status, "Unknown mhdf_TagDataType value (%d) for tag (\"%s\")", (int)result->tags[idx].type,
00303                           name );
00304             free( result );
00305             return NULL;
00306     }
00307     result->tags[idx].bytes = valsize;
00308 
00309     if( result->tags[idx].type != mhdf_OPAQUE && result->tags[idx].type != mhdf_BITFIELD && result->tags[idx].size > 1 )
00310     {
00311         close_type = 1;
00312         array_len  = result->tags[idx].size;
00313 #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1
00314         type = H5Tarray_create2( type, 1, &array_len );
00315 #else
00316         type = H5Tarray_create( type, 1, &array_len, 0 );
00317 #endif
00318         if( type < 0 )
00319         {
00320             mhdf_setFail( status, "H5Tarray_create failed for tag (\"%s\")", name );
00321             free( result );
00322             return NULL;
00323         }
00324     }
00325 
00326     if( have_default || have_global )
00327     {
00328         if( have_default )
00329         {
00330             ptr = realloc_data( &result, have_default, status );
00331             if( NULL == ptr )
00332             {
00333                 if( close_type )
00334                 {
00335                     H5Tclose( type );
00336                 }
00337                 return NULL;
00338             }
00339             result->tags[idx].default_value = ptr;
00340         }
00341         if( have_global )
00342         {
00343             ptr = realloc_data( &result, have_global, status );
00344             if( NULL == ptr )
00345             {
00346                 if( close_type )
00347                 {
00348                     H5Tclose( type );
00349                 }
00350                 return NULL;
00351             }
00352             result->tags[idx].global_value = ptr;
00353         }
00354         mhdf_getTagValues( file_handle, name, type, result->tags[idx].default_value, result->tags[idx].global_value,
00355                            status );
00356         if( close_type )
00357         {
00358             H5Tclose( type );
00359         }
00360         if( mhdf_isError( status ) )
00361         {
00362             free( result );
00363             return NULL;
00364         }
00365     }
00366 
00367     return result;
00368 }
00369 
00370 static void free_string_list( char** list, int count )
00371 {
00372     int i;
00373     for( i = 0; i < count; ++i )
00374         free( list[i] );
00375     free( list );
00376 }
00377 
00378 struct mhdf_FileDesc* mhdf_getFileSummary( mhdf_FileHandle file_handle,
00379                                            hid_t file_id_type,
00380                                            mhdf_Status* status,
00381                                            int extraSetInfo )
00382 {
00383     struct mhdf_FileDesc* result;
00384     hid_t table_id;
00385     int i, i1, numtags, j, k, size, *indices, have, num_tag_names = 0;
00386     unsigned int ui;
00387     void* ptr;
00388     char **elem_handles = 0, **tag_names = 0;
00389     unsigned char *array, *matrix;
00390     const char* pname[5] = { "PARALLEL_PARTITION", "MATERIAL_SET", "NEUMANN_SET", "DIRICHLET_SET", "GEOM_DIMENSION" };
00391 
00392     long* id_list;
00393     struct mhdf_TagDesc* tag_desc;
00394     long int nval, junk;
00395     hid_t table[3];
00396     hid_t data_type;
00397 
00398     API_BEGIN;
00399 
00400     mhdf_setOkay( status );
00401     result = alloc_file_desc( status );
00402     if( NULL == result ) return NULL;
00403 
00404     /* get node info */
00405     have = mhdf_haveNodes( file_handle, status );
00406     if( mhdf_isError( status ) )
00407     {
00408         free( result );
00409         return NULL;
00410     }
00411     if( have )
00412     {
00413         table_id = mhdf_openNodeCoords( file_handle, &result->nodes.count, &result->nodes.vals_per_ent,
00414                                         &result->nodes.start_id, status );
00415         if( table_id < 0 )
00416         {
00417             free( result );
00418             return NULL;
00419         }
00420         mhdf_closeData( file_handle, table_id, status );
00421     }
00422     else
00423     {
00424         result->nodes.count        = 0;
00425         result->nodes.vals_per_ent = 0;
00426         result->nodes.start_id     = 0;
00427     }
00428 
00429     /* get set info */
00430     result->sets.vals_per_ent = -1;
00431     have                      = mhdf_haveSets( file_handle, &result->have_set_contents, &result->have_set_children,
00432                                                &result->have_set_parents, status );
00433     if( mhdf_isError( status ) )
00434     {
00435         free( result );
00436         return NULL;
00437     }
00438     if( have )
00439     {
00440         table_id = mhdf_openSetMeta( file_handle, &result->sets.count, &result->sets.start_id, status );
00441         if( table_id < 0 )
00442         {
00443             free( result );
00444             return NULL;
00445         }
00446         mhdf_closeData( file_handle, table_id, status );
00447     }
00448     else
00449     {
00450         result->sets.count    = 0;
00451         result->sets.start_id = 0;
00452     }
00453 
00454     /* get element list */
00455     elem_handles = mhdf_getElemHandles( file_handle, &ui, status );
00456     if( elem_handles == NULL )
00457     {
00458         free( result );
00459         return NULL;
00460     }
00461     result->num_elem_desc = ui;
00462 
00463     /* allocate array of element descriptors */
00464     size = result->num_elem_desc * sizeof( struct mhdf_ElemDesc );
00465     ptr  = realloc_data( &result, size, status );
00466     if( NULL == ptr )
00467     {
00468         free( elem_handles );
00469         return NULL;
00470     }
00471     memset( ptr, 0, size );
00472     result->elems = ptr;
00473 
00474     /* Initialize each element descriptor */
00475     for( i = 0; i < result->num_elem_desc; ++i )
00476     {
00477         result = get_elem_desc( file_handle, result, elem_handles[i], i, status );
00478         if( NULL == result )
00479         {
00480             free( elem_handles );
00481             return NULL;
00482         }
00483     }
00484 
00485     /* get tag list */
00486     tag_names = mhdf_getTagNames( file_handle, &num_tag_names, status );
00487     if( mhdf_isError( status ) )
00488     {
00489         free( elem_handles );
00490         free( result );
00491         return NULL;
00492     }
00493 
00494     /* allocate array of tag descriptors */
00495     size = num_tag_names * sizeof( struct mhdf_TagDesc );
00496     ptr  = realloc_data( &result, size, status );
00497     if( NULL == ptr )
00498     {
00499         free( elem_handles );
00500         free_string_list( tag_names, result->num_tag_desc );
00501         return NULL;
00502     }
00503     memset( ptr, 0, size );
00504     result->tags         = ptr;
00505     result->num_tag_desc = num_tag_names;
00506     memset( result->tags, 0, size );
00507 
00508     /* Initialize each tag descriptor */
00509     for( i = 0; i < result->num_tag_desc; ++i )
00510     {
00511         result = get_tag_desc( file_handle, result, tag_names[i], i, file_id_type, status );
00512         if( NULL == result )
00513         {
00514             free( elem_handles );
00515             free_string_list( tag_names, num_tag_names );
00516             return NULL;
00517         }
00518     }
00519 
00520     /* Determine which dense tags are present */
00521 
00522     size  = ( 2 + result->num_elem_desc ) * result->num_tag_desc;
00523     array = mhdf_malloc( size, status );
00524     if( NULL == array )
00525     {
00526         free( elem_handles );
00527         free_string_list( tag_names, num_tag_names );
00528         free( result );
00529         return NULL;
00530     }
00531     memset( array, 0, size );
00532     matrix = array + ( 2 * result->num_tag_desc );
00533 
00534     for( j = 0; j < result->num_tag_desc; ++j )
00535     {
00536         if( mhdf_haveDenseTag( file_handle, tag_names[j], mhdf_node_type_handle(), status ) )
00537             matrix[-1 * result->num_tag_desc + j] = 1;
00538         if( mhdf_haveDenseTag( file_handle, tag_names[j], mhdf_set_type_handle(), status ) )
00539             matrix[-2 * result->num_tag_desc + j] = 1;
00540         for( i = 0; i < result->num_elem_desc; ++i )
00541             if( mhdf_haveDenseTag( file_handle, tag_names[j], elem_handles[i], status ) )
00542                 matrix[i * result->num_tag_desc + j] = 1;
00543     }
00544     free( elem_handles );
00545     free_string_list( tag_names, result->num_tag_desc );
00546 
00547     /* Populate dense tag lists for element types */
00548     for( i = -2; i < result->num_elem_desc; ++i )
00549     {
00550         size = 0;
00551         for( j = 0; j < result->num_tag_desc; ++j )
00552             size += matrix[i * result->num_tag_desc + j];
00553         if( !size )
00554         {
00555             indices = NULL;
00556         }
00557         else
00558         {
00559             indices = realloc_data( &result, size * sizeof( int ), status );
00560             if( NULL == indices )
00561             {
00562                 free( array );
00563                 return NULL;
00564             }
00565 
00566             k = 0;
00567             for( j = 0; j < result->num_tag_desc; ++j )
00568                 if( matrix[i * result->num_tag_desc + j] ) indices[k++] = j;
00569             assert( k == size );
00570         }
00571 
00572         if( i == -2 )
00573         {
00574             result->sets.dense_tag_indices = indices;
00575             result->sets.num_dense_tags    = size;
00576         }
00577         else if( i == -1 )
00578         {
00579             result->nodes.dense_tag_indices = indices;
00580             result->nodes.num_dense_tags    = size;
00581         }
00582         else
00583         {
00584             result->elems[i].desc.dense_tag_indices = indices;
00585             result->elems[i].desc.num_dense_tags    = size;
00586         }
00587     }
00588 
00589     /* Populate dense tag lists for each tag */
00590     for( j = 0; j < result->num_tag_desc; ++j )
00591     {
00592         size = 0;
00593         for( i = -2; i < result->num_elem_desc; ++i )
00594             size += matrix[i * result->num_tag_desc + j];
00595         if( !size )
00596         {
00597             indices = 0;
00598         }
00599         else
00600         {
00601             indices = realloc_data( &result, size * sizeof( int ), status );
00602             if( NULL == ptr )
00603             {
00604                 free( array );
00605                 return NULL;
00606             }
00607 
00608             k = 0;
00609             for( i = -2; i < result->num_elem_desc; ++i )
00610                 if( matrix[i * result->num_tag_desc + j] ) indices[k++] = i;
00611             assert( k == size );
00612         }
00613 
00614         result->tags[j].num_dense_indices  = size;
00615         result->tags[j].dense_elem_indices = indices;
00616     }
00617 
00618     if( extraSetInfo )
00619     {
00620         /* open the table for parallel partitions, material sets, neumann sets,
00621          * dirichlet sets
00622          *  to determine number of parts, etc
00623          *   this is needed for iMOAB and VisIt plugin */
00624         const int NPRIMARY_SETS = 5;
00625         ptr                     = realloc_data( &result, NPRIMARY_SETS * sizeof( int ), status );
00626         if( NULL == ptr || mhdf_isError( status ) )
00627         {
00628             free( array );
00629             return NULL;
00630         }
00631         result->numEntSets = ptr;
00632         for( i = 0; i < NPRIMARY_SETS; ++i )
00633             result->numEntSets[i] = 0;
00634 
00635         ptr = realloc_data( &result, NPRIMARY_SETS * sizeof( int* ), status );
00636         if( NULL == ptr || mhdf_isError( status ) )
00637         {
00638             free( array );
00639             return NULL;
00640         }
00641         result->defTagsEntSets = ptr;
00642 
00643         ptr = realloc_data( &result, NPRIMARY_SETS * sizeof( int* ), status );
00644         if( NULL == ptr || mhdf_isError( status ) )
00645         {
00646             free( array );
00647             return NULL;
00648         }
00649         result->defTagsVals = ptr;
00650         numtags             = result->num_tag_desc;
00651 
00652         for( i = 0; i < numtags; i++ )
00653         {
00654             tag_desc = &( result->tags[i] );
00655             for( k = 0; k < NPRIMARY_SETS; k++ ) /* number of default tags to consider */
00656             {
00657                 if( strcmp( pname[k], tag_desc->name ) == 0 )
00658                 {
00659                     if( tag_desc->have_sparse )
00660                     {
00661                         mhdf_openSparseTagData( file_handle, pname[k], &nval, &junk, table, status );
00662                         if( mhdf_isError( status ) )
00663                         {
00664                             free( array );
00665                             return NULL;
00666                         }
00667                         /* for sparse tags, read */
00668                         result->numEntSets[k] = nval;
00669                         if( nval <= 0 ) continue; /* do not do anything */
00670 
00671                         ptr = realloc_data( &result, nval * sizeof( int ), status );
00672                         if( NULL == ptr || mhdf_isError( status ) )
00673                         {
00674                             free( array );
00675                             return NULL;
00676                         }
00677                         memset( ptr, 0, nval * sizeof( int ) );
00678                         result->defTagsEntSets[k] = ptr;
00679                         tag_desc                  = &( result->tags[i] );
00680 
00681                         ptr = realloc_data( &result, nval * sizeof( int ), status );
00682                         if( NULL == ptr || mhdf_isError( status ) )
00683                         {
00684                             free( array );
00685                             return NULL;
00686                         }
00687                         memset( ptr, 0, nval * sizeof( int ) );
00688                         result->defTagsVals[k] = ptr;
00689                         tag_desc               = &( result->tags[i] ); /* this is because the tag might point to
00690                                                               something else*/
00691 
00692                         /* make room for the long array type
00693                           is it long or something else? */
00694                         id_list = mhdf_malloc( nval * sizeof( long ), status );
00695                         /* fill the id with values, then convert to int type (-set start)
00696 
00697                          mhdf_read_data( table_id, offset, count, int_type, id_list, H5P_DEFAULT,
00698                          status );*/
00699 
00700                         data_type = H5Dget_type( table[0] );
00701 
00702                         mhdf_read_data( table[0], 0, nval, data_type, id_list, H5P_DEFAULT, status );
00703                         if( mhdf_isError( status ) )
00704                         {
00705                             free( array );
00706                             return NULL;
00707                         }
00708                         H5Tclose( data_type );
00709 
00710                         for( i1 = 0; i1 < nval; i1++ )
00711                             result->defTagsEntSets[k][i1] = (int)( id_list[i1] - result->sets.start_id + 1 );
00712                         /* now read values, integer type */
00713                         data_type = H5Dget_type( table[1] );
00714                         mhdf_read_data( table[1], 0, nval, data_type, result->defTagsVals[k], H5P_DEFAULT, status );
00715                         if( mhdf_isError( status ) )
00716                         {
00717                             free( array );
00718                             return NULL;
00719                         }
00720                         H5Tclose( data_type );
00721                         mhdf_closeData( file_handle, table[0], status );
00722                         if( mhdf_isError( status ) )
00723                         {
00724                             free( array );
00725                             return NULL;
00726                         }
00727                         mhdf_closeData( file_handle, table[1], status );
00728                         if( mhdf_isError( status ) )
00729                         {
00730                             free( array );
00731                             return NULL;
00732                         }
00733                         free( id_list );
00734                     }
00735                     else if( 0 == k || 1 == k )
00736                     { /* parallel partition or material sets should still work if dense
00737  could be dense tags on sets */
00738                         if( !mhdf_haveDenseTag( file_handle, pname[k], mhdf_set_type_handle(), status ) ) continue;
00739                         table[0] =
00740                             mhdf_openDenseTagData( file_handle, pname[k], mhdf_set_type_handle(), &nval, status );
00741                         if( mhdf_isError( status ) )
00742                         {
00743                             continue; /* do not error out if not a dense tag either */
00744                         }
00745                         result->numEntSets[k] = nval;
00746                         if( nval <= 0 ) continue; /* do not do anything */
00747 
00748                         /*
00749                          * if dense parallel partition or material set, we know what to expect
00750                          */
00751                         result->numEntSets[k] = nval; /* k could be 0 or 1 */
00752                         if( nval <= 0 ) continue;     /* do not do anything */
00753 
00754                         ptr = realloc_data( &result, nval * sizeof( int ), status );
00755                         if( NULL == ptr || mhdf_isError( status ) )
00756                         {
00757                             free( array );
00758                             return NULL;
00759                         }
00760                         memset( ptr, 0, nval * sizeof( int ) );
00761                         result->defTagsEntSets[k] = ptr;
00762                         tag_desc                  = &( result->tags[i] );
00763 
00764                         ptr = realloc_data( &result, nval * sizeof( int ), status );
00765                         if( NULL == ptr || mhdf_isError( status ) )
00766                         {
00767                             free( array );
00768                             return NULL;
00769                         }
00770                         memset( ptr, 0, nval * sizeof( int ) );
00771                         result->defTagsVals[k] = ptr;
00772                         tag_desc               = &( result->tags[i] ); /* this is because the tag might point to
00773                                                               something else*/
00774 
00775                         for( i1 = 0; i1 < nval; i1++ )
00776                         {
00777                             result->defTagsEntSets[k][i1] = i1 + 1;
00778                             /*result -> defTagsVals[k][i1] = i1; we know how the partition looks
00779                              * like  */
00780                         }
00781                         /* fill in the data with the dense tag values
00782                           because dense, sets will be in order
00783 
00784                           we know it has to be integer */
00785                         mhdf_readTagValues( table[0], 0, nval, H5T_NATIVE_INT, result->defTagsVals[k], status );
00786                         if( mhdf_isError( status ) )
00787                         {
00788                             free( array );
00789                             return NULL;
00790                         }
00791                         mhdf_closeData( file_handle, table[0], status );
00792                         if( mhdf_isError( status ) )
00793                         {
00794                             free( array );
00795                             return NULL;
00796                         }
00797                     }
00798                 }
00799             }
00800         }
00801     }
00802     /* Compact memory and return */
00803     free( array );
00804     result->total_size = result->offset - (unsigned char*)result;
00805 
00806     API_END;
00807     return result;
00808 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines