source: IO_handling/trunk/ppio/cell-patch @ 285

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/IO_handling/trunk/ppio/cell-patch@285
Revision 285, 4.0 KB checked in by jkettleb, 15 years ago (diff)

Adds the correct cellmethods attributes to variables depending on their lbproc
in the pp header

Adds the correct cellmethods attributes to variables depending on their lbproc
in the pp header

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1diff -Naur cdat-4.0b3/libcdms/include/cdunifpp/cdunifpp.h cdat-4.0b3-cell/libcdms/include/cdunifpp/cdunifpp.h
2--- cdat-4.0b3/libcdms/include/cdunifpp/cdunifpp.h      2004-08-25 14:31:00.884053368 +0100
3+++ cdat-4.0b3-cell/libcdms/include/cdunifpp/cdunifpp.h 2004-08-25 14:32:57.488326824 +0100
4@@ -687,10 +687,15 @@
5 int pp_get_var_stash_item(const PPhdr *);
6 int pp_get_var_packing(const PPhdr *);
7 int pp_get_var_compression(const PPhdr *);
8+int pp_get_var_processing(const PPhdr *hdr);
9 int pp_get_var_name(int varid, const char *, CuVar *) ;
10 void *pp_get_var_fill_value(const PPhdr *);
11 int pp_var_is_land_mask(const PPhdr *);
12 CuType pp_get_var_type(const PPhdr *);
13+int pp_var_is_time_mean(const PPhdr *hdr);
14+int pp_var_is_time_min(const PPhdr *hdr);
15+int pp_var_is_time_max(const PPhdr *hdr);
16+int pp_var_is_zonal_mean(const PPhdr *hdr);
17 
18 /* in cdunifpp_debug.c: */
19 void pp_dump_header(const PPhdr *);
20diff -Naur cdat-4.0b3/libcdms/src/cdunif/cdunifpp/cdunifpp_process.c cdat-4.0b3-cell/libcdms/src/cdunif/cdunifpp/cdunifpp_process.c
21--- cdat-4.0b3/libcdms/src/cdunif/cdunifpp/cdunifpp_process.c   2004-08-25 14:31:00.931046224 +0100
22+++ cdat-4.0b3-cell/libcdms/src/cdunif/cdunifpp/cdunifpp_process.c      2004-08-25 14:34:19.738822848 +0100
23@@ -59,6 +59,9 @@
24   int ilev;
25   Freal lon_modulo, plev_scale;
26 
27+  int has_cellmethod;
28+  char tmpstring[MAX_ATT_LEN+1];
29+
30   /* ------------------------------------------------------ */ 
31   /* initialisation constants which matter */
32   ncvars = 0;
33@@ -753,15 +756,40 @@
34     }
35 
36     /* cell_methods att for time mean */
37-    if (pp_is_time_mean(fvar->taxis->type)) {
38+    /*
39+     *if (pp_is_time_mean(fvar->taxis->type)) {
40+     * snprintf(cellmethods,MAX_ATT_LEN,"%s: mean",cudims[fvar->taxis->dimid].name);
41+     * if(   pp_add_string_att(ppvar->atts,"cell_methods",cellmethods,heaplist)   !=0) goto err;
42+     *}
43+     */
44+
45+    has_cellmethod=0;
46+    strcpy(cellmethods,"");
47+    if (pp_var_is_time_mean(hdrp)) {  /* mean, min, max should be mutually exclusive */
48+      has_cellmethod=1;
49       snprintf(cellmethods,MAX_ATT_LEN,"%s: mean",cudims[fvar->taxis->dimid].name);
50+    }
51+    if (pp_var_is_time_max(hdrp)) {
52+      has_cellmethod=1;
53+      snprintf(cellmethods,MAX_ATT_LEN,"%s: maximum",cudims[fvar->taxis->dimid].name);
54+    }
55+    if (pp_var_is_time_min(hdrp)) {
56+      has_cellmethod=1;
57+      snprintf(cellmethods,MAX_ATT_LEN,"%s: minimum",cudims[fvar->taxis->dimid].name);
58+    }
59+    if (pp_var_is_zonal_mean(hdrp)) {
60+      has_cellmethod=1;
61+      snprintf(tmpstring,MAX_ATT_LEN," %s: mean",cudims[fvar->xaxis->dimid].name);
62+      strncat(cellmethods,tmpstring,MAX_ATT_LEN-strlen(cellmethods));  /* correct length? */
63+    }
64+    if (has_cellmethod) {
65       if(   pp_add_string_att(ppvar->atts,"cell_methods",cellmethods,heaplist)   !=0) goto err;
66     }
67 
68     /* FIXME(?): maybe do time difference analogously to time mean, but with different
69      * cell_methods attribute.  See also pp_taxis_to_values() in cdunifpp_axisvals.c
70      */
71-   
72+   
73     if(   pp_copy_and_free_atts(file,var,ppvar->atts,heaplist)   !=0) goto err;
74 
75     varid++;
76diff -Naur cdat-4.0b3/libcdms/src/cdunif/cdunifpp/cdunifpp_varinfo.c cdat-4.0b3-cell/libcdms/src/cdunif/cdunifpp/cdunifpp_varinfo.c
77--- cdat-4.0b3/libcdms/src/cdunif/cdunifpp/cdunifpp_varinfo.c   2004-08-25 14:31:00.980038776 +0100
78+++ cdat-4.0b3-cell/libcdms/src/cdunif/cdunifpp/cdunifpp_varinfo.c      2004-08-25 14:34:19.774817376 +0100
79@@ -118,6 +118,11 @@
80   return (hdr->LBPACK / 10) % 10;
81 }
82 
83+int pp_get_var_processing(const PPhdr *hdr)
84+{
85+  return hdr->LBPROC;
86+}
87+
88 /*-----------------------------------------------------------------*/
89 
90 int pp_get_var_name(int varid, const char *prefix, CuVar *cuvars) {
91@@ -219,4 +224,24 @@
92   return 0;
93 }
94 
95+int pp_var_is_time_mean(const PPhdr *hdr)
96+{
97+  return (hdr->LBPROC & 128);
98+}
99+
100+int pp_var_is_time_min(const PPhdr *hdr)
101+{
102+  return (hdr->LBPROC & 4096);
103+}
104+
105+int pp_var_is_time_max(const PPhdr *hdr)
106+{
107+  return (hdr->LBPROC & 8192);
108+}
109+
110+int pp_var_is_zonal_mean(const PPhdr *hdr)
111+{
112+  return (hdr->LBPROC & 64);
113+}
114+
115 #endif
Note: See TracBrowser for help on using the repository browser.