| Bsoft 2.0.5 Bernard's software package

Functions | Variables
rwmodel.cpp File Reference

Library routines to read and write atomic model parameters. More...

`#include "rwmodel.h"`
`#include "rwmodel_star.h"`
`#include "rwmodel_xml.h"`
`#include "rwmodel_cmm.h"`
`#include "rwmodel_bild.h"`
`#include "rwmodel_mol.h"`
`#include "rwmodel_vega.h"`
`#include "model_links.h"`
`#include "file_util.h"`
`#include "linked_list.h"`
`#include "Color.h"`
`#include "utilities.h"`

Go to the source code of this file.

## Functions
Bmodel * | read_model (Bstring &filename)
Bmodel * | read_model (Bstring *file_list)
Bmodel * | read_model (Bstring &filename, Bstring &paramfile)
Bmodel * | read_model (Bstring *file_list, Bstring &paramfile)
| Reads model parameters. More...
int | write_model (Bstring &filename, Bmodel *model)
| Writes model parameters. More...
Bmodel * | model_init (Bstring &id)
| Initializes a model structure. More...
Bmodel * | model_init (const char *cid)
Bmodel * | model_add (Bmodel **model, Bstring &id)
| Adds a model to a linked list. More...
Bmodel * | model_add (Bmodel **model, const char *cid)
Bmodel * | model_add (Bmodel **model, Bmodel *model_nu)
Bcomptype * | component_type_add (Bcomptype **type, Bstring &id)
| Adds a component type to a linked list. More...
Bcomponent * | component_add (Bcomponent **comp, Bstring &id)
| Adds a component to a linked list. More...
Bcomponent * | component_add (Bcomponent **comp, unsigned long number)
Blink * | link_add (Blink **link, Bcomponent *comp1, Bcomponent *comp2, double length, double radius)
| Adds a component link to a linked list. More...
Blink * | link_add (Blink **link, Bcomponent *comp1, Bcomponent *comp2)
int | link_index (Bcomponent *comp, Bcomponent *comp2)
| Returns the index of a linked component. More...
int | model_set_map_filenames (Bmodel *model, Bstring &mapfile)
| Sets all the map file names of selected models. More...
Bcomptype * | model_add_type_by_id (Bmodel *model, Bstring &id)
| Add a type to a model if the identifier does not exist already. More...
Bcomptype * | model_add_type_by_filename (Bmodel *model, Bstring &filename, int num)
| Add a type to a model if the type with the given file name does not exist already. More...
Bcomptype * | model_add_type_by_id_and_filename (Bmodel *model, Bstring &id, Bstring &filename, int num)
| Add a type to a model if the type with the given id and file name does not exist already. More...
Bcomptype * | model_get_type (Bmodel *model, Bstring &id)
| Return the type corresponding to an identifier. More...
int | model_set_type (Bmodel *model, Bstring &set_type)
| Reset the component types. More...
int | model_change_type (Bmodel *model, Bstring &change_type)
| Change a component type name. More...
int | model_count_component_types (Bmodel *model)
| Counts the number of components for each type. More...
int | model_check (Bmodel *model, Bstring path)
| Checks model properties. More...
int | model_component_count (Bmodel *model)
| Counts the total number of components. More...
Bmodel * | model_list_copy (Bmodel *model)
| Copies a model. More...
Bmodel * | model_copy (Bmodel *model)
| Copies a model. More...
int | component_type_copy (Bcomptype *fromct, Bcomptype *toct)
| Copies all elements from one component to another. More...
int | component_copy (Bcomponent *fromcomp, Bcomponent *tocomp)
| Copies all elements from one component to another. More...
long | component_count (Bcomponent *comp)
| Counts the total number of components. More...
Bcomponent * | component_find (Bcomponent *comp, Bstring &id)
| Finds a component in a component list. More...
int | link_copy (Blink *fromlink, Blink *tolink)
| Copies all elements from one link to another. More...
Blink * | link_find (Blink *link, Bcomponent *comp1, Bcomponent *comp2)
| Finds a link in a link list. More...
int | component_kill (Bcomponent *comp)
| Deallocates memory for one component. More...
int | component_list_kill (Bcomponent *comp)
| Deallocates memory for a list of components. More...
int | comp_type_kill (Bcomptype *type)
| Deallocates memory for one component type. More...
int | comp_type_list_kill (Bcomptype *type)
| Deallocates memory for a list of component types. More...
int | model_link_list_kill (Bmodel *model)
| Deallocates memory for a list of component links. More...
int | link_kill (Blink **link_list, Bcomponent *comp, int i)
| Deletes a link. More...
int | link_kill (Blink **link_list, Bcomponent *comp, Bcomponent *comp2)
| Deletes a link. More...
int | poly_list_kill (Bpolygon *poly)
| Deallocates memory for a list of polygons. More...
int | comp_associated_links_kill (Bcomponent *comp, Blink **link)
| Deallocates memory for links associated with a component. More...
int | model_kill (Bmodel *model)
| Deallocates all memory in the list. More...
int | model_update_comment (Bmodel *model, int n, char **strings)
| Puts a set of strings and time in the comment of a model. More...
int | model_associate (Bmodel *model, Bstring &associate_type, Bstring &associate_file)
| Associates a model file with a component type. More...
int | model_associate_mass (Bmodel *model, Bstring &associate_type, double mass)
| Associates a mass with a component type. More...
int | model_set_comptype_filenames (Bmodel *model, Bstring &filename)
| Sets the filenames of all selected component types to the given string. More...
long | model_set_component_radius (Bmodel *model, double comprad)
| Set the display radius for all components to a specific value. More...
long | model_set_density (Bmodel *model, double density)
| Set the density of selected components to a specific value. More...
long | model_set_fom (Bmodel *model, double fom)
| Set the FOM of selected components to a specific value. More...

