Changeset 3781


Ignore:
Timestamp:
05/17/10 15:08:06 (15 years ago)
Author:
Mathieu Morlighem
Message:

added Matlab routines StringAsEnum

Location:
issm/trunk/src/c/EnumDefinitions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/EnumDefinitions/SynchronizeMatlabEnum.sh

    r3764 r3781  
    1111cat EnumDefinitions.h | grep "[Aa-Zz]Enum" | grep -v StringAsEnum | sed -e "s/,//g" | awk '{ printf "%s %s\n", NR, $0 }' > temp
    1212
    13 #Build header of AnalysisTypeFromEnum.m{{{
    14 cat <<END > AnalysisTypeFromEnum.m
    15 function string=AnalysisTypeFromEnum(enum)
    16 %ANALYSISASENUM - get analysis type from Enum
     13#Build header of EnumAsString.m {{{1
     14cat <<END > EnumAsString.m
     15function string=EnumAsString(enum)
     16%ENUMASSTRING - output string associated with enum
    1717%
    1818%   WARNING: DO NOT MODIFY THIS FILE
     
    2121%
    2222%   Usage:
    23 %      string=AnalysisTypeFromEnum(enum)
     23%      string=EnumAsString(enum)
    2424
    25 %initialize output
    26 string='not found';
     25switch enum,
     26
     27END
     28#}}}
     29#Build header of StringAsEnum.m {{{1
     30cat <<END > StringAsEnum.m
     31function enum=StringAsEnum(name)
     32%STRINGASENUM - output enum associated with string
     33%
     34%   WARNING: DO NOT MODIFY THIS FILE
     35%            this file has been automatically generated by src/c/SynchronizeMatlabEnum
     36%            Please read src/c/README for more information
     37%
     38%   Usage:
     39%      enum=StringAsEnum(name)
     40
    2741END
    2842#}}}
     
    3549
    3650        #Get name and enum of the line i
    37         NAME=$(cat temp | grep "^[ ]*$i " | awk '{printf("%s",$2);}');
     51        NAMEENUM=$(cat temp | grep "^[ ]*$i " | awk '{printf("%s",$2);}');
     52        NAME=$(echo $NAMEENUM | sed -e "s/Enum//g")
    3853        ENUM=$i;
    3954        #offset Enum by one (Enum begins with 0 and not 1!)
     
    5772        #}}}
    5873        #Add case to matlabenum file{{{
    59         cat <<END > $(echo $NAME".m")
    60 function macro=$(echo $NAME)()
    61 %$(echo `echo $NAME | sed -e "s/[a-z]/\U&/g"`) - Enum of $(echo `echo $NAME | sed -e "s/Enum//"`)
     74        cat <<END > $ISSM_DIR"/src/m/enum/"$(echo $NAMEENUM".m")
     75function macro=$(echo $NAMEENUM)()
     76%$(echo $NAMEENUM | sed -e "s/[a-z]/\U&/g") - Enum of $(echo $NAME)
    6277%
    6378%   WARNING: DO NOT MODIFY THIS FILE
     
    6681%
    6782%   Usage:
    68 %      macro=$NAME()
     83%      macro=$NAMEENUM()
    6984
    7085macro=$ENUM;
    7186END
    7287#}}}
    73 #Add case to AnalysisTypeFromEnum file{{{
    74         if [ $(echo $NAME | grep AnalysisEnum) ]
     88#Add case to EnumAsString.m {{{
     89cat <<END >> EnumAsString.m
     90        case $NAMEENUM(), string='$NAME'; return
     91END
     92#}}}
     93        #Add case to StringAsEnum.m {{{
     94        if [ $i -eq 1 ]
    7595        then
    76                 cat <<END >> AnalysisTypeFromEnum.m
    77 
    78 if enum==$NAME(),
    79         string='$(echo `echo $NAME | sed -e "s/AnalysisEnum//g" | awk {'print tolower($_)'}`)';
    80 end
     96                cat <<END >> StringAsEnum.m
     97if (strcmpi(name,'$NAME')), enum=$NAMEENUM(); return
     98END
     99        else
     100                cat <<END >> StringAsEnum.m
     101elseif (strcmpi(name,'$NAME')), enum=$NAMEENUM(); return
    81102END
    82103        fi
    83104#}}}
    84105
    85         #move file to m/enum
    86         mv $NAME".m" $ISSM_DIR"/src/m/enum/"
    87 
    88106done
    89107
    90 #Footer of AnalysisTypeFromEnum.m{{{
    91 cat <<END >> AnalysisTypeFromEnum.m
     108#Add footer of of EnumAsString.m{{{1
     109cat <<END >> EnumAsString.m
     110        otherwise, error(['Enum ' num2str(enum)  ' not found']);
    92111
    93 %check that an analysis type has been found for enum
    94 if strcmp(string,'not found'),
    95         error(['AnalysisTypeFromEnum error message: enum ' num2str(enum) ' not supported!']);
     112end
     113END
     114#}}}
     115#Add footer of of StringAsEnum.m{{{1
     116cat <<END >> StringAsEnum.m
     117else error(['Enum ' name  ' not found']);
     118
    96119end
    97120END
     
    99122
    100123#clean up{{{
    101 mv AnalysisTypeFromEnum.m $ISSM_DIR/src/m/enum/
     124mv StringAsEnum.m $ISSM_DIR/src/m/enum/
     125mv EnumAsString.m $ISSM_DIR/src/m/enum/
    102126rm temp
    103127#}}}
  • issm/trunk/src/c/EnumDefinitions/SynchronizeStrings.sh

    r3764 r3781  
    2121
    2222#include "../shared/shared.h"
    23 #include "../include/macros.h"
     23#include "../include/include.h"
    2424#include "./EnumDefinitions.h"
    2525
     
    4242
    4343#include "../shared/shared.h"
    44 #include "../include/macros.h"
     44#include "../include/include.h"
    4545#include "./EnumDefinitions.h"
    4646
Note: See TracChangeset for help on using the changeset viewer.