************************************************************************
README file for the directory "fortran" included in "code_and_scripts.zip"
Petri Räisänen, Finnish Meteorological Institute, 26 Aug 2024.
************************************************************************

The zip file "fortran.zip" includes fortran programs and some auxiliary files
that were used to analyze CMIP6 and ERA5-Land data to produce the results
discussed in the manuscript Räisänen et al. (2024).

Räisänen, P., Luomaranta, A., and Jylhä, K. (2024): Future snow scenarios for
Northern Europe based on Coupled Model Intercomparison Project phase 6 data.
International Journal of Climatology, submitted.
*******************************************************************************

The following fortran files are included. The files are listed here in the
order they are described below.

yearly_analysis_CMIP6.f90
yearly_analysis_single_model_ensemble.f90
yearly_analysis_ERA5-Land.f90
modify_resolution_CMIP6_yearly.f90
modify_resolution_single_model_ensemble_yearly.f90
modify_resolution_ERA5-Land_yearly.f90
calc_trends_CMIP6.f90
calc_trends_single_model_ensemble.f90
calc_trends_ERA5-Land.f90
areal_means_CMIP6.f90
areal_means_single_model_ensemble.f90
CMIP6_ensemble_statistics_for_areal_means.f90
single_model_ensemble_statistics_for_areal_means.f90
composite_analysis_CMIP6.f90
composite_analysis_ERA5-Land.f90
modify_resolution_CMIP6_composite.f90
modify_resolution_ERA5-Land_composite.f90
make_ERA5_Land_mask.f90
modify_resolution_ERA5-Land_mask.f90

In addition, the directory "auxiliary_files" contains some files used by these
programs.

********************************************
1.
yearly_analysis_CMIP6.f90
yearly_analysis_single_model_ensemble.f90
yearly_analysis_ERA5-Land.f90
********************************************

These three programs were employed for computing snow season metrics for each
snow year (from 1 Sep of the previous year to 31 Aug of this year). The first,
second and third program were used for the set of 17 CMIP6 models with a single
realization, for large single-model ensembles for three models (ACCESS-ESM1-5,
CanESM5 and MIROC6), and for ERA5-Land reanalysis data, respectively.
The computations were performed in the native grid of each dataset. 

