Skip to content

Commit acb750d

Browse files
authored
Merge pull request #20 from ukos-git/functions_load_uncompiled
load from storage in uncompiled state
2 parents a40fb1c + 875e7ad commit acb750d

File tree

2 files changed

+75
-43
lines changed

2 files changed

+75
-43
lines changed

procedures/CodeBrowser.ipf

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -649,12 +649,14 @@ End
649649
// Parses all procedure windows and write into the decl and line waves
650650
Function/S parseProcedure(procedure, [checksumIsCalculated])
651651
STRUCT procedure &procedure
652-
Variable checksumIsCalculated
652+
Variable checkSumIsCalculated
653653

654654
if(ParamIsDefault(checksumIsCalculated))
655-
checksumIsCalculated = 0
655+
checkSumIsCalculated = 0
656+
endif
657+
if(!checkSumIsCalculated)
658+
DebugPrint("CheckSum needs to be calculated")
656659
endif
657-
DebugPrint("Checksum recalc:" + num2str(checksumIsCalculated))
658660

659661
// start timer
660662
Variable timer = timerStart()
@@ -720,10 +722,19 @@ static Function saveResults(procedure)
720722
endif
721723
End
722724

725+
// Load the specified procedure from storage waves
726+
//
727+
// return errorCode
728+
// 1 Load successfull
729+
// 0 save state loaded with zero elements
730+
// -1 Could not load save state
731+
// -2 CheckSum missmatch. CheckSum has been calculated and was stored in
732+
// global variable
723733
static Function saveLoad(procedure)
724734
STRUCT procedure &procedure
725735

726736
Variable numResults
737+
string CheckSum
727738

728739
Wave/T declWave = getDeclWave()
729740
Wave/I lineWave = getLineWave()
@@ -732,72 +743,72 @@ static Function saveLoad(procedure)
732743
Wave/T SaveStringsWave = getSaveStrings()
733744
Wave SaveVariablesWave = getSaveVariables()
734745

746+
// if maximum storage capacity was reached (procedure.row == -1) or
747+
// Element not found (procedure.row == endofWave) --> nothing loadable
735748
if((procedure.row < 0) || (procedure.row == Dimsize(SaveStringsWave, 0)) || (Dimsize(SaveStringsWave, 0) == 0))
736-
// if maximum storage capacity was reached (procedure.row == -1) or Element not found (procedure.row == endofWave) there is nothing to load.
737749
debugPrint("save state not found")
738750
return -1
739-
elseif(SaveVariablesWave[procedure.row][0] == 0)
740-
// procedure marked as non valid by AfterRecompileHook
741-
// checksum needs to be compared.
751+
endif
752+
if(isCompiled() && !SaveVariablesWave[procedure.row][0])
753+
// procedure marked as not valid by
754+
// AfterCompiledHook --> updatePanel --> saveReParse
755+
// --> CheckSum needs to be compared.
742756

743-
// getting checksum
744-
if(setChecksum(procedure) != 1)
745-
debugPrint("error creating variable")
757+
if(!setChecksum(procedure))
758+
debugPrint("error creating CheckSum")
746759
return -1
747760
endif
748-
// comparing checksum
749-
if(cmpstr(SaveStringsWave[procedure.row][1],getChecksum()) != 0)
750-
// checksum changed. return -2 to indicate that calculation was already done by setChecksum.
751-
debugPrint("Checksum missmatch: Procedure has to be reloaded.")
761+
CheckSum = getCheckSum()
762+
if(!!cmpstr(SaveStringsWave[procedure.row][1], CheckSum))
763+
debugPrint("CheckSum missmatch: Procedure has to be reloaded.")
752764
return -2
753-
else
754-
//mark as valid
755-
debugPrint("Checksum match: Procedure marked valid.")
756-
SaveVariablesWave[procedure.row][0] = 1
757765
endif
766+
debugPrint("CheckSum match: " + CheckSum)
767+
768+
SaveVariablesWave[procedure.row][0] = 1
769+
debugPrint("Procedure " + procedure.fullname + " marked as valid.")
758770
endif
759771

