# hydrotian/cama-flood_v4 architecture

> Architecture diagram of the GitHub repository hydrotian/cama-flood_v4, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hydrotian/cama-flood_v4
- Repository: https://github.com/hydrotian/cama-flood_v4

## Overview

##### Main System Components
a. Preprocessing (Map/Input Preparation)
- /src/src_param
- /src/src_region
- /src/src_dam
- etc/downscale_flddph, etc/levee_test, etc/n-year_flood_depth, etc/storage_to_floodstage, etc/runoff_preset, etc/sealev_boundary, etc/sediment
- Scripts & Python helpers under etc/* (e.g., .sh, .py)
b. Build & Execution Orchestration
- adm/ (compiler‐specific include files)
- src/ & util/ (Fortran codebase + Makefiles)
- gosh/ (job‐submission & run workflows for various HPC configs)
c. Model Core
- src/ (MAIN_cmf.F90, modules controlling boundary, physics, output, MPI, time, tracer, etc.)
- src/ICI (ice module)
- src/sediment (sediment module)
- util/igetday.F90 (utility)
d. Postprocessing & Analysis
- etc/validation (validation scripts, Python)
- etc/result_mapping (plotting)
- etc/… (various analysis workflows)
e. External Dependencies & Environment
- HPC Scheduler (SLURM/PBS/MPI)
- netCDF, MPI libraries
- External input data (maps, gauges, boundary data—not in repo, downloaded separately)
- GitHub (repository, version control)

##### Architectural Patterns & Design Principles
- Modular Fortran design (separate modules for I/O, physics, tracers, time, etc.)
- Configuration‐driven builds via adm/ include files for cross‐platform HPC builds
- Pipeline/workflow pattern: preprocess ➔ build & run ➔ postprocess
- Separation of concerns: core compute engine vs. data preparation vs. visualization
- Extensibility: new schemes toggled by runtime switches, sample workflows under etc/

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% GitHub Repo
    GH["GitHub Repository"]:::external

    %% External Dependencies & Environment
    subgraph "External Dependencies & Environment"
        DataIn["External Input Data"]:::yellow
        Scheduler["HPC Scheduler<br/>(SLURM/PBS)"]:::orange
        Libs["MPI & netCDF Libraries"]:::orange
        OptionsHPC["etc/options_HPC"]:::green
    end

    %% Preprocessing
    subgraph "Preprocessing (Map/Input Preparation)"
        Param["src/src_param"]:::blue
        Region["src/src_region"]:::blue
        Dam["src/src_dam"]:::blue
        Downscale["etc/downscale_flddph"]:::green
        LeveeT["etc/levee_test"]:::green
        FloodD["etc/n-year_flood_depth"]:::green
        Storage["etc/storage_to_floodstage"]:::green
        Runoff["etc/runoff_preset"]:::green
        SeaLev["etc/sealev_boundary"]:::green
        SedPrep["etc/sediment"]:::green
    end

    %% Build & Execution Orchestration
    subgraph "Build & Execution Orchestration"
        Adm["adm/ Include Files"]:::blue
        SrcMF["src/Makefile"]:::blue
        UtilMF["util/Makefile"]:::blue
        Iget["util/igetday.F90"]:::blue
        Gosh["gosh/ Workflows"]:::green
    end

    %% Model Core
    subgraph "Model Core (CaMa-Flood Engine)"
        Main["src/MAIN_cmf.F90"]:::blue
        Modules["src/*.F90 Modules"]:::blue
        ICI["src/ICI Module"]:::blue
        SedCore["src/sediment Module"]:::blue
    end

    %% Postprocessing & Analysis
    subgraph "Postprocessing & Analysis"
        Validation["etc/validation"]:::green
        ResultMap["etc/result_mapping"]:::green
    end

    %% Data and Control Flows
    DataIn -->|provides maps & data| Param
    DataIn --> Region
    DataIn --> Dam
    DataIn -->|feeds| Main
    OptionsHPC --> Gosh

    Param -->|input files| Main
    Region --> Main
    Dam --> Main
    Downscale --> Main
    LeveeT --> Main
    FloodD --> Main
    Storage --> Main
    Runoff --> Main
    SeaLev --> Main
    SedPrep --> Main

    Adm -->|include files| Main
    SrcMF -->|build rules| Main
    UtilMF -->|build rules| Main
    Iget -->|utility| Main
    Libs -->|linked libraries| Main

    Gosh -->|submits jobs| Main
    Scheduler -->|manages| Gosh

    Main -->|binary outputs| Validation
    Main -->|NetCDF outputs| ResultMap

    GH --> Param
    GH --> Region
    GH --> Dam
    GH --> Adm
    GH --> SrcMF
    GH --> UtilMF
    GH --> Iget
    GH --> Gosh
    GH --> Main
    GH --> Modules
    GH --> ICI
    GH --> SedCore
    GH --> Validation
    GH --> ResultMap

    %% Click Events
    click Param "https://github.com/hydrotian/cama-flood_v4/tree/master/map/src/src_param"
    click Region "https://github.com/hydrotian/cama-flood_v4/tree/master/map/src/src_region"
    click Dam "https://github.com/hydrotian/cama-flood_v4/tree/master/map/src/src_dam"
    click Downscale "https://github.com/hydrotian/cama-flood_v4/tree/master/etc/downscale_flddph"
    click LeveeT "https://github.com/hydrotian/cama-flood_v4/tree/master/etc/levee_test"
    click FloodD "https://github.com/hydrotian/cama-flood_v4/tree/master/etc/n-year_flood_depth"
    click Storage "https://github.com/hydrotian/cama-flood_v4/tree/master/etc/storage_to_floodstage"
    click Runoff "https://github.com/hydrotian/cama-flood_v4/tree/master/etc/runoff_preset"
    click SeaLev "https://github.com/hydrotian/cama-flood_v4/tree/master/etc/sealev_boundary"
    click SedPrep "https://github.com/hydrotian/cama-flood_v4/tree/master/etc/sediment"
    click Adm "https://github.com/hydrotian/cama-flood_v4/tree/master/adm/"
    click SrcMF "https://github.com/hydrotian/cama-flood_v4/tree/master/src/Makefile"
    click UtilMF "https://github.com/hydrotian/cama-flood_v4/tree/master/util/Makefile"
    click Iget "https://github.com/hydrotian/cama-flood_v4/blob/master/util/igetday.F90"
    click Gosh "https://github.com/hydrotian/cama-flood_v4/tree/master/gosh/"
    click Main "https://github.com/hydrotian/cama-flood_v4/blob/master/src/MAIN_cmf.F90"
    click ICI "https://github.com/hydrotian/cama-flood_v4/tree/master/src/ICI"
    click SedCore "https://github.com/hydrotian/cama-flood_v4/tree/master/src/sediment"
    click Validation "https://github.com/hydrotian/cama-flood_v4/tree/master/etc/validation"
    click ResultMap "https://github.com/hydrotian/cama-flood_v4/tree/master/etc/result_mapping"
    click OptionsHPC "https://github.com/hydrotian/cama-flood_v4/tree/master/etc/options_HPC"

    %% Styles
    classDef blue fill:#a8d0e6,stroke:#000,stroke-width:1px;
    classDef green fill:#84fab0,stroke:#000,stroke-width:1px;
    classDef yellow fill:#ffe66d,stroke:#000,stroke-width:1px;
    classDef orange fill:#ff8c42,stroke:#000,stroke-width:1px;
    classDef external fill:#f0f0f0,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5;
```
