File: tst_ar5.c

package info (click to toggle)
netcdf 1%3A4.4.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 96,828 kB
  • ctags: 15,369
  • sloc: ansic: 163,650; sh: 9,294; yacc: 2,457; makefile: 1,208; lex: 1,161; xml: 173; f90: 7; fortran: 6; awk: 2
file content (99 lines) | stat: -rw-r--r-- 3,358 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* This is part of the netCDF package.
   Copyright 2005 University Corporation for Atmospheric Research/Unidata
   See COPYRIGHT file for conditions of use.

   This program does some benchmarking of netCDF files for the AR-5
   data.
*/

#include <nc_tests.h>
#include "err_macros.h"
#include "netcdf.h"
#include <unistd.h>
#include <time.h>
#include <sys/time.h> /* Extra high precision time info. */
#include <../ncdump/nciter.h>

#define MILLION 1000000
#define MAX_LEN 30
#define TMP_FILE_NAME "tst_files2_tmp.out"

/* This function uses the ps command to find the amount of memory in
use by the process. From the ps man page:

size SZ approximate amount of swap space that would be required if
        the process were to dirty all writable pages and then be
        swapped out. This number is very rough!
*/
void
get_mem_used1(int *mem_used)
{
   char cmd[NC_MAX_NAME + 1];
   char blob[MAX_LEN + 1] = "";
   FILE *fp;
   int num_char;

   /* Run the ps command for this process, putting output (one number)
    * into file TMP_FILE_NAME. */
   sprintf(cmd, "ps -o size= %d > %s", getpid(), TMP_FILE_NAME);
   system(cmd);

   /* Read the results and delete temp file. */
   if (!(fp = fopen(TMP_FILE_NAME, "r"))) exit;
   num_char = fread(blob, MAX_LEN, 1, fp);
   sscanf(blob, "%d", mem_used);
   fclose(fp);
   unlink(TMP_FILE_NAME);
}

int
main(int argc, char **argv)
{

#define BUFSIZE 1000000 /* access data in megabyte sized pieces */
#define THETAU_FILE "/machine/downloads/AR5_sample_data/thetao_O1.SRESA1B_2.CCSM.ocnm.2000-01_cat_2099-12.nc"
#define NDIMS_DATA 4
   printf("\n*** Running some AR-5 benchmarks.\n");
   printf("*** testing various chunksizes for thetau file...\n");
   {
      int ncid, ncid_out;
      /*char var_buf[BUFSIZE];*/  /* buffer for variable data */
/*      nciter_t iter; */     /* opaque structure for iteration status */
/*      size_t start[NDIMS_DATA];
	size_t count[NDIMS_DATA];*/
      /*float *data = (float *)var_buf; */
      char file_out[NC_MAX_NAME + 1];
      /*int ndims, nvars, natts, unlimdimid;*/
      size_t cs[NDIMS_DATA] = {120, 4, 40, 32};

/*       /\* Open input. *\/ */
/*       if (nc_open(THETAU_FILE, NC_NOWRITE, &ncid)) ERR; */

/*       /\* Create output file. *\/ */
/*       sprintf(file_out, "thetau_%d_%d_%d_%d.nc", (int)cs[0],  */
/* 	      (int)cs[1], (int)cs[2], (int)cs[3]); */
/*       if (nc_create(file_out, NC_NOWRITE, &ncid_out)) ERR; */

/*       /\* Copy the easy ones. *\/ */
/* /\*      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; */
/* 	if (ndims != 5 || nvars != 9 || natts != 8 || unlimdimid != 0) ERR;*\/ */

/* /\*       /\\* Copy the main data payload with Russ's new nciters. *\\/ *\/ */
/* /\*       varid = 8; *\/ */
/* /\*       if (nc_get_iter(ncid, varid, BUFSIZE, &iter)) ERR; *\/ */
/* /\*       while((nvals = nc_next_iter(&iter, start, count)) > 0)  *\/ */
/* /\*       { *\/ */
/* /\* 	 /\\* read in a block of data *\\/ *\/ */
/* /\* 	 if (nc_get_vara_double(ncid, varid, start, count, data)) ERR; *\/ */

/* /\* 	 /\\* now write the changed data back out *\\/ *\/ */
/* /\* 	 if (nc_out_vara_double(ncid, varid, start, count, data)) ERR; *\/ */
/* /\*       } *\/ */
/* /\*       if (nvals < 0) ERR; *\/ */

/*       if (nc_close(ncid)) ERR; */
/*       if (nc_close(ncid_out)) ERR; */
   }
   SUMMARIZE_ERR;
   FINAL_RESULTS;
}