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