Пример #1
0
int artio_fileset_add_particles( artio_fileset *handle,
		int num_particle_files, int allocation_strategy,
		int num_species, char ** species_labels,
		int * num_primary_variables,
		int * num_secondary_variables,
		char *** primary_variable_labels_per_species,
		char *** secondary_variable_labels_per_species) {

	int i, k;
	int ret;
	int64_t l, cur;
	int64_t first_file_sfc, last_file_sfc;

	int first_file, last_file;
	char filename[256];
	char species_label[64];
	int mode;
	int64_t *local_particles_per_species, *total_particles_per_species;
	artio_particle_file *phandle;

	if ( handle == NULL ) {
		return ARTIO_ERR_INVALID_HANDLE;
	}

	if ( handle->open_mode != ARTIO_FILESET_WRITE ) {
		return ARTIO_ERR_INVALID_FILESET_MODE;
	}

	if ( handle->open_type & ARTIO_OPEN_PARTICLES ||
			handle->particle != NULL ) {
		return ARTIO_ERR_DATA_EXISTS;
	}
	handle->open_type |= ARTIO_OPEN_PARTICLES;

	phandle = artio_particle_file_allocate();
	if ( phandle == NULL ) {
		return ARTIO_ERR_MEMORY_ALLOCATION;
	}

	phandle->num_species = num_species;
	phandle->num_particle_files = num_particle_files;
	phandle->allocation_strategy = allocation_strategy;

	phandle->num_primary_variables = (int *)malloc(sizeof(int) * num_species);
	phandle->num_secondary_variables = (int *)malloc(sizeof(int) * num_species);
	phandle->num_particles_per_species = (int *)malloc(phandle->num_species * sizeof(int));
	phandle->local_particles_per_species = (int64_t *)malloc( num_species * sizeof(int64_t));
	if ( phandle->num_primary_variables == NULL ||
			phandle->num_secondary_variables == NULL ||
			phandle->num_particles_per_species == NULL ||
			phandle->local_particles_per_species == NULL ) {
		artio_particle_file_destroy(phandle);
		return ARTIO_ERR_MEMORY_ALLOCATION;
	}

	for (i = 0; i < num_species; i++) {
		phandle->num_particles_per_species[i] = 0;
		phandle->local_particles_per_species[i] = 0;
		phandle->num_primary_variables[i] = num_primary_variables[i];
		phandle->num_secondary_variables[i] = num_secondary_variables[i];
	}

	artio_parameter_set_int(handle, "num_particle_files", num_particle_files);
	artio_parameter_set_int(handle, "num_particle_species", num_species);
	artio_parameter_set_string_array(handle, "particle_species_labels",
			num_species, species_labels);
	artio_parameter_set_int_array(handle, "num_primary_variables", num_species,
			num_primary_variables);
	artio_parameter_set_int_array(handle, "num_secondary_variables",
			num_species, num_secondary_variables);

	for(i=0;i<num_species;i++) {
		sprintf( species_label, "species_%02u_primary_variable_labels", i );
		artio_parameter_set_string_array( handle, species_label,
				num_primary_variables[i], primary_variable_labels_per_species[i] );

		sprintf( species_label, "species_%02u_secondary_variable_labels", i );
		artio_parameter_set_string_array( handle, species_label,
				num_secondary_variables[i], secondary_variable_labels_per_species[i] );
	}

	/* allocate space for sfc offset cache */
	phandle->sfc_size = (int64_t *)malloc(handle->num_local_root_cells*sizeof(int64_t));
	phandle->sfc_list = (int64_t *)malloc(handle->num_local_root_cells*sizeof(int64_t));
	if ( phandle->sfc_size == NULL ||
			phandle->sfc_list == NULL ) {
		artio_particle_file_destroy(phandle);
		return ARTIO_ERR_MEMORY_ALLOCATION;
	}
	phandle->sfc_count = 0;
	handle->particle = phandle;
	return ARTIO_SUCCESS;
}
int artio_parameter_set_int(artio_fileset *handle, const char * key, int32_t value) {
	int32_t tmp = value;
	return artio_parameter_set_int_array(handle, key, 1, &tmp);
}