@@ -441,8 +441,41 @@ int f_new_grid_interpolation(ARG1) {
441441 *
442442 * @return 0 for success, error code otherwise
443443 *
444- * ## Example
445- * ???
444+ * ## Examples
445+ *
446+ * The following creates a grib output file called "new.grb".
447+ * @code{.sh}
448+ * $ wgrib2 gep19.aec -for 1:5 -new_grid_winds earth -new_grid ncep grid 3 new.grb
449+ * 1:0:d=2009060500:HGT:200 mb:180 hour fcst:ENS=+19
450+ * 2:70707:d=2009060500:TMP:200 mb:180 hour fcst:ENS=+19
451+ * 3:96843:d=2009060500:RH:200 mb:180 hour fcst:ENS=+19
452+ * 4:125750:d=2009060500:UGRD:200 mb:180 hour fcst:ENS=+19
453+ * 5:166391:d=2009060500:VGRD:200 mb:180 hour fcst:ENS=+19
454+ * @endcode
455+ *
456+ * The following creates a binary formatted output file "new.bin", the scan order is we:ns. U and V are paired,
457+ * so the input order is the same as the output order.
458+ * @code{.sh}
459+ * $ wgrib2 gep19.aec -for 1:5 -new_grid_format bin -new_grid_winds earth -new_grid ncep grid 3 new.bin
460+ * 1:0:d=2009060500:HGT:200 mb:180 hour fcst:ENS=+19
461+ * 2:70707:d=2009060500:TMP:200 mb:180 hour fcst:ENS=+19
462+ * 3:96843:d=2009060500:RH:200 mb:180 hour fcst:ENS=+19
463+ * 4:125750:d=2009060500:UGRD:200 mb:180 hour fcst:ENS=+19
464+ * 5:166391:d=2009060500:VGRD:200 mb:180 hour fcst:ENS=+19
465+ * @endcode
466+ *
467+ * The following compares the binary and grib output files.
468+ * @code{.sh}
469+ * $ wgrib2 new.grb -rpn sto_0 -import_bin new.bin -rpn 'raw2:rcl_0:print_corr'
470+ * 1:0:rpn_corr=1:d=2009060500:HGT:200 mb:180 hour fcst:ENS=+19
471+ * 2:130502:rpn_corr=1:d=2009060500:TMP:200 mb:180 hour fcst:ENS=+19
472+ * 3:203989:rpn_corr=1:d=2009060500:RH:200 mb:180 hour fcst:ENS=+19
473+ * 4:261186:rpn_corr=1:d=2009060500:UGRD:200 mb:180 hour fcst:ENS=+19
474+ * 5:350963:rpn_corr=1:d=2009060500:VGRD:200 mb:180 hour fcst:ENS=+19
475+ * @endcode
476+ *
477+ * The binary file was written in we:ns, and -import_bin does not change the scan order. Therefore we have to change
478+ * the order we:sn by raw2. rpn_corr=1 .. new.grb == new.bin upto a grib rounding error.
446479 *
447480 * @author Wesley Ebisuzaki @date 6/2010
448481 */
@@ -800,10 +833,160 @@ unsigned char blank_sec1[21] = { 0,0,0,21,1,
800833 * won't be relevant to the average wgrib2 user. See the Usage section above for details about any input
801834 * parameters.
802835 *
836+ * ## Changes from copygb
837+ *
838+ * People may want to convert from copygb and copygb2 to wgrib2's -new_grid. Some differences to keep in mind.
839+ * 1. copygb default vectors: UGRD/VGRD
840+ * 2. wgrib2 default vectors: depends on version of wgrib2. See new_grid_vectors.
841+ * 3. copygb can have vectors in any order
842+ * 4. wgrib2 must have V follow U for vectors pairs
843+ * 5. copygb has bilinear, bicubic, nearest neighbor, budget, neighbor budget, and spectral interpolations.
844+ * 6. wgrib2 has bilinear, bicubic, nearest neighbor, budget, and spectral interpolations.
845+ * 7. wgrib2 can select the interpolation type depending on the variable (ex soil type)
846+ * 8. copygb uses fixed Earth's radius
847+ * 9. wgrib2 uses Earth's radius based on grib message
848+ * 10. wgrib2 doesn't have merging, mapthreshold or map files
849+ * 11. copygb by default, ignores the binary scaling and preserves decimal scaling
850+ * 12. wgrib2 by default, preserves binary and decimal scaling
851+ * 13. copygb does grib1.
852+ * 14. copygb2 does grib2.
853+ * 15. wgrib2 does grib2.
854+ *
855+ * ## Speed: Interpolation Weights
856+ * The first step of the -new_grid interpolation is to calculate the interpolation weights. (Each grid point on the
857+ * new grid is a weighted average of a small set of the old grid points.) To save time for future interpolations,
858+ * the last set of weights is saved. Consequently interpolation is fastest when the input and output grids don't change.
859+ * While one can have multiple -new_grid options on the command line, it is not recommended because the caching of the
860+ * weights wouldn't work and weights would have to be recalculated every time.
861+ *
862+ * ## Converting from WE:SN to WE:NS Grids
863+ * Many of wgrib2 grib2 writing options will write the grid in WE:SN order. This natural because geolocation is only enabled
864+ * when the internal grids are in WE:SN order. However, some codes need the grid in WE:NS order. To convert a grib file from
865+ * WE:SN order to WE:NS order, the simplest way is to use -new_grid. Lat0 and lon0 need to be lat/lon of the top left corner
866+ * of the grid. Dlon will a positive number and dlat will be negative.
867+ *
868+ * If you want to be tricky, you can do a variation of the "NDFD work arounds" technique. It will be faster and more generic.
869+ *
870+ * ### NDFD work arounds
871+ * The -new_grid option will give the following error when trying to regrid a field that is written in (WE|EW):SN order.
872+ * @code{.sh}
873+ * *** FATAL ERROR: mk_kgds: unsupported scan mode 80
874+ * @endcode
875+ * The (WE|EW):SN order means that the odd rows are in WE order and the even rows are EW order. The rows go from south to north.
876+ * This scan order is commonly used by NDFD in order to make newbies brain hurt. Try writting a program to get the lat-lon of the
877+ * Nth grid point.
878+ *
879+ * The (WE|EW):SN order is not supported by the ipolates library which does the regridding for the -new_grid option. The simplest
880+ * work around is to convert the grid to a WE:SN order.
881+ *
882+ * 1. Find the grid dimensions.
883+ * @code{.sh}
884+ * $ wgrib2 blend.grb -nxny
885+ * 1:0:(2145 x 1597)
886+ * @endcode
887+ *
888+ * 2. Use -ijsmall_grib to rewrite the entire grid. -ijsmall_grib will write the subgrid in WE:SN order.
889+ * @code{.sh}
890+ * $ wgrib2 blend.grb -ijsmall_grib 1:2145 1:1597 blend2.grb
891+ * @endcode
892+ *
893+ * ## Thinned Gaussian Grids to other Grids
894+ * Converting from a thinned Gaussian grid is a two step process using wgrib2. First you convert from the thinned grid to full grid
895+ * using -reduced_gaussian_grid. Then you can use -new_grid to interpolate to your desired grid.
896+ *
897+ * ## Quilting tiles - Merging files
898+ * Quilting is what we call combining (regional) forecasts for different domains together onto a single grid. For example, you may want
899+ * to combine various regional oceanic forecasts with a global oceanic forecast to produce a forecast for a for the user who is on a
900+ * route that covers different model domains.
901+ *
902+ * Yes, it has been done using -new_grid, -import_grib -rpn/merge. See Example 7 from @ref f_rpn.
903+ *
803904 * @return 0 for success, error code otherwise
804905 *
805- * ## Example
806- * ???
906+ * ## Examples
907+ *
908+ * The following examples interpolate from IN.grb to OUT.grb. The output file uses the same grib packing as
909+ * the input file.
910+ *
911+ * @code{.sh}
912+ * $ wgrib2 IN.grb -set_grib_type same -new_grid_winds earth -new_grid latlon 100:10:1 30:20:1 OUT.grb
913+ * @endcode
914+ *
915+ * Makes a 10x20, 1x1 degree lat-lon grid, lower left corner: 100E 30N
916+ *
917+ * @code{.sh}
918+ * $ wgrib2 IN.grb -set_grib_type same -new_grid_winds earth -new_grid ncep grid 221 OUT.grb
919+ * @endcode
920+ *
921+ * Interpolates to NCEP grid 221.
922+ *
923+ * @code{.sh}
924+ * $ wgrib2 IN.grb -set_grib_type same -new_grid_winds earth -new_grid `grid_defn.pl OLD.grb` OUT.grb
925+ * @endcode
926+ *
927+ * Interpolates using the grid format of OLD.grb (1st record)
928+ *
929+ * ### Example: Sorting the Inventory
930+ * In this example, U and V are not in the required order. This shows a sorting to the required order for
931+ * -new_grid to work.
932+ *
933+ * @code{.sh}
934+ * $ wgrib2 201201.A | sed -e 's/:UGRD:/:UGRDa:/' -e 's/:VGRD:/:UGRDb:/' | \
935+ * sort -t: -k3,3 -k5,8 -k4,4 | \
936+ * wgrib2 201201.A -i -new_grid_winds earth -new_grid ncep grid 2 201201.A.grd2
937+ * @endcode
938+ *
939+ * - The first line creates an inventory with new variable names: UGRD -> UGRDa and VGRD -> UGRDb
940+ * - The second line sorts the inventory so that UGRDb follows UGRDB.
941+ * - The third line regrids the file, with the order of processing controlled by the inventory.
942+ *
943+ * ### Type of Interpolation
944+ * The IPOLATES library supports a number of interpolation schemes including bilinear (default), bicubic,
945+ * neighbor, budget, and spectral. The interpolation method can be selected by using the -new_grid_interpolation
946+ * option before the -new_grid option. Some of the interpolation options need numeric parameters which are set by
947+ * the -new_grid_ipopt option. IPOPT is defined in the iplib library documentation.
948+ *
949+ * You can use different interpolations for different variables. For example, a bilinear interpolation of soil or
950+ * vegetation type is meaningless. So nearest neighbor interpolation is used instead.
951+ *
952+ * @code{.sh}
953+ * $ wgrib2 IN.grb -new_grid_winds earth \
954+ * -new_grid_interpolation bilinear \
955+ * -if ":(VGTYP|SOTYP):" -new_grid_interpolation neighbor -fi \
956+ * -new_grid latlon 0:360:1 90:181:-1 OUT.grb
957+ * @endcode
958+ *
959+ * - line 2: set default interpolation to bilinear
960+ * - line 3: if VGTYP or SOTYP then set the interpolation to nearest neighbor
961+ * - line 4: do the interpolation
962+ *
963+ * When you convert from a high resolution grid to a lower resolution grid, you have to be consider changing from
964+ * the default interpolation (bilinear) to a budget interpolation. The budget gives a better estimate of the cell
965+ * average (the default is 25 bilinear interpolations).
966+ *
967+ * ### Changing from grid-relative to Earth-relative winds and vice versa
968+ * Most NCEP grib files use grid-relative winds. If you want to convert to Earth-relative winds or grid-relative
969+ * winds, you can use the -new_grid option.
970+ *
971+ * To Earth relative:
972+ * @code{.sh}
973+ * $ wgrib2 IN.grb -set_grib_type same -new_grid_winds earth -new_grid_interpolation neighbor \
974+ * -new_grid `grid_defn.pl IN.grb` OUT.grb
975+ * @endcode
976+ *
977+ * To Grid relative:
978+ * @code{.sh}
979+ * $ wgrib2 IN.grb -set_grib_type same -new_grid_winds grid -new_grid_interpolation neighbor \
980+ * -new_grid `grid_defn.pl IN.grb` OUT.grb
981+ * @endcode
982+ *
983+ * - "-set_grib_type same" preserves the grib packing or compression
984+ * - "-new_grid_interpolation neighbor" should be faster than the default bilinear
985+ * - `grid_defn.pl IN.grb` returns the grid definition of the first grib message in IN.grb
986+ *
987+ * The limirations of the above command are:
988+ * - IN.grb can only have one grid type
989+ * - OUT.grb will have any submessages converted into messages
807990 *
808991 * @author Wesley Ebisuzaki @date 6/2010
809992 */
0 commit comments