ECC-851: Refactoring: duplicated tigge 'scan' function

This commit is contained in:
Shahram Najm 2018-12-13 22:22:38 +00:00
parent bdbb473418
commit 338010d94c
3 changed files with 16 additions and 47 deletions

View File

@ -1,28 +1,35 @@
# tigge
# library
ecbuild_add_library(TARGET tigge_tools
TYPE STATIC
NOINSTALL
SOURCES tigge_tools.c tigge_tools.h)
# executables
ecbuild_add_executable(TARGET tigge_check
SOURCES tigge_check.c
INCLUDES ${ECCODES_EXTRA_INCLUDE_DIRS}
LIBS eccodes
LIBS eccodes tigge_tools
)
ecbuild_add_executable(TARGET tigge_name
SOURCES tigge_name.c
INCLUDES ${ECCODES_EXTRA_INCLUDE_DIRS}
CONDITION ECCODES_INSTALL_EXTRA_TOOLS
LIBS eccodes
LIBS eccodes tigge_tools
)
ecbuild_add_executable(TARGET tigge_accumulations
SOURCES tigge_accumulations.c
INCLUDES ${ECCODES_EXTRA_INCLUDE_DIRS}
CONDITION ECCODES_INSTALL_EXTRA_TOOLS
LIBS eccodes
LIBS eccodes tigge_tools
)
ecbuild_add_executable(TARGET tigge_split
SOURCES tigge_split.c
INCLUDES ${ECCODES_EXTRA_INCLUDE_DIRS}
CONDITION ECCODES_INSTALL_EXTRA_TOOLS
LIBS eccodes
LIBS eccodes tigge_tools
)

View File

@ -27,6 +27,7 @@
#include <sys/types.h>
#include <dirent.h>
#include <assert.h>
#include "tigge_tools.h"
#define CHECK(a) check(#a,a)
#define WARN(a) warn(#a,a)
@ -1308,7 +1309,7 @@ static void verify(grib_handle* h)
}
static void validate(const char* path)
void validate(const char* path)
{
FILE *f = fopen(path,"r");
grib_handle *h = 0;
@ -1357,26 +1358,6 @@ static void validate(const char* path)
}
}
static void scan(const char* name)
{
DIR *dir;
if((dir = opendir(name)) != NULL)
{
struct dirent* e;
char tmp[1024];
while( (e = readdir(dir)) != NULL)
{
if(e->d_name[0] == '.') continue;
sprintf(tmp,"%s/%s",name,e->d_name);
scan(tmp);
}
closedir(dir);
}
else
validate(name);
}
static void usage()
{
printf("tigge_check [options] grib_file grib_file ...\n");

View File

@ -26,6 +26,7 @@
#include <math.h>
#include <sys/types.h>
#include <dirent.h>
#include "tigge_tools.h"
/* #define CHECK(a) check(#a,a) */
#define NUMBER(a) (sizeof(a)/sizeof(a[0]))
@ -152,7 +153,7 @@ static void verify(grib_handle *h,const char* full,const char* base)
}
}
static void validate(const char* path)
void validate(const char* path)
{
FILE *f = fopen(path,"r");
grib_handle *h = 0;
@ -204,26 +205,6 @@ static void usage()
exit(1);
}
static void scan(const char* name)
{
DIR *dir;
if((dir = opendir(name)) != NULL)
{
struct dirent* e;
char tmp[1024];
while( (e = readdir(dir)) != NULL)
{
if(e->d_name[0] == '.') continue;
sprintf(tmp,"%s/%s",name,e->d_name);
scan(tmp);
}
closedir(dir);
}
else
validate(name);
}
int main(int argc, char** argv)
{
int i = 1;