00001 #include "Translate/MAD8Parser.hpp"
00002
00003 using namespace std;
00004 using namespace BasicUtilities;
00005
00006
00007
00008
00009 MAD8Parser::MAD8Parser() : TranslateCore() {
00010 language = "MAD8";
00011 include_file_string = "call:filename";
00012 continuation_char = "&";
00013 c_style_format = false;
00014 knl_tn_style_multipoles = true;
00015 abbreviations_permitted = true;
00016 init_lists_mad8();
00017 init_lists_mad();
00018 init_lists_core();
00019 }
00020
00021
00022
00023
00024 bool MAD8Parser::custom_x_statement_to_x (StrList word_list, string comment,
00025 UAPNode* x_rep_root) {
00026
00027
00028
00029
00030 if (word_list.size() < 3) return false;
00031 string word1 = next_word(word_list);
00032 string word2 = next_word(word_list);
00033 string word3 = next_word(word_list);
00034
00035
00036
00037 if (word1 == "use") {
00038 if (!word_list.size() == 0 || word2 != ",") {
00039 info_out.error ("Malformed USE Statement");
00040 return true;
00041 }
00042 UAPNode* node = x_rep_root->addChild(word1);
00043 node->addAttribute("line", word3);
00044 return true;
00045 }
00046
00047 return false;
00048
00049 }
00050
00051
00052
00053
00054 bool MAD8Parser::custom_aml_node_to_x (UAPNode* aml_ele, UAPNode* x_rep) {
00055
00056
00057
00058
00059
00060 return false;
00061
00062 }
00063
00064
00065
00066
00067 bool MAD8Parser::custom_aml_element_attribute_to_x(UAPNode* aml_root, UAPNode* aml_ele,
00068 UAPNode* aml_attrib, UAPNode* x_ele) {
00069
00070 string aml_parent_name = aml_ele->getName();
00071 string ele_name = x_ele->getAttributeString("name");
00072 string aml_attrib_name = aml_attrib->getName();
00073 string aml_attrib_value = aml_attrib->getAttributeString("design");
00074
00075
00076
00077 return false;
00078
00079 }
00080
00081
00082
00083
00084 void MAD8Parser::custom2_aml_element_attribute_to_x (UAPNode* aml_ele, UAPNode* x_rep) {
00085
00086 string aml_name = aml_ele->getName();
00087 bool ok;
00088
00089
00090
00091 return;
00092
00093 }
00094
00095
00096
00097
00098 bool MAD8Parser::custom_x_element_to_x_file (UAPNode* x_node, string& comment,
00099 StreamStruct& x_out) {
00100
00101 string x_name = x_node->getName();
00102
00103
00104
00105 if (x_name == "use") {
00106 x_out << "use, " << x_node->getAttributeString("line") << comment << fini;
00107 return true;
00108 }
00109
00110 return false;
00111
00112 }
00113
00114
00115
00116
00117 bool MAD8Parser::custom_x_add_attributes (StrList& word_list, string ele_class,
00118 string& attrib_name, UAPNode* x_ele_root) {
00119
00120
00121
00122
00123 if (ele_class == "matrix" && attrib_name == "tm") {
00124 if (word_list.size() < 8) {
00125 info_out.error ("Malformed matrix tm term.");
00126 return true;
00127 }
00128 string p1 = next_word(word_list);
00129 string i1 = next_word(word_list);
00130 string c1 = next_word(word_list);
00131 string i2 = next_word(word_list);
00132 string c2 = next_word(word_list);
00133 string i3 = next_word(word_list);
00134 string p2 = next_word(word_list);
00135
00136 bool ok1, ok2, ok3;
00137 int i_1 = string_to_int (i1, ok1);
00138 int i_2 = string_to_int (i1, ok2);
00139 int i_3 = string_to_int (i1, ok3);
00140
00141 if (!ok1 || !ok2 || !ok3 ||
00142 i_1 < 1 || i_1 > 6 || i_2 < 1 || i_2 > 6 || i_3 < 1 || i_3 > 6 ||
00143 p1 != "(" || c1 != "," || c2 != "," || p2 != ")") {
00144 info_out.error ("Bad \"tm(...) =\" in matrix element.");
00145 return true;
00146 }
00147 attrib_name = "tm" + i1 + i2 + i3;
00148 return false;
00149 }
00150
00151
00152
00153 if (ele_class == "matrix" && attrib_name == "rm") {
00154 if (word_list.size() < 6) {
00155 info_out.error ("Malformed matrix rm term.");
00156 return true;
00157 }
00158 string p1 = next_word(word_list);
00159 string i1 = next_word(word_list);
00160 string c1 = next_word(word_list);
00161 string i2 = next_word(word_list);
00162 string p2 = next_word(word_list);
00163
00164 bool ok1, ok2;
00165 int i_1 = string_to_int (i1, ok1);
00166 int i_2 = string_to_int (i1, ok2);
00167
00168 if (!ok1 || !ok2 ||
00169 i_1 < 1 || i_1 > 6 || i_2 < 1 || i_2 > 6 ||
00170 p1 != "(" || c1 != "," || p2 != ")") {
00171 info_out.error ("Bad \"rm(...) =\" in matrix element.");
00172 return true;
00173 }
00174 attrib_name = "rm" + i1 + i2;
00175 return false;
00176 }
00177
00178 return false;
00179
00180 }
00181
00182
00183
00184
00185 void MAD8Parser::custom_x_attrib_to_x_file_translate (string& attrib_name,
00186 string& attrib_value) {
00187
00188 if (!found(map_element_to_attribs["matrix"], attrib_name)) return;
00189
00190 if (attrib_name.substr(0,2) == "rm") {
00191 attrib_name = "rm(" + attrib_name.substr(2,1) + "," + attrib_name.substr(3,1) + ")";
00192 }
00193
00194 if (attrib_name.substr(0,2) == "tm") {
00195 attrib_name = "tm(" + attrib_name.substr(2,1) + "," +
00196 attrib_name.substr(3,1) + "," + attrib_name.substr(4,1) + ")";
00197
00198 }
00199
00200 }
00201
00202
00203
00204
00205 void MAD8Parser::init_lists_mad8 () {
00206
00207 StrVec multipole_attrib;
00208 multipole_attrib << "l" << "tilt" << "k0l" << "k1l"
00209 << "k2l" << "k3l" << "k4l" << "k5l" << "k6l" << "k7l" << "k8l" << "k9l"
00210 << "k10l" << "k11l" << "k12l" << "k13l" << "k14l" << "k15l" << "k16l" << "k17l"
00211 << "k18l" << "k19l" << "k20l" << "t0" << "t1" << "t2" << "t3" << "t4"
00212 << "t5" << "t6" << "t7" << "t8" << "t9" << "t10" << "t11" << "t12"
00213 << "t13" << "t14" << "t15" << "t16" << "t17" << "t18" << "t19" << "t20"
00214 << "lrad" << "type" << "at";
00215 map_element_to_attribs["multipole"] = multipole_attrib;
00216
00217 StrVec matrix_attrib;
00218 matrix_attrib << "type";
00219 for (int i = 1; i < 7; i++) {
00220 ostringstream iss; iss << i;
00221 for (int j = 1; j < 7; j++) {
00222 ostringstream jss; jss << j;
00223 matrix_attrib << "rm" + iss.str() + jss.str();
00224 for (int k = 1; k < 7; k++) {
00225 ostringstream kss; kss << k;
00226 matrix_attrib << "tm" + iss.str() + jss.str() + kss.str();
00227 }
00228 }
00229 }
00230 map_element_to_attribs["matrix"] = matrix_attrib;
00231
00232 register_attribute("lcavity:volt", "rf_cavity:gradient", "# * 1e6 / ![length]",
00233 "# * ![l] / 1e6");
00234 register_attribute("lcavity:lag", "rf_cavity:phase0", "# * twopi", "# / twopi");
00235 register_attribute("rfcavity:volt", "rf_cavity:gradient", "# * 1e6 / ![length]",
00236 "# * ![l] / 1e6");
00237 register_attribute("rfcavity:lag", "rf_cavity:phase0", "# * twopi", "# / twopi");
00238 register_attribute("rfcavity:freq", "rf_cavity:rf_freq", "# * 1e9", "# / 1e9");
00239
00240 register_attribute("e", "electric_kicker:y_kick_u", "# * 1e6 / ![length]", "# * ![l] / 1e6");
00241
00242 return;
00243
00244 }