26 int project_to_xml(
Bproject*
project, xmlDocPtr doc,
int mg_select,
int rec_select);
28 xmlNodePtr particle_to_xml(
Bparticle* part, xmlNodePtr parent,
int euler_flag,
int omega_flag,
FOMType fom_tag[
NFOM]);
40 if ( filename.
length() < 1 ) {
41 error_show(
"No file names found!", __FILE__, __LINE__);
51 doc = xmlParseFile(filename.
c_str());
52 if (doc == NULL)
return -1;
55 cout <<
"# Reading XML file: " << filename << endl;
57 node = xmlDocGetRootElement(doc);
64 if ( xmlStrcmp(node->name, (
const xmlChar *)
PROJECT) ) {
65 cerr <<
"Error: The document " << filename <<
" is not a micrograph parameter file!" << endl;
73 err = xml_to_project(doc,
project, filename);
85 error_show(
"No file names found!", __FILE__, __LINE__);
94 cout <<
"DEBUG read_project_xml: XML filenames:" << endl;
95 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next )
96 cout <<
" " << *thisfile;
100 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next ) {
109 if ( filename.
length() < 1 ) {
110 error_show(
"No file name found!", __FILE__, __LINE__);
117 doc = xmlParseFile(filename.
c_str());
118 if (doc == NULL)
return NULL;
121 cout <<
"# Reading XML file: " << filename << endl;
123 node = xmlDocGetRootElement(doc);
124 if ( node == NULL ) {
130 if ( xmlStrcmp(node->name, (
const xmlChar *)
PARTICLE) ) {
131 cerr <<
"Error: The document " << filename <<
" is not a particle parameter file!" << endl;
136 Bparticle* part = particle_from_xml(node, partlist, fom_tag);
146 cerr <<
"Error: XML files are not supported!" << endl << endl;
160 #if defined(HAVE_XML)
177 for ( mg=field->
mg; mg; mg=mg->
next, i++ ) {
179 name = mg->
id +
".xml";
185 cout <<
"# Writing file: " << name << endl;
186 doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
188 cerr <<
"Error: The XML document tree was not created!" << endl;
191 err = project_to_xml(
project, doc, i, 0);
193 err = xmlSaveFormatFile(name.
c_str(), doc, 1);
199 name = rec->
id +
".xml";
205 cout <<
"# Writing file: " << name << endl;
206 doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
208 cerr <<
"Error: The XML document tree was not created!" << endl;
211 err = project_to_xml(
project, doc, 0, i);
213 err = xmlSaveFormatFile(name.
c_str(), doc, 1);
218 cout <<
"# Writing file: " << filename << endl;
219 doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
221 cerr <<
"Error: The XML document tree was not created!" << endl;
224 err = project_to_xml(
project, doc, 0, 0);
226 err = xmlSaveFormatFile(filename.
c_str(), doc, 1);
235 xmlDocPtr doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
236 if (doc == NULL)
return -1;
239 cout <<
"# Writing XML file: " << filename << endl;
241 xmlNodePtr node = xmlNewDocPI(doc, BAD_CAST
"xml-stylesheet",
242 BAD_CAST
"href=\"Bsoft_particle.xsl\" type=\"text/xsl\"");
243 xmlDocSetRootElement(doc, node);
245 xmlNodePtr part_node = particle_to_xml(part, NULL, euler_flag, omega_flag, fom_tag);
248 xmlAddSibling(node, part_node);
250 if ( xmlSaveFormatFile(filename.
c_str(), doc, 1) < 0 )
251 cerr <<
"Error: XML file " << filename <<
" not written!" << endl;
260 cerr <<
"Error: XML files are not supported!" << endl << endl;
268 CTFparam* ctf_from_xml(xmlNodePtr node)
296 Bframe* frame_from_xml(xmlNodePtr node,
Bframe** framelist)
301 frame_id = xmlGetProp(node, BAD_CAST
ID);
302 frame =
frame_add(framelist, atoi((
char *) frame_id));
304 if ( !frame )
return frame;
316 int f, euler_flag, omega_flag;
322 part_id = xmlGetProp(node, BAD_CAST
ID);
325 if ( !part )
return part;
343 if ( euler_flag == 0 ) {
358 for ( f=0; f<
NFOM; f++ )
if ( fom_tag[f] ) {
370 xmlNodePtr fnode_node = NULL;
374 fil_id = xmlGetProp(node, BAD_CAST
ID);
377 for ( fnode_node = node->xmlChildrenNode; fnode_node; fnode_node = fnode_node->next ) {
378 if ( !xmlStrcmp(fnode_node->name, BAD_CAST
FILAMENT_NODE) ) {
379 fil_id = xmlGetProp(node, BAD_CAST
ID);
407 mark_id = xmlGetProp(node, BAD_CAST
ID);
408 mark->
id = atoi((
char *) mark_id);
449 line->
fom = line->
sel = 1;
482 xmlChar *xstring, *id;
486 xmlNodePtr project_node = xmlDocGetRootElement(doc);
487 xmlNodePtr child_node = NULL;
488 xmlNodePtr mg_node = NULL;
489 xmlNodePtr node = NULL;
500 for ( i=0, child_node = project_node->xmlChildrenNode; child_node; child_node = child_node->next ) {
502 if ( !xmlStrcmp(child_node->name, BAD_CAST
COMMENT) )
506 if ( !xmlStrcmp(child_node->name, BAD_CAST
MAP_REFERENCE) ) {
507 xstring = xmlNodeGetContent(child_node);
512 if ( !xmlStrcmp(child_node->name, BAD_CAST
FIELD) ) {
513 id = xmlGetProp(child_node, BAD_CAST
ID);
516 if ( field->
id == bid )
break;
519 for ( mg_node = child_node->xmlChildrenNode; mg_node; mg_node = mg_node->next ) {
520 if ( !xmlStrcmp(mg_node->name, BAD_CAST
MICROGRAPH) ) {
521 id = xmlGetProp(mg_node, BAD_CAST
ID);
575 mg->
ctf = ctf_from_xml(mg_node);
600 for ( node = mg_node->xmlChildrenNode; node; node = node->next ) {
602 frame_from_xml(node, &mg->
frame);
603 if ( !xmlStrcmp(node->name, BAD_CAST
PARTICLE) )
605 if ( !xmlStrcmp(node->name, BAD_CAST
FILAMENT) )
606 filament_from_xml(node, &mg->
fil);
608 badarea_from_xml(node, &mg->
bad);
609 if ( !xmlStrcmp(node->name, BAD_CAST
MARKER) )
610 marker_from_xml(node, &mg->
mark);
611 if ( !xmlStrcmp(node->name, BAD_CAST
REFLEX) )
612 strucfac_from_xml(node, &mg->
sf);
613 if ( !xmlStrcmp(node->name, BAD_CAST
LAYERLINE) )
614 layerline_from_xml(node, &mg->
layer);
618 }
else if ( !xmlStrcmp(child_node->name, BAD_CAST
MAP) ) {
619 id = xmlGetProp(child_node, BAD_CAST
ID);
646 rec->
ctf = ctf_from_xml(child_node);
672 for ( node = child_node->xmlChildrenNode; node; node = node->next ) {
673 if ( !xmlStrcmp(node->name, BAD_CAST
PARTICLE) )
675 if ( !xmlStrcmp(node->name, BAD_CAST
FILAMENT) )
676 filament_from_xml(node, &rec->
fil);
678 badarea_from_xml(node, &rec->
bad);
679 if ( !xmlStrcmp(node->name, BAD_CAST
MARKER) )
680 marker_from_xml(node, &rec->
mark);
681 if ( !xmlStrcmp(node->name, BAD_CAST
REFLEX) )
682 strucfac_from_xml(node, &rec->
sf);
684 }
else if ( !xmlStrcmp(child_node->name, BAD_CAST
CLASS_AVERAGE) ) {
685 for ( node = child_node->xmlChildrenNode; node; node = node->next )
686 if ( !xmlStrcmp(node->name, BAD_CAST
PARTICLE) )
694 int ctf_to_xml(
CTFparam* ctf, xmlNodePtr parent)
696 if ( !ctf )
return -1;
722 int frame_to_xml(
Bframe* framelist, xmlNodePtr parent)
726 xmlNodePtr frame_node = NULL;
728 for ( frame=framelist; frame; frame=frame->
next, nframe++ ) {
740 xmlNodePtr particle_to_xml(
Bparticle* part, xmlNodePtr parent,
int euler_flag,
int omega_flag,
FOMType fom_tag[
NFOM])
746 xmlNodePtr part_node = NULL;
748 if ( parent ) part_node = xmlNewChild(parent, NULL, BAD_CAST
PARTICLE, NULL);
749 else part_node = xmlNewNode(NULL, BAD_CAST
PARTICLE);
774 if ( euler_flag < 1 ) {
781 if ( omega_flag ) euler[0] = -euler.
psi();
787 for ( f=0; f<
NFOM; f++ )
if ( fom_tag[f] ) {
789 if ( strlen(tag) > 1 ) {
799 int filament_to_xml(
Bfilament* fillist, xmlNodePtr parent)
804 xmlNodePtr fil_node = NULL;
805 xmlNodePtr fnode_node = NULL;
807 for ( fil=fillist; fil; fil=fil->
next, nfil++ ) {
808 fil_node = xmlNewChild(parent, NULL, BAD_CAST
FILAMENT, NULL);
810 for ( fnode=fil->
node; fnode; fnode=fnode->
next ) {
811 fnode_node = xmlNewChild(fil_node, NULL, BAD_CAST
FILAMENT_NODE, NULL);
822 int badarea_to_xml(
Bbadarea* badlist, xmlNodePtr parent)
826 xmlNodePtr bad_node = NULL;
828 for ( bad=badlist; bad; bad=bad->
next, nbad++ ) {
829 bad_node = xmlNewChild(parent, NULL, BAD_CAST
PARTICLE_BAD, NULL);
838 int marker_to_xml(
Bmarker* marklist, xmlNodePtr parent)
842 xmlNodePtr mark_node = NULL;
844 for ( mark=marklist; mark; mark=mark->
next, nmark++ ) {
845 mark_node = xmlNewChild(parent, NULL, BAD_CAST
MARKER, NULL);
861 int strucfac_to_xml(
Bstrucfac* sflist, xmlNodePtr parent)
865 xmlNodePtr sf_node = NULL;
867 for ( sf=sflist; sf; sf=sf->
next, nsf++ ) {
868 sf_node = xmlNewChild(parent, NULL, BAD_CAST
REFLEX, NULL);
886 int layerline_to_xml(
Blayerline* linelist, xmlNodePtr parent)
890 xmlNodePtr ll_node = NULL;
892 for ( line=linelist; line; line=line->
next, nll++ ) {
893 ll_node = xmlNewChild(parent, NULL, BAD_CAST
LAYERLINE, NULL);
921 int project_to_xml(
Bproject*
project, xmlDocPtr doc,
int mg_select,
int rec_select)
931 int i, j, sel, npart(0);
933 xmlNodePtr node = xmlNewDocPI(doc, BAD_CAST
"xml-stylesheet",
934 BAD_CAST
"href=\"Bsoft_micrograph.xsl\" type=\"text/xsl\"");
935 xmlDocSetRootElement(doc, node);
937 xmlNodePtr project_node = xmlNewNode(NULL, BAD_CAST
PROJECT);
940 xmlAddSibling(node, project_node);
942 xmlNodePtr field_node = NULL;
943 xmlNodePtr mg_node = NULL;
944 xmlNodePtr rec_node = NULL;
954 if ( mg_select < 0 ) sel = 1;
955 else for ( j=i, mg=field->
mg; mg; mg=mg->
next, j++ )
if ( j==mg_select ) sel = 1;
957 if ( mg_select < 1 ) sel = 1;
958 else for ( mg=field->
mg; mg; mg=mg->
next )
if ( mg->
select ) sel = 1;
961 field_node = xmlNewChild(project_node, NULL, BAD_CAST
FIELD, NULL);
962 xmlNewProp(field_node, BAD_CAST
ID, BAD_CAST field->
id.
c_str());
964 for ( mg=field->
mg; mg; mg=mg->
next, i++ ) {
967 if ( i==mg_select || mg_select < 0 ) sel = 1;
969 if ( mg_select < 1 || mg->select > 0 ) sel = 1;
972 mg_node = xmlNewChild(field_node, NULL, BAD_CAST
MICROGRAPH, NULL);
973 xmlNewProp(mg_node, BAD_CAST
ID, BAD_CAST mg->
id.
c_str());
1035 frame_to_xml(mg->
frame, mg_node);
1036 ctf_to_xml(mg->
ctf, mg_node);
1037 for ( part=mg->
part; part; part=part->
next, npart++ )
1039 filament_to_xml(mg->
fil, mg_node);
1040 badarea_to_xml(mg->
bad, mg_node);
1041 marker_to_xml(mg->
mark, mg_node);
1042 strucfac_to_xml(mg->
sf, mg_node);
1043 layerline_to_xml(mg->
layer, mg_node);
1045 cout <<
"Writing field \"" << field->
id <<
"\", micrograph \""
1046 << mg->
id <<
"\" with " << npart <<
" particles" << endl;
1054 if ( i==rec_select || rec_select < 0 ) sel = 1;
1056 if ( rec_select < 1 || rec->select > 0 ) sel = 1;
1059 rec_node = xmlNewChild(project_node, NULL, BAD_CAST
MAP, NULL);
1060 xmlNewProp(rec_node, BAD_CAST
ID, BAD_CAST rec->
id.
c_str());
1087 ctf_to_xml(rec->
ctf, rec_node);
1102 for ( part=rec->
part; part; part=part->
next, npart++ )
1104 filament_to_xml(rec->
fil, rec_node);
1105 badarea_to_xml(rec->
bad, rec_node);
1106 marker_to_xml(rec->
mark, rec_node);
1107 strucfac_to_xml(rec->
sf, rec_node);
1112 xmlNewChild(project_node, NULL, BAD_CAST
CLASS_AVERAGE, NULL);