File: vpointer-ex2.nco

package info (click to toggle)
nco 5.3.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 38,260 kB
  • sloc: ansic: 84,963; cpp: 28,654; sh: 14,071; perl: 5,996; makefile: 2,009; lex: 1,009; python: 127; csh: 40
file content (91 lines) | stat: -rw-r--r-- 1,795 bytes parent folder | download | duplicates (7)
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

// Produce a list of all vars in input
// each element of att list  is of type NC_STRING
// nb get_var_in() can take a single argument that can be a var name or regular expression
// lists are  of type NC_STRING and can are in essence ragged arrays
@all=get_vars_in();

*sz=@all.size();
*idx=0;


// sort vars into three buckets     
// DOUBLE, FLOAT, INT
for(idx=0;idx<sz;idx++)
{
  // remember @var_nm is of type NC_STRING
  @var_nm=@all(idx);
  ltype=*@var_nm.type();

  // push is quite clever if it is called with a "&" (reference) att
  // and that att doesnt exist then it is created on the fly
  if(ltype==NC_DOUBLE)
   push(&@dv, @var_nm);
  else if(ltype==NC_FLOAT)
     push(&@fv, @var_nm);     
  else if(ltype==NC_INT)
     push(&@iv, @var_nm);

}



// change missing values
sz=@dv.size();

print("starting doubles\n");

for(idx=0;idx<sz;idx++)
{
  @var_nm=@dv(idx);

  if( *@var_nm.ndims()>0)
  { 
    *@var_nm=*@var_nm;  
    *@var_nm.change_miss(-666.0);
  }
}

print("starting floats\n");

// average floats
sz=@fv.size();

for(idx=0;idx<sz;idx++)
{
  // we wish to append "_avg" to the var_nm. Since we cant easily append to NC_STRING 
  // we convert the  NC_STRING to type NC_CHAR using sprint()
  // then we can easily append to the NC_CHAR using push() again
  @var_nm=sprint(@fv(idx)); 
  @var_nm_avg=push(@var_nm,"_avg");
  
  if(*@var_nm.ndims() >0)
     *@var_nm_avg=*@var_nm.avg();  

}


// permute last two dims of ints
sz=@iv.size();

print("starting ints\n");

for(idx=0;idx<sz;idx++)
{
  @var_nm=@iv(idx);
          
  /// since we dont know the names of the dims -we can use placeholder arguments
  if(*@var_nm.ndims() ==3)
    *@var_nm=*@var_nm.permute($0,$2,$1);    
  else if(*@var_nm.ndims() ==4)
    *@var_nm=*@var_nm.permute($0,$1,$3,$2);    



}