1 | /* |
---|
2 | Copyright or © or Copr. MMSA team, LOCEAN Paris (2011) |
---|
3 | |
---|
4 | This software is a framework for variational data assimilation in |
---|
5 | numerical models. |
---|
6 | |
---|
7 | This software is governed by the CeCILL license under French law and |
---|
8 | abiding by the rules of distribution of free software. You can use, |
---|
9 | modify and/ or redistribute the software under the terms of the CeCILL |
---|
10 | license as circulated by CEA, CNRS and INRIA at the following URL |
---|
11 | "http://www.cecill.info". |
---|
12 | |
---|
13 | As a counterpart to the access to the source code and rights to copy, |
---|
14 | modify and redistribute granted by the license, users are provided only |
---|
15 | with a limited warranty and the software's author, the holder of the |
---|
16 | economic rights, and the successive licensors have only limited |
---|
17 | liability. |
---|
18 | |
---|
19 | In this respect, the user's attention is drawn to the risks associated |
---|
20 | with loading, using, modifying and/or developing or reproducing the |
---|
21 | software by the user in light of its specific status of free software, |
---|
22 | that may mean that it is complicated to manipulate, and that also |
---|
23 | therefore means that it is reserved for developers and experienced |
---|
24 | professionals having in-depth computer knowledge. Users are therefore |
---|
25 | encouraged to load and test the software's suitability as regards their |
---|
26 | requirements in conditions enabling the security of their systems and/or |
---|
27 | data to be ensured and, more generally, to use and operate it in the |
---|
28 | same conditions as regards security. |
---|
29 | |
---|
30 | The fact that you are presently reading this means that you have had |
---|
31 | knowledge of the CeCILL license and that you accept its terms. |
---|
32 | |
---|
33 | YAO website : http://www.locean-ipsl.upmc.fr/~yao/ |
---|
34 | Contact : yao@locean-ipsl.upmc.fr |
---|
35 | */ |
---|
36 | // Contributor : Charles Sorror |
---|
37 | |
---|
38 | //gcc ylmodf.c -Wall -o ylmodf |
---|
39 | |
---|
40 | #include <stdlib.h> |
---|
41 | #include <stdio.h> |
---|
42 | #include <string.h> |
---|
43 | |
---|
44 | #define BUFSIZE 2048 |
---|
45 | #define LG_MAX_NAME 24 |
---|
46 | #define LG_STR80 80 |
---|
47 | |
---|
48 | FILE *fpin, *fpout; |
---|
49 | char buffer[BUFSIZE+1]; |
---|
50 | int nbenrlus; |
---|
51 | int nbitem; |
---|
52 | char modname[LG_MAX_NAME+1]; |
---|
53 | int nbi, nbo, mode, prodlev; |
---|
54 | int wi; |
---|
55 | char cdesys[LG_STR80+1]; |
---|
56 | |
---|
57 | //========================================================== |
---|
58 | int main(int argc, char *argv[]) |
---|
59 | { //syntaxe: ylmodf filein fileout [mode] |
---|
60 | // mode determine le mode d'ecriture du fichier filout : |
---|
61 | // avec mode = 1, >> dans filout |
---|
62 | // mode = 0, raz de filout |
---|
63 | // mais attention, ce mode est positionne selon en priorite : |
---|
64 | // - le 2eme caratere du 1er enregistrement de filin a condition |
---|
65 | // qu'il commence par un diese et qu'il valle 0 ou 1 |
---|
66 | // - le mode passe en parametre qui doit valoir 0 ou 1, |
---|
67 | // - et par defaut, mode = 1 |
---|
68 | printf("\n"); |
---|
69 | |
---|
70 | /* debut : verif arg, ouverture fichier ... */ |
---|
71 | if (argc<3 || argc>4) |
---|
72 | { printf (" > ylmodf: syntaxe error: ylmodf file_in file_out [mode]\n"); |
---|
73 | exit(-9); |
---|
74 | } |
---|
75 | if ((fpin = fopen(argv[1], "r")) <= 0) |
---|
76 | { printf (" > ylmodf: problem when opening %s \n", argv[1]); |
---|
77 | exit(-9); |
---|
78 | } |
---|
79 | if (argc==3) mode = 1; |
---|
80 | if (argc==4) mode = atoi(argv[3]); |
---|
81 | if (mode!=0 && mode!=1) |
---|
82 | { printf(" > ylmodf: error on mode value (%i), must 0 to RAZ or 1 to CONCAT\n", mode); |
---|
83 | } |
---|
84 | /*-------------------------- |
---|
85 | if (mode==0) |
---|
86 | { if ((fpout = fopen(argv[2], "w")) <= 0) |
---|
87 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
88 | exit(-9); |
---|
89 | } |
---|
90 | } |
---|
91 | else //=>mode==1 |
---|
92 | { if ((fpout = fopen(argv[2], "r")) <= 0) |
---|
93 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
94 | exit(-9); |
---|
95 | } |
---|
96 | } |
---|
97 | fclose(fpout); //on n'a plus besoin ici de file out |
---|
98 | */ |
---|
99 | |
---|
100 | //------------------------------------------------------------------- |
---|
101 | nbenrlus=0; |
---|
102 | while ( (fgets(buffer, BUFSIZE+1, fpin)) != NULL) |
---|
103 | { ++nbenrlus; |
---|
104 | |
---|
105 | nbitem=sscanf(buffer, "%s %i %i %i", modname, &nbi, &nbo, &prodlev); |
---|
106 | //printf(" %i> %s %i %i [%i] \n", nbitem, modname, nbi, nbo, prodlev); |
---|
107 | |
---|
108 | if (nbenrlus==1) |
---|
109 | { //si dans l'entete (i.e 1er enreg) du fichier on trouve que le |
---|
110 | // 1er caractere du 1er token est un '#' (indication de commentaire), |
---|
111 | // et que le 2eme token correspond a O ou 1, alors c'est |
---|
112 | // ca qui prime pour determiner le mode 'w' ou 'r' |
---|
113 | if (nbitem >=2 && modname[0]=='#' && (nbi==0 || nbi==1)) |
---|
114 | { mode=nbi; |
---|
115 | //-------------------------- |
---|
116 | if (mode==0) |
---|
117 | { if ((fpout = fopen(argv[2], "w")) <= 0) |
---|
118 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
119 | exit(-9); |
---|
120 | } |
---|
121 | } |
---|
122 | else //=>mode==1 |
---|
123 | { if ((fpout = fopen(argv[2], "r")) <= 0) |
---|
124 | { if ((fpout = fopen(argv[2], "w")) <= 0) |
---|
125 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
126 | exit(-9); |
---|
127 | } |
---|
128 | } |
---|
129 | } |
---|
130 | fclose(fpout); //on n'a plus besoin ici de file out |
---|
131 | //-------------------------- |
---|
132 | continue; |
---|
133 | } |
---|
134 | else //alors seulement le mode passed en parametre ou par defaut est utilise |
---|
135 | { //-------------------------- |
---|
136 | if (mode==0) |
---|
137 | { if ((fpout = fopen(argv[2], "w")) <= 0) |
---|
138 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
139 | exit(-9); |
---|
140 | } |
---|
141 | } |
---|
142 | else //=>mode==1 |
---|
143 | { if ((fpout = fopen(argv[2], "r")) <= 0) |
---|
144 | { if ((fpout = fopen(argv[2], "w")) <= 0) |
---|
145 | { printf (" > ylmodf: problem when opening %s \n", argv[2]); |
---|
146 | exit(-9); |
---|
147 | } |
---|
148 | } |
---|
149 | } |
---|
150 | fclose(fpout); //on n'a plus besoin ici de file out |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | if (nbitem<=0) continue; //ligne vide |
---|
155 | if (modname[0]=='#') continue; //commentaire |
---|
156 | |
---|
157 | //dans un enregistrement, on doit au moins trouver modname nbi nbo |
---|
158 | if (nbitem<3) |
---|
159 | { printf(" < %s", buffer); |
---|
160 | printf(" > ylmodf: uncomplete ligne; skeep to the next\n"); |
---|
161 | continue; |
---|
162 | } |
---|
163 | |
---|
164 | //on verifie que le module existe bien |
---|
165 | if ((fpout = fopen(modname, "r")) <= 0) //on essaye avec le nom tel quel |
---|
166 | { //sinon on essaye en rajoutant .h |
---|
167 | strcat(modname, ".h"); |
---|
168 | if ((fpout = fopen(modname, "r")) <= 0) |
---|
169 | { printf (" > ylmodf: problem when opening %s \n", modname); |
---|
170 | printf (" skeep to next module\n\n"); |
---|
171 | continue; |
---|
172 | } |
---|
173 | } |
---|
174 | fclose(fpout); //c'etait juste pour verifier |
---|
175 | |
---|
176 | //on cree la commande d'appel a la procedure de derivation automatique |
---|
177 | //pour le module: YdfA fileout modname nbi nbo prodlev |
---|
178 | sprintf(cdesys, "YdfA %s %s %i %i %i\n", argv[2], modname, nbi, nbo, prodlev); |
---|
179 | system (cdesys); |
---|
180 | } |
---|
181 | |
---|
182 | fclose(fpin); |
---|
183 | printf("\n"); |
---|
184 | return(0); |
---|
185 | } |
---|
186 | //========================================================= |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | |
---|