Note that due to data volume constraints, original CMIP6 and ERA5-Land
reanalysis data are not included in the provided data set. They can be
retrieved from ESGF (e.g, node https://esgf-data.dkrz.de) and from the
Copernicus Climate Data Store (https://cds.climate.copernicus.eu/#!/home),
respectively.

The following snow season metrics were calculated for each snow year
(1 Sep -> 31 Aug) and grid point based on the daily series of snow water
equivalent (SWE) and 2-m air temperature. (For the large single-model
ensembles, only SWE was analyzed, so the temperature-related variables
"tas_month" and "tas_year" are not included.)

- tas_month    = Monthly-mean 2-m air temperature (Sep -> Aug) 
- swe_month    = Monthly-mean SWE (Sep -> Aug)
- snowday_month= Monthly-mean snow occurrence (0-1) (Sep -> Aug)
- tas_year     = Yearly-mean 2-m air temperature (Sep -> Aug) 
- swe_year     = Yearly-mean SWE (Sep -> Aug)
- snowday_year = Yearly-mean snow occurrence (0-1) (Sep -> Aug)
- nsnowday     = Number of days with snow per "snow year"
- nsnowseason  = Indicator for a snow season with "good statistics"
- dayfirst     = Day of year for the first day with snow
- daylast      = Day of year for the last day with snow
- daystart     = Day of year for the start of the longest snow period
- dayend       = Day of year for the end of the longest snow period
- length       = Length of the longest snow period (days)
- swemax       = Maximum value of SWE
- dayswemax    = Day of year for maximum SWE
- daysnowoff1  = Snow-off day of year, based on maximum SWE
- daysnowoff2  = Snow-off day of year, based on longest snow period

Out of these quantities, mainly four are considered in the paper: swemax,
daystart, dayend and length. 

The output files are in direct access binary format, which can be read by
GrADS (http://cola.gmu.edu/grads/) and also e.g. in Fortran. The output
files and the corresponding GrADS control files are named as follows:

CMIP6 models, with a single realization per model
-------------------------------------------------
  output_yearly-{MODEL}.grads
  output_yearly-{MODEL}.ctl

These files contain data for snow years 1951-2100, and they have been
produced separately for the four scenarios SSP126, SSP245, SSP370 and SSP585.
The files are included in the zip files

  yearly_historical+ssp126.zip
  yearly_historical+ssp245.zip
  yearly_historical+ssp370.zip
  yearly_historical+ssp585.zip

Large single-model ensembles
------------------------------
The output files are provided for snow years 1951-2100, combining the
historical experiments with the SSP245 scenario. The output file and GrADS
control file names are of the form
  output_yearly_{MODEL}_{REALIZATION}.grads
  output_yearly_{MODEL}_{REALIZATION}.ctl

They are included in the zip files

  yearly_historical+ssp245_ACCESS-ESM1-5.zip
  yearly_historical+ssp245_CanESM5.zip
  yearly_historical+ssp245_MIROC6.zip

ERA5-Land reanalysis data
--------------------------
Snow metrics computed for snow years 1951-2023 are provided at the original
0.1 x 0.1 deg resolution. The output file and GrADS control file are named

  output_yearly-ERA5-Land.grads
  output_yearly-ERA5-Land.ctl

These files are included in the zip file "yearly_ERA5-Land.zip".


***************************************************
2.
modify_resolution_CMIP6_yearly.f90
modify_resolution_single_model_ensemble_yearly.f90
modify_resolution_ERA5-Land_yearly.f90
***************************************************

These programs were employed for regridding the yearly snow season metrics
data to a uniform 0.5 x 0.5 deg grid. For CMIP6 data, bilinear interpolation
with respect to latitude and longitude was used, while for ERA5-Land data,
the regridding was made through conservative interpolation that conserves the
areal-mean values. The output files and GrADS control files are named as:

CMIP6 models, with a single realization per model
-------------------------------------------------
  output_yearly-{MODEL}-0.50x0.50_deg.grads
  output_yearly-{MODEL}-0.50x0.50_deg.ctl

Large single-model ensembles
------------------------------
  output_yearly_{MODEL}_{REALIZATION}-0.50x0.50_deg.grads
  output_yearly_{MODEL}_{REALIZATION}-0.50x0.50_deg.ctl

ERA5-Land reanalysis data
--------------------------
  output_yearly-ERA5-Land-0.50x0.50_deg.grads
  output_yearly-ERA5-Land-0.50x0.50_deg.ctl

These files are included in the same "yearly_historical***.zip" files as
the snow season metrics at the native resolution (listed above).


***************************************
3.
calc_trends_CMIP6.f90
calc_trends_single_model_ensemble.f90
calc_trends_ERA5-Land.f90
***************************************

Trends in snow season metrics were calculated based on CMIP6 and ERA5-Land
yearly snow season metrics interpolated to a 0.5 x 0.5 deg grid. Trends were
calculated for years 1951-2023 and for (CMIP6 data only) 2023-2100, for
five snow season metrics

- nsnowday     = Number of days with snow per snow year
- daystart     = Day of year for the start of the longest snow period
- dayend       = Day of year for the end of the longest snow period
- length       = Length of the longest snow period (days)
- swemax       = Maximum value of SWE

Three options were employed for calculating the trends
  1) Ordinary linear regression
  2) Ordinary linear regression with pre-whitening
     to account for lag-1 autocorrelations, based on Eq. (A11) in

  Wang, X. L., and V. R. Swail, 2001: Changes of Extreme Wave Heights
  in Northern Hemisphere Oceans and Related Atmospheric Circulation
  Regimes. J. Climate, 14, 2204–2221,
  https://doi.org/10.1175/1520-0442(2001)014<2204:COEWHI>2.0.CO;2.

  3) Theil-Sen regression, with Mann-Kendall test to determine
  statistical significance

In practice, the trends calculated using these three options agree closely. For
simplicity, results for the ordinary linear regression are used in Räisänen
et al. 2024.

The output files and GrADS control files are named as follows:

CMIP6 models, with a single realization per model
-------------------------------------------------
  trends-{MODEL}-{PERIOD}-0.50x0.50_deg.grads
  trends-{MODEL}-{PERIOD}-0.50x0.50_deg.ctl

These  were computed separately for the four scenarios SSP126, SSP245, SSP370
and SSP585. The files are included in "trends.zip", in the directories
   historical+ssp126
   historical+ssp245
   historical+ssp370
   historical+ssp585

