Run C2Vsim on Linux

The California Central Valley Groundwater-Surface Water Simulation Model (C2VSim) is an integrated numerical model that simulates water movement through the linked land surface, groundwater and surface water flow systems in California’s Central Valley.

In this post I’d like to highlight the changes of the input files needed to run C2Vsim on Linux systems.

First we create a similar to *.bat file for linux e.g. an file.

Because I want to switch easily between the debug and release versions of IWFM I’ll have the script switching to debug mode when the user provides a zero input. e.g. ./ 0

At the first lines of the file I define some user input as follows

The first line is the path to the IWFM executables and the second is a temporary name whose purpose will be explained shortly.

The next part of the script identifies which version the user chooses

Next we enter the Preprocessor folder and run the preprocessing part of the program. The last line moves the output of the program to the simulation folder

Next its time to run the main simulation program. However we need to fix the input and output paths. Unfortunately linux paths are not recognized by IWFM, therefore all input and output files should be located under the simulation folder. This is as easy as to remove the ../Results/ from all input and output filenames inside the file. Once this is taken care, the follow snippet will enter the simulation folder run the model and move the output files from the Simulation folder to Results folder to keep everything neat and clean

After the simulation is finished we can run the Budget. Similar to above IWFM does not understands linux paths and we have to put the input files in the same folder as the main input. The following snippet enters the Budget directory and copies all the required inputs from results to the budget folder after appending a prefix defined by the user. This prefix will be handy later to delete those files. However we need to change the filenames of the input budget file. To do so we have to change the ..\Results\ with temp_ or any temp name defined by the user above. Next run the budget and copy the results to the ../Results folder without the prefix temp. Last we delete all the files with temp prefix to keep the folder clean

The last step is to run the Zbudget. For each budget zone we have to repeat the following lines. First we enter the Z-Budget folder and copy the required input from the Results folder to the Z-Budget folder while appending the prefix temp for the same reasons that were explained previously. We have also to modify the namefiles inside the input file as we did previously (replace the ..\Results\ with temp_). After the Zbudget code is executed the result is copied to the ../Results folder without the prefix and finally remove the temporary files.

That concludes the simulation and exit the Z-Budget folder


IMPORTANT NOTE: IWFM is case sensitive. CVPrint.dat is different from CVprint.dat


Build IWFM on Linux

The Integrated Water Flow Model (IWFM) is a water resources management and planning model that simulates groundwater, surface water, stream-groundwater interaction, and other components of the hydrologic system.

The model is written in Fortran, and windows executables for 32 and 64bit OS are readily available from their website. However for linux the code has to be compiled. In this post I’ll describe the tweaks needed to compile IWFM under Ubuntu. Using this process I have been able to compile IWFM on my desktop PC and a local installation on the UCDavis cluster.

Although the source code of the program is available it does not contain makefiles for linux builds. Yet the developers can provide upon request a linux version of the source code with all necessary files.

The code I received provided 2 makefiles for 32 and 64bit system. Here I’m explaining the installation of the 64bit version. The entry point of the installation is the file 

We need first to change the path of the on the second line. First do a search to find the location of the file using for example $ locate and then change the path after source accordingly. The rest of the file is good to go. However we need few additional tweaks:

1) find the paths for the files ieee_exceptions.modintr and ieee_arithmetic.modintr.

2) The folders ../x64/Debug and ../x64/Release contain a makefile named makefile_objs_D and makefile_objs respectively. In these files there is an absolute definition of the location of the above files which is very unlikely that matches yours. Correct those paths accordingly

For the cluster installation we should load first the appropriate module. for example $ module load intel

Finally compile the code by running the $ ./

Note: The above steps worked for my desktop PC. However in the cluster I was getting warnings related to some ar flags that should be changed to xiar. In this case one need to modify the makefile under ../IWFM_UTIL/x64/Release and change the ar flag of the build library to xiar. It should read as

IWFM_Util_x64.a : $(OBJS)
               xiar rc IWFM_Util_x64.a $(OBJS)