Chapter 7

Model postprocessor

       This chapter will illustrate the post processor following the model forecast. There are two major post processors for two different types of GRIB files. One calls the pressure GRIB file; the other one calls the sigma GRIB file. The file structure and fields were already introduced in chapter 4 when we discussed the file IO. Thus we already know the pressure GRIB file contains more fields on the pressure surface. Some of the diagnostic fields from the sigma files as well as from the model diagnostic fields are also included. The sigma GRIB file contains fields on the sigma surface as well as ground surface.

      In section 7.1, we will describe the related source code to do the sigma to pressure interpolation as well as some other related routines. We will also show the user how to combine the model diagnostic field into pressure GRIB files. The second section will describe the related source code convert the binary sigma files into sigma GRIB files with some additional fields. The third section describes the method to make packed GRIB files as well as related routines. Besides the GRIB packed pressure and sigma files. There are two kinds of model outputs and related code. These outputs include station sounding profiles and budgets.


7.1 Sigma to pressure surface interpolation and related code

      The first major postprocessor is the pressure GRIB postprocessor. The job of this postprocessor is to interpolate binary sigma file from sigma surface to pressure surface and to compute some surface fields or fields by accumulation in sigma layers etc.

      Let's first "walk" through the elements of the pressure post processor.

main source file : $DISK/common/source97/MAINRPGB
related code file : can be seen from the include file
include file : $DISK/common/include/INCPOSTP
 %INCLUDE DCLSYS   ;
 %INCLUDE DCLRFCST ;
 %INCLUDE CONSTANT ;
 %INCLUDE DCLFULL  ;
 %INCLUDE MAINRPGB ;
 %INCLUDE IDSDEF   ;
 %INCLUDE GRIBIT   ;
 %INCLUDE MAKECTL  ;
                     where files before MAINRPGB are definition
                     in $DISK/common/definition, after it are
                     all in $DISK/common/source97.
do compilation  : $DISK/[machine]/[exp]/run[case] cmpl
                  with RPPGB=yes in run[case]
                  needs $DISK/[machine]/grib[machine]/w3lib.a

executable file : $DISK/run/[exp]/exec/rpgb.x

script file     : $DISK/common/script/PRPOST
#! /bin/sh
set -x
r_sigf=$1
r_flxf=$2
r_sgbf=$3
r_pgbf=$4
FH=$5

    rm -rf GRIBOUT
    $FILEENV
    $ASSIGN $r_sigf $FILEFORM  ${UNIT}11
    $ASSIGN ctlsig             ${UNIT}61
    rsgbexec=$DIREXEC/rsgb.x
    $rsgbexec >stdout.rsgb || exit
    grep ',0' ctlsig | wc -l >wc.out
    read n <wc.out && rm wc.out
    echo "s|DATAFILE|$r_sgbf|g" >inp
    echo "s|MAPFILE|$r_sgbf.map|g" >>inp
    echo "s|TOTALNUM|$n|g" >>inp
    sed -f inp ctlsig >$r_sgbf.ctlsig
    mv GRIBOUT $r_sgbf
    $FILEENV
    $ASSIGN $r_sigf $FILEFORM  ${UNIT}11
    $ASSIGN $r_flxf $FILEFORM  ${UNIT}21
    $ASSIGN ctlprs             ${UNIT}61
    $ASSIGN ctlslr             ${UNIT}62
    $ASSIGN ctldlr             ${UNIT}63
    rpgbexec=$DIREXEC/rpgb.x
    $rpgbexec >stdout.rpgb || exit
    grep ',0' ctlprs | wc -l >wc.out
    read n <wc.out && rm wc.out
    echo "s|DATAFILE|$r_pgbf|g" >inp
    echo "s|MAPFILE|$r_pgbf.map|g" >>inp
    echo "s|TOTALNUM|$n|g" >>inp
    sed -f inp ctlprs >$r_pgbf.ctlprs
    mv GRIBOUT $r_pgbf
                  : where all $ variables are defined in
                    run script. As mentioned before, this script
                    is for sigma and surface files preparation.
                    But it is flexible that it can be used for
                    sigma file with or without new regional
                    mountain, or surface file etc, and for g2n,
                    g2r, c2n or c2r. The gray characters are for
                    sigma post processor.

run it           : $DISK/[machine]/[exp]/run[case] fcst
                   It runs under the fcst section in run
                   script. However, with a little change,
                   it can be run in any place as long as the
                   directory of exe executable and the locations
                   of the files are specified.
input files      : $DISK/run/[exp]/output/r_sigf00 r_sigf03 ....
                   $DISK/run/[exp]/output/r_flxf00 r_flxf03 ....

output files     : $DISK/run/[exp]/output/r_pgbf00 
                   $DISK/run/[exp]/output/r_pgbf00.ctlprs 
Code tree        : for MAINRPGB

