From 6a0e0f99ceaa032f853a10b88eb7a621c519b250 Mon Sep 17 00:00:00 2001
From: lhausamm <loic_hausammann@hotmail.com>
Date: Fri, 8 Dec 2017 11:34:33 +0100
Subject: [PATCH] update comments

---
 src/cooling_wrapper.c  | 18 ++++++++++++------
 src/parser_wrapper.c   |  4 ++++
 src/part_wrapper.c     |  2 ++
 src/pyswiftsim_tools.c |  2 +-
 src/units_wrapper.c    |  6 ++++++
 5 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/cooling_wrapper.c b/src/cooling_wrapper.c
index b81e13f..49d6592 100644
--- a/src/cooling_wrapper.c
+++ b/src/cooling_wrapper.c
@@ -14,6 +14,7 @@ PyObject* pycooling_init(PyObject* self, PyObject* args) {
   PyObject *pyus;
   PyObject *pypconst;
 
+  /* parse arguments */
   if (!PyArg_ParseTuple(args, "OOO", &pyparams, &pyus, &pypconst))
       return NULL;
 
@@ -32,8 +33,10 @@ PyObject* pycooling_init(PyObject* self, PyObject* args) {
 
   struct cooling_function_data cooling;
 
+  /* init cooling */
   cooling_init_backend(params, us, pconst, &cooling);
 
+  /* construct python object */
   PyObject *pycooling = pytools_return(&cooling, class_cooling_function_data);
 
   return pycooling;
@@ -51,6 +54,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
 
   float dt = 1e-3;
 
+  /* parse argument */
   if (!PyArg_ParseTuple(args,
 			"OOOOO|f",
 			&pypconst,
@@ -61,6 +65,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
 			&dt))
     return NULL;
 
+  /* check numpy array */
   if (pytools_check_array(energy, 1, NPY_FLOAT) != SUCCESS)
     {
       return NULL;
@@ -76,7 +81,9 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
       pyerror("Density and energy should have the same dimension");
     }
 
-    size_t N = PyArray_DIM(energy, 0);
+  size_t N = PyArray_DIM(energy, 0);
+
+  /* transform PyObject to C struct */
 
   struct cooling_function_data *cooling = (struct cooling_function_data*) pytools_construct(pycooling, class_cooling_function_data);
   if (cooling == NULL)
@@ -92,20 +99,19 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
 
   struct part p;
 
-#ifdef COOLING_GRACKLE
-  grackle_data.grackle_data_file = cooling->GrackleCloudyTable;
-#endif
-
+  /* return object */
   PyArrayObject *rate = PyArray_NewLikeArray(energy, NPY_ANYORDER, NULL, 1);
 
+  /* loop over all particles */
   for(size_t i = 0; i < N; i++)
     {
+      /* set particle data */
       p.rho = *(float*) PyArray_GETPTR1(rho, i);
       float u = *(float*) PyArray_GETPTR1(energy, i);
       p.entropy = gas_entropy_from_internal_energy(p.rho, u);
 
+      /* compute cooling rate */
       float *tmp = PyArray_GETPTR1(rate, i);
-
 #ifdef COOLING_GRACKLE
       *tmp = cooling_rate(pconst, us, cooling, &p, dt);
 #else
diff --git a/src/parser_wrapper.c b/src/parser_wrapper.c
index a6ecc0b..ef164f5 100644
--- a/src/parser_wrapper.c
+++ b/src/parser_wrapper.c
@@ -7,13 +7,17 @@ PyObject* pyparser_read_file(PyObject *self, PyObject *args)
 {
 
   char *filename;
+
+  /* parse argument */
   if (!PyArg_ParseTuple(args, "s", &filename))
     return NULL;
 
   struct swift_params params;
 
+  /* parse file */
   parser_read_file(filename, &params);
 
+  /* create return python object */
   PyObject* obj = pytools_return(&params, class_swift_params);
 
   return obj;
diff --git a/src/part_wrapper.c b/src/part_wrapper.c
index 0fd3220..a4765ee 100644
--- a/src/part_wrapper.c
+++ b/src/part_wrapper.c
@@ -12,6 +12,7 @@ PyObject* pypart_test_struct(PyObject *self, PyObject *args)
 
   size_t N = sizeof(struct part);
 
+  /* initialize particle */
   struct part *p = malloc(N);
   p->id = 0;
   for(size_t k = 0; k < DIM; k++)
@@ -29,6 +30,7 @@ PyObject* pypart_test_struct(PyObject *self, PyObject *args)
   
   hydro_init_part(p, NULL);
 
+  /* create python object */
   PyObject *object = pytools_return(p, class_part);
 
   free(p);
diff --git a/src/pyswiftsim_tools.c b/src/pyswiftsim_tools.c
index 07ba933..4181459 100644
--- a/src/pyswiftsim_tools.c
+++ b/src/pyswiftsim_tools.c
@@ -51,7 +51,7 @@ PyObject* pytools_import(char* module_name, char* object_name)
       pyerror("Failed to get module '%s' dictionary", module_name);
     }
 
-  /* get right class */
+  /* get right object */
   PyObject *python_obj = PyDict_GetItemString(dict, object_name);
   Py_DECREF(dict);
 
diff --git a/src/units_wrapper.c b/src/units_wrapper.c
index 1858c2b..aeda170 100644
--- a/src/units_wrapper.c
+++ b/src/units_wrapper.c
@@ -13,6 +13,7 @@ PyObject* pyunit_system_test_struct(PyObject *self, PyObject *args)
 
   size_t N = sizeof(struct unit_system);
 
+  /* initialize array */
   struct unit_system *us = malloc(N);
   us->UnitMass_in_cgs = 1.;
   us->UnitLength_in_cgs = 2.;
@@ -20,6 +21,7 @@ PyObject* pyunit_system_test_struct(PyObject *self, PyObject *args)
   us->UnitCurrent_in_cgs = 4.;
   us->UnitTemperature_in_cgs = 5.;
 
+  /* construct python object */
   PyObject *object = pytools_return(us, class_unit_system);
   free(us);
   if (object == NULL)
@@ -32,6 +34,7 @@ PyObject* pyunit_system_init(PyObject *self, PyObject *args)
 {
   PyObject* parser;
 
+  /* parse arguement */
   if (!PyArg_ParseTuple(args, "O", &parser))
     return NULL;
 
@@ -40,12 +43,15 @@ PyObject* pyunit_system_init(PyObject *self, PyObject *args)
   if (params == NULL)
     return NULL;
 
+  /* initialize units */
   struct unit_system us;
   units_init(&us, params, "InternalUnitSystem");
 
+  /* initialize phys_const */
   struct phys_const pconst;
   phys_const_init(&us, &pconst);
 
+  /* create python object to return */
   PyObject *pyus = pytools_return(&us, class_unit_system);
   if (pyus == NULL)
     return NULL;
-- 
GitLab