Skip Navigation Links www.nws.noaa.gov 
NOAA logo - Click to go to the NOAA home page National Weather Service   NWS logo - Click to go to the NWS home page
Climate Prediction Center
 
 

 
About Us
   Our Mission
   Who We Are

Contact Us
   CPC Information
   CPC Web Team

 
HOME > Monitoring_and_Data > Oceanic and Atmospheric Data > Reanalysis: Atmospheric Data > wgrib2
 

wgrib2: a sample function

Introduction

Wgrib2 is "function" driven. Every option on the command line now calls a function. Each function is called several times, for initialization (mode=-1), for each grib record (mode=0,1,2 depending on the verbosity index) and for clean up (mode=-2). Here is a sample function.



#include <stdio.h>
#include "grb2.h"
#include "wgrib2.h"
#include "fnlist.h"

extern int decode;
extern int need_output_file;

/*
* HEADER:100:min:inv:0:print minimum value
* the above line is needed by each command line option
* HEADER:sort-order:type-of-function:number-of-arguments:description
*/

int f_min(int mode, unsigned char **sec, float *data, int ndata, FILE *out) {
   double mn;
   int ok, i;

   if (mode == -1) decode = 1;
   else {
     mn = ok = 0;
     for (i = 0; i < ndata; i++) {
       if (!UNDEFINED_VAL(data[i])) {
         if (ok) mn = mn < data[i] ? mn : data[i];
         else { ok = 1; mn = data[i]; }
       }
     }
     if (ok) printf("min=%lg",mn);
     else printf("min=undefined");
   }
   return 0;
}

NOAA/ National Weather Service
National Centers for Environmental Prediction
Climate Prediction Center
5830 University Research Court
College Park, Maryland 20740
Climate Prediction Center Web Team
Page last modified: May 15, 2005
Disclaimer Privacy Policy