added README_changes.txt
[wrffire.git] / wrfv2_fire / external / RSL / RSL / rsl_error_dup.c
blob78db8478868f8320261c4c516ad4e5c42df499a6
1 /***********************************************************************
3 COPYRIGHT
5 The following is a notice of limited availability of the code and
6 Government license and disclaimer which must be included in the
7 prologue of the code and in all source listings of the code.
9 Copyright notice
10 (c) 1977 University of Chicago
12 Permission is hereby granted to use, reproduce, prepare
13 derivative works, and to redistribute to others at no charge. If
14 you distribute a copy or copies of the Software, or you modify a
15 copy or copies of the Software or any portion of it, thus forming
16 a work based on the Software and make and/or distribute copies of
17 such work, you must meet the following conditions:
19 a) If you make a copy of the Software (modified or verbatim)
20 it must include the copyright notice and Government
21 license and disclaimer.
23 b) You must cause the modified Software to carry prominent
24 notices stating that you changed specified portions of
25 the Software.
27 This software was authored by:
29 Argonne National Laboratory
30 J. Michalakes: (630) 252-6646; email: michalak@mcs.anl.gov
31 Mathematics and Computer Science Division
32 Argonne National Laboratory, Argonne, IL 60439
34 ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES
35 OF ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT,
36 AND OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A
37 CONTRACT WITH THE DEPARTMENT OF ENERGY.
39 GOVERNMENT LICENSE AND DISCLAIMER
41 This computer code material was prepared, in part, as an account
42 of work sponsored by an agency of the United States Government.
43 The Government is granted for itself and others acting on its
44 behalf a paid-up, nonexclusive, irrevocable worldwide license in
45 this data to reproduce, prepare derivative works, distribute
46 copies to the public, perform publicly and display publicly, and
47 to permit others to do so. NEITHER THE UNITED STATES GOVERNMENT
48 NOR ANY AGENCY THEREOF, NOR THE UNIVERSITY OF CHICAGO, NOR ANY OF
49 THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
50 ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
51 COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS,
52 PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD
53 NOT INFRINGE PRIVATELY OWNED RIGHTS.
55 ***************************************************************************/
57 /* redirect standard error from process into a file */
58 /* also redirect standard output to a file */
60 #include <stdio.h>
61 #ifdef SEQUENT
62 #include <sys/file.h>
63 #else
64 #include <fcntl.h>
65 #endif
67 #include "rsl.h"
69 #define STANDARD_ERROR 2
71 #define STANDARD_OUTPUT 1
73 /*@
74 RSL_ERROR_DUP --- Redirect standard out and error on each proc.
76 Notes:
77 This routine redirects the standard and error outputs to a
78 unique pair of files for each processor. The file names generated
79 are rsl.out.dddd and rsl.error.dddd, where dddd is the 4-digit
80 zero-padded processor number. RSL\_INITIALIZE must be called before
81 this routine.
83 See also:
84 RSL\_INITIALIZE, RSL\_MESH
85 @*/
87 RSL_ERROR_DUP ()
89 int newfd ;
90 char filename[256] ;
92 int *me ;
94 me = &rsl_myproc ;
96 /* redirect standard out*/
97 sprintf(filename,"rsl.out.%04d",*me) ;
98 if ((newfd = open( filename, O_CREAT | O_WRONLY, 0666 )) < 0 )
100 perror("error_dup: cannot open rsl.out.nnnn") ;
101 fprintf(stderr,"...sending output to standard output and continuing.\n") ;
102 return ;
104 if( dup2( newfd, STANDARD_OUTPUT ) < 0 )
106 perror("error_dup: dup2 fails to change output descriptor") ;
107 fprintf(stderr,"...sending output to standard output and continuing.\n") ;
108 close(newfd) ;
109 return ;
112 /* redirect standard error */
113 sprintf(filename,"rsl.error.%04d",*me) ;
114 if ((newfd = open( filename, O_CREAT | O_WRONLY, 0666 )) < 0 )
116 perror("error_dup: cannot open rsl.error.log") ;
117 fprintf(stderr,"...sending error to standard error and continuing.\n") ;
118 return ;
120 if( dup2( newfd, STANDARD_ERROR ) < 0 )
122 perror("error_dup: dup2 fails to change error descriptor") ;
123 fprintf(stderr,"...sending error to standard error and continuing.\n") ;
124 close(newfd) ;
125 return ;
130 RSL_ERROR_DUP1 ( int *me )
132 int newfd ;
133 char filename[256] ;
135 /* redirect standard out*/
136 sprintf(filename,"rsl.out.%04d",*me) ;
137 if ((newfd = open( filename, O_CREAT | O_WRONLY, 0666 )) < 0 )
139 perror("error_dup: cannot open rsl.out.nnnn") ;
140 fprintf(stderr,"...sending output to standard output and continuing.\n") ;
141 return ;
143 if( dup2( newfd, STANDARD_OUTPUT ) < 0 )
145 perror("error_dup: dup2 fails to change output descriptor") ;
146 fprintf(stderr,"...sending output to standard output and continuing.\n") ;
147 close(newfd) ;
148 return ;
151 /* redirect standard error */
152 sprintf(filename,"rsl.error.%04d",*me) ;
153 if ((newfd = open( filename, O_CREAT | O_WRONLY, 0666 )) < 0 )
155 perror("error_dup: cannot open rsl.error.log") ;
156 fprintf(stderr,"...sending error to standard error and continuing.\n") ;
157 return ;
159 if( dup2( newfd, STANDARD_ERROR ) < 0 )
161 perror("error_dup: dup2 fails to change error descriptor") ;
162 fprintf(stderr,"...sending error to standard error and continuing.\n") ;
163 close(newfd) ;
164 return ;