/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/sedflux/run_tide.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_TIDE_PROC_NAME "tide"
00022 #define EH_LOG_DOMAIN SED_TIDE_PROC_NAME
00023 
00024 #include <stdio.h>
00025 #include <string.h>
00026 #include <math.h>
00027 
00028 #include <utils/utils.h>
00029 #include "my_processes.h"
00030 
00031 Sed_process_info
00032 run_tide( Sed_process proc , Sed_cube prof )
00033 {
00034    Tide_t*          data = sed_process_user_data(proc);
00035    Sed_process_info info = SED_EMPTY_INFO;
00036 
00037    if ( data->tidal_period<0 )
00038       data->tidal_period = sed_cube_time_step_in_days( prof );
00039 
00040    sed_cube_set_tidal_range ( prof , data->tidal_range  );
00041    sed_cube_set_tidal_period( prof , data->tidal_period );
00042 
00043    eh_message( "time         : %f" , sed_cube_age_in_years(prof) );
00044    eh_message( "tidal range  : %f" , data->tidal_range                  );
00045    eh_message( "tidal period : %f" , data->tidal_period                 );
00046 
00047    return info;
00048 }
00049 
00050 #include <sys/stat.h>
00051 
00052 #define S_KEY_TIDE_RANGE  "tidal range"
00053 #define S_KEY_TIDE_PERIOD "tidal period"
00054 
00055 gboolean
00056 init_tide( Sed_process p , Eh_symbol_table tab , GError** error )
00057 {
00058    Tide_t*  data    = sed_process_new_user_data( p , Tide_t );
00059    GError*  tmp_err = NULL;
00060    gchar**  err_s   = NULL;
00061    gboolean is_ok   = TRUE;
00062    gchar*   str;
00063 
00064    eh_return_val_if_fail( error==NULL || *error==NULL , FALSE );
00065 
00066    data->tidal_range  = eh_symbol_table_dbl_value( tab , S_KEY_TIDE_RANGE  );
00067    str                = eh_symbol_table_lookup   ( tab , S_KEY_TIDE_PERIOD );
00068 
00069    if ( g_ascii_strcasecmp( str , "time step" )==0 ) data->tidal_period = -1;
00070    else
00071    {
00072       data->tidal_period = eh_str_to_dbl( str , &tmp_err );
00073 
00074       g_message( "The tidal period must be set to 'time step'.  Resetting." );
00075       data->tidal_period = -1;
00076    }
00077 
00078    eh_check_to_s( data->tidal_range>=0 , "Tidal range positive" , &err_s );
00079 
00080    if ( !tmp_err && err_s )
00081       eh_set_error_strv( &tmp_err , SEDFLUX_ERROR , SEDFLUX_ERROR_BAD_PARAM , err_s );
00082 
00083    if ( tmp_err )
00084    {
00085       g_propagate_error( error , tmp_err );
00086       is_ok = FALSE;
00087    }
00088 
00089    return is_ok;
00090 }
00091 
00092 gboolean
00093 destroy_tide( Sed_process p )
00094 {
00095    if ( p )
00096    {
00097       Tide_t* data = sed_process_user_data( p );
00098       
00099       if ( data ) eh_free( data );
00100    }
00101 
00102    return TRUE;
00103 }
00104 

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