Пример #1
0
plot_type * plot_alloc(const char * __driver_type , void * init_arg , bool logx , bool logy)
{
  plot_type * plot = util_malloc(sizeof *plot );
  {
    /*
      Loading the driver:
    */
    char * driver_type = util_alloc_string_copy( __driver_type );
    util_strupr( driver_type );

    if (util_string_equal( driver_type , "PLPLOT"))
      plot->driver  = plplot_driver_alloc(init_arg);
    else if (util_string_equal( driver_type , "TEXT"))
      plot->driver  = text_driver_alloc(init_arg);
    else
      util_abort("%s: plot driver:%s not implemented ... \n",__func__ , __driver_type);
    
    plot_driver_assert( plot->driver );

    free( driver_type );
  }

  /* Initializing plot data which is common to all drivers. */
  plot->is_histogram    = false;
  plot->dataset         = vector_alloc_new();
  plot->dataset_hash    = hash_alloc();
  plot->range           = plot_range_alloc();
  plot->timefmt         = NULL;
  plot->xlabel          = NULL;
  plot->ylabel          = NULL;
  plot->title           = NULL;
  
  /* 
     These functions only manipulate the internal plot_state
     variables, and do not call the driver functions.
  */
  plot_set_window_size(plot , PLOT_DEFAULT_WIDTH , PLOT_DEFAULT_HEIGHT);
  plot_set_box_color(plot , PLOT_DEFAULT_BOX_COLOR);
  plot_set_label_color(plot , PLOT_DEFAULT_LABEL_COLOR);
  plot_set_label_fontsize(plot , 1.0);
  plot_set_axis_fontsize(plot , 1.0);
  plot_set_labels(plot , "" , "" , ""); /* Initializeing with empty labels. */
  plot_set_log( plot , logx , logy); /* Default - no log on the axis. */
  return plot;
}
Пример #2
0
static int ecl_util_get_month_nr__(const char * _month_name) {
  int month_nr = -1;
  char * month_name = util_alloc_string_copy(_month_name);
  util_strupr(month_name);
  
  if (strncmp(month_name , "JAN" , 3)      == 0) 
    month_nr = 1;
  else if (strncmp(month_name , "FEB" , 3) == 0) 
    month_nr = 2;
  else if (strncmp(month_name , "MAR" , 3) == 0) 
    month_nr = 3;
  else if (strncmp(month_name , "APR" , 3) == 0) 
    month_nr = 4;
  else if (strncmp(month_name , "MAI" , 3) == 0) 
    month_nr = 5;
  else if (strncmp(month_name , "MAY" , 3) == 0) 
    month_nr = 5;
  else if (strncmp(month_name , "JUN" , 3) == 0) 
    month_nr = 6;
  else if (strncmp(month_name , "JUL" , 3) == 0) 
    month_nr = 7;
  else if (strncmp(month_name , "JLY" , 3) == 0)   /* ECLIPSE ambigus on July. */
    month_nr = 7;
  else if (strncmp(month_name , "AUG" , 3) == 0) 
    month_nr = 8;
  else if (strncmp(month_name , "SEP" , 3) == 0) 
    month_nr = 9;
  else if (strncmp(month_name , "OCT" , 3) == 0) 
    month_nr = 10;
  else if (strncmp(month_name , "OKT" , 3) == 0) 
    month_nr = 10;
  else if (strncmp(month_name , "NOV" , 3) == 0) 
    month_nr = 11;
  else if (strncmp(month_name , "DEC" , 3) == 0) 
    month_nr = 12;
  else if (strncmp(month_name , "DES" , 3) == 0) 
    month_nr = 12;
  free(month_name);
  return month_nr;
}
Пример #3
0
field_file_format_type field_config_default_export_format(const char * filename) {
    field_file_format_type export_format = FILE_FORMAT_NULL;
    if (filename != NULL) {
        export_format = ECL_KW_FILE_ALL_CELLS;   /* Suitable for PERMX/PORO/... ; when this export format is
                                                used IMPORT must be used in the datafile instead of
                                                INCLUDE. This gives faster ECLIPSE startup time, but is
                                                (unfortunately) quite unstandard. */

        char * extension;
        util_alloc_file_components(filename , NULL,NULL,&extension);
        if (extension != NULL) {
            util_strupr(extension);
            if (strcmp(extension , "GRDECL") == 0)
                export_format = ECL_GRDECL_FILE;
            else if (strcmp(extension , "ROFF") == 0)
                export_format = RMS_ROFF_FILE;

            free(extension);
        }

    }
    return export_format;
}
Пример #4
0
bool parser_fseek_string(const parser_type * parser , FILE * stream , const char * __string , bool skip_string, bool case_sensitive) {
  bool string_found        = false;
  char * string            = util_alloc_string_copy( __string );
  if (!case_sensitive)
    util_strupr( string );
  {
    long int initial_pos     = ftell( stream );   /* Store the inital position. */
    bool cont                = true;
    
    if (strstr( string , parser->comment_start ) != NULL)
      util_abort("%s: sorry the string contains a comment start - will never find it ... \n"); /* A bit harsh ?? */
    
    do {
      int c = fgetc( stream );
      if (!case_sensitive) c = toupper( c );
      
      /* Special treatment of quoters - does not properly handle escaping of the quoters. */
      if (is_in_quoters( c , parser )) {
        long int quote_start_pos = ftell(stream);
        if (!fseek_quote_end( c , stream )) {
          fseek( stream ,  quote_start_pos , SEEK_SET);
          fprintf(stderr,"Warning: unterminated quotation starting at line: %d \n",util_get_current_linenr( stream ));
          fseek(stream , 0 , SEEK_END);
        }
        /* 
           Now we are either at the first character following a
           terminated quotation, or at EOF. 
        */
        continue;
      }
      
      /* Special treatment of comments: */
      if (c == parser->comment_start[0]) {
        /* OK - this might be the start of a comment - let us check further. */
        bool comment_start = fgetc_while_equal( stream , &parser->comment_start[1] , false);
        if (comment_start) {
          long int comment_start_pos = ftell(stream) - strlen( parser->comment_start );
          /* Start seeking for comment_end */
          if (!util_fseek_string(stream , parser->comment_end , true , true)) { 
            /* 
               No end comment end was found - what to do about that??
               The file is just positioned at the end - and the routine
               will exit at the next step - with a Warning. 
            */
            fseek( stream , comment_start_pos , SEEK_SET);
            fprintf(stderr,"Warning: unterminated comment starting at line: %d \n",util_get_current_linenr( stream ));
            fseek(stream , 0 , SEEK_END);
          } continue;
          /* Now we are at the character following a comment end - or at EOF. */
        } 
      }
      
      /*****************************************************************/
      
      /* Now c is a regular character - and we can start looking for our string. */
      if (c == string[0]) {  /* OK - we got the first character right - lets try in more detail: */
        bool equal = fgetc_while_equal( stream , &string[1] , case_sensitive);
        if (equal) {
          string_found = true;
          cont = false;
        } 
      }
      
      if (c == EOF) 
        cont = false;
      
    } while (cont);
    
    if (string_found) {
      if (!skip_string)
        fseek(stream , -strlen(string) , SEEK_CUR); /* Reposition to the beginning of 'string' */
    } else
      fseek(stream , initial_pos , SEEK_SET);       /* Could not find the string reposition at initial position. */
  }
  free( string );
  return string_found;
}