/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/failure/decider.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 <stdio.h>
00022 #include <unistd.h>
00023 #include <string.h>
00024 #include <utils/utils.h>
00025 #include <sed/sed_sedflux.h>
00026 #include "failure.h"
00027 
00028 #ifdef DECIDER_STANDALONE
00029 int main(int argc, char *argv[])
00030 {
00031    int decider(const Sed_cube*,double);
00032    int decision;
00033    Sed_cube p;
00034 
00035    p = sed_cube_read(stdin);
00036 
00037    decision = decider(p,DECIDER_THRESHOLD);
00038 
00039    sed_cube_write(stdout,p);
00040 
00041    fprintf(stderr,"decision = %d\n",decision);
00042 
00043    return decision;
00044 }
00045 #endif
00046 
00047 int decider( const Sed_cube p , double threshold )
00048 {
00049    double fsand=0,fclay=0;
00050    int decision;
00051 
00052    eh_require( p );
00053    eh_require( threshold>=0 );
00054    eh_require( threshold<=1 );
00055    eh_require( sed_cube_is_1d(p) );
00056 
00057    {
00058       gssize n_grains = sed_sediment_env_n_types( );
00059       gssize i;
00060       Sed_cell fail = sed_cell_new( n_grains );
00061       Sed_cell c    = sed_cell_new( n_grains );
00062 
00063       for ( i=0 ; i<sed_cube_n_y(p) ; i++ )
00064       {
00065          sed_column_top( sed_cube_col(p,i) , sed_cube_thickness(p,0,i) , c );
00066          sed_cell_add(fail,c);
00067       }
00068       fsand = sed_cell_sand_fraction( fail );
00069       fclay = sed_cell_clay_fraction( fail );
00070 
00071       sed_cell_destroy( c    );
00072       sed_cell_destroy( fail );
00073    }
00074 
00075    if ( fclay >= threshold )
00076       decision = DECIDER_DEBRIS_FLOW;
00077    else
00078       decision = DECIDER_TURBIDITY_CURRENT;
00079 
00080    return decision;
00081 }

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