2828#include < bzlib.h>
2929#include < unistd.h>
3030#include " fontdata.h"
31+ #include < emscripten/emscripten.h>
3132
3233#define GAMMA 2.5
3334#define BZBUFFER 65536
@@ -3192,21 +3193,15 @@ void PlotLRMap(struct site source, double altitude, char *plo_filename)
31923193 of a topographic map when the WritePPMLR() or
31933194 WritePPMSS() functions are later invoked. */
31943195
3195- int y, z, count;
3196+ int y, count;
31963197 struct site edge;
3197- double lat, lon, minwest, maxnorth, th;
3198- unsigned char x, symbol[4 ];
3198+ double lat, lon, minwest, maxnorth;
31993199 static unsigned char mask_value=1 ;
32003200 FILE *fd=NULL ;
32013201
32023202 minwest=dpp+(double )min_west;
32033203 maxnorth=(double )max_north-dpp;
32043204
3205- symbol[0 ]=' .' ;
3206- symbol[1 ]=' o' ;
3207- symbol[2 ]=' O' ;
3208- symbol[3 ]=' o' ;
3209-
32103205 count=0 ;
32113206
32123207 if (olditm)
@@ -3229,9 +3224,6 @@ void PlotLRMap(struct site source, double altitude, char *plo_filename)
32293224 if (clutter>0.0 )
32303225 fprintf (stdout," \n and %.2f %s of ground clutter" ,metric?clutter*METERS_PER_FOOT :clutter,metric?" meters" :" feet" );
32313226
3232- fprintf (stdout," ...\n\n 0%c to 25%c " ,37 ,37 );
3233- fflush (stdout);
3234-
32353227 if (plo_filename[0 ]!=0 )
32363228 fd=fopen (plo_filename," wb" );
32373229
@@ -3242,14 +3234,14 @@ void PlotLRMap(struct site source, double altitude, char *plo_filename)
32423234 fprintf (fd," %d, %d\t ; max_west, min_west\n %d, %d\t ; max_north, min_north\n " ,max_west, min_west, max_north, min_north);
32433235 }
32443236
3245- /* th=pixels/degree divided by 64 loops per
3246- progress indicator symbol (.oOo) printed. */
3247-
3248- th=ppd/64.0 ;
3237+ int total_q1 = static_cast <int >(LonDiff (static_cast <double >(max_west), minwest)/dpp);
3238+ int total_q2 = static_cast <int >((maxnorth-min_north)/dpp);
3239+ int total_steps = total_q1 + total_q2;
32493240
3250- z=(int )(th*ReduceAngle (max_west-min_west));
3241+ // Avoid spamming progress updates every iteration; only write progress each 1% of the job
3242+ int nsteps_per_report = static_cast <int >(static_cast <double >(total_steps)/100.0 );
32513243
3252- for (lon=minwest, x= 0 , y=0 ; (LonDiff (lon,(double )max_west)<=0.0 ); y++, lon=minwest+(dpp*(double )y))
3244+ for (lon=minwest, y=0 ; (LonDiff (lon,(double )max_west)<=0.0 ); y++, lon=minwest+(dpp*(double )y))
32533245 {
32543246 if (lon>=360.0 )
32553247 lon-=360.0 ;
@@ -3259,112 +3251,47 @@ void PlotLRMap(struct site source, double altitude, char *plo_filename)
32593251 edge.alt =altitude;
32603252
32613253 PlotLRPath (source,edge,mask_value,fd);
3262- count++;
3263-
3264- if (count==z)
3265- {
3266- fprintf (stdout," %c" ,symbol[x]);
3267- fflush (stdout);
3268- count=0 ;
3269-
3270- if (x==3 )
3271- x=0 ;
3272- else
3273- x++;
3274- }
3275- }
32763254
3277- count=0 ;
3278- fprintf (stdout," \n 25%c to 50%c " ,37 ,37 );
3279- fflush (stdout);
3280-
3281- z=(int )(th*(double )(max_north-min_north));
3282-
3283- for (lat=maxnorth, x=0 , y=0 ; lat>=(double )min_north; y++, lat=maxnorth-(dpp*(double )y))
3284- {
3285- edge.lat =lat;
3286- edge.lon =min_west;
3255+ edge.lat =min_north;
3256+ edge.lon =lon;
32873257 edge.alt =altitude;
32883258
32893259 PlotLRPath (source,edge,mask_value,fd);
3290- count++ ;
3260+ ++count ;
32913261
3292- if (count==z)
3293- {
3294- fprintf (stdout," %c" ,symbol[x]);
3295- fflush (stdout);
3296- count=0 ;
3297-
3298- if (x==3 )
3299- x=0 ;
3300- else
3301- x++;
3302- }
3262+ if (count % nsteps_per_report == 0 ) {
3263+ EM_ASM ({
3264+ progress (' Plotting LR map...' , $0 , $1 );
3265+ }, count, total_steps);
3266+ }
33033267 }
33043268
3305- count=0 ;
3306- fprintf (stdout," \n 50%c to 75%c " ,37 ,37 );
3307- fflush (stdout);
3308-
3309- z=(int )(th*ReduceAngle (max_west-min_west));
3310-
3311- for (lon=minwest, x=0 , y=0 ; (LonDiff (lon,(double )max_west)<=0.0 ); y++, lon=minwest+(dpp*(double )y))
3269+ for (lat=maxnorth, y=0 ; lat>=(double )min_north; y++, lat=maxnorth-(dpp*(double )y))
33123270 {
3313- if (lon>=360.0 )
3314- lon-=360.0 ;
3315-
3316- edge.lat =min_north;
3317- edge.lon =lon;
3271+ edge.lat =lat;
3272+ edge.lon =min_west;
33183273 edge.alt =altitude;
33193274
33203275 PlotLRPath (source,edge,mask_value,fd);
3321- count++;
33223276
3323- if (count==z)
3324- {
3325- fprintf (stdout," %c" ,symbol[x]);
3326- fflush (stdout);
3327- count=0 ;
3328-
3329- if (x==3 )
3330- x=0 ;
3331- else
3332- x++;
3333- }
3334- }
3335-
3336- count=0 ;
3337- fprintf (stdout," \n 75%c to 100%c " ,37 ,37 );
3338- fflush (stdout);
3339-
3340- z=(int )(th*(double )(max_north-min_north));
3341-
3342- for (lat=(double )min_north, x=0 , y=0 ; lat<(double )max_north; y++, lat=(double )min_north+(dpp*(double )y))
3343- {
33443277 edge.lat =lat;
33453278 edge.lon =max_west;
33463279 edge.alt =altitude;
33473280
33483281 PlotLRPath (source,edge,mask_value,fd);
3349- count++ ;
3282+ ++count ;
33503283
3351- if (count==z)
3352- {
3353- fprintf (stdout," %c" ,symbol[x]);
3354- fflush (stdout);
3355- count=0 ;
3356-
3357- if (x==3 )
3358- x=0 ;
3359- else
3360- x++;
3361- }
3284+ if (count % nsteps_per_report == 0 ) {
3285+ EM_ASM ({
3286+ progress (' Plotting LR map...' , $0 , $1 );
3287+ }, count, total_steps);
3288+ }
33623289 }
33633290
33643291 if (fd!=NULL )
33653292 fclose (fd);
33663293
3367- fprintf (stdout," \n Done !\n " );
3294+ fprintf (stdout," \n LR map done !\n " );
33683295 fflush (stdout);
33693296
33703297 if (mask_value<30 )
0 commit comments