Ignore:
Timestamp:
Jan 29, 2009 5:34:59 PM (16 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
da3dae3
Parents:
1f3655a
Message:

c_model wrappergenerator modified…
self.fixed list added to model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/sans/models/c_models/WrapperGenerator.py

    r95986b5 r836fe6e  
    8181        #model description 
    8282        self.description='' 
     83        # paramaters for fittable 
     84        self.fixed= [] 
    8385         
    8486    def __repr__(self): 
     
    8991        rep += "  params:     %s\n" % self.params 
    9092        rep += "  description:     %s\n" % self.description 
     93        rep += "  fittable paramaters list %s\n"% self.fixed 
    9194        return rep 
    9295         
     
    108111        self.details += "        self.details = {}\n" 
    109112         # Catch Description 
     113        key = "[FIXED]" 
     114        #open item in this case Fixed 
     115        text='text' 
     116        key2="<%s>"%text.lower() 
     117        # close an item in this case fixed 
     118        text='text' 
     119        key3="</%s>"%text.lower() 
     120        temp="" 
     121        # flag to found key 
     122        find_fixed= 0 
     123         
     124        for line in lines: 
     125            if line.count(key)>0 :#[FIXED]= ..... 
     126                try: 
     127                    find_fixed= 1 
     128                    index = line.index(key) 
     129                    toks  = line[index:].split("=",1 ) 
     130                    temp  = toks[1].lstrip().rstrip() 
     131                    if re.match(key2,temp)!=None:#[FIXED]= <text> axis_phi.width; axis_theta</text> 
     132                        print "when here" 
     133                        toks2=temp.split(key2,1)\ 
     134                        # split the ";" inside the string 
     135                        print "toks[2]",toks2,toks2[1] 
     136                        if  re.search(";",toks2[1]) !=None: 
     137                            params= toks2[1].split(";") 
     138                            for item in params: 
     139                                print "item", item 
     140                                if  re.search( key3,item)!=None: 
     141                                    par= item.split(key3)#remove key3 
     142                                    print "par", par, par[0] 
     143                                    new_par=par[0].lstrip().rstrip() 
     144                                    break 
     145                            #print "Key2 and Key3 in the same line , more than 1 param", self.fixed 
     146                        else:#only 1 param with key2 and key3 
     147                            if  re.search( key3,toks2[1])!=None: 
     148                                par= toks2[1].split(key3)#remove key3 
     149                                new_par=par[0].lstrip().rstrip() 
     150                                self.fixed.append(new_par.lstrip().rstrip()) 
     151                                #print "Key2 and Key3 in the same line , only 1 param ",self.fixed  
     152                                break 
     153                    else: # no key2 and key3 #[FIXED]=  axis_phi.width; axis_theta 
     154                        temp2 = temp.lstrip().rstrip() 
     155                        if  re.search(";", temp2) !=None:# more than 1 param in the same line 
     156                            params= temp2.split(";") 
     157                            #print "no key2 and key3  params", params 
     158                            for item in params: 
     159                                if item!='': 
     160                                    self.fixed.append(item.lstrip().rstrip()) 
     161                            #print "no key2 and key3, more than 1 param ",self.fixed 
     162                        else:# only one param per line #[FIXED]=  axis_phi.width 
     163                             self.fixed.append(temp2) 
     164                             #print "no key2 and key3, only 1 param ",self.fixed 
     165                        break 
     166                except: 
     167                     raise 
     168                     raise ValueError, "Could not parse file %s" % self.file 
     169            if find_fixed==1:# go to the 2nd line containing info found 1 key2 
     170                #[FIXED]= <text> axis_phi.width; axis_theta;radius_a.width; 
     171                #radius_</text> 
     172                if re.search(key3,line)!=None:# find  </text> 
     173                    tok=line.split(key3,1) 
     174                    print "tok",tok,tok[0] 
     175                    if re.match('//',tok[0].lstrip().rstrip())!=None:# look for '//' 
     176                        temp=tok[0].split("//",1)# remove "//" 
     177                    elif re.match('\*',tok[0].lstrip().rstrip())!=None: 
     178                        temp=tok[0].split("*",1)# remove "*" 
     179                    else: 
     180                        # missing "*" or "//" on comment  
     181                        raise 
     182                        #raise ValueError, "Could not parse file %s" % self.file 
     183                    for item in temp: 
     184                        if item.lstrip().rstrip() !='': 
     185                            pars= item.lstrip().rstrip() 
     186                            if  re.search(";",pars) !=None:# split string by ";" more than 1 parameter 
     187                                params= pars.split(";") 
     188                                for name in params: 
     189                                    if name.lstrip().rstrip() !='': 
     190                                        self.fixed.append(name.lstrip().rstrip()) 
     191                            else:# contains only one parameter 
     192                                name=pars.lstrip().rstrip() 
     193                                if name!='' and name!= key3:#only 1 parameter but ignore key3 
     194                                    self.fixed.append(name.lstrip().rstrip()) 
     195                                    #print "the line contains only one parameters",name.lstrip().rstrip() 
     196                                break 
     197             
     198                 
     199        # Catch Description 
    110200        key = "[DESCRIPTION]" 
    111201        find_description= 0 
     
    393483                                        "[PAR_DETAILS]", self.details) 
    394484            
    395  
     485            # fixed list  details 
     486            newline = self.replaceToken(newline,  
     487                                        "[FIXED]",str(self.fixed)) 
     488            
    396489            # Write new line to the wrapper .c file 
    397490            file.write(newline+'\n') 
     
    409502        lenkey = len(key) 
    410503        newline = line 
     504        
    411505        while newline.count(key)>0: 
    412506            index = newline.index(key) 
    413507            newline = newline[:index]+value+newline[index+lenkey:] 
     508         
    414509        return newline 
    415510         
Note: See TracChangeset for help on using the changeset viewer.