Large single-model ensembles
------------------------------
   trends-{MODEL}_ensemble-{PERIOD}-0.50x0.50_deg.grads
   trends-{MODEL}_ensemble-{PERIOD}-0.50x0.50_deg.ctl

These files are included in "trends.zip", in the directory "historical+ssp245"

ERA5-Land reanalysis data
--------------------------
  trends-ERA5-Land_1951-2023-0.50x0.50_deg.grads
  trends-ERA5-Land_1951-2023-0.50x0.50_deg.ctl

These files are included in "trends.zip", in the directory "ERA5-Land".


***************************************
4.
areal_means_CMIP6.f90
areal_means_single_model_ensemble.f90
***************************************

These programs were used for calculating areal-mean values of yearly snow
season metrics (snow years 1951-2100) for Southern Finland (60.5-62N, 23-27E)
and Finnish Lapland (67-69N, 24-28E) for CMIP6 models with a single realization
per experiment, and for the three large single-model ensembles (ACCESS-ESM1-5,
CanESM5 and MIROC6). As input, yearly snow season metrics at 0.5 x 0.5 deg
resolution were used. The output files and the respective GrADS control files
are named as follows:

CMIP6 models, with a single realization per model
-------------------------------------------------
  avg_South_yearly-{MODEL}.grads
  avg_South_yearly-{MODEL}.ctl
  avg_North_yearly-{MODEL}.grads
  avg_North_yearly-{MODEL}.ctl

Here, "South" refers to the Southern Finland region and "North" to Finnish
Lapland. These files are included in the zip file "areal_means.zip", in
the directories
  historical+ssp126
  historical+ssp245
  historical+ssp370
  historical+ssp585

Large single-model ensembles
------------------------------
  avg_South_yearly-{MODEL}_ensemble.grads
  avg_South_yearly-{MODEL}_ensemble.ctl
  avg_North_yearly-{MODEL}_ensemble.grads
  avg_North_yearly-{MODEL}_ensemble.ctl

These files are in the zip file "areal_means.zip", in the directory
"historical+ssp245".


*****************************************************
5.
CMIP6_ensemble_statistics_for_areal_means.f90
single_model_ensemble_statistics_for_areal_means.f90
*****************************************************

These programs were used for calculating ensemble statistics of 20-year
running-mean values of snow season metrics and their differences from the
averages over the reference period 1981-2010, for the Southern Finland
("South") and Finnish Lapland ("North") regions. With the first program,
computations were made for an ensemble of 11 CMIP6 models with a single
realization per experiment, combining time series of the historical
experiments with each of the four emission scenarions SSP126, SSP245, SSP370
and SSP585. Both unweighted statistics (i.e., the same weight for all models)
and statistics weighted based on the Transient Climate Response (TCR) were
computed (see Räisänen et al. 2024). With the second program, ensemble
statistics were computed for the three large single-model ensembles
(ACCESS-ESM1-5, CanESM5 and MIROC6) for the historical+SSP245 experiments.

In both cases, the statistics include ensemble mean values, standard
deviations, minimum and maximum values and percentage points (5th, 25th, 50th,
75th and 95th perecentile of the distribution).

Output and GrADS control file are named as follows:

CMIP6 models, with a single realization per model
-------------------------------------------------
   statistics_South_CMIP6_TCR-weighted.grads
   statistics_South_CMIP6_unweighted.grads
   statistics_North_CMIP6_TCR-weighted.grads
   statistics_North_CMIP6_unweighted.grads

   statistics_South_CMIP6_TCR-weighted.ctl
   statistics_South_CMIP6_unweighted.ctl
   statistics_North_CMIP6_TCR-weighted.ctl
   statistics_North_CMIP6_unweighted.ctl

These files are included in the zip file "areal_means.zip", in the directories
   historical+ssp126
   historical+ssp245
   historical+ssp370
   historical+ssp585

Large single-model ensembles
------------------------------
  statistics_South_{MODEL}.grads
  statistics_North_{MODEL}.grads
  statistics_South_{MODEL}.ctl
  statistics_North_{MODEL}.ctl

These files are included in the zip file "areal_means.zip", in the directory
   historical+ssp245


**********************************
6.
composite_analysis_CMIP6.f90
composite_analysis_ERA5-Land.f90
**********************************

