1 | /* |
---|
2 | Copyright or © or Copr. Charles SORROR (2011/01/13) |
---|
3 | |
---|
4 | mail of the author: cslod@locean-ipsl.upmc.fr |
---|
5 | |
---|
6 | This software is a framework for variational data assimilation in |
---|
7 | numerical models. |
---|
8 | |
---|
9 | This software is governed by the CeCILL license under French law and |
---|
10 | abiding by the rules of distribution of free software. You can use, |
---|
11 | modify and/ or redistribute the software under the terms of the CeCILL |
---|
12 | license as circulated by CEA, CNRS and INRIA at the following URL |
---|
13 | "http://www.cecill.info". |
---|
14 | |
---|
15 | As a counterpart to the access to the source code and rights to copy, |
---|
16 | modify and redistribute granted by the license, users are provided only |
---|
17 | with a limited warranty and the software's author, the holder of the |
---|
18 | economic rights, and the successive licensors have only limited |
---|
19 | liability. |
---|
20 | |
---|
21 | In this respect, the user's attention is drawn to the risks associated |
---|
22 | with loading, using, modifying and/or developing or reproducing the |
---|
23 | software by the user in light of its specific status of free software, |
---|
24 | that may mean that it is complicated to manipulate, and that also |
---|
25 | therefore means that it is reserved for developers and experienced |
---|
26 | professionals having in-depth computer knowledge. Users are therefore |
---|
27 | encouraged to load and test the software's suitability as regards their |
---|
28 | requirements in conditions enabling the security of their systems and/or |
---|
29 | data to be ensured and, more generally, to use and operate it in the |
---|
30 | same conditions as regards security. |
---|
31 | |
---|
32 | The fact that you are presently reading this means that you have had |
---|
33 | knowledge of the CeCILL license and that you accept its terms. |
---|
34 | */ |
---|
35 | |
---|
36 | #include <stdio.h> |
---|
37 | #include <stdlib.h> |
---|
38 | |
---|
39 | #define BUFSIZE 80 |
---|
40 | |
---|
41 | int main (int argc, char *argv[]) |
---|
42 | { /* . Syntaxe : yf2m f1 mf ncol |
---|
43 | . Purpose : file (f1) to matlab matrice file (mf) ; |
---|
44 | ncol is the number of column of the matrice. |
---|
45 | . Compilation : cc -Wall -o yf2m yf2m.c */ |
---|
46 | |
---|
47 | FILE *f1, *mf; |
---|
48 | char buf[BUFSIZE+1]; |
---|
49 | int ncol; |
---|
50 | int icol, nblig; |
---|
51 | |
---|
52 | if ((f1 = fopen(argv[1], "r")) <= 0) |
---|
53 | { printf ("yao file %s not found !!!\n", argv[1]); |
---|
54 | exit(0); |
---|
55 | } |
---|
56 | if ((mf = fopen(argv[2], "w")) <= 0) |
---|
57 | { printf ("failed while opening matlab file %s !!!\n", argv[2]); |
---|
58 | exit(0); |
---|
59 | } |
---|
60 | |
---|
61 | ncol = atoi(argv[3]); |
---|
62 | if (ncol<=0) |
---|
63 | { printf ("bad value for ncol \n"); |
---|
64 | exit(0); |
---|
65 | } |
---|
66 | |
---|
67 | icol=0; nblig=0; |
---|
68 | //while (fgets (buf, BUFSIZE, f1) != NULL) |
---|
69 | while (fscanf(f1, "%s", buf) > 0) |
---|
70 | { |
---|
71 | fprintf(mf, "%s", buf); //printf("%s", buf); |
---|
72 | icol = (icol+1)%ncol; |
---|
73 | if (icol) fprintf(mf, "\t"); //printf("\t"); |
---|
74 | else |
---|
75 | { fprintf(mf, "\n"); //printf("\n"); |
---|
76 | ++nblig; |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | if (icol != 0) |
---|
81 | printf("\nyf2m: Warning : last line not complete : only %i elt instead of %i \n", icol, ncol); |
---|
82 | |
---|
83 | printf ("yf2m: %i line resumed\n", nblig); |
---|
84 | return(0); |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | |
---|