## Variables
int | verbose

## Detailed Description

Library routines to read and write atomic model parameters.

Author
  Bernard Heymann

Date
  Created: 20060919
  Modified: 20161004

Definition in file rwmodel.cpp.

## Function Documentation

## ◆ comp_associated_links_kill()

int comp_associated_links_kill | ( | Bcomponent * | comp,
|  | Blink ** | link
| ) |  |

Deallocates memory for links associated with a component.

Parameters

  *comp | associated componet.
  **link | pointer to component link list.

Returns
  int number of component links deallocated.

Definition at line 1092 of file rwmodel.cpp.

## ◆ comp_type_kill()

int comp_type_kill | ( | Bcomptype * | type | ) |

Deallocates memory for one component type.

Parameters

  *type | component type.

Returns
  int 0.

Definition at line 912 of file rwmodel.cpp.

## ◆ comp_type_list_kill()

int comp_type_list_kill | ( | Bcomptype * | type | ) |

Deallocates memory for a list of component types.

Parameters

  *type | component type list.

Returns
  int total number of component types.

Definition at line 926 of file rwmodel.cpp.

## ◆ component_add() [1/2]

Bcomponent* component_add | ( | Bcomponent ** | comp,
|  | Bstring & | id
| ) |  |

Adds a component to a linked list.

    The function allocates memory for a new component structure.
    If the content of the pointer is null, the new structure is
    the first in the list. Otherwise, the end of the list is found
    and the new structure added to it.

Parameters

  **comp | component list.
  &id | component identifier.

Returns
  Bcomponent new component.

Definition at line 267 of file rwmodel.cpp.

## ◆ component_add() [2/2]

Bcomponent* component_add | ( | Bcomponent ** | comp,
|  | unsigned long | number
| ) |  |

Definition at line 294 of file rwmodel.cpp.

## ◆ component_copy()

int component_copy | ( | Bcomponent * | fromcomp,
|  | Bcomponent * | tocomp
| ) |  |

Copies all elements from one component to another.

Parameters

  *fromcomp | source component.
  *tocomp | destination component.

Returns
  int 0.

Definition at line 783 of file rwmodel.cpp.

## ◆ component_count()

long component_count | ( | Bcomponent * | comp | ) |

Counts the total number of components.

Parameters

  *comp | component list.

Returns
  long number of components.

Definition at line 805 of file rwmodel.cpp.

## ◆ component_find()

Bcomponent* component_find | ( | Bcomponent * | comp,
|  | Bstring & | id
| ) |  |

Finds a component in a component list.

Parameters

  *comp | starting component.
  &id | component identifier.

Returns
  Bcomponent* component found, NULL otherwise.

Definition at line 822 of file rwmodel.cpp.

## ◆ component_kill()

int component_kill | ( | Bcomponent * | comp | ) |

Deallocates memory for one component.

Parameters

  *comp | component.

Returns
  int 0.

Definition at line 877 of file rwmodel.cpp.

## ◆ component_list_kill()

int component_list_kill | ( | Bcomponent * | comp | ) |

Deallocates memory for a list of components.

Parameters

  *comp | component list.

Returns
  int total number of components.

Definition at line 891 of file rwmodel.cpp.

