Blame view

php/src/nctimeinfo.c 2.09 KB
16035364   Benjamin Renard   First commit
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
#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, timeID, dimids[NC_MAX_DIMS];
      size_t nrecs;
      double time_double[3], sampling, sampling_min = 100000;      
      int i, status, nvars;
      
      char varname[NC_MAX_NAME];
	
      size_t TimeStart = 0;
      size_t TimeCount = 3;  
      
      
        if (argc <= 1) {
            printf("Incorrect number of arguments\n"); 
   	    exit(0);
	}
	
	if((status = nc_open(argv[1],0,&ncID)) != NC_NOERR){
	    printf("%d",status);
	    exit(0);
	}
		
	if ((status = nc_inq_varid (ncID, "Time", &timeID)) != NC_NOERR) {
	      printf("%d",status);
	      exit(0);                
	} 
	
	if ((status = nc_inq_vardimid(ncID, timeID, dimids)) != NC_NOERR){
	      printf("%d", status);
	      exit(0); 
	}
	
	if ((status = nc_inq_dimlen(ncID,dimids[0], &nrecs)) != NC_NOERR){	 
	      printf("%d", status);
	      exit(0);  
	} 
	
	if ((status =  nc_get_vara_double(ncID, timeID, &TimeStart, &TimeCount,  time_double)) != NC_NOERR){
		printf("%d", status);
		exit(0);  
	}  
		 
	for (i = 0; i < 2; i++) {
	   sampling = time_double[i+1] - time_double[i];
af97ef56   Elena.Budnik   make C executable...
58
	   if (sampling < sampling_min && sampling > 0.0) sampling_min = sampling;	  
16035364   Benjamin Renard   First commit
59
60
61
62
63
64
65
66
67
68
69
70
71
	 }
	  
	 printf("%lf:", time_double[0]);        
	 
	 TimeStart = nrecs - 3;
	 if ((status =  nc_get_vara_double(ncID, timeID, &TimeStart, &TimeCount,  time_double)) != NC_NOERR){
		printf("%d", status);
		exit(0);  
	} 	
	printf("%lf#", time_double[2]);
	
	for (i = 0; i < 2; i++) {
	   sampling = time_double[i+1] - time_double[i];
af97ef56   Elena.Budnik   make C executable...
72
	   if (sampling < sampling_min && sampling > 0.0) sampling_min = sampling;	  
16035364   Benjamin Renard   First commit
73
74
75
76
77
78
79
80
81
82
83
84
85
	 }
	 
	printf("%lf", sampling_min);
 
	status = nc_close(ncID);
}
/*--------------------------------------------------------------------------
 *  Handles a netCDF error.
 *--------------------------------------------------------------------------*/

void handle_netcdf_error(int status) {
  fprintf(stderr, "%s\n", nc_strerror(status));  
}