getDataCDAWEB.php
3.7 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
<?php
/**
* @file getDataCDAWEB.php
* @version $Id: getDataCDAWEB.php,v 1.5 2009/08/26 09:32:40 budnik Exp $
* @brief DD_Server tools <br> Gets Data from CDAWEB
*
* Args: remDataSetID ddVIdir StartTime StopTime \n
* Env Vars: $DDBASE $DDBASEBIN \n
* Executables: cdf2nc(DECODERS) TimesUpdate clean
*
*
* @todo General getData.php(dataBaseID)
*/
/*----------------------------------------------------------------------
* DD SERVER TOOLS
* data update collection
* getDataCDAWEB.php
* php getDataCDAWEB.php <remDataSetID> <ddVIdir> <StartTime> <StopTime>
* 17 June 2007 V.1.0
* 02 Aug 2007 V.1.1
* 06 Aug 2007 V.1.2, cd to Data directory
* 23 Aug 2007 V.1.3, Another program for VI times update
* 23 Aug 2007 V.1.4, ZIP files before updating
* 23 Nov 2007 V.1.5 Copy LOCK file
* 21 jan 2008 V.1.6 Process all SOAP exceptions
* cut file names longer than 32
*-----------------------------------------------------------------------*/
// 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;
$MAX_VI_NAME_LENGTH = 16;
$wsdl = "http://cdaweb.gsfc.nasa.gov/WS/istp_public/jaxrpc?WSDL";
// Opent STDERR stream
$STDERR = fopen("php://stderr","w");
try {
$client = new SoapClient($wsdl);
}
catch (SoapFault $exception) {
fprintf($STDERR,"CDAWEB WSDL is unreachable \n");
exit(0);
}
// Stamp -> this directory is being updated
$LockName = $ViDir."/LOCK";
touch($LockName);
fprintf($STDERR,$ViDir." is LOCKED\n");
system("cd ".$ViDir."; ./clean");
// If name is too long.
$nc_prefix = strlen($id) > $MAX_VI_NAME_LENGTH ? substr(strtolower($id),0,15): strtolower($id);
try
{
$dataFileDesc = $client->__soapCall("getDataFiles", array($id, $Start, $Stop));
fprintf($STDERR, "FILES GOT ".count($dataFileDesc)."\n");
}
catch (SoapFault $exception)
{
unlink($LockName);
fprintf($STDERR, $exception."\n");
exit(0);
}
if (count($dataFileDesc) > 0)
{
for ($i = 0; $i < count($dataFileDesc); $i++) {
$file = $dataFileDesc[$i]->name;
$fileArr = split("/",$file);
// fprintf($STDERR, $fileArr[count($fileArr)-1]."\n");
if (copy($file, $fileArr[count($fileArr)-1])) {
system($DDBASEBIN."/cdf2nc ".$fileArr[count($fileArr)-1]);
fprintf($STDERR, "FILES TRANSLATED ".$i."\n");
$ncFile = str_replace(".cdf", ".nc", $fileArr[count($fileArr)-1]);
unlink($fileArr[count($fileArr)-1]);
$ncFileTrue = ($strLength = strlen($ncFile)) > $MAX_NAME_LENGTH ?
$nc_prefix."_".time().$i.".nc" : $ncFile;
rename($ncFile,$ViDir."/".$ncFileTrue);
system("cd ".$ViDir."; ".$DDBASEBIN."/TimesUpdate -u ".strtolower($id)."_times.nc ".$ncFileTrue);
fprintf($STDERR, "TIMES IS UPDATED ".$i."\n");
}
else fprintf($STDERR, $file." is not found\n");
}
}
system("cd ".$ViDir."; ".$DDBASEBIN."/TimesUpdateNoData ".strtolower($id)."_times.nc ".$argv[3]." ".$argv[4]);
unlink($LockName);
fprintf($STDERR, "UNLOCK \n");
?>