These programs were used for composite analysis of SWE and 2-m air temperature
with respect to the time before the snowoff-day (first day with SWE < 1 kg m-2)
after the winter's main snow period. Two definitions of the "main snow period"
were used. 1) The period in which the winter's maximum SWE occurs. 2) The
winter's longest period with SWE > 1 kg m-2. The latter definition was used in
Räisänen et al. (2024) (Supporting information Figure S1) but both give very
similar results. Composite mean values over the snow years 1981-2010 were
computed for each grid point at the native resolution of CMIP6 models and
ERA5-Land reanalysis. The following output data are computed as a function
of the time difference to the snow-off day (from -60 to 10 days):

tas1     average temperature (K), snow-off based on SWE maximum
snw1     average SWE (kg m-2), snow-off based on SWE maximum
psnow1   probability of snow present, snow-off based on SWE maximum
tas2     average temperature (K), snow-off based on longest snow period
snw2     average SWE (kg m-2), snow-off  based on longest snow period
psnow2   probability of snow present, snow-off based on longest snow period

The output files and corresponding GrADS control files are named as follows:

CMIP6 models, with a single realization per model
-------------------------------------------------
  output_composite-{MODEL}.grads
  output_composite-{MODEL}.ctl

These files are included in the zip file "composite.zip".

ERA5-Land reanalysis data
--------------------------
  output_composite-ERA5-Land.grads
  output_composite-ERA5-Land.ctl

These files are likewise included in the zip file "composite.zip".


******************************************
7.
modify_resolution_CMIP6_composite.f90
modify_resolution_ERA5-Land_composite.f90
******************************************

These programs were used for regridding the composite analysis results to
a uniform 0.5 x 0.5 deg grid, by means of blinear interpolation for CMIP6 data
and conservative interpolation for ERA5-Land data. The output files and
corresponding GrADS control files are named as follows:

CMIP6 models, with a single realization per model
-------------------------------------------------
  output_composite-{MODEL}-0.50x0.50_deg.grads
  output_composite-{MODEL}-0.50x0.50_deg.ctl

These files are included in the zip file "composite.zip".

ERA5-Land reanalysis data
--------------------------
  output_composite-ERA5-Land-0.50x0.50_deg.grads
  output_composite-ERA5-Land-0.50x0.50_deg.ctl

These files are likewise included in the zip file "composite.zip".


**************************************
8. 
make_ERA5_Land_mask.f90
modify_resolution_ERA5-Land_mask.f90
**************************************

The first program was used to make a land mask file for ERA5-Land data. Since
the land mask is temporally constant, the land mask was made based on
a single time step of ERA5-Land 2-m air temperature data
("2m_temperature_ERA5-Land_1Jan2000_00UTC.nc"). The second program was
used for regridding the land mask file to 0.5 x 0.5 deg resolution.
The output files and the corresponding GrADS control files

ERA5_Land_mask.grads
ERA5_Land_mask-0.50x0.50_deg.grads
ERA5_Land_mask.ctl
ERA5_Land_mask-0.50x0.50_deg.ctl

are included in the file "fortran.zip" in the directory "auxiliary_files".


********************************
9. auxiliary_files (directory)
********************************

A number of auxiliary files are read by the fortran programs listed above.

9.1) Files related to the ERA5-Land land mask

  2m_temperature_ERA5-Land_1Jan2000_00UTC.nc 
  ERA5_Land_mask-0.50x0.50_deg.ctl
  ERA5_Land_mask-0.50x0.50_deg.grads
  ERA5_Land_mask.ctl
  ERA5_Land_mask.grads  

The first file was used as input for definining the land mask.

9.2) Lists of input files: CMIP6 models with a single realization per model

  inputfiles_historical.asc
  inputfiles_historical+ssp126.asc
  inputfiles_historical+ssp245.asc
  inputfiles_historical+ssp370.asc
  inputfiles_historical+ssp585.asc

9.3) List of input files: the three large single-model ensembles

  inputfiles_ACCESS-ESM1-5.asc
  inputfiles_CanESM5.asc
  inputfiles_MIROC6.asc

9.4) Template files used when producing control files for the GrADS files

  CMIP6_ensemble_areal_mean_statistics_template.ctl
  output_composite_template.ctl
  output_yearly_areal_means_single_model_ensemble_template.ctl
  output_yearly_areal_means_template.ctl
  output_yearly_template.ctl
  output_yearly_template_snow.ctl
  single_model_ensemble_areal_mean_statistics_template.ctl
  trends_template_CMIP6.ctl
  trends_template_ERA5-Land.ctl
  trends_template_single_model_ensemble.ctl

