Sample C#
// ASTAR / CSharp // csc /r:AStar.dll /out:sample.cs.exe sample.cs using System; using AStar.Cif; using AStar.Common; namespace Sample.CSharp { public class Program { public static void Main() { string fn = "../data/fa3203.cif"; Console.WriteLine("Read the CIF file: {0}", fn); CifPack pack = new CifPack(fn); foreach(CifBlock block in pack) { Console.WriteLine("[Block: {0}]", block.Name); if(block.Contains("_chemical_formula_sum")) { Console.WriteLine(" Formula: {0}", block["_chemical_formula_sum"].Value); Console.WriteLine(" atom U(iso/eq) s.u."); foreach(CifLoopRow row in block.GetLoop("_atom_site_U_iso_or_equiv").Rows) { CifValue val = row["_atom_site_U_iso_or_equiv"]; Console.WriteLine(" {0,-4} {1,-9:F6} ({2:F6})", row["_atom_site_label"], val.ToNumber(), val.ToMeasurand().Su); } } } CifBlock test = new CifBlock("TEST"); pack.Add(test); test.CreateField("_astar_test_description", "CSharp"); test.CreateField("_astar_test_number", 50); test.CreateField("_astar_test_measurand", new Measurand(2.3533, 0.0022)); test.Add(new CifLoop("_astar_test_la", "_astar_test_lb")); test["_astar_test_la"].List = new CifValueList("AAA", "AAB", "ABB"); test["_astar_test_lb"].List = new CifValueList("BBB", "BBA", "BAA"); fn = "output/fa3203_test.cif"; Console.WriteLine("Write the CIF file: {0}", fn); pack.Save(fn); } } }
Sample VB.Net
' ASTAR / VB.Net ' vbc /r:AStar.dll /out:sample.vb.exe sample.vb Imports System Imports AStar.Cif Imports AStar.Common Namespace Sample.VBNet Public Class Program Public Shared Sub Main() Dim fn As String = "../data/fa3203.cif" Console.WriteLine("Read the CIF file: {0}", fn) Dim pack As New CifPack(fn) For Each block As CifBlock In pack Console.WriteLine("[Block: {0}]", block.Name) If block.Contains("_chemical_formula_sum") Then Console.WriteLine(" Formula: {0}", block("_chemical_formula_sum").Value) Console.WriteLine(" atom U(iso/eq) s.u.") For Each row As CifLoopRow In block.GetLoop("_atom_site_U_iso_or_equiv").Rows Dim val As CifValue = row("_atom_site_U_iso_or_equiv") Console.WriteLine(" {0,-4} {1,-9:F6} ({2:F6})", row("_atom_site_label"), val.ToNumber(), val.ToMeasurand().Su) Next End If Next Dim test As CifBlock = New CifBlock("TEST") pack.Add(test) test.CreateField("_astar_test_description", "VB.net") test.CreateField("_astar_test_number", 50) test.CreateField("_astar_test_measurand", New Measurand(2.3533, 0.0022)) test.Add(New CifLoop("_astar_test_la", "_astar_test_lb")) test("_astar_test_la").List = New CifValueList("AAA", "AAB", "ABB") test("_astar_test_lb").List = New CifValueList("BBB", "BBA", "BAA") fn = "output/fa3203_test.cif" Console.WriteLine("Write the CIF file: {0}", fn) pack.Save(fn) End Sub End Class End Namespace
Sample Python (IronPython)
# ASTAR / IronPython # ipy sample.py import clr clr.AddReference('AStar.dll') from AStar.Cif import * from AStar.Common import Measurand fn = '../data/fa3203.cif' print 'Read the CIF file: %s' % fn pack = CifPack(fn) for block in pack: print '[Block: %s]' % block.Name if block.Contains('_chemical_formula_sum'): print ' Formula: %s' % block['_chemical_formula_sum'].Value print ' atom U(iso/eq) s.u.' for row in block.GetLoop('_atom_site_U_iso_or_equiv').Rows: val = row['_atom_site_U_iso_or_equiv'] print ' %-4s %-9f (%f)' % (row['_atom_site_label'], val.ToNumber(), val.ToMeasurand().Su) test = CifBlock('TEST') pack.Add(test) test.CreateField('_astar_test_description', 'PYthon') test.CreateField('_astar_test_number', 50) test.CreateField('_astar_test_measurand', Measurand(2.3533, 0.0022)) test.Add(CifLoop('_astar_test_la', '_astar_test_lb')) test['_astar_test_la'].List = CifValueList('AAA', 'AAB', 'ABB') test['_astar_test_lb'].List = CifValueList('BBB', 'BBA', 'BAA') fn = 'output/fa3203_test.cif' print 'Write the CIF file: %s' % fn pack.Save(fn)
Sample Ruby (IronRuby)
# ASTAR / IronRuby # ir sample.rb require 'AStar.dll' include AStar::Cif include AStar::Common fn = '../data/fa3203.cif' puts("Read the CIF file: #{fn}") pack = CifPack.new(fn) for block in pack do printf("[Block: %s]\n", block.Name) if block.Contains('_chemical_formula_sum') then printf(" Formula: %s\n", block['_chemical_formula_sum'].Value) print(" atom U(iso/eq) s.u.\n") for row in block.GetLoop('_atom_site_U_iso_or_equiv').Rows do val = row['_atom_site_U_iso_or_equiv'] printf(" %-4s %-9f (%f)\n", row['_atom_site_label'], val.ToNumber(), val.ToMeasurand().Su) end end end test = CifBlock.new('TEST') pack.Add(test) test.CreateField('_astar_test_description', CifValue.new('RuBy')) test.CreateField('_astar_test_number', CifValue.new(50)) test.CreateField('_astar_test_measurand', Measurand.new(2.3533, 0.0022)) pack['TEST'].Add(CifLoop.new('_astar_test_la', '_astar_test_lb')) test['_astar_test_la'].List = CifValueList.new('AAA', 'AAB', 'ABB') test['_astar_test_lb'].List = CifValueList.new('BBB', 'BBA', 'BAA') fn = 'output/fa3203_test.cif' puts("Write the CIF file: #{fn}") pack.Save(fn)
Sample F#
(* ASTAR / FSharp *) (* fsc -r:AStar.dll -o sample.fs.exe sample.fs *) (* for fsi / fsc: *) (* with the switch: -r:AStar.dll *) (* or for fsi interactive or in a .fsx script: *) (* #r "AStar.dll" *) open AStar.Cif open AStar.Common let fn_i = "../data/fa3203.cif" printfn "Read the CIF file: %s" fn_i let pack = CifPack(fn_i) for block in pack do printfn "Formula: %s" block.Name if block.Contains("_chemical_formula_sum") then printfn " Formula: %s" (pack.["I"].["_chemical_formula_sum"].Value.ToString()) printfn " atom U(iso/eq) s.u." for row in block.GetLoop("_atom_site_U_iso_or_equiv").Rows do let v = row.["_atom_site_U_iso_or_equiv"] printfn " %-4s %-9f (%f)" (row.["_atom_site_label"].ToString()) (v.ToNumber()) (v.ToMeasurand().Su) let test = CifBlock("TEST") pack.Add(test) test.CreateField("_astar_test_description", CifValue("FSharp")) test.CreateField("_astar_test_number", CifValue(50L)) test.CreateField("_astar_test_measurand", CifValue(Measurand(2.3533, 0.0022))) test.Add(CifLoop("_astar_test_la", "_astar_test_lb")) test.["_astar_test_la"].List <- CifValueList("AAA", "AAB", "ABB") test.["_astar_test_lb"].List <- CifValueList("BBB", "BBA", "BAA") let fn_o = "output/fa3203_test.cif" printfn "Write the CIF file: %s" fn_o pack.Save(fn_o)
Sample BOO
# ASTAR / BOO # booc -r:AStar.dll -o:sample.boo.exe sample.boo # - or - # booi sample.boo import System # import AStar.Cif # import AStar.Common # for booi: import AStar.Cif from 'AStar.dll' import AStar.Common from 'AStar.dll' fn = '../data/fa3203.cif' Console.WriteLine('Read the CIF file: {0}', fn) pack = CifPack(fn) for block as CifBlock in pack: Console.WriteLine('[Block: {0}]', block.Name) if block.Contains('_chemical_formula_sum'): Console.WriteLine(' Formula: {0}', block['_chemical_formula_sum'].Value) Console.WriteLine(' atom U(iso/eq) s.u.') for row as CifLoopRow in block.GetLoop('_atom_site_U_iso_or_equiv').Rows: val as CifValue = row['_atom_site_U_iso_or_equiv'] Console.WriteLine(' {0,-4} {1,-9:F6} ({2:F6})', row['_atom_site_label'], val.ToNumber(), val.ToMeasurand().Su) test = CifBlock('TEST') pack.Add(test) test.CreateField('_astar_test_description', CifValue('BOO')) test.CreateField('_astar_test_number', 50) test.CreateField('_astar_test_measurand', Measurand(2.3533, 0.0022)) test.Add(CifLoop('_astar_test_la', '_astar_test_lb')) test['_astar_test_la'].List = CifValueList('AAA', 'AAB', 'ABB') test['_astar_test_lb'].List = CifValueList('BBB', 'BBA', 'BAA') fn = 'output/fa3203_test.cif' Console.WriteLine('Write the CIF file: {0}', fn) pack.Save(fn)
Sample JScript.Net
// ASTAR / JS.Net // jsc /r:AStar.dll /out:sample.js.exe sample.js import System; import AStar.Cif; import AStar.Common; var fn : String = "../data/fa3203.cif"; Console.WriteLine("Read the CIF file: {0}", fn); var pack : CifPack = new CifPack(fn); for(var block : CifBlock in pack) { Console.WriteLine("[Block: {0}]", block.Name); if(block.Contains("_chemical_formula_sum")) { Console.WriteLine(" Formula: {0}", block["_chemical_formula_sum"].Value); Console.WriteLine(" atom U(iso/eq) s.u."); // JS.Net does not support IEnumerable<T> / .Rows. for(var i : int = 0, loop = block.GetLoop("_atom_site_U_iso_or_equiv"); i < loop.RowCount; i++) { var val : CifValue = loop[i, "_atom_site_U_iso_or_equiv"]; Console.WriteLine(" {0,-4} {1,-9:F6} ({2:F6})", loop[i, "_atom_site_label"], val.ToNumber(), val.ToMeasurand().Su); } } } var test : CifBlock = new CifBlock("TEST"); pack.Add(test); test.CreateField("_astar_test_description", new CifValue("JS.net")); test.CreateField("_astar_test_number", new CifValue(50)); test.CreateField("_astar_test_measurand", new Measurand(2.3533, 0.0022)); pack["TEST"].Add(new CifLoop("_astar_test_la", "_astar_test_lb")); test["_astar_test_la"].List = new CifValueList("AAA", "AAB", "ABB"); test["_astar_test_lb"].List = new CifValueList("BBB", "BBA", "BAA"); fn = "output/fa3203_test.cif"; Console.WriteLine("Write the CIF file: {0}", fn); pack.Save(fn);