## ◆ component_type_add()

Bcomptype* component_type_add | ( | Bcomptype ** | type,
|  | Bstring & | id
| ) |  |

Adds a component type to a linked list.

Parameters

  **type | component type list.
  &id | component type identifier.

Returns
  Bcomptype* new component type.

      The function allocates memory for a new component type structure.
      If the content of the pointer is null, the new structure is
      the first in the list. Otherwise, the end of the list is found
      and the new structure added to it.

Definition at line 230 of file rwmodel.cpp.

## ◆ component_type_copy()

int component_type_copy | ( | Bcomptype * | fromct,
|  | Bcomptype * | toct
| ) |  |

Copies all elements from one component to another.

Parameters

  *fromct | source component.
  *toct | destination component.

Returns
  int 0.

Definition at line 763 of file rwmodel.cpp.

## ◆ link_add() [1/2]

Blink* link_add | ( | Blink ** | link,
|  | Bcomponent * | comp1,
|  | Bcomponent * | comp2,
|  | double | length,
|  | double | radius
| ) |  |

Adds a component link to a linked list.

    The function allocates memory for a new link structure.
    If the content of the pointer is null, the new structure is
    the first in the list. Otherwise, the end of the list is found
    and the new structure added to it.

Parameters

  **link | component link list.
  *comp1 | first component.
  *comp2 | second component.
  length | length of link.
  radius | display radius.

Returns
  Bcomponent new component.

Definition at line 315 of file rwmodel.cpp.

## ◆ link_add() [2/2]

Blink* link_add | ( | Blink ** | link,
|  | Bcomponent * | comp1,
|  | Bcomponent * | comp2
| ) |  |

Definition at line 363 of file rwmodel.cpp.

## ◆ link_copy()

int link_copy | ( | Blink * | fromlink,
|  | Blink * | tolink
| ) |  |

Copies all elements from one link to another.

Parameters

  *fromlink | source link.
  *tolink | destination link.

Returns
  int 0.

Definition at line 836 of file rwmodel.cpp.

## ◆ link_find()

Blink* link_find | ( | Blink * | link,
|  | Bcomponent * | comp1,
|  | Bcomponent * | comp2
| ) |  |

Finds a link in a link list.

Parameters

  *link | starting link.
  *comp1 | one component.
  *comp2 | other component.

Returns
  Blink* link found, NULL otherwise.

Definition at line 857 of file rwmodel.cpp.

## ◆ link_index()

int link_index | ( | Bcomponent * | comp,
|  | Bcomponent * | comp2
| ) |  |

Returns the index of a linked component.

Parameters

  *comp | component with list of linked components to be searched.
  *comp2 | component to search for.

Returns
  int link index, -1 if not found.

      If the second component is not found in the list of linked components,
      a -1 is returned.

Definition at line 378 of file rwmodel.cpp.

## ◆ link_kill() [1/2]

int link_kill | ( | Blink ** | link_list,
|  | Bcomponent * | comp,
|  | int | i
| ) |  |

Deletes a link.

    The link in the model link list is removed.
    The associated references to the link in the component link arrays
    are removed and the link arrays reorganized.

Parameters

  **link_list | pointer to list of links.
  *comp | one component in the link.
  i | index for second component in link array of first component.

Returns
  Bdistmat* new distance matrix structure.

Definition at line 988 of file rwmodel.cpp.

## ◆ link_kill() [2/2]

int link_kill | ( | Blink ** | link_list,
|  | Bcomponent * | comp,
|  | Bcomponent * | comp2
| ) |  |

Deletes a link.

    The link in the model link list is removed.
    The associated references to the link in the component link arrays
    are removed and the link arrays reorganized.

Parameters

  **link_list | pointer to list of links.
  *comp | one component in the link.
  *comp2 | second component in the link.

Returns
  Bdistmat* new distance matrix structure.

Definition at line 1051 of file rwmodel.cpp.

## ◆ model_add() [1/3]

Bmodel* model_add | ( | Bmodel ** | model,
|  | Bstring & | id
| ) |  |

Adds a model to a linked list.

Parameters

  **model | model list.
  &id | model identifier.

Returns
  Bmodel* new model.

      The function allocates memory for a new model structure.
      If the content of the pointer is null, the new structure is
      the first in the list. Otherwise, the end of the list is found
      and the new structure added to it.

Definition at line 178 of file rwmodel.cpp.

## ◆ model_add() [2/3]

Bmodel* model_add | ( | Bmodel ** | model,
|  | const char * | cid
| ) |  |

