struct sockaddr_in make_address(char *address, uint16_t port){ struct sockaddr_in addr; struct hostent *hostinfo; addr.sin_family = AF_INET; addr.sin_port = htons (port); hostinfo = gethostbyname(address); if(hostinfo == NULL)HERR("gethostbyname"); addr.sin_addr = *(struct in_addr*) hostinfo->h_addr; return addr; }
/* ------- begin -------------------------- writeAtmos_p.c --- */ void writeAtmos_p(void) { /* Write atmos arrays. This has now been modified and writes the interpolated arrays, from depth_refine. With that, now this is the only viable option to write the atmos data, as there is no option to save in memory and writeAtmos_all used to write from the input file, not the interpolated quantities IMPORTANT: at the moment this is a trimmed version, only writing z to save space and computational time. */ const char routineName[] = "writeAtmos_p"; hsize_t offset[] = {0, 0, 0, 0}; hsize_t count[] = {1, 1, 1, 1}; hsize_t dims[4]; hid_t file_dspace, mem_dspace; /* Memory dataspace */ dims[0] = atmos.Nspace; if (( mem_dspace = H5Screate_simple(1, dims, NULL) ) < 0) HERR(routineName); /* File dataspace */ offset[0] = mpi.ix; offset[1] = mpi.iy; offset[2] = mpi.zcut; count[2] = atmos.Nspace; if (( file_dspace = H5Dget_space(io.in_atmos_T) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_atmos_T, H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, atmos.T) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_atmos_vz, H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, geometry.vel) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_atmos_z, H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, geometry.height) ) < 0) HERR(routineName); /* release dataspace resources */ if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); return; }
/* ------- begin -------------------------- readMolPops_p.c -- */ void readMolPops(Molecule *molecule) { /* --- Read populations from file. Note: readPopulations only reads the true populations and not the LTE populations. -- -------------- */ const char routineName[] = "readMolPops"; char group_name[ARR_STRLEN], *atmosID; int nz, nlevel; H5T_class_t type_class; size_t attr_size; hsize_t offset[] = {0, 0, 0, 0}; hsize_t count[] = {1, 1, 1, 1}; hsize_t dims[4]; hid_t ncid, file_dspace, mem_dspace, pop_var; /* --- Open molecule group --- */ sprintf(group_name, "molecule_%s", molecule->ID); if (( ncid = H5Gopen(io.aux_ncid, group_name, H5P_DEFAULT) ) < 0) HERR(routineName); /* --- Consistency checks --- */ /* Check that atmosID is the same */ if (( H5LTget_attribute_info(io.aux_ncid, "/", "atmosID", NULL, &type_class, &attr_size) ) < 0) HERR(routineName); atmosID = (char *) malloc(attr_size + 1); if (( H5LTget_attribute_string(io.aux_ncid, "/", "atmosID", atmosID) ) < 0) HERR(routineName); if (!strstr(atmosID, atmos.ID)) { sprintf(messageStr, "Indata file was calculated for different atmosphere (%s) than current", atmosID); Error(WARNING, routineName, messageStr); } free(atmosID); /* Check that dimension sizes match */ if (( H5LTget_attribute_int(ncid, ".", "nlevel_vibr", &nlevel) ) < 0) HERR(routineName); if (nlevel != molecule->Nv) { sprintf(messageStr, "Number of levels mismatch: expected %d, found %d.", molecule->Nv, (int)nlevel); Error(ERROR_LEVEL_2, routineName, messageStr); } if (( H5LTget_attribute_int(io.aux_ncid, ".", "nz", &nz) ) < 0) HERR(routineName); if (nz < atmos.Nspace) { sprintf(messageStr, "Number of depth points mismatch: expected %ld, found %d.", atmos.Nspace, (int)nz); Error(ERROR_LEVEL_2, routineName, messageStr); } /* --- Read data --- */ if (( pop_var = H5Dopen2(ncid, POP_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = molecule->Nv; dims[1] = atmos.Nspace; if (( mem_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName); /* File dataspace */ offset[0] = 0; offset[1] = mpi.ix; offset[2] = mpi.iy; offset[3] = mpi.zcut; count[0] = molecule->Nv; count[3] = atmos.Nspace; if (( file_dspace = H5Dget_space(pop_var) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dread(pop_var, H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, molecule->nv[0]) ) < 0) HERR(routineName); if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); if (( H5Dclose(pop_var) ) < 0) HERR(routineName); return; }
/* ------- begin -------------------------- readPopulations_p.c -- */ void readPopulations(Atom *atom) { /* --- Read populations from file. Note: readPopulations only reads the true populations and not the LTE populations. Note2: This routine will not work yet in HFD5. Access to the aux file needs to be better regulated in OLD_POPULATIONS cases (ie, append and read/write acess). The code below assumes the file is already open, which may not be the case. -- -------------- */ const char routineName[] = "readPopulations_p"; char group_name[ARR_STRLEN], *atmosID; int nz, nlevel; H5T_class_t type_class; size_t attr_size; hsize_t offset[] = {0, 0, 0, 0}; hsize_t count[] = {1, 1, 1, 1}; hsize_t dims[4]; hid_t ncid, file_dspace, mem_dspace, pop_var; /* --- Open atom group --- */ sprintf(group_name,(atom->ID[1] == ' ') ? "atom_%.1s" : "atom_%.2s", atom->ID); if (( ncid = H5Gopen(io.aux_ncid, group_name, H5P_DEFAULT) ) < 0) HERR(routineName); /* --- Consistency checks --- */ /* Check that atmosID is the same */ if (( H5LTget_attribute_info(io.aux_ncid, "/", "atmosID", NULL, &type_class, &attr_size) ) < 0) HERR(routineName); atmosID = (char *) malloc(attr_size + 1); if (( H5LTget_attribute_string(io.aux_ncid, "/", "atmosID", atmosID) ) < 0) HERR(routineName); if (!strstr(atmosID, atmos.ID)) { sprintf(messageStr, "Indata file was calculated for different atmosphere (%s) than current", atmosID); Error(WARNING, routineName, messageStr); } free(atmosID); /* Check that dimension sizes match */ if (( H5LTget_attribute_int(ncid, ".", "nlevel", &nlevel) ) < 0) HERR(routineName); if (nlevel != atom->Nlevel) { sprintf(messageStr, "Number of levels mismatch: expected %d, found %d.", atom->Nlevel, (int)nlevel); Error(ERROR_LEVEL_2, routineName, messageStr); } if (( H5LTget_attribute_int(io.aux_ncid, ".", "nz", &nz) ) < 0) HERR(routineName); if (nz < atmos.Nspace) { sprintf(messageStr, "Number of depth points mismatch: expected %ld, found %d.", atmos.Nspace, (int)nz); Error(ERROR_LEVEL_2, routineName, messageStr); } /* --- Read data --- */ if (( pop_var = H5Dopen2(ncid, POP_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = atom->Nlevel; dims[1] = atmos.Nspace; if (( mem_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName); /* File dataspace */ offset[0] = 0; offset[1] = mpi.ix; offset[2] = mpi.iy; offset[3] = mpi.zcut; count[0] = atom->Nlevel; count[3] = atmos.Nspace; if (( file_dspace = H5Dget_space(pop_var) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dread(pop_var, H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, atom->n[0]) ) < 0) HERR(routineName); if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); if (( H5Dclose(pop_var) ) < 0) HERR(routineName); return; }
/* ------- begin -------------------------- writeAux_p.c --- */ void writeAux_p(void) { /* this will write: populations, radrates, coll, damping */ const char routineName[] = "writeAux_p"; int nact, kr; hsize_t offset[] = {0, 0, 0, 0}; hsize_t count[] = {1, 1, 1, 1}; hsize_t dims[4]; hid_t file_dspace, mem_dspace; Atom *atom; Molecule *molecule; AtomicLine *line; AtomicContinuum *continuum; /* --- ATOMS --- */ for (nact = 0; nact < atmos.Nactiveatom; nact++) { atom = atmos.activeatoms[nact]; /* Write populations */ /* Memory dataspace */ dims[0] = atom->Nlevel; dims[1] = atmos.Nspace; /* File dataspace */ offset[0] = 0; offset[1] = mpi.ix; offset[2] = mpi.iy; offset[3] = mpi.zcut; count[0] = atom->Nlevel; count[3] = atmos.Nspace; if (input.p15d_wpop) { if (( mem_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName); if (( file_dspace = H5Dget_space(io.aux_atom_pop[nact]) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_pop[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, atom->n[0]) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_poplte[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, atom->nstar[0]) ) < 0) HERR(routineName); if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); } if (input.p15d_wrates) { /* Write radiative rates */ dims[0] = atmos.Nspace; count[0] = 1; if (( mem_dspace = H5Screate_simple(1, dims, NULL) ) < 0) HERR(routineName); if (( file_dspace = H5Dget_space(io.aux_atom_RijL[nact]) ) < 0) HERR(routineName); for (kr=0; kr < atom->Nline; kr++) { offset[0] = kr; line = &atom->line[kr]; if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_RijL[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, line->Rij) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_RjiL[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, line->Rji) ) < 0) HERR(routineName); } for (kr=0; kr < atom->Ncont; kr++) { offset[0] = kr; continuum = &atom->continuum[kr]; if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_RijC[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, continuum->Rij) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_RjiC[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, continuum->Rji) ) < 0) HERR(routineName); } if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); } } /* --- MOLECULES --- */ for (nact = 0; nact < atmos.Nactivemol; nact++) { molecule = atmos.activemols[nact]; if (input.p15d_wpop) { /* Write populations */ dims[0] = molecule->Nv; dims[1] = atmos.Nspace; if (( mem_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName); offset[0] = 0; offset[1] = mpi.ix; offset[2] = mpi.iy; offset[3] = mpi.zcut; count[0] = molecule->Nv; count[3] = atmos.Nspace; if (( file_dspace = H5Dget_space(io.aux_mol_pop[nact]) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_mol_pop[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, molecule->nv[0]) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_mol_poplte[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, molecule->nvstar[0]) ) < 0) HERR(routineName); if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); } } return; }
/* ------- begin -------------------------- init_aux_new.c -- --- */ void init_aux_new(void) { /* Creates the HDF5 file for the auxiliary data */ const char routineName[] = "init_aux_new"; unsigned int *tmp; double *tmp_double; int i; hid_t plist, ncid, file_dspace, ncid_atom, ncid_mol; hid_t id_x, id_y, id_z, id_n, id_tmp; hsize_t dims[4]; char group_name[ARR_STRLEN]; Atom *atom; Molecule *molecule; /* Create the file */ if (( plist = H5Pcreate(H5P_FILE_ACCESS) ) < 0) HERR(routineName); if (( H5Pset_fapl_mpio(plist, mpi.comm, mpi.info) ) < 0) HERR(routineName); if (( ncid = H5Fcreate(AUX_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, plist) ) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); /* --- Definitions for the root group --- */ /* dimensions as attributes */ if (( H5LTset_attribute_int(ncid, "/", "nx", &mpi.nx, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid, "/", "ny", &mpi.ny, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid, "/", "nz", (int *) &infile.nz, 1 )) < 0) HERR(routineName); /* attributes */ if (( H5LTset_attribute_string(ncid, "/", "atmosID", atmos.ID)) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid, "/", "rev_id", mpi.rev_id) ) < 0) HERR(routineName); /* Create arrays for multiple-atom/molecule output */ io.aux_atom_ncid = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_mol_ncid = (hid_t *) malloc(atmos.Nactivemol * sizeof(hid_t)); if (input.p15d_wpop) { io.aux_atom_pop = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_poplte = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_mol_pop = (hid_t *) malloc(atmos.Nactivemol * sizeof(hid_t)); io.aux_mol_poplte = (hid_t *) malloc(atmos.Nactivemol * sizeof(hid_t)); } if (input.p15d_wrates) { io.aux_atom_RijL = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_RjiL = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_RijC = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_RjiC = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); } /* Fill value */ if (( plist = H5Pcreate(H5P_DATASET_CREATE) ) < 0) HERR(routineName); if (( H5Pset_fill_value(plist, H5T_NATIVE_FLOAT, &FILLVALUE) ) < 0) HERR(routineName); if (( H5Pset_alloc_time(plist, H5D_ALLOC_TIME_EARLY) ) < 0) HERR(routineName); if (( H5Pset_fill_time(plist, H5D_FILL_TIME_ALLOC) ) < 0) HERR(routineName); /* --- Group loop over active ATOMS --- */ for (i=0; i < atmos.Nactiveatom; i++) { atom = atmos.activeatoms[i]; /* Get group name */ sprintf(group_name, (atom->ID[1] == ' ') ? "atom_%.1s" : "atom_%.2s", atom->ID); if (( ncid_atom = H5Gcreate(ncid, group_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) ) < 0) HERR(routineName); io.aux_atom_ncid[i] = ncid_atom; /* --- dimensions as attributes --- */ if (( H5LTset_attribute_int(ncid_atom, ".", "nlevel", &atom->Nlevel, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_atom, ".", "nline", &atom->Nline, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_atom, ".", "ncontinuum", &atom->Ncont, 1)) < 0) HERR(routineName); /* --- dimension datasets --- */ dims[0] = mpi.nx; if (( H5LTmake_dataset(ncid_atom, X_NAME, 1, dims, H5T_NATIVE_DOUBLE, geometry.xscale) ) < 0) HERR(routineName); if (( id_x = H5Dopen2(ncid_atom, X_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = mpi.ny; if (( H5LTmake_dataset(ncid_atom, Y_NAME, 1, dims, H5T_NATIVE_DOUBLE, geometry.yscale) ) < 0) HERR(routineName); if (( id_y = H5Dopen2(ncid_atom, Y_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = infile.nz; tmp_double = (double *) calloc(infile.nz , sizeof(double)); if (( H5LTmake_dataset(ncid_atom, ZOUT_NAME, 1, dims, H5T_NATIVE_DOUBLE, tmp_double) ) < 0) HERR(routineName); free(tmp_double); if (( id_z = H5Dopen2(ncid_atom, ZOUT_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = atom->Nlevel; tmp = (unsigned int *) calloc(atom->Nlevel , sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_atom, LEVEL_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); dims[0] = atom->Nline; tmp = (unsigned int *) calloc(atom->Nline , sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_atom, LINE_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); if (atom->Ncont > 0) { dims[0] = atom->Ncont; tmp = (unsigned int *) calloc(atom->Ncont , sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_atom, CONT_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); } /* For compatibility with netCDF readers, only use dataset as dimension */ if (( H5LTset_attribute_string(ncid_atom, ZOUT_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atom, LEVEL_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atom, LINE_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (atom->Ncont > 0) { if (( H5LTset_attribute_string(ncid_atom, CONT_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); } /* --- variables --- */ dims[0] = atom->Nlevel; dims[1] = mpi.nx; dims[2] = mpi.ny; dims[3] = infile.nz; /* Populations */ if (input.p15d_wpop) { if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0) HERR(routineName); if (( id_n = H5Dopen2(ncid_atom, LEVEL_NAME, H5P_DEFAULT)) < 0) HERR(routineName); if (atom->n != NULL) { if (( id_tmp = H5Dcreate(ncid_atom, POP_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, POP_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_pop[i] = id_tmp; } if (atom->nstar != NULL) { if (( id_tmp = H5Dcreate(ncid_atom, POPLTE_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, POPLTE_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_poplte[i] = id_tmp; } if (( H5Dclose(id_n) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); } if (input.p15d_wrates) { /* Radiative rates */ dims[0] = atom->Nline; dims[1] = mpi.nx; dims[2] = mpi.ny; dims[3] = infile.nz; if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0) HERR(routineName); if (( id_n = H5Dopen2(ncid_atom, LINE_NAME, H5P_DEFAULT)) < 0) HERR(routineName); if (( id_tmp = H5Dcreate(ncid_atom, RIJ_L_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, RIJ_L_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_RijL[i] = id_tmp; if (( id_tmp = H5Dcreate(ncid_atom, RJI_L_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, RJI_L_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_RjiL[i] = id_tmp; if (( H5Dclose(id_n) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); if (atom->Ncont > 0) { dims[0] = atom->Ncont; if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0) HERR(routineName); if (( id_n = H5Dopen2(ncid_atom, CONT_NAME, H5P_DEFAULT)) < 0) HERR(routineName); if (( id_tmp = H5Dcreate(ncid_atom, RIJ_C_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, RIJ_C_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_RijC[i] = id_tmp; if (( id_tmp = H5Dcreate(ncid_atom, RJI_C_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); if (( H5LTset_attribute_float(ncid_atom, RJI_C_NAME, "_FillValue", &FILLVALUE, 1) ) < 0) HERR(routineName); io.aux_atom_RjiC[i] = id_tmp; if (( H5Dclose(id_n) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); } } if (( H5Dclose(id_x) ) < 0) HERR(routineName); if (( H5Dclose(id_y) ) < 0) HERR(routineName); if (( H5Dclose(id_z) ) < 0) HERR(routineName); } /* end active ATOMS loop */ /* --- Group loop over active MOLECULES --- */ for (i=0; i < atmos.Nactivemol; i++) { molecule = atmos.activemols[i]; /* Get group name */ sprintf( group_name, "molecule_%s", molecule->ID); if (( ncid_mol = H5Gcreate(ncid, group_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) ) < 0) HERR(routineName); io.aux_mol_ncid[i] = ncid_mol; /* --- dimensions as attributes --- */ if (( H5LTset_attribute_int(ncid_mol, ".", "nlevel_vibr", &molecule->Nv, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mol, ".", "nline_molecule", &molecule->Nrt, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mol, ".", "nJ", &molecule->NJ, 1)) < 0) HERR(routineName); /* --- dimension datasets --- */ dims[0] = mpi.nx; if (( H5LTmake_dataset(ncid_mol, X_NAME, 1, dims, H5T_NATIVE_DOUBLE, geometry.xscale) ) < 0) HERR(routineName); if (( id_x = H5Dopen2(ncid_mol, X_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = mpi.ny; if (( H5LTmake_dataset(ncid_mol, Y_NAME, 1, dims, H5T_NATIVE_DOUBLE, geometry.yscale) ) < 0) HERR(routineName); if (( id_y = H5Dopen2(ncid_mol, Y_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = infile.nz; tmp_double = (double *) calloc(infile.nz , sizeof(double)); if (( H5LTmake_dataset(ncid_mol, ZOUT_NAME, 1, dims, H5T_NATIVE_DOUBLE, tmp_double) ) < 0) HERR(routineName); free(tmp_double); if (( id_z = H5Dopen2(ncid_mol, ZOUT_NAME, H5P_DEFAULT)) < 0) HERR(routineName); dims[0] = molecule->Nv; tmp = (unsigned int *) calloc(molecule->Nv, sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_mol, VLEVEL_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); dims[0] = molecule->Nrt; tmp = (unsigned int *) calloc(molecule->Nrt, sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_mol, VLINE_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); dims[0] = molecule->NJ; tmp = (unsigned int *) calloc(molecule->NJ, sizeof(unsigned int)); if (( H5LTmake_dataset(ncid_mol, NJ_NAME, 1, dims, H5T_NATIVE_UINT, tmp) ) < 0) HERR(routineName); free(tmp); /* For compatibility with netCDF readers, only use dataset as dimension */ if (( H5LTset_attribute_string(ncid_mol, ZOUT_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_mol, VLEVEL_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_mol, VLINE_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_mol, NJ_NAME, "NAME", NETCDF_COMPAT) ) < 0) HERR(routineName); /* --- variables --- */ dims[0] = molecule->Nv; dims[1] = mpi.nx; dims[2] = mpi.ny; dims[3] = infile.nz; /* Populations */ if (input.p15d_wpop) { if (( file_dspace = H5Screate_simple(4, dims, NULL) ) < 0) HERR(routineName); if (( id_n = H5Dopen2(ncid_mol, VLEVEL_NAME, H5P_DEFAULT)) < 0) HERR(routineName); if (molecule->nv != NULL) { if (( id_tmp = H5Dcreate(ncid_mol, POP_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); io.aux_mol_pop[i] = id_tmp; } if (molecule->nvstar != NULL) { if (( id_tmp = H5Dcreate(ncid_mol, POPLTE_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_n, 0)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_x, 1)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_y, 2)) < 0) HERR(routineName); if (( H5DSattach_scale(id_tmp, id_z, 3)) < 0) HERR(routineName); io.aux_mol_poplte[i] = id_tmp; } if (( H5Dclose(id_n) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); // TODO: molecule->Ediss, molecule->Tmin, molecule->Tmax } if (( H5Dclose(id_x) ) < 0) HERR(routineName); if (( H5Dclose(id_y) ) < 0) HERR(routineName); if (( H5Dclose(id_z) ) < 0) HERR(routineName); } /* end active MOLECULES loop */ io.aux_ncid = ncid; /* Copy stuff to the IO data struct */ if (( H5Pclose(plist) ) < 0) HERR(routineName); /* Free hdf5 resources */ /* Flush ensures file is created in case of crash */ if (( H5Fflush(ncid, H5F_SCOPE_LOCAL) ) < 0) HERR(routineName); return; }
/* ------- begin -------------------------- writeAux_all.c --- */ void writeAux_all(void) { const char routineName[] = "writeAux_all"; hsize_t offset[] = {0, 0, 0, 0}; hsize_t count[] = {1, 1, 1, 1}; hsize_t dims[4]; hid_t file_dspace, mem_dspace; Atom *atom; Molecule *molecule; int nact, task; long ind = 0; /* ATOM loop */ for (nact = 0; nact < atmos.Nactiveatom; nact++) { atom = atmos.activeatoms[nact]; ind = 0; /* Index of each task inside variables */ for (task = 0; task < mpi.Ntasks; task++) { /* If there was a crash, no data were written into buffer variables */ if (mpi.convergence[task] < 0) continue; /* Memory dataspace */ dims[0] = atom->Nlevel; dims[1] = infile.nz - mpi.zcut_hist[task]; if (( mem_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName); /* File dataspace */ offset[0] = 0; offset[1] = mpi.taskmap[task + mpi.my_start][0]; offset[2] = mpi.taskmap[task + mpi.my_start][1]; offset[3] = mpi.zcut_hist[task]; count[0] = atom->Nlevel; count[1] = 1; count[2] = 1; count[3] = infile.nz - mpi.zcut_hist[task]; if (input.p15d_wpop) { if (( file_dspace = H5Dget_space(io.aux_atom_pop[nact]) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_pop[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, &iobuf.n[nact][ind * atom->Nlevel]) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_poplte[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, &iobuf.nstar[nact][ind * atom->Nlevel]) ) < 0) HERR(routineName); /* release dataspace resources */ if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); } if (input.p15d_wrates) { /* Memory dataspace */ dims[0] = atom->Nline; if (( mem_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName); count[0] = atom->Nline; if (( file_dspace = H5Dget_space(io.aux_atom_RijL[nact]) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_RijL[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, &iobuf.RijL[nact][ind * atom->Nline]) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_RjiL[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, &iobuf.RjiL[nact][ind * atom->Nline]) ) < 0) HERR(routineName); /* release dataspace resources */ if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); if (atom->Ncont > 0) { /* Memory dataspace */ dims[0] = atom->Ncont; if (( mem_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName); count[0] = atom->Ncont; if (( file_dspace = H5Dget_space(io.aux_atom_RijC[nact]) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_RijC[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, &iobuf.RijC[nact][ind * atom->Ncont]) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_atom_RjiC[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, &iobuf.RjiC[nact][ind * atom->Ncont]) ) < 0) HERR(routineName); /* release dataspace resources */ if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); } } ind += count[3]; } } /* MOLECULE loop */ for (nact = 0; nact < atmos.Nactivemol; nact++) { molecule = atmos.activemols[nact]; ind = 0; /* Index of each task inside variables */ for (task = 0; task < mpi.Ntasks; task++) { /* If there was a crash, no data were written into buffer variables */ if (mpi.convergence[task] < 0) continue; if (input.p15d_wpop) { /* Memory dataspace */ dims[0] = molecule->Nv; dims[1] = infile.nz - mpi.zcut_hist[task]; if (( mem_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName); /* File dataspace */ offset[0] = 0; offset[1] = mpi.taskmap[task + mpi.my_start][0]; offset[2] = mpi.taskmap[task + mpi.my_start][1]; offset[3] = mpi.zcut_hist[task]; count[0] = molecule->Nv; count[3] = infile.nz - mpi.zcut_hist[task]; if (( file_dspace = H5Dget_space(io.aux_mol_pop[nact]) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_mol_pop[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, &iobuf.nv[nact][ind * molecule->Nv]) ) < 0) HERR(routineName); if (( H5Dwrite(io.aux_mol_poplte[nact], H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, &iobuf.nvstar[nact][ind * molecule->Nv]) ) < 0) HERR(routineName); /* release dataspace resources */ if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); } ind += count[3]; } } return; }
/* ------- begin -------------------------- close_hdf5_aux.c --- */ void close_hdf5_aux(void) /* Closes the aux file */ { const char routineName[] = "close_hdf5_aux"; Atom *atom; int i; /* Close all datasets and groups */ for (i=0; i < atmos.Nactiveatom; i++) { atom = atmos.activeatoms[i]; if (input.p15d_wpop) { if (( H5Dclose(io.aux_atom_pop[i]) ) < 0) HERR(routineName); if (( H5Dclose(io.aux_atom_poplte[i]) ) < 0) HERR(routineName); } if (input.p15d_wrates) { if (( H5Dclose(io.aux_atom_RijL[i]) ) < 0) HERR(routineName); if (( H5Dclose(io.aux_atom_RjiL[i]) ) < 0) HERR(routineName); if (atom->Ncont > 0) { if (( H5Dclose(io.aux_atom_RijC[i]) ) < 0) HERR(routineName); if (( H5Dclose(io.aux_atom_RjiC[i]) ) < 0) HERR(routineName); } } if (( H5Gclose(io.aux_atom_ncid[i]) ) < 0) HERR(routineName); } for (i=0; i < atmos.Nactivemol; i++) { if (input.p15d_wpop) { if (( H5Dclose(io.aux_mol_pop[i]) ) < 0) HERR(routineName); if (( H5Dclose(io.aux_mol_poplte[i]) ) < 0) HERR(routineName); } if (( H5Gclose(io.aux_mol_ncid[i]) ) < 0) HERR(routineName); } /* Close file */ if (( H5Fclose(io.aux_ncid) ) < 0) HERR(routineName); return; }
/* ------- begin -------------------- init_aux_existing.c --- */ void init_aux_existing(void) { const char routineName[] = "init_aux_existing"; int i, nlevel, nline, ncont; size_t attr_size; hid_t ncid, ncid_atom, ncid_mol, plist; H5T_class_t type_class; char group_name[ARR_STRLEN], *atmosID; Atom *atom; Molecule *molecule; /* Open the file with parallel MPI-IO access */ if (( plist = H5Pcreate(H5P_FILE_ACCESS )) < 0) HERR(routineName); if (( H5Pset_fapl_mpio(plist, mpi.comm, mpi.info) ) < 0) HERR(routineName); if (( ncid = H5Fopen(AUX_FILE, H5F_ACC_RDWR, plist) ) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); io.aux_ncid = ncid; /* --- Consistency checks --- */ /* Check that atmosID is the same */ if (( H5LTget_attribute_info(ncid, "/", "atmosID", NULL, &type_class, &attr_size) ) < 0) HERR(routineName); atmosID = (char *) malloc(attr_size + 1); if (( H5LTget_attribute_string(ncid, "/", "atmosID", atmosID) ) < 0) HERR(routineName); if (!strstr(atmosID, atmos.ID)) { sprintf(messageStr, "Indata file was calculated for different atmosphere (%s) than current", atmosID); Error(WARNING, routineName, messageStr); } free(atmosID); /* Create arrays for multiple-atom/molecule output */ io.aux_atom_ncid = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_mol_ncid = (hid_t *) malloc(atmos.Nactivemol * sizeof(hid_t)); if (input.p15d_wpop) { io.aux_atom_pop = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_poplte = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_mol_pop = (hid_t *) malloc(atmos.Nactivemol * sizeof(hid_t)); io.aux_mol_poplte = (hid_t *) malloc(atmos.Nactivemol * sizeof(hid_t)); } if (input.p15d_wrates) { io.aux_atom_RijL = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_RjiL = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_RijC = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); io.aux_atom_RjiC = (hid_t *) malloc(atmos.Nactiveatom * sizeof(hid_t)); } /* --- Group loop over active ATOMS --- */ for (i=0; i < atmos.Nactiveatom; i++) { atom = atmos.activeatoms[i]; /* --- Get ncid of the atom group --- */ sprintf(group_name,(atom->ID[1] == ' ') ? "atom_%.1s" : "atom_%.2s", atom->ID); if (( io.aux_atom_ncid[i] = H5Gopen(io.aux_ncid, group_name, H5P_DEFAULT) ) < 0) HERR(routineName); ncid_atom = io.aux_atom_ncid[i]; /* Check that dimension sizes match */ if (( H5LTget_attribute_int(ncid_atom, ".", "nlevel", &nlevel) ) < 0) HERR(routineName); if (nlevel != atom->Nlevel) { sprintf(messageStr, "Number of levels mismatch: expected %d, found %d.", atom->Nlevel, (int)nlevel); Error(ERROR_LEVEL_2, routineName, messageStr); } if (( H5LTget_attribute_int(ncid_atom, ".", "nline", &nline) ) < 0) HERR(routineName); if (nline != atom->Nline) { sprintf(messageStr, "Number of lines mismatch: expected %d, found %d.", atom->Nline, (int)nline); Error(ERROR_LEVEL_2, routineName, messageStr); } if (( H5LTget_attribute_int(ncid_atom, ".", "ncontinuum", &ncont) ) < 0) HERR(routineName); if (ncont != atom->Ncont) { sprintf(messageStr, "Number of continua mismatch: expected %d, found %d.", atom->Ncont, (int)ncont); Error(ERROR_LEVEL_2, routineName, messageStr); } /* --- Open datasets collectively ---*/ if (input.p15d_wpop) { if (( io.aux_atom_pop[i] = H5Dopen(ncid_atom, POP_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.aux_atom_poplte[i] = H5Dopen(ncid_atom, POPLTE_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); } if (input.p15d_wrates) { if (( io.aux_atom_RijL[i] = H5Dopen(ncid_atom, RIJ_L_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.aux_atom_RjiL[i] = H5Dopen(ncid_atom, RJI_L_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); if (atom->Ncont > 0) { if (( io.aux_atom_RijC[i] = H5Dopen(ncid_atom, RIJ_C_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.aux_atom_RjiC[i] = H5Dopen(ncid_atom, RJI_C_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); } } } /* end active ATOMS loop */ /* --- Group loop over active MOLECULES --- */ for (i=0; i < atmos.Nactivemol; i++) { molecule = atmos.activemols[i]; /* --- Get ncid of the molecule group --- */ sprintf( group_name, "molecule_%s", molecule->ID); if (( io.aux_mol_ncid[i] = H5Gopen(io.aux_ncid, group_name, H5P_DEFAULT) ) < 0) HERR(routineName); ncid_mol = io.aux_mol_ncid[i]; /* Check that dimension sizes match */ if (( H5LTget_attribute_int(ncid_mol, ".", "nlevel_vibr", &nlevel) ) < 0) HERR(routineName); if (nlevel != molecule->Nv) { sprintf(messageStr, "Number of levels mismatch: expected %d, found %d.", molecule->Nv, (int)nlevel); Error(ERROR_LEVEL_2, routineName, messageStr); } if (( H5LTget_attribute_int(ncid_mol, ".", "nline_molecule", &nline) ) < 0) HERR(routineName); if (nline != molecule->Nrt) { sprintf(messageStr, "Number of lines mismatch: expected %d, found %d.", molecule->Nrt, (int)nline); Error(ERROR_LEVEL_2, routineName, messageStr); } if (( H5LTget_attribute_int(ncid_mol, ".", "nJ", &ncont) ) < 0) HERR(routineName); if (ncont != molecule->NJ) { sprintf(messageStr, "Number of J mismatch: expected %d, found %d.", molecule->NJ, (int)ncont); Error(ERROR_LEVEL_2, routineName, messageStr); } /* --- Open datasets collectively ---*/ if (input.p15d_wpop) { if (( io.aux_mol_pop[i] = H5Dopen(ncid_mol, POP_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.aux_mol_poplte[i] = H5Dopen(ncid_mol, POPLTE_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); } } /* end active MOLECULES loop */ return; }
/* ------- begin -------------------------- readConvergence.c --- */ void readConvergence(void) { /* This is a self-contained function to read the convergence matrix, written by RH. */ const char routineName[] = "readConvergence"; char *atmosID; int ncid, ncid_mpi, nx, ny; size_t attr_size; hid_t plist; H5T_class_t type_class; mpi.rh_converged = matrix_int(mpi.nx, mpi.ny); /* --- Open the inputdata file --- */ if (( plist = H5Pcreate(H5P_FILE_ACCESS )) < 0) HERR(routineName); if (( H5Pset_fapl_mpio(plist, mpi.comm, mpi.info) ) < 0) HERR(routineName); if (( ncid = H5Fopen(INPUTDATA_FILE, H5F_ACC_RDWR, plist) ) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); /* Get ncid of the MPI group */ if (( ncid_mpi = H5Gopen(ncid, "mpi", H5P_DEFAULT) ) < 0) HERR(routineName); /* --- Consistency checks --- */ /* Check that atmosID is the same */ if (( H5LTget_attribute_info(ncid, "/", "atmosID", NULL, &type_class, &attr_size) ) < 0) HERR(routineName); atmosID = (char *) malloc(attr_size + 1); if (( H5LTget_attribute_string(ncid, "/", "atmosID", atmosID) ) < 0) HERR(routineName); if (!strstr(atmosID, atmos.ID)) { sprintf(messageStr, "Indata file was calculated for different atmosphere (%s) than current", atmosID); Error(WARNING, routineName, messageStr); } free(atmosID); /* Check that dimension sizes match */ if (( H5LTget_attribute_int(ncid, "/", "nx", &nx) ) < 0) HERR(routineName); if (nx != mpi.nx) { sprintf(messageStr, "Number of x points mismatch: expected %d, found %d.", mpi.nx, (int)nx); Error(WARNING, routineName, messageStr); } if (( H5LTget_attribute_int(ncid, "/", "ny", &ny) ) < 0) HERR(routineName); if (ny != mpi.ny) { sprintf(messageStr, "Number of y points mismatch: expected %d, found %d.", mpi.ny, (int)ny); Error(WARNING, routineName, messageStr); } /* --- Read variable --- */ if (( H5LTread_dataset_int(ncid_mpi, CONV_NAME, mpi.rh_converged[0]) ) < 0) HERR(routineName); /* --- Close inputdata file --- */ if (( H5Gclose(ncid_mpi) ) < 0) HERR(routineName); if (( H5Fclose(ncid) ) < 0) HERR(routineName); return; }
/* ------- begin -------------------------- writeMPI_p.c ----- */ void writeMPI_p(int task) { /* Writes output on indata file, MPI group, one task at once */ const char routineName[] = "writeMPI_p"; hsize_t offset[] = {0, 0, 0, 0}; hsize_t count[] = {1, 1, 1, 1}; hsize_t dims[4]; hid_t file_dspace, mem_dspace; dims[0] = 1; if (( mem_dspace = H5Screate_simple(1, dims, NULL) ) < 0) HERR(routineName); offset[0] = mpi.ix; offset[1] = mpi.iy; if (( file_dspace = H5Dget_space(io.in_mpi_tm) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_tm, H5T_NATIVE_INT, mem_dspace, file_dspace, H5P_DEFAULT, &mpi.rank) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_tn, H5T_NATIVE_INT, mem_dspace, file_dspace, H5P_DEFAULT, &task) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_it, H5T_NATIVE_INT, mem_dspace, file_dspace, H5P_DEFAULT, &mpi.niter[0]) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_conv, H5T_NATIVE_INT, mem_dspace, file_dspace, H5P_DEFAULT, &mpi.convergence[0]) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_zc, H5T_NATIVE_INT, mem_dspace, file_dspace, H5P_DEFAULT, &mpi.zcut_hist[0]) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_dm, H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, &mpi.dpopsmax[0]) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); dims[0] = mpi.niter[0]; if (( mem_dspace = H5Screate_simple(1, dims, NULL) ) < 0) HERR(routineName); offset[0] = mpi.ix; offset[1] = mpi.iy; count[2] = mpi.niter[0]; if (( file_dspace = H5Dget_space(io.in_mpi_dmh) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_dmh, H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, mpi.dpopsmax_hist[0]) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); return; }
/* ------- begin -------------------------- writeMPI_all.c --- */ void writeMPI_all(void) { /* Writes output on indata file, MPI group, all tasks at once */ const char routineName[] = "writeMPI_all"; int task; hsize_t offset[] = {0, 0, 0, 0}; hsize_t count[] = {1, 1, 1, 1}; hsize_t dims[4]; hid_t file_dspace, mem_dspace; /* Write single values of Ntasks, one value at a time */ dims[0] = 1; if (( mem_dspace = H5Screate_simple(1, dims, NULL) ) < 0) HERR(routineName); for (task = 0; task < mpi.Ntasks; task++) { offset[0] = mpi.taskmap[task + mpi.my_start][0]; offset[1] = mpi.taskmap[task + mpi.my_start][1]; if (( file_dspace = H5Dget_space(io.in_mpi_it) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_it, H5T_NATIVE_INT, mem_dspace, file_dspace, H5P_DEFAULT, &mpi.niter[task]) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_conv, H5T_NATIVE_INT, mem_dspace, file_dspace, H5P_DEFAULT, &mpi.convergence[task]) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_zc, H5T_NATIVE_INT, mem_dspace, file_dspace, H5P_DEFAULT, &mpi.zcut_hist[task]) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_dm, H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, &mpi.dpopsmax[task]) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); } if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); /* Write array with multiple values */ for (task = 0; task < mpi.Ntasks; task++) { dims[0] = mpi.niter[task]; if (( mem_dspace = H5Screate_simple(1, dims, NULL) ) < 0) HERR(routineName); offset[0] = mpi.taskmap[task + mpi.my_start][0]; offset[1] = mpi.taskmap[task + mpi.my_start][1]; count[2] = mpi.niter[task]; if (( file_dspace = H5Dget_space(io.in_mpi_dmh) ) < 0) HERR(routineName); if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset, NULL, count, NULL) ) < 0) HERR(routineName); if (( H5Dwrite(io.in_mpi_dmh, H5T_NATIVE_DOUBLE, mem_dspace, file_dspace, H5P_DEFAULT, mpi.dpopsmax_hist[task]) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName); } return; }
/* ------- begin -------------------------- init_hdf5_indata.c --- */ void init_hdf5_indata_new(void) /* Creates the netCDF file for the input data */ { const char routineName[] = "init_hdf5_indata_new"; int i, PRD_angle_dep; double *eweight, *eabund, *x, *y; /* This value is harcoded for efficiency. Maximum number of iterations ever needed */ int NMaxIter = 1500; hid_t plist, ncid, file_dspace, ncid_input, ncid_atmos, ncid_mpi; hsize_t dims[4]; bool_t XRD; char startJ[MAX_LINE_SIZE], StokesMode[MAX_LINE_SIZE], angleSet[MAX_LINE_SIZE]; /* Create the file */ if (( plist = H5Pcreate(H5P_FILE_ACCESS )) < 0) HERR(routineName); if (( H5Pset_fapl_mpio(plist, mpi.comm, mpi.info) ) < 0) HERR(routineName); if (( ncid = H5Fcreate(INPUTDATA_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, plist) ) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); /* Create groups */ if (( ncid_input = H5Gcreate(ncid, "/input", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) ) < 0) HERR(routineName); if (( ncid_atmos = H5Gcreate(ncid, "/atmos", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) ) < 0) HERR(routineName); if (( ncid_mpi = H5Gcreate(ncid, "/mpi", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) ) < 0) HERR(routineName); /* --- Definitions for the root group --- */ /* dimensions as attributes */ if (( H5LTset_attribute_int(ncid, "/", "nx", &mpi.nx, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid, "/", "ny", &mpi.ny, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid, "/", "nz", (int *) &infile.nz, 1 )) < 0) HERR(routineName); /* attributes */ if (( H5LTset_attribute_string(ncid, "/", "atmosID", atmos.ID)) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid, "/", "rev_id", mpi.rev_id) ) < 0) HERR(routineName); /* --- Definitions for the INPUT group --- */ /* attributes */ if ( atmos.NPRDactive > 0) PRD_angle_dep = input.PRD_angle_dep; else PRD_angle_dep=0; XRD = (input.XRD && atmos.NPRDactive > 0); if (( H5LTset_attribute_uchar(ncid_input, ".", "Magneto_optical", (unsigned char *) &input.magneto_optical, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_uchar(ncid_input, ".", "PRD_angle_dep", (unsigned char *) &PRD_angle_dep, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_uchar(ncid_input, ".", "XRD", (unsigned char *) &XRD, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_uchar(ncid_input, ".", "Background_polarization", (unsigned char *) &input.backgr_pol, 1)) < 0) HERR(routineName); switch (input.startJ) { case UNKNOWN: strcpy(startJ, "Unknown"); break; case LTE_POPULATIONS: strcpy(startJ, "LTE_POPULATIONS"); break; case ZERO_RADIATION: strcpy(startJ, "ZERO_RADIATION"); break; case OLD_POPULATIONS: strcpy(startJ, "OLD_POPULATIONS"); break; case ESCAPE_PROBABILITY: strcpy(startJ, "ESCAPE_PROBABILITY"); break; case NEW_J: strcpy(startJ, "NEW_J"); break; case OLD_J: strcpy(startJ, "OLD_J"); break; } if (( H5LTset_attribute_string(ncid_input, ".", "Start_J", startJ)) < 0) HERR(routineName); switch (input.StokesMode) { case NO_STOKES: strcpy(StokesMode, "NO_STOKES"); break; case FIELD_FREE: strcpy(StokesMode, "FIELD_FREE"); break; case POLARIZATION_FREE: strcpy(StokesMode, "POLARIZATION_FREE"); break; case FULL_STOKES: strcpy(StokesMode, "FULL_STOKES"); break; } if (( H5LTset_attribute_string(ncid_input, ".", "Stokes_mode", StokesMode) ) < 0) HERR(routineName); switch (atmos.angleSet.set) { case SET_VERTICAL: strcpy(angleSet, "SET_VERTICAL"); break; case SET_GL: strcpy(angleSet, "SET_GL"); break; case SET_A2: strcpy(angleSet, "SET_A2"); break; case SET_A4: strcpy(angleSet, "SET_A4"); break; case SET_A6: strcpy(angleSet, "SET_A6"); break; case SET_A8: strcpy(angleSet, "SET_A8"); break; case SET_B4: strcpy(angleSet, "SET_B4"); break; case SET_B6: strcpy(angleSet, "SET_B6"); break; case SET_B8: strcpy(angleSet, "SET_B8"); break; case NO_SET: strcpy(angleSet, "NO_SET"); break; } if (( H5LTset_attribute_string(ncid_input, ".", "Angle_set", angleSet) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_input, ".", "Atmos_file", input.atmos_input) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_input, ".", "Abundances_file", input.abund_input) ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_input, ".", "Kurucz_PF_data", input.pfData) ) < 0) HERR(routineName); if (( H5LTset_attribute_double(ncid_input, ".", "Iteration_limit", &input.iterLimit, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_double(ncid_input, ".", "PRD_Iteration_limit", &input.PRDiterLimit, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "N_max_iter", &input.NmaxIter, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "Ng_delay", &input.Ngdelay, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "Ng_order", &input.Ngorder, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "Ng_period", &input.Ngperiod, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "PRD_N_max_iter", &input.PRD_NmaxIter, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "PRD_Ng_delay", &input.PRD_Ngdelay, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "PRD_Ng_order", &input.PRD_Ngorder, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_input, ".", "PRD_Ng_period", &input.PRD_Ngperiod, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_double(ncid_input, ".", "Metallicity", &input.metallicity, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_double(ncid_input, ".", "Lambda_reference", &atmos.lambda_ref, 1) ) < 0) HERR(routineName); /* --- Definitions for the ATMOS group --- */ /* dimensions */ if (( H5LTset_attribute_int(ncid_atmos, ".", "nhydr", &atmos.H->Nlevel, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_atmos, ".", "nelements", &atmos.Nelem, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_atmos, ".", "nrays", &geometry.Nrays, 1) ) < 0) HERR(routineName); /* variables*/ dims[0] = mpi.nx; dims[1] = mpi.ny; dims[2] = infile.nz; if (( file_dspace = H5Screate_simple(3, dims, NULL) ) < 0) HERR(routineName); if (( plist = H5Pcreate(H5P_DATASET_CREATE) ) < 0) HERR(routineName); if (( H5Pset_fill_value(plist, H5T_NATIVE_FLOAT, &FILLVALUE) ) < 0) HERR(routineName); if (( H5Pset_alloc_time(plist, H5D_ALLOC_TIME_EARLY) ) < 0) HERR(routineName); if (( H5Pset_fill_time(plist, H5D_FILL_TIME_ALLOC) ) < 0) HERR(routineName); if (( io.in_atmos_T = H5Dcreate(ncid_atmos, "temperature", H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_atmos_vz = H5Dcreate(ncid_atmos, "velocity_z", H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_atmos_z = H5Dcreate(ncid_atmos, "height", H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); /* --- Write some data that does not depend on xi, yi, ATMOS group --- */ /* arrays of number of elements */ eweight = (double *) malloc(atmos.Nelem * sizeof(double)); eabund = (double *) malloc(atmos.Nelem * sizeof(double)); for (i=0; i < atmos.Nelem; i++) { eweight[i] = atmos.elements[i].weight; eabund[i] = atmos.elements[i].abund; } dims[0] = atmos.Nelem; if (( H5LTmake_dataset(ncid_atmos, "element_weight", 1, dims, H5T_NATIVE_DOUBLE, eweight) ) < 0) HERR(routineName); if (( H5LTmake_dataset(ncid_atmos, "element_abundance", 1, dims, H5T_NATIVE_DOUBLE, eabund) ) < 0) HERR(routineName); /* Not writing element_id for now dims[1] = strlen; if (( H5LTmake_dataset(ncid_atmos, "element_id", 2, dims, H5T_C_S1, eID) ) < 0) HERR(routineName); */ free(eweight); free(eabund); dims[0] = geometry.Nrays; if (( H5LTmake_dataset(ncid_atmos, "muz", 1, dims, H5T_NATIVE_DOUBLE, geometry.muz) ) < 0) HERR(routineName); if (( H5LTmake_dataset(ncid_atmos, "wmu", 1, dims, H5T_NATIVE_DOUBLE, geometry.wmu) ) < 0) HERR(routineName); x = (double *) malloc(mpi.nx * sizeof(double)); y = (double *) malloc(mpi.ny * sizeof(double)); for (i=0; i < mpi.nx; i++) x[i] = infile.x[mpi.xnum[i]]; for (i=0; i < mpi.ny; i++) y[i] = infile.y[mpi.ynum[i]]; dims[0] = mpi.nx; if (( H5LTmake_dataset(ncid_atmos, "x", 1, dims, H5T_NATIVE_DOUBLE, x) ) < 0) HERR(routineName); dims[0] = mpi.ny; if (( H5LTmake_dataset(ncid_atmos, "y", 1, dims, H5T_NATIVE_DOUBLE, y) ) < 0) HERR(routineName); free(x); free(y); /* attributes */ if (( H5LTset_attribute_uchar(ncid_atmos, ".", "moving", (unsigned char *) &atmos.moving, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_uchar(ncid_atmos, ".", "stokes", (unsigned char *) &atmos.Stokes, 1)) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "temperature", "units", "K") ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "velocity_z", "units", "m s^-1") ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "height", "units", "m") ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "element_weight", "units", "atomic_mass_units") ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "x", "units", "m") ) < 0) HERR(routineName); if (( H5LTset_attribute_string(ncid_atmos, "y", "units", "m") ) < 0) HERR(routineName); /* --- Definitions for the MPI group --- */ /* dimensions */ if (( H5LTset_attribute_int(ncid_mpi, ".", "nprocesses", &mpi.size, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "niterations", &NMaxIter, 1) ) < 0) HERR(routineName); /* variables*/ dims[0] = mpi.nx; if (( H5LTmake_dataset(ncid_mpi, XNUM_NAME, 1, dims, H5T_NATIVE_INT, mpi.xnum) ) < 0) HERR(routineName); dims[0] = mpi.ny; if (( H5LTmake_dataset(ncid_mpi, YNUM_NAME, 1, dims, H5T_NATIVE_INT, mpi.ynum) ) < 0) HERR(routineName); dims[0] = mpi.nx; dims[1] = mpi.ny; if (( file_dspace = H5Screate_simple(2, dims, NULL) ) < 0) HERR(routineName); if (( plist = H5Pcreate(H5P_DATASET_CREATE) ) < 0) HERR(routineName); if (( H5Pset_fill_value(plist, H5T_NATIVE_FLOAT, &FILLVALUE) ) < 0) HERR(routineName); if (( H5Pset_alloc_time(plist, H5D_ALLOC_TIME_EARLY) ) < 0) HERR(routineName); if (( H5Pset_fill_time(plist, H5D_FILL_TIME_ALLOC) ) < 0) HERR(routineName); if (( io.in_mpi_tm = H5Dcreate(ncid_mpi, TASK_MAP, H5T_NATIVE_LONG, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_mpi_tn = H5Dcreate(ncid_mpi, TASK_NUMBER, H5T_NATIVE_LONG, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_mpi_it = H5Dcreate(ncid_mpi, ITER_NAME, H5T_NATIVE_LONG, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_mpi_conv = H5Dcreate(ncid_mpi, CONV_NAME, H5T_NATIVE_LONG, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_mpi_dm = H5Dcreate(ncid_mpi, DM_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( io.in_mpi_zc = H5Dcreate(ncid_mpi, ZC_NAME, H5T_NATIVE_INT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); dims[0] = mpi.nx; dims[1] = mpi.ny; dims[2] = NMaxIter; if (( file_dspace = H5Screate_simple(3, dims, NULL) ) < 0) HERR(routineName); if (( plist = H5Pcreate(H5P_DATASET_CREATE) ) < 0) HERR(routineName); if (( H5Pset_fill_value(plist, H5T_NATIVE_FLOAT, &FILLVALUE) ) < 0) HERR(routineName); if (( H5Pset_alloc_time(plist, H5D_ALLOC_TIME_EARLY) ) < 0) HERR(routineName); if (( H5Pset_fill_time(plist, H5D_FILL_TIME_ALLOC) ) < 0) HERR(routineName); if (( io.in_mpi_dmh = H5Dcreate(ncid_mpi, DMH_NAME, H5T_NATIVE_FLOAT, file_dspace, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); if (( H5Sclose(file_dspace) ) < 0) HERR(routineName); /* attributes */ if (( H5LTset_attribute_int(ncid_mpi, ".", "x_start", &input.p15d_x0, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "x_end", &input.p15d_x1, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "x_step", &input.p15d_xst, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "y_start", &input.p15d_y0, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "y_end", &input.p15d_y1, 1) ) < 0) HERR(routineName); if (( H5LTset_attribute_int(ncid_mpi, ".", "y_step", &input.p15d_yst, 1) ) < 0) HERR(routineName); /* Tiago: most of the arrays involving Ntasks or rank as index are not currently being written. They should eventually be migrated into arrays of [ix, iy] and be written for each task. This is to avoid causing problems with pool mode, where these quantities are not known from the start. */ /* Flush ensures file is created in case of crash */ if (( H5Fflush(ncid, H5F_SCOPE_LOCAL) ) < 0) HERR(routineName); /* --- Copy stuff to the IO data struct --- */ io.in_ncid = ncid; io.in_input_ncid = ncid_input; io.in_atmos_ncid = ncid_atmos; io.in_mpi_ncid = ncid_mpi; return; }
/* ------- begin -------------------------- close_hdf5_indata.c --- */ void close_hdf5_indata(void) /* Closes the indata netCDF file */ { const char routineName[] = "close_hdf5_indata"; /* Close all datasets */ if (( H5Dclose(io.in_atmos_T) ) < 0) HERR(routineName); if (( H5Dclose(io.in_atmos_vz) ) < 0) HERR(routineName); if (( H5Dclose(io.in_atmos_z) ) < 0) HERR(routineName); if (( H5Dclose(io.in_mpi_tm) ) < 0) HERR(routineName); if (( H5Dclose(io.in_mpi_tn) ) < 0) HERR(routineName); if (( H5Dclose(io.in_mpi_it) ) < 0) HERR(routineName); if (( H5Dclose(io.in_mpi_conv) ) < 0) HERR(routineName); if (( H5Dclose(io.in_mpi_dm) ) < 0) HERR(routineName); if (( H5Dclose(io.in_mpi_dmh) ) < 0) HERR(routineName); if (( H5Dclose(io.in_mpi_zc) ) < 0) HERR(routineName); /* Close all groups */ if (( H5Gclose(io.in_input_ncid) ) < 0) HERR(routineName); if (( H5Gclose(io.in_atmos_ncid) ) < 0) HERR(routineName); if (( H5Gclose(io.in_mpi_ncid) ) < 0) HERR(routineName); /* Close file */ if (( H5Fclose(io.in_ncid) ) < 0) HERR(routineName); return; }
/* ------- begin -------------------------- init_hdf5_indata_old.c --- */ void init_hdf5_indata_existing(void) /* Opens an existing NetCDF input data file, loads structures and ids */ { const char routineName[] = "init_hdf5_indata_existing"; int ncid; size_t attr_size; hid_t plist; char *atmosID; H5T_class_t type_class; /* Open the file with parallel MPI-IO access */ if (( plist = H5Pcreate(H5P_FILE_ACCESS )) < 0) HERR(routineName); if (( H5Pset_fapl_mpio(plist, mpi.comm, mpi.info) ) < 0) HERR(routineName); if (( ncid = H5Fopen(INPUTDATA_FILE, H5F_ACC_RDWR, plist) ) < 0) HERR(routineName); if (( H5Pclose(plist) ) < 0) HERR(routineName); io.in_ncid = ncid; /* --- Consistency checks --- */ /* Check that atmosID is the same */ if (( H5LTget_attribute_info(ncid, "/", "atmosID", NULL, &type_class, &attr_size) ) < 0) HERR(routineName); atmosID = (char *) malloc(attr_size + 1); if (( H5LTget_attribute_string(ncid, "/", "atmosID", atmosID) ) < 0) HERR(routineName); if (!strstr(atmosID, atmos.ID)) { sprintf(messageStr, "Indata file was calculated for different atmosphere (%s) than current", atmosID); Error(WARNING, routineName, messageStr); } free(atmosID); /* Get group IDs */ if (( io.in_input_ncid = H5Gopen(ncid, "input", H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.in_atmos_ncid = H5Gopen(ncid, "atmos", H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.in_mpi_ncid = H5Gopen(ncid, "mpi", H5P_DEFAULT) ) < 0) HERR(routineName); /* --- Open datasets collectively ---*/ if (( io.in_atmos_T = H5Dopen(io.in_atmos_ncid, "temperature", H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.in_atmos_vz = H5Dopen(io.in_atmos_ncid, "velocity_z", H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.in_atmos_z = H5Dopen(io.in_atmos_ncid, "height", H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.in_mpi_tm = H5Dopen(io.in_mpi_ncid, TASK_MAP, H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.in_mpi_tn = H5Dopen(io.in_mpi_ncid, TASK_NUMBER, H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.in_mpi_it = H5Dopen(io.in_mpi_ncid, ITER_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.in_mpi_conv = H5Dopen(io.in_mpi_ncid, CONV_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.in_mpi_dm = H5Dopen(io.in_mpi_ncid, DM_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.in_mpi_dmh = H5Dopen(io.in_mpi_ncid, DMH_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); if (( io.in_mpi_zc = H5Dopen(io.in_mpi_ncid, ZC_NAME, H5P_DEFAULT) ) < 0) HERR(routineName); return; }