PK.LABPKEY
A^prefix,
"PATS",@1,
END;

[1]::PATS
/ARGV[1]^DT,
2^nr,
DO{nr</ARGC 1,
   /ARGV[nr]^ACT,
   ?(A)AAAI[ACT]^aa,
   "PTH",@2,
   nr+1^nr};

[2]::PTH
""^Q,
DO{"NEXT.SPEC",@3 "SEND",@4};

[3]::NEXT.SPEC
>(?(SP)SPSP[aa,Q],sps)^Q;

[4]::SEND
IF{$(SP)SPS[sps]|3<DT;
   +$(SP)SPS[sps]FS[""]_.=.;
   "<Document>"^!,
   "<InstanceMnemonic>"_prefix_sps_"</InstanceMnemonic>"^!,
   "append x to key because t0 may be empty",
   "<Key>"_"x"_$(SP)SPS[sps]A|10_"</Key>"^!,
   "<PersonMnemonic>"_$(A)AA[aa]|3_"</PersonMnemonic>"^!,
   "<EventEndDateTime>"_%(Z)date.in.magic($(SP)SPS[sps]|13)_%(Z)time.out($(SP)SPS[sps]|13)_"</EventEndDateTime>"^!,
   "<EventSetMnemonic>AP</EventSetMnemonic>"^!,
   "</Document>"^!};

