Created
December 8, 2016 06:48
-
-
Save jyoshida-sci/92ae6e1c90f1f56012a61f3f750fcaa7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"driletter": "E", | |
"mod": 1, | |
"pl": 2, | |
"vxmm": 1.1, | |
"vymm": 0.5, | |
"vzmm": 0.006, | |
"nx": 20, | |
"ny": 30, | |
"zu": 0.600, | |
"zl": 0.000, | |
"gksize": 17, | |
"iothre": 3000 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <fstream> | |
#include "..\picojson.h" | |
class ScanParams | |
{ | |
private: | |
std::string driletter; | |
int mod; | |
int pl; | |
double vxmm; | |
double vymm; | |
double vzmm; | |
int nx; | |
int ny; | |
double zu;//upper surface | |
double zl;//lower surface | |
int gksize; | |
int iothre; | |
public: | |
ScanParams(){} | |
~ScanParams(){} | |
bool ReadJSON(char* jsonname){ | |
std::ifstream fs; | |
fs.open(jsonname, std::ios::binary); | |
if (!fs.is_open()) { | |
return false; | |
} | |
picojson::value val; | |
fs >> val; | |
fs.close(); | |
driletter = val.get<picojson::object>()["driletter"].get<std::string>(); | |
mod = int(val.get<picojson::object>()["mod"].get<double>()); | |
pl = int(val.get<picojson::object>()["pl"].get<double>()); | |
vxmm = val.get<picojson::object>()["vxmm"].get<double>(); | |
vymm = val.get<picojson::object>()["vymm"].get<double>(); | |
vzmm = val.get<picojson::object>()["vzmm"].get<double>(); | |
nx = int(val.get<picojson::object>()["nx"].get<double>()); | |
ny = int(val.get<picojson::object>()["ny"].get<double>()); | |
zu = val.get<picojson::object>()["zu"].get<double>(); | |
zl = val.get<picojson::object>()["zl"].get<double>(); | |
gksize = int(val.get<picojson::object>()["gksize"].get<double>()); | |
iothre = int(val.get<picojson::object>()["iothre"].get<double>()); | |
return true; | |
} | |
std::string DriLetter(){return driletter;} | |
int MOD(){ return mod; } | |
int PL(){ return pl; } | |
double VXmm(){ return vxmm; } | |
double VYmm(){ return vymm; } | |
double VZmm(){ return vzmm; } | |
int NX(){ return nx; } | |
int NY(){ return ny; } | |
int NZ(){ return int((zu-zl)/vzmm); } | |
int GKSize(){ return gksize; } | |
int IOThre(){ return iothre; } | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
#include <string> | |
#include <assert.h> | |
#include "ScanParams.h" | |
int main(int argc, char* argv[]){ | |
std::cout << "hello" << std::endl; | |
//assert(false); | |
bool flag; | |
ScanParams sp = ScanParams(); | |
flag = sp.ReadJSON("notexist.json"); | |
assert(flag == false); | |
flag = sp.ReadJSON("params.json"); | |
assert(flag == true); | |
assert(sp.DriLetter() == "E"); | |
assert(sp.MOD() == 1); | |
assert(sp.PL() == 2); | |
std::cout << sp.VXmm() << std::endl; | |
assert(sp.VXmm() == 1.1); | |
assert(sp.NX() == 20); | |
assert(sp.NZ() == 100); | |
assert(sp.GKSize() == 17); | |
assert(sp.IOThre() == 3000); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment