joint_inversion.c 3.39 KB
Newer Older
1
/*-----------------------------------------------------------------------------------------
2
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
3
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
4
 * This file is part of IFOS.
5
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
6
 * IFOS is free software: you can redistribute it and/or modify
7 8 9
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.0 of the License only.
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
10
 * IFOS is distributed in the hope that it will be useful,
11 12 13 14 15
 * 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
Florian Wittkamp's avatar
Florian Wittkamp committed
16
 * along with IFOS. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
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
 -----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *
 * Joint Inversion
 *
 *
 *  ----------------------------------------------------------------------*/
#include "fd.h"

float ** joint_inversion_grad ( float ** gradiant_1,float ** gradiant_2, float alpha, int joint_type) {
    /*
     * Input parameters:
     * - gradiant_1 : first gradiant
     * - gradiant_2 : second gradiant
     * - alpha : value for weighting
     * - joint_type:
     *              1: Normalize both and take the arithmetic mean
     *
     */
    
    /* Define local variables  */
    float ** joint_gradiant; // This will be the merged gradiant, which will be returned
    int i, j;
    float max1=0.0,max2=0.0;
    /* Define extern variables */
    extern int NX, NY, NXG, NYG;
    extern int NPROCX, NPROCY, MYID;
    extern FILE *FP;
    
47
    
48 49
    switch (joint_type) {
        case 1:
50 51 52
            /* joint_type=1: Normalize both and take the arithmetic mean */
            max1=global_maximum(gradiant_1);
            max2=global_maximum(gradiant_2);
53
            for (j=1;j<=NY;j++){
54 55
                for (i=1;i<=NX;i++){
                    gradiant_1[j][i]=((1-alpha)*gradiant_1[j][i]/max1+alpha*gradiant_2[j][i]/max2);
56 57 58 59
                    
                    if (isnan(gradiant_1[j][i])) {
                        gradiant_1[j][i]=0.0;
                    }
60
                }
61
            }
62 63
            joint_gradiant=gradiant_1;
            break;
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
            
        case 2:
             /* joint_type=2: Arithmetic mean without normalization */
            for (j=1;j<=NY;j++){
                for (i=1;i<=NX;i++){
                    gradiant_1[j][i]=((1-alpha)*gradiant_1[j][i]+alpha*gradiant_2[j][i]);
                    
                    if (isnan(gradiant_1[j][i])) {
                        gradiant_1[j][i]=0.0;
                    }
                }
            }
            joint_gradiant=gradiant_1;
            break;
            
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
        case 3:
            /* joint_type=1: Normalize both and take the arithmetic mean */
            max1=global_maximum(gradiant_1);
            max2=global_maximum(gradiant_2);
            for (j=1;j<=NY;j++){
                for (i=1;i<=NX;i++){
                    gradiant_1[j][i]=(gradiant_1[j][i]/max1+gradiant_2[j][i]/max2)*(max2+max1);
                    
                    if (isnan(gradiant_1[j][i])) {
                        gradiant_1[j][i]=0.0;
                    }
                }
            }
            joint_gradiant=gradiant_1;
            break;
94
    }
95

96 97 98 99
    return joint_gradiant;
};