getDataSKR.php
2.64 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
<?php
/**
* @file getDataSKR.php
* @brief DD_Server tools <br> Gets Data from SKR
*
* @arg remDataSetID ddVIdir StartTime StopTime
* @arg Env Vars: $DDBASE $DDBASEBIN \n
* @arg Executables: skr2nc(DECODERS) TimesUpdate TimesUpdateNoData clean
*
*
* @todo General getData.php(dataBaseID)
* @version $Id: $
* @date 20 june 2008
*/
// Args
$id = $argv[1];
$ViDir = $argv[2];
$Start = $argv[3];
$Stop = $argv[4];
// Env variables
$DDBASEBIN = getenv("DDBASEBIN");
$DDBASE = getenv("DDBASE");
$MAX_NAME_LENGTH = 31;
// SKR STUFF
$url = "http://rpwsTeam:KronoS04@www.lesia.obspm.fr/kronos/"
// Open STDERR stream
$STDERR = fopen("php://stderr","w");
// Lock VI directory for Updating
// Stamp -> this directory is being updated
$LockName = $ViDir."/LOCK";
touch($LockName);
fprintf($STDERR,$ViDir." is LOCKED\n");
// Send - Receive query
$url .= http_build_query($args);
$fileList = new DOMDocument();
$fileList->load($url);
$Files = $fileList->getElementsByTagName("url");
fprintf($STDERR, "FILES RETURN ". $Files->length."\n");
// Clean VI directory
system("cd ".$ViDir."; clean");
if ($Files->length > 0) {
for ($i = 0; $i < $Files->length; $i++) {
copy($ViDir."/header.nc","temp.nc");
$fileName_ = explode("//",$Files->item($i)->nodeValue);
$fileName = $fileName_[0].$passwd.$fileName_[1];
$fileArr = split("/",$fileName);
// Copy URL file to DD_Server dir
copy($fileName, $fileArr[count($fileArr)-1]);
// Convert ascii TAB to nc using header.nc
system($DDBASEBIN."/ascii2nc ".$fileArr[count($fileArr)-1]);
fprintf($STDERR, "FILE $i TRANSLATED \n");
unlink($fileArr[count($fileArr)-1]);
$ncFile = name2DD($fileArr[count($fileArr)-1]);
// Truncate file if it is too long
$ncFileTrue = ($strLength = strlen($ncFile)) > $MAX_NAME_LENGTH ?
"t".substr(substr($ncFile, 0, $strLength-3), $strLength-$MAX_NAME_LENGTH+1, $MAX_NAME_LENGTH-4).".nc" : $ncFile;
// Move nc file to VIdir
rename("temp.nc", $ViDir."/".$ncFileTrue);
// Updates VI time info
system("cd ".$ViDir."; ".$DDBASEBIN."/TimesUpdate -u ".strtolower($id)."_times.nc ".$ncFileTrue);
}
fprintf($STDERR, "TIMES IS UPDATED \n");
}
system("cd ".$ViDir."; ".$DDBASEBIN."/TimesUpdateNoData ".strtolower($id)."_times.nc ".$argv[3]." ".$argv[4]);
// Unlock VI dir
unlink($LockName);
fprintf($STDERR, "UNLOCK \n");
?>