{"id":270,"date":"2021-02-27T15:59:06","date_gmt":"2021-02-27T15:59:06","guid":{"rendered":"http:\/\/www.martin-rdz.de\/?p=270"},"modified":"2021-12-23T10:36:01","modified_gmt":"2021-12-23T10:36:01","slug":"flexpart-10-into-a-docker-container","status":"publish","type":"post","link":"http:\/\/www.martin-rdz.de\/index.php\/2021\/02\/27\/flexpart-10-into-a-docker-container\/","title":{"rendered":"FLEXPART 10 into a Docker container"},"content":{"rendered":"<p>For a <a href=\"https:\/\/github.com\/martin-rdz\/trace_airmass_source\/\">recent project<\/a>, I wanted to include the Lagrangian particle dispersion model FLEXPART (<a href=\"https:\/\/www.flexpart.eu\/\">more<\/a> <a href=\"https:\/\/gmd.copernicus.org\/articles\/12\/4955\/2019\/\">on that<\/a>) into an easy-to-deploy project. The analysis part of that project runs on python, but uses some nifty geography libraries, which in turn require C and Fortran libraries. So, I already put this part into a <a href=\"https:\/\/www.docker.com\/resources\/what-container\">docker container<\/a>. FLEXPART provides the actual input for the analysis part, so it seemed logical to also include that part.<\/p>\n<p>Not too long ago version 10 came available, also including <a href=\"https:\/\/www.unidata.ucar.edu\/software\/netcdf\/\">netCDF<\/a> output. However, with added dependencies, compiling the source became a bit more complicated. Let&#8217;s have a look at the Dockerfile:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"wpcustom\" data-enlighter-highlight=\"34-42\">FROM ubuntu:18.04\r\n\r\n\r\nARG DEBIAN_FRONTEND=noninteractive\r\n\r\nRUN apt-get update &amp;&amp; apt-get update &amp;&amp; apt-get install -y \\\r\n  language-pack-en openssh-server vim software-properties-common \\\r\n  build-essential make gcc g++ zlib1g-dev git python3 python3-dev python3-pip \\\r\n  pandoc python3-setuptools imagemagick\\\r\n  gfortran autoconf libtool automake flex bison cmake git-core \\\r\n  libjpeg8-dev libfreetype6-dev libhdf5-serial-dev \\\r\n  libeccodes0 libeccodes-data libeccodes-dev \\\r\n  libnetcdf-c++4 libnetcdf-c++4-dev libnetcdff-dev \\\r\n  binutils  python3-numpy python3-mysqldb \\\r\n  python3-scipy python3-sphinx libedit-dev unzip curl wget\r\n  \r\n  \r\n# replaced 'libpng12-dev' by libpng-dev\r\nRUN add-apt-repository ppa:ubuntugis\/ppa \\\r\n  &amp;&amp; apt-get update \\\r\n  &amp;&amp; apt-get install -y libatlas-base-dev libpng-dev \\\r\n     libproj-dev libgdal-dev gdal-bin  \r\n\r\nRUN add-apt-repository 'deb http:\/\/security.ubuntu.com\/ubuntu xenial-security main' \\\r\n  &amp;&amp; apt-get update \\\r\n  &amp;&amp; apt-get install -y libjasper1 libjasper-dev libeccodes-tools libeccodes-dev\r\n\r\n#ENV HTTP https:\/\/confluence.ecmwf.int\/download\/attachments\/45757960\r\n#ENV ECCODES eccodes-2.9.2-Source\r\n\r\n#\r\n# Download, modify and compile flexpart 10\r\n#\r\nRUN mkdir flex_src &amp;&amp; cd flex_src \\\r\n  &amp;&amp; wget https:\/\/www.flexpart.eu\/downloads\/66 \\\r\n  &amp;&amp; tar -xvf 66 \\\r\n  &amp;&amp; rm 66 \\\r\n  &amp;&amp; cd flexpart_v10.4_3d7eebf\/src \\\r\n  &amp;&amp; cp makefile makefile_local \\\r\n  &amp;&amp; sed -i '74 a INCPATH1 = \/usr\/include\\nINCPATH2 = \/usr\/include\\nLIBPATH1 = \/usr\/lib\\n F90 = gfortran' makefile_local \\\r\n  &amp;&amp; sed -i 's\/LIBS = -lgrib_api_f90 -lgrib_api -lm -ljasper $(NCOPT)\/LIBS = -leccodes_f90 -leccodes -lm -ljasper $(NCOPT)\/' makefile_local \\\r\n  &amp;&amp; make -f makefile_local\r\n\r\nENV PATH \/flex_src\/flexpart_v10.4_3d7eebf\/src\/:$PATH\r\n\r\n# pip install some more python libraries\r\n<\/pre>\n<p>The interesting part happens in L34-42. The source is downloaded and unpacked. Then the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"wpcustom\">makefile<\/code>\u00a0 needs to be modified to find all libraries (which were installed with apt-get before). <a href=\"https:\/\/man.openbsd.org\/sed.1\">Sed<\/a> is of great use here. First a line is added to the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"wpcustom\">makefile_local<\/code> and another line is searched and replaces. Finally make is executed to compile FLEXPART.<\/p>\n<p>Now the container can be ran and FLEXPART be executed from within. At least for my application with a couple of thousand particles being simulated, performance is sufficient and a small penalty is outweigh by the ease of deployment.<\/p>\n<h5>Further reading:<\/h5>\n<ul>\n<li><a href=\"https:\/\/medium.com\/@urban_institute\/fortran-and-docker-how-to-combine-legacy-code-with-cutting-edge-components-35e934b15023\">Fortran and Docker: How to Combine Legacy Code with Cutting-Edge Components<\/a><\/li>\n<li><a href=\"https:\/\/www.icl.utk.edu\/files\/publications\/2020\/icl-utk-1328-2020.pdf\">Docker Container based PaaS Cloud Computing Comprehensive Benchmarks using LAPACK<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>For a recent project, I wanted to include the Lagrangian particle dispersion model FLEXPART (more on that) into an easy-to-deploy project. The analysis part of that project runs on python, but uses some nifty geography libraries, which in turn require C and Fortran libraries. So, I already put this part into a docker container. FLEXPART &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.martin-rdz.de\/index.php\/wp-json\/wp\/v2\/posts\/270"}],"collection":[{"href":"http:\/\/www.martin-rdz.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.martin-rdz.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.martin-rdz.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.martin-rdz.de\/index.php\/wp-json\/wp\/v2\/comments?post=270"}],"version-history":[{"count":5,"href":"http:\/\/www.martin-rdz.de\/index.php\/wp-json\/wp\/v2\/posts\/270\/revisions"}],"predecessor-version":[{"id":276,"href":"http:\/\/www.martin-rdz.de\/index.php\/wp-json\/wp\/v2\/posts\/270\/revisions\/276"}],"wp:attachment":[{"href":"http:\/\/www.martin-rdz.de\/index.php\/wp-json\/wp\/v2\/media?parent=270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.martin-rdz.de\/index.php\/wp-json\/wp\/v2\/categories?post=270"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.martin-rdz.de\/index.php\/wp-json\/wp\/v2\/tags?post=270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}