createHeaderVEXGRAZ.php
2.08 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
<?php
/**
* @file createHeaderVEXGRAZ.php
* @version $Id: createHeaderVEXGRAZ.php,v 1.1 2009/03/23 14:02:39 budnik Exp $
* @brief Function to create header.nc for MapsKP datasets which are not self-described
* @todo Exclude absolute path for /usr/local/bin/ncgen
*/
function createHeaderVEXGRAZ($remSetID) {
$infoDom = new DOMDocument();
$infoDom->load(INFODIR."../AmdaInfo/MAG_VSO.xml");
$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/local/bin/ncgen -o header.nc header.cdl");
}
?>