Definition at line 196 of file rwmodel.cpp.

## ◆ model_add() [3/3]

Bmodel* model_add | ( | Bmodel ** | model,
|  | Bmodel * | model_nu
| ) |  |

Definition at line 205 of file rwmodel.cpp.

## ◆ model_add_type_by_filename()

Bcomptype* model_add_type_by_filename | ( | Bmodel * | model,
|  | Bstring & | filename,
|  | int | num
| ) |  |

Add a type to a model if the type with the given file name does not exist already.

Parameters

  *model | model parameters.
  &filename | model file to check for and add.
  num | model number within file.

Returns
  Bcomptype* type identifier.

Definition at line 434 of file rwmodel.cpp.

## ◆ 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.

Parameters

  *model | model parameters.
  &id | component type identifier to check for and add.

Returns
  Bcomptype* type identifier.

Definition at line 411 of file rwmodel.cpp.

## ◆ model_add_type_by_id_and_filename()

Bcomptype* model_add_type_by_id_and_filename | ( | Bmodel * | model,
|  | Bstring & | id,
|  | Bstring & | filename,
|  | int | num
| ) |  |

Add a type to a model if the type with the given id and file name does not exist already.

Parameters

  *model | model parameters.
  &id | component type identifier to check for and add.
  &filename | model file to check for and add.
  num | model number within file.

Returns
  Bcomptype* type identifier.

Definition at line 465 of file rwmodel.cpp.

## ◆ model_associate()

int model_associate | ( | Bmodel * | model,
|  | Bstring & | associate_type,
|  | Bstring & | associate_file
| ) |  |

Associates a model file with a component type.

Parameters

  *model | the model.
  &associate_type | component type.
  &associate_file | component file name.

Returns
  int number of types associated.

      Model files can be coordinates or maps.

Definition at line 1177 of file rwmodel.cpp.

## ◆ model_associate_mass()

int model_associate_mass | ( | Bmodel * | model,
|  | Bstring & | associate_type,
|  | double | mass
| ) |  |

Associates a mass with a component type.

Parameters

  *model | model list.
  &associate_type | component type.
  mass | component type mass.

Returns
  int number of types associated.

Definition at line 1207 of file rwmodel.cpp.

## ◆ model_change_type()

int model_change_type | ( | Bmodel * | model,
|  | Bstring & | change_type
| ) |  |

Change a component type name.

Parameters

  *model | model.
  &change_type | component type.

Returns
  int number of models.

      Sets all the component types to the given string.

Definition at line 545 of file rwmodel.cpp.

## ◆ model_check()

int model_check | ( | Bmodel * | model,
|  | Bstring | path
| ) |  |

Checks model properties.

Parameters

  *model | model.
  path | search path to find map files.

Returns
  int 0.

Definition at line 592 of file rwmodel.cpp.

## ◆ model_component_count()

int model_component_count | ( | Bmodel * | model | ) |

Counts the total number of components.

Parameters

  *model | model parameters.

Returns
  int 0.

Definition at line 635 of file rwmodel.cpp.

## ◆ model_copy()

Bmodel* model_copy | ( | Bmodel * | model | ) |

Copies a model.

Parameters

  *model | model parameters.

Returns
  Bmodel* model copy.

      Copies only the first model in the list.

Definition at line 685 of file rwmodel.cpp.

## ◆ model_count_component_types()

int model_count_component_types | ( | Bmodel * | model | ) |

Counts the number of components for each type.

Parameters

  *model | model.

Returns
  int 0.

Definition at line 568 of file rwmodel.cpp.

## ◆ model_get_type()

Bcomptype* model_get_type | ( | Bmodel * | model,
|  | Bstring & | id
| ) |  |

Return the type corresponding to an identifier.

Parameters

  *model | model parameters.
  &id | component identifier to check for and add.

Returns
  Bcomptype* component type.

Definition at line 491 of file rwmodel.cpp.

## ◆ model_init() [1/2]

Bmodel* model_init | ( | Bstring & | id | ) |

Initializes a model structure.

Parameters

  &id | model identifier.

Returns
  Bmodel* new model structure.

Definition at line 144 of file rwmodel.cpp.

## ◆ model_init() [2/2]

Bmodel* model_init | ( | const char * | cid | ) |

Definition at line 157 of file rwmodel.cpp.

## ◆ model_kill()

int model_kill | ( | Bmodel * | model | ) |

Deallocates all memory in the list.

Parameters

  *model | model parameters.

Returns
  int 0.

Definition at line 1124 of file rwmodel.cpp.

