00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00116 }
00117
00118 if ( dt <= 1 )
00119
00120 dep = plume_width_averaged_deposit_num( dep , river , NULL , width );
00121
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