examples/test_io/test_io.c

Go to the documentation of this file.
00001 /*
00002    libit - Library for basic source and channel coding functions
00003    Copyright (C) 2005-2005 Vivien Chappelier, Herve Jegou
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /*------------------------------------------------------------*/
00021 /** @file test_io.c Test program for Input/Output functions   */
00022 /*------------------------------------------------------------*/
00023 
00024 #include <stdio.h>
00025 #include <stdarg.h>
00026 
00027 #include <it/types.h>
00028 #include <it/vec.h>
00029 #include <it/io.h>
00030 
00031 int main ()
00032 {
00033   int  d1 = 5, d2 = 7;
00034   double f1 = 3.14159, f2 = -5.6;
00035   cplx mycplx;
00036   char *s = "toto";
00037   char *char_vec = " [ 1.23, 45.6,-78, 9 ,10 ]";
00038   char *char_ivec = " [ 1,-478, 9 ,-10 ]";
00039   char *char_cplx = "i";
00040   char c = 'x';
00041 
00042 
00043   vec  v = vec_new_arithm (1, -2, 15);
00044   ivec iv = ivec_new_geom (1, 2, 8);
00045   bvec bv = bvec_new_ones (4), bvr;
00046 
00047   vec  v2 = vec_new_string ("35 2.3 634 -34;");
00048   ivec iv2 = ivec_new_string (" 35 2 634,-34");
00049   bvec bv2 = bvec_new_string ("[35 2 23 34] ");
00050   cvec cv2 = cvec_new_string ("[35+1i -2+3i 634i i -34 -i +1+i] ");
00051 
00052   /* Read and print a complex number */
00053   it_read_cplx (char_cplx, &mycplx);
00054   it_printf ("mycplx = %z\n", mycplx);
00055 
00056   /* Display usual types of variables  */
00057   printf ("d1=%5d\nd2=%d\nf1=%2.5g\nf2=%3f\ns=%s\nc=%c\n\n",
00058     d1, d2, f1, f2, s, c);
00059 
00060   it_printf ("d1=%5d\nd2=%d\nf1=%2.5g\nf2=%3f\ns=%s\nc=%c\n\n",
00061        d1, d2, f1, f2, s, c);
00062 
00063   /* Display vector variables  */
00064   it_printf ("v=$.3f\niv=$d\nbv=$b\n", v, iv, bv);
00065 
00066   /* Read a vector */
00067   it_read_vec (char_vec, &v);
00068   it_read_ivec (char_ivec, &iv);
00069   it_printf ("read string %s\nv = $v\n", char_vec, v);
00070   it_printf ("read string %s\niv = $i\n", char_ivec, iv);
00071 
00072   it_printf ("v2 = $v\n", v2);
00073   it_printf ("iv2 = $i\n", iv2);
00074   it_printf ("bv2 = $b\n", bv2);
00075   it_printf ("cv2 = $.3z\n", cv2);
00076 
00077   bvec_push (bv, 1);
00078   bvec_push (bv, 0);
00079   bvec_push (bv, 1);
00080   bvec_push (bv, 0);
00081   bvec_push (bv, 1);
00082   bvec_file_write_bits ("test_io_bvec", bv);
00083   bvr = bvec_file_read_bits ("test_io_bvec", bvec_length (bv));
00084   it_printf ("bvr = $b\n", bvr);
00085 
00086   vec_delete (v);
00087   ivec_delete (iv);
00088   bvec_delete (bv);
00089   vec_delete (v2);
00090   ivec_delete (iv2);
00091   bvec_delete (bv2);
00092   bvec_delete (bvr);
00093   return 0;
00094 }

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau