mirror of https://github.com/ecmwf/eccodes.git
Make C, Fortran and Python examples ECC-15
This commit is contained in:
parent
09a3156f6e
commit
e220456317
|
@ -55,24 +55,22 @@ int main(int argc,char* argv[])
|
||||||
printf("message: %d\n",cnt);
|
printf("message: %d\n",cnt);
|
||||||
|
|
||||||
/* we need to instruct ecCodes to expand the descriptors
|
/* we need to instruct ecCodes to expand the descriptors
|
||||||
i.e. unpack the data values */
|
i.e. unpack the data values */
|
||||||
CODES_CHECK(codes_set_long(h,"unpack",1),0);
|
CODES_CHECK(codes_set_long(h,"unpack",1),0);
|
||||||
|
|
||||||
/* In what follows we rely on the fact that for
|
/* In what follows we rely on the fact that for
|
||||||
temperature significant levels the value of key
|
temperature significant levels the value of key
|
||||||
verticalSoundingSignificance is 4 (see flag table 8001 for details).
|
verticalSoundingSignificance is 4 (see flag table 8001 for details).
|
||||||
|
|
||||||
We also make use of the fact that in our BUFR message
|
We also make use of the fact that in our BUFR message
|
||||||
verticalSoundingSignificance is always followed by geopotential,
|
verticalSoundingSignificance is always followed by geopotential,
|
||||||
airTemperature, dewpointTemperature,
|
airTemperature, dewpointTemperature,
|
||||||
windDirection, windSpeed and pressure. */
|
windDirection, windSpeed and pressure. */
|
||||||
|
|
||||||
/* -------------------------------------------------------
|
/* Get the number of the temperature significant levels.*/
|
||||||
Get the number of the temperature significant levels.
|
|
||||||
------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* We find out the number of temperature significant levels by
|
/* We find out the number of temperature significant levels by
|
||||||
counting how many pressure values we have on these levels. */
|
counting how many pressure values we have on these levels. */
|
||||||
|
|
||||||
sprintf(key_name,"/verticalSoundingSignificance=4/pressure");
|
sprintf(key_name,"/verticalSoundingSignificance=4/pressure");
|
||||||
CODES_CHECK(codes_get_size(h,key_name,&sigt_len),0);
|
CODES_CHECK(codes_get_size(h,key_name,&sigt_len),0);
|
||||||
|
@ -80,15 +78,13 @@ int main(int argc,char* argv[])
|
||||||
printf("Number of T significant levels: %ld\n",sigt_len);
|
printf("Number of T significant levels: %ld\n",sigt_len);
|
||||||
|
|
||||||
/* Allocate memory for the values to be read. Each
|
/* Allocate memory for the values to be read. Each
|
||||||
parameter must have the same number of values. */
|
parameter must have the same number of values. */
|
||||||
sigt_pres = malloc(sigt_len*sizeof(double));
|
sigt_pres = malloc(sigt_len*sizeof(double));
|
||||||
sigt_geo = malloc(sigt_len*sizeof(double));
|
sigt_geo = malloc(sigt_len*sizeof(double));
|
||||||
sigt_t = malloc(sigt_len*sizeof(double));
|
sigt_t = malloc(sigt_len*sizeof(double));
|
||||||
sigt_td = malloc(sigt_len*sizeof(double));
|
sigt_td = malloc(sigt_len*sizeof(double));
|
||||||
|
|
||||||
/* --------------------------
|
/* Get pressure */
|
||||||
Get pressure
|
|
||||||
----------------------------*/
|
|
||||||
|
|
||||||
sprintf(key_name,"/verticalSoundingSignificance=4/pressure");
|
sprintf(key_name,"/verticalSoundingSignificance=4/pressure");
|
||||||
|
|
||||||
|
@ -96,13 +92,11 @@ int main(int argc,char* argv[])
|
||||||
len=sigt_len;
|
len=sigt_len;
|
||||||
CODES_CHECK(codes_get_double_array(h,key_name,sigt_pres,&len),0);
|
CODES_CHECK(codes_get_double_array(h,key_name,sigt_pres,&len),0);
|
||||||
|
|
||||||
/* --------------------------
|
/* Get gepotential */
|
||||||
Get gepotential
|
|
||||||
----------------------------*/
|
|
||||||
|
|
||||||
sprintf(key_name,"/verticalSoundingSignificance=4/geopotential");
|
sprintf(key_name,"/verticalSoundingSignificance=4/geopotential");
|
||||||
|
|
||||||
/* Check the size*/
|
/* check the size*/
|
||||||
CODES_CHECK(codes_get_size(h,key_name,&len),0);
|
CODES_CHECK(codes_get_size(h,key_name,&len),0);
|
||||||
if(len != sigt_len)
|
if(len != sigt_len)
|
||||||
{
|
{
|
||||||
|
@ -113,13 +107,11 @@ int main(int argc,char* argv[])
|
||||||
/* get the values */
|
/* get the values */
|
||||||
CODES_CHECK(codes_get_double_array(h,key_name,sigt_geo,&len),0);
|
CODES_CHECK(codes_get_double_array(h,key_name,sigt_geo,&len),0);
|
||||||
|
|
||||||
/* --------------------------
|
/* Get temperature */
|
||||||
Get temperature
|
|
||||||
----------------------------*/
|
|
||||||
|
|
||||||
sprintf(key_name,"/verticalSoundingSignificance=4/airTemperature");
|
sprintf(key_name,"/verticalSoundingSignificance=4/airTemperature");
|
||||||
|
|
||||||
/* Check the size*/
|
/* check the size*/
|
||||||
if(len != sigt_len)
|
if(len != sigt_len)
|
||||||
{
|
{
|
||||||
printf("inconsistent number of temperature values found!\n");
|
printf("inconsistent number of temperature values found!\n");
|
||||||
|
@ -129,14 +121,11 @@ int main(int argc,char* argv[])
|
||||||
/* get the values */
|
/* get the values */
|
||||||
CODES_CHECK(codes_get_double_array(h,key_name,sigt_t,&len),0);
|
CODES_CHECK(codes_get_double_array(h,key_name,sigt_t,&len),0);
|
||||||
|
|
||||||
|
/* Get dew point */
|
||||||
/* --------------------------
|
|
||||||
Get dew point
|
|
||||||
----------------------------*/
|
|
||||||
|
|
||||||
sprintf(key_name,"/verticalSoundingSignificance=4/dewpointTemperature");
|
sprintf(key_name,"/verticalSoundingSignificance=4/dewpointTemperature");
|
||||||
|
|
||||||
/* Check the size*/
|
/* check the size*/
|
||||||
if(len != sigt_len)
|
if(len != sigt_len)
|
||||||
{
|
{
|
||||||
printf("inconsistent number of dewpoint temperature values found!\n");
|
printf("inconsistent number of dewpoint temperature values found!\n");
|
||||||
|
@ -146,10 +135,7 @@ int main(int argc,char* argv[])
|
||||||
/* get the values */
|
/* get the values */
|
||||||
CODES_CHECK(codes_get_double_array(h,key_name,sigt_td,&len),0);
|
CODES_CHECK(codes_get_double_array(h,key_name,sigt_td,&len),0);
|
||||||
|
|
||||||
|
/* Print the values */
|
||||||
/*--------------------------------
|
|
||||||
Print the values
|
|
||||||
---------------------------------*/
|
|
||||||
|
|
||||||
printf("lev pres geo t td\n");
|
printf("lev pres geo t td\n");
|
||||||
printf("-------------------------------\n");
|
printf("-------------------------------\n");
|
||||||
|
|
|
@ -49,60 +49,48 @@ def example():
|
||||||
# airTemperature, dewpointTemperature,
|
# airTemperature, dewpointTemperature,
|
||||||
# windDirection, windSpeed and pressure.
|
# windDirection, windSpeed and pressure.
|
||||||
|
|
||||||
#-------------------------------------------------------
|
|
||||||
# Get the number of the temperature significant levels.
|
# Get the number of the temperature significant levels.
|
||||||
#------------------------------------------------------
|
|
||||||
|
|
||||||
# We find out the number of temperature significant levels by
|
# We find out the number of temperature significant levels by
|
||||||
# counting how many pressure values we have on these levels.
|
# counting how many pressure values we have on these levels.
|
||||||
|
|
||||||
numSigT=codes_get_size(gid,"/verticalSoundingSignificance=4/pressure")
|
numSigT=codes_get_size(gid,"/verticalSoundingSignificance=4/pressure")
|
||||||
print ' Number of temperature significant levels %ld' % (numSigT)
|
print ' Number of temperature significant levels %ld' % (numSigT)
|
||||||
|
|
||||||
# ----------------------------
|
|
||||||
# Get pressure
|
# Get pressure
|
||||||
# ----------------------------
|
|
||||||
|
sigt_pres=codes_get_double_array(gid,"/verticalSoundingSignificance=4/pressure")
|
||||||
sigt_pres=codes_get_array(gid,"/verticalSoundingSignificance=4/pressure")
|
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# Get gepotential
|
# Get gepotential
|
||||||
#--------------------------------
|
|
||||||
|
sigt_geo=codes_get_double_array(gid,"/verticalSoundingSignificance=4/geopotential")
|
||||||
|
|
||||||
sigt_geo=codes_get_array(gid,"/verticalSoundingSignificance=4/geopotential")
|
if len(sigt_geo) != numSigT :
|
||||||
|
|
||||||
if len(sigt_geo) != sigTNum :
|
|
||||||
print "inconstitent number of geopotential values found!"
|
print "inconstitent number of geopotential values found!"
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# Get temperature
|
# Get temperature
|
||||||
#--------------------------------
|
|
||||||
|
sigt_t=codes_get_double_array(gid,"/verticalSoundingSignificance=4/airTemperature")
|
||||||
|
|
||||||
sigt_t=codes_get_array(gid,"/verticalSoundingSignificance=4/airTemperature")
|
if len(sigt_t) != numSigT :
|
||||||
|
|
||||||
if len(sigt_t) != sigTNum :
|
|
||||||
print "inconstitent number of temprature values found!"
|
print "inconstitent number of temprature values found!"
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# Get dew point
|
# Get dew point
|
||||||
#--------------------------------
|
|
||||||
|
|
||||||
sigt_td=codes_get_array(gid,"/verticalSoundingSignificance=4/dewpointTemperature")
|
sigt_td=codes_get_double_array(gid,"/verticalSoundingSignificance=4/dewpointTemperature")
|
||||||
|
|
||||||
if len(sigt_td) != sigTNum :
|
if len(sigt_td) != numSigT:
|
||||||
print "inconstitent number of dewpoint temperature values found!"
|
print "inconstitent number of dewpoint temperature values found!"
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
#------------------------------------
|
|
||||||
# Print the values
|
# Print the values
|
||||||
# -----------------------------------
|
|
||||||
|
|
||||||
print "lev pres geo t td"
|
print "lev pres geo t td"
|
||||||
print "-------------------------------"
|
print "-------------------------------"
|
||||||
|
|
||||||
for i in xrange(sigTNum):
|
for i in xrange(numSigT):
|
||||||
print "%3d %6.0f %6.0f %.1f %.1f" % (i+1,sigt_pres[i],sigt_geo[i],sigt_t[i],sigt_td[i])
|
print "%3d %6.0f %6.0f %.1f %.1f" % (i+1,sigt_pres[i],sigt_geo[i],sigt_t[i],sigt_td[i])
|
||||||
|
|
||||||
cnt+=1
|
cnt+=1
|
||||||
|
|
Loading…
Reference in New Issue