source: trunk/WRF.COMMON/WRFV3/external/io_grib1/MEL_grib1/map_lvl.c @ 3567

Last change on this file since 3567 was 2759, checked in by aslmd, 2 years ago

adding unmodified code from WRFV3.0.1.1, expurged from useless data +1M size

File size: 3.3 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include "dprints.h"      /* for debug printing  */
4#include "grib_lookup.h"  /* LVL_DEFN */
5#include "gribfuncs.h"          /* prototypes */
6
7extern LVL_DEFN    db_lvl_tbl[NLEV];     /* defined in ld_dec_lookup.c */
8
9/*
10************************************************************************
11* A. FUNCTION:  map_lvl
12*       Map the given Level_type to its appropriate usLevelid, scale up the
13*       Level_1 and Level_2 to GRIB unit and also return the Scale Factor,
14*       Reference.
15*
16*    INTERFACE:
17*       int map_lvl (lvl_type, data_input, lvl_scl_fctr, lvl_reference, errmsg)
18*
19*    ARGUMENTS (I=input, O=output, I&O=input and output):
20*      (I)   char *lvl_type;
21*            name of Level to look for in the array of Level structures;
22*      (I&O) DATA_INPUT *data_input;
23*            structure holding data pertaining to current message required by
24*            the encoder;  Three of its attributes get filled (usLevel_id,
25*            nLvl_1, nLvl_2);
26*      (O)   float *lvl_scl_fctr, float *lvl_reference;
27*            numbers needed to scale the Level up to GRIB unit.
28*            multiply the level value by the Scale Factor, then add to the
29*            Reference to convert to GRIB unit;
30*      (O)   char *errmsg;
31*            empty array, returned filled if error occurred;
32*
33*      RETURN CODE:
34*        0: success, DATA_INPUT filled, fbuff may have changed;
35*        1: parameter not found, errmsg filled;
36************************************************************************
37*/
38#if PROTOTYPE_NEEDED
39int   map_lvl ( char            *lvl_type,
40                DATA_INPUT      *data_input,
41                float           *lvl_scl_fctr,
42                float           *lvl_reference,
43                char            *errmsg)
44#else
45int   map_lvl ( lvl_type, data_input, lvl_scl_fctr, lvl_reference,errmsg)
46                char            *lvl_type;
47                DATA_INPUT      *data_input;
48                float           *lvl_scl_fctr;
49                float           *lvl_reference;
50                char            *errmsg;
51#endif
52{
53char    *func= "map_lvl";
54int     indx= 0;                /* index for array */
55int     found = 0;              /* set if located level  */
56LVL_DEFN   *PL;                 /* working var */
57
58 DPRINT1 ("Entering %s\n", func);
59/*
60* A.1       SEARCH the Level info table for the given Level Type
61*/
62   for (PL=db_lvl_tbl; indx < NLEV ; PL=(++indx +db_lvl_tbl)) 
63        if (PL->db_name[0] && !strcmp (PL->db_name, lvl_type))  {
64                found=1; break; 
65           }
66/*
67*
68* A.2       IF (cannot find it) THEN
69*              FILL errmsg with message
70*              RETURN 1  ! bad status
71*           ENDIF
72*/
73   if (!found) { 
74        DPRINT1 ("No '%s' in db_lvl_tbl;\n", lvl_type);
75        sprintf (errmsg, "%s:  no '%s' in db_lvl_tbl;", func, lvl_type);
76        return (1); 
77        }
78/*
79*
80* A.3       SCALE up nLvl_1 and nLvl_2 to GRIB's unit
81*/
82   data_input->nLvl_1 = (int)(data_input->nLvl_1 * PL->fScale + PL->fOffset);
83   data_input->nLvl_2 = (int)(data_input->nLvl_2 * PL->fScale + PL->fOffset);
84   
85/*
86*
87* A.4       FILL in Level_id DATA_INPUT struct
88*           FILL in caller's Scale factor & Reference
89*/
90   data_input->usLevel_id       = PL->usLevel_id;
91   *lvl_scl_fctr                = PL->fScale; 
92   *lvl_reference               = PL->fOffset;
93
94/*
95*
96* A.5       RETURN with no errors
97*/
98   DPRINT6 (
99    "Found '%s'\nfill Data_Input->usLevel_id=%d; *lvl_scl=%lf, *lvl_ref=%lf\n"\
100    "Scaled up Data_Input->nLvl_1= %d\nScaled up Data_Input->Lvl_2= %d\n",
101    lvl_type,
102    data_input->usLevel_id , *lvl_scl_fctr ,*lvl_reference,
103    data_input->nLvl_1, data_input->nLvl_2);
104 
105   DPRINT1 ("Exiting %s with no errors\n", func);
106   return (0);
107}
Note: See TracBrowser for help on using the repository browser.