Scheduled Downtime
On Friday 21 April 2023 @ 5pm MT, this website will be down for maintenance and expected to return online the morning of 24 April 2023 at the latest

4-dimensional variable in WRF output


Dear forum,

Maybe this is not a question, not to be posted here, but it might be of utility to anyone else.

I am currently working on the version 2 of the CORDEX-WRF module (CDXWRF - Wikicima, Fita et al 2019, GMD).

In this new version I would like to introduce a new diagnostic in the output which is 4-dimensional: (west_east, south_north, dimA, dimB). Up to now I only have seen 3-dimensional variables such as (west_east, south_north, bottom_top).

I spend some time diving in the code in the various I/O modules of the model: frame/module_io.f90, external/io_netcdf/wrf_io.F90, ... and it does not seems to me (as fr I understood), that there is any 'easy' way to do it. It seems that it would require a lot of coding, as far as increasing the PARAMTER NVarDims (from the external/io_netcdf/wrf_io.F90).

I am wondering if WRF does have the capability to have in the output a 4-dimensionl variable + Time? Right now I can compute the diagnostic, but it is not written in the output and simulation crashes with a segmentation fall and the creation of a core file

Thank you,

Hi Lluís,
The only information we have available on adding 4D arrays is here, but I'm not sure if that's what you're looking for.
Hi kwerner,

Thank you for the quick answer and the link.

I already succeed in defining the 4-dimensional variable in Registry and managing the 2 additional dimensions from the namelist. Even, I managed to compile and run the model with it (until it crashes).

My question is about how to write the variable in the output of the model. As far as I saw (and manage to understand), all the code related to the output seems unprepared to be able to write a variable with a rank larger than 3. It seems to me, that I would need to introduce that into the code, and it seems quite complex since is really a sensitive code with a lot of different aspects to take into account (netcdf, GRIB, pnetcdf, quilting, ...) which I do not feel confident enough with Fortran / parallelization / memory management to be able to code it.

Thank you,

After quite a long time, I got some positive feedback.

The variable I am trying to introduce is the period of time that a given grid point simultaneously passes within a threshold of 2-m temperature (T2i <= T2 < T2e) and 2-m relative humidity (RH2i <= RH2 < RH2e). In order to do that I split the 2m-temperature and 2m-relative humidity ranges in bins. The definition of these bins for T2 and RH2 is done via the namelist by the introduction of new parameters for the namelist and dimensions in the Registry

I did not managed to introduce a 4D-variable into the WRF output. However, I collapsed 2 of the dimensions related to the bins in a single one, and what I got is a 3D field.

What I tried to do is to have a variable with the following 4-dimensional variables (in output notation):
tashurstresTime, ntasrng, nhursrng, south_north, west_east)

Instead of that I created the variable as 3D:
tashurstresTime, ntashursrng, south_north, west_east)

where ntashursrng = ntasrng*nhursrng

Here is how I defined the dimensions and the associated configuration, it might be useful to someone:
* registry.cordex:
rconfig   integer nhtasrng             namelist,cordex       1              42      rh    "nhtasrng"       "amount + 1 of bins for temporal residence of tas"   ""
rconfig   integer nhhursrng            namelist,cordex       1              23      rh    "nhhursrng"      "amount + 1 of bins for temporal residence of hurs"  ""
rconfig   integer nhtashursrng         namelist,cordex       1              966     rh    "nhtashursrng"   "amount + 1 of bins for temporal residence of tas and hurs (nhtas+1)*(nhhurs+1)"   ""
rconfig   real    htasrng              namelist,cordex       max_rng        -1      rh    "htasrng"        "bins for temporal residence of tas"   ""
rconfig   real    hhursrng             namelist,cordex       max_rng        -1      rh    "hhursrng"       "bins for temporal residence of hurs"  ""
state    real  tasbins       {ht}      misc        1         -      rh9      "tasbins"        "bins of 2-m temperature for simultaneous temporal residence of 2-m temperature and relative humidity" "K"
state    real  hursbins      {hh}      misc        1         -      rh9      "hursbins"       "bins of 2-m relative humidity for simultaneous temporal residence of 2-m temperature and relative humidity" "%"
state    real  tashurstres i{hth}j     misc        1         -      rh9      "tashurstres"    "simultaneous temporal residence of 2-m temperature and relative humidity" "second"
where max_rng = 1500

* registry.diags:
dimspec    ht      2     namelist=nhtasrng             c     nhtasrng
dimspec    hh      3     namelist=nhhursrng            c     nhhursrng
dimspec    hth     2     namelist=nhtashursrng         z     nhtashursrng

At the namelist.input I would have:
nhtasrng           = 48
nhhursrng          = 23
nhtashursrng       = 1104
htasrng            = 248.15, 253.15, 258.15, 263.15,
  268.15, 269.15, 270.15, 271.15, 272.15, 273.15, 274.15, 275.15,
  276.15, 277.15, 278.15, 279.15, 280.15, 281.15, 282.15, 283.15,
  284.15, 285.15, 286.15, 287.15, 288.15, 289.15, 290.15, 291.15,
  292.15, 293.15, 294.15, 295.15, 296.15, 297.15, 298.15, 299.15,
  300.15, 301.15, 302.15, 303.15, 304.15, 305.15, 306.15, 307.15,
  308.15, 313.15, 318.15
hhursrng           = 0.00,0.05,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50,0.55,0.60,0.65,0.70,0.75,0.80,0.85,0.90,0.95,1.00,1.05,1.10,

So, to get the desired final 4D variable I would need to post-process the output by a loop like this (Fortran notation):
DO it=1, Time
  DO i=1,west_east
    DO j=1,south_north
      DO itas=nhtasrng
        DO ihurs=nhhursrng
          tashurstres(i,j,itas,ihurs,it) = wrfout_tresvar(i,j,(itas-1)*nhhursrng+ihurs,it)
        END DO
      END DO
    END DO

Many thanks for the assistance,

I forgot to mention, that the pre-definition of the max_rng (the maximum length of the bins) is done in frame/module_driver_constants.F, for example:
   ! 5. CORDEX-WRF diagnostics
   ! Maximum amount of bins for the simultaneous time of residence  
   REAL, PARAMETER                                       :: max_rng = 1500
Now the diagnostic is working, see my post on #13654

By the way, I created a fork from the main GIT WRF repository (v 4.5.3 I guess) into my own gitHUB. I included all the CORDEX-WRF module there.

I am testing it, and it seems to properly work.

I would appreciate in case WRF is interested in including it in the main repository to tell me how to proceed.

Many thanks for all your assistance,