// rt_p_a1a3 : Programm RASTELL-TOULL
//      a1   : Reading an auxillary file in format RASTELL-TOULL
//      a1a3 : Format 0 in Scilab language

// A1 Comments display
Programme = "rt_p_a1a3"
Version = "V2.1 du 20120507"
Copyright = "Jacques-Deric Rouault - Rastell Toull"
mprintf ("Program   = " + Programme + "\n")
mprintf ("Version   = " + Version + "\n")
mprintf ("Copyright = " + Copyright + "\n" + "\n")

// A2 Directory control
[fsce,erreur] = mopen (Programme + ".sce","r");
if erreur<>0 then 
  mprintf ("ERROR A2 : DIRECTORY ERROR " + Programme + ".sce\n\n");
  abort; 
end;  
mclose (fsce);
mprintf ("A2 : Directory Control OK\n");

// A3 Opening the auxilliary text file
[ftxt,erreur] = mopen(Programme +'.txt','r')
if erreur<>0 then
  mprintf ("ERROR A3 : AUXILLIARY FILE NOT FOUND\n\n")
  abort
end
mprintf ("A3 : Opening the auxilliary text file OK\n");

// A4 Reading and control of identifier RASTELL-TOULL
str = mgetl (ftxt,1);
if str <> "\\RASTELL-TOULL" then 
  mclose (ftxt);  
  mprintf ("ERROR A4 : IDENTIFIER RASTELL-TOULL INCORRECT\n\n");
  mclose(ftxt)
  abort;
end;
mprintf ("A4 : Identifier RASTELL-TOULL OK\n");

// A5 Reading and control of identifier FORMAT
str = mgetl (ftxt,1);
if str <> "\\FORMAT" then 
  mprintf ("ERROR A5 : IDENTIFIER FORMAT INCORRECT\n\n");
  mclose (ftxt);  
  abort;
end;
mprintf ("A5 : Identifier FORMAT OK\n");

// A6 Reading and control of the value of format
str = mgetl (ftxt,1);
format_fichier = sscanf (str,"%i");
if format_fichier <> 1 then 
  mprintf ("ERROR A6 : INCORRECT VALUE OF FORMAT\n\n");
  mclose (ftxt);  
  abort;
end;
mprintf ("A6 : Value of format is correct\n");

// A7 Reading and control of identifier FICHIERS
str = mgetl (ftxt,1);
if str <> "\\FICHIERS" then 
  mprintf ("ERROR A7 : IDENTIFIER FICHIERS INCORRECT\n\n");
  mclose (ftxt);  
  abort;
end;
mprintf ("A7 : Identifier FICHIERS OK\n");

// A8 Reading the comment and the name of the XLS file to be read
str = mgetl (ftxt,1);
nom_fichier_xls = mgetl (ftxt,1);
mprintf ("A8 : Name of the XLS file = %s\n",nom_fichier_xls);

// A9 Reading and control of identifier PARAMETRES
str = mgetl (ftxt,1);
if str <> "\\PARAMETRES" then 
  mprintf ("ERROR A9 : IDENTIFIER PARAMETRES INCORRECT\n\n");
  mclose (ftxt);  
  abort;
end;
mprintf ("A9 : Identifier PARAMETRES OK\n");

// B10 Reading the comment and the rank of the page of the XLS file
str = mgetl (ftxt,1);
str = mgetl (ftxt,1);
page_xls = sscanf (str,"%i");
mprintf ("B10 : Rank of the page = %i\n",page_xls);

// B11 Reading the comment and the rank of the column
str = mgetl (ftxt,1);
str = mgetl (ftxt,1);
colonne = sscanf (str,"%i");
mprintf ("B11 : Rank of the column = %i\n",colonne);

// B12 Reading the comment and the rank of the first line
str = mgetl (ftxt,1);
str = mgetl (ftxt,1);
ligne_debut = sscanf (str,"%i");
mprintf ("B12 : Rank of the first line = %i\n",ligne_debut);

// B13 Reading the comment and the rank of the last line
str = mgetl (ftxt,1);
str = mgetl (ftxt,1);
ligne_fin = sscanf (str,"%i");
mprintf ("B13 : Rank of the last line = %i\n",ligne_fin);

// B14 Reading and control of identificer FINEND
str = mgetl (ftxt,1);
if str <> "\\FINEND" then 
  mprintf ("ERROR B13 : IDENTIFIER FINEND INCORRECT\n\n");
  mclose (ftxt);  
  abort;
end;
mprintf ("B14 : Identifier FINEND correct\n");

// B15 Closing the auxilliary file
mclose(ftxt)

// B16 Display of the values read in the auxilliary file
  mprintf ("\nName of file = " + nom_fichier_xls +"\n");
  mprintf ("Rank of the page       = %i \n",page_xls);
  mprintf ("Rank of the column     = %i \n",colonne);
  mprintf ("Rank of the first line = %i \n",ligne_debut);
  mprintf ("Rank of the last  line = %i \n\n",ligne_fin);

// B17 End of running
mprintf ("End of running " + Programme + " OK\n");
