source: tags/svn.1.5.4/NTREE/AP_conservProfile2Gnuplot.cxx

Last change on this file was 8393, checked in by westram, 13 years ago
  • cppchecked (1.53)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : AP_conservProfile2Gnuplot.cxx                     //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11#include "nt_internal.h"
12#include "ap_conservProfile2Gnuplot.hxx"
13
14#include <aw_window.hxx>
15#include <aw_file.hxx>
16#include <aw_awar.hxx>
17#include <aw_msg.hxx>
18#include <aw_root.hxx>
19#include <arbdbt.h>
20
21extern GBDATA *GLOBAL_gb_main;
22
23static void AP_conservProfile2Gnuplot_callback(AW_window *aww) {
24    GB_ERROR  error   = 0;
25    char     *command_file;
26    char     *cmdName = GB_unique_filename("arb", "gnuplot");
27    FILE     *cmdFile = GB_fopen_tempfile(cmdName, "wt", &command_file);
28
29    if (!cmdFile) error = GB_await_error();
30    else {
31        char *fname   = aww->get_root()->awar(AP_AWAR_CONSPRO_FILENAME)->read_string();
32        char *smooth  = aww->get_root()->awar(AP_AWAR_CONSPRO_SMOOTH_GNUPLOT)->read_string();
33        char *legend  = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_LEGEND)->read_string();
34        int   dispPos = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_DISP_POS)->read_int();
35        int   minX    = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_MIN_X)->read_int();
36        int   maxX    = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_MAX_X)->read_int();
37        int   minY    = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_MIN_Y)->read_int();
38        int   maxY    = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_MAX_Y)->read_int();
39
40        if (minX>0 || maxX>0)   fprintf(cmdFile, "set xrange [%i:%i]\n", minX, maxX);
41        if (minY>0 || maxY>0)   fprintf(cmdFile, "set yrange [%i:%i]\n", minY, maxY);
42
43        fprintf(cmdFile, "plot \"%s\" %s title \"%s\"\n", fname, smooth, legend);
44
45        if (dispPos) fprintf(cmdFile, "replot \"%s\" title \"Base Positions\"\n", fname);
46
47        fprintf(cmdFile, "pause -1 \"Press RETURN to close gnuplot\"\n");
48
49        free(legend);
50        free(smooth);
51        free(fname);
52
53        fclose(cmdFile);
54    }
55
56    if (!error) {
57        char *script = GBS_global_string_copy("gnuplot %s && rm -f %s", command_file, command_file);
58        GB_xcmd(script, true, true);          // execute GNUPLOT using command_file
59        free(script);
60    }
61    free(command_file);
62    free(cmdName);
63
64    if (error) aw_message(error);
65}
66
67
68static AW_window *AP_createConservationProfileWindow(AW_root *root) { // @@@ unused! test and add to menu if useful
69
70    AW_window_simple *aws = new AW_window_simple;
71
72    aws->init(root, "DISP_CONSERV_PROFILE_GNUPLOT", "Conservation Profile Using Base Frequency Filter");
73    aws->load_xfig("conservProfile2Gnuplot.fig");
74
75    root->awar_string(AP_AWAR_CONSPRO_SMOOTH_GNUPLOT);
76    root->awar_string(AP_AWAR_BASE_FREQ_FILTER_NAME);
77
78    AW_create_fileselection_awars(root, AP_AWAR_CONSPRO, "", ".gnu", "noname.gnu");
79
80    root->awar_string(AP_AWAR_CONSPRO_GNUPLOT_LEGEND);
81    root->awar_int(AP_AWAR_CONSPRO_GNUPLOT_DISP_POS);
82    root->awar_int(AP_AWAR_CONSPRO_GNUPLOT_MIN_X);
83    root->awar_int(AP_AWAR_CONSPRO_GNUPLOT_MAX_X);
84    root->awar_int(AP_AWAR_CONSPRO_GNUPLOT_MIN_Y);
85    root->awar_int(AP_AWAR_CONSPRO_GNUPLOT_MAX_Y);
86
87    aws->at("close"); aws->callback((AW_CB0)AW_POPDOWN);
88    aws->create_button("CLOSE", "CLOSE", "C");
89
90    aws->at("help"); aws->callback(AW_POPUP_HELP, (AW_CL)"conservProfile2Gnuplot.hlp");
91    aws->create_button("HELP", "HELP", "H");
92
93    AW_create_fileselection(aws, AP_AWAR_CONSPRO);
94
95    aws->at("baseFreqFlt");
96    aws->create_button("SELECT_FILTER", AP_AWAR_BASE_FREQ_FILTER_NAME);
97
98    aws->at("minX");
99    aws->create_input_field(AP_AWAR_CONSPRO_GNUPLOT_MIN_X);
100
101    aws->at("maxX");
102    aws->create_input_field(AP_AWAR_CONSPRO_GNUPLOT_MAX_X);
103
104    aws->at("minY");
105    aws->create_input_field(AP_AWAR_CONSPRO_GNUPLOT_MIN_Y);
106
107    aws->at("maxY");
108    aws->create_input_field(AP_AWAR_CONSPRO_GNUPLOT_MAX_Y);
109
110    aws->at("legend");
111    aws->create_input_field(AP_AWAR_CONSPRO_GNUPLOT_LEGEND);
112
113    aws->at("smooth");
114    aws->create_toggle_field(AP_AWAR_CONSPRO_SMOOTH_GNUPLOT, 1);
115    aws->insert_default_toggle("None", "N", "");
116    aws->insert_toggle("Unique", "U", "smooth unique");
117    aws->insert_toggle("Bezier", "B", "smooth bezier");
118    aws->update_toggle_field();
119
120    aws->at("dispPos");
121    aws->create_toggle(AP_AWAR_CONSPRO_GNUPLOT_DISP_POS);
122
123    aws->at("dispProfile");
124    aws->callback(AP_conservProfile2Gnuplot_callback);
125    aws->create_button("DISPLAY_PROFILE", "SAVE & DISPLAY CONSERVATION PROFILE");
126
127    return aws;
128}
129
Note: See TracBrowser for help on using the repository browser.