getDataTHEMIS.php
5.22 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* @file getDataTHEMIS.php
* @version $Id: getDataTHEMIS.php,v 1.7 2010/01/11 18:16:46 budnik Exp $
* @brief DD_Server tools <br> Gets Data from /THEMIS_B1 (NFS)
*
* @arg remDataSetID ddVIdir StartTime StopTime \n
* Env Vars: $DDBASE $DDBASEBIN \n
* Executables: [DataSet]2nc(DECODERS) TimesUpdate TimesUpdateNoData clean
*
*
* @todo General getData.php(dataBaseID)
*/
// Open STDERR stream
$STDERR = fopen("php://stderr","w");
// Args
$id = $argv[1];
$ViDir = $argv[2];
$Start = $argv[3];
$Stop = $argv[4];
// NFS direcory
define('ThemisDir', '/THEMIS_B1/themisdata/');
define('DataSetDir', ThemisDir.strtr($id,"_","/"));
// Env variables
define('DDBASEBIN', getenv("DDBASEBIN"));
define('DDBASE', getenv("DDBASE"));
$arr = explode("/", $ViDir);
$instrument = $arr[5];
$mission = $arr[4];
$mode = strpos($arr[6],"_") === false ? $arr[6] : substr($arr[6],0,4);
switch ($mode) {
case "psif" :
case "psef" :
case "peif" :
case "peef" :
case "peim" :
case "peem" :
case "h" :
case "l" :
$realDir = DDBASE."/".$mission."/".$instrument."/".$arr[6]."/";
system("cd $realDir ; ./clean");
touch($realDir."/LOCK");
fprintf($STDERR,$realDir." is LOCKED\n");
break;
case "peir" :
case "peer" :
case "peib" :
case "peeb" :
$dirAdd = array("/sp", "/mom");
$fileAdd = array("s", "");
$realDir = DDBASE."/".$mission."/".$instrument."/".$mode."/";
for ($n = 0; $n < 2; $n++) {
$theDir = $realDir.$dirAdd[$n];
system("cd $theDir ; ./clean ");
touch($theDir."/LOCK");
fprintf($STDERR,$theDir." is LOCKED\n");
}
break;
}
switch ($mode) {
case "peif" :
case "peef" :
$program = DDBASEBIN."/themis_esafull2nc ";
break;
case "peim" :
case "peem" :
$program = DDBASEBIN."/themis_esamom2nc ";
break;
case "peir" :
case "peer" :
case "peib" :
case "peeb" :
$program = DDBASEBIN."/themis_esa2nc ";
break;
case "psif" :
case "psef" :
$program = DDBASEBIN."/themis_sst2nc ";
break;
case "h" :
case "l" :
$program = DDBASEBIN."/themis_fgm2nc ";
break;
}
// fprintf($STDERR, "REALDIR ".$realDir." \n");
// Which files
$currTime = strtotime($Start);
$stopTime = strtotime($Stop);
$currTime -= 3600.0;
while ($currTime <= $stopTime) {
$fileName = DataSetDir."/".date('Y', $currTime)."/".$id."_".date('Ymd', $currTime)."_v01.cdf";
if (file_exists($fileName)) {
system($program." ".$fileName." ".$mission." ".$mode);
fprintf($STDERR, "FILE $fileName is TRANSLATED \n");
}
else {
fprintf($STDERR,"NO SUCH FILE $fileName \n");
}
$currTime += 24*60*60;
}
switch ($mode) {
case "psif" :
case "psef" :
case "peif" :
case "peef" :
case "peim" :
case "peem" :
system("mv ".$mode."[0-9]*.nc $realDir");
system("cd $realDir ;".DDBASEBIN."/TimesUpdate -u ".$mode."_times.nc ".$mode."[0-9]*.nc; ".DDBASEBIN."/TimesUpdateNoData ".$mode."_times.nc ".$argv[3]." ".$argv[4]);
unlink($realDir."/LOCK");
break;
case "peir" :
case "peer" :
case "peib" :
case "peeb" :
for ($n = 0; $n < 2; $n++) {
$theDir = $realDir.$dirAdd[$n];
system("mv ".$fileAdd[$n].$mode."[0-9]*.nc $theDir");
system("cd $theDir ;".DDBASEBIN."/TimesUpdate -u ".$mode."_times.nc ".$fileAdd[$n].$mode."[0-9]*.nc; ".DDBASEBIN."/TimesUpdateNoData ".$mode."_times.nc ".$argv[3]." ".$argv[4]);
unlink($theDir."/LOCK");
}
break;
case "h" :
case "l" :
system("mv fgm".$mode."[0-9]*.nc $realDir");
system("cd $realDir ;".DDBASEBIN."/TimesUpdate -u fgm".$mode."_times.nc fgm".$mode."[0-9]*.nc; ".DDBASEBIN."/TimesUpdateNoData fgm".$mode."_times.nc ".$argv[3]." ".$argv[4]);
unlink($realDir."/LOCK");
break;
}
fprintf($STDERR, "TIMES IS UPDATED \n");
fprintf($STDERR, "UNLOCK \n");
?>