File: nc_sync_child.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 (100 lines) | stat: -rw-r--r-- 1,972 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
100
#include <stdio.h>
#include <netcdf.h>
#include "nc_sync.h"

int
main()
{
    int	ncid;
    int	ncerr;
    int	everythingOK = 1;

    setbuf(stdout, NULL);	/* unbuffer stdout */

    /*
     * Open the netCDF file.
     */
    ncerr = nc_open("nc_sync.nc", 0, &ncid);
    if (ncerr != NC_NOERR)
    {
	fprintf(stderr, "nc_open() error: %s\n", nc_strerror(ncerr));
	everythingOK = 0;
    }
    else
    {
	double	var[DIM2][DIM1][DIM0];
	size_t	start[NDIM] = {0, 0, 0, 0};
	size_t	count[NDIM] = {1, DIM2, DIM1, DIM0};
	int	eofRead = 0;

	/*
	 * Loop over the unlimited dimension.
	 */
	while (everythingOK && !eofRead)
	{
	    int	i3;
	    int	ivar;
	    int	nitem;

	    /*
	     * Read the unlimited dimension index.
	     */
	    puts("CHILD: Getting notification");
	    fflush(stdout);
	    nitem = fread(&i3, sizeof(i3), 1, stdin);
	    if (nitem == 0)
	    {
		puts("CHILD: Read EOF");
		fflush(stdout);
		eofRead = 1;
	    }
	    else if (nitem != 1)
	    {
		perror("fread() error");
		everythingOK = 0;
	    }
	    else
	    {
		start[0] = i3;

		/*
		 * Synchronize the netCDF file.
		 */
		puts("CHILD: Calling nc_sync()");
		fflush(stdout);
		ncerr = nc_sync(ncid);
		if (ncerr != NC_NOERR)
		{
		    fprintf(
			stderr, "nc_sync() error: %s\n", nc_strerror(ncerr));
		    everythingOK = 0;
		}
		else
		{
		    printf("CHILD: Reading %d\n", i3);
		    fflush(stdout);

		    /*
		     * Loop over the variables.
		     */
		    for (ivar = 0; everythingOK && ivar < NVAR; ++ivar)
		    {
			ncerr =
			    nc_get_vara_double(
				ncid, ivar, start, count, (double*)var);
			if (ncerr != NC_NOERR)
			{
			    fprintf(
				stderr,
			    "nc_get_vara_double() error: %s: i3=%d, ivar=%d\n",
				nc_strerror(ncerr), i3, ivar);
			    everythingOK = 0;
			}
		    }
		}			/* netCDF file synchronized */
	    }				/* unlimited dimension index read */
	}				/* unlimited dimension loop */
    }					/* input netCDF file opened */

    return everythingOK ? 0 : 1;
}