createHeaderMAPSKP.php
2.9 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
<?php
/* $Id: createHeaderMAPSKP.php,v 1.5 2008/03/05 14:03:45 elena Exp $ */
/**
* \file createHeaderMAPSKP.php
* \brief Function to create header.nc for MapsKP datasets which are not self-described
* \todo Exclude absolute path for /usr/local/bin/ncgen
*/
function createHeaderMAPSKP($remSetID) {
$url = "http://planetoweb.cesr.fr/mapskp-amda/MapskpService.php?";
$passwd = "ftp://amda:dd;mapskp@";
$args = array('service'=>'getInfoUrl',
'datasetId'=>$remSetID);
$url .= http_build_query($args);
$infoDom = new DOMDocument();
$infoDom->load($url);
$File = $infoDom->getElementsByTagName("infoUrl")->item(0)->nodeValue;
$fileName_ = explode("ftp://",$File);
$fileName = $fileName_[0].$passwd.$fileName_[1];
$infoDom->load($fileName);
$sampling = $infoDom->getElementsByTagName("TIME_RESOLUTION")->item(0)->nodeValue;
$globalAttrs = ":minSampling = ".$sampling.";";
$params = $infoDom->getElementsByTagName("PARAM_METADATA");
$Dimensions = "Time = unlimited, TimeLength = 17 ";
$charVariables = "char Time(Time,TimeLength), StartTime(TimeLength), StopTime(TimeLength);";
$floatVariables = "float ";
$Size = array();
$addDim = true;
for ($i = 0; $i < $params->length; $i++) {
$Name = $params->item($i)->getElementsByTagName("PARAM_ID")->item(0)->nodeValue;
$Size[$i] = $params->item($i)->getElementsByTagName("SIZES")->item(0)->nodeValue;
$Type = $params->item($i)->getElementsByTagName("DATA_TYPE")->item(0)->nodeValue;
if ($i > 0) $floatVariables .= ",";
if ($Size[$i] != "1" ) {
for ($j = 0; $j < $i+1; $j++)
if ($Size[$i] == $Size[$j]) {
if ($i != 0 && $j != $i) $addDim = false;
break;
}
if ($addDim) $Dimensions .= ", Dim".$j." = ".$Size[$j];
$floatVariables .= $Name."(Time, Dim".$j.")";
$addDim = true;
}
else
$floatVariables .= $Name."(Time)";
//
}
// Create CDL ASCII file
$cdl = fopen("header.cdl","w");
fwrite($cdl, "netcdf header { \n \n dimensions: \n");
fwrite($cdl,$Dimensions."; \n\n");
fwrite($cdl, "variables: \n ");
fwrite($cdl, $charVariables."\n");
fwrite($cdl, $floatVariables."; \n \n");
fwrite($cdl, $globalAttrs."\n");
fwrite($cdl, "data: \n\n }");
fclose($cdl);
// transform to nc
system("/usr/bin/ncgen -o header.nc header.cdl");
// make constant Energy Tables in info.nc
// For MIMI also ...
if ($remSetID == "RPWS_KEY") {
$StartTime = $infoDom->getElementsByTagName("START_DATE")->item(0)->nodeValue;
$function = "make".$remSetID."info";
include($function.".php");
if ($OK = $function($StartTime)) system("join_nc ".strtolower($remSetID)."_constant.nc ".strtolower($remSetID)."_info.nc");
}
}
?>