# wintermind/bestpred architecture

> Architecture diagram of the GitHub repository wintermind/bestpred, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wintermind/bestpred
- Repository: https://github.com/wintermind/bestpred

## Overview

BESTPRED is a Fortran 90 program for estimating lactation yields and persistency with best-prediction methodology. Its user workflow is to provide lactation/test-day records, run the estimator, and inspect calculated results or lactation-curve plots. The repository also contains breed- and region-specific adjustment routines and standard-curve plotting utilities. The README documents covariance methodology, but the main Fortran sources were not excerpted; their internal stages and connections are therefore shown only as unverified links rather than asserted calls.

Main entry points: [`bestpred_main.f90`](https://github.com/wintermind/bestpred/blob/master/bestpred_main.f90) (Program entry), [`ageadjs.c`](https://github.com/wintermind/bestpred/blob/master/ageadjs.c) (Fortran adjustment bridge), [`bestpred.f90`](https://github.com/wintermind/bestpred/blob/master/bestpred.f90) (Best prediction), [`aiplage.c`](https://github.com/wintermind/bestpred/blob/master/aiplage.c) (AIPL age adjustment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prediction["Prediction"]
  node_main["Program entry<br/>[bestpred_main.f90]"]
  node_parameters["Run parameters<br/>[bestpred_parm.f90]"]
  node_core["Best prediction<br/>[bestpred.f90]"]
  node_format["Format 4 I/O<br/>[bestpred_fmt4.f90]"]
  node_logging["Run logging<br/>[bestpred_log.f90]"]
end

subgraph group_adjustments["Adjustments"]
  node_ageadj["Age adjustment<br/>[ageadj.c]"]
  node_aiplage["AIPL age adjustment<br/>[aiplage.c]"]
  node_agebridge["Fortran adjustment bridge<br/>[ageadjs.c]"]
  node_ageparams["Age factors<br/>[age.h]"]
  node_ageadjparams["Adjustment factors<br/>[ageadj.h]"]
  node_scs["SCS adjustment<br/>[adjscs.c]"]
  node_scsfactors["SCS factors<br/>[adjscs.h]"]
end

subgraph group_curves["Curve tools"]
  node_curves["Output curve plots<br/>[bestpred_curves.py]"]
  node_standard["Standard curves<br/>[standard_curves.py]"]
end

node_user(("Analyst"))
node_records["Test-day records"]
node_operator(("Plot user"))
node_results["Prediction results"]

node_user -.->|"provides"| node_records
node_records -.->|"supplies input"| node_main
node_main -.->|"uses settings"| node_parameters
node_main -.->|"dispatches format"| node_format
node_main -.->|"runs prediction"| node_core
node_main -.->|"records run"| node_logging
node_core -.->|"produces results"| node_results
node_ageadj -->|"uses factors"| node_ageparams
node_aiplage -.->|"computes factors"| node_aiplage
node_agebridge -->|"uses factors"| node_ageadjparams
node_agebridge -->|"calls"| node_scs
node_scs -->|"uses factors"| node_scsfactors
node_operator -.->|"selects output"| node_curves
node_results -.->|"reads results"| node_curves
node_operator -.->|"selects parameters"| node_standard

click node_main "https://github.com/wintermind/bestpred/blob/master/bestpred_main.f90"
click node_parameters "https://github.com/wintermind/bestpred/blob/master/bestpred_parm.f90"
click node_core "https://github.com/wintermind/bestpred/blob/master/bestpred.f90"
click node_format "https://github.com/wintermind/bestpred/blob/master/bestpred_fmt4.f90"
click node_logging "https://github.com/wintermind/bestpred/blob/master/bestpred_log.f90"
click node_ageadj "https://github.com/wintermind/bestpred/blob/master/ageadj.c"
click node_aiplage "https://github.com/wintermind/bestpred/blob/master/aiplage.c"
click node_agebridge "https://github.com/wintermind/bestpred/blob/master/ageadjs.c"
click node_ageparams "https://github.com/wintermind/bestpred/blob/master/age.h"
click node_ageadjparams "https://github.com/wintermind/bestpred/blob/master/ageadj.h"
click node_scs "https://github.com/wintermind/bestpred/blob/master/adjscs.c"
click node_scsfactors "https://github.com/wintermind/bestpred/blob/master/adjscs.h"
click node_curves "https://github.com/wintermind/bestpred/blob/master/bestpred_curves.py"
click node_standard "https://github.com/wintermind/bestpred/blob/master/standard_curves.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_parameters,node_core,node_format,node_logging,node_operator toneBlue
class node_ageadj,node_aiplage,node_agebridge,node_ageparams,node_ageadjparams,node_scs,node_scsfactors toneAmber
class node_curves,node_standard toneMint
class node_user,node_records,node_results toneIndigo
```

## Components

### Prediction

- [Program entry](https://github.com/wintermind/bestpred/blob/master/bestpred_main.f90): `bestpred_main.f90`
- [Run parameters](https://github.com/wintermind/bestpred/blob/master/bestpred_parm.f90): `bestpred_parm.f90`
- [Best prediction](https://github.com/wintermind/bestpred/blob/master/bestpred.f90): `bestpred.f90`
- [Format 4 I/O](https://github.com/wintermind/bestpred/blob/master/bestpred_fmt4.f90): `bestpred_fmt4.f90`
- [Run logging](https://github.com/wintermind/bestpred/blob/master/bestpred_log.f90): `bestpred_log.f90`

### Adjustments

- [Age adjustment](https://github.com/wintermind/bestpred/blob/master/ageadj.c): `ageadj.c`
- [AIPL age adjustment](https://github.com/wintermind/bestpred/blob/master/aiplage.c): `aiplage.c`
- [Fortran adjustment bridge](https://github.com/wintermind/bestpred/blob/master/ageadjs.c): `ageadjs.c`
- [Age factors](https://github.com/wintermind/bestpred/blob/master/age.h): `age.h`
- [Adjustment factors](https://github.com/wintermind/bestpred/blob/master/ageadj.h): `ageadj.h`
- [SCS adjustment](https://github.com/wintermind/bestpred/blob/master/adjscs.c): `adjscs.c`
- [SCS factors](https://github.com/wintermind/bestpred/blob/master/adjscs.h): `adjscs.h`

### Curve tools

- [Output curve plots](https://github.com/wintermind/bestpred/blob/master/bestpred_curves.py): `bestpred_curves.py`
- [Standard curves](https://github.com/wintermind/bestpred/blob/master/standard_curves.py): `standard_curves.py`

### Other components

- **Analyst**
- **Test-day records**
- **Plot user**
- **Prediction results**

## Connections

- Analyst → Test-day records: provides
- Test-day records → Program entry: supplies input
- Program entry → Run parameters: uses settings
- Program entry → Format 4 I/O: dispatches format
- Program entry → Best prediction: runs prediction
- Program entry → Run logging: records run
- Best prediction → Prediction results: produces results
- Age adjustment → Age factors: uses factors (evidence: `ageadj.c`)
- AIPL age adjustment → AIPL age adjustment: computes factors (evidence: `aiplage.c`)
- Fortran adjustment bridge → Adjustment factors: uses factors (evidence: `ageadjs.c`)
- Fortran adjustment bridge → SCS adjustment: calls (evidence: `ageadjs.c`)
- SCS adjustment → SCS factors: uses factors (evidence: `adjscs.c`)
- Plot user → Output curve plots: selects output
- Prediction results → Output curve plots: reads results
- Plot user → Standard curves: selects parameters
