2018-08-23 22:21:55 +08:00
|
|
|
/* This is part of the netCDF package. Copyright 2005-2018 University
|
|
|
|
Corporation for Atmospheric Research/Unidata See COPYRIGHT file for
|
|
|
|
conditions of use.
|
2011-07-21 03:44:27 +08:00
|
|
|
|
2018-08-23 22:21:55 +08:00
|
|
|
This is a benchmarking program that depends on some KNMI files from
|
|
|
|
the Unidata ftp site. The files are opened and read, and
|
|
|
|
performance is timed.
|
2016-10-22 03:42:14 +08:00
|
|
|
|
2018-08-23 22:21:55 +08:00
|
|
|
Ed Hartnett
|
2011-07-21 03:44:27 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <nc_tests.h>
|
2016-10-22 03:42:14 +08:00
|
|
|
#include "err_macros.h"
|
2011-07-21 03:44:27 +08:00
|
|
|
#include <time.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define FILE_NAME_1 "MSGCPP_CWP_NC3.nc"
|
|
|
|
#define FILE_NAME_2 "MSGCPP_CWP_NC4.nc"
|
|
|
|
|
|
|
|
#define NDIMS3 3
|
|
|
|
#define DATA_VAR_NAME "pr"
|
|
|
|
#define NUM_CACHE_TRIES 1
|
|
|
|
#define LON_DIMID 0
|
|
|
|
#define LAT_DIMID 1
|
|
|
|
#define BNDS_DIMID 2
|
|
|
|
#define TIME_DIMID 3
|
|
|
|
#define LON_LEN 256
|
|
|
|
#define LAT_LEN 128
|
|
|
|
#define BNDS_LEN 2
|
|
|
|
#define TIME_LEN 1560
|
|
|
|
#define NUM_TS 1
|
|
|
|
|
2018-08-23 22:21:55 +08:00
|
|
|
/* Prototype from tst_utils.c. */
|
|
|
|
int nc4_timeval_subtract(struct timeval *result, struct timeval *x,
|
|
|
|
struct timeval *y);
|
|
|
|
|
2012-03-29 00:19:16 +08:00
|
|
|
extern const char* nc_strerror(int ncerr);
|
|
|
|
static int
|
|
|
|
complain(int stat)
|
|
|
|
{
|
|
|
|
if(stat) {
|
|
|
|
fprintf(stderr,"%s\n",nc_strerror(stat));
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2016-10-22 03:42:14 +08:00
|
|
|
static int
|
2011-07-21 03:44:27 +08:00
|
|
|
read_file(char *filename)
|
|
|
|
{
|
2011-10-05 21:43:20 +08:00
|
|
|
#define CWP "cwp"
|
|
|
|
#define XLEN 3712
|
|
|
|
#define YLEN 3712
|
|
|
|
|
|
|
|
int ncid, varid;
|
2011-07-21 03:44:27 +08:00
|
|
|
struct timeval start_time, end_time, diff_time;
|
2011-10-05 21:43:20 +08:00
|
|
|
short *data;
|
2011-07-21 03:44:27 +08:00
|
|
|
int time_us;
|
|
|
|
|
|
|
|
printf("**** reading file %s\n", filename);
|
|
|
|
if (gettimeofday(&start_time, NULL)) ERR_RET;
|
2011-11-14 12:20:19 +08:00
|
|
|
if(complain(nc_open(filename, NC_NOWRITE, &ncid))) ERR_RET;
|
2011-07-21 03:44:27 +08:00
|
|
|
if (gettimeofday(&end_time, NULL)) ERR_RET;
|
|
|
|
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR_RET;
|
|
|
|
time_us = (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec;
|
|
|
|
printf("File open time (us): %d\n", (int)time_us);
|
|
|
|
|
2011-10-05 21:43:20 +08:00
|
|
|
if (!(data = malloc(sizeof(short) * XLEN * YLEN))) ERR;
|
|
|
|
if (gettimeofday(&start_time, NULL)) ERR_RET;
|
|
|
|
if (nc_inq_varid(ncid, CWP, &varid)) ERR;
|
|
|
|
if (nc_get_var_short(ncid, varid, data)) ERR;
|
|
|
|
if (gettimeofday(&end_time, NULL)) ERR_RET;
|
|
|
|
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR_RET;
|
|
|
|
time_us = (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec;
|
|
|
|
printf("Data read time (us): %d\n", (int)time_us);
|
|
|
|
free(data);
|
|
|
|
|
2011-07-21 03:44:27 +08:00
|
|
|
if (nc_close(ncid))
|
|
|
|
ERR_RET;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-22 03:42:14 +08:00
|
|
|
int
|
2011-07-21 03:44:27 +08:00
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
printf("\n*** Testing netcdf-4 vs. netcdf-3 performance.\n");
|
2016-10-22 03:42:14 +08:00
|
|
|
if (complain(read_file(FILE_NAME_1))) ERR;
|
|
|
|
if (complain(read_file(FILE_NAME_2))) ERR;
|
2011-07-21 03:44:27 +08:00
|
|
|
SUMMARIZE_ERR;
|
|
|
|
FINAL_RESULTS;
|
|
|
|
}
|