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