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 @ 396

Last change on this file since 396 was 396, checked in by opalod, 18 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
RevLine 
[396]1/******************************************************************************/
2/*                                                                            */
3/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
4/*                                                                            */
5/*     Copyright (C) 2005 Laurent Debreu (Laurent.Debreu@imag.fr)             */
6/*                        Cyril Mazauric (Cyril.Mazauric@imag.fr)             */
7/*                                                                            */
8/*     This program is free software; you can redistribute it and/or modify   */
9/*    it                                                                      */
10/*                                                                            */
11/*    This program is distributed in the hope that it will be useful,         */
12/*     but WITHOUT ANY WARRANTY; without even the implied warranty of         */
13/*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
14/*    GNU General Public License for more details.                            */
15/*                                                                            */
16/******************************************************************************/
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include "decl.h"
21
22/******************************************************************************/
23/*                            tofich_reste                                    */
24/******************************************************************************/
25/* This subroutine is used to write the string s into the fileout             */
26/******************************************************************************/
27/*                                                                            */
28/*                                                                            */
29/*                                                                            */
30/******************************************************************************/
31void tofich_reste (FILE * filout, char *s,int returnlineornot) 
32{
33  char temp[61];
34  char *tmp;
35  int size;
36
37
38  if (strlen (s) <= 60)
39    {
40      if ( returnlineornot == 0 ) fprintf (filout, "     & %s", s);
41      else fprintf (filout, "     & %s\n", s);
42      if ( returnlineornot == 0 ) colnum=colnum+strlen(s)+6;
43      else colnum=0;
44    }
45  else
46    {
47      strncpy (temp, s, 60);
48      strcpy (&temp[60], "\0");
49
50      tmp = strrchr(temp, '+');
51
52      if ( !tmp || strlen(tmp) == 60 ) tmp = strrchr(temp, '-');
53      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, '/');
54      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, '*');
55      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, '%');
56      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, ':');
57      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, ')');
58      if ( tmp )
59      {
60         size = strlen(tmp);
61      }
62      else
63      {
64         size = 0 ;
65      }
66
67      strcpy (&temp[60-size], "\0");
68
69      if ( fortran77 == 0 ) fprintf (filout, "     & %s  &\n", temp);
70      else fprintf (filout, "     & %s  \n", temp);
71      colnum=0;
72      tofich_reste (filout, (char *) &s[60-size],returnlineornot);
73    }
74}
75
76/******************************************************************************/
77/*                            tofich                                          */
78/******************************************************************************/
79/* This subroutine is used to write the string s into the fileout             */
80/******************************************************************************/
81/*                                                                            */
82/*                                                                            */
83/*                                                                            */
84/******************************************************************************/
85void tofich (FILE * filout, char *s, int returnlineornot)   
86{
87  char temp[61];
88  char *tmp;
89  int size;
90 
91  if (strlen (s) <= 60)
92    {
93      if ( returnlineornot == 0 ) fprintf (filout, "      %s", s);
94      else fprintf (filout, "      %s\n", s);
95      if ( returnlineornot == 0 ) colnum=colnum+strlen(s)+6;
96      else colnum=0;
97    }
98  else
99    {
100      strncpy (temp, s, 60);
101      strcpy (&temp[60], "\0");
102
103      tmp = strrchr(temp, ',');
104      if ( !tmp  || strlen(tmp) == strlen(temp) ) tmp = strrchr(temp, '+');
105      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '-');
106      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '/');
107      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '*');
108      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '%');
109      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, ':');
110      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, ')');
111      if ( tmp )
112      {
113         size = strlen(tmp);
114      }
115      else
116      {
117         size = 0 ;
118      }
119
120      strcpy (&temp[60-size], "\0");
121
122      if ( fortran77 == 0 ) fprintf (filout, "      %s  &\n", temp);
123      else fprintf (filout, "      %s  \n", temp);
124      colnum=0;
125      tofich_reste (filout, (char *) &s[60-size], returnlineornot);
126    }
127}
128
129/******************************************************************************/
130/*                       tofich_blanc                                         */
131/******************************************************************************/
132/* This subroutine is used to write size blank into the fileout               */
133/******************************************************************************/
134/*                                                                            */
135/*                                                                            */
136/*                                                                            */
137/******************************************************************************/
138void tofich_blanc (FILE * filout, int size)
139{
140  int i;
141 
142  if (size <= 65)
143    {
144      fprintf (filout, "%*s\n",size,EmptyChar);
145    }
146  else
147    {
148      i=0;
149      do
150      {
151         fprintf (filout, "%*s\n",65,EmptyChar);
152         i = i+1;
153      } while ( i <= size / 65 );
154         fprintf (filout, "%*s\n",size%65,EmptyChar);
155    }
156}
157
158
159/******************************************************************************/
160/*                         RemoveWord                                         */
161/******************************************************************************/
162/* This subroutine is used to remove a sentence in the file filout            */
163/******************************************************************************/
164/*                                                                            */
165/*                                                                            */
166/*                                                                            */
167/******************************************************************************/
168void RemoveWordSET(FILE * filout, long int position, long int sizetoremove)
169{
170   fseek(filout,position,SEEK_SET);
171   tofich_blanc(filout,sizetoremove);
172}
173
174
175/******************************************************************************/
176/*                         RemoveWord                                         */
177/******************************************************************************/
178/* This subroutine is used to remove a sentence in the file filout            */
179/******************************************************************************/
180/*                                                                            */
181/*                                                                            */
182/*                                                                            */
183/******************************************************************************/
184void RemoveWordCUR(FILE * filout, long int position, long int sizetoremove)
185{
186   fseek(filout,position,SEEK_CUR);
187   tofich_blanc(filout,sizetoremove);
188}
Note: See TracBrowser for help on using the repository browser.