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

Go to the documentation of this file.
00001 //---
00002 //
00003 // This file is part of sedflux.
00004 //
00005 // sedflux is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // sedflux is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with sedflux; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //
00019 //---
00020 
00021 #include "sed_cell.h"
00022 
00028 
00053 CLASS ( Sed_cell )
00054 {
00055    gssize     n;        
00056    double*    f;        
00057    double     t_0;      
00058    double     t;        
00059    double     age;      
00060    double     pressure; 
00061    Sed_facies facies;   
00062 };
00063 
00064 #include <stdlib.h>
00065 
00075 Sed_cell
00076 sed_cell_new( gssize n_grains )
00077 {
00078    Sed_cell c = NULL;
00079 
00080    if ( n_grains>0 )
00081    {
00082       NEW_OBJECT( Sed_cell , c );
00083    
00084       c->f = eh_new0( double , n_grains );
00085    
00086       c->n        = n_grains;
00087       c->t_0      = 0.;
00088       c->t        = 0.;
00089       c->age      = 0.;
00090       c->pressure = 0.;
00091       c->facies   = S_FACIES_NOTHING;
00092    }
00093    
00094    return c;
00095 }
00096 
00101 Sed_cell
00102 sed_cell_new_env( void )
00103 {
00104    Sed_cell c = NULL;
00105 
00106    if ( sed_sediment_env_is_set() )
00107       c = sed_cell_new( sed_sediment_env_n_types() );
00108 
00109    return c;
00110 }
00111 
00120 Sed_cell
00121 sed_cell_new_sized( gssize n , double t , double* f )
00122 {
00123    Sed_cell c = sed_cell_new( n );
00124 
00125    sed_cell_set_fraction( c , f );
00126    sed_cell_resize      ( c , t );
00127 
00128    return c;
00129 }
00130 
00139 Sed_cell
00140 sed_cell_new_typed( Sed_sediment s , double t , Sed_type a_type )
00141 {
00142    Sed_cell c = NULL;
00143 
00144    if ( !s )
00145       s = sed_sediment_env();
00146 
00147    {
00148       gssize i;
00149       gssize len = sed_sediment_n_types(s);
00150       double* f = eh_new0( double , len );
00151 
00152       for ( i=0 ; i<len ; i++ )
00153          if ( sed_type_is_same( sed_sediment_type( s , i ) , a_type ) )
00154             f[i] = 1.;
00155 
00156       c = sed_cell_new_sized( len , t , f );
00157 
00158       eh_free( f );
00159    }
00160 
00161    return c;
00162 }
00163 
00172 Sed_cell
00173 sed_cell_new_classed( Sed_sediment s , double t , Sed_size_class class )
00174 {
00175    Sed_cell c = NULL;
00176 
00177    if ( !s )
00178       s = sed_sediment_env();
00179 
00180    if ( s )
00181    {
00182       gssize i;
00183       gssize len = sed_sediment_n_types(s);
00184       double* f = eh_new0( double , len );
00185 
00186       for ( i=0 ; i<len ; i++ )
00187          //if ( sed_type_is_size_class( sed_sediment_type( s , i ) , class ) )
00188          if ( class & sed_type_size_class(sed_sediment_type(s,i)) )
00189             f[i] = 1.;
00190 
00191       eh_dbl_array_normalize( f , len );
00192 
00193       c = sed_cell_new_sized( len , t , f );
00194 
00195       eh_free( f );
00196    }
00197 
00198    return c;
00199 }
00200 
00208 Sed_cell
00209 sed_cell_new_bedload( Sed_sediment s , double t )
00210 {
00211    Sed_cell c = NULL;
00212 
00213    if ( !s )
00214       s = sed_sediment_env();
00215 
00216    if ( s )
00217    {
00218       gssize len = sed_sediment_n_types(s);
00219       double* f = eh_new0( double , len );
00220 
00221       f[0] = 1.;
00222 
00223       c = sed_cell_new_sized( len , t , f );
00224 
00225       eh_free( f );
00226    }
00227 
00228    return c;
00229 }
00230 
00244 Sed_cell
00245 sed_cell_dup( Sed_cell c )
00246 {
00247    Sed_cell dup_cell = NULL;
00248 
00249    eh_require( c )
00250    {
00251       dup_cell = sed_cell_copy( NULL , c );
00252    }
00253 
00254    return dup_cell;
00255 }
00256 
00271 Sed_cell*
00272 sed_cell_list_new( gssize len , gssize n )
00273 {
00274    Sed_cell *c_list = NULL;
00275 
00276    eh_require( len>0 )
00277    {
00278       gssize i;
00279 
00280       c_list = eh_new( Sed_cell , len+1 );
00281 
00282       for ( i=0 ; i<len ; i++ )
00283          c_list[i] = sed_cell_new( n );
00284       c_list[len]=NULL;
00285    }
00286 
00287    return c_list;
00288 }
00289 
00297 Sed_cell*
00298 sed_cell_list_destroy(Sed_cell *c_list)
00299 {
00300    eh_require( c_list )
00301    {
00302       gssize i;
00303 
00304       for ( i=0 ; c_list[i] ; i++ )
00305          c_list[i] = sed_cell_destroy( c_list[i] );
00306       eh_free(c_list);
00307    }
00308 
00309    return NULL;
00310 }
00311 
00320 Sed_cell
00321 sed_cell_destroy( Sed_cell c )
00322 {
00323    if ( c )
00324    {
00325       eh_free( c->f );
00326       eh_free( c );
00327    }
00328    
00329    return NULL;   
00330 }
00331 
00339 gssize
00340 sed_cell_fprint( FILE* fp , const Sed_cell c )
00341 {
00342    gssize n=0;
00343 
00344    if ( c )
00345    {
00346       gssize i;
00347 
00348       n += fprintf( fp , "Thickness : %f\n" , c->t );
00349       n += fprintf( fp , "Age       : %f\n" , c->age );
00350       n += fprintf( fp , "Fraction: : %f"   , c->f[0] );
00351       for ( i=1 ; i<sed_cell_n_types(c) ; i++ )
00352          n += fprintf( fp , ", %f" , c->f[i] );
00353       n += fprintf( fp , "\n" );
00354    }
00355    else
00356       n += fprintf( fp , "( null )\n" );
00357 
00358    return n;
00359 }
00360 
00373 Sed_cell
00374 sed_cell_clear( Sed_cell c )
00375 {
00376    eh_require( c )
00377    {
00378       gssize n;
00379    
00380       for ( n=0 ; n<sed_cell_n_types(c) ; n++ )
00381          c->f[n] = 0;
00382 
00383       c->t        = 0;
00384       c->t_0      = 0;
00385       c->age      = 0;
00386       c->pressure = 0.;
00387       c->facies   = S_FACIES_NOTHING;
00388    }
00389    
00390    return c;
00391 }
00392 
00405 Sed_cell*
00406 sed_cell_clear_vector(Sed_cell *vec,int low,int high )
00407 {
00408    int i;
00409    for (i=low;i<=high;i++)
00410       sed_cell_clear( vec[i] );
00411    return vec;
00412 }
00413 
00428 Sed_cell
00429 sed_cell_copy( Sed_cell dest , const Sed_cell src )
00430 {
00431    eh_require( src )
00432 
00433    if ( dest != src )
00434    {
00435       if ( !dest )
00436          dest = sed_cell_new( sed_cell_n_types(src) );
00437       else
00438          eh_require( sed_cell_is_compatible( dest , src ) );
00439 
00440       memcpy( dest->f , src->f , sed_cell_n_types(src)*sizeof(double) );
00441 
00442       dest->n        = src->n;
00443       dest->t_0      = src->t_0;
00444       dest->t        = src->t;
00445       dest->age      = src->age;
00446       dest->pressure = src->pressure;
00447       dest->facies   = src->facies;
00448 
00449    }
00450    
00451    return dest;
00452 }
00453 
00461 Sed_cell
00462 sed_cell_set_age( Sed_cell c , double age )
00463 {
00464    eh_require( c );
00465    c->age = age;
00466    return c;
00467 }
00468 
00476 Sed_cell
00477 sed_cell_set_thickness( Sed_cell c , double t )
00478 {
00479    eh_require( c );
00480    c->t = t;
00481    return c;
00482 }
00483 
00491 Sed_cell
00492 sed_cell_set_pressure( Sed_cell c , double p )
00493 {
00494    eh_require( c );
00495    c->pressure = p;
00496    return c;
00497 }
00498 
00506 Sed_cell
00507 sed_cell_set_facies( Sed_cell c , Sed_facies f )
00508 {
00509    eh_require( c );
00510    c->facies = f;
00511    return c;
00512 }
00513 
00514 Sed_cell
00515 sed_cell_add_facies( Sed_cell c , Sed_facies f )
00516 {
00517    eh_require( c );
00518    c->facies |= f;
00519    return c;
00520 }
00521 
00533 Sed_cell
00534 sed_cell_set_fraction(Sed_cell c , double f[] )
00535 {
00536    eh_require( c );
00537    eh_require( f );
00538 
00539    {
00540       memcpy( c->f , f , sed_cell_n_types(c)*sizeof(double) );
00541    }
00542    
00543    return c;   
00544 }
00545 
00552 Sed_cell
00553 sed_cell_set_equal_fraction( Sed_cell c )
00554 {
00555    eh_require( c );
00556 
00557    {
00558       gssize n, len = sed_cell_n_types(c);
00559       for ( n=0 ; n<len ; n++ )
00560          c->f[n] = 1./len;
00561    }
00562    
00563    return c;   
00564 }
00565 
00580 Sed_cell
00581 sed_cell_add( Sed_cell a , const Sed_cell b )
00582 {
00583    eh_require( a );
00584 
00585    {
00586       if ( b && !sed_cell_is_empty(b) )
00587       {
00588          gssize n;
00589          gssize len = sed_cell_n_types( b );
00590          double ratio = a->t / b->t;
00591 /*
00592          if ( !sed_cell_is_valid(b) )
00593             sed_cell_fprint( stderr , b );
00594 */
00595          eh_require_critical( sed_cell_is_valid(b) );
00596 
00597          eh_require( sed_cell_is_compatible( a , b ) );
00598 
00599          for ( n=0 ; n<len ; n++ )
00600             a->f[n] = (a->f[n]*ratio + b->f[n])/(ratio+1.);
00601 
00602          a->t        = a->t   + b->t;
00603          a->t_0      = a->t_0 + b->t_0;
00604          a->age      = (a->age*ratio + b->age) / (ratio + 1.);
00605          a->pressure = (a->pressure*ratio + b->pressure) / (ratio + 1.);
00606          a->facies   = a->facies | b->facies;
00607       }
00608 
00609 //      eh_require_critical( sed_cell_is_valid(a) );
00610    }
00611 
00612    return a;
00613 }
00614 
00625 gboolean
00626 sed_cell_is_empty( Sed_cell c )
00627 {
00628    return c->t < 1e-12;
00629 }
00630 
00642 gboolean
00643 sed_cell_is_clear( Sed_cell c )
00644 {
00645    gboolean is_clear = FALSE;
00646 
00647    if ( c )
00648    {
00649       if ( sed_cell_is_empty(c) )
00650       {
00651          gssize n;
00652          gssize len = sed_cell_n_types(c);
00653 
00654          is_clear = TRUE;
00655 
00656          for ( n=0 ; is_clear && n<len ; n++ )
00657             if ( c->f[n] > 1e-12 )
00658                is_clear = FALSE;
00659       }
00660    }
00661    else
00662       is_clear = TRUE;
00663 
00664    return is_clear;
00665 }
00666 
00674 gboolean
00675 sed_cell_is_size( Sed_cell c , double t )
00676 {
00677    return eh_compare_dbl( sed_cell_size(c) , t , 1e-12 );
00678 }
00679 
00687 gboolean
00688 sed_cell_is_age( Sed_cell c , double a )
00689 {
00690    return eh_compare_dbl( sed_cell_age(c) , a , 1e-12 );
00691 }
00692 
00700 gboolean
00701 sed_cell_is_mass( Sed_cell c , double m )
00702 {
00703    return eh_compare_dbl( sed_cell_mass(c) , m , 1e-12 );
00704 }
00705 
00713 gboolean
00714 sed_cell_is_size_class( Sed_cell c , Sed_size_class size )
00715 {
00716    return sed_cell_size_class( c )&size;
00717 }
00718 
00729 gboolean
00730 sed_cell_is_compatible( Sed_cell a , Sed_cell b )
00731 {
00732    return sed_cell_n_types(a) == sed_cell_n_types(b);
00733 }
00734 
00748 Sed_cell
00749 sed_cell_separate_amount( Sed_cell in ,
00750                           double t[]  ,
00751                           Sed_cell out )
00752 {
00753    eh_require( in );
00754    eh_require( t  );
00755 
00756    {
00757       if ( !sed_cell_is_empty( in ) )
00758       {
00759          gssize n;
00760          gssize len   = sed_cell_n_types( in );
00761          double *f    = eh_new0( double , len );
00762          double total = sed_cell_size( in );
00763 
00764          for ( n=0 ; n<len ; n++ )
00765          {
00766             if ( in->f[n]>0. )
00767                f[n] = t[n]/(total*in->f[n]);
00768 //            f[n] = t[n]/total;
00769             eh_clamp( f[n] , 0. , 1. );
00770          }
00771 
00772          out = sed_cell_separate_fraction( in , f , out );
00773 
00774          eh_free( f );
00775       }
00776       else
00777       {
00778          out = sed_cell_copy( out , in );
00779          sed_cell_resize( out , 0. );
00780       }
00781    }
00782 
00783    return out;
00784 }
00785 
00800 Sed_cell
00801 sed_cell_separate_thickness( Sed_cell in ,
00802                              double   t  ,
00803                              Sed_cell out )
00804 {
00805    eh_require( in );
00806 
00807    {
00808       double total    = sed_cell_size( in );
00809       double in_size  = total - t;
00810       double out_size = total - in_size;
00811 
00812       eh_clamp( in_size  , 0 , total );
00813       eh_clamp( out_size , 0 , total );
00814 
00815       out = sed_cell_copy( out , in );
00816 
00817       sed_cell_resize( in  , in_size  );
00818       sed_cell_resize( out , out_size );
00819    }
00820 
00821    return out;
00822 }
00823 
00836 Sed_cell
00837 sed_cell_separate_fraction( Sed_cell in ,
00838                             double f[] ,
00839                             Sed_cell out )
00840 {
00841    eh_require( in );
00842    eh_require( f  );
00843 
00844    {
00845       out = sed_cell_copy( out , in );
00846 
00847       if ( !sed_cell_is_empty( in ) )
00848       {
00849          gssize n;
00850          gssize len     = sed_cell_n_types( in );
00851          double* in_t   = eh_new( double , len );
00852          double* out_t  = eh_new( double , len );
00853          double in_size = sed_cell_size( in );
00854 
00855          for ( n=0 ; n<len ; n++ )
00856          {
00857             out_t[n] = f[n]     *in_size*in->f[n];
00858             in_t[n]  = (1.-f[n])*in_size*in->f[n];
00859          }
00860 
00861          sed_cell_set_amount( in  , in_t  );
00862          sed_cell_set_amount( out , out_t );
00863 
00864          eh_free( in_t  );
00865          eh_free( out_t );
00866       }
00867    }
00868 
00869    return out;
00870 }
00871 
00879 Sed_cell
00880 sed_cell_set_amount( Sed_cell c , const double* t )
00881 {
00882    eh_return_val_if_fail( c , NULL );
00883    eh_return_val_if_fail( t , c    );
00884 
00885    {
00886       gssize n;
00887       gssize len = sed_cell_n_types(c);
00888       double sum = eh_dbl_array_sum( t , len );
00889 
00890       if ( sum>0 )
00891       {
00892          for ( n=0 ; n<len ; n++ )
00893             c->f[n] = t[n] / sum;
00894 
00895          sed_cell_resize( c , sum );
00896       }
00897       else
00898          sed_cell_clear( c );
00899    }
00900 
00901    return c;
00902 }
00903 
00919 Sed_cell
00920 sed_cell_add_amount( Sed_cell a , const double t[] )
00921 {
00922    eh_return_val_if_fail( a , NULL );
00923    eh_return_val_if_fail( t , a    );
00924 
00925    {
00926       gssize len = sed_cell_n_types(a);
00927       double sum = eh_dbl_array_sum( t , len );
00928 
00929       if ( sum > 0 )
00930       {
00931          gssize n;
00932          double new_t = sum + a->t;
00933 
00934          for ( n=0 ; n<len ; n++ )
00935             a->f[n] = ( a->f[n]*a->t + t[n] ) / new_t;
00936 
00937          a->t   += sum;
00938          a->t_0 += sum;
00939       }
00940    }
00941 
00942    return a;   
00943 }
00944 
00955 Sed_cell
00956 sed_cell_separate_cell( Sed_cell in ,
00957                         Sed_cell out )
00958 {
00959    sed_cell_destroy( sed_cell_separate( in , out->f , sed_cell_size(out) , NULL ) );
00960 
00961    return in;
00962 }
00963 
00976 Sed_cell
00977 sed_cell_separate( Sed_cell in ,
00978                    double f[]  ,
00979                    double t    ,
00980                    Sed_cell out )
00981 {
00982    eh_require( in   );
00983    eh_require( f    );
00984    eh_require( t>=0 );
00985 
00986    out = sed_cell_copy( out , in );
00987 
00988    if ( !sed_cell_is_empty( in ) )
00989    {
00990       gssize n;
00991       gssize len   = sed_cell_n_types( in );
00992       double* t_rem = eh_new( double , len );
00993       double sum;
00994 
00995       for ( n=0,sum=0 ; n<len ; n++ )
00996          sum += f[n];
00997 
00998       for ( n=0 ; n<len ; n++ )
00999          t_rem[n] = f[n]/sum*t;
01000 
01001       out = sed_cell_separate_amount( in , t_rem , out );
01002 
01003       eh_free( t_rem );
01004    }
01005 
01006    return out;
01007 }
01008 
01022 void
01023 sed_cell_move_thickness( Sed_cell src , Sed_cell dest , double t )
01024 {
01025    eh_require( src );
01026    eh_require( dest );
01027    eh_require( sed_cell_is_compatible( src , dest ) );
01028 
01029    if ( t>0 )
01030    {
01031       Sed_cell temp = sed_cell_separate_thickness( src , t , NULL );
01032       sed_cell_add( dest , temp );
01033       temp = sed_cell_destroy( temp );
01034    }
01035 }
01036 
01050 void
01051 sed_cell_move_fraction( Sed_cell src  ,
01052                         Sed_cell dest ,
01053                         double f[] )
01054 {
01055    eh_require( src  );
01056    eh_require( dest );
01057    eh_require( f    );
01058    eh_require( sed_cell_is_compatible( src , dest ) );
01059 
01060    {
01061       Sed_cell temp = sed_cell_separate_fraction( src , f , NULL );
01062       sed_cell_add( dest , temp );
01063       temp = sed_cell_destroy( temp );
01064    }
01065 }
01066 
01083 void
01084 sed_cell_move( Sed_cell src  ,
01085                Sed_cell dest ,
01086                double f[]    ,
01087                double t )
01088 {
01089    Sed_cell temp1 = sed_cell_separate_thickness( src   , t , NULL );
01090    Sed_cell temp2 = sed_cell_separate_fraction ( temp1 , f , NULL );
01091 
01092    sed_cell_add( src  , temp1 );
01093    sed_cell_add( dest , temp2 );
01094 
01095    temp1 = sed_cell_destroy( temp1 );
01096    temp2 = sed_cell_destroy( temp2 );
01097 }
01098 
01100 //
01101 // These are the pre-defined S_property_func's
01102 //
01103 //   functions are of the form:
01104 //   double f(Sed_cell*,sediment,n)
01105 //
01106 
01115 double
01116 sed_cell_density_0( const Sed_cell c )
01117 {
01118    return sed_sediment_property_avg( NULL , c->f , &sed_type_density_0 );
01119 }
01120 
01129 double
01130 sed_cell_grain_density( const Sed_cell c )
01131 {
01132    return sed_sediment_property_avg( NULL , c->f , &sed_type_rho_grain );
01133 }
01134 
01143 double
01144 sed_cell_max_density( const Sed_cell c )
01145 {
01146    return sed_sediment_property_avg( NULL , c->f , &sed_type_rho_max );
01147 }
01148 
01157 double
01158 sed_cell_grain_size( const Sed_cell c )
01159 {
01160    double g = 0;
01161 
01162    if ( c )
01163       g = sed_sediment_property_avg( NULL , c->f , &sed_type_grain_size );
01164 
01165    return g;
01166 }
01167 
01176 double
01177 sed_cell_grain_size_in_phi( const Sed_cell c )
01178 {
01179    return sed_sediment_property_avg( NULL , c->f , &sed_type_grain_size_in_phi );
01180 }
01181 
01182 double
01183 sed_cell_sand_fraction( const Sed_cell c )
01184 {
01185    return sed_sediment_property_avg( NULL , c->f , &sed_type_is_sand );
01186 }
01187 
01188 double
01189 sed_cell_silt_fraction( const Sed_cell c )
01190 {
01191    return sed_sediment_property_avg( NULL , c->f , &sed_type_is_silt );
01192 }
01193 
01194 double
01195 sed_cell_clay_fraction( const Sed_cell c )
01196 {
01197    return sed_sediment_property_avg( NULL , c->f , &sed_type_is_clay );
01198 }
01199 
01200 double
01201 sed_cell_mud_fraction( const Sed_cell c )
01202 {
01203    return sed_sediment_property_avg( NULL , c->f , &sed_type_is_mud );
01204 }
01205 
01206 double
01207 sed_cell_nth_fraction( const Sed_cell c , gssize n )
01208 {
01209    return sed_cell_fraction( c , n );
01210 }
01211 
01212 double
01213 sed_cell_nth_amount( const Sed_cell c , gssize n )
01214 {
01215    return sed_cell_fraction(c,n)*sed_cell_size(c);
01216 }
01217 
01218 double*
01219 sed_cell_fraction_ptr( const Sed_cell c )
01220 {
01221    return c->f;
01222 }
01223 
01234 double*
01235 sed_cell_copy_fraction( double* f , const Sed_cell c )
01236 {
01237    eh_require( c );
01238 
01239    if ( !f )
01240       f = eh_new( double , sed_cell_n_types(c) );
01241    memcpy( f , c->f , sizeof(double)*sed_cell_n_types(c) );
01242 
01243    return f;
01244 }
01245 
01254 double
01255 sed_cell_c_consolidation( const Sed_cell c )
01256 {
01257    return sed_sediment_property_avg( NULL , c->f , &sed_type_c_consolidation );
01258 }
01259 
01268 double
01269 sed_cell_velocity( const Sed_cell c )
01270 {
01271    return sed_sediment_property_avg( NULL , c->f , &sed_type_velocity );
01272 }
01273 
01282 double
01283 sed_cell_viscosity( const Sed_cell c )
01284 {
01285    return sed_sediment_property_avg( NULL , c->f , &sed_type_viscosity );
01286 }
01287 
01296 double
01297 sed_cell_relative_density( const Sed_cell c )
01298 {
01299    return sed_sediment_property_avg( NULL , c->f , &sed_type_relative_density );
01300 }
01301 
01310 double
01311 sed_cell_porosity( const Sed_cell c )
01312 {
01313    return sed_sediment_property_avg( NULL , c->f , &sed_type_porosity );
01314 }
01315 
01326 double
01327 sed_cell_porosity_max( const Sed_cell c )
01328 {
01329    return sed_sediment_property_avg( NULL , c->f , &sed_type_porosity_max );
01330 }
01331 
01342 double
01343 sed_cell_porosity_min( const Sed_cell c )
01344 {
01345    return sed_sediment_property_avg( NULL , c->f , &sed_type_porosity_min );
01346 }
01347 
01356 double
01357 sed_cell_plastic_index( const Sed_cell c )
01358 {
01359    return sed_sediment_property_avg( NULL , c->f , &sed_type_plastic_index );
01360 }
01361 
01370 double
01371 sed_cell_permeability( const Sed_cell c )
01372 {
01373    return sed_sediment_property_avg( NULL , c->f , &sed_type_permeability );
01374 }
01375 
01384 double
01385 sed_cell_hydraulic_conductivity( const Sed_cell c )
01386 {
01387    return sed_sediment_property_avg( NULL , c->f , &sed_type_hydraulic_conductivity );
01388 }
01389 
01396 double
01397 sed_cell_bulk_permeability( const Sed_cell c )
01398 { 
01399    double s;
01400    double e = sed_cell_void_ratio( c );
01401    static const double s_f = SED_CELL_CONST_S_F;
01402 
01403    s = 6.*sed_sediment_property_avg( NULL , c->f , &sed_type_inv_grain_size_in_meters );
01404 
01405   return 1./(5.*s_f*s*s)*(pow(e,3.)/(1+e));
01406 }
01407 
01408 double
01409 sed_cell_bulk_log_permeability( const Sed_cell c )
01410 {
01411    double k = sed_cell_bulk_permeability( c );
01412    return ( k<=0 )?eh_nan():log(k);
01413 }
01414 
01415 double
01416 sed_cell_bulk_hydraulic_conductivity( const Sed_cell c )
01417 {
01418    return sed_cell_bulk_permeability( c ) * S_GAMMA_WATER / S_ETA_WATER;
01419 }
01420 
01429 double
01430 sed_cell_void_ratio( const Sed_cell c )
01431 {
01432    double e = sed_sediment_property_avg( NULL , c->f , &sed_type_void_ratio );
01433    return ( c->t/c->t_0 ) * ( 1.+e ) - 1.;
01434 }
01435 
01446 double
01447 sed_cell_void_ratio_min( const Sed_cell c )
01448 {
01449    return sed_sediment_property_avg( NULL , c->f , &sed_type_void_ratio_min );
01450 }
01451 
01462 double
01463 sed_cell_void_ratio_max( const Sed_cell c )
01464 {
01465    return sed_sediment_property_avg( NULL , c->f , &sed_type_void_ratio_max );
01466 }
01467 
01474 double
01475 sed_cell_friction_angle( const Sed_cell c )
01476 {
01477    return sed_sediment_property_avg( NULL , c->f , &sed_type_friction_angle );
01478 }
01479 
01480 double
01481 sed_cell_cc( const Sed_cell c )
01482 {
01483    return sed_sediment_property_avg( NULL , c->f , &sed_type_c_consolidation );
01484 }
01485 
01486 double
01487 sed_cell_compressibility( const Sed_cell c )
01488 {
01489    return sed_sediment_property_avg( NULL , c->f , &sed_type_compressibility );
01490 }
01491 
01506 double
01507 sed_cell_yield_strength( const Sed_cell c )
01508 {
01509    return sed_sediment_property_avg( NULL , c->f , &sed_type_yield_strength );
01510 }
01511 
01518 double
01519 sed_cell_bulk_yield_strength( const Sed_cell c )
01520 {
01521    double a, f_sand;
01522    double conc = 1. - sed_cell_porosity( c );
01523 
01524    f_sand = sed_cell_sand_fraction( c );
01525 
01526    if ( f_sand > .99 )
01527       a = 3.;
01528    else
01529    {
01530       double f_clay = sed_cell_clay_fraction( c );
01531       double f_silt = sed_cell_silt_fraction( c );
01532 
01533       conc *= (f_silt+f_clay);
01534 
01535       if ( f_silt/(f_silt+f_clay) > .95 )
01536          a = 13.;
01537       else
01538          a = 23;
01539    }
01540 
01541    conc = 1. - sed_cell_porosity( c );
01542    a = 13.;
01543 
01544    return .1*exp( a*( conc - .05 ) );
01545 }
01546 
01556 double
01557 sed_cell_dynamic_viscosity( const Sed_cell c )
01558 {
01559    return sed_sediment_property_avg( NULL , c->f , &sed_type_dynamic_viscosity );
01560 }
01561 
01568 double
01569 sed_cell_bulk_dynamic_viscosity( const Sed_cell c )
01570 {
01571    double a, f_sand;
01572    double conc = 1.-sed_cell_porosity( c );
01573 
01574    f_sand = sed_cell_sand_fraction( c );
01575 
01576    if ( f_sand > .95 )
01577       a = 10.;
01578    else
01579    {
01580       conc *= (1.-f_sand);
01581       a = 23.;
01582    }
01583 
01584    conc = 1.-sed_cell_porosity( c );
01585    a = 10.;
01586 
01587    return S_ETA_WATER*( 1. + 2.5*conc + exp( a*( conc - .05 ) ) );
01588 }
01589 
01590 double
01591 sed_cell_relative_pressure( const Sed_cell c , double load )
01592 {
01593    double pressure = sed_cell_pressure( c );
01594 
01595    if ( load <= 0 )
01596       return 0;
01597    else
01598       return pressure / load;
01599 }
01600 
01613 Sed_size_class
01614 sed_cell_size_class( const Sed_cell c )
01615 {
01616    Sed_size_class class = S_SED_TYPE_NONE;
01617 
01618    if ( c )
01619    {
01620       double d_mean = sed_sediment_property_avg( NULL , c->f , &sed_type_grain_size_in_phi );
01621       class = sed_size_class( d_mean );
01622    }
01623 
01624    return class;
01625 }
01626 
01639 double
01640 sed_cell_size_class_percent( const Sed_cell c , Sed_size_class size )
01641 {
01642    double p = 0.;
01643 
01644    if ( c )
01645       p = sed_sediment_property_avg_with_data( NULL , c->f , &sed_type_is_size_class_with_data , &size );
01646    return p;
01647 }
01648 
01649 Sed_size_class
01650 sed_cell_size_classes( const Sed_cell c )
01651 {
01652    Sed_size_class size = S_SED_TYPE_NONE;
01653 
01654    if ( c )
01655       sed_sediment_property_avg_with_data( NULL , c->f , &sed_type_sum_size_classes_with_data , &size );
01656    return size;
01657 }
01658 
01659 double
01660 sed_cell_density( const Sed_cell c )
01661 {
01662    double d = c->t / c->t_0;
01663    return sed_sediment_property_avg_with_data( NULL , c->f , &sed_type_density_compacted , &d );
01664 }
01665 
01666 double
01667 sed_cell_sediment_volume( const Sed_cell c )
01668 {
01669    double v = 0.;
01670 
01671    if ( c )
01672       v = c->t / ( sed_cell_void_ratio(c) + 1 );
01673 
01674    return v;
01675 }
01676 
01677 double
01678 sed_cell_sediment_mass( const Sed_cell c )
01679 {
01680    double m = 0;
01681 
01682    if ( c )
01683       m = sed_cell_grain_density(c)*sed_cell_sediment_volume(c);
01684 
01685    return m;
01686 }
01687 
01688 //
01689 // End of S_property_func's
01690 //
01692 
01694 //
01695 // These are the pre-defined S_property_with_load_func's
01696 //
01697 //   functions are of the form:
01698 //   double f(Sed_cell*,double,sediment,n)
01699 //
01700 
01701 double
01702 sed_cell_mv( const Sed_cell c )
01703 {
01704 /*
01705    double e=sed_cell_void_ratio(c,sed,n);
01706    double Cc=sed_cell_cc(c,sed,n);
01707    return .435 / (1+e) * ( Cc / load );
01708 */
01709    return sed_sediment_property_avg( NULL , c->f , &sed_type_compressibility );
01710 }
01711 
01712 double
01713 sed_cell_cv( const Sed_cell c )
01714 {
01715    return sed_sediment_property_avg( NULL , c->f , &sed_type_cv );
01716 }
01717 
01718 double
01719 sed_cell_bulk_cv( const Sed_cell c )
01720 {
01721    double mv = sed_cell_mv( c );
01722    return sed_cell_bulk_hydraulic_conductivity( c ) / ( S_GAMMA_WATER * mv );
01723 }
01724 
01732 double
01733 sed_cell_shear_strength( const Sed_cell c , double load )
01734 {
01735    return sed_sediment_property_avg_with_data( NULL , c->f , &sed_type_shear_strength_with_data , &load );
01736 }
01737 
01745 double
01746 sed_cell_cohesion(const Sed_cell c, double load )
01747 {
01748    load -= c->pressure;
01749    eh_lower_bound( load , 0 );
01750 
01751    return sed_sediment_property_avg_with_data( NULL , c->f , &sed_type_cohesion_with_data , &load );
01752 //   cohesion = load * tan(sed_cell_friction_angle(c,sed,n)*M_PI/180.) - sed_cell_shear_strength(c,load,sed,n);
01753 }
01754 
01769 double
01770 sed_cell_consolidation( const Sed_cell c , double time_now )
01771 {
01772    double dt = time_now - sed_cell_age_in_years( c );
01773    double d  = sed_cell_size(c);
01774    double data[2];
01775 
01776    data[0] = d;
01777    data[1] = dt;
01778 
01779    return sed_sediment_property_avg_with_data( NULL , c->f , &sed_type_consolidation_with_data , data );
01780 }
01781 
01782 /* now defined in sed_property.c
01783 double
01784 sed_calculate_avg_consolidation( double c_v , double d , double t )
01785 {
01786    double t_v = c_v*t/(d*d);
01787    if ( d <= 0 )
01788       return 1.;
01789    if ( t_v < .2827 )
01790       return ( sqrt(4./G_PI*t_v) );
01791    else
01792       return ( 1-8/(G_PI*G_PI)*exp(-G_PI*G_PI/4.*t_v) );
01793 }
01794 
01795 double
01796 sed_calculate_consolidation( double c_v , double d , double z , double t )
01797 {
01798    double t_v = c_v*t/(d*d);
01799    double n, eps = G_MAXDOUBLE;
01800    double u, u_0;
01801 
01802    if ( d <= 0 )
01803       return 1.;
01804    if ( t <= 0 )
01805       return 0;
01806 
01807    for ( n=1,u=0 ; eps>1e-3 ; n+=2 )
01808    {
01809       u_0 = u;
01810       u += 1./n*sin( n*G_PI*z/d )*exp( -pow(n*G_PI*.5,2)*t_v );
01811       eps = fabs( ( u_0 - u ) / u );
01812    }
01813    u *= 4/G_PI;
01814 
01815    return 1-u;
01816 }
01817 */
01818 
01819 double
01820 sed_cell_consolidation_rate( const Sed_cell c , double time_now )
01821 {
01822    double dt = time_now - sed_cell_age_in_years( c );
01823    double d  = sed_cell_size(c);
01824    double data[2];
01825 
01826    data[0] = d;
01827    data[1] = dt;
01828 
01829    return sed_sediment_property_avg_with_data( NULL , c->f , &sed_type_consolidation_rate_with_data , data );
01830 }
01831 
01832 //
01833 // End of S_property_with_load_func's
01834 //
01836 
01837 double
01838 sed_cell_thickness(const Sed_cell c)
01839 {
01840    if ( G_LIKELY(c) )
01841       return c->t;
01842    else
01843       return 0;
01844 }
01845 
01852 double
01853 sed_cell_size( const Sed_cell c )
01854 {
01855    if ( G_LIKELY(c) )
01856       return c->t;
01857    else
01858       return 0;
01859 }
01860 
01861 double
01862 sed_cell_size_0( const Sed_cell c )
01863 {
01864    if ( G_LIKELY(c) )
01865       return c->t_0;
01866    else
01867       return 0;
01868 }
01869 
01874 double
01875 sed_cell_fraction( const Sed_cell c , gssize n )
01876 {
01877    eh_require( c );
01878    eh_require( n>=0 );
01879    eh_require( n<sed_cell_n_types(c) );
01880 
01881    return c->f[n];
01882 }
01883 
01890 double
01891 sed_cell_pressure( const Sed_cell c )
01892 {
01893    eh_require( c );
01894    return c->pressure;
01895 }
01896 
01897 double
01898 sed_cell_excess_pressure( const Sed_cell c   ,
01899                                  double hydro_static )
01900 {
01901    double pressure;
01902    eh_require( c );
01903    
01904    pressure = sed_cell_pressure(c) - hydro_static;
01905 
01906    return (pressure<0)?0:pressure;
01907 }
01908 
01912 double
01913 sed_cell_age(const Sed_cell c)
01914 {
01915    eh_require( c );
01916    return c->age;
01917 }
01918 
01919 gssize
01920 sed_cell_n_types( const Sed_cell c )
01921 {
01922    eh_require( c );
01923    return c->n;
01924 }
01925 
01929 double
01930 sed_cell_age_in_years( const Sed_cell c )
01931 {
01932    eh_require( c );
01933    return c->age;
01934 }
01935 
01939 Sed_facies
01940 sed_cell_facies( const Sed_cell c )
01941 {
01942    eh_require( c );
01943    return c->facies;
01944 }
01945 
01956 double
01957 sed_cell_mass( const Sed_cell c )
01958 {
01959    double mass = 0;
01960 
01961    eh_require( c )
01962    {
01963       if ( !sed_cell_is_empty(c) )
01964          mass = c->t*sed_cell_density( c );
01965    }
01966 
01967    return mass;
01968 }
01969 
01980 double
01981 sed_cell_load( const Sed_cell c )
01982 {
01983    return sed_cell_mass(c)*sed_gravity();
01984 }
01985 
01986 double
01987 sed_cell_sediment_load( const Sed_cell c )
01988 {
01989    return sed_cell_sediment_mass(c)*sed_gravity();
01990 }
01991 
02004 gssize
02005 sed_cell_write( FILE *fp, const Sed_cell c )
02006 {
02007    return sed_cell_write_to_byte_order( fp , c , G_BYTE_ORDER );
02008 }
02009 
02010 gssize
02011 sed_cell_write_to_byte_order( FILE *fp, const Sed_cell c , int order )
02012 {
02013    gssize n = 0;
02014 
02015    eh_require( fp );
02016    eh_require( c  );
02017 
02018    if ( order==G_BYTE_ORDER )
02019    {
02020       n += fwrite( &c->n        , sizeof(gssize)        , 1    , fp );
02021       n += fwrite( c->f         , sizeof(double)        , c->n , fp );
02022       n += fwrite( &c->t_0      , sizeof(double)        , 1    , fp );
02023       n += fwrite( &c->t        , sizeof(double)        , 1    , fp );
02024       n += fwrite( &c->age      , sizeof(double)        , 1    , fp );
02025       n += fwrite( &c->pressure , sizeof(double)        , 1    , fp );
02026       n += fwrite( &c->facies   , sizeof(unsigned char) , 1    , fp );
02027    }
02028    else
02029    {
02030       n += eh_fwrite_int32_swap( &c->n        , sizeof(gssize)        , 1    , fp );
02031       n += eh_fwrite_dbl_swap  ( c->f         , sizeof(double)        , c->n , fp );
02032       n += eh_fwrite_dbl_swap  ( &c->t_0      , sizeof(double)        , 1    , fp );
02033       n += eh_fwrite_dbl_swap  ( &c->t        , sizeof(double)        , 1    , fp );
02034       n += eh_fwrite_dbl_swap  ( &c->age      , sizeof(double)        , 1    , fp );
02035       n += eh_fwrite_dbl_swap  ( &c->pressure , sizeof(double)        , 1    , fp );
02036       n += fwrite              ( &c->facies   , sizeof(unsigned char) , 1    , fp );
02037    }
02038 
02039    eh_require( n == 6+c->n );
02040 
02041    return n;
02042 }
02043 
02057 Sed_cell
02058 sed_cell_read( FILE *fp )
02059 {
02060    Sed_cell c;
02061 
02062    eh_require( fp );
02063 
02064    {
02065       gint32 n;
02066 
02067       fread( &n             , sizeof(gint32)        , 1 , fp );
02068 
02069       eh_require( n>0 );
02070 
02071       c = sed_cell_new( n );
02072 
02073       fread( c->f           , sizeof(double)        , n , fp );
02074       fread( &(c->t_0)      , sizeof(double)        , 1 , fp );
02075       fread( &(c->t)        , sizeof(double)        , 1 , fp );
02076       fread( &(c->age)      , sizeof(double)        , 1 , fp );
02077       fread( &(c->pressure) , sizeof(double)        , 1 , fp );
02078       fread( &(c->facies)   , sizeof(Sed_facies)    , 1 , fp );
02079    }
02080 
02081    return c;
02082 }
02083 
02097 Sed_cell
02098 sed_cell_resize( Sed_cell c , double t )
02099 {
02100    eh_require( c );
02101 
02102    if ( t>0 )
02103    {
02104       if ( c->t > 0 )
02105       {
02106          double ratio = c->t_0 / c->t;
02107          c->t   = t;
02108          c->t_0 = c->t*ratio;
02109       }
02110       else
02111       {
02112          c->t   = t;
02113          c->t_0 = t;
02114       }
02115    }
02116    else
02117       sed_cell_clear( c );
02118 
02119    return c;
02120 }
02121 
02136 Sed_cell
02137 sed_cell_compact( Sed_cell c , double new_t )
02138 {
02139    eh_require( c );
02140    eh_require( new_t>=0 );
02141 
02142    eh_lower_bound( new_t , 0 );
02143 
02144 //   c->pressure  *= c->t/new_t;
02145    c->t  = new_t;
02146 
02147    return c;
02148 }
02149 
02164 Sed_cell_grid
02165 sed_cell_grid_new( gsize n_x , gsize n_y )
02166 {
02167    Sed_cell_grid g = eh_grid_new( Sed_cell , n_x , n_y );
02168    return g;
02169 }
02170 
02171 Sed_cell_grid
02172 sed_cell_grid_new_env( gsize n_x , gsize n_y )
02173 {
02174    Sed_cell_grid g = sed_cell_grid_new( n_x , n_y );
02175    return sed_cell_grid_init( g , sed_sediment_env_n_types() );
02176 }
02177 
02190 Sed_cell_grid
02191 sed_cell_grid_init( Sed_cell_grid g , gssize n_grains )
02192 {
02193    eh_require( g );
02194    eh_require( n_grains>0 );
02195 
02196    if ( g )
02197    {
02198       Sed_cell* data = eh_grid_data_start(g);
02199       gssize i, n_i = eh_grid_n_el( g );
02200 
02201       for ( i=0 ; i<n_i ; i++ )
02202          data[i] = sed_cell_new( n_grains );
02203 
02204    }
02205 
02206    return g;
02207 }
02208 
02218 void
02219 sed_cell_grid_free( Sed_cell_grid g )
02220 {
02221    if ( g )
02222    {
02223       Sed_cell* data = eh_grid_data_start(g);
02224       gssize i, n_i = eh_grid_n_el( g );
02225 
02226       for ( i=0 ; i<n_i ; i++ )
02227          data[i] = sed_cell_destroy( data[i] );
02228    }
02229 }
02230 
02231 Sed_cell_grid
02232 sed_cell_grid_destroy( Sed_cell_grid g )
02233 {
02234    if ( g )
02235    {
02236       sed_cell_grid_free( g );
02237       eh_grid_destroy( g , TRUE );
02238    }
02239 
02240    return NULL;
02241 }
02242 
02243 void
02244 sed_cell_grid_free_data( Sed_cell_grid g )
02245 {
02246    eh_require( g )
02247    {
02248       gssize i;
02249       gssize n_i  = eh_grid_n_el( g );
02250       Sed_cell* c = eh_grid_data_start( g );
02251 
02252       for ( i=0 ; i<n_i ; i++ )
02253          sed_cell_destroy( c[i] );
02254    }
02255 
02256    return;
02257 }
02258 
02259 Sed_cell
02260 sed_cell_grid_val( Sed_cell_grid g , gssize i , gssize j )
02261 {
02262    return ((Sed_cell*)eh_grid_row(g,i))[j];
02263 }
02264 
02265 Sed_cell_grid
02266 sed_cell_grid_add( Sed_cell_grid g_1 , Sed_cell_grid g_2 )
02267 {
02268    gssize i;
02269    gssize n_i    = eh_grid_n_el( g_1 );
02270    Sed_cell* c_1 = eh_grid_data_start( g_1 );
02271    Sed_cell* c_2 = eh_grid_data_start( g_2 );
02272 
02273    eh_require( eh_grid_is_compatible( g_1 , g_2 ) )
02274    {
02275       for ( i=0 ; i<n_i ; i++ )
02276          sed_cell_add( c_1[i] , c_2[i] );
02277    }
02278 
02279    return g_1;
02280 }
02281 
02282 Sed_cell_grid
02283 sed_cell_grid_copy_data( Sed_cell_grid dest , Sed_cell_grid src )
02284 {
02285    gssize i;
02286    gssize n_i    = eh_grid_n_el( dest );
02287    Sed_cell* c_1 = eh_grid_data_start( dest );
02288    Sed_cell* c_2 = eh_grid_data_start( src  );
02289 
02290    eh_require( eh_grid_is_compatible( dest , src ) )
02291    {
02292       for ( i=0 ; i<n_i ; i++ )
02293          sed_cell_copy( c_1[i] , c_2[i] );
02294    }
02295 
02296    return dest;
02297 }
02298 
02299 Sed_cell_grid
02300 sed_cell_grid_clear( Sed_cell_grid g )
02301 {
02302    eh_require( g )
02303    {
02304       gssize i;
02305       gssize n_i  = eh_grid_n_el( g );
02306       Sed_cell* c = eh_grid_data_start( g );
02307 
02308       for ( i=0 ; i<n_i ; i++ )
02309          sed_cell_clear( c[i] );
02310    }
02311 
02312    return g;
02313 }
02314 
02315 double
02316 sed_cell_grid_mass( Sed_cell_grid g )
02317 {
02318    double sum = 0;
02319 
02320    eh_require( g )
02321    {
02322       gssize i;
02323       gssize n_i  = eh_grid_n_el( g );
02324       Sed_cell* c = eh_grid_data_start( g );
02325 
02326       for ( i=0 ; i<n_i ; i++ )
02327          sum += sed_cell_mass( c[i] );
02328    }
02329 
02330    return sum;
02331 }
02332 
02341 Sed_cell**
02342 sed_cell_grid_data( Sed_cell_grid g )
02343 {
02344    return (Sed_cell**)eh_grid_data( g );
02345 }
02346 
02347 gboolean
02348 sed_cell_is_same( Sed_cell a , Sed_cell b )
02349 {
02350    gboolean same = TRUE;
02351 
02352    eh_require( a );
02353    eh_require( b );
02354 
02355    if ( a != b )
02356    {
02357       if (    sed_cell_n_types(a) != sed_cell_n_types(b)
02358            || fabs( sed_cell_size(a)-sed_cell_size(b) )>1e-6
02359            || fabs( sed_cell_age(a) - sed_cell_age(b) )>1e-6
02360            || sed_cell_facies(a) != sed_cell_facies(b) )
02361          same = FALSE;
02362       else
02363       {
02364          gssize n;
02365          gssize len = sed_cell_n_types(a);
02366 
02367          for ( n=0 ; same && n<len ; n++ )
02368          {
02369             if ( fabs( a->f[n]-b->f[n] ) > 1e-6 )
02370                same = FALSE;
02371          }
02372       }
02373    }
02374 
02375    return same;
02376 }
02377 
02378 gboolean
02379 sed_cell_is_valid( Sed_cell c )
02380 {
02381    gboolean is_valid = TRUE;
02382 
02383    if ( c )
02384    {
02385       if ( sed_cell_n_types(c)<=0 || sed_cell_size(c)<0 )
02386          is_valid = FALSE;
02387       else
02388       {
02389          gssize n;
02390          gssize len = sed_cell_n_types(c);
02391          double sum = 0;
02392 
02393          for ( n=0 ; is_valid && n<len ; n++ )
02394          {
02395             if ( c->f[n]<0. || c->f[n]>1. )
02396                is_valid = FALSE;
02397             else
02398                sum += c->f[n];
02399          }
02400 
02401          if ( is_valid && fabs( sum-1. ) > 1e-6 && !sed_cell_is_clear(c) )
02402             is_valid = FALSE;
02403       }
02404    }
02405    else
02406       is_valid = FALSE;
02407 
02408    return is_valid;
02409 }
02410 
02411 Sed_cell*
02412 sed_cell_array_free( Sed_cell* a )
02413 {
02414    if ( a )
02415    {
02416       Sed_cell* p = a;
02417       for ( ; *p ; p++ ) sed_cell_destroy( *p );
02418       eh_free( a );
02419    }
02420    return NULL;
02421 }
02422 
02423 double
02424 sed_cell_array_mass( Sed_cell* a )
02425 {
02426    double m = 0;
02427 
02428    if ( a )
02429    {
02430       Sed_cell* p = a;
02431       for ( ; *p ; p++ ) m += sed_cell_mass( *p );
02432    }
02433 
02434    return m;
02435 }
02436 
02437 gint
02438 sed_cell_array_fprint( FILE* fp , Sed_cell* a )
02439 {
02440    gint n = 0;
02441    if ( a )
02442    {
02443       Sed_cell* c = a;
02444       for ( ; *c ; c++ ) n += sed_cell_fprint( fp , *c );
02445    }
02446    else
02447       n += fprintf( fp , "(empty cell array)\n" );
02448 
02449    return n;
02450 }
02451 
02452 Sed_cell*
02453 sed_cell_array_delete_empty( Sed_cell* a )
02454 {
02455    if ( a )
02456    {
02457       Sed_cell* c = a;
02458       Sed_cell* p = a;
02459 
02460       for ( ; *c ; c++ )
02461          if ( sed_cell_is_empty(*c) || sed_cell_is_clear(*c) )
02462             sed_cell_destroy(*c);
02463          else
02464          {
02465             *p = *c;
02466             p++;
02467          }
02468       *p = NULL;
02469 
02470       if ( *a==NULL )
02471       {
02472          eh_free( a );
02473          a = NULL;
02474       }
02475    }
02476    return a;
02477 }
02478  /* End Sed_cell group */
02480 

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