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