File: command_dump.c

package info (click to toggle)
garlic 1.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 4,440 kB
  • ctags: 1,403
  • sloc: ansic: 52,465; makefile: 1,134
file content (271 lines) | stat: -rw-r--r-- 8,537 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* Copyright (C) 2004-2006 Damir Zucic */

/*=============================================================================

				command_dump.c

Purpose:
	Execute dump command: dump some numeric data to the specified file
	or to the standard output stream.

Input:
	(1) Pointer to MolComplexS structure.
	(2) The number of macromolecular complexes.
	(3) Pointer to RuntimeS structure.
	(4) Pointer to the remainder of the command string.  The remainder
	    should contain only one keyword and optionally the output file
	    name.  The keywords are:  AVE (AVERAGE),  WEI (WEIGHTED),  HYD
	    (HYDROPHOBICITY), F1, F2, F3, F4, F5, F6 and F7.

Output:
	(1) Numeric data written to the output file or to stdout stream.
	(2) Return value.

Return value:
	(1) Positive (command) code on success.
	(2) Negative (error) code on failure.

========includes:============================================================*/

#include <stdio.h>

#include <string.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "commands.h"
#include "typedefs.h"

/*======function prototypes:=================================================*/

char		*ExtractToken_ (char *, int, char *, char *);

/*======execute dump command:================================================*/

