/source/calcCohTransLoss.c

https://github.com/EyNuel/cTraceo · C · 116 lines · 53 code · 12 blank · 51 comment · 9 complexity · be860e02e2c334eec58faf34c8904472 MD5 · raw file

  1. /****************************************************************************************
  2. * calcCohTransLoss.c *
  3. * (formerly "calctl.for") *
  4. * Calculates Coherent Transmission Loss. *
  5. * *
  6. * ------------------------------------------------------------------------------------ *
  7. * Website: *
  8. * https://github.com/EyNuel/cTraceo/wiki *
  9. * *
  10. * License: This file is part of the cTraceo Raytracing Model and is released under the *
  11. * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License *
  12. * http://creativecommons.org/licenses/by-nc-sa/3.0/ *
  13. * *
  14. * NOTE: cTraceo is research code under active development. *
  15. * The code may contain bugs and updates are possible in the future. *
  16. * *
  17. * Written for project SENSOCEAN by: *
  18. * Emanuel Ey *
  19. * emanuel.ey@gmail.com *
  20. * Copyright (C) 2011 - 2013 *
  21. * Signal Processing Laboratory *
  22. * Universidade do Algarve *
  23. * *
  24. * cTraceo is the C port of the FORTRAN 77 TRACEO code written by: *
  25. * Orlando Camargo Rodriguez: *
  26. * Copyright (C) 2010 *
  27. * Orlando Camargo Rodriguez *
  28. * orodrig@ualg.pt *
  29. * Universidade do Algarve *
  30. * Physics Department *
  31. * Signal Processing Laboratory *
  32. * *
  33. * ------------------------------------------------------------------------------------ *
  34. * Inputs: *
  35. * settings: Pointer to structure containing all input info. *
  36. * *
  37. * Outputs: *
  38. * "ctl.mat": File containing Coherent Transmission Loss. *
  39. * *
  40. * Return Value: *
  41. * None *
  42. * *
  43. * NOTE: *
  44. * This function requires that the coherent acoustic pressure has been *
  45. * calculated (by calcCohAcoustPress) and will be of no use otherwise. *
  46. * *
  47. ****************************************************************************************/
  48. #include "globals.h"
  49. #if USE_MATLAB == 1
  50. #include <mat.h>
  51. #include "matrix.h"
  52. #else
  53. #include "matOut/matOut.h"
  54. #endif
  55. #include <math.h>
  56. #include <complex.h>
  57. void calcCohTransLoss(settings_t*);
  58. void calcCohTransLoss(settings_t* settings){
  59. uint32_t i, j, dim;
  60. double* tl = NULL;
  61. double** tl2D = NULL;
  62. mxArray* ptl = NULL;
  63. mxArray* ptl2D = NULL;
  64. switch(settings->output.arrayType){
  65. case ARRAY_TYPE__RECTANGULAR:
  66. case ARRAY_TYPE__HORIZONTAL:
  67. case ARRAY_TYPE__VERTICAL:
  68. /*
  69. * horizontal and vertical arrays are special cases of Rectangular hydrophone arrays,
  70. * so all of them can be handled by the same code.
  71. */
  72. tl2D = mallocDouble2D(settings->output.nArrayR, settings->output.nArrayZ);
  73. for(i=0; i<settings->output.nArrayR; i++){
  74. for(j=0; j<settings->output.nArrayZ; j++){
  75. tl2D[i][j] = -20.0*log10( cabs( settings->output.pressure2D[i][j] ) );
  76. }
  77. }
  78. ptl2D = mxCreateDoubleMatrix((MWSIZE)settings->output.nArrayZ, (MWSIZE)settings->output.nArrayR, mxREAL);
  79. if(ptl2D == NULL){
  80. fatal("Memory alocation error.");
  81. }
  82. copyDoubleToPtr2D_transposed(tl2D, ptl2D, settings->output.nArrayZ, settings->output.nArrayR);
  83. matPutVariable(settings->options.matfile,"tl",ptl2D);
  84. mxDestroyArray(ptl2D);
  85. freeDouble2D(tl2D, settings->output.nArrayR);
  86. break;
  87. case ARRAY_TYPE__LINEAR:
  88. dim = (uint32_t)max((double)settings->output.nArrayR, (double)settings->output.nArrayZ);
  89. tl = mallocDouble(dim);
  90. for(j=0; j<dim; j++){
  91. tl[j] = -20.0*log10( cabs( settings->output.pressure2D[0][j] ) );
  92. DEBUG(8, "|p|: %lf, tl: %lf\n", cabs( settings->output.pressure2D[0][j] ), tl[j]);
  93. }
  94. ptl = mxCreateDoubleMatrix((MWSIZE)1, (MWSIZE)dim, mxREAL);
  95. if(ptl == NULL){
  96. fatal("Memory alocation error.");
  97. }
  98. copyDoubleToPtr(tl, mxGetPr(ptl), dim);
  99. matPutVariable(settings->options.matfile,"tl",ptl);
  100. mxDestroyArray(ptl);
  101. free(tl);
  102. break;
  103. }
  104. }