usr/kevin/code/develop/sim_gil_obj.c
int gil_react_encode(gil_react_t * pr, u_json_t ** head) {

  u_json_t * jr = NULL;
  u_json_t * jarr = NULL;
  u_json_t * jobj = NULL;

  void * it; /* opaque list iterator */
  int icount;
  gil_stoich_t * ps = NULL;

  dbg_return_if(pr == NULL, -1);
  dbg_return_if(head == NULL, -1);

  dbg_err_if(u_json_new_object(NULL, &jr));
  dbg_err_if(u_json_new_int("Number of Reactants", pr->nreactant, &jobj));
  dbg_err_if(u_json_add(jr, jobj));
  dbg_err_if(u_json_new_int("Number of Products", pr->nproduct, &jobj));
  dbg_err_if(u_json_add(jr, jobj));

  dbg_err_if(u_json_new_array("List of Reactants", &jarr));

  u_list_iforeach(pr->reactants, ps, it, icount) {
    dbg_err_if(gil_stoich_encode(ps, &jobj));
    dbg_err_if(u_json_add(jarr, jobj));
  }

  err_err_ifm(icount != pr->nreactant, "Inconsistent number of reactants");
  dbg_err_if(u_json_add(jr, jarr));

  dbg_err_if(u_json_new_array("List of Products", &jarr));

  u_list_iforeach(pr->products, ps, it, icount) {
    dbg_err_if(gil_stoich_encode(ps, &jobj));
    dbg_err_if(u_json_add(jarr, jobj));
  }

  err_err_ifm(icount != pr->nproduct, "Inconsistent number of products");
  dbg_err_if(u_json_add(jr, jarr));

  dbg_err_if(u_json_new_real("Rate constant", pr->k, &jobj));
  dbg_err_if(u_json_add(jr, jobj));
  *head = jr;

  return 0;

 err:
  u_json_free(jobj);
  u_json_free(jarr);
  u_json_free(jr);

  return -1;
}
/*****************************************************************************
 *
 *  \brief Create json parse tree for a reaction
 *
 *  This returns a pointer to a new u_json_t object which is the
 *  representation of the reaction.
 *
 *  \param pr      a pointer to an existing reaction
 *  \param head    the new object, returned via argument
 *
 *  \retval 0      a success
 *  \retval -1     a failure
 *
 *****************************************************************************/
\brief Create json parse tree for a reaction
This returns a pointer to a new u_json_t object which is the
representation of the reaction.

\param pr      a pointer to an existing reaction
\param head    the new object, returned via argument

\retval 0      a success
\retval -1     a failure
\ brief Create json parse tree for a reaction This returns a pointer to a new u_json_t object which is the representation of the reaction . \ param pr a pointer to an existing reaction \ param head the new object returned via argument \ retval 0 a success \ retval - 1 a failure
int gil_react_encode(gil_react_t * pr, u_json_t ** head) {
  u_json_t * jr = NULL;
  u_json_t * jarr = NULL;
  u_json_t * jobj = NULL;
  void * it; 
  int icount;
  gil_stoich_t * ps = NULL;
  dbg_return_if(pr == NULL, -1);
  dbg_return_if(head == NULL, -1);
  dbg_err_if(u_json_new_object(NULL, &jr));
  dbg_err_if(u_json_new_int("Number of Reactants", pr->nreactant, &jobj));
  dbg_err_if(u_json_add(jr, jobj));
  dbg_err_if(u_json_new_int("Number of Products", pr->nproduct, &jobj));
  dbg_err_if(u_json_add(jr, jobj));
  dbg_err_if(u_json_new_array("List of Reactants", &jarr));
  u_list_iforeach(pr->reactants, ps, it, icount) {
    dbg_err_if(gil_stoich_encode(ps, &jobj));
    dbg_err_if(u_json_add(jarr, jobj));
  }
  err_err_ifm(icount != pr->nreactant, "Inconsistent number of reactants");
  dbg_err_if(u_json_add(jr, jarr));
  dbg_err_if(u_json_new_array("List of Products", &jarr));
  u_list_iforeach(pr->products, ps, it, icount) {
    dbg_err_if(gil_stoich_encode(ps, &jobj));
    dbg_err_if(u_json_add(jarr, jobj));
  }
  err_err_ifm(icount != pr->nproduct, "Inconsistent number of products");
  dbg_err_if(u_json_add(jr, jarr));
  dbg_err_if(u_json_new_real("Rate constant", pr->k, &jobj));
  dbg_err_if(u_json_add(jr, jobj));
  *head = jr;
  return 0;
 err:
  u_json_free(jobj);
  u_json_free(jarr);
  u_json_free(jr);
  return -1;
}
int gil_react_encode ( gil_react_t * pr , u_json_t * * head ) { u_json_t * jr = NULL ; u_json_t * jarr = NULL ; u_json_t * jobj = NULL ; void * it ; int icount ; gil_stoich_t * ps = NULL ; dbg_return_if ( pr == NULL , -1 ) ; dbg_return_if ( head == NULL , -1 ) ; dbg_err_if ( u_json_new_object ( NULL , & jr ) ) ; dbg_err_if ( u_json_new_int ( " " , pr -> nreactant , & jobj ) ) ; dbg_err_if ( u_json_add ( jr , jobj ) ) ; dbg_err_if ( u_json_new_int ( " " , pr -> nproduct , & jobj ) ) ; dbg_err_if ( u_json_add ( jr , jobj ) ) ; dbg_err_if ( u_json_new_array ( " " , & jarr ) ) ; u_list_iforeach ( pr -> reactants , ps , it , icount ) { dbg_err_if ( gil_stoich_encode ( ps , & jobj ) ) ; dbg_err_if ( u_json_add ( jarr , jobj ) ) ; } err_err_ifm ( icount != pr -> nreactant , " " ) ; dbg_err_if ( u_json_add ( jr , jarr ) ) ; dbg_err_if ( u_json_new_array ( " " , & jarr ) ) ; u_list_iforeach ( pr -> products , ps , it , icount ) { dbg_err_if ( gil_stoich_encode ( ps , & jobj ) ) ; dbg_err_if ( u_json_add ( jarr , jobj ) ) ; } err_err_ifm ( icount != pr -> nproduct , " " ) ; dbg_err_if ( u_json_add ( jr , jarr ) ) ; dbg_err_if ( u_json_new_real ( " " , pr -> k , & jobj ) ) ; dbg_err_if ( u_json_add ( jr , jobj ) ) ; * head = jr ; return 0 ; err : u_json_free ( jobj ) ; u_json_free ( jarr ) ; u_json_free ( jr ) ; return -1 ; }
\brief Create json parse tree for a reaction
  This returns a pointer to a new u_json_t object which is the
  representation of the reaction.
\ brief Create json parse tree for a reaction This returns a pointer to a new u_json_t object which is the representation of the reaction .
/* opaque list iterator */