/*-------------------------------------------------------------------- * * Copyright (c) 1991-2021 by the GMT Team (https://www.generic-mapping-tools.org/team.html) * See LICENSE.TXT file for copying and redistribution conditions. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 3 or 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 Lesser General Public License for more details. * * Contact info: www.generic-mapping-tools.org *--------------------------------------------------------------------*/ /* * Brief synopsis: grd2cpt reads a 2d binary gridded grdfile and creates a continuous-color- * palette CPT, with a non-linear histogram-equalized mapping between * hue and data value. (The linear mapping can be made with grd2cpt.) * * Creates a cumulative distribution function f(z) describing the data * in the grdfile. f(z) is sampled at z values supplied by the user * [with -S option] or guessed from the sample mean and standard deviation. * f(z) is then found by looping over the grd array for each z and counting * data values <= z. Once f(z) is found then a master CPT is resampled * based on a normalized f(z). * * Author: Walter H. F. Smith * Date: 1-JAN-2010 * Version: 6 API * */ #include "gmt_dev.h" #define THIS_MODULE_CLASSIC_NAME "grd2cpt" #define THIS_MODULE_MODERN_NAME "grd2cpt" #define THIS_MODULE_LIB "core" #define THIS_MODULE_PURPOSE "Make linear or histogram-equalized color palette table from grid" #define THIS_MODULE_KEYS "C},ED)=f" #define THIS_MODULE_NEEDS "" #define THIS_MODULE_OPTIONS "->RVhbo" #define GRD2CPT_N_LEVELS 11 /* The default number of levels if nothing is specified */ struct GRD2CPT_CTRL { struct GRD2CPT_In { bool active; } In; struct GRD2CPT_Out { /* -> */ bool active; char *file; } Out; struct GRD2CPT_A { /* -A[+a] */ bool active; unsigned int mode; double value; } A; struct GRD2CPT_C { /* -C or -C,[,,...] */ bool active; char *file; } C; struct GRD2CPT_D { /* -D[i|o] */ bool active; unsigned int mode; } D; struct GRD2CPT_E { /* -E[+c][+f] */ bool active; bool cdf; char *file; unsigned int levels; } E; struct GRD2CPT_F { /* -F[r|R|h|c][+c[