TargetDir = './'; // new amda $this->PRODIR = TEMPLATES; $this->PredefinedDir = PREDEFINED; } protected function param2dd($paramID){ $pairs = array(":" => "_"); return strtr($paramID, $pairs); } protected function param2ddPoint($paramID){ $pairs = array(":" => "_", "." => "_"); return strtr($paramID, $pairs); } public function makeNewChain($chain, $vars){ // cleanup components array !!! $this->components = array(); rsort($vars); for ($i = 0; $i < count($vars); $i++){ $start = 0; while (($pos = strpos($chain, $vars[$i], $start)) !== false) { $moreLong = false; if ($i > 0) { for ($k = 0; $k < $i; $k++) { if (substr($vars[$k],0,strlen($vars[$i])) === $vars[$i]) { if (strpos($chain, $vars[$k], $pos) !== false) { $moreLong = true; $start = $pos+strlen($vars[$k]); $break; } } } } if (!$moreLong) { if (($open = strpos($chain,$vars[$i]."(",$start)) === false) { $chain = substr_replace($chain,$vars[$i]."(num)", $pos, strlen($vars[$i])); $this->components[] = $vars[$i]."(*)"; $start = $pos+strlen($vars[$i]); } else { $close = strpos($chain, ",num)", $open); if ($close !== false && ($close-$open) < (strlen($vars[$i])+5)) { $start = $open+strlen($vars[$i]); } else { $close = strpos($chain,")",$open); $vector_pos = strpos($chain,":",$open); if ($vector_pos === false || $vector_pos > $close) { $chain = substr_replace($chain,",num)",$close,1); $this->components[] = substr($chain,$open,$close-$open).",*)"; } else { $comp = substr($chain, $vector_pos+3, 1); $this->components[] = substr($chain,$open,strlen($vars[$i]))."(".$comp.",*)"; $chain = substr_replace($chain,",num),".$comp, $close-2, 3); } $start = $open+strlen($vars[$i]); } } } } } $this->components = array_unique($this->components); return $chain; } public function makeParamCalcul($chain, $vars, $name) { foreach ($vars as &$var) $var = $this->param2dd($var); $chain = $this->param2dd($chain); $newChain = $this->makeNewChain($chain, $vars); $function_name = $name == "" ? "paramcalcul" : strtolower($name)."_calcul"; $fillValue = $name == "" ? "3" : "!Values.F_NAN"; $pro = fopen($this->TargetDir.$function_name.".pro", "w"); fwrite($pro,"function ".$function_name.",".join(",",$vars).PHP_EOL); fwrite($pro,"common InternalCommon, FinalTime, num".PHP_EOL); fwrite($pro,"OutPut = REPLICATE(".$fillValue.", N_Elements(FinalTime))".PHP_EOL); fwrite($pro,"num = -1L\n"); /* * !!!! array_unique($this->components) -> keeps unset empty values!!! */ foreach ($this->components as $comp) { fwrite($pro," num_ = where(finite(".$comp."), Index)\n"); fwrite($pro," if (Index eq 0) then return, OutPut\n"); fwrite($pro," if (num[0] eq -1L) then num = num_ $\n else begin\n numTemp = -1L\n k = -1L\n j0 = 0L\n"); fwrite($pro," for i = 0L, n_elements(num) - 1 do begin\n for j = j0, n_elements(num_) - 1 do begin\n"); fwrite($pro," if (num[i] eq num_[j]) then begin\n k++\n if (k eq 0) then numTemp = num[i] $\n else numTemp = [numTemp, num[i]]\n"); fwrite($pro," j0 = j+1\n break\n endif\n endfor\n endfor\n"); fwrite($pro," if (j0 gt 0) then num = numTemp else return, OutPut\n endelse \n"); } // printf, LUN, 'On_error,2' fwrite($pro,"OutPut[num] = ".$newChain.PHP_EOL); fwrite($pro,"return, OutPut".PHP_EOL); fwrite($pro,"end".PHP_EOL); fclose($pro); } /* * * Make all staff for local params from templates & descriptor XML * */ public function paramLocalBuild($id) { /* * Get Param Info */ $infoMgr = new ParamsInfoMgr(); $infos = $infoMgr->GetParamInfo($id); if (!$infos['success']) { die($infos['message']); } $name = $infos['codeinfos']['name']; $vi = $infos['codeinfos']['vi']; $size = $infos['codeinfos']['size']; $tensor = $infos['codeinfos']['tensor']; if ($tensor == '') $tensor = -1; $value_type = $infos['codeinfos']['valuetype']; $fill_value = $infos['codeinfos']['fillvalue']; if ($fill_value == "NaN") $fill_value = "!Values.F_NAN"; $units = $infos['codeinfos']['units']; $sampling = $infos['codeinfos']['minsampling']; $maxSampling = $infos['codeinfos']['maxsampling']; $frame = $infos['codeinfos']['frame']; $legend = $infos['codeinfos']['legend']; $title = $infos['codeinfos']['title']; $plottype = $infos['codeinfos']['plottype']; $mission = $infos['codeinfos']['mission']; $energychannel = $infos['codeinfos']['energychannel']; if ($energychannel == '') $energychannel = 'Energy'; $ytitle = $units != NULL ? $title.",!C".$units : $title; $conversion = $infos['codeinfos']['conversion']; $process = $infos['codeinfos']['process']; /* * Make init */ if (file_exists($this->PredefinedDir.$id."_init.pro")) { copy($this->PredefinedDir.$id."_init.pro", $this->TargetDir.$id."_init.pro"); } else { $newfile = fopen($this->TargetDir.$id."_init.pro","w"); $pairs = array("LOCALPARAM" => $id,"LOCALTENSOR"=>$tensor,"LOCALSIZE"=>$size,"LOCALYTITLE"=>"'".$ytitle."'","LOCALPROCESS"=>"'".$process."'", "LOCALFRAME"=>"'".$frame."'","LOCALMISSION"=>"'".$mission."'","LOCALPLOTTYPE"=>"'".$plottype."'", "LOCALLEGEND"=>"'".$legend."'"); $lines = file($this->PRODIR."localparam_init.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); if ($size > 1) { $comp = array("/X", "/Y", "/Z"); // VECTOR if ($size <= 3) { $comp = array("/X", "/Y", "/Z"); for ($i = 0; $i < $size; $i++) { $newfile = fopen($id."_".$i."_init.pro", "w"); fwrite($newfile,"pro ".$id."_".$i."_init, FRAME=frame,LOG=log,LIN=lin,COLOR=color,PSYM=psym,AY1TITLE=aytitle, _EXTRA=e".PHP_EOL); fwrite($newfile,"cmd = '".$id."_init, ".$comp[$i]."'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(COLOR) then cmd += ',COLOR=color'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(FRAME) then cmd += ',FRAME=frame'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(PSYM) then cmd += ',PSYM=psym'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(LOG) then cmd += ',/LOG'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(LIN) then cmd += ',/LIN'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(AY1TITLE) then cmd += ',AY1TITLE=ay1title'".PHP_EOL); fwrite($newfile,"R = execute(cmd)".PHP_EOL); fwrite($newfile,"return".PHP_EOL); fwrite($newfile,"end".PHP_EOL); fclose($newfile); } } elseif ($plottype == "STACK") { for ($i = 0; $i < $size; $i++) { $newfile = fopen($id."_".$i."_init.pro", "w"); fwrite($newfile,"pro ".$id."_".$i."_init, LOG=log,LIN=lin,COLOR=color,PSYM=psym,AY1TITLE=aytitle, _EXTRA=e".PHP_EOL); fwrite($newfile,"cmd = '".$id."_init, CHANNEL=".($i+1)."'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(COLOR) then cmd += ',COLOR=color'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(PSYM) then cmd += ',PSYM=psym'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(LOG) then cmd += ',/LOG'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(LIN) then cmd += ',/LIN'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(AY1TITLE) then cmd += ',AY1TITLE=ay1title'".PHP_EOL); fwrite($newfile,"R = execute(cmd)".PHP_EOL); fwrite($newfile,"return".PHP_EOL); fwrite($newfile,"end".PHP_EOL); fclose($newfile); } } // TENSOR; diagonal elements elseif ($size == 9 && $tensor == 2) { $sizeR = array(0, 4, 8); for ($i = 0; $i < 3; $i++) { $newfile = fopen($id."_".$sizeR[$i]."_init.pro", "w"); fwrite($newfile,"pro ".$id."_".$sizeR[$i]."_init, LOG=log,LIN=lin,COLOR=color,PSYM=psym,AY1TITLE=aytitle, _EXTRA=e".PHP_EOL); fwrite($newfile,"cmd = '".$id."_init, ".$comp[$i].PHP_EOL); fwrite($newfile, "if KEYWORD_SET(COLOR) then cmd += ',COLOR=color'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(PSYM) then cmd += ',PSYM=psym'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(LOG) then cmd += ',/LOG'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(LIN) then cmd += ',/LIN'".PHP_EOL); fwrite($newfile, "if KEYWORD_SET(AY1TITLE) then cmd += ',AY1TITLE=ay1title'".PHP_EOL); fwrite($newfile,"R = execute(cmd)".PHP_EOL); fwrite($newfile,"return".PHP_EOL); fwrite($newfile,"end".PHP_EOL); fclose($newfile); } } } } /* * Make com */ if (file_exists($this->PredefinedDir.$id."_com.pro")) { copy($this->PredefinedDir.$id."_com.pro", $this->TargetDir.$id."_com.pro"); } else { $newfile = fopen($this->TargetDir.$id."_com.pro","w"); $pairs = array("LOCALPARAM" => $id,"LOCALSIZE"=>$size,"LOCALSAMPLING"=>$sampling, "LOCALMAXSAMPLING"=>$maxSampling,"LOCALFILLVALUE"=>$fill_value, "LOCALPLOTTYPE"=>"'".$plottype."'","LOCALVI"=>"'".$vi."'","LOCALENERGYCHANNEL"=>"'".$energychannel."'", "LOCALCONVERSION" => "'".$conversion."'"); $lines = file($this->PRODIR."localparam_com.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); } /* * Make get */ if (file_exists($this->PredefinedDir."get".$id.".pro")) { copy($this->PredefinedDir."get".$id.".pro", $this->TargetDir."get".$id.".pro"); } else { $newfile = fopen($this->TargetDir."get".$id.".pro","w"); $pairs = array("LOCALPARAM" => $id,"LOCALSIZE"=>$size,"LOCALPARAMNAME"=>"'".$this->param2ddPoint($name)."'", "LOCALVI"=>"'".$vi."'", "LOCALDATATYPE" => "'".$value_type."'", "LOCALCONVERSION" => "'".$conversion."'"); $lines = file($this->PRODIR."getlocalparam.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); } /* * Make parameter */ if (file_exists($this->PredefinedDir.$id."_.pro")) { copy($this->PredefinedDir.$id."_.pro", $this->TargetDir.$id."_.pro"); } else { $newfile = fopen($this->TargetDir.$id."_.pro","w"); $pairs = array("LOCALPARAM" => $id,"LOCALSIZE"=>$size, "LOCALSAMPLING"=>$sampling, "LOCALPARAMNAME"=>"'".$this->param2ddPoint($name)."'", "LOCALVI"=>"'".$vi."'", "LOCALDATATYPE" => "'".$value_type."'","LOCALFILLVALUE"=>$fill_value,"LOCALPROCESS"=>"'".$process."'", "LOCALCONVERSION" => "'".$conversion."'"); $lines = file($this->PRODIR."localparam_.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); } } /* * Make WS parameter */ public function makeWsParamPlot($ws_object) { /* * Make init */ $infoMgr = new ParamsInfoMgr(); $infos = $infoMgr->GetParamInfo($ws_object); $Ytitle = $ws_object; if ($infos['success']) { if ($infos['infos']['ytitle'] != 'undefined') $Ytitle = $infos['infos']['ytitle']; if ($infos['infos']['units'] != 'undefined') $Ytitle .= ','.$infos['infos']['units']; } $pairs = array("WS" => $ws_object, "TTT" => $Ytitle); $newfile = fopen($this->TargetDir.$ws_object."_init.pro","w"); $lines = file($this->PRODIR."ws_init.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); /* * Make Common */ $newfile = fopen($this->TargetDir.$ws_object."_com.pro","w"); $lines = file($this->PRODIR."ws_com.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); /* * Make Get */ $newfile = fopen($this->TargetDir."get".$ws_object.".pro","w"); $lines = file($this->PRODIR."getws.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); /* * Make parameter */ $newfile = fopen($this->TargetDir.$ws_object."_.pro","w"); $lines = file($this->PRODIR."ws_.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); } /* * Make WSD parameter */ public function makeWsdParam($wsd) { copy (OLD_CLASSPATH."getViStart.php",$this->TargetDir."getViStart.php"); copy (OLD_CLASSPATH."getViStop.php",$this->TargetDir."getViStop.php"); copy (OLD_CLASSPATH."setViStart.php",$this->TargetDir."setViStart.php"); copy (OLD_CLASSPATH."setViStop.php",$this->TargetDir."setViStop.php"); copy (OLD_CLASSPATH."getFileNames.php",$this->TargetDir."getFileNames.php"); copy (OLD_CLASSPATH."getVotVar.php",$this->TargetDir."getVotVar.php"); copy (OLD_CLASSPATH."moreData.php",$this->TargetDir."moreData.php"); //TODO do we need wsd_..xml??? // $param_xml = USERWSDIR.$wsd.".xml"; $param_xml = getenv('USER_WS_PATH').$wsd.".xml"; $param_dom = new DomDocument("1.0"); $param_dom -> load($param_xml); /* * Get Param Info */ if (strncmp($wsd, "simu_", 5) == 0) { $paramType = 'simu'; $isMoreData = 1; $theParam = $param_dom->getElementsByTagName("mysimudata")->item(0); } elseif (strncmp($wsd, "wsr_", 4) == 0) { $paramType = 'wsr'; $isMoreData = 1; $theParam = $param_dom->getElementsByTagName("mywsrdata")->item(0); } else { $paramType = 'wsd'; $isMoreData = 0; $theParam = $param_dom->getElementsByTagName("mydata")->item(0); } if ($paramType == 'wsr' || $paramType == 'simu') $alias = strtolower($theParam->getElementsByTagName("name")->item(0)->nodeValue); else $alias = "wsd_".strtolower($theParam->getElementsByTagName("name")->item(0)->nodeValue); $name = $theParam->getElementsByTagName("realvar")->item(0)->nodeValue; $size = $theParam->getElementsByTagName("size")->item(0)->nodeValue; $format = $theParam->getElementsByTagName("format")->item(0)->nodeValue; $vi = $theParam->getElementsByTagName("vi")->item(0)->nodeValue; $plottypeArr = $theParam->getElementsByTagName("plottype"); $plot_type = $plottypeArr->length > 0 ? $plottypeArr->item(0)->nodeValue : 'undefined'; switch ($size) { case "3" : $tensor = 1; break; case "1" : $tensor = 0; break; default : $tensor = 2; } $value_type = $theParam->getElementsByTagName("type")->item(0)->nodeValue; $fill_value = $theParam->getElementsByTagName("fillvalue")->item(0)->nodeValue; if (!$fill_value) $fill_value = -1.e+31; if ($fill_value == "NaN") $fill_value = "!Values.F_NAN"; $units = $theParam->getElementsByTagName("units")->item(0)->nodeValue; if (!$units) $units = ""; $sampling = $theParam->getElementsByTagName("minsampling")->item(0)->nodeValue; $maxSampling = $sampling; if ($theParam->getElementsByTagName("maxsampling")->item(0)->nodeValue != $sampling) $maxSampling =$theParam->getElementsByTagName("maxsampling")->item(0)->nodeValue; $legend = $theParam->getElementsByTagName("legend")->item(0)->nodeValue; if (!$legend) $legend = " X; Y; Z"; $ytitle = $theParam->getElementsByTagName("ytitle")->item(0)->nodeValue; /* * Make init */ $newfile = fopen($this->TargetDir.$alias."_init.pro","w"); $pairs = array("WSDPARAM" => $alias,"WSDTENSOR"=>$tensor,"WSDUNITS"=>"'".$units."'","WSDPLOTTYPE"=>"'".$plot_type."'","WSDSIZE"=>$size,"WSDYTITLE"=>"'".$ytitle."'", "WSDLEGEND"=>"'".$legend."'"); $lines = file($this->PRODIR."wsd_init.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); if ($size > 1) { $comp = array("/X", "/Y", "/Z"); for ($i = 0; $i < $size; $i++) { $newfile = fopen($alias."_".$i."_init.pro", "w"); fwrite($newfile,"pro ".$alias."_".$i."_init \n"); fwrite($newfile,"cmd = '".$alias."_init, ".$comp[$i]."'\n"); fwrite($newfile,"R = execute(cmd) \n"); fwrite($newfile,"return \n"); fwrite($newfile,"end \n"); fclose($newfile); } } /* * Make com */ $newfile = fopen($this->TargetDir.$alias."_com.pro","w"); $pairs = array("WSDPARAM" => $alias,"WSDSIZE"=>$size,"WSDSAMPLING"=>$sampling,"WSDMAXSAMPLING"=>$maxSampling, "WSDFILLVALUE"=>$fill_value); $lines = file($this->PRODIR."wsd_com.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); /* * Make get */ $newfile = fopen($this->TargetDir."get".$alias.".pro","w"); $pairs = array("WSDPARAM" => $alias,"WSDSIZE"=>$size,"WSDPARAMNAME"=>"'".$name."'", "WSDDATATYPE" => "'".$value_type."'","WSDFORMAT" => "'".$format."'", "WSDVI" => "'".$vi."'", "WSDMOREDATA" => $isMoreData,"WSDPLOTTYPE"=>"'".$plot_type."'"); $lines = file($this->PRODIR."getwsd.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); /* * Make parameter */ $newfile = fopen($this->TargetDir.$alias."_.pro","w"); $pairs = array("WSDPARAM" => $alias,"WSDSIZE"=>$size,"WSDSAMPLING"=>$sampling, "WSDPARAMNAME"=>"'".$name."'", "WSDDATATYPE" => "'".$value_type."'","WSDFORMAT" => "'".$format."'","WSDFILLVALUE"=>$fill_value, "WSDVI" => "'".$vi."'"); $lines = file($this->PRODIR."wsd_.pro"); for ($i = 0; $i < count($lines); $i++) { $newline = strtr($lines[$i],$pairs); fwrite($newfile,$newline); } fclose($newfile); } } ?>