first working trial

fixed bug in write iv file. Need to search solutions for array (dynamic
memory or workaround). some functions not implemented yet