"Fossies" - the Fresh Open Source Software Archive

Member "gfsview-snapshot-121130/batch/module.c" (30 Nov 2012, 5250 Bytes) of package /linux/privat/gfsview-snapshot-121130.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "module.c" see the Fossies "Dox" file reference documentation.

    1 /* Gerris - The GNU Flow Solver                       (-*-C-*-)
    2  * Copyright (C) 2010 National Institute of Water and Atmospheric Research
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License as
    6  * published by the Free Software Foundation; either version 2 of the
    7  * License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   12  * General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   17  * 02111-1307, USA.  
   18  */
   19 
   20 #include <errno.h>
   21 #include <string.h>
   22 #include <gerris/output.h>
   23 
   24 #include "render.h"
   25 
   26 /* GfsOutputView: Header */
   27 
   28 typedef struct _GfsOutputView         GfsOutputView;
   29 
   30 struct _GfsOutputView {
   31   /*< private >*/
   32   GfsOutput parent;
   33 
   34   /*< public >*/
   35   GfsGlViewParams view;
   36   GfsGl2PSParams p;
   37   GList * list;
   38   gchar * fname;
   39 };
   40 
   41 #define GFS_OUTPUT_VIEW(obj)            GTS_OBJECT_CAST (obj,\
   42                              GfsOutputView,\
   43                              gfs_output_view_class ())
   44 #define GFS_IS_OUTPUT_VIEW(obj)         (gts_object_is_from_class (obj,\
   45                          gfs_output_view_class ()))
   46 
   47 GfsEventClass * gfs_output_view_class  (void);
   48 
   49 /* GfsOutputView: Object */
   50 
   51 static void gfs_output_view_read (GtsObject ** o, GtsFile * fp)
   52 {
   53   (* GTS_OBJECT_CLASS (gfs_output_view_class ())->parent_class->read) (o, fp);
   54   if (fp->type == GTS_ERROR)
   55     return;
   56 
   57   if (fp->type == '{') {
   58     gfs_gl2ps_params_read (&GFS_OUTPUT_VIEW (*o)->p, fp);
   59     if (fp->type == GTS_ERROR)
   60       return;
   61   }
   62 
   63   if (fp->type != GTS_STRING) {
   64     gts_file_error (fp, "expecting a string (GfsView parameter file)");
   65     return;
   66   }
   67   FILE * f = fopen (fp->token->str, "r");
   68   if (f == NULL) {
   69     gts_file_error (fp, "could not open file '%s'\n%s", fp->token->str, strerror (errno));
   70     return;
   71   }
   72   GfsOutputView * output = GFS_OUTPUT_VIEW (*o);
   73   GtsFile * fp1 = gts_file_new (f);
   74   gfs_gl_view_params_read (&output->view, fp1);
   75   while (fp1->type == '\n')
   76     gts_file_next_token (fp1);
   77   while (fp1->type == GTS_STRING) {
   78     GfsGl * gl;
   79     if ((gl = gfs_gl_new_from_file (fp1))) {
   80       gl->p = &output->view;
   81       output->list = g_list_append (output->list, gl);
   82     }
   83     else if (fp1->type != GTS_ERROR) {
   84       gts_file_error (fp1, "unknown keyword `%s'", fp1->token->str);
   85       break;
   86     }
   87     while (fp1->type == '\n')
   88       gts_file_next_token (fp1);
   89   }
   90   if (fp1->type == GTS_ERROR) {
   91     gts_file_error (fp, "not a valid GfsView file\n%s:%d:%d: %s", 
   92             fp->token->str, fp1->line, fp1->pos, fp1->error);
   93     gts_file_destroy (fp1);
   94     fclose (f);
   95   }
   96   else {
   97     gts_file_destroy (fp1);
   98     fclose (f);
   99     g_free (output->fname);
  100     output->fname = g_strdup (fp->token->str);
  101     gts_file_next_token (fp);
  102   }
  103 }
  104 
  105 static void gfs_output_view_write (GtsObject * o, FILE * fp)
  106 {
  107   (* GTS_OBJECT_CLASS (gfs_output_view_class ())->parent_class->write) (o, fp);
  108 
  109   gfs_gl2ps_params_write (&GFS_OUTPUT_VIEW (o)->p, fp);
  110   fprintf (fp, " %s", GFS_OUTPUT_VIEW (o)->fname);
  111 }
  112 
  113 static void gfs_output_view_destroy (GtsObject * object)
  114 {
  115   GfsOutputView * output = GFS_OUTPUT_VIEW (object);
  116   g_list_foreach (output->list, (GFunc) gts_object_destroy, NULL);
  117   g_list_free (output->list);
  118   g_free (output->fname);
  119 
  120   (* GTS_OBJECT_CLASS (gfs_output_view_class ())->parent_class->destroy) (object);
  121 }
  122 
  123 static gboolean gfs_output_view_event (GfsEvent * event, GfsSimulation * sim)
  124 {
  125   if ((* GFS_EVENT_CLASS (gfs_output_class())->event) (event, sim)) {
  126     GfsOutputView * output = GFS_OUTPUT_VIEW (event);
  127     g_list_foreach (output->list, (GFunc) gfs_gl_set_simulation, sim);
  128     gfs_gl_osmesa_render (&output->p, sim, &output->view, output->list, 
  129               GFS_OUTPUT (event)->file->fp, 
  130               !GFS_OUTPUT (event)->parallel);
  131     return TRUE;
  132   }
  133   return FALSE;
  134 }
  135 
  136 static void gfs_output_view_class_init (GtsObjectClass * klass)
  137 {
  138   klass->read = gfs_output_view_read;
  139   klass->write = gfs_output_view_write;
  140   klass->destroy = gfs_output_view_destroy;
  141   GFS_EVENT_CLASS (klass)->event = gfs_output_view_event;
  142 }
  143 
  144 static void gfs_output_view_init (GfsOutputView * object)
  145 {
  146   gfs_gl2ps_params_init (&object->p);
  147   gfs_gl_view_params_init (&object->view);
  148 }
  149 
  150 GfsEventClass * gfs_output_view_class (void)
  151 {
  152   static GfsEventClass * klass = NULL;
  153 
  154   if (klass == NULL) {
  155     GtsObjectClassInfo gfs_output_view_info = {
  156       "GfsOutputView",
  157       sizeof (GfsOutputView),
  158       sizeof (GfsEventClass),
  159       (GtsObjectClassInitFunc) gfs_output_view_class_init,
  160       (GtsObjectInitFunc) gfs_output_view_init,
  161       (GtsArgSetFunc) NULL,
  162       (GtsArgGetFunc) NULL
  163     };
  164     klass = gts_object_class_new (GTS_OBJECT_CLASS (gfs_output_class ()),
  165                   &gfs_output_view_info);
  166   }
  167 
  168   return klass;
  169 }
  170 
  171 /* Initialize module */
  172 const gchar   gfs_module_name[] = "gfsview";
  173 const gchar * g_module_check_init (void);
  174 
  175 const gchar * g_module_check_init (void)
  176 {
  177   gfs_gl_init ();
  178   gfs_output_view_class ();
  179   return NULL;
  180 }