Log In | Users | Register
COSMO Web

Advice on writing code

We summarize here some external information on how to write correct and efficient code with a focus on the COSMO model. Additional information on good coding practices from a past C2SM training can be found here.

Steps for source code development and rules to follow

1. Find a partner (post-doc, Data staff, ...) who will follow your development, provide you some help/advices, review your code.

The "4-eyes principle" is really important for your work. Having someone else looking at your code will greatly improve its quality, will ensure that it is readable also for someone else and thus ensure that your code will have a long and successful life!

2. Make a code design.

You have to write down on paper the scientific problem that you want to solve, the algorithms that you will use to solve it. Show it to your partner.

3. Start from a clean code version stored in a git repository on Github.

It means that you should not accept to start directly your developments in a code that you received from someone in your group or from an external partner or that was lying in a folder somewhere on your machine. If the version that you want to use is not available on Github or if you want to start from a code that you received from someone else, ask me and we can check it in together. In this way, you will be able to keep a trace of all your developments and go back to the original version for comparison or in case you have to undo some developments.

  1. Create a fork of the git repository in case you don't have one (see doc).
  2. Read carefully the COSMO coding standards
  3. If you have no experience in Fortran programming, consider reading a Fortran book or attending a Fortran course (e.g. check for the Fortran lecture proposed by the Earth Sciences department at ETH)
  4. Be sure that you have basic knowledge about the machine you will be computing on (check the websites of the service provider (e.g. CSCS) or ask me).
  5. Start your development. At this point, you should have discussed already your implementation strategy with your partner and they should have approved your strategy.
  6. Every evening or every week (or each time you have coded a small chunk), check-in your developments with git and comment them in the log files in detail.
  7. Document also your code internally (i.e. write the meaning of each variable and of each code chunk) and externally (either write a technical report or a short wiki page).
  8. Show your developments regularly to your partner.
  9. Use some debug options to compile your code as long as you are developing (see doc and the README provided with the code).
  10. Pay attention also to the compiler warnings that originate from your code parts and try to fix the source of these warnings.
  11. Check the results you are producing on a regular basis.
  12. Check the performance of your code by comparing the computing time of your version to the computing time of the version that you used as base version for your developments.

For COSMO and other softwares that are part of the COSMO software package (Int2lm, Fieldextra, Versus), the COSMO Coding Standards for Source Code Development have to be followed: COSMO coding standards

Anybody who wants his/her code to be included into an official version must at least fulfill the criteria listed in this document. For those developers who do not target the inclusion of their code into an official version, it is nevertheless recommended to apply these rules. spacer

This site is managed by the Center for Climate Systems Modeling (C2SM).
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems? Send feedback!