## ◆ model_link_list_kill()

int model_link_list_kill | ( | Bmodel * | model | ) |

Deallocates memory for a list of component links.

    Only the first model in the list is processed.

Parameters

  *model | model.

Returns
  int total number of component links.

Definition at line 950 of file rwmodel.cpp.

## ◆ model_list_copy()

Bmodel* model_list_copy | ( | Bmodel * | model | ) |

Copies a model.

    Copies all the models in a list.

Parameters

  *model | model parameters.

Returns
  Bmodel* model copy.

Definition at line 657 of file rwmodel.cpp.

## ◆ model_set_component_radius()

long model_set_component_radius | ( | Bmodel * | model,
|  | double | comprad
| ) |  |

Set the display radius for all components to a specific value.

Parameters

  *model | model parameters.
  comprad | component display radius.

Returns
  long number of components selected.

Definition at line 1264 of file rwmodel.cpp.

## ◆ model_set_comptype_filenames()

int model_set_comptype_filenames | ( | Bmodel * | model,
|  | Bstring & | filename
| ) |  |

Sets the filenames of all selected component types to the given string.

Parameters

  *model | model parameters.
  &filename | component file name.

Returns
  int number of component types set.

      The image numbers are sequentially set as well.

Definition at line 1239 of file rwmodel.cpp.

## ◆ model_set_density()

long model_set_density | ( | Bmodel * | model,
|  | double | density
| ) |  |

Set the density of selected components to a specific value.

Parameters

  *model | model parameters.
  density | new density value.

Returns
  long number of components selected.

Definition at line 1285 of file rwmodel.cpp.

## ◆ model_set_fom()

long model_set_fom | ( | Bmodel * | model,
|  | double | fom
| ) |  |

Set the FOM of selected components to a specific value.

Parameters

  *model | model parameters.
  fom | new FOM value.

Returns
  long number of components selected.

Definition at line 1306 of file rwmodel.cpp.

## ◆ model_set_map_filenames()

int model_set_map_filenames | ( | Bmodel * | model,
|  | Bstring & | mapfile
| ) |  |

Sets all the map file names of selected models.

Parameters

  *model | model parameters.
  &mapfile | map file name.

Returns
  int 0.

Definition at line 395 of file rwmodel.cpp.

## ◆ model_set_type()

int model_set_type | ( | Bmodel * | model,
|  | Bstring & | set_type
| ) |  |

Reset the component types.

Parameters

  *model | model.
  &set_type | component type.

Returns
  int number of models.

      Sets all the component types to the given string.

Definition at line 516 of file rwmodel.cpp.

## ◆ model_update_comment()

int model_update_comment | ( | Bmodel * | model,
|  | int | n,
|  | char ** | strings
| ) |  |

Puts a set of strings and time in the comment of a model.

Parameters

  *model | the model.
  n | the number of strings.
  **strings | an array of strings.

Returns
  int string length of the new comment.

      This is designed to pack the command line into a string followed by
      a second string for the time.

Definition at line 1158 of file rwmodel.cpp.

## ◆ poly_list_kill()

int poly_list_kill | ( | Bpolygon * | poly | ) |

Deallocates memory for a list of polygons.

Parameters

  *poly | polygon list.

Returns
  int total number of polygons.

Definition at line 1070 of file rwmodel.cpp.

## ◆ read_model() [1/4]

Bmodel* read_model | ( | Bstring & | filename | ) |

Definition at line 28 of file rwmodel.cpp.

## ◆ read_model() [2/4]

Bmodel* read_model | ( | Bstring * | file_list | ) |

Definition at line 33 of file rwmodel.cpp.

## ◆ read_model() [3/4]

Bmodel* read_model | ( | Bstring & | filename,
|  | Bstring & | paramfile
| ) |  |

Definition at line 39 of file rwmodel.cpp.

## ◆ read_model() [4/4]

Bmodel* read_model | ( | Bstring * | file_list,
|  | Bstring & | paramfile
| ) |  |

Reads model parameters.

Parameters

  *file_list | list of model parameter file names.
  &paramfile | parameter file.

Returns
  Bmodel* model parameters.

Definition at line 50 of file rwmodel.cpp.

## ◆ write_model()

int write_model | ( | Bstring & | filename,
|  | Bmodel * | model
| ) |  |

Writes model parameters.

Parameters

  &filename | model parameter file name.
  *model | model parameters.

Returns
  int number of models.

Definition at line 91 of file rwmodel.cpp.

## Variable Documentation

## ◆ verbose

int verbose