ncvarinfo.c
1.58 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netcdf.h>
/**************************
Function prototypes
**************************/
void handle_netcdf_error (int);
main(int argc, char **argv)
{
int ncID, varID, ndims, dimids[NC_MAX_DIMS];
nc_type type;
size_t len, nrecs;
char varname[NC_MAX_NAME];
int i, ii, j, status;
if (argc <= 2) {
printf("Incorrect number of arguments\n");
exit(0);
}
/* open nc file to write */
if((status = nc_open(argv[1],NC_WRITE|NC_SHARE,&ncID)) != NC_NOERR){
printf("%d",status);
exit(0);
}
if ((status = nc_inq_varid(ncID, argv[2], &varID)) != NC_NOERR) {
printf("%d",status);
exit(0);
}
if ((status = nc_inq_vartype(ncID, varID, &type)) != NC_NOERR) {
printf("%d",status);
exit(0);
}
if ((status = nc_inq_varndims(ncID, varID, &ndims)) != NC_NOERR) {
printf("%d", status);
exit(0);
}
if ((status = nc_inq_vardimid(ncID, varID, dimids)) != NC_NOERR){
printf("%d", status);
exit(0);
}
printf("%d %d ", type, ndims);
for (i = 0; i < ndims; i++) {
status = nc_inq_dimlen(ncID, dimids[i], &len);
printf("%d ", len);
}
status = nc_close(ncID);
}
/*--------------------------------------------------------------------------
* Handles a netCDF error.
*--------------------------------------------------------------------------*/
void handle_netcdf_error(int status) {
fprintf(stderr, "%s\n", nc_strerror(status));
}