251    bool removeFormatter = 
false;
 
  252    if(pvl.format() == NULL) {
 
  254      removeFormatter = 
true;
 
  258    if(pvl.hasFormatTemplate()) outTemplate = *(
Isis::Pvl *)pvl.formatTemplate();
 
  264    for(
int i = 0; i < outTemplate.keywords(); i++) {
 
  265      if(outTemplate[i].isNamed(
"Isis:PvlTemplate:File")) {
 
  266        QString filename = outTemplate[i];
 
  268        if(!file.fileExists()) {
 
  269          QString message = 
"Could not open the template file [" + filename + 
"]";
 
  274        for(
int j = 0; j < include.
keywords(); j++) {
 
  275          if(!newTemp.hasKeyword(include[j].
name()))
 
  276            newTemp.addKeyword(include[j]);
 
  279        for(
int j = 0; j < include.
objects(); j++) {
 
  280          if(!newTemp.hasObject(include.
object(j).
name()))
 
  281            newTemp.addObject(include.
object(j));
 
  284        for(
int j = 0; j < include.
groups(); j++) {
 
  285          if(!newTemp.hasGroup(include.
group(j).
name()))
 
  286            newTemp.addGroup(include.
group(j));
 
  290      else if(!newTemp.hasKeyword(outTemplate[i].name()))
 
  291        newTemp.addKeyword(outTemplate[i]);
 
  295    for(
int i = 0; i < outTemplate.objects(); i++) {
 
  296      if(!newTemp.hasObject(outTemplate.object(i).name()))
 
  297        newTemp.addObject(outTemplate.object(i));
 
  301    for(
int i = 0; i < outTemplate.groups(); i++) {
 
  302      if(!newTemp.hasGroup(outTemplate.group(i).name()))
 
  303        newTemp.addGroup(outTemplate.group(i));
 
  306    outTemplate = newTemp;
 
  309    for(
int i = 0; i < pvl.comments(); i++) {
 
  310      os << pvl.comment(i) << pvl.format()->formatEOL();
 
  311      if(i == (pvl.comments() - 1)) os << pvl.format()->formatEOL();
 
  315    if(pvl.keywords() > 0) {
 
  323    for(
int i = 0; i < outTemplate.objects(); i++) {
 
  324      for(
int j = 0; j < pvl.objects(); j++) {
 
  325        if(outTemplate.object(i).name() != pvl.object(j).name()) 
continue;
 
  326        if(numObjects == 0 && pvl.keywords() > 0) os << pvl.format()->formatEOL();
 
  327        pvl.object(j).setIndent(pvl.indent());
 
  328        pvl.object(j).setFormatTemplate(outTemplate.object(i));
 
  329        pvl.object(j).setFormat(pvl.format());
 
  330        os << pvl.object(j) << pvl.format()->formatEOL();
 
  331        pvl.object(j).setFormat(NULL);
 
  332        pvl.object(j).setIndent(0);
 
  333        if(++numObjects < pvl.objects()) os << pvl.format()->formatEOL();
 
  338    for(
int i = 0; i < pvl.objects(); i++) {
 
  339      if(outTemplate.hasObject(pvl.object(i).name())) 
continue;
 
  340      if(numObjects == 0 && pvl.keywords() > 0) os << pvl.format()->formatEOL();
 
  341      pvl.object(i).setIndent(pvl.indent());
 
  342      pvl.object(i).setFormat(pvl.format());
 
  343      os << pvl.object(i) << pvl.format()->formatEOL();
 
  344      pvl.object(i).setFormat(NULL);
 
  345      pvl.object(i).setIndent(0);
 
  346      if(++numObjects < pvl.objects()) os << pvl.format()->formatEOL();
 
  353    for(
int i = 0; i < outTemplate.groups(); i++) {
 
  354      for(
int j = 0; j < pvl.groups(); j++) {
 
  355        if(outTemplate.group(i).name() != pvl.group(j).name()) 
continue;
 
  356        if((numGroups == 0) &&
 
  357            (pvl.objects() > 0 || pvl.keywords() > 0)) os << pvl.format()->formatEOL();
 
  358        pvl.group(j).setIndent(pvl.indent());
 
  359        pvl.group(j).setFormatTemplate(outTemplate.group(i));
 
  360        pvl.group(j).setFormat(pvl.format());
 
  361        os << pvl.group(j) << pvl.format()->formatEOL();
 
  362        pvl.group(j).setFormat(NULL);
 
  363        pvl.group(j).setIndent(0);
 
  364        if(++numGroups < pvl.groups()) os << pvl.format()->formatEOL();
 
  369    for(
int i = 0; i < pvl.groups(); i++) {
 
  370      if(outTemplate.hasGroup(pvl.group(i).name())) 
continue;
 
  371      if((numGroups == 0) &&
 
  372          (pvl.objects() > 0 || pvl.keywords() > 0)) os << pvl.format()->formatEOL();
 
  373      pvl.group(i).setIndent(pvl.indent());
 
  374      pvl.group(i).setFormat(pvl.format());
 
  375      os << pvl.group(i) << pvl.format()->formatEOL();
 
  376      pvl.group(i).setFormat(NULL);
 
  377      pvl.group(i).setIndent(0);
 
  378      if(++numGroups < pvl.groups()) os << pvl.format()->formatEOL();
 
  382    if(pvl.terminator() != 
"") {
 
  383      os << pvl.terminator();
 
  386    if(removeFormatter) {
 
 
  405      string msg = 
"Tried to read input stream with an error state into a Pvl";
 
  418      istream::pos_type beforeKeywordPos = is.tellg();
 
  422      while(readKeyword != termination) {
 
  423        for(
unsigned int errorKey = 0;
 
  424            errorKey < 
sizeof(errorKeywords) / 
sizeof(
PvlKeyword);
 
  426          if(readKeyword == errorKeywords[errorKey]) {
 
  427            is.seekg(beforeKeywordPos, ios::beg);
 
  429            QString msg = 
"Unexpected [";
 
  430            msg += readKeyword.
name();
 
  431            msg += 
"] in PVL Object [ROOT]";
 
  437          is.seekg(beforeKeywordPos);
 
  440          pvl.addGroup(newGroup);
 
  442        else if(readKeyword == 
PvlKeyword(
"Object")) {
 
  443          is.seekg(beforeKeywordPos);
 
  449          pvl.addKeyword(readKeyword);
 
  453        beforeKeywordPos = is.tellg();
 
  456        if(is.good() && (is.peek() < 32 || is.peek() > 126)) {
 
  473      if(is.eof() && !is.bad()) {
 
  478      istream::pos_type errorPos = is.tellg();
 
  479      if((
int)errorPos == -1) 
throw;
 
  481      is.seekg(0, ios::beg);
 
  484      if((
int)is.tellg() == -1) 
throw;
 
  486      while(is.good() && is.tellg() < errorPos) {
 
  487        char next = is.get();
 
  489        if(!isprint(next) && !isspace(next)) {
 
  490          is.seekg(errorPos, ios::beg);
 
  492        else if(next == 
'\n') {
 
  499        msg = 
"Error in PVL file on line [";
 
 
  531    pPvlResults=
Pvl(pPvl);
 
  536    for(
int i=0; i<iTmplObjSize; i++) {
 
  539      QString sObjName = pvlTmplObj.name();
 
  540      bool bObjFound = 
false;
 
  543      if(pPvl.hasObject(sObjName)) {
 
  545        pvlTmplObj.validateObject(pvlObj);
 
  546        if(pvlObj.objects()==0 && pvlObj.groups()==0 && pvlObj.keywords()==0) {
 
  547          pPvlResults.deleteObject(sObjName);
 
  552        QString sOption = sObjName + 
"__Required";
 
  554        if(pvlTmplObj.hasKeyword(sOption)) {
 
  555          PvlKeyword pvlKeyOption = pvlTmplObj.findKeyword(sOption);
 
  556          if(pvlKeyOption[0] == 
"true") { 
 
  561      if (bObjFound == 
false) {
 
  562        QString sErrMsg = 
"Object \"" + sObjName + 
"\" Not Found in the Template File\n";
 
  568    int iTmplGrpSize = 
groups();
 
  569    for(
int i=0; i<iTmplGrpSize; i++) {
 
  572      QString sGrpName  = pvlTmplGrp.name();
 
  573      bool bGrpFound = 
false;
 
  576      if(pPvl.hasGroup(sGrpName)) {
 
  577        PvlGroup & pvlGrp = pPvlResults.findGroup(sGrpName);
 
  579        if(pvlGrp.keywords()==0) {
 
  580          pPvlResults.deleteGroup(sGrpName);
 
  586        QString sOption = sGrpName + 
"__Required";
 
  587        if(pvlTmplGrp.hasKeyword(sOption)) {
 
  588          PvlKeyword pvlKeyOption = pvlTmplGrp.findKeyword(sOption);
 
  589          if(pvlKeyOption[0] == 
"true") { 
 
  594      if (bGrpFound == 
false) {
 
  595        QString sErrMsg = 
"Group \"" + sGrpName + 
"\" Not Found in the Template File\n";