117 for (file >> line; !file.eof() && !file.fail() && !file.bad(); file >> line) {
143 std::vector<double> phi_angles;
144 for (
size_t i = 0; i < num_phi; i++) {
148 if (type == degrees) {
152 phi_angles.push_back(phi);
160 for (file >> r >> z; !file.eof() && !file.fail() && !file.bad(); file >> r >> z) {
171 file.eof() ? file.clear(std::iostream::eofbit) : file.clear();
173 for (
double phi : phi_angles) {
174 limiters[phi].push_back(
limiter);
188 std::ifstream file(file_name);
190 std::map<const double, std::vector<vertex *> > limiters;
220 int main(
int argc,
const char * argv[]) {
223 std::cout <<
"Expected 7 arguments." << std::endl;
224 std::cout <<
"lgrid filename r0 dr numr z0 dz numz" << std::endl;
227 std::map<const double, std::vector<vertex *> > limiters =
parse_limiter_file(argv[1]);
229 const double r0 = atof(argv[2]);
230 const double dr = atof(argv[3]);
231 const size_t num_r = atoll(argv[4]);
233 const double z0 = atof(argv[5]);
234 const double dz = atof(argv[6]);
235 const size_t num_z = atoll(argv[7]);
237 std::vector<double> grids;
240 nc_create((std::string(argv[1]) + std::string(
".nc")).c_str(), NC_WRITE, &ncid);
243 nc_def_dim(ncid,
"num_phi", limiters.size(), &num_phi_dimid);
245 nc_def_dim(ncid,
"num_r", num_r, &num_r_dimid);
247 nc_def_dim(ncid,
"num_z", num_z, &num_z_dimid);
249 std::vector<double> phi_angles;
251 for (std::pair<
const double, std::vector<vertex *> > &phi : limiters) {
252 phi_angles.push_back(phi.first);
253 for (
size_t j = 0; j < num_z; j++) {
254 const double z = z0 + j*dz;
255 for (
size_t i = 0; i < num_r; i++) {
256 const double r = r0 + i*dr;
257 std::vector<double> d;
261 std::sort(d.begin(), d.end(), [](
double a,
double b) {
262 return fabs(a) < fabs(b);
264 grids.push_back(d[0]);
269 int phi_angles_varid;
270 nc_def_var(ncid,
"phi_angles", NC_DOUBLE, 1, &num_phi_dimid, &phi_angles_varid);
272 nc_def_var(ncid,
"r0", NC_DOUBLE, 0,
nullptr, &r0_varid);
274 nc_def_var(ncid,
"dr", NC_DOUBLE, 0,
nullptr, &dr_varid);
276 nc_def_var(ncid,
"z0", NC_DOUBLE, 0,
nullptr, &z0_varid);
278 nc_def_var(ncid,
"dz", NC_DOUBLE, 0,
nullptr, &dz_varid);
281 std::array<int, 3> grid_dims;
282 grid_dims[0] = num_phi_dimid;
283 grid_dims[1] = num_z_dimid;
284 grid_dims[2] = num_r_dimid;
285 nc_def_var(ncid,
"iso_grids", NC_DOUBLE, 3, grid_dims.data(), &grids_varid);
289 nc_put_var(ncid, phi_angles_varid, phi_angles.data());
290 nc_put_var(ncid, r0_varid, &r0);
291 nc_put_var(ncid, dr_varid, &dr);
292 nc_put_var(ncid, z0_varid, &z0);
293 nc_put_var(ncid, dz_varid, &dz);
294 nc_put_var(ncid, grids_varid, grids.data());