RSMPGRB ->  IDSDEF initial GRIB index
            CTLINI initial GrADS control file
            GPVS   initial four thermodynamical tables
            GTDP   
            GTHE
            GTMA
            RRDSGH read sigma 2 header records
            RPGB1 --> SUNPRM  prepare index for sundry
                      RRDSGR  read all sigma file
                      { loop of J row
                       GETRH  compute relative humidity
                       OMEGAW compute dp/dt and dz/dt
                       HYDRO  compute geopotential
                       SIG2P  sigma to pressure cubic interpolation
                       SIG2PT sigma to constant pressure thickness
                       SIG2Z  sigma to height
                       SUNDRY --> terrain, surface p,
                                    surface pressure tendency
                                  column precipitable water
                                         relative humidity
                                  SIG2TP tropopause fields
                                  LIFTIX lift index, cape, cini
                                  SIG2MW --> SPCOEF
                                             SPFMAX
                                             to max. wind level

                                  mean sea level pressure
                                  three low level rh
                                  2 m T rh
                                  10 m wind
                                  total cloud water if have
                                  total ozone if have
                                  5 wave height if have

                      }
                      compute absolute vorticity
                      determine the map projection
                      CTLHEAD  write GrADS control file header
                      { loop of field
                       GRIBIT --> GTBITS
                                  W3FI68
                                  PDSENS for ensemble
                                  W3FI72 create GRIB pack 
                       WRYTA   write out the packed field
                       CTLVAR  write the packed field 
                                 name to control file
                      }
                      { loop of flux field
                       READ flux
                       GRIBIT --> GTBITS
                                  W3FI68
                                  PDSENS 
                                  W3FI72 create GRIB pack
                       WRYTA
                       CTLVAR
                      }
                      compute other field
                      GRIBIT --> --> GTBITS
                                     W3FI68
                                     PDSENS 
                                     W3FI72 create GRIB pack
                      WRYTA  
                      CTLVAR
                      CTLEND  close the GrADS control file
                      return

             RRDSGH read next file hearder
             END


7.2 Diagnostic fields from sigma file and related code

       The second major postprocessor is the sigma GRIB postprocessor. The major job of this postprocessor is to pack binary sigma file into GRIB type.

 

main source file : $DISK/common/source97/MAINRSGB
related code file : can be seen from the include file
include file : $DISK/common/include/INCPOSTP
                   %INCLUDE DCLSYS   ;
                   %INCLUDE DCLRFCST ;
                   %INCLUDE CONSTANT ;
                   %INCLUDE DCLFULL  ;
                   %INCLUDE MAINRSGB ;
                   %INCLUDE IDSDEF   ;
                   %INCLUDE GRIBIT   ;
                   %INCLUDE MAKECTL  ;
do compilation : $DISK/[machine]/[exp]/run[case] cmpl 
                 with RPSGB=yes in run[case]
                 needs $DISK/[machine]/grib[machine]/w3lib.a
executable file : $DISK/run/[exp]/exec/rsgb.x
script file : $DISK/common/script/PRPOST
#! /bin/sh
     set -x
     r_sigf=$1
     r_flxf=$2
        r_sgbf=$3
        r_pgbf=$4
        FH=$5

         rm -rf GRIBOUT

         $FILEENV
         $ASSIGN $r_sigf $FILEFORM  ${UNIT}11
         $ASSIGN ctlsig             ${UNIT}61
         rsgbexec=$DIREXEC/rsgb.x
         $rsgbexec >stdout.rsgb || exit
         grep ',0' ctlsig | wc -l >wc.out
         read n <wc.out && rm wc.out
         echo "s|DATAFILE|$r_sgbf|g" >inp
         echo "s|MAPFILE|$r_sgbf.map|g" >>inp
         echo "s|TOTALNUM|$n|g" >>inp
         sed -f inp ctlsig >$r_sgbf.ctlsig
         mv GRIBOUT $r_sgbf

         $FILEENV
         $ASSIGN $r_sigf $FILEFORM  ${UNIT}11
         $ASSIGN $r_flxf $FILEFORM  ${UNIT}21
         $ASSIGN ctlprs             ${UNIT}61
         $ASSIGN ctlslr             ${UNIT}62
         $ASSIGN ctldlr             ${UNIT}63
         rpgbexec=$DIREXEC/rpgb.x
         $rpgbexec >stdout.rpgb || exit
         grep ',0' ctlprs | wc -l >wc.out
         read n <wc.out && rm wc.out
         echo "s|DATAFILE|$r_pgbf|g" >inp
         echo "s|MAPFILE|$r_pgbf.map|g" >>inp
         echo "s|TOTALNUM|$n|g" >>inp
         sed -f inp ctlprs >$r_pgbf.ctlprs
         mv GRIBOUT $r_pgbf
                  : where all $ variables are defined in
                    run script. As mentioned before, this script
                    is for sigma and surface files preparation.
                    But it is flexible that it can be used for
                    sigma file with or without new regional
                    mountain, or surface file etc, and for g2n,
                    g2r, c2n or c2r. The gray characters are for
                    sigma post processor.

run it           : $DISK/[machine]/[exp]/run[case] fcst
                   It runs under the fcst section in run
                   script. However, with a little change,
                   it can be run in any place as long as the
                   directory of exe executable and the locations
                   of the files are specified.

input files      : $DISK/run/[exp]/output/r_sigf00 r_sigf03 ....

output files     : $DISK/run/[exp]/output/r_sgbf00 
                   $DISK/run/[exp]/output/r_sgbf00.ctlsig

Code tree        : for MAINRSGB

RSMSGRB -> IDSDEF initial GRIB index
           read the header to get the related constant
           RSGB1 -> CTLINI initial GrADS control file
                    RRDSGR  read entire sigma file out
                            and compute dz/dt and dp/dt
                    set the projection definition
                    CTLHEAD write GrADS control header
                    { loop all the fields
                     GRIBIT create grid message and packed data
                     WRYTE  write out the packed data
                     CTLVAR write out the field info 
                            to control file
                    }
                    WRYTE  flush out packed data buffer
                    CTLVAR flush out the variable
                    CTLEND end of the control file
            END