diff --git a/Nasa2FGearthview/LICENSE b/Nasa2FGearthview/LICENSE
new file mode 100644
index 0000000..23cb790
--- /dev/null
+++ b/Nasa2FGearthview/LICENSE
@@ -0,0 +1,339 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ {description}
+ Copyright (C) {year} {fullname}
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ {signature of Ty Coon}, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/Nasa2FGearthview/README.md b/Nasa2FGearthview/README.md
new file mode 100644
index 0000000..3fd0213
--- /dev/null
+++ b/Nasa2FGearthview/README.md
@@ -0,0 +1,167 @@
+# Nasa2FGearthview
+A bash-script to convert NASA satellite images to ready-to-use
+textures for FG's EarthView using ImageMagick.
+
+For info about FGearthview, see the forum thread:
+ https://forum.flightgear.org/viewtopic.php?f=6&t=15754
+or this FG-wiki-page:
+ http://wiki.flightgear.org/Earthview
+
+
+------------------------------------
+About:
+
+This script runs on Linux (maybe Mac also?) in a Bash
+(Bourne Again Shell) - Windows is not supported (by the nature of the
+script). Maybe it works on windows as well, I don't know, feel free
+to try, and please let me know! :)
+
+This will download the raw images from http://visibleearth.nasa.gov -
+their server is not very fast, so I provide an alternative download
+location: https://musicchris.de/download/FG/EarthView/raw-data-NASA.7z
+This one is much quicker! If you really want the images directly from
+NASA, then provide "nasa" to the script (see below)
+
+In the end you will have 8 world-textures in .png and .dds format.
+Generally .dds is better in performance, but it won't work on some
+graphics cards. If this is the case for you, then try the .png files.
+For further information see:
+http://wiki.flightgear.org/index.php?title=DDS_Textures_in_FlightGear&redirect=no
+
+If you also converted the clouds, then you'll also find 8 cloud-
+textures in the format .png. Because the .dds-format has trouble with
+rendering heavy alpha images, which is because of it's compression
+algorythm [1], I think it's useless to also build faulty files.
+However, this is not entirely true! It is possible to switch off the
+.dds/DXT compression. But this results in huge files and is rather
+heavy on the GPU's RAM.
+
+Buckaroo has created a nice overview on dds-compression:
+[1] http://www.buckarooshangar.com/flightgear/tut_dds.html
+
+------------------------------------
+Installation and usage:
+
+Simply copy "convert.sh" into a folder of your liking and run it:
+
+$ ./convert.sh
+
+This will show a help text, since you didn't specify any target(s).
+Possible targets are:
+* world
+* clouds
+* all
+
+Additionally, there are some options you could specify (further
+explained below):
+* 1k | 2k | 4k | 8k | 16k
+* nasa
+* no-download
+* cleanup
+* rebuild
+* check
+
+So your call could look sth like this:
+
+$ ./convert.sh world no-download cleanup 8k
+
+
+------------------------------------
+Requirements:
+
+WARNING!
+
+This script uses a *lot* disk space! Make sure you have at least 90GB
+available!
+
+Also, this script will run for a *very long* time! It might be best to
+let it run over night - your computer might become unresponsive from
+time to time, due to the heavy CPU and memory load, which tends to
+occur, when converting 54000x27000 images. ;-)
+I also recommend to deactivate swapping!
+ $ sudo swapoff -a
+To reactivate swapping do:
+ $ sudo swapon -a
+
+This script relies on wget and imagemagick. Both are easily installed
+by your systems package-management-system.
+(On Debian/Ubuntu this is "apt-get")
+
+So, on Debian for instance, you only need to put the following into
+the console:
+
+ $ sudo apt-get install wget imagemagick
+
+Depending on your distro, the package names might differ slightly! Use
+a search engine of your choice to find out, how the packages are named
+in your distro!
+
+You may want to check:
+
+ $ apt search imagemagick
+
+
+------------------------------------
+Targets:
+
+world
+ Generates the world tiles, needed to run FG with EarthView.
+ You will find the results in output/[$resolution]/*. Copy
+ these into $FGDATA/Models/Astro/*. More about the installation
+ of these textures can be found here:
+ http://wiki.flightgear.org/Earthview#Customization
+
+clouds
+ Generates the cloud tiles, needed to run FG with EarthView.
+ The locations are the same as the other textures mentioned
+ above. Note that clouds are only available with up to 8k
+ resolution, due to the available data at NASA.
+
+all
+ Converts everything needed for a full-blown earthview texture
+ set. Does the same as:
+ $ ./convert.sh world clouds
+
+
+Options:
+
+1k | 2k | 4k | 8k | 16k
+ Lets you specify a desired resolution of the textures.
+ Possible values are 1k, 2k, 4k, 8k and 16k. If nothing is
+ specified, the script will generate all of the resolutions.
+ 16k is only available for earth textures.
+
+nasa
+ Causes the script to download directly from
+ http://visibleearth.nasa.gov . If omitted the script will
+ download from
+ https://musicchris.de/download/FG/EarthView/raw-data-NASA.7z
+ which is much faster!
+ Uses wget either way.
+
+no-download
+ Causes the script to skip the download function. If you
+ already have the source images, then you don't need to
+ re-download them. (About 2.4GB!)
+ If omitted, the script will download the source images from
+ https://musicchris.de/download/FG/EarthView/raw-data-NASA.7z
+
+cleanup
+ Deletes the temporary files created during texture generation.
+ These can be found in tmp/
+ Note: if for some reason you later want some other resolution,
+ then it's good to have the data there. So only do this, when
+ you're quite sure that you're done.
+ Frees up a lot of disk-space! Which would have to be
+ regenerated if needed again.
+
+rebuild
+ Deletes only the temporary files of the given target. So if
+ you call './convert.sh rebuild world' the script will delete
+ all corresponding temp-files of the target world, which will
+ trigger a complete regeneration of the relevant (instead of
+ skipping existing files)
+
+check
+ Creates mosaics of the tiles, so you can look at them and see
+ if all went well.
diff --git a/Nasa2FGearthview/convert.sh b/Nasa2FGearthview/convert.sh
new file mode 100755
index 0000000..48854a6
--- /dev/null
+++ b/Nasa2FGearthview/convert.sh
@@ -0,0 +1,1403 @@
+#!/bin/bash
+
+# convert.sh - a script to convert NASA sattelite images into textures for use with FGearthview (orbital rendering)
+# Copyright (C) 2016 Chris Schwarz
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+VERSION="v0.11"
+
+# make sure the script halts on error
+set -e
+
+function showHelp
+ {
+ echo "Nasa2FGearthview converter script $VERSION"
+ echo "https://github.com/chris-blues/Nasa2FGearthview"
+ echo
+ echo "Usage:"
+ echo "./convert.sh [ download world clouds 8k cleanup rebuild ]"
+ echo
+ echo "* Append \"nasa\" to download the needed images from NASA"
+ echo " -> This will download ca 2.4GB of data!"
+ echo " -> wget can continue interrupted downloads!"
+ echo " If omitted, it will download from my server, which is a lot"
+ echo " faster. See README for details."
+ echo "* Append \"no-download\" to the command to skip the download"
+ echo " process alltogether. Only makes sense if you already got"
+ echo " the necessary data."
+ echo "* Append \"world\" to the command to generate the world tiles"
+ echo "* Append \"clouds\" to the command to generate cloud tiles"
+ echo "* Append \"all\" to the command to generate both - world and"
+ echo " clouds"
+ echo "* Append the size of the tiles (1k, 2k, 4, 8k, 16k). If you"
+ echo " don't pass a resolution, then all resolutions will be"
+ echo " generated."
+ echo "* Append \"cleanup\" to delete all temporary files in tmp/"
+ echo " Same as \"./convert.sh world clouds rebuild\""
+ echo " Useful if the source files have changed."
+ echo "* Append \"rebuild\" to remove the corresponding temp-files"
+ echo " of your requested target."
+ echo " If you have \"world\" as target, that means all files in"
+ echo " tmp/world* and tmp/night* will be deleted, so that the"
+ echo " script will have to rebuild the entire set of files."
+ echo " So, if clouds and world are requested, effectively all temp-"
+ echo " files will be deleted (same as cleanup)"
+ echo " Useful if the source files have changed."
+ echo "* Append \"check\" to let check the results. This will create"
+ echo " mosaics of the existing tiles. If no target is specified,"
+ echo " all 3 layers will be built: clouds world and nightlights."
+ echo
+ echo "If, for some reason, the script aborts, then it will try to"
+ echo "skip the already completed steps, so you don't have to wait"
+ echo "for the first steps to be redone. Those also happen to be the"
+ echo "most heavy loads on the ressources."
+ echo
+ echo "WARNING!"
+ echo "This script uses a _lot_ of disk space! Make sure you choose"
+ echo "a disk, with at least 90GB free space."
+ echo
+ echo "This script will take a very long time, depending on your CPU"
+ echo "and memory. It's propably best, to let it run over night..."
+ echo
+ echo "Examples:"
+ echo "./convert.sh world clouds"
+ echo "Will generate all textures needed for EarthView"
+ echo
+ echo "./convert.sh rebuild clouds no-download"
+ echo "Will skip the download function and will proceed under the"
+ echo "assumption that the download has previously finished"
+ echo "correctly. Furthermore it will only generate the cloud-"
+ echo "textures. Before that all temp-files will be deleted, so that"
+ echo "the textures will be generated from scratch."
+ echo
+ echo "./convert.sh cleanup"
+ echo "Will delete all temp-files, so that on the next run"
+ echo "everything will have to be regenerated from scratch. Useful"
+ echo "if the source images have changed."
+ echo
+ echo "./convert world 4k"
+ echo "Will generate only tiles of the world of 4096x4096 size."
+ exit 1
+ }
+if [ -z $1 ] ; then showHelp ; fi
+if [ $1 == "--help" ] ; then showHelp ; fi
+if [ $1 == "-h" ] ; then showHelp ; fi
+
+################################
+## Get command line arguments ##
+################################
+for ARG in "$@"
+do
+ if [ $ARG == "nasa" ] ; then DOWNLOAD="true" ; DL_LOCATION="NASA" ; echo "Downloading from visibleearth.nasa.gov" ; fi
+ if [ $ARG == "no-download" ] ; then DOWNLOAD="false" ; echo "Skipping the download process" ; fi
+ if [ $ARG == "world" ] ; then WORLD="true" ; fi
+ if [ $ARG == "clouds" ] ; then CLOUDS="true" ; fi
+ if [ $ARG == "all" ] ; then WORLD="true" ; CLOUDS="true" ; fi
+ if [ $ARG == "1k" ] ; then RESOLUTION="1024" ; fi
+ if [ $ARG == "2k" ] ; then RESOLUTION="2048" ; fi
+ if [ $ARG == "4k" ] ; then RESOLUTION="4096" ; fi
+ if [ $ARG == "8k" ] ; then RESOLUTION="8192" ; fi
+ if [ $ARG == "16k" ] ; then RESOLUTION="16384" ; fi
+ if [ $ARG == "cleanup" ] ; then CLEANUP="true" ; fi
+ if [ $ARG == "rebuild" ] ; then REBUILD="true" ; fi
+ if [ $ARG == "check" ] ; then BUILDCHECKS="true" ; fi
+done
+if [ -z $DOWNLOAD ] ; then DOWNLOAD="true" ; fi
+if [ -z $WORLD ] ; then WORLD="false" ; fi
+if [ -z $CLOUDS ] ; then CLOUDS="false" ; fi
+if [ -z $CLEANUP ] ; then CLEANUP="false" ; fi
+if [ -z $REBUILD ] ; then REBUILD="false" ; fi
+if [ -z $BUILDCHECKS ] ; then BUILDCHECKS="false" ; fi
+
+CHECKWORLD=$WORLD
+CHECKCLOUDS=$CLOUDS
+
+
+########################
+## Set some variables ##
+########################
+mkdir -p tmp
+export MAGICK_TMPDIR=${PWD}/tmp
+echo "tmp-dir: $MAGICK_TMPDIR"
+
+mkdir -p logs
+TIME=$(date +"%Y-%m-%d_%H:%M:%S")
+LOGFILE_GENERAL="logs/${TIME}.log"
+LOGFILE_TIME="logs/${TIME}.time.log"
+
+URLS_WORLD="http://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.200408.3x21600x21600.A1.png
+http://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.200408.3x21600x21600.A2.png
+http://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.200408.3x21600x21600.B1.png
+http://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.200408.3x21600x21600.B2.png
+http://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.200408.3x21600x21600.C1.png
+http://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.200408.3x21600x21600.C2.png
+http://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.200408.3x21600x21600.D1.png
+http://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.200408.3x21600x21600.D2.png
+http://eoimages.gsfc.nasa.gov/images/imagerecords/79000/79765/dnb_land_ocean_ice.2012.54000x27000_geo.tif"
+
+URLS_CLOUDS="http://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57747/cloud.E.2001210.21600x21600.png
+http://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57747/cloud.W.2001210.21600x21600.png"
+
+ALTERNATE_URL="https://musicchris.de/download/FG/EarthView/raw-data-NASA.7z"
+ALTERNATE_FILENAME="raw-data-NASA.7z"
+
+if [ -z $RESOLUTION ]
+ then
+ RESOLUTION="1024
+2048
+4096
+8192
+16384"
+ NO_RESOLUTION_GIVEN="true"
+ RESOLUTION_MAX="16384"
+fi
+if [ -z $RESOLUTION_MAX ] ; then RESOLUTION_MAX=$RESOLUTION ; fi
+let "BORDER_WIDTH = $RESOLUTION_MAX / 128"
+let "IMAGE_BORDERLESS = $RESOLUTION_MAX - ( 2 * $BORDER_WIDTH )"
+let "IMAGE_WITH_BORDER_POS = $RESOLUTION_MAX - $BORDER_WIDTH"
+let "IMAGE_WITH_BORDER = $RESOLUTION_MAX - $BORDER_WIDTH - 1"
+
+NASA="A1
+B1
+C1
+D1
+A2
+B2
+C2
+D2"
+
+IM="0
+1
+2
+3
+4
+5
+6
+7"
+
+TILES="N1
+N2
+N3
+N4
+S1
+S2
+S3
+S4"
+
+BORDERS="top
+right
+bottom
+left"
+
+
+#################
+## FUNCTIONS ##
+#################
+
+function rebuild
+ {
+ #############################################
+ ## Only remove tmp-files of given target ##
+ #############################################
+
+ if [ $WORLD == "true" ]
+ then
+ {
+ echo
+ echo "########################################"
+ echo "## Removing tmp-files of target world ##"
+ echo "########################################"
+ rm tmp/world*
+ rm tmp/night*
+ }
+ fi
+
+ if [ $CLOUDS == "true" ]
+ then
+ {
+ echo
+ echo "#########################################"
+ echo "## Removing tmp-files of target clouds ##"
+ echo "#########################################"
+ rm tmp/cloud*
+ }
+ fi
+ }
+
+function cleanUp
+ {
+ echo
+ echo "############################"
+ echo "## Removing all tmp-files ##"
+ echo "############################"
+ rm -rv tmp/night*
+ rm -rv tmp/world*
+ rm -rv tmp/clouds*
+ }
+
+function prettyTime
+ {
+ if [ $SECS -gt 60 ]
+ then let "MINUTES = $SECS / 60"
+ else MINUTES=0
+ fi
+ if [ $MINUTES -gt 60 ]
+ then let "HOURS = $MINUTES / 60"
+ else HOURS=0
+ fi
+ if [ $HOURS -gt 24 ]
+ then let "DAYS = $HOURS / 24"
+ else DAYS=0
+ fi
+ if [ $DAYS -gt 0 ] ; then let "HOURS = $HOURS - ( $DAYS * 24 )" ; fi
+ if [ $HOURS -gt 0 ] ; then let "MINUTES = $MINUTES - ( ( ( $DAYS * 24 ) + $HOURS ) * 60 )" ; fi
+ if [ $MINUTES -gt 0 ] ; then let "SECS = $SECS - ( ( ( ( ( $DAYS * 24 ) + $HOURS ) * 60 ) + $MINUTES ) * 60 )" ; fi
+ }
+
+function getProcessingTime
+ {
+ ENDTIME=$(date +%s)
+ if [ $LASTTIME -eq $ENDTIME ]
+ then SECS=0
+ else let "SECS = $ENDTIME - $LASTTIME"
+ fi
+ prettyTime
+ OUTPUTSTRING="${SECS}s"
+ if [ $MINUTES -gt 0 ] ; then OUTPUTSTRING="${MINUTES}m ${SECS}s" ; fi
+ if [ $HOURS -gt 0 ] ; then OUTPUTSTRING="${HOURS}h ${MINUTES}m ${SECS}s" ; fi
+ if [ $DAYS -gt 0 ] ; then OUTPUTSTRING="${DAYS}d ${HOURS}h ${MINUTES}m ${SECS}s" ; fi
+ echo "Processing time: $OUTPUTSTRING" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ LASTTIME=$ENDTIME
+ }
+
+function NASA2FG
+ {
+ if [ $1 == "A1" ] ; then DEST="N1" ; fi
+ if [ $1 == "B1" ] ; then DEST="N2" ; fi
+ if [ $1 == "C1" ] ; then DEST="N3" ; fi
+ if [ $1 == "D1" ] ; then DEST="N4" ; fi
+ if [ $1 == "A2" ] ; then DEST="S1" ; fi
+ if [ $1 == "B2" ] ; then DEST="S2" ; fi
+ if [ $1 == "C2" ] ; then DEST="S3" ; fi
+ if [ $1 == "D2" ] ; then DEST="S4" ; fi
+ }
+
+function IM2FG
+ {
+ if [ $1 == "0" ] ; then DEST="N1" ; fi
+ if [ $1 == "1" ] ; then DEST="N2" ; fi
+ if [ $1 == "2" ] ; then DEST="N3" ; fi
+ if [ $1 == "3" ] ; then DEST="N4" ; fi
+ if [ $1 == "4" ] ; then DEST="S1" ; fi
+ if [ $1 == "5" ] ; then DEST="S2" ; fi
+ if [ $1 == "6" ] ; then DEST="S3" ; fi
+ if [ $1 == "7" ] ; then DEST="S4" ; fi
+ }
+
+function downloadImages
+ {
+ echo | tee -a $LOGFILE_GENERAL
+ echo "###################################################" | tee -a $LOGFILE_GENERAL
+ if [ ! -z $DL_LOCATION ]
+ then echo "## Downloading images from visibleearth.nasa.gov ##" | tee -a $LOGFILE_GENERAL
+ else echo "## Downloading images from musicchris.de ##" | tee -a $LOGFILE_GENERAL
+ fi
+ echo "###################################################" | tee -a $LOGFILE_GENERAL
+ if [ -z $DL_LOCATION ] ; then f=$ALTERNATE_URL ; DL_LOCATION="musicchris.de" ; fi
+ FILENAME=$(echo $f | sed 's@.*/@@')
+ if [ $WORLD == "true" ]
+ then
+ if [ $DL_LOCATION == "NASA" ]
+ then
+ downloadWorld
+ fi
+ fi
+
+ if [ $CLOUDS == "true" ]
+ then
+ if [ $DL_LOCATION == "NASA" ]
+ then
+ downloadClouds
+ fi
+ fi
+
+ if [ $DL_LOCATION == "musicchris.de" ] ; then downloadMusicchris ; fi
+ }
+
+function downloadWorld
+ {
+ mkdir -p input
+ echo "Downloading world tiles..." | tee -a $LOGFILE_GENERAL
+ for f in $URLS_WORLD
+ do
+ FILENAME=$(echo $f | sed 's@.*/@@')
+ wget --output-document=input/$FILENAME --continue --show-progress $f 2>> $LOGFILE_GENERAL
+ done
+ }
+
+function downloadClouds
+ {
+ mkdir -p input
+ echo "Downloading cloud tiles..." | tee -a $LOGFILE_GENERAL
+ for f in $URLS_CLOUDS
+ do
+ FILENAME=$(echo $f | sed 's@.*/@@')
+ wget --output-document=input/$FILENAME --continue --show-progress $f 2>> $LOGFILE_GENERAL
+ done
+ }
+
+function downloadMusicchris
+ {
+ mkdir -p input
+ echo "Downloading raw images... (ca 2.2 GB)" | tee -a $LOGFILE_GENERAL
+ for p in 1 2 3 4 5
+ do
+ wget --output-document=input/${FILENAME}.00${p} --continue --show-progress $ALTERNATE_URL | tee -a $LOGFILE_GENERAL 2>> $LOGFILE_GENERAL
+ done
+ echo "Unpacking raw images..." | tee -a $LOGFILE_GENERAL
+ cd input
+ 7z e -bt -y raw-data-NASA.7z 2>> $LOGFILE_GENERAL
+ cd ..
+ }
+
+function generateWorld
+ {
+ STARTTIME=$(date +%s)
+ echo | tee -a $LOGFILE_GENERAL
+ echo "################################" | tee -a $LOGFILE_GENERAL
+ echo "#### Processing World ####" | tee -a $LOGFILE_GENERAL
+ echo "################################" | tee -a $LOGFILE_GENERAL
+ echo | tee -a $LOGFILE_GENERAL
+
+ mkdir -p tmp
+ mkdir -p output
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "############################" | tee -a $LOGFILE_GENERAL
+ echo "## Prepare night lights ##" | tee -a $LOGFILE_GENERAL
+ echo "############################" | tee -a $LOGFILE_GENERAL
+ echo | tee -a $LOGFILE_GENERAL
+ echo "########################################" | tee -a $LOGFILE_GENERAL
+ echo "## Convert to a more efficient format ##" | tee -a $LOGFILE_GENERAL
+ echo "########################################" | tee -a $LOGFILE_GENERAL
+ if [ ! -s "tmp/nightlights_54000x27000.mpc" ]
+ then
+ # set -x
+ convert \
+ -monitor \
+ -limit memory 32 \
+ -limit map 32 \
+ input/dnb_land_ocean_ice.2012.54000x27000_geo.tif \
+ tmp/nightlights_54000x27000.mpc
+ set +x
+ else echo "=> Skipping existing file: tmp/nightlights_54000x27000.mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ echo "input/dnb_land_ocean_ice.2012.54000x27000_geo.tif -> tmp/nightlights_54000x27000.mpc" >> $LOGFILE_TIME
+ LASTTIME=$STARTTIME
+ # 1m, 59s
+ getProcessingTime
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "########################" | tee -a $LOGFILE_GENERAL
+ echo "## Resize nightlights ##" | tee -a $LOGFILE_GENERAL
+ echo "########################" | tee -a $LOGFILE_GENERAL
+ let "RESIZE_W = ( $RESOLUTION_MAX - ( 2 * $BORDER_WIDTH ) ) * 4"
+ let "RESIZE_H = ( $RESOLUTION_MAX - ( 2 * $BORDER_WIDTH ) ) * 2"
+ if [ ! -s "tmp/nightlights_${RESIZE_W}x${RESIZE_H}.mpc" ]
+ then
+ for r in 16384 8192 4096 2048
+ do
+ if [ $r -le $RESOLUTION_MAX ]
+ then continue
+ fi
+ let "IMAGE_SIZE = $r - ( 2 * ( $r / 128 ) )"
+ let "I_W = $IMAGE_SIZE * 4"
+ let "I_H = $IMAGE_SIZE * 2"
+ if [ -s tmp/nightlights_${I_W}x${I_H}.mpc ]
+ then
+ if [ $I_W -ge $RESIZE_W ]
+ then
+ echo "--> Found tmp/nightlights_${I_W}x${I_H}.mpc : usable for ${RESOLUTION_MAX}x${RESOLUTION_MAX}" >> $LOGFILE_GENERAL
+ FOUND_BIGGER_PICTURE="true"
+ TIMESAVER_SIZE="$IMAGE_SIZE"
+ fi
+ else
+ echo "--> No." >> $LOGFILE_GENERAL
+ fi
+ done
+ echo
+ if [ -z $FOUND_BIGGER_PICTURE ]
+ then
+ echo "No suitable image found. Using NASA original..."
+ # set -x
+ convert \
+ -monitor \
+ -limit memory 32 \
+ -limit map 32 \
+ tmp/nightlights_54000x27000.mpc \
+ -resize ${RESIZE_W}x${RESIZE_H} \
+ tmp/nightlights_${RESIZE_W}x${RESIZE_H}.mpc
+ set +x
+ else
+ let "I_W = $TIMESAVER_SIZE * 4"
+ let "I_H = $TIMESAVER_SIZE * 2"
+ echo "==> Timesaver:) Using existing file: tmp/nightlights_${I_W}x${I_H}.mpc" | tee -a $LOGFILE_GENERAL
+ # set -x
+ convert \
+ -monitor \
+ -limit memory 32 \
+ -limit map 32 \
+ tmp/nightlights_${I_W}x${I_H}.mpc \
+ -resize ${RESIZE_W}x${RESIZE_H} \
+ tmp/nightlights_${RESIZE_W}x${RESIZE_H}.mpc
+ set +x
+ fi
+ else echo "=> Skipping existing file: tmp/nightlights_${RESIZE_W}x${RESIZE_H}.mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ # 3h, 47m, 29s
+ echo "-> tmp/nightlights_${RESIZE_W}x${RESIZE_H}.mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "#############################################" | tee -a $LOGFILE_GENERAL
+ echo "## Filter out low colors (continents, ice) ##" | tee -a $LOGFILE_GENERAL
+ echo "#############################################" | tee -a $LOGFILE_GENERAL
+ if [ ! -s "tmp/nightlights_${RESIZE_W}x${RESIZE_H}_lowColorsCut.mpc" ]
+ then
+ # set -x
+ convert \
+ -monitor \
+ -limit memory 32 \
+ -limit map 32 \
+ tmp/nightlights_${RESIZE_W}x${RESIZE_H}.mpc \
+ -channel R -level 7.8%,100%,1.5 \
+ -channel G -level 13.7%,100%,1.5 \
+ -channel B -level 33%,100%,1.5 \
+ +channel \
+ tmp/nightlights_${RESIZE_W}x${RESIZE_H}_lowColorsCut.mpc
+ set +x
+ else echo "=> Skipping existing file: tmp/nightlights_${RESIZE_W}x${RESIZE_H}_lowColorsCut.mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ # 1h, 8m, 52s
+ echo "-> tmp/nightlights_${RESIZE_W}x${RESIZE_H}_lowColorsCut.mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "#####################################" | tee -a $LOGFILE_GENERAL
+ echo "## cut nightlight image into tiles ##" | tee -a $LOGFILE_GENERAL
+ echo "#####################################" | tee -a $LOGFILE_GENERAL
+ if [ ! -s "tmp/night_${IMAGE_BORDERLESS}_7.mpc" ]
+ then
+ # set -x
+ convert \
+ -monitor \
+ -limit memory 32 \
+ -limit map 32 \
+ tmp/nightlights_${RESIZE_W}x${RESIZE_H}_lowColorsCut.mpc \
+ -crop ${IMAGE_BORDERLESS}x${IMAGE_BORDERLESS} +repage \
+ -alpha Off \
+ tmp/night_${IMAGE_BORDERLESS}_%d.mpc
+ set +x
+ else echo "=> Skipping existing files: tmp/night_${IMAGE_BORDERLESS}_[0-7].mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ # 41m, 43s
+ echo "-> tmp/night_${IMAGE_BORDERLESS}_[0-7].mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "###################" | tee -a $LOGFILE_GENERAL
+ echo "## invert colors ##" | tee -a $LOGFILE_GENERAL
+ echo "###################" | tee -a $LOGFILE_GENERAL
+ for f in $IM
+ do
+ IM2FG $f
+ if [ ! -s "tmp/night_${IMAGE_BORDERLESS}_${DEST}_neg.mpc" ]
+ then
+ # set -x
+ convert \
+ -monitor \
+ tmp/night_${IMAGE_BORDERLESS}_${f}.mpc \
+ -negate \
+ tmp/night_${IMAGE_BORDERLESS}_${DEST}_neg.mpc
+ set +x
+ else echo "=> Skipping existing file: tmp/night_${IMAGE_BORDERLESS}_${DEST}_neg.mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ done
+ # 5m, 33s
+ echo "-> tmp/night_${IMAGE_BORDERLESS}_[NS][1-4]_neg.mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "##############################" | tee -a $LOGFILE_GENERAL
+ echo "## Prepare world textures ##" | tee -a $LOGFILE_GENERAL
+ echo "##############################" | tee -a $LOGFILE_GENERAL
+ echo | tee -a $LOGFILE_GENERAL
+ echo "################################################" | tee -a $LOGFILE_GENERAL
+ echo "## Resize the NASA-Originals to ${RESOLUTION_MAX}-(2*${BORDER_WIDTH}) ##" | tee -a $LOGFILE_GENERAL
+ echo "################################################" | tee -a $LOGFILE_GENERAL
+ for t in $NASA
+ do
+ NASA2FG $t
+ FOUND_BIGGER_WORLD_PICTURE="false"
+ unset $TIMESAVER_SIZE
+ if [ ! -s "tmp/world_seamless_${IMAGE_BORDERLESS}_${DEST}.mpc" ]
+ then
+ {
+ for r in 16384 8192 4096 2048
+ do
+ if [ $r -le $RESOLUTION_MAX ]
+ then
+ continue
+ fi
+ let "IMAGE_SIZE = $r - ( 2 * ( $r / 128 ) )"
+ let "I_W = $IMAGE_SIZE * 4"
+ let "I_H = $IMAGE_SIZE * 2"
+ if [ -s tmp/world_seamless_${IMAGE_SIZE}_${DEST}.mpc ]
+ then
+ if [ $IMAGE_SIZE -ge $IMAGE_BORDERLESS ]
+ then
+ FOUND_BIGGER_WORLD_PICTURE="true"
+ TIMESAVER_SIZE="$IMAGE_SIZE"
+ fi
+ fi
+ done
+ if [ $FOUND_BIGGER_WORLD_PICTURE != "true" ]
+ then
+ ## Workaround for tiles N3 and N4 - there's a gray failure area at the top border - let's remove it!
+ if [ $t == "C1" ]
+ then
+ # pick a sample pixel. The polar regions are all equally colored.
+ let "OVERLAY_HEIGHT = ${RESOLUTION_MAX} / 14"
+ # set -x
+ convert \
+ -monitor \
+ -limit memory 32 \
+ -limit map 32 \
+ tmp/world_seamless_${IMAGE_BORDERLESS}_N2.mpc \
+ -crop 1x1+1+1 \
+ -resize ${IMAGE_BORDERLESS}x${OVERLAY_HEIGHT}\! \
+ tmp/bluebar.mpc
+ set +x
+ fi
+ if [ $t == "C1" -o $t == "D1" ]
+ then
+ {
+ # copy the sample over to the tile:
+ # set -x
+ convert \
+ -monitor \
+ -limit memory 32 \
+ -limit map 32 \
+ input/world.200408.3x21600x21600.${t}.png \
+ -resize ${IMAGE_BORDERLESS}x${IMAGE_BORDERLESS} \
+ tmp/bluebar.mpc \
+ -geometry +0+0 \
+ -composite \
+ tmp/world_seamless_${IMAGE_BORDERLESS}_${DEST}.mpc
+ set +x
+ echo
+ }
+ else
+ {
+ # set -x
+ convert \
+ -monitor \
+ -limit memory 32 \
+ -limit map 32 \
+ input/world.200408.3x21600x21600.${t}.png \
+ -resize ${IMAGE_BORDERLESS}x${IMAGE_BORDERLESS} \
+ tmp/world_seamless_${IMAGE_BORDERLESS}_${DEST}.mpc
+ set +x
+ }
+ fi
+ else
+ echo "==> Timesaver:) Using existing file: tmp/world_seamless_${TIMESAVER_SIZE}_${DEST}.mpc -> tmp/world_seamless_${IMAGE_BORDERLESS}_${DEST}.mpc" | tee -a $LOGFILE_GENERAL
+ set -x
+ convert \
+ -monitor \
+ -limit memory 32 \
+ -limit map 32 \
+ tmp/world_seamless_${TIMESAVER_SIZE}_${DEST}.mpc \
+ -resize ${IMAGE_BORDERLESS}x${IMAGE_BORDERLESS} \
+ tmp/world_seamless_${IMAGE_BORDERLESS}_${DEST}.mpc
+ set +x
+ fi
+ }
+ else echo "=> Skipping existing file: tmp/world_seamless_${IMAGE_BORDERLESS}_${DEST}.mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ done
+ # 3h, 12m, 9s
+ echo "input/world.200408.3x21600x21600.[A-D][12].png -> tmp/world_seamless_${IMAGE_BORDERLESS}_[NS][1-4].mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "##################################################" | tee -a $LOGFILE_GENERAL
+ echo "## Merge nightlights into world's alpha channel ##" | tee -a $LOGFILE_GENERAL
+ echo "##################################################" | tee -a $LOGFILE_GENERAL
+ for t in $TILES
+ do
+ if [ ! -s "tmp/world_seamless_${IMAGE_BORDERLESS}_${t}_composite.mpc" ]
+ then
+ # set -x
+ convert \
+ -monitor \
+ tmp/world_seamless_${IMAGE_BORDERLESS}_${t}.mpc \
+ tmp/night_${IMAGE_BORDERLESS}_${t}_neg.mpc \
+ -compose CopyOpacity \
+ -composite \
+ tmp/world_seamless_${IMAGE_BORDERLESS}_${t}_composite.mpc
+ set +x
+ else echo "=> Skipping existing file: tmp/world_seamless_${IMAGE_BORDERLESS}_${t}_composite.mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ done
+ # 11m, 26s
+ echo "-> tmp/world_seamless_${IMAGE_BORDERLESS}_[NS][1-4]_composite.mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "#####################################" | tee -a $LOGFILE_GENERAL
+ echo "## Put a ${BORDER_WIDTH}px border to each side ##" | tee -a $LOGFILE_GENERAL
+ echo "#####################################" | tee -a $LOGFILE_GENERAL
+ for t in $TILES
+ do
+ if [ ! -s "tmp/world_seams_${RESOLUTION_MAX}_${t}_emptyBorder.mpc" ]
+ then
+ # set -x
+ convert \
+ -monitor \
+ tmp/world_seamless_${IMAGE_BORDERLESS}_${t}_composite.mpc \
+ -bordercolor none \
+ -border ${BORDER_WIDTH} \
+ tmp/world_seams_${RESOLUTION_MAX}_${t}_emptyBorder.mpc
+ set +x
+ echo
+ fi
+ if [ ! -s "tmp/world_seams_${RESOLUTION_MAX}_${t}.mpc" ]
+ then
+ # set -x
+ cp tmp/world_seams_${RESOLUTION_MAX}_${t}_emptyBorder.mpc tmp/world_seams_${RESOLUTION_MAX}_${t}.mpc
+ cp tmp/world_seams_${RESOLUTION_MAX}_${t}_emptyBorder.cache tmp/world_seams_${RESOLUTION_MAX}_${t}.cache
+ set +x
+ else echo "=> Skipping existing file: tmp/world_seams_${RESOLUTION_MAX}_${t}.mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ done
+ # 11m, 24s
+ echo "-> tmp/world_seams_${RESOLUTION_MAX}_[NS][1-4]_emptyBorder.mpc -> tmp/world_seams_${RESOLUTION_MAX}_[NS][1-4].mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "######################################################" | tee -a $LOGFILE_GENERAL
+ echo "## crop borderline pixels and propagate to the edge ##" | tee -a $LOGFILE_GENERAL
+ echo "######################################################" | tee -a $LOGFILE_GENERAL
+
+ CROP_TOP="${IMAGE_BORDERLESS}x1+${BORDER_WIDTH}+${BORDER_WIDTH}"
+ CROP_RIGHT="1x${IMAGE_BORDERLESS}+${IMAGE_WITH_BORDER}+${BORDER_WIDTH}"
+ CROP_BOTTOM="${IMAGE_BORDERLESS}x1+${BORDER_WIDTH}+${IMAGE_WITH_BORDER}"
+ CROP_LEFT="1x${IMAGE_BORDERLESS}+${BORDER_WIDTH}+${BORDER_WIDTH}"
+ CROP_TOPLEFT="1x1+${BORDER_WIDTH}+${BORDER_WIDTH}"
+ CROP_TOPRIGHT="1x1+${IMAGE_WITH_BORDER}+${BORDER_WIDTH}"
+ CROP_BOTTOMRIGHT="1x1+${IMAGE_WITH_BORDER}+${IMAGE_WITH_BORDER}"
+ CROP_BOTTOMLEFT="1x1+${BORDER_WIDTH}+${IMAGE_WITH_BORDER}"
+
+ ## HORIZ meaning a horizontal bar, like the one on top
+ HORIZ_RESIZE="${IMAGE_BORDERLESS}x${BORDER_WIDTH}"
+ VERT_RESIZE="${BORDER_WIDTH}x${IMAGE_BORDERLESS}"
+
+ POS_TOP="+${BORDER_WIDTH}+0"
+ POS_RIGHT="+${IMAGE_WITH_BORDER_POS}+${BORDER_WIDTH}"
+ POS_BOTTOM="+${BORDER_WIDTH}+${IMAGE_WITH_BORDER_POS}"
+ POS_LEFT="+0+${BORDER_WIDTH}"
+
+ for t in $TILES
+ do
+ if [ ! -s "tmp/world_${RESOLUTION_MAX}_done_${t}.mpc" ]
+ then
+ for b in $BORDERS
+ do
+ {
+ if [ $b == "top" ]
+ then
+ CROP=$CROP_TOP
+ RESIZE=$HORIZ_RESIZE
+ POSITION=$POS_TOP
+ CROPCORNER=$CROP_TOPRIGHT
+ CORNER_POS="+${IMAGE_WITH_BORDER_POS}+0"
+ CORNER_NAME="topRight"
+ fi
+ if [ $b == "right" ]
+ then
+ CROP=$CROP_RIGHT
+ RESIZE=$VERT_RESIZE
+ POSITION=$POS_RIGHT
+ CROPCORNER=$CROP_BOTTOMRIGHT
+ CORNER_POS="+${IMAGE_WITH_BORDER_POS}+${IMAGE_WITH_BORDER_POS}"
+ CORNER_NAME="bottomRight"
+ fi
+ if [ $b == "bottom" ]
+ then
+ CROP=$CROP_BOTTOM
+ RESIZE=$HORIZ_RESIZE
+ POSITION=$POS_BOTTOM
+ CROPCORNER=$CROP_BOTTOMLEFT
+ CORNER_POS="+0+${IMAGE_WITH_BORDER_POS}"
+ CORNER_NAME="bottomLeft"
+ fi
+ if [ $b == "left" ]
+ then
+ CROP=$CROP_LEFT
+ RESIZE=$VERT_RESIZE
+ POSITION=$POS_LEFT
+ CROPCORNER=$CROP_TOPLEFT
+ CORNER_POS="+0+0"
+ CORNER_NAME="topLeft"
+ fi
+ echo
+ # set -x
+ convert \
+ -monitor \
+ tmp/world_seams_${RESOLUTION_MAX}_${t}_emptyBorder.mpc \
+ -crop $CROP \
+ -resize $RESIZE\! \
+ tmp/world_${RESOLUTION_MAX}_${t}_seam_${b}.mpc
+ convert \
+ -monitor \
+ tmp/world_seams_${RESOLUTION_MAX}_${t}_emptyBorder.mpc \
+ -crop $CROPCORNER \
+ -resize ${BORDER_WIDTH}x${BORDER_WIDTH}\! \
+ tmp/world_${RESOLUTION_MAX}_${t}_seam_${CORNER_NAME}.mpc
+ convert \
+ -monitor \
+ tmp/world_seams_${RESOLUTION_MAX}_${t}.mpc \
+ tmp/world_${RESOLUTION_MAX}_${t}_seam_${b}.mpc \
+ -geometry $POSITION \
+ -composite \
+ tmp/world_seams_${RESOLUTION_MAX}_${t}.mpc
+ echo
+ convert \
+ -monitor \
+ tmp/world_seams_${RESOLUTION_MAX}_${t}.mpc \
+ tmp/world_${RESOLUTION_MAX}_${t}_seam_${CORNER_NAME}.mpc \
+ -geometry $CORNER_POS \
+ -composite \
+ tmp/world_seams_${RESOLUTION_MAX}_${t}.mpc
+ set +x
+ echo
+ }
+ done
+ echo
+ # set -x
+ cp -v tmp/world_seams_${RESOLUTION_MAX}_${t}.mpc tmp/world_${RESOLUTION_MAX}_done_${t}.mpc | tee -a $LOGFILE_GENERAL
+ cp -v tmp/world_seams_${RESOLUTION_MAX}_${t}.cache tmp/world_${RESOLUTION_MAX}_done_${t}.cache | tee -a $LOGFILE_GENERAL
+ set +x
+
+ else echo "=> Skipping existing file: tmp/world_${RESOLUTION_MAX}_done_${t}.mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+
+ done
+ # 37m, 6s
+ echo "-> tmp/world_seams_${RESOLUTION_MAX}_[NS][1-4].mpc -> tmp/world_${RESOLUTION_MAX}_done_[NS][1-4].mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ for t in $TILES
+ do
+ echo | tee -a $LOGFILE_GENERAL
+ echo "#############################" | tee -a $LOGFILE_GENERAL
+ echo "## Final output of tile $t ##" | tee -a $LOGFILE_GENERAL
+ echo "#############################" | tee -a $LOGFILE_GENERAL
+ for r in $RESOLUTION
+ do
+ {
+ mkdir -p output/$r
+ echo
+ echo "--> Writing output/${r}/world_${t}.dds @ ${r}x${r}"
+ # set -x
+ convert \
+ -monitor \
+ tmp/world_${RESOLUTION_MAX}_done_${t}.mpc \
+ -resize ${r}x${r} \
+ -flip \
+ -define dds:compression=dxt5 \
+ output/${r}/world_${t}.dds
+ set +x
+ echo
+ echo "--> Writing output/${r}/world_${t}.png @ ${r}x${r}"
+ # set -x
+ convert \
+ -monitor \
+ tmp/world_${RESOLUTION_MAX}_done_${t}.mpc \
+ -resize ${r}x${r} \
+ output/${r}/world_${t}.png
+ set +x
+ echo
+ }
+ done
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "World $t [ done ]" | tee -a $LOGFILE_GENERAL
+ echo | tee -a $LOGFILE_GENERAL
+
+ done
+ echo "###############################" | tee -a $LOGFILE_GENERAL
+ echo "#### World: [ done ] ####" | tee -a $LOGFILE_GENERAL
+ echo "###############################" | tee -a $LOGFILE_GENERAL
+ # 2h, 19m, 7s
+ # Overall processing time: 44089 s
+ # Overall processing time: 0 d, 2 h, 19 m, 7 s
+
+ echo "-> output/<\$RESOLUTIONS>/world_[NS][1-4].png" >> $LOGFILE_TIME
+ getProcessingTime
+ echo
+ if [ $STARTTIME -eq $ENDTIME ]
+ then SECS=0
+ else let "SECS = $ENDTIME - $STARTTIME"
+ fi
+ echo "Overall processing time: $SECS s" | tee -a $LOGFILE_GENERAL
+ prettyTime
+ echo "Overall processing time: $DAYS d, $HOURS h, $MINUTES m, $SECS s" | tee -a $LOGFILE_GENERAL
+ }
+
+function generateClouds
+ {
+ if [ -z $STARTTIME ] ; then STARTTIME=$(date +%s) ; fi
+ # maximum cloud-tile resolution is 8192, since we have no big enough source files...
+ if [ $RESOLUTION_MAX -eq 16384 ] ; then RESOLUTION_MAX=8192 ; fi
+ let "BORDER_WIDTH = $RESOLUTION_MAX / 128"
+ let "IMAGE_BORDERLESS = $RESOLUTION_MAX - ( 2 * $BORDER_WIDTH )"
+ let "IMAGE_WITH_BORDER = $RESOLUTION_MAX - $BORDER_WIDTH - 1"
+ let "IMAGE_WITH_BORDER_POS = $RESOLUTION_MAX - $BORDER_WIDTH"
+ let "SIZE = 2 * $IMAGE_BORDERLESS"
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "#################################" | tee -a $LOGFILE_GENERAL
+ echo "#### Processing clouds ####" | tee -a $LOGFILE_GENERAL
+ echo "#################################" | tee -a $LOGFILE_GENERAL
+ echo | tee -a $LOGFILE_GENERAL
+
+ mkdir -p tmp
+ mkdir -p output
+
+ echo "######################################" | tee -a $LOGFILE_GENERAL
+ echo "## Resize images to ${SIZE} resolution, ##" | tee -a $LOGFILE_GENERAL
+ echo "## copy image to alpha-channel and ##" | tee -a $LOGFILE_GENERAL
+ echo "## paint the canvas white (#FFFFFF) ##" | tee -a $LOGFILE_GENERAL
+ echo "######################################" | tee -a $LOGFILE_GENERAL
+ CT="E
+W"
+ for t in $CT
+ do
+ unset FOUND_BIGGER_CLOUD_PICTURE
+ unset TIMESAVER_SIZE
+ if [ ! -s "tmp/cloud_T_${SIZE}_${t}.mpc" ]
+ then
+ for r in 16384 8192 4096 2048
+ do
+ if [ $r -le $RESOLUTION_MAX ]
+ then continue
+ fi
+ let "IMAGE_SIZE = ( $r - ( 2 * ( $r / 128 ) ) ) * 2"
+ echo "Does tmp/cloud_T_${IMAGE_SIZE}_${t}.mpc exist?" >> $LOGFILE_GENERAL
+ if [ -s tmp/cloud_T_${IMAGE_SIZE}_${t}.mpc ]
+ then
+ echo "Yes. Is it usable? ( $IMAGE_SIZE >= $SIZE )" >> $LOGFILE_GENERAL
+ if [ $IMAGE_SIZE -ge $SIZE ]
+ then
+ echo "Yes - use it!" >> $LOGFILE_GENERAL
+ FOUND_BIGGER_CLOUD_PICTURE="true"
+ TIMESAVER_SIZE="$IMAGE_SIZE"
+ else echo "No." >> $LOGFILE_GENERAL
+ fi
+ else echo "No." >> $LOGFILE_GENERAL
+ fi
+ done
+ if [ -z $FOUND_BIGGER_CLOUD_PICTURE ]
+ then
+ echo "So we'll have to use the NASA originals." >> $LOGFILE_GENERAL
+ # set -x
+ convert \
+ -monitor \
+ input/cloud.${t}.2001210.21600x21600.png \
+ -resize ${SIZE}x${SIZE} \
+ -alpha copy \
+ +level-colors white \
+ tmp/cloud_T_${SIZE}_${t}.mpc
+ set +x
+ else
+ echo "==> Timesaver:) Using existing file: tmp/cloud_T_${TIMESAVER_SIZE}_${t}.mpc" | tee -a $LOGFILE_GENERAL
+ # set -x
+ convert \
+ -monitor \
+ tmp/cloud_T_${TIMESAVER_SIZE}_${t}.mpc \
+ -resize ${SIZE}x${SIZE} \
+ tmp/cloud_T_${SIZE}_${t}.mpc
+ set +x
+ fi
+ else echo "=> Skipping existing file: tmp/cloud_T_${SIZE}_${t}.mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ done
+ echo
+ # 6m, 4s
+ if [ -z $LASTTIME ] ; then LASTTIME=$STARTTIME ; fi
+ echo "input/cloud.[EW].2001210.21600x21600.png -> tmp/cloud_T_${SIZE}_[EW].mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "#################################" | tee -a $LOGFILE_GENERAL
+ echo "## cut cloud images into tiles ##" | tee -a $LOGFILE_GENERAL
+ echo "#################################" | tee -a $LOGFILE_GENERAL
+ if [ ! -s "tmp/clouds_${IMAGE_BORDERLESS}_S2.mpc" ]
+ then
+ {
+ convert \
+ -monitor \
+ tmp/cloud_T_${SIZE}_E.mpc \
+ -crop ${IMAGE_BORDERLESS}x${IMAGE_BORDERLESS} \
+ +repage \
+ tmp/clouds_${IMAGE_BORDERLESS}_%d.mpc
+ N="0
+1
+2
+3"
+ for t in $N
+ do
+ {
+ if [ $t == "0" ]
+ then
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.mpc tmp/clouds_${IMAGE_BORDERLESS}_N3.mpc
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.cache tmp/clouds_${IMAGE_BORDERLESS}_N3.cache
+ fi
+ if [ $t == "1" ]
+ then
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.mpc tmp/clouds_${IMAGE_BORDERLESS}_N4.mpc
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.cache tmp/clouds_${IMAGE_BORDERLESS}_N4.cache
+ fi
+ if [ $t == "2" ]
+ then
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.mpc tmp/clouds_${IMAGE_BORDERLESS}_S3.mpc
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.cache tmp/clouds_${IMAGE_BORDERLESS}_S3.cache
+ fi
+ if [ $t == "3" ]
+ then
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.mpc tmp/clouds_${IMAGE_BORDERLESS}_S4.mpc
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.cache tmp/clouds_${IMAGE_BORDERLESS}_S4.cache
+ fi
+ }
+ done
+ }
+ else echo "=> Skipping existing files: tmp/clouds_${IMAGE_BORDERLESS}_[N3-S4].mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ if [ ! -s "tmp/clouds_${IMAGE_BORDERLESS}_S2.mpc" ]
+ then
+ {
+ convert \
+ -monitor \
+ tmp/cloud_T_${SIZE}_W.mpc \
+ -crop ${IMAGE_BORDERLESS}x${IMAGE_BORDERLESS} \
+ +repage \
+ tmp/clouds_${IMAGE_BORDERLESS}_%d.mpc
+ echo
+ for t in $N
+ do
+ {
+ if [ $t == "0" ]
+ then
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.mpc tmp/clouds_${IMAGE_BORDERLESS}_N1.mpc
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.cache tmp/clouds_${IMAGE_BORDERLESS}_N1.cache
+ fi
+ if [ $t == "1" ]
+ then
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.mpc tmp/clouds_${IMAGE_BORDERLESS}_N2.mpc
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.cache tmp/clouds_${IMAGE_BORDERLESS}_N2.cache
+ fi
+ if [ $t == "2" ]
+ then
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.mpc tmp/clouds_${IMAGE_BORDERLESS}_S1.mpc
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.cache tmp/clouds_${IMAGE_BORDERLESS}_S1.cache
+ fi
+ if [ $t == "3" ]
+ then
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.mpc tmp/clouds_${IMAGE_BORDERLESS}_S2.mpc
+ mv tmp/clouds_${IMAGE_BORDERLESS}_${t}.cache tmp/clouds_${IMAGE_BORDERLESS}_S2.cache
+ fi
+ }
+ done
+ }
+ else echo "=> Skipping existing files: tmp/clouds_${IMAGE_BORDERLESS}_[N1-S2].mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ # 1m, 30s
+ echo "-> tmp/clouds_${IMAGE_BORDERLESS}_[0-7].mpc -> tmp/clouds_${IMAGE_BORDERLESS}_[NS][1-4].mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "###################################" | tee -a $LOGFILE_GENERAL
+ echo "## add ${BORDER_WIDTH}px borders to the tiles ##" | tee -a $LOGFILE_GENERAL
+ echo "###################################" | tee -a $LOGFILE_GENERAL
+ for t in $TILES
+ do
+ if [ ! -s "tmp/clouds_${RESOLUTION_MAX}_${t}_emptyBorder.mpc" ]
+ then
+ convert \
+ -monitor \
+ tmp/clouds_${IMAGE_BORDERLESS}_${t}.mpc \
+ -bordercolor none \
+ -border ${BORDER_WIDTH} \
+ tmp/clouds_${RESOLUTION_MAX}_${t}_emptyBorder.mpc
+ echo
+ cp tmp/clouds_${RESOLUTION_MAX}_${t}_emptyBorder.mpc tmp/clouds_seams_${RESOLUTION_MAX}_${t}.mpc
+ cp tmp/clouds_${RESOLUTION_MAX}_${t}_emptyBorder.cache tmp/clouds_seams_${RESOLUTION_MAX}_${t}.cache
+ else echo "=> Skipping existing file: tmp/clouds_${RESOLUTION_MAX}_${t}_emptyBorder.mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ done
+ echo
+ # 1m, 44s
+ echo "-> tmp/clouds_${RESOLUTION_MAX}_[NS][1-4]_emptyBorder.mpc tmp/clouds_seams_${RESOLUTION_MAX}_[NS][1-4].mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "#######################################" | tee -a $LOGFILE_GENERAL
+ echo "## propagate last pixels to the edge ##" | tee -a $LOGFILE_GENERAL
+ echo "#######################################" | tee -a $LOGFILE_GENERAL
+
+ if [ $RESOLUTION_MAX -eq 16384 ] ; then RESOLUTION_MAX=8192 ; fi
+ let "BORDER_WIDTH = $RESOLUTION_MAX / 128"
+ let "IMAGE_BORDERLESS = $RESOLUTION_MAX - ( 2 * $BORDER_WIDTH )"
+ let "IMAGE_WITH_BORDER = $RESOLUTION_MAX - $BORDER_WIDTH - 1"
+ let "IMAGE_WITH_BORDER_POS = $RESOLUTION_MAX - $BORDER_WIDTH"
+ let "SIZE = 2 * $IMAGE_BORDERLESS"
+
+ CROP_TOP="${IMAGE_BORDERLESS}x1+${BORDER_WIDTH}+${BORDER_WIDTH}"
+ CROP_RIGHT="1x${IMAGE_BORDERLESS}+${IMAGE_WITH_BORDER}+${BORDER_WIDTH}"
+ CROP_BOTTOM="${IMAGE_BORDERLESS}x1+${BORDER_WIDTH}+${IMAGE_WITH_BORDER}"
+ CROP_LEFT="1x${IMAGE_BORDERLESS}+${BORDER_WIDTH}+${BORDER_WIDTH}"
+ CROP_TOPLEFT="1x1+${BORDER_WIDTH}+${BORDER_WIDTH}"
+ CROP_TOPRIGHT="1x1+${IMAGE_WITH_BORDER}+${BORDER_WIDTH}"
+ CROP_BOTTOMRIGHT="1x1+${IMAGE_WITH_BORDER}+${IMAGE_WITH_BORDER}"
+ CROP_BOTTOMLEFT="1x1+${BORDER_WIDTH}+${IMAGE_WITH_BORDER}"
+
+ ## HORIZ meaning a horizontal bar, like the one on top
+ HORIZ_RESIZE="${IMAGE_BORDERLESS}x${BORDER_WIDTH}"
+ VERT_RESIZE="${BORDER_WIDTH}x${IMAGE_BORDERLESS}"
+
+ POS_TOP="+${BORDER_WIDTH}+0"
+ POS_RIGHT="+${IMAGE_WITH_BORDER_POS}+${BORDER_WIDTH}"
+ POS_BOTTOM="+${BORDER_WIDTH}+${IMAGE_WITH_BORDER_POS}"
+ POS_LEFT="+0+${BORDER_WIDTH}"
+
+ for t in $TILES
+ do
+ if [ ! -s tmp/clouds_${RESOLUTION_MAX}_${t}_done.mpc ]
+ then
+ for b in $BORDERS
+ do
+ {
+ if [ $b == "top" ]
+ then
+ CROP=$CROP_TOP
+ RESIZE=$HORIZ_RESIZE
+ POSITION=$POS_TOP
+ CROPCORNER=$CROP_TOPRIGHT
+ CORNER_POS="+${IMAGE_WITH_BORDER_POS}+0"
+ CORNER_NAME="topRight"
+ fi
+ if [ $b == "right" ]
+ then
+ CROP=$CROP_RIGHT
+ RESIZE=$VERT_RESIZE
+ POSITION=$POS_RIGHT
+ CROPCORNER=$CROP_BOTTOMRIGHT
+ CORNER_POS="+${IMAGE_WITH_BORDER_POS}+${IMAGE_WITH_BORDER_POS}"
+ CORNER_NAME="bottomRight"
+ fi
+ if [ $b == "bottom" ]
+ then
+ CROP=$CROP_BOTTOM
+ RESIZE=$HORIZ_RESIZE
+ POSITION=$POS_BOTTOM
+ CROPCORNER=$CROP_BOTTOMLEFT
+ CORNER_POS="+0+${IMAGE_WITH_BORDER_POS}"
+ CORNER_NAME="bottomLeft"
+ fi
+ if [ $b == "left" ]
+ then
+ CROP=$CROP_LEFT
+ RESIZE=$VERT_RESIZE
+ POSITION=$POS_LEFT
+ CROPCORNER=$CROP_TOPLEFT
+ CORNER_POS="+0+0"
+ CORNER_NAME="topLeft"
+ fi
+ #set -x
+ convert \
+ -monitor \
+ tmp/clouds_seams_${RESOLUTION_MAX}_${t}.mpc \
+ -crop $CROP \
+ -resize $RESIZE\! \
+ tmp/clouds_${RESOLUTION_MAX}_${t}_seam_${b}.mpc
+ convert \
+ -monitor \
+ tmp/clouds_seams_${RESOLUTION_MAX}_${t}.mpc \
+ -crop $CROPCORNER \
+ -resize ${BORDER_WIDTH}x${BORDER_WIDTH}\! \
+ tmp/clouds_${RESOLUTION_MAX}_${t}_seam_${CORNER_NAME}.mpc
+ convert \
+ -monitor \
+ tmp/clouds_seams_${RESOLUTION_MAX}_${t}.mpc \
+ tmp/clouds_${RESOLUTION_MAX}_${t}_seam_${b}.mpc \
+ -geometry $POSITION \
+ -composite \
+ tmp/clouds_seams_${RESOLUTION_MAX}_${t}.mpc
+ echo
+ convert \
+ -monitor \
+ tmp/clouds_seams_${RESOLUTION_MAX}_${t}.mpc \
+ tmp/clouds_${RESOLUTION_MAX}_${t}_seam_${CORNER_NAME}.mpc \
+ -geometry $CORNER_POS \
+ -composite \
+ tmp/clouds_seams_${RESOLUTION_MAX}_${t}.mpc
+ set +x
+ echo
+ }
+ done
+ echo
+ cp tmp/clouds_seams_${RESOLUTION_MAX}_${t}.mpc tmp/clouds_${RESOLUTION_MAX}_${t}_done.mpc
+ cp tmp/clouds_seams_${RESOLUTION_MAX}_${t}.cache tmp/clouds_${RESOLUTION_MAX}_${t}_done.cache
+ else echo "=> Skipping existing file: tmp/clouds_${RESOLUTION_MAX}_${t}_done.mpc" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ fi
+ done
+ # 2m, 34s
+ echo "-> tmp/clouds_seams_${RESOLUTION_MAX}_[NS][1-4].mpc -> tmp/clouds_${RESOLUTION_MAX}_[NS][1-4]_done.mpc" >> $LOGFILE_TIME
+ getProcessingTime
+
+ for t in $TILES
+ do
+ echo | tee -a $LOGFILE_GENERAL
+ echo "#############################" | tee -a $LOGFILE_GENERAL
+ echo "## Final output of tile $t ##" | tee -a $LOGFILE_GENERAL
+ echo "#############################" | tee -a $LOGFILE_GENERAL
+ for r in $RESOLUTION
+ do
+ {
+ if [ $r -eq 16384 ]
+ then
+ if [ $NO_RESOLUTION_GIVEN == "true" ]
+ then
+ continue
+ else
+ r=8192
+ fi
+ fi
+ mkdir -p output/$r
+ echo
+ echo "--> Writing output/${r}/clouds_${t}.png @ ${r}x${r}" | tee -a $LOGFILE_GENERAL
+ convert \
+ -monitor \
+ tmp/clouds_${RESOLUTION_MAX}_${t}_done.mpc \
+ -resize ${r}x${r} \
+ output/${r}/clouds_${t}.png
+ }
+ done
+
+ echo | tee -a $LOGFILE_GENERAL
+ echo "Cloud $t [ done ]" | tee -a $LOGFILE_GENERAL
+ echo | tee -a $LOGFILE_GENERAL
+ done
+ echo "################################" | tee -a $LOGFILE_GENERAL
+ echo "#### Clouds: [ done ] ####" | tee -a $LOGFILE_GENERAL
+ echo "################################" | tee -a $LOGFILE_GENERAL
+
+ # 7m, 4s
+ echo "-> output/<\$RESOLUTION>/clouds_[NS][1-4].png" | tee -a $LOGFILE_TIME
+ getProcessingTime
+ echo
+ if [ $STARTTIME -eq $ENDTIME ]
+ then SECS=0
+ else let "SECS = $ENDTIME - $STARTTIME"
+ fi
+ echo "Overall processing time: $SECS s" | tee -a $LOGFILE_GENERAL
+ prettyTime
+ echo "Overall processing time: $DAYS d, $HOURS h, $MINUTES m, $SECS s" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+ }
+
+function checkResults
+ {
+ echo | tee -a $LOGFILE_GENERAL
+ echo "##############################################" | tee -a $LOGFILE_GENERAL
+ echo "## Creating a mosaic of the created tiles ##" | tee -a $LOGFILE_GENERAL
+ echo "##############################################" | tee -a $LOGFILE_GENERAL
+ echo | tee -a $LOGFILE_GENERAL
+
+ RES=16384
+ for r in $RESOLUTION
+ do
+ if [ $r -le $RES ]
+ then
+ RES=$r
+ fi
+ done
+ let "WIDTH = 4 * $RES"
+ let "HEIGHT = 2 * $RES"
+ echo "Lowest available resolution is: $RES" | tee -a $LOGFILE_GENERAL
+
+ if [ $CHECKCLOUDS == "true" ]
+ then
+ {
+ echo "checking clouds..." | tee -a $LOGFILE_GENERAL
+ echo | tee -a $LOGFILE_GENERAL
+
+ echo "Creating canvas ${WIDTH}x${HEIGHT}" | tee -a $LOGFILE_GENERAL
+ convert \
+ -size ${WIDTH}x${HEIGHT} \
+ xc:Black \
+ -alpha on \
+ check_clouds.png
+
+ POS=0
+ for t in 1 2 3 4
+ do
+ convert \
+ -monitor \
+ check_clouds.png \
+ output/${RES}/clouds_N${t}.png \
+ -geometry +${POS}+0 \
+ -composite \
+ check_clouds.png
+ echo
+ convert \
+ -monitor \
+ check_clouds.png \
+ output/${RES}/clouds_S${t}.png \
+ -geometry +${POS}+${RES} \
+ -composite \
+ check_clouds.png
+ echo
+ let "POS += $RES"
+ done
+ mogrify \
+ -monitor \
+ -resize 4096x2048 \
+ check_clouds.png
+ }
+ fi
+
+ if [ $CHECKWORLD == "true" ]
+ then
+ {
+ echo "checking world..." | tee -a $LOGFILE_GENERAL
+ echo | tee -a $LOGFILE_GENERAL
+
+ echo "Creating canvas ${WIDTH}x${HEIGHT}" | tee -a $LOGFILE_GENERAL
+ convert \
+ -size ${WIDTH}x${HEIGHT} \
+ xc:Black \
+ -alpha on \
+ check_world.png
+
+ POS=0
+ for t in 1 2 3 4
+ do
+ convert \
+ -monitor \
+ check_world.png \
+ output/${RES}/world_N${t}.png \
+ -alpha Off \
+ -geometry +${POS}+0 \
+ -composite \
+ check_world.png
+ echo
+ convert \
+ -monitor \
+ check_world.png \
+ output/${RES}/world_S${t}.png \
+ -alpha Off \
+ -geometry +${POS}+${RES} \
+ -composite \
+ check_world.png
+ echo
+ let "POS += $RES"
+ done
+ mogrify \
+ -monitor \
+ -resize 4096x2048 \
+ check_world.png
+
+ for f in $TILES
+ do
+ convert \
+ -monitor \
+ tmp/night_${IMAGE_BORDERLESS}_${f}_neg.mpc \
+ -resize 1024x1024 \
+ -negate \
+ tmp/night_${IMAGE_BORDERLESS}_${f}_check.mpc
+ done
+ montage \
+ -monitor \
+ -mode concatenate \
+ -tile 4x \
+ tmp/night_${IMAGE_BORDERLESS}_??_check.mpc \
+ check_night.png
+ }
+ fi
+ }
+
+
+
+###############################
+#### Actual program: ####
+###############################
+
+echo | tee $LOGFILE_GENERAL
+echo "--------------------------------------------------------------" | tee -a $LOGFILE_GENERAL
+echo | tee -a $LOGFILE_GENERAL
+echo "Processing starts..." | tee -a $LOGFILE_GENERAL | tee $LOGFILE_TIME
+echo $TIME | tee -a $LOGFILE_TIME
+echo | tee -a $LOGFILE_GENERAL
+printf "Target: " | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+if [ $CLOUDS == "true" ] ; then printf "clouds " | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME ; fi
+if [ $WORLD == "true" ] ; then printf "world " | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME ; fi
+echo | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+echo "Will work in ${RESOLUTION_MAX}x${RESOLUTION_MAX} resolution and will output" | tee -a $LOGFILE_GENERAL
+printf "Resolution: " | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+for r in $RESOLUTION ; do printf "%sx%s " $r $r | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME ; done
+echo | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+echo | tee -a $LOGFILE_GENERAL
+echo "--------------------------------------------------------------" | tee -a $LOGFILE_GENERAL | tee -a $LOGFILE_TIME
+echo | tee -a $LOGFILE_GENERAL
+
+
+if [ $REBUILD == "true" ] ; then rebuild ; fi
+if [ $DOWNLOAD == "true" ] ; then downloadImages ; fi
+if [ $WORLD == "true" ] ; then generateWorld ; fi
+if [ $CLOUDS == "true" ] ; then generateClouds ; fi
+if [ $BUILDCHECKS == "true" ] ; then checkResults ; fi
+if [ $CLEANUP == "true" ] ; then cleanUp ; fi
+
+
+
+
+
+echo | tee -a $LOGFILE_GENERAL
+echo "convert.sh has finished." | tee -a $LOGFILE_GENERAL
+echo | tee -a $LOGFILE_GENERAL
+echo "You will find the textures in \"output\" in your requested"
+echo "resolution. Copy these to \$FGDATA/Models/Astro/*"
+if [ $CLEANUP == "false" ]
+then
+ echo "If you're certain, that the generated textures are to your satisfaction"
+ echo "you can delete folder tmp and thus free up disk space."
+ echo "./convert.sh cleanup"
+ echo "or"
+ echo "rm -r tmp/"
+fi