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