/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/sedutils/sedflux-make-sequence.c

Go to the documentation of this file.
00001 #include <glib.h>
00002 #include <sed/sed_sedflux.h>
00003 
00004 static gchar*   out_file      = NULL;
00005 static double   val           = 1.;
00006 static double   time_key      = 0.;
00007 static gint     n_x           = 100;
00008 static gint     n_y           = 100;
00009 static gboolean big_endian    = FALSE;
00010 static gboolean little_endian = FALSE;
00011 static gboolean append        = FALSE;
00012 static gboolean version       = FALSE;
00013 static gint     verbosity     = 0;
00014 static gboolean debug         = FALSE;
00015 
00016 GOptionEntry entries[] =
00017 {
00018    { "out-file"      , 'o' , 0 , G_OPTION_ARG_FILENAME , &out_file      , "Output sequence file"          , "<file>" } ,
00019    { "val"           , 's' , 0 , G_OPTION_ARG_DOUBLE   , &val           , "Sequence value"                , "X"      } ,
00020    { "time"          , 't' , 0 , G_OPTION_ARG_DOUBLE   , &time_key      , "Time value of the grid"        , "TIME"   } ,
00021    { "nx"            , 'x' , 0 , G_OPTION_ARG_INT      , &n_x           , "Number of cell in x-dimension" , "NX"     } ,
00022    { "ny"            , 'y' , 0 , G_OPTION_ARG_INT      , &n_y           , "Number of cell in y-dimension" , "NY"     } ,
00023    { "big-endian"    , 'b' , 0 , G_OPTION_ARG_NONE     , &big_endian    , "Byte order is big endian"      , NULL     } ,
00024    { "little-endian" , 'l' , 0 , G_OPTION_ARG_NONE     , &little_endian , "Byte order is little endian"   , NULL     } ,
00025    { "append"        , 'a' , 0 , G_OPTION_ARG_NONE     , &append        , "Append a grid to the sequence" , NULL     } ,
00026    { "verbose"       , 'V' , 0 , G_OPTION_ARG_INT      , &verbosity     , "Verbosity level"               , "n"      } ,
00027    { "version"       , 'v' , 0 , G_OPTION_ARG_NONE     , &version       , "Version number"                , NULL     } ,
00028    { "debug"         , 'd' , 0 , G_OPTION_ARG_NONE     , &debug         , "Write debugging messages"      , NULL     } ,
00029    { NULL }
00030 };
00031 
00032 int main( int argc , char* argv[] )
00033 {
00034    GOptionContext* context = g_option_context_new( "Create a sequence grid file for sedflux-3d" );
00035    GError*         error   = NULL;
00036    FILE*           fp_out  = stdout;
00037    gint            byte_order = G_BYTE_ORDER;
00038 
00039    g_option_context_add_main_entries( context , entries , NULL );
00040 
00041    if ( !g_option_context_parse( context , &argc , &argv , &error ) )
00042       eh_error( "Error parsing command line arguments: %s" , error->message );
00043 
00044    if ( version )
00045       eh_fprint_version_info( stdout , "sedflux-make-sequence" , 0 , 9 , 0 ), exit(0);
00046 
00047    if ( debug )
00048       g_setenv( "SEDFLUX_MAKE_SEQUENCE_DEBUG" , "TRUE" , TRUE );
00049 
00050    eh_set_verbosity_level( verbosity );
00051 
00052    if ( out_file )
00053    {
00054       if ( append )
00055          fp_out = eh_fopen_error( out_file , "a" , &error );
00056       else
00057          fp_out = eh_fopen_error( out_file , "w" , &error );
00058    }
00059 
00060    if ( !fp_out )
00061       eh_error( "Error opening file: %s" , error->message );
00062 
00063    if      ( big_endian && little_endian )
00064       eh_error( "Byte order must be big endian or little endian" );
00065    else if ( !big_endian && !little_endian )
00066       byte_order = G_BYTE_ORDER;
00067    else if ( big_endian )
00068       byte_order = G_BIG_ENDIAN;
00069    else if ( little_endian )
00070       byte_order = G_LITTLE_ENDIAN;
00071 
00072    eh_message( "x-dimension : %d" , n_x       );
00073    eh_message( "y-dimension : %d" , n_y       );
00074    eh_message( "Grid value  : %f" , val       );
00075    eh_message( "Time value  : %f" , time_key  );
00076    eh_message( "Byte order  : %s" , byte_order==G_BIG_ENDIAN?"Big-endian":"Little-endian" );
00077    eh_message( "Format      : %s" , "<32-bit-integer=NY> <32-bit-integer=NX> <<64-bit-double> <<64-bit-double*NX*NY>... EOF>>" );
00078 
00079    {
00080       Eh_dbl_grid g = eh_grid_new( double , n_x , n_y );
00081 
00082       eh_dbl_grid_set( g , val );
00083 
00084       if ( byte_order == G_BYTE_ORDER )
00085       {
00086          if ( !append )
00087          {
00088             fwrite( &n_y                  , sizeof(gint32) , 1       , fp_out );
00089             fwrite( &n_x                  , sizeof(gint32) , 1       , fp_out );
00090          }
00091          fwrite( &time_key             , sizeof(double) , 1       , fp_out );
00092          fwrite( eh_grid_data_start(g) , sizeof(double) , n_x*n_y , fp_out );
00093       }
00094       else
00095       {
00096          if ( !append )
00097          {
00098             eh_fwrite_int32_swap( &n_y                  , sizeof(gint32) , 1       , fp_out );
00099             eh_fwrite_int32_swap( &n_x                  , sizeof(gint32) , 1       , fp_out );
00100          }
00101          eh_fwrite_dbl_swap  ( &time_key             , sizeof(double) , 1       , fp_out );
00102          eh_fwrite_dbl_swap  ( eh_grid_data_start(g) , sizeof(double) , n_x*n_y , fp_out );
00103       }
00104 
00105       eh_grid_destroy( g , TRUE );
00106    }
00107 
00108    fclose( fp_out );
00109 }
00110 

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