1 | //------------------------------------------------------------------------------// |
---|
2 | // This file is part of PALM. |
---|
3 | // |
---|
4 | // PALM is free software: you can redistribute it and/or modify it under the terms |
---|
5 | // of the GNU General Public License as published by the Free Software Foundation, |
---|
6 | // either version 3 of the License, or (at your option) any later version. |
---|
7 | // |
---|
8 | // PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
9 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
10 | // A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
11 | // |
---|
12 | // You should have received a copy of the GNU General Public License along with |
---|
13 | // PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
14 | // |
---|
15 | // Copyright 1997-2012 Leibniz University Hannover |
---|
16 | //--------------------------------------------------------------------------------// |
---|
17 | // |
---|
18 | // Current revisions: |
---|
19 | // ----------------- |
---|
20 | // |
---|
21 | // |
---|
22 | // Former revisions: |
---|
23 | // ----------------- |
---|
24 | // $Id: mainwindow.cpp 2070 2016-11-14 16:59:19Z lvollmer $ |
---|
25 | // |
---|
26 | // 2069 2016-11-14 16:58:29Z maronga |
---|
27 | // Bugfix: keep xterm alive for interactive runs |
---|
28 | // Changed: some style improvements |
---|
29 | // |
---|
30 | // 2067 2016-11-11 21:55:49Z maronga |
---|
31 | // Added support for PALM job manager |
---|
32 | // |
---|
33 | // 1804 2016-04-05 16:30:18Z maronga |
---|
34 | // Removed parameter file check |
---|
35 | // Update for use with qt5 |
---|
36 | // |
---|
37 | // 1723 2015-11-16 15:25:51Z boeske |
---|
38 | // Added checkbox for cyclic fill flag in mrungui |
---|
39 | // |
---|
40 | // 1611 2015-07-07 12:23:22Z maronga |
---|
41 | // Added routine start_watchdog. |
---|
42 | // |
---|
43 | // 1046 2012-11-09 14:38:45Z maronga |
---|
44 | // code put under GPL (PALM 3.9) |
---|
45 | // |
---|
46 | // mainwindow.cpp 920 2012-06-05 09:56:53Z maronga |
---|
47 | // Added -Z option (disable combine_plot_fields) |
---|
48 | // |
---|
49 | // 818 2012-02-08 16:11:23Z maronga |
---|
50 | // New: flag parameter -z implemented (used for skipping parameter file check) |
---|
51 | // |
---|
52 | // 811 2012-01-31 09:45:54Z maronga |
---|
53 | // Bugfix: waitForFinished time exceeded limits, adjusted to 1h waiting time |
---|
54 | // |
---|
55 | // 809 2012-01-30 13:32:58Z marong |
---|
56 | // Bugfix: waiting for 20 minutes does not suffice for local runs |
---|
57 | // |
---|
58 | // 793 2011-12-12 15:15:24Z maronga |
---|
59 | // Initial revision |
---|
60 | // |
---|
61 | // Description: |
---|
62 | // ------------ |
---|
63 | // All subroutines for mrungui |
---|
64 | //----------------------------------------------------------------------------// |
---|
65 | |
---|
66 | #include <QApplication> |
---|
67 | #include "mainwindow.h" |
---|
68 | #include "ui_mainwindow.h" |
---|
69 | #include "ui_about.h" |
---|
70 | #include "ui_help.h" |
---|
71 | #include <QString> |
---|
72 | #include <QFileDialog> |
---|
73 | #include <QDateTime> |
---|
74 | #include "stdlib.h" |
---|
75 | #include <QProcess> |
---|
76 | #include <QTextStream> |
---|
77 | |
---|
78 | |
---|
79 | // Define username on host as global variable |
---|
80 | QString username = getenv("USER"); |
---|
81 | // Define variable branch (location of mrungui, e.g. |
---|
82 | // "/home/user/palm/current_version" |
---|
83 | QString branch; |
---|
84 | |
---|
85 | |
---|
86 | //****************************************************************************// |
---|
87 | // Initialization of the main window |
---|
88 | MainWindow::MainWindow(QWidget *parent) : |
---|
89 | QMainWindow(parent), |
---|
90 | ui(new Ui::MainWindow) |
---|
91 | { |
---|
92 | ui->setupUi(this); |
---|
93 | |
---|
94 | // Empty the mrun command line (hereafter mrunline) |
---|
95 | ui->commandline->setText(""); |
---|
96 | |
---|
97 | // Get path of the program and set default file |
---|
98 | branch = QCoreApplication::applicationDirPath(); |
---|
99 | branch = branch.left(branch.length() - 14); |
---|
100 | |
---|
101 | |
---|
102 | QFile file(branch+"/.mrun.gui.default"); |
---|
103 | |
---|
104 | // Read default settings |
---|
105 | if ( file.exists() == true && file.size() > 10) |
---|
106 | { |
---|
107 | |
---|
108 | QString mrunline; |
---|
109 | if ( file.open(QIODevice::ReadOnly | QIODevice::Text ) ) |
---|
110 | { |
---|
111 | |
---|
112 | // File opened successfully |
---|
113 | QTextStream in(&file); |
---|
114 | |
---|
115 | QString line = in.readLine(); |
---|
116 | while (!line.isNull()) |
---|
117 | { |
---|
118 | mrunline = line; |
---|
119 | line = in.readLine(); |
---|
120 | } |
---|
121 | |
---|
122 | file.close(); |
---|
123 | } |
---|
124 | |
---|
125 | mrunline = mrunline.right(mrunline.length() - 17); |
---|
126 | ui->commandline->setText(mrunline); |
---|
127 | |
---|
128 | setup_gui(mrunline); |
---|
129 | |
---|
130 | } |
---|
131 | |
---|
132 | // Load jobs into the recent jobs list |
---|
133 | recent_jobs(10); |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | //****************************************************************************// |
---|
138 | // Routine for listing jobs in the recent jobs list |
---|
139 | int MainWindow::recent_jobs(int noj) |
---|
140 | { |
---|
141 | branch = QCoreApplication::applicationDirPath(); |
---|
142 | branch = branch.left(branch.length() - 14); |
---|
143 | |
---|
144 | QFile file(branch+"/.mrun.history"); |
---|
145 | QString listitem, timestamp; |
---|
146 | |
---|
147 | // Read mrun history and select the last used jobs |
---|
148 | if ( file.exists() == true && file.size() > 10) |
---|
149 | { |
---|
150 | |
---|
151 | // Open history |
---|
152 | QStringList history, tmphistory; |
---|
153 | if ( file.open(QIODevice::ReadOnly | QIODevice::Text ) ) |
---|
154 | { |
---|
155 | |
---|
156 | // file opened successfully |
---|
157 | QTextStream in(&file); |
---|
158 | |
---|
159 | QString line = in.readLine(); |
---|
160 | while (!line.isNull()) |
---|
161 | { |
---|
162 | history.append(line); |
---|
163 | line = in.readLine(); |
---|
164 | } |
---|
165 | |
---|
166 | file.close(); |
---|
167 | } |
---|
168 | |
---|
169 | int j = 0; |
---|
170 | |
---|
171 | ui->list_jobname->clear(); |
---|
172 | |
---|
173 | // Read history entries and append to recent job list |
---|
174 | for (int i=history.count(); i>=1; i--) |
---|
175 | { |
---|
176 | timestamp = history[i-1].left(16); |
---|
177 | listitem = history[i-1].right(history[i-1].length() - 17); |
---|
178 | listitem = listitem.split("-d ", QString::SkipEmptyParts)[1]; |
---|
179 | listitem = listitem.split(" -", QString::SkipEmptyParts)[0]; |
---|
180 | listitem = listitem.replace(" ",""); |
---|
181 | |
---|
182 | QList<QListWidgetItem *> matchitems = \ |
---|
183 | ui->list_jobname->findItems(listitem, Qt::MatchExactly); |
---|
184 | |
---|
185 | if ( matchitems.count() == 0 ) |
---|
186 | { |
---|
187 | ui->list_jobname->addItem(listitem); |
---|
188 | tmphistory.append(listitem+" ("+timestamp+")"); |
---|
189 | j++; |
---|
190 | } |
---|
191 | if ( j == noj ) |
---|
192 | { |
---|
193 | break; |
---|
194 | } |
---|
195 | } |
---|
196 | |
---|
197 | // Send to list |
---|
198 | ui->list_jobname->clear(); |
---|
199 | for (int i=tmphistory.count(); i>=1; i--) |
---|
200 | { |
---|
201 | ui->list_jobname->addItem(tmphistory[i-1]); |
---|
202 | } |
---|
203 | |
---|
204 | } |
---|
205 | return 0; |
---|
206 | } |
---|
207 | |
---|
208 | //****************************************************************************// |
---|
209 | // Exit program |
---|
210 | MainWindow::~MainWindow() |
---|
211 | { |
---|
212 | |
---|
213 | delete ui; |
---|
214 | } |
---|
215 | |
---|
216 | |
---|
217 | //****************************************************************************// |
---|
218 | // Start the mrun command via xterm |
---|
219 | int MainWindow::startmrun() |
---|
220 | { |
---|
221 | |
---|
222 | QString xtermoutput; |
---|
223 | QString mrunline_save; |
---|
224 | QString history_line; |
---|
225 | QString mrunline = ui->commandline->text(); |
---|
226 | QString userline = ui->line_user->text(); |
---|
227 | QRect geomet; |
---|
228 | QString posx; |
---|
229 | QString posy; |
---|
230 | |
---|
231 | // Check for empty line |
---|
232 | mrunline_save = mrunline; |
---|
233 | if (userline != "") |
---|
234 | { |
---|
235 | mrunline = mrunline + " " + userline; |
---|
236 | } |
---|
237 | history_line = mrunline; |
---|
238 | |
---|
239 | // Disable the main window |
---|
240 | ui->group_job->setEnabled(false); |
---|
241 | ui->group_execution->setEnabled(false); |
---|
242 | ui->group_runcontrol->setEnabled(false); |
---|
243 | ui->group_advanced->setEnabled(false); |
---|
244 | ui->check_advanced->setEnabled(false); |
---|
245 | ui->check_verbose->setEnabled(false); |
---|
246 | ui->button_start->setEnabled(false); |
---|
247 | ui->button_start->setText("wait..."); |
---|
248 | |
---|
249 | branch = QCoreApplication::applicationDirPath(); |
---|
250 | branch = branch.left(branch.length() - 14); |
---|
251 | |
---|
252 | ui->commandline->setText("Executing mrun in xterm..."); |
---|
253 | |
---|
254 | // Wait until all commands have been executed (ugly) |
---|
255 | for(int i=0; i<20; i++) |
---|
256 | qApp->processEvents(); |
---|
257 | |
---|
258 | // Start xterm as QProcess |
---|
259 | QProcess mrun; |
---|
260 | mrun.setProcessChannelMode(QProcess::MergedChannels); |
---|
261 | mrun.setWorkingDirectory(branch); |
---|
262 | |
---|
263 | geomet = frameGeometry(); |
---|
264 | |
---|
265 | posx=QString::number(geomet.x()+geomet.width()); |
---|
266 | posy=QString::number(geomet.y()); |
---|
267 | |
---|
268 | mrunline = " -title \"Executing mrun...\" -fa \"Monospace\" -fs 11 -geometry \"80x38+"+posx+"+"+posy+"\" -e \""\ |
---|
269 | +mrunline.replace("\"","\'")\ |
---|
270 | +";echo -n '--> Press enter to continue...';read yesno\"</dev/stdin"; |
---|
271 | |
---|
272 | mrun.start("xterm"+mrunline); |
---|
273 | |
---|
274 | if(!mrun.waitForStarted()) |
---|
275 | return 0; |
---|
276 | |
---|
277 | // while(mrun.waitForReadyRead()) |
---|
278 | // xtermoutput = xtermoutput+mrun.readAllStandardOutput(); |
---|
279 | |
---|
280 | // Wait until mrun has finished or wait for 200 minutes |
---|
281 | mrun.waitForFinished(3600000); |
---|
282 | |
---|
283 | |
---|
284 | // Jobs has been submitted or aborted. Continuing... |
---|
285 | // Save the mrun command to history file |
---|
286 | QString filename = branch+"/.mrun.history"; |
---|
287 | |
---|
288 | QDateTime time = QDateTime::currentDateTime(); |
---|
289 | QString tmptime = time.toString("yyyy/MM/dd hh:mm"); |
---|
290 | |
---|
291 | QFile file(filename); |
---|
292 | file.open(QIODevice::Append | QIODevice::Text); |
---|
293 | QTextStream out(&file); |
---|
294 | out << tmptime + " " + history_line + "\n"; |
---|
295 | file.close(); |
---|
296 | |
---|
297 | // Enable main window again |
---|
298 | ui->group_job->setEnabled(true); |
---|
299 | ui->group_execution->setEnabled(true); |
---|
300 | ui->group_runcontrol->setEnabled(true); |
---|
301 | if ( ui->check_advanced->isChecked() == true) |
---|
302 | { |
---|
303 | ui->group_advanced->setEnabled(true); |
---|
304 | } |
---|
305 | ui->check_advanced->setEnabled(true); |
---|
306 | ui->check_verbose->setEnabled(true); |
---|
307 | ui->button_start->setEnabled(true); |
---|
308 | ui->action_save->setEnabled(true); |
---|
309 | ui->button_start->setText("Start mrun"); |
---|
310 | ui->commandline->setText(mrunline_save); |
---|
311 | |
---|
312 | // Reload recent jobs |
---|
313 | recent_jobs(10); |
---|
314 | |
---|
315 | return 0; |
---|
316 | } |
---|
317 | |
---|
318 | |
---|
319 | //****************************************************************************// |
---|
320 | // Disable/Enable advanced settings dialog |
---|
321 | int MainWindow::enable_advanced() |
---|
322 | { |
---|
323 | bool status; |
---|
324 | |
---|
325 | status = ui->group_advanced->isEnabled(); |
---|
326 | if (status == true) |
---|
327 | { |
---|
328 | ui->group_advanced->setEnabled(false); |
---|
329 | } |
---|
330 | else |
---|
331 | { |
---|
332 | ui->group_advanced->setEnabled(true); |
---|
333 | } |
---|
334 | |
---|
335 | return 0; |
---|
336 | } |
---|
337 | |
---|
338 | |
---|
339 | //****************************************************************************// |
---|
340 | // Disable/enable dialog for coupled runs |
---|
341 | int MainWindow::enable_coupled() |
---|
342 | { |
---|
343 | QString status; |
---|
344 | |
---|
345 | status = ui->drop_job->currentText(); |
---|
346 | if (status == "Coupled restart") |
---|
347 | { |
---|
348 | ui->label_coupled1->setEnabled(true); |
---|
349 | ui->label_coupled2->setEnabled(true); |
---|
350 | ui->label_coupled3->setEnabled(true); |
---|
351 | ui->line_PE_atmos->setEnabled(true); |
---|
352 | ui->line_PE_ocean->setEnabled(true); |
---|
353 | |
---|
354 | QString pe_total = ui->line_pe->text(); |
---|
355 | QString pe_atmos = ui->line_PE_atmos->text(); |
---|
356 | QString pe_ocean = ui->line_PE_ocean->text(); |
---|
357 | if (pe_total != "") |
---|
358 | { |
---|
359 | int PE_split = pe_total.toInt()/2; |
---|
360 | ui->line_PE_atmos->setText(QString::number(PE_split)); |
---|
361 | ui->line_PE_ocean->setText(QString::number(PE_split)); |
---|
362 | } |
---|
363 | } |
---|
364 | else |
---|
365 | { |
---|
366 | ui->label_coupled1->setEnabled(false); |
---|
367 | ui->label_coupled2->setEnabled(false); |
---|
368 | ui->label_coupled3->setEnabled(false); |
---|
369 | ui->line_PE_atmos->setEnabled(false); |
---|
370 | ui->line_PE_ocean->setEnabled(false); |
---|
371 | } |
---|
372 | |
---|
373 | return 0; |
---|
374 | } |
---|
375 | |
---|
376 | |
---|
377 | //****************************************************************************// |
---|
378 | // Choose job from dialog |
---|
379 | int MainWindow::choosejob() |
---|
380 | { |
---|
381 | QString filename; |
---|
382 | branch = QCoreApplication::applicationDirPath(); |
---|
383 | branch = branch.left(branch.length() - 14); |
---|
384 | |
---|
385 | QString jobdir = branch+"/JOBS"; |
---|
386 | |
---|
387 | |
---|
388 | // Pick a job from dialog |
---|
389 | filename = QFileDialog::getExistingDirectory(this, \ |
---|
390 | tr("Choose a job directory"), branch+"/JOBS", \ |
---|
391 | QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | \ |
---|
392 | QFileDialog::DontUseNativeDialog | QFileDialog::ReadOnly | \ |
---|
393 | QFileDialog::DontConfirmOverwrite); |
---|
394 | |
---|
395 | |
---|
396 | |
---|
397 | |
---|
398 | |
---|
399 | // If a file was selected, load it into mainwindow |
---|
400 | if ( filename != "") |
---|
401 | { |
---|
402 | filename = filename.right(filename.length() - jobdir.length() - 1); |
---|
403 | |
---|
404 | ui->line_jobname->setText(filename); |
---|
405 | ui->list_jobname->clearSelection(); |
---|
406 | |
---|
407 | // Change mrunline accordingly |
---|
408 | change_commandline("d",""); |
---|
409 | change_commandline("r",""); |
---|
410 | return 0; |
---|
411 | } |
---|
412 | else |
---|
413 | { |
---|
414 | return 1; |
---|
415 | } |
---|
416 | } |
---|
417 | |
---|
418 | |
---|
419 | //****************************************************************************// |
---|
420 | // Choose job from the recent job list and load all settings |
---|
421 | int MainWindow::choosejob_list() |
---|
422 | { |
---|
423 | QString filename, timestamp, jobname; |
---|
424 | |
---|
425 | // Get selected item from list |
---|
426 | filename = ui->list_jobname->currentItem()->text(); |
---|
427 | int itemint = ui->list_jobname->currentRow(); |
---|
428 | |
---|
429 | // Reload list |
---|
430 | ui->setupUi(this); |
---|
431 | recent_jobs(10); |
---|
432 | |
---|
433 | // Set selected item to jobname |
---|
434 | ui->list_jobname->item(itemint)->setSelected(true); |
---|
435 | |
---|
436 | timestamp = filename.right(17).left(16); |
---|
437 | jobname = filename.left(filename.length() - 19); |
---|
438 | |
---|
439 | branch = QCoreApplication::applicationDirPath(); |
---|
440 | branch = branch.left(branch.length() - 14); |
---|
441 | QFile file(branch+"/.mrun.history"); |
---|
442 | QString listitem; |
---|
443 | |
---|
444 | // Load history |
---|
445 | if ( file.exists() == true && file.size() > 10) |
---|
446 | { |
---|
447 | |
---|
448 | QStringList history; |
---|
449 | if ( file.open(QIODevice::ReadOnly | QIODevice::Text ) ) |
---|
450 | { |
---|
451 | |
---|
452 | // file opened successfully |
---|
453 | QTextStream in(&file); |
---|
454 | |
---|
455 | QString line = in.readLine(); |
---|
456 | while (!line.isNull()) |
---|
457 | { |
---|
458 | history.append(line); |
---|
459 | line = in.readLine(); |
---|
460 | } |
---|
461 | |
---|
462 | file.close(); |
---|
463 | } |
---|
464 | |
---|
465 | for (int i=history.count(); i>=1; i--) |
---|
466 | { |
---|
467 | listitem = history[i-1].right(history[i-1].length() - 17); |
---|
468 | listitem = listitem.split("-d ", QString::SkipEmptyParts)[1]; |
---|
469 | listitem = listitem.split(" -", QString::SkipEmptyParts)[0]; |
---|
470 | listitem = listitem.replace(" ",""); |
---|
471 | |
---|
472 | |
---|
473 | // Select command line with correct timestamp and jobname |
---|
474 | if (history[i-1].left(16) == timestamp && listitem == jobname) |
---|
475 | { |
---|
476 | QString mrunline = history[i-1]; |
---|
477 | mrunline = mrunline.right(mrunline.length() - 17); |
---|
478 | ui->commandline->setText(mrunline); |
---|
479 | |
---|
480 | setup_gui(mrunline); |
---|
481 | } |
---|
482 | } |
---|
483 | } |
---|
484 | |
---|
485 | return 0; |
---|
486 | } |
---|
487 | |
---|
488 | |
---|
489 | //****************************************************************************// |
---|
490 | // Change run identifer (initial, restart, coupled...) |
---|
491 | int MainWindow::change_rc_list() |
---|
492 | { |
---|
493 | |
---|
494 | |
---|
495 | QString drop_job = ui->drop_job->currentText(); |
---|
496 | |
---|
497 | change_commandline("r",""); |
---|
498 | |
---|
499 | // Enable PE distribution for atmosphere/ocean |
---|
500 | if ( drop_job == "Coupled restart") |
---|
501 | { |
---|
502 | QString drop_atmos = ui->line_PE_atmos->text(); |
---|
503 | QString drop_ocean = ui->line_PE_ocean->text(); |
---|
504 | |
---|
505 | change_commandline("Y",drop_atmos+" "+drop_ocean); |
---|
506 | } |
---|
507 | |
---|
508 | // Check of ocean runs |
---|
509 | else |
---|
510 | { |
---|
511 | delete_commandline("Y"); |
---|
512 | if (drop_job == "Precursor run (Ocean)") |
---|
513 | { |
---|
514 | activate_flag("y"); |
---|
515 | } |
---|
516 | else |
---|
517 | { |
---|
518 | deactivate_flag("y"); |
---|
519 | } |
---|
520 | } |
---|
521 | |
---|
522 | |
---|
523 | return 0; |
---|
524 | } |
---|
525 | |
---|
526 | |
---|
527 | //****************************************************************************// |
---|
528 | // Routine for processing any changes in the mainwindow settings |
---|
529 | int MainWindow::change_commandline(QString id,QString fwstring) |
---|
530 | { |
---|
531 | |
---|
532 | // First get the mrunline |
---|
533 | QString newmrunline; |
---|
534 | bool initialize=false; |
---|
535 | |
---|
536 | QString mrunline = ui->commandline->text(); |
---|
537 | |
---|
538 | QStringList splitline = mrunline.split(" -"+id+"", QString::SkipEmptyParts); |
---|
539 | if ( splitline.count() == 1) |
---|
540 | { |
---|
541 | splitline.append(" "); |
---|
542 | } |
---|
543 | else if ( splitline.count() == 0 ) |
---|
544 | { |
---|
545 | splitline.append("mrun"); |
---|
546 | splitline.append(" "); |
---|
547 | initialize = true; |
---|
548 | } |
---|
549 | |
---|
550 | QStringList param = splitline[1].split("-"); |
---|
551 | |
---|
552 | // Change in parameter "d" (jobname) |
---|
553 | if (id == "d") |
---|
554 | { |
---|
555 | QString filename = ui->line_jobname->text(); |
---|
556 | |
---|
557 | param[0] = filename.replace(" ",""); |
---|
558 | |
---|
559 | if ( initialize == true && ui->group_runcontrol->isEnabled() == true ) |
---|
560 | { |
---|
561 | ui->group_runcontrol->setEnabled(true); |
---|
562 | ui->group_execution->setEnabled(true); |
---|
563 | ui->drop_job->setEnabled(true); |
---|
564 | ui->check_advanced->setEnabled(true); |
---|
565 | ui->button_start->setEnabled(true); |
---|
566 | ui->action_save->setEnabled(true); |
---|
567 | } |
---|
568 | else if ( param[0] == "") |
---|
569 | { |
---|
570 | ui->group_runcontrol->setEnabled(false); |
---|
571 | ui->group_execution->setEnabled(false); |
---|
572 | ui->drop_job->setEnabled(false); |
---|
573 | ui->button_start->setEnabled(false); |
---|
574 | ui->action_save->setEnabled(false); |
---|
575 | ui->group_advanced->setEnabled(false); |
---|
576 | ui->check_advanced->setEnabled(false); |
---|
577 | delete_commandline("d"); |
---|
578 | change_commandline("r","remove"); |
---|
579 | ui->label_usercode->setText(""); |
---|
580 | return 1; |
---|
581 | } |
---|
582 | else |
---|
583 | { |
---|
584 | |
---|
585 | // Check if user code is available |
---|
586 | branch = QCoreApplication::applicationDirPath(); |
---|
587 | branch = branch.left(branch.length() - 14); |
---|
588 | QDir usercode = branch+"/USER_CODE/"+param[0]; |
---|
589 | if (usercode.exists() == true) |
---|
590 | { |
---|
591 | ui->label_usercode->setText("<font color='green'>User code found.</font>"); |
---|
592 | } |
---|
593 | else |
---|
594 | { |
---|
595 | ui->label_usercode->setText("<font color='red'>Warning: no user code found!</font>"); |
---|
596 | } |
---|
597 | |
---|
598 | // Check if _pdf file is available, otherwise notice user |
---|
599 | if (ui->check_restarts->checkState() == 2) |
---|
600 | { |
---|
601 | QString jobname = ui->line_jobname->text(); |
---|
602 | QFile restartfile(branch+"/JOBS/"+jobname+"/INPUT/"+jobname+"_p3df"); |
---|
603 | if (restartfile.exists() == true) |
---|
604 | { |
---|
605 | ui->label_restart->setText(""); |
---|
606 | } |
---|
607 | else |
---|
608 | { |
---|
609 | ui->label_restart->setText("<font color='red'>Warning: No p3df file found!</font>"); |
---|
610 | } |
---|
611 | } |
---|
612 | |
---|
613 | ui->group_runcontrol->setEnabled(true); |
---|
614 | ui->group_execution->setEnabled(true); |
---|
615 | ui->drop_job->setEnabled(true); |
---|
616 | ui->check_advanced->setEnabled(true); |
---|
617 | |
---|
618 | if ( ui->check_advanced->isChecked() == true ) |
---|
619 | { |
---|
620 | ui->group_advanced->setEnabled(true); |
---|
621 | if ( ui->line_i->text() != "" || ui->line_o->text() != "") |
---|
622 | { |
---|
623 | change_commandline("r","remove"); |
---|
624 | ui->group_runcontrol->setEnabled(false); |
---|
625 | } |
---|
626 | } |
---|
627 | } |
---|
628 | |
---|
629 | } |
---|
630 | |
---|
631 | // Change in parameter "r" (run control list) |
---|
632 | else if (id == "r") |
---|
633 | { |
---|
634 | int status_ts = ui->check_ts->checkState(); |
---|
635 | int status_pr = ui->check_pr->checkState(); |
---|
636 | int status_xy = ui->check_xy->checkState(); |
---|
637 | int status_xz = ui->check_xz->checkState(); |
---|
638 | int status_yz = ui->check_yz->checkState(); |
---|
639 | int status_3d = ui->check_3d->checkState(); |
---|
640 | int status_ma = ui->check_ma->checkState(); |
---|
641 | int status_sp = ui->check_sp->checkState(); |
---|
642 | int status_pts = ui->check_pts->checkState(); |
---|
643 | int status_prt = ui->check_prt->checkState(); |
---|
644 | |
---|
645 | QString drop_job = ui->drop_job->currentText(); |
---|
646 | QString rc_flag = "#"; |
---|
647 | |
---|
648 | if (drop_job == "Initial run") |
---|
649 | { |
---|
650 | rc_flag = "#"; |
---|
651 | } |
---|
652 | else if (drop_job == "Restart run") |
---|
653 | { |
---|
654 | rc_flag = "f"; |
---|
655 | } |
---|
656 | else if (drop_job == "Precursor run (Atmosphere)") |
---|
657 | { |
---|
658 | rc_flag = "#"; |
---|
659 | } |
---|
660 | else if (drop_job == "Precursor run (Ocean)") |
---|
661 | { |
---|
662 | rc_flag = "o#"; |
---|
663 | } |
---|
664 | else if (drop_job == "Coupled restart") |
---|
665 | { |
---|
666 | rc_flag = "f"; |
---|
667 | } |
---|
668 | |
---|
669 | param[0] = "\"d3"+rc_flag; |
---|
670 | |
---|
671 | if (status_ts == 2) |
---|
672 | { |
---|
673 | param[0] = param[0]+" ts"+rc_flag; |
---|
674 | } |
---|
675 | if (status_pr == 2) |
---|
676 | { |
---|
677 | param[0] = param[0]+" pr"+rc_flag; |
---|
678 | } |
---|
679 | if (status_xy == 2) |
---|
680 | { |
---|
681 | param[0] = param[0]+" xy"+rc_flag; |
---|
682 | } |
---|
683 | if (status_xz == 2) |
---|
684 | { |
---|
685 | param[0] = param[0]+" xz"+rc_flag; |
---|
686 | } |
---|
687 | if (status_yz == 2) |
---|
688 | { |
---|
689 | param[0] = param[0]+" yz"+rc_flag; |
---|
690 | } |
---|
691 | if (status_3d == 2) |
---|
692 | { |
---|
693 | param[0] = param[0]+" 3d"+rc_flag; |
---|
694 | } |
---|
695 | if (status_ma == 2) |
---|
696 | { |
---|
697 | param[0] = param[0]+" ma"+rc_flag; |
---|
698 | } |
---|
699 | if (status_sp == 2) |
---|
700 | { |
---|
701 | param[0] = param[0]+" sp"+rc_flag; |
---|
702 | } |
---|
703 | if (status_prt == 2) |
---|
704 | { |
---|
705 | param[0] = param[0]+" prt"+rc_flag; |
---|
706 | } |
---|
707 | if (status_pts == 2) |
---|
708 | { |
---|
709 | param[0] = param[0]+" pts"+rc_flag; |
---|
710 | } |
---|
711 | |
---|
712 | if (drop_job == "Coupled restart") |
---|
713 | { |
---|
714 | rc_flag = "of"; |
---|
715 | param[0] = param[0]+" d3"+rc_flag; |
---|
716 | |
---|
717 | if (status_ts == 2) |
---|
718 | { |
---|
719 | param[0] = param[0]+" ts"+rc_flag; |
---|
720 | } |
---|
721 | if (status_pr == 2) |
---|
722 | { |
---|
723 | param[0] = param[0]+" pr"+rc_flag; |
---|
724 | } |
---|
725 | if (status_xy == 2) |
---|
726 | { |
---|
727 | param[0] = param[0]+" xy"+rc_flag; |
---|
728 | } |
---|
729 | if (status_xz == 2) |
---|
730 | { |
---|
731 | param[0] = param[0]+" xz"+rc_flag; |
---|
732 | } |
---|
733 | if (status_yz == 2) |
---|
734 | { |
---|
735 | param[0] = param[0]+" yz"+rc_flag; |
---|
736 | } |
---|
737 | if (status_3d == 2) |
---|
738 | { |
---|
739 | param[0] = param[0]+" 3d"+rc_flag; |
---|
740 | } |
---|
741 | if (status_ma == 2) |
---|
742 | { |
---|
743 | param[0] = param[0]+" ma"+rc_flag; |
---|
744 | } |
---|
745 | if (status_sp == 2) |
---|
746 | { |
---|
747 | param[0] = param[0]+" sp"+rc_flag; |
---|
748 | } |
---|
749 | if (status_prt == 2) |
---|
750 | { |
---|
751 | param[0] = param[0]+" prt"+rc_flag; |
---|
752 | } |
---|
753 | if (status_pts == 2) |
---|
754 | { |
---|
755 | param[0] = param[0]+" pts"+rc_flag; |
---|
756 | } |
---|
757 | } |
---|
758 | |
---|
759 | int status_restarts = ui->check_restarts->checkState(); |
---|
760 | |
---|
761 | |
---|
762 | |
---|
763 | if (status_restarts == 2) |
---|
764 | { |
---|
765 | param[0]=param[0]+" restart"; |
---|
766 | |
---|
767 | // Check if _pdf file is available, otherwise notice user |
---|
768 | if (ui->check_restarts->checkState() == 2) |
---|
769 | { |
---|
770 | QString jobname = ui->line_jobname->text(); |
---|
771 | branch = QCoreApplication::applicationDirPath(); |
---|
772 | branch = branch.left(branch.length() - 14); |
---|
773 | QFile restartfile(branch+"/JOBS/"+jobname+"/INPUT/"+jobname+ \ |
---|
774 | "_p3df"); |
---|
775 | if (restartfile.exists() == true) |
---|
776 | { |
---|
777 | ui->label_restart->setText(""); |
---|
778 | } |
---|
779 | else |
---|
780 | { |
---|
781 | ui->label_restart->setText("<font color='red'>Warning: No p3df file found!</font>"); |
---|
782 | } |
---|
783 | } |
---|
784 | |
---|
785 | } |
---|
786 | else { |
---|
787 | ui->label_restart->setText(""); |
---|
788 | } |
---|
789 | |
---|
790 | |
---|
791 | |
---|
792 | int status_cycfill = ui->check_cycfill->checkState(); |
---|
793 | |
---|
794 | if (status_cycfill == 2) |
---|
795 | { |
---|
796 | param[0]=param[0]+" cycfill"; |
---|
797 | } |
---|
798 | |
---|
799 | |
---|
800 | |
---|
801 | param[0]=param[0]+"\" "; |
---|
802 | |
---|
803 | if ( fwstring == "remove") |
---|
804 | { |
---|
805 | delete_commandline(id); |
---|
806 | return 1; |
---|
807 | } |
---|
808 | else |
---|
809 | { |
---|
810 | ui->button_start->setEnabled(true); |
---|
811 | ui->action_save->setEnabled(true); |
---|
812 | } |
---|
813 | } |
---|
814 | // Change in any other parameter |
---|
815 | else |
---|
816 | { |
---|
817 | if ( fwstring != "") |
---|
818 | { |
---|
819 | param[0] = "\""+fwstring+"\""; |
---|
820 | } |
---|
821 | else |
---|
822 | { |
---|
823 | delete_commandline(id); |
---|
824 | return 1; |
---|
825 | } |
---|
826 | |
---|
827 | } |
---|
828 | param[0] = param[0] + " "; |
---|
829 | |
---|
830 | // Join the new mrunline |
---|
831 | splitline[1]= param.join("-"); |
---|
832 | newmrunline = splitline.join(" -"+id+" "); |
---|
833 | |
---|
834 | // Print the new mrunline to mainwindow |
---|
835 | newmrunline.replace(" "," "); |
---|
836 | ui->commandline->setText(newmrunline); |
---|
837 | |
---|
838 | return 0; |
---|
839 | } |
---|
840 | |
---|
841 | |
---|
842 | //****************************************************************************// |
---|
843 | // Get all signals from mainwindow and perform change via change_commandline() |
---|
844 | int MainWindow::change_lineinput() |
---|
845 | { |
---|
846 | QString tmptext; |
---|
847 | |
---|
848 | if ( sender() == ui->line_host ) |
---|
849 | { |
---|
850 | tmptext = ui->line_host->text(); |
---|
851 | change_commandline("h",tmptext); |
---|
852 | } |
---|
853 | else if ( sender() == ui->line_jobname) |
---|
854 | { |
---|
855 | tmptext = ui->line_jobname->text(); |
---|
856 | change_commandline("d",tmptext); |
---|
857 | } |
---|
858 | else if ( sender() == ui->line_q) |
---|
859 | { |
---|
860 | tmptext = ui->line_q->text(); |
---|
861 | change_commandline("q",tmptext); |
---|
862 | } |
---|
863 | else if ( sender() == ui->line_account) |
---|
864 | { |
---|
865 | tmptext = ui->line_account->text(); |
---|
866 | change_commandline("u",tmptext); |
---|
867 | } |
---|
868 | else if ( sender() == ui->line_pe) |
---|
869 | { |
---|
870 | tmptext = ui->line_pe->text(); |
---|
871 | change_commandline("X",tmptext); |
---|
872 | } |
---|
873 | else if ( sender() == ui->line_tpn) |
---|
874 | { |
---|
875 | tmptext = ui->line_tpn->text(); |
---|
876 | change_commandline("T",tmptext); |
---|
877 | } |
---|
878 | else if ( sender() == ui->line_branch) |
---|
879 | { |
---|
880 | tmptext = ui->line_branch->text(); |
---|
881 | change_commandline("K",tmptext); |
---|
882 | } |
---|
883 | else if ( sender() == ui->line_time) |
---|
884 | { |
---|
885 | tmptext = ui->line_time->text(); |
---|
886 | change_commandline("t",tmptext); |
---|
887 | } |
---|
888 | else if ( sender() == ui->line_M) |
---|
889 | { |
---|
890 | tmptext = ui->line_M->text(); |
---|
891 | change_commandline("M",tmptext); |
---|
892 | } |
---|
893 | else if ( sender() == ui->line_m) |
---|
894 | { |
---|
895 | tmptext = ui->line_m->text(); |
---|
896 | change_commandline("m",tmptext); |
---|
897 | } |
---|
898 | else if ( sender() == ui->line_a) |
---|
899 | { |
---|
900 | tmptext = ui->line_a->text(); |
---|
901 | change_commandline("a",tmptext); |
---|
902 | } |
---|
903 | else if ( sender() == ui->line_D) |
---|
904 | { |
---|
905 | tmptext = ui->line_D->text(); |
---|
906 | change_commandline("D",tmptext); |
---|
907 | } |
---|
908 | else if ( sender() == ui->line_c) |
---|
909 | { |
---|
910 | tmptext = ui->line_c->text(); |
---|
911 | if ( tmptext == ".mrun.config") |
---|
912 | { |
---|
913 | tmptext = ""; |
---|
914 | } |
---|
915 | change_commandline("c",tmptext); |
---|
916 | } |
---|
917 | else if ( sender() == ui->line_p) |
---|
918 | { |
---|
919 | tmptext = ui->line_p->text(); |
---|
920 | change_commandline("p",tmptext); |
---|
921 | } |
---|
922 | else if ( sender() == ui->line_s) |
---|
923 | { |
---|
924 | tmptext = ui->line_s->text(); |
---|
925 | change_commandline("s",tmptext); |
---|
926 | } |
---|
927 | else if ( sender() == ui->line_i) |
---|
928 | { |
---|
929 | tmptext = ui->line_i->text(); |
---|
930 | if ( tmptext != "") |
---|
931 | { |
---|
932 | change_commandline("r","remove"); |
---|
933 | ui->group_runcontrol->setEnabled(false); |
---|
934 | |
---|
935 | ui->button_start->setEnabled(true); |
---|
936 | ui->action_save->setEnabled(true); |
---|
937 | } |
---|
938 | else if (ui->line_o->text() == "" ) |
---|
939 | { |
---|
940 | ui->group_runcontrol->setEnabled(true); |
---|
941 | change_commandline("r",""); |
---|
942 | } |
---|
943 | |
---|
944 | change_commandline("i",tmptext); |
---|
945 | } |
---|
946 | else if ( sender() == ui->line_o) |
---|
947 | { |
---|
948 | tmptext = ui->line_o->text(); |
---|
949 | if ( tmptext != "") |
---|
950 | { |
---|
951 | change_commandline("r","remove"); |
---|
952 | ui->button_start->setEnabled(true); |
---|
953 | ui->action_save->setEnabled(true); |
---|
954 | ui->group_runcontrol->setEnabled(false); |
---|
955 | } |
---|
956 | else if (ui->line_i->text() == "" ) |
---|
957 | { |
---|
958 | ui->group_runcontrol->setEnabled(true); |
---|
959 | change_commandline("r",""); |
---|
960 | } |
---|
961 | |
---|
962 | change_commandline("o",tmptext); |
---|
963 | |
---|
964 | } |
---|
965 | else if ( sender() == ui->line_w) |
---|
966 | { |
---|
967 | tmptext = ui->line_w->text(); |
---|
968 | change_commandline("w",tmptext); |
---|
969 | } |
---|
970 | else if ( sender() == ui->line_PE_atmos || sender() == ui->line_PE_ocean) |
---|
971 | { |
---|
972 | tmptext = ui->line_PE_atmos->text() + " " + ui->line_PE_ocean->text(); |
---|
973 | change_commandline("Y",tmptext); |
---|
974 | int PE_total = ui->line_PE_atmos->text().toInt() + \ |
---|
975 | ui->line_PE_ocean->text().toInt(); |
---|
976 | ui->line_pe->setText(QString::number(PE_total)); |
---|
977 | change_commandline("X",QString::number(PE_total)); |
---|
978 | } |
---|
979 | |
---|
980 | else if ( sender() == ui->combo_n) |
---|
981 | { |
---|
982 | tmptext = ui->combo_n->currentText(); |
---|
983 | if ( tmptext == "default") |
---|
984 | { |
---|
985 | tmptext = ""; |
---|
986 | } |
---|
987 | change_commandline("n",tmptext); |
---|
988 | } |
---|
989 | else if ( sender() == ui->line_user) |
---|
990 | { |
---|
991 | return 0; |
---|
992 | } |
---|
993 | |
---|
994 | return 0; |
---|
995 | } |
---|
996 | |
---|
997 | |
---|
998 | //****************************************************************************// |
---|
999 | // Delete a parameter from mrunline |
---|
1000 | int MainWindow::delete_commandline(QString id) |
---|
1001 | { |
---|
1002 | |
---|
1003 | // Read mrunline |
---|
1004 | QString newmrunline; |
---|
1005 | QString mrunline = ui->commandline->text(); |
---|
1006 | QStringList splitline = mrunline.split(" -"+id, QString::SkipEmptyParts); |
---|
1007 | if ( splitline.count() == 1) |
---|
1008 | { |
---|
1009 | return 0; |
---|
1010 | } |
---|
1011 | else |
---|
1012 | { |
---|
1013 | QStringList param = splitline[1].split("-"); |
---|
1014 | param[0] = ""; |
---|
1015 | splitline[1]= param.join(" -"); |
---|
1016 | newmrunline = splitline.join(""); |
---|
1017 | |
---|
1018 | // Print new mrunline to screen |
---|
1019 | ui->commandline->setText(newmrunline); |
---|
1020 | |
---|
1021 | return 0; |
---|
1022 | } |
---|
1023 | } |
---|
1024 | |
---|
1025 | |
---|
1026 | //****************************************************************************// |
---|
1027 | // Check routine for all flag parameters |
---|
1028 | int MainWindow::check_flags() |
---|
1029 | { |
---|
1030 | |
---|
1031 | int status = ui->check_delete_tmp_files->checkState(); |
---|
1032 | |
---|
1033 | if (status == 2) |
---|
1034 | { |
---|
1035 | activate_flag("B"); |
---|
1036 | } |
---|
1037 | else |
---|
1038 | { |
---|
1039 | deactivate_flag("B"); |
---|
1040 | } |
---|
1041 | |
---|
1042 | status = ui->check_verbose->checkState(); |
---|
1043 | |
---|
1044 | if (status == 2) |
---|
1045 | { |
---|
1046 | activate_flag("v"); |
---|
1047 | } |
---|
1048 | else |
---|
1049 | { |
---|
1050 | deactivate_flag("v"); |
---|
1051 | } |
---|
1052 | |
---|
1053 | status = ui->check_A->checkState(); |
---|
1054 | |
---|
1055 | if (status == 2) |
---|
1056 | { |
---|
1057 | activate_flag("A"); |
---|
1058 | } |
---|
1059 | else |
---|
1060 | { |
---|
1061 | deactivate_flag("A"); |
---|
1062 | } |
---|
1063 | |
---|
1064 | status = ui->check_b->checkState(); |
---|
1065 | |
---|
1066 | if (status == 2) |
---|
1067 | { |
---|
1068 | activate_flag("b"); |
---|
1069 | } |
---|
1070 | else |
---|
1071 | { |
---|
1072 | deactivate_flag("b"); |
---|
1073 | } |
---|
1074 | |
---|
1075 | status = ui->check_F->checkState(); |
---|
1076 | |
---|
1077 | if (status == 2) |
---|
1078 | { |
---|
1079 | activate_flag("F"); |
---|
1080 | } |
---|
1081 | else |
---|
1082 | { |
---|
1083 | deactivate_flag("F"); |
---|
1084 | } |
---|
1085 | status = ui->check_I->checkState(); |
---|
1086 | |
---|
1087 | if (status == 2) |
---|
1088 | { |
---|
1089 | activate_flag("I"); |
---|
1090 | } |
---|
1091 | else |
---|
1092 | { |
---|
1093 | deactivate_flag("I"); |
---|
1094 | } |
---|
1095 | status = ui->check_k->checkState(); |
---|
1096 | |
---|
1097 | if (status == 2) |
---|
1098 | { |
---|
1099 | activate_flag("k"); |
---|
1100 | } |
---|
1101 | else |
---|
1102 | { |
---|
1103 | deactivate_flag("k"); |
---|
1104 | } |
---|
1105 | status = ui->check_O->checkState(); |
---|
1106 | |
---|
1107 | if (status == 2) |
---|
1108 | { |
---|
1109 | activate_flag("O"); |
---|
1110 | } |
---|
1111 | else |
---|
1112 | { |
---|
1113 | deactivate_flag("O"); |
---|
1114 | } |
---|
1115 | status = ui->check_S->checkState(); |
---|
1116 | |
---|
1117 | if (status == 2) |
---|
1118 | { |
---|
1119 | activate_flag("S"); |
---|
1120 | } |
---|
1121 | else |
---|
1122 | { |
---|
1123 | deactivate_flag("S"); |
---|
1124 | } |
---|
1125 | status = ui->check_x->checkState(); |
---|
1126 | |
---|
1127 | if (status == 2) |
---|
1128 | { |
---|
1129 | activate_flag("x"); |
---|
1130 | } |
---|
1131 | else |
---|
1132 | { |
---|
1133 | deactivate_flag("x"); |
---|
1134 | } |
---|
1135 | |
---|
1136 | status = ui->check_Z->checkState(); |
---|
1137 | |
---|
1138 | if (status == 2) |
---|
1139 | { |
---|
1140 | activate_flag("Z"); |
---|
1141 | } |
---|
1142 | else |
---|
1143 | { |
---|
1144 | deactivate_flag("Z"); |
---|
1145 | } |
---|
1146 | return 0; |
---|
1147 | |
---|
1148 | } |
---|
1149 | |
---|
1150 | |
---|
1151 | //****************************************************************************// |
---|
1152 | // Activate flag |
---|
1153 | int MainWindow::activate_flag(QString id) |
---|
1154 | { |
---|
1155 | QString newmrunline; |
---|
1156 | |
---|
1157 | QString mrunline = ui->commandline->text(); |
---|
1158 | |
---|
1159 | QStringList splitline = mrunline.split(" -"+id, QString::SkipEmptyParts); |
---|
1160 | if ( splitline.count() == 1) |
---|
1161 | { |
---|
1162 | splitline.append(""); |
---|
1163 | newmrunline = splitline.join(" -"+id); |
---|
1164 | |
---|
1165 | // print new commandline to screen |
---|
1166 | newmrunline.replace(" "," "); |
---|
1167 | ui->commandline->setText(newmrunline); |
---|
1168 | |
---|
1169 | return 0; |
---|
1170 | } |
---|
1171 | else |
---|
1172 | { |
---|
1173 | return 0; |
---|
1174 | } |
---|
1175 | } |
---|
1176 | |
---|
1177 | |
---|
1178 | //****************************************************************************// |
---|
1179 | // Deactivate flag |
---|
1180 | int MainWindow::deactivate_flag(QString id) |
---|
1181 | { |
---|
1182 | QString newmrunline; |
---|
1183 | |
---|
1184 | QString mrunline = ui->commandline->text(); |
---|
1185 | |
---|
1186 | QStringList splitline = mrunline.split(" -"+id, QString::SkipEmptyParts); |
---|
1187 | |
---|
1188 | newmrunline = splitline.join(""); |
---|
1189 | // print new commandline to screen |
---|
1190 | newmrunline.replace(" "," "); |
---|
1191 | ui->commandline->setText(newmrunline); |
---|
1192 | |
---|
1193 | return 0; |
---|
1194 | } |
---|
1195 | |
---|
1196 | |
---|
1197 | //****************************************************************************// |
---|
1198 | // Mainwindow reset |
---|
1199 | int MainWindow::reset_window() |
---|
1200 | { |
---|
1201 | ui->setupUi(this); |
---|
1202 | recent_jobs(10); |
---|
1203 | return 0; |
---|
1204 | } |
---|
1205 | |
---|
1206 | |
---|
1207 | //****************************************************************************// |
---|
1208 | // Save current setting as default |
---|
1209 | int MainWindow::save_default() |
---|
1210 | { |
---|
1211 | |
---|
1212 | // Get mrunline |
---|
1213 | QString mrunline_save; |
---|
1214 | QString mrunline = ui->commandline->text(); |
---|
1215 | QString userline = ui->line_user->text(); |
---|
1216 | |
---|
1217 | mrunline_save = mrunline; |
---|
1218 | if (userline != "") |
---|
1219 | { |
---|
1220 | mrunline = mrunline + " " + userline; |
---|
1221 | } |
---|
1222 | |
---|
1223 | |
---|
1224 | // Define filename |
---|
1225 | branch = QCoreApplication::applicationDirPath(); |
---|
1226 | branch = branch.left(branch.length() - 14); |
---|
1227 | |
---|
1228 | QString filename = branch+"/.mrun.gui.default"; |
---|
1229 | |
---|
1230 | // Prepare data output |
---|
1231 | QDateTime time = QDateTime::currentDateTime(); |
---|
1232 | QString tmptime = time.toString("yyyy/MM/dd hh:mm"); |
---|
1233 | |
---|
1234 | // Write to file |
---|
1235 | QFile file(filename); |
---|
1236 | file.open(QIODevice::WriteOnly | QIODevice::Text); |
---|
1237 | QTextStream out(&file); |
---|
1238 | if ( mrunline == "" || mrunline == " ") |
---|
1239 | { |
---|
1240 | out << ""; |
---|
1241 | } |
---|
1242 | else |
---|
1243 | { |
---|
1244 | out << tmptime + " " + mrunline; |
---|
1245 | } |
---|
1246 | |
---|
1247 | file.close(); |
---|
1248 | |
---|
1249 | return 0; |
---|
1250 | } |
---|
1251 | |
---|
1252 | |
---|
1253 | //****************************************************************************// |
---|
1254 | // Save current settings to a file of choice |
---|
1255 | int MainWindow::save_to_file() |
---|
1256 | { |
---|
1257 | |
---|
1258 | // Get mrunline |
---|
1259 | QString mrunline_save; |
---|
1260 | QString mrunline = ui->commandline->text(); |
---|
1261 | QString userline = ui->line_user->text(); |
---|
1262 | |
---|
1263 | mrunline_save = mrunline; |
---|
1264 | if (userline != "") |
---|
1265 | { |
---|
1266 | mrunline = mrunline + " " + userline; |
---|
1267 | } |
---|
1268 | |
---|
1269 | // Define a filename |
---|
1270 | QString filename = QFileDialog::getSaveFileName(this, tr("Save to file"), \ |
---|
1271 | "", tr("Save files (*.sav)")); |
---|
1272 | QString extension = filename.right(4); |
---|
1273 | |
---|
1274 | if ( extension != ".sav" ) |
---|
1275 | { |
---|
1276 | filename = filename + ".sav"; |
---|
1277 | } |
---|
1278 | |
---|
1279 | // Prepare data output |
---|
1280 | QDateTime time = QDateTime::currentDateTime(); |
---|
1281 | QString tmptime = time.toString("yyyy/MM/dd hh:mm"); |
---|
1282 | |
---|
1283 | // Write to file |
---|
1284 | QFile file(filename); |
---|
1285 | file.open(QIODevice::WriteOnly | QIODevice::Text); |
---|
1286 | QTextStream out(&file); |
---|
1287 | out << tmptime + " " + mrunline; |
---|
1288 | file.close(); |
---|
1289 | |
---|
1290 | return 0; |
---|
1291 | } |
---|
1292 | |
---|
1293 | //****************************************************************************// |
---|
1294 | // Start watchdog (palm_wd) |
---|
1295 | int MainWindow::start_watchdog() |
---|
1296 | { |
---|
1297 | return system("nohup palm_wd >> /dev/null 2>&1 &"); |
---|
1298 | |
---|
1299 | } |
---|
1300 | |
---|
1301 | //****************************************************************************// |
---|
1302 | // Start job manager (palm_jm) |
---|
1303 | int MainWindow::start_jobmanager() |
---|
1304 | { |
---|
1305 | return system("nohup palm_jm >> /dev/null 2>&1 &"); |
---|
1306 | |
---|
1307 | } |
---|
1308 | |
---|
1309 | |
---|
1310 | //****************************************************************************// |
---|
1311 | // Open job from file (previously saved by the user) |
---|
1312 | int MainWindow::open_from_file() |
---|
1313 | { |
---|
1314 | |
---|
1315 | // Select filename and open it |
---|
1316 | QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), \ |
---|
1317 | "", tr("Save files (*.sav)")); |
---|
1318 | |
---|
1319 | QFile file(filename); |
---|
1320 | QString mrunline; |
---|
1321 | if ( filename != "") |
---|
1322 | { |
---|
1323 | if ( file.open(QIODevice::ReadOnly | QIODevice::Text ) ) |
---|
1324 | { |
---|
1325 | |
---|
1326 | // File opened successfully |
---|
1327 | QTextStream in(&file); |
---|
1328 | |
---|
1329 | QString line = in.readLine(); |
---|
1330 | while (!line.isNull()) |
---|
1331 | { |
---|
1332 | mrunline = line; |
---|
1333 | line = in.readLine(); |
---|
1334 | } |
---|
1335 | file.close(); |
---|
1336 | } |
---|
1337 | |
---|
1338 | // In case a mrunline was found, load it to mainwindow |
---|
1339 | if ( mrunline != "") |
---|
1340 | { |
---|
1341 | |
---|
1342 | mrunline = mrunline.right(mrunline.length() - 17); |
---|
1343 | ui->commandline->setText(mrunline); |
---|
1344 | |
---|
1345 | setup_gui(mrunline); |
---|
1346 | } |
---|
1347 | } |
---|
1348 | return 0; |
---|
1349 | } |
---|
1350 | |
---|
1351 | |
---|
1352 | //****************************************************************************// |
---|
1353 | // Open the last submitted job |
---|
1354 | int MainWindow::open_last() |
---|
1355 | { |
---|
1356 | branch = QCoreApplication::applicationDirPath(); |
---|
1357 | branch = branch.left(branch.length() - 14); |
---|
1358 | |
---|
1359 | QFile file(branch+"/.mrun.history"); |
---|
1360 | |
---|
1361 | // Load mrun history |
---|
1362 | QString mrunline; |
---|
1363 | if ( file.open(QIODevice::ReadOnly | QIODevice::Text ) ) |
---|
1364 | { |
---|
1365 | |
---|
1366 | // file opened successfully |
---|
1367 | QTextStream in(&file); |
---|
1368 | |
---|
1369 | QString line = in.readLine(); |
---|
1370 | while (!line.isNull()) |
---|
1371 | { |
---|
1372 | mrunline = line; |
---|
1373 | line = in.readLine(); |
---|
1374 | } |
---|
1375 | |
---|
1376 | file.close(); |
---|
1377 | } |
---|
1378 | |
---|
1379 | // Select the last submitted job and print it to mainwindow |
---|
1380 | if ( mrunline != "" ) |
---|
1381 | { |
---|
1382 | mrunline = mrunline.right(mrunline.length() - 17); |
---|
1383 | ui->commandline->setText(mrunline); |
---|
1384 | |
---|
1385 | setup_gui(mrunline); |
---|
1386 | } |
---|
1387 | return 0; |
---|
1388 | } |
---|
1389 | |
---|
1390 | //****************************************************************************// |
---|
1391 | // Display help window |
---|
1392 | int MainWindow::help() |
---|
1393 | { |
---|
1394 | |
---|
1395 | QDialog *child_help = new QDialog; |
---|
1396 | Ui::child_help ui; |
---|
1397 | ui.setupUi(child_help); |
---|
1398 | child_help->show(); |
---|
1399 | |
---|
1400 | |
---|
1401 | return 0; |
---|
1402 | } |
---|
1403 | |
---|
1404 | //****************************************************************************// |
---|
1405 | // Display about window |
---|
1406 | int MainWindow::about_gui() |
---|
1407 | { |
---|
1408 | |
---|
1409 | QDialog *about = new QDialog; |
---|
1410 | Ui::about ui; |
---|
1411 | ui.setupUi(about); |
---|
1412 | about->show(); |
---|
1413 | |
---|
1414 | return 0; |
---|
1415 | } |
---|
1416 | |
---|
1417 | //****************************************************************************// |
---|
1418 | // Setup mainwindow according to a given mrunline |
---|
1419 | int MainWindow::setup_gui(QString mrunline) |
---|
1420 | { |
---|
1421 | |
---|
1422 | // Some initial settings |
---|
1423 | QString user = ""; |
---|
1424 | |
---|
1425 | bool coupled_run = false; |
---|
1426 | bool ocean_run = false; |
---|
1427 | bool advanced = false; |
---|
1428 | bool nojob = false; |
---|
1429 | bool rc_manual = false; |
---|
1430 | |
---|
1431 | // Split parameters in mrunline |
---|
1432 | QStringList splitline = mrunline.split(" -", QString::SkipEmptyParts); |
---|
1433 | |
---|
1434 | if ( splitline[0] != "mrun") |
---|
1435 | { |
---|
1436 | return 1; |
---|
1437 | |
---|
1438 | } |
---|
1439 | else |
---|
1440 | { |
---|
1441 | ui->group_job->setEnabled(true); |
---|
1442 | |
---|
1443 | // Loop for all parameters in mrunline |
---|
1444 | for(int i=splitline.count()-1; i>=1; i--) |
---|
1445 | { |
---|
1446 | |
---|
1447 | // Determine parameter |
---|
1448 | QStringList splitparameter = splitline[i].split(" ", \ |
---|
1449 | QString::SkipEmptyParts); |
---|
1450 | |
---|
1451 | QString parameter = splitparameter[0]; |
---|
1452 | splitparameter.removeFirst(); |
---|
1453 | QString options = splitparameter.join(" "); |
---|
1454 | options = options.replace("\"",""); |
---|
1455 | |
---|
1456 | // Check for suitable switch |
---|
1457 | if ( parameter == "d") |
---|
1458 | { |
---|
1459 | if ( options != "") |
---|
1460 | { |
---|
1461 | ui->line_jobname->setText(options); |
---|
1462 | nojob = false; |
---|
1463 | } |
---|
1464 | else |
---|
1465 | { |
---|
1466 | nojob = true; |
---|
1467 | } |
---|
1468 | } |
---|
1469 | else if ( parameter == "h") |
---|
1470 | { |
---|
1471 | ui->line_host->setText(options); |
---|
1472 | } |
---|
1473 | else if ( parameter == "q") |
---|
1474 | { |
---|
1475 | ui->line_q->setText(options); |
---|
1476 | } |
---|
1477 | else if ( parameter == "K") |
---|
1478 | { |
---|
1479 | ui->line_branch->setText(options); |
---|
1480 | } |
---|
1481 | else if ( parameter == "u") |
---|
1482 | { |
---|
1483 | ui->line_account->setText(options); |
---|
1484 | } |
---|
1485 | else if ( parameter == "X") |
---|
1486 | { |
---|
1487 | ui->line_pe->setText(options); |
---|
1488 | } |
---|
1489 | else if ( parameter == "T") |
---|
1490 | { |
---|
1491 | ui->line_tpn->setText(options); |
---|
1492 | } |
---|
1493 | else if ( parameter == "t") |
---|
1494 | { |
---|
1495 | ui->line_time->setText(options); |
---|
1496 | } |
---|
1497 | else if ( parameter == "B") |
---|
1498 | { |
---|
1499 | ui->check_delete_tmp_files->setChecked(true); |
---|
1500 | } |
---|
1501 | else if ( parameter == "v") |
---|
1502 | { |
---|
1503 | ui->check_verbose->setChecked(true); |
---|
1504 | } |
---|
1505 | else if ( parameter == "A") |
---|
1506 | { |
---|
1507 | ui->check_A->setChecked(true); |
---|
1508 | } |
---|
1509 | else if ( parameter == "b") |
---|
1510 | { |
---|
1511 | ui->check_b->setChecked(true); |
---|
1512 | advanced = true; |
---|
1513 | } |
---|
1514 | else if ( parameter == "F") |
---|
1515 | { |
---|
1516 | ui->check_F->setChecked(true); |
---|
1517 | advanced = true; |
---|
1518 | } |
---|
1519 | else if ( parameter == "I") |
---|
1520 | { |
---|
1521 | ui->check_I->setChecked(true); |
---|
1522 | advanced = true; |
---|
1523 | } |
---|
1524 | else if ( parameter == "k") |
---|
1525 | { |
---|
1526 | ui->check_k->setChecked(true); |
---|
1527 | advanced = true; |
---|
1528 | } |
---|
1529 | else if ( parameter == "O") |
---|
1530 | { |
---|
1531 | ui->check_O->setChecked(true); |
---|
1532 | advanced = true; |
---|
1533 | } |
---|
1534 | else if ( parameter == "S") |
---|
1535 | { |
---|
1536 | ui->check_S->setChecked(true); |
---|
1537 | advanced = true; |
---|
1538 | } |
---|
1539 | else if ( parameter == "x") |
---|
1540 | { |
---|
1541 | ui->check_x->setChecked(true); |
---|
1542 | advanced = true; |
---|
1543 | } |
---|
1544 | else if ( parameter == "Z") |
---|
1545 | { |
---|
1546 | ui->check_Z->setChecked(true); |
---|
1547 | advanced = true; |
---|
1548 | } |
---|
1549 | else if ( parameter == "m") |
---|
1550 | { |
---|
1551 | ui->line_m->setText(options); |
---|
1552 | advanced = true; |
---|
1553 | } |
---|
1554 | else if ( parameter == "M") |
---|
1555 | { |
---|
1556 | ui->line_M->setText(options); |
---|
1557 | advanced = true; |
---|
1558 | } |
---|
1559 | else if ( parameter == "a") |
---|
1560 | { |
---|
1561 | ui->line_a->setText(options); |
---|
1562 | advanced = true; |
---|
1563 | } |
---|
1564 | else if ( parameter == "D") |
---|
1565 | { |
---|
1566 | ui->line_D->setText(options); |
---|
1567 | advanced = true; |
---|
1568 | } |
---|
1569 | else if ( parameter == "c") |
---|
1570 | { |
---|
1571 | ui->line_c->setText(options); |
---|
1572 | advanced = true; |
---|
1573 | } |
---|
1574 | else if ( parameter == "p") |
---|
1575 | { |
---|
1576 | ui->line_p->setText(options); |
---|
1577 | advanced = true; |
---|
1578 | } |
---|
1579 | else if ( parameter == "s") |
---|
1580 | { |
---|
1581 | ui->line_s->setText(options); |
---|
1582 | advanced = true; |
---|
1583 | } |
---|
1584 | else if ( parameter == "i") |
---|
1585 | { |
---|
1586 | ui->line_i->setText(options); |
---|
1587 | advanced = true; |
---|
1588 | rc_manual = true; |
---|
1589 | } |
---|
1590 | else if ( parameter == "o") |
---|
1591 | { |
---|
1592 | ui->line_o->setText(options); |
---|
1593 | advanced = true; |
---|
1594 | rc_manual = true; |
---|
1595 | } |
---|
1596 | else if ( parameter == "w") |
---|
1597 | { |
---|
1598 | ui->line_w->setText(options); |
---|
1599 | advanced = true; |
---|
1600 | } |
---|
1601 | |
---|
1602 | // Determine settings for coupled restart runs |
---|
1603 | else if ( parameter == "Y") |
---|
1604 | { |
---|
1605 | QStringList optionssplit = options.split(" ", \ |
---|
1606 | QString::SkipEmptyParts); |
---|
1607 | |
---|
1608 | ui->line_PE_atmos->setEnabled(true); |
---|
1609 | ui->line_PE_ocean->setEnabled(true); |
---|
1610 | ui->label_coupled1->setEnabled(true); |
---|
1611 | ui->label_coupled2->setEnabled(true); |
---|
1612 | ui->label_coupled3->setEnabled(true); |
---|
1613 | ui->label_coupling->setEnabled(true); |
---|
1614 | |
---|
1615 | if (optionssplit.count() == 2) |
---|
1616 | { |
---|
1617 | ui->line_PE_atmos->setText(optionssplit[0]); |
---|
1618 | ui->line_PE_ocean->setText(optionssplit[1]); |
---|
1619 | } |
---|
1620 | else |
---|
1621 | { |
---|
1622 | ui->line_PE_atmos->setText(""); |
---|
1623 | ui->line_PE_ocean->setText(""); |
---|
1624 | } |
---|
1625 | coupled_run = true; |
---|
1626 | } |
---|
1627 | else if ( parameter == "n") |
---|
1628 | { |
---|
1629 | if ( options == "shared") |
---|
1630 | { |
---|
1631 | ui->combo_n->setCurrentIndex(1); |
---|
1632 | } |
---|
1633 | else if ( options == "non_shared") |
---|
1634 | { |
---|
1635 | ui->combo_n->setCurrentIndex(2); |
---|
1636 | } |
---|
1637 | else |
---|
1638 | { |
---|
1639 | ui->combo_n->setCurrentIndex(0); |
---|
1640 | } |
---|
1641 | } |
---|
1642 | else if ( parameter == "y") |
---|
1643 | { |
---|
1644 | ui->drop_job->setCurrentIndex(3); |
---|
1645 | } |
---|
1646 | |
---|
1647 | // Determine settings for the run control list |
---|
1648 | else if ( parameter == "r") |
---|
1649 | { |
---|
1650 | QStringList optionssplit = options.split(" ", \ |
---|
1651 | QString::SkipEmptyParts); |
---|
1652 | |
---|
1653 | QString options_2; |
---|
1654 | QString options_all; |
---|
1655 | for (int j=0; j<optionssplit.count(); j++) |
---|
1656 | { |
---|
1657 | options_all = optionssplit[j]; |
---|
1658 | options_2 = optionssplit[j].left(2); |
---|
1659 | if (options_2 == "ts") |
---|
1660 | { |
---|
1661 | ui->check_ts->setChecked(true); |
---|
1662 | } |
---|
1663 | if (options_2 == "pr" && options_all.left(3) != "prt") |
---|
1664 | { |
---|
1665 | ui->check_pr->setChecked(true); |
---|
1666 | } |
---|
1667 | if (options_2 == "xy") |
---|
1668 | { |
---|
1669 | ui->check_xy->setChecked(true); |
---|
1670 | } |
---|
1671 | if (options_2 == "xz") |
---|
1672 | { |
---|
1673 | ui->check_xz->setChecked(true); |
---|
1674 | } |
---|
1675 | if (options_2 == "yz") |
---|
1676 | { |
---|
1677 | ui->check_yz->setChecked(true); |
---|
1678 | } |
---|
1679 | if (options_2 == "3d") |
---|
1680 | { |
---|
1681 | ui->check_3d->setChecked(true); |
---|
1682 | } |
---|
1683 | if (options_2 == "ma") |
---|
1684 | { |
---|
1685 | ui->check_ma->setChecked(true); |
---|
1686 | } |
---|
1687 | if (options_2 == "sp") |
---|
1688 | { |
---|
1689 | ui->check_sp->setChecked(true); |
---|
1690 | } |
---|
1691 | if (options_all.left(3) == "prt") |
---|
1692 | { |
---|
1693 | ui->check_prt->setChecked(true); |
---|
1694 | } |
---|
1695 | if (options_all.left(3) == "pts") |
---|
1696 | { |
---|
1697 | ui->check_pts->setChecked(true); |
---|
1698 | } |
---|
1699 | if (options_2 == "d3") |
---|
1700 | { |
---|
1701 | if (options_all.left(3).right(1) == "#") |
---|
1702 | { |
---|
1703 | ui->drop_job->setCurrentIndex(0); |
---|
1704 | } |
---|
1705 | else if (options_all.left(3).right(1) == "f") |
---|
1706 | { |
---|
1707 | ui->drop_job->setCurrentIndex(1); |
---|
1708 | } |
---|
1709 | else if (options_all.left(3).right(1) == "o") |
---|
1710 | { |
---|
1711 | ocean_run = true; |
---|
1712 | } |
---|
1713 | } |
---|
1714 | if (options_all == "restart") |
---|
1715 | { |
---|
1716 | ui->check_restarts->setChecked(true); |
---|
1717 | // Check if _pdf file is available, otherwise notice user |
---|
1718 | QString jobname = ui->line_jobname->text(); |
---|
1719 | branch = QCoreApplication::applicationDirPath(); |
---|
1720 | branch = branch.left(branch.length() - 14); |
---|
1721 | |
---|
1722 | QFile restartfile(branch+"/JOBS/"+jobname+"/INPUT/"+ \ |
---|
1723 | jobname+"_p3df"); |
---|
1724 | if (restartfile.exists() == true) |
---|
1725 | { |
---|
1726 | ui->label_restart->setText(""); |
---|
1727 | } |
---|
1728 | else |
---|
1729 | { |
---|
1730 | ui->label_restart->setText("<font color='red'>Warning: No p3df file \ |
---|
1731 | found!</font>"); |
---|
1732 | } |
---|
1733 | } |
---|
1734 | |
---|
1735 | } |
---|
1736 | |
---|
1737 | } |
---|
1738 | |
---|
1739 | // All unknown parameters are set as extra user parameters |
---|
1740 | else |
---|
1741 | { |
---|
1742 | user = user + "-" + parameter + " \"" + options + "\" "; |
---|
1743 | splitline.removeAt(i); |
---|
1744 | } |
---|
1745 | } |
---|
1746 | |
---|
1747 | // Change drop box state in case of ocean precursor or coupled restart runs |
---|
1748 | if ( ocean_run == true ) |
---|
1749 | { |
---|
1750 | if ( coupled_run == true ) |
---|
1751 | { |
---|
1752 | ui->drop_job->setCurrentIndex(4); |
---|
1753 | } |
---|
1754 | else |
---|
1755 | { |
---|
1756 | ui->drop_job->setCurrentIndex(3); |
---|
1757 | } |
---|
1758 | } |
---|
1759 | |
---|
1760 | if ( user != "") |
---|
1761 | { |
---|
1762 | ui->line_user->setText(user); |
---|
1763 | } |
---|
1764 | |
---|
1765 | // Join mrunline and post it to mainwindow |
---|
1766 | mrunline = splitline.join(" -"); |
---|
1767 | ui->commandline->setText(mrunline); |
---|
1768 | |
---|
1769 | // Check if advanced settings are used and enable advanced dialog |
---|
1770 | if ( advanced == true ) |
---|
1771 | { |
---|
1772 | ui->check_advanced->setChecked(true); |
---|
1773 | } |
---|
1774 | |
---|
1775 | // Disable mainwindow if no job was found, otherwise enable |
---|
1776 | if ( nojob == true ) |
---|
1777 | { |
---|
1778 | ui->group_execution->setEnabled(false); |
---|
1779 | ui->group_runcontrol->setEnabled(false); |
---|
1780 | ui->button_start->setEnabled(false); |
---|
1781 | ui->action_save->setEnabled(false); |
---|
1782 | ui->drop_job->setEnabled(false); |
---|
1783 | ui->group_advanced->setEnabled(false); |
---|
1784 | ui->check_advanced->setEnabled(false); |
---|
1785 | } |
---|
1786 | else |
---|
1787 | { |
---|
1788 | ui->group_execution->setEnabled(true); |
---|
1789 | ui->group_runcontrol->setEnabled(true); |
---|
1790 | ui->button_start->setEnabled(true); |
---|
1791 | ui->action_save->setEnabled(true); |
---|
1792 | ui->check_advanced->setEnabled(true); |
---|
1793 | ui->drop_job->setEnabled(true); |
---|
1794 | if ( advanced == true ) |
---|
1795 | { |
---|
1796 | ui->group_advanced->setEnabled(true); |
---|
1797 | } |
---|
1798 | else |
---|
1799 | { |
---|
1800 | ui->group_advanced->setEnabled(false); |
---|
1801 | } |
---|
1802 | } |
---|
1803 | |
---|
1804 | // Disable run control box, if manual settings of -i and -o are used |
---|
1805 | if ( rc_manual == true ) |
---|
1806 | { |
---|
1807 | ui->group_runcontrol->setEnabled(false); |
---|
1808 | change_commandline("r","remove"); |
---|
1809 | ui->button_start->setEnabled(true); |
---|
1810 | ui->action_save->setEnabled(true); |
---|
1811 | } |
---|
1812 | |
---|
1813 | } |
---|
1814 | |
---|
1815 | return 0; |
---|
1816 | } |
---|