2011-03-22 00:00:55 +08:00
|
|
|
/* This is part of the netCDF package.
|
|
|
|
Copyright 2005 University Corporation for Atmospheric Research/Unidata
|
|
|
|
See COPYRIGHT file for conditions of use.
|
|
|
|
|
2016-10-22 01:17:39 +08:00
|
|
|
Test internal netcdf-4 file code.
|
2011-03-22 00:00:55 +08:00
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <nc_tests.h>
|
2016-10-22 01:17:39 +08:00
|
|
|
#include <err_macros.h>
|
2011-03-22 00:00:55 +08:00
|
|
|
#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;
|
2016-10-22 01:17:39 +08:00
|
|
|
|
2011-03-22 00:00:55 +08:00
|
|
|
snprintf(buf, 30, "/proc/%u/statm", (unsigned)getpid());
|
|
|
|
pf = fopen(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)*/
|
2016-10-22 01:17:39 +08:00
|
|
|
fscanf(pf, "%u %u %u %u %u %u", &size, &resident, &share,
|
2011-03-22 00:00:55 +08:00
|
|
|
&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...");
|
2016-10-22 01:17:39 +08:00
|
|
|
|
2011-03-22 00:00:55 +08:00
|
|
|
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);
|
2016-10-22 01:17:39 +08:00
|
|
|
for (i = 0; i < NUM_TRIES; i++)
|
2011-03-22 00:00:55 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|