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 <limits.h> 00023 #include <math.h> 00024 #include <string.h> 00025 00026 #include <sed/sed_sedflux.h> 00027 #include <plume_types.h> 00028 #include <utils/utils.h> 00029 00046 /* 00047 Sed_process_queue 00048 sedflux_create_process_queue( const gchar* file , gchar** user_data , GError** error ) 00049 { 00050 Sed_process_queue q = NULL; 00051 00052 eh_require( file ); 00053 eh_return_val_if_fail( error==NULL || *error==NULL , NULL ); 00054 00055 if ( file ) 00056 { 00057 GError* tmp_err = NULL; 00058 Eh_key_file key_file = NULL; 00059 00060 key_file = eh_key_file_scan( file , &tmp_err ); 00061 00062 if ( key_file ) 00063 { 00064 gint n_processes = sizeof( process_list ) / sizeof(Sed_process_init_t); 00065 gssize i; 00066 00067 q = sed_process_queue_new(); 00068 for ( i=0 ; i<n_processes ; i++ ) 00069 sed_process_queue_push( q , process_list[i] ); 00070 00071 sed_process_queue_scan( q , key_file , &tmp_err ); 00072 00073 if ( !tmp_err ) 00074 { 00075 if ( user_data ) 00076 { 00077 gchar** name; 00078 sed_process_queue_deactivate( q , "<all>" ); 00079 00080 for ( name=user_data ; *name ; name++ ) 00081 sed_process_queue_activate( q , *name ); 00082 } 00083 00084 00085 { 00086 gssize i; 00087 Failure_proc_t** data; 00088 Sed_process d = sed_process_queue_find_nth_obj( q , "debris flow" , 0 ); 00089 Sed_process t = sed_process_queue_find_nth_obj( q , "turbidity current" , 0 ); 00090 Sed_process s = sed_process_queue_find_nth_obj( q , "slump" , 0 ); 00091 00092 data = (Failure_proc_t**)sed_process_queue_obj_data( q , "failure" ); 00093 for ( i=0 ; data && data[i] ; i++ ) 00094 { 00095 data[i]->debris_flow = d; 00096 data[i]->turbidity_current = t; 00097 data[i]->slump = s; 00098 } 00099 eh_free( data ); 00100 } 00101 } 00102 } 00103 00104 if ( tmp_err ) 00105 { 00106 g_propagate_error( error , tmp_err ); 00107 q = NULL; 00108 } 00109 00110 eh_key_file_destroy( key_file ); 00111 } 00112 00113 return q; 00114 } 00115 */ 00116 00117 typedef struct 00118 { 00119 const gchar* name; 00120 gint error; 00121 } Process_check_t; 00122 00125 Process_check_t process_check[] = 00126 { 00127 {"plume" , SED_ERROR_MULTIPLE_PROCS|SED_ERROR_INACTIVE|SED_ERROR_NOT_ALWAYS } , 00128 {"bedload dumping" , SED_ERROR_MULTIPLE_PROCS|SED_ERROR_INACTIVE|SED_ERROR_NOT_ALWAYS } , 00129 {"bbl" , SED_ERROR_MULTIPLE_PROCS|SED_ERROR_INACTIVE|SED_ERROR_NOT_ALWAYS } , 00130 {"river" , SED_ERROR_INACTIVE|SED_ERROR_NOT_ALWAYS } , 00131 {"earthquake" , SED_ERROR_MULTIPLE_PROCS } , 00132 {"storms" , SED_ERROR_MULTIPLE_PROCS } 00133 }; 00134 00135 typedef struct 00136 { 00137 const gchar* parent_name; 00138 const gchar* child_name; 00139 gint error; 00140 } Family_check_t; 00141 00144 Family_check_t family_check[] = 00145 { 00146 { "failure" , "earthquake" , SED_ERROR_INACTIVE_PARENT|SED_ERROR_ABSENT_PARENT|SED_ERROR_DT_MISMATCH }, 00147 { "squall" , "storms" , SED_ERROR_INACTIVE_PARENT|SED_ERROR_ABSENT_PARENT|SED_ERROR_DT_MISMATCH }, 00148 { "xshore" , "storms" , SED_ERROR_INACTIVE_PARENT|SED_ERROR_ABSENT_PARENT|SED_ERROR_DT_MISMATCH }, 00149 { "diffusion" , "storms" , SED_ERROR_INACTIVE_PARENT|SED_ERROR_ABSENT_PARENT|SED_ERROR_DT_MISMATCH } 00150 }; 00151 00152 00165 /* 00166 gboolean 00167 check_process_list( Sed_process_queue q , GError** error ) 00168 { 00169 gboolean file_is_ok = TRUE; 00170 gchar** err_s_list = NULL; 00171 gint error_no = 0; 00172 gssize n_checks = sizeof( process_check ) / sizeof( Process_check_t ); 00173 gssize n_families; 00174 gssize i; 00175 gchar* err_s = NULL; 00176 00177 eh_return_val_if_fail( error==NULL || *error==NULL , FALSE ); 00178 00179 for ( i=0 ; i<n_checks ; i++ ) 00180 { 00181 error_no = sed_process_queue_check( q , process_check[i].name ); 00182 if ( error_no!=0 & process_check[i].error ) 00183 { 00184 err_s = g_strdup_printf( "%s: Error in process input file" , process_check[i].name , error_no ); 00185 eh_strv_append( &err_s_list , err_s ); 00186 } 00187 } 00188 00189 n_families = sizeof( family_check ) / sizeof( Family_check_t ); 00190 00191 for ( i=0 ; i<n_families ; i++ ) 00192 { 00193 error_no = sed_process_queue_check_family( q , 00194 family_check[i].parent_name , 00195 family_check[i].child_name , NULL ); 00196 if ( error_no!=0 & family_check[i].error ) 00197 { 00198 eh_warning( "%s: Possible error (#%d) in process input file." , 00199 family_check[i].parent_name , error ); 00200 00201 err_s = g_strdup_printf( "%s: Error %d in process input file" , process_check[i].name , error_no ); 00202 eh_strv_append( &err_s_list , err_s ); 00203 } 00204 } 00205 00206 if ( err_s_list!=NULL ) 00207 { 00208 GError* tmp_err = NULL; 00209 gchar* err_msg = g_strjoinv( "\n" , err_s_list ); 00210 00211 g_set_error( &tmp_err , SEDFLUX_ERROR , SEDFLUX_ERROR_PROCESS_FILE_CHECK , err_msg ); 00212 00213 g_propagate_error( error , tmp_err ); 00214 00215 eh_free ( err_msg ); 00216 g_strfreev( err_s_list ); 00217 00218 file_is_ok = FALSE; 00219 } 00220 else 00221 file_is_ok = TRUE; 00222 00223 return file_is_ok; 00224 } 00225 */ 00226 00227 00245 /* 00246 gboolean 00247 check_process_files( Sed_epoch_queue e_list , gchar** active , GError** error ) 00248 { 00249 gboolean no_errors = TRUE; 00250 00251 eh_return_val_if_fail( error==NULL || *error==NULL , FALSE ); 00252 00253 { 00254 GError* tmp_err = NULL; 00255 int n_epochs = sed_epoch_queue_length( e_list ); 00256 gssize i; 00257 Sed_process_queue q; 00258 Sed_epoch this_epoch; 00259 00260 //--- 00261 // For each epoch, we create each of the processes, initialize the 00262 // processes from the appropriate input file, and destroy the processes. 00263 //--- 00264 for ( i=0 ; i<n_epochs && !tmp_err ; i++ ) 00265 { 00266 this_epoch = sed_epoch_queue_nth( e_list , i ); 00267 00268 q = sedflux_create_process_queue( sed_epoch_filename(this_epoch) , active , &tmp_err ); 00269 00270 if ( q ) 00271 { 00272 no_errors = no_errors && check_process_list( q , &tmp_err ); 00273 sed_process_queue_destroy( q ); 00274 } 00275 } 00276 00277 if ( tmp_err ) 00278 { 00279 g_propagate_error( error , tmp_err ); 00280 no_errors = FALSE; 00281 } 00282 } 00283 00284 return no_errors; 00285 } 00286 */ 00287