/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/sed/sed_property.c

Go to the documentation of this file.
00001 #include "sed_property.h"
00002 
00003 typedef struct
00004 {
00005    gchar*                 name;   
00006    gchar*                 ext;    
00007    Sed_cell_property_func f;      
00008    gssize                 n_args; 
00009 } Sed_property_static;
00010 
00013 CLASS( Sed_property )
00014 {
00015    gchar*                 name;   
00016    gchar*                 ext;    
00017    Sed_cell_property_func f;      
00018    gssize                 n_args; 
00019 };
00020 
00021 //const Sed_property S_AGE = sed_property_new_full( "age" , "age" , &sed_cell_age , 1 );
00022 
00023 static Sed_property_static all_properties[41] = {
00024    { "age"                , "age"      , {(Sed_cell_property_func_0)(&sed_cell_age)}     , 1 } ,
00025    { "facies"             , "facies"   , {(Sed_cell_property_func_0)(&sed_cell_facies)}  , 1 } ,
00026 //   { "facies"             , "facies"   , {&sed_cell_facies}            , 1 } ,
00027    { "pressure"           , "press"    , {&sed_cell_pressure}          , 1 } ,
00028    { "density"            , "bulk"     , {&sed_cell_density}           , 1 } ,
00029    { "grain density"      , "rhograin" , {&sed_cell_grain_density}     , 1 } ,
00030    { "max density"        , "rho_max"  , {&sed_cell_max_density}       , 1 } ,
00031    { "grain"              , "grain"    , {&sed_cell_grain_size_in_phi} , 1 } ,
00032    { "grain in meters"    , "grain"    , {&sed_cell_grain_size}        , 1 } ,
00033    { "sand"               , "sand"     , {&sed_cell_sand_fraction}     , 1 } ,
00034    { "silt"               , "silt"     , {&sed_cell_silt_fraction}     , 1 } ,
00035    { "clay"               , "clay"     , {&sed_cell_clay_fraction}     , 1 } ,
00036    { "mud"                , "mud"      , {&sed_cell_mud_fraction}      , 1 } ,
00037    { "velocity"           , "vel"      , {&sed_cell_velocity}          , 1 } ,
00038    { "viscosity"          , "visc"     , {&sed_cell_viscosity}         , 1 } ,
00039    { "relative density"   , "dr"       , {&sed_cell_relative_density}  , 1 } ,
00040    { "porosity"           , "por"      , {&sed_cell_porosity}          , 1 } ,
00041    { "porosity min"       , "pormin"   , {&sed_cell_porosity_min}      , 1 } ,
00042    { "porosity max"       , "pormax"   , {&sed_cell_porosity_max}      , 1 } ,
00043    { "pi"                 , "pi"       , {&sed_cell_plastic_index}     , 1 } ,
00044    { "permeability"       , "perm"     , {&sed_cell_permeability}      , 1 } ,
00045    { "permeability"       , "perm"     , {&sed_cell_permeability}      , 1 } ,
00046    { "void ratio"         , "void"     , {&sed_cell_void_ratio}        , 1 } ,
00047    { "void ratio min"     , "emin"     , {&sed_cell_void_ratio_min}    , 1 } ,
00048    { "void ratio max"     , "emax"     , {&sed_cell_void_ratio_max}    , 1 } ,
00049    { "friction angle"     , "angle"    , {&sed_cell_friction_angle}    , 1 } ,
00050    { "consolidation"      , "cc"       , {&sed_cell_cc}                , 1 } ,
00051    { "yield strength"     , "yield"    , {&sed_cell_yield_strength}    , 1 } ,
00052    { "dynamic viscosity"  , "nu"       , {&sed_cell_dynamic_viscosity} , 1 } ,
00053    { "mv"                 , "mv"       , {&sed_cell_compressibility}   , 1 } ,
00054    { "cv"                 , "cv"       , {&sed_cell_cv}                , 1 } ,
00055    { "cv"                 , "cv"       , {&sed_cell_bulk_cv}           , 1 } ,
00056    { "hydraulic con"      , "hydro"    , {&sed_cell_bulk_hydraulic_conductivity} , 1 } ,
00057    { "shear strength"     , "sheer"    , {&sed_cell_shear_strength}    , 2 } ,
00058    { "cohesion"           , "cohesion" , {&sed_cell_cohesion}       , 2 } ,
00059    { "consolidation"      , "con"      , {&sed_cell_consolidation}  , 2 } ,
00060    { "consolidation rate" , "du"       , {&sed_cell_consolidation_rate}  , 2 } ,
00061    { "excess pressure"    , "excess"   , {&sed_cell_excess_pressure} , 2 } ,
00062    { "relative pressure"  , "rel"      , {&sed_cell_relative_pressure} , 2 } ,
00063    { "fraction"           , "fraction" , {&sed_cell_fraction} , 2 } ,
00064    { NULL , NULL , {NULL} , 0 } };
00065 
00066 Sed_property sed_property_new_full( char* name , char* ext , Sed_cell_property_func f , gssize n_args )
00067 {
00068    Sed_property p;
00069 
00070    NEW_OBJECT( Sed_property , p );
00071 
00072    p->name   = g_strdup( name );
00073    p->ext    = g_strdup( ext  );
00074    p->f      = f;
00075    p->n_args = n_args;
00076 
00077    return p;
00078 }
00079 
00089 Sed_property
00090 sed_property_new( const char *name )
00091 {
00092    Sed_property prop = NULL;
00093 
00094    eh_require( name );
00095 
00096    if ( name )
00097    {
00098       gssize   i;
00099       gboolean found      = FALSE;
00100       gchar**  split_name = g_strsplit( name , "=" , -1 );
00101 
00102       for ( i=0 ; !found && all_properties[i].name ; i++ )
00103          if ( g_ascii_strcasecmp( split_name[0] , all_properties[i].name )==0 )
00104             found = TRUE;
00105       i--;
00106 
00107       if ( !found )
00108       {
00109          eh_error( "unknown property name: %s" , split_name[0] );
00110          prop = NULL;
00111       }
00112       else
00113          prop = sed_property_dup( &(all_properties[i]) );
00114 
00115       g_strfreev( split_name );
00116    }
00117 
00118    return prop;
00119 }
00120 
00121 Sed_property sed_property_copy( Sed_property dest , Sed_property src )
00122 {
00123    eh_require( src );
00124 
00125    if ( src )
00126    {
00127       if ( !dest )
00128          dest = sed_property_new_full( src->name , src->ext , src->f , src->n_args );
00129       else
00130       {
00131          eh_free( dest->name );
00132          eh_free( dest->ext  );
00133 
00134          dest->name   = g_strdup( src->name );
00135          dest->ext    = g_strdup( src->ext  );
00136          dest->f      = src->f;
00137          dest->n_args = src->n_args;
00138       }
00139    }
00140    else
00141       dest = NULL;
00142 
00143    return dest;
00144 }
00145 
00146 Sed_property sed_property_dup( Sed_property src )
00147 {
00148    return sed_property_copy( NULL , src );
00149 }
00150 
00151 gboolean sed_property_is_named( Sed_property p , const char* name )
00152 {
00153    return g_ascii_strcasecmp( p->name , name )==0;
00154 }
00155 
00156 char* sed_property_extension( Sed_property p )
00157 {
00158    char* ext = NULL;
00159 
00160    if ( p )
00161       ext = g_strdup( p->ext );
00162 
00163    return ext;
00164 }
00165 
00166 char* sed_property_name( Sed_property p )
00167 {
00168    char* name = NULL;
00169 
00170    if ( p )
00171       name = g_strdup( p->name );
00172 
00173    return name;
00174 }
00175 
00176 gssize sed_property_n_args( Sed_property p )
00177 {
00178    eh_return_val_if_fail( p , 0 );
00179    return p->n_args;
00180 }
00181 
00182 double sed_property_measure( Sed_property p , Sed_cell c , ... )
00183 {
00184    double val = 0.;
00185 
00186    eh_require( p );
00187    eh_require( c );
00188 
00189    if ( p && c )
00190    {
00191       if ( p->n_args == 1 )
00192       {
00193          val = (*(p->f.f_0))( c );
00194       }
00195       else
00196       {
00197          double arg_1, arg_2;
00198          va_list arg_list;
00199          va_start( arg_list , c );
00200 
00201          arg_1 = va_arg( arg_list , double );
00202 
00203          if ( p->n_args==2 )
00204             val = (*(p->f.f_1))( c , arg_1 );
00205          else
00206          {
00207             arg_2 = va_arg( arg_list , double );
00208             val = p->f.f_2( c , arg_1 , arg_2 );
00209          }
00210 
00211          va_end( arg_list );
00212       }
00213    }
00214 
00215    return val;
00216 }
00217 
00218 Sed_property sed_property_destroy( Sed_property p )
00219 {
00220    if ( p )
00221    {
00222       eh_free( p->name );
00223       eh_free( p->ext  );
00224       eh_free( p );
00225    }
00226 
00227    return NULL;
00228 }
00229 

Generated on Fri Jan 4 18:04:15 2008 for sedflux by  doxygen 1.5.2