-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c092dc9
commit 3236810
Showing
13 changed files
with
283 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
#include "options.h" | ||
#include <assert.h> | ||
#include <math.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "MALLOCC.h" | ||
#include "contourdefs.h" | ||
#include "histogram.h" | ||
#include "isodefs.h" | ||
#include "smokeviewdefs.h" | ||
#include "string_util.h" | ||
#include "structures.h" | ||
|
||
#include "readobject.h" | ||
|
||
#include "readlabel.h" | ||
|
||
/* ------------------ LabelGet ------------------------ */ | ||
|
||
labeldata *LabelGet(labels_collection *labelscoll, char *name) { | ||
labeldata *thislabel; | ||
|
||
if(name == NULL) return NULL; | ||
for(thislabel = labelscoll->label_first_ptr->next; thislabel->next != NULL; | ||
thislabel = thislabel->next) { | ||
if(strcmp(thislabel->name, name) == 0) return thislabel; | ||
} | ||
return NULL; | ||
} | ||
|
||
void LabelInsertBefore(labeldata *listlabel, labeldata *label) { | ||
labeldata *prev, *next; | ||
|
||
prev = listlabel->prev; | ||
next = listlabel; | ||
prev->next = label; | ||
next->prev = label; | ||
label->prev = prev; | ||
label->next = next; | ||
} | ||
|
||
void LabelInsertAfter(labeldata *listlabel, labeldata *label) { | ||
labeldata *prev, *next; | ||
|
||
prev = listlabel; | ||
next = listlabel->next; | ||
prev->next = label; | ||
next->prev = label; | ||
label->prev = prev; | ||
label->next = next; | ||
} | ||
|
||
labeldata *LabelInsert(labels_collection *labelscoll, labeldata *labeltemp) { | ||
labeldata *newlabel, *thislabel; | ||
labeldata *firstuserptr, *lastuserptr; | ||
|
||
NewMemory((void **)&newlabel, sizeof(labeldata)); | ||
memcpy(newlabel, labeltemp, sizeof(labeldata)); | ||
|
||
thislabel = LabelGet(labelscoll, newlabel->name); | ||
if(thislabel != NULL) { | ||
LabelInsertAfter(thislabel->prev, newlabel); | ||
return newlabel; | ||
} | ||
|
||
firstuserptr = labelscoll->label_first_ptr->next; | ||
if(firstuserptr == labelscoll->label_last_ptr) firstuserptr = NULL; | ||
|
||
lastuserptr = labelscoll->label_last_ptr->prev; | ||
if(lastuserptr == labelscoll->label_first_ptr) lastuserptr = NULL; | ||
|
||
if(firstuserptr != NULL && strcmp(newlabel->name, firstuserptr->name) < 0) { | ||
LabelInsertBefore(firstuserptr, newlabel); | ||
return newlabel; | ||
} | ||
if(lastuserptr != NULL && strcmp(newlabel->name, lastuserptr->name) > 0) { | ||
LabelInsertAfter(lastuserptr, newlabel); | ||
return newlabel; | ||
} | ||
if(firstuserptr == NULL && lastuserptr == NULL) { | ||
LabelInsertAfter(labelscoll->label_first_ptr, newlabel); | ||
return newlabel; | ||
} | ||
for(thislabel = labelscoll->label_first_ptr->next; thislabel->next != NULL; | ||
thislabel = thislabel->next) { | ||
labeldata *nextlabel; | ||
|
||
nextlabel = thislabel->next; | ||
if(strcmp(thislabel->name, newlabel->name) < 0 && | ||
strcmp(newlabel->name, nextlabel->name) < 0) { | ||
LabelInsertAfter(thislabel, newlabel); | ||
return newlabel; | ||
} | ||
} | ||
return NULL; | ||
} | ||
|
||
/* ------------------ LabelDelete ------------------------ */ | ||
|
||
void LabelDelete(labeldata *label) { | ||
labeldata *prev, *next; | ||
|
||
prev = label->prev; | ||
next = label->next; | ||
CheckMemory; | ||
FREEMEMORY(label); | ||
prev->next = next; | ||
next->prev = prev; | ||
} | ||
|
||
/* ------------------ LabelCopy ------------------------ */ | ||
|
||
void LabelCopy(labeldata *label_to, labeldata *label_from) { | ||
labeldata *prev, *next; | ||
|
||
prev = label_to->prev; | ||
next = label_to->next; | ||
memcpy(label_to, label_from, sizeof(labeldata)); | ||
label_to->prev = prev; | ||
label_to->next = next; | ||
} | ||
|
||
/* ------------------ LabelResort ------------------------ */ | ||
|
||
void LabelResort(labels_collection *labelscoll, labeldata *label) { | ||
labeldata labelcopy; | ||
|
||
CheckMemory; | ||
memcpy(&labelcopy, label, sizeof(labeldata)); | ||
CheckMemory; | ||
LabelDelete(label); | ||
LabelInsert(labelscoll, &labelcopy); | ||
} | ||
|
||
/* ------------------ LabelPrint ------------------------ */ | ||
|
||
void LabelPrint(labeldata *label_first_ptr) { | ||
labeldata *thislabel; | ||
float *xyz; | ||
|
||
for(thislabel = label_first_ptr->next; thislabel->next != NULL; | ||
thislabel = thislabel->next) { | ||
xyz = thislabel->xyz; | ||
PRINTF("label: %s position: %f %f %f\n", thislabel->name, xyz[0], xyz[1], | ||
xyz[2]); | ||
} | ||
} | ||
|
||
/* ------------------ LabelNext ------------------------ */ | ||
|
||
labeldata *LabelNext(labels_collection *labelscoll, labeldata *label) { | ||
labeldata *thislabel; | ||
|
||
if(label == NULL) return NULL; | ||
if(labelscoll->label_first_ptr->next->next == NULL) return NULL; | ||
for(thislabel = label->next; thislabel != label; | ||
thislabel = thislabel->next) { | ||
if(thislabel->next == NULL) thislabel = labelscoll->label_first_ptr->next; | ||
if(thislabel->labeltype == TYPE_SMV) continue; | ||
return thislabel; | ||
} | ||
return NULL; | ||
} | ||
|
||
/* ------------------ LabelPrevious ------------------------ */ | ||
|
||
labeldata *LabelPrevious(labels_collection *labelscoll, labeldata *label) { | ||
labeldata *thislabel; | ||
|
||
if(label == NULL) return NULL; | ||
if(labelscoll->label_last_ptr->prev->prev == NULL) return NULL; | ||
for(thislabel = label->prev; thislabel != label; | ||
thislabel = thislabel->prev) { | ||
if(thislabel->prev == NULL) thislabel = labelscoll->label_last_ptr->prev; | ||
if(thislabel->labeltype == TYPE_SMV) continue; | ||
return thislabel; | ||
} | ||
return NULL; | ||
} | ||
|
||
/* ------------------ LabelInit ------------------------ */ | ||
|
||
int LabelInit(labels_collection *labelscoll, labeldata *gl) { | ||
labeldata *thislabel; | ||
|
||
for(thislabel = labelscoll->label_first_ptr->next; thislabel->next != NULL; | ||
thislabel = thislabel->next) { | ||
if(thislabel->labeltype == TYPE_SMV) continue; | ||
LabelCopy(gl, thislabel); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
/* ------------------ LabelGetNUserLabels ------------------------ */ | ||
|
||
int LabelGetNUserLabels(labels_collection *labelscoll) { | ||
int count = 0; | ||
labeldata *thislabel; | ||
|
||
for(thislabel = labelscoll->label_first_ptr->next; thislabel->next != NULL; | ||
thislabel = thislabel->next) { | ||
if(thislabel->labeltype == TYPE_INI) count++; | ||
} | ||
return count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef READLABEL_H_DEFINED | ||
#define READLABEL_H_DEFINED | ||
|
||
/** | ||
* @brief A collection of labels. At it's core this collection | ||
* contains a linked list, but also an array of pointers into that linked list. | ||
* | ||
*/ | ||
typedef struct { | ||
labeldata label_first; | ||
labeldata label_last; | ||
labeldata *label_first_ptr; | ||
labeldata *label_last_ptr; | ||
} labels_collection; | ||
|
||
EXTERNCPP labeldata *LabelGet(labels_collection *labelscoll, char *name); | ||
EXTERNCPP labeldata *LabelInsert(labels_collection *labelscoll, | ||
labeldata *labeltemp); | ||
|
||
EXTERNCPP int LabelGetNUserLabels(labels_collection *labelscoll); | ||
EXTERNCPP labeldata *LabelPrevious(labels_collection *labelscoll, | ||
labeldata *label); | ||
EXTERNCPP labeldata *LabelNext(labels_collection *labelscoll, labeldata *label); | ||
EXTERNCPP void LabelCopy(labeldata *label_to, labeldata *label_from); | ||
EXTERNCPP void LabelDelete(labeldata *label); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.