usr/kevin/code/develop/sim_gil_obj.c
int gil_encode(gil_t * pgi, u_json_t * head) {

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

  void * it; /* opaque u_list_t iterator */
  int icount;
  gil_comp_t * pc = NULL;
  gil_react_t * pr = NULL;

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

  dbg_err_if(u_json_new_int("Number of Components", pgi->ncomponent, &jobj));
  dbg_err_if(u_json_add(head, jobj));
  dbg_err_if(u_json_new_int("Number of Reactions", pgi->nreaction, &jobj));
  dbg_err_if(u_json_add(head, jobj));

  /* Components */

  dbg_err_if(u_json_new_array("Components", &jarr));

  u_list_iforeach(pgi->components, pc, it, icount) {
    dbg_err_if(gil_comp_encode(pc, &jobj));
    dbg_err_if(u_json_add(jarr, jobj));
  }

  err_err_ifm(icount != pgi->ncomponent, "Inconsistent component list");
  dbg_err_if(u_json_add(head, jarr));

  /* Reactions */

  dbg_err_if(u_json_new_array("Reactions", &jarr));

  u_list_iforeach(pgi->reactions, pr, it, icount) {
    dbg_err_if(gil_react_encode(pr, &jobj));
    dbg_err_if(u_json_add(jarr, jobj));
  }

  err_err_ifm(icount != pgi->nreaction, "Inconsistent number of reactions");
  dbg_err_if(u_json_add(head, jarr));

  return 0;

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

  return -1;
}
/*****************************************************************************
 *
 *  \brief Produce Create json representation of Gillespie object
 *
 *  \param pgi    existing gillespie object
 *  \param head   existing head of tree
 *
 *  \retval 0     a success
 *  \retval -1    a failure
 *
 *****************************************************************************/
\brief Produce Create json representation of Gillespie object
\param pgi    existing gillespie object
\param head   existing head of tree

\retval 0     a success
\retval -1    a failure
\ brief Produce Create json representation of Gillespie object \ param pgi existing gillespie object \ param head existing head of tree \ retval 0 a success \ retval - 1 a failure
int gil_encode(gil_t * pgi, u_json_t * head) {
  u_json_t * jobj = NULL;
  u_json_t * jarr = NULL;
  void * it; 
  int icount;
  gil_comp_t * pc = NULL;
  gil_react_t * pr = NULL;
  dbg_return_if(pgi == NULL, -1);
  dbg_return_if(head == NULL, -1);
  dbg_err_if(u_json_new_int("Number of Components", pgi->ncomponent, &jobj));
  dbg_err_if(u_json_add(head, jobj));
  dbg_err_if(u_json_new_int("Number of Reactions", pgi->nreaction, &jobj));
  dbg_err_if(u_json_add(head, jobj));
  dbg_err_if(u_json_new_array("Components", &jarr));
  u_list_iforeach(pgi->components, pc, it, icount) {
    dbg_err_if(gil_comp_encode(pc, &jobj));
    dbg_err_if(u_json_add(jarr, jobj));
  }
  err_err_ifm(icount != pgi->ncomponent, "Inconsistent component list");
  dbg_err_if(u_json_add(head, jarr));
  dbg_err_if(u_json_new_array("Reactions", &jarr));
  u_list_iforeach(pgi->reactions, pr, it, icount) {
    dbg_err_if(gil_react_encode(pr, &jobj));
    dbg_err_if(u_json_add(jarr, jobj));
  }
  err_err_ifm(icount != pgi->nreaction, "Inconsistent number of reactions");
  dbg_err_if(u_json_add(head, jarr));
  return 0;
 err:
  u_json_free(jobj);
  u_json_free(jarr);
  return -1;
}
int gil_encode ( gil_t * pgi , u_json_t * head ) { u_json_t * jobj = NULL ; u_json_t * jarr = NULL ; void * it ; int icount ; gil_comp_t * pc = NULL ; gil_react_t * pr = NULL ; dbg_return_if ( pgi == NULL , -1 ) ; dbg_return_if ( head == NULL , -1 ) ; dbg_err_if ( u_json_new_int ( " " , pgi -> ncomponent , & jobj ) ) ; dbg_err_if ( u_json_add ( head , jobj ) ) ; dbg_err_if ( u_json_new_int ( " " , pgi -> nreaction , & jobj ) ) ; dbg_err_if ( u_json_add ( head , jobj ) ) ; dbg_err_if ( u_json_new_array ( " " , & jarr ) ) ; u_list_iforeach ( pgi -> components , pc , it , icount ) { dbg_err_if ( gil_comp_encode ( pc , & jobj ) ) ; dbg_err_if ( u_json_add ( jarr , jobj ) ) ; } err_err_ifm ( icount != pgi -> ncomponent , " " ) ; dbg_err_if ( u_json_add ( head , jarr ) ) ; dbg_err_if ( u_json_new_array ( " " , & jarr ) ) ; u_list_iforeach ( pgi -> reactions , pr , it , icount ) { dbg_err_if ( gil_react_encode ( pr , & jobj ) ) ; dbg_err_if ( u_json_add ( jarr , jobj ) ) ; } err_err_ifm ( icount != pgi -> nreaction , " " ) ; dbg_err_if ( u_json_add ( head , jarr ) ) ; return 0 ; err : u_json_free ( jobj ) ; u_json_free ( jarr ) ; return -1 ; }
\brief Produce Create json representation of Gillespie object
  \param pgi    existing gillespie object
  \param head   existing head of tree
\ brief Produce Create json representation of Gillespie object \ param pgi existing gillespie object \ param head existing head of tree
/* opaque u_list_t iterator */ /* Components */ /* Reactions */