File: tst_fillonlyz.c

package info (click to toggle)
netcdf-parallel 1%3A4.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 113,164 kB
  • sloc: ansic: 267,893; sh: 12,869; cpp: 5,822; yacc: 2,613; makefile: 1,813; lex: 1,216; xml: 173; awk: 2
file content (87 lines) | stat: -rw-r--r-- 1,748 bytes parent folder | download | duplicates (2)
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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "netcdf.h"
#include "nclist.h"

#include "zincludes.h"

#include "tst_utils.h"

#undef DEBUG

static void
nccheck(int ret, int lineno)
{
    if(ret == NC_NOERR) return;
    report(ret,lineno);
}

#define NCCHECK(err) nccheck(err,__LINE__)

int
main(int argc, char *argv[] )
{
    int   err, ncid, varid, dimid[1];
    size_t  dimlen[1];
    float   *fdat;
    int     *idat;
    const char* filename = NULL;
    const char* varname = "f";
    const char* dimname = "x";
    size_t i;

    NCCHECK(getoptions(&argc,&argv));
    filename = options->file;

    NCCHECK(err = nc_open(filename,NC_NETCDF4,&ncid));
    NCCHECK(err = nc_inq_varid(ncid, varname, &varid));
    NCCHECK(err = nc_inq_dimid(ncid, dimname, dimid));
    NCCHECK(err = nc_inq_dim(ncid, dimid[0], NULL, dimlen));

    /* Make room for both double and floating dat */
    fdat = (float  *)calloc(1,sizeof(float) * dimlen[0]);
    idat = (int  *)calloc(1,sizeof(int) * dimlen[0]);

    NCCHECK(err = nc_get_var_int(ncid, varid, idat));
    NCCHECK(err = nc_get_var_float(ncid, varid, fdat));

#ifdef DEBUG
    printf("int[0..%d]:",(int)dimlen[0]);
    for(i=0; i<dimlen[0]; i++ ) printf(" %i", idat[i]);
    printf("\n");

    printf("float[0..%d]:",(int)dimlen[0]);
    for(i=0; i<dimlen[0]; i++ ) printf(" %f", fdat[i]);
    printf("\n");
#endif

    /* Do the comparisons */
    for(i=0; i<dimlen[0]; i++ ) {
	if(fdat[i] != (float)(idat[i])) {
	    fprintf(stderr,"data mismatch [%d]: float=%f (float)int=%f int=%i\n",(int)i,fdat[i],(float)idat[i],idat[i]);
	    return 1;
	}
    }

    if(fdat) free(fdat);
    if(idat) free(idat);
    return 0;
}