source: trunk/WRF.COMMON/WRFV3/external/io_grib1/MEL_grib1/map_parm.c

Last change on this file 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: 4.3 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include "dprints.h"      /* for debug printing  */
4#include "grib_lookup.h"  /* PARM_DEFN */
5#include "gribfuncs.h"          /* prototypes */
6
7/* DB_PARM_TBL is defined in ld_enc_inputs.c:
8#  as of 4/9/97 this tbl is the master Parameter Table holding
9#  MAX_PARM_TBLS  sets of 256 parameters (previously known as
10#  Tbl 0/A/B/C/D/E).
11#  Index that are divisable by 256 are reserved and not used;
12#    indices   000-255:  Main parameter tbl (000 is reserved & not used)
13#    indices   256-511:  subtable A (256 is reserved & not used)
14#    indices   512-767:  subtable B (512 is reserved & not used)
15#    indices  768-1023:  subtable C (768 is reserved & not used)
16#    indices 1024-1279:  subtable D (1024 is reserved & not used)
17#    indices 1080-1535:  subtable E (1080 is reserved & not used)
18*/
19extern PARM_DEFN    db_parm_tbl[];
20
21/*
22************************************************************************
23* A. FUNCTION:  map_parm
24*      Map the given Parm_name to its appropriate usParm_id and usParm_sub
25*      within the Parameter Lookup table, and also return its
26*      Scale Factor and Reference which the caller can apply to the
27*      float dta at a later time.
28*
29*    INTERFACE
30*      int  map_parm (parm_name, data_input, parm_scl, parm_ref, errmsg)
31*
32*    ARGUMENTS (I=input, O=output, I&O=input and output):
33*      (I)  char *parm_name
34*           Name of Parameter to look for in the array of Parameter structs
35*      (I&O) DATA_INPUT *data_input
36*           attributes (usParm_id, usParm_sub_id, nDec_sc_fctr) are filled;
37*      (O)  float *parm_scl       
38*           used along with parm_ref to convert data to GRIB unit
39*      (O)  float *parm_ref       
40*           used along with parm_scl to convert data to GRIB unit
41*                     
42*    RETURN CODE:
43*      0> success, DATA_INPUT, parm_scl and parm_ref filled
44*      1> parameter not found, errmsg filled;
45************************************************************************
46*/
47#if PROTOTYPE_NEEDED
48int     map_parm ( char         *parm_name,
49                DATA_INPUT      *data_input,
50                float           *parm_scl, 
51                float           *parm_ref,
52                char            *errmsg)
53
54#else
55int     map_parm ( parm_name, data_input, parm_scl, parm_ref, errmsg)
56                char            *parm_name;
57                DATA_INPUT      *data_input;
58                float           *parm_scl;
59                float           *parm_ref;
60                char            *errmsg;
61#endif
62{
63char    *func= "map_parm";
64int     indx= 0;                /* index for array */
65int     found = 0;              /* set if located parm */
66PARM_DEFN   *P;                 /* working var */
67
68  DPRINT1 ("Entering %s\n", func);
69
70/*
71* A.1       SEARCH the Parameter info table for the given Parm Name
72*/
73   for (P=db_parm_tbl; indx < NPARM*MAX_PARM_TBLS; P=(++indx +db_parm_tbl)) 
74        if (P->db_name[0] && !strcmp (P->db_name, parm_name))  {
75                found=1; break; 
76           }
77/*
78*
79* A.2       IF (cannot find it) THEN
80*              FILL errmsg with message
81*              RETURN 1  ! bad status
82*           ENDIF
83*/
84   if (!found) { 
85        DPRINT1 ("No '%s' in db_parm_tbl;\n", parm_name);
86        sprintf (errmsg, "%s: no '%s' in db_parm_tbl", func, parm_name);
87        DPRINT1 ("Exiting  %s, with errors\n", func);
88        return (1); 
89        }
90/*
91*
92* A.3       FILL in Parmid, subParmid, nDec_sc_fctr of DATA_INPUT struct
93*           FILL in Parm_scl and Parm_ref for caller
94*/
95   data_input->usParm_id      = P->usParm_id;
96   data_input->usParm_sub_id  = P->usParm_sub;
97   data_input->nDec_sc_fctr   = P->sDSF;
98   *parm_scl            = P->fScale;
99   *parm_ref            = P->fOffset;
100
101   DPRINT4 (
102   "Found '%s'\nfill Data_Input->Parm_id=%d; \nfill Data_Input->Parm_sub=%d;"\
103   "\nfill Data_Input->DSF=%d\n",
104   parm_name, data_input->usParm_id, data_input->usParm_sub_id,
105   data_input->nDec_sc_fctr);
106
107/*
108#*
109* A.4       /# comment #/
110#* A.4       IF (there is a scl fctr  OR nonzero Offset) THEN
111#*               APPLY Scale Fctr and Offset to Float data
112#*               for all data points in grid
113#*           ENDIF
114##/
115#  ... where... data_pts was passed in as an argument...
116#
117#   if (P->fScale != 1.0 || P->fOffset != 0.0) {
118#       DPRINT3 ("Scaling FloatArr[%d pts] w/ Scale=%lf, Off=%lf\n",
119#       data_pts,  P->fScale , P->fOffset);
120#
121#       for (indx=0; indx < data_pts; ++indx)
122#               fbuff[indx]=  fbuff[indx] * P->fScale + P->fOffset;
123#       }
124#   else { DPRINT2("Not scaling float dta  (Scl=%lf, Offs=%lf)\n",
125#        P->fScale , P->fOffset);
126#       }
127*/
128   
129/*
130*
131* A.5       RETURN with no errors
132*/
133   DPRINT1 ("Exiting %s with no errors\n", func);
134   return (0);
135/*
136*
137* END OF FUNCTION
138*/
139}
Note: See TracBrowser for help on using the repository browser.