Commit 20abcc89 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Create loop from repetitive code.

parent 94fdbca9
...@@ -2135,11 +2135,13 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -2135,11 +2135,13 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
size_t len = sizeof (mesg) -1; size_t len = sizeof (mesg) -1;
GRIB_CHECK(my_grib_set_string(gh, "gridType", mesg, &len), 0); GRIB_CHECK(my_grib_set_string(gh, "gridType", mesg, &len), 0);
} }
int trunc = gridInqTrunc(gridID); {
GRIB_CHECK(my_grib_set_long(gh, "J", trunc), 0); int trunc = gridInqTrunc(gridID);
GRIB_CHECK(my_grib_set_long(gh, "K", trunc), 0); enum { numTruncAtt = 3 };
GRIB_CHECK(my_grib_set_long(gh, "M", trunc), 0); static const char truncAttNames[numTruncAtt][2] = { "J", "K", "M" };
for (size_t i = 0; i < numTruncAtt; ++i)
GRIB_CHECK(my_grib_set_long(gh, truncAttNames[i], trunc), 0);
}
// GRIB_CHECK(my_grib_set_long(gh, "numberOfDataPoints", gridsize), 0); // GRIB_CHECK(my_grib_set_long(gh, "numberOfDataPoints", gridsize), 0);
/* /*
if ( lieee ) if ( lieee )
...@@ -2156,10 +2158,11 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -2156,10 +2158,11 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
static const char mesg[] = "spectral_complex"; static const char mesg[] = "spectral_complex";
size_t len = sizeof (mesg) -1; size_t len = sizeof (mesg) -1;
GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0); GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
enum { numTruncAtt = 3 };
GRIB_CHECK(my_grib_set_long(gh, "JS", 20), 0); static const char truncAttNames[numTruncAtt][3]
GRIB_CHECK(my_grib_set_long(gh, "KS", 20), 0); = { "JS", "KS", "MS" };
GRIB_CHECK(my_grib_set_long(gh, "MS", 20), 0); for (size_t i = 0; i < numTruncAtt; ++i)
GRIB_CHECK(my_grib_set_long(gh, truncAttNames[i], 20), 0);
} }
else else
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment