|
9 | 9 | #include <array> |
10 | 10 | #include <vector> |
11 | 11 | #include <cassert> |
| 12 | +#include <cctype> |
12 | 13 | #include <limits> |
13 | 14 | #include "source_base/formatter.h" |
14 | 15 | #include "source_base/global_file.h" |
@@ -522,32 +523,32 @@ void ReadInput::check_ntype(const std::string& fn, int& param_ntype) |
522 | 523 | { |
523 | 524 | break; |
524 | 525 | } |
525 | | - else if (isalpha(temp[0])) |
| 526 | + else if (!temp.empty() && std::isalpha(static_cast<unsigned char>(temp[0]))) |
526 | 527 | { |
527 | 528 | ntype_stru += 1; |
528 | 529 | } |
529 | 530 | } |
530 | 531 | } |
531 | 532 |
|
532 | | - if (param_ntype == 0) |
| 533 | + if (ntype_stru <= 0) |
533 | 534 | { |
534 | | - param_ntype = ntype_stru; |
535 | | - GlobalV::ofs_running << " 'ntype' is no longer required in INPUT, and " |
536 | | - "it will be ignored. " |
537 | | - << std::endl; |
| 535 | + ModuleBase::WARNING_QUIT("ReadInput::check_ntype", |
| 536 | + "Failed to detect valid ntype from STRU: no valid ATOMIC_SPECIES entries were found."); |
538 | 537 | } |
539 | | - else if (param_ntype != ntype_stru) |
| 538 | + |
| 539 | + if (param_ntype < 0) |
540 | 540 | { |
541 | | - ModuleBase::WARNING_QUIT("ReadInput", |
542 | | - "The ntype in INPUT is not equal to the ntype " |
543 | | - "counted in STRU, check it."); |
| 541 | + ModuleBase::WARNING_QUIT("ReadInput::check_ntype", "The ntype in INPUT should not be less than 0."); |
544 | 542 | } |
545 | | - if (param_ntype <= 0) |
| 543 | + else if (param_ntype != 0 && param_ntype != ntype_stru) |
546 | 544 | { |
547 | | - ModuleBase::WARNING_QUIT("ReadInput", "ntype should be greater than 0."); |
| 545 | + ModuleBase::WARNING_QUIT("ReadInput::check_ntype", |
| 546 | + "The ntype in INPUT is not equal to the ntype " |
| 547 | + "counted in STRU, check it."); |
548 | 548 | } |
549 | | - else |
| 549 | + else if (param_ntype == 0) |
550 | 550 | { |
| 551 | + param_ntype = ntype_stru; |
551 | 552 | GlobalV::ofs_running << " 'ntype' is automatically set to " << param_ntype << std::endl; |
552 | 553 | } |
553 | 554 | } |
|
0 commit comments