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