Dead code removal

This commit is contained in:
Shahram Najm 2023-06-24 13:32:21 +01:00
parent f7c5c47e94
commit 546f1d8cf3
4 changed files with 165 additions and 179 deletions

View File

@ -10,7 +10,6 @@
/***************************************************************************
* Enrico Fucile - 19.06.2007 *
* *
***************************************************************************/
#include "grib_bits_any_endian_simple.h"
@ -84,7 +83,7 @@ int grib_decode_long_array(const unsigned char* p, long* bitp, long bitsPerValue
// unsigned long lvalue = 0;
// double x;
//#if 0
//#if OLD_REF_CODE
// [> slow reference code <]
// int j=0;
// for(i=0;i < n_vals;i++) {

View File

@ -191,34 +191,31 @@ static void binary_search_gaussian_latitudes(const double array[], const unsigne
*j = -1; /* Not found */
}
#if 0
static void binary_search_old(const double xx[], const unsigned long n, double x, long* j)
{
/*This routine works only on descending ordered arrays*/
unsigned long ju, jm, jl;
jl = 0;
ju = n;
if (fabs(x - xx[0]) < EPSILON) {
*j = 0;
return;
}
if (fabs(x - xx[n]) < EPSILON) {
*j = n;
return;
}
while (ju - jl > 1) {
jm = (ju + jl) >> 1;
if (fabs(x - xx[jm]) < EPSILON) {
/* found something close enough. We're done */
*j = jm;
return;
}
if (x < xx[jm])
jl = jm;
else
ju = jm;
}
*j = jl;
}
#endif
// static void binary_search_old(const double xx[], const unsigned long n, double x, long* j)
// {
// /*This routine works only on descending ordered arrays*/
// unsigned long ju, jm, jl;
// jl = 0;
// ju = n;
// if (fabs(x - xx[0]) < EPSILON) {
// *j = 0;
// return;
// }
// if (fabs(x - xx[n]) < EPSILON) {
// *j = n;
// return;
// }
// while (ju - jl > 1) {
// jm = (ju + jl) >> 1;
// if (fabs(x - xx[jm]) < EPSILON) {
// /* found something close enough. We're done */
// *j = jm;
// return;
// }
// if (x < xx[jm])
// jl = jm;
// else
// ju = jm;
// }
// *j = jl;
// }

View File

@ -208,26 +208,20 @@ static void* fast_realloc(void* p, size_t s, mempool* pool)
return q;
}
#if 0
/*
void fast_memory_info(const char *title,mempool *pool)
{
void fast_memory_info(const char *title,mempool *pool) {
memblk *m = (memblk*)pool->priv;
int count = 0;
int size = 0;
while(m)
{
count++;
size += m->size;
m = m->next;
while(m) {
count++;
size += m->size;
m = m->next;
}
marslog(LOG_INFO,"%s : %sbytes %d blocks",
title,
bytename(size),count);
marslog(LOG_INFO,"%s : %sbytes %d blocks", title, bytename(size),count);
}
void memory_info()
{
void memory_info() {
memblk *r = reserve;
long size = 0;
while(r)
@ -237,13 +231,11 @@ static void* fast_realloc(void* p, size_t s, mempool* pool)
size += r->size;
r = r->next;
}
marslog(LOG_INFO,"Total large : %sbytes",bytename(size));
fast_memory_info("Transient memory",transient_mem);
fast_memory_info("Permanent memory",permanent_mem);
}
*/
#endif
void* grib_transient_malloc(const grib_context* c, size_t s)
{

View File

@ -158,15 +158,15 @@ int grib_recompose_name(grib_handle* h, grib_accessor* observer, const char* una
else if (uname[i] == '[')
mode = 0;
else {
#if 0
int llen=strlen(fname); /* The strlen cost is too high */
fname[llen]=uname[i];
fname[llen+1]='\0';
#else
/* Performance: faster to avoid call to strlen. Append to end */
// Old way: Slow; The strlen cost is too high
//int llen=strlen(fname);
//fname[llen]=uname[i];
//fname[llen+1]='\0';
// Faster to avoid call to strlen. Append to end
*ptrEnd_fname++ = uname[i];
*ptrEnd_fname = '\0';
#endif
type = GRIB_TYPE_STRING;
}
i++;
@ -175,131 +175,129 @@ int grib_recompose_name(grib_handle* h, grib_accessor* observer, const char* una
return GRIB_SUCCESS;
}
#if 0
int grib_accessor_print(grib_accessor* a, const char* name, int type, const char* format,
const char* separator, int maxcols, int* newline, FILE* out)
{
size_t size = 0;
char* sval = NULL;
char* p = NULL;
double* dval = 0;
long* lval = 0;
char sbuf[1024] = {0,};
size_t replen = 0;
int ret = 0;
char* myformat = NULL;
char* myseparator = NULL;
char double_format[] = "%.12g"; /* default format for printing double keys */
char long_format[] = "%ld"; /* default format for printing integer keys */
char default_separator[] = " ";
grib_handle* h = grib_handle_of_accessor(a);
// int grib_accessor_print(grib_accessor* a, const char* name, int type, const char* format,
// const char* separator, int maxcols, int* newline, FILE* out)
// {
// size_t size = 0;
// char* sval = NULL;
// char* p = NULL;
// double* dval = 0;
// long* lval = 0;
// char sbuf[1024] = {0,};
// size_t replen = 0;
// int ret = 0;
// char* myformat = NULL;
// char* myseparator = NULL;
// char double_format[] = "%.12g"; /* default format for printing double keys */
// char long_format[] = "%ld"; /* default format for printing integer keys */
// char default_separator[] = " ";
// grib_handle* h = grib_handle_of_accessor(a);
if (type == -1)
type = grib_accessor_get_native_type(a);
switch (type) {
case GRIB_TYPE_STRING:
replen = sizeof(sbuf) / sizeof(*sbuf);
ret = grib_unpack_string(a, sbuf, &replen);
fprintf(out, "%s", sbuf);
break;
case GRIB_TYPE_DOUBLE:
myformat = format ? (char*)format : double_format;
myseparator = separator ? (char*)separator : default_separator;
if (name[0] == '/' || name[0] == '#') {
long count;
ret = grib_value_count(a, &count);
size = count;
}
else {
ret = ecc__grib_get_size(h, a, &size);
}
if (ret) return ret;
dval = (double*)grib_context_malloc_clear(h->context, sizeof(double) * size);
if (name[0] == '/' || name[0] == '#') {
replen = size;
ret = grib_unpack_double(a, dval, &replen);
}
else {
replen = 0;
ret = ecc__grib_get_double_array_internal(h, a, dval, size, &replen);
}
if (replen == 1)
fprintf(out, myformat, dval[0]);
else {
int i = 0;
int cols = 0;
for (i = 0; i < replen; i++) {
*newline = 1;
fprintf(out, myformat, dval[i]);
if (i < replen - 1)
fprintf(out, "%s", myseparator);
cols++;
if (cols >= maxcols) {
fprintf(out, "\n");
*newline = 1;
cols = 0;
}
}
}
grib_context_free(h->context, dval);
break;
case GRIB_TYPE_LONG:
myformat = format ? (char*)format : long_format;
myseparator = separator ? (char*)separator : default_separator;
if (name[0] == '/' || name[0] == '#') {
long count;
ret = grib_value_count(a, &count);
size = count;
}
else {
ret = ecc__grib_get_size(h, a, &size);
}
if (ret) return ret;
lval = (long*)grib_context_malloc_clear(h->context, sizeof(long) * size);
if (name[0] == '/' || name[0] == '#') {
replen = size;
ret = grib_unpack_long(a, lval, &replen);
}
else {
replen = 0;
ret = ecc__grib_get_long_array_internal(h, a, lval, size, &replen);
}
if (replen == 1)
fprintf(out, myformat, lval[0]);
else {
int i = 0;
int cols = 0;
for (i = 0; i < replen; i++) {
*newline = 1;
fprintf(out, myformat, lval[i]);
if (i < replen - 1)
fprintf(out, "%s", myseparator);
cols++;
if (cols >= maxcols) {
fprintf(out, "\n");
*newline = 1;
cols = 0;
}
}
}
grib_context_free(h->context, lval);
break;
case GRIB_TYPE_BYTES:
replen = a->length;
sval = (char*)grib_context_malloc(h->context, replen * sizeof(char));
ret = grib_unpack_string(a, sval, &replen);
p = sval;
while ((replen--) > 0)
fprintf(out, "%c", *(p++));
grib_context_free(h->context, sval);
*newline = 0;
break;
default:
grib_context_log(h->context, GRIB_LOG_WARNING, "grib_accessor_print: Problem to print \"%s\", invalid type %d", a->name, type);
}
return ret;
}
#endif
// if (type == -1)
// type = grib_accessor_get_native_type(a);
// switch (type) {
// case GRIB_TYPE_STRING:
// replen = sizeof(sbuf) / sizeof(*sbuf);
// ret = grib_unpack_string(a, sbuf, &replen);
// fprintf(out, "%s", sbuf);
// break;
// case GRIB_TYPE_DOUBLE:
// myformat = format ? (char*)format : double_format;
// myseparator = separator ? (char*)separator : default_separator;
// if (name[0] == '/' || name[0] == '#') {
// long count;
// ret = grib_value_count(a, &count);
// size = count;
// }
// else {
// ret = ecc__grib_get_size(h, a, &size);
// }
// if (ret) return ret;
// dval = (double*)grib_context_malloc_clear(h->context, sizeof(double) * size);
// if (name[0] == '/' || name[0] == '#') {
// replen = size;
// ret = grib_unpack_double(a, dval, &replen);
// }
// else {
// replen = 0;
// ret = ecc__grib_get_double_array_internal(h, a, dval, size, &replen);
// }
// if (replen == 1)
// fprintf(out, myformat, dval[0]);
// else {
// int i = 0;
// int cols = 0;
// for (i = 0; i < replen; i++) {
// *newline = 1;
// fprintf(out, myformat, dval[i]);
// if (i < replen - 1)
// fprintf(out, "%s", myseparator);
// cols++;
// if (cols >= maxcols) {
// fprintf(out, "\n");
// *newline = 1;
// cols = 0;
// }
// }
// }
// grib_context_free(h->context, dval);
// break;
// case GRIB_TYPE_LONG:
// myformat = format ? (char*)format : long_format;
// myseparator = separator ? (char*)separator : default_separator;
// if (name[0] == '/' || name[0] == '#') {
// long count;
// ret = grib_value_count(a, &count);
// size = count;
// }
// else {
// ret = ecc__grib_get_size(h, a, &size);
// }
// if (ret) return ret;
// lval = (long*)grib_context_malloc_clear(h->context, sizeof(long) * size);
// if (name[0] == '/' || name[0] == '#') {
// replen = size;
// ret = grib_unpack_long(a, lval, &replen);
// }
// else {
// replen = 0;
// ret = ecc__grib_get_long_array_internal(h, a, lval, size, &replen);
// }
// if (replen == 1)
// fprintf(out, myformat, lval[0]);
// else {
// int i = 0;
// int cols = 0;
// for (i = 0; i < replen; i++) {
// *newline = 1;
// fprintf(out, myformat, lval[i]);
// if (i < replen - 1)
// fprintf(out, "%s", myseparator);
// cols++;
// if (cols >= maxcols) {
// fprintf(out, "\n");
// *newline = 1;
// cols = 0;
// }
// }
// }
// grib_context_free(h->context, lval);
// break;
// case GRIB_TYPE_BYTES:
// replen = a->length;
// sval = (char*)grib_context_malloc(h->context, replen * sizeof(char));
// ret = grib_unpack_string(a, sval, &replen);
// p = sval;
// while ((replen--) > 0)
// fprintf(out, "%c", *(p++));
// grib_context_free(h->context, sval);
// *newline = 0;
// break;
// default:
// grib_context_log(h->context, GRIB_LOG_WARNING, "grib_accessor_print: Problem to print \"%s\", invalid type %d", a->name, type);
// }
// return ret;
// }
int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const char* name,
int type, const char* format, const char* separator, int maxcols, int* newline, FILE* out)