5 #include "dprints.h" /* for debug printing */
6 #include "grib_lookup.h" /* LVL_DEFN */
7 #include "gribfuncs.h" /* prototypes */
9 extern LVL_DEFN db_lvl_tbl
[NLEV
]; /* defined in ld_dec_lookup.c */
12 ************************************************************************
13 * A. FUNCTION: map_lvl
14 * Map the given Level_type to its appropriate usLevelid, scale up the
15 * Level_1 and Level_2 to GRIB unit and also return the Scale Factor,
19 * int map_lvl (lvl_type, data_input, lvl_scl_fctr, lvl_reference, errmsg)
21 * ARGUMENTS (I=input, O=output, I&O=input and output):
23 * name of Level to look for in the array of Level structures;
24 * (I&O) DATA_INPUT *data_input;
25 * structure holding data pertaining to current message required by
26 * the encoder; Three of its attributes get filled (usLevel_id,
28 * (O) float *lvl_scl_fctr, float *lvl_reference;
29 * numbers needed to scale the Level up to GRIB unit.
30 * multiply the level value by the Scale Factor, then add to the
31 * Reference to convert to GRIB unit;
33 * empty array, returned filled if error occurred;
36 * 0: success, DATA_INPUT filled, fbuff may have changed;
37 * 1: parameter not found, errmsg filled;
38 ************************************************************************
41 int map_lvl ( char *lvl_type
,
42 DATA_INPUT
*data_input
,
47 int map_lvl ( lvl_type
, data_input
, lvl_scl_fctr
, lvl_reference
,errmsg
)
49 DATA_INPUT
*data_input
;
55 char *func
= "map_lvl";
56 int indx
= 0; /* index for array */
57 int found
= 0; /* set if located level */
58 LVL_DEFN
*PL
; /* working var */
60 DPRINT1 ("Entering %s\n", func
);
62 * A.1 SEARCH the Level info table for the given Level Type
64 for (PL
=db_lvl_tbl
; indx
< NLEV
; PL
=(++indx
+db_lvl_tbl
))
65 if (PL
->db_name
[0] && !strcmp (PL
->db_name
, lvl_type
)) {
70 * A.2 IF (cannot find it) THEN
71 * FILL errmsg with message
72 * RETURN 1 ! bad status
76 DPRINT1 ("No '%s' in db_lvl_tbl;\n", lvl_type
);
77 sprintf (errmsg
, "%s: no '%s' in db_lvl_tbl;", func
, lvl_type
);
82 * A.3 SCALE up nLvl_1 and nLvl_2 to GRIB's unit
84 data_input
->nLvl_1
= (int)(data_input
->nLvl_1
* PL
->fScale
+ PL
->fOffset
);
85 data_input
->nLvl_2
= (int)(data_input
->nLvl_2
* PL
->fScale
+ PL
->fOffset
);
89 * A.4 FILL in Level_id DATA_INPUT struct
90 * FILL in caller's Scale factor & Reference
92 data_input
->usLevel_id
= PL
->usLevel_id
;
93 *lvl_scl_fctr
= PL
->fScale
;
94 *lvl_reference
= PL
->fOffset
;
98 * A.5 RETURN with no errors
101 "Found '%s'\nfill Data_Input->usLevel_id=%d; *lvl_scl=%lf, *lvl_ref=%lf\n"\
102 "Scaled up Data_Input->nLvl_1= %d\nScaled up Data_Input->Lvl_2= %d\n",
104 data_input
->usLevel_id
, *lvl_scl_fctr
,*lvl_reference
,
105 data_input
->nLvl_1
, data_input
->nLvl_2
);
107 DPRINT1 ("Exiting %s with no errors\n", func
);