00001
00002
00003
00004
00006 #ifndef __FIBER_HDF5_TYPEREGISTRY_HPP
00007 #define __FIBER_HDF5_TYPEREGISTRY_HPP "Created 27.02.2001 21:42:27 by werner"
00008
00009 #include "FBhdf5API.h"
00010 #include "init.hpp"
00011 #include <memcore/RefPtr.hpp>
00012 #include <memcore/typemap.hpp>
00013 #include <field/FiberType.hpp>
00014 #include <F5/F5Bchart.h>
00015 #include <F5/F5F.h>
00016
00017 namespace Fiber
00018 {
00019 using namespace MemCore;
00020
00028 class HDF5BUNDLE_API H5ID : public Interface<H5ID>
00029 {
00030 hid_t hid;
00031
00032 public:
00033 typedef typemap<string> ChartNameMap_t;
00034 typedef std::map<string, TypeInfo> ChartTypeMap_t;
00035
00036 static ChartNameMap_t&ChartMap();
00037 static ChartTypeMap_t&ChartType();
00038
00039 static void insert(const char*chartname, const type_info&charttype)
00040 {
00041 ChartMap() [ charttype ] = chartname;
00042 ChartType().insert(
00043 ChartTypeMap_t::value_type(chartname,
00044 TypeInfo(charttype) ) );
00045 }
00046
00047 template <class ChartDomain>
00048 struct Domain
00049 {
00050 static void associate(const char*chartname)
00051 {
00052 insert(chartname, typeid(ChartDomain) );
00053 }
00054
00055 static string name()
00056 {
00057 ChartNameMap_t::const_iterator cit = ChartMap().find( typeid(ChartDomain) );
00058 if (cit == ChartMap().end() )
00059 return "void";
00060
00061 return cit->second;
00062 }
00063 };
00064
00065
00066
00067 static TypeInfo getChartType(hid_t type_id);
00068
00069 H5ID(hid_t hid);
00070 ~H5ID();
00071
00072 hid_t getId() const
00073 {
00074 return hid;
00075 }
00076
00081 static RefPtr<FiberTypeBase> find(hid_t type_id);
00082
00087 static RefPtr<FiberTypeBase> find(F5Path*field);
00088
00089
00095 static RefPtr<H5ID> retrieve(const RefPtr<FiberTypeBase>&FTB);
00096
00097
00098 static void printTypeInfo(hid_t id);
00099
00100 };
00101
00102
00103 class HDF5BUNDLE_API F5Domain : public Interface<F5Domain>
00104 {
00105 public:
00106 ChartDomain_IDs*ChartDomain;
00107
00108 F5Domain(ChartDomain_IDs*CD)
00109 : ChartDomain(CD)
00110 {}
00111 };
00112
00113
00118 template <class Type>
00119 struct HDF5TypeAction : TypeAction
00120 {
00121 typedef FiberType<Type> FiberType_t;
00122
00123 static hid_t getId()
00124 {
00125 const FiberTypeBase&FTB = FiberType_t::getFiberType();
00126 RefPtr<TypeAction> TA = find( FTB.self() );
00127 if (!TA)
00128 return -1;
00129
00130 RefPtr<H5ID> Hid = interface_cast<H5ID>(TA);
00131 if (!Hid)
00132 return -1;
00133
00134 return Hid->getId();
00135 }
00136
00137 static bool registerHID(hid_t type_id, const RefPtr<F5Domain>&f = NullPtr() )
00138 {
00139 const FiberTypeBase&FTB = FiberType_t::getFiberType();
00140
00141 RefPtr<TypeAction> TA = TypeAction::create( FTB.self() );
00142
00143 if (!TA)
00144 return false;
00145
00146 printf("TYPE %s --> HDF5 ID %d\n", Typename(FTB.getType()).c_str(), type_id);
00147 assert(type_id>0);
00148 if ( H5Tget_size(type_id) != FTB.mem_size() )
00149 {
00150 printf("HDF5TypeAction<>::registerHID() ERROR ==> HDF5 is %d bytes, memory is %d bytes, %s\n",
00151 (int)H5Tget_size(type_id), (int) FTB.mem_size(), FTB.description().c_str() );
00152 assert ( H5Tget_size(type_id) == FTB.mem_size() );
00153 }
00154
00155
00156 TA->addInterface( new H5ID( type_id ) );
00157
00158 if (f)
00159 TA->addInterface( f );
00160
00161 return true;
00162 }
00163
00164 static RefPtr<F5Domain> makeDomainType(const char*coordnames[])
00165 {
00166 const FiberTypeBase&FTB = FiberType_t::getFiberType();
00167
00168 RefPtr<TypeAction> TA = TypeAction::create( FTB.self() );
00169
00170 if (!TA)
00171 return NullPtr();
00172
00173 enum { ELEMENTS = FiberType_t::FiberInfo_t::MULTIPLICITY };
00174 enum { RANK = FiberType_t::FiberInfo_t::RANK };
00175
00176 typedef typename FiberType_t::FiberInfo_t::Chart_t DomainType;
00177
00178 typedef typename FiberType_t::element_t element_t;
00179
00180 hid_t ElementType = HDF5TypeAction<element_t>::getId();
00181
00182 string Domainname = H5ID::Domain<DomainType>::name();
00183
00184 printf("TYPEREGISTRY: Domain [%s] Element Type is %x TODO: Create only ONCE global domain here\n", Domainname.c_str(), (int)ElementType);
00185
00186 ChartDomain_IDs*CD;
00187 switch( H5Tget_class(ElementType) )
00188 {
00189 case H5T_INTEGER:
00190 printf(" new integer domain ");
00191 CD = F5B_new_global_int_domain(coordnames, ELEMENTS, Domainname.c_str(), F5_FORTRAN_ORDER, RANK);
00192 break;
00193
00194 case H5T_FLOAT:
00195 printf(" new chart ");
00196 CD = F5B_new_global_float_chart(coordnames, ELEMENTS, Domainname.c_str(), F5_FORTRAN_ORDER);
00197 break;
00198 default:
00199 puts(__FILE__ "stuff not supported.");
00200 assert(0);
00201 }
00202
00203 hsize_t ElementTypeSize = H5Tget_size(ElementType);
00204
00205 puts(ElementTypeSize==8?"(double, 64bit precision)":"(single, 32bit or less precision)");
00206
00207 hid_t type_id = (ElementTypeSize==8)?CD->DoublePrecision.Point_hid_t:CD->SinglePrecision.Point_hid_t;
00208 TA->addInterface( new H5ID( type_id ) );
00209
00210
00211 RefPtr<F5Domain> f = new F5Domain( CD );
00212 TA->addInterface( f );
00213
00214 return f;
00215 }
00216
00217
00218 static RefPtr<F5Domain> makeDomainType()
00219 {
00220 enum { ELEMENTS = FiberType_t::FiberInfo_t::MULTIPLICITY };
00221
00222 const char*coordnames[ELEMENTS];
00223 for(int i=0; i<ELEMENTS; i++)
00224 {
00225 coordnames[i] = Type::coordinate_name(i);
00226 }
00227 return makeDomainType(coordnames);
00228 }
00229
00230 static bool registerCellType(const char*F5DomainName)
00231 {
00232 H5ID::Domain<Type>::associate( F5DomainName );
00233 return makeDomainType();
00234 }
00235 };
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 }
00301
00302 #endif
00303