Bsoft  2.1.0
Bernard's software package
rwmodel_vega.cpp
Go to the documentation of this file.
1 
9 #include "rwmodel.h"
10 #include "utilities.h"
11 #include <fstream>
12 
13 // Declaration of global variables
14 extern int verbose; // Level of output to the screen
15 
22 {
23  int i, n, m, l1, l2, l3, readflag;
24  float x, y, z;
25  Bmodel* model = NULL;
26  Bmodel* mp = NULL;
27  Bcomponent* comp = NULL;
28  Blink* link = NULL;
29  Bstring id;
30  Bstring comptype("VER");
31  Bstring* filename;
32  ifstream fmod;
33  char aline[200];
34  Bcomponent** car;
35 
36  for ( i=1, filename = file_list; filename; filename = filename->next, i++ ) {
37  if ( verbose & VERB_LABEL )
38  cout << "Reading file: " << *filename << endl;
39  fmod.open(filename->c_str());
40  if ( fmod.fail() ) return NULL;
41  readflag = m = 0;
42 // while ( fmod.getline(aline, 200) != NULL ) {
43  while ( fmod.getline(aline, 200) && fmod.good() ) {
44  if ( readflag ) {
45  sscanf(aline, "%d %f %f %f %d %d %d", &n, &x, &y, &z, &l1, &l2, &l3);
46  if ( n > 0 ) {
47  id = Bstring(n, "%d");
48  comp = component_add(&comp, id);
49  if ( !mp->comp ) mp->comp = comp;
50  comp->loc = Vector3<float>(x, y, z);
51  comp->flag[0] = l1; // The flags carry the indices of the linked components
52  comp->flag[1] = l2;
53  comp->flag[2] = l3;
54  comp->sel = n;
55  comp->type = model_add_type_by_id(mp, comptype);
56  if ( m < n ) m = n;
57  } else readflag = 0;
58  }
59  if ( strstr(aline, "writegraph3d planar") ) {
60  link = NULL;
61  comp = NULL;
62  id = Bstring(i, "%d");
63  mp = model_add(&mp, id);
64  if ( !model ) model = mp;
65  mp->type_id = mp->id;
66  readflag = 1;
67  }
68  }
69  fmod.close();
70  m++;
71  car = new Bcomponent*[m];
72  for ( comp = mp->comp; comp; comp = comp->next ) car[comp->sel] = comp;
73  for ( comp = mp->comp; comp; comp = comp->next ) {
74  for ( n=0; n<MAXLINK && comp->flag[n]>0; n++ ) {
75  comp->link[n] = car[comp->flag[n]];
76  if ( comp->sel < comp->flag[n] ) {
77  link = link_add(&link, comp, comp->link[n], 0, 1);
78  if ( !mp->link ) mp->link = link;
79  }
80  comp->flag[n] = 1; // flag=1 indicates a link
81  }
82  comp->sel = 1;
83  }
84  delete[] car;
85  }
86 
87  return model;
88 }
89 
97 {
98  int n;
99  Bmodel* mp = NULL;
100  Bcomponent* comp;
101  Bstring onename;
102 
103  ofstream fmod;
104 
105  for ( n=0, mp = model; mp; mp = mp->next, n++ ) {
106  if ( model->next )
107  onename = filename.pre_rev('.') + Bstring(n+1, "_%04d.") + filename.post_rev('.');
108  else
109  onename = filename;
110  fmod.open(onename.c_str());
111  if ( fmod.fail() ) return -1;
112  fmod << ">>writegraph3d planar <<" << endl;
113  for ( comp = mp->comp; comp; comp = comp->next )
114  fmod << comp->id.integer() << " " <<
115  comp->loc[0] << " " << comp->loc[1] << " " << comp->loc[2] << " " <<
116  comp->link[0]->id.integer() << " " << comp->link[1]->id.integer() << " " << comp->link[2]->id.integer() << endl;
117  fmod << "0" << endl;
118  fmod.close();
119  }
120 
121  return 0;
122 }
Bcomponent::next
Bcomponent * next
Definition: rwmodel.h:52
Bcomponent
Definition: rwmodel.h:51
rwmodel.h
Header file for reading and writing atomic model files.
Bcomponent::loc
Vector3< float > loc
Definition: rwmodel.h:58
Bstring
Definition: Bstring.h:29
Bcomponent::id
Bstring id
Definition: rwmodel.h:53
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:436
Bstring::integer
long integer()
Definition: Bstring.cpp:547
component_add
Bcomponent * component_add(Bcomponent **comp, Bstring &id)
Adds a component to a linked list.
Definition: rwmodel.cpp:270
Vector3< float >
link_add
Blink * link_add(Blink **link, Bcomponent *comp1, Bcomponent *comp2, double length, double radius)
Adds a component link to a linked list.
Definition: rwmodel.cpp:318
Bmodel::next
Bmodel * next
Definition: rwmodel.h:120
write_model_vega
int write_model_vega(Bstring &filename, Bmodel *model)
Writes Vega model parameters.
Definition: rwmodel_vega.cpp:96
Bmodel::link
Blink * link
Definition: rwmodel.h:133
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
verbose
int verbose
Bmodel::comp
Bcomponent * comp
Definition: rwmodel.h:132
read_model_vega
Bmodel * read_model_vega(Bstring *file_list)
Reads Vega model parameters.
Definition: rwmodel_vega.cpp:21
Bmodel::id
Bstring id
Definition: rwmodel.h:121
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
Bcomponent::flag
int flag[MAXLINK]
Definition: rwmodel.h:57
Bmodel
Definition: rwmodel.h:119
utilities.h
Header file for general utilities.
Bcomponent::type
Bcomptype * type
Definition: rwmodel.h:54
model
Bmodel * model
Definition: bshow.cpp:34
Bstring::next
Bstring * next
Definition: Bstring.h:31
model_add
Bmodel * model_add(Bmodel **model, Bstring &id)
Adds a model to a linked list.
Definition: rwmodel.cpp:181
model_add_type_by_id
Bcomptype * model_add_type_by_id(Bmodel *model, Bstring &id)
Add a type to a model if the identifier does not exist already.
Definition: rwmodel.cpp:414
MAXLINK
#define MAXLINK
Definition: rwmodel.h:14
Bcomponent::link
Bcomponent * link[MAXLINK]
Definition: rwmodel.h:55
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
Bmodel::type_id
Bstring type_id
Definition: rwmodel.h:122
Bcomponent::sel
int sel
Definition: rwmodel.h:66