/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/sedflux/run_squall.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 #define SED_SQUALL_PROC_NAME "squall"
00022 #define EH_LOG_DOMAIN SED_SQUALL_PROC_NAME
00023 
00024 #include <stdio.h>
00025 #include <math.h>
00026 #include <string.h>
00027 #include <glib.h>
00028 #include <utils/utils.h>
00029 #include <sed/sed_sedflux.h>
00030 #include <squall.h>
00031 #include "my_processes.h"
00032 
00033 #include "sedflux.h"
00034 
00035 Sed_process_info
00036 run_squall( Sed_process proc , Sed_cube prof )
00037 {
00038    Squall_t *       data = sed_process_user_data(proc);
00039    Sed_process_info info = SED_EMPTY_INFO;
00040    double t=0, dt, total_t;
00041 
00042 // 1e6y year run
00043 //   total_t = sed_get_profile_time_step_in_years( prof )*1e-2;
00044 // squall run
00045 //   total_t = sed_get_profile_time_step_in_years( prof )*1e-0;
00046 
00047 //   total_t = sed_get_profile_time_step_in_years( prof )*data->time_fraction;
00048    total_t = data->squall_duration;
00049    dt      = data->dt;
00050 
00051 //   sed_set_profile_wave_height( prof , 9   );
00052 //   sed_set_profile_wave_length( prof , 260 );
00053    
00054    eh_message( "squall            : %s" , "start" );
00055    eh_message( "time              : %f" , sed_cube_age_in_years(prof) );
00056    eh_message( "time step         : %f" , data->dt                    );
00057    eh_message( "no. of time steps : %f" , total_t/data->dt            );
00058    eh_message( "wave height       : %f" , sed_cube_wave_height(prof)  );
00059    eh_message( "wave length       : %f" , sed_cube_wave_length(prof)  );
00060    eh_message( "wave period       : %f" , sed_cube_wave_period(prof)  );
00061 
00062    do
00063    {
00064       if ( t+dt>total_t )
00065          dt = total_t-t;
00066       if ( !squall( prof , dt ) )
00067       {
00068          eh_message( "squall            : %s" , "done" );
00069          return info;
00070       }
00071       t += dt;
00072    }
00073    while ( t<total_t );
00074 
00075    eh_message( "squall            : %s" , "done" );
00076 
00077    return info;
00078 }
00079 
00080 #define S_KEY_TIME_STEP      "time step"
00081 #define S_KEY_TIME_FRACTION  "duration of squall"
00082 
00083 gboolean
00084 init_squall( Sed_process p , Eh_symbol_table tab , GError** error )
00085 {
00086    Squall_t* data    = sed_process_new_user_data( p , Squall_t );
00087    GError*   tmp_err = NULL;
00088    gchar**   err_s   = NULL;
00089    gboolean  is_ok   = TRUE;
00090 
00091    eh_return_val_if_fail( error==NULL || *error==NULL , FALSE );
00092 
00093    // Read squall time step and time fraction.
00094    data->dt              = eh_symbol_table_time_value( tab , S_KEY_TIME_STEP     );
00095    data->squall_duration = eh_symbol_table_time_value( tab , S_KEY_TIME_FRACTION );
00096 
00097    eh_check_to_s( data->dt>=0.               , "Time step positive"          , &err_s );
00098    eh_check_to_s( data->squall_duration>=0.  , "Duration of squall positive" , &err_s );
00099 
00100    if ( !tmp_err && err_s )
00101       eh_set_error_strv( &tmp_err , SEDFLUX_ERROR , SEDFLUX_ERROR_BAD_PARAM , err_s );
00102 
00103    if ( tmp_err )
00104    {
00105       g_propagate_error( error , tmp_err );
00106       is_ok = FALSE;
00107    }
00108 
00109    return is_ok;
00110 }
00111 
00112 gboolean
00113 destroy_squall( Sed_process p )
00114 {
00115    if ( p )
00116    {
00117       Squall_t* data = sed_process_user_data( p );
00118       
00119       if ( data ) eh_free( data );
00120    }
00121 
00122    return TRUE;
00123 }
00124 

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