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