$url_ascii, 'Description' => "", 'Fields' => array() ); // ------------------------------------------------------------------- // Go through the file line by line and extract field names and data // ------------------------------------------------------------------- $ascii_table = preg_split("/[\n]+/", $ascii_file); // Split the ascii file into an array of lines $First = true; // Flag for detecting the first non-comment line (= line with field names) foreach($ascii_table as $line) { // Store comment lines into VOT table description // Comment lines start with character '#' if (substr($line,0,1) == "#") { $params['Description'] .= $line . "\n"; continue; } // If first non-comment line read field names and units. The line content is something like: // it year mo dy hr mn sc msc X Y Z rho ux uy uz Bx(nT) By(nT) Bz(nT) p jx jy jz if ($First) { $lineX = str_replace ('X' , 'X(Re)' , $line); $lineY = str_replace ('Y' , 'Y(Re)' , $lineX); $lineZ = str_replace ('Z' , 'Z(Re)' , $lineY); $lineRho = str_replace ('rho' , 'rho(cm-3)' , $lineZ); $lineUx = str_replace ('ux' , 'ux(km/s)' , $lineRho); $lineUy = str_replace ('uy' , 'uy(km/s)' , $lineUx); $lineUz = str_replace ('uz' , 'uz(km/s)' , $lineUy); $lineP = str_replace ('P' , 'P(nPa)' , $lineUz); $lineJx = str_replace ('jx' , 'jx(mA/m2)' , $lineP); $lineJy = str_replace ('jy' , 'jy(mA/m2)' , $lineJx); $lineJz = str_replace ('jz' , 'jz(mA/m2)' , $lineJy); $Field_list = preg_split("/[\s,]+/", trim($lineJz)); // Create an array of field names foreach($Field_list as $field) { $params['Fields'][] = array(); // Create a new associative array for this field $index = count($params['Fields']) - 1; // Get name and possible unit (included in parenthesis) preg_match("/([^(]+)[(]*([^)]*)[)]*$/", $field, $matches); $params['Fields'][$index]['name'] = $matches[1]; $params['Fields'][$index]['unit'] = $matches[2]; // unit string is "" if no unit defined // Set the datatype attribute. Otherwise Topcat won't recognize the variable if (in_array($matches[1], array('it','year','mo','dy','hr','mn','sc','msc'))) $params['Fields'][$index]['datatype'] = 'int'; else $params['Fields'][$index]['datatype'] = 'float'; $params['Fields'][$index]['data'] = array(); // Define the array for data values } $First = false; continue; } // Read data line $i = 0; $Value_list = preg_split("/[\s,]+/", trim($line)); // Make an array of data values in this line foreach($Value_list as $value) { $params['Fields'][$i++]['data'][] = $value; // Add the data value into field's data array } } // --------------------------------------- // Add the time column in ISO8601 format. // --------------------------------------- // First try to locate the data arrays for year, mo, dy, hr, mn, sc and msc columns foreach($params['Fields'] as $field) { if ($field['name'] == 'year') $year_data = $field['data']; if ($field['name'] == 'mo') $mo_data = $field['data']; if ($field['name'] == 'dy') $dy_data = $field['data']; if ($field['name'] == 'hr') $hr_data = $field['data']; if ($field['name'] == 'mn') $mn_data = $field['data']; if ($field['name'] == 'sc') $sc_data = $field['data']; if ($field['name'] == 'msc') $msc_data = $field['data']; } // If all date arrays are found then create the date string in ISO8601 format if (isset($year_data) and isset($mo_data) and isset($dy_data) and isset($hr_data) and isset($mn_data) and isset($sc_data) and isset($msc_data)) { $params['Fields'][] = array(); // Add new field to $params array $index = count($params['Fields']) - 1; // Index of the new field $params['Fields'][$index]['name'] = 'Time'; // Set the name to 'Time' $params['Fields'][$index]['data'] = array(); // Create array for data values for ($i = 0; $i < count($year_data); $i++) { // Fill the data array $time_stamp = gmmktime($hr_data[$i], $mn_data[$i], $sc_data[$i], $mo_data[$i], $dy_data[$i], $year_data[$i]); $time_str = gmdate("Y-m-d\TH:i:s", $time_stamp) . "." . substr("000" . $msc_data[$i],-3); $params['Fields'][$index]['data'][] = $time_str; // Add the value to the end of the data table } } // ------------------------------------------------------------------------- // More computable quantities (e.g. Btot, Utot) may be added here similarly // ------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------- // Finally call the getVOTableURL method to create a VOTtable file and store it into FMI's server // ----------------------------------------------------------------------------------------------- $methods_file = "http://impex-fp7.fmi.fi/ws/Methods_FMI.wsdl"; $client = new SoapClient($methods_file); try { $data_url = $client->getVOTableURL($params); } catch (Exception $e) { echo "Error :
"; echo $e->getMessage(); exit(); } if ($data_url){ $contenu = file_get_contents($data_url); echo $contenu; } // echo $data_url . "\n"; ?>