Taarifa reporting for International Medical Corps UK at hack4good London

On the weekend of 4-6th October I was part of #hack4good in London working with Chris Adams, Corinne Pritchard and Nick Stanton tackling multi-agency reporting at refugee camps for International Medical Corps UK with the Taarifa platform.

We approached the problem from two angles: One was developing a workflow for a paper-based reporting system, where report forms are automatically generated for a specific area like a refugee camp. Refugees would be able make a report by filling in the form themselves with the help of a simple iconography to overcome the language barrier, mark the location on a map and drop it into a collection box. The forms are machine readable and can be digitized in an automated process.

The other was the technical challenge of providing a platform that could process a variety of different reports that various agencies working at a refugee camp need to deal with from santiation over general feedback to sexual exploitation. These can be aggregated in one place by the Taarifa API which I’ve extended to be able to handle any report schema. Creating a new report type is a simple as sending a POST request describing the schema to the API in JSON format. Reports can then be submitted immediately via the JSON API or via an automatically generated web form. All of that is live and operational at http://api.taarifa.org.

There was quite a bit of media coverage around #hack4good: Channel 4, SkyNews and a video of the London event by Big Bang Lab.

C pointers to multi-dimensional assumed shape Fortran arrays with gfortran

Interoperability between C and Fortran codes is often complicated by Fortran’s support for “true” multi-dimensional arrays. In addition, Fortran 90 supports assumed shape (also referred to as deferred shape) arrays, where the extent sizes are determined at runtime. Actual arguments for array dummy arguments can be array slices that may be of non-unit stride. In short, an assumed size Fortran array can reference non-contiguous chunks of memory.

Therefore, the compiler will reject an attempt to obtain a raw data pointer of a Fortran array to pass to a C function like in the following module:

gfortran 4.7 emits the following error message:

Error: Assumed-shape array 'v' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable

What if you know that the assumed-shaped array passed to your function is actually contiguous (or you choose to leave it the caller’s responsibility)? Surely the compiler should be able to give you a pointer to the first array element like so:

Turns out gfortran doesn’t and generates the same error as before. The gfortran developers have recognized this as a bug, which will be fixed in the 4.9 release.

In the meantime you can work around it by defining a pure function that simply returns the first argument of an assumed shape array. gfortran is happy with that since now the type of the argument passed to c_loc is a scalar and therefore interoperable:

However, this workaround confuses Intel’s and PGI’s Fortran compilers, so simply escape it using the a preprocessor #define: