~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to plot.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                plot.c
 
6
 
 
7
Purpose:
 
8
        Execute plot command: plot requested functions.  The command plot
 
9
        may be followed by a list of keywords. If keyword OFF is present,
 
10
        the main window  drawing mode  will be  changed  to default mode.
 
11
        Otherwise, for all recognized keywords the corresponding flags in
 
12
        RuntimeS structure will be set to one.
 
13
 
 
14
Input:
 
15
        (1) Pointer to MolComplexS structure.
 
16
        (2) The number of macromolecular complexes.
 
17
        (3) Pointer to RuntimeS structure.
 
18
        (4) Pointer to ConfigS structure.
 
19
        (5) Pointer to GUIS structure.
 
20
        (6) Pointer to NearestAtomS structure.
 
21
        (7) The number of pixels in the main window free area.
 
22
        (8) Pointer to refreshI.
 
23
        (9) Pointer to the remainder of the command string.  This command
 
24
            may be given with a list of keywords or with keyword OFF.
 
25
 
 
26
Output:
 
27
        (1) The main window mode changed to 4 (default is zero).
 
28
        (2) Return value.
 
29
 
 
30
Return value:
 
31
        (1) Positive (command) code on success.
 
32
        (2) Negative (error) code on failure.
 
33
 
 
34
Notes:
 
35
        (1) This command reinitializes the NearestAtomS array,  except if
 
36
            at least one of additional keywords is not recognized.
 
37
 
 
38
========includes:============================================================*/
 
39
 
 
40
#include <stdio.h>
 
41
 
 
42
#include <string.h>
 
43
 
 
44
#include <X11/Xlib.h>
 
45
#include <X11/Xutil.h>
 
46
#include <X11/Xos.h>
 
47
#include <X11/Xatom.h>
 
48
 
 
49
#include "defines.h"
 
50
#include "commands.h"
 
51
#include "typedefs.h"
 
52
 
 
53
/*======function prototypes:=================================================*/
 
54
 
 
55
void            InitNearest_ (NearestAtomS *, size_t);
 
56
int             ExtractTwoIntegers_ (int *, int *, char *);
 
57
size_t          MainRefresh_ (MolComplexS *, int,
 
58
                              RuntimeS *, ConfigS *, GUIS *,
 
59
                              NearestAtomS *, size_t, unsigned int);
 
60
int             ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *);
 
61
 
 
62
/*======execute plot command:================================================*/
 
63
 
 
64
int Plot_ (MolComplexS *mol_complexSP, int mol_complexesN,
 
65
           RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP,
 
66
           NearestAtomS *nearest_atomSP, size_t pixelsN,
 
67
           unsigned int *refreshIP, char *stringP)
 
68
{
 
69
char            *P;
 
70
int             n;
 
71
int             residue1I, residue2I;
 
72
 
 
73
/* Reset flags: */
 
74
runtimeSP->averaged_hydrophobicityF = 0;
 
75
runtimeSP->hydrophobic_momentF      = 0;
 
76
 
 
77
/* If keyword OFF is present, switch to default drawing mode: */
 
78
if (strstr (stringP, "OFF"))
 
79
        {
 
80
        /* Reset drawing mode index: */
 
81
        guiSP->main_window_modeI = 0;
 
82
 
 
83
        /* Reinitialize the NearestAtomS array: */
 
84
        InitNearest_ (nearest_atomSP, pixelsN);
 
85
        *refreshIP = 1;
 
86
 
 
87
        /* Refresh the main window: */
 
88
        (*refreshIP)++;
 
89
        MainRefresh_ (mol_complexSP, mol_complexesN,
 
90
                      runtimeSP, configSP, guiSP,
 
91
                      nearest_atomSP, pixelsN, *refreshIP);
 
92
 
 
93
        /* Refresh the control window: */
 
94
        ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
 
95
                         configSP, guiSP);
 
96
 
 
97
        /* Return the command code: */
 
98
        return COMMAND_PLOT;
 
99
        }
 
100
 
 
101
/* The sliding window should not be wider than the sequence: */
 
102
if (runtimeSP->sliding_window_width > runtimeSP->residuesN)
 
103
        {
 
104
        strcpy (runtimeSP->messageA,
 
105
                "The sliding window is wider than the sequence!");
 
106
        runtimeSP->message_length = strlen (runtimeSP->messageA);
 
107
        return ERROR_PLOT;
 
108
        }
 
109
 
 
110
/* If keyword  HYD  (short for HYDROPHOBICITY) is present,  set the */
 
111
/* flag which signals that averaged hydrophobicity should be drawn: */
 
112
if (strstr (stringP, "HYD"))
 
113
        {
 
114
        runtimeSP->averaged_hydrophobicityF = 1;
 
115
        }
 
116
 
 
117
/* If keyword MOM (short for MOMENT) is present, set the flag */
 
118
/* which signals  that  hydrophobic moment  should be  drawn: */
 
119
if (strstr (stringP, "MOM"))
 
120
        {
 
121
        runtimeSP->hydrophobic_momentF = 1;
 
122
        }
 
123
 
 
124
/* At least one flag should be set to one: */
 
125
if ((runtimeSP->averaged_hydrophobicityF == 0) &&
 
126
    (runtimeSP->hydrophobic_momentF      == 0))
 
127
        {
 
128
        strcpy (runtimeSP->messageA,
 
129
                "Failed to recognize what should be drawn!");
 
130
        runtimeSP->message_length = strlen (runtimeSP->messageA);
 
131
        return ERROR_PLOT;
 
132
        }
 
133
 
 
134
/* Replace each minus and colon in the input string with space: */
 
135
P = stringP;
 
136
while ((n = *P++) != '\0')
 
137
        {
 
138
        if      (n == '-') *(P - 1) = ' ';
 
139
        else if (n == ':') *(P - 1) = ' ';
 
140
        }
 
141
 
 
142
/* Try to extract two indices: */
 
143
if (ExtractTwoIntegers_ (&residue1I, &residue2I, stringP) > 0)
 
144
        {
 
145
        /* Check indices: */
 
146
        if (residue2I < residue1I)
 
147
                {
 
148
                strcpy (runtimeSP->messageA, "Bad range (check indices)!");
 
149
                runtimeSP->message_length = strlen (runtimeSP->messageA);
 
150
                return ERROR_PLOT;
 
151
                }
 
152
 
 
153
        /* Store the extracted indices: */
 
154
        runtimeSP->range_startI = (size_t) residue1I;
 
155
        runtimeSP->range_endI   = (size_t) residue2I;
 
156
        }
 
157
 
 
158
/* If failed to extract indices, use default values: */
 
159
else
 
160
        {
 
161
        runtimeSP->range_startI = *runtimeSP->serialIP;
 
162
        runtimeSP->range_endI   = *(runtimeSP->serialIP +
 
163
                                    runtimeSP->residuesN - 1);
 
164
        }
 
165
 
 
166
/* Set the main window drawing mode index: */
 
167
guiSP->main_window_modeI = 4;
 
168
 
 
169
/* Reinitialize the NearestAtomS array and refresh index: */
 
170
InitNearest_ (nearest_atomSP, pixelsN);
 
171
*refreshIP = 1;
 
172
 
 
173
/* Refresh the main window: */
 
174
(*refreshIP)++;
 
175
MainRefresh_ (mol_complexSP, mol_complexesN,
 
176
              runtimeSP, configSP, guiSP,
 
177
              nearest_atomSP, pixelsN, *refreshIP);
 
178
 
 
179
/* Refresh the control window: */
 
180
ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP);
 
181
 
 
182
/* Return the command code: */
 
183
return COMMAND_PLOT;
 
184
}
 
185
 
 
186
/*===========================================================================*/
 
187
 
 
188