/*************************************************************************** dump_nonlocal_field.cpp Author: Andreas Suter e-mail: andreas.suter@psi.ch ***************************************************************************/ /*************************************************************************** * Copyright (C) 2009-2025 by Andreas Suter * * andreas.suter@psi.ch * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include #include #include #include #include #include #include "PNL_PippardFitter.h" #ifdef HAVE_DNLF_CONFIG_H #include "dnlf_config.h" #endif //----------------------------------------------------------------------------- /** *

dump_nonlocal_field synatx console output. */ void dnlf_syntax() { std::cout << std::endl; std::cout << "usage: dump_nonlocal_field [ --out [--step ] | --version | --help]" << std::endl; std::cout << " : nonlocal msr-file name." << std::endl; std::cout << " --out : ascii field dump output file name." << std::endl; std::cout << " --range : this optional parameter (in nm) will overwrite the standard z-range = 5 * lambdaL." << std::endl; std::cout << " --step : this optional parameters allows to define the z-value step size in (nm)." << std::endl; std::cout << " --version : dumps the version" << std::endl; std::cout << " --help : will dump this help" << std::endl; std::cout << std::endl << std::endl; } //----------------------------------------------------------------------------- /** *

reads the msr-file and estracts the necessary parameter information. * * @param fln msr-file name * @param param parameter vector needed to calculate the magnetic field * * @return true, if everything went smoothly, false otherwise. */ bool dnlf_read_msr(const std::string fln, std::vector ¶m) { std::ifstream fin(fln.c_str(), std::ifstream::in); if (!fin.is_open()) { std::cerr << std::endl; std::cerr << "**ERROR** couldn't open msr-file: " << fln << std::endl; std::cerr << std::endl; return false; } std::vector msrData; std::string line; while (fin.good()) { std::getline(fin, line); msrData.push_back(line); } fin.close(); // find userFcn line line = ""; for (int i=0; i tok; boost::split(tok, line, boost::is_any_of(" \t"), boost::token_compress_on); std::vector paramIdx; int ival; for (int i=0; i paramMap; double dval; for (int i=0; isecond; else dval = 0.0; param.push_back(dval); } return true; } int main(int argc, char* argv[]) { std::string msrFileName(""); std::string outFileName(""); double step{0.0}; double range{0.0}; bool show_syntax(false); if (argc == 1) { dnlf_syntax(); return 0; } for (int i=0; i" << std::endl; show_syntax = true; break; } } else if (!strcmp(argv[i], "--range")) { if (i < argc-1) { try { range = std::stod(argv[i+1]); } catch(std::exception& e) { std::cout << "dump_nonlocal_field: **ERROR** '" << argv[i+1] << "' seems not to be a double." << std::endl; show_syntax = true; break; } i++; } else { std::cerr << std::endl << "dump_nonlocal_field: **ERROR** found option --range without " << std::endl; show_syntax = true; break; } } else if (!strcmp(argv[i], "--step")) { if (i < argc-1) { try { step = std::stod(argv[i+1]); } catch(std::exception& e) { std::cout << "dump_nonlocal_field: **ERROR** '" << argv[i+1] << "' seems not to be a double." << std::endl; show_syntax = true; break; } i++; } else { std::cerr << std::endl << "dump_nonlocal_field: **ERROR** found option --step without " << std::endl; show_syntax = true; break; } } } if (show_syntax) { dnlf_syntax(); return -1; } std::vector param; if (!dnlf_read_msr(msrFileName, param)) { return -2; } // calculate field and write it to file PNL_PippardFitterGlobal pip; if (pip.IsValid()) pip.CalculateField(param); else return -3; std::ofstream fout(outFileName.c_str(), std::ofstream::out); if (!fout.is_open()) { std::cout << std::endl; std::cerr << "**ERROR** can not write to file '" << outFileName << "'." << std::endl; std::cout << std::endl; return -4; } // write header fout << "% z (nm), field (G)" << std::endl; // write data double z=0.0; if (step == 0.0) step = 0.1; double prevField=0.0, field=0.0; bool done(false); double deadLayer = param[8]; double b0 = param[6]; if (range == 0.0) range = 5.0*param[5]; // 5*lambda do { if (z < deadLayer) { fout << z << ", " << b0 << std::endl; } else { field = pip.GetMagneticField(z-deadLayer); fout << z << ", " << b0*field << std::endl; if ((fabs(prevField-field) < 1.0e-10) && (z >= range)) done = true; prevField = field; } z += step; } while (!done); fout.close(); return 0; }