-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-logbook.sh
More file actions
executable file
·878 lines (742 loc) · 33.7 KB
/
Copy pathgenerate-logbook.sh
File metadata and controls
executable file
·878 lines (742 loc) · 33.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
#!/bin/bash
#####################
###### LICENSE ######
#####################
# generate-logbook.sh -- Generate a logbook for a given list of celestial objects
#
# Copyright (C) 2013 Akarsh Simha <akarsh@kde.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#############################################
###### Description and some basic help ######
#############################################
#
# Generate a logbook for a given list of celestial objects.
#
# This script uses KStars and LaTeX to generate observing log books
# for a list of celestial objects.
#
# The objects must exist in KStars. KStars must be running and be
# accessible via qdbus.
#
# Dependencies: xmlstarlet, inkscape, pdflatex, kstars, ImageMagick (convert), pdftk
#
# Invokation:
# ./generate-logbook.sh <configuration shell script> ["build" directory]
# Note that the build directory *MUST BE* relative to the current directory. The default value is 'build'
##### Variables in the configuration file supplied. Default values in parantheses. #####
########################################################################################
# You may set these variables in the configuration file (essentially a
# shell script) supplied on the command line to set various parameters
# of the logbook generation.
### Mandatory
# PROJECT_NAME -- The title of the book (eg: The Messier Observer's Handbook)
# OBJECTLIST_FILE -- A file containing a list of objects that KStars knows about. Optionally, separated by |, fields containing a brief description of the object, and observability codes
# PREFACE_FILE -- A TeX file containing the preface of the logbook
### Generic
# DEBUG (unset) -- if set, enables verbose debugging output
# NO_DELETE_UNUSED (unset) -- if set, does not delete temporary sky chart SVG and DSS gif files
# NO_REUSE_EXISTING_SKYCHART (unset) -- if set, does not reuse existing skychart images, and generates new ones instead
# NO_REUSE_EXISTING_DSS (unset) -- if set, does not reuse existing DSS images, and downloads new ones instead
# DSS_RESIZE (unset) -- can be set to a size (eg: 1024) argument understood by the -resize option of ImageMagick's convert utility, so as to save space by downscaling DSS imagery.
### Controlling the form generation
# SINGLE_PAGE (unset) -- if set, enables single-page logging forms
# FOV_ZOOMED_IN (unset) -- used only in two-page mode. Sets the zoomed-in FOV. If unset, a dynamic FOV of 10 * (object's major axis is used)
# FOV_ZOOMED_OUT (40) -- used only in two-page mode. Sets the zoomed-out FOV. If unset, a default of 40 degrees is used
# FOV_INTERMEDIATE (unset) -- used only in two-page mode. Sets the intermediate FOV. If unset, the logarithmic average of the zoomed-in and zoomed-out FOVs is used.
# ZOOMED_IN_FOV_NO_SMALLER_THAN_DSS (unset) -- used only in two-page mode. If set, the zoomed-in FOV is always larger than the larger DSS image dimension.
# APPROX_FOV (20) -- used only in single-page mode. Sets the FOV of the skychart
# SKYCHART_RATIO (0.6) -- used only in single-page mode. Sets the ratio of space used by the sky chart to the total space used by the DSS image and the sky chart.
### Overlays
# LOGO_SIZE (0.7) -- size of an optional logo overlay in inches
# LOGO_FILE (unset) -- file containing an optional logo to render on each object's front page
# BINOCULAR_ICON (binoculars.pdf) -- a file containing clipart of a binocular to render for binocular-observable objects
# TELESCOPE_ICON (kstars.pdf) -- a file containing clipart of a telescope to render for telescope-observable objects
# EYE_ICON (eye.pdf) -- a file containing clipart indicative of naked eye observability
# LOGFORM_FILE (Logging-Form.pdf) -- a file containing the logging form
# CITY_ICON (city.pdf) -- a file containing the city icon
##################################
############# SCRIPT #############
##################################
##### Default values for various settable parameters.
## Unsettables
unset LOGO_FILE
unset DSS_RESIZE
unset NO_DELETE_UNUSED
unset NO_REUSE_EXISTING_DSS
unset NO_REUSE_EXISTING_SKYCHART
unset SINGLE_PAGE
unset FOV_ZOOMED_IN
unset FOV_INTERMEDIATE
unset FOV_ZOOMED_OUT
unset APPROX_FOV
unset ZOOMED_IN_FOV_NO_SMALLER_THAN_DSS
unset NO_PREFACE
## Debug mode (verbosity)
unset DEBUG
## Star chart and DSS imagery settings
SKYCHART_RATIO=0.6 ## Used _only_ with single page mode. Percentage of the space that is allocated to the Sky Chart.
## Default values for files and properties for various icons and overlays. To override, redefine in the config file
LOGO_SIZE=0.7 # Logo size in inches.
CITY_ICON="city.pdf"
BINOCULAR_ICON="binoculars.pdf"
TELESCOPE_ICON="kstars.pdf"
EYE_ICON="eye.pdf"
LOGFORM_FILE="Logging-Form.pdf"
MAIN_TEX_FILE="Main.tex"
##### Read command line arguments. Check if we have been supplied with a configuration file, exporting various variables.
if [ -z "$1" ]; then
echo "ERROR: No configuration file supplied. Please see the README for details on how to create one."
echo "Invokation: ./generate-logbook.sh <configuration shell script> [\"build\" directory]"
echo "Note that the build directory *MUST BE* relative to the current directory. The default value is 'build'"
exit 1;
else
CONFIG_FILE=$1
fi;
if [ ! -f "$CONFIG_FILE" ]; then
echo "ERROR: Configuration script file " $CONFIG_FILE " not found. Please supply a valid filename."
echo "Invokation: ./generate-logbook.sh <configuration shell script> [\"build\" directory]"
echo "Note that the build directory *MUST BE* relative to the current directory. The default value is 'build'"
exit 1;
fi;
if [ -z "$2" ]; then
BUILD_DIR='build'
else
BUILD_DIR=$4
fi;
if [ $DEBUG ]; then echo "Using the directory ${BUILD_DIR} for temporary files and for caching DSS images. The directory will be created if it does not already exist."; fi;
mkdir -p $BUILD_DIR; # Create the "build" directory
##### Source configuration file and check if essential variables are defined and valid
if [ $DEBUG ]; then echo "Sourcing config file: ${CONFIG_FILE}"; fi;
source $CONFIG_FILE;
if [ -z "$PROJECT_NAME" ]; then
echo "ERROR: Project Name is blank. Please set at least the bare minimum required parameters. See the README for more."
exit 1;
fi;
if [ ! -f "$OBJECTLIST_FILE" ]; then
echo "ERROR: Object list file " $OBJECTLIST_FILE " not found. Please set a valid file."
exit 1;
fi;
if [ ! "${NO_PREFACE}" ]; then
if [ ! -f "$PREFACE_FILE" ]; then
echo "ERROR: LaTeX Preface file \"$2\" is not a valid file. Please set a valid file."
exit 1;
fi;
else
if [ $DEBUG ]; then echo "No preface."; fi;
fi;
if [ $DEBUG ]; then echo "Object list file: ${OBJECTLIST_FILE}. Preface file: ${PREFACE_FILE}. Project Name: ${PROJECT_NAME}"; fi;
if [ ! -f "$LOGO_FILE" ]; then
echo "Warning: Not a valid file: " $LOGO_FILE
echo "Will not use any logo"
LOGO_FILE=""
fi;
##### Some derived quantities that don't change
TOTAL_OBJECTS=`cat ${OBJECTLIST_FILE} | wc -l` # Total number of objects
PREFACE_FILE_WITHOUT_EXTENSION=${PREFACE_FILE%.[tT][eE][xX]}
SKYCHART_SIZE=`echo "${SKYCHART_RATIO}*0.8" | bc -l`
DSS_SIZE=`echo "(1-${SKYCHART_RATIO})*0.8" | bc -l`
##### Initialize various counters and "loop" variables
list='' # List of objects for final processing
checklist_count=20 # Count for objects in checklist to prevent overflowing the page. Start from 10 since the first page has a chapter title etc.
object_count=0 # Count of the number of objects, that doesn't reset
##### Initialize the content of various files
echo "" > ${BUILD_DIR}/Objects.tex
echo "" > ${BUILD_DIR}/ConstType.txt
echo "" > ${BUILD_DIR}/ObjectsByType.tex
echo "" > ${BUILD_DIR}/ObjectsByConstellation.tex
echo "" > ${BUILD_DIR}/TrivialNames.txt
echo "%\resizebox{\textwidth}{!}{
%\centering
%\newcolumntype{C}{>{\centering\arraybackslash} m{0.1\textwidth}}
{
\rowcolors{3}{white}{tablealt}
\begin{longtable}{r l l l l l l |c|c| }
\caption{Checklist of Objects}\\\\
%\hline
Sl. No. & Object & Type & Constellation & Mag. & Size & Page & Obs. Date & Second Obs.\\\\
%\hline
\toprule
\endhead
\midrule
\multicolumn{9}{r}{\emph{Continued on the following page}}
\endfoot
\bottomrule
\endlastfoot
" > ${BUILD_DIR}/Checklist.tex
echo "\title{\Huge ${PROJECT_NAME}}
\maketitle
\frontmatter
\tableofcontents
%% Commands for icons
\renewcommand{\cityicon}{${CITY_ICON}}
\renewcommand{\binocularicon}{${BINOCULAR_ICON}}
\renewcommand{\eyeicon}{${EYE_ICON}}
\renewcommand{\telescopeicon}{${TELESCOPE_ICON}} " > ${BUILD_DIR}/FrontMatter.tex
if [ ! "${NO_PREFACE}" ]; then
echo "
\chapter*{Preface}
\input{$PREFACE_FILE_WITHOUT_EXTENSION}" >> ${BUILD_DIR}/FrontMatter.tex
fi;
##### Main loop -- loops over objects in the list
while read object_list_line; do
if [ $DEBUG ]; then echo "Processing line: " $object_list_line; fi;
#### Retrieve and set up object data in variables.
object=`echo $object_list_line | awk -F'|' '{ print $1 }'` # Retrieve the name of the object from the list
object_description=`echo $object_list_line | awk -F'|' '{ print $2 }' | sed 's/___REPLACE_PIPE___/|/g'` # Retrieve a description of the object. The sed is a hack to be able to use \verb|...| (verbatim)
object_observability=`echo $object_list_line | awk -F'|' '{ print $3 }'` # Retrieve an observability string indicating whether the object is city / binocular observable
if [ -n "$object_description" ]; then
object_description_with_prefix="\textbf{Description:} $object_description";
else
object_description_with_prefix="\vskip 20pt"
fi;
if [ $DEBUG ]; then echo "Object: " $object; fi;
object_underscored=`echo $object | sed 's/ /_/g'`; # An underscored copy of the object for use in file names etc
if [ $DEBUG ]; then echo "Underscored: " $object_underscored; fi;
# Look towards object before getting XML so that current RA / Dec are updated.
if [ $DEBUG ]; then echo "Steering KStars to object ${object}. Make sure it exists in KStars as there is no error checking."; fi;
qdbus org.kde.kstars /KStars org.kde.kstars.lookTowards "$object"
qdbus org.kde.kstars /KStars org.kde.kstars.lookTowards "$object" # KStars has some weird bug of landing slightly off from the object. Calling this again is a hack to get right on the object.
qdbus org.kde.kstars /KStars org.kde.kstars.lookTowards "$object" # KStars has some weird bug of landing slightly off from the object. Calling this again is a hack to get right on the obj
XML=`qdbus org.kde.kstars /KStars org.kde.kstars.getObjectDataXML "$object"`
maj_axis=`echo $XML | xmlstarlet sel -t -m "object" -v "Major_Axis"`
min_axis=`echo $XML | xmlstarlet sel -t -m "object" -v "Minor_Axis"`
RA_HMS=`echo $XML | xmlstarlet sel -t -m "object" -v "RA_HMS" | sed 's/\([hms]\)/^{\\\mathrm{\1}\\\,}/g'`
RA_HMS_J2000=`echo $XML | xmlstarlet sel -t -m "object" -v "RA_J2000_HMS" | sed 's/\([hms]\)/^{\\\mathrm{\1}\\\\\,}/g'`
Dec_DMS=`echo $XML | xmlstarlet sel -t -m "object" -v "Dec_DMS" | sed "s/°/\\\\\circdegree\\\\\,/;s/'/'\\\\\,/;s/\"/''\\\\\,/"` # SED needed because LaTeX doesn't like the degree symbol
Dec_DMS_J2000=`echo $XML | xmlstarlet sel -t -m "object" -v "Dec_J2000_DMS" | sed "s/°/\\\\\circdegree\\\\\,/;s/'/'\\\\\,/;s/\"/''\\\\\,/"` # SED needed because LaTeX doesn't like the degree symbol
mag=`echo $XML | xmlstarlet sel -t -m "object" -v "Magnitude"`
Name=`echo $XML | xmlstarlet sel -t -m "object" -v "Name"`
Long_Name=`echo $XML | xmlstarlet sel -t -m "object" -v "Long_Name"`
Alt_Name=`echo $XML | xmlstarlet sel -t -m "object" -v "Alt_Name"`
Object_Type=`echo $XML | xmlstarlet sel -t -m "object" -v "Type"`
Position_Angle=`echo $XML | xmlstarlet sel -t -m "object" -v "Position_Angle"`
Constellation=`echo $XML | xmlstarlet sel -t -m "object" -v "Constellation"`
if test "$Long_Name" != "$Name"; then
# Mirach's Ghost gets its own special hack to remove "(Galaxy not found :)" :D
Long_Name=`echo ${Long_Name} | sed 's/ (Galaxy not found :)//'`
# Add an entry into the Trivial Names list
echo "${Long_Name} & ${Name} & \\pageref{${object_underscored}} \\\\ %\\hline" >> ${BUILD_DIR}/TrivialNames.txt
Name_Display="${Name} (${Long_Name})"
else
Name_Display="${Name}"
fi;
if test -z "$Alt_Name"; then
Alt_Name="--" # Use a dash for blank alternate names
fi;
# skymap_aspect_ratio=`qdbus org.kde.kstars /KStars org.kde.kstars.getSkyMapDimensions | sed 's,x,/,' | bc -l`
# width=`qdbus org.kde.kstars /KStars org.kde.kstars.getSkyMapDimensions | sed 's,x.*$,,'`
# height=`qdbus org.kde.kstars /KStars org.kde.kstars.getSkyMapDimensions | sed 's,^.*x,,'`
#### Get DSS image
DSS_URL=`qdbus org.kde.kstars /KStars org.kde.kstars.getDSSURL "$object"`
DSS_width=`echo $DSS_URL | sed "s/^.*&h=\([0-9\.]*\)&w=\([0-9\.]*\)&.*$/\2/"`
DSS_height=`echo $DSS_URL | sed "s/^.*&h=\([0-9\.]*\)&w=\([0-9\.]*\)&.*$/\1/"`
# DSS_size_string=`echo $DSS_URL | sed "s/^.*&h=\([0-9\.]*\)&w=\([0-9\.]*\)&.*$/$\2' \\\\\times \1'$/"`
DSS_size_string="$ ${DSS_width}' \\times ${DSS_height}' $"
DSS=${BUILD_DIR}/${object_underscored}_dss.png
DSS_band="B"
if [ ! -f "${DSS}" -o "${NO_REUSE_EXISTING_DSS}" ]; then
if [ $DEBUG ]; then echo "Obtaining DSS image. Query URL: " $DSS_URL; fi;
wget $DSS_URL -O ${BUILD_DIR}/${object_underscored}_dss.gif
ftype=`file "${BUILD_DIR}/${object_underscored}_dss.gif"`
if [[ $ftype != *GIF* ]]; then
if [ $DEBUG ]; then echo "Failed on Blue. Trying to obtain a red plate"; fi;
# We failed to download. Try Red plates
wget `echo "$DSS_URL" | sed 's/_blue/_red/'` -O ${BUILD_DIR}/${object_underscored}_dss.gif
ftype=`file "${BUILD_DIR}/${object_underscored}_dss.gif"`
DSS_band="R"
if [[ $ftype != *GIF* ]]; then
if [ $DEBUG ]; then echo "Failed on Red. Trying to obtain an IR plate"; fi;
# Even the red plates failed. Try IR
wget `echo "$DSS_URL" | sed 's/_blue/_ir/'` -O ${BUILD_DIR}/${object_underscored}_dss.gif
ftype=`file "${BUILD_DIR}/${object_underscored}_dss.gif"`
DSS_band="I"
fi;
fi;
## TODO: Add the band (IR / Blue / Red) of the DSS image to the caption
if [[ $ftype != *GIF* ]]; then
echo "Warning: Could not download DSS image. Will proceed without one";
DSS_band="?"
DSS_size_string="?"
rm -f ${BUILD_DIR}/${object_underscored}_dss.gif # Make sure it's not re-used in future
rm -f ${BUILD_DIR}/${object_underscored}_dss_metadata.txt
else
echo "(${DSS_band}, ${DSS_size_string})" > ${BUILD_DIR}/${object_underscored}_dss_metadata.txt
fi;
if [ $DSS_RESIZE ]; then
convert -negate ${BUILD_DIR}/${object_underscored}_dss.gif -resize ${DSS_RESIZE} $DSS
else
convert -negate ${BUILD_DIR}/${object_underscored}_dss.gif $DSS
fi;
if [ ! ${NO_DELETE_UNUSED} ]; then
rm -f ${BUILD_DIR}/${object_underscored}_dss.gif
fi;
else
if [ $DEBUG ]; then echo "DSS image found at ${DSS}. Assuming that we can use that."; fi;
fi;
if [ -f ${BUILD_DIR}/${object_underscored}_dss_metadata.txt ]; then
DSS_metadata=`cat "${BUILD_DIR}/${object_underscored}_dss_metadata.txt"`
else
DSS_metadata="(details unknown)"
fi;
#### Calculate FOVs and Acquire sky maps
# if [ $DEBUG ]; then echo "Steering KStars to object ${object}. Make sure it exists in KStars as there is no error checking."; fi;
# qdbus org.kde.kstars /KStars org.kde.kstars.lookTowards "$object"
# qdbus org.kde.kstars /KStars org.kde.kstars.lookTowards "$object" # KStars has some weird bug of landing slightly off from the object. Calling this again is a hack to get right on the object.
if [ ! ${SINGLE_PAGE} ]; then
## Filenames to carry the 3 skycharts
zoomed_out_skychart=`pwd`/${BUILD_DIR}/${object_underscored}_skychart_zoomed_out.svg
intermediate_skychart=`pwd`/${BUILD_DIR}/${object_underscored}_skychart_intermediate.svg
zoomed_in_skychart=`pwd`/${BUILD_DIR}/${object_underscored}_skychart_zoomed_in.svg
zoomed_out_skychart_PDF=`pwd`/${BUILD_DIR}/${object_underscored}_skychart_zoomed_out.pdf
intermediate_skychart_PDF=`pwd`/${BUILD_DIR}/${object_underscored}_skychart_intermediate.pdf
zoomed_in_skychart_PDF=`pwd`/${BUILD_DIR}/${object_underscored}_skychart_zoomed_in.pdf
## FOV sizes, in degrees for multi-page mode
if [ -n "${FOV_ZOOMED_IN}" ]; then
fov_zoomed_in=${FOV_ZOOMED_IN}
else
fov_zoomed_in=`echo $maj_axis/6.0 | bc -l` # 10 x the major axis, in degrees
if [ -z $fov_zoomed_in -o $(echo "$fov_zoomed_in <= 0.35" | bc -l) -eq 1 ]; then
fov_zoomed_in=0.35
fi;
fi;
if [ -n "${ZOOMED_IN_FOV_NO_SMALLER_THAN_DSS}" ]; then
DSS_max_dimension=${DSS_width}
if [ `echo "${DSS_height} > ${DSS_max_dimension}" | bc` -eq 1 ]; then
DSS_max_dimension=${DSS_height};
fi;
if [ `echo "${fov_zoomed_in}*60.0 < ${DSS_max_dimension}" | bc` -eq 1 ]; then
if [ $DEBUG ]; then echo "Zoomed-in FOV ${fov_zoomed_in} is smaller than DSS dimensions ${DSS_width} × ${DSS_height}. Resetting zoomed-in FOV to ${DSS_max_dimension}."; fi;
fov_zoomed_in=`echo "${DSS_max_dimension} / 60.0" | bc`;
fi;
fi;
if [ -n "${FOV_ZOOMED_OUT}" ]; then
fov_zoomed_out=${FOV_ZOOMED_OUT}
else
fov_zoomed_out=40
fi;
if [ -n "${FOV_INTERMEDIATE}" ]; then
fov_intermediate=${FOV_INTERMEDIATE}
else
fov_intermediate=`echo "e(( l($fov_zoomed_in) + l($fov_zoomed_out) )/2)" | bc -l` # Arithmetic mean of log(FOV)
fi;
if [ $DEBUG ]; then echo "FOVs in Degrees. Zoomed-in: ${fov_zoomed_in}; Intermediate: ${fov_intermediate}; Zoomed-out: ${fov_zoomed_out}"; fi;
if [ -f "$zoomed_in_skychart_PDF" -a ! "${NO_REUSE_EXISTING_SKYCHART}" ]; then
echo "Warning: Using existing zoomed in sky chart for object ${object} -- ${zoomed_in_skychart_PDF}. If you changed FOVs, please delete the files.";
else
if [ $DEBUG ]; then echo "Capturing zoomed in skychart for ${object}. FOV = ${fov_zoomed_in}"; fi;
qdbus org.kde.kstars /KStars org.kde.kstars.setApproxFOV ${fov_zoomed_in}
qdbus org.kde.kstars /KStars org.kde.kstars.setApproxFOV ${fov_zoomed_in}
qdbus org.kde.kstars /KStars org.kde.kstars.exportImage "${zoomed_in_skychart}"
inkscape -T -A ${zoomed_in_skychart_PDF} ${zoomed_in_skychart}
fi;
if [ -f "$intermediate_skychart_PDF" -a ! "${NO_REUSE_EXISTING_SKYCHART}" ]; then
echo "Warning: Using existing intermediate sky chart for object ${object} -- ${intermediate_skychart_PDF}. If you changed FOVs, please delete the files.";
else
if [ $DEBUG ]; then echo "Capturing intermediate skychart for ${object}. FOV = ${fov_intermediate}"; fi;
qdbus org.kde.kstars /KStars org.kde.kstars.setApproxFOV ${fov_intermediate}
qdbus org.kde.kstars /KStars org.kde.kstars.setApproxFOV ${fov_intermediate}
qdbus org.kde.kstars /KStars org.kde.kstars.exportImage "${intermediate_skychart}"
inkscape -T -A ${intermediate_skychart_PDF} ${intermediate_skychart}
fi;
if [ -f "$zoomed_out_skychart_PDF" -a ! "${NO_REUSE_EXISTING_SKYCHART}" ]; then
echo "Warning: Using existing zoomed out sky chart for object ${object} -- ${zoomed_out_skychart_PDF}. If you changed FOVs, please delete the files.";
else
if [ $DEBUG ]; then echo "Capturing zoomed out skychart for ${object}. FOV = ${fov_zoomed_out}"; fi;
qdbus org.kde.kstars /KStars org.kde.kstars.setApproxFOV ${fov_zoomed_out}
qdbus org.kde.kstars /KStars org.kde.kstars.setApproxFOV ${fov_zoomed_out}
qdbus org.kde.kstars /KStars org.kde.kstars.exportImage "${zoomed_out_skychart}"
inkscape -T -A ${zoomed_out_skychart_PDF} ${zoomed_out_skychart}
fi;
if [ ! ${NO_DELETE_UNUSED} ]; then
if [ $DEBUG ]; then echo "Deleting unused SVG files."; fi;
rm -f "${zoomed_out_skychart}" "${zoomed_in_skychart}" "${intermediate_skychart}"
else
if [ $DEBUG ]; then echo "Keeping unused SVG files since NO_DELETE_UNUSED was defined."; fi;
fi;
else
## FOV sizes, in degrees, for single-page mode
skychart=`pwd`/${BUILD_DIR}/${object_underscored}_skychart.svg
skychart_PDF=`pwd`/${BUILD_DIR}/${object_underscored}_skychart.pdf
if [ ${APPROX_FOV} ]; then
fov=${APPROX_FOV}
else
fov=20;
fi;
if [ -f "${skychart_PDF}" -a ! "${NO_REUSE_EXISTING_SKYCHART}" ]; then
echo "Warning: Using existing sky chart for object ${object} -- ${skychart_PDF}. If you changed FOVs, please delete the files.";
else
if [ $DEBUG ]; then echo "Capturing skychart for ${object}. FOV = ${fov}"; fi;
qdbus org.kde.kstars /KStars org.kde.kstars.setApproxFOV "${fov}"
qdbus org.kde.kstars /KStars org.kde.kstars.exportImage "${skychart}"
inkscape -T -A ${skychart_PDF} ${skychart}
fi;
if [ ! ${NO_DELETE_UNUSED} ]; then
if [ $DEBUG ]; then echo "Deleting unused SVG file."; fi;
rm -f "${skychart}"
else
if [ $DEBUG ]; then echo "Keeping unused SVG file since NO_DELETE_UNUSED was defined."; fi;
fi;
fi;
##### Set up the observation pageLaTeX. FIXME: Is there a better way to write this?
if [ $DEBUG ]; then echo "Generating TeX for the object's logging form"; fi;
texfile=${BUILD_DIR}/${object_underscored}.tex
echo "" > $texfile
### First write out the common parts -- title, subtitle, data table, and description.
echo "
\section*{\center \Huge ${Name_Display}}
\vspace{-2pt}
\begin{center}
\Large ${Object_Type} in ${Constellation} \\\\
\end{center}
\ifletterpaper
\vspace{0.1pt}
\else
\vspace{2pt}
\fi
\begin{center}
\label{$object_underscored}
\ifletterpaper
\vspace{2pt}
\else
\vspace{5pt}
\fi
\ifletterpaper
\else
\resizebox{4.5in}{!}{
\fi
\begin{tabular}{| l | c || l | c |}
\hline
Right Ascension (current) & $ ${RA_HMS} $ & Declination (current) & $ ${Dec_DMS} $ \\\\
Right Ascension (J2000.0) & $ ${RA_HMS_J2000} $ & Declination (J2000.0) & $ ${Dec_DMS_J2000} $ \\\\
\hline
Size & $ ${maj_axis}' \times ${min_axis}' $ & Position Angle & $ ${Position_Angle} \\circdegree $ \\\\
Magnitude & $ ${mag} $ & Other Designation & ${Alt_Name} \\\\
\hline
\end{tabular}
\ifletterpaper
\else
}
\fi
\end{center}
\vspace{3pt}
{\small ${object_description_with_prefix}} \\\\
\ifletterpaper
\vspace{-8pt}
\else
\vspace{2pt}
\fi
" >> $texfile
if [ ${SINGLE_PAGE} ]; then
### In single page mode, put the single skychart and the DSS image side-by-side
if [ $DEBUG ]; then echo "Generating single page version"; fi;
echo "
\begin{figure*}[h!]
\centering
\begin{subfigure}[h!]{${SKYCHART_SIZE}\textwidth}
\centering
\includegraphics[width=\textwidth]{${skychart_PDF}}
\caption*{Sky Chart}
\end{subfigure}
~
\begin{subfigure}[h!]{${DSS_SIZE}\textwidth}
\centering
\includegraphics[width=\textwidth]{$DSS}
\caption*{DSS Image ${DSS_metadata}}
\end{subfigure}
\end{figure*}
\\\\ " >> $texfile
### Put in the logging form in the remaining space
echo "
\begin{figure*}[h!]
\centering
\includegraphics[width=0.85\textwidth,height=0.35\textheight,keepaspectratio]{${LOGFORM_FILE}}
\end{figure*}
" >> $texfile
else
### For multi-page mode, just write the first page now
if [ $DEBUG ]; then echo "Generating two-page version"; fi;
### In multi-page mode, put the lower two zoom levels side-by-side
echo "
\begin{figure*}[h!]
\centering
\begin{subfigure}[h!]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{${zoomed_out_skychart_PDF}}
\caption*{Wide-field chart}
\end{subfigure}
~
\begin{subfigure}[h!]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{${intermediate_skychart_PDF}}
\caption*{Intermediate chart}
\end{subfigure}
\end{figure*}
\vspace{2pt}
" >> $texfile
### Then put the wide-field chart filling the rest of the page
echo "
\begin{figure*}[h!]
\centering
\ifletterpaper
\includegraphics[width=0.9\textwidth,height=0.3\textheight,keepaspectratio]{${zoomed_in_skychart_PDF}}
\else
\includegraphics[width=0.9\textwidth,height=0.35\textheight,keepaspectratio]{${zoomed_in_skychart_PDF}}
\fi
\caption*{Zoomed-in chart}
\end{figure*}" >> $texfile
### We still have the second page to write, but we take a break here to put the overlays on the front page.
fi;
#### Draw the overlay figures -- a logo, if supplied; city, telescopes, binocular icons for indicating observability
## If a logo file is supplied, render it. TODO: Make the position specifiable
if [ -n "$LOGO_FILE" -a -f "$LOGO_FILE" ]; then
if [ $DEBUG ]; then echo "Writing TeX to place logo from ${LOGO_FILE}"; fi;
echo "
\ifletterpaper
\begin{textblock}{${LOGO_SIZE}}(1.05,1.8)
\else
\begin{textblock}{${LOGO_SIZE}}(0.8,2.0)
\fi
\begin{minipage}{\textwidth}
\setlength{\parindent}{0pt}%
\setlength{\parskip}{0.1cm}%
\begin{figure*}[h!]
\includegraphics[width=\textwidth]{$LOGO_FILE}
\end{figure*}
\end{minipage}
\end{textblock}
" >> $texfile
fi;
## If the object is city-observable, render a city icon and a telescope icon on the top-right
if [[ "${object_observability}" == *C* ]]; then
if [ $DEBUG ]; then echo "Writing TeX to place city icon from ${CITY_ICON} and telescope icon from ${TELESCOPE_ICON}"; fi;
echo "
\ifletterpaper
\begin{textblock}{0.5}(6.9,1.95)
\else
\begin{textblock}{0.5}(6.51,2.15)
\fi
\begin{minipage}{\textwidth}
\setlength{\parindent}{0pt}%
\setlength{\parskip}{0.1cm}%
\begin{figure*}[h!]
\includegraphics[width=\textwidth]{${CITY_ICON}}
\end{figure*}
\end{minipage}
\end{textblock}
\ifletterpaper
\begin{textblock}{0.2}(7.47,2.10)
\else
\begin{textblock}{0.2}(7.08,2.30)
\fi
\begin{minipage}{\textwidth}
\setlength{\parindent}{0pt}%
\setlength{\parskip}{0.1cm}%
\begin{figure*}[h!]
\includegraphics[width=\textwidth]{${TELESCOPE_ICON}}
\end{figure*}
\end{minipage}
\end{textblock}
" >> $texfile;
fi;
## If the object is binocular-observable, render a binocular icon on the top-right
if [[ "${object_observability}" == *B* ]]; then
if [ $DEBUG ]; then echo "Writing TeX to place binocular icon from ${BINOCULAR_ICON}"; fi;
echo "
\ifletterpaper
\begin{textblock}{0.5}(6.9,2.325)
\else
\begin{textblock}{0.5}(6.51,2.525)
\fi
\begin{minipage}{\textwidth}
\setlength{\parindent}{0pt}%
\setlength{\parskip}{0.1cm}%
\begin{figure*}[h!]
\includegraphics[width=\textwidth]{${BINOCULAR_ICON}}
\end{figure*}
\end{minipage}
\end{textblock}
" >> $texfile;
fi;
## If the object is observable in the city with binoculars, additionally render a small binocular icon next to the city icon
if [[ "${object_observability}" == *CB* ]]; then
if [ $DEBUG ]; then echo "Writing TeX to place binocular icon from ${BINOCULAR_ICON} next to the city icon"; fi;
echo "
\ifletterpaper
\begin{textblock}{0.20}(7.47,1.90)
\else
\begin{textblock}{0.20}(7.08,2.10)
\fi
\begin{minipage}{\textwidth}
\setlength{\parindent}{0pt}%
\setlength{\parskip}{0.1cm}%
\begin{figure*}[h!]
\includegraphics[width=\textwidth]{${BINOCULAR_ICON}}
\end{figure*}
\end{minipage}
\end{textblock}
" >> $texfile;
fi;
## If the object is observable with the naked eye, render a the naked eye icon on the top-right
if [[ "${object_observability}" == *N* ]]; then
if [ $DEBUG ]; then echo "Writing TeX to place eye icon from ${EYE_ICON}"; fi;
echo "
\ifletterpaper
\begin{textblock}{0.5}(7.47,2.45)
\else
\begin{textblock}{0.5}(7.08,2.65)
\fi
\begin{minipage}{\textwidth}
\setlength{\parindent}{0pt}%
\setlength{\parskip}{0.1cm}%
\begin{figure*}[h!]
\includegraphics[width=\textwidth]{${EYE_ICON}}
\end{figure*}
\end{minipage}
\end{textblock}
" >> $texfile;
fi;
## If the object is observable in the city with the naked eye, additionally render a small eye icon next to the city icon
if [[ "${object_observability}" == *CN* ]]; then
if [ $DEBUG ]; then echo "Writing TeX to place eye icon from ${EYE_ICON} next to the city icon"; fi;
echo "
\ifletterpaper
\begin{textblock}{0.20}(7.70,1.95)
\else
\begin{textblock}{0.20}(7.30,2.15)
\fi
\begin{minipage}{\textwidth}
\setlength{\parindent}{0pt}%
\setlength{\parskip}{0.1cm}%
\begin{figure*}[h!]
\includegraphics[width=\textwidth]{${EYE_ICON}}
\end{figure*}
\end{minipage}
\end{textblock}
" >> $texfile;
fi;
## If we are writing 2 pages, we should resume writing the second page.
if [ ! ${SINGLE_PAGE} ]; then
### If we are writing 2 pages per object, we have to still write the next page.
### So we first clear the page
echo "\clearpage" >> $texfile
### Put the DSS image, filling 0.9\textwidth or 0.5\textheight, whichever is smaller
echo "
\ifletterpaper
\vskip 15pt
\\
\fi
\begin{figure*}[h!]
\centering
\ifletterpaper
\includegraphics[width=0.9\textwidth,height=0.42\textheight,keepaspectratio]{${DSS}}
\else
\includegraphics[width=0.9\textwidth,height=0.42\textheight,keepaspectratio]{${DSS}}
\fi
\caption*{DSS Image (${DSS_size_string})}
\end{figure*}" >> $texfile
### Put the observing log form in the remaining space
echo "
\begin{figure*}[h!]
\centering
\ifletterpaper
\includegraphics[width=0.9\textwidth,height=0.42\textheight,keepaspectratio]{${LOGFORM_FILE}}
\else
\includegraphics[width=0.9\textwidth,height=0.42\textheight,keepaspectratio]{${LOGFORM_FILE}}
\fi
\end{figure*}
" >> $texfile
fi;
#### Now we're done writing the TeX content into ${object_underscored}.tex. We need to put that into the larger Objects file.
## Append the object to the list of objects
list="$list ${object_underscored}.pdf"
if [ $DEBUG ]; then echo "Adding a \input for ${object_underscored}.tex into the Objects.tex file in the ${BUILD_DIR} directory"; fi;
echo -e "\n%%%%%%%%%%%%%%%%%%%%%% ${object} %%%%%%%%%%%%%%%%%%%%%%" >> ${BUILD_DIR}/Objects.tex
echo -e "\n\\\\clearpage" >> ${BUILD_DIR}/Objects.tex ### Clear the page before starting every object's log form
echo "\input{${BUILD_DIR}/${object_underscored}}" >> ${BUILD_DIR}/Objects.tex
#### Write a LaTeX entry into the Checklist.tex file to include this object in the checklist
object_count=$(($object_count+1)) # Increment object count before writing into Checklist / ConstType, so serial numbers begin with 1.
if [ $DEBUG ]; then echo "Writing entry into Checklist file"; fi;
echo "${object_count} & ${Name_Display} & ${Object_Type} & ${Constellation} & $ ${mag} $ & $ ${maj_axis}' \times ${min_axis}' $ & \pageref{$object_underscored} & & \\\\" >> ${BUILD_DIR}/Checklist.tex
#### Write an entry into ConstType.txt to generate indexes containing objects by constellation and type
if [ $DEBUG ]; then echo "Writing entry into ConstType.txt file for generation of index by constellation and type"; fi;
echo "${Constellation}|${Object_Type}|${object_underscored}|${object}|${object_count}|${Name_Display}" >> ${BUILD_DIR}/ConstType.txt
# ## If we are overflowing a page (~ 65 entries) of the checklist, close the table, clearpage, and start afresh on the next page.
# checklist_count=$(($checklist_count+1))
# if [ $DEBUG ]; then echo "Object count: ${object_count}; Checklist count: ${checklist_count}; Total objects: ${TOTAL_OBJECTS}"; fi;
# if [ ${checklist_count} -ge 1155 -a ${object_count} -lt ${TOTAL_OBJECTS} ]; then
# if [ $DEBUG ]; then echo "Hit per-page limit for checklist before we're done. Creating a new page."; fi;
# echo "\end{tabular}
# }
# \clearpage
# \resizebox{\textwidth}{!}{
# \centering
# %\newcolumntype{C}{>{\centering\arraybackslash} m{0.1\textwidth}}
# \begin{tabular}{|r||c|c|c|c|c|c||c|c|}
# \hline
# Sl.No. & Object & Type & Constellation & Mag. & Size & Page & Obs. Date & Second Obs.\\\\
# \hline
# \hline
# " >> ${BUILD_DIR}/Checklist.tex
# checklist_count=0;
# fi;
#### Write progress text to terminal
echo "Object-wise Progress: " `echo "100*${object_count}/${TOTAL_OBJECTS}" | bc`"%";
done <$OBJECTLIST_FILE;
##### Close up the checklist file
echo "\end{longtable}
}" >> ${BUILD_DIR}/Checklist.tex
##### Generate sorted lists of constellations and types
if [ $DEBUG ]; then echo "Making lists of constellations and types in Constellations.txt and Types.txt."; fi;
cat ${BUILD_DIR}/ConstType.txt | awk -F'|' '{ print $1 }' | sort | uniq > ${BUILD_DIR}/Constellations.txt
cat ${BUILD_DIR}/ConstType.txt | awk -F'|' '{ print $2 }' | sort | uniq > ${BUILD_DIR}/Types.txt
##### Generate object list by constellation
while read Constellation; do
if [ $DEBUG ]; then echo "Writing constellation-wise index for constellation ${Constellation}"; fi;
echo "\subsection*{${Constellation}}" >> ${BUILD_DIR}/ObjectsByConstellation.tex
grep "^${Constellation}|" ${BUILD_DIR}/ConstType.txt | awk -F'|' '{ print $NF " [\\pageref{" $3 "}]" "\\\\" }' | sort >> ${BUILD_DIR}/ObjectsByConstellation.tex
done < ${BUILD_DIR}/Constellations.txt;
##### Generate object list by type
while read Type; do
if [ $DEBUG ]; then echo "Writing object-type-wise index for object type ${Type}"; fi;
echo "\subsection*{${Type}}" >> ${BUILD_DIR}/ObjectsByType.tex
grep "^[^|]*|${Type}|" ${BUILD_DIR}/ConstType.txt | awk -F'|' '{ print $NF " [\\pageref{" $3 "}]" "\\\\" }' | sort >> ${BUILD_DIR}/ObjectsByType.tex
done < ${BUILD_DIR}/Types.txt;
##### Listing of Common Names
echo "\begin{center}
\rowcolors{3}{white}{tablealt}
\begin{longtable}{l l r}
\caption{Objects by common name}\\\\
%\hline
Common Name & Catalog Designation & Page \\\\
\toprule
%\hline
\endhead
\midrule
\multicolumn{3}{r}{\emph{Cont. on following page}}
\endfoot
\bottomrule
\endlastfoot
" > ${BUILD_DIR}/TrivialNames.tex
cat ${BUILD_DIR}/TrivialNames.txt | sort >> ${BUILD_DIR}/TrivialNames.tex
echo "
\end{longtable}
\end{center}
" >> ${BUILD_DIR}/TrivialNames.tex
##### Invoke PDFLaTeX twice to generate the PDFs
if [ $DEBUG ]; then echo "Done generating sources. Invoking pdflatex"; fi;
pdflatex -interaction nonstopmode -output-directory ${BUILD_DIR} ${MAIN_TEX_FILE}
pdflatex -interaction nonstopmode -output-directory ${BUILD_DIR} ${MAIN_TEX_FILE}
cp ${BUILD_DIR}/`echo ${MAIN_TEX_FILE} | sed 's/tex/pdf/'` Output.pdf
if [ $DEBUG ]; then echo "Script finished!"; fi;