mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-21 03:13:42 +08:00
36102e3c32
re: Issue https://github.com/Unidata/netcdf-c/issues/2190 The primary purpose of this PR is to improve the utf8 support for windows. This is persuant to a change in Windows that supports utf8 natively (almost). The almost means that it is still utf16 internally and the set of characters representable by utf8 is larger than those representable by utf16. This leaves open the question in the Issue about handling the Windows 1252 character set. This required the following changes: 1. Test the Windows build and major version in order to see if native utf8 is supported. 2. If native utf8 is supported, Modify dpathmgr.c to call the 8-bit version of the windows fopen() and open() functions. 3. In support of this, programs that use XGetOpt (Windows versions) need to get the command line as utf8 and then parse to arc+argv as utf8. This requires using a homegrown command line parser named XCommandLineToArgvA. 4. Add a utility program called "acpget" that prints out the current Windows code page and locale. Additionally, some technical debt was cleaned up as follows: 1. Unify all the places which attempt to read all or a part of a file into the dutil.c#NC_readfile code. 2. Similary unify all the code that creates temp files into dutil.c#NC_mktmp code. 3. Convert almost all remaining calls to fopen() and open() to NCfopen() and NCopen3(). This is to ensure that path management is used consistently. This touches a number of files. 4. extern->EXTERNL as needed to get it to work under Windows.
83 lines
2.2 KiB
C
83 lines
2.2 KiB
C
/* This is part of the netCDF package.
|
|
Copyright 2018 University Corporation for Atmospheric Research/Unidata
|
|
See COPYRIGHT file for conditions of use.
|
|
|
|
Test memory use of a netCDF-4 file with unlimited dimensions.
|
|
Ed Hartnett
|
|
*/
|
|
|
|
#include <config.h>
|
|
#include <stdio.h>
|
|
#include <nc_tests.h>
|
|
#include <err_macros.h>
|
|
#include "netcdf.h"
|
|
#include <hdf5.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
#include <sys/time.h> /* Extra high precision time info. */
|
|
#include <string.h>
|
|
|
|
#define NDIMS 1
|
|
#define FILE_NAME "tst_mem.nc"
|
|
#define NUM_TRIES 20000
|
|
#define TIME_NAME "time"
|
|
#define SFC_TEMP_NAME "sfc_temp"
|
|
|
|
void
|
|
get_mem_used2(int *mem_used)
|
|
{
|
|
char buf[30];
|
|
FILE *pf;
|
|
|
|
snprintf(buf, 30, "/proc/%u/statm", (unsigned)getpid());
|
|
pf = NCfopen(buf, "r");
|
|
if (pf) {
|
|
unsigned size; /* total program size */
|
|
unsigned resident;/* resident set size */
|
|
unsigned share;/* shared pages */
|
|
unsigned text;/* text (code) */
|
|
unsigned lib;/* library */
|
|
unsigned data;/* data/stack */
|
|
/*unsigned dt; dirty pages (unused in Linux 2.6)*/
|
|
fscanf(pf, "%u %u %u %u %u %u", &size, &resident, &share,
|
|
&text, &lib, &data);
|
|
*mem_used = data;
|
|
}
|
|
else
|
|
*mem_used = -1;
|
|
fclose(pf);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
int ncid, sfc_tempid;
|
|
float data;
|
|
int dimid;
|
|
size_t l_index[NDIMS] = {10000};
|
|
int mem_used, mem_used1;
|
|
int i;
|
|
|
|
printf("\n*** Testing netcdf-4 memory use with unlimited dimensions.\n");
|
|
printf("*** testing with user-contributed code...");
|
|
|
|
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
|
if (nc_def_dim(ncid, TIME_NAME, NC_UNLIMITED, &dimid)) ERR;
|
|
if (nc_def_var(ncid, SFC_TEMP_NAME, NC_FLOAT, NDIMS, &dimid, &sfc_tempid)) ERR;
|
|
|
|
/* Write data each 100ms*/
|
|
get_mem_used2(&mem_used);
|
|
for (i = 0; i < NUM_TRIES; i++)
|
|
{
|
|
data = 25.5 + l_index[0];
|
|
if (nc_put_var1_float(ncid, sfc_tempid, l_index, (const float*) &data)) ERR;
|
|
l_index[0]++;
|
|
get_mem_used2(&mem_used1);
|
|
if (!(i%100) && mem_used1 - mem_used)
|
|
printf("delta %d bytes of memory for try %d\n", mem_used1 - mem_used, i);
|
|
}
|
|
|
|
if (nc_close(ncid)) ERR;
|
|
SUMMARIZE_ERR;
|
|
FINAL_RESULTS;
|
|
}
|