int Dump_ (MolComplexS *mol_complexSP, int mol_complexesN,
	   RuntimeS *runtimeSP, char *stringP)
{
char		*remainderP;
char		tokenA[STRINGSIZE];
char		keywordA[SHORTSTRINGSIZE];
int		output_fileF = 0;
char		string_copyA[STRINGSIZE];
FILE		*outfileP = NULL;
size_t		residueI;
double		d;

/* Extract the first token, if present: */
remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n");

/* If there are no tokens in  the remainder of */
/* the command string, the keyword is missing: */
if (!remainderP)
	{
	strcpy (runtimeSP->messageA, "At least one keyword is expected!");
	runtimeSP->message_length = strlen (runtimeSP->messageA);
	return ERROR_DUMP;
	}

/* Copy up to three letters of the first token for future use: */
strncpy (keywordA, tokenA, 3);
keywordA[3] = '\0';

/* If the second token is present, it should contain the output file name: */
remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
if (!remainderP) output_fileF = 0;	/* 0 = send output to stdout */
else             output_fileF = 1;	/* 1 = send output to a file */

/* Extract the output file name (if requested) and open file: */
if (output_fileF)
	{
	/* Copy the original command string: */
	strncpy (string_copyA, runtimeSP->curr_commandA, STRINGSIZE - 1);
	string_copyA[STRINGSIZE - 1] = '\0';

	/* Skip two tokens; the third token should contain output file name: */
	remainderP = ExtractToken_ (tokenA, STRINGSIZE, string_copyA, " \t\n");
	if (!remainderP)
		{
		strcpy (runtimeSP->messageA, "Nasty error #1 in Dump_!");
		runtimeSP->message_length = strlen (runtimeSP->messageA);
		return ERROR_DUMP;
		}
	remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
	if (!remainderP)
		{
		strcpy (runtimeSP->messageA, "Nasty error #2 in Dump_!");
		runtimeSP->message_length = strlen (runtimeSP->messageA);
		return ERROR_DUMP;
		}
	remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
	if (!remainderP) 
		{
		strcpy (runtimeSP->messageA, "Nasty error #3 in Dump_!");
		runtimeSP->message_length = strlen (runtimeSP->messageA);
		return ERROR_DUMP;
		}

	/* Try to open output file: */
	if (!(outfileP = fopen (tokenA, "w")))
		{
		strcpy (runtimeSP->messageA, "Failed to open output file!");
		runtimeSP->message_length = strlen (runtimeSP->messageA);
		return ERROR_DUMP;
		}
	}

/* A paranoid check: */
if (!outfileP) output_fileF = 0;

/* Dump the raw hydrophobicity, the average hydrophobicity or some */
/* other  hydrophobicity function  (F1, F2, F3, F4, F5, F6 or F7): */
if ((strstr (keywordA, "AVE") == keywordA) ||
    (strstr (keywordA, "WEI") == keywordA) ||
    (strstr (keywordA, "HYD") == keywordA) ||
    (strstr (keywordA, "F1")  == keywordA) ||
    (strstr (keywordA, "F2")  == keywordA) ||
    (strstr (keywordA, "F3")  == keywordA) ||
    (strstr (keywordA, "F4")  == keywordA) ||
    (strstr (keywordA, "F5")  == keywordA) ||
    (strstr (keywordA, "F6")  == keywordA) ||
    (strstr (keywordA, "F7")  == keywordA))
	{
	/* Write the title: */
	if (strstr (keywordA, "AVE") == keywordA)
		{
		if (output_fileF)
			fprintf (outfileP, "# Average hydrophobicity\n");
		else fprintf (stdout, "# Average hydrophobicity\n");
		}
	else if (strstr (keywordA, "WEI") == keywordA)
		{
		if (output_fileF)
			fprintf (outfileP, "# Weighted hydrophobicity\n");
		else fprintf (stdout, "# Weighted hydrophobicity\n");
		}
	else if (strstr (keywordA, "HYD") == keywordA)
		{
		if (output_fileF) fprintf (outfileP, "# Raw hydrophobicity\n");
		else fprintf (stdout, "# Raw hydrophobicity\n");
		}
	else if (strstr (keywordA, "F1") == keywordA)
		{
		if (output_fileF) fprintf (outfileP, "# Function F1\n");
		else fprintf (stdout, "# Function F1\n"); 
		}
	else if (strstr (keywordA, "F2") == keywordA)
		{
		if (output_fileF) fprintf (outfileP, "# Function F2\n");
		else fprintf (stdout, "# Function F2\n"); 
		}
	else if (strstr (keywordA, "F3") == keywordA)
		{
		if (output_fileF) fprintf (outfileP, "# Function F3\n");
		else fprintf (stdout, "# Function F3\n"); 
		}
	else if (strstr (keywordA, "F4") == keywordA)
		{
		if (output_fileF) fprintf (outfileP, "# Function F4\n");
		else fprintf (stdout, "# Function F4\n"); 
		}
	else if (strstr (keywordA, "F5") == keywordA)
		{
		if (output_fileF) fprintf (outfileP, "# Function F5\n");
		else fprintf (stdout, "# Function F5\n"); 
		}
	else if (strstr (keywordA, "F6") == keywordA)
		{
		if (output_fileF) fprintf (outfileP, "# Function F6\n");
		else fprintf (stdout, "# Function F6\n"); 
		}
	else if (strstr (keywordA, "F7") == keywordA)
		{
		if (output_fileF) fprintf (outfileP, "# Function F7\n");
		else fprintf (stdout, "# Function F7\n"); 
		}

	/* Write the values: */
	for (residueI = 0; residueI < runtimeSP->residuesN; residueI++)
		{
		/* Write the serial number, without newline: */
		if (output_fileF) fprintf (outfileP, "%8d", residueI);
		else fprintf (stdout, "%8d", residueI);

		/* Write the requested hydrophobicity function: */
		if (strstr (keywordA, "AVE") == keywordA)
			{
			d = *(runtimeSP->average_hydrophobicityP + residueI);
			if (output_fileF) fprintf (outfileP, " %8.2f\n", d);
			else fprintf (stdout, " %8.2f\n", d);
			}
		else if (strstr (keywordA, "WEI") == keywordA)
			{
			d = *(runtimeSP->weighted_hydrophobicityP + residueI);
			if (output_fileF) fprintf (outfileP, " %8.2f\n", d);
			else fprintf (stdout, " %8.2f\n", d);
			}
		else if (strstr (keywordA, "HYD") == keywordA)
			{
			d = *(runtimeSP->hydrophobicityP + residueI);
			if (output_fileF) fprintf (outfileP, " %8.2f\n", d);
			else fprintf (stdout, " %8.2f\n", d);
			}
		else if (strstr (keywordA, "F1") == keywordA)
			{
			d = *(runtimeSP->function1P + residueI);
			if (output_fileF) fprintf (outfileP, " %8.2f\n", d);
			else fprintf (stdout, " %8.2f\n", d); 
			}
		else if (strstr (keywordA, "F2") == keywordA)
			{
			d = *(runtimeSP->function2P + residueI);
			if (output_fileF) fprintf (outfileP, " %8.2f\n", d);
			else fprintf (stdout, " %8.2f\n", d); 
			}
		else if (strstr (keywordA, "F3") == keywordA)
			{
			d = *(runtimeSP->function3P + residueI);
			if (output_fileF) fprintf (outfileP, " %8.2f\n", d);
			else fprintf (stdout, " %8.2f\n", d); 
			}
		else if (strstr (keywordA, "F4") == keywordA)
			{
			d = *(runtimeSP->function4P + residueI);
			if (output_fileF) fprintf (outfileP, " %8.2f\n", d);
			else fprintf (stdout, " %8.2f\n", d); 
			}
		else if (strstr (keywordA, "F5") == keywordA)
			{
			d = *(runtimeSP->function5P + residueI);
			if (output_fileF) fprintf (outfileP, " %8.2f\n", d);
			else fprintf (stdout, " %8.2f\n", d); 
			}
		else if (strstr (keywordA, "F6") == keywordA)
			{
			d = *(runtimeSP->function6P + residueI);
			if (output_fileF) fprintf (outfileP, " %8.2f\n", d);
			else fprintf (stdout, " %8.2f\n", d); 
			}
		else if (strstr (keywordA, "F7") == keywordA)
			{
			d = *(runtimeSP->function7P + residueI);
			if (output_fileF) fprintf (outfileP, " %8.2f\n", d);
			else fprintf (stdout, " %8.2f\n", d); 
			}
		}
	}

/* Close the output file, if opened before: */
if (output_fileF) fclose (outfileP);

/* Return the command code: */
return COMMAND_DUMP;
}

/*===========================================================================*/