summaryrefslogtreecommitdiff
path: root/macros/GeneralFunctions/ReadStringCard.sci
blob: a4525d901ae1c7c818c56278a75504b92baaf8ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function cardvalue = ReadStringCard(filename,cardname,commentdelim,enableerror)
// function cardvalue = ReadStringCard(filename,cardname,commentdelim,enableerror)
// -----------------------------------------------------------------
// #RNU_RES_B
// Reads the string associated to the card cardname placed 
// in filename.
// The value of cardname is assumed to be a string.
// If the card is not found an error will occur.
// 
// Input data:
// filename: full path + name of the file where the card
//           is being searched.
// cardname: string with the name of the card.
// commentdelim: specifies a character for an eventual comment
//               (to be discarded) after the card value.
// enableerror: 'y' enable error message.
//              'n' enable warning message.
//
// Output data:
// cardvalue: string associated to the card. Blanks characters 
//            are discarded.
// #RNU_RES_E
//
// Status:
// 06-Feb-2004 -- Nutricato Raffaele: Author.
// 06-Feb-2004 -- Nutricato Raffaele: TEST OK.
// 25-Jun-2004 -- Nutricato Raffaele: Added Comment delimiter
//                                    and enableerror as input parameter.
// 13-Apr-2007 -- Intelligente Fabio: Rewritten from Matlab to Scilab.
//
// Copyright 2007 Raffaele Nutricato.
// Contact: raffaele.nutricato@tiscali.it
// -----------------------------------------------------------------

// ------------------------------
// --- Check input arguments. ---
// ------------------------------
SCI2CNInArgCheck(argn(2),2,3);

if argn(2) == 2 then
   commentdelim = ' ';
   enableerror  = 'y';
      
elseif argn(2) == 3 then
   enableerror  = 'y';
end

[flag_found,requested_line,dummy2] = ... 
   KeyString2FileStringPos(filename,cardname,'cut');
cardvalue = stripblanks(strtok(requested_line,commentdelim));
clear requested_line dummy2

if (flag_found == 0) then
   if (enableerror == 'y') then
      error(9999, cardname+' not found'); 
   else
      warning([cardname,' not found']);
   end
end
 
endfunction