Example #1
0
struct storage__file* storage__creat(
            const char* dirname, const char* basename, const char* depname, 
            int block_size, int block_group_size, int best_compression) {
    struct storage__file* c;
    assert(block_size < 32768 && block_size > 0);
    assert(block_group_size > 0 && block_group_size < 32768);
    c = (struct storage__file*)malloc(sizeof(struct storage__file));
    assert(c!=NULL);
    {
        char namebuf[4096];
        snprintf(namebuf, 4096, "%s/%s.dat", dirname, basename);
        c->data_file = fopen(namebuf, "wb+");
        assert(c->data_file != NULL);
        
        snprintf(namebuf, 4096, "%s/%s.idx", dirname, basename);
        c->index_file = fopen(namebuf, "wb+");
        assert(c->index_file != NULL);
        
        snprintf(namebuf, 4096, "%s/%s.dsc", dirname, basename);
        c->description_file = fopen(namebuf, "wb+");
        assert(c->description_file != NULL);
        
        snprintf(namebuf, 4096, "%s/%s.hsh", dirname, basename);
        c->hash_file = fopen(namebuf, "wb+");
        assert(c->hash_file != NULL);
    }
    c->block_size = block_size;
    c->block_group_size = block_group_size;
    c->current_block = 0;
    
    c->current_index_entry = (struct index_entry*)malloc(get_index_entry_size(c));
    memset(c->current_index_entry, 0, get_index_entry_size(c));
    
    write_descriptor_file(c);
    
    c->outbuf = (unsigned char*)malloc(CHUNK);
        
    open_deps(c, dirname, depname);
    
    if(depname) {
        fprintf(c->description_file, "%s", depname);
        fflush(c->description_file);
    }
    
    c->writestat_compressed = 0;
    c->writestat_uncompressible = 0;
    c->writestat_dblrefs = 0;
    c->writestat_reused = 0;
    c->writestat_hashcoll = 0;
    c->writestat_zero = 0;
    
    c->opened_for_writing = 1;
    c->best_compression=best_compression;

    return c;
}
Example #2
0
int write_final_descriptor_file(int u_f, int u_s)
{
  int compute_energy;
  int compute_forces;
  int compute_virial;
  int status;

  /* set_compute flag */
  if (!g_kim.kim_model_has_energy) {
    compute_energy = 0;
    error(1,"KIM Model does not provide `energy'.\n");
  } else {
    compute_energy = 1;
  }

  if (u_f) {
    if (g_kim.kim_model_has_forces) {
      compute_forces = 1;
    } else {
      compute_forces = 0;
      error(1,"KIM Model does not provide `forces'.\n");
    }
  }else {
    compute_forces = 0;
  }

  if (u_s) {
    if (g_kim.kim_model_has_virial) {
      compute_virial = 1;
    } else {
      compute_virial = 0;
      error(1,"KIM Model does not provide `virial'.\n");
    }
  }else {
    compute_virial = 0;
  }

  /* write the `descritor.kim' file for this test */
  status = write_descriptor_file(g_param.ntypes, (const char**) g_config.elements,
                              compute_energy, compute_forces, compute_virial);
  if (KIM_STATUS_OK > status) {
    KIM_API_report_error(__LINE__, __FILE__, "write_descriptor_file", status);
    return(status);
  }

  return KIM_STATUS_OK;
}
Example #3
0
int write_temporary_descriptor_file(char* modelname)
{
	/* local variables */
	void* pkim;
	const char* species[1];
	int status;
	int Nspecies = 1;

  /* create a temporary object*/
  status = KIM_API_model_info(&pkim, modelname);
  if (KIM_STATUS_OK > status) {
    KIM_API_report_error(__LINE__, __FILE__, "KIM_API_model_info", status);
    return(status);
  }

  /* get the first species supported by the model */
  status = KIM_API_get_model_species(pkim, 0, species);
  if (KIM_STATUS_OK > status) {
    KIM_API_report_error(__LINE__, __FILE__, "KIM_API_get_model_species", status);
    return(status);
  }

  /* write a temporary `descriptor.kim' file, used only to query model info */
  /* we'll write `descriptor.kim' file with the species reading from potfit later. */
  status = write_descriptor_file(Nspecies, species, 0, 0, 0);
  if (KIM_STATUS_OK > status) {
    KIM_API_report_error(__LINE__, __FILE__, "write_descriptor_file", status);
    return(status);
  }

  /* free the temporary object */
  KIM_API_free(&pkim, &status);
  if (KIM_STATUS_OK > status) {
    KIM_API_report_error(__LINE__, __FILE__, "KIM_API_free", status);
    return(status);
  }

	return KIM_STATUS_OK;
}