New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
WriteInFile.c in branches/UKMO/dev_r5518_sshiau_off/NEMOGCM/EXTERNAL/AGRIF/LIB – NEMO

source: branches/UKMO/dev_r5518_sshiau_off/NEMOGCM/EXTERNAL/AGRIF/LIB/WriteInFile.c @ 7697

Last change on this file since 7697 was 7697, checked in by anaguiar, 7 years ago

Clear svn keywords

File size: 9.9 KB
Line 
1/******************************************************************************/
2/*                                                                            */
3/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
4/*                                                                            */
5/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
6/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
7/* This software is governed by the CeCILL-C 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-C   */
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-C license and that you accept its terms.           */
32/******************************************************************************/
33/* version 1.7                                                                */
34/******************************************************************************/
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include "decl.h"
39
40/******************************************************************************/
41/*                            tofich_reste                                    */
42/******************************************************************************/
43/* This subroutine is used to write the string s into the fileout             */
44/******************************************************************************/
45void tofich_reste (FILE * filout, char *s,int returnlineornot)
46{
47  char temp[61];
48  char *tmp;
49  int size;
50  int val_min;
51
52  if (strlen (s) <= 60)
53    {
54      if ( returnlineornot == 0 ) fprintf (filout, "     &%s", s);
55      else if ( returnlineornot == 2 ) fprintf (filout, "&%s", s);
56      else if ( returnlineornot == 3 ) fprintf (filout, "&%s\n", s);
57      else                             fprintf (filout, "     &%s\n", s);
58      if ( returnlineornot == 0 ||
59           returnlineornot == 2 ) colnum=colnum+strlen(s)+6;
60      else colnum=0;
61    }
62  else
63    {
64      val_min = 60;
65      strncpy (temp, s, 60);
66      strcpy (&temp[60], "\0");
67
68      tmp = strrchr(temp, '+');
69      if ( tmp )
70      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
71      tmp = strrchr(temp, '-');
72      if ( tmp )
73      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
74      tmp = strrchr(temp, '/');
75      if ( tmp )
76      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
77      tmp = strrchr(temp, '*');
78      if ( tmp )
79      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
80      tmp = strrchr(temp, '%');
81      if ( tmp )
82      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
83      tmp = strrchr(temp, ',');
84      if ( tmp )
85      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
86      tmp = strrchr(temp, ')');
87      if ( tmp )
88      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
89      tmp = strrchr(temp, '(');
90      if ( tmp )
91      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
92
93      size = val_min;
94
95      strcpy (&temp[60-size], "\0");
96
97      if ( retour77 == 0 ) fprintf (filout, "     &%s&\n", temp);
98      else fprintf (filout, "     &%s\n", temp);
99      colnum=0;
100      tofich_reste (filout, (char *) &s[60-size],returnlineornot);
101    }
102}
103
104/******************************************************************************/
105/*                            tofich                                          */
106/******************************************************************************/
107/* This subroutine is used to write the string s into the fileout             */
108/******************************************************************************/
109void tofich (FILE * filout, char *s, int returnlineornot)
110{
111  char temp[61];
112  char *tmp;
113  int size;
114  int val_min;
115
116  if (strlen (s) <= 60)
117    {
118      if ( returnlineornot == 0 ) fprintf (filout, "      %s", s);
119      else if ( returnlineornot == 2 ) fprintf (filout, "%s", s);
120      else if ( returnlineornot == 3 ) fprintf (filout, "%s\n", s);
121      else                             fprintf (filout, "      %s\n", s);
122      if ( returnlineornot == 0 || returnlineornot == 2 )
123                                                      colnum=colnum+strlen(s)+6;
124      else colnum=0;
125    }
126  else
127    {
128      val_min = 60;
129      strncpy (temp, s, 60);
130      strcpy (&temp[60], "\0");
131
132      tmp = strrchr(temp, '+');
133      if ( tmp )
134      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
135      tmp = strrchr(temp, '-');
136      if ( tmp )
137      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
138      tmp = strrchr(temp, '/');
139      if ( tmp )
140      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
141      tmp = strrchr(temp, '*');
142      if ( tmp )
143      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
144      tmp = strrchr(temp, '%');
145      if ( tmp )
146      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
147      tmp = strrchr(temp, ',');
148      if ( tmp )
149      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
150      tmp = strrchr(temp, ')');
151      if ( tmp )
152      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
153      tmp = strrchr(temp, '(');
154      if ( tmp )
155      if ( strlen(tmp) < val_min ) val_min = strlen(tmp);
156
157      size = val_min;
158
159      strcpy (&temp[60-size], "\0");
160
161      if ( retour77 == 0 ) fprintf (filout, "      %s&\n", temp);
162      else fprintf (filout, "      %s\n", temp);
163      colnum=0;
164      tofich_reste (filout, (char *) &s[60-size], returnlineornot);
165    }
166}
167
168/******************************************************************************/
169/*                       tofich_blanc                                         */
170/******************************************************************************/
171/* This subroutine is used to write size blank into the fileout               */
172/******************************************************************************/
173void tofich_blanc (FILE * filout, int size)
174{
175  int i;
176
177  if (size <= 65) fprintf (filout, "%*s\n",size,EmptyChar);
178  else
179  {
180      i=0;
181      do
182      {
183         fprintf (filout, "%*s\n",65,EmptyChar);
184         i = i+1;
185      } while ( i <= size / 65 );
186         fprintf (filout, "%*s\n",size%65,EmptyChar);
187  }
188
189}
190/******************************************************************************/
191/*                       tofich_line                                          */
192/******************************************************************************/
193/* This subroutine is used to write size blank into the fileout               */
194/******************************************************************************/
195void tofich_line (FILE * filout, int size, int long position)
196{
197  int i;
198  int retour;
199
200  if (size <= 65) fprintf (filout, "%*s",size,EmptyChar);
201  else
202  {
203      i=0;
204      do
205      {
206         fprintf (filout, "%*s",65,EmptyChar);
207         i = i+1;
208      } while ( i <= size / 65 );
209         fprintf (filout, "%*s",size%65,EmptyChar);
210  }
211
212   if ( !strstr(motparse1,"\n") ) retour=0;
213   else retour=1;
214
215   fseek(filout,position,SEEK_SET);
216   if (retour == 1 ) fprintf (filout, "\n");
217
218}
219
220
221/******************************************************************************/
222/*                           RemoveWordSET_0                                  */
223/******************************************************************************/
224/* This subroutine is used to remove a sentence in the file filout            */
225/******************************************************************************/
226void RemoveWordSET_0(FILE * filout, long int position, long int sizetoremove)
227{
228   if ( firstpass == 0 && couldaddvariable == 1 )
229   {
230      fseek(filout,position,SEEK_SET);
231      tofich_line(filout,sizetoremove,position);
232
233   }
234}
235
236
237/******************************************************************************/
238/*                         RemoveWordCUR_0                                    */
239/******************************************************************************/
240/* This subroutine is used to remove a sentence in the file filout            */
241/******************************************************************************/
242void RemoveWordCUR_0(FILE * filout, long int position, long int sizetoremove)
243{
244   if ( firstpass == 0  && couldaddvariable == 1 )
245   {
246      fseek(filout,position,SEEK_CUR);
247      tofich_blanc(filout,sizetoremove);
248
249   }
250}
Note: See TracBrowser for help on using the repository browser.