/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/plume/plume_run_file.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 "plumevars.h"
00022 #include "plumeinput.h"
00023 #include "plume_approx.h"
00024 
00025 #include "glib.h"
00026 #include <utils/utils.h>
00027 #include <sed/sed_sedflux.h>
00028 
00029 Eh_opt_entry all_entries[] = {
00030    { "infile"  , 'i' , "Hydrotrend input file" , NULL , "-"                   },
00031    { "sedfile" , 's' , "Sediment input file"   , NULL , SED_SEDIMENT_TEST_FILE },
00032    { "len"     , 'n' , "Number of grid points" , NULL , "1000" },
00033    { "spacing" , 'd' , "Spacing between grid nodes" , NULL , "100" },
00034    { "width"   , 'w' , "Width of the basin"         , NULL , "1000" },
00035    { "verbose" , 'v' , "Verbose" , NULL , "TRUE" },
00036    { NULL }
00037 };
00038 
00039 int main(int argc, char *argv[])
00040 {
00041    char* river_file;
00042    char* sediment_file;
00043    gssize len;
00044    double dx;
00045    double width;
00046    gboolean verbose;
00047    Sed_cell_grid dep;
00048 
00049    eh_init_glib();
00050 
00051    {
00052       Eh_opt_context this_context = eh_opt_create_context( "PLUME" ,
00053                                                            "Run plumes from a file"  ,
00054                                                            "Option specific to PLUME" );
00055 
00056       eh_opt_set_context  ( this_context , all_entries );
00057       eh_opt_parse_context( this_context , &argc , &argv , NULL );
00058 
00059       river_file    = eh_opt_value     ( this_context , "infile"  );
00060       sediment_file = eh_opt_value     ( this_context , "sedfile" );
00061       len           = eh_opt_int_value ( this_context , "len"     );
00062       dx            = eh_opt_dbl_value ( this_context , "spacing" );
00063       width         = eh_opt_dbl_value ( this_context , "width"   );
00064       verbose       = eh_opt_bool_value( this_context , "verbose" );
00065 dx = 12.5;
00066    }
00067 
00068    {
00069       GError*      error    = NULL;
00070       Sed_sediment this_sed = sed_sediment_scan( sediment_file , &error );
00071 
00072       if ( !this_sed )
00073          eh_error( "%s: Unable to scan sediment file: %s" , sediment_file , error->message );
00074 
00075       sed_sediment_set_env( this_sed );
00076       sed_sediment_destroy( this_sed );
00077    }
00078 
00079    if ( verbose )
00080    {
00081       fprintf( stderr , "Number of grid nodes  : %d\n" , len );
00082       fprintf( stderr , "Spacing of grid nodes : %f\n" , dx );
00083       fprintf( stderr , "Basin width           : %f\n" , width );
00084       fprintf( stderr , "Input file            : %s\n" , river_file );
00085       fprintf( stderr , "Sediment file         : %s\n" , sediment_file );
00086    }
00087 
00088    {
00089       dep = eh_grid_new( Sed_cell , 1 , len );
00090       eh_grid_set_y_lin( dep , 0 , dx );
00091       sed_cell_grid_init( dep , sed_sediment_env_n_types() );
00092    }
00093 
00094    if ( river_file )
00095    {
00096       gssize i;
00097       double dt;
00098       Sed_hydro_file f = sed_hydro_file_new( river_file , SED_HYDRO_HYDROTREND , FALSE , TRUE , NULL );
00099 //      Sed_hydro_file f = sed_hydro_file_new( river_file , HYDRO_HYDROTREND|HYDRO_USE_BUFFER , TRUE );
00100       Sed_hydro river;
00101       double mass_in  = 0;
00102       double mass_out = 0;
00103 
00104       for ( dt=0 ; dt<1 ; )
00105       {
00106          river = sed_hydro_file_read_record( f );
00107 
00108          mass_in += sed_hydro_suspended_load( river );
00109 
00110          dt += sed_hydro_duration( river );
00111 
00112          if ( verbose )
00113          {
00114             fprintf( stderr , "\r%.2f%%" , dt/365.*100. );
00115 //            sed_hydro_fprint( stderr , river );
00116          }
00117 
00118          if ( dt <= 1 )
00119 //            dep = plume_width_averaged_deposit( dep , river , sed_sediment_env() , width );
00120            dep = plume_width_averaged_deposit_num( dep , river , NULL , width );
00121 //            dep = plume_centerline_deposit( dep , river , sed_sediment_env() );
00122 
00123          sed_hydro_destroy( river );
00124 
00125          for ( i=0 ; i<len-1 ; i++ )
00126             fprintf( stdout , "%.12f " , sed_cell_size( sed_cell_grid_val(dep,0,i) ) );
00127          fprintf( stdout , "%.12f\n" , sed_cell_size( sed_cell_grid_val(dep,0,i) ) );
00128       }
00129 
00130       if ( verbose )
00131          fprintf( stderr , "\n" );
00132 
00133       sed_hydro_file_destroy( f );
00134 
00135       for ( i=0 ; i<len ; i++ )
00136          mass_out += sed_cell_mass( sed_cell_grid_val(dep,0,i) )*dx*width ;
00137 
00138       if ( verbose )
00139       {
00140          fprintf( stderr , "Mass input from river (kg)   : %f\n" , mass_in  );
00141          fprintf( stderr , "Mass deposited by plume (kg) : %f\n" , mass_out );
00142       }
00143 
00144    }
00145 
00146    sed_cell_grid_free( dep );
00147    eh_grid_destroy( dep , TRUE );
00148 
00149    sed_sediment_unset_env();
00150 
00151    return 0;
00152 }
00153 

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