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