Пример #1
0
void misfit_ensemble_initialize( misfit_ensemble_type * misfit_ensemble ,
                                 const ensemble_config_type * ensemble_config ,
                                 const enkf_obs_type * enkf_obs ,
                                 enkf_fs_type * fs ,
                                 int ens_size ,
                                 int history_length,
                                 bool force_init) {

    if (force_init || !misfit_ensemble->initialized) {
        misfit_ensemble_clear( misfit_ensemble );

        msg_type * msg                 = msg_alloc("Evaluating misfit for observation: " , false);
        double ** chi2_work            = __2d_malloc( history_length + 1 , ens_size );
        bool_vector_type * iens_valid  = bool_vector_alloc( ens_size , true );

        hash_iter_type * obs_iter = enkf_obs_alloc_iter( enkf_obs );
        const char * obs_key      = hash_iter_get_next_key( obs_iter );

        misfit_ensemble->history_length = history_length;
        misfit_ensemble_set_ens_size( misfit_ensemble , ens_size );

        msg_show( msg );
        while (obs_key != NULL) {
            obs_vector_type * obs_vector = enkf_obs_get_vector( enkf_obs , obs_key );
            msg_update( msg , obs_key );

            bool_vector_reset( iens_valid );
            bool_vector_iset( iens_valid , ens_size - 1 , true );
            obs_vector_ensemble_chi2( obs_vector ,
                                      fs ,
                                      iens_valid ,
                                      0 ,
                                      misfit_ensemble->history_length,
                                      0 ,
                                      ens_size ,
                                      chi2_work);

            /**
                Internalizing the results from the chi2_work table into the misfit structure.
            */
            for (int iens = 0; iens < ens_size; iens++) {
                misfit_member_type * node = misfit_ensemble_iget_member( misfit_ensemble , iens );
                if (bool_vector_iget( iens_valid , iens))
                    misfit_member_update( node , obs_key , misfit_ensemble->history_length , iens , (const double **) chi2_work);
            }
            obs_key = hash_iter_get_next_key( obs_iter );
        }

        bool_vector_free( iens_valid );
        msg_free(msg , true );
        hash_iter_free( obs_iter );

        __2d_free( chi2_work , misfit_ensemble->history_length + 1);
        misfit_ensemble->initialized = true;
    }
}
Пример #2
0
bool tar_and_remove_dir( const char * root_path , const char * current_dir , int current_depth , void * arg) {
  if (strncmp(current_dir , "mem" , 3) == 0) {
    msg_type * msg = msg_safe_cast( arg );
    {
      char * tar_file    = util_alloc_filename(NULL , current_dir , "tar.gz");
      char * target_file = util_alloc_filename(root_path , current_dir , "tar.gz");
      char * text        = util_alloc_sprintf("%s: Creating %s" , root_path , tar_file );
      msg_update( msg , text );
      util_fork_exec("tar" , 3 , (const char *[3]) {"-czf" , tar_file , current_dir} , true , target_file , root_path , NULL , NULL , NULL);
      free( text );
      free( tar_file );
      free( target_file );
    }
Пример #3
0
static void migrate_file( const char * src_case, int num_src_drivers , const char * target_case, int num_target_drivers, const char * file, int block_size , msg_type * msg) {
  block_fs_type ** target_fs = util_calloc( num_target_drivers , sizeof * target_fs  ); 
  int itarget;
  for (itarget = 0; itarget < num_target_drivers; itarget++) {
    char * path       = util_alloc_sprintf("%s/mod_%d" , target_case , itarget );
    char * mount_file = util_alloc_sprintf("%s/mod_%d/%s.mnt" , target_case , itarget , file );
    util_make_path( path );
    
    target_fs[itarget] =  block_fs_mount( mount_file , 16 , 0 , 1.0, 0 , false , false );
    free( mount_file );
    free( path );
  } 

  {
    int isrc;
    buffer_type * buffer = buffer_alloc(1024);
    for (isrc = 0; isrc < num_src_drivers; isrc++) {
      char * mount_file = util_alloc_sprintf("%s/mod_%d/%s.mnt" , src_case , isrc , file );
      block_fs_type   * src_fs    = block_fs_mount( mount_file , 16 , 1024 , 1.0 , 0 , true , true );
      vector_type     * file_list = block_fs_alloc_filelist( src_fs , NULL , NO_SORT , false );
      int ifile;
      msg_update( msg , mount_file );
      for (ifile = 0; ifile < vector_get_size( file_list ); ifile++) {
        const file_node_type * node = vector_iget_const( file_list , ifile );
        const char * filename       = file_node_get_filename( node );
        int   report_step , iens;
        char * key;
        if (block_fs_sscanf_key( filename , &key , &report_step , &iens )) {
          block_fs_fread_realloc_buffer( src_fs , filename , buffer);
          block_fs_fwrite_buffer( target_fs[(iens % num_target_drivers)] , filename , buffer );
          free( key );
        } else
          util_abort("%s: All hell is loose - failed to parse:%s \n",__func__ , filename);
      }

      vector_free( file_list );
      block_fs_close(src_fs , false);
    }
    buffer_free( buffer );
  }

  
  for (itarget = 0; itarget < num_target_drivers; itarget++) 
    block_fs_close( target_fs[itarget] , false);
  free( target_fs );
}
Пример #4
0
int main(int argc , char ** argv) {
  install_SIGNALS();
  if (argc < 4)
    usage();
  {
    const char * src_mount      = argv[1];
    const char * target_mount   = argv[2];
    if (block_fs_is_mount(src_mount)) {
      const char * pattern  = NULL;
      int iarg;
      
      for (iarg = 3; iarg < argc; iarg++) {
        if (argv[iarg][0] == '-') {
          /** OK - this is an option .. */
        }
        else pattern = argv[iarg];
      }
      
      {
        block_fs_type * src_fs    = block_fs_mount(src_mount , 1 , 0 , 1 , 0 , false , true );
        block_fs_type * target_fs = block_fs_mount(target_mount , 1 , 0 , 1 , 0 , false , false );
        vector_type   * files     = block_fs_alloc_filelist( src_fs , pattern , NO_SORT , false );
        buffer_type   * buffer    = buffer_alloc( 1024 );
        {
          int i;
          msg_type   * msg      = msg_alloc("Copying :" , false);
          msg_show( msg );
          for (i=0; i < vector_get_size( files ); i++) {
            const user_file_node_type * node = vector_iget_const( files , i );
            const char * filename       = user_file_node_get_filename( node );
            msg_update( msg , filename ); 
            block_fs_fread_realloc_buffer( src_fs , filename , buffer );
            block_fs_fwrite_buffer( target_fs , filename , buffer );
          }
          msg_free( msg , true );
        }
        buffer_free( buffer );
        vector_free( files );
        block_fs_close( target_fs , true);
        block_fs_close( src_fs    , false );
      }
    } else 
      fprintf(stderr,"The files:%s/%s does not seem to be a block_fs mount files.\n" , src_mount , target_mount);
  }
}
Пример #5
0
/***************************************************************************
  Adds news message to mesg_table
***************************************************************************/
void messagewdg::msg(const struct message *pmsg)
{
  int i;
  QFont f;
  QTableWidgetItem *item;

  item = new QTableWidgetItem;
  item->setText(pmsg->descr);
  i = mesg_table->rowCount();
  mesg_table->insertRow(i);
  if (pmsg->visited) {
    f = item->font();
    f.setItalic(true);
    item->setFont(f);
  }
  mesg_table->setItem(i, 0, item);
  msg_update();
  mesg_table->scrollToBottom();
}
Пример #6
0
/**
  * Loads plasma, filters it and sends to the output system.
  */
static void
process_record (int apply_filter)
{
    int cpu = 0;
    while (1) {
        msg_update ("rec: %2d, cpu: %2d", record, cpu);

        // Probes file for reading.
        FILE *fp = fopen (IO_plasmaName (record, cpu++), "rb");
        if (!fp)
            break;

        // Loads data into temprorary allocated buffer.
        fread (&plasmaN, sizeof (long int), 1, fp);
        if (plasmaN) {
            plasma = (marker_t *) realloc (plasma, plasmaN*sizeof (marker_t));
            MF_ENSURE (plasma, "cannot allocate %d markers.", plasmaN);
            fread (plasma, sizeof (marker_t), plasmaN, fp);
        }
        fclose (fp);

        // Converts units to microns.
        double factor = 1.0/units (mc_micron);
        for (int i = 0 ; i < plasmaN ; ++i) {
            plasma[i].x *= factor;
            plasma[i].y *= factor;
            plasma[i].z *= factor;
        }

        if (apply_filter)
            plasmaN = distiller_filter (plasma, plasmaN);

        for (int i = 0 ; i < plasmaN ; ++i)
            save_marker (plasma + i);
    }
}
Пример #7
0
static void enkf_tui_fs_copy_ensemble__(
  enkf_main_type * enkf_main,
  const char     * source_case,
  const char     * target_case,
  int              report_step_from,
  state_enum       state_from,
  int              report_step_to,
  state_enum       state_to,
  bool             only_parameters)
{
  msg_type       * msg          = msg_alloc("Copying: " , false);
  ensemble_config_type * config = enkf_main_get_ensemble_config(enkf_main);
  int ens_size                  = enkf_main_get_ensemble_size(enkf_main);
  char * ranking_key;
  const int  * ranking_permutation = NULL;
  int  * identity_permutation;
  ranking_table_type * ranking_table = enkf_main_get_ranking_table( enkf_main );
  

  if (ranking_table_get_size( ranking_table ) > 0) {
    util_printf_prompt("Name of ranking to resort by (or blank)" , 50  , '=' , "=> ");
    ranking_key = util_alloc_stdin_line();
    if (ranking_table_has_ranking( ranking_table , ranking_key )) 
      ranking_permutation = ranking_table_get_permutation( ranking_table , ranking_key );
    else {
      fprintf(stderr," Sorry: ranking:%s does not exist \n", ranking_key );
      return;
    }
  }
  identity_permutation = util_calloc( ens_size , sizeof * identity_permutation );
  {
    int iens;
    for (iens =0; iens < ens_size; iens++) 
      identity_permutation[iens] = iens;
  }

  if (ranking_permutation == NULL)
    ranking_permutation = identity_permutation;
  

  {
    /* If the current target_case does not exist it is automatically created by the select_write_dir function */
    enkf_fs_type * src_fs    = enkf_main_mount_alt_fs( enkf_main , source_case , false );
    enkf_fs_type * target_fs = enkf_main_mount_alt_fs( enkf_main , target_case , true );
    
    stringlist_type * nodes = ensemble_config_alloc_keylist_from_var_type(config, PARAMETER);
    
    {
      int num_nodes = stringlist_get_size(nodes);
      msg_show(msg);
      for(int i = 0; i < num_nodes; i++) {
        const char * key = stringlist_iget(nodes, i);
        enkf_config_node_type * config_node = ensemble_config_get_node(config , key);
        msg_update(msg , key);
        enkf_node_copy_ensemble(config_node, src_fs , target_fs , report_step_from, state_from, report_step_to , state_to , ens_size , ranking_permutation);
      }
    }
    
    enkf_fs_decref( src_fs );
    enkf_fs_decref( target_fs );
    
    msg_free(msg , true);
    stringlist_free(nodes);
  }
  free( identity_permutation );
}
Пример #8
0
int main(int argc, char ** argv) {
  int num_files = argc - 1;
  if (num_files >= 1) {
    /* File type and formatted / unformatted is determined from the first argument on the command line. */
    char * ecl_base;
    char * path;
    ecl_file_enum file_type , target_type;
    bool fmt_file;

    /** Look at the first command line argument to determine type and formatted/unformatted status. */
    file_type = ecl_util_get_file_type( argv[1] , &fmt_file , NULL);
    if (file_type == ECL_SUMMARY_FILE)
      target_type = ECL_UNIFIED_SUMMARY_FILE;
    else if (file_type == ECL_RESTART_FILE)
      target_type = ECL_UNIFIED_RESTART_FILE;
    else {
      util_exit("The ecl_pack program can only be used with ECLIPSE restart files or summary files.\n");
      target_type = -1;
    }
    util_alloc_file_components( argv[1] , &path , &ecl_base , NULL);

    
    /**
       Will pack to cwd, even though the source files might be
       somewhere else. To unpack to the same directory as the source
       files, just send in @path as first argument when creating the
       target_file.
    */

    {
      msg_type * msg;
      int i , report_step , prev_report_step;
      char *  target_file_name   = ecl_util_alloc_filename( NULL , ecl_base , target_type , fmt_file , -1);
      stringlist_type * filelist = stringlist_alloc_argv_copy( (const char **) &argv[1] , num_files );
      ecl_kw_type * seqnum_kw    = NULL;
      fortio_type * target       = fortio_open_writer( target_file_name , fmt_file , ECL_ENDIAN_FLIP);

      if (target_type == ECL_UNIFIED_RESTART_FILE) {
        int dummy;
        seqnum_kw = ecl_kw_alloc_new("SEQNUM" , 1 , ECL_INT_TYPE , &dummy);
      } 
      
      {
        char * msg_format = util_alloc_sprintf("Packing %s <= " , target_file_name);
        msg = msg_alloc( msg_format , false);
        free( msg_format );
      }
      

      msg_show( msg );
      stringlist_sort( filelist , ecl_util_fname_report_cmp);
      prev_report_step = -1;
      for (i=0; i < num_files; i++) {
        ecl_file_enum this_file_type;
        this_file_type = ecl_util_get_file_type( stringlist_iget(filelist , i)  , NULL , &report_step);
        if (this_file_type == file_type) {
          if (report_step == prev_report_step)
            util_exit("Tried to write same report step twice: %s / %s \n",
                      stringlist_iget(filelist , i-1) , 
                      stringlist_iget(filelist , i));

          prev_report_step = report_step;
          msg_update(msg , stringlist_iget( filelist , i));
          {
            ecl_file_type * src_file = ecl_file_open( stringlist_iget( filelist , i) , 0 );
            if (target_type == ECL_UNIFIED_RESTART_FILE) {
              /* Must insert the SEQNUM keyword first. */
              ecl_kw_iset_int(seqnum_kw , 0 , report_step);
              ecl_kw_fwrite( seqnum_kw , target );
            }
            ecl_file_fwrite_fortio( src_file , target , 0);
            ecl_file_close( src_file );
          }
        }  /* Else skipping file of incorrect type. */
      }
      msg_free(msg , false);
      fortio_fclose( target );
      free(target_file_name);
      stringlist_free( filelist );
      if (seqnum_kw != NULL) ecl_kw_free(seqnum_kw);
    }
    free(ecl_base);
    util_safe_free(path);
  }
}
Пример #9
0
double obs_vector_total_chi2(const obs_vector_type * obs_vector , enkf_fs_type * fs , int iens, state_enum load_state) {
  int report_step;
  double sum_chi2 = 0;
  enkf_node_type * enkf_node = enkf_node_alloc( obs_vector->config_node );
  node_id_type node_id = {.report_step = 0, .iens = iens , .state = load_state };

  for (report_step = 0; report_step < vector_get_size( obs_vector->nodes ); report_step++) {
    if (vector_iget(obs_vector->nodes , report_step) != NULL) {
      node_id.report_step = report_step;

      if (enkf_node_try_load( enkf_node , fs , node_id)) 
        sum_chi2 += obs_vector_chi2__(obs_vector , report_step , enkf_node, node_id);

    }
  }
  enkf_node_free( enkf_node );
  return sum_chi2;
}


/** 
   This function will sum up all timesteps of the obs_vector, for all ensemble members.
*/

void obs_vector_ensemble_total_chi2(const obs_vector_type * obs_vector , enkf_fs_type * fs , int ens_size , state_enum load_state , double * sum_chi2) {
  const bool verbose = true;
  msg_type * msg;
  int report_step;
  int iens;
  char * msg_text = NULL;
  
  for (iens = 0; iens < ens_size; iens++)
    sum_chi2[iens] = 0;

  if (verbose) {
    msg = msg_alloc("Observation: " , false);
    msg_show(msg);
  }

  {
    node_id_type node_id = {.report_step = 0, .iens = iens , .state = load_state };
    enkf_node_type * enkf_node = enkf_node_alloc( obs_vector->config_node );
    for (report_step = 0; report_step < vector_get_size( obs_vector->nodes); report_step++) { 
      if (verbose) {
        msg_text = util_realloc_sprintf( msg_text , "%s[%03d]" , obs_vector->obs_key , report_step);
        msg_update(msg , msg_text);
      }
      if (vector_iget(obs_vector->nodes , report_step) != NULL) {
        node_id.report_step = report_step;
        for (iens = 0; iens < ens_size; iens++) {
          node_id.iens = iens;

          if (enkf_node_try_load( enkf_node , fs , node_id)) 
            sum_chi2[iens] += obs_vector_chi2__(obs_vector , report_step , enkf_node, node_id);

        }
      }
    }
    enkf_node_free( enkf_node );
  }

  if (verbose) {
    msg_free(msg , true);
    util_safe_free( msg_text );
  }
}

const char * obs_vector_get_obs_key( const obs_vector_type * obs_vector) {
  return obs_vector->obs_key;
}


/*****************************************************************/


VOID_FREE(obs_vector)
Пример #10
0
void unpack_file(const char * filename) {
  ecl_file_enum target_type = ECL_OTHER_FILE;
  ecl_file_enum file_type;
  bool fmt_file;
  file_type = ecl_util_get_file_type(filename , &fmt_file , NULL);
  if (file_type == ECL_UNIFIED_SUMMARY_FILE)
    target_type = ECL_SUMMARY_FILE;
  else if (file_type == ECL_UNIFIED_RESTART_FILE)
    target_type = ECL_RESTART_FILE;
  else 
    util_exit("Can only unpack unified ECLIPSE summary and restart files\n");
  
  if (target_type == ECL_SUMMARY_FILE) {
    printf("** Warning: when unpacking unified summary files it as ambigous - starting with 0001  -> \n");
  }
  {
    ecl_file_type * src_file = ecl_file_open( filename , 0 );
    int    size;
    int    offset;
    int    report_step = 0;
    int    block_index = 0;
    char * path; 
    char * base;
    msg_type * msg;
    util_alloc_file_components( filename , &path , &base , NULL);
    {
      char * label  = util_alloc_sprintf("Unpacking %s => ", filename);
      msg = msg_alloc( label , false);
      free( label );
    }
    msg_show(msg);

    if (target_type == ECL_SUMMARY_FILE) 
      size = ecl_file_get_num_named_kw( src_file , "SEQHDR" );
    else
      size = ecl_file_get_num_named_kw( src_file , "SEQNUM" );
    
    
    while (true) {
      if (block_index == size)
        break;

      if (target_type == ECL_SUMMARY_FILE) {
        ecl_file_select_block( src_file , SEQHDR_KW , block_index );
        report_step += 1;
        offset = 0;
      } else {
        ecl_kw_type * seqnum_kw;
        ecl_file_select_block( src_file , SEQNUM_KW , block_index );
        seqnum_kw = ecl_file_iget_named_kw( src_file , SEQNUM_KW , 0);
        report_step = ecl_kw_iget_int( seqnum_kw , 0);
        offset = 1;
      }

      /**
         Will unpack to cwd, even though the source files might be
         somewhere else. To unpack to the same directory as the source
         files, just send in @path as first argument when creating the
         target_file.
      */
      
      {
        char * target_file = ecl_util_alloc_filename( NULL , base , target_type , fmt_file , report_step);
        fortio_type * fortio_target = fortio_open_writer( target_file , fmt_file , ECL_ENDIAN_FLIP );
        msg_update(msg , target_file);
        ecl_file_fwrite_fortio( src_file , fortio_target , offset);
        
        fortio_fclose(fortio_target);
        free(target_file);
      }
      block_index++;
    } 
    ecl_file_close( src_file );
    util_safe_free(path);
    free(base);
    msg_free(msg , true);
  }
}
Пример #11
0
/***************************************************************************
  Resize event for messagewdg
***************************************************************************/
void messagewdg::resizeEvent(QResizeEvent* event)
{
  msg_update();
}