├── .dockerignore ├── .github ├── ISSUE_TEMPLATE │ ├── rapid_enhancement.yml │ ├── rapid_question.yml │ └── rapid_user_info.yml └── workflows │ ├── github_actions_CD.yml │ └── github_actions_CI.yml ├── .gitignore ├── CONTRIBUTING ├── Dockerfile ├── LICENSE ├── README.md ├── docker.test.yml ├── drv └── drv_MERIT_Hydro_v07_Basins_v01_GLDAS_v20.py ├── rapid_apprise_year.sh ├── rapid_install_prereqs.sh ├── rapid_specify_varpath.sh ├── requirements.apt ├── src ├── makefile ├── rapid_QtoV.F90 ├── rapid_arrays.F90 ├── rapid_cli.F90 ├── rapid_close_Qfinal_file.F90 ├── rapid_close_Qfor_file.F90 ├── rapid_close_Qhum_file.F90 ├── rapid_close_Qinit_file.F90 ├── rapid_close_Qobs_file.F90 ├── rapid_close_Qout_file.F90 ├── rapid_close_V_file.F90 ├── rapid_close_Vlat_file.F90 ├── rapid_cov_mat.F90 ├── rapid_create_Qfinal_file.F90 ├── rapid_create_Qout_file.F90 ├── rapid_create_V_file.F90 ├── rapid_create_obj.F90 ├── rapid_destro_obj.F90 ├── rapid_final.F90 ├── rapid_get_Qdam.F90 ├── rapid_hsh_mat.F90 ├── rapid_init.F90 ├── rapid_kf_cov_mat.F90 ├── rapid_kf_obs_mat.F90 ├── rapid_kf_update.F90 ├── rapid_main.F90 ├── rapid_meta_Vlat_file.F90 ├── rapid_mus_mat.F90 ├── rapid_net_mat.F90 ├── rapid_net_mat_brk.F90 ├── rapid_obs_mat.F90 ├── rapid_open_Qfinal_file.F90 ├── rapid_open_Qfor_file.F90 ├── rapid_open_Qhum_file.F90 ├── rapid_open_Qinit_file.F90 ├── rapid_open_Qobs_file.F90 ├── rapid_open_Qout_file.F90 ├── rapid_open_V_file.F90 ├── rapid_open_Vlat_file.F90 ├── rapid_petsc_includes.sh ├── rapid_phiroutine.F90 ├── rapid_read_Qfor_file.F90 ├── rapid_read_Qhum_file.F90 ├── rapid_read_Qinit_file.F90 ├── rapid_read_Qobs_file.F90 ├── rapid_read_Vlat_file.F90 ├── rapid_read_namelist.F90 ├── rapid_routing.F90 ├── rapid_routing_param.F90 ├── rapid_run2strm_mat_smpl.F90 ├── rapid_runoff2streamflow_mat.F90 ├── rapid_set_Qext0.F90 ├── rapid_uq.F90 ├── rapid_var.F90 ├── rapid_version.sh ├── rapid_write_Qfinal_file.F90 ├── rapid_write_Qout_file.F90 └── rapid_write_V_file.F90 └── tst ├── rapid_namelist_France_HP ├── rapid_namelist_HSmsp_WRR ├── rapid_namelist_MGBM_FRN ├── rapid_namelist_Reg07_JHM ├── rapid_namelist_San_Guad_JHM ├── rapid_namelist_San_Guad_JHM2 ├── rapid_namelist_WSWM_GRL ├── tst_mem_chck.sh ├── tst_nml_tidy_France_HP.sh ├── tst_nml_tidy_HSmsp_WRR.sh ├── tst_nml_tidy_MGBM_FRN.sh ├── tst_nml_tidy_Reg07_JHM.sh ├── tst_nml_tidy_San_Guad_JHM.sh ├── tst_nml_tidy_San_Guad_JHM2.sh ├── tst_nml_tidy_WSWM_GRL.sh ├── tst_opt_comp.sh ├── tst_opt_find.sh ├── tst_opt_gtol.sh ├── tst_opt_pick.sh ├── tst_pub_dwnl_David_etal_2011_HP.sh ├── tst_pub_dwnl_David_etal_2011_JHM.sh ├── tst_pub_dwnl_David_etal_2015_WRR.sh ├── tst_pub_dwnl_David_etal_2019_GRL.sh ├── tst_pub_dwnl_Emery_etal_2020_JHM2.sh ├── tst_pub_dwnl_Sikder_etal_201x_FRN.sh ├── tst_pub_repr_David_etal_2011_HP.sh ├── tst_pub_repr_David_etal_2011_JHM.sh ├── tst_pub_repr_David_etal_2015_WRR.sh ├── tst_pub_repr_David_etal_2019_GRL.sh ├── tst_pub_repr_Emery_etal_2020_JHM2.sh ├── tst_pub_repr_Sikder_etal_201x_FRN.sh ├── tst_pub_xtra_David_etal_2011_JHM.sh ├── tst_run_cerr.f90 ├── tst_run_comp.f90 └── tst_run_conv_Qinit.f90 /.dockerignore: -------------------------------------------------------------------------------- 1 | #******************************************************************************* 2 | #.dockerignore 3 | #******************************************************************************* 4 | 5 | #Purpose: 6 | #The Docker program is informed here to ignore the following files while sending 7 | #files to the Docker daemon as the build context. Ignoring files helps decrease 8 | #time for build, pull and push of images; and runtime size for containers. 9 | #Author: 10 | #Cedric H. David, 2018-2024. 11 | 12 | 13 | #******************************************************************************* 14 | #List of files that Docker will ignore 15 | #******************************************************************************* 16 | 17 | #------------------------------------------------------------------------------- 18 | #The input and output files stored in the sub-directories of input/ and output/ 19 | #------------------------------------------------------------------------------- 20 | input/ 21 | output/ 22 | 23 | #------------------------------------------------------------------------------- 24 | #The files added by users to the run directory except for rapid_script.sh 25 | #------------------------------------------------------------------------------- 26 | run/* 27 | !run/rapid_script.sh 28 | 29 | #------------------------------------------------------------------------------- 30 | #The RAPID executable 31 | #------------------------------------------------------------------------------- 32 | src/rapid 33 | 34 | #------------------------------------------------------------------------------- 35 | #The files potentially added to the tst directory 36 | #------------------------------------------------------------------------------- 37 | tst/rapid 38 | tst/rapid_namelist 39 | tst/tst_run_comp 40 | tst/tst_run_cerr 41 | tst/tst_run_conv_Qinit 42 | tst/tmp_* 43 | 44 | 45 | #******************************************************************************* 46 | #End 47 | #******************************************************************************* 48 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/rapid_enhancement.yml: -------------------------------------------------------------------------------- 1 | name: Proposed Enhancement for RAPID 2 | description: If you would like to suggest an enhancement to RAPID. 3 | title: "[enhancement]: " 4 | labels: ["enhancement"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to make a suggestion for RAPID! 10 | - type: textarea 11 | attributes: 12 | label: What would you like to suggest? 13 | description: > 14 | We cannot promise anything, but we love suggestions for improvement. 15 | placeholder: Please tell us. 16 | validations: 17 | required: false 18 | - type: checkboxes 19 | attributes: 20 | label: Let us ensure open source development is sustainable! 21 | description: > 22 | We care about open source, and we would like for our interactions to be 23 | a productive collaboration. 24 | options: 25 | - label: > 26 | I have looked at previous GitHub issues and this enhancement has not 27 | yet been proposed. 28 | required: true 29 | - label: > 30 | I have already submitted one unique GitHub issue with my RAPID User 31 | Information. 32 | required: true 33 | - label: > 34 | I have read the last paragraph of Section 6.3 in 35 | [David et al., 2016](https://doi.org/10.1002/2015EA000142). 36 | required: true 37 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/rapid_question.yml: -------------------------------------------------------------------------------- 1 | name: Question about RAPID 2 | description: If you would like to ask a question about RAPID. 3 | title: "[question]: " 4 | labels: ["question"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to ask us about RAPID! 10 | - type: textarea 11 | attributes: 12 | label: What would you like to ask? 13 | description: > 14 | All questions are good questions! 15 | placeholder: Please tell us. 16 | validations: 17 | required: false 18 | - type: checkboxes 19 | attributes: 20 | label: Let us ensure open source development is sustainable! 21 | description: > 22 | We care about open source, and we would like for our interactions to be 23 | a productive collaboration. 24 | options: 25 | - label: > 26 | I have looked at previous GitHub issues and this question has not 27 | yet been addressed. 28 | required: true 29 | - label: > 30 | I have already submitted one unique GitHub issue with my RAPID User 31 | Information. 32 | required: true 33 | - label: > 34 | I have read the last paragraph of Section 6.3 in 35 | [David et al., 2016](https://doi.org/10.1002/2015EA000142). 36 | required: true 37 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/rapid_user_info.yml: -------------------------------------------------------------------------------- 1 | name: RAPID User Information 2 | description: Please start by telling us about your use of RAPID. 3 | title: "[user]: Your Name" 4 | labels: ["user"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to tell us about your use of RAPID! 10 | - type: input 11 | attributes: 12 | label: Your Name 13 | description: What are your first name and your last name? 14 | placeholder: ex. Jane Doe 15 | validations: 16 | required: true 17 | - type: input 18 | attributes: 19 | label: Your Institution 20 | description: Where do you work? 21 | placeholder: ex. Jet Propulsion Laboratory 22 | validations: 23 | required: true 24 | - type: input 25 | attributes: 26 | label: Your Location 27 | description: Where are you located? 28 | placeholder: ex. Pasadena, California, United States 29 | validations: 30 | required: true 31 | - type: textarea 32 | attributes: 33 | label: Your Use Case 34 | description: > 35 | Please describe what you're using RAPID for. You can include such 36 | information as geographical domain, temporal range of your study, the 37 | type of river network you're using (NHDPlus, HydroSHEDS, other?), where 38 | your runoff data comes from (self-produced, obtained from NLDAS, GLDAS, 39 | or others), as well as what you’re hoping to accomplish with RAPID. 40 | placeholder: Tell us as much as you can! 41 | validations: 42 | required: true 43 | - type: textarea 44 | attributes: 45 | label: Why RAPID? 46 | description: > 47 | Please tell us why you chose RAPID. Perhaps because it is open source, 48 | is dockerized, uses mapped rivers as its computational elements, has 49 | parallel computing capabilities, has automated parameter estimation, 50 | etc. 51 | placeholder: This may give us ideas for what to keep supporting. 52 | validations: 53 | required: true 54 | - type: textarea 55 | attributes: 56 | label: How do you use RAPID? 57 | description: > 58 | Do you use our Docker images? Do you install RAPID yourself? If so, 59 | what operating system do you use? Are you on a local machine, a high 60 | performance computer, the compute cloud (which one)? 61 | placeholder: We like knowing these details to best support you. 62 | validations: 63 | required: true 64 | - type: textarea 65 | attributes: 66 | label: Anything else you'd like us to know? 67 | description: > 68 | Feel free to share! 69 | placeholder: Additional thoughts are welcome. 70 | validations: 71 | required: false 72 | - type: checkboxes 73 | attributes: 74 | label: Are you aware of our philosphy for open source? 75 | description: > 76 | RAPID has been open source since inception, and we have spend some time 77 | reflecting on what it took to build it and keep it open to all. The 78 | outcome of this reflection is 79 | [David et al., 2016](https://doi.org/10.1002/2015EA000142). 80 | We don't expect you to read it all, but we ask that you please read just 81 | this one paragraph. 82 | options: 83 | - label: > 84 | I have read the last paragraph of Section 6.3 in 85 | [David et al., 2016](https://doi.org/10.1002/2015EA000142) 86 | (the one starting with 87 | "Finally, and contrary to common belief, open source software does 88 | not mean...") 89 | required: true 90 | -------------------------------------------------------------------------------- /.github/workflows/github_actions_CD.yml: -------------------------------------------------------------------------------- 1 | #******************************************************************************* 2 | #github_actions_CD.yml 3 | #******************************************************************************* 4 | 5 | #Purpose: 6 | #GitHub Actions is a continuous integration and continuous delivery (CI/CD) 7 | #platform that allows to automate the build, test, and deployment pipeline. The 8 | #The purpose of this file is to give instructions to GitHub on how to do the 9 | #image deployment to Docker Hub. 10 | #Author: 11 | #Cedric H. David, 2022-2024. 12 | 13 | 14 | #******************************************************************************* 15 | #Name and specification of triggers 16 | #******************************************************************************* 17 | name: GitHub Actions CD 18 | on: 19 | push: 20 | branches: 21 | - 'main' 22 | tags: 23 | - 'v*' 24 | - '20*' 25 | 26 | 27 | #******************************************************************************* 28 | #Jobs 29 | #******************************************************************************* 30 | jobs: 31 | 32 | #---------------------------------------------------------------------------- 33 | #Ubuntu 34 | #---------------------------------------------------------------------------- 35 | ubuntu: 36 | runs-on: ubuntu-20.04 37 | 38 | steps: 39 | 40 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 41 | #Display GitHub Action-related information 42 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 43 | - name: Display GitHub Action-related information 44 | run: | 45 | echo "This job was triggered by a ${{ github.event_name }} event." 46 | echo "This job is running on a ${{ runner.os }} server at GitHub!" 47 | echo "The name of the repository is ${{ github.repository }}." 48 | echo "The full git reference of this event is ${{ github.ref }}." 49 | echo "The short git reference of this event is ${{ github.ref_name }}." 50 | echo "The current working directory is $PWD" 51 | echo "The GitHub workspace is ${{ github.workspace }}" 52 | echo "The shell used is $SHELL" 53 | 54 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 55 | #Checkout RAPID code 56 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 57 | - name: Checkout RAPID code 58 | uses: actions/checkout@v4 59 | 60 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 61 | #Set up QEMU 62 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 63 | - name: Set up QEMU 64 | uses: docker/setup-qemu-action@v3 65 | 66 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 67 | #Set up Docker Buildx 68 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 69 | - name: Set up Docker Buildx 70 | uses: docker/setup-buildx-action@v3 71 | 72 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 73 | #Login to Docker Hub 74 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 75 | - name: Login to Docker Hub 76 | uses: docker/login-action@v3 77 | with: 78 | username: ${{ secrets.DOCKER_HUB_NAME }} 79 | password: ${{ secrets.DOCKER_HUB_TOKN }} 80 | 81 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 82 | #Build and push to Docker Hub 83 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 84 | - name: Build and push 85 | uses: docker/build-push-action@v5 86 | with: 87 | push: true 88 | platforms: linux/amd64,linux/arm64 89 | tags: | 90 | ${{ secrets.DOCKER_HUB_NAME }}/rapid:latest 91 | ${{ secrets.DOCKER_HUB_NAME }}/rapid:${{ github.ref_name }} 92 | 93 | 94 | #******************************************************************************* 95 | #End 96 | #******************************************************************************* 97 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #******************************************************************************* 2 | #.gitignore 3 | #******************************************************************************* 4 | 5 | #Purpose: 6 | #The git program is informed here to ignore the following files while performing 7 | #its distributed revision control and source code management. 8 | #Author: 9 | #Cedric H. David, 2014-2024. 10 | 11 | 12 | #******************************************************************************* 13 | #List of files that git will ignore 14 | #******************************************************************************* 15 | 16 | #------------------------------------------------------------------------------- 17 | #Initial releases of RAPID included batch submission scripts for supercomputers 18 | #------------------------------------------------------------------------------- 19 | job_* 20 | 21 | #------------------------------------------------------------------------------- 22 | #Legacy name for BSD 3-clause license of RAPID between 20120831 - 20131113 23 | #------------------------------------------------------------------------------- 24 | rapid_license.txt 25 | 26 | #------------------------------------------------------------------------------- 27 | #The input and output files stored in sub-directories of 28 | #------------------------------------------------------------------------------- 29 | input/ 30 | output/ 31 | 32 | #------------------------------------------------------------------------------- 33 | #The files added by users to the run directory except for rapid_script.sh 34 | #------------------------------------------------------------------------------- 35 | run/* 36 | !run/rapid_script.sh 37 | 38 | #------------------------------------------------------------------------------- 39 | #The RAPID executable 40 | #------------------------------------------------------------------------------- 41 | src/rapid 42 | 43 | #------------------------------------------------------------------------------- 44 | #The files potentially added to the tst directory 45 | #------------------------------------------------------------------------------- 46 | tst/rapid 47 | tst/rapid_namelist 48 | tst/tst_run_comp 49 | tst/tst_run_cerr 50 | tst/tst_run_conv_Qinit 51 | tst/tmp_* 52 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | There are many ways in which RAPID can be improved, and many new features that 2 | should be added to it. We therefore enthusiastically welcome contributions 3 | from others! If you are interested in helping with the development of RAPID, 4 | please contact the lead developer to discuss your ideas before embarking on the 5 | coding journey, as such will help ensure the least overlap with ongoing efforts 6 | and the most efficient use of your time. 7 | 8 | The following people have so far contributed to the development of RAPID: 9 | 10 | Lead developer: 11 | - Cedric H. David 12 | 13 | Contributing developers (thank you!!!): 14 | - Quentin Bonassies 15 | - Charlotte M. Emery 16 | - Kel N. Markert 17 | - Alan D. Snow 18 | - Ahmad A. Tavakoly 19 | - Luke A. Winslow 20 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | #******************************************************************************* 2 | #Dockerfile 3 | #******************************************************************************* 4 | 5 | #Purpose: 6 | #This file describes the operating system prerequisites for RAPID, and is used 7 | #by the Docker software. 8 | #Author: 9 | #Cedric H. David, 2018-2024. 10 | 11 | 12 | #******************************************************************************* 13 | #Usage 14 | #******************************************************************************* 15 | #docker build -t ubuntu:rapid -f Dockerfile . #Create image 16 | #docker run --rm --name ubuntu_rapid -it ubuntu:rapid #Run image in container 17 | #docker save -o ubuntu_rapid.tar ubuntu:rapid #Save a copy of image 18 | #docker load -i ubuntu_rapid.tar #Load a saved image 19 | 20 | 21 | #******************************************************************************* 22 | #Operating System 23 | #******************************************************************************* 24 | FROM debian:11.7-slim 25 | 26 | 27 | #******************************************************************************* 28 | #Copy files into Docker image (this ignores the files listed in .dockerignore) 29 | #******************************************************************************* 30 | WORKDIR /home/rapid/ 31 | COPY . . 32 | 33 | 34 | #******************************************************************************* 35 | #Operating System Requirements 36 | #******************************************************************************* 37 | RUN apt-get update && \ 38 | apt-get install -y --no-install-recommends $(grep -v -E '(^#|^$)' requirements.apt) && \ 39 | rm -rf /var/lib/apt/lists/* 40 | 41 | 42 | #******************************************************************************* 43 | #Other Software Requirements 44 | #******************************************************************************* 45 | 46 | #------------------------------------------------------------------------------- 47 | #Install other software 48 | #------------------------------------------------------------------------------- 49 | ENV INSTALLZ_DIR=/home/installz 50 | #Directory where software is installed 51 | 52 | RUN mkdir $INSTALLZ_DIR && \ 53 | ./rapid_install_prereqs.sh -i=$INSTALLZ_DIR 54 | 55 | #------------------------------------------------------------------------------- 56 | #Update environment (ENV variables are available in Docker images & containers) 57 | #------------------------------------------------------------------------------- 58 | ENV NETCDF_LIB='-L /usr/lib -lnetcdff' 59 | ENV NETCDF_INCLUDE='-I /usr/include' 60 | #netCDF 61 | 62 | ENV PETSC_DIR=$INSTALLZ_DIR/petsc-3.13.6 63 | ENV PETSC_ARCH=linux-gcc-c 64 | ENV PATH=$PATH:$PETSC_DIR/$PETSC_ARCH/bin 65 | #PETSc 66 | 67 | 68 | #******************************************************************************* 69 | #Build RAPID 70 | #******************************************************************************* 71 | RUN cd ./src/ && \ 72 | make rapid && \ 73 | cd ../tst/ && \ 74 | gfortran -o tst_run_comp tst_run_comp.f90 $NETCDF_INCLUDE $NETCDF_LIB && \ 75 | gfortran -o tst_run_cerr tst_run_cerr.f90 $NETCDF_INCLUDE $NETCDF_LIB && \ 76 | gfortran -o tst_run_conv_Qinit tst_run_conv_Qinit.f90 $NETCDF_INCLUDE $NETCDF_LIB 77 | 78 | 79 | #******************************************************************************* 80 | #Intended (default) command at execution of image (not used during build) 81 | #******************************************************************************* 82 | CMD /bin/bash 83 | 84 | 85 | #******************************************************************************* 86 | #End 87 | #******************************************************************************* 88 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007-2024, Cedric H. David 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this 10 | list of conditions and the following disclaimer in the documentation and/or 11 | other materials provided with the distribution. 12 | * The name Cedric H. David may not be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL CEDRIC H. DAVID BE LIABLE FOR ANY DIRECT, 19 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 23 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RAPID 2 | [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.593867.svg)](https://doi.org/10.5281/zenodo.593867) 3 | 4 | [![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-yellow.svg)](https://github.com/c-h-david/rapid/blob/main/LICENSE) 5 | 6 | [![Docker Images](https://img.shields.io/badge/docker-images-blue?logo=docker)](https://hub.docker.com/r/chdavid/rapid/tags) 7 | 8 | [![GitHub CI Status](https://github.com/c-h-david/rapid/actions/workflows/github_actions_CI.yml/badge.svg)](https://github.com/c-h-david/rapid/actions/workflows/github_actions_CI.yml) 9 | 10 | [![GitHub CD Status](https://github.com/c-h-david/rapid/actions/workflows/github_actions_CD.yml/badge.svg)](https://github.com/c-h-david/rapid/actions/workflows/github_actions_CD.yml) 11 | 12 | The Routing Application for Parallel computatIon of Discharge (RAPID) is a river 13 | network routing model. Given surface and groundwater inflow to rivers, this 14 | model can compute flow and volume of water everywhere in river networks made out 15 | of many thousands of reaches. 16 | 17 | For further information on RAPID including peer-reviewed publications, tutorials, 18 | sample input/output data, sample processing scripts and animations of model 19 | results, please go to: 20 | [http://rapid-hub.org/](http://rapid-hub.org/). 21 | 22 | ## Installation with Docker 23 | Installing RAPID is **by far the easiest with Docker**. This document was 24 | written and tested using 25 | [Docker Community Edition](https://www.docker.com/community-edition#/download) 26 | which is available for free and can be installed on a wide variety of operating 27 | systems. To install it, follow the instructions in the link provided above. 28 | 29 | Note that the experienced users may find more up-to-date installation 30 | instructions in 31 | [Dockerfile](https://github.com/c-h-david/rapid/blob/main/Dockerfile). 32 | 33 | ### Download RAPID 34 | Downloading RAPID with Docker can be done using: 35 | 36 | ``` 37 | $ docker pull chdavid/rapid 38 | ``` 39 | 40 | > The images for RAPID on Docker Hub support CPU architectures for both AMD64 41 | > and ARM64! 42 | 43 | ### Install packages 44 | The beauty of Docker is that there is **no need to install anymore packages**. 45 | RAPID is ready to go! To run it, just use: 46 | 47 | ``` 48 | $ docker run --rm --name rapid -it chdavid/rapid 49 | ``` 50 | 51 | ## Testing with Docker 52 | Testing scripts are currently under development. 53 | 54 | Note that the experienced users may find more up-to-date testing instructions 55 | in 56 | [docker.test.yml](https://github.com/c-h-david/rapid/blob/main/docker.test.yml). 57 | 58 | ## Installation on Debian 59 | This document was written and tested on a machine with a **clean** image of 60 | [Debian 11.7.0 ARM64](https://cdimage.debian.org/cdimage/archive/11.7.0/arm64/iso-cd/debian-11.7.0-arm64-netinst.iso) 61 | installed, *i.e.* **no update** was performed, and **no upgrade** either. 62 | Similar steps **may** be applicable for Ubuntu. 63 | 64 | Note that the experienced users may find more up-to-date installation 65 | instructions in 66 | [github\_actions\_CI.yml](https://github.com/c-h-david/rapid/blob/main/.github/workflows/github_actions_CI.yml). 67 | 68 | ### Download RAPID 69 | First, make sure that `git` is installed: 70 | 71 | ``` 72 | $ sudo apt-get install -y --no-install-recommends git 73 | ``` 74 | 75 | Then download RAPID: 76 | 77 | ``` 78 | $ git clone https://github.com/c-h-david/rapid 79 | ``` 80 | 81 | Finally, enter the rapid directory: 82 | 83 | ``` 84 | $ cd rapid/ 85 | ``` 86 | 87 | ### Install APT packages 88 | Software packages for the Advanced Packaging Tool (APT) are summarized in 89 | [requirements.apt](https://github.com/c-h-david/rapid/blob/main/requirements.apt) 90 | and can be installed with `apt-get`. All packages can be installed at once using: 91 | 92 | ``` 93 | $ sudo apt-get install -y --no-install-recommends $(grep -v -E '(^#|^$)' requirements.apt) 94 | ``` 95 | 96 | > Alternatively, one may install the APT packages listed in 97 | > [requirements.apt](https://github.com/c-h-david/rapid/blob/main/requirements.apt) 98 | > one by one, for example: 99 | > 100 | > ``` 101 | > $ sudo apt-get install -y --no-install-recommends gfortran 102 | >``` 103 | 104 | ### Install netCDF 105 | The Network Common Data Form (NetCDF) was already installed with `apt-get`. 106 | 107 | However, the environment should be updated using: 108 | 109 | ``` 110 | $ export NETCDF_LIB='-L /usr/lib -lnetcdff' 111 | $ export NETCDF_INCLUDE='-I /usr/include' 112 | ``` 113 | 114 | > Note that these four lines can also be added in `~/.bash_aliases` so that the 115 | > environment variables persist. 116 | 117 | ### Install PETSc 118 | The Portable, Extensible Toolkit for Scientific Computation (PETSc) 119 | can be installed using: 120 | 121 | ``` 122 | $ mkdir $HOME/installz 123 | $ cd $HOME/installz 124 | $ wget "https://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-3.13.6.tar.gz" 125 | $ tar -xzf petsc-3.13.6.tar.gz 126 | $ cd petsc-3.13.6 127 | $ python3 ./configure PETSC_DIR=$PWD PETSC_ARCH=linux-gcc-c --download-fblaslapack=1 --download-mpich=1 --with-cc=gcc --with-fc=gfortran --with-clanguage=c --with-debugging=0 128 | $ make PETSC_DIR=$PWD PETSC_ARCH=linux-gcc-c all > all.log 129 | $ make PETSC_DIR=$PWD PETSC_ARCH=linux-gcc-c check > check.log 130 | ``` 131 | 132 | > Note that the following can be used as a replacement for the above code block: 133 | > 134 | > ``` 135 | > $ mkdir $HOME/installz 136 | > $ ./rapid_install_prereqs.sh --installz=$HOME/installz 137 | > ``` 138 | 139 | Then, the environment should be updated using: 140 | 141 | ``` 142 | $ export PETSC_DIR=$HOME/installz/petsc-3.13.6 143 | $ export PETSC_ARCH=linux-gcc-c 144 | $ export PATH=$PATH:$PETSC_DIR/$PETSC_ARCH/bin 145 | ``` 146 | 147 | > Note that these three lines can also be added in `~/.bash_aliases` so that the 148 | > environment variables persist. 149 | > 150 | 151 | ### Build RAPID 152 | 153 | ``` 154 | $ cd rapid/ 155 | $ cd src/ 156 | $ make rapid 157 | ``` 158 | 159 | ## Testing on Debian 160 | Testing scripts are currently under development. 161 | 162 | ``` 163 | $ cd rapid/ 164 | $ cd tst/ 165 | $ gfortran -o tst_run_comp tst_run_comp.f90 $NETCDF_INCLUDE $NETCDF_LIB 166 | $ gfortran -o tst_run_cerr tst_run_cerr.f90 $NETCDF_INCLUDE $NETCDF_LIB 167 | $ gfortran -o tst_run_conv_Qinit tst_run_conv_Qinit.f90 $NETCDF_INCLUDE $NETCDF_LIB 168 | ``` 169 | 170 | Note that the experienced users may find more up-to-date testing instructions 171 | in 172 | [github\_actions\_CI.yml](https://github.com/c-h-david/rapid/blob/main/.github/workflows/github_actions_CI.yml). 173 | -------------------------------------------------------------------------------- /docker.test.yml: -------------------------------------------------------------------------------- 1 | #******************************************************************************* 2 | #docker.test.yml 3 | #******************************************************************************* 4 | 5 | #Purpose: 6 | #Docker-compose can be used to build a Docker image from a Dockerfile and run 7 | #the image in a Docker container using a specific command that performs a series 8 | #of tests on the software included in the image. The purpose of this 9 | #docker.test.yml file is to give instructions to docker-compose on how to do the 10 | #work. 11 | #Author: 12 | #Cedric H. David, 2018-2024. 13 | 14 | 15 | #******************************************************************************* 16 | #Usage 17 | #******************************************************************************* 18 | #docker-compose -f docker.test.yml up #Create image if it does not exist, and 19 | #run it in a container w/ the command. 20 | #Note: command has no impact on image. 21 | #docker-compose -f docker.test.yml down #Remove the container, not the image. 22 | 23 | 24 | #******************************************************************************* 25 | #Test 26 | #******************************************************************************* 27 | sut: 28 | build: . 29 | #The name of the Docker image that is created will be rapid_sut, this name 30 | #is generated automatically based on the folder where docker-compose is run 31 | #(rapid) and the service name (sut, i.e. 'system under test') 32 | command: bash -xc "cd ./tst/;"\ 33 | "./tst_pub_dwnl_David_etal_2011_JHM.sh;"\ 34 | "./tst_pub_repr_David_etal_2011_JHM.sh 1" 35 | #bash -c (string) allows to make the code more readable here 36 | #bash -x (verbose) allows to make the commands more readable at runtime 37 | 38 | 39 | #******************************************************************************* 40 | #End 41 | #******************************************************************************* 42 | -------------------------------------------------------------------------------- /rapid_apprise_year.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #rapid_apprise_year.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script allows updating the authorship year for all RAPID files. 8 | #Author: 9 | #Cedric H. David, 2019-2024. 10 | 11 | 12 | #******************************************************************************* 13 | #Check command line arguments 14 | #******************************************************************************* 15 | if [ "$#" -ne "2" ]; then 16 | echo "ERROR - A total of 2 arguments must be provided" 1>&2 17 | exit 22 18 | fi 19 | #Check that 2 arguments were provided 20 | 21 | if ! [[ $1 =~ ^[0-9]+$ ]] || [[ ${#1} != 4 ]]; then 22 | echo "ERROR - Argument 1 must be a year" 23 | exit 22 24 | fi 25 | #Check that argument 1 is a year 26 | 27 | if ! [[ $2 =~ ^[0-9]+$ ]] || [[ ${#2} != 4 ]]; then 28 | echo "ERROR - Argument 2 must be a year" 29 | exit 22 30 | fi 31 | #Check that argument 2 is a year 32 | 33 | 34 | #******************************************************************************* 35 | #Assign command line arguments to local variables 36 | #******************************************************************************* 37 | old_year=$1 38 | new_year=$2 39 | 40 | echo "- Changing the authorship year in all files from $old_year to $new_year" 41 | 42 | 43 | #******************************************************************************* 44 | #Change year in ./ directory 45 | #******************************************************************************* 46 | for file in `find ./ -maxdepth 1 -type f` 47 | do 48 | sed -i -e "s|\-$old_year|\-$new_year|" $file 49 | done 50 | 51 | echo " . Done for ./ directory" 52 | 53 | 54 | #******************************************************************************* 55 | #Change year in ./drv/ directory 56 | #******************************************************************************* 57 | for file in `find ./drv/ -maxdepth 1 -type f` 58 | do 59 | sed -i -e "s|\-$old_year|\-$new_year|" $file 60 | done 61 | 62 | echo " . Done for ./drv/ directory" 63 | 64 | 65 | #******************************************************************************* 66 | #Change year in ./src/ directory 67 | #******************************************************************************* 68 | for file in `find ./src/ -maxdepth 1 -type f` 69 | do 70 | sed -i -e "s|\-$old_year|\-$new_year|" $file 71 | done 72 | 73 | echo " . Done for ./src/ directory" 74 | 75 | 76 | #******************************************************************************* 77 | #Change year in ./tst/ directory 78 | #******************************************************************************* 79 | for file in `find ./tst/ -maxdepth 1 -type f` 80 | do 81 | sed -i -e "s|\-$old_year|\-$new_year|" $file 82 | done 83 | 84 | echo " . Done for ./tst/ directory" 85 | 86 | 87 | #******************************************************************************* 88 | #Change year in ./.github/workflows/ directory 89 | #******************************************************************************* 90 | for file in `find ./.github/workflows/ -maxdepth 1 -type f` 91 | do 92 | sed -i -e "s|\-$old_year|\-$new_year|" $file 93 | done 94 | 95 | echo " . Done for ./.github/workflows/ directory" 96 | 97 | 98 | #******************************************************************************* 99 | #end 100 | #******************************************************************************* 101 | -------------------------------------------------------------------------------- /rapid_install_prereqs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #rapid_install_prereqs.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This shell script installs all prerequisites for running RAPID on Linux. 8 | #Author: 9 | #Alan D. Snow and Cedric H. David, 2015-2024. 10 | 11 | 12 | #******************************************************************************* 13 | #Before installing 14 | #******************************************************************************* 15 | #Make sure this file has execute privileges. 16 | # $ chmod u+x rapid_install_prereqs.sh 17 | # 18 | #Compilers for C and FORTRAN are needed in order to install the libraries used 19 | #by RAPID. Here we use the GNU Compiler Collection (GCC). One can make sure that 20 | #all necessary compilers are installed by executing: 21 | # $ which gcc 22 | # $ which gfortran 23 | # 24 | #If one or more of the compilers is missing, execute: 25 | # $ yum install gcc gfortran (Red Hat) 26 | # $ apt-get install gcc gfortran (Debian) 27 | # $ brew install gcc (Mac) 28 | 29 | 30 | #******************************************************************************* 31 | #Get command line arguments 32 | #******************************************************************************* 33 | 34 | #------------------------------------------------------------------------------- 35 | #Default arguments 36 | #------------------------------------------------------------------------------- 37 | INSTALLZ_DIR=$HOME/installz 38 | #Default installation directory. This can be set from the command line using the 39 | #'-i' option. This location can be updated as wished, but do not move anything 40 | #after running this script, or do so at your own risks! 41 | 42 | FORCE_INSTALL_PETSC=false 43 | #Installation of PETSc is not forced by default. 44 | 45 | #------------------------------------------------------------------------------- 46 | #Command line arguments 47 | #------------------------------------------------------------------------------- 48 | for i in "$@" 49 | do 50 | case $i in 51 | 52 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 53 | #Display help message 54 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 55 | -h|--help) 56 | echo "To install with defaults, ./install_rapid_prereqs.sh" 57 | echo "-i=/path/to/installz | --installz=/path/to/installz | last argument /path/to/installz" 58 | echo "To force installation of PETSc: -pf | --petsc_force" 59 | exit 60 | ;; 61 | 62 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 63 | #Installation directory 64 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 65 | -i=*|--installz=*) 66 | INSTALLZ_DIR="${i#*=}" 67 | shift 68 | ;; 69 | 70 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 71 | #Forcing installation of PETSc 72 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 73 | -pf|--petsc_force) 74 | FORCE_INSTALL_PETSC=true 75 | shift 76 | ;; 77 | 78 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 79 | #Unknown option 80 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 81 | *) 82 | echo "Unknown option" 83 | exit 22 84 | ;; 85 | 86 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 87 | #End command line options 88 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 89 | esac 90 | done 91 | 92 | #------------------------------------------------------------------------------- 93 | #Check if $INSTALLZ_DIR is a directory and if its path is absolute 94 | #------------------------------------------------------------------------------- 95 | if [ ! -d "$INSTALLZ_DIR" ]; then 96 | echo "ERROR: $INSTALLZ_DIR is not a directory" 1>&2 97 | exit 22 98 | fi 99 | #Check if $INSTALLZ_DIR is a directory 100 | 101 | if [[ ! "$INSTALLZ_DIR" = /* ]]; then 102 | echo "ERROR: $INSTALLZ_DIR is not an absolute path" 1>&2 103 | exit 22 104 | fi 105 | #Check if $INSTALLZ_DIR is an absolute path 106 | 107 | #------------------------------------------------------------------------------- 108 | #Print options on standard output 109 | #------------------------------------------------------------------------------- 110 | echo "Installing RAPID prereqs in: $INSTALLZ_DIR" 111 | 112 | if $FORCE_INSTALL_PETSC ; then 113 | echo "Forcing reinstallation of PETSc even if its directory exists." 114 | else 115 | echo "Not forcing reinstallation of PETSc if its directory exists." 116 | fi 117 | 118 | 119 | #******************************************************************************* 120 | #Installing prerequisites 121 | #******************************************************************************* 122 | 123 | #------------------------------------------------------------------------------- 124 | #Installing PETSc 3.13.6 125 | #------------------------------------------------------------------------------- 126 | cd $INSTALLZ_DIR 127 | 128 | if $FORCE_INSTALL_PETSC ; then 129 | rm -rf petsc-3.13.6 130 | fi 131 | #Remove old PETSc directories if FORCE_INSTALL_PETSC 132 | 133 | if [ ! -d petsc-3.13.6.tar.gz ] && [ ! -d petsc-3.13.6 ]; then 134 | wget "https://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-3.13.6.tar.gz" 135 | fi 136 | #Download PETSc installation file if it does not exist 137 | 138 | if [ ! -d petsc-3.13.6 ]; then 139 | tar -xzf petsc-3.13.6.tar.gz 140 | fi 141 | #Extract PETSc installation file if directory does not exist 142 | 143 | if [ ! -d petsc-3.13.6/linux-gcc-c ]; then 144 | cd petsc-3.13.6 145 | python3 ./configure PETSC_DIR=$PWD PETSC_ARCH=linux-gcc-c --download-fblaslapack=1 --download-mpich=1 --with-cc=gcc --with-fc=gfortran --with-clanguage=c --with-debugging=0 146 | make PETSC_DIR=$PWD PETSC_ARCH=linux-gcc-c all 147 | make PETSC_DIR=$PWD PETSC_ARCH=linux-gcc-c check 148 | else 149 | echo "- Skipped PETSc installation: petsc-3.13.6/linux-gcc-c directory" 150 | echo " already exists." 151 | echo " To force installation, run with -pf or --petsc_force." 152 | fi 153 | #Install PETSc if directory does not exist 154 | 155 | 156 | #******************************************************************************* 157 | #End 158 | #******************************************************************************* 159 | -------------------------------------------------------------------------------- /rapid_specify_varpath.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #rapid_specify_varpath.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This shell script specifies the environment variables and updates the PATH for 8 | #use by RAPID. 9 | #The usage is the following: 10 | # - source ./rapid_specify_varpath.sh /path/to/directory 11 | # or 12 | # - source ./rapid_specify_varpath.sh $HOME/installz 13 | # or 14 | # - source ./rapid_specify_varpath.sh (uses the default above) 15 | #Author: 16 | #Cedric H. David, 2016-2024. 17 | 18 | 19 | #******************************************************************************* 20 | #Update from default value if an argument is provided 21 | #******************************************************************************* 22 | if [ "$1" == "" ]; then 23 | INSTALLZ_DIR=$HOME/installz 24 | #Default installation directory. 25 | else 26 | INSTALLZ_DIR=$1 27 | #First argument can be provided instead of default directory 28 | fi 29 | 30 | 31 | #******************************************************************************* 32 | #Check if $INSTALLZ_DIR is a directory and if its path is absolute 33 | #******************************************************************************* 34 | if [ ! -d "$INSTALLZ_DIR" ]; then 35 | echo "ERROR: $INSTALLZ_DIR is not a directory" 1>&2 36 | exit 22 37 | fi 38 | #Check if $INSTALLZ_DIR is a directory 39 | 40 | if [[ "$INSTALLZ_DIR" != /* ]]; then 41 | #The double brackets allow for not expanding the /* into /bin /dev /etc... 42 | echo "ERROR: $INSTALLZ_DIR is not an absolute path" 1>&2 43 | exit 22 44 | fi 45 | #Check if $INSTALLZ_DIR is an absolute path 46 | 47 | 48 | #******************************************************************************* 49 | #Exporting environment variables 50 | #******************************************************************************* 51 | export NETCDF_LIB='-L /usr/lib -lnetcdff' 52 | export NETCDF_INCLUDE='-I /usr/include' 53 | export PETSC_DIR=$INSTALLZ_DIR/petsc-3.13.6 54 | export PETSC_ARCH='linux-gcc-c' 55 | 56 | 57 | #******************************************************************************* 58 | #Exporting directories with library-related executables to $PATH 59 | #******************************************************************************* 60 | export PATH=$PATH:/$PETSC_DIR/$PETSC_ARCH/bin 61 | 62 | 63 | #******************************************************************************* 64 | #End 65 | #******************************************************************************* 66 | -------------------------------------------------------------------------------- /requirements.apt: -------------------------------------------------------------------------------- 1 | #******************************************************************************* 2 | #requirements.apt 3 | #******************************************************************************* 4 | 5 | #Purpose: 6 | #This file lists all the packages from the Advanced Packaging Tool that are 7 | #required by RAPID, and is used by the "apt-get" software. 8 | #Author: 9 | #Cedric H. David, 2017-2024. 10 | 11 | 12 | #******************************************************************************* 13 | #Usage 14 | #******************************************************************************* 15 | #sudo apt-get install -y $(grep -v -E '(^#|^$)' requirements.apt) 16 | #can also use the '--no-install-recommends' flag 17 | 18 | 19 | #******************************************************************************* 20 | #Requirements for apt-get 21 | #******************************************************************************* 22 | 23 | #------------------------------------------------------------------------------- 24 | #Code management 25 | #------------------------------------------------------------------------------- 26 | git 27 | #version control system 28 | vim 29 | #text editor 30 | 31 | #------------------------------------------------------------------------------- 32 | #Code building 33 | #------------------------------------------------------------------------------- 34 | gcc 35 | #compiler for C 36 | gfortran 37 | #compiler for Fortran 38 | python3 39 | #interpreter for Python 40 | make 41 | #compilation orchestration 42 | libnetcdf-dev 43 | #netCDF C libraries 44 | libnetcdff-dev 45 | #netCDF Fortran libraries 46 | netcdf-bin 47 | #netCDF binaries 48 | python3-distutils 49 | #needed for PETSc 50 | 51 | #------------------------------------------------------------------------------- 52 | #Code testing 53 | #------------------------------------------------------------------------------- 54 | wget 55 | #download utility 56 | ca-certificates 57 | #certificate authority 58 | bc 59 | #basic calculator 60 | nco 61 | #netCDF operators 62 | 63 | 64 | #******************************************************************************* 65 | #End 66 | #******************************************************************************* 67 | -------------------------------------------------------------------------------- /src/rapid_QtoV.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_QtoV 3 | !******************************************************************************* 4 | subroutine rapid_QtoV(ZV_k,ZV_x,ZV_QoutbarR,ZV_Qext,ZV_VbarR) 5 | 6 | !Purpose: 7 | !Computes the volume of water in each river reach from the flows based on the 8 | !Muskingum method (McCarthy 1938). 9 | !Author: 10 | !Cedric H. David, 2015-2024. 11 | 12 | 13 | !******************************************************************************* 14 | !Fortran includes, modules, and implicity 15 | !******************************************************************************* 16 | #include 17 | use petscmat 18 | use rapid_var, only : & 19 | ZM_Net,ierr 20 | implicit none 21 | 22 | 23 | !******************************************************************************* 24 | !Intent (in/out), and local variables 25 | !******************************************************************************* 26 | Vec, intent(in) :: ZV_QoutbarR,ZV_Qext, & 27 | ZV_k,ZV_x 28 | Vec, intent(inout) :: ZV_VbarR 29 | 30 | PetscInt :: IS_localsize,JS_localsize 31 | 32 | PetscScalar, pointer :: ZV_QoutbarR_p(:),ZV_Qext_p(:), & 33 | ZV_k_p(:),ZV_x_p(:), & 34 | ZV_VbarR_p(:) 35 | 36 | 37 | !******************************************************************************* 38 | !Get local sizes for vectors 39 | !******************************************************************************* 40 | call VecGetLocalSize(ZV_QoutbarR,IS_localsize,ierr) 41 | 42 | 43 | !******************************************************************************* 44 | !Calculation of Volume 45 | !******************************************************************************* 46 | call MatMult(ZM_Net,ZV_QoutbarR,ZV_VbarR,ierr) 47 | !Vbar=Net*QoutbarR 48 | 49 | call VecGetArrayF90(ZV_QoutbarR,ZV_QoutbarR_p,ierr) 50 | call VecGetArrayF90(ZV_Qext,ZV_Qext_p,ierr) 51 | call VecGetArrayF90(ZV_k,ZV_k_p,ierr) 52 | call VecGetArrayF90(ZV_x,ZV_x_p,ierr) 53 | call VecGetArrayF90(ZV_VbarR,ZV_VbarR_p,ierr) 54 | 55 | do JS_localsize=1,IS_localsize 56 | ZV_VbarR_p(JS_localsize)=ZV_VbarR_p(JS_localsize)+ZV_Qext_p(JS_localsize) 57 | !VbarR=VbarR+Qext 58 | ZV_VbarR_p(JS_localsize)=ZV_VbarR_p(JS_localsize)*ZV_x_p(JS_localsize) 59 | !VbarR=VbarR*x 60 | ZV_VbarR_p(JS_localsize)=ZV_VbarR_p(JS_localsize) & 61 | +(1-ZV_x_p(JS_localsize)) & 62 | *ZV_QoutbarR_p(JS_localsize) 63 | !VbarR=VbarR+(1-x)*QoutbarR 64 | ZV_VbarR_p(JS_localsize)=ZV_VbarR_p(JS_localsize)*ZV_k_p(JS_localsize) 65 | !VbarR=VbarR*x 66 | end do 67 | 68 | call VecRestoreArrayF90(ZV_QoutbarR,ZV_QoutbarR_p,ierr) 69 | call VecRestoreArrayF90(ZV_Qext,ZV_Qext_p,ierr) 70 | call VecRestoreArrayF90(ZV_k,ZV_k_p,ierr) 71 | call VecRestoreArrayF90(ZV_x,ZV_x_p,ierr) 72 | call VecRestoreArrayF90(ZV_VbarR,ZV_VbarR_p,ierr) 73 | 74 | 75 | !******************************************************************************* 76 | !End subroutine 77 | !******************************************************************************* 78 | end subroutine rapid_QtoV 79 | -------------------------------------------------------------------------------- /src/rapid_cli.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_cli 3 | !******************************************************************************* 4 | subroutine rapid_cli 5 | 6 | !Purpose: 7 | !Command line interface for RAPID. 8 | !Authors: 9 | !Kel Markert and Cedric H. David, 2021-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use rapid_var, only : & 16 | rank, & 17 | YV_version,namelist_file 18 | implicit none 19 | 20 | 21 | !******************************************************************************* 22 | !Intent (in/out), and local variables 23 | !******************************************************************************* 24 | integer :: IS_arg, JS_arg 25 | character(len=50) :: YV_arg 26 | 27 | 28 | !******************************************************************************* 29 | !Default namelist 30 | !******************************************************************************* 31 | namelist_file='./rapid_namelist' 32 | 33 | 34 | !******************************************************************************* 35 | !Get the version of RAPID determined during build 36 | !******************************************************************************* 37 | #ifdef RAPID_VERSION 38 | YV_version=RAPID_VERSION 39 | #else 40 | YV_version='unknown' 41 | #endif 42 | !Compilation examples: -D RAPID_VERSION="'v1.4.0'" 43 | ! -D RAPID_VERSION="'20131114'" 44 | 45 | 46 | !******************************************************************************* 47 | !Get number of command line arguments 48 | !******************************************************************************* 49 | IS_arg=command_argument_count() 50 | 51 | 52 | !******************************************************************************* 53 | !Evaluate command line options and perform associated action 54 | !******************************************************************************* 55 | do JS_arg=1,IS_arg 56 | call get_command_argument(JS_arg, YV_arg) 57 | !-------------------------------------------------------------------------- 58 | !help 59 | !-------------------------------------------------------------------------- 60 | if (YV_arg=='-h' .or. YV_arg=='--help') then 61 | if (rank==0) then 62 | print *, 'Help message to be added' 63 | end if 64 | call exit(0) 65 | end if 66 | !-------------------------------------------------------------------------- 67 | !vesion 68 | !-------------------------------------------------------------------------- 69 | if (YV_arg=='-v' .or. YV_arg=='--version') then 70 | if (rank==0) then 71 | print *, 'RAPID: ' // YV_version 72 | end if 73 | call exit(0) 74 | end if 75 | !-------------------------------------------------------------------------- 76 | !namelist 77 | !-------------------------------------------------------------------------- 78 | if (YV_arg=='-nl' .or. YV_arg=='--namelist') then 79 | if (JS_arg+1<=IS_arg) then 80 | call get_command_argument(JS_arg+1, YV_arg) 81 | namelist_file=YV_arg 82 | else 83 | print *, 'ERROR: Missing argument after -nl (or --namelist)' 84 | call exit(22) 85 | end if 86 | end if 87 | !-------------------------------------------------------------------------- 88 | ! 89 | !-------------------------------------------------------------------------- 90 | end do 91 | 92 | 93 | !******************************************************************************* 94 | !End subroutine 95 | !******************************************************************************* 96 | end subroutine rapid_cli 97 | -------------------------------------------------------------------------------- /src/rapid_close_Qfinal_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_close_Qfinal_file 3 | !******************************************************************************* 4 | subroutine rapid_close_Qfinal_file 5 | 6 | !Purpose: 7 | !Close Qfinal_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2017-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use netcdf 16 | use rapid_var, only : & 17 | rank,IS_nc_status,IS_nc_id_fil_Qfinal 18 | implicit none 19 | 20 | 21 | !******************************************************************************* 22 | !Intent (in/out), and local variables 23 | !******************************************************************************* 24 | 25 | 26 | !******************************************************************************* 27 | !Close file 28 | !******************************************************************************* 29 | if (rank==0) IS_nc_status=NF90_CLOSE(IS_nc_id_fil_Qfinal) 30 | 31 | 32 | !******************************************************************************* 33 | !End subroutine 34 | !******************************************************************************* 35 | end subroutine rapid_close_Qfinal_file 36 | -------------------------------------------------------------------------------- /src/rapid_close_Qfor_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_close_Qfor_file 3 | !******************************************************************************* 4 | subroutine rapid_close_Qfor_file 5 | 6 | !Purpose: 7 | !Close Qfor_file from Fortran. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use rapid_var, only : & 16 | rank 17 | implicit none 18 | 19 | 20 | !******************************************************************************* 21 | !Intent (in/out), and local variables 22 | !******************************************************************************* 23 | 24 | 25 | !******************************************************************************* 26 | !Close file 27 | !******************************************************************************* 28 | if (rank==0) close(34) 29 | 30 | !******************************************************************************* 31 | !End subroutine 32 | !******************************************************************************* 33 | end subroutine rapid_close_Qfor_file 34 | -------------------------------------------------------------------------------- /src/rapid_close_Qhum_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_close_Qhum_file 3 | !******************************************************************************* 4 | subroutine rapid_close_Qhum_file 5 | 6 | !Purpose: 7 | !Close Qhum_file from Fortran. 8 | !Author: 9 | !Cedric H. David, 2014-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use rapid_var, only : & 16 | rank 17 | implicit none 18 | 19 | 20 | !******************************************************************************* 21 | !Intent (in/out), and local variables 22 | !******************************************************************************* 23 | 24 | 25 | !******************************************************************************* 26 | !Close file 27 | !******************************************************************************* 28 | if (rank==0) close(36) 29 | 30 | !******************************************************************************* 31 | !End subroutine 32 | !******************************************************************************* 33 | end subroutine rapid_close_Qhum_file 34 | -------------------------------------------------------------------------------- /src/rapid_close_Qinit_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_close_Qinit_file 3 | !******************************************************************************* 4 | subroutine rapid_close_Qinit_file 5 | 6 | !Purpose: 7 | !Close Qinit_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2017-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use netcdf 16 | use rapid_var, only : & 17 | rank,IS_nc_status,IS_nc_id_fil_Qinit 18 | implicit none 19 | 20 | 21 | !******************************************************************************* 22 | !Intent (in/out), and local variables 23 | !******************************************************************************* 24 | 25 | 26 | !******************************************************************************* 27 | !Close file 28 | !******************************************************************************* 29 | if (rank==0) IS_nc_status=NF90_CLOSE(IS_nc_id_fil_Qinit) 30 | 31 | 32 | !******************************************************************************* 33 | !End subroutine 34 | !******************************************************************************* 35 | end subroutine rapid_close_Qinit_file 36 | -------------------------------------------------------------------------------- /src/rapid_close_Qobs_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_close_Qobs_file 3 | !******************************************************************************* 4 | subroutine rapid_close_Qobs_file 5 | 6 | !Purpose: 7 | !Close Qobs_file from Fortran. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use rapid_var, only : & 16 | rank 17 | implicit none 18 | 19 | 20 | !******************************************************************************* 21 | !Intent (in/out), and local variables 22 | !******************************************************************************* 23 | 24 | 25 | !******************************************************************************* 26 | !Close file 27 | !******************************************************************************* 28 | if (rank==0) close(33) 29 | 30 | !******************************************************************************* 31 | !End subroutine 32 | !******************************************************************************* 33 | end subroutine rapid_close_Qobs_file 34 | -------------------------------------------------------------------------------- /src/rapid_close_Qout_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_close_Qout_file 3 | !******************************************************************************* 4 | subroutine rapid_close_Qout_file 5 | 6 | !Purpose: 7 | !Close Qout_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use netcdf 16 | use rapid_var, only : & 17 | rank,IS_nc_status,IS_nc_id_fil_Qout 18 | implicit none 19 | 20 | 21 | !******************************************************************************* 22 | !Intent (in/out), and local variables 23 | !******************************************************************************* 24 | 25 | 26 | !******************************************************************************* 27 | !Close file 28 | !******************************************************************************* 29 | if (rank==0) IS_nc_status=NF90_CLOSE(IS_nc_id_fil_Qout) 30 | 31 | 32 | !******************************************************************************* 33 | !End subroutine 34 | !******************************************************************************* 35 | end subroutine rapid_close_Qout_file 36 | -------------------------------------------------------------------------------- /src/rapid_close_V_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_close_V_file 3 | !******************************************************************************* 4 | subroutine rapid_close_V_file 5 | 6 | !Purpose: 7 | !Close V_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2015-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use netcdf 16 | use rapid_var, only : & 17 | rank,IS_nc_status,IS_nc_id_fil_V 18 | implicit none 19 | 20 | 21 | !******************************************************************************* 22 | !Intent (in/out), and local variables 23 | !******************************************************************************* 24 | 25 | 26 | !******************************************************************************* 27 | !Close file 28 | !******************************************************************************* 29 | if (rank==0) IS_nc_status=NF90_CLOSE(IS_nc_id_fil_V) 30 | 31 | 32 | !******************************************************************************* 33 | !End subroutine 34 | !******************************************************************************* 35 | end subroutine rapid_close_V_file 36 | -------------------------------------------------------------------------------- /src/rapid_close_Vlat_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_close_Vlat_file 3 | !******************************************************************************* 4 | subroutine rapid_close_Vlat_file 5 | 6 | !Purpose: 7 | !Close Qobs_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use netcdf 16 | use rapid_var, only : & 17 | rank,IS_nc_status,IS_nc_id_fil_Vlat 18 | implicit none 19 | 20 | 21 | !******************************************************************************* 22 | !Intent (in/out), and local variables 23 | !******************************************************************************* 24 | 25 | 26 | !******************************************************************************* 27 | !Close file 28 | !******************************************************************************* 29 | if (rank==0) IS_nc_status=NF90_CLOSE(IS_nc_id_fil_Vlat) 30 | 31 | 32 | !******************************************************************************* 33 | !End subroutine 34 | !******************************************************************************* 35 | end subroutine rapid_close_Vlat_file 36 | -------------------------------------------------------------------------------- /src/rapid_destro_obj.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_destro_obj 3 | !******************************************************************************* 4 | subroutine rapid_destro_obj 5 | 6 | !Purpose: 7 | !All PETSc and TAO objects need be destroyed (requirement of both mathematical 8 | !libraries). PETSc and TAO also need be finalized. This is what's done here 9 | !Note: only finilized here, need to add destroy of vectors. 10 | !Author: 11 | !Cedric H. David, 2008-2024. 12 | 13 | 14 | !******************************************************************************* 15 | !Fortran includes, modules, and implicity 16 | !******************************************************************************* 17 | #include 18 | use petsctao 19 | use rapid_var, only : & 20 | IS_riv_bas, & 21 | ZM_hsh_tot,ZM_hsh_bas, & 22 | ZM_Net,ZM_A,ZM_T,ZM_TC1,ZM_M, & 23 | ZM_Obs,ZV_Qobs,ZV_temp1,ZV_temp2,ZV_kfac, & 24 | ZV_k,ZV_x,ZV_p,ZV_pnorm,ZV_pfac, & 25 | ZV_C1,ZV_C2,ZV_C3,ZV_Cdenom, & 26 | ZV_b,ZV_babsmax,ZV_bhat, & 27 | ZV_Qext,ZV_Qfor,ZV_Qlat,ZV_Qhum,ZV_Qdam, & 28 | ZV_Vext,ZV_Vfor,ZV_Vlat, & 29 | ZV_VinitM,ZV_QoutinitM,ZV_QoutinitO,ZV_QoutbarO, & 30 | ZV_QoutR,ZV_QoutinitR,ZV_QoutprevR,ZV_QoutbarR,ZV_QinbarR, & 31 | ZV_QoutRabsmin,ZV_QoutRabsmax,ZV_QoutRhat, & 32 | ZV_VR,ZV_VinitR,ZV_VprevR,ZV_VbarR,ZV_VoutR, & 33 | ZV_Qobsbarrec, & 34 | ZV_bQlat,ZV_vQlat,ZV_caQlat,ZV_bQout,ZV_sQout,ZV_rQout, & 35 | ZV_nbuptot, & 36 | ierr,ksp,vecscat,ZV_SeqZero,ZV_one, & 37 | tao,ZV_1stIndex,ZV_2ndIndex, & 38 | ZM_Pb,ZM_L,ZM_H,ZM_S,ZM_HPbt,ZM_HPbHt, & 39 | ZV_Qbmean,ZV_dQeb,ksp2,ZV_QoutinitR_save, & 40 | IS_opt_run 41 | implicit none 42 | 43 | 44 | !******************************************************************************* 45 | !Destroy all objects and finalize PETSc and TAO 46 | !******************************************************************************* 47 | call VecDestroy(ZV_1stIndex,ierr) 48 | call VecDestroy(ZV_2ndIndex,ierr) 49 | call TaoDestroy(tao,ierr) 50 | 51 | call KSPDestroy(ksp,ierr) 52 | call KSPDestroy(ksp2,ierr) 53 | 54 | call MatDestroy(ZM_hsh_tot,ierr) 55 | call MatDestroy(ZM_hsh_bas,ierr) 56 | 57 | call MatDestroy(ZM_A,ierr) 58 | call MatDestroy(ZM_Net,ierr) 59 | call MatDestroy(ZM_T,ierr) 60 | call MatDestroy(ZM_TC1,ierr) 61 | call MatDestroy(ZM_M,ierr) 62 | call MatDestroy(ZM_Obs,ierr) 63 | 64 | call MatDestroy(ZM_Pb,ierr) 65 | if (IS_opt_run.ne.3) call MatDestroy(ZM_L,ierr) 66 | if (IS_opt_run.eq.3) then 67 | call MatDestroy(ZM_H,ierr) 68 | call MatDestroy(ZM_S,ierr) 69 | call MatDestroy(ZM_HPbt,ierr) 70 | call MatDestroy(ZM_HPbHt,ierr) 71 | end if 72 | 73 | call VecDestroy(ZV_k,ierr) 74 | call VecDestroy(ZV_x,ierr) 75 | call VecDestroy(ZV_C1,ierr) 76 | call VecDestroy(ZV_C2,ierr) 77 | call VecDestroy(ZV_C3,ierr) 78 | call VecDestroy(ZV_Cdenom,ierr) 79 | 80 | call VecDestroy(ZV_b,ierr) 81 | call VecDestroy(ZV_babsmax,ierr) 82 | call VecDestroy(ZV_bhat,ierr) 83 | 84 | call VecDestroy(ZV_Qext,ierr) 85 | call VecDestroy(ZV_Qfor,ierr) 86 | call VecDestroy(ZV_Qlat,ierr) 87 | call VecDestroy(ZV_Qhum,ierr) 88 | call VecDestroy(ZV_Qdam,ierr) 89 | call VecDestroy(ZV_Vext,ierr) 90 | call VecDestroy(ZV_Vfor,ierr) 91 | call VecDestroy(ZV_Vlat,ierr) 92 | 93 | call VecDestroy(ZV_QoutinitM,ierr) 94 | call VecDestroy(ZV_QoutinitO,ierr) 95 | call VecDestroy(ZV_QoutbarO,ierr) 96 | 97 | call VecDestroy(ZV_QoutR,ierr) 98 | call VecDestroy(ZV_QoutinitR,ierr) 99 | call VecDestroy(ZV_QoutprevR,ierr) 100 | call VecDestroy(ZV_QoutbarR,ierr) 101 | call VecDestroy(ZV_QinbarR,ierr) 102 | call VecDestroy(ZV_QoutRabsmin,ierr) 103 | call VecDestroy(ZV_QoutRabsmax,ierr) 104 | call VecDestroy(ZV_QoutRhat,ierr) 105 | 106 | call VecDestroy(ZV_QoutinitR_save,ierr) 107 | 108 | call VecDestroy(ZV_VinitM,ierr) 109 | 110 | call VecDestroy(ZV_VR,ierr) 111 | call VecDestroy(ZV_VinitR,ierr) 112 | call VecDestroy(ZV_VprevR,ierr) 113 | call VecDestroy(ZV_VbarR,ierr) 114 | call VecDestroy(ZV_VoutR,ierr) 115 | 116 | call VecDestroy(ZV_temp1,ierr) 117 | call VecDestroy(ZV_temp2,ierr) 118 | call VecDestroy(ZV_Qobs,ierr) 119 | call VecDestroy(ZV_kfac,ierr) 120 | call VecDestroy(ZV_Qobsbarrec,ierr) 121 | 122 | call VecDestroy(ZV_one,ierr) 123 | 124 | call VecDestroy(ZV_p,ierr) 125 | call VecDestroy(ZV_pnorm,ierr) 126 | call VecDestroy(ZV_pfac,ierr) 127 | 128 | call VecDestroy(ZV_nbuptot,ierr) 129 | call VecDestroy(ZV_bQlat,ierr) 130 | call VecDestroy(ZV_vQlat,ierr) 131 | call VecDestroy(ZV_caQlat,ierr) 132 | call VecDestroy(ZV_bQout,ierr) 133 | call VecDestroy(ZV_sQout,ierr) 134 | call VecDestroy(ZV_rQout,ierr) 135 | 136 | call VecDestroy(ZV_Qbmean,ierr) 137 | call VecDestroy(ZV_dQeb,ierr) 138 | 139 | call VecDestroy(ZV_SeqZero,ierr) 140 | call VecScatterDestroy(vecscat,ierr) 141 | !Need to be destroyed separately even though created together 142 | 143 | call PetscFinalize(ierr) 144 | 145 | 146 | !******************************************************************************* 147 | !End subroutine 148 | !******************************************************************************* 149 | end subroutine rapid_destro_obj 150 | -------------------------------------------------------------------------------- /src/rapid_kf_cov_mat.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_kf_cov_mat 3 | !******************************************************************************* 4 | subroutine rapid_kf_cov_mat 5 | 6 | !Purpose: 7 | !Compute runoff error covariance matrices in Kalman gain 8 | !ZM_HPbt = (ZM_Pb*ZM_H^(T))^(T) 9 | !ZM_HPbHt = ZM_H*ZM_Pb*ZM_H^(T) 10 | !Authors: 11 | !Charlotte M. Emery, and Cedric H. David, 2018-2024. 12 | 13 | 14 | !******************************************************************************* 15 | !Fortran includes, modules, and implicity 16 | !******************************************************************************* 17 | #include 18 | use petscmat 19 | use rapid_var, only : & 20 | ZM_Pb,ZM_H,ZM_HPbt,ZM_HPbHt,ierr 21 | implicit none 22 | 23 | 24 | !******************************************************************************* 25 | !Local variables 26 | !******************************************************************************* 27 | 28 | Mat :: ZM_Ht 29 | 30 | !******************************************************************************* 31 | !Compute matrix ZM_HPbt : H*Pb^(T) = H*Pb as Pb symmetric 32 | !******************************************************************************* 33 | 34 | call MatMatMult(ZM_H, & 35 | ZM_Pb, & 36 | MAT_INITIAL_MATRIX, & 37 | PETSC_DEFAULT_REAL, & 38 | ZM_HPbt, & 39 | ierr) 40 | 41 | !******************************************************************************* 42 | !Compute matrix ZM_HPbHt 43 | !******************************************************************************* 44 | 45 | call MatTranspose(ZM_H,MAT_INITIAL_MATRIX,ZM_Ht,ierr) 46 | 47 | call MatMatMult(ZM_HPbt, & 48 | ZM_Ht, & 49 | MAT_INITIAL_MATRIX, & 50 | PETSC_DEFAULT_REAL, & 51 | ZM_HPbHt, & 52 | ierr) 53 | 54 | call PetscPrintf(PETSC_COMM_WORLD,'Kalman Filter control error covariance matrix created' & 55 | //char(10),ierr) 56 | 57 | !******************************************************************************* 58 | !Delete temporary variables 59 | !******************************************************************************* 60 | call MatDestroy(ZM_Ht,ierr) 61 | 62 | 63 | !******************************************************************************* 64 | !End subroutine 65 | !******************************************************************************* 66 | call PetscPrintf(PETSC_COMM_WORLD,'--------------------------'//char(10),ierr) 67 | 68 | end subroutine rapid_kf_cov_mat 69 | -------------------------------------------------------------------------------- /src/rapid_kf_obs_mat.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_kf_obs_mat 3 | !******************************************************************************* 4 | subroutine rapid_kf_obs_mat 5 | 6 | !Purpose: 7 | !Using the set of available observation gage, 8 | !Compute the observation operator for data assimilation (ZM_H) 9 | !This operator is a submatrix of runoff-to-discharge operator (ZM_L) 10 | !As it contains only the rows of ZM_L that corresponds to potentially 11 | !observed reach 12 | !Authors: 13 | !Charlotte M. Emery, and Cedric H. David, 2018-2024. 14 | 15 | 16 | !******************************************************************************* 17 | !Fortran includes, modules, and implicity 18 | !******************************************************************************* 19 | #include 20 | use petscmat 21 | use rapid_var, only : & 22 | IS_riv_bas, & 23 | IV_obs_loc1,IS_obs_bas,JS_obs_bas, & 24 | ierr,rank, & 25 | IS_one,ZS_one, & 26 | ZM_L,ZM_S,ZM_H 27 | implicit none 28 | 29 | 30 | !******************************************************************************* 31 | !Intent (in/out), and local variables 32 | !******************************************************************************* 33 | 34 | PetscInt :: IS_val 35 | PetscInt :: ISobs_ownfirst, ISobs_ownlast 36 | 37 | PetscInt, dimension(:), allocatable :: IV_sorted_obs_loc1, IV_sort 38 | PetscInt, dimension(:), allocatable :: IVobs_nz, IVobs_dnz, IVobs_onz 39 | 40 | !******************************************************************************* 41 | !Prepare for selection operator preallocation 42 | !******************************************************************************* 43 | 44 | !------------------------------------------------------------------------------- 45 | !Allocate/Initialize local (temporary variables) 46 | !------------------------------------------------------------------------------- 47 | 48 | allocate(IV_sorted_obs_loc1(IS_obs_bas)) 49 | allocate(IV_sort(IS_obs_bas)) 50 | 51 | allocate(IVobs_nz(IS_obs_bas)) 52 | allocate(IVobs_dnz(IS_obs_bas)) 53 | allocate(IVobs_onz(IS_obs_bas)) 54 | 55 | IVobs_nz(:) = 1 56 | IVobs_dnz(:) = 1 57 | IVobs_onz(:) = 0 58 | 59 | !------------------------------------------------------------------------------- 60 | !Sort observation gages from upstream to downstream 61 | !------------------------------------------------------------------------------- 62 | 63 | do JS_obs_bas = 1,IS_obs_bas 64 | IV_sort(JS_obs_bas) = IV_obs_loc1(JS_obs_bas) 65 | end do 66 | 67 | do JS_obs_bas = 1,IS_obs_bas 68 | IS_val = MINLOC(IV_sort,DIM=1) 69 | IV_sorted_obs_loc1(JS_obs_bas) = IV_sort(IS_val) 70 | IV_sort(IS_val) = MAXVAL(IV_sort)+1 71 | end do 72 | 73 | !------------------------------------------------------------------------------- 74 | !Create observation operator matrix 75 | !------------------------------------------------------------------------------- 76 | 77 | call MatCreate(PETSC_COMM_WORLD,ZM_S,ierr) 78 | call MatSetSizes(ZM_S,PETSC_DECIDE,PETSC_DECIDE,IS_obs_bas,IS_riv_bas,ierr) 79 | call MatSetFromOptions(ZM_S,ierr) 80 | call MatSetUp(ZM_S,ierr) 81 | 82 | !------------------------------------------------------------------------------- 83 | !Count non-zeros in ZM_S 84 | !------------------------------------------------------------------------------- 85 | 86 | call MatGetOwnershipRange(ZM_S,ISobs_ownfirst,ISobs_ownlast,ierr) 87 | 88 | do JS_obs_bas = 1,IS_obs_bas 89 | 90 | IS_val = IV_sorted_obs_loc1(JS_obs_bas) 91 | 92 | if (((JS_obs_bas.ge.ISobs_ownfirst+1).and.(JS_obs_bas.lt.ISobs_ownlast+1)).and. & 93 | ((IS_val.ge.ISobs_ownfirst).and.(IS_val.lt.ISobs_ownlast))) then 94 | IVobs_dnz(JS_obs_bas) = 1 95 | end if 96 | 97 | if (((JS_obs_bas.ge.ISobs_ownfirst+1).and.(JS_obs_bas.lt.ISobs_ownlast+1)).and. & 98 | ((IS_val.lt.ISobs_ownfirst).or.(IS_val.ge.ISobs_ownlast))) then 99 | IVobs_onz(JS_obs_bas) = 1 100 | end if 101 | end do 102 | 103 | 104 | !******************************************************************************* 105 | !Selection operator preallocation 106 | !******************************************************************************* 107 | 108 | call MatSeqAIJSetPreallocation(ZM_S,PETSC_DEFAULT_INTEGER,IVobs_nz,ierr) 109 | call MatMPIAIJSetPreallocation(ZM_S, & 110 | PETSC_DEFAULT_INTEGER, & 111 | IVobs_dnz(ISobs_ownfirst+1:ISobs_ownlast), & 112 | PETSC_DEFAULT_INTEGER, & 113 | IVobs_onz(ISobs_ownfirst+1:ISobs_ownlast),ierr) 114 | 115 | !******************************************************************************* 116 | !Compute operator preallocation 117 | !******************************************************************************* 118 | 119 | if (rank.eq.0) then 120 | 121 | do JS_obs_bas = 1,IS_obs_bas 122 | IS_val = IV_sorted_obs_loc1(JS_obs_bas) 123 | 124 | call MatSetValues(ZM_S, & 125 | IS_one, & 126 | JS_obs_bas-1, & 127 | IS_one, & 128 | IS_val, & 129 | ZS_one, & 130 | INSERT_VALUES,ierr) 131 | 132 | end do 133 | 134 | end if 135 | 136 | call MatAssemblyBegin(ZM_S,MAT_FINAL_ASSEMBLY,ierr) 137 | call MatAssemblyEnd(ZM_S,MAT_FINAL_ASSEMBLY,ierr) 138 | 139 | !******************************************************************************* 140 | !Compute observation operator ZM_H = ZM_S*ZM_L 141 | !******************************************************************************* 142 | 143 | call MatMatMult(ZM_S,ZM_L,MAT_INITIAL_MATRIX,PETSC_DEFAULT_REAL,ZM_H,ierr) 144 | 145 | call PetscPrintf(PETSC_COMM_WORLD,'Observation operator ZM_H created'//char(10),ierr) 146 | 147 | !******************************************************************************* 148 | !Free up memory used by local (temporary) variables 149 | !******************************************************************************* 150 | 151 | deallocate(IV_sorted_obs_loc1) 152 | deallocate(IV_sort) 153 | 154 | call MatDestroy(ZM_L,ierr) 155 | 156 | !******************************************************************************* 157 | !End subroutine 158 | !******************************************************************************* 159 | end subroutine rapid_kf_obs_mat 160 | -------------------------------------------------------------------------------- /src/rapid_kf_update.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_kf_updade 3 | !******************************************************************************* 4 | subroutine rapid_kf_update 5 | 6 | !Purpose: 7 | !Compute the Kalman filter update: 8 | ! dQeb = Pb*H^(T)*( H*Pb*H^(T) + R )^(-1)(Qobs-HQeb) 9 | !Authors: 10 | !Charlotte M. Emery, and Cedric H. David, 2018-2024. 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | #include 16 | use petscksp 17 | use rapid_var, only : & 18 | ierr,ksp2, & 19 | ZS_one,ZS_stdobs, & 20 | IS_obs_bas, & 21 | ZV_dQeb,ZV_Qbmean,ZV_Qobs, & 22 | ZM_S,ZM_HPbt,ZM_HPbHt 23 | implicit none 24 | 25 | 26 | !******************************************************************************* 27 | !Local variables 28 | !******************************************************************************* 29 | 30 | Vec :: ZV_D 31 | Vec :: ZV_R 32 | Vec :: ZV_xb 33 | Mat :: ZM_HPbHt_R 34 | 35 | !******************************************************************************* 36 | !Build innovation 37 | !******************************************************************************* 38 | 39 | !------------------------------------------------------------------------------- 40 | !Build innovation in control space 41 | !------------------------------------------------------------------------------- 42 | 43 | call VecAYPX(ZV_Qbmean,-ZS_one,ZV_Qobs,ierr) 44 | !ZV_Qb = ZV_Qobs-ZV_Qb 45 | 46 | 47 | !------------------------------------------------------------------------------- 48 | !Create innovation vector in observation space 49 | !------------------------------------------------------------------------------- 50 | 51 | call VecCreate(PETSC_COMM_WORLD,ZV_D,ierr) 52 | call VecSetSizes(ZV_D,PETSC_DECIDE,IS_obs_bas,ierr) 53 | call VecSetFromOptions(ZV_D,ierr) 54 | 55 | !------------------------------------------------------------------------------- 56 | !Build innovation in observation space 57 | !------------------------------------------------------------------------------- 58 | 59 | call MatMult(ZM_S,ZV_Qbmean,ZV_D,ierr) 60 | !ZV_D = ZM_S*(ZV_Qobs-ZV_Qb) 61 | 62 | !******************************************************************************* 63 | !Build observation error vector 64 | !******************************************************************************* 65 | 66 | !------------------------------------------------------------------------------- 67 | !Build observation error vector in control space 68 | !------------------------------------------------------------------------------ 69 | 70 | call VecScale(ZV_Qobs,ZS_stdobs,ierr) 71 | call VecPow(ZV_Qobs,2*ZS_one,ierr) 72 | 73 | !------------------------------------------------------------------------------- 74 | !Create observation error vector in observation space 75 | !------------------------------------------------------------------------------- 76 | 77 | call VecCreate(PETSC_COMM_WORLD,ZV_R,ierr) 78 | call VecSetSizes(ZV_R,PETSC_DECIDE,IS_obs_bas,ierr) 79 | call VecSetFromOptions(ZV_R,ierr) 80 | 81 | !------------------------------------------------------------------------------- 82 | !Build observation error vector in observation space 83 | !------------------------------------------------------------------------------- 84 | 85 | call MatMult(ZM_S,ZV_Qobs,ZV_R,ierr) 86 | !ZV_R = ZM_S*(ZS_stdobs*ZV_Qobs) 87 | 88 | 89 | !******************************************************************************* 90 | !Build ( HPbHt+R )^(-1)*ZV_D 91 | !******************************************************************************* 92 | 93 | !------------------------------------------------------------------------------- 94 | !Set matrix for linear system 95 | !------------------------------------------------------------------------------- 96 | 97 | call MatDuplicate(ZM_HPbHt,MAT_COPY_VALUES,ZM_HPbHt_R,ierr) 98 | call MatDiagonalSet(ZM_HPbHt_R,ZV_R,ADD_VALUES,ierr) 99 | !HPbHt+R 100 | 101 | call KSPSetOperators(ksp2,ZM_HPbHt_R,ZM_HPbHt_R,ierr) 102 | !Set KSP2 to use matrix ZM_HPbHt 103 | 104 | !------------------------------------------------------------------------------- 105 | !Create linear system unknown vector 106 | !------------------------------------------------------------------------------- 107 | 108 | call VecCreate(PETSC_COMM_WORLD,ZV_xb,ierr) 109 | call VecSetSizes(ZV_xb,PETSC_DECIDE,IS_obs_bas,ierr) 110 | call VecSetFromOptions(ZV_xb,ierr) 111 | 112 | !------------------------------------------------------------------------------- 113 | !Solve linear system 114 | !------------------------------------------------------------------------------- 115 | 116 | call KSPSolve(ksp2,ZV_D,ZV_xb,ierr) 117 | !ZV_xb = ( ZM_HPbHt+diag(ZV_R) )^(-1)*ZV_D 118 | !ZV_xb = ( HPbHt+R )^(-1)*(yo-Hxb) 119 | 120 | 121 | !******************************************************************************* 122 | !Compute kalman update 123 | !******************************************************************************* 124 | 125 | call MatMultTranspose(ZM_HPbt,ZV_xb,ZV_dQeb,ierr) 126 | !ZV_dQeb = [ZM_HPbt]^(T)*ZV_xb 127 | !ZV_dQeb = ZM_Pb*ZM_Ht*( HPbHt+R )^(-1)*(yo-Hxb) 128 | 129 | 130 | !******************************************************************************* 131 | !Delete temporary variables 132 | !******************************************************************************* 133 | 134 | call VecDestroy(ZV_D,ierr) 135 | call VecDestroy(ZV_R,ierr) 136 | call VecDestroy(ZV_xb,ierr) 137 | 138 | call MatDestroy(ZM_HPbHt_R,ierr) 139 | 140 | !******************************************************************************* 141 | !End subroutine 142 | !******************************************************************************* 143 | end subroutine rapid_kf_update 144 | -------------------------------------------------------------------------------- /src/rapid_meta_Vlat_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_meta_Vlat_file 3 | !******************************************************************************* 4 | subroutine rapid_meta_Vlat_file(Vlat_file) 5 | 6 | !Purpose: 7 | !Read metadata for Vlat_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2016-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use netcdf 16 | use rapid_var, only : & 17 | rank,IS_nc_status,IS_nc_id_fil_Vlat, & 18 | IS_nc_id_var_time,IS_nc_id_var_time_bnds,IS_nc_id_var_crs, & 19 | IS_nc_id_var_lon,IS_nc_id_var_lat,IS_nc_id_var_Vlat_err, & 20 | IS_riv_tot,IS_riv_bas,IS_time,JS_time,ZS_TauR, & 21 | YV_title,YV_institution,YV_comment, & 22 | YV_time_units,ZS_crs_sma,ZS_crs_iflat, & 23 | ZV_riv_tot_lon,ZV_riv_tot_lat,IV_time,IM_time_bnds, & 24 | ZV_riv_tot_bQlat,ZV_riv_tot_vQlat,ZV_riv_tot_caQlat,ZS_dtUQ,& 25 | ZV_riv_tot_cdownQlat,IS_radius 26 | implicit none 27 | 28 | 29 | !******************************************************************************* 30 | !Intent (in/out), and local variables 31 | !******************************************************************************* 32 | character(len=*), intent(in):: Vlat_file 33 | 34 | 35 | !******************************************************************************* 36 | !Read global attributes 37 | !******************************************************************************* 38 | if (rank==0) then 39 | IS_nc_status=NF90_GET_ATT(IS_nc_id_fil_Vlat,NF90_GLOBAL, \ 40 | "title", YV_title) 41 | IS_nc_status=NF90_GET_ATT(IS_nc_id_fil_Vlat,NF90_GLOBAL, \ 42 | "institution", YV_institution) 43 | IS_nc_status=NF90_GET_ATT(IS_nc_id_fil_Vlat,NF90_GLOBAL, \ 44 | "comment", YV_comment) 45 | end if 46 | 47 | 48 | !******************************************************************************* 49 | !Read variable attributes 50 | !******************************************************************************* 51 | if (rank==0) then 52 | IS_nc_status=NF90_GET_ATT(IS_nc_id_fil_Vlat,IS_nc_id_var_time, \ 53 | "units", YV_time_units) 54 | IS_nc_status=NF90_GET_ATT(IS_nc_id_fil_Vlat,IS_nc_id_var_crs, \ 55 | "semi_major_axis", ZS_crs_sma) 56 | IS_nc_status=NF90_GET_ATT(IS_nc_id_fil_Vlat,IS_nc_id_var_crs, \ 57 | "inverse_flattening", ZS_crs_iflat) 58 | end if 59 | 60 | 61 | !******************************************************************************* 62 | !Read space and time variable values 63 | !******************************************************************************* 64 | if (rank==0) then 65 | if (IS_nc_id_var_lon>=0) then 66 | IS_nc_status=NF90_GET_VAR(IS_nc_id_fil_Vlat,IS_nc_id_var_lon, \ 67 | ZV_riv_tot_lon,(/1/),(/IS_riv_tot/)) 68 | end if 69 | if (IS_nc_id_var_lat>=0) then 70 | IS_nc_status=NF90_GET_VAR(IS_nc_id_fil_Vlat,IS_nc_id_var_lat, \ 71 | ZV_riv_tot_lat,(/1/),(/IS_riv_tot/)) 72 | end if 73 | if (IS_nc_id_var_time>=0) then 74 | IS_nc_status=NF90_GET_VAR(IS_nc_id_fil_Vlat,IS_nc_id_var_time, \ 75 | IV_time,(/1/),(/IS_time/)) 76 | end if 77 | if (IS_nc_id_var_time_bnds>=0) then 78 | IS_nc_status=NF90_GET_VAR(IS_nc_id_fil_Vlat,IS_nc_id_var_time_bnds, \ 79 | IM_time_bnds,(/1,1/),(/2,IS_time/)) 80 | end if 81 | end if 82 | 83 | 84 | !******************************************************************************* 85 | !Read uncertainty quantification inputs, convert from volume to flow 86 | !******************************************************************************* 87 | if (rank==0) then 88 | if (IS_nc_id_var_Vlat_err>=0) then 89 | IS_nc_status=NF90_GET_VAR(IS_nc_id_fil_Vlat,IS_nc_id_var_Vlat_err, \ 90 | ZV_riv_tot_bQlat,(/1,1/),(/IS_riv_tot,1/)) 91 | IS_nc_status=NF90_GET_VAR(IS_nc_id_fil_Vlat,IS_nc_id_var_Vlat_err, \ 92 | ZV_riv_tot_vQlat,(/1,2/),(/IS_riv_tot,1/)) 93 | IS_nc_status=NF90_GET_VAR(IS_nc_id_fil_Vlat,IS_nc_id_var_Vlat_err, \ 94 | ZV_riv_tot_caQlat,(/1,3/),(/IS_riv_tot,1/)) 95 | IS_nc_status=NF90_GET_VAR(IS_nc_id_fil_Vlat,IS_nc_id_var_Vlat_err, \ 96 | ZV_riv_tot_cdownQlat,(/1,4/),(/IS_riv_tot,IS_radius/)) 97 | 98 | ZV_riv_tot_bQlat=sign(sqrt(abs(ZV_riv_tot_bQlat)),ZV_riv_tot_bQlat)/ZS_dtUQ 99 | ZV_riv_tot_vQlat=ZV_riv_tot_vQlat/(ZS_dtUQ**2) 100 | ZV_riv_tot_caQlat=ZV_riv_tot_caQlat/(ZS_dtUQ**2) 101 | ZV_riv_tot_cdownQlat=ZV_riv_tot_cdownQlat/(ZS_dtUQ**2) 102 | end if 103 | end if 104 | 105 | 106 | !******************************************************************************* 107 | !Check temporal consistency if metadata present 108 | !******************************************************************************* 109 | if (IV_time(1)/=-9999) then 110 | do JS_time=1,IS_time-1 111 | if (IV_time(JS_time+1)-IV_time(JS_time)/=int(ZS_TauR)) then 112 | !Checking that interval between values of the time variable is ZS_TauR 113 | print '(a53)','Inconsistent time intervals in namelist and Vlat_file' 114 | stop 99 115 | end if 116 | end do 117 | end if 118 | 119 | if (IM_time_bnds(1,1)/=-9999) then 120 | do JS_time=1,IS_time-1 121 | if (IM_time_bnds(1,JS_time+1)-IM_time_bnds(1,JS_time)/=int(ZS_TauR)) then 122 | !Checking that interval between values of the time_bnd variable is ZS_TauR 123 | print '(a53)','Inconsistent time intervals in namelist and Vlat_file' 124 | stop 99 125 | end if 126 | end do 127 | do JS_time=1,IS_time 128 | if (IM_time_bnds(2,JS_time)-IM_time_bnds(1,JS_time)/=int(ZS_TauR)) then 129 | !Checking that interval for each value of the time_bnd variable is ZS_TauR 130 | print '(a53)','Inconsistent time intervals in namelist and Vlat_file' 131 | stop 99 132 | end if 133 | end do 134 | end if 135 | 136 | 137 | !******************************************************************************* 138 | !End subroutine 139 | !******************************************************************************* 140 | end subroutine rapid_meta_Vlat_file 141 | -------------------------------------------------------------------------------- /src/rapid_obs_mat.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_obs_mat 3 | !******************************************************************************* 4 | subroutine rapid_obs_mat 5 | 6 | !Purpose: 7 | !Creates a kronecker-type diagonal sparse matrix. "1" is recorded at the row 8 | !and column where observations are available. 9 | !Author: 10 | !Cedric H. David, 2008-2024. 11 | 12 | 13 | !******************************************************************************* 14 | !Fortran includes, modules, and implicity 15 | !******************************************************************************* 16 | #include 17 | use petscmat 18 | use rapid_var, only : & 19 | IS_riv_bas,JS_riv_bas, & 20 | IS_obs_bas,JS_obs_bas, & 21 | IV_riv_bas_id,IV_obs_tot_id, & 22 | IV_obs_index, & 23 | ZM_Obs,ZS_norm, & 24 | ierr, & 25 | IS_one,ZS_one,temp_char 26 | implicit none 27 | 28 | 29 | !******************************************************************************* 30 | !Preallocation of the observation matrix 31 | !******************************************************************************* 32 | call MatSeqAIJSetPreallocation(ZM_Obs,1*IS_one,PETSC_NULL_INTEGER,ierr) 33 | call MatMPIAIJSetPreallocation(ZM_Obs,1*IS_one,PETSC_NULL_INTEGER,0*IS_one, & 34 | PETSC_NULL_INTEGER,ierr) 35 | !Very basic preallocation assuming that all reaches have one gage. Cannot use 36 | !IV_obs_loc1 for preallocation because it is of size IS_obs_bas and not 37 | !IS_riv_bas. To do a better preallocation one needs to count the diagonal 38 | !elements in a new vector 39 | 40 | !call PetscPrintf(PETSC_COMM_WORLD,'Observation matrix preallocated'//char(10), & 41 | ! ierr) 42 | 43 | 44 | !******************************************************************************* 45 | !Creation of the observation matrix 46 | !******************************************************************************* 47 | do JS_riv_bas=1,IS_riv_bas 48 | do JS_obs_bas=1,IS_obs_bas 49 | 50 | if (IV_obs_tot_id(IV_obs_index(JS_obs_bas))==IV_riv_bas_id(JS_riv_bas)) then 51 | call MatSetValues(ZM_Obs,IS_one,JS_riv_bas-1,IS_one,JS_riv_bas-1, & 52 | ZS_one,INSERT_VALUES,ierr) 53 | end if 54 | 55 | enddo 56 | enddo 57 | 58 | call MatAssemblyBegin(ZM_Obs,MAT_FINAL_ASSEMBLY,ierr) 59 | call MatAssemblyEnd(ZM_Obs,MAT_FINAL_ASSEMBLY,ierr) 60 | !sparse matrices need be assembled once their elements have been filled 61 | 62 | 63 | !******************************************************************************* 64 | !Optional: calculation of number of gaging stations used in subbasin 65 | !******************************************************************************* 66 | call MatNorm(ZM_Obs,NORM_FROBENIUS,ZS_norm,ierr) 67 | ZS_norm=ZS_norm*ZS_norm 68 | write(temp_char,'(f10.1)') ZS_norm 69 | call PetscPrintf(PETSC_COMM_WORLD,'Number of gage IDs in ' // & 70 | 'this simulation (based on norm):' // temp_char // char(10), & 71 | ierr) 72 | 73 | 74 | !******************************************************************************* 75 | !Display matrix on stdout 76 | !******************************************************************************* 77 | !call PetscPrintf(PETSC_COMM_WORLD,'ZM_Obs:'//char(10),ierr) 78 | !call MatView(ZM_Obs,PETSC_VIEWER_STDOUT_WORLD,ierr) 79 | 80 | 81 | !******************************************************************************* 82 | !End subroutine 83 | !******************************************************************************* 84 | call PetscPrintf(PETSC_COMM_WORLD,'Observation matrix created'//char(10),ierr) 85 | call PetscPrintf(PETSC_COMM_WORLD,'--------------------------'//char(10),ierr) 86 | 87 | end subroutine rapid_obs_mat 88 | -------------------------------------------------------------------------------- /src/rapid_open_Qfinal_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_open_Qfinal_file 3 | !******************************************************************************* 4 | subroutine rapid_open_Qfinal_file(Qfinal_file) 5 | 6 | !Purpose: 7 | !Open Qfinal_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2017-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use netcdf 16 | use rapid_var, only : & 17 | rank,IS_nc_status,IS_nc_id_fil_Qfinal,IS_nc_id_var_Qfinal 18 | implicit none 19 | 20 | 21 | !******************************************************************************* 22 | !Intent (in/out), and local variables 23 | !******************************************************************************* 24 | character(len=*), intent(in):: Qfinal_file 25 | 26 | 27 | !******************************************************************************* 28 | !Open file 29 | !******************************************************************************* 30 | if (rank==0) then 31 | open(99,file=Qfinal_file,status='old') 32 | close(99) 33 | IS_nc_status=NF90_OPEN(Qfinal_file,NF90_WRITE,IS_nc_id_fil_Qfinal) 34 | IS_nc_status=NF90_INQ_VARID(IS_nc_id_fil_Qfinal,'Qout',IS_nc_id_var_Qfinal) 35 | end if 36 | 37 | 38 | !******************************************************************************* 39 | !End subroutine 40 | !******************************************************************************* 41 | end subroutine rapid_open_Qfinal_file 42 | -------------------------------------------------------------------------------- /src/rapid_open_Qfor_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_open_Qfor 3 | !******************************************************************************* 4 | subroutine rapid_open_Qfor_file(Qfor_file) 5 | 6 | !Purpose: 7 | !Open Qfor_file from Fortran. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use rapid_var, only : & 16 | rank 17 | implicit none 18 | 19 | 20 | !******************************************************************************* 21 | !Intent (in/out), and local variables 22 | !******************************************************************************* 23 | character(len=*), intent(in):: Qfor_file 24 | 25 | 26 | !******************************************************************************* 27 | !Open file 28 | !******************************************************************************* 29 | if (rank==0) open(34,file=Qfor_file,status='old') 30 | 31 | 32 | !******************************************************************************* 33 | !End subroutine 34 | !******************************************************************************* 35 | end subroutine rapid_open_Qfor_file 36 | -------------------------------------------------------------------------------- /src/rapid_open_Qhum_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_open_Qhum 3 | !******************************************************************************* 4 | subroutine rapid_open_Qhum_file(Qhum_file) 5 | 6 | !Purpose: 7 | !Open Qhum_file from Fortran. 8 | !Author: 9 | !Cedric H. David, 2014-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use rapid_var, only : & 16 | rank 17 | implicit none 18 | 19 | 20 | !******************************************************************************* 21 | !Intent (in/out), and local variables 22 | !******************************************************************************* 23 | character(len=*), intent(in):: Qhum_file 24 | 25 | 26 | !******************************************************************************* 27 | !Open file 28 | !******************************************************************************* 29 | if (rank==0) open(36,file=Qhum_file,status='old') 30 | 31 | 32 | !******************************************************************************* 33 | !End subroutine 34 | !******************************************************************************* 35 | end subroutine rapid_open_Qhum_file 36 | -------------------------------------------------------------------------------- /src/rapid_open_Qinit_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_open_Qinit_file 3 | !******************************************************************************* 4 | subroutine rapid_open_Qinit_file(Qinit_file) 5 | 6 | !Purpose: 7 | !Open Qinit_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2017-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use netcdf 16 | use rapid_var, only : & 17 | rank,IS_nc_status,IS_nc_id_fil_Qinit,IS_nc_id_var_Qinit 18 | implicit none 19 | 20 | 21 | !******************************************************************************* 22 | !Intent (in/out), and local variables 23 | !******************************************************************************* 24 | character(len=*), intent(in):: Qinit_file 25 | 26 | 27 | !******************************************************************************* 28 | !Open file 29 | !******************************************************************************* 30 | if (rank==0) then 31 | open(30,file=Qinit_file,status='old') 32 | close(30) 33 | IS_nc_status=NF90_OPEN(Qinit_file,NF90_WRITE,IS_nc_id_fil_Qinit) 34 | IS_nc_status=NF90_INQ_VARID(IS_nc_id_fil_Qinit,'Qout',IS_nc_id_var_Qinit) 35 | end if 36 | 37 | 38 | !******************************************************************************* 39 | !End subroutine 40 | !******************************************************************************* 41 | end subroutine rapid_open_Qinit_file 42 | -------------------------------------------------------------------------------- /src/rapid_open_Qobs_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_open_Qobs 3 | !******************************************************************************* 4 | subroutine rapid_open_Qobs_file(Qobs_file) 5 | 6 | !Purpose: 7 | !Open Qobs_file from Fortran. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use rapid_var, only : & 16 | rank 17 | implicit none 18 | 19 | 20 | !******************************************************************************* 21 | !Intent (in/out), and local variables 22 | !******************************************************************************* 23 | character(len=*), intent(in):: Qobs_file 24 | 25 | 26 | !******************************************************************************* 27 | !Open file 28 | !******************************************************************************* 29 | if (rank==0) open(33,file=Qobs_file,status='old') 30 | 31 | 32 | !******************************************************************************* 33 | !End subroutine 34 | !******************************************************************************* 35 | end subroutine rapid_open_Qobs_file 36 | -------------------------------------------------------------------------------- /src/rapid_open_Qout_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_open_Qout_file 3 | !******************************************************************************* 4 | subroutine rapid_open_Qout_file(Qout_file) 5 | 6 | !Purpose: 7 | !Open Qout_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use netcdf 16 | use rapid_var, only : & 17 | rank,IS_nc_status,IS_nc_id_fil_Qout,IS_nc_id_var_Qout 18 | implicit none 19 | 20 | 21 | !******************************************************************************* 22 | !Intent (in/out), and local variables 23 | !******************************************************************************* 24 | character(len=*), intent(in):: Qout_file 25 | 26 | 27 | !******************************************************************************* 28 | !Open file 29 | !******************************************************************************* 30 | if (rank==0) then 31 | open(99,file=Qout_file,status='old') 32 | close(99) 33 | IS_nc_status=NF90_OPEN(Qout_file,NF90_WRITE,IS_nc_id_fil_Qout) 34 | IS_nc_status=NF90_INQ_VARID(IS_nc_id_fil_Qout,'Qout',IS_nc_id_var_Qout) 35 | end if 36 | 37 | 38 | !******************************************************************************* 39 | !End subroutine 40 | !******************************************************************************* 41 | end subroutine rapid_open_Qout_file 42 | -------------------------------------------------------------------------------- /src/rapid_open_V_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_open_V_file 3 | !******************************************************************************* 4 | subroutine rapid_open_V_file(V_file) 5 | 6 | !Purpose: 7 | !Open V_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2015-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use netcdf 16 | use rapid_var, only : & 17 | rank,IS_nc_status,IS_nc_id_fil_V,IS_nc_id_var_V 18 | implicit none 19 | 20 | 21 | !******************************************************************************* 22 | !Intent (in/out), and local variables 23 | !******************************************************************************* 24 | character(len=*), intent(in):: V_file 25 | 26 | 27 | !******************************************************************************* 28 | !Open file 29 | !******************************************************************************* 30 | if (rank==0) then 31 | open(99,file=V_file,status='old') 32 | close(99) 33 | IS_nc_status=NF90_OPEN(V_file,NF90_WRITE,IS_nc_id_fil_V) 34 | IS_nc_status=NF90_INQ_VARID(IS_nc_id_fil_V,'V',IS_nc_id_var_V) 35 | end if 36 | 37 | 38 | !******************************************************************************* 39 | !End subroutine 40 | !******************************************************************************* 41 | end subroutine rapid_open_V_file 42 | -------------------------------------------------------------------------------- /src/rapid_open_Vlat_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_open_Vlat_file 3 | !******************************************************************************* 4 | subroutine rapid_open_Vlat_file(Vlat_file) 5 | 6 | !Purpose: 7 | !Open Vlat_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | use netcdf 16 | use rapid_var, only : & 17 | rank,IS_nc_status,IS_nc_id_fil_Vlat,IS_nc_id_var_Vlat, & 18 | IS_nc_id_var_time,IS_nc_id_var_time_bnds,IS_nc_id_var_crs, & 19 | IS_nc_id_var_lon,IS_nc_id_var_lat, IS_nc_id_var_Vlat_err 20 | implicit none 21 | 22 | 23 | !******************************************************************************* 24 | !Intent (in/out), and local variables 25 | !******************************************************************************* 26 | character(len=*), intent(in):: Vlat_file 27 | 28 | 29 | !******************************************************************************* 30 | !Open file 31 | !******************************************************************************* 32 | if (rank==0) then 33 | open(99,file=Vlat_file,status='old') 34 | close(99) 35 | IS_nc_status=NF90_OPEN(Vlat_file,NF90_NOWRITE,IS_nc_id_fil_Vlat) 36 | IS_nc_status=NF90_INQ_VARID(IS_nc_id_fil_Vlat,'m3_riv',IS_nc_id_var_Vlat) 37 | if (IS_nc_status<0) IS_nc_id_var_Vlat=-9999 38 | IS_nc_status=NF90_INQ_VARID(IS_nc_id_fil_Vlat,'time',IS_nc_id_var_time) 39 | if (IS_nc_status<0) IS_nc_id_var_time=-9999 40 | IS_nc_status=NF90_INQ_VARID(IS_nc_id_fil_Vlat,'time_bnds', \ 41 | IS_nc_id_var_time_bnds) 42 | if (IS_nc_status<0) IS_nc_id_var_time_bnds=-9999 43 | IS_nc_status=NF90_INQ_VARID(IS_nc_id_fil_Vlat,'lon',IS_nc_id_var_lon) 44 | if (IS_nc_status<0) IS_nc_id_var_lon=-9999 45 | IS_nc_status=NF90_INQ_VARID(IS_nc_id_fil_Vlat,'lat',IS_nc_id_var_lat) 46 | if (IS_nc_status<0) IS_nc_id_var_lat=-9999 47 | IS_nc_status=NF90_INQ_VARID(IS_nc_id_fil_Vlat,'crs',IS_nc_id_var_crs) 48 | if (IS_nc_status<0) IS_nc_id_var_crs=-9999 49 | IS_nc_status=NF90_INQ_VARID(IS_nc_id_fil_Vlat,'m3_riv_err', \ 50 | IS_nc_id_var_Vlat_err) 51 | if (IS_nc_status<0) IS_nc_id_var_Vlat_err=-9999 52 | !A negative value for IS_nc_id_var_* is used if the variable doesn't exist, 53 | !this is because the default value of "1" might match another existing 54 | !variable. 55 | end if 56 | 57 | 58 | !******************************************************************************* 59 | !End subroutine 60 | !******************************************************************************* 61 | end subroutine rapid_open_Vlat_file 62 | -------------------------------------------------------------------------------- /src/rapid_petsc_includes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #rapid_petsc_includes.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #Determine which Fortran 90 files need which PETSc modules and includes. 8 | #Author: 9 | #Cedric H. David, 2020-2024. 10 | 11 | 12 | #******************************************************************************* 13 | #Tao 14 | #******************************************************************************* 15 | echo '********************' 16 | echo '- List of Fortran files that need petsctao.h' 17 | grep -l 'Tao' *.F90 18 | 19 | 20 | #******************************************************************************* 21 | #KSP 22 | #******************************************************************************* 23 | echo '********************' 24 | echo '- List of Fortran files that need petscksp.h' 25 | grep -L 'Tao' *.F90 | xargs -r grep -l 'KSP' 26 | 27 | 28 | #******************************************************************************* 29 | #PC 30 | #******************************************************************************* 31 | echo '********************' 32 | echo '- List of Fortran files that need petscpc.h' 33 | grep -L 'Tao' *.F90 | xargs -r grep -L 'KSP' | xargs -r grep -l 'PC' 34 | 35 | 36 | #******************************************************************************* 37 | #Mat 38 | #******************************************************************************* 39 | echo '********************' 40 | echo '- List of Fortran files that need petscmat.h' 41 | grep -L 'Tao' *.F90 | xargs -r grep -L 'KSP' | xargs -r grep -L 'PC' | xargs -r grep -l 'Mat' 42 | 43 | 44 | #******************************************************************************* 45 | #Vec 46 | #******************************************************************************* 47 | echo '********************' 48 | echo '- List of Fortran files that need petscvec.h' 49 | grep -L 'Tao' *.F90 | xargs -r grep -L 'KSP' | xargs -r grep -L 'PC' | xargs -r grep -L 'Mat' | xargs -r grep -l 'Vec' 50 | 51 | 52 | #******************************************************************************* 53 | #Sys 54 | #******************************************************************************* 55 | echo '********************' 56 | echo '- List of Fortran files that need petscsys.h' 57 | grep -L 'Tao' *.F90 | xargs -r grep -L 'KSP' | xargs -r grep -L 'PC' | xargs -r grep -L 'Mat' | xargs -r grep -L 'Vec' | xargs -r grep -l 'ierr' 58 | 59 | 60 | #******************************************************************************* 61 | #No PETSc 62 | #******************************************************************************* 63 | echo '********************' 64 | echo '- List of Fortran files that do not need PETSc includes' 65 | grep -L 'Tao' *.F90 | xargs -r grep -L 'KSP' | xargs -r grep -L 'PC' | xargs -r grep -L 'Mat' | xargs -r grep -L 'Vec' | xargs -r grep -L 'ierr' 66 | 67 | 68 | #******************************************************************************* 69 | #end 70 | #******************************************************************************* 71 | echo '********************' 72 | -------------------------------------------------------------------------------- /src/rapid_read_Qfor_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_read_Qfor_file 3 | !******************************************************************************* 4 | subroutine rapid_read_Qfor_file 5 | 6 | !Purpose: 7 | !Read Qfor_file from Fortran. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | #include 16 | use petscvec 17 | use rapid_var, only : & 18 | rank,ierr,ZV_read_for_tot, & 19 | ZV_Qfor,IS_for_bas,IV_for_loc2,IV_for_index,ZV_read_for_tot 20 | implicit none 21 | 22 | 23 | !******************************************************************************* 24 | !Intent (in/out), and local variables 25 | !******************************************************************************* 26 | 27 | 28 | !******************************************************************************* 29 | !Read file 30 | !******************************************************************************* 31 | if (rank==0) read(34,*) ZV_read_for_tot 32 | 33 | 34 | !******************************************************************************* 35 | !Set values in PETSc vector 36 | !******************************************************************************* 37 | if (rank==0) then 38 | call VecSetValues(ZV_Qfor,IS_for_bas,IV_for_loc2, & 39 | ZV_read_for_tot(IV_for_index),INSERT_VALUES,ierr) 40 | !here we only look at the forcing within the basin studied 41 | end if 42 | 43 | !******************************************************************************* 44 | !Assemble PETSc vector 45 | !******************************************************************************* 46 | call VecAssemblyBegin(ZV_Qfor,ierr) 47 | call VecAssemblyEnd(ZV_Qfor,ierr) 48 | 49 | 50 | !******************************************************************************* 51 | !End subroutine 52 | !******************************************************************************* 53 | end subroutine rapid_read_Qfor_file 54 | -------------------------------------------------------------------------------- /src/rapid_read_Qhum_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_read_Qhum_file 3 | !******************************************************************************* 4 | subroutine rapid_read_Qhum_file 5 | 6 | !Purpose: 7 | !Read Qhum_file from Fortran. 8 | !Author: 9 | !Cedric H. David, 2014-2024. 10 | 11 | 12 | !!******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | #include 16 | use petscvec 17 | use rapid_var, only : & 18 | rank,ierr,ZV_read_hum_tot, & 19 | ZV_Qhum,IS_hum_bas,IV_hum_loc1,IV_hum_index,ZV_read_hum_tot 20 | implicit none 21 | 22 | 23 | !******************************************************************************* 24 | !Intent (in/out), and local variables 25 | !******************************************************************************* 26 | 27 | 28 | !******************************************************************************* 29 | !Read file 30 | !******************************************************************************* 31 | if (rank==0) read(36,*) ZV_read_hum_tot 32 | 33 | 34 | !******************************************************************************* 35 | !Set values in PETSc vector 36 | !******************************************************************************* 37 | if (rank==0) then 38 | call VecSetValues(ZV_Qhum,IS_hum_bas,IV_hum_loc1, & 39 | ZV_read_hum_tot(IV_hum_index),INSERT_VALUES,ierr) 40 | !here we only look at the human-induced flows within the basin 41 | !studied 42 | end if 43 | 44 | !******************************************************************************* 45 | !Assemble PETSc vector 46 | !******************************************************************************* 47 | call VecAssemblyBegin(ZV_Qhum,ierr) 48 | call VecAssemblyEnd(ZV_Qhum,ierr) 49 | 50 | 51 | !******************************************************************************* 52 | !End subroutine 53 | !******************************************************************************* 54 | end subroutine rapid_read_Qhum_file 55 | -------------------------------------------------------------------------------- /src/rapid_read_Qinit_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_read_Qinit_file 3 | !******************************************************************************* 4 | subroutine rapid_read_Qinit_file 5 | 6 | !Purpose: 7 | !Read Qinit_file from Fortran. 8 | !Author: 9 | !Cedric H. David, 2017-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | #include 16 | use petscvec 17 | use netcdf 18 | use rapid_var, only : & 19 | rank,ierr, & 20 | IS_nc_status,IS_nc_id_fil_Qinit,IS_nc_id_var_Qinit, & 21 | IS_riv_bas,IV_riv_loc1,IV_riv_index,ZV_read_riv_tot, & 22 | IS_riv_tot,ZV_QoutinitM 23 | implicit none 24 | 25 | 26 | !******************************************************************************* 27 | !Intent (in/out), and local variables 28 | !******************************************************************************* 29 | 30 | 31 | !******************************************************************************* 32 | !Read file 33 | !******************************************************************************* 34 | if (rank==0) then 35 | IS_nc_status=NF90_GET_VAR(IS_nc_id_fil_Qinit,IS_nc_id_var_Qinit, & 36 | ZV_read_riv_tot,(/1,1/),(/IS_riv_tot,1/)) 37 | end if 38 | 39 | 40 | !******************************************************************************* 41 | !Set values in PETSc vector 42 | !******************************************************************************* 43 | if (rank==0) then 44 | call VecSetValues(ZV_QoutinitM,IS_riv_bas,IV_riv_loc1, & 45 | ZV_read_riv_tot(IV_riv_index),INSERT_VALUES,ierr) 46 | end if 47 | 48 | 49 | !******************************************************************************* 50 | !Assemble PETSc vector 51 | !******************************************************************************* 52 | call VecAssemblyBegin(ZV_QoutinitM,ierr) 53 | call VecAssemblyEnd(ZV_QoutinitM,ierr) 54 | 55 | 56 | !******************************************************************************* 57 | !End subroutine 58 | !******************************************************************************* 59 | end subroutine rapid_read_Qinit_file 60 | -------------------------------------------------------------------------------- /src/rapid_read_Qobs_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_read_Qobs_file 3 | !******************************************************************************* 4 | subroutine rapid_read_Qobs_file 5 | 6 | !Purpose: 7 | !Read Qobs_file from Fortran. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | #include 16 | use petscvec 17 | use rapid_var, only : & 18 | rank,ierr, & 19 | ZV_Qobs,IS_obs_bas,IV_obs_loc1,IV_obs_index,ZV_read_obs_tot 20 | implicit none 21 | 22 | 23 | !******************************************************************************* 24 | !Intent (in/out), and local variables 25 | !******************************************************************************* 26 | 27 | 28 | !******************************************************************************* 29 | !Read file 30 | !******************************************************************************* 31 | if (rank==0) read(33,*) ZV_read_obs_tot 32 | 33 | 34 | !******************************************************************************* 35 | !Set values in PETSc vector 36 | !******************************************************************************* 37 | if (rank==0) then 38 | call VecSetValues(ZV_Qobs,IS_obs_bas,IV_obs_loc1, & 39 | ZV_read_obs_tot(IV_obs_index),INSERT_VALUES,ierr) 40 | !here we only look at the observations within the basin 41 | !studied 42 | end if 43 | 44 | 45 | !******************************************************************************* 46 | !Assemble PETSc vector 47 | !******************************************************************************* 48 | call VecAssemblyBegin(ZV_Qobs,ierr) 49 | call VecAssemblyEnd(ZV_Qobs,ierr) 50 | 51 | 52 | !******************************************************************************* 53 | !End subroutine 54 | !******************************************************************************* 55 | end subroutine rapid_read_Qobs_file 56 | -------------------------------------------------------------------------------- /src/rapid_read_Vlat_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_read_Vlat_file 3 | !******************************************************************************* 4 | subroutine rapid_read_Vlat_file 5 | 6 | !Purpose: 7 | !Read Vlat_file from Fortran. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | #include 16 | use petscvec 17 | use netcdf 18 | use rapid_var, only : & 19 | rank,ierr, & 20 | IS_nc_status,IS_nc_id_fil_Vlat,IS_nc_id_var_Vlat, & 21 | IV_nc_start,IV_nc_count, & 22 | IS_riv_bas,IV_riv_loc1,IV_riv_index,ZV_read_riv_tot,ZV_Vlat 23 | implicit none 24 | 25 | 26 | !******************************************************************************* 27 | !Intent (in/out), and local variables 28 | !******************************************************************************* 29 | 30 | 31 | !******************************************************************************* 32 | !Read file 33 | !******************************************************************************* 34 | if (rank==0) then 35 | IS_nc_status=NF90_GET_VAR(IS_nc_id_fil_Vlat,IS_nc_id_var_Vlat, & 36 | ZV_read_riv_tot,IV_nc_start,IV_nc_count) 37 | end if 38 | 39 | 40 | !******************************************************************************* 41 | !Set values in PETSc vector 42 | !******************************************************************************* 43 | if (rank==0) then 44 | call VecSetValues(ZV_Vlat,IS_riv_bas,IV_riv_loc1, & 45 | ZV_read_riv_tot(IV_riv_index),INSERT_VALUES,ierr) 46 | end if 47 | 48 | 49 | !******************************************************************************* 50 | !Assemble PETSc vector 51 | !******************************************************************************* 52 | call VecAssemblyBegin(ZV_Vlat,ierr) 53 | call VecAssemblyEnd(ZV_Vlat,ierr) 54 | 55 | 56 | !******************************************************************************* 57 | !End subroutine 58 | !******************************************************************************* 59 | end subroutine rapid_read_Vlat_file 60 | -------------------------------------------------------------------------------- /src/rapid_read_namelist.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_read_namelist 3 | !******************************************************************************* 4 | subroutine rapid_read_namelist 5 | 6 | !Purpose: 7 | !This subroutine allows to read the RAPID namelist and hence to run the model 8 | !multiple times without ever have to recompile. Some information on the options 9 | !used is also printed in the stdout. 10 | !Author: 11 | !Cedric H. David, 2011-2024. 12 | 13 | 14 | !******************************************************************************* 15 | !Fortran includes, modules, and implicity 16 | !******************************************************************************* 17 | use rapid_var, only : & 18 | NL_namelist,namelist_file 19 | implicit none 20 | 21 | 22 | !******************************************************************************* 23 | !Read namelist file 24 | !******************************************************************************* 25 | open(88,file=namelist_file,status='old',form='formatted') 26 | read(88, NL_namelist) 27 | close(88) 28 | 29 | 30 | !******************************************************************************* 31 | !Optional prints what was read 32 | !******************************************************************************* 33 | !print *, namelist_file 34 | 35 | 36 | !******************************************************************************* 37 | !End subroutine 38 | !******************************************************************************* 39 | end subroutine rapid_read_namelist 40 | -------------------------------------------------------------------------------- /src/rapid_routing_param.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_routing_param 3 | !******************************************************************************* 4 | subroutine rapid_routing_param(ZV_k,ZV_x, & 5 | ZV_C1,ZV_C2,ZV_C3,ZM_A) 6 | 7 | !Purpose: 8 | !Calculates the Muskingum method (McCarthy 1938) parameters C1, C2 and C3. 9 | !Also calculates the matrix A used for linear system solver. 10 | !Author: 11 | !Cedric H. David, 2010-2024. 12 | 13 | 14 | !******************************************************************************* 15 | !Fortran includes, modules, and implicity 16 | !******************************************************************************* 17 | #include 18 | use petscmat 19 | use rapid_var, only : & 20 | ZM_Net,ZM_T,ZM_TC1, & 21 | ZV_Cdenom,ZS_dtR, & 22 | ierr,ZS_one,ZV_one,IS_opt_routing 23 | implicit none 24 | 25 | 26 | !******************************************************************************* 27 | !Intent (in/out), and local variables 28 | !******************************************************************************* 29 | Vec, intent(in) :: ZV_k,ZV_x 30 | Vec, intent(inout) :: ZV_C1,ZV_C2,ZV_C3 31 | Mat, intent(inout) :: ZM_A 32 | 33 | 34 | !******************************************************************************* 35 | !Calculation of the Muskingum method constants (C1,C2,C3) and of the matrix A 36 | !used in the linear system A*Qout=b 37 | !******************************************************************************* 38 | call VecCopy(ZV_x,ZV_Cdenom,ierr) 39 | call VecScale(ZV_Cdenom,-ZS_one,ierr) 40 | call VecShift(ZV_Cdenom,ZS_one,ierr) 41 | call VecPointwiseMult(ZV_Cdenom,ZV_Cdenom,ZV_k,ierr) 42 | call VecShift(ZV_Cdenom,ZS_dtR/2,ierr) 43 | !Cdenom=k*(1-x)+dtR/2 44 | 45 | call VecPointwiseMult(ZV_C1,ZV_k,ZV_x,ierr) 46 | call VecScale(ZV_C1,-ZS_one,ierr) 47 | call VecShift(ZV_C1,ZS_dtR/2,ierr) 48 | call VecPointwiseDivide(ZV_C1,ZV_C1,ZV_Cdenom,ierr) 49 | !C1=(-k*x+dtR/2)/Cdenom 50 | 51 | call VecPointwiseMult(ZV_C2,ZV_k,ZV_x,ierr) 52 | call VecShift(ZV_C2,ZS_dtR/2,ierr) 53 | call VecPointwiseDivide(ZV_C2,ZV_C2,ZV_Cdenom,ierr) 54 | !C2=(k*x+dtR/2)/Cdenom 55 | 56 | call VecCopy(ZV_x,ZV_C3,ierr) 57 | call VecScale(ZV_C3,-ZS_one,ierr) 58 | call VecShift(ZV_C3,ZS_one,ierr) 59 | call VecPointwiseMult(ZV_C3,ZV_C3,ZV_k,ierr) 60 | call VecShift(ZV_C3,-ZS_dtR/2,ierr) 61 | call VecPointwiseDivide(ZV_C3,ZV_C3,ZV_Cdenom,ierr) 62 | !C3=(k*(1-x)-dtR/2)/Cdenom 63 | !C1, C2 and C3 completed 64 | 65 | 66 | call MatCopy(ZM_Net,ZM_A,DIFFERENT_NONZERO_PATTERN,ierr) !A=Net 67 | call MatDiagonalScale(ZM_A,ZV_C1,ZV_one,ierr) !A=diag(C1)*A 68 | call MatScale(ZM_A,-ZS_one,ierr) !A=-A 69 | call MatShift(ZM_A,ZS_one,ierr) !A=A+1*I 70 | !Result:A=I-diag(C1)*Net 71 | 72 | if (IS_opt_routing==3) then 73 | call MatCopy(ZM_T,ZM_TC1,DIFFERENT_NONZERO_PATTERN,ierr) !TC1=T 74 | call MatDiagonalScale(ZM_TC1,ZV_C1,ZV_one,ierr) !TC1=diag(C1)*TC1 75 | !Result:TC1=T*diag(C1) 76 | end if 77 | 78 | !******************************************************************************* 79 | !End subroutine 80 | !******************************************************************************* 81 | end subroutine rapid_routing_param 82 | -------------------------------------------------------------------------------- /src/rapid_set_Qext0.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_set_Qext0 3 | !******************************************************************************* 4 | subroutine rapid_set_Qext0 5 | 6 | !Purpose: 7 | !This subroutine is only useful if a dam model is used and its goal is to 8 | !properly initialize the flow of water into the dams. 9 | !The inflow of water ZV_Qin_dam_prev from the river network and from outside of 10 | !the river network into the dams is computed based on ZV_QoutbarR and ZV_Qext 11 | !in the subroutine rapid_get_Qdam.F90. 12 | !Therefore, one has to inject the initial value of ZV_Qin_dam_prev (ZV_Qin_dam0) 13 | !into either ZV_QoutbarR or ZV_Qext otherwise the initial value will be 14 | !overwritten in rapid_get_Qdam.F90. The latter is used here (through ZV_Qdam) 15 | !since the modifications made on the network matrix make it difficult to use 16 | !ZV_Qin_dam_prev without creating a new variable. 17 | !Author: 18 | !Cedric H. David, 2013-2024. 19 | 20 | 21 | !******************************************************************************* 22 | !Fortran includes, modules, and implicity 23 | !******************************************************************************* 24 | #include 25 | use petscvec 26 | use rapid_var, only: & 27 | rank,ierr,IS_one,ZS_one, & 28 | ZV_Qdam,ZV_Qext, & 29 | IS_dam_tot,JS_dam_tot,IV_dam_pos, & 30 | ZV_Qin_dam0, & 31 | ZV_Qout_dam_prev,ZV_Qout_dam0 32 | implicit none 33 | 34 | 35 | !******************************************************************************* 36 | !Set Qdam to zero, because this is called at the beginning of every phiroutine 37 | !******************************************************************************* 38 | call VecSet(ZV_Qdam,0*ZS_one,ierr) !Qdam=0 39 | !call VecView(ZV_Qdam,PETSC_VIEWER_STDOUT_WORLD,ierr) 40 | 41 | 42 | !******************************************************************************* 43 | !Set values of Qin_dam0 into Qdam to allow proper initialization 44 | !******************************************************************************* 45 | if (rank==0) then 46 | do JS_dam_tot=1,IS_dam_tot 47 | 48 | if (IV_dam_pos(JS_dam_tot)/=0) then 49 | call VecSetValues(ZV_Qdam,IS_one,IV_dam_pos(JS_dam_tot)-1, & 50 | ZV_Qin_dam0(JS_dam_tot),INSERT_VALUES,ierr) 51 | !print *, IV_dam_pos(JS_dam_tot)-1, ZV_Qin_dam0(JS_dam_tot) 52 | end if 53 | 54 | end do 55 | end if 56 | 57 | call VecAssemblyBegin(ZV_Qdam,ierr) 58 | call VecAssemblyEnd(ZV_Qdam,ierr) 59 | !call VecView(ZV_Qdam,PETSC_VIEWER_STDOUT_WORLD,ierr) 60 | !the values of Qindam0 are set here where the dams are, not downstream of them 61 | 62 | 63 | !******************************************************************************* 64 | !Copy Qdam into Qext and reset Qdam to zero 65 | !******************************************************************************* 66 | call VecCopy(ZV_Qdam,ZV_Qext,ierr) !Qext=Qdam 67 | call VecSet(ZV_Qdam,0*ZS_one,ierr) !Qdam=0 68 | !call VecView(ZV_Qext,PETSC_VIEWER_STDOUT_WORLD,ierr) 69 | 70 | 71 | !******************************************************************************* 72 | !Initialize Qout_dam_prev again or its values differ with each phiroutine call 73 | !******************************************************************************* 74 | if (rank==0) then 75 | ZV_Qout_dam_prev=ZV_Qout_dam0 76 | end if 77 | 78 | 79 | !******************************************************************************* 80 | !End subroutine 81 | !******************************************************************************* 82 | end subroutine rapid_set_Qext0 83 | -------------------------------------------------------------------------------- /src/rapid_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #rapid_version.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script allows determining the version of RAPID that is being used, but 8 | #only if git is installed and if the RAPID git repository is present. Otherwise 9 | #'unknown' is used. 10 | #Author: 11 | #Cedric H. David, 2016-2024. 12 | 13 | 14 | #******************************************************************************* 15 | #Check if a program exists and perform tasks 16 | #******************************************************************************* 17 | if type 'git' > /dev/null; then 18 | #git is installed 19 | if git rev-parse --git-dir > /dev/null 2>&1; then 20 | #this is a git repository 21 | git describe 22 | else 23 | #this is not a git repository 24 | echo "unknown, NOT a git repository" 25 | fi 26 | else 27 | #git is not installed 28 | echo "unknown, git NOT installed" 29 | fi 30 | 31 | 32 | #******************************************************************************* 33 | #end 34 | #******************************************************************************* 35 | -------------------------------------------------------------------------------- /src/rapid_write_Qfinal_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_write_Qfinal_file 3 | !******************************************************************************* 4 | subroutine rapid_write_Qfinal_file 5 | 6 | !Purpose: 7 | !Write into Qfinal_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2017-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | #include 16 | use petscvec 17 | use netcdf 18 | use rapid_var, only : & 19 | rank,ierr,vecscat,ZV_SeqZero,ZV_pointer, & 20 | IS_nc_status,IS_nc_id_fil_Qfinal,IS_nc_id_var_Qfinal, & 21 | IS_nc_id_var_time, & 22 | IV_time,IS_time,ZS_TauR, & 23 | IS_riv_tot,ZV_read_riv_tot,IV_riv_index, & 24 | ZV_QoutR 25 | implicit none 26 | 27 | 28 | !******************************************************************************* 29 | !Intent (in/out), and local variables 30 | !******************************************************************************* 31 | 32 | 33 | !******************************************************************************* 34 | !Gather PETSc vector on processor zero 35 | !******************************************************************************* 36 | call VecScatterBegin(vecscat,ZV_QoutR,ZV_SeqZero, & 37 | INSERT_VALUES,SCATTER_FORWARD,ierr) 38 | call VecScatterEnd(vecscat,ZV_QoutR,ZV_SeqZero, & 39 | INSERT_VALUES,SCATTER_FORWARD,ierr) 40 | 41 | 42 | !******************************************************************************* 43 | !Get array from PETSc vector 44 | !******************************************************************************* 45 | if (rank==0) call VecGetArrayF90(ZV_SeqZero,ZV_pointer,ierr) 46 | 47 | 48 | !******************************************************************************* 49 | !Transform the array from size of IS_riv_bas to size of IS_riv_tot 50 | !******************************************************************************* 51 | if (rank==0) then 52 | ZV_read_riv_tot=0 53 | ZV_read_riv_tot(IV_riv_index)=ZV_pointer 54 | end if 55 | 56 | 57 | !******************************************************************************* 58 | !Write data 59 | !******************************************************************************* 60 | if (rank==0) IS_nc_status=NF90_PUT_VAR(IS_nc_id_fil_Qfinal,IS_nc_id_var_Qfinal,& 61 | ZV_read_riv_tot,(/1,1/),(/IS_riv_tot,1/)) 62 | 63 | if (rank==0 .and. IV_time(1)/=-9999) then 64 | !The default value for 'no data' in rapid_init.F90 is -9999 for time 65 | IS_nc_status=NF90_PUT_VAR(IS_nc_id_fil_Qfinal,IS_nc_id_var_time, & 66 | IV_time(IS_time)+int(ZS_TauR),(/1/)) 67 | !IV_time(IS_time) is the number of seconds since epoch at the beginning of 68 | !the last time step within Vlat_file. We need to shift forward by the 69 | !number of seconds in a time step to obtain the time corresponding to 70 | !Qfinal. 71 | end if 72 | 73 | 74 | !******************************************************************************* 75 | !Restore array to PETSc vector 76 | !******************************************************************************* 77 | if (rank==0) call VecRestoreArrayF90(ZV_SeqZero,ZV_pointer,ierr) 78 | 79 | 80 | !******************************************************************************* 81 | !End subroutine 82 | !******************************************************************************* 83 | end subroutine rapid_write_Qfinal_file 84 | -------------------------------------------------------------------------------- /src/rapid_write_Qout_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_write_Qout_file 3 | !******************************************************************************* 4 | subroutine rapid_write_Qout_file 5 | 6 | !Purpose: 7 | !Write into Qout_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2013-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | #include 16 | use petscvec 17 | use netcdf 18 | use rapid_var, only : & 19 | rank,ierr,vecscat,ZV_SeqZero,ZV_pointer, & 20 | IS_nc_status,IS_nc_id_fil_Qout,IS_nc_id_var_Qout, & 21 | IV_nc_start,IV_nc_count2, & 22 | IS_nc_id_var_time,IS_nc_id_var_time_bnds, & 23 | IV_time,IM_time_bnds, & 24 | ZV_QoutbarR 25 | implicit none 26 | 27 | 28 | !******************************************************************************* 29 | !Intent (in/out), and local variables 30 | !******************************************************************************* 31 | 32 | 33 | !******************************************************************************* 34 | !Gather PETSc vector on processor zero 35 | !******************************************************************************* 36 | call VecScatterBegin(vecscat,ZV_QoutbarR,ZV_SeqZero, & 37 | INSERT_VALUES,SCATTER_FORWARD,ierr) 38 | call VecScatterEnd(vecscat,ZV_QoutbarR,ZV_SeqZero, & 39 | INSERT_VALUES,SCATTER_FORWARD,ierr) 40 | 41 | 42 | !******************************************************************************* 43 | !Get array from PETSc vector 44 | !******************************************************************************* 45 | if (rank==0) call VecGetArrayF90(ZV_SeqZero,ZV_pointer,ierr) 46 | 47 | 48 | !******************************************************************************* 49 | !Write data 50 | !******************************************************************************* 51 | if (rank==0) IS_nc_status=NF90_PUT_VAR(IS_nc_id_fil_Qout,IS_nc_id_var_Qout, & 52 | ZV_pointer,IV_nc_start,IV_nc_count2) 53 | 54 | if (rank==0 .and. IV_time(1)/=-9999) then 55 | !The default value for 'no data' in rapid_init.F90 is -9999 for time 56 | IS_nc_status=NF90_PUT_VAR(IS_nc_id_fil_Qout,IS_nc_id_var_time, & 57 | IV_time(IV_nc_start(2)),(/IV_nc_start(2)/)) 58 | end if 59 | 60 | if (rank==0 .and. IM_time_bnds(1,1)/=-9999) then 61 | !The default value for 'no data' in rapid_init.F90 is -9999 for time_bnds 62 | IS_nc_status=NF90_PUT_VAR(IS_nc_id_fil_Qout,IS_nc_id_var_time_bnds, & 63 | IM_time_bnds(1:2,IV_nc_start(2)), & 64 | (/1,IV_nc_start(2)/),(/2,1/)) 65 | end if 66 | 67 | 68 | !******************************************************************************* 69 | !Restore array to PETSc vector 70 | !******************************************************************************* 71 | if (rank==0) call VecRestoreArrayF90(ZV_SeqZero,ZV_pointer,ierr) 72 | 73 | 74 | !******************************************************************************* 75 | !End subroutine 76 | !******************************************************************************* 77 | end subroutine rapid_write_Qout_file 78 | -------------------------------------------------------------------------------- /src/rapid_write_V_file.F90: -------------------------------------------------------------------------------- 1 | !******************************************************************************* 2 | !Subroutine - rapid_write_V_file 3 | !******************************************************************************* 4 | subroutine rapid_write_V_file 5 | 6 | !Purpose: 7 | !Write into V_file from Fortran/netCDF. 8 | !Author: 9 | !Cedric H. David, 2015-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Fortran includes, modules, and implicity 14 | !******************************************************************************* 15 | #include 16 | use petscvec 17 | use netcdf 18 | use rapid_var, only : & 19 | rank,ierr,vecscat,ZV_SeqZero,ZV_pointer, & 20 | IS_nc_status,IS_nc_id_fil_V,IS_nc_id_var_V, & 21 | IV_nc_start,IV_nc_count2, & 22 | IS_nc_id_var_time,IS_nc_id_var_time_bnds, & 23 | IV_time,IM_time_bnds, & 24 | ZV_VbarR 25 | implicit none 26 | 27 | 28 | !******************************************************************************* 29 | !Intent (in/out), and local variables 30 | !******************************************************************************* 31 | 32 | 33 | !******************************************************************************* 34 | !Gather PETSc vector on processor zero 35 | !******************************************************************************* 36 | call VecScatterBegin(vecscat,ZV_VbarR,ZV_SeqZero, & 37 | INSERT_VALUES,SCATTER_FORWARD,ierr) 38 | call VecScatterEnd(vecscat,ZV_VbarR,ZV_SeqZero, & 39 | INSERT_VALUES,SCATTER_FORWARD,ierr) 40 | 41 | 42 | !******************************************************************************* 43 | !Get array from PETSc vector 44 | !******************************************************************************* 45 | if (rank==0) call VecGetArrayF90(ZV_SeqZero,ZV_pointer,ierr) 46 | 47 | 48 | !******************************************************************************* 49 | !Write data 50 | !******************************************************************************* 51 | if (rank==0) IS_nc_status=NF90_PUT_VAR(IS_nc_id_fil_V,IS_nc_id_var_V, & 52 | ZV_pointer,IV_nc_start,IV_nc_count2) 53 | 54 | if (rank==0 .and. IV_time(1)/=-9999) then 55 | !The default value for 'no data' in rapid_init.F90 is -9999 for time 56 | IS_nc_status=NF90_PUT_VAR(IS_nc_id_fil_V,IS_nc_id_var_time, & 57 | IV_time(IV_nc_start(2)),(/IV_nc_start(2)/)) 58 | end if 59 | 60 | if (rank==0 .and. IM_time_bnds(1,1)/=-9999) then 61 | !The default value for 'no data' in rapid_init.F90 is -9999 for time_bnds 62 | IS_nc_status=NF90_PUT_VAR(IS_nc_id_fil_V,IS_nc_id_var_time_bnds, & 63 | IM_time_bnds(1:2,IV_nc_start(2)), & 64 | (/1,IV_nc_start(2)/),(/2,1/)) 65 | end if 66 | 67 | 68 | !******************************************************************************* 69 | !Restore array to PETSc vector 70 | !******************************************************************************* 71 | if (rank==0) call VecRestoreArrayF90(ZV_SeqZero,ZV_pointer,ierr) 72 | 73 | 74 | !******************************************************************************* 75 | !End subroutine 76 | !******************************************************************************* 77 | end subroutine rapid_write_V_file 78 | -------------------------------------------------------------------------------- /tst/rapid_namelist_MGBM_FRN: -------------------------------------------------------------------------------- 1 | &NL_namelist 2 | !******************************************************************************* 3 | !rapid_namelist_San_Guad_JHM 4 | !******************************************************************************* 5 | 6 | !Purpose: 7 | !This ASCII file contains instructions for RAPID corresponding to San_Guad_JHM. 8 | !Author: 9 | !Cedric H. David, 2017-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Runtime options 14 | !******************************************************************************* 15 | BS_opt_Qinit =.false. 16 | !.false. --> no read initial flow .true. --> read initial flow 17 | 18 | BS_opt_Qfinal =.false. 19 | !.false. --> no write final flow .true. --> write final flow 20 | 21 | BS_opt_V =.false. 22 | !.false. --> no compute volume .true. --> compute volume 23 | 24 | BS_opt_dam =.false. 25 | !.false. --> no dam model used .true. --> dam model used 26 | 27 | BS_opt_for =.false. 28 | !.false. --> no forcing .true. --> forcing 29 | 30 | BS_opt_influence =.false. 31 | !.false. --> no output influence .true. --> output influence 32 | 33 | BS_opt_uq =.false. 34 | !.false. --> no uncertainty quantif. .true. --> uncertainty quantif. 35 | 36 | IS_opt_routing =1 37 | !1 --> matrix-based Muskingum 2 --> traditional Muskingum 38 | !3 --> Transbnd. matrix-based 4 --> Muskingum operator 39 | 40 | IS_opt_run =1 41 | !1 --> regular run 2 --> parameter optimization 42 | 43 | IS_opt_phi =1 44 | !1 --> phi1 2 --> phi2 45 | 46 | !******************************************************************************* 47 | !Temporal information 48 | !******************************************************************************* 49 | ZS_TauM =315619200 50 | !3600*24*1460=126144000 51 | ZS_dtM =86400 52 | !3600*24=86400 53 | 54 | ZS_TauO =31622400 55 | !3600*24*182=15724800 56 | ZS_dtO =86400 57 | !3600*24=86400 58 | 59 | ZS_TauR =10800 60 | !3600*3=10800 61 | ZS_dtR =1800 62 | !60*15=900 63 | 64 | ZS_dtF =86400 65 | !3600*24=86400 66 | 67 | !******************************************************************************* 68 | !Domain in which input data is available 69 | !******************************************************************************* 70 | IS_riv_tot =89356 71 | rapid_connect_file ='../input/MIGBM_GGG/rapid_connect_MIGBM.csv' 72 | IS_max_up =4 73 | Vlat_file ='../input/MIGBM_GGG/m3_riv_MIGBM_20000101_20091231_VIC10_utc.nc' 74 | 75 | !******************************************************************************* 76 | !Domain in which model runs 77 | !******************************************************************************* 78 | IS_riv_bas =89356 79 | riv_bas_id_file ='../input/MIGBM_GGG/riv_bas_id_MIGBM_topo.csv' 80 | 81 | !******************************************************************************* 82 | !Initial instantaneous flow file 83 | !******************************************************************************* 84 | Qinit_file ='' 85 | 86 | !******************************************************************************* 87 | !Final instantaneous flow file 88 | !******************************************************************************* 89 | Qfinal_file ='' 90 | 91 | !******************************************************************************* 92 | !Available dam data 93 | !******************************************************************************* 94 | IS_dam_tot =0 95 | dam_tot_id_file ='' 96 | 97 | !******************************************************************************* 98 | !Dam data used 99 | !******************************************************************************* 100 | IS_dam_use =0 101 | dam_use_id_file ='' 102 | 103 | !******************************************************************************* 104 | !Available forcing data 105 | !******************************************************************************* 106 | IS_for_tot =0 107 | for_tot_id_file ='' 108 | Qfor_file ='' 109 | 110 | !******************************************************************************* 111 | !Forcing data used 112 | !******************************************************************************* 113 | IS_for_use =0 114 | for_use_id_file ='' 115 | 116 | !******************************************************************************* 117 | !File where max (min) of absolute values of b (QoutR) are stored 118 | !******************************************************************************* 119 | babsmax_file ='' 120 | QoutRabsmin_file ='' 121 | QoutRabsmax_file ='' 122 | 123 | !******************************************************************************* 124 | !Uncertainty quantification 125 | !******************************************************************************* 126 | 127 | !******************************************************************************* 128 | !Muskingum operator and data assimilation 129 | !******************************************************************************* 130 | ZS_threshold =0.0 131 | 132 | !******************************************************************************* 133 | !Regular model run 134 | !******************************************************************************* 135 | k_file ='../input/MIGBM_GGG/k_MIGBM_0.csv' 136 | x_file ='../input/MIGBM_GGG/x_MIGBM_0.csv' 137 | Qout_file ='../output/MIGBM_GGG/Qout_MIGBM_20000101_20091231_utc_p0_dtR1800s_nx_method.nc' 138 | V_file ='' 139 | 140 | !******************************************************************************* 141 | !Optimization 142 | !******************************************************************************* 143 | ZS_phifac =0.001 144 | !------------------------------------------------------------------------------- 145 | !Routing parameters 146 | !------------------------------------------------------------------------------- 147 | kfac_file ='../input/MIGBM_GGG/kfac_MIGBM_1km_hour.csv' 148 | ZS_knorm_init =2 149 | ZS_xnorm_init =3 150 | !------------------------------------------------------------------------------- 151 | !Gage observations 152 | !------------------------------------------------------------------------------- 153 | IS_obs_tot =2 154 | obs_tot_id_file ='../input/MIGBM_GGG/obs_tot_id_MIGBM_20000101_20091231_full.csv' 155 | Qobs_file ='../input/MIGBM_GGG/Qobs_MIGBM_20000101_20091231_full.csv' 156 | Qobsbarrec_file ='' 157 | IS_obs_use =2 158 | obs_use_id_file ='../input/MIGBM_GGG/obs_tot_id_MIGBM_20000101_20091231_full.csv' 159 | IS_strt_opt =1 160 | !0*8+1=1 161 | 162 | !******************************************************************************* 163 | !End name list 164 | !******************************************************************************* 165 | / 166 | -------------------------------------------------------------------------------- /tst/rapid_namelist_Reg07_JHM: -------------------------------------------------------------------------------- 1 | &NL_namelist 2 | !******************************************************************************* 3 | !rapid_namelist_Reg07_JHM 4 | !******************************************************************************* 5 | 6 | !Purpose: 7 | !This ASCII file contains instructions for RAPID corresponding to Reg07_JHM. 8 | !Author: 9 | !Cedric H. David, 2015-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Runtime options 14 | !******************************************************************************* 15 | BS_opt_Qinit =.false. 16 | !.false. --> no read initial flow .true. --> read initial flow 17 | 18 | BS_opt_Qfinal =.false. 19 | !.false. --> no write final flow .true. --> write final flow 20 | 21 | BS_opt_V =.false. 22 | !.false. --> no compute volume .true. --> compute volume 23 | 24 | BS_opt_dam =.false. 25 | !.false. --> no dam model used .true. --> dam model used 26 | 27 | BS_opt_for =.false. 28 | !.false. --> no forcing .true. --> forcing 29 | 30 | BS_opt_influence =.false. 31 | !.false. --> no output influence .true. --> output influence 32 | 33 | BS_opt_uq =.false. 34 | !.false. --> no uncertainty quantif. .true. --> uncertainty quantif. 35 | 36 | IS_opt_routing =1 37 | !1 --> matrix-based Muskingum 2 --> traditional Muskingum 38 | !3 --> Transbnd. matrix-based 4 --> Muskingum operator 39 | 40 | IS_opt_run =1 41 | !1 --> regular run 2 --> parameter optimization 42 | 43 | IS_opt_phi =1 44 | !1 --> phi1 2 --> phi2 45 | 46 | !******************************************************************************* 47 | !Temporal information 48 | !******************************************************************************* 49 | ZS_TauM =8640000 50 | !3600*24*100=8640000 51 | ZS_dtM =86400 52 | !3600*24=86400 53 | 54 | ZS_TauO =0 55 | !3600*24*0=0 56 | ZS_dtO =0 57 | !3600*24*0=0 58 | 59 | ZS_TauR =10800 60 | !3600*3=10800 61 | ZS_dtR =900 62 | !60*15=900 63 | 64 | ZS_dtF =86400 65 | !3600*24=86400 66 | 67 | !******************************************************************************* 68 | !Domain in which input data is available 69 | !******************************************************************************* 70 | IS_riv_tot =182240 71 | rapid_connect_file ='../../rapid/input/Reg07_JHM/rapid_connect_Reg07.csv' 72 | IS_max_up =4 73 | Vlat_file ='../../rapid/input/Reg07_JHM/m3_riv_Reg07_100days_dummy.nc' 74 | 75 | !******************************************************************************* 76 | !Domain in which model runs 77 | !******************************************************************************* 78 | IS_riv_bas =182240 79 | riv_bas_id_file ='../../rapid/input/Reg07_JHM/basin_id_Reg07_hydroseq.csv' 80 | 81 | !******************************************************************************* 82 | !Initial instantaneous flow file 83 | !******************************************************************************* 84 | Qinit_file ='' 85 | 86 | !******************************************************************************* 87 | !Final instantaneous flow file 88 | !******************************************************************************* 89 | Qfinal_file ='' 90 | 91 | !******************************************************************************* 92 | !Available dam data 93 | !******************************************************************************* 94 | IS_dam_tot =0 95 | dam_tot_id_file ='' 96 | 97 | !******************************************************************************* 98 | !Dam data used 99 | !******************************************************************************* 100 | IS_dam_use =0 101 | dam_use_id_file ='' 102 | 103 | !******************************************************************************* 104 | !Available forcing data 105 | !******************************************************************************* 106 | IS_for_tot =0 107 | for_tot_id_file ='' 108 | Qfor_file ='' 109 | 110 | !******************************************************************************* 111 | !Forcing data used 112 | !******************************************************************************* 113 | IS_for_use =0 114 | for_use_id_file ='' 115 | 116 | !******************************************************************************* 117 | !File where max (min) of absolute values of b (QoutR) are stored 118 | !******************************************************************************* 119 | babsmax_file ='' 120 | QoutRabsmin_file ='' 121 | QoutRabsmax_file ='' 122 | 123 | !******************************************************************************* 124 | !Uncertainty quantification 125 | !******************************************************************************* 126 | 127 | !******************************************************************************* 128 | !Muskingum operator and data assimilation 129 | !******************************************************************************* 130 | ZS_threshold =0.0 131 | 132 | !******************************************************************************* 133 | !Regular model run 134 | !******************************************************************************* 135 | k_file ='../../rapid/input/Reg07_JHM/kfac_Reg07_2.5ms.csv' 136 | x_file ='../../rapid/input/Reg07_JHM/xfac_Reg07_0.3.csv' 137 | Qout_file ='../../rapid/output/Reg07_JHM/Qout_Reg07_100days_pfac_dtR900s_nx_method.nc' 138 | V_file ='' 139 | 140 | !******************************************************************************* 141 | !Optimization 142 | !******************************************************************************* 143 | ZS_phifac =0.0 144 | !------------------------------------------------------------------------------- 145 | !Routing parameters 146 | !------------------------------------------------------------------------------- 147 | kfac_file ='' 148 | ZS_knorm_init =0 149 | ZS_xnorm_init =0 150 | !------------------------------------------------------------------------------- 151 | !Gage observations 152 | !------------------------------------------------------------------------------- 153 | IS_obs_tot =0 154 | obs_tot_id_file ='' 155 | Qobs_file ='' 156 | Qobsbarrec_file ='' 157 | IS_obs_use =0 158 | obs_use_id_file ='' 159 | IS_strt_opt =0 160 | !0*8+1=1 161 | 162 | !******************************************************************************* 163 | !End name list 164 | !******************************************************************************* 165 | / 166 | -------------------------------------------------------------------------------- /tst/rapid_namelist_San_Guad_JHM: -------------------------------------------------------------------------------- 1 | &NL_namelist 2 | !******************************************************************************* 3 | !rapid_namelist_San_Guad_JHM 4 | !******************************************************************************* 5 | 6 | !Purpose: 7 | !This ASCII file contains instructions for RAPID corresponding to San_Guad_JHM. 8 | !Author: 9 | !Cedric H. David, 2015-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Runtime options 14 | !******************************************************************************* 15 | BS_opt_Qinit =.false. 16 | !.false. --> no read initial flow .true. --> read initial flow 17 | 18 | BS_opt_Qfinal =.false. 19 | !.false. --> no write final flow .true. --> write final flow 20 | 21 | BS_opt_V =.false. 22 | !.false. --> no compute volume .true. --> compute volume 23 | 24 | BS_opt_dam =.false. 25 | !.false. --> no dam model used .true. --> dam model used 26 | 27 | BS_opt_for =.false. 28 | !.false. --> no forcing .true. --> forcing 29 | 30 | BS_opt_influence =.false. 31 | !.false. --> no output influence .true. --> output influence 32 | 33 | BS_opt_uq =.false. 34 | !.false. --> no uncertainty quantif. .true. --> uncertainty quantif. 35 | 36 | IS_opt_routing =1 37 | !1 --> matrix-based Muskingum 2 --> traditional Muskingum 38 | !3 --> Transbnd. matrix-based 4 --> Muskingum operator 39 | 40 | IS_opt_run =1 41 | !1 --> regular run 2 --> parameter optimization 42 | 43 | IS_opt_phi =1 44 | !1 --> phi1 2 --> phi2 45 | 46 | !******************************************************************************* 47 | !Temporal information 48 | !******************************************************************************* 49 | ZS_TauM =126144000 50 | !3600*24*1460=126144000 51 | ZS_dtM =86400 52 | !3600*24=86400 53 | 54 | ZS_TauO =15724800 55 | !3600*24*182=15724800 56 | ZS_dtO =86400 57 | !3600*24=86400 58 | 59 | ZS_TauR =10800 60 | !3600*3=10800 61 | ZS_dtR =900 62 | !60*15=900 63 | 64 | ZS_dtF =86400 65 | !3600*24=86400 66 | 67 | !******************************************************************************* 68 | !Domain in which input data is available 69 | !******************************************************************************* 70 | IS_riv_tot =5175 71 | rapid_connect_file ='../../rapid/input/San_Guad_JHM/rapid_connect_San_Guad.csv' 72 | IS_max_up =4 73 | Vlat_file ='../../rapid/input/San_Guad_JHM/m3_riv_San_Guad_2004_2007_cst.nc' 74 | 75 | !******************************************************************************* 76 | !Domain in which model runs 77 | !******************************************************************************* 78 | IS_riv_bas =5175 79 | riv_bas_id_file ='../../rapid/input/San_Guad_JHM/basin_id_San_Guad_hydroseq.csv' 80 | 81 | !******************************************************************************* 82 | !Initial instantaneous flow file 83 | !******************************************************************************* 84 | Qinit_file ='' 85 | 86 | !******************************************************************************* 87 | !Final instantaneous flow file 88 | !******************************************************************************* 89 | Qfinal_file ='' 90 | 91 | !******************************************************************************* 92 | !Available dam data 93 | !******************************************************************************* 94 | IS_dam_tot =0 95 | dam_tot_id_file ='' 96 | 97 | !******************************************************************************* 98 | !Dam data used 99 | !******************************************************************************* 100 | IS_dam_use =0 101 | dam_use_id_file ='' 102 | 103 | !******************************************************************************* 104 | !Available forcing data 105 | !******************************************************************************* 106 | IS_for_tot =0 107 | for_tot_id_file ='' 108 | Qfor_file ='' 109 | 110 | !******************************************************************************* 111 | !Forcing data used 112 | !******************************************************************************* 113 | IS_for_use =0 114 | for_use_id_file ='' 115 | 116 | !******************************************************************************* 117 | !File where max (min) of absolute values of b (QoutR) are stored 118 | !******************************************************************************* 119 | babsmax_file ='' 120 | QoutRabsmin_file ='' 121 | QoutRabsmax_file ='' 122 | 123 | !******************************************************************************* 124 | !Uncertainty quantification 125 | !******************************************************************************* 126 | 127 | !******************************************************************************* 128 | !Muskingum operator and data assimilation 129 | !******************************************************************************* 130 | ZS_threshold =0.0 131 | 132 | !******************************************************************************* 133 | !Regular model run 134 | !******************************************************************************* 135 | k_file ='../../rapid/input/San_Guad_JHM/k_San_Guad_2004_1.csv' 136 | x_file ='../../rapid/input/San_Guad_JHM/x_San_Guad_2004_1.csv' 137 | Qout_file ='../../rapid/output/San_Guad_JHM/Qout_San_Guad_1460days_p1_dtR900s_nx_method.nc' 138 | V_file ='' 139 | 140 | !******************************************************************************* 141 | !Optimization 142 | !******************************************************************************* 143 | ZS_phifac =0.001 144 | !------------------------------------------------------------------------------- 145 | !Routing parameters 146 | !------------------------------------------------------------------------------- 147 | kfac_file ='../../rapid/input/San_Guad_JHM/kfac_San_Guad_1km_hour.csv' 148 | ZS_knorm_init =2 149 | ZS_xnorm_init =3 150 | !------------------------------------------------------------------------------- 151 | !Gage observations 152 | !------------------------------------------------------------------------------- 153 | IS_obs_tot =36 154 | obs_tot_id_file ='../../rapid/input/San_Guad_JHM/gage_id_San_Guad_2004_2007_full.csv' 155 | Qobs_file ='../../rapid/input/San_Guad_JHM/Qobs_San_Guad_2004_2007_full.csv' 156 | Qobsbarrec_file ='' 157 | IS_obs_use =36 158 | obs_use_id_file ='../../rapid/input/San_Guad_JHM/gage_id_San_Guad_2004_2007_full.csv' 159 | IS_strt_opt =1 160 | !0*8+1=1 161 | 162 | !******************************************************************************* 163 | !End name list 164 | !******************************************************************************* 165 | / 166 | -------------------------------------------------------------------------------- /tst/rapid_namelist_WSWM_GRL: -------------------------------------------------------------------------------- 1 | &NL_namelist 2 | !******************************************************************************* 3 | !rapid_namelist_WSWM_GRL 4 | !******************************************************************************* 5 | 6 | !Purpose: 7 | !This ASCII file contains instructions for RAPID corresponding to WSWM_GRL. 8 | !Author: 9 | !Cedric H. David, 2015-2024. 10 | 11 | 12 | !******************************************************************************* 13 | !Runtime options 14 | !******************************************************************************* 15 | BS_opt_Qinit =.false. 16 | !.false. --> no read initial flow .true. --> read initial flow 17 | 18 | BS_opt_Qfinal =.false. 19 | !.false. --> no write final flow .true. --> write final flow 20 | 21 | BS_opt_V =.false. 22 | !.false. --> no compute volume .true. --> compute volume 23 | 24 | BS_opt_dam =.false. 25 | !.false. --> no dam model used .true. --> dam model used 26 | 27 | BS_opt_for =.false. 28 | !.false. --> no forcing .true. --> forcing 29 | 30 | BS_opt_influence =.false. 31 | !.false. --> no output influence .true. --> output influence 32 | 33 | BS_opt_uq =.false. 34 | !.false. --> no uncertainty quantif. .true. --> uncertainty quantif. 35 | 36 | IS_opt_routing =1 37 | !1 --> matrix-based Muskingum 2 --> traditional Muskingum 38 | !3 --> Transbnd. matrix-based 4 --> Muskingum operator 39 | 40 | IS_opt_run =1 41 | !1 --> regular run 2 --> parameter optimization 42 | 43 | IS_opt_phi =1 44 | !1 --> phi1 2 --> phi2 45 | 46 | !******************************************************************************* 47 | !Temporal information 48 | !******************************************************************************* 49 | ZS_TauM =62985600 50 | !3600*24*729=62985600 51 | ZS_dtM =86400 52 | !3600*24=86400 53 | 54 | ZS_TauO =15638400 55 | !3600*24*181=15638400 56 | ZS_dtO =86400 57 | !3600*24=86400 58 | 59 | ZS_TauR =10800 60 | !3600*3=10800 61 | ZS_dtR =900 62 | !60*15=900 63 | 64 | ZS_dtF =86400 65 | !3600*24=86400 66 | 67 | !******************************************************************************* 68 | !Domain in which input data is available 69 | !******************************************************************************* 70 | IS_riv_tot =658702 71 | rapid_connect_file ='../../rapid/input/WSWM_GRL/rapid_connect_WSWM.csv' 72 | IS_max_up =12 73 | Vlat_file ='../../rapid/input/WSWM_GRL/m3_riv_WSWM_19970101_19981231_VIC0125_3H_cst_err.nc4' 74 | 75 | !******************************************************************************* 76 | !Domain in which model runs 77 | !******************************************************************************* 78 | IS_riv_bas =658702 79 | riv_bas_id_file ='../../rapid/input/WSWM_GRL/riv_bas_id_WSWM_hydroseq.csv' 80 | 81 | !******************************************************************************* 82 | !Initial instantaneous flow file 83 | !******************************************************************************* 84 | Qinit_file ='' 85 | 86 | !******************************************************************************* 87 | !Final instantaneous flow file 88 | !******************************************************************************* 89 | Qfinal_file ='' 90 | 91 | !******************************************************************************* 92 | !Available dam data 93 | !******************************************************************************* 94 | IS_dam_tot =0 95 | dam_tot_id_file ='' 96 | 97 | !******************************************************************************* 98 | !Dam data used 99 | !******************************************************************************* 100 | IS_dam_use =0 101 | dam_use_id_file ='' 102 | 103 | !******************************************************************************* 104 | !Available forcing data 105 | !******************************************************************************* 106 | IS_for_tot =0 107 | for_tot_id_file ='' 108 | Qfor_file ='' 109 | 110 | !******************************************************************************* 111 | !Forcing data used 112 | !******************************************************************************* 113 | IS_for_use =0 114 | for_use_id_file ='' 115 | 116 | !******************************************************************************* 117 | !File where max (min) of absolute values of b (QoutR) are stored 118 | !******************************************************************************* 119 | babsmax_file ='' 120 | QoutRabsmin_file ='' 121 | QoutRabsmax_file ='' 122 | 123 | !******************************************************************************* 124 | !Uncertainty quantification 125 | !******************************************************************************* 126 | ZS_dtUQ =2628000 127 | 128 | !******************************************************************************* 129 | !Muskingum operator and data assimilation 130 | !******************************************************************************* 131 | ZS_threshold =0.0 132 | 133 | !******************************************************************************* 134 | !Regular model run 135 | !******************************************************************************* 136 | k_file ='../../rapid/input/WSWM_GRL/k_WSWM_pag.csv' 137 | x_file ='../../rapid/input/WSWM_GRL/x_WSWM_pag.csv' 138 | Qout_file ='../../rapid/output/WSWM_GRL/Qout_WSWM_729days_pag_dtR900s_nx_method.nc' 139 | V_file ='../../rapid/output/WSWM_GRL/V_WSWM_729days_pag_dtR900s_nx_method.nc' 140 | 141 | !******************************************************************************* 142 | !Optimization 143 | !******************************************************************************* 144 | ZS_phifac =0.001 145 | !------------------------------------------------------------------------------- 146 | !Routing parameters 147 | !------------------------------------------------------------------------------- 148 | kfac_file ='../../rapid/input/WSWM_GRL/kfac_WSWM_1km_hour.csv' 149 | ZS_knorm_init =2 150 | ZS_xnorm_init =3 151 | !------------------------------------------------------------------------------- 152 | !Gage observations 153 | !------------------------------------------------------------------------------- 154 | IS_obs_tot =1562 155 | obs_tot_id_file ='../../rapid/input/WSWM_GRL/gage_id_WSWM_1997_1998_full.csv' 156 | Qobs_file ='../../rapid/input/WSWM_GRL/Qobs_WSWM_1997_1998_full.csv' 157 | Qobsbarrec_file ='' 158 | IS_obs_use =1562 159 | obs_use_id_file ='../../rapid/input/WSWM_GRL/gage_id_WSWM_1997_1998_full.csv' 160 | IS_strt_opt =1 161 | !0*8+1=1 162 | 163 | !******************************************************************************* 164 | !End name list 165 | !******************************************************************************* 166 | / 167 | -------------------------------------------------------------------------------- /tst/tst_opt_comp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #tst_opt_comp.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script compares previous RAPID optimization results to the values given in 8 | #a text file (from tst_opt_find.sh or tst_opt_pick.sh). 9 | #A total of 4 arguments must be provided: 10 | # - Argument 1: Name of the text file 11 | # - Argument 2: Value for Lambda k (to be compared with line 2 of text file) 12 | # - Argument 3: Value for Lambda x (to be compared with line 3 of text file) 13 | # - Argument 4: Value for Phi (to be compared with line 4 of text file) 14 | #The script returns the following exit codes 15 | # - 0 if the values are the same 16 | # - 22 if arguments are faulty 17 | # - 99 if the comparison failed 18 | #Author: 19 | #Cedric H. David, 2015-2024. 20 | 21 | 22 | #******************************************************************************* 23 | #Notes on tricks used here 24 | #******************************************************************************* 25 | #$# --> the number of arguments given 26 | #$@ --> list all arguments given 27 | #$1 --> the first argument given 28 | #sed -n '2p' $1 --> extracts the string in line 2 of argument 1 29 | 30 | 31 | #******************************************************************************* 32 | #Perform comparison 33 | #******************************************************************************* 34 | #------------------------------------------------------------------------------- 35 | #Check that 4 arguments are given and that the input text file exists 36 | #------------------------------------------------------------------------------- 37 | if [ "$#" -ne "4" ]; then 38 | echo "A total of 4 arguments must be provided" 1>&2 39 | exit 22 40 | fi 41 | #Check that 4 arguments were provided 42 | 43 | if [ ! -e "$1" ]; then 44 | echo "Input file $file doesn't exist" 1>&2 45 | exit 22 46 | fi 47 | #Check that the input file exists 48 | 49 | #------------------------------------------------------------------------------- 50 | #Compare the values in file with values given as arguments 51 | #------------------------------------------------------------------------------- 52 | lkf=`sed -n '2p' $1` 53 | lxf=`sed -n '3p' $1` 54 | phif=`sed -n '4p' $1` 55 | 56 | lkc=$2 57 | lxc=$3 58 | phic=$4 59 | 60 | 61 | bool=`echo "$lkf == $lkc" | bc -l` 62 | if [ "$bool" = "0" ]; then 63 | echo "The values for Lambda k don't match: $lkf /= $lkc" 1>&2 64 | exit 99 65 | fi 66 | 67 | bool=`echo "$lxf == $lxc" | bc -l` 68 | if [ "$bool" = "0" ]; then 69 | echo "The values for Lambda x don't match: $lxf /= $lxc" 1>&2 70 | exit 99 71 | fi 72 | 73 | bool=`echo "$phif == $phic" | bc -l` 74 | if [ "$bool" = "0" ]; then 75 | echo "The values for Phi don't match: $phif /= $phic" 1>&2 76 | exit 99 77 | fi 78 | 79 | 80 | #******************************************************************************* 81 | #Done 82 | #******************************************************************************* 83 | -------------------------------------------------------------------------------- /tst/tst_opt_gtol.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #tst_opt_gtol.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script helps with the transition between PETSc 3.6 and PETSc 3.7 in which 8 | #the convergence tolerances on the function (absolute: fatol, relative: frtol) 9 | #were deprecated. The only tolerances available now are on the function gradient 10 | #(absolute: gatol, relative: grtol, and relative to initial gradient: gttol). 11 | #Using the previous default value in RAPID (fatol=0.0001 and frtol=0.0001), and 12 | #results from previous RAPID optimization experiments, this script computes 13 | #suggested values of gatol and grtol that can be used in order to reproduce the 14 | #same results. 15 | #A total of n (n>=1) arguments can be provided: 16 | # - Argument 1: Name of the 1st text file output from tst_opt_find.sh 17 | # - Argument 2: Name of the 2nd text file output from tst_opt_find.sh (optional) 18 | # - ... 19 | # - Argument n: Name of the nth text file output from tst_opt_find.sh (optional) 20 | #The script returns the following exit codes 21 | # - 0 if the script found the desired answer 22 | # - 22 if arguments are faulty 23 | #Author: 24 | #Cedric H. David, 2016-2024. 25 | 26 | 27 | #******************************************************************************* 28 | #Notes on tricks used here 29 | #******************************************************************************* 30 | #$# --> the number of arguments given 31 | #$@ --> list all arguments given 32 | #$1 --> the first argument given 33 | #sed -n '2p' $1 --> extracts the string in line 2 of argument 1 34 | 35 | 36 | #******************************************************************************* 37 | #Compute recommended gradient tolerances 38 | #******************************************************************************* 39 | 40 | #------------------------------------------------------------------------------- 41 | #Check that input files are given and that they all exist 42 | #------------------------------------------------------------------------------- 43 | if [ "$#" = "0" ]; then 44 | echo "No file names were provided" 1>&2 45 | exit 22 46 | fi 47 | #Check that at least 1 input file is given 48 | 49 | for file in "$@" 50 | do 51 | if [ ! -e "$file" ]; then 52 | echo "Input file $file doesn't exist" 1>&2 53 | exit 22 54 | fi 55 | done 56 | #Check that all files exist 57 | 58 | #------------------------------------------------------------------------------- 59 | #Find the average value of the final objective function 60 | #------------------------------------------------------------------------------- 61 | phi_avg=0 62 | 63 | for file in "$@" 64 | do 65 | phi_end=`sed -n '4p' $file` 66 | phi_avg=$(echo $phi_avg + $phi_end | bc -l) 67 | done 68 | phi_avg=$(echo $phi_avg / $# | bc -l) 69 | 70 | #------------------------------------------------------------------------------- 71 | #Output recommended gradient tolerances 72 | #------------------------------------------------------------------------------- 73 | gatol=$(echo "sqrt(0.0001)" | bc -l) 74 | grtol=$(echo "sqrt(0.0001 / $phi_avg)" | bc -l) 75 | 76 | printf "%3.1e \n" $gatol 77 | printf "%3.1e \n" $grtol 78 | 79 | 80 | #******************************************************************************* 81 | #End 82 | #******************************************************************************* 83 | -------------------------------------------------------------------------------- /tst/tst_opt_pick.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #tst_opt_pick.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script picks the best values of Lamba k, Lambda x and Phi in a series of 8 | #text files (from tst_opt_find.sh) provided as input 9 | #A total of at least one argument must be provided: 10 | # - Argument 1: Name of the text file 1 11 | # - Argument 2: Name of the text file 2 (optional) 12 | # - ... 13 | # - Argument n: Name of the text file n (optional) 14 | #The script returns the following exit codes 15 | # - 0 if the script found the desired answer 16 | # - 22 if arguments are faulty 17 | # - 33 if the search failed 18 | #Author: 19 | #Cedric H. David, 2015-2024. 20 | 21 | 22 | #******************************************************************************* 23 | #Notes on tricks used here 24 | #******************************************************************************* 25 | #$# --> the number of arguments given 26 | #$@ --> list all arguments given 27 | 28 | 29 | #******************************************************************************* 30 | #Find best RAPID optimization values 31 | #******************************************************************************* 32 | #------------------------------------------------------------------------------- 33 | #Check that input files are given and that they all exist 34 | #------------------------------------------------------------------------------- 35 | if [ "$#" = "0" ]; then 36 | echo "No file names were provided" 1>&2 37 | exit 22 38 | fi 39 | #Check that at least 1 input file is given 40 | 41 | for file in "$@" 42 | do 43 | if [ ! -e "$file" ]; then 44 | echo "Input file $file doesn't exist" 1>&2 45 | 46 | exit 22 47 | fi 48 | done 49 | #Check that all files exist 50 | 51 | #------------------------------------------------------------------------------- 52 | #Determine which input file leads to best values 53 | #------------------------------------------------------------------------------- 54 | phio=1000000 55 | 56 | for file in "$@" 57 | do 58 | lkc=`sed -n '2p' $file` 59 | lxc=`sed -n '3p' $file` 60 | phic=`sed -n '4p' $file` 61 | bool=`echo "$phic < $phio" | bc -l` 62 | if [ "$bool" = "1" ]; then 63 | lko=$lkc 64 | lxo=$lxc 65 | phio=$phic 66 | fi 67 | done 68 | 69 | #------------------------------------------------------------------------------- 70 | #Check that best value is not default 71 | #------------------------------------------------------------------------------- 72 | if [ "$phio" = "1000000" ]; then 73 | echo "The search best values was not successful" 1>&2 74 | exit 33 75 | fi 76 | 77 | #------------------------------------------------------------------------------- 78 | #Output results 79 | #------------------------------------------------------------------------------- 80 | echo "Using: $@" 81 | echo $lko 82 | echo $lxo 83 | echo $phio 84 | 85 | 86 | #******************************************************************************* 87 | #Done 88 | #******************************************************************************* 89 | -------------------------------------------------------------------------------- /tst/tst_pub_dwnl_David_etal_2011_JHM.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #tst_pub_dwnl_David_etal_2011_JHM.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script downloads all the files corresponding to: 8 | #David, Cédric H., David R. Maidment, Guo-Yue Niu, Zong- Liang Yang, Florence 9 | #Habets and Victor Eijkhout (2011), River network routing on the NHDPlus 10 | #dataset, Journal of Hydrometeorology, 12(5), 913-934. 11 | #DOI: 10.1175/2011JHM1345.1 12 | #These files are available from: 13 | #David, Cédric H., David R. Maidment, Guo-Yue Niu, Zong- Liang Yang, Florence 14 | #Habets and Victor Eijkhout (2011), RAPID input and output files corresponding 15 | #to "River Network Routing on the NHDPlus Dataset", Zenodo. 16 | #DOI: 10.5281/zenodo.16565 17 | #The script returns the following exit codes 18 | # - 0 if all downloads are successful 19 | # - 22 if there was a conversion problem 20 | # - 44 if one download is not successful 21 | #Author: 22 | #Cedric H. David, 2015-2024. 23 | 24 | 25 | #******************************************************************************* 26 | #Notes on tricks used here 27 | #******************************************************************************* 28 | #wget -nv -nc --> Non-verbose (silent), No-clobber (don't overwrite) 29 | 30 | 31 | #******************************************************************************* 32 | #Publication message 33 | #******************************************************************************* 34 | echo "********************" 35 | echo "Downloading files from: http://dx.doi.org/10.5281/zenodo.16565" 36 | echo "which correspond to : http://dx.doi.org/10.1175/2011JHM1345.1" 37 | echo "These files are under a Creative Commons Attribution (CC BY) license." 38 | echo "Please cite these two DOIs if using these files for your publications." 39 | echo "********************" 40 | 41 | 42 | #******************************************************************************* 43 | #Location of the dataset 44 | #******************************************************************************* 45 | URL="https://zenodo.org/record/16565/files" 46 | 47 | 48 | #******************************************************************************* 49 | #Download all input files corresponding to the San Antonio and Guadalupe Basins 50 | #******************************************************************************* 51 | folder="../input/San_Guad_JHM" 52 | list=" \ 53 | rapid_connect_San_Guad.csv \ 54 | m3_riv_San_Guad_2004_2007_cst.nc \ 55 | kfac_San_Guad_1km_hour.csv \ 56 | kfac_San_Guad_celerity.csv \ 57 | k_San_Guad_2004_1.csv \ 58 | k_San_Guad_2004_2.csv \ 59 | k_San_Guad_2004_3.csv \ 60 | k_San_Guad_2004_4.csv \ 61 | x_San_Guad_2004_1.csv \ 62 | x_San_Guad_2004_2.csv \ 63 | x_San_Guad_2004_3.csv \ 64 | x_San_Guad_2004_4.csv \ 65 | basin_id_San_Guad_hydroseq.csv \ 66 | gage_id_San_Guad_2004_2007_full.csv \ 67 | Qobs_San_Guad_2004_2007_full.csv \ 68 | " 69 | 70 | mkdir -p $folder 71 | for file in $list 72 | do 73 | wget -nv -nc $URL/$file -P $folder 74 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 75 | done 76 | 77 | 78 | #******************************************************************************* 79 | #Download all output files corresponding to the San Antonio and Guadalupe Basins 80 | #******************************************************************************* 81 | folder="../output/San_Guad_JHM" 82 | list=" \ 83 | Qout_San_Guad_1460days_p1_dtR900s.nc \ 84 | Qout_San_Guad_1460days_p2_dtR900s.nc \ 85 | Qout_San_Guad_1460days_p3_dtR900s.nc \ 86 | Qout_San_Guad_1460days_p4_dtR900s.nc \ 87 | QoutR_San_Guad_182days_p1_dtR900s.nc \ 88 | QoutR_San_Guad_182days_p2_dtR900s.nc \ 89 | QoutR_San_Guad_182days_p3_dtR900s.nc \ 90 | QoutR_San_Guad_182days_p4_dtR900s.nc \ 91 | " 92 | 93 | mkdir -p $folder 94 | for file in $list 95 | do 96 | wget -nv -nc $URL/$file -P $folder 97 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 98 | done 99 | 100 | 101 | #******************************************************************************* 102 | #Download all input files corresponding to the Upper Mississippi Basin 103 | #******************************************************************************* 104 | folder="../input/Reg07_JHM" 105 | list=" \ 106 | rapid_connect_Reg07.csv \ 107 | m3_riv_Reg07_100days_dummy.nc \ 108 | kfac_Reg07_2.5ms.csv \ 109 | xfac_Reg07_0.3.csv \ 110 | basin_id_Reg07_hydroseq.csv \ 111 | " 112 | 113 | mkdir -p $folder 114 | for file in $list 115 | do 116 | wget -nv -nc $URL/$file -P $folder 117 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 118 | done 119 | 120 | 121 | #******************************************************************************* 122 | #Download all output files corresponding to the Upper Mississippi Basin 123 | #******************************************************************************* 124 | folder="../output/Reg07_JHM" 125 | list=" \ 126 | Qout_Reg07_100days_pfac_dtR900s.nc \ 127 | " 128 | 129 | mkdir -p $folder 130 | for file in $list 131 | do 132 | wget -nv -nc $URL/$file -P $folder 133 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 134 | done 135 | 136 | 137 | #******************************************************************************* 138 | #Convert legacy files 139 | #******************************************************************************* 140 | #N/A 141 | 142 | 143 | #******************************************************************************* 144 | #Done 145 | #******************************************************************************* 146 | -------------------------------------------------------------------------------- /tst/tst_pub_dwnl_David_etal_2015_WRR.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #tst_pub_dwnl_David_etal_2015_WRR.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script downloads all the files corresponding to: 8 | #David, Cédric H., James S. Famiglietti, Zong-Liang Yang, and Victor Eijkhout 9 | #(2015), Enhanced fixed-size parallel speedup with the Muskingum method using a 10 | #trans-boundary approach and a large sub-basins approximation, Water Resources 11 | #Research, 51(9), 1-25, 12 | #DOI: 10.1002/2014WR016650. 13 | #These files are available from: 14 | #David, Cédric H., James S. Famiglietti, Zong-Liang Yang, and Victor Eijkhout 15 | #(2015), 16 | #xxx 17 | #DOI: xx.xxxx/xxxxxx 18 | #The script returns the following exit codes 19 | # - 0 if all downloads are successful 20 | # - 22 if there was a conversion problem 21 | # - 44 if one download is not successful 22 | #Author: 23 | #Cedric H. David, 2018-2024. 24 | 25 | 26 | #******************************************************************************* 27 | #Notes on tricks used here 28 | #******************************************************************************* 29 | #wget -nv -nc --> Non-verbose (silent), No-clobber (don't overwrite) 30 | 31 | 32 | #******************************************************************************* 33 | #Publication message 34 | #******************************************************************************* 35 | echo "********************" 36 | echo "Downloading files from: http://dx.doi.org/xx.xxxx/xxxxxx" 37 | echo "which correspond to : http://dx.doi.org/10.1002/2014WR016650" 38 | echo "These files are under a Creative Commons Attribution (CC BY) license." 39 | echo "Please cite these four DOIs if using these files for your publications." 40 | echo "********************" 41 | 42 | 43 | #******************************************************************************* 44 | #Location of the dataset 45 | #******************************************************************************* 46 | URL="http://rapid-hub.org/data/CI/HSmsp_WRR" 47 | 48 | 49 | #******************************************************************************* 50 | #Download all input files 51 | #******************************************************************************* 52 | folder="../input/HSmsp_WRR" 53 | list=" \ 54 | k_HSmsp_pa_guess.csv \ 55 | k_HSmsp_pa_phi1_2008_0.csv \ 56 | k_HSmsp_pa_phi1_2008_1.csv \ 57 | kfac_HSmsp_1km_hour.csv \ 58 | m3_riv_HSmsp_2000_2009_cst_VIC_NASA.nc \ 59 | obs_tot_id_HSmsp_2000_2009.csv \ 60 | Qobs_HSmsp_2000_2009.csv \ 61 | rapid_connect_HSmsp.csv \ 62 | riv_bas_id_HSmsp_topo.csv \ 63 | x_HSmsp_pa_guess.csv \ 64 | x_HSmsp_pa_phi1_2008_0.csv \ 65 | x_HSmsp_pa_phi1_2008_1.csv \ 66 | " 67 | 68 | mkdir -p $folder 69 | for file in $list 70 | do 71 | wget -nv -nc $URL/$file -P $folder 72 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 73 | done 74 | 75 | 76 | #******************************************************************************* 77 | #Download all output files 78 | #******************************************************************************* 79 | folder="../output/MIGBM_GGG" 80 | list=" \ 81 | Qout_HSmsp_2000_2009_VIC_NASA_sgl_pa_guess_n1_preonly_ilu.nc \ 82 | Qout_HSmsp_2000_2009_VIC_NASA_sgl_pa_phi1_2008_0_n1_preonly_ilu.nc \ 83 | Qout_HSmsp_2000_2009_VIC_NASA_sgl_pa_phi1_2008_1_n1_preonly_ilu.nc \ 84 | " 85 | 86 | mkdir -p $folder 87 | for file in $list 88 | do 89 | wget -nv -nc $URL/$file -P $folder 90 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 91 | done 92 | 93 | 94 | #******************************************************************************* 95 | #Convert legacy files 96 | #******************************************************************************* 97 | #N/A 98 | 99 | 100 | #******************************************************************************* 101 | #Done 102 | #******************************************************************************* 103 | -------------------------------------------------------------------------------- /tst/tst_pub_dwnl_David_etal_2019_GRL.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #tst_pub_dwnl_David_etal_2019_GRL.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script reproduces all RAPID simulations that were used in the writing of: 8 | #David, Cédric H., Jonathan M. Hobbs, Michael J. Turmon, Charlotte M. Emery, 9 | #John T. Reager, and James S. Famiglietti (2019), Analytical Propagation of 10 | #Runoff Uncertainty into Discharge Uncertainty through a Large River Network, 11 | #Geophysical Research Letters. 12 | #DOI: 10.1029/2019GL083342 13 | #The files used are available from: 14 | #David, Cédric H., Jonathan M. Hobbs, Michael J. Turmon, Charlotte M. Emery, 15 | #John T. Reager, and James S. Famiglietti (2019), RRR/RAPID input and output 16 | #files corresponding to "Analytical Propagation of Runoff Uncertainty into 17 | #Discharge Uncertainty through a Large River Network", Zenodo. 18 | #DOI: 10.5281/zenodo.2665084 19 | #The script returns the following exit codes 20 | # - 0 if all downloads are successful 21 | # - 22 if there was a conversion problem 22 | # - 44 if one download is not successful 23 | #Author: 24 | #Cedric H. David, 2015-2024. 25 | 26 | 27 | #******************************************************************************* 28 | #Notes on tricks used here 29 | #******************************************************************************* 30 | #wget -nv -nc --> Non-verbose (silent), No-clobber (don't overwrite) 31 | 32 | 33 | #******************************************************************************* 34 | #Publication message 35 | #******************************************************************************* 36 | echo "********************" 37 | echo "Downloading files from: http://dx.doi.org/10.5281/zenodo.2665084" 38 | echo "which correspond to : http://dx.doi.org/10.1029/2019GL083342" 39 | echo "These files are under a Creative Commons Attribution (CC BY) license." 40 | echo "Please cite these two DOIs if using these files for your publications." 41 | echo "********************" 42 | 43 | 44 | #******************************************************************************* 45 | #Location of the dataset 46 | #******************************************************************************* 47 | URL="https://zenodo.org/record/2665084/files" 48 | 49 | 50 | #******************************************************************************* 51 | #Download all input files 52 | #******************************************************************************* 53 | folder="../input/WSWM_GRL" 54 | list=" \ 55 | rapid_connect_WSWM.csv \ 56 | m3_riv_WSWM_19970101_19981231_VIC0125_3H_cst_err.nc4 \ 57 | k_WSWM_pag.csv \ 58 | x_WSWM_pag.csv \ 59 | riv_bas_id_WSWM_hydroseq.csv \ 60 | " 61 | 62 | mkdir -p $folder 63 | for file in $list 64 | do 65 | wget -nv -nc $URL/$file -P $folder 66 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 67 | done 68 | 69 | 70 | #******************************************************************************* 71 | #Download all output files 72 | #******************************************************************************* 73 | folder="../output/WSWM_GRL" 74 | list=" \ 75 | Qout_WSWM_729days_pag_dtR900s_n1_preonly.nc \ 76 | Qfinal_WSWM_729days_pag_dtR900s_n1_preonly.nc \ 77 | Qout_WSWM_729days_pag_dtR900s_n1_preonly_init_err.nc \ 78 | " 79 | 80 | mkdir -p $folder 81 | for file in $list 82 | do 83 | wget -nv -nc $URL/$file -P $folder 84 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 85 | done 86 | 87 | 88 | #******************************************************************************* 89 | #Convert legacy files 90 | #******************************************************************************* 91 | #N/A 92 | 93 | 94 | #******************************************************************************* 95 | #Done 96 | #******************************************************************************* 97 | -------------------------------------------------------------------------------- /tst/tst_pub_dwnl_Emery_etal_2020_JHM2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #tst_pub_dwnl_Emery_etal_2020_JHM2.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script downloads all the files corresponding to: 8 | #Emery, Charlotte M., Cedric H. David, Kostas M. Andreadis, Michael J. Turmon, 9 | #John T. Reager, Jonathan M. Hobbs, Ming Pan, James S. Famiglietti, 10 | #R. Edward Beighley, and Matthew Rodell (2020), Underlying Fundamentals of 11 | #Kalman Filtering for River Network Modeling, Journal of Hydrometeorology, 21, 12 | #453-474 13 | #DOI: 10.1175/JHM-D-19-0084.1 14 | #These files are available from: 15 | #Emery, Charlotte M., Cedric H. David, Kostas M. Andreadis, Michael J. Turmon, 16 | #John T. Reager, Jonathan M. Hobbs, Ming Pan, James S. Famiglietti, 17 | #R. Edward Beighley, and Matthew Rodell (2020), RRR/RAPID input and output files 18 | #for "Underlying Fundamentals of Kalman Filtering for River Network Modeling", 19 | #Zenodo. 20 | #DOI: 10.5281/zenodo.3688691 21 | #The script returns the following exit codes 22 | # - 0 if all downloads are successful 23 | # - 22 if there was a conversion problem 24 | # - 44 if one download is not successful 25 | #Authors: 26 | #Charlotte M. Emery, Cedric H. David, 2017-2024. 27 | 28 | #******************************************************************************* 29 | #Notes on tricks used here 30 | #******************************************************************************* 31 | #wget -nv -nc --> Non-verbose (silent), No-clobber (don't overwrite) 32 | 33 | 34 | #******************************************************************************* 35 | #Publication message 36 | #******************************************************************************* 37 | echo "********************" 38 | echo "Downloading files from: https://dx.doi.org/10.5281/zenodo.3688691" 39 | echo "which correspond to : https://dx.doi.org/10.1175/JHM-D-19-0084.1" 40 | echo "These files are under a Creative Commons Attribution (CC BY) license." 41 | echo "Please cite these two DOIs if using these files for your publications." 42 | echo "********************" 43 | 44 | #******************************************************************************* 45 | #Location of the dataset 46 | #******************************************************************************* 47 | URL="https://zenodo.org/record/3688691/files" 48 | 49 | 50 | #******************************************************************************* 51 | #Download all input files 52 | #******************************************************************************* 53 | folder="../input/San_Guad_JHM2" 54 | list=" \ 55 | k_San_Guad_2004_1.csv \ 56 | m3_riv_San_Guad_20100101_20131231_VIC0125_3H_utc_err_R286_D_scl.nc \ 57 | m3_riv_San_Guad_20100101_20131231_VIC0125_3H_utc_err_R286_D.nc \ 58 | m3_riv_San_Guad_20100101_20131231_VIC0125_3H_utc_err_R286_M.nc \ 59 | obs_tot_id_San_Guad_2010_2013_full.csv \ 60 | obs_use_id_San_Guad_2010_2013_23.csv \ 61 | Qobs_San_Guad_2010_2013_full.csv \ 62 | rapid_connect_San_Guad.csv \ 63 | riv_bas_id_San_Guad_hydroseq.csv \ 64 | x_San_Guad_2004_1.csv \ 65 | " 66 | 67 | mkdir -p $folder 68 | for file in $list 69 | do 70 | wget -nv -nc $URL/$file -P $folder 71 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 72 | done 73 | 74 | #******************************************************************************* 75 | #Download all output files 76 | #******************************************************************************* 77 | folder="../output/San_Guad_JHM2" 78 | list=" \ 79 | Qout_San_Guad_exp00_err_D_scl.nc \ 80 | Qout_San_Guad_exp00_err_D.nc \ 81 | Qout_San_Guad_exp00_err_M.nc \ 82 | Qout_San_Guad_exp00.nc \ 83 | Qout_San_Guad_exp01.nc \ 84 | Qout_San_Guad_exp02.nc \ 85 | Qout_San_Guad_exp03.nc \ 86 | Qout_San_Guad_exp04.nc \ 87 | Qout_San_Guad_exp05.nc \ 88 | Qout_San_Guad_exp06.nc \ 89 | Qout_San_Guad_exp07.nc \ 90 | Qout_San_Guad_exp08.nc \ 91 | Qout_San_Guad_exp09.nc \ 92 | Qout_San_Guad_exp10.nc \ 93 | Qout_San_Guad_exp11.nc \ 94 | Qout_San_Guad_exp12.nc \ 95 | Qout_San_Guad_exp13.nc \ 96 | Qout_San_Guad_exp14.nc \ 97 | Qout_San_Guad_exp15.nc \ 98 | Qout_San_Guad_exp16.nc \ 99 | Qout_San_Guad_exp17.nc \ 100 | Qout_San_Guad_exp18.nc \ 101 | Qout_San_Guad_exp19.nc \ 102 | Qout_San_Guad_exp20.nc \ 103 | Qout_San_Guad_exp21.nc \ 104 | " 105 | 106 | mkdir -p $folder 107 | for file in $list 108 | do 109 | wget -nv -nc $URL/$file -P $folder 110 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 111 | done 112 | 113 | #******************************************************************************* 114 | #Done 115 | #******************************************************************************* 116 | -------------------------------------------------------------------------------- /tst/tst_pub_dwnl_Sikder_etal_201x_FRN.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #tst_pub_dwnl_Sikder_etal_201x_FRN.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script downloads all the files corresponding to: 8 | #Sikder, M. Safat, et al. (201x) 9 | #xxx 10 | #DOI: xx.xxxx/xxxxxx 11 | #These files are available from: 12 | #Sikder, M. Safat, et al. (201x) 13 | #xxx 14 | #DOI: xx.xxxx/xxxxxx 15 | #The script returns the following exit codes 16 | # - 0 if all downloads are successful 17 | # - 22 if there was a conversion problem 18 | # - 44 if one download is not successful 19 | #Author: 20 | #Cedric H. David, 2018-2024. 21 | 22 | 23 | #******************************************************************************* 24 | #Notes on tricks used here 25 | #******************************************************************************* 26 | #wget -nv -nc --> Non-verbose (silent), No-clobber (don't overwrite) 27 | 28 | 29 | #******************************************************************************* 30 | #Publication message 31 | #******************************************************************************* 32 | echo "********************" 33 | echo "Downloading files from: http://dx.doi.org/xx.xxxx/xxxxxx" 34 | echo "which correspond to : http://dx.doi.org/xx.xxxx/xxxxxx" 35 | echo "These files are under a Creative Commons Attribution (CC BY) license." 36 | echo "Please cite these two DOIs if using these files for your publications." 37 | echo "********************" 38 | 39 | 40 | #******************************************************************************* 41 | #Location of the dataset 42 | #******************************************************************************* 43 | URL="https://zenodo.org/record/xxxxx/files" 44 | 45 | 46 | #******************************************************************************* 47 | #Download all input files 48 | #******************************************************************************* 49 | folder="../input/MIGBM_GGG" 50 | list=" \ 51 | " 52 | 53 | mkdir -p $folder 54 | for file in $list 55 | do 56 | wget -nv -nc $URL/$file -P $folder 57 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 58 | done 59 | 60 | 61 | #******************************************************************************* 62 | #Download all output files 63 | #******************************************************************************* 64 | folder="../output/MIGBM_GGG" 65 | list=" \ 66 | " 67 | 68 | mkdir -p $folder 69 | for file in $list 70 | do 71 | wget -nv -nc $URL/$file -P $folder 72 | if [ $? -gt 0 ] ; then echo "Problem downloading $file" >&2 ; exit 44 ; fi 73 | done 74 | 75 | 76 | #******************************************************************************* 77 | #Convert legacy files 78 | #******************************************************************************* 79 | #N/A 80 | 81 | 82 | #******************************************************************************* 83 | #Done 84 | #******************************************************************************* 85 | -------------------------------------------------------------------------------- /tst/tst_pub_repr_David_etal_2015_WRR.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #tst_pub_repr_David_etal_2015_WRR.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script reproduces all RAPID simulations that were used in the writing of: 8 | #David, Cédric H., James S. Famiglietti, Zong-Liang Yang, and Victor Eijkhout 9 | #(2015), Enhanced fixed-size parallel speedup with the Muskingum method using a 10 | #trans-boundary approach and a large sub-basins approximation, Water Resources 11 | #Research, 51(9), 1-25, 12 | #DOI: 10.1002/2014WR016650. 13 | #These files are available from: 14 | #David, Cédric H., James S. Famiglietti, Zong-Liang Yang, and Victor Eijkhout 15 | #(2015), 16 | #xxx 17 | #DOI: xx.xxxx/xxxxxx 18 | #The script returns the following exit codes 19 | # - 0 if all experiments are successful 20 | # - 22 if some arguments are faulty 21 | # - 33 if a search failed 22 | # - 99 if a comparison failed 23 | #Author: 24 | #Cedric H. David, 2018-2024. 25 | 26 | 27 | #******************************************************************************* 28 | #Notes on tricks used here 29 | #******************************************************************************* 30 | 31 | 32 | #******************************************************************************* 33 | #Publication message 34 | #******************************************************************************* 35 | echo "********************" 36 | echo "Reproducing results of: http://dx.doi.org/xx.xxxx/xxxxxx" 37 | echo "********************" 38 | 39 | 40 | #******************************************************************************* 41 | #Select which unit tests to perform based on inputs to this shell script 42 | #******************************************************************************* 43 | if [ "$#" = "0" ]; then 44 | fst=1 45 | lst=99 46 | echo "Performing all unit tests: 1-99" 47 | echo "********************" 48 | fi 49 | #Perform all unit tests if no options are given 50 | 51 | if [ "$#" = "1" ]; then 52 | fst=$1 53 | lst=$1 54 | echo "Performing one unit test: $1" 55 | echo "********************" 56 | fi 57 | #Perform one single unit test if one option is given 58 | 59 | if [ "$#" = "2" ]; then 60 | fst=$1 61 | lst=$2 62 | echo "Performing unit tests: $1-$2" 63 | echo "********************" 64 | fi 65 | #Perform all unit tests between first and second option given (both included) 66 | 67 | if [ "$#" -gt "2" ]; then 68 | echo "A maximum of two options can be used" 1>&2 69 | exit 22 70 | fi 71 | #Exit if more than two options are given 72 | 73 | 74 | #******************************************************************************* 75 | #Initialize counts for number of RAPID regular, optimizations and unit tests 76 | #******************************************************************************* 77 | unt=0 78 | 79 | 80 | #******************************************************************************* 81 | #Run all simulations 82 | #******************************************************************************* 83 | 84 | #------------------------------------------------------------------------------- 85 | #Create symbolic list to default namelist 86 | #------------------------------------------------------------------------------- 87 | rm -f rapid_namelist 88 | ln -s rapid_namelist_HSmsp_WRR rapid_namelist 89 | 90 | #------------------------------------------------------------------------------- 91 | #Run simulations and compare output files 92 | #------------------------------------------------------------------------------- 93 | 94 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 95 | #Test 1/x - simulation 96 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 97 | unt=$((unt+1)) 98 | if (("$unt" >= "$fst")) && (("$unt" <= "$lst")) ; then 99 | ./tst_nml_tidy_HSmsp_WRR.sh 100 | echo "Running test $unt/x - simulation" 101 | 102 | test_file="tmp_run_$unt.txt" 103 | comp_file="tmp_run_comp_$unt.txt" 104 | Qout_gold='../output/HSmsp_WRR/Qout_HSmsp_2000_2009_VIC_NASA_sgl_pa_guess_n1_preonly_ilu.nc' 105 | 106 | Qout_file='../output/HSmsp_WRR/Qout_HSmsp_2000_2009_VIC_NASA_sgl_pa_guess_n1_preonly_ilu_tst.nc' 107 | sed -i -e "s|Qout_file =.*|Qout_file ='$Qout_file'|" \ 108 | rapid_namelist_HSmsp_WRR 109 | sleep 3 110 | 111 | mpiexec -n 1 ./rapid -ksp_type preonly > $test_file 112 | 113 | echo "Comparing files" 114 | ./tst_run_comp $Qout_gold $Qout_file 1e-12 1e-10 > $comp_file 115 | x=$? && if [ $x -gt 0 ] ; then echo "Failed comparison: $comp_file" >&2 ; exit $x ; fi 116 | 117 | rm $Qout_file 118 | rm $test_file 119 | rm $comp_file 120 | ./tst_nml_tidy_HSmsp_WRR.sh 121 | echo "Success" 122 | echo "********************" 123 | fi 124 | 125 | #------------------------------------------------------------------------------- 126 | #Remove symbolic list to default namelist 127 | #------------------------------------------------------------------------------- 128 | rm -f rapid_namelist 129 | 130 | 131 | #******************************************************************************* 132 | #Done 133 | #******************************************************************************* 134 | echo "Success on all tests" 135 | echo "********************" 136 | -------------------------------------------------------------------------------- /tst/tst_pub_repr_Sikder_etal_201x_FRN.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #******************************************************************************* 3 | #tst_pub_repr_Sikder_etal_201x_FRN.sh 4 | #******************************************************************************* 5 | 6 | #Purpose: 7 | #This script reproduces all RAPID simulations that were used in the writing of: 8 | #Sikder, M. Safat, et al. (201x) 9 | #xxx 10 | #DOI: xx.xxxx/xxxxxx 11 | #The files used are available from: 12 | #Sikder, M. Safat, et al. (201x) 13 | #xxx 14 | #DOI: xx.xxxx/xxxxxx 15 | #The script returns the following exit codes 16 | # - 0 if all experiments are successful 17 | # - 22 if some arguments are faulty 18 | # - 33 if a search failed 19 | # - 99 if a comparison failed 20 | #Author: 21 | #Cedric H. David, 2018-2024. 22 | 23 | 24 | #******************************************************************************* 25 | #Notes on tricks used here 26 | #******************************************************************************* 27 | 28 | 29 | #******************************************************************************* 30 | #Publication message 31 | #******************************************************************************* 32 | echo "********************" 33 | echo "Reproducing results of: http://dx.doi.org/xx.xxxx/xxxxxx" 34 | echo "********************" 35 | 36 | 37 | #******************************************************************************* 38 | #Select which unit tests to perform based on inputs to this shell script 39 | #******************************************************************************* 40 | if [ "$#" = "0" ]; then 41 | fst=1 42 | lst=99 43 | echo "Performing all unit tests: 1-99" 44 | echo "********************" 45 | fi 46 | #Perform all unit tests if no options are given 47 | 48 | if [ "$#" = "1" ]; then 49 | fst=$1 50 | lst=$1 51 | echo "Performing one unit test: $1" 52 | echo "********************" 53 | fi 54 | #Perform one single unit test if one option is given 55 | 56 | if [ "$#" = "2" ]; then 57 | fst=$1 58 | lst=$2 59 | echo "Performing unit tests: $1-$2" 60 | echo "********************" 61 | fi 62 | #Perform all unit tests between first and second option given (both included) 63 | 64 | if [ "$#" -gt "2" ]; then 65 | echo "A maximum of two options can be used" 1>&2 66 | exit 22 67 | fi 68 | #Exit if more than two options are given 69 | 70 | 71 | #******************************************************************************* 72 | #Initialize counts for number of RAPID regular, optimizations and unit tests 73 | #******************************************************************************* 74 | unt=0 75 | 76 | 77 | #******************************************************************************* 78 | #Run all simulations 79 | #******************************************************************************* 80 | 81 | #------------------------------------------------------------------------------- 82 | #Create symbolic list to default namelist 83 | #------------------------------------------------------------------------------- 84 | rm -f rapid_namelist 85 | ln -s rapid_namelist_MIGBM_GGG rapid_namelist 86 | 87 | #------------------------------------------------------------------------------- 88 | #Run simulations and compare output files 89 | #------------------------------------------------------------------------------- 90 | 91 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 92 | #Test 1/x - simulation 93 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 94 | unt=$((unt+1)) 95 | if (("$unt" >= "$fst")) && (("$unt" <= "$lst")) ; then 96 | ./tst_nml_tidy_MIGBM_GGG.sh 97 | echo "Running test $unt/x - simulation" 98 | 99 | test_file="tmp_run_$unt.txt" 100 | comp_file="tmp_run_comp_$unt.txt" 101 | Qout_gold='../output/MIGBM_GGG/Qout_MIGBM_20000101_20091231_utc_p0_dtR1800s_n1_preonly.nc' 102 | 103 | Qout_file='../output/MIGBM_GGG/Qout_MIGBM_20000101_20091231_utc_p0_dtR1800s_n1_preonly_tst.nc' 104 | sed -i -e "s|Qout_file =.*|Qout_file ='$Qout_file'|" \ 105 | rapid_namelist_MIGBM_GGG 106 | sleep 3 107 | 108 | mpiexec -n 1 ./rapid -ksp_type preonly > $test_file 109 | 110 | echo "Comparing files" 111 | ./tst_run_comp $Qout_gold $Qout_file 1e-6 1e-3 > $comp_file 112 | x=$? && if [ $x -gt 0 ] ; then echo "Failed comparison: $comp_file" >&2 ; exit $x ; fi 113 | 114 | rm $Qout_file 115 | rm $test_file 116 | rm $comp_file 117 | ./tst_nml_tidy_MIGBM_GGG.sh 118 | echo "Success" 119 | echo "********************" 120 | fi 121 | 122 | #------------------------------------------------------------------------------- 123 | #Remove symbolic list to default namelist 124 | #------------------------------------------------------------------------------- 125 | rm -f rapid_namelist 126 | 127 | 128 | #******************************************************************************* 129 | #Done 130 | #******************************************************************************* 131 | echo "Success on all tests" 132 | echo "********************" 133 | --------------------------------------------------------------------------------