760-
// load results from free waves
761772
numResults = Dimsize(SaveWavesWave[procedure.row][0], 0)
762773
Redimension/N=(numResults, -1) declWave, lineWave
763-
if(numResults > 0)
764-
WAVE/T load0 = SaveWavesWave[procedure.row][0]
765-
WAVE/I load1 = SaveWavesWave[procedure.row][1]
766-
declWave[][0] = load0[p][0]
767-
declWave[][1] = load0[p][1]
768-
lineWave[] = load1[p]
769-
debugPrint("save state loaded successfully")
770-
return 1
771-
else
774+
if(numResults == 0)
772775
debugPrint("no elements in save state")
773776
return 0
774777
endif
778+
779+
WAVE/T load0 = SaveWavesWave[procedure.row][0]
780+
WAVE/I load1 = SaveWavesWave[procedure.row][1]
781+
declWave[][0] = load0[p][0]
782+
declWave[][1] = load0[p][1]
783+
lineWave[] = load1[p]
784+
785+
debugPrint("save state loaded successfully")
786+
return 1
775787
End
776788

777789
// Identifier = module#procedure
778790
static Function getSaveRow(Identifier)
779791
String Identifier
780792

781793
Wave/T SaveStrings = getSaveStrings()
782-
Variable found, endOfWave
794+
Variable found, endOfWave, element
783795

784796
FindValue/TEXT=Identifier/TXOP=4/Z SaveStrings
785-
if(V_value == -1)
786-
// element not found
797+
if(V_Value == -1)
798+
debugPrint("Element not found")
787799
return Dimsize(SaveStrings, 0)
788-
else
789-
// element found at position V_value
790-
791-
// check for inconsistency.
792-
if(V_value > CsaveMaximum )
793-
DebugPrint("Storage capacity exceeded")
794-
// should only happen if(CsaveMaximum) was touched on runtime.
795-
// Redimension/Deletion of Wave could be possible.
796-
return (CsaveMaximum - 1)
797-
endif
798-
799-
return V_value
800800
endif
801+
element = V_Value
802+
803+
// check for inconsistency.
804+
if(element > CsaveMaximum )
805+
debugPrint("Storage capacity exceeded")
806+
// should only happen if(CsaveMaximum) was touched on runtime.
807+
// Redimension/Deletion of Wave could be possible.
808+
return (CsaveMaximum - 1)
809+
endif
810+
811+
return element
801812
End
802813

803814
// drop first item at position 0. push all elements upward by 1 element. Free last Position.
@@ -1116,6 +1127,8 @@ End
11161127

11171128
static Function setParsingTime(numTime)
11181129
Variable numTime
1130+
1131+
debugPrint("parsing time:" + num2str(numTime))
11191132
return setGlobalVar("parsingTime", numTime)
11201133
End
11211134

procedures/CodeBrowser_utils.ipf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,22 @@ Function timerStop(timerRefNum)
279279
microseconds = stopMSTimer(timerRefNum)
280280
return microseconds
281281
End
282+
283+
// check if procedures are in compiled state.
284+
//
285+
// @param funcList [optional] input FunctionList to save time
286+
//
287+
// @return 0 if procedure is not compiled, 1 otherwise
288+
Function isCompiled([funcList])
289+
string funcList
290+
291+
if(ParamIsDefault(funcList))
292+
funcList = FunctionList("*", ";", "KIND:18,WIN:Procedure [ProcGlobal]")
293+
endif
294+
295+
if(!cmpstr(funclist, "Procedures Not Compiled;"))
296+
debugPrint("procedures are in uncompiled state.")
297+
return 0
298+
endif
299+
return 1
300+
End

0 commit comments

Comments
 (0)