netcdf-c/ncdump/nc4print.c
Dennis Heimbigner 90fd1406bc Make use of clock_gettime be conditional.
Re: GH Issue https://github.com/Unidata/netcdf-c/issues/1900

Apparently the clock_gettime() function is not always available.
It is used in unit_test/tst_exhash.c and unit_test/tst_xcache.c.

To solve this, a number of things were changed:
* Move the timing code to a new file unit_tests/timer_utils.[ch]
* Modify the timing code to choose one of several timing methods
depending on availability. The prioritized order is as follows:
    1. If Windows, use the QueryPerformanceCounter mechanism else
    2. Use clock_gettime if available else
    3. Use gettimeofday if available else
    4. Use getrusage if available

Note that the resolution of 3 and 4 is less than 1 or 2.

Misc. Other Changes:
* Move the test in CMakeLists.txt that disables unit tests for WIN32 to unit_test/CMakeLists.txt since some unit tests actually work under Visual Studio.
* Fix some of the unit tests to work under visual studio
* Fix problem with using remove() in zmap_nzf.c
* Remove some warning about use of EXTERNL
2020-12-06 18:19:53 -07:00

54 lines
1.2 KiB
C

/*********************************************************************
* Copyright 2018, UCAR/Unidata
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*********************************************************************/
/**
This provides a simple netcdf-4 metadata -> xml printer.
Primarily for use in debugging, but could be adapted to
create other tools.
*/
/**************************************************/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include "netcdf.h"
#include "ncbytes.h"
extern int NC4print(NCbytes* buf, int ncid);
int
main(int argc, char** argv)
{
int i;
int ret = NC_NOERR;
if(argc == 1) {
fprintf(stderr,"usage: nc4printer <file> <file>...\n");
exit(1);
}
for(i=1;i<argc;i++) {
int ncid;
char* filename;
NCbytes* buf;
filename = argv[i];
buf = ncbytesnew();
if((ret = nc_open(filename,NC_NETCDF4,&ncid))) goto fail;
ret = NC4print(buf,ncid);
ncbytesnull(buf);
fprintf(stderr,"========== %s ==========\n",filename);
fprintf(stderr,"%s\n",ncbytescontents(buf));
ncbytesfree(buf);
}
exit(0);
fail:
fprintf(stderr,"***Fail: (%d) %s\n",ret,nc_strerror(ret));
exit(1);
}