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