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 trunk/AGRIF/LIB – NEMO

source: trunk/AGRIF/LIB/WriteInFile.c @ 663

Last change on this file since 663 was 663, checked in by opalod, 17 years ago

RB: update CONV

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 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.6                                                                */
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
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      strncpy (temp, s, 60);
65      strcpy (&temp[60], "\0");
66
67      tmp = strrchr(temp, '+');
68
69      if ( !tmp || strlen(tmp) == 60 ) tmp = strrchr(temp, '-');
70      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, '/');
71      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, '*');
72      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, '%');
73      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, ',');
74      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, ':');
75      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, ')');
76      if ( tmp )
77      {
78         size = strlen(tmp);
79      }
80      else
81      {
82         size = 0 ;
83      }
84
85      strcpy (&temp[60-size], "\0");
86
87      if ( retour77 == 0 ) fprintf (filout, "     & %s  &\n", temp);
88      else fprintf (filout, "     & %s  \n", temp);
89      colnum=0;
90      tofich_reste (filout, (char *) &s[60-size],returnlineornot);
91    }
92}
93
94/******************************************************************************/
95/*                            tofich                                          */
96/******************************************************************************/
97/* This subroutine is used to write the string s into the fileout             */
98/******************************************************************************/
99void tofich (FILE * filout, char *s, int returnlineornot)
100{
101  char temp[61];
102  char *tmp;
103  int size;
104
105  if (strlen (s) <= 60)
106    {
107      if ( returnlineornot == 0 ) fprintf (filout, "      %s", s);
108      else if ( returnlineornot == 2 ) fprintf (filout, "%s", s);
109      else if ( returnlineornot == 3 ) fprintf (filout, "%s\n", s);
110      else                             fprintf (filout, "      %s\n", s);
111      if ( returnlineornot == 0 || returnlineornot == 2 )
112                                                      colnum=colnum+strlen(s)+6;
113      else colnum=0;
114    }
115  else
116    {
117      strncpy (temp, s, 60);
118      strcpy (&temp[60], "\0");
119
120      tmp = strrchr(temp, ',');
121      if ( !tmp  || strlen(tmp) == strlen(temp) ) tmp = strrchr(temp, '+');
122      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '-');
123      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '/');
124      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '*');
125      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '%');
126      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, ',');
127      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, ':');
128      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, ')');
129      if ( tmp )
130      {
131         size = strlen(tmp);
132      }
133      else
134      {
135         size = 0 ;
136      }
137
138      strcpy (&temp[60-size], "\0");
139
140      if ( retour77 == 0 ) fprintf (filout, "      %s  &\n", temp);
141      else fprintf (filout, "      %s  \n", temp);
142      colnum=0;
143      tofich_reste (filout, (char *) &s[60-size], returnlineornot);
144    }
145}
146
147/******************************************************************************/
148/*                       tofich_blanc                                         */
149/******************************************************************************/
150/* This subroutine is used to write size blank into the fileout               */
151/******************************************************************************/
152void tofich_blanc (FILE * filout, int size)
153{
154  int i;
155
156  if (size <= 65) fprintf (filout, "%*s\n",size,EmptyChar);
157  else
158  {
159      i=0;
160      do
161      {
162         fprintf (filout, "%*s\n",65,EmptyChar);
163         i = i+1;
164      } while ( i <= size / 65 );
165         fprintf (filout, "%*s\n",size%65,EmptyChar);
166  }
167
168}
169/******************************************************************************/
170/*                       tofich_line                                          */
171/******************************************************************************/
172/* This subroutine is used to write size blank into the fileout               */
173/******************************************************************************/
174void tofich_line (FILE * filout, int size, int long position)
175{
176  int i;
177  int retour;
178
179  if (size <= 65) fprintf (filout, "%*s",size,EmptyChar);
180  else
181  {
182      i=0;
183      do
184      {
185         fprintf (filout, "%*s",65,EmptyChar);
186         i = i+1;
187      } while ( i <= size / 65 );
188         fprintf (filout, "%*s",size%65,EmptyChar);
189  }
190
191   if ( !strstr(motparse1,"\n") ) retour=0;
192   else retour=1;
193
194   fseek(filout,position,SEEK_SET);
195   if (retour == 1 ) fprintf (filout, "\n");
196
197}
198
199
200/******************************************************************************/
201/*                           RemoveWordSET_0                                  */
202/******************************************************************************/
203/* This subroutine is used to remove a sentence in the file filout            */
204/******************************************************************************/
205void RemoveWordSET_0(FILE * filout, long int position, long int sizetoremove)
206{
207   if ( firstpass == 0 && couldaddvariable == 1 )
208   {
209      fseek(filout,position,SEEK_SET);
210      tofich_line(filout,sizetoremove,position);
211   }
212}
213
214
215/******************************************************************************/
216/*                         RemoveWordCUR_0                                    */
217/******************************************************************************/
218/* This subroutine is used to remove a sentence in the file filout            */
219/******************************************************************************/
220void RemoveWordCUR_0(FILE * filout, long int position, long int sizetoremove)
221{
222   if ( firstpass == 0  && couldaddvariable == 1 )
223   {
224      fseek(filout,position,SEEK_CUR);
225      tofich_blanc(filout,sizetoremove);
226   }
227}
Note: See TracBrowser for help on using the repository browser.