functionsodb.sh 2.22 KB
Newer Older
saeed's avatar
m  
saeed committed
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
function getyear(){
    time_d=${1} 
    year=`echo ${time_d}|cut -d- -f1`
    echo ${year}
}

function getmon(){
    time_d=${1} 
    mon=`echo ${time_d}| cut -d- -f2`
    echo ${mon}
}

function getday(){
    time_d=${1} 
    day=`echo ${time_d}| cut -d- -f3`
    echo ${day}
}

function yearmonday(){
    time_d=${1} 
    year=`echo ${time_d}|cut -d- -f1`
    mon=`echo ${time_d}| cut -d- -f2`
    day=`echo ${time_d}| cut -d- -f3`
    echo ${year}${mon}${day}
}

saeed's avatar
m    
saeed committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

function getyear_1(){
    str=${1}
    echo ${str:0:4}
}

function getmonth_1(){
    str=${1}
    echo ${str:4:2}
}

function getday_1(){
    str=${1}
    echo ${str:6:2}
}

saeed's avatar
m  
saeed committed
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
92
93
94
95
function addbackslash(){
    str=${1}
    echo ${str/,/\\\/}
}

function output_name(){
    fin=${1}
    fout=${fin/".odb"/".txt"}
    echo ${fout}
}

function output_name_cycle(){
    fin=${1}
    cycle=${2}
    fout=${fin/".txt"/}
    fout_cycle=${fout}"_cycle""${cycle}"".txt"
    echo ${fout_cycle}
}


function ismonthly(){

    result=0
    date1=$1
    date2=$2
    y1=`getyear ${date1}`
    y2=`getyear ${date2}`
    m1=`getmon ${date1}`
    m2=`getmon ${date2}`
    
    if [ ${y1} -eq ${y2} -a ${m1} -eq ${m2} ];then
	result=1
    fi
    echo ${result}
}

function do_filter(){
    fin=${1}
    fout=${fin/".odb"/".txt"}
    if [ -f ${fin} ];then
	odb sql 'SELECT                                       
         date@hdr,                                                                                                  
         time@hdr,                                                                                                  
         lat@hdr,
         lon@hdr,                                                                                                  
         obsvalue@body,                                                                                               
         varno@body,                                                                                                  
         codetype@hdr,
         count(*)                                                                                                
         WHERE                                                                                               
         datum_status.active@body == 1' -i ${fin} -o ${fout}
    fi
}