Skip to content

Commit 41fd650

Browse files
finish replacing example placeholders
1 parent 63564d4 commit 41fd650

39 files changed

Lines changed: 1433 additions & 88 deletions

src/Ncpu.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@
4444
* @return 0 for success, error code otherwise.
4545
*
4646
* ## Example
47-
* ???
47+
* @code{.sh}
48+
* $ wgrib2 IN.grb -ncpu 3 -new_grid_winds grid -new_grid ncep grid 221 - | wgrib2 - -ncpu 1 -set_grib_type j -ncep_uv OUT.grb
49+
* @endcode
50+
*
51+
* The above line uses 3 threads for regridding and one thread for jpeg2000 compression. The jpeg2000
52+
* compression routines can't take advantage of more than one thread.
4853
*
4954
* @author Wesley Ebisuzaki @date 2006
5055
*/

src/Ndate.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@
7373
* @return 0 for success, error code otherwise
7474
*
7575
* ## Example
76-
* ???
76+
* @code{.sh}
77+
* $ wgrib2 /dev/null -ndate 2016010212 -6hr
78+
* 2016010206
79+
* @endcode
80+
*
7781
*
7882
* @author Wesley Ebisuzaki @date 1/2019
7983
*/

src/Ndates.c

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ extern struct seq_file inv_file;
3636
/**
3737
* Creates a list of date codes.
3838
*
39-
* This option has nothing to do with grib, but adding it to wgrib2 was trivial, and this option has been so helpful in scripting. Anyways, if a Swiss army knife can have a bottle opener, wgrib2 can have a date code routine. Anyways one less program to port is helpful.
39+
* This option has nothing to do with grib, but adding it to wgrib2 was trivial, and this option has been so helpful in scripting.
40+
* Anyways, if a Swiss army knife can have a bottle opener, wgrib2 can have a date code routine. Anyways one less program to port
41+
* is helpful.
4042
*
41-
* Note that until wgrib2 v3.0.3, the number of date codes was limited by the stdout buffer size. (See wgrib2 -config.) Wgrib2 v3.1.4 allows the optional equal sign option to include the terminating date code.
43+
* Note that until wgrib2 v3.0.3, the number of date codes was limited by the stdout buffer size. (See wgrib2 -config.) Recent versions
44+
* allow the optional equal sign option to include the terminating date code.
4245
*
43-
* The -ndate and -ndates options are initialization routines. They are run when all the options are initialized. Therefore they are run before reading the grib file. The -ndates_fmt option has to preceed the -ndates option to alter the output format.
46+
* The -ndate and -ndates options are initialization routines. They are run when all the options are initialized. Therefore they are run
47+
* before reading the grib file. The -ndates_fmt option has to preceed the -ndates option to alter the output format.
4448
*
4549
* The wgrib2 command line can have multple -ndates options.
4650
*
@@ -138,6 +142,102 @@ extern struct seq_file inv_file;
138142
*
139143
* @return 0 for success, error code otherwise
140144
*
145+
* ## Examples
146+
*
147+
* Suppose you want a list of days for 2003.
148+
* @code{.sh}
149+
* $ wgrib2 /dev/null -ndates 2003 2004 1dy
150+
* 20030101 20030102 ... 20231231
151+
* @endcode
152+
*
153+
* You could get the same result by:
154+
* @code{.sh}
155+
* $ wgrib2 /dev/null -ndates 2003 1yr 1dy
156+
* @endcode
157+
*
158+
* Now suppose you want the output to include the hours, then
159+
* @code{.sh}
160+
* $ wgrib2 /dev/null -ndates 2003 2004 24hr
161+
* 2003010100 2003010200 ... 2023123100
162+
* @endcode
163+
*
164+
* Suppose that you want the list of day from April 2000 to December 2000 inclusive. Then you can use the
165+
* inclusive form of -ndates.
166+
* @code{.sh}
167+
* $ wgrib2 /dev/null -ndates 200004 =200012 1mo
168+
* 200004 ... 200012
169+
* @endcode
170+
*
171+
* This command prints date codes for 1 month, every day:
172+
* @code{.sh}
173+
* $ wgrib2 /dev/null -ndates 2019020100 1mo 1dy
174+
* @endcode
175+
*
176+
* This prints date codes for 1 day, every 6 hours:
177+
* @code{.sh}
178+
* $ wgrib2 /dev/null -ndates 2019020100 1dy 6hr
179+
* @endcode
180+
*
181+
* This prints the months from 202001 to 202012 (inclusive):
182+
* @code{.sh}
183+
* $ wgrib2 /dev/null -ndates 202001 202101 1mo
184+
* @endcode
185+
*
186+
* ### Finding the Julian Date (ordinal date)
187+
* The ordinal date is the year and day of the year ranging from 1 and 366. To get the day of the year
188+
* from YYYYMMDD, you can use -ndates.
189+
* @code{.sh}
190+
* $ wgrib2 /dev/null -ndates {YYYY-1}1231 {YYYYMMDD} 1dy | wc -w
191+
* @endcode
192+
*
193+
* ### Date from the Julian Date (ordinal date)
194+
* Using wgrib2 to convert the date code to the Julian day is easy.
195+
*
196+
* Let YYYY be the year and N be the Julian date.
197+
* @code{.sh}
198+
* $ wgrib2 /dev/null -ndate {YYYY} {N-1}dy
199+
* @endcode
200+
*
201+
* ### Changing the ndates Format
202+
* The output of -ndates has the format:
203+
* <pre>
204+
* ( DATE)*
205+
* </pre>
206+
* space followed by the date, repeated N times.
207+
*
208+
* For example:
209+
* @code{.sh}
210+
* 2001010100 2001010106 2001010112 ...
211+
* @endcode
212+
*
213+
* For must uses, this format is fine. However, the xargs program wants each date to be on its own line.
214+
* <pre>
215+
* (DATE1)
216+
* (DATE2)
217+
* (DATE3)
218+
* ...
219+
* </pre>
220+
*
221+
* To convert the ndates format, use sed.
222+
* @code{.sh}
223+
* $ dates=`wgrib2 /dev/null -ndates 200001 1mo 1dy | sed 's/^ //' | sed 's/ /\n/g'`
224+
* @endcode
225+
* The first sed command removes the leading space, and the second sed command replaces the spaces with newlines.
226+
* Note that '\n' is the backslash character followed by the letter n. This is the bash convention for single quoted
227+
* strings.
228+
* @code{.sh}
229+
* $ echo "$dates"
230+
* @endcode
231+
* You should see the dates printed one per line.
232+
*
233+
* @code{.sh}
234+
* $ echo "$dates" | xargs -P4 -t -I% cp $dir/pgb_%_ensmean $out_dir/
235+
* @endcode
236+
* "xargs -P4" runs using 4 processes. The "-t" option echoes the command to be executred. The "-I%" option replaces
237+
* the % with the line from stdin.
238+
*
239+
* You could also change the format by the -ndates_fmt option (see @ref f_ndates_fmt).
240+
*
141241
* @author Wesley Ebisuzaki @date 1/2019
142242
*/
143243
int f_ndates(ARG3) {
@@ -346,7 +446,14 @@ int f_ndates(ARG3) {
346446
*
347447
* @return 0 for success, error code otherwise
348448
*
449+
* ## Example
450+
* @code{.sh}
451+
* $ dates=`wgrib2 /dev/null -ndates_fmt "%s\n" -ndates 200001 1mo 1dy`
452+
* $ echo "$dates" | xargs -P4 -t -I% cp $dir/pgb_%_ensmean $out_dir/
453+
* @endcode
454+
*
349455
* @author Wesley Ebisuzaki @date 1/2019
456+
*
350457
*/
351458
int f_ndates_fmt(ARG1) {
352459
const char *in;

src/New_grid.c

Lines changed: 187 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)