Skip to content

Commit

Permalink
smokeview source: make time render label sizes consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
gforney committed Sep 26, 2024
1 parent 0c9038f commit f23102d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
17 changes: 17 additions & 0 deletions Source/shared/string_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,23 @@ char *GetString(char *buffer){
return NULL;
}

/* ------------------ Time2RenderLabel ------------------------ */

char *Time2RenderLabel(float sv_time, float dt, float maxtime, char *timelabel){
char *timelabelptr, format[32], percen[2], period[2];
int ndigits_right, ndigits_left, total_digits;

strcpy(percen, "%");
strcpy(period, ".");
ndigits_right = MAX(-log10(dt), 0) + 2;
ndigits_left = MAX(1, log10(maxtime)+1);
total_digits = 1 + ndigits_left + ndigits_right;
sprintf(format, "%s0%i%s%if", percen, total_digits, period, ndigits_right);
sprintf(timelabel, format, sv_time);
timelabelptr=TrimFront(timelabel);
return timelabelptr;
}

/* ------------------ Time2TimeLabel ------------------------ */

char *Time2TimeLabel(float sv_time, float dt, char *timelabel, int fixed_point){
Expand Down
1 change: 1 addition & 0 deletions Source/shared/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ EXTERNCPP float GetMantissaExponent(float x, int *exp10);
EXTERNCPP void GetGitInfo(char *githash, char *gitdate);
EXTERNCPP char *GetString(char *buffer);
EXTERNCPP char *Time2TimeLabel(float time, float dt, char *timelabel, int fixed_point);
EXTERNCPP char *Time2RenderLabel(float time, float dt, float maxtime, char *timelabel);
EXTERNCPP char *RandStr(char* str, int length);
EXTERNCPP void GetBaseTitle(char *progname, char *title_base);
EXTERNCPP void GetTitle(char *progname, char *fulltitle);
Expand Down
13 changes: 7 additions & 6 deletions Source/smokeview/renderimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ int GetRenderFileName(int view_mode, char *renderfile_dir, char *renderfile_full
}
code = GetPlot3dTime(&time_local);
if(code == 1 && render_label_type == RENDER_LABEL_TIME){
char timelabel_local[20], *timelabelptr, dt = 1.0;
char timelabel_local[20], *timelabelptr;
float dt = 1.0, maxtime=100000.0;

timelabelptr = Time2TimeLabel(time_local, dt, timelabel_local, force_fixedpoint);
timelabelptr = Time2RenderLabel(time_local, dt, maxtime, timelabel_local);
strcat(suffix, "_");
strcat(suffix, timelabelptr);
strcat(suffix, "s");
Expand All @@ -352,12 +353,12 @@ int GetRenderFileName(int view_mode, char *renderfile_dir, char *renderfile_full
else{
float time_local;
char timelabel_local[20], *timelabelptr;
float dt;
float dt, maxtime;

time_local = global_times[itimes];
dt = global_times[1] - global_times[0];
if(dt < 0.0)dt = -dt;
timelabelptr = Time2TimeLabel(time_local, dt, timelabel_local, force_fixedpoint);
dt = ABS(global_times[1] - global_times[0]);
maxtime = global_times[nglobal_times-1];
timelabelptr = Time2RenderLabel(time_local, dt, maxtime, timelabel_local);
strcpy(suffix, timelabelptr);
strcat(suffix, "s");
}
Expand Down

0 comments on commit f23102d

Please sign in to comment.