\n";
$xmlfile.="\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
// TITLE is required in JCAMP
// SAMPLENAME is required in animl-sample.xsd
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##TITLE']."\n";
$xmlfile.=" \n";
// CASNAME is optional in JCAMP
// NAME is optional in animl-sample.xsd
if($ldrs['##CASNAME']!="")
{
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##CASNAME']."";
$xmlfile.=" \n";
}
// CONCENTRATIONS is optional in JCAMP
// SAMPLECONCENTRATIONS is optional in animl-sample.xsd
// Must get unit of concentration in addition to value
if($ldrs['##CONCENTRATIONS']!="")
{
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##CONCENTRATIONS']."\n";
if($ldrs['##CONCENTRATIONS.UNIT']=="M")
{
$xmlfile.=" \n";
$xmlfile.=" mol\n";
$xmlfile.=" m\n";
$xmlfile.=" \n";
}
elseif($ldrs['##CONCENTRATIONS.UNIT']=="g/L")
{
$xmlfile.=" \n";
$xmlfile.=" g\n";
$xmlfile.=" m\n";
$xmlfile.=" \n";
}
elseif($ldrs['##CONCENTRATIONS.UNIT']=="%")
{
$xmlfile.=" \n";
$xmlfile.=" 1\n";
$xmlfile.=" \n";
}
$xmlfile.=" \n";
}
// STATE is optional in JCAMP
// SAMPLESTATE is optional in animl-sample.xsd
// (Solid|Liquid|Gas|Solution)
if($ldrs['##STATE']!="")
{
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##STATE']."\n";
$xmlfile.=" \n";
}
// SAMPLINGPROCEDURE optional in JCAMP
// SAMPLEPREPARATIONPROCEDURE is option
if($ldrs['##SAMPLINGPROCEDURE']!="")
{
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##SAMPLINGPROCEDURE']."\n";
$xmlfile.=" \n";
}
// OWNER is required in JCAMP
// SAMPLEOWNER is optional in animl-sample.xsd
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##OWNER']."\n";
$xmlfile.=" \n";
// PRESSURE is optional in JCAMP
// PRESSURE is optional in animl-sample.xsd
// Must get unit of pressure in addition to value
if($ldrs['##PRESSURE']!="")
{
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##PRESSURE']."\n";
$xmlfile.=pressunit($ldrs['##PRESSURE.UNIT'],28);
$xmlfile.=" \n";
}
// TEMPERATURE is optional in JCAMP
// TEMPERATURE is optional in animl-sample.xsd
// Must get unit of temperature in addition to value
if($ldrs['##TEMPERATURE']!="")
{
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##TEMPERATURE']."\n";
$xmlfile.=tempunit($ldrs['##TEMPERATURE.UNIT'],28);
$xmlfile.=" \n";
}
// BP is optional in JCAMP
// BP is optional in animl-sample.xsd
// Must get unit of temperature in addition to value
if($ldrs['##BP']!="")
{
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##BP']."\n";
$xmlfile.=pressunit($ldrs['##BP.UNIT'],32);
$xmlfile.=" \n";
$xmlfile.=" ";
$xmlfile.=" 101325.01";
$xmlfile.=" \n";
$xmlfile.=" m\n";
$xmlfile.=" kg\n";
$xmlfile.=" s\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
}
// MP is optional in JCAMP
// MP is optional in animl-sample.xsd
// Must get unit of temperature in addition to value
if($ldrs['##MP']!="")
{
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##MP']."\n";
$xmlfile.=pressunit($ldrs['##MP.UNIT'],32);
$xmlfile.=" \n";
$xmlfile.=" ";
$xmlfile.=" 101325.01";
$xmlfile.=" \n";
$xmlfile.=" m\n";
$xmlfile.=" kg\n";
$xmlfile.=" s\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
}
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##ORIGIN']."\n";
$xmlfile.=" ".$ldrs['##OWNER']."\n";
$xmlfile.=" \n";
// DATE and TIME are optional in JCAMP
// Timestamp is optional in animl-core.xsd
// Make UTC/W3C DATETIME format from DATE and TIME
// UTC format is YYYY-MM-DDThh:mm:ss.sZ (how to deal with no timezone?)
// REf: http://www.w3.org/TR/NOTE-datetime
$timestamp="";
if($ldrs['##DATE']!="")
{
// Format YY/MM/DD
list($year,$month,$day)=explode("/",$ldrs['##DATE'],3);
if($year>50)
{
$year="19".$year;
}
else
{
$year="20".$year;
}
$timestamp.=$year."-".str_pad($month,2,"0",STR_PAD_LEFT)."-".str_pad($day,2,"0",STR_PAD_LEFT)."T";
}
else
{
$timestamp.="0000-00-00T";
}
if($ldrs['##TIME']!="")
{
// Format HH:MM:SS.ss
$timestamp.=$ldrs['##TIME'];
}
if($timestamp!="0000-00-00T")
{
$xmlfile.=" ".$timestamp."\n";
}
$xmlfile.=" \n";
// Using filename here as a unique ID. Other suggestions?
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
// The data type of the y data points is either float32 or int coming from JCAMP
// This could be inferred by the use of a non unity value for the YFACTOR however easier script wise to check for presence of "." in y data string
// Data is in the $data array coming from jcamp2animl.php
if(stristr($data[0]['Y'],".")): $ydata_type="float32";
else: $ydata_type="int";
endif;
$xmlfile.=" \n";
// This is set in jcamp2animl.php. Could be overridden by a GET variable if we wanted to.
if($yencode=="ivs")
{
$xmlfile.=" \n";
foreach($data as $point)
{
$xmlfile.=" <".$ydata_type.">".$point['Y']."".$ydata_type.">\n";
}
$xmlfile.=" \n";
}
// YUNIT values from JCAMP can be TRANSMITTANCE, REFLECTANCE, ABSORBANCE, KUBELKA-MUNK, ARBITARY UNITS (this list is still in JCAMP 6 draft...)
// Intensity vector units are Absorbance, %Transmittance, Transmittance, Arb. Units, and Counts in UVTechniqueDefinition.atid
$ldrs['##YUNITS']=strtoupper($ldrs['##YUNITS']);
if($ldrs['##YUNITS']=="A"||$ldrs['##YUNITS']=="ABS"||$ldrs['##YUNITS']=="ABSORBANCE"||$ldrs['##YUNITS']=="AU"||$ldrs['##YUNITS']=="AUFS"||$ldrs['##YUNITS']=="OPTICAL DENSITY")
{
$xmlfile.=" \n";
}
elseif($ldrs['##YUNITS']=="%T"||$ldrs['##YUNITS']=="%TRANSMITTANCE"||$ldrs['##YUNITS']=="PERCENT TRANSMITTANCE")
{
$xmlfile.=" \n";
}
elseif($ldrs['##YUNITS']=="T"||$ldrs['##YUNITS']=="TRANSMITTANCE")
{
$xmlfile.=" \n";
}
elseif($ldrs['##YUNITS']=="COUNTS"||$ldrs['##YUNITS']=="CTS")
{
$xmlfile.=" \n";
}
else
{
$xmlfile.=" \n";
}
$xmlfile.=" 1\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
// The data type of the x data points is either float32 or int coming from JCAMP
// This could be inferred by the use of a non unity value for the XFACTOR however easier script wise to check for presence of "." in FIRSTX string
// Data is in the $data array coming from jcamp2animl.php
if(stristr($ldrs['##FIRSTX'],".")): $xdata_type="float32";
else: $xdata_type="int";
endif;
$xmlfile.=" \n";
// This is set in jcamp2animl.php. Could be overridden by a GET variable if we wanted to.
if($xencode=="avs")
{
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" <".$xdata_type.">".$ldrs['##FIRSTX']."".$xdata_type.">\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" <".$xdata_type.">".$ldrs['##DELTAX']."".$xdata_type.">\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
}
// YCUNIT values from JCAMP can be TRANSMITTANCE, REFLECTANCE, ABSORBANCE, KUBELKA-MUNK, ARBITARY UNITS (this list is still in JCAMP 6 draft...)
// Intensity vector units are Absorbance, %Transmittance, Transmittance, Arb. Units, and Counts in UVTechniqueDefinition.atid
$ldrs['##XUNITS']=strtoupper($ldrs['##XUNITS']);
if(stristr($ldrs['##XUNITS'],"wavenumber")||stristr($ldrs['##XUNITS'],"1/cm")||stristr($ldrs['##XUNITS'],"cm-1"))
{
$xmlfile.=" \n";
$xmlfile.=" m\n";
}
elseif(stristr($ldrs['##XUNITS'],"um")||$ldrs['##XUNITS']==".micro.m"||stristr($ldrs['##XUNITS'],"micrometer"))
{
$xmlfile.=" \n";
$xmlfile.=" m\n";
}
elseif(stristr($ldrs['##XUNITS'],"nm")||stristr($ldrs['##XUNITS'],"nanometer")||stristr($ldrs['##XUNITS'],"wavelength"))
{
$xmlfile.=" \n";
$xmlfile.=" m\n";
}
elseif(stristr($ldrs['##XUNITS'],"pm")||stristr($ldrs['##XUNITS'],"picometer"))
{
$xmlfile.=" \n";
$xmlfile.=" m\n";
}
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##TITLE']."\n";
$xmlfile.=" \n";
// PATHLENGTH is optional in JCAMP (if it is present the unit is cm)
// PATHLENGTH is required in UVTechniqueDefinition.atid (assume 1.0 cm if not stated or use -1.0 to indicate that it was not set?)
if($ldrs['##PATHLENGTH']=="") { $ldrs['##PATHLENGTH']="1.0"; }
$xmlfile.=" \n";
$xmlfile.=" ".$ldrs['##PATHLENGTH']."\n";
$xmlfile.=" \n";
$xmlfile.=" m\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" Spectrum\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
//
// Add the peaktable here...
//
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" See Model description\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
if($ldrs['##SPECTROMETERDATASYSTEM']=="") { $ldrs['##SPECTROMETERDATASYSTEM']="Not available in JCAMP file"; }
$xmlfile.=" ".$ldrs['##SPECTROMETERDATASYSTEM']."\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
if($ldrs['##RESOLUTION']=="") { $ldrs['##RESOLUTION']="Not available in JCAMP file"; }
$xmlfile.=" ".$ldrs['##RESOLUTION']."\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.=" ".date(DATE_ISO8601)."\n";
$xmlfile.=" \n";
$xmlfile.=" JCAMP to AnIML converter 1.0 Stuart J. Chalk http://fad.coas.unf.edu/animl/jcamp/jcamp2animl.php\n";
$xmlfile.=" \n";
$xmlfile.=" created\n";
$xmlfile.=" Conversion from JCAMP-DX file - ".str_replace("../temp/","",$_GET['file'])."\n";
$xmlfile.=" The following is the complete header of the JCAMP file that this XML file was converted from: ".$header."\n";
$xmlfile.=" \n";
$xmlfile.=" \n";
$xmlfile.="\n";
// Generic function to format temperature units in AnIML - offset is space indentation of text
function tempunit($unit,$offest)
{
$o=str_pad(" "," ",$offset-1);
if($unit=="°F")
{
$xmlfile.=$o."\n";
$xmlfile.=$o." K\n";
$xmlfile.=$o."\n";
}
elseif($unit=="°C")
{
$xmlfile.=$o."\n";
$xmlfile.=$o." K\n";
$xmlfile.=$o."\n";
}
elseif($unit=="K")
{
$xmlfile.=$o."\n";
$xmlfile.=$o." K\n";
$xmlfile.=$o."\n";
}
}
// Generic function to format pressure units in AnIML - offset is space indentation of text
function pressunit($unit,$offest)
{
$o=str_pad(" "," ",$offset-1);
if($unit=="Pa")
{
$xmlfile.=$o."\n";
$xmlfile.=$o." m\n";
$xmlfile.=$o." kg\n";
$xmlfile.=$o." s\n";
$xmlfile.=$o."\n";
}
elseif($unit=="atm");
{
$xmlfile.=$o."\n";
$xmlfile.=$o." m\n";
$xmlfile.=$o." kg\n";
$xmlfile.=$o." s\n";
$xmlfile.=$o."\n";
}
// Other units that need to be added?
}
?>