Sometimes you want to add custom functions or subroutines to customize the initialization of some particular WRF case. Some people opt to alter the initialization code directly in order to achieve the desired effects. I have found that creating a Fortran module with all the specific functions/subroutines that you need for customization is a nice way of both compartmentalizing your code and making it easier to use in many contexts. Below is a small tutorial on how to implement this “modular” strategy.
- Create Fortran module and save as a “.F” file. WRF expects FORTRAN files to be preprocessed with C. Take care to remember the module name. The module name is defined when you begin your module. That is…
MODULE your_module_name ! Module stuff goes here END MODULE your_module_name
- Add the USE <your module name> to the desired case initialization code. This is most often going to be in the dyn_em directory.
- Edit the Makefile in the dyn_em directory. Here you will want to add <your module name>.o to the MODULES section at the top of the file.
- Edit the depend.dyn_em file in the dyn_em directory. Add <your module name>.o to the section of the code that pertains to case you are looking to compile. For example, if you were compiling the baroclinic wave case, you would add <your module name>.o underneath the module_initialize_b_wave.o section header.
- If you are invoking any functions present in other libraries, be sure to have those library names/paths added to the compiler options. This can easily be done by editing the configure.wrf file in the main WRF directory. There is a section called POSTAMBLE that has several compiler flags and library options underneath it. Here you can add your own custom libraries, etc. (using the original code as a template). After making your library array, be sure to add your library array to the main LIB array variable that will be used when WRF is compiled.
- If necessary, you may need to alter the original initialization code for your particular case so that your new functions/subroutines are called.
- That’s it! Just compile your case as you would normally. Pay attention to any error messages. If all is well, you should have all the WRF executables with your custom module included.